From f9f79ca1809ff62237785c228da5e60c6b21e511 Mon Sep 17 00:00:00 2001 From: D Date: Thu, 1 Jul 2021 18:07:23 +0700 Subject: [PATCH 1/6] added module, module configuration, logic to update premium dns for domain or create domains with premium dns parameter --- .../Controllers/System/DomainController.php | 43 +++++++ .../OpenProvider/API/DomainRegistration.php | 10 +- .../openprovider/enums/DatabaseTable.php | 2 + modules/servers/openprovider/api.php | 29 +++++ modules/servers/openprovider/hooks.php | 39 ++++++ modules/servers/openprovider/openprovider.php | 111 ++++++++++++++++++ 6 files changed, 232 insertions(+), 2 deletions(-) create mode 100644 modules/servers/openprovider/api.php create mode 100644 modules/servers/openprovider/hooks.php create mode 100644 modules/servers/openprovider/openprovider.php diff --git a/modules/registrars/openprovider/Controllers/System/DomainController.php b/modules/registrars/openprovider/Controllers/System/DomainController.php index 96b1975c..a0cf4aee 100644 --- a/modules/registrars/openprovider/Controllers/System/DomainController.php +++ b/modules/registrars/openprovider/Controllers/System/DomainController.php @@ -10,6 +10,7 @@ use OpenProvider\API\APITools; use OpenProvider\API\DomainTransfer; use OpenProvider\API\DomainRegistration; +use OpenProvider\WhmcsRegistrar\enums\DatabaseTable; use OpenProvider\WhmcsRegistrar\src\PremiumDomain; use OpenProvider\WhmcsRegistrar\src\Handle; use OpenProvider\WhmcsRegistrar\src\AdditionalFields; @@ -17,6 +18,7 @@ use Symfony\Component\Serializer\Serializer; use WeDevelopCoffee\wPower\Controllers\BaseController; use WeDevelopCoffee\wPower\Core\Core; +use WHMCS\Database\Capsule; /** * Class DomainController @@ -113,6 +115,8 @@ public function register($params) $domain->extension = $params['tld']; $domain->name = $params['sld']; + $params = $this->setPremiumDNSInParamsIfProductChoosen($params); + // Prepare the nameservers $nameServers = APITools::createNameserversArray($params); @@ -206,6 +210,10 @@ public function register($params) unset($domainRegistration->additionalData->idnScript); } + if (isset($params['premiumDNS']) && $params['premiumDNS']) { + $domainRegistration->premiumDNS = $params['premiumDNS']; + } + // Sleep for 2 seconds. Some registrars accept a new contact but do not process this immediately. sleep(2); @@ -316,4 +324,39 @@ public function transfer($params) } return $values; } + + /** + * @param array $params + * @return array $params but if premium dns enabled, params with premium name servers + */ + private function setPremiumDNSInParamsIfProductChoosen(array $params) + { + if (!isset($params['domainid'])) { + return $params; + } + + try { + $orderRow = Capsule::table(DatabaseTable::Domains) + ->where('id', $params['domainid']) + ->select('orderid', 'domain') + ->first(); + + if (!$orderRow) { + return $params; + } + + $hostingRow = Capsule::table(DatabaseTable::Hosting) + ->where('orderid', $orderRow->orderid) + ->where('domain', $orderRow->domain) + ->first(); + + if (!$hostingRow) { + return $params; + } + + $params['premiumDNS'] = true; + } catch (\Exception $e) {} + + return $params; + } } diff --git a/modules/registrars/openprovider/OpenProvider/API/DomainRegistration.php b/modules/registrars/openprovider/OpenProvider/API/DomainRegistration.php index 8f7e3686..407e21ab 100644 --- a/modules/registrars/openprovider/OpenProvider/API/DomainRegistration.php +++ b/modules/registrars/openprovider/OpenProvider/API/DomainRegistration.php @@ -46,8 +46,10 @@ class DomainRegistration extends \OpenProvider\API\AutoloadConstructor * @var string */ public $billingHandle = null; - - + + /** + * @var array + */ public $nameServers = null; /** @@ -93,4 +95,8 @@ class DomainRegistration extends \OpenProvider\API\AutoloadConstructor */ public $isDnssecEnabled; + /** + * @var boolean + */ + public $premiumDNS; } diff --git a/modules/registrars/openprovider/enums/DatabaseTable.php b/modules/registrars/openprovider/enums/DatabaseTable.php index 2449dec5..117fc40f 100644 --- a/modules/registrars/openprovider/enums/DatabaseTable.php +++ b/modules/registrars/openprovider/enums/DatabaseTable.php @@ -29,4 +29,6 @@ class DatabaseTable const Currencies = 'tblcurrencies'; const Configuration = 'tblconfiguration'; + + const Hosting = 'tblhosting'; } diff --git a/modules/servers/openprovider/api.php b/modules/servers/openprovider/api.php new file mode 100644 index 00000000..642e0010 --- /dev/null +++ b/modules/servers/openprovider/api.php @@ -0,0 +1,29 @@ +getConfiguration()->setHost(OPENPROVIDER_HOST); + + $tokenRequest = $api->call('generateAuthTokenRequest', [ + 'username' => $username, + 'password' => $password + ]); + + if ($tokenRequest->getCode() != 0) { + return null; + } + + $token = $tokenRequest->getData()['token']; + + $api->getConfiguration()->setToken($token); + + return $api; +} diff --git a/modules/servers/openprovider/hooks.php b/modules/servers/openprovider/hooks.php new file mode 100644 index 00000000..c10c8384 --- /dev/null +++ b/modules/servers/openprovider/hooks.php @@ -0,0 +1,39 @@ +where('id', $productId) + ->first(); + + $username = $productRow->configoption1; + $password = $productRow->configoption2; + + $api = getApi($username, $password); + + if (is_null($api)) { + return 'Something was wrong! Check your credentials and try again'; + } + + $domainFullName = $vars['sld'] . $vars['tld']; + + $domainRequest = $api->call('searchDomainRequest', [ + 'fullName' => $domainFullName + ]); + + if ($domainRequest->getCode() != 0 || count($domainRequest->getData()['results']) == 0) { + return 'This domain not found in Openprovider or something went wrong!'; + } +}); diff --git a/modules/servers/openprovider/openprovider.php b/modules/servers/openprovider/openprovider.php new file mode 100644 index 00000000..edd7cefb --- /dev/null +++ b/modules/servers/openprovider/openprovider.php @@ -0,0 +1,111 @@ + 'Openprovider-premiumDNS', + 'APIVersion' => '1.1', // Use API Version 1.1 + 'RequiresServer' => true, // Set true if module requires a server to work + 'DefaultNonSSLPort' => '1111', // Default Non-SSL Connection Port + 'DefaultSSLPort' => '1112', // Default SSL Connection Port + 'ServiceSingleSignOnLabel' => 'Login to Panel as User', + 'AdminSingleSignOnLabel' => 'Login to Panel as Admin', + ); +} + +function openprovider_ConfigOptions() +{ + return [ + // a text field type allows for single line text input + 'Login' => [ + 'Type' => 'text', + 'Description' => 'Enter Openprovider login', + 'SimpleMode' => true, + ], + // a password field type allows for masked text input + 'Password' => [ + 'Type' => 'password', + 'Description' => 'Enter Openprovider password', + 'SimpleMode' => true, + ], + ]; +} + +/** + * Provision a new instance of a product/service. + * + * Attempt to provision a new instance of a given product/service. This is + * called any time provisioning is requested inside of WHMCS. Depending upon the + * configuration, this can be any of: + * * When a new order is placed + * * When an invoice for a new order is paid + * * Upon manual request by an admin user + * + * @param array $params common module parameters + * + * @see https://developers.whmcs.com/provisioning-modules/module-parameters/ + * + * @return string "success" or an error message + */ +function openprovider_CreateAccount(array $params) +{ + try { + $username = $params['configoption1']; + $password = $params['configoption2']; + + $api = getApi($username, $password); + + if (is_null($api)) { + return 'provisioning module cannot configure api. Maybe your credentials are incorrect.'; + } + + $domainRequest = $api->call('searchDomainRequest', [ + 'fullName' => $params['domain'] + ]); + + if ($domainRequest->getCode() != 0 || count($domainRequest->getData()['results']) == 0) { + return 'This domain not found in Openprovider or something went wrong!'; + } + + $domain = $domainRequest->getData()['results'][0]; + + $modifyDomainRequest = $api->call('modifyDomainRequest', [ + 'id' => $domain['id'], + 'premiumDNS' => true, + ]); + + if ($modifyDomainRequest->getCode() != 0) { + return $modifyDomainRequest->getMessage(); + } + + } catch (Exception $e) { + // Record the error in WHMCS's module log. + logModuleCall( + 'provisioningmodule', + __FUNCTION__, + $params, + $e->getMessage(), + $e->getTraceAsString() + ); + + return $e->getMessage(); + } + + return 'success'; +} From bb22a2fc64e0628171f1586b44aed0a97da2ef62 Mon Sep 17 00:00:00 2001 From: Danila Date: Mon, 9 Aug 2021 16:56:48 +0700 Subject: [PATCH 2/6] updated premium dns name from premiumDNS to isSectigoDnsEnabled --- .../openprovider/Controllers/System/DomainController.php | 2 +- .../openprovider/OpenProvider/API/DomainRegistration.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/registrars/openprovider/Controllers/System/DomainController.php b/modules/registrars/openprovider/Controllers/System/DomainController.php index a0cf4aee..17817e3f 100644 --- a/modules/registrars/openprovider/Controllers/System/DomainController.php +++ b/modules/registrars/openprovider/Controllers/System/DomainController.php @@ -211,7 +211,7 @@ public function register($params) } if (isset($params['premiumDNS']) && $params['premiumDNS']) { - $domainRegistration->premiumDNS = $params['premiumDNS']; + $domainRegistration->isSectigoDnsEnabled = $params['premiumDNS']; } // Sleep for 2 seconds. Some registrars accept a new contact but do not process this immediately. diff --git a/modules/registrars/openprovider/OpenProvider/API/DomainRegistration.php b/modules/registrars/openprovider/OpenProvider/API/DomainRegistration.php index 407e21ab..1e264abb 100644 --- a/modules/registrars/openprovider/OpenProvider/API/DomainRegistration.php +++ b/modules/registrars/openprovider/OpenProvider/API/DomainRegistration.php @@ -98,5 +98,5 @@ class DomainRegistration extends \OpenProvider\API\AutoloadConstructor /** * @var boolean */ - public $premiumDNS; + public $isSectigoDnsEnabled; } From a243f50e0242b1568e3603589a2c0c0f9d63ac9b Mon Sep 17 00:00:00 2001 From: Danila Date: Mon, 16 Aug 2021 15:03:20 +0700 Subject: [PATCH 3/6] updated param from premiumDNS to isSectigoDnsEnabled --- modules/servers/openprovider/openprovider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/servers/openprovider/openprovider.php b/modules/servers/openprovider/openprovider.php index edd7cefb..b8c2d695 100644 --- a/modules/servers/openprovider/openprovider.php +++ b/modules/servers/openprovider/openprovider.php @@ -87,7 +87,7 @@ function openprovider_CreateAccount(array $params) $modifyDomainRequest = $api->call('modifyDomainRequest', [ 'id' => $domain['id'], - 'premiumDNS' => true, + 'isSectigoDnsEnabled' => true, ]); if ($modifyDomainRequest->getCode() != 0) { From 78dbd7667e27330c7c3fbd3913f7503be628b8dc Mon Sep 17 00:00:00 2001 From: Danila Date: Mon, 30 Aug 2021 14:43:40 +0700 Subject: [PATCH 4/6] updated provisioning module for sectigo dns --- .../Controllers/System/DomainController.php | 41 ----------- .../OpenProvider/API/DomainRegistration.php | 5 -- .../api.php | 3 +- .../openprovidersectigodns/functions.php | 24 +++++++ .../hooks.php | 0 .../openprovidersectigodns.php} | 69 ++++++++++--------- 6 files changed, 61 insertions(+), 81 deletions(-) rename modules/servers/{openprovider => openprovidersectigodns}/api.php (91%) create mode 100644 modules/servers/openprovidersectigodns/functions.php rename modules/servers/{openprovider => openprovidersectigodns}/hooks.php (100%) rename modules/servers/{openprovider/openprovider.php => openprovidersectigodns/openprovidersectigodns.php} (58%) diff --git a/modules/registrars/openprovider/Controllers/System/DomainController.php b/modules/registrars/openprovider/Controllers/System/DomainController.php index 17817e3f..806a70e1 100644 --- a/modules/registrars/openprovider/Controllers/System/DomainController.php +++ b/modules/registrars/openprovider/Controllers/System/DomainController.php @@ -115,8 +115,6 @@ public function register($params) $domain->extension = $params['tld']; $domain->name = $params['sld']; - $params = $this->setPremiumDNSInParamsIfProductChoosen($params); - // Prepare the nameservers $nameServers = APITools::createNameserversArray($params); @@ -210,10 +208,6 @@ public function register($params) unset($domainRegistration->additionalData->idnScript); } - if (isset($params['premiumDNS']) && $params['premiumDNS']) { - $domainRegistration->isSectigoDnsEnabled = $params['premiumDNS']; - } - // Sleep for 2 seconds. Some registrars accept a new contact but do not process this immediately. sleep(2); @@ -324,39 +318,4 @@ public function transfer($params) } return $values; } - - /** - * @param array $params - * @return array $params but if premium dns enabled, params with premium name servers - */ - private function setPremiumDNSInParamsIfProductChoosen(array $params) - { - if (!isset($params['domainid'])) { - return $params; - } - - try { - $orderRow = Capsule::table(DatabaseTable::Domains) - ->where('id', $params['domainid']) - ->select('orderid', 'domain') - ->first(); - - if (!$orderRow) { - return $params; - } - - $hostingRow = Capsule::table(DatabaseTable::Hosting) - ->where('orderid', $orderRow->orderid) - ->where('domain', $orderRow->domain) - ->first(); - - if (!$hostingRow) { - return $params; - } - - $params['premiumDNS'] = true; - } catch (\Exception $e) {} - - return $params; - } } diff --git a/modules/registrars/openprovider/OpenProvider/API/DomainRegistration.php b/modules/registrars/openprovider/OpenProvider/API/DomainRegistration.php index 1e264abb..b63fe7cf 100644 --- a/modules/registrars/openprovider/OpenProvider/API/DomainRegistration.php +++ b/modules/registrars/openprovider/OpenProvider/API/DomainRegistration.php @@ -94,9 +94,4 @@ class DomainRegistration extends \OpenProvider\API\AutoloadConstructor * @var boolean */ public $isDnssecEnabled; - - /** - * @var boolean - */ - public $isSectigoDnsEnabled; } diff --git a/modules/servers/openprovider/api.php b/modules/servers/openprovidersectigodns/api.php similarity index 91% rename from modules/servers/openprovider/api.php rename to modules/servers/openprovidersectigodns/api.php index 642e0010..73a2391f 100644 --- a/modules/servers/openprovider/api.php +++ b/modules/servers/openprovidersectigodns/api.php @@ -4,12 +4,11 @@ use OpenProvider\Logger; use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter; -const OPENPROVIDER_HOST = 'https://api.cte.openprovider.eu'; +const OPENPROVIDER_HOST = 'https://api.openprovider.eu'; function getApi($username, $password): ?ApiV1 { $api = new ApiV1(new Logger(), new CamelCaseToSnakeCaseNameConverter, new idna_convert); - $api->getConfiguration()->setHost(OPENPROVIDER_HOST); $tokenRequest = $api->call('generateAuthTokenRequest', [ diff --git a/modules/servers/openprovidersectigodns/functions.php b/modules/servers/openprovidersectigodns/functions.php new file mode 100644 index 00000000..3f1c196c --- /dev/null +++ b/modules/servers/openprovidersectigodns/functions.php @@ -0,0 +1,24 @@ + ['domain', 'com'] + * + * @param string $domain + * @return array domain array ['domain name', 'domain extension'] + */ +function getDomainArrayFromDomain(string $domain): array +{ + $domainArray = explode('.', $domain); + if (count($domainArray) < 2) { + throw new \Exception('Domain name has no tld.'); + } + + $domainSld = explode('.', $domain)[0]; + $domainTld = substr(str_replace($domainSld, '', $domain), 1); + + return [ + $domainSld, + $domainTld + ]; +} diff --git a/modules/servers/openprovider/hooks.php b/modules/servers/openprovidersectigodns/hooks.php similarity index 100% rename from modules/servers/openprovider/hooks.php rename to modules/servers/openprovidersectigodns/hooks.php diff --git a/modules/servers/openprovider/openprovider.php b/modules/servers/openprovidersectigodns/openprovidersectigodns.php similarity index 58% rename from modules/servers/openprovider/openprovider.php rename to modules/servers/openprovidersectigodns/openprovidersectigodns.php index b8c2d695..e40cd16d 100644 --- a/modules/servers/openprovider/openprovider.php +++ b/modules/servers/openprovidersectigodns/openprovidersectigodns.php @@ -5,6 +5,7 @@ } include_once 'api.php'; +include_once 'functions.php'; /** * Define module related meta data. @@ -16,7 +17,7 @@ * * @return array */ -function openprovider_MetaData() +function openprovidersectigodns_MetaData() { return array( 'DisplayName' => 'Openprovider-premiumDNS', @@ -29,7 +30,7 @@ function openprovider_MetaData() ); } -function openprovider_ConfigOptions() +function openprovidersectigodns_ConfigOptions() { return [ // a text field type allows for single line text input @@ -63,48 +64,50 @@ function openprovider_ConfigOptions() * * @return string "success" or an error message */ -function openprovider_CreateAccount(array $params) +function openprovidersectigodns_CreateAccount(array $params) { - try { - $username = $params['configoption1']; - $password = $params['configoption2']; + $username = $params['configoption1']; + $password = $params['configoption2']; - $api = getApi($username, $password); + $api = getApi($username, $password); - if (is_null($api)) { - return 'provisioning module cannot configure api. Maybe your credentials are incorrect.'; - } + if (is_null($api)) { + return 'provisioning module cannot configure api. Maybe your credentials are incorrect.'; + } - $domainRequest = $api->call('searchDomainRequest', [ - 'fullName' => $params['domain'] + // get dns zone if exist + $dnsZoneResponse = $api->call('retrieveZoneDnsRequest', [ + 'name' => $params['domain'], + ]); + + // if zone doesn't exist + if ($dnsZoneResponse->getCode() == 0) { + $modifyZoneResponse = $api->call('modifyZoneDnsRequest', [ + 'name' => $params['domain'], + 'premiumDNS' => true, ]); - if ($domainRequest->getCode() != 0 || count($domainRequest->getData()['results']) == 0) { - return 'This domain not found in Openprovider or something went wrong!'; + if ($modifyZoneResponse->getCode() != 0) { + return $modifyZoneResponse->getMessage(); } - $domain = $domainRequest->getData()['results'][0]; - - $modifyDomainRequest = $api->call('modifyDomainRequest', [ - 'id' => $domain['id'], - 'isSectigoDnsEnabled' => true, - ]); + return 'success'; + } - if ($modifyDomainRequest->getCode() != 0) { - return $modifyDomainRequest->getMessage(); - } + list($domainName, $domainExtension) = getDomainArrayFromDomain($params['domain']); - } catch (Exception $e) { - // Record the error in WHMCS's module log. - logModuleCall( - 'provisioningmodule', - __FUNCTION__, - $params, - $e->getMessage(), - $e->getTraceAsString() - ); + $createDnsZoneResponse = $api->call('createZoneDnsRequest', [ + 'domain' => [ + 'name' => $domainName, + 'extension' => $domainExtension, + ], + 'records' => [], + 'type' => 'master', + 'premiumDNS' => true, + ]); - return $e->getMessage(); + if ($createDnsZoneResponse->getCode() != 0) { + return $createDnsZoneResponse->getMessage(); } return 'success'; From b78e951a69e394513fb8a1dc84ea3346b486ce98 Mon Sep 17 00:00:00 2001 From: Danila Date: Mon, 30 Aug 2021 16:52:05 +0700 Subject: [PATCH 5/6] added handling exception --- .../openprovidersectigodns/openprovidersectigodns.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/servers/openprovidersectigodns/openprovidersectigodns.php b/modules/servers/openprovidersectigodns/openprovidersectigodns.php index e40cd16d..5f01b4e6 100644 --- a/modules/servers/openprovidersectigodns/openprovidersectigodns.php +++ b/modules/servers/openprovidersectigodns/openprovidersectigodns.php @@ -80,7 +80,7 @@ function openprovidersectigodns_CreateAccount(array $params) 'name' => $params['domain'], ]); - // if zone doesn't exist + // if zone exists if ($dnsZoneResponse->getCode() == 0) { $modifyZoneResponse = $api->call('modifyZoneDnsRequest', [ 'name' => $params['domain'], @@ -94,7 +94,12 @@ function openprovidersectigodns_CreateAccount(array $params) return 'success'; } - list($domainName, $domainExtension) = getDomainArrayFromDomain($params['domain']); + // if zone does not exist + try { + list($domainName, $domainExtension) = getDomainArrayFromDomain($params['domain']); + } catch (Exception $e) { + return $e->getMessage(); + } $createDnsZoneResponse = $api->call('createZoneDnsRequest', [ 'domain' => [ From 90514df8ea0d8794cde62a4d1277a29a123dcbac Mon Sep 17 00:00:00 2001 From: Danila Date: Mon, 30 Aug 2021 17:06:19 +0700 Subject: [PATCH 6/6] refactoring provisioning module --- .../openprovidersectigodns/functions.php | 4 +- .../servers/openprovidersectigodns/hooks.php | 9 +-- .../openprovidersectigodns.php | 58 +++++++++++-------- 3 files changed, 39 insertions(+), 32 deletions(-) diff --git a/modules/servers/openprovidersectigodns/functions.php b/modules/servers/openprovidersectigodns/functions.php index 3f1c196c..70f70166 100644 --- a/modules/servers/openprovidersectigodns/functions.php +++ b/modules/servers/openprovidersectigodns/functions.php @@ -18,7 +18,7 @@ function getDomainArrayFromDomain(string $domain): array $domainTld = substr(str_replace($domainSld, '', $domain), 1); return [ - $domainSld, - $domainTld + 'name' => $domainSld, + 'extension' => $domainTld ]; } diff --git a/modules/servers/openprovidersectigodns/hooks.php b/modules/servers/openprovidersectigodns/hooks.php index c10c8384..bb7743c3 100644 --- a/modules/servers/openprovidersectigodns/hooks.php +++ b/modules/servers/openprovidersectigodns/hooks.php @@ -18,19 +18,14 @@ ->where('id', $productId) ->first(); - $username = $productRow->configoption1; - $password = $productRow->configoption2; - - $api = getApi($username, $password); + $api = getApi($productRow->configoption1, $productRow->configoption2); if (is_null($api)) { return 'Something was wrong! Check your credentials and try again'; } - $domainFullName = $vars['sld'] . $vars['tld']; - $domainRequest = $api->call('searchDomainRequest', [ - 'fullName' => $domainFullName + 'fullName' => sprintf('%s.%s', $vars['sld'], $vars['tld']) ]); if ($domainRequest->getCode() != 0 || count($domainRequest->getData()['results']) == 0) { diff --git a/modules/servers/openprovidersectigodns/openprovidersectigodns.php b/modules/servers/openprovidersectigodns/openprovidersectigodns.php index 5f01b4e6..c15d3338 100644 --- a/modules/servers/openprovidersectigodns/openprovidersectigodns.php +++ b/modules/servers/openprovidersectigodns/openprovidersectigodns.php @@ -7,6 +7,24 @@ include_once 'api.php'; include_once 'functions.php'; +const CREATE_DNS_ZONE_TYPE = 'master'; + +const SUCCESS_MESSAGE = 'success'; + +const MODULE_NAME = 'Openprovider-premiumDNS'; +const API_VERSION = '1.1'; // Use API Version 1.1 +const REQUIRES_SERVER = true; // Set true if module requires a server to work +const DEFAULT_NON_SSL_PORT = '1111'; // Default Non-SSL Connection Port +const DEFAULT_SSL_PORT = '1112'; // Default SSL Connection Port +const SERVICE_SINGLE_SIGN_ON_LABEL = 'Login to Panel as User'; +const ADMIN_SINGLE_SIGN_ON_LABEL = 'Login to Panel as Admin'; + +const CONFIG_OPTION_LOGIN_NAME = 'Login'; +const CONFIG_OPTION_LOGIN_DESCRIPTION = 'Enter Openprovider login'; + +const CONFIG_OPTION_PASSWORD_NAME = 'Password'; +const CONFIG_OPTION_PASSWORD_DESCRIPTION = 'Enter Openprovider password'; + /** * Define module related meta data. * @@ -20,13 +38,13 @@ function openprovidersectigodns_MetaData() { return array( - 'DisplayName' => 'Openprovider-premiumDNS', - 'APIVersion' => '1.1', // Use API Version 1.1 - 'RequiresServer' => true, // Set true if module requires a server to work - 'DefaultNonSSLPort' => '1111', // Default Non-SSL Connection Port - 'DefaultSSLPort' => '1112', // Default SSL Connection Port - 'ServiceSingleSignOnLabel' => 'Login to Panel as User', - 'AdminSingleSignOnLabel' => 'Login to Panel as Admin', + 'DisplayName' => MODULE_NAME, + 'APIVersion' => API_VERSION, + 'RequiresServer' => REQUIRES_SERVER, + 'DefaultNonSSLPort' => DEFAULT_NON_SSL_PORT, + 'DefaultSSLPort' => DEFAULT_SSL_PORT, + 'ServiceSingleSignOnLabel' => SERVICE_SINGLE_SIGN_ON_LABEL, + 'AdminSingleSignOnLabel' => ADMIN_SINGLE_SIGN_ON_LABEL, ); } @@ -34,15 +52,15 @@ function openprovidersectigodns_ConfigOptions() { return [ // a text field type allows for single line text input - 'Login' => [ + CONFIG_OPTION_LOGIN_NAME => [ 'Type' => 'text', - 'Description' => 'Enter Openprovider login', + 'Description' => CONFIG_OPTION_LOGIN_DESCRIPTION, 'SimpleMode' => true, ], // a password field type allows for masked text input - 'Password' => [ + CONFIG_OPTION_PASSWORD_NAME => [ 'Type' => 'password', - 'Description' => 'Enter Openprovider password', + 'Description' => CONFIG_OPTION_PASSWORD_DESCRIPTION, 'SimpleMode' => true, ], ]; @@ -66,10 +84,7 @@ function openprovidersectigodns_ConfigOptions() */ function openprovidersectigodns_CreateAccount(array $params) { - $username = $params['configoption1']; - $password = $params['configoption2']; - - $api = getApi($username, $password); + $api = getApi($params['configoption1'], $params['configoption2']); if (is_null($api)) { return 'provisioning module cannot configure api. Maybe your credentials are incorrect.'; @@ -91,23 +106,20 @@ function openprovidersectigodns_CreateAccount(array $params) return $modifyZoneResponse->getMessage(); } - return 'success'; + return SUCCESS_MESSAGE; } // if zone does not exist try { - list($domainName, $domainExtension) = getDomainArrayFromDomain($params['domain']); + $domainArray = getDomainArrayFromDomain($params['domain']); } catch (Exception $e) { return $e->getMessage(); } $createDnsZoneResponse = $api->call('createZoneDnsRequest', [ - 'domain' => [ - 'name' => $domainName, - 'extension' => $domainExtension, - ], + 'domain' => $domainArray, 'records' => [], - 'type' => 'master', + 'type' => CREATE_DNS_ZONE_TYPE, 'premiumDNS' => true, ]); @@ -115,5 +127,5 @@ function openprovidersectigodns_CreateAccount(array $params) return $createDnsZoneResponse->getMessage(); } - return 'success'; + return SUCCESS_MESSAGE; }