Esempio n. 1
0
 /**
  * @param CAccount $oAccount
  * @return bool
  */
 public function UpdateAccount(CAccount $oAccount)
 {
     $oAccount->PreviousMailPassword = '';
     $oAccount->FlushObsolete('PreviousMailPassword');
     CSession::Set(CApiUsersNodbStorage::SESS_ACCOUNT_STORAGE, $oAccount);
     return true;
 }
Esempio n. 2
0
 /**
  * Obtains CAccount object by query-string.
  * 
  * @param string $sSql Query-string for obtaining CAccount object.
  * 
  * @return CAccount
  */
 protected function _getAccountBySql($sSql)
 {
     $oAccount = false;
     if ($this->oConnection->Execute($sSql)) {
         $oAccount = null;
         $oRow = $this->oConnection->GetNextRecord();
         if ($oRow) {
             $this->oConnection->FreeResult();
             /* @var $oApiDomainsManager CApiDomainsManager */
             $oApiDomainsManager = CApi::Manager('domains');
             $oDomain = null;
             $iDomainId = $oRow->id_domain;
             if (0 < $iDomainId) {
                 $oDomain = $oApiDomainsManager->getDomainById($iDomainId);
             } else {
                 $oDomain = $oApiDomainsManager->getDefaultDomain();
             }
             if ($oDomain) {
                 $oAccount = new CAccount($oDomain);
                 $oAccount->initByDbRow($oRow);
                 $oUser = $this->getUserById($oAccount->IdUser, $oDomain);
                 if ($oUser) {
                     $oAccount->User = $oUser;
                 } else {
                     $oAccount = null;
                 }
             }
         } else {
             $this->oConnection->FreeResult();
         }
     }
     $this->throwDbExceptionIfExist();
     return $oAccount;
 }
Esempio n. 3
0
 /**
  * @param CAccount $oAccount
  */
 public function InitByAccount($oAccount)
 {
     $bResult = false;
     if ($oAccount != null && $this->Dav == null && $this->User != $oAccount->Email || $this->Account->Email != $oAccount->Email) {
         $this->Account = $oAccount;
         $this->User = $oAccount->Email;
         $this->TimeZone = $oAccount->getDefaultStrTimeZone();
         $this->aAddressBooksCache = array();
         $this->aGroupItemsCache = array();
         $this->ContactsCache = array();
         $this->Url = $this->ApiDavManager ? $this->ApiDavManager->getServerUrl() : '';
         $this->Dav = new CDAVClient($this->Url, $this->User, $oAccount->IncomingMailPassword);
         if ($this->Dav->Connect()) {
             $this->Connected = true;
             $this->Principal = $this->Dav->GetCurrentPrincipal();
             $this->AddressBookHomeSet = $this->Dav->GetAddressBookHomeSet($this->Principal);
         }
     }
     if ($this->Account) {
         $bResult = true;
     }
     return $bResult;
 }
Esempio n. 4
0
 /**
  * Initializes system folders.
  * 
  * @param CAccount $oAccount Account object.
  * @param CApiMailFolderCollection $oFolderCollection Collection of folders.
  * @param bool $bCreateUnExistenSystemFilders Create non-existen system folders.
  *
  * @return bool
  */
 private function _initSystemFolders($oAccount, &$oFolderCollection, $bCreateUnExistenSystemFilders)
 {
     $bAddSystemFolder = false;
     try {
         $aFoldersMap = $oAccount->Domain->GetFoldersMap();
         unset($aFoldersMap[EFolderType::Inbox]);
         if (!$oAccount->isExtensionEnabled(CAccount::SpamFolderExtension) && isset($aFoldersMap[EFolderType::Spam])) {
             unset($aFoldersMap[EFolderType::Spam]);
         }
         $aTypes = array_keys($aFoldersMap);
         $aUnExistenSystemNames = array();
         $aSystemNames = $this->getSystemFolderNames($oAccount);
         $oInbox = $oFolderCollection->getFolder('INBOX');
         $oInbox->setType(EFolderType::Inbox);
         if (is_array($aSystemNames) && 0 < count($aSystemNames)) {
             unset($aSystemNames['INBOX']);
             $aUnExistenSystemNames = $aSystemNames;
             foreach ($aSystemNames as $sSystemFolderFullName => $iFolderType) {
                 $iKey = array_search($iFolderType, $aTypes);
                 if (false !== $iKey) {
                     $oFolder = $oFolderCollection->getFolder($sSystemFolderFullName, true);
                     if ($oFolder) {
                         unset($aTypes[$iKey]);
                         unset($aFoldersMap[$iKey]);
                         unset($aUnExistenSystemNames[$sSystemFolderFullName]);
                         $oFolder->setType($iFolderType);
                     }
                 }
             }
         } else {
             // set system type from flags
             $oFolderCollection->foreachWithSubFolders(function ($oFolder) use(&$aTypes, &$aFoldersMap) {
                 $iXListType = $oFolder->getFolderXListType();
                 $iKey = array_search($iXListType, $aTypes);
                 if (false !== $iKey && EFolderType::Custom === $oFolder->getType() && isset($aFoldersMap[$iXListType])) {
                     unset($aTypes[$iKey]);
                     unset($aFoldersMap[$iXListType]);
                     $oFolder->setType($iXListType);
                 }
             });
             // set system type from domain settings
             if (is_array($aFoldersMap) && 0 < count($aFoldersMap)) {
                 $oFolderCollection->foreachOnlyRoot(function ($oFolder) use(&$aFoldersMap) {
                     if (EFolderType::Custom === $oFolder->getType()) {
                         foreach ($aFoldersMap as $iFolderType => $aFoldersNames) {
                             $aList = array();
                             if (is_array($aFoldersNames)) {
                                 $aList = $aFoldersNames;
                             } else {
                                 if (is_string($aFoldersNames)) {
                                     $aList = array($aFoldersNames);
                                 }
                             }
                             if (is_array($aList) && 0 < count($aList)) {
                                 if (in_array($oFolder->getRawName(), $aList) || in_array($oFolder->getName(), $aList)) {
                                     unset($aFoldersMap[$iFolderType]);
                                     $oFolder->setType($iFolderType);
                                 }
                             }
                         }
                     }
                 });
             }
             if (is_array($aFoldersMap) && 0 < count($aFoldersMap)) {
                 $sNamespace = $oFolderCollection->getNamespace();
                 foreach ($aFoldersMap as $iFolderType => $mFolderName) {
                     $sFolderFullName = is_array($mFolderName) && isset($mFolderName[0]) && is_string($mFolderName[0]) && 0 < strlen($mFolderName[0]) ? $mFolderName[0] : (is_string($mFolderName) && 0 < strlen($mFolderName) ? $mFolderName : '');
                     if (0 < strlen($sFolderFullName)) {
                         $aUnExistenSystemNames[$sNamespace . $sFolderFullName] = $iFolderType;
                     }
                 }
             }
         }
         if ($bCreateUnExistenSystemFilders && is_array($aUnExistenSystemNames) && 0 < count($aUnExistenSystemNames)) {
             foreach ($aUnExistenSystemNames as $sFolderFullName => $iFolderType) {
                 $this->createFolderByFullName($oAccount, $sFolderFullName);
                 $bAddSystemFolder = true;
             }
         }
     } catch (Exception $oException) {
         $bAddSystemFolder = false;
     }
     return $bAddSystemFolder;
 }
Esempio n. 5
0
 /**
  * @param CAccount $oAccount
  *
  * @return array
  */
 private function appDataUserSettings($oAccount)
 {
     $aResult = array();
     if ($oAccount) {
         $oSettings =& CApi::GetSettings();
         $oApiCapabilityManager = CApi::Manager('capability');
         /* @var $oApiCapabilityManager CApiCapabilityManager */
         $aResult['IdUser'] = $oAccount->User->IdUser;
         $aResult['MailsPerPage'] = (int) $oAccount->User->MailsPerPage;
         $aResult['ContactsPerPage'] = (int) $oAccount->User->ContactsPerPage;
         $aResult['AutoCheckMailInterval'] = (int) $oAccount->User->AutoCheckMailInterval;
         $aResult['DefaultEditor'] = (int) $oAccount->User->DefaultEditor;
         $aResult['Layout'] = 0;
         $aResult['LoginsCount'] = $oAccount->User->LoginsCount;
         $aResult['CanLoginWithPassword'] = $oAccount->canLoginWithPassword();
         if ($oAccount->User->LoginsCount === 1) {
             $oApiSocialManager = CApi::Manager('social');
             $aSocials = $oApiSocialManager->getSocials($oAccount->IdAccount);
             if (count($aSocials) > 0) {
                 $aResult['SocialName'] = $aSocials[0]->Name;
             }
         }
         $aResult['DefaultTheme'] = $oAccount->User->DefaultSkin;
         $aResult['DefaultLanguage'] = $oAccount->User->DefaultLanguage;
         $aResult['DefaultLanguageShort'] = api_Utils::ConvertLanguageNameToShort($oAccount->User->DefaultLanguage);
         $aResult['DefaultDateFormat'] = $oAccount->User->DefaultDateFormat;
         $aResult['DefaultTimeFormat'] = $oAccount->User->DefaultTimeFormat;
         $aResult['AllowCompose'] = (bool) $oAccount->AllowCompose;
         $aResult['AllowReply'] = (bool) $oAccount->AllowReply;
         $aResult['AllowForward'] = (bool) $oAccount->AllowForward;
         $aFetcherDomains = CApi::GetConf('labs.fetchers.domains', array());
         $aResult['AllowFetcher'] = CApi::GetConf('labs.fetchers', false) && ($oAccount->Domain->IsInternal || \in_array($oAccount->IncomingMailServer, $aFetcherDomains));
         $iSaveMail = $oSettings->GetConf('WebMail/SaveMail');
         $iSaveMail = ESaveMail::Always !== $iSaveMail ? $oAccount->User->SaveMail : ESaveMail::Always;
         $aResult['SaveMail'] = (int) $iSaveMail;
         $aResult['ThreadsEnabled'] = !!$oAccount->Domain->UseThreads;
         $aResult['UseThreads'] = false;
         $aResult['SaveRepliedMessagesToCurrentFolder'] = false;
         $aResult['DesktopNotifications'] = (bool) $oAccount->User->DesktopNotifications;
         $aResult['AllowChangeInputDirection'] = (bool) $oAccount->User->AllowChangeInputDirection;
         $aResult['EnableOpenPgp'] = (bool) $oAccount->User->EnableOpenPgp;
         $aResult['AllowAutosaveInDrafts'] = (bool) $oAccount->User->AllowAutosaveInDrafts;
         $aResult['AutosignOutgoingEmails'] = (bool) $oAccount->User->AutosignOutgoingEmails;
         $aResult['EmailNotification'] = !empty($oAccount->User->EmailNotification) ? $oAccount->User->EmailNotification : $oAccount->Email;
         if ($aResult['ThreadsEnabled']) {
             $aResult['UseThreads'] = (bool) $oAccount->User->UseThreads;
             $aResult['SaveRepliedMessagesToCurrentFolder'] = (bool) $oAccount->User->SaveRepliedMessagesToCurrentFolder;
         }
         $aResult['OutlookSyncEnable'] = $oApiCapabilityManager->isOutlookSyncSupported($oAccount);
         $aResult['MobileSyncEnable'] = $oApiCapabilityManager->isMobileSyncSupported($oAccount);
         $aResult['ShowPersonalContacts'] = $oApiCapabilityManager->isPersonalContactsSupported($oAccount);
         $aResult['ShowGlobalContacts'] = $oApiCapabilityManager->isGlobalContactsSupported($oAccount, true);
         $aResult['IsCollaborationSupported'] = $oApiCapabilityManager->isCollaborationSupported();
         $aResult['AllowFilesSharing'] = (bool) CApi::GetConf('labs.files-sharing', false);
         $aResult['IsFilesSupported'] = $oApiCapabilityManager->isFilesSupported($oAccount);
         $aResult['IsHelpdeskSupported'] = $oApiCapabilityManager->isHelpdeskSupported($oAccount);
         $aResult['IsHelpdeskAgent'] = $aResult['IsHelpdeskSupported'];
         // TODO
         $aResult['AllowHelpdeskNotifications'] = (bool) $oAccount->User->AllowHelpdeskNotifications;
         $aResult['HelpdeskSignature'] = (string) $oAccount->User->HelpdeskSignature;
         $aResult['HelpdeskSignatureEnable'] = (bool) $oAccount->User->HelpdeskSignatureEnable;
         $aResult['LastLogin'] = 0;
         if ($oSettings->GetConf('WebMail/EnableLastLoginNotification')) {
             $aResult['LastLogin'] = $oAccount->User->LastLogin;
         }
         $aResult['AllowVoice'] = false;
         $aResult['VoiceProvider'] = '';
         $aResult['SipRealm'] = '';
         $aResult['SipWebsocketProxyUrl'] = '';
         $aResult['SipOutboundProxyUrl'] = '';
         $aResult['SipCallerID'] = '';
         $aResult['TwilioNumber'] = '';
         $aResult['TwilioEnable'] = true;
         $aResult['SipEnable'] = true;
         $aResult['SipImpi'] = '';
         $aResult['SipPassword'] = '';
         $aResult['FilesEnable'] = $oAccount->User->FilesEnable;
         $oApiTenants = CApi::Manager('tenants');
         /* @var $oApiTenants CApiTenantsManager */
         if ($oApiTenants) {
             $oTenant = 0 < $oAccount->IdTenant ? $oApiTenants->getTenantById($oAccount->IdTenant) : $oApiTenants->getDefaultGlobalTenant();
             if ($oTenant) {
                 if ($oTenant->SipAllowConfiguration && $oTenant->SipAllow && $oTenant->isSipSupported() && $oApiCapabilityManager->isSipSupported($oAccount)) {
                     $aResult['AllowVoice'] = $oTenant->SipAllow;
                     if ($aResult['AllowVoice']) {
                         $aResult['AllowVoice'] = $oAccount->User->SipEnable;
                     }
                     $aResult['VoiceProvider'] = 'sip';
                     $aResult['SipRealm'] = (string) $oTenant->SipRealm;
                     $aResult['SipWebsocketProxyUrl'] = (string) $oTenant->SipWebsocketProxyUrl;
                     $aResult['SipOutboundProxyUrl'] = (string) $oTenant->SipOutboundProxyUrl;
                     $aResult['SipCallerID'] = (string) $oTenant->SipCallerID;
                     $aResult['SipEnable'] = $oAccount->User->SipEnable;
                     $aResult['SipImpi'] = $oAccount->User->SipImpi;
                     $aResult['SipPassword'] = $oAccount->User->SipPassword;
                 } else {
                     if ($oTenant->TwilioAllowConfiguration && $oTenant->TwilioAllow && $oTenant->isTwilioSupported() && $oApiCapabilityManager->isTwilioSupported($oAccount)) {
                         $aResult['AllowVoice'] = $oTenant->TwilioAllow;
                         if ($aResult['AllowVoice']) {
                             $aResult['AllowVoice'] = $oAccount->User->TwilioEnable;
                         }
                         $aResult['VoiceProvider'] = 'twilio';
                         $aResult['TwilioNumber'] = $oAccount->User->TwilioNumber;
                         $aResult['TwilioEnable'] = $oAccount->User->TwilioEnable;
                     }
                 }
             }
             if ($aResult['VoiceProvider'] === 'sip' && (0 === strlen($aResult['SipRealm']) || 0 === strlen($aResult['SipWebsocketProxyUrl']))) {
                 $aResult['AllowVoice'] = false;
                 $aResult['SipRealm'] = '';
                 $aResult['SipWebsocketProxyUrl'] = '';
                 $aResult['SipOutboundProxyUrl'] = '';
                 $aResult['SipCallerID'] = '';
                 $aResult['SipEnable'] = false;
                 $aResult['SipImpi'] = '';
                 $aResult['SipPassword'] = '';
             }
         }
         /* @var $oApiUsersManager CApiUsersManager */
         $oApiUsersManager = CApi::Manager('users');
         /* @var $oApiDavManager CApiDavManager */
         $oApiDavManager = CApi::Manager('dav');
         $aResult['AllowCalendar'] = $oApiCapabilityManager->isCalendarSupported($oAccount);
         $aResult['Calendar'] = null;
         if ($aResult['AllowCalendar'] && $oApiDavManager && $oAccount->IsDefaultAccount) {
             /* @var $oCalUser CCalUser */
             $oCalUser = $oApiUsersManager->getOrCreateCalUser($oAccount->IdUser);
             if ($oCalUser) {
                 $aResult['Calendar'] = array();
                 $aResult['Calendar']['ShowWeekEnds'] = (bool) $oCalUser->ShowWeekEnds;
                 $aResult['Calendar']['ShowWorkDay'] = (bool) $oCalUser->ShowWorkDay;
                 $aResult['Calendar']['WorkDayStarts'] = (int) $oCalUser->WorkDayStarts;
                 $aResult['Calendar']['WorkDayEnds'] = (int) $oCalUser->WorkDayEnds;
                 $aResult['Calendar']['WeekStartsOn'] = (int) $oCalUser->WeekStartsOn;
                 $aResult['Calendar']['DefaultTab'] = (int) $oCalUser->DefaultTab;
                 $aResult['Calendar']['SyncLogin'] = (string) $oApiDavManager->getLogin($oAccount);
                 $aResult['Calendar']['DavServerUrl'] = (string) $oApiDavManager->getServerUrl($oAccount);
                 $aResult['Calendar']['DavPrincipalUrl'] = (string) $oApiDavManager->getPrincipalUrl($oAccount);
                 $aResult['Calendar']['AllowReminders'] = true;
             }
         }
         $aResult['CalendarSharing'] = false;
         $aResult['CalendarAppointments'] = false;
         $aResult['AllowCalendar'] = null === $aResult['Calendar'] ? false : $aResult['AllowCalendar'];
         if ($aResult['AllowCalendar']) {
             $aResult['CalendarSharing'] = $oApiCapabilityManager->isCalendarSharingSupported($oAccount);
             $aResult['CalendarAppointments'] = $oApiCapabilityManager->isCalendarAppointmentsSupported($oAccount);
         }
         $bIsDemo = false;
         CApi::Plugin()->RunHook('plugin-is-demo-account', array(&$oAccount, &$bIsDemo));
         $aResult['IsDemo'] = $bIsDemo;
         CApi::Plugin()->RunHook('api-app-user-data', array(&$oAccount, &$aResult));
     }
     return $aResult;
 }
 /**
  * @param string $sWhere
  * @return string
  */
 protected function getAccountByWhere($sWhere)
 {
     $aMap = api_AContainer::DbReadKeys(CAccount::GetStaticMap());
     $aMap = array_map(array($this, 'escapeColumn'), $aMap);
     $sSql = 'SELECT %s FROM %sawm_accounts WHERE %s';
     return sprintf($sSql, implode(', ', $aMap), $this->Prefix(), $sWhere);
 }
Esempio n. 7
0
 /**
  * @param CAccount $oAccount
  * @param string $sAuthType
  * @param int $iDataType
  * @param string $sDataValue
  * @return bool
  */
 public function updateAccount(CAccount &$oAccount, $sAuthType, $iDataType, $sDataValue)
 {
     $bResult = false;
     try {
         if ($oAccount->isValid()) {
             $this->oStorage->updateAccount($oAccount, $sAuthType, $iDataType, $sDataValue);
         }
         $bResult = true;
     } catch (CApiBaseException $oException) {
         $bResult = false;
         $this->setLastException($oException);
     }
     return $bResult;
 }
Esempio n. 8
0
 /**
  * Saves changes made to the account.
  * 
  * @api
  * 
  * @param CAccount &$oAccount Account object containing data to be saved.
  * @param bool $bSetIdentityDefault Default value is **false**.. If **true** account identity needs treatting as default.
  * 
  * @return bool
  */
 public function updateAccount(CAccount &$oAccount, $bSetIdentityDefault = false)
 {
     $bResult = false;
     try {
         if ($oAccount->isValid()) {
             $oAccount->IncomingMailUseSSL = in_array($oAccount->IncomingMailPort, array(993, 995));
             $oAccount->OutgoingMailUseSSL = in_array($oAccount->OutgoingMailPort, array(465));
             if (0 < $oAccount->Domain->IdTenant && CApi::GetConf('tenant', false) && null !== $oAccount->GetObsoleteValue('StorageQuota')) {
                 /* @var $oTenantsApi CApiTenantsManager */
                 $oTenantsApi = CApi::Manager('tenants');
                 if ($oTenantsApi) {
                     /* @var $oTenant CTenant */
                     $oTenant = $oTenantsApi->getTenantById($oAccount->Domain->IdTenant);
                     if (!$oTenant) {
                         throw new CApiManagerException(Errs::TenantsManager_TenantDoesNotExist);
                     } else {
                         $this->_validateAccountSubscriptionLimits($oAccount, $oTenant, false);
                         if (0 < $oTenant->QuotaInMB) {
                             $iAccountStorageQuota = $oAccount->GetObsoleteValue('StorageQuota');
                             $iSize = $oTenantsApi->getTenantAllocatedSize($oTenant->IdTenant);
                             $iSize -= (int) ($iAccountStorageQuota / 1024);
                             if ((int) ($oAccount->getRealQuotaSize() / 1024) + $iSize > $oTenant->QuotaInMB) {
                                 throw new CApiManagerException(Errs::TenantsManager_QuotaLimitExided);
                             }
                         }
                     }
                 }
             }
             $bUseOnlyHookUpdate = false;
             CApi::Plugin()->RunHook('api-update-account', array(&$oAccount, &$bUseOnlyHookUpdate));
             if (!$bUseOnlyHookUpdate) {
                 if (!$this->oStorage->updateAccount($oAccount)) {
                     $this->moveStorageExceptionToManager();
                     throw new CApiManagerException(Errs::UserManager_AccountUpdateFailed);
                 }
             }
             if ($oAccount->IsDefaultAccount && 0 < $oAccount->User->IdHelpdeskUser) {
                 /* @var $oApiHelpdeskManager CApiHelpdeskManager */
                 $oApiHelpdeskManager = CApi::Manager('helpdesk');
                 if ($oApiHelpdeskManager) {
                     $oHelpdeskUser = $oApiHelpdeskManager->getUserById($oAccount->IdTenant, $oAccount->User->IdHelpdeskUser);
                     if ($oHelpdeskUser) {
                         $oHelpdeskUser->MailNotifications = $oAccount->User->AllowHelpdeskNotifications;
                         $oHelpdeskUser->Signature = $oAccount->User->HelpdeskSignature;
                         $oHelpdeskUser->SignatureEnable = $oAccount->User->HelpdeskSignatureEnable;
                         $oHelpdeskUser->Name = $oAccount->FriendlyName;
                         $oApiHelpdeskManager->updateUser($oHelpdeskUser);
                     }
                 }
             }
             if ($oAccount->IsDefaultAccount && (null !== $oAccount->GetObsoleteValue('FriendlyName') && $oAccount->GetObsoleteValue('FriendlyName') !== $oAccount->FriendlyName || null !== $oAccount->GetObsoleteValue('HideInGAB') && $oAccount->GetObsoleteValue('HideInGAB') !== $oAccount->HideInGAB)) {
                 /* @var $oApiGContactsManager CApiGcontactsManager */
                 $oApiGContactsManager = CApi::Manager('gcontacts');
                 if ($oApiGContactsManager) {
                     $oContact = $oApiGContactsManager->getContactByTypeId($oAccount, $oAccount->IdUser, true);
                     if ($oContact) {
                         $oContact->FullName = $oAccount->FriendlyName;
                         $oContact->HideInGAB = !!$oAccount->HideInGAB;
                         $oApiGContactsManager->updateContact($oContact);
                     }
                 }
             }
             if ($bSetIdentityDefault) {
                 $this->oStorage->updateIdentitiesDefaults(null, $oAccount->IdAccount);
                 //TODO remove this from there
             }
             $bResult = true;
         }
     } catch (CApiBaseException $oException) {
         $bResult = false;
         $this->setLastException($oException);
     }
     return $bResult;
 }