servnest/pg-act/reg/register.php

48 lines
1.4 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']);
$registered = query('select', 'registry', ['domain' => $domain], 'domain') !== [];
$reserved = in_array($_POST['subdomain'], explode(LF, file_get_contents(ROOT_PATH . '/pg-act/reg/reserved.txt')));
$message = match ($registered) {
false => match ($reserved) {
false => match ($_POST['action']) {
'register' => NULL,
default => '✔️ ' . _('This domain is open to registration!'),
},
default => '❌ ' . _('This domain is reserved.'),
},
default => '❌ ' . _('This domain is already registered.'),
};
if ($message !== NULL)
output(200, data: [
'message' => '<p>' . $message . '</p>',
'domain' => htmlspecialchars($_POST['subdomain']),
]);
rateLimit();
insert('registry', [
'domain' => $domain,
'username' => $_SESSION['id'],
'last_renewal' => date('Y-m-d H:i:s'),
]);
output(200, _('Domain registered.'));