-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPluginDomainnameapi.php
More file actions
639 lines (554 loc) · 23.7 KB
/
Copy pathPluginDomainnameapi.php
File metadata and controls
639 lines (554 loc) · 23.7 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
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
<?php
use DomainNameApi\DomainNameAPI_PHPLibrary;
require_once 'modules/admin/models/RegistrarPlugin.php';
require_once 'plugins/registrars/domainnameapi/api.php';
class PluginDomainnameapi extends RegistrarPlugin
{
public const MODULE_VERSION='2.0.2';
public $features = [
'nameSuggest' => false,
'importDomains' => true,
'importPrices' => true,
];
/**
* @var DomainNameAPI_PHPLibrary
*/
private $api;
public function setup()
{
$this->api = new DomainNameAPI_PHPLibrary(
$this->settings->get('plugin_Domainnameapi_Username'),
$this->settings->get('plugin_Domainnameapi_Password')
);
}
public function getVariables()
{
$variables = [
lang('Plugin Name') => [
'type' => 'hidden',
'description' => lang('How CE sees this plugin (not to be confused with the Signup Name)'),
'value' => lang('Domain Name Api')
],
lang('Use testing server') => [
'type' => 'yesno',
'description' => lang('Select Yes if you wish to use the testing environment, so that transactions are not actually made.'),
'value' => 0
],
lang('Username') => [
'type' => 'text',
'description' => lang('Enter your username for your Domain Name Api reseller account.'),
'value' => ''
],
lang('Password') => [
'type' => 'password',
'description' => lang('Enter the password for your Domain Name API reseller account.'),
'value' => '',
],
lang('NameServer 1') => [
'type' => 'text',
'description' => lang('Enter Name Server #1, used in stand alone domains.'),
'value' => '',
],
lang('NameServer 2') => [
'type' => 'text',
'description' => lang('Enter Name Server #1, used in stand alone domains.'),
'value' => '',
],
lang('Supported Features') => [
'type' => 'label',
'description' => '* ' . lang('TLD Lookup') . '<br>* ' . lang('Domain Registration') . ' <br>* ' . lang('Domain Registration with ID Protect') . ' <br>* ' . lang('Existing Domain Importing') . ' <br>* ' . lang('Get / Set Nameserver Records') . ' <br>* ' . lang('Get / Set Contact Information') . ' <br>* ' . lang('Get / Set Registrar Lock') . ' <br>* ' . lang('Initiate Domain Transfer') . ' <br>* ' . lang('Automatically Renew Domain') . ' <br>* ' . lang('View EPP Code'),
'value' => ''
],
lang('Actions') => [
'type' => 'hidden',
'description' => lang('Current actions that are active for this plugin (when a domain isn\'t registered)'),
'value' => 'Register'
],
lang('Registered Actions') => [
'type' => 'hidden',
'description' => lang('Current actions that are active for this plugin (when a domain is registered)'),
'value' => 'SetPrivacyWhois ('.lang('Toggle Privacy Whois').'),Renew (Renew Domain),DomainTransferWithPopup (Initiate Transfer)',
],
lang('Registered Actions For Customer') => [
'type' => 'hidden',
'description' => lang('Current actions that are active for this plugin (when a domain is registered)'),
'value' => 'SetPrivacyWhois ('.lang('Toggle Privacy Whois').')',
]
];
return $variables;
}
public function checkDomain($params)
{
$this->setup();
$domains = [];
if (!empty($params['namesuggest'])) {
$params['namesuggest'] = array_diff($params['namesuggest'], [$params['tld']]);
array_unshift($params['namesuggest'], $params['tld']);
$tldList = $params['namesuggest'];
} else {
$tldList = [$params['tld']];
}
$result = $this->api->CheckAvailability([$params['sld']], $tldList, '1', 'create');
$this->logCall();
if (isset($result['result']) && $result['result'] == 'ERROR') {
$domains[] = [
'tld' => $params['tld'],
'domain' => $params['sld'],
'status' => -2
];
return ['result' => $domains];
}
if (is_array($result)) {
foreach ($result as $results) {
$status = ($results['Status'] == 'notavailable') ? 1 : 0;
$domains[] = [
'tld' => $results['TLD'],
'domain' => $results['DomainName'],
'status' => $status
];
}
} else {
throw new Exception($result['error']['Message'] . "\n" . $result['error']['Details']);
}
return ['result' => $domains];
}
/**
* Initiate a domain transfer
*
* @param array $params
*/
public function doDomainTransferWithPopup($params)
{
$userPackage = new UserPackage($params['userPackageId']);
$transferid = $this->initiateTransfer($this->buildTransferParams($userPackage, $params));
$userPackage->setCustomField("Registrar Order Id", $userPackage->getCustomField("Registrar") . '-' . $transferid);
$userPackage->setCustomField('Transfer Status', $transferid);
return $this->user->lang('Transfer has been initiated.');
}
/**
* Register domain name
*
* @param array $params
*/
public function doRegister($params)
{
$userPackage = new UserPackage($params['userPackageId']);
$orderid = $this->registerDomain($this->buildRegisterParams($userPackage, $params));
$userPackage->setCustomField("Registrar Order Id", $userPackage->getCustomField("Registrar") . '-' . $orderid);
return $userPackage->getCustomField('Domain Name') . ' has been registered.';
}
/**
* Renew domain name
*
* @param array $params
*/
public function doRenew($params)
{
$userPackage = new UserPackage($params['userPackageId']);
$orderid = $this->renewDomain($this->buildRenewParams($userPackage, $params));
$userPackage->setCustomField("Registrar Order Id", $userPackage->getCustomField("Registrar") . '-' . $orderid);
return $userPackage->getCustomField('Domain Name') . ' has been renewed.';
}
public function getTransferStatus($params)
{
}
public function initiateTransfer($params)
{
$this->setup();
$result = $this->api->Transfer($params['sld'] . '.' . $params['tld'], $params['eppCode']);
$this->logCall($result);
if ($result['result'] == 'OK') {
} else {
throw new CE_Exception($result['error']['Message'] . "\n" . $result['error']['Details']);
}
}
public function renewDomain($params)
{
$this->setup();
$result = $this->api->Renew($params['sld'] . '.' . $params['tld'], $params['NumYears']);
$this->logCall($result);
if ($result['result'] == 'OK') {
} else {
throw new CE_Exception($result['error']['Message'] . "\n" . $result['error']['Details']);
}
}
public function registerDomain($params)
{
$this->setup();
$nameServers = [];
if (isset($params['NS1'])) {
for ($i = 1; $i <= 12; $i++) {
if (isset($params["NS$i"])) {
$nameServers[] = $params["NS$i"]['hostname'];
} else {
break;
}
}
}
if (count($nameServers) == 0) {
$nameServers = [
$this->settings->get('plugin_Domainnameapi_NameServer 1'),
$this->settings->get('plugin_Domainnameapi_NameServer 2')
];
}
$privacy = false;
if (isset($params['package_addons']['IDPROTECT']) && $params['package_addons']['IDPROTECT'] == 1) {
$privacy = true;
}
$result = $this->api->RegisterWithContactInfo($params['sld'] . '.' . $params['tld'], $params['NumYears'], [
'Administrative' => $this->contactInfoToArray($params),
'Billing' => $this->contactInfoToArray($params),
'Technical' => $this->contactInfoToArray($params),
'Registrant' => $this->contactInfoToArray($params)
],
$nameServers,
true,
$privacy
);
$this->logCall();
if ($result['result'] == 'OK') {
} else {
throw new CE_Exception($result['error']['Message'] . "\n" . $result['error']['Details']);
}
}
private function contactInfoToArray($params, $set = false)
{
$contactInfo = [
'FirstName' => $params[$set ? 'Registrant_FirstName' : 'RegistrantFirstName'],
'LastName' => $params[$set ? 'Registrant_LastName' : 'RegistrantLastName'],
'Company' => $params[$set ? 'Registrant_OrganizationName' : 'RegistrantOrganizationName'],
'EMail' => $params[$set ? 'Registrant_EmailAddress' : 'RegistrantEmailAddress'],
'AddressLine1' => $params[$set ? 'Registrant_Address1' : 'RegistrantAddress1'],
'AddressLine2' => $params[$set ? 'Registrant_Address2' : 'RegistrantAddress2'],
'City' => $params[$set ? 'Registrant_City' : 'RegistrantCity'],
'Country' => $params[$set ? 'Registrant_Country' : 'RegistrantCountry'],
'Fax' => $params[$set ? 'Registrant_Fax' : 'RegistrantFax'],
'Phone' => $this->validatePhone($params[$set ? 'Registrant_Phone' : 'RegistrantPhone'], $params[$set ? 'Registrant_Country' : 'RegistrantCountry']),
'PhoneCountryCode' => $this->validateCountryCode($params[$set ? 'Registrant_Phone' : 'RegistrantPhone'], $params[$set ? 'Registrant_Country' : 'RegistrantCountry']),
'Type' => 'Contact',
'ZipCode' => $params[$set ? 'Registrant_PostalCode' : 'RegistrantPostalCode'],
'State' => $params[$set ? 'Registrant_StateProvince' : 'RegistrantStateProvince'],
];
if (!$set) {
$contactInfo['Status'] = '';
}
return $contactInfo;
}
private function validateCountryCode($country)
{
$query = "SELECT phone_code FROM country WHERE iso=? AND phone_code != ''";
$result = $this->db->query($query, $country);
if (!$row = $result->fetch()) {
return '';
}
return $row['phone_code'];
}
private function validatePhone($phone, $country)
{
// strip all non numerical values
$phone = preg_replace('/[^\d]/', '', $phone);
if ($phone == '') {
return $phone;
}
$code = $this->validateCountryCode($country);
if ($code == '') {
return $phone;
}
// check if code is already there
$phone = preg_replace("/^($code)(\\d+)/", '+\1.\2', $phone);
if ($phone[0] == '+') {
return $phone;
}
// if not, prepend it
return "+$code.$phone";
}
public function getContactInformation($params)
{
$this->setup();
$result = $this->api->GetContacts($params['sld'] . '.' . $params['tld']);
$this->logCall();
if ($result['result'] == 'OK') {
$info = [];
foreach (['Administrative', 'Billing', 'Registrant', 'Technical'] as $type) {
$data = $result['data']['contacts'][$type];
$info[$type]['OrganizationName'] = [$this->user->lang('Organization'), $data['Company']];
$info[$type]['FirstName'] = [$this->user->lang('First Name'), $data['FirstName']];
$info[$type]['LastName'] = [$this->user->lang('Last Name'), $data['LastName']];
$info[$type]['Address1'] = [$this->user->lang('Address') . ' 1', $data['Address']['Line1']];
$info[$type]['Address2'] = [$this->user->lang('Address') . ' 2', $data['Address']['Line2']];
$info[$type]['City'] = [$this->user->lang('City'), $data['Address']['City']];
$info[$type]['StateProvince'] = [$this->user->lang('Province') . '/' . $this->user->lang('State'), $data['Address']['State']];
$info[$type]['Country'] = [$this->user->lang('Country'), $data['Address']['Country']];
$info[$type]['PostalCode'] = [$this->user->lang('Postal Code'), $data['Address']['ZipCode']];
$info[$type]['EmailAddress'] = [$this->user->lang('E-mail'), $data['EMail']];
$info[$type]['Phone'] = [$this->user->lang('Phone'), $data['Phone']['Phone']['Number']];
$info[$type]['Fax'] = [$this->user->lang('Fax'), $data['Phone']['Fax']['Number']];
}
return $info;
} else {
throw new CE_Exception($result['error']['Message'] . "\n" . $result['error']['Details']);
}
}
public function setContactInformation($params)
{
$this->setup();
$result = $this->api->SaveContacts(
$params['sld'] . '.' . $params['tld'],
[
'Administrative' => $this->contactInfoToArray($params, true) ,
'Billing' => $this->contactInfoToArray($params, true),
'Technical' => $this->contactInfoToArray($params, true),
'Registrant' => $this->contactInfoToArray($params, true),
]
);
$this->logCall();
if ($result['result'] == 'OK') {
return $this->user->lang('Contact Information updated successfully.');
} else {
throw new CE_Exception($result['error']['Message'] . "\n" . $result['error']['Details']);
}
}
public function getNameServers($params)
{
$this->setup();
$result = $this->api->SyncFromRegistry($params['sld'] . '.' . $params['tld']);
$this->logCall();
$info = [];
if ($result["result"] == "OK") {
$nameservers = isset($result["data"]["NameServers"][0]) ? $result["data"]["NameServers"] : [];
return array_values($nameservers);
} else {
throw new CE_Exception($result['error']['Message'] . "\n" . $result['error']['Details']);
}
}
public function setNameServers($params)
{
$this->setup();
$nameservers = [];
foreach ($params['ns'] as $value) {
$nameservers[] = $value;
}
$result = $this->api->ModifyNameserver($params['sld'] . '.' . $params['tld'], $nameservers);
$this->logCall();
if ($result["result"] == "OK") {
} else {
throw new CE_Exception($result['error']['Message'] . "\n" . $result['error']['Details']);
}
}
public function getGeneralInfo($params)
{
$this->setup();
$domain = $params['sld'] . '.' . $params['tld'];
if(isset($params['domain'])){
$domain = $params['domain'];
}
$result = $this->api->SyncFromRegistry($domain);
if ($result['result'] == 'OK') {
$data = [];
$data['domain'] = $result['data']['DomainName'];
$data['expiration'] = $result['data']['Dates']['Expiration'];
$data['is_registered'] = $result['data']['Status'] == 'ACTIVE';
$data['is_expired'] = strtotime($result['data']['Dates']['Expiration'])>time();
$data['registrationstatus'] = 'N/A';
$data['purchasestatus'] = 'N/A';
$data['is_locked'] = $result['data']['LockStatus']==='true';
$data['is_privacy_protected'] = $result['data']['PrivacyProtectionStatus']==='true';
return $data;
} else {
throw new Exception('Error fetching domain details.');
}
}
public function fetchDomains($params)
{
$this->setup();
$domainsList = [];
$pageLength = 100000;
$page=0;
if ($params['next'] > $pageLength) {
$page = ceil($params['next'] / $pageLength);
}
$getListArgs = [
'PageSize' => $pageLength,
'PageNumber' => $page,
'OrderColumn' => 'Id',
'OrderDirection' => 'DESC',
];
$result = $this->api->GetList($getListArgs);
if (is_array($result['data']['Domains'])) {
foreach ($result['data']['Domains'] as $domain) {
$domainName = trim($domain['DomainName']);
$temp = explode('.', $domainName);
$sld = $temp[0];
unset($temp[0]);
$tld = implode('.', $temp);
$data = [
'id' => $domain['ID'],
'sld' => $sld,
'tld' => $tld,
'exp' => $domain['Dates']['Expiration']
];
$domainsList[] = $data;
}
}
$metaData = [];
$metaData['total'] = (int)$result['TotalCount'];
$metaData['next'] = $page * $pageLength + 1;
$metaData['start'] = 1 + ($page - 1) * $pageLength;
$metaData['end'] = min($page * $pageLength, $metaData['total']);
$metaData['numPerPage'] = $pageLength;
return [$domainsList, $metaData];
}
public function getRegistrarLock($params)
{
$this->setup();
$result = $this->api->SyncFromRegistry($params['sld'] . '.' . $params['tld']);
if ($result['result'] == 'OK') {
return $result['data']['LockStatus'] == 'true';
} else {
throw new CE_Exception($result['error']['Message'] . "\n" . $result['error']['Details']);
}
}
public function doSetRegistrarLock($params)
{
$userPackage = new UserPackage($params['userPackageId']);
$this->setRegistrarLock($this->buildLockParams($userPackage, $params));
return $this->user->lang('Updated Registrar Lock.');
}
public function setRegistrarLock($params)
{
$this->setup();
$result = $this->api->SyncFromRegistry($params['sld'] . '.' . $params['tld']);
if ($result['result'] == 'OK') {
if ($result['data']['LockStatus'] == 'true') {
$result = $this->api->DisableTheftProtectionLock($params['sld'] . '.' . $params['tld']);
} else {
$result = $this->api->EnableTheftProtectionLock($params['sld'] . '.' . $params['tld']);
}
$this->logCall();
if ($result['result'] == 'OK') {
$this->user->lang('Registrar Lock updated successfully.');
} else {
throw new CE_Exception($result['error']['Message'] . "\n" . $result['error']['Details']);
}
} else {
throw new CE_Exception($result['error']['Message'] . "\n" . $result['error']['Details']);
}
}
public function doSetPrivacyWhois($params): string
{
$userPackage = new UserPackage($params['userPackageId']);
$domain = $userPackage->getCustomField('Domain Name');
if ($userPackage->status == PACKAGE_STATUS_PENDING) {
return $this->user->lang("This domain is currently not active");
}
$params['domain']=$domain;
$domainDetail = $this->getGeneralInfo($params);
if (!is_array($domainDetail)) {
return $this->user->lang("Error fetching domain details");
}
if ($domainDetail['is_privacy_protected']===true) {
$modifyResult = $this->api->ModifyPrivacyProtectionStatus($domain, false);
} else {
$modifyResult = $this->api->ModifyPrivacyProtectionStatus($domain, true);
}
if($modifyResult['result'] != 'OK'){
throw new CE_Exception($modifyResult['error']['Message'] . "\n" . $modifyResult['error']['Details']);
}
return $this->user->lang("Whois privacy for domain %s is now %s", $domain, $modifyResult['data']['PrivacyProtectionStatus'] ? "enabled" : "disabled");
}
public function getEPPCode($params)
{
$this->setup();
$result = $this->api->SyncFromRegistry($params['sld'] . '.' . $params['tld']);
if ($result['result'] == 'OK') {
return $result['data']['AuthCode'];
} else {
throw new CE_Exception($result['error']['Message'] . "\n" . $result['error']['Details']);
}
}
private function logCall()
{
CE_Lib::log(4, 'DomainName API Request:');
CE_Lib::log(4, $this->api->getRequestData());
CE_Lib::log(4, 'DomainName API Response:');
CE_Lib::log(4, $this->api->getResponseData());
}
public function getDNS($params)
{
throw new CE_Exception('DNS Management is not currently supported.');
}
public function setDNS($params)
{
throw new CE_Exception('DNS Management is not currently supported.');
}
public function sendTransferKey($params)
{
}
public function setAutorenew($params)
{
}
public function checkNSStatus($params)
{
}
public function registerNS($params)
{
$this->setup();
$nameserver = $params['nsname'];
$ip = $params['nsip'];
$result = $this->api->AddChildNameServer($params['sld'] . '.' . $params['tld'], $nameserver, $ip);
$this->logCall();
if ($result['result'] == 'OK') {
return $this->user->lang('Name Server registered successfully.');
} else {
throw new CE_Exception($result['error']['Message'] . "\n" . $result['error']['Details']);
}
}
public function editNS($params)
{
$this->setup();
$nameserver = $params['nsname'];
$newIp = $params['nsnewip'];
$result = $this->api->ModifyChildNameServer($params['sld'] . '.' . $params['tld'], $nameserver, $newIp);
$this->logCall();
if ($result['result'] == 'OK') {
return $this->user->lang('Name Server updated successfully.');
} else {
throw new CE_Exception($result['error']['Message'] . "\n" . $result['error']['Details']);
}
}
public function deleteNS($params)
{
$this->setup();
$nameserver = $params['nsname'];
$result = $this->api->DeleteChildNameServer($params['sld'] . '.' . $params['tld'], $nameserver);
$this->logCall();
if ($result['result'] == 'OK') {
return $this->user->lang('Name Server deleted successfully.');
} else {
throw new CE_Exception($result['error']['Message'] . "\n" . $result['error']['Details']);
}
}
public function getTLDsAndPrices($params)
{
$this->setup();
$tldlist = $this->api->GetTldList(1200);
$this->logCall();
$tlds = [];
if ($tldlist['result'] == 'OK') {
foreach ($tldlist['data'] as $extension) {
if(strlen($extension['tld'])>1){
$price_registration = $extension['pricing']['registration']['1'];
$price_renew = $extension['pricing']['renew']['1'];
$price_transfer = $extension['pricing']['transfer']['1'];
$current_currency = $extension['currencies']['registration'];
$tlds[$extension['tld']]['pricing']['register']=(float)$price_registration;
$tlds[$extension['tld']]['pricing']['renew']=(float)$price_renew;
$tlds[$extension['tld']]['pricing']['transfer']=(float)$price_transfer;
}
}
return $tlds;
} else {
throw new CE_Exception($tldlist['error']['Message'] . "\n" . $tldlist['error']['Details']);
}
}
}