summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/configuration.md21
-rw-r--r--execute.php8
-rw-r--r--includes/config.defaults.php22
-rw-r--r--index.php33
-rw-r--r--routers/bird.php8
-rw-r--r--routers/cisco.php8
-rw-r--r--routers/juniper.php8
-rw-r--r--routers/quagga.php8
-rw-r--r--routers/router.php4
9 files changed, 69 insertions, 51 deletions
diff --git a/docs/configuration.md b/docs/configuration.md
index 2483713..25f99b6 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -145,6 +145,17 @@ 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.
+```php
+$config['routers']['router1']['disable_ipv6'] = false;
+```
+If set to true, disable the use of IPv6 for the router.
+
+```php
+$config['routers']['router1']['disable_ipv4'] = false;
+```
+If set to true, disable the use of IPv4 for the router.
+
+
#### Telnet
```php
@@ -220,16 +231,6 @@ $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 227c6e6..7fd8fc6 100644
--- a/execute.php
+++ b/execute.php
@@ -54,15 +54,15 @@ if (isset($_POST['query']) && !empty($_POST['query']) &&
$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.';
+ if (match_ipv6($parameter) && $router->get_config()['disable_ipv6']) {
+ $error = 'IPv6 has been disabled for this router, 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.';
+ if (match_ipv4($parameter) && $router->get_config()['disable_ipv4']) {
+ $error = 'IPv4 has been disabled for this router, you can only use IPv6.';
print(json_encode(array('error' => $error)));
return;
}
diff --git a/includes/config.defaults.php b/includes/config.defaults.php
index dfc0d58..fa17f66 100644
--- a/includes/config.defaults.php
+++ b/includes/config.defaults.php
@@ -24,6 +24,22 @@
* Make changes to the configuration array in config.php.
*/
+function set_defaults_for_routers(&$parsed_config) {
+ $router_defaults = array(
+ 'disable_ipv6' => false,
+ 'disable_ipv4' => false
+ );
+
+ // Loads defaults when key does not exist
+ foreach ($parsed_config['routers'] as &$router) {
+ foreach ($router_defaults as $key => $value) {
+ if (!array_key_exists($key, $router)) {
+ $router[$key] = $value;
+ }
+ }
+ }
+}
+
$config = array(
// Release configuration
@@ -92,11 +108,7 @@ $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,
- // Disable IPv6
- 'disable_ipv6' => false,
- // Disable IPv4
- 'disable_ipv4' => false
+ 'allow_reserved_ip' => true
),
// Tools used for some processing
diff --git a/index.php b/index.php
index 5cef958..9b90915 100644
--- a/index.php
+++ b/index.php
@@ -30,6 +30,8 @@ final class LookingGlass {
private $routers;
function __construct($config) {
+ set_defaults_for_routers($config);
+
$this->release = $config['release'];
$this->frontpage = $config['frontpage'];
$this->contact = $config['contact'];
@@ -44,14 +46,24 @@ final class LookingGlass {
$first = true;
foreach (array_keys($this->routers) as $router) {
+ // IPv6 and IPv4 both disabled for the router, ignore it
+ if ($this->routers[$router]['disable_ipv6'] &&
+ $this->routers[$router]['disable_ipv4']) {
+ continue;
+ }
+
+ print('<option value="'.$router.'"');
if ($first) {
$first = false;
- print('<option value="'.$router.'" selected="selected">'.
- $this->routers[$router]['desc'].'</option>');
- } else {
- print('<option value="'.$router.'">'.$this->routers[$router]['desc'].
- '</option>');
+ print(' selected="selected"');
}
+ print('>'.$this->routers[$router]['desc']);
+ if ($this->routers[$router]['disable_ipv6']) {
+ print(' (IPv4 only)');
+ } else if ($this->routers[$router]['disable_ipv4']) {
+ print(' (IPv6 only)');
+ }
+ print('</option>');
}
print('</select>');
@@ -112,17 +124,6 @@ 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">&times;</button>');
print('<strong>Error!</strong>&nbsp;<span id="error-text"></span>');
diff --git a/routers/bird.php b/routers/bird.php
index 5219cc2..9a6c869 100644
--- a/routers/bird.php
+++ b/routers/bird.php
@@ -120,11 +120,11 @@ final class Bird extends Router {
case 'as-path-regex':
if (match_aspath_regex($parameter)) {
- if (!$this->global_config['misc']['disable_ipv6']) {
+ if (!$this->config['disable_ipv6']) {
$commands[] = $birdc6.' \'show route where bgp_path ~ [= '.
$parameter.' =]\'';
}
- if (!$this->global_config['misc']['disable_ipv4']) {
+ if (!$this->config['disable_ipv4']) {
$commands[] = $birdc.' \'show route where bgp_path ~ [= '.
$parameter.' =]\'';
}
@@ -135,11 +135,11 @@ final class Bird extends Router {
case 'as':
if (match_as($parameter)) {
- if (!$this->global_config['misc']['disable_ipv6']) {
+ if (!$this->config['disable_ipv6']) {
$commands[] = $birdc6.' \'show route where bgp_path ~ [= '.
$parameter.' =]\'';
}
- if (!$this->global_config['misc']['disable_ipv4']) {
+ if (!$this->config['disable_ipv4']) {
$commands[] = $birdc.' \'show route where bgp_path ~ [= '.
$parameter.' =]\'';
}
diff --git a/routers/cisco.php b/routers/cisco.php
index aee0b02..fe6c746 100644
--- a/routers/cisco.php
+++ b/routers/cisco.php
@@ -89,11 +89,11 @@ final class Cisco extends Router {
case 'as-path-regex':
if (match_aspath_regex($parameter)) {
- if (!$this->global_config['misc']['disable_ipv6']) {
+ if (!$this->config['disable_ipv6']) {
$commands[] = 'show bgp ipv6 unicast quote-regexp "'.$parameter.
'"';
}
- if (!$this->global_config['misc']['disable_ipv4']) {
+ if (!$this->config['disable_ipv4']) {
$commands[] = 'show bgp ipv4 unicast quote-regexp "'.$parameter.
'"';
}
@@ -104,11 +104,11 @@ final class Cisco extends Router {
case 'as':
if (match_as($parameter)) {
- if (!$this->global_config['misc']['disable_ipv6']) {
+ if (!$this->config['disable_ipv6']) {
$commands[] = 'show bgp ipv6 unicast quote-regexp "^'.$parameter.
'_"';
}
- if (!$this->global_config['misc']['disable_ipv4']) {
+ if (!$this->config['disable_ipv4']) {
$commands[] = 'show bgp ipv4 unicast quote-regexp "^'.$parameter.
'_"';
}
diff --git a/routers/juniper.php b/routers/juniper.php
index 3e04921..7ec2470 100644
--- a/routers/juniper.php
+++ b/routers/juniper.php
@@ -76,11 +76,11 @@ final class Juniper extends Router {
case 'as-path-regex':
if (match_aspath_regex($parameter)) {
- if (!$this->global_config['misc']['disable_ipv6']) {
+ if (!$this->config['disable_ipv6']) {
$commands[] = 'show route aspath-regex "'.$parameter.
'" protocol bgp table inet6.0';
}
- if (!$this->global_config['misc']['disable_ipv4']) {
+ if (!$this->config['disable_ipv4']) {
$commands[] = 'show route aspath-regex "'.$parameter.
'" protocol bgp table inet.0';
}
@@ -91,11 +91,11 @@ final class Juniper extends Router {
case 'as':
if (match_as($parameter)) {
- if (!$this->global_config['misc']['disable_ipv6']) {
+ if (!$this->config['disable_ipv6']) {
$commands[] = 'show route aspath-regex "^'.$parameter.
' .*" protocol bgp table inet6.0';
}
- if (!$this->global_config['misc']['disable_ipv4']) {
+ if (!$this->config['disable_ipv4']) {
$commands[] = 'show route aspath-regex "^'.$parameter.
' .*" protocol bgp table inet.0';
}
diff --git a/routers/quagga.php b/routers/quagga.php
index 01d4387..d451e94 100644
--- a/routers/quagga.php
+++ b/routers/quagga.php
@@ -119,10 +119,10 @@ final class Quagga extends Router {
case 'as-path-regex':
if (match_aspath_regex($parameter)) {
- if (!$this->global_config['misc']['disable_ipv6']) {
+ if (!$this->config['disable_ipv6']) {
$commands[] = $vtysh.'show ipv6 bgp regexp '.$parameter.'"';
}
- if (!$this->global_config['misc']['disable_ipv4']) {
+ if (!$this->config['disable_ipv4']) {
$commands[] = $vtysh.'show ip bgp regexp '.$parameter.'"';
}
} else {
@@ -132,10 +132,10 @@ final class Quagga extends Router {
case 'as':
if (match_as($parameter)) {
- if (!$this->global_config['misc']['disable_ipv6']) {
+ if (!$this->config['disable_ipv6']) {
$commands[] = $vtysh.'show ipv6 bgp regexp ^'.$parameter.'_'.'"';
}
- if (!$this->global_config['misc']['disable_ipv4']) {
+ if (!$this->config['disable_ipv4']) {
$commands[] = $vtysh.'show ip bgp regexp ^'.$parameter.'_'.'"';
}
} else {
diff --git a/routers/router.php b/routers/router.php
index f980982..6e564d6 100644
--- a/routers/router.php
+++ b/routers/router.php
@@ -112,6 +112,10 @@ abstract class Router {
protected abstract function build_commands($command, $parameter);
+ public function get_config() {
+ return $this->config;
+ }
+
public function send_command($command, $parameter) {
try {
$commands = $this->build_commands($command, $parameter);