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 = call("action_index")
17 local page = node("admin", "status", "olsr", "routes")
18 page.target = call("action_routes")
19 page.title = i18n("Routen")
22 local page = node("admin", "status", "olsr", "topology")
23 page.target = call("action_topology")
24 page.title = i18n("Topologie")
27 local page = node("admin", "status", "olsr", "hna")
28 page.target = call("action_hna")
32 local page = node("admin", "status", "olsr", "mid")
33 page.target = call("action_mid")
37 local page = node("admin", "status", "olsr", "smartgw")
38 page.target = call("action_smartgw")
39 page.title = "SmartGW"
43 {"admin", "services", "olsrd"},
44 cbi("olsr/olsrd"), "OLSR"
50 {"admin", "services", "olsrd", "iface"},
51 cbi("olsr/olsrdiface")
55 {"admin", "services", "olsrd", "hna"},
56 cbi("olsr/olsrdhna"), "HNA Announcements"
60 {"admin", "services", "olsrd", "plugins"},
61 cbi("olsr/olsrdplugins"), "Plugins"
67 local uci = require("luci.model.uci").cursor()
68 uci:foreach("olsrd", "LoadPlugin",
70 local lib = section.library
72 {"admin", "services", "olsrd", "plugins", lib },
73 cbi("olsr/olsrdplugins"),
74 nil --'Plugin "%s"' % lib:gsub("^olsrd_",""):gsub("%.so.+$","")
80 function action_index()
81 local data = fetch_txtinfo("links")
83 if not data or not data.Links then
84 luci.template.render("status-olsr/error_olsr")
88 local function compare(a, b)
89 local c = tonumber(a.Cost)
90 local d = tonumber(b.Cost)
92 if not c or c == 0 then
96 if not d or d == 0 then
103 table.sort(data.Links, compare)
105 luci.template.render("status-olsr/index", {links=data.Links})
108 function action_routes()
109 local data = fetch_txtinfo("routes")
111 if not data or not data.Routes then
112 luci.template.render("status-olsr/error_olsr")
116 local function compare(a, b)
117 local c = tonumber(a.ETX)
118 local d = tonumber(b.ETX)
120 if not c or c == 0 then
124 if not d or d == 0 then
131 table.sort(data.Routes, compare)
133 luci.template.render("status-olsr/routes", {routes=data.Routes})
136 function action_topology()
137 local data = fetch_txtinfo("topology")
139 if not data or not data.Topology then
140 luci.template.render("status-olsr/error_olsr")
144 local function compare(a, b)
145 return a["Dest. IP"] < b["Dest. IP"]
148 table.sort(data.Topology, compare)
150 luci.template.render("status-olsr/topology", {routes=data.Topology})
153 function action_hna()
154 local data = fetch_txtinfo("hna")
156 if not data or not data.HNA then
157 luci.template.render("status-olsr/error_olsr")
161 local function compare(a, b)
162 return a.Destination < b.Destination
165 table.sort(data.HNA, compare)
167 luci.template.render("status-olsr/hna", {routes=data.HNA})
170 function action_mid()
171 local data = fetch_txtinfo("mid")
173 if not data or not data.MID then
174 luci.template.render("status-olsr/error_olsr")
178 local function compare(a, b)
179 return a["IP address"] < b["IP address"]
182 table.sort(data.MID, compare)
184 luci.template.render("status-olsr/mid", {mids=data.MID})
187 function action_smartgw()
188 local data = fetch_txtinfo("gateways")
190 if not data or not data.Gateways then
191 luci.template.render("status-olsr/error_olsr")
195 local function compare(a, b)
196 return a["ETX"] < b["ETX"]
199 table.sort(data.Gateways, compare)
201 luci.template.render("status-olsr/smartgw", {gws=data.Gateways})
207 function fetch_txtinfo(otable)
209 local uci = require "luci.model.uci".cursor_state()
210 otable = otable or ""
211 local rawdata = luci.sys.httpget("http://127.0.0.1:2006/"..otable)
212 local rawdatav6 = luci.sys.httpget("http://[::1]:2006/"..otable)
217 if #rawdata ~= 0 then
218 local tables = luci.util.split(luci.util.trim(rawdata), "\r?\n\r?\n", nil, true)
220 for i, tbl in ipairs(tables) do
221 local lines = luci.util.split(tbl, "\r?\n", nil, true)
222 name = table.remove(lines, 1):sub(8)
223 local keys = luci.util.split(table.remove(lines, 1), "\t")
224 local split = #keys - 1
225 if not data[name] then
229 for j, line in ipairs(lines) do
230 dataindex = ( dataindex + 1 )
232 local fields = luci.util.split(line, "\t", split)
234 for k, key in pairs(keys) do
235 if key == "Remote IP" or key == "Dest. IP" or key == "Gateway IP" or key == "Gateway" then
236 hostname = nixio.getnameinfo(fields[k], "inet")
238 data[name][di][key] = fields[k]
239 data[name][di]["Hostname"] = hostname
241 data[name][di][key] = fields[k]
243 elseif key == "Local IP" then
244 data[name][di][key] = fields[k]
245 data[name][di]['Local Device'] = fields[k]
246 uci:foreach("network", "interface",
248 localip = string.gsub(fields[k], ' ', '')
249 if s.ipaddr == localip then
250 data[name][di]['Local Device'] = s['.name'] or interface
253 elseif key == "Interface" then
254 data[name][di][key] = fields[k]
255 uci:foreach("network", "interface",
257 interface = string.gsub(fields[k], ' ', '')
258 if s.ifname == interface then
259 data[name][di][key] = s['.name'] or interface
263 data[name][di][key] = fields[k]
266 if data[name][di].Linkcost then
267 data[name][di].LinkQuality,
270 data[name][di].Linkcost:match("([%w.]+)/([%w.]+)[%s]+([%w.]+)")
276 if #rawdatav6 ~= 0 then
277 local tables = luci.util.split(luci.util.trim(rawdatav6), "\r?\n\r?\n", nil, true)
278 for i, tbl in ipairs(tables) do
279 local lines = luci.util.split(tbl, "\r?\n", nil, true)
280 name = table.remove(lines, 1):sub(8)
281 local keys = luci.util.split(table.remove(lines, 1), "\t")
282 local split = #keys - 1
283 if not data[name] then
286 for j, line in ipairs(lines) do
287 dataindex = ( dataindex + 1 )
289 local fields = luci.util.split(line, "\t", split)
291 for k, key in pairs(keys) do
292 if key == "Remote IP" then
293 hostname = nixio.getnameinfo(fields[k], "inet6")
295 data[name][di][key] = "[" .. fields[k] .. "]"
296 data[name][di]["Hostname"] = hostname
298 data[name][di][key] = "[" .. fields[k] .. "]"
300 elseif key == "Local IP" then
301 data[name][di][key] = fields[k]
302 data[name][di]['Local Device'] = fields[k]
303 uci:foreach("network", "interface",
305 local localip = string.gsub(fields[k], ' ', '')
307 local ip6addr = string.gsub(s.ip6addr, '\/.*', '')
308 if ip6addr == localip then
309 data[name][di]['Local Device'] = s['.name'] or s.interface
313 elseif key == "Dest. IP" then
314 data[name][di][key] = "[" .. fields[k] .. "]"
315 elseif key == "Last hop IP" then
316 data[name][di][key] = "[" .. fields[k] .. "]"
317 elseif key == "IP address" then
318 data[name][di][key] = "[" .. fields[k] .. "]"
319 elseif key == "Gateway" then
320 data[name][di][key] = "[" .. fields[k] .. "]"
322 data[name][di][key] = fields[k]
326 if data[name][di].Linkcost then
327 data[name][di].LinkQuality,
330 data[name][di].Linkcost:match("([%w.]+)/([%w.]+)[%s]+([%w.]+)")