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")
38 {"admin", "services", "olsrd"},
39 cbi("olsr/olsrd"), "OLSR"
45 {"admin", "services", "olsrd", "hna"},
46 cbi("olsr/olsrdhna"), "HNA Announcements"
50 {"admin", "services", "olsrd", "plugins"},
51 cbi("olsr/olsrdplugins"), "Plugins"
57 local uci = require("luci.model.uci").cursor()
58 uci:foreach("olsrd", "LoadPlugin",
60 local lib = section.library
62 {"admin", "services", "olsrd", "plugins", lib },
63 cbi("olsr/olsrdplugins"),
64 nil --'Plugin "%s"' % lib:gsub("^olsrd_",""):gsub("%.so.+$","")
70 function action_index()
71 local data = fetch_txtinfo("links")
73 if not data or not data.Links then
74 luci.template.render("status-olsr/error_olsr")
78 local function compare(a, b)
79 local c = tonumber(a.Cost)
80 local d = tonumber(b.Cost)
82 if not c or c == 0 then
86 if not d or d == 0 then
93 table.sort(data.Links, compare)
95 luci.template.render("status-olsr/index", {links=data.Links})
98 function action_routes()
99 local data = fetch_txtinfo("routes")
101 if not data or not data.Routes then
102 luci.template.render("status-olsr/error_olsr")
106 local function compare(a, b)
107 local c = tonumber(a.ETX)
108 local d = tonumber(b.ETX)
110 if not c or c == 0 then
114 if not d or d == 0 then
121 table.sort(data.Routes, compare)
123 luci.template.render("status-olsr/routes", {routes=data.Routes})
126 function action_topology()
127 local data = fetch_txtinfo("topology")
129 if not data or not data.Topology then
130 luci.template.render("status-olsr/error_olsr")
134 local function compare(a, b)
135 return a["Dest. IP"] < b["Dest. IP"]
138 table.sort(data.Topology, compare)
140 luci.template.render("status-olsr/topology", {routes=data.Topology})
143 function action_hna()
144 local data = fetch_txtinfo("hna")
146 if not data or not data.HNA then
147 luci.template.render("status-olsr/error_olsr")
151 local function compare(a, b)
152 return a.Destination < b.Destination
155 table.sort(data.HNA, compare)
157 luci.template.render("status-olsr/hna", {routes=data.HNA})
160 function action_mid()
161 local data = fetch_txtinfo("mid")
163 if not data or not data.MID then
164 luci.template.render("status-olsr/error_olsr")
168 local function compare(a, b)
169 return a["IP address"] < b["IP address"]
172 table.sort(data.MID, compare)
174 luci.template.render("status-olsr/mid", {mids=data.MID})
179 function fetch_txtinfo(otable)
181 otable = otable or ""
182 local rawdata = luci.sys.httpget("http://127.0.0.1:2006/"..otable)
184 if #rawdata == 0 then
185 if nixio.fs.access("/proc/net/ipv6_route", "r") then
186 rawdata = luci.sys.httpget("http://[::1]:2006/"..otable)
187 if #rawdata == 0 then
197 local tables = luci.util.split(luci.util.trim(rawdata), "\r?\n\r?\n", nil, true)
200 for i, tbl in ipairs(tables) do
201 local lines = luci.util.split(tbl, "\r?\n", nil, true)
202 local name = table.remove(lines, 1):sub(8)
203 local keys = luci.util.split(table.remove(lines, 1), "\t")
204 local split = #keys - 1
208 for j, line in ipairs(lines) do
209 local fields = luci.util.split(line, "\t", split)
211 for k, key in pairs(keys) do
212 data[name][j][key] = fields[k]
215 if data[name][j].Linkcost then
216 data[name][j].LinkQuality,
219 data[name][j].Linkcost:match("([%w.]+)/([%w.]+)[%s]+([%w.]+)")