System: Gateways: Configuration - ensure proper types are emitted in searchGatewayAction() when configd action fails.

should prevent hard failures like:

TypeError: array_key_exists(): Argument #2 ($array) must be of type array, null given in /usr/local/opnsense/mvc/app/controllers/OPNsense/Routing/Api/SettingsController.php:122 Stack trace: #0
This commit is contained in:
Ad Schellevis
2026-03-02 21:43:20 +01:00
parent 4bc542cc7f
commit a19a72cda8
@@ -54,8 +54,8 @@ class SettingsController extends ApiMutableModelControllerBase
public function searchGatewayAction()
{
$cfg = Config::getInstance()->object();
$ifconfig = json_decode((new Backend())->configdRun('interface list ifconfig'), true);
$gateways_status = json_decode((new Backend())->configdRun('interface gateways status'), true);
$ifconfig = json_decode((new Backend())->configdRun('interface list ifconfig'), true) ?? [];
$gateways_status = json_decode((new Backend())->configdRun('interface gateways status'), true) ?? [];
$gateways = array_values($this->getModel()->gatewaysIndexedByName(true, false, true));
$down_gateways = !empty((string)$cfg->system->gw_switch_default) ? array_map(function ($gw) {
if (str_contains($gw['status'], 'down')) {