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