From f78df07af61ef598e9c3899f5ed16cc4cf8deec4 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Wed, 11 Dec 2019 22:19:00 +0100 Subject: [PATCH] IPsec: refactor tunnel settings page for https://github.com/opnsense/core/issues/3717 --- src/www/vpn_ipsec.php | 272 ++++++++++++++++++------------------------ 1 file changed, 118 insertions(+), 154 deletions(-) diff --git a/src/www/vpn_ipsec.php b/src/www/vpn_ipsec.php index c6038e16f..60ad4e340 100644 --- a/src/www/vpn_ipsec.php +++ b/src/www/vpn_ipsec.php @@ -107,6 +107,27 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { unset($config['ipsec']['phase1'][$p1entrydel]); } + write_config(); + mark_subsystem_dirty('ipsec'); + header(url_safe('Location: /vpn_ipsec.php')); + exit; + } elseif (!empty($_POST['act']) && $_POST['act'] == "delselected" ) { + if (empty($_POST['id']) && isset($_POST['p2entry']) && count($_POST['p2entry'])) { + foreach ($_POST['p2entry'] as $p2entrydel) { + unset($config['ipsec']['phase2'][$p2entrydel]); + } + } + if (empty($_POST['id']) && isset($_POST['p1entry']) && count($_POST['p1entry'])) { + foreach ($_POST['p1entry'] as $p1entrydel) { + $ikeid = $a_phase1[$p1entrydel]['ikeid']; + foreach ($a_phase2 as $p2index => $ph2tmp) { + if ($ph2tmp['ikeid'] == $ikeid) { + unset($a_phase2[$p2index]); + } + } + unset($config['ipsec']['phase1'][$p1entrydel]); + } + } write_config(); mark_subsystem_dirty('ipsec'); header(url_safe('Location: /vpn_ipsec.php')); @@ -114,31 +135,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { } elseif (!empty($_POST['act']) && $_POST['act'] == "delphase2" ) { if (isset($_POST['id']) && isset($config['ipsec']['phase2'][$_POST['id']])){ unset($config['ipsec']['phase2'][$_POST['id']]); - } elseif (empty($_POST['id']) && isset($_POST['p2entry']) && count($_POST['p2entry'])) { - foreach ($_POST['p2entry'] as $p1entrydel) { - unset($config['ipsec']['phase2'][$p1entrydel]); - } } write_config(); mark_subsystem_dirty('ipsec'); header(url_safe('Location: /vpn_ipsec.php')); exit; - } elseif (!empty($_POST['act']) && $_POST['act'] == "movep1" ) { - // move phase 1 records - if (isset($_POST['p1entry']) && count($_POST['p1entry']) > 0) { - // if rule not set/found, move to end - if (!isset($_POST['id']) || !isset($a_phase1[$_POST['id']])) { - $id = count($a_phase1); - } else { - $id = $_POST['id']; - } - $a_phase1 = legacy_move_config_list_items($a_phase1, $id, $_POST['p1entry']); - } - write_config(); - mark_subsystem_dirty('ipsec'); - header(url_safe('Location: /vpn_ipsec.php')); - exit; - } elseif (!empty($_POST['act']) && $_POST['act'] == "movep2" ) { + } elseif (!empty($_POST['act']) && $_POST['act'] == "move" ) { // move phase 2 records if (isset($_POST['p2entry']) && count($_POST['p2entry']) > 0) { // if rule not set/found, move to end @@ -149,6 +151,16 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { } $a_phase2 = legacy_move_config_list_items($a_phase2, $id, $_POST['p2entry']); } + // move phase 1 records + if (isset($_POST['p1entry']) && count($_POST['p1entry']) > 0) { + // if rule not set/found, move to end + if (!isset($_POST['id']) || !isset($a_phase1[$_POST['id']])) { + $id = count($a_phase1); + } else { + $id = $_POST['id']; + } + $a_phase1 = legacy_move_config_list_items($a_phase1, $id, $_POST['p1entry']); + } write_config(); mark_subsystem_dirty('ipsec'); header(url_safe('Location: /vpn_ipsec.php')); @@ -235,52 +247,30 @@ $( document ).ready(function() { $(".act_delete_p1").click(function(event){ event.preventDefault(); var id = $(this).data("id"); - if (id != 'x') { - // delete single - BootstrapDialog.show({ - type:BootstrapDialog.TYPE_DANGER, - title: "", - message: "", - buttons: [{ - label: "", - action: function(dialogRef) { - dialogRef.close(); - }}, { - label: "", - action: function(dialogRef) { - $("#id").val(id); - $("#action").val("delphase1"); - $("#iform").submit() - } - }] + // delete single + BootstrapDialog.show({ + type:BootstrapDialog.TYPE_DANGER, + title: "", + message: "", + buttons: [{ + label: "", + action: function(dialogRef) { + dialogRef.close(); + }}, { + label: "", + action: function(dialogRef) { + $("#id").val(id); + $("#action").val("delphase1"); + $("#iform").submit() + } + }] }); - } else { - // delete selected - BootstrapDialog.show({ - type:BootstrapDialog.TYPE_DANGER, - title: "", - message: "", - buttons: [{ - label: "", - action: function(dialogRef) { - dialogRef.close(); - }}, { - label: "", - action: function(dialogRef) { - $("#id").val(""); - $("#action").val("delphase1"); - $("#iform").submit() - } - }] - }); - } }); // link delete phase 2 buttons $(".act_delete_p2").click(function(event){ - event.preventDefault(); - var id = $(this).data("id"); - if (id != 'x') { + event.preventDefault(); + var id = $(this).data("id"); // delete single BootstrapDialog.show({ type:BootstrapDialog.TYPE_DANGER, @@ -298,13 +288,16 @@ $( document ).ready(function() { $("#iform").submit() } }] - }); - } else { + }); + }); + + $("#act_delete_selected").click(function(event){ + event.preventDefault(); // delete selected BootstrapDialog.show({ type:BootstrapDialog.TYPE_DANGER, title: "", - message: "", + message: "", buttons: [{ label: "", action: function(dialogRef) { @@ -313,23 +306,33 @@ $( document ).ready(function() { label: "", action: function(dialogRef) { $("#id").val(""); - $("#action").val("delphase2"); + $("#action").val("delselected"); $("#iform").submit() } }] }); - } }); - // show phase 2 entries - $(".act_show_p2").click(function(){ - $("#tdph2-"+$(this).data("id")).show(); - $("#shph2but-"+$(this).data("id")).hide(); + $("#collapse_p2").click(function(){ + $(".phase2_tr").toggleClass("hidden"); }); + }); +
@@ -346,25 +349,36 @@ $( document ).ready(function() {
- +
- - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - + @@ -431,7 +445,7 @@ $( document ).ready(function() { - - - - @@ -621,17 +585,17 @@ $( document ).ready(function() { - " data-toggle="tooltip"
  
 ">
  
- @@ -451,10 +465,12 @@ $( document ).ready(function() { + " class="btn btn-default btn-xs" + title="" data-toggle="tooltip"> + +
-
- -
- -