1 module("luci.controller.olsr", package.seeall)
4 if not nixio.fs.access("/etc/config/olsrd") then
8 local page = node("admin", "status", "olsr")
9 page.target = template("status-olsr/overview")
10 page.title = _("OLSR")
14 local page = node("admin", "status", "olsr", "neighbors")
15 page.target = call("action_neigh")
16 page.title = _("Neighbours")
20 local page = node("admin", "status", "olsr", "routes")
21 page.target = call("action_routes")
22 page.title = _("Routes")
25 local page = node("admin", "status", "olsr", "topology")
26 page.target = call("action_topology")
27 page.title = _("Topology")
30 local page = node("admin", "status", "olsr", "hna")
31 page.target = call("action_hna")
35 local page = node("admin", "status", "olsr", "mid")
36 page.target = call("action_mid")
40 local page = node("admin", "status", "olsr", "smartgw")
41 page.target = call("action_smartgw")
42 page.title = _("SmartGW")
45 local page = node("admin", "status", "olsr", "interfaces")
46 page.target = call("action_interfaces")
47 page.title = _("Interfaces")
51 {"admin", "services", "olsrd"},
52 cbi("olsr/olsrd"), "OLSR"
58 {"admin", "services", "olsrd", "iface"},
59 cbi("olsr/olsrdiface")
63 {"admin", "services", "olsrd", "hna"},
64 cbi("olsr/olsrdhna"), _("HNA Announcements")
68 {"admin", "services", "olsrd", "plugins"},
69 cbi("olsr/olsrdplugins"), _("Plugins")
73 {"admin", "services", "olsrd", "display"},
74 cbi("olsr/olsrddisplay"), _("Display")
81 local uci = require("luci.model.uci").cursor()
82 uci:foreach("olsrd", "LoadPlugin",
84 local lib = section.library
86 {"admin", "services", "olsrd", "plugins", lib },
87 cbi("olsr/olsrdplugins"),
88 nil --'Plugin "%s"' % lib:gsub("^olsrd_",""):gsub("%.so.+$","")
94 function action_neigh()
95 local data = fetch_txtinfo("links")
97 if not data or not data.Links then
98 luci.template.render("status-olsr/error_olsr")
102 local function compare(a, b)
103 local c = tonumber(a.Cost)
104 local d = tonumber(b.Cost)
106 if not c or c == 0 then
110 if not d or d == 0 then
117 table.sort(data.Links, compare)
119 luci.template.render("status-olsr/neighbors", {links=data.Links})
122 function action_routes()
123 local data = fetch_txtinfo("routes")
125 if not data or not data.Routes then
126 luci.template.render("status-olsr/error_olsr")
130 local function compare(a, b)
131 local c = tonumber(a.ETX)
132 local d = tonumber(b.ETX)
134 if not c or c == 0 then
138 if not d or d == 0 then
145 table.sort(data.Routes, compare)
147 luci.template.render("status-olsr/routes", {routes=data.Routes})
150 function action_topology()
151 local data = fetch_txtinfo("topology")
153 if not data or not data.Topology then
154 luci.template.render("status-olsr/error_olsr")
158 local function compare(a, b)
159 return a["Dest. IP"] < b["Dest. IP"]
162 table.sort(data.Topology, compare)
164 luci.template.render("status-olsr/topology", {routes=data.Topology})
167 function action_hna()
168 local data = fetch_txtinfo("hna")
170 if not data or not data.HNA then
171 luci.template.render("status-olsr/error_olsr")
175 local function compare(a, b)
176 return a.Destination < b.Destination
179 table.sort(data.HNA, compare)
181 luci.template.render("status-olsr/hna", {routes=data.HNA})
184 function action_mid()
185 local data = fetch_txtinfo("mid")
187 if not data or not data.MID then
188 luci.template.render("status-olsr/error_olsr")
192 local function compare(a, b)
193 return a["IP address"] < b["IP address"]
196 table.sort(data.MID, compare)
198 luci.template.render("status-olsr/mid", {mids=data.MID})
201 function action_smartgw()
202 local data = fetch_txtinfo("gateways")
204 if not data or not data.Gateways then
205 luci.template.render("status-olsr/error_olsr")
209 local function compare(a, b)
210 return a["ETX"] < b["ETX"]
213 table.sort(data.Gateways, compare)
215 luci.template.render("status-olsr/smartgw", {gws=data.Gateways})
218 function action_interfaces()
219 local data = fetch_txtinfo("interfaces")
221 if not data or not data.Interfaces then
222 luci.template.render("status-olsr/error_olsr")
226 luci.template.render("status-olsr/interfaces", {iface=data.Interfaces})
230 function fetch_txtinfo(otable)
232 local uci = require "luci.model.uci".cursor_state()
233 local resolve = uci:get("luci_olsr", "general", "resolve")
234 otable = otable or ""
235 local rawdata = luci.sys.httpget("http://127.0.0.1:2006/"..otable)
236 local rawdatav6 = luci.sys.httpget("http://[::1]:2006/"..otable)
242 if #rawdata ~= 0 then
243 local tables = luci.util.split(luci.util.trim(rawdata), "\r?\n\r?\n", nil, true)
245 if otable == "links" then
247 luci.sys.net.routes(function(r) if r.dest:prefix() == 0 then defaultgw = r.gateway:string() end end)
250 for i, tbl in ipairs(tables) do
251 local lines = luci.util.split(tbl, "\r?\n", nil, true)
252 name = table.remove(lines, 1):sub(8)
253 local keys = luci.util.split(table.remove(lines, 1), "\t")
254 local split = #keys - 1
255 if not data[name] then
259 for j, line in ipairs(lines) do
260 dataindex = ( dataindex + 1 )
262 local fields = luci.util.split(line, "\t", split)
264 for k, key in pairs(keys) do
265 if key == "Remote IP" or key == "Dest. IP" or key == "Gateway IP" or key == "Gateway" then
266 data[name][di][key] = fields[k]
267 if resolve == "1" then
268 hostname = nixio.getnameinfo(fields[k], "inet")
270 data[name][di]["Hostname"] = hostname
273 if key == "Remote IP" and defaultgw then
274 if defaultgw == fields[k] then
275 data[name][di]["defaultgw"] = 1
278 elseif key == "Local IP" then
279 data[name][di][key] = fields[k]
280 data[name][di]['Local Device'] = fields[k]
281 uci:foreach("network", "interface",
283 localip = string.gsub(fields[k], ' ', '')
284 if s.ipaddr == localip then
285 data[name][di]['Local Device'] = s['.name'] or interface
288 elseif key == "Interface" then
289 data[name][di][key] = fields[k]
290 uci:foreach("network", "interface",
292 interface = string.gsub(fields[k], ' ', '')
293 if s.ifname == interface then
294 data[name][di][key] = s['.name'] or interface
298 data[name][di][key] = fields[k]
301 if data[name][di].Linkcost then
302 data[name][di].LinkQuality,
305 data[name][di].Linkcost:match("([%w.]+)/([%w.]+)[%s]+([%w.]+)")
311 if #rawdatav6 ~= 0 then
312 local tables = luci.util.split(luci.util.trim(rawdatav6), "\r?\n\r?\n", nil, true)
313 for i, tbl in ipairs(tables) do
314 local lines = luci.util.split(tbl, "\r?\n", nil, true)
315 name = table.remove(lines, 1):sub(8)
316 local keys = luci.util.split(table.remove(lines, 1), "\t")
317 local split = #keys - 1
318 if not data[name] then
321 for j, line in ipairs(lines) do
322 dataindex = ( dataindex + 1 )
324 local fields = luci.util.split(line, "\t", split)
326 for k, key in pairs(keys) do
327 if key == "Remote IP" then
328 data[name][di][key] = "[" .. fields[k] .. "]"
329 if resolve == "1" then
330 hostname = nixio.getnameinfo(fields[k], "inet6")
332 data[name][di]["Hostname"] = hostname
335 elseif key == "Local IP" then
336 data[name][di][key] = fields[k]
337 data[name][di]['Local Device'] = fields[k]
338 uci:foreach("network", "interface",
340 local localip = string.gsub(fields[k], ' ', '')
342 local ip6addr = string.gsub(s.ip6addr, '\/.*', '')
343 if ip6addr == localip then
344 data[name][di]['Local Device'] = s['.name'] or s.interface
348 elseif key == "Dest. IP" then
349 data[name][di][key] = "[" .. fields[k] .. "]"
350 elseif key == "Last hop IP" then
351 data[name][di][key] = "[" .. fields[k] .. "]"
352 elseif key == "IP address" then
353 data[name][di][key] = "[" .. fields[k] .. "]"
354 elseif key == "Gateway" then
355 data[name][di][key] = "[" .. fields[k] .. "]"
357 data[name][di][key] = fields[k]
361 if data[name][di].Linkcost then
362 data[name][di].LinkQuality,
365 data[name][di].Linkcost:match("([%w.]+)/([%w.]+)[%s]+([%w.]+)")