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