Exemplo n.º 1
0
 public function CheckApi()
 {
     if (!class_exists('\\CApi') || !\CApi::IsValid()) {
         echo 'AfterLogic API';
         return '';
     }
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
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;
 }
Exemplo 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)
 {
     $mResult = false;
     if (class_exists('CApi') && \CApi::IsValid()) {
         /* @var $oApiCapabilityManager \CApiCapabilityManager */
         $oApiCapabilityManager = \CApi::GetSystemManager('capability');
         if ($oApiCapabilityManager) {
             $oDavDecorator = \CApi::GetModuleDecorator('Dav');
             if ($oDavDecorator) {
                 $mResult = $oDavDecorator->Login($sUserName, $sPassword);
             }
             $bIsOutlookSyncClient = \Afterlogic\DAV\Utils::ValidateClient('outlooksync');
             $bIsMobileSync = false;
             $bIsOutlookSync = false;
             $bIsDemo = false;
             //				if ($mResult !== false) {
             //					$iIdUser = isset($mResult['id']) ? $mResult['id'] : 0;
             //					return true;
             /*					
             					$bIsMobileSync = $oApiCapabilityManager->isMobileSyncSupported($iIdUser);
             					$bIsOutlookSync = $oApiCapabilityManager->isOutlookSyncSupported($iIdUser);
             					
             					\CApi::Plugin()->RunHook(
             							'plugin-is-demo-account', 
             							array(&$oAccount, &$bIsDemo)
             					);
             * 
             */
             //				}
             /*
             				if (($oAccount && $oAccount->IncomingMailPassword === $sPassword &&
             						(($bIsMobileSync && !$bIsOutlookSyncClient) || 
             						($bIsOutlookSync && $bIsOutlookSyncClient))) ||
             						$bIsDemo || $sUserName === \CApi::ExecuteMethod('Dav::GetPublicUser')) {
             					return true;
             				}
             * 
             */
         }
     }
     return $mResult;
 }
Exemplo n.º 5
0
 /**
  * @return void
  */
 protected function initAdminPanel()
 {
     $this->RType = (bool) CApi::GetConf('tenant', false);
     $this->AType = !!CApi::Manager('collaboration');
     $this->aTabsSort = array(AP_TAB_COMMON, AP_TAB_DOMAINS, AP_TAB_USERS, AP_TAB_TENANTS, AP_TAB_CHANNELS, AP_TAB_SYSTEM);
     $GLOBALS[AP_START_TIME] = ap_Utils::Microtime();
     $GLOBALS[AP_DB_COUNT] = 0;
     if (isset($_GET['logout'])) {
         CSession::ClearAll();
         CApi::Location(AP_INDEX_FILE . '?login');
     }
     if (isset($_GET['tab']) && strlen($_GET['tab']) > 0) {
         CSession::Set(AP_SESS_TAB, $_GET['tab']);
     } else {
         CSession::Set(AP_SESS_TAB, CSession::Get(AP_SESS_TAB, AP_TAB_DEFAULT));
     }
     $this->sTab = CSession::Get(AP_SESS_TAB, AP_TAB_DEFAULT);
     try {
         $this->CssAddFile('static/styles/style.css');
         $this->JsAddFile('static/js/common.js');
         $this->JsAddFile('static/js/jquery.js');
         if (!CApi::IsValid()) {
             return false;
         }
         $this->initModules();
         $this->initType();
         $this->initAuth();
         $this->sHelpUrl = '';
         $sUrl = $this->IsTenantAuthType() ? (string) CApi::GetConf('labs.custom-tenant-help-url', '') : (string) CApi::GetConf('labs.custom-admin-help-url', '');
         if (0 < strlen($sUrl)) {
             $this->sHelpUrl = $sUrl;
         } else {
             if ($this->AType) {
                 $this->sHelpUrl = 'http://www.afterlogic.com/wiki/Aurora_documentation';
             } else {
                 if ($this->PType) {
                     $this->sHelpUrl = 'http://www.afterlogic.com/wiki/WebMail_Pro_documentation';
                 } else {
                     $this->sHelpUrl = 'http://www.afterlogic.com/wiki/WebMail_Lite_documentation';
                 }
             }
         }
         if (isset($_GET['help'])) {
             if (0 < strlen($this->sHelpUrl)) {
                 CApi::Location($this->sHelpUrl);
             } else {
                 CApi::Location('?root');
             }
         }
         $bResetToDefault = true;
         foreach ($this->aTabs as $aTab) {
             if (isset($aTab[1]) && (string) $aTab[1] === (string) $this->sTab) {
                 $bResetToDefault = false;
                 break;
             }
         }
         if ($bResetToDefault) {
             $this->sTab = $this->IsTenantAuthType() ? AP_TAB_TENANT_DEFAULT : AP_TAB_DEFAULT;
             CSession::Set(AP_SESS_TAB, $this->sTab);
         }
         if (isset($_GET['submit']) && isset($_POST) && 0 < count($_POST)) {
             $this->bShowScreen = false;
             $sReturnRef = $this->initPostActionModules($this->sTab);
             CApi::Location(AP_INDEX_FILE . $sReturnRef);
         } else {
             if (isset($_GET['pop'])) {
                 $this->bShowScreen = false;
                 $this->initPopActionModules($this->sTab);
             } else {
                 if (isset($_GET['blank'])) {
                     $this->bShowScreen = false;
                     $this->initBlankActionModules($this->sTab);
                 } else {
                     if (isset($_GET['ajax'])) {
                         $this->bShowScreen = false;
                         $this->initAjaxActionModules($this->sTab);
                     } else {
                         $this->oCurrentScreen = $this->initScreen($this->sTab);
                         if ($this->oCurrentScreen) {
                             $this->oCurrentScreen->PreModuleInit();
                             $this->initCurrentScreenByModules('first', $this->sTab, $this->oCurrentScreen);
                             $this->oCurrentScreen->MiddleModuleInit();
                             $this->initCurrentScreenByModules('second', $this->sTab, $this->oCurrentScreen);
                             $this->oCurrentScreen->EndModuleInit();
                             $this->initCurrentScreenByModules('third', $this->sTab, $this->oCurrentScreen);
                         }
                         if (CSession::Has(AP_SESS_ERROR)) {
                             $this->JsAddInitText('OnlineMsgError("' . ap_Utils::ReBuildStringToJavaScript(nl2br(CSession::Get(AP_SESS_ERROR, '')), '"') . '");');
                             CSession::Clear(AP_SESS_ERROR);
                         } else {
                             if (CSession::Has(AP_SESS_MESSAGE)) {
                                 $this->JsAddInitText('OnlineMsgInfo("' . ap_Utils::ReBuildStringToJavaScript(nl2br(CSession::Get(AP_SESS_MESSAGE, '')), '"') . '");');
                                 CSession::Clear(AP_SESS_MESSAGE);
                             }
                         }
                     }
                 }
             }
         }
     } catch (Exception $oExeption) {
         $this->oCurrentScreen = new ap_Simple_Screen($this, 'error.php', array('ErrorDesc' => 'Admin Panel internal error.'));
     }
 }
Exemplo n.º 6
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;
 }
Exemplo n.º 7
0
 /**
  * @param string $sManagerType
  * @param string $sForcedStorage = ''
  */
 public function GetByType1($sManagerType, $sForcedStorage = '')
 {
     $oResult = null;
     if (CApi::IsValid()) {
         if (empty($sForcedStorage)) {
             if (isset($this->aManagers[$sManagerType])) {
                 $oResult =& $this->aManagers[$sManagerType];
             } else {
                 $sManagerType = strtolower($sManagerType);
                 if (CApi::Inc('common.managers.' . $sManagerType . '.manager', false)) {
                     $sClassName = 'CApi' . ucfirst($sManagerType) . 'Manager';
                     $this->aManagers[$sManagerType] = new $sClassName($this);
                     $oResult =& $this->aManagers[$sManagerType];
                 }
             }
         } else {
             if (CApi::Inc('common.managers.' . $sManagerType . '.manager', false)) {
                 $sClassName = 'CApi' . ucfirst($sManagerType) . 'Manager';
                 $oResult = new $sClassName($this, $sForcedStorage);
             }
         }
     }
     return $oResult;
 }
Exemplo n.º 8
0
<?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();
    }
}
Exemplo n.º 9
0
<?php

/*
 * Copyright 2004-2015, AfterLogic Corp.
 * Licensed under AGPLv3 license or AfterLogic license
 * if commercial version of the product was purchased.
 * See the LICENSE file for a full license statement.
 */
// remove the following line for real use
exit('remove this line');
// Example of logging into WebMail account using email and password for incorporating into another web application
// utilizing API
include_once __DIR__ . '/../libraries/afterlogic/api.php';
if (class_exists('CApi') && CApi::IsValid()) {
    // data for logging into account
    $sEmail = '*****@*****.**';
    $sPassword = '******';
    try {
        // Getting required API class
        $oApiIntegratorManager = CApi::Manager('integrator');
        // attempting to obtain object for account we're trying to log into
        $oAccount = $oApiIntegratorManager->loginToAccount($sEmail, $sPassword);
        if ($oAccount) {
            // populating session data from the account
            $oApiIntegratorManager->setAccountAsLoggedIn($oAccount);
            // redirecting to WebMail
            CApi::Location('../');
        } else {
            // login error
            echo $oApiIntegratorManager->GetLastErrorMessage();
        }
Exemplo n.º 10
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;
 }
Exemplo n.º 11
0
    parse_str($sContents, $aInputData);
} else {
    $aInputData = isset($_REQUEST) && is_array($_REQUEST) ? $_REQUEST : array();
}
//$sMethod = isset($aInputData['method']) ? $aInputData['method'] : '';
$sMethod = strlen($_SERVER['PATH_INFO']) > 0 ? $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['PATH_INFO'] : '';
$sToken = isset($aInputData['token']) ? $aInputData['token'] : '';
$aSecret = CApi::DecodeKeyValues($sToken);
$bMethod = in_array($sMethod, array('GET /token', 'POST /account', 'PUT /account/update', 'DELETE /account', 'PUT /account/enable', 'PUT /account/disable', 'PUT /account/password', 'GET /account/list', 'GET /account/exists', 'GET /account', 'POST /domain', 'PUT /domain/update', 'DELETE /domain', 'GET /domain/list', 'GET /domain/exists', 'GET /domain'));
$aResult = array('method' => $sMethod);
if (!CApi::GetConf('labs.rest', true)) {
    $aResult['message'] = 'rest api disabled';
    $aResult['errorCode'] = \ProjectSeven\Notifications::RestApiDisabled;
    $aResult['result'] = false;
} else {
    if (class_exists('CApi') && CApi::IsValid() && $bMethod) {
        /* @var $oApiDomainsManager CApiDomainsManager */
        $oApiDomainsManager = CApi::Manager('domains');
        /* @var $oApiTenantsManager CApiTenantsManager */
        $oApiTenantsManager = CApi::Manager('tenants');
        /* @var $oApiUsersManager CApiUsersManager */
        $oApiUsersManager = CApi::Manager('users');
        /* @var $oApiIntegratorManager CApiIntegratorManager */
        $oApiIntegratorManager = CApi::Manager('integrator');
        if ($sMethod === 'GET /token') {
            $oSettings = CApi::GetSettings();
            $sLogin = isset($aInputData['login']) ? $aInputData['login'] : '';
            $sPassword = isset($aInputData['password']) ? $aInputData['password'] : '';
            if (0 < strlen($sLogin) && 0 < strlen($sPassword) && $oApiTenantsManager && $oSettings) {
                $sSettingsLogin = $oSettings->GetConf('Common/AdminLogin');
                $sSettingsPassword = $oSettings->GetConf('Common/AdminPassword');
Exemplo n.º 12
0
 /**
  * @param string $sManagerType
  * @param string $sForcedStorage = ''
  */
 public function GetByType($sManagerType, $sForcedStorage = '')
 {
     $oResult = null;
     if (CApi::IsValid()) {
         $sManagerKey = empty($sForcedStorage) ? $sManagerType : $sManagerType . '/' . $sForcedStorage;
         if (isset($this->aManagers[$sManagerKey])) {
             $oResult =& $this->aManagers[$sManagerKey];
         } else {
             $sManagerType = strtolower($sManagerType);
             $sClassName = 'CApi' . ucfirst($sManagerType) . 'Manager';
             if (!class_exists($sClassName)) {
                 CApi::Inc('managers.' . $sManagerType . '.manager', false);
             }
             if (class_exists($sClassName)) {
                 $oMan = new $sClassName($this, $sForcedStorage);
                 $sCurrentStorageName = $oMan->GetStorageName();
                 $sManagerKey = empty($sCurrentStorageName) ? $sManagerType : $sManagerType . '/' . $sCurrentStorageName;
                 $this->aManagers[$sManagerKey] = $oMan;
                 $oResult =& $this->aManagers[$sManagerKey];
             }
         }
     }
     return $oResult;
 }