diff --git a/public/reg/ds.php b/public/reg/ds.php
index 907a319..74e4f28 100644
--- a/public/reg/ds.php
+++ b/public/reg/ds.php
@@ -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 algo
.");
+ if (
+ ($_POST['algo'] !== "8")
+ AND ($_POST['algo'] !== "13")
+ AND ($_POST['algo'] !== "14")
+ AND ($_POST['algo'] !== "15")
+ AND ($_POST['algo'] !== "16")
+ ) userError("Wrong value for algo
.");
$_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 keytag
.");
- if (!$_POST['dt'] === "2" AND !$_POST['dt'] === "4")
+ if ($_POST['dt'] !== "2" AND $_POST['dt'] !== "4")
userError("Wrong value for dt
.");
- 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";
}
-
?>
diff --git a/public/reg/glue.php b/public/reg/glue.php
index faa512a..0459042 100644
--- a/public/reg/glue.php
+++ b/public/reg/glue.php
@@ -21,13 +21,8 @@
." . $suffix . "";
- }
- }
+ foreach(regListUserDomains($_SESSION['username']) as $suffix)
+ echo " ";
?>
@@ -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'];
diff --git a/public/reg/ns.php b/public/reg/ns.php
index 04cfa36..402fa2c 100644
--- a/public/reg/ns.php
+++ b/public/reg/ns.php
@@ -14,13 +14,8 @@
" . $domain . "";
- }
- }
+ foreach(regListUserDomains($_SESSION['username']) as $suffix)
+ echo " ";
?>
diff --git a/reg.php b/reg.php
index ce0eb8f..2156eba 100644
--- a/reg.php
+++ b/reg.php
@@ -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.");
}