Project

General

Profile

Download (5.99 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php
2
/*
3
	diag_ping.php
4 5543b9ed Scott Ullrich
	part of m0n0wall (http://m0n0.ch/wall)
5 5b237745 Scott Ullrich
6 5543b9ed Scott Ullrich
	Copyright (C) 2003-2005 Bob Zoller (bob@kludgebox.com) and Manuel Kasper <mk@neon1.net>.
7 5b237745 Scott Ullrich
	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 3c98b3f7 jim-p
/*
32 8bea9639 Seth Mos
	pfSense_BUILDER_BINARIES:	/sbin/ping /sbin/ping6
33 13d193c2 Scott Ullrich
	pfSense_MODULE:	routing
34
*/
35
36 6b07c15a Matthew Grooms
##|+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 0d56c06b jim-p
$allowautocomplete = true;
44 36678039 Carlos Eduardo Ramos
$pgtitle = array(gettext("Diagnostics"), gettext("Ping"));
45 53483463 jim-p
require_once("guiconfig.inc");
46
47 5b237745 Scott Ullrich
48
define('MAX_COUNT', 10);
49
define('DEFAULT_COUNT', 3);
50
51 b8cc74ed sullrich
if ($_POST || $_REQUEST['host']) {
52 5b237745 Scott Ullrich
	unset($input_errors);
53
	unset($do_ping);
54
55
	/* input validation */
56
	$reqdfields = explode(" ", "host count");
57 9d8eeb2f Vinicius Coque
	$reqdfieldsn = array(gettext("Host"),gettext("Count"));
58 1e9b4611 Renato Botelho
	do_input_validation($_REQUEST, $reqdfields, $reqdfieldsn, $input_errors);
59 5b237745 Scott Ullrich
60 b8cc74ed sullrich
	if (($_REQUEST['count'] < 1) || ($_REQUEST['count'] > MAX_COUNT)) {
61 4a5430e3 cadu
		$input_errors[] = sprintf(gettext("Count must be between 1 and %s"), MAX_COUNT);
62 5b237745 Scott Ullrich
	}
63
64 4f3bb062 jim-p
	$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 5b237745 Scott Ullrich
	if (!$input_errors) {
72
		$do_ping = true;
73 c5e51011 jim-p
		$sourceip = $_REQUEST['sourceip'];
74 61ba386b Scott Ullrich
		$count = $_POST['count'];
75 3a134b53 Erik Fonnesbeck
		if (preg_match('/[^0-9]/', $count) )
76
			$count = DEFAULT_COUNT;
77 5b237745 Scott Ullrich
	}
78
}
79
if (!isset($do_ping)) {
80
	$do_ping = false;
81
	$host = '';
82
	$count = DEFAULT_COUNT;
83
}
84 b63695db Scott Ullrich
85 aad0ec36 Bill Marquette
include("head.inc"); ?>
86
<body link="#000000" vlink="#000000" alink="#000000">
87 a3381369 Colin Fleming
<?php include("fbegin.inc"); ?>
88 aad0ec36 Bill Marquette
<table width="100%" border="0" cellpadding="0" cellspacing="0">
89 3c98b3f7 jim-p
<tr><td>
90 5b237745 Scott Ullrich
<?php if ($input_errors) print_input_errors($input_errors); ?>
91 3c98b3f7 jim-p
<form action="diag_ping.php" method="post" name="iform" id="iform">
92
<table width="100%" border="0" cellpadding="6" cellspacing="0">
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 0d56c06b jim-p
	<td width="22%" valign="top" class="vncell"><?=gettext("Source Address"); ?></td>
112 3c98b3f7 jim-p
	<td width="78%" class="vtable">
113 c5e51011 jim-p
		<select name="sourceip" class="formselect">
114 6fee4655 Chris Buechler
			<option value="">Default</option>
115 81448ffa jim-p
		<?php $sourceips = get_possible_traffic_source_addresses(true);
116 0d56c06b jim-p
			foreach ($sourceips as $sip):
117 3c98b3f7 jim-p
				$selected = "";
118 0d56c06b jim-p
				if (!link_interface_to_bridge($sip['value']) && ($sip['value'] == $sourceip))
119 3c98b3f7 jim-p
					$selected = 'selected="selected"';
120
		?>
121 0d56c06b jim-p
			<option value="<?=$sip['value'];?>" <?=$selected;?>>
122
				<?=htmlspecialchars($sip['name']);?>
123 3c98b3f7 jim-p
			</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"; ?>><?=$i;?></option>
134
		<?php endfor; ?>
135
		</select>
136 13d193c2 Scott Ullrich
	</td>
137
</tr>
138 3c98b3f7 jim-p
<tr>
139
	<td width="22%" valign="top">&nbsp;</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 8cd558b6 ayvis
		echo "<strong>" . gettext("Ping output") . ":</strong><br />";
149 3c98b3f7 jim-p
		echo('<pre>');
150 bd6ff328 Renato Botelho
		$ifscope = '';
151 3c98b3f7 jim-p
		$command = "/sbin/ping";
152
		if ($ipproto == "ipv6") {
153
			$command .= "6";
154 dbd182af jim-p
			$ifaddr = is_ipaddr($sourceip) ? $sourceip : get_interface_ipv6($sourceip);
155 bd6ff328 Renato Botelho
			if (is_linklocal($ifaddr))
156
				$ifscope = get_ll_scope($ifaddr);
157 3c98b3f7 jim-p
		} else {
158 c5e51011 jim-p
			$ifaddr = is_ipaddr($sourceip) ? $sourceip : get_interface_ip($sourceip);
159 3c98b3f7 jim-p
		}
160 bd6ff328 Renato Botelho
		if ($ifaddr && (is_ipaddr($host) || is_hostname($host))) {
161 dbd182af jim-p
			$srcip = "-S" . escapeshellarg($ifaddr);
162 bd6ff328 Renato Botelho
			if (is_linklocal($host) && !strstr($host, "%") && !empty($ifscope))
163
				$host .= "%{$ifscope}";
164
		}
165 dbd182af jim-p
166
		$cmd = "{$command} {$srcip} -c" . escapeshellarg($count) . " " . escapeshellarg($host);
167 3c98b3f7 jim-p
		//echo "Ping command: {$cmd}\n";
168
		system($cmd);
169
		echo('</pre>');
170
	}
171
	?>
172
	</td>
173
</tr>
174
<tr>
175
	<td width="22%" valign="top">&nbsp;</td>
176
	<td width="78%">&nbsp;</td>
177
</tr>
178 13d193c2 Scott Ullrich
</table>
179 3c98b3f7 jim-p
</form>
180
</td></tr>
181
</table>
182 bd6ff328 Renato Botelho
<?php include("fend.inc"); ?>