summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--execute.php15
-rw-r--r--routers/bird.php12
-rw-r--r--routers/cisco.php27
-rw-r--r--routers/juniper.php45
-rw-r--r--routers/quagga.php12
5 files changed, 31 insertions, 80 deletions
diff --git a/execute.php b/execute.php
index 71dc304..227c6e6 100644
--- a/execute.php
+++ b/execute.php
@@ -22,6 +22,7 @@
require_once('includes/config.defaults.php');
require_once('config.php');
require_once('routers/router.php');
+require_once('includes/utils.php');
// From where the user *really* comes from.
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
@@ -52,6 +53,20 @@ if (isset($_POST['query']) && !empty($_POST['query']) &&
// Do the processing
$router = Router::instance($hostname, $requester);
+ // Check if parameter is an IPv6 and if IPv6 is disabled
+ if (match_ipv6($parameter) && $config['misc']['disable_ipv6']) {
+ $error = 'IPv6 has been disabled, you can only use IPv4.';
+ print(json_encode(array('error' => $error)));
+ return;
+ }
+
+ // Check if parameter is an IPv4 and if IPv4 is disabled
+ if (match_ipv4($parameter) && $config['misc']['disable_ipv4']) {
+ $error = 'IPv4 has been disabled, you can only use IPv6.';
+ print(json_encode(array('error' => $error)));
+ return;
+ }
+
try {
$output = $router->send_command($query, $parameter);
} catch (Exception $e) {
diff --git a/routers/bird.php b/routers/bird.php
index 34f1a96..5219cc2 100644
--- a/routers/bird.php
+++ b/routers/bird.php
@@ -110,17 +110,9 @@ final class Bird extends Router {
switch ($command) {
case 'bgp':
if (match_ipv6($parameter, false)) {
- if ($this->global_config['misc']['disable_ipv6']) {
- throw new Exception('IPv6 is disabled.');
- } else {
- $commands[] = $birdc6.' \'show route for '.$parameter.'\'';
- }
+ $commands[] = $birdc6.' \'show route for '.$parameter.'\'';
} else if (match_ipv4($parameter, false)) {
- if ($this->global_config['misc']['disable_ipv4']) {
- throw new Exception('IPv4 is disabled.');
- } else {
- $commands[] = $birdc.' \'show route for '.$parameter.'\'';
- }
+ $commands[] = $birdc.' \'show route for '.$parameter.'\'';
} else {
throw new Exception('The parameter is not an IP address.');
}
diff --git a/routers/cisco.php b/routers/cisco.php
index 0a7cb76..aee0b02 100644
--- a/routers/cisco.php
+++ b/routers/cisco.php
@@ -26,20 +26,9 @@ final class Cisco extends Router {
protected function build_ping($destination) {
$ping = null;
- if (match_hostname($destination)) {
+ if (match_hostname($destination) || match_ipv6($destination) ||
+ match_ipv4($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 IP address or a hostname.');
}
@@ -90,17 +79,9 @@ final class Cisco extends Router {
switch ($command) {
case 'bgp':
if (match_ipv6($parameter, false)) {
- if ($this->global_config['misc']['disable_ipv6']) {
- throw new Exception('IPv6 is disabled.');
- } else {
- $commands[] = 'show bgp ipv6 unicast '.$parameter;
- }
+ $commands[] = 'show bgp ipv6 unicast '.$parameter;
} else if (match_ipv4($parameter, false)) {
- if ($this->global_config['misc']['disable_ipv4']) {
- throw new Exception('IPv4 is disabled.');
- } else {
- $commands[] = 'show bgp ipv4 unicast '.$parameter;
- }
+ $commands[] = 'show bgp ipv4 unicast '.$parameter;
} else {
throw new Exception('The parameter is not an IP address.');
}
diff --git a/routers/juniper.php b/routers/juniper.php
index 355a1d3..3e04921 100644
--- a/routers/juniper.php
+++ b/routers/juniper.php
@@ -26,20 +26,9 @@ final class Juniper extends Router {
protected function build_ping($destination) {
$ping = null;
- if (match_hostname($destination)) {
+ if (match_hostname($destination) || match_ipv6($destination) ||
+ match_ipv4($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 IP address or a hostname.');
}
@@ -54,20 +43,10 @@ final class Juniper extends Router {
protected function build_traceroute($destination) {
$traceroute = null;
- if (match_hostname($destination)) {
+ if (match_hostname($destination) || match_ipv6($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)) {
- if ($this->global_config['misc']['disable_ipv4']) {
- throw new Exception('IPv4 is disabled.');
- } else {
- $traceroute = 'traceroute inet as-number-lookup '.$destination;
- }
+ $traceroute = 'traceroute as-number-lookup '.$destination;
} else {
throw new Exception('The parameter is not an IP address or a hostname.');
}
@@ -85,19 +64,11 @@ final class Juniper extends Router {
switch ($command) {
case 'bgp':
if (match_ipv6($parameter, false)) {
- 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';
- }
+ $commands[] = 'show route '.$parameter.
+ ' protocol bgp table inet6.0 active-path';
} else if (match_ipv4($parameter, false)) {
- 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';
- }
+ $commands[] = 'show route '.$parameter.
+ ' protocol bgp table inet.0 active-path';
} else {
throw new Exception('The parameter is not an IP address.');
}
diff --git a/routers/quagga.php b/routers/quagga.php
index bc91cdf..01d4387 100644
--- a/routers/quagga.php
+++ b/routers/quagga.php
@@ -109,17 +109,9 @@ final class Quagga extends Router {
switch ($command) {
case 'bgp':
if (match_ipv6($parameter, false)) {
- if ($this->global_config['misc']['disable_ipv6']) {
- throw new Exception('IPv6 is disabled.');
- } else {
- $commands[] = $vtysh.'show bgp ipv6 unicast '.$parameter.'"';
- }
+ $commands[] = $vtysh.'show bgp ipv6 unicast '.$parameter.'"';
} else if (match_ipv4($parameter, false)) {
- if ($this->global_config['misc']['disable_ipv4']) {
- throw new Exception('IPv4 is disabled.');
- } else {
- $commands[] = $vtysh.'show bgp ipv4 unicast '.$parameter.'"';
- }
+ $commands[] = $vtysh.'show bgp ipv4 unicast '.$parameter.'"';
} else {
throw new Exception('The parameter is not an IP address.');
}