From a3e23ae52933a3294c055eca32ea9a4b4206cf5c Mon Sep 17 00:00:00 2001 From: Nikolaos Date: Thu, 15 May 2025 10:01:53 +0300 Subject: [PATCH 1/5] Added system plugin save_domain to store domain in #__swjprojects_keys --- plugins/system/save_domain/index.html | 1 + plugins/system/save_domain/save_domain.php | 37 ++++++++++++++++++++++ plugins/system/save_domain/save_domain.xml | 12 +++++++ 3 files changed, 50 insertions(+) create mode 100644 plugins/system/save_domain/index.html create mode 100644 plugins/system/save_domain/save_domain.php create mode 100644 plugins/system/save_domain/save_domain.xml diff --git a/plugins/system/save_domain/index.html b/plugins/system/save_domain/index.html new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/plugins/system/save_domain/index.html @@ -0,0 +1 @@ + diff --git a/plugins/system/save_domain/save_domain.php b/plugins/system/save_domain/save_domain.php new file mode 100644 index 00000000..ba9773c3 --- /dev/null +++ b/plugins/system/save_domain/save_domain.php @@ -0,0 +1,37 @@ +input; + $json = json_decode(file_get_contents('php://input')); + + if (!isset($json->key_id) || !isset($json->domain)) { + return json_encode(['success' => false, 'message' => 'Missing parameters']); + } + + // Debug log + file_put_contents(JPATH_SITE . '/logs/save_domain_log.txt', "Key ID: {$json->key_id}, Domain: {$json->domain}\n", FILE_APPEND); + + $db = Factory::getDbo(); + $query = $db->getQuery(true) + ->update($db->quoteName('#__swjprojects_keys')) + ->set($db->quoteName('domain') . ' = ' . $db->quote($json->domain)) + ->where($db->quoteName('id') . ' = ' . (int) $json->key_id); + + $db->setQuery($query); + + try { + $db->execute(); + return json_encode(['success' => true, 'message' => 'Domain saved successfully']); + } catch (Exception $e) { + return json_encode(['success' => false, 'message' => $e->getMessage()]); + } + } +} diff --git a/plugins/system/save_domain/save_domain.xml b/plugins/system/save_domain/save_domain.xml new file mode 100644 index 00000000..188ba31d --- /dev/null +++ b/plugins/system/save_domain/save_domain.xml @@ -0,0 +1,12 @@ + + + System - Save Domain + Nick Giannelis + 1.0.0 + Plugin to save domain for user keys + + save_domain.php + + + + From 57626c8c23679516a17fc967e53af69f6f06fb3e Mon Sep 17 00:00:00 2001 From: Nikolaos Date: Thu, 15 May 2025 10:37:15 +0300 Subject: [PATCH 2/5] Added template override example for domain input field --- .../html/com_swjprojects/userkeys/default.php | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 template_override_example/templates/cassiopeia/html/com_swjprojects/userkeys/default.php diff --git a/template_override_example/templates/cassiopeia/html/com_swjprojects/userkeys/default.php b/template_override_example/templates/cassiopeia/html/com_swjprojects/userkeys/default.php new file mode 100644 index 00000000..c13795eb --- /dev/null +++ b/template_override_example/templates/cassiopeia/html/com_swjprojects/userkeys/default.php @@ -0,0 +1,119 @@ +getDocument()->getWebAssetManager(); +$wa->registerAndUseScript('com_swjprojects.userkeys.copykey', 'com_swjprojects/copy-userkey.js', ['version' => 'auto', 'relative' => true]); + +?> +
+

+ items)) : ?> +
+ + + +
+ +
+
+ items as $item) : + $downloadAble = ($item->limit && $item->limit_count == 0) ? false : true; + $date_expired = ((new Date())->toUnix() > (new Date($item->date_end))->toUnix()) ? false : true; + if (!$date_expired) $downloadAble = false; + ?> +
+
+
+
+ + + + + + key); ?> + + + + + +
+
+ + +
+ + + +
+ +
+
+ +
+
+ +
+ + From fca7f55a2aab80dc14893858ffd280ee90325f52 Mon Sep 17 00:00:00 2001 From: Nikolaos Date: Thu, 15 May 2025 11:13:34 +0300 Subject: [PATCH 3/5] Add basic AJAX license checker plugin for validating keys --- ajax_license_checker/wt_license_checker.php | 107 ++++++++++++++++++++ ajax_license_checker/wt_license_checker.xml | 11 ++ 2 files changed, 118 insertions(+) create mode 100644 ajax_license_checker/wt_license_checker.php create mode 100644 ajax_license_checker/wt_license_checker.xml diff --git a/ajax_license_checker/wt_license_checker.php b/ajax_license_checker/wt_license_checker.php new file mode 100644 index 00000000..b1ddeb7e --- /dev/null +++ b/ajax_license_checker/wt_license_checker.php @@ -0,0 +1,107 @@ + setHeader('Content-Type', 'application/json', true); + + // Pairnoume to License Key kai to Domain apo to request + $input = Factory::getApplication()->input; + $licenseKey = $input->getString('key', ''); + $domain = $input->getString('domain', ''); + + // An den yparxei license key 'h domain, epistrefoume error + if (empty($licenseKey) || empty($domain)) { + echo json_encode(['error' => 'Missing license key or domain']); + return; + } + + // Sindesi me thn vash dedomenwn + $db = Factory::getContainer()->get(DatabaseDriver::class); + $query = $db->getQuery(true) + ->select('*') + ->from($db->quoteName('#__swjprojects_keys')) + ->where($db->quoteName('key') . ' = ' . $db->quote($licenseKey)); + $db->setQuery($query); + $result = $db->loadAssoc(); + + // An den yparxei to kleidi, epistrefoume error + if (!$result) { + echo json_encode(['error' => 'Invalid license key']); + return; + } + + $dateEnd = $result['date_end']; + + // Epitrepomena plugins + $allowedPlugins = isset($result['allowed_plugins']) ? $result['allowed_plugins'] : '*'; + + // Kataxwrimeno domain sth vash + $registeredDomain = $result['domain']; + + // Elegxos an to trexon domain einai epitrepto + $isDomainValid = $this->isAllowedDomain($registeredDomain, $domain); + + // An to domain den tairiazei , h adeia den einai egkyrh + if (!$isDomainValid) { + $isValid = false; + } else { + // An to domain tairiazei, elegxoume thn hmeromhnia lhkshs ths adeias + $isValid = ($dateEnd == '0000-00-00 00:00:00' || strtotime($dateEnd) > time()); + } + + // Dhmiourgia apanthshs JSON + $data = [ + 'domain' => $registeredDomain, + 'date_start' => $result['date_start'], + 'date_end' => $result['date_end'], + 'project_id' => $result['project_id'], + 'state' => $result['state'], + 'license_name' => 'Lifetime', + 'expires' => ($isValid ? 'never' : $result['date_end']), + 'key_status' => ($isValid ? 'Active' : 'Expired'), + 'owner' => 'Theodoropoulos', + 'license_valid' => ($isValid ? '1' : '0'), + 'allows_plugins' => ($isValid ? '1' : '0'), + 'is_trial_license'=> '0', + 'allowed_plugins' => ($isValid ? $allowedPlugins : '') // An h adeia exei lhksei, kenh lista plugins + ]; + + echo json_encode($data); + return; + } + + /** + * Elegxei an to domain (mazi me subdomains) epitrepetai + */ + private function isAllowedDomain($registeredDomain, $currentDomain) + { + // An den yparxei kataxwrimeno domain, epistrefoume false + if (empty($registeredDomain)) { + return false; + } + + // Metatrepoume to domain se kathari morfh (xwris http/https) + $registeredDomain = parse_url('http://' . $registeredDomain, PHP_URL_HOST); + $currentDomain = parse_url('http://' . $currentDomain, PHP_URL_HOST); + + // An einai akrivws to idio, epitrepetai + if ($registeredDomain === $currentDomain) { + return true; + } + + // An to currentDomain einai subdomain tou registeredDomain, epitrepetai + if (str_ends_with($currentDomain, '.' . $registeredDomain)) { + return true; + } + + return false; + } +} diff --git a/ajax_license_checker/wt_license_checker.xml b/ajax_license_checker/wt_license_checker.xml new file mode 100644 index 00000000..4c8d67e8 --- /dev/null +++ b/ajax_license_checker/wt_license_checker.xml @@ -0,0 +1,11 @@ + + + WT License Checker + Nick Giannelis + 1.0.0 + March 2025 + AJAX plugin for checking license keys in SW JProjects + + wt_license_checker.php + + From 3633cc895fbabb19401696e27a4fdb5706575461 Mon Sep 17 00:00:00 2001 From: Nick Giannelis Date: Thu, 15 May 2025 13:11:00 +0300 Subject: [PATCH 4/5] Update wt_license_checker.php --- ajax_license_checker/wt_license_checker.php | 59 ++++++++------------- 1 file changed, 23 insertions(+), 36 deletions(-) diff --git a/ajax_license_checker/wt_license_checker.php b/ajax_license_checker/wt_license_checker.php index b1ddeb7e..cf74b68a 100644 --- a/ajax_license_checker/wt_license_checker.php +++ b/ajax_license_checker/wt_license_checker.php @@ -1,4 +1,4 @@ - setHeader('Content-Type', 'application/json', true); - // Pairnoume to License Key kai to Domain apo to request + // Get license key and domain from the request $input = Factory::getApplication()->input; $licenseKey = $input->getString('key', ''); $domain = $input->getString('domain', ''); - // An den yparxei license key 'h domain, epistrefoume error + // Validate input if (empty($licenseKey) || empty($domain)) { echo json_encode(['error' => 'Missing license key or domain']); return; } - // Sindesi me thn vash dedomenwn + // Query license key from the database $db = Factory::getContainer()->get(DatabaseDriver::class); $query = $db->getQuery(true) ->select('*') @@ -32,46 +32,37 @@ public function onAjaxWt_license_checker() $db->setQuery($query); $result = $db->loadAssoc(); - // An den yparxei to kleidi, epistrefoume error + // If license key not found if (!$result) { echo json_encode(['error' => 'Invalid license key']); return; } $dateEnd = $result['date_end']; - - // Epitrepomena plugins $allowedPlugins = isset($result['allowed_plugins']) ? $result['allowed_plugins'] : '*'; - - // Kataxwrimeno domain sth vash $registeredDomain = $result['domain']; - // Elegxos an to trexon domain einai epitrepto + // Validate domain $isDomainValid = $this->isAllowedDomain($registeredDomain, $domain); - // An to domain den tairiazei , h adeia den einai egkyrh - if (!$isDomainValid) { - $isValid = false; - } else { - // An to domain tairiazei, elegxoume thn hmeromhnia lhkshs ths adeias - $isValid = ($dateEnd == '0000-00-00 00:00:00' || strtotime($dateEnd) > time()); - } + // Check if license is still valid + $isValid = $isDomainValid && ($dateEnd == '0000-00-00 00:00:00' || strtotime($dateEnd) > time()); - // Dhmiourgia apanthshs JSON + // Prepare response (fix it as you want) $data = [ - 'domain' => $registeredDomain, - 'date_start' => $result['date_start'], - 'date_end' => $result['date_end'], - 'project_id' => $result['project_id'], - 'state' => $result['state'], - 'license_name' => 'Lifetime', - 'expires' => ($isValid ? 'never' : $result['date_end']), - 'key_status' => ($isValid ? 'Active' : 'Expired'), - 'owner' => 'Theodoropoulos', - 'license_valid' => ($isValid ? '1' : '0'), - 'allows_plugins' => ($isValid ? '1' : '0'), - 'is_trial_license'=> '0', - 'allowed_plugins' => ($isValid ? $allowedPlugins : '') // An h adeia exei lhksei, kenh lista plugins + 'domain' => $registeredDomain, + 'date_start' => $result['date_start'], + 'date_end' => $result['date_end'], + 'project_id' => $result['project_id'], + 'state' => $result['state'], + 'license_name' => $result['license_name'] ?? 'Standard', + 'expires' => ($isValid ? 'never' : $result['date_end']), + 'key_status' => ($isValid ? 'Active' : 'Expired'), + 'owner' => $result['owner'] ?? 'N/A', + 'license_valid' => ($isValid ? '1' : '0'), + 'allows_plugins' => ($isValid ? '1' : '0'), + 'is_trial_license' => $result['is_trial_license'] ?? '0', + 'allowed_plugins' => ($isValid ? $allowedPlugins : '') ]; echo json_encode($data); @@ -79,25 +70,21 @@ public function onAjaxWt_license_checker() } /** - * Elegxei an to domain (mazi me subdomains) epitrepetai + * Check if current domain is allowed (supports subdomains) */ private function isAllowedDomain($registeredDomain, $currentDomain) { - // An den yparxei kataxwrimeno domain, epistrefoume false if (empty($registeredDomain)) { return false; } - // Metatrepoume to domain se kathari morfh (xwris http/https) $registeredDomain = parse_url('http://' . $registeredDomain, PHP_URL_HOST); $currentDomain = parse_url('http://' . $currentDomain, PHP_URL_HOST); - // An einai akrivws to idio, epitrepetai if ($registeredDomain === $currentDomain) { return true; } - // An to currentDomain einai subdomain tou registeredDomain, epitrepetai if (str_ends_with($currentDomain, '.' . $registeredDomain)) { return true; } From 30a7c1683e917275c346ecd385c2e0bc25787548 Mon Sep 17 00:00:00 2001 From: Nick Giannelis Date: Thu, 15 May 2025 13:13:09 +0300 Subject: [PATCH 5/5] Update default.php --- .../cassiopeia/html/com_swjprojects/userkeys/default.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template_override_example/templates/cassiopeia/html/com_swjprojects/userkeys/default.php b/template_override_example/templates/cassiopeia/html/com_swjprojects/userkeys/default.php index c13795eb..cf76df82 100644 --- a/template_override_example/templates/cassiopeia/html/com_swjprojects/userkeys/default.php +++ b/template_override_example/templates/cassiopeia/html/com_swjprojects/userkeys/default.php @@ -61,7 +61,7 @@ - +