Esempio n. 1
0
 /**
  * import the accounts from eGroupWare 1.4
  *
  * @todo add primary group or use Admin_Controller_User::getInstance()->create
  * @todo import user password
  */
 protected function importAccounts()
 {
     $this->_log->INFO('start importing egw users');
     $select = $this->_egwDb->select()->from(array('accounts' => 'egw_accounts'))->joinLeft(array('contacts' => 'egw_addressbook'), $this->_egwDb->quoteIdentifier('accounts.account_id') . ' = ' . $this->_egwDb->quoteIdentifier('contacts.account_id'))->where($this->_egwDb->quoteInto($this->_egwDb->quoteIdentifier('accounts.account_type') . ' = ?', 'u'));
     $accounts = $this->_egwDb->fetchAll($select, NULL, Zend_Db::FETCH_OBJ);
     foreach ($accounts as $account) {
         $user = new Tinebase_Model_FullUser(array('accountId' => $account->account_id, 'accountLoginName' => $account->account_lid, 'accountLastLogin' => $account->account_lastlogin > 0 ? new Tinebase_DateTime($account->account_lastlogin) : NULL, 'accountLastLoginfrom' => $account->account_lastloginfrom, 'accountLastPasswordChange' => $account->account_lastpwd_change > 0 ? new Tinebase_DateTime($account->account_lastpwd_change) : NULL, 'accountStatus' => $account->account_status == 'A' ? 'enabled' : 'disabled', 'accountExpires' => $account->account_expires > 0 ? new Tinebase_DateTime($account->account_expires) : NULL, 'accountPrimaryGroup' => abs($account->account_primary_group), 'accountLastName' => $account->n_family ? $account->n_family : 'Lastname', 'accountFirstName' => $account->n_given ? $account->n_given : 'Firstname', 'accountEmailAddress' => isset($account->email) ? $account->email : $account->contact_email));
         $this->_log->DEBUG(__METHOD__ . '::' . __LINE__ . ' user: '******'accountId', $user->accountId);
             $user = Tinebase_User::getInstance()->updateUser($user);
         } catch (Tinebase_Exception_NotFound $ten) {
             $user = Tinebase_User::getInstance()->addUser($user);
         }
         // (re)set password
         Tinebase_User::getInstance()->setPassword($user, $account->account_pwd, FALSE);
         // plase user in his groups
         Tinebase_Group::getInstance()->addGroupMember($user->accountPrimaryGroup, $user);
     }
     $this->_log->NOTICE('imported ' . count($accounts) . ' users from egw');
 }
 /**
  * add new member to course
  * 
  * @param Courses_Model_Course $course
  * @param Tinebase_Model_FullUser $user
  * @return Tinebase_Model_FullUser
  * 
  * @todo use importMembers() here to avoid duplication
  */
 public function createNewMember(Courses_Model_Course $course, Tinebase_Model_FullUser $user)
 {
     $this->checkRight(Courses_Acl_Rights::ADD_NEW_USER);
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Creating new member for ' . $course->name);
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($course->toArray(), TRUE));
     }
     $password = $user->applyOptionsAndGeneratePassword($this->_getNewUserConfig($course));
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . print_r($user->toArray(), TRUE));
     }
     $newMember = $this->_userController->create($user, $password, $password);
     // add to default group and manage access group for user
     $this->_groupController->addGroupMember(Tinebase_Group::getInstance()->getDefaultGroup()->getId(), $newMember->getId());
     $this->_manageAccessGroups(array($newMember->getId()), $course);
     $this->_addToStudentGroup(array($newMember->getId()));
     return $newMember;
 }
 /**
  * import contactdata(phone, address, fax, birthday. photo)
  * 
  * @param Tinebase_Model_FullUser $syncedUser
  * @param array $options
  */
 public static function syncContactData($syncedUser, $options)
 {
     if (!Tinebase_Config::getInstance()->get(Tinebase_Config::SYNC_USER_CONTACT_DATA, true) || !isset($options['syncContactData']) || !$options['syncContactData'] || !Tinebase_Application::getInstance()->isInstalled('Addressbook') || $syncedUser->visibility === Tinebase_Model_FullUser::VISIBILITY_HIDDEN) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Contact data sync disabled');
         }
         return;
     }
     $addressbook = Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL);
     try {
         $contact = $addressbook->getByUserId($syncedUser->getId());
         $originalContact = clone $contact;
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
             Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' user: '******'::' . __LINE__ . ' new contact: ' . print_r($contact->toArray(), true) . ' orig contact:' . print_r($originalContact->toArray(), true));
         }
         // TODO allow to diff jpegphoto, too / maybe this should only be done when called via CLI/cronjob
         $diff = $contact->diff($originalContact, array('jpegphoto'));
         if (!$diff->isEmpty() || $originalContact->jpegphoto == 0 && !empty($contact->jpegphoto)) {
             // add modlog info
             Tinebase_Timemachine_ModificationLog::setRecordMetaData($contact, 'update');
             if ($contact->container_id !== null) {
                 Tinebase_Container::getInstance()->increaseContentSequence($contact->container_id);
             }
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Updating contact data for user ' . $syncedUser->accountLoginName);
             }
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Diff: ' . print_r($diff->toArray(), true));
             }
             $addressbook->update($contact);
         } else {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' User contact is up to date.');
             }
         }
     } catch (Addressbook_Exception_NotFound $aenf) {
         self::createContactForSyncedUser($syncedUser);
         $syncedUser = Tinebase_User::getInstance()->updateUserInSqlBackend($syncedUser);
     } catch (Tinebase_Exception_NotFound $tenf) {
         if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
             Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Contact information seems to be missing in sync backend');
         }
         Tinebase_Exception::log($tenf);
     }
 }
 /**
  * create user
  *
  * @param  Tinebase_Model_FullUser  $_account           the account
  * @param  string                     $_password           the new password
  * @param  string                     $_passwordRepeat  the new password again
  * @return Tinebase_Model_FullUser
  */
 public function create(Tinebase_Model_FullUser $_user, $_password, $_passwordRepeat)
 {
     $this->checkRight('MANAGE_ACCOUNTS');
     // avoid forging accountId, gets created in backend
     unset($_user->accountId);
     if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Create new user ' . $_user->accountLoginName);
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($_user->toArray(), TRUE));
     }
     $this->_checkLoginNameExistance($_user);
     $this->_checkLoginNameLength($_user);
     $this->_checkPrimaryGroupExistance($_user);
     if ($_password != $_passwordRepeat) {
         throw new Admin_Exception("Passwords don't match.");
     } else {
         if (empty($_password)) {
             $_password = '';
             $_passwordRepeat = '';
         }
     }
     Tinebase_User::getInstance()->checkPasswordPolicy($_password, $_user);
     try {
         $transactionId = Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb());
         if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true) {
             $contact = $this->createOrUpdateContact($_user);
             $_user->contact_id = $contact->getId();
         }
         Tinebase_Timemachine_ModificationLog::setRecordMetaData($_user, 'create');
         $user = $this->_userBackend->addUser($_user);
         // make sure primary groups is in the list of groupmemberships
         $groups = array_unique(array_merge(array($user->accountPrimaryGroup), (array) $_user->groups));
         Admin_Controller_Group::getInstance()->setGroupMemberships($user, $groups);
         Tinebase_TransactionManager::getInstance()->commitTransaction($transactionId);
     } catch (Exception $e) {
         Tinebase_TransactionManager::getInstance()->rollBack();
         Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ' ' . $e->getMessage());
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getTraceAsString());
         }
         throw $e;
     }
     $event = new Admin_Event_AddAccount(array('account' => $user));
     Tinebase_Event::fireEvent($event);
     $this->setAccountPassword($user, $_password, $_passwordRepeat);
     return $user;
 }
 /**
  * returns array of raw email user data
  *
  * @param  Tinebase_Model_EmailUser $_user
  * @param  Tinebase_Model_EmailUser $_newUserProperties
  * @throws Tinebase_Exception_UnexpectedValue
  * @return array
  * 
  * @todo   validate domains of aliases too
  */
 protected function _recordToRawData(Tinebase_Model_FullUser $_user, Tinebase_Model_FullUser $_newUserProperties)
 {
     $rawData = array();
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($_newUserProperties->toArray(), true));
     }
     if (isset($_newUserProperties->smtpUser)) {
         foreach ($_newUserProperties->smtpUser as $key => $value) {
             $property = isset($this->_propertyMapping[$key]) || array_key_exists($key, $this->_propertyMapping) ? $this->_propertyMapping[$key] : false;
             if ($property) {
                 switch ($key) {
                     case 'emailAliases':
                         $rawData[$property] = array();
                         foreach ((array) $value as $address) {
                             if ($this->_checkDomain($address) === true) {
                                 $rawData[$property][] = $address;
                             }
                         }
                         break;
                     case 'emailForwards':
                         $rawData[$property] = is_array($value) ? $value : array();
                         break;
                     default:
                         $rawData[$property] = $value;
                         break;
                 }
             }
         }
     }
     if (!empty($_user->accountEmailAddress)) {
         $this->_checkDomain($_user->accountEmailAddress, TRUE);
     }
     $rawData[$this->_propertyMapping['emailAddress']] = $_user->accountEmailAddress;
     $rawData[$this->_propertyMapping['emailUserId']] = $_user->getId();
     $rawData[$this->_propertyMapping['emailUsername']] = $_user->accountLoginName;
     if (empty($rawData[$this->_propertyMapping['emailAddress']])) {
         $rawData[$this->_propertyMapping['emailAliases']] = null;
         $rawData[$this->_propertyMapping['emailForwards']] = null;
     }
     if (empty($rawData[$this->_propertyMapping['emailForwards']])) {
         $rawData[$this->_propertyMapping['emailForwardOnly']] = 0;
     }
     $rawData['domain'] = $this->_config['domain'];
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($rawData, true));
     }
     return $rawData;
 }
Esempio n. 6
0
 /**
  * add one record
  *
  * @param   Tinebase_Record_Interface $_record
  * @return  Tinebase_Record_Interface
  */
 public function create(Tinebase_Record_Interface $_record)
 {
     $course = parent::create($_record);
     // add teacher account
     $i18n = Tinebase_Translation::getTranslation('Courses');
     $courseName = strtolower($course->name);
     $loginName = strtolower($i18n->_('teacher') . '-' . $course->name);
     $schoolName = strtolower(Tinebase_Department::getInstance()->get($course->type)->name);
     $account = new Tinebase_Model_FullUser(array('accountLoginName' => $loginName, 'accountLoginShell' => '/bin/false', 'accountStatus' => 'enabled', 'accountPrimaryGroup' => $course->group_id, 'accountLastName' => $i18n->_('Teacher'), 'accountDisplayName' => $course->name . ' ' . $i18n->_('Teacher Account'), 'accountFirstName' => $course->name, 'accountExpires' => NULL, 'accountEmailAddress' => isset($this->_config->domain) && !empty($this->_config->domain) ? $loginName . '@' . $this->_config->domain : '', 'accountHomeDirectory' => isset($this->_config->basehomedir) ? $this->_config->basehomedir . $schoolName . '/' . $courseName . '/' . $loginName : ''));
     if (isset($this->_config->samba)) {
         $samUser = new Tinebase_Model_SAMUser(array('homePath' => $this->_config->samba->basehomepath . $loginName, 'homeDrive' => $this->_config->samba->homedrive, 'logonScript' => $courseName . $this->_config->samba->logonscript_postfix_teacher, 'profilePath' => $this->_config->samba->baseprofilepath . $schoolName . '\\' . $courseName . '\\' . $loginName));
         $account->sambaSAM = $samUser;
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Created teacher account for course ' . $course->name . ': ' . print_r($account->toArray(), true));
     }
     #$event = new Courses_Event_BeforeAddTeacher($account, $course);
     #Tinebase_Event::fireEvent($event);
     $password = $this->_config->get('teacher_password', $account->accountLoginName);
     $account = Admin_Controller_User::getInstance()->create($account, $password, $password);
     // add to teacher group if available
     if (isset($this->_config->teacher_group) && !empty($this->_config->teacher_group)) {
         Admin_Controller_Group::getInstance()->addGroupMember($this->_config->teacher_group, $account->getId());
     }
     // add to students group if available
     if (isset($this->_config->students_group) && !empty($this->_config->students_group)) {
         Admin_Controller_Group::getInstance()->addGroupMember($this->_config->students_group, $account->getId());
     }
     return $course;
 }