Bladeren bron

nic > reg, securised glue record page

Miraty 4 jaren geleden
bovenliggende
commit
98c0e0617b
13 gewijzigde bestanden met toevoegingen van 108 en 69 verwijderingen
  1. 4 7
      auth/index.php
  2. 0 3
      ht/index.php
  3. 0 25
      inc/all.inc.php
  4. 1 1
      inc/pages.inc.php
  5. 46 0
      inc/reg.inc.php
  6. 2 2
      index.php
  7. 8 11
      ns/index.php
  8. 1 1
      reg/ds.php
  9. 35 5
      reg/glue.php
  10. 0 3
      reg/index.php
  11. 5 9
      reg/ns.php
  12. 0 0
      reg/register.php
  13. 6 2
      top.inc.php

+ 4 - 7
auth/index.php

@@ -1,16 +1,13 @@
 <?php require "../top.inc.php"; ?>
 <?php if (isset($_SESSION['username'])) { ?>
 
-<a class="authButton" href="logout">Se déconnecter</a>
-<br>
-<a class="authButton" href="password">Changer le mot de passe</a>
+<h2><a class="authButton" href="logout">Se déconnecter</a></h2>
+<h2><a class="authButton" href="password">Changer le mot de passe</a></h2>
 
 <?php } else { ?>
   Vous devez être authentifié·e pour utiliser Niver
-  <br>
-  <a class="authButton" href="register">Créer un compte</a>
-  <br>
-  <a class="authButton" href="login">Se connecter</a>
+  <h2><a class="authButton" href="register">Créer un compte</a></h2>
+  <h2><a class="authButton" href="login">Se connecter</a></h2>
 <?php } ?>
 
 

+ 0 - 3
ht/index.php

@@ -2,13 +2,10 @@
 
 <h2><a class="htButton" href="sftp">Gérer l'accès SFTP</a></h2>
 Accéder à son espace SFTP, pour publier et mettre à jour ses sites
-<br>
 <h2><a class="htButton" href="http-onion">Accès HTTP en Onion</a></h2>
 Un site HTML, accessible par Tor, avec une adresse en .onion
-<br>
 <h2><a class="htButton" href="https-domain">Accès HTTPS par DNS</a></h2>
 Des pages HTML, accessible directement, par un nom de domaine
-<br>
 <h2><a class="htButton" href="le">Installer un certificat Let's Encrypt sur un domaine</a></h2>
 
 <?php require "../bottom.inc.php"; ?>

+ 0 - 25
inc/all.inc.php

@@ -54,31 +54,6 @@ function nsCheckZonePossession($zone) {
 
 }
 
-function nicCheckDomainPossession($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'];
-  }
-
-  if (!($owned === true))
-    exit("Erreur : Vous ne possédez pas ce domaine sur le registre !");
-
-}
-
 function checkPassword($username, $password) {
   $username2[0] = $username;
 

+ 1 - 1
inc/pages.inc.php

@@ -31,7 +31,7 @@ switch (SERVICE) {
     }
   break;
 
-  case "nic":
+  case "reg":
     $page['service'] = "Registre";
     switch (PAGE) {
       case "index":

+ 46 - 0
inc/reg.inc.php

@@ -2,6 +2,52 @@
 if (strpos($_SERVER['PHP_SELF'], "inc.php") !== false)
   exit("This file is meant to be included.");
 
+function regListUserDomains($username) {
+  $db = new PDO('sqlite:' . DB_PATH);
+  $usernameArray[0] = $username;
+
+  $op = $db->prepare('SELECT domain FROM registry WHERE username = ?');
+  $op->execute($usernameArray);
+
+  $domains = false;
+
+  $domain = $op->fetch()['domain'];
+  $i = 0;
+
+  while ($domain != NULL) {
+    $domains[$i] = $domain;
+
+    $domain = $op->fetch()['domain'];
+    $i++;
+  }
+
+  return $domains;
+}
+
+function nicCheckDomainPossession($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'];
+  }
+
+  if (!($owned === true))
+    exit("Erreur : Vous ne possédez pas ce domaine sur le registre !");
+}
+
 function isFree($domain) {
 
   $domainArray[0] = $domain;

+ 2 - 2
index.php

@@ -1,6 +1,6 @@
 <?php require "top.inc.php"; ?>
 
-<h2><a class="nicButton" href="nic">Registre atope.art</a></h2>
+<h2><a class="nicButton" href="reg">Registre atope.art</a></h2>
 
 Demander l'attribution d'un sous-domaine d'atope.art
 
@@ -10,7 +10,7 @@ Utiliser les serveurs ns*.atope.art pour héberger ses zones de domaines
 
 <h2><a class="htButton" href="ht">Hypertexte</a></h2>
 
-Mettre en ligne son site statique sur un espace SFTP, et le faire répondre sur des domaines ou par Tor
+Mettre en ligne son site statique sur un espace <abbr title="SSH File Transfert Protocol">SFTP</abbr>, et le faire répondre en <abbr title="HyperText Transfert Protocol">HTTP</abbr> sur des domaines ou par Tor
 
 <h2><a class="authButton" href="auth">Authentification</a></h2>
 

+ 8 - 11
ns/index.php

@@ -1,15 +1,12 @@
 <?php require "../top.inc.php"; ?>
 
-<p>
-  Utiliser ns1.atope.art comme serveur de noms sur ses domaines
-  <br>
-  <a class="nsButton" href="zone">Ajouter une zone</a>
-  <br>
-  <a class="nsButton" href="dnssec">Obtenir les enregistrements DS d'une zone</a>
-  <br>
-  <a class="nsButton" href="ip">Ajouter un enregistrement A ou AAAA à une zone</a>
-  <br>
-  <a class="nsButton" href="ns">Ajouter un enregistrement NS à une zone</a>
-</p>
+<h2><a class="nsButton" href="zone">Ajouter une zone</a></h2>
+Pour qu'elle soit gérée par le serveur de noms ns1.atope.art
+<h2><a class="nsButton" href="ip">Enregistrements A ou AAAA</a></h2>
+Pour indiquer l'adresse IP d'un domaine
+<h2><a class="nsButton" href="ns">Enregistremenst NS</a></h2>
+Pour indiquer le serveur de noms d'une zone
+<h2><a class="nsButton" href="dnssec">Obtenir les enregistrements DS d'une zone</a></h2>
+À indiquer à la zone parente pour activer DNSSEC
 
 <?php require "../bottom.inc.php"; ?>

+ 1 - 1
nic/ds.php → reg/ds.php

@@ -7,7 +7,7 @@
     <option value="" disabled="" selected="">---</option>
 
     <?php
-    $db = new PDO('sqlite:' . $dbPath);
+    $db = new PDO('sqlite:' . DB_PATH);
     $username[0] = $_SESSION['username'];
 
     var_dump($username);

+ 35 - 5
nic/glue.php → reg/glue.php

@@ -7,8 +7,22 @@
     <option value="delete">Retirer</option>
   </select>
   <br>
-  <label for="ns">Serveur de nom</label><br>
-  <input required="" id="ns" placeholder="ns1.atope.art." name="ns" type="text">
+  <input required="" id="subdomain" placeholder="ns1" name="subdomain" type="text">
+  <select required="" name="suffix" id="suffix">
+    <option value="" disabled="" selected="">---</option>
+
+    <?php
+
+    $domains = regListUserDomains($_SESSION['username']);
+
+    if ($domains) {
+      foreach($domains as $domain) {
+        echo "<option value='" . $domain . "'>." . $domain . "</option>";
+      }
+    }
+
+    ?>
+  </select>
   <br>
   <label for="ip">IP</label><br>
   <input required="" pattern="^[a-f0-9:.]+$" id="ip" name="ip" minlength="7" maxlength="39" size="40" type="text" placeholder="2a0b:cbc0:1103:2::106f ou 45.13.104.169">
@@ -18,9 +32,22 @@
 
 <?php
 
-if (isset($_POST['action']) AND isset($_POST['ns']) AND isset($_POST['ip'])) {
+if (isset($_POST['action']) AND isset($_POST['subdomain']) AND isset($_POST['suffix']) AND isset($_POST['ip'])) {
 
-  checkAbsoluteDomainFormat($_POST['ns']);
+  if ($domains) {
+    foreach($domains as $domain) {
+      if ($_POST['suffix'] == $domain) goto ownedSuffix;
+    }
+    exit("ERROR : You don't own this suffix");
+  } else {
+    exit("ERROR : You don't own any domain");
+  }
+
+  ownedSuffix:
+
+  $domain = $_POST['subdomain'] . "." . $_POST['suffix'];
+
+  checkAbsoluteDomainFormat($domain);
 
   checkIpFormat($_POST['ip']);
 
@@ -38,8 +65,11 @@ if (isset($_POST['action']) AND isset($_POST['ns']) AND isset($_POST['ip'])) {
   else
     exit("ERROR : Wrong value for action");
 
+  // Remove anything before the first dot and the first dot itself
+  $suffix = preg_replace("/^[^.]+\./", "", $_POST['suffix']);
+
   exec(KNOTC_PATH . " zone-begin " . $suffix);
-  exec(KNOTC_PATH . " zone-" . $action . "set " . $suffix . " " . $_POST['ns'] . " 86400 " . $record . " " . $_POST['ip']);
+  exec(KNOTC_PATH . " zone-" . $action . "set " . $suffix . " " . $_POST['subdomain'] . " 86400 " . $record . " " . $_POST['ip']);
   exec(KNOTC_PATH . " zone-commit " . $suffix);
   echo "Glue record ajouté";
 }

+ 0 - 3
nic/index.php → reg/index.php

@@ -2,13 +2,10 @@
 
 <h2><a class="nicButton" href="register">Enregistrer un nouveau nom de domaine</a></h2>
 Prendre possession d'un sous-domaine d'atope.art
-<br>
 <h2><a class="nicButton" href="ns">NS (Name Server)</a></h2>
 Indiquer les serveurs de noms de son sous-domaine d'atope.art
-<br>
 <h2><a class="nicButton" href="glue">Glue Record</a></h2>
 Indiquer les IP de ses serveurs de noms de son sous-domaine d'atope.art dont les adresses se trouvent sur ce même sous-domaine
-<br>
 <h2><a class="nicButton" href="ds">DS (Delegation Signer)</a></h2>
 Déléguer la confiance DNSSEC
 

+ 5 - 9
nic/ns.php → reg/ns.php

@@ -13,17 +13,13 @@
     <option value="" disabled="" selected="">---</option>
 
     <?php
-    $db = new PDO('sqlite:' . DB_PATH);
-    $username[0] = $_SESSION['username'];
 
-    $req = $db->prepare('SELECT domain FROM registry WHERE username = ?');
-    $req->execute($username);
+    $domains = regListUserDomains($_SESSION['username']);
 
-    $domain = $req->fetch()['domain'];
-
-    while ($domain != NULL) {
-      echo "<option value='" . $domain . "'>" . $domain . "</option>";
-      $domain = $req->fetch()['domain'];
+    if ($domains) {
+      foreach($domains as $domain) {
+        echo "<option value='" . $domain . "'>" . $domain . "</option>";
+      }
     }
 
     ?>

+ 0 - 0
nic/register.php → reg/register.php


+ 6 - 2
top.inc.php

@@ -27,10 +27,14 @@ define("DB_PATH", ROOT_PATH . "/db/niver.db");
 define("KNOTC_PATH", "/usr/sbin/knotc");
 
 if (SERVICE != "auth" AND !isset($_SESSION['username'])) {
-  header('Location: ' . PREFIX . '/auth/login?redir=' . SERVICE . "/" . PAGE);
+  header('Location: ' . PREFIX . '/auth/login?redir=' . SERVICE . "/" . PAGE, true, 302);
   exit;
 }
 
+if (substr($_SERVER['REQUEST_URI'], -4) == '.php') {
+  header("Location: " . PREFIX . "/" . SERVICE . "/" . PAGE, true, 301); // 301 Moved Permanently
+  exit;
+}
 
 $theme = array(
   'htColor' => "#FF0000",
@@ -45,7 +49,7 @@ switch (SERVICE) {
   case "ht":
     $theme = array('mainColor' => $theme['htColor']) + $theme;
   break;
-  case "nic":
+  case "reg":
     $theme = array('mainColor' => $theme['nicColor']) + $theme;
   break;
   case "auth":