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

(legacy) refactor vpn_ipsec_keys.php

parent 575c202e
......@@ -39,35 +39,33 @@ if (!is_array($config['ipsec'])) {
if (!is_array($config['ipsec']['mobilekey'])) {
$config['ipsec']['mobilekey'] = array();
}
ipsec_mobilekey_sort();
$a_secret = &$config['ipsec']['mobilekey'];
$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);
;
}
} else {
ipsec_mobilekey_sort();
}
if (isset($_POST['apply'])) {
$retval = vpn_ipsec_configure();
/* reload the filter in the background */
filter_configure();
$savemsg = get_std_save_message($retval);
if (is_subsystem_dirty('ipsec')) {
clear_subsystem_dirty('ipsec');
}
}
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");
exit;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['act']) && isset($_POST['id']) && is_numericint($_POST['id']) && $_POST['act'] == "del") {
// delete entry
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
$retval = vpn_ipsec_configure();
/* reload the filter in the background */
filter_configure();
$savemsg = get_std_save_message($retval);
if (is_subsystem_dirty('ipsec')) {
clear_subsystem_dirty('ipsec');
}
} else {
// nothing to post, redirect
header("Location: vpn_ipsec_keys.php");
exit;
}
}
......@@ -75,130 +73,127 @@ $pgtitle = gettext("VPN: IPsec: Keys");
$shortcut_section = "ipsec";
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>
<?php include("fbegin.inc"); ?>
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php
if (isset($savemsg)) {
print_info_box($savemsg);
}
if (is_subsystem_dirty('ipsec')) {
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">
<? $active_tab = "/vpn_ipsec_settings.php";
include('vpn_ipsec_tabs.inc'); ?>
<div class="tab-content content-box col-xs-12">
<form action="vpn_ipsec_keys.php" method="post">
<div class="table-responsive">
<table class="table table-striped table-sort">
<div class="container-fluid">
<div class="row">
<?php
if (isset($savemsg)) {
print_info_box($savemsg);
}
if (is_subsystem_dirty('ipsec')) {
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."));
}
<tr>
<td class="listhdrr"><?=gettext("Identifier"); ?></td>
<td class="listhdr"><?=gettext("Pre-Shared Key"); ?></td>
<td class="list">
<table border="0" cellspacing="0" cellpadding="1" summary="add key">
<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>
?>
<section class="col-xs-12">
<?php
$active_tab = "/vpn_ipsec_settings.php";
include('vpn_ipsec_tabs.inc');
?>
<div class="tab-content content-box col-xs-12">
<form action="vpn_ipsec_keys.php" method="post">
<div class="table-responsive">
<table class="table table-striped">
<tr>
<td><?=gettext("Identifier"); ?></td>
<td><?=gettext("Pre-Shared Key"); ?></td>
<td>
<a href="vpn_ipsec_keys_edit.php" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-plus"></span></a>
</td>
</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>
<td class="listlr gray">
<?php
if ($secretent['ident'] == 'allusers') {
echo gettext("ANY USER");
} else {
echo htmlspecialchars($secretent['ident']);
}
?>
</td>
<td class="listr gray">
<?=htmlspecialchars($secretent['pre-shared-key']);?>
</td>
<td class="list nowrap">
<form action="system_usermanager.php" method="post" name="form_edit_key">
<input type="hidden" name="act" value="edit" />
<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>
<?php $i++;
endforeach; ?>
<?php $i = 0; foreach ($a_secret as $secretent) :
<td>
<?=$secretent['ident'] == 'allusers' ? gettext("ANY USER") : htmlspecialchars($secretent['ident']) ;?>
</td>
<td>
<?=htmlspecialchars($secretent['pre-shared-key']);?>
</td>
<td>
<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>
</td>
</tr>
<?php $i++;
endforeach; ?>
<?php
$i = 0;
foreach ($config['ipsec']['mobilekey'] as $secretent) :
?>
<tr>
<td class="listlr">
<?=htmlspecialchars($secretent['ident']);?>
</td>
<td class="listr">
<?=htmlspecialchars($secretent['pre-shared-key']);?>
</td>
<td class="list nowrap"><a href="vpn_ipsec_keys_edit.php?id=<?=$i;
?>"><img src="./themes/<?= $g['theme'];
?>/images/icons/icon_e.gif" title="<?=gettext("edit key"); ?>" width="17" height="17" border="0" alt="edit" /></a>
&nbsp;<a href="vpn_ipsec_keys.php?act=del&amp;id=<?=$i;
?>" 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>
<?php $i++;
endforeach; ?>
<tr>
<td class="list" colspan="2"></td>
<td class="list">
<table border="0" cellspacing="0" cellpadding="1" summary="add key">
<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>
<tr>
<td>
<?=htmlspecialchars($secretent['ident']);?>
</td>
<td>
<?=htmlspecialchars($secretent['pre-shared-key']);?>
</td>
<td>
<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>
<a id="del_<?=$i;?>" title="<?=gettext("delete key"); ?>" class="act_delete btn btn-default btn-xs"><span class="glyphicon glyphicon-remove"></span></a>
</td>
</tr>
<?php $i++;
endforeach; ?>
<tr>
<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>
</tr>
</table>
</div>
</form>
<div class="container-fluid">
<p>
<span class="vexpl">
<span class="text-danger">
<strong><?=gettext("Note"); ?>:<br /></strong>
</span>
<?=gettext("PSK for any user can be set by using an identifier of any/ANY");?>
</span>
</p>
</div>
</div>
</section>
</div>
</table>
</div>
</form>
<div class="container-fluid">
<span class="text-danger">
<strong><?=gettext("Note"); ?>:<br /></strong>
</span>
<?=gettext("PSK for any user can be set by using an identifier of any/ANY");?>
</div>
</div>
</section>
</div>
</div>
</section>
<?php include("foot.inc");
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