2017-03-22 10:17:13 +00:00
< ? php
2020-07-10 16:17:09 +02:00
$param = [];
2017-03-22 10:17:13 +00:00
// Exclude Private and reserved ASN ranges
2023-10-04 17:07:14 +02:00
// 64512 - 65534 (Private)
// 65535 (Well Known)
// 4200000000 - 4294967294 (Private)
// 4294967295 (Reserved)
2017-03-22 10:17:13 +00:00
$sql = ' FROM `devices` WHERE `disabled` = 0 AND `ignore` = 0 AND `bgpLocalAs` > 0 AND (`bgpLocalAs` < 64512 OR `bgpLocalAs` > 65535) AND `bgpLocalAs` < 4200000000 ' ;
if ( isset ( $searchPhrase ) && ! empty ( $searchPhrase )) {
2020-07-10 16:17:09 +02:00
$sql .= ' AND (`bgpLocalAs` LIKE ?)' ;
$param [] = " % $searchPhrase % " ;
2017-03-22 10:17:13 +00:00
}
$count_sql = " SELECT COUNT(*) $sql " ;
2020-07-10 16:17:09 +02:00
$total = dbFetchCell ( $count_sql , $param );
2017-03-22 10:17:13 +00:00
if ( empty ( $total )) {
$total = 0 ;
}
if ( ! isset ( $sort ) || empty ( $sort )) {
$sort = 'bgpLocalAs ASC' ;
}
$sql .= " GROUP BY `bgpLocalAs` ORDER BY $sort " ;
if ( isset ( $current )) {
2023-03-13 22:32:22 +01:00
$limit_low = (( $current * $rowCount ) - $rowCount );
2017-03-22 10:17:13 +00:00
$limit_high = $rowCount ;
}
if ( $rowCount != - 1 ) {
$sql .= " LIMIT $limit_low , $limit_high " ;
}
$sql = " SELECT `bgpLocalAs` $sql " ;
2020-07-10 16:17:09 +02:00
foreach ( dbFetchRows ( $sql , $param ) as $asn ) {
2023-10-04 10:17:34 -05:00
$astext = \LibreNMS\Util\AutonomousSystem :: get ( $asn [ 'bgpLocalAs' ]) -> name ();
2017-03-22 10:17:13 +00:00
$response [] = [
2024-01-05 05:39:12 +01:00
'bgpLocalAs' => $asn [ 'bgpLocalAs' ],
2017-03-22 10:17:13 +00:00
'asname' => $astext ,
2021-03-28 17:25:30 -05:00
'action' => " <a class='btn btn-sm btn-primary' href=' " . \LibreNMS\Util\Url :: generate ([ 'page' => 'peering' , 'section' => 'ix-list' , 'bgpLocalAs' => $asn [ 'bgpLocalAs' ]]) . " ' role='button'>Show connected IXes</a> " ,
2017-03-22 10:17:13 +00:00
];
}
$output = [
2024-01-05 05:39:12 +01:00
'current' => $current ,
2017-03-22 10:17:13 +00:00
'rowCount' => $rowCount ,
2024-01-05 05:39:12 +01:00
'rows' => $response ,
'total' => $total ,
2017-03-22 10:17:13 +00:00
];
2021-03-04 07:55:41 -06:00
echo json_encode ( $output , JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );