daily pastebin goal
52%
SHARE
TWEET

Untitled

a guest Jun 5th, 2017 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.                                 // Can't find account, goodbye profile.
  45.                                 exec("rmdir $dir/$file");
  46.  
  47.                         }
  48.                 }
  49.         }
  50.         closedir($dh);
  51.     }
  52. }
  53.  
  54.  
  55. ldap_unbind($ds);
  56. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top