Project

General

Profile

Download (4.91 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-2005 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
$pgtitle = array("Diagnostics", "Ping");
33
require("guiconfig.inc");
34

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

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

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

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

    
51
	if (!$input_errors) {
52
		$do_ping = true;
53
		$host = $_POST['host'];
54
		$interface = $_POST['interface'];
55
		$count = $_POST['count'];
56
	}
57
}
58
if (!isset($do_ping)) {
59
	$do_ping = false;
60
	$host = '';
61
	$count = DEFAULT_COUNT;
62
}
63

    
64
function get_interface_addr($ifdescr) {
65
	
66
	global $config, $g;
67
	
68
	/* find out interface name */
69
	if ($ifdescr == "wan")
70
		$if = get_real_wan_interface();
71
	else
72
		$if = $config['interfaces'][$ifdescr]['if'];
73
	
74
	/* try to determine IP address and netmask with ifconfig */
75
	unset($ifconfiginfo);
76
	exec("/sbin/ifconfig " . $if, $ifconfiginfo);
77
	
78
	foreach ($ifconfiginfo as $ici) {
79
		if (preg_match("/inet (\S+)/", $ici, $matches)) {
80
			return $matches[1];
81
		}
82
	}
83
	
84
	return false;
85
}
86

    
87
$pgtitle = "Diagnostics: Ping";
88
include("head.inc");
89
include("fbegin.inc"); 
90
?>
91
<?php if ($input_errors) print_input_errors($input_errors); ?>
92
			<form action="diag_ping.php" method="post" name="iform" id="iform">
93
			  <table width="100%" border="0" cellpadding="6" cellspacing="0">
94
                <tr>
95
				  <td width="22%" valign="top" class="vncellreq">Host</td>
96
				  <td width="78%" class="vtable"> 
97
                    <?=$mandfldhtml;?><input name="host" type="text" class="formfld" id="host" size="20" value="<?=htmlspecialchars($host);?>"></td>
98
				</tr>
99
				<tr>
100
				  <td width="22%" valign="top" class="vncellreq">Interface</td>
101
				  <td width="78%" class="vtable">
102
				  <select name="interface" class="formfld">
103
                      <?php $interfaces = array('wan' => 'WAN', 'lan' => 'LAN');
104
					  for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
105
					    if (isset($config['interfaces']['opt' . $i]['enable']) &&
106
							!$config['interfaces']['opt' . $i]['bridge'])
107
					  		$interfaces['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
108
					  }
109
					  foreach ($interfaces as $iface => $ifacename): ?>
110
                      <option value="<?=$iface;?>" <?php if ($iface == $interface) echo "selected"; ?>> 
111
                      <?=htmlspecialchars($ifacename);?>
112
                      </option>
113
                      <?php endforeach; ?>
114
                    </select>
115
				  </td>
116
				</tr>
117
				<tr>
118
				  <td width="22%" valign="top" class="vncellreq">Count</td>
119
				  <td width="78%" class="vtable">
120
					<select name="count" class="formfld" id="count">
121
					<?php for ($i = 1; $i <= MAX_COUNT; $i++): ?>
122
					<option value="<?=$i;?>" <?php if ($i == $count) echo "selected"; ?>><?=$i;?></option>
123
					<?php endfor; ?>
124
					</select></td>
125
				</tr>
126
				<tr>
127
				  <td width="22%" valign="top">&nbsp;</td>
128
				  <td width="78%"> 
129
                    <input name="Submit" type="submit" class="formbtn" value="Ping">
130
				</td>
131
				</tr>
132
				<tr>
133
				<td valign="top" colspan="2">
134
				<? if ($do_ping) {
135
					echo("<strong>Ping output:</strong><br>");
136
					echo('<pre>');
137
					ob_end_flush();
138
					$ifaddr = get_interface_addr($interface);
139
					if ($ifaddr)
140
						system("/sbin/ping -S$ifaddr -c$count " . escapeshellarg($host));
141
					else
142
						system("/sbin/ping -c$count " . escapeshellarg($host));
143
					echo('</pre>');
144
				}
145
				?>
146
				</td>
147
				</tr>
148
			</table>
149
</form>
150
<?php include("fend.inc"); ?>
(20-20/146)