1 module("ffluci.controller.public.olsr", package.seeall)
4 function action_index()
5 local data = fetch_txtinfo("links")
7 if not data or not data.Links then
8 ffluci.template.render("public_olsr/error_olsr")
12 local function compare(a, b)
13 if tonumber(a.ETX) == 0 then
17 if tonumber(b.ETX) == 0 then
21 return tonumber(a.ETX) < tonumber(b.ETX)
24 table.sort(data.Links, compare)
26 ffluci.template.render("public_olsr/index", {links=data.Links})
29 function action_routes()
30 local data = fetch_txtinfo("routes")
32 if not data or not data.Routes then
33 ffluci.template.render("public_olsr/error_olsr")
37 local function compare(a, b)
38 if tonumber(a.ETX) == 0 then
42 if tonumber(b.ETX) == 0 then
46 return tonumber(a.ETX) < tonumber(b.ETX)
49 table.sort(data.Routes, compare)
51 ffluci.template.render("public_olsr/routes", {routes=data.Routes})
54 function action_topology()
55 local data = fetch_txtinfo("topology")
57 if not data or not data.Topology then
58 ffluci.template.render("public_olsr/error_olsr")
62 local function compare(a, b)
63 return a["Destination IP"] < b["Destination IP"]
66 table.sort(data.Topology, compare)
68 ffluci.template.render("public_olsr/topology", {routes=data.Topology})
72 local data = fetch_txtinfo("hna")
74 if not data or not data.HNA then
75 ffluci.template.render("public_olsr/error_olsr")
79 local function compare(a, b)
80 return a.Network < b.Network
83 table.sort(data.HNA, compare)
85 ffluci.template.render("public_olsr/hna", {routes=data.HNA})
89 local data = fetch_txtinfo("mid")
91 if not data or not data.MID then
92 ffluci.template.render("public_olsr/error_olsr")
96 local function compare(a, b)
100 table.sort(data.MID, compare)
102 ffluci.template.render("public_olsr/mid", {mids=data.MID})
107 function fetch_txtinfo(otable)
108 otable = otable or ""
109 local rawdata = ffluci.sys.httpget("http://127.0.0.1:2006/"..otable)
111 if #rawdata == 0 then
117 local tables = ffluci.util.split(ffluci.util.trim(rawdata), "\n\n")
120 for i, tbl in ipairs(tables) do
121 local lines = ffluci.util.split(tbl, "\n")
122 local name = table.remove(lines, 1):sub(8)
123 local keys = ffluci.util.split(table.remove(lines, 1), "\t")
127 for j, line in ipairs(lines) do
128 local fields = ffluci.util.split(line, "\t")
130 for k, key in pairs(keys) do
131 data[name][j][key] = fields[k]