Project

General

Profile

Download (5.1 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	diag_ping.php
4
	part of m0n0wall (http://m0n0.ch/wall)
5

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

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

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

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

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

    
31
$pgtitle = array("Diagnostics", "Ping");
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 = $_POST['host'];
53
		$interface = $_POST['interface'];
54
		$count = $_POST['count'];
55
	}
56
}
57
if (!isset($do_ping)) {
58
	$do_ping = false;
59
	$host = '';
60
	$count = DEFAULT_COUNT;
61
}
62

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

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