diff options
Diffstat (limited to 'routers/cisco.php')
-rw-r--r-- | routers/cisco.php | 59 |
1 files changed, 45 insertions, 14 deletions
diff --git a/routers/cisco.php b/routers/cisco.php index 4529d2d..0a7cb76 100644 --- a/routers/cisco.php +++ b/routers/cisco.php @@ -2,7 +2,7 @@ /* * Looking Glass - An easy to deploy Looking Glass - * Copyright (C) 2014-2015 Guillaume Mazoyer <gmazoyer@gravitons.in> + * Copyright (C) 2014-2016 Guillaume Mazoyer <gmazoyer@gravitons.in> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,11 +26,22 @@ final class Cisco extends Router { protected function build_ping($destination) { $ping = null; - if (match_ipv6($destination) || match_ipv4($destination) || - match_hostname($destination)) { + if (match_hostname($destination)) { $ping = 'ping '.$destination.' repeat 10'; + } else if (match_ipv6($destination)) { + if ($this->global_config['misc']['disable_ipv6']) { + throw new Exception('IPv6 is disabled.'); + } else { + $ping = 'ping '.$destination.' repeat 10'; + } + } else if (match_ipv4($destination)) { + if ($this->global_config['misc']['disable_ipv4']) { + throw new Exception('IPv4 is disabled.'); + } else { + $ping = 'ping '.$destination.' repeat 10'; + } } else { - throw new Exception('The parameter is not an IPv6/IPv4 address or a hostname.'); + throw new Exception('The parameter is not an IP address or a hostname.'); } if (($ping != null) && $this->has_source_interface_id()) { @@ -51,7 +62,7 @@ final class Cisco extends Router { $destination = hostname_to_ip_address($hostname); if (!$destination) { - throw new Exception('No AAAA or A record found for '.$hostname); + throw new Exception('No record found for '.$hostname); } if (match_ipv6($destination)) { @@ -59,10 +70,10 @@ final class Cisco extends Router { } else if (match_ipv4($destination)) { $traceroute = 'traceroute ip '.(isset($hostname) ? $hostname : $destination); } else { - throw new Exception('The parameter does not resolve to an IPv6/IPv4 address.'); + throw new Exception('The parameter does not resolve to an IP address.'); } } else { - throw new Exception('The parameter is not an IPv6/IPv4 address or a hostname.'); + throw new Exception('The parameter is not an IP address or a hostname.'); } if (($traceroute != null) && $this->has_source_interface_id() && @@ -79,18 +90,32 @@ final class Cisco extends Router { switch ($command) { case 'bgp': if (match_ipv6($parameter, false)) { - $commands[] = 'show bgp ipv6 unicast '.$parameter; + if ($this->global_config['misc']['disable_ipv6']) { + throw new Exception('IPv6 is disabled.'); + } else { + $commands[] = 'show bgp ipv6 unicast '.$parameter; + } } else if (match_ipv4($parameter, false)) { - $commands[] = 'show bgp ipv4 unicast '.$parameter; + if ($this->global_config['misc']['disable_ipv4']) { + throw new Exception('IPv4 is disabled.'); + } else { + $commands[] = 'show bgp ipv4 unicast '.$parameter; + } } else { - throw new Exception('The parameter is not an IPv6/IPv4 address.'); + throw new Exception('The parameter is not an IP address.'); } break; case 'as-path-regex': if (match_aspath_regex($parameter)) { - $commands[] = 'show bgp ipv6 unicast quote-regexp "'.$parameter.'"'; - $commands[] = 'show bgp ipv4 unicast quote-regexp "'.$parameter.'"'; + if (!$this->global_config['misc']['disable_ipv6']) { + $commands[] = 'show bgp ipv6 unicast quote-regexp "'.$parameter. + '"'; + } + if (!$this->global_config['misc']['disable_ipv4']) { + $commands[] = 'show bgp ipv4 unicast quote-regexp "'.$parameter. + '"'; + } } else { throw new Exception('The parameter is not an AS-Path regular expression.'); } @@ -98,8 +123,14 @@ final class Cisco extends Router { case 'as': if (match_as($parameter)) { - $commands[] = 'show bgp ipv6 unicast quote-regexp "^'.$parameter.'_"'; - $commands[] = 'show bgp ipv4 unicast quote-regexp "^'.$parameter.'_"'; + if (!$this->global_config['misc']['disable_ipv6']) { + $commands[] = 'show bgp ipv6 unicast quote-regexp "^'.$parameter. + '_"'; + } + if (!$this->global_config['misc']['disable_ipv4']) { + $commands[] = 'show bgp ipv4 unicast quote-regexp "^'.$parameter. + '_"'; + } } else { throw new Exception('The parameter is not an AS number.'); } |