Browse Source

Small fixes (in reg)

Miraty 4 years ago
parent
commit
b024503f3f
7 changed files with 44 additions and 37 deletions
  1. 0 24
      inc/all.inc.php
  2. 26 0
      inc/ns.inc.php
  3. 7 3
      inc/reg.inc.php
  4. 1 1
      reg/glue.php
  5. 7 7
      reg/ns.php
  6. 1 1
      reg/register.php
  7. 2 1
      top.inc.php

+ 0 - 24
inc/all.inc.php

@@ -30,30 +30,6 @@ function listUserZones($username) {
   return $zones;
 }
 
-function nsCheckZonePossession($zone) {
-  checkAbsoluteDomainFormat($zone);
-
-  $db = new PDO('sqlite:' . DB_PATH);
-  $username[0] = $_SESSION['username'];
-
-  $op = $db->prepare('SELECT zone FROM zones WHERE username = ?');
-  $op->execute($username);
-
-  $domain = $op->fetch()['zone'];
-
-  while ($domain != NULL) {
-    if ($domain == $zone) {
-      $owned = true;
-      break;
-    }
-    $domain = $op->fetch()['zone'];
-  }
-
-  if (!$owned)
-    exit("Erreur : Vous ne possédez pas ce domaine sur le serveur de noms !");
-
-}
-
 function checkPassword($username, $password) {
   $username2[0] = $username;
 

+ 26 - 0
inc/ns.inc.php

@@ -0,0 +1,26 @@
+<?php
+if (strpos($_SERVER['PHP_SELF'], "inc.php") !== false)
+  exit("This file is meant to be included.");
+
+function nsCheckZonePossession($zone) {
+  checkAbsoluteDomainFormat($zone);
+
+  $db = new PDO('sqlite:' . DB_PATH);
+  $username[0] = $_SESSION['username'];
+
+  $op = $db->prepare('SELECT zone FROM zones WHERE username = ?');
+  $op->execute($username);
+
+  $domain = $op->fetch()['zone'];
+
+  while ($domain != NULL) {
+    if ($domain === $zone) {
+      $owned = true;
+      break;
+    }
+    $domain = $op->fetch()['zone'];
+  }
+
+  if (!($owned === true))
+    exit("Erreur : Vous ne possédez pas ce domaine sur le serveur de noms !");
+}

+ 7 - 3
inc/reg.inc.php

@@ -2,6 +2,10 @@
 if (strpos($_SERVER['PHP_SELF'], "inc.php") !== false)
   exit("This file is meant to be included.");
 
+function regGetSuffix($domain) {
+  return preg_replace("/^[^.]+\./", "", $domain);
+}
+
 function regListUserDomains($username) {
   $db = new PDO('sqlite:' . DB_PATH);
   $usernameArray[0] = $username;
@@ -24,7 +28,7 @@ function regListUserDomains($username) {
   return $domains;
 }
 
-function nicCheckDomainPossession($domain) {
+function regCheckDomainPossession($domain) {
   checkAbsoluteDomainFormat($domain);
 
   $db = new PDO('sqlite:' . DB_PATH);
@@ -37,7 +41,7 @@ function nicCheckDomainPossession($domain) {
 
   $owned = false;
   while ($dbDomain != NULL) {
-    if ($dbDomain == $domain) {
+    if ($dbDomain === $domain) {
       $owned = true;
       break;
     }
@@ -48,7 +52,7 @@ function nicCheckDomainPossession($domain) {
     exit("Erreur : Vous ne possédez pas ce domaine sur le registre !");
 }
 
-function isFree($domain) {
+function regIsFree($domain) {
 
   $domainArray[0] = $domain;
 

+ 1 - 1
reg/glue.php

@@ -66,7 +66,7 @@ if (isset($_POST['action']) AND isset($_POST['subdomain']) AND isset($_POST['suf
     exit("ERROR : Wrong value for action");
 
   // Remove anything before the first dot and the first dot itself
-  $suffix = preg_replace("/^[^.]+\./", "", $_POST['suffix']);
+  $suffix = regGetSuffix($_POST['suffix']);
 
   exec(KNOTC_PATH . " zone-begin " . $suffix);
   exec(KNOTC_PATH . " zone-" . $action . "set " . $suffix . " " . $_POST['subdomain'] . " 86400 " . $record . " " . $_POST['ip']);

+ 7 - 7
reg/ns.php

@@ -36,7 +36,7 @@
 
 if (isset($_POST['domain']) AND isset($_POST['action']) AND isset($_POST['ns']) AND isset($_SESSION['username'])) {
 
-  nicCheckDomainPossession($_POST['domain']);
+  regCheckDomainPossession($_POST['domain']);
   checkAbsoluteDomainFormat($_POST['ns']);
 
   if ($_POST['action'] == "delete")
@@ -46,12 +46,12 @@ if (isset($_POST['domain']) AND isset($_POST['action']) AND isset($_POST['ns'])
   else
     exit("Erreur : valeur invalide pour action");
 
-  exec("knotc zone-begin atope.art");
-  exec("knotc zone-" . $action . "set atope.art " . $_POST['domain'] . " 3600 IN NS " . $_POST['ns']);
-  exec("knotc zone-commit atope.art");
-  echo "Modifications appliquées";
-} else {
-  echo "Rien n'a été appliqué lors du dernier chargement.";
+  $suffix = regGetSuffix($_POST['domain']);
+
+  exec(KNOTC_PATH . " zone-begin atope.art");
+  exec(KNOTC_PATH . " zone-" . $action . "set " . $suffix . " " . $_POST['domain'] . " 86400 NS " . $_POST['ns']);
+  exec(KNOTC_PATH . " zone-commit atope.art");
+  echo "Enregistrement NS ajouté";
 }
 
 ?>

+ 1 - 1
reg/register.php

@@ -139,7 +139,7 @@ if (isset($_POST['subdomain']) AND isset($_SESSION['username'])) {
 
     checkAbsoluteDomainFormat($domain);
 
-    if (isFree($domain)) {
+    if (regIsFree($domain)) {
       $db = new PDO('sqlite:' . DB_PATH);
       $stmt = $db->prepare("INSERT INTO registry(domain, username, last_renewal) VALUES(:domain, :username, :last_renewal)");
       $username = $_SESSION['username'];

+ 2 - 1
top.inc.php

@@ -31,7 +31,7 @@ if (SERVICE != "auth" AND !isset($_SESSION['username'])) {
   exit;
 }
 
-if (substr($_SERVER['REQUEST_URI'], -4) == '.php') {
+if (substr($_SERVER['REQUEST_URI'], -4) == ".php") {
   header("Location: " . PREFIX . "/" . SERVICE . "/" . PAGE, true, 301); // 301 Moved Permanently
   exit;
 }
@@ -66,6 +66,7 @@ switch (SERVICE) {
 require "inc/all.inc.php";
 require "inc/format.inc.php";
 require "inc/ht.inc.php";
+require "inc/ns.inc.php";
 require "inc/pages.inc.php";
 require "inc/reg.inc.php";