64666880da180889fbbdab69dbf4e5da5e4211ab
[project/luci.git] / modules / admin-full / luasrc / view / admin_network / diagnostics.htm
1 <%#
2 LuCI - Lua Configuration Interface
3 Copyright 2010 Jo-Philipp Wich <xm@subsignal.org>
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9         http://www.apache.org/licenses/LICENSE-2.0
10
11 $Id$
12
13 -%>
14
15 <%+header%>
16
17 <%
18 local fs   = require "nixio.fs"
19 local has_ping6 = fs.access("/bin/ping6") or fs.access("/usr/bin/ping6")
20 local has_traceroute6 = fs.access("/usr/bin/traceroute6")
21 %>
22
23 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
24 <script type="text/javascript">//<![CDATA[
25         var stxhr = new XHR();
26
27         function update_status(field,proto)
28         {
29                 var tool = field.name;
30                 var addr = field.value;
31                 var protocol = ""
32
33                 var legend = document.getElementById('diag-rc-legend');
34                 var output = document.getElementById('diag-rc-output');
35
36                 if (typeof proto != 'undefined') {
37                         for(var i = 0; i < proto.length; i++) {
38                                 if(proto[i].checked) {
39                                         protocol = proto[i].value;
40                                 }
41                         }
42                 }
43
44                 if (legend && output)
45                 {
46                         output.innerHTML =
47                                 '<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" /> ' +
48                                 '<%:Waiting for command to complete...%>'
49                         ;
50
51                         legend.parentNode.style.display = 'block';
52                         legend.style.display = 'inline';
53
54                         stxhr.get('<%=luci.dispatcher.build_url("admin", "network")%>/diag_' + tool + protocol + '/' + addr, null,
55                                 function(x)
56                                 {
57                                         if (x.responseText)
58                                         {
59                                                 legend.style.display = 'none';
60                                                 output.innerHTML = String.format('<pre>%h</pre>', x.responseText);
61                                         }
62                                         else
63                                         {
64                                                 legend.style.display = 'none';
65                                                 output.innerHTML = '<span class="error"><%:Bad address specified!%></span>';
66                                         }
67                                 }
68                         );
69                 }
70         }
71 //]]></script>
72
73 <form method="post" action="<%=pcdata(luci.http.getenv("REQUEST_URI"))%>">
74         <div class="cbi-map">
75                 <h2><a id="content" name="content"><%:Diagnostics%></a></h2>
76
77                 <fieldset class="cbi-section">
78                         <legend><%:Network Utilities%></legend>
79
80                         <br />
81
82                         <div style="width:30%; float:left">
83                                 <input style="width: 50%" type="text" value="openwrt.org" name="ping" />
84                                 <input type="button" value="<%:Ping%>" class="cbi-button cbi-button-apply" onclick="update_status(this.form.ping,this.form.proto)" />
85                                 <% if has_ping6 then %>
86                                 <div style="width:100%; margin-top: 10px;">
87                                         <input type="radio" name="proto" value="" checked="checked" /> <%:IPv4%>
88                                         <input type="radio" name="proto" value="6" /> <%:IPv6%>
89                                 </div>
90                                 <%end%>
91                         </div>
92
93                         <div style="width:33%; float:left">
94                                 <input style="width: 50%" type="text" value="openwrt.org" name="traceroute" />
95                                 <input type="button" value="<%:Traceroute%>" class="cbi-button cbi-button-apply" onclick="update_status(this.form.traceroute,this.form.trproto)" />
96                                 <% if has_traceroute6 then %>
97                                 <div style="width:100%; margin-top: 10px;">
98                                         <input type="radio" name="trproto" value="" checked="checked" /> <%:IPv4%>
99                                         <input type="radio" name="trproto" value="6" /> <%:IPv6%>
100                                 </div>
101                                 <%end%>
102                         </div>
103
104                         <div style="width:33%; float:left;">
105                                 <input style="width: 50%" type="text" value="openwrt.org" name="nslookup" />
106                                 <input type="button" value="<%:Nslookup%>" class="cbi-button cbi-button-apply" onclick="update_status(this.form.nslookup)" />
107                         </div>
108
109                         <br style="clear:both" /><br />
110
111                 </fieldset>
112         </div>
113
114         <fieldset class="cbi-section" style="display:none">
115                 <legend id="diag-rc-legend"><%:Collecting data...%></legend>
116                 <span id="diag-rc-output"></span>
117         </fieldset>
118 </form>
119
120 <%+footer%>