Created
October 7, 2014 17:07
-
-
Save blizzz/d5987ff2474589e641d2 to your computer and use it in GitHub Desktop.
batch create ldap users
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
$adn = 'uid=foobar,ou=barfoo,dc=foo,dc=bar'; | |
$apwd = 'owncloudagent'; | |
$host = 'ldap.foo.bar'; | |
$port = 389; | |
$cr = ldap_connect($host, $port); | |
ldap_set_option($cr, LDAP_OPT_PROTOCOL_VERSION, 3); | |
ldap_bind($cr, $adn, $apwd); | |
//creates on OU | |
if(true) { | |
$ouDN = 'ou=Zombies,dc=foo,dc=bar'; | |
$entry['objectclass'][] = 'top'; | |
$entry['objectclass'][] = 'organizationalunit'; | |
$entry['ou'] = 'Zombies'; | |
$b = ldap_add($cr, $ouDN, $entry); | |
if(!$b) { | |
die; | |
} | |
} | |
$names = unserialize(file_get_contents('names.dat')); | |
$cfn = count($names['fns']) - 1; | |
$csn = count($names['sns']) - 1; | |
$start = 294; | |
$uidStart = 10249; | |
$amount = 30000; | |
for($i=$start;$i<($amount+$start);$i++) { | |
$uid = 'zombie'.$i; | |
$newDN = 'uid='.$uid.',ou=Zombies,dc=foo,dc=bar'; | |
$fn = $names['fns'][rand(0, $cfn)]; | |
$sn = $names['sns'][rand(0, $csn)]; | |
$entry = array(); | |
$entry['cn'] = $fn.' '.$sn; | |
$entry['gecos'] = $fn.' '.$sn; | |
$entry['sn'] = $sn; | |
$entry['givenName'] = $fn; | |
$entry['displayName'] = $sn.', '.$fn; | |
$entry['homeDirectory'] = '/home/openldap/'.$uid; | |
$entry['objectclass'][] = 'posixAccount'; | |
$entry['objectclass'][] = 'inetOrgPerson'; | |
$entry['loginShell'] = '/bin/bash'; | |
$entry['userPassword'] = $uid; | |
$entry['gidNumber'] = 5000; | |
$entry['uidNumber'] = $uidStart + $i + 1; | |
$ok = ldap_add($cr, $newDN, $entry); | |
if($ok) { | |
echo('created ' . $uid . ': ' . $entry['displayName'] . PHP_EOL); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment