Project

General

Profile

Download (6.42 KB) Statistics
| Branch: | Tag: | Revision:
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
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
10
	All rights reserved.
11

    
12
	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
/*
35
	pfSense_BUILDER_BINARIES:	/sbin/ping /sbin/ping6
36
	pfSense_MODULE:	routing
37
*/
38

    
39
##|+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
$allowautocomplete = true;
47
$pgtitle = array(gettext("Diagnostics"), gettext("Ping"));
48
require_once("guiconfig.inc");
49

    
50

    
51
define('MAX_COUNT', 10);
52
define('DEFAULT_COUNT', 3);
53

    
54
if ($_POST || $_REQUEST['host']) {
55
	unset($input_errors);
56
	unset($do_ping);
57

    
58
	/* input validation */
59
	$reqdfields = explode(" ", "host count");
60
	$reqdfieldsn = array(gettext("Host"),gettext("Count"));
61
	do_input_validation($_REQUEST, $reqdfields, $reqdfieldsn, $input_errors);
62

    
63
	if (($_REQUEST['count'] < 1) || ($_REQUEST['count'] > MAX_COUNT)) {
64
		$input_errors[] = sprintf(gettext("Count must be between 1 and %s"), MAX_COUNT);
65
	}
66

    
67
	$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
	if (!$input_errors) {
75
		$do_ping = true;
76
		$sourceip = $_REQUEST['sourceip'];
77
		$count = $_POST['count'];
78
		if (preg_match('/[^0-9]/', $count) )
79
			$count = DEFAULT_COUNT;
80
	}
81
}
82
if (!isset($do_ping)) {
83
	$do_ping = false;
84
	$host = '';
85
	$count = DEFAULT_COUNT;
86
}
87

    
88
include("head.inc"); ?>
89
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
90
<?php include("fbegin.inc"); ?>
91
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="ping">
92
<tr><td>
93
<?php if ($input_errors) print_input_errors($input_errors); ?>
94
<form action="diag_ping.php" method="post" name="iform" id="iform">
95
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="tabcont">
96
<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
		<?=$mandfldhtml;?><input name="host" type="text" class="formfld unknown" id="host" size="20" value="<?=htmlspecialchars($host);?>" /></td>
103
</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
			<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
		</select>
111
	</td>
112
</tr>
113
<tr>
114
	<td width="22%" valign="top" class="vncell"><?=gettext("Source Address"); ?></td>
115
	<td width="78%" class="vtable">
116
		<select name="sourceip" class="formselect">
117
			<option value="">Default</option>
118
		<?php $sourceips = get_possible_traffic_source_addresses(true);
119
			foreach ($sourceips as $sip):
120
				$selected = "";
121
				if (!link_interface_to_bridge($sip['value']) && ($sip['value'] == $sourceip))
122
					$selected = "selected=\"selected\"";
123
		?>
124
			<option value="<?=$sip['value'];?>" <?=$selected;?>>
125
				<?=htmlspecialchars($sip['name']);?>
126
			</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
			<option value="<?=$i;?>" <?php if ($i == $count) echo "selected=\"selected\""; ?>><?=$i;?></option>
137
		<?php endfor; ?>
138
		</select>
139
	</td>
140
</tr>
141
<tr>
142
	<td width="22%" valign="top">&nbsp;</td>
143
	<td width="78%">
144
		<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Ping"); ?>" />
145
	</td>
146
</tr>
147
<tr>
148
	<td valign="top" colspan="2">
149
	<?php if ($do_ping) {
150
		echo "<font face=\"terminal\" size=\"2\">";
151
		echo "<strong>" . gettext("Ping output") . ":</strong><br />";
152
?>
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
		$ifscope = '';
163
		$command = "/sbin/ping";
164
		if ($ipproto == "ipv6") {
165
			$command .= "6";
166
			$ifaddr = is_ipaddr($sourceip) ? $sourceip : get_interface_ipv6($sourceip);
167
			if (is_linklocal($ifaddr))
168
				$ifscope = get_ll_scope($ifaddr);
169
		} else {
170
			$ifaddr = is_ipaddr($sourceip) ? $sourceip : get_interface_ip($sourceip);
171
		}
172
		if ($ifaddr && (is_ipaddr($host) || is_hostname($host))) {
173
			$srcip = "-S" . escapeshellarg($ifaddr);
174
			if (is_linklocal($host) && !strstr($host, "%") && !empty($ifscope))
175
				$host .= "%{$ifscope}";
176
		}
177

    
178
		$cmd = "{$command} {$srcip} -c" . escapeshellarg($count) . " " . escapeshellarg($host);
179
		//echo "Ping command: {$cmd}\n";
180
		system($cmd);
181
		echo('</textarea>&nbsp;</font>');
182
	}
183
	?>
184
	</td>
185
</tr>
186
<tr>
187
	<td width="22%" valign="top">&nbsp;</td>
188
	<td width="78%">&nbsp;</td>
189
</tr>
190
</table>
191
</form>
192
</td></tr>
193
</table>
194
<?php include("fend.inc"); ?>
195
</body>
196
</html>
(42-42/256)