コード例 #1
0
 /**
  * @return \MailSo\Cache\CacheClient
  */
 public function Cacher()
 {
     return $this->oActions->Cacher();
 }
コード例 #2
0
ファイル: Social.php プロジェクト: GTAWWEKID/tsiserver.us
 /**
  * @return string
  */
 public function TwitterPopupService()
 {
     $sResult = '';
     $sLoginUrl = '';
     $sSocialName = '';
     $bLogin = false;
     $iErrorCode = \RainLoop\Notifications::UnknownError;
     $sRedirectUrl = $this->oHttp->GetFullUrl() . '?SocialTwitter';
     if (0 < strlen($this->oActions->GetSpecAuthToken())) {
         $sRedirectUrl .= '&rlah=' . $this->oActions->GetSpecAuthToken();
     } else {
         if ($this->oHttp->HasQuery('rlah')) {
             $this->oActions->SetSpecAuthToken($this->oHttp->GetQuery('rlah', ''));
             $sRedirectUrl .= '&rlah=' . $this->oActions->GetSpecAuthToken();
         }
     }
     try {
         $oTwitter = $this->TwitterConnector();
         if ($oTwitter) {
             $sSessionKey = \implode('_', array('twitter', \md5($oTwitter->config['consumer_secret']), \md5(\RainLoop\Utils::GetConnectionToken()), 'AuthSessionData'));
             $oAccount = $this->oActions->GetAccount();
             if ($oAccount) {
                 if (isset($_REQUEST['oauth_verifier'])) {
                     $sAuth = $this->oActions->Cacher()->Get($sSessionKey);
                     $oAuth = $sAuth ? \json_decode($sAuth, true) : null;
                     if ($oAuth && !empty($oAuth['oauth_token']) && !empty($oAuth['oauth_token_secret'])) {
                         $oTwitter->config['user_token'] = $oAuth['oauth_token'];
                         $oTwitter->config['user_secret'] = $oAuth['oauth_token_secret'];
                         $iCode = $oTwitter->request('POST', $oTwitter->url('oauth/access_token', ''), array('oauth_callback' => $sRedirectUrl, 'oauth_verifier' => $_REQUEST['oauth_verifier']));
                         if (200 === $iCode && isset($oTwitter->response['response'])) {
                             $this->oActions->Logger()->WriteDump($oTwitter->response['response']);
                             $aAccessToken = $oTwitter->extract_params($oTwitter->response['response']);
                             $this->oActions->Logger()->WriteDump($aAccessToken);
                             if ($aAccessToken && isset($aAccessToken['oauth_token']) && !empty($aAccessToken['user_id'])) {
                                 $oTwitter->config['user_token'] = $aAccessToken['oauth_token'];
                                 $oTwitter->config['user_secret'] = $aAccessToken['oauth_token_secret'];
                                 $sSocialName = !empty($aAccessToken['screen_name']) ? '@' . $aAccessToken['screen_name'] : $aAccessToken['user_id'];
                                 $sSocialName = \trim($sSocialName);
                                 $aUserData = array('Email' => $oAccount->Email(), 'Password' => $oAccount->Password());
                                 $oSettings = $this->oActions->SettingsProvider()->Load($oAccount);
                                 $oSettings->SetConf('TwitterAccessToken', \RainLoop\Utils::EncodeKeyValues($aAccessToken));
                                 $oSettings->SetConf('TwitterSocialName', $sSocialName);
                                 $this->oActions->SettingsProvider()->Save($oAccount, $oSettings);
                                 $this->oActions->StorageProvider()->Put(null, \RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY, $this->TwitterUserLoginStorageKey($oTwitter, $aAccessToken['user_id']), \RainLoop\Utils::EncodeKeyValues($aUserData));
                                 $iErrorCode = 0;
                             }
                         }
                     }
                 } else {
                     $aParams = array('oauth_callback' => $sRedirectUrl, 'x_auth_access_type' => 'read');
                     $iCode = $oTwitter->request('POST', $oTwitter->url('oauth/request_token', ''), $aParams);
                     if (200 === $iCode && isset($oTwitter->response['response'])) {
                         $oAuth = $oTwitter->extract_params($oTwitter->response['response']);
                         if (!empty($oAuth['oauth_token'])) {
                             $this->oActions->Cacher()->Set($sSessionKey, \json_encode($oAuth));
                             $sLoginUrl = $oTwitter->url('oauth/authenticate', '') . '?oauth_token=' . $oAuth['oauth_token'];
                         }
                     }
                 }
             } else {
                 $bLogin = true;
                 if (isset($_REQUEST['oauth_verifier'])) {
                     $sAuth = $this->oActions->Cacher()->Get($sSessionKey);
                     $oAuth = $sAuth ? \json_decode($sAuth, true) : null;
                     if ($oAuth && !empty($oAuth['oauth_token']) && !empty($oAuth['oauth_token_secret'])) {
                         $oTwitter->config['user_token'] = $oAuth['oauth_token'];
                         $oTwitter->config['user_secret'] = $oAuth['oauth_token_secret'];
                         $iCode = $oTwitter->request('POST', $oTwitter->url('oauth/access_token', ''), array('oauth_callback' => $sRedirectUrl, 'oauth_verifier' => $_REQUEST['oauth_verifier']));
                         if (200 === $iCode && isset($oTwitter->response['response'])) {
                             $aAccessToken = $oTwitter->extract_params($oTwitter->response['response']);
                             if ($aAccessToken && isset($aAccessToken['oauth_token']) && !empty($aAccessToken['user_id'])) {
                                 $sUserData = $this->oActions->StorageProvider()->Get(null, \RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY, $this->TwitterUserLoginStorageKey($oTwitter, $aAccessToken['user_id']));
                                 $aUserData = \RainLoop\Utils::DecodeKeyValues($sUserData);
                                 if ($aUserData && \is_array($aUserData) && !empty($aUserData['Email']) && isset($aUserData['Password'])) {
                                     $oAccount = $this->oActions->LoginProcess($aUserData['Email'], $aUserData['Password']);
                                     if ($oAccount instanceof \RainLoop\Account) {
                                         $this->oActions->AuthProcess($oAccount);
                                         $iErrorCode = 0;
                                     }
                                 } else {
                                     $iErrorCode = \RainLoop\Notifications::SocialTwitterLoginAccessDisable;
                                 }
                                 $this->oActions->Cacher()->Delete($sSessionKey);
                             }
                         }
                     }
                 } else {
                     $aParams = array('oauth_callback' => $sRedirectUrl, 'x_auth_access_type' => 'read');
                     $iCode = $oTwitter->request('POST', $oTwitter->url('oauth/request_token', ''), $aParams);
                     if (200 === $iCode && isset($oTwitter->response['response'])) {
                         $oAuth = $oTwitter->extract_params($oTwitter->response['response']);
                         if (!empty($oAuth['oauth_token'])) {
                             $this->oActions->Cacher()->Set($sSessionKey, \json_encode($oAuth));
                             $sLoginUrl = $oTwitter->url('oauth/authenticate', '') . '?oauth_token=' . $oAuth['oauth_token'];
                         }
                     }
                 }
             }
         }
     } catch (\Exception $oException) {
         $this->oActions->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR);
     }
     if ($sLoginUrl) {
         $this->oActions->Location($sLoginUrl);
     } else {
         @\header('Content-Type: text/html; charset=utf-8');
         $sCallBackType = $bLogin ? '_login' : '';
         $sConnectionFunc = 'rl_' . \md5(\RainLoop\Utils::GetConnectionToken()) . '_twitter' . $sCallBackType . '_service';
         $sResult = '<script type="text/javascript" data-cfasync="false">opener && opener.' . $sConnectionFunc . ' && opener.' . $sConnectionFunc . '(' . $iErrorCode . '); self && self.close && self.close();</script>';
     }
     return $sResult;
 }
コード例 #3
0
ファイル: Service.php プロジェクト: helsaba/rainloop-webmail
 /**
  * @return \RainLoop\Service
  */
 private function localHandle()
 {
     if (!\class_exists('MailSo\\Version')) {
         return $this;
     }
     $this->oActions->BootStart();
     $sResult = '';
     $bCached = false;
     $sQuery = $this->oActions->ParseQueryAuthString();
     $this->oActions->Plugins()->RunHook('filter.http-query', array(&$sQuery));
     $aPaths = \explode('/', $sQuery);
     $this->oActions->Plugins()->RunHook('filter.http-paths', array(&$aPaths));
     $bAdmin = false;
     $sAdminPanelHost = $this->oActions->Config()->Get('security', 'admin_panel_host', '');
     if (empty($sAdminPanelHost)) {
         $bAdmin = !empty($aPaths[0]) && \in_array(\strtolower($aPaths[0]), array('admin', 'cp'));
     } else {
         if (empty($aPaths[0]) && \MailSo\Base\Utils::StrToLowerIfAscii($sAdminPanelHost) === \MailSo\Base\Utils::StrToLowerIfAscii($this->oHttp->GetHost())) {
             $bAdmin = true;
         }
     }
     if ($this->oHttp->IsPost()) {
         $this->oHttp->ServerNoCache();
     }
     if ($bAdmin && !$this->oActions->Config()->Get('security', 'allow_admin_panel', true)) {
         echo $this->oServiceActions->ErrorTemplates('Access Denied.', 'Access to the RainLoop Webmail Admin Panel is not allowed!', true);
         return $this;
     }
     $bIndex = true;
     if (0 < \count($aPaths) && !empty($aPaths[0]) && !$bAdmin && 'index' !== $aPaths[0]) {
         $bIndex = false;
         $sMethodName = 'Service' . $aPaths[0];
         if (\method_exists($this->oServiceActions, $sMethodName) && \is_callable(array($this->oServiceActions, $sMethodName))) {
             $this->oServiceActions->SetQuery($sQuery)->SetPaths($aPaths);
             $sResult = \call_user_func(array($this->oServiceActions, $sMethodName));
         } else {
             if (!$this->oActions->Plugins()->RunAdditionalPart($aPaths[0], $aPaths)) {
                 $bIndex = true;
             }
         }
     }
     if ($bIndex) {
         @\header('Content-Security-Policy:');
         @\header_remove('Content-Security-Policy');
         @header('Content-Type: text/html; charset=utf-8');
         $this->oHttp->ServerNoCache();
         if (!@\is_dir(APP_DATA_FOLDER_PATH) || !@\is_writable(APP_DATA_FOLDER_PATH)) {
             echo $this->oServiceActions->ErrorTemplates('Permission denied!', 'RainLoop Webmail cannot access to the data folder "' . APP_DATA_FOLDER_PATH . '"');
             return $this;
         }
         $aTemplateParameters = $this->indexTemplateParameters($bAdmin);
         $sCacheFileName = '';
         if ($this->oActions->Config()->Get('labs', 'cache_system_data', true)) {
             $sCacheFileName = 'TMPL:' . $aTemplateParameters['{{BaseHash}}'];
             $sResult = $this->oActions->Cacher()->Get($sCacheFileName);
         }
         if (0 === \strlen($sResult)) {
             //				$aTemplateParameters['{{BaseTemplates}}'] = $this->oServiceActions->compileTemplates($bAdmin, false);
             $sResult = \strtr(\file_get_contents(APP_VERSION_ROOT_PATH . 'app/templates/Index.html'), $aTemplateParameters);
             $sResult = \RainLoop\Utils::ClearHtmlOutput($sResult);
             if (0 < \strlen($sCacheFileName)) {
                 $this->oActions->Cacher()->Set($sCacheFileName, $sResult);
             }
         } else {
             $bCached = true;
         }
         $sResult .= '<!--';
         $sResult .= ' [time:' . \substr(\microtime(true) - APP_START, 0, 6);
         //			$sResult .= '][version:'.APP_VERSION;
         if ($this->oActions->IsOpen()) {
             $sResult .= '][AGPLv3';
         }
         $sResult .= '][cached:' . ($bCached ? 'true' : 'false');
         //			$sResult .= '][hash:'.$aTemplateParameters['{{BaseHash}}'];
         //			$sResult .= '][session:'.\md5(\RainLoop\Utils::GetShortToken());
         if (\RainLoop\Utils::IsOwnCloud()) {
             $sResult .= '][owncloud:true';
         }
         $sResult .= '] //-->';
     }
     // Output result
     echo $sResult;
     unset($sResult);
     $this->oActions->BootEnd();
     return $this;
 }
コード例 #4
0
ファイル: Service.php プロジェクト: GTAWWEKID/tsiserver.us
 /**
  * @return \RainLoop\Service
  */
 public function Handle()
 {
     if (!\class_exists('MailSo\\Version')) {
         return $this;
     }
     $this->oActions->BootStart();
     $this->oActions->ParseQueryAuthString();
     $bCached = false;
     $sResult = '';
     $sQuery = \trim(\trim($this->oHttp->GetServer('QUERY_STRING', '')), ' /');
     $iPos = \strpos($sQuery, '&');
     if (0 < $iPos) {
         $sQuery = \substr($sQuery, 0, $iPos);
     }
     $this->oActions->Plugins()->RunHook('filter.http-query', array(&$sQuery));
     $aPaths = \explode('/', $sQuery);
     $this->oActions->Plugins()->RunHook('filter.http-paths', array(&$aPaths));
     $bAdmin = false;
     $sAdminPanelHost = $this->oActions->Config()->Get('security', 'admin_panel_host', '');
     if (empty($sAdminPanelHost)) {
         $bAdmin = !empty($aPaths[0]) && \in_array(\strtolower($aPaths[0]), array('admin', 'cp'));
     } else {
         if (empty($aPaths[0]) && \MailSo\Base\Utils::StrToLowerIfAscii($sAdminPanelHost) === \MailSo\Base\Utils::StrToLowerIfAscii($this->oHttp->GetHost())) {
             $bAdmin = true;
         }
     }
     if ($bAdmin && !$this->oActions->Config()->Get('security', 'allow_admin_panel', true)) {
         echo $this->oActions->ErrorTemplates('Access Denied.', 'Access to the RainLoop Webmail Admin Panel is not allowed!', true);
         return $this;
     }
     $bIndex = true;
     if (0 < \count($aPaths) && !empty($aPaths[0]) && !$bAdmin && 'index' !== $aPaths[0]) {
         $bIndex = false;
         $sMethodName = 'Service' . $aPaths[0];
         if (\method_exists($this->oServiceActions, $sMethodName) && \is_callable(array($this->oServiceActions, $sMethodName))) {
             $this->oServiceActions->SetQuery($sQuery)->SetPaths($aPaths);
             $sResult = \call_user_func(array($this->oServiceActions, $sMethodName));
         } else {
             if (!$this->oActions->Plugins()->RunAdditionalPart($aPaths[0], $aPaths)) {
                 $bIndex = true;
             }
         }
     }
     if ($bIndex) {
         @header('Content-Type: text/html; charset=utf-8');
         $this->oHttp->ServerNoCache();
         $aData = $this->startUpData($bAdmin);
         $sCacheFileName = '';
         if ($this->oActions->Config()->Get('labs', 'cache_system_data', true)) {
             $sCacheFileName = 'TMPL:' . $aData['Hash'];
             $sResult = $this->oActions->Cacher()->Get($sCacheFileName);
         }
         if (0 === \strlen($sResult)) {
             $sJsBoot = \file_get_contents(APP_VERSION_ROOT_PATH . 'static/js/boot.js');
             $sResult = \strtr(\file_get_contents(APP_VERSION_ROOT_PATH . 'app/templates/Index.html'), array('{{BaseRandHash}}' => \md5(\rand(1000, 9000) . \microtime(true)), '{{BaseAppDataScriptLink}}' => $bAdmin ? './?/AdminAppData/' : './?/AppData/', '{{BaseAppFaviconIcoFile}}' => $aData['FaviconIcoLink'], '{{BaseAppFaviconPngFile}}' => $aData['FaviconPngLink'], '{{BaseAppAppleTouchFile}}' => $aData['AppleTouchLink'], '{{BaseAppMainCssLink}}' => $aData['AppCssLink'], '{{BaseAppBootScriptSource}}' => $sJsBoot, '{{BaseAppLibsScriptLink}}' => $aData['LibJsLink'], '{{BaseAppEditorScriptLink}}' => $aData['EditorJsLink'], '{{BaseAppMainScriptLink}}' => $aData['AppJsLink'], '{{BaseAppLoadingDescription}}' => \htmlspecialchars($aData['LoadingDescription'], ENT_QUOTES | ENT_IGNORE, 'UTF-8'), '{{BaseDir}}' => \in_array($aData['Language'], array('ar', 'he', 'ur')) ? 'rtl' : 'ltr'));
             $sResult = \RainLoop\Utils::ClearHtmlOutput($sResult);
             if (0 < \strlen($sCacheFileName)) {
                 $this->oActions->Cacher()->Set($sCacheFileName, $sResult);
             }
         } else {
             $bCached = true;
         }
         $sResult .= '<!--';
         $sResult .= ' [version:' . APP_VERSION;
         $sResult .= '][time:' . \substr(\microtime(true) - APP_START, 0, 6);
         $sResult .= '][cached:' . ($bCached ? 'true' : 'false');
         $sResult .= '][session:' . \md5(\RainLoop\Utils::GetShortToken());
         $sResult .= '] -->';
     }
     // Output result
     echo $sResult;
     unset($sResult);
     $this->oActions->BootEnd();
     return $this;
 }