Commit 96dfff26 authored by Ad Schellevis's avatar Ad Schellevis

(legacy) refactor vpn_ipsec_keys.php

parent 575c202e
...@@ -39,19 +39,22 @@ if (!is_array($config['ipsec'])) { ...@@ -39,19 +39,22 @@ if (!is_array($config['ipsec'])) {
if (!is_array($config['ipsec']['mobilekey'])) { if (!is_array($config['ipsec']['mobilekey'])) {
$config['ipsec']['mobilekey'] = array(); $config['ipsec']['mobilekey'] = array();
} else {
ipsec_mobilekey_sort();
} }
ipsec_mobilekey_sort();
$a_secret = &$config['ipsec']['mobilekey'];
$userkeys = array(); if ($_SERVER['REQUEST_METHOD'] === 'POST') {
foreach ($config['system']['user'] as $id => $user) { if (isset($_POST['act']) && isset($_POST['id']) && is_numericint($_POST['id']) && $_POST['act'] == "del") {
if (!empty($user['ipsecpsk'])) { // delete entry
$userkeys[] = array('ident' => $user['name'], 'pre-shared-key' => $user['ipsecpsk'], 'id' => $id); if (isset($config['ipsec']['mobilekey'][$_POST['id']])) {
; unset($config['ipsec']['mobilekey'][$_POST['id']]);
write_config(gettext("Deleted IPsec Pre-Shared Key"));
mark_subsystem_dirty('ipsec');
header("Location: vpn_ipsec_keys.php");
exit;
} }
} } elseif (isset($_POST['apply'])) {
// apply changes
if (isset($_POST['apply'])) {
$retval = vpn_ipsec_configure(); $retval = vpn_ipsec_configure();
/* reload the filter in the background */ /* reload the filter in the background */
filter_configure(); filter_configure();
...@@ -59,13 +62,8 @@ if (isset($_POST['apply'])) { ...@@ -59,13 +62,8 @@ if (isset($_POST['apply'])) {
if (is_subsystem_dirty('ipsec')) { if (is_subsystem_dirty('ipsec')) {
clear_subsystem_dirty('ipsec'); clear_subsystem_dirty('ipsec');
} }
} } else {
// nothing to post, redirect
if ($_GET['act'] == "del") {
if ($a_secret[$_GET['id']]) {
unset($a_secret[$_GET['id']]);
write_config(gettext("Deleted IPsec Pre-Shared Key"));
mark_subsystem_dirty('ipsec');
header("Location: vpn_ipsec_keys.php"); header("Location: vpn_ipsec_keys.php");
exit; exit;
} }
...@@ -75,18 +73,43 @@ $pgtitle = gettext("VPN: IPsec: Keys"); ...@@ -75,18 +73,43 @@ $pgtitle = gettext("VPN: IPsec: Keys");
$shortcut_section = "ipsec"; $shortcut_section = "ipsec";
include("head.inc"); include("head.inc");
?> ?>
<script type="text/javascript">
$( document ).ready(function() {
// link delete buttons
$(".act_delete").click(function(){
var id = $(this).attr("id").split('_').pop(-1);
BootstrapDialog.show({
type:BootstrapDialog.TYPE_INFO,
title: "<?= gettext("IPsec");?>",
message: "<?= gettext("Do you really want to delete this Pre-Shared Key?");?>",
buttons: [{
label: "<?= gettext("No");?>",
action: function(dialogRef) {
dialogRef.close();
}}, {
label: "<?= gettext("Yes");?>",
action: function(dialogRef) {
$.post(window.location, {act: 'del', id:id}, function(data) {
location.reload();
});
dialogRef.close();
}
}]
});
});
});
</script>
<body> <body>
<?php include("fbegin.inc"); ?> <?php include("fbegin.inc"); ?>
<section class="page-content-main"> <section class="page-content-main">
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <div class="row">
<?php
<?php
if (isset($savemsg)) { if (isset($savemsg)) {
print_info_box($savemsg); print_info_box($savemsg);
} }
...@@ -94,106 +117,78 @@ include("head.inc"); ...@@ -94,106 +117,78 @@ include("head.inc");
print_info_box_np(gettext("The IPsec tunnel configuration has been changed") . ".<br />" . gettext("You must apply the changes in order for them to take effect.")); print_info_box_np(gettext("The IPsec tunnel configuration has been changed") . ".<br />" . gettext("You must apply the changes in order for them to take effect."));
} }
?> ?>
<section class="col-xs-12"> <section class="col-xs-12">
<?php
<? $active_tab = "/vpn_ipsec_settings.php"; $active_tab = "/vpn_ipsec_settings.php";
include('vpn_ipsec_tabs.inc'); ?> include('vpn_ipsec_tabs.inc');
?>
<div class="tab-content content-box col-xs-12"> <div class="tab-content content-box col-xs-12">
<form action="vpn_ipsec_keys.php" method="post"> <form action="vpn_ipsec_keys.php" method="post">
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-striped table-sort"> <table class="table table-striped">
<tr> <tr>
<td class="listhdrr"><?=gettext("Identifier"); ?></td> <td><?=gettext("Identifier"); ?></td>
<td class="listhdr"><?=gettext("Pre-Shared Key"); ?></td> <td><?=gettext("Pre-Shared Key"); ?></td>
<td class="list"> <td>
<table border="0" cellspacing="0" cellpadding="1" summary="add key"> <a href="vpn_ipsec_keys_edit.php" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-plus"></span></a>
<tr>
<td width="20" height="17"></td>
<td><a href="vpn_ipsec_keys_edit.php" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-plus"></span></a></td>
</tr>
</table>
</td> </td>
</tr> </tr>
<?php $i = 0; foreach ($userkeys as $secretent) : <?php $i = 0;
$userkeys = array();
foreach ($config['system']['user'] as $id => $user) {
if (!empty($user['ipsecpsk'])) {
$userkeys[] = array('ident' => $user['name'], 'pre-shared-key' => $user['ipsecpsk'], 'id' => $id);
;
}
}
foreach ($userkeys as $secretent) :
?> ?>
<tr> <tr>
<td class="listlr gray"> <td>
<?php <?=$secretent['ident'] == 'allusers' ? gettext("ANY USER") : htmlspecialchars($secretent['ident']) ;?>
if ($secretent['ident'] == 'allusers') {
echo gettext("ANY USER");
} else {
echo htmlspecialchars($secretent['ident']);
}
?>
</td> </td>
<td class="listr gray"> <td>
<?=htmlspecialchars($secretent['pre-shared-key']);?> <?=htmlspecialchars($secretent['pre-shared-key']);?>
</td> </td>
<td class="list nowrap"> <td>
<form action="system_usermanager.php" method="post" name="form_edit_key"> <a href="system_usermanager.php?userid=<?=$secretent['id'];?>&act=edit" title="<?=gettext("edit"); ?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil"></span></a>
<input type="hidden" name="act" value="edit" /> </td>
<input type="hidden" name="userid" value="<?=$secretent['id'];?>" />
<input type="image" name="edituser[]" width="17" height="17" border="0"
src="/themes/<?=$g['theme'];?>/images/icons/icon_e.gif"
title="<?=gettext("edit");?>" />
</form>
&nbsp;</td>
</tr> </tr>
<?php $i++; <?php $i++;
endforeach; ?>
endforeach; ?> <?php
$i = 0;
<?php $i = 0; foreach ($a_secret as $secretent) : foreach ($config['ipsec']['mobilekey'] as $secretent) :
?> ?>
<tr> <tr>
<td class="listlr"> <td>
<?=htmlspecialchars($secretent['ident']);?> <?=htmlspecialchars($secretent['ident']);?>
</td> </td>
<td class="listr"> <td>
<?=htmlspecialchars($secretent['pre-shared-key']);?> <?=htmlspecialchars($secretent['pre-shared-key']);?>
</td> </td>
<td class="list nowrap"><a href="vpn_ipsec_keys_edit.php?id=<?=$i; <td>
?>"><img src="./themes/<?= $g['theme']; <a href="vpn_ipsec_keys_edit.php?id=<?=$i;?>" title="<?=gettext("edit key"); ?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil"></span></a>
?>/images/icons/icon_e.gif" title="<?=gettext("edit key"); ?>" width="17" height="17" border="0" alt="edit" /></a> <a id="del_<?=$i;?>" title="<?=gettext("delete key"); ?>" class="act_delete btn btn-default btn-xs"><span class="glyphicon glyphicon-remove"></span></a>
&nbsp;<a href="vpn_ipsec_keys.php?act=del&amp;id=<?=$i; </td>
?>" onclick="return confirm('<?=gettext("Do you really want to delete this Pre-Shared Key?");
?>')"><img src="./themes/<?= $g['theme'];
?>/images/icons/icon_x.gif" title="<?=gettext("delete key"); ?>" width="17" height="17" border="0" alt="delete" /></a></td>
</tr> </tr>
<?php $i++; <?php $i++;
endforeach; ?>
endforeach; ?>
<tr>
<td class="list" colspan="2"></td>
<td class="list">
<table border="0" cellspacing="0" cellpadding="1" summary="add key">
<tr> <tr>
<td width="20" height="17"></td> <td colspan="2"></td>
<td><a href="vpn_ipsec_keys_edit.php" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-plus"></span></a></td> <td>
</tr> <a href="vpn_ipsec_keys_edit.php" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-plus"></span></a>
</table>
</td> </td>
</tr> </tr>
</table> </table>
</div> </div>
</form> </form>
<div class="container-fluid"> <div class="container-fluid">
<p>
<span class="vexpl">
<span class="text-danger"> <span class="text-danger">
<strong><?=gettext("Note"); ?>:<br /></strong> <strong><?=gettext("Note"); ?>:<br /></strong>
</span> </span>
<?=gettext("PSK for any user can be set by using an identifier of any/ANY");?> <?=gettext("PSK for any user can be set by using an identifier of any/ANY");?>
</span>
</p>
</div> </div>
</div> </div>
</section> </section>
......
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