summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Mazoyer <respawneral@gmail.com>2014-06-14 23:17:22 +0200
committerGuillaume Mazoyer <respawneral@gmail.com>2014-06-14 23:17:22 +0200
commitf97dcdd539407d5987236bdffacc093cc790d373 (patch)
treec39dcd05d218a3a7d6e4638b0bbaf83bdfea9088
parent6f3b61ae16cc04c4b4f036a795842ef81d210635 (diff)
Add preliminary support for Cisco routers.
Need to be tested.
-rw-r--r--README.md12
-rw-r--r--auth/ssh.php2
-rw-r--r--auth/telnet.php2
-rw-r--r--config.php.example24
-rw-r--r--routers/cisco.php86
-rw-r--r--routers/router.php9
6 files changed, 106 insertions, 29 deletions
diff --git a/README.md b/README.md
index d49f552..abdc500 100644
--- a/README.md
+++ b/README.md
@@ -20,20 +20,20 @@ execute some commands on routers. The output is sent back to the user.
For now this looking glass is quite simple. Here you have some features:
* Interface using Javascript and AJAX calls (needs a decent browser)
- * Support of Juniper routers
- * Support of SSH connection to routers using password authentication
+ * Support of Cisco and Juniper routers
+ * Support of Telnet and SSH connection to routers using password
+ authentication and SSH keys.
* Configurable list of routers
- * Tweakable interface (title, logo, footer)
+ * Tweakable interface (title, logo, footer, elements order)
* Log all commands in a file
* Customizable output with regular expressions
And here is a list of what this looking glass should be able to do in the
future:
- * Support of Cisco, Quagga, BIRD and more routers
- * Support of various authentication types
+ * Support of Quagga, BIRD and more routers
+ * Support of other types of authentication
* Configurable list of allowed commands
- * More customizable interface
Configuration
-------------
diff --git a/auth/ssh.php b/auth/ssh.php
index 07a51d2..2b67541 100644
--- a/auth/ssh.php
+++ b/auth/ssh.php
@@ -27,7 +27,7 @@ final class SSH extends Authentication {
public function __construct($config) {
parent::__construct($config);
- $this->port = isset($this->config['port']) ? $this->config['port'] : 22;
+ $this->port = isset($this->config['port']) ? (int) $this->config['port'] : 22;
}
protected function check_config() {
diff --git a/auth/telnet.php b/auth/telnet.php
index 6e4064e..f490148 100644
--- a/auth/telnet.php
+++ b/auth/telnet.php
@@ -27,7 +27,7 @@ final class Telnet extends Authentication {
public function __construct($config) {
parent::__construct($config);
- $this->port = isset($this->config['port']) ? $this->config['port'] : 23;
+ $this->port = isset($this->config['port']) ? (int) $this->config['port'] : 23;
}
protected function check_config() {
diff --git a/config.php.example b/config.php.example
index 0f19e46..0749398 100644
--- a/config.php.example
+++ b/config.php.example
@@ -29,16 +29,16 @@ $config['filters'][1] = '/^NotToShow/';
// Routers definitions
-// Authentication based on SSH with password
+// Authentication based on SSH or Telnet with password
// The hostname or the IP address
$config['routers']['router1']['host'] = 'r1.example.net';
// The user to use to connect to the router
$config['routers']['router1']['user'] = 'readonlyuser';
// The password of the given user
$config['routers']['router1']['pass'] = 'readonlypassword';
-// The authentication mecanism to use (ssh-password, ssh-key or telnet)
+// The authentication mecanism to use (can be ssh-password or telnet)
$config['routers']['router1']['auth'] = 'ssh-password';
-// The router type (juniper/junos only supported for now)
+// The router type (can be cisco, ios, juniper or junos)
$config['routers']['router1']['type'] = 'juniper';
// The router description to be displayed in the router list
$config['routers']['router1']['desc'] = 'Example\'s Router 1';
@@ -54,25 +54,11 @@ $config['routers']['router2']['public_key'] = '/home/user/.ssh/key.pub';
$config['routers']['router2']['private_key'] = '/home/user/.ssh/key.pub';
// The passphrase of the key (optional if the key has no passphrase)
$config['routers']['router2']['pass'] = 'mypassphrase';
-// The authentication mecanism to use (ssh-password, ssh-key or telnet)
+// The authentication mecanism to use (ssh-key for SSH based on keys)
$config['routers']['router2']['auth'] = 'ssh-key';
-// The router type (juniper/junos only supported for now)
+// The router type (can be cisco, ios, juniper or junos)
$config['routers']['router2']['type'] = 'juniper';
// The router description to be displayed in the router list
$config['routers']['router2']['desc'] = 'Example\'s Router 2';
-// Authentication based on Telnet
-// The hostname or the IP address
-$config['routers']['router3']['host'] = 'r3.example.net';
-// The user to use to connect to the router
-$config['routers']['router3']['user'] = 'readonlyuser';
-// The password of the given user
-$config['routers']['router3']['pass'] = 'readonlypassword';
-// The authentication mecanism to use (ssh-password, ssh-key or telnet)
-$config['routers']['router3']['auth'] = 'telnet';
-// The router type (juniper/junos only supported for now)
-$config['routers']['router3']['type'] = 'juniper';
-// The router description to be displayed in the router list
-$config['routers']['router3']['desc'] = 'Example\'s Router 3';
-
// End of config.php
diff --git a/routers/cisco.php b/routers/cisco.php
new file mode 100644
index 0000000..cc601a7
--- /dev/null
+++ b/routers/cisco.php
@@ -0,0 +1,86 @@
+<?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 Cisco extends Router {
+ protected function build_commands($command, $parameters) {
+ $commands = array();
+
+ switch ($command) {
+ case 'bgp':
+ if (match_ipv4($parameters)) {
+ $commands[] = 'show bgp ipv4 unicast '.$parameters;
+ } else if (match_ipv6($parameters)) {
+ $commands[] = '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[] = '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-Path regular expression like ".*XXXX YYYY.*".');
+ }
+ break;
+
+ case 'as':
+ if (match_as($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.');
+ }
+ break;
+
+ case 'ping':
+ if (match_ipv4($parameters)) {
+ $commands[] = 'ping '.$parameters.' count 10';
+ } else if (match_ipv6($parameters)) {
+ $commands[] = 'ping ipv6 '.$parameters.' count 10';
+ } else {
+ throw new Exception('The parameter is not an IPv4/IPv6 address.');
+ }
+ break;
+
+ case 'traceroute':
+ if (match_ipv4($parameters)) {
+ $commands[] = 'traceroute ip '.$parameters;
+ } else if (match_ipv6($parameters)) {
+ $commands[] = 'traceroute ipv6 '.$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 e0e8d00..8eaa2ef 100644
--- a/routers/router.php
+++ b/routers/router.php
@@ -20,6 +20,7 @@
*/
require_once 'config.php';
+require_once 'cisco.php';
require_once 'juniper.php';
require_once 'utils.php';
require_once 'auth/authentication.php';
@@ -63,8 +64,8 @@ abstract class Router {
$auth->disconnect();
foreach ($commands as $selected) {
- log_to_file('[client: '.$this->requester.'] '.$this->config['host'].'> '.
- $selected);
+ log_to_file('[client: '.$this->requester.'] '.$this->config['host'].
+ '> '.$selected);
}
}
@@ -77,6 +78,10 @@ abstract class Router {
$router_config = $config['routers'][$id];
switch ($router_config['type']) {
+ case 'cisco':
+ case 'ios':
+ return new Cisco($router_config, $id, $requester);
+
case 'juniper':
case 'junos':
return new Juniper($router_config, $id, $requester);