diff --git a/src/www/vpn_openvpn_client.php b/src/www/vpn_openvpn_client.php index f39891205..e477596ea 100644 --- a/src/www/vpn_openvpn_client.php +++ b/src/www/vpn_openvpn_client.php @@ -123,6 +123,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { } } } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { + $pconfig = $_POST; + $input_errors = array(); if (isset($_POST['id']) && isset($a_client[$_POST['id']])) { $id = $_POST['id']; } @@ -132,20 +134,49 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { if ($act == "del") { // remove client - if (!isset($id)) { - header("Location: vpn_openvpn_client.php"); - exit; - } - if (!empty($a_client[$id])) { + if (isset($id)) { openvpn_delete('client', $a_client[$id]); + unset($a_client[$id]); + write_config(); } - unset($a_client[$id]); - write_config(); + header("Location: vpn_openvpn_client.php"); + exit; + } elseif ($act == "del_x") { + if (!empty($pconfig['rule']) && is_array($pconfig['rule'])) { + foreach ($pconfig['rule'] as $rulei) { + if (isset($a_client[$rulei])) { + openvpn_delete('client', $a_client[$rulei]); + unset($a_client[$rulei]); + } + } + write_config(); + } + header("Location: vpn_openvpn_client.php"); + exit; + } elseif ($act == "move"){ + // move selected items + if (!isset($id)) { + // if id not set/found, move to end + $id = count($a_client); + } + $a_client = legacy_move_config_list_items($a_client, $id, $pconfig['rule']); + write_config(); + header("Location: vpn_openvpn_client.php"); + exit; + } elseif ($act == "toggle") { + if (isset($id)) { + if (isset($a_client[$id]['disable'])) { + unset($a_client[$id]['disable']); + } else { + $a_client[$id]['disable'] = true; + } + openvpn_resync('client', $a_client[$id]); + write_config(); + } + header("Location: vpn_openvpn_client.php"); + exit; } else { // update client (after validation) - $pconfig = $_POST; - $input_errors = array(); - if (isset($id)) { $vpnid = $a_client[$id]['vpnid']; } @@ -342,26 +373,63 @@ $( document ).ready(function() { // link delete buttons $(".act_delete").click(function(){ - var id = $(this).attr("id").split('_').pop(-1); - BootstrapDialog.show({ + var id = $(this).data("id"); + if (id != 'x') { + BootstrapDialog.show({ + type:BootstrapDialog.TYPE_DANGER, + title: "", + message: "", + buttons: [{ + label: "", + action: function(dialogRef) { + dialogRef.close(); + }}, { + label: "", + action: function(dialogRef) { + $.post(window.location, {act: 'del', id:id}, function(data) { + location.reload(); + }); + dialogRef.close(); + } + }] + }); + } else { + // delete selected + BootstrapDialog.show({ type:BootstrapDialog.TYPE_DANGER, - title: "", - message: "", + title: "", + message: "", buttons: [{ - label: "", - action: function(dialogRef) { + label: "", + action: function(dialogRef) { dialogRef.close(); - }}, { + }}, { label: "", action: function(dialogRef) { - $.post(window.location, {act: 'del', id:id}, function(data) { - location.reload(); - }); - dialogRef.close(); + $("#id").val(""); + $("#action").val("del_x"); + $("#iform2").submit() } - }] - }); + }] + }); + } }); + + // link toggle buttons + $(".act_toggle").click(function(){ + $.post(window.location, {act: 'toggle', id:$(this).data("id")}, function(data) { + location.reload(); + }); + }); + + // link move buttons + $(".act_move").click(function(){ + $("#id").val($(this).data("id")); + $("#action").val("move"); + $("#iform2").submit(); + }); + + }); @@ -398,18 +466,18 @@ function dev_mode_change() { } function autokey_change() { - if (document.iform.autokey_enable != undefined && document.iform.autokey_enable.checked) - document.getElementById("autokey_opts").style.display="none"; - else + if (document.iform.autokey_enable != undefined && document.iform.autokey_enable.checked) { + document.getElementById("autokey_opts").style.display="none"; + } else { document.getElementById("autokey_opts").style.display=""; + } } function useproxy_changed() { - - if (jQuery('#proxy_authtype').val() != 'none') { - jQuery('#proxy_authtype_opts').show(); + if ($('#proxy_authtype').val() != 'none') { + $('#proxy_authtype_opts').show(); } else { - jQuery('#proxy_authtype_opts').hide(); + $('#proxy_authtype_opts').hide(); } } @@ -439,10 +507,11 @@ else : - if (document.iform.tlsauth_enable.checked && !autocheck) - document.getElementById("autotls_opts").style.display=""; - else - document.getElementById("autotls_opts").style.display="none"; + if (document.iform.tlsauth_enable.checked && !autocheck) { + document.getElementById("autotls_opts").style.display=""; + } else { + document.getElementById("autotls_opts").style.display="none"; + } } //]]> @@ -1006,55 +1075,73 @@ endif; ?> - - - - - - - - - - - + + + +
+ + + + + + + + + + - - - - - - - + $i = 0; + foreach ($a_client as $client) : + $server = "{$client['server_addr']}:{$client['server_port']}";?> + + + + + + + - -
- - - - - - - - - - - - " class="act_delete btn btn-default btn-xs"> - - - "> - - -
+ +   + "> + "> + + + + + + + + + " class="act_move btn btn-default btn-xs"> + + + + + + " class="act_delete btn btn-default btn-xs"> + + + "> + + +
+ $i++; + endforeach;?> + + + + " class="act_move btn btn-default btn-xs"> + + + " data-toggle="tooltip" class="act_delete btn btn-default btn-xs"> + + + + + + +