-
Notifications
You must be signed in to change notification settings - Fork 36
/
namecheap.php
1428 lines (1246 loc) · 61.4 KB
/
namecheap.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
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
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
// ****************************************************************************
// * *
// * NameCheap.com WHMCS Registrar Module *
// * Version 1.2.11
// * *
// * Copyright 2008-2016 NameCheap.com *
// *
// * *
// * Licensed under the Apache License, Version 2.0 (the "License"); *
// * you may not use this file except in compliance with the License. *
// * You may obtain a copy of the License at *
// * *
// * http://www.apache.org/licenses/LICENSE-2.0 *
// * *
// * Unless required by applicable law or agreed to in writing, software *
// * distributed under the License is distributed on an "AS IS" BASIS, *
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
// * See the License for the specific language governing permissions and *
// * limitations under the License. *
// * *
// ****************************************************************************
// * *
// * To install, create a folder named namecheap under *
// * modules/registrar under your whmcs root directory and place *
// * namecheap.php, namecheapapi.php, namecheapsync.php, *
// * additionaldomainfields.php, logo.gif into it. *
// * Then in WHMCS admin menu, go to registrar module settings and select *
// * Namecheap, and configure. You should enter your api key in *
// * the password field and api username in username field. *
// * *
// ****************************************************************************
// * Changes:
// *
// * November, 25, 2016 (1.2.11)
// * - Added Registeredfor parameter for .uk domains in SaveContactDetails method
// *
// * November, 21, 2016 (1.2.10)
// * - Added SGAdminId, COMSGAdminId parameters
// * - Removed Whoisguard restriction TLD list
// *
// * December, 21, 2015 (1.2.9)
// * - Updated extended attributes for .es, .com.es, .nom.es, .org.es
// *
// * April, 17, 2014 (1.2.8)
// * - Added ability to enable WhoisGuard with transfers
// * - Added active and transfer domain syncing module functions according to WHMCS Domain Cron Synchronisation flow
// * - Removed module domain synchronization script (deprecated)
// * - Changed method of creating Registrant/Billing/Admin/Tech contact details API parameters depending on WHMCS general settings for domains:
// * When "Use Clients Details" checkbox is checked Registrant/Billing/Admin/Tech contacts are taken from Client details, if not - Registrant details are taken from Client details, and Billing/Admin/Tech - from Default Contact Details.
// * - Added quotes decoding for epp code (whmcs bug)
// * - Removed "http_x_forwarded_for" for client ip address
// * - Added .asia Locality parameter to custom additionaldomainfields.php (with verification for native additionaldomainfields.php file)
// * - Minor bug fixes
//
// * October 21, 2013 (1.2.7)
// * - Added .fr, .sg, .com.sg, .fr, .net.au, .org.au, .com.au, .es, .com.es, .nom.es, .org.es support
// * - Removed error "Domain name not found" for domains in any status, except for not in "Active" or "Expired"
// * - Added "Job Title" additional field for .ca and .au domains
// * - All errors from API response are returned by the module (in case there is more than one error)
// * - Fixed error with domains that have been added in punycode to WHMCS
// * - Added conversion for registrant state/province and zip code fields for .ca domains according to the registry requirements
// * May 10, 2013 (1.2.6)
// * - Added IDN support
// * - Added debug mode
// * - Removed validation for empty phone/fax fields
// * - Fixed bug for editing MX and MXE records
// * - Fixed bug for setting default nameservers after domain registration
// * - Changed 4 default NS count to 5
// * - Fixed dependency on php directive arg_separator.output
// * December 11, 2012 (1.2.5)
// * - Added logs on exceptions
// * July 24, 2012 (1.2.4)
// * - Extended attributes for .me.uk domains
// * June 18, 2012 (1.2.3)
// * - Fixed domain name case sensitivity in the sync script
// * May 2, 2012 (1.2.2)
// * - Fixed issue with incorrect parameters on domain contact details saving
// * - Replace classes NamecheapApi and NamecheapApiException with NamecheapRegistrarApi and NamecheapRegistrarApiException
// * to avoid conflict with our Namecheap SSL module
// * March 6, 2012 (1.2.1)
// * - Added default params for .de domains to request (DEConfirmAddress=DE,DEAgreeDelete=Yes)
// * - Added Base64 encoding for EPPCode
// * January 13, 2012 (1.2.0)
// * - This version is recommended for WHMCS 5.0.0 and over only
// * - Fixed bug with parsing domain transfer data that prevent domains from being recognized as already transferred
// * - Removed our custom client warnings regarding Whoisguard stuff
// * - Dropped our .asia domain entries in favor of the standard WHMCS stuff
// * NOTE: unfortunately you still need to add this code right after other $additionaldomainfields[".asia"][] entries
// * in the file includes/additionaldomainfields.php
// * $additionaldomainfields[".asia"][] = array(
// * "Name" => "Locality", "Type" => "dropdown",
// * "Options" => "af,bd,ck,in,jp,kg,mh,nz,ps,sg,th,tv,aq,bt,cy,id,kz,la,fm,nu,pg,sb,tl,ae,am,bn,fj,ir,ki,lb,mn,nf,ph,lk,tk,uz,au,kh,ge,iq,kp,mo,mm,om,qa,sy,to,vu,az,cn,hm,il,kr,my,nr,pk,ws,tw,tr,vn,bh,cc,hk,jo,kw,mv,np,pw,sa,tj,tm,ye"
// * );
// * September 28, 2011 (1.1.8)
// * - Fixed showing of Whoisguard related error messages in the Client Area
// * - Improved Sync script to produce more detailed report on dates synchronisation
// * March 31, 2011 (1.1.7)
// * - Removed support for free SSL on domain creation
// * Feb 14, 2011 (1.1.6)
// * - Added synchronization for expirydate and nextduedate for all active domains
// * Feb 03, 2011 (1.1.5)
// * - Added reactivate functionality for already expired domains in renew function
// * Dec 16, 2010 (1.1.4.1)
// * - Now nextduedate is set the same as expirydate
// * Dec 3, 2010 (1.1.4)
// * - Added sync script namecheapsync.php that synchronises domain status, expirydate and nextduedate for
// * domains that are transferred (for setup notes look for registrar module configuration page)
// * - Now warnings from API that should not be interpreted as errors are sent to admins
// * Oct 22, 2010 (1.1.3)
// * - Added support for new required fields for .ca domains (NOTE: you have to use WHMCS 4.3.1a or higher)
// * - Allow specifying FreePositiveSSL auto adding on domain creation
// * Sept 16, 2010 (1.1.2)
// * - Rewrote algorithm for phone country code checking
// * - Registration and extended attributes for .eu
// * NOTE: at this time WHMCS doesn't support extended attributes for .eu domains. You have to add below code at the end
// * of the file includes/additionaldomainfields.php before ? >
// * $additionaldomainfields[".eu"][] = array(
// * "Name" => "Language for Address Used",
// * "Type" => "dropdown",
// * "Options" => "Bulgaria,Czech,Danish,Dutch,English,Estonian,Finnish,French,German,Greek,Hungarian,Italian,Latvian,Lithuanian,Maltese,Polish,Portuguese,Romania,Slovak,Slovenian,Spanish,Swedish"
// * );
// * Sept 11, 2010 (1.1.1)
// * - Bug fixes
// * - Fixed issue with billing/admin/tech contacts not being set properly when using custom contact details.
// * - Fixed warning php message (Warning: Wrong parameter count for preg_replace() in modules/registrars/namecheap/namecheapapi.php on line 111)
// * - Changes made in regards to warning node for sethosts (domains using custom DNS) and warning node for create domains using unregistered nameservers
// * Jul 12, 2010 (1.1.0)
// * - New Namecheap API wrapper
// * - Allow specifying a coupon code
// * - Allow separate entries for sandbox user/api key
// * - Registration and extended attributes for .us, .ca, .co.uk and .org.uk
// * - Other bug fixes
// * Feb 14, 2010 (1.0.2):
// * - Client IP fix. Client IP was not passed properly and it is now fixed
// * - Removed error during registration (domain create)
// * - Code reformatting
// * - Phone number formatting (country codes not recognized properly)
// ****************************************************************************
function namecheap_getConfigArray()
{
$configarray = array(
'Username' => array('Type' => "text", 'Size' => "20", 'Description' => "Enter your username here."),
'Password' => array('Type' => "text", 'Size' => "20", 'Description' => "Enter your API key here. To get your api key, go to Manage Profile section in Namecheap.com, then click API access link on the left hand side. C/p the key here. DON'T include your password."),
//'AddFreePositiveSSL' => array('Type' => "yesno", 'Description' => 'Add free PositiveSSL for the domains purchased'),
'PromotionCode' => array('Type' => "text", 'Size' => "20", 'Description' => "Enter your promotional (coupon) code."),
'SandboxUsername' => array('Type' => "text", 'Size' => "20", 'Description' => "Enter your sandbox username here. (This will be used only if you set the test mode on.)"),
'SandboxPassword' => array('Type' => "text", 'Size' => "20", 'Description' => "Enter your sandbox API key here. (This will be used only if you set the test mode on.)"),
'TestMode' => array('Type' => "yesno"),
//'SyncNextDueDate' => array('Type' => "yesno", 'Description' => "Tick this box if you want the expiry date sync script to update the expiry and next due dates (cron must be configured)"),
'DebugMode' => array('Type' => "yesno"),
);
return $configarray;
}
function namecheap_GetNameservers($params)
{
require_once dirname(__FILE__) . "/namecheapapi.php";
$testmode = (bool)$params['TestMode'];
$debugmode =(bool)$params['DebugMode'];
$username = $testmode ? $params['SandboxUsername'] : $params['Username'];
$password = $testmode ? $params['SandboxPassword'] : $params['Password'];
$tld = $params['tld'];
$sld = $params['sld'];
// do not get nameservers for domains that not registered
$r = mysql_query('SELECT * from tbldomains WHERE id='.(int)$params['domainid']);
if (!mysql_num_rows($r)){
return;
}
$row = mysql_fetch_assoc($r);
if (!in_array($row['status'],array(/*'Pending','Pending Transfer',*/'Active','Expired',/*'Cancelled','Fraud'*/))){
return;
}
$oIDNA = new NamecheapRegistrarIDNA($sld, $tld);
$sld = $oIDNA->getEncodedSld();
try
{
$request_params = array(
'SLD' => $sld,
'TLD' => $tld
);
$api = new NamecheapRegistrarApi($username, $password, $testmode,$debugmode);
$response = $api->request("namecheap.domains.dns.getList", $request_params);
$result = $api->parseResponse($response);
$ns = $result['DomainDNSGetListResult']['Nameserver'];
if (!isset($ns[0])) {
$ns = array($ns);
}
$values['ns1'] = $ns[0];
$values['ns2'] = $ns[1];
$values['ns3'] = $ns[2];
$values['ns4'] = $ns[3];
$values['ns5'] = $ns[4];
}
catch (Exception $e) {
$values['error'] = "An error occurred: " . $e->getMessage();
if (!$debugmode){
logModuleCall('namecheap', 'GetNameservers', array('command' => "namecheap.domains.dns.getList") + $request_params, $response, $result, array());
}
}
return $values;
}
function namecheap_SaveNameservers($params)
{
require_once dirname(__FILE__) . "/namecheapapi.php";
$testmode = (bool)$params['TestMode'];
$debugmode =(bool)$params['DebugMode'];
$username = $testmode ? $params['SandboxUsername'] : $params['Username'];
$password = $testmode ? $params['SandboxPassword'] : $params['Password'];
$tld = $params['tld'];
$sld = $params['sld'];
$oIDNA = new NamecheapRegistrarIDNA($sld, $tld);
$sld = $oIDNA->getEncodedSld();
$defaultNs = true;
$defaultNsServers = array("dns1.registrar-servers.com", "dns2.registrar-servers.com", "dns3.registrar-servers.com", "dns4.registrar-servers.com", "dns5.registrar-servers.com");
$nameservers = array($params['ns1'], $params['ns2'], $params['ns3'], $params['ns4'], $params['ns5']);
foreach ($nameservers as $k => $v) {
if (!$v) { unset($nameservers[$k]); continue;}
if (!in_array($v, $defaultNsServers)) {
$defaultNs = false;
}
}
try
{
$request_params = array(
'SLD' => $sld,
'TLD' => $tld
);
$api = new NamecheapRegistrarApi($username, $password, $testmode, $debugmode);
if (false===$defaultNs){
$request_params['Nameservers'] = implode(',', $nameservers);
$response = $api->request("namecheap.domains.dns.setCustom", $request_params);
}else{
$response = $api->request("namecheap.domains.dns.setDefault", $request_params);
}
$result = $api->parseResponse($response);
}
catch (Exception $e) {
$values['error'] = "An error occurred: " . $e->getMessage();
if (!$debugmode){
logModuleCall('namecheap', 'SetNameservers', array('command' => "namecheap.domains.dns.setCustom") + $request_params, $response, $result, array());
}
}
return $values;
}
function namecheap_GetRegistrarLock($params)
{
require_once dirname(__FILE__) . "/namecheapapi.php";
$testmode = (bool)$params['TestMode'];
$debugmode =(bool)$params['DebugMode'];
$username = $testmode ? $params['SandboxUsername'] : $params['Username'];
$password = $testmode ? $params['SandboxPassword'] : $params['Password'];
$tld = $params['tld'];
$sld = $params['sld'];
$oIDNA = new NamecheapRegistrarIDNA($sld, $tld);
$sld = $oIDNA->getEncodedSld();
try
{
$request_params = array(
'DomainName' => $sld . '.' . $tld
);
$api = new NamecheapRegistrarApi($username, $password, $testmode, $debugmode);
$response = $api->request("namecheap.domains.getRegistrarLock", $request_params);
$result = $api->parseResponse($response);
$lockstatus = ("true" == $result['DomainGetRegistrarLockResult']['@attributes']['RegistrarLockStatus']);
return $lockstatus ? "locked" : "unlocked";
}
catch (Exception $e) {
$values['error'] = "An error occurred: " . $e->getMessage();
if (!$debugmode){
logModuleCall('namecheap', 'GetRegistrarLock', array('command' => "namecheap.domains.getRegistrarLock") + $request_params, $response, $result, array());
}
}
return $values;
}
function namecheap_SaveRegistrarLock($params)
{
require_once dirname(__FILE__) . "/namecheapapi.php";
$testmode = (bool)$params['TestMode'];
$debugmode =(bool)$params['DebugMode'];
$username = $testmode ? $params['SandboxUsername'] : $params['Username'];
$password = $testmode ? $params['SandboxPassword'] : $params['Password'];
$tld = $params['tld'];
$sld = $params['sld'];
$oIDNA = new NamecheapRegistrarIDNA($sld, $tld);
$sld = $oIDNA->getEncodedSld();
try
{
$request_params = array(
'DomainName' => $sld . '.' . $tld,
'LockAction' => ("locked" == $params['lockenabled']) ? "lock" : "unlock"
);
$api = new NamecheapRegistrarApi($username, $password, $testmode, $debugmode);
$response = $api->request("namecheap.domains.setRegistrarLock", $request_params);
$result = $api->parseResponse($response);
}
catch (Exception $e) {
$rl_unable_domains = array("ca", "cm", "co.uk", "org.uk", "me.uk", "de", "eu", "ws");
$msg = $e->getMessage();
$values['error'] = "An error occurred: " . $msg;
if ("[3031510] Failed to get Registrar Lock Status" == $msg && in_array(strtolower($tld), $rl_unable_domains)) {
$values['error'] = "Registrar lock is not applicable for <strong>" . $tld . "</strong> domains.";
}
if (!$debugmode){
logModuleCall('namecheap', 'SaveRegistrarLock', array('command' => "namecheap.domains.setRegistrarLock") + $request_params, $response, $result, array());
}
}
return $values;
}
function namecheap_GetEmailForwarding($params)
{
require_once dirname(__FILE__) . "/namecheapapi.php";
$testmode = (bool)$params['TestMode'];
$debugmode =(bool)$params['DebugMode'];
$username = $testmode ? $params['SandboxUsername'] : $params['Username'];
$password = $testmode ? $params['SandboxPassword'] : $params['Password'];
$tld = $params['tld'];
$sld = $params['sld'];
$oIDNA = new NamecheapRegistrarIDNA($sld, $tld);
$sld = $oIDNA->getEncodedSld();
try
{
$request_params = array(
'DomainName' => $sld . '.' . $tld
);
$api = new NamecheapRegistrarApi($username, $password, $testmode, $debugmode);
$response = $api->request("namecheap.domains.dns.getEmailForwarding", $request_params);
$result = $api->parseResponse($response);
$forward = $result['DomainDNSGetEmailForwardingResult']['Forward'];
if (!isset($forward[0])) {
$forward = array($forward);
}
$values = array();
foreach ($forward as $v) {
$values[] = array(
'prefix' => $v['@attributes']['mailbox'],
'forwardto' => $v['@value']
);
}
}
catch (Exception $e) {
$values['error'] = "An error occurred: " . $e->getMessage();
if (!$debugmode){
logModuleCall('namecheap', 'GetEmailForwarding', array('command' => "namecheap.domains.dns.getEmailForwarding") + $request_params, $response, $result, array());
}
}
return $values;
}
function namecheap_SaveEmailForwarding($params)
{
require_once dirname(__FILE__) . "/namecheapapi.php";
$testmode = (bool)$params['TestMode'];
$debugmode =(bool)$params['DebugMode'];
$username = $testmode ? $params['SandboxUsername'] : $params['Username'];
$password = $testmode ? $params['SandboxPassword'] : $params['Password'];
$tld = $params['tld'];
$sld = $params['sld'];
$oIDNA = new NamecheapRegistrarIDNA($sld, $tld);
$sld = $oIDNA->getEncodedSld();
try
{
$request_params = array(
'DomainName' => $sld . '.' . $tld
);
foreach ($params['prefix'] AS $k => $v) {
if (!empty($params['prefix'][$k]) && !empty($params['forwardto'][$k])) {
$request_params['MailBox' . ($k + 1)] = $params['prefix'][$k];
$request_params['ForwardTo' . ($k + 1)] = $params['forwardto'][$k];
}
}
$api = new NamecheapRegistrarApi($username, $password, $testmode, $debugmode);
$response = $api->request("namecheap.domains.dns.setEmailForwarding", $request_params);
$result = $api->parseResponse($response);
}
catch (Exception $e) {
$values['error'] = "An error occurred: " . $e->getMessage();
if (!$debugmode){
logModuleCall('namecheap', 'SaveEmailForwarding', array('command' => "namecheap.domains.dns.setEmailForwarding") + $request_params, $response, $result, array());
}
}
return $values;
}
function namecheap_GetDNS($params)
{
require_once dirname(__FILE__) . "/namecheapapi.php";
$testmode = (bool)$params['TestMode'];
$debugmode =(bool)$params['DebugMode'];
$username = $testmode ? $params['SandboxUsername'] : $params['Username'];
$password = $testmode ? $params['SandboxPassword'] : $params['Password'];
$tld = $params['tld'];
$sld = $params['sld'];
$oIDNA = new NamecheapRegistrarIDNA($sld, $tld);
$sld = $oIDNA->getEncodedSld();
try
{
$request_params = array(
'SLD' => $sld,
'TLD' => $tld
);
$api = new NamecheapRegistrarApi($username, $password, $testmode, $debugmode);
$response = $api->request("namecheap.domains.dns.getHosts", $request_params);
$result = $api->parseResponse($response);
$host = $result['DomainDNSGetHostsResult']['host'];
if (!isset($host[0])) {
$host = array($host);
}
$values = array();
foreach ($host as $v) {
$values[] = array(
'hostname' => $v['@attributes']['Name'],
'type' => $v['@attributes']['Type'],
'address' => $v['@attributes']['Address']
);
}
}
catch (Exception $e) {
$values['error'] = "An error occurred: " . $e->getMessage();
if (!$debugmode){
logModuleCall('namecheap', 'GetDNS', array('command' => "namecheap.domains.dns.getHosts") + $request_params, $response, $result, array());
}
}
return $values;
}
function namecheap_SaveDNS($params)
{
require_once dirname(__FILE__) . "/namecheapapi.php";
$testmode = (bool)$params['TestMode'];
$debugmode =(bool)$params['DebugMode'];
$username = $testmode ? $params['SandboxUsername'] : $params['Username'];
$password = $testmode ? $params['SandboxPassword'] : $params['Password'];
$tld = $params['tld'];
$sld = $params['sld'];
$oIDNA = new NamecheapRegistrarIDNA($sld, $tld);
$sld = $oIDNA->getEncodedSld();
try
{
$request_params = array(
'SLD' => $sld,
'TLD' => $tld
);
foreach ($params['dnsrecords'] as $k => $v) {
if (!empty($v['hostname']) && !empty($v['type']) && !empty($v['address'])) {
$request_params['HostName' . ($k + 1)] = $v['hostname'];
$request_params['RecordType' . ($k + 1)] = $v['type'];
$request_params['Address' . ($k + 1)] = $v['address'];
if ($v['type'] == 'MX'){
$request_params['EmailType'] = 'MX';
}
if ($v['type'] == 'MXE'){
$request_params['EmailType'] = 'MXE';
}
}
}
$api = new NamecheapRegistrarApi($username, $password, $testmode, $debugmode);
$response = $api->request("namecheap.domains.dns.setHosts", $request_params);
$result = $api->parseResponse($response);
if (isset($result['DomainDNSSetHostsResult']['Warnings']['Warning'])) {
$message = "Saving DNS warning<br />"
. "-----------------------------------------------------------------------------------------<br />"
. $result['DomainDNSSetHostsResult']['Warnings']['Warning']['@value'] . "<br />"
. "-----------------------------------------------------------------------------------------<br />"
. "Domain: " . $tld . "." . $sld . "<br />"
. "<pre>" . print_r($params['dnsrecords']) . "</pre>";
sendadminnotification("system", "WHMCS Namecheap Domain Registrar Module", $message);
}
}
catch (Exception $e) {
$values['error'] = "An error occurred: " . $e->getMessage();
if (!$debugmode){
logModuleCall('namecheap', 'SaveDNS', array('command' => "namecheap.domains.dns.setHosts") + $request_params, $response, $result, array());
}
}
return $values;
}
function namecheap_RegisterDomain($params)
{
require_once dirname(__FILE__) . "/namecheapapi.php";
$testmode = (bool)$params['TestMode'];
$debugmode =(bool)$params['DebugMode'];
$username = $testmode ? $params['SandboxUsername'] : $params['Username'];
$password = $testmode ? $params['SandboxPassword'] : $params['Password'];
$tld = $params['tld'];
$sld = $params['sld'];
$oIDNA = new NamecheapRegistrarIDNA($sld, $tld);
$sld = $oIDNA->getEncodedSld();
$nameservers = array($params['ns1'], $params['ns2'], $params['ns3'], $params['ns4'],$params['ns5']);
foreach ($nameservers as $k => $v) {
if (!$v) { unset($nameservers[$k]); }
}
try
{
if('ca'==strtolower($tld)){
// change state province for US and CA countries
if(!empty(NamecheapRegistrarApi::$_caStateProvince[$params['admincountry']][str_replace(' ', '', $params['adminstate'] )])){
$params['adminstate'] = NamecheapRegistrarApi::$_caStateProvince[$params['admincountry']][str_replace(' ', '', $params['adminstate'] )];
}
$params['adminpostcode'] =str_replace(' ','',$params['adminpostcode']);
// change zip code
if('CA'==$params['admincountry']){
if(' ' != $params['adminpostcode'][3]){
$params['adminpostcode'] = substr($params['adminpostcode'], 0, 3) . ' ' . substr($params['adminpostcode'], 3);
}
}
if('US'==$params['admincountry']){
if(strlen($params['adminpostcode'])>5){
$params['adminpostcode'] = substr($params['adminpostcode'], 0, 5) . '-' . substr($params['adminpostcode'], 5);
}
}
}
// Client Details
$registrant = array(
'RegistrantFirstName' => $params['firstname'],
'RegistrantLastName' => $params['lastname'],
'RegistrantOrganizationName' => $params['companyname'],
'RegistrantAddress1' => $params['address1'],
'RegistrantAddress2' => $params['address2'],
'RegistrantCity' => $params['city'],
'RegistrantStateProvince' => $params['state'],
'RegistrantPostalCode' => $params['postcode'],
'RegistrantCountry' => $params['country'],
'RegistrantPhone' => $params['phonenumber'],
'RegistrantEmailAddress' => $params['email'],
);
// Billing/Admin/Tech Contact Details
$registrantAdmin = array(
'FirstName' => $params['adminfirstname'],
'LastName' => $params['adminlastname'],
'OrganizationName' => $params['admincompanyname'],
'Address1' => $params['adminaddress1'],
'Address2' => $params['adminaddress2'],
'City' => $params['admincity'],
'StateProvince' => $params['adminstate'],
'PostalCode' => $params['adminpostcode'],
'Country' => $params['admincountry'],
'Phone' => $params['adminphonenumber'],
'EmailAddress' => $params['adminemail'],
);
$aux = $tech = $admin = array();
foreach ($registrantAdmin as $k => $v) {
$admin["Admin" . $k] = $v;
$tech["Tech" . $k] = $v;
$aux["AuxBilling" . $k] = $v;
}
$request_params = array(
'DomainName' => $sld . '.' . $tld,
'Years' => $params['regperiod'],
'Nameservers' => implode(',', $nameservers),
);
// idn code
if ($oIDNA->sldWasEncoded()){
$request_params['IdnCode'] = $oIDNA->getIdnCode(empty($params['additionalfields']['idnCode']) ? '' : $params['additionalfields']['idnCode']);
}
$request_params += $registrant + $admin + $tech + $aux;
if (!empty($params['PromotionCode'])) {
$request_params['PromotionCode'] = $params['PromotionCode'];
}
// whois guard
//$wg_ex = array("bz", "ca", "cn", "co.uk", "de", "eu", "in", "me.uk", "mobi", "nu", "org.uk", "us", "ws");
if ($params['idprotection']) {
$request_params['AddFreeWhoisguard'] = "yes";
$request_params['WGEnabled'] = "yes";
}
//if ($params['AddFreePositiveSSL']) {
// $request_params['AddFreePositiveSSL'] = "yes";
//}
// extended attributes for some TLDs
if ('eu' == strtolower($tld)) { // for .eu domains
$request_params['EUAgreeWhoisPolicy'] = "YES";
$request_params['EUAgreeDeletePolicy'] = "YES";
$langs = array('BG' => "Bulgaria", 'CS' => "Czech", 'DS' => "Danish", 'NL' => "Dutch", 'EN' => "English",
'ET' => "Estonian", 'FI' => "Finnish", 'FR' => "French", 'DE' => "German", 'EL' => "Greek",
'HL' => "Hungarian", 'IT' => "Italian", 'LV' => "Latvian", 'LI' => "Lithuanian", 'MT' => "Maltese",
'PL' => "Polish", 'PT' => "Portuguese", 'RO' => "Romania", 'SK' => "Slovak", 'SL' => "Slovenian",
'ES' => "Spanish", 'SV' => "Swedish");
foreach ($langs as $k => $v) {
if ($v == $params['additionalfields']['Language for Address Used']) {
$request_params['EUAdrLang'] = $k;
break;
}
}
} elseif ('us' == strtolower($tld)) { // for .us domains
$request_params['RegistrantNexus'] = $params['additionalfields']['Nexus Category'];
$request_params['RegistrantNexusCountry'] = $params['additionalfields']['Nexus Country'];
switch ($params['additionalfields']['Application Purpose']) {
case "Business use for profit":
$request_params['RegistrantPurpose'] = "P1";
break;
case "Non-profit business":
case "Club":
case "Association":
case "Religious Organization":
$request_params['RegistrantPurpose'] = "P2";
break;
case "Educational purposes":
$request_params['RegistrantPurpose'] = "P4";
break;
case "Government purposes":
$request_params['RegistrantPurpose'] = "P5";
break;
case "Personal Use":
default:
$request_params['RegistrantPurpose'] = "P3";
break;
}
} elseif ('ca' == strtolower($tld)) {
$request_params['CIRAWhoisDisplay'] = ("on" == $params['additionalfields']['WHOIS Opt-out']) ? "Private" : "Full";
$request_params['CIRAAgreementVersion'] = "2.0";
$request_params['CIRAAgreementValue'] = ("on" == $params['additionalfields']['CIRA Agreement']) ? "Y" : "";
$request_params['CIRALanguage'] = "en";
if(!empty($params['additionalfields']['jobTitle'])){
$jobTitle = $params['additionalfields']['jobTitle'];
}else if(!empty($params['additionalfields']['Job Title'])){
$jobTitle = $params['additionalfields']['Job Title'];
}else{
$jobTitle = 'Director';
}
$request_params['RegistrantJobTitle'] = $jobTitle;
$request_params['AdminJobTitle'] = $jobTitle;
$request_params['TechJobTitle'] = $jobTitle;
$request_params['AuxBillingJobTitle'] = $jobTitle;
/**
* missing from WHMCS:
* "INB" - Indian Band
* "MAJ" - The Queen
*/
switch ($params['additionalfields']['Legal Type']) {
case 'Corporation':
$request_params['CIRALegalType'] = "CCO";
break;
case 'Permanent Resident of Canada':
$request_params['CIRALegalType'] = "RES";
break;
case 'Government':
$request_params['CIRALegalType'] = "GOV";
break;
case 'Canadian Educational Institution':
$request_params['CIRALegalType'] = "EDU";
break;
case 'Canadian Unincorporated Association':
$request_params['CIRALegalType'] = "ASS";
break;
case 'Canadian Hospital':
$request_params['CIRALegalType'] = "HOP";
break;
case 'Partnership Registered in Canada':
$request_params['CIRALegalType'] = "PRT";
break;
case 'Trade-mark registered in Canada':
$request_params['CIRALegalType'] = "TDM";
break;
case 'Canadian Trade Union':
$request_params['CIRALegalType'] = "TRD";
break;
case 'Canadian Political Party':
$request_params['CIRALegalType'] = "PLT";
break;
case 'Canadian Library Archive or Museum':
$request_params['CIRALegalType'] = "LAM";
break;
case 'Trust established in Canada':
$request_params['CIRALegalType'] = "TRS";
break;
case 'Aboriginal Peoples':
$request_params['CIRALegalType'] = "ABO";
break;
case 'Legal Representative of a Canadian Citizen':
$request_params['CIRALegalType'] = "LGR";
break;
case 'Official mark registered in Canada':
$request_params['CIRALegalType'] = "OMK";
break;
case 'Canadian Citizen':
default:
$request_params['CIRALegalType'] = "CCT";
break;
}
} elseif ('co.uk' == strtolower($tld) || 'org.uk' == strtolower($tld) || 'me.uk' == strtolower($tld)) {
$key = strtoupper(str_replace('.', '', $tld));
$request_params[$key . 'CompanyID'] = $params['additionalfields']['Company ID Number'];
$request_params[$key . 'Registeredfor'] = $params['additionalfields']['Registrant Name'];
/**
* missing from WHMCS:
* "FIND" - Non-UK individual
* "IP" - UK Industrial/Provident Registered Company
* "SCH" - UK School
* "GOV" - UK Government Body
* "CRC" - UK Corporation by Royal Charter
* "STAT" - UK Statutory Body FIND
*/
switch ($params['Legal Type']) {
case 'UK Limited Company':
$request_params[$key . 'LegalType'] = "LTD";
break;
case 'UK Public Limited Company':
$request_params[$key . 'LegalType'] = "PLC";
break;
case 'UK Partnership':
$request_params[$key . 'LegalType'] = "PTNR";
break;
case 'UK Limited Liability Partnership':
$request_params[$key . 'LegalType'] = "LLP";
break;
case 'Sole Trader':
$request_params[$key . 'LegalType'] = "STRA";
break;
case 'UK Registered Charity':
$request_params[$key . 'LegalType'] = "RCHAR";
break;
case 'UK Entity (other)':
$request_params[$key . 'LegalType'] = "OTHER";
break;
case 'Foreign Organization':
$request_params[$key . 'LegalType'] = "FCORP";
break;
case 'Other foreign organizations':
$request_params[$key . 'LegalType'] = "FOTHER";
break;
case 'Individual':
default:
$request_params[$key . 'LegalType'] = "IND";
break;
}
} elseif ('de' == strtolower($tld)) {
$request_params['DEConfirmAddress'] = "DE";
$request_params['DEAgreeDelete'] = "Yes";
} elseif ('asia' == strtolower($tld)) {
$request_params['ASIACCLocality'] = $params['additionalfields']['Locality'];
$request_params['ASIALegalEntityType'] = $params['additionalfields']['Legal Type'];
$request_params['ASIAIdentForm'] = $params['additionalfields']['Identity Form'];
$request_params['ASIAIdentNumber'] = $params['additionalfields']['Identity Number'];
} elseif('sg' == strtolower($tld)){
$request_params['SGRCBID'] = $params['additionalfields']['RCB Singapore ID'];
$request_params['SGAdminId'] = $params['additionalfields']['Admin ID'];
} elseif('com.sg' == strtolower($tld)){
$request_params['COMSGRCBID'] = $params['additionalfields']['RCB Singapore ID'];
$request_params['COMSGAdminId'] = $params['additionalfields']['Admin ID'];
} elseif ('com.au' == strtolower($tld) || 'net.au' == strtolower($tld) || 'org.au' == strtolower($tld)){
$key_prefix = strtoupper(str_replace('.','',$tld));
$request_params[$key_prefix.'RegistrantId'] = $params['additionalfields']['Registrant ID'];
if('Business Registration Number' == $params['additionalfields']['Registrant ID Type']){
$params['additionalfields']['Registrant ID Type'] = 'RBN';
}
$request_params[$key_prefix.'RegistrantIdType'] = $params['additionalfields']['Registrant ID Type'];
if(!empty($params['additionalfields']['jobTitle'])){
$jobTitle = $params['additionalfields']['jobTitle'];
}else if(!empty($params['additionalfields']['Job Title'])){
$jobTitle = $params['additionalfields']['Job Title'];
}else{
$jobTitle = 'Director';
}
$request_params['RegistrantJobTitle'] = $jobTitle;
$request_params['AdminJobTitle'] = $jobTitle;
$request_params['TechJobTitle'] = $jobTitle;
$request_params['AuxBillingJobTitle'] = $jobTitle;
} elseif('es' == strtolower($tld)||'com.es' == strtolower($tld)||'nom.es' == strtolower($tld)||'org.es' == strtolower($tld)){
$key_prefix = strtoupper(str_replace('.','',$tld));
if(!empty($params['additionalfields']['Registrant ID Type']))
$request_params[$key_prefix.'RegistrantIdType'] = $params['additionalfields']['Registrant ID Type'];
if(!empty($params['additionalfields']['Registrant ID']))
$request_params[$key_prefix.'RegistrantId'] = $params['additionalfields']['Registrant ID'];
if(!empty($params['additionalfields']['Legal Form']))
$request_params[$key_prefix.'LegalFormType'] = $params['additionalfields']['Legal Form'];
if(!empty($params['additionalfields']['I accept the .ES terms and conditions']))
$request_params[$key_prefix.'AcceptAgreement'] = 'Yes';
if(!empty($params['additionalfields']['Admin ID']))
$request_params[$key_prefix.'AdminId'] = $params['additionalfields']['Admin ID'];
if(!empty($params['additionalfields']['Admin ID Type']))
$request_params[$key_prefix.'AdminIdType'] = $params['additionalfields']['Admin ID Type'];
} elseif ('fr' == strtolower($tld)){
if(!empty($params['additionalfields']['Legal Type'])){
$request_params['FRLegalType'] = $params['additionalfields']['Legal Type'];
}
if(!empty($params['additionalfields']['Date of Birth'])){
$request_params['FRRegistrantBirthDate'] = $params['additionalfields']['Date of Birth'];
}
if(!empty($params['additionalfields']['Place of Birth'])){
$request_params['FRRegistrantBirthPlace'] = $params['additionalfields']['Place of Birth'];
}
if(!empty($params['additionalfields']['Legal Id'])){
$request_params['FRRegistrantLegalId'] = $params['additionalfields']['Legal Id'];
}
if(!empty($params['additionalfields']['Trade Number'])){
$request_params['FRRegistrantTradeNumber'] = $params['additionalfields']['Trade Number'];
}
if(!empty($params['additionalfields']['Duns Number'])){
$request_params['FRRegistrantDunsNumber'] = $params['additionalfields']['Duns Number'];
}
if(!empty($params['additionalfields']['Local Id'])){
$request_params['FRRegistrantLocalId'] = $params['additionalfields']['Local Id'];
}
if(!empty($params['additionalfields']['Journal Date of Declaration'])){
$request_params['FRRegistrantJoDateDec'] = $params['additionalfields']['Journal Date of Declaration'];
}
if(!empty($params['additionalfields']['Journal Date of Publication'])){
$request_params['FRRegistrantJoDatePub'] = $params['additionalfields']['Journal Date of Publication'];
}
if(!empty($params['additionalfields']['Journal Number'])){
$request_params['FRRegistrantJoNumber'] = $params['additionalfields']['Journal Number'];
}
if(!empty($params['additionalfields']['Journal Page'])){
$request_params['FRRegistrantJoPage'] = $params['additionalfields']['Journal Page'];
}
}
$api = new NamecheapRegistrarApi($username, $password, $testmode, $debugmode);
$response = $api->request("namecheap.domains.create", $request_params);
$result = $api->parseResponse($response);
if (isset($result['DomainCreateResult']['warnings']['Warning'])) {
$message = "Registering Domain warning<br />"
. "-----------------------------------------------------------------------------------------<br />"
. $result['DomainCreateResult']['warnings']['Warning']['@value'] . "<br />"
. "-----------------------------------------------------------------------------------------<br />"
. "Domain: " . $tld . "." . $sld . "<br />"
. "Nameservers: " . implode(',', $nameservers);
sendadminnotification("system", "WHMCS Namecheap Domain Registrar Module", $message);
}
}
catch (Exception $e) {
$values['error'] = "An error occurred: " . $e->getMessage();
if (!$debugmode){
logModuleCall('namecheap', 'RegisterDomain', array('command' => "namecheap.domains.create") + $request_params, $response, $result, array());
}
}
return $values;
}
function namecheap_TransferDomain($params)
{
require_once dirname(__FILE__) . "/namecheapapi.php";
$testmode = (bool)$params['TestMode'];
$debugmode =(bool)$params['DebugMode'];
$username = $testmode ? $params['SandboxUsername'] : $params['Username'];
$password = $testmode ? $params['SandboxPassword'] : $params['Password'];
$tld = $params['tld'];
$sld = $params['sld'];
$oIDNA = new NamecheapRegistrarIDNA($sld, $tld);
$sld = $oIDNA->getEncodedSld();
try
{
$request_params = array(
'DomainName' => $sld . '.' . $tld,
'Years' => $params['regperiod'],
'EPPCode' => $params['transfersecret']
);
if (!empty($params['PromotionCode'])) {
$request_params['PromotionCode'] = $params['PromotionCode'];
}
//$wg_ex = array("bz", "ca", "cn", "co.uk", "de", "eu", "in", "me.uk", "mobi", "nu", "org.uk", "us", "ws");
if ($params['idprotection']) {
$request_params['AddFreeWhoisguard'] = "yes";
$request_params['WGEnabled'] = "yes";
}
$api = new NamecheapRegistrarApi($username, $password, $testmode, $debugmode);
$response = $api->request("namecheap.domains.transfer.create", $request_params);
$result = $api->parseResponse($response);
}
catch (Exception $e) {
$values['error'] = "An error occurred: " . $e->getMessage();
if (!$debugmode){
logModuleCall('namecheap', 'TransferDomain', array('command' => "namecheap.domains.transfer.create") + $request_params, $response, $result, array());
}
}
return $values;
}
function namecheap_RenewDomain($params)
{
require_once dirname(__FILE__) . "/namecheapapi.php";
$testmode = (bool)$params['TestMode'];
$debugmode =(bool)$params['DebugMode'];
$username = $testmode ? $params['SandboxUsername'] : $params['Username'];
$password = $testmode ? $params['SandboxPassword'] : $params['Password'];
$tld = $params['tld'];
$sld = $params['sld'];
$oIDNA = new NamecheapRegistrarIDNA($sld, $tld);
$sld = $oIDNA->getEncodedSld();
$exCode = 0;
try
{
$request_params = array(
'DomainName' => $sld . '.' . $tld,
'Years' => $params['regperiod']
);
if (!empty($params['PromotionCode'])) {
$request_params['PromotionCode'] = $params['PromotionCode'];
}
$api = new NamecheapRegistrarApi($username, $password, $testmode, $debugmode);
$response = $api->request("namecheap.domains.renew", $request_params);
$result = $api->parseResponse($response);
$values['status'] = "Domain Renewed";
}
catch (Exception $e) {
$exCode = $e->getCode();
$values['error'] = "An error occurred: " . $e->getMessage();
}
if ($exCode != 2020166) {
return $values;
}
// domain has expired, we need to reactivate it
try
{
unset($values['error']);
unset($request_params['Years']);