From d7dca966a2a926be8b45ab337488143eac3ce9ba Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 30 Aug 2013 10:17:50 +0200 Subject: [PATCH 001/297] improved error messaging, initial commit --- apps/files_encryption/appinfo/database.xml | 7 +++ apps/files_encryption/appinfo/version | 2 +- apps/files_encryption/files/error.php | 2 +- apps/files_encryption/hooks/hooks.php | 29 +++++++----- apps/files_encryption/lib/helper.php | 44 ++++++++++++------ apps/files_encryption/lib/stream.php | 34 +++++++------- apps/files_encryption/lib/util.php | 52 ++++++++++++++++++++++ 7 files changed, 126 insertions(+), 44 deletions(-) diff --git a/apps/files_encryption/appinfo/database.xml b/apps/files_encryption/appinfo/database.xml index 4587930da0a..cd5434b8c27 100644 --- a/apps/files_encryption/appinfo/database.xml +++ b/apps/files_encryption/appinfo/database.xml @@ -34,6 +34,13 @@ 0 Whether encryption migration has been performed + + initialized + integer + true + 0 + Did the user initialized the encryption app at least once + \ No newline at end of file diff --git a/apps/files_encryption/appinfo/version b/apps/files_encryption/appinfo/version index bd73f47072b..2eb3c4fe4ee 100644 --- a/apps/files_encryption/appinfo/version +++ b/apps/files_encryption/appinfo/version @@ -1 +1 @@ -0.4 +0.5 diff --git a/apps/files_encryption/files/error.php b/apps/files_encryption/files/error.php index 2dd27257abe..7a2bb1a2811 100644 --- a/apps/files_encryption/files/error.php +++ b/apps/files_encryption/files/error.php @@ -4,7 +4,7 @@ if (!isset($_)) { //also provide standalone error page $l = OC_L10N::get('files_encryption'); - $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.'); + $errorMsg = $l->t('Your private key is not valid! Maybe the encryption app was re-enabled during your session. Please try to log out and log back in to initialize the encryption app. If this doesn\'t help maybe 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.'); if(isset($_GET['p']) && $_GET['p'] === '1') { header('HTTP/1.0 404 ' . $errorMsg); diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index de306462d79..aefb274e1c4 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -70,9 +70,11 @@ class Hooks { // If migration not yet done if ($ready) { + $util->setInitialized(Util::ENCRYPTION_INITIALIZED); + $userView = new \OC_FilesystemView('/' . $params['uid']); - // Set legacy encryption key if it exists, to support + // Set legacy encryption key if it exists, to support // depreciated encryption system if ( $userView->file_exists('encryption.key') @@ -143,6 +145,7 @@ class Hooks { * @brief If the password can't be changed within ownCloud, than update the key password in advance. */ public static function preSetPassphrase($params) { + return true; if ( ! \OC_User::canUserChangePassword($params['uid']) ) { self::setPassphrase($params); } @@ -153,7 +156,7 @@ class Hooks { * @param array $params keys: uid, password */ public static function setPassphrase($params) { - + return true; // Only attempt to change passphrase if server-side encryption // is in use (client-side encryption does not have access to // the necessary keys) @@ -248,7 +251,7 @@ class Hooks { $params['run'] = false; $params['error'] = $l->t('Following users are not set up for encryption:') . ' ' . join(', ' , $notConfigured); } - + } /** @@ -259,7 +262,7 @@ class Hooks { // NOTE: $params has keys: // [itemType] => file // itemSource -> int, filecache file ID - // [parent] => + // [parent] => // [itemTarget] => /13 // shareWith -> string, uid of user being shared to // fileTarget -> path of file being shared @@ -300,13 +303,13 @@ class Hooks { // NOTE: parent is folder but shared was a file! // we try to rebuild the missing path // some examples we face here - // user1 share folder1 with user2 folder1 has - // the following structure + // user1 share folder1 with user2 folder1 has + // the following structure // /folder1/subfolder1/subsubfolder1/somefile.txt // user2 re-share subfolder2 with user3 // user3 re-share somefile.txt user4 - // so our path should be - // /Shared/subfolder1/subsubfolder1/somefile.txt + // so our path should be + // /Shared/subfolder1/subsubfolder1/somefile.txt // while user3 is sharing if ($params['itemType'] === 'file') { @@ -537,14 +540,18 @@ class Hooks { } /** - * set migration status back to '0' so that all new files get encrypted + * set migration status and the init status back to '0' so that all new files get encrypted * if the app gets enabled again * @param array $params contains the app ID */ public static function preDisable($params) { if ($params['app'] === 'files_encryption') { - $query = \OC_DB::prepare('UPDATE `*PREFIX*encryption` SET `migration_status`=0'); - $query->execute(); + + $setMigrationStatus = \OC_DB::prepare('UPDATE `*PREFIX*encryption` SET `migration_status`=0'); + $setMigrationStatus->execute(); + + $setInitStatus = \OC_DB::prepare('UPDATE `*PREFIX*encryption` SET `initialized`=0'); + $setInitStatus->execute(); } } diff --git a/apps/files_encryption/lib/helper.php b/apps/files_encryption/lib/helper.php index 0209a5d18b7..105c5357e96 100755 --- a/apps/files_encryption/lib/helper.php +++ b/apps/files_encryption/lib/helper.php @@ -199,12 +199,12 @@ class Helper { public static function stripUserFilesPath($path) { $trimmed = ltrim($path, '/'); $split = explode('/', $trimmed); - + // it is not a file relative to data/user/files if (count($split) < 3 || $split[1] !== 'files') { return false; } - + $sliced = array_slice($split, 2); $relPath = implode('/', $sliced); @@ -219,30 +219,46 @@ class Helper { public static function getPathToRealFile($path) { $trimmed = ltrim($path, '/'); $split = explode('/', $trimmed); - + if (count($split) < 3 || $split[1] !== "files_versions") { return false; } - + $sliced = array_slice($split, 2); $realPath = implode('/', $sliced); //remove the last .v $realPath = substr($realPath, 0, strrpos($realPath, '.v')); return $realPath; - } - + } + /** * @brief redirect to a error page */ - public static function redirectToErrorPage() { - $location = \OC_Helper::linkToAbsolute('apps/files_encryption/files', 'error.php'); - $post = 0; - if(count($_POST) > 0) { - $post = 1; + public static function redirectToErrorPage($util) { + + $l = \OC_L10N::get('files_encryption'); + + if ($util->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.'); } - header('Location: ' . $location . '?p=' . $post); - exit(); + + 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; } /** @@ -259,7 +275,7 @@ class Helper { return (bool) $result; } - + /** * check some common errors if the server isn't configured properly for encryption * @return bool true if configuration seems to be OK diff --git a/apps/files_encryption/lib/stream.php b/apps/files_encryption/lib/stream.php index 335ea3733eb..87b8dc3ee2f 100644 --- a/apps/files_encryption/lib/stream.php +++ b/apps/files_encryption/lib/stream.php @@ -81,7 +81,7 @@ class Stream { * @return bool */ public function stream_open($path, $mode, $options, &$opened_path) { - + // assume that the file already exist before we decide it finally in getKey() $this->newFile = false; @@ -106,12 +106,12 @@ class Stream { if ($this->relPath === false) { $this->relPath = Helper::getPathToRealFile($this->rawPath); } - + if($this->relPath === false) { \OCP\Util::writeLog('Encryption library', 'failed to open file "' . $this->rawPath . '" expecting a path to user/files or to user/files_versions', \OCP\Util::ERROR); return false; } - + // Disable fileproxies so we can get the file size and open the source file without recursive encryption $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; @@ -131,7 +131,7 @@ class Stream { if($this->privateKey === false) { // if private key is not valid redirect user to a error page - \OCA\Encryption\Helper::redirectToErrorPage(); + \OCA\Encryption\Helper::redirectToErrorPage($util); } $this->size = $this->rootView->filesize($this->rawPath, $mode); @@ -272,7 +272,7 @@ class Stream { } else { $this->newFile = true; - + return false; } @@ -296,9 +296,9 @@ class Stream { return strlen($data); } - // Disable the file proxies so that encryption is not - // automatically attempted when the file is written to disk - - // we are handling that separately here and we don't want to + // Disable the file proxies so that encryption is not + // automatically attempted when the file is written to disk - + // we are handling that separately here and we don't want to // get into an infinite loop $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; @@ -311,7 +311,7 @@ class Stream { $pointer = ftell($this->handle); // Get / generate the keyfile for the file we're handling - // If we're writing a new file (not overwriting an existing + // If we're writing a new file (not overwriting an existing // one), save the newly generated keyfile if (!$this->getKey()) { @@ -319,7 +319,7 @@ class Stream { } - // If extra data is left over from the last round, make sure it + // If extra data is left over from the last round, make sure it // is integrated into the next 6126 / 8192 block if ($this->writeCache) { @@ -344,12 +344,12 @@ class Stream { if ($remainingLength < 6126) { // Set writeCache to contents of $data - // The writeCache will be carried over to the - // next write round, and added to the start of - // $data to ensure that written blocks are - // always the correct length. If there is still - // data in writeCache after the writing round - // has finished, then the data will be written + // The writeCache will be carried over to the + // next write round, and added to the start of + // $data to ensure that written blocks are + // always the correct length. If there is still + // data in writeCache after the writing round + // has finished, then the data will be written // to disk by $this->flush(). $this->writeCache = $data; @@ -363,7 +363,7 @@ class Stream { $encrypted = $this->preWriteEncrypt($chunk, $this->plainKey); - // Write the data chunk to disk. This will be + // Write the data chunk to disk. This will be // attended to the last data chunk if the file // being handled totals more than 6126 bytes fwrite($this->handle, $encrypted); diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index b8d68623493..edb9564e73a 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -37,6 +37,8 @@ class Util { const MIGRATION_IN_PROGRESS = -1; // migration is running const MIGRATION_OPEN = 0; // user still needs to be migrated + const ENCRYPTION_INITIALIZED = 1; + const ENCRYPTION_NOT_INITIALIZED = 0; private $view; // OC_FilesystemView object for filesystem operations private $userId; // ID of the currently logged-in user @@ -1216,6 +1218,56 @@ class Util { return $return; } + /** + * set remember if the encryption app was already initialized or not + * @param type $status + */ + public function setInitialized($status) { + $sql = 'UPDATE `*PREFIX*encryption` SET `initialized` = ? WHERE `uid` = ?'; + $args = array($status, $this->userId); + $query = \OCP\DB::prepare($sql); + $query->execute($args); + } + + /** + * set remember if the encryption app was already initialized or not + */ + public function getInitialized() { + $sql = 'SELECT `initialized` FROM `*PREFIX*encryption` WHERE `uid` = ?'; + $args = array($this->userId); + $query = \OCP\DB::prepare($sql); + + $result = $query->execute($args); + $initializedStatus = null; + + if (\OCP\DB::isError($result)) { + \OCP\Util::writeLog('Encryption library', \OC_DB::getErrorMessage($result), \OCP\Util::ERROR); + } else { + if ($result->numRows() > 0) { + $row = $result->fetchRow(); + if (isset($row['initialized'])) { + $initializedStatus = (int)$row['initialized']; + } + } + } + + // If no record is found + if (empty($initializedStatus)) { + \OCP\Util::writeLog('Encryption library', "Could not get initialized status for " . $this->userId . ", no record found", \OCP\Util::ERROR); + return false; + // If a record is found + } else { + return (bool)$initializedStatus; + } + + + + $sql = 'UPDATE `*PREFIX*encryption` SET `initialized` = ? WHERE `uid` = ?'; + $args = array($status, $this->userId); + $query = \OCP\DB::prepare($sql); + $query->execute($args); + } + /** * @brief close migration mode after users data has been encrypted successfully * @return boolean From 77adaee6457c3e17d0f0b32c74da4cdbfce60164 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 30 Aug 2013 13:53:49 +0200 Subject: [PATCH 002/297] enable user to inform recipients about a shared file by mail --- apps/files/index.php | 3 +- apps/files/templates/index.php | 1 + core/ajax/share.php | 106 +++++++++++++++++++++++++++++++-- core/css/share.css | 4 +- core/js/share.js | 39 ++++++++++-- db_structure.xml | 8 +++ lib/defaults.php | 31 +++++++++- lib/public/defaults.php | 19 ++++++ lib/public/share.php | 81 ++++++++++++++++++++++--- lib/util.php | 16 ++--- settings/admin.php | 5 +- settings/templates/admin.php | 10 +++- 12 files changed, 292 insertions(+), 31 deletions(-) diff --git a/apps/files/index.php b/apps/files/index.php index e4d8e353858..7f5f9ec4741 100644 --- a/apps/files/index.php +++ b/apps/files/index.php @@ -131,7 +131,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'); @@ -151,5 +151,6 @@ if ($needUpgrade) { $tmpl->assign('isPublic', false); $tmpl->assign('publicUploadEnabled', $publicUploadEnabled); $tmpl->assign("encryptedFiles", \OCP\Util::encryptedFiles()); + $tmpl->assign("mailNotificationEnabled", \OC_Appconfig::getValue('core', 'shareapi_allow_mail_notification', 'yes')); $tmpl->printPage(); } diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php index 360874103f8..e3fcecbe47a 100644 --- a/apps/files/templates/index.php +++ b/apps/files/templates/index.php @@ -120,3 +120,4 @@ + diff --git a/core/ajax/share.php b/core/ajax/share.php index d3c6a8456a6..3f6a9953266 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -23,6 +23,8 @@ OC_JSON::checkLoggedIn(); OCP\JSON::callCheck(); OC_App::loadApps(); +$defaults = new \OCP\Defaults(); + if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSource'])) { switch ($_POST['action']) { case 'share': @@ -33,7 +35,7 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo if ($shareType === OCP\Share::SHARE_TYPE_LINK && $shareWith == '') { $shareWith = null; } - + $token = OCP\Share::shareItem( $_POST['itemType'], $_POST['itemSource'], @@ -41,7 +43,7 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo $shareWith, $_POST['permissions'] ); - + if (is_string($token)) { OC_JSON::success(array('data' => array('token' => $token))); } else { @@ -81,6 +83,102 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo ($return) ? OC_JSON::success() : OC_JSON::error(); } break; + case 'informRecipients': + + $l = OC_L10N::get('core'); + + $shareType = (int) $_POST['shareType']; + $itemType = $_POST['itemType']; + $itemSource = $_POST['itemSource']; + $recipient = $_POST['recipient']; + $from = \OCP\Util::getDefaultEmailAddress('sharing-noreply'); + $subject = $defaults->getShareNotificationSubject($itemType); + + $noMail = array(); + $recipientList = array(); + + if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { + $users = \OC_Group::usersInGroup($recipient); + foreach ($users as $user) { + $email = OC_Preferences::getValue($user, 'settings', 'email', ''); + if ($email !== '' || $recipient === \OCP\User::getUser()) { + $recipientList[] = array( + 'email' => $email, + 'displayName' => \OCP\User::getDisplayName($user), + 'uid' => $user, + ); + } else { + $noMail[] = \OCP\User::getDisplayName($user); + } + } + } else { // shared to a single user + $email = OC_Preferences::getValue($recipient, 'settings', 'email', ''); + if ($email !== '') { + $recipientList[] = array( + 'email' => $email, + 'displayName' => \OCP\User::getDisplayName($recipient), + 'uid' => $recipient, + ); + } else { + $noMail[] = \OCP\User::getDisplayName($recipient); + } + } + + // send mail to all recipients with an email address + foreach ($recipientList as $recipient) { + //get correct target folder name + + $users = \OCP\Share::getItemSharedWithUser($itemType, $itemSource, $recipient['uid']); + $targetName = $users[0]['file_target']; + + //$share = $shareManager->getShares($itemType, array('shareWith' => $recipient['uid'], 'isShareWithUser' => true, 'itemSource' => $itemSource)); + //$targetName = $share[0]->getItemTarget(); + if ($itemType === 'folder') { + $foldername = "/Shared/" . $targetName; + $filename = $targetName; + } else { + // if it is a file we can just link to the Shared folder, + // that's the place where the user will find the file + $foldername = "/Shared"; + $filename = $targetName; + } + + $url = \OCP\Util::linkToAbsolute('files', 'index.php', array("dir" => $foldername)); + $text = $defaults->getShareNotificationText(\OCP\User::getDisplayName(), $filename, $itemType, $url); + + try { + OCP\Util::sendMail( + $recipient['email'], + $recipient['displayName'], + $subject, + $text, + $from, + \OCP\User::getDisplayName() + ); + } catch (Exception $exception) { + $noMail[] = \OCP\User::getDisplayName($recipient['displayName']); + } + } + + \OCP\Share::setSendMailStatus($itemType, $itemSource, $shareType, true); + + if (empty($noMail)) { + OCP\JSON::success(); + } else { + OCP\JSON::error(array('data' => array('message' => $l->t("Couldn't send mail to following users: %s ", implode(', ', $noMail))))); + } + break; + case 'informRecipientsDisabled': + $itemSource = $_POST['itemSource']; + $itemType = $_POST['itemType']; + $recipient = $_POST['recipient']; + //$share = $shareManager->getShares($itemType, array('shareWith' => $recipient, 'isShareWithUser' => true, 'itemSource' => $itemSource)); + //$share[0]->setMailSend(false); + //$shareManager->update($share[0]); + //write status to db + OCP\JSON::success(); + break; + case 'email': // read post variables $user = OCP\USER::getUser(); @@ -213,10 +311,10 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo } } $count = 0; - + // enable l10n support $l = OC_L10N::get('core'); - + foreach ($groups as $group) { if ($count < 15) { if (stripos($group, $_GET['search']) !== false diff --git a/core/css/share.css b/core/css/share.css index 2d6849b4bb1..b6c5a0c1390 100644 --- a/core/css/share.css +++ b/core/css/share.css @@ -11,7 +11,7 @@ margin-right:7em; position:absolute; right:0; - width:19em; + width:25em; z-index:500; padding:1em; } @@ -24,7 +24,7 @@ #shareWithList li { padding-top:.1em; } - + #shareWithList li:first-child { white-space:normal; } diff --git a/core/js/share.js b/core/js/share.js index 27c16f38b92..c806d83f10c 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -217,9 +217,9 @@ OC.Share={ OC.Share.showLink(share.token, share.share_with, itemSource); } else { if (share.collection) { - OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.permissions, possiblePermissions, share.collection); + OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.permissions, possiblePermissions, share.mail_send, share.collection); } else { - OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.permissions, possiblePermissions, false); + OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.mail_send, share.permissions, possiblePermissions, share.mail_send, false); } } if (share.expiration != null) { @@ -299,7 +299,7 @@ OC.Share={ } }); }, - addShareWith:function(shareType, shareWith, shareWithDisplayName, permissions, possiblePermissions, collection) { + addShareWith:function(shareType, shareWith, shareWithDisplayName, permissions, possiblePermissions, mailSend, collection) { if (!OC.Share.itemShares[shareType]) { OC.Share.itemShares[shareType] = []; } @@ -341,6 +341,14 @@ OC.Share={ }else{ html += escapeHTML(shareWithDisplayName); } + mailNotificationEnabled = $('input:hidden[name=mailNotificationEnabled]').val(); + if (mailNotificationEnabled === 'yes') { + checked = ''; + if (mailSend === true) { + checked = 'checked'; + } + html += ''+t('core', 'notify user by email')+''; + } if (possiblePermissions & OC.PERMISSION_CREATE || possiblePermissions & OC.PERMISSION_UPDATE || possiblePermissions & OC.PERMISSION_DELETE) { if (editChecked == '') { html += ''; diff --git a/lib/public/share.php b/lib/public/share.php index eac6fab2b6a..c2dd0096ab9 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -1030,19 +1030,19 @@ class Share { if ($format == self::FORMAT_STATUSES) { if ($itemType == 'file' || $itemType == 'folder') { $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`,' - .' `share_type`, `file_source`, `path`, `expiration`, `storage`'; + .' `share_type`, `file_source`, `path`, `expiration`, `storage`, `mail_send`'; } else { - $select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `expiration`'; + $select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `expiration`, `mail_send`'; } } else { if (isset($uidOwner)) { if ($itemType == 'file' || $itemType == 'folder') { $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`,' .' `share_type`, `share_with`, `file_source`, `path`, `permissions`, `stime`,' - .' `expiration`, `token`, `storage`'; + .' `expiration`, `token`, `storage`, `storage`, `mail_send`'; } else { $select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `share_with`, `permissions`,' - .' `stime`, `file_source`, `expiration`, `token`'; + .' `stime`, `file_source`, `expiration`, `token`, `storage`, `mail_send`'; } } else { if ($fileDependent) { @@ -1053,11 +1053,11 @@ class Share { $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `uid_owner`, ' .'`share_type`, `share_with`, `file_source`, `path`, `file_target`, ' .'`permissions`, `expiration`, `storage`, `*PREFIX*filecache`.`parent` as `file_parent`, ' - .'`name`, `mtime`, `mimetype`, `mimepart`, `size`, `encrypted`, `etag`'; + .'`name`, `mtime`, `mimetype`, `mimepart`, `size`, `encrypted`, `etag`, `storage`, `mail_send`'; } else { $select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `item_target`, `*PREFIX*share`.`parent`, `share_type`, `share_with`, `uid_owner`, - `file_source`, `path`, `file_target`, `permissions`, `stime`, `expiration`, `token`, `storage`'; + `file_source`, `path`, `file_target`, `permissions`, `stime`, `expiration`, `token`, `storage`, `storage`, `mail_send`'; } } else { $select = '*'; From 36574241f821f0cbef2f52032b8187b99c5fce94 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 30 Aug 2013 16:21:52 +0200 Subject: [PATCH 004/297] some clean-up --- core/ajax/share.php | 85 ++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 52 deletions(-) diff --git a/core/ajax/share.php b/core/ajax/share.php index 3f6a9953266..9727f7d02e3 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -97,66 +97,47 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo $noMail = array(); $recipientList = array(); - if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { - $users = \OC_Group::usersInGroup($recipient); - foreach ($users as $user) { - $email = OC_Preferences::getValue($user, 'settings', 'email', ''); - if ($email !== '' || $recipient === \OCP\User::getUser()) { - $recipientList[] = array( - 'email' => $email, - 'displayName' => \OCP\User::getDisplayName($user), - 'uid' => $user, - ); - } else { - $noMail[] = \OCP\User::getDisplayName($user); - } - } - } else { // shared to a single user - $email = OC_Preferences::getValue($recipient, 'settings', 'email', ''); - if ($email !== '') { - $recipientList[] = array( - 'email' => $email, - 'displayName' => \OCP\User::getDisplayName($recipient), - 'uid' => $recipient, - ); - } else { - $noMail[] = \OCP\User::getDisplayName($recipient); - } + if($shareType === \OCP\Share::SHARE_TYPE_USER) { + $recipientList[] = $recipient; + } elseif ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { + $recipientList = \OC_Group::usersInGroup($recipient); } // send mail to all recipients with an email address foreach ($recipientList as $recipient) { //get correct target folder name + $email = OC_Preferences::getValue($recipient, 'settings', 'email', ''); - $users = \OCP\Share::getItemSharedWithUser($itemType, $itemSource, $recipient['uid']); - $targetName = $users[0]['file_target']; + if ($email !== '') { + $displayName = \OCP\User::getDisplayName($recipient); + $items = \OCP\Share::getItemSharedWithUser($itemType, $itemSource, $recipient); + $filename = $items[0]['file_target']; - //$share = $shareManager->getShares($itemType, array('shareWith' => $recipient['uid'], 'isShareWithUser' => true, 'itemSource' => $itemSource)); - //$targetName = $share[0]->getItemTarget(); - if ($itemType === 'folder') { - $foldername = "/Shared/" . $targetName; - $filename = $targetName; + if ($itemType === 'folder') { + $foldername = "/Shared/" . $filename; + } else { + // if it is a file we can just link to the Shared folder, + // that's the place where the user will find the file + $foldername = "/Shared"; + } + + $url = \OCP\Util::linkToAbsolute('files', 'index.php', array("dir" => $foldername)); + $text = $defaults->getShareNotificationText(\OCP\User::getDisplayName(), $filename, $itemType, $url); + + try { + OCP\Util::sendMail( + $email, + $displayName, + $subject, + $text, + $from, + \OCP\User::getDisplayName() + ); + } catch (Exception $exception) { + $noMail[] = \OCP\User::getDisplayName($recipient['displayName']); + } } else { - // if it is a file we can just link to the Shared folder, - // that's the place where the user will find the file - $foldername = "/Shared"; - $filename = $targetName; - } - - $url = \OCP\Util::linkToAbsolute('files', 'index.php', array("dir" => $foldername)); - $text = $defaults->getShareNotificationText(\OCP\User::getDisplayName(), $filename, $itemType, $url); - - try { - OCP\Util::sendMail( - $recipient['email'], - $recipient['displayName'], - $subject, - $text, - $from, - \OCP\User::getDisplayName() - ); - } catch (Exception $exception) { - $noMail[] = \OCP\User::getDisplayName($recipient['displayName']); + $noMail[] = \OCP\User::getDisplayName($recipient); } } From 65ddefc89d6730f3c32727bddae2895232c66a62 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 30 Aug 2013 16:29:22 +0200 Subject: [PATCH 005/297] set sendMail status back to false --- core/ajax/share.php | 8 +++----- core/js/share.js | 4 +--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/core/ajax/share.php b/core/ajax/share.php index 9727f7d02e3..76a67f54720 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -134,7 +134,7 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo \OCP\User::getDisplayName() ); } catch (Exception $exception) { - $noMail[] = \OCP\User::getDisplayName($recipient['displayName']); + $noMail[] = \OCP\User::getDisplayName($recipient); } } else { $noMail[] = \OCP\User::getDisplayName($recipient); @@ -151,12 +151,10 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo break; case 'informRecipientsDisabled': $itemSource = $_POST['itemSource']; + $shareType = $_POST['shareType']; $itemType = $_POST['itemType']; $recipient = $_POST['recipient']; - //$share = $shareManager->getShares($itemType, array('shareWith' => $recipient, 'isShareWithUser' => true, 'itemSource' => $itemSource)); - //$share[0]->setMailSend(false); - //$shareManager->update($share[0]); - //write status to db + \OCP\Share::setSendMailStatus($itemType, $itemSource, $shareType, false); OCP\JSON::success(); break; diff --git a/core/js/share.js b/core/js/share.js index 7d7f580c9bb..e253f77ef27 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -695,9 +695,7 @@ $(document).ready(function() { } }); - $(document).on('click', '#dropdown input[name=mailNotification]', function(event) { - event.preventDefault(); - event.stopPropagation(); + $(document).on('click', '#dropdown input[name=mailNotification]', function() { var li = $(this).parent(); var itemType = $('#dropdown').data('item-type'); var itemSource = $('#dropdown').data('item-source'); From e7959f4fd23ff3354db7b876db2c3e595044bc4c Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 30 Aug 2013 16:52:06 +0200 Subject: [PATCH 006/297] don't send mail to the user who shared the file --- core/ajax/share.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/ajax/share.php b/core/ajax/share.php index 76a67f54720..0cf4b246f98 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -103,6 +103,9 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo $recipientList = \OC_Group::usersInGroup($recipient); } + // don't send a mail to the user who shared the file + array_diff($recipientList, [\OCP\User::getUser()]); + // send mail to all recipients with an email address foreach ($recipientList as $recipient) { //get correct target folder name From 4bbefdf608fdf930fa6fd1f783d6f58267752394 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 30 Aug 2013 17:20:10 +0200 Subject: [PATCH 007/297] add expiration date if it is already set --- core/ajax/share.php | 8 ++++++-- lib/defaults.php | 11 ++++++++--- lib/public/defaults.php | 5 +++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/core/ajax/share.php b/core/ajax/share.php index 0cf4b246f98..8b5191e6550 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -114,7 +114,11 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo if ($email !== '') { $displayName = \OCP\User::getDisplayName($recipient); $items = \OCP\Share::getItemSharedWithUser($itemType, $itemSource, $recipient); - $filename = $items[0]['file_target']; + $filename = trim($items[0]['file_target'], '/'); + $expiration = null; + if (isset($items[0]['expiration'])) { + $expiration = $items[0]['expiration']; + } if ($itemType === 'folder') { $foldername = "/Shared/" . $filename; @@ -125,7 +129,7 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo } $url = \OCP\Util::linkToAbsolute('files', 'index.php', array("dir" => $foldername)); - $text = $defaults->getShareNotificationText(\OCP\User::getDisplayName(), $filename, $itemType, $url); + $text = $defaults->getShareNotificationText(\OCP\User::getDisplayName(), $filename, $itemType, $url, $expiration); try { OCP\Util::sendMail( diff --git a/lib/defaults.php b/lib/defaults.php index 26f417ae2ae..0685fbb16c0 100644 --- a/lib/defaults.php +++ b/lib/defaults.php @@ -65,12 +65,17 @@ class OC_Defaults { * @param string $itemName name of the file/folder * @param string $itemType typically "file" or "folder" * @param string $link link directly to the file/folder in your ownCloud + * @param string $expiration expiration date */ - public function getShareNotificationText($sender, $itemName, $itemType, $link) { + public function getShareNotificationText($sender, $itemName, $itemType, $link, $expiration=null) { if ($this->themeExist('getShareNotificationText')) { - return $this->theme->getShareNotificationText($sender, $itemName, $itemType, $link); + return $this->theme->getShareNotificationText($sender, $itemName, $itemType, $link, $expiration); } else { - return $this->l->t("%s shared a %s called %s with you. You can find the %s here: %s", array($sender, $itemType, $itemName, $itemType, $link)); + if ($expiration) { + return $this->l->t("%s shared a %s called %s with you. The share will expire at %s. You can find the %s here: %s", array($sender, $itemType, $itemName, $expiration, $itemType, $link)); + } else { + return $this->l->t("%s shared a %s called %s with you. You can find the %s here: %s", array($sender, $itemType, $itemName, $itemType, $link)); + } } } diff --git a/lib/public/defaults.php b/lib/public/defaults.php index 9c8c3c0bdab..573831e8eae 100644 --- a/lib/public/defaults.php +++ b/lib/public/defaults.php @@ -48,9 +48,10 @@ class Defaults { * @param string $itemName name of the file/folder * @param string $itemType typically "file" or "folder" * @param string $link link directly to the file/folder in your ownCloud + * @param string $expiration expiration date */ - public function getShareNotificationText($sender, $itemName, $itemType, $link) { - return $this->defaults->getShareNotificationText($sender, $itemName, $itemType, $link); + public function getShareNotificationText($sender, $itemName, $itemType, $link, $expiration) { + return $this->defaults->getShareNotificationText($sender, $itemName, $itemType, $link, $expiration); } /** From bab63c22eea058ea619de5c021d16803ba48ab8d Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 2 Sep 2013 11:26:11 +0200 Subject: [PATCH 008/297] encryption error messages, distinguish between a re-enabled encryption app and a password change from outside --- apps/files_encryption/appinfo/database.xml | 7 --- apps/files_encryption/hooks/hooks.php | 8 +-- apps/files_encryption/lib/helper.php | 4 +- apps/files_encryption/lib/session.php | 27 +++++++++ apps/files_encryption/lib/stream.php | 2 +- apps/files_encryption/lib/util.php | 60 ++----------------- apps/files_encryption/settings-personal.php | 5 +- .../templates/settings-personal.php | 10 ++-- settings/ajax/changepassword.php | 2 +- settings/templates/personal.php | 2 +- 10 files changed, 48 insertions(+), 79 deletions(-) diff --git a/apps/files_encryption/appinfo/database.xml b/apps/files_encryption/appinfo/database.xml index cd5434b8c27..4587930da0a 100644 --- a/apps/files_encryption/appinfo/database.xml +++ b/apps/files_encryption/appinfo/database.xml @@ -34,13 +34,6 @@ 0 Whether encryption migration has been performed - - initialized - integer - true - 0 - Did the user initialized the encryption app at least once - \ No newline at end of file diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index aefb274e1c4..4c6122b7c2b 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -70,8 +70,6 @@ class Hooks { // If migration not yet done if ($ready) { - $util->setInitialized(Util::ENCRYPTION_INITIALIZED); - $userView = new \OC_FilesystemView('/' . $params['uid']); // Set legacy encryption key if it exists, to support @@ -145,7 +143,6 @@ class Hooks { * @brief If the password can't be changed within ownCloud, than update the key password in advance. */ public static function preSetPassphrase($params) { - return true; if ( ! \OC_User::canUserChangePassword($params['uid']) ) { self::setPassphrase($params); } @@ -156,7 +153,6 @@ class Hooks { * @param array $params keys: uid, password */ public static function setPassphrase($params) { - return true; // Only attempt to change passphrase if server-side encryption // is in use (client-side encryption does not have access to // the necessary keys) @@ -550,8 +546,8 @@ class Hooks { $setMigrationStatus = \OC_DB::prepare('UPDATE `*PREFIX*encryption` SET `migration_status`=0'); $setMigrationStatus->execute(); - $setInitStatus = \OC_DB::prepare('UPDATE `*PREFIX*encryption` SET `initialized`=0'); - $setInitStatus->execute(); + $session = new \OCA\Encryption\Session(new \OC\Files\View('/')); + $session->setInitialized(false); } } diff --git a/apps/files_encryption/lib/helper.php b/apps/files_encryption/lib/helper.php index 105c5357e96..7d466b88523 100755 --- a/apps/files_encryption/lib/helper.php +++ b/apps/files_encryption/lib/helper.php @@ -235,11 +235,11 @@ class Helper { /** * @brief redirect to a error page */ - public static function redirectToErrorPage($util) { + public static function redirectToErrorPage($session) { $l = \OC_L10N::get('files_encryption'); - if ($util->getInitialized() === false) { + 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.'); diff --git a/apps/files_encryption/lib/session.php b/apps/files_encryption/lib/session.php index 1911386cd12..f5ce7083af0 100644 --- a/apps/files_encryption/lib/session.php +++ b/apps/files_encryption/lib/session.php @@ -112,6 +112,33 @@ class Session { } + /** + * @brief Sets status if we tried to initialize the encyption app + * @param bool $privateKey true=initialized false=not initialized + * @return bool + */ + public function setInitialized($init) { + + \OC::$session->set('encryptionInitialized', $init); + + return true; + + } + + + /** + * @brief Gets status if we already tried to initialize the encryption app + * @returns bool + * + */ + public function getInitialized() { + if (!is_null(\OC::$session->get('encryptionInitialized'))) { + return \OC::$session->get('encryptionInitialized'); + } else { + return false; + } + } + /** * @brief Gets user or public share private key from session * @returns string $privateKey The user's plaintext private key diff --git a/apps/files_encryption/lib/stream.php b/apps/files_encryption/lib/stream.php index 87b8dc3ee2f..9215352aa78 100644 --- a/apps/files_encryption/lib/stream.php +++ b/apps/files_encryption/lib/stream.php @@ -131,7 +131,7 @@ class Stream { if($this->privateKey === false) { // if private key is not valid redirect user to a error page - \OCA\Encryption\Helper::redirectToErrorPage($util); + \OCA\Encryption\Helper::redirectToErrorPage($this->session); } $this->size = $this->rootView->filesize($this->rawPath, $mode); diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index edb9564e73a..17096a787f2 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -37,9 +37,6 @@ class Util { const MIGRATION_IN_PROGRESS = -1; // migration is running const MIGRATION_OPEN = 0; // user still needs to be migrated - const ENCRYPTION_INITIALIZED = 1; - const ENCRYPTION_NOT_INITIALIZED = 0; - private $view; // OC_FilesystemView object for filesystem operations private $userId; // ID of the currently logged-in user private $client; // Client side encryption mode flag @@ -1218,56 +1215,6 @@ class Util { return $return; } - /** - * set remember if the encryption app was already initialized or not - * @param type $status - */ - public function setInitialized($status) { - $sql = 'UPDATE `*PREFIX*encryption` SET `initialized` = ? WHERE `uid` = ?'; - $args = array($status, $this->userId); - $query = \OCP\DB::prepare($sql); - $query->execute($args); - } - - /** - * set remember if the encryption app was already initialized or not - */ - public function getInitialized() { - $sql = 'SELECT `initialized` FROM `*PREFIX*encryption` WHERE `uid` = ?'; - $args = array($this->userId); - $query = \OCP\DB::prepare($sql); - - $result = $query->execute($args); - $initializedStatus = null; - - if (\OCP\DB::isError($result)) { - \OCP\Util::writeLog('Encryption library', \OC_DB::getErrorMessage($result), \OCP\Util::ERROR); - } else { - if ($result->numRows() > 0) { - $row = $result->fetchRow(); - if (isset($row['initialized'])) { - $initializedStatus = (int)$row['initialized']; - } - } - } - - // If no record is found - if (empty($initializedStatus)) { - \OCP\Util::writeLog('Encryption library', "Could not get initialized status for " . $this->userId . ", no record found", \OCP\Util::ERROR); - return false; - // If a record is found - } else { - return (bool)$initializedStatus; - } - - - - $sql = 'UPDATE `*PREFIX*encryption` SET `initialized` = ? WHERE `uid` = ?'; - $args = array($status, $this->userId); - $query = \OCP\DB::prepare($sql); - $query->execute($args); - } - /** * @brief close migration mode after users data has been encrypted successfully * @return boolean @@ -1774,6 +1721,11 @@ class Util { */ public function initEncryption($params) { + $session = new \OCA\Encryption\Session($this->view); + + // we tried to initialize the encryption app for this session + $session->setInitialized(true); + $encryptedKey = Keymanager::getPrivateKey($this->view, $params['uid']); $privateKey = Crypt::decryptPrivateKey($encryptedKey, $params['password']); @@ -1784,8 +1736,6 @@ class Util { return false; } - $session = new \OCA\Encryption\Session($this->view); - $session->setPrivateKey($privateKey); return $session; diff --git a/apps/files_encryption/settings-personal.php b/apps/files_encryption/settings-personal.php index 589219f32ad..c0c91bdf652 100644 --- a/apps/files_encryption/settings-personal.php +++ b/apps/files_encryption/settings-personal.php @@ -16,7 +16,9 @@ $view = new \OC_FilesystemView('/'); $util = new \OCA\Encryption\Util($view, $user); $session = new \OCA\Encryption\Session($view); -$privateKeySet = $session->getPrivateKey() !== false; +$privateKeySet = $session->getPrivateKey() !== false; +// was the key successfully initialized during log-in +$initialized = $session->getInitialized(); $recoveryAdminEnabled = OC_Appconfig::getValue('files_encryption', 'recoveryAdminEnabled'); $recoveryEnabledForUser = $util->recoveryEnabledForUser(); @@ -31,6 +33,7 @@ if ($recoveryAdminEnabled || !$privateKeySet) { $tmpl->assign('recoveryEnabled', $recoveryAdminEnabled); $tmpl->assign('recoveryEnabledForUser', $recoveryEnabledForUser); $tmpl->assign('privateKeySet', $privateKeySet); + $tmpl->assign('initialized', $initialized); $result = $tmpl->fetchPage(); } diff --git a/apps/files_encryption/templates/settings-personal.php b/apps/files_encryption/templates/settings-personal.php index 38512453207..ff04556dd53 100644 --- a/apps/files_encryption/templates/settings-personal.php +++ b/apps/files_encryption/templates/settings-personal.php @@ -4,7 +4,7 @@ t( 'Encryption' ) ); ?> - +


t( "Enabling this option will allow you to reobtain access to your encrypted files in case of password loss" ) ); ?>
- /> t( "Enabled" ) ); ?>
- - t('Your password was changed');?>

- From 5e508f1ccbd3b83ed11f7eab35fea43e1583caf3 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 2 Sep 2013 11:34:28 +0200 Subject: [PATCH 009/297] improved documentation of the methods --- apps/files_encryption/lib/session.php | 3 +++ apps/files_encryption/settings-personal.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/files_encryption/lib/session.php b/apps/files_encryption/lib/session.php index f5ce7083af0..648e6e9ab07 100644 --- a/apps/files_encryption/lib/session.php +++ b/apps/files_encryption/lib/session.php @@ -116,6 +116,8 @@ class Session { * @brief Sets status if we tried to initialize the encyption app * @param bool $privateKey true=initialized false=not initialized * @return bool + * + * @note this doesn not indicate of the init was successful, we just remeber the try! */ public function setInitialized($init) { @@ -130,6 +132,7 @@ class Session { * @brief Gets status if we already tried to initialize the encryption app * @returns bool * + * @note this doesn not indicate of the init was successful, we just remeber the try! */ public function getInitialized() { if (!is_null(\OC::$session->get('encryptionInitialized'))) { diff --git a/apps/files_encryption/settings-personal.php b/apps/files_encryption/settings-personal.php index c0c91bdf652..ffcb99602e2 100644 --- a/apps/files_encryption/settings-personal.php +++ b/apps/files_encryption/settings-personal.php @@ -17,7 +17,7 @@ $util = new \OCA\Encryption\Util($view, $user); $session = new \OCA\Encryption\Session($view); $privateKeySet = $session->getPrivateKey() !== false; -// was the key successfully initialized during log-in +// did we tried to initialize the keys for this session? $initialized = $session->getInitialized(); $recoveryAdminEnabled = OC_Appconfig::getValue('files_encryption', 'recoveryAdminEnabled'); From 6572ca811fc56c71b4efc970668741630acbd63c Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 2 Sep 2013 11:36:20 +0200 Subject: [PATCH 010/297] error.php no longer needed --- apps/files_encryption/files/error.php | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 apps/files_encryption/files/error.php diff --git a/apps/files_encryption/files/error.php b/apps/files_encryption/files/error.php deleted file mode 100644 index 7a2bb1a2811..00000000000 --- a/apps/files_encryption/files/error.php +++ /dev/null @@ -1,23 +0,0 @@ -t('Your private key is not valid! Maybe the encryption app was re-enabled during your session. Please try to log out and log back in to initialize the encryption app. If this doesn\'t help maybe 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.'); - - if(isset($_GET['p']) && $_GET['p'] === '1') { - 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; -} From 983da0d78fe13814fb771eb90dd2f10a89e0bcc6 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 2 Sep 2013 17:01:10 +0200 Subject: [PATCH 011/297] fix db queries --- lib/public/share.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/public/share.php b/lib/public/share.php index c2dd0096ab9..cb55c5c9756 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -1053,11 +1053,11 @@ class Share { $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `uid_owner`, ' .'`share_type`, `share_with`, `file_source`, `path`, `file_target`, ' .'`permissions`, `expiration`, `storage`, `*PREFIX*filecache`.`parent` as `file_parent`, ' - .'`name`, `mtime`, `mimetype`, `mimepart`, `size`, `encrypted`, `etag`, `storage`, `mail_send`'; + .'`name`, `mtime`, `mimetype`, `mimepart`, `size`, `encrypted`, `etag`, `mail_send`'; } else { $select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `item_target`, `*PREFIX*share`.`parent`, `share_type`, `share_with`, `uid_owner`, - `file_source`, `path`, `file_target`, `permissions`, `stime`, `expiration`, `token`, `storage`, `storage`, `mail_send`'; + `file_source`, `path`, `file_target`, `permissions`, `stime`, `expiration`, `token`, `storage`, `mail_send`'; } } else { $select = '*'; From 931e90634e905816e5ec8db3d10f9446c1b1eacc Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 2 Sep 2013 17:03:35 +0200 Subject: [PATCH 012/297] fix db queries --- lib/public/share.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/public/share.php b/lib/public/share.php index cb55c5c9756..4461a1d421f 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -1039,10 +1039,10 @@ class Share { if ($itemType == 'file' || $itemType == 'folder') { $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`,' .' `share_type`, `share_with`, `file_source`, `path`, `permissions`, `stime`,' - .' `expiration`, `token`, `storage`, `storage`, `mail_send`'; + .' `expiration`, `token`, `storage`, `mail_send`'; } else { $select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `share_with`, `permissions`,' - .' `stime`, `file_source`, `expiration`, `token`, `storage`, `mail_send`'; + .' `stime`, `file_source`, `expiration`, `token`, `mail_send`'; } } else { if ($fileDependent) { From 7ce54f7b3a86c4cc1301cb6d96f3029c7047a95b Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 2 Sep 2013 17:09:26 +0200 Subject: [PATCH 013/297] revert submodule reference changes --- 3rdparty | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rdparty b/3rdparty index 21b466b72cd..dc87ea63028 160000 --- a/3rdparty +++ b/3rdparty @@ -1 +1 @@ -Subproject commit 21b466b72cdd4c823c011669593ecef1defb1f3c +Subproject commit dc87ea630287f27502eba825fbb19fcc33c34c86 From 3ce4bf5ec70ed4cfd0e6d619e2f7ae0a1bfdb06c Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 2 Sep 2013 17:14:11 +0200 Subject: [PATCH 014/297] use css class hidden to hide setting elements --- settings/templates/admin.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/settings/templates/admin.php b/settings/templates/admin.php index 22cf946803e..72e93e78dac 100644 --- a/settings/templates/admin.php +++ b/settings/templates/admin.php @@ -128,7 +128,7 @@ if (!$_['internetconnectionworking']) { - > + > />
@@ -137,7 +137,7 @@ if (!$_['internetconnectionworking']) { - > + > />
@@ -146,7 +146,7 @@ if (!$_['internetconnectionworking']) { - > + > />
@@ -154,7 +154,7 @@ if (!$_['internetconnectionworking']) { - > + > />
@@ -164,7 +164,7 @@ if (!$_['internetconnectionworking']) { - > + > />
From fd7469db9e1cd1fd85e3a8a18aac87c7040ec8e7 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 3 Sep 2013 13:37:06 +0200 Subject: [PATCH 015/297] coding-style fixes --- core/ajax/share.php | 16 ++++++++++++++-- core/js/share.js | 2 +- lib/defaults.php | 9 +++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/core/ajax/share.php b/core/ajax/share.php index 1e954ac4f9d..8f5432a0fcb 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -129,7 +129,13 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo } $url = \OCP\Util::linkToAbsolute('files', 'index.php', array("dir" => $foldername)); - $text = $defaults->getShareNotificationText(\OCP\User::getDisplayName(), $filename, $itemType, $url, $expiration); + $text = $defaults->getShareNotificationText( + \OCP\User::getDisplayName(), + $filename, + $itemType, + $url, + $expiration + ); try { OCP\Util::sendMail( @@ -153,7 +159,13 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo if (empty($noMail)) { OCP\JSON::success(); } else { - OCP\JSON::error(array('data' => array('message' => $l->t("Couldn't send mail to following users: %s ", implode(', ', $noMail))))); + OCP\JSON::error(array( + 'data' => array( + 'message' => $l->t("Couldn't send mail to following users: %s ", + implode(', ', $noMail) + ) + ) + )); } break; case 'informRecipientsDisabled': diff --git a/core/js/share.js b/core/js/share.js index e253f77ef27..763713e7cf2 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -493,7 +493,7 @@ $(document).ready(function() { $('input:[type=checkbox]', this).hide(); $('label', this).hide(); } - } else { + } else { $('a.unshare', this).hide(); } }); diff --git a/lib/defaults.php b/lib/defaults.php index 0685fbb16c0..efb6c2c7b32 100644 --- a/lib/defaults.php +++ b/lib/defaults.php @@ -72,9 +72,14 @@ class OC_Defaults { return $this->theme->getShareNotificationText($sender, $itemName, $itemType, $link, $expiration); } else { if ($expiration) { - return $this->l->t("%s shared a %s called %s with you. The share will expire at %s. You can find the %s here: %s", array($sender, $itemType, $itemName, $expiration, $itemType, $link)); + return $this->l->t("%s shared a %s called %s with you. " . + "The share will expire at %s. ". + "You can find the %s here: %s", + array($sender, $itemType, $itemName, $expiration, $itemType, $link)); } else { - return $this->l->t("%s shared a %s called %s with you. You can find the %s here: %s", array($sender, $itemType, $itemName, $itemType, $link)); + return $this->l->t("%s shared a %s called %s with you. ". + "You can find the %s here: %s", + array($sender, $itemType, $itemName, $itemType, $link)); } } } From 985758305f66d80f2b0625423b0bee68fce2a2d9 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 4 Sep 2013 14:32:05 +0200 Subject: [PATCH 016/297] initial commit, start implementing the ocs share api --- apps/files_sharing/appinfo/app.php | 1 + apps/files_sharing/appinfo/routes.php | 53 ++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index 895d446a336..ffdcbf05109 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -7,6 +7,7 @@ OC::$CLASSPATH['OC\Files\Cache\Shared_Cache'] = 'files_sharing/lib/cache.php'; OC::$CLASSPATH['OC\Files\Cache\Shared_Permissions'] = 'files_sharing/lib/permissions.php'; OC::$CLASSPATH['OC\Files\Cache\Shared_Updater'] = 'files_sharing/lib/updater.php'; OC::$CLASSPATH['OC\Files\Cache\Shared_Watcher'] = 'files_sharing/lib/watcher.php'; +OC::$CLASSPATH['OCA\Files\Share\Api'] = 'files_sharing/lib/api.php'; OCP\Util::connectHook('OC_Filesystem', 'setup', '\OC\Files\Storage\Shared', 'setup'); OCP\Share::registerBackend('file', 'OC_Share_Backend_File'); OCP\Share::registerBackend('folder', 'OC_Share_Backend_Folder', 'file'); diff --git a/apps/files_sharing/appinfo/routes.php b/apps/files_sharing/appinfo/routes.php index 02815b5eb42..15af5226e18 100644 --- a/apps/files_sharing/appinfo/routes.php +++ b/apps/files_sharing/appinfo/routes.php @@ -2,4 +2,55 @@ $this->create('core_ajax_public_preview', '/publicpreview.png')->action( function() { require_once __DIR__ . '/../ajax/publicpreview.php'; -}); \ No newline at end of file +}); + +//TODO: GET: share status of a given file/folder +//TODO: GET: share status of all files in a given folder? +//TODO: SET: share (unshare) +//TODO: SET: permissions +//TODO: SET: expire date +//TODO: SET: mail notification + +OC_API::register('get', + '/apps/files_sharing/api/share/{path}', + array('\OCA\Files\Share\Api', 'getShare'), + 'files_sharing', + OC_API::USER_AUTH, + array('path' => ''), + array('path' => '.+')); //allow slashes in parameter path +/* +OC_API::register('get', + '/apps/files_sharing/api/share/group/{path}', + array('\OCA\Files\Share\Api', 'getShare'), + 'files_sharing', + OC_API::USER_AUTH, + array('path' => '')); + +OC_API::register('get', + '/apps/files_sharing/api/share/user/{path}', + array('\OCA\Files\Share\Api', 'getShare'), + 'files_sharing', + OC_API::USER_AUTH, + array('path' => '')); + +OC_API::register('get', + '/apps/files_sharing/api/permission/{path}', + array('\OCA\Files\Share\Api', 'getShare'), + 'files_sharing', + OC_API::USER_AUTH, + array('path' => '')); + +OC_API::register('get', + '/apps/files_sharing/api/expire/{path}', + array('\OCA\Files\Share\Api', 'getShare'), + 'files_sharing', + OC_API::USER_AUTH, + array('path' => '')); + +OC_API::register('get', + '/apps/files_sharing/api/notify/{path}', + array('\OCA\Files\Share\Api', 'getShare'), + 'files_sharing', + OC_API::USER_AUTH, + array('path' => '')); +*/ From 21a0a96e4395fedb7fae8fe5f731ca283ce937b1 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 4 Sep 2013 17:25:15 +0200 Subject: [PATCH 017/297] intermediate results, share api --- apps/files_sharing/appinfo/routes.php | 14 -------- apps/files_sharing/lib/api.php | 48 +++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 apps/files_sharing/lib/api.php diff --git a/apps/files_sharing/appinfo/routes.php b/apps/files_sharing/appinfo/routes.php index 15af5226e18..2e26033cad0 100644 --- a/apps/files_sharing/appinfo/routes.php +++ b/apps/files_sharing/appinfo/routes.php @@ -19,20 +19,6 @@ OC_API::register('get', array('path' => ''), array('path' => '.+')); //allow slashes in parameter path /* -OC_API::register('get', - '/apps/files_sharing/api/share/group/{path}', - array('\OCA\Files\Share\Api', 'getShare'), - 'files_sharing', - OC_API::USER_AUTH, - array('path' => '')); - -OC_API::register('get', - '/apps/files_sharing/api/share/user/{path}', - array('\OCA\Files\Share\Api', 'getShare'), - 'files_sharing', - OC_API::USER_AUTH, - array('path' => '')); - OC_API::register('get', '/apps/files_sharing/api/permission/{path}', array('\OCA\Files\Share\Api', 'getShare'), diff --git a/apps/files_sharing/lib/api.php b/apps/files_sharing/lib/api.php new file mode 100644 index 00000000000..cfe1fc2da46 --- /dev/null +++ b/apps/files_sharing/lib/api.php @@ -0,0 +1,48 @@ +. + * + */ + +namespace OCA\Files\Share; + +class Api { + + /** + * @brief get share information for a given file/folder + * + * @param array $params which contains a 'path' to a file/folder + * @return \OC_OCS_Result share information + */ + public static function getShare($params) { + $path = $params['path']; + + $view = new \OC\Files\View('/'.\OCP\User::getUser().'/files'); + $fileInfo = $view->getFileInfo($path); + if ($fileInfo) { + $share = \OCP\Share::getItemShared('file', $fileInfo['fileid']); + } else { + \OCP\Util::writeLog('files_sharing', 'OCS API getShare, file ' . $path . ' does not exists', \OCP\Util::WARN); + $share = array(); + } + + return new \OC_OCS_Result($share); + } + +} \ No newline at end of file From b6ee727399c3d0eced5b2ee2bce9f17a813a1bb2 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 6 Sep 2013 10:49:21 +0200 Subject: [PATCH 018/297] intermediate result ocs api --- apps/files_sharing/appinfo/routes.php | 22 +++++- apps/files_sharing/lib/api.php | 106 ++++++++++++++++++++++++-- 2 files changed, 118 insertions(+), 10 deletions(-) diff --git a/apps/files_sharing/appinfo/routes.php b/apps/files_sharing/appinfo/routes.php index 2e26033cad0..1c7f5b4a1fc 100644 --- a/apps/files_sharing/appinfo/routes.php +++ b/apps/files_sharing/appinfo/routes.php @@ -4,12 +4,11 @@ function() { require_once __DIR__ . '/../ajax/publicpreview.php'; }); -//TODO: GET: share status of a given file/folder -//TODO: GET: share status of all files in a given folder? -//TODO: SET: share (unshare) +//TODO: SET: unshare //TODO: SET: permissions //TODO: SET: expire date //TODO: SET: mail notification +//TODO: SET: can upload OC_API::register('get', '/apps/files_sharing/api/share/{path}', @@ -18,6 +17,23 @@ OC_API::register('get', OC_API::USER_AUTH, array('path' => ''), array('path' => '.+')); //allow slashes in parameter path + +OC_API::register('post', + '/apps/files_sharing/api/share/{path}', + array('\OCA\Files\Share\Api', 'setShare'), + 'files_sharing', + OC_API::USER_AUTH, + array('path' => ''), + array('path' => '.+')); + +OC_API::register('post', + '/apps/files_sharing/api/permission/{path}', + array('\OCA\Files\Share\Api', 'setPermission'), + 'files_sharing', + OC_API::USER_AUTH, + array('path' => ''), + array('path' => '.+')); + /* OC_API::register('get', '/apps/files_sharing/api/permission/{path}', diff --git a/apps/files_sharing/lib/api.php b/apps/files_sharing/lib/api.php index cfe1fc2da46..7f7f925eb23 100644 --- a/apps/files_sharing/lib/api.php +++ b/apps/files_sharing/lib/api.php @@ -33,16 +33,108 @@ class Api { public static function getShare($params) { $path = $params['path']; - $view = new \OC\Files\View('/'.\OCP\User::getUser().'/files'); - $fileInfo = $view->getFileInfo($path); - if ($fileInfo) { - $share = \OCP\Share::getItemShared('file', $fileInfo['fileid']); + $fileId = self::getFileId($path); + if ($fileId !== null) { + $share = \OCP\Share::getItemShared('file', $fileId); } else { - \OCP\Util::writeLog('files_sharing', 'OCS API getShare, file ' . $path . ' does not exists', \OCP\Util::WARN); - $share = array(); + $share = null; } - return new \OC_OCS_Result($share); + if ($share !== null) { + return new \OC_OCS_Result($share); + } else { + return new \OC_OCS_Result(null, 404, 'file/folder doesn\'t exists'); + } + } + + /** + * @brief share file with a user/group + * + * @param array $params which contains a 'path' to a file/folder + * @return \OC_OCS_Result result of share operation + */ + public static function setShare($params) { + $path = $params['path']; + $errorMessage = ''; + + $itemSource = self::getFileId($path); + $itemType = self::getItemType($path); + + $shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null; + $shareType = isset($_POST['shareType']) ? (int)$_POST['shareType'] : null; + + if($shareType === \OCP\Share::SHARE_TYPE_LINK) { + $permissions = 1; + $shareWith = null; + } else { + $permissions = 31; + } + + + $token = null; + if (($shareWith !== null || $shareType === \OCP\Share::SHARE_TYPE_LINK) + && $shareType !== false + && $itemType !== false) { + $token = \OCP\Share::shareItem( + $itemType, + $itemSource, + $shareType, + $shareWith, + $permissions + ); + } else { + $errorMessage = "You need to specify at least 'shareType' and provide a correct file/folder path." + . " For non public shares you also need specify 'shareWith'."; + } + + + if ($token) { + $data = null; + if(is_string($token)) { //public link share + $url = \OCP\Util::linkToPublic('files&t='.$token); + $data = array('url' => $url, // '&' gets encoded to $amp; + 'token' => $token); + + } + return new \OC_OCS_Result($data); + } else { + return new \OC_OCS_Result(null, 404, $errorMessage); + } + } + + /** + * @brief get file ID from a given path + * @param string $path + * @return string fileID or null + */ + private static function getFileId($path) { + $view = new \OC\Files\View('/'.\OCP\User::getUser().'/files'); + $fileId = null; + + $fileInfo = $view->getFileInfo($path); + if ($fileInfo) { + $fileId = $fileInfo['fileid']; + } + + return $fileId; + } + + /** + * @brief get itemType + * @param string $path + * @return string type 'file', 'folder' or null of file/folder doesn't exists + */ + private static function getItemType($path) { + $view = new \OC\Files\View('/'.\OCP\User::getUser().'/files'); + $itemType = null; + + if ($view->is_dir($path)) { + $itemType = "folder"; + } elseif ($view->is_file($path)) { + $itemType = "file"; + } + + return $itemType; } } \ No newline at end of file From 69b1625f0e368e65771fef473f4b4d4a13456354 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 6 Sep 2013 12:27:25 +0200 Subject: [PATCH 019/297] re-added error.php --- apps/files_encryption/files/error.php | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 apps/files_encryption/files/error.php diff --git a/apps/files_encryption/files/error.php b/apps/files_encryption/files/error.php new file mode 100644 index 00000000000..ac0c0269164 --- /dev/null +++ b/apps/files_encryption/files/error.php @@ -0,0 +1,33 @@ +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.'); + $init = '0'; + } 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 = '1'; + } + + if (isset($_GET['p']) && $_GET['p'] === '1') { + 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->assign('message', $errorMsg); + $tmpl->assign('init', $init); + $tmpl->printPage(); + } + + exit; +} + From fb462e83ccde5c46565c23545c5eb894acbd6fd3 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 6 Sep 2013 12:27:40 +0200 Subject: [PATCH 020/297] no longer enforce log out, but provide useful errors/warnings instead --- apps/files/index.php | 7 ++++- apps/files/js/files.js | 9 +++++++ apps/files/templates/index.php | 1 + .../ajax/updatePrivateKeyPassword.php | 1 + apps/files_encryption/appinfo/app.php | 17 ------------ apps/files_encryption/hooks/hooks.php | 2 +- apps/files_encryption/lib/helper.php | 27 +++++-------------- apps/files_encryption/lib/session.php | 15 +++++++---- apps/files_encryption/lib/stream.php | 2 +- apps/files_encryption/lib/util.php | 3 ++- .../templates/invalid_private_key.php | 6 +++-- 11 files changed, 42 insertions(+), 48 deletions(-) diff --git a/apps/files/index.php b/apps/files/index.php index f1e120c872c..b81ba2bdde9 100644 --- a/apps/files/index.php +++ b/apps/files/index.php @@ -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(); } diff --git a/apps/files/js/files.js b/apps/files/js/files.js index d729077ea72..63c3544b53d 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -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; diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php index 24cb8c2fe58..e17273e47b1 100644 --- a/apps/files/templates/index.php +++ b/apps/files/templates/index.php @@ -123,3 +123,4 @@ + \ No newline at end of file diff --git a/apps/files_encryption/ajax/updatePrivateKeyPassword.php b/apps/files_encryption/ajax/updatePrivateKeyPassword.php index 1e6644da576..29c72952ae9 100644 --- a/apps/files_encryption/ajax/updatePrivateKeyPassword.php +++ b/apps/files_encryption/ajax/updatePrivateKeyPassword.php @@ -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.')))); diff --git a/apps/files_encryption/appinfo/app.php b/apps/files_encryption/appinfo/app.php index 90a9984e27f..cd26cd10cd9 100644 --- a/apps/files_encryption/appinfo/app.php +++ b/apps/files_encryption/appinfo/app.php @@ -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 diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index 4c6122b7c2b..c945deeea0c 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -547,7 +547,7 @@ class Hooks { $setMigrationStatus->execute(); $session = new \OCA\Encryption\Session(new \OC\Files\View('/')); - $session->setInitialized(false); + $session->setInitialized(\OCA\Encryption\Session::NOT_INITIALIZED); } } diff --git a/apps/files_encryption/lib/helper.php b/apps/files_encryption/lib/helper.php index 7d466b88523..048473ce846 100755 --- a/apps/files_encryption/lib/helper.php +++ b/apps/files_encryption/lib/helper.php @@ -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(); } /** diff --git a/apps/files_encryption/lib/session.php b/apps/files_encryption/lib/session.php index 648e6e9ab07..25f2198181f 100644 --- a/apps/files_encryption/lib/session.php +++ b/apps/files_encryption/lib/session.php @@ -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; } } diff --git a/apps/files_encryption/lib/stream.php b/apps/files_encryption/lib/stream.php index 9215352aa78..c6db10ce40d 100644 --- a/apps/files_encryption/lib/stream.php +++ b/apps/files_encryption/lib/stream.php @@ -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); diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index 17096a787f2..7a19f954643 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -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; } diff --git a/apps/files_encryption/templates/invalid_private_key.php b/apps/files_encryption/templates/invalid_private_key.php index 5c086d6514c..9af65f831b4 100644 --- a/apps/files_encryption/templates/invalid_private_key.php +++ b/apps/files_encryption/templates/invalid_private_key.php @@ -2,9 +2,11 @@
  • - t('Your private key is not valid! Maybe the your password was changed from outside.')); ?> +
    - t('You can unlock your private key in your ')); ?>
    t('personal settings')); ?>. + + p($l->t('Go directly to your ')); ?> t('personal settings')); ?>. +
  • From 1558cb860c2fb26fdde14fce2a16acbb29d12b3e Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 6 Sep 2013 13:16:48 +0200 Subject: [PATCH 021/297] remove test code --- apps/files_encryption/lib/stream.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_encryption/lib/stream.php b/apps/files_encryption/lib/stream.php index c6db10ce40d..9215352aa78 100644 --- a/apps/files_encryption/lib/stream.php +++ b/apps/files_encryption/lib/stream.php @@ -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); From 3861c9bce185e0f38b4941afd752c9da73985570 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 6 Sep 2013 16:00:01 +0200 Subject: [PATCH 022/297] some more OCS calls for sharing --- apps/files_sharing/appinfo/routes.php | 9 +- apps/files_sharing/lib/api.php | 131 +++++++++++++++++++++----- 2 files changed, 118 insertions(+), 22 deletions(-) diff --git a/apps/files_sharing/appinfo/routes.php b/apps/files_sharing/appinfo/routes.php index 1c7f5b4a1fc..3f80614cc0c 100644 --- a/apps/files_sharing/appinfo/routes.php +++ b/apps/files_sharing/appinfo/routes.php @@ -5,7 +5,6 @@ function() { }); //TODO: SET: unshare -//TODO: SET: permissions //TODO: SET: expire date //TODO: SET: mail notification //TODO: SET: can upload @@ -34,6 +33,14 @@ OC_API::register('post', array('path' => ''), array('path' => '.+')); +OC_API::register('post', + '/apps/files_sharing/api/expire/{path}', + array('\OCA\Files\Share\Api', 'setExpire'), + 'files_sharing', + OC_API::USER_AUTH, + array('path' => ''), + array('path' => '.+')); + /* OC_API::register('get', '/apps/files_sharing/api/permission/{path}', diff --git a/apps/files_sharing/lib/api.php b/apps/files_sharing/lib/api.php index 7f7f925eb23..90d8a93d3a4 100644 --- a/apps/files_sharing/lib/api.php +++ b/apps/files_sharing/lib/api.php @@ -25,7 +25,7 @@ namespace OCA\Files\Share; class Api { /** - * @brief get share information for a given file/folder + * @brief get share information for a given file/folder path is encoded in URL * * @param array $params which contains a 'path' to a file/folder * @return \OC_OCS_Result share information @@ -48,45 +48,53 @@ class Api { } /** - * @brief share file with a user/group + * @brief share file with a user/group, path to file is encoded in URL * - * @param array $params which contains a 'path' to a file/folder + * @param array $params with following parameters 'shareWith', 'shareType' * @return \OC_OCS_Result result of share operation */ public static function setShare($params) { $path = $params['path']; - $errorMessage = ''; $itemSource = self::getFileId($path); $itemType = self::getItemType($path); + if($itemSource === null) { + return new \OC_OCS_Result(null, 404, "wrong path, file/folder doesn't exist."); + } + $shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null; $shareType = isset($_POST['shareType']) ? (int)$_POST['shareType'] : null; - if($shareType === \OCP\Share::SHARE_TYPE_LINK) { - $permissions = 1; - $shareWith = null; - } else { - $permissions = 31; + switch($shareType) { + case \OCP\Share::SHARE_TYPE_USER: + $permission = 31; + if (!\OCP\User::userExists($shareWith)) { + return new \OC_OCS_Result(null, 404, "user doesn't exist"); + } + break; + case \OCP\Share::SHARE_TYPE_GROUP: + $permission = 31; + if (!\OC_Group::groupExists($shareWith)) { + return new \OC_OCS_Result(null, 404, "group doesn't exist"); + } + break; + case \OCP\Share::SHARE_TYPE_LINK: + $permission = 1; + $shareWith = null; + break; + default: + return new \OC_OCS_Result(null, 404, "unknown share type"); } - $token = null; - if (($shareWith !== null || $shareType === \OCP\Share::SHARE_TYPE_LINK) - && $shareType !== false - && $itemType !== false) { - $token = \OCP\Share::shareItem( + $token = \OCP\Share::shareItem( $itemType, $itemSource, $shareType, $shareWith, - $permissions + $permission ); - } else { - $errorMessage = "You need to specify at least 'shareType' and provide a correct file/folder path." - . " For non public shares you also need specify 'shareWith'."; - } - if ($token) { $data = null; @@ -98,9 +106,90 @@ class Api { } return new \OC_OCS_Result($data); } else { - return new \OC_OCS_Result(null, 404, $errorMessage); + return new \OC_OCS_Result(null, 404, "couldn't share file"); } } + /** + * @brief set permission for a share, path to file is encoded in URL + * @param array $params contain 'shareWith', 'shareType', 'permission' + * @return \OC_OCS_Result + */ + public static function setPermission($params) { + $path = $params['path']; + $itemSource = self::getFileId($path); + $itemType = self::getItemType($path); + + if($itemSource === null) { + return new \OC_OCS_Result(null, 404, "wrong path, file/folder doesn't exist."); + } + + $shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null; + $shareType = isset($_POST['shareType']) ? (int)$_POST['shareType'] : null; + $permission = isset($_POST['permission']) ? (int)$_POST['permission'] : null; + + switch($shareType) { + case \OCP\Share::SHARE_TYPE_USER: + if (!\OCP\User::userExists($shareWith)) { + return new \OC_OCS_Result(null, 404, "user doesn't exist"); + } + break; + case \OCP\Share::SHARE_TYPE_GROUP: + if (!\OC_Group::groupExists($shareWith)) { + return new \OC_OCS_Result(null, 404, "group doesn't exist"); + } + break; + case \OCP\Share::SHARE_TYPE_LINK: + break; + default: + return new \OC_OCS_Result(null, 404, "unknown share type"); + } + + + $return = \OCP\Share::setPermissions( + $itemType, + $itemSource, + $shareType, + $shareWith, + $permission + ); + + if ($return) { + return new \OC_OCS_Result(); + } else { + return new \OC_OCS_Result(null, 404, "couldn't set permissions"); + } + } + + /** + * @brief set expire date, path to file is encoded in URL + * @param array $params contains 'expire' (format DD-MM-YYYY) + * @return \OC_OCS_Result + */ + public static function setExpire($params) { + $path = $params['path']; + $itemSource = self::getFileId($path); + $itemType = self::getItemType($path); + + if($itemSource === null) { + return new \OC_OCS_Result(null, 404, "wrong path, file/folder doesn't exist."); + } + + $expire = isset($_POST['expire']) ? (int)$_POST['expire'] : null; + + $return = false; + if ($expire) { + $return = \OCP\Share::setExpirationDate($itemType, $itemSource, $expire); + } + + if ($return) { + return new \OC_OCS_Result(); + } else { + $msg = "Failed, please check the expire date, expected format 'DD-MM-YYYY'."; + return new \OC_OCS_Result(null, 404, $msg); + } + + + } /** * @brief get file ID from a given path From 14437ffd159db79eaccee4fc88d91084e10ac3c6 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 16 Sep 2013 17:04:49 +0200 Subject: [PATCH 023/297] ocs api for file sharing --- apps/files_sharing/appinfo/routes.php | 32 ++------ apps/files_sharing/lib/api.php | 113 +++++++++++++++++--------- 2 files changed, 84 insertions(+), 61 deletions(-) diff --git a/apps/files_sharing/appinfo/routes.php b/apps/files_sharing/appinfo/routes.php index 3f80614cc0c..cf0a69dc7ec 100644 --- a/apps/files_sharing/appinfo/routes.php +++ b/apps/files_sharing/appinfo/routes.php @@ -4,10 +4,9 @@ function() { require_once __DIR__ . '/../ajax/publicpreview.php'; }); -//TODO: SET: unshare -//TODO: SET: expire date -//TODO: SET: mail notification -//TODO: SET: can upload +// OCS API + +//TODO: SET: mail notification, waiting for PR #4689 to be accepted OC_API::register('get', '/apps/files_sharing/api/share/{path}', @@ -41,25 +40,10 @@ OC_API::register('post', array('path' => ''), array('path' => '.+')); -/* -OC_API::register('get', - '/apps/files_sharing/api/permission/{path}', - array('\OCA\Files\Share\Api', 'getShare'), +OC_API::register('post', + '/apps/files_sharing/api/unshare/{path}', + array('\OCA\Files\Share\Api', 'setUnshare'), 'files_sharing', OC_API::USER_AUTH, - array('path' => '')); - -OC_API::register('get', - '/apps/files_sharing/api/expire/{path}', - array('\OCA\Files\Share\Api', 'getShare'), - 'files_sharing', - OC_API::USER_AUTH, - array('path' => '')); - -OC_API::register('get', - '/apps/files_sharing/api/notify/{path}', - array('\OCA\Files\Share\Api', 'getShare'), - 'files_sharing', - OC_API::USER_AUTH, - array('path' => '')); -*/ + array('path' => ''), + array('path' => '.+')); diff --git a/apps/files_sharing/lib/api.php b/apps/files_sharing/lib/api.php index 90d8a93d3a4..6f05d46cbdf 100644 --- a/apps/files_sharing/lib/api.php +++ b/apps/files_sharing/lib/api.php @@ -50,7 +50,8 @@ class Api { /** * @brief share file with a user/group, path to file is encoded in URL * - * @param array $params with following parameters 'shareWith', 'shareType' + * @param array $params with following parameters 'shareWith', 'shareType', 'path' + * optional 'publicUpload' and 'password' for public shares * @return \OC_OCS_Result result of share operation */ public static function setShare($params) { @@ -69,32 +70,29 @@ class Api { switch($shareType) { case \OCP\Share::SHARE_TYPE_USER: $permission = 31; - if (!\OCP\User::userExists($shareWith)) { - return new \OC_OCS_Result(null, 404, "user doesn't exist"); - } break; case \OCP\Share::SHARE_TYPE_GROUP: $permission = 31; - if (!\OC_Group::groupExists($shareWith)) { - return new \OC_OCS_Result(null, 404, "group doesn't exist"); - } break; case \OCP\Share::SHARE_TYPE_LINK: - $permission = 1; - $shareWith = null; + //allow password protection + $shareWith = isset($_POST['password']) ? $_POST['password'] : null; + $publicUpload = isset($_POST['publicUpload']) ? $_POST['publicUpload'] : 'no'; + $permission = self::getPublicLinkSharePermissions($publicUpload); break; - default: - return new \OC_OCS_Result(null, 404, "unknown share type"); } - - $token = \OCP\Share::shareItem( + try { + $token = \OCP\Share::shareItem( $itemType, $itemSource, $shareType, $shareWith, $permission ); + } catch (\Exception $e) { + return new \OC_OCS_Result(null, 404, $e->getMessage()); + } if ($token) { $data = null; @@ -127,32 +125,18 @@ class Api { $shareType = isset($_POST['shareType']) ? (int)$_POST['shareType'] : null; $permission = isset($_POST['permission']) ? (int)$_POST['permission'] : null; - switch($shareType) { - case \OCP\Share::SHARE_TYPE_USER: - if (!\OCP\User::userExists($shareWith)) { - return new \OC_OCS_Result(null, 404, "user doesn't exist"); - } - break; - case \OCP\Share::SHARE_TYPE_GROUP: - if (!\OC_Group::groupExists($shareWith)) { - return new \OC_OCS_Result(null, 404, "group doesn't exist"); - } - break; - case \OCP\Share::SHARE_TYPE_LINK: - break; - default: - return new \OC_OCS_Result(null, 404, "unknown share type"); + try { + $return = \OCP\Share::setPermissions( + $itemType, + $itemSource, + $shareType, + $shareWith, + $permission + ); + } catch (\Exception $e) { + return new \OC_OCS_Result(null, 404, $e->getMessage()); } - - $return = \OCP\Share::setPermissions( - $itemType, - $itemSource, - $shareType, - $shareWith, - $permission - ); - if ($return) { return new \OC_OCS_Result(); } else { @@ -187,8 +171,63 @@ class Api { $msg = "Failed, please check the expire date, expected format 'DD-MM-YYYY'."; return new \OC_OCS_Result(null, 404, $msg); } + } + /** + * @brief unshare a file/folder + * @param array $params with following parameters 'shareWith', 'shareType', 'path' + * @return \OC_OCS_Result + */ + public static function setUnshare($params) { + $path = $params['path']; + $itemSource = self::getFileId($path); + $itemType = self::getItemType($path); + if($itemSource === null) { + return new \OC_OCS_Result(null, 404, "wrong path, file/folder doesn't exist."); + } + + $shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null; + $shareType = isset($_POST['shareType']) ? (int)$_POST['shareType'] : null; + + if( $shareType == \OCP\Share::SHARE_TYPE_LINK) { + $shareWith = null; + } + + try { + $return = \OCP\Share::unshare( + $itemType, + $itemSource, + $shareType, + $shareWith); + } catch (\Exception $e) { + return new \OC_OCS_Result(null, 404, $e->getMessage()); + } + + if ($return) { + return new \OC_OCS_Result(); + } else { + $msg = "Unshare Failed"; + return new \OC_OCS_Result(null, 404, $msg); + } + } + + /** + * @brief get public link share permissions to allow/forbid public uploads + * @param string $publicUpload 'yes' or 'no' + * @return int permissions read (1) or create,update,read (7) + */ + private static function getPublicLinkSharePermissions($publicUpload) { + + $publicUploadEnabled = \OC_Appconfig::getValue('core', 'shareapi_allow_public_upload', 'yes'); + + if(\OC_App::isEnabled('files_encryption') || + $publicUploadEnabled !== 'yes' || + $publicUpload === 'no') { + return 1; // read + } else { + return 7; // create, update, read + } } /** From 7aed24fa6c3df13d553f5b83b7de57e89f119d15 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 16 Sep 2013 17:28:17 +0200 Subject: [PATCH 024/297] allow to set a different permission during initial share operation --- apps/files_sharing/lib/api.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/files_sharing/lib/api.php b/apps/files_sharing/lib/api.php index 6f05d46cbdf..ba186094311 100644 --- a/apps/files_sharing/lib/api.php +++ b/apps/files_sharing/lib/api.php @@ -69,10 +69,10 @@ class Api { switch($shareType) { case \OCP\Share::SHARE_TYPE_USER: - $permission = 31; + $permission = isset($_POST['permission']) ? (int)$_POST['permission'] : 31; break; case \OCP\Share::SHARE_TYPE_GROUP: - $permission = 31; + $permission = isset($_POST['permission']) ? (int)$_POST['permission'] : 31; break; case \OCP\Share::SHARE_TYPE_LINK: //allow password protection @@ -265,4 +265,4 @@ class Api { return $itemType; } -} \ No newline at end of file +} From ef3307f0996f1025a75a697a549166b26576e670 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 16 Sep 2013 17:42:56 +0200 Subject: [PATCH 025/297] return error if public upload is disabled --- apps/files_sharing/lib/api.php | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/apps/files_sharing/lib/api.php b/apps/files_sharing/lib/api.php index ba186094311..f641623ac10 100644 --- a/apps/files_sharing/lib/api.php +++ b/apps/files_sharing/lib/api.php @@ -77,8 +77,17 @@ class Api { case \OCP\Share::SHARE_TYPE_LINK: //allow password protection $shareWith = isset($_POST['password']) ? $_POST['password'] : null; + //check public link share + $publicUploadEnabled = \OC_Appconfig::getValue('core', 'shareapi_allow_public_upload', 'yes'); + $encryptionEnabled = \OC_App::isEnabled('files_encryption'); + if(isset($_POST['publicUpload']) && + ($encryptionEnabled || $publicUploadEnabled !== 'yes')) { + return new \OC_OCS_Result(null, 404, "public upload disabled by the administrator"); + } $publicUpload = isset($_POST['publicUpload']) ? $_POST['publicUpload'] : 'no'; - $permission = self::getPublicLinkSharePermissions($publicUpload); + // read, create, update (7) if public upload is enabled or + // read (1) if public upload is disabled + $permission = $publicUpload === 'yes' ? 7 : 1; break; } @@ -212,24 +221,6 @@ class Api { } } - /** - * @brief get public link share permissions to allow/forbid public uploads - * @param string $publicUpload 'yes' or 'no' - * @return int permissions read (1) or create,update,read (7) - */ - private static function getPublicLinkSharePermissions($publicUpload) { - - $publicUploadEnabled = \OC_Appconfig::getValue('core', 'shareapi_allow_public_upload', 'yes'); - - if(\OC_App::isEnabled('files_encryption') || - $publicUploadEnabled !== 'yes' || - $publicUpload === 'no') { - return 1; // read - } else { - return 7; // create, update, read - } - } - /** * @brief get file ID from a given path * @param string $path From 86dbb13823087f316e9962ca9453303b73b55bde Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 17 Sep 2013 11:53:06 +0200 Subject: [PATCH 026/297] more rest-style API --- apps/files_sharing/appinfo/routes.php | 40 +++---- apps/files_sharing/lib/api.php | 147 ++++++++++++++++++++------ 2 files changed, 134 insertions(+), 53 deletions(-) diff --git a/apps/files_sharing/appinfo/routes.php b/apps/files_sharing/appinfo/routes.php index cf0a69dc7ec..381a1091e0a 100644 --- a/apps/files_sharing/appinfo/routes.php +++ b/apps/files_sharing/appinfo/routes.php @@ -9,40 +9,34 @@ function() { //TODO: SET: mail notification, waiting for PR #4689 to be accepted OC_API::register('get', - '/apps/files_sharing/api/share/{path}', + '/apps/files_sharing/api/shares', + array('\OCA\Files\Share\Api', 'getAllShare'), + 'files_sharing'); + +OC_API::register('post', + '/apps/files_sharing/api/shares', + array('\OCA\Files\Share\Api', 'createShare'), + 'files_sharing'); + +OC_API::register('get', + '/apps/files_sharing/api/shares/{path}', array('\OCA\Files\Share\Api', 'getShare'), 'files_sharing', OC_API::USER_AUTH, array('path' => ''), array('path' => '.+')); //allow slashes in parameter path -OC_API::register('post', - '/apps/files_sharing/api/share/{path}', - array('\OCA\Files\Share\Api', 'setShare'), +OC_API::register('put', + '/apps/files_sharing/api/shares/{path}', + array('\OCA\Files\Share\Api', 'updateShare'), 'files_sharing', OC_API::USER_AUTH, array('path' => ''), array('path' => '.+')); -OC_API::register('post', - '/apps/files_sharing/api/permission/{path}', - array('\OCA\Files\Share\Api', 'setPermission'), - 'files_sharing', - OC_API::USER_AUTH, - array('path' => ''), - array('path' => '.+')); - -OC_API::register('post', - '/apps/files_sharing/api/expire/{path}', - array('\OCA\Files\Share\Api', 'setExpire'), - 'files_sharing', - OC_API::USER_AUTH, - array('path' => ''), - array('path' => '.+')); - -OC_API::register('post', - '/apps/files_sharing/api/unshare/{path}', - array('\OCA\Files\Share\Api', 'setUnshare'), +OC_API::register('delete', + '/apps/files_sharing/api/shares/{path}', + array('\OCA\Files\Share\Api', 'deleteShare'), 'files_sharing', OC_API::USER_AUTH, array('path' => ''), diff --git a/apps/files_sharing/lib/api.php b/apps/files_sharing/lib/api.php index f641623ac10..1cfe9a67a25 100644 --- a/apps/files_sharing/lib/api.php +++ b/apps/files_sharing/lib/api.php @@ -24,6 +24,23 @@ namespace OCA\Files\Share; class Api { + /** + * @brief get all shares + * + * @param array $params + * @return \OC_OCS_Result share information + */ + public static function getAllShare($params) { + + $share = \OCP\Share::getItemShared('file', null); + + if ($share !== null) { + return new \OC_OCS_Result($share); + } else { + return new \OC_OCS_Result(null, 404, 'no shares available'); + } + } + /** * @brief get share information for a given file/folder path is encoded in URL * @@ -48,14 +65,17 @@ class Api { } /** - * @brief share file with a user/group, path to file is encoded in URL - * - * @param array $params with following parameters 'shareWith', 'shareType', 'path' - * optional 'publicUpload' and 'password' for public shares - * @return \OC_OCS_Result result of share operation + * @breif create a new share + * @param array $params 'path', 'shareWith', 'shareType' + * @return \OC_OCS_Result */ - public static function setShare($params) { - $path = $params['path']; + public static function createShare($params) { + + $path = isset($_POST['path']) ? $_POST['path'] : null; + + if($path === null) { + return new \OC_OCS_Result(null, 404, "please specify a file or folder path"); + } $itemSource = self::getFileId($path); $itemType = self::getItemType($path); @@ -69,10 +89,10 @@ class Api { switch($shareType) { case \OCP\Share::SHARE_TYPE_USER: - $permission = isset($_POST['permission']) ? (int)$_POST['permission'] : 31; + $permissions = isset($_POST['permissions']) ? (int)$_POST['permissions'] : 31; break; case \OCP\Share::SHARE_TYPE_GROUP: - $permission = isset($_POST['permission']) ? (int)$_POST['permission'] : 31; + $permissions = isset($_POST['permissions']) ? (int)$_POST['permissions'] : 31; break; case \OCP\Share::SHARE_TYPE_LINK: //allow password protection @@ -87,7 +107,7 @@ class Api { $publicUpload = isset($_POST['publicUpload']) ? $_POST['publicUpload'] : 'no'; // read, create, update (7) if public upload is enabled or // read (1) if public upload is disabled - $permission = $publicUpload === 'yes' ? 7 : 1; + $permissions = $publicUpload === 'yes' ? 7 : 1; break; } @@ -97,7 +117,7 @@ class Api { $itemSource, $shareType, $shareWith, - $permission + $permissions ); } catch (\Exception $e) { return new \OC_OCS_Result(null, 404, $e->getMessage()); @@ -116,13 +136,17 @@ class Api { return new \OC_OCS_Result(null, 404, "couldn't share file"); } } + /** - * @brief set permission for a share, path to file is encoded in URL - * @param array $params contain 'shareWith', 'shareType', 'permission' + * update shares, e.g. expire date, permissions, etc + * @param array $params 'path', 'shareWith', 'shareType' and + * 'permissions' or 'expire' or 'password' * @return \OC_OCS_Result */ - public static function setPermission($params) { + public static function updateShare($params) { + $path = $params['path']; + $itemSource = self::getFileId($path); $itemType = self::getItemType($path); @@ -130,9 +154,34 @@ class Api { return new \OC_OCS_Result(null, 404, "wrong path, file/folder doesn't exist."); } - $shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null; - $shareType = isset($_POST['shareType']) ? (int)$_POST['shareType'] : null; - $permission = isset($_POST['permission']) ? (int)$_POST['permission'] : null; + try { + if(isset($params['_put']['permissions'])) { + return self::updatePermissions($itemSource, $itemType, $params); + } elseif (isset($params['_put']['expire'])) { + return self::updateExpire($itemSource, $itemType, $params); + } elseif (isset($params['_put']['password'])) { + return self::updatePassword($itemSource, $itemType, $params); + } + } catch (\Exception $e) { + return new \OC_OCS_Result(null, 404, $e->getMessage()); + } + + return new \OC_OCS_Result(null, 404, "Couldn't find a parameter to update"); + + } + + /** + * @brief update permissions for a share + * @param int $itemSource file ID + * @param string $itemType 'file' or 'folder' + * @param array $params contain 'shareWith', 'shareType', 'permissions' + * @return \OC_OCS_Result + */ + private static function updatePermissions($itemSource, $itemType, $params) { + + $shareWith = isset($params['_put']['shareWith']) ? $params['_put']['shareWith'] : null; + $shareType = isset($params['_put']['shareType']) ? (int)$params['_put']['shareType'] : null; + $permissions = isset($params['_put']['permissions']) ? (int)$params['_put']['permissions'] : null; try { $return = \OCP\Share::setPermissions( @@ -140,7 +189,7 @@ class Api { $itemSource, $shareType, $shareWith, - $permission + $permissions ); } catch (\Exception $e) { return new \OC_OCS_Result(null, 404, $e->getMessage()); @@ -153,21 +202,59 @@ class Api { } } + /** + * @brief update password for public link share + * @param int $itemSource file ID + * @param string $itemType 'file' or 'folder' + * @param type $params 'password' + * @return \OC_OCS_Result + */ + private static function updatePassword($itemSource, $itemType, $params) { + error_log("update password"); + $shareWith = isset($params['_put']['password']) ? $params['_put']['password'] : null; + + if($shareWith === '') { + $shareWith = null; + } + + $items = \OCP\Share::getItemShared($itemType, $itemSource); + + $checkExists = false; + foreach ($items as $item) { + if($item['share_type'] === \OCP\Share::SHARE_TYPE_LINK) { + $checkExists = true; + $permissions = $item['permissions']; + } + } + + if (!$checkExists) { + return new \OC_OCS_Result(null, 404, "share doesn't exists, can't change password"); + } + + $result = \OCP\Share::shareItem( + $itemType, + $itemSource, + \OCP\Share::SHARE_TYPE_LINK, + $shareWith, + $permissions + ); + if($result) { + return new \OC_OCS_Result(); + } + + return new \OC_OCS_Result(null, 404, "couldn't set password"); + } + /** * @brief set expire date, path to file is encoded in URL + * @param int $itemSource file ID + * @param string $itemType 'file' or 'folder' * @param array $params contains 'expire' (format DD-MM-YYYY) * @return \OC_OCS_Result */ - public static function setExpire($params) { - $path = $params['path']; - $itemSource = self::getFileId($path); - $itemType = self::getItemType($path); + private static function updateExpire($itemSource, $itemType, $params) { - if($itemSource === null) { - return new \OC_OCS_Result(null, 404, "wrong path, file/folder doesn't exist."); - } - - $expire = isset($_POST['expire']) ? (int)$_POST['expire'] : null; + $expire = isset($params['_put']['expire']) ? (int)$params['_put']['expire'] : null; $return = false; if ($expire) { @@ -187,7 +274,7 @@ class Api { * @param array $params with following parameters 'shareWith', 'shareType', 'path' * @return \OC_OCS_Result */ - public static function setUnshare($params) { + public static function deleteShare($params) { $path = $params['path']; $itemSource = self::getFileId($path); $itemType = self::getItemType($path); @@ -196,8 +283,8 @@ class Api { return new \OC_OCS_Result(null, 404, "wrong path, file/folder doesn't exist."); } - $shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null; - $shareType = isset($_POST['shareType']) ? (int)$_POST['shareType'] : null; + $shareWith = isset($params['_delete']['shareWith']) ? $params['_delete']['shareWith'] : null; + $shareType = isset($params['_delete']['shareType']) ? (int)$params['_delete']['shareType'] : null; if( $shareType == \OCP\Share::SHARE_TYPE_LINK) { $shareWith = null; From e52639e4e64d31c6aec3bb4b865bee8a84db08f2 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 17 Sep 2013 15:27:10 +0200 Subject: [PATCH 027/297] use share ID as REST resource --- apps/files_sharing/appinfo/routes.php | 25 +-- apps/files_sharing/lib/api.php | 229 ++++++++++++++++++-------- 2 files changed, 167 insertions(+), 87 deletions(-) diff --git a/apps/files_sharing/appinfo/routes.php b/apps/files_sharing/appinfo/routes.php index 381a1091e0a..a373bff4dad 100644 --- a/apps/files_sharing/appinfo/routes.php +++ b/apps/files_sharing/appinfo/routes.php @@ -9,35 +9,26 @@ function() { //TODO: SET: mail notification, waiting for PR #4689 to be accepted OC_API::register('get', - '/apps/files_sharing/api/shares', + '/apps/files_sharing/api/v1/shares', array('\OCA\Files\Share\Api', 'getAllShare'), 'files_sharing'); OC_API::register('post', - '/apps/files_sharing/api/shares', + '/apps/files_sharing/api/v1/shares', array('\OCA\Files\Share\Api', 'createShare'), 'files_sharing'); OC_API::register('get', - '/apps/files_sharing/api/shares/{path}', + '/apps/files_sharing/api/v1/shares/{id}', array('\OCA\Files\Share\Api', 'getShare'), - 'files_sharing', - OC_API::USER_AUTH, - array('path' => ''), - array('path' => '.+')); //allow slashes in parameter path + 'files_sharing'); OC_API::register('put', - '/apps/files_sharing/api/shares/{path}', + '/apps/files_sharing/api/v1/shares/{id}', array('\OCA\Files\Share\Api', 'updateShare'), - 'files_sharing', - OC_API::USER_AUTH, - array('path' => ''), - array('path' => '.+')); + 'files_sharing'); OC_API::register('delete', - '/apps/files_sharing/api/shares/{path}', + '/apps/files_sharing/api/v1/shares/{id}', array('\OCA\Files\Share\Api', 'deleteShare'), - 'files_sharing', - OC_API::USER_AUTH, - array('path' => ''), - array('path' => '.+')); + 'files_sharing'); diff --git a/apps/files_sharing/lib/api.php b/apps/files_sharing/lib/api.php index 1cfe9a67a25..87841150de7 100644 --- a/apps/files_sharing/lib/api.php +++ b/apps/files_sharing/lib/api.php @@ -27,11 +27,17 @@ class Api { /** * @brief get all shares * - * @param array $params + * @param array $params option 'file' to limit the result to a specific file/folder * @return \OC_OCS_Result share information */ public static function getAllShare($params) { + // if a file is specified, get the share for this file + if (isset($_GET['file'])) { + $params['itemSource'] = self::getFileId($_GET['file']); + return self::getShare($params); + } + $share = \OCP\Share::getItemShared('file', null); if ($share !== null) { @@ -42,25 +48,43 @@ class Api { } /** - * @brief get share information for a given file/folder path is encoded in URL + * @brief get share information for a given share * - * @param array $params which contains a 'path' to a file/folder + * @param array $params which contains a 'id' * @return \OC_OCS_Result share information */ public static function getShare($params) { - $path = $params['path']; - $fileId = self::getFileId($path); - if ($fileId !== null) { - $share = \OCP\Share::getItemShared('file', $fileId); + // either the $params already contains a itemSource if we come from + // getAllShare() or we need to translate the shareID to a itemSource + if(isset($params['itemSource'])) { + $itemSource = $params['itemSource']; + $getAll = true; } else { - $share = null; + $s = self::getShareFromId($params['id']); + $itemSource = $s['item_source']; + $getAll = false; } - if ($share !== null) { - return new \OC_OCS_Result($share); + if ($itemSource !== null) { + $shares = \OCP\Share::getItemShared('file', $itemSource); + // if a specific share was specified only return this one + if ($getAll === false) { + foreach ($shares as $share) { + if ($share['id'] === (int)$params['id']) { + $shares = array('element' => $share); + break; + } + } + } } else { - return new \OC_OCS_Result(null, 404, 'file/folder doesn\'t exists'); + $shares = null; + } + + if ($shares === null || empty($shares)) { + return new \OC_OCS_Result(null, 404, 'share doesn\'t exists'); + } else { + return new \OC_OCS_Result($shares); } } @@ -74,7 +98,7 @@ class Api { $path = isset($_POST['path']) ? $_POST['path'] : null; if($path === null) { - return new \OC_OCS_Result(null, 404, "please specify a file or folder path"); + return new \OC_OCS_Result(null, 400, "please specify a file or folder path"); } $itemSource = self::getFileId($path); @@ -125,11 +149,27 @@ class Api { if ($token) { $data = null; + $shares = \OCP\Share::getItemShared('file', $itemSource); if(is_string($token)) { //public link share + foreach ($shares as $share) { + if ($share['token'] === $token) { + $shareId = $share['id']; + break; + } + } $url = \OCP\Util::linkToPublic('files&t='.$token); $data = array('url' => $url, // '&' gets encoded to $amp; - 'token' => $token); + 'token' => $token, + 'id' => $shareId); + } else { + foreach ($shares as $share) { + if ($share['share_with'] === $shareWith && $share['share_type'] === $shareType) { + $shareId = $share['id']; + $data = array('id' => $shareId); + break; + } + } } return new \OC_OCS_Result($data); } else { @@ -138,51 +178,65 @@ class Api { } /** - * update shares, e.g. expire date, permissions, etc - * @param array $params 'path', 'shareWith', 'shareType' and - * 'permissions' or 'expire' or 'password' + * update shares, e.g. password, permissions, etc + * @param array $params shareId 'id' and the parameter we want to update + * currently supported: permissions, password, publicUpload * @return \OC_OCS_Result */ public static function updateShare($params) { - $path = $params['path']; - - $itemSource = self::getFileId($path); - $itemType = self::getItemType($path); + $share = self::getShareFromId($params['id']); + $itemSource = isset($share['item_source']) ? $share['item_source'] : null; if($itemSource === null) { - return new \OC_OCS_Result(null, 404, "wrong path, file/folder doesn't exist."); + return new \OC_OCS_Result(null, 404, "wrong share Id, share doesn't exist."); } try { if(isset($params['_put']['permissions'])) { - return self::updatePermissions($itemSource, $itemType, $params); - } elseif (isset($params['_put']['expire'])) { - return self::updateExpire($itemSource, $itemType, $params); + return self::updatePermissions($share, $params); } elseif (isset($params['_put']['password'])) { - return self::updatePassword($itemSource, $itemType, $params); + return self::updatePassword($share, $params); + } elseif (isset($params['_put']['publicUpload'])) { + return self::updatePublicUpload($share, $params); } } catch (\Exception $e) { - return new \OC_OCS_Result(null, 404, $e->getMessage()); + return new \OC_OCS_Result(null, 400, $e->getMessage()); } - return new \OC_OCS_Result(null, 404, "Couldn't find a parameter to update"); + return new \OC_OCS_Result(null, 400, "Wrong or no update parameter given"); } /** * @brief update permissions for a share - * @param int $itemSource file ID - * @param string $itemType 'file' or 'folder' - * @param array $params contain 'shareWith', 'shareType', 'permissions' + * @param array $share information about the share + * @param array $params contains 'permissions' * @return \OC_OCS_Result */ - private static function updatePermissions($itemSource, $itemType, $params) { + private static function updatePermissions($share, $params) { - $shareWith = isset($params['_put']['shareWith']) ? $params['_put']['shareWith'] : null; - $shareType = isset($params['_put']['shareType']) ? (int)$params['_put']['shareType'] : null; + $itemSource = $share['item_source']; + $itemType = $share['item_type']; + $shareWith = $share['share_with']; + $shareType = $share['share_type']; $permissions = isset($params['_put']['permissions']) ? (int)$params['_put']['permissions'] : null; + $publicUploadStatus = \OC_Appconfig::getValue('core', 'shareapi_allow_public_upload', 'yes'); + $encryptionEnabled = \OC_App::isEnabled('files_encryption'); + $publicUploadEnabled = false; + if(!$encryptionEnabled && $publicUploadStatus === 'yes') { + $publicUploadEnabled = true; + } + + // only change permissions for public shares if public upload is enabled + // and we want to set permissions to 1 (read only) or 7 (allow upload) + if ( (int)$shareType === \OCP\Share::SHARE_TYPE_LINK ) { + if ($publicUploadEnabled === false || ($permissions !== 7 && $permissions !== 1)) { + return new \OC_OCS_Result(null, 400, "can't change permission for public link share"); + } + } + try { $return = \OCP\Share::setPermissions( $itemType, @@ -202,15 +256,48 @@ class Api { } } + /** + * @brief enable/disable public upload + * @param array $share information about the share + * @param array $params contains 'publicUpload' which can be 'yes' or 'no' + * @return \OC_OCS_Result + */ + private static function updatePublicUpload($share, $params) { + + $publicUploadEnabled = \OC_Appconfig::getValue('core', 'shareapi_allow_public_upload', 'yes'); + $encryptionEnabled = \OC_App::isEnabled('files_encryption'); + if($encryptionEnabled || $publicUploadEnabled !== 'yes') { + return new \OC_OCS_Result(null, 404, "public upload disabled by the administrator"); + } + + if ($share['item_type'] !== 'folder' || + (int)$share['share_type'] !== \OCP\Share::SHARE_TYPE_LINK ) { + return new \OC_OCS_Result(null, 404, "public upload is only possible for public shared folders"); + } + + // read, create, update (7) if public upload is enabled or + // read (1) if public upload is disabled + $params['_put']['permissions'] = $params['_put']['publicUpload'] === 'yes' ? 7 : 1; + + return self::updatePermissions($share, $params); + + } + /** * @brief update password for public link share - * @param int $itemSource file ID - * @param string $itemType 'file' or 'folder' + * @param array $share information about the share * @param type $params 'password' * @return \OC_OCS_Result */ - private static function updatePassword($itemSource, $itemType, $params) { - error_log("update password"); + private static function updatePassword($share, $params) { + + $itemSource = $share['item_source']; + $itemType = $share['item_type']; + + if( (int)$share['share_type'] !== \OCP\Share::SHARE_TYPE_LINK) { + return new \OC_OCS_Result(null, 400, "password protection is only supported for public shares"); + } + $shareWith = isset($params['_put']['password']) ? $params['_put']['password'] : null; if($shareWith === '') { @@ -230,7 +317,7 @@ class Api { if (!$checkExists) { return new \OC_OCS_Result(null, 404, "share doesn't exists, can't change password"); } - + error_log("type: $itemType"); $result = \OCP\Share::shareItem( $itemType, $itemSource, @@ -245,48 +332,25 @@ class Api { return new \OC_OCS_Result(null, 404, "couldn't set password"); } - /** - * @brief set expire date, path to file is encoded in URL - * @param int $itemSource file ID - * @param string $itemType 'file' or 'folder' - * @param array $params contains 'expire' (format DD-MM-YYYY) - * @return \OC_OCS_Result - */ - private static function updateExpire($itemSource, $itemType, $params) { - - $expire = isset($params['_put']['expire']) ? (int)$params['_put']['expire'] : null; - - $return = false; - if ($expire) { - $return = \OCP\Share::setExpirationDate($itemType, $itemSource, $expire); - } - - if ($return) { - return new \OC_OCS_Result(); - } else { - $msg = "Failed, please check the expire date, expected format 'DD-MM-YYYY'."; - return new \OC_OCS_Result(null, 404, $msg); - } - } - /** * @brief unshare a file/folder - * @param array $params with following parameters 'shareWith', 'shareType', 'path' + * @param array $params contains the shareID 'id' which should be unshared * @return \OC_OCS_Result */ public static function deleteShare($params) { - $path = $params['path']; - $itemSource = self::getFileId($path); - $itemType = self::getItemType($path); + + $share = self::getShareFromId($params['id']); + $itemSource = isset($share['item_source']) ? $share['item_source'] : null; + $itemType = isset($share['item_type']) ? $share['item_type'] : null;; if($itemSource === null) { - return new \OC_OCS_Result(null, 404, "wrong path, file/folder doesn't exist."); + return new \OC_OCS_Result(null, 404, "wrong share ID, share doesn't exist."); } - $shareWith = isset($params['_delete']['shareWith']) ? $params['_delete']['shareWith'] : null; - $shareType = isset($params['_delete']['shareType']) ? (int)$params['_delete']['shareType'] : null; + $shareWith = isset($share['share_with']) ? $share['share_with'] : null; + $shareType = isset($share['share_type']) ? (int)$share['share_type'] : null; - if( $shareType == \OCP\Share::SHARE_TYPE_LINK) { + if( $shareType === \OCP\Share::SHARE_TYPE_LINK) { $shareWith = null; } @@ -343,4 +407,29 @@ class Api { return $itemType; } + /** + * @brief get some information from a given share + * @param int $shareID + * @return array with: item_source, share_type, share_with, item_type, permissions + */ + private static function getShareFromId($shareID) { + $sql = 'SELECT `item_source`, `share_type`, `share_with`, `item_type`, `permissions` FROM `*PREFIX*share` WHERE `id` = ?'; + $args = array($shareID); + $query = \OCP\DB::prepare($sql); + $result = $query->execute($args); + + $share = Null; + + if (\OCP\DB::isError($result)) { + \OCP\Util::writeLog('files_sharing', \OC_DB::getErrorMessage($result), \OCP\Util::ERROR); + } else { + if ($result->numRows() > 0) { + $share = $result->fetchRow(); + } + } + + return $share; + + } + } From 171b7ebffe96c4f6bd326652a6c12118956e39ca Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 18 Sep 2013 10:11:20 +0200 Subject: [PATCH 028/297] remove debug output --- apps/files_sharing/lib/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_sharing/lib/api.php b/apps/files_sharing/lib/api.php index 87841150de7..b88850bf17d 100644 --- a/apps/files_sharing/lib/api.php +++ b/apps/files_sharing/lib/api.php @@ -317,7 +317,7 @@ class Api { if (!$checkExists) { return new \OC_OCS_Result(null, 404, "share doesn't exists, can't change password"); } - error_log("type: $itemType"); + $result = \OCP\Share::shareItem( $itemType, $itemSource, From 5ae4d675406b310df0940c8b9a43dcf556010e91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Wed, 18 Sep 2013 11:06:00 +0200 Subject: [PATCH 029/297] in case the cache cannot be initialized within the autoloader we just shoul not use it --- lib/autoloader.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/autoloader.php b/lib/autoloader.php index 01841f831be..2c19350e904 100644 --- a/lib/autoloader.php +++ b/lib/autoloader.php @@ -117,7 +117,11 @@ class Autoloader { // Does this PHP have an in-memory cache? We cache the paths there if ($this->constructingMemoryCache && !$this->memoryCache) { $this->constructingMemoryCache = false; - $this->memoryCache = \OC\Memcache\Factory::createLowLatency('Autoloader'); + try { + $this->memoryCache = \OC\Memcache\Factory::createLowLatency('Autoloader'); + } catch(\Exception $ex) { + // no caching then - fine with me + } } if ($this->memoryCache) { $pathsToRequire = $this->memoryCache->get($class); From ce58c32c901fb874264922dabec1692f9d05123d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Wed, 18 Sep 2013 11:07:19 +0200 Subject: [PATCH 030/297] using OC_Config::$object->setValue in order to get the underlying exception thrown up to the caller --- lib/util.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/util.php b/lib/util.php index 41f5f1d16be..b9ff07a03fa 100755 --- a/lib/util.php +++ b/lib/util.php @@ -552,7 +552,7 @@ class OC_Util { if(is_null($id)) { // We need to guarantee at least one letter in instanceid so it can be used as the session_name $id = 'oc' . self::generateRandomBytes(10); - OC_Config::setValue('instanceid', $id); + OC_Config::$object->setValue('instanceid', $id); } return $id; } From 5fb0e257a4e7b16024389261cfe924f53deb69ae Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 18 Sep 2013 16:03:53 +0200 Subject: [PATCH 031/297] let user repeat the recovery key password to prevent typos --- apps/files_encryption/js/settings-admin.js | 36 ++++++++++--------- .../templates/settings-admin.php | 28 +++++++++------ 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/apps/files_encryption/js/settings-admin.js b/apps/files_encryption/js/settings-admin.js index 6647c621e7b..82fdb517088 100644 --- a/apps/files_encryption/js/settings-admin.js +++ b/apps/files_encryption/js/settings-admin.js @@ -1,6 +1,6 @@ /** - * Copyright (c) 2013, Sam Tuke , Robin Appelman - * + * Copyright (c) 2013, Sam Tuke , Robin Appelman + * , Bjoern Schiessle * This file is licensed under the Affero General Public License version 3 or later. * See the COPYING-README file. */ @@ -31,22 +31,23 @@ $(document).ready(function(){ // Trigger ajax on recoveryAdmin status change var enabledStatus = $('#adminEnableRecovery').val(); - $('input:password[name="recoveryPassword"]').keyup(function(event) { - var recoveryPassword = $( '#recoveryPassword' ).val(); + $('input:password[name="encryptionRecoveryPassword"]').keyup(function(event) { + var recoveryPassword = $( '#encryptionRecoveryPassword' ).val(); + var recoveryPasswordRepeated = $( '#repeatEncryptionRecoveryPassword' ).val(); var checkedButton = $('input:radio[name="adminEnableRecovery"]:checked').val(); var uncheckedValue = (1+parseInt(checkedButton)) % 2; - if (recoveryPassword != '' ) { + if (recoveryPassword !== '' && recoveryPassword === recoveryPasswordRepeated) { $('input:radio[name="adminEnableRecovery"][value="'+uncheckedValue.toString()+'"]').removeAttr("disabled"); } else { $('input:radio[name="adminEnableRecovery"][value="'+uncheckedValue.toString()+'"]').attr("disabled", "true"); } }); - $( 'input:radio[name="adminEnableRecovery"]' ).change( + $( 'input:radio[name="adminEnableRecovery"]' ).change( function() { var recoveryStatus = $( this ).val(); var oldStatus = (1+parseInt(recoveryStatus)) % 2; - var recoveryPassword = $( '#recoveryPassword' ).val(); + var recoveryPassword = $( '#encryptionRecoveryPassword' ).val(); $.post( OC.filePath( 'files_encryption', 'ajax', 'adminrecovery.php' ) , { adminEnableRecovery: recoveryStatus, recoveryPassword: recoveryPassword } @@ -57,11 +58,10 @@ $(document).ready(function(){ } else { OC.Notification.hide(); if (recoveryStatus === "0") { - $('button:button[name="submitChangeRecoveryKey"]').attr("disabled", "true"); - $('input:password[name="changeRecoveryPassword"]').attr("disabled", "true"); - $('input:password[name="changeRecoveryPassword"]').val(""); + $('p[name="changeRecoveryPasswordBlock"]').attr("class", "hidden"); } else { - $('input:password[name="changeRecoveryPassword"]').removeAttr("disabled"); + $('input:password[name="changeRecoveryPassword"]').val(""); + $('p[name="changeRecoveryPasswordBlock"]').removeAttr("class"); } } } @@ -72,9 +72,11 @@ $(document).ready(function(){ // change recovery password $('input:password[name="changeRecoveryPassword"]').keyup(function(event) { - var oldRecoveryPassword = $('input:password[id="oldRecoveryPassword"]').val(); - var newRecoveryPassword = $('input:password[id="newRecoveryPassword"]').val(); - if (newRecoveryPassword != '' && oldRecoveryPassword != '' ) { + var oldRecoveryPassword = $('#oldEncryptionRecoveryPassword').val(); + var newRecoveryPassword = $('#newEncryptionRecoveryPassword').val(); + var newRecoveryPasswordRepeated = $('#repeatedNewEncryptionRecoveryPassword').val(); + console.log("new: " + newRecoveryPassword + " - repeated: " + newRecoveryPasswordRepeated); + if (newRecoveryPassword !== '' && oldRecoveryPassword !== '' && newRecoveryPassword === newRecoveryPasswordRepeated) { $('button:button[name="submitChangeRecoveryKey"]').removeAttr("disabled"); } else { $('button:button[name="submitChangeRecoveryKey"]').attr("disabled", "true"); @@ -83,8 +85,8 @@ $(document).ready(function(){ $('button:button[name="submitChangeRecoveryKey"]').click(function() { - var oldRecoveryPassword = $('input:password[id="oldRecoveryPassword"]').val(); - var newRecoveryPassword = $('input:password[id="newRecoveryPassword"]').val(); + var oldRecoveryPassword = $('#oldEncryptionRecoveryPassword').val(); + var newRecoveryPassword = $('#newEncryptionRecoveryPassword').val(); OC.msg.startSaving('#encryption .msg'); $.post( OC.filePath( 'files_encryption', 'ajax', 'changeRecoveryPassword.php' ) @@ -98,5 +100,5 @@ $(document).ready(function(){ } ); }); - + }); diff --git a/apps/files_encryption/templates/settings-admin.php b/apps/files_encryption/templates/settings-admin.php index f5f7582c2a6..3a6adc09f4b 100644 --- a/apps/files_encryption/templates/settings-admin.php +++ b/apps/files_encryption/templates/settings-admin.php @@ -10,14 +10,17 @@ t("Enable recovery key (allow to recover users files in case of password loss):")); ?>

    - +
    + + +
    /> + /> t("Enabled")); ?>
    @@ -25,27 +28,32 @@ type='radio' name='adminEnableRecovery' value='0' - /> + /> t("Disabled")); ?>



    -

    +

    > t("Change recovery key password:")); ?>

    /> - + id="oldEncryptionRecoveryPassword" + +

    /> - + id="newEncryptionRecoveryPassword" + +
    + t("Repeat New Recovery key password")); ?>