2022-05-22 14:59:45 +02:00
|
|
|
<?php require "../../common/html.php"; ?>
|
2021-02-16 19:20:19 +01:00
|
|
|
<p>
|
2022-04-18 16:05:00 +02:00
|
|
|
Ajouter un accès en .onion sur un dossier
|
2021-02-16 19:20:19 +01:00
|
|
|
</p>
|
|
|
|
|
|
|
|
<form method="post">
|
2022-04-18 16:05:00 +02:00
|
|
|
<label for="dir">Dossier ciblé</label><br>
|
|
|
|
<select required="" name="dir" id="dir">
|
|
|
|
<option value="" disabled="" selected="">---</option>
|
|
|
|
|
2022-05-21 02:15:36 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
if (isset($_SESSION['username'])) {
|
|
|
|
$dirsStatuses = dirsStatuses($_SESSION['username'], "onion", "http");
|
|
|
|
|
|
|
|
foreach ($dirsStatuses as $dir => $alreadyEnabled) {
|
|
|
|
$disabled = $alreadyEnabled ? "disabled='' " : "";
|
|
|
|
echo " <option " . $disabled . "value='" . $dir . "'>" . $dir . "</option>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
2022-04-18 16:05:00 +02:00
|
|
|
</select>
|
|
|
|
<br>
|
|
|
|
<input value="Valider" type="submit">
|
2021-02-16 19:20:19 +01:00
|
|
|
</form>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
|
2022-05-31 17:31:48 +02:00
|
|
|
switchToFormProcess();
|
2021-02-16 19:20:19 +01:00
|
|
|
|
2022-05-31 17:31:48 +02:00
|
|
|
if ($dirsStatuses[$_POST['dir']] !== false)
|
|
|
|
userError("Wrong value for <code>dir</code>.");
|
2021-02-16 19:20:19 +01:00
|
|
|
|
2022-05-31 17:31:48 +02:00
|
|
|
// Generate a .onion address
|
|
|
|
$torConf = file_get_contents(CONF['ht']['tor_config_path']);
|
|
|
|
$torConf = $torConf . "HiddenServiceDir " . CONF['ht']['tor_keys_path'] . "/" . $_POST['dir'] . "/
|
2022-05-20 00:15:13 +02:00
|
|
|
HiddenServicePort 80 [::1]:" . CONF['ht']['internal_onion_http_port'] . "
|
2022-05-04 17:41:17 +02:00
|
|
|
";
|
2022-05-31 17:31:48 +02:00
|
|
|
file_put_contents(CONF['ht']['tor_config_path'], $torConf);
|
|
|
|
|
|
|
|
exec(CONF['ht']['sudo_path'] . " " . CONF['ht']['systemctl_path'] . " reload tor", $output);
|
|
|
|
addNiverLog("Tor reloaded by " . $_SESSION['username'], $output);
|
|
|
|
|
|
|
|
// Copy generated address to a location readable by PHP
|
|
|
|
exec(CONF['ht']['sudo_path'] . " " . MANIVER_PATH . " export-tor " . $_SESSION['username'] . " " . $_POST['dir'], $output);
|
|
|
|
addNiverLog("Tor data exported by " . $_SESSION['username'], $output);
|
|
|
|
|
|
|
|
// Wait
|
|
|
|
sleep(1);
|
|
|
|
|
|
|
|
// Get the address generated by Tor
|
|
|
|
$onion = file_get_contents(CONF['ht']['ht_path'] . "/" . $_SESSION['username'] . "/" . $_POST['dir'] . "/hostname");
|
|
|
|
$onion = str_replace(array("\r", "\n"), "", $onion);
|
|
|
|
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 it to Nginx
|
|
|
|
$nginxConf = file_get_contents(NIVER_TEMPLATE_PATH . "/nginx/onion.template");
|
|
|
|
$nginxConf = str_replace("{{CONF['ht']['internal_onion_http_port']}}", CONF['ht']['internal_onion_http_port'], $nginxConf);
|
|
|
|
$nginxConf = str_replace("{{DOMAIN}}", $onion, $nginxConf);
|
|
|
|
$nginxConf = str_replace("{{CONF['ht']['ht_path']}}", CONF['ht']['ht_path'], $nginxConf);
|
|
|
|
$nginxConf = str_replace("{{USERNAME}}", $_SESSION['username'], $nginxConf);
|
|
|
|
$nginxConf = str_replace("{{DIR}}", $_POST['dir'], $nginxConf);
|
|
|
|
file_put_contents(CONF['ht']['nginx_config_path'] . "/" . $_POST['dir'] . ".conf", $nginxConf);
|
|
|
|
|
|
|
|
// Reload Nginx
|
|
|
|
exec(CONF['ht']['sudo_path'] . " " . CONF['ht']['systemctl_path'] . " reload nginx", $output);
|
|
|
|
addNiverLog("Nginx reloaded by " . $_SESSION['username'], $output);
|
|
|
|
|
|
|
|
// Tell the user their site address
|
|
|
|
success("L'adresse de votre service Onion HTTP est : <a href='http://" . $onion . "/'<code>http://" . $onion . "/</code></a>");
|