Project

General

Profile

Download (3.72 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/*
4
	diag_ping.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6

    
7
	Copyright (C) 2003-2004 Bob Zoller (bob@kludgebox.com) and Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9

    
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12

    
13
	1. Redistributions of source code must retain the above copyright notice,
14
	this list of conditions and the following disclaimer.
15

    
16
	2. Redistributions in binary form must reproduce the above copyright
17
	notice, this list of conditions and the following disclaimer in the
18
	documentation and/or other materials provided with the distribution.
19

    
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31

    
32
require("guiconfig.inc");
33

    
34
define('MAX_COUNT', 10);
35
define('DEFAULT_COUNT', 3);
36

    
37
if ($_POST) {
38
	unset($input_errors);
39
	unset($do_ping);
40

    
41
	/* input validation */
42
	$reqdfields = explode(" ", "host count");
43
	$reqdfieldsn = explode(",", "Host,Count");
44
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
45

    
46
	if (($_POST['count'] < 1) || ($_POST['count'] > MAX_COUNT)) {
47
		$input_errors[] = "Count must be between 1 and {MAX_COUNT}";
48
	}
49

    
50
	if (!$input_errors) {
51
		$do_ping = true;
52
		$host = preg_replace ("/[^A-Za-z0-9.]/","",$_POST['host']);
53
		$count = $_POST['count'];
54

    
55
	}
56
}
57
if (!isset($do_ping)) {
58
	$do_ping = false;
59
	$host = '';
60
	$count = DEFAULT_COUNT;
61
}
62
?>
63
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
64
<html>
65
<head>
66
<title><?=gentitle("Diagnostics: Ping");?></title>
67
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
68
<link href="gui.css" rel="stylesheet" type="text/css">
69
</head>
70

    
71
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
72
<?php include("fbegin.inc"); ?>
73
<p class="pgtitle">Diagnostics: Ping</font></p>
74
<?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
				  <td width="78%" class="vtable"> 
80
                    <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
				  <td width="78%"> 
94
                    <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>
(11-11/86)