1 module("luci.controller.admin.status_olsr", package.seeall)
5 local page = node("admin", "status", "olsr")
6 page.target = call("action_index")
9 local page = node("admin", "status", "olsr", "routes")
10 page.target = call("action_routes")
14 local page = node("admin", "status", "olsr", "topology")
15 page.target = call("action_topology")
16 page.title = "Topologie"
19 local page = node("admin", "status", "olsr", "hna")
20 page.target = call("action_hna")
24 local page = node("admin", "status", "olsr", "mid")
25 page.target = call("action_mid")
30 function action_index()
31 local data = fetch_txtinfo("links")
33 if not data or not data.Links then
34 luci.template.render("status-olsr/error_olsr")
38 local function compare(a, b)
39 if tonumber(a.ETX) == 0 then
43 if tonumber(b.ETX) == 0 then
47 return tonumber(a.ETX) < tonumber(b.ETX)
50 table.sort(data.Links, compare)
52 luci.template.render("status-olsr/index", {links=data.Links})
55 function action_routes()
56 local data = fetch_txtinfo("routes")
58 if not data or not data.Routes then
59 luci.template.render("status-olsr/error_olsr")
63 local function compare(a, b)
64 if tonumber(a.ETX) == 0 then
68 if tonumber(b.ETX) == 0 then
72 return tonumber(a.ETX) < tonumber(b.ETX)
75 table.sort(data.Routes, compare)
77 luci.template.render("status-olsr/routes", {routes=data.Routes})
80 function action_topology()
81 local data = fetch_txtinfo("topology")
83 if not data or not data.Topology then
84 luci.template.render("status-olsr/error_olsr")
88 local function compare(a, b)
89 return a["Destination IP"] < b["Destination IP"]
92 table.sort(data.Topology, compare)
94 luci.template.render("status-olsr/topology", {routes=data.Topology})
98 local data = fetch_txtinfo("hna")
100 if not data or not data.HNA then
101 luci.template.render("status-olsr/error_olsr")
105 local function compare(a, b)
106 return a.Network < b.Network
109 table.sort(data.HNA, compare)
111 luci.template.render("status-olsr/hna", {routes=data.HNA})
114 function action_mid()
115 local data = fetch_txtinfo("mid")
117 if not data or not data.MID then
118 luci.template.render("status-olsr/error_olsr")
122 local function compare(a, b)
126 table.sort(data.MID, compare)
128 luci.template.render("status-olsr/mid", {mids=data.MID})
133 function fetch_txtinfo(otable)
134 otable = otable or ""
135 local rawdata = luci.sys.httpget("http://127.0.0.1:2006/"..otable)
137 if #rawdata == 0 then
143 local tables = luci.util.split(luci.util.trim(rawdata), "\n\n")
146 for i, tbl in ipairs(tables) do
147 local lines = luci.util.split(tbl, "\n")
148 local name = table.remove(lines, 1):sub(8)
149 local keys = luci.util.split(table.remove(lines, 1), "\t")
153 for j, line in ipairs(lines) do
154 local fields = luci.util.split(line, "\t")
156 for k, key in pairs(keys) do
157 data[name][j][key] = fields[k]