switchepp.php 68 KB

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