summaryrefslogtreecommitdiffhomepage
path: root/modules/freifunk/luasrc/controller
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-05-27 12:23:39 +0000
committerSteven Barth <steven@midlink.org>2008-05-27 12:23:39 +0000
commitd35a620e9f5665a94967f4bd02c93581a1dd7e00 (patch)
treecbe7a9b9fe71e40d850c649361c87608d56ea48b /modules/freifunk/luasrc/controller
parent5df565faba5eb0c26a7ce0e2d6e9092bf71cb1e8 (diff)
commit 4f6198094cf4134179d1f9c9fa8f79759a27c87e
Author: Felix Fietkau <nbd@openwrt.org> Date: Tue May 27 13:56:12 2008 +0200 rename src/ to luasrc/
Diffstat (limited to 'modules/freifunk/luasrc/controller')
-rw-r--r--modules/freifunk/luasrc/controller/freifunk/freifunk.lua68
-rw-r--r--modules/freifunk/luasrc/controller/freifunk/luciinfo.lua45
-rw-r--r--modules/freifunk/luasrc/controller/freifunk/olsr.lua164
3 files changed, 277 insertions, 0 deletions
diff --git a/modules/freifunk/luasrc/controller/freifunk/freifunk.lua b/modules/freifunk/luasrc/controller/freifunk/freifunk.lua
new file mode 100644
index 0000000000..104f6cdfc3
--- /dev/null
+++ b/modules/freifunk/luasrc/controller/freifunk/freifunk.lua
@@ -0,0 +1,68 @@
+module("luci.controller.freifunk.freifunk", package.seeall)
+
+function index()
+ local page = node()
+ page.target = alias("freifunk")
+
+ local page = node("freifunk")
+ page.title = "Freifunk"
+ page.target = alias("freifunk", "index")
+ page.order = 5
+ page.setuser = "nobody"
+ page.setgroup = "nogroup"
+
+ local page = node("freifunk", "index")
+ page.target = template("freifunk/index")
+ page.title = "Übersicht"
+ page.order = 10
+
+ local page = node("freifunk", "index", "contact")
+ page.target = template("freifunk/contact")
+ page.title = "Kontakt"
+
+
+ local page = node("freifunk", "status")
+ page.target = action_status
+ page.title = "Status"
+ page.order = 20
+ page.setuser = false
+ page.setgroup = false
+
+ local page = node("freifunk", "status", "routes")
+ page.target = template("public_status/routes")
+ page.title = "Routingtabelle"
+ page.order = 10
+
+ local page = node("freifunk", "status", "iwscan")
+ page.target = template("public_status/iwscan")
+ page.title = "WLAN-Scan"
+ page.order = 20
+
+ local page = node("admin", "index", "freifunk")
+ page.target = cbi("freifunk/freifunk")
+ page.title = "Freifunk"
+ page.order = 30
+
+ local page = node("admin", "index", "contact")
+ page.target = cbi("freifunk/contact")
+ page.title = "Kontakt"
+ page.order = 40
+end
+
+function action_status()
+ local data = {}
+
+ data.s, data.m, data.r = luci.sys.sysinfo()
+
+ data.wifi = luci.sys.wifi.getiwconfig()
+
+ data.routes = {}
+ for i, r in pairs(luci.sys.net.routes()) do
+ if r.Destination == "00000000" then
+ table.insert(data.routes, r)
+ end
+ end
+
+
+ luci.template.render("public_status/index", data)
+end \ No newline at end of file
diff --git a/modules/freifunk/luasrc/controller/freifunk/luciinfo.lua b/modules/freifunk/luasrc/controller/freifunk/luciinfo.lua
new file mode 100644
index 0000000000..aabab19a12
--- /dev/null
+++ b/modules/freifunk/luasrc/controller/freifunk/luciinfo.lua
@@ -0,0 +1,45 @@
+module("luci.controller.freifunk.luciinfo", package.seeall)
+
+function index()
+ node("freifunk", "luciinfo").target = action_index
+end
+
+function action_index()
+ local uci = luci.model.uci.StateSession()
+
+ luci.http.prepare_content("text/plain")
+
+ -- General
+ print("luciinfo.api=1")
+ print("luciinfo.version=" .. tostring(require("luci").__version__))
+
+ -- Sysinfo
+ local s, m, r = luci.sys.sysinfo()
+ local dr = luci.sys.net.defaultroute()
+ dr = dr and luci.sys.net.hexip4(dr.Gateway) or ""
+ local l1, l5, l15 = luci.sys.loadavg()
+
+ print("sysinfo.system=" .. sanitize(s))
+ print("sysinfo.cpu=" .. sanitize(m))
+ print("sysinfo.ram=" .. sanitize(r))
+ print("sysinfo.hostname=" .. sanitize(luci.sys.hostname()))
+ print("sysinfo.load1=" .. tostring(l1))
+ print("sysinfo.load5=" .. tostring(l5))
+ print("sysinfo.load15=" .. tostring(l15))
+ print("sysinfo.defaultgw=" .. dr)
+
+
+ -- Freifunk
+ local ff = uci:sections("freifunk") or {}
+ for k, v in pairs(ff) do
+ for i, j in pairs(v) do
+ if i:sub(1, 1) ~= "." then
+ print("freifunk." .. k .. "." .. i .. "=" .. j)
+ end
+ end
+ end
+end
+
+function sanitize(val)
+ return val:gsub("\n", "\t")
+end \ No newline at end of file
diff --git a/modules/freifunk/luasrc/controller/freifunk/olsr.lua b/modules/freifunk/luasrc/controller/freifunk/olsr.lua
new file mode 100644
index 0000000000..29858fc0e0
--- /dev/null
+++ b/modules/freifunk/luasrc/controller/freifunk/olsr.lua
@@ -0,0 +1,164 @@
+module("luci.controller.freifunk.olsr", package.seeall)
+require("luci.sys")
+
+function index()
+ local page = node("freifunk", "olsr")
+ page.target = action_index
+ page.title = "OLSR"
+ page.order = 30
+
+ local page = node("freifunk", "olsr", "routes")
+ page.target = action_routes
+ page.title = "Routen"
+ page.order = 10
+
+ local page = node("freifunk", "olsr", "topology")
+ page.target = action_topology
+ page.title = "Topologie"
+ page.order = 20
+
+ local page = node("freifunk", "olsr", "hna")
+ page.target = action_hna
+ page.title = "HNA"
+ page.order = 30
+
+ local page = node("freifunk", "olsr", "mid")
+ page.target = action_mid
+ page.title = "MID"
+ page.order = 50
+end
+
+function action_index()
+ local data = fetch_txtinfo("links")
+
+ if not data or not data.Links then
+ luci.template.render("freifunk-olsr/error_olsr")
+ return nil
+ end
+
+ local function compare(a, b)
+ if tonumber(a.ETX) == 0 then
+ return false
+ end
+
+ if tonumber(b.ETX) == 0 then
+ return true
+ end
+
+ return tonumber(a.ETX) < tonumber(b.ETX)
+ end
+
+ table.sort(data.Links, compare)
+
+ luci.template.render("freifunk-olsr/index", {links=data.Links})
+end
+
+function action_routes()
+ local data = fetch_txtinfo("routes")
+
+ if not data or not data.Routes then
+ luci.template.render("freifunk-olsr/error_olsr")
+ return nil
+ end
+
+ local function compare(a, b)
+ if tonumber(a.ETX) == 0 then
+ return false
+ end
+
+ if tonumber(b.ETX) == 0 then
+ return true
+ end
+
+ return tonumber(a.ETX) < tonumber(b.ETX)
+ end
+
+ table.sort(data.Routes, compare)
+
+ luci.template.render("freifunk-olsr/routes", {routes=data.Routes})
+end
+
+function action_topology()
+ local data = fetch_txtinfo("topology")
+
+ if not data or not data.Topology then
+ luci.template.render("freifunk-olsr/error_olsr")
+ return nil
+ end
+
+ local function compare(a, b)
+ return a["Destination IP"] < b["Destination IP"]
+ end
+
+ table.sort(data.Topology, compare)
+
+ luci.template.render("freifunk-olsr/topology", {routes=data.Topology})
+end
+
+function action_hna()
+ local data = fetch_txtinfo("hna")
+
+ if not data or not data.HNA then
+ luci.template.render("freifunk-olsr/error_olsr")
+ return nil
+ end
+
+ local function compare(a, b)
+ return a.Network < b.Network
+ end
+
+ table.sort(data.HNA, compare)
+
+ luci.template.render("freifunk-olsr/hna", {routes=data.HNA})
+end
+
+function action_mid()
+ local data = fetch_txtinfo("mid")
+
+ if not data or not data.MID then
+ luci.template.render("freifunk-olsr/error_olsr")
+ return nil
+ end
+
+ local function compare(a, b)
+ return a.IP < b.IP
+ end
+
+ table.sort(data.MID, compare)
+
+ luci.template.render("freifunk-olsr/mid", {mids=data.MID})
+end
+
+
+-- Internal
+function fetch_txtinfo(otable)
+ otable = otable or ""
+ local rawdata = luci.sys.httpget("http://127.0.0.1:2006/"..otable)
+
+ if #rawdata == 0 then
+ return nil
+ end
+
+ local data = {}
+
+ local tables = luci.util.split(luci.util.trim(rawdata), "\n\n")
+
+
+ for i, tbl in ipairs(tables) do
+ local lines = luci.util.split(tbl, "\n")
+ local name = table.remove(lines, 1):sub(8)
+ local keys = luci.util.split(table.remove(lines, 1), "\t")
+
+ data[name] = {}
+
+ for j, line in ipairs(lines) do
+ local fields = luci.util.split(line, "\t")
+ data[name][j] = {}
+ for k, key in pairs(keys) do
+ data[name][j][key] = fields[k]
+ end
+ end
+ end
+
+ return data
+end \ No newline at end of file