From 41568a968484e7e965e0f1b8875dd70f445f711c Mon Sep 17 00:00:00 2001 From: Miraty Date: Sun, 12 Jun 2022 03:28:43 +0200 Subject: [PATCH] Split zone.php and use arrays for page titles --- common/pages.php | 156 ++++++++++++----------------------------- fn/reg.php | 5 +- public/ns/index.php | 6 +- public/ns/zone-add.php | 37 ++++++++++ public/ns/zone-del.php | 41 +++++++++++ public/ns/zone.php | 92 ------------------------ 6 files changed, 129 insertions(+), 208 deletions(-) create mode 100644 public/ns/zone-add.php create mode 100644 public/ns/zone-del.php delete mode 100644 public/ns/zone.php diff --git a/common/pages.php b/common/pages.php index 50cbfb4..1e0b667 100644 --- a/common/pages.php +++ b/common/pages.php @@ -1,115 +1,49 @@ '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": - $page['service'] = "Serveurs de noms"; - switch (PAGE) { - case "index": - $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; +if (SERVICE !== '') { + $page['service'] = TITLES[SERVICE]['index']; + if (PAGE !== 'index') + $page['title'] = TITLES[SERVICE][PAGE]; } diff --git a/fn/reg.php b/fn/reg.php index 693c2ad..c865a97 100644 --- a/fn/reg.php +++ b/fn/reg.php @@ -19,8 +19,5 @@ function regCheckDomainPossession($domain) { } function regIsFree($domain) { - foreach (query('select', 'registry', ['domain' => $domain], 'domain')) { - - } - + return empty(query('select', 'registry', ['domain' => $domain], 'domain')); } diff --git a/public/ns/index.php b/public/ns/index.php index 2a07480..baee0b3 100644 --- a/public/ns/index.php +++ b/public/ns/index.php @@ -1,10 +1,14 @@
-
Gérer ses zones
+
Ajouter une zone
Pour qu'elle soit gérée par le serveur de noms de Niver
+
Effacer une zone
+
+ Effacer toutes les données d'une zone +
Obtenir les enregistrements DS
À indiquer à la zone parente pour activer DNSSEC diff --git a/public/ns/zone-add.php b/public/ns/zone-add.php new file mode 100644 index 0000000..c270689 --- /dev/null +++ b/public/ns/zone-add.php @@ -0,0 +1,37 @@ + + +
+
+
+ +
+ +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."); diff --git a/public/ns/zone-del.php b/public/ns/zone-del.php new file mode 100644 index 0000000..0ae5e17 --- /dev/null +++ b/public/ns/zone-del.php @@ -0,0 +1,41 @@ + + +
+ + +
+ +
+ + $_POST['zone'], + 'username' => $_SESSION['username'], +]); + +success("Zone effacée."); diff --git a/public/ns/zone.php b/public/ns/zone.php deleted file mode 100644 index 039a308..0000000 --- a/public/ns/zone.php +++ /dev/null @@ -1,92 +0,0 @@ - - -
-

Ajouter une zone

-
-
- -
- -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."; - -} - -?> - -
-

Supprimer une zone

- - -
- -
- -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."; -} - -?> - -