Browse Source

Fix some PHP8 warnings and use constants for paths

Miraty 4 years ago
parent
commit
07b68301c3
17 changed files with 141 additions and 132 deletions
  1. 18 16
      ht/gemini-domain.php
  2. 18 16
      ht/gemini-onion.php
  3. 18 16
      ht/http-onion.php
  4. 18 15
      ht/https-domain.php
  5. 2 2
      ht/le.php
  6. 1 1
      ht/sftp.php
  7. 0 20
      inc/all.inc.php
  8. 12 3
      inc/ht.inc.php
  9. 25 0
      inc/ns.inc.php
  10. 8 3
      inc/reg.inc.php
  11. 1 1
      ns/caa.php
  12. 5 10
      ns/dnssec.php
  13. 3 12
      ns/ip.php
  14. 1 1
      ns/ns.php
  15. 1 1
      ns/txt.php
  16. 6 13
      reg/ds.php
  17. 4 2
      top.inc.php

+ 18 - 16
ht/gemini-domain.php

@@ -22,25 +22,27 @@
     $j = 0;
     $alreadyEnabledDirs = NULL;
     $notYetEnabledDirs = NULL;
-    foreach ($fsDirs as $fsDir) {
-      if ($dbUsedDirs AND in_array($fsDir, $dbUsedDirs)) {
-        $alreadyEnabledDirs[$i] = $fsDir;
-        $i++;
-      } else {
-        $notYetEnabledDirs[$j] = $fsDir;
-        $j++;
+    if ($fsDirs) {
+      foreach ($fsDirs as $fsDir) {
+        if ($dbUsedDirs AND in_array($fsDir, $dbUsedDirs)) {
+          $alreadyEnabledDirs[$i] = $fsDir;
+          $i++;
+        } else {
+          $notYetEnabledDirs[$j] = $fsDir;
+          $j++;
+        }
       }
-    }
 
-    if (!is_null($notYetEnabledDirs)) {
-      foreach ($notYetEnabledDirs as $dir) {
-        echo "<option value='" . $dir . "'>" . $dir . "</option>";
+      if (!is_null($notYetEnabledDirs)) {
+        foreach ($notYetEnabledDirs as $dir) {
+          echo "<option value='" . $dir . "'>" . $dir . "</option>";
+        }
       }
-    }
 
-    if (!is_null($alreadyEnabledDirs)) {
-      foreach ($alreadyEnabledDirs as $dir) {
-        echo "<option disabled='' value='" . $dir . "'>" . $dir . "</option>";
+      if (!is_null($alreadyEnabledDirs)) {
+        foreach ($alreadyEnabledDirs as $dir) {
+          echo "<option disabled='' value='" . $dir . "'>" . $dir . "</option>";
+        }
       }
     }
     ?>
@@ -68,7 +70,7 @@ root=/srv/hyper/" . $_SESSION['username'] . "/hyper/" . $_POST['dir'] . "
   file_put_contents("/etc/gmnisrv.ini", $conf, FILE_APPEND);
 
   // Restart the gmnisrv daemon (as there is no reload support)
-  exec("sudo " . MANIVER_PATH . " restart-gmnisrv");
+  exec(SUDO_PATH . " " . MANIVER_PATH . " restart-gmnisrv");
 
   echo "Accès par domaine ajouté sur ce dossier !";
 }

+ 18 - 16
ht/gemini-onion.php

@@ -16,25 +16,27 @@
     $j = 0;
     $alreadyEnabledDirs = NULL;
     $notYetEnabledDirs = NULL;
-    foreach ($fsDirs as $fsDir) {
-      if ($dbUsedDirs AND in_array($fsDir, $dbUsedDirs)) {
-        $alreadyEnabledDirs[$i] = $fsDir;
-        $i++;
-      } else {
-        $notYetEnabledDirs[$j] = $fsDir;
-        $j++;
+    if ($fsDirs) {
+      foreach ($fsDirs as $fsDir) {
+        if ($dbUsedDirs AND in_array($fsDir, $dbUsedDirs)) {
+          $alreadyEnabledDirs[$i] = $fsDir;
+          $i++;
+        } else {
+          $notYetEnabledDirs[$j] = $fsDir;
+          $j++;
+        }
       }
-    }
 
-    if (!is_null($notYetEnabledDirs)) {
-      foreach ($notYetEnabledDirs as $dir) {
-        echo "<option value='" . $dir . "'>" . $dir . "</option>";
+      if (!is_null($notYetEnabledDirs)) {
+        foreach ($notYetEnabledDirs as $dir) {
+          echo "<option value='" . $dir . "'>" . $dir . "</option>";
+        }
       }
-    }
 
-    if (!is_null($alreadyEnabledDirs)) {
-      foreach ($alreadyEnabledDirs as $dir) {
-        echo "<option disabled='' value='" . $dir . "'>" . $dir . "</option>";
+      if (!is_null($alreadyEnabledDirs)) {
+        foreach ($alreadyEnabledDirs as $dir) {
+          echo "<option disabled='' value='" . $dir . "'>" . $dir . "</option>";
+        }
       }
     }
     ?>
@@ -77,7 +79,7 @@ root=/srv/hyper/" . $_SESSION['username'] . "/hyper/" . $_POST['dir'] . "
   file_put_contents("/etc/gmnisrv.ini", $conf, FILE_APPEND);
 
   // Restart the gmnisrv daemon (as there is no reload support)
-  exec("sudo " . MANIVER_PATH . " restart-gmnisrv");
+  exec(SUDO_PATH . " " . MANIVER_PATH . " restart-gmnisrv");
 
   // Tell the user their site address
   echo "<p>L'adresse de votre capsule Onion Gemini est :<br><a href='http://" . $onion . "'<code>http://" . $onion . "</code></a></p>";

+ 18 - 16
ht/http-onion.php

@@ -16,25 +16,27 @@
     $j = 0;
     $alreadyEnabledDirs = NULL;
     $notYetEnabledDirs = NULL;
-    foreach ($fsDirs as $fsDir) {
-      if ($dbUsedDirs AND in_array($fsDir, $dbUsedDirs)) {
-        $alreadyEnabledDirs[$i] = $fsDir;
-        $i++;
-      } else {
-        $notYetEnabledDirs[$j] = $fsDir;
-        $j++;
+    if ($fsDirs) {
+      foreach ($fsDirs as $fsDir) {
+        if ($dbUsedDirs AND in_array($fsDir, $dbUsedDirs)) {
+          $alreadyEnabledDirs[$i] = $fsDir;
+          $i++;
+        } else {
+          $notYetEnabledDirs[$j] = $fsDir;
+          $j++;
+        }
       }
-    }
 
-    if (!is_null($notYetEnabledDirs)) {
-      foreach ($notYetEnabledDirs as $dir) {
-        echo "<option value='" . $dir . "'>" . $dir . "</option>";
+      if (!is_null($notYetEnabledDirs)) {
+        foreach ($notYetEnabledDirs as $dir) {
+          echo "<option value='" . $dir . "'>" . $dir . "</option>";
+        }
       }
-    }
 
-    if (!is_null($alreadyEnabledDirs)) {
-      foreach ($alreadyEnabledDirs as $dir) {
-        echo "<option disabled='' value='" . $dir . "'>" . $dir . "</option>";
+      if (!is_null($alreadyEnabledDirs)) {
+        foreach ($alreadyEnabledDirs as $dir) {
+          echo "<option disabled='' value='" . $dir . "'>" . $dir . "</option>";
+        }
       }
     }
     ?>
@@ -77,7 +79,7 @@ if (isset($_POST['dir']) AND isset($_SESSION['username'])) {
   file_put_contents(NGINX_CONFIG_PATH . "/" . $_POST['dir'] . ".conf", $nginxConf);
 
   // Reload Nginx
-  exec("sudo " . MANIVER_PATH . " reload-nginx");
+  exec(SUDO_PATH . " " . MANIVER_PATH . " reload-nginx");
 
   // Tell the user their site address
   echo "<p>L'adresse de votre site Onion HTTP est :<br><a href='http://" . $onion . "'<code>http://" . $onion . "</code></a></p>";

+ 18 - 15
ht/https-domain.php

@@ -22,27 +22,30 @@
     $j = 0;
     $alreadyEnabledDirs = NULL;
     $notYetEnabledDirs = NULL;
-    foreach ($fsDirs as $fsDir) {
-      if ($dbUsedDirs AND in_array($fsDir, $dbUsedDirs)) {
-        $alreadyEnabledDirs[$i] = $fsDir;
-        $i++;
-      } else {
-        $notYetEnabledDirs[$j] = $fsDir;
-        $j++;
+    if ($fsDirs) {
+      foreach ($fsDirs as $fsDir) {
+        if ($dbUsedDirs AND in_array($fsDir, $dbUsedDirs)) {
+          $alreadyEnabledDirs[$i] = $fsDir;
+          $i++;
+        } else {
+          $notYetEnabledDirs[$j] = $fsDir;
+          $j++;
+        }
       }
-    }
 
-    if (!is_null($notYetEnabledDirs)) {
-      foreach ($notYetEnabledDirs as $dir) {
-        echo "<option value='" . $dir . "'>" . $dir . "</option>";
+      if (!is_null($notYetEnabledDirs)) {
+        foreach ($notYetEnabledDirs as $dir) {
+          echo "<option value='" . $dir . "'>" . $dir . "</option>";
+        }
       }
-    }
 
-    if (!is_null($alreadyEnabledDirs)) {
-      foreach ($alreadyEnabledDirs as $dir) {
-        echo "<option disabled='' value='" . $dir . "'>" . $dir . "</option>";
+      if (!is_null($alreadyEnabledDirs)) {
+        foreach ($alreadyEnabledDirs as $dir) {
+          echo "<option disabled='' value='" . $dir . "'>" . $dir . "</option>";
+        }
       }
     }
+
     ?>
   </select>
   <br>

+ 2 - 2
ht/le.php

@@ -14,13 +14,13 @@
 
 if (isset($_POST['domain'])) {
 
-  exec("sudo " . MANIVER_PATH . " le-install " . $_POST['domain'], $output);
+  exec(SUDO_PATH . " " . MANIVER_PATH . " le-install " . $_POST['domain'], $output);
   addNiverLog($_SESSION['username'] . " installed a Let's Encrypt certificate on their site", $output);
   $conf = file_get_contents(NGINX_CONFIG_PATH . "/" . $_POST['domain'] . ".conf");
   $conf = preg_replace("#host\.atope\.art#", $_POST['domain'], $conf);
   file_put_contents(NGINX_CONFIG_PATH . "/" . $_POST['domain'] . ".conf", $conf);
 
-  exec("sudo " . MANIVER_PATH . " reload-nginx");
+  exec(SUDO_PATH . " " . MANIVER_PATH . " reload-nginx");
 
   echo "Formulaire traité !!";
 } else {

+ 1 - 1
ht/sftp.php

@@ -19,7 +19,7 @@ if ($_SESSION['sftp_enabled'] == false) { ?>
 
   if (isset($_SESSION['username']) AND isset($_POST['password'])) {
     // Setup SFTP access
-    exec("sudo " . MANIVER_PATH . " setup-user " . $_SESSION['username'] . " " . $_POST['password'], $output);
+    exec(SUDO_PATH . " " . MANIVER_PATH . " setup-user " . $_SESSION['username'] . " " . $_POST['password'], $output);
     addNiverLog($_SESSION['username'] . " enabled SFTP on their account", $output);
     enableSftp($_SESSION['username']);
     $_SESSION['sftp_enabled'] = true;

+ 0 - 20
inc/all.inc.php

@@ -19,26 +19,6 @@ function checkAction($action) {
     exit("ERROR: wrong value for action");
 }
 
-function listUserZones($username) {
-  $db = new PDO('sqlite:' . DB_PATH);
-  $usernameArray[0] = $username;
-
-  $op = $db->prepare('SELECT zone FROM zones WHERE username = ?');
-  $op->execute($usernameArray);
-
-  $zone = $op->fetch()['zone'];
-
-  $i = 0;
-
-  while ($zone != NULL) {
-    $zones[$i] = $zone;
-    $i++;
-    $zone = $op->fetch()['zone'];
-  }
-
-  return $zones;
-}
-
 function checkPassword($username, $password) {
   $username2[0] = $username;
 

+ 12 - 3
inc/ht.inc.php

@@ -3,7 +3,8 @@ if (strpos($_SERVER['PHP_SELF'], "inc.php") !== false)
   exit("This file is meant to be included.");
 
 function listFsDirs($username) {
-  exec("/usr/bin/ls ls --format=single-column -d /srv/hyper/" . $username . "/hyper/*/", $absoluteDirs);
+  exec(LS_PATH . " ls --format=single-column -d /srv/hyper/" . $username . "/hyper/*/", $absoluteDirs);
+  $relativeDirs = false;
   foreach ($absoluteDirs as $i => $absoluteDir) {
     $tree = explode("/", $absoluteDir); // The last key is NULL
     end($tree);
@@ -40,12 +41,20 @@ function listDbDirs($username, $domainType, $protocol) {
   $op->execute();
 
   $i = 0;
-  $siteDir = $op->fetch()['site_dir'];
+  $data = $op->fetch();
+  if (isset($data['site_dir']))
+    $siteDir = $data['site_dir'];
+  else
+    $siteDir = NULL;
 
   while ($siteDir != NULL) {
     $siteDirs[$i] = $siteDir;
     $i++;
-    $siteDir = $op->fetch()['site_dir'];
+    $data = $op->fetch();
+    if (isset($data['site_dir']))
+      $siteDir = $data['site_dir'];
+    else
+      $siteDir = NULL;
   }
   if (isset($siteDirs))
     return $siteDirs;

+ 25 - 0
inc/ns.inc.php

@@ -11,6 +11,31 @@ function nsTtl($value, $multiplier) {
   return $ttl;
 }
 
+function nsListUserZones($username) {
+  $db = new PDO('sqlite:' . DB_PATH);
+  $usernameArray[0] = $username;
+
+  $op = $db->prepare('SELECT zone FROM zones WHERE username = ?');
+  $op->execute($usernameArray);
+
+  $data = $op->fetch();
+  $zone = $data['zone'];
+
+  $i = 0;
+
+  while ($zone != NULL) {
+    $zones[$i] = $zone;
+    $i++;
+    $data = $op->fetch();
+    if (isset($data['zone']))
+      $zone = $data['zone'];
+    else
+      $zone = NULL;
+  }
+
+  return $zones;
+}
+
 function nsCheckZonePossession($submittedZone) {
   checkAbsoluteDomainFormat($submittedZone);
 

+ 8 - 3
inc/reg.inc.php

@@ -14,14 +14,19 @@ function regListUserDomains($username) {
   $op->execute($usernameArray);
 
   $domains = false;
-
-  $domain = $op->fetch()['domain'];
   $i = 0;
+  $data = $op->fetch();
+  $domain = $data['domain'];
 
   while ($domain != NULL) {
     $domains[$i] = $domain;
 
-    $domain = $op->fetch()['domain'];
+    $data = $op->fetch();
+    if (isset($data['domain']))
+      $domain = $data['domain'];
+    else
+      $domain = NULL;
+
     $i++;
   }
 

+ 1 - 1
ns/caa.php

@@ -13,7 +13,7 @@
     <option value="" disabled="" selected="">---</option>
 
     <?php
-    $zones = listUserZones($_SESSION['username']);
+    $zones = nsListUserZones($_SESSION['username']);
 
     foreach ($zones as $zone) {
       echo "<option value='" . $zone . "'>" . $zone . "</option>";

+ 5 - 10
ns/dnssec.php

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

+ 3 - 12
ns/ip.php

@@ -20,19 +20,10 @@
     <option value="" disabled="" selected="">---</option>
 
     <?php
-    $db = new PDO('sqlite:' . DB_PATH);
-    $username[0] = $_SESSION['username'];
+    $zones = nsListUserZones($_SESSION['username']);
 
-    var_dump($username);
-
-    $req = $db->prepare('SELECT zone FROM zones WHERE username = ?');
-    $req->execute($username);
-
-    $domain = $req->fetch()['zone'];
-
-    while ($domain != NULL) {
-      echo "<option value='" . $domain . "'>" . $domain . "</option>";
-      $domain = $req->fetch()['zone'];
+    foreach ($zones as $zone) {
+      echo "<option value='" . $zone . "'>" . $zone . "</option>";
     }
 
     ?>

+ 1 - 1
ns/ns.php

@@ -13,7 +13,7 @@
     <option value="" disabled="" selected="">---</option>
 
     <?php
-    $zones = listUserZones($_SESSION['username']);
+    $zones = nsListUserZones($_SESSION['username']);
 
     foreach ($zones as $zone) {
       echo "<option value='" . $zone . "'>" . $zone . "</option>";

+ 1 - 1
ns/txt.php

@@ -13,7 +13,7 @@
     <option value="" disabled="" selected="">---</option>
 
     <?php
-    $zones = listUserZones($_SESSION['username']);
+    $zones = nsListUserZones($_SESSION['username']);
 
     foreach ($zones as $zone) {
       echo "<option value='" . $zone . "'>" . $zone . "</option>";

+ 6 - 13
reg/ds.php

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

+ 4 - 2
top.inc.php

@@ -28,9 +28,10 @@ define("NGINX_CONFIG_PATH", "/etc/nginx/hyper"); // Config directory
 define("TOR_CONFIG_PATH", "/etc/tor/torrc"); // Config file
 define("TOR_KEYS_PATH", "/var/lib/tor/niver"); // Keys directory
 define("SUDO_PATH", "/usr/bin/sudo"); // Binary file
-define("MANIVER_PATH", "/root/maniver/target/release/maniver"); // Binary file
+define("LS_PATH", "/usr/bin/ls"); // Binary file
+define("MANIVER_PATH", "/usr/local/bin/maniver"); // Binary file
 // The mountpoint of the hypertext storage partition (that will be accessed over SFTP)
-define("HT_PATH", "/srv/hyper");
+define("HT_PATH", "/srv/ht");
 
 define("SERVICE", substr(dirname($_SERVER['PHP_SELF']), strlen(PREFIX) + 1));
 define("PAGE", basename($_SERVER['PHP_SELF'], '.php'));
@@ -93,6 +94,7 @@ $cssFileName = Less_Cache::Get($absoluteLessFiles, $options, $theme);
 <!DOCTYPE html>
 <html lang="fr">
   <head>
+    <meta charset="UTF-8">
     <title><?php
     if (isset($page['title']) AND $page['title'] != "Accueil")
       echo $page['title'] . " · ";