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
|
<%#
Copyright 2008 Steven Barth <steven@midlink.org>
Copyright 2008 Jo-Philipp Wich <jow@openwrt.org>
Copyright 2011 Manuel Munz <freifunk at somakoma dot de>
Licensed to the public under the Apache License 2.0.
-%>
<%
has_ipv4_conf = luci.model.uci.cursor():get_first("olsrd", "olsrd", "IpVersion")
has_ipv6_conf = luci.model.uci.cursor():get_first("olsrd6", "olsrd", "IpVersion")
function write_conf(conf, file)
local fs = require "nixio.fs"
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_v4 then
write_conf("/etc/config/olsrd", "olsrd")
return false
end
if conf.openwrt_v6 then
write_conf("/etc/config/olsrd6", "olsrd6")
return false
end
if conf.conf_v4 then
write_conf("/var/etc/olsrd.conf", "olsrd.conf")
return false
end
if conf.conf_v6 then
write_conf("/var/etc/olsrd6.conf", "olsrd6.conf")
return false
end
%>
<%+header%>
<script type="text/javascript" src="<%=resource%>/cbi.js"></script>
<script type="text/javascript">//<![CDATA[
XHR.poll(10, '<%=REQUEST_URI%>/json', { },
function(x, info)
{
var e;
if (! info) {
document.getElementById('error').innerHTML = '<%:Could not get any data. Make sure the jsoninfo plugin is installed and allows connections from localhost.%>';
return
}
document.getElementById('error').innerHTML = '';
if (e = document.getElementById('version'))
var version;
var date;
if (info.v4.config.olsrdVersion != undefined) {
version = info.v4.config.olsrdVersion
date = info.v4.config.olsrdBuildDate
} else if (info.v6.config.olsrdVersion != undefined) {
version = info.v6.config.olsrdVersion
date = info.v6.config.olsrdBuildDate
} else {
version = 'unknown'
date = 'unknown'
}
e.innerHTML = version + '<br />' + date;
if (e = document.getElementById('nr_neigh'))
var neigh = 0;
if (info.v4.links != undefined) {
neigh = neigh + info.v4.links.length
}
if (info.v6.links != undefined) {
neigh = neigh + info.v6.links.length
}
e.innerHTML = neigh;
if (e = document.getElementById('nr_hna'))
var hna = 0;
if (info.v4.hna != undefined) {
hna = hna + info.v4.hna.length
}
if (info.v6.hna != undefined) {
hna = hna + info.v6.hna.length
}
e.innerHTML = hna;
if (e = document.getElementById('nr_ifaces'))
var nrint = 0
if (info.v4.interfaces != undefined) {
nrint = nrint + info.v4.interfaces.length
}
if (info.v6.interfaces != undefined) {
nrint = nrint + info.v6.interfaces.length
}
e.innerHTML = nrint
if (e = document.getElementById('nr_topo'))
var topo = 0;
var nodes = [];
Array.prototype.contains = function (element) {
for (var i = 0; i < this.length; i++) {
if (this[i] == element) {
return true;
}
}
return false;
}
if (info.v4.topology != undefined) {
topo = topo + info.v4.topology.length;
for (var i = 0; i < info.v4.topology.length; i++) {
var destip = info.v4.topology[i].destinationIP
if (! nodes.contains(destip) ) {
nodes.push(destip)
}
}
}
if (info.v6.topology != undefined) {
topo = topo + info.v6.topology.length
for (var i = 0; i < info.v6.topology.length; i++) {
var destip = info.v6.topology[i].destinationIP
if (! nodes.contains(destip) ) {
nodes.push(destip)
}
}
}
e.innerHTML = topo;
if (e = document.getElementById('nr_nodes'))
e.innerHTML = nodes.length;
if (e = document.getElementById('meshfactor'))
var meshfactor = topo / nodes.length
e.innerHTML = meshfactor.toFixed(2)
}
);
//]]></script>
<div id="error" class="error"></div>
<h2><a id="content" name="content">OLSR <%:Overview%></a></h2>
<fieldset class="cbi-section">
<legend><%:Network%></legend>
<table width="100%" cellspacing="10">
<tr><td width="33%"><%:Interfaces%></td><td>
<a href="<%=REQUEST_URI%>/interfaces">
<span id="nr_ifaces">-<span>
</a>
</td></tr>
<tr><td width="33%"><%:Neighbors%></td><td>
<a href="<%=REQUEST_URI%>/neighbors">
<span id="nr_neigh">-</span>
</a>
</td></tr>
<tr><td width="33%"><%:Nodes%></td><td>
<a href="<%=REQUEST_URI%>/topology">
<span id="nr_nodes">-</span>
</a>
</td></tr>
<tr><td width="33%"><%:HNA%></td><td>
<a href="<%=REQUEST_URI%>/hna">
<span id="nr_hna">-</span>
</a>
</td></tr>
<tr><td width="33%"><%:Links total%></td><td>
<a href="<%=REQUEST_URI%>/topology">
<span id="nr_topo">-</span>
</a>
</td></tr>
<tr><td width="33%"><%:Links per node (average)%></td><td>
<span id="meshfactor">-</span>
</td></tr>
</table>
</fieldset>
<fieldset class="cbi-section">
<legend>OLSR <%:Configuration%></legend>
<table width="100%" cellspacing="10">
<tr><td width="33%"><%:Version%></td><td>
<span id="version">-<span>
</td></tr>
<tr><td width="33%"><%:Download Config%></td><td>
<% if has_ipv4_conf then %>
<a href="<%=REQUEST_URI%>?openwrt_v4">OpenWrt (IPv4)</a>,
<% end %>
<% if has_ipv6_conf then %>
<a href="<%=REQUEST_URI%>?openwrt_v6">OpenWrt (IPv6)</a>,
<% end %>
<% if has_ipv4_conf then %>
<a href="<%=REQUEST_URI%>?conf_v4">OLSRD (IPv4)</a>,
<% end %>
<% if has_ipv6_conf then %>
<a href="<%=REQUEST_URI%>?conf_v6">OLSRD (IPv6)</a>
<% end %>
</td></tr>
</table>
</fieldset>
<%+footer%>
|