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. --- includes/config.defaults.php | 10 ++++----- includes/utils.php | 50 +++++++++++++++++++++++--------------------- 2 files changed, 31 insertions(+), 29 deletions(-) (limited to 'includes') diff --git a/includes/config.defaults.php b/includes/config.defaults.php index bd1687f..0fbca1a 100644 --- a/includes/config.defaults.php +++ b/includes/config.defaults.php @@ -132,15 +132,15 @@ $config = array( ), // Documentation for the 'ping' query 'ping' => array( - 'command' => 'ping IP_ADDRESS|FQDN', - 'description' => 'Send 10 pings to the given destination.', - 'parameter' => 'The parameter must be an IPv4/IPv6 address (without mask) or a fully qualified domain name.
RFC1918 addresses, IPv6 starting with FD or FC, and IPv4 reserved ranges (0.0.0.0/8, 169.254.0.0/16, 192.0.2.0/24 and 224.0.0.0/4) may be refused.

Example of valid arguments:
' + 'command' => 'ping IP_ADDRESS|HOSTNAME', + 'description' => 'Send pings to the given destination.', + 'parameter' => 'The parameter must be an IPv4/IPv6 address (without mask) or a hostname.
RFC1918 addresses, IPv6 starting with FD or FC, and IPv4 reserved ranges (0.0.0.0/8, 169.254.0.0/16, 192.0.2.0/24 and 224.0.0.0/4) may be refused.

Example of valid arguments:
' ), // Documentation for the 'traceroute' query 'traceroute' => array( - 'command' =>'traceroute IP_ADDRESS|FQDN', + 'command' =>'traceroute IP_ADDRESS|HOSTNAME', 'description' => 'Display the path to a given destination.', - 'parameter' => 'The parameter must be an IPv4/IPv6 address (without mask) or a fully qualified domain name.
RFC1918 addresses, IPv6 starting with FD or FC, and IPv4 reserved ranges (0.0.0.0/8, 169.254.0.0/16, 192.0.2.0/24 and 224.0.0.0/4) may be refused.

Example of valid arguments:
' + 'parameter' => 'The parameter must be an IPv4/IPv6 address (without mask) or a hostname.
RFC1918 addresses, IPv6 starting with FD or FC, and IPv4 reserved ranges (0.0.0.0/8, 169.254.0.0/16, 192.0.2.0/24 and 224.0.0.0/4) may be refused.

Example of valid arguments:
' ) ), diff --git a/includes/utils.php b/includes/utils.php index 828832f..79888dd 100644 --- a/includes/utils.php +++ b/includes/utils.php @@ -142,24 +142,25 @@ function match_ipv6($ip, $ip_only = true) { } /** - * Test if a given parameter is a valid FQDN or not. + * Test if a given parameter is a valid hostname or not. * - * @param string $fqdn the parameter to test. - * @return boolean true if the parameter matches a valid FQDN, false otherwise. + * See: http://stackoverflow.com/a/4694816 + * http://stackoverflow.com/a/2183140 + * for references. + * + * @param string $hostname the parameter to test. + * @return boolean true if the parameter matches a valid hostname, false + * otherwise. */ -function match_fqdn($fqdn) { - $regex = '/(?=^.{4,255}$)(^((?!-)[a-zA-Z0-9-]{1,63}(?