diff --git a/ajax_license_checker/wt_license_checker.php b/ajax_license_checker/wt_license_checker.php new file mode 100644 index 00000000..cf74b68a --- /dev/null +++ b/ajax_license_checker/wt_license_checker.php @@ -0,0 +1,94 @@ +setHeader('Content-Type', 'application/json', true); + + // Get license key and domain from the request + $input = Factory::getApplication()->input; + $licenseKey = $input->getString('key', ''); + $domain = $input->getString('domain', ''); + + // Validate input + if (empty($licenseKey) || empty($domain)) { + echo json_encode(['error' => 'Missing license key or domain']); + return; + } + + // Query license key from the database + $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(); + + // If license key not found + if (!$result) { + echo json_encode(['error' => 'Invalid license key']); + return; + } + + $dateEnd = $result['date_end']; + $allowedPlugins = isset($result['allowed_plugins']) ? $result['allowed_plugins'] : '*'; + $registeredDomain = $result['domain']; + + // Validate domain + $isDomainValid = $this->isAllowedDomain($registeredDomain, $domain); + + // Check if license is still valid + $isValid = $isDomainValid && ($dateEnd == '0000-00-00 00:00:00' || strtotime($dateEnd) > time()); + + // 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' => $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); + return; + } + + /** + * Check if current domain is allowed (supports subdomains) + */ + private function isAllowedDomain($registeredDomain, $currentDomain) + { + if (empty($registeredDomain)) { + return false; + } + + $registeredDomain = parse_url('http://' . $registeredDomain, PHP_URL_HOST); + $currentDomain = parse_url('http://' . $currentDomain, PHP_URL_HOST); + + if ($registeredDomain === $currentDomain) { + return true; + } + + 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 + + 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 + + + + 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..cf76df82 --- /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); ?> + + + + + +
+
+ + +
+ + + +
+ +
+
+ +
+
+ +
+ +