forked from sed-seyedi/namesilo-php-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
namesilo.php
290 lines (288 loc) · 8.09 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
279
280
281
282
283
284
285
286
287
288
289
290
<?php
/*
Copyright (C) 2015 <Seyed Seyedi doing business as SunSed,LLC>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
$ns_url = 'http://sandbox.namesilo.com/api/'; // for development
//$ns_url = 'https://www.namesilo.com/api/'; // for production
$ns_key = 'your api key provided by namesilo';
$ns_error = ''; // used for internal errors keep it empty!
$ns_debug = false; // weather to turn debuging on or off
function ns_create_contact($fn,$ln,$ad,$cy,$st,$zp,$ct,$em,$ph){
$result = ns_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(ns_request_successp($result))
return $result['reply']['contact_id'];
return false;
}
function ns_update_nameservers($domain,$ns1,$ns2){
$result = ns_request('changeNameServers',[
['domain',$domain],
['ns1',$ns1],
['ns2',$ns2]
]);
if(ns_request_successp($result))
return true;
return false;
}
function ns_update_contact_by_domain($domain,$fn,$ln,$ad,$cy,$st,$zp,$ct,$em,$ph){
$contact_id = ns_get_contact_id_by_domain($domain);
$result = ns_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(ns_request_successp($result))
return true;
return false;
}
function ns_delete_contact($contact_id){
$result = ns_request('contactDelete',[
['contact_id',$contact_id]
]);
if(ns_request_successp($result))
return true;
return false;
}
function ns_register_domain_by_contact_id($domain,$contact_id,$years=1){
$result = ns_request('registerDomain',[
['domain',$domain],
['years',$years],
['private',1],
['auto_renew',0],
['contact_id',$contact_id],
]);
if(!ns_request_successp($result)){
ns_delete_contact($contact_id);
return false;
}
return true;
}
function ns_register_domain($domain,$fn,$ln,$ad,$cy,$st,$zp,$ct,$em,$ph,$years=1){
$contact_id = ns_create_contact($fn,$ln,$ad,$cy,$st,$zp,$ct,$em,$ph);
if(!$contact_id)
return false;
$result = ns_request('registerDomain',[
['domain',$domain],
['years',$years],
['private',1],
['auto_renew',0],
['contact_id',$contact_id],
]);
if(!ns_request_successp($result)){
return false;
}
return true;
}
function ns_add_dns_record($domain,$type,$host,$value,$distance='',$ttl=''){
$result = ns_request('dnsAddRecord',[
['domain',$domain],
['rrtype',$type],
['rrhost',$host],
['rrvalue',$value],
['rrdistance',$distance],
['rrttl',$ttl],
]);
if(ns_request_successp($result))
return true;
else
return false;
}
function ns_delete_dns_record($domain,$record_id){
$result = ns_request('dnsDeleteRecord',[
['domain',$domain],
['rrid',$record_id],
]);
if(ns_request_successp($result))
return true;
else
return false;
}
function ns_get_dns_records($domain){
$result = ns_request('dnsListRecords',[
['domain',$domain],
]);
if(ns_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;
}
}
function ns_is_domain_available($domain){
$result = ns_request('checkRegisterAvailability',[['domains',$domain]]);
if(ns_request_successp($result) && isset($result['reply']['available']))
return 'available';
if(ns_request_successp($result) && isset($result['reply']['invalid']))
return 'invalid';
if(ns_request_successp($result) && isset($result['reply']['unavailable']))
return 'unavailable';
return false;
}
function ns_send_auth_code($domain){
return ns_request_successp(ns_request('retrieveAuthCode',[['domain',$domain]]));
}
function ns_get_contact_by_id($contact_id){
$result = ns_request('contactList',[['contact_id',$contact_id]]);
if(!ns_request_successp($result))
return false;
return $result['reply']['contact'];
}
function ns_get_all_contacts(){
$result = ns_request('contactList');
if(!ns_request_successp($result))
return false;
return $result['reply']['contact'];
}
function ns_get_contact_by_domain($domain){
$contact_id = ns_get_contact_id_by_domain($domain);
if(!$contact_id)
return false;
return ns_get_contact_by_id($contact_id);
}
function ns_list_domains(){
$result = ns_request('listDomains');
if(!ns_request_successp($result))
return false;
return $result['reply']['domains']['domain'];
}
function ns_get_nameservers($domain){
$domain_info = ns_get_domain_info($domain);
if(!$domain_info)
return false;
if(is_array($domain_info['nameservers']))
return $domain_info['nameservers']['nameserver'];
else
return false;
}
// domain privacy
function ns_privacy_status($domain){
$domain_info = ns_get_domain_info($domain);
if(!$domain_info)
return false;
$private = strtolower($domain_info['private']);
if($private == 'yes')
return true;
else
return false;
}
function ns_add_privacy($domain){
$result = ns_request('addPrivacy',[['domain',$domain]]);
return ns_request_successp($result);
}
function ns_remove_privacy($domain){
$result = ns_request('removePrivacy',[['domain',$domain]]);
return ns_request_successp($result);
}
// domain lock
function ns_lock_status($domain){
$domain_info = ns_get_domain_info($domain);
if(!$domain_info)
return false;
$private = strtolower($domain_info['locked']);
if($private == 'yes')
return true;
else
return false;
}
function ns_domain_lock($domain){
$result = ns_request('domainLock',[['domain',$domain]]);
return ns_request_successp($result);
}
function ns_domain_unlock($domain){
$result = ns_request('domainUnlock',[['domain',$domain]]);
return ns_request_successp($result);
}
// other commands
function ns_get_contact_id_by_domain($domain){
$domain_info = ns_get_domain_info($domain);
if(!$domain_info)
return false;
$contact_id = $domain_info['contact_ids']['registrant'];
return $contact_id;
}
function ns_get_domain_info($domain){
$result = ns_request('getDomainInfo',[['domain',$domain]]);
if(ns_request_successp($result))
return $result['reply'];
else
return false;
}
function ns_get_account_balance(){
$result = ns_request('getAccountBalance');
if(ns_request_successp($result))
return $result['reply']['balance'];
else
return false;
}
// main functions
function ns_request($command,$options=''){
global $ns_url,$ns_key,$ns_debug,$ns_error;
$created_options = '';
if(!empty($options)){
foreach($options as $pair){
$created_options .= '&';
$created_options .= $pair[0];
$created_options .= '=';
$created_options .= urlencode($pair[1]);
}
}
$command_ready = $ns_url . $command . '?version=1&type=xml&key=' . $ns_key . $created_options;
$str = file_get_contents($command_ready);
$result = xml_to_arr($str);
if($ns_debug){
echo '<pre>';
print_r($result);
echo '</pre>';
}
if(!ns_request_successp($result)){
$ns_error = $result['reply']['detail'];
}
if($result['reply']['code'] == 301 || $result['reply']['code'] == 302){
$ns_error = $result['reply']['detail'];
}
return $result;
}
function xml_to_arr($str){
$str = trim($str);
$xml = simplexml_load_string($str);
$json = json_encode($xml);
$array = json_decode($json,TRUE);
return $array;
}
function ns_request_successp($arr){
if($arr['reply']['code'] == 300 || $arr['reply']['code'] == 301 || $arr['reply']['code'] == 302)
return true;
else
return false;
}