Project

General

Profile

Download (3.58 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php
2
<?php
3 b46bfcf5 Bill Marquette
/* $Id$ */
4 5b237745 Scott Ullrich
/*
5
	diag_ping.php
6 4d875b4f Scott Ullrich
	Copyright (C) 2004 Scott Ullrich
7
	All rights reserved.
8 5b237745 Scott Ullrich
9 4d875b4f Scott Ullrich
	originially part of m0n0wall (http://m0n0.ch/wall)
10 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Bob Zoller (bob@kludgebox.com) and Manuel Kasper <mk@neon1.net>.
11
	All rights reserved.
12
13
	Redistribution and use in source and binary forms, with or without
14
	modification, are permitted provided that the following conditions are met:
15
16
	1. Redistributions of source code must retain the above copyright notice,
17
	this list of conditions and the following disclaimer.
18
19
	2. Redistributions in binary form must reproduce the above copyright
20
	notice, this list of conditions and the following disclaimer in the
21
	documentation and/or other materials provided with the distribution.
22
23
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
	POSSIBILITY OF SUCH DAMAGE.
33
*/
34
35
require("guiconfig.inc");
36
37
define('MAX_COUNT', 10);
38
define('DEFAULT_COUNT', 3);
39
40
if ($_POST) {
41
	unset($input_errors);
42
	unset($do_ping);
43
44
	/* input validation */
45
	$reqdfields = explode(" ", "host count");
46
	$reqdfieldsn = explode(",", "Host,Count");
47
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
48
49
	if (($_POST['count'] < 1) || ($_POST['count'] > MAX_COUNT)) {
50
		$input_errors[] = "Count must be between 1 and {MAX_COUNT}";
51
	}
52
53
	if (!$input_errors) {
54
		$do_ping = true;
55
		$host = preg_replace ("/[^A-Za-z0-9.]/","",$_POST['host']);
56
		$count = $_POST['count'];
57
58
	}
59
}
60
if (!isset($do_ping)) {
61
	$do_ping = false;
62
	$host = '';
63
	$count = DEFAULT_COUNT;
64
}
65 b63695db Scott Ullrich
66
$pgtitle = "Diagnostics: Ping";
67
include("head.inc");
68
69 5b237745 Scott Ullrich
?>
70
71
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
72
<?php include("fbegin.inc"); ?>
73 310b2c06 Bill Marquette
<p class="pgtitle"><?=$pgtitle?></p>
74 5b237745 Scott Ullrich
<?php if ($input_errors) print_input_errors($input_errors); ?>
75
			<form action="diag_ping.php" method="post" name="iform" id="iform">
76
			  <table width="100%" border="0" cellpadding="6" cellspacing="0">
77
                <tr>
78
				  <td width="22%" valign="top" class="vncellreq">Host</td>
79 4d875b4f Scott Ullrich
				  <td width="78%" class="vtable">
80 5b237745 Scott Ullrich
                    <input name="host" type="text" class="formfld" id="host" size="20" value="<?=htmlspecialchars($host);?>"></td>
81
				</tr>
82
				<tr>
83
				  <td width="22%" valign="top" class="vncellreq">Count</td>
84
				  <td width="78%" class="vtable">
85
<select name="count" class="formfld" id="count">
86
					<?php for ($i = 1; $i <= MAX_COUNT; $i++): ?>
87
					<option value="<?=$i;?>" <?php if ($i == $count) echo "selected"; ?>><?=$i;?></option>
88
					<?php endfor; ?>
89
					</select></td>
90
				</tr>
91
				<tr>
92
				  <td width="22%" valign="top">&nbsp;</td>
93 4d875b4f Scott Ullrich
				  <td width="78%">
94 5b237745 Scott Ullrich
                    <input name="Submit" type="submit" class="formbtn" value="Ping">
95
				</td>
96
				</tr>
97
				<tr>
98
				<td valign="top" colspan="2">
99
				<? if ($do_ping) {
100
					echo("<strong>Ping output:</strong><br>");
101
					echo('<pre>');
102
					ob_end_flush();
103
					system("/sbin/ping -c$count " . escapeshellarg($host));
104
					echo('</pre>');
105
				}
106
				?>
107
				</td>
108
				</tr>
109
			</table>
110
</form>
111
<?php include("fend.inc"); ?>
112
</body>
113
</html>