createUsersWithoutDisplayName.php 1019 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. if (php_sapi_name() !== 'cli') {
  8. print('Only via CLI, please.');
  9. exit(1);
  10. }
  11. include __DIR__ . '/config.php';
  12. $cr = ldap_connect($host, $port);
  13. ldap_set_option($cr, LDAP_OPT_PROTOCOL_VERSION, 3);
  14. $ok = ldap_bind($cr, $adn, $apwd);
  15. if (!$ok) {
  16. die(ldap_error($cr));
  17. }
  18. $ouName = 'Users';
  19. $ouDN = 'ou=' . $ouName . ',' . $bdn;
  20. $users = ['robot'];
  21. foreach ($users as $uid) {
  22. $newDN = 'uid=' . $uid . ',' . $ouDN;
  23. $fn = ucfirst($uid);
  24. $sn = ucfirst(str_shuffle($uid)); // not so explicit but it's OK.
  25. $entry = [];
  26. $entry['cn'] = ucfirst($uid);
  27. $entry['objectclass'][] = 'inetOrgPerson';
  28. $entry['objectclass'][] = 'person';
  29. $entry['sn'] = $sn;
  30. $entry['userPassword'] = $uid;
  31. $ok = ldap_add($cr, $newDN, $entry);
  32. if ($ok) {
  33. echo('created user ' . ': ' . $entry['cn'] . PHP_EOL);
  34. } else {
  35. die(ldap_error($cr));
  36. }
  37. }