Project

General

Profile

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