Skip to content

Commit

Permalink
Handle IPsec Advanced Settings save before IPsec is enabled
Browse files Browse the repository at this point in the history
If the Advanced Settings are saved before any other IPsec is set up then $config['ipsec'] can be just the empty string. As a result you can get:
a) If you select some debug settings then those are not saved. The code to save those settings was only executed when $config['ipsec'] was already an array. Actually the code already did the necessary "if isset() then unset()" stuuf. So I just took the the "if is_array()" away from the code block.

b) Some potential unset() can go wrong with errors like:
Fatal error: Cannot unset string offsets in /usr/local/www/vpn_ipsec_settings.php on line 168
This is corrected by adding more "if (isset())" checks.

Fixes Redmine #4865
Conflicts:
	usr/local/www/vpn_ipsec_settings.php
  • Loading branch information
Phil Davis authored and Chris Buechler committed Jul 22, 2015
1 parent 5bded42 commit b3bcc72
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions usr/local/www/vpn_ipsec_settings.php
Expand Up @@ -118,13 +118,13 @@

if (!$input_errors) {

if (is_array($config['ipsec'])) {
foreach ($ipsec_loglevels as $lkey => $ldescr) {
if (empty($_POST["ipsec_{$lkey}"])) {
if (isset($config['ipsec']["ipsec_{$lkey}"]))
unset($config['ipsec']["ipsec_{$lkey}"]);
} else
$config['ipsec']["ipsec_{$lkey}"] = $_POST["ipsec_{$lkey}"];
foreach ($ipsec_loglevels as $lkey => $ldescr) {
if (empty($_POST["ipsec_{$lkey}"])) {
if (isset($config['ipsec']["ipsec_{$lkey}"])) {
unset($config['ipsec']["ipsec_{$lkey}"]);
}
} else {
$config['ipsec']["ipsec_{$lkey}"] = $_POST["ipsec_{$lkey}"];
}
}

Expand Down Expand Up @@ -164,8 +164,10 @@
}

/* The wierd logic here is to avoid negative policies when checked #4655 */
if($_POST['noshuntlaninterfaces'] == "yes") {
unset($config['ipsec']['noshuntlaninterfaces']);
if ($_POST['noshuntlaninterfaces'] == "yes") {
if (isset($config['ipsec']['noshuntlaninterfaces'])) {
unset($config['ipsec']['noshuntlaninterfaces']);
}
} else {
$config['ipsec']['noshuntlaninterfaces'] = true;
}
Expand All @@ -181,16 +183,20 @@

if(!empty($_POST['uniqueids'])) {
$config['ipsec']['uniqueids'] = $_POST['uniqueids'];
} else {
} else if (isset($config['ipsec']['uniqueids'])) {
unset($config['ipsec']['uniqueids']);
}

if($_POST['maxmss_enable'] == "yes") {
$config['system']['maxmss_enable'] = true;
$config['system']['maxmss'] = $_POST['maxmss'];
} else {
unset($config['system']['maxmss_enable']);
unset($config['system']['maxmss']);
if (isset($config['system']['maxmss_enable'])) {
unset($config['system']['maxmss_enable']);
}
if (isset($config['system']['maxmss'])) {
unset($config['system']['maxmss']);
}
}

write_config();
Expand Down

0 comments on commit b3bcc72

Please sign in to comment.