Commit 2a76c4ab authored by Franco Fichtner's avatar Franco Fichtner

wizard: add language selection; closes #648

parent 26814679
...@@ -228,6 +228,28 @@ function system_resolvconf_generate($dynupdate = false) ...@@ -228,6 +228,28 @@ function system_resolvconf_generate($dynupdate = false)
return 0; return 0;
} }
function get_locale_list()
{
$locales = array();
/* first one is the default */
$locales['en_US'] = gettext('English');
$locales['zh_CN'] = gettext('Chinese (Simplified)');
$locales['nl_NL'] = gettext('Dutch');
$locales['fr_FR'] = gettext('French');
$locales['de_DE'] = gettext('German');
$locales['it_IT'] = gettext('Italian');
$locales['ja_JP'] = gettext('Japanese');
$locales['mn_MN'] = gettext('Mongolian');
$locales['pt_BR'] = gettext('Portuguese');
$locales['ru_RU'] = gettext('Russian');
$locales['es_ES'] = gettext('Spanish');
$locales['sv_SE'] = gettext('Swedish');
$locales['tr_TR'] = gettext('Turkish');
return $locales;
}
function get_country_codes() function get_country_codes()
{ {
$dn_cc = array(); $dn_cc = array();
......
...@@ -56,7 +56,9 @@ ...@@ -56,7 +56,9 @@
<Log VisibleName="Log File" url="/diag_logs_gateways.php"/> <Log VisibleName="Log File" url="/diag_logs_gateways.php"/>
</Gateways> </Gateways>
<Settings order="20" cssClass="fa fa-cogs fa-fw"> <Settings order="20" cssClass="fa fa-cogs fa-fw">
<General order="100" url="/system_general.php"/> <General order="100" url="/system_general.php">
<workAround url="/system_general.php*"/>
</General>
<Administration order="200" url="/system_advanced_admin.php"/> <Administration order="200" url="/system_advanced_admin.php"/>
<Logging order="300" url="/diag_logs_settings.php"/> <Logging order="300" url="/diag_logs_settings.php"/>
<Notifications order="400" url="/system_advanced_notifications.php"/> <Notifications order="400" url="/system_advanced_notifications.php"/>
......
...@@ -68,6 +68,11 @@ ...@@ -68,6 +68,11 @@
<validate>^[a-z0-9.|-]+$</validate> <validate>^[a-z0-9.|-]+$</validate>
<message>Domain name field is invalid</message> <message>Domain name field is invalid</message>
</field> </field>
<field>
<name>Language</name>
<type>language_select</type>
<bindstofield>system->language</bindstofield>
</field>
<field> <field>
<name>Primary DNS Server</name> <name>Primary DNS Server</name>
<type>input</type> <type>input</type>
......
...@@ -49,25 +49,6 @@ session_write_close(); ...@@ -49,25 +49,6 @@ session_write_close();
/* CSRF END: THANK YOU FOR YOUR COOPERATION */ /* CSRF END: THANK YOU FOR YOUR COOPERATION */
function set_language()
{
global $config;
$lang = 'en_US';
if (!empty($config['system']['language'])) {
$lang = $config['system']['language'];
}
$lang_encoding = $lang . '.UTF-8';
$textdomain = 'OPNsense';
putenv('LANG=' . $lang_encoding);
setlocale(LC_ALL, $lang_encoding);
textdomain($textdomain);
bindtextdomain($textdomain, '/usr/local/share/locale');
bind_textdomain_codeset($textdomain, $lang_encoding);
}
function get_current_theme() function get_current_theme()
{ {
global $config; global $config;
...@@ -89,7 +70,20 @@ function html_safe($text) ...@@ -89,7 +70,20 @@ function html_safe($text)
header("X-Frame-Options: SAMEORIGIN"); header("X-Frame-Options: SAMEORIGIN");
set_language(); /* set language */
$lang = 'en_US';
if (!empty($config['system']['language'])) {
$lang = $config['system']['language'];
}
$lang_encoding = $lang . '.UTF-8';
$textdomain = 'OPNsense';
putenv('LANG=' . $lang_encoding);
setlocale(LC_ALL, $lang_encoding);
textdomain($textdomain);
bindtextdomain($textdomain, '/usr/local/share/locale');
bind_textdomain_codeset($textdomain, $lang_encoding);
require_once("authgui.inc"); require_once("authgui.inc");
......
...@@ -34,31 +34,13 @@ require_once("unbound.inc"); ...@@ -34,31 +34,13 @@ require_once("unbound.inc");
require_once("interfaces.inc"); require_once("interfaces.inc");
require_once("services.inc"); require_once("services.inc");
function get_locale_list()
{
$locales = array();
/* first one is the default */
$locales['en_US'] = gettext('English');
$locales['zh_CN'] = gettext('Chinese (Simplified)');
$locales['nl_NL'] = gettext('Dutch');
$locales['fr_FR'] = gettext('French');
$locales['de_DE'] = gettext('German');
$locales['it_IT'] = gettext('Italian');
$locales['ja_JP'] = gettext('Japanese');
$locales['mn_MN'] = gettext('Mongolian');
$locales['pt_BR'] = gettext('Portuguese');
$locales['ru_RU'] = gettext('Russian');
$locales['es_ES'] = gettext('Spanish');
$locales['sv_SE'] = gettext('Swedish');
$locales['tr_TR'] = gettext('Turkish');
return $locales;
}
if ($_SERVER['REQUEST_METHOD'] === 'GET') { if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$pconfig = array(); $pconfig = array();
if (isset($_GET['savemsg'])) {
$savemsg = htmlspecialchars($_GET['savemsg']);
}
$pconfig['dns1gw'] = null; $pconfig['dns1gw'] = null;
$pconfig['dns2gw'] = null; $pconfig['dns2gw'] = null;
$pconfig['dns3gw'] = null; $pconfig['dns3gw'] = null;
...@@ -152,116 +134,113 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -152,116 +134,113 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
} }
if (count($input_errors) == 0) { if (count($input_errors) == 0) {
$config['system']['hostname'] = $pconfig['hostname']; $config['system']['hostname'] = $pconfig['hostname'];
$config['system']['domain'] = $pconfig['domain']; $config['system']['domain'] = $pconfig['domain'];
$config['system']['timezone'] = $pconfig['timezone']; $config['system']['timezone'] = $pconfig['timezone'];
$config['theme'] = $pconfig['theme']; $config['theme'] = $pconfig['theme'];
if (!empty($pconfig['language']) && $pconfig['language'] != $config['system']['language']) {
$config['system']['language'] = $pconfig['language'];
/* XXX while this is very proactive, we should defer in favour of a unified language transition point ;) */
set_language();
}
if (!empty($pconfig['prefer_ipv4'])) { if (!empty($pconfig['language']) && $pconfig['language'] != $config['system']['language']) {
$config['system']['prefer_ipv4'] = true; $config['system']['language'] = $pconfig['language'];
} elseif (isset($config['system']['prefer_ipv4'])) { }
unset($config['system']['prefer_ipv4']);
}
if (!empty($pconfig['gw_switch_default'])) { if (!empty($pconfig['prefer_ipv4'])) {
$config['system']['gw_switch_default'] = true; $config['system']['prefer_ipv4'] = true;
} elseif (isset($config['system']['gw_switch_default'])) { } elseif (isset($config['system']['prefer_ipv4'])) {
unset($config['system']['gw_switch_default']); unset($config['system']['prefer_ipv4']);
} }
$olddnsservers = $config['system']['dnsserver']; if (!empty($pconfig['gw_switch_default'])) {
$config['system']['dnsserver'] = array(); $config['system']['gw_switch_default'] = true;
foreach (array('dns1', 'dns2', 'dns3', 'dns4') as $dnsopt) { } elseif (isset($config['system']['gw_switch_default'])) {
if (!empty($pconfig[$dnsopt])) { unset($config['system']['gw_switch_default']);
$config['system']['dnsserver'][] = $pconfig[$dnsopt]; }
}
} $olddnsservers = $config['system']['dnsserver'];
$olddnsallowoverride = !empty($config['system']['dnsallowoverride']); $config['system']['dnsserver'] = array();
foreach (array('dns1', 'dns2', 'dns3', 'dns4') as $dnsopt) {
if (!empty($pconfig[$dnsopt])) {
$config['system']['dnsserver'][] = $pconfig[$dnsopt];
}
}
$olddnsallowoverride = !empty($config['system']['dnsallowoverride']);
$config['system']['dnsallowoverride'] = !empty($pconfig['dnsallowoverride']); $config['system']['dnsallowoverride'] = !empty($pconfig['dnsallowoverride']);
if($pconfig['dnslocalhost'] == "yes") { if($pconfig['dnslocalhost'] == "yes") {
$config['system']['dnslocalhost'] = true; $config['system']['dnslocalhost'] = true;
} elseif (isset($config['system']['dnslocalhost'])) { } elseif (isset($config['system']['dnslocalhost'])) {
unset($config['system']['dnslocalhost']); unset($config['system']['dnslocalhost']);
} }
/* which interface should the dns servers resolve through? */ /* which interface should the dns servers resolve through? */
$outdnscounter = 0; $outdnscounter = 0;
for ($dnscounter=1; $dnscounter<5; $dnscounter++) { for ($dnscounter=1; $dnscounter<5; $dnscounter++) {
$dnsname="dns{$dnscounter}"; $dnsname="dns{$dnscounter}";
$dnsgwname="dns{$dnscounter}gw"; $dnsgwname="dns{$dnscounter}gw";
$olddnsgwname = !empty($config['system'][$dnsgwname]) ? $config['system'][$dnsgwname] : "none" ; $olddnsgwname = !empty($config['system'][$dnsgwname]) ? $config['system'][$dnsgwname] : "none" ;
if ($ignore_posted_dnsgw[$dnsgwname]) {
$thisdnsgwname = "none";
} else {
$thisdnsgwname = $pconfig[$dnsgwname];
}
// "Blank" out the settings for this index, then we set them below using the "outdnscounter" index.
$config['system'][$dnsgwname] = "none";
$pconfig[$dnsgwname] = "none";
$pconfig[$dnsname] = "";
if (!empty($_POST[$dnsname])) {
// Only the non-blank DNS servers were put into the config above.
// So we similarly only add the corresponding gateways sequentially to the config (and to pconfig), as we find non-blank DNS servers.
// This keeps the DNS server IP and corresponding gateway "lined up" when the user blanks out a DNS server IP in the middle of the list.
$outdnscounter++;
$outdnsname="dns{$outdnscounter}";
$outdnsgwname="dns{$outdnscounter}gw";
$pconfig[$outdnsname] = $_POST[$dnsname];
if(!empty($_POST[$dnsgwname])) {
$config['system'][$outdnsgwname] = $thisdnsgwname;
$pconfig[$outdnsgwname] = $thisdnsgwname;
} else {
// Note: when no DNS GW name is chosen, the entry is set to "none", so actually this case never happens.
unset($config['system'][$outdnsgwname]);
$pconfig[$outdnsgwname] = "";
}
}
if ($olddnsgwname != "none" && ($olddnsgwname != $thisdnsgwname || $olddnsservers[$dnscounter-1] != $_POST[$dnsname])) {
// A previous DNS GW name was specified. It has now gone or changed, or the DNS server address has changed.
// Remove the route. Later calls will add the correct new route if needed.
if (is_ipaddrv4($olddnsservers[$dnscounter-1])) {
mwexec("/sbin/route delete " . escapeshellarg($olddnsservers[$dnscounter-1]));
} else {
if (is_ipaddrv6($olddnsservers[$dnscounter-1])) {
mwexec("/sbin/route delete -inet6 " . escapeshellarg($olddnsservers[$dnscounter-1]));
}
}
}
}
write_config(); if ($ignore_posted_dnsgw[$dnsgwname]) {
$thisdnsgwname = "none";
} else {
$thisdnsgwname = $pconfig[$dnsgwname];
}
prefer_ipv4_or_ipv6(); // "Blank" out the settings for this index, then we set them below using the "outdnscounter" index.
system_hostname_configure(); $config['system'][$dnsgwname] = "none";
system_hosts_generate(); $pconfig[$dnsgwname] = "none";
services_dhcpleases_configure(); $pconfig[$dnsname] = "";
system_resolvconf_generate();
services_dnsmasq_configure(false); if (!empty($_POST[$dnsname])) {
services_unbound_configure(false); // Only the non-blank DNS servers were put into the config above.
services_dhcpd_configure(); // So we similarly only add the corresponding gateways sequentially to the config (and to pconfig), as we find non-blank DNS servers.
system_timezone_configure(); // This keeps the DNS server IP and corresponding gateway "lined up" when the user blanks out a DNS server IP in the middle of the list.
$outdnscounter++;
$outdnsname="dns{$outdnscounter}";
$outdnsgwname="dns{$outdnscounter}gw";
$pconfig[$outdnsname] = $_POST[$dnsname];
if(!empty($_POST[$dnsgwname])) {
$config['system'][$outdnsgwname] = $thisdnsgwname;
$pconfig[$outdnsgwname] = $thisdnsgwname;
} else {
// Note: when no DNS GW name is chosen, the entry is set to "none", so actually this case never happens.
unset($config['system'][$outdnsgwname]);
$pconfig[$outdnsgwname] = "";
}
}
if ($olddnsgwname != "none" && ($olddnsgwname != $thisdnsgwname || $olddnsservers[$dnscounter-1] != $_POST[$dnsname])) {
// A previous DNS GW name was specified. It has now gone or changed, or the DNS server address has changed.
// Remove the route. Later calls will add the correct new route if needed.
if (is_ipaddrv4($olddnsservers[$dnscounter-1])) {
mwexec("/sbin/route delete " . escapeshellarg($olddnsservers[$dnscounter-1]));
} else {
if (is_ipaddrv6($olddnsservers[$dnscounter-1])) {
mwexec("/sbin/route delete -inet6 " . escapeshellarg($olddnsservers[$dnscounter-1]));
}
}
}
}
if ($olddnsallowoverride != $config['system']['dnsallowoverride']) { write_config();
configd_run("dns reload");
}
filter_configure(); prefer_ipv4_or_ipv6();
system_hostname_configure();
system_hosts_generate();
services_dhcpleases_configure();
system_resolvconf_generate();
services_dnsmasq_configure(false);
services_unbound_configure(false);
services_dhcpd_configure();
system_timezone_configure();
$savemsg = get_std_save_message(); if ($olddnsallowoverride != $config['system']['dnsallowoverride']) {
} configd_run("dns reload");
}
unset($ignore_posted_dnsgw); filter_configure();
header(url_safe('Location: /system_general.php?savemsg=%s', array(get_std_save_message())));
exit;
}
} }
legacy_html_escape_form_data($pconfig); legacy_html_escape_form_data($pconfig);
...@@ -269,7 +248,6 @@ legacy_html_escape_form_data($pconfig); ...@@ -269,7 +248,6 @@ legacy_html_escape_form_data($pconfig);
include("head.inc"); include("head.inc");
?> ?>
<body> <body>
<?php include("fbegin.inc"); ?> <?php include("fbegin.inc"); ?>
......
...@@ -749,6 +749,35 @@ function showchange() { ...@@ -749,6 +749,35 @@ function showchange() {
echo "<br /> " . $field['description']; echo "<br /> " . $field['description'];
} }
break;
case "language_select":
$languagelist = get_locale_list();
if ($field['displayname']) {
echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
echo $field['displayname'];
echo ":</td>\n";
} else if(!$field['dontdisplayname']) {
echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
echo fixup_string($field['name']);
echo ":</td>";
}
if(!$field['dontcombinecells'])
echo "<td class=\"vtable\">";
echo "<select class='form-control' name='{$name}'>\n";
foreach ($languagelist as $langkey => $langval) {
$SELECTED = "";
if ($value == $langkey) $SELECTED = " selected=\"selected\"";
echo "<option value=\"" . htmlspecialchars($langkey) . "\" {$SELECTED}>";
echo htmlspecialchars($langval);
echo "</option>\n";
}
echo "</select>\n";
if($field['description'] <> "") {
echo "<br /> " . $field['description'];
}
break; break;
case "timezone_select": case "timezone_select":
$timezonelist = get_zoneinfo(); $timezonelist = get_zoneinfo();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment