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")
112 http.prepare_content("application/json")
113 http.write("{v4:" .. jsonreq4 .. ", v6:" .. jsonreq6 .. "}")
116 function action_neigh(json)
117 local data, has_v4, has_v6, error = fetch_jsoninfo('links')
123 local uci = require "luci.model.uci".cursor_state()
124 local resolve = uci:get("luci_olsr", "general", "resolve")
125 luci.sys.net.routes(function(r) if r.dest:prefix() == 0 then defaultgw = r.gateway:string() end end)
127 local function compare(a,b)
128 if a.proto == b.proto then
129 return a.linkCost < b.linkCost
131 return a.proto < b.proto
135 for k, v in ipairs(data) do
136 if resolve == "1" then
137 hostname = nixio.getnameinfo(v.remoteIP, nil, 100)
139 v.hostname = hostname
142 if defaultgw == v.remoteIP then
147 table.sort(data, compare)
148 luci.template.render("status-olsr/neighbors", {links=data, has_v4=has_v4, has_v6=has_v6})
151 function action_routes()
152 local data, has_v4, has_v6, error = fetch_jsoninfo('routes')
157 local uci = require "luci.model.uci".cursor_state()
158 local resolve = uci:get("luci_olsr", "general", "resolve")
160 for k, v in ipairs(data) do
161 if resolve == "1" then
162 local hostname = nixio.getnameinfo(v.gateway, nil, 100)
164 v.hostname = hostname
169 local function compare(a,b)
170 if a.proto == b.proto then
171 return a.rtpMetricCost < b.rtpMetricCost
173 return a.proto < b.proto
177 table.sort(data, compare)
178 luci.template.render("status-olsr/routes", {routes=data, has_v4=has_v4, has_v6=has_v6})
181 function action_topology()
182 local data, has_v4, has_v6, error = fetch_jsoninfo('topology')
187 local function compare(a,b)
188 if a.proto == b.proto then
189 return a.tcEdgeCost < b.tcEdgeCost
191 return a.proto < b.proto
195 table.sort(data, compare)
196 luci.template.render("status-olsr/topology", {routes=data, has_v4=has_v4, has_v6=has_v6})
199 function action_hna()
200 local data, has_v4, has_v6, error = fetch_jsoninfo('hna')
205 local uci = require "luci.model.uci".cursor_state()
206 local resolve = uci:get("luci_olsr", "general", "resolve")
208 local function compare(a,b)
209 if a.proto == b.proto then
210 return a.genmask < b.genmask
212 return a.proto < b.proto
216 for k, v in ipairs(data) do
217 if resolve == "1" then
218 hostname = nixio.getnameinfo(v.gateway, nil, 100)
220 v.hostname = hostname
223 if v.validityTime then
224 v.validityTime = tonumber(string.format("%.0f", v.validityTime / 1000))
228 table.sort(data, compare)
229 luci.template.render("status-olsr/hna", {hna=data, has_v4=has_v4, has_v6=has_v6})
232 function action_mid()
233 local data, has_v4, has_v6, error = fetch_jsoninfo('mid')
238 local function compare(a,b)
239 if a.proto == b.proto then
240 return a.ipAddress < b.ipAddress
242 return a.proto < b.proto
246 table.sort(data, compare)
247 luci.template.render("status-olsr/mid", {mids=data, has_v4=has_v4, has_v6=has_v6})
250 function action_smartgw()
251 local data, has_v4, has_v6, error = fetch_jsoninfo('gateways')
256 local function compare(a,b)
257 if a.proto == b.proto then
258 return a.tcPathCost < b.tcPathCost
260 return a.proto < b.proto
264 table.sort(data, compare)
265 luci.template.render("status-olsr/smartgw", {gws=data, has_v4=has_v4, has_v6=has_v6})
268 function action_interfaces()
269 local data, has_v4, has_v6, error = fetch_jsoninfo('interfaces')
274 local function compare(a,b)
275 return a.proto < b.proto
278 table.sort(data, compare)
279 luci.template.render("status-olsr/interfaces", {iface=data, has_v4=has_v4, has_v6=has_v6})
283 function fetch_jsoninfo(otable)
284 local utl = require "luci.util"
285 local json = require "luci.json"
286 local jsonreq4 = utl.exec("echo /" .. otable .. " | nc 127.0.0.1 9090")
288 local jsonreq6 = utl.exec("echo /" .. otable .. " | nc ::1 9090")
295 if jsonreq4 == '' and jsonreq6 == '' then
296 luci.template.render("status-olsr/error_olsr")
297 return nil, 0, 0, true
300 if #jsonreq4 ~= 0 then
302 jsondata4 = json.decode(jsonreq4)
303 if otable == 'status' then
306 data4 = jsondata4[otable]
309 for k, v in ipairs(data4) do
310 data4[k]['proto'] = '4'
313 if #jsonreq6 ~= 0 then
315 jsondata6 = json.decode(jsonreq6)
316 if otable == 'status' then
319 data6 = jsondata6[otable]
321 for k, v in ipairs(data6) do
322 data6[k]['proto'] = '6'
326 for k, v in ipairs(data6) do
327 table.insert(data4, v)
330 return data4, has_v4, has_v6, false