8cd2088e425985969cb3d897885f416c5b8518a3
[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.ipv4, gws.ipv6) do
21 gw.cost = tonumber(gw.cost)/1024 or 0
22 if gw.cost >= 100 then
23 gw.cost = 0
24 end
25
26 rv[#rv+1] = {
27 proto = gw.IPv4 and '4' or '6',
28 originator = gw.originator,
29 selected = gw.selected and luci.i18n.translate('yes') or luci.i18n.translate('no'),
30 cost = gw.cost > 0 and string.format("%.3f", gw.cost) or luci.i18n.translate('infinate'),
31 hops = gw.hops,
32 uplink = gw.uplink,
33 downlink = gw.downlink,
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 prefix = gw.prefix
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 = '<div class="tr cbi-section-table-titles">' +
55 '<div class="th cbi-section-table-cell"><%:Gateway%></div>' +
56 '<div class="th cbi-section-table-cell"><%:Selected%></div>' +
57 '<div class="th cbi-section-table-cell"><%:ETX%></div>' +
58 '<div class="th cbi-section-table-cell"><%:Hops%></div>' +
59 '<div class="th cbi-section-table-cell"><%:Uplink%></div>' +
60 '<div class="th cbi-section-table-cell"><%:Downlink%></div>' +
61 '<div class="th cbi-section-table-cell"><%:IPv4%></div>' +
62 '<div class="th cbi-section-table-cell"><%:IPv6%></div>' +
63 '<div class="th cbi-section-table-cell"><%:Prefix%></div>' +
64 '</div>';
65
66 for (var idx = 0; idx < info.length; idx++)
67 {
68 var smartgw = info[idx];
69 var linkgw;
70 s += '<div class="tr cbi-section-table-row cbi-rowstyle-'+(1 + (idx % 2))+' proto-' + smartgw.proto + '">'
71 if (smartgw.proto == '6') {
72 linkgw = '<a href="http://[' + smartgw.originator + ']/cgi-bin-status.html">' + smartgw.originator + '</a>'
73 } else {
74 linkgw = '<a href="http://' + smartgw.originator + '/cgi-bin-status.html">' + smartgw.originator + '</a>'
75 }
76
77 s += String.format(
78 '<div class="td cbi-section-table-cell left">%s</div>' +
79 '<div class="td cbi-section-table-cell left">%s</div>' +
80 '<div class="td cbi-section-table-cell left">%s</div>' +
81 '<div class="td cbi-section-table-cell left">%s</div>' +
82 '<div class="td cbi-section-table-cell left">%s</div>' +
83 '<div class="td cbi-section-table-cell left">%s</div>' +
84 '<div class="td cbi-section-table-cell left">%s</div>' +
85 '<div class="td cbi-section-table-cell left">%s</div>' +
86 '<div class="td cbi-section-table-cell left">%s</div>',
87 linkgw, smartgw.selected, smartgw.cost, smartgw.hops, smartgw.uplink, smartgw.downlink, smartgw.v4, smartgw.v6, smartgw.prefix
88 )
89 s += '</div>'
90 }
91 smartgwdiv.innerHTML = s;
92 }
93 }
94 );
95 //]]></script>
96
97 <h2 name="content"><%:SmartGW announcements%></h2>
98
99 <div id="togglebuttons"></div>
100
101 <% if has_smartgw then %>
102
103 <fieldset class="cbi-section">
104 <legend><%:Overview of smart gateways in this network%></legend>
105 <div class="table cbi-section-table" id="olsrd_smartgw">
106 <div class="tr cbi-section-table-titles">
107 <div class="th cbi-section-table-cell"><%:Gateway%></div>
108 <div class="th cbi-section-table-cell"><%:Selected%></div>
109 <div class="th cbi-section-table-cell"><%:ETX%></div>
110 <div class="th cbi-section-table-cell"><%:Hops%></div>
111 <div class="th cbi-section-table-cell"><%:Uplink%></div>
112 <div class="th cbi-section-table-cell"><%:Downlink%></div>
113 <div class="th cbi-section-table-cell"><%:IPv4%></div>
114 <div class="th cbi-section-table-cell"><%:IPv6%></div>
115 <div class="th cbi-section-table-cell"><%:Prefix%></div>
116 </div>
117
118 <% for k, gw in ipairs(gws.ipv4, gws.ipv6) do
119
120 gw.cost = tonumber(gw.cost)/1024 or 0
121 if gw.cost >= 100 then
122 gw.cost = 0
123 end
124 %>
125
126 <div class="tr cbi-section-table-row cbi-rowstyle-<%=i%> proto-<%=proto%>">
127 <% if gw.proto == '6' then %>
128 <div class="td cbi-section-table-cell left"><a href="http://[<%=gw.originator%>]/cgi-bin-status.html"><%=gw.originator%></a></div>
129 <% else %>
130 <div class="td cbi-section-table-cell left"><a href="http://<%=gw.originator%>/cgi-bin-status.html"><%=gw.originator%></a></div>
131 <% end %>
132
133 <div class="td cbi-section-table-cell left"><%=gw.selected and luci.i18n.translate('yes') or luci.i18n.translate('no')%></div>
134 <div class="td cbi-section-table-cell left"><%=gw.cost > 0 and string.format("%.3f", gw.cost) or luci.i18n.translate('infinate')%></div>
135 <div class="td cbi-section-table-cell left"><%=gw.hops%></div>
136 <div class="td cbi-section-table-cell left"><%=gw.uplink%></div>
137 <div class="td cbi-section-table-cell left"><%=gw.downlink%></div>
138 <div class="td cbi-section-table-cell left"><%=gw.IPv4 and luci.i18n.translate('yes') or luci.i18n.translate('no')%></div>
139 <div class="td cbi-section-table-cell left"><%=gw.IPv6 and luci.i18n.translate('yes') or luci.i18n.translate('no')%></div>
140 <div class="td cbi-section-table-cell left"><%=gw.prefix%></div>
141 </div>
142
143 <% i = ((i % 2) + 1)
144 end %>
145 </div>
146 </fieldset>
147
148 <% else %>
149
150 <%:SmartGateway is not configured on this system.%>
151
152 <% end %>
153
154 <%+status-olsr/common_js%>
155 <%+footer%>