Merge pull request #278 from nmav/ocserv
[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 } else {
76 version = 'unknown'
77 date = 'unknown'
78 }
79 e.innerHTML = version + '<br />' + date;
80
81 if (e = document.getElementById('nr_neigh'))
82 var neigh = 0;
83 if (info.v4.links != undefined) {
84 neigh = neigh + info.v4.links.length
85 }
86 if (info.v6.links != undefined) {
87 neigh = neigh + info.v6.links.length
88 }
89 e.innerHTML = neigh;
90
91
92 if (e = document.getElementById('nr_hna'))
93 var hna = 0;
94 if (info.v4.hna != undefined) {
95 hna = hna + info.v4.hna.length
96 }
97 if (info.v6.hna != undefined) {
98 hna = hna + info.v6.hna.length
99 }
100 e.innerHTML = hna;
101
102
103 if (e = document.getElementById('nr_ifaces'))
104 var nrint = 0
105 if (info.v4.interfaces != undefined) {
106 nrint = nrint + info.v4.interfaces.length
107 }
108 if (info.v6.interfaces != undefined) {
109 nrint = nrint + info.v6.interfaces.length
110 }
111 e.innerHTML = nrint
112
113
114 if (e = document.getElementById('nr_topo'))
115 var topo = 0;
116 var nodes = [];
117
118 Array.prototype.contains = function (element) {
119 for (var i = 0; i < this.length; i++) {
120 if (this[i] == element) {
121 return true;
122 }
123 }
124 return false;
125 }
126
127 if (info.v4.topology != undefined) {
128 topo = topo + info.v4.topology.length;
129 for (var i = 0; i < info.v4.topology.length; i++) {
130 var destip = info.v4.topology[i].destinationIP
131 if (! nodes.contains(destip) ) {
132 nodes.push(destip)
133 }
134 }
135 }
136
137 if (info.v6.topology != undefined) {
138 topo = topo + info.v6.topology.length
139 for (var i = 0; i < info.v6.topology.length; i++) {
140 var destip = info.v6.topology[i].destinationIP
141 if (! nodes.contains(destip) ) {
142 nodes.push(destip)
143 }
144 }
145
146 }
147 e.innerHTML = topo;
148
149 if (e = document.getElementById('nr_nodes'))
150 e.innerHTML = nodes.length;
151
152 if (e = document.getElementById('meshfactor'))
153 var meshfactor = topo / nodes.length
154 e.innerHTML = meshfactor.toFixed(2)
155 }
156 );
157 //]]></script>
158
159
160 <div id="error" class="error"></div>
161
162 <h2><a id="content" name="content">OLSR <%:Overview%></a></h2>
163
164 <fieldset class="cbi-section">
165 <legend><%:Network%></legend>
166
167 <table width="100%" cellspacing="10">
168 <tr><td width="33%"><%:Interfaces%></td><td>
169 <a href="<%=REQUEST_URI%>/interfaces">
170 <span id="nr_ifaces">-<span>
171 </a>
172 </td></tr>
173 <tr><td width="33%"><%:Neighbors%></td><td>
174 <a href="<%=REQUEST_URI%>/neighbors">
175 <span id="nr_neigh">-</span>
176 </a>
177 </td></tr>
178 <tr><td width="33%"><%:Nodes%></td><td>
179 <a href="<%=REQUEST_URI%>/topology">
180 <span id="nr_nodes">-</span>
181 </a>
182 </td></tr>
183 <tr><td width="33%"><%:HNA%></td><td>
184 <a href="<%=REQUEST_URI%>/hna">
185 <span id="nr_hna">-</span>
186 </a>
187 </td></tr>
188 <tr><td width="33%"><%:Links total%></td><td>
189 <a href="<%=REQUEST_URI%>/topology">
190 <span id="nr_topo">-</span>
191 </a>
192 </td></tr>
193 <tr><td width="33%"><%:Links per node (average)%></td><td>
194 <span id="meshfactor">-</span>
195 </td></tr>
196
197
198 </table>
199 </fieldset>
200
201
202 <fieldset class="cbi-section">
203 <legend>OLSR <%:Configuration%></legend>
204 <table width="100%" cellspacing="10">
205 <tr><td width="33%"><%:Version%></td><td>
206 <span id="version">-<span>
207 </td></tr>
208 <tr><td width="33%"><%:Download Config%></td><td>
209 <a href="<%=REQUEST_URI%>?openwrt">OpenWrt</a>,
210 <% if ipv == "6and4" then %>
211 <a href="<%=REQUEST_URI%>?conf_v4">OLSRD IPv4</a>,
212 <a href="<%=REQUEST_URI%>?conf_v6">OLSRD IPv6</a>
213 <% else %>
214 <a href="<%=REQUEST_URI%>?conf">OLSRD</a>
215 <% end %>
216 </td></tr>
217 </table>
218 </fieldset>
219
220 <%+footer%>