1 module("luci.controller.olsr", package.seeall)
4 if not luci.fs.isfile("/etc/config/olsr") then
8 local page = node("admin", "status", "olsr")
9 page.target = call("action_index")
12 local page = node("admin", "status", "olsr", "routes")
13 page.target = call("action_routes")
17 local page = node("admin", "status", "olsr", "topology")
18 page.target = call("action_topology")
19 page.title = "Topologie"
22 local page = node("admin", "status", "olsr", "hna")
23 page.target = call("action_hna")
27 local page = node("admin", "status", "olsr", "mid")
28 page.target = call("action_mid")
32 entry({"admin", "services", "olsrd"}, cbi("olsr/olsrd"), "OLSR")
35 function action_index()
36 local data = fetch_txtinfo("links")
38 if not data or not data.Links then
39 luci.template.render("status-olsr/error_olsr")
43 local function compare(a, b)
44 if tonumber(a.ETX) == 0 then
48 if tonumber(b.ETX) == 0 then
52 return tonumber(a.ETX) < tonumber(b.ETX)
55 table.sort(data.Links, compare)
57 luci.template.render("status-olsr/index", {links=data.Links})
60 function action_routes()
61 local data = fetch_txtinfo("routes")
63 if not data or not data.Routes then
64 luci.template.render("status-olsr/error_olsr")
68 local function compare(a, b)
69 if tonumber(a.ETX) == 0 then
73 if tonumber(b.ETX) == 0 then
77 return tonumber(a.ETX) < tonumber(b.ETX)
80 table.sort(data.Routes, compare)
82 luci.template.render("status-olsr/routes", {routes=data.Routes})
85 function action_topology()
86 local data = fetch_txtinfo("topology")
88 if not data or not data.Topology then
89 luci.template.render("status-olsr/error_olsr")
93 local function compare(a, b)
94 return a["Destination IP"] < b["Destination IP"]
97 table.sort(data.Topology, compare)
99 luci.template.render("status-olsr/topology", {routes=data.Topology})
102 function action_hna()
103 local data = fetch_txtinfo("hna")
105 if not data or not data.HNA then
106 luci.template.render("status-olsr/error_olsr")
110 local function compare(a, b)
111 return a.Network < b.Network
114 table.sort(data.HNA, compare)
116 luci.template.render("status-olsr/hna", {routes=data.HNA})
119 function action_mid()
120 local data = fetch_txtinfo("mid")
122 if not data or not data.MID then
123 luci.template.render("status-olsr/error_olsr")
127 local function compare(a, b)
131 table.sort(data.MID, compare)
133 luci.template.render("status-olsr/mid", {mids=data.MID})
138 function fetch_txtinfo(otable)
140 otable = otable or ""
141 local rawdata = luci.sys.httpget("http://127.0.0.1:2006/"..otable)
143 if #rawdata == 0 then
149 local tables = luci.util.split(luci.util.trim(rawdata), "\n\n")
152 for i, tbl in ipairs(tables) do
153 local lines = luci.util.split(tbl, "\n")
154 local name = table.remove(lines, 1):sub(8)
155 local keys = luci.util.split(table.remove(lines, 1), "\t")
159 for j, line in ipairs(lines) do
160 local fields = luci.util.split(line, "\t")
162 for k, key in pairs(keys) do
163 data[name][j][key] = fields[k]