From b1ef4c398bc2d35b333331ac5f823bc17bf56ff2 Mon Sep 17 00:00:00 2001 From: Manuel Munz Date: Wed, 9 Nov 2011 18:12:25 +0000 Subject: [PATCH] applications/luci-olsr: Update all statuspages; use json reloading on overview, neighbors and topology pages --- .../luci-olsr/luasrc/controller/olsr.lua | 33 ++-- applications/luci-olsr/luasrc/tools/olsr.lua | 28 +++ .../luci-olsr/luasrc/view/status-olsr/hna.htm | 51 +++-- .../luasrc/view/status-olsr/interfaces.htm | 65 ++++--- .../luci-olsr/luasrc/view/status-olsr/mid.htm | 40 ++-- .../luasrc/view/status-olsr/neighbors.htm | 182 +++++++++++++----- .../luasrc/view/status-olsr/overview.htm | 94 ++++++++- .../luasrc/view/status-olsr/routes.htm | 154 +++++++++++---- .../luasrc/view/status-olsr/smartgw.htm | 74 ++++--- .../luasrc/view/status-olsr/topology.htm | 58 +++--- 10 files changed, 549 insertions(+), 230 deletions(-) create mode 100644 applications/luci-olsr/luasrc/tools/olsr.lua diff --git a/applications/luci-olsr/luasrc/controller/olsr.lua b/applications/luci-olsr/luasrc/controller/olsr.lua index 6d6dc1ace..a47496b31 100644 --- a/applications/luci-olsr/luasrc/controller/olsr.lua +++ b/applications/luci-olsr/luasrc/controller/olsr.lua @@ -91,30 +91,29 @@ function index() ) end -function action_neigh() - local data = fetch_txtinfo("links") +local function compare_links(a, b) + local c = tonumber(a.Cost) + local d = tonumber(b.Cost) - if not data or not data.Links then - luci.template.render("status-olsr/error_olsr") - return nil + if not c or c == 0 then + return false end - local function compare(a, b) - local c = tonumber(a.Cost) - local d = tonumber(b.Cost) - - if not c or c == 0 then - return false - end + if not d or d == 0 then + return true + end + return c < d +end - if not d or d == 0 then - return true - end +function action_neigh(json) + local data = fetch_txtinfo("links") - return c < d + if not data or not data.Links then + luci.template.render("status-olsr/error_olsr") + return nil end - table.sort(data.Links, compare) + table.sort(data.Links, compare_links) luci.template.render("status-olsr/neighbors", {links=data.Links}) end diff --git a/applications/luci-olsr/luasrc/tools/olsr.lua b/applications/luci-olsr/luasrc/tools/olsr.lua new file mode 100644 index 000000000..45501020a --- /dev/null +++ b/applications/luci-olsr/luasrc/tools/olsr.lua @@ -0,0 +1,28 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2011 Manuel Munz + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 +]]-- + +module("luci.tools.olsr", package.seeall) + +function etx_color(etx) + local color = "#bb3333" + if etx == 0 then + color = "#bb3333" + elseif etx < 4 then + color = "#00cc00" + elseif etx < 10 then + color = "#ffcb05" + elseif etx < 100 then + color = "#ff6600" + end + return color +end + diff --git a/applications/luci-olsr/luasrc/view/status-olsr/hna.htm b/applications/luci-olsr/luasrc/view/status-olsr/hna.htm index a7a14e4fa..9e29edf64 100644 --- a/applications/luci-olsr/luasrc/view/status-olsr/hna.htm +++ b/applications/luci-olsr/luasrc/view/status-olsr/hna.htm @@ -2,6 +2,7 @@ LuCI - Lua Configuration Interface Copyright 2008 Steven Barth Copyright 2008 Jo-Philipp Wich +Copyright 2011 Manuel Munz Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -12,26 +13,36 @@ You may obtain a copy of the License at $Id$ -%> +<% +local i = 1 +%> + <%+header%> +

<%:Active host net announcements%>

-

<%:Overview of currently active OLSR host net announcements%>

-
- - - - - -<% for k, route in ipairs(routes) do %> - - - - -<% end %> -
<%:Announced network%><%:OLSR gateway%>
<%=route.Destination%> -<%=route.Gateway%> -<% if route.Hostname then %> - / <%=route.Hostname%> -<% end %> -
-
+ +
+ <%:Overview of currently active OLSR host net announcements%> + + + + + + + <% for k, route in ipairs(routes) do %> + + + + + + + <% if i == 1 then i = 0 elseif i == 0 then i = 1 end + end %> +
<%:Announced network%><%:OLSR gateway%>
<%=route.Destination%> + <%=route.Gateway%> + <% if route.Hostname then %> + / <%=route.Hostname%> + <% end %> +
+
<%+footer%> diff --git a/applications/luci-olsr/luasrc/view/status-olsr/interfaces.htm b/applications/luci-olsr/luasrc/view/status-olsr/interfaces.htm index b409fede9..2d3ff876a 100644 --- a/applications/luci-olsr/luasrc/view/status-olsr/interfaces.htm +++ b/applications/luci-olsr/luasrc/view/status-olsr/interfaces.htm @@ -2,7 +2,7 @@ LuCI - Lua Configuration Interface Copyright 2008 Steven Barth Copyright 2008 Jo-Philipp Wich -Copyright 2010 Manuel Munz +Copyright 2011 Manuel Munz Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -13,33 +13,42 @@ You may obtain a copy of the License at $Id: mid.htm 5448 2009-10-31 15:54:11Z jow $ -%> + +<% +local i = 1 +%> + <%+header%> +

<%:Interfaces%>

-

<%:Overview of interfaces where OLSR is running%>

-
- - - - - - - - - - - -<% for k, i in ipairs(iface) do %> - - - - - - - - - -<% end %> - -
<%:Interface%><%:State%><%:MTU%><%:WLAN%><%:Source address%><%:Netmask%><%:Broadcast address%>
<%=i.Name%><%=i.State%><%=i.MTU%><%=i.WLAN%><%=i["Src-Adress"]%><%=i.Mask%><%=i["Dst-Adress"]%>
-
+ +
+ <%:Overview of interfaces where OLSR is running%> + + + + + + + + + + + + + <% for k, iface in ipairs(iface) do %> + + + + + + + + + + + <% if i == 1 then i = 0 elseif i == 0 then i = 1 end + end %> +
<%:Interface%><%:State%><%:MTU%><%:WLAN%><%:Source address%><%:Netmask%><%:Broadcast address%>
<%=iface.Name%><%=iface.State%><%=iface.MTU%><%=iface.WLAN%><%=iface["Src-Adress"]%><%=iface.Mask%><%=iface["Dst-Adress"]%>
+
<%+footer%> diff --git a/applications/luci-olsr/luasrc/view/status-olsr/mid.htm b/applications/luci-olsr/luasrc/view/status-olsr/mid.htm index c934fc9d7..1af864d85 100644 --- a/applications/luci-olsr/luasrc/view/status-olsr/mid.htm +++ b/applications/luci-olsr/luasrc/view/status-olsr/mid.htm @@ -2,6 +2,7 @@ LuCI - Lua Configuration Interface Copyright 2008 Steven Barth Copyright 2008 Jo-Philipp Wich +Copyright 2011 Manuel Munz Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -12,21 +13,30 @@ You may obtain a copy of the License at $Id$ -%> +<% +local i = 1 +%> + <%+header%>

<%:Active MID announcements%>

-

<%:Overview of known multiple interface announcements%>

-
- - - - - -<% for k, mid in ipairs(mids) do %> - - - - -<% end %> -
<%:OLSR node%><%:Secondary OLSR interfaces%>
"><%=mid["IP address"]%><%=mid.Aliases%>
-
+ +
+ <%:Overview of known multiple interface announcements%> + + + + + + + <% for k, mid in ipairs(mids) do %> + + + + + + + <% if i == 1 then i = 0 elseif i == 0 then i = 1 end + end %> +
<%:OLSR node%><%:Secondary OLSR interfaces%>
/cgi-bin-status.html"><%=mid["IP address"]%><%=mid.Aliases%>
+
<%+footer%> diff --git a/applications/luci-olsr/luasrc/view/status-olsr/neighbors.htm b/applications/luci-olsr/luasrc/view/status-olsr/neighbors.htm index 46ebebf86..4eff933c9 100644 --- a/applications/luci-olsr/luasrc/view/status-olsr/neighbors.htm +++ b/applications/luci-olsr/luasrc/view/status-olsr/neighbors.htm @@ -2,65 +2,153 @@ LuCI - Lua Configuration Interface Copyright 2008 Steven Barth Copyright 2008 Jo-Philipp Wich - +Copyright 2011 Manuel Munz + Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -$Id: index.htm 6619 2010-12-05 15:02:44Z soma $ - -%> -<%+header%> -

<%:OLSR connections%>

-

<%:Overview of currently established OLSR connections%>

-
- - - - - - - - - - -<% for k, link in ipairs(links) do - local color = "#bb3333" - - link.Cost = tonumber(link.Cost) or 0 - if link.Cost == 0 then - color = "#bb3333" - elseif link.Cost < 4 then - color = "#00cc00" - elseif link.Cost < 10 then - color = "#ffcb05" - elseif link.Cost < 100 then - color = "#ff6600" - end - defaultgw_color = "" - if link.defaultgw == 1 then - defaultgw_color = "#ffff99" +<% +local olsrtools = require "luci.tools.olsr" + +if luci.http.formvalue("status") == "1" then + local rv = {} + local i = 1 + + for k, link in ipairs(links) do + link.Cost = tonumber(link.Cost) or 0 + local color = olsrtools.etx_color(link.Cost) + 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), + color = color, + rs = i, + dfgcolor = defaultgw_color + } + if i == 1 then i = 0 elseif i == 0 then i = 1 end end + luci.http.prepare_content("application/json") + luci.http.write_json(rv) + return +end %> - - - - - - - - - -<% end %> -
<%:Neighbour IP%><%:Hostname%><%:Local interface IP%><%:Device%>LQNLQETX
/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)%>
+ +<%+header%> + + + + + +

<%:OLSR connections%>

+ +
+ <%:Overview of currently established OLSR connections%> + + + + + + + + + + + + + + + <% local i = 1 + for k, link in ipairs(links) do + link.Cost = tonumber(link.Cost) or 0 + color = olsrtools.etx_color(link.Cost) + + defaultgw_color = "" + if link.defaultgw == 1 then + defaultgw_color = "#ffff99" + end + %> + + + + + + + + + + + <% + if i == 1 then i = 0 elseif i == 0 then i = 1 end + end %> + +
<%:Neighbour IP%><%:Hostname%><%:Local interface IP%><%:Device%>LQNLQETX
/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)%>

+

<%:Legend%>:

    -
  • LQ: <%:Success rate of packages received from the neighbour%>
  • -
  • NLQ: <%:Success rate of packages sent to the neighbour%>
  • -
  • ETX: <%:Expected retransmission count%>
  • +
  • LQ: <%:Success rate of packages received from the neighbour%>
  • +
  • NLQ: <%:Success rate of packages sent to the neighbour%>
  • +
  • ETX: <%:Expected retransmission count%>
+
<%+footer%> diff --git a/applications/luci-olsr/luasrc/view/status-olsr/overview.htm b/applications/luci-olsr/luasrc/view/status-olsr/overview.htm index 952dd28cc..753e3b912 100644 --- a/applications/luci-olsr/luasrc/view/status-olsr/overview.htm +++ b/applications/luci-olsr/luasrc/view/status-olsr/overview.htm @@ -2,7 +2,7 @@ LuCI - Lua Configuration Interface Copyright 2008 Steven Barth Copyright 2008 Jo-Philipp Wich -Copyright 2010 Manuel Munz +Copyright 2011 Manuel Munz Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -69,6 +69,23 @@ 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) @@ -104,6 +121,43 @@ end %> <%+header%> + + + + +

OLSR <%:Overview%>

@@ -111,10 +165,15 @@ end
- <%=interfaces%> + + <%=interfaces%> +
@@ -122,31 +181,48 @@ end
- <%=neighbors%> + + <%=neighbors%> +
-
-
-
-
<%=meshfactor%> +
+ + <%=meshfactor%> +
diff --git a/applications/luci-olsr/luasrc/view/status-olsr/routes.htm b/applications/luci-olsr/luasrc/view/status-olsr/routes.htm index cad9c3588..5281f7083 100644 --- a/applications/luci-olsr/luasrc/view/status-olsr/routes.htm +++ b/applications/luci-olsr/luasrc/view/status-olsr/routes.htm @@ -2,55 +2,129 @@ LuCI - Lua Configuration Interface Copyright 2008 Steven Barth Copyright 2008 Jo-Philipp Wich +Copyright 2011 Manuel Munz Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +-%> -$Id$ +<% --%> -<%+header%> -

<%:Known OLSR routes%>

-

<%:Overview of currently known routes to other OLSR nodes%>

-
- - - - - - - - -<% for k, route in ipairs(routes) do - local color = "#bb3333" - - route.ETX = tonumber(route.ETX) - if route.ETX == 0 then - color = "#bb3333" - elseif route.ETX < 4 then - color = "#00cc00" - elseif route.ETX < 10 then - color = "#ffcb05" - elseif route.ETX < 100 then - color = "#ff6600" +local olsrtools = require "luci.tools.olsr" +local i = 1 + +if luci.http.formvalue("status") == "1" then + local rv = {} + for k, route in ipairs(routes) do + 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)), + rs = i + } + if i == 1 then i = 0 elseif i == 0 then i = 1 end end + luci.http.prepare_content("application/json") + luci.http.write_json(rv) + return +end + %> - - - - - - - -<% end %> + +<%+header%> + + + + + + +

<%:Known OLSR routes%>

+ +
+<%:Overview of currently known routes to other OLSR nodes%> + +
<%:Announced network%><%:OLSR gateway%><%:Interface%><%:Metric%>ETX
<%=route.Destination%> -/cgi-bin-status.html"><%=route["Gateway IP"]%> -<% if route.Hostname then %> - / <%=route.Hostname%> -<% end %> -<%=route.Interface%><%=route.Metric%><%=string.format("%.3f", tonumber(route.ETX) or 0)%>
+ + + + + + + + + + + <% for k, route in ipairs(routes) do + color = olsrtools.etx_color(tonumber(route.ETX)) + %> + + + + + + + + + <% + if i == 1 then i = 0 elseif i == 0 then i = 1 end + end %> +
<%:Announced network%><%:OLSR gateway%><%:Interface%><%:Metric%>ETX
<%=route.Destination%> + /cgi-bin-status.html"><%=route["Gateway IP"]%> + <% if route.Hostname then %> + / <%=route.Hostname%> + <% end %> + <%=route.Interface%><%=route.Metric%><%=string.format("%.3f", tonumber(route.ETX) or 0)%>
-
+ + <%+footer%> diff --git a/applications/luci-olsr/luasrc/view/status-olsr/smartgw.htm b/applications/luci-olsr/luasrc/view/status-olsr/smartgw.htm index ecf7b4150..60f43b7f8 100644 --- a/applications/luci-olsr/luasrc/view/status-olsr/smartgw.htm +++ b/applications/luci-olsr/luasrc/view/status-olsr/smartgw.htm @@ -2,7 +2,7 @@ LuCI - Lua Configuration Interface Copyright 2008 Steven Barth Copyright 2008 Jo-Philipp Wich -Copyright 2010 Manuel Munz +Copyright 2011 Manuel Munz Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -12,6 +12,7 @@ You may obtain a copy of the License at -%> <% +local i = 1 require("luci.model.uci") local uci = luci.model.uci.cursor_state() @@ -23,39 +24,48 @@ end) <%+header%>

<%:SmartGW announcements%>

+ <% if has_smartgw then %> -

<%:Overview of smart gateways in this network%>

-
- - - - - - - - - - - - - -<% for k, gw in ipairs(gws) do %> - - - - - - - - - - - -<% end %> -
<%:Gateway%><%:Status%><%:ETX%><%:Hops%><%:Uplink%><%:Downlink%><%:IPv4%><%:IPv6%><%:Prefix%>
/cgi-bin-status.html"><%=gw["Gateway IP"]%><%=gw.Status%><%=gw.ETX%><%=gw.Hopcnt%><%=gw.Uplink%><%=gw.Downlnk%><%=gw.IPv4%><%=gw.IPv6%><%=gw.Prefix%>
-
+ +
+ <%:Overview of smart gateways in this network%> + + + + + + + + + + + + + + + <% for k, gw in ipairs(gws) do %> + + + + + + + + + + + + + + <% if i == 1 then i = 0 elseif i == 0 then i = 1 end + end %> +
<%:Gateway%><%:Status%><%:ETX%><%:Hops%><%:Uplink%><%:Downlink%><%:IPv4%><%:IPv6%><%:Prefix%>
/cgi-bin-status.html"><%=gw["Gateway IP"]%><%=gw.Status%><%=gw.ETX%><%=gw.Hopcnt%><%=gw.Uplink%><%=gw.Downlnk%><%=gw.IPv4%><%=gw.IPv6%><%=gw.Prefix%>
+
<% else %> -<%:SmartGateway is not configured on this system.%> + + <%:SmartGateway is not configured on this system.%> + <% end %> + <%+footer%> diff --git a/applications/luci-olsr/luasrc/view/status-olsr/topology.htm b/applications/luci-olsr/luasrc/view/status-olsr/topology.htm index 110faeafc..b4221bb80 100644 --- a/applications/luci-olsr/luasrc/view/status-olsr/topology.htm +++ b/applications/luci-olsr/luasrc/view/status-olsr/topology.htm @@ -2,6 +2,7 @@ LuCI - Lua Configuration Interface Copyright 2008 Steven Barth Copyright 2008 Jo-Philipp Wich +Copyright 2011 Manuel Munz Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -12,28 +13,41 @@ You may obtain a copy of the License at $Id$ -%> +<% +local i = 1 +local olsrtools = require "luci.tools.olsr" +%> + <%+header%>

<%:Active OLSR nodes%>

-

<%:Overview of currently known OLSR nodes%>

-
- - - - - - - - -<% for k, route in ipairs(routes) do -%> - - - - - - - -<% end %> -
<%:OLSR node%><%:Last hop%>LQILQETX
"><%=route["Dest. IP"]%>"><%=route["Last hop IP"]%><%=route.LQ%><%=route.NLQ%><%=string.format("%.3f", tonumber(route.Cost) or 0)%>
-
+ +
+ <%:Overview of currently known OLSR nodes%> + + + + + + + + + + <% for k, route in ipairs(routes) do + local cost = string.format("%.3f", tonumber(route.Cost) or 0) + local color = olsrtools.etx_color(tonumber(cost)) + %> + + + + + + + + + + <% if i == 1 then i = 0 elseif i == 0 then i = 1 end + end %> +
<%:OLSR node%><%:Last hop%><%:LQ%><%:NLQ%><%:ETX%>
/cgi-bin-status.html"><%=route["Dest. IP"]%>/cgi-bin-status.html"><%=route["Last hop IP"]%><%=route.LQ%><%=route.NLQ%><%=cost%>
+
+ <%+footer%> -- 2.25.1