switchepp.php.bak 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328
  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. #**********************************Get Contact Detail*******************************#
  389. function switchepp_GetContactDetails($params) {
  390. try {
  391. // $check_license = switchepp_license_status($params); #Check License
  392. $client = switchepp_clientloginepp($params); #Epp Connection
  393. $login = switchepp_loggedinepp($client, $params); #Epp Client login
  394. #get domain info
  395. $xml = switchepp_domain_info($params);
  396. $info_domain = switchepp_write_xml($client, $xml, __FUNCTION__ . '(domain info)');
  397. $registrant_id = $info_domain->response->resData->children("domain", true)->infData->registrant; #registrant id
  398. $Tech_id = $info_domain->response->resData->children("domain", true)->infData->contact; #Tech id
  399. $xml2 = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  400. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  401. <command>
  402. <info>
  403. <contact:info xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
  404. <contact:id>' . $registrant_id . '</contact:id>
  405. </contact:info>
  406. </info>
  407. <clTRID>clientref-' . rand(1000, 9999) . '</clTRID>
  408. </command>
  409. </epp>';
  410. $info_contact = switchepp_write_xml($client, $xml2, __FUNCTION__ . '(registrant contact info)');
  411. $contactdataArr = $info_contact->response->resData->children("contact", true)->infData;
  412. $results["Registrant"]["Contact Name"] = $contactdataArr->postalInfo->name;
  413. $results["Registrant"]["Organisation"] = $contactdataArr->postalInfo->org;
  414. $results["Registrant"]["Address line 1"] = $contactdataArr->postalInfo->addr->street[0];
  415. $results["Registrant"]["Address line 2"] = $contactdataArr->postalInfo->addr->street[1];
  416. $results["Registrant"]["TownCity"] = $contactdataArr->postalInfo->addr->city;
  417. $results["Registrant"]["Zip code"] = $contactdataArr->postalInfo->addr->pc;
  418. $results["Registrant"]["Country Code"] = $contactdataArr->postalInfo->addr->cc;
  419. $results["Registrant"]["Phone"] = $contactdataArr->voice;
  420. $results["Registrant"]["Email"] = $contactdataArr->email;
  421. if (!empty($Tech_id)) {
  422. #get tech detail
  423. $xml3 = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  424. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  425. <command>
  426. <info>
  427. <contact:info xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
  428. <contact:id>' . $Tech_id . '</contact:id>
  429. </contact:info>
  430. </info>
  431. <clTRID>clientref-' . rand(1000, 9999) . '</clTRID>
  432. </command>
  433. </epp>';
  434. $tect_info_contact = switchepp_write_xml($client, $xml3, __FUNCTION__ . '(tech contact info)');
  435. #*************************Show tech information in field****************************#
  436. $techdataArr = $tect_info_contact->response->resData->children("contact", true)->infData;
  437. $results["Technical"]["Contact Name"] = $techdataArr->postalInfo->name;
  438. $results["Technical"]["Organisation"] = $techdataArr->postalInfo->org;
  439. $results["Technical"]["Address line 1"] = $techdataArr->postalInfo->addr->street[0];
  440. $results["Technical"]["Address line 2"] = $techdataArr->postalInfo->addr->street[1];
  441. $results["Technical"]["TownCity"] = $techdataArr->postalInfo->addr->city;
  442. $results["Technical"]["Zip code"] = $techdataArr->postalInfo->addr->pc;
  443. $results["Technical"]["Country Code"] = $techdataArr->postalInfo->addr->cc;
  444. $results["Technical"]["Phone"] = $techdataArr->voice;
  445. $results["Technical"]["Email"] = $techdataArr->email;
  446. }
  447. } catch (Exception $ex) {
  448. $results['error'] = $ex->getMessage();
  449. }
  450. if (!empty($client))
  451. switchepp_logoutepp($client, $params);
  452. return $results;
  453. }
  454. #******************Save Contact/Tech Detail*********************#
  455. function switchepp_SaveContactDetails($params) {
  456. try {
  457. // $check_license = switchepp_license_status($params); #Check License
  458. $client = switchepp_clientloginepp($params); #Epp Connection
  459. $login = switchepp_loggedinepp($client, $params); #Epp Client login
  460. #get domain info
  461. $xml = switchepp_domain_info($params);
  462. $info_domain = switchepp_write_xml($client, $xml, __FUNCTION__ . '(domain info)');
  463. $registrant_id = $info_domain->response->resData->children("domain", true)->infData->registrant; #registrant id
  464. $Tech_id = $info_domain->response->resData->children("domain", true)->infData->contact; #Tech id
  465. $contactArr = ['Registrant' => $registrant_id, 'Technical' => $Tech_id];
  466. $updateContactArr = $getContactArr = [];
  467. foreach ($contactArr as $type => $contactId) {
  468. if (!empty($contactArr[$type])) {
  469. $contact = [];
  470. $contact = $params['contactdetails'][$type];
  471. $updateName = ($contact['Full Name']) ? $contact['Full Name'] : $contact['Contact Name'];
  472. $updateOrg = ($contact['Organisation Name']) ? $contact['Organisation Name'] : $contact['Organisation'];
  473. $updateAdd1 = ($contact['Address 1']) ? $contact['Address 1'] : $contact['Address line 1'];
  474. $updateAdd2 = ($contact['Address 2']) ? $contact['Address 2'] : $contact['Address line 2'];
  475. $updateCity = ($contact['City']) ? $contact['City'] : $contact['TownCity'];
  476. $updateZip = ($contact['Postcode']) ? $contact['Postcode'] : $contact['Zip code'];
  477. $updateCc = ($contact['Country']) ? $contact['Country'] : $contact['Country Code'];
  478. $updateEmail = $contact['Email'];
  479. $updatePhn = ($contact['Phone Number']) ? $contact['Phone Number'] : $contact['Phone'];
  480. $updateContactArr['Contact Name'] = htmlspecialchars(trim($updateName));
  481. $updateContactArr['Organisation'] = htmlspecialchars(trim($updateOrg));
  482. $updateContactArr['Address line 1'] = htmlspecialchars(trim($updateAdd1));
  483. $updateContactArr['Address line 2'] = htmlspecialchars(trim($updateAdd2));
  484. $updateContactArr['TownCity'] = htmlspecialchars(trim($updateCity));
  485. $updateContactArr['Zip code'] = htmlspecialchars(trim($updateZip));
  486. $updateContactArr['Country Code'] = htmlspecialchars(trim($updateCc));
  487. $updateContactArr['Phone'] = htmlspecialchars(trim($updatePhn));
  488. $updateContactArr['Email'] = htmlspecialchars(trim($updateEmail));
  489. $contactInfo = switchepp_contact_info($client, $contactId, 'Get ' . $type);
  490. $contact_detail = simplexml_load_string($contactInfo);
  491. $contactdataArr = $contact_detail->response->resData->children("contact", true)->infData;
  492. foreach ($contactdataArr->postalInfo as $contactFromSwitch) {
  493. $getName = htmlspecialchars($contactFromSwitch->name);
  494. $getOrg = htmlspecialchars($contactFromSwitch->org);
  495. $getAdd1 = htmlspecialchars($contactFromSwitch->addr->street[0]);
  496. $getAdd2 = htmlspecialchars($contactFromSwitch->addr->street[1]);
  497. $getCity = htmlspecialchars($contactFromSwitch->addr->city);
  498. $getZip = htmlspecialchars($contactFromSwitch->addr->pc);
  499. $getCc = htmlspecialchars($contactFromSwitch->addr->cc);
  500. $getContactArr['Contact Name'] = trim($getName);
  501. $getContactArr['Organisation'] = trim($getOrg);
  502. $getContactArr['Address line 1'] = trim($getAdd1);
  503. $getContactArr['Address line 2'] = trim($getAdd2);
  504. $getContactArr['TownCity'] = trim($getCity);
  505. $getContactArr['Zip code'] = trim($getZip);
  506. $getContactArr['Country Code'] = trim($getCc);
  507. }
  508. $getEmail = htmlspecialchars($contactdataArr->email);
  509. $getPhn = htmlspecialchars($contactdataArr->voice);
  510. $getContactArr['Phone'] = trim($getPhn);
  511. $getContactArr['Email'] = trim($getEmail);
  512. if ($getContactArr == $updateContactArr)
  513. continue;
  514. $updateXml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  515. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  516. <command>
  517. <update>
  518. <contact:update xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
  519. <contact:id>' . $contactId . '</contact:id>
  520. <contact:chg>
  521. <contact:postalInfo type="loc">
  522. <contact:name>' . $updateContactArr['Contact Name'] . '</contact:name>
  523. <contact:org>' . $updateContactArr['Organisation'] . '</contact:org>
  524. <contact:addr>
  525. <contact:street>' . $updateContactArr['Address line 1'] . '</contact:street>
  526. <contact:street>' . $updateContactArr['Address line 2'] . '</contact:street>
  527. <contact:city>' . $updateContactArr['TownCity'] . '</contact:city>
  528. <contact:sp>' . $updateContactArr['TownCity'] . '</contact:sp>
  529. <contact:pc>' . $updateContactArr['Zip code'] . '</contact:pc>
  530. <contact:cc>' . $updateContactArr['Country Code'] . '</contact:cc>
  531. </contact:addr>
  532. </contact:postalInfo>
  533. <contact:voice>' . $updateContactArr['Phone'] . '</contact:voice>
  534. <contact:fax/>
  535. <contact:email>' . $updateContactArr['Email'] . '</contact:email>
  536. <contact:authInfo>
  537. <contact:pw>con-' . time() . '</contact:pw>
  538. </contact:authInfo>
  539. </contact:chg>
  540. </contact:update>
  541. </update>
  542. <clTRID>clientref-' . rand(1000, 9999) . '</clTRID>
  543. </command>
  544. </epp>';
  545. switchepp_write_xml($client, $updateXml, 'Save ' . $type);
  546. }
  547. }
  548. } catch (Exception $ex) {
  549. $values['error'] = $ex->getMessage();
  550. }
  551. if (!empty($client))
  552. switchepp_logoutepp($client, $params);
  553. return $values;
  554. }
  555. #************************Domain Delete*************************#
  556. function switchepp_RequestDelete($params) {
  557. try {
  558. // $check_license = switchepp_license_status($params); #Check License
  559. $client = switchepp_clientloginepp($params); #Epp Connection
  560. $login = switchepp_loggedinepp($client, $params); #Epp Client login
  561. #get domain info
  562. $xml = switchepp_domain_info($params);
  563. $info_domain = switchepp_write_xml($client, $xml, __FUNCTION__ . '(domain info)');
  564. $IDN = new idna_convert();
  565. $input = switcheppGetDomainName($params['domainid']);
  566. $domainname = $IDN->encode($input);
  567. $deletxml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  568. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  569. <command>
  570. <delete>
  571. <domain:delete xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
  572. <domain:name>' . $domainname . '</domain:name>
  573. </domain:delete>
  574. </delete>
  575. <clTRID>delete-domain-' . rand(1000, 9999) . '</clTRID>
  576. </command>
  577. </epp>';
  578. $delete_domain = switchepp_write_xml($client, $deletxml, __FUNCTION__);
  579. } catch (Exception $ex) {
  580. $values['error'] = $ex->getMessage();
  581. }
  582. if (!empty($client))
  583. switchepp_logoutepp($client, $params);
  584. return $values;
  585. }
  586. #******************************Domain transfer********************************#
  587. function switchepp_TransferDomain($params) {
  588. try {
  589. // $check_license = switchepp_license_status($params); #Check License
  590. $client = switchepp_clientloginepp($params); #Epp Connection
  591. $login = switchepp_loggedinepp($client, $params); #Epp Client login
  592. #get domain info
  593. $xml = switchepp_domain_info($params);
  594. $IDN = new idna_convert();
  595. $input = switcheppGetDomainName($params['domainid']);
  596. $domainname = $IDN->encode($input);
  597. #domain transfer
  598. $xmlTransfer = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  599. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  600. <command>
  601. <transfer op="request">
  602. <domain:transfer xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
  603. <domain:name>' . $domainname . '</domain:name>
  604. <domain:authInfo>
  605. <domain:pw>' . htmlentities($params['transfersecret']) . '</domain:pw>
  606. </domain:authInfo>
  607. </domain:transfer>
  608. </transfer>
  609. <clTRID>clientref-' . rand(1000, 9999) . '</clTRID>
  610. </command>
  611. </epp>';
  612. $Transfer_domain = switchepp_write_xml($client, $xmlTransfer, __FUNCTION__);
  613. $regContactId = strtoupper(switchepp_generateContactID(8) . $params['domainid']);
  614. $contactCheckXml = switchepp_checkContact($regContactId);
  615. $contact_check = switchepp_write_xml($client, $contactCheckXml, __FUNCTION__ . ' (check contact)');
  616. if (1 == (int) $contact_check->response->resData->children("contact", true)->chkData->cd[0]->id->attributes()->avail) {
  617. $xmlclient = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  618. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  619. <command>
  620. <create>
  621. <contact:create xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
  622. <contact:id>RE' . $regContactId . '</contact:id>
  623. <contact:postalInfo type="loc">
  624. <contact:name>' . $params['fullname'] . '</contact:name>
  625. <contact:org>' . $params['companyname'] . '</contact:org>
  626. <contact:addr>
  627. <contact:street>' . $params['address1'] . '</contact:street>
  628. <contact:street>' . $params['address2'] . '</contact:street>
  629. <contact:city>' . $params['city'] . '</contact:city>
  630. <contact:pc>' . $params['postcode'] . '</contact:pc>
  631. <contact:cc>' . $params['country'] . '</contact:cc>
  632. </contact:addr>
  633. </contact:postalInfo>
  634. <contact:voice>' . $params['phonenumberformatted'] . '</contact:voice>
  635. <contact:email>' . $params['email'] . '</contact:email>
  636. <contact:authInfo>
  637. <contact:pw>Con-' . time() . '</contact:pw>
  638. </contact:authInfo>
  639. </contact:create>
  640. </create>
  641. <clTRID>clientref-' . rand(1000, 9999) . '</clTRID>
  642. </command>
  643. </epp>';
  644. $create_reg_contact = switchepp_write_xml($client, $xmlclient, __FUNCTION__ . ' (create reg contact)');
  645. $reg_contact_id = $create_reg_contact->response->resData->children('contact', true)->creData->id;
  646. } else
  647. $reg_contact_id = $regContactId;
  648. #*************tech create*****************#
  649. $techContactId = strtoupper(switchepp_generateContactID(6) . $params['domainid']);
  650. $contactCheckXml = switchepp_checkContact($techContactId);
  651. $contact_check = switchepp_write_xml($client, $contactCheckXml, __FUNCTION__ . ' (check contact)');
  652. if (1 == (int) $contact_check->response->resData->children("contact", true)->chkData->cd[0]->id->attributes()->avail) {
  653. $xmlTech = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  654. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  655. <command>
  656. <create>
  657. <contact:create xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
  658. <contact:id>TE' . $techContactId . '</contact:id>
  659. <contact:postalInfo type="loc">
  660. <contact:name>' . $params['adminfirstname'] . ' ' . $params['adminlastname'] . '</contact:name>
  661. <contact:org>' . $params['admincompanyname'] . '</contact:org>
  662. <contact:addr>
  663. <contact:street>' . $params['adminaddress1'] . '</contact:street>
  664. <contact:street>' . $params['adminaddress2'] . '</contact:street>
  665. <contact:city>' . $params['admincity'] . '</contact:city>
  666. <contact:pc>' . $params['adminpostcode'] . '</contact:pc>
  667. <contact:cc>' . $params['admincountry'] . '</contact:cc>
  668. </contact:addr>
  669. </contact:postalInfo>
  670. <contact:voice>' . $params['adminfullphonenumber'] . '</contact:voice>
  671. <contact:email>' . $params['adminemail'] . '</contact:email>
  672. <contact:authInfo>
  673. <contact:pw>Tec-' . time() . '</contact:pw>
  674. </contact:authInfo>
  675. </contact:create>
  676. </create>
  677. <clTRID>clientref-' . rand(1000, 9999) . '</clTRID>
  678. </command>
  679. </epp>';
  680. $create_tech_contact = switchepp_write_xml($client, $xmlTech, __FUNCTION__ . ' (create tech contact)');
  681. $tech_contact_id = $create_tech_contact->response->resData->children('contact', true)->creData->id;
  682. } else
  683. $tech_contact_id = $techContactId;
  684. if ($params['dnssec'] == "on") {
  685. $digestType = $params['digest_type'];
  686. if (empty($digestType))
  687. $digestType = 1;
  688. if ($digestType == 1) {
  689. $string = switchepp_generateDigestRandomString(40);
  690. $digest = strtoupper(bin2hex($string));
  691. $digest = substr($digest, 0, 40);
  692. } elseif ($digestType == 2) {
  693. $string = switchepp_generateDigestRandomString(64);
  694. $digest = strtoupper(bin2hex($string));
  695. $digest = substr($digest, 0, 64);
  696. } elseif ($digestType == 3 || $digestType == 4) {
  697. $string = switchepp_generateDigestRandomString(96);
  698. $digest = strtoupper(bin2hex($string));
  699. $digest = substr($digest, 0, 96);
  700. }
  701. $params['algorithm'] = (!empty($params['algorithm'])) ? $params['algorithm'] : '5';
  702. $dnssec = '<extension>
  703. <secDNS:update xmlns:secDNS="urn:ietf:params:xml:ns:secDNS-1.1">
  704. <secDNS:add>
  705. <secDNS:dsData>
  706. <secDNS:keyTag>' . substr(time(), 0, 5) . '</secDNS:keyTag>
  707. <secDNS:alg>' . $params['algorithm'] . '</secDNS:alg>
  708. <secDNS:digestType>' . $digestType . '</secDNS:digestType>
  709. <secDNS:digest>' . $digest . '</secDNS:digest>
  710. </secDNS:dsData>
  711. </secDNS:add>
  712. </secDNS:update>
  713. </extension>';
  714. }
  715. $xmlUpdate = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  716. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  717. <command>
  718. <update>
  719. <domain:update xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
  720. <domain:name>' . $domainname . '</domain:name>
  721. <domain:add>
  722. <domain:contact type="tech">' . $tech_contact_id . '</domain:contact>
  723. </domain:add>
  724. <domain:chg>
  725. <domain:registrant>' . $reg_contact_id . '</domain:registrant>
  726. </domain:chg>
  727. </domain:update>
  728. </update>
  729. ' . $dnssec . '
  730. <clTRID>clientref-' . rand(1000, 9999) . '</clTRID>
  731. </command>
  732. </epp>';
  733. $update_domain = switchepp_write_xml($client, $xmlUpdate, __FUNCTION__ . ' (Domain update)');
  734. } catch (Exception $ex) {
  735. $values['error'] = $ex->getMessage();
  736. }
  737. if (!empty($client))
  738. switchepp_logoutepp($client, $params);
  739. return $values;
  740. }
  741. #***************************Get Epp Code******************************#
  742. function switchepp_GetEPPCode($params) {
  743. try {
  744. // $check_license = switchepp_license_status($params); #Check License
  745. $client = switchepp_clientloginepp($params); #Epp Connection
  746. $login = switchepp_loggedinepp($client, $params); #Epp Client login
  747. #get domain info
  748. $xml = switchepp_domain_info($params);
  749. $domainPw = switchepp_generateRandomString(15);
  750. $xml = switchepp_update_domain_auth($params, $domainPw);
  751. $domainUpdate = switchepp_write_xml($client, $xml, __FUNCTION__);
  752. $values['eppcode'] = $domainPw;
  753. } catch (Exception $ex) {
  754. $values['error'] = $ex->getMessage();
  755. }
  756. if (!empty($client))
  757. switchepp_logoutepp($client, $params);
  758. return $values;
  759. }
  760. #***************************Custom button function******************************#
  761. function switchepp_AdminCustomButtonArray() {
  762. $buttonarray = array(
  763. "Restore Domain" => "Restore",
  764. );
  765. return $buttonarray;
  766. }
  767. #***************************Restore Domain******************************#
  768. function switchepp_Restore($params) {
  769. try {
  770. // $check_license = switchepp_license_status($params); #Check License
  771. $client = switchepp_clientloginepp($params); #Epp Connection
  772. $login = switchepp_loggedinepp($client, $params); #Epp Client login
  773. #Domain Restore XML
  774. $xml = switchepp_domain_restore($params);
  775. $domainRestore = switchepp_write_xml($client, $xml, __FUNCTION__);
  776. } catch (Exception $ex) {
  777. $values['error'] = $ex->getMessage();
  778. }
  779. if (!empty($client))
  780. switchepp_logoutepp($client, $params);
  781. return $values;
  782. }
  783. #***************************Admin Fields******************************#
  784. function switchepp_AdminDomainsTabFields($params) {
  785. try {
  786. $settingArr = getSwitchEPP_setting($params['domainid']); #get registrar config settings
  787. $params = array_merge($params, $settingArr);
  788. // $check_license = switchepp_license_status($params); #Check License
  789. $client = switchepp_clientloginepp($params); #Epp Connection
  790. $login = switchepp_loggedinepp($client, $params); #Epp Client login
  791. #get domain info
  792. $xml = switchepp_domain_info($params);
  793. $info_domain = switchepp_write_xml($client, $xml, __FUNCTION__ . '(domain info)');
  794. $expDate = $info_domain->response->resData->children("domain", true)->infData->exDate ? date('m-d-Y', strtotime($info_domain->response->resData->children("domain", true)->infData->exDate)) : '';
  795. $status = $info_domain->response->resData->children("domain", true)->infData->status->attributes()->s;
  796. $upDate = $info_domain->response->resData->children("domain", true)->infData->upDate ? date('m-d-Y', strtotime($info_domain->response->resData->children("domain", true)->infData->upDate)) : '';
  797. $transferDate = $info_domain->response->resData->children("domain", true)->infData->trDate ? date('m-d-Y', strtotime($info_domain->response->resData->children("domain", true)->infData->trDate)) : '';
  798. $createDate = $info_domain->response->resData->children("domain", true)->infData->crDate ? date('m-d-Y', strtotime($info_domain->response->resData->children("domain", true)->infData->crDate)) : '';
  799. $html = '';
  800. $html .= '<table width="100%" style="margin-bottom:0;" class="datatable">';
  801. $html .= '<tbody>';
  802. $html .= '<tr align="left">';
  803. $html .= '<th style="text-align: left;">Item</th>';
  804. $html .= '<th style="text-align: left;">Content</th>';
  805. $html .= '</tr>';
  806. $html .= '<tr align="left">';
  807. $html .= '<td>Status</td>';
  808. $html .= '<td>' . $status . '</td>';
  809. $html .= '</tr>';
  810. $html .= '<tr align="left">';
  811. $html .= '<td>Creation Date</td>';
  812. $html .= '<td>' . $createDate . '</td>';
  813. $html .= '</tr>';
  814. $html .= '<tr align="left">';
  815. $html .= '<td>Expiration Date</td>';
  816. $html .= '<td>' . $expDate . '</td>';
  817. $html .= '</tr>';
  818. $html .= '<tr align="left">';
  819. $html .= '<td>Last Update</td>';
  820. $html .= '<td>' . $upDate . '</td>';
  821. $html .= '</tr>';
  822. $html .= '<tr align="left">';
  823. $html .= '<td>Last Transfer</td>';
  824. $html .= '<td>' . $transferDate . '</td>';
  825. $html .= '</tr>';
  826. $html .= '</tbody>';
  827. $html .= '</table>';
  828. $values['Domain Detail'] = $html;
  829. } catch (Exception $ex) {
  830. $values['error'] = $ex->getMessage();
  831. }
  832. if (!empty($client))
  833. switchepp_logoutepp($client, $params);
  834. return $values;
  835. }
  836. #*******************Module Syncronize********************#
  837. function switchepp_Sync($params) {
  838. try {
  839. $client = switchepp_clientloginepp($params); #Epp Connection
  840. $login = switchepp_loggedinepp($client, $params); #Epp Client login
  841. #get domain info
  842. $xml = switchepp_domain_info($params);
  843. $info_domain = switchepp_write_xml($client, $xml, __FUNCTION__ . '(domain info)');
  844. $expDate = substr($info_domain->response->resData->children("domain", true)->infData->exDate, 0, 10);
  845. $statusres = $info_domain->response->resData->children("domain", true)->infData->status->attributes()->s;
  846. $timestamp = strtotime($info_domain->response->resData->children("domain", true)->infData->exDate);
  847. if ($timestamp === false) {
  848. return array(
  849. 'error' => 'Renewal date empty for domain: ' . $params['domain']
  850. );
  851. }
  852. Capsule::table('tbldomains')->where('id', $params['domainid'])->update(['expirydate' => $expDate]);
  853. $domain = Capsule::table('tbldomains')
  854. ->where('id', '=', $params['domainid'])
  855. ->where('donotrenew', '=', '1')
  856. ->where('registrar', '=', 'switchepp')
  857. ->whereRaw('`expirydate` >= CURRENT_DATE() AND `expirydate` < ADDDATE(CURRENT_DATE(), INTERVAL 1 DAY)')
  858. ->first();
  859. if (isset($domain->expirydate)) {
  860. $IDN = new idna_convert();
  861. $input = switcheppGetDomainName($params['domainid']);
  862. $domainname = $IDN->encode($input);
  863. $deletxml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  864. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  865. <command>
  866. <delete>
  867. <domain:delete xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
  868. <domain:name>' . $domainname . '</domain:name>
  869. </domain:delete>
  870. </delete>
  871. <clTRID>delete-domain-' . rand(1000, 9999) . '</clTRID>
  872. </command>
  873. </epp>';
  874. $delete_domain = switchepp_write_xml($client, $deletxml, __FUNCTION__ . ' (delete domain)');
  875. }
  876. if ($timestamp < time()) {
  877. $values['expirydate'] = $expDate;
  878. $values['expired'] = true;
  879. } else {
  880. $values['expirydate'] = $expDate;
  881. $values['active'] = true;
  882. }
  883. } catch (Exception $ex) {
  884. $values['error'] = $ex->getMessage();
  885. }
  886. if (!empty($client))
  887. switchepp_logoutepp($client, $params);
  888. return $values;
  889. }
  890. #*******************Transfer Syncronize********************#
  891. function switchepp_TransferSync($params) {
  892. try {
  893. $client = switchepp_clientloginepp($params); #Epp Connection
  894. $login = switchepp_loggedinepp($client, $params); #Epp Client login
  895. #get domain info
  896. $xml = switchepp_domain_info($params);
  897. $info_domain = switchepp_write_xml($client, $xml, __FUNCTION__ . '(domain info)');
  898. $expDate = substr($info_domain->response->resData->children("domain", true)->infData->exDate, 0, 10);
  899. $statusres = $info_domain->response->resData->children("domain", true)->infData->status->attributes()->s;
  900. if (!$statusres) {
  901. Capsule::table('tbldomains')->where('id', $params['domainid'])->update(["status" => "Cancelled"]);
  902. $values['error'] = "TransferSync/domain-info: Domain not found";
  903. }
  904. Capsule::table('tbldomains')->where('id', $params['domainid'])->update(['expirydate' => $expDate]);
  905. if ($statusres == "ok" || $statusres == "serverTransferProhibited") {
  906. $values['completed'] = true;
  907. } else {
  908. $values['error'] = "Sync/domain-info: Unknown status code '$statusres' ";
  909. }
  910. $values['expirydate'] = $expDate;
  911. } catch (Exception $ex) {
  912. $values['error'] = $ex->getMessage();
  913. }
  914. if (!empty($client))
  915. switchepp_logoutepp($client, $params);
  916. return $values;
  917. }
  918. #***********************Register Nameserver**************************#
  919. function switchepp_RegisterNameserver($params) {
  920. try {
  921. $client = switchepp_clientloginepp($params); #Epp Connection
  922. $login = switchepp_loggedinepp($client, $params); #Epp Client login
  923. #get domain info
  924. $xml = switchepp_domain_info($params);
  925. $xml_Hostcreate = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  926. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  927. <command>
  928. <create>
  929. <host:create xmlns:host="urn:ietf:params:xml:ns:host-1.0">
  930. <host:name>' . $params['nameserver'] . '</host:name>
  931. <host:addr ip="v4">' . $params['ipaddress'] . '</host:addr>
  932. </host:create>
  933. </create>
  934. <clTRID>' . rand(9999999, 100000) . '</clTRID>
  935. </command>
  936. </epp>';
  937. $host_create = switchepp_write_xml($client, $xml_Hostcreate, __FUNCTION__);
  938. } catch (Exception $ex) {
  939. $values['error'] = $ex->getMessage();
  940. }
  941. if (!empty($client))
  942. switchepp_logoutepp($client, $params);
  943. return $values;
  944. }
  945. #**************************Update Nameserver************************#
  946. function switchepp_ModifyNameserver($params) {
  947. try {
  948. //$check_license = switchepp_license_status($params); #Check License
  949. $client = switchepp_clientloginepp($params); #Epp Connection
  950. $login = switchepp_loggedinepp($client, $params); #Epp Client login
  951. #get domain info
  952. $xml = switchepp_domain_info($params);
  953. $update_req = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  954. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  955. <command>
  956. <update>
  957. <host:update xmlns:host="urn:ietf:params:xml:ns:host-1.0">
  958. <host:name>' . $params['nameserver'] . '</host:name>
  959. <host:add>
  960. <host:addr ip="v4">' . $params['currentipaddress'] . '</host:addr>
  961. </host:add>
  962. <host:rem>
  963. <host:addr ip="v6">' . $params['newipaddress'] . '</host:addr>
  964. </host:rem>
  965. </host:update>
  966. </update>
  967. <clTRID>' . rand(9999999, 100000) . '</clTRID>
  968. </command>
  969. </epp>';
  970. $update = switchepp_write_xml($client, $update_req, __FUNCTION__);
  971. } catch (Exception $ex) {
  972. $values['error'] = $ex->getMessage();
  973. }
  974. if (!empty($client))
  975. switchepp_logoutepp($client, $params);
  976. return $values;
  977. }
  978. #**********************Delete Nameserver****************************#
  979. function switchepp_DeleteNameserver($params) {
  980. try {
  981. $client = switchepp_clientloginepp($params); #Epp Connection
  982. $login = switchepp_loggedinepp($client, $params); #Epp Client login
  983. #get domain info
  984. $xml = switchepp_domain_info($params);
  985. $delete_xml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  986. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  987. <command>
  988. <delete>
  989. <host:delete
  990. xmlns:host="urn:ietf:params:xml:ns:host-1.0">
  991. <host:name>' . $params['nameserver'] . '</host:name>
  992. </host:delete>
  993. </delete>
  994. <clTRID>' . rand(9999999, 100000) . '</clTRID>
  995. </command>
  996. </epp>';
  997. $delete = switchepp_write_xml($client, $delete_xml, __FUNCTION__);
  998. } catch (Exception $ex) {
  999. $values['error'] = $ex->getMessage();
  1000. }
  1001. if (!empty($client))
  1002. switchepp_logoutepp($client, $params);
  1003. return $values;
  1004. }
  1005. #*********************Create Epp Connection**************************#
  1006. function switchepp_clientloginepp($params) {
  1007. try {
  1008. $certFile = __DIR__ . '/cert/cert.pem';
  1009. $client = new Net_EPP_Client();
  1010. $use_ssl = true;
  1011. if (file_exists($certFile)) {
  1012. $context = stream_context_create();
  1013. stream_context_set_option($context, 'ssl', 'verify_peer', false);
  1014. stream_context_set_option($context, 'ssl', 'allow_self_signed', true);
  1015. stream_context_set_option($context, 'ssl', 'local_cert', $certFile);
  1016. stream_context_set_option($context, 'ssl', 'passphrase', $params['passphrase']);
  1017. $client->connect($params['eppurl'], $params['eppport'], 300, $use_ssl, $context) or die("Not connected with epp server");
  1018. } else {
  1019. $context = false;
  1020. $client->connect($params['eppurl'], $params['eppport'], 300, $use_ssl, $context) or die("Not connected with epp server");
  1021. }
  1022. } catch (Exception $e) {
  1023. $port = $params['eppport'];
  1024. throw new exception("Connection Error: " . $e->getMessage());
  1025. }
  1026. return $client;
  1027. }
  1028. #*********************Epp client login**************************#
  1029. function switchepp_loggedinepp($client, $params) {
  1030. error_log("switchepp_loggedinepp " . $client . " | " . $params);
  1031. if ($params['svcExtension'] == "on") {
  1032. $dnssec = '<svcExtension>
  1033. <extURI>urn:ietf:params:xml:ns:secDNS-1.1</extURI>
  1034. <extURI>urn:ietf:params:xml:ns:rgp-1.0</extURI>
  1035. <extURI>urn:ietf:params:xml:ns:changePoll-1.0</extURI>
  1036. <extURI>https://www.nic.ch/epp/balance-1.0</extURI>
  1037. </svcExtension>';
  1038. } else {
  1039. $dnssec = '<svcExtension>
  1040. <extURI>urn:ietf:params:xml:ns:rgp-1.0</extURI>
  1041. <extURI>urn:ietf:params:xml:ns:changePoll-1.0</extURI>
  1042. <extURI>https://www.nic.ch/epp/balance-1.0</extURI>
  1043. </svcExtension>';
  1044. }
  1045. $xml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  1046. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  1047. <command>
  1048. <login>
  1049. <clID>' . $params['registrar_id'] . '</clID>
  1050. <pw>' . $params['registrar_password'] . '</pw>
  1051. <options>
  1052. <version>1.0</version>
  1053. <lang>en</lang>
  1054. </options>
  1055. <svcs>
  1056. <objURI>urn:ietf:params:xml:ns:domain-1.0</objURI>
  1057. <objURI>urn:ietf:params:xml:ns:contact-1.0</objURI>
  1058. <objURI>urn:ietf:params:xml:ns:host-1.0</objURI>
  1059. ' . $dnssec . '
  1060. </svcs>
  1061. </login>
  1062. <clTRID>' . rand(9999999, 100000) . '</clTRID>
  1063. </command>
  1064. </epp>';
  1065. error_log("EPP LOGIN: " . $xml);
  1066. $response = $client->request($xml);
  1067. logModuleCall('SWITCH EPP', 'login', $xml, $response);
  1068. $result = new SimpleXMLElement($response);
  1069. if ($result->response->result->attributes()->code >= 2000) {
  1070. throw new exception($result->response->result->msg . '. ' . $result->response->result->extValue->reason);
  1071. }
  1072. return $result;
  1073. }
  1074. function switchepp_logoutepp($client, $params) {
  1075. $xml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  1076. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  1077. <epp:command xmlns:epp="urn:ietf:params:xml:ns:epp-1.0">
  1078. <epp:logout />
  1079. <epp:clTRID>' . $params['registrar_id'] . '</epp:clTRID>
  1080. </epp:command>
  1081. </epp>';
  1082. $response = $client->request($xml);
  1083. logModuleCall('SWITCH EPP', 'logout', $xml, $response);
  1084. }
  1085. #******************** Get Contact info*****************#
  1086. function switchepp_contact_info($client, $contactId, $contactType) {
  1087. #get contact detail
  1088. $xml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  1089. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  1090. <command>
  1091. <info>
  1092. <contact:info xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
  1093. <contact:id>' . $contactId . '</contact:id>
  1094. </contact:info>
  1095. </info>
  1096. <clTRID>clientref-' . rand(1000, 9999) . '</clTRID>
  1097. </command>
  1098. </epp>';
  1099. $response = $client->request($xml);
  1100. logModuleCall('SWITCH EPP', $contactType, $xml, $response);
  1101. return $response;
  1102. }
  1103. #***********************Get domain info*************************#
  1104. function switchepp_domain_info($params) {
  1105. $IDN = new idna_convert();
  1106. $input = switcheppGetDomainName($params['domainid']);
  1107. $domainname = $IDN->encode($input);
  1108. $xml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  1109. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  1110. <command>
  1111. <info>
  1112. <domain:info xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
  1113. <domain:name hosts="all">' . $domainname . '</domain:name>
  1114. </domain:info>
  1115. </info>
  1116. <clTRID>clientref-' . rand(100, 999) . '</clTRID>
  1117. </command>
  1118. </epp>';
  1119. return $xml;
  1120. }
  1121. function switchepp_domain_restore($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. <update>
  1129. <domain:update xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
  1130. <domain:name>' . $domainname . '</domain:name>
  1131. <domain:chg />
  1132. </domain:update>
  1133. </update>
  1134. <extension>
  1135. <rgp:update xmlns:rgp="urn:ietf:params:xml:ns:rgp-1.0">
  1136. <rgp:restore op="request" />
  1137. </rgp:update>
  1138. </extension>
  1139. </command>
  1140. </epp>';
  1141. return $xml;
  1142. }
  1143. function switchepp_update_domain_auth($params, $domainPw) {
  1144. $IDN = new idna_convert();
  1145. $input = switcheppGetDomainName($params['domainid']);
  1146. $domainname = $IDN->encode($input);
  1147. $xml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  1148. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  1149. <command>
  1150. <update>
  1151. <domain:update xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
  1152. <domain:name>' . $domainname . '</domain:name>
  1153. <domain:chg>
  1154. <domain:authInfo>
  1155. <domain:pw>' . $domainPw . '</domain:pw>
  1156. </domain:authInfo>
  1157. </domain:chg>
  1158. </domain:update>
  1159. </update>
  1160. <clTRID>domainupdate-' . rand(1000, 9999) . '</clTRID>
  1161. </command>
  1162. </epp>';
  1163. return $xml;
  1164. }
  1165. function switchepp_checkContact($id) {
  1166. $xml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  1167. <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  1168. <command>
  1169. <check>
  1170. <contact:check xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
  1171. <contact:id>' . $id . '</contact:id>
  1172. </contact:check>
  1173. </check>
  1174. <clTRID>ABC-12345</clTRID>
  1175. </command>
  1176. </epp>';
  1177. return $xml;
  1178. }
  1179. function switchepp_generateRandomString($length = 15) {
  1180. $characters = 'abcdefghijklmnopqrstuvwxyz123456789!@$*%#ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  1181. $charactersLength = strlen($characters);
  1182. $randomString = '';
  1183. for ($i = 0; $i < $length; $i++) {
  1184. $randomString .= $characters[rand(0, $charactersLength - 1)];
  1185. }
  1186. return $randomString;
  1187. }
  1188. function switchepp_generateDigestRandomString($length = 15) {
  1189. $characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  1190. $charactersLength = strlen($characters);
  1191. $randomString = '';
  1192. for ($i = 0; $i < $length; $i++) {
  1193. $randomString .= $characters[rand(0, $charactersLength - 1)];
  1194. }
  1195. return $randomString;
  1196. }
  1197. function switchepp_generateContactID($length = 15) {
  1198. $characters = 'abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  1199. $charactersLength = strlen($characters);
  1200. $randomString = '';
  1201. for ($i = 0; $i < $length; $i++) {
  1202. $randomString .= $characters[rand(0, $charactersLength - 1)];
  1203. }
  1204. return $randomString;
  1205. }
  1206. function switcheppGetDomainName($id) {
  1207. $data = Capsule::table('tbldomains')->where('id', $id)->first();
  1208. return $data->domain;
  1209. }
  1210. function switchepp_write_xml($client, $xml, $action, $extra = NULL) {
  1211. $response = $client->request($xml);
  1212. if (empty($extra)) {
  1213. logModuleCall('SWITCH EPP', $action, $xml, $response);
  1214. $result = new SimpleXMLElement($response);
  1215. if ($result->response->result->attributes()->code >= 2000) {
  1216. throw new exception($result->response->result->msg . '. ' . $result->response->result->extValue->reason);
  1217. }
  1218. return $result;
  1219. }
  1220. }
  1221. function getSwitchEPP_setting($id) {
  1222. #select table domain data
  1223. $domain_select_data = Capsule::table('tbldomains')->where('id', $id)->first();
  1224. #select registrar data
  1225. foreach (Capsule::table('tblregistrars')->where('registrar', $domain_select_data->registrar)->get() as $registrar_data) {
  1226. $data[$registrar_data->setting] = decrypt($registrar_data->value);
  1227. }
  1228. return $data;
  1229. }
  1230. function switchepp_license_status($params) {
  1231. if ($license_check['status'] != 'Active') {
  1232. throw new exception('license is ' . $license_check['status']);
  1233. }
  1234. return $license_check;
  1235. }
  1236. #License function
  1237. ?>