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