diff options
author | Guillaume Mazoyer <gmazoyer@gravitons.in> | 2014-08-05 00:36:03 +0200 |
---|---|---|
committer | Guillaume Mazoyer <gmazoyer@gravitons.in> | 2014-08-05 00:36:03 +0200 |
commit | b3141237d766978ac71d9c65c5986afecd2f8fad (patch) | |
tree | d5a3475c7d94cc349e67de3497762a4df22df1f3 | |
parent | 2e6c301b4efd557ae876d40815f36fe9966bb2dc (diff) | |
parent | d0510f1a3582b1cee78d7893d1d61b1dceb3f325 (diff) |
Merge pull request #2 from rboissat/master
Adding Quagga support and fixing Cisco commands.
-rw-r--r-- | routers/cisco.php | 4 | ||||
-rw-r--r-- | routers/quagga.php | 88 | ||||
-rw-r--r-- | routers/router.php | 5 |
3 files changed, 95 insertions, 2 deletions
diff --git a/routers/cisco.php b/routers/cisco.php index d1b65b2..bebec78 100644 --- a/routers/cisco.php +++ b/routers/cisco.php @@ -48,8 +48,8 @@ final class Cisco extends Router { case 'as': if (match_as($parameters)) { - $commands[] = 'show bgp ipv4 unicast quote-regexp "^'.$parameters.'$"'; - $commands[] = 'show bgp ipv6 unicast quote-regexp "^'.$parameters.'$"'; + $commands[] = 'show bgp ipv4 unicast quote-regexp "^'.$parameters.'_"'; + $commands[] = 'show bgp ipv6 unicast quote-regexp "^'.$parameters.'_"'; } else { throw new Exception('The parameter is not an AS number.'); } diff --git a/routers/quagga.php b/routers/quagga.php new file mode 100644 index 0000000..a9fe99b --- /dev/null +++ b/routers/quagga.php @@ -0,0 +1,88 @@ +<?php + +/* + * Looking Glass - An easy to deploy Looking Glass + * Copyright (C) 2014 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +require_once 'router.php'; +require_once 'utils.php'; + +final class Quagga extends Router { + protected function build_commands($command, $parameters) { + $commands = array(); + + $vtysh = 'vtysh -c "'; + + switch ($command) { + case 'bgp': + if (match_ipv4($parameters)) { + $commands[] = $vtysh.'show bgp ipv4 unicast '.$parameters.'"'; + } else if (match_ipv6($parameters)) { + $commands[] = $vtysh.'show bgp ipv6 unicast '.$parameters.'"'; + } else { + throw new Exception('The parameter is not an IPv4/IPv6 address.'); + } + break; + + case 'as-path-regex': + if (match_aspath_regex($parameters)) { + $commands[] = $vtysh.'show ip bgp regexp '.$parameters.'"'; + $commands[] = $vtysh.'show ipv6 bgp regexp '.$parameters.'"'; + } else { + throw new Exception('The parameter is not an AS-Path regular expression like ".*XXXX YYYY.*".'); + } + break; + + case 'as': + if (match_as($parameters)) { + $commands[] = $vtysh.'show ip bgp regexp ^'.$parameters.'_'.'"'; + $commands[] = $vtysh.'show ipv6 bgp regexp ^'.$parameters.'_'.'"'; + } else { + throw new Exception('The parameter is not an AS number.'); + } + break; + + case 'ping': + if (match_ipv4($parameters)) { + $commands[] = 'ping -A -c 10 '.$parameters; + } else if (match_ipv6($parameters)) { + $commands[] = 'ping6 -A -c 10 '.$parameters; + } else { + throw new Exception('The parameter is not an IPv4/IPv6 address.'); + } + break; + + case 'traceroute': + if (match_ipv4($parameters)) { + $commands[] = 'traceroute -4 -A -q1 -N32 -w1 -m15 '.$parameters; + } else if (match_ipv6($parameters)) { + $commands[] = 'traceroute -6 -A -q1 -N32 -w1 -m15 '.$parameters; + } else { + throw new Exception('The parameter is not an IPv4/IPv6 address.'); + } + break; + + default: + throw new Exception('Command not supported.'); + } + + return $commands; + } +} + +// End of cisco.php diff --git a/routers/router.php b/routers/router.php index bf5c466..f1d2427 100644 --- a/routers/router.php +++ b/routers/router.php @@ -23,6 +23,7 @@ require_once 'config.php'; require_once 'bird.php'; require_once 'cisco.php'; require_once 'juniper.php'; +require_once 'quagga.php'; require_once 'utils.php'; require_once 'auth/authentication.php'; @@ -82,6 +83,10 @@ abstract class Router { case 'junos': return new Juniper($router_config, $id, $requester); + case 'quagga': + case 'zebra': + return new Quagga($router_config, $id, $requester); + default: print 'Unknown router type "'.$router_config['type'].'"."'; return null; |