From 640ba1828f3edfdd2e71825828c51b734fb19d1c Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 19 Mar 2012 21:56:07 +0100 Subject: Start of audit app Audit the filesystem action --- lib/filesystem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/filesystem.php b/lib/filesystem.php index cac7e8648ef..2b45e66c92f 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -25,7 +25,7 @@ /** * Class for abstraction of filesystem functions * This class won't call any filesystem functions for itself but but will pass them to the correct OC_Filestorage object - * this class should also handle all the file premission related stuff + * this class should also handle all the file permission related stuff * * Hooks provided: * read(path) -- cgit v1.2.3 From 0d3f5f736f8e0d32470ea31980bae1094fcab50a Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Thu, 14 Jun 2012 18:22:48 +0200 Subject: Disable minizing when DEBUG is true --- lib/minimizer/css.php | 4 +++- lib/minimizer/js.php | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/minimizer/css.php b/lib/minimizer/css.php index 4637417579e..09a0efdc3a7 100644 --- a/lib/minimizer/css.php +++ b/lib/minimizer/css.php @@ -67,7 +67,9 @@ class OC_Minimizer_CSS extends OC_Minimizer $remote .= dirname($file_info[2]); $css_out .= CSSMin::remap($css, dirname($file), $remote, true); } - $css_out = CSSMin::minify($css_out); + if (!defined('DEBUG') || !DEBUG){ + $css_out = CSSMin::minify($css_out); + } return $css_out; } } diff --git a/lib/minimizer/js.php b/lib/minimizer/js.php index 4ddaa79d81a..b9a023e0686 100644 --- a/lib/minimizer/js.php +++ b/lib/minimizer/js.php @@ -56,7 +56,9 @@ class OC_Minimizer_JS extends OC_Minimizer $js_out .= '/* ' . $file . ' */' . "\n"; $js_out .= file_get_contents($file); } - $js_out = JavaScriptMinifier::minify($js_out); + if (!defined('DEBUG') || !DEBUG){ + $js_out = JavaScriptMinifier::minify($js_out); + } return $js_out; } } -- cgit v1.2.3 From 2b228fba3463722ad19ea6ccd150b96772508791 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 15 Jun 2012 11:18:38 +0200 Subject: Load app before running update script --- lib/app.php | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/app.php b/lib/app.php index 0c51e3c5532..7fdfc93138f 100755 --- a/lib/app.php +++ b/lib/app.php @@ -542,6 +542,7 @@ class OC_App{ return; } if(file_exists(OC::$APPSROOT.'/apps/'.$appid.'/appinfo/update.php')){ + self::loadApp($appid); include OC::$APPSROOT.'/apps/'.$appid.'/appinfo/update.php'; } -- cgit v1.2.3 From 400769ab400f8c57b95d762420ff2b8da62738a3 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 15 Jun 2012 16:04:01 +0200 Subject: Optimize WebDav access using OC_FileCache --- lib/connector/sabre/directory.php | 25 +++++++++++-------------- lib/connector/sabre/file.php | 7 +++++-- lib/connector/sabre/node.php | 22 +++++++++++++++------- 3 files changed, 31 insertions(+), 23 deletions(-) (limited to 'lib') diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php index e74d832cb00..5aa70392d76 100644 --- a/lib/connector/sabre/directory.php +++ b/lib/connector/sabre/directory.php @@ -59,19 +59,22 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa * @throws Sabre_DAV_Exception_FileNotFound * @return Sabre_DAV_INode */ - public function getChild($name) { + public function getChild($name, $info = null) { $path = $this->path . '/' . $name; + if (is_null($info)) { + $info = OC_FileCache::get($path); + } - if (!OC_Filesystem::file_exists($path)) throw new Sabre_DAV_Exception_NotFound('File with name ' . $path . ' could not be located'); + if (!$info) throw new Sabre_DAV_Exception_NotFound('File with name ' . $path . ' could not be located'); - if (OC_Filesystem::is_dir($path)) { + if ($info['mimetype'] == 'httpd/unix-directory') { - return new OC_Connector_Sabre_Directory($path); + return new OC_Connector_Sabre_Directory($path, $info); } else { - return new OC_Connector_Sabre_File($path); + return new OC_Connector_Sabre_File($path, $info); } @@ -85,17 +88,11 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa public function getChildren() { $nodes = array(); - // foreach(scandir($this->path) as $node) if($node!='.' && $node!='..') $nodes[] = $this->getChild($node); - if( OC_Filesystem::is_dir($this->path . '/')){ - $dh = OC_Filesystem::opendir($this->path . '/'); - while(( $node = readdir($dh)) !== false ){ - if($node!='.' && $node!='..'){ - $nodes[] = $this->getChild($node); - } - } + $folder_content = OC_FileCache::getFolderContent($this->path); + foreach($folder_content as $info) { + $nodes[] = $this->getChild($info['name'], $info); } return $nodes; - } /** diff --git a/lib/connector/sabre/file.php b/lib/connector/sabre/file.php index 3ba1b3355f2..dd25df78c29 100644 --- a/lib/connector/sabre/file.php +++ b/lib/connector/sabre/file.php @@ -63,8 +63,8 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D * @return int */ public function getSize() { - $this->stat(); - return $this->stat_cache['size']; + $this->getFileinfoCache(); + return $this->fileinfo_cache['size']; } @@ -92,6 +92,9 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D * @return mixed */ public function getContentType() { + if (isset($this->fileinfo_cache['mimetype'])) { + return $this->fileinfo_cache['mimetype']; + } return OC_Filesystem::getMimeType($this->path); diff --git a/lib/connector/sabre/node.php b/lib/connector/sabre/node.php index e7bcea3171d..e5c059f0c8a 100644 --- a/lib/connector/sabre/node.php +++ b/lib/connector/sabre/node.php @@ -33,7 +33,7 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr * file stat cache * @var array */ - protected $stat_cache; + protected $fileinfo_cache; /** * Sets up the node, expects a full path name @@ -41,8 +41,11 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr * @param string $path * @return void */ - public function __construct($path) { + public function __construct($path, $fileinfo_cache = null) { $this->path = $path; + if ($fileinfo_cache) { + $this->fileinfo_cache = $fileinfo_cache; + } } @@ -85,9 +88,14 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr /** * Set the stat cache */ - protected function stat() { - if (!isset($this->stat_cache)) { - $this->stat_cache = OC_Filesystem::stat($this->path); + protected function getFileinfoCache() { + if (!isset($this->fileinfo_cache)) { + if ($fileinfo_cache = OC_FileCache::get($this->path)) { + } else { + $fileinfo_cache = OC_Filesystem::stat($this->path); + } + + $this->fileinfo_cache = $fileinfo_cache; } } @@ -97,8 +105,8 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr * @return int */ public function getLastModified() { - $this->stat(); - return $this->stat_cache['mtime']; + $this->getFileinfoCache(); + return $this->fileinfo_cache['mtime']; } -- cgit v1.2.3 From 449760f665a2416875458cbb3f34387df038b08a Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 15 Jun 2012 16:43:24 +0200 Subject: add hasUpdated to oc_filestorage --- apps/files_sharing/sharedstorage.php | 9 +++++++++ lib/filestorage.php | 9 +++++++++ lib/filestorage/common.php | 9 +++++++++ lib/filestorage/local.php | 9 +++++++++ tests/lib/filestorage.php | 8 ++++++++ 5 files changed, 44 insertions(+) (limited to 'lib') diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 3bb6e73035e..1a6942ad160 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -512,6 +512,15 @@ class OC_Filestorage_Shared extends OC_Filestorage { OC_Filesystem::mount('OC_Filestorage_Shared', array('datadir' => '/'.OCP\USER::getUser().'/files/Shared'), '/'.OCP\USER::getUser().'/files/Shared/'); } + /** + * check if a file or folder has been updated since $time + * @param int $time + * @return bool + */ + public function hasUpdated($path,$time){ + //TODO + return $this->filemtime($path)>$time; + } } if (OCP\USER::isLoggedIn()) { diff --git a/lib/filestorage.php b/lib/filestorage.php index 1d7e004af3b..71ef4aed00b 100644 --- a/lib/filestorage.php +++ b/lib/filestorage.php @@ -50,4 +50,13 @@ abstract class OC_Filestorage{ abstract public function search($query); abstract public function touch($path, $mtime=null); abstract public function getLocalFile($path);// get a path to a local version of the file, whether the original file is local or remote + /** + * check if a file or folder has been updated since $time + * @param int $time + * @return bool + * + * hasUpdated for folders should return at least true if a file inside the folder is add, removed or renamed. + * returning true for other changes in the folder is optional + */ + abstract public function hasUpdated($path,$time); } diff --git a/lib/filestorage/common.php b/lib/filestorage/common.php index f0bfc064cb5..f2a5775fd19 100644 --- a/lib/filestorage/common.php +++ b/lib/filestorage/common.php @@ -156,4 +156,13 @@ abstract class OC_Filestorage_Common extends OC_Filestorage { } return $files; } + + /** + * check if a file or folder has been updated since $time + * @param int $time + * @return bool + */ + public function hasUpdated($path,$time){ + return $this->filemtime($path)>$time; + } } diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php index ea9a9070263..44a2ab0f634 100644 --- a/lib/filestorage/local.php +++ b/lib/filestorage/local.php @@ -194,4 +194,13 @@ class OC_Filestorage_Local extends OC_Filestorage{ public function getFolderSize($path){ return 0;//depricated, use OC_FileCach instead } + + /** + * check if a file or folder has been updated since $time + * @param int $time + * @return bool + */ + public function hasUpdated($path,$time){ + return $this->filemtime($path)>$time; + } } diff --git a/tests/lib/filestorage.php b/tests/lib/filestorage.php index f71b658253a..00f37b9f1a2 100644 --- a/tests/lib/filestorage.php +++ b/tests/lib/filestorage.php @@ -149,6 +149,9 @@ abstract class Test_FileStorage extends UnitTestCase { $this->assertTrue(($ctimeStart-1)<=$cTime); $this->assertTrue($cTime<=($ctimeEnd+1)); } + $this->assertTrue($this->instance->hasUpdated('/lorem.txt',$ctimeStart-1)); + $this->assertTrue($this->instance->hasUpdated('/',$ctimeStart-1)); + $this->assertTrue(($ctimeStart-1)<=$mTime); $this->assertTrue($mTime<=($ctimeEnd+1)); $this->assertEqual(filesize($textFile),$this->instance->filesize('/lorem.txt')); @@ -168,6 +171,8 @@ abstract class Test_FileStorage extends UnitTestCase { $this->assertTrue(($mtimeStart-1)<=$mTime); $this->assertTrue($mTime<=($mtimeEnd+1)); $this->assertEqual($cTime,$originalCTime); + + $this->assertTrue($this->instance->hasUpdated('/lorem.txt',$mtimeStart-1)); if($this->instance->touch('/lorem.txt',100)!==false){ $mTime=$this->instance->filemtime('/lorem.txt'); @@ -184,6 +189,9 @@ abstract class Test_FileStorage extends UnitTestCase { $mTime=$this->instance->filemtime('/lorem.txt'); $this->assertTrue(($mtimeStart-1)<=$mTime); $this->assertTrue($mTime<=($mtimeEnd+1)); + + $this->instance->unlink('/lorem.txt'); + $this->assertTrue($this->instance->hasUpdated('/',$mtimeStart-1)); } public function testSearch(){ -- cgit v1.2.3 From a9a424a51982396943e9c3353c0c36f289dd41ba Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 15 Jun 2012 17:42:39 +0200 Subject: also add hasUpdated to oc_filesystem and oc_filesystemview --- lib/filesystem.php | 9 +++++++++ lib/filesystemview.php | 9 +++++++++ 2 files changed, 18 insertions(+) (limited to 'lib') diff --git a/lib/filesystem.php b/lib/filesystem.php index 28bd7d52900..89de533d725 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -474,6 +474,15 @@ class OC_Filesystem{ static public function search($query){ return OC_FileCache::search($query); } + + /** + * check if a file or folder has been updated since $time + * @param int $time + * @return bool + */ + static public function hasUpdated($path,$time){ + return self::$defaultInstance->hasUpdated($path); + } } require_once('filecache.php'); diff --git a/lib/filesystemview.php b/lib/filesystemview.php index 58657671b98..813a87cd74e 100644 --- a/lib/filesystemview.php +++ b/lib/filesystemview.php @@ -444,4 +444,13 @@ class OC_FilesystemView { } return null; } + + /** + * check if a file or folder has been updated since $time + * @param int $time + * @return bool + */ + public function hasUpdated($path,$time){ + return $this->basicOperation('hasUpdated',$path,array(),$time); + } } -- cgit v1.2.3 From f06c08a63742de9adea4a146a4480b71ad254f20 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 15 Jun 2012 19:56:15 +0200 Subject: cleanup oc_filecache, splitting it in several parts and using the new hasUpdated --- apps/files/ajax/upload.php | 2 +- apps/files_encryption/lib/proxy.php | 2 +- lib/filecache.php | 430 ++++++------------------------------ lib/filecache/cached.php | 67 ++++++ lib/filecache/update.php | 210 ++++++++++++++++++ lib/fileproxy/quota.php | 4 +- lib/files.php | 2 +- 7 files changed, 344 insertions(+), 373 deletions(-) create mode 100644 lib/filecache/cached.php create mode 100644 lib/filecache/update.php (limited to 'lib') diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php index d6c799af32c..b779924cfb4 100644 --- a/apps/files/ajax/upload.php +++ b/apps/files/ajax/upload.php @@ -48,7 +48,7 @@ if(strpos($dir,'..') === false){ for($i=0;$i<$fileCount;$i++){ $target = OCP\Files::buildNotExistingFileName(stripslashes($dir), $files['name'][$i]); if(is_uploaded_file($files['tmp_name'][$i]) and OC_Filesystem::fromTmpFile($files['tmp_name'][$i],$target)){ - $meta=OC_FileCache::getCached($target); + $meta=OC_FileCache_Cached::get($target); $result[]=array( "status" => "success", 'mime'=>$meta['mimetype'],'size'=>$meta['size'],'name'=>basename($target)); } } diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php index 9fd57c0f02b..ad9bcf55f2b 100644 --- a/apps/files_encryption/lib/proxy.php +++ b/apps/files_encryption/lib/proxy.php @@ -59,7 +59,7 @@ class OC_FileProxy_Encryption extends OC_FileProxy{ * @return bool */ private static function isEncrypted($path){ - $metadata=OC_FileCache::getCached($path,''); + $metadata=OC_FileCache_Cached::get($path,''); return isset($metadata['encrypted']) and (bool)$metadata['encrypted']; } diff --git a/lib/filecache.php b/lib/filecache.php index 3fb8e4113cb..7c9c4dc41ff 100644 --- a/lib/filecache.php +++ b/lib/filecache.php @@ -28,8 +28,6 @@ * It will try to keep the data up to date but changes from outside ownCloud can invalidate the cache */ class OC_FileCache{ - private static $savedData=array(); - /** * get the filesystem info from the cache * @param string path @@ -44,29 +42,15 @@ class OC_FileCache{ * - encrypted * - versioned */ - public static function get($path,$root=''){ - if(self::isUpdated($path,$root)){ - if(!$root){//filesystem hooks are only valid for the default root + public static function get($path,$root=false){ + if(OC_FileCache_Update::hasUpdated($path,$root)){ + if($root===false){//filesystem hooks are only valid for the default root OC_Hook::emit('OC_Filesystem','post_write',array('path'=>$path)); }else{ - self::fileSystemWatcherWrite(array('path'=>$path),$root); + OC_FileCache_Update::update($path,$root); } } - if(!$root){ - $root=OC_Filesystem::getRoot(); - } - if($root=='/'){ - $root=''; - } - $path=$root.$path; - $query=OC_DB::prepare('SELECT ctime,mtime,mimetype,size,encrypted,versioned,writable FROM *PREFIX*fscache WHERE path_hash=?'); - $result=$query->execute(array(md5($path)))->fetchRow(); - if(is_array($result)){ - return $result; - }else{ - OC_Log::write('files','get(): file not found in cache ('.$path.')',OC_Log::DEBUG); - return false; - } + return OC_FileCache_Cached::get($path,$root); } /** @@ -77,30 +61,23 @@ class OC_FileCache{ * * $data is an assiciative array in the same format as returned by get */ - public static function put($path,$data,$root=''){ - if(!$root){ + public static function put($path,$data,$root=false){ + if($root===false){ $root=OC_Filesystem::getRoot(); } - if($root=='/'){ - $root=''; - } $path=$root.$path; - if($path=='/'){ - $parent=-1; - }else{ - $parent=self::getFileId(dirname($path)); - } - $id=self::getFileId($path); + $parent=self::getParentId($path); + $id=self::getId($path,''); if($id!=-1){ self::update($id,$data); return; } - if(isset(self::$savedData[$path])){ - $data=array_merge($data,self::$savedData[$path]); - unset(self::$savedData[$path]); + if(isset(OC_FileCache_Cached::$savedData[$path])){ + $data=array_merge($data,OC_FileCache_Cached::$savedData[$path]); + unset(OC_FileCache_Cached::$savedData[$path]); } if(!isset($data['size']) or !isset($data['mtime'])){//save incomplete data for the next time we write it - self::$savedData[$path]=$data; + OC_FileCache_Cached::$savedData[$path]=$data; return; } if(!isset($data['encrypted'])){ @@ -157,13 +134,10 @@ class OC_FileCache{ * @param string newPath * @param string root (optional) */ - public static function move($oldPath,$newPath,$root=''){ - if(!$root){ + public static function move($oldPath,$newPath,$root=false){ + if($root===false){ $root=OC_Filesystem::getRoot(); } - if($root=='/'){ - $root=''; - } $oldPath=$root.$oldPath; $newPath=$root.$newPath; $newParent=self::getParentId($newPath); @@ -182,28 +156,19 @@ class OC_FileCache{ /** * delete info from the cache - * @param string/int $file + * @param string path * @param string root (optional) */ - public static function delete($file,$root=''){ - if(!is_numeric($file)){ - if(!$root){ - $root=OC_Filesystem::getRoot(); - } - if($root=='/'){ - $root=''; - } - $path=$root.$file; - self::delete(self::getFileId($path)); - }elseif($file!=-1){ - $query=OC_DB::prepare('SELECT id FROM *PREFIX*fscache WHERE parent=?'); - $result=$query->execute(array($file)); - while($child=$result->fetchRow()){ - self::delete(intval($child['id'])); - } - $query=OC_DB::prepare('DELETE FROM *PREFIX*fscache WHERE id=?'); - $query->execute(array($file)); + public static function delete($path,$root=false){ + if($root===false){ + $root=OC_Filesystem::getRoot(); } + $query=OC_DB::prepare('DELETE FROM *PREFIX*fscache WHERE path_hash=?'); + $query->execute(array(md5($root.$path))); + + //delete everything inside the folder + $query=OC_DB::prepare('DELETE FROM *PREFIX*fscache WHERE path LIKE ?'); + $query->execute(array($root.$path.'/%')); } /** @@ -213,13 +178,10 @@ class OC_FileCache{ * @param string root (optional) * @return array of filepaths */ - public static function search($search,$returnData=false,$root=''){ - if(!$root){ + public static function search($search,$returnData=false,$root=false){ + if($root===false){ $root=OC_Filesystem::getRoot(); } - if($root=='/'){ - $root=''; - } $rootLen=strlen($root); if(!$returnData){ $query=OC_DB::prepare('SELECT path FROM *PREFIX*fscache WHERE name LIKE ? AND `user`=?'); @@ -254,26 +216,11 @@ class OC_FileCache{ * - encrypted * - versioned */ - public static function getFolderContent($path,$root='',$mimetype_filter=''){ - if(self::isUpdated($path,$root)){ - self::updateFolder($path,$root); - } - if(!$root){ - $root=OC_Filesystem::getRoot(); - } - if($root=='/'){ - $root=''; - } - $path=$root.$path; - $parent=self::getFileId($path); - $query=OC_DB::prepare('SELECT name,ctime,mtime,mimetype,size,encrypted,versioned,writable FROM *PREFIX*fscache WHERE parent=? AND (mimetype LIKE ? OR mimetype = ?)'); - $result=$query->execute(array($parent, $mimetype_filter.'%', 'httpd/unix-directory'))->fetchAll(); - if(is_array($result)){ - return $result; - }else{ - OC_Log::write('files','getFolderContent(): file not found in cache ('.$path.')',OC_Log::DEBUG); - return false; + public static function getFolderContent($path,$root=false,$mimetype_filter=''){ + if(OC_FileCache_Update::hasUpdated($path,$root)){ + OC_FileCache_Update::updateFolder($path,$root); } + return OC_FileCache_Cached::getFolderContent($path,$root,$mimetype_filter); } /** @@ -282,60 +229,36 @@ class OC_FileCache{ * @param string root (optional) * @return bool */ - public static function inCache($path,$root=''){ - if(!$root){ - $root=OC_Filesystem::getRoot(); - } - if($root=='/'){ - $root=''; - } - $path=$root.$path; - return self::getFileId($path)!=-1; + public static function inCache($path,$root=false){ + return self::getId($path,$root)!=-1; } /** * get the file id as used in the cache - * unlike the public getId, full paths are used here (/usename/files/foo instead of /foo) - * @param string $path + * @param string path + * @param string root (optional) * @return int */ - private static function getFileId($path){ - $query=OC_DB::prepare('SELECT id FROM *PREFIX*fscache WHERE path_hash=?'); - if(OC_DB::isError($query)){ - OC_Log::write('files','error while getting file id of '.$path,OC_Log::ERROR); - return -1; + public static function getId($path,$root=false){ + if($root===false){ + $root=OC_Filesystem::getRoot(); } - $result=$query->execute(array(md5($path))); + + $query=OC_DB::prepare('SELECT id FROM *PREFIX*fscache WHERE path_hash=?'); + $result=$query->execute(array(md5($root.$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('files','getFileId(): file not found in cache ('.$path.')',OC_Log::DEBUG); return -1; } } - /** - * get the file id as used in the cache - * @param string path - * @param string root (optional) - * @return int - */ - public static function getId($path,$root=''){ - if(!$root){ - $root=OC_Filesystem::getRoot(); - } - if($root=='/'){ - $root=''; - } - $path=$root.$path; - return self::getFileId($path); - } - /** * get the file path from the id, relative to the home folder of the user * @param int id @@ -366,154 +289,23 @@ class OC_FileCache{ if($path=='/'){ return -1; }else{ - return self::getFileId(dirname($path)); - } - } - - /** - * called when changes are made to files - * @param array $params - * @param string root (optional) - */ - public static function fileSystemWatcherWrite($params,$root=''){ - if(!$root){ - $view=OC_Filesystem::getView(); - }else{ - $view=new OC_FilesystemView(($root=='/')?'':$root); - } - - $path=$params['path']; - $fullPath=$view->getRoot().$path; - $mimetype=$view->getMimeType($path); - $dir=$view->is_dir($path.'/'); - //dont use self::get here, we don't want inifinte loops when a file has changed - $cachedSize=self::getCachedSize($path,$root); - $size=0; - if($dir){ - if(self::inCache($path,$root)){ - $parent=self::getFileId($fullPath); - $query=OC_DB::prepare('SELECT size FROM *PREFIX*fscache WHERE parent=?'); - $result=$query->execute(array($parent)); - while($row=$result->fetchRow()){ - $size+=$row['size']; - } - $mtime=$view->filemtime($path); - $ctime=$view->filectime($path); - $writable=$view->is_writable($path); - self::put($path,array('size'=>$size,'mtime'=>$mtime,'ctime'=>$ctime,'mimetype'=>$mimetype,'writable'=>$writable)); - }else{ - $count=0; - self::scan($path,null,$count,$root); - } - }else{ - $size=self::scanFile($path,$root); - } - self::increaseSize(dirname($fullPath),$size-$cachedSize); - } - - public static function getCached($path,$root=''){ - if(!$root){ - $root=OC_Filesystem::getRoot(); - }else{ - if($root=='/'){ - $root=''; - } - } - $path=$root.$path; - $query=OC_DB::prepare('SELECT ctime,mtime,mimetype,size,encrypted,versioned,writable FROM *PREFIX*fscache WHERE path_hash=?'); - $result=$query->execute(array(md5($path)))->fetchRow(); - if(is_array($result)){ - if(isset(self::$savedData[$path])){ - $result=array_merge($result,self::$savedData[$path]); - } - return $result; - }else{ - OC_Log::write('files','getCached(): file not found in cache ('.$path.')',OC_Log::DEBUG); - if(isset(self::$savedData[$path])){ - return self::$savedData[$path]; - }else{ - return array(); - } + return self::getId(dirname($path),''); } } - private static function getCachedSize($path,$root){ - if(!$root){ - $root=OC_Filesystem::getRoot(); - }else{ - if($root=='/'){ - $root=''; - } - } - $path=$root.$path; - $query=OC_DB::prepare('SELECT size FROM *PREFIX*fscache WHERE path_hash=?'); - $result=$query->execute(array(md5($path))); - if($row=$result->fetchRow()){ - return $row['size']; - }else{//file not in cache - return 0; - } - } - - /** - * called when files are deleted - * @param array $params - * @param string root (optional) - */ - public static function fileSystemWatcherDelete($params,$root=''){ - if(!$root){ - $root=OC_Filesystem::getRoot(); - } - if($root=='/'){ - $root=''; - } - $path=$params['path']; - $fullPath=$root.$path; - if(self::getFileId($fullPath)==-1){ - return; - } - $size=self::getCachedSize($path,$root); - self::increaseSize(dirname($fullPath),-$size); - self::delete($path); - } - - /** - * called when files are deleted - * @param array $params - * @param string root (optional) - */ - public static function fileSystemWatcherRename($params,$root=''){ - if(!$root){ - $root=OC_Filesystem::getRoot(); - } - if($root=='/'){ - $root=''; - } - $oldPath=$params['oldpath']; - $newPath=$params['newpath']; - $fullOldPath=$root.$oldPath; - $fullNewPath=$root.$newPath; - if(($id=self::getFileId($fullOldPath))!=-1){ - $oldSize=self::getCachedSize($oldPath,$root); - }else{ - return; - } - $size=OC_Filesystem::filesize($newPath); - self::increaseSize(dirname($fullOldPath),-$oldSize); - self::increaseSize(dirname($fullNewPath),$oldSize); - self::move($oldPath,$newPath); - } - /** * adjust the size of the parent folders * @param string $path * @param int $sizeDiff + * @param string root (optinal) */ - private static function increaseSize($path,$sizeDiff){ + public static function increaseSize($path,$sizeDiff, $root=false){ if($sizeDiff==0) return; - while(($id=self::getFileId($path))!=-1){//walk up the filetree increasing the size of all parent folders + $id=self::getId($path,''); + while($id!=-1){//walk up the filetree increasing the size of all parent folders $query=OC_DB::prepare('UPDATE *PREFIX*fscache SET size=size+? WHERE id=?'); $query->execute(array($sizeDiff,$id)); + $id=self::getParentId($path); $path=dirname($path); } } @@ -525,15 +317,15 @@ class OC_FileCache{ * @param int count (optional) * @param string root (optionak) */ - public static function scan($path,$eventSource=false,&$count=0,$root=''){ + public static function scan($path,$eventSource=false,&$count=0,$root=false){ if($eventSource){ $eventSource->send('scanning',array('file'=>$path,'count'=>$count)); } $lastSend=$count; - if(!$root){ + if($root===false){ $view=OC_Filesystem::getView(); }else{ - $view=new OC_FilesystemView(($root=='/')?'':$root); + $view=new OC_FilesystemView($root); } self::scanFile($path,$root); $dh=$view->opendir($path.'/'); @@ -555,8 +347,9 @@ class OC_FileCache{ } } } - self::cleanFolder($path,$root); - self::increaseSize($view->getRoot().$path,$totalSize); + + OC_FileCache_Update::cleanFolder($path,$root); + self::increaseSize($path,$totalSize,$root); } /** @@ -565,11 +358,11 @@ class OC_FileCache{ * @param string root (optional) * @return int size of the scanned file */ - public static function scanFile($path,$root=''){ - if(!$root){ + public static function scanFile($path,$root=false){ + if($root===false){ $view=OC_Filesystem::getView(); }else{ - $view=new OC_FilesystemView(($root=='/')?'':$root); + $view=new OC_FilesystemView($root); } if(!$view->is_readable($path)) return; //cant read, nothing we can do clearstatcache(); @@ -602,11 +395,9 @@ class OC_FileCache{ * seccond mimetype part can be ommited * e.g. searchByMime('audio') */ - public static function searchByMime($part1,$part2=null,$root=null){ - if(!$root){ + public static function searchByMime($part1,$part2=null,$root=false){ + if($root===false){ $root=OC_Filesystem::getRoot(); - }elseif($root=='/'){ - $root=''; } $rootLen=strlen($root); $root .= '%'; @@ -625,103 +416,6 @@ class OC_FileCache{ return $names; } - /** - * check if a file or folder is updated outside owncloud - * @param string path - * @param string root (optional) - * @return bool - */ - public static function isUpdated($path,$root=''){ - if(!$root){ - $root=OC_Filesystem::getRoot(); - $view=OC_Filesystem::getView(); - }else{ - if($root=='/'){ - $root=''; - } - $view=new OC_FilesystemView($root); - } - if(!$view->file_exists($path)){ - return false; - } - $mtime=$view->filemtime($path); - $isDir=$view->is_dir($path); - $fullPath=$root.$path; - $query=OC_DB::prepare('SELECT mtime FROM *PREFIX*fscache WHERE path_hash=?'); - $result=$query->execute(array(md5($fullPath))); - if($row=$result->fetchRow()){ - $cachedMTime=$row['mtime']; - return ($mtime>$cachedMTime); - }else{//file not in cache, so it has to be updated - if($path=='/' or $path==''){//dont auto update the root folder, it will be scanned - return false; - } - return true; - } - } - - /** - * update the cache according to changes in the folder - * @param string path - * @param string root (optional) - */ - private static function updateFolder($path,$root=''){ - if(!$root){ - $view=OC_Filesystem::getView(); - }else{ - $view=new OC_FilesystemView(($root=='/')?'':$root); - } - $dh=$view->opendir($path.'/'); - if($dh){//check for changed/new files - while (($filename = readdir($dh)) !== false) { - if($filename != '.' and $filename != '..'){ - $file=$path.'/'.$filename; - if(self::isUpdated($file,$root)){ - if(!$root){//filesystem hooks are only valid for the default root - OC_Hook::emit('OC_Filesystem','post_write',array('path'=>$file)); - }else{ - self::fileSystemWatcherWrite(array('path'=>$file),$root); - } - } - } - } - } - - self::cleanFolder($path,$root); - - //update the folder last, so we can calculate the size correctly - if(!$root){//filesystem hooks are only valid for the default root - OC_Hook::emit('OC_Filesystem','post_write',array('path'=>$path)); - }else{ - self::fileSystemWatcherWrite(array('path'=>$path),$root); - } - } - - /** - * delete non existing files from the cache - */ - private static function cleanFolder($path,$root=''){ - if(!$root){ - $view=OC_Filesystem::getView(); - }else{ - $view=new OC_FilesystemView(($root=='/')?'':$root); - } - //check for removed files, not using getFolderContent to prevent loops - $parent=self::getFileId($view->getRoot().$path); - $query=OC_DB::prepare('SELECT name FROM *PREFIX*fscache WHERE parent=?'); - $result=$query->execute(array($parent)); - while($row=$result->fetchRow()){ - $file=$path.'/'.$row['name']; - if(!$view->file_exists($file)){ - if(!$root){//filesystem hooks are only valid for the default root - OC_Hook::emit('OC_Filesystem','post_delete',array('path'=>$file)); - }else{ - self::fileSystemWatcherDelete(array('path'=>$file),$root); - } - } - } - } - /** * clean old pre-path_hash entries */ @@ -732,6 +426,6 @@ class OC_FileCache{ } //watch for changes and try to keep the cache up to date -OC_Hook::connect('OC_Filesystem','post_write','OC_FileCache','fileSystemWatcherWrite'); -OC_Hook::connect('OC_Filesystem','post_delete','OC_FileCache','fileSystemWatcherDelete'); -OC_Hook::connect('OC_Filesystem','post_rename','OC_FileCache','fileSystemWatcherRename'); +OC_Hook::connect('OC_Filesystem','post_write','OC_FileCache_Update','fileSystemWatcherWrite'); +OC_Hook::connect('OC_Filesystem','post_delete','OC_FileCache_Update','fileSystemWatcherDelete'); +OC_Hook::connect('OC_Filesystem','post_rename','OC_FileCache_Update','fileSystemWatcherRename'); diff --git a/lib/filecache/cached.php b/lib/filecache/cached.php new file mode 100644 index 00000000000..a22adad4528 --- /dev/null +++ b/lib/filecache/cached.php @@ -0,0 +1,67 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + + +/** + * get data from the filecache without checking for updates + */ +class OC_FileCache_Cached{ + public static $savedData=array(); + + public static function get($path,$root=false){ + if($root===false){ + $root=OC_Filesystem::getRoot(); + } + $path=$root.$path; + $query=OC_DB::prepare('SELECT path,ctime,mtime,mimetype,size,encrypted,versioned,writable FROM *PREFIX*fscache WHERE path_hash=?'); + $result=$query->execute(array(md5($path)))->fetchRow(); + if(is_array($result)){ + if(isset(self::$savedData[$path])){ + $result=array_merge($result,self::$savedData[$path]); + } + return $result; + }else{ + if(isset(self::$savedData[$path])){ + return self::$savedData[$path]; + }else{ + return array(); + } + } + } + + /** + * get all files and folders in a folder + * @param string path + * @param string root (optional) + * @return array + * + * returns an array of assiciative arrays with the following keys: + * - path + * - name + * - size + * - mtime + * - ctime + * - mimetype + * - encrypted + * - versioned + */ + public static function getFolderContent($path,$root=false,$mimetype_filter=''){ + if($root===false){ + $root=OC_Filesystem::getRoot(); + } + $parent=OC_FileCache::getId($path,$root); + $query=OC_DB::prepare('SELECT path,name,ctime,mtime,mimetype,size,encrypted,versioned,writable FROM *PREFIX*fscache WHERE parent=? AND (mimetype LIKE ? OR mimetype = ?)'); + $result=$query->execute(array($parent, $mimetype_filter.'%', 'httpd/unix-directory'))->fetchAll(); + if(is_array($result)){ + return $result; + }else{ + OC_Log::write('files','getFolderContent(): file not found in cache ('.$path.')',OC_Log::DEBUG); + return false; + } + } +} \ No newline at end of file diff --git a/lib/filecache/update.php b/lib/filecache/update.php new file mode 100644 index 00000000000..9e23c6dfe7b --- /dev/null +++ b/lib/filecache/update.php @@ -0,0 +1,210 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + + +/** + * handles updating the filecache according to outside changes + */ +class OC_FileCache_Update{ + /** + * check if a file or folder is updated outside owncloud + * @param string path + * @param string root (optional) + * @return bool + */ + public static function hasUpdated($path,$root=false){ + if($root===false){ + $view=OC_Filesystem::getView(); + }else{ + $view=new OC_FilesystemView($root); + } + if(!$view->file_exists($path)){ + return false; + } + $cachedData=OC_FileCache_Cached::get($path,$root); + if(isset($cachedData['mtime'])){ + $cachedMTime=$cachedData['mtime']; + return $view->hasUpdated($path,$cachedMTime); + }else{//file not in cache, so it has to be updated + if(($path=='/' or $path=='') and $root===false){//dont auto update the home folder, it will be scanned + return false; + } + return true; + } + } + + /** + * delete non existing files from the cache + */ + public static function cleanFolder($path,$root=false){ + if($root===false){ + $view=OC_Filesystem::getView(); + }else{ + $view=new OC_FilesystemView($root); + } + + $cachedContent=OC_FileCache_Cached::getFolderContent($path,$root); + foreach($cachedContent as $fileData){ + $path=$fileData['path']; + $file=$view->getRelativePath($path); + if(!$view->file_exists($file)){ + if($root===false){//filesystem hooks are only valid for the default root + OC_Hook::emit('OC_Filesystem','post_delete',array('path'=>$file)); + }else{ + self::delete($file,$root); + } + } + } + } + + /** + * update the cache according to changes in the folder + * @param string path + * @param string root (optional) + */ + public static function updateFolder($path,$root=false){ + if($root===false){ + $view=OC_Filesystem::getView(); + }else{ + $view=new OC_FilesystemView($root); + } + $dh=$view->opendir($path.'/'); + if($dh){//check for changed/new files + while (($filename = readdir($dh)) !== false) { + if($filename != '.' and $filename != '..'){ + $file=$path.'/'.$filename; + if(self::hasUpdated($file,$root)){ + if($root===false){//filesystem hooks are only valid for the default root + OC_Hook::emit('OC_Filesystem','post_write',array('path'=>$file)); + }else{ + self::update($file,$root); + } + } + } + } + } + + self::cleanFolder($path,$root); + + //update the folder last, so we can calculate the size correctly + if($root===false){//filesystem hooks are only valid for the default root + OC_Hook::emit('OC_Filesystem','post_write',array('path'=>$path)); + }else{ + self::update($path,$root); + } + } + + /** + * called when changes are made to files + * @param array $params + * @param string root (optional) + */ + public static function fileSystemWatcherWrite($params){ + $path=$params['path']; + self::update($path); + } + + /** + * called when files are deleted + * @param array $params + * @param string root (optional) + */ + public static function fileSystemWatcherDelete($params){ + $path=$params['path']; + self::delete($path); + } + + /** + * called when files are deleted + * @param array $params + * @param string root (optional) + */ + public static function fileSystemWatcherRename($params){ + $oldPath=$params['oldpath']; + $newPath=$params['newpath']; + self::rename($oldPath,$newPath); + } + + /** + * update the filecache according to changes to the fileysystem + * @param string path + * @param string root (optional) + */ + public static function update($path,$root=false){ + if($root===false){ + $view=OC_Filesystem::getView(); + }else{ + $view=new OC_FilesystemView($root); + } + + $mimetype=$view->getMimeType($path); + + $size=0; + $cached=OC_FileCache_Cached::get($path,$root); + $cachedSize=isset($cached['size'])?$cached['size']:0; + + if($mimetype=='httpd/unix-directory'){ + if(OC_FileCache::inCache($path,$root)){ + $cachedContent=OC_FileCache_Cached::getFolderContent($path,$root); + foreach($cachedContent as $file){ + $size+=$file['size']; + } + $mtime=$view->filemtime($path); + $ctime=$view->filectime($path); + $writable=$view->is_writable($path); + OC_FileCache::put($path,array('size'=>$size,'mtime'=>$mtime,'ctime'=>$ctime,'mimetype'=>$mimetype,'writable'=>$writable)); + }else{ + $count=0; + OC_FileCache::scan($path,null,$count,$root); + return; //increaseSize is already called inside scan + } + }else{ + $size=OC_FileCache::scanFile($path,$root); + } + OC_FileCache::increaseSize(dirname($path),$size-$cachedSize,$root); + } + + /** + * update the filesystem after a delete has been detected + * @param string path + * @param string root (optional) + */ + public static function delete($path,$root=false){ + $cached=OC_FileCache_Cached::get($path,$root); + if(!isset($cached['size'])){ + return; + } + $size=$cached['size']; + OC_FileCache::increaseSize(dirname($path),-$size,$root); + OC_FileCache::delete($path,$root); + } + + /** + * update the filesystem after a rename has been detected + * @param string oldPath + * @param string newPath + * @param string root (optional) + */ + public static function rename($oldPath,$newPath,$root=false){ + if(!OC_FileCache::inCache($oldPath,$root)){ + return; + } + if($root===false){ + $view=OC_Filesystem::getView(); + }else{ + $view=new OC_FilesystemView($root); + } + + $cached=OC_FileCache_Cached::get($oldPath,$root); + $oldSize=$cached['size']; + $size=$view->filesize($newPath); + OC_FileCache::increaseSize(dirname($oldPath),-$oldSize,$root); + OC_FileCache::increaseSize(dirname($newPath),$oldSize,$root); + OC_FileCache::move($oldPath,$newPath); + } +} \ No newline at end of file diff --git a/lib/fileproxy/quota.php b/lib/fileproxy/quota.php index 9e4c2d0643e..f061d48219b 100644 --- a/lib/fileproxy/quota.php +++ b/lib/fileproxy/quota.php @@ -54,8 +54,8 @@ class OC_FileProxy_Quota extends OC_FileProxy{ * @return int */ private function getFreeSpace(){ - $rootInfo=OC_FileCache::get(''); - $usedSpace=$rootInfo['size']; + $rootInfo=OC_FileCache_Cached::get(''); + $usedSpace=isset($rootInfo['size'])?$rootInfo['size']:0; $totalSpace=$this->getQuota(); if($totalSpace==0){ return 0; diff --git a/lib/files.php b/lib/files.php index 705b7a6ca66..3ecf08739b0 100644 --- a/lib/files.php +++ b/lib/files.php @@ -36,7 +36,7 @@ class OC_Files { if(strpos($directory,OC::$CONFIG_DATADIRECTORY)===0){ $directory=substr($directory,strlen(OC::$CONFIG_DATADIRECTORY)); } - $files=OC_FileCache::getFolderContent($directory, '', $mimetype_filter); + $files=OC_FileCache::getFolderContent($directory, false, $mimetype_filter); foreach($files as &$file){ $file['directory']=$directory; $file['type']=($file['mimetype']=='httpd/unix-directory')?'dir':'file'; -- cgit v1.2.3 From 27efdbd58f284c054ae9150ff2a2b0dcb5fab70f Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 15 Jun 2012 17:04:37 +0200 Subject: Use setter for FileinfoCache --- lib/connector/sabre/directory.php | 10 ++++------ lib/connector/sabre/node.php | 12 +++++++----- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php index 5aa70392d76..6af4dd36562 100644 --- a/lib/connector/sabre/directory.php +++ b/lib/connector/sabre/directory.php @@ -69,15 +69,13 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa if (!$info) throw new Sabre_DAV_Exception_NotFound('File with name ' . $path . ' could not be located'); if ($info['mimetype'] == 'httpd/unix-directory') { - - return new OC_Connector_Sabre_Directory($path, $info); - + $node = new OC_Connector_Sabre_Directory($path); } else { - - return new OC_Connector_Sabre_File($path, $info); - + $node = new OC_Connector_Sabre_File($path); } + $node->setFileinfoCache($info); + return $node; } /** diff --git a/lib/connector/sabre/node.php b/lib/connector/sabre/node.php index e5c059f0c8a..8a860242f28 100644 --- a/lib/connector/sabre/node.php +++ b/lib/connector/sabre/node.php @@ -41,11 +41,8 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr * @param string $path * @return void */ - public function __construct($path, $fileinfo_cache = null) { + public function __construct($path) { $this->path = $path; - if ($fileinfo_cache) { - $this->fileinfo_cache = $fileinfo_cache; - } } @@ -85,8 +82,13 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr } + public function setFileinfoCache($fileinfo_cache) + { + $this->fileinfo_cache = $fileinfo_cache; + } + /** - * Set the stat cache + * Make sure the fileinfo cache is filled. Uses OC_FileCache or a direct stat */ protected function getFileinfoCache() { if (!isset($this->fileinfo_cache)) { -- cgit v1.2.3 From 463a506fcb2ec9c5e219434654ec5c5e0d8f834b Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 15 Jun 2012 17:05:10 +0200 Subject: Fix webdav property name compare --- lib/connector/sabre/node.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/connector/sabre/node.php b/lib/connector/sabre/node.php index 8a860242f28..7a9d8198ae8 100644 --- a/lib/connector/sabre/node.php +++ b/lib/connector/sabre/node.php @@ -139,7 +139,7 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr } } else { - if( strcmp( $propertyName, "lastmodified")) { + if( strcmp( $propertyName, "lastmodified") === 0) { $this->touch($propertyValue); } else { if(!array_key_exists( $propertyName, $existing )){ -- cgit v1.2.3 From e905b14758d18c5254ecf2fbe8e867ea96293877 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 15 Jun 2012 17:05:27 +0200 Subject: Spelling fix --- lib/filecache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/filecache.php b/lib/filecache.php index 7c9c4dc41ff..32c6929ff60 100644 --- a/lib/filecache.php +++ b/lib/filecache.php @@ -34,7 +34,7 @@ class OC_FileCache{ * @param string root (optional) * @return array * - * returns an assiciative array with the following keys: + * returns an associative array with the following keys: * - size * - mtime * - ctime -- cgit v1.2.3 From e11c5a23d52ba0bfe082f36311a504c72278aa40 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 15 Jun 2012 17:51:56 +0200 Subject: Optimize WebDav access by preloading dav custom properties --- lib/connector/sabre/directory.php | 22 ++++++++++++++++++++-- lib/connector/sabre/node.php | 30 +++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php index 6af4dd36562..9832449af3a 100644 --- a/lib/connector/sabre/directory.php +++ b/lib/connector/sabre/directory.php @@ -85,10 +85,28 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa */ public function getChildren() { - $nodes = array(); $folder_content = OC_FileCache::getFolderContent($this->path); + $paths = array(); + foreach($folder_content as $info) { + $paths[] = $this->path.'/'.$info['name']; + } + $placeholders = join(',', array_fill(0, count($paths), '?')); + $query = OC_DB::prepare( 'SELECT * FROM *PREFIX*properties WHERE userid = ?' . ' AND propertypath IN ('.$placeholders.')' ); + array_unshift($paths, OC_User::getUser()); // prepend userid + $result = $query->execute( $paths ); + $properties = array_fill_keys($paths, array()); + while($row = $result->fetchRow()) { + $propertypath = $row['propertypath']; + $propertyname = $row['propertyname']; + $propertyvalue = $row['propertyvalue']; + $properties[$propertypath][$propertyname] = $propertyvalue; + } + + $nodes = array(); foreach($folder_content as $info) { - $nodes[] = $this->getChild($info['name'], $info); + $node = $this->getChild($info['name'], $info); + $node->setPropertyCache($properties[$this->path.'/'.$info['name']]); + $nodes[] = $node; } return $nodes; } diff --git a/lib/connector/sabre/node.php b/lib/connector/sabre/node.php index 7a9d8198ae8..be315a0ffd9 100644 --- a/lib/connector/sabre/node.php +++ b/lib/connector/sabre/node.php @@ -30,10 +30,15 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr */ protected $path; /** - * file stat cache + * node fileinfo cache * @var array */ protected $fileinfo_cache; + /** + * node properties cache + * @var array + */ + protected $property_cache = null; /** * Sets up the node, expects a full path name @@ -101,6 +106,11 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr } } + public function setPropertyCache($property_cache) + { + $this->property_cache = $property_cache; + } + /** * Returns the last modification time, as a unix timestamp * @@ -153,6 +163,7 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr } } + $this->setPropertyCache(null); return true; } @@ -168,23 +179,24 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr * @return void */ function getProperties($properties) { - // At least some magic in here :-) - $query = OC_DB::prepare( 'SELECT * FROM *PREFIX*properties WHERE userid = ? AND propertypath = ?' ); - $result = $query->execute( array( OC_User::getUser(), $this->path )); + if (is_null($this->property_cache)) { + $query = OC_DB::prepare( 'SELECT * FROM *PREFIX*properties WHERE userid = ? AND propertypath = ?' ); + $result = $query->execute( array( OC_User::getUser(), $this->path )); - $existing = array(); - while( $row = $result->fetchRow()){ - $existing[$row['propertyname']] = $row['propertyvalue']; + $this->property_cache = array(); + while( $row = $result->fetchRow()){ + $this->property_cache[$row['propertyname']] = $row['propertyvalue']; + } } // if the array was empty, we need to return everything if(count($properties) == 0){ - return $existing; + return $this->property_cache; } $props = array(); foreach($properties as $property) { - if (isset($existing[$property])) $props[$property] = $existing[$property]; + if (isset($this->property_cache[$property])) $props[$property] = $this->property_cache[$property]; } return $props; } -- cgit v1.2.3 From 6d3ae575b6ed9934e37a884ea152008a29cbfc7b Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 15 Jun 2012 22:35:09 +0200 Subject: Remove $DOCUMENTROOT, not used --- apps/user_webfinger/webfinger.php | 7 ------- lib/base.php | 6 +----- 2 files changed, 1 insertion(+), 12 deletions(-) (limited to 'lib') diff --git a/apps/user_webfinger/webfinger.php b/apps/user_webfinger/webfinger.php index e75c546c2cb..39ab4ba6ba5 100644 --- a/apps/user_webfinger/webfinger.php +++ b/apps/user_webfinger/webfinger.php @@ -17,13 +17,6 @@ header("Content-Type: application/xrd+json"); * '* but can also use complex database queries to generate the webfinger result **/ -// calculate the documentroot -// modified version of the one in lib/base.php that takes the .well-known symlink into account -/*$DOCUMENTROOT=realpath($_SERVER['DOCUMENT_ROOT']); -$SERVERROOT=str_replace("\\",'/',dirname(dirname(dirname(dirname(__FILE__))))); -$SUBURI=substr(realpath($_SERVER["SCRIPT_FILENAME"]),strlen($SERVERROOT)); -$WEBROOT=substr($SUBURI,0,-34); -*/ $userName = ''; $hostName = ''; diff --git a/lib/base.php b/lib/base.php index f85710ddfcf..fedc1238851 100644 --- a/lib/base.php +++ b/lib/base.php @@ -121,8 +121,7 @@ class OC{ } public static function initPaths(){ - // calculate the documentroot - $DOCUMENTROOT=realpath($_SERVER['DOCUMENT_ROOT']); + // calculate the root directories OC::$SERVERROOT=str_replace("\\",'/',substr(__FILE__,0,-13)); OC::$SUBURI= str_replace("\\","/",substr(realpath($_SERVER["SCRIPT_FILENAME"]),strlen(OC::$SERVERROOT))); $scriptName=$_SERVER["SCRIPT_NAME"]; @@ -137,9 +136,6 @@ class OC{ } } OC::$WEBROOT=substr($scriptName,0,strlen($scriptName)-strlen(OC::$SUBURI)); - // try a new way to detect the WEBROOT which is simpler and also works with the app directory outside the owncloud folder. let´s see if this works for everybody -// OC::$WEBROOT=substr(OC::$SERVERROOT,strlen($DOCUMENTROOT)); - if(OC::$WEBROOT!='' and OC::$WEBROOT[0]!=='/'){ OC::$WEBROOT='/'.OC::$WEBROOT; -- cgit v1.2.3 From e37ef6dd473eaedcdf2814445ae12fb39786d585 Mon Sep 17 00:00:00 2001 From: Tom Needham Date: Fri, 15 Jun 2012 23:14:40 +0000 Subject: Move user import to personal settings. Fix user migration between servers. --- apps/user_migrate/admin.php | 87 -------------------------------- apps/user_migrate/settings.php | 66 ++++++++++++++++++++++-- apps/user_migrate/templates/admin.php | 13 ----- apps/user_migrate/templates/settings.php | 13 +++++ lib/migrate.php | 40 +++++---------- 5 files changed, 90 insertions(+), 129 deletions(-) delete mode 100644 apps/user_migrate/admin.php delete mode 100644 apps/user_migrate/templates/admin.php (limited to 'lib') diff --git a/apps/user_migrate/admin.php b/apps/user_migrate/admin.php deleted file mode 100644 index df8bff01c8d..00000000000 --- a/apps/user_migrate/admin.php +++ /dev/null @@ -1,87 +0,0 @@ -. - * - */ -OCP\User::checkAdminUser(); -OCP\App::checkAppEnabled('user_migrate'); - -// Import? -if (isset($_POST['user_import'])) { - - $root = OC::$SERVERROOT . "/"; - $importname = "owncloud_import_" . date("y-m-d_H-i-s"); - - // Save data dir for later - $datadir = OCP\Config::getSystemValue( 'datadirectory' ); - - // Copy the uploaded file - $from = $_FILES['owncloud_import']['tmp_name']; - $to = get_temp_dir().'/'.$importname.'.zip'; - if( !move_uploaded_file( $from, $to ) ){ - $error = array('error'=>'Failed to move the uploaded file','hint'=>'Try checking the permissions of the '.get_temp_dir().' dir.'); - OCP\Util::writeLog( 'user_migrate', "Failed to copy the uploaded file", OCP\Util::ERROR ); - $tmpl = new OCP\Template('user_migrate', 'admin'); - $tmpl->assign('error',$error); - return $tmpl->fetchPage(); - } - $response = json_decode( OC_Migrate::import( $to, 'user' ) ); - if( !$response->success ){ - $error = array('error'=>'There was an error while importing the user!','hint'=>'Please check the logs for a more detailed explaination'); - $tmpl = new OCP\Template('user_migrate', 'admin'); - $tmpl->assign('error',$error); - return $tmpl->fetchPage(); - } else { - // Check import status - foreach( $response->data as $app => $status ){ - if( $status != 'true' ){ - // It failed for some reason - if( $status == 'notsupported' ){ - $notsupported[] = $app; - } else if( !$status ){ - $failed[] = $app; - } - } - } - // Any problems? - if( isset( $notsupported ) || isset( $failed ) ){ - if( count( $failed ) > 0 ){ - $error = array('error'=>'Some app data failed to import','hint'=>'App data for: '.implode(', ', $failed).' failed to import.'); - $tmpl = new OCP\Template('user_migrate', 'admin'); - $tmpl->assign('error',$error); - return $tmpl->fetchPage(); - } else if( count( $notsupported ) > 0 ){ - $error = array('error'=>'Some app data could not be imported, as the apps are not installed on this instance','hint'=>'App data for: '.implode(', ', $notsupported).' failed to import as they were not found. Please install the apps and try again'); - $tmpl = new OCP\Template('user_migrate', 'admin'); - $tmpl->assign('error',$error); - return $tmpl->fetchPage(); - } - } else { - // Went swimmingly! - $tmpl = new OCP\Template('user_migrate', 'admin'); - return $tmpl->fetchPage(); - } - } - -} else { -// fill template - $tmpl = new OCP\Template('user_migrate', 'admin'); - return $tmpl->fetchPage(); -} diff --git a/apps/user_migrate/settings.php b/apps/user_migrate/settings.php index 8edd0353388..098927fa17d 100644 --- a/apps/user_migrate/settings.php +++ b/apps/user_migrate/settings.php @@ -23,7 +23,67 @@ * */ OCP\App::checkAppEnabled('user_migrate'); +if (isset($_POST['user_import'])) { + $root = OC::$SERVERROOT . "/"; + $importname = "owncloud_import_" . date("y-m-d_H-i-s"); + + // Save data dir for later + $datadir = OCP\Config::getSystemValue( 'datadirectory' ); + + // Copy the uploaded file + $from = $_FILES['owncloud_import']['tmp_name']; + $to = get_temp_dir().'/'.$importname.'.zip'; + if( !move_uploaded_file( $from, $to ) ){ -// fill template -$tmpl = new OCP\Template('user_migrate', 'settings'); -return $tmpl->fetchPage(); \ No newline at end of file + $error = array('error'=>'Failed to move the uploaded file','hint'=>'Try checking the permissions of the '.get_temp_dir().' dir.'); + OCP\Util::writeLog( 'user_migrate', "Failed to copy the uploaded file", OCP\Util::ERROR ); + $tmpl = new OCP\Template('user_migrate', 'settings'); + $tmpl->assign('error',$error); + //return $tmpl->fetchPage(); + } + + + $response = json_decode( OC_Migrate::import( $to, 'user' ) ); + if( !$response->success ){ + $error = array('error'=>'There was an error while importing the user!','hint'=>'Please check the logs for a more detailed explaination'); + $tmpl = new OCP\Template('user_migrate', 'settings'); + $tmpl->assign('error',$error); + //return $tmpl->fetchPage(); + } else { + // Check import status + foreach( $response->data as $app => $status ){ + if( $status != 'true' ){ + // It failed for some reason + if( $status == 'notsupported' ){ + $notsupported[] = $app; + } else if( !$status ){ + $failed[] = $app; + } + } + } + // Any problems? + if( isset( $notsupported ) || isset( $failed ) ){ + if( count( $failed ) > 0 ){ + $error = array('error'=>'Some app data failed to import','hint'=>'App data for: '.implode(', ', $failed).' failed to import.'); + $tmpl = new OCP\Template('user_migrate', 'settings'); + $tmpl->assign('error',$error); + //return $tmpl->fetchPage(); + } else if( count( $notsupported ) > 0 ){ + $error = array('error'=>'Some app data could not be imported, as the apps are not installed on this instance','hint'=>'App data for: '.implode(', ', $notsupported).' failed to import as they were not found. Please install the apps and try again'); + $tmpl = new OCP\Template('user_migrate', 'settings'); + $tmpl->assign('error',$error); + //return $tmpl->fetchPage(); + } + } else { + // Went swimmingly! + $tmpl = new OCP\Template('user_migrate', 'settings'); + //return $tmpl->fetchPage(); + } + + } + +} else { + // fill template + $tmpl = new OCP\Template('user_migrate', 'settings'); + return $tmpl->fetchPage(); +} \ No newline at end of file diff --git a/apps/user_migrate/templates/admin.php b/apps/user_migrate/templates/admin.php deleted file mode 100644 index ff51f43ffde..00000000000 --- a/apps/user_migrate/templates/admin.php +++ /dev/null @@ -1,13 +0,0 @@ -
-
- -

-

- - t('Import user account');?> -

-

-

- -
-
diff --git a/apps/user_migrate/templates/settings.php b/apps/user_migrate/templates/settings.php index 8f1fe41df01..1718abe9e0f 100644 --- a/apps/user_migrate/templates/settings.php +++ b/apps/user_migrate/templates/settings.php @@ -4,3 +4,16 @@

+
+
+ +

+

+ + t('Import user account');?> +

+

+

+ +
+
diff --git a/lib/migrate.php b/lib/migrate.php index f9cab915d04..5939ba32e50 100644 --- a/lib/migrate.php +++ b/lib/migrate.php @@ -196,7 +196,7 @@ class OC_Migrate{ * @param optional $uid userid of new user */ public static function import( $path, $type='user', $uid=null ){ - OC_Util::checkAdminUser(); + $datadir = OC_Config::getValue( 'datadirectory' ); // Extract the zip if( !$extractpath = self::extractZip( $path ) ){ @@ -216,12 +216,19 @@ class OC_Migrate{ } self::$exporttype = $type; + $currentuser = OC_User::getUser(); + // Have we got a user if type is user if( self::$exporttype == 'user' ){ - if( !$uid ){ - self::$uid = $json->exporteduser; - } else { - self::$uid = $uid; + self::$uid = !is_null($uid) ? $uid : $currentuser; + } + + // We need to be an admin if we are not importing our own data + if(($type == 'user' && self::$uid != $currentuser) || $type != 'user' ){ + if( !OC_Group::inGroup( OC_User::getUser(), 'admin' )){ + // Naughty. + OC_Log::write( 'migration', 'Import not permitted.', OC_Log::ERROR ); + return json_encode( array( 'success' => false ) ); } } @@ -229,27 +236,8 @@ class OC_Migrate{ switch( self::$exporttype ){ case 'user': // Check user availability - if( OC_User::userExists( self::$uid ) ){ - OC_Log::write( 'migration', 'User already exists', OC_Log::ERROR ); - return json_encode( array( 'success' => false ) ); - } - $run = true; - OC_Hook::emit( "OC_User", "pre_createUser", array( "run" => &$run, "uid" => self::$uid, "password" => $json->hash )); - if( !$run ){ - // Something stopped the user creation - OC_Log::write( 'migration', 'User creation failed', OC_Log::ERROR ); - return json_encode( array( 'success' => false ) ); - } - // Create the user - if( !self::createUser( self::$uid, $json->hash ) ){ - return json_encode( array( 'success' => false ) ); - } - // Emit the post_createUser hook (password is already hashed, will cause problems - OC_Hook::emit( "OC_User", "post_createUser", array( "uid" => self::$uid, "password" => $json->hash )); - // Make the new users data dir - $path = $datadir . '/' . self::$uid; - if( !mkdir( $path, 0755, true ) ){ - OC_Log::write( 'migration', 'Failed to create users data dir: '.$path, OC_Log::ERROR ); + if( !OC_User::userExists( self::$uid ) ){ + OC_Log::write( 'migration', 'User doesn\'t exist', OC_Log::ERROR ); return json_encode( array( 'success' => false ) ); } // Copy data -- cgit v1.2.3 From 709dbd82a60363555b613b381f73d942f9fdbcc4 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Sat, 16 Jun 2012 16:58:55 +0200 Subject: Set default charset to utf-8. --- lib/db.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/db.php b/lib/db.php index bcc8657b4a4..a0ad499b601 100644 --- a/lib/db.php +++ b/lib/db.php @@ -120,7 +120,7 @@ class OC_DB { }else{ $dsn='mysql:dbname='.$name.';host='.$host; } - $opts[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES 'UTF8'"; + $opts[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES 'UTF8'; SET CHARACTER SET 'UTF8';"; break; case 'pgsql': if($port){ -- cgit v1.2.3 From 6e9cd63fa1af24781c981c5535876f22fdb17934 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sat, 16 Jun 2012 20:50:52 +0200 Subject: Only check for apps owncloud version requirment when there is a new owncloud version --- lib/app.php | 29 +++++++++++++++-------------- lib/base.php | 1 + 2 files changed, 16 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/app.php b/lib/app.php index 7fdfc93138f..c08e977b032 100755 --- a/lib/app.php +++ b/lib/app.php @@ -489,32 +489,33 @@ class OC_App{ $currentVersion=OC_App::getAppVersion($app); if ($currentVersion) { if (version_compare($currentVersion, $installedVersion, '>')) { - OC_Log::write($app,'starting app upgrade from '.$installedVersion.' to '.$currentVersion,OC_Log::DEBUG); + OC_Log::write($app, 'starting app upgrade from '.$installedVersion.' to '.$currentVersion,OC_Log::DEBUG); OC_App::updateApp($app); - OC_Appconfig::setValue($app,'installed_version',OC_App::getAppVersion($app)); + OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app)); } } } + } - // check if the current enabled apps are compatible with the current ownCloud version. disable them if not. - // this is important if you upgrade ownCloud and have non ported 3rd party apps installed - $apps =OC_App::getEnabledApps(); - $version=OC_Util::getVersion(); + /** + * check if the current enabled apps are compatible with the current + * ownCloud version. disable them if not. + * This is important if you upgrade ownCloud and have non ported 3rd + * party apps installed. + */ + public static function checkAppsRequirements($apps = array()){ + if (empty($apps)) { + $apps = OC_App::getEnabledApps(); + } + $version = OC_Util::getVersion(); foreach($apps as $app) { - // check if the app is compatible with this version of ownCloud - $info=OC_App::getAppInfo($app); + $info = OC_App::getAppInfo($app); if(!isset($info['require']) or ($version[0]>$info['require'])){ OC_Log::write('core','App "'.$info['name'].'" can\'t be used because it is not compatible with this version of ownCloud',OC_Log::ERROR); OC_App::disable( $app ); } - - - } - - - } /** diff --git a/lib/base.php b/lib/base.php index fedc1238851..30f7e5bba63 100644 --- a/lib/base.php +++ b/lib/base.php @@ -229,6 +229,7 @@ class OC{ } OC_Config::setValue('version',implode('.',OC_Util::getVersion())); + OC_App::checkAppsRequirements(); } OC_App::updateApps(); -- cgit v1.2.3 From 6f93176a4be21dcda1009d9cea052e5fdb50ae16 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sat, 16 Jun 2012 20:52:01 +0200 Subject: Be smarter when checking single app language availability --- lib/l10n.php | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/l10n.php b/lib/l10n.php index 3596c992bae..ba4bf23780e 100644 --- a/lib/l10n.php +++ b/lib/l10n.php @@ -228,23 +228,29 @@ class OC_L10N{ return self::$language; } - $available = array(); - if(is_array($app)){ - $available = $app; - } - else{ - $available=self::findAvailableLanguages($app); - } if(OC_User::getUser() && OC_Preferences::getValue(OC_User::getUser(), 'core', 'lang')){ $lang = OC_Preferences::getValue(OC_User::getUser(), 'core', 'lang'); self::$language = $lang; - if(array_search($lang, $available) !== false){ + if(is_array($app)){ + $available = $app; + $lang_exists = array_search($lang, $available) !== false; + } + else { + $lang_exists = self::languageExists($app, $lang); + } + if($lang_exists){ return $lang; } } if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){ $accepted_languages = preg_split('/,\s*/', $_SERVER['HTTP_ACCEPT_LANGUAGE']); + if(is_array($app)){ + $available = $app; + } + else{ + $available = self::findAvailableLanguages($app); + } foreach($accepted_languages as $i){ $temp = explode(';', $i); if(array_search($temp[0], $available) !== false){ @@ -296,4 +302,15 @@ class OC_L10N{ } return $available; } + + public static function languageExists($app, $lang){ + if ($lang == 'en'){//english is always available + return true; + } + $dir = self::findI18nDir($app); + if(is_dir($dir)){ + return file_exists($dir.'/'.$lang.'.php'); + } + return false; + } } -- cgit v1.2.3 From b38e46276f247315772c5d46f0c73ea11a139cef Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 17 Jun 2012 01:26:30 +0200 Subject: when checking if the content of a folder has been updated, exlicitly state that we are checking a folder solves some issues with external storages not updating correctly --- lib/filecache.php | 2 +- lib/filecache/update.php | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/filecache.php b/lib/filecache.php index 32c6929ff60..9963a5a3baf 100644 --- a/lib/filecache.php +++ b/lib/filecache.php @@ -217,7 +217,7 @@ class OC_FileCache{ * - versioned */ public static function getFolderContent($path,$root=false,$mimetype_filter=''){ - if(OC_FileCache_Update::hasUpdated($path,$root)){ + if(OC_FileCache_Update::hasUpdated($path,$root,true)){ OC_FileCache_Update::updateFolder($path,$root); } return OC_FileCache_Cached::getFolderContent($path,$root,$mimetype_filter); diff --git a/lib/filecache/update.php b/lib/filecache/update.php index 9e23c6dfe7b..2e3eb67da08 100644 --- a/lib/filecache/update.php +++ b/lib/filecache/update.php @@ -15,9 +15,10 @@ class OC_FileCache_Update{ * check if a file or folder is updated outside owncloud * @param string path * @param string root (optional) + * @param boolean folder * @return bool */ - public static function hasUpdated($path,$root=false){ + public static function hasUpdated($path,$root=false,$folder=false){ if($root===false){ $view=OC_Filesystem::getView(); }else{ @@ -29,7 +30,11 @@ class OC_FileCache_Update{ $cachedData=OC_FileCache_Cached::get($path,$root); if(isset($cachedData['mtime'])){ $cachedMTime=$cachedData['mtime']; - return $view->hasUpdated($path,$cachedMTime); + if($folder){ + return $view->hasUpdated($path.'/',$cachedMTime); + }else{ + return $view->hasUpdated($path,$cachedMTime); + } }else{//file not in cache, so it has to be updated if(($path=='/' or $path=='') and $root===false){//dont auto update the home folder, it will be scanned return false; -- cgit v1.2.3 From e8dd86ce0de9ec0d7c1774c62281451445b26c92 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sat, 16 Jun 2012 19:48:03 -0400 Subject: Revert "Set default charset to utf-8." This reverts commit 709dbd82a60363555b613b381f73d942f9fdbcc4. --- lib/db.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/db.php b/lib/db.php index a0ad499b601..bcc8657b4a4 100644 --- a/lib/db.php +++ b/lib/db.php @@ -120,7 +120,7 @@ class OC_DB { }else{ $dsn='mysql:dbname='.$name.';host='.$host; } - $opts[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES 'UTF8'; SET CHARACTER SET 'UTF8';"; + $opts[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES 'UTF8'"; break; case 'pgsql': if($port){ -- cgit v1.2.3 From 549541215e41cc42d94ae92f72df423fce1e5a1c Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 17 Jun 2012 02:15:11 +0200 Subject: get the correct metadate from updated folders to put in the cache --- lib/filecache/update.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/filecache/update.php b/lib/filecache/update.php index 2e3eb67da08..dd77f491ca0 100644 --- a/lib/filecache/update.php +++ b/lib/filecache/update.php @@ -159,9 +159,9 @@ class OC_FileCache_Update{ foreach($cachedContent as $file){ $size+=$file['size']; } - $mtime=$view->filemtime($path); - $ctime=$view->filectime($path); - $writable=$view->is_writable($path); + $mtime=$view->filemtime($path.'/'); + $ctime=$view->filectime($path.'/'); + $writable=$view->is_writable($path.'/'); OC_FileCache::put($path,array('size'=>$size,'mtime'=>$mtime,'ctime'=>$ctime,'mimetype'=>$mimetype,'writable'=>$writable)); }else{ $count=0; -- cgit v1.2.3 From 617de811f786dd9282ad52c062a58072027f5637 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 15 Jun 2012 12:07:31 +0200 Subject: Cache the minimized output also on the server --- core/minimizer.php | 4 ++-- lib/minimizer.php | 22 +++++++++++++++++++--- lib/request.php | 25 +++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 lib/request.php (limited to 'lib') diff --git a/core/minimizer.php b/core/minimizer.php index 709c7508e90..47e3d855e7b 100644 --- a/core/minimizer.php +++ b/core/minimizer.php @@ -6,10 +6,10 @@ OC_App::loadApps(); if ($service == 'core.css'){ $minimizer = new OC_Minimizer_CSS(); $files = $minimizer->findFiles(OC_Util::$core_styles); - $minimizer->output($files); + $minimizer->output($files, $service); } else if ($service == 'core.js'){ $minimizer = new OC_Minimizer_JS(); $files = $minimizer->findFiles(OC_Util::$core_scripts); - $minimizer->output($files); + $minimizer->output($files, $service); } diff --git a/lib/minimizer.php b/lib/minimizer.php index 9f9ef086c4a..428fa477f77 100644 --- a/lib/minimizer.php +++ b/lib/minimizer.php @@ -26,14 +26,30 @@ abstract class OC_Minimizer abstract public function minimizeFiles($files); - public function output($files) { + public function output($files, $cache_key) { header('Content-Type: '.$this->contentType); OC_Response::enableCaching(); $last_modified = $this->getLastModified($files); OC_Response::setLastModifiedHeader($last_modified); - $out = $this->minimizeFiles($files); - OC_Response::setETagHeader(md5($out)); + $gzout = false; + $cache = new OC_Cache_FileGlobal(); + if (!OC_Request::isNoCache() && (!defined('DEBUG') || !DEBUG)){ + $gzout = $cache->get($cache_key.'.gz'); + OC_Response::setETagHeader(md5($gzout)); + } + + if (!$gzout) { + $out = $this->minimizeFiles($files); + $gzout = gzencode($out); + $cache->set($cache_key.'.gz', $gzout); + } + if ($encoding = OC_Request::acceptGZip()) { + header('Content-Encoding: '.$encoding); + $out = $gzout; + } else { + $out = gzdecode($gzout); + } header('Content-Length: '.strlen($out)); echo $out; } diff --git a/lib/request.php b/lib/request.php new file mode 100644 index 00000000000..d152d0c73ba --- /dev/null +++ b/lib/request.php @@ -0,0 +1,25 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +class OC_Request { + static public function isNoCache() { + if (!isset($_SERVER['HTTP_CACHE_CONTROL'])) { + return false; + } + return $_SERVER['HTTP_CACHE_CONTROL'] == 'no-cache'; + } + + static public function acceptGZip() { + $HTTP_ACCEPT_ENCODING = $_SERVER["HTTP_ACCEPT_ENCODING"]; + if( strpos($HTTP_ACCEPT_ENCODING, 'x-gzip') !== false ) + return 'x-gzip'; + else if( strpos($HTTP_ACCEPT_ENCODING,'gzip') !== false ) + return 'gzip'; + return false; + } +} -- cgit v1.2.3 From a5a1a9fd4a2f1cd5f2457ba3ab0ceb432da1be33 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 18 Jun 2012 11:12:53 +0200 Subject: Forgot a file --- lib/cache/fileglobal.php | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 lib/cache/fileglobal.php (limited to 'lib') diff --git a/lib/cache/fileglobal.php b/lib/cache/fileglobal.php new file mode 100644 index 00000000000..469dd4b6dd4 --- /dev/null +++ b/lib/cache/fileglobal.php @@ -0,0 +1,70 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + + +class OC_Cache_FileGlobal{ + protected function getCacheDir() { + $cache_dir = get_temp_dir().'/owncloud-'.OC_Util::getInstanceId().'/'; + if (!is_dir($cache_dir)) { + mkdir($cache_dir); + } + return $cache_dir; + } + + public function get($key) { + if ($this->hasKey($key)) { + $cache_dir = $this->getCacheDir(); + return file_get_contents($cache_dir.$key); + } + return null; + } + + public function set($key, $value, $ttl=0) { + $cache_dir = $this->getCacheDir(); + if ($cache_dir and file_put_contents($cache_dir.$key, $value)) { + if ($ttl === 0) { + $ttl = 86400; // 60*60*24 + } + return touch($cache_dir.$key, time() + $ttl); + } + return false; + } + + public function hasKey($key) { + $cache_dir = $this->getCacheDir(); + if ($cache_dir && is_file($cache_dir.$key)) { + $mtime = filemtime($cache_dir.$key); + if ($mtime < time()) { + unlink($cache_dir.$key); + return false; + } + return true; + } + return false; + } + + public function remove($key) { + $cache_dir = $this->getCacheDir(); + if(!$cache_dir){ + return false; + } + return unlink($cache_dir.$key); + } + + public function clear(){ + $cache_dir = $this->getCacheDir(); + if($cache_dir and is_dir($cache_dir)){ + $dh=opendir($cache_dir); + while($file=readdir($dh)){ + if($file!='.' and $file!='..'){ + unlink($cache_dir.$file); + } + } + } + } +} -- cgit v1.2.3 From 977cd0df6b502c1a15147c1641fea754128a0875 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 18 Jun 2012 11:33:24 +0200 Subject: Fix errors for minimizer --- lib/base.php | 2 +- lib/cache/fileglobal.php | 8 ++++++++ lib/request.php | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/base.php b/lib/base.php index 30f7e5bba63..94ae26c4d1b 100644 --- a/lib/base.php +++ b/lib/base.php @@ -282,7 +282,7 @@ class OC{ if(substr(OC::$REQUESTEDFILE, -3) == 'css'){ $file = 'apps/' . OC::$REQUESTEDAPP . '/' . OC::$REQUESTEDFILE; $minimizer = new OC_Minimizer_CSS(); - $minimizer->output(array(array(OC::$APPSROOT, OC::$APPSWEBROOT, $file))); + $minimizer->output(array(array(OC::$APPSROOT, OC::$APPSWEBROOT, $file)), $file); exit; }elseif(substr(OC::$REQUESTEDFILE, -3) == 'php'){ require_once(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/' . OC::$REQUESTEDFILE); diff --git a/lib/cache/fileglobal.php b/lib/cache/fileglobal.php index 469dd4b6dd4..1c2c9bdc82d 100644 --- a/lib/cache/fileglobal.php +++ b/lib/cache/fileglobal.php @@ -16,7 +16,12 @@ class OC_Cache_FileGlobal{ return $cache_dir; } + protected function fixKey($key) { + return str_replace('/', '_', $key); + } + public function get($key) { + $key = $this->fixKey($key); if ($this->hasKey($key)) { $cache_dir = $this->getCacheDir(); return file_get_contents($cache_dir.$key); @@ -25,6 +30,7 @@ class OC_Cache_FileGlobal{ } public function set($key, $value, $ttl=0) { + $key = $this->fixKey($key); $cache_dir = $this->getCacheDir(); if ($cache_dir and file_put_contents($cache_dir.$key, $value)) { if ($ttl === 0) { @@ -36,6 +42,7 @@ class OC_Cache_FileGlobal{ } public function hasKey($key) { + $key = $this->fixKey($key); $cache_dir = $this->getCacheDir(); if ($cache_dir && is_file($cache_dir.$key)) { $mtime = filemtime($cache_dir.$key); @@ -53,6 +60,7 @@ class OC_Cache_FileGlobal{ if(!$cache_dir){ return false; } + $key = $this->fixKey($key); return unlink($cache_dir.$key); } diff --git a/lib/request.php b/lib/request.php index d152d0c73ba..0b5aaf8ef30 100644 --- a/lib/request.php +++ b/lib/request.php @@ -15,6 +15,9 @@ class OC_Request { } static public function acceptGZip() { + if (!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) { + return false; + } $HTTP_ACCEPT_ENCODING = $_SERVER["HTTP_ACCEPT_ENCODING"]; if( strpos($HTTP_ACCEPT_ENCODING, 'x-gzip') !== false ) return 'x-gzip'; -- cgit v1.2.3 From 332603a2637ec46984f0622ee9a930a84a1c367d Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 18 Jun 2012 12:57:11 +0200 Subject: Move formfactor code to OC_Template --- lib/base.php | 34 ---------------------------------- lib/template.php | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 34 deletions(-) (limited to 'lib') diff --git a/lib/base.php b/lib/base.php index 94ae26c4d1b..db55504117d 100644 --- a/lib/base.php +++ b/lib/base.php @@ -95,31 +95,6 @@ class OC{ } } - /** - * autodetects the formfactor of the used device - * default -> the normal desktop browser interface - * mobile -> interface for smartphones - * tablet -> interface for tablets - * standalone -> the default interface but without header, footer and sidebar. just the application. useful to ue just a specific app on the desktop in a standalone window. - */ - public static function detectFormfactor(){ - // please add more useragent strings for other devices - if(isset($_SERVER['HTTP_USER_AGENT'])){ - if(stripos($_SERVER['HTTP_USER_AGENT'],'ipad')>0) { - $mode='tablet'; - }elseif(stripos($_SERVER['HTTP_USER_AGENT'],'iphone')>0){ - $mode='mobile'; - }elseif((stripos($_SERVER['HTTP_USER_AGENT'],'N9')>0) and (stripos($_SERVER['HTTP_USER_AGENT'],'nokia')>0)){ - $mode='mobile'; - }else{ - $mode='default'; - } - }else{ - $mode='default'; - } - return($mode); - } - public static function initPaths(){ // calculate the root directories OC::$SERVERROOT=str_replace("\\",'/',substr(__FILE__,0,-13)); @@ -237,15 +212,6 @@ class OC{ } public static function initTemplateEngine() { - // if the formfactor is not yet autodetected do the autodetection now. For possible forfactors check the detectFormfactor documentation - if(!isset($_SESSION['formfactor'])){ - $_SESSION['formfactor']=OC::detectFormfactor(); - } - // allow manual override via GET parameter - if(isset($_GET['formfactor'])){ - $_SESSION['formfactor']=$_GET['formfactor']; - } - // Add the stuff we need always OC_Util::addScript( "jquery-1.7.2.min" ); OC_Util::addScript( "jquery-ui-1.8.16.custom.min" ); diff --git a/lib/template.php b/lib/template.php index a3700e133e7..7e2e1d4d526 100644 --- a/lib/template.php +++ b/lib/template.php @@ -166,11 +166,48 @@ class OC_Template{ $this->findTemplate($name); } + /** + * autodetects the formfactor of the used device + * default -> the normal desktop browser interface + * mobile -> interface for smartphones + * tablet -> interface for tablets + * standalone -> the default interface but without header, footer and + * sidebar, just the application. Useful to use just a specific + * app on the desktop in a standalone window. + */ + public static function detectFormfactor(){ + // please add more useragent strings for other devices + if(isset($_SERVER['HTTP_USER_AGENT'])){ + if(stripos($_SERVER['HTTP_USER_AGENT'],'ipad')>0) { + $mode='tablet'; + }elseif(stripos($_SERVER['HTTP_USER_AGENT'],'iphone')>0){ + $mode='mobile'; + }elseif((stripos($_SERVER['HTTP_USER_AGENT'],'N9')>0) and (stripos($_SERVER['HTTP_USER_AGENT'],'nokia')>0)){ + $mode='mobile'; + }else{ + $mode='default'; + } + }else{ + $mode='default'; + } + return($mode); + } + /** * @brief Returns the formfactor extension for current formfactor */ static public function getFormFactorExtension() { + // if the formfactor is not yet autodetected do the + // autodetection now. For possible formfactors check the + // detectFormfactor documentation + if(!isset($_SESSION['formfactor'])){ + $_SESSION['formfactor'] = self::detectFormfactor(); + } + // allow manual override via GET parameter + if(isset($_GET['formfactor'])){ + $_SESSION['formfactor']=$_GET['formfactor']; + } $formfactor=$_SESSION['formfactor']; if($formfactor=='default') { $fext=''; -- cgit v1.2.3 From 180243d92a6e1261092c6262f02b20b2f3785ba7 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 18 Jun 2012 15:04:35 +0200 Subject: Move page layout handling to its own class --- lib/template.php | 130 +------------------------------------ lib/templatelayout.php | 170 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 173 insertions(+), 127 deletions(-) create mode 100644 lib/templatelayout.php (limited to 'lib') diff --git a/lib/template.php b/lib/template.php index 7e2e1d4d526..a5d10c45d23 100644 --- a/lib/template.php +++ b/lib/template.php @@ -307,7 +307,7 @@ class OC_Template{ * * If the key existed before, it will be overwritten */ - public function assign( $key, $value, $sanitizeHTML=true ){ + public function assign( $key, $value, $sanitizeHTML=true ){ if($sanitizeHTML == true) { if(is_array($value)) { array_walk_recursive($value,'OC_Template::sanitizeHTML'); @@ -376,29 +376,6 @@ class OC_Template{ } } - /* - * @brief append the $file-url if exist at $root - * @param $type of collection to use when appending - * @param $root path to check - * @param $web base for path - * @param $file the filename - */ - public function appendIfExist($type, $root, $web, $file) { - if (is_file($root.'/'.$file)) { - $pathes = explode('/', $file); - if($type == 'cssfiles' && $root == OC::$APPSROOT && $pathes[0] == 'apps'){ - $app = $pathes[1]; - unset($pathes[0]); - unset($pathes[1]); - $path = implode('/', $pathes); - $this->append( $type, OC_Helper::linkTo($app, $path)); - }else{ - $this->append( $type, $web.'/'.$file); - } - return true; - } - return false; - } /** * @brief Proceeds the template * @returns content @@ -410,109 +387,9 @@ class OC_Template{ $data = $this->_fetch(); if( $this->renderas ){ - // Decide which page we show - if( $this->renderas == "user" ){ - $page = new OC_Template( "core", "layout.user" ); - $page->assign('searchurl',OC_Helper::linkTo( 'search', 'index.php' ), false); + $page = new OC_TemplateLayout($this->renderas); + if($this->renderas == 'user') { $page->assign('requesttoken', $this->vars['requesttoken']); - if(array_search(OC_APP::getCurrentApp(),array('settings','admin','help'))!==false){ - $page->assign('bodyid','body-settings', false); - }else{ - $page->assign('bodyid','body-user', false); - } - - // Add navigation entry - $navigation = OC_App::getNavigation(); - $page->assign( "navigation", $navigation, false); - $page->assign( "settingsnavigation", OC_App::getSettingsNavigation(), false); - foreach($navigation as $entry) { - if ($entry['active']) { - $page->assign( 'application', $entry['name'], false ); - break; - } - } - }else{ - $page = new OC_Template( "core", "layout.guest" ); - } - - // Read the selected theme from the config file - $theme=OC_Config::getValue( "theme" ); - - // Read the detected formfactor and use the right file name. - $fext = self::getFormFactorExtension(); - - $page->assign('jsfiles', array(), false); - // Add the core js files or the js files provided by the selected theme - foreach(OC_Util::$scripts as $script){ - // Is it in 3rd party? - if($page->appendIfExist('jsfiles', OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $script.'.js')) { - - // Is it in apps and overwritten by the theme? - }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script$fext.js" )) { - }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script.js" )) { - - // Is it part of an app? - }elseif($page->appendIfExist('jsfiles', OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script$fext.js" )) { - }elseif($page->appendIfExist('jsfiles', OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script.js" )) { - - // Is it in the owncloud root but overwritten by the theme? - }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script$fext.js" )) { - }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script.js" )) { - - // Is it in the owncloud root ? - }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "$script$fext.js" )) { - }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "$script.js" )) { - - // Is in core but overwritten by a theme? - }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script$fext.js" )) { - }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script.js" )) { - - // Is it in core? - }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "core/$script$fext.js" )) { - }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "core/$script.js" )) { - - }else{ - echo('js file not found: script:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); - die(); - - } - } - // Add the css files - $page->assign('cssfiles', array()); - foreach(OC_Util::$styles as $style){ - // is it in 3rdparty? - if($page->appendIfExist('cssfiles', OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $style.'.css')) { - - // or in apps? - }elseif($page->appendIfExist('cssfiles', OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$style$fext.css" )) { - }elseif($page->appendIfExist('cssfiles', OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$style.css" )) { - - // or in the owncloud root? - }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "$style$fext.css" )) { - }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "$style.css" )) { - - // or in core ? - }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "core/$style$fext.css" )) { - }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "core/$style.css" )) { - - }else{ - echo('css file not found: style:'.$style.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); - die(); - } - } - // Add the theme css files. you can override the default values here - if(!empty($theme)) { - foreach(OC_Util::$styles as $style){ - if($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style$fext.css" )) { - }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style.css" )) { - - }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style$fext.css" )) { - }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style.css" )) { - - }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style$fext.css" )) { - }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style.css" )) { - } - } } // Add custom headers @@ -521,7 +398,6 @@ class OC_Template{ $page->append('headers',$header); } - // Add css files and js files $page->assign( "content", $data, false ); return $page->fetchPage(); } diff --git a/lib/templatelayout.php b/lib/templatelayout.php new file mode 100644 index 00000000000..e387309ad77 --- /dev/null +++ b/lib/templatelayout.php @@ -0,0 +1,170 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +class OC_TemplateLayout extends OC_Template { + public function __construct( $renderas ){ + // Decide which page we show + if( $renderas == 'user' ){ + parent::__construct( 'core', 'layout.user' ); + $this->assign('searchurl',OC_Helper::linkTo( 'search', 'index.php' ), false); + if(array_search(OC_APP::getCurrentApp(),array('settings','admin','help'))!==false){ + $this->assign('bodyid','body-settings', false); + }else{ + $this->assign('bodyid','body-user', false); + } + + // Add navigation entry + $navigation = OC_App::getNavigation(); + $this->assign( 'navigation', $navigation, false); + $this->assign( 'settingsnavigation', OC_App::getSettingsNavigation(), false); + foreach($navigation as $entry) { + if ($entry['active']) { + $this->assign( 'application', $entry['name'], false ); + break; + } + } + }else{ + parent::__construct( 'core', 'layout.guest' ); + } + + // Add the core js files or the js files provided by the selected theme + $jsfiles = $this->findScripts(OC_Util::$scripts); + $this->assign('jsfiles', array(), false); + foreach($jsfiles as $info) { + $root = $info[0]; + $web = $info[1]; + $file = $info[2]; + $this->append( 'jsfiles', $web.'/'.$file); + } + + // Add the css files + $cssfiles = $this->findStyles(OC_Util::$styles); + $this->assign('cssfiles', array()); + foreach($cssfiles as $info) { + $root = $info[0]; + $web = $info[1]; + $file = $info[2]; + $paths = explode('/', $file); + if($root == OC::$APPSROOT && $paths[0] == 'apps'){ + $app = $paths[1]; + unset($paths[0]); + unset($paths[1]); + $path = implode('/', $paths); + $this->append( 'cssfiles', OC_Helper::linkTo($app, $path)); + }else{ + $this->append( 'cssfiles', $web.'/'.$file); + } + } + } + + /* + * @brief append the $file-url if exist at $root + * @param $files array to append file info to + * @param $root path to check + * @param $web base for path + * @param $file the filename + */ + public function appendIfExist(&$files, $root, $webroot, $file) { + if (is_file($root.'/'.$file)) { + $files[] = array($root, $webroot, $file); + return true; + } + return false; + } + + public function findStyles($styles){ + // Read the selected theme from the config file + $theme=OC_Config::getValue( 'theme' ); + + // Read the detected formfactor and use the right file name. + $fext = self::getFormFactorExtension(); + + $files = array(); + foreach($styles as $style){ + // is it in 3rdparty? + if($this->appendIfExist($files, OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $style.'.css')) { + + // or in apps? + }elseif($this->appendIfExist($files, OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$style$fext.css" )) { + }elseif($this->appendIfExist($files, OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$style.css" )) { + + // or in the owncloud root? + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$style$fext.css" )) { + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$style.css" )) { + + // or in core ? + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$style$fext.css" )) { + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$style.css" )) { + + }else{ + echo('css file not found: style:'.$style.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); + die(); + } + } + // Add the theme css files. you can override the default values here + if(!empty($theme)) { + foreach($styles as $style){ + if($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style$fext.css" )) { + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style.css" )) { + + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style$fext.css" )) { + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style.css" )) { + + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style$fext.css" )) { + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style.css" )) { + } + } + } + return $files; + } + + public function findScripts($scripts){ + // Read the selected theme from the config file + $theme=OC_Config::getValue( 'theme' ); + + // Read the detected formfactor and use the right file name. + $fext = self::getFormFactorExtension(); + + $files = array(); + foreach($scripts as $script){ + // Is it in 3rd party? + if($this->appendIfExist($files, OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $script.'.js')) { + + // Is it in apps and overwritten by the theme? + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script$fext.js" )) { + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script.js" )) { + + // Is it part of an app? + }elseif($this->appendIfExist($files, OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script$fext.js" )) { + }elseif($this->appendIfExist($files, OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script.js" )) { + + // Is it in the owncloud root but overwritten by the theme? + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script$fext.js" )) { + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script.js" )) { + + // Is it in the owncloud root ? + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$script$fext.js" )) { + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$script.js" )) { + + // Is in core but overwritten by a theme? + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script$fext.js" )) { + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script.js" )) { + + // Is it in core? + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$script$fext.js" )) { + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$script.js" )) { + + }else{ + echo('js file not found: script:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); + die(); + + } + } + return $files; + } +} -- cgit v1.2.3 From 3000e8f9d508088abe7bb9c2cbc8f3490fa36c9a Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 18 Jun 2012 15:35:04 +0200 Subject: Prepare template js and css functions for use in the js and css minimizers --- lib/templatelayout.php | 64 +++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) (limited to 'lib') diff --git a/lib/templatelayout.php b/lib/templatelayout.php index e387309ad77..1f82e82be74 100644 --- a/lib/templatelayout.php +++ b/lib/templatelayout.php @@ -32,8 +32,8 @@ class OC_TemplateLayout extends OC_Template { parent::__construct( 'core', 'layout.guest' ); } - // Add the core js files or the js files provided by the selected theme - $jsfiles = $this->findScripts(OC_Util::$scripts); + // Add the js files + $jsfiles = self::findJavascriptFiles(OC_Util::$scripts); $this->assign('jsfiles', array(), false); foreach($jsfiles as $info) { $root = $info[0]; @@ -43,7 +43,7 @@ class OC_TemplateLayout extends OC_Template { } // Add the css files - $cssfiles = $this->findStyles(OC_Util::$styles); + $cssfiles = self::findStylesheetFiles(OC_Util::$styles); $this->assign('cssfiles', array()); foreach($cssfiles as $info) { $root = $info[0]; @@ -69,7 +69,7 @@ class OC_TemplateLayout extends OC_Template { * @param $web base for path * @param $file the filename */ - public function appendIfExist(&$files, $root, $webroot, $file) { + static public function appendIfExist(&$files, $root, $webroot, $file) { if (is_file($root.'/'.$file)) { $files[] = array($root, $webroot, $file); return true; @@ -77,7 +77,7 @@ class OC_TemplateLayout extends OC_Template { return false; } - public function findStyles($styles){ + static public function findStylesheetFiles($styles){ // Read the selected theme from the config file $theme=OC_Config::getValue( 'theme' ); @@ -87,19 +87,19 @@ class OC_TemplateLayout extends OC_Template { $files = array(); foreach($styles as $style){ // is it in 3rdparty? - if($this->appendIfExist($files, OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $style.'.css')) { + if(self::appendIfExist($files, OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $style.'.css')) { // or in apps? - }elseif($this->appendIfExist($files, OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$style$fext.css" )) { - }elseif($this->appendIfExist($files, OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$style.css" )) { + }elseif(self::appendIfExist($files, OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$style$fext.css" )) { + }elseif(self::appendIfExist($files, OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$style.css" )) { // or in the owncloud root? - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$style$fext.css" )) { - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$style.css" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$style$fext.css" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$style.css" )) { // or in core ? - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$style$fext.css" )) { - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$style.css" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$style$fext.css" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$style.css" )) { }else{ echo('css file not found: style:'.$style.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); @@ -109,21 +109,21 @@ class OC_TemplateLayout extends OC_Template { // Add the theme css files. you can override the default values here if(!empty($theme)) { foreach($styles as $style){ - if($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style$fext.css" )) { - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style.css" )) { + if(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style$fext.css" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style.css" )) { - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style$fext.css" )) { - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style.css" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style$fext.css" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style.css" )) { - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style$fext.css" )) { - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style.css" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style$fext.css" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style.css" )) { } } } return $files; } - public function findScripts($scripts){ + static public function findJavascriptFiles($scripts){ // Read the selected theme from the config file $theme=OC_Config::getValue( 'theme' ); @@ -133,31 +133,31 @@ class OC_TemplateLayout extends OC_Template { $files = array(); foreach($scripts as $script){ // Is it in 3rd party? - if($this->appendIfExist($files, OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $script.'.js')) { + if(self::appendIfExist($files, OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $script.'.js')) { // Is it in apps and overwritten by the theme? - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script$fext.js" )) { - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script.js" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script$fext.js" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script.js" )) { // Is it part of an app? - }elseif($this->appendIfExist($files, OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script$fext.js" )) { - }elseif($this->appendIfExist($files, OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script.js" )) { + }elseif(self::appendIfExist($files, OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script$fext.js" )) { + }elseif(self::appendIfExist($files, OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script.js" )) { // Is it in the owncloud root but overwritten by the theme? - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script$fext.js" )) { - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script.js" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script$fext.js" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script.js" )) { // Is it in the owncloud root ? - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$script$fext.js" )) { - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$script.js" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$script$fext.js" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$script.js" )) { // Is in core but overwritten by a theme? - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script$fext.js" )) { - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script.js" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script$fext.js" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script.js" )) { // Is it in core? - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$script$fext.js" )) { - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$script.js" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$script$fext.js" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$script.js" )) { }else{ echo('js file not found: script:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); -- cgit v1.2.3 From 2f00384b5124ec0b3f3703d73a11a129aff93a62 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 18 Jun 2012 15:40:43 +0200 Subject: Use TemplateLayout functions for finding js and css files in minimizer --- core/minimizer.php | 4 ++-- lib/minimizer.php | 13 +------------ lib/minimizer/css.php | 44 -------------------------------------------- lib/minimizer/js.php | 43 ------------------------------------------- 4 files changed, 3 insertions(+), 101 deletions(-) (limited to 'lib') diff --git a/core/minimizer.php b/core/minimizer.php index 47e3d855e7b..0abbca75027 100644 --- a/core/minimizer.php +++ b/core/minimizer.php @@ -5,11 +5,11 @@ OC_App::loadApps(); if ($service == 'core.css'){ $minimizer = new OC_Minimizer_CSS(); - $files = $minimizer->findFiles(OC_Util::$core_styles); + $files = OC_TemplateLayout::findStylesheetFiles(OC_Util::$core_styles); $minimizer->output($files, $service); } else if ($service == 'core.js'){ $minimizer = new OC_Minimizer_JS(); - $files = $minimizer->findFiles(OC_Util::$core_scripts); + $files = OC_TemplateLayout::findJavascriptFiles(OC_Util::$core_scripts); $minimizer->output($files, $service); } diff --git a/lib/minimizer.php b/lib/minimizer.php index 428fa477f77..e17c114f065 100644 --- a/lib/minimizer.php +++ b/lib/minimizer.php @@ -1,17 +1,6 @@ files[] = array($root, $webroot, $file); - return true; - } - return false; - } - +abstract class OC_Minimizer { public function getLastModified($files) { $last_modified = 0; foreach($files as $file_info) { diff --git a/lib/minimizer/css.php b/lib/minimizer/css.php index 09a0efdc3a7..da502bfa9e8 100644 --- a/lib/minimizer/css.php +++ b/lib/minimizer/css.php @@ -6,50 +6,6 @@ class OC_Minimizer_CSS extends OC_Minimizer { protected $contentType = 'text/css'; - public function findFiles($styles) { - // Read the selected theme from the config file - $theme=OC_Config::getValue( "theme" ); - - // Read the detected formfactor and use the right file name. - $fext = OC_Template::getFormFactorExtension(); - foreach($styles as $style){ - // is it in 3rdparty? - if($this->appendIfExist(OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $style.'.css')) { - - // or in apps? - }elseif($this->appendIfExist(OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$style$fext.css" )) { - }elseif($this->appendIfExist(OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$style.css" )) { - - // or in the owncloud root? - }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "$style$fext.css" )) { - }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "$style.css" )) { - - // or in core ? - }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "core/$style$fext.css" )) { - }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "core/$style.css" )) { - - }else{ - echo('css file not found: style:'.$style.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); - die(); - } - } - // Add the theme css files. you can override the default values here - if(!empty($theme)) { - foreach($styles as $style){ - if($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style$fext.css" )) { - }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style.css" )) { - - }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style$fext.css" )) { - }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style.css" )) { - - }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style$fext.css" )) { - }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style.css" )) { - } - } - } - return $this->files; - } - public function minimizeFiles($files) { $css_out = ''; $appswebroot = (string) OC::$APPSWEBROOT; diff --git a/lib/minimizer/js.php b/lib/minimizer/js.php index b9a023e0686..0f5cb7e5577 100644 --- a/lib/minimizer/js.php +++ b/lib/minimizer/js.php @@ -6,49 +6,6 @@ class OC_Minimizer_JS extends OC_Minimizer { protected $contentType = 'application/javascript'; - public function findFiles($scripts) { - // Read the selected theme from the config file - $theme=OC_Config::getValue( "theme" ); - - // Read the detected formfactor and use the right file name. - $fext = OC_Template::getFormFactorExtension(); - // Add the core js files or the js files provided by the selected theme - foreach($scripts as $script){ - // Is it in 3rd party? - if($this->appendIfExist(OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $script.'.js')) { - - // Is it in apps and overwritten by the theme? - }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script$fext.js" )) { - }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script.js" )) { - - // Is it part of an app? - }elseif($this->appendIfExist(OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script$fext.js" )) { - }elseif($this->appendIfExist(OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script.js" )) { - - // Is it in the owncloud root but overwritten by the theme? - }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script$fext.js" )) { - }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script.js" )) { - - // Is it in the owncloud root ? - }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "$script$fext.js" )) { - }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "$script.js" )) { - - // Is in core but overwritten by a theme? - }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script$fext.js" )) { - }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script.js" )) { - - // Is it in core? - }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "core/$script$fext.js" )) { - }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "core/$script.js" )) { - - }else{ - echo('js file not found: script:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); - die(); - } - } - return $this->files; - } - public function minimizeFiles($files) { $js_out = ''; foreach($files as $file_info) { -- cgit v1.2.3 From d496a5e19fbe70d2313cae17be0e788ac6487cd0 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 18 Jun 2012 17:23:54 +0200 Subject: ignore "Shared"-directory when calculating free space --- lib/fileproxy/quota.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib') diff --git a/lib/fileproxy/quota.php b/lib/fileproxy/quota.php index f061d48219b..dab41c5e906 100644 --- a/lib/fileproxy/quota.php +++ b/lib/fileproxy/quota.php @@ -55,7 +55,9 @@ class OC_FileProxy_Quota extends OC_FileProxy{ */ private function getFreeSpace(){ $rootInfo=OC_FileCache_Cached::get(''); + $sharedInfo=OC_FileCache_Cached::get('/Shared'); $usedSpace=isset($rootInfo['size'])?$rootInfo['size']:0; + $usedSpace=isset($sharedInfo['size'])?$rootInfo['size']-$sharedInfo['size']:$rootInfo['size']; $totalSpace=$this->getQuota(); if($totalSpace==0){ return 0; -- cgit v1.2.3 From cfb3b633f50decbe0ebd04ba46eaea5f4e5fa226 Mon Sep 17 00:00:00 2001 From: Brice Maron Date: Mon, 18 Jun 2012 19:51:46 +0000 Subject: Force sanitize function to use UTF8 (for php lower than 5.4) --- lib/template.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/template.php b/lib/template.php index a5d10c45d23..77e9332d5b3 100644 --- a/lib/template.php +++ b/lib/template.php @@ -326,7 +326,7 @@ class OC_Template{ * This function is internally used to sanitize HTML. */ private static function sanitizeHTML( &$value ){ - $value = htmlentities( $value ); + $value = htmlentities( $value , ENT_QUOTES, 'UTF-8'); //Specify encoding for PHP<5.4 return $value; } -- cgit v1.2.3 From d4044d0283147df678dc0f833abfcc844e0eff75 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 18 Jun 2012 21:16:51 +0200 Subject: Delay loading of translations until they are used --- lib/l10n.php | 30 +++++++++++++++++++++++------- lib/l10n/string.php | 25 +++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 lib/l10n/string.php (limited to 'lib') diff --git a/lib/l10n.php b/lib/l10n.php index ba4bf23780e..0f01e927ff9 100644 --- a/lib/l10n.php +++ b/lib/l10n.php @@ -39,6 +39,16 @@ class OC_L10N{ */ protected static $language = ''; + /** + * App of this object + */ + protected $app; + + /** + * Language of this object + */ + protected $lang; + /** * Translations */ @@ -77,10 +87,17 @@ class OC_L10N{ * language. */ public function __construct($app, $lang = null){ - $this->init($app, $lang); + $this->app = $app; + $this->lang = $lang; } - protected function init($app, $lang = null){ + protected function init(){ + if ($this->app === true) { + return; + } + $app = $this->app; + $lang = $this->lang; + $this->app = true; // Find the right language if(is_null($lang)){ $lang = self::findLanguage($app); @@ -127,10 +144,7 @@ class OC_L10N{ * returned. */ public function t($text, $parameters = array()){ - if(array_key_exists($text, $this->translations)){ - return vsprintf($this->translations[$text], $parameters); - } - return vsprintf($text, $parameters); + return new OC_L10N_String($this, $text, $parameters); } /** @@ -144,7 +158,7 @@ class OC_L10N{ public function tA($textArray){ $result = array(); foreach($textArray as $key => $text){ - $result[$key] = $this->t($text); + $result[$key] = (string)$this->t($text); } return $result; } @@ -156,6 +170,7 @@ class OC_L10N{ * Returns an associative array with all translations */ public function getTranslations(){ + $this->init(); return $this->translations; } @@ -182,6 +197,7 @@ class OC_L10N{ * - params: timestamp (int/string) */ public function l($type, $data){ + $this->init(); switch($type){ // If you add something don't forget to add it to $localizations // at the top of the page diff --git a/lib/l10n/string.php b/lib/l10n/string.php new file mode 100644 index 00000000000..4769790a16d --- /dev/null +++ b/lib/l10n/string.php @@ -0,0 +1,25 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +class OC_L10N_String{ + protected $l10n; + public function __construct($l10n, $text, $parameters){ + $this->l10n = $l10n; + $this->text = $text; + $this->parameters = $parameters; + + } + + public function __toString(){ + $translations = $this->l10n->getTranslations(); + if(array_key_exists($this->text, $translations)){ + return vsprintf($translations[$this->text], $this->parameters); + } + return vsprintf($this->text, $this->parameters); + } +} -- cgit v1.2.3 From c1df0539a087f2e8964357e96a05c6887b188c7f Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Mon, 18 Jun 2012 23:33:02 +0200 Subject: fixes oc-668 --- lib/helper.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib') diff --git a/lib/helper.php b/lib/helper.php index 2ded7b13c38..480c3fe930e 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -378,6 +378,12 @@ class OC_Helper { //trim the character set from the end of the response $mimeType=substr($reply,0,strrpos($reply,' ')); + + //trim ; + if (strpos($mimeType, ';') !== false) { + $mimeType = strstr($mimeType, ';', true); + } + } if ($mimeType=='application/octet-stream') { // Fallback solution: (try to guess the type by the file extension -- cgit v1.2.3 From 0469f529fa3c5bb5c643f4c253f886f58ca50ba7 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 19 Jun 2012 09:35:13 +0200 Subject: quota calculation fixed --- lib/fileproxy/quota.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/fileproxy/quota.php b/lib/fileproxy/quota.php index dab41c5e906..b0c3775b9db 100644 --- a/lib/fileproxy/quota.php +++ b/lib/fileproxy/quota.php @@ -57,7 +57,7 @@ class OC_FileProxy_Quota extends OC_FileProxy{ $rootInfo=OC_FileCache_Cached::get(''); $sharedInfo=OC_FileCache_Cached::get('/Shared'); $usedSpace=isset($rootInfo['size'])?$rootInfo['size']:0; - $usedSpace=isset($sharedInfo['size'])?$rootInfo['size']-$sharedInfo['size']:$rootInfo['size']; + $usedSpace=isset($sharedInfo['size'])?$usedSpace-$sharedInfo['size']:$usedSpace; $totalSpace=$this->getQuota(); if($totalSpace==0){ return 0; -- cgit v1.2.3 From d2936bd90caa2b256d32e7d349449ed58b28107b Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 19 Jun 2012 17:20:19 +0200 Subject: introducing a sanitize HTML function for the internal and the public API. This allows to easily convert strings to HTML before displaying them on the web page to reduce the risk of xss vulnerabilities. --- lib/public/util.php | 12 ++++++++++++ lib/util.php | 17 ++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/public/util.php b/lib/public/util.php index d79d3f26b1e..7c0cb666077 100644 --- a/lib/public/util.php +++ b/lib/public/util.php @@ -264,6 +264,18 @@ class Util { public static function callCheck(){ return(\OC_Util::callCheck()); } + + /** + * @brief Used to sanitize HTML + * + * This function is used to sanitize HTML and should be applied on any string or array of strings before displaying it on a web page. + * + * @param string or array of strings + * @return array with sanitized strings or a single sinitized string, depends on the input parameter. + */ + public static function sanitizeHTML( $value ){ + return(\OC_Util::sanitizeHTML($value)); //Specify encoding for PHP<5.4 + } } ?> diff --git a/lib/util.php b/lib/util.php index 0266a8ecc5f..bcfeb417c1d 100755 --- a/lib/util.php +++ b/lib/util.php @@ -370,7 +370,7 @@ class OC_Util { $_SESSION['requesttoken-'.$token]=time(); // cleanup old tokens garbage collector - // only run every 20th time so we don´t waste cpu cycles + // only run every 20th time so we don't waste cpu cycles if(rand(0,20)==0) { foreach($_SESSION as $key=>$value) { // search all tokens in the session @@ -426,4 +426,19 @@ class OC_Util { exit; } } + + /** + * @brief Public function to sanitize HTML + * + * This function is used to sanitize HTML and should be applied on any string or array of strings before displaying it on a web page. + * + * @param string or array of strings + * @return array with sanitized strings or a single sinitized string, depends on the input parameter. + */ + public static function sanitizeHTML( &$value ){ + if (is_array($value) || is_object($value)) array_walk_recursive($value,'OC_Util::sanitizeHTML'); + else $value = htmlentities($value, ENT_QUOTES, 'UTF-8'); //Specify encoding for PHP<5.4 + return $value; + } + } -- cgit v1.2.3 From 089ae980c40544de54a10d407fd366f61ef5ec48 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 19 Jun 2012 17:24:55 +0200 Subject: use new sanitize HTML function --- index.php | 2 +- lib/template.php | 8 +------- settings/admin.php | 2 +- settings/ajax/getlog.php | 2 +- settings/js/log.js | 2 +- 5 files changed, 5 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/index.php b/index.php index 1171c0fe0cf..e3c94adf66f 100755 --- a/index.php +++ b/index.php @@ -122,7 +122,7 @@ elseif(OC_User::isLoggedIn()) { if(!array_key_exists('sectoken', $_SESSION) || (array_key_exists('sectoken', $_SESSION) && is_null(OC::$REQUESTEDFILE)) || substr(OC::$REQUESTEDFILE, -3) == 'php'){ $sectoken=rand(1000000,9999999); $_SESSION['sectoken']=$sectoken; - $redirect_url = (isset($_REQUEST['redirect_url'])) ? strip_tags($_REQUEST['redirect_url']) : $_SERVER['REQUEST_URI']; + $redirect_url = (isset($_REQUEST['redirect_url'])) ? OC_Util::sanitizeHTML($_REQUEST['redirect_url']) : $_SERVER['REQUEST_URI']; OC_Template::printGuestPage('', 'login', array('error' => $error, 'sectoken' => $sectoken, 'redirect' => $redirect_url)); } } diff --git a/lib/template.php b/lib/template.php index 77e9332d5b3..75b33d8aace 100644 --- a/lib/template.php +++ b/lib/template.php @@ -308,13 +308,7 @@ class OC_Template{ * If the key existed before, it will be overwritten */ public function assign( $key, $value, $sanitizeHTML=true ){ - if($sanitizeHTML == true) { - if(is_array($value)) { - array_walk_recursive($value,'OC_Template::sanitizeHTML'); - } else { - $value = OC_Template::sanitizeHTML($value); - } - } + if($sanitizeHTML == true) $value=OC_Util::sanitizeHTML($value); $this->vars[$key] = $value; return true; } diff --git a/settings/admin.php b/settings/admin.php index 4cbd67c3678..a997bad4e3c 100644 --- a/settings/admin.php +++ b/settings/admin.php @@ -23,7 +23,7 @@ function compareEntries($a,$b){ usort($entries, 'compareEntries'); $tmpl->assign('loglevel',OC_Config::getValue( "loglevel", 2 )); -$tmpl->assign('entries',$entries,false); +$tmpl->assign('entries',$entries); $tmpl->assign('forms',array()); foreach($forms as $form){ $tmpl->append('forms',$form); diff --git a/settings/ajax/getlog.php b/settings/ajax/getlog.php index ed48b2cae1a..d9e80de37ba 100644 --- a/settings/ajax/getlog.php +++ b/settings/ajax/getlog.php @@ -14,4 +14,4 @@ $count=(isset($_GET['count']))?$_GET['count']:50; $offset=(isset($_GET['offset']))?$_GET['offset']:0; $entries=OC_Log_Owncloud::getEntries($count,$offset); -OC_JSON::success(array("data" => $entries)); +OC_JSON::success(array("data" => OC_Util::sanitizeHTML($entries))); diff --git a/settings/js/log.js b/settings/js/log.js index bde8b8b104c..6063c7d9a9f 100644 --- a/settings/js/log.js +++ b/settings/js/log.js @@ -39,7 +39,7 @@ OC.Log={ row.append(appTd); var messageTd=$(''); - messageTd.text(entry.message.replace(//, ">")); + messageTd.text(entry.message); row.append(messageTd); var timeTd=$(''); -- cgit v1.2.3 From 4b6f6291c524648ffaa77683d77b486bb467b7e8 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Tue, 19 Jun 2012 17:54:19 +0200 Subject: Remember result of OC_User::isLoggedIn, can be very expensive to check --- lib/user.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/user.php b/lib/user.php index f1903093d6d..23b88aa1d06 100644 --- a/lib/user.php +++ b/lib/user.php @@ -240,13 +240,17 @@ class OC_User { * Checks if the user is logged in */ public static function isLoggedIn(){ + static $is_login_checked = null; + if (!is_null($is_login_checked)) { + return $is_login_checked; + } if( isset($_SESSION['user_id']) AND $_SESSION['user_id']) { OC_App::loadApps(array('authentication')); if (self::userExists($_SESSION['user_id']) ){ - return true; + return $is_login_checked = true; } } - return false; + return $is_login_checked = false; } /** -- cgit v1.2.3 From f11e4d7cd6c5cae9a0be52dff0bb2f32e20e7099 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 19 Jun 2012 19:29:43 +0200 Subject: removing sanitizeHTML() function from template.php since I moved it to util.php to make it more generic. --- lib/template.php | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'lib') diff --git a/lib/template.php b/lib/template.php index 75b33d8aace..8fb0133b289 100644 --- a/lib/template.php +++ b/lib/template.php @@ -313,17 +313,6 @@ class OC_Template{ return true; } - - /** - * @brief Internaly used to sanitze HTML - * - * This function is internally used to sanitize HTML. - */ - private static function sanitizeHTML( &$value ){ - $value = htmlentities( $value , ENT_QUOTES, 'UTF-8'); //Specify encoding for PHP<5.4 - return $value; - } - /** * @brief Appends a variable * @param $key key -- cgit v1.2.3 From 28a72e0e3c25ecf8cc5ab61a4398ab687072b203 Mon Sep 17 00:00:00 2001 From: Sam Tuke Date: Tue, 19 Jun 2012 19:42:40 +0100 Subject: Fixed deleteAll function for deleting all old versions of files (expireAll) Added new readdir() method to all storage classes and handlers (only working implementation in local.php) --- apps/files_archive/lib/storage.php | 1 + apps/files_sharing/sharedstorage.php | 2 ++ apps/files_versions/versions.php | 66 ++++++++++++++++++++++++------------ lib/filestorage.php | 1 + lib/filestorage/local.php | 3 ++ lib/filesystem.php | 3 ++ lib/filesystemview.php | 4 +++ 7 files changed, 58 insertions(+), 22 deletions(-) (limited to 'lib') diff --git a/apps/files_archive/lib/storage.php b/apps/files_archive/lib/storage.php index 86761663611..2f10d6a3e4e 100644 --- a/apps/files_archive/lib/storage.php +++ b/apps/files_archive/lib/storage.php @@ -49,6 +49,7 @@ class OC_Filestorage_Archive extends OC_Filestorage_Common{ OC_FakeDirStream::$dirs[$id]=$content; return opendir('fakedir://'.$id); } + public function readdir($path){} public function stat($path){ $ctime=filectime($this->path); $path=$this->stripPath($path); diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 1a6942ad160..9174334383c 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -139,6 +139,8 @@ class OC_Filestorage_Shared extends OC_Filestorage { } } + public function readdir( $path ) {} + public function is_dir($path) { if ($path == "" || $path == "/") { return true; diff --git a/apps/files_versions/versions.php b/apps/files_versions/versions.php index 44ce7c635aa..6feb0cbb9c7 100644 --- a/apps/files_versions/versions.php +++ b/apps/files_versions/versions.php @@ -303,66 +303,88 @@ class Storage { */ public static function expireAll() { - function deleteAll($directory, $empty = false) { + function deleteAll( $directory, $empty = false ) { - if(substr($directory,-1) == "/") { - $directory = substr($directory,0,-1); + // strip leading slash + if( substr( $directory, 0, 1 ) == "/" ) { + + $directory = substr( $directory, 1 ); + + } + + // strip trailing slash + if( substr( $directory, -1) == "/" ) { + + $directory = substr( $directory, 0, -1 ); + } - if(!file_exists($directory) || !is_dir($directory)) { + $view = new \OC_FilesystemView(''); + + if ( !$view->file_exists( $directory ) || !$view->is_dir( $directory ) ) { return false; - } elseif(!is_readable($directory)) { + } elseif( !$view->is_readable( $directory ) ) { return false; } else { - $directoryHandle = opendir($directory); + $foldername = \OCP\Config::getSystemValue('datadirectory') .'/' . \OCP\USER::getUser() .'/' . $directory; // have to set an absolute path for use with PHP's opendir as OC version doesn't work + + $directoryHandle = opendir( $foldername ); - while ($contents = readdir($directoryHandle)) { + while ( $contents = $view->readdir( $directoryHandle ) ) { - if( $contents != '.' && $contents != '..') { + if ( $contents != '.' && $contents != '..') { $path = $directory . "/" . $contents; - if( is_dir($path) ) { + if ( $view->is_dir( $path ) ) { - deleteAll($path); + deleteAll( $path ); } else { - - unlink($path); + + $view->unlink( \OCP\USER::getUser() .'/' . $path ); // TODO: make unlink use same system path as is_dir } } } - closedir( $directoryHandle ); + //$view->closedir( $directoryHandle ); // TODO: implement closedir in OC_FSV - if( $empty == false ) { + if ( $empty == false ) { - if(!rmdir($directory)) { + if ( !$view->rmdir( $directory ) ) { return false; } - } + } return true; } } + + $dir = \OCP\Config::getSystemValue('files_versionsfolder', Storage::DEFAULTFOLDER); + + deleteAll( $dir, true ); + +// if ( deleteAll( $dir, 1 ) ) { +// +// echo "

deleted ok

"; +// +// } else { +// +// echo "

not deleted

"; +// +// } - /* - // FIXME: make this path dynamic - $dir = '/home/samtuke/owncloud/git/oc5/data/admin/versions'; - - ( deleteAll( $dir, 1 ) ? return true : return false ); - */ } diff --git a/lib/filestorage.php b/lib/filestorage.php index 71ef4aed00b..bf353bb0cce 100644 --- a/lib/filestorage.php +++ b/lib/filestorage.php @@ -28,6 +28,7 @@ abstract class OC_Filestorage{ abstract public function mkdir($path); abstract public function rmdir($path); abstract public function opendir($path); + abstract public function readdir($path); abstract public function is_dir($path); abstract public function is_file($path); abstract public function stat($path); diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php index 44a2ab0f634..27794fe17c0 100644 --- a/lib/filestorage/local.php +++ b/lib/filestorage/local.php @@ -20,6 +20,9 @@ class OC_Filestorage_Local extends OC_Filestorage{ public function opendir($path){ return opendir($this->datadir.$path); } + public function readdir($handle){ + return readdir($handle); + } public function is_dir($path){ if(substr($path,-1)=='/'){ $path=substr($path,0,-1); diff --git a/lib/filesystem.php b/lib/filesystem.php index 89de533d725..0d0943d3639 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -399,6 +399,9 @@ class OC_Filesystem{ static public function opendir($path){ return self::$defaultInstance->opendir($path); } + static public function readdir($path){ + return self::$defaultInstance->readdir($path); + } static public function is_dir($path){ return self::$defaultInstance->is_dir($path); } diff --git a/lib/filesystemview.php b/lib/filesystemview.php index 813a87cd74e..da622bcf920 100644 --- a/lib/filesystemview.php +++ b/lib/filesystemview.php @@ -158,6 +158,10 @@ class OC_FilesystemView { public function opendir($path){ return $this->basicOperation('opendir',$path,array('read')); } + public function readdir($handle){ + $fsLocal= new OC_Filestorage_Local( array( 'datadir' => '/' ) ); + return $fsLocal->readdir( $handle ); + } public function is_dir($path){ if($path=='/'){ return true; -- cgit v1.2.3 From d8b32c2f0e962531fa36707faa6deed6ebb2e378 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Tue, 19 Jun 2012 22:12:05 +0200 Subject: Move check code from setupFS to checkServer --- lib/util.php | 54 ++++++++++++++++++++---------------------------------- 1 file changed, 20 insertions(+), 34 deletions(-) (limited to 'lib') diff --git a/lib/util.php b/lib/util.php index bcfeb417c1d..b6564468ff9 100755 --- a/lib/util.php +++ b/lib/util.php @@ -19,41 +19,12 @@ class OC_Util { return false; } - $CONFIG_DATADIRECTORY_ROOT = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ); - $CONFIG_BACKUPDIRECTORY = OC_Config::getValue( "backupdirectory", OC::$SERVERROOT."/backup" ); - - // Check if config folder is writable. - if(!is_writable(OC::$SERVERROOT."/config/")) { - $tmpl = new OC_Template( '', 'error', 'guest' ); - $tmpl->assign('errors',array(1=>array('error'=>"Can't write into config directory 'config'",'hint'=>"You can usually fix this by giving the webserver user write access to the config directory in owncloud"))); - $tmpl->printPage(); - exit; - } - - // Check if apps folder is writable. - if(OC_Config::getValue('writable_appsdir', true) && !is_writable(OC::$SERVERROOT."/apps/")) { - $tmpl = new OC_Template( '', 'error', 'guest' ); - $tmpl->assign('errors',array(1=>array('error'=>"Can't write into apps directory 'apps'",'hint'=>"You can usually fix this by giving the webserver user write access to the config directory in owncloud"))); - $tmpl->printPage(); - exit; - } - - // Create root dir. - if(!is_dir($CONFIG_DATADIRECTORY_ROOT)){ - $success=@mkdir($CONFIG_DATADIRECTORY_ROOT); - if(!$success) { - $tmpl = new OC_Template( '', 'error', 'guest' ); - $tmpl->assign('errors',array(1=>array('error'=>"Can't create data directory (".$CONFIG_DATADIRECTORY_ROOT.")",'hint'=>"You can usually fix this by giving the webserver write access to the ownCloud directory '".OC::$SERVERROOT."' (in a terminal, use the command 'chown -R www-data:www-data /path/to/your/owncloud/install/data' "))); - $tmpl->printPage(); - exit; - } - } - // If we are not forced to load a specific user we load the one that is logged in if( $user == "" && OC_User::isLoggedIn()){ $user = OC_User::getUser(); } + $CONFIG_DATADIRECTORY_ROOT = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ); //first set up the local "root" storage if(!self::$rootMounted){ OC_Filesystem::mount('OC_Filestorage_Local',array('datadir'=>$CONFIG_DATADIRECTORY_ROOT),'/'); @@ -209,9 +180,6 @@ class OC_Util { * @return array arrays with error messages and hints */ public static function checkServer(){ - $CONFIG_DATADIRECTORY_ROOT = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ); - $CONFIG_BACKUPDIRECTORY = OC_Config::getValue( "backupdirectory", OC::$SERVERROOT."/backup" ); - $CONFIG_INSTALLED = OC_Config::getValue( "installed", false ); $errors=array(); //check for database drivers @@ -224,6 +192,17 @@ class OC_Util { //common hint for all file permissons error messages $permissionsHint="Permissions can usually be fixed by giving the webserver write access to the ownCloud directory"; + // Check if config folder is writable. + if(!is_writable(OC::$SERVERROOT."/config/")) { + $errors[]=array('error'=>"Can't write into config directory 'config'",'hint'=>"You can usually fix this by giving the webserver user write access to the config directory in owncloud"); + } + + // Check if apps folder is writable. + if(OC_Config::getValue('writable_appsdir', true) && !is_writable(OC::$SERVERROOT."/apps/")) { + $errors[]=array('error'=>"Can't write into apps directory 'apps'",'hint'=>"You can usually fix this by giving the webserver user write access to the config directory in owncloud"); + } + + $CONFIG_DATADIRECTORY_ROOT = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ); //check for correct file permissions if(!stristr(PHP_OS, 'WIN')){ $permissionsModHint="Please change the permissions to 0770 so that the directory cannot be listed by other users."; @@ -237,6 +216,7 @@ class OC_Util { } } if( OC_Config::getValue( "enablebackup", false )){ + $CONFIG_BACKUPDIRECTORY = OC_Config::getValue( "backupdirectory", OC::$SERVERROOT."/backup" ); $prems=substr(decoct(@fileperms($CONFIG_BACKUPDIRECTORY)),-3); if(substr($prems,-1)!='0'){ OC_Helper::chmodr($CONFIG_BACKUPDIRECTORY,0770); @@ -250,7 +230,13 @@ class OC_Util { }else{ //TODO: permissions checks for windows hosts } - if(is_dir($CONFIG_DATADIRECTORY_ROOT) and !is_writable($CONFIG_DATADIRECTORY_ROOT)){ + // Create root dir. + if(!is_dir($CONFIG_DATADIRECTORY_ROOT)){ + $success=@mkdir($CONFIG_DATADIRECTORY_ROOT); + if(!$success) { + $errors[]=array('error'=>"Can't create data directory (".$CONFIG_DATADIRECTORY_ROOT.")",'hint'=>"You can usually fix this by giving the webserver write access to the ownCloud directory '".OC::$SERVERROOT."' (in a terminal, use the command 'chown -R www-data:www-data /path/to/your/owncloud/install/data' "); + } + } else if(!is_writable($CONFIG_DATADIRECTORY_ROOT)){ $errors[]=array('error'=>'Data directory ('.$CONFIG_DATADIRECTORY_ROOT.') not writable by ownCloud
','hint'=>$permissionsHint); } -- cgit v1.2.3 From f54ef5a464e3530da36f2ebe7f88052cac0c6ad0 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Tue, 19 Jun 2012 22:50:28 +0200 Subject: Remove OC::$CONFIG_DATADIRECTORY, not used --- lib/base.php | 12 ------------ lib/files.php | 5 +---- lib/util.php | 34 +++++++++++++++++----------------- 3 files changed, 18 insertions(+), 33 deletions(-) (limited to 'lib') diff --git a/lib/base.php b/lib/base.php index db55504117d..6e209afebda 100644 --- a/lib/base.php +++ b/lib/base.php @@ -42,10 +42,6 @@ class OC{ * the owncloud root path for http requests (e.g. owncloud/) */ public static $WEBROOT = ''; - /** - * the folder that stores that data files for the filesystem of the user (e.g. /srv/http/owncloud/data/myusername/files) - */ - public static $CONFIG_DATADIRECTORY = ''; /** * The installation path of the 3rdparty folder on the server (e.g. /srv/http/owncloud/3rdparty) */ @@ -349,19 +345,11 @@ class OC{ exit; } - // TODO: we should get rid of this one, too - // WARNING: to make everything even more confusing, - // DATADIRECTORY is a var that changes and DATADIRECTORY_ROOT - // stays the same, but is set by "datadirectory". - // Any questions? - OC::$CONFIG_DATADIRECTORY = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ); - // User and Groups if( !OC_Config::getValue( "installed", false )){ $_SESSION['user_id'] = ''; } - OC_User::useBackend( OC_Config::getValue( "userbackend", "database" )); OC_Group::useBackend(new OC_Group_Database()); diff --git a/lib/files.php b/lib/files.php index 3ecf08739b0..469c3a15b8e 100644 --- a/lib/files.php +++ b/lib/files.php @@ -30,12 +30,9 @@ class OC_Files { /** * get the content of a directory - * @param dir $directory + * @param dir $directory path under datadirectory */ public static function getDirectoryContent($directory, $mimetype_filter = ''){ - if(strpos($directory,OC::$CONFIG_DATADIRECTORY)===0){ - $directory=substr($directory,strlen(OC::$CONFIG_DATADIRECTORY)); - } $files=OC_FileCache::getFolderContent($directory, false, $mimetype_filter); foreach($files as &$file){ $file['directory']=$directory; diff --git a/lib/util.php b/lib/util.php index b6564468ff9..5492587862c 100755 --- a/lib/util.php +++ b/lib/util.php @@ -24,16 +24,16 @@ class OC_Util { $user = OC_User::getUser(); } - $CONFIG_DATADIRECTORY_ROOT = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ); + $CONFIG_DATADIRECTORY = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ); //first set up the local "root" storage if(!self::$rootMounted){ - OC_Filesystem::mount('OC_Filestorage_Local',array('datadir'=>$CONFIG_DATADIRECTORY_ROOT),'/'); + OC_Filesystem::mount('OC_Filestorage_Local',array('datadir'=>$CONFIG_DATADIRECTORY),'/'); self::$rootMounted=true; } if( $user != "" ){ //if we aren't logged in, there is no use to set up the filesystem - OC::$CONFIG_DATADIRECTORY = $CONFIG_DATADIRECTORY_ROOT."/$user/$root"; - if( !is_dir( OC::$CONFIG_DATADIRECTORY )){ - mkdir( OC::$CONFIG_DATADIRECTORY, 0755, true ); + $userdirectory = $CONFIG_DATADIRECTORY."/$user/$root"; + if( !is_dir( $userdirectory )){ + mkdir( $userdirectory, 0755, true ); } //jail the user into his "home" directory @@ -42,8 +42,8 @@ class OC_Util { OC_FileProxy::register($quotaProxy); self::$fsSetup=true; // Load personal mount config - if (is_file($CONFIG_DATADIRECTORY_ROOT.'/'.$user.'/mount.php')) { - $mountConfig = include($CONFIG_DATADIRECTORY_ROOT.'/'.$user.'/mount.php'); + if (is_file($CONFIG_DATADIRECTORY.'/'.$user.'/mount.php')) { + $mountConfig = include($CONFIG_DATADIRECTORY.'/'.$user.'/mount.php'); if (isset($mountConfig['user'][$user])) { foreach ($mountConfig['user'][$user] as $mountPoint => $options) { OC_Filesystem::mount($options['class'], $options['options'], $mountPoint); @@ -202,17 +202,17 @@ class OC_Util { $errors[]=array('error'=>"Can't write into apps directory 'apps'",'hint'=>"You can usually fix this by giving the webserver user write access to the config directory in owncloud"); } - $CONFIG_DATADIRECTORY_ROOT = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ); + $CONFIG_DATADIRECTORY = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ); //check for correct file permissions if(!stristr(PHP_OS, 'WIN')){ $permissionsModHint="Please change the permissions to 0770 so that the directory cannot be listed by other users."; - $prems=substr(decoct(@fileperms($CONFIG_DATADIRECTORY_ROOT)),-3); + $prems=substr(decoct(@fileperms($CONFIG_DATADIRECTORY)),-3); if(substr($prems,-1)!='0'){ - OC_Helper::chmodr($CONFIG_DATADIRECTORY_ROOT,0770); + OC_Helper::chmodr($CONFIG_DATADIRECTORY,0770); clearstatcache(); - $prems=substr(decoct(@fileperms($CONFIG_DATADIRECTORY_ROOT)),-3); + $prems=substr(decoct(@fileperms($CONFIG_DATADIRECTORY)),-3); if(substr($prems,2,1)!='0'){ - $errors[]=array('error'=>'Data directory ('.$CONFIG_DATADIRECTORY_ROOT.') is readable for other users
','hint'=>$permissionsModHint); + $errors[]=array('error'=>'Data directory ('.$CONFIG_DATADIRECTORY.') is readable for other users
','hint'=>$permissionsModHint); } } if( OC_Config::getValue( "enablebackup", false )){ @@ -231,13 +231,13 @@ class OC_Util { //TODO: permissions checks for windows hosts } // Create root dir. - if(!is_dir($CONFIG_DATADIRECTORY_ROOT)){ - $success=@mkdir($CONFIG_DATADIRECTORY_ROOT); + if(!is_dir($CONFIG_DATADIRECTORY)){ + $success=@mkdir($CONFIG_DATADIRECTORY); if(!$success) { - $errors[]=array('error'=>"Can't create data directory (".$CONFIG_DATADIRECTORY_ROOT.")",'hint'=>"You can usually fix this by giving the webserver write access to the ownCloud directory '".OC::$SERVERROOT."' (in a terminal, use the command 'chown -R www-data:www-data /path/to/your/owncloud/install/data' "); + $errors[]=array('error'=>"Can't create data directory (".$CONFIG_DATADIRECTORY.")",'hint'=>"You can usually fix this by giving the webserver write access to the ownCloud directory '".OC::$SERVERROOT."' (in a terminal, use the command 'chown -R www-data:www-data /path/to/your/owncloud/install/data' "); } - } else if(!is_writable($CONFIG_DATADIRECTORY_ROOT)){ - $errors[]=array('error'=>'Data directory ('.$CONFIG_DATADIRECTORY_ROOT.') not writable by ownCloud
','hint'=>$permissionsHint); + } else if(!is_writable($CONFIG_DATADIRECTORY)){ + $errors[]=array('error'=>'Data directory ('.$CONFIG_DATADIRECTORY.') not writable by ownCloud
','hint'=>$permissionsHint); } // check if all required php modules are present -- cgit v1.2.3 From 13a9ef36fb7bf7706af545cbe227296fa005403c Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 20 Jun 2012 11:34:17 +0200 Subject: don't show other users file if the filesystem is not index already --- lib/filecache/cached.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib') diff --git a/lib/filecache/cached.php b/lib/filecache/cached.php index a22adad4528..17a792a23d4 100644 --- a/lib/filecache/cached.php +++ b/lib/filecache/cached.php @@ -55,6 +55,9 @@ class OC_FileCache_Cached{ $root=OC_Filesystem::getRoot(); } $parent=OC_FileCache::getId($path,$root); + if($parent==-1){ + return array(); + } $query=OC_DB::prepare('SELECT path,name,ctime,mtime,mimetype,size,encrypted,versioned,writable FROM *PREFIX*fscache WHERE parent=? AND (mimetype LIKE ? OR mimetype = ?)'); $result=$query->execute(array($parent, $mimetype_filter.'%', 'httpd/unix-directory'))->fetchAll(); if(is_array($result)){ -- cgit v1.2.3 From 6644511124d0f93ca6636344db5455da6d160c3d Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 20 Jun 2012 16:29:19 +0200 Subject: remove unnecessary comment --- lib/public/util.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/public/util.php b/lib/public/util.php index 7c0cb666077..c611d59a533 100644 --- a/lib/public/util.php +++ b/lib/public/util.php @@ -274,7 +274,7 @@ class Util { * @return array with sanitized strings or a single sinitized string, depends on the input parameter. */ public static function sanitizeHTML( $value ){ - return(\OC_Util::sanitizeHTML($value)); //Specify encoding for PHP<5.4 + return(\OC_Util::sanitizeHTML($value)); } } -- cgit v1.2.3 From 5c8e774cea24bd964632ae96357a308272753513 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 20 Jun 2012 08:57:21 +0200 Subject: Small code reorder --- lib/util.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/util.php b/lib/util.php index 5492587862c..f0999b6d201 100755 --- a/lib/util.php +++ b/lib/util.php @@ -19,17 +19,18 @@ class OC_Util { return false; } - // If we are not forced to load a specific user we load the one that is logged in - if( $user == "" && OC_User::isLoggedIn()){ - $user = OC_User::getUser(); - } - $CONFIG_DATADIRECTORY = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ); //first set up the local "root" storage if(!self::$rootMounted){ OC_Filesystem::mount('OC_Filestorage_Local',array('datadir'=>$CONFIG_DATADIRECTORY),'/'); self::$rootMounted=true; } + + // If we are not forced to load a specific user we load the one that is logged in + if( $user == "" && OC_User::isLoggedIn()){ + $user = OC_User::getUser(); + } + if( $user != "" ){ //if we aren't logged in, there is no use to set up the filesystem $userdirectory = $CONFIG_DATADIRECTORY."/$user/$root"; if( !is_dir( $userdirectory )){ -- cgit v1.2.3 From 6404476bec76a5c4bc2c6d3bb1508bb1c6c025f2 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Tue, 19 Jun 2012 17:38:04 +0200 Subject: Delay setup of FS until OC_Filesystem is used --- apps/files_sharing/appinfo/app.php | 9 +++++++-- apps/files_sharing/sharedstorage.php | 13 +++---------- lib/base.php | 6 ------ lib/filesystem.php | 1 + lib/util.php | 8 +++++--- 5 files changed, 16 insertions(+), 21 deletions(-) (limited to 'lib') diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index ea3a9da6f7a..bbb753d5e69 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -1,15 +1,20 @@ '/'.OCP\USER::getUser().'/files/Shared'), '/'.OCP\USER::getUser().'/files/Shared/'); + public static function setup($options) { + $user_dir = $options['user_dir']; + OC_Filesystem::mount('OC_Filestorage_Shared', array('datadir' => $user_dir.'/Shared'), $user_dir.'/Shared/'); } /** @@ -524,11 +525,3 @@ class OC_Filestorage_Shared extends OC_Filestorage { return $this->filemtime($path)>$time; } } - -if (OCP\USER::isLoggedIn()) { - OC_Filestorage_Shared::setup(); -} else { - OCP\Util::connectHook('OC_User', 'post_login', 'OC_Filestorage_Shared', 'setup'); -} - -?> diff --git a/lib/base.php b/lib/base.php index 6e209afebda..b6ca19568fe 100644 --- a/lib/base.php +++ b/lib/base.php @@ -353,12 +353,6 @@ class OC{ OC_User::useBackend( OC_Config::getValue( "userbackend", "database" )); OC_Group::useBackend(new OC_Group_Database()); - // Set up file system unless forbidden - global $RUNTIME_NOSETUPFS; - if(!$RUNTIME_NOSETUPFS ){ - OC_Util::setupFS(); - } - // Load Apps // This includes plugins for users and filesystems as well global $RUNTIME_NOAPPS; diff --git a/lib/filesystem.php b/lib/filesystem.php index 0d0943d3639..aeeb012f373 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -488,4 +488,5 @@ class OC_Filesystem{ } } +OC_Util::setupFS(); require_once('filecache.php'); diff --git a/lib/util.php b/lib/util.php index f0999b6d201..46c9e0ef927 100755 --- a/lib/util.php +++ b/lib/util.php @@ -14,7 +14,7 @@ class OC_Util { public static $core_scripts=array(); // Can be set up - public static function setupFS( $user = "", $root = "files" ){// configure the initial filesystem based on the configuration + public static function setupFS( $user = '' ){// configure the initial filesystem based on the configuration if(self::$fsSetup){//setting up the filesystem twice can only lead to trouble return false; } @@ -32,13 +32,14 @@ class OC_Util { } if( $user != "" ){ //if we aren't logged in, there is no use to set up the filesystem - $userdirectory = $CONFIG_DATADIRECTORY."/$user/$root"; + $user_dir = '/'.$user.'/files'; + $userdirectory = $CONFIG_DATADIRECTORY.$user_dir; if( !is_dir( $userdirectory )){ mkdir( $userdirectory, 0755, true ); } //jail the user into his "home" directory - OC_Filesystem::init('/'.$user.'/'.$root); + OC_Filesystem::init($user_dir); $quotaProxy=new OC_FileProxy_Quota(); OC_FileProxy::register($quotaProxy); self::$fsSetup=true; @@ -51,6 +52,7 @@ class OC_Util { } } } + OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $user_dir)); } } -- cgit v1.2.3 From 7a3d606cacb68c23d7972d078370c58d4a8f8a2c Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 20 Jun 2012 17:10:17 +0200 Subject: Prefer requested app before redirecting to default page --- lib/util.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/util.php b/lib/util.php index 46c9e0ef927..7792f96d445 100755 --- a/lib/util.php +++ b/lib/util.php @@ -324,7 +324,11 @@ class OC_Util { OC_Log::write('core','redirectToDefaultPage',OC_Log::DEBUG); if(isset($_REQUEST['redirect_url']) && (substr($_REQUEST['redirect_url'], 0, strlen(OC::$WEBROOT)) == OC::$WEBROOT || $_REQUEST['redirect_url'][0] == '/')) { header( 'Location: '.$_REQUEST['redirect_url']); - } else { + } + else if (isset(OC::$REQUESTEDAPP) && !empty(OC::$REQUESTEDAPP)) { + header( 'Location: '.OC::$WEBROOT.'/?app='.OC::$REQUESTEDAPP ); + } + else { header( 'Location: '.OC::$WEBROOT.'/'.OC_Appconfig::getValue('core', 'defaultpage', '?app=files')); } exit(); -- cgit v1.2.3 From c244daac897cf8a9e50297b8c9a643dcc9651338 Mon Sep 17 00:00:00 2001 From: Sam Tuke Date: Wed, 20 Jun 2012 16:24:49 +0100 Subject: removed readdir to fix bug oc-1054 --- apps/files_archive/lib/storage.php | 1 - apps/files_sharing/sharedstorage.php | 2 -- lib/filestorage.php | 1 - 3 files changed, 4 deletions(-) (limited to 'lib') diff --git a/apps/files_archive/lib/storage.php b/apps/files_archive/lib/storage.php index 2f10d6a3e4e..86761663611 100644 --- a/apps/files_archive/lib/storage.php +++ b/apps/files_archive/lib/storage.php @@ -49,7 +49,6 @@ class OC_Filestorage_Archive extends OC_Filestorage_Common{ OC_FakeDirStream::$dirs[$id]=$content; return opendir('fakedir://'.$id); } - public function readdir($path){} public function stat($path){ $ctime=filectime($this->path); $path=$this->stripPath($path); diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 9174334383c..1a6942ad160 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -139,8 +139,6 @@ class OC_Filestorage_Shared extends OC_Filestorage { } } - public function readdir( $path ) {} - public function is_dir($path) { if ($path == "" || $path == "/") { return true; diff --git a/lib/filestorage.php b/lib/filestorage.php index bf353bb0cce..71ef4aed00b 100644 --- a/lib/filestorage.php +++ b/lib/filestorage.php @@ -28,7 +28,6 @@ abstract class OC_Filestorage{ abstract public function mkdir($path); abstract public function rmdir($path); abstract public function opendir($path); - abstract public function readdir($path); abstract public function is_dir($path); abstract public function is_file($path); abstract public function stat($path); -- cgit v1.2.3 From 72215a818d0e222af80000909f9fa78243112533 Mon Sep 17 00:00:00 2001 From: Sam Tuke Date: Wed, 20 Jun 2012 18:25:12 +0100 Subject: added new user settings interface for deleting old file versions fixed OCA_VersionsexpireAll() to use native PHP readdir() removed local storage implementation of readdir() --- apps/files_versions/ajax/expireAll.php | 41 +++++++++++++++++ apps/files_versions/appinfo/app.php | 4 +- apps/files_versions/js/settings-personal.js | 51 ++++++++++++++++++++++ apps/files_versions/settings-personal.php | 8 ++++ .../files_versions/templates/settings-personal.php | 9 ++++ apps/files_versions/versions.php | 26 +++++------ lib/filestorage/local.php | 3 -- 7 files changed, 124 insertions(+), 18 deletions(-) create mode 100644 apps/files_versions/ajax/expireAll.php create mode 100644 apps/files_versions/js/settings-personal.js create mode 100644 apps/files_versions/settings-personal.php create mode 100644 apps/files_versions/templates/settings-personal.php (limited to 'lib') diff --git a/apps/files_versions/ajax/expireAll.php b/apps/files_versions/ajax/expireAll.php new file mode 100644 index 00000000000..f9cd74aed02 --- /dev/null +++ b/apps/files_versions/ajax/expireAll.php @@ -0,0 +1,41 @@ +. + * + */ + +// TODO: Allow admins to expire versions of any user +// TODO: Provide feedback as to how many versions were deleted + +// Check user and app status +OCP\JSON::checkLoggedIn(); +OCP\App::checkAppEnabled('files_versions'); + +if( OCA_Versions\Storage::expireAll() ){ + + OCP\JSON::success(); + die(); + +} else { + + OCP\JSON::error(); + die(); + +} \ No newline at end of file diff --git a/apps/files_versions/appinfo/app.php b/apps/files_versions/appinfo/app.php index 8b891848c57..ef2f54dd3f9 100644 --- a/apps/files_versions/appinfo/app.php +++ b/apps/files_versions/appinfo/app.php @@ -3,7 +3,9 @@ require_once('apps/files_versions/versions.php'); OCP\App::registerAdmin('files_versions', 'settings'); +OCP\App::registerPersonal('files_versions','settings-personal'); + OCP\Util::addscript('files_versions', 'versions'); // Listen to write signals -OCP\Util::connectHook('OC_Filesystem', 'post_write', "OCA_Versions\Storage", "write_hook"); +OCP\Util::connectHook('OC_Filesystem', 'post_write', "OCA_Versions\Storage", "write_hook"); \ No newline at end of file diff --git a/apps/files_versions/js/settings-personal.js b/apps/files_versions/js/settings-personal.js new file mode 100644 index 00000000000..d9456f3f2af --- /dev/null +++ b/apps/files_versions/js/settings-personal.js @@ -0,0 +1,51 @@ +// $(document).ready(function(){ +// $('#versions').change( function(){ +// OC.msg.startSaving('#calendar .msg') +// // Serialize the data +// var post = $( '#timezone' ).serialize(); +// $.post( OC.filePath('calendar', 'ajax/settings', 'settimezone.php'), post, function(data){ +// //OC.msg.finishedSaving('#calendar .msg', data); +// }); +// return false; +// }); +// }); + +$(document).ready(function(){ + // + $('#expireAllBtn').click(function(){ + + // Prevent page from reloading + event.preventDefault(); + + // Show loading gif + $('.expireAllLoading').show(); + + $.getJSON( + OC.filePath('files_versions','ajax','expireAll.php'), + function(result){ + if (result.status == 'success') { + $('.expireAllLoading').hide(); + $('#expireAllBtn').html('Expiration successful'); + } else { + + // Cancel loading + $('#expireAllBtn').html('Expiration failed'); + + // Show Dialog + OC.dialogs.alert( + 'Something went wrong, your files may not have been expired', + 'An error has occurred', + function(){ + $('#expireAllBtn').html(t('files_versions', 'Expire all versions')+''); + } + + ); + + } + } + + ); + + }); + +}); \ No newline at end of file diff --git a/apps/files_versions/settings-personal.php b/apps/files_versions/settings-personal.php new file mode 100644 index 00000000000..db80172979d --- /dev/null +++ b/apps/files_versions/settings-personal.php @@ -0,0 +1,8 @@ +fetchPage(); +?> \ No newline at end of file diff --git a/apps/files_versions/templates/settings-personal.php b/apps/files_versions/templates/settings-personal.php new file mode 100644 index 00000000000..7ff016b585e --- /dev/null +++ b/apps/files_versions/templates/settings-personal.php @@ -0,0 +1,9 @@ +
+
+ + Versions + +

This will delete all existing backup versions of your files

+ +
+
\ No newline at end of file diff --git a/apps/files_versions/versions.php b/apps/files_versions/versions.php index 6feb0cbb9c7..7522538caf2 100644 --- a/apps/files_versions/versions.php +++ b/apps/files_versions/versions.php @@ -333,9 +333,9 @@ class Storage { $foldername = \OCP\Config::getSystemValue('datadirectory') .'/' . \OCP\USER::getUser() .'/' . $directory; // have to set an absolute path for use with PHP's opendir as OC version doesn't work - $directoryHandle = opendir( $foldername ); - - while ( $contents = $view->readdir( $directoryHandle ) ) { + $directoryHandle = $view->opendir( \OCP\USER::getUser() . '/' . $directory ); + + while ( $contents = readdir( $directoryHandle ) ) { if ( $contents != '.' && $contents != '..') { @@ -373,17 +373,15 @@ class Storage { $dir = \OCP\Config::getSystemValue('files_versionsfolder', Storage::DEFAULTFOLDER); - deleteAll( $dir, true ); - -// if ( deleteAll( $dir, 1 ) ) { -// -// echo "

deleted ok

"; -// -// } else { -// -// echo "

not deleted

"; -// -// } + if ( deleteAll( $dir, true ) ) { + + return true; + + } else { + + return false; + + } } diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php index 27794fe17c0..44a2ab0f634 100644 --- a/lib/filestorage/local.php +++ b/lib/filestorage/local.php @@ -20,9 +20,6 @@ class OC_Filestorage_Local extends OC_Filestorage{ public function opendir($path){ return opendir($this->datadir.$path); } - public function readdir($handle){ - return readdir($handle); - } public function is_dir($path){ if(substr($path,-1)=='/'){ $path=substr($path,0,-1); -- cgit v1.2.3 From cc3835d65711a6db3472d2ef7f84a59b112dbe7c Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 20 Jun 2012 19:24:07 -0400 Subject: Only call OC_FileCache::get('/Shared') if it exists in the file cache, prevents premature addition of the Shared folder to the file cache Conflicts: lib/fileproxy/quota.php --- lib/fileproxy/quota.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/fileproxy/quota.php b/lib/fileproxy/quota.php index b0c3775b9db..7316224cc61 100644 --- a/lib/fileproxy/quota.php +++ b/lib/fileproxy/quota.php @@ -55,7 +55,12 @@ class OC_FileProxy_Quota extends OC_FileProxy{ */ private function getFreeSpace(){ $rootInfo=OC_FileCache_Cached::get(''); - $sharedInfo=OC_FileCache_Cached::get('/Shared'); + // TODO Remove after merge of share_api + if (OC_FileCache::inCache('/Shared')) { + $sharedInfo=OC_FileCache_Cached::get('/Shared'); + } else { + $sharedInfo = null; + } $usedSpace=isset($rootInfo['size'])?$rootInfo['size']:0; $usedSpace=isset($sharedInfo['size'])?$usedSpace-$sharedInfo['size']:$usedSpace; $totalSpace=$this->getQuota(); -- cgit v1.2.3 From 96d0b9834afda9d717631789210ede1dddebc86c Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 21 Jun 2012 09:58:04 +0200 Subject: fix mimetype for cdr files - bugfix for oc 559 --- lib/mimetypes.fixlist.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/mimetypes.fixlist.php b/lib/mimetypes.fixlist.php index a40fbd9e228..13e3f16b369 100644 --- a/lib/mimetypes.fixlist.php +++ b/lib/mimetypes.fixlist.php @@ -17,5 +17,6 @@ return array( 'xlsx'=>'application/msexcel', 'ppt'=>'application/mspowerpoint', 'pptx'=>'application/mspowerpoint', - 'sgf' => 'application/sgf' + 'sgf' => 'application/sgf', + 'cdr' => 'application/coreldraw' ); -- cgit v1.2.3 From e95055b2bdcd70568c4b4e21424800cab47a582b Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Thu, 21 Jun 2012 14:07:04 +0200 Subject: check if the data directory is accessible via http. Show a big security warning if yes --- lib/util.php | 53 ++++++++++++++++++++++++++++++++++++++------ settings/admin.php | 2 ++ settings/css/settings.css | 5 ++++- settings/templates/admin.php | 15 +++++++++++++ 4 files changed, 67 insertions(+), 8 deletions(-) mode change 100644 => 100755 settings/admin.php mode change 100644 => 100755 settings/templates/admin.php (limited to 'lib') diff --git a/lib/util.php b/lib/util.php index 7792f96d445..8a2d913109d 100755 --- a/lib/util.php +++ b/lib/util.php @@ -420,18 +420,57 @@ class OC_Util { } } - /** - * @brief Public function to sanitize HTML - * + /** + * @brief Public function to sanitize HTML + * * This function is used to sanitize HTML and should be applied on any string or array of strings before displaying it on a web page. * * @param string or array of strings - * @return array with sanitized strings or a single sinitized string, depends on the input parameter. + * @return array with sanitized strings or a single sinitized string, depends on the input parameter. */ - public static function sanitizeHTML( &$value ){ - if (is_array($value) || is_object($value)) array_walk_recursive($value,'OC_Util::sanitizeHTML'); - else $value = htmlentities($value, ENT_QUOTES, 'UTF-8'); //Specify encoding for PHP<5.4 + public static function sanitizeHTML( &$value ){ + if (is_array($value) || is_object($value)) array_walk_recursive($value,'OC_Util::sanitizeHTML'); + else $value = htmlentities($value, ENT_QUOTES, 'UTF-8'); //Specify encoding for PHP<5.4 return $value; } + + /** + * Check if the htaccess file is working buy creating a test file in the data directory and trying to access via http + */ + public static function ishtaccessworking() { + + // testdata + $filename='/htaccesstest.txt'; + $testcontent='testcontent'; + + // creating a test file + $testfile = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ).'/'.$filename; + $fp = @fopen($testfile, 'w'); + @fwrite($fp, $testcontent); + @fclose($fp); + + // accessing the file via http + $url = OC_Helper::serverProtocol(). '://' . OC_Helper::serverHost() . OC::$WEBROOT.'/data'.$filename; + $fp = @fopen($url, 'r'); + $content=@fread($fp, 2048); + @fclose($fp); + + // cleanup + @unlink($testfile); + + // does it work ? + if($content==$testcontent) { + return(false); + }else{ + return(true); + + } + + } + + + + + } diff --git a/settings/admin.php b/settings/admin.php old mode 100644 new mode 100755 index a997bad4e3c..8369ee64e06 --- a/settings/admin.php +++ b/settings/admin.php @@ -15,6 +15,7 @@ OC_App::setActiveNavigationEntry( "admin" ); $tmpl = new OC_Template( 'settings', 'admin', 'user'); $forms=OC_App::getForms('admin'); +$htaccessworking=OC_Util::ishtaccessworking(); $entries=OC_Log_Owncloud::getEntries(3); function compareEntries($a,$b){ @@ -24,6 +25,7 @@ usort($entries, 'compareEntries'); $tmpl->assign('loglevel',OC_Config::getValue( "loglevel", 2 )); $tmpl->assign('entries',$entries); +$tmpl->assign('htaccessworking',$htaccessworking); $tmpl->assign('forms',array()); foreach($forms as $form){ $tmpl->append('forms',$form); diff --git a/settings/css/settings.css b/settings/css/settings.css index df1e3cfd3c2..80e96df5e66 100644 --- a/settings/css/settings.css +++ b/settings/css/settings.css @@ -48,5 +48,8 @@ li.active { color:#000; } small.externalapp { color:#FFF; background-color:#BBB; font-weight:bold; font-size:6pt; padding:4px; border-radius: 4px;} span.version { margin-left:3em; color:#ddd; } -/* LOF */ +/* LOG */ #log { white-space:normal; } + +/* ADMIN */ +span.securitywarning {color:#C33; font-weight:bold; } diff --git a/settings/templates/admin.php b/settings/templates/admin.php old mode 100644 new mode 100755 index 38c6042c82a..a9f727d6764 --- a/settings/templates/admin.php +++ b/settings/templates/admin.php @@ -6,6 +6,21 @@ $levels=array('Debug','Info','Warning','Error','Fatal'); ?> + +
+ t('Security Warning');?> + + Your data directory and your files are probably accessible from the internet. The .htaccess file that ownCloud provides is not working. We strongly suggest that you configure your webserver in a way that the data directory is no longer accessible or you move the data directory outside the webserver document root. + +
+ + + -- cgit v1.2.3 From d0455c5819099751fb8614a76c272a23c6494b65 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 21 Jun 2012 17:37:53 +0200 Subject: truncate decrypted files based on filelength --- apps/files_encryption/lib/crypt.php | 8 ++++++-- apps/files_encryption/lib/cryptstream.php | 17 +++++++++++++--- apps/files_encryption/lib/proxy.php | 23 ++++++++++++++++++++-- apps/files_encryption/tests/encryption.php | 2 +- apps/files_encryption/tests/proxy.php | 15 +++++++++++++++ apps/files_encryption/tests/stream.php | 30 +++++++++++++++++++++-------- apps/files_encryption/tests/zeros | Bin 0 -> 10238 bytes lib/filecache.php | 10 +++++----- 8 files changed, 84 insertions(+), 21 deletions(-) create mode 100644 apps/files_encryption/tests/zeros (limited to 'lib') diff --git a/apps/files_encryption/lib/crypt.php b/apps/files_encryption/lib/crypt.php index 4c0ffa978ed..1c90954cec8 100644 --- a/apps/files_encryption/lib/crypt.php +++ b/apps/files_encryption/lib/crypt.php @@ -206,12 +206,16 @@ class OC_Crypt { /** * decrypt data in 8192b sized blocks */ - public static function blockDecrypt($data, $key=''){ + public static function blockDecrypt($data, $key='',$maxLength=0){ $result=''; while(strlen($data)){ $result.=self::decrypt(substr($data,0,8192),$key); $data=substr($data,8192); } - return rtrim($result, "\0"); + if($maxLength>0){ + return substr($result,0,$maxLength); + }else{ + return rtrim($result, "\0"); + } } } diff --git a/apps/files_encryption/lib/cryptstream.php b/apps/files_encryption/lib/cryptstream.php index 64fec381ded..4ef7d1e08bb 100644 --- a/apps/files_encryption/lib/cryptstream.php +++ b/apps/files_encryption/lib/cryptstream.php @@ -35,6 +35,7 @@ class OC_CryptStream{ private $meta=array();//header/meta for source stream private $count; private $writeCache; + private $size; private static $rootView; public function stream_open($path, $mode, $options, &$opened_path){ @@ -45,8 +46,14 @@ class OC_CryptStream{ if(dirname($path)=='streams' and isset(self::$sourceStreams[basename($path)])){ $this->source=self::$sourceStreams[basename($path)]['stream']; $this->path=self::$sourceStreams[basename($path)]['path']; + $this->size=self::$sourceStreams[basename($path)]['size']; }else{ $this->path=$path; + if($mode=='w' or $mode=='w+' or $mode=='wb' or $mode=='wb+'){ + $this->size=0; + }else{ + $this->size=self::$rootView->filesize($path,$mode); + } OC_FileProxy::$enabled=false;//disable fileproxies so we can open the source file $this->source=self::$rootView->fopen($path,$mode); OC_FileProxy::$enabled=true; @@ -77,14 +84,16 @@ class OC_CryptStream{ OCP\Util::writeLog('files_encryption','php bug 21641 no longer holds, decryption will not work',OCP\Util::FATAL); die(); } + $pos=ftell($this->source); $data=fread($this->source,8192); if(strlen($data)){ $result=OC_Crypt::decrypt($data); }else{ $result=''; } - if($this->stream_eof()){ - $result=rtrim($result, "\0"); + $length=$this->size-$pos; + if($length<8192){ + $result=substr($result,0,$length); } return $result; } @@ -116,6 +125,8 @@ class OC_CryptStream{ $data=substr($data,8192); } } + $currentPos=ftell($this->source); + $this->size=max($this->size,$currentPos); return $length; } @@ -159,7 +170,7 @@ class OC_CryptStream{ public function stream_close(){ $this->flush(); if($this->meta['mode']!='r' and $this->meta['mode']!='rb'){ - OC_FileCache::put($this->path,array('encrypted'=>true),''); + OC_FileCache::put($this->path,array('encrypted'=>true,'size'=>$this->size),''); } return fclose($this->source); } diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php index b9e719448a3..f25e4a662f6 100644 --- a/apps/files_encryption/lib/proxy.php +++ b/apps/files_encryption/lib/proxy.php @@ -66,15 +66,17 @@ class OC_FileProxy_Encryption extends OC_FileProxy{ public function preFile_put_contents($path,&$data){ if(self::shouldEncrypt($path)){ if (!is_resource($data)) {//stream put contents should have been converter to fopen + $size=strlen($data); $data=OC_Crypt::blockEncrypt($data); - OC_FileCache::put($path,array('encrypted'=>true),''); + OC_FileCache::put($path,array('encrypted'=>true,'size'=>$size),''); } } } public function postFile_get_contents($path,$data){ if(self::isEncrypted($path)){ - $data=OC_Crypt::blockDecrypt($data); + $cached=OC_FileCache_Cached::get($path,''); + $data=OC_Crypt::blockDecrypt($data,'',$cached['size']); } return $data; } @@ -108,4 +110,21 @@ class OC_FileProxy_Encryption extends OC_FileProxy{ } return $mime; } + + public function postStat($path,$data){ + if(self::isEncrypted($path)){ + $cached=OC_FileCache_Cached::get($path,''); + $data['size']=$cached['size']; + } + return $data; + } + + public function postFileSize($path,$size){ + if(self::isEncrypted($path)){ + $cached=OC_FileCache_Cached::get($path,''); + return $cached['size']; + }else{ + return $size; + } + } } diff --git a/apps/files_encryption/tests/encryption.php b/apps/files_encryption/tests/encryption.php index 70aa1daf4c3..286770a69f5 100644 --- a/apps/files_encryption/tests/encryption.php +++ b/apps/files_encryption/tests/encryption.php @@ -66,7 +66,7 @@ class Test_Encryption extends UnitTestCase { $this->assertEqual($decrypted,$source); $encrypted=OC_Crypt::blockEncrypt($source,$key); - $decrypted=OC_Crypt::blockDecrypt($encrypted,$key); + $decrypted=OC_Crypt::blockDecrypt($encrypted,$key,strlen($source)); $this->assertEqual($decrypted,$source); } } diff --git a/apps/files_encryption/tests/proxy.php b/apps/files_encryption/tests/proxy.php index 5616e2091a9..4533289265a 100644 --- a/apps/files_encryption/tests/proxy.php +++ b/apps/files_encryption/tests/proxy.php @@ -50,6 +50,7 @@ class Test_CryptProxy extends UnitTestCase { $fromFile=OC_Filesystem::file_get_contents('/file'); $this->assertNotEqual($original,$stored); + $this->assertEqual(strlen($original),strlen($fromFile)); $this->assertEqual($original,$fromFile); } @@ -88,6 +89,20 @@ class Test_CryptProxy extends UnitTestCase { $fromFile=OC_Filesystem::file_get_contents('/file'); $this->assertNotEqual($original,$stored); + $this->assertEqual(strlen($original),strlen($fromFile)); $this->assertEqual($original,$fromFile); + + $file=__DIR__.'/zeros'; + $original=file_get_contents($file); + + OC_Filesystem::file_put_contents('/file',$original); + + OC_FileProxy::$enabled=false; + $stored=OC_Filesystem::file_get_contents('/file'); + OC_FileProxy::$enabled=true; + + $fromFile=OC_Filesystem::file_get_contents('/file'); + $this->assertNotEqual($original,$stored); + $this->assertEqual(strlen($original),strlen($fromFile)); } } diff --git a/apps/files_encryption/tests/stream.php b/apps/files_encryption/tests/stream.php index 4ffeb6210a9..d95ea792f72 100644 --- a/apps/files_encryption/tests/stream.php +++ b/apps/files_encryption/tests/stream.php @@ -10,23 +10,23 @@ class Test_CryptStream extends UnitTestCase { private $tmpFiles=array(); function testStream(){ - $stream=$this->getStream('test1','w'); + $stream=$this->getStream('test1','w',strlen('foobar')); fwrite($stream,'foobar'); fclose($stream); - $stream=$this->getStream('test1','r'); + $stream=$this->getStream('test1','r',strlen('foobar')); $data=fread($stream,6); fclose($stream); $this->assertEqual('foobar',$data); $file=OC::$SERVERROOT.'/3rdparty/MDB2.php'; $source=fopen($file,'r'); - $target=$this->getStream('test2','w'); + $target=$this->getStream('test2','w',0); OCP\Files::streamCopy($source,$target); fclose($target); fclose($source); - $stream=$this->getStream('test2','r'); + $stream=$this->getStream('test2','r',filesize($file)); $data=stream_get_contents($stream); $original=file_get_contents($file); $this->assertEqual(strlen($original),strlen($data)); @@ -37,9 +37,10 @@ class Test_CryptStream extends UnitTestCase { * get a cryptstream to a temporary file * @param string $id * @param string $mode + * @param int size * @return resource */ - function getStream($id,$mode){ + function getStream($id,$mode,$size){ if($id===''){ $id=uniqid(); } @@ -50,7 +51,7 @@ class Test_CryptStream extends UnitTestCase { $file=$this->tmpFiles[$id]; } $stream=fopen($file,$mode); - OC_CryptStream::$sourceStreams[$id]=array('path'=>'dummy'.$id,'stream'=>$stream); + OC_CryptStream::$sourceStreams[$id]=array('path'=>'dummy'.$id,'stream'=>$stream,'size'=>$size); return fopen('crypt://streams/'.$id,$mode); } @@ -58,11 +59,24 @@ class Test_CryptStream extends UnitTestCase { $file=__DIR__.'/binary'; $source=file_get_contents($file); - $stream=$this->getStream('test','w'); + $stream=$this->getStream('test','w',strlen($source)); fwrite($stream,$source); fclose($stream); - $stream=$this->getStream('test','r'); + $stream=$this->getStream('test','r',strlen($source)); + $data=stream_get_contents($stream); + fclose($stream); + $this->assertEqual(strlen($data),strlen($source)); + $this->assertEqual($source,$data); + + $file=__DIR__.'/zeros'; + $source=file_get_contents($file); + + $stream=$this->getStream('test2','w',strlen($source)); + fwrite($stream,$source); + fclose($stream); + + $stream=$this->getStream('test2','r',strlen($source)); $data=stream_get_contents($stream); fclose($stream); $this->assertEqual(strlen($data),strlen($source)); diff --git a/apps/files_encryption/tests/zeros b/apps/files_encryption/tests/zeros new file mode 100644 index 00000000000..ff982acf423 Binary files /dev/null and b/apps/files_encryption/tests/zeros differ diff --git a/lib/filecache.php b/lib/filecache.php index 9963a5a3baf..d5458834e08 100644 --- a/lib/filecache.php +++ b/lib/filecache.php @@ -68,18 +68,18 @@ class OC_FileCache{ $path=$root.$path; $parent=self::getParentId($path); $id=self::getId($path,''); - if($id!=-1){ - self::update($id,$data); - return; - } if(isset(OC_FileCache_Cached::$savedData[$path])){ - $data=array_merge($data,OC_FileCache_Cached::$savedData[$path]); + $data=array_merge(OC_FileCache_Cached::$savedData[$path],$data); unset(OC_FileCache_Cached::$savedData[$path]); } if(!isset($data['size']) or !isset($data['mtime'])){//save incomplete data for the next time we write it OC_FileCache_Cached::$savedData[$path]=$data; return; } + if($id!=-1){ + self::update($id,$data); + return; + } if(!isset($data['encrypted'])){ $data['encrypted']=false; } -- cgit v1.2.3 From 56de98ed8cb74cc197d5b7cecdc519c2c267e3a5 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 21 Jun 2012 18:07:56 +0200 Subject: fix saved file size for uploaded files --- apps/files_encryption/lib/cryptstream.php | 8 ++++---- lib/filecache.php | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/apps/files_encryption/lib/cryptstream.php b/apps/files_encryption/lib/cryptstream.php index 4ef7d1e08bb..e0020537563 100644 --- a/apps/files_encryption/lib/cryptstream.php +++ b/apps/files_encryption/lib/cryptstream.php @@ -115,8 +115,9 @@ class OC_CryptStream{ $data=substr($block,0,$currentPos%8192).$data; fseek($this->source,-($currentPos%8192),SEEK_CUR); } - while(strlen($data)>0){ - if(strlen($data)<8192){ + $currentPos=ftell($this->source); + while($remainingLength=strlen($data)>0){ + if($remainingLength<8192){ $this->writeCache=$data; $data=''; }else{ @@ -125,8 +126,7 @@ class OC_CryptStream{ $data=substr($data,8192); } } - $currentPos=ftell($this->source); - $this->size=max($this->size,$currentPos); + $this->size=max($this->size,$currentPos+$length); return $length; } diff --git a/lib/filecache.php b/lib/filecache.php index d5458834e08..e3bcc7d0000 100644 --- a/lib/filecache.php +++ b/lib/filecache.php @@ -72,14 +72,14 @@ class OC_FileCache{ $data=array_merge(OC_FileCache_Cached::$savedData[$path],$data); unset(OC_FileCache_Cached::$savedData[$path]); } - if(!isset($data['size']) or !isset($data['mtime'])){//save incomplete data for the next time we write it - OC_FileCache_Cached::$savedData[$path]=$data; - return; - } if($id!=-1){ self::update($id,$data); return; } + if(!isset($data['size']) or !isset($data['mtime'])){//save incomplete data for the next time we write it + OC_FileCache_Cached::$savedData[$path]=$data; + return; + } if(!isset($data['encrypted'])){ $data['encrypted']=false; } -- cgit v1.2.3