ba36ce980ac42fd85d579febb53b49c843066fc8
[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 == 4096 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 = string.format("%.3f", gw.cost),
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 = '';
55 for (var idx = 0; idx < info.length; idx++)
56 {
57 var smartgw = info[idx];
58 var linkgw;
59 s += '<div class="tr cbi-section-table-row cbi-rowstyle-'+(1 + (idx % 2))+' proto-' + smartgw.proto + '">'
60 if (smartgw.proto == '6') {
61 linkgw = '<a href="http://[' + smartgw.originator + ']/cgi-bin-status.html">' + smartgw.originator + '</a>'
62 } else {
63 linkgw = '<a href="http://' + smartgw.originator + '/cgi-bin-status.html">' + smartgw.originator + '</a>'
64 }
65
66 s += String.format(
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 '<div class="td cbi-section-table-cell">%s</div>',
76 linkgw, smartgw.selected, smartgw.cost, smartgw.hops, smartgw.uplink, smartgw.downlink, smartgw.v4, smartgw.v6, smartgw.prefix
77 )
78 s += '</div>'
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 <div class="table cbi-section-table">
98 <div class="thead">
99 <div class="tr cbi-section-table-titles">
100 <div class="th cbi-section-table-cell"><%:Gateway%></div>
101 <div class="th cbi-section-table-cell"><%:Selected%></div>
102 <div class="th cbi-section-table-cell"><%:ETX%></div>
103 <div class="th cbi-section-table-cell"><%:Hops%></div>
104 <div class="th cbi-section-table-cell"><%:Uplink%></div>
105 <div class="th cbi-section-table-cell"><%:Downlink%></div>
106 <div class="th cbi-section-table-cell"><%:IPv4%></div>
107 <div class="th cbi-section-table-cell"><%:IPv6%></div>
108 <div class="th cbi-section-table-cell"><%:Prefix%></div>
109
110 </div>
111 </div>
112
113 <div class="tbody" id="olsrd_smartgw">
114 <% for k, gw in ipairs(gws) do
115
116 gw.cost = tonumber(gw.cost)/1024 or 0
117 if gw.cost == 4096 then
118 gw.cost = 0
119 end
120 %>
121
122 <div class="tr cbi-section-table-row cbi-rowstyle-<%=i%> proto-<%=proto%>">
123 <% if gw.proto == '6' then %>
124 <div class="td cbi-section-table-cell"><a href="http://[<%=gw.originator%>]/cgi-bin-status.html"><%=gw.originator%></a></div>
125 <% else %>
126 <div class="td cbi-section-table-cell"><a href="http://<%=gw.originator%>/cgi-bin-status.html"><%=gw.originator%></a></div>
127 <% end %>
128
129 <div class="td cbi-section-table-cell"><%=gw.selected and luci.i18n.translate('yes') or luci.i18n.translate('no')%></div>
130 <div class="td cbi-section-table-cell"><%=string.format("%.3f", gw.cost)%></div>
131 <div class="td cbi-section-table-cell"><%=gw.hops%></div>
132 <div class="td cbi-section-table-cell"><%=gw.uplink%></div>
133 <div class="td cbi-section-table-cell"><%=gw.downlink%></div>
134 <div class="td cbi-section-table-cell"><%=gw.IPv4 and luci.i18n.translate('yes') or luci.i18n.translate('no')%></div>
135 <div class="td cbi-section-table-cell"><%=gw.IPv6 and luci.i18n.translate('yes') or luci.i18n.translate('no')%></div>
136 <div class="td cbi-section-table-cell"><%=gw.prefix%></div>
137 </div>
138
139 <% i = ((i % 2) + 1)
140 end %>
141 </div>
142 </div>
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%>