From 97f0cf2996be5ce5ad58e22c35ea81336727db08 Mon Sep 17 00:00:00 2001 From: Manuel Munz Date: Sat, 16 Mar 2013 18:08:13 +0000 Subject: applications/luci-olsr: Use jsoninfo instead of txtinfo as data source. --- .../luasrc/view/status-olsr/common_js.htm | 35 ++ .../luasrc/view/status-olsr/error_olsr.htm | 4 +- .../luci-olsr/luasrc/view/status-olsr/hna.htm | 97 +++++- .../luasrc/view/status-olsr/interfaces.htm | 23 +- .../luci-olsr/luasrc/view/status-olsr/legend.htm | 11 + .../luci-olsr/luasrc/view/status-olsr/mid.htm | 26 +- .../luasrc/view/status-olsr/neighbors.htm | 86 ++--- .../luci-olsr/luasrc/view/status-olsr/overview.htm | 367 ++++++++------------- .../luci-olsr/luasrc/view/status-olsr/routes.htm | 62 ++-- .../luci-olsr/luasrc/view/status-olsr/smartgw.htm | 113 ++++++- .../luci-olsr/luasrc/view/status-olsr/topology.htm | 31 +- 11 files changed, 523 insertions(+), 332 deletions(-) create mode 100644 applications/luci-olsr/luasrc/view/status-olsr/common_js.htm create mode 100644 applications/luci-olsr/luasrc/view/status-olsr/legend.htm (limited to 'applications/luci-olsr/luasrc/view') 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 0000000000..1ee763e119 --- /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 97142a689a..2c872fa5a2 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 bde1f009b5..689bafdfae 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 17090ff4aa..dd1a21ea6d 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 0000000000..55b839f52f --- /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 48823b5bc1..ec5caaa953 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 669ddc20cf..4d84241fbd 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 294af7b3a6..3af5490d1b 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 e32b696d58..76e1b1078b 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 7fa8730423..75d0c1c2fb 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 d0e85280e2..eb3df5ff51 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%> -- cgit v1.2.3