1 module("luci.controller.olsr", package.seeall)
4 local page = node("admin", "status", "olsr")
5 page.target = call("action_index")
8 local page = node("admin", "status", "olsr", "routes")
9 page.target = call("action_routes")
13 local page = node("admin", "status", "olsr", "topology")
14 page.target = call("action_topology")
15 page.title = "Topologie"
18 local page = node("admin", "status", "olsr", "hna")
19 page.target = call("action_hna")
23 local page = node("admin", "status", "olsr", "mid")
24 page.target = call("action_mid")
28 entry({"admin", "services", "olsrd"}, cbi("olsr/olsrd"), "OLSR")
31 function action_index()
32 local data = fetch_txtinfo("links")
34 if not data or not data.Links then
35 luci.template.render("status-olsr/error_olsr")
39 local function compare(a, b)
40 if tonumber(a.ETX) == 0 then
44 if tonumber(b.ETX) == 0 then
48 return tonumber(a.ETX) < tonumber(b.ETX)
51 table.sort(data.Links, compare)
53 luci.template.render("status-olsr/index", {links=data.Links})
56 function action_routes()
57 local data = fetch_txtinfo("routes")
59 if not data or not data.Routes then
60 luci.template.render("status-olsr/error_olsr")
64 local function compare(a, b)
65 if tonumber(a.ETX) == 0 then
69 if tonumber(b.ETX) == 0 then
73 return tonumber(a.ETX) < tonumber(b.ETX)
76 table.sort(data.Routes, compare)
78 luci.template.render("status-olsr/routes", {routes=data.Routes})
81 function action_topology()
82 local data = fetch_txtinfo("topology")
84 if not data or not data.Topology then
85 luci.template.render("status-olsr/error_olsr")
89 local function compare(a, b)
90 return a["Destination IP"] < b["Destination IP"]
93 table.sort(data.Topology, compare)
95 luci.template.render("status-olsr/topology", {routes=data.Topology})
99 local data = fetch_txtinfo("hna")
101 if not data or not data.HNA then
102 luci.template.render("status-olsr/error_olsr")
106 local function compare(a, b)
107 return a.Network < b.Network
110 table.sort(data.HNA, compare)
112 luci.template.render("status-olsr/hna", {routes=data.HNA})
115 function action_mid()
116 local data = fetch_txtinfo("mid")
118 if not data or not data.MID then
119 luci.template.render("status-olsr/error_olsr")
123 local function compare(a, b)
127 table.sort(data.MID, compare)
129 luci.template.render("status-olsr/mid", {mids=data.MID})
134 function fetch_txtinfo(otable)
136 otable = otable or ""
137 local rawdata = luci.sys.httpget("http://127.0.0.1:2006/"..otable)
139 if #rawdata == 0 then
145 local tables = luci.util.split(luci.util.trim(rawdata), "\n\n")
148 for i, tbl in ipairs(tables) do
149 local lines = luci.util.split(tbl, "\n")
150 local name = table.remove(lines, 1):sub(8)
151 local keys = luci.util.split(table.remove(lines, 1), "\t")
155 for j, line in ipairs(lines) do
156 local fields = luci.util.split(line, "\t")
158 for k, key in pairs(keys) do
159 data[name][j][key] = fields[k]