
9 changed files with 22 additions and 272 deletions
@ -1,89 +0,0 @@ |
|||
<?php require "../top.inc.php"; ?> |
|||
|
|||
<p> |
|||
Ajouter un domaine sur un dossier de site<br> |
|||
Le domaine doit pointer vers ces adresses IP : |
|||
<br>IPv4 : <code><?= IPV4_ADDRESS ?></code> |
|||
<br>IPv6 : <code><?= IPV6_ADDRESS ?></code> |
|||
</p> |
|||
|
|||
<form method="post"> |
|||
<label for="domain">Domaine sur lequel répondre</label><br> |
|||
<input required="" placeholder="capsule.<?= DOMAIN_EXAMPLE ?>" id="domain" name="domain" type="text"><br> |
|||
<label for="dir">Dossier ciblé</label><br> |
|||
<select required="" name="dir" id="dir"> |
|||
<option value="" disabled="" selected="">---</option> |
|||
|
|||
<?php |
|||
|
|||
$fsDirs = listFsDirs($_SESSION['username']); |
|||
$dbUsedDirs = listDbDirs($_SESSION['username'], "dns", "gemini"); |
|||
$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($alreadyEnabledDirs)) { |
|||
foreach ($alreadyEnabledDirs as $dir) { |
|||
echo "<option disabled='' value='" . $dir . "'>" . $dir . "</option>"; |
|||
} |
|||
} |
|||
} |
|||
?> |
|||
</select> |
|||
<br> |
|||
<input value="Valider" type="submit"> |
|||
</form> |
|||
|
|||
<?php |
|||
|
|||
if (isset($_POST['domain']) AND isset($_POST['dir']) AND isset($_SESSION['username'])) { |
|||
|
|||
antiCSRF(); |
|||
|
|||
checkDomainFormat($_POST['domain']); |
|||
|
|||
if (!in_array($_POST['dir'], $notYetEnabledDirs)) |
|||
exit("ERROR : Wrong value for dir"); |
|||
|
|||
addSite($_SESSION['username'], $_POST['dir'], $_POST['domain'], "dns", "gemini"); |
|||
|
|||
// Generate tls keys |
|||
exec(SUDO_PATH . " " . MANIVER_PATH . " gemini-new-certificate " . $_POST['domain']); |
|||
|
|||
// Add to Twins configuration |
|||
$conf = " |
|||
" . $_POST['domain'] . ": |
|||
cert: " . TWINS_PATH . "/tls/" . $_POST['domain'] . ".crt |
|||
key: " . TWINS_PATH . "/tls/" . $_POST['domain'] . ".key |
|||
paths: |
|||
- |
|||
path: / |
|||
root: " . HT_PATH . "/" . $_SESSION['username'] . "/ht/" . $_POST['dir']; |
|||
file_put_contents(TWINS_PATH . "/twins.conf", $conf, FILE_APPEND); |
|||
|
|||
// Reload Twins daemon |
|||
exec(SUDO_PATH . " " . MANIVER_PATH . " reload-twins"); |
|||
|
|||
echo "Accès par domaine ajouté sur ce dossier !"; |
|||
} |
|||
|
|||
?> |
|||
|
|||
<?php require "../bottom.inc.php"; ?> |
@ -1,103 +0,0 @@ |
|||
<?php require "../top.inc.php"; ?> |
|||
<p> |
|||
Ajouter un accès en .onion sur 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 |
|||
|
|||
$fsDirs = listFsDirs($_SESSION['username']); |
|||
$dbUsedDirs = listDbDirs($_SESSION['username'], "onion", "gemini"); |
|||
$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($alreadyEnabledDirs)) { |
|||
foreach ($alreadyEnabledDirs as $dir) { |
|||
echo "<option disabled='' value='" . $dir . "'>" . $dir . "</option>"; |
|||
} |
|||
} |
|||
} |
|||
?> |
|||
</select> |
|||
<br> |
|||
<input value="Valider" type="submit"> |
|||
</form> |
|||
|
|||
<?php |
|||
|
|||
if (isset($_POST['dir']) AND isset($_SESSION['username'])) { |
|||
|
|||
antiCSRF(); |
|||
|
|||
if (!in_array($_POST['dir'], $notYetEnabledDirs)) |
|||
exit("ERROR : Wrong value for dir"); |
|||
|
|||
// Generate a .onion address |
|||
$torConf = file_get_contents(TOR_CONFIG_PATH); |
|||
$torConf = $torConf . "\nHiddenServiceDir " . TOR_KEYS_PATH . "/" . $_POST['dir'] . "/\nHiddenServicePort 1965 [::1]:1965"; |
|||
file_put_contents(TOR_CONFIG_PATH, $torConf); |
|||
|
|||
exec(SUDO_PATH . " " . MANIVER_PATH . " reload-tor", $output); |
|||
addNiverLog("Tor reloaded by " . $_SESSION['username'], $output); |
|||
|
|||
// Copy generated address to a location readable by PHP |
|||
exec(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(HT_PATH . "/" . $_SESSION['username'] . "/ht/" . $_POST['dir'] . "/hostname"); |
|||
$onion = str_replace(array("\r", "\n"), "", $onion); |
|||
|
|||
// Store it in the database |
|||
addSite($_SESSION['username'], $_POST['dir'], $onion, "onion", "gemini"); |
|||
|
|||
// Generate tls keys |
|||
exec(SUDO_PATH . " " . MANIVER_PATH . " gemini-new-certificate " . $onion); |
|||
|
|||
// Add to Twins configuration |
|||
$conf = " |
|||
" . $onion . ": |
|||
cert: " . TWINS_PATH . "/tls/" . $onion . ".crt |
|||
key: " . TWINS_PATH . "/tls/" . $onion . ".key |
|||
paths: |
|||
- |
|||
path: / |
|||
root: " . HT_PATH . "/" . $_SESSION['username'] . "/ht/" . $_POST['dir']; |
|||
file_put_contents(TWINS_PATH . "/twins.conf", $conf, FILE_APPEND); |
|||
|
|||
// Reload Twins daemon |
|||
exec(SUDO_PATH . " " . MANIVER_PATH . " reload-twins"); |
|||
|
|||
// Tell the user their site address |
|||
echo "<p>L'adresse de votre capsule Onion Gemini est : <br><a href='gemini://" . $onion . "'<code>gemini://" . $onion . "</code></a></p>"; |
|||
|
|||
} |
|||
|
|||
?> |
|||
|
|||
<?php require "../bottom.inc.php"; ?> |
Loading…
Reference in new issue