Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // $dir is profiles path
- // $username and password are a valid AD username & password
- $dir = "c:\path\to\profiles";
- $username = "username";
- //must always check that password length > 0
- $password = "password";
- // Setup Active Directory Params
- $ldap_url = 'dumbledore.rus.mson.org';
- $ldap_domain = 'rus.mson.org';
- $ldap_dn = "dc=rus,dc=mson,dc=org";
- // Connect to LDAP
- $ds = ldap_connect( $ldap_url );
- ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
- ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
- // now try a real login
- $login = ldap_bind( $ds, "$username@$ldap_domain", $password );
- // OK. Is the path given a directory?
- if (is_dir($dir)) {
- if ($dh = opendir($dir)) {
- while (($file = readdir($dh)) !== false) {
- // Lets get directories within the directory
- if(is_dir(''.$dir.'/'.$file.'') && $file != "." && $file != "..") {
- // Lets search LDAP for our account
- $attributes = array("displayname");
- $filter = "(&(objectCategory=person)(sAMAccountName=$file))";
- $result = ldap_search($ds, $ldap_dn, $filter, $attributes);
- $entries = ldap_get_entries($ds, $result);
- if($entries["count"] > 0){
- // OK. Account exists, so lets go! :D
- } else {
- } else {
- // Can't find account, goodbye profile.
- exec("rmdir $dir/$file");
- }
- }
- }
- closedir($dh);
- }
- }
- ldap_unbind($ds);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement