summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
Diffstat (limited to 'includes')
-rw-r--r--includes/config.defaults.php56
-rw-r--r--includes/utils.php99
2 files changed, 155 insertions, 0 deletions
diff --git a/includes/config.defaults.php b/includes/config.defaults.php
new file mode 100644
index 0000000..895810b
--- /dev/null
+++ b/includes/config.defaults.php
@@ -0,0 +1,56 @@
+<?php
+
+$config = array (
+
+ // Frontpage configuration
+ 'frontpage' => array (
+ // CSS to use
+ 'css' => 'css/style.css',
+ // Title of the page
+ 'title' => 'Looking Glass',
+ 'show_title' => true,
+ // Show visitor IP address
+ 'show_visitor_ip' => true,
+ // Frontpage order you can use: routers, commands, parameters, buttons
+ 'order' => array('routers', 'commands', 'parameters', 'buttons')
+ ),
+
+ // Misc
+ 'misc' => array(
+ // Logs file when commands will be written
+ 'logs' => '/var/log/looking-glass.log',
+ // Allow private ASN
+ 'allow_private_asn' => false
+ ),
+
+ // Documentation (must be HTML)
+ 'doc' => array (
+ // Documentation for the 'show route' query
+ 'bgp' => array(
+ 'query' => 'Show the best routes to a given destination.',
+ 'parameter' => 'The parameter must be a valid destination. Destination means an IPv4/IPv6 address or a subnet. Masks are also accepted as part of a valid IPv4/IPv6 address.<br />Please note that some routers always need a mask to be given when looking for an IPv6 address.<br /><br />Example of valid arguments:<br /><ul><li>10.1.1.1</li><li>172.16.0.0/12</li><li>2001:db8:1337::42</li><li>2001:db8::/32</li>'
+ ),
+ // Documentation for the 'as-path-regex' query
+ 'as-path-regex' => array(
+ 'query' => 'Show the routes matching the given AS path regular expression.',
+ 'parameter' => 'The parameter must be a valid AS path regular expression.<br />Please note that these expression can change depending on the router and its software.<br /><br />Here are some examples:<ul><li><strong>Juniper</strong> - ^AS1 AS2 .*$</li><li><strong>Cisco</strong> - ^AS1_</li><li><strong>BIRD</strong> - AS1 AS2 AS3 &hellip; ASZ</li></ul><br />You may find some help with the following link:<br /><ul><li><a href="http://www.juniper.net/techpubs/en_US/junos13.3/topics/reference/command-summary/show-route-aspath-regex.html" title="Juniper Documentation">Juniper Documentation</a></li><li><a href="http://www.cisco.com/c/en/us/support/docs/ip/border-gateway-protocol-bgp/26634-bgp-toc.html#asregexp" title="Cisco Documentation">Cisco Documentation</a></li><li><a href="http://bird.network.cz/?get_doc&f=bird-5.html" title="BIRD Documentation">BIRD Documentation</a> (search for bgpmask)</li></ul>'
+ ),
+ // Documentation for the 'as' query
+ 'as' => array(
+ 'query' => 'Show the routes received from a given AS number.',
+ 'parameter' => 'The parameter must be a valid 16-bit or 32-bit autonomous system number.<br />Be careful, 32-bit ASN are not handled by old routers or old router softwares.<br />Unless specified, private ASN will be considered as invalid.<br /><br />Example of valid argument:<br /><ul><li>15169</li><li>29467</li></ul>'
+ ),
+ // Documentation for the 'ping' query
+ 'ping' => array(
+ 'query' => 'Send 10 pings to the given destination.',
+ 'parameter' => 'The parameter must be an IPv4/IPv6 address (without mask) or a fully qualified domain name.<br /><br />Example of valid arguments:<br /><ul><li>10.1.1.1</li><li>2001:db8:1337::42</li><li>example.com</li></ul>'
+ ),
+ // Documentation for the 'traceroute' query
+ 'traceroute' => array(
+ 'query' => 'Display the path to a given destination.',
+ 'parameter' => 'The parameter must be an IPv4/IPv6 address (without mask) or a fully qualified domain name.<br /><br />Example of valid arguments:<br /><ul><li>10.1.1.1</li><li>2001:db8:1337::42</li><li>example.com</li></ul>'
+ )
+ )
+);
+
+// End of config.defaults..php
diff --git a/includes/utils.php b/includes/utils.php
new file mode 100644
index 0000000..b6fc061
--- /dev/null
+++ b/includes/utils.php
@@ -0,0 +1,99 @@
+<?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 'config.php';
+
+function match_ipv4($ip, $ip_only = true) {
+ if (strrpos($ip, '/') && !$ip_only) {
+ $ip_and_mask = explode('/', $ip, 2);
+
+ return filter_var($ip_and_mask[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) &&
+ filter_var($ip_and_mask[1], FILTER_VALIDATE_INT);
+ } else {
+ return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
+ }
+}
+
+function match_ipv6($ip, $ip_only = true) {
+ if (strrpos($ip, '/') && !$ip_only) {
+ $ip_and_mask = explode('/', $ip, 2);
+
+ return filter_var($ip_and_mask[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) &&
+ filter_var($ip_and_mask[1], FILTER_VALIDATE_INT);
+ } else {
+ return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
+ }
+}
+
+function match_fqdn($fqdn) {
+ $regex = '/(?=^.{4,255}$)(^((?!-)[a-zA-Z0-9-]{1,63}(?<!-)\.)+[a-zA-Z]{2,63}$)/';
+
+ if ((preg_match($regex, $fqdn) === false) ||
+ (preg_match($regex, $fqdn) === 0)) {
+ return false;
+ } else {
+ return true;
+ }
+}
+
+function match_as($as) {
+ global $config;
+
+ $options_wide_range = array(
+ 'options' => array('min_range' => 1, 'max_range' => 4294967294)
+ );
+ $options_16bit_private = array(
+ 'options' => array( 'min_range' => 64512, 'max_range' => 65534)
+ );
+ $options_32bit_private = array(
+ 'options' => array('min_range' => 4200000000, 'max_range' => 4294967294)
+ );
+
+ if (!filter_var($as, FILTER_VALIDATE_INT, $options_wide_range)) {
+ return false;
+ }
+
+ if (filter_var($as, FILTER_VALIDATE_INT, $options_16bit_private)) {
+ return isset($config['misc']['allow_private_asn']) &&
+ $config['misc']['allow_private_asn'] == true;
+ }
+
+ if (filter_var($as, FILTER_VALIDATE_INT, $options_32bit_private)) {
+ return isset($config['misc']['allow_private_asn']) &&
+ $config['misc']['allow_private_asn'] == true;
+ }
+
+ return true;
+}
+
+function match_aspath_regex($aspath_regex) {
+ // TODO: validate a regex with a regex?
+ return true;
+}
+
+function log_to_file($log) {
+ global $config;
+
+ $log = '['.date("Y-m-d H:i:s").'] '.$log."\n";
+ file_put_contents($config['misc']['logs'], $log, FILE_APPEND | LOCK_EX);
+}
+
+// End of utils.php