Add unregister.php

This commit is contained in:
Miraty 2022-06-10 03:10:10 +02:00
parent a6873d6ea6
commit e637877ab3
5 changed files with 51 additions and 1 deletions

View file

@ -53,6 +53,9 @@ switch (SERVICE) {
case "register": case "register":
$page['title'] = "Enregistrer un nouveau domaine"; $page['title'] = "Enregistrer un nouveau domaine";
break; break;
case "unregister":
$page['title'] = "Effacer un domaine";
break;
case "glue": case "glue":
$page['title'] = "Créer un Glue Record"; $page['title'] = "Créer un Glue Record";
break; break;

View file

@ -14,6 +14,7 @@ knotc_path = "/usr/sbin/knotc"
[reg] [reg]
registry = niver.test. registry = niver.test.
registry_file = "/srv/ns/niver.test.zone"
ttl = 86400 ttl = 86400
subdomain_regex = "^[a-z0-9]{4,63}$" subdomain_regex = "^[a-z0-9]{4,63}$"

View file

@ -17,6 +17,10 @@
<dd> <dd>
Indiquer les IP de ses serveurs de noms de son sous-domaine de <code><?= CONF['reg']['registry'] ?></code> dont les adresses se trouvent sur ce même sous-domaine Indiquer les IP de ses serveurs de noms de son sous-domaine de <code><?= CONF['reg']['registry'] ?></code> dont les adresses se trouvent sur ce même sous-domaine
</dd> </dd>
<dt><a href="unregister">Effacer un nom de domaine</a></dt>
<dd>
Effacer toutes les données d'un domaine
</dd>
</dl> </dl>
<?php closeHTML(); ?> <?php closeHTML(); ?>

View file

@ -38,4 +38,4 @@ $stmt->bindParam(':last_renewal', $time);
$stmt->execute(); $stmt->execute();
success("Modification effectuée avec succès"); success("Domaine ajouté au registre.");

42
public/reg/unregister.php Normal file
View file

@ -0,0 +1,42 @@
<?php require "../../common/html.php"; ?>
<form method="post">
<label for="domain">Domaine</label>
<br>
<select required="" name="domain" id="domain">
<option value="" disabled="" selected="">---</option>
<?php
if (isset($_SESSION['username']))
foreach(regListUserDomains($_SESSION['username']) as $suffix)
echo " <option value='" . $suffix . "'>." . $suffix . "</option>\n";
?>
</select>
<br>
<input value="Effacer" type="submit">
</form>
<?php
switchToFormProcess();
regCheckDomainPossession($_POST['domain']);
// Add Tor config
$regFile = file_get_contents(CONF['reg']['registry_file']);
if ($regFile === false)
serverError("Failed to read current registry File.");
$regFile = preg_replace("#[^\n]{0,1024}" . $_POST['domain'] . " {0,1024}[^\n]{0,1024}\n#", "", $regFile);
if (file_put_contents(CONF['reg']['registry_file'], $regFile) === false)
serverError("Failed to write new registry file.");
// Remove from Niver's database
$db = new PDO('sqlite:' . DB_PATH);
$stmt = $db->prepare("DELETE FROM registry WHERE domain = :domain AND username = :username");
$stmt->bindParam(':domain', $_POST['domain']);
$stmt->bindParam(':username', $_SESSION['username']);
$stmt->execute();
success("Domaine effacé du registre.");