From b128c4106c7c6db845f7b70ddb0c66d40e3ec304 Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 24 May 2020 08:14:07 +0100 Subject: [PATCH 1/3] Applied patches from #581 --- ajax/networking/wifi_stations.php | 1 + includes/configure_client.php | 1 + includes/wifi_functions.php | 45 ++++++++++++++++++++++++------- templates/wifi_stations.php | 19 +++++++------ 4 files changed, 47 insertions(+), 19 deletions(-) diff --git a/ajax/networking/wifi_stations.php b/ajax/networking/wifi_stations.php index a867b6b5..7d9bb82e 100644 --- a/ajax/networking/wifi_stations.php +++ b/ajax/networking/wifi_stations.php @@ -13,5 +13,6 @@ $ssid = null; knownWifiStations($networks); nearbyWifiStations($networks, !isset($_REQUEST["refresh"])); connectedWifiStations($networks); +sortNetworksByRSSI($networks); echo renderTemplate('wifi_stations', compact('networks')); diff --git a/includes/configure_client.php b/includes/configure_client.php index 4e0b001f..07715388 100755 --- a/includes/configure_client.php +++ b/includes/configure_client.php @@ -94,6 +94,7 @@ function DisplayWPAConfig() nearbyWifiStations($networks); connectedWifiStations($networks); + sortNetworksByRSSI($networks); echo renderTemplate("configure_client", compact("status")); } diff --git a/includes/wifi_functions.php b/includes/wifi_functions.php index d8a8ce20..d7194b56 100755 --- a/includes/wifi_functions.php +++ b/includes/wifi_functions.php @@ -63,16 +63,26 @@ function nearbyWifiStations(&$networks, $cached = true) } ); - foreach (explode("\n", $scan_results) as $network) { - $arrNetwork = preg_split("/[\t]+/", $network); // split result into array + // get the name of the AP - should be excluded von the nearby networks + exec('cat '.RASPI_HOSTAPD_CONFIG.' | sed -rn "s/ssid=(.*)\s*$/\1/p" ',$ap_ssid); + $ap_ssid = $ap_ssid[0]; + + foreach (explode("\n", $scan_results) as $network) { + $arrNetwork = preg_split("/[\t]+/", $network); // split result into array + if (!array_key_exists(4, $arrNetwork) || + trim($arrNetwork[4]) == $ap_ssid) continue; + + $ssid = trim($arrNetwork[4]); + // filter SSID string - anything invisable in 7bit ASCII or quotes -> ignore network + if( preg_match('[\x00-\x1f\x7f-\xff\'\`\´\"]',$ssid)) continue; // If network is saved - if (array_key_exists(4, $arrNetwork) && array_key_exists($arrNetwork[4], $networks)) { - $networks[$arrNetwork[4]]['visible'] = true; - $networks[$arrNetwork[4]]['channel'] = ConvertToChannel($arrNetwork[1]); + if (array_key_exists($ssid, $networks)) { + $networks[$ssid]['visible'] = true; + $networks[$ssid]['channel'] = ConvertToChannel($arrNetwork[1]); // TODO What if the security has changed? } else { - $networks[$arrNetwork[4]] = array( + $networks[$ssid] = array( 'configured' => false, 'protocol' => ConvertToSecurity($arrNetwork[3]), 'channel' => ConvertToChannel($arrNetwork[1]), @@ -82,10 +92,12 @@ function nearbyWifiStations(&$networks, $cached = true) ); } - // Save RSSI - if (array_key_exists(4, $arrNetwork)) { - $networks[$arrNetwork[4]]['RSSI'] = $arrNetwork[2]; + // Save RSSI, if the current value is larger than the already stored + if (array_key_exists(4, $arrNetwork) && array_key_exists($arrNetwork[4],$networks)) { + if(! array_key_exists('RSSI',$networks[$arrNetwork[4]]) || $networks[$ssid]['RSSI'] < $arrNetwork[2]) + $networks[$ssid]['RSSI'] = $arrNetwork[2]; } + } } @@ -98,3 +110,18 @@ function connectedWifiStations(&$networks) } } } + +function sortNetworksByRSSI(&$networks) { + $valRSSI = array(); + foreach ($networks as $SSID => $net) { + if (!array_key_exists('RSSI',$net)) $net['RSSI'] = -1000; + $valRSSI[$SSID] = $net['RSSI']; + } + $nets = $networks; + arsort($valRSSI); + $networks = array(); + foreach ($valRSSI as $SSID => $RSSI) { + $networks[$SSID] = $nets[$SSID]; + $networks[$SSID]['RSSI'] = $RSSI; + } +} diff --git a/templates/wifi_stations.php b/templates/wifi_stations.php index 1769cc9e..cdfcb654 100755 --- a/templates/wifi_stations.php +++ b/templates/wifi_stations.php @@ -40,16 +40,15 @@
- = -50) { - echo 100; - } elseif ($network['RSSI'] <= -100) { - echo 0; - } else { - echo 2*($network['RSSI'] + 100); - } - echo "%)"; + = -200 ) { + echo htmlspecialchars($network['RSSI'], ENT_QUOTES); + echo "dB ("; + if ($network['RSSI'] >= -50) echo 100; + elseif ($network['RSSI'] <= -100) echo 0; + else echo 2*($network['RSSI'] + 100); + echo "%)"; + } else echo " not found "; ?>
From 1a8ffd94fcfc68d3a3c850f7ddfbf55a2facc019 Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 24 May 2020 08:24:42 +0100 Subject: [PATCH 2/3] Replaced tabs w/ spaces, applied PSR-2 code standard --- includes/wifi_functions.php | 56 ++++++++++--------- templates/wifi_stations.php | 104 +++++++++++++++++++----------------- 2 files changed, 87 insertions(+), 73 deletions(-) diff --git a/includes/wifi_functions.php b/includes/wifi_functions.php index d7194b56..eb1e8d92 100755 --- a/includes/wifi_functions.php +++ b/includes/wifi_functions.php @@ -52,7 +52,8 @@ function nearbyWifiStations(&$networks, $cached = true) } $scan_results = cache( - $cacheKey, function () { + $cacheKey, + function () { exec('sudo wpa_cli -i ' . RASPI_WIFI_CLIENT_INTERFACE . ' scan'); sleep(3); @@ -63,18 +64,22 @@ function nearbyWifiStations(&$networks, $cached = true) } ); - // get the name of the AP - should be excluded von the nearby networks - exec('cat '.RASPI_HOSTAPD_CONFIG.' | sed -rn "s/ssid=(.*)\s*$/\1/p" ',$ap_ssid); + // 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); $ap_ssid = $ap_ssid[0]; - - foreach (explode("\n", $scan_results) as $network) { - $arrNetwork = preg_split("/[\t]+/", $network); // split result into array + + foreach (explode("\n", $scan_results) as $network) { + $arrNetwork = preg_split("/[\t]+/", $network); // split result into array if (!array_key_exists(4, $arrNetwork) || - trim($arrNetwork[4]) == $ap_ssid) continue; + trim($arrNetwork[4]) == $ap_ssid) { + continue; + } $ssid = trim($arrNetwork[4]); - // filter SSID string - anything invisable in 7bit ASCII or quotes -> ignore network - if( preg_match('[\x00-\x1f\x7f-\xff\'\`\´\"]',$ssid)) continue; + // filter SSID string: anything invisible in 7bit ASCII or quotes -> ignore network + if (preg_match('[\x00-\x1f\x7f-\xff\'\`\´\"]', $ssid)) { + continue; + } // If network is saved if (array_key_exists($ssid, $networks)) { @@ -93,11 +98,11 @@ function nearbyWifiStations(&$networks, $cached = true) } // Save RSSI, if the current value is larger than the already stored - if (array_key_exists(4, $arrNetwork) && array_key_exists($arrNetwork[4],$networks)) { - if(! array_key_exists('RSSI',$networks[$arrNetwork[4]]) || $networks[$ssid]['RSSI'] < $arrNetwork[2]) + if (array_key_exists(4, $arrNetwork) && array_key_exists($arrNetwork[4], $networks)) { + if (! array_key_exists('RSSI', $networks[$arrNetwork[4]]) || $networks[$ssid]['RSSI'] < $arrNetwork[2]) { $networks[$ssid]['RSSI'] = $arrNetwork[2]; + } } - } } @@ -111,17 +116,20 @@ function connectedWifiStations(&$networks) } } -function sortNetworksByRSSI(&$networks) { - $valRSSI = array(); - foreach ($networks as $SSID => $net) { - if (!array_key_exists('RSSI',$net)) $net['RSSI'] = -1000; - $valRSSI[$SSID] = $net['RSSI']; - } - $nets = $networks; - arsort($valRSSI); - $networks = array(); - foreach ($valRSSI as $SSID => $RSSI) { - $networks[$SSID] = $nets[$SSID]; - $networks[$SSID]['RSSI'] = $RSSI; +function sortNetworksByRSSI(&$networks) +{ + $valRSSI = array(); + foreach ($networks as $SSID => $net) { + if (!array_key_exists('RSSI', $net)) { + $net['RSSI'] = -1000; } + $valRSSI[$SSID] = $net['RSSI']; + } + $nets = $networks; + arsort($valRSSI); + $networks = array(); + foreach ($valRSSI as $SSID => $RSSI) { + networks[$SSID] = $nets[$SSID]; + $networks[$SSID]['RSSI'] = $RSSI; + } } diff --git a/templates/wifi_stations.php b/templates/wifi_stations.php index cdfcb654..d6705628 100755 --- a/templates/wifi_stations.php +++ b/templates/wifi_stations.php @@ -16,40 +16,46 @@ } ?>
-
+
- - - - - - - + + + + + +
-
+
- - - - X - + + + + X +
-
+
- = -200 ) { - echo htmlspecialchars($network['RSSI'], ENT_QUOTES); - echo "dB ("; - if ($network['RSSI'] >= -50) echo 100; - elseif ($network['RSSI'] <= -100) echo 0; - else echo 2*($network['RSSI'] + 100); + = -200) { + echo htmlspecialchars($network['RSSI'], ENT_QUOTES); + echo "dB ("; + if ($network['RSSI'] >= -50) { + echo 100; + } elseif ($network['RSSI'] <= -100) { + echo 0; + } else { + echo 2*($network['RSSI'] + 100); + } echo "%)"; - } else echo " not found "; - ?> + } else { + echo " not found "; + } + ?>
@@ -57,35 +63,35 @@ -
+
-
-
+
+
- - - - -
- -
- -
-
+ + + + +
+ +
+ +
+ -
- - " id="update" name="update" /> - - - " id="update" name="update" /> - - " name="delete" /> -
+
+ + " id="update" name="update" /> + + + " id="update" name="update" /> + + " name="delete" /> +
- - + + From eb6f2c5db70f96d4afcc5f56354efe979e4b593c Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 24 May 2020 08:30:32 +0100 Subject: [PATCH 3/3] Fix build error --- includes/wifi_functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/wifi_functions.php b/includes/wifi_functions.php index eb1e8d92..248cbda0 100755 --- a/includes/wifi_functions.php +++ b/includes/wifi_functions.php @@ -129,7 +129,7 @@ function sortNetworksByRSSI(&$networks) arsort($valRSSI); $networks = array(); foreach ($valRSSI as $SSID => $RSSI) { - networks[$SSID] = $nets[$SSID]; + $networks[$SSID] = $nets[$SSID]; $networks[$SSID]['RSSI'] = $RSSI; } }