From patchwork Thu Oct 19 22:25:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [v2, 2/3] fff-web: Label Freifunk routers individually in wifiscan.html From: Adrian Schmutzler X-Patchwork-Id: 611 Message-Id: <1508451907-49231-2-git-send-email-freifunk@adrianschmutzler.de> To: franken-dev@freifunk.net Date: Fri, 20 Oct 2017 00:25:06 +0200 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). Changes in v2: none Signed-off-by: Adrian Schmutzler Tested-by: Adrian Schmutzler --- .../fff-web/files/www/ssl/cgi-bin/wifiscan.html | 91 ++++++++++++++++++++-- 1 file changed, 85 insertions(+), 6 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 254c24b..29f99e5 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,8 +1,61 @@ -#!/usr/bin/haserl +#!/usr/bin/haserl --upload-dir=/tmp --upload-limit=12000 +<% +# 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 [ ! -n "$POST_hood" ] ; then + MSG='Hood nicht angegeben!' + else + if /bin/wget -T 10 -O /tmp/wifinodelist "https://monitoring.freifunk-franken.de/api/wifianal/$POST_hood" 2> /dev/null ; then + MSG='Download erfolgreich!' + else + MSG='Download fehlgeschlagen!' + fi + 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}')" + havelist="Ja (Hood: ${filehood}, ${numentries} Einträge)" +else + havelist='Nein' +fi +%> +
+
+
+ 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:
Name der Hood:
+
+
+
Wifi Scan @@ -16,11 +69,37 @@ <% -iwinfo w2mesh scan |\ - awk -v RS='' \ - '{r = gensub(/.*Address: ([0-9A-F:]*)?.*ESSID: "?(unknown|[^"]*)"?[ ]*\n.*Mode: ([^ ]*).*Channel: ([0-9]*).*Signal: (-[0-9]*) dBm.*Encryption: ([^"]*).*/, \ - "", "g"); print r;}' | sort -n | sed 's#&#\&#' - # The HTML comment contains the signal quality to allow sorting +if [ -s /tmp/wifinodelist ] ; then + firststep=$(iwinfo w2mesh scan |\ + awk -v RS='' \ + '{r = gensub(/.*Address: ([0-9A-F:]*)?.*ESSID: "?(unknown|[^"]*)"?[ ]*\n.*Mode: ([^ ]*).*Channel: ([0-9]*).*Signal: (-[0-9]*) dBm.*Encryption: ([^"]*).*/, \ + "\\2\\1", "g"); print r;}' | sort -n | sed 's#&#\&#') + # The HTML comment contains the signal quality to allow sorting + + echo "$firststep" | 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 "${midpart}${endpart}" + done +else + iwinfo w2mesh scan |\ + awk -v RS='' \ + '{r = gensub(/.*Address: ([0-9A-F:]*)?.*ESSID: "?(unknown|[^"]*)"?[ ]*\n.*Mode: ([^ ]*).*Channel: ([0-9]*).*Signal: (-[0-9]*) dBm.*Encryption: ([^"]*).*/, \ + "", "g"); print r;}' | sort -n | sed 's#&#\&#' + # The HTML comment contains the signal quality to allow sorting +fi %>
\\2\\4\\5 dBm\\3\\1\\6
\\4\\5 dBm\\3\\6
${ssid}${mac}
\\2\\4\\5 dBm\\3\\1\\6