$host = "phpuc.ez.no"; $connection = Ldap::connect("ldap://{$host}", "cn=%s,{$dc}", 'admin', 'wee123'); Ldap::delete($connection, 'yoda', "ou=StarWars,{$dc}"); Ldap::delete($connection, 'boba.fett', "ou=StarWars,{$dc}"); Ldap::delete($connection, 'obi.wan', "ou=StarWars,{$dc}"); Ldap::delete($connection, 'jabba.thehutt', "ou=StarWars,{$dc}"); Ldap::delete($connection, 'darth.vader', "ou=StarWars,{$dc}"); Ldap::delete($connection, 'leia', "ou=StarWars,{$dc}"); Ldap::delete($connection, 'han.solo', "ou=StarWars,{$dc}"); Ldap::delete($connection, 'chewbacca', "ou=StarWars,{$dc}"); Ldap::deleteGroup($connection, 'Jedi', "ou=RebelAlliance,ou=StarWars,{$dc}"); Ldap::deleteGroup($connection, 'RebelAlliance', "ou=StarWars,{$dc}"); Ldap::deleteGroup($connection, 'Sith', "ou=GalacticEmpire,ou=StarWars,{$dc}"); Ldap::deleteGroup($connection, 'GalacticEmpire', "ou=StarWars,{$dc}"); Ldap::deleteGroup($connection, 'Rogues', "ou=StarWars,{$dc}"); Ldap::deleteGroup($connection, 'StarWars', $dc); Ldap::addGroup($connection, 'StarWars', $dc); $chewbaccaDN = Ldap::add($connection, 'chewbacca', '{MD5}' . base64_encode(pack('H*', md5('aaawwwwrrrkk'))), "ou=StarWars,{$dc}", 'Chewbacca', 'Chewbacca', array('givenName' => 'Chewbacca', 'displayName' => 'Chewbacca the Wokiee', 'ou' => array('StarWars', 'Rogues', 'RebelAlliance'), 'mail' => array('*****@*****.**'))); $hanSoloDN = Ldap::add($connection, 'han.solo', '{MD5}' . base64_encode(pack('H*', md5('leiaishot'))), "ou=StarWars,{$dc}", 'Solo', 'Han Solo', array('givenName' => 'Han', 'displayName' => 'He who shot first', 'ou' => array('StarWars', 'Rogues', 'RebelAlliance'), 'mail' => array('*****@*****.**'))); $princessLeiaDN = Ldap::add($connection, 'leia', '{MD5}' . base64_encode(pack('H*', md5('bunhead'))), "ou=StarWars,{$dc}", 'Organa', 'Leia Organa', array('givenName' => 'Leia', 'displayName' => 'Princess Leia', 'ou' => array('StarWars', 'RebelAlliance'), 'mail' => array('*****@*****.**'))); $darthVaderDN = Ldap::add($connection, 'darth.vader', '{MD5}' . base64_encode(pack('H*', md5('whosyourdaddy'))), "ou=StarWars,{$dc}", 'Skywalker', 'Anakin Skywalker', array('givenName' => 'Anakin', 'displayName' => 'Darth Vader', 'ou' => array('StarWars', 'GalacticEmpire', 'Sith'), 'mail' => array('*****@*****.**'))); $jabbaTheHuttDN = Ldap::add($connection, 'jabba.thehutt', '{MD5}' . base64_encode(pack('H*', md5('wishihadlegs'))), "ou=StarWars,{$dc}", 'Hutt', 'Jabba Hutt', array('givenName' => 'Jabba', 'displayName' => 'Jabba the Hutt', 'ou' => array('Hutts'), 'mail' => array('*****@*****.**'))); $obiWanDN = Ldap::add($connection, 'obi.wan', '{MD5}' . base64_encode(pack('H*', md5('thesearenotthedroids'))), "ou=StarWars,{$dc}", 'Kenobi', 'Obi Wan Kenobi', array('givenName' => 'Obi Wan', 'displayName' => 'Obi Wan Kenobi', 'ou' => array('StarWars', 'RebelAlliance', 'Jedi'), 'seeAlso' => array("ou=StarWars,{$dc}", "ou=RebelAlliance,ou=StarWars,{$dc}", "ou=Jedi,ou=RebelAlliance,ou=StarWars,{$dc}"), 'mail' => array('*****@*****.**'))); $bobaFettDN = Ldap::add($connection, 'boba.fett', '{MD5}' . base64_encode(pack('H*', md5('ihatesarlacs'))), "ou=StarWars,{$dc}", 'Fett', 'Boba Fett', array('givenName' => 'Boba', 'displayName' => 'Boba Fett', 'ou' => array('StarWars', 'Rogues'), 'seeAlso' => array("ou=StarWars,{$dc}", "ou=Rogues,ou=StarWars,{$dc}"), 'mail' => array('*****@*****.**'))); $yodaDN = Ldap::add($connection, 'yoda', '{MD5}' . base64_encode(pack('H*', md5('dagobah4eva'))), "ou=StarWars,{$dc}", 'Yoda', 'Yoda', array('givenName' => 'Yoda', 'displayName' => 'Yoda', 'ou' => array('StarWars', 'RebelAlliance', 'Jedi'), 'seeAlso' => array("ou=StarWars,{$dc}", "ou=RebelAlliance,ou=StarWars,{$dc}", "ou=Jedi,ou=RebelAlliance,ou=StarWars,{$dc}"), 'mail' => array('*****@*****.**'))); Ldap::addGroup($connection, 'RebelAlliance', "ou=StarWars,{$dc}", array('seeAlso' => array($princessLeiaDN, $chewbaccaDN, $hanSoloDN, $obiWanDN, $yodaDN))); Ldap::addGroup($connection, 'Rogues', "ou=StarWars,{$dc}", array('seeAlso' => array($chewbaccaDN, $hanSoloDN))); Ldap::addGroup($connection, 'GalacticEmpire', "ou=StarWars,{$dc}", array('seeAlso' => array($darthVaderDN))); Ldap::addGroup($connection, 'Sith', "ou=GalacticEmpire,ou=StarWars,{$dc}", array('seeAlso' => array($darthVaderDN))); Ldap::addGroup($connection, 'Jedi', "ou=RebelAlliance,ou=StarWars,{$dc}", array('seeAlso' => array($obiWanDN, $yodaDN))); // This dumps all the LDAP data
/** * Setup the test accounts on the ldap server. * * Assumes the username entries are 'uid'. * */ $dc = "dc=ezctest,dc=ez,dc=no"; $host = "ezctest.ez.no"; $connection = Ldap::connect("ldap://{$host}", "cn=%s,{$dc}", 'admin', 'wee123'); Ldap::delete($connection, 'john.doe', $dc); Ldap::delete($connection, 'jan.modaal', $dc); Ldap::delete($connection, 'zhang.san', $dc); Ldap::delete($connection, 'johnny.doe', "ou=Users,{$dc}"); Ldap::delete($connection, 'hans.mustermann', $dc); Ldap::delete($connection, 'Ruşinică Piţigoi', $dc); Ldap::deleteGroup($connection, 'Users', $dc); Ldap::addGroup($connection, 'Users', $dc); Ldap::add($connection, 'john.doe', '{CRYPT}' . crypt('foobar'), $dc); Ldap::add($connection, 'jan.modaal', '{SHA}' . base64_encode(pack('H*', sha1('qwerty'))), $dc); Ldap::add($connection, 'zhang.san', '{MD5}' . base64_encode(pack('H*', md5('asdfgh'))), $dc); Ldap::add($connection, 'johnny.doe', '{MD5}' . base64_encode(pack('H*', md5('12345'))), "ou=Users,{$dc}", array('displayName' => 'Johnny Doe', 'ou' => array('Users'))); //Ldap::add( $connection, 'jan.modaal', '{SHA}' . base64_encode( sha1( 'qwerty' ) ), $dc ); //Ldap::add( $connection, 'zhang.san', '{MD5}' . base64_encode( md5( 'asdfgh' ) ), $dc ); Ldap::add($connection, 'hans.mustermann', 'abcdef', $dc); Ldap::add($connection, 'Ruşinică Piţigoi', '12345', $dc); Ldap::fetchAll($connection, $dc); Ldap::close($connection); /** * Support for LDAP functions connect, add, delete and get_entries. */ class Ldap