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">
166 <div style=
"width: 15em; float:left;">
167 <label class=
"cbi-value-title"><%:Interfaces%
></label>
169 <div class=
"cbi-value-field">
170 <div style=
"width: 6em; float:left;">
171 <a href=
"<%=luci.dispatcher.build_url("freifunk
", "olsr
", "interfaces
")%>">
172 <span id=
"nr_ifaces">
177 <div style=
"padding-left: 21em;">
178 <span id=
"interfaces">
186 <div class=
"cbi-value">
187 <div style=
"width: 15em; float:left;">
190 <div class=
"cbi-value-field">
191 <div style=
"width: 6em; float:left;">
192 <a href=
"<%=luci.dispatcher.build_url("freifunk
", "olsr
", "neighbors
")%>">
198 <div style=
"padding-left: 21em;">
199 <span id=
"neighbors">
207 <div class=
"cbi-value">
208 <div style=
"width: 15em; float:left;">
211 <div class=
"cbi-value-field">
212 <div style=
"width: 6em; float:left;">
213 <a href=
"<%=luci.dispatcher.build_url("freifunk
", "olsr
", "topology
")%>">
223 <div class=
"cbi-value">
224 <div style=
"width: 15em; float:left;">
227 <div class=
"cbi-value-field">
228 <div style=
"width: 6em; float:left;">
229 <a href=
"<%=luci.dispatcher.build_url("freifunk
", "olsr
", "hna
")%>">
239 <div class=
"cbi-value">
240 <div style=
"width: 15em; float:left;">
243 <div class=
"cbi-value-field">
244 <div style=
"width: 6em; float:left;">
245 <a href=
"<%=luci.dispatcher.build_url("freifunk
", "olsr
", "topology
")%>">
255 <div class=
"cbi-value">
256 <div style=
"width: 15em; float:left;">
257 <%:Links per node (average)%
>
259 <div class=
"cbi-value-field">
260 <div style=
"width: 6em; float:left;">
261 <span id=
"meshfactor">
272 <h2><a id=
"content" name=
"content">OLSR <%:Configuration%
></a></h2>
274 <div class=
"cbi-map">
275 <div class=
"cbi-section-node">
276 <div class=
"cbi-value">
277 <div style=
"width: 15em; float:left;">
280 <div class=
"cbi-value-field">
281 <%=ver.version%
> (built <%=ver.date%
> on <%=ver.host%
>)
286 <div class=
"cbi-value">
287 <div style=
"width: 15em; float:left;">
290 <div class=
"cbi-value-field">
291 <a href=
"<%=REQUEST_URI%>?openwrt">OpenWrt
</a>,
292 <% if ipv ==
"6and4" then %
>
293 <a href=
"<%=REQUEST_URI%>?conf_v4">OLSRD IPv4
</a>,
294 <a href=
"<%=REQUEST_URI%>?conf_v6">OLSRD IPv6
</a>
296 <a href=
"<%=REQUEST_URI%>?conf">OLSRD
</a>