Commit 90d2e9b0 authored by Ad Schellevis's avatar Ad Schellevis Committed by Franco Fichtner

(legacy) add copy/move to vpn_openvpn_csc.php overview + some js cleanups....

(legacy) add copy/move to vpn_openvpn_csc.php overview + some js cleanups. closes https://github.com/opnsense/core/issues/442

(cherry picked from commit a0587c03)
parent 8f2a5d71
...@@ -53,52 +53,79 @@ $vpnid = 0; ...@@ -53,52 +53,79 @@ $vpnid = 0;
$act=null; $act=null;
if ($_SERVER['REQUEST_METHOD'] === 'GET') { if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$pconfig = array(); $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'])) { if (isset($_GET['act'])) {
$act = $_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 // 1 on 1 copy of config attributes
foreach (explode(",", $all_form_fields) as $fieldname) { foreach (explode(",", $all_form_fields) as $fieldname) {
$fieldname = trim($fieldname); $fieldname = trim($fieldname);
if (isset($a_csc[$id][$fieldname])) { if (isset($a_csc[$configId][$fieldname])) {
$pconfig[$fieldname] = $a_csc[$id][$fieldname]; $pconfig[$fieldname] = $a_csc[$configId][$fieldname];
} elseif (!isset($pconfig[$fieldname])) { } elseif (!isset($pconfig[$fieldname])) {
// initialize element // initialize element
$pconfig[$fieldname] = null; $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;
}
}
}
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
$input_errors = array(); $input_errors = array();
$pconfig = $_POST; $pconfig = $_POST;
if (isset($_POST['act'])) { if (isset($_POST['act'])) {
$act = $_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']; $id = $_POST['id'];
} }
if ($act == "del") { if ($act == "del") {
if (!isset($a_csc[$id])) { if (isset($id)) {
@unlink("/var/etc/openvpn-csc/{$a_csc[$id]['common_name']}");
unset($a_csc[$id]);
write_config();
}
header("Location: vpn_openvpn_csc.php"); header("Location: vpn_openvpn_csc.php");
exit; 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]);
} }
}
@unlink("/var/etc/openvpn-csc/{$a_csc[$id]['common_name']}"); write_config();
unset($a_csc[$id]); }
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(); 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 { } else {
/* perform validations */ /* perform validations */
if ($result = openvpn_validate_cidr($pconfig['tunnel_network'], 'Tunnel network')) { if ($result = openvpn_validate_cidr($pconfig['tunnel_network'], 'Tunnel network')) {
...@@ -178,7 +205,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -178,7 +205,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$csc['disable'] = true; $csc['disable'] = true;
} }
if (isset($id) && $a_csc[$id]) { if (isset($id)) {
$old_csc_cn = $a_csc[$id]['common_name']; $old_csc_cn = $a_csc[$id]['common_name'];
$a_csc[$id] = $csc; $a_csc[$id] = $csc;
} else { } else {
...@@ -201,18 +228,17 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -201,18 +228,17 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
legacy_html_escape_form_data($pconfig); legacy_html_escape_form_data($pconfig);
include("head.inc"); include("head.inc");
?> ?>
<body> <body>
<script type="text/javascript"> <script type="text/javascript">
//<![CDATA[ //<![CDATA[
$( document ).ready(function() { $( document ).ready(function() {
// link delete buttons // link delete buttons
$(".act_delete").click(function(){ $(".act_delete").click(function(){
var id = $(this).attr("id").split('_').pop(-1); var id = $(this).data("id");
if (id != 'x') {
BootstrapDialog.show({ BootstrapDialog.show({
type:BootstrapDialog.TYPE_DANGER, type:BootstrapDialog.TYPE_DANGER,
title: "<?= gettext("OpenVPN");?>", title: "<?= gettext("OpenVPN");?>",
...@@ -231,66 +257,94 @@ $( document ).ready(function() { ...@@ -231,66 +257,94 @@ $( document ).ready(function() {
} }
}] }]
}); });
} else {
// delete selected
BootstrapDialog.show({
type:BootstrapDialog.TYPE_DANGER,
title: "<?=gettext("OpenVPN");?>",
message: "<?=gettext("Do you really want to delete the selected csc's?");?>",
buttons: [{
label: "<?= gettext("No");?>",
action: function(dialogRef) {
dialogRef.close();
}}, {
label: "<?= gettext("Yes");?>",
action: function(dialogRef) {
$("#id").val("");
$("#action").val("del_x");
$("#iform2").submit()
}
}]
}); });
// init form (old stuff)
if (document.iform != undefined) {
dns_domain_change();
dns_server_change();
wins_server_change();
ntp_server_change();
netbios_change();
} }
});
// 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"));
function dns_domain_change() { $("#action").val("move");
$("#iform2").submit();
});
if (document.iform.dns_domain_enable.checked) { // checkboxes
document.getElementById("dns_domain_data").style.display=""; $("#dns_domain_enable").change(function(){
if ($("#dns_domain_enable").is(":checked")) {
$("#dns_domain_data").show();
} else { } else {
document.getElementById("dns_domain_data").style.display="none"; $("#dns_domain_data").hide();
} }
} });
function dns_server_change() {
if (document.iform.dns_server_enable.checked) { $("#dns_server_enable").change(function(){
document.getElementById("dns_server_data").style.display=""; if ($("#dns_server_enable").is(":checked")) {
$("#dns_server_data").show();
} else { } else {
document.getElementById("dns_server_data").style.display="none"; $("#dns_server_data").hide();
} }
} });
function wins_server_change() {
if (document.iform.wins_server_enable.checked) { $("#wins_server_enable").change(function(){
document.getElementById("wins_server_data").style.display=""; if ($("#wins_server_enable").is(":checked")) {
$("#wins_server_data").show();
} else { } else {
document.getElementById("wins_server_data").style.display="none"; $("#wins_server_data").hide();
} }
} });
function ntp_server_change() { $("#ntp_server_enable").change(function(){
if ($("#ntp_server_enable").is(":checked")) {
$("#ntp_server_data").show();
} else {
$("#ntp_server_data").hide();
}
});
if (document.iform.ntp_server_enable.checked) { $("#netbios_enable").change(function(){
document.getElementById("ntp_server_data").style.display=""; if ($("#netbios_enable").is(":checked")) {
$("#netbios_data").show();
$("#wins_opts").show();
} else { } else {
document.getElementById("ntp_server_data").style.display="none"; $("#netbios_data").hide();
$("#wins_opts").hide();
} }
} });
function netbios_change() {
if (document.iform.netbios_enable.checked) { // init form (old stuff)
document.getElementById("netbios_data").style.display=""; if (document.iform != undefined) {
document.getElementById("wins_opts").style.display=""; $("#dns_domain_enable").change();
} else { $("#dns_server_enable").change();
document.getElementById("netbios_data").style.display="none"; $("#wins_server_enable").change();
document.getElementById("wins_opts").style.display="none"; $("#ntp_server_enable").change();
} }
}
});
//]]> //]]>
</script> </script>
...@@ -317,7 +371,7 @@ if ($act!="new" && $act!="edit") { ...@@ -317,7 +371,7 @@ if ($act!="new" && $act!="edit") {
<div class="tab-content content-box col-xs-12"> <div class="tab-content content-box col-xs-12">
<?php <?php
if ($act=="new" || $act=="edit") :?> if ($act=="new" || $act=="edit") :?>
<form action="vpn_openvpn_csc.php" method="post" name="iform" id="iform"> <form method="post" name="iform" id="iform">
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-striped"> <table class="table table-striped">
<tr> <tr>
...@@ -471,7 +525,7 @@ if ($act!="new" && $act!="edit") { ...@@ -471,7 +525,7 @@ if ($act!="new" && $act!="edit") {
<td width="22%"><a id="help_for_dns_domain" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("DNS Default Domain"); ?></td> <td width="22%"><a id="help_for_dns_domain" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("DNS Default Domain"); ?></td>
<td width="78%"> <td width="78%">
<input name="dns_domain_enable" type="checkbox" id="dns_domain_enable" value="yes" <?= !empty($pconfig['dns_domain']) ? "checked=\"checked\"" : "";?> onclick="dns_domain_change()" /> <input name="dns_domain_enable" type="checkbox" id="dns_domain_enable" value="yes" <?= !empty($pconfig['dns_domain']) ? "checked=\"checked\"" : "";?> onclick="dns_domain_change()" />
<div id="dns_domain_data"> <div id="dns_domain_data" style="display:none">
<input name="dns_domain" type="text" id="dns_domain" value="<?=$pconfig['dns_domain'];?>" /> <input name="dns_domain" type="text" id="dns_domain" value="<?=$pconfig['dns_domain'];?>" />
</div> </div>
<div class="hidden" for="help_for_dns_domain"> <div class="hidden" for="help_for_dns_domain">
...@@ -483,7 +537,7 @@ if ($act!="new" && $act!="edit") { ...@@ -483,7 +537,7 @@ if ($act!="new" && $act!="edit") {
<td width="22%"><a id="help_for_dns_server" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("DNS Servers"); ?></td> <td width="22%"><a id="help_for_dns_server" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("DNS Servers"); ?></td>
<td width="78%"> <td width="78%">
<input name="dns_server_enable" type="checkbox" id="dns_server_enable" value="yes" <?=!empty($pconfig['dns_server1']) || !empty($pconfig['dns_server2']) || !empty($pconfig['dns_server3']) || !empty($pconfig['dns_server4']) ? "checked=\"checked\"" : "" ;?> onclick="dns_server_change()" /> <input name="dns_server_enable" type="checkbox" id="dns_server_enable" value="yes" <?=!empty($pconfig['dns_server1']) || !empty($pconfig['dns_server2']) || !empty($pconfig['dns_server3']) || !empty($pconfig['dns_server4']) ? "checked=\"checked\"" : "" ;?> onclick="dns_server_change()" />
<div id="dns_server_data"> <div id="dns_server_data" style="display:none">
<?=gettext("Server #1:"); ?>&nbsp; <?=gettext("Server #1:"); ?>&nbsp;
<input name="dns_server1" type="text" id="dns_server1" size="20" value="<?=htmlspecialchars($pconfig['dns_server1']);?>" /> <input name="dns_server1" type="text" id="dns_server1" size="20" value="<?=htmlspecialchars($pconfig['dns_server1']);?>" />
<?=gettext("Server #2:"); ?>&nbsp; <?=gettext("Server #2:"); ?>&nbsp;
...@@ -502,7 +556,7 @@ if ($act!="new" && $act!="edit") { ...@@ -502,7 +556,7 @@ if ($act!="new" && $act!="edit") {
<td width="22%"><a id="help_for_ntp_server" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("NTP Servers"); ?></td> <td width="22%"><a id="help_for_ntp_server" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("NTP Servers"); ?></td>
<td width="78%"> <td width="78%">
<input name="ntp_server_enable" type="checkbox" id="ntp_server_enable" value="yes" <?=!empty($pconfig['ntp_server1']) || !empty($pconfig['ntp_server2']) ? "checked=\"checked\"" : "" ;?> onclick="ntp_server_change()" /> <input name="ntp_server_enable" type="checkbox" id="ntp_server_enable" value="yes" <?=!empty($pconfig['ntp_server1']) || !empty($pconfig['ntp_server2']) ? "checked=\"checked\"" : "" ;?> onclick="ntp_server_change()" />
<div id="ntp_server_data"> <div id="ntp_server_data" style="display:none">
<?=gettext("Server #1:"); ?>&nbsp; <?=gettext("Server #1:"); ?>&nbsp;
<input name="ntp_server1" type="text" id="ntp_server1" size="20" value="<?=$pconfig['ntp_server1'];?>" /> <input name="ntp_server1" type="text" id="ntp_server1" size="20" value="<?=$pconfig['ntp_server1'];?>" />
<?=gettext("Server #2:"); ?>&nbsp; <?=gettext("Server #2:"); ?>&nbsp;
...@@ -557,7 +611,7 @@ if ($act!="new" && $act!="edit") { ...@@ -557,7 +611,7 @@ if ($act!="new" && $act!="edit") {
<td width="22%"><a id="help_for_wins_server" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("WINS Servers"); ?></td> <td width="22%"><a id="help_for_wins_server" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("WINS Servers"); ?></td>
<td width="78%"> <td width="78%">
<input name="wins_server_enable" type="checkbox" id="wins_server_enable" value="yes" <?=!empty($pconfig['wins_server1']) || !empty($pconfig['wins_server2']) ? "checked=\"checked\"" : "" ;?> onclick="wins_server_change()" /> <input name="wins_server_enable" type="checkbox" id="wins_server_enable" value="yes" <?=!empty($pconfig['wins_server1']) || !empty($pconfig['wins_server2']) ? "checked=\"checked\"" : "" ;?> onclick="wins_server_change()" />
<div id="wins_server_data"> <div id="wins_server_data" style="display:none">
<?=gettext("Server #1:"); ?> <?=gettext("Server #1:"); ?>
<input name="wins_server1" type="text" id="wins_server1" size="20" value="<?=$pconfig['wins_server1'];?>" /> <input name="wins_server1" type="text" id="wins_server1" size="20" value="<?=$pconfig['wins_server1'];?>" />
<?=gettext("Server #2:"); ?> <?=gettext("Server #2:"); ?>
...@@ -584,8 +638,8 @@ if ($act!="new" && $act!="edit") { ...@@ -584,8 +638,8 @@ if ($act!="new" && $act!="edit") {
<input name="save" type="submit" class="btn btn-primary" value="<?=gettext("Save"); ?>" /> <input name="save" type="submit" class="btn btn-primary" value="<?=gettext("Save"); ?>" />
<input name="act" type="hidden" value="<?=$act;?>" /> <input name="act" type="hidden" value="<?=$act;?>" />
<?php <?php
if (isset($id) && $a_csc[$id]) :?> if (isset($id)) :?>
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" /> <input name="id" type="hidden" value="<?=$id;?>" />
<?php <?php
endif; ?> endif; ?>
</td> </td>
...@@ -595,34 +649,47 @@ if ($act!="new" && $act!="edit") { ...@@ -595,34 +649,47 @@ if ($act!="new" && $act!="edit") {
</form> </form>
<?php <?php
else :?> else :?>
<form method="post" name="iform2" id="iform2">
<input type="hidden" id="id" name="id" value="" />
<input type="hidden" id="action" name="act" value="" />
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-striped"> <table class="table table-striped">
<tr> <tr>
<td><?=gettext("Disabled"); ?></td> <td></td>
<td><?=gettext("Common Name"); ?></td> <td><?=gettext("Common Name"); ?></td>
<td><?=gettext("Tunnel Network");?></td>
<td><?=gettext("Description"); ?></td> <td><?=gettext("Description"); ?></td>
<td></td> <td></td>
</tr> </tr>
<?php <?php
$i = 0; $i = 0;
foreach ($a_csc as $csc) : foreach ($a_csc as $csc):?>
$disabled = "NO"; <tr>
if (isset($csc['disable'])) {
$disabled = "YES";
}?>
<tr ondblclick="document.location='vpn_openvpn_csc.php?act=edit&amp;id=<?=$i;?>'">
<td> <td>
<?=$disabled;?> <input type="checkbox" name="rule[]" value="<?=$i;?>" />
&nbsp;
<a href="#" class="act_toggle" data-id="<?=$i;?>" data-toggle="tooltip" title="<?=(empty($csc['disable'])) ? gettext("disable") : gettext("enable");?>">
<span class="glyphicon glyphicon-play <?=(empty($csc['disable'])) ? "text-success" : "text-muted";?>"></span>
</a>
</td> </td>
<td> <td>
<?=htmlspecialchars($csc['common_name']);?> <?=htmlspecialchars($csc['common_name']);?>
</td> </td>
<td>
<?=!empty($csc['tunnel_network']) ? htmlspecialchars($csc['tunnel_network']) : "";?>
</td>
<td> <td>
<?=htmlspecialchars($csc['description']);?> <?=htmlspecialchars($csc['description']);?>
</td> </td>
<td> <td>
<a data-id="<?=$i;?>" data-toggle="tooltip" title="<?=gettext("move selected before this item");?>" class="act_move btn btn-default btn-xs">
<span class="glyphicon glyphicon-arrow-left"></span>
</a>
<a href="vpn_openvpn_csc.php?act=edit&amp;id=<?=$i;?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil"></span></a> <a href="vpn_openvpn_csc.php?act=edit&amp;id=<?=$i;?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil"></span></a>
<a id="del_<?=$i;?>" title="<?=gettext("delete csc"); ?>" class="act_delete btn btn-default btn-xs"><span class="fa fa-trash text-muted"></span></a> <a data-id="<?=$i;?>" title="<?=gettext("delete csc"); ?>" class="act_delete btn btn-default btn-xs"><span class="fa fa-trash text-muted"></span></a>
<a href="vpn_openvpn_csc.php?act=new&dup=<?=$i;?>" class="btn btn-default btn-xs" data-toggle="tooltip" title="<?=gettext("clone rule");?>">
<span class="fa fa-clone text-muted"></span>
</a>
</td> </td>
</tr> </tr>
<?php <?php
...@@ -630,13 +697,20 @@ if ($act!="new" && $act!="edit") { ...@@ -630,13 +697,20 @@ if ($act!="new" && $act!="edit") {
endforeach;?> endforeach;?>
<tr> <tr>
<td colspan="4"> <td colspan="4">
<p>
<?=gettext("Additional OpenVPN client specific overrides can be added here.");?> <?=gettext("Additional OpenVPN client specific overrides can be added here.");?>
</p> </td>
<td>
<a type="submit" data-id="<?=$i;?>" data-toggle="tooltip" title="<?=gettext("move selected items to end");?>" class="act_move btn btn-default btn-xs">
<span class="glyphicon glyphicon-arrow-left"></span>
</a>
<a data-id="x" title="<?=gettext("delete selected rules"); ?>" data-toggle="tooltip" class="act_delete btn btn-default btn-xs">
<span class="fa fa-trash text-muted"></span>
</a>
</td> </td>
</tr> </tr>
</table> </table>
</div> </div>
</form>
<?php <?php
endif; ?> endif; ?>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment