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
|
$pgtitle = array(gettext("Diagnostics"), gettext("Ping"));
|
44
|
require("guiconfig.inc");
|
45
|
|
46
|
define('MAX_COUNT', 10);
|
47
|
define('DEFAULT_COUNT', 3);
|
48
|
|
49
|
if ($_POST || $_REQUEST['host']) {
|
50
|
unset($input_errors);
|
51
|
unset($do_ping);
|
52
|
|
53
|
/* input validation */
|
54
|
$reqdfields = explode(" ", "host count");
|
55
|
$reqdfieldsn = array(gettext("Host"),gettext("Count"));
|
56
|
do_input_validation($_REQUEST, $reqdfields, $reqdfieldsn, &$input_errors);
|
57
|
|
58
|
if (($_REQUEST['count'] < 1) || ($_REQUEST['count'] > MAX_COUNT)) {
|
59
|
$input_errors[] = sprintf(gettext("Count must be between 1 and %s"), MAX_COUNT);
|
60
|
}
|
61
|
|
62
|
if (!$input_errors) {
|
63
|
$do_ping = true;
|
64
|
$host = $_REQUEST['host'];
|
65
|
$interface = $_REQUEST['interface'];
|
66
|
$count = $_POST['count'];
|
67
|
if (preg_match('/[^0-9]/', $count) )
|
68
|
$count = DEFAULT_COUNT;
|
69
|
}
|
70
|
}
|
71
|
if (!isset($do_ping)) {
|
72
|
$do_ping = false;
|
73
|
$host = '';
|
74
|
$count = DEFAULT_COUNT;
|
75
|
}
|
76
|
|
77
|
include("head.inc"); ?>
|
78
|
<body link="#000000" vlink="#000000" alink="#000000">
|
79
|
<? include("fbegin.inc"); ?>
|
80
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
81
|
<tr>
|
82
|
<td>
|
83
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
84
|
<form action="diag_ping.php" method="post" name="iform" id="iform">
|
85
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
86
|
<tr>
|
87
|
<td colspan="2" valign="top" class="listtopic"><?=gettext("Ping"); ?></td>
|
88
|
</tr>
|
89
|
<tr>
|
90
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Host"); ?></td>
|
91
|
<td width="78%" class="vtable">
|
92
|
<?=$mandfldhtml;?><input name="host" type="text" class="formfld" id="host" size="20" value="<?=htmlspecialchars($host);?>"></td>
|
93
|
</tr>
|
94
|
<tr>
|
95
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Interface"); ?></td>
|
96
|
<td width="78%" class="vtable">
|
97
|
<select name="interface" class="formfld">
|
98
|
<?php $interfaces = get_configured_interface_with_descr();
|
99
|
foreach ($interfaces as $iface => $ifacename): ?>
|
100
|
<option value="<?=$iface;?>" <?php if (!link_interface_to_bridge($iface) && $iface == $interface) echo "selected"; ?>>
|
101
|
<?=htmlspecialchars($ifacename);?>
|
102
|
</option>
|
103
|
<?php endforeach; ?>
|
104
|
</select>
|
105
|
</td>
|
106
|
</tr>
|
107
|
<tr>
|
108
|
<td width="22%" valign="top" class="vncellreq"><?= gettext("Count"); ?></td>
|
109
|
<td width="78%" class="vtable">
|
110
|
<select name="count" class="formfld" id="count">
|
111
|
<?php for ($i = 1; $i <= MAX_COUNT; $i++): ?>
|
112
|
<option value="<?=$i;?>" <?php if ($i == $count) echo "selected"; ?>><?=$i;?></option>
|
113
|
<?php endfor; ?>
|
114
|
</select></td>
|
115
|
</tr>
|
116
|
<tr>
|
117
|
<td width="22%" valign="top"> </td>
|
118
|
<td width="78%">
|
119
|
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Ping"); ?>">
|
120
|
</td>
|
121
|
</tr>
|
122
|
<tr>
|
123
|
<td valign="top" colspan="2">
|
124
|
<? if ($do_ping) {
|
125
|
echo "<font face='terminal' size='2'>";
|
126
|
echo "<strong>" . gettext("Ping output") . ":</strong><br>";
|
127
|
echo('<pre>');
|
128
|
$ifaddr = get_interface_ip($interface);
|
129
|
if ($ifaddr)
|
130
|
system("/sbin/ping -S$ifaddr -c$count " . escapeshellarg($host));
|
131
|
else
|
132
|
system("/sbin/ping -c$count " . escapeshellarg($host));
|
133
|
$ifaddr = get_interface_ipv6($interface);
|
134
|
if ($ifaddr)
|
135
|
system("/sbin/ping6 -S$ifaddr -c$count " . escapeshellarg($host));
|
136
|
else
|
137
|
system("/sbin/ping6 -c$count " . escapeshellarg($host));
|
138
|
|
139
|
echo('</pre>');
|
140
|
}
|
141
|
?>
|
142
|
</td>
|
143
|
</tr>
|
144
|
<tr>
|
145
|
<td width="22%" valign="top"> </td>
|
146
|
<td width="78%">
|
147
|
</td>
|
148
|
</tr>
|
149
|
</table>
|
150
|
</form>
|
151
|
</td>
|
152
|
</tr>
|
153
|
</table>
|
154
|
<?php include("fend.inc"); ?>
|
155
|
|