1 module("luci.controller.olsr", package.seeall)
4 if not luci.fs.isfile("/etc/config/olsr") then
8 require("luci.i18n").loadc("olsr")
9 local i18n = luci.i18n.translate
11 local page = node("admin", "status", "olsr")
12 page.target = call("action_index")
16 local page = node("admin", "status", "olsr", "routes")
17 page.target = call("action_routes")
18 page.title = i18n("olsr_routes", "Routen")
21 local page = node("admin", "status", "olsr", "topology")
22 page.target = call("action_topology")
23 page.title = i18n("olsr_topology", "Topologie")
26 local page = node("admin", "status", "olsr", "hna")
27 page.target = call("action_hna")
31 local page = node("admin", "status", "olsr", "mid")
32 page.target = call("action_mid")
36 entry({"admin", "services", "olsrd"}, cbi("olsr/olsrd"), "OLSR").i18n = "olsr"
39 function action_index()
40 local data = fetch_txtinfo("links")
42 if not data or not data.Links then
43 luci.template.render("status-olsr/error_olsr")
47 local function compare(a, b)
48 local c = tonumber(a.ETX)
49 local d = tonumber(b.ETX)
51 if not c or c == 0 then
55 if not d or d == 0 then
62 table.sort(data.Links, compare)
64 luci.template.render("status-olsr/index", {links=data.Links})
67 function action_routes()
68 local data = fetch_txtinfo("routes")
70 if not data or not data.Routes then
71 luci.template.render("status-olsr/error_olsr")
75 local function compare(a, b)
76 local c = tonumber(a.ETX)
77 local d = tonumber(b.ETX)
79 if not c or c == 0 then
83 if not d or d == 0 then
90 table.sort(data.Routes, compare)
92 luci.template.render("status-olsr/routes", {routes=data.Routes})
95 function action_topology()
96 local data = fetch_txtinfo("topology")
98 if not data or not data.Topology then
99 luci.template.render("status-olsr/error_olsr")
103 local function compare(a, b)
104 return a["Destination IP"] < b["Destination IP"]
107 table.sort(data.Topology, compare)
109 luci.template.render("status-olsr/topology", {routes=data.Topology})
112 function action_hna()
113 local data = fetch_txtinfo("hna")
115 if not data or not data.HNA then
116 luci.template.render("status-olsr/error_olsr")
120 local function compare(a, b)
121 return a.Network < b.Network
124 table.sort(data.HNA, compare)
126 luci.template.render("status-olsr/hna", {routes=data.HNA})
129 function action_mid()
130 local data = fetch_txtinfo("mid")
132 if not data or not data.MID then
133 luci.template.render("status-olsr/error_olsr")
137 local function compare(a, b)
141 table.sort(data.MID, compare)
143 luci.template.render("status-olsr/mid", {mids=data.MID})
148 function fetch_txtinfo(otable)
150 otable = otable or ""
151 local rawdata = luci.sys.httpget("http://127.0.0.1:2006/"..otable)
153 if #rawdata == 0 then
159 local tables = luci.util.split(luci.util.trim(rawdata), "\r?\n\r?\n", nil, true)
162 for i, tbl in ipairs(tables) do
163 local lines = luci.util.split(tbl, "\r?\n", nil, true)
164 local name = table.remove(lines, 1):sub(8)
165 local keys = luci.util.split(table.remove(lines, 1), "\t")
166 local split = #keys - 1
170 for j, line in ipairs(lines) do
171 local fields = luci.util.split(line, "\t", split)
173 for k, key in pairs(keys) do
174 data[name][j][key] = fields[k]
177 if data[name][j].Linkcost then
178 data[name][j].LinkQuality,
181 data[name][j].Linkcost:match("([%w.]+)/([%w.]+)[%s]+([%w.]+)")