1 |
5b237745
|
Scott Ullrich
|
<?php
|
2 |
|
|
/*
|
3 |
aaec5634
|
Renato Botelho
|
* diag_ping.php
|
4 |
9da2cf1c
|
Stephen Beaver
|
*
|
5 |
aaec5634
|
Renato Botelho
|
* part of pfSense (https://www.pfsense.org)
|
6 |
2a2396a6
|
Renato Botelho
|
* Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
|
7 |
aaec5634
|
Renato Botelho
|
* Copyright (c) 2003-2005 Bob Zoller (bob@kludgebox.com)
|
8 |
|
|
* All rights reserved.
|
9 |
fd9ebcd5
|
Stephen Beaver
|
*
|
10 |
aaec5634
|
Renato Botelho
|
* originally based on m0n0wall (http://m0n0.ch/wall)
|
11 |
|
|
* Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
12 |
|
|
* All rights reserved.
|
13 |
fd9ebcd5
|
Stephen Beaver
|
*
|
14 |
aaec5634
|
Renato Botelho
|
* Redistribution and use in source and binary forms, with or without
|
15 |
|
|
* modification, are permitted provided that the following conditions are met:
|
16 |
fd9ebcd5
|
Stephen Beaver
|
*
|
17 |
aaec5634
|
Renato Botelho
|
* 1. Redistributions of source code must retain the above copyright notice,
|
18 |
|
|
* this list of conditions and the following disclaimer.
|
19 |
fd9ebcd5
|
Stephen Beaver
|
*
|
20 |
aaec5634
|
Renato Botelho
|
* 2. Redistributions in binary form must reproduce the above copyright
|
21 |
|
|
* notice, this list of conditions and the following disclaimer in
|
22 |
|
|
* the documentation and/or other materials provided with the
|
23 |
|
|
* distribution.
|
24 |
fd9ebcd5
|
Stephen Beaver
|
*
|
25 |
aaec5634
|
Renato Botelho
|
* 3. All advertising materials mentioning features or use of this software
|
26 |
|
|
* must display the following acknowledgment:
|
27 |
|
|
* "This product includes software developed by the pfSense Project
|
28 |
|
|
* for use in the pfSense® software distribution. (http://www.pfsense.org/).
|
29 |
fd9ebcd5
|
Stephen Beaver
|
*
|
30 |
aaec5634
|
Renato Botelho
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
31 |
|
|
* endorse or promote products derived from this software without
|
32 |
|
|
* prior written permission. For written permission, please contact
|
33 |
|
|
* coreteam@pfsense.org.
|
34 |
fd9ebcd5
|
Stephen Beaver
|
*
|
35 |
aaec5634
|
Renato Botelho
|
* 5. Products derived from this software may not be called "pfSense"
|
36 |
|
|
* nor may "pfSense" appear in their names without prior written
|
37 |
|
|
* permission of the Electric Sheep Fencing, LLC.
|
38 |
fd9ebcd5
|
Stephen Beaver
|
*
|
39 |
aaec5634
|
Renato Botelho
|
* 6. Redistributions of any form whatsoever must retain the following
|
40 |
|
|
* acknowledgment:
|
41 |
0da0d43e
|
Phil Davis
|
*
|
42 |
aaec5634
|
Renato Botelho
|
* "This product includes software developed by the pfSense Project
|
43 |
|
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
44 |
fd9ebcd5
|
Stephen Beaver
|
*
|
45 |
aaec5634
|
Renato Botelho
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
46 |
|
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
47 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
48 |
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
49 |
|
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
50 |
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
51 |
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
52 |
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
53 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
54 |
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
55 |
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
56 |
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
57 |
fd9ebcd5
|
Stephen Beaver
|
*/
|
58 |
5b237745
|
Scott Ullrich
|
|
59 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
60 |
|
|
##|*IDENT=page-diagnostics-ping
|
61 |
5230f468
|
jim-p
|
##|*NAME=Diagnostics: Ping
|
62 |
6b07c15a
|
Matthew Grooms
|
##|*DESCR=Allow access to the 'Diagnostics: Ping' page.
|
63 |
|
|
##|*MATCH=diag_ping.php*
|
64 |
|
|
##|-PRIV
|
65 |
|
|
|
66 |
0d56c06b
|
jim-p
|
$allowautocomplete = true;
|
67 |
36678039
|
Carlos Eduardo Ramos
|
$pgtitle = array(gettext("Diagnostics"), gettext("Ping"));
|
68 |
53483463
|
jim-p
|
require_once("guiconfig.inc");
|
69 |
|
|
|
70 |
5b237745
|
Scott Ullrich
|
define('MAX_COUNT', 10);
|
71 |
|
|
define('DEFAULT_COUNT', 3);
|
72 |
ed69a496
|
jim-p
|
$do_ping = false;
|
73 |
|
|
$host = '';
|
74 |
|
|
$count = DEFAULT_COUNT;
|
75 |
5b237745
|
Scott Ullrich
|
|
76 |
b8cc74ed
|
sullrich
|
if ($_POST || $_REQUEST['host']) {
|
77 |
5b237745
|
Scott Ullrich
|
unset($input_errors);
|
78 |
|
|
unset($do_ping);
|
79 |
|
|
|
80 |
|
|
/* input validation */
|
81 |
|
|
$reqdfields = explode(" ", "host count");
|
82 |
699737d9
|
Phil Davis
|
$reqdfieldsn = array(gettext("Host"), gettext("Count"));
|
83 |
1e9b4611
|
Renato Botelho
|
do_input_validation($_REQUEST, $reqdfields, $reqdfieldsn, $input_errors);
|
84 |
5b237745
|
Scott Ullrich
|
|
85 |
b8cc74ed
|
sullrich
|
if (($_REQUEST['count'] < 1) || ($_REQUEST['count'] > MAX_COUNT)) {
|
86 |
4a5430e3
|
cadu
|
$input_errors[] = sprintf(gettext("Count must be between 1 and %s"), MAX_COUNT);
|
87 |
5b237745
|
Scott Ullrich
|
}
|
88 |
|
|
|
89 |
4f3bb062
|
jim-p
|
$host = trim($_REQUEST['host']);
|
90 |
|
|
$ipproto = $_REQUEST['ipproto'];
|
91 |
5f601060
|
Phil Davis
|
if (($ipproto == "ipv4") && is_ipaddrv6($host)) {
|
92 |
4f3bb062
|
jim-p
|
$input_errors[] = gettext("When using IPv4, the target host must be an IPv4 address or hostname.");
|
93 |
5f601060
|
Phil Davis
|
}
|
94 |
|
|
if (($ipproto == "ipv6") && is_ipaddrv4($host)) {
|
95 |
4f3bb062
|
jim-p
|
$input_errors[] = gettext("When using IPv6, the target host must be an IPv6 address or hostname.");
|
96 |
5f601060
|
Phil Davis
|
}
|
97 |
4f3bb062
|
jim-p
|
|
98 |
5b237745
|
Scott Ullrich
|
if (!$input_errors) {
|
99 |
ed69a496
|
jim-p
|
if ($_POST) {
|
100 |
|
|
$do_ping = true;
|
101 |
|
|
}
|
102 |
947141fd
|
Phil Davis
|
if (isset($_REQUEST['sourceip'])) {
|
103 |
5e1cfe9e
|
heper
|
$sourceip = $_REQUEST['sourceip'];
|
104 |
|
|
}
|
105 |
|
|
$count = $_REQUEST['count'];
|
106 |
699737d9
|
Phil Davis
|
if (preg_match('/[^0-9]/', $count)) {
|
107 |
3a134b53
|
Erik Fonnesbeck
|
$count = DEFAULT_COUNT;
|
108 |
5f601060
|
Phil Davis
|
}
|
109 |
5b237745
|
Scott Ullrich
|
}
|
110 |
|
|
}
|
111 |
45d6ada5
|
Sjon Hortensius
|
|
112 |
288a2a0f
|
Phil Davis
|
if ($do_ping) {
|
113 |
f1a9b09d
|
Colin Fleming
|
?>
|
114 |
45d6ada5
|
Sjon Hortensius
|
<script type="text/javascript">
|
115 |
|
|
//<![CDATA[
|
116 |
947141fd
|
Phil Davis
|
window.onload=function() {
|
117 |
45d6ada5
|
Sjon Hortensius
|
document.getElementById("pingCaptured").wrap='off';
|
118 |
|
|
}
|
119 |
|
|
//]]>
|
120 |
|
|
</script>
|
121 |
f1a9b09d
|
Colin Fleming
|
<?php
|
122 |
45d6ada5
|
Sjon Hortensius
|
$ifscope = '';
|
123 |
|
|
$command = "/sbin/ping";
|
124 |
|
|
if ($ipproto == "ipv6") {
|
125 |
|
|
$command .= "6";
|
126 |
|
|
$ifaddr = is_ipaddr($sourceip) ? $sourceip : get_interface_ipv6($sourceip);
|
127 |
947141fd
|
Phil Davis
|
if (is_linklocal($ifaddr)) {
|
128 |
45d6ada5
|
Sjon Hortensius
|
$ifscope = get_ll_scope($ifaddr);
|
129 |
947141fd
|
Phil Davis
|
}
|
130 |
45d6ada5
|
Sjon Hortensius
|
} else {
|
131 |
|
|
$ifaddr = is_ipaddr($sourceip) ? $sourceip : get_interface_ip($sourceip);
|
132 |
|
|
}
|
133 |
|
|
|
134 |
|
|
if ($ifaddr && (is_ipaddr($host) || is_hostname($host))) {
|
135 |
|
|
$srcip = "-S" . escapeshellarg($ifaddr);
|
136 |
947141fd
|
Phil Davis
|
if (is_linklocal($host) && !strstr($host, "%") && !empty($ifscope)) {
|
137 |
45d6ada5
|
Sjon Hortensius
|
$host .= "%{$ifscope}";
|
138 |
947141fd
|
Phil Davis
|
}
|
139 |
3c98b3f7
|
jim-p
|
}
|
140 |
45d6ada5
|
Sjon Hortensius
|
|
141 |
|
|
$cmd = "{$command} {$srcip} -c" . escapeshellarg($count) . " " . escapeshellarg($host);
|
142 |
|
|
//echo "Ping command: {$cmd}\n";
|
143 |
|
|
$result = shell_exec($cmd);
|
144 |
|
|
|
145 |
947141fd
|
Phil Davis
|
if (empty($result)) {
|
146 |
babf5d85
|
Phil Davis
|
$input_errors[] = sprintf(gettext('Host "%s" did not respond or could not be resolved.'), $host);
|
147 |
947141fd
|
Phil Davis
|
}
|
148 |
45d6ada5
|
Sjon Hortensius
|
|
149 |
|
|
}
|
150 |
|
|
|
151 |
|
|
include('head.inc');
|
152 |
|
|
|
153 |
947141fd
|
Phil Davis
|
if ($input_errors) {
|
154 |
45d6ada5
|
Sjon Hortensius
|
print_input_errors($input_errors);
|
155 |
947141fd
|
Phil Davis
|
}
|
156 |
45d6ada5
|
Sjon Hortensius
|
|
157 |
37676f4e
|
jim-p
|
$form = new Form(false);
|
158 |
45d6ada5
|
Sjon Hortensius
|
|
159 |
|
|
$section = new Form_Section('Ping');
|
160 |
|
|
|
161 |
|
|
$section->addInput(new Form_Input(
|
162 |
|
|
'host',
|
163 |
|
|
'Hostname',
|
164 |
|
|
'text',
|
165 |
|
|
$host,
|
166 |
|
|
['placeholder' => 'Hostname to ping']
|
167 |
|
|
));
|
168 |
|
|
|
169 |
214e79b0
|
Stephen Beaver
|
$section->addInput(new Form_Select(
|
170 |
45d6ada5
|
Sjon Hortensius
|
'ipproto',
|
171 |
214e79b0
|
Stephen Beaver
|
'IP Protocol',
|
172 |
|
|
$ipproto,
|
173 |
|
|
['ipv4' => 'IPv4', 'ipv6' => 'IPv6']
|
174 |
|
|
));
|
175 |
45d6ada5
|
Sjon Hortensius
|
|
176 |
|
|
$section->addInput(new Form_Select(
|
177 |
|
|
'sourceip',
|
178 |
|
|
'Source address',
|
179 |
3f91d34e
|
Stephen Beaver
|
$sourceip,
|
180 |
430cee65
|
stilez
|
array('' => gettext('Automatically selected (default)')) + get_possible_traffic_source_addresses(true)
|
181 |
c6d73876
|
NOYB
|
))->setHelp('Select source address for the ping.');
|
182 |
45d6ada5
|
Sjon Hortensius
|
|
183 |
|
|
$section->addInput(new Form_Select(
|
184 |
|
|
'count',
|
185 |
|
|
'Maximum number of pings',
|
186 |
|
|
$count,
|
187 |
|
|
array_combine(range(1, MAX_COUNT), range(1, MAX_COUNT))
|
188 |
c6d73876
|
NOYB
|
))->setHelp('Select the maximum number of pings.');
|
189 |
45d6ada5
|
Sjon Hortensius
|
|
190 |
|
|
$form->add($section);
|
191 |
37676f4e
|
jim-p
|
|
192 |
|
|
$form->addGlobal(new Form_Button(
|
193 |
|
|
'Submit',
|
194 |
faab522f
|
Renato Botelho
|
'Ping',
|
195 |
37676f4e
|
jim-p
|
null,
|
196 |
|
|
'fa-rss'
|
197 |
|
|
))->addClass('btn-primary');
|
198 |
|
|
|
199 |
45d6ada5
|
Sjon Hortensius
|
print $form;
|
200 |
|
|
|
201 |
288a2a0f
|
Phil Davis
|
if ($do_ping && !empty($result) && !$input_errors) {
|
202 |
45d6ada5
|
Sjon Hortensius
|
?>
|
203 |
|
|
<div class="panel panel-default">
|
204 |
|
|
<div class="panel-heading">
|
205 |
babf5d85
|
Phil Davis
|
<h2 class="panel-title"><?=gettext('Results')?></h2>
|
206 |
45d6ada5
|
Sjon Hortensius
|
</div>
|
207 |
|
|
|
208 |
|
|
<div class="panel-body">
|
209 |
|
|
<pre><?= $result ?></pre>
|
210 |
|
|
</div>
|
211 |
|
|
</div>
|
212 |
|
|
<?php
|
213 |
|
|
}
|
214 |
|
|
|
215 |
|
|
include('foot.inc');
|