From: Manuel Munz Date: Sat, 16 Mar 2013 18:08:13 +0000 (+0000) Subject: applications/luci-olsr: Use jsoninfo instead of txtinfo as data source. X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fluci.git;a=commitdiff_plain;h=97f0cf2996be5ce5ad58e22c35ea81336727db08 applications/luci-olsr: Use jsoninfo instead of txtinfo as data source. --- diff --git a/applications/luci-olsr/luasrc/controller/olsr.lua b/applications/luci-olsr/luasrc/controller/olsr.lua index fc44820dc..c1b6ed9f4 100644 --- a/applications/luci-olsr/luasrc/controller/olsr.lua +++ b/applications/luci-olsr/luasrc/controller/olsr.lua @@ -5,11 +5,23 @@ function index() return end + require("luci.model.uci") + local uci = luci.model.uci.cursor_state() + + uci:foreach("olsrd", "olsrd", function(s) + if s.SmartGateway and s.SmartGateway == "yes" then has_smartgw = true end + end) + local page = node("admin", "status", "olsr") page.target = template("status-olsr/overview") page.title = _("OLSR") page.subindex = true + local page = node("admin", "status", "olsr", "json") + page.target = call("action_json") + page.title = nil + page.leaf = true + local page = node("admin", "status", "olsr", "neighbors") page.target = call("action_neigh") page.title = _("Neighbours") @@ -36,10 +48,12 @@ function index() page.title = _("MID") page.order = 50 - local page = node("admin", "status", "olsr", "smartgw") - page.target = call("action_smartgw") - page.title = _("SmartGW") - page.order = 60 + if has_smartgw then + local page = node("admin", "status", "olsr", "smartgw") + page.target = call("action_smartgw") + page.title = _("SmartGW") + page.order = 60 + end local page = node("admin", "status", "olsr", "interfaces") page.target = call("action_interfaces") @@ -88,286 +102,231 @@ function index() ) end -local function compare_links(a, b) - local c = tonumber(a.Cost) - local d = tonumber(b.Cost) +function action_json() + local http = require "luci.http" + local utl = require "luci.util" - if not c or c == 0 then - return false - end + local jsonreq4 = utl.exec("echo /status | nc 127.0.0.1 9090") + local jsonreq6 = utl.exec("echo /status | nc ::1 9090") - if not d or d == 0 then - return true - end - return c < d + http.prepare_content("application/json") + http.write("{v4:" .. jsonreq4 .. ", v6:" .. jsonreq6 .. "}") end function action_neigh(json) - local data = fetch_txtinfo("links") + local data, has_v4, has_v6, error = fetch_jsoninfo('links') - if not data or not data.Links then - luci.template.render("status-olsr/error_olsr") - return nil + if error then + return + end + + local uci = require "luci.model.uci".cursor_state() + local resolve = uci:get("luci_olsr", "general", "resolve") + luci.sys.net.routes(function(r) if r.dest:prefix() == 0 then defaultgw = r.gateway:string() end end) + + local function compare(a,b) + if a.proto == b.proto then + return a.linkCost < b.linkCost + else + return a.proto < b.proto + end end - table.sort(data.Links, compare_links) + for k, v in ipairs(data) do + if resolve == "1" then + hostname = nixio.getnameinfo(v.remoteIP) + if hostname then + v.hostname = hostname + end + end + if defaultgw == v.remoteIP then + v.defaultgw = 1 + end + end - luci.template.render("status-olsr/neighbors", {links=data.Links}) + table.sort(data, compare) + luci.template.render("status-olsr/neighbors", {links=data, has_v4=has_v4, has_v6=has_v6}) end function action_routes() - local data = fetch_txtinfo("routes") - - if not data or not data.Routes then - luci.template.render("status-olsr/error_olsr") - return nil + local data, has_v4, has_v6, error = fetch_jsoninfo('routes') + if error then + return end - local function compare(a, b) - local c = tonumber(a.ETX) - local d = tonumber(b.ETX) + local uci = require "luci.model.uci".cursor_state() + local resolve = uci:get("luci_olsr", "general", "resolve") - if not c or c == 0 then - return false + for k, v in ipairs(data) do + if resolve == "1" then + local hostname = nixio.getnameinfo(v.gateway) + if hostname then + v.hostname = hostname + end end + end - if not d or d == 0 then - return true + local function compare(a,b) + if a.proto == b.proto then + return a.rtpMetricCost < b.rtpMetricCost + else + return a.proto < b.proto end - - return c < d end - table.sort(data.Routes, compare) - - luci.template.render("status-olsr/routes", {routes=data.Routes}) + table.sort(data, compare) + luci.template.render("status-olsr/routes", {routes=data, has_v4=has_v4, has_v6=has_v6}) end function action_topology() - local data = fetch_txtinfo("topology") - - if not data or not data.Topology then - luci.template.render("status-olsr/error_olsr") - return nil + local data, has_v4, has_v6, error = fetch_jsoninfo('topology') + if error then + return end - local function compare(a, b) - return a["Dest. IP"] < b["Dest. IP"] + local function compare(a,b) + if a.proto == b.proto then + return a.tcEdgeCost < b.tcEdgeCost + else + return a.proto < b.proto + end end - table.sort(data.Topology, compare) - - luci.template.render("status-olsr/topology", {routes=data.Topology}) + table.sort(data, compare) + luci.template.render("status-olsr/topology", {routes=data, has_v4=has_v4, has_v6=has_v6}) end function action_hna() - local data = fetch_txtinfo("hna") - - if not data or not data.HNA then - luci.template.render("status-olsr/error_olsr") - return nil + local data, has_v4, has_v6, error = fetch_jsoninfo('hna') + if error then + return end - local function compare(a, b) - return a.Destination < b.Destination + local uci = require "luci.model.uci".cursor_state() + local resolve = uci:get("luci_olsr", "general", "resolve") + + local function compare(a,b) + if a.proto == b.proto then + return a.genmask < b.genmask + else + return a.proto < b.proto + end end - table.sort(data.HNA, compare) + for k, v in ipairs(data) do + if resolve == "1" then + hostname = nixio.getnameinfo(v.gateway) + if hostname then + v.hostname = hostname + end + end + if v.validityTime then + v.validityTime = tonumber(string.format("%.0f", v.validityTime / 1000)) + end + end - luci.template.render("status-olsr/hna", {routes=data.HNA}) + table.sort(data, compare) + luci.template.render("status-olsr/hna", {hna=data, has_v4=has_v4, has_v6=has_v6}) end function action_mid() - local data = fetch_txtinfo("mid") - - if not data or not data.MID then - luci.template.render("status-olsr/error_olsr") - return nil + local data, has_v4, has_v6, error = fetch_jsoninfo('mid') + if error then + return end - local function compare(a, b) - return a["IP address"] < b["IP address"] + local function compare(a,b) + if a.proto == b.proto then + return a.ipAddress < b.ipAddress + else + return a.proto < b.proto + end end - table.sort(data.MID, compare) - - luci.template.render("status-olsr/mid", {mids=data.MID}) + table.sort(data, compare) + luci.template.render("status-olsr/mid", {mids=data, has_v4=has_v4, has_v6=has_v6}) end function action_smartgw() - local data = fetch_txtinfo("gateways") - - if not data or not data.Gateways then - luci.template.render("status-olsr/error_olsr") - return nil - end - - local function compare(a, b) - return a["ETX"] < b["ETX"] - end + local data, has_v4, has_v6, error = fetch_jsoninfo('gateways') + if error then + return + end - table.sort(data.Gateways, compare) + local function compare(a,b) + if a.proto == b.proto then + return a.tcPathCost < b.tcPathCost + else + return a.proto < b.proto + end + end - luci.template.render("status-olsr/smartgw", {gws=data.Gateways}) + table.sort(data, compare) + luci.template.render("status-olsr/smartgw", {gws=data, has_v4=has_v4, has_v6=has_v6}) end function action_interfaces() - local data = fetch_txtinfo("interfaces") + local data, has_v4, has_v6, error = fetch_jsoninfo('interfaces') + if error then + return + end - if not data or not data.Interfaces then - luci.template.render("status-olsr/error_olsr") - return nil - end + local function compare(a,b) + return a.proto < b.proto + end - luci.template.render("status-olsr/interfaces", {iface=data.Interfaces}) + table.sort(data, compare) + luci.template.render("status-olsr/interfaces", {iface=data, has_v4=has_v4, has_v6=has_v6}) end -- Internal -function fetch_txtinfo(otable) - require("luci.sys") - local uci = require "luci.model.uci".cursor_state() - local resolve = uci:get("luci_olsr", "general", "resolve") - otable = otable or "" - local rawdata = luci.sys.httpget("http://127.0.0.1:2006/"..otable) - local rawdatav6 = luci.sys.httpget("http://[::1]:2006/"..otable) - local data = {} - local dataindex = 0 - local name = "" - local defaultgw - - if #rawdata ~= 0 then - local tables = luci.util.split(luci.util.trim(rawdata), "\r?\n\r?\n", nil, true) - - if otable == "links" then - local route = {} - luci.sys.net.routes(function(r) if r.dest:prefix() == 0 then defaultgw = r.gateway:string() end end) - end - - for i, tbl in ipairs(tables) do - local lines = luci.util.split(tbl, "\r?\n", nil, true) - name = table.remove(lines, 1):sub(8) - local keys = luci.util.split(table.remove(lines, 1), "\t") - local split = #keys - 1 - if not data[name] then - data[name] = {} - end - - for j, line in ipairs(lines) do - dataindex = ( dataindex + 1 ) - di = dataindex - local fields = luci.util.split(line, "\t", split) - data[name][di] = {} - for k, key in pairs(keys) do - if key == "Remote IP" or key == "Dest. IP" or key == "Gateway IP" or key == "Gateway" then - data[name][di][key] = fields[k] - if resolve == "1" then - hostname = nixio.getnameinfo(fields[k], "inet") - if hostname then - data[name][di]["Hostname"] = hostname - end - end - if key == "Remote IP" and defaultgw then - if defaultgw == fields[k] then - data[name][di]["defaultgw"] = 1 - end - end - elseif key == "Local IP" then - data[name][di][key] = fields[k] - data[name][di]['Local Device'] = fields[k] - uci:foreach("network", "interface", - function(s) - localip = string.gsub(fields[k], ' ', '') - if s.ipaddr == localip then - data[name][di]['Local Device'] = s['.name'] or interface - end - end) - elseif key == "Interface" then - data[name][di][key] = fields[k] - uci:foreach("network", "interface", - function(s) - interface = string.gsub(fields[k], ' ', '') - if s.ifname == interface then - data[name][di][key] = s['.name'] or interface - end - end) - else - data[name][di][key] = fields[k] - end - end - if data[name][di].Linkcost then - data[name][di].LinkQuality, - data[name][di].NLQ, - data[name][di].ETX = - data[name][di].Linkcost:match("([%w.]+)/([%w.]+)[%s]+([%w.]+)") - end - end - end +function fetch_jsoninfo(otable) + local utl = require "luci.util" + local json = require "luci.json" + local jsonreq4 = utl.exec("echo /" .. otable .. " | nc 127.0.0.1 9090") + local jsondata4 = {} + local jsonreq6 = utl.exec("echo /" .. otable .. " | nc ::1 9090") + local jsondata6 = {} + local data4 = {} + local data6 = {} + local has_v4 = False + local has_v6 = False + + if jsonreq4 == '' and jsonreq6 == '' then + luci.template.render("status-olsr/error_olsr") + return nil, 0, 0, true end - if #rawdatav6 ~= 0 then - local tables = luci.util.split(luci.util.trim(rawdatav6), "\r?\n\r?\n", nil, true) - for i, tbl in ipairs(tables) do - local lines = luci.util.split(tbl, "\r?\n", nil, true) - name = table.remove(lines, 1):sub(8) - local keys = luci.util.split(table.remove(lines, 1), "\t") - local split = #keys - 1 - if not data[name] then - data[name] = {} - end - for j, line in ipairs(lines) do - dataindex = ( dataindex + 1 ) - di = dataindex - local fields = luci.util.split(line, "\t", split) - data[name][di] = {} - for k, key in pairs(keys) do - if key == "Remote IP" then - data[name][di][key] = "[" .. fields[k] .. "]" - if resolve == "1" then - hostname = nixio.getnameinfo(fields[k], "inet6") - if hostname then - data[name][di]["Hostname"] = hostname - end - end - elseif key == "Local IP" then - data[name][di][key] = fields[k] - data[name][di]['Local Device'] = fields[k] - uci:foreach("network", "interface", - function(s) - local localip = string.gsub(fields[k], ' ', ''):upper() - localip = luci.ip.IPv6(localip):string() - if s.ip6addr then - s.ip6addr = luci.ip.IPv6(s.ip6addr):string() - local ip6addr = string.gsub(s.ip6addr, '\/.*', ''):upper() - if ip6addr == localip then - data[name][di]['Local Device'] = s['.name'] or s.interface - end - end - end) - elseif key == "Dest. IP" then - data[name][di][key] = "[" .. fields[k] .. "]" - elseif key == "Last hop IP" then - data[name][di][key] = "[" .. fields[k] .. "]" - elseif key == "IP address" then - data[name][di][key] = "[" .. fields[k] .. "]" - elseif key == "Gateway" then - data[name][di][key] = "[" .. fields[k] .. "]" - else - data[name][di][key] = fields[k] - end - end - - if data[name][di].Linkcost then - data[name][di].LinkQuality, - data[name][di].NLQ, - data[name][di].ETX = - data[name][di].Linkcost:match("([%w.]+)/([%w.]+)[%s]+([%w.]+)") - end - end + if #jsonreq4 ~= 0 then + has_v4 = 1 + jsondata4 = json.decode(jsonreq4) + if otable == 'status' then + data4 = jsondata4 + else + data4 = jsondata4[otable] end - end + for k, v in ipairs(data4) do + data4[k]['proto'] = '4' + end + end + if #jsonreq6 ~= 0 then + has_v6 = 1 + jsondata6 = json.decode(jsonreq6) + if otable == 'status' then + data6 = jsondata6 + else + data6 = jsondata6[otable] + end + for k, v in ipairs(data6) do + data6[k]['proto'] = '6' + end + end - if data then - return data + for k, v in ipairs(data6) do + table.insert(data4, v) end + + return data4, has_v4, has_v6, false end + diff --git a/applications/luci-olsr/luasrc/view/status-olsr/common_js.htm b/applications/luci-olsr/luasrc/view/status-olsr/common_js.htm new file mode 100644 index 000000000..1ee763e11 --- /dev/null +++ b/applications/luci-olsr/luasrc/view/status-olsr/common_js.htm @@ -0,0 +1,35 @@ +<% if has_v4 and has_v6 then %> + +<%end %> diff --git a/applications/luci-olsr/luasrc/view/status-olsr/error_olsr.htm b/applications/luci-olsr/luasrc/view/status-olsr/error_olsr.htm index 97142a689..2c872fa5a 100644 --- a/applications/luci-olsr/luasrc/view/status-olsr/error_olsr.htm +++ b/applications/luci-olsr/luasrc/view/status-olsr/error_olsr.htm @@ -9,11 +9,9 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -$Id$ - -%> <%+header%>

<%:OLSR Daemon%>

<%:Unable to connect to the OLSR daemon!%>

-

<%:Make sure that OLSRd is running, the "txtinfo" plugin is loaded, configured on port 2006 and accepts connections from "127.0.0.1".%>

+

<%:Make sure that OLSRd is running, the "jsoninfo" plugin is loaded, configured on port 9090 and accepts connections from "127.0.0.1".%>

<%+footer%> diff --git a/applications/luci-olsr/luasrc/view/status-olsr/hna.htm b/applications/luci-olsr/luasrc/view/status-olsr/hna.htm index bde1f009b..689bafdfa 100644 --- a/applications/luci-olsr/luasrc/view/status-olsr/hna.htm +++ b/applications/luci-olsr/luasrc/view/status-olsr/hna.htm @@ -10,39 +10,120 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -$Id$ - -%> + <% local i = 1 + +if luci.http.formvalue("status") == "1" then + local rv = {} + for k, hna in ipairs(hna) do + rv[#rv+1] = { + proto = hna["proto"], + destination = hna["destination"], + genmask = hna["genmask"], + gateway = hna["gateway"], + hostname = hna["hostname"], + validityTime = hna["validityTime"] + } + end + luci.http.prepare_content("application/json") + luci.http.write_json(rv) + return +end %> <%+header%> + + +

<%:Active host net announcements%>

+
+ <%:Overview of currently active OLSR host net announcements%> + + - <% for k, route in ipairs(routes) do %> + + + <% for k, route in ipairs(hna) do %> - - + + + <% if hna[k].validityTime then + validity = hna[k].validityTime .. 's' + else + validity = '-' + end %> + + <% i = ((i % 2) + 1) end %> +
<%:Announced network%> <%:OLSR gateway%><%:Validity Time%>
<%=route.Destination%>
<%=hna[k].destination%>/<%=hna[k].genmask%> - <%=route.Gateway%> - <% if route.Hostname then %> - / <%=route.Hostname%> + <% if hna[k].proto == '6' then %> + <%=hna[k].gateway%> + <% else %> + <%=hna[k].gateway%> + <% end %> + <% if hna[k].hostname then %> + / <%=hna[k].hostname%> <% end %> <%=validity%>
+ +<%+status-olsr/common_js%> <%+footer%> diff --git a/applications/luci-olsr/luasrc/view/status-olsr/interfaces.htm b/applications/luci-olsr/luasrc/view/status-olsr/interfaces.htm index 17090ff4a..dd1a21ea6 100644 --- a/applications/luci-olsr/luasrc/view/status-olsr/interfaces.htm +++ b/applications/luci-olsr/luasrc/view/status-olsr/interfaces.htm @@ -10,8 +10,6 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -$Id: mid.htm 5448 2009-10-31 15:54:11Z jow $ - -%> <% @@ -22,6 +20,8 @@ local i = 1

<%:Interfaces%>

+
+
<%:Overview of interfaces where OLSR is running%> @@ -38,17 +38,20 @@ local i = 1 <% for k, iface in ipairs(iface) do %> - - <%=iface.Name%> - <%=iface.State%> - <%=iface.MTU%> - <%=iface.WLAN%> - <%=iface["Src-Adress"]%> - <%=iface.Mask%> - <%=iface["Dst-Adress"]%> + + <%=iface.name%> + <%=iface.state%> + <%=iface.olsrMTU%> + <%=iface.wireless and luci.i18n.translate('yes') or luci.i18n.translate('no')%> + <%=iface.ipv4Address or iface.ipv6Address%> + <%=iface.netmask%> + <%=iface.broadcast or iface.multicast%> <% i = ((i % 2) + 1) end %>
+<%+status-olsr/common_js%> <%+footer%> + + diff --git a/applications/luci-olsr/luasrc/view/status-olsr/legend.htm b/applications/luci-olsr/luasrc/view/status-olsr/legend.htm new file mode 100644 index 000000000..55b839f52 --- /dev/null +++ b/applications/luci-olsr/luasrc/view/status-olsr/legend.htm @@ -0,0 +1,11 @@ +

<%:Legend%>:

+ + diff --git a/applications/luci-olsr/luasrc/view/status-olsr/mid.htm b/applications/luci-olsr/luasrc/view/status-olsr/mid.htm index 48823b5bc..ec5caaa95 100644 --- a/applications/luci-olsr/luasrc/view/status-olsr/mid.htm +++ b/applications/luci-olsr/luasrc/view/status-olsr/mid.htm @@ -20,6 +20,7 @@ local i = 1 <%+header%>

<%:Active MID announcements%>

+
<%:Overview of known multiple interface announcements%> @@ -28,15 +29,30 @@ local i = 1 - <% for k, mid in ipairs(mids) do %> - - - - + <% for k, mid in ipairs(mids) do + local aliases = '' + for k,v in ipairs(mid.aliases) do + if aliases == '' then + sep = '' + else + sep = ', ' + end + aliases = v.ipAddress .. sep .. aliases + end + local host = mid.ipAddress + if mid.proto == '6' then + host = '[' .. mid.ipAddress .. ']' + end + %> + + + + <% i = ((i % 2) + 1) end %>
<%:Secondary OLSR interfaces%>
/cgi-bin-status.html"><%=mid["IP address"]%><%=mid.Aliases%>
<%=mid.ipAddress%><%=aliases%>
+<%+status-olsr/common_js%> <%+footer%> diff --git a/applications/luci-olsr/luasrc/view/status-olsr/neighbors.htm b/applications/luci-olsr/luasrc/view/status-olsr/neighbors.htm index 669ddc20c..4d84241fb 100644 --- a/applications/luci-olsr/luasrc/view/status-olsr/neighbors.htm +++ b/applications/luci-olsr/luasrc/view/status-olsr/neighbors.htm @@ -19,23 +19,26 @@ local i = 1 if luci.http.formvalue("status") == "1" then local rv = {} for k, link in ipairs(links) do - link.Cost = tonumber(link.Cost) or 0 - local color = olsrtools.etx_color(link.Cost) + link.linkCost = tonumber(link.linkCost)/1024 or 0 + if link.linkCost == 4096 then + link.linkCost = 0 + end + local color = olsrtools.etx_color(link.linkCost) defaultgw_color = "" if link.defaultgw == 1 then defaultgw_color = "#ffff99" end rv[#rv+1] = { - rip = link["Remote IP"], - hn = link["Hostname"], - lip = link["Local IP"], - dev = link["Local Device"], - lq = link.LQ, - nlq = link.NLQ, - cost = string.format("%.3f", link.Cost), + rip = link.remoteIP, + hn = link.hostname, + lip = link.localIP, + lq = string.format("%.3f", link.linkQuality), + nlq = string.format("%.3f",link.neighborLinkQuality), + cost = string.format("%.3f", link.linkCost), color = color, - dfgcolor = defaultgw_color + dfgcolor = defaultgw_color, + proto = link.proto } end luci.http.prepare_content("application/json") @@ -60,11 +63,19 @@ end { var neigh = info[idx]; - s += String.format( - '' + - '%s', - neigh.dfgcolor, neigh.rip, neigh.rip - ); + if (neigh.proto == '6') { + s += String.format( + '' + + '%s', + neigh.proto, neigh.dfgcolor, neigh.rip, neigh.rip + ); + } else { + s += String.format( + '' + + '%s', + neigh.proto, neigh.dfgcolor, neigh.rip, neigh.rip + ); + } if (neigh.hn) { s += String.format( '%s', @@ -82,10 +93,9 @@ end '%s' + '%s' + '%s' + - '%s' + '', - neigh.dfgcolor, neigh.lip, neigh.dfgcolor, neigh.dev, neigh.dfgcolor, neigh.lq, neigh.dfgcolor, neigh.nlq, neigh.color, neigh.cost || '?' + neigh.dfgcolor, neigh.lip, neigh.dfgcolor, neigh.lq, neigh.dfgcolor, neigh.nlq, neigh.color, neigh.cost || '?' ); } @@ -98,6 +108,8 @@ end

<%:OLSR connections%>

+
+
<%:Overview of currently established OLSR connections%> @@ -107,7 +119,6 @@ end <%:Neighbour IP%> <%:Hostname%> <%:Local interface IP%> - <%:Device%> LQ NLQ ETX @@ -117,8 +128,12 @@ end <% local i = 1 for k, link in ipairs(links) do - link.Cost = tonumber(link.Cost) or 0 - color = olsrtools.etx_color(link.Cost) + link.linkCost = tonumber(link.linkCost)/1024 or 0 + if link.linkCost == 4096 then + link.linkCost = 0 + end + + color = olsrtools.etx_color(link.linkCost) defaultgw_color = "" if link.defaultgw == 1 then @@ -126,14 +141,17 @@ end end %> - - /cgi-bin-status.html"><%=link["Remote IP"]%> - /cgi-bin-status.html"><%=link["Hostname"]%> - <%=link["Local IP"]%> - <%=link["Local Device"]%> - <%=link.LQ%> - <%=link.NLQ%> - <%=string.format("%.3f", link.Cost)%> + + <% if link.proto == "6" then %> + <%=link.remoteIP%> + <% else %> + <%=link.remoteIP%> + <% end %> + <%=link.hostname%> + <%=link.localIP%> + <%=string.format("%.3f", link.linkQuality)%> + <%=string.format("%.3f", link.neighborLinkQuality)%> + <%=string.format("%.3f", link.linkCost)%> <% i = ((i % 2) + 1) @@ -142,15 +160,7 @@ end
-

<%:Legend%>:

- +<%+status-olsr/legend%>
+<%+status-olsr/common_js%> <%+footer%> diff --git a/applications/luci-olsr/luasrc/view/status-olsr/overview.htm b/applications/luci-olsr/luasrc/view/status-olsr/overview.htm index 294af7b3a..3af5490d1 100644 --- a/applications/luci-olsr/luasrc/view/status-olsr/overview.htm +++ b/applications/luci-olsr/luasrc/view/status-olsr/overview.htm @@ -12,83 +12,10 @@ You may obtain a copy of the License at -%> <% -local sys = require "luci.sys" -local utl = require "luci.util" -local fs = require "luci.fs" - -function get_version() - local data = utl.split((utl.trim(sys.exec("/usr/sbin/olsrd -v")))) - local buildfull = utl.trim(utl.split(data[2],": ")[2]) - local ver = { - version = utl.trim(utl.split(data[1]," - ")[2]), - date = utl.trim(utl.split(buildfull, " ")[1]), - time = utl.trim(utl.split(buildfull, " ")[2]), - host = utl.trim(utl.split(buildfull, " ")[4]) - } - return ver -end -local ver = get_version() - -local ifaces = fetch_txtinfo("int") -if not ifaces or not ifaces.Interfaces then - luci.template.render("status-olsr/error_olsr") - return nil -end -local interfaces = "" -for k,v in pairs(ifaces.Interfaces) do - interfaces = utl.trim(interfaces.." "..v.Name) -end -interfaces = string.gsub(interfaces, " ", ", ") -local nr_ifaces = #ifaces.Interfaces - -local links = fetch_txtinfo("links") -local nr_neigh = #links.Links -local neighbors = "" -for k,v in pairs(links.Links) do - local link - if v.Hostname then - link = v.Hostname - else - link = v["Remote IP"] - end - neighbors = utl.trim(""..link.." "..neighbors) -end - -local data = fetch_txtinfo("topology") -local nr_topo = #data.Topology -local utable = {} -for k,v in pairs(data.Topology) do - if utl.contains(utable, v["Dest. IP"]) == false then - table.insert(utable, v["Dest. IP"]) - end -end -local nr_nodes = #utable - -local data = fetch_txtinfo("hna") -local nr_hna = #data.HNA - -local meshfactor = string.format("%.2f", nr_topo / nr_nodes) - -if luci.http.formvalue("status") == "1" then - rv = { - nr_neighbors = nr_neigbors, - neighbors = neighbors, - interfaces = interfaces, - nr_ifaces = nr_ifaces, - nr_links = nr_links, - nr_topo = nr_topo, - nr_nodes = nr_nodes, - meshfactor = meshfactor - } - luci.http.prepare_content("application/json") - luci.http.write_json(rv) - return -end - - local ipv = luci.model.uci.cursor():get_first("olsrd", "olsrd", "IpVersion", "4") function write_conf(conf, file) + local fs = require "luci.fs" if fs.access(conf) then luci.http.header("Content-Disposition", "attachment; filename="..file) luci.http.prepare_content("text/plain") @@ -125,169 +52,161 @@ end +
+

OLSR <%:Overview%>

-
-
-
-
- -
-
- -
- - <%=interfaces%> - -
-
-
-
- -
-
- <%:Neighbors%> -
-
- -
- - <%=neighbors%> - -
-
-
-
- -
-
- <%:Nodes%> -
- -
-
- -
-
- <%:HNA%> -
- -
-
- -
-
- <%:Links total%> -
- -
-
- -
-
- <%:Links per node (average)%> -
-
-
- - <%=meshfactor%> - -
-
-
-
-
-
-
- -

OLSR <%:Configuration%>

- -
-
-
-
- <%:Version%> -
-
- <%=ver.version%> (built <%=ver.date%> on <%=ver.host%>) -
-
-
- -
-
- <%:Download Config%> -
-
+
+ <%:Network%> + + + + + + + + + + +
<%:Interfaces%> + + - + +
<%:Neighbors%> + + - + +
<%:Nodes%> + + - + +
<%:HNA%> + + - + +
<%:Links total%> + + - + +
<%:Links per node (average)%> + - +
+
+ + +
+ OLSR <%:Configuration%> + + + +
<%:Version%> + - +
<%:Download Config%> OpenWrt, <% if ipv == "6and4" then %> OLSRD IPv4, @@ -295,10 +214,8 @@ XHR.poll(30, '<%=REQUEST_URI%>', { status: 1 }, <% else %> OLSRD <% end %> - -
- - - +
+
<%+footer%> diff --git a/applications/luci-olsr/luasrc/view/status-olsr/routes.htm b/applications/luci-olsr/luasrc/view/status-olsr/routes.htm index e32b696d5..76e1b1078 100644 --- a/applications/luci-olsr/luasrc/view/status-olsr/routes.htm +++ b/applications/luci-olsr/luasrc/view/status-olsr/routes.htm @@ -19,14 +19,16 @@ local i = 1 if luci.http.formvalue("status") == "1" then local rv = {} for k, route in ipairs(routes) do + local ETX = string.format("%.3f", tonumber(route.rtpMetricCost)/1024 or 0) rv[#rv+1] = { - hostname = route.Hostname, - dest = route.Destination, - gw = route["Gateway IP"], - interface = route.Interface, - metric = route.Metric, - etx = tonumber(route.ETX), - color = olsrtools.etx_color(tonumber(route.ETX)), + hostname = route.hostname, + dest = route.destination, + genmask = route.genmask, + gw = route.gateway, + interface = route.networkInterface, + metric = route.metric, + etx = ETX, + color = olsrtools.etx_color(tonumber(ETX)) } end luci.http.prepare_content("application/json") @@ -54,20 +56,27 @@ XHR.poll(20, '<%=REQUEST_URI%>', { status: 1 }, var route = info[idx]; s += String.format( - '' + - '%s' + + '' + + '%s/%s' + '' + '%s', - route.dest, route.gw, route.gw + route.proto, route.dest, route.genmask, route.gw, route.gw ) - if (route.hostname) - { - s += String.format( + if (route.hostname) { + if (hna.proto == '6') { + s += String.format( + ' / %s', + route.hostname, route.hostname || '?' + ); + } else { + s += String.format( ' / %s', route.hostname, route.hostname || '?' ); } + + } s += String.format( '' + '%s' + @@ -88,6 +97,8 @@ XHR.poll(20, '<%=REQUEST_URI%>', { status: 1 },

<%:Known OLSR routes%>

+
+
<%:Overview of currently known routes to other OLSR nodes%> @@ -105,20 +116,25 @@ XHR.poll(20, '<%=REQUEST_URI%>', { status: 1 }, <% for k, route in ipairs(routes) do - color = olsrtools.etx_color(tonumber(route.ETX)) + ETX = tonumber(route.rtpMetricCost)/1024 or '0' + color = olsrtools.etx_color(ETX) %> - - <%=route.Destination%> + + <%=route.destination%>/<%=route.genmask%> - /cgi-bin-status.html"><%=route["Gateway IP"]%> - <% if route.Hostname then %> - / <%=route.Hostname%> + <% if route.proto == '6' then %> + <%=route.gateway%> + <% else %> + <%=route.gateway%> + <% end %> + <% if route.hostname then %> + / <%=route.hostname%> <% end %> - <%=route.Interface%> - <%=route.Metric%> - <%=string.format("%.3f", tonumber(route.ETX) or 0)%> + <%=route.networkInterface%> + <%=route.metric%> + <%=string.format("%.3f", ETX)%> <% i = ((i % 2) + 1) @@ -126,5 +142,7 @@ XHR.poll(20, '<%=REQUEST_URI%>', { status: 1 }, +<%+status-olsr/legend%>
+<%+status-olsr/common_js%> <%+footer%> diff --git a/applications/luci-olsr/luasrc/view/status-olsr/smartgw.htm b/applications/luci-olsr/luasrc/view/status-olsr/smartgw.htm index 7fa873042..75d0c1c2f 100644 --- a/applications/luci-olsr/luasrc/view/status-olsr/smartgw.htm +++ b/applications/luci-olsr/luasrc/view/status-olsr/smartgw.htm @@ -19,17 +19,89 @@ local uci = luci.model.uci.cursor_state() uci:foreach("olsrd", "olsrd", function(s) if s.SmartGateway and s.SmartGateway == "yes" then has_smartgw = true end end) + + +if luci.http.formvalue("status") == "1" then + local rv = {} + for k, gw in ipairs(gws) do + gw.tcPathCost = tonumber(gw.tcPathCost)/1024 or 0 + if gw.tcPathCost == 4096 then + gw.tcPathCost = 0 + end + + rv[#rv+1] = { + proto = gw.proto, + ipAddress = gw.ipAddress, + status = gw.ipv4Status or gw.ipv6Status, + tcPathCost = string.format("%.3f", gw.tcPathCost), + hopCount = gw.hopCount, + uplinkSpeed = gw.uplinkSpeed, + downlinkSpeed = gw.downlinkSpeed, + v4 = gw.ipv4 and luci.i18n.translate('yes') or luci.i18n.translate('no'), + v6 = gw.ipv6 and luci.i18n.translate('yes') or luci.i18n.translate('no'), + externalPrefix = gw.externalPrefix + } + end + luci.http.prepare_content("application/json") + luci.http.write_json(rv) + return +end %> <%+header%> + + + + +<%+header%> +

<%:SmartGW announcements%>

+
+ <% if has_smartgw then %>
<%:Overview of smart gateways in this network%> + @@ -42,23 +114,37 @@ end) - - <% for k, gw in ipairs(gws) do %> - - - - - - - - - - - + + + + <% for k, gw in ipairs(gws) do + + gw.tcPathCost = tonumber(gw.tcPathCost)/1024 or 0 + if gw.tcPathCost == 4096 then + gw.tcPathCost = 0 + end + %> + + + <% if gw.proto == '6' then %> + + <% else %> + + <% end %> + + + + + + + + + <% i = ((i % 2) + 1) end %> +
<%:Gateway%> <%:Status%><%:Prefix%>
/cgi-bin-status.html"><%=gw["Gateway IP"]%><%=gw.Status%><%=gw.ETX%><%=gw.Hopcnt%><%=gw.Uplink%><%=gw.Downlnk%><%=gw.IPv4%><%=gw.IPv6%><%=gw.Prefix%>
<%=gw.ipAddress%><%=gw.ipAddress%><%=gw.ipv4Status or gw.ipv6Status or '-' %><%=string.format("%.3f", gw.tcPathCost)%><%=gw.hopCount%><%=gw.uplinkSpeed%><%=gw.downlinkSpeed%><%=gw.ipv4 and luci.i18n.translate('yes') or luci.i18n.translate('no')%><%=gw.ipv6 and luci.i18n.translate('yes') or luci.i18n.translate('no')%><%=gw.externalPrefix%>
@@ -68,4 +154,5 @@ end) <% end %> +<%+status-olsr/common_js%> <%+footer%> diff --git a/applications/luci-olsr/luasrc/view/status-olsr/topology.htm b/applications/luci-olsr/luasrc/view/status-olsr/topology.htm index d0e85280e..eb3df5ff5 100644 --- a/applications/luci-olsr/luasrc/view/status-olsr/topology.htm +++ b/applications/luci-olsr/luasrc/view/status-olsr/topology.htm @@ -10,8 +10,6 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -$Id$ - -%> <% local i = 1 @@ -21,6 +19,8 @@ local olsrtools = require "luci.tools.olsr" <%+header%>

<%:Active OLSR nodes%>

+
+
<%:Overview of currently known OLSR nodes%> @@ -33,21 +33,36 @@ local olsrtools = require "luci.tools.olsr" <% for k, route in ipairs(routes) do - local cost = string.format("%.3f", tonumber(route.Cost) or 0) + local cost = string.format("%.3f", tonumber(route.tcEdgeCost/1024) or 0) local color = olsrtools.etx_color(tonumber(cost)) + local lq = string.format("%.3f", tonumber(route.linkQuality) or 0) + local nlq = string.format("%.3f", tonumber(route.neighborLinkQuality) or 0) %> - - - - - + + + <% if route.proto == "6" then %> + + + + + <% else %> + + + + + <%end%> + + + <% i = ((i % 2) + 1) end %>
/cgi-bin-status.html"><%=route["Dest. IP"]%>/cgi-bin-status.html"><%=route["Last hop IP"]%><%=route.LQ%><%=route.NLQ%>
<%=route.destinationIP%><%=route.lastHopIP%><%=route.destinationIP%><%=route.lastHopIP%><%=lq%><%=nlq%> <%=cost%>
+<%+status-olsr/legend%>
+<%+status-olsr/common_js%> <%+footer%>