. * * @package LibreNMS * @link http://librenms.org * @copyright 2018 Neil Lathwood * @author Neil Lathwood */ $asn = clean($vars['asn']); $ixid = clean($vars['ixid']); $status = clean($vars['status']); $sql = " FROM `pdb_ix_peers` AS `P` LEFT JOIN `pdb_ix` ON `P`.`ix_id` = `pdb_ix`.`ix_id` LEFT JOIN `bgpPeers` ON `P`.`remote_ipaddr4` = `bgpPeers`.`bgpPeerIdentifier` WHERE `P`.`ix_id` = ? AND `remote_ipaddr4` IS NOT NULL"; $params = array($ixid); if ($status === 'connected') { $sql .= " AND `remote_ipaddr4` = `bgpPeerIdentifier` "; } if ($status === 'unconnected') { $sql .= " AND `bgpPeerRemoteAs` IS NULL "; } if (isset($searchPhrase) && !empty($searchPhrase)) { $sql .= " AND (`remote_ipaddr4` LIKE '%$searchPhrase%' OR `remote_asn` LIKE '%$searchPhrase%' OR `P`.`name` LIKE '%$searchPhrase%')"; } $sql .= ' GROUP BY `bgpPeerIdentifier`, `P`.`name`, `P`.`remote_ipaddr4`, `P`.`peer_id`, `P`.`remote_asn` '; $count_sql = "SELECT COUNT(*) $sql"; $total = count(dbFetchRows($count_sql, $params)); if (empty($total)) { $total = 0; } if (!isset($sort) || empty($sort)) { $sort = 'remote_asn ASC'; } $sql .= " ORDER BY $sort"; if (isset($current)) { $limit_low = (($current * $rowCount) - ($rowCount)); $limit_high = $rowCount; } if ($rowCount != -1) { $sql .= " LIMIT $limit_low,$limit_high"; } $sql = "SELECT `P`.`remote_asn`, `P`.`name`, `P`.`remote_ipaddr4`, `P`.`peer_id`, `bgpPeers`.`bgpPeerIdentifier` $sql"; foreach (dbFetchRows($sql, $params) as $peer) { if ($peer['remote_ipaddr4'] === $peer['bgpPeerIdentifier']) { $connected = ''; } else { $connected = ''; } $peer_id = $peer['peer_id']; $response[] = array( 'remote_asn' => $peer['remote_asn'], 'remote_ipaddr4' => $peer['remote_ipaddr4'], 'peer' => $peer['name'], 'connected' => "$connected", 'links' => "", ); } $output = array( 'current' => $current, 'rowCount' => $rowCount, 'rows' => $response, 'total' => $total, ); echo _json_encode($output);