Project

General

Profile

Download (5.26 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php
2
/*
3
	diag_ping.php
4 5543b9ed Scott Ullrich
	part of m0n0wall (http://m0n0.ch/wall)
5 5b237745 Scott Ullrich
6 5543b9ed Scott Ullrich
	Copyright (C) 2003-2005 Bob Zoller (bob@kludgebox.com) and Manuel Kasper <mk@neon1.net>.
7 5b237745 Scott Ullrich
	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 6b07c15a Matthew Grooms
##|+PRIV
32
##|*IDENT=page-diagnostics-ping
33
##|*NAME=Diagnostics: Ping page
34
##|*DESCR=Allow access to the 'Diagnostics: Ping' page.
35
##|*MATCH=diag_ping.php*
36
##|-PRIV
37
38
39 5543b9ed Scott Ullrich
$pgtitle = array("Diagnostics", "Ping");
40 5b237745 Scott Ullrich
require("guiconfig.inc");
41
42
define('MAX_COUNT', 10);
43
define('DEFAULT_COUNT', 3);
44
45
if ($_POST) {
46
	unset($input_errors);
47
	unset($do_ping);
48
49
	/* input validation */
50
	$reqdfields = explode(" ", "host count");
51
	$reqdfieldsn = explode(",", "Host,Count");
52
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
53
54
	if (($_POST['count'] < 1) || ($_POST['count'] > MAX_COUNT)) {
55
		$input_errors[] = "Count must be between 1 and {MAX_COUNT}";
56
	}
57
58
	if (!$input_errors) {
59
		$do_ping = true;
60 5543b9ed Scott Ullrich
		$host = $_POST['host'];
61
		$interface = $_POST['interface'];
62 5b237745 Scott Ullrich
		$count = $_POST['count'];
63
	}
64
}
65
if (!isset($do_ping)) {
66
	$do_ping = false;
67
	$host = '';
68
	$count = DEFAULT_COUNT;
69
}
70 b63695db Scott Ullrich
71 5543b9ed Scott Ullrich
function get_interface_addr($ifdescr) {
72
	
73
	global $config, $g;
74
	
75
	/* find out interface name */
76
	if ($ifdescr == "wan")
77
		$if = get_real_wan_interface();
78
	else
79
		$if = $config['interfaces'][$ifdescr]['if'];
80
	
81
	/* try to determine IP address and netmask with ifconfig */
82 767a716e Scott Ullrich
	$ifconfiginfo = "";
83
	$matches = "";
84 5543b9ed Scott Ullrich
	unset($ifconfiginfo);
85
	exec("/sbin/ifconfig " . $if, $ifconfiginfo);
86
	
87
	foreach ($ifconfiginfo as $ici) {
88
		if (preg_match("/inet (\S+)/", $ici, $matches)) {
89
			return $matches[1];
90
		}
91
	}
92
	
93
	return false;
94
}
95 64203216 Scott Ullrich
96 aad0ec36 Bill Marquette
include("head.inc"); ?>
97
<body link="#000000" vlink="#000000" alink="#000000">
98
<? include("fbegin.inc"); ?>
99
<table width="100%" border="0" cellpadding="0" cellspacing="0">
100
        <tr>
101
                <td>
102 5b237745 Scott Ullrich
<?php if ($input_errors) print_input_errors($input_errors); ?>
103
			<form action="diag_ping.php" method="post" name="iform" id="iform">
104
			  <table width="100%" border="0" cellpadding="6" cellspacing="0">
105
                <tr>
106
				  <td width="22%" valign="top" class="vncellreq">Host</td>
107 5543b9ed Scott Ullrich
				  <td width="78%" class="vtable"> 
108
                    <?=$mandfldhtml;?><input name="host" type="text" class="formfld" id="host" size="20" value="<?=htmlspecialchars($host);?>"></td>
109
				</tr>
110
				<tr>
111
				  <td width="22%" valign="top" class="vncellreq">Interface</td>
112 4d875b4f Scott Ullrich
				  <td width="78%" class="vtable">
113 5543b9ed Scott Ullrich
				  <select name="interface" class="formfld">
114 cbe3ea96 Ermal Luçi
                      <?php $interfaces = get_configured_interface_with_descr();
115 5543b9ed Scott Ullrich
					  foreach ($interfaces as $iface => $ifacename): ?>
116 cbe3ea96 Ermal Luçi
                      <option value="<?=$iface;?>" <?php if (!$config['interfaces'][$iface]['bridge'] && $iface == $interface) echo "selected"; ?>> 
117 5543b9ed Scott Ullrich
                      <?=htmlspecialchars($ifacename);?>
118
                      </option>
119
                      <?php endforeach; ?>
120
                    </select>
121
				  </td>
122 5b237745 Scott Ullrich
				</tr>
123
				<tr>
124
				  <td width="22%" valign="top" class="vncellreq">Count</td>
125
				  <td width="78%" class="vtable">
126 5543b9ed Scott Ullrich
					<select name="count" class="formfld" id="count">
127 5b237745 Scott Ullrich
					<?php for ($i = 1; $i <= MAX_COUNT; $i++): ?>
128
					<option value="<?=$i;?>" <?php if ($i == $count) echo "selected"; ?>><?=$i;?></option>
129
					<?php endfor; ?>
130
					</select></td>
131
				</tr>
132
				<tr>
133
				  <td width="22%" valign="top">&nbsp;</td>
134 5543b9ed Scott Ullrich
				  <td width="78%"> 
135 5b237745 Scott Ullrich
                    <input name="Submit" type="submit" class="formbtn" value="Ping">
136
				</td>
137
				</tr>
138
				<tr>
139
				<td valign="top" colspan="2">
140
				<? if ($do_ping) {
141 586d257b Scott Ullrich
					echo "<font face='terminal' size='2'>";
142 5b237745 Scott Ullrich
					echo("<strong>Ping output:</strong><br>");
143
					echo('<pre>');
144
					ob_end_flush();
145 5543b9ed Scott Ullrich
					$ifaddr = get_interface_addr($interface);
146
					if ($ifaddr)
147
						system("/sbin/ping -S$ifaddr -c$count " . escapeshellarg($host));
148
					else
149
						system("/sbin/ping -c$count " . escapeshellarg($host));
150 5b237745 Scott Ullrich
					echo('</pre>');
151
				}
152
				?>
153
				</td>
154
				</tr>
155 7a01068a Scott Ullrich
				<tr>
156 01c28384 Scott Ullrich
				  <td width="22%" valign="top">&nbsp;</td>
157
				  <td width="78%"> 
158 52456225 Scott Ullrich
					<span class="vexpl"><strong>Note: </strong></span> Multi-wan is not supported from this utility currently.  
159 7a01068a Scott Ullrich
				 </td>
160
				</tr>			
161 5b237745 Scott Ullrich
			</table>
162
</form>
163 aad0ec36 Bill Marquette
</td></tr></table>
164 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>