]> source.dussan.org Git - nextcloud-server.git/commitdiff
no longer enforce log out, but provide useful errors/warnings instead
authorBjoern Schiessle <schiessle@owncloud.com>
Fri, 6 Sep 2013 10:27:40 +0000 (12:27 +0200)
committerBjoern Schiessle <schiessle@owncloud.com>
Fri, 6 Sep 2013 10:27:40 +0000 (12:27 +0200)
apps/files/index.php
apps/files/js/files.js
apps/files/templates/index.php
apps/files_encryption/ajax/updatePrivateKeyPassword.php
apps/files_encryption/appinfo/app.php
apps/files_encryption/hooks/hooks.php
apps/files_encryption/lib/helper.php
apps/files_encryption/lib/session.php
apps/files_encryption/lib/stream.php
apps/files_encryption/lib/util.php
apps/files_encryption/templates/invalid_private_key.php

index f1e120c872cf55f29668414962b3184a5b8536e6..b81ba2bdde9ac3daa27a0b48ad595153e800d521 100644 (file)
@@ -124,8 +124,12 @@ if ($needUpgrade) {
        $storageInfo=OC_Helper::getStorageInfo($dir);
        $maxUploadFilesize=OCP\Util::maxUploadFilesize($dir);
        $publicUploadEnabled = \OC_Appconfig::getValue('core', 'shareapi_allow_public_upload', 'yes');
+       // if the encryption app is disabled, than everything is fine
+       $encryptionInitStatus = \OCA\Encryption\Session::INIT_SUCCESSFUL;
        if (OC_App::isEnabled('files_encryption')) {
                $publicUploadEnabled = 'no';
+               $session = new \OCA\Encryption\Session(new \OC\Files\View('/'));
+               $encryptionInitStatus = $session->getInitialized();
        }
 
        $trashEnabled = \OCP\App::isEnabled('files_trashbin');
@@ -133,7 +137,7 @@ if ($needUpgrade) {
        if ($trashEnabled) {
                $trashEmpty = \OCA\Files_Trashbin\Trashbin::isEmpty($user);
        }
-       
+
        OCP\Util::addscript('files', 'fileactions');
        OCP\Util::addscript('files', 'files');
        OCP\Util::addscript('files', 'keyboardshortcuts');
@@ -153,5 +157,6 @@ if ($needUpgrade) {
        $tmpl->assign('isPublic', false);
        $tmpl->assign('publicUploadEnabled', $publicUploadEnabled);
        $tmpl->assign("encryptedFiles", \OCP\Util::encryptedFiles());
+       $tmpl->assign("encryptionInitStatus", $encryptionInitStatus);
        $tmpl->printPage();
 }
index d729077ea7229c08d16785b368d3ab492c4636e7..63c3544b53d1ae8152e69761947821d14867d602 100644 (file)
@@ -90,6 +90,15 @@ Files={
                }
 
                var encryptedFiles = $('#encryptedFiles').val();
+               var initStatus = $('#encryptionInitStatus').val();
+               if (initStatus === '0') { // enc not initialized, but should be
+                       OC.Notification.show(t('files_encryption', 'Encryption App is enabled but your keys are not initialized, please log-out and log-in again'));
+                       return;
+               }
+               if (initStatus === '1') { // encryption tried to init but failed
+                       OC.Notification.show(t('files_encryption', 'Your private key is not valid! Likely your password was changed outside the ownCloud system (e.g. your corporate directory). You can update your private key password in your personal settings to recover access to your encrypted files.'));
+                       return;
+               }
                if (encryptedFiles === '1') {
                        OC.Notification.show(t('files_encryption', 'Encryption was disabled but your files are still encrypted. Please go to your personal settings to decrypt your files.'));
                        return;
index 24cb8c2fe58d20e5421023d9f53ffb01ae580b11..e17273e47b1dd3e4fb3ecd58cf310cb1d3634992 100644 (file)
 <input type="hidden" name="allowZipDownload" id="allowZipDownload" value="<?php p($_['allowZipDownload']); ?>" />
 <input type="hidden" name="usedSpacePercent" id="usedSpacePercent" value="<?php p($_['usedSpacePercent']); ?>" />
 <input type="hidden" name="encryptedFiles" id="encryptedFiles" value="<?php $_['encryptedFiles'] ? p('1') : p('0'); ?>" />
+<input type="hidden" name="encryptedFiles" id="encryptionInitStatus" value="<?php p($_['encryptionInitStatus']) ?>" />
\ No newline at end of file
index 1e6644da576f56bd8d8daae01506f2032942658a..29c72952ae9de4457cc5d63340c4caef9658615f 100644 (file)
@@ -48,6 +48,7 @@ if ($decryptedKey) {
 
 // success or failure
 if ($return) {
+       $session->setInitialized(\OCA\Encryption\Session::INIT_SUCCESSFUL);
        \OCP\JSON::success(array('data' => array('message' => $l->t('Private key password successfully updated.'))));
 } else {
        \OCP\JSON::error(array('data' => array('message' => $l->t('Could not update the private key password. Maybe the old password was not correct.'))));
index 90a9984e27f17ea1b1922b09279ac8c2124ea41c..cd26cd10cd908bc2c466326f4e014ad64ef53de8 100644 (file)
@@ -41,23 +41,6 @@ if (!OC_Config::getValue('maintenance', false)) {
                if($sessionReady) {
                        $session = new \OCA\Encryption\Session($view);
                }
-
-               $user = \OCP\USER::getUser();
-               // check if user has a private key
-               if ($sessionReady === false
-                       || (!$view->file_exists('/' . $user . '/files_encryption/' . $user . '.private.key')
-                               && OCA\Encryption\Crypt::mode() === 'server')
-               ) {
-
-                       // Force the user to log-in again if the encryption key isn't unlocked
-                       // (happens when a user is logged in before the encryption app is
-                       // enabled)
-                       OCP\User::logout();
-
-                       header("Location: " . OC::$WEBROOT . '/');
-
-                       exit();
-               }
        }
 } else {
        // logout user if we are in maintenance to force re-login
index 4c6122b7c2b693b51f78be3e175fc6dd1b43a97f..c945deeea0c96e12fef93dddd5373530156875af 100644 (file)
@@ -547,7 +547,7 @@ class Hooks {
                        $setMigrationStatus->execute();\r
 \r
                        $session = new \OCA\Encryption\Session(new \OC\Files\View('/'));\r
-                       $session->setInitialized(false);\r
+                       $session->setInitialized(\OCA\Encryption\Session::NOT_INITIALIZED);\r
                }\r
        }\r
 \r
index 7d466b88523a51f1a194e8927fb33f783e0f8bda..048473ce8460173e8d8076f86ccbf6456c059e7d 100755 (executable)
@@ -237,28 +237,15 @@ class Helper {
         */
        public static function redirectToErrorPage($session) {
 
-               $l = \OC_L10N::get('files_encryption');
-
-               if ($session->getInitialized() === false) {
-                       $errorMsg = $l->t('Encryption app not initialized! Maybe the encryption app was re-enabled during your session. Please try to log out and log back in to initialize the encryption app.');
-               } else {
-                       $errorMsg = $l->t('Your private key is not valid! Likely your password was changed outside the ownCloud system (e.g. your corporate directory). You can update your private key password in your personal settings to recover access to your encrypted files.');
-               }
+               $init = $session->getInitialized();
 
+               $location = \OC_Helper::linkToAbsolute('apps/files_encryption/files', 'error.php');
+               $post = 0;
                if(count($_POST) > 0) {
-                       header('HTTP/1.0 404 ' . $errorMsg);
-               }
-
-               // check if ajax request
-               if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
-                       \OCP\JSON::error(array('data' => array('message' => $errorMsg)));
-               } else {
-                       header('HTTP/1.0 404 ' . $errorMsg);
-                       $tmpl = new OC_Template('files_encryption', 'invalid_private_key', 'guest');
-                       $tmpl->printPage();
-               }
-
-               exit;
+                       $post = 1;
+                       }
+                       header('Location: ' . $location . '?p=' . $post . '&i=' . $init);
+                       exit();
        }
 
        /**
index 648e6e9ab07bb2e1c5f72f776d804e287ef3a36b..25f2198181f3db0baddd7924db9c5806da10179e 100644 (file)
@@ -30,6 +30,11 @@ class Session {
 
        private $view;
 
+       const NOT_INITIALIZED = '0';
+       const INIT_EXECUTED = '1';
+       const INIT_SUCCESSFUL = '2';
+
+
        /**
         * @brief if session is started, check if ownCloud key pair is set up, if not create it
         * @param \OC_FilesystemView $view
@@ -113,10 +118,10 @@ class Session {
        }
 
        /**
-        * @brief Sets status if we tried to initialize the encyption app
-        * @param bool $privateKey true=initialized false=not initialized
+        * @brief Sets status of encryption app
+        * @param string $init  INIT_SUCCESSFUL, INIT_EXECUTED, NOT_INOITIALIZED
         * @return bool
-        * 
+        *
         * @note this doesn not indicate of the init was successful, we just remeber the try!
         */
        public function setInitialized($init) {
@@ -130,7 +135,7 @@ class Session {
 
        /**
         * @brief Gets status if we already tried to initialize the encryption app
-        * @returns bool
+        * @returns init status INIT_SUCCESSFUL, INIT_EXECUTED, NOT_INOITIALIZED
         *
         * @note this doesn not indicate of the init was successful, we just remeber the try!
         */
@@ -138,7 +143,7 @@ class Session {
                if (!is_null(\OC::$session->get('encryptionInitialized'))) {
                        return \OC::$session->get('encryptionInitialized');
                } else {
-                       return false;
+                       return self::NOT_INITIALIZED;
                }
        }
 
index 9215352aa785d719369be161c3ecc2e785fb91fb..c6db10ce40dfbc5478dba29de12ab96613613a3a 100644 (file)
@@ -128,7 +128,7 @@ class Stream {
                        $this->unencryptedSize = 0;
 
                } else {
-
+\OCA\Encryption\Helper::redirectToErrorPage($this->session);
                        if($this->privateKey === false) {
                                // if private key is not valid redirect user to a error page
                                \OCA\Encryption\Helper::redirectToErrorPage($this->session);
index 17096a787f2be22f03e0af306de359f42cc9715a..7a19f9546431773efdabe741ccac2e9a854cb74e 100644 (file)
@@ -1724,7 +1724,7 @@ class Util {
                $session = new \OCA\Encryption\Session($this->view);
 
                // we tried to initialize the encryption app for this session
-               $session->setInitialized(true);
+               $session->setInitialized(\OCA\Encryption\Session::INIT_EXECUTED);
 
                $encryptedKey = Keymanager::getPrivateKey($this->view, $params['uid']);
 
@@ -1737,6 +1737,7 @@ class Util {
                }
 
                $session->setPrivateKey($privateKey);
+               $session->setInitialized(\OCA\Encryption\Session::INIT_SUCCESSFUL);
 
                return $session;
        }
index 5c086d6514c1297fb80d5aaea13b9cf90ff3a5ba..9af65f831b43949b8c9c2060351e73079ad154f8 100644 (file)
@@ -2,9 +2,11 @@
        <li class='error'>
                <?php $location = \OC_Helper::linkToRoute( "settings_personal" ).'#changePKPasswd' ?>
 
-               <?php p($l->t('Your private key is not valid! Maybe the your password was changed from outside.')); ?>
+               <?php p($_['message']); ?>
                <br/>
-               <?php p($l->t('You can unlock your private key in your ')); ?> <a href="<?php echo $location?>"><?php p($l->t('personal settings')); ?>.</a>
+               <?php if($_['init']): ?>
+                       <?php>p($l->t('Go directly to your ')); ?> <a href="<?php echo $location?>"><?php p($l->t('personal settings')); ?>.</a>
+               <?php endif; ?>
                <br/>
        </li>
 </ul>