servnest/public/ns/zone.php

92 lines
2.4 KiB
PHP
Raw Normal View History

2022-04-23 01:57:43 +02:00
<?php require "../../common/top.php"; ?>
2021-01-22 21:58:46 +01:00
2021-02-17 22:48:49 +01:00
<form method="post">
2022-04-18 16:05:00 +02:00
<h2>Ajouter une zone</h2>
<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 22:48:49 +01:00
</form>
2021-01-22 21:58:46 +01:00
2021-02-17 22:48:49 +01:00
<?php
2021-01-22 21:58:46 +01:00
2021-02-17 22:48:49 +01:00
if (isset($_POST['domain']) AND isset($_SESSION['username'])) {
2022-04-18 16:05:00 +02:00
antiCSRF();
2021-08-05 14:04:33 +02:00
2022-04-18 16:05:00 +02:00
checkAbsoluteDomainFormat($_POST['domain']);
2022-04-18 16:05:00 +02:00
$db = new PDO('sqlite:' . DB_PATH);
$stmt = $db->prepare("INSERT INTO zones(zone, username) VALUES(:zone, :username)");
2022-04-18 16:05:00 +02:00
$stmt->bindParam(':zone', $_POST['domain']);
$stmt->bindParam(':username', $_SESSION['username']);
2022-04-18 16:05:00 +02:00
$stmt->execute();
2022-04-18 16:05:00 +02:00
$knotZonePath = KNOT_ZONES_PATH . "/" . $_POST['domain'] . "zone";
$knotZone = file_get_contents(NIVER_TEMPLATE_PATH . "/knot.template");
$knotZone = preg_replace("/DOMAIN/", $_POST['domain'], $knotZone);
file_put_contents($knotZonePath, $knotZone);
chmod($knotZonePath, 0660);
2022-04-18 16:05:00 +02:00
exec(KNOTC_PATH . " conf-begin");
exec(KNOTC_PATH . " conf-set 'zone[" . $_POST['domain'] . "]'");
exec(KNOTC_PATH . " conf-set 'zone[" . $_POST['domain'] . "].template' 'niver'");
exec(KNOTC_PATH . " conf-commit");
2022-04-18 16:05:00 +02:00
echo "La requête a été traitée.";
2021-02-17 22:48:49 +01:00
}
2021-01-22 21:58:46 +01:00
2021-02-17 22:48:49 +01:00
?>
2021-01-22 21:58:46 +01:00
<form method="post">
2022-04-18 16:05:00 +02:00
<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>";
}
?>
2022-04-18 16:05:00 +02:00
</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'])) {
2022-04-18 16:05:00 +02:00
nsCheckZonePossession($_POST['zone']);
2022-04-18 16:05:00 +02:00
// Remove Knot zone file
unlink(KNOT_ZONES_PATH . "/" . $_POST['zone'] . "zone");
2021-10-03 18:05:00 +02:00
2022-04-18 16:05:00 +02:00
// Remove Knot tied data
exec(KNOTC_PATH . " zone-purge" . $_POST['zone']);
2021-10-03 18:05:00 +02:00
2022-04-18 16:05:00 +02:00
// Remove from Knot configuration
exec(KNOTC_PATH . " conf-begin");
2022-04-23 01:57:43 +02:00
exec(KNOTC_PATH . " conf-unset 'zone[" . $_POST['zone'] . "]'");
2022-04-18 16:05:00 +02:00
exec(KNOTC_PATH . " conf-commit");
2022-04-18 16:05:00 +02:00
// Remove from Niver's database
$db = new PDO('sqlite:' . DB_PATH);
$stmt = $db->prepare("DELETE FROM zones WHERE zone = :zone AND username = :username");
2022-04-18 16:05:00 +02:00
$stmt->bindParam(':zone', $_POST['zone']);
$stmt->bindParam(':username', $_SESSION['username']);
2022-04-18 16:05:00 +02:00
$stmt->execute();
2022-04-18 16:05:00 +02:00
echo "La requête a été traitée.";
}
?>
2022-04-23 01:57:43 +02:00
<?php require "../../common/bottom.php"; ?>