2 LuCI - Lua Configuration Interface
3 Copyright 2008 Steven Barth <steven@midlink.org>
4 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
5 Copyright 2011 Manuel Munz <freifunk at somakoma dot de>
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
15 local sys = require "luci.sys"
16 local utl = require "luci.util"
17 local fs = require "luci.fs"
19 function get_version()
20 local data = utl.split((utl.trim(sys.exec("/usr/sbin/olsrd -v"))))
21 local buildfull = utl.trim(utl.split(data[2],": ")[2])
23 version = utl.trim(utl.split(data[1]," - ")[2]),
24 date = utl.trim(utl.split(buildfull, " ")[1]),
25 time = utl.trim(utl.split(buildfull, " ")[2]),
26 host = utl.trim(utl.split(buildfull, " ")[4])
30 local ver = get_version()
32 local ifaces = fetch_txtinfo("int")
33 if not ifaces or not ifaces.Interfaces then
34 luci.template.render("status-olsr/error_olsr")
38 for k,v in pairs(ifaces.Interfaces) do
39 interfaces = utl.trim(interfaces.." "..v.Name)
41 interfaces = string.gsub(interfaces, " ", ", ")
42 local nr_ifaces = #ifaces.Interfaces
44 local links = fetch_txtinfo("links")
45 local nr_neigh = #links.Links
47 for k,v in pairs(links.Links) do
54 neighbors = utl.trim("<a href=http://"..link.."/cgi-bin-status.html>"..link.."</a> "..neighbors)
57 local data = fetch_txtinfo("topology")
58 local nr_topo = #data.Topology
60 for k,v in pairs(data.Topology) do
61 if utl.contains(utable, v["Dest. IP"]) == false then
62 table.insert(utable, v["Dest. IP"])
65 local nr_nodes = #utable
67 local data = fetch_txtinfo("hna")
68 local nr_hna = #data.HNA
70 local meshfactor = string.format("%.2f", nr_topo / nr_nodes)
72 if luci.http.formvalue("status") == "1" then
74 nr_neighbors = nr_neigbors,
75 neighbors = neighbors,
76 interfaces = interfaces,
77 nr_ifaces = nr_ifaces,
81 meshfactor = meshfactor
83 luci.http.prepare_content("application/json")
84 luci.http.write_json(rv)
89 local ipv = luci.model.uci.cursor():get_first("olsrd", "olsrd", "IpVersion", "4")
91 function write_conf(conf, file)
92 if fs.access(conf) then
93 luci.http.header("Content-Disposition", "attachment; filename="..file)
94 luci.http.prepare_content("text/plain")
95 luci.http.write(fs.readfile(conf))
99 conf = luci.http.formvalue()
102 write_conf("/etc/config/olsrd", "olsrd")
107 write_conf("/var/etc/olsrd.conf.ipv4", "olsrd.conf.ipv4")
112 write_conf("/var/etc/olsrd.conf.ipv6", "olsrd.conf.ipv6")
117 write_conf("/var/etc/olsrd.conf", "olsrd.conf")
125 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
126 <script type="text/javascript">//<![CDATA[
128 XHR.poll(30, '<%=REQUEST_URI%>', { status: 1 },
133 if (e = document.getElementById('nr_neighbors'))
134 e.innerHTML = info.nr_neighbors;
136 if (e = document.getElementById('neighbors'))
137 e.innerHTML = info.neighbors;
139 if (e = document.getElementById('nr_ifaces'))
140 e.innerHTML = info.nr_ifaces;
142 if (e = document.getElementById('interfaces'))
143 e.innerHTML = info.interfaces;
145 if (e = document.getElementById('nr_links'))
146 e.innerHTML = info.nr_links;
148 if (e = document.getElementById('nr_topo'))
149 e.innerHTML = info.nr_topo;
151 if (e = document.getElementById('nr_nodes'))
152 e.innerHTML = info.nr_nodes;
154 if (e = document.getElementById('meshfactor'))
155 e.innerHTML = info.meshfactor;
161 <h2><a id="content" name="content">OLSR <%:Overview%></a></h2>
163 <div class="cbi-map">
164 <div class="cbi-section-node">
165 <div class="cbi-value"><label class="cbi-value-title"><%:Interfaces%></label>
166 <div class="cbi-value-field">
167 <div style="width: 6em; float:left;">
168 <a href="<%=luci.dispatcher.build_url("freifunk", "olsr", "interfaces")%>">
169 <span id="nr_ifaces">
173 <div style="padding-left: 6em;">
174 <span id="interfaces">
181 <div class="cbi-value"><label class="cbi-value-title"><%:Neighbors%></label>
182 <div class="cbi-value-field">
183 <div style="width: 6em; float:left;">
184 <a href="<%=luci.dispatcher.build_url("freifunk", "olsr", "neighbors")%>">
189 <div style="padding-left: 6em;">
190 <span id="neighbors">
197 <div class="cbi-value"><label class="cbi-value-title"><%:Nodes%></label>
198 <div class="cbi-value-field"><a href="<%=luci.dispatcher.build_url("freifunk", "olsr", "topology")%>">
205 <div class="cbi-value"><label class="cbi-value-title"><%:HNA%></label>
206 <div class="cbi-value-field"><a href="<%=luci.dispatcher.build_url("freifunk", "olsr", "hna")%>">
213 <div class="cbi-value"><label class="cbi-value-title"><%:Links total%></label>
214 <div class="cbi-value-field"><a href="<%=luci.dispatcher.build_url("freifunk", "olsr", "topology")%>">
221 <div class="cbi-value"><label class="cbi-value-title"><%:Links per node (average)%></label>
222 <div class="cbi-value-field">
223 <span id="meshfactor">
231 <h2><a id="content" name="content">OLSR <%:Configuration%></a></h2>
233 <div class="cbi-map">
234 <div class="cbi-section-node">
235 <div class="cbi-value"><label class="cbi-value-title"><%:Version%></label>
236 <div class="cbi-value-field"><%=ver.version%> (built <%=ver.date%> on <%=ver.host%>)
240 <div class="cbi-value"><label class="cbi-value-title"><%:Download Config%></label>
241 <div class="cbi-value-field">
242 <a href="<%=REQUEST_URI%>?openwrt">OpenWrt</a>,
243 <% if ipv == "6and4" then %>
244 <a href="<%=REQUEST_URI%>?conf_v4">OLSRD IPv4</a>,
245 <a href="<%=REQUEST_URI%>?conf_v6">OLSRD IPv6</a>
247 <a href="<%=REQUEST_URI%>?conf">OLSRD</a>