Example #1
0
 public static function Run()
 {
     include_once self::LibrariesPath() . 'MailSo/MailSo.php';
     CApi::$aI18N = null;
     CApi::$aClientI18N = array();
     if (!is_object(CApi::$oManager)) {
         CApi::Inc('common.functions');
         CApi::Inc('common.constants');
         CApi::Inc('common.enum');
         CApi::Inc('common.exception');
         CApi::Inc('common.utils');
         CApi::Inc('common.crypt');
         CApi::Inc('common.container');
         CApi::Inc('common.manager');
         CApi::Inc('common.xml');
         CApi::Inc('common.plugin');
         CApi::Inc('common.utils.get');
         CApi::Inc('common.utils.post');
         CApi::Inc('common.utils.session');
         CApi::Inc('common.http');
         CApi::Inc('common.social');
         CApi::Inc('common.twilio');
         CApi::Inc('common.db.storage');
         $sSalt = '';
         $sSaltFile = CApi::DataPath() . '/salt.php';
         if (!@file_exists($sSaltFile)) {
             $sSaltDesc = '<?php #' . md5(microtime(true) . rand(1000, 9999)) . md5(microtime(true) . rand(1000, 9999));
             @file_put_contents($sSaltFile, $sSaltDesc);
         } else {
             $sSalt = md5(file_get_contents($sSaltFile));
         }
         CApi::$sSalt = $sSalt;
         CApi::$aConfig = (include CApi::RootPath() . 'common/config.php');
         $sSettingsFile = CApi::DataPath() . '/settings/config.php';
         if (@file_exists($sSettingsFile)) {
             $aAppConfig = (include $sSettingsFile);
             if (is_array($aAppConfig)) {
                 CApi::$aConfig = array_merge(CApi::$aConfig, $aAppConfig);
             }
         }
         $oHtml = \MailSo\Base\Http::SingletonInstance();
         $sHost = $oHtml->GetHost();
         if (0 < \strlen($sHost)) {
             $sDomainSettingsFile = CApi::DataPath() . '/settings/' . $sHost . '.config.php';
             if (@file_exists($sDomainSettingsFile)) {
                 $aDomainAppConfig = (include $sDomainSettingsFile);
                 if (is_array($aDomainAppConfig)) {
                     CApi::$aConfig = array_merge(CApi::$aConfig, $aDomainAppConfig);
                 }
             }
         }
         CApi::$oManager = new CApiGlobalManager();
         CApi::$oPlugin = new CApiPluginManager(CApi::$oManager);
         CApi::$bIsValid = CApi::validateApi();
         CApi::$oManager->PrepareStorageMap();
         require_once CApi::RootPath() . 'DAV/autoload.php';
     }
 }
Example #2
0
 /**
  * @return string
  */
 private function helpdeskLink()
 {
     $sPath = rtrim(\MailSo\Base\Http::SingletonInstance()->GetFullUrl(), '\\/ ');
     if ('/crons' === substr($sPath, -6)) {
         $sPath = substr($sPath, 0, -6);
     }
     $sPath .= '/?helpdesk';
     if (0 < $this->IdTenant) {
         $sPath .= '=' . substr(md5($this->IdTenant . CApi::$sSalt), 0, 8);
     }
     return $sPath;
 }
 /**
  * @return void
  */
 private function __construct()
 {
     $this->oHttp = \MailSo\Base\Http::SingletonInstance();
     $this->oActions = \RainLoop\Api::Actions();
     $this->oServiceActions = new \RainLoop\ServiceActions($this->oHttp, $this->oActions);
     if ($this->oActions->Config()->Get('debug', 'enable', false)) {
         \error_reporting(E_ALL);
         \ini_set('display_errors', 1);
     }
     \RainLoop\Api::SetupDefaultMailSoConfig();
     $sServer = \trim($this->oActions->Config()->Get('security', 'custom_server_signature', ''));
     if (0 < \strlen($sServer)) {
         @\header('Server: ' . $sServer, true);
     }
     if ($this->oActions->Config()->Get('labs', 'force_https', false) && !$this->oHttp->IsSecure()) {
         @\header('Location: https://' . $this->oHttp->GetHost(false, false) . $this->oHttp->GetUrl(), true);
         exit;
     }
 }
Example #4
0
 public static function CreateClient($oTenant)
 {
     $oClient = null;
     $oSocial = $oTenant->getSocialByName(self::$ConnectorName);
     if (isset($oSocial) && $oSocial->SocialAllow) {
         $sRedirectUrl = rtrim(\MailSo\Base\Http::SingletonInstance()->GetFullUrl(), '\\/ ') . '/?external-services=' . self::$ConnectorName;
         require PSEVEN_APP_ROOT_PATH . 'libraries/OAuthClient/http.php';
         require PSEVEN_APP_ROOT_PATH . 'libraries/OAuthClient/oauth_client.php';
         $oClient = new \oauth_client_class();
         $oClient->debug = self::$Debug;
         $oClient->debug_http = self::$Debug;
         $oClient->server = 'Facebook';
         $oClient->redirect_uri = $sRedirectUrl;
         $oClient->client_id = $oSocial->SocialId;
         $oClient->client_secret = $oSocial->SocialSecret;
         $oClient->scope = 'email';
     }
     return $oClient;
 }
Example #5
0
 /**
  * @return void
  */
 private function __construct()
 {
     $this->oHttp = \MailSo\Base\Http::SingletonInstance();
     $this->oActions = Actions::NewInstance();
     \set_error_handler(array(&$this, 'LogPhpErrorHandler'));
     $this->oServiceActions = new \RainLoop\ServiceActions($this->oHttp, $this->oActions);
     if ($this->oActions->Config()->Get('debug', 'enable', false)) {
         \error_reporting(E_ALL);
         \ini_set('display_errors', 1);
     }
     if ($this->oActions->Config()->Get('labs', 'disable_iconv_if_mbstring_supported', false) && \class_exists('MailSo\\Capa') && \MailSo\Base\Utils::IsMbStringSupported()) {
         \MailSo\Config::$ICONV = false;
     }
     $sServer = \trim($this->oActions->Config()->Get('security', 'custom_server_signature', ''));
     if (0 < \strlen($sServer)) {
         @\header('Server: ' . $sServer, true);
     }
     if ($this->oActions->Config()->Get('labs', 'force_https', false) && !$this->oHttp->IsSecure()) {
         @\header('Location: https://' . $this->oHttp->GetHost(false, false) . $this->oHttp->GetUrl(), true);
         exit;
     }
 }
Example #6
0
 public static function CreateClient($oTenant)
 {
     $oClient = null;
     $oSocial = $oTenant->getSocialByName(self::$ConnectorName);
     if (isset($oSocial) && $oSocial->SocialAllow) {
         $sRedirectUrl = rtrim(\MailSo\Base\Http::SingletonInstance()->GetFullUrl(), '\\/ ') . '/?external-services=' . self::$ConnectorName;
         if (!strpos($sRedirectUrl, '://localhost')) {
             $sRedirectUrl = str_replace('http:', 'https:', $sRedirectUrl);
         }
         require PSEVEN_APP_ROOT_PATH . 'libraries/OAuthClient/http.php';
         require PSEVEN_APP_ROOT_PATH . 'libraries/OAuthClient/oauth_client.php';
         $oClient = new \oauth_client_class();
         $oClient->debug = self::$Debug;
         $oClient->debug_http = self::$Debug;
         $oClient->server = 'Dropbox2';
         $oClient->redirect_uri = $sRedirectUrl;
         $oClient->client_id = $oSocial->SocialId;
         $oClient->client_secret = $oSocial->SocialSecret;
         $oClient->configuration_file = PSEVEN_APP_ROOT_PATH . 'libraries/OAuthClient/' . $oClient->configuration_file;
     }
     return $oClient;
 }
Example #7
0
 public static function CreateClient($oTenant = null)
 {
     $oClient = null;
     $oSocial = $oTenant->getSocialByName(self::$ConnectorName);
     if (isset($oSocial) && $oSocial->SocialAllow) {
         $sRedirectUrl = rtrim(\MailSo\Base\Http::SingletonInstance()->GetFullUrl(), '\\/ ') . '/?external-services=' . self::$ConnectorName;
         require PSEVEN_APP_ROOT_PATH . 'libraries/OAuthClient/http.php';
         require PSEVEN_APP_ROOT_PATH . 'libraries/OAuthClient/oauth_client.php';
         $oClient = new \oauth_client_class();
         $oClient->offline = true;
         $oClient->debug = self::$Debug;
         $oClient->debug_http = self::$Debug;
         $oClient->server = 'Google';
         $oClient->redirect_uri = $sRedirectUrl;
         $oClient->client_id = $oSocial->SocialId;
         $oClient->client_secret = $oSocial->SocialSecret;
         $oClient->scope = 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile';
         if (in_array('filestorage', self::$Scopes)) {
             $oClient->scope = $oClient->scope . ' https://www.googleapis.com/auth/drive';
         }
     }
     return $oClient;
 }
Example #8
0
 public static function GetGoogleDriveFileInfo($sLink, $sGoogleAPIKey, $sAccessToken = null, $bLinkAsId = false)
 {
     $mResult = false;
     $sGDId = '';
     if ($bLinkAsId) {
         $sGDId = $sLink;
     } else {
         $matches = array();
         preg_match("%https://\\w+\\.google\\.com/\\w+/d/(.*?)/.*%", $sLink, $matches);
         if (!isset($matches[1])) {
             preg_match("%https://\\w+\\.google\\.com/open\\?id=(.*)%", $sLink, $matches);
         }
         $sGDId = isset($matches[1]) ? $matches[1] : '';
     }
     if ($sGDId !== '') {
         $sUrl = "https://www.googleapis.com/drive/v2/files/" . $sGDId . '?key=' . $sGoogleAPIKey;
         $aHeaders = $sAccessToken ? array('Authorization: Bearer ' . $sAccessToken) : array();
         $sContentType = '';
         $iCode = 0;
         $mResult = \MailSo\Base\Http::SingletonInstance()->GetUrlAsString($sUrl, '', $sContentType, $iCode, null, 10, '', '', $aHeaders);
         if ($iCode === 200) {
             $mResult = json_decode($mResult);
             self::PopulateGoogleDriveFileInfo($mResult);
         } else {
             $mResult = false;
         }
     } else {
         $mResult = false;
     }
     return $mResult;
 }
Example #9
0
 /**
  * @return string
  */
 public function ForgotLink()
 {
     $sPath = rtrim(\MailSo\Base\Http::SingletonInstance()->GetFullUrl(), '\\/ ');
     if ('/crons' === substr($sPath, -6)) {
         $sPath = substr($sPath, 0, -6);
     }
     $sPath .= '/?helpdesk';
     if (0 < $this->IdTenant) {
         $sHash = substr(md5($this->IdTenant . CApi::$sSalt), 0, 8);
         $sPath .= '=' . $sHash;
     }
     $sPath .= '&forgot=' . $this->ActivateHash;
     return $sPath;
 }
 /**
  * @return array
  */
 public function DoComposeUploadDrive()
 {
     $oAccount = $this->getAccountFromToken();
     $mResult = false;
     $sUrl = $this->GetActionParam('Url', '');
     $sAccessToken = $this->GetActionParam('AccessToken', '');
     $sGoogleApiKey = (string) $this->Config()->Get('social', 'google_api_key', '');
     if (0 < \strlen($sUrl) && 0 < \strlen($sAccessToken) && 0 < \strlen($sGoogleApiKey)) {
         $oHttp = \MailSo\Base\Http::SingletonInstance();
         $mResult[$sUrl] = false;
         $sTempName = \md5($sUrl);
         $iCode = 0;
         $sContentType = '';
         $rFile = $this->FilesProvider()->GetFile($oAccount, $sTempName, 'wb+');
         if ($rFile && $oHttp->SaveUrlToFile($sUrl . '&key=' . $sGoogleApiKey, $rFile, '', $sContentType, $iCode, $this->Logger(), 60, $this->Config()->Get('labs', 'curl_proxy', ''), $this->Config()->Get('labs', 'curl_proxy_auth', ''), array('Authorization: Bearer ' . $sAccessToken))) {
             $mResult[$sUrl] = array($sTempName, 0);
         }
         if (\is_resource($rFile)) {
             @\fclose($rFile);
         }
         if (isset($mResult[$sUrl][1])) {
             $mResult[$sUrl][1] = $rFile = $this->FilesProvider()->FileSize($oAccount, $sTempName);
         }
     }
     return $this->DefaultResponse(__FUNCTION__, $mResult);
 }
 /**
  * @param \RainLoop\Account $oAccount
  * @param string $sPrevPassword
  * @param string $sNewPassword
  *
  * @return bool
  */
 public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword)
 {
     if ($this->oLogger) {
         $this->oLogger->Write('DirectAdmin: Try to change password for ' . $oAccount->Email());
     }
     $bResult = false;
     if (!empty($this->sHost) && 0 < $this->iPort && $oAccount) {
         $sEmail = \trim(\strtolower($oAccount->Email()));
         $sHost = \trim($this->sHost);
         $sHost = \str_replace('{user:host-imap}', $oAccount->Domain()->IncHost(), $sHost);
         $sHost = \str_replace('{user:host-smtp}', $oAccount->Domain()->OutHost(), $sHost);
         $sHost = \str_replace('{user:domain}', \MailSo\Base\Utils::GetDomainFromEmail($sEmail), $sHost);
         $sHost = \rtrim($this->sHost, '/\\');
         if (!\preg_match('/^http[s]?:\\/\\//i', $sHost)) {
             $sHost = 'http://' . $sHost;
         }
         $sUrl = $sHost . ':' . $this->iPort . '/CMD_CHANGE_EMAIL_PASSWORD';
         $iCode = 0;
         $oHttp = \MailSo\Base\Http::SingletonInstance();
         if ($this->oLogger) {
             $this->oLogger->Write('DirectAdmin[Api Request]:' . $sUrl);
         }
         $mResult = $oHttp->SendPostRequest($sUrl, array('email' => $sEmail, 'oldpassword' => $sPrevPassword, 'password1' => $sNewPassword, 'password2' => $sNewPassword, 'api' => '1'), 'MailSo Http User Agent (v1)', $iCode, $this->oLogger);
         if (false !== $mResult && 200 === $iCode) {
             $aRes = null;
             @\parse_str($mResult, $aRes);
             if (is_array($aRes) && (!isset($aRes['error']) || (int) $aRes['error'] !== 1)) {
                 $bResult = true;
             } else {
                 if ($this->oLogger) {
                     $this->oLogger->Write('DirectAdmin[Error]: Response: ' . $mResult);
                 }
             }
         } else {
             if ($this->oLogger) {
                 $this->oLogger->Write('DirectAdmin[Error]: Empty Response: Code:' . $iCode);
             }
         }
     }
     return $bResult;
 }
Example #12
0
 /**
  * @param bool $bHelpdesk Default value is **false**.
  * @param int $iHelpdeskIdTenant Default value is **null**.
  * @param string $sHelpdeskTenantHash Default value is empty string.
  * @param string $sCalendarPubHash Default value is empty string.
  * @param string $sFileStoragePubHash Default value is empty string.
  * @param string $sAuthToken Default value is empty string.
  *
  * @return array
  */
 public function appData($bHelpdesk = false, $iHelpdeskIdTenant = null, $sHelpdeskTenantHash = '', $sCalendarPubHash = '', $sFileStoragePubHash = '', $sAuthToken = '')
 {
     $aAppData = array('Auth' => false, 'User' => null, 'TenantHash' => $sHelpdeskTenantHash, 'IsMobile' => 0, 'AllowMobile' => false, 'IsMailsuite' => false, 'HelpdeskSiteName' => '', 'HelpdeskIframeUrl' => '', 'HelpdeskRedirect' => false, 'HelpdeskThreadId' => 0, 'HelpdeskActivatedEmail' => '', 'HelpdeskForgotHash' => '', 'ClientDebug' => \CApi::GetConf('labs.webmail-client-debug', false), 'MailExpandFolders' => \CApi::GetConf('labs.mail-expand-folders', false), 'HtmlEditorDefaultFontName' => \CApi::GetConf('labs.htmleditor-default-font-name', ''), 'HtmlEditorDefaultFontSize' => \CApi::GetConf('labs.htmleditor-default-font-size', ''), 'AllowSaveAsPdf' => !!\CApi::GetConf('labs.allow-save-as-pdf', false), 'LastErrorCode' => $this->getLastErrorCode(), 'Token' => $this->getCsrfToken(), 'ZipAttachments' => !!class_exists('ZipArchive'), 'AllowIdentities' => !!$this->oSettings->GetConf('WebMail/AllowIdentities'), 'SocialEmail' => '', 'SocialIsLoggedIn' => false, 'Links' => array('ImportingContacts' => \CApi::GetConf('links.importing-contacts', ''), 'OutlookSyncPlugin32' => \CApi::GetConf('links.outlook-sync-plugin-32', ''), 'OutlookSyncPlugin64' => \CApi::GetConf('links.outlook-sync-plugin-64', ''), 'OutlookSyncPluginReadMore' => \CApi::GetConf('links.outlook-sync-read-more', '')));
     CApi::Plugin()->RunHook('api-pre-app-data', array(&$aAppData));
     $oApiCapability = \CApi::Manager('capability');
     if ($oApiCapability) {
         if ($oApiCapability->isNotLite()) {
             $aAppData['IsMobile'] = $this->isMobile();
             $aAppData['AllowMobile'] = true;
         }
         $aAppData['IsMailsuite'] = $oApiCapability->isMailsuite();
     }
     $iIdTenant = 0;
     /*		TODO: sash
     		if (\CApi::GetConf('labs.allow-social-integration', true))
     		{
     			\api_Social::init($aAppData, $sHelpdeskTenantHash);
     		}
     */
     if (0 < $aAppData['LastErrorCode']) {
         $this->clearLastErrorCode();
     }
     $oAccount = null;
     if (!empty($sCalendarPubHash)) {
         $oAccount = $this->getLogginedDefaultAccount();
         if ($oAccount) {
             $aAppData['Auth'] = true;
             $aAppData['User'] = $this->appDataUserSettings($oAccount);
         }
         $aAppData['CalendarPubHash'] = $sCalendarPubHash;
         $aAppData['IsMobile'] = 0;
         return $aAppData;
     }
     if (!empty($sFileStoragePubHash)) {
         $aAppData['FileStoragePubHash'] = $sFileStoragePubHash;
         $oMin = \CApi::Manager('min');
         $mMin = $oMin->getMinByHash($sFileStoragePubHash);
         $aAppData['FileStoragePubParams'] = array();
         if (!empty($mMin['__hash__'])) {
             $aAppData['FileStoragePubParams'] = $mMin;
         }
         $aAppData['IsMobile'] = 0;
         return $aAppData;
     }
     $oApiHelpdeskManager = CApi::Manager('helpdesk');
     /* @var $oApiHelpdeskManager CApiHelpdeskManager */
     $oApiTenant = CApi::Manager('tenants');
     /* @var $oApiTenant CApiTenantsManager */
     $oTenant = $oApiTenant ? $oApiTenant->getDefaultGlobalTenant() : null;
     $aAppData['LoginStyleImage'] = '';
     $aAppData['AppStyleImage'] = '';
     $aAppData['HelpdeskSiteName'] = '';
     $aAppData['HelpdeskStyleImage'] = '';
     if ($oTenant) {
         $aAppData['LoginStyleImage'] = $oTenant->LoginStyleImage;
         $aAppData['AppStyleImage'] = $oTenant->AppStyleImage;
     }
     $aThreadId = $this->getThreadIdFromRequestAndClear();
     $mThreadId = isset($aThreadId['id']) ? $aThreadId['id'] : null;
     $sThreadAction = isset($aThreadId['action']) ? $aThreadId['action'] : '';
     if ($bHelpdesk) {
         $aHelpdeskMainData = null;
         $aAppData['TenantHash'] = $sHelpdeskTenantHash;
         $aAppData['IsMobile'] = 0;
         $iUserId = $this->getLogginedHelpdeskUserId();
         if (0 < $iUserId && $oApiHelpdeskManager) {
             $oHelpdeskUser = $oApiHelpdeskManager->getUserById($iHelpdeskIdTenant, $iUserId);
             if ($oHelpdeskUser) {
                 $aHelpdeskMainData = $oApiHelpdeskManager->getHelpdeskMainSettings($oHelpdeskUser->IdTenant);
                 $aAppData['Auth'] = true;
                 $aAppData['HelpdeskIframeUrl'] = $oHelpdeskUser->IsAgent ? $aHelpdeskMainData['AgentIframeUrl'] : $aHelpdeskMainData['ClientIframeUrl'];
                 $aAppData['HelpdeskSiteName'] = isset($aHelpdeskMainData['SiteName']) ? $aHelpdeskMainData['SiteName'] : '';
                 $aAppData['User'] = $this->appDataHelpdeskUserSettings($oHelpdeskUser);
             }
         }
         if (!$aHelpdeskMainData && $oApiHelpdeskManager) {
             $iIdTenant = $this->getTenantIdByHash($sHelpdeskTenantHash);
             $aHelpdeskMainData = $oApiHelpdeskManager->getHelpdeskMainSettings($iIdTenant);
             $aAppData['HelpdeskSiteName'] = isset($aHelpdeskMainData['SiteName']) ? $aHelpdeskMainData['SiteName'] : '';
             $aAppData['HelpdeskStyleImage'] = isset($aHelpdeskMainData['StyleImage']) && isset($aHelpdeskMainData['StyleAllow']) ? $aHelpdeskMainData['StyleImage'] : '';
         }
         $oHttp = \MailSo\Base\Http::SingletonInstance();
         $aAppData['HelpdeskForgotHash'] = $oHttp->GetRequest('forgot', '');
         if (0 === strlen($aAppData['HelpdeskForgotHash'])) {
             $aAppData['HelpdeskThreadId'] = null === $mThreadId ? 0 : $mThreadId;
             $aAppData['HelpdeskActivatedEmail'] = $this->getActivatedUserEmailAndClear();
         }
         $aAppData['App'] = array();
         $aAppData['App']['DateFormats'] = array();
         foreach (array(EDateFormat::MMDDYYYY, EDateFormat::DDMMYYYY, EDateFormat::DD_MONTH_YYYY) as $sDateFmtName) {
             $aAppData['App']['DateFormats'][] = $sDateFmtName;
         }
         return $aAppData;
     } else {
         $aAppData['HelpdeskRedirect'] = is_int($mThreadId);
         $aAppData['HelpdeskThreadId'] = null === $mThreadId ? 0 : $mThreadId;
         $aAppData['HelpdeskThreadAction'] = $sThreadAction ? $sThreadAction : '';
     }
     $oDefaultAccount = null;
     $oDomain = null;
     $iUserId = $this->getLogginedUserId($sAuthToken);
     if (0 < $iUserId) {
         /* @var $oApiUsersManager CApiUsersManager */
         $oApiUsersManager = CApi::Manager('users');
         $aInfo = $oApiUsersManager->getUserAccounts($iUserId);
         if (is_array($aInfo) && 0 < count($aInfo)) {
             $aAppData['Auth'] = true;
             $iDefault = 0;
             $iDefaultIndex = 0;
             $aAccounts = array();
             $aDefaultAccount = array();
             foreach ($aInfo as $iAccountId => $aData) {
                 if (is_array($aData) && !empty($aData[1])) {
                     $aAccount = array('AccountID' => $iAccountId, 'Email' => $aData[1], 'FriendlyName' => $aData[2], 'Signature' => array('Signature' => $aData[3], 'Type' => $aData[4], 'Options' => $aData[5]), 'IsPasswordSpecified' => $aData[6], 'AllowMail' => $aData[7]);
                     if ($aData[0]) {
                         $aDefaultAccount = $aAccount;
                         $iDefault = $iAccountId;
                         $iDefaultIndex = count($aAccounts);
                     } else {
                         $aAccounts[] = $aAccount;
                     }
                 }
             }
             $aAppData['Default'] = $iDefault;
             $oDefaultAccount = $oApiUsersManager->getAccountById($iDefault);
             if ($oDefaultAccount) {
                 $aAppData['User'] = $this->appDataUserSettings($oDefaultAccount);
                 if ($oApiHelpdeskManager) {
                     $aData = $oApiHelpdeskManager->getHelpdeskMainSettings($oDefaultAccount->IdTenant);
                     $aAppData['HelpdeskIframeUrl'] = isset($aAppData['User']['IsHelpdeskAgent']) && $aAppData['User']['IsHelpdeskAgent'] ? $aData['AgentIframeUrl'] : $aData['ClientIframeUrl'];
                 }
             }
         }
     }
     if ($aAppData['Auth']) {
         if (0 < $oDefaultAccount->IdTenant) {
             $aAppData['AppStyleImage'] = '';
             $oAccountTenant = $oApiTenant ? 0 < $oDefaultAccount->IdTenant ? $oApiTenant->getTenantById($oDefaultAccount->IdTenant) : $oApiTenant->getDefaultGlobalTenant() : null;
             if ($oAccountTenant) {
                 $aAppData['AppStyleImage'] = $oAccountTenant->AppStyleImage;
             }
         }
     }
     $oDomain = $this->getDefaultAccountDomain($oDefaultAccount);
     if ($oDefaultAccount) {
         array_splice($aAccounts, $iDefaultIndex, 0, array($aDefaultAccount));
         $aAppData['Accounts'] = $aAccounts;
     }
     $aAppData['App'] = $this->appDataDomainSettings($oDomain, $oDefaultAccount);
     if (!isset($aAppData['Plugins'])) {
         $aAppData['Plugins'] = array();
     }
     $aAppData['HelpdeskThreadId'] = null === $aAppData['HelpdeskThreadId'] ? 0 : $aAppData['HelpdeskThreadId'];
     CApi::Plugin()->RunHook('api-app-data', array($oDefaultAccount, &$aAppData));
     return $aAppData;
 }
Example #13
0
 public static function Dropbox($oTenant)
 {
     $bResult = false;
     $oUser = null;
     $bDropboxAllow = $oTenant->SocialDropboxAllow;
     $sDropboxId = $oTenant->SocialDropboxKey;
     $sDropboxSecret = $oTenant->SocialDropboxSecret;
     $sRedirectUrl = rtrim(\MailSo\Base\Http::SingletonInstance()->GetFullUrl(), '\\/ ') . '/?dropbox';
     if (!strpos($sRedirectUrl, '://localhost')) {
         $sRedirectUrl = str_replace('http:', 'https:', $sRedirectUrl);
     }
     if ($bDropboxAllow) {
         require PSEVEN_APP_ROOT_PATH . 'libraries/OAuthClient/http.php';
         require PSEVEN_APP_ROOT_PATH . 'libraries/OAuthClient/oauth_client.php';
         $oClient = new \oauth_client_class();
         $oClient->debug = self::$Debug;
         $oClient->debug_http = self::$Debug;
         $oClient->server = 'Dropbox2';
         $oClient->redirect_uri = $sRedirectUrl;
         $oClient->client_id = $sDropboxId;
         $application_line = __LINE__;
         $oClient->client_secret = $sDropboxSecret;
         $oClient->configuration_file = PSEVEN_APP_ROOT_PATH . 'libraries/OAuthClient/' . $oClient->configuration_file;
         if (strlen($oClient->client_id) == 0 || strlen($oClient->client_secret) == 0) {
             $bResult = false;
             exit('Please go to Dropbox Apps page https://www.dropbox.com/developers/apps , ' . 'create an application, and in the line ' . $application_line . ' set the client_id to Consumer key and client_secret with Consumer secret. ' . 'The Callback URL must be ' . $oClient->redirect_uri) . ' Make sure this URL is ' . 'not in a private network and accessible to the Dropbox site.';
         }
         if ($success = $oClient->Initialize()) {
             if ($success = $oClient->Process()) {
                 if (strlen($oClient->access_token)) {
                     $success = $oClient->CallAPI('https://api.dropbox.com/1/account/info', 'GET', array(), array('FailOnAccessError' => true), $oUser);
                 }
             }
             $success = $oClient->Finalize($success);
         }
         if ($oClient->exit) {
             $bResult = false;
             exit;
         }
         if ($success && $oUser) {
             // if you need re-ask user for permission
             //$oClient->ResetAccessToken();
             $aSocial = array('type' => 'dropbox', 'id' => $oUser->uid, 'name' => $oUser->display_name, 'email' => isset($oUser->email) ? $oUser->email : '', 'access_token' => $oClient->access_token);
             \CApi::Log('social_user_dropbox');
             \CApi::LogObject($oUser);
             $bResult = $aSocial;
         } else {
             $bResult = false;
             $oClient->ResetAccessToken();
             self::_socialError($oClient->error, 'dropbox');
         }
     }
     return $bResult;
 }
Example #14
0
 /**
  * @param string $sVersion
  */
 public function __construct($sName, $sPath, $sVersion = '1.0')
 {
     $this->sVersion = (string) $sVersion;
     $this->sName = $sName;
     $this->sPath = $sPath . $sName;
     $this->aParameters = array();
     $this->oApiCapabilityManager = \CApi::GetSystemManager('capability');
     $this->oHttp = \MailSo\Base\Http::SingletonInstance();
     $this->aEntries = array('api' => 'EntryApi', 'download' => 'EntryDownload');
 }
Example #15
0
 public static function validateAuthToken()
 {
     $bResult = true;
     if (isset($_COOKIE[\System\Service::AUTH_TOKEN_KEY])) {
         $oHttp = \MailSo\Base\Http::SingletonInstance();
         $sAuthToken = $oHttp->GetPost('AuthToken', '');
         $bResult = $sAuthToken === $_COOKIE[\System\Service::AUTH_TOKEN_KEY];
     }
     return $bResult;
 }
Example #16
0
 /**
  * @return string
  */
 public static function WebPath()
 {
     $sAppPath = '';
     if (\RainLoop\Utils::IsOwnCloud()) {
         if (\class_exists('OC_App')) {
             $sAppPath = \rtrim(\trim(\OC_App::getAppWebPath('rainloop')), '\\/') . '/app/';
         }
         if (empty($sAppPath)) {
             $sUrl = \MailSo\Base\Http::SingletonInstance()->GetUrl();
             if ($sUrl && \preg_match('/\\/index\\.php\\/apps\\/rainloop/', $sUrl)) {
                 $sAppPath = \preg_replace('/\\/index\\.php\\/apps\\/rainloop.+$/', '/apps/rainloop/app/', $sUrl);
             }
         }
     }
     return $sAppPath;
 }
Example #17
0
 public static function GetGoogleUserInfo($sGoogleAPIKey, $sAccessToken = null)
 {
     $mResult = false;
     $sUrl = "https://www.googleapis.com/plus/v1/people/me?key=" . $sGoogleAPIKey;
     $aHeaders = $sAccessToken ? array('Authorization: Bearer ' . $sAccessToken) : array();
     $sContentType = '';
     $iCode = 0;
     $mResult = \MailSo\Base\Http::SingletonInstance()->GetUrlAsString($sUrl, '', $sContentType, $iCode, null, 10, '', '', $aHeaders);
     return $iCode === 200 ? json_decode($mResult) : false;
 }
Example #18
0
 /**
  * @return void
  */
 public function Handle()
 {
     $mResult = '';
     $bError = false;
     $bIsHtml = false;
     $this->GetVersion();
     $this->CheckApi();
     $this->RedirectToHttps();
     $aPaths = self::GetPaths();
     $aModules = array();
     if (0 < count($aPaths) && !empty($aPaths[0])) {
         $sEntry = strtolower($aPaths[0]);
         $oModule = $this->oModuleManager->GetModuleFromRequest();
         if ($oModule instanceof \AApiModule) {
             if ($oModule->HasEntry($sEntry)) {
                 $aModules[] = $oModule;
             } else {
                 $mResult = '\'' . $sEntry . '\' entry not found in \'' . $oModule->GetName() . '\' module.';
                 $bError = true;
             }
         } else {
             if ($sEntry === 'api') {
                 $oCoreModule = \CApi::GetModule('Core');
                 if ($oCoreModule instanceof \AApiModule) {
                     $aModules[] = $oCoreModule;
                 }
             } else {
                 $aModules = $this->oModuleManager->GetModulesByEntry($sEntry);
             }
         }
         if (!$bError) {
             if (count($aModules) > 0) {
                 foreach ($aModules as $oModule) {
                     $mEntryResult = $oModule->RunEntry($sEntry);
                     if ($mEntryResult !== 'null') {
                         $mResult .= $mEntryResult;
                     }
                 }
             } else {
                 $bIsHtml = true;
             }
         }
     } else {
         $bIsHtml = true;
     }
     if ($bIsHtml) {
         $mResult = $this->generateHTML();
     }
     $oHttp = \MailSo\Base\Http::SingletonInstance();
     if ($oHttp->GetRequest('Format') !== 'Raw') {
         echo $mResult;
     }
 }