Ajouter un accès en .onion sur un dossier



dir."); // Add Tor config $torConf = file_get_contents(CONF['ht']['tor_config_path']); if ($torConf === false) serverError("Failed to read current Tor configuration."); $torConf = $torConf . "HiddenServiceDir " . CONF['ht']['tor_keys_path'] . "/" . $_POST['dir'] . "/ HiddenServicePort 80 [::1]:" . CONF['ht']['internal_onion_http_port'] . " "; if (file_put_contents(CONF['ht']['tor_config_path'], $torConf) === false) serverError("Failed to write new Tor configuration."); // Reload Tor exec(CONF['ht']['sudo_path'] . " " . CONF['ht']['systemctl_path'] . " reload " . CONF['ht']['tor_service'], $output, $code); if ($code !== 0) serverError("Failed to reload Tor."); // Get the address generated by Tor exec(CONF['ht']['sudo_path'] . " -u " . CONF['ht']['tor_user'] . " " . CONF['ht']['cat_path'] . " " . CONF['ht']['tor_keys_path'] . "/" . $_POST['dir'] . "/hostname", $output); $onion = $output[0]; if (preg_match("/[0-9a-z]{56}\.onion/", $onion) !== 1) serverError("No onion address found."); // Store it in the database addSite($_SESSION['username'], $_POST['dir'], $onion, "onion", "http"); // Add Nginx config $nginxConf = 'server { listen [::1]:' . CONF['ht']['internal_onion_http_port'] . '; server_name ' . $onion . '; root ' . CONF['ht']['ht_path'] . '/' . $_SESSION['username'] . '/' . $_POST['dir'] . '; include inc/ht-onion.conf; } '; if (file_put_contents(CONF['ht']['nginx_config_path'] . "/" . $onion . ".conf", $nginxConf) === false) serverError("Failed to write Nginx configuration."); // Reload Nginx exec(CONF['ht']['sudo_path'] . " " . CONF['ht']['systemctl_path'] . " reload nginx", result_code: $code); if ($code !== 0) serverError("Failed to reload Nginx."); // Tell the user their site address success("L'adresse de votre service Onion HTTP est : http://" . $onion . "/");