From d92a07c5cc3445de1ce74577394f5aeb83089c71 Mon Sep 17 00:00:00 2001 From: bergware Date: Tue, 25 Mar 2025 04:33:06 +0100 Subject: [PATCH] Wireless: fix potential double entries in station list --- .../plugins/dynamix/include/NetworkInfo.php | 32 +++++---- emhttp/plugins/dynamix/include/Wireless.php | 66 +++++++++---------- 2 files changed, 51 insertions(+), 47 deletions(-) diff --git a/emhttp/plugins/dynamix/include/NetworkInfo.php b/emhttp/plugins/dynamix/include/NetworkInfo.php index 5f3d01c0d..f9da84516 100644 --- a/emhttp/plugins/dynamix/include/NetworkInfo.php +++ b/emhttp/plugins/dynamix/include/NetworkInfo.php @@ -57,22 +57,28 @@ if ($wlan0) { $signal = explode(': ',$speed[2])[1]; $rxrate = explode(': ',$speed[3])[1]; $txrate = explode(': ',$speed[4])[1]; + $tmp = '/var/tmp/attr'; + $band = []; + $attr = is_readable($tmp) ? (array)parse_ini_file($tmp,true) : []; + $freq = explode(' ', $attr[$network]['ATTR4'] ?? $freq); + foreach ($freq as $number) { + $number = intval($number); + switch (true) { + case ($number >= 2400 && $number < 2500): + if (!in_array('2.4G', $band)) $band[] = '2.4G'; + break; + case ($number >= 5000 && $number < 6000): + if (!in_array('5G', $band)) $band[] = '5G'; + break; + case ($number >= 6000 && $number < 7000): + if (!in_array('6G', $band)) $band[] = '6G'; + break; + } + } + $band = '('.implode(', ', $band).')'; } else { $network = $signal = $rxrate = $txrate = _('Unknown'); - } - switch (true) { - case ($freq >= 2400 && $freq < 2500): - $band = '(2.4G)'; - break; - case ($freq >= 5000 && $freq < 6000): - $band = '(5G)'; - break; - case ($freq >= 6000 && $freq < 7000): - $band = '(6G)'; - break; - default: $band = ''; - break; } echo ""._('Network name').":$network $band"; echo ""._('Signal level').":$signal"; diff --git a/emhttp/plugins/dynamix/include/Wireless.php b/emhttp/plugins/dynamix/include/Wireless.php index b10615bc0..fc74c7919 100644 --- a/emhttp/plugins/dynamix/include/Wireless.php +++ b/emhttp/plugins/dynamix/include/Wireless.php @@ -33,29 +33,24 @@ $_SERVER['REQUEST_URI'] = 'settings'; require_once "$docroot/webGui/include/Translations.php"; require_once "$docroot/webGui/include/Helpers.php"; -function array_ssid(&$key, &$ssid) { - if (!key_exists('ssid', $key)) return false; - $name = $key['ssid']; - return !str_starts_with($name,'\\x00') && (empty($ssid) || !in_array($name, array_column($ssid,'ssid'))); -} - function scanWifi($port) { - $wlan = $ssid = []; - exec("iw ".escapeshellarg($port)." scan | grep -P '^BSS|signal:|SSID:|Authentication suites:'",$scan); - $n = $x = -1; - for ($i=0; $i 1) { foreach ($wifi as $network => $block) { if ($network == $port) continue; - $wlan[$index]['bss'] = $block['ATTR1']; - $wlan[$index]['signal'] = $block['ATTR2']; - $wlan[$index]['security'] = $block['ATTR3'] ?? $block['SECURITY']; - $wlan[$index]['ssid'] = $network; - $index++; + $wlan[$network][0] = $block['ATTR1'] ?? ''; + $wlan[$network][2] = $block['ATTR2'] ?? ''; + $wlan[$network][4] = $block['ATTR3'] ?? $block['SECURITY'] ?? ''; + $wlan[$network][0] = $block['ATTR1'] ?? ''; + $wlan[$network][1] = $block['ATTR4'] ?? ''; + $wlan[$network][3] = $network; } - $index = 0; } else { $wlan = scanWifi($port); } - if (count(array_column($wlan,'ssid'))) { - $up = is_readable($carrier) && file_get_contents($carrier)==1; + if (count($wlan)) { + try { + $up = @file_get_contents($carrier) == 1; + } catch (Exception $e) { + $up = false; + } $alive = $up ? exec("iw ".escapeshellarg($port)." link 2>/dev/null | grep -Pom1 'SSID: \K.+'") : ''; $state = $up ? _('Connected') : _('Disconnected'); $color = $up ? 'blue' : 'red'; - foreach (array_column($wlan,'ssid') as $network) { - $attr[$network]['ATTR1'] = $wlan[$index]['bss'] ?? ''; - $attr[$network]['ATTR2'] = $wlan[$index]['signal'] ?? ''; - $attr[$network]['ATTR3'] = $wlan[$index]['security'] ?? ''; - $index++; + foreach ($wlan as $network => $block) { + $attr[$network]['ATTR1'] = $block[0] ?? ''; + $attr[$network]['ATTR2'] = $block[2] ?? ''; + $attr[$network]['ATTR3'] = $block[4] ?? ''; + $attr[$network]['ATTR4'] = $block[1] ?? ''; if (isset($wifi[$network]['GROUP'])) { if ($network == $alive || $wifi[$network]['GROUP'] == 'active') { $echo['active'][] = "
$state:
";