/**
  * repair groups
  * 
  * * add missing lists
  * * checks if list container has been deleted (and hides groups if that's the case)
  * 
  * @see 0010401: add repair script for groups without list_ids
  */
 public function repairGroups()
 {
     $count = 0;
     $be = new Tinebase_Group_Sql();
     $listBackend = new Addressbook_Backend_List();
     $groups = $be->getGroups();
     foreach ($groups as $group) {
         if ($group->list_id == null) {
             $list = Addressbook_Controller_List::getInstance()->createByGroup($group);
             $group->list_id = $list->getId();
             $group->visibility = Tinebase_Model_Group::VISIBILITY_DISPLAYED;
             if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
                 Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Add missing list for group ' . $group->name);
             }
             $be->updateGroupInSqlBackend($group);
             $count++;
         } else {
             if ($group->visibility === Tinebase_Model_Group::VISIBILITY_DISPLAYED) {
                 try {
                     $list = $listBackend->get($group->list_id);
                     $listContainer = Tinebase_Container::getInstance()->get($list->container_id);
                 } catch (Tinebase_Exception_NotFound $tenf) {
                     if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
                         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Hide group ' . $group->name . ' without list / list container.');
                     }
                     $group->visibility = Tinebase_Model_Group::VISIBILITY_HIDDEN;
                     $be->updateGroupInSqlBackend($group);
                     $count++;
                 }
             }
         }
     }
     echo $count . " groups repaired!\n";
 }
예제 #2
0
 /**
  * Sets up the fixture.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $this->objects['initialAccount'] = new Tinebase_Model_FullUser(array('accountId' => 10, 'accountLoginName' => 'tine20phpunit', 'accountStatus' => 'enabled', 'accountExpires' => NULL, 'accountPrimaryGroup' => Tinebase_Group_Sql::getInstance()->getGroupByName('Users')->id, 'accountLastName' => 'Tine 2.0', 'accountFirstName' => 'PHPUnit', 'accountEmailAddress' => '*****@*****.**'));
     $this->objects['updatedAccount'] = new Tinebase_Model_FullUser(array('accountId' => 10, 'accountLoginName' => 'tine20phpunit-updated', 'accountStatus' => 'disabled', 'accountExpires' => NULL, 'accountPrimaryGroup' => Tinebase_Group_Sql::getInstance()->getGroupByName('Users')->id, 'accountLastName' => 'Tine 2.0 Updated', 'accountFirstName' => 'PHPUnit Updated', 'accountEmailAddress' => '*****@*****.**'));
     $this->objects['deleteAccount'] = new Tinebase_Model_FullUser(array('accountId' => 11, 'accountLoginName' => 'tine20phpunit-delete', 'accountStatus' => 'disabled', 'accountExpires' => NULL, 'accountPrimaryGroup' => Tinebase_Group_Sql::getInstance()->getGroupByName('Users')->id, 'accountLastName' => 'Tine 2.0 delete', 'accountFirstName' => 'PHPUnit delete', 'accountEmailAddress' => '*****@*****.**'));
     $this->objects['noIdAccount'] = new Tinebase_Model_FullUser(array('accountLoginName' => 'tine20phpunit-noid', 'accountStatus' => 'disabled', 'accountExpires' => NULL, 'accountPrimaryGroup' => Tinebase_Group_Sql::getInstance()->getGroupByName('Users')->id, 'accountLastName' => 'Tine 2.0 noid', 'accountFirstName' => 'PHPUnit noid', 'accountEmailAddress' => '*****@*****.**'));
     return;
 }
 public function testSetGroupMembershipsWithArray()
 {
     $groups[] = new Tinebase_Model_Group(array('name' => 'tine20phpunit1', 'description' => 'group1'));
     $groups[] = new Tinebase_Model_Group(array('name' => 'tine20phpunit2', 'description' => 'group2'));
     $groupId1 = $this->_backend->addGroup($groups[0]);
     $groupId2 = $this->_backend->addGroup($groups[1]);
     $accountId = Tinebase_Core::getUser()->getId();
     $oldGroupMemberships = Tinebase_Core::getUser()->getGroupMemberships();
     $this->_backend->setGroupMembershipsInSqlBackend($accountId, array($groupId1->id, $groupId2->id, $groupId1->id));
     $getGroupMembersArray = $this->_backend->getGroupMembers($groupId1);
     $this->assertTrue(in_array($accountId, $getGroupMembersArray));
     $getGroupMembersArray = $this->_backend->getGroupMembers($groupId2);
     $this->assertTrue(in_array($accountId, $getGroupMembersArray));
     $this->_backend->setGroupMembershipsInSqlBackend($accountId, $oldGroupMemberships);
     $this->_backend->deleteGroups(array($groupId1, $groupId2));
 }
 /**
  * the constructor
  *
  * @param  array $options Options used in connecting, binding, etc.
  */
 public function __construct(array $_options)
 {
     parent::__construct();
     if (empty($_options['userUUIDAttribute'])) {
         $_options['userUUIDAttribute'] = 'entryUUID';
     }
     if (empty($_options['groupUUIDAttribute'])) {
         $_options['groupUUIDAttribute'] = 'entryUUID';
     }
     if (empty($_options['baseDn'])) {
         $_options['baseDn'] = $_options['userDn'];
     }
     if (empty($_options['userFilter'])) {
         $_options['userFilter'] = 'objectclass=posixaccount';
     }
     if (empty($_options['userSearchScope'])) {
         $_options['userSearchScope'] = Zend_Ldap::SEARCH_SCOPE_SUB;
     }
     if (empty($_options['groupFilter'])) {
         $_options['groupFilter'] = 'objectclass=posixgroup';
     }
     $this->_options = $_options;
     if (isset($_options['readonly']) || array_key_exists('readonly', $_options)) {
         $this->_isReadOnlyBackend = (bool) $_options['readonly'];
     }
     if (isset($_options['ldap']) || array_key_exists('ldap', $_options)) {
         $this->_ldap = $_options['ldap'];
     }
     if (isset($this->_options['requiredObjectClass'])) {
         $this->_requiredObjectClass = (array) $this->_options['requiredObjectClass'];
     }
     if (!array_key_exists('groupsDn', $this->_options) || empty($this->_options['groupsDn'])) {
         $this->_isDisabledBackend = true;
     }
     $this->_userUUIDAttribute = strtolower($this->_options['userUUIDAttribute']);
     $this->_groupUUIDAttribute = strtolower($this->_options['groupUUIDAttribute']);
     $this->_baseDn = $this->_options['baseDn'];
     $this->_userBaseFilter = $this->_options['userFilter'];
     $this->_userSearchScope = $this->_options['userSearchScope'];
     $this->_groupBaseFilter = $this->_options['groupFilter'];
     if (isset($_options['plugins']) && is_array($_options['plugins'])) {
         foreach ($_options['plugins'] as $className) {
             $this->_plugins[$className] = new $className($this->getLdap(), $this->_options);
         }
     }
 }
예제 #5
0
 /**
  * the constructor
  *
  * @param  array $options Options used in connecting, binding, etc.
  */
 public function __construct(array $_options)
 {
     parent::__construct();
     if (empty($_options['userUUIDAttribute'])) {
         $_options['userUUIDAttribute'] = 'entryUUID';
     }
     if (empty($_options['groupUUIDAttribute'])) {
         $_options['groupUUIDAttribute'] = 'entryUUID';
     }
     if (empty($_options['baseDn'])) {
         $_options['baseDn'] = $_options['userDn'];
     }
     if (empty($_options['userFilter'])) {
         $_options['userFilter'] = 'objectclass=posixaccount';
     }
     if (empty($_options['userSearchScope'])) {
         $_options['userSearchScope'] = Zend_Ldap::SEARCH_SCOPE_SUB;
     }
     if (empty($_options['groupFilter'])) {
         $_options['groupFilter'] = 'objectclass=posixgroup';
     }
     if (isset($_options['requiredObjectClass'])) {
         $this->_requiredObjectClass = (array) $_options['requiredObjectClass'];
     }
     if (array_key_exists('readonly', $_options)) {
         $this->_isReadOnlyBackend = (bool) $_options['readonly'];
     }
     $this->_options = $_options;
     $this->_userUUIDAttribute = strtolower($this->_options['userUUIDAttribute']);
     $this->_groupUUIDAttribute = strtolower($this->_options['groupUUIDAttribute']);
     $this->_baseDn = $this->_options['baseDn'];
     $this->_userBaseFilter = $this->_options['userFilter'];
     $this->_userSearchScope = $this->_options['userSearchScope'];
     $this->_groupBaseFilter = $this->_options['groupFilter'];
     $this->_ldap = new Tinebase_Ldap($_options);
     $this->_ldap->bind();
     $this->_sql = new Tinebase_Group_Sql();
     foreach ($_options['plugins'] as $className) {
         $this->_plugins[$className] = new $className($this->_ldap, $this->_options);
     }
 }
예제 #6
0
 /**
  * read ldap / get users and groups from tine an create mapping
  * 
  * @return array
  */
 protected function _getGroupMapping()
 {
     $this->_logger->info(__METHOD__ . '::' . __LINE__ . ' Fetching user mapping ...');
     $filter = Zend_Ldap_Filter::andFilter(Zend_Ldap_Filter::string($this->_groupBaseFilter));
     $mapping = array();
     $groupNameMapping = $this->_config->groupNameMapping ? $this->_config->groupNameMapping->toArray() : array();
     $this->_logger->debug(__METHOD__ . '::' . __LINE__ . ' Group name mapping: ' . print_r($groupNameMapping, TRUE));
     $ldapGroups = $this->_ldap->search($filter, $this->_config->ldap->baseDn, $this->_groupSearchScope, array('*', '+'));
     foreach ($ldapGroups as $group) {
         $groupname = isset($groupNameMapping[$group['cn'][0]]) ? $groupNameMapping[$group['cn'][0]] : $group['cn'][0];
         $ldapUuid = $group['entryuuid'][0];
         try {
             $tineGroup = $this->_tineGroupBackend->getGroupByName($groupname);
             $this->_logger->debug(__METHOD__ . '::' . __LINE__ . ' Group ' . $groupname . ' (' . $group['cn'][0] . '): ' . $tineGroup->getId() . ' -> ' . $ldapUuid);
             $mapping[$tineGroup->getId()] = $ldapUuid;
         } catch (Tinebase_Exception_Record_NotDefined $tenf) {
             // @todo should be: Tinebase_Exception_NotFound
             $this->_logger->debug(__METHOD__ . '::' . __LINE__ . ' Group ' . $groupname . ' (' . $group['cn'][0] . '): ' . $tenf->getMessage());
         }
     }
     $this->_logger->info(__METHOD__ . '::' . __LINE__ . ' Found ' . count($mapping) . ' groups for the mapping.');
     $this->_logger->debug(__METHOD__ . '::' . __LINE__ . ' ' . print_r($mapping, TRUE));
     return $mapping;
 }
예제 #7
0
 /**
  * import users from typo3
  * 
  * @param array | optional $_options [options hash passed through the whole setup initialization process]
  *
  */
 public function importUsers($_options = null)
 {
     $sqlGroupBackend = new Tinebase_Group_Sql();
     $t3users = $this->_getUsersFromBackend(NULL, 'Tinebase_Model_FullUser');
     foreach ($t3users as $user) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' user: '******'::' . __LINE__ . ' Could not add user "' . $user->accountLoginName . '" => Skipping');
             Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' classname ' . get_class($user) . ' attributes: ' . print_r($user, 1));
             continue;
         }
         $sqlGroupBackend->addGroupMember($user->accountPrimaryGroup, $user);
         // we directly can import password as its also md5
         $select = $this->_t3db->select()->from('be_users')->where("`uid` LIKE '{$user->getId()}'");
         $t3user = $select->query()->fetchAll(Zend_Db::FETCH_ASSOC);
         $md5passwd = $t3user[0]['password'];
         // import contactdata(phone, address, fax, birthday. photo)
         //$contact = $this->_getContactFromBackend($user);
         //Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL)->update($contact);
     }
 }
 protected function _testImportGroupsHelper($expected)
 {
     $be = new Tinebase_Group_Sql();
     foreach ($expected as $name => $count) {
         $group = $be->getGroupByName($name);
         $members = $be->getGroupMembers($group);
         $this->assertEquals($count, count($members), 'Group ' . $name . ' should have ' . $count . ' members!');
         $this->assertEquals('displayed', $group->visibility, 'Group ' . $name . ' should be visible!');
     }
 }
 /**
  * 
  * @param Tinebase_Record_Abstract $record
  * @param array $members
  */
 protected function _handleGroupMemberShip($record, $members)
 {
     $be = new Tinebase_Group_Sql();
     $group = $be->getGroupByName($record->name);
     $oldMembers = $be->getGroupMembers($group->getId());
     $newMembers = $this->_resolveUsers($members);
     foreach ($oldMembers as $oldMember) {
         if (!in_array($oldMember, $newMembers)) {
             $be->removeGroupMember($record->getId(), $oldMember);
         }
     }
     foreach ($newMembers as $newMember) {
         if (!in_array($newMember, $oldMembers)) {
             $be->addGroupMember($record->getId(), $newMember);
         }
     }
 }
 /**
  * import groupmembers from typo3
  * 
  * NOTE: in typo3 the user object/dbrow knows the group memberships
  * 
  * @return void
  */
 public function importGroupMembers()
 {
     $select = $this->_t3db->select()->from('be_users');
     $usersData = $select->query()->fetchAll(Zend_Db::FETCH_ASSOC);
     // build a groupMap
     $userGroup = Tinebase_Group::getInstance()->getDefaultGroup()->getId();
     $adminGroup = Tinebase_Group::getInstance()->getDefaultAdminGroup()->getId();
     $groupMap = array($userGroup => array(), $adminGroup => array());
     foreach ($usersData as $t3user) {
         $userId = $t3user['uid'];
         // put user in default user OR admin group
         $groupMap[$t3user['admin'] == 1 ? $adminGroup : $userGroup][] = $userId;
         // evaluate typo3 groups
         if (empty($t3user['usergroup'])) {
             continue;
         }
         $t3userGroups = explode(',', $t3user['usergroup']);
         foreach ((array) $t3userGroups as $groupId) {
             if (!(isset($groupMap[$groupId]) || array_key_exists($groupId, $groupMap))) {
                 $groupMap[$groupId] = array();
             }
             $groupMap[$groupId][] = $userId;
         }
     }
     $sqlGroupBackend = new Tinebase_Group_Sql();
     foreach ($groupMap as $groupId => $groupMembers) {
         try {
             $sqlGroupBackend->setGroupMembers($groupId, $groupMembers);
         } catch (Exception $e) {
             // ignore errors
             Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' could not set groupmembers: ' . $e->getMessage());
         }
     }
 }