diff --git a/README.md b/README.md index d7e0db7..e79c663 100644 --- a/README.md +++ b/README.md @@ -172,8 +172,8 @@ From your server: ```bash cd /tmp -wget https://github.com/moddengine/whmcs-dns/releases/download/v3.1.0/whmcs-dns-3.1.0.zip -unzip whmcs-dns-3.1.0.zip +wget https://github.com/moddengine/whmcs-dns/releases/download/v3.1.1/whmcs-dns-3.1.1.zip +unzip whmcs-dns-3.1.1.zip cp -a whmcs_dns /path/to/whmcs/modules/addons/ ``` diff --git a/whmcs_dns/hooks.php b/whmcs_dns/hooks.php index 4f3301a..fa51a5d 100644 --- a/whmcs_dns/hooks.php +++ b/whmcs_dns/hooks.php @@ -18,7 +18,8 @@ if (file_exists($autoload)) { require_once $autoload; } -require_once __DIR__ . '/whmcs_dns.php'; +require_once __DIR__ . '/permissions.php'; +require_once __DIR__ . '/api-keys.php'; add_hook('DailyCronJob', 1, function (): void { whmcs_dns_cleanup_expired_api_keys(); diff --git a/whmcs_dns/permissions.php b/whmcs_dns/permissions.php index 69cdff9..79cd739 100644 --- a/whmcs_dns/permissions.php +++ b/whmcs_dns/permissions.php @@ -8,6 +8,37 @@ use WHMCS\Database\Capsule; use WHMCS\Module\Addon\Setting; +function whmcs_dns_admin_manage_token(string $itemType, int $itemId): string +{ + $now = time(); + $tokens = is_array($_SESSION['whmcs_dns_admin_manage_tokens'] ?? null) + ? $_SESSION['whmcs_dns_admin_manage_tokens'] + : []; + $tokens = array_filter( + $tokens, + static fn (mixed $details): bool => is_array($details) && ($details['expires'] ?? 0) > $now + ); + $token = bin2hex(random_bytes(32)); + $tokens[$token] = ['item_type' => $itemType, 'item_id' => $itemId, 'expires' => $now + 300]; + $_SESSION['whmcs_dns_admin_manage_tokens'] = $tokens; + return $token; +} + +function whmcs_dns_admin_manage_token_valid(string $token, string $itemType, int $itemId): bool +{ + $tokens = is_array($_SESSION['whmcs_dns_admin_manage_tokens'] ?? null) + ? $_SESSION['whmcs_dns_admin_manage_tokens'] + : []; + $details = $tokens[$token] ?? null; + unset($tokens[$token]); + $_SESSION['whmcs_dns_admin_manage_tokens'] = $tokens; + + return is_array($details) + && ($details['expires'] ?? 0) > time() + && ($details['item_type'] ?? null) === $itemType + && ($details['item_id'] ?? null) === $itemId; +} + function whmcs_dns_manage_dns_button_enabled(string $itemType, ?string $location = null): bool { $location ??= (string) (Setting::getSettingValueForModule( diff --git a/whmcs_dns/whmcs.json b/whmcs_dns/whmcs.json index b12e1a1..46d72f3 100644 --- a/whmcs_dns/whmcs.json +++ b/whmcs_dns/whmcs.json @@ -3,7 +3,7 @@ "type": "addon", "name": "whmcs_dns", "displayName": "DNS hosting module", - "version": "3.1.0", + "version": "3.1.1", "license": "MIT", "author": { "name": "Namingo", diff --git a/whmcs_dns/whmcs_dns.php b/whmcs_dns/whmcs_dns.php index e3279c9..827faf6 100644 --- a/whmcs_dns/whmcs_dns.php +++ b/whmcs_dns/whmcs_dns.php @@ -32,37 +32,6 @@ require_once __DIR__ . '/permissions.php'; require_once __DIR__ . '/api-keys.php'; -function whmcs_dns_admin_manage_token(string $itemType, int $itemId): string -{ - $now = time(); - $tokens = is_array($_SESSION['whmcs_dns_admin_manage_tokens'] ?? null) - ? $_SESSION['whmcs_dns_admin_manage_tokens'] - : []; - $tokens = array_filter( - $tokens, - static fn (mixed $details): bool => is_array($details) && ($details['expires'] ?? 0) > $now - ); - $token = bin2hex(random_bytes(32)); - $tokens[$token] = ['item_type' => $itemType, 'item_id' => $itemId, 'expires' => $now + 300]; - $_SESSION['whmcs_dns_admin_manage_tokens'] = $tokens; - return $token; -} - -function whmcs_dns_admin_manage_token_valid(string $token, string $itemType, int $itemId): bool -{ - $tokens = is_array($_SESSION['whmcs_dns_admin_manage_tokens'] ?? null) - ? $_SESSION['whmcs_dns_admin_manage_tokens'] - : []; - $details = $tokens[$token] ?? null; - unset($tokens[$token]); - $_SESSION['whmcs_dns_admin_manage_tokens'] = $tokens; - - return is_array($details) - && ($details['expires'] ?? 0) > time() - && ($details['item_type'] ?? null) === $itemType - && ($details['item_id'] ?? null) === $itemId; -} - /** * Addon module config * @@ -75,7 +44,7 @@ function whmcs_dns_config(): array 'description' => 'DNS management addon enabling zone and record control via external providers', 'author' => 'Namingo', 'language' => 'english', - 'version' => '3.1.0', + 'version' => '3.1.1', 'fields' => [ 'provider' => [ 'FriendlyName' => 'Provider',