From 8243bb12396de3d344385ace44796ffd24696ebd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Karsten=20B=C3=B6ddeker?= <freifunk@kb-light.de>
Date: Fri, 9 Sep 2016 14:53:23 +0200
Subject: [PATCH] ffho-status-page: use upstream gluon-status-page-api

---
 ffho/ffho-status-page/Makefile                |  2 +-
 .../www/cgi-bin/dyn/neighbours-batadv         | 32 ------------
 .../www/cgi-bin/dyn/neighbours-nodeinfo       |  7 ---
 .../status-page/www/cgi-bin/dyn/stations      | 52 -------------------
 .../status-page/www/cgi-bin/dyn/statistics    | 18 -------
 .../gluon/status-page/www/cgi-bin/nodeinfo    | 15 ------
 .../files/lib/gluon/upgrade/500-status-page   | 15 ------
 7 files changed, 1 insertion(+), 140 deletions(-)
 delete mode 100755 ffho/ffho-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/neighbours-batadv
 delete mode 100755 ffho/ffho-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/neighbours-nodeinfo
 delete mode 100755 ffho/ffho-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/stations
 delete mode 100755 ffho/ffho-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/statistics
 delete mode 100755 ffho/ffho-status-page/files/lib/gluon/status-page/www/cgi-bin/nodeinfo
 delete mode 100755 ffho/ffho-status-page/files/lib/gluon/upgrade/500-status-page

diff --git a/ffho/ffho-status-page/Makefile b/ffho/ffho-status-page/Makefile
index df177f9..ecdcb25 100644
--- a/ffho/ffho-status-page/Makefile
+++ b/ffho/ffho-status-page/Makefile
@@ -12,7 +12,7 @@ define Package/ffho-status-page
   SECTION:=ffho
   CATEGORY:=Gluon
   TITLE:=Adds a status page showing information about the node.
-  DEPENDS:=+gluon-core +uhttpd +gluon-neighbour-info +gluon-respondd +libiwinfo-lua +luci-lib-jsonc
+  DEPENDS:=+gluon-core +uhttpd +gluon-status-page-api +libiwinfo-lua +luci-lib-jsonc
   PROVIDES:=gluon-status-page
   MAINTAINER:=Freifunk Hochstift <kontakt@hochstift.freifunk.net>
   URL:=https://git.c3pb.de/freifunk-pb/ffho-packages
diff --git a/ffho/ffho-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/neighbours-batadv b/ffho/ffho-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/neighbours-batadv
deleted file mode 100755
index 3bcdf89..0000000
--- a/ffho/ffho-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/neighbours-batadv
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/usr/bin/lua
-
-local json = require 'luci.jsonc'
-local nixio = require 'nixio'
-
-function neighbours()
-  local neighbours = {}
-  local list = io.lines("/sys/kernel/debug/batman_adv/bat0/originators")
-  for line in list do
-    local mac1, lastseen, tq, mac2, ifname =
-      line:match("^([0-9a-f:]+) +(%d+%.%d+)s +%( *(%d+)%) +([0-9a-f:]+) +%[ *(.-)%]")
-
-    if mac1 ~= nil and mac1 == mac2 then
-      neighbours[mac1] = { tq = tonumber(tq)
-                         , lastseen = tonumber(lastseen)
-                         , ifname = ifname
-                         }
-    end
-  end
-
-  return neighbours
-end
-
-io.write("Access-Control-Allow-Origin: *\n")
-io.write("Content-type: text/event-stream\n\n")
-
-while true do
-  local neighbours = json.stringify(neighbours())
-  io.write("data: " .. neighbours .. "\n\n")
-  io.flush()
-  nixio.nanosleep(1, 0)
-end
diff --git a/ffho/ffho-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/neighbours-nodeinfo b/ffho/ffho-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/neighbours-nodeinfo
deleted file mode 100755
index 34c1204..0000000
--- a/ffho/ffho-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/neighbours-nodeinfo
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/sh
-
-echo 'Access-Control-Allow-Origin: *'
-
-batctl if | cut -d: -f1 | grep -qxF "$QUERY_STRING" || exit 1
-
-exec /usr/bin/gluon-neighbour-info -s -i "$QUERY_STRING" -d ff02::2:1001 -p 1001 -r nodeinfo
diff --git a/ffho/ffho-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/stations b/ffho/ffho-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/stations
deleted file mode 100755
index 637de64..0000000
--- a/ffho/ffho-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/stations
+++ /dev/null
@@ -1,52 +0,0 @@
-#!/usr/bin/lua
-
-util = require 'luci.util'
-json = require 'luci.jsonc'
-nixio = require 'nixio'
-iwinfo = require 'iwinfo'
-
-function badrequest()
-  io.write("Status: 400 Bad Request\n\n")
-  os.exit(1)
-end
-
-function get_stations(iw, ifname)
-  local stations = {}
-
-  for k, v in pairs(iw.assoclist(ifname)) do
-    stations[k:lower()] = {signal = v.signal, noise = v.noise, inactive = v.inactive}
-  end
-
-  return stations
-end
-
-local ifname = os.getenv("QUERY_STRING")
-
-if ifname == nil then badrequest() end
-
-local list = util.exec('batctl if')
-local found = false
-for _, line in ipairs(util.split(list)) do
-  if ifname == line:match('^(.-):') then
-    found = true
-    break
-  end
-end
-
-if found == false then badrequest() end
-
-local wifitype = iwinfo.type(ifname)
-
-if wifitype == nil then badrequest() end
-
-local iw = iwinfo[wifitype]
-
-io.write("Access-Control-Allow-Origin: *\n")
-io.write("Content-type: text/event-stream\n\n")
-
-while true do
-  local stations = json.stringify(get_stations(iw, ifname))
-  io.write("data: " .. stations .. "\n\n")
-  io.flush()
-  nixio.nanosleep(0, 150e6)
-end
diff --git a/ffho/ffho-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/statistics b/ffho/ffho-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/statistics
deleted file mode 100755
index 194564b..0000000
--- a/ffho/ffho-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/statistics
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/usr/bin/lua
-
-local announce = require 'gluon.announce'
-local json = require 'luci.jsonc'
-local util = require 'luci.util'
-local nixio = require 'nixio'
-
-local announce_dir = '/lib/gluon/announce/statistics.d/'
-
-io.write("Access-Control-Allow-Origin: *\n")
-io.write("Content-type: text/event-stream\n\n")
-
-while true do
-  local data = json.stringify(announce.collect_dir(announce_dir))
-  io.write("data: " .. data .. "\n\n")
-  io.flush()
-  nixio.nanosleep(1, 0)
-end
diff --git a/ffho/ffho-status-page/files/lib/gluon/status-page/www/cgi-bin/nodeinfo b/ffho/ffho-status-page/files/lib/gluon/status-page/www/cgi-bin/nodeinfo
deleted file mode 100755
index 7878924..0000000
--- a/ffho/ffho-status-page/files/lib/gluon/status-page/www/cgi-bin/nodeinfo
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/usr/bin/lua
-
-local announce = require 'gluon.announce'
-local json = require 'luci.jsonc'
-local util = require 'luci.util'
-local nixio = require 'nixio'
-
-local announce_dir = '/lib/gluon/announce/nodeinfo.d/'
-
-io.write("Access-Control-Allow-Origin: *\n")
-io.write("Content-type: application/json\n\n")
-
-local data = json.stringify(announce.collect_dir(announce_dir))
-io.write(data)
-io.flush()
diff --git a/ffho/ffho-status-page/files/lib/gluon/upgrade/500-status-page b/ffho/ffho-status-page/files/lib/gluon/upgrade/500-status-page
deleted file mode 100755
index 71eca5b..0000000
--- a/ffho/ffho-status-page/files/lib/gluon/upgrade/500-status-page
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/sh
-
-uci batch <<-EOF
-	delete uhttpd.main.listen_http
-	add_list uhttpd.main.listen_http=0.0.0.0:80
-	add_list uhttpd.main.listen_http=[::]:80
-
-	delete uhttpd.main.listen_https
-
-	set uhttpd.main.home=/lib/gluon/status-page/www
-
-	set uhttpd.main.max_requests=12
-
-	commit uhttpd
-EOF
-- 
GitLab