mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-13 08:09:41 +00:00
Firewall: Rules - refactor soure/destination (port) rendereing and align it with manual rules underneath, while here also hide group items when in a group. closes https://github.com/opnsense/core/issues/6403
This commit is contained in:
parent
9187fe78bf
commit
48bdf53cda
@ -293,4 +293,77 @@ class FilterRule extends Rule
|
||||
}
|
||||
return $ruleTxt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy and MVC use different fields, which at some point need to be merged.
|
||||
* parseFilterRules already does this for the rule output, but gui parts are left with a mix of things
|
||||
*/
|
||||
private function uiConvertNet($network)
|
||||
{
|
||||
$suffix = str_ends_with($network, 'ip') ? gettext("address") : gettext("net");
|
||||
$ifname = rtrim($network, 'ip');
|
||||
if (!empty($this->interfaceMapping[$ifname])) {
|
||||
$if = $this->interfaceMapping[$ifname];
|
||||
return (!empty($if['descr']) ? $if['descr'] : $ifname) . " " . $suffix;
|
||||
} elseif ($ifname == '(self)') {
|
||||
return gettext("This Firewall");
|
||||
}
|
||||
return $network;
|
||||
}
|
||||
public function getUIFromAddress()
|
||||
{
|
||||
if (!empty($this->rule['from'])) {
|
||||
return $this->rule['from'];
|
||||
} elseif (isset($this->rule['source']['address'])) {
|
||||
return $this->rule['source']['address'];
|
||||
} elseif (isset($this->rule['source']['any'])) {
|
||||
return '*';
|
||||
} elseif (isset($this->rule['source']['network'])) {
|
||||
return $this->uiConvertNet($this->rule['source']['network']);
|
||||
}
|
||||
return '*';
|
||||
}
|
||||
public function isUIFromNot()
|
||||
{
|
||||
return isset($this->rule['source']) && isset($this->rule['source']['not']);
|
||||
}
|
||||
public function getUIFromPort()
|
||||
{
|
||||
if (!empty($this->rule['from_port'])) {
|
||||
return $this->rule['from_port'];
|
||||
} elseif (isset($this->rule['source']['port'])) {
|
||||
return $this->rule['source']['port'];
|
||||
}
|
||||
return '*';
|
||||
}
|
||||
public function getUIToAddress()
|
||||
{
|
||||
if (!empty($this->rule['to'])) {
|
||||
return $this->rule['to'];
|
||||
} elseif (isset($this->rule['destination']['address'])) {
|
||||
return $this->rule['destination']['address'];
|
||||
} elseif (isset($this->rule['destination']['any'])) {
|
||||
return '*';
|
||||
} elseif (isset($this->rule['destination']['network'])) {
|
||||
return $this->uiConvertNet($this->rule['destination']['network']);
|
||||
}
|
||||
return '*';
|
||||
}
|
||||
public function isUIToNot()
|
||||
{
|
||||
return isset($this->rule['destination']) && isset($this->rule['destination']['not']);
|
||||
}
|
||||
public function getUIToPort()
|
||||
{
|
||||
if (!empty($this->rule['to_port'])) {
|
||||
return $this->rule['to_port'];
|
||||
} elseif (isset($this->rule['destination']['port'])) {
|
||||
return $this->rule['destination']['port'];
|
||||
}
|
||||
return '*';
|
||||
}
|
||||
public function getUIGateway()
|
||||
{
|
||||
return !empty($this->rule['gateway']) ? $this->rule['gateway'] : "*";
|
||||
}
|
||||
}
|
||||
|
||||
@ -208,6 +208,20 @@ function firewall_rule_item_log($filterent)
|
||||
return "fa fa-info-circle fa-fw text-muted";
|
||||
}
|
||||
}
|
||||
|
||||
function filter_rule_item_alias_tooltip($alias_name)
|
||||
{
|
||||
$alias_descr = htmlspecialchars(get_alias_description($alias_name));
|
||||
$alias_name = htmlspecialchars($alias_name);
|
||||
$result = "<span title=\"${alias_descr}\" data-toggle=\"tooltip\" data-html=\"true\">";
|
||||
$result .= $alias_name . " ";
|
||||
$result .= "</span>";
|
||||
$result .= "<a href=\"/ui/firewall/alias/index/${alias_name}\"";
|
||||
$result .= " title=\"". gettext("edit alias") ."\" data-toggle=\"tooltip\">";
|
||||
$result .= "<i class=\"fa fa-list\"></i>";
|
||||
$result .= "</a>";
|
||||
return $result;
|
||||
}
|
||||
/***********************************************************************************************************
|
||||
*
|
||||
***********************************************************************************************************/
|
||||
@ -738,7 +752,10 @@ $( document ).ready(function() {
|
||||
];
|
||||
foreach ($fw->iterateFilterRules() as $rule):
|
||||
$is_selected = false;
|
||||
if ($rule->getInterface() == $selected_if) {
|
||||
if (empty($ifgroups) && $rule->ruleOrigin() == 'group'){
|
||||
// group view, skip group section (groups can't be nested)
|
||||
$is_selected = false;
|
||||
} elseif ($rule->getInterface() == $selected_if) {
|
||||
// interface view and this interface is selected
|
||||
$is_selected = true;
|
||||
} elseif ($selected_if == "FloatingRules" && $rule->ruleOrigin() == 'floating') {
|
||||
@ -790,19 +807,21 @@ $( document ).ready(function() {
|
||||
<?=firewall_rule_item_proto($filterent);?>
|
||||
</td>
|
||||
<td class="view-info">
|
||||
<?=!empty($filterent['from']) ? $filterent['from'] : "*";?>
|
||||
<?=$rule->isUIFromNot() ? '!' : '';?>
|
||||
<?= is_alias($rule->getUIFromAddress()) ? filter_rule_item_alias_tooltip($rule->getUIFromAddress()) : htmlspecialchars($rule->getUIFromAddress());?>
|
||||
</td>
|
||||
<td class="view-info hidden-xs hidden-sm">
|
||||
<?=isset($filterent['from_port']) ? $filterent['from_port'] : "*";?>
|
||||
<?= is_alias($rule->getUIFromPort()) ? filter_rule_item_alias_tooltip($rule->getUIFromPort()) : htmlspecialchars(pprint_port($rule->getUIFromPort()));?>
|
||||
</td>
|
||||
<td class="view-info hidden-xs hidden-sm">
|
||||
<?=!empty($filterent['to']) ? $filterent['to'] : "*";?>
|
||||
<?=$rule->isUIToNot() ? '!' : '';?>
|
||||
<?= is_alias($rule->getUIToAddress()) ? filter_rule_item_alias_tooltip($rule->getUIToAddress()) : htmlspecialchars($rule->getUIToAddress());?>
|
||||
</td>
|
||||
<td class="view-info hidden-xs hidden-sm">
|
||||
<?=isset($filterent['to_port']) ? $filterent['to_port'] : "*";?>
|
||||
<?= is_alias($rule->getUIToPort()) ? filter_rule_item_alias_tooltip($rule->getUIToPort()) : htmlspecialchars(pprint_port($rule->getUIToPort()));?>
|
||||
</td>
|
||||
<td class="view-info hidden-xs hidden-sm">
|
||||
<?= !empty($filterent['gateway']) ? $filterent['gateway'] : "*";?>
|
||||
<?= $rule->getUIGateway();?>
|
||||
</td>
|
||||
<td class="view-info hidden-xs hidden-sm">*</td>
|
||||
<td class="view-info">
|
||||
@ -865,13 +884,7 @@ $( document ).ready(function() {
|
||||
</td>
|
||||
<td class="view-info">
|
||||
<?php if (isset($filterent['source']['address']) && is_alias($filterent['source']['address'])): ?>
|
||||
<span title="<?=htmlspecialchars(get_alias_description($filterent['source']['address']));?>" data-toggle="tooltip" data-html="true">
|
||||
<?=htmlspecialchars(pprint_address($filterent['source']));?>
|
||||
</span>
|
||||
<a href="/ui/firewall/alias/index/<?=htmlspecialchars($filterent['source']['address']);?>"
|
||||
title="<?=gettext("edit alias");?>" data-toggle="tooltip">
|
||||
<i class="fa fa-list"></i>
|
||||
</a>
|
||||
<?=filter_rule_item_alias_tooltip($filterent['source']['address']);?>
|
||||
<?php else: ?>
|
||||
<?=htmlspecialchars(pprint_address($filterent['source']));?>
|
||||
<?php endif; ?>
|
||||
@ -879,13 +892,7 @@ $( document ).ready(function() {
|
||||
|
||||
<td class="view-info hidden-xs hidden-sm">
|
||||
<?php if (isset($filterent['source']['port']) && is_alias($filterent['source']['port'])): ?>
|
||||
<span title="<?=htmlspecialchars(get_alias_description($filterent['source']['port']));?>" data-toggle="tooltip" data-html="true">
|
||||
<?=htmlspecialchars(pprint_port($filterent['source']['port'])); ?>
|
||||
</span>
|
||||
<a href="/ui/firewall/alias/index/<?=htmlspecialchars($filterent['source']['port']);?>"
|
||||
title="<?=gettext("edit alias");?>" data-toggle="tooltip">
|
||||
<i class="fa fa-list"></i>
|
||||
</a>
|
||||
<?=filter_rule_item_alias_tooltip($filterent['source']['port']);?>
|
||||
<?php else: ?>
|
||||
<?=htmlspecialchars(pprint_port(isset($filterent['source']['port']) ? $filterent['source']['port'] : null)); ?>
|
||||
<?php endif; ?>
|
||||
@ -893,13 +900,7 @@ $( document ).ready(function() {
|
||||
|
||||
<td class="view-info hidden-xs hidden-sm">
|
||||
<?php if (isset($filterent['destination']['address']) && is_alias($filterent['destination']['address'])): ?>
|
||||
<span title="<?=htmlspecialchars(get_alias_description($filterent['destination']['address']));?>" data-toggle="tooltip" data-html="true">
|
||||
<?=htmlspecialchars(pprint_address($filterent['destination'])); ?>
|
||||
</span>
|
||||
<a href="/ui/firewall/alias/index/<?=htmlspecialchars($filterent['destination']['address']);?>"
|
||||
title="<?=gettext("edit alias");?>" data-toggle="tooltip">
|
||||
<i class="fa fa-list"></i>
|
||||
</a>
|
||||
<?=filter_rule_item_alias_tooltip($filterent['destination']['address']);?>
|
||||
<?php else: ?>
|
||||
<?=htmlspecialchars(pprint_address($filterent['destination'])); ?>
|
||||
<?php endif; ?>
|
||||
@ -907,13 +908,7 @@ $( document ).ready(function() {
|
||||
|
||||
<td class="view-info hidden-xs hidden-sm">
|
||||
<?php if (isset($filterent['destination']['port']) && is_alias($filterent['destination']['port'])): ?>
|
||||
<span title="<?=htmlspecialchars(get_alias_description($filterent['destination']['port']));?>" data-toggle="tooltip" data-html="true">
|
||||
<?=htmlspecialchars(pprint_port($filterent['destination']['port'])); ?>
|
||||
</span>
|
||||
<a href="/ui/firewall/alias/index/<?=htmlspecialchars($filterent['destination']['port']);?>"
|
||||
title="<?=gettext("edit alias");?>" data-toggle="tooltip">
|
||||
<i class="fa fa-list"></i>
|
||||
</a>
|
||||
<?=filter_rule_item_alias_tooltip($filterent['destination']['port']);?>
|
||||
<?php else: ?>
|
||||
<?=htmlspecialchars(pprint_port(isset($filterent['destination']['port']) ? $filterent['destination']['port'] : null)); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user