2012-05-14 10:58:58 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
//from version 0.1 to 0.2
|
2012-05-17 17:33:38 +00:00
|
|
|
|
2012-08-23 16:29:43 +00:00
|
|
|
//ATTENTION
|
|
|
|
//Upgrade from ownCloud 3 (LDAP backend 0.1) to ownCloud 4.5 (LDAP backend 0.3) is not supported!!
|
|
|
|
//You must do upgrade to ownCloud 4.0 first!
|
2013-01-31 16:44:25 +00:00
|
|
|
//The upgrade stuff in the section from 0.1 to 0.2 is just to minimize the bad effects.
|
2012-08-23 16:29:43 +00:00
|
|
|
|
2012-05-17 17:33:38 +00:00
|
|
|
//settings
|
2012-05-14 10:58:58 +00:00
|
|
|
$pw = OCP\Config::getAppValue('user_ldap', 'ldap_password');
|
|
|
|
if(!is_null($pw)) {
|
|
|
|
$pwEnc = base64_encode($pw);
|
|
|
|
OCP\Config::setAppValue('user_ldap', 'ldap_agent_password', $pwEnc);
|
|
|
|
OC_Appconfig::deleteKey('user_ldap', 'ldap_password');
|
2012-05-17 17:33:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//detect if we can switch on naming guidelines. We won't do it on conflicts.
|
|
|
|
//it's a bit spaghetti, but hey.
|
2012-08-23 16:29:43 +00:00
|
|
|
$state = OCP\Config::getSystemValue('ldapIgnoreNamingRules', 'unset');
|
2012-09-07 13:22:01 +00:00
|
|
|
if($state == 'unset') {
|
2012-05-18 15:38:22 +00:00
|
|
|
OCP\Config::setSystemValue('ldapIgnoreNamingRules', false);
|
2012-05-28 11:57:45 +00:00
|
|
|
}
|
2012-07-02 18:31:07 +00:00
|
|
|
|
2012-08-23 16:29:43 +00:00
|
|
|
//from version 0.2 to 0.3 (0.2.0.x dev version)
|
2012-07-02 18:31:07 +00:00
|
|
|
$objects = array('user', 'group');
|
|
|
|
|
2013-01-24 21:39:05 +00:00
|
|
|
$connector = new \OCA\user_ldap\lib\Connection();
|
2012-08-23 16:29:43 +00:00
|
|
|
$userBE = new \OCA\user_ldap\USER_LDAP();
|
|
|
|
$userBE->setConnector($connector);
|
|
|
|
$groupBE = new \OCA\user_ldap\GROUP_LDAP();
|
|
|
|
$groupBE->setConnector($connector);
|
|
|
|
|
2012-07-02 18:31:07 +00:00
|
|
|
foreach($objects as $object) {
|
2012-11-16 23:03:35 +00:00
|
|
|
$fetchDNSql = '
|
|
|
|
SELECT `ldap_dn`, `owncloud_name`, `directory_uuid`
|
|
|
|
FROM `*PREFIX*ldap_'.$object.'_mapping`';
|
|
|
|
$updateSql = '
|
|
|
|
UPDATE `*PREFIX*ldap_'.$object.'_mapping`
|
|
|
|
SET `ldap_DN` = ?, `directory_uuid` = ?
|
|
|
|
WHERE `ldap_dn` = ?';
|
2012-07-02 18:31:07 +00:00
|
|
|
|
|
|
|
$query = OCP\DB::prepare($fetchDNSql);
|
|
|
|
$res = $query->execute();
|
|
|
|
$DNs = $res->fetchAll();
|
|
|
|
$updateQuery = OCP\DB::prepare($updateSql);
|
|
|
|
foreach($DNs as $dn) {
|
2012-11-16 23:03:35 +00:00
|
|
|
$newDN = escapeDN(mb_strtolower($dn['ldap_dn'], 'UTF-8'));
|
|
|
|
if(!empty($dn['directory_uuid'])) {
|
|
|
|
$uuid = $dn['directory_uuid'];
|
|
|
|
} elseif($object == 'user') {
|
2012-08-23 16:29:43 +00:00
|
|
|
$uuid = $userBE->getUUID($newDN);
|
2012-08-30 12:54:52 +00:00
|
|
|
//fix home folder to avoid new ones depending on the configuration
|
|
|
|
$userBE->getHome($dn['owncloud_name']);
|
2012-08-23 16:29:43 +00:00
|
|
|
} else {
|
|
|
|
$uuid = $groupBE->getUUID($newDN);
|
|
|
|
}
|
2012-11-16 23:03:35 +00:00
|
|
|
try {
|
|
|
|
$updateQuery->execute(array($newDN, $uuid, $dn['ldap_dn']));
|
|
|
|
} catch(Exception $e) {
|
2013-02-14 21:16:48 +00:00
|
|
|
\OCP\Util::writeLog('user_ldap',
|
|
|
|
'Could not update '.$object.' '.$dn['ldap_dn'].' in the mappings table. ',
|
|
|
|
\OCP\Util::WARN);
|
2012-11-16 23:03:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function escapeDN($dn) {
|
|
|
|
$aDN = ldap_explode_dn($dn, false);
|
|
|
|
unset($aDN['count']);
|
|
|
|
foreach($aDN as $key => $part) {
|
|
|
|
$value = substr($part, strpos($part, '=')+1);
|
|
|
|
$escapedValue = strtr($value, Array(','=>'\2c', '='=>'\3d', '+'=>'\2b',
|
|
|
|
'<'=>'\3c', '>'=>'\3e', ';'=>'\3b', '\\'=>'\5c',
|
|
|
|
'"'=>'\22', '#'=>'\23'));
|
|
|
|
$part = str_replace($part, $value, $escapedValue);
|
2012-07-02 18:31:07 +00:00
|
|
|
}
|
2012-11-16 23:03:35 +00:00
|
|
|
$dn = implode(',', $aDN);
|
|
|
|
|
|
|
|
return $dn;
|
2012-07-02 18:31:07 +00:00
|
|
|
}
|
2013-01-24 21:39:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
// SUPPORTED UPGRADE FROM Version 0.3 (ownCloud 4.5) to 0.4 (ownCloud 5)
|
|
|
|
|
|
|
|
if(!isset($connector)) {
|
|
|
|
$connector = new \OCA\user_ldap\lib\Connection();
|
|
|
|
}
|
2013-01-31 16:44:25 +00:00
|
|
|
//it is required, that connections do have ldap_configuration_active setting stored in the database
|
2013-01-24 21:39:05 +00:00
|
|
|
$connector->getConfiguration();
|
2013-02-06 01:29:55 +00:00
|
|
|
$connector->saveConfiguration();
|
|
|
|
|
2013-02-09 12:10:53 +00:00
|
|
|
// we don't save it anymore, was a well-meant bad idea. Clean up database.
|
|
|
|
$query = OC_DB::prepare('DELETE FROM `*PREFIX*preferences` WHERE `appid` = ? AND `configkey` = ?');
|
|
|
|
$query->execute(array('user_ldap' , 'homedir'));
|