26 lines
1.2 KiB
PHP
26 lines
1.2 KiB
PHP
<?php
|
|
|
|
if (preg_match('/' . SUBDOMAIN_REGEX . '/D', $_POST['domain']) !== 1)
|
|
output(403, 'Le nom de domaine semble incorrect');
|
|
|
|
$domain = $_POST['domain'] . '.' . CONF['reg']['registry'];
|
|
|
|
if (query('select', 'registry', ['username' => $_SESSION['id'], 'domain' => $domain], 'domain') !== [])
|
|
output(403, 'Le compte présent possède déjà ce domaine.');
|
|
|
|
exec(CONF['dns']['kdig_path'] . ' ' . $domain . ' NS @' . CONF['reg']['address'] . ' +noidn', $results);
|
|
if (preg_match('/^' . preg_quote($domain, '/') . '[\t ]+[0-9]{1,8}[\t ]+IN[\t ]+NS[\t ]+(?<salt>[0-9a-f]{8})-(?<hash>[0-9a-f]{32})\._transfer-verification\.' . preg_quote(SERVER_NAME, '/') . '\.$/Dm', implode(LF, $results), $matches) !== 1)
|
|
output(403, 'Enregistrement d\'authentification introuvable');
|
|
|
|
checkAuthToken($matches['salt'], $matches['hash']);
|
|
|
|
DB->prepare('UPDATE registry SET username = :username WHERE domain = :domain')
|
|
->execute([':username' => $_SESSION['id'], ':domain' => $domain]);
|
|
|
|
knotcZoneExec(CONF['reg']['registry'], [
|
|
$domain,
|
|
'NS',
|
|
$matches['salt'] . '-' . $matches['hash'] . '._transfer-verification.' . SERVER_NAME . '.'
|
|
], 'delete');
|
|
|
|
output(200, 'Le domaine a été transféré vers le compte présent, l\'enregistrement d\'authentification a été automatiquement retiré.');
|