-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathnamesilo.php
278 lines (278 loc) · 9.54 KB
/
namesilo.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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<?php
class Namesilo{
#### by default use the sandbox in development
public $api_url = 'https://www.namesilo.com/api/';
public $api_key;
public $debug = false;
public function __construct($api_key,$sandbox=false,$debug=false){
if($sandbox == true){
$this->api_url = 'http://sandbox.namesilo.com/api/';
}
$this->api_key = $api_key;
$this->debug = false;
}
public function create_contact($fn,$ln,$ad,$cy,$st,$zp,$ct,$em,$ph){
$result = $this->request('contactAdd',[
['fn',$fn], // first name
['ln',$ln], // last name
['ad',$ad], // address
['cy',$cy], // city
['st',$st], // state
['zp',$zp], // zip
['ct',$ct], // country
['em',$em], // email
['ph',$ph], // phone number
]);
if($this->request_successp($result))
return $result['reply']['contact_id'];
return false;
}
public function update_nameservers($domain,$ns1,$ns2){
$result = $this->request('changeNameServers',[
['domain',$domain],
['ns1',$ns1],
['ns2',$ns2]
]);
if($this->request_successp($result))
return true;
return false;
}
public function update_contact_by_domain($domain,$fn,$ln,$ad,$cy,$st,$zp,$ct,$em,$ph){
$contact_id = $this->get_contact_id_by_domain($domain);
$result = $this->request('contactUpdate',[
['contact_id',$contact_id],
['fn',$fn], // first name
['ln',$ln], // last name
['ad',$ad], // address
['cy',$cy], // city
['st',$st], // state
['zp',$zp], // zip
['ct',$ct], // country
['em',$em], // email
['ph',$ph], // phone number
]);
if($this->request_successp($result))
return true;
return false;
}
public function delete_contact($contact_id){
$result = $this->request('contactDelete',[
['contact_id',$contact_id]
]);
if($this->request_successp($result))
return true;
return false;
}
public function register_domain_by_contact_id($domain,$contact_id,$years=1){
$result = $this->request('registerDomain',[
['domain',$domain],
['years',$years],
['private',1],
['auto_renew',0],
['contact_id',$contact_id],
]);
if(!$this->request_successp($result)){
$this->delete_contact($contact_id);
return false;
}
return true;
}
public function register_domain($domain,$fn,$ln,$ad,$cy,$st,$zp,$ct,$em,$ph,$years=1){
$contact_id = $this->create_contact($fn,$ln,$ad,$cy,$st,$zp,$ct,$em,$ph);
if(!$contact_id)
return false;
$result = $this->request('registerDomain',[
['domain',$domain],
['years',$years],
['private',1],
['auto_renew',0],
['contact_id',$contact_id],
]);
if(!$this->request_successp($result)){
return false;
}
return true;
}
public function add_dns_record($domain,$type,$host,$value,$distance='',$ttl=''){
$result = $this->request('dnsAddRecord',[
['domain',$domain],
['rrtype',$type],
['rrhost',$host],
['rrvalue',$value],
['rrdistance',$distance],
['rrttl',$ttl],
]);
if($this->request_successp($result))
return true;
else
return false;
}
public function delete_dns_record($domain,$record_id){
$result = $this->request('dnsDeleteRecord',[
['domain',$domain],
['rrid',$record_id],
]);
if($this->request_successp($result))
return true;
else
return false;
}
public function get_dns_records($domain){
$result = $this->request('dnsListRecords',[
['domain',$domain],
]);
if($this->request_successp($result)){
if(!isset($result['reply']['resource_record'][0])){
$temp_arr = [];
$temp_arr[0] = $result['reply']['resource_record'];
return $temp_arr;
}else{
return $result['reply']['resource_record'];
}
}else{
return false;
}
}
public function is_domain_available($domain){
$result = $this->request('checkRegisterAvailability',[['domains',$domain]]);
if($this->request_successp($result) && isset($result['reply']['available']))
return 'available';
if($this->request_successp($result) && isset($result['reply']['invalid']))
return 'invalid';
if($this->request_successp($result) && isset($result['reply']['unavailable']))
return 'unavailable';
return false;
}
public function send_auth_code($domain){
return $this->request_successp($this->request('retrieveAuthCode',[['domain',$domain]]));
}
public function get_contact_by_id($contact_id){
$result = $this->request('contactList',[['contact_id',$contact_id]]);
if(!$this->request_successp($result))
return false;
return $result['reply']['contact'];
}
public function get_all_contacts(){
$result = $this->request('contactList');
if(!$this->request_successp($result))
return false;
return $result['reply']['contact'];
}
public function get_contact_by_domain($domain){
$contact_id = $this->get_contact_id_by_domain($domain);
if(!$contact_id)
return false;
return $this->get_contact_by_id($contact_id);
}
public function list_domains(){
$result = $this->request('listDomains');
if(!$this->request_successp($result))
return false;
return $result['reply']['domains']['domain'];
}
public function get_nameservers($domain){
$domain_info = $this->get_domain_info($domain);
if(!$domain_info)
return false;
if(is_array($domain_info['nameservers']))
return $domain_info['nameservers']['nameserver'];
else
return false;
}
public function privacy_status($domain){
$domain_info = $this->get_domain_info($domain);
if(!$domain_info)
return false;
$private = strtolower($domain_info['private']);
if($private == 'yes')
return true;
else
return false;
}
public function add_privacy($domain){
$result = $this->request('addPrivacy',[['domain',$domain]]);
return $this->request_successp($result);
}
public function remove_privacy($domain){
$result = $this->request('removePrivacy',[['domain',$domain]]);
return $this->request_successp($result);
}
public function lock_status($domain){
$domain_info = $this->get_domain_info($domain);
if(!$domain_info)
return false;
$private = strtolower($domain_info['locked']);
if($private == 'yes')
return true;
else
return false;
}
public function domain_lock($domain){
$result = $this->request('domainLock',[['domain',$domain]]);
return $this->request_successp($result);
}
public function domain_unlock($domain){
$result = $this->request('domainUnlock',[['domain',$domain]]);
return $this->request_successp($result);
}
public function get_contact_id_by_domain($domain){
$domain_info = $this->get_domain_info($domain);
if(!$domain_info)
return false;
$contact_id = $domain_info['contact_ids']['registrant'];
return $contact_id;
}
public function get_domain_info($domain){
$result = $this->request('getDomainInfo',[['domain',$domain]]);
if($this->request_successp($result))
return $result['reply'];
else
return false;
}
public function get_account_balance(){
$result = $this->request('getAccountBalance');
if($this->request_successp($result))
return $result['reply']['balance'];
else
return false;
}
// main public functions
private function request($command,$options=''){
$created_options = '';
if(!empty($options)){
foreach($options as $pair){
$created_options .= '&';
$created_options .= $pair[0];
$created_options .= '=';
$created_options .= urlencode($pair[1]);
}
}
$command_ready = $this->api_url . $command . '?version=1&type=xml&key=' . $this->api_key . $created_options;
$str = file_get_contents($command_ready);
$result = $this->xml_to_arr($str);
if($this->debug){
echo '<pre>';
print_r($result);
echo '</pre>';
}
if(!$this->request_successp($result)){
throw new Exception($result['reply']['detail']);
}
return $result;
}
private function xml_to_arr($str){
$str = trim($str);
$xml = simplexml_load_string($str);
$json = json_encode($xml);
$array = json_decode($json,TRUE);
return $array;
}
private function request_successp($arr){
if($arr['reply']['code'] == 300 ||
$arr['reply']['code'] == 301 ||
$arr['reply']['code'] == 302)
return true;
else
return false;
}
}