1 module("luci.controller.olsr", package.seeall)
4 if not luci.fs.isfile("/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")
16 local page = node("admin", "status", "olsr", "routes")
17 page.target = call("action_routes")
18 page.title = i18n("olsr_routes", "Routen")
21 local page = node("admin", "status", "olsr", "topology")
22 page.target = call("action_topology")
23 page.title = i18n("olsr_topology", "Topologie")
26 local page = node("admin", "status", "olsr", "hna")
27 page.target = call("action_hna")
31 local page = node("admin", "status", "olsr", "mid")
32 page.target = call("action_mid")
37 {"admin", "services", "olsrd"},
38 cbi("olsr/olsrd"), "OLSR"
42 {"admin", "services", "olsrd", "hna"},
43 cbi("olsr/olsrdhna"), "HNA Announcements"
47 {"admin", "services", "olsrd", "plugins"},
48 cbi("olsr/olsrdplugins"), "Plugins"
53 local uci = require("luci.model.uci").cursor()
54 uci:foreach("olsrd", "LoadPlugin",
56 local lib = section.library
58 {"admin", "services", "olsrd", "plugins", lib },
59 cbi("olsr/olsrdplugins"),
60 nil --'Plugin "%s"' % lib:gsub("^olsrd_",""):gsub("%.so.+$","")
66 function action_index()
67 local data = fetch_txtinfo("links")
69 if not data or not data.Links then
70 luci.template.render("status-olsr/error_olsr")
74 local function compare(a, b)
75 local c = tonumber(a.ETX)
76 local d = tonumber(b.ETX)
78 if not c or c == 0 then
82 if not d or d == 0 then
89 table.sort(data.Links, compare)
91 luci.template.render("status-olsr/index", {links=data.Links})
94 function action_routes()
95 local data = fetch_txtinfo("routes")
97 if not data or not data.Routes then
98 luci.template.render("status-olsr/error_olsr")
102 local function compare(a, b)
103 local c = tonumber(a.ETX)
104 local d = tonumber(b.ETX)
106 if not c or c == 0 then
110 if not d or d == 0 then
117 table.sort(data.Routes, compare)
119 luci.template.render("status-olsr/routes", {routes=data.Routes})
122 function action_topology()
123 local data = fetch_txtinfo("topology")
125 if not data or not data.Topology then
126 luci.template.render("status-olsr/error_olsr")
130 local function compare(a, b)
131 return a["Destination IP"] < b["Destination IP"]
134 table.sort(data.Topology, compare)
136 luci.template.render("status-olsr/topology", {routes=data.Topology})
139 function action_hna()
140 local data = fetch_txtinfo("hna")
142 if not data or not data.HNA then
143 luci.template.render("status-olsr/error_olsr")
147 local function compare(a, b)
148 return a.Network < b.Network
151 table.sort(data.HNA, compare)
153 luci.template.render("status-olsr/hna", {routes=data.HNA})
156 function action_mid()
157 local data = fetch_txtinfo("mid")
159 if not data or not data.MID then
160 luci.template.render("status-olsr/error_olsr")
164 local function compare(a, b)
168 table.sort(data.MID, compare)
170 luci.template.render("status-olsr/mid", {mids=data.MID})
175 function fetch_txtinfo(otable)
177 otable = otable or ""
178 local rawdata = luci.sys.httpget("http://127.0.0.1:2006/"..otable)
180 if #rawdata == 0 then
186 local tables = luci.util.split(luci.util.trim(rawdata), "\r?\n\r?\n", nil, true)
189 for i, tbl in ipairs(tables) do
190 local lines = luci.util.split(tbl, "\r?\n", nil, true)
191 local name = table.remove(lines, 1):sub(8)
192 local keys = luci.util.split(table.remove(lines, 1), "\t")
193 local split = #keys - 1
197 for j, line in ipairs(lines) do
198 local fields = luci.util.split(line, "\t", split)
200 for k, key in pairs(keys) do
201 data[name][j][key] = fields[k]
204 if data[name][j].Linkcost then
205 data[name][j].LinkQuality,
208 data[name][j].Linkcost:match("([%w.]+)/([%w.]+)[%s]+([%w.]+)")