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", "iface"},
46 cbi("olsr/olsrdiface")
50 {"admin", "services", "olsrd", "hna"},
51 cbi("olsr/olsrdhna"), "HNA Announcements"
55 {"admin", "services", "olsrd", "plugins"},
56 cbi("olsr/olsrdplugins"), "Plugins"
62 local uci = require("luci.model.uci").cursor()
63 uci:foreach("olsrd", "LoadPlugin",
65 local lib = section.library
67 {"admin", "services", "olsrd", "plugins", lib },
68 cbi("olsr/olsrdplugins"),
69 nil --'Plugin "%s"' % lib:gsub("^olsrd_",""):gsub("%.so.+$","")
75 function action_index()
76 local data = fetch_txtinfo("links")
78 if not data or not data.Links then
79 luci.template.render("status-olsr/error_olsr")
83 local function compare(a, b)
84 local c = tonumber(a.Cost)
85 local d = tonumber(b.Cost)
87 if not c or c == 0 then
91 if not d or d == 0 then
98 table.sort(data.Links, compare)
100 luci.template.render("status-olsr/index", {links=data.Links})
103 function action_routes()
104 local data = fetch_txtinfo("routes")
106 if not data or not data.Routes then
107 luci.template.render("status-olsr/error_olsr")
111 local function compare(a, b)
112 local c = tonumber(a.ETX)
113 local d = tonumber(b.ETX)
115 if not c or c == 0 then
119 if not d or d == 0 then
126 table.sort(data.Routes, compare)
128 luci.template.render("status-olsr/routes", {routes=data.Routes})
131 function action_topology()
132 local data = fetch_txtinfo("topology")
134 if not data or not data.Topology then
135 luci.template.render("status-olsr/error_olsr")
139 local function compare(a, b)
140 return a["Dest. IP"] < b["Dest. IP"]
143 table.sort(data.Topology, compare)
145 luci.template.render("status-olsr/topology", {routes=data.Topology})
148 function action_hna()
149 local data = fetch_txtinfo("hna")
151 if not data or not data.HNA then
152 luci.template.render("status-olsr/error_olsr")
156 local function compare(a, b)
157 return a.Destination < b.Destination
160 table.sort(data.HNA, compare)
162 luci.template.render("status-olsr/hna", {routes=data.HNA})
165 function action_mid()
166 local data = fetch_txtinfo("mid")
168 if not data or not data.MID then
169 luci.template.render("status-olsr/error_olsr")
173 local function compare(a, b)
174 return a["IP address"] < b["IP address"]
177 table.sort(data.MID, compare)
179 luci.template.render("status-olsr/mid", {mids=data.MID})
184 function fetch_txtinfo(otable)
186 otable = otable or ""
187 local rawdata = luci.sys.httpget("http://127.0.0.1:2006/"..otable)
189 if #rawdata == 0 then
190 if nixio.fs.access("/proc/net/ipv6_route", "r") then
191 rawdata = luci.sys.httpget("http://[::1]:2006/"..otable)
192 if #rawdata == 0 then
202 local tables = luci.util.split(luci.util.trim(rawdata), "\r?\n\r?\n", nil, true)
205 for i, tbl in ipairs(tables) do
206 local lines = luci.util.split(tbl, "\r?\n", nil, true)
207 local name = table.remove(lines, 1):sub(8)
208 local keys = luci.util.split(table.remove(lines, 1), "\t")
209 local split = #keys - 1
213 for j, line in ipairs(lines) do
214 local fields = luci.util.split(line, "\t", split)
216 for k, key in pairs(keys) do
217 data[name][j][key] = fields[k]
220 if data[name][j].Linkcost then
221 data[name][j].LinkQuality,
224 data[name][j].Linkcost:match("([%w.]+)/([%w.]+)[%s]+([%w.]+)")