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

76 lines
2.1 KiB
PHP

<?php require "../../common/html.php"; ?>
<p>
Retirer un accès Onion d'un dossier
</p>
<form method="post">
<label for="dir">Dossier ciblé</label><br>
<select required="" name="dir" id="dir">
<option value="" disabled="" selected="">---</option>
<?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>\n";
}
}
?>
</select>
<br>
<input value="Valider" type="submit">
</form>
<?php
switchToFormProcess();
if ($dirsStatuses[$_POST['dir']] !== true)
userError("Wrong value for <code>dir</code>.");
// Delete Tor config
$torConf = file_get_contents(CONF['ht']['tor_config_path']);
if ($torConf === false)
serverError("Failed to read current Tor configuration.");
$torConf = str_replace("HiddenServiceDir " . CONF['ht']['tor_keys_path'] . "/" . $_POST['dir'] . "/
HiddenServicePort 80 [::1]:" . CONF['ht']['internal_onion_http_port'] . "
", "", $torConf);
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.");
// 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
exec(CONF['ht']['sudo_path'] . " " . CONF['ht']['systemctl_path'] . " reload nginx", result_code: $code);
if ($code !== 0)
serverError("Failed to reload Nginx.");
// 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.");