-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzone-downloader.php
62 lines (55 loc) · 1.58 KB
/
zone-downloader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* @var string $username
* @var string $password
* @var string $targetAccount
*/
use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions;
require './config.php';
require 'vendor/autoload.php';
if (empty($argv[1])) {
echo "usage: php -f zone-downloader.php zone.com\n";
echo "error: need a zone parameter\n";
die("execution aborted!\n");
}
// get zone from API
$body = <<<END
{
"Transaction":{
"Username":"$username",
"Password":"$password",
"TargetAccount":"$targetAccount",
"ClientTransactionId":"not applicable"
},
"Zone":"$argv[1]"
}
END;
$httpClient = new Client();
$response = $httpClient->post(
'https://service.partner4trade.de/live/domain.svc/rest/DnsZoneDetail',
[
RequestOptions::BODY => $body,
RequestOptions::HEADERS => [
'Content-Type' => 'application/json',
'Accept' => 'application/json'
]
]
);
$result_array = json_decode($response->getBody()->getContents(), true);
if ($result_array['Result']['Code'] != "15000") die ("Download of zone failed!\n");
$zone_file_array = [
"Transaction" => [
"Username" => "{Username}",
"Password" => "{Password}",
"TargetAccount" => "{TargetAccount}",
"ClientTransactionId" => "not applicable"
],
"Email" => $result_array['Email'],
"Primary" => $result_array['Primary'],
"Records" => $result_array['Records'],
"Ttl" => $result_array['Ttl'],
"Zone" => $result_array['Zone']
];
$zone_file_txt = json_encode($zone_file_array, JSON_PRETTY_PRINT);
file_put_contents('zones.d/' . $argv[1] . '.zone', $zone_file_txt);