Project

General

Profile

Download (6.19 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 36678039 Carlos Eduardo Ramos
$pgtitle = array(gettext("Diagnostics"), gettext("Ping"));
44 53483463 jim-p
require_once("guiconfig.inc");
45
46 5b237745 Scott Ullrich
47
define('MAX_COUNT', 10);
48
define('DEFAULT_COUNT', 3);
49
50 b8cc74ed sullrich
if ($_POST || $_REQUEST['host']) {
51 5b237745 Scott Ullrich
	unset($input_errors);
52
	unset($do_ping);
53
54
	/* input validation */
55
	$reqdfields = explode(" ", "host count");
56 9d8eeb2f Vinicius Coque
	$reqdfieldsn = array(gettext("Host"),gettext("Count"));
57 b8cc74ed sullrich
	do_input_validation($_REQUEST, $reqdfields, $reqdfieldsn, &$input_errors);
58 5b237745 Scott Ullrich
59 b8cc74ed sullrich
	if (($_REQUEST['count'] < 1) || ($_REQUEST['count'] > MAX_COUNT)) {
60 4a5430e3 cadu
		$input_errors[] = sprintf(gettext("Count must be between 1 and %s"), MAX_COUNT);
61 5b237745 Scott Ullrich
	}
62
63 4f3bb062 jim-p
	$host = trim($_REQUEST['host']);
64
	$ipproto = $_REQUEST['ipproto'];
65
	if (($ipproto == "ipv4") && is_ipaddrv6($host))
66
		$input_errors[] = gettext("When using IPv4, the target host must be an IPv4 address or hostname.");
67
	if (($ipproto == "ipv6") && is_ipaddrv4($host))
68
		$input_errors[] = gettext("When using IPv6, the target host must be an IPv6 address or hostname.");
69
70 5b237745 Scott Ullrich
	if (!$input_errors) {
71
		$do_ping = true;
72 b8cc74ed sullrich
		$interface = $_REQUEST['interface'];
73 61ba386b Scott Ullrich
		$count = $_POST['count'];
74 3a134b53 Erik Fonnesbeck
		if (preg_match('/[^0-9]/', $count) )
75
			$count = DEFAULT_COUNT;
76 5b237745 Scott Ullrich
	}
77
}
78
if (!isset($do_ping)) {
79
	$do_ping = false;
80
	$host = '';
81
	$count = DEFAULT_COUNT;
82
}
83 b63695db Scott Ullrich
84 aad0ec36 Bill Marquette
include("head.inc"); ?>
85
<body link="#000000" vlink="#000000" alink="#000000">
86 a3381369 Colin Fleming
<?php include("fbegin.inc"); ?>
87 aad0ec36 Bill Marquette
<table width="100%" border="0" cellpadding="0" cellspacing="0">
88 3c98b3f7 jim-p
<tr><td>
89 5b237745 Scott Ullrich
<?php if ($input_errors) print_input_errors($input_errors); ?>
90 3c98b3f7 jim-p
<form action="diag_ping.php" method="post" name="iform" id="iform">
91
<table width="100%" border="0" cellpadding="6" cellspacing="0">
92
<tr>
93
	<td colspan="2" valign="top" class="listtopic"><?=gettext("Ping"); ?></td>
94
</tr>
95
<tr>
96
	<td width="22%" valign="top" class="vncellreq"><?=gettext("Host"); ?></td>
97
	<td width="78%" class="vtable">
98
		<?=$mandfldhtml;?><input name="host" type="text" class="formfldunknown" id="host" size="20" value="<?=htmlspecialchars($host);?>"></td>
99
</tr>
100
<tr>
101
	<td width="22%" valign="top" class="vncellreq"><?=gettext("IP Protocol"); ?></td>
102
	<td width="78%" class="vtable">
103
		<select name="ipproto" class="formselect">
104
			<option value="ipv4" <?php if ($ipproto == "ipv4") echo 'selected="selected"' ?>>IPv4</option>
105
			<option value="ipv6" <?php if ($ipproto == "ipv6") echo 'selected="selected"' ?>>IPv6</option>
106
		</select>
107
	</td>
108
</tr>
109
<tr>
110
	<td width="22%" valign="top" class="vncellreq"><?=gettext("Interface"); ?></td>
111
	<td width="78%" class="vtable">
112
		<select name="interface" class="formselect">
113
			<option value="">Any</option>
114
		<?php $listenips = get_possible_listen_ips();
115 53483463 jim-p
			foreach (array('server', 'client') as $mode) {
116
				if (is_array($config['openvpn']["openvpn-{$mode}"])) {
117
					foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) {
118
						if (!isset($setting['disable'])) {
119
							$vpn = array();
120
							$vpn['value'] = 'ovpn' . substr($mode, 0, 1) . $setting['vpnid'];
121
							$vpn['name'] = gettext("OpenVPN") . " ".$mode.": ".htmlspecialchars($setting['description']);
122
							$listenips[] = $vpn;
123
						}
124
					}
125
				}
126
			}
127 3c98b3f7 jim-p
			foreach ($listenips as $lip):
128
				$selected = "";
129
				if (!link_interface_to_bridge($lip['value']) && ($lip['value'] == $interface))
130
					$selected = 'selected="selected"';
131
		?>
132
			<option value="<?=$lip['value'];?>" <?=$selected;?>>
133
				<?=htmlspecialchars($lip['name']);?>
134
			</option>
135
			<?php endforeach; ?>
136
		</select>
137
	</td>
138
</tr>
139
<tr>
140
	<td width="22%" valign="top" class="vncellreq"><?= gettext("Count"); ?></td>
141
	<td width="78%" class="vtable">
142
		<select name="count" class="formfld" id="count">
143
		<?php for ($i = 1; $i <= MAX_COUNT; $i++): ?>
144
			<option value="<?=$i;?>" <?php if ($i == $count) echo "selected"; ?>><?=$i;?></option>
145
		<?php endfor; ?>
146
		</select>
147 13d193c2 Scott Ullrich
	</td>
148
</tr>
149 3c98b3f7 jim-p
<tr>
150
	<td width="22%" valign="top">&nbsp;</td>
151
	<td width="78%">
152
		<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Ping"); ?>">
153
	</td>
154
</tr>
155
<tr>
156
	<td valign="top" colspan="2">
157
	<?php if ($do_ping) {
158
		echo "<font face='terminal' size='2'>";
159
		echo "<strong>" . gettext("Ping output") . ":</strong><br>";
160
		echo('<pre>');
161
		$command = "/sbin/ping";
162
		if ($ipproto == "ipv6") {
163
			$command .= "6";
164
			$ifaddr = get_interface_ipv6($interface);
165
		} else {
166
			$ifaddr = is_ipaddr($interface) ? $interface : get_interface_ip($interface);
167
		}
168
		if ($ifaddr && (is_ipaddr($host) || is_hostname($host)))
169
			$cmd = "{$command} -S$ifaddr -c$count " . escapeshellarg($host);
170
		else
171
			$cmd = "{$command} -c$count " . escapeshellarg($host);
172
		//echo "Ping command: {$cmd}\n";
173
		system($cmd);
174
		echo('</pre>');
175
	}
176
	?>
177
	</td>
178
</tr>
179
<tr>
180
	<td width="22%" valign="top">&nbsp;</td>
181
	<td width="78%">&nbsp;</td>
182
</tr>
183 13d193c2 Scott Ullrich
</table>
184 3c98b3f7 jim-p
</form>
185
</td></tr>
186
</table>
187
<?php include("fend.inc"); ?>