84 lines
1.6 KiB
PHP
84 lines
1.6 KiB
PHP
<?php
|
|
|
|
define("SUBDOMAIN_REGEX", "^[a-z]{4,63}$");
|
|
|
|
define("REGISTRY", "niver.test.");
|
|
|
|
define("SUFFIXES", array(
|
|
REGISTRY,
|
|
));
|
|
|
|
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 = false;
|
|
$i = 0;
|
|
$data = $op->fetch();
|
|
$domain = $data['domain'];
|
|
|
|
while ($domain != NULL) {
|
|
$domains[$i] = $domain;
|
|
|
|
$data = $op->fetch();
|
|
if (isset($data['domain']))
|
|
$domain = $data['domain'];
|
|
else
|
|
$domain = NULL;
|
|
|
|
$i++;
|
|
}
|
|
|
|
return $domains;
|
|
}
|
|
|
|
function regCheckDomainPossession($domain) {
|
|
checkAbsoluteDomainFormat($domain);
|
|
|
|
$db = new PDO('sqlite:' . DB_PATH);
|
|
$username[0] = $_SESSION['username'];
|
|
|
|
$op = $db->prepare('SELECT domain FROM registry WHERE username = ?');
|
|
$op->execute($username);
|
|
|
|
$dbDomain = $op->fetch()['domain'];
|
|
|
|
$owned = false;
|
|
while ($dbDomain != NULL) {
|
|
if ($dbDomain === $domain) {
|
|
$owned = true;
|
|
break;
|
|
}
|
|
$dbDomain = $op->fetch()['domain'];
|
|
}
|
|
|
|
if (!($owned === true))
|
|
exit("Erreur : Vous ne possédez pas ce domaine sur le registre !");
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
}
|