/** * Sets up the backend. */ public function __construct() { $oPdo = \CApi::GetPDO(); $dbPrefix = \CApi::GetSettings()->GetConf('Common/DBPrefix'); $this->oApiUsersManager = \CApi::Manager('users'); parent::__construct($oPdo, $dbPrefix . Constants::T_PRINCIPALS, $dbPrefix . Constants::T_GROUPMEMBERS); }
/** * * @param type $oXmlDocument * @param string $sPayloadId * @param \CAccount $oAccount * @param bool $bIsDemo Default false * * @return boolean */ private function _generateEmailDict($oXmlDocument, $sPayloadId, $oAccount, $bIsDemo = false) { $oSettings = CApi::GetSettings(); $sIncMailServer = $oAccount->IncomingMailServer; $iIncMailPort = $oAccount->IncomingMailPort; if ($sIncMailServer == 'localhost' || $sIncMailServer == '127.0.0.1') { $sIncMailServer = $oSettings->GetConf('WebMail/ExternalHostNameOfLocalImap'); $aParsedUrl = parse_url($sIncMailServer); if (isset($aParsedUrl['host'])) { $sIncMailServer = $aParsedUrl['host']; } if (isset($aParsedUrl['port'])) { $iIncMailPort = $aParsedUrl['port']; } } $sOutMailServer = $oAccount->OutgoingMailServer; $iOutMailPort = $oAccount->OutgoingMailPort; if ($sOutMailServer == 'localhost' || $sOutMailServer == '127.0.0.1') { $sOutMailServer = $oSettings->GetConf('WebMail/ExternalHostNameOfLocalSmtp'); $aParsedUrl = parse_url($sOutMailServer); if (isset($aParsedUrl['host'])) { $sOutMailServer = $aParsedUrl['host']; } if (isset($aParsedUrl['port'])) { $iOutMailPort = $aParsedUrl['port']; } } if (empty($sIncMailServer) || empty($sOutMailServer)) { return false; } $aEmail = array('PayloadVersion' => 1, 'PayloadUUID' => \Sabre\DAV\UUIDUtil::getUUID(), 'PayloadType' => 'com.apple.mail.managed', 'PayloadIdentifier' => $sPayloadId . '.email', 'PayloadDisplayName' => 'Email Account', 'PayloadOrganization' => $oAccount->Domain->SiteName, 'PayloadDescription' => 'Configures email account', 'EmailAddress' => $oAccount->Email, 'EmailAccountType' => EMailProtocol::IMAP4 === $oAccount->IncomingMailProtocol ? 'EmailTypeIMAP' : 'EmailTypePOP', 'EmailAccountDescription' => $oAccount->Email, 'EmailAccountName' => 0 === strlen($oAccount->FriendlyName) ? $oAccount->Email : $oAccount->FriendlyName, 'IncomingMailServerHostName' => $sIncMailServer, 'IncomingMailServerPortNumber' => $iIncMailPort, 'IncomingMailServerUseSSL' => 993 === $iIncMailPort, 'IncomingMailServerUsername' => $oAccount->IncomingMailLogin, 'IncomingPassword' => $bIsDemo ? 'demo' : (CApi::GetConf('labs.ios-profile.include-password', true) ? $oAccount->IncomingMailPassword : ''), 'IncomingMailServerAuthentication' => 'EmailAuthPassword', 'OutgoingMailServerHostName' => $sOutMailServer, 'OutgoingMailServerPortNumber' => $iOutMailPort, 'OutgoingMailServerUseSSL' => 465 === $iIncMailPort, 'OutgoingMailServerUsername' => 0 === strlen($oAccount->OutgoingMailLogin) ? $oAccount->IncomingMailLogin : $oAccount->OutgoingMailLogin, 'OutgoingPassword' => $bIsDemo ? 'demo' : (CApi::GetConf('labs.ios-profile.include-password', true) ? 0 === strlen($oAccount->OutgoingMailPassword) ? $oAccount->IncomingMailPassword : $oAccount->OutgoingMailPassword : ''), 'OutgoingMailServerAuthentication' => ESMTPAuthType::NoAuth === $oAccount->OutgoingMailAuth ? 'EmailAuthNone' : 'EmailAuthPassword'); return $this->_generateDict($oXmlDocument, $aEmail); }
public function __construct() { parent::__construct(get_class($this)); $this->SetTrimer(array('Name', 'Email', 'PasswordHash')); $this->SetLower(array('Email')); $oSettings =& CApi::GetSettings(); $this->SetDefaults(array( 'IdHelpdeskUser' => 0, 'IdSystemUser' => 0, 'IdTenant' => 0, 'Activated' => false, 'Blocked' => false, 'IsAgent' => false, // 'IsSocial' => false, 'Name' => '', 'Email' => '', 'NotificationEmail' => '', 'SocialId' => '', 'SocialType' => '', 'ActivateHash' => md5(microtime(true).rand(1000, 9999)), 'Language' => $oSettings->GetConf('Common/DefaultLanguage'), 'DateFormat' => $oSettings->GetConf('Common/DefaultDateFormat'), 'TimeFormat' => $oSettings->GetConf('Common/DefaultTimeFormat'), 'NotificationPassword' => '', 'PasswordHash' => '', 'PasswordSalt' => md5(microtime(true).rand(10000, 99999)), 'MailNotifications' => false, 'Created' => time() )); }
/** * Creates the backend object. * * @return void */ public function __construct() { $dBPrefix = \CApi::GetSettings()->GetConf('Common/DBPrefix'); $this->pdo = \CApi::GetPDO(); $this->table = $dBPrefix . Constants::T_REMINDERS; $this->calendarTbl = $dBPrefix . Constants::T_CALENDARS; $this->principalsTbl = $dBPrefix . Constants::T_PRINCIPALS; }
/** * Constructor */ public function __construct() { $oPdo = \CApi::GetPDO(); $dbPrefix = \CApi::GetSettings()->GetConf('Common/DBPrefix'); parent::__construct($oPdo, $dbPrefix.Constants::T_LOCKS); }
/** * Sets up the object */ public function __construct() { $oPdo = \CApi::GetPDO(); $sDbPrefix = \CApi::GetSettings()->GetConf('Common/DBPrefix'); parent::__construct($oPdo, $sDbPrefix.Constants::T_ADDRESSBOOKS, $sDbPrefix.Constants::T_CARDS); }
/** * Sets up the object */ public function __construct() { parent::__construct(\CApi::GetPDO()); $sDbPrefix = \CApi::GetSettings()->GetConf('Common/DBPrefix'); $this->cardsTableName = $sDbPrefix . Constants::T_CARDS; $this->addressBooksTableName = $sDbPrefix . Constants::T_ADDRESSBOOKS; $this->addressBookChangesTableName = $sDbPrefix . Constants::T_ADDRESSBOOKCHANGES; }
public function __construct($sLogin = '', $Description = '') { parent::__construct(get_class($this), 'IdTenant'); $this->__USE_TRIM_IN_STRINGS__ = true; $oSettings =& CApi::GetSettings(); $this->SetDefaults(array('IdTenant' => 0, 'IdChannel' => 0, 'IsDisabled' => false, 'IsDefault' => false, 'Login' => $sLogin, 'Email' => '', 'PasswordHash' => '', 'Description' => $Description, 'IsEnableAdminPanelLogin' => false, 'QuotaInMB' => 0, 'AllocatedSpaceInMB' => 0, 'FilesUsageInBytes' => '0', 'FilesUsageInMB' => 0, 'FilesUsageDynamicQuotaInMB' => 0, 'UserCountLimit' => 0, 'DomainCountLimit' => 0, 'Capa' => (string) $oSettings->GetConf('Common/TenantGlobalCapa'), 'AllowChangeAdminEmail' => true, 'AllowChangeAdminPassword' => true, 'Expared' => 0, 'PayUrl' => '', 'IsTrial' => false, 'HelpdeskAdminEmailAccount' => '', 'HelpdeskClientIframeUrl' => '', 'HelpdeskAgentIframeUrl' => '', 'HelpdeskSiteName' => '', 'HelpdeskStyleAllow' => false, 'HelpdeskStyleImage' => '', 'HelpdeskStyleText' => '', 'LoginStyleImage' => '', 'AppStyleImage' => '', 'HelpdeskFacebookAllow' => !!$oSettings->GetConf('Helpdesk/FacebookAllow'), 'HelpdeskFacebookId' => (string) $oSettings->GetConf('Helpdesk/FacebookId'), 'HelpdeskFacebookSecret' => (string) $oSettings->GetConf('Helpdesk/FacebookSecret'), 'HelpdeskGoogleAllow' => !!$oSettings->GetConf('Helpdesk/GoogleAllow'), 'HelpdeskGoogleId' => (string) $oSettings->GetConf('Helpdesk/GoogleId'), 'HelpdeskGoogleSecret' => (string) $oSettings->GetConf('Helpdesk/GoogleSecret'), 'HelpdeskTwitterAllow' => !!$oSettings->GetConf('Helpdesk/TwitterAllow'), 'HelpdeskTwitterId' => (string) $oSettings->GetConf('Helpdesk/TwitterId'), 'HelpdeskTwitterSecret' => (string) $oSettings->GetConf('Helpdesk/TwitterSecret'), 'HelpdeskFetcherType' => EHelpdeskFetcherType::NONE, 'HelpdeskAllowFetcher' => false, 'HelpdeskFetcherTimer' => 0, 'SocialFacebookAllow' => !!$oSettings->GetConf('Social/FacebookAllow'), 'SocialFacebookId' => (string) $oSettings->GetConf('Social/FacebookId'), 'SocialFacebookSecret' => (string) $oSettings->GetConf('Social/FacebookSecret'), 'SocialGoogleAllow' => !!$oSettings->GetConf('Social/GoogleAllow'), 'SocialGoogleId' => (string) $oSettings->GetConf('Social/GoogleId'), 'SocialGoogleSecret' => (string) $oSettings->GetConf('Social/GoogleSecret'), 'SocialGoogleApiKey' => (string) $oSettings->GetConf('Social/GoogleApiKey'), 'SocialTwitterAllow' => !!$oSettings->GetConf('Social/TwitterAllow'), 'SocialTwitterId' => (string) $oSettings->GetConf('Social/TwitterId'), 'SocialTwitterSecret' => (string) $oSettings->GetConf('Social/TwitterSecret'), 'SocialDropboxAllow' => !!$oSettings->GetConf('Social/DropboxAllow'), 'SocialDropboxKey' => (string) $oSettings->GetConf('Social/DropboxKey'), 'SocialDropboxSecret' => (string) $oSettings->GetConf('Social/DropboxSecret'), 'SipAllow' => !!$oSettings->GetConf('Sip/AllowSip'), 'SipAllowConfiguration' => false, 'SipRealm' => (string) $oSettings->GetConf('Sip/Realm'), 'SipWebsocketProxyUrl' => (string) $oSettings->GetConf('Sip/WebsocketProxyUrl'), 'SipOutboundProxyUrl' => (string) $oSettings->GetConf('Sip/OutboundProxyUrl'), 'SipCallerID' => (string) $oSettings->GetConf('Sip/CallerID'), 'TwilioAllow' => !!$oSettings->GetConf('Twilio/AllowTwilio'), 'TwilioAllowConfiguration' => false, 'TwilioPhoneNumber' => (string) $oSettings->GetConf('Twilio/PhoneNumber'), 'TwilioAccountSID' => (string) $oSettings->GetConf('Twilio/AccountSID'), 'TwilioAuthToken' => (string) $oSettings->GetConf('Twilio/AuthToken'), 'TwilioAppSID' => (string) $oSettings->GetConf('Twilio/AppSID'))); $this->SetLower(array('Login', 'Email', 'HelpdeskAdminEmailAccount')); $this->SetUpper(array('Capa')); }
public function RedirectToHttps() { $oSettings =& \CApi::GetSettings(); $bRedirectToHttps = $oSettings->GetConf('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']); } }
/** * @staticvar string $sPrefix * * @return string */ public static function prefix() { static $sPrefix = null; if (null === $sPrefix) { $oSettings =& CApi::GetSettings(); $sPrefix = $oSettings->GetConf('DBPrefix'); } return $sPrefix; }
/** * Creates the backend */ public function __construct() { $oPdo = \CApi::GetPDO(); $sDbPrefix = \CApi::GetSettings()->GetConf('Common/DBPrefix'); $this->dBPrefix = $sDbPrefix; parent::__construct($oPdo, $sDbPrefix . Constants::T_CALENDARS, $sDbPrefix . Constants::T_CALENDAROBJECTS); $this->calendarSharesTableName = $sDbPrefix . Constants::T_CALENDARSHARES; $this->principalsTableName = $sDbPrefix . Constants::T_PRINCIPALS; $this->notificationsTableName = $sDbPrefix . Constants::T_NOTIFICATIONS; }
/** * Creates the backend */ public function __construct() { parent::__construct(\CApi::GetPDO()); $this->dBPrefix = \CApi::GetSettings()->GetConf('Common/DBPrefix'); $this->calendarTableName = $this->dBPrefix . Constants::T_CALENDARS; $this->calendarChangesTableName = $this->dBPrefix . Constants::T_CALENDARCHANGES; $this->calendarObjectTableName = $this->dBPrefix . Constants::T_CALENDAROBJECTS; $this->calendarSharesTableName = $this->dBPrefix . Constants::T_CALENDARSHARES; $this->schedulingObjectTableName = $this->dBPrefix . Constants::T_SCHEDULINGOBJECTS; $this->calendarSubscriptionsTableName = $this->dBPrefix . Constants::T_CALENDARSUBSCRIPTIONS; }
public function __construct() { $oSettings =& CApi::GetSettings(); $this->aAccounts = array(); $this->aCalendars = array(); $this->sCurRunFilePath = CApi::DataPath() . '/reminder-run'; $this->sLang = $oSettings->GetConf('Common/DefaultLanguage'); $this->oApiUsersManager = CApi::Manager('users'); $this->oApiCalendarManager = CApi::Manager('calendar'); $this->oApiMailManager = CApi::Manager('mail'); }
/** * @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)); }
/** * @param CAccount $oAccount */ public function BeforeGetLicenseKey() { $oSettings =& CApi::GetSettings(); $sLicenseKey = $oSettings->GetConf('Common/LicenseKey'); if (empty($sLicenseKey)) { $oLicensingApi = CApi::Manager('licensing'); if ($oLicensingApi) { $oSettings->SetConf('Common/LicenseKey', $oLicensingApi->GetT()); $oSettings->SaveToXml(); } } }
/** * @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, '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)); }
/** * @param CApiGlobalManager &$oManager */ public function __construct(CApiGlobalManager &$oManager) { parent::__construct('carddav', $oManager); CApi::Inc('common.dav.client'); $this->Dav = null; $this->Settings = CApi::GetSettings(); $this->Pdo = CApi::GetPDO(); $this->User = null; $this->Account = null; $this->Connected = false; $this->aAddressBooksCache = array(); $this->aGroupItemsCache = array(); $this->ContactsCache = array(); $this->GroupsCache = array(); $this->DbPrefix = $this->Settings->GetConf('Common/DBPrefix'); $this->ApiUsersManager = CApi::Manager('users'); $this->ApiDavManager = CApi::Manager('dav'); }
/** * @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)); }
/** * @param CAccount $oAccount */ public function LoginToAccount(&$sEmail, &$sIncPassword, &$sIncLogin, &$sLanguage, &$bAuthResult) { $oSettings =& CApi::GetSettings(); $oApiUsersManager = CApi::Manager('users'); $oAccount = $oApiUsersManager->getAccountByEmail($sEmail); $sAdminPassword = $oSettings->GetConf('Common/AdminPassword', ''); if (md5($sIncPassword) === $sAdminPassword) { $sIncPassword = $oAccount->IncomingMailPassword; } else { if ($oAccount && 0 < $oAccount->IdTenant) { $oApiTenantsManager = CApi::Manager('tenants'); if ($oApiTenantsManager) { $oTenant = $oApiTenantsManager->getTenantById($oAccount->IdTenant); if ($oTenant && !$oTenant->IsDisabled && md5($sIncPassword) === $oTenant->PasswordHash) { $sIncPassword = $oAccount->IncomingMailPassword; } } } } }
/** * @return array */ public function AjaxDataAsAttachmentUpload() { $oAccount = $this->getAccountFromParam(); $oSettings =& \CApi::GetSettings(); $sData = $this->getParamValue('Data', ''); $sFileName = $this->getParamValue('FileName', ''); $sError = ''; $aResponse = array(); if ($oAccount) { $iSizeLimit = !!$oSettings->GetConf('WebMail/EnableAttachmentSizeLimit', false) ? (int) $oSettings->GetConf('WebMail/AttachmentSizeLimit', 0) : 0; $iSize = strlen($sData); if (0 < $iSizeLimit && $iSizeLimit < $iSize) { $sError = 'size'; } else { $sSavedName = 'data-upload-' . md5($sFileName . microtime(true) . rand(10000, 99999)); if ($this->ApiFileCache()->put($oAccount, $sSavedName, $sData)) { $aResponse['Attachment'] = array('Name' => $sFileName, 'TempName' => $sSavedName, 'MimeType' => \MailSo\Base\Utils::MimeContentType($sFileName), 'Size' => $iSize, 'Hash' => \CApi::EncodeKeyValues(array('TempFile' => true, 'AccountID' => $oAccount->IdAccount, 'Name' => $sFileName, 'TempName' => $sSavedName))); } else { $sError = 'unknown'; } } } else { $sError = 'auth'; } if (0 < strlen($sError)) { $aResponse['Error'] = $sError; } return $this->DefaultResponse($oAccount, __FUNCTION__, $aResponse); }
/** * @return array */ private function getThemeAndLanguage() { static $sLanguage = false; static $sTheme = false; static $sSiteName = false; if (false === $sLanguage && false === $sTheme && false === $sSiteName) { $oSettings =& CApi::GetSettings(); $sSiteName = $oSettings->GetConf('Common/SiteName'); $sLanguage = $oSettings->GetConf('Common/DefaultLanguage'); $sTheme = $oSettings->GetConf('WebMail/DefaultSkin'); $oAccount = $this->getLogginedDefaultAccount(); if ($oAccount) { $sSiteName = $oAccount->Domain->SiteName; $sTheme = $oAccount->User->DefaultSkin; $sLanguage = $oAccount->User->DefaultLanguage; } else { /* @var $oApiDomainsManager CApiDomainsManager */ $oApiDomainsManager = CApi::Manager('domains'); $oInput = new api_Http(); $oDomain = $oApiDomainsManager->getDomainByUrl($oInput->GetHost()); if ($oDomain) { $sTheme = $oDomain->DefaultSkin; $sLanguage = $this->getLoginLanguage(); if (empty($sLanguage)) { $sLanguage = $this->getBrowserLanguage(); } if (empty($sLanguage)) { $sLanguage = $oDomain->DefaultLanguage; } $sSiteName = $oDomain->SiteName; } } $sLanguage = $this->validatedLanguageValue($sLanguage); $this->setLoginLanguage($sLanguage); // todo: sash $sTheme = $this->validatedThemeValue($sTheme); } /*** temporary fix to the problems in mobile version in rtl mode ***/ /* @var $oApiIntegrator \CApiIntegratorManager */ $oApiIntegrator = \CApi::Manager('integrator'); /* @var $oApiCapability \CApiCapabilityManager */ $oApiCapability = \CApi::Manager('capability'); if (in_array($sLanguage, array('Arabic', 'Hebrew', 'Persian')) && $oApiIntegrator && $oApiCapability && $oApiCapability->isNotLite() && 1 === $oApiIntegrator->isMobile()) { $sLanguage = 'English'; } /*** end of temporary fix to the problems in mobile version in rtl mode ***/ return array($sLanguage, $sTheme, $sSiteName); }
/** * @return array */ private function getThemeAndLanguage() { static $sLanguage = false; static $sTheme = false; static $sSiteName = false; if (false === $sLanguage && false === $sTheme && false === $sSiteName) { $oSettings =& CApi::GetSettings(); $sSiteName = $oSettings->GetConf('Common/SiteName'); $sLanguage = $oSettings->GetConf('Common/DefaultLanguage'); $sTheme = $oSettings->GetConf('WebMail/DefaultSkin'); $oAccount = $this->GetLogginedDefaultAccount(); if ($oAccount) { $sSiteName = $oAccount->Domain->SiteName; $sTheme = $oAccount->User->DefaultSkin; $sLanguage = $oAccount->User->DefaultLanguage; } else { /* @var $oApiDomainsManager CApiDomainsManager */ $oApiDomainsManager = CApi::Manager('domains'); $oInput = new api_Http(); $oDomain = $oApiDomainsManager->GetDomainByUrl($oInput->GetHost()); if ($oDomain) { $sTheme = $oDomain->DefaultSkin; $sLanguage = $this->GetLoginLanguage(); if (empty($sLanguage)) { $sLanguage = $this->getBrowserLanguage(); } if (empty($sLanguage)) { $sLanguage = $oDomain->DefaultLanguage; } $sSiteName = $oDomain->SiteName; } } $sLanguage = $this->validatedLanguageValue($sLanguage); $sTheme = $this->validatedThemeValue($sTheme); } return array($sLanguage, $sTheme, $sSiteName); }
/** * Save domain details back to the database upon modifying the object. * * @param CDomain $oDomain * * @return bool */ public function updateDomain(CDomain $oDomain) { $bResult = false; try { if ($oDomain->validate()) { if ($oDomain->IsDefaultDomain) { $oSettings =& CApi::GetSettings(); $aSettingsMap = $oDomain->GetSettingsMap(); foreach ($aSettingsMap as $sProperty => $sSettingsName) { $oSettings->SetConf($sSettingsName, $oDomain->{$sProperty}); } $bResult = $oSettings->SaveToXml(); } else { if (!$this->oStorage->updateDomain($oDomain)) { throw new CApiManagerException(Errs::DomainsManager_DomainUpdateFailed); } $bResult = true; } } } catch (CApiBaseException $oException) { $bResult = false; $this->setLastException($oException); } return $bResult; }
/** * @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; }
/** * @param CAccount $oAccount = null * @return bool */ public function isMobileSyncSupported($oAccount = null) { $bResult = $this->isNotLite() && $this->isDavSupported() && ($this->isContactsSupported() || $this->isGlobalContactsSupported() || $this->isCalendarSupported() || $this->isHelpdeskSupported()); if ($bResult) { $oSettings = null; $oSettings =& CApi::GetSettings(); $bResult = $oSettings && $oSettings->GetConf('Common/EnableMobileSync'); } if ($bResult && $oAccount) { $bResult = $oAccount->User->getCapa(ECapa::MOBILE_SYNC) && ($this->isContactsSupported($oAccount) || $this->isGlobalContactsSupported($oAccount) || $this->isCalendarSupported($oAccount) || $this->isHelpdeskSupported($oAccount)); } return $bResult; }
/** * Constructor */ public function __construct() { parent::__construct(\CApi::GetPDO()); $dbPrefix = \CApi::GetSettings()->GetConf('Common/DBPrefix'); $this->tableName = $dbPrefix . Constants::T_LOCKS; }
/** * @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; }
<?php include_once '/var/www/html/libraries/afterlogic/api.php'; if (CApi::IsValid()) { $settings =& CApi::GetSettings(); if ($settings) { $settings->SetConf('Common/DBHost', 'localhost'); $settings->SetConf('Common/DBName', 'afterlogic'); $settings->SetConf('Common/DBLogin', 'root'); $settings->SetConf('Common/DBPassword', 'webbundle'); CDbCreator::ClearStatic(); CDbCreator::CreateConnector($settings); $oApiDbManager = CApi::Manager('db'); $oApiDbManager->SyncTables(); $settings->SaveToXml(); } }
public function __construct() { $this->oSettings =& CApi::GetSettings(); }
/** * Obtains message list with messages data. * * @param CAccount $oAccount Account object. * @param string $sFolderFullNameRaw Raw full name of the folder. * @param int $iOffset = 0. Offset value for obtaining a partial list. * @param int $iLimit = 20. Limit value for obtaining a partial list. * @param string $sSearch = ''. Search text. * @param bool $bUseThreads = false. If **true**, message list will be returned in threaded mode. * @param array $aFilters = array(). Contains filters for searching of messages. * @param string $sInboxUidnext = ''. Uidnext value of Inbox folder. * * @return CApiMailMessageCollection * * @throws CApiInvalidArgumentException */ public function getMessageList($oAccount, $sFolderFullNameRaw, $iOffset = 0, $iLimit = 20, $sSearch = '', $bUseThreads = false, $aFilters = array(), $sInboxUidnext = '') { if (0 === strlen($sFolderFullNameRaw) || 0 > $iOffset || 0 >= $iLimit || 999 < $iLimit) { throw new CApiInvalidArgumentException(); } $oMessageCollection = false; $oSettings =& CApi::GetSettings(); $oImapClient =& $this->_getImapClient($oAccount, 20, 60 * 2); $oImapClient->FolderExamine($sFolderFullNameRaw); $aList = $this->_getFolderInformation($oImapClient, $sFolderFullNameRaw); $iMessageCount = $aList[0]; $iRealMessageCount = $aList[0]; $iMessageUnseenCount = $aList[1]; $sUidNext = $aList[2]; $oMessageCollection = CApiMailMessageCollection::createInstance(); $oMessageCollection->FolderName = $sFolderFullNameRaw; $oMessageCollection->Offset = $iOffset; $oMessageCollection->Limit = $iLimit; $oMessageCollection->Search = $sSearch; $oMessageCollection->UidNext = $sUidNext; $oMessageCollection->Filters = implode(',', $aFilters); $aThreads = array(); $bUseThreadsIfSupported = !!$oSettings->GetConf('WebMail/UseThreadsIfSupported'); if ($bUseThreadsIfSupported) { $bUseThreadsIfSupported = $bUseThreads; } $oMessageCollection->FolderHash = $aList[3]; $bSearch = false; if (0 < $iRealMessageCount) { $bIndexAsUid = false; $aIndexOrUids = array(); $bUseSortIfSupported = !!$oSettings->GetConf('WebMail/UseSortImapForDateMode'); if ($bUseSortIfSupported) { $bUseSortIfSupported = $oImapClient->IsSupported('SORT'); } if ($bUseThreadsIfSupported) { $bUseThreadsIfSupported = $oImapClient->IsSupported('THREAD=REFS') || $oImapClient->IsSupported('THREAD=REFERENCES') || $oImapClient->IsSupported('THREAD=ORDEREDSUBJECT'); } if (0 < strlen($sSearch) || 0 < count($aFilters)) { $sCutedSearch = $sSearch; $sCutedSearch = \preg_replace('/[\\s]+/', ' ', $sCutedSearch); $sCutedSearch = \preg_replace('/attach[ ]?:[ ]?/i', 'attach:', $sCutedSearch); $bSearchAttachments = false; $fAttachmentSearchCallback = null; $aMatch = array(); if (CApi::GetConf('labs.use-body-structures-for-has-attachments-search', false) && \preg_match('/has[ ]?:[ ]?attachments/i', $sSearch) || \preg_match('/attach:([^\\s]+)/i', $sSearch, $aMatch)) { $bSearchAttachments = true; $sAttachmentName = isset($aMatch[1]) ? trim($aMatch[1]) : ''; $sAttachmentRegs = !empty($sAttachmentName) && '*' !== $sAttachmentName ? '/[^>]*' . str_replace('\\*', '[^>]*', preg_quote(trim($sAttachmentName, '*'), '/')) . '[^>]*/ui' : ''; if (CApi::GetConf('labs.use-body-structures-for-has-attachments-search', false)) { $sCutedSearch = trim(preg_replace('/has[ ]?:[ ]?attachments/i', '', $sCutedSearch)); } $sCutedSearch = trim(preg_replace('/attach:([^\\s]+)/', '', $sCutedSearch)); $fAttachmentSearchCallback = function ($oBodyStructure, $sSize, $sInternalDate, $aFlagsLower, $sUid) use($sFolderFullNameRaw, $sAttachmentRegs) { $bResult = false; if ($oBodyStructure) { $aAttachmentsParts = $oBodyStructure->SearchAttachmentsParts(); if ($aAttachmentsParts && 0 < count($aAttachmentsParts)) { $oAttachments = CApiMailAttachmentCollection::createInstance(); foreach ($aAttachmentsParts as $oAttachmentItem) { $oAttachments->Add(CApiMailAttachment::createInstance($sFolderFullNameRaw, $sUid, $oAttachmentItem)); } $bResult = $oAttachments->hasNotInlineAttachments(); if ($bResult && !empty($sAttachmentRegs)) { $aList = $oAttachments->FilterList(function ($oAttachment) use($sAttachmentRegs) { if ($oAttachment && !$oAttachment->isInline() && !$oAttachment->getCid()) { return !!preg_match($sAttachmentRegs, $oAttachment->getFileName()); } return false; }); return is_array($aList) ? 0 < count($aList) : false; } } } unset($oBodyStructure); return $bResult; }; } if (0 < strlen($sCutedSearch) || 0 < count($aFilters)) { $bSearch = true; $sSearchCriterias = $this->_prepareImapSearchString($oImapClient, $sCutedSearch, $oAccount->getDefaultTimeOffset() * 60, $aFilters); $bIndexAsUid = true; $aIndexOrUids = null; if ($bUseSortIfSupported) { $aIndexOrUids = $oImapClient->MessageSimpleSort(array('REVERSE ARRIVAL'), $sSearchCriterias, $bIndexAsUid); } else { if (!\MailSo\Base\Utils::IsAscii($sCutedSearch)) { try { $aIndexOrUids = $oImapClient->MessageSimpleSearch($sSearchCriterias, $bIndexAsUid, 'UTF-8'); } catch (\MailSo\Imap\Exceptions\NegativeResponseException $oException) { // Charset is not supported. Skip and try request without charset. $aIndexOrUids = null; } } if (null === $aIndexOrUids) { $aIndexOrUids = $oImapClient->MessageSimpleSearch($sSearchCriterias, $bIndexAsUid); } } if ($bSearchAttachments && is_array($aIndexOrUids) && 0 < count($aIndexOrUids)) { $aIndexOrUids = $this->_doSpecialUidsSearch($oImapClient, $fAttachmentSearchCallback, $sFolderFullNameRaw, $aIndexOrUids, $iOffset, $iLimit); } } else { if ($bSearchAttachments) { $bIndexAsUid = true; $aIndexOrUids = $this->_doSpecialIndexSearch($oImapClient, $fAttachmentSearchCallback, $sFolderFullNameRaw, $iOffset, $iLimit); } } } else { if ($bUseThreadsIfSupported && 1 < $iMessageCount) { $bIndexAsUid = true; $aThreadUids = array(); try { $aThreadUids = $oImapClient->MessageSimpleThread(); } catch (\MailSo\Imap\Exceptions\RuntimeException $oException) { $aThreadUids = array(); } $aThreads = $this->_compileThreadList($aThreadUids); if ($bUseSortIfSupported) { $aThreads = $this->_resortThreadList($aThreads, $oImapClient->MessageSimpleSort(array('REVERSE ARRIVAL'), 'ALL', true)); } else { // $this->chunkThreadArray($aThreads); } $aIndexOrUids = array_keys($aThreads); $iMessageCount = count($aIndexOrUids); } else { if ($bUseSortIfSupported && 1 < $iMessageCount) { $bIndexAsUid = true; $aIndexOrUids = $oImapClient->MessageSimpleSort(array('REVERSE ARRIVAL'), 'ALL', $bIndexAsUid); } else { $bIndexAsUid = false; $aIndexOrUids = array(1); if (1 < $iMessageCount) { $aIndexOrUids = array_reverse(range(1, $iMessageCount)); } } } } if (is_array($aIndexOrUids)) { $oMessageCollection->MessageCount = $iRealMessageCount; $oMessageCollection->MessageUnseenCount = $iMessageUnseenCount; $oMessageCollection->MessageResultCount = 0 < strlen($sSearch) || 0 < count($aFilters) ? count($aIndexOrUids) : $iMessageCount; if (0 < count($aIndexOrUids)) { $iOffset = 0 > $iOffset ? 0 : $iOffset; $aRequestIndexOrUids = array_slice($aIndexOrUids, $iOffset, $iLimit); if ($bIndexAsUid) { $oMessageCollection->Uids = $aRequestIndexOrUids; } if (is_array($aRequestIndexOrUids) && 0 < count($aRequestIndexOrUids)) { $aFetchResponse = $oImapClient->Fetch(array(\MailSo\Imap\Enumerations\FetchType::INDEX, \MailSo\Imap\Enumerations\FetchType::UID, \MailSo\Imap\Enumerations\FetchType::RFC822_SIZE, \MailSo\Imap\Enumerations\FetchType::INTERNALDATE, \MailSo\Imap\Enumerations\FetchType::FLAGS, \MailSo\Imap\Enumerations\FetchType::BODYSTRUCTURE, \MailSo\Imap\Enumerations\FetchType::BODY_HEADER_PEEK), implode(',', $aRequestIndexOrUids), $bIndexAsUid); if (is_array($aFetchResponse) && 0 < count($aFetchResponse)) { $aFetchIndexArray = array(); $oFetchResponseItem = null; foreach ($aFetchResponse as &$oFetchResponseItem) { $aFetchIndexArray[$bIndexAsUid ? $oFetchResponseItem->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::UID) : $oFetchResponseItem->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::INDEX)] =& $oFetchResponseItem; unset($oFetchResponseItem); } foreach ($aRequestIndexOrUids as $iFUid) { if (isset($aFetchIndexArray[$iFUid])) { $oMailMessage = CApiMailMessage::createInstance($oMessageCollection->FolderName, $aFetchIndexArray[$iFUid]); if (!$bIndexAsUid) { $oMessageCollection->Uids[] = $oMailMessage->getUid(); } $oMessageCollection->Add($oMailMessage); unset($oMailMessage); } } } } } } } if (!$bSearch && $bUseThreadsIfSupported && 0 < count($aThreads)) { $oMessageCollection->ForeachList(function ($oMessage) use($aThreads) { $iUid = $oMessage->getUid(); if (isset($aThreads[$iUid]) && is_array($aThreads[$iUid])) { $oMessage->setThreads($aThreads[$iUid]); } }); } if (0 < strlen($sInboxUidnext) && 'INBOX' === $oMessageCollection->FolderName && $sInboxUidnext !== $oMessageCollection->UidNext) { $oMessageCollection->New = $this->getNewMessagesInformation($oAccount, 'INBOX', $sInboxUidnext, $oMessageCollection->UidNext); } return $oMessageCollection; }