diff options
author | Guillaume Mazoyer <respawneral@gmail.com> | 2014-12-10 20:47:56 +0100 |
---|---|---|
committer | Guillaume Mazoyer <respawneral@gmail.com> | 2014-12-10 20:47:56 +0100 |
commit | 7436934fe3e1d28ca4c1124ccec5bbcdecdc986f (patch) | |
tree | e6c5fac19adeccb4cc3c360b0e101d6f669614b8 | |
parent | bcb3cc4dc275098c33ebc46fb49ef0397242b1ba (diff) |
Add option to specify an interface or an address for routers.
The interface is used on routers to source ping and traceroute.
On software routers, an address is required instead of the interface.
-rw-r--r-- | config.php.example | 6 | ||||
-rw-r--r-- | docs/configuration.md | 13 | ||||
-rw-r--r-- | routers/bird.php | 58 | ||||
-rw-r--r-- | routers/cisco.php | 12 | ||||
-rw-r--r-- | routers/juniper.php | 23 | ||||
-rw-r--r-- | routers/quagga.php | 58 |
6 files changed, 149 insertions, 21 deletions
diff --git a/config.php.example b/config.php.example index 1126988..107ff1d 100644 --- a/config.php.example +++ b/config.php.example @@ -38,6 +38,8 @@ $config['routers']['router1']['pass'] = 'readonlypassword'; $config['routers']['router1']['auth'] = 'ssh-password'; // The router type (can be cisco, ios, juniper or junos) $config['routers']['router1']['type'] = 'juniper'; +// The router source interface to be used +$config['routers']['router1']['source-interface-id'] = 'lo0'; // The router description to be displayed in the router list $config['routers']['router1']['desc'] = 'Example\'s Router 1'; @@ -54,6 +56,8 @@ $config['routers']['router2']['pass'] = 'mypassphrase'; $config['routers']['router2']['auth'] = 'ssh-key'; // The router type (can be cisco, ios, juniper or junos) $config['routers']['router2']['type'] = 'juniper'; +// The router source interface to be used +$config['routers']['router2']['source-interface-id'] = 'lo0'; // The router description to be displayed in the router list $config['routers']['router2']['desc'] = 'Example\'s Router 2'; @@ -68,6 +72,8 @@ $config['routers']['router3']['pass'] = 'birduserpassword'; $config['routers']['router3']['auth'] = 'ssh-password'; // The router type (can only be bird) $config['routers']['router3']['type'] = 'bird'; +// The router source address to be used +$config['routers']['router3']['source-interface-id'] = '192.168.1.1'; // The router description to be displayed in the router list $config['routers']['router3']['desc'] = 'Example\'s Router 3'; diff --git a/docs/configuration.md b/docs/configuration.md index 8391492..39257da 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -107,6 +107,19 @@ $config['routers']['router1']['type'] = 'juniper'; The router type can be Juniper, Cisco, Quagga or BIRD. You can take a look at the specific documentation for your router. +It is also highly recommended to specify a source interface ID to be used by +the router when it will try to ping or traceroute a destination. This is done +with: + +```php +$config['routers']['router1']['source-interface-id'] = 'lo0'; +``` +for Cisco and Juniper routers (change lo0 with your interface), and with: +```php +$config['routers']['router1']['source-interface-id'] = '192.168.1.1'; +``` +for BIRD and Quagga routers (use your own IP address). + After that you need to set the authentication information for the looking glass to be able to log into the router. For this you select a type of authentication and then supply the needed information. diff --git a/routers/bird.php b/routers/bird.php index b86315b..71a8602 100644 --- a/routers/bird.php +++ b/routers/bird.php @@ -63,10 +63,23 @@ final class Bird extends Router { break; case 'ping': + $append = null; + if (isset($this->config['source-interface-id'])) { + $append = ' -I '.$this->config['source-interface-id']; + } + if (match_ipv4($parameters)) { - $commands[] = 'ping -A -c 10 '.$parameters; + $ping = 'ping -A -c 10 '.$parameters; + if ($append != null) { + $ping .= $append; + } + $commands[] = $ping; } else if (match_ipv6($parameters)) { - $commands[] = 'ping6 -A -c 10 '.$parameters; + $ping = 'ping6 -A -c 10 '.$parameters; + if ($append != null) { + $ping .= $append; + } + $commands[] = $ping; } else if (match_fqdn($parameters)) { $ip_address = fqdn_to_ip_address($parameters); @@ -75,9 +88,17 @@ final class Bird extends Router { } if (match_ipv4($ip_address)) { - $commands[] = 'ping -A -c 10 '.$parameters; + $ping = 'ping -A -c 10 '.$parameters; + if ($append != null) { + $ping .= $append; + } + $commands[] = $ping; } else if (match_ipv6($ip_address)) { - $commands[] = 'ping6 -A -c 10 '.$parameters; + $ping = 'ping6 -A -c 10 '.$parameters; + if ($append != null) { + $ping .= $append; + } + $commands[] = $ping; } } else { throw new Exception('The parameter is not an IPv4/IPv6 address.'); @@ -85,10 +106,23 @@ final class Bird extends Router { break; case 'traceroute': + $append = null; + if (isset($this->config['source-interface-id'])) { + $append = ' -s '.$this->config['source-interface-id']; + } + if (match_ipv4($parameters)) { - $commands[] = 'traceroute -4 -A -q1 -N32 -w1 -m15 '.$parameters; + $traceroute = 'traceroute -4 -A -q1 -N32 -w1 -m15 '.$parameters; + if ($append != null) { + $traceroute .= $append; + } + $commands[] = $traceroute; } else if (match_ipv6($parameters)) { - $commands[] = 'traceroute -6 -A -q1 -N32 -w1 -m15 '.$parameters; + $traceroute = 'traceroute -6 -A -q1 -N32 -w1 -m15 '.$parameters; + if ($append != null) { + $traceroute .= $append; + } + $commands[] = $traceroute; } else if (match_fqdn($parameters)) { $ip_address = fqdn_to_ip_address($parameters); @@ -97,9 +131,17 @@ final class Bird extends Router { } if (match_ipv4($ip_address)) { - $commands[] = 'traceroute -4 -A -q1 -N32 -w1 -m15 '.$parameters; + $traceroute = 'traceroute -4 -A -q1 -N32 -w1 -m15 '.$parameters; + if ($append != null) { + $traceroute .= $append; + } + $commands[] = $traceroute; } else if (match_ipv6($ip_address)) { - $commands[] = 'traceroute -6 -A -q1 -N32 -w1 -m15 '.$parameters; + $traceroute = 'traceroute -6 -A -q1 -N32 -w1 -m15 '.$parameters; + if ($append != null) { + $traceroute .= $append; + } + $commands[] = $traceroute; } } else { throw new Exception('The parameter is not an IPv4/IPv6 address.'); diff --git a/routers/cisco.php b/routers/cisco.php index bc34653..285653a 100644 --- a/routers/cisco.php +++ b/routers/cisco.php @@ -57,7 +57,11 @@ final class Cisco extends Router { case 'ping': if (match_ipv4($parameters) || match_ipv6($parameters) || match_fqdn($parameters)) { - $commands[] = 'ping '.$parameters.' repeat 10'; + $ping = 'ping '.$parameters.' repeat 10'; + if (isset($this->config['source-interface-id'])) { + $ping .= ' source '.$this->config['source-interface-id']; + } + $commands[] = $ping; } else { throw new Exception('The parameter is not an IPv4/IPv6 address.'); } @@ -65,7 +69,11 @@ final class Cisco extends Router { case 'traceroute': if (match_ipv4($parameters) || match_ipv6($parameters) || match_fqdn($parameters)) { - $commands[] = 'traceroute '.$parameters; + $traceroute = 'traceroute '.$parameters; + if (isset($this->config['source-interface-id'])) { + $traceroute .= ' source '.$this->config['source-interface-id']; + } + $commands[] = $traceroute; } else { throw new Exception('The parameter is not an IPv4/IPv6 address.'); } diff --git a/routers/juniper.php b/routers/juniper.php index 6c6acf7..fefdf1c 100644 --- a/routers/juniper.php +++ b/routers/juniper.php @@ -64,17 +64,34 @@ final class Juniper extends Router { case 'ping': if (match_ipv4($parameters) || match_ipv6($parameters) || match_fqdn($parameters)) { - $commands[] = 'ping count 10 '.$parameters.' rapid'; + $ping = 'ping count 10 rapid '.$parameters; + if (isset($this->config['source-interface-id'])) { + $ping .= ' interface '.$this->config['source-interface-id']; + } + $commands[] = $ping; } else { throw new Exception('The parameter is not an IPv4/IPv6 address or a FQDN.'); } break; case 'traceroute': + $append = null; + if (isset($this->config['source-interface-id'])) { + $append = ' interface '.$this->config['source-interface-id']; + } + if (match_ipv4($parameters)) { - $commands[] = 'traceroute '.$parameters.' as-number-lookup'; + $traceroute = 'traceroute as-number-lookup '.$parameters; + if ($append != null) { + $traceroute .= $append; + } + $commands[] = $traceroute; } else if (match_ipv6($parameters) || match_fqdn($parameters)) { - $commands[] = 'traceroute '.$parameters; + $traceroute = 'traceroute '.$parameters; + if ($append != null) { + $traceroute .= $append; + } + $commands[] = $traceroute; } else { throw new Exception('The parameter is not an IPv4/IPv6 address or a FQDN.'); } diff --git a/routers/quagga.php b/routers/quagga.php index 9d7ee77..d12c9e3 100644 --- a/routers/quagga.php +++ b/routers/quagga.php @@ -58,10 +58,23 @@ final class Quagga extends Router { break; case 'ping': + $append = null; + if (isset($this->config['source-interface-id'])) { + $append = ' -I '.$this->config['source-interface-id']; + } + if (match_ipv4($parameters)) { - $commands[] = 'ping -A -c 10 '.$parameters; + $ping = 'ping -A -c 10 '.$parameters; + if ($append != null) { + $ping .= $append; + } + $commands[] = $ping; } else if (match_ipv6($parameters)) { - $commands[] = 'ping6 -A -c 10 '.$parameters; + $ping = 'ping6 -A -c 10 '.$parameters; + if ($append != null) { + $ping .= $append; + } + $commands[] = $ping; } else if (match_fqdn($parameters)) { $ip_address = fqdn_to_ip_address($parameters); @@ -70,9 +83,17 @@ final class Quagga extends Router { } if (match_ipv4($ip_address)) { - $commands[] = 'ping -A -c 10 '.$parameters; + $ping = 'ping -A -c 10 '.$parameters; + if ($append != null) { + $ping .= $append; + } + $commands[] = $ping; } else if (match_ipv6($ip_address)) { - $commands[] = 'ping6 -A -c 10 '.$parameters; + $ping = 'ping6 -A -c 10 '.$parameters; + if ($append != null) { + $ping .= $append; + } + $commands[] = $ping; } } else { throw new Exception('The parameter is not an IPv4/IPv6 address.'); @@ -80,10 +101,23 @@ final class Quagga extends Router { break; case 'traceroute': + $append = null; + if (isset($this->config['source-interface-id'])) { + $append = ' -s '.$this->config['source-interface-id']; + } + if (match_ipv4($parameters)) { - $commands[] = 'traceroute -4 -A -q1 -N32 -w1 -m15 '.$parameters; + $traceroute = 'traceroute -4 -A -q1 -N32 -w1 -m15 '.$parameters; + if ($append != null) { + $traceroute .= $append; + } + $commands[] .= $traceroute; } else if (match_ipv6($parameters)) { - $commands[] = 'traceroute -6 -A -q1 -N32 -w1 -m15 '.$parameters; + $traceroute = 'traceroute -6 -A -q1 -N32 -w1 -m15 '.$parameters; + if ($append != null) { + $traceroute .= $append; + } + $commands[] = $traceroute; } else if (match_fqdn($parameters)) { $ip_address = fqdn_to_ip_address($parameters); @@ -92,9 +126,17 @@ final class Quagga extends Router { } if (match_ipv4($ip_address)) { - $commands[] = 'traceroute -4 -A -q1 -N32 -w1 -m15 '.$parameters; + $traceroute = 'traceroute -4 -A -q1 -N32 -w1 -m15 '.$parameters; + if ($append != null) { + $traceroute .= $append; + } + $commands[] .= $traceroute; } else if (match_ipv6($ip_address)) { - $commands[] = 'traceroute -6 -A -q1 -N32 -w1 -m15 '.$parameters; + $traceroute = 'traceroute -6 -A -q1 -N32 -w1 -m15 '.$parameters; + if ($append != null) { + $traceroute .= $append; + } + $commands[] = $traceroute; } } else { throw new Exception('The parameter is not an IPv4/IPv6 address.'); |