From patchwork Sun Nov 26 13:01:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [v3, 4/4] fff-web: Label Freifunk routers individually in wifiscan.html From: Adrian Schmutzler X-Patchwork-Id: 711 Message-Id: <1511701300-3004-4-git-send-email-freifunk@adrianschmutzler.de> To: franken-dev@freifunk.net Date: Sun, 26 Nov 2017 14:01:40 +0100 This patch enables labelling of routers in the WebUI's WiFi scan page, so their hostname is displayed instead of freifunk.franken.net. The evaluation is performed based on a WifiAnalyzer style node file /tmp/wifinodelist. In the WebUI, this file may be provided by file upload or by downloading from the Monitoring API (if the router has internet access). Signed-off-by: Adrian Schmutzler Tested-by: Adrian Schmutzler --- Changes in v2: none Changes in v3: - Put to the end of the patchset - Use wifianalall API (hood-independent) as this is now available and eves the file for all hoods has only < 200 kB - Reduced upload file size to 1MB --- .../fff-web/files/www/ssl/cgi-bin/wifiscan.html | 79 +++++++++++++++++++++- 1 file changed, 77 insertions(+), 2 deletions(-) diff --git a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/wifiscan.html b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/wifiscan.html index f9186d2..320019b 100755 --- a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/wifiscan.html +++ b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/wifiscan.html @@ -1,7 +1,40 @@ -#!/usr/bin/haserl +#!/usr/bin/haserl --upload-dir=/tmp --upload-limit=1000 +<% +# treat post +if [ "$REQUEST_METHOD" == "POST" ] ; then + if [ "$POST_wifiupload" != "" ] ; then + if [ ! -f "$HASERL_nodelist_path" ] ; then + MSG='Node-Datei nicht gefunden!' + elif [ "$(du -k "$HASERL_nodelist_path" | cut -f1)" == "0" ] ; then + MSG='Node-Datei ist leer!' + else + mv "$HASERL_nodelist_path" /tmp/wifinodelist + MSG='Upload erfolgreich!' + fi + fi + if [ "$POST_wifidownload" != "" ] ; then + if /bin/wget -T 10 -O /tmp/wifinodelist "https://monitoring.freifunk-franken.de/api/wifianalall" 2> /dev/null ; then + MSG='Download erfolgreich!' + else + MSG='Download fehlgeschlagen!' + fi + fi +fi +%> <%in /www/ssl/cgi-bin/header %> +<%in /www/ssl/cgi-bin/helpers %> +<% show_msg %> <% +if [ -s /tmp/wifinodelist ] ; then + numentries="$(grep -c '^[^#]' /tmp/wifinodelist)" + filehood="$(grep -e "#Hood:" /tmp/wifinodelist | awk -F" " '{print $2}')" + [ -n "$filehood" ] || filehood="Alle Hoods" + havelist="Ja (Hood: ${filehood}, ${numentries} Einträge)" +else + havelist='Nein' +fi + readIWinfo() { local iface=$1 local ssid=$2 @@ -13,6 +46,28 @@ readIWinfo() { "<'${ssid}'>\\2\\4\\5 dBm\\3<'${mac}'>\\1\\6", "g"); print r;}' | sort -n | sed 's#&#\&#' # The HTML comment contains the signal quality to allow sorting } + +rewriteIWinfo() { + local data="$1" + + echo "$data" | while read line ; do + mac="$(echo "$line" | sed -e 's#.*\(.*\).*#\1#')" + routerid="$(grep -i -e "$mac" /tmp/wifinodelist | awk -F"|" '{print $2}')" + if [ -n "$routerid" ] ; then + ssid="${routerid}" + else + ssidtmp="$(echo "$line" | sed -e 's#.*\(.*\).*#\1#')" + if [ "$ssidtmp" = "unknown" ] ; then + ssid="${ssidtmp}" + else + ssid="$ssidtmp" + fi + fi + midpart=$(echo "$line" | sed -e 's#.*\(.*\).*#\1#') + endpart=$(echo "$line" | sed -e 's#.*\(.*\).*#\1#') + echo "${ssid}${midpart}${mac}${endpart}" + done +} printWifiScan() { local iface=$1 local freq="2.4 GHz" @@ -34,7 +89,12 @@ printWifiScan() { <% - readIWinfo "$iface" "td" "td" + if [ -s /tmp/wifinodelist ] ; then + firststep="$(readIWinfo "$iface" "ssid" "mac")" + rewriteIWinfo "$firststep" + else + readIWinfo "$iface" "td" "td" + fi %> @@ -44,6 +104,21 @@ printWifiScan() { %> + <% if uci -q get wireless.w2ap > /dev/null ; then printWifiScan "w2ap"
+
+
+ Wifi Node File + + + + + + + +
Alias Liste vorhanden:<%= "$havelist" %>
Upload Node-Liste:
Hier kann eine Node-Liste (WiFiAnalyzer-Stil) hochgeladen werden.
Wenn der Router mit dem Internet verbunden ist, kann die Node-Liste vom Monitoring bezogen werden.
+
+
+