servnest/public/ht/del-http-onion.php

76 lines
2.1 KiB
PHP
Raw Normal View History

<?php require "../../common/html.php"; ?>
2022-06-11 23:50:14 +02:00
2021-02-16 19:20:19 +01:00
<p>
2022-06-11 23:50:14 +02:00
Retirer un accès Onion d'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) {
2022-06-11 23:42:48 +02:00
$disabled = $alreadyEnabled ? "" : "disabled='' ";
echo " <option " . $disabled . "value='" . $dir . "'>" . $dir . "</option>\n";
2022-05-21 02:15:36 +02:00
}
}
?>
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
switchToFormProcess();
2021-02-16 19:20:19 +01:00
2022-06-11 23:42:48 +02:00
if ($dirsStatuses[$_POST['dir']] !== true)
userError("Wrong value for <code>dir</code>.");
2021-02-16 19:20:19 +01:00
2022-06-11 23:42:48 +02:00
// Delete Tor config
$torConf = file_get_contents(CONF['ht']['tor_config_path']);
2022-06-09 02:56:21 +02:00
if ($torConf === false)
serverError("Failed to read current Tor configuration.");
2022-06-11 23:42:48 +02:00
$torConf = str_replace("HiddenServiceDir " . CONF['ht']['tor_keys_path'] . "/" . $_POST['dir'] . "/
HiddenServicePort 80 [::1]:" . CONF['ht']['internal_onion_http_port'] . "
2022-06-11 23:42:48 +02:00
", "", $torConf);
2022-06-09 02:56:21 +02:00
if (file_put_contents(CONF['ht']['tor_config_path'], $torConf) === false)
serverError("Failed to write new Tor configuration.");
2022-06-07 17:58:46 +02:00
// Reload Tor
2022-06-09 02:56:21 +02:00
exec(CONF['ht']['sudo_path'] . " " . CONF['ht']['systemctl_path'] . " reload " . CONF['ht']['tor_service'], $output, $code);
if ($code !== 0)
serverError("Failed to reload Tor.");
2022-06-11 23:42:48 +02:00
// Delete Nginx config
$onion = query('select', 'sites', [
'username' => $_SESSION['username'],
'domain_type' => 'onion',
'protocol' => 'http',
'site_dir' => $_POST['dir'],
], 'domain')[0];
if (unlink(CONF['ht']['nginx_config_path'] . "/" . $onion . ".conf") !== true)
serverError("Failed to delete Nginx configuration.");
// Reload Nginx
2022-06-09 02:56:21 +02:00
exec(CONF['ht']['sudo_path'] . " " . CONF['ht']['systemctl_path'] . " reload nginx", result_code: $code);
if ($code !== 0)
serverError("Failed to reload Nginx.");
2022-06-11 23:42:48 +02:00
// Delete from database
query('delete', 'sites', [
'username' => $_SESSION['username'],
'domain_type' => 'onion',
'protocol' => 'http',
'site_dir' => $_POST['dir'],
]);
success("Accès retiré avec succès.");