Code simplifications

This commit is contained in:
Miraty 2022-05-23 04:41:55 +02:00
parent b7e69d8b41
commit 8dc4169a57
4 changed files with 18 additions and 60 deletions

View file

@ -70,23 +70,21 @@
if (isset($_POST['zone']) AND isset($_POST['keytag']) AND isset($_POST['algo']) AND isset($_POST['key']) AND isset($_SESSION['username'])) {
if (!($_POST['algo'] === "8")
AND !($_POST['algo'] === "13")
AND !($_POST['algo'] === "14")
AND !($_POST['algo'] === "15")
AND !($_POST['algo'] === "16")
)
userError("Wrong value for <code>algo</code>.");
if (
($_POST['algo'] !== "8")
AND ($_POST['algo'] !== "13")
AND ($_POST['algo'] !== "14")
AND ($_POST['algo'] !== "15")
AND ($_POST['algo'] !== "16")
) userError("Wrong value for <code>algo</code>.");
$_POST['keytag'] = intval($_POST['keytag']);
if ((!preg_match("/^[0-9]{1,6}$/", $_POST['keytag'])) OR !($_POST['keytag'] >= 1) OR !($_POST['keytag'] <= 65535))
userError("Wrong value for <code>keytag</code>.");
if (!$_POST['dt'] === "2" AND !$_POST['dt'] === "4")
if ($_POST['dt'] !== "2" AND $_POST['dt'] !== "4")
userError("Wrong value for <code>dt</code>.");
checkAbsoluteDomainFormat($_POST['zone']);
nsCheckZonePossession($_POST['zone']);
regCheckDomainPossession($_POST['zone']);
$action = checkAction($_POST['action']);
@ -99,7 +97,6 @@ if (isset($_POST['zone']) AND isset($_POST['keytag']) AND isset($_POST['algo'])
echo "La requête a été envoyée à Knot";
}
?>
<?php closeHTML(); ?>

View file

@ -21,13 +21,8 @@
<?php
$suffixes = regListUserDomains($_SESSION['username']);
if ($suffixes) {
foreach($suffixes as $suffix) {
foreach(regListUserDomains($_SESSION['username']) as $suffix)
echo " <option value='" . $suffix . "'>." . $suffix . "</option>";
}
}
?>
</select>
@ -43,8 +38,7 @@
if (isset($_POST['action']) AND isset($_POST['subdomain']) AND isset($_POST['suffix']) AND isset($_POST['ip']) AND isset($_SESSION['username'])) {
if (in_array($_POST['suffix'], $suffixes) !== true)
userError("You don't own this domain.");
regCheckDomainPossession($_POST['suffix']);
$domain = $_POST['subdomain'] . "." . $_POST['suffix'];

View file

@ -14,13 +14,8 @@
<?php
$domains = regListUserDomains($_SESSION['username']);
if ($domains) {
foreach($domains as $domain) {
echo "<option value='" . $domain . "'>" . $domain . "</option>";
}
}
foreach(regListUserDomains($_SESSION['username']) as $suffix)
echo " <option value='" . $suffix . "'>." . $suffix . "</option>";
?>
</select>

38
reg.php
View file

@ -12,22 +12,9 @@ function regListUserDomains($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++;
}
$domains = array();
foreach ($op->fetchAll() as $domain)
array_push($domains, $domain['domain']);
return $domains;
}
@ -35,24 +22,9 @@ function regListUserDomains($username) {
function regCheckDomainPossession($domain) {
checkAbsoluteDomainFormat($domain);
$db = new PDO('sqlite:' . DB_PATH);
$username[0] = $_SESSION['username'];
$ownedDomains = regListUserDomains($_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))
if (in_array($domain, $ownedDomains, true) !== true)
userError("You don't own this domain.");
}