treewide: always include cbi.js
[project/luci.git] / applications / luci-app-olsr / luasrc / view / status-olsr / smartgw.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 i = 1
10 require("luci.model.uci")
11 local uci = luci.model.uci.cursor_state()
12
13 uci:foreach("olsrd", "olsrd", function(s)
14 if s.SmartGateway and s.SmartGateway == "yes" then has_smartgw = true end
15 end)
16
17
18 if luci.http.formvalue("status") == "1" then
19 local rv = {}
20 for k, gw in ipairs(gws) do
21 gw.tcPathCost = tonumber(gw.tcPathCost)/1024 or 0
22 if gw.tcPathCost == 4096 then
23 gw.tcPathCost = 0
24 end
25
26 rv[#rv+1] = {
27 proto = gw.proto,
28 ipAddress = gw.ipAddress,
29 status = gw.ipv4Status or gw.ipv6Status,
30 tcPathCost = string.format("%.3f", gw.tcPathCost),
31 hopCount = gw.hopCount,
32 uplinkSpeed = gw.uplinkSpeed,
33 downlinkSpeed = gw.downlinkSpeed,
34 v4 = gw.ipv4 and luci.i18n.translate('yes') or luci.i18n.translate('no'),
35 v6 = gw.ipv6 and luci.i18n.translate('yes') or luci.i18n.translate('no'),
36 externalPrefix = gw.externalPrefix
37 }
38 end
39 luci.http.prepare_content("application/json")
40 luci.http.write_json(rv)
41 return
42 end
43 %>
44
45 <%+header%>
46
47 <script type="text/javascript">//<![CDATA[
48 XHR.poll(10, '<%=REQUEST_URI%>', { status: 1 },
49 function(x, info)
50 {
51 var smartgwdiv = document.getElementById('olsrd_smartgw');
52 if (smartgwdiv)
53 {
54 var s = '';
55 for (var idx = 0; idx < info.length; idx++)
56 {
57 var smartgw = info[idx];
58 s += '<div class="tr cbi-section-table-row cbi-rowstyle-'+(1 + (idx % 2))+' proto-' + smartgw.proto + '">'
59 if (smartgw.proto == '6') {
60 linkgw = '<a href="http://[' + smartgw.ipAddress + ']/cgi-bin-status.html">' + smartgw.ipAddress + '</a>'
61 } else {
62 linkgw = '<a href="http://' + smartgw.ipAddress + '/cgi-bin-status.html">' + smartgw.ipAddress + '</a>'
63 }
64
65 s += String.format(
66 '<div class="td cbi-section-table-cell">%s</div>' +
67 '<div class="td cbi-section-table-cell">%s</div>' +
68 '<div class="td cbi-section-table-cell">%s</div>' +
69 '<div class="td cbi-section-table-cell">%s</div>' +
70 '<div class="td cbi-section-table-cell">%s</div>' +
71 '<div class="td cbi-section-table-cell">%s</div>' +
72 '<div class="td cbi-section-table-cell">%s</div>' +
73 '<div class="td cbi-section-table-cell">%s</div>' +
74 '<div class="td cbi-section-table-cell">%s</div>',
75 linkgw, smartgw.status, smartgw.tcPathCost, smartgw.hopCount, smartgw.uplinkSpeed, smartgw.downlinkSpeed, smartgw.v4, smartgw.v6, smartgw.externalPrefix
76 )
77 s += '</div>'
78 }
79 smartgwdiv.innerHTML = s;
80 }
81 }
82 );
83 //]]></script>
84
85
86 <%+header%>
87
88 <h2 name="content"><%:SmartGW announcements%></h2>
89
90 <div id="togglebuttons"></div>
91
92 <% if has_smartgw then %>
93
94 <fieldset class="cbi-section">
95 <legend><%:Overview of smart gateways in this network%></legend>
96 <div class="table cbi-section-table">
97 <div class="thead">
98 <div class="tr cbi-section-table-titles">
99 <div class="th cbi-section-table-cell"><%:Gateway%></div>
100 <div class="th cbi-section-table-cell"><%:Status%></div>
101 <div class="th cbi-section-table-cell"><%:ETX%></div>
102 <div class="th cbi-section-table-cell"><%:Hops%></div>
103 <div class="th cbi-section-table-cell"><%:Uplink%></div>
104 <div class="th cbi-section-table-cell"><%:Downlink%></div>
105 <div class="th cbi-section-table-cell"><%:IPv4%></div>
106 <div class="th cbi-section-table-cell"><%:IPv6%></div>
107 <div class="th cbi-section-table-cell"><%:Prefix%></div>
108
109 </div>
110 </div>
111
112 <div class="tbody" id="olsrd_smartgw">
113 <% for k, gw in ipairs(gws) do
114
115 gw.tcPathCost = tonumber(gw.tcPathCost)/1024 or 0
116 if gw.tcPathCost == 4096 then
117 gw.tcPathCost = 0
118 end
119 %>
120
121 <div class="tr cbi-section-table-row cbi-rowstyle-<%=i%> proto-<%=proto%>">
122 <% if gw.proto == '6' then %>
123 <div class="td cbi-section-table-cell"><a href="http://[<%=gw.ipAddress%>]/cgi-bin-status.html"><%=gw.ipAddress%></a></div>
124 <% else %>
125 <div class="td cbi-section-table-cell"><a href="http://<%=gw.ipAddress%>/cgi-bin-status.html"><%=gw.ipAddress%></a></div>
126 <% end %>
127
128 <div class="td cbi-section-table-cell"><%=gw.ipv4Status or gw.ipv6Status or '-' %></div>
129 <div class="td cbi-section-table-cell"><%=string.format("%.3f", gw.tcPathCost)%></div>
130 <div class="td cbi-section-table-cell"><%=gw.hopCount%></div>
131 <div class="td cbi-section-table-cell"><%=gw.uplinkSpeed%></div>
132 <div class="td cbi-section-table-cell"><%=gw.downlinkSpeed%></div>
133 <div class="td cbi-section-table-cell"><%=gw.ipv4 and luci.i18n.translate('yes') or luci.i18n.translate('no')%></div>
134 <div class="td cbi-section-table-cell"><%=gw.ipv6 and luci.i18n.translate('yes') or luci.i18n.translate('no')%></div>
135 <div class="td cbi-section-table-cell"><%=gw.externalPrefix%></div>
136 </div>
137
138 <% i = ((i % 2) + 1)
139 end %>
140 </div>
141 </div>
142 </fieldset>
143
144 <% else %>
145
146 <%:SmartGateway is not configured on this system.%>
147
148 <% end %>
149
150 <%+status-olsr/common_js%>
151 <%+footer%>