Unify ns/ forms

This commit is contained in:
Miraty 2021-05-16 16:55:39 +02:00
parent 666261b4d7
commit 7b3484b937
13 changed files with 251 additions and 154 deletions

14
exe.php Normal file
View File

@ -0,0 +1,14 @@
<?php
exec("touch /var/lib/knot/zones/chouquette.atope.art.zone", $output);
var_dump($output);
/*
exec("/usr/sbin/knotc conf-begin", $output);
var_dump($output);
exec("/usr/sbin/knotc conf-abort");
if(function_exists('exec')) {
echo "exec is enabled";
} else {
echo "exec is disabled";
}
*/

46
inc/form/form.ns.inc.php Normal file
View File

@ -0,0 +1,46 @@
<label for="action">Action</label>
<select name="action" id="action">
<option value="add">Ajouter</option>
<option value="delete">Retirer</option>
</select>
<br>
<label for="zone">Zone</label>
<br>
<select required="" name="zone" id="zone">
<option value="" disabled="" selected="">-</option>
<?php
$zones = nsListUserZones($_SESSION['username']);
foreach ($zones as $zone) {
echo "<option value='" . $zone . "'>" . $zone . "</option>";
}
?>
</select>
<fieldset>
<legend><abbr title="Time To Live">TTL</abbr></legend>
<input id="ttl-value" list="ttls" name="ttl-value" size="6" type="number" min="1" max="432000" value="3600" placeholder="3600">
<datalist id="ttls">
<option value="900">
<option value="1800">
<option value="3600">
<option value="10800">
<option value="21600">
<option value="86400">
<option value="432000">
</datalist>
<select name="ttl-multiplier" id="ttl-multiplier">
<option value="1">seconde</option>
<option value="60">minute</option>
<option value="3600">heure</option>
<option value="86400">jour</option>
</select>
</fieldset>
<label for="domain">Domaine</label>
<br>
<input id="domain" placeholder="monsite.atope.art." name="domain" type="text">

View File

@ -2,13 +2,30 @@
if (strpos($_SERVER['PHP_SELF'], "inc.php") !== false)
exit("This file is meant to be included.");
function nsTtl($value, $multiplier) {
$ttl = $value * $multiplier;
function nsCommonRequirements() {
if (isset($_POST['action'])
AND isset($_POST['zone'])
AND isset($_POST['domain'])
AND isset($_POST['ttl-value'])
AND isset($_POST['ttl-multiplier'])
AND isset($_SESSION['username'])
) {
return true;
}
}
if (!($ttl >= 300 AND $ttl <= 432000))
function nsParseCommonRequirements() {
$values['action'] = checkAction($_POST['action']);
nsCheckZonePossession($_POST['zone']);
checkAbsoluteDomainFormat($_POST['domain']);
$values['ttl'] = $_POST['ttl-value'] * $_POST['ttl-multiplier'];
if (!($values['ttl'] >= 300 AND $values['ttl'] <= 432000))
exit("Erreur : le TTL doit être compris entre 5 minutes et 5 jours (entre 300 et 432000 secondes)");
return $ttl;
return $values;
}
function nsListUserZones($username) {

View File

@ -14,7 +14,7 @@ switch (SERVICE) {
$page['title'] = "Obtenir les enregistrements DS";
break;
case "ip":
$page['title'] = "Enregistrements A ou AAAA";
$page['title'] = "Enregistrements A et AAAA";
break;
case "ns":
$page['title'] = "Enregistrement NS";
@ -25,6 +25,12 @@ switch (SERVICE) {
case "caa":
$page['title'] = "Enregistrement CAA";
break;
case "srv":
$page['title'] = "Enregistrement SRV";
break;
case "mx":
$page['title'] = "Enregistrement MX";
break;
case "zone":
$page['title'] = "Ajouter une zone";
break;

View File

@ -10,7 +10,6 @@ form {
input, select {
border-radius: 12px;
height: 30px;
font-size: @fontSize;
margin: 5px;
height: 100%;

View File

@ -1,31 +1,9 @@
<?php include "../top.inc.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>
<br>
<label for="zone">Zone</label>
<br>
<select required="" name="zone" id="zone">
<option value="" disabled="" selected="">---</option>
<?php
$zones = nsListUserZones($_SESSION['username']);
<?php require "../inc/form/form.ns.inc.php"; ?>
foreach ($zones as $zone) {
echo "<option value='" . $zone . "'>" . $zone . "</option>";
}
?>
</select>
<br>
<?php require "../inc/html/ttl.ns.inc.php"; ?>
<br>
<label for="domain">Domaine</label>
<br>
<input id="domain" placeholder="monsite.atope.art." name="domain" type="text">
<br>
<label for="flag">Flag</label>
<br>
@ -44,17 +22,13 @@
<?php
if (
isset($_POST['zone'])
AND isset($_POST['domain'])
AND isset($_POST['ttl-value'])
AND isset($_POST['ttl-multiplier'])
AND isset($_POST['action'])
AND isset($_POST['flag'])
AND isset($_POST['tag'])
AND isset($_POST['value'])
AND isset($_SESSION['username'])
) {
if (nsCommonRequirements()
AND isset($_POST['flag'])
AND isset($_POST['tag'])
AND isset($_POST['value'])
) {
$values = nsParseCommonRequirements();
if (!($_POST['flag'] >= 0 AND $_POST['flag'] <= 255))
exit("ERROR: Wrong value for flag");
@ -65,19 +39,14 @@ if (
if (!(preg_match("/^[a-z0-9.-]{1,255}$/", $_POST['value'])))
exit("ERROR: Wrong value for value");
nsCheckZonePossession($_POST['zone']);
checkAbsoluteDomainFormat($_POST['domain']);
$action = checkAction($_POST['action']);
$ttl = nsTtl($_POST['ttl-value'], $_POST['ttl-multiplier']);
exec(KNOTC_PATH . " zone-begin " . $_POST['zone']);
exec(KNOTC_PATH . " zone-" . $action . "set " . $_POST['zone'] . " " . $_POST['domain'] . " " . $ttl . " IN CAA " . $_POST['flag'] . " " . $_POST['tag'] . " " . $_POST['value']);
exec(KNOTC_PATH . " zone-" . $values['action'] . "set " . $_POST['zone'] . " " . $_POST['domain'] . " " . $values['ttl'] . " IN CAA " . $_POST['flag'] . " " . $_POST['tag'] . " " . $_POST['value']);
exec(KNOTC_PATH . " zone-commit " . $_POST['zone']);
echo "Enregistrement ajouté";
}
?>
<?php include "../bottom.inc.php"; ?>

View File

@ -21,10 +21,6 @@
<dd>
Associer du texte à un domaine
</dd>
<dt><a class="nsButton" href="tlsa">Enregistrement <abbr title="Transport Layer Security Association">TLSA</abbr></a></dt>
<dd>
Mettre en place <abbr title="DNS-based Authentication of Named Entities">DANE</abbr> en indiquant l'empreinte d'un certificat <abbr title="Transport Layer Security">TLS</abbr>
</dd>
<dt><a class="nsButton" href="caa">Enregistrement <abbr title="Certification Authority Authorization">CAA</abbr></a></dt>
<dd>
Indiquer les seules autorités de certifications autorisée à signer les domaines
@ -37,6 +33,11 @@
<dd>
Indiquer le serveur mail pour un domaine
</dd>
<!--
<dt><a class="nsButton" href="tlsa">Enregistrement <abbr title="Transport Layer Security Association">TLSA</abbr></a></dt>
<dd>
Mettre en place <abbr title="DNS-based Authentication of Named Entities">DANE</abbr> en indiquant l'empreinte d'un certificat <abbr title="Transport Layer Security">TLS</abbr>
</dd>
<dt><a class="nsButton" href="loc">Enregistrement LOC</a></dt>
<dd>
Indiquer la localisation physique d'un domaine
@ -51,8 +52,8 @@
</dd>
<dt><a class="nsButton" href="dname">Enregistrement <abbr title="Delegation NAME">DNAME</abbr></a></dt>
<dd>
Définir les sous-domains d'un domaine comme étant les alias des sous-domaines d'un autre domaine
</dd>
Définir les sous-domaines d'un domaine comme étant les alias des sous-domaines d'un autre domaine
</dd>-->
</dl>
<?php require "../bottom.inc.php"; ?>

View File

@ -9,45 +9,19 @@
</p>
<form method="post">
<label for="action">Action</label>
<select name="action" id="action">
<option value="add">Ajouter</option>
<option value="delete">Retirer</option>
</select>
<?php require "../inc/form/form.ns.inc.php"; ?>
<br>
<label for="zone">Zone</label><br>
<select required="" name="zone" id="zone">
<option value="" disabled="" selected="">---</option>
<?php
$zones = nsListUserZones($_SESSION['username']);
foreach ($zones as $zone) {
echo "<option value='" . $zone . "'>" . $zone . "</option>";
}
?>
</select>
<br>
<label for="domain">Domaine</label><br>
<input required="" id="domain" name="domain" type="text" placeholder="www.domaine."><br>
<label for="ttl"><abbr title="Time To Live">TTL</abbr></label><br>
<input required="" id="ttl" list="ttls" name="ttl" size="10" type="number" min="600" max="604800" value="3600" placeholder="3600"><br>
<datalist id="ttls">
<option value="900">
<option value="3600">
<option value="10800">
<option value="86400">
<option value="604800">
</datalist>
<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="2a0b:cbc0:1103:2::106f ou 45.13.104.169"><br>
<input value="Valider" type="submit">
</form>
<?php
if (nsCommonRequirements()
AND isset($_POST['ip'])
) {
if (isset($_POST['domain']) AND isset($_POST['ip']) AND isset($_POST['zone']) AND isset($_POST['action'])) {
$values = nsParseCommonRequirements();
checkIpFormat($_POST['ip']);
@ -56,12 +30,10 @@ if (isset($_POST['domain']) AND isset($_POST['ip']) AND isset($_POST['zone']) AN
else if (filter_var($_POST['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))
$record = "AAAA";
else
exit("Erreur inconnue sur le format de l'IP");
$action = checkAction($_POST['action']);
exit("ERROR: unknown IP format");
exec(KNOTC_PATH . " zone-begin " . $_POST['zone']);
exec(KNOTC_PATH . " zone-" . $action . "set " . $_POST['zone'] . " " . $_POST['domain'] . " 3600 " . $record . " " . $_POST['ip']);
exec(KNOTC_PATH . " zone-" . $values['action'] . "set " . $_POST['zone'] . " " . $_POST['domain'] . " " . $values['ttl'] . " " . $record . " " . $_POST['ip']);
exec(KNOTC_PATH . " zone-commit " . $_POST['zone']);
echo "Enregistrement ajouté";

53
ns/mx.php Normal file
View File

@ -0,0 +1,53 @@
<?php include "../top.inc.php"; ?>
<form method="post">
<?php require "../inc/form/form.ns.inc.php"; ?>
<br>
<label for="priority">Priorité</label>
<br>
<input id="priority" min="0" max="65535" value="0" placeholder="0" name="priority" type="number">
<br>
<label for="host">Hôte</label>
<br>
<input id="host" minlenght="1" maxlength="128" placeholder="mail.exemple." name="host" type="text">
<br>
<input value="Valider" type="submit">
</form>
<?php
if (nsCommonRequirements()
AND isset($_POST['priority'])
AND isset($_POST['weight'])
AND isset($_POST['port'])
AND isset($_POST['target'])
) {
$values = nsParseCommonRequirements();
if (!($_POST['priority'] >= 0 AND $_POST['priority'] <= 255))
exit("ERROR: Wrong value for priority");
if (!($_POST['weight'] >= 0 AND $_POST['weight'] <= 255))
exit("ERROR: Wrong value for weight");
if (!($_POST['port'] >= 0 AND $_POST['port'] <= 65535))
exit("ERROR: Wrong value for port");
checkAbsoluteDomainFormat($_POST['target']);
exec(KNOTC_PATH . " zone-begin " . $_POST['zone']);
exec(KNOTC_PATH . " zone-" . $values['action'] . "set " . $_POST['zone'] . " " . $_POST['domain'] . " " . $values['ttl'] . " IN MX " . $_POST['priority'] . " " . $_POST['weight'] . " " . $_POST['port'] . " " . $_POST['target']);
exec(KNOTC_PATH . " zone-commit " . $_POST['zone']);
echo "Enregistrement ajouté";
}
?>
<?php include "../bottom.inc.php"; ?>

View File

@ -1,29 +1,7 @@
<?php include "../top.inc.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>
<br>
<label for="zone">Zone</label>
<br>
<select required="" name="zone" id="zone">
<option value="" disabled="" selected="">---</option>
<?php
$zones = nsListUserZones($_SESSION['username']);
foreach ($zones as $zone) {
echo "<option value='" . $zone . "'>" . $zone . "</option>";
}
?>
</select>
<br>
<label for="domain">Domaine</label>
<br>
<input id="domain" placeholder="monsite.atope.art." name="domain" type="text">
<?php require "../inc/form/form.ns.inc.php"; ?>
<br>
<label for="ns">Serveur de nom</label>
<br>
@ -33,17 +11,16 @@
</form>
<?php
if (nsCommonRequirements()
AND isset($_POST['ns'])
) {
if (isset($_POST['zone']) AND isset($_POST['domain']) AND isset($_POST['action']) AND isset($_POST['ns']) AND isset($_SESSION['username'])) {
$values = nsParseCommonRequirements();
nsCheckZonePossession($_POST['zone']);
checkAbsoluteDomainFormat($_POST['domain']);
checkAbsoluteDomainFormat($_POST['ns']);
$action = checkAction($_POST['action']);
exec(KNOTC_PATH . " zone-begin " . $_POST['zone']);
exec(KNOTC_PATH . " zone-" . $action . "set " . $_POST['zone'] . " " . $_POST['domain'] . " 3600 IN NS " . $_POST['ns']);
exec(KNOTC_PATH . " zone-" . $values['action'] . "set " . $_POST['zone'] . " " . $_POST['domain'] . " " . $values['ttl'] . " IN NS " . $_POST['ns']);
exec(KNOTC_PATH . " zone-commit " . $_POST['zone']);
echo "Enregistrement ajouté";
}

65
ns/srv.php Normal file
View File

@ -0,0 +1,65 @@
<?php include "../top.inc.php"; ?>
<form method="post">
<?php require "../inc/form/form.ns.inc.php"; ?>
<br>
<label for="priority">Priorité</label>
<br>
<input id="priority" min="0" max="65535" value="0" placeholder="0" name="priority" type="number">
<br>
<label for="weight">Poids</label>
<br>
<input id="weight" min="0" max="65535" value="0" placeholder="0" name="weight" type="number">
<br>
<label for="port">Port</label>
<br>
<input id="port" min="0" max="65535" placeholder="32768" name="port" type="number">
<br>
<label for="target">Cible</label>
<br>
<input id="target" minlenght="1" maxlength="128" placeholder="service.exemple.org." name="target" type="text">
<br>
<input value="Valider" type="submit">
</form>
<?php
if (nsCommonRequirements()
AND isset($_POST['priority'])
AND isset($_POST['weight'])
AND isset($_POST['port'])
AND isset($_POST['target'])
) {
$values = nsParseCommonRequirements();
if (!($_POST['priority'] >= 0 AND $_POST['priority'] <= 65535))
exit("ERROR: Wrong value for priority");
if (!($_POST['weight'] >= 0 AND $_POST['weight'] <= 65535))
exit("ERROR: Wrong value for weight");
if (!($_POST['port'] >= 0 AND $_POST['port'] <= 65535))
exit("ERROR: Wrong value for port");
checkAbsoluteDomainFormat($_POST['target']);
exec(KNOTC_PATH . " zone-begin " . $_POST['zone']);
exec(KNOTC_PATH . " zone-" . $values['action'] . "set " . $_POST['zone'] . " " . $_POST['domain'] . " " . $values['ttl'] . " IN SRV " . $_POST['priority'] . " " . $_POST['weight'] . " " . $_POST['port'] . " " . $_POST['target']);
exec(KNOTC_PATH . " zone-commit " . $_POST['zone']);
echo "Enregistrement ajouté";
}
?>
<?php include "../bottom.inc.php"; ?>

View File

@ -1,29 +1,7 @@
<?php include "../top.inc.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>
<br>
<label for="zone">Zone</label>
<br>
<select required="" name="zone" id="zone">
<option value="" disabled="" selected="">---</option>
<?php
$zones = nsListUserZones($_SESSION['username']);
foreach ($zones as $zone) {
echo "<option value='" . $zone . "'>" . $zone . "</option>";
}
?>
</select>
<br>
<label for="domain">Domaine</label>
<br>
<input id="domain" placeholder="monsite.atope.art." name="domain" type="text">
<?php require "../inc/form/form.ns.inc.php"; ?>
<br>
<label for="txt">Texte</label>
<br>
@ -33,22 +11,17 @@
</form>
<?php
if (nsCommonRequirements()
AND isset($_POST['txt'])
) {
if (isset($_POST['zone']) AND isset($_POST['domain']) AND isset($_POST['action']) AND isset($_POST['txt']) AND isset($_SESSION['username'])) {
$values = nsParseCommonRequirements();
if (!(preg_match("¤^[a-zA-Z0-9 =:!%$+/\()[\]_-]{5,8192}", $_POST['txt'])))
if (!(preg_match("/^[a-zA-Z0-9 =:!%$+\/\()[\]_-]{5,8192}$/", $_POST['txt'])))
exit("ERROR : Wrong caracter or wrong caracter quantity");
nsCheckZonePossession($_POST['zone']);
checkAbsoluteDomainFormat($_POST['domain']);
$action = checkAction($_POST['action']);
$test = ' 3600 IN TXT \"' . $_POST['txt'] . '\"';
echo $test;
exec(KNOTC_PATH . " zone-begin " . $_POST['zone']);
exec(KNOTC_PATH . " zone-" . $action . "set " . $_POST['zone'] . " " . $_POST['domain'] . ' 3600 IN TXT \"' . $_POST['txt'] . '\"');
exec(KNOTC_PATH . " zone-" . $values['action'] . "set " . $_POST['zone'] . " " . $_POST['domain'] . " " . $values['txt'] . ' IN TXT \"' . $_POST['txt'] . '\"');
exec(KNOTC_PATH . " zone-commit " . $_POST['zone']);
echo "Enregistrement ajouté";
}

View File

@ -31,8 +31,13 @@ if (isset($_POST['domain']) AND isset($_SESSION['username'])) {
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";
exec(KNOTC_PATH . " conf-commit");
/*
exec("/usr/sbin/knotc conf-begin");
exec("/usr/sbin/knotc conf-set 'zone[gaalde.atope.art.]'");
exec("/usr/sbin/knotc conf-set 'zone[gaalde.atope.art.].template' 'niver'");
exec("/usr/sbin/knotc conf-commit");
*/
echo "La requête a été traitée.";
}