From 0e64d6e2b88ccf81df051f97ac8bb6bcd921800a Mon Sep 17 00:00:00 2001 From: Miraty Date: Fri, 2 Jun 2023 23:12:59 +0200 Subject: [PATCH] Don't require visiting /ht/ to enable SFTP access --- check.php | 4 +--- router.php | 15 ++++++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/check.php b/check.php index b7799c8..79e2982 100644 --- a/check.php +++ b/check.php @@ -171,9 +171,7 @@ function testNs($domain) { } function testHt($username, $password) { - curlTest('/ht/', []); - - define('TEST_CONTENT', 'test-' . random_bytes(4)); + define('TEST_CONTENT', 'test-' . bin2hex(random_bytes(16))); file_put_contents(sys_get_temp_dir() . '/index.html', TEST_CONTENT); diff --git a/router.php b/router.php index 74cacd8..14dd515 100644 --- a/router.php +++ b/router.php @@ -128,15 +128,16 @@ if (isset($_SESSION['id'])) { // Enable not already enabled services for this user $user_services = array_filter(explode(',', query('select', 'users', ['id' => $_SESSION['id']], 'services')[0])); - if (in_array(SERVICE, SERVICES_USER, true) AND !in_array(SERVICE, $user_services, true) AND CONF['common']['services'][SERVICE] === 'enabled') { - $user_services[] = SERVICE; + foreach (SERVICES_USER as $service) + if (!in_array($service, $user_services, true) AND CONF['common']['services'][$service] === 'enabled') { + $user_services[] = $service; - DB->prepare('UPDATE users SET services = :services WHERE id = :id') - ->execute([':services' => implode(',', $user_services), ':id' => $_SESSION['id']]); + DB->prepare('UPDATE users SET services = :services WHERE id = :id') + ->execute([':services' => implode(',', $user_services), ':id' => $_SESSION['id']]); - if (SERVICE === 'ht') - htSetupUserFs($_SESSION['id']); - } + if ($service === 'ht') + htSetupUserFs($_SESSION['id']); + } } function displayFinalMessage($data) {