Created
November 15, 2022 12:24
-
-
Save maplerock/085856a9b23fc83b7b0598b334c9794b to your computer and use it in GitHub Desktop.
Export DNS Zone file from Cpanel using Laravel/HTTP client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//You'll need to create an API key on WHM (https://api.docs.cpanel.net/whm/tokens/) | |
$user = ""; | |
$key = ""; | |
$domain = "yourdomain.com"; | |
$saveTo = ""; | |
$url = "https://YOUR_SERVER_IP:2087/json-api/json-api/export_zone_files?api.version=1&zone={$domain}"; | |
$response = Http::withHeaders([ | |
'Authorization' => "whm {$user}:{$key}" | |
])->withOptions(["verify"=>false])->get($url); | |
$response_json = $response->json(); | |
$zones = collect($response_json['data']['payload']); | |
$zone = $zones->where('zone',$domain)->first(); | |
$content = base64_decode($zone['text_b64']); | |
$targetPath = "{$saveTo}/{$domain}.txt"; | |
$file = fopen($targetPath, 'w'); | |
fwrite($file, $content); | |
fclose($file); | |
echo "File saved to {$targetPath}"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment