diff options
author | Robin Appelman <icewind@owncloud.com> | 2012-02-26 14:21:06 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2012-02-26 14:21:06 +0100 |
commit | d4d09b06f80462394983fe04d291a0345dd57280 (patch) | |
tree | e4452055533c7ec7bb6fa49ac7f6b5c93ba8c4f7 /lib | |
parent | ea8f71a19c59e7138d4a504bacc0beb410fc77e8 (diff) | |
parent | 3d0d47957e65a72e17d33a924c9c4efcd5088ed2 (diff) | |
download | nextcloud-server-d4d09b06f80462394983fe04d291a0345dd57280.tar.gz nextcloud-server-d4d09b06f80462394983fe04d291a0345dd57280.zip |
merge master into encryption
Diffstat (limited to 'lib')
-rw-r--r-- | lib/base.php | 7 | ||||
-rw-r--r-- | lib/db.php | 25 | ||||
-rw-r--r-- | lib/filecache.php | 23 | ||||
-rw-r--r-- | lib/filestorage.php | 1 | ||||
-rw-r--r-- | lib/filestorage/local.php | 3 | ||||
-rw-r--r-- | lib/filestoragecommon.php | 8 | ||||
-rw-r--r-- | lib/filesystemview.php | 9 | ||||
-rw-r--r-- | lib/geo.php | 31 | ||||
-rw-r--r-- | lib/helper.php | 2 | ||||
-rw-r--r-- | lib/log.php | 26 | ||||
-rw-r--r-- | lib/user/database.php | 49 | ||||
-rw-r--r-- | lib/util.php | 2 |
12 files changed, 146 insertions, 40 deletions
diff --git a/lib/base.php b/lib/base.php index 85afaa62258..ee1a86399ac 100644 --- a/lib/base.php +++ b/lib/base.php @@ -143,6 +143,13 @@ class OC{ $scriptName=$_SERVER["SCRIPT_NAME"]; if(substr($scriptName,-1)=='/'){ $scriptName.='index.php'; + //make sure suburi follows the same rules as scriptName + if(substr(OC::$SUBURI,-9)!='index.php'){ + if(substr(OC::$SUBURI,-1)!='/'){ + OC::$SUBURI=OC::$SUBURI.'/'; + } + OC::$SUBURI=OC::$SUBURI.'index.php'; + } } OC::$WEBROOT=substr($scriptName,0,strlen($scriptName)-strlen(OC::$SUBURI)); diff --git a/lib/db.php b/lib/db.php index 4c17cd0dbd1..02eac7cac9a 100644 --- a/lib/db.php +++ b/lib/db.php @@ -508,6 +508,21 @@ class OC_DB { self::$connection->commit(); self::$inTransaction=false; } + + /** + * check if a result is an error, works with MDB2 and PDOException + * @param mixed $result + * @return bool + */ + public static function isError($result){ + if(!$result){ + return true; + }elseif(self::$backend==self::BACKEND_MDB2 and PEAR::isError($result)){ + return true; + }else{ + return false; + } + } } /** @@ -527,11 +542,15 @@ class PDOStatementWrapper{ public function execute($input=array()){ $this->lastArguments=$input; if(count($input)>0){ - $this->statement->execute($input); + $result=$this->statement->execute($input); }else{ - $this->statement->execute(); + $result=$this->statement->execute(); + } + if($result){ + return $this; + }else{ + return false; } - return $this; } /** diff --git a/lib/filecache.php b/lib/filecache.php index 6ccb0d90ef1..732160c216a 100644 --- a/lib/filecache.php +++ b/lib/filecache.php @@ -112,7 +112,10 @@ class OC_FileCache{ $mimePart=dirname($data['mimetype']); $user=OC_User::getUser(); $query=OC_DB::prepare('INSERT INTO *PREFIX*fscache(parent, name, path, size, mtime, ctime, mimetype, mimepart,user,writable,encrypted,versioned) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)'); - $query->execute(array($parent,basename($path),$path,$data['size'],$data['mtime'],$data['ctime'],$data['mimetype'],$mimePart,$user,$data['writable'],$data['encrypted'],$data['versioned'])); + $result=$query->execute(array($parent,basename($path),$path,$data['size'],$data['mtime'],$data['ctime'],$data['mimetype'],$mimePart,$user,$data['writable'],$data['encrypted'],$data['versioned'])); + if(OC_DB::isError($result)){ + OC_Log::write('files','error while writing file('.$path.') to cache',OC_Log::ERROR); + } } /** @@ -137,7 +140,10 @@ class OC_FileCache{ $sql = 'UPDATE *PREFIX*fscache SET '.implode(' , ',$queryParts).' WHERE id=?'; $query=OC_DB::prepare($sql); - $query->execute($arguments); + $result=$query->execute($arguments); + if(OC_DB::isError($result)){ + OC_Log::write('files','error while updating file('.$path.') in cache',OC_Log::ERROR); + } } /** @@ -271,11 +277,20 @@ class OC_FileCache{ */ private static function getFileId($path){ $query=OC_DB::prepare('SELECT id FROM *PREFIX*fscache WHERE path=?'); - $result=$query->execute(array($path))->fetchRow(); + if(OC_DB::isError($query)){ + OC_Log::write('files','error while getting file id of '.$path,OC_Log::ERROR); + return -1; + } + $result=$query->execute(array($path)); + if(OC_DB::isError($result)){ + OC_Log::write('files','error while getting file id of '.$path,OC_Log::ERROR); + return -1; + } + $result=$result->fetchRow(); if(is_array($result)){ return $result['id']; }else{ - OC_Log::write('getFileId(): file not found in cache ('.$path.')','core',OC_Log::DEBUG); + OC_Log::write('getFileId(): file not found in cache ('.$path.')','core',OC_Log::DEBUG); return -1; } } diff --git a/lib/filestorage.php b/lib/filestorage.php index d420427225b..b6d71d41743 100644 --- a/lib/filestorage.php +++ b/lib/filestorage.php @@ -36,7 +36,6 @@ class OC_Filestorage{ public function is_readable($path){} public function is_writable($path){} public function file_exists($path){} - public function readfile($path){} public function filectime($path){} public function filemtime($path){} public function file_get_contents($path){} diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php index 6f4f68c503d..7d889fbce58 100644 --- a/lib/filestorage/local.php +++ b/lib/filestorage/local.php @@ -52,9 +52,6 @@ class OC_Filestorage_Local extends OC_Filestorage{ public function file_exists($path){ return file_exists($this->datadir.$path); } - public function readfile($path){ - return readfile($this->datadir.$path); - } public function filectime($path){ return filectime($this->datadir.$path); } diff --git a/lib/filestoragecommon.php b/lib/filestoragecommon.php index f522d15c4e9..45ad11fcde8 100644 --- a/lib/filestoragecommon.php +++ b/lib/filestoragecommon.php @@ -37,14 +37,6 @@ class OC_Filestorage_Common extends OC_Filestorage { public function is_readable($path){} public function is_writable($path){} public function file_exists($path){} - public function readfile($path) { - $handle = $this->fopen($path, "r"); - $chunk = 1024; - while (!feof($handle)) { - echo fread($handle, $chunk); - } - return $this->filesize($path); - } public function filectime($path) { $stat = $this->stat($path); return $stat['ctime']; diff --git a/lib/filesystemview.php b/lib/filesystemview.php index c4d5ff35142..ba1490dd276 100644 --- a/lib/filesystemview.php +++ b/lib/filesystemview.php @@ -136,7 +136,14 @@ class OC_FilesystemView { return $this->basicOperation('filesize',$path); } public function readfile($path){ - return $this->basicOperation('readfile',$path,array('read')); + $handle=$this->fopen($path,'r'); + $chunkSize = 1024*1024;// 1 MB chunks + while (!feof($handle)) { + echo fread($handle, $chunkSize); + @ob_flush(); + flush(); + } + return $this->filesize($path); } public function is_readable($path){ return $this->basicOperation('is_readable',$path); diff --git a/lib/geo.php b/lib/geo.php new file mode 100644 index 00000000000..a967ab28a96 --- /dev/null +++ b/lib/geo.php @@ -0,0 +1,31 @@ +<?php +/** + * Copyright (c) 2012 Georg Ehrke <ownclouddev at georgswebsite dot de> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +class OC_Geo{ + /* + * @brief returns the closest timezone to coordinates + * @param (string) $latitude - Latitude + * @param (string) $longitude - Longitude + * @return (string) $timezone - closest timezone + */ + public static function timezone($latitude, $longitude){ + $alltimezones = DateTimeZone::listIdentifiers(); + $variances = array(); + //calculate for all timezones the system know + foreach($alltimezones as $timezone){ + $datetimezoneobj = new DateTimeZone($timezone); + $locationinformations = $datetimezoneobj->getLocation(); + $latitudeoftimezone = $locationinformations['latitude']; + $longitudeoftimezone = $locationinformations['longitude']; + $variances[abs($latitudeoftimezone - $latitude) + abs($longitudeoftimezone - $longitude)] = $timezone; + } + //sort array and return the timezone with the smallest difference + ksort($variances); + reset($variances); + return current($variances); + } +}
\ No newline at end of file diff --git a/lib/helper.php b/lib/helper.php index 6dea4a6a8cd..8cf94f81b0b 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -196,7 +196,7 @@ class OC_Helper { $bytes *= $bytes_array[$matches[1]]; } - $bytes = intval(round($bytes, 2)); + $bytes = round($bytes, 2); return $bytes; } diff --git a/lib/log.php b/lib/log.php index 446ddd48848..4e450a027f5 100644 --- a/lib/log.php +++ b/lib/log.php @@ -3,7 +3,7 @@ * ownCloud * * @author Robin Appelman - * @copyright 2011 Robin Appelman icewind1991@gmail.com + * @copyright 2012 Robin Appelman icewind1991@gmail.com * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE @@ -50,25 +50,29 @@ class OC_Log{ fclose($fh); } } - - public static function getEntries(){ + + /** + * get entries from the log in reverse chronological order + * @param int limit + * @param int offset + * @return array + */ + public static function getEntries($limit=50,$offset=0){ $datadir=OC_Config::getValue( "datadirectory", OC::$SERVERROOT.'/data' ); $logFile=OC_Config::getValue( "logfile", $datadir.'/owncloud.log' ); $entries=array(); if(!file_exists($logFile)){ return array(); } - $fh=fopen($logFile,'r'); - if($fh === false){ // Unable to read log file! + $contents=file($logFile); + if(!$contents){//error while reading log return array(); } - while(!feof($fh)){ - $line=fgets($fh); - if($line){ - $entries[]=json_decode($line); - } + $end=max(count($contents)-$offset-1,0); + $start=max($end-$limit,0); + for($i=$end;$i>$start;$i--){ + $entries[]=json_decode($contents[$i]); } - fclose($fh); return $entries; } } diff --git a/lib/user/database.php b/lib/user/database.php index 452709c1fb9..3eade276dd9 100644 --- a/lib/user/database.php +++ b/lib/user/database.php @@ -33,12 +33,28 @@ * */ +require_once 'phpass/PasswordHash.php'; + /** * Class for user management in a SQL Database (e.g. MySQL, SQLite) */ class OC_User_Database extends OC_User_Backend { static private $userGroupCache=array(); + /** + * @var PasswordHash + */ + static private $hasher=null; + + private function getHasher(){ + if(!self::$hasher){ + //we don't want to use DES based crypt(), since it doesn't return a has with a recognisable prefix + $forcePortable=(CRYPT_BLOWFISH!=1); + self::$hasher=new PasswordHash(8,$forcePortable); + } + return self::$hasher; + } + /** * @brief Create a new user * @param $uid The username of the user to create @@ -51,10 +67,11 @@ class OC_User_Database extends OC_User_Backend { public function createUser( $uid, $password ){ if( $this->userExists($uid) ){ return false; - } - else{ + }else{ + $hasher=$this->getHasher(); + $hash = $hasher->HashPassword($password); $query = OC_DB::prepare( "INSERT INTO `*PREFIX*users` ( `uid`, `password` ) VALUES( ?, ? )" ); - $result = $query->execute( array( $uid, sha1( $password ))); + $result = $query->execute( array( $uid, $hash)); return $result ? true : false; } @@ -84,8 +101,10 @@ class OC_User_Database extends OC_User_Backend { */ public function setPassword( $uid, $password ){ if( $this->userExists($uid) ){ + $hasher=$this->getHasher(); + $hash = $hasher->HashPassword($password); $query = OC_DB::prepare( "UPDATE *PREFIX*users SET password = ? WHERE uid = ?" ); - $result = $query->execute( array( sha1( $password ), $uid )); + $result = $query->execute( array( $hash, $uid )); return true; } @@ -103,12 +122,28 @@ class OC_User_Database extends OC_User_Backend { * Check if the password is correct without logging in the user */ public function checkPassword( $uid, $password ){ - $query = OC_DB::prepare( "SELECT uid FROM *PREFIX*users WHERE uid LIKE ? AND password = ?" ); - $result = $query->execute( array( $uid, sha1( $password ))); + $query = OC_DB::prepare( "SELECT uid, password FROM *PREFIX*users WHERE uid LIKE ?" ); + $result = $query->execute( array( $uid)); $row=$result->fetchRow(); if($row){ - return $row['uid']; + $storedHash=$row['password']; + if (substr($storedHash,0,1)=='$'){//the new phpass based hashing + $hasher=$this->getHasher(); + if($hasher->CheckPassword($password, $storedHash)){ + return $row['uid']; + }else{ + return false; + } + }else{//old sha1 based hashing + if(sha1($password)==$storedHash){ + //upgrade to new hashing + $this->setPassword($row['uid'],$password); + return $row['uid']; + }else{ + return false; + } + } }else{ return false; } diff --git a/lib/util.php b/lib/util.php index 2fd1dd543d6..fa5b3daaab6 100644 --- a/lib/util.php +++ b/lib/util.php @@ -66,7 +66,7 @@ class OC_Util { * @return array */ public static function getVersion(){ - return array(3,00,2); + return array(3,00,3); } /** |