Ejemplo n.º 1
0
 /**
  * @param CDomain $oDomain
  * @return void
  */
 public function __construct()
 {
     parent::__construct(get_class($this), 'IdIdentity');
     $this->SetTrimer(array('Email', 'FriendlyName'));
     $this->SetDefaults(array('IdIdentity' => 0, 'IdUser' => 0, 'IdAccount' => 0, 'Virtual' => false, 'Default' => false, 'Enabled' => true, 'Email' => '', 'FriendlyName' => '', 'Signature' => '', 'SignatureType' => EAccountSignatureType::Html, 'UseSignature' => false));
     CApi::Plugin()->RunHook('api-identity-construct', array(&$this));
 }
Ejemplo n.º 2
0
 public function getDigestHash($sRealm, $sUserName)
 {
     if (class_exists('CApi') && \CApi::IsValid()) {
         /* @var $oApiCapabilityManager \CApiCapabilityManager */
         $oApiCapabilityManager = \CApi::GetSystemManager('capability');
         if ($oApiCapabilityManager) {
             $oAccount = \Afterlogic\DAV\Utils::GetAccountByLogin($sUserName);
             if ($oAccount && $oAccount->IsDisabled) {
                 return null;
             }
             $bIsOutlookSyncClient = \Afterlogic\DAV\Utils::ValidateClient('outlooksync');
             $bIsMobileSync = false;
             $bIsOutlookSync = false;
             $bIsDemo = false;
             if ($oAccount) {
                 $bIsMobileSync = $oApiCapabilityManager->isMobileSyncSupported($oAccount);
                 $bIsOutlookSync = $oApiCapabilityManager->isOutlookSyncSupported($oAccount);
                 \CApi::Plugin()->RunHook('plugin-is-demo-account', array(&$oAccount, &$bIsDemo));
             }
             if ($oAccount && ($bIsMobileSync && !$bIsOutlookSyncClient || $bIsOutlookSync && $bIsOutlookSyncClient) || $bIsDemo || $sUserName === \CApi::ExecuteMethod('Dav::GetPublicUser')) {
                 return md5($sUserName . ':' . $sRealm . ':' . ($bIsDemo ? 'demo' : $oAccount->IncomingMailPassword));
             }
         }
     }
     return null;
 }
Ejemplo n.º 3
0
 public function CommonSocial(ap_Standard_Screen &$oScreen)
 {
     $oApiCapa = CApi::Manager('capability');
     /* @var $oApiCapa CApiCapabilityManager */
     if ($oApiCapa && !$this->oAdminPanel->IsOnlyReadAuthType()) {
         $oTenant = $this->oModule->GetTenantAdminObject();
         if ($oTenant) {
             $aConnectors = array();
             $oPlugin = \CApi::Plugin()->GetPluginByName('external-services');
             if ($oPlugin) {
                 $aEnableConnectors = $oPlugin->GetEnabledConnectors();
                 $aSocials = $oTenant->getSocials();
                 foreach ($aSocials as $sKey => $oSocial) {
                     if (in_array($sKey, $aEnableConnectors)) {
                         $oSocial->SupportedScopes = $oPlugin->GetSupportedScopes($sKey);
                         $oSocial->TranslatedScopes = $oPlugin->GetTranslatedScopes($oSocial->SupportedScopes);
                         $oSocial->HasApiKey = $oPlugin->HasApiKey($sKey);
                         $aConnectors[$sKey] = $oSocial;
                     }
                 }
             }
             $oScreen->Data->SetValue('Socials', $aConnectors);
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Validates a username and password
  *
  * This method should return true or false depending on if login
  * succeeded.
  *
  * @return bool
  */
 protected function validateUserPass($sUserName, $sPassword)
 {
     if (class_exists('CApi') && \CApi::IsValid()) {
         /* @var $oApiCalendarManager \CApiCalendarManager */
         $oApiCalendarManager = \CApi::Manager('calendar');
         /* @var $oApiCapabilityManager \CApiCapabilityManager */
         $oApiCapabilityManager = \CApi::Manager('capability');
         if ($oApiCalendarManager && $oApiCapabilityManager) {
             $oAccount = \afterlogic\DAV\Utils::GetAccountByLogin($sUserName);
             if ($oAccount && $oAccount->IsDisabled) {
                 return false;
             }
             $bIsOutlookSyncClient = \afterlogic\DAV\Utils::ValidateClient('outlooksync');
             $bIsMobileSync = false;
             $bIsOutlookSync = false;
             $bIsDemo = false;
             if ($oAccount) {
                 $bIsMobileSync = $oApiCapabilityManager->IsMobileSyncSupported($oAccount);
                 $bIsOutlookSync = $oApiCapabilityManager->IsOutlookSyncSupported($oAccount);
                 \CApi::Plugin()->RunHook('plugin-is-demo-account', array(&$oAccount, &$bIsDemo));
             }
             if ($oAccount && $oAccount->IncomingMailPassword === $sPassword && ($bIsMobileSync && !$bIsOutlookSyncClient || $bIsOutlookSync && $bIsOutlookSyncClient) || $bIsDemo || $sUserName === $oApiCalendarManager->GetPublicUser()) {
                 \afterlogic\DAV\Utils::CheckPrincipals($sUserName);
                 return true;
             }
         }
     }
     return false;
 }
Ejemplo n.º 5
0
 public function __construct()
 {
     parent::__construct(get_class($this), 'IdGroup');
     $this->__USE_TRIM_IN_STRINGS__ = true;
     $this->SetDefaults(array('IdGroup' => '', 'IdGroupStr' => '', 'IdUser' => 0, 'Name' => '', 'IsOrganization' => false, 'Email' => '', 'Company' => '', 'Street' => '', 'City' => '', 'State' => '', 'Zip' => '', 'Country' => '', 'Phone' => '', 'Fax' => '', 'Web' => '', 'Events' => array()));
     CApi::Plugin()->RunHook('api-group-construct', array(&$this));
 }
Ejemplo n.º 6
0
 public function __construct()
 {
     parent::__construct(get_class($this), 'IdContact');
     $this->__USE_TRIM_IN_STRINGS__ = true;
     $this->SetDefaults(array('IdContact' => '', 'IdContactStr' => '', 'IdUser' => 0, 'IdDomain' => 0, 'IdTenant' => 0, 'GroupsIds' => array(), 'Type' => EContactType::Personal, 'IdTypeLink' => '', 'FullName' => '', 'UseFriendlyName' => true, 'ViewEmail' => '', 'PrimaryEmail' => CApi::GetConf('contacts.default-primary-email', EPrimaryEmailType::Home), 'DateCreated' => time(), 'DateModified' => time(), 'Title' => '', 'FirstName' => '', 'LastName' => '', 'NickName' => '', 'Skype' => '', 'Facebook' => '', 'HomeEmail' => '', 'HomeStreet' => '', 'HomeCity' => '', 'HomeState' => '', 'HomeZip' => '', 'HomeCountry' => '', 'HomePhone' => '', 'HomeFax' => '', 'HomeMobile' => '', 'HomeWeb' => '', 'BusinessEmail' => '', 'BusinessCompany' => '', 'BusinessStreet' => '', 'BusinessCity' => '', 'BusinessState' => '', 'BusinessZip' => '', 'BusinessCountry' => '', 'BusinessJobTitle' => '', 'BusinessDepartment' => '', 'BusinessOffice' => '', 'BusinessPhone' => '', 'BusinessMobile' => '', 'BusinessFax' => '', 'BusinessWeb' => '', 'OtherEmail' => '', 'Notes' => '', 'BirthdayDay' => 0, 'BirthdayMonth' => 0, 'BirthdayYear' => 0, 'ReadOnly' => false, 'Global' => false, 'ItsMe' => false, 'ETag' => '', 'SharedToAll' => false, 'HideInGAB' => false));
     $this->__LOCK_DATE_MODIFIED__ = false;
     $this->__SKIP_VALIDATE__ = false;
     CApi::Plugin()->RunHook('api-contact-construct', array(&$this));
 }
Ejemplo n.º 7
0
 /**
  * @param CDomain $oDomain
  * @return void
  */
 public function __construct($oDomain)
 {
     parent::__construct(get_class($this), 'IdAccount');
     $this->Domain = $oDomain;
     $this->User = new CUser($oDomain);
     $this->aExtension = array();
     $this->SetTrimer(array('Email', 'FriendlyName', 'IncomingMailServer', 'IncomingMailLogin', 'IncomingMailPassword', 'PreviousMailPassword', 'OutgoingMailServer', 'OutgoingMailLogin'));
     $this->SetLower(array('IncomingMailServer', 'OutgoingMailServer'));
     $this->SetDefaults(array('IdAccount' => 0, 'IdUser' => 0, 'IdDomain' => $oDomain->IdDomain, 'IdTenant' => $oDomain->IdTenant, 'IsDefaultAccount' => true, 'IsInternal' => $oDomain->IsInternal, 'IsDisabled' => false, 'IsMailingList' => false, 'StorageQuota' => $oDomain->UserQuota, 'StorageUsedSpace' => 0, 'Email' => '', 'FriendlyName' => '', 'IncomingMailProtocol' => $oDomain->IncomingMailProtocol, 'IncomingMailServer' => $oDomain->IncomingMailServer, 'IncomingMailPort' => $oDomain->IncomingMailPort, 'IncomingMailLogin' => '', 'IncomingMailPassword' => '', 'IncomingMailUseSSL' => $oDomain->IncomingMailUseSSL, 'PreviousMailPassword' => '', 'OutgoingMailServer' => $oDomain->OutgoingMailServer, 'OutgoingMailPort' => $oDomain->OutgoingMailPort, 'OutgoingMailLogin' => '', 'OutgoingMailPassword' => '', 'OutgoingMailAuth' => $oDomain->OutgoingMailAuth, 'OutgoingMailUseSSL' => $oDomain->OutgoingMailUseSSL, 'OutgoingSendingMethod' => $oDomain->OutgoingSendingMethod, 'HideInGAB' => false, 'Signature' => '', 'SignatureType' => EAccountSignatureType::Html, 'SignatureOptions' => EAccountSignatureOptions::DontAdd, 'GlobalAddressBook' => $oDomain->GlobalAddressBook, 'AllowCompose' => true, 'AllowReply' => true, 'AllowForward' => true, 'DetectSpecialFoldersWithXList' => $oDomain->DetectSpecialFoldersWithXList, 'CustomFields' => '', 'ForceSaveOnLogin' => false));
     CApi::Plugin()->RunHook('api-account-construct', array(&$this));
 }
Ejemplo n.º 8
0
 /**
  * @return void
  */
 public function __construct(CDomain $oDomain)
 {
     parent::__construct(get_class($this), 'IdUser');
     $oSettings =& CApi::GetSettings();
     $iSaveMail = $oSettings->GetConf('WebMail/SaveMail');
     $iSaveMail = ESaveMail::Always !== $iSaveMail ? $oSettings->GetConf('WebMail/SaveMail') : ESaveMail::DefaultOn;
     $this->oSubCache = null;
     $this->__USE_TRIM_IN_STRINGS__ = true;
     $this->SetUpper(array('Capa'));
     $this->SetDefaults(array('IdUser' => 0, 'IdSubscription' => 0, 'IdHelpdeskUser' => 0, 'MailsPerPage' => $oDomain->MailsPerPage, 'ContactsPerPage' => $oDomain->ContactsPerPage, 'AutoCheckMailInterval' => $oDomain->AutoCheckMailInterval, 'CreatedTime' => 0, 'LastLogin' => 0, 'LastLoginNow' => 0, 'LoginsCount' => 0, 'DefaultSkin' => $oDomain->DefaultSkin, 'DefaultLanguage' => $oDomain->DefaultLanguage, 'DefaultEditor' => EUserHtmlEditor::Html, 'SaveMail' => $iSaveMail, 'Layout' => $oDomain->Layout, 'DefaultTimeZone' => 0, 'DefaultTimeFormat' => $oDomain->DefaultTimeFormat, 'DefaultDateFormat' => $oDomain->DefaultDateFormat, 'DefaultIncomingCharset' => CApi::GetConf('webmail.default-inc-charset', 'iso-8859-1'), 'Question1' => '', 'Question2' => '', 'Answer1' => '', 'Answer2' => '', 'TwilioNumber' => '', 'TwilioEnable' => true, 'TwilioDefaultNumber' => false, 'SipEnable' => true, 'SipImpi' => '', 'SipPassword' => '', 'Capa' => '', 'ClientTimeZone' => '', 'UseThreads' => $oDomain->UseThreads, 'SaveRepliedMessagesToCurrentFolder' => false, 'DesktopNotifications' => false, 'AllowChangeInputDirection' => false, 'EnableOpenPgp' => false, 'AllowAutosaveInDrafts' => true, 'AutosignOutgoingEmails' => false, 'AllowHelpdeskNotifications' => false, 'CustomFields' => '', 'FilesEnable' => true));
     CApi::Plugin()->RunHook('api-user-construct', array(&$this));
 }
Ejemplo n.º 9
0
 /**
  * @staticvar array $aTablesCache
  *
  * @return array
  */
 public static function getSqlTables()
 {
     static $aTablesCache = null;
     if (null !== $aTablesCache) {
         return $aTablesCache;
     }
     $aTables = array();
     CDbSchemaHelper::addTablesToArray($aTables, array('a_users', 'awm_accounts', 'awm_settings', 'awm_domains', 'awm_folders', 'awm_folders_tree', 'awm_filters', 'awm_messages', 'awm_messages_body', 'awm_reads', 'awm_columns', 'awm_senders', 'awm_mailaliases', 'awm_mailforwards', 'awm_mailinglists', 'awm_addr_book', 'awm_addr_groups', 'awm_addr_groups_contacts', 'awm_addr_groups_events', 'awm_identities', 'awm_tenants', 'awm_fetchers', 'awm_system_folders', 'awm_channels', 'awm_folders_order', 'awm_min', 'awm_subscriptions', 'awm_folders_order_names', 'awm_social', 'awm_tenant_socials', 'awm_account_quotas', 'awm_domain_quotas', 'awm_tenant_quotas', 'acal_calendars', 'acal_events', 'acal_users_data', 'acal_publications', 'acal_reminders', 'acal_appointments', 'acal_eventrepeats', 'acal_exclusions', 'acal_sharing', 'acal_cron_runs', 'acal_awm_fnbl_runs', 'ahd_users', 'ahd_threads', 'ahd_posts', 'ahd_reads', 'ahd_attachments', 'ahd_online', 'ahd_fetcher', 'adav_addressbooks', 'adav_calendars', 'adav_cache', 'adav_calendarobjects', 'adav_cards', 'adav_locks', 'adav_groupmembers', 'adav_principals', 'adav_reminders', 'adav_calendarshares', 'twofa_accounts'));
     CApi::Plugin()->RunHook('api-db-tables', array(&$aTables));
     $aTablesCache = $aTables;
     return $aTablesCache;
 }
Ejemplo n.º 10
0
 /**
  * @param int $iUserId
  * @return void
  */
 public function __construct($iUserId)
 {
     parent::__construct(get_class($this), 'IdCalUser');
     $iUserId = (int) $iUserId;
     $oDomain = null;
     $oSettings =& CApi::GetSettings();
     if (0 < $iUserId) {
         /* @var $oApiUsersManager CApiUsersManager */
         $oApiUsersManager = CApi::Manager('users');
         $iDomainId = $oApiUsersManager->GetDefaultAccountDomainId($iUserId);
         if (0 < $iDomainId) {
             /* @var $oApiDomainsManager CApiDomainsManager */
             $oApiDomainsManager = CApi::Manager('domains');
             $oDomain = $oApiDomainsManager->GetDomainById($iDomainId);
         }
     }
     $this->SetDefaults(array('IdCalUser' => 0, 'IdUser' => (int) $iUserId, 'ShowWeekEnds' => (bool) ($oDomain ? $oDomain->CalendarShowWeekEnds : $oSettings->GetConf('Calendar/ShowWeekEnds')), 'ShowWorkDay' => (bool) ($oDomain ? $oDomain->CalendarShowWorkDay : $oSettings->GetConf('Calendar/ShowWorkDay')), 'WorkDayStarts' => (int) ($oDomain ? $oDomain->CalendarWorkdayStarts : $oSettings->GetConf('Calendar/WorkdayStarts')), 'WorkDayEnds' => (int) ($oDomain ? $oDomain->CalendarWorkdayEnds : $oSettings->GetConf('Calendar/WorkdayEnds')), 'WeekStartsOn' => (int) ($oDomain ? $oDomain->CalendarWeekStartsOn : $oSettings->GetConf('Calendar/WeekStartsOn')), 'DefaultTab' => (int) ($oDomain ? $oDomain->CalendarDefaultTab : $oSettings->GetConf('Calendar/DefaultTab'))));
     CApi::Plugin()->RunHook('api-caluser-construct', array(&$this));
 }
Ejemplo n.º 11
0
 /**
  * @return void
  */
 public function Handle()
 {
     $sVersion = file_get_contents(PSEVEN_APP_ROOT_PATH . 'VERSION');
     define('PSEVEN_APP_VERSION', $sVersion);
     if (!class_exists('MailSo\\Version')) {
         echo 'MailSo';
         return '';
     } else {
         if (!class_exists('\\CApi') || !\CApi::IsValid()) {
             echo 'AfterLogic API';
             return '';
         }
     }
     $sPathInfo = \trim(\trim($this->oHttp->GetServer('PATH_INFO', '')), ' /');
     if (!empty($sPathInfo)) {
         if ('dav' === \substr($sPathInfo, 0, 3)) {
             $this->oActions->PathInfoDav();
             return '';
         }
     }
     /* @var $oApiIntegrator \CApiIntegratorManager */
     $oApiIntegrator = \CApi::Manager('integrator');
     // ------ Redirect to HTTPS
     $oSettings =& \CApi::GetSettings();
     $bRedirectToHttps = $oSettings->GetConf('Common/RedirectToHttps');
     $bHttps = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== "off" || isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == "443";
     if ($bRedirectToHttps && !$bHttps) {
         header("Location: https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
     }
     // ------
     /* @var $oApiCapability \CApiCapabilityManager */
     $oApiCapability = \CApi::Manager('capability');
     $sResult = '';
     $sQuery = \trim(\trim($this->oHttp->GetServer('QUERY_STRING', '')), ' /');
     \CApi::Plugin()->RunQueryHandle($sQuery);
     $iPos = \strpos($sQuery, '&');
     if (0 < $iPos) {
         $sQuery = \substr($sQuery, 0, $iPos);
     }
     $aPaths = explode('/', $sQuery);
     if (0 < count($aPaths) && !empty($aPaths[0])) {
         $sFirstPart = strtolower($aPaths[0]);
         if ('ping' === $sFirstPart) {
             @header('Content-Type: text/plain; charset=utf-8');
             $sResult = 'Pong';
         } else {
             if ('pull' === $sFirstPart) {
                 if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
                     pclose(popen("start /B git pull", "r"));
                 } else {
                     exec("git pull > /dev/null 2>&1 &");
                 }
                 \CApi::Location('./');
             } else {
                 if ('ajax' === $sFirstPart) {
                     @ob_start();
                     $aResponseItem = null;
                     $sAction = $this->oHttp->GetPost('Action', null);
                     try {
                         \CApi::Log('AJAX: Action: ' . $sAction);
                         if ('SystemGetAppData' !== $sAction && \CApi::GetConf('labs.webmail.csrftoken-protection', true) && !$this->validateToken()) {
                             throw new \ProjectCore\Exceptions\ClientException(\ProjectCore\Notifications::InvalidToken);
                         } else {
                             if (!empty($sAction)) {
                                 $sMethodName = 'Ajax' . $sAction;
                                 $this->oActions->SetActionParams($this->oHttp->GetPostAsArray());
                                 if (method_exists($this->oActions, $sMethodName) && is_callable(array($this->oActions, $sMethodName))) {
                                     $aResponseItem = call_user_func(array($this->oActions, $sMethodName));
                                 }
                                 if (\CApi::Plugin()->JsonHookExists($sMethodName)) {
                                     $aResponseItem = \CApi::Plugin()->RunJsonHook($this->oActions, $sMethodName, $aResponseItem);
                                 }
                             }
                         }
                         if (!is_array($aResponseItem)) {
                             throw new \ProjectCore\Exceptions\ClientException(\ProjectCore\Notifications::UnknownError);
                         }
                     } catch (\Exception $oException) {
                         //if ($oException instanceof \ProjectCore\Exceptions\ClientException &&
                         //	\ProjectCore\Notifications::AuthError === $oException->getCode())
                         //{
                         //	$oApiIntegrator = /* @var $oApiIntegrator \CApiIntegratorManager */ \CApi::Manager('integrator');
                         //	$oApiIntegrator->setLastErrorCode(\ProjectCore\Notifications::AuthError);
                         //	$oApiIntegrator->logoutAccount();
                         //}
                         \CApi::LogException($oException);
                         $sAction = empty($sAction) ? 'Unknown' : $sAction;
                         $aAdditionalParams = null;
                         if ($oException instanceof \ProjectCore\Exceptions\ClientException) {
                             $aAdditionalParams = $oException->GetObjectParams();
                         }
                         $aResponseItem = $this->oActions->ExceptionResponse(null, $sAction, $oException, $aAdditionalParams);
                     }
                     @header('Content-Type: application/json; charset=utf-8');
                     \CApi::Plugin()->RunHook('ajax.response-result', array($sAction, &$aResponseItem));
                     $sResult = \MailSo\Base\Utils::Php2js($aResponseItem, \CApi::MailSoLogger());
                     //				\CApi::Log('AJAX: Response: '.$sResult);
                 } else {
                     if ('upload' === $sFirstPart) {
                         @ob_start();
                         $aResponseItem = null;
                         $sAction = empty($aPaths[1]) ? '' : $aPaths[1];
                         if ($this->oHttp->IsPut()) {
                             $rPutData = fopen("php://input", "r");
                             $aFilePath = array_slice($aPaths, 3);
                             $sFilePath = implode('/', $aFilePath);
                             $this->oActions->SetActionParams(array('FileData' => array('name' => basename($sFilePath), 'size' => (int) $this->oHttp->GetHeader('Content-Length'), 'tmp_name' => $rPutData), 'AdditionalData' => json_encode(array('Type' => empty($aPaths[2]) ? 'personal' : strtolower($aPaths[2]), 'CalendarID' => empty($aPaths[2]) ? '' : strtolower($aPaths[2]), 'Folder' => dirname($sFilePath), 'Path' => dirname($sFilePath), 'GroupId' => '', 'IsShared' => false)), 'IsExt' => '1' === (string) $this->oHttp->GetQuery('IsExt', '0') ? '1' : '0', 'TenantHash' => (string) $this->oHttp->GetQuery('TenantHash', ''), 'AuthToken' => $this->oHttp->GetHeader('Auth-Token'), 'AccountID' => empty($aPaths[2]) ? '0' : strtolower($aPaths[2])));
                             try {
                                 $sMethodName = 'Upload' . $sAction;
                                 if (method_exists($this->oActions, $sMethodName) && is_callable(array($this->oActions, $sMethodName))) {
                                     $aResponseItem = call_user_func(array($this->oActions, $sMethodName));
                                 }
                                 if (!is_array($aResponseItem) && empty($sError)) {
                                     throw new \ProjectCore\Exceptions\ClientException(\ProjectCore\Notifications::UnknownError);
                                 }
                             } catch (\Exception $oException) {
                                 \CApi::LogException($oException);
                                 $aResponseItem = $this->oActions->ExceptionResponse(null, 'Upload', $oException);
                                 $sError = 'exception';
                             }
                             if (0 < strlen($sError)) {
                                 $aResponseItem['Error'] = $sError;
                             }
                         } else {
                             try {
                                 $sMethodName = 'Upload' . $sAction;
                                 if (method_exists($this->oActions, $sMethodName) && is_callable(array($this->oActions, $sMethodName))) {
                                     $sError = '';
                                     $sInputName = 'jua-uploader';
                                     $iError = UPLOAD_ERR_OK;
                                     $_FILES = isset($_FILES) ? $_FILES : null;
                                     if (isset($_FILES, $_FILES[$sInputName], $_FILES[$sInputName]['name'], $_FILES[$sInputName]['tmp_name'], $_FILES[$sInputName]['size'], $_FILES[$sInputName]['type'])) {
                                         $iError = isset($_FILES[$sInputName]['error']) ? (int) $_FILES[$sInputName]['error'] : UPLOAD_ERR_OK;
                                         if (UPLOAD_ERR_OK === $iError) {
                                             $this->oActions->SetActionParams(array('AccountID' => $this->oHttp->GetPost('AccountID', ''), 'FileData' => $_FILES[$sInputName], 'AdditionalData' => $this->oHttp->GetPost('AdditionalData', null), 'IsExt' => '1' === (string) $this->oHttp->GetPost('IsExt', '0') ? '1' : '0', 'TenantHash' => (string) $this->oHttp->GetPost('TenantHash', ''), 'Token' => $this->oHttp->GetPost('Token', ''), 'AuthToken' => $this->oHttp->GetPost('AuthToken', '')));
                                             \CApi::LogObject($this->oActions->GetActionParams());
                                             $aResponseItem = call_user_func(array($this->oActions, $sMethodName));
                                         } else {
                                             $sError = $this->oActions->convertUploadErrorToString($iError);
                                         }
                                     } else {
                                         if (!isset($_FILES) || !is_array($_FILES) || 0 === count($_FILES)) {
                                             $sError = 'size';
                                         } else {
                                             $sError = 'unknown';
                                         }
                                     }
                                 }
                                 if (!is_array($aResponseItem) && empty($sError)) {
                                     throw new \ProjectCore\Exceptions\ClientException(\ProjectCore\Notifications::UnknownError);
                                 }
                             } catch (\Exception $oException) {
                                 \CApi::LogException($oException);
                                 $aResponseItem = $this->oActions->ExceptionResponse(null, 'Upload', $oException);
                                 $sError = 'exception';
                             }
                             if (0 < strlen($sError)) {
                                 $aResponseItem['Error'] = $sError;
                             }
                         }
                         @ob_get_clean();
                         @header('Content-Type: text/html; charset=utf-8');
                         $sResult = \MailSo\Base\Utils::Php2js($aResponseItem);
                     } else {
                         if ('speclogon' === $sFirstPart || 'speclogoff' === $sFirstPart) {
                             \CApi::SpecifiedUserLogging('speclogon' === $sFirstPart);
                             \CApi::Location('./');
                         } else {
                             if ('sso' === $sFirstPart) {
                                 $oApiIntegratorManager = \CApi::Manager('integrator');
                                 try {
                                     $sHash = $this->oHttp->GetRequest('hash');
                                     if (!empty($sHash)) {
                                         $sData = \CApi::Cacher()->get('SSO:' . $sHash, true);
                                         $aData = \CApi::DecodeKeyValues($sData);
                                         if (!empty($aData['Email']) && isset($aData['Password'], $aData['Login'])) {
                                             $oAccount = $oApiIntegratorManager->loginToAccount($aData['Email'], $aData['Password'], $aData['Login']);
                                             if ($oAccount) {
                                                 $oApiIntegratorManager->setAccountAsLoggedIn($oAccount);
                                             }
                                         }
                                     } else {
                                         $oApiIntegratorManager->logoutAccount();
                                     }
                                 } catch (\Exception $oExc) {
                                     \CApi::LogException($oExc);
                                 }
                                 \CApi::Location('./');
                             } else {
                                 if ('autodiscover' === $sFirstPart) {
                                     $oSettings =& \CApi::GetSettings();
                                     $sInput = \file_get_contents('php://input');
                                     \CApi::Log('#autodiscover:');
                                     \CApi::LogObject($sInput);
                                     $aMatches = array();
                                     $aEmailAddress = array();
                                     \preg_match("/\\<AcceptableResponseSchema\\>(.*?)\\<\\/AcceptableResponseSchema\\>/i", $sInput, $aMatches);
                                     \preg_match("/\\<EMailAddress\\>(.*?)\\<\\/EMailAddress\\>/", $sInput, $aEmailAddress);
                                     if (!empty($aMatches[1]) && !empty($aEmailAddress[1])) {
                                         $sIncMailServer = trim($oSettings->GetConf('WebMail/ExternalHostNameOfLocalImap'));
                                         $sOutMailServer = trim($oSettings->GetConf('WebMail/ExternalHostNameOfLocalSmtp'));
                                         if (0 < \strlen($sIncMailServer) && 0 < \strlen($sOutMailServer)) {
                                             $iIncMailPort = 143;
                                             $iOutMailPort = 25;
                                             $aMatch = array();
                                             if (\preg_match('/:([\\d]+)$/', $sIncMailServer, $aMatch) && !empty($aMatch[1]) && is_numeric($aMatch[1])) {
                                                 $sIncMailServer = preg_replace('/:[\\d]+$/', $sIncMailServer, '');
                                                 $iIncMailPort = (int) $aMatch[1];
                                             }
                                             $aMatch = array();
                                             if (\preg_match('/:([\\d]+)$/', $sOutMailServer, $aMatch) && !empty($aMatch[1]) && is_numeric($aMatch[1])) {
                                                 $sOutMailServer = preg_replace('/:[\\d]+$/', $sOutMailServer, '');
                                                 $iOutMailPort = (int) $aMatch[1];
                                             }
                                             $sResult = \implode("\n", array('<Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006">', '	<Response xmlns="' . $aMatches[1] . '">', '		<Account>', '			<AccountType>email</AccountType>', '			<Action>settings</Action>', '			<Protocol>', '				<Type>IMAP</Type>', '				<Server>' . $sIncMailServer . '</Server>', '				<LoginName>' . $aEmailAddress[1] . '</LoginName>', '				<Port>' . $iIncMailPort . '</Port>', '				<SSL>' . (993 === $iIncMailPort ? 'on' : 'off') . '</SSL>', '				<SPA>off</SPA>', '				<AuthRequired>on</AuthRequired>', '			</Protocol>', '			<Protocol>', '				<Type>SMTP</Type>', '				<Server>' . $sOutMailServer . '</Server>', '				<LoginName>' . $aEmailAddress[1] . '</LoginName>', '				<Port>' . $iOutMailPort . '</Port>', '				<SSL>' . (465 === $iOutMailPort ? 'on' : 'off') . '</SSL>', '				<SPA>off</SPA>', '				<AuthRequired>on</AuthRequired>', '			</Protocol>', '		</Account>', '	</Response>', '</Autodiscover>'));
                                         }
                                     }
                                     if (empty($sResult)) {
                                         $usec = $sec = 0;
                                         list($usec, $sec) = \explode(' ', microtime());
                                         $sResult = \implode("\n", array('<Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006">', empty($aMatches[1]) ? '	<Response>' : '	<Response xmlns="' . $aMatches[1] . '">', '		<Error Time="' . \gmdate('H:i:s', $sec) . \substr($usec, 0, \strlen($usec) - 2) . '" Id="2477272013">', '			<ErrorCode>600</ErrorCode>', '			<Message>Invalid Request</Message>', '			<DebugData />', '		</Error>', '	</Response>', '</Autodiscover>'));
                                     }
                                     header('Content-Type: text/xml');
                                     $sResult = '<' . '?xml version="1.0" encoding="utf-8"?' . '>' . "\n" . $sResult;
                                     \CApi::Log('');
                                     \CApi::Log($sResult);
                                 } else {
                                     if ('profile' === $sFirstPart) {
                                         /* @var $oApiIosManager \CApiIosManager */
                                         $oApiIosManager = \CApi::Manager('ios');
                                         $oAccount = $oApiIntegrator->getLogginedDefaultAccount();
                                         $mResultProfile = $oApiIosManager && $oAccount ? $oApiIosManager->generateXMLProfile($oAccount) : false;
                                         if ($mResultProfile !== false) {
                                             header('Content-type: application/x-apple-aspen-config; chatset=utf-8');
                                             header('Content-Disposition: attachment; filename="afterlogic.mobileconfig"');
                                             echo $mResultProfile;
                                         } else {
                                             \CApi::Location('./?IOS/Error');
                                         }
                                     } else {
                                         if ('ios' === $sFirstPart) {
                                             $sResult = file_get_contents(PSEVEN_APP_ROOT_PATH . 'templates/Ios.html');
                                             $iUserId = $oApiIntegrator->getLogginedUserId();
                                             if (0 < $iUserId) {
                                                 $oAccount = $oApiIntegrator->getLogginedDefaultAccount();
                                                 $bError = isset($aPaths[1]) && 'error' === strtolower($aPaths[1]);
                                                 // TODO
                                                 @setcookie('skip_ios', '1', time() + 3600 * 3600, '/', null, null, true);
                                                 $sResult = strtr($sResult, array('{{IOS/HELLO}}' => \CApi::ClientI18N('IOS/HELLO', $oAccount), '{{IOS/DESC_P1}}' => \CApi::ClientI18N('IOS/DESC_P1', $oAccount), '{{IOS/DESC_P2}}' => \CApi::ClientI18N('IOS/DESC_P2', $oAccount), '{{IOS/DESC_P3}}' => \CApi::ClientI18N('IOS/DESC_P3', $oAccount), '{{IOS/DESC_P4}}' => \CApi::ClientI18N('IOS/DESC_P4', $oAccount), '{{IOS/DESC_P5}}' => \CApi::ClientI18N('IOS/DESC_P5', $oAccount), '{{IOS/DESC_P6}}' => \CApi::ClientI18N('IOS/DESC_P6', $oAccount), '{{IOS/DESC_P7}}' => \CApi::ClientI18N('IOS/DESC_P7', $oAccount), '{{IOS/DESC_BUTTON_YES}}' => \CApi::ClientI18N('IOS/DESC_BUTTON_YES', $oAccount), '{{IOS/DESC_BUTTON_SKIP}}' => \CApi::ClientI18N('IOS/DESC_BUTTON_SKIP', $oAccount), '{{IOS/DESC_BUTTON_OPEN}}' => \CApi::ClientI18N('IOS/DESC_BUTTON_OPEN', $oAccount), '{{AppVersion}}' => PSEVEN_APP_VERSION, '{{IntegratorLinks}}' => $oApiIntegrator->buildHeadersLink()));
                                             } else {
                                                 \CApi::Location('./');
                                             }
                                         } else {
                                             if ('raw' === $sFirstPart) {
                                                 $sAction = empty($aPaths[1]) ? '' : $aPaths[1];
                                                 try {
                                                     if (!empty($sAction)) {
                                                         $sMethodName = 'Raw' . $sAction;
                                                         if (method_exists($this->oActions, $sMethodName)) {
                                                             $this->oActions->SetActionParams(array('AccountID' => empty($aPaths[2]) || '0' === (string) $aPaths[2] ? '' : $aPaths[2], 'RawKey' => empty($aPaths[3]) ? '' : $aPaths[3], 'IsExt' => empty($aPaths[4]) ? '0' : ('1' === (string) $aPaths[4] ? '1' : 0), 'TenantHash' => empty($aPaths[5]) ? '' : $aPaths[5], 'AuthToken' => empty($aPaths[6]) ? '' : $aPaths[6]));
                                                             if (!call_user_func(array($this->oActions, $sMethodName))) {
                                                                 \CApi::Log('False result.', \ELogLevel::Error);
                                                             }
                                                         } else {
                                                             \CApi::Log('Invalid action.', \ELogLevel::Error);
                                                         }
                                                     } else {
                                                         \CApi::Log('Empty action.', \ELogLevel::Error);
                                                     }
                                                 } catch (\Exception $oException) {
                                                     \CApi::LogException($oException, \ELogLevel::Error);
                                                     $this->oHttp->StatusHeader(404);
                                                 }
                                             } else {
                                                 if ('post' === $sFirstPart) {
                                                     $sAction = $this->oHttp->GetPost('Action');
                                                     try {
                                                         if (!empty($sAction)) {
                                                             $sMethodName = 'Post' . $sAction;
                                                             if (method_exists($this->oActions, $sMethodName) && is_callable(array($this->oActions, $sMethodName))) {
                                                                 $this->oActions->SetActionParams($this->oHttp->GetPostAsArray());
                                                                 if (!call_user_func(array($this->oActions, $sMethodName))) {
                                                                     \CApi::Log('False result.', \ELogLevel::Error);
                                                                 }
                                                             } else {
                                                                 \CApi::Log('Invalid action.', \ELogLevel::Error);
                                                             }
                                                         } else {
                                                             \CApi::Log('Empty action.', \ELogLevel::Error);
                                                         }
                                                     } catch (\Exception $oException) {
                                                         \CApi::LogException($oException, \ELogLevel::Error);
                                                     }
                                                 } else {
                                                     if (\CApi::IsHelpdeskModule()) {
                                                         $sResult = $this->indexHTML(true, $this->oHttp->GetQuery('helpdesk'));
                                                     } else {
                                                         if ($this->oHttp->HasQuery('invite')) {
                                                             $aInviteValues = \CApi::DecodeKeyValues($this->oHttp->GetQuery('invite'));
                                                             $oApiUsersManager = \CApi::Manager('users');
                                                             $oApiCalendarManager = \CApi::Manager('calendar');
                                                             if (isset($aInviteValues['organizer'])) {
                                                                 $oAccountOrganizer = $oApiUsersManager->getAccountByEmail($aInviteValues['organizer']);
                                                                 if (isset($oAccountOrganizer, $aInviteValues['attendee'], $aInviteValues['calendarId'], $aInviteValues['eventId'], $aInviteValues['action'])) {
                                                                     $oCalendar = $oApiCalendarManager->getCalendar($oAccountOrganizer, $aInviteValues['calendarId']);
                                                                     if ($oCalendar) {
                                                                         $oEvent = $oApiCalendarManager->getEvent($oAccountOrganizer, $aInviteValues['calendarId'], $aInviteValues['eventId']);
                                                                         if ($oEvent && is_array($oEvent) && 0 < count($oEvent) && isset($oEvent[0])) {
                                                                             if (is_string($sResult)) {
                                                                                 $sResult = file_get_contents(PSEVEN_APP_ROOT_PATH . 'templates/CalendarEventInviteExternal.html');
                                                                                 $dt = new \DateTime();
                                                                                 $dt->setTimestamp($oEvent[0]['startTS']);
                                                                                 if (!$oEvent[0]['allDay']) {
                                                                                     $sDefaultTimeZone = new \DateTimeZone($oAccountOrganizer->getDefaultStrTimeZone());
                                                                                     $dt->setTimezone($sDefaultTimeZone);
                                                                                 }
                                                                                 $sAction = $aInviteValues['action'];
                                                                                 $sActionColor = 'green';
                                                                                 $sActionText = '';
                                                                                 switch (strtoupper($sAction)) {
                                                                                     case 'ACCEPTED':
                                                                                         $sActionColor = 'green';
                                                                                         $sActionText = 'Accepted';
                                                                                         break;
                                                                                     case 'DECLINED':
                                                                                         $sActionColor = 'red';
                                                                                         $sActionText = 'Declined';
                                                                                         break;
                                                                                     case 'TENTATIVE':
                                                                                         $sActionColor = '#A0A0A0';
                                                                                         $sActionText = 'Tentative';
                                                                                         break;
                                                                                 }
                                                                                 $sDateFormat = 'm/d/Y';
                                                                                 $sTimeFormat = 'h:i A';
                                                                                 switch ($oAccountOrganizer->User->DefaultDateFormat) {
                                                                                     case \EDateFormat::DDMMYYYY:
                                                                                         $sDateFormat = 'd/m/Y';
                                                                                         break;
                                                                                     case \EDateFormat::DD_MONTH_YYYY:
                                                                                         $sDateFormat = 'd/m/Y';
                                                                                         break;
                                                                                     default:
                                                                                         $sDateFormat = 'm/d/Y';
                                                                                         break;
                                                                                 }
                                                                                 switch ($oAccountOrganizer->User->DefaultTimeFormat) {
                                                                                     case \ETimeFormat::F24:
                                                                                         $sTimeFormat = 'H:i';
                                                                                         break;
                                                                                     case \EDateFormat::DD_MONTH_YYYY:
                                                                                         \ETimeFormat::F12;
                                                                                         $sTimeFormat = 'h:i A';
                                                                                         break;
                                                                                     default:
                                                                                         $sTimeFormat = 'h:i A';
                                                                                         break;
                                                                                 }
                                                                                 $sDateTime = $dt->format($sDateFormat . ' ' . $sTimeFormat);
                                                                                 $mResult = array('{{COLOR}}' => $oCalendar->Color, '{{EVENT_NAME}}' => $oEvent[0]['subject'], '{{EVENT_BEGIN}}' => ucfirst(\CApi::ClientI18N('REMINDERS/EVENT_BEGIN', $oAccountOrganizer)), '{{EVENT_DATE}}' => $sDateTime, '{{CALENDAR}}' => ucfirst(\CApi::ClientI18N('REMINDERS/CALENDAR', $oAccountOrganizer)), '{{CALENDAR_NAME}}' => $oCalendar->DisplayName, '{{EVENT_DESCRIPTION}}' => $oEvent[0]['description'], '{{EVENT_ACTION}}' => $sActionText, '{{ACTION_COLOR}}' => $sActionColor);
                                                                                 $sResult = strtr($sResult, $mResult);
                                                                             } else {
                                                                                 \CApi::Log('Empty template.', \ELogLevel::Error);
                                                                             }
                                                                         } else {
                                                                             \CApi::Log('Event not found.', \ELogLevel::Error);
                                                                         }
                                                                     } else {
                                                                         \CApi::Log('Calendar not found.', \ELogLevel::Error);
                                                                     }
                                                                     $sAttendee = $aInviteValues['attendee'];
                                                                     if (!empty($sAttendee)) {
                                                                         $oApiCalendarManager->updateAppointment($oAccountOrganizer, $aInviteValues['calendarId'], $aInviteValues['eventId'], $sAttendee, $aInviteValues['action']);
                                                                     }
                                                                 }
                                                             }
                                                         } else {
                                                             if (\CApi::IsCalendarPubModule()) {
                                                                 $sResult = $this->indexHTML(false, '', $this->oHttp->GetQuery('calendar-pub'));
                                                             } else {
                                                                 if (\CApi::IsFilesPubModule()) {
                                                                     $sResult = $this->indexHTML(false, '', '', $this->oHttp->GetQuery('files-pub'));
                                                                 } else {
                                                                     if ('min' === $sFirstPart || 'window' === $sFirstPart) {
                                                                         $sAction = empty($aPaths[1]) ? '' : $aPaths[1];
                                                                         try {
                                                                             if (!empty($sAction)) {
                                                                                 $sMethodName = $aPaths[0] . $sAction;
                                                                                 if (method_exists($this->oActions, $sMethodName)) {
                                                                                     if ('Min' === $aPaths[0]) {
                                                                                         $oMinManager = \CApi::Manager('min');
                                                                                         $mHashResult = $oMinManager->getMinByHash(empty($aPaths[2]) ? '' : $aPaths[2]);
                                                                                         $this->oActions->SetActionParams(array('Result' => $mHashResult, 'Hash' => empty($aPaths[2]) ? '' : $aPaths[2]));
                                                                                     } else {
                                                                                         $this->oActions->SetActionParams(array('AccountID' => empty($aPaths[2]) || '0' === (string) $aPaths[2] ? '' : $aPaths[2], 'RawKey' => empty($aPaths[3]) ? '' : $aPaths[3]));
                                                                                     }
                                                                                     $mResult = call_user_func(array($this->oActions, $sMethodName));
                                                                                     $sTemplate = isset($mResult['Template']) && !empty($mResult['Template']) && is_string($mResult['Template']) ? $mResult['Template'] : null;
                                                                                     if (!empty($sTemplate) && is_array($mResult) && file_exists(PSEVEN_APP_ROOT_PATH . $sTemplate)) {
                                                                                         $sResult = file_get_contents(PSEVEN_APP_ROOT_PATH . $sTemplate);
                                                                                         if (is_string($sResult)) {
                                                                                             $sResult = strtr($sResult, $mResult);
                                                                                         } else {
                                                                                             \CApi::Log('Empty template.', \ELogLevel::Error);
                                                                                         }
                                                                                     } else {
                                                                                         if (!empty($sTemplate)) {
                                                                                             \CApi::Log('Empty template.', \ELogLevel::Error);
                                                                                         } else {
                                                                                             if (true === $mResult) {
                                                                                                 $sResult = '';
                                                                                             } else {
                                                                                                 \CApi::Log('False result.', \ELogLevel::Error);
                                                                                             }
                                                                                         }
                                                                                     }
                                                                                 } else {
                                                                                     \CApi::Log('Invalid action.', \ELogLevel::Error);
                                                                                 }
                                                                             } else {
                                                                                 \CApi::Log('Empty action.', \ELogLevel::Error);
                                                                             }
                                                                         } catch (\Exception $oException) {
                                                                             \CApi::LogException($oException);
                                                                         }
                                                                     } else {
                                                                         if ('twilio' === $sFirstPart) {
                                                                             $sResult = $this->oTwilio->getTwiML($aPaths, $this->oHttp);
                                                                         } else {
                                                                             if ('plugins' === $sFirstPart) {
                                                                                 $sType = !empty($aPaths[1]) ? trim($aPaths[1]) : '';
                                                                                 if ('js' === $sType) {
                                                                                     @header('Content-Type: application/javascript; charset=utf-8');
                                                                                     $sResult = \CApi::Plugin()->CompileJs();
                                                                                 } else {
                                                                                     if ('images' === $sType) {
                                                                                         if (!empty($aPaths[2]) && !empty($aPaths[3])) {
                                                                                             $oPlugin = \CApi::Plugin()->GetPluginByName($aPaths[2]);
                                                                                             if ($oPlugin) {
                                                                                                 echo $oPlugin->GetImage($aPaths[3]);
                                                                                                 exit;
                                                                                             }
                                                                                         }
                                                                                     } else {
                                                                                         if ('fonts' === $sType) {
                                                                                             if (!empty($aPaths[2]) && !empty($aPaths[3])) {
                                                                                                 $oPlugin = \CApi::Plugin()->GetPluginByName($aPaths[2]);
                                                                                                 if ($oPlugin) {
                                                                                                     echo $oPlugin->GetFont($aPaths[3]);
                                                                                                     exit;
                                                                                                 }
                                                                                             }
                                                                                         }
                                                                                     }
                                                                                 }
                                                                             } else {
                                                                                 if ('postlogin' === $sFirstPart && \CApi::GetConf('labs.allow-post-login', false)) {
                                                                                     $oSettings =& \CApi::GetSettings();
                                                                                     $sEmail = trim((string) $this->oHttp->GetRequest('Email', ''));
                                                                                     $sLogin = (string) $this->oHttp->GetRequest('Login', '');
                                                                                     $sPassword = (string) $this->oHttp->GetRequest('Password', '');
                                                                                     $sAtDomain = trim($oSettings->GetConf('WebMail/LoginAtDomainValue'));
                                                                                     if (\ELoginFormType::Login === (int) $oSettings->GetConf('WebMail/LoginFormType') && 0 < strlen($sAtDomain)) {
                                                                                         $sEmail = \api_Utils::GetAccountNameFromEmail($sLogin) . '@' . $sAtDomain;
                                                                                         $sLogin = $sEmail;
                                                                                     }
                                                                                     if (0 !== strlen($sPassword) && 0 !== strlen($sEmail . $sLogin)) {
                                                                                         try {
                                                                                             $oAccount = $oApiIntegrator->loginToAccount($sEmail, $sPassword, $sLogin);
                                                                                         } catch (\Exception $oException) {
                                                                                             $iErrorCode = \ProjectCore\Notifications::UnknownError;
                                                                                             if ($oException instanceof \CApiManagerException) {
                                                                                                 switch ($oException->getCode()) {
                                                                                                     case \Errs::WebMailManager_AccountDisabled:
                                                                                                     case \Errs::WebMailManager_AccountWebmailDisabled:
                                                                                                         $iErrorCode = \ProjectCore\Notifications::AuthError;
                                                                                                         break;
                                                                                                     case \Errs::UserManager_AccountAuthenticationFailed:
                                                                                                     case \Errs::WebMailManager_AccountAuthentication:
                                                                                                     case \Errs::WebMailManager_NewUserRegistrationDisabled:
                                                                                                     case \Errs::WebMailManager_AccountCreateOnLogin:
                                                                                                     case \Errs::Mail_AccountAuthentication:
                                                                                                     case \Errs::Mail_AccountLoginFailed:
                                                                                                         $iErrorCode = \ProjectCore\Notifications::AuthError;
                                                                                                         break;
                                                                                                     case \Errs::UserManager_AccountConnectToMailServerFailed:
                                                                                                     case \Errs::WebMailManager_AccountConnectToMailServerFailed:
                                                                                                     case \Errs::Mail_AccountConnectToMailServerFailed:
                                                                                                         $iErrorCode = \ProjectCore\Notifications::MailServerError;
                                                                                                         break;
                                                                                                     case \Errs::UserManager_LicenseKeyInvalid:
                                                                                                     case \Errs::UserManager_AccountCreateUserLimitReached:
                                                                                                     case \Errs::UserManager_LicenseKeyIsOutdated:
                                                                                                     case \Errs::TenantsManager_AccountCreateUserLimitReached:
                                                                                                         $iErrorCode = \ProjectCore\Notifications::LicenseProblem;
                                                                                                         break;
                                                                                                     case \Errs::Db_ExceptionError:
                                                                                                         $iErrorCode = \ProjectCore\Notifications::DataBaseError;
                                                                                                         break;
                                                                                                 }
                                                                                             }
                                                                                             $sRedirectUrl = \CApi::GetConf('labs.post-login-error-redirect-url', './');
                                                                                             \CApi::Location($sRedirectUrl . '?error=' . $iErrorCode);
                                                                                             exit;
                                                                                         }
                                                                                         if ($oAccount instanceof \CAccount) {
                                                                                             $oApiIntegrator->setAccountAsLoggedIn($oAccount);
                                                                                         }
                                                                                     }
                                                                                     \CApi::Location('./');
                                                                                 } else {
                                                                                     if ('mobile' === $sFirstPart) {
                                                                                         if ($oApiIntegrator && $oApiCapability && $oApiCapability->isNotLite()) {
                                                                                             $oApiIntegrator->setMobile(true);
                                                                                         }
                                                                                         \CApi::Location('./');
                                                                                     } else {
                                                                                         @ob_start();
                                                                                         \CApi::Plugin()->RunServiceHandle($sFirstPart, $aPaths);
                                                                                         $sResult = @ob_get_clean();
                                                                                         if (0 === strlen($sResult)) {
                                                                                             $sResult = $this->getIndexHTML();
                                                                                         }
                                                                                     }
                                                                                 }
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     } else {
         $sResult = $this->getIndexHTML();
     }
     // Output result
     echo $sResult;
 }
Ejemplo n.º 12
0
 /**
  * @return array
  */
 public function getDefaultSocials()
 {
     $aResult = array();
     $oSettings =& CApi::GetSettings();
     $aSocials = $oSettings->GetConf('Socials');
     if (isset($aSocials) && is_array($aSocials)) {
         $oPlugin = \CApi::Plugin()->GetPluginByName('external-services');
         if ($oPlugin) {
             $aConnectors = $oPlugin->GetEnabledConnectors();
             foreach ($aSocials as $sKey => $aSocial) {
                 if (in_array(strtolower($sKey), $aConnectors)) {
                     $oTenantSocial = CTenantSocials::initFromSettings($aSocial);
                     if ($oTenantSocial !== null) {
                         $aResult[strtolower($sKey)] = $oTenantSocial;
                     }
                 }
             }
         }
     }
     return $aResult;
 }
Ejemplo n.º 13
0
 public function PrepareStorageMap()
 {
     CApi::Plugin()->RunHook('api-prepare-storage-map', array(&$this->aStorageMap));
 }
Ejemplo n.º 14
0
 public static function Process($mResult)
 {
     $sExternalServicesRedirect = '';
     $sError = '';
     $sErrorMessage = '';
     if (isset($_COOKIE["external-services-redirect"])) {
         $sExternalServicesRedirect = $_COOKIE["external-services-redirect"];
         @setcookie('external-services-redirect', null);
     }
     if ($sExternalServicesRedirect === 'helpdesk') {
         self::SetValuesToCookie($mResult);
         $sTenantHash = self::GetTenantHashFromCookie();
         \CApi::Location($sTenantHash ? './?helpdesk=' . $sTenantHash : './?helpdesk');
     } else {
         $oApiUsers = \CApi::Manager('users');
         $oInviteAccount = null;
         if (isset($_COOKIE["external-services-invite-hash"])) {
             $oInviteAccount = $oApiUsers->getAccountById($_COOKIE["external-services-invite-hash"], true);
             @setcookie('external-services-invite-hash', null);
         }
         $sEmail = trim($mResult['email']);
         if (empty($sEmail) && $oInviteAccount) {
             $mResult['email'] = $oInviteAccount->Email;
         }
         $oApiSocial = \CApi::Manager('social');
         $oSocial = new \CSocial();
         $oSocial->TypeStr = $mResult['type'];
         $oSocial->AccessToken = isset($mResult['access_token']) ? $mResult['access_token'] : '';
         $oSocial->RefreshToken = isset($mResult['refresh_token']) ? $mResult['refresh_token'] : '';
         $oSocial->IdSocial = $mResult['id'];
         $oSocial->Name = $mResult['name'];
         $oSocial->Email = $mResult['email'];
         if ($sExternalServicesRedirect === 'login') {
             self::SetValuesToCookie($mResult);
             $oSocialOld = $oApiSocial->getSocialById($oSocial->IdSocial, $oSocial->TypeStr);
             if ($oSocialOld) {
                 if ($oInviteAccount && $oInviteAccount->IdAccount === $oSocialOld->IdAccount || !$oInviteAccount) {
                     if (!$oSocialOld->Disabled && $oSocialOld->issetScope('auth')) {
                         $oSocialOld->setScope('auth');
                         $oSocial->Scopes = $oSocialOld->Scopes;
                         $oApiSocial->updateSocial($oSocial);
                         $oInviteAccount = $oApiUsers->getAccountById($oSocialOld->IdAccount);
                     } else {
                         $bResult = false;
                         $sError = '?error=es-002';
                         if (!empty($mResult['email'])) {
                             $sError = $sError . '&email=' . $mResult['email'];
                         } else {
                             $sError = $sError . '&service=' . $mResult['type'];
                         }
                     }
                 } else {
                     $oInviteAccount = null;
                     $bResult = false;
                     $sError = '?error=es-003';
                 }
             } else {
                 $oInviteAccount = $oApiUsers->getAccountByEmail($mResult['email']);
                 if ($oInviteAccount) {
                     $oSocial->IdAccount = $oInviteAccount->IdAccount;
                     $oSocial->setScopes($mResult['scopes']);
                     $oApiSocial->createSocial($oSocial);
                 } else {
                     $sError = '?error=es-002';
                     if (!empty($mResult['email'])) {
                         $sError = $sError . '&email=' . $mResult['email'];
                     } else {
                         $sError = $sError . '&service=' . $mResult['type'];
                     }
                 }
             }
             if ($oInviteAccount) {
                 $oApiIntegrator = \CApi::Manager('integrator');
                 $oApiIntegrator->setAccountAsLoggedIn($oInviteAccount, true);
                 $oApiUsers->updateAccountLastLoginAndCount($oInviteAccount->IdUser);
             }
             \CApi::Location2('./' . $sError);
         } else {
             $oInviteAccount = \api_Utils::GetDefaultAccount();
             if ($oInviteAccount) {
                 $bResult = false;
                 $oSocial->IdAccount = $oInviteAccount->IdAccount;
                 $oSocialOld = $oApiSocial->getSocialById($oSocial->IdSocial, $oSocial->TypeStr);
                 if ($oSocialOld) {
                     if ($oSocialOld->IdAccount === $oSocial->IdAccount) {
                         if (in_array('null', $mResult['scopes']) || count($mResult['scopes']) === 0) {
                             $bResult = $oSocial->deleteSocial($oInviteAccount->IdAccount, $oSocial->TypeStr);
                         } else {
                             $oSocial->setScopes($mResult['scopes']);
                             $bResult = $oApiSocial->updateSocial($oSocial);
                         }
                     } else {
                         $bResult = false;
                         $oPlugin = \CApi::Plugin()->GetPluginByName('external-services');
                         if ($oPlugin) {
                             $sErrorMessage = $oPlugin->I18N('PLUGIN_EXTERNAL_SERVICES/INFO_ACCOUNT_ALREADY_ASSIGNED', $oInviteAccount);
                         }
                     }
                 } else {
                     if (!in_array('null', $mResult['scopes']) && count($mResult['scopes']) > 0) {
                         $oSocial->setScopes($mResult['scopes']);
                         $bResult = $oApiSocial->createSocial($oSocial);
                     }
                 }
                 $sResult = $bResult ? 'true' : 'false';
                 echo "<script>" . "if (typeof(window.opener.servicesSettingsViewModelCallback) !== 'undefined') {" . "window.opener.servicesSettingsViewModelCallback('" . $mResult['type'] . "', " . $sResult . ", '" . $sErrorMessage . "');" . "window.close();" . "}" . "</script>";
             }
         }
     }
 }
Ejemplo n.º 15
0
 /**
  * Sends message out.
  * 
  * @param CAccount $oAccount Account object.
  * @param \MailSo\Mime\Message $oMessage Message to be sent out.
  * @param CFetcher $oFetcher = null. Fetcher object which may override sending settings.
  * @param string $sSentFolder = ''. Name of Sent folder.
  * @param string $sDraftFolder = ''. Name of Sent folder.
  * @param string $sDraftUid = ''. Last UID value of the message saved in Drafts folder.
  *
  * @return array|bool
  *
  * @throws CApiInvalidArgumentException
  */
 public function sendMessage($oAccount, $oMessage, $oFetcher = null, $sSentFolder = '', $sDraftFolder = '', $sDraftUid = '')
 {
     if (!$oAccount || !$oMessage) {
         throw new CApiInvalidArgumentException();
     }
     $oImapClient =& $this->_getImapClient($oAccount);
     $rMessageStream = \MailSo\Base\ResourceRegistry::CreateMemoryResource();
     $iMessageStreamSize = \MailSo\Base\Utils::MultipleStreamWriter($oMessage->ToStream(true), array($rMessageStream), 8192, true, true, true);
     $mResult = false;
     if (false !== $iMessageStreamSize && is_resource($rMessageStream)) {
         $oRcpt = $oMessage->GetRcpt();
         if ($oRcpt && 0 < $oRcpt->Count()) {
             $sRcptEmail = '';
             try {
                 $iConnectTimeOut = CApi::GetConf('socket.connect-timeout', 5);
                 $iSocketTimeOut = CApi::GetConf('socket.get-timeout', 5);
                 $bVerifySsl = !!CApi::GetConf('socket.verify-ssl', false);
                 CApi::Plugin()->RunHook('webmail-smtp-update-socket-timeouts', array(&$iConnectTimeOut, &$iSocketTimeOut));
                 $oSmtpClient = \MailSo\Smtp\SmtpClient::NewInstance();
                 $oSmtpClient->SetTimeOuts($iConnectTimeOut, $iSocketTimeOut);
                 $oLogger = $oImapClient->Logger();
                 if ($oLogger) {
                     $oSmtpClient->SetLogger($oLogger);
                 }
                 $iSecure = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT;
                 if ($oFetcher) {
                     $iSecure = $oFetcher->OutgoingMailSecurity;
                 } else {
                     if ($oAccount->OutgoingMailUseSSL) {
                         $iSecure = \MailSo\Net\Enumerations\ConnectionSecurityType::SSL;
                     }
                 }
                 $sOutgoingMailLogin = '';
                 if ($oFetcher) {
                     $sOutgoingMailLogin = $oFetcher->IncomingMailLogin;
                 }
                 if (0 === strlen($sOutgoingMailLogin)) {
                     $sOutgoingMailLogin = $oAccount->OutgoingMailLogin;
                     $sOutgoingMailLogin = 0 < strlen($sOutgoingMailLogin) ? $sOutgoingMailLogin : $oAccount->IncomingMailLogin;
                 }
                 $sOutgoingMailPassword = '';
                 if ($oFetcher) {
                     $sOutgoingMailPassword = $oFetcher->IncomingMailPassword;
                 }
                 if (0 === strlen($sOutgoingMailPassword)) {
                     $sOutgoingMailPassword = $oAccount->OutgoingMailPassword;
                     $sOutgoingMailPassword = 0 < strlen($sOutgoingMailPassword) ? $sOutgoingMailPassword : $oAccount->IncomingMailPassword;
                 }
                 $sEhlo = \MailSo\Smtp\SmtpClient::EhloHelper();
                 CApi::Plugin()->RunHook('api-smtp-send-ehlo', array($oAccount, &$sEhlo));
                 if ($oFetcher) {
                     $oSmtpClient->Connect($oFetcher->OutgoingMailServer, $oFetcher->OutgoingMailPort, $sEhlo, $iSecure, $bVerifySsl);
                 } else {
                     $oSmtpClient->Connect($oAccount->OutgoingMailServer, $oAccount->OutgoingMailPort, $sEhlo, $iSecure, $bVerifySsl);
                 }
                 if ($oFetcher && $oFetcher->OutgoingMailAuth || !$oFetcher && $oAccount->OutgoingMailAuth) {
                     $oSmtpClient->Login($sOutgoingMailLogin, $sOutgoingMailPassword);
                 }
                 $oSmtpClient->MailFrom($oFetcher ? $oFetcher->Email : $oAccount->Email, (string) $iMessageStreamSize);
                 $aRcpt =& $oRcpt->GetAsArray();
                 CApi::Plugin()->RunHook('api-smtp-send-rcpt', array($oAccount, &$aRcpt));
                 foreach ($aRcpt as $oEmail) {
                     $sRcptEmail = $oEmail->GetEmail();
                     $oSmtpClient->Rcpt($sRcptEmail);
                 }
                 $oSmtpClient->DataWithStream($rMessageStream);
                 $oSmtpClient->LogoutAndDisconnect();
             } catch (\MailSo\Net\Exceptions\ConnectionException $oException) {
                 throw new \CApiManagerException(Errs::Mail_AccountConnectToMailServerFailed, $oException);
             } catch (\MailSo\Smtp\Exceptions\LoginException $oException) {
                 throw new \CApiManagerException(Errs::Mail_AccountLoginFailed, $oException);
             } catch (\MailSo\Smtp\Exceptions\NegativeResponseException $oException) {
                 throw new \CApiManagerException(Errs::Mail_CannotSendMessage, $oException);
             } catch (\MailSo\Smtp\Exceptions\MailboxUnavailableException $oException) {
                 throw new \CApiManagerException(Errs::Mail_MailboxUnavailable, $oException, array(), array('Mailbox' => $sRcptEmail));
             }
             if (0 < strlen($sSentFolder)) {
                 try {
                     if (!$oMessage->GetBcc()) {
                         if (is_resource($rMessageStream)) {
                             rewind($rMessageStream);
                         }
                         $oImapClient->MessageAppendStream($sSentFolder, $rMessageStream, $iMessageStreamSize, array(\MailSo\Imap\Enumerations\MessageFlag::SEEN));
                     } else {
                         $rAppendMessageStream = \MailSo\Base\ResourceRegistry::CreateMemoryResource();
                         $iAppendMessageStreamSize = \MailSo\Base\Utils::MultipleStreamWriter($oMessage->ToStream(), array($rAppendMessageStream), 8192, true, true, true);
                         $oImapClient->MessageAppendStream($sSentFolder, $rAppendMessageStream, $iAppendMessageStreamSize, array(\MailSo\Imap\Enumerations\MessageFlag::SEEN));
                         if (is_resource($rAppendMessageStream)) {
                             @fclose($rAppendMessageStream);
                         }
                     }
                 } catch (\Exception $oException) {
                     throw new \CApiManagerException(Errs::Mail_CannotSaveMessageInSentItems, $oException);
                 }
                 if (is_resource($rMessageStream)) {
                     @fclose($rMessageStream);
                 }
             }
             if (0 < strlen($sDraftFolder) && 0 < strlen($sDraftUid)) {
                 try {
                     $this->deleteMessage($oAccount, $sDraftFolder, array($sDraftUid));
                 } catch (\Exception $oException) {
                 }
             }
             $mResult = true;
         } else {
             throw new \CApiManagerException(Errs::Mail_InvalidRecipients);
         }
     }
     return $mResult;
 }
Ejemplo n.º 16
0
 /**
  * @return void
  */
 public function Handle()
 {
     $sVersion = file_get_contents(PSEVEN_APP_ROOT_PATH . 'VERSION');
     define('PSEVEN_APP_VERSION', $sVersion);
     if (!class_exists('MailSo\\Version')) {
         echo 'MailSo';
         return '';
     } else {
         if (!class_exists('\\CApi') || !\CApi::IsValid()) {
             echo 'AfterLogic API';
             return '';
         }
     }
     $sPathInfo = \trim(\trim($this->oHttp->GetServer('PATH_INFO', '')), ' /');
     if (!empty($sPathInfo)) {
         if ('dav' === \substr($sPathInfo, 0, 3)) {
             $this->oActions->PathInfoDav();
             return '';
         }
     }
     /* @var $oApiIntegrator \CApiIntegratorManager */
     $oApiIntegrator = \CApi::Manager('integrator');
     /* @var $oApiCapability \CApiCapabilityManager */
     $oApiCapability = \CApi::Manager('capability');
     $sResult = '';
     $sQuery = \trim(\trim($this->oHttp->GetServer('QUERY_STRING', '')), ' /');
     $iPos = \strpos($sQuery, '&');
     if (0 < $iPos) {
         $sQuery = \substr($sQuery, 0, $iPos);
     }
     $aPaths = explode('/', $sQuery);
     if (0 < count($aPaths) && !empty($aPaths[0])) {
         $sFirstPart = strtolower($aPaths[0]);
         if ('ping' === $sFirstPart) {
             @header('Content-Type: text/plain; charset=utf-8');
             $sResult = 'Pong';
         } else {
             if ('ajax' === $sFirstPart) {
                 @ob_start();
                 $aResponseItem = null;
                 $sAction = $this->oHttp->GetPost('Action', null);
                 try {
                     \CApi::Log('AJAX: Action: ' . $sAction);
                     if ('AppData' !== $sAction && \CApi::GetConf('labs.webmail.csrftoken-protection', true) && !$this->validateToken()) {
                         throw new \ProjectSeven\Exceptions\ClientException(\ProjectSeven\Notifications::InvalidToken);
                     } else {
                         if (!empty($sAction)) {
                             $sMethodName = 'Ajax' . $sAction;
                             if (method_exists($this->oActions, $sMethodName) && is_callable(array($this->oActions, $sMethodName))) {
                                 $this->oActions->SetActionParams($this->oHttp->GetPostAsArray());
                                 $aResponseItem = call_user_func(array($this->oActions, $sMethodName));
                             } else {
                                 if (\CApi::Plugin()->JsonHookExists($sMethodName)) {
                                     $this->oActions->SetActionParams($this->oHttp->GetPostAsArray());
                                     $aResponseItem = \CApi::Plugin()->RunJsonHook($this->oActions, $sMethodName);
                                 }
                             }
                         }
                     }
                     if (!is_array($aResponseItem)) {
                         throw new \ProjectSeven\Exceptions\ClientException(\ProjectSeven\Notifications::UnknownError);
                     }
                 } catch (\Exception $oException) {
                     //					if ($oException instanceof \ProjectSeven\Exceptions\ClientException &&
                     //						\ProjectSeven\Notifications::AuthError === $oException->getCode())
                     //					{
                     //						$oApiIntegrator = /* @var $oApiIntegrator \CApiIntegratorManager */ \CApi::Manager('integrator');
                     //						$oApiIntegrator->SetLastErrorCode(\ProjectSeven\Notifications::AuthError);
                     //						$oApiIntegrator->LogoutAccount();
                     //					}
                     \CApi::LogException($oException);
                     $sAction = empty($sAction) ? 'Unknown' : $sAction;
                     $aResponseItem = $this->oActions->ExceptionResponse(null, $sAction, $oException);
                 }
                 @header('Content-Type: application/json; charset=utf-8');
                 \CApi::Plugin()->RunHook('ajax.response-result', array($sAction, &$aResponseItem));
                 $sResult = \MailSo\Base\Utils::Php2js($aResponseItem, \CApi::MailSoLogger());
                 //				\CApi::Log('AJAX: Response: '.$sResult);
             } else {
                 if ('upload' === $sFirstPart) {
                     @ob_start();
                     $aResponseItem = null;
                     $sAction = empty($aPaths[1]) ? '' : $aPaths[1];
                     try {
                         $sMethodName = 'Upload' . $sAction;
                         if (method_exists($this->oActions, $sMethodName) && is_callable(array($this->oActions, $sMethodName))) {
                             $sError = '';
                             $sInputName = 'jua-uploader';
                             $iError = UPLOAD_ERR_OK;
                             $_FILES = isset($_FILES) ? $_FILES : null;
                             if (isset($_FILES, $_FILES[$sInputName], $_FILES[$sInputName]['name'], $_FILES[$sInputName]['tmp_name'], $_FILES[$sInputName]['size'], $_FILES[$sInputName]['type'])) {
                                 $iError = isset($_FILES[$sInputName]['error']) ? (int) $_FILES[$sInputName]['error'] : UPLOAD_ERR_OK;
                                 if (UPLOAD_ERR_OK === $iError) {
                                     $this->oActions->SetActionParams(array('AccountID' => $this->oHttp->GetPost('AccountID', ''), 'FileData' => $_FILES[$sInputName], 'AdditionalData' => $this->oHttp->GetPost('AdditionalData', null), 'IsExt' => '1' === (string) $this->oHttp->GetPost('IsExt', '0') ? '1' : '0', 'TenantHash' => (string) $this->oHttp->GetPost('TenantHash', ''), 'Token' => $this->oHttp->GetPost('Token', '')));
                                     \CApi::LogObject($this->oActions->GetActionParams());
                                     $aResponseItem = call_user_func(array($this->oActions, $sMethodName));
                                 } else {
                                     $sError = $this->oActions->convertUploadErrorToString($iError);
                                 }
                             } else {
                                 if (!isset($_FILES) || !is_array($_FILES) || 0 === count($_FILES)) {
                                     $sError = 'size';
                                 } else {
                                     $sError = 'unknown';
                                 }
                             }
                         }
                         if (!is_array($aResponseItem) && empty($sError)) {
                             throw new \ProjectSeven\Exceptions\ClientException(\ProjectSeven\Notifications::UnknownError);
                         }
                     } catch (\Exception $oException) {
                         \CApi::LogException($oException);
                         $aResponseItem = $this->oActions->ExceptionResponse(null, 'Upload', $oException);
                         $sError = 'exception';
                     }
                     if (0 < strlen($sError)) {
                         $aResponseItem['Error'] = $sError;
                     }
                     @ob_get_clean();
                     if ('iframe' === $this->oHttp->GetPost('jua-post-type', '')) {
                         @header('Content-Type: text/html; charset=utf-8');
                     } else {
                         @header('Content-Type: application/json; charset=utf-8');
                     }
                     $sResult = \MailSo\Base\Utils::Php2js($aResponseItem);
                 } else {
                     if ('speclogon' === $sFirstPart || 'speclogoff' === $sFirstPart) {
                         \CApi::SpecifiedUserLogging('speclogon' === $sFirstPart);
                         \CApi::Location('./');
                     } else {
                         if ('sso' === $sFirstPart) {
                             $oApiIntegratorManager = \CApi::Manager('integrator');
                             try {
                                 $sHash = $this->oHttp->GetRequest('hash');
                                 if (!empty($sHash)) {
                                     $sData = \CApi::Cacher()->Get('SSO:' . $sHash, true);
                                     $aData = \CApi::DecodeKeyValues($sData);
                                     if (!empty($aData['Email']) && isset($aData['Password'], $aData['Login'])) {
                                         $oAccount = $oApiIntegratorManager->LoginToAccount($aData['Email'], $aData['Password'], $aData['Login']);
                                         if ($oAccount) {
                                             $oApiIntegratorManager->SetAccountAsLoggedIn($oAccount);
                                         }
                                     }
                                 } else {
                                     $oApiIntegratorManager->LogoutAccount();
                                 }
                             } catch (\Exception $oExc) {
                                 \CApi::LogException($oExc);
                             }
                             \CApi::Location('./');
                         } else {
                             if ('autodiscover' === $sFirstPart) {
                                 $oSettings =& \CApi::GetSettings();
                                 $sInput = \file_get_contents('php://input');
                                 //$sInput = '<?'.'xml version="1.0" encoding="utf-8"?'.'><Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006"><Request><EMailAddress>test@afterlogic.com</EMailAddress><AcceptableResponseSchema>http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a</AcceptableResponseSchema></Request></Autodiscover>';
                                 \CApi::Log('#autodiscover:');
                                 \CApi::LogObject($sInput);
                                 $aMatches = array();
                                 $aEmailAddress = array();
                                 \preg_match("/\\<AcceptableResponseSchema\\>(.*?)\\<\\/AcceptableResponseSchema\\>/i", $sInput, $aMatches);
                                 \preg_match("/\\<EMailAddress\\>(.*?)\\<\\/EMailAddress\\>/", $sInput, $aEmailAddress);
                                 if (!empty($aMatches[1]) && !empty($aEmailAddress[1])) {
                                     $sIncMailServer = $oSettings->GetConf('WebMail/ExternalHostNameOfLocalImap');
                                     $sOutMailServer = $oSettings->GetConf('WebMail/ExternalHostNameOfLocalSmtp');
                                     if (0 < \strlen($sIncMailServer) && 0 < \strlen($sOutMailServer)) {
                                         $sResult = \implode("\n", array('<Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006">', '	<Response xmlns="' . $aMatches[1] . '">', '		<Account>', '			<AccountType>email</AccountType>', '			<Action>settings</Action>', '			<Protocol>', '				<Type>IMAP</Type>', '				<Server>' . $sIncMailServer . '</Server>', '				<LoginName>' . $aEmailAddress[1] . '</LoginName>', '				<Port>143</Port>', '				<SSL>off</SSL>', '				<SPA>off</SPA>', '				<AuthRequired>on</AuthRequired>', '			</Protocol>', '			<Protocol>', '				<Type>SMTP</Type>', '				<Server>' . $sOutMailServer . '</Server>', '				<LoginName>' . $aEmailAddress[1] . '</LoginName>', '				<Port>25</Port>', '				<SSL>off</SSL>', '				<SPA>off</SPA>', '				<AuthRequired>on</AuthRequired>', '			</Protocol>', '		</Account>', '	</Response>', '</Autodiscover>'));
                                     }
                                 }
                                 if (empty($sResult)) {
                                     $usec = $sec = 0;
                                     list($usec, $sec) = \explode(' ', microtime());
                                     $sResult = \implode("\n", array('<Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006">', empty($aMatches[1]) ? '	<Response>' : '	<Response xmlns="' . $aMatches[1] . '">', '		<Error Time="' . \gmdate('H:i:s', $sec) . \substr($usec, 0, \strlen($usec) - 2) . '" Id="2477272013">', '			<ErrorCode>600</ErrorCode>', '			<Message>Invalid Request</Message>', '			<DebugData />', '		</Error>', '	</Response>', '</Autodiscover>'));
                                 }
                                 header('Content-Type: text/xml');
                                 $sResult = '<' . '?xml version="1.0" encoding="utf-8"?' . '>' . "\n" . $sResult;
                                 \CApi::Log('');
                                 \CApi::Log($sResult);
                             } else {
                                 if ('profile' === $sFirstPart) {
                                     /* @var $oApiIosManager \CApiIosManager */
                                     $oApiIosManager = \CApi::Manager('ios');
                                     $oAccount = $oApiIntegrator->GetLogginedDefaultAccount();
                                     $mResultProfile = $oApiIosManager && $oAccount ? $oApiIosManager->GenerateXMLProfile($oAccount) : false;
                                     if ($mResultProfile !== false) {
                                         header('Content-type: application/x-apple-aspen-config; chatset=utf-8');
                                         header('Content-Disposition: attachment; filename="afterlogic.mobileconfig"');
                                         echo $mResultProfile;
                                     } else {
                                         \CApi::Location('./?IOS/Error');
                                     }
                                 } else {
                                     if ('ios' === $sFirstPart) {
                                         $sResult = file_get_contents(PSEVEN_APP_ROOT_PATH . 'templates/Ios.html');
                                         $iUserId = $oApiIntegrator->GetLogginedUserId();
                                         if (0 < $iUserId) {
                                             $oAccount = $oApiIntegrator->GetLogginedDefaultAccount();
                                             $bError = isset($aPaths[1]) && 'error' === strtolower($aPaths[1]);
                                             // TODO
                                             @setcookie('skip_ios', '1', time() + 3600 * 3600, '/', null, null, true);
                                             $sResult = strtr($sResult, array('{{IOS/HELLO}}' => \CApi::I18N('IOS/HELLO'), '{{IOS/DESC_P1}}' => \CApi::I18N('IOS/DESC_P1'), '{{IOS/DESC_P2}}' => \CApi::I18N('IOS/DESC_P2'), '{{IOS/DESC_P3}}' => \CApi::I18N('IOS/DESC_P3'), '{{IOS/DESC_P4}}' => \CApi::I18N('IOS/DESC_P4'), '{{IOS/DESC_P5}}' => \CApi::I18N('IOS/DESC_P5'), '{{IOS/DESC_P6}}' => \CApi::I18N('IOS/DESC_P6'), '{{IOS/DESC_P7}}' => \CApi::I18N('IOS/DESC_P7'), '{{IOS/DESC_BUTTON_YES}}' => \CApi::I18N('IOS/DESC_BUTTON_YES'), '{{IOS/DESC_BUTTON_SKIP}}' => \CApi::I18N('IOS/DESC_BUTTON_SKIP'), '{{IOS/DESC_BUTTON_OPEN}}' => \CApi::I18N('IOS/DESC_BUTTON_OPEN'), '{{AppVersion}}' => PSEVEN_APP_VERSION, '{{IntegratorLinks}}' => $oApiIntegrator->BuildHeadersLink()));
                                         } else {
                                             \CApi::Location('./');
                                         }
                                     } else {
                                         if ('raw' === $sFirstPart) {
                                             $sAction = empty($aPaths[1]) ? '' : $aPaths[1];
                                             try {
                                                 if (!empty($sAction)) {
                                                     $sMethodName = 'Raw' . $sAction;
                                                     if (method_exists($this->oActions, $sMethodName)) {
                                                         $this->oActions->SetActionParams(array('AccountID' => empty($aPaths[2]) || '0' === (string) $aPaths[2] ? '' : $aPaths[2], 'RawKey' => empty($aPaths[3]) ? '' : $aPaths[3], 'IsExt' => empty($aPaths[4]) ? '0' : ('1' === (string) $aPaths[4] ? '1' : 0), 'TenantHash' => empty($aPaths[5]) ? '' : $aPaths[5]));
                                                         if (!call_user_func(array($this->oActions, $sMethodName))) {
                                                             \CApi::Log('False result.', \ELogLevel::Error);
                                                         }
                                                     } else {
                                                         \CApi::Log('Invalid action.', \ELogLevel::Error);
                                                     }
                                                 } else {
                                                     \CApi::Log('Empty action.', \ELogLevel::Error);
                                                 }
                                             } catch (\Exception $oException) {
                                                 \CApi::LogException($oException, \ELogLevel::Error);
                                             }
                                         } else {
                                             if ('post' === $sFirstPart) {
                                                 $sAction = $this->oHttp->GetPost('Action');
                                                 try {
                                                     if (!empty($sAction)) {
                                                         $sMethodName = 'Post' . $sAction;
                                                         if (method_exists($this->oActions, $sMethodName) && is_callable(array($this->oActions, $sMethodName))) {
                                                             $this->oActions->SetActionParams($this->oHttp->GetPostAsArray());
                                                             if (!call_user_func(array($this->oActions, $sMethodName))) {
                                                                 \CApi::Log('False result.', \ELogLevel::Error);
                                                             }
                                                         } else {
                                                             \CApi::Log('Invalid action.', \ELogLevel::Error);
                                                         }
                                                     } else {
                                                         \CApi::Log('Empty action.', \ELogLevel::Error);
                                                     }
                                                 } catch (\Exception $oException) {
                                                     \CApi::LogException($oException, \ELogLevel::Error);
                                                 }
                                             } else {
                                                 if ($this->oHttp->HasQuery('facebook')) {
                                                     $mResult = \api_Social::Facebook(\api_Social::GetTenantFromCookieByHash());
                                                     if (false !== $mResult && is_array($mResult)) {
                                                         \api_Social::Process($mResult);
                                                     }
                                                 } else {
                                                     if ($this->oHttp->HasQuery('google')) {
                                                         $mResult = \api_Social::Google(\api_Social::GetTenantFromCookieByHash());
                                                         if (false !== $mResult && is_array($mResult)) {
                                                             \api_Social::Process($mResult);
                                                         }
                                                     } else {
                                                         if ($this->oHttp->HasQuery('twitter')) {
                                                             $mResult = \api_Social::Twitter(\api_Social::GetTenantFromCookieByHash());
                                                             if (false !== $mResult && is_array($mResult)) {
                                                                 \api_Social::Process($mResult);
                                                             }
                                                         } else {
                                                             if ($this->oHttp->HasQuery('dropbox')) {
                                                                 $mResult = \api_Social::Dropbox(\api_Social::GetTenantFromCookieByHash());
                                                                 if (false !== $mResult && is_array($mResult)) {
                                                                     \api_Social::Process($mResult);
                                                                 }
                                                             } else {
                                                                 if ($this->oHttp->HasQuery('helpdesk')) {
                                                                     $sResult = $this->indexHTML(true, $this->oHttp->GetQuery('helpdesk'));
                                                                 } else {
                                                                     if ($this->oHttp->HasQuery('invite')) {
                                                                         $aInviteValues = \CApi::DecodeKeyValues($this->oHttp->GetQuery('invite'));
                                                                         $oApiUsersManager = \CApi::Manager('users');
                                                                         $oApiCalendarManager = \CApi::Manager('calendar');
                                                                         if (isset($aInviteValues['organizer'])) {
                                                                             $oAccountOrganizer = $oApiUsersManager->GetAccountOnLogin($aInviteValues['organizer']);
                                                                             if (isset($oAccountOrganizer, $aInviteValues['attendee'], $aInviteValues['calendarId'], $aInviteValues['eventId'], $aInviteValues['action'])) {
                                                                                 $oCalendar = $oApiCalendarManager->GetCalendar($oAccountOrganizer, $aInviteValues['calendarId']);
                                                                                 if ($oCalendar) {
                                                                                     $oEvent = $oApiCalendarManager->GetEvent($oAccountOrganizer, $aInviteValues['calendarId'], $aInviteValues['eventId']);
                                                                                     if ($oEvent && is_array($oEvent) && 0 < count($oEvent) && isset($oEvent[0])) {
                                                                                         if (is_string($sResult)) {
                                                                                             $sResult = file_get_contents(PSEVEN_APP_ROOT_PATH . 'templates/InviteExternal.html');
                                                                                             $dt = new \DateTime();
                                                                                             $dt->setTimestamp($oEvent[0]['startTS']);
                                                                                             if (!$oEvent[0]['allDay']) {
                                                                                                 $sDefaultTimeZone = new \DateTimeZone($oAccountOrganizer->GetDefaultStrTimeZone());
                                                                                                 $dt->setTimezone($sDefaultTimeZone);
                                                                                             }
                                                                                             $sAction = $aInviteValues['action'];
                                                                                             $sActionColor = 'green';
                                                                                             $sActionText = '';
                                                                                             switch (strtoupper($sAction)) {
                                                                                                 case 'ACCEPTED':
                                                                                                     $sActionColor = 'green';
                                                                                                     $sActionText = 'Accepted';
                                                                                                     break;
                                                                                                 case 'DECLINED':
                                                                                                     $sActionColor = 'red';
                                                                                                     $sActionText = 'Declined';
                                                                                                     break;
                                                                                                 case 'TENTATIVE':
                                                                                                     $sActionColor = '#A0A0A0';
                                                                                                     $sActionText = 'Tentative';
                                                                                                     break;
                                                                                             }
                                                                                             $sDateFormat = 'm/d/Y';
                                                                                             $sTimeFormat = 'h:i A';
                                                                                             switch ($oAccountOrganizer->User->DefaultDateFormat) {
                                                                                                 case \EDateFormat::DDMMYYYY:
                                                                                                     $sDateFormat = 'd/m/Y';
                                                                                                     break;
                                                                                                 case \EDateFormat::DD_MONTH_YYYY:
                                                                                                     $sDateFormat = 'd/m/Y';
                                                                                                     break;
                                                                                                 default:
                                                                                                     $sDateFormat = 'm/d/Y';
                                                                                                     break;
                                                                                             }
                                                                                             switch ($oAccountOrganizer->User->DefaultTimeFormat) {
                                                                                                 case \ETimeFormat::F24:
                                                                                                     $sTimeFormat = 'H:i';
                                                                                                     break;
                                                                                                 case \EDateFormat::DD_MONTH_YYYY:
                                                                                                     \ETimeFormat::F12;
                                                                                                     $sTimeFormat = 'h:i A';
                                                                                                     break;
                                                                                                 default:
                                                                                                     $sTimeFormat = 'h:i A';
                                                                                                     break;
                                                                                             }
                                                                                             $sDateTime = $dt->format($sDateFormat . ' ' . $sTimeFormat);
                                                                                             $mResult = array('{{COLOR}}' => $oCalendar->Color, '{{EVENT_NAME}}' => $oEvent[0]['subject'], '{{EVENT_BEGIN}}' => ucfirst(\CApi::ClientI18N('REMINDERS/EVENT_BEGIN', $oAccountOrganizer)), '{{EVENT_DATE}}' => $sDateTime, '{{CALENDAR}}' => ucfirst(\CApi::ClientI18N('REMINDERS/CALENDAR', $oAccountOrganizer)), '{{CALENDAR_NAME}}' => $oCalendar->DisplayName, '{{EVENT_DESCRIPTION}}' => $oEvent[0]['description'], '{{EVENT_ACTION}}' => $sActionText, '{{ACTION_COLOR}}' => $sActionColor);
                                                                                             $sResult = strtr($sResult, $mResult);
                                                                                         } else {
                                                                                             \CApi::Log('Empty template.', \ELogLevel::Error);
                                                                                         }
                                                                                     } else {
                                                                                         \CApi::Log('Event not found.', \ELogLevel::Error);
                                                                                     }
                                                                                 } else {
                                                                                     \CApi::Log('Calendar not found.', \ELogLevel::Error);
                                                                                 }
                                                                                 $sAttendee = $aInviteValues['attendee'];
                                                                                 if (!empty($sAttendee)) {
                                                                                     $oApiCalendarManager->UpdateAppointment($oAccountOrganizer, $aInviteValues['calendarId'], $aInviteValues['eventId'], $sAttendee, $aInviteValues['action']);
                                                                                 }
                                                                             }
                                                                         }
                                                                     } else {
                                                                         if ($this->oHttp->HasQuery('calendar-pub') && 0 < strlen($this->oHttp->GetQuery('calendar-pub'))) {
                                                                             $sResult = $this->indexHTML(false, '', $this->oHttp->GetQuery('calendar-pub'));
                                                                         } else {
                                                                             if ($this->oHttp->HasQuery('files-pub') && 0 < strlen($this->oHttp->GetQuery('files-pub'))) {
                                                                                 $sResult = $this->indexHTML(false, '', '', $this->oHttp->GetQuery('files-pub'));
                                                                             } else {
                                                                                 if ('min' === $sFirstPart || 'window' === $sFirstPart) {
                                                                                     $sAction = empty($aPaths[1]) ? '' : $aPaths[1];
                                                                                     try {
                                                                                         if (!empty($sAction)) {
                                                                                             $sMethodName = $aPaths[0] . $sAction;
                                                                                             if (method_exists($this->oActions, $sMethodName)) {
                                                                                                 if ('Min' === $aPaths[0]) {
                                                                                                     $oMinManager = \CApi::Manager('min');
                                                                                                     $mHashResult = $oMinManager->GetMinByHash(empty($aPaths[2]) ? '' : $aPaths[2]);
                                                                                                     $this->oActions->SetActionParams(array('Result' => $mHashResult, 'Hash' => empty($aPaths[2]) ? '' : $aPaths[2]));
                                                                                                 } else {
                                                                                                     $this->oActions->SetActionParams(array('AccountID' => empty($aPaths[2]) || '0' === (string) $aPaths[2] ? '' : $aPaths[2], 'RawKey' => empty($aPaths[3]) ? '' : $aPaths[3]));
                                                                                                 }
                                                                                                 $mResult = call_user_func(array($this->oActions, $sMethodName));
                                                                                                 $sTemplate = isset($mResult['Template']) && !empty($mResult['Template']) && is_string($mResult['Template']) ? $mResult['Template'] : null;
                                                                                                 if (!empty($sTemplate) && is_array($mResult) && file_exists(PSEVEN_APP_ROOT_PATH . $sTemplate)) {
                                                                                                     $sResult = file_get_contents(PSEVEN_APP_ROOT_PATH . $sTemplate);
                                                                                                     if (is_string($sResult)) {
                                                                                                         $sResult = strtr($sResult, $mResult);
                                                                                                     } else {
                                                                                                         \CApi::Log('Empty template.', \ELogLevel::Error);
                                                                                                     }
                                                                                                 } else {
                                                                                                     if (!empty($sTemplate)) {
                                                                                                         \CApi::Log('Empty template.', \ELogLevel::Error);
                                                                                                     } else {
                                                                                                         if (true === $mResult) {
                                                                                                             $sResult = '';
                                                                                                         } else {
                                                                                                             \CApi::Log('False result.', \ELogLevel::Error);
                                                                                                         }
                                                                                                     }
                                                                                                 }
                                                                                             } else {
                                                                                                 \CApi::Log('Invalid action.', \ELogLevel::Error);
                                                                                             }
                                                                                         } else {
                                                                                             \CApi::Log('Empty action.', \ELogLevel::Error);
                                                                                         }
                                                                                     } catch (\Exception $oException) {
                                                                                         \CApi::LogException($oException);
                                                                                     }
                                                                                 } else {
                                                                                     if ('twilio' === $sFirstPart) {
                                                                                         $sResult = $this->oTwilio->Init($aPaths, $this->oHttp);
                                                                                     } else {
                                                                                         if ('plugins' === $sFirstPart) {
                                                                                             $sType = !empty($aPaths[1]) ? trim($aPaths[1]) : '';
                                                                                             if ('js' === $sType) {
                                                                                                 @header('Content-Type: application/javascript; charset=utf-8');
                                                                                                 $sResult = \CApi::Plugin()->CompileJs();
                                                                                             }
                                                                                         } else {
                                                                                             if ('postlogin' === $sFirstPart && \CApi::GetConf('labs.allow-post-login', false)) {
                                                                                                 $oSettings =& \CApi::GetSettings();
                                                                                                 $sEmail = trim((string) $this->oHttp->GetRequest('Email', ''));
                                                                                                 $sLogin = (string) $this->oHttp->GetRequest('Login', '');
                                                                                                 $sPassword = (string) $this->oHttp->GetRequest('Password', '');
                                                                                                 $sAtDomain = trim($oSettings->GetConf('WebMail/LoginAtDomainValue'));
                                                                                                 if (\ELoginFormType::Login === (int) $oSettings->GetConf('WebMail/LoginFormType') && 0 < strlen($sAtDomain)) {
                                                                                                     $sEmail = \api_Utils::GetAccountNameFromEmail($sLogin) . '@' . $sAtDomain;
                                                                                                     $sLogin = $sEmail;
                                                                                                 }
                                                                                                 if (0 !== strlen($sPassword) && 0 !== strlen($sEmail . $sLogin)) {
                                                                                                     $oAccount = $oApiIntegrator->LoginToAccount($sEmail, $sPassword, $sLogin);
                                                                                                     if ($oAccount instanceof \CAccount) {
                                                                                                         $oApiIntegrator->SetAccountAsLoggedIn($oAccount);
                                                                                                     }
                                                                                                 }
                                                                                                 \CApi::Location('./');
                                                                                             } else {
                                                                                                 if ('mobile' === $sFirstPart) {
                                                                                                     if ($oApiIntegrator && $oApiCapability && $oApiCapability->IsNotLite()) {
                                                                                                         $oApiIntegrator->SetMobile(true);
                                                                                                     }
                                                                                                     \CApi::Location('./');
                                                                                                 } else {
                                                                                                     @ob_start();
                                                                                                     \CApi::Plugin()->RunServiceHandle($sFirstPart, $aPaths);
                                                                                                     $sResult = @ob_get_clean();
                                                                                                     if (0 === strlen($sResult)) {
                                                                                                         $sResult = $this->getIndexHTML();
                                                                                                     }
                                                                                                 }
                                                                                             }
                                                                                         }
                                                                                     }
                                                                                 }
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     } else {
         $sResult = $this->getIndexHTML();
     }
     // Output result
     echo $sResult;
 }
Ejemplo n.º 17
0
 /**
  * @param int $iDomainId
  * @return bool
  */
 public function HasAccessDomain($iDomainId)
 {
     static $aCache = array();
     $iDomainId = '' === $iDomainId ? 0 : (int) $iDomainId;
     if (isset($aCache[$iDomainId])) {
         return $aCache[$iDomainId];
     }
     $iTenantId = $this->TenantId();
     $bResult = false;
     if (AP_SESS_AUTH_TYPE_SUPER_ADMIN_ONLYREAD === $this->iAuthType) {
         CApi::Plugin()->RunHook('adminpanel-demo-domain-access', array($iDomainId, &$bResult));
     } else {
         if (0 < $iDomainId && 0 < $iTenantId || 0 === $iTenantId) {
             if (0 < $iTenantId) {
                 $oDomainsApi = CApi::Manager('domains');
                 $oDomain = $oDomainsApi->GetDomainById($iDomainId);
                 if ($oDomain && $iTenantId === $oDomain->IdTenant) {
                     $bResult = true;
                 }
             } else {
                 $bResult = true;
             }
         }
     }
     $aCache[$iDomainId] = $bResult;
     return $bResult;
 }
Ejemplo n.º 18
0
 /**
  * Can account login with password.
  * 
  * @return bool
  */
 public function canLoginWithPassword()
 {
     $bCanLoginWithPassword = false;
     CApi::Plugin()->RunHook('api-account-can-login-with-password', array(&$bCanLoginWithPassword));
     return $this->AllowMail || $this->IsPasswordSpecified || $bCanLoginWithPassword;
 }
Ejemplo n.º 19
0
 public function Copy($oAccount, $iFromType, $iToType, $sFromPath, $sToPath, $sName, $sNewName = null)
 {
     $bResult = false;
     $bBreak = false;
     \CApi::Plugin()->RunHook('filestorage.copy', array($oAccount, $iFromType, $iToType, $sFromPath, $sToPath, $sName, $sNewName, &$bResult, &$bBreak));
     if (!$bBreak) {
         $bResult = $this->oStorage->Copy($oAccount, $iFromType, $iToType, $sFromPath, $sToPath, $sName, $sNewName);
     }
     return $bResult;
 }
Ejemplo n.º 20
0
 /**
  * @param string $sWebPath Default value is **'.'**.
  * @param bool $bHelpdesk Default value is **false**.
  * @param int $iHelpdeskIdTenant Default value is **null**.
  * @param string $sHelpdeskHash Default value is empty string.
  * @param string $sCalendarPubHash Default value is empty string.
  * @param string $sFileStoragePubHash Default value is empty string.
  * @param bool $bMobile Default value is **false**.
  *
  * @return string
  */
 public function buildBody($sWebPath = '.', $bHelpdesk = false, $iHelpdeskIdTenant = null, $sHelpdeskHash = '', $sCalendarPubHash = '', $sFileStoragePubHash = '', $bMobile = false)
 {
     list($sLanguage, $sTheme, $sSiteName) = $this->getThemeAndLanguage();
     $sMobileSuffix = $bMobile && !$bHelpdesk ? '-mobile' : '';
     $sWebPath = empty($sWebPath) ? '.' : $sWebPath;
     return '<div class="pSevenMain"><div id="pSevenLoading"></div><div id="pSevenContent"></div><div id="pSevenHidden"></div>' . '<div>' . $this->compileTemplates($sTheme, $bMobile) . '<script src="' . $sWebPath . '/static/js/libs.js?' . CApi::VersionJs() . '"></script>' . $this->compileLanguage($sLanguage) . $this->compileAppData($bHelpdesk, $iHelpdeskIdTenant, $sHelpdeskHash, $sCalendarPubHash, $sFileStoragePubHash) . '<script src="' . $sWebPath . '/static/js/app' . $sMobileSuffix . ($bHelpdesk ? '-helpdesk' : (empty($sCalendarPubHash) ? empty($sFileStoragePubHash) ? '' : '-filestorage-pub' : '-calendar-pub')) . (CApi::GetConf('labs.use-app-min-js', false) ? '.min' : '') . '.js?' . CApi::VersionJs() . '"></script>' . (CApi::Plugin()->HasJsFiles() ? '<script src="?/Plugins/js/' . CApi::Plugin()->Hash() . '/"></script>' : '') . '</div></div>' . "\r\n" . '<!-- ' . CApi::Version() . ' -->';
 }
Ejemplo n.º 21
0
 /**
  * @param string $sMimeType
  * @param string $sFileName = ''
  * @return bool
  */
 public static function isIframedMimeTypeSupported($sMimeType, $sFileName = '')
 {
     $bResult = \CApi::GetConf('labs.allow-officeapps-viewer', true) && !!preg_match('/\\.(doc|docx|docm|dotm|dotx|xlsx|xlsb|xls|xlsm|pptx|ppsx|ppt|pps|pptm|potm|ppam|potx|ppsm)$/', strtolower(trim($sFileName)));
     \CApi::Plugin()->RunHook('webmail.supports-iframed-attachments', array(&$bResult, $sMimeType, $sFileName));
     return $bResult;
 }
Ejemplo n.º 22
0
	/**
	 * @param string $sMimeType
	 * @param string $sFileName = ''
	 * @return bool
	 */
	public function isExpandMimeTypeSupported($sMimeType, $sFileName = '')
	{
		$bResult = false;
		\CApi::Plugin()->RunHook('webmail.supports-expanding-attachments', array(&$bResult, $sMimeType, $sFileName));
		return $bResult;
	}
Ejemplo n.º 23
0
 /**
  * @param string $sRawFolderFullName
  * @param \MailSo\Imap\FetchResponse $oFetchResponse
  * @param \MailSo\Imap\BodyStructure $oBodyStructure = null
  * @param array $aAscPartsIds = array()
  *
  * @return CApiMailMessage
  */
 public function InitByFetchResponse($sRawFolderFullName, $oFetchResponse, $oBodyStructure = null, $sRfc822SubMimeIndex = '', $aAscPartsIds = array())
 {
     if (!$oBodyStructure) {
         $oBodyStructure = $oFetchResponse->GetFetchBodyStructure();
     }
     $aTextParts = $oBodyStructure ? $oBodyStructure->SearchHtmlOrPlainParts() : array();
     $aICalPart = $oBodyStructure ? $oBodyStructure->SearchByContentType('text/calendar') : null;
     $oICalPart = is_array($aICalPart) && 0 < count($aICalPart) ? $aICalPart[0] : null;
     $aVCardPart = $oBodyStructure ? $oBodyStructure->SearchByContentType('text/vcard') : null;
     $aVCardPart = $aVCardPart ? $aVCardPart : ($oBodyStructure ? $oBodyStructure->SearchByContentType('text/x-vcard') : null);
     $oVCardPart = is_array($aVCardPart) && 0 < count($aVCardPart) ? $aVCardPart[0] : null;
     $sUid = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::UID);
     $sSize = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::RFC822_SIZE);
     $sInternalDate = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::INTERNALDATE);
     $aFlags = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::FLAGS);
     $this->sFolder = $sRawFolderFullName;
     $this->iUid = is_numeric($sUid) ? (int) $sUid : 0;
     $this->iSize = is_numeric($sSize) ? (int) $sSize : 0;
     $this->iTextSize = 0;
     $this->aFlags = is_array($aFlags) ? $aFlags : array();
     $this->aFlagsLowerCase = array_map('strtolower', $this->aFlags);
     $this->iInternalTimeStampInUTC = \MailSo\Base\DateTimeHelper::ParseInternalDateString($sInternalDate);
     if ($oICalPart) {
         $sICal = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::BODY . '[' . $oICalPart->PartID() . ']');
         if (!empty($sICal)) {
             $sICal = \MailSo\Base\Utils::DecodeEncodingValue($sICal, $oICalPart->MailEncodingName());
             $sICal = \MailSo\Base\Utils::ConvertEncoding($sICal, \MailSo\Base\Utils::NormalizeCharset($oICalPart->Charset(), true), \MailSo\Base\Enumerations\Charset::UTF_8);
             if (!empty($sICal) && false !== strpos($sICal, 'BEGIN:VCALENDAR')) {
                 $sICal = preg_replace('/(.*)(BEGIN[:]VCALENDAR(.+)END[:]VCALENDAR)(.*)/ms', '$2', $sICal);
             } else {
                 $sICal = '';
             }
             if (!empty($sICal)) {
                 $this->AddExtend('ICAL_RAW', $sICal);
             }
         }
     }
     if ($oVCardPart) {
         $sVCard = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::BODY . '[' . $oVCardPart->PartID() . ']');
         if (!empty($sVCard)) {
             $sVCard = \MailSo\Base\Utils::DecodeEncodingValue($sVCard, $oVCardPart->MailEncodingName());
             $sVCard = \MailSo\Base\Utils::ConvertEncoding($sVCard, \MailSo\Base\Utils::NormalizeCharset($oVCardPart->Charset(), true), \MailSo\Base\Enumerations\Charset::UTF_8);
             if (!empty($sVCard) && false !== strpos($sVCard, 'BEGIN:VCARD')) {
                 $sVCard = preg_replace('/(.*)(BEGIN\\:VCARD(.+)END\\:VCARD)(.*)/ms', '$2', $sVCard);
             } else {
                 $sVCard = '';
             }
             if (!empty($sVCard)) {
                 $this->AddExtend('VCARD_RAW', $sVCard);
             }
         }
     }
     $sCharset = $oBodyStructure ? $oBodyStructure->SearchCharset() : '';
     $sCharset = \MailSo\Base\Utils::NormalizeCharset($sCharset);
     $this->sHeaders = trim($oFetchResponse->GetHeaderFieldsValue($sRfc822SubMimeIndex));
     if (!empty($this->sHeaders)) {
         $oHeaders = \MailSo\Mime\HeaderCollection::NewInstance()->Parse($this->sHeaders, false, $sCharset);
         $sContentTypeCharset = $oHeaders->ParameterValue(\MailSo\Mime\Enumerations\Header::CONTENT_TYPE, \MailSo\Mime\Enumerations\Parameter::CHARSET);
         if (!empty($sContentTypeCharset)) {
             $sCharset = $sContentTypeCharset;
             $sCharset = \MailSo\Base\Utils::NormalizeCharset($sCharset);
         }
         if (!empty($sCharset)) {
             $oHeaders->SetParentCharset($sCharset);
         }
         $bCharsetAutoDetect = 0 === \strlen($sCharset);
         $this->sSubject = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::SUBJECT, $bCharsetAutoDetect);
         $this->sMessageId = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::MESSAGE_ID);
         $this->sContentType = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::CONTENT_TYPE);
         $aReceived = $oHeaders->ValuesByName(\MailSo\Mime\Enumerations\Header::RECEIVED);
         $sReceived = !empty($aReceived[0]) ? trim($aReceived[0]) : '';
         $sDate = '';
         if (!empty($sReceived)) {
             $aParts = explode(';', $sReceived);
             if (0 < count($aParts)) {
                 $aParts = array_reverse($aParts);
                 foreach ($aParts as $sReceiveLine) {
                     $sReceiveLine = trim($sReceiveLine);
                     if (preg_match('/[\\d]{4} [\\d]{2}:[\\d]{2}:[\\d]{2} /', $sReceiveLine)) {
                         $sDate = $sReceiveLine;
                         break;
                     }
                 }
             }
         }
         if (empty($sDate)) {
             $sDate = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::DATE);
         }
         if (!empty($sDate)) {
             $this->iReceivedOrDateTimeStampInUTC = \MailSo\Base\DateTimeHelper::ParseRFC2822DateString($sDate);
         }
         $this->oFrom = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::FROM_, $bCharsetAutoDetect);
         $this->oTo = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::TO_, $bCharsetAutoDetect);
         $this->oCc = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::CC, $bCharsetAutoDetect);
         $this->oBcc = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::BCC, $bCharsetAutoDetect);
         $this->oSender = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::SENDER, $bCharsetAutoDetect);
         $this->oReplyTo = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::REPLY_TO, $bCharsetAutoDetect);
         $this->sInReplyTo = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::IN_REPLY_TO);
         $this->sReferences = \preg_replace('/[\\s]+/', ' ', $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::REFERENCES));
         // Sensitivity
         $this->iSensitivity = \MailSo\Mime\Enumerations\Sensitivity::NOTHING;
         $sSensitivity = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::SENSITIVITY);
         switch (strtolower($sSensitivity)) {
             case 'personal':
                 $this->iSensitivity = \MailSo\Mime\Enumerations\Sensitivity::PERSONAL;
                 break;
             case 'private':
                 $this->iSensitivity = \MailSo\Mime\Enumerations\Sensitivity::PRIVATE_;
                 break;
             case 'company-confidential':
                 $this->iSensitivity = \MailSo\Mime\Enumerations\Sensitivity::CONFIDENTIAL;
                 break;
         }
         // Priority
         $this->iPriority = \MailSo\Mime\Enumerations\MessagePriority::NORMAL;
         $sPriority = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_MSMAIL_PRIORITY);
         if (0 === strlen($sPriority)) {
             $sPriority = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::IMPORTANCE);
         }
         if (0 === strlen($sPriority)) {
             $sPriority = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_PRIORITY);
         }
         if (0 < strlen($sPriority)) {
             switch (str_replace(' ', '', strtolower($sPriority))) {
                 case 'high':
                 case '1(highest)':
                 case '2(high)':
                 case '1':
                 case '2':
                     $this->iPriority = \MailSo\Mime\Enumerations\MessagePriority::HIGH;
                     break;
                 case 'low':
                 case '4(low)':
                 case '5(lowest)':
                 case '4':
                 case '5':
                     $this->iPriority = \MailSo\Mime\Enumerations\MessagePriority::LOW;
                     break;
             }
         }
         // ReadingConfirmation
         $this->sReadingConfirmation = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::DISPOSITION_NOTIFICATION_TO);
         if (0 === strlen($this->sReadingConfirmation)) {
             $this->sReadingConfirmation = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_CONFIRM_READING_TO);
         }
         $this->sReadingConfirmation = trim($this->sReadingConfirmation);
         $sDraftInfo = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_DRAFT_INFO);
         if (0 < strlen($sDraftInfo)) {
             $sType = '';
             $sFolder = '';
             $sUid = '';
             \MailSo\Mime\ParameterCollection::NewInstance($sDraftInfo)->ForeachList(function ($oParameter) use(&$sType, &$sFolder, &$sUid) {
                 switch (strtolower($oParameter->Name())) {
                     case 'type':
                         $sType = $oParameter->Value();
                         break;
                     case 'uid':
                         $sUid = $oParameter->Value();
                         break;
                     case 'folder':
                         $sFolder = base64_decode($oParameter->Value());
                         break;
                 }
             });
             if (0 < strlen($sType) && 0 < strlen($sFolder) && 0 < strlen($sUid)) {
                 $this->aDraftInfo = array($sType, $sUid, $sFolder);
             }
         }
         \CApi::Plugin()->RunHook('api-mail-message-headers-parse', array(&$this, $oHeaders));
     }
     if (is_array($aTextParts) && 0 < count($aTextParts)) {
         if (0 === \strlen($sCharset)) {
             $sCharset = \MailSo\Base\Enumerations\Charset::UTF_8;
         }
         $sHtmlParts = array();
         $sPlainParts = array();
         $iHtmlSize = 0;
         $iPlainSize = 0;
         foreach ($aTextParts as $oPart) {
             if ($oPart) {
                 if ('text/html ' === $oPart->ContentType()) {
                     $iHtmlSize += $oPart->EstimatedSize();
                 } else {
                     $iPlainSize += $oPart->EstimatedSize();
                 }
             }
             $sText = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::BODY . '[' . $oPart->PartID() . ('' !== $sRfc822SubMimeIndex && is_numeric($sRfc822SubMimeIndex) ? '.1' : '') . ']');
             //				if (null === $sText)
             //				{
             //					$sText = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::BODY.'['.$oPart->PartID().
             //						('' !== $sRfc822SubMimeIndex && is_numeric($sRfc822SubMimeIndex) ? '.1' : '').']<0>');
             //				}
             if (is_string($sText) && 0 < strlen($sText)) {
                 $sTextCharset = $oPart->Charset();
                 if (empty($sTextCharset)) {
                     $sTextCharset = $sCharset;
                 }
                 $sTextCharset = \MailSo\Base\Utils::NormalizeCharset($sTextCharset, true);
                 $sText = \MailSo\Base\Utils::DecodeEncodingValue($sText, $oPart->MailEncodingName());
                 $sText = \MailSo\Base\Utils::ConvertEncoding($sText, $sTextCharset, \MailSo\Base\Enumerations\Charset::UTF_8);
                 $sText = \MailSo\Base\Utils::Utf8Clear($sText);
                 if ('text/html' === $oPart->ContentType()) {
                     $sHtmlParts[] = $sText;
                 } else {
                     $sPlainParts[] = $sText;
                 }
             }
         }
         if (0 < count($sHtmlParts)) {
             $this->sHtml = trim(implode('<br />', $sHtmlParts));
             $this->iTextSize = strlen($this->sHtml);
         } else {
             $this->sPlain = trim(implode("\n", $sPlainParts));
             $this->iTextSize = strlen($this->sPlain);
         }
         if (0 === $this->iTextSize) {
             $this->iTextSize = 0 < $iHtmlSize ? $iHtmlSize : $iPlainSize;
         }
         unset($sHtmlParts, $sPlainParts);
     }
     if ($oBodyStructure) {
         $aAttachmentsParts = $oBodyStructure->SearchAttachmentsParts();
         if ($aAttachmentsParts && 0 < count($aAttachmentsParts)) {
             $this->oAttachments = CApiMailAttachmentCollection::NewInstance();
             foreach ($aAttachmentsParts as $oAttachmentItem) {
                 $this->oAttachments->Add(CApiMailAttachment::NewBodyStructureInstance($this->sFolder, $this->iUid, $oAttachmentItem));
             }
             $this->oAttachments->ForeachList(function ($oAttachment) use($aAscPartsIds, $oFetchResponse) {
                 if ($oAttachment && in_array($oAttachment->MimeIndex(), $aAscPartsIds)) {
                     $mContent = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::BODY . '[' . $oAttachment->MimeIndex() . ']');
                     if (is_string($mContent)) {
                         $oAttachment->SetContent(\MailSo\Base\Utils::DecodeEncodingValue($mContent, $oAttachment->ContentTransferEncoding()));
                     }
                 }
             });
         }
     }
     \CApi::Plugin()->RunHook('api-mail-message-parse', array(&$this, $oFetchResponse, $oBodyStructure, $sRfc822SubMimeIndex));
     return $this;
 }
Ejemplo n.º 24
0
 /**
  * @return bool
  */
 public function RawIframe()
 {
     $sEncodedUrl = $this->getParamValue('RawKey', '');
     $sUrl = urldecode($sEncodedUrl);
     $sUrl = trim(trim($sUrl), '/\\?');
     $aParts = null;
     if (!empty($sUrl)) {
         $aParts = explode('/', $sUrl);
     }
     if (is_array($aParts) && isset($aParts[0], $aParts[1], $aParts[2], $aParts[3])) {
         $aValues = \CApi::DecodeKeyValues($aParts[3]);
         if (isset($aValues['Iframed'], $aValues['Name'], $aValues['AccountID']) && (!isset($aValues['MimeType']) || !isset($aValues['FileName']))) {
             $aValues['FileName'] = $aValues['Name'];
             $aValues['MimeType'] = \api_Utils::MimeContentType($aValues['FileName']);
         }
         if (isset($aValues['Iframed'], $aValues['MimeType'], $aValues['FileName']) && $aValues['Iframed'] && \CApi::isIframedMimeTypeSupported($aValues['MimeType'], $aValues['FileName'])) {
             $oAccount = $this->getAccountFromParam(false);
             if ($oAccount) {
                 $sNewUrl = '';
                 $sNewHash = '';
                 $sResultUrl = '';
                 $aSubParts = \CApi::DecodeKeyValues($aParts[3]);
                 if (isset($aSubParts['Iframed']) && (int) $aParts[2] === (int) $oAccount->IdAccount && 0 < $oAccount->IdAccount) {
                     $aSubParts['Time'] = \time();
                     $sNewHash = \CApi::EncodeKeyValues($aSubParts);
                 }
                 if (!empty($sNewHash)) {
                     $aParts[3] = $sNewHash;
                     $sNewUrl = rtrim(trim($this->oHttp->GetFullUrl()), '/') . '/?/' . implode('/', $aParts);
                     \CApi::Plugin()->RunHook('webmail.filter.iframed-attachments-url', array(&$sResultUrl, $sNewUrl, $aValues['MimeType'], $aValues['FileName']));
                     if (empty($sResultUrl) && \CApi::GetConf('labs.allow-officeapps-viewer', true)) {
                         $sResultUrl = 'https://view.officeapps.live.com/op/view.aspx?src=' . urlencode($sNewUrl);
                     }
                 }
                 if (!empty($sResultUrl)) {
                     header('Content-Type: text/html', true);
                     echo '<html style="height: 100%; width: 100%; margin: 0; padding: 0"><head></head><body' . ' style="height: 100%; width: 100%; margin: 0; padding: 0">' . '<iframe style="height: 100%; width: 100%; margin: 0; padding: 0; border: 0" src="' . $sResultUrl . '"></iframe></body></html>';
                     return true;
                 }
             }
         }
     }
     return false;
 }
Ejemplo n.º 25
0
 /**
  * @param CAccount $oAccount
  * @param CGroup $oGroup
  * @param bool $bIsUpdate
  * @return array
  */
 private function getEntryFromGroup($oAccount, &$oGroup, $bIsUpdate)
 {
     $sId = $oGroup->IdGroup;
     if (!$bIsUpdate) {
         $sId = 'group' . md5($oGroup->Name . time() . rand(1000, 9999));
     }
     $oGroup->IdGroup = (string) $sId;
     $oGroup->IdGroupStr = $oGroup->IdGroup;
     $oGroup->IdUser = $oAccount->IdUser;
     $aE = array('cn' => $oGroup->Name, 'objectClass' => array('top', 'pabGroup'));
     $aE[$this->sGroupUidFieldName] = $oGroup->IdGroup;
     if ($bIsUpdate) {
         unset($aE['objectClass']);
     }
     CApi::Plugin()->RunHook('api-ldap-get-entry-from-group', array($oAccount, &$oGroup, &$aE, $bIsUpdate));
     return $aE;
 }
Ejemplo n.º 26
0
 /**
  * Updates calendar user settings.
  * 
  * @api
  * 
  * @param CCalUser $oCalUser CCalUser object.
  * 
  * @return bool
  */
 public function updateCalUser(CCalUser $oCalUser)
 {
     $bResult = false;
     try {
         if ($oCalUser->isValid()) {
             $bUseOnlyHookUpdate = false;
             CApi::Plugin()->RunHook('api-update-cal-user', array(&$oCalUser, &$bUseOnlyHookUpdate));
             if (!$bUseOnlyHookUpdate) {
                 if (!$this->oStorage->updateCalUser($oCalUser)) {
                     $this->moveStorageExceptionToManager();
                     throw new CApiManagerException(Errs::UserManager_CalUserUpdateFailed);
                 }
             }
         }
         $bResult = true;
     } catch (CApiBaseException $oException) {
         $bResult = false;
         $this->setLastException($oException);
     }
     return $bResult;
 }
Ejemplo n.º 27
0
 /**
  * @param \CAccount $oAccount
  * @return string
  */
 public function generateXMLProfile($oAccount)
 {
     $mResult = false;
     if ($oAccount) {
         $oDomImplementation = new DOMImplementation();
         $oDocumentType = $oDomImplementation->createDocumentType('plist', '-//Apple//DTD PLIST 1.0//EN', 'http://www.apple.com/DTDs/PropertyList-1.0.dtd');
         $oXmlDocument = $oDomImplementation->createDocument('', '', $oDocumentType);
         $oXmlDocument->xmlVersion = '1.0';
         $oXmlDocument->encoding = 'UTF-8';
         $oXmlDocument->formatOutput = true;
         $oPlist = $oXmlDocument->createElement('plist');
         $oPlist->setAttribute('version', '1.0');
         $sPayloadId = $this->oApiDavManager ? 'afterlogic.' . $this->oApiDavManager->getServerHost($oAccount) : '';
         $aPayload = array('PayloadVersion' => 1, 'PayloadUUID' => \Sabre\DAV\UUIDUtil::getUUID(), 'PayloadType' => 'Configuration', 'PayloadRemovalDisallowed' => false, 'PayloadIdentifier' => $sPayloadId, 'PayloadOrganization' => $oAccount->Domain->SiteName, 'PayloadDescription' => $oAccount->Domain->SiteName . ' Mobile', 'PayloadDisplayName' => $oAccount->Domain->SiteName . ' Mobile Profile');
         $oArrayElement = $oXmlDocument->createElement('array');
         $bIsDemo = false;
         \CApi::Plugin()->RunHook('plugin-is-demo-account', array(&$oAccount, &$bIsDemo));
         if (!$bIsDemo) {
             $aInfo = $this->oApiUsersManager->getUserAccounts($oAccount->IdUser);
             if (is_array($aInfo) && 0 < count($aInfo)) {
                 foreach (array_keys($aInfo) as $iIdAccount) {
                     if ($oAccount->IdAccount === $iIdAccount) {
                         $oAccountItem = $oAccount;
                     } else {
                         $oAccountItem = $this->oApiUsersManager->getAccountById($iIdAccount);
                     }
                     $oEmailDictElement = $this->_generateEmailDict($oXmlDocument, $sPayloadId, $oAccountItem, $bIsDemo);
                     if ($oEmailDictElement === false) {
                         return false;
                     } else {
                         $oArrayElement->appendChild($oEmailDictElement);
                     }
                     unset($oAccountItem);
                     unset($oEmailDictElement);
                 }
             } else {
                 return false;
             }
         }
         // Calendars
         $oCaldavDictElement = $this->_generateCaldavDict($oXmlDocument, $sPayloadId, $oAccount, $bIsDemo);
         $oArrayElement->appendChild($oCaldavDictElement);
         // Contacts
         $oCarddavDictElement = $this->_generateCarddavDict($oXmlDocument, $sPayloadId, $oAccount, $bIsDemo);
         $oArrayElement->appendChild($oCarddavDictElement);
         $oDictElement = $this->_generateDict($oXmlDocument, $aPayload);
         $oPayloadContentElement = $oXmlDocument->createElement('key', 'PayloadContent');
         $oDictElement->appendChild($oPayloadContentElement);
         $oDictElement->appendChild($oArrayElement);
         $oPlist->appendChild($oDictElement);
         $oXmlDocument->appendChild($oPlist);
         $mResult = $oXmlDocument->saveXML();
     }
     return $mResult;
 }
Ejemplo n.º 28
0
 /**
  * @param string $sEmail
  * @param string $sPassword
  * @param string $sChangeLang = ''
  * @param array $aExtValues = null
  * @param bool $bAllowInternalOnly = false
  * @return CAccount | false
  */
 public function CreateAccountProcess($sEmail, $sPassword, $sChangeLang = '', $aExtValues = null, $bAllowInternalOnly = false)
 {
     $mResult = false;
     try {
         /* @var $oApiDomainsManager CApiDomainsManager */
         $oApiDomainsManager = CApi::Manager('domains');
         /* @var $oApiUsersManager CApiUsersManager */
         $oApiUsersManager = CApi::Manager('users');
         $sDomainName = api_Utils::GetDomainFromEmail($sEmail);
         $oDomain = $oApiDomainsManager->GetDomainByName($sDomainName);
         if (!$oDomain) {
             $oDomain = $oApiDomainsManager->GetDefaultDomain();
         }
         $bApiIntegratorLoginToAccountResult = isset($aExtValues['ApiIntegratorLoginToAccountResult']) ? $aExtValues['ApiIntegratorLoginToAccountResult'] : false;
         if ($oDomain && ($bApiIntegratorLoginToAccountResult || $oDomain->AllowNewUsersRegister || $oDomain->IsInternal && $bAllowInternalOnly || 'nodb' === CApi::GetManager()->GetStorageByType('webmail'))) {
             /*if ($oDomain && !$oDomain->AllowWebMail)
             		{
             			throw new CApiManagerException(Errs::WebMailManager_AccountWebmailDisabled);
             		}
             		else */
             if ($oDomain && $oDomain->IsInternal && !$bAllowInternalOnly) {
                 throw new CApiManagerException(Errs::WebMailManager_NewUserRegistrationDisabled);
             } else {
                 if ($oDomain && $bAllowInternalOnly && (!$oDomain->IsInternal || $oDomain->IsDefaultDomain)) {
                     throw new CApiManagerException(Errs::WebMailManager_NewUserRegistrationDisabled);
                 } else {
                     if ($oDomain) {
                         $oAccountToCreate = new CAccount($oDomain);
                         $oAccountToCreate->Email = $sEmail;
                         //					$oAccountToCreate->IncomingMailLogin = (isset($aExtValues['Login'])) ? $aExtValues['Login'] :
                         //						(($this->oSettings->GetConf('WebMail/UseLoginWithoutDomain'))
                         //							? api_Utils::GetAccountNameFromEmail($sEmail) : $sEmail);
                         $oAccountToCreate->IncomingMailLogin = isset($aExtValues['Login']) ? $aExtValues['Login'] : $sEmail;
                         if ($this->oSettings->GetConf('WebMail/UseLoginWithoutDomain')) {
                             $oAccountToCreate->IncomingMailLogin = api_Utils::GetAccountNameFromEmail($oAccountToCreate->IncomingMailLogin);
                         }
                         $oAccountToCreate->IncomingMailPassword = $sPassword;
                         if (0 < strlen($sChangeLang) && $sChangeLang !== $oAccountToCreate->User->DefaultLanguage) {
                             $oAccountToCreate->User->DefaultLanguage = $sChangeLang;
                         }
                         if ($oDomain->IsDefaultDomain && isset($aExtValues['IncProtocol'], $aExtValues['IncHost'], $aExtValues['IncPort'], $aExtValues['OutHost'], $aExtValues['OutPort'], $aExtValues['OutAuth'])) {
                             $oAccountToCreate->IncomingMailProtocol = (int) $aExtValues['IncProtocol'];
                             $oAccountToCreate->IncomingMailServer = trim($aExtValues['IncHost']);
                             $oAccountToCreate->IncomingMailPort = (int) trim($aExtValues['IncPort']);
                             $oAccountToCreate->OutgoingMailServer = trim($aExtValues['OutHost']);
                             $oAccountToCreate->OutgoingMailPort = (int) trim($aExtValues['OutPort']);
                             $oAccountToCreate->OutgoingMailAuth = (bool) $aExtValues['OutAuth'] ? ESMTPAuthType::AuthCurrentUser : ESMTPAuthType::NoAuth;
                             // TODO
                             $oAccountToCreate->IncomingMailUseSSL = in_array($oAccountToCreate->IncomingMailPort, array(993, 995));
                             $oAccountToCreate->OutgoingMailUseSSL = in_array($oAccountToCreate->OutgoingMailPort, array(465));
                         }
                         CApi::Plugin()->RunHook('api-pre-create-account-process-call', array(&$oAccountToCreate));
                         if (isset($aExtValues['FriendlyName'])) {
                             $oAccountToCreate->FriendlyName = $aExtValues['FriendlyName'];
                         }
                         if (isset($aExtValues['Question1'])) {
                             $oAccountToCreate->User->Question1 = $aExtValues['Question1'];
                         }
                         if (isset($aExtValues['Question2'])) {
                             $oAccountToCreate->User->Question2 = $aExtValues['Question2'];
                         }
                         if (isset($aExtValues['Answer1'])) {
                             $oAccountToCreate->User->Answer1 = $aExtValues['Answer1'];
                         }
                         if (isset($aExtValues['Answer2'])) {
                             $oAccountToCreate->User->Answer2 = $aExtValues['Answer2'];
                         }
                         if ($oApiUsersManager->CreateAccount($oAccountToCreate, !($oAccountToCreate->IsInternal || !$oAccountToCreate->Domain->AllowWebMail || $bApiIntegratorLoginToAccountResult))) {
                             CApi::Plugin()->RunHook('api-success-post-create-account-process-call', array(&$oAccountToCreate));
                             $mResult = $oAccountToCreate;
                         } else {
                             $oException = $oApiUsersManager->GetLastException();
                             CApi::Plugin()->RunHook('api-error-post-create-account-process-call', array(&$oAccountToCreate, &$oException));
                             throw is_object($oException) ? $oException : new CApiManagerException(Errs::WebMailManager_AccountCreateOnLogin);
                         }
                     } else {
                         throw new CApiManagerException(Errs::WebMailManager_DomainDoesNotExist);
                     }
                 }
             }
         } else {
             throw new CApiManagerException(Errs::WebMailManager_NewUserRegistrationDisabled);
         }
     } catch (CApiBaseException $oException) {
         $mResult = false;
         $this->setLastException($oException);
     }
     return $mResult;
 }
Ejemplo n.º 29
0
 public function AjaxExternalFileStorages()
 {
     $oAccount = $this->getDefaultAccountFromParam();
     if (!$this->oApiCapability->IsFilesSupported($oAccount)) {
         throw new \ProjectSeven\Exceptions\ClientException(\ProjectSeven\Notifications::FilesNotAllowed);
     }
     $oResult = array();
     \CApi::Plugin()->RunHook('filestorage.get-external-storages', array($oAccount, &$oResult));
     return $this->DefaultResponse($oAccount, __FUNCTION__, $oResult);
 }
Ejemplo n.º 30
0
 /**
  * @param string $sName = ''
  * @param string $sUrl = null
  * @param int $iTenantId = 0
  */
 public function __construct($sName = '', $sUrl = null, $iTenantId = 0)
 {
     parent::__construct(get_class($this), 'IdDomain');
     $oSettings =& CApi::GetSettings();
     $aDefaults = array('IdDomain' => 0, 'IdTenant' => $iTenantId, 'IsDisabled' => false, 'Name' => trim($sName), 'Url' => null === $sUrl ? '' : trim($sUrl), 'IsDefaultDomain' => false, 'IsDefaultTenantDomain' => false, 'IsInternal' => false, 'UseThreads' => true, 'OverrideSettings' => true);
     $aSettingsMap = $this->GetSettingsMap();
     foreach ($aSettingsMap as $sProperty => $sSettingsName) {
         $aDefaults[$sProperty] = $oSettings->GetConf($sSettingsName);
     }
     $this->__USE_TRIM_IN_STRINGS__ = true;
     $this->SetDefaults($aDefaults);
     $this->aFolders = array(EFolderType::Inbox => array('INBOX', 'Inbox'), EFolderType::Drafts => array('Drafts', 'Draft'), EFolderType::Sent => array('Sent', 'Sent Items', 'Sent Mail'), EFolderType::Spam => array('Spam', 'Junk', 'Junk Mail', 'Junk E-mail', 'Bulk Mail'), EFolderType::Trash => array('Trash', 'Bin', 'Deleted', 'Deleted Items'));
     $this->SetLower(array('Name', 'IncomingMailServer', 'OutgoingMailServer'));
     CApi::Plugin()->RunHook('api-domain-construct', array(&$this));
 }