init.php 984 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /* Requires php-imap
  3. Put the following options in config.php:
  4. define('IMAP_AUTH_SERVER', 'your.imap.server:port');
  5. define('IMAP_AUTH_OPTIONS', '/tls/novalidate-cert/norsh');
  6. // More about options: http://php.net/manual/ru/function.imap-open.php
  7. */
  8. class Auth_Imap extends Plugin implements IAuthModule {
  9. private $link;
  10. private $host;
  11. private $base;
  12. function about() {
  13. return array(1.0,
  14. "Authenticates against an IMAP server (configured in config.php)",
  15. "fox",
  16. true);
  17. }
  18. function init($host) {
  19. $this->link = $host->get_link();
  20. $this->host = $host;
  21. $this->base = new Auth_Base($this->link);
  22. $host->add_hook($host::HOOK_AUTH_USER, $this);
  23. }
  24. function authenticate($login, $password) {
  25. if ($login && $password) {
  26. $imap = imap_open(
  27. "{".IMAP_AUTH_SERVER.IMAP_AUTH_OPTIONS."}INBOX",
  28. $login,
  29. $password);
  30. if ($imap) {
  31. imap_close($imap);
  32. return $this->base->auto_create_user($login);
  33. }
  34. }
  35. return false;
  36. }
  37. }
  38. ?>