Add debug message when denying SFTP login

This commit is contained in:
Miraty 2023-06-03 18:44:48 +02:00
parent 0e64d6e2b8
commit 4c9e5a5580

View file

@ -5,29 +5,29 @@ const DEBUG = false;
require 'router.php';
function deny() {
!DEBUG or file_put_contents(ROOT_PATH . '/db/debug.txt', ob_get_contents());
function deny($reason) {
!DEBUG or file_put_contents(ROOT_PATH . '/db/debug.txt', ob_get_contents() . $reason . LF);
http_response_code(403);
exit();
}
if (CONF['common']['services']['ht'] !== 'enabled')
deny();
deny('Service not enabled.');
$auth_data = json_decode(file_get_contents('php://input'), true, flags: JSON_THROW_ON_ERROR);
$username = hashUsername($auth_data['username']);
if (usernameExists($username) !== true)
deny();
deny('This username doesn\'t exist.');
if (!in_array('ht', explode(',', query('select', 'users', ['username' => $username], 'services')[0]), true))
deny();
deny('Service not enabled for this user.');
$id = query('select', 'users', ['username' => $username], 'id')[0];
if (checkPassword($id, $auth_data['password']) !== true)
deny();
deny('Wrong password.');
echo '
{