1 module("luci.controller.olsr", package.seeall)
4 if not nixio.fs.access("/etc/config/olsrd") then
8 require("luci.model.uci")
9 local uci = luci.model.uci.cursor_state()
11 uci:foreach("olsrd", "olsrd", function(s)
12 if s.SmartGateway and s.SmartGateway == "yes" then has_smartgw = true end
15 local page = node("admin", "status", "olsr")
16 page.target = template("status-olsr/overview")
17 page.title = _("OLSR")
20 local page = node("admin", "status", "olsr", "json")
21 page.target = call("action_json")
25 local page = node("admin", "status", "olsr", "neighbors")
26 page.target = call("action_neigh")
27 page.title = _("Neighbours")
31 local page = node("admin", "status", "olsr", "routes")
32 page.target = call("action_routes")
33 page.title = _("Routes")
36 local page = node("admin", "status", "olsr", "topology")
37 page.target = call("action_topology")
38 page.title = _("Topology")
41 local page = node("admin", "status", "olsr", "hna")
42 page.target = call("action_hna")
46 local page = node("admin", "status", "olsr", "mid")
47 page.target = call("action_mid")
52 local page = node("admin", "status", "olsr", "smartgw")
53 page.target = call("action_smartgw")
54 page.title = _("SmartGW")
58 local page = node("admin", "status", "olsr", "interfaces")
59 page.target = call("action_interfaces")
60 page.title = _("Interfaces")
64 {"admin", "services", "olsrd"},
65 cbi("olsr/olsrd"), "OLSR"
70 {"admin", "services", "olsrd", "iface"},
71 cbi("olsr/olsrdiface")
75 {"admin", "services", "olsrd", "hna"},
76 cbi("olsr/olsrdhna"), _("HNA Announcements")
80 {"admin", "services", "olsrd", "plugins"},
81 cbi("olsr/olsrdplugins"), _("Plugins")
85 {"admin", "services", "olsrd", "display"},
86 cbi("olsr/olsrddisplay"), _("Display")
92 local uci = require("luci.model.uci").cursor()
93 uci:foreach("olsrd", "LoadPlugin",
95 local lib = section.library
97 {"admin", "services", "olsrd", "plugins", lib },
98 cbi("olsr/olsrdplugins"),
99 nil --'Plugin "%s"' % lib:gsub("^olsrd_",""):gsub("%.so.+$","")
105 function action_json()
106 local http = require "luci.http"
107 local utl = require "luci.util"
109 local jsonreq4 = utl.exec("echo /status | nc 127.0.0.1 9090")
110 local jsonreq6 = utl.exec("echo /status | nc ::1 9090")
111 http.prepare_content("application/json")
113 if #jsonreq4 < 1 then
117 if #jsonreq6 < 1 then
121 http.write("{v4:" .. jsonreq4 .. ", v6:" .. jsonreq6 .. "}")
124 function action_neigh(json)
125 local data, has_v4, has_v6, error = fetch_jsoninfo('links')
131 local uci = require "luci.model.uci".cursor_state()
132 local resolve = uci:get("luci_olsr", "general", "resolve")
133 luci.sys.net.routes(function(r) if r.dest:prefix() == 0 then defaultgw = r.gateway:string() end end)
135 local function compare(a,b)
136 if a.proto == b.proto then
137 return a.linkCost < b.linkCost
139 return a.proto < b.proto
143 for k, v in ipairs(data) do
144 if resolve == "1" then
145 hostname = nixio.getnameinfo(v.remoteIP, nil, 100)
147 v.hostname = hostname
150 if defaultgw == v.remoteIP then
155 table.sort(data, compare)
156 luci.template.render("status-olsr/neighbors", {links=data, has_v4=has_v4, has_v6=has_v6})
159 function action_routes()
160 local data, has_v4, has_v6, error = fetch_jsoninfo('routes')
165 local uci = require "luci.model.uci".cursor_state()
166 local resolve = uci:get("luci_olsr", "general", "resolve")
168 for k, v in ipairs(data) do
169 if resolve == "1" then
170 local hostname = nixio.getnameinfo(v.gateway, nil, 100)
172 v.hostname = hostname
177 local function compare(a,b)
178 if a.proto == b.proto then
179 return a.rtpMetricCost < b.rtpMetricCost
181 return a.proto < b.proto
185 table.sort(data, compare)
186 luci.template.render("status-olsr/routes", {routes=data, has_v4=has_v4, has_v6=has_v6})
189 function action_topology()
190 local data, has_v4, has_v6, error = fetch_jsoninfo('topology')
195 local function compare(a,b)
196 if a.proto == b.proto then
197 return a.tcEdgeCost < b.tcEdgeCost
199 return a.proto < b.proto
203 table.sort(data, compare)
204 luci.template.render("status-olsr/topology", {routes=data, has_v4=has_v4, has_v6=has_v6})
207 function action_hna()
208 local data, has_v4, has_v6, error = fetch_jsoninfo('hna')
213 local uci = require "luci.model.uci".cursor_state()
214 local resolve = uci:get("luci_olsr", "general", "resolve")
216 local function compare(a,b)
217 if a.proto == b.proto then
218 return a.genmask < b.genmask
220 return a.proto < b.proto
224 for k, v in ipairs(data) do
225 if resolve == "1" then
226 hostname = nixio.getnameinfo(v.gateway, nil, 100)
228 v.hostname = hostname
231 if v.validityTime then
232 v.validityTime = tonumber(string.format("%.0f", v.validityTime / 1000))
236 table.sort(data, compare)
237 luci.template.render("status-olsr/hna", {hna=data, has_v4=has_v4, has_v6=has_v6})
240 function action_mid()
241 local data, has_v4, has_v6, error = fetch_jsoninfo('mid')
246 local function compare(a,b)
247 if a.proto == b.proto then
248 return a.ipAddress < b.ipAddress
250 return a.proto < b.proto
254 table.sort(data, compare)
255 luci.template.render("status-olsr/mid", {mids=data, has_v4=has_v4, has_v6=has_v6})
258 function action_smartgw()
259 local data, has_v4, has_v6, error = fetch_jsoninfo('gateways')
264 local function compare(a,b)
265 if a.proto == b.proto then
266 return a.tcPathCost < b.tcPathCost
268 return a.proto < b.proto
272 table.sort(data, compare)
273 luci.template.render("status-olsr/smartgw", {gws=data, has_v4=has_v4, has_v6=has_v6})
276 function action_interfaces()
277 local data, has_v4, has_v6, error = fetch_jsoninfo('interfaces')
282 local function compare(a,b)
283 return a.proto < b.proto
286 table.sort(data, compare)
287 luci.template.render("status-olsr/interfaces", {iface=data, has_v4=has_v4, has_v6=has_v6})
291 function fetch_jsoninfo(otable)
292 local utl = require "luci.util"
293 local json = require "luci.json"
294 local jsonreq4 = utl.exec("echo /" .. otable .. " | nc 127.0.0.1 9090")
296 local jsonreq6 = utl.exec("echo /" .. otable .. " | nc ::1 9090")
303 if jsonreq4 == '' and jsonreq6 == '' then
304 luci.template.render("status-olsr/error_olsr")
305 return nil, 0, 0, true
308 if #jsonreq4 ~= 0 then
310 jsondata4 = json.decode(jsonreq4)
311 if otable == 'status' then
314 data4 = jsondata4[otable]
317 for k, v in ipairs(data4) do
318 data4[k]['proto'] = '4'
321 if #jsonreq6 ~= 0 then
323 jsondata6 = json.decode(jsonreq6)
324 if otable == 'status' then
327 data6 = jsondata6[otable]
329 for k, v in ipairs(data6) do
330 data6[k]['proto'] = '6'
334 for k, v in ipairs(data6) do
335 table.insert(data4, v)
338 return data4, has_v4, has_v6, false