servnest/inc/ns.inc.php

61 lines
1.4 KiB
PHP
Raw Normal View History

2021-02-19 12:23:26 +00:00
<?php
if (strpos($_SERVER['PHP_SELF'], "inc.php") !== false)
exit("This file is meant to be included.");
2021-03-02 21:56:38 +00:00
function nsTtl($value, $multiplier) {
$ttl = $value * $multiplier;
if (!($ttl >= 300 AND $ttl <= 432000))
exit("Erreur : le TTL doit être compris entre 5 minutes et 5 jours (entre 300 et 432000 secondes)");
return $ttl;
}
function nsListUserZones($username) {
$db = new PDO('sqlite:' . DB_PATH);
$usernameArray[0] = $username;
$op = $db->prepare('SELECT zone FROM zones WHERE username = ?');
$op->execute($usernameArray);
$data = $op->fetch();
2021-05-14 19:10:56 +00:00
if (isset($data['zone']))
$zone = $data['zone'];
else
$zone = NULL;
$i = 0;
while ($zone != NULL) {
$zones[$i] = $zone;
$i++;
$data = $op->fetch();
if (isset($data['zone']))
$zone = $data['zone'];
else
$zone = NULL;
}
return $zones;
}
2021-03-02 21:56:38 +00:00
function nsCheckZonePossession($submittedZone) {
checkAbsoluteDomainFormat($submittedZone);
2021-02-19 12:23:26 +00:00
$db = new PDO('sqlite:' . DB_PATH);
$username[0] = $_SESSION['username'];
$op = $db->prepare('SELECT zone FROM zones WHERE username = ?');
$op->execute($username);
2021-03-02 21:56:38 +00:00
$dbZone = $op->fetch()['zone'];
2021-02-19 12:23:26 +00:00
2021-03-02 21:56:38 +00:00
while ($dbZone != NULL) {
if ($dbZone === $submittedZone) return;
$dbZone = $op->fetch()['zone'];
2021-02-19 12:23:26 +00:00
}
2021-03-02 21:56:38 +00:00
// If there is no entry in the database for the user matching the submitted zone
exit("ERROR: You don't own this zone on the nameserver");
2021-02-19 12:23:26 +00:00
}