diff --git a/src/www/vpn_openvpn_csc.php b/src/www/vpn_openvpn_csc.php index fb717a785..893f0e7cc 100644 --- a/src/www/vpn_openvpn_csc.php +++ b/src/www/vpn_openvpn_csc.php @@ -53,31 +53,25 @@ $vpnid = 0; $act=null; if ($_SERVER['REQUEST_METHOD'] === 'GET') { $pconfig = array(); + if (isset($_GET['dup']) && isset($a_csc[$_GET['dup']])) { + $configId = $_GET['dup']; + } elseif (isset($_GET['id']) && isset($a_csc[$_GET['id']])) { + $id = $_GET['id']; + $configId = $id; + } + if (isset($_GET['act'])) { $act = $_GET['act']; } - if (isset($_GET['id']) && is_numericint($_GET['id'])) { - $id = $_GET['id']; - } - if ($act=="edit" && isset($id) && isset($a_csc[$id])) { - // 1 on 1 copy of config attributes - foreach (explode(",", $all_form_fields) as $fieldname) { - $fieldname = trim($fieldname); - if (isset($a_csc[$id][$fieldname])) { - $pconfig[$fieldname] = $a_csc[$id][$fieldname]; - } elseif (!isset($pconfig[$fieldname])) { - // initialize element - $pconfig[$fieldname] = null; - } - } - } else { - // init all form attributes - foreach (explode(",", $all_form_fields) as $fieldname) { - $fieldname = trim($fieldname); - if (!isset($pconfig[$fieldname])) { - $pconfig[$fieldname] = null; - } + // 1 on 1 copy of config attributes + foreach (explode(",", $all_form_fields) as $fieldname) { + $fieldname = trim($fieldname); + if (isset($a_csc[$configId][$fieldname])) { + $pconfig[$fieldname] = $a_csc[$configId][$fieldname]; + } elseif (!isset($pconfig[$fieldname])) { + // initialize element + $pconfig[$fieldname] = null; } } } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { @@ -86,19 +80,52 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { if (isset($_POST['act'])) { $act = $_POST['act']; } - if (isset($_POST['id']) && is_numericint($_POST['id'])) { + if (isset($_POST['id']) && isset($a_csc[$_POST['id']])) { $id = $_POST['id']; } if ($act == "del") { - if (!isset($a_csc[$id])) { - header("Location: vpn_openvpn_csc.php"); - exit; + if (isset($id)) { + @unlink("/var/etc/openvpn-csc/{$a_csc[$id]['common_name']}"); + unset($a_csc[$id]); + write_config(); } - - @unlink("/var/etc/openvpn-csc/{$a_csc[$id]['common_name']}"); - unset($a_csc[$id]); - write_config(); + header("Location: vpn_openvpn_csc.php"); + exit; + } elseif ($act == "del_x") { + if (!empty($pconfig['rule']) && is_array($pconfig['rule'])) { + foreach ($pconfig['rule'] as $rulei) { + if (isset($a_csc[$rulei])) { + @unlink("/var/etc/openvpn-csc/{$a_csc[$rulei]['common_name']}"); + unset($a_csc[$rulei]); + } + } + write_config(); + } + header("Location: vpn_openvpn_csc.php"); + exit; + } elseif ($act == "move"){ + // move selected items + if (!isset($id)) { + // if id not set/found, move to end + $id = count($a_csc); + } + $a_csc = legacy_move_config_list_items($a_csc, $id, $pconfig['rule']); + write_config(); + header("Location: vpn_openvpn_csc.php"); + exit; + } elseif ($act == "toggle") { + if (isset($id)) { + if (isset($a_csc[$id]['disable'])) { + unset($a_csc[$id]['disable']); + } else { + $a_csc[$id]['disable'] = true; + } + openvpn_resync_csc($a_csc[$id]); + write_config(); + } + header("Location: vpn_openvpn_csc.php"); + exit; } else { /* perform validations */ if ($result = openvpn_validate_cidr($pconfig['tunnel_network'], 'Tunnel network')) { @@ -178,7 +205,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $csc['disable'] = true; } - if (isset($id) && $a_csc[$id]) { + if (isset($id)) { $old_csc_cn = $a_csc[$id]['common_name']; $a_csc[$id] = $csc; } else { @@ -201,96 +228,123 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { legacy_html_escape_form_data($pconfig); include("head.inc"); - ?>
@@ -317,7 +371,7 @@ if ($act!="new" && $act!="edit") {