Extend source address dropdown with specialnets, https://github.com/opnsense/core/issues/2837

This commit is contained in:
Ad Schellevis 2018-10-25 09:10:31 +02:00
parent a53724edb6
commit 9be373ff75
2 changed files with 12 additions and 5 deletions

View File

@ -388,6 +388,8 @@ include("head.inc");
title="<?=gettext("edit alias");?>" data-toggle="tooltip">
<i class="fa fa-list"></i>
</a>
<?php elseif (is_specialnet($natent['source']['network'])):?>
<?=htmlspecialchars(get_specialnets()[$natent['source']['network']]); ?>
<?php else: ?>
<?=$natent['source']['network'] == "(self)" ? gettext("This Firewall") : htmlspecialchars($natent['source']['network']); ?>&nbsp;
<?php endif; ?>

View File

@ -168,9 +168,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
}
}
if (!(in_array($pconfig['source'], array("any","(self)")) || is_ipaddroralias($pconfig['source']))) {
$input_errors[] = gettext("A valid source must be specified.");
if (!is_specialnet($pconfig['source']) && !is_ipaddroralias($pconfig['source'])) {
$input_errors[] = sprintf(gettext("%s is not a valid source IP address or alias."), $pconfig['source']);
}
if (!empty($pconfig['source_subnet']) && !is_numericint($pconfig['source_subnet'])) {
$input_errors[] = gettext("A valid source bit count must be specified.");
}
@ -262,7 +263,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$natent['source']['network'] = "any";
} else if($pconfig['source'] == "(self)") {
$natent['source']['network'] = "(self)";
} else if(is_alias($pconfig['source'])) {
} else if(is_alias($pconfig['source']) || is_specialnet($pconfig['source'])) {
$natent['source']['network'] = trim($pconfig['source']);
} else {
if (is_ipaddrv6($pconfig['source'])) {
@ -491,14 +492,18 @@ include("head.inc");
<td>
<select name="source" id="source" class="selectpicker" data-live-search="true" data-size="5" data-width="auto">
<option data-other=true value="<?=$pconfig['source'];?>" <?=!is_alias($pconfig['source']) && !in_array($pconfig['source'],array('(self)','any')) ? "selected=\"selected\"" : "";?>><?=gettext("Single host or Network"); ?></option>
<option value="any" <?=$pconfig['source'] == "any" ? "selected=\"selected\"" : ""; ?>><?=gettext("any");?></option>
<option value="(self)" <?=$pconfig['source'] == "(self)" ? "selected=\"selected\"" : ""; ?>><?=gettext("This Firewall (self)");?></option>
<optgroup label="<?=gettext("Aliases");?>">
<?php foreach (legacy_list_aliases("network") as $alias):
?>
<option value="<?=$alias['name'];?>" <?=$alias['name'] == $pconfig['source'] ? "selected=\"selected\"" : "";?>><?=htmlspecialchars($alias['name']);?></option>
<?php endforeach; ?>
</optgroup>
<optgroup label="<?=gettext("Networks");?>">
<?php foreach (get_specialnets(true) as $ifent => $ifdesc):
?>
<option value="<?=$ifent;?>" <?= $pconfig['source'] == $ifent ? "selected=\"selected\"" : ""; ?>><?=$ifdesc;?></option>
<?php endforeach; ?>
</optgroup>
</select>
</td>
</tr>