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.

LDAP.php 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /*
  3. * $Id: LDAP.php 501 2013-07-11 17:44:37Z imooreyahoo@gmail.com $
  4. * Experimental!
  5. */
  6. class phpvbAuthLDAP implements phpvbAuth {
  7. var $capabilities = array(
  8. 'canChangePassword' => false,
  9. 'canLogout' => true
  10. );
  11. var $config = array(
  12. 'host' => '127.0.0.1', // LDAP server ip
  13. 'bind_dn' => 'uid=%s, ou=admins, dc=internal, dc=local', // %s will be replaced with login username
  14. 'adminUser' => ''
  15. );
  16. function phpvbAuthLDAP($userConfig = null) {
  17. if($userConfig) $this->config = array_merge($this->config,$userConfig);
  18. }
  19. function login($username, $password)
  20. {
  21. global $_SESSION;
  22. // Check for LDAP functions
  23. if(!function_exists('ldap_connect')) {
  24. $ex = 'LDAP support is not enabled in your PHP configuration.';
  25. if(strtolower(substr(PHP_OS, 0, 3)) == 'win') {
  26. ob_start();
  27. phpinfo(INFO_GENERAL);
  28. $phpinfo = ob_get_contents();
  29. ob_end_clean();
  30. preg_match('/Loaded Configuration File <\/td><td.*?>(.*?)\s*</', $phpinfo, $phpinfo);
  31. $ex .= ' You probably just need to uncomment the line ;extension=php_ldap.dll in php.ini'.
  32. (count($phpinfo) > 1 ? ' (' .trim($phpinfo[1]).')' : '') . ' by removing the ";" and restart your web server.';
  33. } else if(strtolower(substr(PHP_OS, 0, 5)) == 'Linux') {
  34. $ex .= ' You probably need to install the php5-ldap (or similar depending on your distribution) package.';
  35. }
  36. throw new Exception($ex);
  37. }
  38. $auth = ldap_connect($this->config['host']);
  39. if(!$auth) return false;
  40. ldap_set_option($auth,LDAP_OPT_PROTOCOL_VERSION, 3);
  41. if(!@ldap_bind($auth, sprintf($this->config['bind_dn'], $username), $password))
  42. return false;
  43. $_SESSION['valid'] = true;
  44. $_SESSION['user'] = $username;
  45. $_SESSION['admin'] = (!$this->config['adminUser']) || ($_SESSION['user'] == $this->config['adminUser']);
  46. $_SESSION['authCheckHeartbeat'] = time();
  47. }
  48. function heartbeat($vbox)
  49. {
  50. global $_SESSION;
  51. $_SESSION['valid'] = true;
  52. $_SESSION['authCheckHeartbeat'] = time();
  53. }
  54. function changePassword($old, $new)
  55. {
  56. }
  57. function logout(&$response)
  58. {
  59. global $_SESSION;
  60. if(function_exists('session_destroy')) session_destroy();
  61. else unset($_SESSION['valid']);
  62. $response['data']['result'] = 1;
  63. }
  64. function listUsers()
  65. {
  66. }
  67. function updateUser($vboxRequest, $skipExistCheck)
  68. {
  69. }
  70. function deleteUser($user)
  71. {
  72. }
  73. }