switchepp.php 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349
  1. <?php
  2. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  3. * SWITCH EPP REGISTRAR WHMCS Module By whmcsglobalservices.com
  4. * Copyright whmcsglobalservices, All Rights Reserved
  5. *
  6. * Release: 21 January, 2015
  7. * Version: 3.0.6
  8. * WHMCS Version: v6,v7
  9. * Update Date: 04 Sep, 2019
  10. *
  11. * By WHMCSGLOBALSERVICES https://whmcsglobalservices.com
  12. * Contact info@whmcsglobalservices.com
  13. *
  14. * This module is made under license issued by whmcsglobalservices.com
  15. * and used under all terms and conditions of license. Ownership of
  16. * module can not be changed. Title and copy of module is not
  17. * available to any other person.
  18. *
  19. * @owner <whmcsglobalservices.com>
  20. * @author <WHMCSGLOBALSERVICES>
  21. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  22. use Illuminate\Database\Capsule\Manager as Capsule;
  23. use WGSSWITCHEPP\IDNA\idna_convert as idna_convert;
  24. if (!defined("WHMCS"))
  25. die("This file cannot be accessed directly");
  26. if (!class_exists('Net_EPP_Protocol')) {
  27. if (file_exists(__DIR__ . "/Net/EPP/Client.php"))
  28. require_once __DIR__ . "/Net/EPP/Client.php";
  29. }
  30. require_once(__DIR__ . '/idna_convert.class.php');
  31. #*********************Registrar config options***************************#
  32. function switchepp_getConfigArray() {
  33. $configarray = array(
  34. "FriendlyName" => array(
  35. "Type" => "System",
  36. "Value" => "Switch Epp"
  37. ),
  38. "registrar_id" => array(
  39. "FriendlyName" => "Registrar Id",
  40. "Type" => "text",
  41. "Size" => "50",
  42. ),
  43. "registrar_password" => array(
  44. "FriendlyName" => "Password",
  45. "Type" => "password",
  46. "Size" => "50",
  47. ),
  48. "eppurl" => array(
  49. "FriendlyName" => "EPP URL",
  50. "Type" => "text",
  51. "Size" => "50",
  52. ),
  53. "eppport" => array(
  54. "FriendlyName" => "Port Number",
  55. "Type" => "text",
  56. "Size" => "50",
  57. ),
  58. "licensenum" => array(
  59. "FriendlyName" => "License Key",
  60. "Type" => "text",
  61. "Size" => "50",
  62. ),
  63. "dnssec" => array(
  64. "FriendlyName" => "DNSSEC",
  65. "Type" => "yesno",
  66. ),
  67. "algorithm" => array(
  68. "FriendlyName" => "Algorithm",
  69. 'Type' => 'dropdown',
  70. 'Options' => "5,7,8,10,13,14,15,16",
  71. 'Default' => '5',
  72. ),
  73. "digest_type" => array(
  74. "FriendlyName" => "Digest Type",
  75. 'Type' => 'dropdown',
  76. 'Options' => "1,2,3,4",
  77. 'Default' => '1',
  78. ),
  79. "passphrase" => array(
  80. "FriendlyName" => "Pass Phrase",
  81. "Type" => "password",
  82. "Size" => "30",
  83. "Description" => "It's optional"
  84. ),
  85. "svcExtension" => array(
  86. "FriendlyName" => "Enable svcExtension",
  87. "Type" => "yesno",
  88. "Description" => "Tick if svcExtension supported."
  89. ),
  90. "switchepp_version" => array(
  91. "FriendlyName" => "Version",
  92. "Description" => "3.0.6",
  93. ),
  94. "switchepp_update" => array(
  95. "FriendlyName" => "Updated Date",
  96. "Description" => "04 Sep, 2019",
  97. )
  98. );
  99. return $configarray;
  100. }
  101. #*******************Get Nameserver***********************#
  102. function switchepp_GetNameservers($params) {
  103. try {
  104. $client = switchepp_clientloginepp($params); #Epp Connection
  105. $login = switchepp_loggedinepp($client, $params); #Epp Client login
  106. #get domain info
  107. $xml = switchepp_domain_info($params);
  108. $info_domain = switchepp_write_xml($client, $xml, __FUNCTION__ . '(domain info)');
  109. $ns = $info_domain->response->resData->children("domain", true)->infData->ns->hostObj;
  110. $i = 1;
  111. $values = array();
  112. foreach ($ns as $nn) {
  113. $values["ns{$i}"] = $nn;
  114. $i++;
  115. }
  116. } catch (Exception $ex) {
  117. $values['error'] = $ex->getMessage();
  118. }
  119. if (!empty($client))
  120. switchepp_logoutepp($client, $params);
  121. return $values;
  122. }
  123. #*********************Save mameserver**************************#
  124. function switchepp_SaveNameservers($params) {
  125. try {
  126. $client = switchepp_clientloginepp($params); #Epp Connection
  127. $login = switchepp_loggedinepp($client, $params); #Epp Client login
  128. #get domain info
  129. $xml = switchepp_domain_info($params);
  130. $info_domain = switchepp_write_xml($client, $xml, __FUNCTION__ . '(domain info)');
  131. $ns = $info_domain->response->resData->children("domain", true)->infData->ns->hostObj;
  132. $rem_hosts = '';
  133. foreach ($ns as $nn) {
  134. $rem_hosts .= ' <domain:hostObj>' . $nn . '</domain:hostObj> ';
  135. }
  136. # Generate XML for nameservers
  137. if ($nameserver1 = $params["ns1"]) {
  138. $add_hosts = ' <domain:hostObj>' . $nameserver1 . '</domain:hostObj> ';
  139. }
  140. if ($nameserver2 = $params["ns2"]) {
  141. $add_hosts .= ' <domain:hostObj>' . $nameserver2 . '</domain:hostObj> ';
  142. }
  143. if ($nameserver3 = $params["ns3"]) {
  144. $add_hosts .= ' <domain:hostObj>' . $nameserver3 . '</domain:hostObj> ';
  145. }
  146. if ($nameserver4 = $params["ns4"]) {
  147. $add_hosts .= ' <domain:hostObj>' . $nameserver4 . '</domain:hostObj> ';
  148. }
  149. if ($nameserver5 = $params["ns5"]) {
  150. $add_hosts .= ' <domain:hostObj>' . $nameserver5 . '</domain:hostObj> ';
  151. }
  152. $IDN = new idna_convert();
  153. $input = switcheppGetDomainName($params['domainid']);
  154. $domainname = $IDN->encode($input);
  155. if ($params['dnssec'] == "on") {
  156. $digestType = $params['digest_type'];
  157. if (empty($digestType))
  158. $digestType = 1;
  159. if ($digestType == 1) {
  160. $string = switchepp_generateDigestRandomString(40);
  161. $digest = strtoupper(bin2hex($string));
  162. $digest = substr($digest, 0, 40);
  163. } elseif ($digestType == 2) {
  164. $string = switchepp_generateDigestRandomString(64);
  165. $digest = strtoupper(bin2hex($string));
  166. $digest = substr($digest, 0, 64);
  167. } elseif ($digestType == 3 || $digestType == 4) {
  168. $string = switchepp_generateDigestRandomString(96);
  169. $digest = strtoupper(bin2hex($string));
  170. $digest = substr($digest, 0, 96);
  171. }
  172. $params['algorithm'] = (!empty($params['algorithm'])) ? $params['algorithm'] : '5';
  173. $dnssec = '<extension>
  174. <secDNS:update xmlns:secDNS="urn:ietf:params:xml:ns:secDNS-1.1">
  175. <secDNS:add>
  176. <secDNS:dsData>
  177. <secDNS:keyTag>' . substr(time(), 0, 5) . '</secDNS:keyTag>
  178. <secDNS:alg>' . $params['algorithm'] . '</secDNS:alg>
  179. <secDNS:digestType>' . $digestType . '</secDNS:digestType>
  180. <secDNS:digest>' . $digest . '</secDNS:digest>
  181. </secDNS:dsData>
  182. </secDNS:add>
  183. </secDNS:update>
  184. </extension>';
  185. }
  186. $xmlUpdate = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  187. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  188. <command>
  189. <update>
  190. <domain:update xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
  191. <domain:name>' . $domainname . '</domain:name>
  192. <domain:add>
  193. <domain:ns>
  194. ' . $add_hosts . '
  195. </domain:ns>
  196. </domain:add>
  197. <domain:rem>
  198. <domain:ns>
  199. ' . $rem_hosts . '
  200. </domain:ns>
  201. </domain:rem>
  202. </domain:update>
  203. </update>
  204. ' . $dnssec . '
  205. <clTRID>clientref-' . rand(1000, 9999) . '</clTRID>
  206. </command>
  207. </epp>';
  208. $update_domain = switchepp_write_xml($client, $xmlUpdate, __FUNCTION__);
  209. } catch (Exception $ex) {
  210. $values['error'] = $ex->getMessage();
  211. }
  212. if (!empty($client))
  213. switchepp_logoutepp($client, $params);
  214. return $values;
  215. }
  216. #*************************Domain Register****************************#
  217. function switchepp_RegisterDomain($params) {
  218. try {
  219. // $check_license = switchepp_license_status($params); #Check License
  220. $client = switchepp_clientloginepp($params); #Epp Connection
  221. $login = switchepp_loggedinepp($client, $params); #Epp Client login
  222. #get domain info
  223. $xmlcheck = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  224. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  225. <command>
  226. <check>
  227. <domain:check xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
  228. <domain:name>' . switcheppGetDomainName($params['domainid']) . '</domain:name>
  229. </domain:check>
  230. </check>
  231. <clTRID>' . rand(9999999, 100000) . '</clTRID>
  232. </command>
  233. </epp>';
  234. $domain_check = switchepp_write_xml($client, $xmlcheck, __FUNCTION__ . '( check domain)');
  235. if (0 == (int) $domain_check->response->resData->children("domain", true)->chkData->cd[0]->name->attributes()->avail)
  236. throw new exception($domain_check->response->resData->children("domain", true)->chkData->cd[0]->name . ' ' . $domain_check->response->resData->children("domain", true)->chkData->cd[0]->reason);
  237. $regContactId = strtoupper(switchepp_generateContactID(8) . $params['domainid']);
  238. $contactCheckXml = switchepp_checkContact($regContactId);
  239. $contact_check = switchepp_write_xml($client, $contactCheckXml, __FUNCTION__ . ' (check contact)');
  240. if (1 == (int) $contact_check->response->resData->children("contact", true)->chkData->cd[0]->id->attributes()->avail) {
  241. $xmlclient = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  242. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  243. <command>
  244. <create>
  245. <contact:create xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
  246. <contact:id>REG' . $regContactId . '</contact:id>
  247. <contact:postalInfo type="loc">
  248. <contact:name>' . $params['fullname'] . '</contact:name>
  249. <contact:org>' . $params['companyname'] . '</contact:org>
  250. <contact:addr>
  251. <contact:street>' . $params['address1'] . '</contact:street>
  252. <contact:street>' . $params['address2'] . '</contact:street>
  253. <contact:city>' . $params['city'] . '</contact:city>
  254. <contact:pc>' . $params['postcode'] . '</contact:pc>
  255. <contact:cc>' . $params['country'] . '</contact:cc>
  256. </contact:addr>
  257. </contact:postalInfo>
  258. <contact:voice>' . $params['phonenumberformatted'] . '</contact:voice>
  259. <contact:email>' . $params['email'] . '</contact:email>
  260. <contact:authInfo>
  261. <contact:pw>Con-' . time() . '</contact:pw>
  262. </contact:authInfo>
  263. </contact:create>
  264. </create>
  265. <clTRID>Regcon-' . rand(1000, 9999) . '</clTRID>
  266. </command>
  267. </epp>';
  268. $create_reg_contact = switchepp_write_xml($client, $xmlclient, __FUNCTION__ . '( create reg contact)');
  269. $reg_contact_id = $create_reg_contact->response->resData->children('contact', true)->creData->id;
  270. } else {
  271. $reg_contact_id = $regContactId;
  272. }
  273. #*************tech create*****************#
  274. $techContactId = strtoupper(switchepp_generateContactID(6) . $params['domainid']);
  275. $contactCheckXml = switchepp_checkContact($techContactId);
  276. $contact_check = switchepp_write_xml($client, $contactCheckXml, __FUNCTION__ . ' (check contact)');
  277. if (1 == (int) $contact_check->response->resData->children("contact", true)->chkData->cd[0]->id->attributes()->avail) {
  278. $xmlTech = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  279. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  280. <command>
  281. <create>
  282. <contact:create xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
  283. <contact:id>TE' . $techContactId . '</contact:id>
  284. <contact:postalInfo type="loc">
  285. <contact:name>' . $params['adminfirstname'] . ' ' . $params['adminlastname'] . '</contact:name>
  286. <contact:org>' . $params['admincompanyname'] . '</contact:org>
  287. <contact:addr>
  288. <contact:street>' . $params['adminaddress1'] . '</contact:street>
  289. <contact:street>' . $params['adminaddress2'] . '</contact:street>
  290. <contact:city>' . $params['admincity'] . '</contact:city>
  291. <contact:pc>' . $params['adminpostcode'] . '</contact:pc>
  292. <contact:cc>' . $params['admincountry'] . '</contact:cc>
  293. </contact:addr>
  294. </contact:postalInfo>
  295. <contact:voice>' . $params['adminfullphonenumber'] . '</contact:voice>
  296. <contact:email>' . $params['adminemail'] . '</contact:email>
  297. <contact:authInfo>
  298. <contact:pw>Tec-' . time() . '</contact:pw>
  299. </contact:authInfo>
  300. </contact:create>
  301. </create>
  302. <clTRID>clientref-' . rand(1000, 9999) . '</clTRID>
  303. </command>
  304. </epp>';
  305. $create_tech_contact = switchepp_write_xml($client, $xmlTech, __FUNCTION__ . '( create tech contact)');
  306. $tech_contact_id = $create_tech_contact->response->resData->children('contact', true)->creData->id;
  307. } else {
  308. $tech_contact_id = $techContactId;
  309. }
  310. #*******************NameServer*************#
  311. if ($params['ns1']) {
  312. $ns .= '<domain:hostObj>' . $params['ns1'] . '</domain:hostObj>';
  313. }
  314. if ($params['ns2']) {
  315. $ns .= '<domain:hostObj>' . $params['ns2'] . '</domain:hostObj>';
  316. }
  317. if ($params['ns3']) {
  318. $ns .= '<domain:hostObj>' . $params['ns3'] . '</domain:hostObj>';
  319. }
  320. if ($params['ns4']) {
  321. $ns .= '<domain:hostObj>' . $params['ns4'] . '</domain:hostObj>';
  322. }
  323. if ($ns) {
  324. $nsnameserver = ' <domain:ns>
  325. ' . $ns . '
  326. </domain:ns>';
  327. }
  328. $IDN = new idna_convert();
  329. $input = switcheppGetDomainName($params['domainid']);
  330. $domainname = $IDN->encode($input);
  331. if ($params['dnssec'] == "on") {
  332. $digestType = $params['digest_type'];
  333. if (empty($digestType))
  334. $digestType = 1;
  335. if ($digestType == 1) {
  336. $string = switchepp_generateDigestRandomString(40);
  337. $digest = strtoupper(bin2hex($string));
  338. $digest = substr($digest, 0, 40);
  339. } elseif ($digestType == 2) {
  340. $string = switchepp_generateDigestRandomString(64);
  341. $digest = strtoupper(bin2hex($string));
  342. $digest = substr($digest, 0, 64);
  343. } elseif ($digestType == 3 || $digestType == 4) {
  344. $string = switchepp_generateDigestRandomString(96);
  345. $digest = strtoupper(bin2hex($string));
  346. $digest = substr($digest, 0, 96);
  347. }
  348. $params['algorithm'] = (!empty($params['algorithm'])) ? $params['algorithm'] : '5';
  349. $dnssec = '<extension>
  350. <secDNS:create xmlns:secDNS="urn:ietf:params:xml:ns:secDNS-1.1">
  351. <secDNS:dsData>
  352. <secDNS:keyTag>' . substr(time(), 0, 5) . '</secDNS:keyTag>
  353. <secDNS:alg>' . $params['algorithm'] . '</secDNS:alg>
  354. <secDNS:digestType>' . $digestType . '</secDNS:digestType>
  355. <secDNS:digest>' . $digest . '</secDNS:digest>
  356. </secDNS:dsData>
  357. </secDNS:create>
  358. </extension>';
  359. }
  360. $domainPw = switchepp_generateRandomString(15);
  361. #domian create command
  362. $xmldomain = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  363. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  364. <command>
  365. <create>
  366. <domain:create xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
  367. <domain:name>' . $domainname . '</domain:name>
  368. ' . $nsnameserver . '
  369. <domain:registrant>' . $reg_contact_id . '</domain:registrant>
  370. <domain:contact type="tech">' . $tech_contact_id . '</domain:contact>
  371. <domain:authInfo>
  372. <domain:pw>' . $domainPw . '</domain:pw>
  373. </domain:authInfo>
  374. </domain:create>
  375. </create>
  376. ' . $dnssec . '
  377. <clTRID>' . rand(9999999, 100000) . '</clTRID>
  378. </command>
  379. </epp>';
  380. $domain_create = switchepp_write_xml($client, $xmldomain, __FUNCTION__);
  381. } catch (Exception $ex) {
  382. $values['error'] = $ex->getMessage();
  383. }
  384. if (!empty($client))
  385. switchepp_logoutepp($client, $params);
  386. return $values;
  387. }
  388. #**********************************Renew Domain*******************************#
  389. /*
  390. function switchepp_RenewDomain($params) {
  391. $userIdentifier = $params['APIUsername'];
  392. $apiKey = $params['APIKey'];
  393. $testMode = $params['TestMode'];
  394. $accountMode = $params['AccountMode'];
  395. $emailPreference = $params['EmailPreference'];
  396. // registration parameters
  397. $sld = $params['sld'];
  398. $tld = $params['tld'];
  399. $registrationPeriod = $params['regperiod'];
  400. // domain addon purchase status
  401. $enableDnsManagement = (bool) $params['dnsmanagement'];
  402. $enableEmailForwarding = (bool) $params['emailforwarding'];
  403. $enableIdProtection = (bool) $params['idprotection'];
  404. }*/
  405. #**********************************Get Contact Detail*******************************#
  406. function switchepp_GetContactDetails($params) {
  407. try {
  408. // $check_license = switchepp_license_status($params); #Check License
  409. $client = switchepp_clientloginepp($params); #Epp Connection
  410. $login = switchepp_loggedinepp($client, $params); #Epp Client login
  411. #get domain info
  412. $xml = switchepp_domain_info($params);
  413. $info_domain = switchepp_write_xml($client, $xml, __FUNCTION__ . '(domain info)');
  414. $registrant_id = $info_domain->response->resData->children("domain", true)->infData->registrant; #registrant id
  415. $Tech_id = $info_domain->response->resData->children("domain", true)->infData->contact; #Tech id
  416. $xml2 = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  417. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  418. <command>
  419. <info>
  420. <contact:info xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
  421. <contact:id>' . $registrant_id . '</contact:id>
  422. </contact:info>
  423. </info>
  424. <clTRID>clientref-' . rand(1000, 9999) . '</clTRID>
  425. </command>
  426. </epp>';
  427. $info_contact = switchepp_write_xml($client, $xml2, __FUNCTION__ . '(registrant contact info)');
  428. $contactdataArr = $info_contact->response->resData->children("contact", true)->infData;
  429. $results["Registrant"]["Contact Name"] = $contactdataArr->postalInfo->name;
  430. $results["Registrant"]["Organisation"] = $contactdataArr->postalInfo->org;
  431. $results["Registrant"]["Address line 1"] = $contactdataArr->postalInfo->addr->street[0];
  432. $results["Registrant"]["Address line 2"] = $contactdataArr->postalInfo->addr->street[1];
  433. $results["Registrant"]["TownCity"] = $contactdataArr->postalInfo->addr->city;
  434. $results["Registrant"]["Zip code"] = $contactdataArr->postalInfo->addr->pc;
  435. $results["Registrant"]["Country Code"] = $contactdataArr->postalInfo->addr->cc;
  436. $results["Registrant"]["Phone"] = $contactdataArr->voice;
  437. $results["Registrant"]["Email"] = $contactdataArr->email;
  438. if (!empty($Tech_id)) {
  439. #get tech detail
  440. $xml3 = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  441. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  442. <command>
  443. <info>
  444. <contact:info xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
  445. <contact:id>' . $Tech_id . '</contact:id>
  446. </contact:info>
  447. </info>
  448. <clTRID>clientref-' . rand(1000, 9999) . '</clTRID>
  449. </command>
  450. </epp>';
  451. $tect_info_contact = switchepp_write_xml($client, $xml3, __FUNCTION__ . '(tech contact info)');
  452. #*************************Show tech information in field****************************#
  453. $techdataArr = $tect_info_contact->response->resData->children("contact", true)->infData;
  454. $results["Technical"]["Contact Name"] = $techdataArr->postalInfo->name;
  455. $results["Technical"]["Organisation"] = $techdataArr->postalInfo->org;
  456. $results["Technical"]["Address line 1"] = $techdataArr->postalInfo->addr->street[0];
  457. $results["Technical"]["Address line 2"] = $techdataArr->postalInfo->addr->street[1];
  458. $results["Technical"]["TownCity"] = $techdataArr->postalInfo->addr->city;
  459. $results["Technical"]["Zip code"] = $techdataArr->postalInfo->addr->pc;
  460. $results["Technical"]["Country Code"] = $techdataArr->postalInfo->addr->cc;
  461. $results["Technical"]["Phone"] = $techdataArr->voice;
  462. $results["Technical"]["Email"] = $techdataArr->email;
  463. }
  464. } catch (Exception $ex) {
  465. $results['error'] = $ex->getMessage();
  466. }
  467. if (!empty($client))
  468. switchepp_logoutepp($client, $params);
  469. return $results;
  470. }
  471. #******************Save Contact/Tech Detail*********************#
  472. function switchepp_SaveContactDetails($params) {
  473. try {
  474. // $check_license = switchepp_license_status($params); #Check License
  475. $client = switchepp_clientloginepp($params); #Epp Connection
  476. $login = switchepp_loggedinepp($client, $params); #Epp Client login
  477. #get domain info
  478. $xml = switchepp_domain_info($params);
  479. $info_domain = switchepp_write_xml($client, $xml, __FUNCTION__ . '(domain info)');
  480. $registrant_id = $info_domain->response->resData->children("domain", true)->infData->registrant; #registrant id
  481. $Tech_id = $info_domain->response->resData->children("domain", true)->infData->contact; #Tech id
  482. $contactArr = ['Registrant' => $registrant_id, 'Technical' => $Tech_id];
  483. $updateContactArr = $getContactArr = [];
  484. foreach ($contactArr as $type => $contactId) {
  485. if (!empty($contactArr[$type])) {
  486. $contact = [];
  487. $contact = $params['contactdetails'][$type];
  488. $updateName = ($contact['Full Name']) ? $contact['Full Name'] : $contact['Contact Name'];
  489. $updateOrg = ($contact['Organisation Name']) ? $contact['Organisation Name'] : $contact['Organisation'];
  490. $updateAdd1 = ($contact['Address 1']) ? $contact['Address 1'] : $contact['Address line 1'];
  491. $updateAdd2 = ($contact['Address 2']) ? $contact['Address 2'] : $contact['Address line 2'];
  492. $updateCity = ($contact['City']) ? $contact['City'] : $contact['TownCity'];
  493. $updateZip = ($contact['Postcode']) ? $contact['Postcode'] : $contact['Zip code'];
  494. $updateCc = ($contact['Country']) ? $contact['Country'] : $contact['Country Code'];
  495. $updateEmail = $contact['Email'];
  496. $updatePhn = ($contact['Phone Number']) ? $contact['Phone Number'] : $contact['Phone'];
  497. $updateContactArr['Contact Name'] = htmlspecialchars(trim($updateName));
  498. $updateContactArr['Organisation'] = htmlspecialchars(trim($updateOrg));
  499. $updateContactArr['Address line 1'] = htmlspecialchars(trim($updateAdd1));
  500. $updateContactArr['Address line 2'] = htmlspecialchars(trim($updateAdd2));
  501. $updateContactArr['TownCity'] = htmlspecialchars(trim($updateCity));
  502. $updateContactArr['Zip code'] = htmlspecialchars(trim($updateZip));
  503. $updateContactArr['Country Code'] = htmlspecialchars(trim($updateCc));
  504. $updateContactArr['Phone'] = htmlspecialchars(trim($updatePhn));
  505. $updateContactArr['Email'] = htmlspecialchars(trim($updateEmail));
  506. $contactInfo = switchepp_contact_info($client, $contactId, 'Get ' . $type);
  507. $contact_detail = simplexml_load_string($contactInfo);
  508. $contactdataArr = $contact_detail->response->resData->children("contact", true)->infData;
  509. foreach ($contactdataArr->postalInfo as $contactFromSwitch) {
  510. $getName = htmlspecialchars($contactFromSwitch->name);
  511. $getOrg = htmlspecialchars($contactFromSwitch->org);
  512. $getAdd1 = htmlspecialchars($contactFromSwitch->addr->street[0]);
  513. $getAdd2 = htmlspecialchars($contactFromSwitch->addr->street[1]);
  514. $getCity = htmlspecialchars($contactFromSwitch->addr->city);
  515. $getZip = htmlspecialchars($contactFromSwitch->addr->pc);
  516. $getCc = htmlspecialchars($contactFromSwitch->addr->cc);
  517. $getContactArr['Contact Name'] = trim($getName);
  518. $getContactArr['Organisation'] = trim($getOrg);
  519. $getContactArr['Address line 1'] = trim($getAdd1);
  520. $getContactArr['Address line 2'] = trim($getAdd2);
  521. $getContactArr['TownCity'] = trim($getCity);
  522. $getContactArr['Zip code'] = trim($getZip);
  523. $getContactArr['Country Code'] = trim($getCc);
  524. }
  525. $getEmail = htmlspecialchars($contactdataArr->email);
  526. $getPhn = htmlspecialchars($contactdataArr->voice);
  527. $getContactArr['Phone'] = trim($getPhn);
  528. $getContactArr['Email'] = trim($getEmail);
  529. if ($getContactArr == $updateContactArr)
  530. continue;
  531. $updateXml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  532. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  533. <command>
  534. <update>
  535. <contact:update xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
  536. <contact:id>' . $contactId . '</contact:id>
  537. <contact:chg>
  538. <contact:postalInfo type="loc">
  539. <contact:name>' . $updateContactArr['Contact Name'] . '</contact:name>
  540. <contact:org>' . $updateContactArr['Organisation'] . '</contact:org>
  541. <contact:addr>
  542. <contact:street>' . $updateContactArr['Address line 1'] . '</contact:street>
  543. <contact:street>' . $updateContactArr['Address line 2'] . '</contact:street>
  544. <contact:city>' . $updateContactArr['TownCity'] . '</contact:city>
  545. <contact:sp>' . $updateContactArr['TownCity'] . '</contact:sp>
  546. <contact:pc>' . $updateContactArr['Zip code'] . '</contact:pc>
  547. <contact:cc>' . $updateContactArr['Country Code'] . '</contact:cc>
  548. </contact:addr>
  549. </contact:postalInfo>
  550. <contact:voice>' . $updateContactArr['Phone'] . '</contact:voice>
  551. <contact:fax/>
  552. <contact:email>' . $updateContactArr['Email'] . '</contact:email>
  553. <contact:authInfo>
  554. <contact:pw>con-' . time() . '</contact:pw>
  555. </contact:authInfo>
  556. </contact:chg>
  557. </contact:update>
  558. </update>
  559. <clTRID>clientref-' . rand(1000, 9999) . '</clTRID>
  560. </command>
  561. </epp>';
  562. switchepp_write_xml($client, $updateXml, 'Save ' . $type);
  563. }
  564. }
  565. } catch (Exception $ex) {
  566. $values['error'] = $ex->getMessage();
  567. }
  568. if (!empty($client))
  569. switchepp_logoutepp($client, $params);
  570. return $values;
  571. }
  572. #************************Domain Delete*************************#
  573. function switchepp_RequestDelete($params) {
  574. try {
  575. // $check_license = switchepp_license_status($params); #Check License
  576. $client = switchepp_clientloginepp($params); #Epp Connection
  577. $login = switchepp_loggedinepp($client, $params); #Epp Client login
  578. #get domain info
  579. $xml = switchepp_domain_info($params);
  580. $info_domain = switchepp_write_xml($client, $xml, __FUNCTION__ . '(domain info)');
  581. $IDN = new idna_convert();
  582. $input = switcheppGetDomainName($params['domainid']);
  583. $domainname = $IDN->encode($input);
  584. $deletxml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  585. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  586. <command>
  587. <delete>
  588. <domain:delete xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
  589. <domain:name>' . $domainname . '</domain:name>
  590. </domain:delete>
  591. </delete>
  592. <clTRID>delete-domain-' . rand(1000, 9999) . '</clTRID>
  593. </command>
  594. </epp>';
  595. $delete_domain = switchepp_write_xml($client, $deletxml, __FUNCTION__);
  596. } catch (Exception $ex) {
  597. $values['error'] = $ex->getMessage();
  598. }
  599. if (!empty($client))
  600. switchepp_logoutepp($client, $params);
  601. return $values;
  602. }
  603. #******************************Domain transfer********************************#
  604. function switchepp_TransferDomain($params) {
  605. try {
  606. // $check_license = switchepp_license_status($params); #Check License
  607. $client = switchepp_clientloginepp($params); #Epp Connection
  608. $login = switchepp_loggedinepp($client, $params); #Epp Client login
  609. #get domain info
  610. $xml = switchepp_domain_info($params);
  611. $IDN = new idna_convert();
  612. $input = switcheppGetDomainName($params['domainid']);
  613. $domainname = $IDN->encode($input);
  614. #domain transfer
  615. $xmlTransfer = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  616. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  617. <command>
  618. <transfer op="request">
  619. <domain:transfer xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
  620. <domain:name>' . $domainname . '</domain:name>
  621. <domain:authInfo>
  622. <domain:pw>' . htmlentities($params['transfersecret']) . '</domain:pw>
  623. </domain:authInfo>
  624. </domain:transfer>
  625. </transfer>
  626. <clTRID>clientref-' . rand(1000, 9999) . '</clTRID>
  627. </command>
  628. </epp>';
  629. $Transfer_domain = switchepp_write_xml($client, $xmlTransfer, __FUNCTION__);
  630. $regContactId = strtoupper(switchepp_generateContactID(8) . $params['domainid']);
  631. $contactCheckXml = switchepp_checkContact($regContactId);
  632. $contact_check = switchepp_write_xml($client, $contactCheckXml, __FUNCTION__ . ' (check contact)');
  633. if (1 == (int) $contact_check->response->resData->children("contact", true)->chkData->cd[0]->id->attributes()->avail) {
  634. $xmlclient = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  635. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  636. <command>
  637. <create>
  638. <contact:create xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
  639. <contact:id>RE' . $regContactId . '</contact:id>
  640. <contact:postalInfo type="loc">
  641. <contact:name>' . $params['fullname'] . '</contact:name>
  642. <contact:org>' . $params['companyname'] . '</contact:org>
  643. <contact:addr>
  644. <contact:street>' . $params['address1'] . '</contact:street>
  645. <contact:street>' . $params['address2'] . '</contact:street>
  646. <contact:city>' . $params['city'] . '</contact:city>
  647. <contact:pc>' . $params['postcode'] . '</contact:pc>
  648. <contact:cc>' . $params['country'] . '</contact:cc>
  649. </contact:addr>
  650. </contact:postalInfo>
  651. <contact:voice>' . $params['phonenumberformatted'] . '</contact:voice>
  652. <contact:email>' . $params['email'] . '</contact:email>
  653. <contact:authInfo>
  654. <contact:pw>Con-' . time() . '</contact:pw>
  655. </contact:authInfo>
  656. </contact:create>
  657. </create>
  658. <clTRID>clientref-' . rand(1000, 9999) . '</clTRID>
  659. </command>
  660. </epp>';
  661. $create_reg_contact = switchepp_write_xml($client, $xmlclient, __FUNCTION__ . ' (create reg contact)');
  662. $reg_contact_id = $create_reg_contact->response->resData->children('contact', true)->creData->id;
  663. } else
  664. $reg_contact_id = $regContactId;
  665. #*************tech create*****************#
  666. $techContactId = strtoupper(switchepp_generateContactID(6) . $params['domainid']);
  667. $contactCheckXml = switchepp_checkContact($techContactId);
  668. $contact_check = switchepp_write_xml($client, $contactCheckXml, __FUNCTION__ . ' (check contact)');
  669. if (1 == (int) $contact_check->response->resData->children("contact", true)->chkData->cd[0]->id->attributes()->avail) {
  670. $xmlTech = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  671. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  672. <command>
  673. <create>
  674. <contact:create xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
  675. <contact:id>TE' . $techContactId . '</contact:id>
  676. <contact:postalInfo type="loc">
  677. <contact:name>' . $params['adminfirstname'] . ' ' . $params['adminlastname'] . '</contact:name>
  678. <contact:org>' . $params['admincompanyname'] . '</contact:org>
  679. <contact:addr>
  680. <contact:street>' . $params['adminaddress1'] . '</contact:street>
  681. <contact:street>' . $params['adminaddress2'] . '</contact:street>
  682. <contact:city>' . $params['admincity'] . '</contact:city>
  683. <contact:pc>' . $params['adminpostcode'] . '</contact:pc>
  684. <contact:cc>' . $params['admincountry'] . '</contact:cc>
  685. </contact:addr>
  686. </contact:postalInfo>
  687. <contact:voice>' . $params['adminfullphonenumber'] . '</contact:voice>
  688. <contact:email>' . $params['adminemail'] . '</contact:email>
  689. <contact:authInfo>
  690. <contact:pw>Tec-' . time() . '</contact:pw>
  691. </contact:authInfo>
  692. </contact:create>
  693. </create>
  694. <clTRID>clientref-' . rand(1000, 9999) . '</clTRID>
  695. </command>
  696. </epp>';
  697. $create_tech_contact = switchepp_write_xml($client, $xmlTech, __FUNCTION__ . ' (create tech contact)');
  698. $tech_contact_id = $create_tech_contact->response->resData->children('contact', true)->creData->id;
  699. } else
  700. $tech_contact_id = $techContactId;
  701. if ($params['dnssec'] == "on") {
  702. $digestType = $params['digest_type'];
  703. if (empty($digestType))
  704. $digestType = 1;
  705. if ($digestType == 1) {
  706. $string = switchepp_generateDigestRandomString(40);
  707. $digest = strtoupper(bin2hex($string));
  708. $digest = substr($digest, 0, 40);
  709. } elseif ($digestType == 2) {
  710. $string = switchepp_generateDigestRandomString(64);
  711. $digest = strtoupper(bin2hex($string));
  712. $digest = substr($digest, 0, 64);
  713. } elseif ($digestType == 3 || $digestType == 4) {
  714. $string = switchepp_generateDigestRandomString(96);
  715. $digest = strtoupper(bin2hex($string));
  716. $digest = substr($digest, 0, 96);
  717. }
  718. $params['algorithm'] = (!empty($params['algorithm'])) ? $params['algorithm'] : '5';
  719. $dnssec = '<extension>
  720. <secDNS:update xmlns:secDNS="urn:ietf:params:xml:ns:secDNS-1.1">
  721. <secDNS:add>
  722. <secDNS:dsData>
  723. <secDNS:keyTag>' . substr(time(), 0, 5) . '</secDNS:keyTag>
  724. <secDNS:alg>' . $params['algorithm'] . '</secDNS:alg>
  725. <secDNS:digestType>' . $digestType . '</secDNS:digestType>
  726. <secDNS:digest>' . $digest . '</secDNS:digest>
  727. </secDNS:dsData>
  728. </secDNS:add>
  729. </secDNS:update>
  730. </extension>';
  731. }
  732. $xmlUpdate = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  733. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  734. <command>
  735. <update>
  736. <domain:update xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
  737. <domain:name>' . $domainname . '</domain:name>
  738. <domain:add>
  739. <domain:contact type="tech">' . $tech_contact_id . '</domain:contact>
  740. </domain:add>
  741. <domain:chg>
  742. <domain:registrant>' . $reg_contact_id . '</domain:registrant>
  743. </domain:chg>
  744. </domain:update>
  745. </update>
  746. ' . $dnssec . '
  747. <clTRID>clientref-' . rand(1000, 9999) . '</clTRID>
  748. </command>
  749. </epp>';
  750. $update_domain = switchepp_write_xml($client, $xmlUpdate, __FUNCTION__ . ' (Domain update)');
  751. } catch (Exception $ex) {
  752. $values['error'] = $ex->getMessage();
  753. }
  754. if (!empty($client))
  755. switchepp_logoutepp($client, $params);
  756. return $values;
  757. }
  758. #***************************Get Epp Code******************************#
  759. function switchepp_GetEPPCode($params) {
  760. try {
  761. // $check_license = switchepp_license_status($params); #Check License
  762. $client = switchepp_clientloginepp($params); #Epp Connection
  763. $login = switchepp_loggedinepp($client, $params); #Epp Client login
  764. #get domain info
  765. $xml = switchepp_domain_info($params);
  766. $domainPw = switchepp_generateRandomString(15);
  767. $xml = switchepp_update_domain_auth($params, $domainPw);
  768. $domainUpdate = switchepp_write_xml($client, $xml, __FUNCTION__);
  769. $values['eppcode'] = $domainPw;
  770. } catch (Exception $ex) {
  771. $values['error'] = $ex->getMessage();
  772. }
  773. if (!empty($client))
  774. switchepp_logoutepp($client, $params);
  775. return $values;
  776. }
  777. #***************************Custom button function******************************#
  778. function switchepp_AdminCustomButtonArray() {
  779. $buttonarray = array(
  780. "Restore Domain" => "Restore",
  781. );
  782. return $buttonarray;
  783. }
  784. #***************************Restore Domain******************************#
  785. function switchepp_Restore($params) {
  786. try {
  787. // $check_license = switchepp_license_status($params); #Check License
  788. $client = switchepp_clientloginepp($params); #Epp Connection
  789. $login = switchepp_loggedinepp($client, $params); #Epp Client login
  790. #Domain Restore XML
  791. $xml = switchepp_domain_restore($params);
  792. $domainRestore = switchepp_write_xml($client, $xml, __FUNCTION__);
  793. } catch (Exception $ex) {
  794. $values['error'] = $ex->getMessage();
  795. }
  796. if (!empty($client))
  797. switchepp_logoutepp($client, $params);
  798. return $values;
  799. }
  800. #***************************Admin Fields******************************#
  801. function switchepp_AdminDomainsTabFields($params) {
  802. try {
  803. $settingArr = getSwitchEPP_setting($params['domainid']); #get registrar config settings
  804. $params = array_merge($params, $settingArr);
  805. // $check_license = switchepp_license_status($params); #Check License
  806. $client = switchepp_clientloginepp($params); #Epp Connection
  807. $login = switchepp_loggedinepp($client, $params); #Epp Client login
  808. #get domain info
  809. $xml = switchepp_domain_info($params);
  810. $info_domain = switchepp_write_xml($client, $xml, __FUNCTION__ . '(domain info)');
  811. $expDate = $info_domain->response->resData->children("domain", true)->infData->exDate ? date('m-d-Y', strtotime($info_domain->response->resData->children("domain", true)->infData->exDate)) : '';
  812. $status = $info_domain->response->resData->children("domain", true)->infData->status->attributes()->s;
  813. $upDate = $info_domain->response->resData->children("domain", true)->infData->upDate ? date('m-d-Y', strtotime($info_domain->response->resData->children("domain", true)->infData->upDate)) : '';
  814. $transferDate = $info_domain->response->resData->children("domain", true)->infData->trDate ? date('m-d-Y', strtotime($info_domain->response->resData->children("domain", true)->infData->trDate)) : '';
  815. $createDate = $info_domain->response->resData->children("domain", true)->infData->crDate ? date('m-d-Y', strtotime($info_domain->response->resData->children("domain", true)->infData->crDate)) : '';
  816. $html = '';
  817. $html .= '<table width="100%" style="margin-bottom:0;" class="datatable">';
  818. $html .= '<tbody>';
  819. $html .= '<tr align="left">';
  820. $html .= '<th style="text-align: left;">Item</th>';
  821. $html .= '<th style="text-align: left;">Content</th>';
  822. $html .= '</tr>';
  823. $html .= '<tr align="left">';
  824. $html .= '<td>Status</td>';
  825. $html .= '<td>' . $status . '</td>';
  826. $html .= '</tr>';
  827. $html .= '<tr align="left">';
  828. $html .= '<td>Creation Date</td>';
  829. $html .= '<td>' . $createDate . '</td>';
  830. $html .= '</tr>';
  831. $html .= '<tr align="left">';
  832. $html .= '<td>Expiration Date</td>';
  833. $html .= '<td>' . $expDate . '</td>';
  834. $html .= '</tr>';
  835. $html .= '<tr align="left">';
  836. $html .= '<td>Last Update</td>';
  837. $html .= '<td>' . $upDate . '</td>';
  838. $html .= '</tr>';
  839. $html .= '<tr align="left">';
  840. $html .= '<td>Last Transfer</td>';
  841. $html .= '<td>' . $transferDate . '</td>';
  842. $html .= '</tr>';
  843. $html .= '</tbody>';
  844. $html .= '</table>';
  845. $values['Domain Detail'] = $html;
  846. } catch (Exception $ex) {
  847. $values['error'] = $ex->getMessage();
  848. }
  849. if (!empty($client))
  850. switchepp_logoutepp($client, $params);
  851. return $values;
  852. }
  853. #*******************Module Syncronize********************#
  854. function switchepp_Sync($params) {
  855. try {
  856. $client = switchepp_clientloginepp($params); #Epp Connection
  857. $login = switchepp_loggedinepp($client, $params); #Epp Client login
  858. #get domain info
  859. $xml = switchepp_domain_info($params);
  860. $info_domain = switchepp_write_xml($client, $xml, __FUNCTION__ . '(domain info)');
  861. $expDate = substr($info_domain->response->resData->children("domain", true)->infData->exDate, 0, 10);
  862. $statusres = $info_domain->response->resData->children("domain", true)->infData->status->attributes()->s;
  863. $timestamp = strtotime($info_domain->response->resData->children("domain", true)->infData->exDate);
  864. if ($timestamp === false) {
  865. return array(
  866. 'error' => 'Renewal date empty for domain: ' . $params['domain']
  867. );
  868. }
  869. Capsule::table('tbldomains')->where('id', $params['domainid'])->update(['expirydate' => $expDate]);
  870. $domain = Capsule::table('tbldomains')
  871. ->where('id', '=', $params['domainid'])
  872. ->where('donotrenew', '=', '1')
  873. ->where('registrar', '=', 'switchepp')
  874. ->whereRaw('`expirydate` >= CURRENT_DATE() AND `expirydate` < ADDDATE(CURRENT_DATE(), INTERVAL 1 DAY)')
  875. ->first();
  876. if (isset($domain->expirydate)) {
  877. $IDN = new idna_convert();
  878. $input = switcheppGetDomainName($params['domainid']);
  879. $domainname = $IDN->encode($input);
  880. $deletxml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  881. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  882. <command>
  883. <delete>
  884. <domain:delete xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
  885. <domain:name>' . $domainname . '</domain:name>
  886. </domain:delete>
  887. </delete>
  888. <clTRID>delete-domain-' . rand(1000, 9999) . '</clTRID>
  889. </command>
  890. </epp>';
  891. $delete_domain = switchepp_write_xml($client, $deletxml, __FUNCTION__ . ' (delete domain)');
  892. }
  893. if ($timestamp < time()) {
  894. $values['expirydate'] = $expDate;
  895. $values['expired'] = true;
  896. } else {
  897. $values['expirydate'] = $expDate;
  898. $values['active'] = true;
  899. }
  900. } catch (Exception $ex) {
  901. $values['error'] = $ex->getMessage();
  902. }
  903. if (!empty($client))
  904. switchepp_logoutepp($client, $params);
  905. return $values;
  906. }
  907. #*******************Transfer Syncronize********************#
  908. function switchepp_TransferSync($params) {
  909. try {
  910. $client = switchepp_clientloginepp($params); #Epp Connection
  911. $login = switchepp_loggedinepp($client, $params); #Epp Client login
  912. #get domain info
  913. $xml = switchepp_domain_info($params);
  914. $info_domain = switchepp_write_xml($client, $xml, __FUNCTION__ . '(domain info)');
  915. $expDate = substr($info_domain->response->resData->children("domain", true)->infData->exDate, 0, 10);
  916. $statusres = $info_domain->response->resData->children("domain", true)->infData->status->attributes()->s;
  917. if (!$statusres) {
  918. Capsule::table('tbldomains')->where('id', $params['domainid'])->update(["status" => "Cancelled"]);
  919. $values['error'] = "TransferSync/domain-info: Domain not found";
  920. }
  921. Capsule::table('tbldomains')->where('id', $params['domainid'])->update(['expirydate' => $expDate]);
  922. if ($statusres == "ok" || $statusres == "serverTransferProhibited") {
  923. $values['completed'] = true;
  924. } else {
  925. $values['error'] = "Sync/domain-info: Unknown status code '$statusres' ";
  926. }
  927. $values['expirydate'] = $expDate;
  928. } catch (Exception $ex) {
  929. $values['error'] = $ex->getMessage();
  930. }
  931. if (!empty($client))
  932. switchepp_logoutepp($client, $params);
  933. return $values;
  934. }
  935. #***********************Register Nameserver**************************#
  936. function switchepp_RegisterNameserver($params) {
  937. try {
  938. $client = switchepp_clientloginepp($params); #Epp Connection
  939. $login = switchepp_loggedinepp($client, $params); #Epp Client login
  940. #get domain info
  941. $xml = switchepp_domain_info($params);
  942. $xml_Hostcreate = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  943. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  944. <command>
  945. <create>
  946. <host:create xmlns:host="urn:ietf:params:xml:ns:host-1.0">
  947. <host:name>' . $params['nameserver'] . '</host:name>
  948. <host:addr ip="v4">' . $params['ipaddress'] . '</host:addr>
  949. </host:create>
  950. </create>
  951. <clTRID>' . rand(9999999, 100000) . '</clTRID>
  952. </command>
  953. </epp>';
  954. $host_create = switchepp_write_xml($client, $xml_Hostcreate, __FUNCTION__);
  955. } catch (Exception $ex) {
  956. $values['error'] = $ex->getMessage();
  957. }
  958. if (!empty($client))
  959. switchepp_logoutepp($client, $params);
  960. return $values;
  961. }
  962. #**************************Update Nameserver************************#
  963. function switchepp_ModifyNameserver($params) {
  964. try {
  965. //$check_license = switchepp_license_status($params); #Check License
  966. $client = switchepp_clientloginepp($params); #Epp Connection
  967. $login = switchepp_loggedinepp($client, $params); #Epp Client login
  968. #get domain info
  969. $xml = switchepp_domain_info($params);
  970. $update_req = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  971. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  972. <command>
  973. <update>
  974. <host:update xmlns:host="urn:ietf:params:xml:ns:host-1.0">
  975. <host:name>' . $params['nameserver'] . '</host:name>
  976. <host:add>
  977. <host:addr ip="v4">' . $params['currentipaddress'] . '</host:addr>
  978. </host:add>
  979. <host:rem>
  980. <host:addr ip="v6">' . $params['newipaddress'] . '</host:addr>
  981. </host:rem>
  982. </host:update>
  983. </update>
  984. <clTRID>' . rand(9999999, 100000) . '</clTRID>
  985. </command>
  986. </epp>';
  987. $update = switchepp_write_xml($client, $update_req, __FUNCTION__);
  988. } catch (Exception $ex) {
  989. $values['error'] = $ex->getMessage();
  990. }
  991. if (!empty($client))
  992. switchepp_logoutepp($client, $params);
  993. return $values;
  994. }
  995. #**********************Delete Nameserver****************************#
  996. function switchepp_DeleteNameserver($params) {
  997. try {
  998. $client = switchepp_clientloginepp($params); #Epp Connection
  999. $login = switchepp_loggedinepp($client, $params); #Epp Client login
  1000. #get domain info
  1001. $xml = switchepp_domain_info($params);
  1002. $delete_xml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  1003. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  1004. <command>
  1005. <delete>
  1006. <host:delete
  1007. xmlns:host="urn:ietf:params:xml:ns:host-1.0">
  1008. <host:name>' . $params['nameserver'] . '</host:name>
  1009. </host:delete>
  1010. </delete>
  1011. <clTRID>' . rand(9999999, 100000) . '</clTRID>
  1012. </command>
  1013. </epp>';
  1014. $delete = switchepp_write_xml($client, $delete_xml, __FUNCTION__);
  1015. } catch (Exception $ex) {
  1016. $values['error'] = $ex->getMessage();
  1017. }
  1018. if (!empty($client))
  1019. switchepp_logoutepp($client, $params);
  1020. return $values;
  1021. }
  1022. #*********************Create Epp Connection**************************#
  1023. function switchepp_clientloginepp($params) {
  1024. try {
  1025. $certFile = __DIR__ . '/cert/cert.pem';
  1026. $client = new Net_EPP_Client();
  1027. $use_ssl = true;
  1028. if (file_exists($certFile)) {
  1029. $context = stream_context_create();
  1030. stream_context_set_option($context, 'ssl', 'verify_peer', false);
  1031. stream_context_set_option($context, 'ssl', 'allow_self_signed', true);
  1032. stream_context_set_option($context, 'ssl', 'local_cert', $certFile);
  1033. stream_context_set_option($context, 'ssl', 'passphrase', $params['passphrase']);
  1034. $client->connect($params['eppurl'], $params['eppport'], 300, $use_ssl, $context) or die("Not connected with epp server");
  1035. } else {
  1036. $context = false;
  1037. $client->connect($params['eppurl'], $params['eppport'], 300, $use_ssl, $context) or die("Not connected with epp server");
  1038. }
  1039. } catch (Exception $e) {
  1040. $port = $params['eppport'];
  1041. throw new exception("Connection Error: " . $e->getMessage());
  1042. }
  1043. return $client;
  1044. }
  1045. #*********************Epp client login**************************#
  1046. function switchepp_loggedinepp($client, $params) {
  1047. # error_log("switchepp_loggedinepp " . $client . " | " . $params);
  1048. if ($params['svcExtension'] == "on") {
  1049. $dnssec = '<svcExtension>
  1050. <extURI>urn:ietf:params:xml:ns:secDNS-1.1</extURI>
  1051. <extURI>urn:ietf:params:xml:ns:rgp-1.0</extURI>
  1052. <extURI>urn:ietf:params:xml:ns:changePoll-1.0</extURI>
  1053. <extURI>https://www.nic.ch/epp/balance-1.0</extURI>
  1054. </svcExtension>';
  1055. } else {
  1056. $dnssec = '<svcExtension>
  1057. <extURI>urn:ietf:params:xml:ns:rgp-1.0</extURI>
  1058. <extURI>urn:ietf:params:xml:ns:changePoll-1.0</extURI>
  1059. <extURI>https://www.nic.ch/epp/balance-1.0</extURI>
  1060. </svcExtension>';
  1061. }
  1062. $xml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  1063. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  1064. <command>
  1065. <login>
  1066. <clID>' . $params['registrar_id'] . '</clID>
  1067. <pw>' . $params['registrar_password'] . '</pw>
  1068. <options>
  1069. <version>1.0</version>
  1070. <lang>en</lang>
  1071. </options>
  1072. <svcs>
  1073. <objURI>urn:ietf:params:xml:ns:domain-1.0</objURI>
  1074. <objURI>urn:ietf:params:xml:ns:contact-1.0</objURI>
  1075. <objURI>urn:ietf:params:xml:ns:host-1.0</objURI>
  1076. ' . $dnssec . '
  1077. </svcs>
  1078. </login>
  1079. <clTRID>' . rand(9999999, 100000) . '</clTRID>
  1080. </command>
  1081. </epp>';
  1082. error_log("EPP LOGIN: " . $xml);
  1083. $response = $client->request($xml);
  1084. logModuleCall('SWITCH EPP', 'login', $xml, $response);
  1085. $result = new SimpleXMLElement($response);
  1086. if ($result->response->result->attributes()->code >= 2000) {
  1087. throw new exception($result->response->result->msg . '. ' . $result->response->result->extValue->reason);
  1088. }
  1089. return $result;
  1090. }
  1091. function switchepp_logoutepp($client, $params) {
  1092. $xml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  1093. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  1094. <epp:command xmlns:epp="urn:ietf:params:xml:ns:epp-1.0">
  1095. <epp:logout />
  1096. <epp:clTRID>' . $params['registrar_id'] . '</epp:clTRID>
  1097. </epp:command>
  1098. </epp>';
  1099. $response = $client->request($xml);
  1100. logModuleCall('SWITCH EPP', 'logout', $xml, $response);
  1101. }
  1102. #******************** Get Contact info*****************#
  1103. function switchepp_contact_info($client, $contactId, $contactType) {
  1104. #get contact detail
  1105. $xml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  1106. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  1107. <command>
  1108. <info>
  1109. <contact:info xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
  1110. <contact:id>' . $contactId . '</contact:id>
  1111. </contact:info>
  1112. </info>
  1113. <clTRID>clientref-' . rand(1000, 9999) . '</clTRID>
  1114. </command>
  1115. </epp>';
  1116. $response = $client->request($xml);
  1117. logModuleCall('SWITCH EPP', $contactType, $xml, $response);
  1118. return $response;
  1119. }
  1120. #***********************Get domain info*************************#
  1121. function switchepp_domain_info($params) {
  1122. $IDN = new idna_convert();
  1123. $input = switcheppGetDomainName($params['domainid']);
  1124. $domainname = $IDN->encode($input);
  1125. $xml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  1126. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  1127. <command>
  1128. <info>
  1129. <domain:info xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
  1130. <domain:name hosts="all">' . $domainname . '</domain:name>
  1131. </domain:info>
  1132. </info>
  1133. <clTRID>clientref-' . rand(100, 999) . '</clTRID>
  1134. </command>
  1135. </epp>';
  1136. return $xml;
  1137. }
  1138. function switchepp_domain_restore($params) {
  1139. $IDN = new idna_convert();
  1140. $input = switcheppGetDomainName($params['domainid']);
  1141. $domainname = $IDN->encode($input);
  1142. $xml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  1143. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  1144. <command>
  1145. <update>
  1146. <domain:update xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
  1147. <domain:name>' . $domainname . '</domain:name>
  1148. <domain:chg />
  1149. </domain:update>
  1150. </update>
  1151. <extension>
  1152. <rgp:update xmlns:rgp="urn:ietf:params:xml:ns:rgp-1.0">
  1153. <rgp:restore op="request" />
  1154. </rgp:update>
  1155. </extension>
  1156. </command>
  1157. </epp>';
  1158. return $xml;
  1159. }
  1160. function switchepp_update_domain_auth($params, $domainPw) {
  1161. $IDN = new idna_convert();
  1162. $input = switcheppGetDomainName($params['domainid']);
  1163. $domainname = $IDN->encode($input);
  1164. $xml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  1165. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  1166. <command>
  1167. <update>
  1168. <domain:update xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
  1169. <domain:name>' . $domainname . '</domain:name>
  1170. <domain:chg>
  1171. <domain:authInfo>
  1172. <domain:pw>' . $domainPw . '</domain:pw>
  1173. </domain:authInfo>
  1174. </domain:chg>
  1175. </domain:update>
  1176. </update>
  1177. <clTRID>domainupdate-' . rand(1000, 9999) . '</clTRID>
  1178. </command>
  1179. </epp>';
  1180. return $xml;
  1181. }
  1182. function switchepp_checkContact($id) {
  1183. $xml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  1184. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  1185. <command>
  1186. <check>
  1187. <contact:check xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
  1188. <contact:id>' . $id . '</contact:id>
  1189. </contact:check>
  1190. </check>
  1191. <clTRID>ABC-12345</clTRID>
  1192. </command>
  1193. </epp>';
  1194. return $xml;
  1195. }
  1196. function switchepp_generateRandomString($length = 15) {
  1197. $characters = 'abcdefghijklmnopqrstuvwxyz123456789!@$*%#ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  1198. $charactersLength = strlen($characters);
  1199. $randomString = '';
  1200. for ($i = 0; $i < $length; $i++) {
  1201. $randomString .= $characters[rand(0, $charactersLength - 1)];
  1202. }
  1203. return $randomString;
  1204. }
  1205. function switchepp_generateDigestRandomString($length = 15) {
  1206. $characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  1207. $charactersLength = strlen($characters);
  1208. $randomString = '';
  1209. for ($i = 0; $i < $length; $i++) {
  1210. $randomString .= $characters[rand(0, $charactersLength - 1)];
  1211. }
  1212. return $randomString;
  1213. }
  1214. function switchepp_generateContactID($length = 15) {
  1215. $characters = 'abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  1216. $charactersLength = strlen($characters);
  1217. $randomString = '';
  1218. for ($i = 0; $i < $length; $i++) {
  1219. $randomString .= $characters[rand(0, $charactersLength - 1)];
  1220. }
  1221. return $randomString;
  1222. }
  1223. function switcheppGetDomainName($id) {
  1224. $data = Capsule::table('tbldomains')->where('id', $id)->first();
  1225. return $data->domain;
  1226. }
  1227. function switchepp_write_xml($client, $xml, $action, $extra = NULL) {
  1228. $response = $client->request($xml);
  1229. if (empty($extra)) {
  1230. logModuleCall('SWITCH EPP', $action, $xml, $response);
  1231. $result = new SimpleXMLElement($response);
  1232. if ($result->response->result->attributes()->code >= 2000) {
  1233. throw new exception($result->response->result->msg . '. ' . $result->response->result->extValue->reason);
  1234. }
  1235. return $result;
  1236. }
  1237. }
  1238. function getSwitchEPP_setting($id) {
  1239. #select table domain data
  1240. $domain_select_data = Capsule::table('tbldomains')->where('id', $id)->first();
  1241. #select registrar data
  1242. foreach (Capsule::table('tblregistrars')->where('registrar', $domain_select_data->registrar)->get() as $registrar_data) {
  1243. $data[$registrar_data->setting] = decrypt($registrar_data->value);
  1244. }
  1245. return $data;
  1246. }
  1247. function switchepp_license_status($params) {
  1248. if ($license_check['status'] != 'Active') {
  1249. throw new exception('license is ' . $license_check['status']);
  1250. }
  1251. return $license_check;
  1252. }
  1253. #License function
  1254. ?>