servnest/fn/ns.php

62 lines
1.6 KiB
PHP
Raw Normal View History

2021-02-19 13:23:26 +01:00
<?php
2021-05-16 16:55:39 +02:00
function nsCommonRequirements() {
return (isset($_POST['action'])
2022-04-18 16:05:00 +02:00
AND isset($_POST['zone'])
AND isset($_POST['ttl-value'])
AND isset($_POST['ttl-multiplier'])
AND isset($_SESSION['username'])
);
2021-05-16 16:55:39 +02:00
}
function nsParseCommonRequirements() {
2022-04-18 16:05:00 +02:00
nsCheckZonePossession($_POST['zone']);
2022-04-18 16:05:00 +02:00
if (($_POST['subdomain'] === "") OR ($_POST['subdomain'] === "@"))
$values['domain'] = $_POST['zone'];
else
$values['domain'] = $_POST['subdomain'] . "." . $_POST['zone'];
checkAbsoluteDomainFormat($values['domain']);
2021-05-16 16:55:39 +02:00
2022-04-18 16:05:00 +02:00
$values['ttl'] = $_POST['ttl-value'] * $_POST['ttl-multiplier'];
2021-03-02 22:56:38 +01:00
2022-04-18 16:05:00 +02:00
if (!($values['ttl'] >= 300 AND $values['ttl'] <= 432000))
userError("Le TTL doit être compris entre 5 minutes et 5 jours (entre 300 et 432000 secondes).");
2021-03-02 22:56:38 +01:00
2022-04-18 16:05:00 +02:00
return $values;
2021-03-02 22:56:38 +01:00
}
function nsListUserZones($username) {
2022-04-18 16:05:00 +02:00
$db = new PDO('sqlite:' . DB_PATH);
$usernameArray[0] = $username;
$op = $db->prepare('SELECT zone FROM zones WHERE username = ?');
$op->execute($usernameArray);
2022-05-25 01:16:41 +02:00
$zones = array();
foreach ($op->fetchAll() as $zone)
array_push($zones, $zone['zone']);
2022-04-18 16:05:00 +02:00
return $zones;
}
2021-03-02 22:56:38 +01:00
function nsCheckZonePossession($submittedZone) {
2022-04-18 16:05:00 +02:00
checkAbsoluteDomainFormat($submittedZone);
2021-02-19 13:23:26 +01:00
2022-04-18 16:05:00 +02:00
$db = new PDO('sqlite:' . DB_PATH);
$username[0] = $_SESSION['username'];
2021-02-19 13:23:26 +01:00
2022-04-18 16:05:00 +02:00
$op = $db->prepare('SELECT zone FROM zones WHERE username = ?');
$op->execute($username);
2021-02-19 13:23:26 +01:00
2022-04-18 16:05:00 +02:00
$dbZone = $op->fetch()['zone'];
2021-02-19 13:23:26 +01:00
2022-04-18 16:05:00 +02:00
while ($dbZone != NULL) {
if ($dbZone === $submittedZone) return;
$dbZone = $op->fetch()['zone'];
}
2021-02-19 13:23:26 +01:00
2022-04-18 16:05:00 +02:00
// If there is no entry in the database for the user matching the submitted zone
userError("You don't own this zone on the nameserver.");
2021-02-19 13:23:26 +01:00
}