diff --git a/htdocs/index.php b/htdocs/index.php index 4bd9a1b..fcc4a9a 100644 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -90,6 +90,22 @@ $query = isset($_REQUEST['query']) ? trim($_REQUEST['query']) : FALSE; $token = isset($_REQUEST['token']) ? trim($_REQUEST['token']) : FALSE; +# Check if client IP is within safe subnets + +$ipsafe = false; +if(isset($_CONFIG['safesubnets']) AND ! empty($_CONFIG['safesubnets'])) +{ + foreach($_CONFIG['safesubnets'] as $safesubnet) + { + if(! empty($safesubnet)) + { + if(checkIP($_SERVER['REMOTE_ADDR'], $safesubnet)) + { + $ipsafe = true; + } + } + } +} if ($command != 'graph' OR !isset($_REQUEST['render']) OR !isset($_CONFIG['routers'][$router])) { @@ -136,7 +152,7 @@ function load() { } //--> - + "; @@ -1170,33 +1171,13 @@ function parse_out($output, $check = FALSE) { $data_exp = explode(' ', trim($summary_part), 3); - if(!$ipsafe){ - $summary_part = preg_replace("/\svia\s\s?\S+/x", "", $summary_part); - } - $matches = null; - preg_match('/bgp-as-path\=\"([^\"]+)\"/', $summary_part, $matches); - if(! empty($matches[1])){ - $aspathmatches = array(); - $aspathOriginal = $matches[0]; - $aspathOriginal = str_replace('"', '\"', $aspathOriginal); - $summary_part = str_replace($matches[0], $aspathOriginal, $summary_part); - $aspath = $aspathOriginal; - preg_match_all("/((?:\d+)+)/", $aspath, $matches); - $asns = null; - $asns = $matches[1]; - $matchCount = 0; - if(! empty($asns)){ - foreach($matches[1] as $m){ - if(empty($aspathmatches[$m])){ - $aspathmatches[$m] = link_as($m); - } - } - if(!empty($aspathmatches)){ - $aspath = str_replace(array_keys($aspathmatches), array_values($aspathmatches), $aspath); - $summary_part = str_replace($aspathOriginal, stripslashes($aspath), $summary_part); - } - } - } + $summary_part = preg_replace_callback( + "/bgp-as-path=\"([^\"]+)\"/x", + function ($matches) { + return stripslashes('bgp-as-path=\"'.link_as($matches[1]).'\"'); + }, + $summary_part + ); if (strpos($data_exp[1], 'A') !== FALSE) { @@ -1383,12 +1364,12 @@ function ($matches) { } else { - #$radb = get_radb($exp[1]); - $asn = get_as($exp[1], "15835"); + $radb = get_radb($exp[1]); + $new_exp[1] = get_ptr($exp[1]); $new_exp[2] = '('.$exp[1].')'; - #$new_exp[3] = '['.(isset($radb['origin']) ? 'AS '.link_as($radb['origin']) : '').']'; - $new_exp[3] = $asn; + $new_exp[3] = '['.(isset($radb['origin']) ? 'AS '.link_as($radb['origin']) : '').']'; + $new_exp[4] = $exp[5].'ms'; $new_exp[5] = $exp[6].'ms'; $new_exp[6] = $exp[7].'ms'; @@ -2597,40 +2578,9 @@ function link_as($line, $word = FALSE, $type = null) { global $_CONFIG; - $asn = intval(preg_replace("/(?:AS)?([\d]+)/is", - "$1", $line)); - - $url = null; - $publicasn = false; - if(($asn >= 1 AND $asn <= 23455) OR ($asn >= 23457 AND $asn <= 64495) OR ($asn >= 131072 AND $asn <= 4199999999)){ - $publicasn = true; - } - - if($word) - { - $asnword = "AS" . $asn; - } - else - { - $asnword = $asn; - } + return preg_replace("/(?:AS)?([\d]+)/is", + "".($word ? 'AS' : '')."\\1", $line); - if($publicasn AND $type == "url") - { - return htmlspecialchars($_CONFIG['aswhois']) . "AS" . $asn; - } - elseif($publicasn) - { - return '' . $asnword . ''; - } - elseif($type == "url") - { - return null; - } - else - { - return $asnword; - } } function get_as($ip, $original_as)