createUsersWithoutDisplayName.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. if (php_sapi_name() !== 'cli') {
  24. print('Only via CLI, please.');
  25. exit(1);
  26. }
  27. include __DIR__ . '/config.php';
  28. $cr = ldap_connect($host, $port);
  29. ldap_set_option($cr, LDAP_OPT_PROTOCOL_VERSION, 3);
  30. $ok = ldap_bind($cr, $adn, $apwd);
  31. if (!$ok) {
  32. die(ldap_error($cr));
  33. }
  34. $ouName = 'Users';
  35. $ouDN = 'ou=' . $ouName . ',' . $bdn;
  36. $users = ['robot'];
  37. foreach ($users as $uid) {
  38. $newDN = 'uid=' . $uid . ',' . $ouDN;
  39. $fn = ucfirst($uid);
  40. $sn = ucfirst(str_shuffle($uid)); // not so explicit but it's OK.
  41. $entry = [];
  42. $entry['cn'] = ucfirst($uid);
  43. $entry['objectclass'][] = 'inetOrgPerson';
  44. $entry['objectclass'][] = 'person';
  45. $entry['sn'] = $sn;
  46. $entry['userPassword'] = $uid;
  47. $ok = ldap_add($cr, $newDN, $entry);
  48. if ($ok) {
  49. echo('created user ' . ': ' . $entry['cn'] . PHP_EOL);
  50. } else {
  51. die(ldap_error($cr));
  52. }
  53. }