servnest/reg.php

87 lines
1.6 KiB
PHP
Raw Normal View History

2021-02-17 21:48:49 +00:00
<?php
2022-04-22 23:57:43 +00:00
require "dns.php";
define("SUBDOMAIN_REGEX", "^[a-z]{4,63}$");
define("REGISTRY", "niver.test.");
define("SUFFIXES", array(
REGISTRY,
));
function regGetUpperDomain($domain) {
2022-04-18 14:05:00 +00:00
// Remove anything before the first dot and the first dot itself
return preg_replace("/^[^.]+\./", "", $domain);
2021-02-19 12:23:26 +00:00
}
2021-02-18 21:40:16 +00:00
function regListUserDomains($username) {
2022-04-18 14:05:00 +00:00
$db = new PDO('sqlite:' . DB_PATH);
$usernameArray[0] = $username;
2021-02-18 21:40:16 +00:00
2022-04-18 14:05:00 +00:00
$op = $db->prepare('SELECT domain FROM registry WHERE username = ?');
$op->execute($usernameArray);
2021-02-18 21:40:16 +00:00
2022-04-18 14:05:00 +00:00
$domains = false;
$i = 0;
$data = $op->fetch();
$domain = $data['domain'];
2021-02-18 21:40:16 +00:00
2022-04-18 14:05:00 +00:00
while ($domain != NULL) {
$domains[$i] = $domain;
2021-02-18 21:40:16 +00:00
2022-04-18 14:05:00 +00:00
$data = $op->fetch();
if (isset($data['domain']))
$domain = $data['domain'];
else
$domain = NULL;
2022-04-18 14:05:00 +00:00
$i++;
}
2021-02-18 21:40:16 +00:00
2022-04-18 14:05:00 +00:00
return $domains;
2021-02-18 21:40:16 +00:00
}
2021-02-19 12:23:26 +00:00
function regCheckDomainPossession($domain) {
2022-04-18 14:05:00 +00:00
checkAbsoluteDomainFormat($domain);
2021-02-18 21:40:16 +00:00
2022-04-18 14:05:00 +00:00
$db = new PDO('sqlite:' . DB_PATH);
$username[0] = $_SESSION['username'];
2021-02-18 21:40:16 +00:00
2022-04-18 14:05:00 +00:00
$op = $db->prepare('SELECT domain FROM registry WHERE username = ?');
$op->execute($username);
2021-02-18 21:40:16 +00:00
2022-04-18 14:05:00 +00:00
$dbDomain = $op->fetch()['domain'];
2021-02-18 21:40:16 +00:00
2022-04-18 14:05:00 +00:00
$owned = false;
while ($dbDomain != NULL) {
if ($dbDomain === $domain) {
$owned = true;
break;
}
$dbDomain = $op->fetch()['domain'];
}
2021-02-18 21:40:16 +00:00
2022-04-18 14:05:00 +00:00
if (!($owned === true))
exit("Erreur : Vous ne possédez pas ce domaine sur le registre !");
2021-02-18 21:40:16 +00:00
}
2021-02-19 12:23:26 +00:00
function regIsFree($domain) {
2021-02-17 21:48:49 +00:00
2022-04-18 14:05:00 +00:00
$domainArray[0] = $domain;
2021-02-17 21:48:49 +00:00
2022-04-18 14:05:00 +00:00
$db = new PDO('sqlite:' . DB_PATH);
2021-02-17 21:48:49 +00:00
2022-04-18 14:05:00 +00:00
$req = $db->prepare('SELECT domain FROM registry WHERE domain = ?');
$req->execute($domainArray);
2021-02-17 21:48:49 +00:00
2022-04-18 14:05:00 +00:00
$data = $req->fetch();
2021-02-17 21:48:49 +00:00
2022-04-18 14:05:00 +00:00
if (isset($data['domain'])) {
return false;
} else {
return true;
}
2021-02-17 21:48:49 +00:00
}