Project

General

Profile

Download (3.79 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/* $Id$ */
4
/*
5
	diag_ping.php
6
	Copyright (C) 2004 Scott Ullrich
7
	All rights reserved.
8

    
9
	originially part of m0n0wall (http://m0n0.ch/wall)
10
	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
?>
66
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
67
<html>
68
<head>
69
<title><?=gentitle("Diagnostics: Ping");?></title>
70
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
71
<link href="gui.css" rel="stylesheet" type="text/css">
72
</head>
73

    
74
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
75
<?php include("fbegin.inc"); ?>
76
<p class="pgtitle">Diagnostics: Ping</font></p>
77
<?php if ($input_errors) print_input_errors($input_errors); ?>
78
			<form action="diag_ping.php" method="post" name="iform" id="iform">
79
			  <table width="100%" border="0" cellpadding="6" cellspacing="0">
80
                <tr>
81
				  <td width="22%" valign="top" class="vncellreq">Host</td>
82
				  <td width="78%" class="vtable">
83
                    <input name="host" type="text" class="formfld" id="host" size="20" value="<?=htmlspecialchars($host);?>"></td>
84
				</tr>
85
				<tr>
86
				  <td width="22%" valign="top" class="vncellreq">Count</td>
87
				  <td width="78%" class="vtable">
88
<select name="count" class="formfld" id="count">
89
					<?php for ($i = 1; $i <= MAX_COUNT; $i++): ?>
90
					<option value="<?=$i;?>" <?php if ($i == $count) echo "selected"; ?>><?=$i;?></option>
91
					<?php endfor; ?>
92
					</select></td>
93
				</tr>
94
				<tr>
95
				  <td width="22%" valign="top">&nbsp;</td>
96
				  <td width="78%">
97
                    <input name="Submit" type="submit" class="formbtn" value="Ping">
98
				</td>
99
				</tr>
100
				<tr>
101
				<td valign="top" colspan="2">
102
				<? if ($do_ping) {
103
					echo("<strong>Ping output:</strong><br>");
104
					echo('<pre>');
105
					ob_end_flush();
106
					system("/sbin/ping -c$count " . escapeshellarg($host));
107
					echo('</pre>');
108
				}
109
				?>
110
				</td>
111
				</tr>
112
			</table>
113
</form>
114
<?php include("fend.inc"); ?>
115
</body>
116
</html>
(16-16/117)