diff --git a/auth.php b/auth.php index 83ecae2..bae15b4 100644 --- a/auth.php +++ b/auth.php @@ -4,6 +4,7 @@ define("USERNAME_REGEX", "^[a-z]{4,32}$"); define("PASSWORD_REGEX", "^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])[a-zA-Z0-9]{8,1024}|.{10,1024}$"); define("ORIGIN", "https://niver.test:42443"); +define("CHGRP_PATH", "/usr/bin/chgrp"); // Password storage security define("ALGO_PASSWORD", PASSWORD_ARGON2ID); diff --git a/common/top.php b/common/top.php index 8675e98..3a27bbf 100644 --- a/common/top.php +++ b/common/top.php @@ -1,12 +1,12 @@ 2. TLDs for Testing, & Documentation Examples -define("NIVER_TEMPLATE_PATH", "/usr/local/share/niver"); // Templates directory (nginx, knot...) define("PREFIX", ""); // Prefix in URL, if any -define("ROOT_PATH", "/srv/php/niver" . PREFIX); // niver-php directory +define("ROOT_PATH", "/srv/php/niver"); // niver-php directory define("SERVICE", substr(dirname($_SERVER['PHP_SELF']), strlen(PREFIX) + 1)); define("PAGE", basename($_SERVER['PHP_SELF'], '.php')); define("DB_PATH", ROOT_PATH . "/db/niver.db"); // Niver's SQLite database +define("SUDO_PATH", "/usr/bin/sudo"); // Service-specific functions and constants if (SERVICE !== "") diff --git a/ht.php b/ht.php index 491f4e0..0fa99b9 100644 --- a/ht.php +++ b/ht.php @@ -11,7 +11,6 @@ define("HT_PATH", "/srv/ht"); define("MANIVER_PATH", "/usr/local/bin/maniver"); define("SYSTEMCTL_PATH", "/usr/bin/systemctl"); define("CERTBOT_PATH", "/usr/bin/certbot"); -define("SUDO_PATH", "/usr/bin/sudo"); define("LS_PATH", "/usr/bin/ls"); define("NGINX_CONFIG_PATH", "/etc/nginx/ht"); // Nginx configuration directory define("TOR_CONFIG_PATH", "/etc/tor/instances/niver/torrc"); // Tor configuration file diff --git a/public/auth/register.php b/public/auth/register.php index ebc0436..971044e 100644 --- a/public/auth/register.php +++ b/public/auth/register.php @@ -16,6 +16,14 @@ if (isset($_POST['username']) AND isset($_POST['password'])) { $userExist = userExist($username); if (!$userExist) { + // Setup SFTP directory + umask(0002); + if (!mkdir("/srv/ht/" . $username, 0775)) + exit("ERROR: Can't create directory"); + exec(SUDO_PATH . " " . CHGRP_PATH . " sftpgo " . HT_PATH . "/" . $username, $stdout, $code); + if ($code !== 0) + exit("ERROR: Can't change group"); + $password = hashPassword($_POST['password']); $db = new PDO('sqlite:' . DB_PATH);