Project

General

Profile

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