diff options
author | Michael Gapczynski <mtgap@owncloud.com> | 2013-02-25 17:56:40 -0500 |
---|---|---|
committer | Michael Gapczynski <mtgap@owncloud.com> | 2013-02-25 17:56:40 -0500 |
commit | 4a05e8820f5ff376c7e6076aee0b2c2e2c9cc94c (patch) | |
tree | 8486ff4dbafd1c6e892695b37e7346057759a413 /lib | |
parent | 05a8766cbc5826a89e52248994e3e2d0b6c57be5 (diff) | |
parent | d713948d3f85a6e0a369bf1a9052ce563250e3da (diff) | |
download | nextcloud-server-4a05e8820f5ff376c7e6076aee0b2c2e2c9cc94c.tar.gz nextcloud-server-4a05e8820f5ff376c7e6076aee0b2c2e2c9cc94c.zip |
Merge branch 'master' into external_storage_ui_feedback
Diffstat (limited to 'lib')
32 files changed, 706 insertions, 219 deletions
diff --git a/lib/app.php b/lib/app.php index e653c30b2d9..2eb43a582e2 100644 --- a/lib/app.php +++ b/lib/app.php @@ -223,7 +223,7 @@ class OC_App{ // check if the app is compatible with this version of ownCloud $info=OC_App::getAppInfo($app); $version=OC_Util::getVersion(); - if(!isset($info['require']) or ($version[0]>$info['require'])) { + if(!isset($info['require']) or !self::isAppVersionCompatible($version, $info['require'])) { OC_Log::write('core', 'App "'.$info['name'].'" can\'t be installed because it is' .' not compatible with this version of ownCloud', @@ -851,7 +851,7 @@ class OC_App{ foreach($apps as $app) { // check if the app is compatible with this version of ownCloud $info = OC_App::getAppInfo($app); - if(!isset($info['require']) or (($version[0].'.'.$version[1])>$info['require'])) { + if(!isset($info['require']) or !self::isAppVersionCompatible($version, $info['require'])) { OC_Log::write('core', 'App "'.$info['name'].'" ('.$app.') can\'t be used because it is' .' not compatible with this version of ownCloud', @@ -862,6 +862,36 @@ class OC_App{ } } + + /** + * Compares the app version with the owncloud version to see if the app + * requires a newer version than the currently active one + * @param array $owncloudVersions array with 3 entries: major minor bugfix + * @param string $appRequired the required version from the xml + * major.minor.bugfix + * @return boolean true if compatible, otherwise false + */ + public static function isAppVersionCompatible($owncloudVersions, $appRequired){ + $appVersions = explode('.', $appRequired); + + for($i=0; $i<count($appVersions); $i++){ + $appVersion = (int) $appVersions[$i]; + + if(isset($owncloudVersions[$i])){ + $owncloudVersion = $owncloudVersions[$i]; + } else { + $owncloudVersion = 0; + } + + if($owncloudVersion < $appVersion){ + return false; + } + } + + return true; + } + + /** * get the installed version of all apps */ diff --git a/lib/base.php b/lib/base.php index b5439c00abf..f9bb1bb11bf 100644 --- a/lib/base.php +++ b/lib/base.php @@ -320,8 +320,21 @@ class OC { // set the session name to the instance id - which is unique session_name(OC_Util::getInstanceId()); - // (re)-initialize session - session_start(); + // if session cant be started break with http 500 error + if (session_start() === false){ + OC_Log::write('core', 'Session could not be initialized', + OC_Log::ERROR); + + header('HTTP/1.1 500 Internal Server Error'); + $error = 'Session could not be initialized. Please contact your '; + $error .= 'system administrator'; + + $tmpl = new OC_Template('', 'error', 'guest'); + $tmpl->assign('errors', array(1 => array('error' => $error))); + $tmpl->printPage(); + + exit(); + } // regenerate session id periodically to avoid session fixation if (!isset($_SESSION['SID_CREATED'])) { diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php index a9aa891d409..953692f80a9 100644 --- a/lib/connector/sabre/directory.php +++ b/lib/connector/sabre/directory.php @@ -62,12 +62,12 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa } } else { $newPath = $this->path . '/' . $name; - + // mark file as partial while uploading (ignored by the scanner) $partpath = $newPath . '.part'; - + \OC\Files\Filesystem::file_put_contents($partpath, $data); - + //detect aborted upload if (isset ($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT' ) { if (isset($_SERVER['CONTENT_LENGTH'])) { @@ -80,10 +80,10 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa } } } - + // rename to correct path \OC\Files\Filesystem::rename($partpath, $newPath); - + // allow sync clients to send the mtime along in a header $mtime = OC_Request::hasModificationTime(); if ($mtime !== false) { @@ -91,7 +91,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa header('X-OC-MTime: accepted'); } } - + return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath); } diff --git a/lib/connector/sabre/file.php b/lib/connector/sabre/file.php index c4c27e92251..91646312e90 100644 --- a/lib/connector/sabre/file.php +++ b/lib/connector/sabre/file.php @@ -47,9 +47,9 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D // mark file as partial while uploading (ignored by the scanner) $partpath = $this->path . '.part'; - + \OC\Files\Filesystem::file_put_contents($partpath, $data); - + //detect aborted upload if (isset ($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT' ) { if (isset($_SERVER['CONTENT_LENGTH'])) { @@ -62,10 +62,10 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D } } } - + // rename to correct path \OC\Files\Filesystem::rename($partpath, $this->path); - + //allow sync clients to send the mtime along in a header $mtime = OC_Request::hasModificationTime(); if ($mtime !== false) { diff --git a/lib/connector/sabre/quotaplugin.php b/lib/connector/sabre/quotaplugin.php index ce9a968eb3c..c80a33d04b1 100644 --- a/lib/connector/sabre/quotaplugin.php +++ b/lib/connector/sabre/quotaplugin.php @@ -50,7 +50,8 @@ class OC_Connector_Sabre_QuotaPlugin extends Sabre_DAV_ServerPlugin { $uri='/'.$uri; } list($parentUri, $newName) = Sabre_DAV_URLUtil::splitPath($uri); - if ($length > \OC\Files\Filesystem::free_space($parentUri)) { + $freeSpace = \OC\Files\Filesystem::free_space($parentUri); + if ($freeSpace !== \OC\Files\FREE_SPACE_UNKNOWN && $length > $freeSpace) { throw new Sabre_DAV_Exception_InsufficientStorage(); } } diff --git a/lib/db.php b/lib/db.php index edbc2fe13ed..fb2c027cdb9 100644 --- a/lib/db.php +++ b/lib/db.php @@ -178,6 +178,13 @@ class OC_DB { $dsn = 'oci:dbname=//' . $host . '/' . $name; } break; + case 'mssql': + if ($port) { + $dsn='sqlsrv:Server='.$host.','.$port.';Database='.$name; + } else { + $dsn='sqlsrv:Server='.$host.';Database='.$name; + } + break; default: return false; } @@ -278,6 +285,15 @@ class OC_DB { $dsn['database'] = $user; } break; + case 'mssql': + $dsn = array( + 'phptype' => 'sqlsrv', + 'username' => $user, + 'password' => $pass, + 'hostspec' => $host, + 'database' => $name + ); + break; default: return false; } @@ -389,6 +405,13 @@ class OC_DB { $query = self::prepare('SELECT lastval() AS id'); $row = $query->execute()->fetchRow(); return $row['id']; + } + if( $type == 'mssql' ) { + if($table !== null) { + $prefix = OC_Config::getValue( "dbtableprefix", "oc_" ); + $table = str_replace( '*PREFIX*', $prefix, $table ); + } + return self::$connection->lastInsertId($table); }else{ if($table !== null) { $prefix = OC_Config::getValue( "dbtableprefix", "oc_" ); @@ -631,7 +654,7 @@ class OC_DB { } else { return true; } - } elseif( $type == 'pgsql' || $type == 'oci' || $type == 'mysql') { + } elseif( $type == 'pgsql' || $type == 'oci' || $type == 'mysql' || $type == 'mssql') { $query = 'INSERT INTO `' .$table . '` (' . implode(',', array_keys($input)) . ') SELECT \'' . implode('\',\'', array_values($input)) . '\' FROM ' . $table . ' WHERE '; @@ -691,7 +714,15 @@ class OC_DB { }elseif( $type == 'oci' ) { $query = str_replace( '`', '"', $query ); $query = str_ireplace( 'NOW()', 'CURRENT_TIMESTAMP', $query ); - } + }elseif( $type == 'mssql' ) { + $query = preg_replace( "/\`(.*?)`/", "[$1]", $query ); + $query = str_replace( 'NOW()', 'CURRENT_TIMESTAMP', $query ); + $query = str_replace( 'now()', 'CURRENT_TIMESTAMP', $query ); + $query = str_replace( 'LENGTH(', 'LEN(', $query ); + $query = str_replace( 'SUBSTR(', 'SUBSTRING(', $query ); + + $query = self::fixLimitClauseForMSSQL($query); + } // replace table name prefix $query = str_replace( '*PREFIX*', $prefix, $query ); @@ -699,6 +730,60 @@ class OC_DB { return $query; } + private static function fixLimitClauseForMSSQL($query) { + $limitLocation = stripos ($query, "LIMIT"); + + if ( $limitLocation === false ) { + return $query; + } + + // total == 0 means all results - not zero results + // + // First number is either total or offset, locate it by first space + // + $offset = substr ($query, $limitLocation + 5); + $offset = substr ($offset, 0, stripos ($offset, ' ')); + $offset = trim ($offset); + + // check for another parameter + if (stripos ($offset, ',') === false) { + // no more parameters + $offset = 0; + $total = intval ($offset); + } else { + // found another parameter + $offset = intval ($offset); + + $total = substr ($query, $limitLocation + 5); + $total = substr ($total, stripos ($total, ',')); + + $total = substr ($total, 0, stripos ($total, ' ')); + $total = intval ($total); + } + + $query = trim (substr ($query, 0, $limitLocation)); + + if ($offset == 0 && $total !== 0) { + if (strpos($query, "SELECT") === false) { + $query = "TOP {$total} " . $query; + } else { + $query = preg_replace('/SELECT(\s*DISTINCT)?/Dsi', 'SELECT$1 TOP '.$total, $query); + } + } else if ($offset > 0) { + $query = preg_replace('/SELECT(\s*DISTINCT)?/Dsi', 'SELECT$1 TOP(10000000) ', $query); + $query = 'SELECT * + FROM (SELECT sub2.*, ROW_NUMBER() OVER(ORDER BY sub2.line2) AS line3 + FROM (SELECT 1 AS line2, sub1.* FROM (' . $query . ') AS sub1) as sub2) AS sub3'; + + if ($total > 0) { + $query .= ' WHERE line3 BETWEEN ' . ($offset + 1) . ' AND ' . ($offset + $total); + } else { + $query .= ' WHERE line3 > ' . $offset; + } + } + return $query; + } + /** * @brief drop a table * @param string $tableName the table to drop @@ -850,19 +935,119 @@ class PDOStatementWrapper{ * make execute return the result instead of a bool */ public function execute($input=array()) { - $this->lastArguments=$input; - if(count($input)>0) { + $this->lastArguments = $input; + if (count($input) > 0) { + + if (!isset($type)) { + $type = OC_Config::getValue( "dbtype", "sqlite" ); + } + + if ($type == 'mssql') { + $input = $this->tryFixSubstringLastArgumentDataForMSSQL($input); + } + $result=$this->statement->execute($input); - }else{ + } else { $result=$this->statement->execute(); } - if($result) { + + if ($result) { return $this; - }else{ + } else { return false; } } + private function tryFixSubstringLastArgumentDataForMSSQL($input) { + $query = $this->statement->queryString; + $pos = stripos ($query, 'SUBSTRING'); + + if ( $pos === false) { + return; + } + + try { + $newQuery = ''; + + $cArg = 0; + + $inSubstring = false; + + // Create new query + for ($i = 0; $i < strlen ($query); $i++) { + if ($inSubstring == false) { + // Defines when we should start inserting values + if (substr ($query, $i, 9) == 'SUBSTRING') { + $inSubstring = true; + } + } else { + // Defines when we should stop inserting values + if (substr ($query, $i, 1) == ')') { + $inSubstring = false; + } + } + + if (substr ($query, $i, 1) == '?') { + // We found a question mark + if ($inSubstring) { + $newQuery .= $input[$cArg]; + + // + // Remove from input array + // + array_splice ($input, $cArg, 1); + } else { + $newQuery .= substr ($query, $i, 1); + $cArg++; + } + } else { + $newQuery .= substr ($query, $i, 1); + } + } + + // The global data we need + $name = OC_Config::getValue( "dbname", "owncloud" ); + $host = OC_Config::getValue( "dbhost", "" ); + $user = OC_Config::getValue( "dbuser", "" ); + $pass = OC_Config::getValue( "dbpassword", "" ); + if (strpos($host,':')) { + list($host, $port) = explode(':', $host, 2); + } else { + $port = false; + } + $opts = array(); + + if ($port) { + $dsn = 'sqlsrv:Server='.$host.','.$port.';Database='.$name; + } else { + $dsn = 'sqlsrv:Server='.$host.';Database='.$name; + } + + $PDO = new PDO($dsn, $user, $pass, $opts); + $PDO->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); + $PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + $this->statement = $PDO->prepare($newQuery); + + $this->lastArguments = $input; + + return $input; + } catch (PDOException $e){ + $entry = 'PDO DB Error: "'.$e->getMessage().'"<br />'; + $entry .= 'Offending command was: '.$this->statement->queryString .'<br />'; + $entry .= 'Input parameters: ' .print_r($input, true).'<br />'; + $entry .= 'Stack trace: ' .$e->getTraceAsString().'<br />'; + OC_Log::write('core', $entry, OC_Log::FATAL); + OC_User::setUserId(null); + + // send http status 503 + header('HTTP/1.1 503 Service Temporarily Unavailable'); + header('Status: 503 Service Temporarily Unavailable'); + OC_Template::printErrorPage('Failed to connect to database'); + die ($entry); + } + } + /** * provide numRows */ diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php index 3652dc7cf23..01e6e788263 100644 --- a/lib/files/cache/cache.php +++ b/lib/files/cache/cache.php @@ -500,8 +500,8 @@ class Cache { public function getIncomplete() { $query = \OC_DB::prepare('SELECT `path` FROM `*PREFIX*filecache`' . ' WHERE `storage` = ? AND `size` = -1 ORDER BY `fileid` DESC LIMIT 1'); - $query->execute(array($this->numericId)); - if ($row = $query->fetchRow()) { + $result = $query->execute(array($this->numericId)); + if ($row = $result->fetchRow()) { return $row['path']; } else { return false; diff --git a/lib/files/cache/legacy.php b/lib/files/cache/legacy.php index 6d1ffa7b40b..2b8689fcbda 100644 --- a/lib/files/cache/legacy.php +++ b/lib/files/cache/legacy.php @@ -51,12 +51,12 @@ class Legacy { $this->cacheHasItems = false; return false; } - + if ($result === false || property_exists($result, 'error_message_prefix')) { $this->cacheHasItems = false; return false; - } - + } + $this->cacheHasItems = (bool)$result->fetchRow(); return $this->cacheHasItems; } diff --git a/lib/files/filesystem.php b/lib/files/filesystem.php index 875a9d6c5ee..0bbd7550d74 100644 --- a/lib/files/filesystem.php +++ b/lib/files/filesystem.php @@ -219,11 +219,14 @@ class Filesystem { } $parser = new \OC\ArrayParser(); + $root = \OC_User::getHome($user); + self::mount('\OC\Files\Storage\Local', array('datadir' => $root), $user); + // Load system mount points if (is_file(\OC::$SERVERROOT . '/config/mount.php') or is_file(\OC::$SERVERROOT . '/config/mount.json')) { - if(is_file(\OC::$SERVERROOT . '/config/mount.json')){ + if (is_file(\OC::$SERVERROOT . '/config/mount.json')) { $mountConfig = json_decode(file_get_contents(\OC::$SERVERROOT . '/config/mount.json'), true); - }elseif(is_file(\OC::$SERVERROOT . '/config/mount.php')){ + } elseif (is_file(\OC::$SERVERROOT . '/config/mount.php')) { $mountConfig = $parser->parsePHP(file_get_contents(\OC::$SERVERROOT . '/config/mount.php')); } if (isset($mountConfig['global'])) { @@ -259,12 +262,10 @@ class Filesystem { } } // Load personal mount points - $root = \OC_User::getHome($user); - self::mount('\OC\Files\Storage\Local', array('datadir' => $root), $user); if (is_file($root . '/mount.php') or is_file($root . '/mount.json')) { - if (is_file($root . '/mount.json')){ + if (is_file($root . '/mount.json')) { $mountConfig = json_decode(file_get_contents($root . '/mount.json'), true); - } elseif (is_file($root . '/mount.php')){ + } elseif (is_file($root . '/mount.php')) { $mountConfig = $parser->parsePHP(file_get_contents($root . '/mount.php')); } if (isset($mountConfig['user'][$user])) { @@ -389,21 +390,29 @@ class Filesystem { * @param array $data from hook */ static public function isBlacklisted($data) { - $blacklist = \OC_Config::getValue('blacklisted_files', array('.htaccess')); if (isset($data['path'])) { $path = $data['path']; } else if (isset($data['newpath'])) { $path = $data['newpath']; } if (isset($path)) { - $filename = strtolower(basename($path)); - if (in_array($filename, $blacklist)) { + if (self::isFileBlacklisted($path)) { $data['run'] = false; } } } /** + * @param string $filename + * @return bool + */ + static public function isFileBlacklisted($filename) { + $blacklist = \OC_Config::getValue('blacklisted_files', array('.htaccess')); + $filename = strtolower(basename($filename)); + return (in_array($filename, $blacklist)); + } + + /** * following functions are equivalent to their php builtin equivalents for arguments/return values. */ static public function mkdir($path) { diff --git a/lib/files/storage/common.php b/lib/files/storage/common.php index f23dcf0d4eb..488a3f357c3 100644 --- a/lib/files/storage/common.php +++ b/lib/files/storage/common.php @@ -97,8 +97,8 @@ abstract class Common implements \OC\Files\Storage\Storage { public function copy($path1, $path2) { $source=$this->fopen($path1, 'r'); $target=$this->fopen($path2, 'w'); - $count=\OC_Helper::streamCopy($source, $target); - return $count>0; + list($count, $result) = \OC_Helper::streamCopy($source, $target); + return $result; } /** @@ -278,7 +278,7 @@ abstract class Common implements \OC\Files\Storage\Storage { return uniqid(); } } - + /** * clean a path, i.e. remove all redundant '.' and '..' * making sure that it can't point to higher than '/' @@ -289,7 +289,7 @@ abstract class Common implements \OC\Files\Storage\Storage { if (strlen($path) == 0 or $path[0] != '/') { $path = '/' . $path; } - + $output = array(); foreach (explode('/', $path) as $chunk) { if ($chunk == '..') { diff --git a/lib/files/view.php b/lib/files/view.php index 9ac08c98082..f48d0c8b225 100644 --- a/lib/files/view.php +++ b/lib/files/view.php @@ -285,7 +285,7 @@ class View { } $target = $this->fopen($path, 'w'); if ($target) { - $count = \OC_Helper::streamCopy($data, $target); + list ($count, $result) = \OC_Helper::streamCopy($data, $target); fclose($target); fclose($data); if ($this->fakeRoot == Filesystem::getRoot()) { @@ -303,7 +303,7 @@ class View { ); } \OC_FileProxy::runPostProxies('file_put_contents', $absolutePath, $count); - return $count > 0; + return $result; } else { return false; } @@ -361,10 +361,9 @@ class View { } else { $source = $this->fopen($path1 . $postFix1, 'r'); $target = $this->fopen($path2 . $postFix2, 'w'); - $count = \OC_Helper::streamCopy($source, $target); + list($count, $result) = \OC_Helper::streamCopy($source, $target); list($storage1, $internalPath1) = Filesystem::resolvePath($absolutePath1 . $postFix1); $storage1->unlink($internalPath1); - $result = $count > 0; } if ($this->fakeRoot == Filesystem::getRoot()) { \OC_Hook::emit( @@ -444,7 +443,7 @@ class View { } else { $source = $this->fopen($path1 . $postFix1, 'r'); $target = $this->fopen($path2 . $postFix2, 'w'); - $result = \OC_Helper::streamCopy($source, $target); + list($count, $result) = \OC_Helper::streamCopy($source, $target); } if ($this->fakeRoot == Filesystem::getRoot()) { \OC_Hook::emit( diff --git a/lib/group.php b/lib/group.php index 6afe1440030..88f0a2a032c 100644 --- a/lib/group.php +++ b/lib/group.php @@ -286,38 +286,39 @@ class OC_Group { } return $users; } - - /**
- * @brief get a list of all display names in a group
- * @returns array with display names (value) and user ids(key)
- */
- public static function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) {
- $displayNames=array();
- foreach(self::$_usedBackends as $backend) {
- $displayNames = array_merge($backend->displayNamesInGroup($gid, $search, $limit, $offset), $displayNames);
- }
- return $displayNames;
+ + /** + * @brief get a list of all display names in a group + * @returns array with display names (value) and user ids(key) + */ + public static function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) { + $displayNames=array(); + foreach(self::$_usedBackends as $backend) { + $displayNames = array_merge($backend->displayNamesInGroup($gid, $search, $limit, $offset), $displayNames); + } + return $displayNames; } - - /**
- * @brief get a list of all display names in several groups
- * @param array $gids
- * @param string $search
- * @param int $limit
- * @param int $offset
- * @return array with display names (Key) user ids (value)
- */
- public static function displayNamesInGroups($gids, $search = '', $limit = -1, $offset = 0) {
- $displayNames = array();
- foreach ($gids as $gid) {
- // TODO Need to apply limits to groups as total
- $displayNames = array_merge( - array_diff( - self::displayNamesInGroup($gid, $search, $limit, $offset), - $displayNames - ), - $displayNames); - }
- return $displayNames;
+ + /** + * @brief get a list of all display names in several groups + * @param array $gids + * @param string $search + * @param int $limit + * @param int $offset + * @return array with display names (Key) user ids (value) + */ + public static function displayNamesInGroups($gids, $search = '', $limit = -1, $offset = 0) { + $displayNames = array(); + foreach ($gids as $gid) { + // TODO Need to apply limits to groups as total + $diff = array_diff( + self::displayNamesInGroup($gid, $search, $limit, $offset), + $displayNames + ); + if ($diff) { + $displayNames = array_merge($diff, $displayNames); + } + } + return $displayNames; } } diff --git a/lib/group/backend.php b/lib/group/backend.php index 4f6570c3be3..e7b7b21d957 100644 --- a/lib/group/backend.php +++ b/lib/group/backend.php @@ -133,23 +133,23 @@ abstract class OC_Group_Backend implements OC_Group_Interface { public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { return array(); } - - /**
- * @brief get a list of all display names in a group
- * @param string $gid
- * @param string $search
- * @param int $limit
- * @param int $offset
- * @return array with display names (value) and user ids (key)
- */
- public function DisplayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) {
- $displayNames = '';
- $users = $this->usersInGroup($gid, $search, $limit, $offset);
- foreach ( $users as $user ) {
- $DisplayNames[$user] = $user;
- }
-
- return $DisplayNames;
+ + /** + * @brief get a list of all display names in a group + * @param string $gid + * @param string $search + * @param int $limit + * @param int $offset + * @return array with display names (value) and user ids (key) + */ + public function DisplayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) { + $displayNames = ''; + $users = $this->usersInGroup($gid, $search, $limit, $offset); + foreach ( $users as $user ) { + $DisplayNames[$user] = $user; + } + + return $DisplayNames; } } diff --git a/lib/group/database.php b/lib/group/database.php index 8816dd8169c..40e9b0d4147 100644 --- a/lib/group/database.php +++ b/lib/group/database.php @@ -210,30 +210,30 @@ class OC_Group_Database extends OC_Group_Backend { } return $users; } - - /**
- * @brief get a list of all display names in a group
- * @param string $gid
- * @param string $search
- * @param int $limit
- * @param int $offset
- * @return array with display names (value) and user ids (key)
- */
- public function DisplayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) {
+ + /** + * @brief get a list of all display names in a group + * @param string $gid + * @param string $search + * @param int $limit + * @param int $offset + * @return array with display names (value) and user ids (key) + */ + public function DisplayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) { $displayNames = ''; $stmt = OC_DB::prepare('SELECT `*PREFIX*users`.`uid`, `*PREFIX*users`.`displayname`' .' FROM `*PREFIX*users`' .' INNER JOIN `*PREFIX*group_user` ON `*PREFIX*group_user`.`uid` = `*PREFIX*users`.`uid`' - .' WHERE `gid` = ? AND `*PREFIX*group_user.uid` LIKE ?', + .' WHERE `gid` = ? AND `*PREFIX*group_user`.`uid` LIKE ?', $limit, $offset); - $result = $stmt->execute(array($gid, $search.'%'));
- $users = array();
+ $result = $stmt->execute(array($gid, $search.'%')); + $users = array(); while ($row = $result->fetchRow()) { - $displayName = trim($row['displayname'], ' ');
- $displayNames[$row['uid']] = empty($displayName) ? $row['uid'] : $displayName;
- }
- return $displayNames;
+ $displayName = trim($row['displayname'], ' '); + $displayNames[$row['uid']] = empty($displayName) ? $row['uid'] : $displayName; + } + return $displayNames; } } diff --git a/lib/helper.php b/lib/helper.php index add5c66e7be..41985ca57a7 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -513,11 +513,16 @@ class OC_Helper { if(!$source or !$target) { return false; } - $count=0; + $result = true; + $count = 0; while(!feof($source)) { - $count+=fwrite($target, fread($source, 8192)); + if ( ( $c = fwrite($target, fread($source, 8192)) ) === false) { + $result = false; + } else { + $count += $c; + } } - return $count; + return array($count, $result); } /** diff --git a/lib/hook.php b/lib/hook.php index 554381251d6..8516cf0dcff 100644 --- a/lib/hook.php +++ b/lib/hook.php @@ -20,23 +20,23 @@ class OC_Hook{ * TODO: write example */ static public function connect( $signalclass, $signalname, $slotclass, $slotname ) { - // If we're trying to connect to an emitting class that isn't + // If we're trying to connect to an emitting class that isn't // yet registered, register it if( !array_key_exists( $signalclass, self::$registered )) { self::$registered[$signalclass] = array(); } - // If we're trying to connect to an emitting method that isn't + // If we're trying to connect to an emitting method that isn't // yet registered, register it with the emitting class - if( !array_key_exists( $signalname, self::$registered[$signalclass] )) { + if( !array_key_exists( $signalname, self::$registered[$signalclass] )) { self::$registered[$signalclass][$signalname] = array(); } - + // Connect the hook handler to the requested emitter self::$registered[$signalclass][$signalname][] = array( "class" => $slotclass, "name" => $slotname ); - + // No chance for failure ;-) return true; } @@ -53,19 +53,19 @@ class OC_Hook{ * TODO: write example */ static public function emit( $signalclass, $signalname, $params = array()) { - + // Return false if no hook handlers are listening to this // emitting class if( !array_key_exists( $signalclass, self::$registered )) { return false; } - + // Return false if no hook handlers are listening to this // emitting method if( !array_key_exists( $signalname, self::$registered[$signalclass] )) { return false; } - + // Call all slots foreach( self::$registered[$signalclass][$signalname] as $i ) { try { diff --git a/lib/image.php b/lib/image.php index 7b0cbefd657..97b0231047b 100644 --- a/lib/image.php +++ b/lib/image.php @@ -702,6 +702,13 @@ class OC_Image { return false; } + // preserve transparency + if($this->imagetype == IMAGETYPE_GIF or $this->imagetype == IMAGETYPE_PNG) { + imagecolortransparent($process, imagecolorallocatealpha($process, 0, 0, 0, 127)); + imagealphablending($process, false); + imagesavealpha($process, true); + } + imagecopyresampled($process, $this->resource, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); if ($process == false) { OC_Log::write('core', __METHOD__.'(): Error resampling process image '.$width.'x'.$height, OC_Log::ERROR); @@ -751,6 +758,14 @@ class OC_Image { imagedestroy($process); return false; } + + // preserve transparency + if($this->imagetype == IMAGETYPE_GIF or $this->imagetype == IMAGETYPE_PNG) { + imagecolortransparent($process, imagecolorallocatealpha($process, 0, 0, 0, 127)); + imagealphablending($process, false); + imagesavealpha($process, true); + } + imagecopyresampled($process, $this->resource, 0, 0, $x, $y, $targetWidth, $targetHeight, $width, $height); if ($process == false) { OC_Log::write('core', diff --git a/lib/l10n/de.php b/lib/l10n/de.php index 0ad254ad844..87b0b29469c 100644 --- a/lib/l10n/de.php +++ b/lib/l10n/de.php @@ -9,7 +9,7 @@ "Files need to be downloaded one by one." => "Die Dateien müssen einzeln heruntergeladen werden.", "Back to Files" => "Zurück zu \"Dateien\"", "Selected files too large to generate zip file." => "Die gewählten Dateien sind zu groß, um eine ZIP-Datei zu erstellen.", -"couldn't be determined" => "Konnte nicht festgestellt werden", +"couldn't be determined" => "konnte nicht festgestellt werden", "Application is not enabled" => "Die Anwendung ist nicht aktiviert", "Authentication error" => "Authentifizierungs-Fehler", "Token expired. Please reload page." => "Token abgelaufen. Bitte lade die Seite neu.", @@ -18,7 +18,7 @@ "Images" => "Bilder", "Set an admin username." => "Setze Administrator Benutzername.", "Set an admin password." => "Setze Administrator Passwort", -"Specify a data folder." => "Datei-Verzeichnis angeben", +"Specify a data folder." => "Datei-Verzeichnis angeben.", "%s enter the database username." => "%s gib den Datenbank-Benutzernamen an.", "%s enter the database name." => "%s gib den Datenbank-Namen an.", "%s you may not use dots in the database name" => "%s Der Datenbank-Name darf keine Punkte enthalten", @@ -32,7 +32,7 @@ "MySQL user '%s'@'localhost' exists already." => "MySQL Benutzer '%s'@'localhost' existiert bereits.", "Drop this user from MySQL" => "Lösche diesen Benutzer von MySQL", "MySQL user '%s'@'%%' already exists" => "MySQL Benutzer '%s'@'%%' existiert bereits", -"Drop this user from MySQL." => "Lösche diesen Benutzer von MySQL.", +"Drop this user from MySQL." => "Lösche diesen Benutzer aus MySQL.", "Offending command was: \"%s\", name: %s, password: %s" => "Fehlerhafter Befehl war: \"%s\", Name: %s, Passwort: %s", "Your web server is not yet properly setup to allow files synchronization because the WebDAV interface seems to be broken." => "Dein Web-Server ist noch nicht für Datei-Synchronisation bereit, weil die WebDAV-Schnittstelle vermutlich defekt ist.", "Please double check the <a href='%s'>installation guides</a>." => "Bitte prüfe die <a href='%s'>Instalationsanleitungen</a>.", diff --git a/lib/l10n/de_DE.php b/lib/l10n/de_DE.php index 1f63fdd87b0..d04c691f7ec 100644 --- a/lib/l10n/de_DE.php +++ b/lib/l10n/de_DE.php @@ -30,9 +30,9 @@ "DB Error: \"%s\"" => "DB Fehler: \"%s\"", "Offending command was: \"%s\"" => "Fehlerhafter Befehl war: \"%s\"", "MySQL user '%s'@'localhost' exists already." => "MySQL Benutzer '%s'@'localhost' existiert bereits.", -"Drop this user from MySQL" => "Lösche diesen Benutzer von MySQL", +"Drop this user from MySQL" => "Lösche diesen Benutzer aus MySQL", "MySQL user '%s'@'%%' already exists" => "MySQL Benutzer '%s'@'%%' existiert bereits", -"Drop this user from MySQL." => "Lösche diesen Benutzer von MySQL.", +"Drop this user from MySQL." => "Lösche diesen Benutzer aus MySQL.", "Offending command was: \"%s\", name: %s, password: %s" => "Fehlerhafter Befehl war: \"%s\", Name: %s, Passwort: %s", "Your web server is not yet properly setup to allow files synchronization because the WebDAV interface seems to be broken." => "Ihr Web-Server ist noch nicht für Datei-Synchronisation bereit, weil die WebDAV-Schnittstelle vermutlich defekt ist.", "Please double check the <a href='%s'>installation guides</a>." => "Bitte prüfen Sie die <a href='%s'>Instalationsanleitungen</a>.", diff --git a/lib/l10n/my_MM.php b/lib/l10n/my_MM.php new file mode 100644 index 00000000000..d725a06a3a9 --- /dev/null +++ b/lib/l10n/my_MM.php @@ -0,0 +1,31 @@ +<?php $TRANSLATIONS = array( +"Help" => "အကူအညီ", +"Users" => "သုံးစွဲသူ", +"Apps" => "Apps", +"Admin" => "အက်ဒမင်", +"ZIP download is turned off." => "ZIP ဒေါင်းလုတ်ကိုပိတ်ထားသည်", +"Files need to be downloaded one by one." => "ဖိုင်များသည် တစ်ခုပြီး တစ်ခုဒေါင်းလုတ်ချရန်လိုအပ်သည်", +"Back to Files" => "ဖိုင်သို့ပြန်သွားမည်", +"Selected files too large to generate zip file." => "zip ဖိုင်အဖြစ်ပြုလုပ်ရန် ရွေးချယ်ထားသောဖိုင်များသည် အရမ်းကြီးလွန်းသည်", +"couldn't be determined" => "မဆုံးဖြတ်နိုင်ပါ။", +"Authentication error" => "ခွင့်ပြုချက်မအောင်မြင်", +"Files" => "ဖိုင်များ", +"Text" => "စာသား", +"Images" => "ပုံရိပ်များ", +"seconds ago" => "စက္ကန့်အနည်းငယ်က", +"1 minute ago" => "၁ မိနစ်အရင်က", +"%d minutes ago" => "%d မိနစ်အရင်က", +"1 hour ago" => "၁ နာရီ အရင်က", +"%d hours ago" => "%d နာရီအရင်က", +"today" => "ယနေ့", +"yesterday" => "မနေ့က", +"%d days ago" => "%d ရက် အရင်က", +"last month" => "ပြီးခဲ့သောလ", +"%d months ago" => "%d လအရင်က", +"last year" => "မနှစ်က", +"years ago" => "နှစ် အရင်က", +"%s is available. Get <a href=\"%s\">more information</a>" => "%s ကိုရရှိနိုင်ပါပြီ။ <a href=\"%s\">နောက်ထပ်အချက်အလက်များ</a>ရယူပါ။", +"up to date" => "နောက်ဆုံးပေါ်", +"updates check is disabled" => "နောက်ဆုံးပေါ်စစ်ဆေးခြင်းကိုပိတ်ထားသည်", +"Could not find category \"%s\"" => "\"%s\"ခေါင်းစဉ်ကို ရှာမတွေ့ပါ" +); diff --git a/lib/public/files.php b/lib/public/files.php index c2945b200e8..700bf574537 100644 --- a/lib/public/files.php +++ b/lib/public/files.php @@ -62,7 +62,8 @@ class Files { * @return int the number of bytes copied */ public static function streamCopy( $source, $target ) { - return(\OC_Helper::streamCopy( $source, $target )); + list($count, $result) = \OC_Helper::streamCopy( $source, $target ); + return $count; } /** diff --git a/lib/public/share.php b/lib/public/share.php index c0f35333e83..37cf0838ed1 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -384,7 +384,7 @@ class Share { 'itemSource' => $itemSource, 'shareType' => $shareType, 'shareWith' => $shareWith, - )); + )); self::delete($item['id']); return true; } @@ -404,7 +404,7 @@ class Share { 'itemType' => $itemType, 'itemSource' => $itemSource, 'shares' => $shares - )); + )); foreach ($shares as $share) { self::delete($share['id']); } @@ -848,7 +848,7 @@ class Share { if ( isset($row['uid_owner']) && $row['uid_owner'] != '') { $row['displayname_owner'] = \OCP\User::getDisplayName($row['uid_owner']); } - + $items[$row['id']] = $row; } if (!empty($items)) { diff --git a/lib/public/user.php b/lib/public/user.php index 86d1d0ccde8..9edebe0e7cf 100644 --- a/lib/public/user.php +++ b/lib/public/user.php @@ -52,25 +52,25 @@ class User { public static function getUsers($search = '', $limit = null, $offset = null) { return \OC_USER::getUsers(); } - - /**
- * @brief get the user display name of the user currently logged in.
- * @return string display name
- */
- public static function getDisplayName($user=null) {
- return \OC_USER::getDisplayName($user);
+ + /** + * @brief get the user display name of the user currently logged in. + * @return string display name + */ + public static function getDisplayName($user=null) { + return \OC_USER::getDisplayName($user); } - - /**
- * @brief Get a list of all display names
- * @returns array with all display names (value) and the correspondig uids (key)
- *
- * Get a list of all display names and user ids.
- */
- public static function getDisplayNames($search = '', $limit = null, $offset = null) {
- return \OC_USER::getDisplayNames($search, $limit, $offset);
+ + /** + * @brief Get a list of all display names + * @returns array with all display names (value) and the correspondig uids (key) + * + * Get a list of all display names and user ids. + */ + public static function getDisplayNames($search = '', $limit = null, $offset = null) { + return \OC_USER::getDisplayNames($search, $limit, $offset); } - + /** * @brief Check if the user is logged in * @returns true/false diff --git a/lib/request.php b/lib/request.php index 3af93289670..30a25df23ab 100755 --- a/lib/request.php +++ b/lib/request.php @@ -149,7 +149,7 @@ class OC_Request { return 'gzip'; return false; } - + /** * @brief Check if the requester sent along an mtime * @returns false or an mtime diff --git a/lib/search.php b/lib/search.php index e5a65f7157d..b9c75dfc333 100644 --- a/lib/search.php +++ b/lib/search.php @@ -57,14 +57,14 @@ class OC_Search{ } return $results; } - + /** * remove an existing search provider * @param string $provider class name of a OC_Search_Provider */ public static function removeProvider($provider) { self::$registeredProviders = array_filter( - self::$registeredProviders, + self::$registeredProviders, function ($element) use ($provider) { return ($element['class'] != $provider); } diff --git a/lib/setup.php b/lib/setup.php index 0c049841b2a..fd5f3cd5bee 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -40,11 +40,13 @@ class OC_Setup { $error[] = $l->t('Specify a data folder.'); } - if($dbtype=='mysql' or $dbtype == 'pgsql' or $dbtype == 'oci') { //mysql and postgresql needs more config options - if($dbtype=='mysql') + if($dbtype == 'mysql' or $dbtype == 'pgsql' or $dbtype == 'oci' or $dbtype == 'mssql') { //mysql and postgresql needs more config options + if($dbtype == 'mysql') $dbprettyname = 'MySQL'; - else if($dbtype=='pgsql') + else if($dbtype == 'pgsql') $dbprettyname = 'PostgreSQL'; + else if ($dbtype == 'mssql') + $dbprettyname = 'MS SQL Server'; else $dbprettyname = 'Oracle'; @@ -98,7 +100,7 @@ class OC_Setup { $error[] = array( 'error' => $e->getMessage(), 'hint' => $e->getHint() - ); + ); return($error); } catch (Exception $e) { $error[] = array( @@ -152,6 +154,29 @@ class OC_Setup { return $error; } } + elseif ($dbtype == 'mssql') { + $dbuser = $options['dbuser']; + $dbpass = $options['dbpass']; + $dbname = $options['dbname']; + $dbhost = $options['dbhost']; + $dbtableprefix = isset($options['dbtableprefix']) ? $options['dbtableprefix'] : 'oc_'; + + OC_Config::setValue('dbname', $dbname); + OC_Config::setValue('dbhost', $dbhost); + OC_Config::setValue('dbuser', $dbuser); + OC_Config::setValue('dbpassword', $dbpass); + OC_Config::setValue('dbtableprefix', $dbtableprefix); + + try { + self::setupMSSQLDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix); + } catch (Exception $e) { + $error[] = array( + 'error' => 'MS SQL username and/or password not valid', + 'hint' => 'You need to enter either an existing account or the administrator.' + ); + return $error; + } + } else { //delete the old sqlite database first, might cause infinte loops otherwise if(file_exists("$datadir/owncloud.db")) { @@ -174,7 +199,7 @@ class OC_Setup { OC_Appconfig::setValue('core', 'lastupdatedat', microtime(true)); OC_AppConfig::setValue('core', 'remote_core.css', '/core/minimizer.php'); OC_AppConfig::setValue('core', 'remote_core.js', '/core/minimizer.php'); - + OC_Group::createGroup('admin'); OC_Group::addToGroup($username, 'admin'); OC_User::login($username, $password); @@ -256,11 +281,12 @@ class OC_Setup { if(!$result) { $entry = $l->t('DB Error: "%s"', array(mysql_error($connection))) . '<br />'; $entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />'; - echo($entry); + \OC_Log::write('setup.mssql', $entry, \OC_Log::WARN); } $query="GRANT ALL PRIVILEGES ON `$name` . * TO '$user'"; - //this query will fail if there aren't the right permissons, ignore the error - $result = mysql_query($query, $connection); + + //this query will fail if there aren't the right permissions, ignore the error + mysql_query($query, $connection); } private static function createDBUser($name, $password, $connection) { @@ -276,7 +302,7 @@ class OC_Setup { $query = "CREATE USER '$name'@'%' IDENTIFIED BY '$password'"; $result = mysql_query($query, $connection); if (!$result) { - throw new DatabaseSetupException($l->t("MySQL user '%s'@'%%' already exists", array($name)), + throw new DatabaseSetupException($l->t("MySQL user '%s'@'%%' already exists", array($name)), $l->t("Drop this user from MySQL.")); } } @@ -359,7 +385,7 @@ class OC_Setup { if(!$result) { $entry = $l->t('DB Error: "%s"', array(pg_last_error($connection))) . '<br />'; $entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />'; - echo($entry); + \OC_Log::write('setup.pg', $entry, \OC_Log::WARN); } if(! pg_fetch_row($result)) { //The database does not exists... let's create it @@ -368,11 +394,11 @@ class OC_Setup { if(!$result) { $entry = $l->t('DB Error: "%s"', array(pg_last_error($connection))) . '<br />'; $entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />'; - echo($entry); + \OC_Log::write('setup.pg', $entry, \OC_Log::WARN); } else { $query = "REVOKE ALL PRIVILEGES ON DATABASE \"$e_name\" FROM PUBLIC"; - $result = pg_query($connection, $query); + pg_query($connection, $query); } } } @@ -386,7 +412,7 @@ class OC_Setup { if(!$result) { $entry = $l->t('DB Error: "%s"', array(pg_last_error($connection))) . '<br />'; $entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />'; - echo($entry); + \OC_Log::write('setup.pg', $entry, \OC_Log::WARN); } if(! pg_fetch_row($result)) { @@ -396,7 +422,7 @@ class OC_Setup { if(!$result) { $entry = $l->t('DB Error: "%s"', array(pg_last_error($connection))) . '<br />'; $entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />'; - echo($entry); + \OC_Log::write('setup.pg', $entry, \OC_Log::WARN); } } else { // change password of the existing role @@ -405,7 +431,7 @@ class OC_Setup { if(!$result) { $entry = $l->t('DB Error: "%s"', array(pg_last_error($connection))) . '<br />'; $entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />'; - echo($entry); + \OC_Log::write('setup.pg', $entry, \OC_Log::WARN); } } } @@ -434,7 +460,7 @@ class OC_Setup { if (!$stmt) { $entry = $l->t('DB Error: "%s"', array(oci_last_error($connection))) . '<br />'; $entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />'; - echo($entry); + \OC_Log::write('setup.oci', $entry, \OC_Log::WARN); } $result = oci_execute($stmt); if($result) { @@ -498,9 +524,9 @@ class OC_Setup { $un = $dbtableprefix.'users'; oci_bind_by_name($stmt, ':un', $un); if (!$stmt) { - $entry = $l->t('DB Error: "%s"', array(oci_last_error($connection))) . '<br />'; + $entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '<br />'; $entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />'; - echo($entry); + \OC_Log::write('setup.oci', $entry, \OC_Log::WARN); } $result = oci_execute($stmt); @@ -526,14 +552,14 @@ class OC_Setup { if (!$stmt) { $entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '<br />'; $entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />'; - echo($entry); + \OC_Log::write('setup.oci', $entry, \OC_Log::WARN); } oci_bind_by_name($stmt, ':un', $name); $result = oci_execute($stmt); if(!$result) { $entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '<br />'; $entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />'; - echo($entry); + \OC_Log::write('setup.oci', $entry, \OC_Log::WARN); } if(! oci_fetch_row($stmt)) { @@ -544,15 +570,15 @@ class OC_Setup { if (!$stmt) { $entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '<br />'; $entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />'; - echo($entry); + \OC_Log::write('setup.oci', $entry, \OC_Log::WARN); } //oci_bind_by_name($stmt, ':un', $name); $result = oci_execute($stmt); if(!$result) { $entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '<br />'; - $entry .= $l->t('Offending command was: "%s", name: %s, password: %s', + $entry .= $l->t('Offending command was: "%s", name: %s, password: %s', array($query, $name, $password)) . '<br />'; - echo($entry); + \OC_Log::write('setup.oci', $entry, \OC_Log::WARN); } } else { // change password of the existing role $query = "ALTER USER :un IDENTIFIED BY :pw"; @@ -560,7 +586,7 @@ class OC_Setup { if (!$stmt) { $entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '<br />'; $entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />'; - echo($entry); + \OC_Log::write('setup.oci', $entry, \OC_Log::WARN); } oci_bind_by_name($stmt, ':un', $name); oci_bind_by_name($stmt, ':pw', $password); @@ -568,26 +594,200 @@ class OC_Setup { if(!$result) { $entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '<br />'; $entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />'; - echo($entry); + \OC_Log::write('setup.oci', $entry, \OC_Log::WARN); } } - // grant neccessary roles + // grant necessary roles $query = 'GRANT CREATE SESSION, CREATE TABLE, CREATE SEQUENCE, CREATE TRIGGER, UNLIMITED TABLESPACE TO '.$name; $stmt = oci_parse($connection, $query); if (!$stmt) { $entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '<br />'; $entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />'; - echo($entry); + \OC_Log::write('setup.oci', $entry, \OC_Log::WARN); } $result = oci_execute($stmt); if(!$result) { $entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '<br />'; - $entry .= $l->t('Offending command was: "%s", name: %s, password: %s', + $entry .= $l->t('Offending command was: "%s", name: %s, password: %s', array($query, $name, $password)) . '<br />'; - echo($entry); + \OC_Log::write('setup.oci', $entry, \OC_Log::WARN); } } + private static function setupMSSQLDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix) { + $l = self::getTrans(); + + //check if the database user has admin right + $masterConnectionInfo = array( "Database" => "master", "UID" => $dbuser, "PWD" => $dbpass); + + $masterConnection = @sqlsrv_connect($dbhost, $masterConnectionInfo); + if(!$masterConnection) { + $entry = null; + if( ($errors = sqlsrv_errors() ) != null) { + $entry='DB Error: "'.print_r(sqlsrv_errors()).'"<br />'; + } else { + $entry = ''; + } + throw new Exception($l->t('MS SQL username and/or password not valid: $s', array($entry))); + } + + OC_Config::setValue('dbuser', $dbuser); + OC_Config::setValue('dbpassword', $dbpass); + + self::mssql_createDBLogin($dbuser, $dbpass, $masterConnection); + + self::mssql_createDatabase($dbname, $masterConnection); + + self::mssql_createDBUser($dbuser, $dbname, $masterConnection); + + sqlsrv_close($masterConnection); + + self::mssql_createDatabaseStructure($dbhost, $dbname, $dbuser, $dbpass, $dbtableprefix); + } + + private static function mssql_createDBLogin($name, $password, $connection) { + $query = "SELECT * FROM master.sys.server_principals WHERE name = '".$name."';"; + $result = sqlsrv_query($connection, $query); + if ($result === false) { + if ( ($errors = sqlsrv_errors() ) != null) { + $entry='DB Error: "'.print_r(sqlsrv_errors()).'"<br />'; + } else { + $entry = ''; + } + $entry.='Offending command was: '.$query.'<br />'; + \OC_Log::write('setup.mssql', $entry, \OC_Log::WARN); + } else { + $row = sqlsrv_fetch_array($result); + + if ($row === false) { + if ( ($errors = sqlsrv_errors() ) != null) { + $entry='DB Error: "'.print_r(sqlsrv_errors()).'"<br />'; + } else { + $entry = ''; + } + $entry.='Offending command was: '.$query.'<br />'; + \OC_Log::write('setup.mssql', $entry, \OC_Log::WARN); + } else { + if ($row == null) { + $query = "CREATE LOGIN [".$name."] WITH PASSWORD = '".$password."';"; + $result = sqlsrv_query($connection, $query); + if (!$result or $result === false) { + if ( ($errors = sqlsrv_errors() ) != null) { + $entry='DB Error: "'.print_r(sqlsrv_errors()).'"<br />'; + } else { + $entry = ''; + } + $entry.='Offending command was: '.$query.'<br />'; + \OC_Log::write('setup.mssql', $entry, \OC_Log::WARN); + } + } + } + } + } + + private static function mssql_createDBUser($name, $dbname, $connection) { + $query = "SELECT * FROM [".$dbname."].sys.database_principals WHERE name = '".$name."';"; + $result = sqlsrv_query($connection, $query); + if ($result === false) { + if ( ($errors = sqlsrv_errors() ) != null) { + $entry='DB Error: "'.print_r(sqlsrv_errors()).'"<br />'; + } else { + $entry = ''; + } + $entry.='Offending command was: '.$query.'<br />'; + \OC_Log::write('setup.mssql', $entry, \OC_Log::WARN); + } else { + $row = sqlsrv_fetch_array($result); + + if ($row === false) { + if ( ($errors = sqlsrv_errors() ) != null) { + $entry='DB Error: "'.print_r(sqlsrv_errors()).'"<br />'; + } else { + $entry = ''; + } + $entry.='Offending command was: '.$query.'<br />'; + \OC_Log::write('setup.mssql', $entry, \OC_Log::WARN); + } else { + if ($row == null) { + $query = "USE [".$dbname."]; CREATE USER [".$name."] FOR LOGIN [".$name."];"; + $result = sqlsrv_query($connection, $query); + if (!$result || $result === false) { + if ( ($errors = sqlsrv_errors() ) != null) { + $entry = 'DB Error: "'.print_r(sqlsrv_errors()).'"<br />'; + } else { + $entry = ''; + } + $entry.='Offending command was: '.$query.'<br />'; + \OC_Log::write('setup.mssql', $entry, \OC_Log::WARN); + } + } + + $query = "USE [".$dbname."]; EXEC sp_addrolemember 'db_owner', '".$name."';"; + $result = sqlsrv_query($connection, $query); + if (!$result || $result === false) { + if ( ($errors = sqlsrv_errors() ) != null) { + $entry='DB Error: "'.print_r(sqlsrv_errors()).'"<br />'; + } else { + $entry = ''; + } + $entry.='Offending command was: '.$query.'<br />'; + \OC_Log::write('setup.mssql', $entry, \OC_Log::WARN); + } + } + } + } + + private static function mssql_createDatabase($dbname, $connection) { + $query = "CREATE DATABASE [".$dbname."];"; + $result = sqlsrv_query($connection, $query); + if (!$result || $result === false) { + if ( ($errors = sqlsrv_errors() ) != null) { + $entry='DB Error: "'.print_r(sqlsrv_errors()).'"<br />'; + } else { + $entry = ''; + } + $entry.='Offending command was: '.$query.'<br />'; + \OC_Log::write('setup.mssql', $entry, \OC_Log::WARN); + } + } + + private static function mssql_createDatabaseStructure($dbhost, $dbname, $dbuser, $dbpass, $dbtableprefix) { + $connectionInfo = array( "Database" => $dbname, "UID" => $dbuser, "PWD" => $dbpass); + + $connection = @sqlsrv_connect($dbhost, $connectionInfo); + + //fill the database if needed + $query = "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '{$dbname}' AND TABLE_NAME = '{$dbtableprefix}users'"; + $result = sqlsrv_query($connection, $query); + if ($result === false) { + if ( ($errors = sqlsrv_errors() ) != null) { + $entry='DB Error: "'.print_r(sqlsrv_errors()).'"<br />'; + } else { + $entry = ''; + } + $entry.='Offending command was: '.$query.'<br />'; + \OC_Log::write('setup.mssql', $entry, \OC_Log::WARN); + } else { + $row = sqlsrv_fetch_array($result); + + if ($row === false) { + if ( ($errors = sqlsrv_errors() ) != null) { + $entry='DB Error: "'.print_r(sqlsrv_errors()).'"<br />'; + } else { + $entry = ''; + } + $entry.='Offending command was: '.$query.'<br />'; + \OC_Log::write('setup.mssql', $entry, \OC_Log::WARN); + } else { + if ($row == null) { + OC_DB::createDbFromStructure('db_structure.xml'); + } + } + } + + sqlsrv_close($connection); + } + /** * create .htaccess files for apache hosts */ @@ -646,8 +846,7 @@ class OC_Setup { header("Location: ".OC::$WEBROOT.'/'); } else { - $error = $l->t('Your web server is not yet properly setup to allow files' - .' synchronization because the WebDAV interface seems to be broken.'); + $error = $l->t('Your web server is not yet properly setup to allow files synchronization because the WebDAV interface seems to be broken.'); $hint = $l->t('Please double check the <a href=\'%s\'>installation guides</a>.', 'http://doc.owncloud.org/server/5.0/admin_manual/installation.html'); diff --git a/lib/template.php b/lib/template.php index 3df5a24f946..ce55e58d28d 100644 --- a/lib/template.php +++ b/lib/template.php @@ -413,11 +413,6 @@ class OC_Template{ if( $this->renderas ) { $page = new OC_TemplateLayout($this->renderas); - if($this->renderas == 'user') { - $page->assign('requesttoken', $this->vars['requesttoken']); - $user = OC_User::getUser(); - $page->assign('displayname', OCP\User::getDisplayName($user)); - } // Add custom headers $page->assign('headers', $this->headers, false); @@ -530,8 +525,10 @@ class OC_Template{ * @param string $hint An option hint message */ public static function printErrorPage( $error_msg, $hint = '' ) { + $content = new OC_Template( '', 'error', 'error' ); $errors = array(array('error' => $error_msg, 'hint' => $hint)); - OC_Template::printGuestPage("", "error", array("errors" => $errors)); + $content->assign( 'errors', $errors, false ); + $content->printPage(); die(); } } diff --git a/lib/templatelayout.php b/lib/templatelayout.php index 25d4033d9ee..afa875b0a6d 100644 --- a/lib/templatelayout.php +++ b/lib/templatelayout.php @@ -31,7 +31,7 @@ class OC_TemplateLayout extends OC_Template { } $user_displayname = OC_User::getDisplayName(); $this->assign( 'user_displayname', $user_displayname ); - } else if ($renderas == 'guest') { + } else if ($renderas == 'guest' || $renderas == 'error') { parent::__construct('core', 'layout.guest'); } else { parent::__construct('core', 'layout.base'); @@ -39,7 +39,7 @@ class OC_TemplateLayout extends OC_Template { // Add the js files $jsfiles = self::findJavascriptFiles(OC_Util::$scripts); $this->assign('jsfiles', array(), false); - if (OC_Config::getValue('installed', false)) { + if (OC_Config::getValue('installed', false) && $renderas!='error') { $this->append( 'jsfiles', OC_Helper::linkToRoute('js_config')); } if (!empty(OC_Util::$core_scripts)) { diff --git a/lib/user.php b/lib/user.php index e69fef95a13..16f6d2787cb 100644 --- a/lib/user.php +++ b/lib/user.php @@ -437,7 +437,7 @@ class OC_User { } return false; } - + /** * @brief Check whether user can change his display name * @param $uid The username diff --git a/lib/user/backend.php b/lib/user/backend.php index 60b3cc6c5e4..93e8f17ca98 100644 --- a/lib/user/backend.php +++ b/lib/user/backend.php @@ -124,7 +124,7 @@ abstract class OC_User_Backend implements OC_User_Interface { public function getHome($uid) { return false; } - + /** * @brief get display name of the user * @param $uid user ID of the user @@ -133,7 +133,7 @@ abstract class OC_User_Backend implements OC_User_Interface { public function getDisplayName($uid) { return $uid; } - + /** * @brief Get a list of all display names * @returns array with all displayNames (value) and the corresponding uids (key) diff --git a/lib/user/database.php b/lib/user/database.php index a0ad03fe0a0..210c7f3e1eb 100644 --- a/lib/user/database.php +++ b/lib/user/database.php @@ -110,7 +110,7 @@ class OC_User_Database extends OC_User_Backend { return false; } } - + /** * @brief Set display name * @param $uid The username @@ -146,7 +146,7 @@ class OC_User_Database extends OC_User_Backend { } } } - + /** * @brief Get a list of all display names * @returns array with all displayNames (value) and the correspondig uids (key) @@ -162,7 +162,7 @@ class OC_User_Database extends OC_User_Backend { while ($row = $result->fetchRow()) { $displayNames[$row['uid']] = $row['displayname']; } - + // let's see if we can also find some users who don't have a display name yet $query = OC_DB::prepare('SELECT `uid`, `displayname` FROM `*PREFIX*users`' .' WHERE LOWER(`uid`) LIKE LOWER(?)', $limit, $offset); @@ -173,11 +173,11 @@ class OC_User_Database extends OC_User_Backend { $displayNames[$row['uid']] = $row['uid']; } } - - + + return $displayNames; } - + /** * @brief Check if the password is correct * @param $uid The username diff --git a/lib/util.php b/lib/util.php index b2a4fce65a2..cfb13ad292d 100755 --- a/lib/util.php +++ b/lib/util.php @@ -73,9 +73,9 @@ class OC_Util { * @return array */ public static function getVersion() { - // hint: We only can count up. So the internal version number - // of ownCloud 4.5 will be 4.90.0. This is not visible to the user - return array(4, 92, 10); + // hint: We only can count up. Reset minor/patchlevel when + // updating major/minor version number. + return array(4, 94, 10); } /** @@ -83,7 +83,7 @@ class OC_Util { * @return string */ public static function getVersionString() { - return '5.0 alpha 1'; + return '5.0 beta 2'; } /** @@ -269,18 +269,10 @@ class OC_Util { 'hint'=>'Please ask your server administrator to install the module.'); $web_server_restart= false; } - - $handler = ini_get("session.save_handler"); - if($handler == "files") { - $tmpDir = session_save_path(); - if($tmpDir != "") { - if(!@is_writable($tmpDir)) { - $errors[]=array('error' => 'The temporary folder used by PHP to save the session data' - .' is either incorrect or not writable! Please check : '.session_save_path().'<br/>', - 'hint'=>'Please ask your server administrator to grant write access' - .' or define another temporary folder.'); - } - } + if(ini_get('safe_mode')) { + $errors[]=array('error'=>'PHP Safe Mode is enabled. ownCloud requires that it is disabled to work properly.<br/>', + 'hint'=>'PHP Safe Mode is a deprecated and mostly useless setting that should be disabled. Please ask your server administrator to disable it in php.ini or in your webserver config.'); + $web_server_restart= false; } if($web_server_restart) { @@ -504,10 +496,10 @@ class OC_Util { * @return array with sanitized strings or a single sanitized string, depends on the input parameter. */ public static function sanitizeHTML( &$value ) { - if (is_array($value) || is_object($value)) { + if (is_array($value)) { array_walk_recursive($value, 'OC_Util::sanitizeHTML'); } else { - $value = htmlentities($value, ENT_QUOTES, 'UTF-8'); //Specify encoding for PHP<5.4 + $value = htmlentities((string)$value, ENT_QUOTES, 'UTF-8'); //Specify encoding for PHP<5.4 } return $value; } @@ -562,13 +554,18 @@ class OC_Util { */ public static function isWebDAVWorking() { if (!function_exists('curl_init')) { - return; + return true; } - $settings = array( 'baseUri' => OC_Helper::linkToRemote('webdav'), ); + // save the old timeout so that we can restore it later + $old_timeout=ini_get("default_socket_timeout"); + + // use a 5 sec timeout for the check. Should be enough for local requests. + ini_set("default_socket_timeout", 5); + $client = new \Sabre_DAV_Client($settings); $return = true; @@ -578,9 +575,13 @@ class OC_Util { } catch(\Sabre_DAV_Exception_NotAuthenticated $e) { $return = true; } catch(\Exception $e) { + OC_Log::write('core', 'isWebDAVWorking: NO - Reason: '.$e, OC_Log::WARN); $return = false; } + // restore the original timeout + ini_set("default_socket_timeout", $old_timeout); + return $return; } |