Created
October 7, 2014 16:13
-
-
Save blizzz/926b51ae91fe340a8806 to your computer and use it in GitHub Desktop.
batch create ldap groups
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=Boxes,dc=foo,dc=bar'; | |
$entry['objectclass'][] = 'top'; | |
$entry['objectclass'][] = 'organizationalunit'; | |
$entry['ou'] = 'Boxes'; | |
$b = ldap_add($cr, $ouDN, $entry); | |
if(!$b) { | |
die; | |
} | |
} | |
$start = 4; | |
$gidStart = 6000; | |
$amount = 7000; | |
for($i=$start;$i<($amount+$start);$i++) { | |
$cn = 'Box' . $i; | |
$newDN = 'cn='.$cn.',ou=Boxes,dc=foo,dc=bar'; | |
$entry = array(); | |
$entry['cn'] = $cn; | |
$entry['gidNumber'] = $gidStart + $i + 1; | |
$entry['objectclass'][] = 'posixGroup'; | |
$ok = ldap_add($cr, $newDN, $entry); | |
if($ok) { | |
echo('created ' . ': ' . $entry['cn'] . PHP_EOL); | |
} else { | |
var_dump($entry); | |
die; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment