From 7ace20f5454b0b96187b8c593fe549d2cb7ba56c Mon Sep 17 00:00:00 2001 From: xa81 Date: Sun, 6 Oct 2024 01:19:48 +0300 Subject: [PATCH] version 1.0.4 - Bugfixes , api upgraded --- components/modules/domainnameapi/apis/api.php | 563 +++++------------- .../modules/domainnameapi/composer.json | 22 +- components/modules/domainnameapi/config.json | 2 +- .../modules/domainnameapi/domainnameapi.php | 58 +- .../domainnameapi/views/default/add_row.pdt | 78 +-- .../domainnameapi/views/default/edit_row.pdt | 76 +-- .../domainnameapi/views/default/manage.pdt | 3 +- .../views/default/service_fields.pdt | 1 + .../views/default/service_fields_client.pdt | 37 +- .../views/default/tab_client_nameservers.pdt | 40 +- .../views/default/tab_client_settings.pdt | 8 + .../views/default/tab_client_whois.pdt | 166 +++--- .../views/default/tab_nameservers.pdt | 35 +- .../views/default/tab_settings.pdt | 6 + 14 files changed, 454 insertions(+), 641 deletions(-) diff --git a/components/modules/domainnameapi/apis/api.php b/components/modules/domainnameapi/apis/api.php index 8dd8e9e..e86347c 100644 --- a/components/modules/domainnameapi/apis/api.php +++ b/components/modules/domainnameapi/apis/api.php @@ -20,49 +20,52 @@ namespace DomainNameApi; +use Exception; +use SoapClient; +use SoapFault; + class DomainNameAPI_PHPLibrary { /** * Version of the library */ - const VERSION = '2.0.20'; + const VERSION = '2.0.22'; /** * Error reporting enabled */ - private $errorReportingEnabled = true; + private bool $errorReportingEnabled = true; /** * Error Reporting Will send this sentry endpoint, if errorReportingEnabled is true * This request does not include sensitive informations, sensitive informations are filtered. * @var string $errorReportingDsn */ - private $errorReportingDsn = 'https://d4e2d61e4af2d4c68fb21ab93bf51ff2@o4507492369039360.ingest.de.sentry.io/4507492373954640'; + private string $errorReportingDsn = 'https://d4e2d61e4af2d4c68fb21ab93bf51ff2@o4507492369039360.ingest.de.sentry.io/4507492373954640'; /** * Api Username * * @var string $serviceUsername */ - private $serviceUsername = "ownername"; + private string $serviceUsername = "ownername"; /* * Api Password * @var string $servicePassword */ - private $servicePassword = "ownerpass"; + private string $servicePassword = "ownerpass"; /** * Api Service Soap URL * @var string $serviceUrl */ - private $serviceUrl = "https://whmcs.domainnameapi.com/DomainApi.svc"; - public $lastRequest = []; - public $lastResponse = []; - public $lastParsedResponse = []; - public $lastFunction = ''; - private $service; + private string $serviceUrl = "https://whmcs.domainnameapi.com/DomainApi.svc"; + public array $lastRequest = []; + public array $lastResponse = []; + public array $lastParsedResponse = []; + public string $lastFunction = ''; + private SoapClient $service; private $startAt; - private $errorTriggered = []; /** @@ -70,7 +73,7 @@ class DomainNameAPI_PHPLibrary * @param string $userName * @param string $password * @param bool $testMode - * @throws \Exception | \SoapFault + * @throws Exception | SoapFault */ public function __construct($userName = "ownername", $password = "ownerpass", $testMode = false) { @@ -80,18 +83,18 @@ public function __construct($userName = "ownername", $password = "ownerpass", $t try { // Create unique connection - $this->service = new \SoapClient($this->serviceUrl . "?singlewsdl", [ + $this->service = new SoapClient($this->serviceUrl . "?singlewsdl", [ "encoding" => "UTF-8", 'features' => SOAP_SINGLE_ELEMENT_ARRAYS, 'exceptions' => true, 'connection_timeout' => 20, ]); - } catch (\SoapFault $e) { + } catch (SoapFault $e) { $this->sendErrorToSentryAsync($e); - throw new \Exception("SOAP Connection Error: " . $e->getMessage()); - } catch (\Exception $e) { + throw new Exception("SOAP Connection Error: " . $e->getMessage()); + } catch (Exception $e) { $this->sendErrorToSentryAsync($e); - throw new \Exception("SOAP Error: " . $e->getMessage()); + throw new Exception("SOAP Error: " . $e->getMessage()); } } @@ -133,11 +136,12 @@ public function getRequestData() /** * This method sets the last request sent to the API - * @return array|mixed + * @return DomainNameAPI_PHPLibrary */ public function setRequestData($request) { $this->lastRequest = $request; + return $this; } /** @@ -156,6 +160,7 @@ public function getResponseData() public function setResponseData($response) { $this->lastResponse = $response; + return $this; } /** @@ -174,6 +179,7 @@ public function getParsedResponseData() public function setParsedResponseData($response) { $this->lastParsedResponse = $response; + return $this; } /** @@ -187,11 +193,12 @@ public function getLastFunction() /** * This method sets the last function called - * @return string + * @return DomainNameAPI_PHPLibrary */ public function setLastFunction($function) { $this->lastFunction = $function; + return $this; } public function getServiceUrl() @@ -210,7 +217,7 @@ public function setServiceUrl($url) * * @return void */ - private function sendErrorToSentryAsync(\Exception $e) + private function sendErrorToSentryAsync(Exception $e) { if (!$this->errorReportingEnabled) { return; @@ -360,7 +367,7 @@ private function getServerIp() } return $external_ip; - } catch (\Exception $e) { + } catch (Exception $e) { return 'unknown'; } } @@ -392,7 +399,7 @@ public function GetResellerDetails() $active_currency = $data['ResellerInfo']['BalanceInfoList']['BalanceInfo'][0]; $balances = []; - foreach ($data['ResellerInfo']['BalanceInfoList']['BalanceInfo'] as $k => $v) { + foreach ($data['ResellerInfo']['BalanceInfoList']['BalanceInfo'] as $v) { if ($v['CurrencyName'] == $data['ResellerInfo']['CurrencyInfo']['Code']) { $active_currency = $v; } @@ -559,7 +566,7 @@ public function GetList($extra_parameters = []) $result["error"] = $this->setError("INVALID_DOMAIN_LIST", "Invalid response received from server!", "Domain info is not a valid array or more than one domain info has returned!"); - $this->sendErrorToSentryAsync(new \Exception("INVALID_DOMAIN_LIST: Invalid response received from server! Domain info is not a valid array or more than one domain info has returned!")); + $this->sendErrorToSentryAsync(new Exception("INVALID_DOMAIN_LIST: Invalid response received from server! Domain info is not a valid array or more than one domain info has returned!")); } return $result; }); @@ -628,7 +635,7 @@ public function GetTldList($count = 20) 'error' => $this->setError("INVALID_TLD_LIST", "Invalid response received from server!", "Domain info is not a valid array or more than one domain info has returned!") ]; - $this->sendErrorToSentryAsync(new \Exception("INVALID_TLD_LIST: Invalid response received from server! Domain info is not a valid array or more than one domain info has returned!")); + $this->sendErrorToSentryAsync(new Exception("INVALID_TLD_LIST: Invalid response received from server! Domain info is not a valid array or more than one domain info has returned!")); } return $result; @@ -669,7 +676,7 @@ public function GetDetails($domainName) $result["error"] = $this->setError("INVALID_DOMAIN_LIST", "Invalid response received from server!", "Domain info is not a valid array or more than one domain info has returned!"); - $this->sendErrorToSentryAsync(new \Exception("INVALID_DOMAIN_LIST: Invalid response received from server! Domain info is not a valid array or more than one domain info has returned!")); + $this->sendErrorToSentryAsync(new Exception("INVALID_DOMAIN_LIST: Invalid response received from server! Domain info is not a valid array or more than one domain info has returned!")); } return $result; }); @@ -914,7 +921,7 @@ public function GetContacts($domainName) "Contact info is not a valid array or more than one contact info has returned!"), 'result' => 'ERROR' ]; - $this->sendErrorToSentryAsync(new \Exception("INVALID_CONTACT_INTO: Invalid response received from server! Contact info is not a valid array or more than one contact info has returned!")); + $this->sendErrorToSentryAsync(new Exception("INVALID_CONTACT_INTO: Invalid response received from server! Contact info is not a valid array or more than one contact info has returned!")); } return $result; }); @@ -962,7 +969,7 @@ public function SaveContacts($domainName, $contacts) "Contact info is not a valid array or more than one contact info has returned!") ]; - $this->sendErrorToSentryAsync(new \Exception("INVALID_CONTACT_SAVE: Invalid response received from server! Contact info is not a valid array or more than one contact info has returned!")); + $this->sendErrorToSentryAsync(new Exception("INVALID_CONTACT_SAVE: Invalid response received from server! Contact info is not a valid array or more than one contact info has returned!")); } return $result; }); @@ -1019,7 +1026,7 @@ public function Transfer($domainName, $eppCode, $period) "Invalid response received from server!", "Domain info is not a valid array or more than one domain info has returned!") ]; - $this->sendErrorToSentryAsync(new \Exception("INVALID_DOMAIN_TRANSFER_REQUEST: Invalid response received from server! Domain info is not a valid array or more than one domain info has returned!")); + $this->sendErrorToSentryAsync(new Exception("INVALID_DOMAIN_TRANSFER_REQUEST: Invalid response received from server! Domain info is not a valid array or more than one domain info has returned!")); } return $result; }); @@ -1154,7 +1161,7 @@ public function Renew($domainName, $period) 'error' => $this->setError("INVALID_DOMAIN_RENEW", "Invalid response received from server!", "Domain info is not a valid array or more than one domain info has returned!") ]; - $this->sendErrorToSentryAsync(new \Exception("INVALID_DOMAIN_RENEW: Invalid response received from server! Domain info is not a valid array or more than one domain info has returned!")); + $this->sendErrorToSentryAsync(new Exception("INVALID_DOMAIN_RENEW: Invalid response received from server! Domain info is not a valid array or more than one domain info has returned!")); } }); @@ -1228,7 +1235,7 @@ public function RegisterWithContactInfo( 'error' => $this->setError("INVALID_DOMAIN_REGISTER", "Invalid response received from server!", "Domain info is not a valid array or more than one domain info has returned!") ]; - $this->sendErrorToSentryAsync(new \Exception("INVALID_DOMAIN_REGISTER: Invalid response received from server! Domain info is not a valid array or more than one domain info has returned!")); + $this->sendErrorToSentryAsync(new Exception("INVALID_DOMAIN_REGISTER: Invalid response received from server! Domain info is not a valid array or more than one domain info has returned!")); } return $result; }); @@ -1261,7 +1268,7 @@ public function ModifyPrivacyProtectionStatus($domainName, $status, $Reason = "O ] ]; - $response = self::parseCall(__FUNCTION__, $parameters, function ($response) use ($parameters) { + return self::parseCall(__FUNCTION__, $parameters, function ($response) use ($parameters) { return [ 'data' => [ 'PrivacyProtectionStatus' => $parameters["request"]["ProtectPrivacy"] @@ -1271,7 +1278,6 @@ public function ModifyPrivacyProtectionStatus($domainName, $status, $Reason = "O }); - return $response; } @@ -1290,8 +1296,7 @@ public function SyncFromRegistry($domainName) ] ]; - $response = self::parseCall(__FUNCTION__, $parameters, function ($response) use ($parameters) { - $result = []; + return self::parseCall(__FUNCTION__, $parameters, function ($response) use ($parameters) { $data = $response[key($response)]; // If DomainInfo a valid array @@ -1308,13 +1313,12 @@ public function SyncFromRegistry($domainName) "Domain info is not a valid array or more than one domain info has returned!"), 'result' => 'ERROR' ]; - $this->sendErrorToSentryAsync(new \Exception("INVALID_DOMAIN_SYNC: Invalid response received from server! Domain info is not a valid array or more than one domain info has returned!")); + $this->sendErrorToSentryAsync(new Exception("INVALID_DOMAIN_SYNC: Invalid response received from server! Domain info is not a valid array or more than one domain info has returned!")); } return $result; }); - return $response; } @@ -1323,7 +1327,7 @@ private function objectToArray($_obj) { try { $_obj = json_decode(json_encode($_obj), true); - } catch (\Exception $ex) { + } catch (Exception $ex) { } return $_obj; } @@ -1406,7 +1410,7 @@ private function parseError($response, $trace = true) } if (isset($result["Code"]) && $trace === true) { - $this->sendErrorToSentryAsync(new \Exception("API_ERROR: " . $result["Code"] . " - " . $result["Message"] . " - " . $result["Details"])); + $this->sendErrorToSentryAsync(new Exception("API_ERROR: " . $result["Code"] . " - " . $result["Message"] . " - " . $result["Details"])); } return $result; @@ -1415,7 +1419,7 @@ private function parseError($response, $trace = true) // Check if response contains error private function hasError($response) { - return ($this->parseError($response, false) === false) ? false : true; + return !(($this->parseError($response, false) === false)); } // Set error message @@ -1431,395 +1435,146 @@ private function setError($Code, $Message, $Details) // Parse domain info private function parseDomainInfo($data) { - $result = []; - $result["ID"] = ""; - $result["Status"] = ""; - $result["DomainName"] = ""; - $result["AuthCode"] = ""; - $result["LockStatus"] = ""; - $result["PrivacyProtectionStatus"] = ""; - $result["IsChildNameServer"] = ""; - $result["Contacts"] = []; - $result["Contacts"]["Billing"] = []; - $result["Contacts"]["Technical"] = []; - $result["Contacts"]["Administrative"] = []; - $result["Contacts"]["Registrant"] = []; - $result["Contacts"]["Billing"]["ID"] = ""; - $result["Contacts"]["Technical"]["ID"] = ""; - $result["Contacts"]["Administrative"]["ID"] = ""; - $result["Contacts"]["Registrant"]["ID"] = ""; - $result["Dates"] = []; - $result["Dates"]["Start"] = ""; - $result["Dates"]["Expiration"] = ""; - $result["Dates"]["RemainingDays"] = ""; - $result["NameServers"] = []; - $result["Additional"] = []; - $result["ChildNameServers"] = []; - - foreach ($data as $attrName => $attrValue) { - switch ($attrName) { - case "Id": - if (is_numeric($attrValue)) { - $result["ID"] = $attrValue; - } - break; - - - case "Status": - - $result["Status"] = $attrValue; - break; - - - case "DomainName": - - $result["DomainName"] = $attrValue; - break; - - - case "AdministrativeContactId": - - if (is_numeric($attrValue)) { - $result["Contacts"]["Administrative"]["ID"] = $attrValue; - } - break; - - - case "BillingContactId": - - if (is_numeric($attrValue)) { - $result["Contacts"]["Billing"]["ID"] = $attrValue; - } - break; - - - case "TechnicalContactId": - - if (is_numeric($attrValue)) { - $result["Contacts"]["Technical"]["ID"] = $attrValue; - } - break; - - - case "RegistrantContactId": - - if (is_numeric($attrValue)) { - $result["Contacts"]["Registrant"]["ID"] = $attrValue; - } - break; - - - case "Auth": - - if (is_string($attrValue) && !is_null($attrValue)) { - $result["AuthCode"] = $attrValue; - } - break; - - - case "StartDate": - - $result["Dates"]["Start"] = $attrValue; - break; - - - case "ExpirationDate": - - $result["Dates"]["Expiration"] = $attrValue; - break; - - - case "LockStatus": - - if (is_bool($attrValue)) { - $result["LockStatus"] = var_export($attrValue, true); - } - break; - - - case "PrivacyProtectionStatus": - - if (is_bool($attrValue)) { - $result["PrivacyProtectionStatus"] = var_export($attrValue, true); - } - break; - - - case "IsChildNameServer": - - if (is_bool($attrValue)) { - $result["IsChildNameServer"] = var_export($attrValue, true); - } - break; - - - case "RemainingDay": - - if (is_numeric($attrValue)) { - $result["Dates"]["RemainingDays"] = $attrValue; - } - break; - - - case "NameServerList": - - if (is_array($attrValue)) { - foreach ($attrValue as $nameserverValue) { - $result["NameServers"] = $nameserverValue; - } - } - break; - - - case "AdditionalAttributes": - - if (is_array($attrValue)) { - if (isset($attrValue["KeyValueOfstringstring"])) { - foreach ($attrValue["KeyValueOfstringstring"] as $attribute) { + $result = [ + "ID" => isset($data["Id"]) && is_numeric($data["Id"]) ? $data["Id"] : "", + "Status" => $data["Status"] ?? "", + "DomainName" => $data["DomainName"] ?? "", + "AuthCode" => $data["Auth"] ?? "", + "LockStatus" => isset($data["LockStatus"]) ? var_export($data["LockStatus"], true) : "", + "PrivacyProtectionStatus" => isset($data["PrivacyProtectionStatus"]) ? var_export($data["PrivacyProtectionStatus"], true) : "", + "IsChildNameServer" => isset($data["IsChildNameServer"]) ? var_export($data["IsChildNameServer"], true) : "", + "Contacts" => [ + "Billing" => [ + "ID" => isset($data["BillingContactId"]) && is_numeric($data["BillingContactId"]) ? $data["BillingContactId"] : "", + ], + "Technical" => [ + "ID" => isset($data["TechnicalContactId"]) && is_numeric($data["TechnicalContactId"]) ? $data["TechnicalContactId"] : "", + ], + "Administrative" => [ + "ID" => isset($data["AdministrativeContactId"]) && is_numeric($data["AdministrativeContactId"]) ? $data["AdministrativeContactId"] : "", + ], + "Registrant" => [ + "ID" => isset($data["RegistrantContactId"]) && is_numeric($data["RegistrantContactId"]) ? $data["RegistrantContactId"] : "", + ], + ], + "Dates" => [ + "Start" => $data["StartDate"] ?? "", + "Expiration" => $data["ExpirationDate"] ?? "", + "RemainingDays" => isset($data["RemainingDay"]) && is_numeric($data["RemainingDay"]) ? $data["RemainingDay"] : "", + ], + "NameServers" => $data["NameServerList"] ?? [], + "Additional" => [], + "ChildNameServers" => [], + ]; + + // 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"]; } } } - } - break; - - case "ChildNameServerInfo": - if (is_array($attrValue)) { - if (isset($attrValue["ChildNameServerInfo"]) && is_array($attrValue["ChildNameServerInfo"]) && count($attrValue["ChildNameServerInfo"]) > 0) { - foreach ($attrValue["ChildNameServerInfo"] as $attribute) { + // ChildNameServerInfo kontrolü + if (isset($data["ChildNameServerInfo"]) && is_array($data["ChildNameServerInfo"])) { + foreach ($data["ChildNameServerInfo"] as $attribute) { if (isset($attribute["ChildNameServer"]) && isset($attribute["IpAddress"])) { - $ns = ""; + $ns = is_string($attribute["ChildNameServer"]) ? $attribute["ChildNameServer"] : ""; $IpAddresses = []; - // Name of NameServer - if (is_string($attribute["ChildNameServer"])) { - $ns = $attribute["ChildNameServer"]; - } - - // IP adresses of NameServer - if (is_array($attribute["IpAddress"]) && isset($attribute["IpAddress"]["string"])) { + if (is_array($attribute["IpAddress"])) { + if (isset($attribute["IpAddress"]["string"])) { if (is_array($attribute["IpAddress"]["string"])) { - foreach ($attribute["IpAddress"]["string"] as $ip) { - if (isset($ip) && is_string($ip)) { - $IpAddresses = $ip; - } - } + $IpAddresses = array_filter($attribute["IpAddress"]["string"], 'is_string'); } elseif (is_string($attribute["IpAddress"]["string"])) { - $IpAddresses = $attribute["IpAddress"]["string"]; + $IpAddresses = [$attribute["IpAddress"]["string"]]; + } } } $result["ChildNameServers"][] = [ "ns" => $ns, - "ip" => $IpAddresses + "ip" => $IpAddresses, ]; } } } - } - break; - } - } return $result; } - // Parse Contact info + /* Parses contact information from the provided data array. + * + * @param array $data The data array containing contact information. + * + * @return array An associative array with the parsed contact information, including: + * - string ID + * - string Status + * - string AuthCode + * - string FirstName + * - string LastName + * - string Company + * - string EMail + * - string Type + * - array Address + * - string Line1 + * - string Line2 + * - string Line3 + * - string State + * - string City + * - string Country + * - string ZipCode + * - array Phone + * - array Phone + * - string Number + * - string CountryCode + * - array Fax + * - string Number + * - string CountryCode + * - array Additional + */ private function parseContactInfo($data) { - $result = []; - $result["ID"] = ""; - $result["Status"] = ""; - $result["Additional"] = []; - $result["Address"] = []; - $result["Address"]["Line1"] = ""; - $result["Address"]["Line2"] = ""; - $result["Address"]["Line3"] = ""; - $result["Address"]["State"] = ""; - $result["Address"]["City"] = ""; - $result["Address"]["Country"] = ""; - $result["Address"]["ZipCode"] = ""; - $result["Phone"] = []; - $result["Phone"]["Phone"] = []; - $result["Phone"]["Phone"]["Number"] = ""; - $result["Phone"]["Phone"]["CountryCode"] = ""; - $result["Phone"]["Fax"]["Number"] = ""; - $result["Phone"]["Fax"]["CountryCode"] = ""; - $result["AuthCode"] = ""; - $result["FirstName"] = ""; - $result["LastName"] = ""; - $result["Company"] = ""; - $result["EMail"] = ""; - $result["Type"] = ""; - - foreach ($data as $attrName => $attrValue) { - switch ($attrName) { - case "Id": - - if (is_numeric($attrValue)) { - $result["ID"] = $attrValue; - } - break; - - - case "Status": - - $result["Status"] = $attrValue; - break; - - - case "AdditionalAttributes": + $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"] ?? "", + ], + "Fax" => [ + "Number" => $data["Fax"] ?? "", + "CountryCode" => $data["FaxCountryCode"] ?? "", + ], + ], + "Additional" => [], + ]; - if (is_array($attrValue)) { - if (isset($attrValue["KeyValueOfstringstring"])) { - foreach ($attrValue["KeyValueOfstringstring"] as $attribute) { + // 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"]; } } } - } - break; - - - case "AddressLine1": - - if (is_string($attrValue) && !is_null($attrValue)) { - $result["Address"]["Line1"] = $attrValue; - } - break; - - - case "AddressLine2": - - if (is_string($attrValue) && !is_null($attrValue)) { - $result["Address"]["Line2"] = $attrValue; - } - break; - - - case "AddressLine3": - - if (is_string($attrValue) && !is_null($attrValue)) { - $result["Address"]["Line3"] = $attrValue; - } - break; - - - case "Auth": - - if (is_string($attrValue) && !is_null($attrValue)) { - $result["AuthCode"] = $attrValue; - } - break; - - - case "City": - - if (is_string($attrValue) && !is_null($attrValue)) { - $result["Address"]["City"] = $attrValue; - } - break; - - - case "Company": - - if (is_string($attrValue) && !is_null($attrValue)) { - $result["Company"] = $attrValue; - } - break; - - - case "Country": - - if (is_string($attrValue) && !is_null($attrValue)) { - $result["Address"]["Country"] = $attrValue; - } - break; - - - case "EMail": - - if (is_string($attrValue) && !is_null($attrValue)) { - $result["EMail"] = $attrValue; - } - break; - - - case "Fax": - - if (is_string($attrValue) && !is_null($attrValue)) { - $result["Phone"]["Fax"]["Number"] = $attrValue; - } - break; - - - case "FaxCountryCode": - - if (is_string($attrValue) && !is_null($attrValue)) { - $result["Phone"]["Fax"]["CountryCode"] = $attrValue; - } - break; - - - case "Phone": - - if (is_string($attrValue) && !is_null($attrValue)) { - $result["Phone"]["Phone"]["Number"] = $attrValue; - } - break; - - - case "PhoneCountryCode": - - if (is_string($attrValue) && !is_null($attrValue)) { - $result["Phone"]["Phone"]["CountryCode"] = $attrValue; - } - break; - - - case "FirstName": - - if (is_string($attrValue) && !is_null($attrValue)) { - $result["FirstName"] = $attrValue; - } - break; - - - case "LastName": - - if (is_string($attrValue) && !is_null($attrValue)) { - $result["LastName"] = $attrValue; - } - break; - - - case "State": - - if (is_string($attrValue) && !is_null($attrValue)) { - $result["Address"]["State"] = $attrValue; - } - break; - - - case "ZipCode": - - if (is_string($attrValue) && !is_null($attrValue)) { - $result["Address"]["ZipCode"] = $attrValue; - } - break; - - - case "Type": - - if (is_string($attrValue) && !is_null($attrValue)) { - $result["Type"] = $attrValue; - } - break; - } - } return $result; } @@ -1834,9 +1589,9 @@ private function parseCall($fn, $parameters, $_callback) try { // SOAP method which is same as current function name called - $_response_raw = $_response = $this->service->__soapCall($fn, [$parameters]); + $_response = $this->service->__soapCall($fn, [$parameters]); - $_response_raw = $this->service->__getLastResponse(); + $this->service->__getLastResponse(); // Serialize as array @@ -1855,11 +1610,12 @@ private function parseCall($fn, $parameters, $_callback) $result["result"] = "ERROR"; $result["error"] = $this->parseError($_response); } - } catch (\SoapFault $ex) { + + } catch (SoapFault $ex) { $result["result"] = "ERROR"; $result["error"] = $this->setError('INVALID_RESPONSE', 'Invalid Response occured', $ex->getMessage()); $this->sendErrorToSentryAsync($ex); - } catch (\Exception $ex) { + } catch (Exception $ex) { $result["result"] = "ERROR"; $result["error"] = $this->parseError($this->objectToArray($ex)); $this->sendErrorToSentryAsync($ex); @@ -1879,8 +1635,9 @@ private function parseCall($fn, $parameters, $_callback) */ public function isTrTLD($domain) { - preg_match('/\.com\.tr|\.net\.tr|\.org\.tr|\.biz\.tr|\.info\.tr|\.tv\.tr|\.gen\.tr|\.web\.tr|\.tel\.tr|\.name\.tr|\.bbs\.tr|\.gov\.tr|\.bel\.tr|\.pol\.tr|\.edu\.tr|\.k12\.tr|\.av\.tr|\.dr\.tr$/', - $domain, $result); + //preg_match('/\.com\.tr|\.net\.tr|\.org\.tr|\.biz\.tr|\.info\.tr|\.tv\.tr|\.gen\.tr|\.web\.tr|\.tel\.tr|\.name\.tr|\.bbs\.tr|\.gov\.tr|\.bel\.tr|\.pol\.tr|\.edu\.tr|\.k12\.tr|\.av\.tr|\.dr\.tr$/', $domain, $result); + + preg_match('/\.tr$/', $domain, $result); return isset($result[0]); } diff --git a/components/modules/domainnameapi/composer.json b/components/modules/domainnameapi/composer.json index 5863f92..939eb32 100644 --- a/components/modules/domainnameapi/composer.json +++ b/components/modules/domainnameapi/composer.json @@ -1,13 +1,13 @@ { - "name": "blesta/domainnameapi", - "description": "DomainNameApi", - "license": "proprietary", - "type": "blesta-module", - "require": { - "blesta/composer-installer": "~1.0", - "ext-dom": "*", - "ext-simplexml": "*", - "ext-curl": "*", - "ext-soap": "*" - } + "name": "blesta/domainnameapi", + "description": "DomainNameApi", + "license": "proprietary", + "type": "blesta-module", + "require": { + "blesta/composer-installer": "~1.0", + "ext-dom": "*", + "ext-simplexml": "*", + "ext-curl": "*", + "ext-soap": "*" + } } diff --git a/components/modules/domainnameapi/config.json b/components/modules/domainnameapi/config.json index b4ef4bb..79b6b7a 100644 --- a/components/modules/domainnameapi/config.json +++ b/components/modules/domainnameapi/config.json @@ -1,5 +1,5 @@ { - "version": "1.0.3", + "version": "1.0.4", "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 6ba66f1..e4b9629 100644 --- a/components/modules/domainnameapi/domainnameapi.php +++ b/components/modules/domainnameapi/domainnameapi.php @@ -568,7 +568,7 @@ public function getAdminAddFields($package, $vars = null) // Set default name servers if (!isset($vars->ns1) && isset($package->meta->ns)) { - $i = 0; + $i = 1; foreach ($package->meta->ns as $ns) { $vars->{'ns' . ($i++)} = $ns; } @@ -618,7 +618,10 @@ public function getClientAddFields($package, $vars = null) if (!isset($vars->ns) && isset($package->meta->ns)) { $i = 0; foreach ($package->meta->ns as $ns) { - $vars->{'ns' . $i++ } = $ns; + if(strlen($ns) > 0) { + $i++; + $vars->{'ns' . ($i)} = $ns; + } } } @@ -998,7 +1001,6 @@ private function manageNameservers($view, $package, $service, array $get = null, if (!empty($post)) { - die(var_dump($post)); // Update domain nameservers $this->setDomainNameservers($fields->domain, $package->module_row, ($post['ns'] ?? [])); $vars = (object)$post; @@ -1026,9 +1028,9 @@ private function manageNameservers($view, $package, $service, array $get = null, * @param string $view The view to use * @param stdClass $package A stdClass object representing the current package * @param stdClass $service A stdClass object representing the current service - * @param array $get Any GET parameters - * @param array $post Any POST parameters - * @param array $files Any FILES parameters + * @param array|null $get Any GET parameters + * @param array|null $post Any POST parameters + * @param array|null $files Any FILES parameters * @return string The string representing the contents of this tab */ private function manageSettings($view, $package, $service, array $get = null, array $post = null, array $files = null) { @@ -1045,6 +1047,7 @@ private function manageSettings($view, $package, $service, array $get = null, ar // Determine if this service has access to id_protection $id_protection = $this->featureServiceEnabled('id_protection', $service); + // Determine if this service has access to epp_code $epp_code = $package->meta->epp_code ?? '0'; @@ -1054,20 +1057,35 @@ private function manageSettings($view, $package, $service, array $get = null, ar if (!empty($post)) { // Set domain status - if ($post['registrar_lock'] == 'true') { - $this->lockDomain($fields->domain, $package->module_row); - } else { - $this->unlockDomain($fields->domain, $package->module_row); + if ($post['registrar_lock'] == 'true' && $post['current_id_protection'] == 'false') { + $lockStatus = $this->lockDomain($fields->domain, $package->module_row); + if ($lockStatus === true) { + $vars->registrar_lock = 'true'; + } + + $this->view->set('lockStatus', $lockStatus); + } + + if ($post['registrar_lock'] == 'false' && $post['current_id_protection'] == 'true') { + $unlockStatus = $this->unlockDomain($fields->domain, $package->module_row); + if ($unlockStatus === true) { + $vars->registrar_lock = 'false'; + } } - if($id_protection){ - if($post['whois_privacy_state'] == 'true'){ - $this->enablePrivacyProtection($fields->domain, $package->module_row); - }else{ - $this->disablePrivacyProtection($fields->domain, $package->module_row); + if ($post['whois_privacy_state'] == 'true' && $post['current_privacy_state'] == 'false' && $id_protection === true) { + $privacyStatus = $this->enablePrivacyProtection($fields->domain, $package->module_row); + if ($privacyStatus === true) { + $vars->whois_privacy_state = 'true'; } } + if ($post['whois_privacy_state'] == 'false' && $post['current_privacy_state'] == 'true' && $id_protection === true) { + $privacyStatus = $this->disablePrivacyProtection($fields->domain, $package->module_row); + if ($privacyStatus === true) { + $vars->whois_privacy_state = 'false'; + } + } } @@ -1300,7 +1318,7 @@ public function lockDomain($domain, $module_row_id = null) $response = $api->EnableTheftProtectionLock($domain); $this->processResponse($api); - return $response['status'] == 'OK'; + return $response['result'] == 'OK'; } /** @@ -1319,7 +1337,7 @@ public function unlockDomain($domain, $module_row_id = null) $response = $api->DisableTheftProtectionLock($domain); $this->processResponse($api); - return $response['status'] == 'OK'; + return $response['result'] == 'OK'; } public function enablePrivacyProtection($domain, $module_row_id = null) @@ -1330,7 +1348,7 @@ public function enablePrivacyProtection($domain, $module_row_id = null) $response = $api->ModifyPrivacyProtectionStatus($domain,true); $this->processResponse($api); - return $response['status'] == 'OK'; + return $response['result'] == 'OK'; } public function disablePrivacyProtection($domain, $module_row_id = null) { @@ -1340,7 +1358,7 @@ public function disablePrivacyProtection($domain, $module_row_id = null) $response = $api->ModifyPrivacyProtectionStatus($domain,false); $this->processResponse($api); - return $response['status'] == 'OK'; + return $response['result'] == 'OK'; } @@ -1382,7 +1400,7 @@ public function registerDomain($domain, $module_row_id = null, array $vars = []) $this->processResponse($api); - return $registerResult['status'] == 'OK'; + return $registerResult['result'] == 'OK'; } /** diff --git a/components/modules/domainnameapi/views/default/add_row.pdt b/components/modules/domainnameapi/views/default/add_row.pdt index b67835f..a33877e 100644 --- a/components/modules/domainnameapi/views/default/add_row.pdt +++ b/components/modules/domainnameapi/views/default/add_row.pdt @@ -1,41 +1,43 @@ - Widget->clear(); - $this->Widget->create($this->_('Domainnameapi.add_row.box_title', true)); - ?> -
- Form->create(); - ?> -
-

_('Domainnameapi.add_row.basic_title');?>

-
-
-
    -
  • - Form->label($this->_('Domainnameapi.row_meta.user', true), 'user'); - $this->Form->fieldText('user', ($vars->user ?? null), ['id' => 'user']); - ?> -
  • -
  • - Form->label($this->_('Domainnameapi.row_meta.key', true), 'key'); - $this->Form->fieldText('key', ($vars->key ?? null), ['id' => 'key' , 'type'=>'password']); - ?> -
  • - -
-
- -
+Widget->clear(); +$this->Widget->create($this->_('Domainnameapi.add_row.box_title', true)); +?> +
+ Form->create(); + ?> +
+

_('Domainnameapi.add_row.basic_title'); ?>

+
+
+
    +
  • Form->fieldSubmit('save', $this->_('Domainnameapi.add_row.add_btn', true), ['class' => 'btn btn-primary float-right']); + $this->Form->label($this->_('Domainnameapi.row_meta.user', true), 'user'); + $this->Form->fieldText('user', ($vars->user ?? null), ['id' => 'user']); ?> -
- Form->end(); - ?> -
+ +
  • + Form->label($this->_('Domainnameapi.row_meta.key', true), 'key'); + $this->Form->fieldText('key', ($vars->key ?? null), ['id' => 'key', 'type' => 'password']); + ?> +
  • + + +
    + +
    Widget->end(); - ?> \ No newline at end of file + $this->Form->fieldSubmit('save', $this->_('Domainnameapi.add_row.add_btn', true), + ['class' => 'btn btn-primary float-right']); + ?> +
    + Form->end(); + ?> +
    +Widget->end(); +?> \ No newline at end of file diff --git a/components/modules/domainnameapi/views/default/edit_row.pdt b/components/modules/domainnameapi/views/default/edit_row.pdt index 42b5f4e..ca4aa4b 100644 --- a/components/modules/domainnameapi/views/default/edit_row.pdt +++ b/components/modules/domainnameapi/views/default/edit_row.pdt @@ -1,40 +1,42 @@ - Widget->clear(); - $this->Widget->create($this->_('Domainnameapi.edit_row.box_title', true)); - ?> -
    - Form->create(); - ?> -
    -

    _('Domainnameapi.edit_row.basic_title');?>

    -
    -
    -
      -
    • - Form->label($this->_('Domainnameapi.row_meta.user', true), 'user'); - $this->Form->fieldText('user', ($vars->user ?? null), ['id' => 'user']); - ?> -
    • -
    • - Form->label($this->_('Domainnameapi.row_meta.key', true), 'key'); - $this->Form->fieldText('key', ($vars->key ?? null), ['id' => 'key', 'type'=>'password']); - ?> -
    • -
    -
    - -
    +Widget->clear(); +$this->Widget->create($this->_('Domainnameapi.edit_row.box_title', true)); +?> +
    + Form->create(); + ?> +
    +

    _('Domainnameapi.edit_row.basic_title'); ?>

    +
    +
    +
      +
    • Form->fieldSubmit('save', $this->_('Domainnameapi.edit_row.add_btn', true), ['class' => 'btn btn-primary float-right']); + $this->Form->label($this->_('Domainnameapi.row_meta.user', true), 'user'); + $this->Form->fieldText('user', ($vars->user ?? null), ['id' => 'user']); ?> -
    - Form->end(); - ?> -
    + +
  • + Form->label($this->_('Domainnameapi.row_meta.key', true), 'key'); + $this->Form->fieldText('key', ($vars->key ?? null), ['id' => 'key', 'type' => 'password']); + ?> +
  • + +
    + +
    Widget->end(); - ?> \ No newline at end of file + $this->Form->fieldSubmit('save', $this->_('Domainnameapi.edit_row.add_btn', true), + ['class' => 'btn btn-primary float-right']); + ?> +
    + Form->end(); + ?> +
    +Widget->end(); +?> \ No newline at end of file diff --git a/components/modules/domainnameapi/views/default/manage.pdt b/components/modules/domainnameapi/views/default/manage.pdt index e526aa1..0221a04 100644 --- a/components/modules/domainnameapi/views/default/manage.pdt +++ b/components/modules/domainnameapi/views/default/manage.pdt @@ -1,7 +1,8 @@ [ - 'name' => $this->_('Domainnameapi.add_module_row', true), + 'name' => $this->_('Domainnameapi.add_module_row', true), 'attributes' => ['href' => $this->base_uri . 'settings/company/modules/addrow/' . $module->id] ] ]; diff --git a/components/modules/domainnameapi/views/default/service_fields.pdt b/components/modules/domainnameapi/views/default/service_fields.pdt index d6ea679..a1adcf8 100644 --- a/components/modules/domainnameapi/views/default/service_fields.pdt +++ b/components/modules/domainnameapi/views/default/service_fields.pdt @@ -1,4 +1,5 @@