Globally convert headline anchors into name attributes.
[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" src="<%=resource%>/cbi.js"></script>
48 <script type="text/javascript">//<![CDATA[
49 XHR.poll(10, '<%=REQUEST_URI%>', { status: 1 },
50 function(x, info)
51 {
52 var smartgwdiv = document.getElementById('olsrd_smartgw');
53 if (smartgwdiv)
54 {
55 var s = '';
56 for (var idx = 0; idx < info.length; idx++)
57 {
58 var smartgw = info[idx];
59 s += '<tr class="cbi-section-table-row cbi-rowstyle-'+(1 + (idx % 2))+' proto-' + smartgw.proto + '">'
60 if (smartgw.proto == '6') {
61 linkgw = '<a href="http://[' + smartgw.ipAddress + ']/cgi-bin-status.html">' + smartgw.ipAddress + '</a>'
62 } else {
63 linkgw = '<a href="http://' + smartgw.ipAddress + '/cgi-bin-status.html">' + smartgw.ipAddress + '</a>'
64 }
65
66 s += String.format(
67 '<td class="cbi-section-table-cell">%s</td>' +
68 '<td class="cbi-section-table-cell">%s</td>' +
69 '<td class="cbi-section-table-cell">%s</td>' +
70 '<td class="cbi-section-table-cell">%s</td>' +
71 '<td class="cbi-section-table-cell">%s</td>' +
72 '<td class="cbi-section-table-cell">%s</td>' +
73 '<td class="cbi-section-table-cell">%s</td>' +
74 '<td class="cbi-section-table-cell">%s</td>' +
75 '<td class="cbi-section-table-cell">%s</td>',
76 linkgw, smartgw.status, smartgw.tcPathCost, smartgw.hopCount, smartgw.uplinkSpeed, smartgw.downlinkSpeed, smartgw.v4, smartgw.v6, smartgw.externalPrefix
77 )
78 s += '</tr>'
79 }
80 smartgwdiv.innerHTML = s;
81 }
82 }
83 );
84 //]]></script>
85
86
87 <%+header%>
88
89 <h2 name="content"><%:SmartGW announcements%></h2>
90
91 <div id="togglebuttons"></div>
92
93 <% if has_smartgw then %>
94
95 <fieldset class="cbi-section">
96 <legend><%:Overview of smart gateways in this network%></legend>
97 <table class="cbi-section-table">
98 <thead>
99 <tr class="cbi-section-table-titles">
100 <th class="cbi-section-table-cell"><%:Gateway%></th>
101 <th class="cbi-section-table-cell"><%:Status%></th>
102 <th class="cbi-section-table-cell"><%:ETX%></th>
103 <th class="cbi-section-table-cell"><%:Hops%></th>
104 <th class="cbi-section-table-cell"><%:Uplink%></th>
105 <th class="cbi-section-table-cell"><%:Downlink%></th>
106 <th class="cbi-section-table-cell"><%:IPv4%></th>
107 <th class="cbi-section-table-cell"><%:IPv6%></th>
108 <th class="cbi-section-table-cell"><%:Prefix%></th>
109
110 </tr>
111 </thead>
112
113 <tbody id="olsrd_smartgw">
114 <% for k, gw in ipairs(gws) do
115
116 gw.tcPathCost = tonumber(gw.tcPathCost)/1024 or 0
117 if gw.tcPathCost == 4096 then
118 gw.tcPathCost = 0
119 end
120 %>
121
122 <tr class="cbi-section-table-row cbi-rowstyle-<%=i%> proto-<%=proto%>">
123 <% if gw.proto == '6' then %>
124 <td class="cbi-section-table-cell"><a href="http://[<%=gw.ipAddress%>]/cgi-bin-status.html"><%=gw.ipAddress%></a></td>
125 <% else %>
126 <td class="cbi-section-table-cell"><a href="http://<%=gw.ipAddress%>/cgi-bin-status.html"><%=gw.ipAddress%></a></td>
127 <% end %>
128
129 <td class="cbi-section-table-cell"><%=gw.ipv4Status or gw.ipv6Status or '-' %></td>
130 <td class="cbi-section-table-cell"><%=string.format("%.3f", gw.tcPathCost)%></td>
131 <td class="cbi-section-table-cell"><%=gw.hopCount%></td>
132 <td class="cbi-section-table-cell"><%=gw.uplinkSpeed%></td>
133 <td class="cbi-section-table-cell"><%=gw.downlinkSpeed%></td>
134 <td class="cbi-section-table-cell"><%=gw.ipv4 and luci.i18n.translate('yes') or luci.i18n.translate('no')%></td>
135 <td class="cbi-section-table-cell"><%=gw.ipv6 and luci.i18n.translate('yes') or luci.i18n.translate('no')%></td>
136 <td class="cbi-section-table-cell"><%=gw.externalPrefix%></td>
137 </tr>
138
139 <% i = ((i % 2) + 1)
140 end %>
141 </tbody>
142 </table>
143 </fieldset>
144
145 <% else %>
146
147 <%:SmartGateway is not configured on this system.%>
148
149 <% end %>
150
151 <%+status-olsr/common_js%>
152 <%+footer%>