Advertisement
Guest User

huawei.php looking glass

a guest
Apr 5th, 2020
895
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.57 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  * Looking Glass - An easy to deploy Looking Glass
  5.  * Copyright (C) 2014-2020 Guillaume Mazoyer <gmazoyer@gravitons.in>
  6.  *
  7.  * This program is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation; either version 3 of the License, or
  10.  * (at your option) any later version.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program; if not, write to the Free Software Foundation,
  19.  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
  20.  *
  21.  *
  22.  * Implementacao Huawei VRP by Alexandre J. Correa <ajcorrea@gmail.com> - 06/04/2020
  23. */
  24.  
  25. require_once('router.php');
  26. require_once('includes/command_builder.php');
  27. require_once('includes/utils.php');
  28.  
  29. class Huawei extends Router {
  30.   protected function build_bgp($parameter) {
  31.     $cmd = new CommandBuilder();
  32.     $cmd->add('display');
  33.  
  34.     if (match_ipv6($parameter, false)) {
  35.       $cmd->add('ipv6');
  36.     }
  37.     if (match_ipv4($parameter, false)) {
  38.       $cmd->add('ip');
  39.     }
  40.     $cmd->add('routing-table', $parameter);
  41.  
  42.     return array($cmd);
  43.   }
  44.  
  45.   protected function build_aspath_regexp($parameter) {
  46.     $parameter = quote($parameter);
  47.     $commands = array();
  48.     $cmd = new CommandBuilder();
  49.     $cmd->add('display bgp');
  50.  
  51.     if (!$this->config['disable_ipv6']) {
  52.       $commands[] = (clone $cmd)->add('ipv6 routing-table regular-expression', $parameter);
  53.     }
  54.     if (!$this->config['disable_ipv4']) {
  55.       $commands[] = (clone $cmd)->add('routing-table regular-expression', $parameter);
  56.     }
  57.  
  58.     return $commands;
  59.   }
  60.  
  61.   protected function build_as($parameter) {
  62.     $parameter = '^'.$parameter.'_';
  63.     return $this->build_aspath_regexp($parameter);
  64.   }
  65.  
  66.   protected function build_ping($parameter) {
  67.     if (!is_valid_destination($parameter)) {
  68.       throw new Exception('The parameter is not an IP address or a hostname.');
  69.     }
  70.  
  71.     $cmd = new CommandBuilder();
  72.     $cmd->add('ping -c 10 ');
  73.  
  74.     if ($this->has_source_interface_id()) {
  75.       $cmd->add('-a ', $this->get_source_interface_id());
  76.     }
  77.     $cmd->add($parameter);
  78.  
  79.     return array($cmd);
  80.   }
  81.  
  82.   protected function build_traceroute($parameter) {
  83.     if (!is_valid_destination($parameter)) {
  84.       throw new Exception('The parameter is not an IP address or a hostname.');
  85.     }
  86.  
  87.     $cmd = new CommandBuilder();
  88.     $cmd->add('tracert');
  89.  
  90.     if ($this->has_source_interface_id() && !match_ipv6($parameter)) {
  91.       $cmd->add('-a ', $this->get_source_interface_id());
  92.     }
  93.     if (match_ipv6($parameter) || match_ipv4($parameter) ||
  94.         !$this->has_source_interface_id()) {
  95.       $cmd->add($parameter);
  96.     } else {
  97.       // Resolve the hostname and go for right IP version
  98.       $hostname = $parameter;
  99.       $parameter = hostname_to_ip_address($hostname);
  100.  
  101.       if (!$parameter) {
  102.         throw new Exception('No record found for '.$hostname);
  103.       }
  104.  
  105.       if (match_ipv6($parameter)) {
  106.         $cmd->add('ipv6', (isset($hostname) ? $hostname : $parameter));
  107.       }
  108.       if (match_ipv4($parameter)) {
  109.         $cmd->add((isset($hostname) ? $hostname : $parameter));
  110.       }
  111.     }
  112.  
  113.     // Make sure to use the right source interface
  114.  
  115.     return array($cmd);
  116.   }
  117. }
  118.  
  119. // End of huawei.php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement