treewide: always include cbi.js
[project/luci.git] / applications / luci-app-olsr / luasrc / view / status-olsr / overview.htm
1 <%#
2 Copyright 2008 Steven Barth <steven@midlink.org>
3 Copyright 2008 Jo-Philipp Wich <jow@openwrt.org>
4 Copyright 2011 Manuel Munz <freifunk at somakoma dot de>
5 Licensed to the public under the Apache License 2.0.
6 -%>
7
8 <%
9
10 has_ipv4_conf = luci.model.uci.cursor():get_first("olsrd", "olsrd", "IpVersion")
11 has_ipv6_conf = luci.model.uci.cursor():get_first("olsrd6", "olsrd", "IpVersion")
12
13 function write_conf(conf, file)
14 local fs = require "nixio.fs"
15 if fs.access(conf) then
16 luci.http.header("Content-Disposition", "attachment; filename="..file)
17 luci.http.prepare_content("text/plain")
18 luci.http.write(fs.readfile(conf))
19 end
20 end
21
22 conf = luci.http.formvalue()
23
24 if conf.openwrt_v4 then
25 write_conf("/etc/config/olsrd", "olsrd")
26 return false
27 end
28
29 if conf.openwrt_v6 then
30 write_conf("/etc/config/olsrd6", "olsrd6")
31 return false
32 end
33
34 if conf.conf_v4 then
35 write_conf("/var/etc/olsrd.conf", "olsrd.conf")
36 return false
37 end
38
39 if conf.conf_v6 then
40 write_conf("/var/etc/olsrd6.conf", "olsrd6.conf")
41 return false
42 end
43
44 %>
45
46 <%+header%>
47
48 <script type="text/javascript">//<![CDATA[
49
50 XHR.poll(10, '<%=REQUEST_URI%>/json', { },
51 function(x, info)
52 {
53 var e;
54
55 if (! info) {
56 document.getElementById('error').innerHTML = '<%:Could not get any data. Make sure the jsoninfo plugin is installed and allows connections from localhost.%>';
57 return
58 }
59 document.getElementById('error').innerHTML = '';
60
61 if (e = document.getElementById('version'))
62 var version;
63 var date;
64 if (info.v4.config.olsrdVersion != undefined) {
65 version = info.v4.config.olsrdVersion
66 date = info.v4.config.olsrdBuildDate
67 } else if (info.v6.config.olsrdVersion != undefined) {
68 version = info.v6.config.olsrdVersion
69 date = info.v6.config.olsrdBuildDate
70 } else {
71 version = 'unknown'
72 date = 'unknown'
73 }
74 e.innerHTML = version + '<br />' + date;
75
76 if (e = document.getElementById('nr_neigh'))
77 var neigh = 0;
78 if (info.v4.links != undefined) {
79 neigh = neigh + info.v4.links.length
80 }
81 if (info.v6.links != undefined) {
82 neigh = neigh + info.v6.links.length
83 }
84 e.innerHTML = neigh;
85
86
87 if (e = document.getElementById('nr_hna'))
88 var hna = 0;
89 if (info.v4.hna != undefined) {
90 hna = hna + info.v4.hna.length
91 }
92 if (info.v6.hna != undefined) {
93 hna = hna + info.v6.hna.length
94 }
95 e.innerHTML = hna;
96
97
98 if (e = document.getElementById('nr_ifaces'))
99 var nrint = 0
100 if (info.v4.interfaces != undefined) {
101 nrint = nrint + info.v4.interfaces.length
102 }
103 if (info.v6.interfaces != undefined) {
104 nrint = nrint + info.v6.interfaces.length
105 }
106 e.innerHTML = nrint
107
108
109 if (e = document.getElementById('nr_topo'))
110 var topo = 0;
111 var nodes = [];
112
113 Array.prototype.contains = function (element) {
114 for (var i = 0; i < this.length; i++) {
115 if (this[i] == element) {
116 return true;
117 }
118 }
119 return false;
120 }
121
122 if (info.v4.topology != undefined) {
123 topo = topo + info.v4.topology.length;
124 for (var i = 0; i < info.v4.topology.length; i++) {
125 var destip = info.v4.topology[i].destinationIP
126 if (! nodes.contains(destip) ) {
127 nodes.push(destip)
128 }
129 }
130 }
131
132 if (info.v6.topology != undefined) {
133 topo = topo + info.v6.topology.length
134 for (var i = 0; i < info.v6.topology.length; i++) {
135 var destip = info.v6.topology[i].destinationIP
136 if (! nodes.contains(destip) ) {
137 nodes.push(destip)
138 }
139 }
140
141 }
142 e.innerHTML = topo;
143
144 if (e = document.getElementById('nr_nodes'))
145 e.innerHTML = nodes.length;
146
147 if (e = document.getElementById('meshfactor'))
148 var meshfactor = topo / nodes.length
149 e.innerHTML = meshfactor.toFixed(2)
150 }
151 );
152 //]]></script>
153
154
155 <div id="error" class="error"></div>
156
157 <h2 name="content">OLSR <%:Overview%></h2>
158
159 <fieldset class="cbi-section">
160 <legend><%:Network%></legend>
161
162 <div class="table" width="100%" cellspacing="10">
163 <div class="tr"><div class="td" width="33%"><%:Interfaces%></div><div class="td">
164 <a href="<%=REQUEST_URI%>/interfaces">
165 <span id="nr_ifaces">-<span>
166 </a>
167 </div></div>
168 <div class="tr"><div class="td" width="33%"><%:Neighbors%></div><div class="td">
169 <a href="<%=REQUEST_URI%>/neighbors">
170 <span id="nr_neigh">-</span>
171 </a>
172 </div></div>
173 <div class="tr"><div class="td" width="33%"><%:Nodes%></div><div class="td">
174 <a href="<%=REQUEST_URI%>/topology">
175 <span id="nr_nodes">-</span>
176 </a>
177 </div></div>
178 <div class="tr"><div class="td" width="33%"><%:HNA%></div><div class="td">
179 <a href="<%=REQUEST_URI%>/hna">
180 <span id="nr_hna">-</span>
181 </a>
182 </div></div>
183 <div class="tr"><div class="td" width="33%"><%:Links total%></div><div class="td">
184 <a href="<%=REQUEST_URI%>/topology">
185 <span id="nr_topo">-</span>
186 </a>
187 </div></div>
188 <div class="tr"><div class="td" width="33%"><%:Links per node (average)%></div><div class="td">
189 <span id="meshfactor">-</span>
190 </div></div>
191
192
193 </div>
194 </fieldset>
195
196
197 <fieldset class="cbi-section">
198 <legend>OLSR <%:Configuration%></legend>
199 <div class="table" width="100%" cellspacing="10">
200 <div class="tr"><div class="td" width="33%"><%:Version%></div><div class="td">
201 <span id="version">-<span>
202 </div></div>
203 <div class="tr"><div class="td" width="33%"><%:Download Config%></div><div class="td">
204 <% if has_ipv4_conf then %>
205 <a href="<%=REQUEST_URI%>?openwrt_v4">OpenWrt (IPv4)</a>,
206 <% end %>
207 <% if has_ipv6_conf then %>
208 <a href="<%=REQUEST_URI%>?openwrt_v6">OpenWrt (IPv6)</a>,
209 <% end %>
210 <% if has_ipv4_conf then %>
211 <a href="<%=REQUEST_URI%>?conf_v4">OLSRD (IPv4)</a>,
212 <% end %>
213 <% if has_ipv6_conf then %>
214 <a href="<%=REQUEST_URI%>?conf_v6">OLSRD (IPv6)</a>
215 <% end %>
216 </div></div>
217 </div>
218 </fieldset>
219
220 <%+footer%>