Split zone.php and use arrays for page titles

This commit is contained in:
Miraty 2022-06-12 03:28:43 +02:00
parent 265097aa85
commit 41568a9684
6 changed files with 129 additions and 208 deletions

View file

@ -1,115 +1,49 @@
<?php <?php
switch (SERVICE) { define('TITLES', [
'index' => 'niver',
'auth' => [
'index' => 'Authentification',
'login' => 'Se connecter',
'register' => 'Créer un compte',
'password' => 'Changer la clé de passe',
'logout' => 'Déconnexion',
],
'reg' => [
'index' => 'Registre',
'register' => 'Enregistrer un nouveau domaine',
'unregister' => 'Effacer un domaine',
'ns' => 'Ajouter un enregistrement NS',
'ds' => 'Ajouter un enregistrement DS',
'glue' => 'Créer un Glue Record',
],
'ns' => [
'index' => 'Serveurs de noms',
'zone-add' => 'Ajouter une zone',
'zone-del' => 'Effacer une zone',
'dnssec' => 'Afficher les enregistrements DS',
'ip' => 'Enregistrements A et AAAA',
'ns' => 'Enregistrement NS',
'txt' => 'Enregistrement TXT',
'caa' => 'Enregistrement CAA',
'srv' => 'Enregistrement SRV',
'mx' => 'Enregistrement MX',
'sshfp' => 'Enregistrement SSHFP',
'tlsa' => 'Enregistrement TLSA',
],
'ht' => [
'index' => 'Hypertexte',
'add-http-onion' => 'Ajouter un accès HTTP par Onion',
'add-http-dns' => 'Ajouter un accès HTTP par DNS+TLS',
'del-http-onion' => 'Retirer un accès HTTP par Onion',
'del-http-dns' => 'Retirer un accès HTTP par DNS+TLS',
'le' => 'Installer un certificat Let\'s Encrypt',
],
]
);
case "ns": if (SERVICE !== '') {
$page['service'] = "Serveurs de noms"; $page['service'] = TITLES[SERVICE]['index'];
switch (PAGE) { if (PAGE !== 'index')
case "index": $page['title'] = TITLES[SERVICE][PAGE];
$page['title'] = $page['service'];
break;
case "dnssec":
$page['title'] = "Obtenir les enregistrements DS";
break;
case "ip":
$page['title'] = "Enregistrements A et AAAA";
break;
case "ns":
$page['title'] = "Enregistrement NS";
break;
case "txt":
$page['title'] = "Enregistrement TXT";
break;
case "caa":
$page['title'] = "Enregistrement CAA";
break;
case "srv":
$page['title'] = "Enregistrement SRV";
break;
case "mx":
$page['title'] = "Enregistrement MX";
break;
case "sshfp":
$page['title'] = "Enregistrement SSHFP";
break;
case "tlsa":
$page['title'] = "Enregistrement TLSA";
break;
case "zone":
$page['title'] = "Gérer ses zones";
break;
}
break;
case "reg":
$page['service'] = "Registre";
switch (PAGE) {
case "index":
$page['title'] = $page['service'];
break;
case "ns":
$page['title'] = "Ajouter un enregistrement NS";
break;
case "register":
$page['title'] = "Enregistrer un nouveau domaine";
break;
case "unregister":
$page['title'] = "Effacer un domaine";
break;
case "glue":
$page['title'] = "Créer un Glue Record";
break;
case "ds":
$page['title'] = "Ajouter un enregistrement DS";
break;
}
break;
case "auth":
$page['service'] = "Authentification";
switch (PAGE) {
case "index":
$page['title'] = $page['service'];
break;
case "login":
$page['title'] = "Se connecter";
break;
case "register":
$page['title'] = "Créer un compte";
break;
case "password":
$page['title'] = "Changer la clé de passe";
break;
case "logout":
$page['title'] = "Déconnexion";
break;
}
break;
case "ht":
$page['service'] = "Hypertexte";
switch (PAGE) {
case "mkdir":
$page['title'] = "Créer un dossier de site";
break;
case "add-http-onion":
$page['title'] = "Ajouter un accès HTTP par Onion";
break;
case "add-http-dns":
$page['title'] = "Ajouter un accès HTTP par DNS+TLS";
break;
case "del-http-onion":
$page['title'] = "Retirer un accès HTTP par Onion";
break;
case "del-http-dns":
$page['title'] = "Retirer un accès HTTP par DNS+TLS";
break;
case "le":
$page['title'] = "Installer un certificat Let's Encrypt";
break;
case "index":
$page['title'] = $page['service'];
break;
}
break;
} }

View file

@ -19,8 +19,5 @@ function regCheckDomainPossession($domain) {
} }
function regIsFree($domain) { function regIsFree($domain) {
foreach (query('select', 'registry', ['domain' => $domain], 'domain')) { return empty(query('select', 'registry', ['domain' => $domain], 'domain'));
}
} }

View file

@ -1,10 +1,14 @@
<?php require "../../common/html.php"; ?> <?php require "../../common/html.php"; ?>
<dl> <dl>
<dt><a href="zone">Gérer ses zones</a></dt> <dt><a href="zone-add">Ajouter une zone</a></dt>
<dd> <dd>
Pour qu'elle soit gérée par le serveur de noms de Niver Pour qu'elle soit gérée par le serveur de noms de Niver
</dd> </dd>
<dt><a href="zone-del">Effacer une zone</a></dt>
<dd>
Effacer toutes les données d'une zone
</dd>
<dt><a href="dnssec">Obtenir les enregistrements <abbr title="Delegation Signer">DS</abbr></a></dt> <dt><a href="dnssec">Obtenir les enregistrements <abbr title="Delegation Signer">DS</abbr></a></dt>
<dd> <dd>
À indiquer à la zone parente pour activer <abbr title="Domain Name System Security Extensions">DNSSEC</abbr> À indiquer à la zone parente pour activer <abbr title="Domain Name System Security Extensions">DNSSEC</abbr>

37
public/ns/zone-add.php Normal file
View file

@ -0,0 +1,37 @@
<?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();
checkAbsoluteDomainFormat($_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.");
exec(CONF['dns']['knotc_path'] . " conf-begin");
exec(CONF['dns']['knotc_path'] . " conf-set 'zone[" . $_POST['domain'] . "]'");
exec(CONF['dns']['knotc_path'] . " conf-set 'zone[" . $_POST['domain'] . "].template' 'niver'");
exec(CONF['dns']['knotc_path'] . " conf-commit");
success("La requête a été traitée.");

41
public/ns/zone-del.php Normal file
View file

@ -0,0 +1,41 @@
<?php require "../../common/html.php"; ?>
<form method="post">
<label for="zone">Zone</label>
<select required="" name="zone" id="zone">
<option value="" disabled="" selected="">-</option>
<?php
if (isset($_SESSION['username']))
foreach (nsListUserZones($_SESSION['username']) as $zone)
echo " <option value='" . $zone . "'>" . $zone . "</option>\n";
?>
</select>
<br>
<input value="Supprimer toutes les données liées à cette zone" type="submit">
</form>
<?php
switchToFormProcess();
nsCheckZonePossession($_POST['zone']);
// Remove from Knot configuration
exec(CONF['dns']['knotc_path'] . " conf-begin");
exec(CONF['dns']['knotc_path'] . " conf-unset 'zone[" . $_POST['zone'] . "]'");
exec(CONF['dns']['knotc_path'] . " conf-commit");
// Remove Knot zone file
if(unlink(CONF['ns']['knot_zones_path'] . "/" . $_POST['zone'] . "zone") !== true)
serverError("Failed to remove Knot zone file.");
// Remove Knot related data
exec(CONF['dns']['knotc_path'] . " zone-purge " . $_POST['zone']);
// Remove from database
query('delete', 'zones', [
'zone' => $_POST['zone'],
'username' => $_SESSION['username'],
]);
success("Zone effacée.");

View file

@ -1,92 +0,0 @@
<?php require "../../common/html.php"; ?>
<form method="post">
<h2>Ajouter une zone</h2>
<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
if (isset($_POST['domain']) AND isset($_SESSION['username'])) {
checkAbsoluteDomainFormat($_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.
';
file_put_contents($knotZonePath, $knotZone);
chmod($knotZonePath, 0660);
exec(CONF['dns']['knotc_path'] . " conf-begin");
exec(CONF['dns']['knotc_path'] . " conf-set 'zone[" . $_POST['domain'] . "]'");
exec(CONF['dns']['knotc_path'] . " conf-set 'zone[" . $_POST['domain'] . "].template' 'niver'");
exec(CONF['dns']['knotc_path'] . " conf-commit");
echo "La requête a été traitée.";
}
?>
<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
if (isset($_SESSION['username'])) {
$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']);
// Remove from Knot configuration
exec(CONF['dns']['knotc_path'] . " conf-begin");
exec(CONF['dns']['knotc_path'] . " conf-unset 'zone[" . $_POST['zone'] . "]'");
exec(CONF['dns']['knotc_path'] . " conf-commit");
// Remove Knot zone file
unlink(CONF['ns']['knot_zones_path'] . "/" . $_POST['zone'] . "zone");
// Remove Knot related data
exec(CONF['dns']['knotc_path'] . " zone-purge " . $_POST['zone']);
// Remove from Niver's database
$db = new PDO('sqlite:' . DB_PATH);
$stmt = $db->prepare("DELETE FROM zones WHERE zone = :zone AND username = :username");
$stmt->bindValue(':zone', $_POST['zone']);
$stmt->bindValue(':username', $_SESSION['username']);
$stmt->execute();
echo "La requête a été traitée.";
}
?>
<?php closeHTML(); ?>