servnest/public/reg/glue.php

69 lines
2 KiB
PHP

<?php require "../../common/html.php"; ?>
<form method="post">
<label for="action">Action</label>
<select name="action" id="action">
<option value="add">Ajouter</option>
<option value="delete">Retirer</option>
</select>
<fieldset>
<legend>Domaine</legend>
<div class="elForm">
<label for="subdomain">Sous-domaine</label>
<br>
<input required="" id="subdomain" placeholder="ns1" name="subdomain" type="text">
</div>
<div class="elForm">
<label for="suffix">Domaine</label>
<br>
<select required="" name="suffix" id="suffix">
<option value="" disabled="" selected="">---</option>
<?php
$suffixes = regListUserDomains($_SESSION['username']);
if ($suffixes) {
foreach($suffixes as $suffix) {
echo "<option value='" . $suffix . "'>." . $suffix . "</option>";
}
}
?>
</select>
</div>
</fieldset>
<label for="ip">IP</label><br>
<input required="" pattern="^[a-f0-9:.]+$" id="ip" name="ip" minlength="7" maxlength="39" size="40" type="text" placeholder="<?= CONF['common']['ipv4_example'] ?> ou <?= CONF['common']['ipv6_example'] ?>">
<br>
<input value="Valider" type="submit">
</form>
<?php
if (isset($_POST['action']) AND isset($_POST['subdomain']) AND isset($_POST['suffix']) AND isset($_POST['ip']) AND isset($_SESSION['username'])) {
antiCSRF();
if (in_array($_POST['suffix'], $suffixes) !== true)
userError("You don't own this domain.");
$domain = $_POST['subdomain'] . "." . $_POST['suffix'];
checkAbsoluteDomainFormat($domain);
$record = checkIpFormat($_POST['ip']);
$action = checkAction($_POST['action']);
$publicSuffix = regGetUpperDomain($_POST['suffix']);
exec(CONF['reg']['knotc_path'] . " zone-begin " . $publicSuffix);
exec(CONF['reg']['knotc_path'] . " zone-" . $action . "set " . $publicSuffix . " " . $domain . " 86400 IN " . $record . " " . $_POST['ip']);
exec(CONF['reg']['knotc_path'] . " zone-commit " . $publicSuffix);
echo "Glue record ajouté";
}
?>
<?php closeHTML(); ?>