2021-02-17 22:48:49 +01:00
|
|
|
<?php
|
|
|
|
|
2022-11-30 23:12:42 +01:00
|
|
|
const SUBDOMAIN_REGEX = '^[a-z0-9]{4,63}$';
|
2022-11-20 18:17:03 +01:00
|
|
|
|
2022-12-20 21:17:03 +01:00
|
|
|
function regListUserDomains() {
|
|
|
|
if (isset($_SESSION['id']))
|
|
|
|
return query('select', 'registry', ['username' => $_SESSION['id']], 'domain');
|
|
|
|
return [];
|
2021-02-18 22:40:16 +01:00
|
|
|
}
|
|
|
|
|
2021-02-19 13:23:26 +01:00
|
|
|
function regCheckDomainPossession($domain) {
|
2022-12-20 21:17:03 +01:00
|
|
|
if (in_array($domain, regListUserDomains(), true) !== true)
|
2023-01-21 01:27:52 +01:00
|
|
|
output(403, 'You don\'t own this domain on the registry.');
|
2021-02-18 22:40:16 +01:00
|
|
|
}
|
|
|
|
|
2022-06-18 04:22:05 +02:00
|
|
|
function regDeleteDomain($domain) {
|
|
|
|
// Delete domain from registry file
|
2023-01-23 01:14:59 +01:00
|
|
|
$path = CONF['reg']['suffixes_path'] . '/' . regParseDomain($domain)['suffix'] . 'zone';
|
|
|
|
$content = file_get_contents($path);
|
|
|
|
if ($content === false)
|
|
|
|
output(500, 'Failed to read current registry file.');
|
2023-01-23 01:42:18 +01:00
|
|
|
$content = preg_replace('/^(?:[a-z0-9._-]+\.)?' . preg_quote($domain, '/') . '[\t ]+.+$/Dm', '', $content);
|
2023-01-23 01:14:59 +01:00
|
|
|
if (file_put_contents($path, $content) === false)
|
2022-09-15 19:17:48 +02:00
|
|
|
output(500, 'Failed to write new registry file.');
|
2022-06-18 04:22:05 +02:00
|
|
|
|
2023-01-29 21:09:00 +01:00
|
|
|
// Delete from database
|
2022-06-18 04:22:05 +02:00
|
|
|
query('delete', 'registry', [
|
|
|
|
'domain' => $domain,
|
2022-11-30 23:12:42 +01:00
|
|
|
'username' => $_SESSION['id'],
|
2022-06-18 04:22:05 +02:00
|
|
|
]);
|
|
|
|
}
|
2023-01-23 01:14:59 +01:00
|
|
|
|
|
|
|
function regParseDomain($domain) {
|
|
|
|
$parts = explode('.', $domain, 2);
|
|
|
|
$subdomain = $parts[0];
|
|
|
|
$suffix = $parts[1];
|
|
|
|
|
|
|
|
if (array_key_exists($suffix, CONF['reg']['suffixes']) !== true)
|
|
|
|
output(403, 'This suffix doesn\'t exist.');
|
|
|
|
|
|
|
|
return [
|
|
|
|
'subdomain' => $subdomain,
|
|
|
|
'suffix' => $suffix,
|
|
|
|
];
|
|
|
|
}
|