fa32315280f3ceec6ae9668934a12f3c88bbd2a5
[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" src="<%=resource%>/cbi.js"></script>
49 <script type="text/javascript">//<![CDATA[
50
51 XHR.poll(10, '<%=REQUEST_URI%>/json', { },
52                 function(x, info)
53                 {
54                 var e;
55
56                 if (! info) {
57                         document.getElementById('error').innerHTML = '<%:Could not get any data. Make sure the jsoninfo plugin is installed and allows connections from localhost.%>';
58                         return
59                 }
60                 document.getElementById('error').innerHTML = '';
61
62                 if (e = document.getElementById('version'))
63                         var version;
64                         var date;
65                         if (info.v4.config.olsrdVersion != undefined) {
66                                 version = info.v4.config.olsrdVersion
67                                 date = info.v4.config.olsrdBuildDate
68                         } else if (info.v6.config.olsrdVersion != undefined) {
69                                 version = info.v6.config.olsrdVersion
70                                 date = info.v6.config.olsrdBuildDate
71                         } else {
72                                 version = 'unknown'
73                                 date = 'unknown'
74                         }               
75                         e.innerHTML = version + '<br />' + date;
76
77                 if (e = document.getElementById('nr_neigh'))
78                         var neigh = 0;
79                         if (info.v4.links != undefined) {
80                                 neigh = neigh + info.v4.links.length
81                         }
82                         if (info.v6.links != undefined) {
83                                 neigh = neigh + info.v6.links.length
84                         }
85                         e.innerHTML = neigh;
86
87
88                 if (e = document.getElementById('nr_hna'))
89                         var hna = 0;
90                         if (info.v4.hna != undefined) {
91                                 hna = hna + info.v4.hna.length
92                         }
93                         if (info.v6.hna != undefined) {
94                                 hna = hna + info.v6.hna.length
95                         }
96                         e.innerHTML = hna;
97
98
99                 if (e = document.getElementById('nr_ifaces'))
100                         var nrint = 0
101                         if (info.v4.interfaces != undefined) {
102                                 nrint = nrint + info.v4.interfaces.length
103                         }
104                         if (info.v6.interfaces != undefined) {
105                                 nrint = nrint + info.v6.interfaces.length
106                         }
107                         e.innerHTML = nrint
108
109
110                 if (e = document.getElementById('nr_topo'))
111                         var topo = 0;
112                         var nodes = [];
113
114                         Array.prototype.contains = function (element) {
115                                 for (var i = 0; i < this.length; i++) {
116                                         if (this[i] == element) {
117                                                 return true;
118                                         }
119                                 }
120                                 return false;
121                         }
122
123                         if (info.v4.topology != undefined) {
124                                 topo = topo + info.v4.topology.length;
125                                 for (var i = 0; i < info.v4.topology.length; i++) {
126                                         var destip = info.v4.topology[i].destinationIP
127                                         if (! nodes.contains(destip) ) {
128                                                 nodes.push(destip)
129                                         }
130                                 }
131                         }
132
133                         if (info.v6.topology != undefined) {
134                                 topo = topo + info.v6.topology.length
135                                 for (var i = 0; i < info.v6.topology.length; i++) {
136                                         var destip = info.v6.topology[i].destinationIP
137                                         if (! nodes.contains(destip) ) {
138                                                 nodes.push(destip)
139                                         }
140                                 }
141
142                         }
143                         e.innerHTML = topo;
144
145                         if (e = document.getElementById('nr_nodes'))
146                                 e.innerHTML = nodes.length;
147
148                         if (e = document.getElementById('meshfactor'))
149                                 var meshfactor = topo / nodes.length
150                                 e.innerHTML = meshfactor.toFixed(2)
151                 }
152         );
153 //]]></script>
154
155
156 <div id="error" class="error"></div>
157
158 <h2><a id="content" name="content">OLSR <%:Overview%></a></h2>
159
160 <fieldset class="cbi-section">
161         <legend><%:Network%></legend>
162
163         <table width="100%" cellspacing="10">
164                 <tr><td width="33%"><%:Interfaces%></td><td>
165                         <a href="<%=REQUEST_URI%>/interfaces">
166                                 <span id="nr_ifaces">-<span>
167                         </a>
168                 </td></tr>
169                 <tr><td width="33%"><%:Neighbors%></td><td>
170                         <a href="<%=REQUEST_URI%>/neighbors">
171                                 <span id="nr_neigh">-</span>
172                         </a>
173                 </td></tr>
174                 <tr><td width="33%"><%:Nodes%></td><td>
175                         <a href="<%=REQUEST_URI%>/topology">
176                                 <span id="nr_nodes">-</span>
177                         </a>
178                 </td></tr>
179                 <tr><td width="33%"><%:HNA%></td><td>
180                         <a href="<%=REQUEST_URI%>/hna">
181                                 <span id="nr_hna">-</span>
182                         </a>
183                 </td></tr>
184                 <tr><td width="33%"><%:Links total%></td><td>
185                         <a href="<%=REQUEST_URI%>/topology">
186                                 <span id="nr_topo">-</span>
187                         </a>
188                 </td></tr>
189                 <tr><td width="33%"><%:Links per node (average)%></td><td>
190                         <span id="meshfactor">-</span>
191                 </td></tr>
192
193
194         </table>
195 </fieldset>
196
197
198 <fieldset class="cbi-section">
199         <legend>OLSR <%:Configuration%></legend>
200         <table width="100%" cellspacing="10">
201                 <tr><td width="33%"><%:Version%></td><td>
202                         <span id="version">-<span>
203                 </td></tr>
204                 <tr><td width="33%"><%:Download Config%></td><td>
205                         <% if has_ipv4_conf then %>
206                             <a href="<%=REQUEST_URI%>?openwrt_v4">OpenWrt (IPv4)</a>,
207                         <% end %>
208                         <% if has_ipv6_conf then %>
209                             <a href="<%=REQUEST_URI%>?openwrt_v6">OpenWrt (IPv6)</a>,
210                         <% end %>
211                         <% if has_ipv4_conf then %>
212                             <a href="<%=REQUEST_URI%>?conf_v4">OLSRD (IPv4)</a>,
213                         <% end %>
214                         <% if has_ipv6_conf then %>
215                             <a href="<%=REQUEST_URI%>?conf_v6">OLSRD (IPv6)</a>
216                         <% end %>
217                 </td></tr>
218         </table>
219 </fieldset>
220
221 <%+footer%>