Skip to content

Instantly share code, notes, and snippets.

@JoelLisenby
Last active May 24, 2023 00:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoelLisenby/56b813ceee19b737684be2949b4575a9 to your computer and use it in GitHub Desktop.
Save JoelLisenby/56b813ceee19b737684be2949b4575a9 to your computer and use it in GitHub Desktop.
<?php
// Example run:
// php -f get_wpengine_installs_status.php > installs.csv
//
// acquire your username and password from https://my.wpengine.com/profile/api_access
define('API_USERNAME','');
define('API_PASSWORD','');
$result_obj = run_query( 'https://api.wpengineapi.com/v1/installs' );
$runs = 1;
$advanced_network_ips = array( '141.193.213.10', '141.193.213.11' );
echo 'name,primary domain,base domain,dns a records,dns ns records,advanced network,cname,php,multisite'."\r\n";
while( !empty( $result_obj->next ) && $runs < 2000 ) {
foreach( $result_obj->results as $install ) {
if( $install->environment == 'production' && $install->status == 'active' ) {
$base_domain = get_base_domain( $install->primary_domain );
echo $install->name .',';
echo $install->primary_domain .',';
echo $base_domain .',';
$dns_records_a = dns_get_record( $install->primary_domain, DNS_A );
$a_record_ips = array();
$cnt = 0;
foreach( $dns_records_a as $dns_record_a ) {
$cnt++;
echo $dns_record_a['ip'].($cnt < count( $dns_records_a ) ? '|' : '' );
$a_record_ips[] = trim( $dns_record_a['ip'] );
}
echo ",";
$dns_records_ns = dns_get_record( $base_domain, DNS_NS );
$ns_record_hosts = array();
$cnt = 0;
foreach( $dns_records_ns as $dns_record_ns ) {
$cnt++;
echo $dns_record_ns['target'].($cnt < count( $dns_records_ns ) ? '|' : '' );
$a_record_hosts[] = trim( $dns_record_ns['target'] );
}
echo ",";
echo jbl_in_array( $a_record_ips, $advanced_network_ips ) .',';
echo $install->cname .',';
echo $install->php_version .',';
echo $install->is_multisite .',';
echo "\r\n";
}
}
$result_obj = run_query( $result_obj->next );
$runs++;
}
function get_base_domain( $input ) {
$tlds = array( 'com', 'co.uk', 'co.au', 'net', 'us', 'org', 'vet', 'games', 'jp', 'edu', 'life', 'io', 'co.jp', 'biz', 'glass', 'me', 'bio', 'ai', 'info' );
$base_domain = "";
$hostData = explode( '.', $input );
$hostData = array_reverse( $hostData );
if( array_search($hostData[1] . '.' . $hostData[0], $tlds) !== false ) {
$base_domain = $hostData[2] . '.' . $hostData[1] . '.' . $hostData[0];
} else if( array_search($hostData[0], $tlds) !== false ) {
$base_domain = $hostData[1] . '.' . $hostData[0];
}
return $base_domain;
}
function jbl_in_array( $needles, $haystack ) {
$output = 0;
foreach( $needles as $needle ) {
foreach( $haystack as $hay ) {
if( $needle == $hay ) {
$output = 1;
}
}
}
return $output;
}
function run_query( $url ) {
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'GET' );
$headers = array();
$cred_string = API_USERNAME .":". API_PASSWORD;
$headers[] = "Authorization: Basic " . base64_encode($cred_string);
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
$result = curl_exec( $ch );
if ( curl_errno( $ch ) ) {
echo 'Error:' . curl_error( $ch );
return false;
}
curl_close( $ch );
return json_decode( $result );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment