03dd5aab29004935cc921147d80732406b978524
[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("/bin/traceroute6") or fs.access("/usr/bin/traceroute6")
12
13 local dns_host = luci.config.diag and luci.config.diag.dns or "dev.openwrt.org"
14 local ping_host = luci.config.diag and luci.config.diag.ping or "dev.openwrt.org"
15 local route_host = luci.config.diag and luci.config.diag.route or "dev.openwrt.org"
16 %>
17
18 <script type="text/javascript">//<![CDATA[
19 var stxhr = new XHR();
20
21 function update_status(field, proto)
22 {
23 var tool = field.name;
24 var addr = field.value;
25 var protocol = proto ? "6" : "";
26
27 var legend = document.getElementById('diag-rc-legend');
28 var output = document.getElementById('diag-rc-output');
29
30 if (legend && output)
31 {
32 output.innerHTML =
33 '<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" /> ' +
34 '<%:Waiting for command to complete...%>'
35 ;
36
37 legend.parentNode.style.display = 'block';
38 legend.style.display = 'inline';
39
40 stxhr.post('<%=url('admin/network')%>/diag_' + tool + protocol + '/' + addr, { token: '<%=token%>' },
41 function(x)
42 {
43 if (x.responseText)
44 {
45 legend.style.display = 'none';
46 output.innerHTML = String.format('<pre>%h</pre>', x.responseText);
47 }
48 else
49 {
50 legend.style.display = 'none';
51 output.innerHTML = '<span class="error"><%:Bad address specified!%></span>';
52 }
53 }
54 );
55 }
56 }
57 //]]></script>
58
59 <form method="post" action="<%=url('admin/network/diagnostics')%>">
60 <div class="cbi-map">
61 <h2 name="content"><%:Diagnostics%></h2>
62
63 <div class="cbi-section">
64 <legend><%:Network Utilities%></legend>
65
66 <div class="table">
67 <div class="tr">
68 <div class="td left">
69 <input style="margin: 5px 0" type="text" value="<%=ping_host%>" name="ping" /><br />
70 <% if has_ping6 then %>
71 <span>
72 <select name="ping_proto" style="width:auto">
73 <option value="" selected="selected"><%:IPv4%></option>
74 <option value="6"><%:IPv6%></option>
75 </select>
76 </span>
77 <input type="button" value="<%:Ping%>" class="cbi-button cbi-button-apply" onclick="update_status(this.form.ping, this.form.ping_proto.selectedIndex)" />
78 <% else %>
79 <input type="button" value="<%:Ping%>" class="cbi-button cbi-button-apply" onclick="update_status(this.form.ping)" />
80 <% end %>
81 </div>
82
83 <div class="td left">
84 <input style="margin: 5px 0" type="text" value="<%=route_host%>" name="traceroute" /><br />
85 <% if has_traceroute6 then %>
86 <span>
87 <select name="traceroute_proto" style="width:auto">
88 <option value="" selected="selected"><%:IPv4%></option>
89 <option value="6"><%:IPv6%></option>
90 </select>
91 </span>
92 <input type="button" value="<%:Traceroute%>" class="cbi-button cbi-button-apply" onclick="update_status(this.form.traceroute, this.form.traceroute_proto.selectedIndex)" />
93 <% else %>
94 <input type="button" value="<%:Traceroute%>" class="cbi-button cbi-button-apply" onclick="update_status(this.form.traceroute)" />
95 <% end %>
96 <% if not has_traceroute6 then %>
97 <p>&#160;</p>
98 <p><%:Install iputils-traceroute6 for IPv6 traceroute%></p>
99 <% end %>
100 </div>
101
102 <div class="td left">
103 <input style="margin: 5px 0" type="text" value="<%=dns_host%>" name="nslookup" /><br />
104 <input type="button" value="<%:Nslookup%>" class="cbi-button cbi-button-apply" onclick="update_status(this.form.nslookup)" />
105 </div>
106 </div>
107 </div>
108 </div>
109 </div>
110
111 <div class="cbi-section" style="display:none">
112 <strong id="diag-rc-legend"></strong>
113 <span id="diag-rc-output"></span>
114 </div>
115 </form>
116
117 <%+footer%>