2021-02-17 21:48:49 +00:00
|
|
|
<?php
|
|
|
|
|
2022-11-20 17:17:03 +00:00
|
|
|
define('SUBDOMAIN_REGEX', '^[a-z0-9]{4,63}$');
|
|
|
|
|
2021-02-18 21:40:16 +00:00
|
|
|
function regListUserDomains($username) {
|
2022-06-11 23:31:16 +00:00
|
|
|
return query('select', 'registry', ['username' => $username], 'domain');
|
2021-02-18 21:40:16 +00:00
|
|
|
}
|
|
|
|
|
2021-02-19 12:23:26 +00:00
|
|
|
function regCheckDomainPossession($domain) {
|
2022-06-15 13:30:18 +00:00
|
|
|
if (in_array($domain, regListUserDomains($_SESSION['username']), true) !== true)
|
2022-09-15 17:17:48 +00:00
|
|
|
output(403, 'You don\'t own this domain.');
|
2021-02-18 21:40:16 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 02:22:05 +00:00
|
|
|
function regDeleteDomain($domain) {
|
|
|
|
// Delete domain from registry file
|
|
|
|
$regFile = file_get_contents(CONF['reg']['registry_file']);
|
|
|
|
if ($regFile === false)
|
2022-09-15 17:17:48 +00:00
|
|
|
output(500, 'Failed to read current registry File.');
|
2022-11-20 17:17:03 +00:00
|
|
|
$regFile = preg_replace('/^(?:[a-z0-9._-]+\.)' . preg_quote($domain, '/') . '[\t ]+.+$/Dm', '', $regFile);
|
2022-06-18 02:22:05 +00:00
|
|
|
if (file_put_contents(CONF['reg']['registry_file'], $regFile) === false)
|
2022-09-15 17:17:48 +00:00
|
|
|
output(500, 'Failed to write new registry file.');
|
2022-06-18 02:22:05 +00:00
|
|
|
|
|
|
|
// Delete from Niver's database
|
|
|
|
query('delete', 'registry', [
|
|
|
|
'domain' => $domain,
|
|
|
|
'username' => $_SESSION['username'],
|
|
|
|
]);
|
|
|
|
}
|