Project

General

Profile

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