Przeglądaj źródła

Switch from gmnisrv to Twins

Miraty 3 lat temu
rodzic
commit
24113b8899
3 zmienionych plików z 34 dodań i 17 usunięć
  1. 16 9
      ht/gemini-domain.php
  2. 16 8
      ht/gemini-onion.php
  3. 2 0
      inc/const.inc.php

+ 16 - 9
ht/gemini-domain.php

@@ -64,15 +64,22 @@ if (isset($_POST['domain']) AND isset($_POST['dir']) AND isset($_SESSION['userna
 
 
   addSite($_SESSION['username'], $_POST['dir'], $_POST['domain'], "dns", "gemini");
   addSite($_SESSION['username'], $_POST['dir'], $_POST['domain'], "dns", "gemini");
 
 
-  $conf = "# START NIVERSITE
-[" . $_POST['domain'] . "]
-root=" . HT_PATH . "/" . $_SESSION['username'] . "/ht/" . $_POST['dir'] . "
-# STOP NIVERSITE
-";
-  file_put_contents("/etc/gmnisrv.ini", $conf, FILE_APPEND);
-
-  // Restart the gmnisrv daemon (as there is no reload support)
-  exec(SUDO_PATH . " " . MANIVER_PATH . " restart-gmnisrv");
+  // Generate tls keys
+  exec(SUDO_PATH . " " . MANIVER_PATH . " gemini-new-certificate " . $_POST['domain']);
+
+  // Add to Twins configuration
+  $conf = "
+  " . $_POST['domain'] . ":
+    cert: " . TWINS_PATH . "/tls/" . $_POST['domain'] . ".crt
+    key: " . TWINS_PATH . "/tls/" . $_POST['domain'] . ".key
+    paths:
+      -
+        path: /
+        root: " . HT_PATH . "/" . $_SESSION['username'] . "/ht/" . $_POST['dir'];
+  file_put_contents(TWINS_PATH . "/twins.conf", $conf, FILE_APPEND);
+
+  // Reload Twins daemon
+  exec(SUDO_PATH . " " . MANIVER_PATH . " reload-twins");
 
 
   echo "Accès par domaine ajouté sur ce dossier !";
   echo "Accès par domaine ajouté sur ce dossier !";
 }
 }

+ 16 - 8
ht/gemini-onion.php

@@ -76,17 +76,25 @@ if (isset($_POST['dir']) AND isset($_SESSION['username'])) {
   // Store it in the database
   // Store it in the database
   addSite($_SESSION['username'], $_POST['dir'], $onion, "onion", "gemini");
   addSite($_SESSION['username'], $_POST['dir'], $onion, "onion", "gemini");
 
 
-  $conf = "
-[" . $onion . "]
-root=" . HT_PATH . "/" . $_SESSION['username'] . "/ht/" . $_POST['dir'] . "
-";
-  file_put_contents("/etc/gmnisrv.ini", $conf, FILE_APPEND);
+  // Generate tls keys
+  exec(SUDO_PATH . " " . MANIVER_PATH . " gemini-new-certificate " . $onion);
 
 
-  // Restart the gmnisrv daemon (as there is no reload support)
-  exec(SUDO_PATH . " " . MANIVER_PATH . " restart-gmnisrv");
+  // Add to Twins configuration
+  $conf = "
+  " . $onion . ":
+    cert: " . TWINS_PATH . "/tls/" . $onion . ".crt
+    key: " . TWINS_PATH . "/tls/" . $onion . ".key
+    paths:
+      -
+        path: /
+        root: " . HT_PATH . "/" . $_SESSION['username'] . "/ht/" . $_POST['dir'];
+  file_put_contents(TWINS_PATH . "/twins.conf", $conf, FILE_APPEND);
+
+  // Reload Twins daemon
+  exec(SUDO_PATH . " " . MANIVER_PATH . " reload-twins");
 
 
   // Tell the user their site address
   // 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>";
+  echo "<p>L'adresse de votre capsule Onion Gemini est : <br><a href='gemini://" . $onion . "'<code>gemini://" . $onion . "</code></a></p>";
 
 
 }
 }
 
 

+ 2 - 0
inc/const.inc.php

@@ -29,6 +29,8 @@ define("TOR_CONFIG_PATH", "/etc/tor/instances/niver/torrc"); // Tor configuratio
 define("TOR_KEYS_PATH", "/var/lib/tor-instances/niver/keys"); // Tor keys directory
 define("TOR_KEYS_PATH", "/var/lib/tor-instances/niver/keys"); // Tor keys directory
 // Knot
 // Knot
 define("KNOT_ZONES_PATH", "/var/lib/knot/zones"); // Knot zones directory
 define("KNOT_ZONES_PATH", "/var/lib/knot/zones"); // Knot zones directory
+// Twins
+define("TWINS_PATH", "/var/local/twins"); // Twins directory containing configuration and TLS certificates
 // Executable files (you can get the full path of a command with $ which <command>)
 // Executable files (you can get the full path of a command with $ which <command>)
 define("KNOTC_PATH", "/usr/sbin/knotc");
 define("KNOTC_PATH", "/usr/sbin/knotc");
 define("KEYMGR_PATH", "/usr/sbin/keymgr");
 define("KEYMGR_PATH", "/usr/sbin/keymgr");