diff options
-rw-r--r-- | auth/authentication.php | 2 | ||||
-rw-r--r-- | auth/ssh.php | 2 | ||||
-rw-r--r-- | auth/telnet.php | 2 | ||||
-rw-r--r-- | docs/configuration.md | 10 | ||||
-rw-r--r-- | execute.php | 2 | ||||
-rw-r--r-- | includes/config.defaults.php | 8 | ||||
-rw-r--r-- | includes/utils.php | 18 | ||||
-rw-r--r-- | index.php | 25 | ||||
-rw-r--r-- | routers/bird.php | 60 | ||||
-rw-r--r-- | routers/cisco.php | 59 | ||||
-rw-r--r-- | routers/juniper.php | 77 | ||||
-rw-r--r-- | routers/quagga.php | 40 | ||||
-rw-r--r-- | routers/router.php | 2 |
13 files changed, 222 insertions, 85 deletions
diff --git a/auth/authentication.php b/auth/authentication.php index b0079a6..366ffa1 100644 --- a/auth/authentication.php +++ b/auth/authentication.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 diff --git a/auth/ssh.php b/auth/ssh.php index e4d22a2..bce82ab 100644 --- a/auth/ssh.php +++ b/auth/ssh.php @@ -2,7 +2,7 @@ /* * Looking Glass - An easy to deploy Looking Glass - * Copyright (C) 2014 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 diff --git a/auth/telnet.php b/auth/telnet.php index 15052ec..20b85a6 100644 --- a/auth/telnet.php +++ b/auth/telnet.php @@ -2,7 +2,7 @@ /* * Looking Glass - An easy to deploy Looking Glass - * Copyright (C) 2014 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 diff --git a/docs/configuration.md b/docs/configuration.md index 9335a51..2483713 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -220,6 +220,16 @@ $config['misc']['allow_reserved_ip'] = true; If set to true, allows reserved the use of IPv4 addresses (0.0.0.0/8, 169.254.0.0/16, 192.0.2.0/24 and 224.0.0.0/4) as parameters. +```php +$config['misc']['disable_ipv6'] = false; +``` +If set to true, disable the use of IPv6. + +```php +$config['misc']['disable_ipv4'] = false; +``` +If set to true, disable the use of IPv4. + ### Tools The tools that are used by this software are **ping** and **traceroute** for diff --git a/execute.php b/execute.php index ac0f892..71dc304 100644 --- a/execute.php +++ b/execute.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 diff --git a/includes/config.defaults.php b/includes/config.defaults.php index 25eaf6f..dfc0d58 100644 --- a/includes/config.defaults.php +++ b/includes/config.defaults.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 @@ -92,7 +92,11 @@ $config = array( 'allow_private_ip' => true, // Allow reserved IPv4 addresses (0.0.0.0/8, 169.254.0.0/16, // 192.0.2.0/24 and 224.0.0.0/4) - 'allow_reserved_ip' => true + 'allow_reserved_ip' => true, + // Disable IPv6 + 'disable_ipv6' => false, + // Disable IPv4 + 'disable_ipv4' => false ), // Tools used for some processing diff --git a/includes/utils.php b/includes/utils.php index b297d61..0fbf3f7 100644 --- a/includes/utils.php +++ b/includes/utils.php @@ -2,7 +2,7 @@ /* * Looking Glass - An easy to deploy Looking Glass - * Copyright (C) 2014 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 @@ -243,7 +243,20 @@ function match_aspath_regex($aspath_regex) { * @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_AAAA + DNS_A); + global $config; + + $record_types = DNS_AAAA + DNS_A; + + // IPv6 is disabled look for A records only + if ($config['misc']['disable_ipv6']) { + $record_types = DNS_A; + } + // IPv4 is disabled look for AAAA records only + if ($config['misc']['disabke_ipv4']) { + $record_types = DNS_AAAA; + } + + $dns_record = dns_get_record($hostname, $record_types); // No DNS record found if (!$dns_record) { @@ -265,7 +278,6 @@ function hostname_to_ip_address($hostname) { // Several records found if ($records_nb > 1) { - // TODO: this could probably be more optimal foreach ($dns_record as $record) { if ($record['type'] == 'AAAA') { return $record['ipv6']; @@ -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 @@ -100,7 +100,7 @@ final class LookingGlass { } print('<div class="header_bar">'); if ($this->frontpage['show_title']) { - print('<h1>'.htmlentities($this->frontpage['title']).'</h1><br />'); + print('<h1>'.htmlentities($this->frontpage['title']).'</h1><br>'); } if ($this->frontpage['image']) { print('<img src="'.$this->frontpage['image'].'" alt="Logo" />'); @@ -112,6 +112,17 @@ final class LookingGlass { } private function render_content() { + if ($this->misc['disable_ipv6'] && $this->misc['disable_ipv4']) { + print('<div class="content">'); + print('<strong>Configuration error!</strong><br>'); + print('It looks like you have disabled IPv6 and IPv4. Do you want to do any networking someday?<br>'); + print('Please enable IPv6 or IPv4 (or even both) by using the following lines in your configuration:<br><br>'); + print('<pre>$config[\'misc\'][\'disable_ipv6\'] = false;</pre>'); + print('<pre>$config[\'misc\'][\'disable_ipv4\'] = false;</pre>'); + print('</div>'); + return; + } + print('<div class="alert alert-danger alert-dismissable" id="error">'); print('<button type="button" class="close" aria-hidden="true">×</button>'); print('<strong>Error!</strong> <span id="error-text"></span>'); @@ -165,20 +176,20 @@ final class LookingGlass { if ($this->frontpage['show_visitor_ip']) { if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { - print('Your IP address: '.htmlentities($_SERVER['HTTP_X_FORWARDED_FOR']).'<br />'); + print('Your IP address: '.htmlentities($_SERVER['HTTP_X_FORWARDED_FOR']).'<br>'); } else { - print('Your IP address: '.htmlentities($_SERVER['REMOTE_ADDR']).'<br />'); + print('Your IP address: '.htmlentities($_SERVER['REMOTE_ADDR']).'<br>'); } } if ($this->frontpage['disclaimer']) { print($this->frontpage['disclaimer']); - print('<br /><br />'); + print('<br><br>'); } if ($this->frontpage['peering_policy_file']) { print('<button type="button" class="btn btn-default btn-sm" data-toggle="modal" data-target="#peering-policy"><span class="glyphicon glyphicon-list-alt"></span> Peering Policy</button>'); - print('<br/><br/>'); + print('<br><br>'); } if ($this->contact['name'] && $this->contact['mail']) { @@ -187,7 +198,7 @@ final class LookingGlass { htmlentities($this->contact['name']).'</a>'); } - print('<br /><br />'); + print('<br><br>'); print('<span class="origin">Powered by <a href="https://github.com/respawner/looking-glass" title="Looking Glass Project">Looking Glass '.$this->release['version'].'</a></span>'); print('</p>'); print('</div>'); diff --git a/routers/bird.php b/routers/bird.php index 6d74672..34f1a96 100644 --- a/routers/bird.php +++ b/routers/bird.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 @@ -31,7 +31,7 @@ final class Bird 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); } } @@ -42,7 +42,7 @@ final class Bird extends Router { $ping = 'ping '.$this->global_config['tools']['ping_options'].' '. (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.'); } if (($ping != null) && $this->has_source_interface_id()) { @@ -68,7 +68,7 @@ final class Bird 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); } } @@ -81,20 +81,20 @@ final class Bird extends Router { $this->global_config['tools']['traceroute_options'].' '. (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.'); } 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'); } } @@ -110,20 +110,32 @@ final class Bird extends Router { switch ($command) { case 'bgp': if (match_ipv6($parameter, false)) { - $commands[] = $birdc6.' \'show route for '.$parameter.'\''; + if ($this->global_config['misc']['disable_ipv6']) { + throw new Exception('IPv6 is disabled.'); + } else { + $commands[] = $birdc6.' \'show route for '.$parameter.'\''; + } } else if (match_ipv4($parameter, false)) { - $commands[] = $birdc.' \'show route for '.$parameter.'\''; + if ($this->global_config['misc']['disable_ipv4']) { + throw new Exception('IPv4 is disabled.'); + } else { + $commands[] = $birdc.' \'show route for '.$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[] = $birdc6.' \'show route where bgp_path ~ [= '. - $parameter.' =]\''; - $commands[] = $birdc.' \'show route where bgp_path ~ [= '. - $parameter.' =]\''; + if (!$this->global_config['misc']['disable_ipv6']) { + $commands[] = $birdc6.' \'show route where bgp_path ~ [= '. + $parameter.' =]\''; + } + if (!$this->global_config['misc']['disable_ipv4']) { + $commands[] = $birdc.' \'show route where bgp_path ~ [= '. + $parameter.' =]\''; + } } else { throw new Exception('The parameter is not an AS-Path regular expression.'); } @@ -131,10 +143,14 @@ final class Bird extends Router { case 'as': if (match_as($parameter)) { - $commands[] = $birdc6.' \'show route where bgp_path ~ [= '. - $parameter.' =]\''; - $commands[] = $birdc.' \'show route where bgp_path ~ [= '. - $parameter.' =]\''; + if (!$this->global_config['misc']['disable_ipv6']) { + $commands[] = $birdc6.' \'show route where bgp_path ~ [= '. + $parameter.' =]\''; + } + if (!$this->global_config['misc']['disable_ipv4']) { + $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 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.'); } diff --git a/routers/juniper.php b/routers/juniper.php index 53c9473..355a1d3 100644 --- a/routers/juniper.php +++ b/routers/juniper.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 Juniper 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 count 10 rapid '.$destination; + } else if (match_ipv6($destination)) { + if ($this->global_config['misc']['disable_ipv6']) { + throw new Exception('IPv6 is disabled.'); + } else { + $ping = 'ping inet6 count 10 rapid '.$destination; + } + } else if (match_ipv4($destination)) { + if ($this->global_config['misc']['disable_ipv4']) { + throw new Exception('IPv4 is disabled.'); + } else { + $ping = 'ping inet count 10 rapid '.$destination; + } } 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()) { @@ -43,12 +54,22 @@ final class Juniper extends Router { protected function build_traceroute($destination) { $traceroute = null; - if (match_ipv6($destination) || match_hostname($destination)) { + if (match_hostname($destination)) { $traceroute = 'traceroute '.$destination; + } else if (match_ipv6($destination)) { + if ($this->global_config['misc']['disable_ipv6']) { + throw new Exception('IPv6 is disabled.'); + } else { + $traceroute = 'traceroute inet6 '.$destination; + } } else if (match_ipv4($destination)) { - $traceroute = 'traceroute as-number-lookup '.$destination; + if ($this->global_config['misc']['disable_ipv4']) { + throw new Exception('IPv4 is disabled.'); + } else { + $traceroute = 'traceroute inet as-number-lookup '.$destination; + } } 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()) { @@ -64,22 +85,34 @@ final class Juniper extends Router { switch ($command) { case 'bgp': if (match_ipv6($parameter, false)) { - $commands[] = 'show route '.$parameter. - ' protocol bgp table inet6.0 active-path'; + if ($this->global_config['misc']['disable_ipv6']) { + throw new Exception('IPv6 is disabled.'); + } else { + $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'; + if ($this->global_config['misc']['disable_ipv4']) { + throw new Exception('IPv4 is disabled.'); + } else { + $commands[] = 'show route '.$parameter. + ' protocol bgp table inet.0 active-path'; + } } 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 route aspath-regex "'.$parameter. - '" protocol bgp table inet6.0'; - $commands[] = 'show route aspath-regex "'.$parameter. - '" protocol bgp table inet.0'; + if (!$this->global_config['misc']['disable_ipv6']) { + $commands[] = 'show route aspath-regex "'.$parameter. + '" protocol bgp table inet6.0'; + } + if (!$this->global_config['misc']['disable_ipv4']) { + $commands[] = 'show route aspath-regex "'.$parameter. + '" protocol bgp table inet.0'; + } } else { throw new Exception('The parameter is not an AS-Path regular expression.'); } @@ -87,10 +120,14 @@ final class Juniper extends Router { case 'as': if (match_as($parameter)) { - $commands[] = 'show route aspath-regex "^'.$parameter. - ' .*" protocol bgp table inet6.0'; - $commands[] = 'show route aspath-regex "^'.$parameter. - ' .*" protocol bgp table inet.0'; + if (!$this->global_config['misc']['disable_ipv6']) { + $commands[] = 'show route aspath-regex "^'.$parameter. + ' .*" protocol bgp table inet6.0'; + } + if (!$this->global_config['misc']['disable_ipv4']) { + $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 55f423f..bc91cdf 100644 --- a/routers/quagga.php +++ b/routers/quagga.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 @@ -31,7 +31,7 @@ final class Quagga 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); } } @@ -42,7 +42,7 @@ final class Quagga extends Router { $ping = 'ping '.$this->global_config['tools']['ping_options'].' '. (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.'); } if (($ping != null) && $this->has_source_interface_id()) { @@ -68,7 +68,7 @@ final class Quagga 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); } } @@ -81,7 +81,7 @@ final class Quagga extends Router { $this->global_config['tools']['traceroute_options'].' '. (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.'); } if (($traceroute != null) && $this->has_source_interface_id()) { @@ -109,18 +109,30 @@ final class Quagga extends Router { switch ($command) { case 'bgp': if (match_ipv6($parameter, false)) { - $commands[] = $vtysh.'show bgp ipv6 unicast '.$parameter.'"'; + if ($this->global_config['misc']['disable_ipv6']) { + throw new Exception('IPv6 is disabled.'); + } else { + $commands[] = $vtysh.'show bgp ipv6 unicast '.$parameter.'"'; + } } else if (match_ipv4($parameter, false)) { - $commands[] = $vtysh.'show bgp ipv4 unicast '.$parameter.'"'; + if ($this->global_config['misc']['disable_ipv4']) { + throw new Exception('IPv4 is disabled.'); + } else { + $commands[] = $vtysh.'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 IP address.'); } break; case 'as-path-regex': if (match_aspath_regex($parameter)) { - $commands[] = $vtysh.'show ipv6 bgp regexp '.$parameter.'"'; - $commands[] = $vtysh.'show ip bgp regexp '.$parameter.'"'; + if (!$this->global_config['misc']['disable_ipv6']) { + $commands[] = $vtysh.'show ipv6 bgp regexp '.$parameter.'"'; + } + if (!$this->global_config['misc']['disable_ipv4']) { + $commands[] = $vtysh.'show ip bgp regexp '.$parameter.'"'; + } } else { throw new Exception('The parameter is not an AS-Path regular expression.'); } @@ -128,8 +140,12 @@ final class Quagga extends Router { case 'as': if (match_as($parameter)) { - $commands[] = $vtysh.'show ipv6 bgp regexp ^'.$parameter.'_'.'"'; - $commands[] = $vtysh.'show ip bgp regexp ^'.$parameter.'_'.'"'; + if (!$this->global_config['misc']['disable_ipv6']) { + $commands[] = $vtysh.'show ipv6 bgp regexp ^'.$parameter.'_'.'"'; + } + if (!$this->global_config['misc']['disable_ipv4']) { + $commands[] = $vtysh.'show ip bgp regexp ^'.$parameter.'_'.'"'; + } } else { throw new Exception('The parameter is not an AS number.'); } diff --git a/routers/router.php b/routers/router.php index 984de2d..f980982 100644 --- a/routers/router.php +++ b/routers/router.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 |