1 module("luci.controller.olsr", package.seeall)
4 if not luci.fs.isfile("/etc/config/olsr") 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")
36 entry({"admin", "services", "olsrd"}, cbi("olsr/olsrd"), "OLSR").i18n = "olsr"
39 function action_index()
40 local data = fetch_txtinfo("links")
42 if not data or not data.Links then
43 luci.template.render("status-olsr/error_olsr")
47 local function compare(a, b)
48 if tonumber(a.ETX) == 0 then
52 if tonumber(b.ETX) == 0 then
56 return tonumber(a.ETX) < tonumber(b.ETX)
59 table.sort(data.Links, compare)
61 luci.template.render("status-olsr/index", {links=data.Links})
64 function action_routes()
65 local data = fetch_txtinfo("routes")
67 if not data or not data.Routes then
68 luci.template.render("status-olsr/error_olsr")
72 local function compare(a, b)
73 if tonumber(a.ETX) == 0 then
77 if tonumber(b.ETX) == 0 then
81 return tonumber(a.ETX) < tonumber(b.ETX)
84 table.sort(data.Routes, compare)
86 luci.template.render("status-olsr/routes", {routes=data.Routes})
89 function action_topology()
90 local data = fetch_txtinfo("topology")
92 if not data or not data.Topology then
93 luci.template.render("status-olsr/error_olsr")
97 local function compare(a, b)
98 return a["Destination IP"] < b["Destination IP"]
101 table.sort(data.Topology, compare)
103 luci.template.render("status-olsr/topology", {routes=data.Topology})
106 function action_hna()
107 local data = fetch_txtinfo("hna")
109 if not data or not data.HNA then
110 luci.template.render("status-olsr/error_olsr")
114 local function compare(a, b)
115 return a.Network < b.Network
118 table.sort(data.HNA, compare)
120 luci.template.render("status-olsr/hna", {routes=data.HNA})
123 function action_mid()
124 local data = fetch_txtinfo("mid")
126 if not data or not data.MID then
127 luci.template.render("status-olsr/error_olsr")
131 local function compare(a, b)
135 table.sort(data.MID, compare)
137 luci.template.render("status-olsr/mid", {mids=data.MID})
142 function fetch_txtinfo(otable)
144 otable = otable or ""
145 local rawdata = luci.sys.httpget("http://127.0.0.1:2006/"..otable)
147 if #rawdata == 0 then
153 local tables = luci.util.split(luci.util.trim(rawdata), "\n\n")
156 for i, tbl in ipairs(tables) do
157 local lines = luci.util.split(tbl, "\n")
158 local name = table.remove(lines, 1):sub(8)
159 local keys = luci.util.split(table.remove(lines, 1), "\t")
163 for j, line in ipairs(lines) do
164 local fields = luci.util.split(line, "\t")
166 for k, key in pairs(keys) do
167 data[name][j][key] = fields[k]