servnest/fn/reg.php

49 lines
1.0 KiB
PHP
Raw Normal View History

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