From d86ad11f0a9cc4ed61b8c9e3a24984bb446a3554 Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 23 Nov 2025 10:40:26 +0100 Subject: [PATCH] Revise getNetworkIdBySSID to handle networks w/o flags --- src/RaspAP/Networking/Hotspot/WiFiManager.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/RaspAP/Networking/Hotspot/WiFiManager.php b/src/RaspAP/Networking/Hotspot/WiFiManager.php index 76fdd0b0..e7b24921 100644 --- a/src/RaspAP/Networking/Hotspot/WiFiManager.php +++ b/src/RaspAP/Networking/Hotspot/WiFiManager.php @@ -447,12 +447,12 @@ class WiFiManager error_log("Successfully added network: {$network['ssid']}"); } - /* + /** * Parses wpa_cli list_networks output and returns the id * of a corresponding network SSID * * @param string $ssid - * @return integer id + * @return integer id or null */ public function getNetworkIdBySSID($ssid) { $iface = escapeshellarg($_SESSION['wifi_client_interface']); @@ -460,10 +460,11 @@ class WiFiManager $output = []; exec($cmd, $output); array_shift($output); + foreach ($output as $line) { $columns = preg_split('/\t/', $line); - if (count($columns) >= 4 && trim($columns[1]) === trim($ssid)) { - return $columns[0]; // return network ID + if (count($columns) >= 2 && trim($columns[1]) === trim($ssid)) { + return (int)$columns[0]; } } return null;