diff --git a/src/RaspAP/Networking/Hotspot/WiFiManager.php b/src/RaspAP/Networking/Hotspot/WiFiManager.php index 76fdd0b0..8fb580d9 100644 --- a/src/RaspAP/Networking/Hotspot/WiFiManager.php +++ b/src/RaspAP/Networking/Hotspot/WiFiManager.php @@ -22,11 +22,9 @@ class WiFiManager { // find currently configured networks exec(' sudo cat ' . RASPI_WPA_SUPPLICANT_CONFIG, $known_return); - $index = 0; foreach ($known_return as $line) { if (preg_match('/network\s*=/', $line)) { $network = array('visible' => false, 'configured' => true, 'connected' => false, 'index' => null); - ++$index; } elseif (isset($network) && $network !== null) { if (preg_match('/^\s*}\s*$/', $line)) { $networks[$ssid] = $network; @@ -38,8 +36,7 @@ class WiFiManager $ssid = trim($lineArr[1], '"'); $ssid = str_replace('P"','',$ssid); $network['ssid'] = $ssid; - $index = $this->getNetworkIdBySSID($ssid); - $network['index'] = $index; + $network['index'] = $this->getNetworkIdBySSID($ssid); break; case 'psk': $network['passkey'] = trim($lineArr[1]); @@ -93,13 +90,16 @@ class WiFiManager exec('sed -rn "s/ssid=(.*)\s*$/\1/p" ' . escapeshellarg(RASPI_HOSTAPD_CONFIG), $ap_ssid); $ap_ssid = $ap_ssid[0] ?? ''; - $index = 0; + // determine the next index that follows the indexes of the known networks + $index = -1; if (!empty($networks)) { - $lastnet = end($networks); - if (isset($lastnet['index'])) { - $index = $lastnet['index'] + 1; + foreach ($networks as $network) { + if (isset($network['index']) && ($network['index'] > $index)) { + $index = $network['index']; + } } } + $index++; $current = []; $commitCurrent = function () use (&$current, &$networks, &$index, $ap_ssid) {