Commit 259cfe7fbe861d53e513e1cfe43b9561ce0c297e

Authored by Michael Joseph
1 parent e85bada3

first cut ldap migration script


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@2796 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 33 additions and 0 deletions
sync/migrateLDAP.php 0 → 100644
  1 +<?php
  2 +
  3 +/**
  4 + * LDAP Migration script.
  5 + * For all users in the database, the username is queried in the new directory server
  6 + * This DN is then used to create an UPDATE statement to correct the old directory server dns
  7 + * in the database.
  8 + */
  9 +
  10 +require_once("../config/dmsDefaults.php");
  11 +
  12 +// first select all users
  13 +$aUsers = User::getList();
  14 +
  15 +// then initialise the LDAP authenticator with the new directory server address
  16 +$sNewLdapServer = "smaurg.mrc.ac.za";
  17 +$sNewLdapDn = "";
  18 +$oLdap = new LDAPAuthenticator($sNewLdapServer, $sNewLdapDn);;
  19 +
  20 +for ($i=0; $i<count($aUsers); $i++) {
  21 + // for each user, lookup the dn based on the username
  22 + $oUser = $aUsers[$i];
  23 + $aResults = $oLdap->searchUsers($oUser->getUserName(), array ("dn"));
  24 + if (count($aResults) > 1) {
  25 + echo "retrieved " . count($aResults) . " matches for username=" + $oUser->getUserName();
  26 + } else {
  27 + $sNewDN = $aResults[$oUser->getUserName()]["dn"];
  28 + // echo an update statement that sets the dn to the correct value
  29 + echo "UPDATE users SET ldap_dn='" . $sNewDN . "' WHERE id=" . $oUser->getID();
  30 + }
  31 +}
  32 +echo "Change the configuration file to point to the new directory server-" . $sNewLdapServer;
  33 +?>
0 34 \ No newline at end of file
... ...