* @author * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ use Illuminate\Database\Capsule\Manager as Capsule; use WGSSWITCHEPP\IDNA\idna_convert as idna_convert; if (!defined("WHMCS")) die("This file cannot be accessed directly"); if (!class_exists('Net_EPP_Protocol')) { if (file_exists(__DIR__ . "/Net/EPP/Client.php")) require_once __DIR__ . "/Net/EPP/Client.php"; } require_once(__DIR__ . '/idna_convert.class.php'); #*********************Registrar config options***************************# function switchepp_getConfigArray() { $configarray = array( "FriendlyName" => array( "Type" => "System", "Value" => "Switch Epp" ), "registrar_id" => array( "FriendlyName" => "Registrar Id", "Type" => "text", "Size" => "50", ), "registrar_password" => array( "FriendlyName" => "Password", "Type" => "password", "Size" => "50", ), "eppurl" => array( "FriendlyName" => "EPP URL", "Type" => "text", "Size" => "50", ), "eppport" => array( "FriendlyName" => "Port Number", "Type" => "text", "Size" => "50", ), "licensenum" => array( "FriendlyName" => "License Key", "Type" => "text", "Size" => "50", ), "dnssec" => array( "FriendlyName" => "DNSSEC", "Type" => "yesno", ), "algorithm" => array( "FriendlyName" => "Algorithm", 'Type' => 'dropdown', 'Options' => "5,7,8,10,13,14,15,16", 'Default' => '5', ), "digest_type" => array( "FriendlyName" => "Digest Type", 'Type' => 'dropdown', 'Options' => "1,2,3,4", 'Default' => '1', ), "passphrase" => array( "FriendlyName" => "Pass Phrase", "Type" => "password", "Size" => "30", "Description" => "It's optional" ), "svcExtension" => array( "FriendlyName" => "Enable svcExtension", "Type" => "yesno", "Description" => "Tick if svcExtension supported." ), "switchepp_version" => array( "FriendlyName" => "Version", "Description" => "3.0.6", ), "switchepp_update" => array( "FriendlyName" => "Updated Date", "Description" => "04 Sep, 2019", ) ); return $configarray; } #*******************Get Nameserver***********************# function switchepp_GetNameservers($params) { try { $client = switchepp_clientloginepp($params); #Epp Connection $login = switchepp_loggedinepp($client, $params); #Epp Client login #get domain info $xml = switchepp_domain_info($params); $info_domain = switchepp_write_xml($client, $xml, __FUNCTION__ . '(domain info)'); $ns = $info_domain->response->resData->children("domain", true)->infData->ns->hostObj; $i = 1; $values = array(); foreach ($ns as $nn) { $values["ns{$i}"] = $nn; $i++; } } catch (Exception $ex) { $values['error'] = $ex->getMessage(); } if (!empty($client)) switchepp_logoutepp($client, $params); return $values; } #*********************Save mameserver**************************# function switchepp_SaveNameservers($params) { try { $client = switchepp_clientloginepp($params); #Epp Connection $login = switchepp_loggedinepp($client, $params); #Epp Client login #get domain info $xml = switchepp_domain_info($params); $info_domain = switchepp_write_xml($client, $xml, __FUNCTION__ . '(domain info)'); $ns = $info_domain->response->resData->children("domain", true)->infData->ns->hostObj; $rem_hosts = ''; foreach ($ns as $nn) { $rem_hosts .= ' ' . $nn . ' '; } # Generate XML for nameservers if ($nameserver1 = $params["ns1"]) { $add_hosts = ' ' . $nameserver1 . ' '; } if ($nameserver2 = $params["ns2"]) { $add_hosts .= ' ' . $nameserver2 . ' '; } if ($nameserver3 = $params["ns3"]) { $add_hosts .= ' ' . $nameserver3 . ' '; } if ($nameserver4 = $params["ns4"]) { $add_hosts .= ' ' . $nameserver4 . ' '; } if ($nameserver5 = $params["ns5"]) { $add_hosts .= ' ' . $nameserver5 . ' '; } $IDN = new idna_convert(); $input = switcheppGetDomainName($params['domainid']); $domainname = $IDN->encode($input); if ($params['dnssec'] == "on") { $digestType = $params['digest_type']; if (empty($digestType)) $digestType = 1; if ($digestType == 1) { $string = switchepp_generateDigestRandomString(40); $digest = strtoupper(bin2hex($string)); $digest = substr($digest, 0, 40); } elseif ($digestType == 2) { $string = switchepp_generateDigestRandomString(64); $digest = strtoupper(bin2hex($string)); $digest = substr($digest, 0, 64); } elseif ($digestType == 3 || $digestType == 4) { $string = switchepp_generateDigestRandomString(96); $digest = strtoupper(bin2hex($string)); $digest = substr($digest, 0, 96); } $params['algorithm'] = (!empty($params['algorithm'])) ? $params['algorithm'] : '5'; $dnssec = ' ' . substr(time(), 0, 5) . ' ' . $params['algorithm'] . ' ' . $digestType . ' ' . $digest . ' '; } $xmlUpdate = ' ' . $domainname . ' ' . $add_hosts . ' ' . $rem_hosts . ' ' . $dnssec . ' clientref-' . rand(1000, 9999) . ' '; $update_domain = switchepp_write_xml($client, $xmlUpdate, __FUNCTION__); } catch (Exception $ex) { $values['error'] = $ex->getMessage(); } if (!empty($client)) switchepp_logoutepp($client, $params); return $values; } #*************************Domain Register****************************# function switchepp_RegisterDomain($params) { try { // $check_license = switchepp_license_status($params); #Check License $client = switchepp_clientloginepp($params); #Epp Connection $login = switchepp_loggedinepp($client, $params); #Epp Client login #get domain info $xmlcheck = ' ' . switcheppGetDomainName($params['domainid']) . ' ' . rand(9999999, 100000) . ' '; $domain_check = switchepp_write_xml($client, $xmlcheck, __FUNCTION__ . '( check domain)'); if (0 == (int) $domain_check->response->resData->children("domain", true)->chkData->cd[0]->name->attributes()->avail) 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); $regContactId = strtoupper(switchepp_generateContactID(8) . $params['domainid']); $contactCheckXml = switchepp_checkContact($regContactId); $contact_check = switchepp_write_xml($client, $contactCheckXml, __FUNCTION__ . ' (check contact)'); if (1 == (int) $contact_check->response->resData->children("contact", true)->chkData->cd[0]->id->attributes()->avail) { $xmlclient = ' REG' . $regContactId . ' ' . $params['fullname'] . ' ' . $params['companyname'] . ' ' . $params['address1'] . ' ' . $params['address2'] . ' ' . $params['city'] . ' ' . $params['postcode'] . ' ' . $params['country'] . ' ' . $params['phonenumberformatted'] . ' ' . $params['email'] . ' Con-' . time() . ' Regcon-' . rand(1000, 9999) . ' '; $create_reg_contact = switchepp_write_xml($client, $xmlclient, __FUNCTION__ . '( create reg contact)'); $reg_contact_id = $create_reg_contact->response->resData->children('contact', true)->creData->id; } else { $reg_contact_id = $regContactId; } #*************tech create*****************# $techContactId = strtoupper(switchepp_generateContactID(6) . $params['domainid']); $contactCheckXml = switchepp_checkContact($techContactId); $contact_check = switchepp_write_xml($client, $contactCheckXml, __FUNCTION__ . ' (check contact)'); if (1 == (int) $contact_check->response->resData->children("contact", true)->chkData->cd[0]->id->attributes()->avail) { $xmlTech = ' TE' . $techContactId . ' ' . $params['adminfirstname'] . ' ' . $params['adminlastname'] . ' ' . $params['admincompanyname'] . ' ' . $params['adminaddress1'] . ' ' . $params['adminaddress2'] . ' ' . $params['admincity'] . ' ' . $params['adminpostcode'] . ' ' . $params['admincountry'] . ' ' . $params['adminfullphonenumber'] . ' ' . $params['adminemail'] . ' Tec-' . time() . ' clientref-' . rand(1000, 9999) . ' '; $create_tech_contact = switchepp_write_xml($client, $xmlTech, __FUNCTION__ . '( create tech contact)'); $tech_contact_id = $create_tech_contact->response->resData->children('contact', true)->creData->id; } else { $tech_contact_id = $techContactId; } #*******************NameServer*************# if ($params['ns1']) { $ns .= '' . $params['ns1'] . ''; } if ($params['ns2']) { $ns .= '' . $params['ns2'] . ''; } if ($params['ns3']) { $ns .= '' . $params['ns3'] . ''; } if ($params['ns4']) { $ns .= '' . $params['ns4'] . ''; } if ($ns) { $nsnameserver = ' ' . $ns . ' '; } $IDN = new idna_convert(); $input = switcheppGetDomainName($params['domainid']); $domainname = $IDN->encode($input); if ($params['dnssec'] == "on") { $digestType = $params['digest_type']; if (empty($digestType)) $digestType = 1; if ($digestType == 1) { $string = switchepp_generateDigestRandomString(40); $digest = strtoupper(bin2hex($string)); $digest = substr($digest, 0, 40); } elseif ($digestType == 2) { $string = switchepp_generateDigestRandomString(64); $digest = strtoupper(bin2hex($string)); $digest = substr($digest, 0, 64); } elseif ($digestType == 3 || $digestType == 4) { $string = switchepp_generateDigestRandomString(96); $digest = strtoupper(bin2hex($string)); $digest = substr($digest, 0, 96); } $params['algorithm'] = (!empty($params['algorithm'])) ? $params['algorithm'] : '5'; $dnssec = ' ' . substr(time(), 0, 5) . ' ' . $params['algorithm'] . ' ' . $digestType . ' ' . $digest . ' '; } $domainPw = switchepp_generateRandomString(15); #domian create command $xmldomain = ' ' . $domainname . ' ' . $nsnameserver . ' ' . $reg_contact_id . ' ' . $tech_contact_id . ' ' . $domainPw . ' ' . $dnssec . ' ' . rand(9999999, 100000) . ' '; $domain_create = switchepp_write_xml($client, $xmldomain, __FUNCTION__); } catch (Exception $ex) { $values['error'] = $ex->getMessage(); } if (!empty($client)) switchepp_logoutepp($client, $params); return $values; } #**********************************Renew Domain*******************************# /* function switchepp_RenewDomain($params) { $userIdentifier = $params['APIUsername']; $apiKey = $params['APIKey']; $testMode = $params['TestMode']; $accountMode = $params['AccountMode']; $emailPreference = $params['EmailPreference']; // registration parameters $sld = $params['sld']; $tld = $params['tld']; $registrationPeriod = $params['regperiod']; // domain addon purchase status $enableDnsManagement = (bool) $params['dnsmanagement']; $enableEmailForwarding = (bool) $params['emailforwarding']; $enableIdProtection = (bool) $params['idprotection']; }*/ #**********************************Get Contact Detail*******************************# function switchepp_GetContactDetails($params) { try { // $check_license = switchepp_license_status($params); #Check License $client = switchepp_clientloginepp($params); #Epp Connection $login = switchepp_loggedinepp($client, $params); #Epp Client login #get domain info $xml = switchepp_domain_info($params); $info_domain = switchepp_write_xml($client, $xml, __FUNCTION__ . '(domain info)'); $registrant_id = $info_domain->response->resData->children("domain", true)->infData->registrant; #registrant id $Tech_id = $info_domain->response->resData->children("domain", true)->infData->contact; #Tech id $xml2 = ' ' . $registrant_id . ' clientref-' . rand(1000, 9999) . ' '; $info_contact = switchepp_write_xml($client, $xml2, __FUNCTION__ . '(registrant contact info)'); $contactdataArr = $info_contact->response->resData->children("contact", true)->infData; $results["Registrant"]["Contact Name"] = $contactdataArr->postalInfo->name; $results["Registrant"]["Organisation"] = $contactdataArr->postalInfo->org; $results["Registrant"]["Address line 1"] = $contactdataArr->postalInfo->addr->street[0]; $results["Registrant"]["Address line 2"] = $contactdataArr->postalInfo->addr->street[1]; $results["Registrant"]["TownCity"] = $contactdataArr->postalInfo->addr->city; $results["Registrant"]["Zip code"] = $contactdataArr->postalInfo->addr->pc; $results["Registrant"]["Country Code"] = $contactdataArr->postalInfo->addr->cc; $results["Registrant"]["Phone"] = $contactdataArr->voice; $results["Registrant"]["Email"] = $contactdataArr->email; if (!empty($Tech_id)) { #get tech detail $xml3 = ' ' . $Tech_id . ' clientref-' . rand(1000, 9999) . ' '; $tect_info_contact = switchepp_write_xml($client, $xml3, __FUNCTION__ . '(tech contact info)'); #*************************Show tech information in field****************************# $techdataArr = $tect_info_contact->response->resData->children("contact", true)->infData; $results["Technical"]["Contact Name"] = $techdataArr->postalInfo->name; $results["Technical"]["Organisation"] = $techdataArr->postalInfo->org; $results["Technical"]["Address line 1"] = $techdataArr->postalInfo->addr->street[0]; $results["Technical"]["Address line 2"] = $techdataArr->postalInfo->addr->street[1]; $results["Technical"]["TownCity"] = $techdataArr->postalInfo->addr->city; $results["Technical"]["Zip code"] = $techdataArr->postalInfo->addr->pc; $results["Technical"]["Country Code"] = $techdataArr->postalInfo->addr->cc; $results["Technical"]["Phone"] = $techdataArr->voice; $results["Technical"]["Email"] = $techdataArr->email; } } catch (Exception $ex) { $results['error'] = $ex->getMessage(); } if (!empty($client)) switchepp_logoutepp($client, $params); return $results; } #******************Save Contact/Tech Detail*********************# function switchepp_SaveContactDetails($params) { try { // $check_license = switchepp_license_status($params); #Check License $client = switchepp_clientloginepp($params); #Epp Connection $login = switchepp_loggedinepp($client, $params); #Epp Client login #get domain info $xml = switchepp_domain_info($params); $info_domain = switchepp_write_xml($client, $xml, __FUNCTION__ . '(domain info)'); $registrant_id = $info_domain->response->resData->children("domain", true)->infData->registrant; #registrant id $Tech_id = $info_domain->response->resData->children("domain", true)->infData->contact; #Tech id $contactArr = ['Registrant' => $registrant_id, 'Technical' => $Tech_id]; $updateContactArr = $getContactArr = []; foreach ($contactArr as $type => $contactId) { if (!empty($contactArr[$type])) { $contact = []; $contact = $params['contactdetails'][$type]; $updateName = ($contact['Full Name']) ? $contact['Full Name'] : $contact['Contact Name']; $updateOrg = ($contact['Organisation Name']) ? $contact['Organisation Name'] : $contact['Organisation']; $updateAdd1 = ($contact['Address 1']) ? $contact['Address 1'] : $contact['Address line 1']; $updateAdd2 = ($contact['Address 2']) ? $contact['Address 2'] : $contact['Address line 2']; $updateCity = ($contact['City']) ? $contact['City'] : $contact['TownCity']; $updateZip = ($contact['Postcode']) ? $contact['Postcode'] : $contact['Zip code']; $updateCc = ($contact['Country']) ? $contact['Country'] : $contact['Country Code']; $updateEmail = $contact['Email']; $updatePhn = ($contact['Phone Number']) ? $contact['Phone Number'] : $contact['Phone']; $updateContactArr['Contact Name'] = htmlspecialchars(trim($updateName)); $updateContactArr['Organisation'] = htmlspecialchars(trim($updateOrg)); $updateContactArr['Address line 1'] = htmlspecialchars(trim($updateAdd1)); $updateContactArr['Address line 2'] = htmlspecialchars(trim($updateAdd2)); $updateContactArr['TownCity'] = htmlspecialchars(trim($updateCity)); $updateContactArr['Zip code'] = htmlspecialchars(trim($updateZip)); $updateContactArr['Country Code'] = htmlspecialchars(trim($updateCc)); $updateContactArr['Phone'] = htmlspecialchars(trim($updatePhn)); $updateContactArr['Email'] = htmlspecialchars(trim($updateEmail)); $contactInfo = switchepp_contact_info($client, $contactId, 'Get ' . $type); $contact_detail = simplexml_load_string($contactInfo); $contactdataArr = $contact_detail->response->resData->children("contact", true)->infData; foreach ($contactdataArr->postalInfo as $contactFromSwitch) { $getName = htmlspecialchars($contactFromSwitch->name); $getOrg = htmlspecialchars($contactFromSwitch->org); $getAdd1 = htmlspecialchars($contactFromSwitch->addr->street[0]); $getAdd2 = htmlspecialchars($contactFromSwitch->addr->street[1]); $getCity = htmlspecialchars($contactFromSwitch->addr->city); $getZip = htmlspecialchars($contactFromSwitch->addr->pc); $getCc = htmlspecialchars($contactFromSwitch->addr->cc); $getContactArr['Contact Name'] = trim($getName); $getContactArr['Organisation'] = trim($getOrg); $getContactArr['Address line 1'] = trim($getAdd1); $getContactArr['Address line 2'] = trim($getAdd2); $getContactArr['TownCity'] = trim($getCity); $getContactArr['Zip code'] = trim($getZip); $getContactArr['Country Code'] = trim($getCc); } $getEmail = htmlspecialchars($contactdataArr->email); $getPhn = htmlspecialchars($contactdataArr->voice); $getContactArr['Phone'] = trim($getPhn); $getContactArr['Email'] = trim($getEmail); if ($getContactArr == $updateContactArr) continue; $updateXml = ' ' . $contactId . ' ' . $updateContactArr['Contact Name'] . ' ' . $updateContactArr['Organisation'] . ' ' . $updateContactArr['Address line 1'] . ' ' . $updateContactArr['Address line 2'] . ' ' . $updateContactArr['TownCity'] . ' ' . $updateContactArr['TownCity'] . ' ' . $updateContactArr['Zip code'] . ' ' . $updateContactArr['Country Code'] . ' ' . $updateContactArr['Phone'] . ' ' . $updateContactArr['Email'] . ' con-' . time() . ' clientref-' . rand(1000, 9999) . ' '; switchepp_write_xml($client, $updateXml, 'Save ' . $type); } } } catch (Exception $ex) { $values['error'] = $ex->getMessage(); } if (!empty($client)) switchepp_logoutepp($client, $params); return $values; } #************************Domain Delete*************************# function switchepp_RequestDelete($params) { try { // $check_license = switchepp_license_status($params); #Check License $client = switchepp_clientloginepp($params); #Epp Connection $login = switchepp_loggedinepp($client, $params); #Epp Client login #get domain info $xml = switchepp_domain_info($params); $info_domain = switchepp_write_xml($client, $xml, __FUNCTION__ . '(domain info)'); $IDN = new idna_convert(); $input = switcheppGetDomainName($params['domainid']); $domainname = $IDN->encode($input); $deletxml = ' ' . $domainname . ' delete-domain-' . rand(1000, 9999) . ' '; $delete_domain = switchepp_write_xml($client, $deletxml, __FUNCTION__); } catch (Exception $ex) { $values['error'] = $ex->getMessage(); } if (!empty($client)) switchepp_logoutepp($client, $params); return $values; } #******************************Domain transfer********************************# function switchepp_TransferDomain($params) { try { // $check_license = switchepp_license_status($params); #Check License $client = switchepp_clientloginepp($params); #Epp Connection $login = switchepp_loggedinepp($client, $params); #Epp Client login #get domain info $xml = switchepp_domain_info($params); $IDN = new idna_convert(); $input = switcheppGetDomainName($params['domainid']); $domainname = $IDN->encode($input); #domain transfer $xmlTransfer = ' ' . $domainname . ' ' . htmlentities($params['transfersecret']) . ' clientref-' . rand(1000, 9999) . ' '; $Transfer_domain = switchepp_write_xml($client, $xmlTransfer, __FUNCTION__); $regContactId = strtoupper(switchepp_generateContactID(8) . $params['domainid']); $contactCheckXml = switchepp_checkContact($regContactId); $contact_check = switchepp_write_xml($client, $contactCheckXml, __FUNCTION__ . ' (check contact)'); if (1 == (int) $contact_check->response->resData->children("contact", true)->chkData->cd[0]->id->attributes()->avail) { $xmlclient = ' RE' . $regContactId . ' ' . $params['fullname'] . ' ' . $params['companyname'] . ' ' . $params['address1'] . ' ' . $params['address2'] . ' ' . $params['city'] . ' ' . $params['postcode'] . ' ' . $params['country'] . ' ' . $params['phonenumberformatted'] . ' ' . $params['email'] . ' Con-' . time() . ' clientref-' . rand(1000, 9999) . ' '; $create_reg_contact = switchepp_write_xml($client, $xmlclient, __FUNCTION__ . ' (create reg contact)'); $reg_contact_id = $create_reg_contact->response->resData->children('contact', true)->creData->id; } else $reg_contact_id = $regContactId; #*************tech create*****************# $techContactId = strtoupper(switchepp_generateContactID(6) . $params['domainid']); $contactCheckXml = switchepp_checkContact($techContactId); $contact_check = switchepp_write_xml($client, $contactCheckXml, __FUNCTION__ . ' (check contact)'); if (1 == (int) $contact_check->response->resData->children("contact", true)->chkData->cd[0]->id->attributes()->avail) { $xmlTech = ' TE' . $techContactId . ' ' . $params['adminfirstname'] . ' ' . $params['adminlastname'] . ' ' . $params['admincompanyname'] . ' ' . $params['adminaddress1'] . ' ' . $params['adminaddress2'] . ' ' . $params['admincity'] . ' ' . $params['adminpostcode'] . ' ' . $params['admincountry'] . ' ' . $params['adminfullphonenumber'] . ' ' . $params['adminemail'] . ' Tec-' . time() . ' clientref-' . rand(1000, 9999) . ' '; $create_tech_contact = switchepp_write_xml($client, $xmlTech, __FUNCTION__ . ' (create tech contact)'); $tech_contact_id = $create_tech_contact->response->resData->children('contact', true)->creData->id; } else $tech_contact_id = $techContactId; if ($params['dnssec'] == "on") { $digestType = $params['digest_type']; if (empty($digestType)) $digestType = 1; if ($digestType == 1) { $string = switchepp_generateDigestRandomString(40); $digest = strtoupper(bin2hex($string)); $digest = substr($digest, 0, 40); } elseif ($digestType == 2) { $string = switchepp_generateDigestRandomString(64); $digest = strtoupper(bin2hex($string)); $digest = substr($digest, 0, 64); } elseif ($digestType == 3 || $digestType == 4) { $string = switchepp_generateDigestRandomString(96); $digest = strtoupper(bin2hex($string)); $digest = substr($digest, 0, 96); } $params['algorithm'] = (!empty($params['algorithm'])) ? $params['algorithm'] : '5'; $dnssec = ' ' . substr(time(), 0, 5) . ' ' . $params['algorithm'] . ' ' . $digestType . ' ' . $digest . ' '; } $xmlUpdate = ' ' . $domainname . ' ' . $tech_contact_id . ' ' . $reg_contact_id . ' ' . $dnssec . ' clientref-' . rand(1000, 9999) . ' '; $update_domain = switchepp_write_xml($client, $xmlUpdate, __FUNCTION__ . ' (Domain update)'); } catch (Exception $ex) { $values['error'] = $ex->getMessage(); } if (!empty($client)) switchepp_logoutepp($client, $params); return $values; } #***************************Get Epp Code******************************# function switchepp_GetEPPCode($params) { try { // $check_license = switchepp_license_status($params); #Check License $client = switchepp_clientloginepp($params); #Epp Connection $login = switchepp_loggedinepp($client, $params); #Epp Client login #get domain info $xml = switchepp_domain_info($params); $domainPw = switchepp_generateRandomString(15); $xml = switchepp_update_domain_auth($params, $domainPw); $domainUpdate = switchepp_write_xml($client, $xml, __FUNCTION__); $values['eppcode'] = $domainPw; } catch (Exception $ex) { $values['error'] = $ex->getMessage(); } if (!empty($client)) switchepp_logoutepp($client, $params); return $values; } #***************************Custom button function******************************# function switchepp_AdminCustomButtonArray() { $buttonarray = array( "Restore Domain" => "Restore", ); return $buttonarray; } #***************************Restore Domain******************************# function switchepp_Restore($params) { try { // $check_license = switchepp_license_status($params); #Check License $client = switchepp_clientloginepp($params); #Epp Connection $login = switchepp_loggedinepp($client, $params); #Epp Client login #Domain Restore XML $xml = switchepp_domain_restore($params); $domainRestore = switchepp_write_xml($client, $xml, __FUNCTION__); } catch (Exception $ex) { $values['error'] = $ex->getMessage(); } if (!empty($client)) switchepp_logoutepp($client, $params); return $values; } #***************************Admin Fields******************************# function switchepp_AdminDomainsTabFields($params) { try { $settingArr = getSwitchEPP_setting($params['domainid']); #get registrar config settings $params = array_merge($params, $settingArr); // $check_license = switchepp_license_status($params); #Check License $client = switchepp_clientloginepp($params); #Epp Connection $login = switchepp_loggedinepp($client, $params); #Epp Client login #get domain info $xml = switchepp_domain_info($params); $info_domain = switchepp_write_xml($client, $xml, __FUNCTION__ . '(domain info)'); $expDate = $info_domain->response->resData->children("domain", true)->infData->exDate ? date('m-d-Y', strtotime($info_domain->response->resData->children("domain", true)->infData->exDate)) : ''; $status = $info_domain->response->resData->children("domain", true)->infData->status->attributes()->s; $upDate = $info_domain->response->resData->children("domain", true)->infData->upDate ? date('m-d-Y', strtotime($info_domain->response->resData->children("domain", true)->infData->upDate)) : ''; $transferDate = $info_domain->response->resData->children("domain", true)->infData->trDate ? date('m-d-Y', strtotime($info_domain->response->resData->children("domain", true)->infData->trDate)) : ''; $createDate = $info_domain->response->resData->children("domain", true)->infData->crDate ? date('m-d-Y', strtotime($info_domain->response->resData->children("domain", true)->infData->crDate)) : ''; $html = ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= '
ItemContent
Status' . $status . '
Creation Date' . $createDate . '
Expiration Date' . $expDate . '
Last Update' . $upDate . '
Last Transfer' . $transferDate . '
'; $values['Domain Detail'] = $html; } catch (Exception $ex) { $values['error'] = $ex->getMessage(); } if (!empty($client)) switchepp_logoutepp($client, $params); return $values; } #*******************Module Syncronize********************# function switchepp_Sync($params) { try { $client = switchepp_clientloginepp($params); #Epp Connection $login = switchepp_loggedinepp($client, $params); #Epp Client login #get domain info $xml = switchepp_domain_info($params); $info_domain = switchepp_write_xml($client, $xml, __FUNCTION__ . '(domain info)'); $expDate = substr($info_domain->response->resData->children("domain", true)->infData->exDate, 0, 10); $statusres = $info_domain->response->resData->children("domain", true)->infData->status->attributes()->s; $timestamp = strtotime($info_domain->response->resData->children("domain", true)->infData->exDate); if ($timestamp === false) { return array( 'error' => 'Renewal date empty for domain: ' . $params['domain'] ); } Capsule::table('tbldomains')->where('id', $params['domainid'])->update(['expirydate' => $expDate]); $domain = Capsule::table('tbldomains') ->where('id', '=', $params['domainid']) ->where('donotrenew', '=', '1') ->where('registrar', '=', 'switchepp') ->whereRaw('`expirydate` >= CURRENT_DATE() AND `expirydate` < ADDDATE(CURRENT_DATE(), INTERVAL 1 DAY)') ->first(); if (isset($domain->expirydate)) { $IDN = new idna_convert(); $input = switcheppGetDomainName($params['domainid']); $domainname = $IDN->encode($input); $deletxml = ' ' . $domainname . ' delete-domain-' . rand(1000, 9999) . ' '; $delete_domain = switchepp_write_xml($client, $deletxml, __FUNCTION__ . ' (delete domain)'); } if ($timestamp < time()) { $values['expirydate'] = $expDate; $values['expired'] = true; } else { $values['expirydate'] = $expDate; $values['active'] = true; } } catch (Exception $ex) { $values['error'] = $ex->getMessage(); } if (!empty($client)) switchepp_logoutepp($client, $params); return $values; } #*******************Transfer Syncronize********************# function switchepp_TransferSync($params) { try { $client = switchepp_clientloginepp($params); #Epp Connection $login = switchepp_loggedinepp($client, $params); #Epp Client login #get domain info $xml = switchepp_domain_info($params); $info_domain = switchepp_write_xml($client, $xml, __FUNCTION__ . '(domain info)'); $expDate = substr($info_domain->response->resData->children("domain", true)->infData->exDate, 0, 10); $statusres = $info_domain->response->resData->children("domain", true)->infData->status->attributes()->s; if (!$statusres) { Capsule::table('tbldomains')->where('id', $params['domainid'])->update(["status" => "Cancelled"]); $values['error'] = "TransferSync/domain-info: Domain not found"; } Capsule::table('tbldomains')->where('id', $params['domainid'])->update(['expirydate' => $expDate]); if ($statusres == "ok" || $statusres == "serverTransferProhibited") { $values['completed'] = true; } else { $values['error'] = "Sync/domain-info: Unknown status code '$statusres' "; } $values['expirydate'] = $expDate; } catch (Exception $ex) { $values['error'] = $ex->getMessage(); } if (!empty($client)) switchepp_logoutepp($client, $params); return $values; } #***********************Register Nameserver**************************# function switchepp_RegisterNameserver($params) { try { $client = switchepp_clientloginepp($params); #Epp Connection $login = switchepp_loggedinepp($client, $params); #Epp Client login #get domain info $xml = switchepp_domain_info($params); $xml_Hostcreate = ' ' . $params['nameserver'] . ' ' . $params['ipaddress'] . ' ' . rand(9999999, 100000) . ' '; $host_create = switchepp_write_xml($client, $xml_Hostcreate, __FUNCTION__); } catch (Exception $ex) { $values['error'] = $ex->getMessage(); } if (!empty($client)) switchepp_logoutepp($client, $params); return $values; } #**************************Update Nameserver************************# function switchepp_ModifyNameserver($params) { try { //$check_license = switchepp_license_status($params); #Check License $client = switchepp_clientloginepp($params); #Epp Connection $login = switchepp_loggedinepp($client, $params); #Epp Client login #get domain info $xml = switchepp_domain_info($params); $update_req = ' ' . $params['nameserver'] . ' ' . $params['currentipaddress'] . ' ' . $params['newipaddress'] . ' ' . rand(9999999, 100000) . ' '; $update = switchepp_write_xml($client, $update_req, __FUNCTION__); } catch (Exception $ex) { $values['error'] = $ex->getMessage(); } if (!empty($client)) switchepp_logoutepp($client, $params); return $values; } #**********************Delete Nameserver****************************# function switchepp_DeleteNameserver($params) { try { $client = switchepp_clientloginepp($params); #Epp Connection $login = switchepp_loggedinepp($client, $params); #Epp Client login #get domain info $xml = switchepp_domain_info($params); $delete_xml = ' ' . $params['nameserver'] . ' ' . rand(9999999, 100000) . ' '; $delete = switchepp_write_xml($client, $delete_xml, __FUNCTION__); } catch (Exception $ex) { $values['error'] = $ex->getMessage(); } if (!empty($client)) switchepp_logoutepp($client, $params); return $values; } #*********************Create Epp Connection**************************# function switchepp_clientloginepp($params) { try { $certFile = __DIR__ . '/cert/cert.pem'; $client = new Net_EPP_Client(); $use_ssl = true; if (file_exists($certFile)) { $context = stream_context_create(); stream_context_set_option($context, 'ssl', 'verify_peer', false); stream_context_set_option($context, 'ssl', 'allow_self_signed', true); stream_context_set_option($context, 'ssl', 'local_cert', $certFile); stream_context_set_option($context, 'ssl', 'passphrase', $params['passphrase']); $client->connect($params['eppurl'], $params['eppport'], 300, $use_ssl, $context) or die("Not connected with epp server"); } else { $context = false; $client->connect($params['eppurl'], $params['eppport'], 300, $use_ssl, $context) or die("Not connected with epp server"); } } catch (Exception $e) { $port = $params['eppport']; throw new exception("Connection Error: " . $e->getMessage()); } return $client; } #*********************Epp client login**************************# function switchepp_loggedinepp($client, $params) { # error_log("switchepp_loggedinepp " . $client . " | " . $params); if ($params['svcExtension'] == "on") { $dnssec = ' urn:ietf:params:xml:ns:secDNS-1.1 urn:ietf:params:xml:ns:rgp-1.0 urn:ietf:params:xml:ns:changePoll-1.0 https://www.nic.ch/epp/balance-1.0 '; } else { $dnssec = ' urn:ietf:params:xml:ns:rgp-1.0 urn:ietf:params:xml:ns:changePoll-1.0 https://www.nic.ch/epp/balance-1.0 '; } $xml = ' ' . $params['registrar_id'] . ' ' . $params['registrar_password'] . ' 1.0 en urn:ietf:params:xml:ns:domain-1.0 urn:ietf:params:xml:ns:contact-1.0 urn:ietf:params:xml:ns:host-1.0 ' . $dnssec . ' ' . rand(9999999, 100000) . ' '; error_log("EPP LOGIN: " . $xml); $response = $client->request($xml); logModuleCall('SWITCH EPP', 'login', $xml, $response); $result = new SimpleXMLElement($response); if ($result->response->result->attributes()->code >= 2000) { throw new exception($result->response->result->msg . '. ' . $result->response->result->extValue->reason); } return $result; } function switchepp_logoutepp($client, $params) { $xml = ' ' . $params['registrar_id'] . ' '; $response = $client->request($xml); logModuleCall('SWITCH EPP', 'logout', $xml, $response); } #******************** Get Contact info*****************# function switchepp_contact_info($client, $contactId, $contactType) { #get contact detail $xml = ' ' . $contactId . ' clientref-' . rand(1000, 9999) . ' '; $response = $client->request($xml); logModuleCall('SWITCH EPP', $contactType, $xml, $response); return $response; } #***********************Get domain info*************************# function switchepp_domain_info($params) { $IDN = new idna_convert(); $input = switcheppGetDomainName($params['domainid']); $domainname = $IDN->encode($input); $xml = ' ' . $domainname . ' clientref-' . rand(100, 999) . ' '; return $xml; } function switchepp_domain_restore($params) { $IDN = new idna_convert(); $input = switcheppGetDomainName($params['domainid']); $domainname = $IDN->encode($input); $xml = ' ' . $domainname . ' '; return $xml; } function switchepp_update_domain_auth($params, $domainPw) { $IDN = new idna_convert(); $input = switcheppGetDomainName($params['domainid']); $domainname = $IDN->encode($input); $xml = ' ' . $domainname . ' ' . $domainPw . ' domainupdate-' . rand(1000, 9999) . ' '; return $xml; } function switchepp_checkContact($id) { $xml = ' ' . $id . ' ABC-12345 '; return $xml; } function switchepp_generateRandomString($length = 15) { $characters = 'abcdefghijklmnopqrstuvwxyz123456789!@$*%#ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $charactersLength = strlen($characters); $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, $charactersLength - 1)]; } return $randomString; } function switchepp_generateDigestRandomString($length = 15) { $characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $charactersLength = strlen($characters); $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, $charactersLength - 1)]; } return $randomString; } function switchepp_generateContactID($length = 15) { $characters = 'abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $charactersLength = strlen($characters); $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, $charactersLength - 1)]; } return $randomString; } function switcheppGetDomainName($id) { $data = Capsule::table('tbldomains')->where('id', $id)->first(); return $data->domain; } function switchepp_write_xml($client, $xml, $action, $extra = NULL) { $response = $client->request($xml); if (empty($extra)) { logModuleCall('SWITCH EPP', $action, $xml, $response); $result = new SimpleXMLElement($response); if ($result->response->result->attributes()->code >= 2000) { throw new exception($result->response->result->msg . '. ' . $result->response->result->extValue->reason); } return $result; } } function getSwitchEPP_setting($id) { #select table domain data $domain_select_data = Capsule::table('tbldomains')->where('id', $id)->first(); #select registrar data foreach (Capsule::table('tblregistrars')->where('registrar', $domain_select_data->registrar)->get() as $registrar_data) { $data[$registrar_data->setting] = decrypt($registrar_data->value); } return $data; } function switchepp_license_status($params) { if ($license_check['status'] != 'Active') { throw new exception('license is ' . $license_check['status']); } return $license_check; } #License function ?>