note 78902 added to function.ldap-add

From: Date: Thu, 01 Nov 2007 14:27:48 +0000
Subject: note 78902 added to function.ldap-add
Groups: php.notes 
Request: Send a blank email to php-notes+get-131915@lists.php.net to get a copy of this message
This solution works for us. In the form the CN and pwdtxt are randomly generated from strict rules. This script creates 50-60 users i AD pr.day! and never even had a glitch! <?php ## From form $CN = $_POST['CN']; $givenName = $_POST['givenName']; $SN = $_POST['SN']; $mail = $_POST['mail']; $Phone = $_POST['Phone']; $pwdtxt = $_POST['pwdtxt']; $AD_server = "localhost:390"; // Local Stunnel --> http://www.stunnel.org/ $AD_Auth_User = "administrator@student.somwhere.com"; //Administrative user $AD_Auth_PWD = "duppiduppdupp"; //The password $dn = 'CN='.$CN.',OU=Brukere,DC=student,DC=somwhere,DC=com'; ## Create Unicode password $newPassword = "\"" . $pwdtxt . "\""; $len = strlen($newPassword); $newPassw = ""; for($i=0;$i<$len;$i++) { $newPassw .= "{$newPassword{$i}}\000"; } ## CONNNECT TO AD $ds = ldap_connect($AD_server); if ($ds) { ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); // IMPORTANT $r = ldap_bind($ds, $AD_Auth_User, $AD_Auth_PWD); //BIND $ldaprecord['cn'] = $CN; $ldaprecord['givenName'] = $givenName; $ldaprecord['sn'] = $SN; $ldaprecord['objectclass'][0] = "top"; $ldaprecord['objectclass'][1] = "person"; $ldaprecord['objectclass'][1] = "organizationalPerson"; $ldaprecord['objectclass'][2] = "user"; $ldaprecord['mail'] = $mail; $ldaprecord['telephoneNumber'] = $Phone; $ldaprecord["unicodepwd"] = $newPassw; $ldaprecord["sAMAccountName"] = $CN; $ldaprecord["UserAccountControl"] = "512"; //This is to prevent the user from beeing disabled. --> http://support.microsoft.com/default.aspx?scid=kb;en-us;305144 $r = ldap_add($ds, $dn, $ldaprecord); } else { echo "cannot connect to LDAP server at $AD_server."; } ?> This is code example creates a user i AD. We use this on an internal web page to create temporary users that kan access the wireless network. We have a .pl script that deletes the users after 24H. ---- Server IP: 194.153.94.10 Probable Submitter: 158.38.27.108 ---- Manual Page -- http://www.php.net/manual/en/function.ldap-add.php Edit -- https://master.php.net/note/edit/78902 Del: integrated -- https://master.php.net/note/delete/78902/integrated Del: useless -- https://master.php.net/note/delete/78902/useless Del: bad code -- https://master.php.net/note/delete/78902/bad+code Del: spam -- https://master.php.net/note/delete/78902/spam Del: non-english -- https://master.php.net/note/delete/78902/non-english Del: in docs -- https://master.php.net/note/delete/78902/in+docs Del: other reasons-- https://master.php.net/note/delete/78902 Reject -- https://master.php.net/note/reject/78902 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#131915) next »