filter - cleanup some php8 warnings

This commit is contained in:
Ad Schellevis 2022-08-01 16:56:28 +02:00
parent 8f8449ebe8
commit edcc29ab5c
6 changed files with 21 additions and 20 deletions

View File

@ -323,7 +323,7 @@ function filter_configure_sync($verbose = false, $load_aliases = true)
log_error(sprintf("Ignore down %s gateways : %s", $ipprotocol, implode(",", $down_gateways)));
}
$default_gw = $fw->getGateways()->getDefaultGW($down_gateways, $ipprotocol);
if ($default_gw !== null) {
if ($default_gw !== null && !empty($default_gw['gateway'])) {
system_default_route(
$default_gw['gateway'],
$ipprotocol,
@ -422,7 +422,7 @@ function filter_configure_sync($verbose = false, $load_aliases = true)
$limitrules .= "set limit frags {$config['system']['maximumfrags']}\n";
}
if (isset($config['system']['lb_use_sticky']) && is_numeric($config['system']['srctrack']) && ($config['system']['srctrack'] > 0)) {
if (isset($config['system']['lb_use_sticky']) && is_numeric($config['system']['srctrack'] ?? null) && ($config['system']['srctrack'] > 0)) {
$limitrules .= "set timeout src.track {$config['system']['srctrack']}\n";
}

View File

@ -114,7 +114,7 @@ class DNatRule extends Rule
// yield reflection rdr rules when enabled
$interface = $rule['interface'];
$reflinterf = $this->reflectionInterfaces($interface);
if (!$rule['disabled'] && $rule['natreflection'] == "enable") {
if (empty($rule['disabled']) && ($rule['natreflection'] ?? "") == "enable") {
foreach ($reflinterf as $interf) {
$is_ipv4 = $this->isIpV4($rule);
if (
@ -129,7 +129,7 @@ class DNatRule extends Rule
}
// yield reflection nat rules when enabled, but only for interfaces with networks configured
if (!$rule['disabled'] && !empty($rule['enablenatreflectionhelper'])) {
if (empty($rule['disabled']) && !empty($rule['enablenatreflectionhelper'])) {
$reflinterf[] = $interface;
foreach ($reflinterf as $interf) {
if (!empty($this->interfaceMapping[$interf])) {

View File

@ -130,7 +130,7 @@ class FilterRule extends Rule
$rule['reply'] = "reply-to {$if} ";
}
}
} elseif (!isset($rule['disablereplyto']) && $rule['direction'] != 'any') {
} elseif (!isset($rule['disablereplyto']) && ($rule['direction'] ?? "") != 'any') {
$proto = $rule['ipprotocol'];
if (!empty($this->interfaceMapping[$rule['interface']]['if']) && empty($rule['gateway'])) {
$if = $this->interfaceMapping[$rule['interface']]['if'];
@ -209,7 +209,7 @@ class FilterRule extends Rule
}
}
// restructure state settings for easier output parsing
if (!empty($rule['statetype']) && ($rule['type'] == 'pass' || empty($rule['type']))) {
if (!empty($rule['statetype']) && (empty($rule['type']) || $rule['type'] == 'pass')) {
$rule['state'] = array('type' => 'keep', 'options' => array());
switch ($rule['statetype']) {
case 'none':
@ -232,7 +232,7 @@ class FilterRule extends Rule
$rule['state']['options'][] = $state_tag . " " . $rule[$state_tag];
}
}
if (is_numeric($rule['adaptivestart']) && is_numeric($rule['adaptiveend'])) {
if (!empty($rule['adaptivestart']) && is_numeric($rule['adaptivestart']) && is_numeric($rule['adaptiveend'])) {
$rule['state']['options'][] = "adaptive.start " . $rule['adaptivestart'] . ", adaptive.end " . $rule['adaptiveend'];
}
if (!empty($rule['statetimeout'])) {
@ -246,7 +246,7 @@ class FilterRule extends Rule
}
}
// icmp-type switch (ipv4/ipv6)
if ($rule['protocol'] == "icmp" && !empty($rule['icmptype'])) {
if (!empty($rule['protocol']) && $rule['protocol'] == "icmp" && !empty($rule['icmptype'])) {
if ($rule['ipprotocol'] == 'inet') {
$rule['icmp-type'] = $rule['icmptype'];
} elseif ($rule['ipprotocol'] == 'inet6') {

View File

@ -145,7 +145,7 @@ class ForwardRule extends Rule
// When reflection is enabled our ruleset should cover all
$interflist = array($tmp['interface']);
if (!$tmp['disabled'] && !$tmp['nordr'] && in_array($tmp['natreflection'], array("purenat", "enable"))) {
if (empty($tmp['disabled']) && !$tmp['nordr'] && in_array($tmp['natreflection'], array("purenat", "enable"))) {
$is_ipv4 = $this->isIpV4($tmp);
$reflinterf = $this->reflectionInterfaces($tmp['interface']);
foreach ($reflinterf as $interf) {
@ -160,7 +160,7 @@ class ForwardRule extends Rule
foreach ($interflist as $interf) {
$rule = $tmp;
// automatically generate nat rule when enablenatreflectionhelper is set
if (!$rule['disabled'] && empty($rule['nordr']) && !empty($rule['enablenatreflectionhelper'])) {
if (empty($rule['disabled']) && empty($rule['nordr']) && !empty($rule['enablenatreflectionhelper'])) {
if (
!empty($this->interfaceMapping[$rule['interface']]) && (
!empty($this->interfaceMapping[$rule['interface']]['ifconfig']['ipv4']) ||

View File

@ -102,17 +102,18 @@ class Plugin
{
$this->gateways = $gateways;
foreach ($gateways->gatewaysIndexedByName(false, true) as $key => $gw) {
if (!empty($gw['gateway_interface']) || Util::isIpAddress($gw['gateway'])) {
if (Util::isIpAddress($gw['gateway'])) {
$logic = "route-to ( {$gw['if']} {$gw['gateway']} )";
if (!empty($gw['gateway_interface']) || Util::isIpAddress($gw['gateway'] ?? null)) {
$this->gatewayMapping[$key] = [
"interface" => $gw['if'],
"proto" => $gw['ipprotocol'],
"type" => "gateway"
];
if (!empty($gw['gateway']) && Util::isIpAddress($gw['gateway'])) {
$this->gatewayMapping[$key]['logic'] = "route-to ( {$gw['if']} {$gw['gateway']} )";
$this->gatewayMapping[$key]['gateway'] = $gw['gateway'];
} else {
$logic = "route-to {$gw['if']}";
$this->gatewayMapping[$key]['logic'] = "route-to {$gw['if']}";
}
$this->gatewayMapping[$key] = array("logic" => $logic,
"interface" => $gw['if'],
"gateway" => $gw['gateway'],
"proto" => $gw['ipprotocol'],
"type" => "gateway");
}
}
}

View File

@ -282,7 +282,7 @@ abstract class Rule
$rule[$target] = "!" . $rule[$target];
}
if (isset($rule['protocol']) && in_array(strtolower($rule['protocol']), array("tcp","udp","tcp/udp"))) {
$port = str_replace('-', ':', $rule[$tag]['port']);
$port =!empty($rule[$tag]['port']) ? str_replace('-', ':', $rule[$tag]['port']) : null;
if (strpos($port, ':any') !== false xor strpos($port, 'any:') !== false) {
// convert 'any' to upper or lower bound when provided in range. e.g. 80:any --> 80:65535
$port = str_replace('any', strpos($port, ':any') !== false ? '65535' : '1', $port);