Browse Source

Code simplifications

Miraty 3 years ago
parent
commit
8dc4169a57
4 changed files with 18 additions and 60 deletions
  1. 8 11
      public/reg/ds.php
  2. 3 9
      public/reg/glue.php
  3. 2 7
      public/reg/ns.php
  4. 5 33
      reg.php

+ 8 - 11
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 <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(); ?>

+ 3 - 9
public/reg/glue.php

@@ -21,13 +21,8 @@
 
 				<?php
 
-				$suffixes = regListUserDomains($_SESSION['username']);
-
-				if ($suffixes) {
-					foreach($suffixes as $suffix) {
-						echo "<option value='" . $suffix . "'>." . $suffix . "</option>";
-					}
-				}
+				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'];
 

+ 2 - 7
public/reg/ns.php

@@ -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>

+ 5 - 33
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'];
-
-	$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'];
-	}
+	$ownedDomains = regListUserDomains($_SESSION['username']);
 
-	if (!($owned === true))
+	if (in_array($domain, $ownedDomains, true) !== true)
 		userError("You don't own this domain.");
 }