reg/register: add "Check availability" feature

This commit is contained in:
Miraty 2023-03-19 22:22:34 +01:00
parent 15ddd77bc4
commit ed05d4aab9
6 changed files with 86 additions and 52 deletions

View file

@ -4,7 +4,7 @@ form {
margin-bottom: 0.6rem; margin-bottom: 0.6rem;
} }
input, select, textarea { input, button, select, textarea {
border-radius: 0.5rem; border-radius: 0.5rem;
font-size: 1rem; font-size: 1rem;
margin: 0.3rem; margin: 0.3rem;

View file

@ -1,6 +1,6 @@
<?php <?php
function output($code, $msg = '', $logs = ['']) { function output($code, $msg = '', $logs = [''], $data = []) {
http_response_code($code); http_response_code($code);
$shortCode = intval($code / 100); $shortCode = intval($code / 100);
if ($shortCode === 5) if ($shortCode === 5)
@ -10,7 +10,7 @@ function output($code, $msg = '', $logs = ['']) {
4 => '<p><output>' . _('<strong>User error</strong>: ') . '<em>' . $msg . '</em></output></p>' . LF, 4 => '<p><output>' . _('<strong>User error</strong>: ') . '<em>' . $msg . '</em></output></p>' . LF,
5 => '<p><output>' . _('<strong>Server error</strong>: ') . '<em>' . $msg . '</em></output></p>' . LF, 5 => '<p><output>' . _('<strong>Server error</strong>: ') . '<em>' . $msg . '</em></output></p>' . LF,
}; };
displayPage(['final_message' => $final_message]); displayPage(array_merge(['final_message' => $final_message], $data));
} }
function insert($table, $values) { function insert($table, $values) {

View file

@ -218,7 +218,7 @@ msgstr "Définir un domaine comme étant l'alias d'un autre"
#: pages.php:140 #: pages.php:140
msgid "Define all subdomains of a domain as aliases of subdomains of another domain" msgid "Define all subdomains of a domain as aliases of subdomains of another domain"
msgstr "Définir la descendance d'un domain comme alias de la descendance d'un autre domaine" msgstr "Définir la descendance d'un domaine comme alias de la descendance d'un autre domaine"
#: pages.php:144 #: pages.php:144
msgid "Store geographic coordinates" msgid "Store geographic coordinates"
@ -272,15 +272,15 @@ msgstr "Supprimer un accès"
msgid "Delete an existing HTTP access from a subdirectory of the SFTP space" msgid "Delete an existing HTTP access from a subdirectory of the SFTP space"
msgstr "Retirer un accès HTTP existant d'un sous-dossier de l'espace SFTP" msgstr "Retirer un accès HTTP existant d'un sous-dossier de l'espace SFTP"
#: router.php:137 view.php:39 #: router.php:133 view.php:39
msgid "This service is currently under maintenance. No action can be taken on it until an administrator finishes repairing it." msgid "This service is currently under maintenance. No action can be taken on it until an administrator finishes repairing it."
msgstr "Ce service est en cours de maintenance. Aucune action ne peut être effectuée avant qu'ane administrataire termine de le réparer." msgstr "Ce service est en cours de maintenance. Aucune action ne peut être effectuée avant qu'ane administrataire termine de le réparer."
#: router.php:147 #: router.php:144
msgid "You need to be logged in to do this." msgid "You need to be logged in to do this."
msgstr "Vous devez être connecté·e à un compte pour faire cela." msgstr "Vous devez être connecté·e à un compte pour faire cela."
#: router.php:149 #: router.php:146
msgid "This account doesn't exist anymore. Log out to end this ghost session." msgid "This account doesn't exist anymore. Log out to end this ghost session."
msgstr "Ce compte n'existe plus. Déconnectez-vous pour terminer cette session fantôme." msgstr "Ce compte n'existe plus. Déconnectez-vous pour terminer cette session fantôme."
@ -360,7 +360,8 @@ msgstr "Ce compte n'existe pas."
msgid "Wrong password." msgid "Wrong password."
msgstr "Clé de passe incorrecte." msgstr "Clé de passe incorrecte."
#: pg-act/auth/password.php:6 #: pg-act/auth/password.php:6 pg-act/auth/unregister.php:4
#: pg-act/auth/username.php:6
msgid "Wrong current password." msgid "Wrong current password."
msgstr "Clé de passe actuelle incorrecte." msgstr "Clé de passe actuelle incorrecte."
@ -368,24 +369,24 @@ msgstr "Clé de passe actuelle incorrecte."
msgid "Password updated." msgid "Password updated."
msgstr "Clé de passe mise à jour." msgstr "Clé de passe mise à jour."
#: pg-act/auth/register.php:10 pg-act/auth/username.php:8 #: pg-act/auth/register.php:10 pg-act/auth/username.php:11
msgid "This username is already taken." msgid "This username is already taken."
msgstr "Cet identifiant est déjà pris." msgstr "Cet identifiant est déjà pris."
#: pg-act/auth/unregister.php:4 #: pg-act/auth/unregister.php:7
msgid "Account deletion must be confirmed." msgid "Account deletion must be confirmed."
msgstr "La suppression du compte doit être confirmée." msgstr "La suppression du compte doit être confirmée."
#: pg-act/auth/unregister.php:10 #: pg-act/auth/unregister.php:13
#, php-format #, php-format
msgid "Your account can't be deleted because the %s service is currently unavailable." msgid "Your account can't be deleted because the %s service is currently unavailable."
msgstr "Votre compte ne peut pas être supprimé car le service %s est actuellement indisponible." msgstr "Votre compte ne peut pas être supprimé car le service %s est actuellement indisponible."
#: pg-act/auth/unregister.php:39 #: pg-act/auth/unregister.php:42
msgid "Account deleted." msgid "Account deleted."
msgstr "Compte supprimé." msgstr "Compte supprimé."
#: pg-act/auth/username.php:17 #: pg-act/auth/username.php:20
msgid "Username updated." msgid "Username updated."
msgstr "Identifiant mis à jour." msgstr "Identifiant mis à jour."
@ -401,7 +402,7 @@ msgstr "Impossible de récupérer l'enregistrement %s."
#: pg-act/ht/add-dns.php:15 pg-act/ht/add-dns.php:21 #: pg-act/ht/add-dns.php:15 pg-act/ht/add-dns.php:21
#, php-format #, php-format
msgid "This domain must have %2$s as its only %1$s record." msgid "This domain must have %2$s as its only %1$s record."
msgstr "Ce domain doit avoir %2$s pour unique enregistrement %1$s." msgstr "Ce domaine doit avoir %2$s pour unique enregistrement %1$s."
#: pg-act/ht/add-dns.php:27 #: pg-act/ht/add-dns.php:27
msgid "No TXT record with the expected format has been found." msgid "No TXT record with the expected format has been found."
@ -484,15 +485,19 @@ msgstr "Zone supprimée."
msgid "This format of subdomain is not allowed." msgid "This format of subdomain is not allowed."
msgstr "Ce format de sous-domaine n'est pas autorisé." msgstr "Ce format de sous-domaine n'est pas autorisé."
#: pg-act/reg/register.php:21 #: pg-act/reg/register.php:27
msgid "This domain is already registered." msgid "This domain is open to registration!"
msgstr "Ce domain est déjà enregistré." msgstr "Ce domaine est disponible à l'enregistrement."
#: pg-act/reg/register.php:24 #: pg-act/reg/register.php:29
msgid "This domain is reserved." msgid "This domain is reserved."
msgstr "Ce domain est réservé." msgstr "Ce domaine est réservé."
#: pg-act/reg/register.php:34 #: pg-act/reg/register.php:31
msgid "This domain is already registered."
msgstr "Ce domaine est déjà enregistré."
#: pg-act/reg/register.php:47
msgid "Domain registered." msgid "Domain registered."
msgstr "Domaine enregistré." msgstr "Domaine enregistré."
@ -598,7 +603,8 @@ msgstr "Identifiant"
msgid "Password" msgid "Password"
msgstr "Clé de passe" msgstr "Clé de passe"
#: pg-view/auth/password.php:2 #: pg-view/auth/password.php:2 pg-view/auth/unregister.php:6
#: pg-view/auth/username.php:2
msgid "Current password" msgid "Current password"
msgstr "Clé de passe actuelle" msgstr "Clé de passe actuelle"
@ -623,20 +629,20 @@ msgstr "Minimum %1$s caractères, ou %2$s caractères si elle contient minuscule
msgid "This will delete every resource managed by the current account, including registered domains, hosted DNS records, websites files and cryptographic keys for Onion services and DNSSEC." msgid "This will delete every resource managed by the current account, including registered domains, hosted DNS records, websites files and cryptographic keys for Onion services and DNSSEC."
msgstr "Ceci supprimera toutes les ressources gérées par le compte actuel, y compris les domaines enregistrés, les enregistrements DNS hébergés, les fichiers des sites et les clés cryptographiques des services Onion et de DNSSEC." msgstr "Ceci supprimera toutes les ressources gérées par le compte actuel, y compris les domaines enregistrés, les enregistrements DNS hébergés, les fichiers des sites et les clés cryptographiques des services Onion et de DNSSEC."
#: pg-view/auth/unregister.php:7 #: pg-view/auth/unregister.php:10
msgid "Delete the current account and everything related (required)" msgid "Delete the current account and everything related (required)"
msgstr "Supprimer le compte actuel et tout ce qui y est lié (requis)" msgstr "Supprimer le compte actuel et tout ce qui y est lié (requis)"
#: pg-view/auth/unregister.php:9 pg-view/ns/form.ns.php:4 pg-view/reg/ds.php:5 #: pg-view/auth/unregister.php:12 pg-view/ns/form.ns.php:4 pg-view/reg/ds.php:5
#: pg-view/reg/glue.php:5 pg-view/reg/ns.php:5 #: pg-view/reg/glue.php:5 pg-view/reg/ns.php:5
msgid "Delete" msgid "Delete"
msgstr "Supprimer" msgstr "Supprimer"
#: pg-view/auth/username.php:2 #: pg-view/auth/username.php:5
msgid "New username" msgid "New username"
msgstr "Nouvel identifiant" msgstr "Nouvel identifiant"
#: pg-view/auth/username.php:5 #: pg-view/auth/username.php:8
msgid "Update username" msgid "Update username"
msgstr "Mettre à jour l'identifiant" msgstr "Mettre à jour l'identifiant"
@ -1088,7 +1094,11 @@ msgstr "Enregistrer un nouveau domaine sur son compte. Il doit être composé d'
msgid "Suffix" msgid "Suffix"
msgstr "Suffixe" msgstr "Suffixe"
#: pg-view/reg/register.php:28 #: pg-view/reg/register.php:27
msgid "Check availability"
msgstr "Vérifier sa disponibilité"
#: pg-view/reg/register.php:29
msgid "Register" msgid "Register"
msgstr "Enregistrer" msgstr "Enregistrer"

View file

@ -271,15 +271,15 @@ msgstr ""
msgid "Delete an existing HTTP access from a subdirectory of the SFTP space" msgid "Delete an existing HTTP access from a subdirectory of the SFTP space"
msgstr "" msgstr ""
#: router.php:137 view.php:39 #: router.php:133 view.php:39
msgid "This service is currently under maintenance. No action can be taken on it until an administrator finishes repairing it." msgid "This service is currently under maintenance. No action can be taken on it until an administrator finishes repairing it."
msgstr "" msgstr ""
#: router.php:147 #: router.php:144
msgid "You need to be logged in to do this." msgid "You need to be logged in to do this."
msgstr "" msgstr ""
#: router.php:149 #: router.php:146
msgid "This account doesn't exist anymore. Log out to end this ghost session." msgid "This account doesn't exist anymore. Log out to end this ghost session."
msgstr "" msgstr ""
@ -359,7 +359,8 @@ msgstr ""
msgid "Wrong password." msgid "Wrong password."
msgstr "" msgstr ""
#: pg-act/auth/password.php:6 #: pg-act/auth/password.php:6 pg-act/auth/unregister.php:4
#: pg-act/auth/username.php:6
msgid "Wrong current password." msgid "Wrong current password."
msgstr "" msgstr ""
@ -367,24 +368,24 @@ msgstr ""
msgid "Password updated." msgid "Password updated."
msgstr "" msgstr ""
#: pg-act/auth/register.php:10 pg-act/auth/username.php:8 #: pg-act/auth/register.php:10 pg-act/auth/username.php:11
msgid "This username is already taken." msgid "This username is already taken."
msgstr "" msgstr ""
#: pg-act/auth/unregister.php:4 #: pg-act/auth/unregister.php:7
msgid "Account deletion must be confirmed." msgid "Account deletion must be confirmed."
msgstr "" msgstr ""
#: pg-act/auth/unregister.php:10 #: pg-act/auth/unregister.php:13
#, php-format #, php-format
msgid "Your account can't be deleted because the %s service is currently unavailable." msgid "Your account can't be deleted because the %s service is currently unavailable."
msgstr "" msgstr ""
#: pg-act/auth/unregister.php:39 #: pg-act/auth/unregister.php:42
msgid "Account deleted." msgid "Account deleted."
msgstr "" msgstr ""
#: pg-act/auth/username.php:17 #: pg-act/auth/username.php:20
msgid "Username updated." msgid "Username updated."
msgstr "" msgstr ""
@ -483,15 +484,19 @@ msgstr ""
msgid "This format of subdomain is not allowed." msgid "This format of subdomain is not allowed."
msgstr "" msgstr ""
#: pg-act/reg/register.php:21 #: pg-act/reg/register.php:27
msgid "This domain is already registered." msgid "This domain is open to registration!"
msgstr "" msgstr ""
#: pg-act/reg/register.php:24 #: pg-act/reg/register.php:29
msgid "This domain is reserved." msgid "This domain is reserved."
msgstr "" msgstr ""
#: pg-act/reg/register.php:34 #: pg-act/reg/register.php:31
msgid "This domain is already registered."
msgstr ""
#: pg-act/reg/register.php:47
msgid "Domain registered." msgid "Domain registered."
msgstr "" msgstr ""
@ -597,7 +602,8 @@ msgstr ""
msgid "Password" msgid "Password"
msgstr "" msgstr ""
#: pg-view/auth/password.php:2 #: pg-view/auth/password.php:2 pg-view/auth/unregister.php:6
#: pg-view/auth/username.php:2
msgid "Current password" msgid "Current password"
msgstr "" msgstr ""
@ -622,20 +628,20 @@ msgstr ""
msgid "This will delete every resource managed by the current account, including registered domains, hosted DNS records, websites files and cryptographic keys for Onion services and DNSSEC." msgid "This will delete every resource managed by the current account, including registered domains, hosted DNS records, websites files and cryptographic keys for Onion services and DNSSEC."
msgstr "" msgstr ""
#: pg-view/auth/unregister.php:7 #: pg-view/auth/unregister.php:10
msgid "Delete the current account and everything related (required)" msgid "Delete the current account and everything related (required)"
msgstr "" msgstr ""
#: pg-view/auth/unregister.php:9 pg-view/ns/form.ns.php:4 pg-view/reg/ds.php:5 #: pg-view/auth/unregister.php:12 pg-view/ns/form.ns.php:4 pg-view/reg/ds.php:5
#: pg-view/reg/glue.php:5 pg-view/reg/ns.php:5 #: pg-view/reg/glue.php:5 pg-view/reg/ns.php:5
msgid "Delete" msgid "Delete"
msgstr "" msgstr ""
#: pg-view/auth/username.php:2 #: pg-view/auth/username.php:5
msgid "New username" msgid "New username"
msgstr "" msgstr ""
#: pg-view/auth/username.php:5 #: pg-view/auth/username.php:8
msgid "Update username" msgid "Update username"
msgstr "" msgstr ""
@ -1087,7 +1093,11 @@ msgstr ""
msgid "Suffix" msgid "Suffix"
msgstr "" msgstr ""
#: pg-view/reg/register.php:28 #: pg-view/reg/register.php:27
msgid "Check availability"
msgstr ""
#: pg-view/reg/register.php:29
msgid "Register" msgid "Register"
msgstr "" msgstr ""

View file

@ -17,11 +17,24 @@ match (CONF['reg']['suffixes'][$_POST['suffix']]) {
$domain = formatAbsoluteDomain($_POST['subdomain'] . '.' . $_POST['suffix']); $domain = formatAbsoluteDomain($_POST['subdomain'] . '.' . $_POST['suffix']);
if (query('select', 'registry', ['domain' => $domain], 'domain') !== []) $registered = query('select', 'registry', ['domain' => $domain], 'domain') !== [];
output(403, _('This domain is already registered.')); $reserved = in_array($_POST['subdomain'], explode(LF, file_get_contents(ROOT_PATH . '/pg-act/reg/reserved.txt')));
if (in_array($_POST['subdomain'], explode(LF, file_get_contents(ROOT_PATH . '/pg-act/reg/reserved.txt')))) $message = match ($registered) {
output(403, _('This domain is reserved.')); false => match ($reserved) {
false => match ($_POST['action']) {
'register' => NULL,
default => '✔️ ' . _('This domain is open to registration!'),
},
default => '❌ ' . _('This domain is reserved.'),
},
default => '❌ ' . _('This domain is already registered.'),
};
if ($message !== NULL)
output(200, data: [
'message' => '<p>' . $message . '</p>',
'domain' => htmlspecialchars($_POST['subdomain']),
]);
rateLimit(); rateLimit();

View file

@ -8,7 +8,7 @@
<div> <div>
<label for="subdomain"><?= _('Subdomain') ?></label> <label for="subdomain"><?= _('Subdomain') ?></label>
<br> <br>
<input id="subdomain" pattern="<?= SUBDOMAIN_REGEX ?>" required="" placeholder="servnest" name="subdomain" type="text"> <input id="subdomain" pattern="<?= SUBDOMAIN_REGEX ?>" required="" placeholder="servnest" name="subdomain" type="text" value="<?= $data['domain'] ?? '' ?>">
</div> </div>
<div> <div>
<label for="suffix"><?= _('Suffix') ?></label> <label for="suffix"><?= _('Suffix') ?></label>
@ -24,6 +24,7 @@ foreach (CONF['reg']['suffixes'] as $suffix => $availability) {
</select> </select>
</div> </div>
</fieldset> </fieldset>
<button type="submit" name="action" value="check">👁️ <?= _('Check availability') ?></button>
<input type="submit" value="<?= _('Register') ?>"> <?= $data['message'] ?? '<br>' ?>
<button type="submit" name="action" value="register">🔗 <?= _('Register') ?></button>
</form> </form>