servnest/ns/zone.php

82 lines
2.2 KiB
PHP
Raw Normal View History

2021-01-22 20:58:46 +00:00
<?php require "../top.inc.php"; ?>
2021-02-17 21:48:49 +00:00
<form method="post">
<h2>Ajouter une zone</h2>
2021-02-17 21:48:49 +00:00
<label for="domain">Domaine</label><br>
<input required="" placeholder="domain.<?= DOMAIN_EXAMPLE ?>." id="domain" name="domain" type="text"><br>
<input value="Ajouter" type="submit">
2021-02-17 21:48:49 +00:00
</form>
2021-01-22 20:58:46 +00:00
2021-02-17 21:48:49 +00:00
<?php
2021-01-22 20:58:46 +00:00
2021-02-17 21:48:49 +00:00
if (isset($_POST['domain']) AND isset($_SESSION['username'])) {
2021-02-17 21:48:49 +00:00
checkAbsoluteDomainFormat($_POST['domain']);
2021-02-17 21:48:49 +00:00
$db = new PDO('sqlite:' . DB_PATH);
$stmt = $db->prepare("INSERT INTO zones(zone, username) VALUES(:zone, :username)");
2021-02-17 21:48:49 +00:00
$stmt->bindParam(':zone', $_POST['domain']);
$stmt->bindParam(':username', $_SESSION['username']);
2021-02-17 21:48:49 +00:00
$stmt->execute();
$knotZonePath = KNOT_ZONES_PATH . "/" . $_POST['domain'] . "zone";
$knotZone = file_get_contents(NIVER_TEMPLATE_PATH . "/knot.template");
$knotZone = preg_replace("/DOMAIN/", $_POST['domain'], $knotZone);
2021-05-14 19:10:56 +00:00
file_put_contents($knotZonePath, $knotZone);
chmod($knotZonePath, 0660);
2021-02-19 12:29:04 +00:00
exec(KNOTC_PATH . " conf-begin");
exec(KNOTC_PATH . " conf-set 'zone[" . $_POST['domain'] . "]'");
2021-05-14 19:10:56 +00:00
exec(KNOTC_PATH . " conf-set 'zone[" . $_POST['domain'] . "].template' 'niver'");
2021-05-16 14:55:39 +00:00
exec(KNOTC_PATH . " conf-commit");
2021-02-17 21:48:49 +00:00
echo "La requête a été traitée.";
2021-02-17 21:48:49 +00:00
}
2021-01-22 20:58:46 +00:00
2021-02-17 21:48:49 +00:00
?>
2021-01-22 20:58:46 +00:00
<form method="post">
<h2>Supprimer une zone</h2>
<label for="zone">Zone</label>
<select required="" name="zone" id="zone">
<option value="" disabled="" selected="">-</option><?php
$zones = nsListUserZones($_SESSION['username']);
if (!empty($zones)) {
foreach ($zones as $zone)
echo "<option value='" . $zone . "'>" . $zone . "</option>";
}
?>
</select>
<br>
<input value="Supprimer toutes les données liées à cette zone" type="submit">
</form>
<?php
if (isset($_POST['zone']) AND isset($_SESSION['username'])) {
nsCheckZonePossession($_POST['zone']);
$knotZonePath = KNOT_ZONES_PATH . "/" . $_POST['zone'] . "zone";
unlink($knotZonePath);
$db = new PDO('sqlite:' . DB_PATH);
$stmt = $db->prepare("DELETE FROM zones WHERE zone = :zone AND username = :username");
$stmt->bindParam(':zone', $_POST['zone']);
$stmt->bindParam(':username', $_SESSION['username']);
$stmt->execute();
echo "La requête a été traitée.";
}
?>
2021-01-22 20:58:46 +00:00
<?php require "../bottom.inc.php"; ?>