1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
<%#
LuCI - Lua Configuration Interface
Copyright 2008 Steven Barth <steven@midlink.org>
Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
Copyright 2011 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("/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)
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)
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%>
<script type="text/javascript" src="<%=resource%>/cbi.js"></script>
<script type="text/javascript">//<![CDATA[
XHR.poll(30, '<%=REQUEST_URI%>', { status: 1 },
function(x, info)
{
var e;
if (e = document.getElementById('nr_neighbors'))
e.innerHTML = info.nr_neighbors;
if (e = document.getElementById('neighbors'))
e.innerHTML = info.neighbors;
if (e = document.getElementById('nr_ifaces'))
e.innerHTML = info.nr_ifaces;
if (e = document.getElementById('interfaces'))
e.innerHTML = info.interfaces;
if (e = document.getElementById('nr_links'))
e.innerHTML = info.nr_links;
if (e = document.getElementById('nr_topo'))
e.innerHTML = info.nr_topo;
if (e = document.getElementById('nr_nodes'))
e.innerHTML = info.nr_nodes;
if (e = document.getElementById('meshfactor'))
e.innerHTML = info.meshfactor;
}
);
//]]></script>
<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")%>">
<span id="nr_ifaces">
<%=nr_ifaces%></a>
<span>
</div>
<div style="padding-left: 6em;">
<span id="interfaces">
<%=interfaces%>
</span>
</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")%>">
<span id="nr_neigh">
<%=nr_neigh%></a>
</span>
</div>
<div style="padding-left: 6em;">
<span id="neighbors">
<%=neighbors%>
</span>
</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")%>">
<span id="nr_nodes">
<%=nr_nodes%></a>
</span>
</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")%>">
<span id="nr_hna">
<%=nr_hna%></a>
</span>
</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")%>">
<span id="nr_topo">
<%=nr_topo%></a>
</span>
</div>
</div>
<div class="cbi-value"><label class="cbi-value-title"><%:Links per node (average)%></label>
<div class="cbi-value-field">
<span id="meshfactor">
<%=meshfactor%>
</span>
</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%>
|