From 495c7f0c8e750d6630f72114fc794d5ce20b1bff Mon Sep 17 00:00:00 2001 From: Renato Botelho Date: Thu, 4 Sep 2014 12:12:00 -0300 Subject: Replace all GET use by POST --- usr/local/www/vpn_ipsec.php | 155 ++++++++++++++++++++------------------------ 1 file changed, 72 insertions(+), 83 deletions(-) diff --git a/usr/local/www/vpn_ipsec.php b/usr/local/www/vpn_ipsec.php index a1af171..c592a3a 100644 --- a/usr/local/www/vpn_ipsec.php +++ b/usr/local/www/vpn_ipsec.php @@ -97,13 +97,25 @@ if ($_POST) { } } else { /* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */ - unset($movebtn); + unset($delbtn, $delbtnp2, $movebtn, $movebtnp2, $togglebtn, $togglebtnp2); foreach ($_POST as $pn => $pd) { - if (preg_match("/move_(\d+)_x/", $pn, $matches)) { + if (preg_match("/del_(\d+)_x/", $pn, $matches)) { + $delbtn = $matches[1]; + } else if (preg_match("/delp2_(\d+)_x/", $pn, $matches)) { + $delbtnp2 = $matches[1]; + } else if (preg_match("/move_(\d+)_x/", $pn, $matches)) { $movebtn = $matches[1]; - break; + } else if (preg_match("/movep2_(\d+)_x/", $pn, $matches)) { + $movebtnp2 = $matches[1]; + } else if (preg_match("/toggle_(\d+)_x/", $pn, $matches)) { + $togglebtn = $matches[1]; + } else if (preg_match("/togglep2_(\d+)_x/", $pn, $matches)) { + $togglebtnp2 = $matches[1]; } } + + $save = 1; + /* move selected p1 entries before this */ if (isset($movebtn) && is_array($_POST['p1entry']) && count($_POST['p1entry'])) { $a_phase1_new = array(); @@ -134,104 +146,75 @@ if ($_POST) { if (count($a_phase1_new) > 0) $a_phase1 = $a_phase1_new; - if (write_config()) - mark_subsystem_dirty('ipsec'); - header("Location: vpn_ipsec.php"); - exit; - } - - unset($movebtn); - foreach ($_POST as $pn => $pd) { - if (preg_match("/movep2_(\d+)_x/", $pn, $matches)) { - $movebtn = $matches[1]; - break; - } - } - /* move selected p2 entries before this */ - if (isset($movebtn) && is_array($_POST['p2entry']) && count($_POST['p2entry'])) { + } else if (isset($movebtnp2) && is_array($_POST['p2entry']) && count($_POST['p2entry'])) { + /* move selected p2 entries before this */ $a_phase2_new = array(); - /* copy all p2 entries < $movebtn and not selected */ - for ($i = 0; $i < $movebtn; $i++) { + /* copy all p2 entries < $movebtnp2 and not selected */ + for ($i = 0; $i < $movebtnp2; $i++) { if (!in_array($i, $_POST['p2entry'])) $a_phase2_new[] = $a_phase2[$i]; } /* copy all selected p2 entries */ for ($i = 0; $i < count($a_phase2); $i++) { - if ($i == $movebtn) + if ($i == $movebtnp2) continue; if (in_array($i, $_POST['p2entry'])) $a_phase2_new[] = $a_phase2[$i]; } - /* copy $movebtn p2 entry */ - if ($movebtn < count($a_phase2)) - $a_phase2_new[] = $a_phase2[$movebtn]; + /* copy $movebtnp2 p2 entry */ + if ($movebtnp2 < count($a_phase2)) + $a_phase2_new[] = $a_phase2[$movebtnp2]; - /* copy all p2 entries > $movebtn and not selected */ - for ($i = $movebtn+1; $i < count($a_phase2); $i++) { + /* copy all p2 entries > $movebtnp2 and not selected */ + for ($i = $movebtnp2+1; $i < count($a_phase2); $i++) { if (!in_array($i, $_POST['p2entry'])) $a_phase2_new[] = $a_phase2[$i]; } if (count($a_phase2_new) > 0) $a_phase2 = $a_phase2_new; - if (write_config()) - mark_subsystem_dirty('ipsec'); - header("Location: vpn_ipsec.php"); - exit; - } - } -} + } else if (isset($togglebtn)) { + if (isset($a_phase1[$togglebtn]['disabled'])) + unset($a_phase1[$togglebtn]['disabled']); + else + $a_phase1[$togglebtn]['disabled'] = true; -if (isset($_GET['p1index']) && is_numericint($_GET['p1index']) && isset($a_phase1[$_GET['p1index']])) { - if ($_GET['act'] == "delph1") { - /* remove static route if interface is not WAN */ - if ($a_phase1[$_GET['p1index']]['interface'] <> "wan") - mwexec("/sbin/route delete -host {$a_phase1[$_GET['p1index']]['remote-gateway']}"); - - /* remove all phase2 entries that match the ikeid */ - $ikeid = $a_phase1[$_GET['p1index']]['ikeid']; - foreach ($a_phase2 as $p2index => $ph2tmp) - if ($ph2tmp['ikeid'] == $ikeid) { - unset($a_phase2[$p2index]); - } + } else if (isset($togglebtnp2)) { + if (isset($a_phase2[$togglebtnp2]['disabled'])) + unset($a_phase2[$togglebtnp2]['disabled']); + else + $a_phase2[$togglebtnp2]['disabled'] = true; - /* remove the phase1 entry */ - unset($a_phase1[$_GET['p1index']]); - write_config(); - mark_subsystem_dirty('ipsec'); - } else if ($_GET['act'] == "delph2") { - /* remove the phase2 entry */ - unset($a_phase2[$_GET['p2index']]); - write_config(); - mark_subsystem_dirty('ipsec'); - } else if ($_GET['act'] == "toggle") { - if (isset($a_phase1[$_GET['p1index']]['disabled'])) - unset($a_phase1[$_GET['p1index']]['disabled']); - else - $a_phase1[$_GET['p1index']]['disabled'] = true; + } else if (isset($delbtn)) { + /* remove static route if interface is not WAN */ + if ($a_phase1[$delbtn]['interface'] <> "wan") + mwexec("/sbin/route delete -host {$a_phase1[$delbtn]['remote-gateway']}"); - write_config(); - mark_subsystem_dirty('ipsec'); - } + /* remove all phase2 entries that match the ikeid */ + $ikeid = $a_phase1[$delbtn]['ikeid']; + foreach ($a_phase2 as $p2index => $ph2tmp) + if ($ph2tmp['ikeid'] == $ikeid) { + unset($a_phase2[$p2index]); + } - header("Location: vpn_ipsec.php"); - exit; -} else if (isset($_GET['p2index']) && is_numericint($_GET['p2index']) && isset($a_phase2[$_GET['p2index']])) { - if ($_GET['act'] == "togglep2") { - if (isset($a_phase2[$_GET['p2index']]['disabled'])) - unset($a_phase2[$_GET['p2index']]['disabled']); - else - $a_phase2[$_GET['p2index']]['disabled'] = true; + unset($a_phase1[$delbtn]); - write_config(); - mark_subsystem_dirty('ipsec'); - } + } else if (isset($delbtnp2)) { + unset($a_phase2[$delbtnp2]); - header("Location: vpn_ipsec.php"); - exit; + } else + $save = 0; + + if ($save === 1) { + if (write_config()) + mark_subsystem_dirty('ipsec'); + header("Location: vpn_ipsec.php"); + exit; + } + } } $pgtitle = array(gettext("VPN"),gettext("IPsec")); @@ -317,7 +300,9 @@ include("head.inc"); - " alt="icon" /> + " + type="image" style="height:11;width:11;border:0" /> @@ -408,9 +393,10 @@ include("head.inc"); - ')"> - " width="17" height="17" border="0" alt="delete" /> - + " + type="image" style="height:17;width:17;border:0" + onclick="return confirm('')" /> " name="p2entry[]" value="" onclick="fr_bgcolor('', '')" style="margin: 0; padding: 0; width: 15px; height: 15px;" /> - " alt="icon" /> + " + type="image" style="height:11;width:11;border:0" /> @@ -547,9 +535,10 @@ include("head.inc"); " width="17" height="17" border="0" alt="edit" /> - ')"> - " width="17" height="17" border="0" alt="delete" /> - + " + type="image" style="height:17;width:17;border:0" + onclick="return confirm('')" /> " width="17" height="17" border="0" alt="add" /> -- cgit v1.1