init.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. class Auth_Proxy extends Plugin implements IAuthModule {
  3. private $host;
  4. /* @var Auth_Base $base */
  5. private $base;
  6. function about() {
  7. return array(1.0,
  8. "Trust proxy X-Forwarded-User. May be dangerous, see doc",
  9. "boyska",
  10. true);
  11. }
  12. /* @var PluginHost $host */
  13. function init($host ) {
  14. $this->host = $host;
  15. $this->base = new Auth_Base();
  16. $host->add_hook($host::HOOK_AUTH_USER, $this);
  17. }
  18. /**
  19. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  20. */
  21. function authenticate($login, $password) {
  22. // TODO: check source ip!
  23. if(!array_key_exists("HTTP_X_FORWARDED_USER", $_SERVER)) {
  24. return false;
  25. }
  26. $try_login = $_SERVER["HTTP_X_FORWARDED_USER"];
  27. if ($try_login) {
  28. $user_id = $this->base->auto_create_user($try_login, $password);
  29. if ($user_id) {
  30. $_SESSION["fake_login"] = $try_login;
  31. $_SESSION["fake_password"] = "******";
  32. $_SESSION["hide_hello"] = true;
  33. $_SESSION["hide_logout"] = true;
  34. return $user_id;
  35. }
  36. }
  37. return false;
  38. }
  39. function api_version() {
  40. return 2;
  41. }
  42. }