diff options
author | Pellaeon Lin <nfsmwlin@gmail.com> | 2014-01-30 22:50:20 +0800 |
---|---|---|
committer | Pellaeon Lin <nfsmwlin@gmail.com> | 2014-01-30 22:50:20 +0800 |
commit | 099b71c712c38de7dac7e386252da02bb0cadf12 (patch) | |
tree | 84bcf83efdc4cc759a5ff184fa5148195abaab51 /lib/public | |
parent | 929c930b0afd682bb98eb389d7ebad91bb34d643 (diff) | |
parent | 299a8285bd2601ccbac988b2e3e9b067d47921a2 (diff) | |
download | nextcloud-server-099b71c712c38de7dac7e386252da02bb0cadf12.tar.gz nextcloud-server-099b71c712c38de7dac7e386252da02bb0cadf12.zip |
Merge branch 'master' into pr-exceed_upload_limit_msg
Conflicts:
apps/files/templates/index.php
apps/files_sharing/templates/public.php
Diffstat (limited to 'lib/public')
-rw-r--r-- | lib/public/backgroundjob.php | 8 | ||||
-rw-r--r-- | lib/public/db.php | 12 | ||||
-rw-r--r-- | lib/public/iconfig.php | 15 | ||||
-rw-r--r-- | lib/public/json.php | 18 | ||||
-rw-r--r-- | lib/public/response.php | 9 | ||||
-rw-r--r-- | lib/public/share.php | 60 | ||||
-rw-r--r-- | lib/public/util.php | 16 |
7 files changed, 114 insertions, 24 deletions
diff --git a/lib/public/backgroundjob.php b/lib/public/backgroundjob.php index 1788c4e293d..a7f54491dfa 100644 --- a/lib/public/backgroundjob.php +++ b/lib/public/backgroundjob.php @@ -45,6 +45,7 @@ use \OC\BackgroundJob\JobList; class BackgroundJob { /** * get the execution type of background jobs + * * @return string * * This method returns the type how background jobs are executed. If the user @@ -56,6 +57,7 @@ class BackgroundJob { /** * sets the background jobs execution type + * * @param string $type execution type * @return boolean * @@ -83,8 +85,10 @@ class BackgroundJob { * @return true */ public static function addRegularTask($klass, $method) { - self::registerJob('OC\BackgroundJob\Legacy\RegularJob', array($klass, $method)); - return true; + if (!\OC::needUpgrade()) { + self::registerJob('OC\BackgroundJob\Legacy\RegularJob', array($klass, $method)); + return true; + } } /** diff --git a/lib/public/db.php b/lib/public/db.php index c9997c79c3c..4a19d78d444 100644 --- a/lib/public/db.php +++ b/lib/public/db.php @@ -39,9 +39,9 @@ class DB { * @param string $query Query string * @param int $limit Limit of the SQL statement * @param int $offset Offset of the SQL statement - * @return \MDB2_Statement_Common prepared SQL query + * @return \Doctrine\DBAL\Statement prepared SQL query * - * SQL query via MDB2 prepare(), needs to be execute()'d! + * SQL query via Doctrine prepare(), needs to be execute()'d! */ static public function prepare( $query, $limit=null, $offset=null ) { return(\OC_DB::prepare($query, $limit, $offset)); @@ -73,7 +73,7 @@ class DB { * @param $table string The optional table name (will replace *PREFIX*) and add sequence suffix * @return int * - * MDB2 lastInsertID() + * \Doctrine\DBAL\Connection lastInsertID() * * Call this method right after the insert command or other functions may * cause trouble! @@ -86,18 +86,18 @@ class DB { * Start a transaction */ public static function beginTransaction() { - return(\OC_DB::beginTransaction()); + \OC_DB::beginTransaction(); } /** * Commit the database changes done during a transaction that is in progress */ public static function commit() { - return(\OC_DB::commit()); + \OC_DB::commit(); } /** - * Check if a result is an error, works with MDB2 and PDOException + * Check if a result is an error, works with Doctrine * @param mixed $result * @return bool */ diff --git a/lib/public/iconfig.php b/lib/public/iconfig.php index da6b6c54843..1d0f8e0015c 100644 --- a/lib/public/iconfig.php +++ b/lib/public/iconfig.php @@ -36,6 +36,7 @@ namespace OCP; interface IConfig { /** * Sets a new system wide value + * * @param string $key the key of the value, under which will be saved * @param string $value the value that should be stored * @todo need a use case for this @@ -44,14 +45,17 @@ interface IConfig { /** * Looks up a system wide defined value + * * @param string $key the key of the value, under which it was saved + * @param string $default the default value to be returned if the value isn't set * @return string the saved value */ - public function getSystemValue($key); + public function getSystemValue($key, $default = ''); /** * Writes a new app wide value + * * @param string $appName the appName that we want to store the value under * @param string $key the key of the value, under which will be saved * @param string $value the value that should be stored @@ -60,15 +64,18 @@ interface IConfig { /** * Looks up an app wide defined value + * * @param string $appName the appName that we stored the value under * @param string $key the key of the value, under which it was saved + * @param string $default the default value to be returned if the value isn't set * @return string the saved value */ - public function getAppValue($appName, $key); + public function getAppValue($appName, $key, $default = ''); /** * Set a user defined value + * * @param string $userId the userId of the user that we want to store the value under * @param string $appName the appName that we want to store the value under * @param string $key the key under which the value is being stored @@ -78,9 +85,11 @@ interface IConfig { /** * Shortcut for getting a user defined value + * * @param string $userId the userId of the user that we want to store the value under * @param string $appName the appName that we stored the value under * @param string $key the key under which the value is being stored + * @param string $default the default value to be returned if the value isn't set */ - public function getUserValue($userId, $appName, $key); + public function getUserValue($userId, $appName, $key, $default = ''); } diff --git a/lib/public/json.php b/lib/public/json.php index 134f724b0e6..cd5d233ef90 100644 --- a/lib/public/json.php +++ b/lib/public/json.php @@ -167,6 +167,22 @@ class JSON { * @return string json formatted string if not admin user. */ public static function checkAdminUser() { - return(\OC_JSON::checkAdminUser()); + \OC_JSON::checkAdminUser(); + } + + /** + * Encode JSON + * @param array $data + */ + public static function encode($data) { + return(\OC_JSON::encode($data)); + } + + /** + * Check is a given user exists - send json error msg if not + * @param string $user + */ + public static function checkUserExists($user) { + \OC_JSON::checkUserExists($user); } } diff --git a/lib/public/response.php b/lib/public/response.php index 2ca0a0c9fa4..24d3c81d628 100644 --- a/lib/public/response.php +++ b/lib/public/response.php @@ -55,6 +55,15 @@ class Response { } /** + * Sets the content disposition header (with possible workarounds) + * @param string $filename file name + * @param string $type disposition type, either 'attachment' or 'inline' + */ + static public function setContentDispositionHeader( $filename, $type = 'attachment' ) { + \OC_Response::setContentDispositionHeader( $filename, $type ); + } + + /** * Disable browser caching * @see enableCaching with cache_time = 0 */ diff --git a/lib/public/share.php b/lib/public/share.php index 6b3397c85c6..f832d04a70f 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -347,20 +347,29 @@ class Share { } /** - * Get the item shared by a token - * @param string token - * @return Item + * Based on the given token the share information will be returned - password protected shares will be verified + * @param string $token + * @return array | bool false will be returned in case the token is unknown or unauthorized */ - public static function getShareByToken($token) { + public static function getShareByToken($token, $checkPasswordProtection = true) { $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share` WHERE `token` = ?', 1); $result = $query->execute(array($token)); if (\OC_DB::isError($result)) { \OC_Log::write('OCP\Share', \OC_DB::getErrorMessage($result) . ', token=' . $token, \OC_Log::ERROR); } $row = $result->fetchRow(); + if ($row === false) { + return false; + } if (is_array($row) and self::expireItem($row)) { return false; } + + // password protected shares need to be authenticated + if ($checkPasswordProtection && !\OCP\Share::checkPasswordProtectedShare($row)) { + return false; + } + return $row; } @@ -655,7 +664,15 @@ class Share { * @return Returns true on success or false on failure */ public static function unshareAll($itemType, $itemSource) { - if ($shares = self::getItemShared($itemType, $itemSource)) { + // Get all of the owners of shares of this item. + $query = \OC_DB::prepare( 'SELECT `uid_owner` from `*PREFIX*share` WHERE `item_type`=? AND `item_source`=?' ); + $result = $query->execute(array($itemType, $itemSource)); + $shares = array(); + // Add each owner's shares to the array of all shares for this item. + while ($row = $result->fetchRow()) { + $shares = array_merge($shares, self::getItems($itemType, $itemSource, null, null, $row['uid_owner'])); + } + if (!empty($shares)) { // Pass all the vars we have for now, they may be useful $hookParams = array( 'itemType' => $itemType, @@ -850,9 +867,8 @@ class Share { protected static function expireItem(array $item) { if (!empty($item['expiration'])) { $now = new \DateTime(); - $expirationDate = \Doctrine\DBAL\Types\Type::getType('datetime') - ->convertToPhpValue($item['expiration'], \OC_DB::getConnection()->getDatabasePlatform()); - if ($now > $expirationDate) { + $expires = new \DateTime($item['expiration']); + if ($now > $expires) { self::unshareItem($item); return true; } @@ -1881,6 +1897,34 @@ class Share { } } + /** + * In case a password protected link is not yet authenticated this function will return false + * + * @param array $linkItem + * @return bool + */ + public static function checkPasswordProtectedShare(array $linkItem) { + if (!isset($linkItem['share_with'])) { + return true; + } + if (!isset($linkItem['share_type'])) { + return true; + } + if (!isset($linkItem['id'])) { + return true; + } + + if ($linkItem['share_type'] != \OCP\Share::SHARE_TYPE_LINK) { + return true; + } + + if ( \OC::$session->exists('public_link_authenticated') + && \OC::$session->get('public_link_authenticated') === $linkItem['id'] ) { + return true; + } + + return false; + } } /** diff --git a/lib/public/util.php b/lib/public/util.php index cf7ac63ba51..d8497e29cfc 100644 --- a/lib/public/util.php +++ b/lib/public/util.php @@ -88,14 +88,18 @@ class Util { * @param Exception $ex exception to log */ public static function logException( $app, \Exception $ex ) { - $message = $ex->getMessage(); + $class = get_class($ex); + if ($class !== 'Exception') { + $message = $class . ': '; + } + $message .= $ex->getMessage(); if ($ex->getCode()) { $message .= ' [' . $ex->getCode() . ']'; } \OCP\Util::writeLog($app, 'Exception: ' . $message, \OCP\Util::FATAL); if (defined('DEBUG') and DEBUG) { // also log stack trace - $stack = explode('#', $ex->getTraceAsString()); + $stack = explode("\n", $ex->getTraceAsString()); // first element is empty array_shift($stack); foreach ($stack as $s) { @@ -103,9 +107,8 @@ class Util { } // include cause - $l = \OC_L10N::get('lib'); while (method_exists($ex, 'getPrevious') && $ex = $ex->getPrevious()) { - $message .= ' - '.$l->t('Caused by:').' '; + $message .= ' - Caused by:' . ' '; $message .= $ex->getMessage(); if ($ex->getCode()) { $message .= '[' . $ex->getCode() . '] '; @@ -255,8 +258,13 @@ class Util { * Example: when given lostpassword-noreply as $user_part param, * and is currently accessed via http(s)://example.com/, * it would return 'lostpassword-noreply@example.com' + * + * If the configuration value 'mail_from_address' is set in + * config.php, this value will override the $user_part that + * is passed to this function */ public static function getDefaultEmailAddress($user_part) { + $user_part = \OC_Config::getValue('mail_from_address', $user_part); $host_name = self::getServerHostName(); $host_name = \OC_Config::getValue('mail_domain', $host_name); $defaultEmailAddress = $user_part.'@'.$host_name; |