2022-05-19 14:59:32 +00:00
|
|
|
<?php
|
|
|
|
|
2023-04-15 16:01:19 +00:00
|
|
|
const DEBUG = false;
|
|
|
|
!DEBUG or ob_start();
|
|
|
|
|
2022-11-20 14:11:54 +00:00
|
|
|
require 'router.php';
|
2022-05-19 14:59:32 +00:00
|
|
|
|
2023-03-09 13:40:26 +00:00
|
|
|
function deny() {
|
2023-04-15 16:01:19 +00:00
|
|
|
!DEBUG or file_put_contents(ROOT_PATH . '/db/debug.txt', ob_get_contents());
|
2023-03-09 13:40:26 +00:00
|
|
|
http_response_code(403);
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CONF['common']['services']['ht'] !== 'enabled')
|
|
|
|
deny();
|
|
|
|
|
2023-04-09 22:50:42 +00:00
|
|
|
$auth_data = json_decode(file_get_contents('php://input'), true, flags: JSON_THROW_ON_ERROR);
|
2022-05-19 14:59:32 +00:00
|
|
|
|
2022-11-30 22:12:42 +00:00
|
|
|
$username = hashUsername($auth_data['username']);
|
2022-11-26 20:45:48 +00:00
|
|
|
|
2023-03-09 13:40:26 +00:00
|
|
|
if (usernameExists($username) !== true)
|
|
|
|
deny();
|
|
|
|
|
2023-03-18 17:38:27 +00:00
|
|
|
if (!in_array('ht', explode(',', query('select', 'users', ['username' => $username], 'services')[0]), true))
|
|
|
|
deny();
|
|
|
|
|
2022-11-30 22:12:42 +00:00
|
|
|
$id = query('select', 'users', ['username' => $username], 'id')[0];
|
|
|
|
|
2023-03-09 13:40:26 +00:00
|
|
|
if (checkPassword($id, $auth_data['password']) !== true)
|
|
|
|
deny();
|
|
|
|
|
|
|
|
echo '
|
|
|
|
{
|
|
|
|
"status": 1,
|
|
|
|
"username": ' . json_encode($auth_data['username']) . ',
|
2023-04-09 22:50:42 +00:00
|
|
|
"home_dir": "' . CONF['ht']['ht_path'] . '/fs/' . $id . '",
|
2023-03-09 13:40:26 +00:00
|
|
|
"quota_size": ' . ((query('select', 'users', ['id' => $id], 'type')[0] === 'approved') ? CONF['ht']['user_quota_approved'] : CONF['ht']['user_quota_testing']) . ',
|
|
|
|
"permissions": {
|
|
|
|
"/": [
|
|
|
|
"*"
|
|
|
|
]
|
2022-06-28 20:08:34 +00:00
|
|
|
}
|
2022-05-19 14:59:32 +00:00
|
|
|
}
|
2023-03-09 13:40:26 +00:00
|
|
|
';
|
2023-04-15 16:01:19 +00:00
|
|
|
|
|
|
|
!DEBUG or file_put_contents(ROOT_PATH . '/db/debug.txt', ob_get_contents());
|
2023-03-09 13:40:26 +00:00
|
|
|
http_response_code(200);
|