diff --git a/build/owncloud/rainloop-app/app.php b/build/owncloud/rainloop-app/app.php index 94fdee86e..9fe0f27f8 100644 --- a/build/owncloud/rainloop-app/app.php +++ b/build/owncloud/rainloop-app/app.php @@ -6,5 +6,29 @@ if (@file_exists(__DIR__.'/app/index.php')) OC_RainLoop_Helper::regRainLoopDataFunction(); + if (isset($_GET['OwnCloudAuth'])) + { + $sEmail = ''; + $sEncodedPassword = ''; + + $sUser = OCP\User::getUser(); + + if ($bAutologin) + { + $sEmail = $sUser; + $sEncodedPassword = OCP\Config::getUserValue($sUser, 'rainloop', 'rainloop-autologin-password', ''); + } + else + { + $sEmail = OCP\Config::getUserValue($sUser, 'rainloop', 'rainloop-email', ''); + $sEncodedPassword = OCP\Config::getUserValue($sUser, 'rainloop', 'rainloop-password', ''); + } + + $sDecodedPassword = OC_RainLoop_Helper::decodePassword($sEncodedPassword, md5($sEmail)); + + $_ENV['___rainloop_owncloud_email'] = $sEmail; + $_ENV['___rainloop_owncloud_password'] = $sDecodedPassword; + } + include __DIR__.'/app/index.php'; } diff --git a/build/owncloud/rainloop-app/appinfo/info.xml b/build/owncloud/rainloop-app/appinfo/info.xml index 776d340e5..7ec7dbdd9 100644 --- a/build/owncloud/rainloop-app/appinfo/info.xml +++ b/build/owncloud/rainloop-app/appinfo/info.xml @@ -2,12 +2,12 @@ rainloop RainLoop - Simple, modern & fast web-based email client. - -Modest system requirements, decent performance, simple installation and upgrade, no database required - -all these make RainLoop Webmail a perfect choice for your email solution. + Simple, modern and fast web-based email client. 0.0 CC BY-NC-SA 3.0 RainLoop Team 6.0 + + + \ No newline at end of file diff --git a/build/owncloud/rainloop-app/index.php b/build/owncloud/rainloop-app/index.php index c38d27def..9de5e2c4a 100644 --- a/build/owncloud/rainloop-app/index.php +++ b/build/owncloud/rainloop-app/index.php @@ -38,25 +38,32 @@ if ('' === $sUrl || '' === $sPath) } else { - $sUser = OCP\User::getUser(); - - if ($bAutologin) + $sUrl = OC_RainLoop_Helper::normalizeUrl($sUrl); + if ($bInstalledLocaly) { - $sEmail = $sUser; - $sEncodedPassword = OCP\Config::getUserValue($sUser, 'rainloop', 'rainloop-autologin-password', ''); + $sResultUrl = $sUrl.'?OwnCloudAuth'; } else { - $sEmail = OCP\Config::getUserValue($sUser, 'rainloop', 'rainloop-email', ''); - $sEncodedPassword = OCP\Config::getUserValue($sUser, 'rainloop', 'rainloop-password', ''); + $sUser = OCP\User::getUser(); + + if ($bAutologin) + { + $sEmail = $sUser; + $sEncodedPassword = OCP\Config::getUserValue($sUser, 'rainloop', 'rainloop-autologin-password', ''); + } + else + { + $sEmail = OCP\Config::getUserValue($sUser, 'rainloop', 'rainloop-email', ''); + $sEncodedPassword = OCP\Config::getUserValue($sUser, 'rainloop', 'rainloop-password', ''); + } + + $sDecodedPassword = OC_RainLoop_Helper::decodePassword($sEncodedPassword, md5($sEmail)); + + $sSsoHash = OC_RainLoop_Helper::getSsoHash($sPath, $sEmail, $sDecodedPassword); + $sResultUrl = empty($sSsoHash) ? $sUrl.'?sso' : $sUrl.'?sso&hash='.$sSsoHash; } - $sDecodedPassword = OC_RainLoop_Helper::decodePassword($sEncodedPassword, md5($sEmail)); - $sSsoHash = OC_RainLoop_Helper::getSsoHash($sPath, $sEmail, $sDecodedPassword); - - $sUrl = OC_RainLoop_Helper::normalizeUrl($sUrl); - $sResultUrl = empty($sSsoHash) ? $sUrl.'?sso' : $sUrl.'?sso&hash='.$sSsoHash; - $oTemplate = new OCP\Template('rainloop', 'index', 'user'); $oTemplate->assign('rainloop-url', $sResultUrl); } diff --git a/build/owncloud/rainloop-app/lib/RainLoopHelper.php b/build/owncloud/rainloop-app/lib/RainLoopHelper.php index eb3d1cdf5..c3d1ec1cd 100644 --- a/build/owncloud/rainloop-app/lib/RainLoopHelper.php +++ b/build/owncloud/rainloop-app/lib/RainLoopHelper.php @@ -7,6 +7,15 @@ class OC_RainLoop_Helper */ public static function getAppUrl() { + if (class_exists('\\OC\\URLGenerator') && isset(\OC::$server)) + { + $oUrlGenerator = new \OC\URLGenerator(\OC::$server->getConfig()); + if ($oUrlGenerator) + { + return $oUrlGenerator->linkToRoute('rainloop_app'); + } + } + $sRequestUri = empty($_SERVER['REQUEST_URI']) ? '': trim($_SERVER['REQUEST_URI']); $sRequestUri = preg_replace('/index.php\/.+$/', 'index.php/', $sRequestUri); $sRequestUri = $sRequestUri.'apps/rainloop/app/'; diff --git a/dev/Common/Links.js b/dev/Common/Links.js index 8255bce82..3a2d2564d 100644 --- a/dev/Common/Links.js +++ b/dev/Common/Links.js @@ -21,7 +21,9 @@ this.sSubSubQuery = '&ss=/'; this.sVersion = Settings.settingsGet('Version'); this.sSpecSuffix = Settings.settingsGet('AuthAccountHash') || '0'; - this.sStaticPrefix = Settings.settingsGet('StaticPrefix') || 'rainloop/v/' + this.sVersion + '/static/'; + this.sWebPrefix = Settings.settingsGet('WebPath') || ''; + this.sVersionPrefix = Settings.settingsGet('WebVersionPath') || 'rainloop/v/' + this.sVersion + '/'; + this.sStaticPrefix = this.sVersionPrefix + 'static/'; } /** @@ -330,11 +332,11 @@ */ Links.prototype.themePreviewLink = function (sTheme) { - var sPrefix = 'rainloop/v/' + this.sVersion + '/'; + var sPrefix = this.sVersionPrefix; if ('@custom' === sTheme.substr(-7)) { sTheme = Utils.trim(sTheme.substring(0, sTheme.length - 7)); - sPrefix = ''; + sPrefix = this.sWebPrefix; } return sPrefix + 'themes/' + window.encodeURI(sTheme) + '/images/preview.png'; diff --git a/rainloop/v/0.0.0/app/libraries/RainLoop/Actions.php b/rainloop/v/0.0.0/app/libraries/RainLoop/Actions.php index d6dbab2b4..df038119d 100644 --- a/rainloop/v/0.0.0/app/libraries/RainLoop/Actions.php +++ b/rainloop/v/0.0.0/app/libraries/RainLoop/Actions.php @@ -512,6 +512,7 @@ class Actions */ public function SetAuthLogoutToken() { + @\header('X-RainLoop-Action: Logout'); \RainLoop\Utils::SetCookie(self::AUTH_SPEC_LOGOUT_TOKEN_KEY, \md5(APP_START_TIME), 0, '/', null, null, true); } @@ -941,6 +942,7 @@ class Actions '][APC:'.(\MailSo\Base\Utils::FunctionExistsAndEnabled('apc_fetch') ? 'on' : 'off'). '][MB:'.(\MailSo\Base\Utils::FunctionExistsAndEnabled('mb_convert_encoding') ? 'on' : 'off'). '][PDO:'.$sPdo. + (\RainLoop\Utils::IsOwnCloud() ? '][ownCloud:true' : ''). '][Streams:'.\implode(',', \stream_get_transports()). ']'); @@ -1218,7 +1220,8 @@ class Actions 'Version' => APP_VERSION, 'Auth' => false, 'AccountHash' => '', - 'StaticPrefix' => 'rainloop/v/'.APP_VERSION.'/static/', + 'WebPath' => \RainLoop\Utils::WebPath(), + 'WebVersionPath' => \RainLoop\Utils::WebVersionPath(), 'AccountSignMe' => false, 'AuthAccountHash' => '', 'MailToEmail' => '', diff --git a/rainloop/v/0.0.0/app/libraries/RainLoop/Service.php b/rainloop/v/0.0.0/app/libraries/RainLoop/Service.php index 2a8fee58b..b079fe8b8 100644 --- a/rainloop/v/0.0.0/app/libraries/RainLoop/Service.php +++ b/rainloop/v/0.0.0/app/libraries/RainLoop/Service.php @@ -187,6 +187,12 @@ class Service $sResult .= '][cached:'.($bCached ? 'true' : 'false'); $sResult .= '][hash:'.$aTemplateParameters['{{BaseHash}}']; $sResult .= '][session:'.\md5(\RainLoop\Utils::GetShortToken()); + + if (\RainLoop\Utils::IsOwnCloud()) + { + $sResult .= '][owncloud:true'; + } + $sResult .= '] -->'; } @@ -219,7 +225,7 @@ class Service $bAppJsDebug = !!$this->oActions->Config()->Get('labs', 'use_app_debug_js', false); $bAppCssDebug = !!$this->oActions->Config()->Get('labs', 'use_app_debug_css', false); - $sStaticPrefix = $this->oServiceActions->WebStaticPath(); + $sStaticPrefix = \RainLoop\Utils::WebStaticPath(); $aData = array( 'Language' => $sLanguage, @@ -257,7 +263,7 @@ class Service \implode('~', array( \md5($this->oActions->Config()->Get('cache', 'index', '')), $this->oActions->Plugins()->Hash(), - $this->oServiceActions->WebVersionPath(), APP_VERSION + \RainLoop\Utils::WebVersionPath(), APP_VERSION )). \implode('~', $aTemplateParameters) ); diff --git a/rainloop/v/0.0.0/app/libraries/RainLoop/ServiceActions.php b/rainloop/v/0.0.0/app/libraries/RainLoop/ServiceActions.php index bd8f63976..a894b507a 100644 --- a/rainloop/v/0.0.0/app/libraries/RainLoop/ServiceActions.php +++ b/rainloop/v/0.0.0/app/libraries/RainLoop/ServiceActions.php @@ -221,6 +221,45 @@ class ServiceActions return $sResult; } + /** + * @return string + */ + public function ServiceOwnCloudAuth() + { + if (!\RainLoop\Utils::IsOwnCloud() || + empty($_ENV['___rainloop_owncloud_email']) && + !isset($_ENV['___rainloop_owncloud_password']) + ) + { + $this->oActions->SetAuthLogoutToken(); + $this->oActions->Location('./'); + return ''; + } + + $sEmail = $_ENV['___rainloop_owncloud_email']; + $sPassword = $_ENV['___rainloop_owncloud_password']; + + try + { + $oAccount = $this->oActions->LoginProcess($sEmail, $sPassword); + $this->oActions->AuthToken($oAccount); + + $bLogout = !($oAccount instanceof \RainLoop\Model\Account); + } + catch (\Exception $oException) + { + $this->oActions->Logger()->WriteException($oException); + } + + if ($bLogout) + { + $this->oActions->SetAuthLogoutToken(); + } + + $this->oActions->Location('./'); + return ''; + } + /** * @return string */ @@ -675,7 +714,10 @@ class ServiceActions if (\file_exists($sThemeFile) && \file_exists($sThemeTemplateFile) && \file_exists($sThemeValuesFile)) { - $aResult[] = '@base: "'.($bCustomTheme ? $this->WebPath() : $this->WebVersionPath()).'themes/'.$sRealTheme.'/";'; + $aResult[] = '@base: "'. + ($bCustomTheme ? \RainLoop\Utils::WebPath() : \RainLoop\Utils::WebVersionPath()). + 'themes/'.$sRealTheme.'/";'; + $aResult[] = \file_get_contents($sThemeValuesFile); $aResult[] = \file_get_contents($sThemeFile); $aResult[] = \file_get_contents($sThemeTemplateFile); @@ -779,7 +821,7 @@ class ServiceActions @\header('Content-Type: text/html; charset=utf-8'); return \strtr(\file_get_contents(APP_VERSION_ROOT_PATH.'app/templates/BadBrowser.html'), array( - '{{BaseWebStaticPath}}' => $this->WebStaticPath(), + '{{BaseWebStaticPath}}' => \RainLoop\Utils::WebStaticPath(), '{{ErrorTitle}}' => $sTitle, '{{ErrorHeader}}' => $sTitle, '{{ErrorDesc}}' => $sDesc @@ -1060,7 +1102,7 @@ class ServiceActions public function ErrorTemplates($sTitle, $sDesc, $bShowBackLink = true) { return strtr(file_get_contents(APP_VERSION_ROOT_PATH.'app/templates/Error.html'), array( - '{{BaseWebStaticPath}}' => $this->WebStaticPath(), + '{{BaseWebStaticPath}}' => \RainLoop\Utils::WebStaticPath(), '{{ErrorTitle}}' => $sTitle, '{{ErrorHeader}}' => $sTitle, '{{ErrorDesc}}' => $sDesc, @@ -1070,39 +1112,6 @@ class ServiceActions )); } - /** - * @return string - */ - public function WebPath() - { - if (isset($_ENV['RAINLOOP_OWNCLOUD']) && $_ENV['RAINLOOP_OWNCLOUD']) - { - $sUrl = $this->oHttp->GetUrl(); - if ($sUrl && \preg_match('/\/index\.php\/apps\/rainloop/', $sUrl)) - { - $sUrl = \preg_replace('/\/index\.php\/apps\/rainloop.+$/', '/', $sUrl); - return \rtrim(\trim($sUrl), '\//').'/apps/rainloop/app/'; - } - } - - return ''; - } - /** - * @return string - */ - public function WebVersionPath() - { - return $this->WebPath().'rainloop/v/'.APP_VERSION.'/'; - } - - /** - * @return string - */ - public function WebStaticPath() - { - return $this->WebVersionPath().'static/'; - } - /** * @param string $sTitle * @param string $sDesc diff --git a/rainloop/v/0.0.0/app/libraries/RainLoop/Utils.php b/rainloop/v/0.0.0/app/libraries/RainLoop/Utils.php index f04983e7e..12e49f1da 100644 --- a/rainloop/v/0.0.0/app/libraries/RainLoop/Utils.php +++ b/rainloop/v/0.0.0/app/libraries/RainLoop/Utils.php @@ -307,6 +307,57 @@ class Utils @\setcookie($sName, '', \time() - 3600 * 24 * 30, '/'); } + /** + * @return bool + */ + public static function IsOwnCloud() + { + return isset($_ENV['RAINLOOP_OWNCLOUD']) && $_ENV['RAINLOOP_OWNCLOUD'] && + \class_exists('\\OC'); + } + + /** + * @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; + } + /** + * @return string + */ + public static function WebVersionPath() + { + return self::WebPath().'rainloop/v/'.APP_VERSION.'/'; + } + + /** + * @return string + */ + public static function WebStaticPath() + { + return self::WebVersionPath().'static/'; + } + /** * @param string $sFileName * @param bool $bProcessSections = false