29 lines
918 B
PHP
29 lines
918 B
PHP
<?php
|
|
|
|
const SUBDOMAIN_REGEX = '^[a-z0-9]{4,63}$';
|
|
|
|
function regListUserDomains($username) {
|
|
return query('select', 'registry', ['username' => $username], 'domain');
|
|
}
|
|
|
|
function regCheckDomainPossession($domain) {
|
|
if (in_array($domain, regListUserDomains($_SESSION['id']), true) !== true)
|
|
output(403, 'You don\'t own this domain.');
|
|
}
|
|
|
|
function regDeleteDomain($domain) {
|
|
// Delete domain from registry file
|
|
$regFile = file_get_contents(CONF['reg']['registry_file']);
|
|
if ($regFile === false)
|
|
output(500, 'Failed to read current registry File.');
|
|
$regFile = preg_replace('/^(?:[a-z0-9._-]+\.)' . preg_quote($domain, '/') . '[\t ]+.+$/Dm', '', $regFile);
|
|
if (file_put_contents(CONF['reg']['registry_file'], $regFile) === false)
|
|
output(500, 'Failed to write new registry file.');
|
|
|
|
// Delete from Niver's database
|
|
query('delete', 'registry', [
|
|
'domain' => $domain,
|
|
'username' => $_SESSION['id'],
|
|
]);
|
|
}
|