Skip to content

Instantly share code, notes, and snippets.

@pjaudiomv
Last active November 13, 2018 23:17
Show Gist options
  • Save pjaudiomv/eefb84bb49c1f808e16db2766ce34476 to your computer and use it in GitHub Desktop.
Save pjaudiomv/eefb84bb49c1f808e16db2766ce34476 to your computer and use it in GitHub Desktop.
Get and check api keys form all know bmlt root servers
<?php
$rootServerList = json_decode(file_get_contents('https://raw.githubusercontent.com/LittleGreenViper/BMLTTally/master/rootServerList.json'), true);
foreach ($rootServerList as $rootServer) {
echo "<strong>Name:</strong> " . $rootServer['name'] . "<br>";
echo "<strong>Root URL:</strong> " . $rootServer['rootURL'] . "<br>";
echo "<strong>Google API Key:</strong> ";
$getGkeys = json_decode(file_get_contents($rootServer['rootURL'] . 'client_interface/json/?switcher=GetServerInfo'), true);
for ( $i = 0; $i < count( $getGkeys ); $i++ ) {
echo $getGkeys[$i]['google_api_key'] . "<br>";
echo "<strong>Status:</strong> " . checkGkey($getGkeys[$i]['google_api_key']);
echo "<br><br>";
}
}
function checkGkey($google_maps_api_key) {
$googleapi_settings = json_decode(file_get_contents("https://maps.googleapis.com/maps/api/geocode/json?key=" . trim($google_maps_api_key) . "&address=91409"));
$timezone_settings = json_decode(file_get_contents("https://maps.googleapis.com/maps/api/timezone/json?key=" . trim($google_maps_api_key) . "&location=34.2011137,-118.475058&timestamp=" . time()));
$keystatus = '';
if (isset($google_maps_api_key) && $googleapi_settings->status == "REQUEST_DENIED") {
$keystatus .= "Your Google Maps API key came back with the following error. " .$googleapi_settings->error_message. " Please make sure you have the \"Google Maps Geocoding API\" enabled and that the API key is entered properly and has no referer restrictions. You can check your key at the Google API console <a target=\"_blank\" href=\"https://console.cloud.google.com/apis/\">here</a><br><br>";
}
else if ($googleapi_settings->status == "OK") {
$keystatus .= "Your Google Key for Geocoding API seems to be working fine! :)<br><br>";
}
if (isset($google_maps_api_key) && $timezone_settings->status == "REQUEST_DENIED") {
$keystatus .= "Your Google Maps API key came back with the following error. " .$timezone_settings->errorMessage. " Please make sure you have the \"Google Time Zone API\" enabled and that the API key is entered properly and has no referer restrictions. You can check your key at the Google API console <a target=\"_blank\" href=\"https://console.cloud.google.com/apis/\">here</a><br><br>";
}
else if ($timezone_settings->status == "OK") {
$keystatus .= "Your Google Key for Time Zone API seems to be working fine! :)<br><br>";
}
else if (empty($google_maps_api_key)) {
$keystatus .= "No Key";
}
return $keystatus;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment