luci-mod-admin-full: protect network post actions with csrf tokens
[project/luci.git] / modules / luci-mod-admin-full / luasrc / view / admin_network / diagnostics.htm
1 <%#
2 Copyright 2010 Jo-Philipp Wich <jow@openwrt.org>
3 Licensed to the public under the Apache License 2.0.
4 -%>
5
6 <%+header%>
7
8 <%
9 local fs = require "nixio.fs"
10 local has_ping6 = fs.access("/bin/ping6") or fs.access("/usr/bin/ping6")
11 local has_traceroute6 = fs.access("/usr/bin/traceroute6")
12 %>
13
14 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
15 <script type="text/javascript">//<![CDATA[
16 var stxhr = new XHR();
17
18 function update_status(field, proto)
19 {
20 var tool = field.name;
21 var addr = field.value;
22 var protocol = proto ? "6" : "";
23
24 var legend = document.getElementById('diag-rc-legend');
25 var output = document.getElementById('diag-rc-output');
26
27 if (legend && output)
28 {
29 output.innerHTML =
30 '<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" /> ' +
31 '<%:Waiting for command to complete...%>'
32 ;
33
34 legend.parentNode.style.display = 'block';
35 legend.style.display = 'inline';
36
37 stxhr.post('<%=url('admin/network')%>/diag_' + tool + protocol + '/' + addr, { token: '<%=token%>' },
38 function(x)
39 {
40 if (x.responseText)
41 {
42 legend.style.display = 'none';
43 output.innerHTML = String.format('<pre>%h</pre>', x.responseText);
44 }
45 else
46 {
47 legend.style.display = 'none';
48 output.innerHTML = '<span class="error"><%:Bad address specified!%></span>';
49 }
50 }
51 );
52 }
53 }
54 //]]></script>
55
56 <form method="post" action="<%=url('admin/network/diagnostics')%>">
57 <div class="cbi-map">
58 <h2 name="content"><%:Diagnostics%></h2>
59
60 <fieldset class="cbi-section">
61 <legend><%:Network Utilities%></legend>
62
63 <br />
64
65 <div style="width:30%; float:left">
66 <input style="margin: 5px 0" type="text" value="dev.openwrt.org" name="ping" /><br />
67 <% if has_ping6 then %>
68 <select name="ping_proto" style="width:auto">
69 <option value="" selected="selected"><%:IPv4%></option>
70 <option value="6"><%:IPv6%></option>
71 </select>
72 <input type="button" value="<%:Ping%>" class="cbi-button cbi-button-apply" onclick="update_status(this.form.ping, this.form.ping_proto.selectedIndex)" />
73 <% else %>
74 <input type="button" value="<%:Ping%>" class="cbi-button cbi-button-apply" onclick="update_status(this.form.ping)" />
75 <% end %>
76 </div>
77
78 <div style="width:33%; float:left">
79 <input style="margin: 5px 0" type="text" value="dev.openwrt.org" name="traceroute" /><br />
80 <% if has_traceroute6 then %>
81 <select name="traceroute_proto" style="width:auto">
82 <option value="" selected="selected"><%:IPv4%></option>
83 <option value="6"><%:IPv6%></option>
84 </select>
85 <input type="button" value="<%:Traceroute%>" class="cbi-button cbi-button-apply" onclick="update_status(this.form.traceroute, this.form.traceroute_proto.selectedIndex)" />
86 <% else %>
87 <input type="button" value="<%:Traceroute%>" class="cbi-button cbi-button-apply" onclick="update_status(this.form.traceroute)" />
88 <% end %>
89 <% if not has_traceroute6 then %>
90 <p>&#160;</p>
91 <p><%:Install iputils-traceroute6 for IPv6 traceroute%></p>
92 <% end %>
93 </div>
94
95 <div style="width:33%; float:left;">
96 <input style="margin: 5px 0" type="text" value="dev.openwrt.org" name="nslookup" /><br />
97 <input type="button" value="<%:Nslookup%>" class="cbi-button cbi-button-apply" onclick="update_status(this.form.nslookup)" />
98 </div>
99
100 <br style="clear:both" /><br />
101
102 </fieldset>
103 </div>
104
105 <fieldset class="cbi-section" style="display:none">
106 <legend id="diag-rc-legend"><%:Collecting data...%></legend>
107 <span id="diag-rc-output"></span>
108 </fieldset>
109 </form>
110
111 <%+footer%>