Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $queryReachableAPs = array(
- "reachabilityStatus" => "REACHABLE",
- "unifiedApInfo.primaryMwar" => "WLC-Name",
- "locationHierarchy" => "notStartsWith(Root)",
- "unifiedApInfo.maintenanceMode" => "ne(TRUE)"
- );
- $queryReachableAPsJson = callPrimeAPI('AccessPointDetails.json?', $queryReachableAPs);
- if ($queryReachableAPsJson) {
- $countReachableAPs = $queryReachableAPsJson->{'queryResponse'}->{'@count'};
- if ($countReachableAPs > 0) {
- $primeListHTML .= "<div class='list-group-item greenStyle d-flex align-items-center'><span>$upImage</span>$countReachableAPs APs Up</div>";
- }
- // Could do a debug here to see all avialable info (debug($queryReachableAPsJson);)
- }
- function debug($input)
- {
- #debug_print_backtrace();
- if (is_string($input)) {
- echo nl2br($input);
- } else {
- var_dump($input);
- }
- }
- function callPrimeAPI($primeAPIResource, $queryArray)
- {
- include ($_SERVER['DOCUMENT_ROOT'] . '/include/integeration.php');
- $primeURL = "";
- if ($queryArray) {
- // Web escape the URL
- $primeWebAddress = "https://yourprime.yournet.net";
- $primeAPIAddress = "$primeWebAddress/webacs/api/v4/data/";
- $primeURL = $primeAPIAddress . $primeAPIResource . http_build_query($queryArray);
- } else {
- // If no query params are given, assign it's a direct resource URL
- $primeURL = $primeAPIResource;
- }
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
- $primeAuthData = "$primeAPIUsername:$primeAPIPassword";
- curl_setopt($curl, CURLOPT_USERPWD, $primeAuthData);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
- curl_setopt($curl, CURLOPT_TIMEOUT, 3);
- $curlHeaders = [
- "Accept: application/json"
- ];
- curl_setopt($curl, CURLOPT_HTTPHEADER, $curlHeaders);
- curl_setopt($curl, CURLOPT_URL, $primeURL);
- $primeResult = curl_exec($curl);
- $jsonResult = null;
- if (! $primeResult) {
- debug("Error contacting Prime API");
- return false;
- } else {
- $responseCode = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
- if ($responseCode === 200) {
- $jsonResult = json_decode($primeResult);
- return $jsonResult;
- } else {
- debug("Prime invalid response code. Code returned: $responseCode");
- return false;
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement