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