Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/
```

Expand Down
3 changes: 2 additions & 1 deletion whmcs_dns/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
31 changes: 31 additions & 0 deletions whmcs_dns/permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion whmcs_dns/whmcs.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
33 changes: 1 addition & 32 deletions whmcs_dns/whmcs_dns.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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',
Expand Down
Loading