Browse Source

ht/ rework for onions step 1

Miraty 3 years ago
parent
commit
f9a31faea1
1 changed files with 30 additions and 25 deletions
  1. 30 25
      public/ht/http-onion.php

+ 30 - 25
public/ht/http-onion.php

@@ -10,32 +10,35 @@
 
 		<?php
 
-		$fsDirs = listFsDirs($_SESSION['username']);
-		$dbUsedDirs = listDbDirs($_SESSION['username'], "onion", "http");
-		$i = 0;
-		$j = 0;
-		$alreadyEnabledDirs = NULL;
-		$notYetEnabledDirs = NULL;
-		if ($fsDirs) {
-			foreach ($fsDirs as $fsDir) {
-				if ($dbUsedDirs AND in_array($fsDir, $dbUsedDirs)) {
-					$alreadyEnabledDirs[$i] = $fsDir;
-					$i++;
-				} else {
-					$notYetEnabledDirs[$j] = $fsDir;
-					$j++;
+		if (isset($_SESSION['username'])) {
+
+			$fsDirs = listFsDirs($_SESSION['username']);
+			$dbUsedDirs = listDbDirs($_SESSION['username'], "onion", "http");
+			$i = 0;
+			$j = 0;
+			$alreadyEnabledDirs = NULL;
+			$notYetEnabledDirs = NULL;
+			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>";
+					}
 				}
 			}
 		}
@@ -56,10 +59,12 @@ if (isset($_POST['dir']) AND isset($_SESSION['username'])) {
 
 	// Generate a .onion address
 	$torConf = file_get_contents(TOR_CONFIG_PATH);
-	$torConf = $torConf . "\nHiddenServiceDir " . TOR_KEYS_PATH . "/" . $_POST['dir'] . "/\nHiddenServicePort 80 [::1]:" . INTERNAL_ONION_HTTP_PORT;
+	$torConf = $torConf . "HiddenServiceDir " . TOR_KEYS_PATH . "/" . $_POST['dir'] . "/
+HiddenServicePort 80 [::1]:" . INTERNAL_ONION_HTTP_PORT . "
+";
 	file_put_contents(TOR_CONFIG_PATH, $torConf);
 
-	exec(SUDO_PATH . " " . MANIVER_PATH . " reload-tor", $output);
+	exec(SUDO_PATH . " " . SYSTEMCTL_PATH . " reload-tor", $output);
 	addNiverLog("Tor reloaded by " . $_SESSION['username'], $output);
 
 	// Copy generated address to a location readable by PHP
@@ -70,7 +75,7 @@ if (isset($_POST['dir']) AND isset($_SESSION['username'])) {
 	sleep(1);
 
 	// Get the address generated by Tor
-	$onion = file_get_contents(HT_PATH . "/" . $_SESSION['username'] . "/ht/" . $_POST['dir'] . "/hostname");
+	$onion = file_get_contents(HT_PATH . "/" . $_SESSION['username'] . "/" . $_POST['dir'] . "/hostname");
 	$onion = str_replace(array("\r", "\n"), "", $onion);
 
 	// Store it in the database