servnest/public/auth/register.php

67 lines
2.6 KiB
PHP
Raw Normal View History

<?php require "../../common/html.php"; ?>
2021-01-22 21:58:46 +01:00
2022-06-06 23:14:50 +02:00
<p>Déjà un compte ? <a class="auth" href="login">Se connecter</a></p>
2022-06-10 21:14:47 +02:00
<form method="post">
2022-05-21 19:41:46 +02:00
2022-06-10 21:14:47 +02:00
<details>
<summary><label for="username">Identifiant</label></summary>
Uniquement composé de lettres minuscules.
</details>
<input id="username" maxlength="32" pattern="<?= USERNAME_REGEX ?>" required="" name="username" type="text" placeholder="<?= PLACEHOLDER_USERNAME ?>"><br>
2021-01-22 21:58:46 +01:00
2022-06-10 21:14:47 +02:00
<details>
<summary><label for="password">Clé de passe</label></summary>
<p>Une clé de passe sécurisée est trop compliquée à deviner pour une attaque qui testerais automatiquement plein de clés de passe tout en connaissant d'autres informations et secrets sur vous.</p>
<p>Minimum 8 caractères si elle contient minuscule, majuscule et chiffre, ou minimum 10 caractères sinon.</p>
</details>
2022-06-10 21:14:47 +02:00
<input autocomplete="new-password" id="password" minlength="8" maxlength="1024" pattern="<?= PASSWORD_REGEX ?>" required="" name="password" type="password" placeholder="<?= PLACEHOLDER_PASSWORD ?>"><br>
2021-01-22 21:58:46 +01:00
2022-06-10 21:14:47 +02:00
<input type="submit">
</form>
2021-01-22 21:58:46 +01:00
2022-06-10 21:14:47 +02:00
<?php
2021-01-22 21:58:46 +01:00
2022-06-10 21:14:47 +02:00
switchToFormProcess(requireLogin: false);
2021-01-22 21:58:46 +01:00
2022-06-10 21:14:47 +02:00
checkPasswordFormat($_POST['password']);
2021-01-22 21:58:46 +01:00
2022-06-10 21:14:47 +02:00
checkUsernameFormat($_POST['username']);
2021-01-22 21:58:46 +01:00
2022-06-10 21:14:47 +02:00
if (userExist($_POST['username']) !== false)
userError("Ce nom de compte est déjà utilisé.");
2022-05-21 19:41:46 +02:00
2022-06-10 21:14:47 +02:00
// Setup SFTP directory
umask(0002);
if (mkdir(CONF['ht']['ht_path'] . "/" . $_POST['username'], 0775) !== true)
serverError("Can't create user directory.");
exec(CONF['ht']['sudo_path'] . " " . CONF['ht']['chgrp_path'] . " " . CONF['ht']['sftpgo_group'] . " " . CONF['ht']['ht_path'] . "/" . $_POST['username'] . " --no-dereference", result_code: $code);
2022-06-10 21:14:47 +02:00
if ($code !== 0)
serverError("Can't change user directory group.");
// Setup Tor config directory
if (mkdir(CONF['ht']['tor_config_path'] . "/" . $_POST['username'], 0755) !== true)
serverError("Can't create Tor config directory.");
// Setup Tor keys directory
exec(CONF['ht']['sudo_path'] . " -u " . CONF['ht']['tor_user'] . " " . CONF['ht']['mkdir_path'] . " --mode=0700 " . CONF['ht']['tor_keys_path'] . "/" . $_POST['username'], result_code: $code);
if ($code !== 0)
serverError("Can't create Tor keys directory.");
2022-06-10 21:14:47 +02:00
$db = new PDO('sqlite:' . DB_PATH);
2021-01-22 21:58:46 +01:00
2022-06-10 21:14:47 +02:00
$stmt = $db->prepare("INSERT INTO users(username, password, registration_date) VALUES(:username, :password, :registration_date)");
2022-04-18 16:05:00 +02:00
2022-06-11 23:42:48 +02:00
$stmt->bindValue(':username', $_POST['username']);
$stmt->bindValue(':password', hashPassword($_POST['password']));
$stmt->bindValue(':registration_date', date("Y-m-d H:i:s"));
2022-05-31 23:28:32 +02:00
2022-06-10 21:14:47 +02:00
$stmt->execute();
2022-04-18 16:05:00 +02:00
2022-06-10 21:14:47 +02:00
$_SESSION['username'] = $_POST['username'];
2022-04-18 16:05:00 +02:00
2022-06-17 15:45:52 +02:00
redir();
2022-06-10 21:14:47 +02:00
success("Compte créé.");