1 module("luci.controller.olsr", package.seeall)
4 if not nixio.fs.access("/etc/config/olsrd") then
8 require("luci.i18n").loadc("olsr")
9 local i18n = luci.i18n.translate
11 local page = node("admin", "status", "olsr")
12 page.target = template("status-olsr/overview")
17 local page = node("admin", "status", "olsr", "neighbors")
18 page.target = call("action_neigh")
19 page.title = i18n("Neighbors")
23 local page = node("admin", "status", "olsr", "routes")
24 page.target = call("action_routes")
25 page.title = i18n("Routen")
28 local page = node("admin", "status", "olsr", "topology")
29 page.target = call("action_topology")
30 page.title = i18n("Topologie")
33 local page = node("admin", "status", "olsr", "hna")
34 page.target = call("action_hna")
38 local page = node("admin", "status", "olsr", "mid")
39 page.target = call("action_mid")
43 local page = node("admin", "status", "olsr", "smartgw")
44 page.target = call("action_smartgw")
45 page.title = "SmartGW"
48 local page = node("admin", "status", "olsr", "interfaces")
49 page.target = call("action_interfaces")
50 page.title = i18n("Interfaces")
54 {"admin", "services", "olsrd"},
55 cbi("olsr/olsrd"), "OLSR"
61 {"admin", "services", "olsrd", "iface"},
62 cbi("olsr/olsrdiface")
66 {"admin", "services", "olsrd", "hna"},
67 cbi("olsr/olsrdhna"), "HNA Announcements"
71 {"admin", "services", "olsrd", "plugins"},
72 cbi("olsr/olsrdplugins"), "Plugins"
78 local uci = require("luci.model.uci").cursor()
79 uci:foreach("olsrd", "LoadPlugin",
81 local lib = section.library
83 {"admin", "services", "olsrd", "plugins", lib },
84 cbi("olsr/olsrdplugins"),
85 nil --'Plugin "%s"' % lib:gsub("^olsrd_",""):gsub("%.so.+$","")
91 function action_neigh()
92 local data = fetch_txtinfo("links")
94 if not data or not data.Links then
95 luci.template.render("status-olsr/error_olsr")
99 local function compare(a, b)
100 local c = tonumber(a.Cost)
101 local d = tonumber(b.Cost)
103 if not c or c == 0 then
107 if not d or d == 0 then
114 table.sort(data.Links, compare)
116 luci.template.render("status-olsr/neighbors", {links=data.Links})
119 function action_routes()
120 local data = fetch_txtinfo("routes")
122 if not data or not data.Routes then
123 luci.template.render("status-olsr/error_olsr")
127 local function compare(a, b)
128 local c = tonumber(a.ETX)
129 local d = tonumber(b.ETX)
131 if not c or c == 0 then
135 if not d or d == 0 then
142 table.sort(data.Routes, compare)
144 luci.template.render("status-olsr/routes", {routes=data.Routes})
147 function action_topology()
148 local data = fetch_txtinfo("topology")
150 if not data or not data.Topology then
151 luci.template.render("status-olsr/error_olsr")
155 local function compare(a, b)
156 return a["Dest. IP"] < b["Dest. IP"]
159 table.sort(data.Topology, compare)
161 luci.template.render("status-olsr/topology", {routes=data.Topology})
164 function action_hna()
165 local data = fetch_txtinfo("hna")
167 if not data or not data.HNA then
168 luci.template.render("status-olsr/error_olsr")
172 local function compare(a, b)
173 return a.Destination < b.Destination
176 table.sort(data.HNA, compare)
178 luci.template.render("status-olsr/hna", {routes=data.HNA})
181 function action_mid()
182 local data = fetch_txtinfo("mid")
184 if not data or not data.MID then
185 luci.template.render("status-olsr/error_olsr")
189 local function compare(a, b)
190 return a["IP address"] < b["IP address"]
193 table.sort(data.MID, compare)
195 luci.template.render("status-olsr/mid", {mids=data.MID})
198 function action_smartgw()
199 local data = fetch_txtinfo("gateways")
201 if not data or not data.Gateways then
202 luci.template.render("status-olsr/error_olsr")
206 local function compare(a, b)
207 return a["ETX"] < b["ETX"]
210 table.sort(data.Gateways, compare)
212 luci.template.render("status-olsr/smartgw", {gws=data.Gateways})
215 function action_interfaces()
216 local data = fetch_txtinfo("interfaces")
218 if not data or not data.Interfaces then
219 luci.template.render("status-olsr/error_olsr")
223 luci.template.render("status-olsr/interfaces", {iface=data.Interfaces})
227 function fetch_txtinfo(otable)
229 local uci = require "luci.model.uci".cursor_state()
230 otable = otable or ""
231 local rawdata = luci.sys.httpget("http://127.0.0.1:2006/"..otable)
232 local rawdatav6 = luci.sys.httpget("http://[::1]:2006/"..otable)
238 if #rawdata ~= 0 then
239 local tables = luci.util.split(luci.util.trim(rawdata), "\r?\n\r?\n", nil, true)
241 if otable == "links" then
243 for i, route in ipairs(luci.sys.net.routes()) do
244 if route.dest:prefix() == 0 then
245 defaultgw = route.gateway:string()
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 hostname = nixio.getnameinfo(fields[k], "inet")
269 data[name][di]["Hostname"] = hostname
271 if key == "Remote IP" and defaultgw then
272 if defaultgw == fields[k] then
273 data[name][di]["defaultgw"] = 1
276 elseif key == "Local IP" then
277 data[name][di][key] = fields[k]
278 data[name][di]['Local Device'] = fields[k]
279 uci:foreach("network", "interface",
281 localip = string.gsub(fields[k], ' ', '')
282 if s.ipaddr == localip then
283 data[name][di]['Local Device'] = s['.name'] or interface
286 elseif key == "Interface" then
287 data[name][di][key] = fields[k]
288 uci:foreach("network", "interface",
290 interface = string.gsub(fields[k], ' ', '')
291 if s.ifname == interface then
292 data[name][di][key] = s['.name'] or interface
296 data[name][di][key] = fields[k]
299 if data[name][di].Linkcost then
300 data[name][di].LinkQuality,
303 data[name][di].Linkcost:match("([%w.]+)/([%w.]+)[%s]+([%w.]+)")
309 if #rawdatav6 ~= 0 then
310 local tables = luci.util.split(luci.util.trim(rawdatav6), "\r?\n\r?\n", nil, true)
311 for i, tbl in ipairs(tables) do
312 local lines = luci.util.split(tbl, "\r?\n", nil, true)
313 name = table.remove(lines, 1):sub(8)
314 local keys = luci.util.split(table.remove(lines, 1), "\t")
315 local split = #keys - 1
316 if not data[name] then
319 for j, line in ipairs(lines) do
320 dataindex = ( dataindex + 1 )
322 local fields = luci.util.split(line, "\t", split)
324 for k, key in pairs(keys) do
325 if key == "Remote IP" then
326 data[name][di][key] = "[" .. fields[k] .. "]"
327 hostname = nixio.getnameinfo(fields[k], "inet6")
329 data[name][di]["Hostname"] = hostname
331 elseif key == "Local IP" then
332 data[name][di][key] = fields[k]
333 data[name][di]['Local Device'] = fields[k]
334 uci:foreach("network", "interface",
336 local localip = string.gsub(fields[k], ' ', '')
338 local ip6addr = string.gsub(s.ip6addr, '\/.*', '')
339 if ip6addr == localip then
340 data[name][di]['Local Device'] = s['.name'] or s.interface
344 elseif key == "Dest. IP" then
345 data[name][di][key] = "[" .. fields[k] .. "]"
346 elseif key == "Last hop IP" then
347 data[name][di][key] = "[" .. fields[k] .. "]"
348 elseif key == "IP address" then
349 data[name][di][key] = "[" .. fields[k] .. "]"
350 elseif key == "Gateway" then
351 data[name][di][key] = "[" .. fields[k] .. "]"
353 data[name][di][key] = fields[k]
357 if data[name][di].Linkcost then
358 data[name][di].LinkQuality,
361 data[name][di].Linkcost:match("([%w.]+)/([%w.]+)[%s]+([%w.]+)")