You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

autologon.php 1013B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Sample plugin to try out some hooks.
  4. * This performs an automatic login if accessed from localhost
  5. *
  6. * @license GNU GPLv3+
  7. * @author Thomas Bruederli
  8. */
  9. class autologon extends rcube_plugin
  10. {
  11. public $task = 'login';
  12. function init()
  13. {
  14. $this->add_hook('startup', array($this, 'startup'));
  15. $this->add_hook('authenticate', array($this, 'authenticate'));
  16. }
  17. function startup($args)
  18. {
  19. // change action to login
  20. if (empty($_SESSION['user_id']) && !empty($_GET['_autologin']) && $this->is_localhost())
  21. $args['action'] = 'login';
  22. return $args;
  23. }
  24. function authenticate($args)
  25. {
  26. if (!empty($_GET['_autologin']) && $this->is_localhost()) {
  27. $args['user'] = 'me';
  28. $args['pass'] = '******';
  29. $args['host'] = 'localhost';
  30. $args['cookiecheck'] = false;
  31. $args['valid'] = true;
  32. }
  33. return $args;
  34. }
  35. function is_localhost()
  36. {
  37. return $_SERVER['REMOTE_ADDR'] == '::1' || $_SERVER['REMOTE_ADDR'] == '127.0.0.1';
  38. }
  39. }