Firewall: Automation: Filter - add gateway groups to the list, closes https://github.com/opnsense/core/issues/7625

This commit is contained in:
Ad Schellevis 2024-10-05 18:22:30 +02:00
parent 0cae921340
commit e648aefb76
3 changed files with 19 additions and 4 deletions

View File

@ -85,7 +85,7 @@
<ValidationMessage>Please specify a valid portnumber, name, alias or range</ValidationMessage>
</destination_port>
<gateway type="JsonKeyValueStoreField">
<ConfigdPopulateAct>interface gateways list</ConfigdPopulateAct>
<ConfigdPopulateAct>interface gateways list -g</ConfigdPopulateAct>
<ValidationMessage>Specify a valid gateway from the list matching the networks ip protocol.</ValidationMessage>
</gateway>
<log type="BooleanField">

View File

@ -31,9 +31,10 @@ require_once 'config.inc';
require_once 'util.inc';
require_once 'interfaces.inc';
$gateways = (new \OPNsense\Routing\Gateways())->gatewaysIndexedByName(true, true, true);
$mdl = (new \OPNsense\Routing\Gateways());
$gateways = $mdl->gatewaysIndexedByName(true, true, true);
$ret = array();
$ret = [];
foreach ($gateways as $gateway) {
if (is_ipaddr($gateway['gateway'] ?? '')) {
@ -43,4 +44,17 @@ foreach ($gateways as $gateway) {
}
}
echo json_encode($ret) . PHP_EOL;
$opts = getopt('gh', [], $optind);
$args = array_slice($argv, $optind);
if (isset($opts['h'])) {
echo "Usage: gateways.php [-g] [-h]\n\n";
echo "\t-g add gateway groups\n";
} else {
if (isset($opts['g'])) {
foreach ($mdl->getGroupNames() as $name) {
$ret[$name] = $name;
}
}
echo json_encode($ret) . PHP_EOL;
}

View File

@ -148,6 +148,7 @@ type: script_output
[gateways.list]
command:/usr/local/opnsense/scripts/routes/gateways.php
parameters: %s
type:script_output
message:list gateways
cache_ttl:20