From 0d2b9aac4ece65ba89656fb03fb78d1de5d1301c Mon Sep 17 00:00:00 2001 From: "pieterjan.eilers" Date: Fri, 30 Aug 2024 13:59:10 +0200 Subject: [PATCH 1/6] all tools added --- modules/registrars/realtimeregister/hooks.php | 21 ++- .../src/Assets/Css/actions.css | 7 + .../src/Assets/Css/autorenew.css | 45 +++++++ .../src/Assets/Css/general.css | 53 ++++++++ .../src/Assets/Css/importdomains.css | 42 +++++- .../src/Assets/Js/importDomains.js | 30 ----- .../realtimeregister/src/Assets/Js/util.js | 25 ++++ .../src/Assets/Tpl/actions.tpl | 53 ++++++++ .../src/Assets/Tpl/autoRenew.tpl | 83 ++++++++++++ .../src/Assets/Tpl/content.tpl | 10 ++ .../src/Assets/Tpl/importDomains.tpl | 39 ++++-- .../src/Assets/Tpl/importDomainsStepThree.tpl | 41 +++--- .../src/Assets/Tpl/importDomainsStepTwo.tpl | 37 ++--- .../src/Assets/Tpl/syncDomains.tpl | 105 +++++++++++++++ .../realtimeregister/src/ConfigArray.php | 5 - .../src/Hooks/AutoRenewStatus.php | 63 +++++++++ .../src/Hooks/ImportDomains.php | 126 +++--------------- .../realtimeregister/src/Hooks/SyncExpiry.php | 53 ++++++++ .../src/Hooks/Widgets/ToolsWidget.php | 13 ++ .../realtimeregister/src/Services/Assets.php | 5 +- .../src/Services/TemplateService.php | 4 +- .../src/Widget/ToolsWidget.php | 26 ++++ 22 files changed, 672 insertions(+), 214 deletions(-) create mode 100644 modules/registrars/realtimeregister/src/Assets/Css/actions.css create mode 100644 modules/registrars/realtimeregister/src/Assets/Css/autorenew.css create mode 100644 modules/registrars/realtimeregister/src/Assets/Css/general.css delete mode 100644 modules/registrars/realtimeregister/src/Assets/Js/importDomains.js create mode 100644 modules/registrars/realtimeregister/src/Assets/Js/util.js create mode 100644 modules/registrars/realtimeregister/src/Assets/Tpl/actions.tpl create mode 100644 modules/registrars/realtimeregister/src/Assets/Tpl/autoRenew.tpl create mode 100644 modules/registrars/realtimeregister/src/Assets/Tpl/content.tpl create mode 100644 modules/registrars/realtimeregister/src/Assets/Tpl/syncDomains.tpl create mode 100644 modules/registrars/realtimeregister/src/Hooks/AutoRenewStatus.php create mode 100644 modules/registrars/realtimeregister/src/Hooks/SyncExpiry.php create mode 100644 modules/registrars/realtimeregister/src/Hooks/Widgets/ToolsWidget.php create mode 100644 modules/registrars/realtimeregister/src/Widget/ToolsWidget.php diff --git a/modules/registrars/realtimeregister/hooks.php b/modules/registrars/realtimeregister/hooks.php index 84026c7..84e1ddb 100644 --- a/modules/registrars/realtimeregister/hooks.php +++ b/modules/registrars/realtimeregister/hooks.php @@ -7,19 +7,30 @@ App::boot(); +// Utils +add_hook("AdminHomepage", 1, function() { + App::assets()->addScript("util.js"); + App::assets()->addStyle("general.css"); + App::assets()->addStyle("actions.css"); +}); + App::hook(Hooks\PreRegistrarGetContactDetails::class); -App::hook(Hooks\AdminAreaPage::class, 10); -App::hook("AdminAreaHeadOutput", Hooks\CheckCredentials::class, 1); +App::hook(Hooks\AdminAreaPage::class, null, 10); +App::hook("AdminAreaHeadOutput", Hooks\CheckCredentials::class); +App::hook("AdminHomepage", Hooks\SyncExpiry::class, 2); +App::hook("AdminHomepage", Hooks\ImportDomains::class, 2); +App::hook("AdminHomepage", Hooks\AutoRenewStatus::class ,2); + App::hook(Hooks\AdminAreaHeadOutput::class, null, 100); App::hook(Hooks\AdminAreaFooterOutput::class, null, 100); App::hook(Hooks\ClientAreaPage::class); App::hook(Hooks\ContactEdit::class); -App::hook("AdminAreaHeadOutput", Hooks\ImportDomains::class); -App::hook('AdminHomeWidgets', Hooks\Widgets\BalanceWidget::class); -App::hook('AdminHomeWidgets', Hooks\Widgets\DomainOverviewWidget::class); + +App::hook('AdminHomeWidgets', Hooks\Widgets\ToolsWidget::class); +//App::hook('AdminHomeWidgets', Hooks\Widgets\DomainOverviewWidget::class); App::hook('ClientAreaHeadOutput', Hooks\HeadAssets::class, 100); App::hook('ClientAreaFooterOutput', Hooks\FooterAssets::class, 100); diff --git a/modules/registrars/realtimeregister/src/Assets/Css/actions.css b/modules/registrars/realtimeregister/src/Assets/Css/actions.css new file mode 100644 index 0000000..c0bb3d9 --- /dev/null +++ b/modules/registrars/realtimeregister/src/Assets/Css/actions.css @@ -0,0 +1,7 @@ + + +.action-group { + display: flex; + flex-direction: column; + gap: 1rem; +} \ No newline at end of file diff --git a/modules/registrars/realtimeregister/src/Assets/Css/autorenew.css b/modules/registrars/realtimeregister/src/Assets/Css/autorenew.css new file mode 100644 index 0000000..74e30a2 --- /dev/null +++ b/modules/registrars/realtimeregister/src/Assets/Css/autorenew.css @@ -0,0 +1,45 @@ +.autorenew .failed_updates, +.autorenew .failed_domains, +.autorenew .processed_updates { + display: none; +} + +.autorenew .processed_updates { + font-weight: bold; +} + +.autorenew .failed_updates { + margin-top: 10px; + color: red; + font-weight: bold; +} + +.autorenew .failed_domains { + max-height: 170px; + overflow-y: scroll; + margin-top: 15px; + background-color: #f7e9e9; + padding: 15px; + border-radius: 3px; +} + +.autorenew .failed_domains p { + margin-top: 10px; + margin-bottom: 0; +} + +.autorenew .failed_domains p:first-child { + margin-top: 0; +} + +.autorenew .amount { + font-weight: bold; +} + +#renew_form .submit { + margin: 1rem 0; +} + +.autorenew .is-active { + display: block; +} \ No newline at end of file diff --git a/modules/registrars/realtimeregister/src/Assets/Css/general.css b/modules/registrars/realtimeregister/src/Assets/Css/general.css new file mode 100644 index 0000000..ee50008 --- /dev/null +++ b/modules/registrars/realtimeregister/src/Assets/Css/general.css @@ -0,0 +1,53 @@ +@keyframes move { + 0% { + background-position: 0 0; + } + 100% { + background-position: 50px 50px; + } +} + +.rtr-progress-bar { + display: none; + background-color: #f1f0e8; + position: relative; + height: 30px; + overflow: hidden; + border-radius: 3px; +} + +.rtr-progress-bar .progress-label { + color: white; + text-align: center; + height: 30px; + background-color: #2261a3; + width: 5%; + line-height: 30px; + position: relative; +} + +.rtr-progress-bar .progress-label .complete:after { + display: none; +} + +.rtr-progress-bar .progress-label:after { + content: ""; + position: absolute; + top: 0; + left: 0; + bottom: 0; + right: 0; + z-index: 1; + background-size: 50px 50px; + background-image: linear-gradient( + 45deg, + rgba(255, 255, 255, 0.2) 25%, + transparent 25%, + transparent 50%, + rgba(255, 255, 255, 0.2) 50%, + rgba(255, 255, 255, 0.2) 75%, + transparent 75%, + transparent + ); + animation: move 2s linear infinite; +} \ No newline at end of file diff --git a/modules/registrars/realtimeregister/src/Assets/Css/importdomains.css b/modules/registrars/realtimeregister/src/Assets/Css/importdomains.css index d7754d8..81be0a9 100644 --- a/modules/registrars/realtimeregister/src/Assets/Css/importdomains.css +++ b/modules/registrars/realtimeregister/src/Assets/Css/importdomains.css @@ -1,29 +1,53 @@ .stepwizard-row { + position: relative; display: flex; flex-direction: row; align-items: center; - gap: 1rem + justify-content: space-between; } .stepwizard-step { display: flex; align-items: center; - flex-direction: row; - gap: 0.75rem + flex-direction: column; + gap: 0.5rem; + z-index: 2; +} + +.stepwizard-row:before { + top: 14px; + bottom: 0; + position: absolute; + content: " "; + width: 100%; + height: 2px; + background-color: #ccc; } .btn-circle { width: 30px; height: 30px; - text-align: center; - padding: 6px 0; + padding: 0 0; font-size: 12px; line-height: 1.428571429; border-radius: 15px; } -.btn-circle:not(.btn-current) { - background: #79a8d0 !important; +.btn-circle:not(.btn-current):not(:disabled) { + color: #333333; + opacity: 1 !important; + background: #fff +} + +.btn-circle:disabled { + background-color: lightgrey; + border-color: grey; + opacity: 1 !important; +} + +.btn-circle:disabled:hover { + background-color: lightgrey; + border-color: grey; } .failed-domains { @@ -34,6 +58,10 @@ color: red; } +.rtr-progress-bar { + margin-top: 2rem; +} + .brand_overview, .failed_domains, .warning_domains { diff --git a/modules/registrars/realtimeregister/src/Assets/Js/importDomains.js b/modules/registrars/realtimeregister/src/Assets/Js/importDomains.js deleted file mode 100644 index 62f8e26..0000000 --- a/modules/registrars/realtimeregister/src/Assets/Js/importDomains.js +++ /dev/null @@ -1,30 +0,0 @@ -$(document).ready( - function () { - const moduleName = 'realtimeregister'; - const configContainer = $('#' + moduleName + 'config'); - - configContainer.on( - 'click', '.import-wizard', function (e) { - e.preventDefault(); - - const contentArea = $('#contentarea'); - - $.post( - window.location.href, - { - action: 'importWizard', - module: moduleName, - }, - function (response) { - contentArea.html(response); - window.scrollTo(0,0); - }, - "html" - ).fail( - function (e) { - } - ); - } - ); - } -); \ No newline at end of file diff --git a/modules/registrars/realtimeregister/src/Assets/Js/util.js b/modules/registrars/realtimeregister/src/Assets/Js/util.js new file mode 100644 index 0000000..ed9fbd7 --- /dev/null +++ b/modules/registrars/realtimeregister/src/Assets/Js/util.js @@ -0,0 +1,25 @@ +function setProgress(total, current) { + progress = (100 / total * current); + if (progress < 100) { + $(".rtr-progress-bar .progress-label").text(Math.floor(progress) + '%') + .stop(true, true) + .animate({ + width: Math.floor(progress) + '%' + }, 200); + } else { + progressComplete(); + } +} + +function showProgressBar() { + $(".rtr-progress-bar").show(); +} + +function progressComplete() { + $('.rtr-progress-bar .progress-label').addClass('complete'); + $(".rtr-progress-bar .progress-label").text('Complete!') + .stop(true, true) + .animate({ + width: '100%' + }, 200); +} \ No newline at end of file diff --git a/modules/registrars/realtimeregister/src/Assets/Tpl/actions.tpl b/modules/registrars/realtimeregister/src/Assets/Tpl/actions.tpl new file mode 100644 index 0000000..c41e464 --- /dev/null +++ b/modules/registrars/realtimeregister/src/Assets/Tpl/actions.tpl @@ -0,0 +1,53 @@ +
+ +
+ + + +
+ + +
+ + \ No newline at end of file diff --git a/modules/registrars/realtimeregister/src/Assets/Tpl/autoRenew.tpl b/modules/registrars/realtimeregister/src/Assets/Tpl/autoRenew.tpl new file mode 100644 index 0000000..b00b763 --- /dev/null +++ b/modules/registrars/realtimeregister/src/Assets/Tpl/autoRenew.tpl @@ -0,0 +1,83 @@ +
+

+ Set the renewal for {count($domains)} domains to false +

+ +

Processed updates: 0/{count($domains)}

+ +
+
Processing...
+
+ +

Failed updates: 0

+
+ +
+ + +
+ +

+ NOTE: if you have .NL and .DE domains with a period shorter than 12 months, the auto-renew + status will not be changed.
+ .NL/.DE --> periods 1 and 3 months must be on AUTO_RENEW TRUE at Realtime Register.
+

+
+ + diff --git a/modules/registrars/realtimeregister/src/Assets/Tpl/content.tpl b/modules/registrars/realtimeregister/src/Assets/Tpl/content.tpl new file mode 100644 index 0000000..e1f2082 --- /dev/null +++ b/modules/registrars/realtimeregister/src/Assets/Tpl/content.tpl @@ -0,0 +1,10 @@ + \ No newline at end of file diff --git a/modules/registrars/realtimeregister/src/Assets/Tpl/importDomains.tpl b/modules/registrars/realtimeregister/src/Assets/Tpl/importDomains.tpl index fe628a5..14ef299 100644 --- a/modules/registrars/realtimeregister/src/Assets/Tpl/importDomains.tpl +++ b/modules/registrars/realtimeregister/src/Assets/Tpl/importDomains.tpl @@ -1,4 +1,4 @@ -
+

This wizard will import domains from your Realtime Register account into WHMCS. Domain attributes like expiry date and status will be copied automatically. The importer will match up domain @@ -11,11 +11,11 @@ Setup

- + Confirm
- + Import
@@ -29,8 +29,7 @@ {/if}
-
- @@ -218,18 +218,20 @@ function setBrandSelection(type) { brandSelectionMethod = type; if (type === 'list') { - $('.brand-selection-list').removeClass('hidden'); + $('.brand-selection-list').show(); } else { - $('.brand-selection-list').addClass('hidden'); + $('.brand-selection-list').hide(); } } function setDomainSelection(type) { domainSelectionMethod = type; if (type === 'list') { - $('.domain-selection-list').removeClass('hidden'); + $('.domain-selection-list').show(); + $('.warning_domains').hide(); } else { - $('.domain-selection-list').addClass('hidden'); + $('.domain-selection-list').hide(); + $('.warning_domains').show(); } } @@ -276,6 +278,15 @@ $(function () { if (domainSelectionMethod === 'list') { $('.domain-selection-list textarea').val((fields.selectedDomains || []).join("\n")); + $('.warning_domains').hide(); + } else { + $('.domain-selection-list').hide(); + } + + if (brandSelectionMethod === 'list') { + $('.brand-selection-list').show(); + } else { + $('.brand-selection-list').hide(); } $('.step-one-form').on("submit", event => { @@ -284,7 +295,7 @@ return; } - const contentArea = $('#contentarea'); + const contentArea = $('.modal-body'); $.post( window.location.href, { diff --git a/modules/registrars/realtimeregister/src/Assets/Tpl/importDomainsStepThree.tpl b/modules/registrars/realtimeregister/src/Assets/Tpl/importDomainsStepThree.tpl index 9fb822a..3ddbdaa 100644 --- a/modules/registrars/realtimeregister/src/Assets/Tpl/importDomainsStepThree.tpl +++ b/modules/registrars/realtimeregister/src/Assets/Tpl/importDomainsStepThree.tpl @@ -6,7 +6,7 @@ Setup
- + Confirm
@@ -15,32 +15,28 @@
-
- The domain importer is running. Please be patient until this process completes. -
-
-
- - 0% - +
+
Processing...
+

Processed domains: 0

- \ No newline at end of file diff --git a/modules/registrars/realtimeregister/src/Assets/Tpl/syncDomains.tpl b/modules/registrars/realtimeregister/src/Assets/Tpl/syncDomains.tpl new file mode 100644 index 0000000..228cf23 --- /dev/null +++ b/modules/registrars/realtimeregister/src/Assets/Tpl/syncDomains.tpl @@ -0,0 +1,105 @@ +
+ {if count($fields['whmcsDomains']) < count($fields['rtrDomains'])} +

+ It looks like your WHMCS installation is out of sync with RealtimeRegister, please use the Import + Wizard to import all domains from RealtimeRegister. +

+

+ Domain count: 0 +

+

+ Domains present in WHMCS: {{count($fields['whmcsDomains'])}} +

+

+ Domains present at Realtime Register: {{count($fields['rtrDomains'])}} +

+ {/if} + + + +
+ +
+
Loading...
+
+ + +
+

Processed domains: 0/0

+
+ +
+ +
+
+ Expiry date sync completed! + +
+

Total domains synced: 0

+

Domains changed: 0

+

Domains skipped: 0

+
+
+
+
+ + diff --git a/modules/registrars/realtimeregister/src/ConfigArray.php b/modules/registrars/realtimeregister/src/ConfigArray.php index c3db4da..9c14692 100644 --- a/modules/registrars/realtimeregister/src/ConfigArray.php +++ b/modules/registrars/realtimeregister/src/ConfigArray.php @@ -42,11 +42,6 @@ public function __invoke(): array 'Description' => ' ', ], - 'import_domains' => [ - 'FriendlyName' => "
", - 'Type' => 'none', - 'Description' => '' - ], /** * General settings. */ diff --git a/modules/registrars/realtimeregister/src/Hooks/AutoRenewStatus.php b/modules/registrars/realtimeregister/src/Hooks/AutoRenewStatus.php new file mode 100644 index 0000000..4755ae0 --- /dev/null +++ b/modules/registrars/realtimeregister/src/Hooks/AutoRenewStatus.php @@ -0,0 +1,63 @@ +addScript("autoRenew.js"); + App::assets()->addStyle("autorenew.css"); + + if ($_POST['action'] === $this->ACTION && $_POST['module'] == 'realtimeregister') { + if ($_POST['domain']) { + self::updateDomain($_POST['domain']); + } else { + $domains = self::getDomains(); + echo TemplateService::renderTemplate("autoRenew.tpl", ["domains" => $domains]); + } + exit(); + } + } + + private static function getDomains(): array + { + $whmcsDomains = array_map(fn($domain) => $domain['domain'], Domain::query() + ->select(['domain']) + ->where('registrar', '=', 'realtimeregister') + ->whereIn('status', ['active', 'pending']) + ->get() + ->toArray()); + + + $rtrDomains = array_map(fn($domain) => $domain['domainName'], + App::client()->domains->export([ + 'fields' => 'domainName', + 'autoRenew' => 'true', + 'autoRenewPeriod:gte' => '12' + ])); + + return array_values(array_intersect($rtrDomains, $whmcsDomains)); + } + + private static function updateDomain(string $domain): void + { + try { + App::client()->domains->update(domainName: $domain, autoRenew: false); + logActivity(sprintf('Autorenew is set to false for domain: %s', $domain)); + echo json_encode(["updated" => true]); + } catch (\Exception $e) { + logActivity('ERROR (Realtime Register): ' . $domain . ': ' . $e->getMessage()); + http_response_code(500); + echo json_encode(["message" => $domain . ': ' . $e->getMessage()]); + } + } +} \ No newline at end of file diff --git a/modules/registrars/realtimeregister/src/Hooks/ImportDomains.php b/modules/registrars/realtimeregister/src/Hooks/ImportDomains.php index 749da0c..32e9ebd 100644 --- a/modules/registrars/realtimeregister/src/Hooks/ImportDomains.php +++ b/modules/registrars/realtimeregister/src/Hooks/ImportDomains.php @@ -6,10 +6,10 @@ use RealtimeRegister\App; use RealtimeRegister\Entities\DataObject; use RealtimeRegister\Models\RealtimeRegister\Cache; -use Realtimeregister\Models\RTRContactMapping; use RealtimeRegister\Models\Whmcs\AdditionalFields; use RealtimeRegister\Models\Whmcs\Admin; use RealtimeRegister\Models\Whmcs\Client; +use RealtimeRegister\Models\Whmcs\Configuration; use RealtimeRegister\Models\Whmcs\Domain; use RealtimeRegister\Models\Whmcs\DomainPricing; use RealtimeRegister\Models\Whmcs\PaymentGateway; @@ -26,8 +26,7 @@ public function __invoke(DataObject $vars): void App::assets()->addScript("importDomains.js"); App::assets()->addStyle("importdomains.css"); - if ($_POST['action'] === $this->ACTION && $_POST['module'] == 'realtimeregister') { - + if ($_REQUEST['action'] === $this->ACTION && $_REQUEST['module'] == 'realtimeregister') { self::importWizard(); } } @@ -44,7 +43,6 @@ public function __invoke(DataObject $vars): void default: self::step1(); break; - } exit; } @@ -155,6 +153,7 @@ private static function importDomains() : int $metadata = new MetadataService($domain['domainName']); $expiryDate = $metadata->getOffsetExpiryDate($domain['expiryDate']); + $dueDate = self::getSyncDueDate($expiryDate); $tld = MetadataService::getTld($domain['domainName']); $recurringAmount = '0.00'; @@ -172,8 +171,8 @@ private static function importDomains() : int 'paymentmethod' => $paymentMethod, 'status' => 'Active', //'is_premium' => 0, - 'nextduedate' => $expiryDate, - 'nextinvoicedate' => $expiryDate, + 'nextduedate' => $dueDate, + 'nextinvoicedate' => $dueDate, 'expirydate' => $expiryDate ]); @@ -285,108 +284,23 @@ public static function createContact($clientId, $info) return 0; } - /* - * foreach ($domainsWithRegistrant as $domain) { - if (!self::domainExists($domain['domainName'])) { - $userid = self::getRegistrantUser($domain['registrant']['handle']); - if (!$userid) { - if (in_array($domain['brand']['handle'], $brands)) { - $userid = self::createClient($domain['brand']); - } else { - $userid = self::createClient($domain['registrant']); - } - } - - if (!RTRContactMapping::where('userid', $userid)->where('handle', $domain['registrant']['handle'])->exists()) { - $contactid = self::createContact($userid, $domain['registrant']); - - $values = [ - 'userid' => $userid, - 'contactid' => $contactid, - 'handle' => $domain['registrant']['handle'], - 'org_allowed' => true - ]; - - RTRContactMapping::insert($values); - } - - try { - $metadata = new MetadataService($domain['domainName'], rtrApiClient::instance($params)); - $expirydate = DomainDateService::getOffsetExpiryDate($domain['expiryDate'], $metadata); - } catch (DefaultException $e) { - $expirydate = date('Y-m-d', strtotime($domain['expiryDate'])); - } - - $duedate = DomainDateService::getSyncDueDate($expirydate); - - $tld = rtrHelper::getTld($domain['domainName']); - $recurringamount = '0.00'; - if (!empty($tldPricing['pricing'][$tld]['renew'][$tldPricingCurrencyid])) { - $recurringamount = $tldPricing['pricing'][$tld]['renew'][$tldPricingCurrencyid]; - } - - // Insert domain in the database - $domainId = Capsule::table("tbldomains")->insertGetId([ - 'userid' => $userid, - 'registrationdate' => $domain['createdDate'], - 'domain' => $domain['domainName'], - 'recurringamount' => $recurringamount, - 'registrar' => 'realtimeregister', - 'registrationperiod' => ceil($domain['autoRenewPeriod'] / 12), - 'paymentmethod' => $paymentmethod, - 'status' => RtrApiService::mapStatustoWhmcs($domain['status']), - //'is_premium' => 0, - 'nextduedate' => $duedate, - 'nextinvoicedate' => $duedate, - 'expirydate' => $expirydate - ]); - - if (!empty($domain['registrant']['properties'])) { - $provider = rtrApiClient::instance($params)->tldProvider($tld); - - if (!empty($domain['registrant']['properties'][$provider])) { - foreach ($domain['registrant']['properties'][$provider] as $name => $value) { - Capsule::table("tbldomainsadditionalfields")->insert([ - 'domainid' => $domainId, - 'name' => $name, - 'value' => $value - ]); - } - } - } - - $resultCount['domains']++; - } else { - // Domain already exists - $resultCount['domains_exists']++; - } - } - */ - - - - /* - * if (isset($_POST['rtr']) && $_POST['rtr'] == 'import' && !empty($_POST['selection'])) { - $args = [ - 'fields' => 'domainName,autoRenewPeriod,status,createdDate,expiryDate,registrant,ns,contacts,customer', - 'export' => 'true' - ]; - if (!empty($_POST['domains'])) { - foreach ($_POST['domains'] as &$domain) { - if (Config::get('tldinfomapping.' . rtrHelper::getTld($domain)) === 'centralnic') { - $domain = $domain . '.centralnic'; - } - } - $args['domainName:in'] = implode(',', $_POST['domains']); + public static function getSyncDueDate($date) + { + $hasOffset = Configuration::query() + ->select(["value"]) + ->where("setting", '=', 'DomainSyncNextDueDate') + ->first(); + $syncOffset = Configuration::query() + ->select(["value"]) + ->where("setting", '=', 'DomainSyncNextDueDateDays') + ->first(); + + if ($hasOffset?->value && $syncOffset?->value) { + return date("Y-m-d", strtotime($date . (-$syncOffset->value) . ' days')); } - $paymentmethod = $_POST['paymentmethod']; - $brands = isset($_POST['brands']) && is_array($_POST['brands']) ? $_POST['brands'] : []; - - echo json_encode(WhmcsService::insertDomains(WhmcsService::getRtrDomainsWithActiveTld($args), $brands, $paymentmethod, $vars)); - exit; + return $date; } - */ private static function getNonActiveTlds(array $domains): array { @@ -397,7 +311,7 @@ private static function getNonActiveTlds(array $domains): array })); } - private static function randomPassword() + private static function randomPassword(): string { $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_-=+;:,.?"; diff --git a/modules/registrars/realtimeregister/src/Hooks/SyncExpiry.php b/modules/registrars/realtimeregister/src/Hooks/SyncExpiry.php new file mode 100644 index 0000000..18d3d66 --- /dev/null +++ b/modules/registrars/realtimeregister/src/Hooks/SyncExpiry.php @@ -0,0 +1,53 @@ +addScript("syncDomains.js"); + + if ($_POST['action'] === $this->ACTION && $_POST['module'] == 'realtimeregister') { + if ($_POST['domains']) { + self::syncDomains($_POST['domains']); + exit(); + } + $rtrDomains = App::client()->domains->export(['fields' => 'domainName,expiryDate']); + $whmcsDomains = array_map( + fn($domain) => $domain['domain'], + Domain::query() + ->select(['domain']) + ->where('registrar', '=', 'realtimeregister') + ->get() + ->toArray() + ); + + echo TemplateService::renderTemplate("syncDomains.tpl", ["fields" => [ + "rtrDomains" => $rtrDomains, + "whmcsDomains" => $whmcsDomains + ]]); + exit(); + } + } + + private static function syncDomains(array $domains): void + { + $updated = 0; + foreach ($domains as $domain) { + $newExpiryDate = (new MetadataService($domain['domainName']))->getOffsetExpiryDate($domain['expiryDate']); + $updated += Domain::query() + ->where('domain', '=', $domain['domainName']) + ->update(["expiryDate" => $newExpiryDate]); + } + echo json_encode(["updated" => $updated]); + } +} diff --git a/modules/registrars/realtimeregister/src/Hooks/Widgets/ToolsWidget.php b/modules/registrars/realtimeregister/src/Hooks/Widgets/ToolsWidget.php new file mode 100644 index 0000000..809434b --- /dev/null +++ b/modules/registrars/realtimeregister/src/Hooks/Widgets/ToolsWidget.php @@ -0,0 +1,13 @@ +getBasePath('/Assets/Js/' . $name)) - . '?' . App::VERSION . '">'; + . '?' . rand() . '">'; if ($scriptLocationType === ScriptLocationType::Header) { $this->addToHeader($payload); } else { @@ -86,7 +85,7 @@ public function addStyle(string $name): self { $this->addToHeader( '' + . '?' . rand() . '" rel="stylesheet">' ); return $this; diff --git a/modules/registrars/realtimeregister/src/Services/TemplateService.php b/modules/registrars/realtimeregister/src/Services/TemplateService.php index 3a33f36..2dec434 100644 --- a/modules/registrars/realtimeregister/src/Services/TemplateService.php +++ b/modules/registrars/realtimeregister/src/Services/TemplateService.php @@ -6,10 +6,10 @@ class TemplateService { - public static function renderTemplate(string $templatePath, array $args = []) : false | string + public static function renderTemplate(string $templatePath, array $args = []): false|string { $smarty = new Smarty; - + foreach ($args as $key => $value) { $smarty->assign($key, $value); } diff --git a/modules/registrars/realtimeregister/src/Widget/ToolsWidget.php b/modules/registrars/realtimeregister/src/Widget/ToolsWidget.php new file mode 100644 index 0000000..2ea85c6 --- /dev/null +++ b/modules/registrars/realtimeregister/src/Widget/ToolsWidget.php @@ -0,0 +1,26 @@ + Date: Fri, 30 Aug 2024 14:34:10 +0200 Subject: [PATCH 2/6] refactors --- modules/registrars/realtimeregister/hooks.php | 2 +- .../src/Assets/Css/actions.css | 8 +-- .../src/Assets/Tpl/actions.tpl | 50 ++++++++++++++----- .../src/Assets/Tpl/autoRenew.tpl | 16 +++--- .../src/Assets/Tpl/syncDomains.tpl | 18 ++++--- .../{ToolsWidget.php => ActionsWidget.php} | 4 +- .../realtimeregister/src/Services/Assets.php | 5 +- .../{ToolsWidget.php => ActionsWidget.php} | 4 +- 8 files changed, 69 insertions(+), 38 deletions(-) rename modules/registrars/realtimeregister/src/Hooks/Widgets/{ToolsWidget.php => ActionsWidget.php} (66%) rename modules/registrars/realtimeregister/src/Widget/{ToolsWidget.php => ActionsWidget.php} (81%) diff --git a/modules/registrars/realtimeregister/hooks.php b/modules/registrars/realtimeregister/hooks.php index 84e1ddb..0cfe7e4 100644 --- a/modules/registrars/realtimeregister/hooks.php +++ b/modules/registrars/realtimeregister/hooks.php @@ -29,7 +29,7 @@ App::hook(Hooks\ContactEdit::class); -App::hook('AdminHomeWidgets', Hooks\Widgets\ToolsWidget::class); +App::hook('AdminHomeWidgets', Hooks\Widgets\ActionsWidget::class); //App::hook('AdminHomeWidgets', Hooks\Widgets\DomainOverviewWidget::class); App::hook('ClientAreaHeadOutput', Hooks\HeadAssets::class, 100); diff --git a/modules/registrars/realtimeregister/src/Assets/Css/actions.css b/modules/registrars/realtimeregister/src/Assets/Css/actions.css index c0bb3d9..f9af65e 100644 --- a/modules/registrars/realtimeregister/src/Assets/Css/actions.css +++ b/modules/registrars/realtimeregister/src/Assets/Css/actions.css @@ -1,7 +1,9 @@ - - .action-group { + margin: 0.75rem; display: flex; flex-direction: column; - gap: 1rem; + gap: 0.75rem; +} +.action-item { + cursor: pointer; } \ No newline at end of file diff --git a/modules/registrars/realtimeregister/src/Assets/Tpl/actions.tpl b/modules/registrars/realtimeregister/src/Assets/Tpl/actions.tpl index c41e464..6e8808c 100644 --- a/modules/registrars/realtimeregister/src/Assets/Tpl/actions.tpl +++ b/modules/registrars/realtimeregister/src/Assets/Tpl/actions.tpl @@ -1,9 +1,42 @@
- - - +
+
+ +
+
+ Import domains + Import domains/clients from RealtimeRegister into WHMCS +
+
+
+
+ +
+
+ Sync Expiry Dates + Sync the expiry date for all domains in your WHMCS account +
+
+
+
+ +
+
+ Change Auto Renew Status + Change the domains autorenew status to false at RealtimeRegister +
+
'; + . '?' . App::VERSION . '">'; if ($scriptLocationType === ScriptLocationType::Header) { $this->addToHeader($payload); } else { @@ -85,7 +86,7 @@ public function addStyle(string $name): self { $this->addToHeader( '' + . '?' . App::VERSION . '" rel="stylesheet">' ); return $this; diff --git a/modules/registrars/realtimeregister/src/Widget/ToolsWidget.php b/modules/registrars/realtimeregister/src/Widget/ActionsWidget.php similarity index 81% rename from modules/registrars/realtimeregister/src/Widget/ToolsWidget.php rename to modules/registrars/realtimeregister/src/Widget/ActionsWidget.php index 2ea85c6..19277cf 100644 --- a/modules/registrars/realtimeregister/src/Widget/ToolsWidget.php +++ b/modules/registrars/realtimeregister/src/Widget/ActionsWidget.php @@ -4,9 +4,9 @@ use RealtimeRegister\Services\TemplateService; -class ToolsWidget extends \WHMCS\Module\AbstractWidget +class ActionsWidget extends \WHMCS\Module\AbstractWidget { - protected $title = 'Realtime Register - Tools'; + protected $title = 'Realtime Register - Actions'; protected $description = ''; protected $weight = 150; protected $columns = 1; From 982f432e08c5bf6ac2158b571dea23cf14dddc91 Mon Sep 17 00:00:00 2001 From: "pieterjan.eilers" Date: Fri, 30 Aug 2024 14:40:38 +0200 Subject: [PATCH 3/6] phpcbf --- modules/registrars/realtimeregister/hooks.php | 17 +++-- .../src/Actions/Domains/Sync.php | 6 +- .../realtimeregister/src/Assets/Js/util.js | 25 ++++--- .../src/Enums/WhmcsDomainStatus.php | 9 ++- .../src/Hooks/AutoRenewStatus.php | 24 ++++--- .../src/Hooks/ImportDomains.php | 68 ++++++++++++------- .../realtimeregister/src/Hooks/SyncExpiry.php | 6 +- .../src/Hooks/Widgets/ActionsWidget.php | 3 +- .../src/Models/Whmcs/Domain.php | 5 +- .../src/Models/Whmcs/PaymentGateway.php | 3 +- .../src/Services/ContactService.php | 4 +- .../src/Services/MetadataService.php | 10 +-- .../src/Widget/DomainOverviewModuleWidget.php | 4 +- 13 files changed, 110 insertions(+), 74 deletions(-) diff --git a/modules/registrars/realtimeregister/hooks.php b/modules/registrars/realtimeregister/hooks.php index 0cfe7e4..497adb4 100644 --- a/modules/registrars/realtimeregister/hooks.php +++ b/modules/registrars/realtimeregister/hooks.php @@ -8,11 +8,13 @@ App::boot(); // Utils -add_hook("AdminHomepage", 1, function() { - App::assets()->addScript("util.js"); - App::assets()->addStyle("general.css"); - App::assets()->addStyle("actions.css"); -}); +add_hook( + "AdminHomepage", 1, function () { + App::assets()->addScript("util.js"); + App::assets()->addStyle("general.css"); + App::assets()->addStyle("actions.css"); + } +); App::hook(Hooks\PreRegistrarGetContactDetails::class); @@ -20,7 +22,7 @@ App::hook("AdminAreaHeadOutput", Hooks\CheckCredentials::class); App::hook("AdminHomepage", Hooks\SyncExpiry::class, 2); App::hook("AdminHomepage", Hooks\ImportDomains::class, 2); -App::hook("AdminHomepage", Hooks\AutoRenewStatus::class ,2); +App::hook("AdminHomepage", Hooks\AutoRenewStatus::class, 2); App::hook(Hooks\AdminAreaHeadOutput::class, null, 100); @@ -30,7 +32,8 @@ App::hook('AdminHomeWidgets', Hooks\Widgets\ActionsWidget::class); -//App::hook('AdminHomeWidgets', Hooks\Widgets\DomainOverviewWidget::class); +App::hook('AdminHomeWidgets', Hooks\Widgets\DomainOverviewWidget::class); +App::hook('AdminHomeWidgets', Hooks\Widgets\BalanceWidget::class); App::hook('ClientAreaHeadOutput', Hooks\HeadAssets::class, 100); App::hook('ClientAreaFooterOutput', Hooks\FooterAssets::class, 100); diff --git a/modules/registrars/realtimeregister/src/Actions/Domains/Sync.php b/modules/registrars/realtimeregister/src/Actions/Domains/Sync.php index 87296bb..8379ba5 100644 --- a/modules/registrars/realtimeregister/src/Actions/Domains/Sync.php +++ b/modules/registrars/realtimeregister/src/Actions/Domains/Sync.php @@ -48,8 +48,7 @@ public function __invoke(Request $request) $status = WhmcsDomainStatus::fromDomainDetails($domain); - if ( - !in_array($status, [WhmcsDomainStatus::Active, WhmcsDomainStatus::Expired, WhmcsDomainStatus::Redemption]) + if (!in_array($status, [WhmcsDomainStatus::Active, WhmcsDomainStatus::Expired, WhmcsDomainStatus::Redemption]) ) { throw new Exception(sprintf("Domain status %s", $status->value)); } @@ -72,8 +71,7 @@ protected function syncDueDate(string $date): string protected function parseDomainStatus(array $statuses): string { - if ( - array_intersect([DomainStatusEnum::STATUS_SERVER_HOLD, DomainStatusEnum::STATUS_REGISTRAR_HOLD], $statuses) + if (array_intersect([DomainStatusEnum::STATUS_SERVER_HOLD, DomainStatusEnum::STATUS_REGISTRAR_HOLD], $statuses) ) { return 'Fraud'; } diff --git a/modules/registrars/realtimeregister/src/Assets/Js/util.js b/modules/registrars/realtimeregister/src/Assets/Js/util.js index ed9fbd7..c23dcd6 100644 --- a/modules/registrars/realtimeregister/src/Assets/Js/util.js +++ b/modules/registrars/realtimeregister/src/Assets/Js/util.js @@ -1,25 +1,32 @@ -function setProgress(total, current) { +function setProgress(total, current) +{ progress = (100 / total * current); if (progress < 100) { $(".rtr-progress-bar .progress-label").text(Math.floor(progress) + '%') .stop(true, true) - .animate({ - width: Math.floor(progress) + '%' - }, 200); + .animate( + { + width: Math.floor(progress) + '%' + }, 200 + ); } else { progressComplete(); } } -function showProgressBar() { +function showProgressBar() +{ $(".rtr-progress-bar").show(); } -function progressComplete() { +function progressComplete() +{ $('.rtr-progress-bar .progress-label').addClass('complete'); $(".rtr-progress-bar .progress-label").text('Complete!') .stop(true, true) - .animate({ - width: '100%' - }, 200); + .animate( + { + width: '100%' + }, 200 + ); } \ No newline at end of file diff --git a/modules/registrars/realtimeregister/src/Enums/WhmcsDomainStatus.php b/modules/registrars/realtimeregister/src/Enums/WhmcsDomainStatus.php index f78972d..d7dd987 100644 --- a/modules/registrars/realtimeregister/src/Enums/WhmcsDomainStatus.php +++ b/modules/registrars/realtimeregister/src/Enums/WhmcsDomainStatus.php @@ -15,11 +15,10 @@ enum WhmcsDomainStatus: string public static function fromDomainDetails(DomainDetails $domain): WhmcsDomainStatus { - if ( - array_intersect( - [DomainStatusEnum::STATUS_SERVER_HOLD, DomainStatusEnum::STATUS_REGISTRAR_HOLD], - $domain->status - ) + if (array_intersect( + [DomainStatusEnum::STATUS_SERVER_HOLD, DomainStatusEnum::STATUS_REGISTRAR_HOLD], + $domain->status + ) ) { return self::Fraud; } diff --git a/modules/registrars/realtimeregister/src/Hooks/AutoRenewStatus.php b/modules/registrars/realtimeregister/src/Hooks/AutoRenewStatus.php index 4755ae0..212c2a5 100644 --- a/modules/registrars/realtimeregister/src/Hooks/AutoRenewStatus.php +++ b/modules/registrars/realtimeregister/src/Hooks/AutoRenewStatus.php @@ -30,20 +30,26 @@ public function __invoke(DataObject $vars): void private static function getDomains(): array { - $whmcsDomains = array_map(fn($domain) => $domain['domain'], Domain::query() - ->select(['domain']) - ->where('registrar', '=', 'realtimeregister') - ->whereIn('status', ['active', 'pending']) - ->get() - ->toArray()); + $whmcsDomains = array_map( + fn($domain) => $domain['domain'], Domain::query() + ->select(['domain']) + ->where('registrar', '=', 'realtimeregister') + ->whereIn('status', ['active', 'pending']) + ->get() + ->toArray() + ); - $rtrDomains = array_map(fn($domain) => $domain['domainName'], - App::client()->domains->export([ + $rtrDomains = array_map( + fn($domain) => $domain['domainName'], + App::client()->domains->export( + [ 'fields' => 'domainName', 'autoRenew' => 'true', 'autoRenewPeriod:gte' => '12' - ])); + ] + ) + ); return array_values(array_intersect($rtrDomains, $whmcsDomains)); } diff --git a/modules/registrars/realtimeregister/src/Hooks/ImportDomains.php b/modules/registrars/realtimeregister/src/Hooks/ImportDomains.php index 32e9ebd..78c11b5 100644 --- a/modules/registrars/realtimeregister/src/Hooks/ImportDomains.php +++ b/modules/registrars/realtimeregister/src/Hooks/ImportDomains.php @@ -34,15 +34,15 @@ public function __invoke(DataObject $vars): void #[NoReturn] private static function importWizard(): void { switch ($_POST['step']) { - case 2: - self::step2(); - break; - case 3: - self::step3(); - break; - default: - self::step1(); - break; + case 2: + self::step2(); + break; + case 3: + self::step3(); + break; + default: + self::step1(); + break; } exit; } @@ -62,28 +62,35 @@ private static function step1(): void $fields = $_POST['fields'] ?? []; - echo TemplateService::renderTemplate('importDomains.tpl', + echo TemplateService::renderTemplate( + 'importDomains.tpl', [ - "fields" => array_merge(["brandSelectionList" => [], + "fields" => array_merge( + ["brandSelectionList" => [], "allBrands" => $brands, "allDomains" => $domains, "gateways" => $paymentGateways, "nonActiveTlds" => self::getNonActiveTlds($domains), 'domainSelectionMethod' => 'all', - "brandSelectionMethod" => "contactsAsClients"], $fields) - ]); + "brandSelectionMethod" => "contactsAsClients"], $fields + ) + ] + ); } private static function step2(): void { - echo TemplateService::renderTemplate('importDomainsStepTwo.tpl', [ + echo TemplateService::renderTemplate( + 'importDomainsStepTwo.tpl', [ "fields" => $_POST['fields'], - ]); + ] + ); } - private static function getDomainName(string $domain) { + private static function getDomainName(string $domain) + { if (Config::get('tldinfomapping.' . MetadataService::getTld($domain)) === 'centralnic') { return $domain . '.centralnic'; } @@ -108,7 +115,8 @@ function () use ($customer, $domain) { return $domains; } - private static function step3(): void { + private static function step3(): void + { if ($_POST['domains']) { echo json_encode(["updated" => self::importDomains()]); } else { @@ -161,7 +169,8 @@ private static function importDomains() : int $recurringAmount = $tldPricing['pricing'][$tld]['renew'][$tldPricingCurrencyid]; } - $domainId = Domain::query()->insertGetId([ + $domainId = Domain::query()->insertGetId( + [ 'userid' => $userId, 'registrationdate' => $domain['createdDate'], 'domain' => $domain['domainName'], @@ -174,17 +183,20 @@ private static function importDomains() : int 'nextduedate' => $dueDate, 'nextinvoicedate' => $dueDate, 'expirydate' => $expiryDate - ]); + ] + ); $provider = $metadata->getProvider(); if (!empty($domain['registrant']['properties'] && !empty($domain['registrant']['properties'][$provider]))) { foreach ($domain['registrant']['properties'][$provider] as $name => $value) { - AdditionalFields::query()->insert([ + AdditionalFields::query()->insert( + [ 'domainid' => $domainId, 'name' => $name, 'value' => $value - ]); + ] + ); } } @@ -242,7 +254,7 @@ public static function createClient($info, $admin) if ($results['result'] == 'success') { return $results['clientid']; } else { - logActivity("Error for creating a client. An Error Occurred: " . implode(" | ",$results)); + logActivity("Error for creating a client. An Error Occurred: " . implode(" | ", $results)); } return 0; @@ -278,7 +290,7 @@ public static function createContact($clientId, $info) if ($results['result'] == 'success') { return $results['contactid']; } else { - logActivity("Error for creating a contact. An Error Occurred: " . implode(" | ",$results)); + logActivity("Error for creating a contact. An Error Occurred: " . implode(" | ", $results)); } return 0; @@ -306,9 +318,13 @@ private static function getNonActiveTlds(array $domains): array { $tlds = array_map(fn($domain) => MetadataService::getTld($domain), $domains); $activeTlds = array_map(fn($pricing) => $pricing['extension'], DomainPricing::query()->get(['extension'])->toArray()); - return array_values(array_filter($tlds, function ($tld) use ($activeTlds) { - return !in_array("." . strtolower($tld), $activeTlds); - })); + return array_values( + array_filter( + $tlds, function ($tld) use ($activeTlds) { + return !in_array("." . strtolower($tld), $activeTlds); + } + ) + ); } private static function randomPassword(): string diff --git a/modules/registrars/realtimeregister/src/Hooks/SyncExpiry.php b/modules/registrars/realtimeregister/src/Hooks/SyncExpiry.php index 18d3d66..5ed0576 100644 --- a/modules/registrars/realtimeregister/src/Hooks/SyncExpiry.php +++ b/modules/registrars/realtimeregister/src/Hooks/SyncExpiry.php @@ -31,10 +31,12 @@ public function __invoke(DataObject $vars): void ->toArray() ); - echo TemplateService::renderTemplate("syncDomains.tpl", ["fields" => [ + echo TemplateService::renderTemplate( + "syncDomains.tpl", ["fields" => [ "rtrDomains" => $rtrDomains, "whmcsDomains" => $whmcsDomains - ]]); + ]] + ); exit(); } } diff --git a/modules/registrars/realtimeregister/src/Hooks/Widgets/ActionsWidget.php b/modules/registrars/realtimeregister/src/Hooks/Widgets/ActionsWidget.php index aa961dd..e575caf 100644 --- a/modules/registrars/realtimeregister/src/Hooks/Widgets/ActionsWidget.php +++ b/modules/registrars/realtimeregister/src/Hooks/Widgets/ActionsWidget.php @@ -5,7 +5,8 @@ use RealtimeRegister\Entities\DataObject; use RealtimeRegister\Hooks\Hook; -class ActionsWidget extends Hook { +class ActionsWidget extends Hook +{ public function __invoke(DataObject $vars) { return new \RealtimeRegister\Widget\ActionsWidget(); diff --git a/modules/registrars/realtimeregister/src/Models/Whmcs/Domain.php b/modules/registrars/realtimeregister/src/Models/Whmcs/Domain.php index 4fefc96..39b619f 100644 --- a/modules/registrars/realtimeregister/src/Models/Whmcs/Domain.php +++ b/modules/registrars/realtimeregister/src/Models/Whmcs/Domain.php @@ -9,7 +9,8 @@ class Domain extends Model public const TABLE_NAME = 'tbldomains'; protected $table = self::TABLE_NAME; - public static function exists(string $domainName): bool { - return self::query()->select(["id"])->where('domain','=', $domainName)->count() > 0; + public static function exists(string $domainName): bool + { + return self::query()->select(["id"])->where('domain', '=', $domainName)->count() > 0; } } diff --git a/modules/registrars/realtimeregister/src/Models/Whmcs/PaymentGateway.php b/modules/registrars/realtimeregister/src/Models/Whmcs/PaymentGateway.php index 509f151..e5345c4 100644 --- a/modules/registrars/realtimeregister/src/Models/Whmcs/PaymentGateway.php +++ b/modules/registrars/realtimeregister/src/Models/Whmcs/PaymentGateway.php @@ -4,7 +4,8 @@ use Illuminate\Database\Eloquent\Model; -class PaymentGateway extends Model { +class PaymentGateway extends Model +{ protected $table = 'tblpaymentgateways'; protected $guarded = ['id']; diff --git a/modules/registrars/realtimeregister/src/Services/ContactService.php b/modules/registrars/realtimeregister/src/Services/ContactService.php index 5badbed..f479173 100644 --- a/modules/registrars/realtimeregister/src/Services/ContactService.php +++ b/modules/registrars/realtimeregister/src/Services/ContactService.php @@ -78,8 +78,8 @@ public static function convertToRtrContact(DataObject $whmcsContact, bool $organ } /** - * @param string|int $userId - * @param string|int $contactId + * @param string|int $userId + * @param string|int $contactId * @return Collection */ public function fetchMappingByContactId(string|int $userId, string|int $contactId): Collection diff --git a/modules/registrars/realtimeregister/src/Services/MetadataService.php b/modules/registrars/realtimeregister/src/Services/MetadataService.php index e51ae5f..7921bfb 100644 --- a/modules/registrars/realtimeregister/src/Services/MetadataService.php +++ b/modules/registrars/realtimeregister/src/Services/MetadataService.php @@ -52,7 +52,7 @@ public function getAll(): TLDInfo } /** - * @param string $param + * @param string $param * @return string|int|array|bool */ public function get(string $param) @@ -76,7 +76,7 @@ public function getApplicableFor() } /** - * @param string $domain the domain name + * @param string $domain the domain name * @return string */ public static function getTld($domain) @@ -280,9 +280,9 @@ public static function getAllTlds(): array public static function isRtr($tld) { return DomainPricing::query() - ->where("extension", "." . $tld) - ->whereIn("autoreg", ["realtimeregister", ""]) - ->first() !== null; + ->where("extension", "." . $tld) + ->whereIn("autoreg", ["realtimeregister", ""]) + ->first() !== null; } public function getOffsetExpiryDate(string $expiryDate): string diff --git a/modules/registrars/realtimeregister/src/Widget/DomainOverviewModuleWidget.php b/modules/registrars/realtimeregister/src/Widget/DomainOverviewModuleWidget.php index 8f47496..0f6b75f 100644 --- a/modules/registrars/realtimeregister/src/Widget/DomainOverviewModuleWidget.php +++ b/modules/registrars/realtimeregister/src/Widget/DomainOverviewModuleWidget.php @@ -23,7 +23,9 @@ public function getData() public function generateOutput($data): string { - /** @var Pagination $data */ + /** + * @var Pagination $data +*/ $number = number_format($data->total); return << Date: Fri, 30 Aug 2024 14:50:24 +0200 Subject: [PATCH 4/6] Homepage hook --- modules/registrars/realtimeregister/hooks.php | 14 +- .../realtimeregister/src/Assets/Js/adac.js | 220 +++++++----- .../realtimeregister/src/Assets/Js/rtr.js | 34 +- .../src/Assets/Js/rtrClient.js | 340 ++++++++++-------- .../src/Assets/Js/rtrHandleMapping.js | 45 ++- .../src/Assets/Tpl/importDomainsStepThree.tpl | 2 +- .../src/Assets/Tpl/syncDomains.tpl | 2 +- .../realtimeregister/src/Hooks/Adac.php | 33 +- .../src/Hooks/AdminHomepage.php | 16 + .../src/Hooks/ClientAreaHeadOutput.php | 6 +- .../src/Services/ShoppingCartService.php | 10 +- 11 files changed, 414 insertions(+), 308 deletions(-) create mode 100644 modules/registrars/realtimeregister/src/Hooks/AdminHomepage.php diff --git a/modules/registrars/realtimeregister/hooks.php b/modules/registrars/realtimeregister/hooks.php index d80efb3..4d525ce 100644 --- a/modules/registrars/realtimeregister/hooks.php +++ b/modules/registrars/realtimeregister/hooks.php @@ -7,15 +7,6 @@ App::boot(); -// Utils -add_hook( - "AdminHomepage", 1, function () { - App::assets()->addScript("util.js"); - App::assets()->addStyle("general.css"); - App::assets()->addStyle("actions.css"); - } -); - App::hook(Hooks\PreRegistrarGetContactDetails::class); App::hook(Hooks\AdminAreaPage::class, null, 10); @@ -36,9 +27,10 @@ App::hook('ClientAreaHeadOutput', Hooks\ClientAreaHeadOutput::class, 20); App::hook('AdminHomeWidgets', Hooks\Widgets\ActionsWidget::class); -App::hook('AdminHomeWidgets', Hooks\Widgets\DomainOverviewWidget::class); -App::hook('AdminHomeWidgets', Hooks\Widgets\BalanceWidget::class); +//App::hook('AdminHomeWidgets', Hooks\Widgets\DomainOverviewWidget::class); +//App::hook('AdminHomeWidgets', Hooks\Widgets\BalanceWidget::class); +App::hook(Hooks\AdminHomepage::class); App::hook('ClientAreaHeadOutput', Hooks\HeadAssets::class, 100); App::hook('ClientAreaFooterOutput', Hooks\FooterAssets::class, 100); App::hook('AdminAreaHeadOutput', Hooks\HeadAssets::class, 100); diff --git a/modules/registrars/realtimeregister/src/Assets/Js/adac.js b/modules/registrars/realtimeregister/src/Assets/Js/adac.js index 4c73d9e..917c640 100644 --- a/modules/registrars/realtimeregister/src/Assets/Js/adac.js +++ b/modules/registrars/realtimeregister/src/Assets/Js/adac.js @@ -49,7 +49,8 @@ statusClass[3] = 'label-danger'; statusClass[4] = 'label-default'; statusClass[5] = 'label-default'; -function ready(fn) { +function ready(fn) +{ if (document.readyState != 'loading') { fn(); } @@ -57,15 +58,18 @@ function ready(fn) { document.addEventListener('DOMContentLoaded', fn); } else { - document.attachEvent('onreadystatechange', function () { - if (document.readyState != 'loading') { - fn(); + document.attachEvent( + 'onreadystatechange', function () { + if (document.readyState != 'loading') { + fn(); + } } - }); + ); } } -function getCheckedBoxes(checkboxName) { +function getCheckedBoxes(checkboxName) +{ var checkboxes = document.getElementsByName(checkboxName); var checkboxesChecked = []; @@ -92,24 +96,31 @@ var init = function () { } var dataArray = JSON.parse(xhr.responseText); - dataArray.forEach(function (data) { - adac['action_' + data.action](data.data); - }); + dataArray.forEach( + function (data) { + adac['action_' + data.action](data.data); + } + ); } if (xhr.status == 200) { adac.pollServer(); } else { - setTimeout(function () { - adac.pollServer(); - }, adac.RECONNECT_TIME); + setTimeout( + function () { + adac.pollServer(); + }, adac.RECONNECT_TIME + ); } } }; adac.inputElement.onpaste = function (event) { - setTimeout(function () { adac.processInput.call(adac.inputElement, event, adac.inputElement.value); }, 0); + setTimeout( + function () { + adac.processInput.call(adac.inputElement, event, adac.inputElement.value); }, 0 + ); }; adac.pollServer = function (xhr_type, command) { @@ -144,9 +155,11 @@ var init = function () { adac.connection.send(JSON.stringify(command)); } else { - setTimeout(function () { - adac.sendCommand(command); - }, 100); + setTimeout( + function () { + adac.sendCommand(command); + }, 100 + ); } }; @@ -171,12 +184,14 @@ var init = function () { } setupFallbackConnection(); } else { - setTimeout(function () { - if (adac.debug) { - console.log('ws connection retrying...'); - } - setupWebsocketConnection(); - }, adac.RECONNECT_TIME); + setTimeout( + function () { + if (adac.debug) { + console.log('ws connection retrying...'); + } + setupWebsocketConnection(); + }, adac.RECONNECT_TIME + ); } }; }; @@ -203,9 +218,11 @@ var adac = { return function () { var context = this, args = arguments; clearTimeout(timer); - timer = setTimeout(function () { - fn.apply(context, args); - }, delay); + timer = setTimeout( + function () { + fn.apply(context, args); + }, delay + ); }; }, @@ -236,16 +253,20 @@ var adac = { adac.categoriesElement = config.categoriesElement; adac.debug = config.debug; - ready(function() { - init(); - adac.fetch_categories(); + ready( + function () { + init(); + adac.fetch_categories(); - $(document).ready(function () { - if (adac.inputElement.value) { - adac.processInput.call(adac.inputElement, null, adac.inputElement.value); - } - }); - }); + $(document).ready( + function () { + if (adac.inputElement.value) { + adac.processInput.call(adac.inputElement, null, adac.inputElement.value); + } + } + ); + } + ); }, fetch_categories: function () { @@ -254,15 +275,17 @@ var adac = { }, initInputListener: function () { - adac.inputElement.onkeyup = adac.debounce(function (event) { - var ignoreKeys = [9, 16, 17, 18, 20, 37, 38, 39, 40, 91, 92, 93]; - if (ignoreKeys.indexOf(event.which) > -1) { - return false; - } + adac.inputElement.onkeyup = adac.debounce( + function (event) { + var ignoreKeys = [9, 16, 17, 18, 20, 37, 38, 39, 40, 91, 92, 93]; + if (ignoreKeys.indexOf(event.which) > -1) { + return false; + } - adac.preInput(this.value); - adac.processInput.call(this, event, this.value); - }, adac.DEBOUNCE_TIME); + adac.preInput(this.value); + adac.processInput.call(this, event, this.value); + }, adac.DEBOUNCE_TIME + ); if (adac.categoriesElement) { adac.categoriesElement.onchange = function (event) { @@ -368,7 +391,7 @@ var adac = { div.className = 'domain-option domain_status_' + domainResult.status; // Premium label - if(domainResult.price != undefined){ + if(domainResult.price != undefined) { document.getElementById('domain-name-' + domainResult.domain_name).innerHTML += ' ' + premiumLang + ''; } } @@ -473,27 +496,29 @@ var adac = { console.error('Categories container not found. Please check the `adac.categoriesElement` setting.'); } } else { - categories.forEach(function (category, _index, _array) { - var id = category[0], + categories.forEach( + function (category, _index, _array) { + var id = category[0], name = category[1], checkbox = document.createElement('input'); - checkbox.type = 'checkbox'; - checkbox.name = 'adac-js-categories'; - checkbox.value = id; - checkbox.id = id; + checkbox.type = 'checkbox'; + checkbox.name = 'adac-js-categories'; + checkbox.value = id; + checkbox.id = id; - var label = document.createElement('label'); - label.htmlFor = id; - label.appendChild(document.createTextNode(name)); + var label = document.createElement('label'); + label.htmlFor = id; + label.appendChild(document.createTextNode(name)); - adac.categoriesElement.appendChild(checkbox); - adac.categoriesElement.appendChild(label); - }); + adac.categoriesElement.appendChild(checkbox); + adac.categoriesElement.appendChild(label); + } + ); } }, - showError: function(error) { + showError: function (error) { var p = document.createElement('p'); p.appendChild(document.createTextNode('Error: ' + error)); adac.resultsElement.appendChild(p); @@ -503,17 +528,24 @@ var adac = { var checkedBoxes = getCheckedBoxes('adac-js-categories'); if (checkedBoxes) { - return checkedBoxes.map(function (element) { - return parseInt(element.value); - }); + return checkedBoxes.map( + function (element) { + return parseInt(element.value); + } + ); } return null; }, - ensureUUID: function() { + ensureUUID: function () { if (localStorage.getItem('sessionId') === null) { - localStorage.setItem('sessionId', 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);})); + localStorage.setItem( + 'sessionId', 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace( + /[xy]/g, function (c) { + var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);} + ) + ); } } }; @@ -535,10 +567,10 @@ function domainHtml(domainName, domainResult) domainName.className = 'domain col-xs-12 col-sm-5 text-xs-center'; domainName.innerHTML = '' + domainWithoutExtension[0] + '.' + domainResult.suffix + ''; - if (tldPrices['' + suffixWithoutDot + ''] != undefined && - tldPrices['' + suffixWithoutDot + ''].group != undefined && - tldPrices['' + suffixWithoutDot + ''].group != 'none' && - tldPrices['' + suffixWithoutDot + ''].group != '' + if (tldPrices['' + suffixWithoutDot + ''] != undefined + && tldPrices['' + suffixWithoutDot + ''].group != undefined + && tldPrices['' + suffixWithoutDot + ''].group != 'none' + && tldPrices['' + suffixWithoutDot + ''].group != '' ) { var group = tldPrices['' + suffixWithoutDot + ''].group; var labelClass = 'label-warning'; @@ -571,26 +603,32 @@ function priceHtml(price, domainResult, status) price.innerHTML = premiumNotSupportedLang; } else { // Do ajax call to get premium price - $.post(document.location.href, { - adacpremium: domainResult.domain_name, - adacpremiumprice: domainResult.price, - adacpremiumcurrency: domainResult.currency - }) - .done(function (data) { - var json = $.parseJSON(data); - - if (json.error != undefined) { - price.innerHTML = ''; - status.innerHTML = 'error'; - $('.adac-register-domain[domain="' + domainResult.domain_name + '"]').replaceWith( - json.error); - } else { - // Set register to enable - price.innerHTML = json.price + ' ' + json.currency['suffix']; - $('.adac-register-domain[domain="' + domainResult.domain_name + '"]').removeClass( - 'disabled'); - } - }, "json"); + $.post( + document.location.href, { + adacpremium: domainResult.domain_name, + adacpremiumprice: domainResult.price, + adacpremiumcurrency: domainResult.currency + } + ) + .done( + function (data) { + var json = $.parseJSON(data); + + if (json.error != undefined) { + price.innerHTML = ''; + status.innerHTML = 'error'; + $('.adac-register-domain[domain="' + domainResult.domain_name + '"]').replaceWith( + json.error + ); + } else { + // Set register to enable + price.innerHTML = json.price + ' ' + json.currency['suffix']; + $('.adac-register-domain[domain="' + domainResult.domain_name + '"]').removeClass( + 'disabled' + ); + } + }, "json" + ); price.innerHTML = ''; } } else if(tldPrices['' + suffixWithoutDot + ''] && tldPrices['' + suffixWithoutDot + ''].domainregister != undefined) { @@ -613,10 +651,12 @@ function clickRegister(event, domain) button.html(""); $.post(window.location.pathname, {a: "addToCart", domain: domain, token: csrfToken, whois: 0}) - .done(function (data) { - button.attr("href", "cart.php?a=confdomains"); - button.html(' ' + checkoutLang); - button.addClass('checkout'); - }); + .done( + function (data) { + button.attr("href", "cart.php?a=confdomains"); + button.html(' ' + checkoutLang); + button.addClass('checkout'); + } + ); } } diff --git a/modules/registrars/realtimeregister/src/Assets/Js/rtr.js b/modules/registrars/realtimeregister/src/Assets/Js/rtr.js index e99caf3..5eea8ec 100644 --- a/modules/registrars/realtimeregister/src/Assets/Js/rtr.js +++ b/modules/registrars/realtimeregister/src/Assets/Js/rtr.js @@ -1,17 +1,23 @@ (function ($) { - rtr = $.extend({ - controller: [], - params: null, - routes: {}, - error: null - }, rtr); + rtr = $.extend( + { + controller: [], + params: null, + routes: {}, + error: null + }, rtr + ); - $(document).ready(function () { - // Initialize router controller. - $.each(rtr.controller, function (i, controller) { - if ($.isFunction(rtr.routes[controller])) { - rtr.routes[controller](); - } - }); - }); + $(document).ready( + function () { + // Initialize router controller. + $.each( + rtr.controller, function (i, controller) { + if ($.isFunction(rtr.routes[controller])) { + rtr.routes[controller](); + } + } + ); + } + ); })(jQuery); diff --git a/modules/registrars/realtimeregister/src/Assets/Js/rtrClient.js b/modules/registrars/realtimeregister/src/Assets/Js/rtrClient.js index 19fc411..6e3af9a 100644 --- a/modules/registrars/realtimeregister/src/Assets/Js/rtrClient.js +++ b/modules/registrars/realtimeregister/src/Assets/Js/rtrClient.js @@ -8,158 +8,198 @@ $('[href="cart.php?gid=renewals"]').hide(); }; - $(document).ready(function () { - // Remove language code selection when not needed - $('#frmConfigureDomains').find('> .row > div:contains("Select Language Code")').parent().each(function() { - let self = $(this); - let domain = self.prevAll('.sub-heading').first().find('span').text(); - if (domain.match(/^([0-9a-z\-]+\.)+([a-z\-]+|xn--[a-z0-9\-]+)$/) && !domain.startsWith('xn--')) { - self.remove(); - } - }); - - let key = $('input[name="totalIPS"]').val(); - - $(document).on('click', '.delete-ns', function (e) { - e.preventDefault(); - - let self = this, host = $(self).attr('data-ns'); - - if (confirm("Do you want to delete host: " + host)) { - $(self).closest('li').find('.spinner').addClass('active'); - $.post(document.location.href, { - hostAction: "delete", - hostName: host - }, function (response) { - $(self).closest('li').remove(); - }); - } - }); - - $( ".remove-key-data" ).click(function(e) { - e.preventDefault(); - $(this).closest('tr').remove(); - }); - - $( ".add-keydata" ).click(function(e) { - e.preventDefault(); - let total = $(this).closest('form').find('input[name="totalDNSsec"]').val(); - - $(this).closest('form').find('input[name="totalDNSsec"]').val(parseInt(total) + 1); - - // Flags - let flags = $('').attr({ - name: 'algorithm[' + total + ']', - class: 'form-control' - }), algorithmsOptions = [ - {key: '1', text: '1 (RSA/MD5)'}, - {key: '3', text: '3 (DSA/SHA1)'}, - {key: '5', text: '5 (RSA/SHA-1)'}, - {key: '6', text: '6 (DSA-NSEC3-SHA1)'}, - {key: '7', text: '7 (RSASHA1-NSEC3-SHA1)'}, - {key: '8', text: '8 (RSA/SHA-256)'}, - {key: '10', text: '10 (RSA/SHA-512)'}, - {key: '12', text: '12 (GOST R 34.10-2001)'}, - {key: '13', text: '13 (ECDSA Curve P-256 with SHA-256)'}, - {key: '14', text: '14 (ECDSA Curve P-384 with SHA-384)'}, - {key: '15', text: '15 (Ed25519)'}, - {key: '16', text: '16 (Ed448)'}, - ]; - - for (let i = 0; i < algorithmsOptions.length; i++) { - algorithms.append($('