Advertisement
Guest User

Untitled

a guest
Jun 5th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.67 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. // $dir is profiles path
  5. // $username and password are a valid AD username & password
  6. $dir = "c:\path\to\profiles";
  7. $username = "username";
  8.  
  9. //must always check that password length > 0
  10. $password = "password";
  11.  
  12. // Setup Active Directory Params
  13. $ldap_url = 'dumbledore.rus.mson.org';
  14. $ldap_domain = 'rus.mson.org';
  15. $ldap_dn = "dc=rus,dc=mson,dc=org";
  16.  
  17. // Connect to LDAP
  18. $ds = ldap_connect( $ldap_url );
  19. ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
  20. ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
  21.  
  22. // now try a real login
  23. $login = ldap_bind( $ds, "$username@$ldap_domain", $password );
  24.  
  25. // OK. Is the path given a directory?
  26. if (is_dir($dir)) {
  27.     if ($dh = opendir($dir)) {
  28.         while (($file = readdir($dh)) !== false) {
  29.  
  30.         // Lets get directories within the directory
  31.         if(is_dir(''.$dir.'/'.$file.'') && $file != "." && $file != "..") {
  32.  
  33.                         // Lets search LDAP for our account
  34.                         $attributes = array("displayname");
  35.                         $filter = "(&(objectCategory=person)(sAMAccountName=$file))";
  36.  
  37.                         $result = ldap_search($ds, $ldap_dn, $filter, $attributes);
  38.  
  39.                         $entries = ldap_get_entries($ds, $result);
  40.  
  41.                         if($entries["count"] > 0){
  42.                                 // OK. Account exists, so lets go! :D
  43.                         } else {
  44.                         } else {
  45.                                 // Can't find account, goodbye profile.
  46.                                 exec("rmdir $dir/$file");
  47.  
  48.                         }
  49.                 }
  50.         }
  51.         closedir($dh);
  52.     }
  53. }
  54.  
  55.  
  56. ldap_unbind($ds);
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement