Skip to content

Commit

Permalink
firewall: simplify and prettify alias pages #443
Browse files Browse the repository at this point in the history
(cherry picked from commit 2e20c8d)
  • Loading branch information
fichtner committed Apr 1, 2016
1 parent f2ad718 commit 2f32f45
Show file tree
Hide file tree
Showing 4 changed files with 245 additions and 277 deletions.
20 changes: 4 additions & 16 deletions src/opnsense/mvc/app/models/OPNsense/Base/Menu/Menu.xml
Expand Up @@ -141,22 +141,10 @@
</Interfaces>
<Firewall order="3" cssClass="glyphicon glyphicon-fire">
<Aliases order="10" cssClass="fa fa-list-alt fa-fw">
<All order="100" url="/firewall_aliases.php?tab=all">
<Edit url="/firewall_aliases_edit.php?tab=all" visibility="hidden"/>
<Network url="/firewall_aliases.php?tab=network" visibility="hidden"/>
<NoneEdit url="/firewall_aliases_edit.php?id=*" visibility="hidden"/>
<None url="/firewall_aliases.php" visibility="hidden"/>
</All>
<IPs order="200" url="/firewall_aliases.php?tab=ip">
<Edit url="/firewall_aliases_edit.php?tab=ip" visibility="hidden"/>
</IPs>
<Ports order="300" url="/firewall_aliases.php?tab=port">
<Edit url="/firewall_aliases_edit.php?tab=port" visibility="hidden"/>
</Ports>
<URLs order="400" url="/firewall_aliases.php?tab=url">
<Edit url="/firewall_aliases_edit.php?tab=url" visibility="hidden"/>
</URLs>
<Import order="500" url="/firewall_aliases_import.php"/>
<View order="100" url="/firewall_aliases.php">
<Edit url="/firewall_aliases_edit.php*" visibility="hidden"/>
</View>
<Import order="200" url="/firewall_aliases_import.php"/>
</Aliases>
<Rules order="20" url="/firewall_rules.php" cssClass="fa fa-check fa-fw">
<RulesEdit url="/firewall_rules_edit.php*" visibility="hidden"/>
Expand Down
75 changes: 36 additions & 39 deletions src/www/firewall_aliases.php
Expand Up @@ -31,6 +31,25 @@
require_once("guiconfig.inc");
require_once("filter.inc");

function find_alias_type($type)
{
$types = array(
'host' => gettext('Host(s)'),
'network' => gettext('Network(s)'),
'port' => gettext('Port(s)'),
'url' => gettext('URL (IPs)'),
'url_ports' => gettext('URL (Ports)'),
'urltable' => gettext('URL Table (IPs)'),
'urltable_ports' => gettext('URL Table (Ports)'),
);

if (isset($types[$type])) {
return $types[$type];
}

return $type;
}

function find_alias_reference($section, $field, $origname, &$is_alias_referenced, &$referenced_by) {
global $config;
if(!$origname || $is_alias_referenced)
Expand Down Expand Up @@ -75,9 +94,6 @@ function find_alias_reference($section, $field, $origname, &$is_alias_referenced
}
$a_aliases = &$config['aliases']['alias'];

// determine selected tab
$selected_tab = htmlspecialchars(($_REQUEST['tab'] == "" ? "ip" : preg_replace("/\W/","",$_REQUEST['tab'])));

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['apply'])) {
/* reload all components that use aliases */
Expand Down Expand Up @@ -128,7 +144,7 @@ function find_alias_reference($section, $field, $origname, &$is_alias_referenced
filter_configure();
mark_subsystem_dirty('aliases');
}
header("Location: firewall_aliases.php?tab=" . $selected_tab);
header('Location: firewall_aliases.php');
exit;
}
}
Expand All @@ -137,7 +153,7 @@ function find_alias_reference($section, $field, $origname, &$is_alias_referenced

legacy_html_escape_form_data($a_aliases);
$main_buttons = array(
array('href'=>'firewall_aliases_edit.php?tab='.$selected_tab, 'label'=>gettext("Add a new alias")),
array('href' => 'firewall_aliases_edit.php', 'label' => gettext('Add a new alias')),
);

include("head.inc");
Expand Down Expand Up @@ -186,37 +202,18 @@ function find_alias_reference($section, $field, $origname, &$is_alias_referenced
<table class="table table-striped">
<tr>
<td><?=gettext("Name"); ?></td>
<td><?=gettext("Values"); ?></td>
<td><?=gettext("Type"); ?></td>
<td><?=gettext("Description"); ?></td>
<td><?=gettext("Values"); ?></td>
<td>&nbsp;</td>
</tr>
<?php
uasort($a_aliases, function($a, $b){
uasort($a_aliases, function($a, $b) {
return strnatcmp($a['name'], $b['name']);
});

foreach ($a_aliases as $i=> $alias){
$show_alias = false;
switch ($selected_tab){
case "all":
$show_alias= true;
break;
case "ip":
case "host":
case "network":
if (preg_match("/(host|network)/",$alias["type"]))
$show_alias= true;
break;
case "url":
if (preg_match("/(url)/i",$alias["type"]))
$show_alias= true;
break;
case "port":
if($alias["type"] == "port")
$show_alias= true;
break;
}
if ($show_alias ){
?>
?>
<tr>
<td ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
<?=$alias['name'];?>
Expand All @@ -238,28 +235,28 @@ function find_alias_reference($section, $field, $origname, &$is_alias_referenced
}
?>
<td ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
<?=$alias_values; ?>
<?= find_alias_type($alias['type']) ?>
</td>
<td ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
<?= $alias['descr'] ?>
</td>
<td ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
<?=$alias['descr'];?>
<?= $alias_values ?>
</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 id="del_<?=$i;?>" title="<?=gettext("delete alias"); ?>" class="act_delete btn btn-default btn-xs"><span class="fa fa-trash text-muted"></span></a>
</td>
</tr>
<?php
} // if ($show_alias)
} // foreach
?>
<tr>
<td colspan="5">
<?=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."); ?>
</td>
</tr>
</table>
<div class="container-fluid">
<span class="text-danger">
<strong><?=gettext("Note:"); ?><br />
</strong></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."); ?>
</div>
</form>
</div>
</section>
Expand Down

0 comments on commit 2f32f45

Please sign in to comment.