servnest/public/ns/zone-add.php

38 lines
1.2 KiB
PHP

<?php require "../../common/html.php"; ?>
<form method="post">
<label for="domain">Domaine</label><br>
<input required="" placeholder="domain.<?= PLACEHOLDER_DOMAIN ?>." id="domain" name="domain" type="text"><br>
<input value="Ajouter" type="submit">
</form>
<?php
switchToFormProcess();
$_POST['domain'] = formatAbsoluteDomain($_POST['domain']);
$db = new PDO('sqlite:' . DB_PATH);
$stmt = $db->prepare("INSERT INTO zones(zone, username) VALUES(:zone, :username)");
$stmt->bindValue(':zone', $_POST['domain']);
$stmt->bindValue(':username', $_SESSION['username']);
$stmt->execute();
$knotZonePath = CONF['ns']['knot_zones_path'] . "/" . $_POST['domain'] . "zone";
$knotZone = $_POST['domain'] . ' 3600 SOA ns1.niver.test. admin.niver.test. 1 21600 7200 3628800 3600
' . $_POST['domain'] . ' 86400 NS ns1.niver.test.
';
if (is_int(file_put_contents($knotZonePath, $knotZone)) !== true)
serverError("Failed to write new zone file.");
if (chmod($knotZonePath, 0660) !== true)
serverError("Failed to chmod new zone file.");
knotcConfExec([
"set 'zone[" . $_POST['domain'] . "]'",
"set 'zone[" . $_POST['domain'] . "].template' 'niver'",
]);
success("La requête a été traitée.");