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