applications/luci-olsr: Add overview page, move old index to neigbors
authorManuel Munz <freifunk@somakoma.de>
Fri, 17 Dec 2010 02:14:28 +0000 (02:14 +0000)
committerManuel Munz <freifunk@somakoma.de>
Fri, 17 Dec 2010 02:14:28 +0000 (02:14 +0000)
applications/luci-olsr/htdocs/cgi-bin-nodes.html [new symlink]
applications/luci-olsr/htdocs/cgi-bin-status.html [new file with mode: 0644]
applications/luci-olsr/luasrc/controller/olsr.lua
applications/luci-olsr/luasrc/view/status-olsr/index.htm [deleted file]
applications/luci-olsr/luasrc/view/status-olsr/interfaces.htm [new file with mode: 0644]
applications/luci-olsr/luasrc/view/status-olsr/neighbors.htm [new file with mode: 0644]
applications/luci-olsr/luasrc/view/status-olsr/overview.htm [new file with mode: 0644]
applications/luci-olsr/luasrc/view/status-olsr/smartgw.htm

diff --git a/applications/luci-olsr/htdocs/cgi-bin-nodes.html b/applications/luci-olsr/htdocs/cgi-bin-nodes.html
new file mode 120000 (symlink)
index 0000000..80d235f
--- /dev/null
@@ -0,0 +1 @@
+cgi-bin-status.html
\ No newline at end of file
diff --git a/applications/luci-olsr/htdocs/cgi-bin-status.html b/applications/luci-olsr/htdocs/cgi-bin-status.html
new file mode 100644 (file)
index 0000000..0270f4a
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="refresh" content="0; URL=/cgi-bin/luci/freifunk/olsr/neighbors" />
+</head>
+<body style="background-color: black">
+<a style="color: white; text-decoration: none" href="/cgi-bin/luci/freifunk/olsr/neighbors">LuCI - Lua Configuration Interface</a>
+</body>
+</html>
index 9866060..d5a212c 100644 (file)
@@ -9,11 +9,17 @@ function index()
        local i18n = luci.i18n.translate
 
        local page  = node("admin", "status", "olsr")
        local i18n = luci.i18n.translate
 
        local page  = node("admin", "status", "olsr")
-       page.target = call("action_index")
+       page.target = template("status-olsr/overview")
        page.title  = "OLSR"
        page.i18n   = "olsr"
        page.subindex = true
 
        page.title  = "OLSR"
        page.i18n   = "olsr"
        page.subindex = true
 
+       local page  = node("admin", "status", "olsr", "neighbors")
+       page.target = call("action_neigh")
+       page.title  = i18n("Neighbors")
+       page.subindex = true
+       page.order  = 5
+
        local page  = node("admin", "status", "olsr", "routes")
        page.target = call("action_routes")
        page.title  = i18n("Routen")
        local page  = node("admin", "status", "olsr", "routes")
        page.target = call("action_routes")
        page.title  = i18n("Routen")
@@ -39,6 +45,11 @@ function index()
        page.title  = "SmartGW"
        page.order  = 60
 
        page.title  = "SmartGW"
        page.order  = 60
 
+       local page  = node("admin", "status", "olsr", "interfaces")
+        page.target = call("action_interfaces")
+        page.title  = i18n("Interfaces")
+        page.order  = 70
+
        local ol = entry(
                {"admin", "services", "olsrd"},
                cbi("olsr/olsrd"), "OLSR"
        local ol = entry(
                {"admin", "services", "olsrd"},
                cbi("olsr/olsrd"), "OLSR"
@@ -77,7 +88,7 @@ function index()
        )
 end
 
        )
 end
 
-function action_index()
+function action_neigh()
        local data = fetch_txtinfo("links")
 
        if not data or not data.Links then
        local data = fetch_txtinfo("links")
 
        if not data or not data.Links then
@@ -102,7 +113,7 @@ function action_index()
 
        table.sort(data.Links, compare)
 
 
        table.sort(data.Links, compare)
 
-       luci.template.render("status-olsr/index", {links=data.Links})
+       luci.template.render("status-olsr/neighbors", {links=data.Links})
 end
 
 function action_routes()
 end
 
 function action_routes()
@@ -201,7 +212,16 @@ function action_smartgw()
         luci.template.render("status-olsr/smartgw", {gws=data.Gateways})
 end
 
         luci.template.render("status-olsr/smartgw", {gws=data.Gateways})
 end
 
+function action_interfaces()
+        local data = fetch_txtinfo("interfaces")
+
+        if not data or not data.Interfaces then
+                luci.template.render("status-olsr/error_olsr")
+                return nil
+        end
 
 
+        luci.template.render("status-olsr/interfaces", {iface=data.Interfaces})
+end
 
 -- Internal
 function fetch_txtinfo(otable)
 
 -- Internal
 function fetch_txtinfo(otable)
diff --git a/applications/luci-olsr/luasrc/view/status-olsr/index.htm b/applications/luci-olsr/luasrc/view/status-olsr/index.htm
deleted file mode 100644 (file)
index 786c859..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-<%#
-LuCI - Lua Configuration Interface
-Copyright 2008 Steven Barth <steven@midlink.org>
-Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
-
-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%>
-<h2><a id="content" name="content"><%:OLSR connections%></a></h2>
-<p><%:Overview of currently established OLSR connections%></p>
-<br />
-<table class="smalltext" cellspacing="0" cellpadding="6">
-<tr>
-<th><%:Neighbour IP%></th>
-<th><%:Hostname%></th>
-<th><%:Local interface IP%></th>
-<th><%:Device%></th>
-<th>LQ</th>
-<th>NLQ</th>
-<th>ETX</th>
-</tr>
-<% 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
-%>
-<tr>
-<td><a href="http://<%=link["Remote IP"]%>/cgi-bin-status.html"><%=link["Remote IP"]%></a></td>
-<td><a href="http://<%=link["Hostname"]%>/cgi-bin-status.html"><%=link["Hostname"]%></a></td>
-<td><%=link["Local IP"]%></td>
-<td><%=link["Local Device"]%></td>
-<td><%=link.LQ%></td>
-<td><%=link.NLQ%></td>
-<td style="background-color:<%=color%>"><%=string.format("%.3f", link.Cost)%></td>
-</tr>
-<% end %>
-</table>
-<br />
-<h3><%:Legend%>:</h3>
-<ul>
-<li><strong>LQ: </strong><%:Success rate of packages received from the neighbour%></li>
-<li><strong>NLQ: </strong><%:Success rate of packages sent to the neighbour%></li>
-<li><strong>ETX: </strong><%:Expected retransmission count%></li>
-</ul>
-<%+footer%>
diff --git a/applications/luci-olsr/luasrc/view/status-olsr/interfaces.htm b/applications/luci-olsr/luasrc/view/status-olsr/interfaces.htm
new file mode 100644 (file)
index 0000000..b409fed
--- /dev/null
@@ -0,0 +1,45 @@
+<%#
+LuCI - Lua Configuration Interface
+Copyright 2008 Steven Barth <steven@midlink.org>
+Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
+Copyright 2010 Manuel Munz <freifunk at somakoma dot de>
+
+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: mid.htm 5448 2009-10-31 15:54:11Z jow $
+
+-%>
+<%+header%>
+<h2><a id="content" name="content"><%:Interfaces%></a></h2>
+<p><%:Overview of interfaces where OLSR is running%></p>
+<br />
+<table class="smalltext" cellspacing="0" cellpadding="6">
+<tr>
+<th><%:Interface%></th>
+<th><%:State%></th>
+<th><%:MTU%></th>
+<th><%:WLAN%></th>
+<th><%:Source address%></th>
+<th><%:Netmask%></th>
+<th><%:Broadcast address%></th>
+</tr>
+
+<% for k, i in ipairs(iface) do %>
+<tr>
+<td><%=i.Name%></td>
+<td><%=i.State%></td>
+<td><%=i.MTU%></td>
+<td><%=i.WLAN%></td>
+<td><%=i["Src-Adress"]%></td>
+<td><%=i.Mask%></td>
+<td><%=i["Dst-Adress"]%></td>
+</tr>
+<% end %>
+
+</table>
+<br />
+<%+footer%>
diff --git a/applications/luci-olsr/luasrc/view/status-olsr/neighbors.htm b/applications/luci-olsr/luasrc/view/status-olsr/neighbors.htm
new file mode 100644 (file)
index 0000000..60afdc3
--- /dev/null
@@ -0,0 +1,61 @@
+<%#
+LuCI - Lua Configuration Interface
+Copyright 2008 Steven Barth <steven@midlink.org>
+Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+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%>
+<h2><a id="content" name="content"><%:OLSR connections%></a></h2>
+<p><%:Overview of currently established OLSR connections%></p>
+<br />
+<table class="smalltext" cellspacing="0" cellpadding="6">
+<tr>
+<th><%:Neighbour IP%></th>
+<th><%:Hostname%></th>
+<th><%:Local interface IP%></th>
+<th><%:Device%></th>
+<th>LQ</th>
+<th>NLQ</th>
+<th>ETX</th>
+</tr>
+<% 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
+%>
+<tr>
+<td><a href="http://<%=link["Remote IP"]%>/cgi-bin-status.html"><%=link["Remote IP"]%></a></td>
+<td><a href="http://<%=link["Hostname"]%>/cgi-bin-status.html"><%=link["Hostname"]%></a></td>
+<td><%=link["Local IP"]%></td>
+<td><%=link["Local Device"]%></td>
+<td><%=link.LQ%></td>
+<td><%=link.NLQ%></td>
+<td style="background-color:<%=color%>"><%=string.format("%.3f", link.Cost)%></td>
+</tr>
+<% end %>
+</table>
+<br />
+<h3><%:Legend%>:</h3>
+<ul>
+<li><strong>LQ: </strong><%:Success rate of packages received from the neighbour%></li>
+<li><strong>NLQ: </strong><%:Success rate of packages sent to the neighbour%></li>
+<li><strong>ETX: </strong><%:Expected retransmission count%></li>
+</ul>
+<%+footer%>
diff --git a/applications/luci-olsr/luasrc/view/status-olsr/overview.htm b/applications/luci-olsr/luasrc/view/status-olsr/overview.htm
new file mode 100644 (file)
index 0000000..673938c
--- /dev/null
@@ -0,0 +1,178 @@
+<%#
+LuCI - Lua Configuration Interface
+Copyright 2008 Steven Barth <steven@midlink.org>
+Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
+Copyright 2010 Manuel Munz <freifunk at somakoma dot de>
+
+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
+-%>
+
+<%
+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("/rom/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("<a href=http://"..link.."/cgi-bin-status.html>"..link.."</a> "..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)
+
+local ipv = luci.model.uci.cursor():get_first("olsrd", "olsrd", "IpVersion", "4")
+
+function write_conf(conf, file)
+       if fs.access(conf) then
+               luci.http.header("Content-Disposition", "attachment; filename="..file)
+               luci.http.prepare_content("text/plain")
+               luci.http.write(fs.readfile(conf))
+       end
+end
+
+conf = luci.http.formvalue()
+
+if conf.openwrt then
+       write_conf("/etc/config/olsrd", "olsrd")
+       return false
+end
+
+if conf.conf_v4 then   
+       write_conf("/var/etc/olsrd.conf.ipv4", "olsrd.conf.ipv4")
+       return false
+end
+
+if conf.conf_v6 then
+       write_conf("/var/etc/olsrd.conf.ipv6", "olsrd.conf.ipv6")
+       return false
+end
+
+if conf.conf then
+       write_conf("/var/etc/olsrd.conf", "olsrd.conf")
+       return false
+end
+
+%>
+
+<%+header%>
+<h2><a id="content" name="content">OLSR <%:Overview%></a></h2>
+
+<div class="cbi-map">
+       <div class="cbi-section-node">
+               <div class="cbi-value"><label class="cbi-value-title"><%:Interfaces%></label>
+                       <div class="cbi-value-field">
+                               <div style="width: 6em; float:left;">
+                                       <a href="<%=luci.dispatcher.build_url("freifunk", "olsr", "interfaces")%>"><%=nr_ifaces%></a>
+                               </div>
+                               <div style="padding-left: 6em;">
+                                       <%=interfaces%>
+                               </div>
+                       </div>
+               </div>
+       
+               <div class="cbi-value"><label class="cbi-value-title"><%:Neighbors%></label>
+                       <div class="cbi-value-field">
+                               <div style="width: 6em; float:left;">
+                                       <a href="<%=luci.dispatcher.build_url("freifunk", "olsr", "neighbors")%>"><%=nr_neigh%></a>
+                               </div>
+                               <div style="padding-left: 6em;">
+                                       <%=neighbors%>
+                               </div>
+                       </div>
+               </div>
+
+               <div class="cbi-value"><label class="cbi-value-title"><%:Nodes%></label>
+                       <div class="cbi-value-field"><a href="<%=luci.dispatcher.build_url("freifunk", "olsr", "topology")%>"><%=nr_nodes%></a>
+                       </div>
+               </div>
+
+               <div class="cbi-value"><label class="cbi-value-title"><%:HNA%></label>
+                       <div class="cbi-value-field"><a href="<%=luci.dispatcher.build_url("freifunk", "olsr", "hna")%>"><%=nr_hna%></a>
+                       </div>
+               </div>
+
+               <div class="cbi-value"><label class="cbi-value-title"><%:Links total%></label>
+                       <div class="cbi-value-field"><a href="<%=luci.dispatcher.build_url("freifunk", "olsr", "topology")%>"><%=nr_topo%></a>
+                       </div>
+               </div>
+
+               <div class="cbi-value"><label class="cbi-value-title"><%:Links per node (average)%></label>
+                       <div class="cbi-value-field"><%=meshfactor%>
+                       </div>
+               </div>
+       </div>
+</div>
+
+<h2><a id="content" name="content">OLSR <%:Configuration%></a></h2>
+
+<div class="cbi-map">
+       <div class="cbi-section-node">
+               <div class="cbi-value"><label class="cbi-value-title"><%:Version%></label>
+                       <div class="cbi-value-field"><%=ver.version%> (built <%=ver.date%> on <%=ver.host%>)
+                       </div>
+               </div>
+
+               <div class="cbi-value"><label class="cbi-value-title"><%:Download Config%></label>
+                       <div class="cbi-value-field">
+                               <a href="<%=REQUEST_URI%>?openwrt">OpenWrt</a>,
+                               <% if ipv == "6and4" then %>
+                                       <a href="<%=REQUEST_URI%>?conf_v4">OLSRD IPv4</a>,
+                                       <a href="<%=REQUEST_URI%>?conf_v6">OLSRD IPv6</a>
+                               <% else %>
+                                       <a href="<%=REQUEST_URI%>?conf">OLSRD</a>
+                               <% end %>
+                       </div>
+               </div>
+       </div>
+</div>
+
+<%+footer%>
index a64c7bf..10d516c 100644 (file)
@@ -2,16 +2,15 @@
 LuCI - Lua Configuration Interface
 Copyright 2008 Steven Barth <steven@midlink.org>
 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
 LuCI - Lua Configuration Interface
 Copyright 2008 Steven Barth <steven@midlink.org>
 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
+Copyright 2010 Manuel Munz <freifunk at somakoma dot de>
 
 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
 
 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: mid.htm 5448 2009-10-31 15:54:11Z jow $
-
 -%>
 -%>
+
 <%
 require("luci.model.uci")
 local uci = luci.model.uci.cursor_state()
 <%
 require("luci.model.uci")
 local uci = luci.model.uci.cursor_state()