From 8985e5f4d73a5ffc108bb66dde00a8143e952c58 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Sat, 22 Sep 2018 22:12:55 +0200 Subject: [PATCH] interfaces: port probe no longer uses get_possible_listen_ips() --- src/www/diag_testport.php | 194 +++++++++++++++++--------------------- 1 file changed, 84 insertions(+), 110 deletions(-) diff --git a/src/www/diag_testport.php b/src/www/diag_testport.php index 9561275b3..b35f6d746 100644 --- a/src/www/diag_testport.php +++ b/src/www/diag_testport.php @@ -1,33 +1,34 @@ - Copyright (C) 2003-2005 Bob Zoller - Copyright (C) 2003-2005 Manuel Kasper - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. -*/ + * Copyright (C) 2018 Franco Fichtner + * Copyright (C) 2016 Deciso B.V. + * Copyright (C) 2013 Jim Pingle + * Copyright (C) 2003-2005 Bob Zoller + * Copyright (C) 2003-2005 Manuel Kasper + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ require_once("guiconfig.inc"); require_once("system.inc"); @@ -41,7 +42,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $pconfig['host'] = null; $pconfig['port'] = null; $pconfig['showtext'] = null; - $pconfig['sourceip'] = null; + $pconfig['interface'] = null; } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { $pconfig = $_POST; $input_errors = array(); @@ -63,43 +64,39 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $input_errors[] = gettext("Please enter a valid source port number, or leave the field blank."); } - if (is_ipaddrv4($pconfig['host']) && ($pconfig['ipprotocol'] == "ipv6")) { - $input_errors[] = gettext("You cannot connect to an IPv4 address using IPv6."); - } - if (is_ipaddrv6($pconfig['host']) && ($pconfig['ipprotocol'] == "ipv4")) { - $input_errors[] = gettext("You cannot connect to an IPv6 address using IPv4."); - } - if (count($input_errors) == 0) { $nc_args = "-w 10" ; if (empty($pconfig['showtext'])) { $nc_args .= " -z "; } if (!empty($pconfig['srcport'])) { - $nc_args .= " -p " . escapeshellarg($pconfig['srcport']) . " "; + $nc_args .= exec_safe(' -p %s ', $pconfig['srcport']); } switch ($pconfig['ipprotocol']) { - case "ipv4": - $ifaddr = ($pconfig['sourceip'] == "any") ? "" : get_interface_ip($pconfig['sourceip']); - $nc_args .= " -4"; - break; - case "ipv6": - $ifaddr = (is_linklocal($pconfig['sourceip']) ? $pconfig['sourceip'] : get_interface_ipv6($pconfig['sourceip'])); + case 'ipv6': + $ifaddr = find_interface_ipv6(get_real_interface($pconfig['interface'], 'inet6')); $nc_args .= " -6"; break; - } - if (!empty($ifaddr)) { - $nc_args .= " -s " . escapeshellarg($ifaddr) . " "; - $scope = get_ll_scope($ifaddr); - if (!empty($scope) && !strstr($host, "%")) { - $host .= "%{$scope}"; - } + case 'ipv6-ll': + $realif = get_real_interface($pconfig['interface'], 'inet6'); + $ifaddr = find_interface_ipv6_ll($realif) . "%{$realif}"; + $nc_args .= " -6"; + break; + default: + $ifaddr = find_interface_ip(get_real_interface($pconfig['interface'])); + $nc_args .= " -4"; + break; } - $cmd_action = "/usr/bin/nc {$nc_args} " . escapeshellarg($pconfig['host']) . " " . escapeshellarg($pconfig['port']) . " 2>&1"; + if (!empty($ifaddr)) { + $nc_args .= exec_safe(' -s %s ', $ifaddr); + } + + $cmd_action = exec_safe("/usr/bin/nc {$nc_args} %s %s", array($pconfig['host'], $pconfig['port'])); $process = proc_open($cmd_action, array(array("pipe", "r"), array("pipe", "w"), array("pipe", "w")), $pipes); if (is_resource($process)) { - $cmd_output = stream_get_contents($pipes[1]); + $cmd_output = "# $cmd_action\n"; + $cmd_output .= stream_get_contents($pipes[1]); $cmd_output .= stream_get_contents($pipes[2]); } } @@ -120,38 +117,18 @@ include("head.inc"); ?>
-
0) print_input_errors($input_errors); ?>
- - + - - - - - - + + + + + + + + - - - - -
 
- - -
@@ -164,6 +141,32 @@ include("head.inc"); ?>
+ + +
+ +
@@ -182,55 +185,26 @@ include("head.inc"); ?>
- -
  " />
-
- +
-
-
-

-
-
- -
- -
- -
- - -
-
+ +
+ +
+ +
+
- +