Commit 2a5ed7b0 authored by Ad Schellevis's avatar Ad Schellevis

(legacy) refactor interfaces_groups.php

parent 23a446fe
......@@ -32,20 +32,26 @@ require_once("guiconfig.inc");
require_once("interfaces.inc");
if (!isset($config['ifgroups']['ifgroupentry'])) {
$config['ifgroups']['ifgroupentry'] = array();
$a_ifgroups = array();
} else {
$a_ifgroups = &$config['ifgroups']['ifgroupentry'];
}
$a_ifgroups = &$config['ifgroups']['ifgroupentry'];
if ($_GET['act'] == "del") {
if ($a_ifgroups[$_GET['id']]) {
$members = explode(" ", $a_ifgroups[$_GET['id']]['members']);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (!empty($a_ifgroups[$_POST['id']])) {
$id = $_POST['id'];
}
if (!empty($_POST['action']) && $_POST['action'] == "del" && isset($id)) {
$members = explode(" ", $a_ifgroups[$id]['members']);
foreach ($members as $ifs) {
$realif = get_real_interface($ifs);
if ($realif)
mwexec("/sbin/ifconfig {$realif} -group " . $a_ifgroups[$_GET['id']]['ifname']);
if (!empty($realif)) {
mwexec("/sbin/ifconfig " . escapeshellarg($realif) . " -group " . escapeshellarg($a_ifgroups[$id]['ifname']));
}
unset($a_ifgroups[$_GET['id']]);
}
unset($a_ifgroups[$id]);
write_config();
header("Location: interfaces_groups.php");
exit;
......@@ -53,85 +59,98 @@ if ($_GET['act'] == "del") {
}
include("head.inc");
legacy_html_escape_form_data($a_ifgroups);
$main_buttons = array(
array('href' => 'interfaces_groups_edit.php', 'label' => gettext('Add')),
);
?>
<body>
<?php include("fbegin.inc"); ?>
<script type="text/javascript">
$( document ).ready(function() {
// link delete buttons
$(".act_delete").click(function(event){
event.preventDefault();
var id = $(this).data("id");
// delete single
BootstrapDialog.show({
type:BootstrapDialog.TYPE_INFO,
title: "<?= gettext("Group");?>",
message: "<?=gettext("Do you really want to delete this group? All elements that still use it will become invalid (e.g. filter rules)!");?>",
buttons: [{
label: "<?= gettext("No");?>",
action: function(dialogRef) {
dialogRef.close();
}}, {
label: "<?= gettext("Yes");?>",
action: function(dialogRef) {
$("#id").val(id);
$("#action").val("del");
$("#iform").submit()
}
}]
});
});
});
</script>
<?php include("fbegin.inc"); ?>
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<section class="col-xs-12">
<div class="tab-content content-box col-xs-12">
<form action="interfaces_assign.php" method="post" name="iform" id="iform">
<table class="table table-striped table-sort">
<form method="post" name="iform" id="iform">
<input type="hidden" id="action" name="action" value="">
<input type="hidden" id="id" name="id" value="">
<table class="table table-striped">
<thead>
<tr>
<th width="15%" class="listtopic"><?=gettext("Name");?></th>
<th width="30%" class="listtopic"><?=gettext("Members");?></th>
<th width="25%" class="listtopic"><?=gettext("Description");?></th>
<th width="10%" class="listtopic">&nbsp;</th>
<th><?=gettext("Name");?></th>
<th><?=gettext("Members");?></th>
<th><?=gettext("Description");?></th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
<?php if (count ($a_ifgroups)):
$i = 0; foreach ($a_ifgroups as $ifgroupentry): ?>
<?php
$i = 0;
foreach ($a_ifgroups as $ifgroupentry): ?>
<tr>
<td class="listlr" ondblclick="document.location='interfaces_groups_edit.php?id=<?=$i;?>';">
<a href="/firewall_rules.php?if=<?=htmlspecialchars($ifgroupentry['ifname']);?>"><?=htmlspecialchars($ifgroupentry['ifname']);?></a>
<td>
<a href="/firewall_rules.php?if=<?=$ifgroupentry['ifname'];?>"><?=$ifgroupentry['ifname'];?></a>
</td>
<td class="listr" ondblclick="document.location='interfaces_groups_edit.php?id=<?=$i;?>';">
<?php
$members_arr = explode(" ", $ifgroupentry['members']);
<td>
<?php
$iflist = get_configured_interface_with_descr(false, true);
$memberses_arr = array();
foreach ($members_arr as $memb)
$memberses_arr[] = $iflist[$memb] ? $iflist[$memb] : $memb;
unset($iflist);
$memberses = implode(", ", $memberses_arr);
echo $memberses;
if(count($members_arr) < 10) {
echo " ";
} else {
echo "...";
}
?>
</td>
<td class="listbg" ondblclick="document.location='interfaces_groups_edit.php?id=<?=$i;?>';">
<?=htmlspecialchars($ifgroupentry['descr']);?>&nbsp;
foreach (explode(" ", $ifgroupentry['members']) as $id => $memb):?>
<?=$id > 0 ? "," : "";?>
<?=!empty($iflist[$memb]) ? $iflist[$memb] : $memb;?>
<?php
endforeach;?>
</td>
<td valign="middle" class="list nowrap">
<a href="interfaces_groups_edit.php?id=<?=$i;?>" class="btn btn-default"><span class="glyphicon glyphicon-edit" data-toggle="tooltip" data-placement="left" title="<?=gettext("edit group");?>"></span></a>
<a href="interfaces_groups.php?act=del&amp;id=<?=$i;?>" class="btn btn-default" onclick="return confirm('<?=gettext("Do you really want to delete this group? All elements that still use it will become invalid (e.g. filter rules)!");?>')" data-toggle="tooltip" data-placement="left" title="<?=gettext("delete ifgroupentry");?>"><span class="glyphicon glyphicon-remove"></span></a>
<td><?=$ifgroupentry['descr'];?></td>
<td>
<a href="interfaces_groups_edit.php?id=<?=$i;?>" class="btn btn-xs btn-default" data-toggle="tooltip" data-placement="left" title="<?=gettext("edit group");?>">
<span class="glyphicon glyphicon-edit"></span>
</a>
<button title="<?=gettext("delete ifgroupentry");?>" data-toggle="tooltip" data-placement="left" data-id="<?=$i;?>" class="btn btn-default btn-xs act_delete" type="submit">
<span class=" glyphicon glyphicon-remove"></span>
</button>
</td>
</tr>
<?php $i++; endforeach; endif;?>
<?php
$i++;
endforeach; ?>
</tbody>
</table>
<div class="container-fluid">
<p><span class="vexpl"><span class="text-danger"><strong><?=gettext("Note:");?><br /></strong></span><?=gettext("Interface Groups allow you to create rules that apply to multiple interfaces without duplicating the rules. If you remove members from an interface group, the group rules no longer apply to that interface.");?></span></p>
<p>
<span class="text-danger"><strong><?=gettext("Note:");?><br /></strong></span>
<?=gettext("Interface Groups allow you to create rules that apply to multiple interfaces without duplicating the rules. If you remove members from an interface group, the group rules no longer apply to that interface.");?>
</p>
</div>
</form>
</div>
</section>
</div>
......
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