From e5c009599d428db392e06e374bb5e68b0eb773c8 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 28 Mar 2012 16:38:42 +0200 Subject: remove check for variable which was set one line above - bugfix for oc-324 --- lib/db.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'lib') diff --git a/lib/db.php b/lib/db.php index 9fab51edfcd..a0fb6c385d8 100644 --- a/lib/db.php +++ b/lib/db.php @@ -318,9 +318,6 @@ class OC_DB { // Make changes and save them to an in-memory file $file2 = 'static://db_scheme'; - if($file2 == ''){ - die('could not create tempfile in get_temp_dir() - aborting'); - } $content = str_replace( '*dbname*', $CONFIG_DBNAME, $content ); $content = str_replace( '*dbprefix*', $CONFIG_DBTABLEPREFIX, $content ); if( $CONFIG_DBTYPE == 'pgsql' ){ //mysql support it too but sqlite doesn't -- cgit v1.2.3 From d8e9db207f94d8a46cd8a81caa1b49cd64843259 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 28 Mar 2012 22:30:55 +0200 Subject: add tempory folder utility to OC_Helper --- lib/helper.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/helper.php b/lib/helper.php index 66f31d929be..efff00c2fe6 100755 --- a/lib/helper.php +++ b/lib/helper.php @@ -432,6 +432,19 @@ class OC_Helper { self::$tmpFiles[]=$file; return $file; } + + /** + * create a temporary folder with an unique filename + * @return string + * + * temporary files are automatically cleaned up after the script is finished + */ + public static function tmpFolder(){ + $path=get_temp_dir().'/'.md5(time().rand()); + mkdir($path); + self::$tmpFiles[]=$path; + return $path.'/'; + } /** * remove all files created by self::tmpFile @@ -439,7 +452,7 @@ class OC_Helper { public static function cleanTmp(){ foreach(self::$tmpFiles as $file){ if(file_exists($file)){ - unlink($file); + self::rmdirr($file); } } } -- cgit v1.2.3 From d6a9af31389819c95084e33aab3c7f4a6d4cbef8 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 29 Mar 2012 00:07:28 +0200 Subject: add support for installing apps from tgz --- lib/installer.php | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/installer.php b/lib/installer.php index 2a9676998f6..db64d8e32d5 100644 --- a/lib/installer.php +++ b/lib/installer.php @@ -62,7 +62,7 @@ class OC_Installer{ //download the file if necesary if($data['source']=='http'){ - $path=OC_Helper::tmpFile('.zip'); + $path=OC_Helper::tmpFile(); if(!isset($data['href'])){ OC_Log::write('core','No href specified when installing app from http',OC_Log::ERROR); return false; @@ -76,14 +76,24 @@ class OC_Installer{ $path=$data['path']; } + //detect the archive type + $mime=OC_Helper::getMimeType($path); + if($mime=='application/zip'){ + rename($path,$path.'.zip'); + $path.='.zip'; + }elseif($mime=='application/x-gzip'){ + rename($path,$path.'.tgz'); + $path.='.tgz'; + }else{ + OC_Log::write('core','Archives of type '.$mime.' are not supported',OC_Log::ERROR); + return false; + } + //extract the archive in a temporary folder - $extractDir=tempnam(get_temp_dir(),'oc_installer_uncompressed_'); - unlink($extractDir); + $extractDir=OC_Helper::tmpFolder(); mkdir($extractDir); - $zip = new ZipArchive; - if($zip->open($path)===true){ - $zip->extractTo($extractDir); - $zip->close(); + if($archive=OC_Archive::open($path)){ + $archive->extract($extractDir); } else { OC_Log::write('core','Failed to open archive when installing app',OC_Log::ERROR); OC_Helper::rmdirr($extractDir); -- cgit v1.2.3 From 60ba5508a4bfaf0581301a6240011060a7432997 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 29 Mar 2012 00:11:29 +0200 Subject: add support for installing apps from a subfolder in the zip/tgz file --- lib/installer.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lib') diff --git a/lib/installer.php b/lib/installer.php index db64d8e32d5..c5ecacae544 100644 --- a/lib/installer.php +++ b/lib/installer.php @@ -104,6 +104,17 @@ class OC_Installer{ } //load the info.xml file of the app + if(!is_file($extractDir.'/appinfo/info.xml')){ + //try to find it in a subdir + $dh=opendir($extractDir); + while($folder=readdir($dh)){ + if(substr($folder,0,1)!='.' and is_dir($extractDir.'/'.$folder)){ + if(is_file($extractDir.'/'.$folder.'/appinfo/info.xml')){ + $extractDir.='/'.$folder; + } + } + } + } if(!is_file($extractDir.'/appinfo/info.xml')){ OC_Log::write('core','App does not provide an info.xml file',OC_Log::ERROR); OC_Helper::rmdirr($extractDir); -- cgit v1.2.3 From 7bc9fa765c75846e5a293ea534505d3722d612f5 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 30 Mar 2012 13:48:44 +0200 Subject: optimizations for updateApps --- lib/app.php | 29 +++++++++++++++++++++-------- lib/installer.php | 4 ++-- 2 files changed, 23 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/app.php b/lib/app.php index 3daf539aa21..5ee9a0e5654 100755 --- a/lib/app.php +++ b/lib/app.php @@ -265,19 +265,20 @@ class OC_App{ /** * @brief Read app metadata from the info.xml file * @param string $appid id of the app or the path of the info.xml file + * @param boolean path (optional) * @returns array */ - public static function getAppInfo($appid){ - if(is_file($appid)){ + public static function getAppInfo($appid,$path=false){ + if($path){ $file=$appid; }else{ $file=OC::$APPSROOT.'/apps/'.$appid.'/appinfo/info.xml'; - if(!is_file($file)){ - return array(); - } } $data=array(); $content=file_get_contents($file); + if(!$content){ + return; + } $xml = new SimpleXMLElement($content); $data['info']=array(); foreach($xml->children() as $child){ @@ -381,9 +382,8 @@ class OC_App{ */ public static function updateApps(){ // The rest comes here - $apps = OC_Appconfig::getApps(); - foreach( $apps as $app ){ - $installedVersion=OC_Appconfig::getValue($app,'installed_version'); + $versions = self::getAppVersions(); + foreach( $versions as $app=>$installedVersion ){ $appInfo=OC_App::getAppInfo($app); if (isset($appInfo['version'])) { $currentVersion=$appInfo['version']; @@ -395,6 +395,19 @@ class OC_App{ } } + /** + * get the installed version of all papps + */ + public static function getAppVersions(){ + $versions=array(); + $query = OC_DB::prepare( 'SELECT appid, configvalue FROM *PREFIX*appconfig WHERE configkey = "installed_version"' ); + $result = $query->execute(); + while($row = $result->fetchRow()){ + $versions[$row['appid']]=$row['configvalue']; + } + return $versions; + } + /** * update the database for the app and call the update script * @param string appid diff --git a/lib/installer.php b/lib/installer.php index c5ecacae544..38e17130e3c 100644 --- a/lib/installer.php +++ b/lib/installer.php @@ -123,7 +123,7 @@ class OC_Installer{ } return false; } - $info=OC_App::getAppInfo($extractDir.'/appinfo/info.xml'); + $info=OC_App::getAppInfo($extractDir.'/appinfo/info.xml',true); $basedir=OC::$APPSROOT.'/apps/'.$info['id']; //check if an app with the same id is already installed @@ -296,7 +296,7 @@ class OC_Installer{ if(is_file(OC::$APPSROOT."/apps/$app/appinfo/install.php")){ include(OC::$APPSROOT."/apps/$app/appinfo/install.php"); } - $info=OC_App::getAppInfo(OC::$APPSROOT."/apps/$app/appinfo/info.xml"); + $info=OC_App::getAppInfo($app); OC_Appconfig::setValue($app,'installed_version',$info['version']); return $info; } -- cgit v1.2.3 From a07c6b1a2ea66f00b3e85d480703ca06a4b241be Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 30 Mar 2012 14:00:24 +0200 Subject: optimizations for loadApps --- lib/app.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/app.php b/lib/app.php index 5ee9a0e5654..fa0a1d22d15 100755 --- a/lib/app.php +++ b/lib/app.php @@ -55,12 +55,10 @@ class OC_App{ } // The rest comes here - $apps = OC_Appconfig::getApps(); + $apps = self::getEnabledApps(); foreach( $apps as $app ){ - if( self::isEnabled( $app )){ - if(is_file(OC::$APPSROOT.'/apps/'.$app.'/appinfo/app.php')){ - require( $app.'/appinfo/app.php' ); - } + if(is_file(OC::$APPSROOT.'/apps/'.$app.'/appinfo/app.php')){ + require( $app.'/appinfo/app.php' ); } } @@ -70,6 +68,19 @@ class OC_App{ return true; } + /** + * get all enabled apps + */ + public static function getEnabledApps(){ + $apps=array(); + $query = OC_DB::prepare( 'SELECT appid FROM *PREFIX*appconfig WHERE configkey = "enabled" AND configvalue="yes"' ); + $query->execute(); + while($row=$query->fetchRow()){ + $apps[]=$row['appid']; + } + return $apps; + } + /** * @brief checks whether or not an app is enabled * @param $app app -- cgit v1.2.3 From 523fdda39915dd49190727ac74458a28f2d00f10 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 30 Mar 2012 14:39:07 +0200 Subject: add the option to only load apps of a specific type --- apps/files_archive/appinfo/info.xml | 3 ++ apps/files_encryption/appinfo/info.xml | 3 ++ apps/files_remote/appinfo/info.xml | 3 ++ apps/files_sharing/appinfo/info.xml | 3 ++ files/ajax/download.php | 3 ++ files/ajax/list.php | 3 ++ files/ajax/mimeicon.php | 3 ++ files/webdav.php | 3 ++ lib/app.php | 51 ++++++++++++++++++++++++++++++---- lib/base.php | 7 ++++- 10 files changed, 76 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/apps/files_archive/appinfo/info.xml b/apps/files_archive/appinfo/info.xml index df767d39f6b..236b5a64b05 100644 --- a/apps/files_archive/appinfo/info.xml +++ b/apps/files_archive/appinfo/info.xml @@ -7,4 +7,7 @@ AGPL Robin Appelman 3 + + + diff --git a/apps/files_encryption/appinfo/info.xml b/apps/files_encryption/appinfo/info.xml index 053044aaed2..691b265bf60 100644 --- a/apps/files_encryption/appinfo/info.xml +++ b/apps/files_encryption/appinfo/info.xml @@ -7,4 +7,7 @@ AGPL Robin Appelman 3 + + + diff --git a/apps/files_remote/appinfo/info.xml b/apps/files_remote/appinfo/info.xml index 0720b6095b9..8cf66ddbc37 100644 --- a/apps/files_remote/appinfo/info.xml +++ b/apps/files_remote/appinfo/info.xml @@ -7,4 +7,7 @@ AGPL Robin Appelman 3 + + + diff --git a/apps/files_sharing/appinfo/info.xml b/apps/files_sharing/appinfo/info.xml index abf847b4483..8fda775520b 100644 --- a/apps/files_sharing/appinfo/info.xml +++ b/apps/files_sharing/appinfo/info.xml @@ -8,4 +8,7 @@ Michael Gapczynski 2 + + + diff --git a/files/ajax/download.php b/files/ajax/download.php index 198069f3fa1..39852613ab9 100644 --- a/files/ajax/download.php +++ b/files/ajax/download.php @@ -21,6 +21,9 @@ * */ +// only need filesystem apps +$RUNTIME_APPTYPES=array('filesystem'); + // Init owncloud require_once('../../lib/base.php'); diff --git a/files/ajax/list.php b/files/ajax/list.php index 8a414827e1c..ec9ab7342dd 100644 --- a/files/ajax/list.php +++ b/files/ajax/list.php @@ -1,5 +1,8 @@ children() as $child){ - $data[$child->getName()]=(string)$child; + if($child->getName()=='types'){ + $data['types']=array(); + foreach($child->children() as $type){ + $data['types'][]=$type->getName(); + } + }else{ + $data[$child->getName()]=(string)$child; + } } + self::$appInfo[$appid]=$data; return $data; } diff --git a/lib/base.php b/lib/base.php index b07ac5af416..b031572f177 100644 --- a/lib/base.php +++ b/lib/base.php @@ -333,8 +333,13 @@ class OC{ // Load Apps // This includes plugins for users and filesystems as well global $RUNTIME_NOAPPS; + global $RUNTIME_APPTYPES; if(!$RUNTIME_NOAPPS ){ - OC_App::loadApps(); + if($RUNTIME_APPTYPES){ + OC_App::loadApps($RUNTIME_APPTYPES); + }else{ + OC_App::loadApps(); + } } //make sure temporary files are cleaned up -- cgit v1.2.3 From 7552390031ee10ed5006ef927fa1f55cdd148554 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 30 Mar 2012 18:12:33 +0200 Subject: add path_hash to the filesystem cache --- db_structure.xml | 28 ++++++++++++++++++++++------ lib/filecache.php | 28 ++++++++++++++-------------- lib/util.php | 2 +- 3 files changed, 37 insertions(+), 21 deletions(-) (limited to 'lib') diff --git a/db_structure.xml b/db_structure.xml index 5eef44d8e84..82d2a731d4c 100644 --- a/db_structure.xml +++ b/db_structure.xml @@ -64,6 +64,15 @@ 512 + + path_hash + text + + + true + 32 + + parent integer @@ -79,7 +88,7 @@ true - 512 + 300 @@ -159,14 +168,13 @@ 1 - + parent_index @@ -176,6 +184,14 @@ + + name_index + + name + ascending + + + parent_name_index diff --git a/lib/filecache.php b/lib/filecache.php index 280a9929db0..a8c48e3f144 100644 --- a/lib/filecache.php +++ b/lib/filecache.php @@ -59,8 +59,8 @@ class OC_FileCache{ $root=''; } $path=$root.$path; - $query=OC_DB::prepare('SELECT ctime,mtime,mimetype,size,encrypted,versioned,writable FROM *PREFIX*fscache WHERE path=?'); - $result=$query->execute(array($path))->fetchRow(); + $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{ @@ -111,8 +111,8 @@ class OC_FileCache{ } $mimePart=dirname($data['mimetype']); $user=OC_User::getUser(); - $query=OC_DB::prepare('INSERT INTO *PREFIX*fscache(parent, name, path, size, mtime, ctime, mimetype, mimepart,user,writable,encrypted,versioned) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)'); - $result=$query->execute(array($parent,basename($path),$path,$data['size'],$data['mtime'],$data['ctime'],$data['mimetype'],$mimePart,$user,$data['writable'],$data['encrypted'],$data['versioned'])); + $query=OC_DB::prepare('INSERT INTO *PREFIX*fscache(parent, name, path, path_hash, size, mtime, ctime, mimetype, mimepart,user,writable,encrypted,versioned) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)'); + $result=$query->execute(array($parent,basename($path),$path,md5($path),$data['size'],$data['mtime'],$data['ctime'],$data['mimetype'],$mimePart,$user,$data['writable'],$data['encrypted'],$data['versioned'])); if(OC_DB::isError($result)){ OC_Log::write('files','error while writing file('.$path.') to cache',OC_Log::ERROR); } @@ -162,8 +162,8 @@ class OC_FileCache{ $oldPath=$root.$oldPath; $newPath=$root.$newPath; $newParent=self::getParentId($newPath); - $query=OC_DB::prepare('UPDATE *PREFIX*fscache SET parent=? ,name=?, path=? WHERE path=?'); - $query->execute(array($newParent,basename($newPath),$newPath,$oldPath)); + $query=OC_DB::prepare('UPDATE *PREFIX*fscache SET parent=? ,name=?, path=?, path_hash=? WHERE path_hash=?'); + $query->execute(array($newParent,basename($newPath),$newPath,md5($newPath),md5($oldPath))); } /** @@ -285,12 +285,12 @@ class OC_FileCache{ * @return int */ private static function getFileId($path){ - $query=OC_DB::prepare('SELECT id FROM *PREFIX*fscache WHERE 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; } - $result=$query->execute(array($path)); + $result=$query->execute(array(md5($path))); if(OC_DB::isError($result)){ OC_Log::write('files','error while getting file id of '.$path,OC_Log::ERROR); return -1; @@ -367,8 +367,8 @@ class OC_FileCache{ } } $path=$root.$path; - $query=OC_DB::prepare('SELECT ctime,mtime,mimetype,size,encrypted,versioned,writable FROM *PREFIX*fscache WHERE path=?'); - $result=$query->execute(array($path))->fetchRow(); + $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]); @@ -389,8 +389,8 @@ class OC_FileCache{ } } $path=$root.$path; - $query=OC_DB::prepare('SELECT size FROM *PREFIX*fscache WHERE path=?'); - $result=$query->execute(array($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 @@ -579,8 +579,8 @@ class OC_FileCache{ $mtime=$view->filemtime($path); $isDir=$view->is_dir($path); $path=$root.$path; - $query=OC_DB::prepare('SELECT mtime FROM *PREFIX*fscache WHERE path=?'); - $result=$query->execute(array($path)); + $query=OC_DB::prepare('SELECT mtime FROM *PREFIX*fscache WHERE path_hash=?'); + $result=$query->execute(array(md5($path))); if($row=$result->fetchRow()){ $cachedMTime=$row['mtime']; return ($mtime>$cachedMTime); diff --git a/lib/util.php b/lib/util.php index fa5b3daaab6..529b6d958fb 100644 --- a/lib/util.php +++ b/lib/util.php @@ -66,7 +66,7 @@ class OC_Util { * @return array */ public static function getVersion(){ - return array(3,00,3); + return array(3,00,4); } /** -- cgit v1.2.3 From 65eee1f69dbbbe86bb4bf0716a464dc9f2c66a67 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 30 Mar 2012 19:44:38 +0200 Subject: clean pre-path_hash fscache entries --- db_structure.xml | 3 +-- files/ajax/scan.php | 1 + lib/filecache.php | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/db_structure.xml b/db_structure.xml index 82d2a731d4c..2df218d359c 100644 --- a/db_structure.xml +++ b/db_structure.xml @@ -67,8 +67,7 @@ path_hash text - - + true 32 diff --git a/files/ajax/scan.php b/files/ajax/scan.php index 565275911b4..db09b7d5c64 100644 --- a/files/ajax/scan.php +++ b/files/ajax/scan.php @@ -17,6 +17,7 @@ if($force or !OC_FileCache::inCache('')){ if(!$checkOnly){ OC_DB::beginTransaction(); OC_FileCache::scan('',$eventSource); + OC_FileCache::clean(); OC_DB::commit(); $eventSource->send('success',true); }else{ diff --git a/lib/filecache.php b/lib/filecache.php index a8c48e3f144..86d865ed9f3 100644 --- a/lib/filecache.php +++ b/lib/filecache.php @@ -637,6 +637,14 @@ class OC_FileCache{ self::fileSystemWatcherWrite(array('path'=>$path),$root); } } + + /** + * clean old pre-path_hash entries + */ + public static function clean(){ + $query=OC_DB::prepare('DELETE FROM *PREFIX*fscache WHERE LENGTH(path_hash)<30'); + $query->execute(); + } } //watch for changes and try to keep the cache up to date -- cgit v1.2.3 From 3a4521a012fe75d8ec3685e1eb87374e5abd9da2 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 30 Mar 2012 23:15:48 +0200 Subject: Add support for logging to syslog --- lib/log.php | 71 ++++++++++--------------------------------- lib/log/owncloud.php | 78 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/log/syslog.php | 37 +++++++++++++++++++++++ settings/ajax/getlog.php | 2 +- settings/log.php | 2 +- 5 files changed, 133 insertions(+), 57 deletions(-) create mode 100644 lib/log/owncloud.php create mode 100644 lib/log/syslog.php (limited to 'lib') diff --git a/lib/log.php b/lib/log.php index 4e450a027f5..8bb2839be66 100644 --- a/lib/log.php +++ b/lib/log.php @@ -1,78 +1,39 @@ . - * + * Copyright (c) 2012 Bart Visscher + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. */ /** - *logging utilities + * logging utilities * - * Log is saved at data/owncloud.log (on default) + * Log is saved by default at data/owncloud.log using OC_Log_Owncloud. + * Selecting other backend is done with a config option 'log_type'. */ -class OC_Log{ +class OC_Log { const DEBUG=0; const INFO=1; const WARN=2; const ERROR=3; const FATAL=4; + static protected $class = null; + /** * write a message in the log * @param string $app * @param string $message * @param int level */ - public static function write($app,$message,$level){ - $minLevel=OC_Config::getValue( "loglevel", 2 ); - if($level>=$minLevel){ - $datadir=OC_Config::getValue( "datadirectory", OC::$SERVERROOT.'/data' ); - $logFile=OC_Config::getValue( "logfile", $datadir.'/owncloud.log' ); - $entry=array('app'=>$app,'message'=>$message,'level'=>$level,'time'=>time()); - $fh=fopen($logFile,'a'); - fwrite($fh,json_encode($entry)."\n"); - fclose($fh); - } - } - - /** - * get entries from the log in reverse chronological order - * @param int limit - * @param int offset - * @return array - */ - public static function getEntries($limit=50,$offset=0){ - $datadir=OC_Config::getValue( "datadirectory", OC::$SERVERROOT.'/data' ); - $logFile=OC_Config::getValue( "logfile", $datadir.'/owncloud.log' ); - $entries=array(); - if(!file_exists($logFile)){ - return array(); - } - $contents=file($logFile); - if(!$contents){//error while reading log - return array(); - } - $end=max(count($contents)-$offset-1,0); - $start=max($end-$limit,0); - for($i=$end;$i>$start;$i--){ - $entries[]=json_decode($contents[$i]); + public static function write($app, $message, $level) { + if (!self::$class) { + self::$class = 'OC_Log_'.ucfirst(OC_Config::getValue('log_type', 'owncloud')); + call_user_func(array(self::$class, 'init')); } - return $entries; + $log_class=self::$class; + $log_class::write($app, $message, $level); } } diff --git a/lib/log/owncloud.php b/lib/log/owncloud.php new file mode 100644 index 00000000000..6df346e9b17 --- /dev/null +++ b/lib/log/owncloud.php @@ -0,0 +1,78 @@ +. + * + */ + +/** + * logging utilities + * + * Log is saved at data/owncloud.log (on default) + */ + +class OC_Log_Owncloud { + /** + * Init class data + */ + public static function init() { + } + + /** + * write a message in the log + * @param string $app + * @param string $message + * @param int level + */ + public static function write($app, $message, $level) { + $minLevel=OC_Config::getValue( "loglevel", 2 ); + if($level>=$minLevel){ + $datadir=OC_Config::getValue( "datadirectory", OC::$SERVERROOT.'/data' ); + $logFile=OC_Config::getValue( "logfile", $datadir.'/owncloud.log' ); + $entry=array('app'=>$app, 'message'=>$message, 'level'=>$level,'time'=>time()); + $fh=fopen($logFile, 'a'); + fwrite($fh, json_encode($entry)."\n"); + fclose($fh); + } + } + + /** + * get entries from the log in reverse chronological order + * @param int limit + * @param int offset + * @return array + */ + public static function getEntries($limit=50, $offset=0){ + $datadir=OC_Config::getValue( "datadirectory", OC::$SERVERROOT.'/data' ); + $logFile=OC_Config::getValue( "logfile", $datadir.'/owncloud.log' ); + $entries=array(); + if(!file_exists($logFile)) { + return array(); + } + $contents=file($logFile); + if(!$contents) {//error while reading log + return array(); + } + $end=max(count($contents)-$offset-1, 0); + $start=max($end-$limit,0); + for($i=$end;$i>$start;$i--) { + $entries[]=json_decode($contents[$i]); + } + return $entries; + } +} diff --git a/lib/log/syslog.php b/lib/log/syslog.php new file mode 100644 index 00000000000..d1fb28d8b0a --- /dev/null +++ b/lib/log/syslog.php @@ -0,0 +1,37 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +class OC_Log_Syslog { + static protected $levels = array( + OC_Log::DEBUG => LOG_DEBUG, + OC_Log::INFO => LOG_INFO, + OC_Log::WARN => LOG_WARNING, + OC_Log::ERROR => LOG_ERR, + OC_Log::FATAL => LOG_CRIT, + ); + + /** + * Init class data + */ + public static function init() { + openlog('ownCloud', LOG_PID | LOG_CONS, LOG_USER); + // Close at shutdown + register_shutdown_function('closelog'); + } + + /** + * write a message in the log + * @param string $app + * @param string $message + * @param int level + */ + public static function write($app, $message, $level) { + $syslog_level = self::$levels[$level]; + syslog($syslog_level, '{'.$app.'} '.$message); + } +} diff --git a/settings/ajax/getlog.php b/settings/ajax/getlog.php index 600ebefcece..ed48b2cae1a 100644 --- a/settings/ajax/getlog.php +++ b/settings/ajax/getlog.php @@ -13,5 +13,5 @@ OC_JSON::checkAdminUser(); $count=(isset($_GET['count']))?$_GET['count']:50; $offset=(isset($_GET['offset']))?$_GET['offset']:0; -$entries=OC_Log::getEntries($count,$offset); +$entries=OC_Log_Owncloud::getEntries($count,$offset); OC_JSON::success(array("data" => $entries)); diff --git a/settings/log.php b/settings/log.php index 946f2b6f8e5..ddbf72c4433 100644 --- a/settings/log.php +++ b/settings/log.php @@ -28,7 +28,7 @@ OC_Util::addStyle( "settings", "settings" ); OC_Util::addScript( "settings", "apps" ); OC_App::setActiveNavigationEntry( "core_log" ); -$entries=OC_Log::getEntries(); +$entries=OC_Log_Owncloud::getEntries(); OC_Util::addScript('settings','log'); OC_Util::addStyle('settings','settings'); -- cgit v1.2.3 From a7438189f315288c5e57bbf3bfb59a37c896cd6c Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 30 Mar 2012 23:31:05 +0200 Subject: Move more from base init to separate functions --- lib/base.php | 64 +++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 29 deletions(-) (limited to 'lib') diff --git a/lib/base.php b/lib/base.php index b031572f177..e9788f54b66 100644 --- a/lib/base.php +++ b/lib/base.php @@ -229,6 +229,39 @@ 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.6.4.min" ); + OC_Util::addScript( "jquery-ui-1.8.16.custom.min" ); + OC_Util::addScript( "jquery-showpassword" ); + OC_Util::addScript( "jquery.infieldlabel.min" ); + OC_Util::addScript( "jquery-tipsy" ); + OC_Util::addScript( "oc-dialogs" ); + OC_Util::addScript( "js" ); + OC_Util::addScript( "eventsource" ); + OC_Util::addScript( "config" ); + //OC_Util::addScript( "multiselect" ); + OC_Util::addScript('search','result'); + OC_Util::addStyle( "styles" ); + OC_Util::addStyle( "multiselect" ); + OC_Util::addStyle( "jquery-ui-1.8.16.custom" ); + OC_Util::addStyle( "jquery-tipsy" ); + } + + public static function initSession() { + ini_set('session.cookie_httponly','1;'); + session_start(); + } + public static function init(){ // register autoloader spl_autoload_register(array('OC','autoload')); @@ -272,35 +305,8 @@ class OC{ self::checkSSL(); self::checkUpgrade(); - ini_set('session.cookie_httponly','1;'); - session_start(); - - // 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.6.4.min" ); - OC_Util::addScript( "jquery-ui-1.8.16.custom.min" ); - OC_Util::addScript( "jquery-showpassword" ); - OC_Util::addScript( "jquery.infieldlabel.min" ); - OC_Util::addScript( "jquery-tipsy" ); - OC_Util::addScript( "oc-dialogs" ); - OC_Util::addScript( "js" ); - OC_Util::addScript( "eventsource" ); - OC_Util::addScript( "config" ); - //OC_Util::addScript( "multiselect" ); - OC_Util::addScript('search','result'); - OC_Util::addStyle( "styles" ); - OC_Util::addStyle( "multiselect" ); - OC_Util::addStyle( "jquery-ui-1.8.16.custom" ); - OC_Util::addStyle( "jquery-tipsy" ); + self::initSession(); + self::initTemplateEngine(); $errors=OC_Util::checkServer(); if(count($errors)>0) { -- cgit v1.2.3 From 3300d6ea532a973e987c7aeeef1af63a60487c58 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 30 Mar 2012 23:33:36 +0200 Subject: checkUpgrade has to be after template initialization The error path of checkUpgrade uses the template --- lib/base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/base.php b/lib/base.php index e9788f54b66..22f7f4ea486 100644 --- a/lib/base.php +++ b/lib/base.php @@ -303,10 +303,10 @@ class OC{ self::checkInstalled(); self::checkSSL(); - self::checkUpgrade(); self::initSession(); self::initTemplateEngine(); + self::checkUpgrade(); $errors=OC_Util::checkServer(); if(count($errors)>0) { -- cgit v1.2.3 From 20fc23c82bbcaff56caafe6a6cc0ef15db9b2bf8 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 30 Mar 2012 23:40:16 +0200 Subject: Move logfile determination to init function --- lib/log/owncloud.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/log/owncloud.php b/lib/log/owncloud.php index 6df346e9b17..5e143205563 100644 --- a/lib/log/owncloud.php +++ b/lib/log/owncloud.php @@ -27,10 +27,14 @@ */ class OC_Log_Owncloud { + static protected $logFile; + /** * Init class data */ public static function init() { + $datadir=OC_Config::getValue( "datadirectory", OC::$SERVERROOT.'/data' ); + self::$logFile=OC_Config::getValue( "logfile", $datadir.'/owncloud.log' ); } /** @@ -42,10 +46,8 @@ class OC_Log_Owncloud { public static function write($app, $message, $level) { $minLevel=OC_Config::getValue( "loglevel", 2 ); if($level>=$minLevel){ - $datadir=OC_Config::getValue( "datadirectory", OC::$SERVERROOT.'/data' ); - $logFile=OC_Config::getValue( "logfile", $datadir.'/owncloud.log' ); $entry=array('app'=>$app, 'message'=>$message, 'level'=>$level,'time'=>time()); - $fh=fopen($logFile, 'a'); + $fh=fopen(self::$logFile, 'a'); fwrite($fh, json_encode($entry)."\n"); fclose($fh); } @@ -58,10 +60,9 @@ class OC_Log_Owncloud { * @return array */ public static function getEntries($limit=50, $offset=0){ - $datadir=OC_Config::getValue( "datadirectory", OC::$SERVERROOT.'/data' ); - $logFile=OC_Config::getValue( "logfile", $datadir.'/owncloud.log' ); + self::init(); $entries=array(); - if(!file_exists($logFile)) { + if(!file_exists(self::$logFile)) { return array(); } $contents=file($logFile); -- cgit v1.2.3 From b72d7f1ab324aa5669a1cce69564ff7b10551084 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 31 Mar 2012 16:20:32 +0200 Subject: make sure output buffering is dissabled when using eventsource --- lib/eventsource.php | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/eventsource.php b/lib/eventsource.php index 523f72403c3..dc28616c2dd 100644 --- a/lib/eventsource.php +++ b/lib/eventsource.php @@ -32,6 +32,7 @@ class OC_EventSource{ private $fallBackId=0; public function __construct(){ + @ob_end_clean(); header('Cache-Control: no-cache'); $this->fallback=isset($_GET['fallback']) and $_GET['fallback']=='true'; if($this->fallback){ -- cgit v1.2.3 From 9d2f8aa717826c1db8f8ec5f49a4128af3651edb Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 31 Mar 2012 16:24:53 +0200 Subject: send more progress updates when scanning large folders --- lib/filecache.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/filecache.php b/lib/filecache.php index 86d865ed9f3..59b0fb1b503 100644 --- a/lib/filecache.php +++ b/lib/filecache.php @@ -469,6 +469,10 @@ class OC_FileCache{ * @param string root (optionak) */ public static function scan($path,$eventSource=false,&$count=0,$root=''){ + if($eventSource){ + $eventSource->send('scanning',array('file'=>$path,'count'=>$count)); + } + $lastSend=$count; if(!$root){ $view=OC_Filesystem::getView(); }else{ @@ -482,13 +486,15 @@ class OC_FileCache{ if($filename != '.' and $filename != '..'){ $file=$path.'/'.$filename; if($view->is_dir($file.'/')){ - if($eventSource){ - $eventSource->send('scanning',array('file'=>$file,'count'=>$count)); - } self::scan($file,$eventSource,$count,$root); }else{ $totalSize+=self::scanFile($file,$root); $count++; + if($count>$lastSend+25){ + if($eventSource){ + $eventSource->send('scanning',array('file'=>$path,'count'=>$count)); + } + } } } } -- cgit v1.2.3 From ebc7a6a0a6249213122bf97104f850d2ce6b7c1a Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 31 Mar 2012 16:28:22 +0200 Subject: dont send to much when scanning large folders --- lib/filecache.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/filecache.php b/lib/filecache.php index 59b0fb1b503..4a4183cbdb5 100644 --- a/lib/filecache.php +++ b/lib/filecache.php @@ -490,10 +490,9 @@ class OC_FileCache{ }else{ $totalSize+=self::scanFile($file,$root); $count++; - if($count>$lastSend+25){ - if($eventSource){ - $eventSource->send('scanning',array('file'=>$path,'count'=>$count)); - } + if($count>$lastSend+25 and $eventSource){ + $lastSend=$count; + $eventSource->send('scanning',array('file'=>$path,'count'=>$count)); } } } -- cgit v1.2.3 From 2f68b084919437013cc6d977c0f077e541cf83f9 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 31 Mar 2012 16:40:42 +0200 Subject: fix eventsource for ie --- core/js/eventsource.js | 2 +- lib/eventsource.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/core/js/eventsource.js b/core/js/eventsource.js index 34bce60c24a..08259e02cae 100644 --- a/core/js/eventsource.js +++ b/core/js/eventsource.js @@ -68,7 +68,7 @@ OC.EventSource=function(src,data){ OC.EventSource.fallBackSources=[]; OC.EventSource.iframeCount=0;//number of fallback iframes OC.EventSource.fallBackCallBack=function(id,type,data){ - OC.EventSource.fallBackSources[id].fallBackCallBack(type,JSON.parse(data)); + OC.EventSource.fallBackSources[id].fallBackCallBack(type,data); } OC.EventSource.prototype={ typelessListeners:[], diff --git a/lib/eventsource.php b/lib/eventsource.php index dc28616c2dd..cf10660b94c 100644 --- a/lib/eventsource.php +++ b/lib/eventsource.php @@ -59,7 +59,7 @@ class OC_EventSource{ $type=null; } if($this->fallback){ - $response=''.PHP_EOL; + $response=''.PHP_EOL; echo $response; }else{ if($type){ -- cgit v1.2.3