Commit a4f9af68 authored by Franco Fichtner's avatar Franco Fichtner

wizard: add language selection; closes #648

(cherry picked from commit 2a76c4ab)
parent 2e3cf91c
......@@ -228,6 +228,22 @@ function system_resolvconf_generate($dynupdate = false)
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['fr_FR'] = gettext('French');
$locales['de_DE'] = gettext('German');
$locales['it_IT'] = gettext('Italian');
$locales['ja_JP'] = gettext('Japanese');
$locales['ru_RU'] = gettext('Russian');
return $locales;
}
function get_country_codes()
{
$dn_cc = array();
......
......@@ -56,7 +56,9 @@
<Log VisibleName="Log File" url="/diag_logs_gateways.php"/>
</Gateways>
<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"/>
<Logging order="300" url="/diag_logs_settings.php"/>
<Notifications order="400" url="/system_advanced_notifications.php"/>
......
......@@ -68,6 +68,11 @@
<validate>^[a-z0-9.|-]+$</validate>
<message>Domain name field is invalid</message>
</field>
<field>
<name>Language</name>
<type>language_select</type>
<bindstofield>system->language</bindstofield>
</field>
<field>
<name>Primary DNS Server</name>
<type>input</type>
......
......@@ -49,25 +49,6 @@ session_write_close();
/* 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()
{
global $config;
......@@ -89,7 +70,20 @@ function html_safe($text)
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");
......
......@@ -34,25 +34,13 @@ require_once("unbound.inc");
require_once("interfaces.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['fr_FR'] = gettext('French');
$locales['de_DE'] = gettext('German');
$locales['it_IT'] = gettext('Italian');
$locales['ja_JP'] = gettext('Japanese');
$locales['ru_RU'] = gettext('Russian');
return $locales;
}
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$pconfig = array();
if (isset($_GET['savemsg'])) {
$savemsg = htmlspecialchars($_GET['savemsg']);
}
$pconfig['dns1gw'] = null;
$pconfig['dns2gw'] = null;
$pconfig['dns3gw'] = null;
......@@ -146,116 +134,113 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
}
if (count($input_errors) == 0) {
$config['system']['hostname'] = $pconfig['hostname'];
$config['system']['domain'] = $pconfig['domain'];
$config['system']['timezone'] = $pconfig['timezone'];
$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();
}
$config['system']['hostname'] = $pconfig['hostname'];
$config['system']['domain'] = $pconfig['domain'];
$config['system']['timezone'] = $pconfig['timezone'];
$config['theme'] = $pconfig['theme'];
if (!empty($pconfig['prefer_ipv4'])) {
$config['system']['prefer_ipv4'] = true;
} elseif (isset($config['system']['prefer_ipv4'])) {
unset($config['system']['prefer_ipv4']);
}
if (!empty($pconfig['language']) && $pconfig['language'] != $config['system']['language']) {
$config['system']['language'] = $pconfig['language'];
}
if (!empty($pconfig['gw_switch_default'])) {
$config['system']['gw_switch_default'] = true;
} elseif (isset($config['system']['gw_switch_default'])) {
unset($config['system']['gw_switch_default']);
}
if (!empty($pconfig['prefer_ipv4'])) {
$config['system']['prefer_ipv4'] = true;
} elseif (isset($config['system']['prefer_ipv4'])) {
unset($config['system']['prefer_ipv4']);
}
$olddnsservers = $config['system']['dnsserver'];
$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']);
if (!empty($pconfig['gw_switch_default'])) {
$config['system']['gw_switch_default'] = true;
} elseif (isset($config['system']['gw_switch_default'])) {
unset($config['system']['gw_switch_default']);
}
$olddnsservers = $config['system']['dnsserver'];
$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;
} elseif (isset($config['system']['dnslocalhost'])) {
unset($config['system']['dnslocalhost']);
}
} elseif (isset($config['system']['dnslocalhost'])) {
unset($config['system']['dnslocalhost']);
}
/* which interface should the dns servers resolve through? */
$outdnscounter = 0;
for ($dnscounter=1; $dnscounter<5; $dnscounter++) {
$dnsname="dns{$dnscounter}";
$dnsgwname="dns{$dnscounter}gw";
$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]));
}
}
}
}
/* which interface should the dns servers resolve through? */
$outdnscounter = 0;
for ($dnscounter=1; $dnscounter<5; $dnscounter++) {
$dnsname="dns{$dnscounter}";
$dnsgwname="dns{$dnscounter}gw";
$olddnsgwname = !empty($config['system'][$dnsgwname]) ? $config['system'][$dnsgwname] : "none" ;
write_config();
if ($ignore_posted_dnsgw[$dnsgwname]) {
$thisdnsgwname = "none";
} else {
$thisdnsgwname = $pconfig[$dnsgwname];
}
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();
// "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]));
}
}
}
}
if ($olddnsallowoverride != $config['system']['dnsallowoverride']) {
configd_run("dns reload");
}
write_config();
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);
......@@ -263,7 +248,6 @@ legacy_html_escape_form_data($pconfig);
include("head.inc");
?>
<body>
<?php include("fbegin.inc"); ?>
......
......@@ -749,6 +749,35 @@ function showchange() {
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;
case "timezone_select":
$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