From 2f52f826bd4caf06a42eea79dd10d319a972ba7b Mon Sep 17 00:00:00 2001 From: Martin Porcheron Date: Sat, 9 Aug 2014 21:46:23 +0100 Subject: [PATCH] Automatic login with ownCloud credentials --- build/owncloud/rainloop-app/INSTALL | 52 ++++----- build/owncloud/rainloop-app/VERSION | 2 +- build/owncloud/rainloop-app/admin.php | 1 + build/owncloud/rainloop-app/ajax/admin.php | 3 + build/owncloud/rainloop-app/ajax/personal.php | 0 build/owncloud/rainloop-app/appinfo/app.php | 12 ++- build/owncloud/rainloop-app/appinfo/info.xml | 18 ++-- .../owncloud/rainloop-app/img/logo-64x64.png | Bin build/owncloud/rainloop-app/img/mail.png | Bin build/owncloud/rainloop-app/index.php | 100 ++++++++++-------- build/owncloud/rainloop-app/js/admin.js | 0 build/owncloud/rainloop-app/js/personal.js | 0 build/owncloud/rainloop-app/js/rainloop.js | 0 build/owncloud/rainloop-app/js/resize.js | 50 ++++----- .../rainloop-app/lib/RainLoopHelper.php | 77 ++++++++++++++ build/owncloud/rainloop-app/personal.php | 3 +- .../owncloud/rainloop-app/templates/admin.php | 51 ++++----- .../owncloud/rainloop-app/templates/empty.php | 0 .../rainloop-app/templates/index-empty.php | 0 .../owncloud/rainloop-app/templates/index.php | 4 +- .../rainloop-app/templates/personal.php | 38 +++---- 21 files changed, 259 insertions(+), 152 deletions(-) mode change 100644 => 100755 build/owncloud/rainloop-app/INSTALL mode change 100644 => 100755 build/owncloud/rainloop-app/VERSION mode change 100644 => 100755 build/owncloud/rainloop-app/ajax/personal.php mode change 100644 => 100755 build/owncloud/rainloop-app/appinfo/info.xml mode change 100644 => 100755 build/owncloud/rainloop-app/img/logo-64x64.png mode change 100644 => 100755 build/owncloud/rainloop-app/img/mail.png mode change 100644 => 100755 build/owncloud/rainloop-app/js/admin.js mode change 100644 => 100755 build/owncloud/rainloop-app/js/personal.js mode change 100644 => 100755 build/owncloud/rainloop-app/js/rainloop.js mode change 100644 => 100755 build/owncloud/rainloop-app/js/resize.js mode change 100644 => 100755 build/owncloud/rainloop-app/templates/empty.php mode change 100644 => 100755 build/owncloud/rainloop-app/templates/index-empty.php mode change 100644 => 100755 build/owncloud/rainloop-app/templates/index.php diff --git a/build/owncloud/rainloop-app/INSTALL b/build/owncloud/rainloop-app/INSTALL old mode 100644 new mode 100755 index 2f3b274e1..8a8662368 --- a/build/owncloud/rainloop-app/INSTALL +++ b/build/owncloud/rainloop-app/INSTALL @@ -1,26 +1,26 @@ -************************************************************************ -* -* ownCloud - RainLoop Webmail mail plugin -* -* @author RainLoop Team -* @copyright 2014 RainLoop Team -* -* https://github.com/RainLoop/rainloop-webmail/tree/master/build/owncloud -* -************************************************************************ - -REQUIREMENTS: -- Installed and configured RainLoop Webmail (standalone) -- ownCloud version 6 or higher -- Both apps (RainLoop & ownCloud) running on the same domain - - -INSTALL: -- Unpack the RainLoop Webmail application package in the apps directory of your OwnCloud instance - - -CONFIGURATION: -- ownCloud: - 1) In the Apps > Enable 'RainLoop' plugin - 2) In the Settings > Admin > Enter "RainLoop Webmail URL" and "Absolute (full) path to RainLoop Webmail installation" - 3) In the Settings > Personal > Type your mail server email (login) and password +************************************************************************ +* +* ownCloud - RainLoop Webmail mail plugin +* +* @author RainLoop Team +* @copyright 2014 RainLoop Team +* +* https://github.com/RainLoop/rainloop-webmail/tree/master/build/owncloud +* +************************************************************************ + +REQUIREMENTS: +- Installed and configured RainLoop Webmail (standalone) +- ownCloud version 6 or higher +- Both apps (RainLoop & ownCloud) running on the same domain + + +INSTALL: +- Unpack the RainLoop Webmail application package in the apps directory of your OwnCloud instance + + +CONFIGURATION: +- ownCloud: + 1) In the Apps > Enable 'RainLoop' plugin + 2) In the Settings > Admin > Enter "RainLoop Webmail URL" and "Absolute (full) path to RainLoop Webmail installation" + 3) In the Settings > Personal > Type your mail server email (login) and password diff --git a/build/owncloud/rainloop-app/VERSION b/build/owncloud/rainloop-app/VERSION old mode 100644 new mode 100755 index 171538eb0..415b19fc3 --- a/build/owncloud/rainloop-app/VERSION +++ b/build/owncloud/rainloop-app/VERSION @@ -1 +1 @@ -0.0 \ No newline at end of file +2.0 \ No newline at end of file diff --git a/build/owncloud/rainloop-app/admin.php b/build/owncloud/rainloop-app/admin.php index 1e8b0633e..ba8913669 100644 --- a/build/owncloud/rainloop-app/admin.php +++ b/build/owncloud/rainloop-app/admin.php @@ -16,4 +16,5 @@ OCP\Util::addScript('rainloop', 'admin'); $oTemplate = new OCP\Template('rainloop', 'admin'); $oTemplate->assign('rainloop-url', OCP\Config::getAppValue('rainloop', 'rainloop-url', '')); $oTemplate->assign('rainloop-path', OCP\Config::getAppValue('rainloop', 'rainloop-path', '')); +$oTemplate->assign('rainloop-autologin', OCP\Config::getAppValue('rainloop', 'rainloop-autologin', false)); return $oTemplate->fetchPage(); diff --git a/build/owncloud/rainloop-app/ajax/admin.php b/build/owncloud/rainloop-app/ajax/admin.php index 911d54a60..f2f1f8963 100644 --- a/build/owncloud/rainloop-app/ajax/admin.php +++ b/build/owncloud/rainloop-app/ajax/admin.php @@ -15,14 +15,17 @@ OCP\JSON::callCheck(); $sUrl = ''; $sPath = ''; +$bAutologin = false; if (isset($_POST['appname'], $_POST['rainloop-url'], $_POST['rainloop-path']) && 'rainloop' === $_POST['appname']) { OCP\Config::setAppValue('rainloop', 'rainloop-url', $_POST['rainloop-url']); OCP\Config::setAppValue('rainloop', 'rainloop-path', $_POST['rainloop-path']); + OCP\Config::setAppValue('rainloop', 'rainloop-autologin', $_POST['rainloop-autologin']); $sUrl = OCP\Config::getAppValue('rainloop', 'rainloop-url', ''); $sPath = OCP\Config::getAppValue('rainloop', 'rainloop-path', ''); + $bAutologin = OCP\Config::getAppValue('rainloop', 'rainloop-autologin', false); } else { diff --git a/build/owncloud/rainloop-app/ajax/personal.php b/build/owncloud/rainloop-app/ajax/personal.php old mode 100644 new mode 100755 diff --git a/build/owncloud/rainloop-app/appinfo/app.php b/build/owncloud/rainloop-app/appinfo/app.php index 5ee71099d..9f6172b95 100644 --- a/build/owncloud/rainloop-app/appinfo/app.php +++ b/build/owncloud/rainloop-app/appinfo/app.php @@ -9,9 +9,19 @@ * https://github.com/RainLoop/owncloud */ +OC::$CLASSPATH['OC_RainLoop_Helper'] = OC_App::getAppPath('rainloop') . '/lib/RainLoopHelper.php'; + OCP\App::registerAdmin('rainloop', 'admin'); OCP\App::registerPersonal('rainloop', 'personal'); +$bAutologin = OCP\Config::getAppValue('rainloop', 'rainloop-autologin', false); +if ('on' === $bAutologin) +{ + OCP\Util::connectHook('OC_User', 'post_login', 'OC_RainLoop_Helper', 'login'); + OCP\Util::connectHook('OC_User', 'logout', 'OC_RainLoop_Helper', 'logout'); + OCP\Util::connectHook('OC_User', 'post_setPassword', 'OC_RainLoop_Helper', 'changePassword'); +} + OCP\Util::addScript('rainloop', 'rainloop'); OCP\App::addNavigationEntry(array( @@ -19,5 +29,5 @@ OCP\App::addNavigationEntry(array( 'order' => 10, 'href' => OCP\Util::linkTo('rainloop', 'index.php'), 'icon' => OCP\Util::imagePath('rainloop', 'mail.png'), - 'name' => 'RainLoop' + 'name' => 'Email' )); diff --git a/build/owncloud/rainloop-app/appinfo/info.xml b/build/owncloud/rainloop-app/appinfo/info.xml old mode 100644 new mode 100755 index c261b5b93..fcb2212cf --- a/build/owncloud/rainloop-app/appinfo/info.xml +++ b/build/owncloud/rainloop-app/appinfo/info.xml @@ -1,10 +1,10 @@ - - - rainloop - RainLoop - RainLoop Webmail - 0.0 - CC BY-NC-SA 3.0 - RainLoop Team - 6.0 + + + rainloop + RainLoop + RainLoop Webmail + 2.0 + CC BY-NC-SA 3.0 + RainLoop Team + 6.0 \ No newline at end of file diff --git a/build/owncloud/rainloop-app/img/logo-64x64.png b/build/owncloud/rainloop-app/img/logo-64x64.png old mode 100644 new mode 100755 diff --git a/build/owncloud/rainloop-app/img/mail.png b/build/owncloud/rainloop-app/img/mail.png old mode 100644 new mode 100755 diff --git a/build/owncloud/rainloop-app/index.php b/build/owncloud/rainloop-app/index.php index 97f5b00ad..35dfb7266 100644 --- a/build/owncloud/rainloop-app/index.php +++ b/build/owncloud/rainloop-app/index.php @@ -1,44 +1,56 @@ -assign('rainloop-url', $sResultUrl); -} - -$oTemplate->printpage(); +assign('rainloop-url', $sResultUrl); +} + +$oTemplate->printpage(); diff --git a/build/owncloud/rainloop-app/js/admin.js b/build/owncloud/rainloop-app/js/admin.js old mode 100644 new mode 100755 diff --git a/build/owncloud/rainloop-app/js/personal.js b/build/owncloud/rainloop-app/js/personal.js old mode 100644 new mode 100755 diff --git a/build/owncloud/rainloop-app/js/rainloop.js b/build/owncloud/rainloop-app/js/rainloop.js old mode 100644 new mode 100755 diff --git a/build/owncloud/rainloop-app/js/resize.js b/build/owncloud/rainloop-app/js/resize.js old mode 100644 new mode 100755 index 66041d5f9..78476b611 --- a/build/owncloud/rainloop-app/js/resize.js +++ b/build/owncloud/rainloop-app/js/resize.js @@ -1,26 +1,26 @@ -$(function (window, document) { - - var - buffer = 5, - ifr = document.getElementById('rliframe') - ; - - - function pageY(elem) { - return elem.offsetParent ? (elem.offsetTop + pageY(elem.offsetParent)) : elem.offsetTop; - } - - function resizeIframe() { - var height = document.documentElement.clientHeight; - height -= pageY(ifr) + buffer; - height = (height < 0) ? 0 : height; - ifr.style.height = height + 'px'; - } - - if (ifr) - { - ifr.onload = resizeIframe; - window.onresize = resizeIframe; - } - +$(function (window, document) { + + var + buffer = 5, + ifr = document.getElementById('rliframe') + ; + + + function pageY(elem) { + return elem.offsetParent ? (elem.offsetTop + pageY(elem.offsetParent)) : elem.offsetTop; + } + + function resizeIframe() { + var height = document.documentElement.clientHeight; + height -= pageY(ifr) + buffer; + height = (height < 0) ? 0 : height; + ifr.style.height = height + 'px'; + } + + if (ifr) + { + ifr.onload = resizeIframe; + window.onresize = resizeIframe; + } + }(window, document)); \ No newline at end of file diff --git a/build/owncloud/rainloop-app/lib/RainLoopHelper.php b/build/owncloud/rainloop-app/lib/RainLoopHelper.php index 9c259f124..3eed425de 100644 --- a/build/owncloud/rainloop-app/lib/RainLoopHelper.php +++ b/build/owncloud/rainloop-app/lib/RainLoopHelper.php @@ -28,6 +28,30 @@ class OC_RainLoop_Helper return $SsoHash; } + /** + * @param string $sSsoHash + * + * @return boolean + */ + public static function clearUserSsoHash($sSsoHash) + { + $result = false; + + $sPath = rtrim(trim($sPath), '\\/').'/index.php'; + if (file_exists($sPath)) + { + $_ENV['RAINLOOP_INCLUDE_AS_API'] = true; + include $sPath; + + if (class_exists('\\RainLoop\\Api')) + { + $result = \RainLoop\Api::ClearUserSsoHash($sSsoHash); + } + } + + return $result; + } + /** * @param string $sUrl * @@ -67,4 +91,57 @@ class OC_RainLoop_Helper return @base64_decode(trim($sPassword)); } + + public static function login($params) + { + $sUser = $params['uid']; + $sEmail = $sUser; + $sPassword = $params['password']; + + $sUrl = trim(OCP\Config::getAppValue('rainloop', 'rainloop-url', '')); + $sPath = trim(OCP\Config::getAppValue('rainloop', 'rainloop-path', '')); + + if ('' !== $sUrl && '' !== $sPath) + { + $sPassword = self::encodePassword($sPassword, md5($sEmail)); + return OCP\Config::setUserValue($sUser, 'rainloop', 'rainloop-password', $sPassword); + } + + return false; + } + + public static function logout($params) + { + $sUser = OCP\User::getUser(); + $sSsoHash = OCP\Config::getUserValue($sUser, 'rainloop', 'rainloop-ssohash', ''); + + $a = OCP\Config::setUserValue($sUser, 'rainloop', 'rainloop-password', null); + $b = OCP\Config::setUserValue($sUser, 'rainloop', 'rainloop-ssohash', null); + + if('' !== $sSsoHash) { + self::clearUserSsoHash($sSsoHash); + } + + return $a && $b; + } + + public static function changePassword($params) + { + $sUser = $params['uid']; + $sEmail = $sUser; + $sPassword = $params['password']; + + OCP\Util::writeLog('rainloop', 'rainloop|login: Setting new RainLoop password for '. $sEmail, OCP\Util::DEBUG); + + $sUrl = trim(OCP\Config::getAppValue('rainloop', 'rainloop-url', '')); + $sPath = trim(OCP\Config::getAppValue('rainloop', 'rainloop-path', '')); + + if ('' !== $sUrl && '' !== $sPath) + { + $sPassword = self::encodePassword($sPassword, md5($sEmail)); + return OCP\Config::setUserValue($sUser, 'rainloop', 'rainloop-password', $sPassword); + } + + return false; + } } diff --git a/build/owncloud/rainloop-app/personal.php b/build/owncloud/rainloop-app/personal.php index f995bd05f..c29e47ea8 100644 --- a/build/owncloud/rainloop-app/personal.php +++ b/build/owncloud/rainloop-app/personal.php @@ -16,8 +16,9 @@ OCP\Util::addScript('rainloop', 'personal'); $sUrl = trim(OCP\Config::getAppValue('rainloop', 'rainloop-url', '')); $sPath = trim(OCP\Config::getAppValue('rainloop', 'rainloop-path', '')); +$bAutologin = OCP\Config::getAppValue('rainloop', 'rainloop-autologin', false); -if ('' === $sUrl || '' === $sPath) +if ('on' === $bAutologin || '' === $sUrl || '' === $sPath) { $oTemplate = new OCP\Template('rainloop', 'empty'); } diff --git a/build/owncloud/rainloop-app/templates/admin.php b/build/owncloud/rainloop-app/templates/admin.php index 67dfd08b8..082f59c52 100644 --- a/build/owncloud/rainloop-app/templates/admin.php +++ b/build/owncloud/rainloop-app/templates/admin.php @@ -1,25 +1,28 @@ -
-
- - - -
-

t('RainLoop Webmail')); ?>

-
-

- t('RainLoop Webmail URL')); ?>: -
- -
-
- t('Absolute (full) path to RainLoop Webmail installation')); ?>: -
- -
-
- -    -

-
-
+
+
+ + + +
+

t('RainLoop Webmail')); ?>

+
+

+ t('RainLoop Webmail URL')); ?>: +
+ +
+
+ t('Absolute (full) path to RainLoop Webmail installation')); ?>: +
+ +
+
+ checked="checked" />t('Automatically login with ownCloud user credentials')); ?> +
+
+ +    +

+
+
\ No newline at end of file diff --git a/build/owncloud/rainloop-app/templates/empty.php b/build/owncloud/rainloop-app/templates/empty.php old mode 100644 new mode 100755 diff --git a/build/owncloud/rainloop-app/templates/index-empty.php b/build/owncloud/rainloop-app/templates/index-empty.php old mode 100644 new mode 100755 diff --git a/build/owncloud/rainloop-app/templates/index.php b/build/owncloud/rainloop-app/templates/index.php old mode 100644 new mode 100755 index ffd436802..d10fd0026 --- a/build/owncloud/rainloop-app/templates/index.php +++ b/build/owncloud/rainloop-app/templates/index.php @@ -1,3 +1,3 @@ -
-
- - - -
-

t('RainLoop Webmail')); ?>

-

- - - - - -    -

-
-
+
+
+ + + +
+

t('RainLoop Webmail')); ?>

+

+ + + + + +    +

+
+
\ No newline at end of file