1
|
<?php
|
2
|
/*
|
3
|
diag_ping.php
|
4
|
part of m0n0wall (http://m0n0.ch/wall)
|
5
|
|
6
|
Copyright (C) 2003-2005 Bob Zoller (bob@kludgebox.com) and Manuel Kasper <mk@neon1.net>.
|
7
|
All rights reserved.
|
8
|
|
9
|
Redistribution and use in source and binary forms, with or without
|
10
|
modification, are permitted provided that the following conditions are met:
|
11
|
|
12
|
1. Redistributions of source code must retain the above copyright notice,
|
13
|
this list of conditions and the following disclaimer.
|
14
|
|
15
|
2. Redistributions in binary form must reproduce the above copyright
|
16
|
notice, this list of conditions and the following disclaimer in the
|
17
|
documentation and/or other materials provided with the distribution.
|
18
|
|
19
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
20
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
21
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
22
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
23
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
24
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
25
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
26
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
27
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28
|
POSSIBILITY OF SUCH DAMAGE.
|
29
|
*/
|
30
|
|
31
|
/*
|
32
|
pfSense_BUILDER_BINARIES: /sbin/ping /sbin/ping6
|
33
|
pfSense_MODULE: routing
|
34
|
*/
|
35
|
|
36
|
##|+PRIV
|
37
|
##|*IDENT=page-diagnostics-ping
|
38
|
##|*NAME=Diagnostics: Ping page
|
39
|
##|*DESCR=Allow access to the 'Diagnostics: Ping' page.
|
40
|
##|*MATCH=diag_ping.php*
|
41
|
##|-PRIV
|
42
|
|
43
|
$allowautocomplete = true;
|
44
|
$pgtitle = array(gettext("Diagnostics"), gettext("Ping"));
|
45
|
require_once("guiconfig.inc");
|
46
|
|
47
|
|
48
|
define('MAX_COUNT', 10);
|
49
|
define('DEFAULT_COUNT', 3);
|
50
|
|
51
|
if ($_POST || $_REQUEST['host']) {
|
52
|
unset($input_errors);
|
53
|
unset($do_ping);
|
54
|
|
55
|
/* input validation */
|
56
|
$reqdfields = explode(" ", "host count");
|
57
|
$reqdfieldsn = array(gettext("Host"),gettext("Count"));
|
58
|
do_input_validation($_REQUEST, $reqdfields, $reqdfieldsn, $input_errors);
|
59
|
|
60
|
if (($_REQUEST['count'] < 1) || ($_REQUEST['count'] > MAX_COUNT)) {
|
61
|
$input_errors[] = sprintf(gettext("Count must be between 1 and %s"), MAX_COUNT);
|
62
|
}
|
63
|
|
64
|
$host = trim($_REQUEST['host']);
|
65
|
$ipproto = $_REQUEST['ipproto'];
|
66
|
if (($ipproto == "ipv4") && is_ipaddrv6($host))
|
67
|
$input_errors[] = gettext("When using IPv4, the target host must be an IPv4 address or hostname.");
|
68
|
if (($ipproto == "ipv6") && is_ipaddrv4($host))
|
69
|
$input_errors[] = gettext("When using IPv6, the target host must be an IPv6 address or hostname.");
|
70
|
|
71
|
if (!$input_errors) {
|
72
|
$do_ping = true;
|
73
|
$sourceip = $_REQUEST['sourceip'];
|
74
|
$count = $_POST['count'];
|
75
|
if (preg_match('/[^0-9]/', $count) )
|
76
|
$count = DEFAULT_COUNT;
|
77
|
}
|
78
|
}
|
79
|
if (!isset($do_ping)) {
|
80
|
$do_ping = false;
|
81
|
$host = '';
|
82
|
$count = DEFAULT_COUNT;
|
83
|
}
|
84
|
|
85
|
include("head.inc"); ?>
|
86
|
<body link="#000000" vlink="#000000" alink="#000000">
|
87
|
<?php include("fbegin.inc"); ?>
|
88
|
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="ping">
|
89
|
<tr><td>
|
90
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
91
|
<form action="diag_ping.php" method="post" name="iform" id="iform">
|
92
|
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="tabcont">
|
93
|
<tr>
|
94
|
<td colspan="2" valign="top" class="listtopic"><?=gettext("Ping"); ?></td>
|
95
|
</tr>
|
96
|
<tr>
|
97
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Host"); ?></td>
|
98
|
<td width="78%" class="vtable">
|
99
|
<?=$mandfldhtml;?><input name="host" type="text" class="formfldunknown" id="host" size="20" value="<?=htmlspecialchars($host);?>" /></td>
|
100
|
</tr>
|
101
|
<tr>
|
102
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("IP Protocol"); ?></td>
|
103
|
<td width="78%" class="vtable">
|
104
|
<select name="ipproto" class="formselect">
|
105
|
<option value="ipv4" <?php if ($ipproto == "ipv4") echo "selected=\"selected\"" ?>>IPv4</option>
|
106
|
<option value="ipv6" <?php if ($ipproto == "ipv6") echo "selected=\"selected\"" ?>>IPv6</option>
|
107
|
</select>
|
108
|
</td>
|
109
|
</tr>
|
110
|
<tr>
|
111
|
<td width="22%" valign="top" class="vncell"><?=gettext("Source Address"); ?></td>
|
112
|
<td width="78%" class="vtable">
|
113
|
<select name="sourceip" class="formselect">
|
114
|
<option value="">Default</option>
|
115
|
<?php $sourceips = get_possible_traffic_source_addresses(true);
|
116
|
foreach ($sourceips as $sip):
|
117
|
$selected = "";
|
118
|
if (!link_interface_to_bridge($sip['value']) && ($sip['value'] == $sourceip))
|
119
|
$selected = "selected=\"selected\"";
|
120
|
?>
|
121
|
<option value="<?=$sip['value'];?>" <?=$selected;?>>
|
122
|
<?=htmlspecialchars($sip['name']);?>
|
123
|
</option>
|
124
|
<?php endforeach; ?>
|
125
|
</select>
|
126
|
</td>
|
127
|
</tr>
|
128
|
<tr>
|
129
|
<td width="22%" valign="top" class="vncellreq"><?= gettext("Count"); ?></td>
|
130
|
<td width="78%" class="vtable">
|
131
|
<select name="count" class="formfld" id="count">
|
132
|
<?php for ($i = 1; $i <= MAX_COUNT; $i++): ?>
|
133
|
<option value="<?=$i;?>" <?php if ($i == $count) echo "selected=\"selected\""; ?>><?=$i;?></option>
|
134
|
<?php endfor; ?>
|
135
|
</select>
|
136
|
</td>
|
137
|
</tr>
|
138
|
<tr>
|
139
|
<td width="22%" valign="top"> </td>
|
140
|
<td width="78%">
|
141
|
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Ping"); ?>" />
|
142
|
</td>
|
143
|
</tr>
|
144
|
<tr>
|
145
|
<td valign="top" colspan="2">
|
146
|
<?php if ($do_ping) {
|
147
|
echo "<font face=\"terminal\" size=\"2\">";
|
148
|
echo "<strong>" . gettext("Ping output") . ":</strong><br />";
|
149
|
?>
|
150
|
<script type="text/javascript">
|
151
|
//<![CDATA[
|
152
|
window.onload=function(){
|
153
|
document.getElementById("pingCaptured").wrap='off';
|
154
|
}
|
155
|
//]]>
|
156
|
</script>
|
157
|
<?php
|
158
|
echo "<textarea id=\"pingCaptured\" style=\"width:98%\" name=\"code\" rows=\"15\" cols=\"66\" readonly=\"readonly\">";
|
159
|
$ifscope = '';
|
160
|
$command = "/sbin/ping";
|
161
|
if ($ipproto == "ipv6") {
|
162
|
$command .= "6";
|
163
|
$ifaddr = is_ipaddr($sourceip) ? $sourceip : get_interface_ipv6($sourceip);
|
164
|
if (is_linklocal($ifaddr))
|
165
|
$ifscope = get_ll_scope($ifaddr);
|
166
|
} else {
|
167
|
$ifaddr = is_ipaddr($sourceip) ? $sourceip : get_interface_ip($sourceip);
|
168
|
}
|
169
|
if ($ifaddr && (is_ipaddr($host) || is_hostname($host))) {
|
170
|
$srcip = "-S" . escapeshellarg($ifaddr);
|
171
|
if (is_linklocal($host) && !strstr($host, "%") && !empty($ifscope))
|
172
|
$host .= "%{$ifscope}";
|
173
|
}
|
174
|
|
175
|
$cmd = "{$command} {$srcip} -c" . escapeshellarg($count) . " " . escapeshellarg($host);
|
176
|
//echo "Ping command: {$cmd}\n";
|
177
|
system($cmd);
|
178
|
echo('</textarea> </font>');
|
179
|
}
|
180
|
?>
|
181
|
</td>
|
182
|
</tr>
|
183
|
<tr>
|
184
|
<td width="22%" valign="top"> </td>
|
185
|
<td width="78%"> </td>
|
186
|
</tr>
|
187
|
</table>
|
188
|
</form>
|
189
|
</td></tr>
|
190
|
</table>
|
191
|
<?php include("fend.inc"); ?>
|
192
|
</body>
|
193
|
</html>
|