Commit a6675631 authored by Ad Schellevis's avatar Ad Schellevis

whitespace firewall_aliases.php

parent 62b4d129
<?php <?php
/* /*
Copyright (C) 2014 Deciso B.V. Copyright (C) 2014 Deciso B.V.
Copyright (C) 2004 Scott Ullrich Copyright (C) 2004 Scott Ullrich
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>. Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, 1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
require_once("guiconfig.inc"); require_once("guiconfig.inc");
require_once("filter.inc"); require_once("filter.inc");
function find_alias_reference($section, $field, $origname, &$is_alias_referenced, &$referenced_by) { function find_alias_reference($section, $field, $origname, &$is_alias_referenced, &$referenced_by) {
global $config; global $config;
if(!$origname || $is_alias_referenced) if(!$origname || $is_alias_referenced)
return; return;
$sectionref = &$config; $sectionref = &$config;
foreach($section as $sectionname) { foreach($section as $sectionname) {
if(is_array($sectionref) && isset($sectionref[$sectionname])) if(is_array($sectionref) && isset($sectionref[$sectionname]))
$sectionref = &$sectionref[$sectionname]; $sectionref = &$sectionref[$sectionname];
else else
return; return;
} }
if(is_array($sectionref)) { if(is_array($sectionref)) {
foreach($sectionref as $itemkey => $item) { foreach($sectionref as $itemkey => $item) {
$fieldfound = true; $fieldfound = true;
$fieldref = &$sectionref[$itemkey]; $fieldref = &$sectionref[$itemkey];
foreach($field as $fieldname) { foreach($field as $fieldname) {
if(is_array($fieldref) && isset($fieldref[$fieldname])) if(is_array($fieldref) && isset($fieldref[$fieldname]))
$fieldref = &$fieldref[$fieldname]; $fieldref = &$fieldref[$fieldname];
else { else {
$fieldfound = false; $fieldfound = false;
break; break;
} }
} }
if($fieldfound && $fieldref == $origname) { if($fieldfound && $fieldref == $origname) {
$is_alias_referenced = true; $is_alias_referenced = true;
if(is_array($item)) if(is_array($item))
$referenced_by = $item['descr']; $referenced_by = $item['descr'];
break; break;
} }
} }
} }
} }
if (!isset($config['aliases'])) { if (!isset($config['aliases'])) {
$config['aliases'] = array(); $config['aliases'] = array();
} }
if (!isset($config['aliases']['alias'])) { if (!isset($config['aliases']['alias'])) {
$config['aliases']['alias'] = array(); $config['aliases']['alias'] = array();
} }
$a_aliases = &$config['aliases']['alias']; $a_aliases = &$config['aliases']['alias'];
...@@ -79,68 +79,68 @@ $a_aliases = &$config['aliases']['alias']; ...@@ -79,68 +79,68 @@ $a_aliases = &$config['aliases']['alias'];
$selected_tab = htmlspecialchars(($_REQUEST['tab'] == "" ? "ip" : preg_replace("/\W/","",$_REQUEST['tab']))); $selected_tab = htmlspecialchars(($_REQUEST['tab'] == "" ? "ip" : preg_replace("/\W/","",$_REQUEST['tab'])));
if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['apply'])) { if (isset($_POST['apply'])) {
/* reload all components that use aliases */ /* reload all components that use aliases */
filter_configure(); filter_configure();
$savemsg = get_std_save_message(); $savemsg = get_std_save_message();
clear_subsystem_dirty('aliases'); clear_subsystem_dirty('aliases');
} elseif (isset($_POST['act']) && $_POST['act'] == "del") { } elseif (isset($_POST['act']) && $_POST['act'] == "del") {
if (isset($_POST['id']) && isset($a_aliases[$_POST['id']])) { if (isset($_POST['id']) && isset($a_aliases[$_POST['id']])) {
// perform validation // perform validation
/* make sure rule is not being referenced by any nat or filter rules */ /* make sure rule is not being referenced by any nat or filter rules */
$is_alias_referenced = false; $is_alias_referenced = false;
$referenced_by = false; $referenced_by = false;
$alias_name = $a_aliases[$_POST['id']]['name']; $alias_name = $a_aliases[$_POST['id']]['name'];
// Firewall rules // Firewall rules
find_alias_reference(array('filter', 'rule'), array('source', 'address'), $alias_name, $is_alias_referenced, $referenced_by); find_alias_reference(array('filter', 'rule'), array('source', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
find_alias_reference(array('filter', 'rule'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by); find_alias_reference(array('filter', 'rule'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
find_alias_reference(array('filter', 'rule'), array('source', 'port'), $alias_name, $is_alias_referenced, $referenced_by); find_alias_reference(array('filter', 'rule'), array('source', 'port'), $alias_name, $is_alias_referenced, $referenced_by);
find_alias_reference(array('filter', 'rule'), array('destination', 'port'), $alias_name, $is_alias_referenced, $referenced_by); find_alias_reference(array('filter', 'rule'), array('destination', 'port'), $alias_name, $is_alias_referenced, $referenced_by);
// NAT Rules // NAT Rules
find_alias_reference(array('nat', 'rule'), array('source', 'address'), $alias_name, $is_alias_referenced, $referenced_by); find_alias_reference(array('nat', 'rule'), array('source', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
find_alias_reference(array('nat', 'rule'), array('source', 'port'), $alias_name, $is_alias_referenced, $referenced_by); find_alias_reference(array('nat', 'rule'), array('source', 'port'), $alias_name, $is_alias_referenced, $referenced_by);
find_alias_reference(array('nat', 'rule'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by); find_alias_reference(array('nat', 'rule'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
find_alias_reference(array('nat', 'rule'), array('destination', 'port'), $alias_name, $is_alias_referenced, $referenced_by); find_alias_reference(array('nat', 'rule'), array('destination', 'port'), $alias_name, $is_alias_referenced, $referenced_by);
find_alias_reference(array('nat', 'rule'), array('target'), $alias_name, $is_alias_referenced, $referenced_by); find_alias_reference(array('nat', 'rule'), array('target'), $alias_name, $is_alias_referenced, $referenced_by);
find_alias_reference(array('nat', 'rule'), array('local-port'), $alias_name, $is_alias_referenced, $referenced_by); find_alias_reference(array('nat', 'rule'), array('local-port'), $alias_name, $is_alias_referenced, $referenced_by);
// NAT 1:1 Rules // NAT 1:1 Rules
//find_alias_reference(array('nat', 'onetoone'), array('external'), $alias_name, $is_alias_referenced, $referenced_by); //find_alias_reference(array('nat', 'onetoone'), array('external'), $alias_name, $is_alias_referenced, $referenced_by);
//find_alias_reference(array('nat', 'onetoone'), array('source', 'address'), $alias_name, $is_alias_referenced, $referenced_by); //find_alias_reference(array('nat', 'onetoone'), array('source', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
find_alias_reference(array('nat', 'onetoone'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by); find_alias_reference(array('nat', 'onetoone'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
// NAT Outbound Rules // NAT Outbound Rules
find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('source', 'network'), $alias_name, $is_alias_referenced, $referenced_by); find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('source', 'network'), $alias_name, $is_alias_referenced, $referenced_by);
find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('sourceport'), $alias_name, $is_alias_referenced, $referenced_by); find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('sourceport'), $alias_name, $is_alias_referenced, $referenced_by);
find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by); find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('dstport'), $alias_name, $is_alias_referenced, $referenced_by); find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('dstport'), $alias_name, $is_alias_referenced, $referenced_by);
find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('target'), $alias_name, $is_alias_referenced, $referenced_by); find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('target'), $alias_name, $is_alias_referenced, $referenced_by);
// Alias in an alias // Alias in an alias
find_alias_reference(array('aliases', 'alias'), array('address'), $alias_name, $is_alias_referenced, $referenced_by); find_alias_reference(array('aliases', 'alias'), array('address'), $alias_name, $is_alias_referenced, $referenced_by);
// Load Balancer // Load Balancer
find_alias_reference(array('load_balancer', 'lbpool'), array('port'), $alias_name, $is_alias_referenced, $referenced_by); find_alias_reference(array('load_balancer', 'lbpool'), array('port'), $alias_name, $is_alias_referenced, $referenced_by);
find_alias_reference(array('load_balancer', 'virtual_server'), array('port'), $alias_name, $is_alias_referenced, $referenced_by); find_alias_reference(array('load_balancer', 'virtual_server'), array('port'), $alias_name, $is_alias_referenced, $referenced_by);
// Static routes // Static routes
find_alias_reference(array('staticroutes', 'route'), array('network'), $alias_name, $is_alias_referenced, $referenced_by); find_alias_reference(array('staticroutes', 'route'), array('network'), $alias_name, $is_alias_referenced, $referenced_by);
if($is_alias_referenced) { if($is_alias_referenced) {
$savemsg = sprintf(gettext("Cannot delete alias. Currently in use by %s"), $referenced_by); $savemsg = sprintf(gettext("Cannot delete alias. Currently in use by %s"), $referenced_by);
} else { } else {
unset($a_aliases[$_POST['id']]); unset($a_aliases[$_POST['id']]);
if (write_config()) { if (write_config()) {
filter_configure(); filter_configure();
mark_subsystem_dirty('aliases'); mark_subsystem_dirty('aliases');
} }
header("Location: firewall_aliases.php?tab=" . $selected_tab); header("Location: firewall_aliases.php?tab=" . $selected_tab);
exit; exit;
} }
} }
} }
} }
$pgtitle = array(gettext("Firewall"), gettext("Aliases")); $pgtitle = array(gettext("Firewall"), gettext("Aliases"));
$shortcut_section = "aliases"; $shortcut_section = "aliases";
$main_buttons = array( $main_buttons = array(
array('href'=>'firewall_aliases_edit.php?tab='.$selected_tab, 'label'=>gettext("Add a new alias")), array('href'=>'firewall_aliases_edit.php?tab='.$selected_tab, 'label'=>gettext("Add a new alias")),
array('href'=>'firewall_aliases_import.php', 'label'=>gettext("Bulk import aliases from list")), array('href'=>'firewall_aliases_import.php', 'label'=>gettext("Bulk import aliases from list")),
); );
...@@ -149,130 +149,130 @@ include("head.inc"); ...@@ -149,130 +149,130 @@ include("head.inc");
<body> <body>
<script type="text/javascript"> <script type="text/javascript">
$( 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).attr("id").split('_').pop(-1);
BootstrapDialog.show({ BootstrapDialog.show({
type:BootstrapDialog.TYPE_INFO, type:BootstrapDialog.TYPE_INFO,
title: "<?= gettext("Aliasses");?>", title: "<?= gettext("Aliasses");?>",
message: "<?=gettext("Do you really want to delete this alias? All elements that still use it will become invalid (e.g. filter rules)!");?>", message: "<?=gettext("Do you really want to delete this alias? All elements that still use it will become invalid (e.g. filter rules)!");?>",
buttons: [{ buttons: [{
label: "<?= gettext("No");?>", label: "<?= gettext("No");?>",
action: function(dialogRef) { action: function(dialogRef) {
dialogRef.close(); dialogRef.close();
}}, { }}, {
label: "<?= gettext("Yes");?>", label: "<?= gettext("Yes");?>",
action: function(dialogRef) { action: function(dialogRef) {
$("#delId").val(id); $("#delId").val(id);
$("#iform").submit() $("#iform").submit()
} }
}] }]
}); });
}); });
}); });
</script> </script>
<?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 if (isset($savemsg)) print_info_box($savemsg); ?> <?php if (isset($savemsg)) print_info_box($savemsg); ?>
<?php if (is_subsystem_dirty('aliases')): ?> <?php if (is_subsystem_dirty('aliases')): ?>
<?php print_info_box_np(gettext("The alias list has been changed.") . "<br />" . gettext("You must apply the changes in order for them to take effect."));?> <?php print_info_box_np(gettext("The alias list has been changed.") . "<br />" . gettext("You must apply the changes in order for them to take effect."));?>
<?php endif; ?> <?php endif; ?>
<section class="col-xs-12"> <section class="col-xs-12">
<?php <?php
$tab_array = array(); $tab_array = array();
$tab_array[] = array(gettext("IP"),($selected_tab=="ip" ? true : ($selected_tab=="host" ? true : ($selected_tab == "network" ? true : false))), "/firewall_aliases.php?tab=ip"); $tab_array[] = array(gettext("IP"),($selected_tab=="ip" ? true : ($selected_tab=="host" ? true : ($selected_tab == "network" ? true : false))), "/firewall_aliases.php?tab=ip");
$tab_array[] = array(gettext("Ports"), ($selected_tab=="port"? true : false), "/firewall_aliases.php?tab=port"); $tab_array[] = array(gettext("Ports"), ($selected_tab=="port"? true : false), "/firewall_aliases.php?tab=port");
$tab_array[] = array(gettext("URLs"), ($selected_tab=="url"? true : false), "/firewall_aliases.php?tab=url"); $tab_array[] = array(gettext("URLs"), ($selected_tab=="url"? true : false), "/firewall_aliases.php?tab=url");
$tab_array[] = array(gettext("All"), ($selected_tab=="all"? true : false), "/firewall_aliases.php?tab=all"); $tab_array[] = array(gettext("All"), ($selected_tab=="all"? true : false), "/firewall_aliases.php?tab=all");
display_top_tabs($tab_array); display_top_tabs($tab_array);
?> ?>
<div class="tab-content content-box col-xs-12"> <div class="tab-content content-box col-xs-12">
<form action="firewall_aliases.php" method="post" name="iform" id="iform"> <form action="firewall_aliases.php" method="post" name="iform" id="iform">
<input type="hidden" name="tab" value="<?=$selected_tab;?>" /> <input type="hidden" name="tab" value="<?=$selected_tab;?>" />
<input type="hidden" name="id" value="" id="delId"/> <input type="hidden" name="id" value="" id="delId"/>
<input type="hidden" name="act" value="del"/> <input type="hidden" name="act" value="del"/>
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-striped"> <table class="table table-striped">
<tr> <tr>
<td><?=gettext("Name"); ?></td> <td><?=gettext("Name"); ?></td>
<td><?=gettext("Values"); ?></td> <td><?=gettext("Values"); ?></td>
<td><?=gettext("Description"); ?></td> <td><?=gettext("Description"); ?></td>
<td>&nbsp;</td> <td>&nbsp;</td>
</tr> </tr>
<?php <?php
asort($a_aliases); asort($a_aliases);
foreach ($a_aliases as $i=> $alias){ foreach ($a_aliases as $i=> $alias){
$show_alias = false; $show_alias = false;
switch ($selected_tab){ switch ($selected_tab){
case "all": case "all":
$show_alias= true; $show_alias= true;
break; break;
case "ip": case "ip":
case "host": case "host":
case "network": case "network":
if (preg_match("/(host|network)/",$alias["type"])) if (preg_match("/(host|network)/",$alias["type"]))
$show_alias= true; $show_alias= true;
break; break;
case "url": case "url":
if (preg_match("/(url)/i",$alias["type"])) if (preg_match("/(url)/i",$alias["type"]))
$show_alias= true; $show_alias= true;
break; break;
case "port": case "port":
if($alias["type"] == "port") if($alias["type"] == "port")
$show_alias= true; $show_alias= true;
break; break;
} }
if ($show_alias ){ if ($show_alias ){
?> ?>
<tr> <tr>
<td ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';"> <td ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
<?=htmlspecialchars($alias['name']);?> <?=htmlspecialchars($alias['name']);?>
</td> </td>
<?php <?php
$alias_values = ''; $alias_values = '';
if (!empty($alias["url"])) { if (!empty($alias["url"])) {
$alias_values = $alias["url"]; $alias_values = $alias["url"];
} elseif(isset($alias["aliasurl"])) { } elseif(isset($alias["aliasurl"])) {
$alias_values = implode(", ", array_slice($alias['aliasurl'], 0, 5)); $alias_values = implode(", ", array_slice($alias['aliasurl'], 0, 5));
if(count($alias['aliasurl']) > 5) { if(count($alias['aliasurl']) > 5) {
$alias_values .= "..."; $alias_values .= "...";
} }
} else { } else {
$alias_values = implode(", ", array_slice(explode(" ", $alias['address']), 0, 5)); $alias_values = implode(", ", array_slice(explode(" ", $alias['address']), 0, 5));
if(count(explode(" ", $alias['address'])) > 5) { if(count(explode(" ", $alias['address'])) > 5) {
$alias_values .= "..."; $alias_values .= "...";
} }
} }
?> ?>
<td ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';"> <td ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
<?= htmlspecialchars($alias_values); ?> <?= htmlspecialchars($alias_values); ?>
</td> </td>
<td ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';"> <td ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
<?=htmlspecialchars($alias['descr']);?> <?=htmlspecialchars($alias['descr']);?>
</td> </td>
<td> <td>
<a href="firewall_aliases_edit.php?id=<?=$i;?>" title="<?=gettext("Edit alias"); ?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil"></span></a> <a href="firewall_aliases_edit.php?id=<?=$i;?>" title="<?=gettext("Edit alias"); ?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil"></span></a>
<a id="del_<?=$i;?>" title="<?=gettext("delete alias"); ?>" class="act_delete btn btn-default btn-xs"><span class="glyphicon glyphicon-remove"></span></a> <a id="del_<?=$i;?>" title="<?=gettext("delete alias"); ?>" class="act_delete btn btn-default btn-xs"><span class="glyphicon glyphicon-remove"></span></a>
</td> </td>
</tr> </tr>
<?php <?php
} // if ($show_alias) } // if ($show_alias)
} // foreach } // foreach
?> ?>
</table> </table>
<div class="container-fluid"> <div class="container-fluid">
<span class="text-danger"> <span class="text-danger">
<strong><?=gettext("Note:"); ?><br /> <strong><?=gettext("Note:"); ?><br />
</strong></span> </strong></span>
</span> </span>
<?=gettext("Aliases act as placeholders for real hosts, networks or ports. They can be used to minimize the number of changes that have to be made if a host, network or port changes. You can enter the name of an alias instead of the host, network or port in all fields that have a red background. The alias will be resolved according to the list above. If an alias cannot be resolved (e.g. because you deleted it), the corresponding element (e.g. filter/NAT/shaper rule) will be considered invalid and skipped."); ?> <?=gettext("Aliases act as placeholders for real hosts, networks or ports. They can be used to minimize the number of changes that have to be made if a host, network or port changes. You can enter the name of an alias instead of the host, network or port in all fields that have a red background. The alias will be resolved according to the list above. If an alias cannot be resolved (e.g. because you deleted it), the corresponding element (e.g. filter/NAT/shaper rule) will be considered invalid and skipped."); ?>
</div> </div>
</form> </form>
</div> </div>
</section> </section>
</div> </div>
</div> </div>
</section> </section>
<?php include("foot.inc"); ?> <?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