Merge pull request #1275 from RaspAP/fix/wpa-cli-spaces

Improve handling of wpa_cli output
This commit is contained in:
Bill Zimmerman 2022-12-30 06:30:09 +01:00 committed by GitHub
commit f18e867352
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 11 deletions

View file

@ -107,8 +107,7 @@ function DisplayDashboard(&$extraFooterScripts)
$wlanHasLink = false; $wlanHasLink = false;
$matchesSSID[1] = 'None'; $matchesSSID[1] = 'None';
} }
$connectedSSID = str_replace('\x20', '', $matchesSSID[1]);
$connectedSSID = $matchesSSID[1];
preg_match('/freq: (\d+)/i', $stdoutIwWRepSpaces, $matchesFrequency) || $matchesFrequency[1] = ''; preg_match('/freq: (\d+)/i', $stdoutIwWRepSpaces, $matchesFrequency) || $matchesFrequency[1] = '';
$frequency = $matchesFrequency[1].' MHz'; $frequency = $matchesFrequency[1].' MHz';

View file

@ -60,13 +60,10 @@ function nearbyWifiStations(&$networks, $cached = true)
exec('sudo wpa_cli -i ' .$_SESSION['wifi_client_interface']. ' scan'); exec('sudo wpa_cli -i ' .$_SESSION['wifi_client_interface']. ' scan');
sleep(3); sleep(3);
exec('sudo wpa_cli -i ' .$_SESSION['wifi_client_interface']. ' scan_results', $stdout); $stdout = shell_exec('sudo wpa_cli -i ' .$_SESSION['wifi_client_interface']. ' scan_results');
array_shift($stdout); return preg_split("/\n/", $stdout);
return implode("\n", $stdout);
} }
); );
// get the name of the AP. Should be excluded from nearby networks // get the name of the AP. Should be excluded from nearby networks
exec('cat '.RASPI_HOSTAPD_CONFIG.' | sed -rn "s/ssid=(.*)\s*$/\1/p" ', $ap_ssid); exec('cat '.RASPI_HOSTAPD_CONFIG.' | sed -rn "s/ssid=(.*)\s*$/\1/p" ', $ap_ssid);
$ap_ssid = $ap_ssid[0]; $ap_ssid = $ap_ssid[0];
@ -76,11 +73,11 @@ function nearbyWifiStations(&$networks, $cached = true)
$lastnet = end($networks); $lastnet = end($networks);
if ( isset($lastnet['index']) ) $index = $lastnet['index'] + 1; if ( isset($lastnet['index']) ) $index = $lastnet['index'] + 1;
} }
foreach (explode("\n", $scan_results) as $network) {
$arrNetwork = preg_split("/[\t]+/", $network); // split result into array
$ssid = trim($arrNetwork[4]); array_shift($scan_results);
foreach ($scan_results as $network) {
$arrNetwork = preg_split("/[\t]+/", $network); // split result into array
$ssid = $arrNetwork[4];
// exclude raspap ssid // exclude raspap ssid
if (empty($ssid) || $ssid == $ap_ssid) { if (empty($ssid) || $ssid == $ap_ssid) {