Revision 6aa305d2
Added by Jim Pingle over 12 years ago
usr/local/www/diag_testport.php | ||
---|---|---|
82 | 82 |
if (!$input_errors) { |
83 | 83 |
$do_testport = true; |
84 | 84 |
$host = $_REQUEST['host']; |
85 |
$interface = $_REQUEST['interface'];
|
|
85 |
$sourceip = $_REQUEST['sourceip'];
|
|
86 | 86 |
$port = $_REQUEST['port']; |
87 | 87 |
$srcport = $_REQUEST['srcport']; |
88 | 88 |
$showtext = isset($_REQUEST['showtext']); |
... | ... | |
140 | 140 |
</td> |
141 | 141 |
</tr> |
142 | 142 |
<tr> |
143 |
<td width="22%" valign="top" class="vncell"><?=gettext("Interface"); ?></td>
|
|
143 |
<td width="22%" valign="top" class="vncell"><?=gettext("Source Address"); ?></td>
|
|
144 | 144 |
<td width="78%" class="vtable"> |
145 |
<select name="interface" class="formfld"> |
|
146 |
<option value="any" <?php if ("any" == $interface) echo "selected"; ?>> |
|
147 |
Any |
|
148 |
</option> |
|
149 |
<?php $interfaces = get_configured_interface_with_descr(); |
|
150 |
foreach ($interfaces as $iface => $ifacename): ?> |
|
151 |
<option value="<?=$iface;?>" <?php if (!link_interface_to_bridge($iface) && $iface == $interface) echo "selected"; ?>> |
|
152 |
<?=htmlspecialchars($ifacename);?> |
|
153 |
</option> |
|
154 |
<?php endforeach; ?> |
|
155 |
</select> |
|
145 |
<select name="sourceip" class="formselect"> |
|
146 |
<option value="">Any</option> |
|
147 |
<?php $sourceips = get_possible_traffic_source_addresses(); |
|
148 |
foreach ($sourceips as $sip): |
|
149 |
$selected = ""; |
|
150 |
if (!link_interface_to_bridge($sip['value']) && ($sip['value'] == $sourceip)) |
|
151 |
$selected = 'selected="selected"'; |
|
152 |
?> |
|
153 |
<option value="<?=$sip['value'];?>" <?=$selected;?>> |
|
154 |
<?=htmlspecialchars($sip['name']);?> |
|
155 |
</option> |
|
156 |
<?php endforeach; ?> |
|
157 |
</select> |
|
156 | 158 |
</td> |
157 | 159 |
</tr> |
158 | 160 |
<tr> |
... | ... | |
195 | 197 |
|
196 | 198 |
/* Attempt to determine the interface address, if possible. Else try both. */ |
197 | 199 |
if (is_ipaddrv4($host)) { |
198 |
$ifaddr = ($interface == "any") ? "" : get_interface_ip($interface);
|
|
200 |
$ifaddr = ($sourceip == "any") ? "" : get_interface_ip($sourceip);
|
|
199 | 201 |
$nc_args .= " -4"; |
200 | 202 |
} elseif (is_ipaddrv6($host)) { |
201 |
$ifaddr = ($interface == "any") ? "" : get_interface_ipv6($interface);
|
|
203 |
$ifaddr = ($sourceip == "any") ? "" : get_interface_ipv6($sourceip);
|
|
202 | 204 |
$nc_args .= " -6"; |
203 | 205 |
} else { |
204 | 206 |
switch ($ipprotocol) { |
205 | 207 |
case "ipv4": |
206 |
$ifaddr = get_interface_ip($interface);
|
|
208 |
$ifaddr = get_interface_ip($sourceip);
|
|
207 | 209 |
$nc_ipproto = " -4"; |
208 | 210 |
break; |
209 | 211 |
case "ipv6": |
210 |
$ifaddr = get_interface_ipv6($interface);
|
|
212 |
$ifaddr = get_interface_ipv6($sourceip);
|
|
211 | 213 |
$nc_ipproto = " -6"; |
212 | 214 |
break; |
213 | 215 |
case "any": |
214 |
$ifaddr = get_interface_ip($interface);
|
|
216 |
$ifaddr = get_interface_ip($sourceip);
|
|
215 | 217 |
$nc_ipproto = (!empty($ifaddr)) ? " -4" : ""; |
216 | 218 |
if (empty($ifaddr)) { |
217 |
$ifaddr = get_interface_ipv6($interface);
|
|
219 |
$ifaddr = get_interface_ipv6($sourceip);
|
|
218 | 220 |
$nc_ipproto = (!empty($ifaddr)) ? " -6" : ""; |
219 | 221 |
} |
220 | 222 |
break; |
... | ... | |
222 | 224 |
/* Netcat doesn't like it if we try to connect using a certain type of IP without specifying the family. */ |
223 | 225 |
if (!empty($ifaddr)) { |
224 | 226 |
$nc_args .= $nc_ipproto; |
225 |
} elseif ($interface == "any") {
|
|
227 |
} elseif ($sourceip == "any") {
|
|
226 | 228 |
switch ($ipprotocol) { |
227 | 229 |
case "ipv4": |
228 | 230 |
$nc_ipproto = " -4"; |
... | ... | |
236 | 238 |
} |
237 | 239 |
/* Only add on the interface IP if we managed to find one. */ |
238 | 240 |
if (!empty($ifaddr)) |
239 |
$nc_args .= " -s {$ifaddr} ";
|
|
241 |
$nc_args .= " -s " . escapeshellarg($ifaddr) . " ";
|
|
240 | 242 |
|
241 | 243 |
$nc_cmd = "{$nc_base_cmd} {$nc_args} " . escapeshellarg($host) . " " . escapeshellarg($port) . " 2>&1"; |
242 | 244 |
exec($nc_cmd, $result, $retval); |
Also available in: Unified diff
Fixup source address options on Test Port page.