From 0728d473bb6a155e592b54852a75830f1c86c633 Mon Sep 17 00:00:00 2001 From: xa81 Date: Thu, 9 Jan 2025 19:58:43 +0300 Subject: [PATCH] v1.0.9 --- components/modules/domainnameapi/apis/api.php | 537 ++++++++++-------- components/modules/domainnameapi/config.json | 2 +- .../modules/domainnameapi/domainnameapi.php | 2 +- 3 files changed, 316 insertions(+), 225 deletions(-) diff --git a/components/modules/domainnameapi/apis/api.php b/components/modules/domainnameapi/apis/api.php index d029acc..f74524b 100644 --- a/components/modules/domainnameapi/apis/api.php +++ b/components/modules/domainnameapi/apis/api.php @@ -10,7 +10,7 @@ /** * Class DomainNameAPI_PHPLibrary * @package DomainNameApi - * @version 2.1.3 + * @version 2.1.4 */ @@ -26,7 +26,7 @@ class DomainNameAPI_PHPLibrary /** * Version of the library */ - const VERSION = '2.1.3'; + const VERSION = '2.1.4'; const DEFAULT_NAMESERVERS = [ 'ns1.domainnameapi.com', @@ -36,13 +36,38 @@ class DomainNameAPI_PHPLibrary const DEFAULT_IGNORED_ERRORS=[ 'Domain not found', 'ERR_DOMAIN_NOT_FOUND', - 'Reseller not found' + 'Reseller not found', + 'Domain is not in updateable status. It must be active', + 'balance is not sufficient', + 'Price definition not found', ]; const DEFAULT_CACHE_TTL = 512; const DEFAULT_TIMEOUT = 20; const DEFAULT_REASON = 'Owner request'; + const APPLICATION_WHMCS = 'WHMCS'; + const APPLICATION_WISECP = 'WISECP'; + const APPLICATION_HOSTBILL = 'HOSTBILL'; + const APPLICATION_BLESTA = 'BLESTA'; + const APPLICATION_ISPBILLMANAGER = 'ISPBILLMANAGER'; + const APPLICATION_CLIENTEXEC = 'CLIENTEXEC'; + const APPLICATION_HOSTFACT = 'HOSTFACT'; + const APPLICATION_CORE = 'CORE'; + const APPLICATION_NONE = 'NONE'; + + const APPLICATIONS=[ + self::APPLICATION_WHMCS, + self::APPLICATION_WISECP, + self::APPLICATION_HOSTBILL, + self::APPLICATION_BLESTA, + self::APPLICATION_ISPBILLMANAGER, + self::APPLICATION_CLIENTEXEC, + self::APPLICATION_HOSTFACT, + self::APPLICATION_CORE, + self::APPLICATION_NONE, + ]; + /** * Error reporting enabled */ @@ -53,6 +78,7 @@ class DomainNameAPI_PHPLibrary * @var string $errorReportingDsn */ private string $errorReportingDsn = 'https://0ea94fed70c09f95c17dfa211d43ac66@sentry.atakdomain.com/2'; + private string $errorReportingPath = ''; /** * Api Username @@ -72,12 +98,13 @@ class DomainNameAPI_PHPLibrary * @var string $serviceUrl */ private string $serviceUrl = "https://whmcs.domainnameapi.com/DomainApi.svc"; + private string $application = "CORE"; public array $lastRequest = []; public array $lastResponse = []; public array $lastParsedResponse = []; public string $lastFunction = ''; private SoapClient $service; - private $startAt; + private $startAt; /** @@ -87,11 +114,11 @@ class DomainNameAPI_PHPLibrary * @param bool $testMode * @throws Exception | SoapFault */ - public function __construct($userName = "ownername", $password = "ownerpass", $testMode = false) + public function __construct($userName = "ownername", $password = "ownerpass", $application='CORE') { $this->startAt = microtime(true); self::setCredentials($userName, $password); - self::useTestMode($testMode); + self::setApplication($application); $context = stream_context_create( [ @@ -108,7 +135,7 @@ public function __construct($userName = "ownername", $password = "ownerpass", $t "encoding" => "UTF-8", 'features' => SOAP_SINGLE_ELEMENT_ARRAYS, 'exceptions' => true, - 'connection_timeout' => 20, + 'connection_timeout' => self::DEFAULT_TIMEOUT, 'stream_context' => $context ]); } catch (SoapFault $e) { @@ -120,6 +147,55 @@ public function __construct($userName = "ownername", $password = "ownerpass", $t } } + private function setApplication($application) + { + $this->application = $application; + + if(!in_array( $this->application,self::APPLICATIONS)){ + $this->application = 'CORE'; + } + switch ( $this->application) { + case self::APPLICATION_WHMCS: + $this->errorReportingDsn = "https://cbaee35fa4d2836942641e10c2109cb6@sentry.atakdomain.com/9"; + $this->errorReportingPath='/modules/registrars/domainnameapi/'; + break; + + case self::APPLICATION_WISECP: + $this->errorReportingDsn = "https://16578e3378f7d6c329ff95d9573bc6fa@sentry.atakdomain.com/8"; + $this->errorReportingPath='/coremio/modules/Registrars/DomainNameAPI/'; + break; + + case self::APPLICATION_HOSTBILL: + $this->errorReportingDsn = "https://be47804b215cb479dbfc44db5c662549@sentry.atakdomain.com/11"; + $this->errorReportingPath='/includes/modules/Domain/domainnameapi/'; + break; + + case self::APPLICATION_BLESTA: + $this->errorReportingDsn = "https://8f8ed6f84abaa93ff49b56f15d3c1f38@sentry.atakdomain.com/10"; + $this->errorReportingPath='/components/modules/domainnameapi/'; + break; + + case self::APPLICATION_CORE: + $this->errorReportingDsn = "https://0ea94fed70c09f95c17dfa211d43ac66@sentry.atakdomain.com/2"; + break; + + case self::APPLICATION_ISPBILLMANAGER: + $this->errorReportingDsn = "https://dace28deb069996acecf619c9e397b15@sentry.atakdomain.com/12"; + break; + + case self::APPLICATION_CLIENTEXEC: + $this->errorReportingDsn = "https://033791219211d863fdb9c08b328ba058@sentry.atakdomain.com/13"; + break; + + case self::APPLICATION_HOSTFACT: + $this->errorReportingDsn = "https://58fe0a01a6704d9f1c2dbbc1a316f233@sentry.atakdomain.com/14"; + break; + case self::APPLICATION_NONE: + $this->errorReportingEnabled = false; + break; + } + + } /** * Deprecated @@ -234,161 +310,7 @@ public function setServiceUrl($url) } - /** - * This method sends anonymous error data to the Sentry server, if error reporting is enabled - * - * @return void - */ - private function sendErrorToSentryAsync(Exception $e) - { - if (!$this->errorReportingEnabled) { - return; - } - - $skipped_errors = self::DEFAULT_IGNORED_ERRORS; - - foreach ($skipped_errors as $ek => $ev) { - if(strpos($e->getMessage(),$ev) !== false){ - return ; - } - } - - $elapsed_time = microtime(true) - $this->startAt; - $parsed_dsn = parse_url($this->errorReportingDsn); - - // API URL'si - $host = $parsed_dsn['host']; - $project_id = ltrim($parsed_dsn['path'], '/'); - $public_key = $parsed_dsn['user']; - $secret_key = $parsed_dsn['pass'] ?? null; - $api_url = "https://$host/api/$project_id/store/"; - - $external_ip = $this->getServerIp(); - - - - // Hata verisi - $errorData = [ - 'event_id' => bin2hex(random_bytes(16)), - 'timestamp' => gmdate('Y-m-d\TH:i:s\Z'), - 'level' => 'error', - 'logger' => 'php', - 'platform' => 'php', - 'culprit' => __FILE__, - 'message' => [ - 'formatted' => $e->getMessage() - ], - 'exception' => [ - 'values' => [ - [ - 'type' => str_replace(['DomainNameApi\DomainNameAPI_PHPLibrary'],['DNALib Exception'],self::class), - 'value' => $e->getMessage(), - 'stacktrace' => [ - 'frames' => [ - [ - 'filename' => $e->getFile(), - 'lineno' => $e->getLine(), - 'function' => str_replace([dirname(__DIR__),'DomainNameApi\DomainNameAPI_PHPLibrary'],['.','Lib'],$e->getTraceAsString()), - ] - ] - ] - ] - ] - ], - 'tags' => [ - 'handled' => 'yes', - 'level' => 'error', - 'release' => self::VERSION, - 'environment' => 'production', - 'url' => $_SERVER['REQUEST_URI'] ?? 'unknown', - 'transaction' => $_SERVER['REQUEST_METHOD'] ?? 'unknown', - 'status_code' => http_response_code(), - 'trace_id' => bin2hex(random_bytes(8)), // Trace ID örneği - 'runtime_name' => 'PHP', - 'runtime_version' => phpversion(), - 'ip_address' => $external_ip, - 'elapsed_time' => number_format($elapsed_time, 4), - - ], - 'extra' => [ - 'request_data' => $this->getRequestData(), - 'response_data' => $this->getResponseData(), - ] - ]; - - // Sentry başlığı - $sentry_auth = [ - 'sentry_version=7', - 'sentry_client=blestalib-php/' . self::VERSION, - "sentry_key=$public_key" - ]; - if ($secret_key) { - $sentry_auth[] = "sentry_secret=$secret_key"; - } - $sentry_auth_header = 'X-Sentry-Auth: Sentry ' . implode(', ', $sentry_auth); - - if(function_exists('escapeshellarg') && function_exists('exec')){ - $cmd = 'curl -X POST ' . escapeshellarg($api_url) . ' -H ' . escapeshellarg('Content-Type: application/json') . ' -H ' . escapeshellarg($sentry_auth_header) . ' -d ' . escapeshellarg(json_encode($errorData)) . ' > /dev/null 2>&1 &'; - exec($cmd); - }else{ - $jsonData = json_encode($errorData); - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $api_url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); - curl_setopt($ch, CURLOPT_TIMEOUT, 2); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2); - curl_setopt($ch, CURLOPT_HTTPHEADER, [ - 'Content-Type: application/json', - $sentry_auth_header - ]); - curl_exec($ch); - curl_close($ch); - } - } - - private function getServerIp() - { - $cache_ttl = 512; // Cache süresi 512 saniye - $cache_key = 'external_ip'; - $cache_file = __DIR__ . '/ip_addr.cache'; - $current_time = time(); - - if (function_exists('apcu_fetch')) { - // APCu ile cache kontrolü - $external_ip = apcu_fetch($cache_key); - if ($external_ip !== false) { - return $external_ip; - } - } elseif (file_exists($cache_file) && ($current_time - filemtime($cache_file) < $cache_ttl)) { - // Dosya ile cache kontrolü - return file_get_contents($cache_file); - } - - // IP adresini alma ve cacheleme - try { - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, "http://ipecho.net/plain"); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_TIMEOUT, 2); - $external_ip = curl_exec($ch); - curl_close($ch); - - if ($external_ip !== false) { - // APCu ile cachele - if (function_exists('apcu_store')) { - apcu_store($cache_key, $external_ip, $cache_ttl); - } - // Dosya ile cachele - file_put_contents($cache_file, $external_ip); - } - return $external_ip; - } catch (Exception $e) { - return 'unknown'; - } - } /** @@ -433,8 +355,7 @@ public function GetResellerDetails() $resp['balances'] = $balances; } else { $resp['result'] = 'ERROR'; - $resp['error'] = $this->setError("INVALID_CREDINENTIALS", "Invalid response received from server!", - "invalid username and password"); + $resp['error'] = $this->setError("INVALID_CREDINENTIALS", "Invalid response received from server!", "invalid username and password"); } @@ -445,7 +366,6 @@ public function GetResellerDetails() return $response; } - /** * Get Current primary Balance for your account */ @@ -524,6 +444,7 @@ public function CheckAvailability($domains, $extensions, $period, $Command) ]; } + foreach ($data["DomainAvailabilityInfoList"]['DomainAvailabilityInfo'] as $name => $value) { $available[] = [ "TLD" => $value["Tld"], @@ -547,7 +468,6 @@ public function CheckAvailability($domains, $extensions, $period, $Command) return $response; } - /** * Hesabınızdaki alan adlarının listesini getirir * @@ -627,7 +547,6 @@ public function GetList($extra_parameters = []) return $response; } - /** * Retrieves TLD list and pricing matrix required for price and TLD synchronization * @@ -718,7 +637,6 @@ public function GetTldList($count = 20) return $result; } - /** * Retrieves detailed information for a specific domain * @@ -1002,7 +920,7 @@ public function DeleteChildNameServer($domainName, $nameServer) } - /** + /** * Modifies IP address of a child nameserver for a domain * * @param string $domainName The domain name that owns the child nameserver @@ -1051,7 +969,7 @@ public function ModifyChildNameServer($domainName, $nameServer, $ipAddress) // CONTACT MANAGEMENT - /** + /** * Retrieves all contact information for a domain (Administrative, Billing, Technical, Registrant) * * @param string $domainName The domain name to get contacts for @@ -1147,7 +1065,7 @@ public function GetContacts($domainName) } - /** + /** * Saves or updates contact information for all contact types of a domain * * @param string $domainName The domain name to update contacts for @@ -1312,7 +1230,7 @@ public function Transfer($domainName, $eppCode, $period) } - /** + /** * Cancels a pending incoming transfer request for a domain * * @param string $domainName The domain name to cancel transfer for @@ -1355,7 +1273,7 @@ public function CancelTransfer($domainName) } - /** + /** * Approves a pending outgoing transfer request for a domain * * @param string $domainName The domain name to approve transfer for @@ -1397,8 +1315,7 @@ public function ApproveTransfer($domainName) return $response; } - - /** + /** * Rejects a pending outgoing transfer request for a domain * * @param string $domainName The domain name to reject transfer for @@ -1441,7 +1358,7 @@ public function RejectTransfer($domainName) } - /** + /** * Renews a domain registration for specified period * * @param string $domainName The domain name to renew @@ -1494,7 +1411,7 @@ public function Renew($domainName, $period) } - /** + /** * Registers a new domain with complete contact information * * @param string $domainName The domain name to register @@ -1644,26 +1561,24 @@ public function ModifyPrivacyProtectionStatus($domainName, $status, $reason = se { $parameters = [ "request" => [ - "DomainName" => $domainName, + "DomainName" => $domainName, "ProtectPrivacy" => $status, "Reason" => trim($reason) ?: self::DEFAULT_REASON ] ]; - return self::parseCall(__FUNCTION__, $parameters, function ($response) use ($parameters) { + return self::parseCall(__FUNCTION__, $parameters, function ($response) use ($parameters) { return [ - 'data' => [ + 'data' => [ 'PrivacyProtectionStatus' => $parameters["request"]["ProtectPrivacy"] ], 'result' => 'OK' ]; }); - - } - /** + /** * Synchronizes domain information with the registry * * @param string $domainName The domain name to synchronize @@ -1711,7 +1626,7 @@ public function SyncFromRegistry($domainName) ]; return self::parseCall(__FUNCTION__, $parameters, function ($response) use ($parameters) { - $data = $response[key($response)]; + $data = $response[key($response)]; // If DomainInfo a valid array if (isset($data["DomainInfo"]) && is_array($data["DomainInfo"])) { @@ -1747,7 +1662,7 @@ private function objectToArray($_obj) } // Get error if exists - private function parseError($response, $trace = true) + private function parseError($response,$trace=true) { $result = false; @@ -1807,6 +1722,7 @@ private function parseError($response, $trace = true) "Code" => '', "Message" => 'Failed', "Details" => '', + ]; if (isset($response[key($response)]["OperationMessage"])) { @@ -1823,7 +1739,7 @@ private function parseError($response, $trace = true) } } - if (isset($result["Code"]) && $trace === true) { + if (isset($result["Code"]) && $trace===true) { $this->sendErrorToSentryAsync(new Exception("API_ERROR: " . $result["Code"] . " - " . $result["Message"] . " - " . $result["Details"])); } @@ -2044,6 +1960,7 @@ private function parseDomainInfo($data) return $result; } + /* Parses contact information from the provided data array. * * @param array $data The data array containing contact information. @@ -2076,50 +1993,49 @@ private function parseDomainInfo($data) */ private function parseContactInfo($data) { - $result = [ - "ID" => isset($data["Id"]) && is_numeric($data["Id"]) ? $data["Id"] : "", - "Status" => $data["Status"] ?? "", - "AuthCode" => $data["Auth"] ?? "", - "FirstName" => $data["FirstName"] ?? "", - "LastName" => $data["LastName"] ?? "", - "Company" => $data["Company"] ?? "", - "EMail" => $data["EMail"] ?? "", - "Type" => $data["Type"] ?? "", - "Address" => [ - "Line1" => $data["AddressLine1"] ?? "", - "Line2" => $data["AddressLine2"] ?? "", - "Line3" => $data["AddressLine3"] ?? "", - "State" => $data["State"] ?? "", - "City" => $data["City"] ?? "", - "Country" => $data["Country"] ?? "", - "ZipCode" => $data["ZipCode"] ?? "", - ], - "Phone" => [ - "Phone" => [ - "Number" => $data["Phone"] ?? "", - "CountryCode" => $data["PhoneCountryCode"] ?? "", + $result = [ + "ID" => isset($data["Id"]) && is_numeric($data["Id"]) ? $data["Id"] : "", + "Status" => $data["Status"] ?? "", + "AuthCode" => $data["Auth"] ?? "", + "FirstName" => $data["FirstName"] ?? "", + "LastName" => $data["LastName"] ?? "", + "Company" => $data["Company"] ?? "", + "EMail" => $data["EMail"] ?? "", + "Type" => $data["Type"] ?? "", + "Address" => [ + "Line1" => $data["AddressLine1"] ?? "", + "Line2" => $data["AddressLine2"] ?? "", + "Line3" => $data["AddressLine3"] ?? "", + "State" => $data["State"] ?? "", + "City" => $data["City"] ?? "", + "Country" => $data["Country"] ?? "", + "ZipCode" => $data["ZipCode"] ?? "", ], - "Fax" => [ - "Number" => $data["Fax"] ?? "", - "CountryCode" => $data["FaxCountryCode"] ?? "", + "Phone" => [ + "Phone" => [ + "Number" => $data["Phone"] ?? "", + "CountryCode" => $data["PhoneCountryCode"] ?? "", + ], + "Fax" => [ + "Number" => $data["Fax"] ?? "", + "CountryCode" => $data["FaxCountryCode"] ?? "", + ], ], - ], - "Additional" => [], - ]; + "Additional" => [], + ]; - // AdditionalAttributes kontrolü - if (isset($data["AdditionalAttributes"]["KeyValueOfstringstring"]) && is_array($data["AdditionalAttributes"]["KeyValueOfstringstring"])) { - foreach ($data["AdditionalAttributes"]["KeyValueOfstringstring"] as $attribute) { - if (isset($attribute["Key"]) && isset($attribute["Value"])) { - $result["Additional"][$attribute["Key"]] = $attribute["Value"]; - } - } - } + // AdditionalAttributes kontrolü + if (isset($data["AdditionalAttributes"]["KeyValueOfstringstring"]) && is_array($data["AdditionalAttributes"]["KeyValueOfstringstring"])) { + foreach ($data["AdditionalAttributes"]["KeyValueOfstringstring"] as $attribute) { + if (isset($attribute["Key"]) && isset($attribute["Value"])) { + $result["Additional"][$attribute["Key"]] = $attribute["Value"]; + } + } + } return $result; } - private function parseCall($fn, $parameters, $_callback) { $result = [ @@ -2151,7 +2067,6 @@ private function parseCall($fn, $parameters, $_callback) $result["result"] = "ERROR"; $result["error"] = $this->parseError($_response); } - } catch (SoapFault $ex) { $result["result"] = "ERROR"; $result["error"] = $this->setError('INVALID_RESPONSE', 'Invalid response occurred', $ex->getMessage()); @@ -2170,6 +2085,7 @@ private function parseCall($fn, $parameters, $_callback) } + /** * Domain is TR type * @param $domain @@ -2184,5 +2100,180 @@ public function isTrTLD($domain) return isset($result[0]); } + /** + * This method sends anonymous error data to the Sentry server, if error reporting is enabled + * + * @return void + */ + private function sendErrorToSentryAsync(Exception $e) + { + if (!$this->errorReportingEnabled) { + return; + } + + $skipped_errors = self::DEFAULT_IGNORED_ERRORS; + + foreach ($skipped_errors as $ek => $ev) { + if(strpos($e->getMessage(),$ev) !== false){ + return ; + } + } + + $elapsed_time = microtime(true) - $this->startAt; + $parsed_dsn = parse_url($this->errorReportingDsn); + + // API URL'si + $host = $parsed_dsn['host']; + $project_id = ltrim($parsed_dsn['path'], '/'); + $public_key = $parsed_dsn['user']; + $secret_key = $parsed_dsn['pass'] ?? null; + $api_url = "https://$host/api/$project_id/store/"; + + $external_ip = $this->getServerIp(); + + + $knownPath = __FILE__; + $errFile=$e->getFile(); + $vhostUser = ''; + + + if (preg_match('/\/home\/([^\/]+)\//', $knownPath, $matches)) { + $vhostUser = $matches[1]; + } + if($vhostUser==''){ + $vhostUser = get_current_user(); + } + + if (strlen($this->errorReportingPath)>0) { + if (strpos($knownPath, $this->errorReportingPath) !== false) { + $knownPath = substr($knownPath, strpos($knownPath, $this->errorReportingPath) + strlen($this->errorReportingPath)); + $errFile = substr($errFile, strpos($errFile, $this->errorReportingPath) + strlen($this->errorReportingPath)); + } + } + + // Hata verisi + $errorData = [ + 'event_id' => bin2hex(random_bytes(16)), + 'timestamp' => gmdate('Y-m-d\TH:i:s\Z'), + 'level' => 'error', + 'logger' => 'php', + 'platform' => 'php', + 'culprit' => $knownPath, + 'message' => [ + 'formatted' => $e->getMessage() + ], + 'exception' => [ + 'values' => [ + [ + 'type' => str_replace(['DomainNameApi\DomainNameAPI_PHPLibrary'],[$this->application.' Exception'],self::class), + 'value' => $e->getMessage(), + 'stacktrace' => [ + 'frames' => [ + [ + 'filename' => $errFile, + 'lineno' => $e->getLine(), + 'function' => str_replace([dirname(__DIR__),'DomainNameApi\DomainNameAPI_PHPLibrary'],['.','Lib'],$e->getTraceAsString()), + ] + ] + ] + ] + ] + ], + 'tags' => [ + 'handled' => 'yes', + 'level' => 'error', + 'release' => self::VERSION, + 'environment' => 'production', + 'url' => $_SERVER['REQUEST_URI'] ?? 'unknown', + 'transaction' => $_SERVER['REQUEST_METHOD'] ?? 'unknown', + 'status_code' => http_response_code(), + 'trace_id' => bin2hex(random_bytes(8)), // Trace ID örneği + 'runtime_name' => 'PHP', + 'runtime_version' => phpversion(), + 'ip_address' => $external_ip, + 'elapsed_time' => number_format($elapsed_time,4), + 'vhost_user' => $vhostUser, + 'application' => $this->application, + + ], + 'extra' => [ + 'request_data' => $this->getRequestData(), + 'response_data' => $this->getResponseData(), + ] + ]; + + // Sentry başlığı + $sentry_auth = [ + 'sentry_version=7', + 'sentry_client=phplib-php/' . self::VERSION, + "sentry_key=$public_key" + ]; + if ($secret_key) { + $sentry_auth[] = "sentry_secret=$secret_key"; + } + $sentry_auth_header = 'X-Sentry-Auth: Sentry ' . implode(', ', $sentry_auth); + + if(function_exists('escapeshellarg') && function_exists('exec')){ + $cmd = 'curl -X POST ' . escapeshellarg($api_url) . ' -H ' . escapeshellarg('Content-Type: application/json') . ' -H ' . escapeshellarg($sentry_auth_header) . ' -d ' . escapeshellarg(json_encode($errorData)) . ' > /dev/null 2>&1 &'; + exec($cmd); + }else{ + $jsonData = json_encode($errorData); + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $api_url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); + curl_setopt($ch, CURLOPT_TIMEOUT, 2); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2); + curl_setopt($ch, CURLOPT_HTTPHEADER, [ + 'Content-Type: application/json', + $sentry_auth_header + ]); + curl_exec($ch); + curl_close($ch); + } + } + + private function getServerIp() + { + $cache_ttl = self::DEFAULT_CACHE_TTL; + $cache_key = 'external_ip'; + $cache_file = __DIR__ . '/ip_addr.cache'; + $current_time = time(); + + if (function_exists('apcu_fetch')) { + // APCu ile cache kontrolü + $external_ip = apcu_fetch($cache_key); + if ($external_ip !== false) { + return $external_ip; + } + } elseif (file_exists($cache_file) && ($current_time - filemtime($cache_file) < $cache_ttl)) { + // Dosya ile cache kontrolü + return file_get_contents($cache_file); + } + + // IP adresini alma ve cacheleme + try { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, "http://ipecho.net/plain"); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_TIMEOUT, 2); + $external_ip = curl_exec($ch); + curl_close($ch); + + if ($external_ip !== false) { + // APCu ile cachele + if (function_exists('apcu_store')) { + apcu_store($cache_key, $external_ip, $cache_ttl); + } + // Dosya ile cachele + file_put_contents($cache_file, $external_ip); + } + + return $external_ip; + } catch (Exception $e) { + return 'unknown'; + } + } } diff --git a/components/modules/domainnameapi/config.json b/components/modules/domainnameapi/config.json index 1da358a..b861558 100644 --- a/components/modules/domainnameapi/config.json +++ b/components/modules/domainnameapi/config.json @@ -1,5 +1,5 @@ { - "version": "1.0.8", + "version": "1.0.9", "type": "registrar", "name": "Domainnameapi", "description": "DomainNameApi is a domain registration module that allows you to register and manage domain names. More Than 800 extension!", diff --git a/components/modules/domainnameapi/domainnameapi.php b/components/modules/domainnameapi/domainnameapi.php index 5ab2273..5539e3a 100644 --- a/components/modules/domainnameapi/domainnameapi.php +++ b/components/modules/domainnameapi/domainnameapi.php @@ -1581,7 +1581,7 @@ private function getApi($username, $key) Loader::load(dirname(__FILE__) . '/' . 'apis' . '/' . 'api.php'); } - return new DomainNameAPI_PHPLibrary($username, $key); + return new DomainNameAPI_PHPLibrary($username, $key,DomainNameAPI_PHPLibrary::APPLICATION_BLESTA); } /**