-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodifydomain.php
More file actions
125 lines (88 loc) · 3.83 KB
/
modifydomain.php
File metadata and controls
125 lines (88 loc) · 3.83 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
header("content-type: text/plain;charset=utf8");
$response = "";
$additional_parameters = "";
$namecheap_url = "https://api.namecheap.com/xml.response?"; #Url it will remain same always
$user_name = "{USER_NAME}"; #Require user name
$api_user = "{API_USER}"; #Require api user
$api_key = "{API_KEY}"; #Require api key
$command_get = "namecheap.domains.dns.getHosts"; #Always Remain the same
$command_set = "namecheap.domains.dns.setHosts"; #Always Remain the same
$client_ip = "{WHITELIST_IP}"; #Require whitelist IP
$sld = "{DOMAIN_NAME}"; #Require domain name for example xyz
$tld = "{TLD}"; #Require top level domain for example xyz.com TLD=com
$get_records_list = "{$namecheap_url}apikey={$api_key}&Command={$command_get}".
"&ClientIp={$client_ip}&SLD={$sld}&TLD={$tld}".
"&username={$user_name}&apiuser={$api_user}";
$set_hosts_call = "{$namecheap_url}apikey={$api_key}&Command={$command_set}".
"&ClientIp={$client_ip}&SLD={$sld}&TLD={$tld}".
"&username={$user_name}&apiuser={$api_user}";
execute_rest_call($get_records_list);
$xml=simplexml_load_string($response);
if(empty($_GET)) {
print_r($xml);
exit(1);
}
$hostCount = 0;
$Count = 1;
$recordMatch = 0;
if($_GET['DeleteAll']=="true") {
$set_hosts_call .= $additional_parameters;
execute_rest_call($set_hosts_call);
$xml=simplexml_load_string($response);
print_r($xml);
exit(1);
}
foreach($xml->CommandResponse->DomainDNSGetHostsResult->children() as $host) {
$record_type = $xml->CommandResponse->DomainDNSGetHostsResult->host[$hostCount]['Type'];
$host_name = $xml->CommandResponse->DomainDNSGetHostsResult->host[$hostCount]['Name'];
$address = $xml->CommandResponse->DomainDNSGetHostsResult->host[$hostCount]['Address'];
$ttl = $xml->CommandResponse->DomainDNSGetHostsResult->host[$hostCount]['TTL'];
if($_GET['SetRecordType']==$record_type) {
if($_GET['DeleteRecord']=="true") {
$hostCount++;
continue;
}
$additional_parameters .= "&HostName{$Count}={$_GET['SetHostName']}".
"&RecordType{$Count}={$_GET['SetRecordType']}".
"&Address{$Count}={$_GET['Address']}".
"&TTL{$Count}={$_GET['TTL']}";
$recordMatch = 1;
$hostCount++;
$Count++;
continue;
}
$additional_parameters .= "&HostName{$Count}={$host_name}".
"&RecordType{$Count}={$record_type}".
"&Address{$Count}={$address}".
"&TTL{$Count}={$ttl}";
$hostCount++;
$Count++;
}
if ($recordMatch == 0 && $_GET['DeleteRecord']!="true") {
$additional_parameters .= "&HostName{$Count}={$_GET['SetHostName']}".
"&RecordType{$Count}={$_GET['SetRecordType']}".
"&Address{$Count}={$_GET['Address']}".
"&TTL{$Count}={$_GET['TTL']}";
}
$set_hosts_call .= $additional_parameters;
echo $set_hosts_call;
execute_rest_call($set_hosts_call);
$xml=simplexml_load_string($response);
print_r($xml);
function execute_rest_call($result_url) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "{$result_url}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$GLOBALS['response'] = curl_exec($curl);
curl_close($curl);
}
?>