ソースを参照

Create SFTP directory at account creation

Miraty 3 年 前
コミット
50c23f6245
4 ファイル変更11 行追加3 行削除
  1. 1 0
      auth.php
  2. 2 2
      common/top.php
  3. 0 1
      ht.php
  4. 8 0
      public/auth/register.php

+ 1 - 0
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);

+ 2 - 2
common/top.php

@@ -1,12 +1,12 @@
 <?php
 
 define("DOMAIN_EXAMPLE", "example"); // From RFC2606: Reserved Top Level DNS Names > 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 !== "")

+ 0 - 1
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

+ 8 - 0
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);