Skip to content

Commit

Permalink
Merge pull request hsdn#7 from hsdn/master
Browse files Browse the repository at this point in the history
Merg into test branch
  • Loading branch information
mrjwilz authored Jan 25, 2023
2 parents 679998d + e4d84d3 commit 5cfd696
Showing 1 changed file with 50 additions and 14 deletions.
64 changes: 50 additions & 14 deletions htdocs/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ function load() {
(
'bgp' => 'display bgp routing-table %s',
'advertised-routes' => 'display bgp routing-table peer %s advertised-routes',
'bgp-within' => 'display bgp routing-table community | include %s',
'received-routes' => 'display bgp routing-table peer %s received-routes',
'routes' => 'display bgp routing-table peer %s received-routes active',
'summary' => 'display bgp peer',
Expand Down Expand Up @@ -370,6 +371,8 @@ function load() {

$url = @parse_url($url);

$routing_instance = $_CONFIG['routers'][$router]['routing-instance'];

$os = $_CONFIG['routers'][$router]['os'];

if ($command == 'graph' AND isset($queries[$os][$protocol]['bgp']))
Expand Down Expand Up @@ -445,47 +448,55 @@ function load() {
if ($os == 'junos')
{
// @see JunOS Routing Table Names (http://www.net-gyver.com/?p=602)
$table = ($protocol == 'ipv6') ? 'inet6.0' : 'inet.0';
if ($routing_instance){
$table = ($protocol == 'ipv6') ? $routing_instance.'.inet6.0' : $routing_instance.'.inet.0';
}else{
$table = ($protocol == 'ipv6') ? 'inet6.0' : 'inet.0';
}

if (preg_match("/^show bgp n\w*\s+([\d\.A-Fa-f:]+)$/", $exec, $exec_exp))
{
$exec = 'show bgp neighbor '.$exec_exp[1];
if ($routing_instance){
$exec = 'show bgp neighbor instance '.$routing_instance.' '.$exec_exp[1];
}else{
$exec = 'show bgp neighbor '.$exec_exp[1];
}
}
else if (preg_match("/^show bgp n\w*\s+([\d\.A-Fa-f:]+) ro\w*$/", $exec, $exec_exp))
{
$exec = 'show route receive-protocol bgp '.$exec_exp[1];
$exec = 'show route receive-protocol bgp '.$exec_exp[1]." table ".$table;
}
else if (preg_match("/^show bgp neighbors ([\d\.A-Fa-f:]+) routes all$/", $exec, $exec_exp))
{
$exec = 'show route receive-protocol bgp '.$exec_exp[1].' all';
$exec = 'show route receive-protocol bgp '.$exec_exp[1].' table '.$table.' all';
}
else if (preg_match("/^show bgp neighbors ([\d\.A-Fa-f:]+) routes damping suppressed$/", $exec, $exec_exp))
{
$exec = 'show route receive-protocol bgp '.$exec_exp[1].' damping suppressed';
$exec = 'show route receive-protocol bgp '.$exec_exp[1].' table '.$table.' damping suppressed';
}
else if (preg_match("/^show bgp n\w*\s+([\d\.A-Fa-f:]+) advertised-routes ([\d\.A-Fa-f:\/]+)$/", $exec, $exec_exp))
{
$exec = 'show route advertising-protocol bgp '.$exec_exp[1].' '.$exec_exp[2].' exact detail';
$exec = 'show route advertising-protocol bgp '.$exec_exp[1].' '.$exec_exp[2].' table '.$table.' exact detail';
}
else if (preg_match("/^show bgp n\w*\s+([\d\.A-Fa-f:]+) receive-protocol ([\d\.A-Fa-f:\/]+)$/", $exec, $exec_exp))
{
$exec = 'show route receive-protocol bgp '.$exec_exp[1].' '.$exec_exp[2].' exact detail';
$exec = 'show route receive-protocol bgp '.$exec_exp[1].' '.$exec_exp[2].' table '.$table.' exact detail';
}
else if (preg_match("/^show bgp n\w*\s+([\d\.A-Fa-f:]+) a[\w\-]*$/", $exec, $exec_exp))
{
$exec = 'show route advertising-protocol bgp '.$exec_exp[1];
$exec = 'show route advertising-protocol bgp '.$exec_exp[1].' table '.$table;
}
else if (preg_match("/^show bgp\s+([\d\.A-Fa-f:]+\/\d+)$/", $exec, $exec_exp))
{
$exec = 'show route protocol bgp '.$exec_exp[1].' terse exact';
$exec = 'show route protocol bgp '.$exec_exp[1].' table '.$table.' terse exact';
}
else if (preg_match("/^show bgp\s+([\d\.A-Fa-f:]+)$/", $exec, $exec_exp))
{
$exec = 'show route protocol bgp '.$exec_exp[1].' table '.$table;
}
else if (preg_match("/^show bgp\s+([\d\.A-Fa-f:\/]+) exact$/", $exec, $exec_exp))
{
$exec = 'show route protocol bgp '.$exec_exp[1].' exact detail all';
$exec = 'show route protocol bgp '.$exec_exp[1].' table '.$table.' exact detail all';
}
else if (preg_match("/^show bgp re\s+(.*)$/", $exec, $exec_exp))
{
Expand All @@ -501,8 +512,33 @@ function load() {
$re = $re.".*\$";
}

$exec = 'show route aspath-regex "'.str_replace('_', ' ', $re).'" all';
if ($routing_instance){
$exec = 'show route instance '.$routing_instance.' aspath-regex "'.str_replace('_', ' ', $re).'" all';
}else{
$exec = 'show route aspath-regex "'.str_replace('_', ' ', $re).'" all';
}
}
else if (preg_match("/^show bgp summary$/", $exec, $exec_exp))
{
if ($routing_instance){
$exec = 'show bgp summary instance '.$routing_instance;
}else{
$exec = 'show bgp summary';
}
}
else if (preg_match("/^show route advertising-protocol bgp\s+([\d\.A-Fa-f:\/]+)$/", $exec, $exec_exp))
{
$exec = 'show route advertising-protocol bgp '.$exec_exp[1].' table '.$table;
}
else if (preg_match("/^traceroute (ip|ipv6) ([\d\.A-Fa-f:\/]+)$/", $exec, $exec_exp))
{
if ($routing_instance){
$exec = 'traceroute '.$exec_exp[1].' routing-instance '.$routing_instance.' '.$exec_exp[2];
}else{
$exec = 'traceroute '.$exec_exp[1].' '.$exec_exp[2];
}
}

}

if ($command == 'graph')
Expand Down Expand Up @@ -1489,7 +1525,7 @@ function ($matches) use ($lastip) {
return $output;
}

if ($exec == 'show bgp summary')
if (preg_match("/^show bgp summary(?:\s+instance\s+[\d\w-]*)?$/", $exec))
{
// JunOS
if (preg_match("/^([\dA-Fa-f:][\d\.A-Fa-f:]+)\s+/", $output, $lastip_exp))
Expand Down Expand Up @@ -1655,7 +1691,7 @@ function ($matches) {
}

// JunOS
if (preg_match("/^show route advertising-protocol bgp\s+([\d\.A-Fa-f:]+)$/i", $exec, $ip_exp))
if (preg_match("/^show route advertising-protocol bgp\s+([\d\.A-Fa-f:]+)(?:\s+table\s+[\d\w\-\.]*)?$/i", $exec, $ip_exp))
{
$ip = $ip_exp[1];

Expand Down Expand Up @@ -1862,7 +1898,7 @@ function ($matches) {
return $output;
}

if (preg_match("/^show bgp n\w*\s+([\d\.A-Fa-f:]+)/i", $exec, $ip_exp))
if (preg_match("/^show bgp n\w*\s+(?:instance\s+[\d\w-]*)?\s*([\d\.A-Fa-f:]+)/i", $exec, $ip_exp))
{
$ip = $ip_exp[1];

Expand Down

0 comments on commit 5cfd696

Please sign in to comment.