servnest/fn/reg.php
2022-05-31 19:12:14 +02:00

48 lines
1 KiB
PHP

<?php
function regGetUpperDomain($domain) {
// Remove anything before the first dot and the first dot itself
return preg_replace("/^[^.]+\./", "", $domain);
}
function regListUserDomains($username) {
$db = new PDO('sqlite:' . DB_PATH);
$usernameArray[0] = $username;
$op = $db->prepare('SELECT domain FROM registry WHERE username = ?');
$op->execute($usernameArray);
$domains = array();
foreach ($op->fetchAll() as $domain)
array_push($domains, $domain['domain']);
return $domains;
}
function regCheckDomainPossession($domain) {
checkAbsoluteDomainFormat($domain);
$ownedDomains = regListUserDomains($_SESSION['username']);
if (in_array($domain, $ownedDomains, true) !== true)
userError("You don't own this domain.");
}
function regIsFree($domain) {
$domainArray[0] = $domain;
$db = new PDO('sqlite:' . DB_PATH);
$req = $db->prepare('SELECT domain FROM registry WHERE domain = ?');
$req->execute($domainArray);
$data = $req->fetch();
if (isset($data['domain'])) {
return false;
} else {
return true;
}
}