2023-07-17 19:15:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2022-12-20 20:17:03 +00:00
|
|
|
|
2023-01-23 00:14:59 +00:00
|
|
|
if (preg_match('/' . SUBDOMAIN_REGEX . '/D', $_POST['subdomain']) !== 1)
|
|
|
|
output(403, _('This format of subdomain is not allowed.'));
|
2022-12-20 20:17:03 +00:00
|
|
|
|
2023-01-23 00:14:59 +00:00
|
|
|
if (array_key_exists($_POST['suffix'], CONF['reg']['suffixes']) !== true)
|
|
|
|
output(403, 'This suffix doesn\'t exist.');
|
|
|
|
|
|
|
|
$domain = formatAbsoluteDomain($_POST['subdomain'] . '.' . $_POST['suffix']);
|
2022-12-20 20:17:03 +00:00
|
|
|
|
2023-10-07 22:50:48 +00:00
|
|
|
if (query('select', 'registry', ['username' => $_SESSION['id'], 'domain' => $domain], ['domain']) !== [])
|
2023-01-21 00:27:52 +00:00
|
|
|
output(403, _('The current account already owns this domain.'));
|
2022-12-20 20:17:03 +00:00
|
|
|
|
2023-08-13 16:52:34 +00:00
|
|
|
$ns_records = array_column(kdig(name: $domain, type: 'NS', server: CONF['reg']['address'])['authorityRRs'], 'rdataNS');
|
|
|
|
if (preg_match('/^(?<salt>[0-9a-f]{8})-(?<hash>[0-9a-f]{32})\._transfer-verification\.' . preg_quote(SERVER_NAME, '/') . '\.$/Dm', implode(LF, $ns_records), $matches) !== 1)
|
2023-01-21 00:27:52 +00:00
|
|
|
output(403, _('NS authentication record not found.'));
|
2022-12-20 20:17:03 +00:00
|
|
|
|
|
|
|
checkAuthToken($matches['salt'], $matches['hash']);
|
|
|
|
|
2023-04-28 13:39:05 +00:00
|
|
|
rateLimit();
|
|
|
|
|
2022-12-20 20:17:03 +00:00
|
|
|
DB->prepare('UPDATE registry SET username = :username WHERE domain = :domain')
|
|
|
|
->execute([':username' => $_SESSION['id'], ':domain' => $domain]);
|
|
|
|
|
2023-01-23 00:14:59 +00:00
|
|
|
knotcZoneExec($_POST['suffix'], [
|
2022-12-20 20:17:03 +00:00
|
|
|
$domain,
|
|
|
|
'NS',
|
|
|
|
$matches['salt'] . '-' . $matches['hash'] . '._transfer-verification.' . SERVER_NAME . '.'
|
|
|
|
], 'delete');
|
|
|
|
|
2023-01-21 00:27:52 +00:00
|
|
|
output(200, _('The domain has been transferred to the current account ; the NS authentication record has been automatically deleted.'));
|