Project

General

Profile

« Previous | Next » 

Revision 45d6ada5

Added by Sjon Hortensius over 10 years ago

Revert "Merge pull request #100 from sbeaver-netgate/halt"

This reverts commit 5bd406696ae634b3993d79a8b9aef03eeab42488, reversing
changes made to b9bd62735f2afb818d9ff3afd399c6c7d3b904c5.

View differences:

usr/local/www/diag_ping.php
33 33

  
34 34
/*
35 35
	pfSense_BUILDER_BINARIES:	/sbin/ping /sbin/ping6
36
	pfSense_MODULE:	routing
36
	pfSense_MODULE: routing
37 37
*/
38 38

  
39 39
##|+PRIV
......
47 47
$pgtitle = array(gettext("Diagnostics"), gettext("Ping"));
48 48
require_once("guiconfig.inc");
49 49

  
50

  
51 50
define('MAX_COUNT', 10);
52 51
define('DEFAULT_COUNT', 3);
53 52

  
53
function create_sourceaddresslist() {
54
	$list = array('any' => 'Any');
55

  
56
	foreach (get_possible_traffic_source_addresses(true) as $sipname)
57
		$list[$sipname['value']] = $sipname['name'];
58

  
59
	return $list;
60
}
61

  
54 62
if ($_POST || $_REQUEST['host']) {
55 63
	unset($input_errors);
56 64
	unset($do_ping);
......
79 87
			$count = DEFAULT_COUNT;
80 88
	}
81 89
}
90

  
82 91
if (!isset($do_ping)) {
83 92
	$do_ping = false;
84 93
	$host = '';
85 94
	$count = DEFAULT_COUNT;
86 95
}
87 96

  
88
include("head.inc"); ?>
89
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
90
<?php include("fbegin.inc"); ?>
91
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="ping">
92
<tr><td>
93
<?php if ($input_errors) print_input_errors($input_errors); ?>
94
<form action="diag_ping.php" method="post" name="iform" id="iform">
95
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="tabcont">
96
<tr>
97
	<td colspan="2" valign="top" class="listtopic"><?=gettext("Ping"); ?></td>
98
</tr>
99
<tr>
100
	<td width="22%" valign="top" class="vncellreq"><?=gettext("Host"); ?></td>
101
	<td width="78%" class="vtable">
102
		<?=$mandfldhtml;?><input name="host" type="text" class="formfld unknown" id="host" size="20" value="<?=htmlspecialchars($host);?>" /></td>
103
</tr>
104
<tr>
105
	<td width="22%" valign="top" class="vncellreq"><?=gettext("IP Protocol"); ?></td>
106
	<td width="78%" class="vtable">
107
		<select name="ipproto" class="formselect">
108
			<option value="ipv4" <?php if ($ipproto == "ipv4") echo "selected=\"selected\"" ?>>IPv4</option>
109
			<option value="ipv6" <?php if ($ipproto == "ipv6") echo "selected=\"selected\"" ?>>IPv6</option>
110
		</select>
111
	</td>
112
</tr>
113
<tr>
114
	<td width="22%" valign="top" class="vncell"><?=gettext("Source Address"); ?></td>
115
	<td width="78%" class="vtable">
116
		<select name="sourceip" class="formselect">
117
			<option value="">Default</option>
118
		<?php $sourceips = get_possible_traffic_source_addresses(true);
119
			foreach ($sourceips as $sipvalue => $sipname):
120
				$selected = "";
121
				if (!link_interface_to_bridge($sipvalue) && ($sipvalue == $sourceip))
122
					$selected = "selected=\"selected\"";
123
		?>
124
			<option value="<?=$sipvalue;?>" <?=$selected;?>>
125
				<?=htmlspecialchars($sipname);?>
126
			</option>
127
			<?php endforeach; ?>
128
		</select>
129
	</td>
130
</tr>
131
<tr>
132
	<td width="22%" valign="top" class="vncellreq"><?= gettext("Count"); ?></td>
133
	<td width="78%" class="vtable">
134
		<select name="count" class="formfld" id="count">
135
		<?php for ($i = 1; $i <= MAX_COUNT; $i++): ?>
136
			<option value="<?=$i;?>" <?php if ($i == $count) echo "selected=\"selected\""; ?>><?=$i;?></option>
137
		<?php endfor; ?>
138
		</select>
139
	</td>
140
</tr>
141
<tr>
142
	<td width="22%" valign="top">&nbsp;</td>
143
	<td width="78%">
144
		<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Ping"); ?>" />
145
	</td>
146
</tr>
147
<tr>
148
	<td valign="top" colspan="2">
149
	<?php if ($do_ping) {
150
		echo "<font face=\"terminal\" size=\"2\">";
151
		echo "<strong>" . gettext("Ping output") . ":</strong><br />";
97
if($do_ping) {
152 98
?>
153
		<script type="text/javascript">
154
		//<![CDATA[
155
		window.onload=function(){
156
			document.getElementById("pingCaptured").wrap='off';
157
		}
158
		//]]>
159
		</script>
99
	<script type="text/javascript">
100
	//<![CDATA[
101
	window.onload=function(){
102
		document.getElementById("pingCaptured").wrap='off';
103
	}
104
	//]]>
105
	</script>
160 106
<?php
161
		echo "<textarea id=\"pingCaptured\" style=\"width:98%\" name=\"code\" rows=\"15\" cols=\"66\" readonly=\"readonly\">";
162
		$ifscope = '';
163
		$command = "/sbin/ping";
164
		if ($ipproto == "ipv6") {
165
			$command .= "6";
166
			$ifaddr = is_ipaddr($sourceip) ? $sourceip : get_interface_ipv6($sourceip);
167
			if (is_linklocal($ifaddr))
168
				$ifscope = get_ll_scope($ifaddr);
169
		} else {
170
			$ifaddr = is_ipaddr($sourceip) ? $sourceip : get_interface_ip($sourceip);
171
		}
172
		if ($ifaddr && (is_ipaddr($host) || is_hostname($host))) {
173
			$srcip = "-S" . escapeshellarg($ifaddr);
174
			if (is_linklocal($host) && !strstr($host, "%") && !empty($ifscope))
175
				$host .= "%{$ifscope}";
176
		}
177

  
178
		$cmd = "{$command} {$srcip} -c" . escapeshellarg($count) . " " . escapeshellarg($host);
179
		//echo "Ping command: {$cmd}\n";
180
		system($cmd);
181
		echo('</textarea>&nbsp;</font>');
107
	$ifscope = '';
108
	$command = "/sbin/ping";
109
	if ($ipproto == "ipv6") {
110
		$command .= "6";
111
		$ifaddr = is_ipaddr($sourceip) ? $sourceip : get_interface_ipv6($sourceip);
112
		if (is_linklocal($ifaddr))
113
			$ifscope = get_ll_scope($ifaddr);
114
	} else {
115
		$ifaddr = is_ipaddr($sourceip) ? $sourceip : get_interface_ip($sourceip);
116
	}
117

  
118
	if ($ifaddr && (is_ipaddr($host) || is_hostname($host))) {
119
		$srcip = "-S" . escapeshellarg($ifaddr);
120
		if (is_linklocal($host) && !strstr($host, "%") && !empty($ifscope))
121
			$host .= "%{$ifscope}";
182 122
	}
183
	?>
184
	</td>
185
</tr>
186
<tr>
187
	<td width="22%" valign="top">&nbsp;</td>
188
	<td width="78%">&nbsp;</td>
189
</tr>
190
</table>
191
</form>
192
</td></tr>
193
</table>
194
<?php include("fend.inc"); ?>
195
</body>
196
</html>
123

  
124
	$cmd = "{$command} {$srcip} -c" . escapeshellarg($count) . " " . escapeshellarg($host);
125
	//echo "Ping command: {$cmd}\n";
126
	$result = shell_exec($cmd);
127

  
128
	if(empty($result))
129
		$input_errors[] = "Host \"" . $host . "\" did not respond or could not be resolved.";
130

  
131
}
132

  
133
include('head.inc');
134

  
135
if ($input_errors)
136
	print_input_errors($input_errors);
137

  
138
require('classes/Form.class.php');
139

  
140
$form = new Form(new Form_Button(
141
	'submit',
142
	'Ping'
143
));
144

  
145
$section = new Form_Section('Ping');
146

  
147
$section->addInput(new Form_Input(
148
	'host',
149
	'Hostname',
150
	'text',
151
	$host,
152
	['placeholder' => 'Hostname to ping']
153
));
154

  
155
$group = new Form_Group('IP Protocol');
156
$group->add(new Form_Checkbox(
157
	'ipproto',
158
	null,
159
	'IPv4',
160
	('ipv6' != $ipproto), # negative check, so this would be checked by default
161
	'ipv4'
162
))->displayAsRadio();
163
$group->add(new Form_Checkbox(
164
	'ipproto',
165
	null,
166
	'IPv6',
167
	('ipv6' == $ipproto),
168
	'ipv6'
169
))->displayAsRadio();
170
$group->setHelp('Select the protocol to use');
171
$section->add($group);
172

  
173
$section->addInput(new Form_Select(
174
	'sourceip',
175
	'Source address',
176
	$pconfig['source'],
177
	create_sourceaddresslist()
178
))->setHelp('Select source address for the ping');
179

  
180
$section->addInput(new Form_Select(
181
	'count',
182
	'Maximum number of pings',
183
	$count,
184
	array_combine(range(1, MAX_COUNT), range(1, MAX_COUNT))
185
))->setHelp('Select the maximum number pings');
186

  
187
$form->add($section);
188
print $form;
189

  
190
if($do_ping && !empty($result) && !$input_errors) {
191
?>
192
	<div class="panel panel-default">
193
		<div class="panel-heading">
194
			<h2 class="panel-title">Results</h2>
195
		</div>
196

  
197
		<div class="panel-body">
198
			<pre><?= $result ?></pre>
199
		</div>
200
	</div>
201
<?php
202
}
203

  
204
include('foot.inc');

Also available in: Unified diff