72 lines
2.7 KiB
PHP
72 lines
2.7 KiB
PHP
<?php
|
|
|
|
if (preg_match('/' . SUBDOMAIN_REGEX . '/D', $_POST['subdomain']) !== 1)
|
|
output(403, _('This format of subdomain is not allowed.'));
|
|
|
|
if (array_key_exists($_POST['suffix'], CONF['reg']['suffixes']) !== true)
|
|
output(403, 'This suffix doesn\'t exist.');
|
|
|
|
match (CONF['reg']['suffixes'][$_POST['suffix']]) {
|
|
'all' => NULL,
|
|
'approved' => match ($_SESSION['type']) {
|
|
'approved' => NULL,
|
|
default => output(403, 'The current account type is not allowed to register in this suffix.'),
|
|
},
|
|
default => output(403, 'This suffix is not open to registration.'),
|
|
};
|
|
|
|
$domain = formatAbsoluteDomain($_POST['subdomain'] . '.' . $_POST['suffix']);
|
|
|
|
if (in_array($_POST['subdomain'], explode(LF, file_get_contents(ROOT_PATH . '/pg-act/reg/reserved.txt')), true))
|
|
message('❌ ' . _('This domain is reserved.'));
|
|
|
|
$message = '<ul>';
|
|
$blocked = false;
|
|
foreach (query('select', 'registry-history', ['domain' => $domain]) as $data) {
|
|
$creation = DateTimeImmutable::createFromFormat('Y-m', $data['creation']);
|
|
$expiration = DateTimeImmutable::createFromFormat('Y-m', $data['expiration']);
|
|
|
|
$registration_duration = intval(round($creation->diff($expiration)->format('%a') / 30.4375));
|
|
$expected_expiration_duration = min(intval($registration_duration * 0.5) + 12, 12*8);
|
|
|
|
$new_registration_date = $expiration->add(new DateInterval('P' . $expected_expiration_duration . 'M'));
|
|
|
|
$message .= '<li>' . sprintf(_('This domain was registered from %s to %s.'), '<time>' . $data['creation'] . '</time>', '<time>' . $data['expiration'] . '</time>') . ' ';
|
|
|
|
if (new DateTimeImmutable('now', new DateTimeZone('UTC')) < $new_registration_date) {
|
|
$blocked = true;
|
|
$message .= sprintf(_('This blocks it until %s.'), '<time>' . $new_registration_date->format('Y-m') . '</time>') . ' ❌';
|
|
} else {
|
|
$message .= sprintf(_('This had blocked it until %s.'), '<time>' . $new_registration_date->format('Y-m') . '</time>');
|
|
}
|
|
$message .= '</li>';
|
|
}
|
|
$message .= '</ul>';
|
|
|
|
$registration_data = query('select', 'registry', ['domain' => $domain]);
|
|
if ($registration_data !== [])
|
|
$message .= sprintf(_('This domain is already registered, since %s.'), '<time>' . $registration_data[0]['creation'] . '</time>');
|
|
|
|
if ($blocked OR $registration_data !== [])
|
|
message($message);
|
|
|
|
if ($_POST['action'] !== 'register')
|
|
message($message . ' ✔️ ' . _('This domain is open to registration!'));
|
|
|
|
function message($message) {
|
|
output(200, data: [
|
|
'message' => '<p>' . $message . '</p>',
|
|
'domain' => htmlspecialchars($_POST['subdomain']),
|
|
]);
|
|
}
|
|
|
|
rateLimit();
|
|
|
|
insert('registry', [
|
|
'domain' => $domain,
|
|
'username' => $_SESSION['id'],
|
|
'creation' => date('Y-m'),
|
|
]);
|
|
|
|
output(200, _('Domain registered.'), ['message' => '<p>' . $message . '</p>']);
|