-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmetaregistrar.php
executable file
·2062 lines (1869 loc) · 74 KB
/
metaregistrar.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
require_once("3rdparty/domain/IRegistrar.php");
require_once("3rdparty/domain/standardfunctions.php");
require_once("3rdparty/domain/metaregistrar/autoloader.php");
/**
* -------------------------------------------------------------------------------------
* Metaregistrar - IRegistrar
*
* Author : Ewout de Graaf
* Copyright : (c) 2018 Metaregistrar BV
* Version : 1.0
*
* CHANGE LOG:
* -------------------------------------------------------------------------------------
* 2017-08-18 E.W. de Graaf Initial version
* 2017-08-23 E.W. de Graaf Added DNS management
* -------------------------------------------------------------------------------------
*/
class metaregistrar implements IRegistrar
{
public $User;
public $Password;
public $Error;
public $Warning;
public $Success;
public $Period = 1;
public $registrarHandles = array();
private $ClassName;
/**
* The connection to Metaregistrar EPP
* @var \Metaregistrar\EPP\eppConnection
*/
private $conn;
/**
* Indicates if the user is loggedin, useful for repetitive functions and cleanup
* @var bool
*/
private $loggedin;
/**
* metaregistrar constructor.
*/
function __construct(){
$this->ClassName = __CLASS__;
$this->Error = array();
$this->Warning = array();
$this->Success = array();
return true;
}
/**
* metaregistrar destructor
*/
function __destruct(){
//$this->logout();
return true;
}
/*
*
* METAREGISTRAR CONNECTION FUNCTIONS
* These functions make use of https://github.com/metaregistrar/php-epp-client for EPP connection
*
*
*
*
*
*/
/**
* @return bool
*/
private function login() {
try {
$this->conn = new Metaregistrar\EPP\metaregEppConnection();
// Set parameters
$this->conn->setHostname('ssl://eppl.metaregistrar.com');
$this->conn->setPort(7000);
$this->conn->setUsername($this->User);
$this->conn->setPassword($this->Password);
$this->conn->setConnectionComment("Wefact user");
// Send EPP login command
if ($this->conn->login()) {
// $this->Success[] = "Succesfully logged-in to metaregistrar with user ".$this->User;
$this->loggedin = true;
return true;
} else {
$this->Error[] = "Unable to login with user id: ".$this->User;
return false;
}
} catch (Metaregistrar\EPP\eppException $e) {
$this->Error[] = $e->getMessage();
return false;
}
}
/**
*
*/
private function logout() {
// Log out of EPP when still connected
if ($this->conn) {
if ($this->loggedin) {
// When still logged-in, logout
$this->conn->logout();
$this->loggedin = false;
}
$this->conn->disconnect();
}
}
private function generateauth($length = 12) {
srand((double)microtime()*1000000);
$str = '';
$characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789=+#@%_';
$max = strlen($characters) - 1;
for ($i = 0; $i < $length; $i++) {
$rand = mt_rand(0, $max);
$str .= $characters[$rand];
}
return $str;
}
/**
* Create a new domain name
* @param $domainname
* @param $registrant
* @param $adminc
* @param $techc
* @param $nameservers
* @param $period
* @param $authcode
* @return bool
*/
private function mtrcreatedomain($domainname, $registrant, $adminc, $techc, $nameservers, $period, $authcode) {
if (!$this->loggedin) {
if (!$this->login()) {
return false;
}
}
try {
$domain = new \Metaregistrar\EPP\eppDomain($domainname);
// Set domain parameters
$domain->setRegistrant($registrant);
$domain->addContact(new \Metaregistrar\EPP\eppContactHandle($adminc,\Metaregistrar\EPP\eppContactHandle::CONTACT_TYPE_ADMIN));
$domain->addContact(new \Metaregistrar\EPP\eppContactHandle($techc,\Metaregistrar\EPP\eppContactHandle::CONTACT_TYPE_TECH));
$domain->addContact(new \Metaregistrar\EPP\eppContactHandle($techc,\Metaregistrar\EPP\eppContactHandle::CONTACT_TYPE_BILLING));
if (is_array($nameservers)) {
foreach ($nameservers as $ns) {
if (strlen($ns) > 0) {
if (!filter_var($ns, FILTER_VALIDATE_IP)) {
$domain->addHost(new \Metaregistrar\EPP\eppHost($ns));
}
}
}
}
$domain->setPeriod($period);
$domain->setPeriodUnit('y');
$domain->setAuthorisationCode($authcode);
// Make EPP request to create domain
$create = new \Metaregistrar\EPP\eppCreateDomainRequest($domain);
// Send the request
if ($response = $this->conn->request($create)) {
/* @var $response \Metaregistrar\EPP\eppCreateDomainResponse */
// Process the response
if (($response->getResultCode()==1000) || ($response->getResultCode()==1001)) {
return true;
} else {
$this->Error[] = $response->getResultMessage().' '.$response->getResultReason();
return false;
}
} // ELSE function is caught by eppException
} catch (Metaregistrar\EPP\eppException $e) {
$this->Error[] = $e->getMessage();
return false;
}
$this->Error[] = 'Algemene fout opgetreden bij aanvragen van domeinnaam '.$domainname;
return false;
}
/**
* Request transfer of a domain name
* @param $domainname
* @param $registrant
* @param $adminc
* @param $techc
* @param $nameservers
* @param $period
* @param $authcode
* @return bool
*/
private function mtrtransferdomain($domainname, $registrant, $adminc, $techc, $nameservers, $period, $authcode) {
if (!$this->loggedin) {
if (!$this->login()) {
return false;
}
}
try {
// Set domain transfer parameters
$domain = new \Metaregistrar\EPP\eppDomain($domainname);
$domain->setRegistrant($registrant);
$domain->addContact(new \Metaregistrar\EPP\eppContactHandle($adminc,\Metaregistrar\EPP\eppContactHandle::CONTACT_TYPE_ADMIN));
$domain->addContact(new \Metaregistrar\EPP\eppContactHandle($techc,\Metaregistrar\EPP\eppContactHandle::CONTACT_TYPE_TECH));
$domain->addContact(new \Metaregistrar\EPP\eppContactHandle($techc,\Metaregistrar\EPP\eppContactHandle::CONTACT_TYPE_BILLING));
if (is_array($nameservers)) {
foreach ($nameservers as $ns) {
if (strlen($ns) > 0) {
if (!filter_var($ns, FILTER_VALIDATE_IP)) {
$domain->addHost(new \Metaregistrar\EPP\eppHost($ns));
}
}
}
}
$domain->setPeriod($period);
$domain->setPeriodUnit('y');
$domain->setAuthorisationCode($authcode);
// Create an EPP transfer request
$transfer = new \Metaregistrar\EPP\metaregEppTransferExtendedRequest(\Metaregistrar\EPP\eppTransferRequest::OPERATION_REQUEST,$domain);
// Send the EPP request
if ($response = $this->conn->request($transfer)) {
/* @var $response \Metaregistrar\EPP\eppTransferResponse */
// Process the response
if (($response->getResultCode()==1000) || ($response->getResultCode()==1001)) {
return true;
} else {
$this->Error[] = $response->getResultMessage().' '.$response->getResultReason();
return false;
}
}
} catch (Metaregistrar\EPP\eppException $e) {
$this->Error[] = $e->getMessage();
return false;
}
$this->Error[] = 'Algemene fout opgetreden bij aanvragen van domeinnaam '.$domainname;
return false;
}
private function mtrupdatecontact($handle, $whois) {
if (!$this->loggedin) {
if (!$this->login()) {
return false;
}
}
try {
// Set the handle to be updated
$contacthandle = new \Metaregistrar\EPP\eppContactHandle($handle);
// Set the contact parameters for update
$postalinfo = new \Metaregistrar\EPP\eppContactPostalInfo($whois->ownerInitials.' '.$whois->ownerSurName, $whois->ownerCity, $whois->ownerCountry, $whois->ownerCompanyName, $whois->ownerAddress, '', $whois->ownerZipCode);
if (strlen($whois->ownerFaxNumber) > 0) {
$whois->ownerFaxNumber = $whois->CountryCode.'.'.$whois->ownerFaxNumber;
}
if (strlen($whois->ownerPhoneNumber) > 0) {
$whois->ownerPhoneNumber = $whois->CountryCode.'.'.$whois->ownerPhoneNumber;
}
$contact = new \Metaregistrar\EPP\eppContact($postalinfo, $whois->ownerEmailAddress, $whois->ownerPhoneNumber, $whois->ownerFaxNumber);
// Create an EPP update request
$update = new \Metaregistrar\EPP\eppUpdateContactRequest($contacthandle, null, null, $contact);
// Send the EPP request
if ($response = $this->conn->request($update)) {
/* @var $response \Metaregistrar\EPP\eppUpdateContactResponse */
// Process the response
if ($response->getResultCode() == 1000) {
return true;
} else {
$this->Error[] = $response->getResultMessage(). ' '.$response->getResultReason();
return false;
}
}
} catch (Metaregistrar\EPP\eppException $e) {
$this->Error[] = $e->getMessage();
return false;
}
$this->Error[] = 'Algemene fout opgetreden bij bijwerken van contact '.$handle;
return false;
}
/**
* @param $whois
* @return bool|string
*/
private function mtrcreatecontact($whois) {
if (!$this->loggedin) {
if (!$this->login()) {
return false;
}
}
try {
// Set the contact parameters
$postalinfo = new \Metaregistrar\EPP\eppContactPostalInfo(htmlspecialchars_decode($whois->ownerInitials).' '.htmlspecialchars_decode($whois->ownerSurName), $whois->ownerCity, $whois->ownerCountry, htmlspecialchars_decode($whois->ownerCompanyName), htmlspecialchars_decode($whois->ownerAddress), '', $whois->ownerZipCode);
if (strlen($whois->ownerFaxNumber) > 0) {
if (strpos($whois->ownerFaxNumber,'+31.')===false) {
$whois->ownerFaxNumber = $whois->CountryCode . '.' . $whois->ownerFaxNumber;
}
}
if (strlen($whois->ownerPhoneNumber) > 0) {
if (strpos($whois->ownerPhoneNumber,'+31.')===false) {
$whois->ownerPhoneNumber = $whois->CountryCode.'.'.$whois->ownerPhoneNumber;
}
}
$contact = new \Metaregistrar\EPP\eppContact($postalinfo, $whois->ownerEmailAddress, $whois->ownerPhoneNumber, $whois->ownerFaxNumber);
// Create an EPP contact:create request
$create = new \Metaregistrar\EPP\eppCreateContactRequest($contact);
// Send the request
if ($response = $this->conn->request($create)) {
/* @var $response \Metaregistrar\EPP\eppCreateContactResponse */
// Handle the response
if ($response->getResultCode() == 1000) {
return $response->getContactId();
} else {
$this->Error[] = $response->getResultMessage(). ' '.$response->getResultReason();
return false;
}
}
} catch (Metaregistrar\EPP\eppException $e) {
$this->Error[] = $e->getMessage();
return false;
}
$this->Error[] = 'Algemene fout opgetreden bij aanmaken nieuw contact';
return false;
}
/**
* Retrieve information on a domain name
* @param $domainname
* @return array|bool
*/
private function mtrgetdomaininfo($domainname) {
if (!$this->loggedin) {
if (!$this->login()) {
return false;
}
}
try {
// Set the domain to be infoed
$domain = new \Metaregistrar\EPP\eppDomain($domainname);
// Create the EPP domain:info request
$request = new \Metaregistrar\EPP\eppInfoDomainRequest($domain);
// Send the EPP request
if ($response = $this->conn->request($request)) {
/* @var $response \Metaregistrar\EPP\eppInfoDomainResponse */
// Handle the response
$info = [];
$info['registrant'] = $response->getDomainRegistrant();
$info['admin-c'] = $response->getDomainContact(\Metaregistrar\EPP\eppContactHandle::CONTACT_TYPE_ADMIN);
$info['tech-c'] = $response->getDomainContact(\Metaregistrar\EPP\eppContactHandle::CONTACT_TYPE_TECH);
$info['authcode'] = $response->getDomainAuthInfo();
$info['credate'] = $response->getDomainCreateDate();
$info['expdate'] = $response->getDomainExpirationDate();
$info['nameservers'] = explode(',',$response->getDomainNameserversCSV());
return $info;
}
} catch (Metaregistrar\EPP\eppException $e) {
$this->Error[] = $e->getMessage();
return false;
}
$this->Error[] = 'Algemene fout opgetreden bij opvragen domeinnaam informatie van '.$domainname;
return false;
}
/**
* Get all contents of a contact object
* @param string $handle
* @return bool|array
*/
private function mtrgetcontactinfo($handle) {
if (!$this->loggedin) {
if (!$this->login()) {
return false;
}
}
try {
// Set the contact handle to be queried
$contact = new \Metaregistrar\EPP\eppContactHandle($handle);
// Create an EPP contact:info request
$request = new \Metaregistrar\EPP\eppInfoContactRequest($contact);
// Send the request
if ($response = $this->conn->request($request)) {
/* @var $response \Metaregistrar\EPP\eppInfoContactResponse */
// Handle the response
$info = [];
$postalinfo = $response->getContactPostalInfo();
/* @var $postalinfo \Metaregistrar\EPP\eppContactPostalInfo */
$info['company'] = $postalinfo[0]->getOrganisationName();
$info['name'] = $postalinfo[0]->getName();
$info['address'] = $postalinfo[0]->getStreet(0);
$info['postcode'] = $postalinfo[0]->getZipcode();
$info['city'] = $postalinfo[0]->getCity();
$info['countrycode'] = $postalinfo[0]->getCountrycode();
$info['phone'] = $response->getContactVoice();
$info['fax'] = $response->getContactFax();
$info['email'] = $response->getContactEmail();
return $info;
}
} catch (Metaregistrar\EPP\eppException $e) {
$this->Error[] = $e->getMessage();
return false;
}
$this->Error[] = 'Algemene fout opgetreden bij opvragen contact informatie van '.$handle;
return false;
}
/**
* @param string $domainname
* @param bool $autorenew
* @return bool
*/
private function mtrupdateautorenew($domainname, $autorenew) {
if (!$this->loggedin) {
if (!$this->login()) {
return false;
}
}
try {
// Set the domain to be updated
$domain = new \Metaregistrar\EPP\eppDomain($domainname);
// Create EPP domain:update request with autorenew extension
$update = new \Metaregistrar\EPP\metaregEppAutorenewRequest($domain,$autorenew);
// Send the request
if ($response = $this->conn->request($update)) {
// Handle the response
if ($response->getResultCode() == 1000) {
return true;
}
} else {
$this->Error[] = $response->getResultMessage();
return false;
}
} catch (Metaregistrar\EPP\eppException $e) {
$this->Error[] = $e->getMessage();
return false;
}
$this->Error[] = 'Algemene fout opgetreden bij wijzigen nameserver informatie van '.$domainname;
return false;
}
/**
* Update the nameservers of the domain name. Specify the new set of nameservers as wanted, the system will determine the changes to be made
* @param $domainname
* @param $nameservers
* @return bool
*/
private function mtrupdatenameservers($domainname, $nameservers) {
if (!$this->loggedin) {
if (!$this->login()) {
return false;
}
}
try {
// First get the current nameservers of this domain name
$info = $this->mtrgetdomaininfo($domainname);
if ($info) {
// Process the current nameservers to see if the new ones are already in there
$oldns = $info['nameservers'];
foreach ($nameservers as $index=>$ns) {
if (in_array($ns,$oldns)) {
// If the new nameservers are already in the current nameservers, nothing has to be removed or added
$ind = array_search($ns,$oldns);
unset($oldns[$ind]);
unset($nameservers[$index]);
}
}
// Check if we still have nameservers left to add or remove
if ((count($nameservers) > 0) || (count($oldns) > 0)) {
$domain = new \Metaregistrar\EPP\eppDomain($domainname);
$add = null;
// There are still nameservers left to add
if (count($nameservers) > 0) {
$add = new \Metaregistrar\EPP\eppDomain($domainname);
foreach ($nameservers as $ns) {
if (strlen($ns) > 0) {
$add->addHost(new \Metaregistrar\EPP\eppHost($ns));
}
}
}
$rem = null;
// There are still nameservers left to be removed
if (count($oldns) > 0) {
$rem = new \Metaregistrar\EPP\eppDomain($domainname);
foreach ($oldns as $ns) {
if (strlen($ns) > 0) {
$rem->addHost(new \Metaregistrar\EPP\eppHost($ns));
}
}
}
// Create the EPP domain:update request
$update = new \Metaregistrar\EPP\eppUpdateDomainRequest($domain, $add, $rem, null);
// Send the request
if ($response = $this->conn->request($update)) {
/* @var $response \Metaregistrar\EPP\eppUpdateDomainResponse */
// Handle the response
if ($response->getResultCode() == 1000) {
return true;
}
}
} else {
return true;
}
} else {
return false;
}
} catch (Metaregistrar\EPP\eppException $e) {
$this->Error[] = $e->getMessage();
return false;
}
$this->Error[] = 'Algemene fout opgetreden bij wijzigen nameserver informatie van '.$domainname;
return false;
}
/**
* Check if a domain name is free or taken
* @param string $domainname
* @return bool
*/
private function mtrcheckdomain($domainname) {
if (!$this->loggedin) {
if (!$this->login()) {
return false;
}
}
try {
// The domain name to be checked
$domain = new \Metaregistrar\EPP\eppDomain($domainname);
// Create an EPP domain:check request
$check = new \Metaregistrar\EPP\eppCheckDomainRequest($domain);
// Send the request
if ($response = $this->conn->request($check)) {
/* @var $response \Metaregistrar\EPP\eppCheckDomainResponse */
// Handle the response
$test = $response->getCheckedDomains();
return $test[0]['available'];
} else {
$this->Error[] = 'Error checking domain name '.$domainname;
return false;
}
} catch (Metaregistrar\EPP\eppException $e) {
$this->Error[] = $e->getMessage();
return false;
}
}
/**
* Cancel a domain name
* @param string $domainname
* @return bool
*/
private function mtrdeletedomain($domainname) {
if (!$this->loggedin) {
if (!$this->login()) {
return false;
}
}
try {
// Set the domain to be deleted
$domain = new \Metaregistrar\EPP\eppDomain($domainname);
// Create an EPP domain:delete request
$delete = new \Metaregistrar\EPP\eppDeleteDomainRequest($domain);
// Send the EPP request
if ($response = $this->conn->request($delete)) {
/* @var $response \Metaregistrar\EPP\eppDeleteResponse */
// Handle the response
if (($response->getResultCode() == 1000) || ($response->getResultCode() == 1001)) {
return true;
}
} else {
$this->Error[] = 'Error deleting domain name '.$domainname;
return false;
}
} catch (Metaregistrar\EPP\eppException $e) {
$this->Error[] = $e->getMessage();
return false;
}
$this->Error[] = 'General error deleting domain name '.$domainname;
return false;
}
/**
* Put a domain name on clientHold or remove the clientHold
* @param $domainname
* @param $lock
* @return bool
*/
function mtrlockdomain($domainname, $lock) {
if (!$this->loggedin) {
if (!$this->login()) {
return false;
}
}
try {
// Set the domain name to be locked
$domain = new \Metaregistrar\EPP\eppDomain($domainname);
// Set the lock parameters, which lock to apply
$change = new \Metaregistrar\EPP\eppDomain($domainname);
$change->addStatus(\Metaregistrar\EPP\eppDomain::STATUS_CLIENT_HOLD);
if ($lock) {
// Add the lock status
$update = new \Metaregistrar\EPP\eppUpdateDomainRequest($domain,$change,null,null);
} else {
// Remove the lock status
$update = new \Metaregistrar\EPP\eppUpdateDomainRequest($domain, null,$change,null);
}
// Send the EPP request
if ($response = $this->conn->request($update)) {
/* @var $response \Metaregistrar\EPP\eppUpdateDomainResponse */
// Handle the response
if (($response->getResultCode() == 1000) || ($response->getResultCode() == 1001)) {
return true;
}
} else {
$this->Error[] = 'Error locking domain name '.$domainname;
return false;
}
} catch (Metaregistrar\EPP\eppException $e) {
$this->Error[] = $e->getMessage();
return false;
}
$this->Error[] = 'General error occurred locking domain name '.$domainname;
return false;
}
/**
* Get all DNS records for a specific domain name
* @param string $domainname
* @return array|bool
*/
function mtrgetdnszone($domainname) {
if (!$this->loggedin) {
if (!$this->login()) {
return false;
}
}
try {
$domain = new \Metaregistrar\EPP\eppDomain($domainname);
$request = new \Metaregistrar\EPP\metaregInfoDnsRequest($domain);
if ($response = $this->conn->request($request)) {
/* @var $response \Metaregistrar\EPP\metaregInfoDnsResponse */
$content = $response->getContent();
return $content;
} else {
$this->Error[] = 'Error retrieving DNS for '.$domainname;
return false;
}
} catch (Metaregistrar\EPP\eppException $e) {
if ($e->getCode()==2303) {
$this->mtrcreatednszone($domainname);
$this->Error[] = "Er waren nog geen DNS gegevens bekend voor deze domeinnaam. De zone is nu aangemaakt, klik opnieuw op 'DNS beheer' om deze te bewerken";
return false;
} else {
$this->Error[] = $e->getMessage();
return false;
}
}
}
function mtrcreatednszone($domainname) {
if (!$this->loggedin) {
if (!$this->login()) {
return false;
}
}
try {
$domain = new \Metaregistrar\EPP\eppDomain($domainname);
$records = [];
$records[] = ['type' => 'NS', 'name' => $domainname, 'content' => 'ns1.yourdomainprovider.net', 'ttl' => 3600];
$records[] = ['type' => 'NS', 'name' => $domainname, 'content' => 'ns2.yourdomainprovider.net', 'ttl' => 3600];
$records[] = ['type' => 'NS', 'name' => $domainname, 'content' => 'ns3.yourdomainprovider.net', 'ttl' => 3600];
$request = new \Metaregistrar\EPP\metaregCreateDnsRequest($domain,$records);
if ($response = $this->conn->request($request)) {
/* @var $response \Metaregistrar\EPP\metaregInfoDnsResponse */
return true;
} else {
$this->Error[] = 'Error retrieving DNS for '.$domainname;
return false;
}
} catch (Metaregistrar\EPP\eppException $e) {
$this->Error[] = $e->getMessage();
return false;
}
}
/**
* Update the DNS information, add and remove records in the DNS
* @param string $domainname
* @param array $adds
* @param array $dels
* @return bool
*/
private function mtrupdatednszone($domainname, $adds, $dels) {
try {
$domain = new Metaregistrar\EPP\eppDomain($domainname);
if (count($adds) == 0) {
$adds = null;
}
if (count($dels) == 0) {
$dels = null;
}
$update= new Metaregistrar\EPP\metaregUpdateDnsRequest($domain,$adds,$dels,null);
$this->Success[] = $update->saveXML();
if ($response = $this->conn->request($update)) {
if ($response->getResultCode()==1000) {
return true;
} else {
$this->Error[] = $response->getResultMessage();
return false;
}
} else {
$this->Error[] = "Error updating DNS";
return false;
}
} catch (\Metaregistrar\EPP\eppException $e) {
$this->Error[] = $e->getMessage();
return false;
}
}
/*
*
* STANDARD Wefact functions
* These functions come with the standard Wefact implemenation and call the metaregistrar functions where applicable
*
*
*
*
*
*/
/**
* Check whether a domain is already registered or not.
*
* @param string $domain The name of the domain that needs to be checked.
* @return boolean True if free, False if not free, False and $this->Error[] in case of error.
*/
function checkDomain($domain) {
return $this->mtrcheckdomain($domain);
}
// /**
// * EXAMPLE IF A FUNCTION IS NOT SUPPORTED
// * Check whether a domain is already registered or not.
// *
// * @param string $domain The name of the domain that needs to be checked.
// * @return boolean True if free, False if not free, False and $this->Error[] in case of error.
// */
// function checkDomain($domain) {
// $this->Warning[] = 'Metaregistrar: checking availability for domain '.$domain.' cannot be checked via the API.';
//
// if($this->caller == 'register'){
// return true;
// }elseif($this->caller == 'transfer'){
// return false;
// }
// }
/**
* Register a new domain
*
* @param string $domain The domainname that needs to be registered.
* @param array $nameservers The nameservers for the new domain.
* @param array $whois The customer information for the domain's whois information.
* @return bool True on success; False otherwise.
*/
function registerDomain($domain, $nameservers = array(), $whois = null) {
/** if you use DNS management, the following variables are also available
* $this->DNSTemplateID
* $this->DNSTemplateName
*/
/**
* Step 1) obtain an owner handle
*/
$ownerHandle = "";
// Check if a registrar-specific ownerhandle for this domain already exists.
if (isset($whois->ownerRegistrarHandles[$this->ClassName]))
{
$ownerHandle = $whois->ownerRegistrarHandles[$this->ClassName];
}
// If not, check if WHOIS-data for owner contact is available to search or create new handle
elseif($whois->ownerSurName != "")
{
// Search for existing handle, based on WHOIS data (not supported by the Metaregistrar API)
//$ownerHandle = $this->getContactHandle($whois, HANDLE_OWNER);
// If no existing handle is found, create new handle
if ($ownerHandle == "")
{
// Try to create new handle. In case of failure, quit function
if(!$ownerHandle = $this->createContact($whois, HANDLE_OWNER))
{
return false;
}
}
// If a new handle is created or found, store in array. WeFact will store this data, which will result in faster registration next time.
$this->registrarHandles['owner'] = $ownerHandle;
} else {
// If no handle can be created, because data is missing, quit function
$this->Error[] = sprintf("Metaregistrar: Geen eigenaar ingesteld voor domeinnaam '%s'.", $domain);
return false;
}
/**
* Step 2) obtain an admin handle
*/
$adminHandle = "";
// Check if a registrar-specific adminhandle for this domain already exists.
if (isset($whois->adminRegistrarHandles[$this->ClassName]))
{
$adminHandle = $whois->adminRegistrarHandles[$this->ClassName];
}
// If not, check if WHOIS-data for admin contact is available to search or create new handle
elseif($whois->adminSurName != "")
{
// Search for existing handle, based on WHOIS data (not supported by the Metaregistrar API)
//$adminHandle = $this->getContactHandle($whois, HANDLE_ADMIN);
// If no existing handle is found, create new handle
if ($adminHandle == "")
{
// Try to create new handle. In case of failure, quit function
if(!$adminHandle = $this->createContact($whois, HANDLE_ADMIN))
{
return false;
}
}
// If a new handle is created or found, store in array. WeFact will store this data, which will result in faster registration next time.
$this->registrarHandles['admin'] = $adminHandle;
} else {
// If no handle can be created, because data is missing, quit function
$this->Error[] = sprintf("Metaregistrar: Geen admin-c ingegeven voor domeinnaam '%s'.", $domain);
return false;
}
/**
* Step 3) obtain a tech handle
*/
$techHandle = "";
// Check if a registrar-specific techhandle for this domain already exists.
if (isset($whois->techRegistrarHandles[$this->ClassName]))
{
$techHandle = $whois->techRegistrarHandles[$this->ClassName];
}
// If not, check if WHOIS-data for tech contact is available to search or create new handle
elseif($whois->techSurName != "")
{
// Search for existing handle, based on WHOIS data (not supported by the Metaregistrar API)
//$techHandle = $this->getContactHandle($whois, HANDLE_TECH);
// If no existing handle is found, create new handle
if ($techHandle == "")
{
// Try to create new handle. In case of failure, quit function
if(!$techHandle = $this->createContact($whois, HANDLE_TECH))
{
return false;
}
}
// If a new handle is created or found, store in array. WeFact will store this data, which will result in faster registration next time.
$this->registrarHandles['tech'] = $techHandle;
} else {
// If no handle can be created, because data is missing, quit function
$this->Error[] = sprintf("Metaregistrar: Geen tech-c ingegeven voor domeinnaam '%s'.", $domain);
return false;
}
/**
* Step 4) obtain nameserver handles
*/
// If your system uses nameserver groups or handles, you can check the $nameserver array and match these hostnames with your own system.
$requestns = [];
foreach ($nameservers as $index=>$ns) {
// Filter out IP addresses
if (strpos($index,'ip')===false) {
$requestns[] = $ns;
}
}
/**
* Step 5) check your own default settings
*/
// Determine period for registration in years, based on your TLD properties.
// $this->Period is also used in WeFact, for determining the renewal date.
$this->Period = 1;
/**
* Step 6) register domain
*/
// Start registering the domain, you can use $domain, $ownerHandle, $adminHandle, $techHandle, $nameservers
$response = $this->mtrcreatedomain($domain, $ownerHandle, $adminHandle, $techHandle, $requestns, $this->Period, $this->generateauth());
/**
* Step 7) provide feedback to WeFact
*/
return $response;
}
/**
* Transfer a domain to the given user.
*
* @param string $domain The demainname that needs to be transfered.
* @param array $nameservers The nameservers for the tranfered domain.
* @param array $whois The contact information for the new owner, admin, tech and billing contact.
* @return bool True on success; False otherwise;
*/
function transferDomain($domain, $nameservers = array(), $whois = null, $authcode = "") {
/** if you use DNS management, the following variables are also available
* $this->DNSTemplateID
* $this->DNSTemplateName
*/
/**
* Step 1) obtain an owner handle
*/
$ownerHandle = "";
// Check if a registrar-specific ownerhandle for this domain already exists.
if (isset($whois->ownerRegistrarHandles[$this->ClassName]))
{
$ownerHandle = $whois->ownerRegistrarHandles[$this->ClassName];
}
// If not, check if WHOIS-data for owner contact is available to search or create new handle
elseif($whois->ownerSurName != "")
{
// Search for existing handle, based on WHOIS data (not supported by the Metaregistrar API)
//$ownerHandle = $this->getContactHandle($whois, HANDLE_OWNER);
// If no existing handle is found, create new handle
if ($ownerHandle == "")
{
// Try to create new handle. In case of failure, quit function
if(!$ownerHandle = $this->createContact($whois, HANDLE_OWNER))
{
return false;
}
}
// If a new handle is created or found, store in array. WeFact will store this data, which will result in faster transfer next time.
$this->registrarHandles['owner'] = $ownerHandle;
} else {
// If no handle can be created, because data is missing, quit function
$this->Error[] = sprintf("Metaregistrar: Geen eigenaar opgegeven voor domeinnaam '%s'.", $domain);
return false;
}
/**
* Step 2) obtain an admin handle
*/
$adminHandle = "";
// Check if a registrar-specific adminhandle for this domain already exists.
if (isset($whois->adminRegistrarHandles[$this->ClassName]))
{
$adminHandle = $whois->adminRegistrarHandles[$this->ClassName];
}
// If not, check if WHOIS-data for admin contact is available to search or create new handle
elseif($whois->adminSurName != "")
{
// Search for existing handle, based on WHOIS data (not supported by the Metaregistrar API)
//$adminHandle = $this->getContactHandle($whois, HANDLE_ADMIN);
// If no existing handle is found, create new handle
if ($adminHandle == "")
{
// Try to create new handle. In case of failure, quit function
if(!$adminHandle = $this->createContact($whois, HANDLE_ADMIN))
{
return false;
}
}
// If a new handle is created or found, store in array. WeFact will store this data, which will result in faster transfer next time.
$this->registrarHandles['admin'] = $adminHandle;
} else {
// If no handle can be created, because data is missing, quit function
$this->Error[] = sprintf("Metaregistrar: Geen admin-c contact opgegeven voor domeinnaam '%s'.", $domain);
return false;
}
/**