From c6119c771d8fdc4f4794e03afd9a4f84b5cdbebe Mon Sep 17 00:00:00 2001 From: Guillaume Mazoyer Date: Thu, 23 Jul 2015 17:59:59 +0200 Subject: Rework hostname parameter check. Rename FQDN to hostname which seems more appropriate. Refactor match_fqdn / match_hostname function to use a more accurate way of checking a potential hostname. --- routers/cisco.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'routers/cisco.php') diff --git a/routers/cisco.php b/routers/cisco.php index 0763bd7..e36a6bf 100644 --- a/routers/cisco.php +++ b/routers/cisco.php @@ -27,10 +27,10 @@ final class Cisco extends Router { $ping = null; if (match_ipv4($destination) || match_ipv6($destination) || - match_fqdn($destination)) { + match_hostname($destination)) { $ping = 'ping '.$destination.' repeat 10'; } else { - throw new Exception('The parameter is not an IPv4/IPv6 address or a FQDN.'); + throw new Exception('The parameter is not an IPv4/IPv6 address or a hostname.'); } if (($ping != null) && $this->has_source_interface_id()) { @@ -44,25 +44,25 @@ final class Cisco extends Router { $traceroute = null; if (match_ipv4($destination) || match_ipv6($destination) || - (match_fqdn($destination) && !$this->has_source_interface_id())) { + (match_hostname($destination) && !$this->has_source_interface_id())) { $traceroute = 'traceroute '.$destination; - } else if (match_fqdn($destination)) { - $fqdn = $destination; - $destination = fqdn_to_ip_address($fqdn); + } else if (match_hostname($destination)) { + $hostname = $destination; + $destination = hostname_to_ip_address($hostname); if (!$destination) { - throw new Exception('No A or AAAA record found for '.$fqdn); + throw new Exception('No A or AAAA record found for '.$hostname); } if (match_ipv4($destination)) { - $traceroute = 'traceroute ip '.(isset($fqdn) ? $fqdn : $destination); + $traceroute = 'traceroute ip '.(isset($hostname) ? $hostname : $destination); } else if (match_ipv6($destination)) { - $traceroute = 'traceroute ipv6 '.(isset($fqdn) ? $fqdn : $destination); + $traceroute = 'traceroute ipv6 '.(isset($hostname) ? $hostname : $destination); } else { throw new Exception('The parameter does not resolve to an IPv4/IPv6 address.'); } } else { - throw new Exception('The parameter is not an IPv4/IPv6 address or a FQDN.'); + throw new Exception('The parameter is not an IPv4/IPv6 address or a hostname.'); } if (($traceroute != null) && $this->has_source_interface_id() && -- cgit v1.2.3