summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/utils.php54
-rw-r--r--routers/bird.php50
-rw-r--r--routers/cisco.php30
-rw-r--r--routers/juniper.php30
-rw-r--r--routers/quagga.php56
5 files changed, 110 insertions, 110 deletions
diff --git a/includes/utils.php b/includes/utils.php
index 4dfe132..b297d61 100644
--- a/includes/utils.php
+++ b/includes/utils.php
@@ -56,17 +56,17 @@ function match_reserved_ip_range($ip) {
}
/**
- * Test if a given parameter is an IPv4 or not.
+ * Test if a given parameter is an IPv6 or not.
*
* @param string $ip the parameter to test.
* @param boolean $ip_only optional parameter, if omitted or set to true, it
- * will ensure that the first parameter is an IPv4
+ * will ensure that the first parameter is an IPv6
* address without mask, if set to false the IP/MASK
* form is considered as valid.
- * @return boolean true if the parameter matches an IPv4 address, false
+ * @return boolean true if the parameter matches an IPv6 address, false
* otherwise.
*/
-function match_ipv4($ip, $ip_only = true) {
+function match_ipv6($ip, $ip_only = true) {
global $config;
if (empty($ip)) {
@@ -81,12 +81,7 @@ function match_ipv4($ip, $ip_only = true) {
return false;
}
- if (!$config['misc']['allow_reserved_ip'] &&
- match_reserved_ip_range($ip_and_mask[0])) {
- return false;
- }
-
- return filter_var($ip_and_mask[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) &&
+ return filter_var($ip_and_mask[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) &&
filter_var($ip_and_mask[1], FILTER_VALIDATE_INT);
} else {
if (!$config['misc']['allow_private_ip'] &&
@@ -94,27 +89,22 @@ function match_ipv4($ip, $ip_only = true) {
return false;
}
- if (!$config['misc']['allow_reserved_ip'] &&
- match_reserved_ip_range($ip)) {
- return false;
- }
-
- return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
+ return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
}
}
/**
- * Test if a given parameter is an IPv6 or not.
+ * Test if a given parameter is an IPv4 or not.
*
* @param string $ip the parameter to test.
* @param boolean $ip_only optional parameter, if omitted or set to true, it
- * will ensure that the first parameter is an IPv6
+ * will ensure that the first parameter is an IPv4
* address without mask, if set to false the IP/MASK
* form is considered as valid.
- * @return boolean true if the parameter matches an IPv6 address, false
+ * @return boolean true if the parameter matches an IPv4 address, false
* otherwise.
*/
-function match_ipv6($ip, $ip_only = true) {
+function match_ipv4($ip, $ip_only = true) {
global $config;
if (empty($ip)) {
@@ -129,7 +119,12 @@ function match_ipv6($ip, $ip_only = true) {
return false;
}
- return filter_var($ip_and_mask[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) &&
+ if (!$config['misc']['allow_reserved_ip'] &&
+ match_reserved_ip_range($ip_and_mask[0])) {
+ return false;
+ }
+
+ return filter_var($ip_and_mask[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) &&
filter_var($ip_and_mask[1], FILTER_VALIDATE_INT);
} else {
if (!$config['misc']['allow_private_ip'] &&
@@ -137,7 +132,12 @@ function match_ipv6($ip, $ip_only = true) {
return false;
}
- return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
+ if (!$config['misc']['allow_reserved_ip'] &&
+ match_reserved_ip_range($ip)) {
+ return false;
+ }
+
+ return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
}
}
@@ -230,20 +230,20 @@ function match_aspath_regex($aspath_regex) {
}
/**
- * For a given hostname try to find the corresponding IPv4 or IPv6 address.
+ * For a given hostname try to find the corresponding IPv6 or IPv4 address.
*
* If there is multiple addresses attached to the same hostname it will give
- * the first IPv4 or IPv6 found.
+ * the first IPv6 or IPv4 found.
*
- * If the hostname have both IPv4 and IPv6 addresses it will give the first
+ * If the hostname have both IPv6 and IPv4 addresses it will give the first
* IPv6 address found.
*
* @param string $hostname the hostname to use to search in the DNS
* databases.
- * @return string an IPv4 or IPv6 address based on the DNS records.
+ * @return string an IPv6 or IPv4 address based on the DNS records.
*/
function hostname_to_ip_address($hostname) {
- $dns_record = dns_get_record($hostname, DNS_A + DNS_AAAA);
+ $dns_record = dns_get_record($hostname, DNS_AAAA + DNS_A);
// No DNS record found
if (!$dns_record) {
diff --git a/routers/bird.php b/routers/bird.php
index b1a75b8..6d7a296 100644
--- a/routers/bird.php
+++ b/routers/bird.php
@@ -35,25 +35,25 @@ final class Bird extends Router {
}
}
- if (match_ipv4($destination)) {
- $ping = 'ping '.$this->global_config['tools']['ping_options'].' '.
- (isset($hostname) ? $hostname : $destination);
- } else if (match_ipv6($destination)) {
+ if (match_ipv6($destination)) {
$ping = 'ping6 '.$this->global_config['tools']['ping_options'].' '.
(isset($hostname) ? $hostname : $destination);
+ } else if (match_ipv4($destination)) {
+ $ping = 'ping '.$this->global_config['tools']['ping_options'].' '.
+ (isset($hostname) ? $hostname : $destination);
} else {
- throw new Exception('The parameter does not resolve to an IPv4/IPv6 address.');
+ throw new Exception('The parameter does not resolve to an IPv6/IPv4 address.');
}
if (($ping != null) && $this->has_source_interface_id()) {
- if (match_ipv4($destination) &&
- ($this->get_source_interface_id('ipv4') != null)) {
- $ping .= ' '.$this->global_config['tools']['ping_source_option'].' '.
- $this->get_source_interface_id('ipv4');
- } else if (match_ipv6($destination) &&
+ if (match_ipv6($destination) &&
($this->get_source_interface_id('ipv6') != null)) {
$ping .= ' '.$this->global_config['tools']['ping_source_option'].' '.
$this->get_source_interface_id('ipv6');
+ } else if (match_ipv4($destination) &&
+ ($this->get_source_interface_id('ipv4') != null)) {
+ $ping .= ' '.$this->global_config['tools']['ping_source_option'].' '.
+ $this->get_source_interface_id('ipv4');
}
}
@@ -68,20 +68,20 @@ final class Bird extends Router {
$destination = hostname_to_ip_address($hostname);
if (!$destination) {
- throw new Exception('No A or AAAA record found for '.$hostname);
+ throw new Exception('No AAAA or A record found for '.$hostname);
}
}
- if (match_ipv4($destination)) {
- $traceroute = $this->global_config['tools']['traceroute4'].' '.
+ if (match_ipv6($destination)) {
+ $traceroute = $this->global_config['tools']['traceroute6'].' '.
$this->global_config['tools']['traceroute_options'].' '.
(isset($hostname) ? $hostname : $destination);
- } else if (match_ipv6($destination)) {
- $traceroute = $this->global_config['tools']['traceroute6'].' '.
+ } else if (match_ipv4($destination)) {
+ $traceroute = $this->global_config['tools']['traceroute4'].' '.
$this->global_config['tools']['traceroute_options'].' '.
(isset($hostname) ? $hostname : $destination);
} else {
- throw new Exception('The parameter does not resolve to an IPv4/IPv6 address.');
+ throw new Exception('The parameter does not resolve to an IPv6/IPv4 address.');
}
if (($traceroute != null) && $this->has_source_interface_id()) {
@@ -104,26 +104,26 @@ final class Bird extends Router {
protected function build_commands($command, $parameter) {
$commands = array();
- $birdc = 'birdc';
$birdc6 = 'birdc6';
+ $birdc = 'birdc';
switch ($command) {
case 'bgp':
- if (match_ipv4($parameter, false)) {
- $commands[] = $birdc.' \'show route for '.$parameter.'\'';
- } else if (match_ipv6($parameter, false)) {
+ if (match_ipv6($parameter, false)) {
$commands[] = $birdc6.' \'show route for '.$parameter.'\'';
+ } else if (match_ipv4($parameter, false)) {
+ $commands[] = $birdc.' \'show route for '.$parameter.'\'';
} else {
- throw new Exception('The parameter is not an IPv4/IPv6 address.');
+ throw new Exception('The parameter is not an IPv6/IPv4 address.');
}
break;
case 'as-path-regex':
if (match_aspath_regex($parameter)) {
- $commands[] = $birdc.' \'show route where bgp_path ~ [= '.
- $parameter.' =]\'';
$commands[] = $birdc6.' \'show route where bgp_path ~ [= '.
$parameter.' =]\'';
+ $commands[] = $birdc.' \'show route where bgp_path ~ [= '.
+ $parameter.' =]\'';
} else {
throw new Exception('The parameter is not an AS-Path regular expression.');
}
@@ -131,10 +131,10 @@ final class Bird extends Router {
case 'as':
if (match_as($parameter)) {
- $commands[] = $birdc.' \'show route where bgp_path ~ [= '.
- $parameter.' =]\'';
$commands[] = $birdc6.' \'show route where bgp_path ~ [= '.
$parameter.' =]\'';
+ $commands[] = $birdc.' \'show route where bgp_path ~ [= '.
+ $parameter.' =]\'';
} else {
throw new Exception('The parameter is not an AS number.');
}
diff --git a/routers/cisco.php b/routers/cisco.php
index e36a6bf..4529d2d 100644
--- a/routers/cisco.php
+++ b/routers/cisco.php
@@ -26,11 +26,11 @@ final class Cisco extends Router {
protected function build_ping($destination) {
$ping = null;
- if (match_ipv4($destination) || match_ipv6($destination) ||
+ if (match_ipv6($destination) || match_ipv4($destination) ||
match_hostname($destination)) {
$ping = 'ping '.$destination.' repeat 10';
} else {
- throw new Exception('The parameter is not an IPv4/IPv6 address or a hostname.');
+ throw new Exception('The parameter is not an IPv6/IPv4 address or a hostname.');
}
if (($ping != null) && $this->has_source_interface_id()) {
@@ -43,7 +43,7 @@ final class Cisco extends Router {
protected function build_traceroute($destination) {
$traceroute = null;
- if (match_ipv4($destination) || match_ipv6($destination) ||
+ if (match_ipv6($destination) || match_ipv4($destination) ||
(match_hostname($destination) && !$this->has_source_interface_id())) {
$traceroute = 'traceroute '.$destination;
} else if (match_hostname($destination)) {
@@ -51,18 +51,18 @@ final class Cisco extends Router {
$destination = hostname_to_ip_address($hostname);
if (!$destination) {
- throw new Exception('No A or AAAA record found for '.$hostname);
+ throw new Exception('No AAAA or A record found for '.$hostname);
}
- if (match_ipv4($destination)) {
- $traceroute = 'traceroute ip '.(isset($hostname) ? $hostname : $destination);
- } else if (match_ipv6($destination)) {
+ if (match_ipv6($destination)) {
$traceroute = 'traceroute ipv6 '.(isset($hostname) ? $hostname : $destination);
+ } else if (match_ipv4($destination)) {
+ $traceroute = 'traceroute ip '.(isset($hostname) ? $hostname : $destination);
} else {
- throw new Exception('The parameter does not resolve to an IPv4/IPv6 address.');
+ throw new Exception('The parameter does not resolve to an IPv6/IPv4 address.');
}
} else {
- throw new Exception('The parameter is not an IPv4/IPv6 address or a hostname.');
+ throw new Exception('The parameter is not an IPv6/IPv4 address or a hostname.');
}
if (($traceroute != null) && $this->has_source_interface_id() &&
@@ -78,19 +78,19 @@ final class Cisco extends Router {
switch ($command) {
case 'bgp':
- if (match_ipv4($parameter, false)) {
- $commands[] = 'show bgp ipv4 unicast '.$parameter;
- } else if (match_ipv6($parameter, false)) {
+ if (match_ipv6($parameter, false)) {
$commands[] = 'show bgp ipv6 unicast '.$parameter;
+ } else if (match_ipv4($parameter, false)) {
+ $commands[] = 'show bgp ipv4 unicast '.$parameter;
} else {
- throw new Exception('The parameter is not an IPv4/IPv6 address.');
+ throw new Exception('The parameter is not an IPv6/IPv4 address.');
}
break;
case 'as-path-regex':
if (match_aspath_regex($parameter)) {
- $commands[] = 'show bgp ipv4 unicast quote-regexp "'.$parameter.'"';
$commands[] = 'show bgp ipv6 unicast quote-regexp "'.$parameter.'"';
+ $commands[] = 'show bgp ipv4 unicast quote-regexp "'.$parameter.'"';
} else {
throw new Exception('The parameter is not an AS-Path regular expression.');
}
@@ -98,8 +98,8 @@ final class Cisco extends Router {
case 'as':
if (match_as($parameter)) {
- $commands[] = 'show bgp ipv4 unicast quote-regexp "^'.$parameter.'_"';
$commands[] = 'show bgp ipv6 unicast quote-regexp "^'.$parameter.'_"';
+ $commands[] = 'show bgp ipv4 unicast quote-regexp "^'.$parameter.'_"';
} else {
throw new Exception('The parameter is not an AS number.');
}
diff --git a/routers/juniper.php b/routers/juniper.php
index 3eb34e5..53c9473 100644
--- a/routers/juniper.php
+++ b/routers/juniper.php
@@ -26,11 +26,11 @@ final class Juniper extends Router {
protected function build_ping($destination) {
$ping = null;
- if (match_ipv4($destination) || match_ipv6($destination) ||
+ if (match_ipv6($destination) || match_ipv4($destination) ||
match_hostname($destination)) {
$ping = 'ping count 10 rapid '.$destination;
} else {
- throw new Exception('The parameter is not an IPv4/IPv6 address or a hostname.');
+ throw new Exception('The parameter is not an IPv6/IPv4 address or a hostname.');
}
if (($ping != null) && $this->has_source_interface_id()) {
@@ -43,12 +43,12 @@ final class Juniper extends Router {
protected function build_traceroute($destination) {
$traceroute = null;
- if (match_ipv4($destination)) {
- $traceroute = 'traceroute as-number-lookup '.$destination;
- } else if (match_ipv6($destination) || match_hostname($destination)) {
+ if (match_ipv6($destination) || match_hostname($destination)) {
$traceroute = 'traceroute '.$destination;
+ } else if (match_ipv4($destination)) {
+ $traceroute = 'traceroute as-number-lookup '.$destination;
} else {
- throw new Exception('The parameter is not an IPv4/IPv6 address or a hostname.');
+ throw new Exception('The parameter is not an IPv6/IPv4 address or a hostname.');
}
if (($traceroute != null) && $this->has_source_interface_id()) {
@@ -63,23 +63,23 @@ final class Juniper extends Router {
switch ($command) {
case 'bgp':
- if (match_ipv4($parameter, false)) {
- $commands[] = 'show route '.$parameter.
- ' protocol bgp table inet.0 active-path';
- } else if (match_ipv6($parameter, false)) {
+ if (match_ipv6($parameter, false)) {
$commands[] = 'show route '.$parameter.
' protocol bgp table inet6.0 active-path';
+ } else if (match_ipv4($parameter, false)) {
+ $commands[] = 'show route '.$parameter.
+ ' protocol bgp table inet.0 active-path';
} else {
- throw new Exception('The parameter is not an IPv4/IPv6 address.');
+ throw new Exception('The parameter is not an IPv6/IPv4 address.');
}
break;
case 'as-path-regex':
if (match_aspath_regex($parameter)) {
$commands[] = 'show route aspath-regex "'.$parameter.
- '" protocol bgp table inet.0';
- $commands[] = 'show route aspath-regex "'.$parameter.
'" protocol bgp table inet6.0';
+ $commands[] = 'show route aspath-regex "'.$parameter.
+ '" protocol bgp table inet.0';
} else {
throw new Exception('The parameter is not an AS-Path regular expression.');
}
@@ -88,9 +88,9 @@ final class Juniper extends Router {
case 'as':
if (match_as($parameter)) {
$commands[] = 'show route aspath-regex "^'.$parameter.
- ' .*" protocol bgp table inet.0';
- $commands[] = 'show route aspath-regex "^'.$parameter.
' .*" protocol bgp table inet6.0';
+ $commands[] = 'show route aspath-regex "^'.$parameter.
+ ' .*" protocol bgp table inet.0';
} else {
throw new Exception('The parameter is not an AS number.');
}
diff --git a/routers/quagga.php b/routers/quagga.php
index 9ce6606..55f423f 100644
--- a/routers/quagga.php
+++ b/routers/quagga.php
@@ -31,29 +31,29 @@ final class Quagga extends Router {
$destination = hostname_to_ip_address($hostname);
if (!$destination) {
- throw new Exception('No A or AAAA record found for '.$hostname);
+ throw new Exception('No AAAA or A record found for '.$hostname);
}
}
- if (match_ipv4($destination)) {
- $ping = 'ping '.$this->global_config['tools']['ping_options'].' '.
- (isset($hostname) ? $hostname : $destination);
- } else if (match_ipv6($destination)) {
+ if (match_ipv6($destination)) {
$ping = 'ping6 '.$this->global_config['tools']['ping_options'].' '.
(isset($hostname) ? $hostname : $destination);
+ } else if (match_ipv4($destination)) {
+ $ping = 'ping '.$this->global_config['tools']['ping_options'].' '.
+ (isset($hostname) ? $hostname : $destination);
} else {
- throw new Exception('The parameter does not resolve to an IPv4/IPv6 address.');
+ throw new Exception('The parameter does not resolve to an IPv6/IPv4 address.');
}
if (($ping != null) && $this->has_source_interface_id()) {
- if (match_ipv4($destination) &&
- ($this->get_source_interface_id('ipv4') != null)) {
- $ping .= ' '.$this->global_config['tools']['ping_source_option'].' '.
- $this->get_source_interface_id('ipv4');
- } else if (match_ipv6($destination) &&
+ if (match_ipv6($destination) &&
($this->get_source_interface_id('ipv6') != null)) {
$ping .= ' '.$this->global_config['tools']['ping_source_option'].' '.
$this->get_source_interface_id('ipv6');
+ } else if (match_ipv4($destination) &&
+ ($this->get_source_interface_id('ipv4') != null)) {
+ $ping .= ' '.$this->global_config['tools']['ping_source_option'].' '.
+ $this->get_source_interface_id('ipv4');
}
}
@@ -68,33 +68,33 @@ final class Quagga extends Router {
$destination = hostname_to_ip_address($hostname);
if (!$destination) {
- throw new Exception('No A or AAAA record found for '.$hostname);
+ throw new Exception('No AAAA or A record found for '.$hostname);
}
}
- if (match_ipv4($destination)) {
- $traceroute = $this->global_config['tools']['traceroute4'].' '.
+ if (match_ipv6($destination)) {
+ $traceroute = $this->global_config['tools']['traceroute6'].' '.
$this->global_config['tools']['traceroute_options'].' '.
(isset($hostname) ? $hostname : $destination);
- } else if (match_ipv6($destination)) {
- $traceroute = $this->global_config['tools']['traceroute6'].' '.
+ } else if (match_ipv4($destination)) {
+ $traceroute = $this->global_config['tools']['traceroute4'].' '.
$this->global_config['tools']['traceroute_options'].' '.
(isset($hostname) ? $hostname : $destination);
} else {
- throw new Exception('The parameter does not resolve to an IPv4/IPv6 address.');
+ throw new Exception('The parameter does not resolve to an IPv6/IPv4 address.');
}
if (($traceroute != null) && $this->has_source_interface_id()) {
- if (match_ipv4($destination) &&
- ($this->get_source_interface_id('ipv4') != null)) {
- $traceroute .= ' '.
- $this->global_config['tools']['traceroute_source_option'].' '.
- $this->get_source_interface_id('ipv4');
- } else if (match_ipv6($destination) &&
+ if (match_ipv6($destination) &&
($this->get_source_interface_id('ipv6') != null)) {
$traceroute .= ' '.
$this->global_config['tools']['traceroute_source_option'].' '.
$this->get_source_interface_id('ipv6');
+ } else if (match_ipv4($destination) &&
+ ($this->get_source_interface_id('ipv4') != null)) {
+ $traceroute .= ' '.
+ $this->global_config['tools']['traceroute_source_option'].' '.
+ $this->get_source_interface_id('ipv4');
}
}
@@ -108,10 +108,10 @@ final class Quagga extends Router {
switch ($command) {
case 'bgp':
- if (match_ipv4($parameter, false)) {
- $commands[] = $vtysh.'show bgp ipv4 unicast '.$parameter.'"';
- } else if (match_ipv6($parameter, false)) {
+ if (match_ipv6($parameter, false)) {
$commands[] = $vtysh.'show bgp ipv6 unicast '.$parameter.'"';
+ } else if (match_ipv4($parameter, false)) {
+ $commands[] = $vtysh.'show bgp ipv4 unicast '.$parameter.'"';
} else {
throw new Exception('The parameter is not an IPv4/IPv6 address.');
}
@@ -119,8 +119,8 @@ final class Quagga extends Router {
case 'as-path-regex':
if (match_aspath_regex($parameter)) {
- $commands[] = $vtysh.'show ip bgp regexp '.$parameter.'"';
$commands[] = $vtysh.'show ipv6 bgp regexp '.$parameter.'"';
+ $commands[] = $vtysh.'show ip bgp regexp '.$parameter.'"';
} else {
throw new Exception('The parameter is not an AS-Path regular expression.');
}
@@ -128,8 +128,8 @@ final class Quagga extends Router {
case 'as':
if (match_as($parameter)) {
- $commands[] = $vtysh.'show ip bgp regexp ^'.$parameter.'_'.'"';
$commands[] = $vtysh.'show ipv6 bgp regexp ^'.$parameter.'_'.'"';
+ $commands[] = $vtysh.'show ip bgp regexp ^'.$parameter.'_'.'"';
} else {
throw new Exception('The parameter is not an AS number.');
}