6dbc63a36a
Move service-specific deletion code to functions
30 lines
982 B
PHP
30 lines
982 B
PHP
<?php
|
|
|
|
function regListUserDomains($username) {
|
|
return query('select', 'registry', ['username' => $username], 'domain');
|
|
}
|
|
|
|
function regCheckDomainPossession($domain) {
|
|
if (in_array($domain, regListUserDomains($_SESSION['username']), true) !== true)
|
|
userError("You don't own this domain.");
|
|
}
|
|
|
|
function regIsFree($domain) {
|
|
return empty(query('select', 'registry', ['domain' => $domain], 'domain'));
|
|
}
|
|
|
|
function regDeleteDomain($domain) {
|
|
// Delete domain from registry file
|
|
$regFile = file_get_contents(CONF['reg']['registry_file']);
|
|
if ($regFile === false)
|
|
serverError("Failed to read current registry File.");
|
|
$regFile = preg_replace("#[^\n]{0,1024}" . $domain . " {0,1024}[^\n]{0,1024}\n#", "", $regFile);
|
|
if (file_put_contents(CONF['reg']['registry_file'], $regFile) === false)
|
|
serverError("Failed to write new registry file.");
|
|
|
|
// Delete from Niver's database
|
|
query('delete', 'registry', [
|
|
'domain' => $domain,
|
|
'username' => $_SESSION['username'],
|
|
]);
|
|
}
|