sftpgo-auth.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. const DEBUG = false;
  3. !DEBUG or ob_start();
  4. require 'router.php';
  5. function deny() {
  6. !DEBUG or file_put_contents(ROOT_PATH . '/db/debug.txt', ob_get_contents());
  7. http_response_code(403);
  8. exit();
  9. }
  10. if (CONF['common']['services']['ht'] !== 'enabled')
  11. deny();
  12. $auth_data = json_decode(file_get_contents('php://input'), true, flags: JSON_THROW_ON_ERROR);
  13. $username = hashUsername($auth_data['username']);
  14. if (usernameExists($username) !== true)
  15. deny();
  16. if (!in_array('ht', explode(',', query('select', 'users', ['username' => $username], 'services')[0]), true))
  17. deny();
  18. $id = query('select', 'users', ['username' => $username], 'id')[0];
  19. if (checkPassword($id, $auth_data['password']) !== true)
  20. deny();
  21. echo '
  22. {
  23. "status": 1,
  24. "username": ' . json_encode($auth_data['username']) . ',
  25. "home_dir": "' . CONF['ht']['ht_path'] . '/fs/' . $id . '",
  26. "quota_size": ' . ((query('select', 'users', ['id' => $id], 'type')[0] === 'approved') ? CONF['ht']['user_quota_approved'] : CONF['ht']['user_quota_testing']) . ',
  27. "permissions": {
  28. "/": [
  29. "*"
  30. ]
  31. }
  32. }
  33. ';
  34. !DEBUG or file_put_contents(ROOT_PATH . '/db/debug.txt', ob_get_contents());
  35. http_response_code(200);