99 lines
2.5 KiB
PHP
99 lines
2.5 KiB
PHP
<?php require "../../common/top.php"; ?>
|
|
|
|
<p>
|
|
Ajouter un domaine sur un dossier de site<br>
|
|
Le domaine doit pointer vers ces adresses IP :
|
|
<br>IPv4 : <code><?= CONF['ht']['ipv4_address'] ?></code>
|
|
<br>IPv6 : <code><?= CONF['ht']['ipv6_address'] ?></code>
|
|
</p>
|
|
|
|
<form method="post">
|
|
<label for="domain">Domaine sur lequel répondre</label><br>
|
|
<input required="" placeholder="site.<?= CONF['common']['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
|
|
|
|
|
|
|
|
if (isset($_SESSION['username'])) {
|
|
$fsDirs = listFsDirs($_SESSION['username']);
|
|
$dbUsedDirs = listDbDirs($_SESSION['username'], "dns", "http");
|
|
$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", "http");
|
|
|
|
$nginxConf = 'server {
|
|
listen [::1]:' . CONF['ht']['https_port'] . ' ssl http2;
|
|
listen 127.0.0.1:' . CONF['ht']['https_port'] . ' ssl http2;
|
|
server_name ' . $_POST['domain'] . ';
|
|
root ' . CONF['ht']['ht_path'] . '/' . $_SESSION['username'] . '/' . $_POST['dir'] . ';
|
|
|
|
ssl_certificate /etc/ssl/certs/niver.crt;
|
|
ssl_certificate_key /etc/ssl/private/niver.key;
|
|
|
|
include inc/tls.conf;
|
|
|
|
location / {
|
|
try_files $uri $uri.html $uri/ =404;
|
|
}
|
|
}
|
|
';
|
|
file_put_contents(CONF['ht']['nginx_config_path'] . "/" . $_POST['domain'] . ".conf", $nginxConf);
|
|
|
|
// Reload Nginx
|
|
exec(CONF['ht']['sudo_path'] . " " . CONF['ht']['systemctl_path'] . " reload nginx");
|
|
|
|
echo "Accès HTTP par domaine ajouté sur ce dossier !";
|
|
}
|
|
|
|
?>
|
|
|
|
<?php require "../../common/bottom.php"; ?>
|