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"
52 function action_index()
53 local data = fetch_txtinfo("links")
55 if not data or not data.Links then
56 luci.template.render("status-olsr/error_olsr")
60 local function compare(a, b)
61 local c = tonumber(a.ETX)
62 local d = tonumber(b.ETX)
64 if not c or c == 0 then
68 if not d or d == 0 then
75 table.sort(data.Links, compare)
77 luci.template.render("status-olsr/index", {links=data.Links})
80 function action_routes()
81 local data = fetch_txtinfo("routes")
83 if not data or not data.Routes then
84 luci.template.render("status-olsr/error_olsr")
88 local function compare(a, b)
89 local c = tonumber(a.ETX)
90 local d = tonumber(b.ETX)
92 if not c or c == 0 then
96 if not d or d == 0 then
103 table.sort(data.Routes, compare)
105 luci.template.render("status-olsr/routes", {routes=data.Routes})
108 function action_topology()
109 local data = fetch_txtinfo("topology")
111 if not data or not data.Topology then
112 luci.template.render("status-olsr/error_olsr")
116 local function compare(a, b)
117 return a["Destination IP"] < b["Destination IP"]
120 table.sort(data.Topology, compare)
122 luci.template.render("status-olsr/topology", {routes=data.Topology})
125 function action_hna()
126 local data = fetch_txtinfo("hna")
128 if not data or not data.HNA then
129 luci.template.render("status-olsr/error_olsr")
133 local function compare(a, b)
134 return a.Network < b.Network
137 table.sort(data.HNA, compare)
139 luci.template.render("status-olsr/hna", {routes=data.HNA})
142 function action_mid()
143 local data = fetch_txtinfo("mid")
145 if not data or not data.MID then
146 luci.template.render("status-olsr/error_olsr")
150 local function compare(a, b)
154 table.sort(data.MID, compare)
156 luci.template.render("status-olsr/mid", {mids=data.MID})
161 function fetch_txtinfo(otable)
163 otable = otable or ""
164 local rawdata = luci.sys.httpget("http://127.0.0.1:2006/"..otable)
166 if #rawdata == 0 then
172 local tables = luci.util.split(luci.util.trim(rawdata), "\r?\n\r?\n", nil, true)
175 for i, tbl in ipairs(tables) do
176 local lines = luci.util.split(tbl, "\r?\n", nil, true)
177 local name = table.remove(lines, 1):sub(8)
178 local keys = luci.util.split(table.remove(lines, 1), "\t")
179 local split = #keys - 1
183 for j, line in ipairs(lines) do
184 local fields = luci.util.split(line, "\t", split)
186 for k, key in pairs(keys) do
187 data[name][j][key] = fields[k]
190 if data[name][j].Linkcost then
191 data[name][j].LinkQuality,
194 data[name][j].Linkcost:match("([%w.]+)/([%w.]+)[%s]+([%w.]+)")