From 640ba1828f3edfdd2e71825828c51b734fb19d1c Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 19 Mar 2012 21:56:07 +0100 Subject: [PATCH 01/16] Start of audit app Audit the filesystem action --- apps/admin_audit/appinfo/app.php | 10 +++++++ apps/admin_audit/appinfo/info.xml | 10 +++++++ apps/admin_audit/lib/hooks_handlers.php | 36 +++++++++++++++++++++++++ lib/filesystem.php | 2 +- 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 apps/admin_audit/appinfo/app.php create mode 100644 apps/admin_audit/appinfo/info.xml create mode 100644 apps/admin_audit/lib/hooks_handlers.php diff --git a/apps/admin_audit/appinfo/app.php b/apps/admin_audit/appinfo/app.php new file mode 100644 index 0000000000..b1b986fb7b --- /dev/null +++ b/apps/admin_audit/appinfo/app.php @@ -0,0 +1,10 @@ + + + admin_audit + Log audit info + 0.1 + AGPL + Bart Visscher + 2 + Audit user actions in Owncloud + diff --git a/apps/admin_audit/lib/hooks_handlers.php b/apps/admin_audit/lib/hooks_handlers.php new file mode 100644 index 0000000000..924878840a --- /dev/null +++ b/apps/admin_audit/lib/hooks_handlers.php @@ -0,0 +1,36 @@ + Date: Fri, 23 Mar 2012 22:34:55 +0100 Subject: [PATCH 02/16] Audit: Add user login/logout logging --- apps/admin_audit/appinfo/app.php | 4 ++++ apps/admin_audit/lib/hooks_handlers.php | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/apps/admin_audit/appinfo/app.php b/apps/admin_audit/appinfo/app.php index b1b986fb7b..27a72de432 100644 --- a/apps/admin_audit/appinfo/app.php +++ b/apps/admin_audit/appinfo/app.php @@ -2,6 +2,10 @@ OC::$CLASSPATH['OC_Admin_Audit_Hooks_Handlers'] = 'apps/admin_audit/lib/hooks_handlers.php'; +OCP\Util::connectHook('OCP\User', 'pre_login', 'OC_Admin_Audit_Hooks_Handlers', 'pre_login'); +OCP\Util::connectHook('OCP\User', 'post_login', 'OC_Admin_Audit_Hooks_Handlers', 'post_login'); +OCP\Util::connectHook('OCP\User', 'logout', 'OC_Admin_Audit_Hooks_Handlers', 'logout'); + OCP\Util::connectHook(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_rename, 'OC_Admin_Audit_Hooks_Handlers', 'rename'); OCP\Util::connectHook(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_create, 'OC_Admin_Audit_Hooks_Handlers', 'create'); OCP\Util::connectHook(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_copy, 'OC_Admin_Audit_Hooks_Handlers', 'copy'); diff --git a/apps/admin_audit/lib/hooks_handlers.php b/apps/admin_audit/lib/hooks_handlers.php index 924878840a..8ebabbac7b 100644 --- a/apps/admin_audit/lib/hooks_handlers.php +++ b/apps/admin_audit/lib/hooks_handlers.php @@ -1,6 +1,19 @@ Date: Thu, 29 Mar 2012 11:24:29 +0200 Subject: [PATCH 03/16] Audit: Log messages with separate function --- apps/admin_audit/lib/hooks_handlers.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/apps/admin_audit/lib/hooks_handlers.php b/apps/admin_audit/lib/hooks_handlers.php index 8ebabbac7b..4cc3194eaf 100644 --- a/apps/admin_audit/lib/hooks_handlers.php +++ b/apps/admin_audit/lib/hooks_handlers.php @@ -3,47 +3,50 @@ class OC_Admin_Audit_Hooks_Handlers { static public function pre_login($params) { $path = $params['uid']; - OCP\Util::writeLog('admin_audit', 'Trying login '.$user, OCP\Util::INFO); + self::log('Trying login '.$user); } static public function post_login($params) { $path = $params['uid']; - OCP\Util::writeLog('admin_audit', 'Login '.$user, OCP\Util::INFO); + self::log('Login '.$user); } static public function logout($params) { $user = OCP\User::getUser(); - OCP\Util::writeLog('admin_audit', 'Logout '.$user, OCP\Util::INFO); + self::log('Logout '.$user); } static public function rename($params) { $oldpath = $params[OC_Filesystem::signal_param_oldpath]; $newpath = $params[OC_Filesystem::signal_param_newpath]; $user = OCP\User::getUser(); - OCP\Util::writeLog('admin_audit', 'Rename "'.$oldpath.'" to "'.$newpath.'" by '.$user, OCP\Util::INFO); + self::log('Rename "'.$oldpath.'" to "'.$newpath.'" by '.$user); } static public function create($params) { $path = $params[OC_Filesystem::signal_param_path]; $user = OCP\User::getUser(); - OCP\Util::writeLog('admin_audit', 'Create "'.$path.'" by '.$user, OCP\Util::INFO); + self::log('Create "'.$path.'" by '.$user); } static public function copy($params) { $oldpath = $params[OC_Filesystem::signal_param_oldpath]; $newpath = $params[OC_Filesystem::signal_param_newpath]; $user = OCP\User::getUser(); - OCP\Util::writeLog('admin_audit', 'Copy "'.$oldpath.'" to "'.$newpath.'" by '.$user, OCP\Util::INFO); + self::log('Copy "'.$oldpath.'" to "'.$newpath.'" by '.$user); } static public function write($params) { $path = $params[OC_Filesystem::signal_param_path]; $user = OCP\User::getUser(); - OCP\Util::writeLog('admin_audit', 'Write "'.$path.'" by '.$user, OCP\Util::INFO); + self::log('Write "'.$path.'" by '.$user); } static public function read($params) { $path = $params[OC_Filesystem::signal_param_path]; $user = OCP\User::getUser(); - OCP\Util::writeLog('admin_audit', 'Read "'.$path.'" by '.$user, OCP\Util::INFO); + self::log('Read "'.$path.'" by '.$user); } static public function delete($params) { $path = $params[OC_Filesystem::signal_param_path]; $user = OCP\User::getUser(); - OCP\Util::writeLog('admin_audit', 'Delete "'.$path.'" by '.$user, OCP\Util::INFO); + self::log('Delete "'.$path.'" by '.$user); + } + static protected function log($msg) { + OCP\Util::writeLog('admin_audit', $msg, OCP\Util::INFO); } } From 2d581c675fb488df0875e4a489821cf88b7679ac Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 13 Apr 2012 19:40:33 +0200 Subject: [PATCH 04/16] Audit: Log sharing actions --- apps/admin_audit/appinfo/app.php | 4 ++++ apps/admin_audit/lib/hooks_handlers.php | 20 ++++++++++++++++++++ apps/files_sharing/get.php | 1 + apps/files_sharing/lib_share.php | 2 ++ 4 files changed, 27 insertions(+) diff --git a/apps/admin_audit/appinfo/app.php b/apps/admin_audit/appinfo/app.php index 27a72de432..e52f633cf1 100644 --- a/apps/admin_audit/appinfo/app.php +++ b/apps/admin_audit/appinfo/app.php @@ -12,3 +12,7 @@ OCP\Util::connectHook(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_copy, 'OC_ OCP\Util::connectHook(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_write, 'OC_Admin_Audit_Hooks_Handlers', 'write'); OCP\Util::connectHook(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_read, 'OC_Admin_Audit_Hooks_Handlers', 'read'); OCP\Util::connectHook(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_delete, 'OC_Admin_Audit_Hooks_Handlers', 'delete'); + +OCP\Util::connectHook('OC_Share', 'public', 'OC_Admin_Audit_Hooks_Handlers', 'share_public'); +OCP\Util::connectHook('OC_Share', 'public-download', 'OC_Admin_Audit_Hooks_Handlers', 'share_public_download'); +OCP\Util::connectHook('OC_Share', 'user', 'OC_Admin_Audit_Hooks_Handlers', 'share_user'); diff --git a/apps/admin_audit/lib/hooks_handlers.php b/apps/admin_audit/lib/hooks_handlers.php index 4cc3194eaf..c5aec97d93 100644 --- a/apps/admin_audit/lib/hooks_handlers.php +++ b/apps/admin_audit/lib/hooks_handlers.php @@ -46,6 +46,26 @@ class OC_Admin_Audit_Hooks_Handlers { $user = OCP\User::getUser(); self::log('Delete "'.$path.'" by '.$user); } + static public function share_public($params) { + $path = $params['source']; + $token = $params['token']; + $user = OCP\User::getUser(); + self::log('Shared "'.$path.'" with public, token="'.$token.'" by '.$user); + } + static public function share_public_download($params) { + $path = $params['source']; + $token = $params['token']; + $user = $_SERVER['REMOTE_ADDR']; + self::log('Download of shared "'.$path.'" token="'.$token.'" by '.$user); + } + static public function share_user($params) { + $path = $params['source']; + $permissions = $params['permissions']; + $with = $params['with']; + $user = OCP\User::getUser(); + $rw = $permissions & OC_Share::WRITE ? 'w' : 'o'; + self::log('Shared "'.$path.'" (r'.$rw.') with user "'.$with.'" by '.$user); + } static protected function log($msg) { OCP\Util::writeLog('admin_audit', $msg, OCP\Util::INFO); } diff --git a/apps/files_sharing/get.php b/apps/files_sharing/get.php index de3bc5f46d..57ff6b6e20 100755 --- a/apps/files_sharing/get.php +++ b/apps/files_sharing/get.php @@ -74,6 +74,7 @@ if ($source !== false) { header("Content-Length: " . OC_Filesystem::filesize($source)); //download the file @ob_clean(); + OCP\Util::emitHook('OC_Share', 'public-download', array('source'=>$source, 'token'=>$token); OC_Filesystem::readfile($source); } } else { diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index d5cf3d0a1b..14c61c620a 100755 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -43,6 +43,7 @@ class OC_Share { $query = OCP\DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)"); if ($uid_shared_with == self::PUBLICLINK) { $token = sha1("$uid_shared_with-$source"); + OCP\Util::emitHook('OC_Share', 'public', array('source'=>$source, 'token'=>$token, 'permissions'=>$permissions)); $query->execute(array($uid_owner, self::PUBLICLINK, $source, $token, $permissions)); $this->token = $token; } else { @@ -97,6 +98,7 @@ class OC_Share { if (isset($gid)) { $uid = $uid."@".$gid; } + OCP\Util::emitHook('OC_Share', 'user', array('source'=>$source, 'target'=>$target, 'with'=>$uid, 'permissions'=>$permissions)); $query->execute(array($uid_owner, $uid, $source, $target, $permissions)); // Add file to filesystem cache $userDirectory = "/".OCP\USER::getUser()."/files"; From 4510571aa15d18d958947efd380b211a9a12aaaa Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 30 May 2012 17:46:49 +0200 Subject: [PATCH 05/16] Add app for logging access to shared files --- apps/files_sharing/sharedstorage.php | 16 ++++++++ apps/files_sharing_log/appinfo/app.php | 22 +++++++++++ apps/files_sharing_log/appinfo/database.xml | 44 +++++++++++++++++++++ apps/files_sharing_log/appinfo/info.xml | 10 +++++ apps/files_sharing_log/appinfo/version | 1 + apps/files_sharing_log/css/style.css | 7 ++++ apps/files_sharing_log/index.php | 21 ++++++++++ apps/files_sharing_log/log.php | 34 ++++++++++++++++ apps/files_sharing_log/templates/index.php | 42 ++++++++++++++++++++ 9 files changed, 197 insertions(+) create mode 100644 apps/files_sharing_log/appinfo/app.php create mode 100644 apps/files_sharing_log/appinfo/database.xml create mode 100644 apps/files_sharing_log/appinfo/info.xml create mode 100644 apps/files_sharing_log/appinfo/version create mode 100644 apps/files_sharing_log/css/style.css create mode 100644 apps/files_sharing_log/index.php create mode 100644 apps/files_sharing_log/log.php create mode 100644 apps/files_sharing_log/templates/index.php diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 3bb6e73035..e8aa73dd56 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -320,6 +320,11 @@ class OC_Filestorage_Shared extends OC_Filestorage { public function file_get_contents($path) { $source = $this->getSource($path); if ($source) { + $info = array( + 'target' => $this->datadir.$path, + 'source' => $source, + ); + OCP\Util::emitHook('OC_Filestorage_Shared', 'file_get_contents', $info); $storage = OC_Filesystem::getStorage($source); return $storage->file_get_contents($this->getInternalPath($source)); } @@ -329,6 +334,11 @@ class OC_Filestorage_Shared extends OC_Filestorage { if ($this->is_writable($path)) { $source = $this->getSource($path); if ($source) { + $info = array( + 'target' => $this->datadir.$path, + 'source' => $source, + ); + OCP\Util::emitHook('OC_Filestorage_Shared', 'file_put_contents', $info); $storage = OC_Filesystem::getStorage($source); $result = $storage->file_put_contents($this->getInternalPath($source), $data); if ($result) { @@ -416,6 +426,12 @@ class OC_Filestorage_Shared extends OC_Filestorage { public function fopen($path, $mode) { $source = $this->getSource($path); if ($source) { + $info = array( + 'target' => $this->datadir.$path, + 'source' => $source, + 'mode' => $mode, + ); + OCP\Util::emitHook('OC_Filestorage_Shared', 'fopen', $info); $storage = OC_Filesystem::getStorage($source); return $storage->fopen($this->getInternalPath($source), $mode); } diff --git a/apps/files_sharing_log/appinfo/app.php b/apps/files_sharing_log/appinfo/app.php new file mode 100644 index 0000000000..23cae61fbf --- /dev/null +++ b/apps/files_sharing_log/appinfo/app.php @@ -0,0 +1,22 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +OC::$CLASSPATH['OC_Files_Sharing_Log'] = 'apps/files_sharing_log/log.php'; + +$l=new OC_L10N('files_sharing_log'); +OCP\App::addNavigationEntry( array( + 'id' => 'files_sharing_log_index', + 'order' => 5, + 'href' => OCP\Util::linkTo( 'files_sharing_log', 'index.php' ), + 'icon' => OCP\Util::imagePath( 'files_sharing_log', 'icon.png' ), + 'name' => $l->t('Shared files log')) +); + +OCP\Util::connectHook('OC_Filestorage_Shared', 'fopen', 'OC_Files_Sharing_Log', 'fopen'); +OCP\Util::connectHook('OC_Filestorage_Shared', 'file_get_contents', 'OC_Files_Sharing_Log', 'file_get_contents'); +OCP\Util::connectHook('OC_Filestorage_Shared', 'file_put_contents', 'OC_Files_Sharing_Log', 'file_put_contents'); diff --git a/apps/files_sharing_log/appinfo/database.xml b/apps/files_sharing_log/appinfo/database.xml new file mode 100644 index 0000000000..92e5f0125b --- /dev/null +++ b/apps/files_sharing_log/appinfo/database.xml @@ -0,0 +1,44 @@ + + + *dbname* + true + false + latin1 + + *dbprefix*sharing_log + + + user_id + text + true + 64 + + + source + text + true + 128 + + + uid_who + text + true + 64 + + + when + integer + + false + true + 4 + + + mode + text + true + 4 + + +
+
diff --git a/apps/files_sharing_log/appinfo/info.xml b/apps/files_sharing_log/appinfo/info.xml new file mode 100644 index 0000000000..d5e3283df3 --- /dev/null +++ b/apps/files_sharing_log/appinfo/info.xml @@ -0,0 +1,10 @@ + + + files_sharing_log + File Shared access logging app + Log access to shared files + AGPL + Bart Visscher + 4 + true + diff --git a/apps/files_sharing_log/appinfo/version b/apps/files_sharing_log/appinfo/version new file mode 100644 index 0000000000..49d59571fb --- /dev/null +++ b/apps/files_sharing_log/appinfo/version @@ -0,0 +1 @@ +0.1 diff --git a/apps/files_sharing_log/css/style.css b/apps/files_sharing_log/css/style.css new file mode 100644 index 0000000000..069d3a45e0 --- /dev/null +++ b/apps/files_sharing_log/css/style.css @@ -0,0 +1,7 @@ +#files_sharing_log { +padding: 2em; +} +#files_sharing_log th, +#files_sharing_log td { +padding: 0 1em; +} diff --git a/apps/files_sharing_log/index.php b/apps/files_sharing_log/index.php new file mode 100644 index 0000000000..ffacbdd860 --- /dev/null +++ b/apps/files_sharing_log/index.php @@ -0,0 +1,21 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +OCP\User::checkLoggedIn(); +OCP\App::checkAppEnabled('files_sharing_log'); + +OCP\App::setActiveNavigationEntry('files_sharing_log_index'); + +OCP\Util::addStyle('files_sharing_log', 'style'); + +$query = OCP\DB::prepare('SELECT * FROM *PREFIX*sharing_log WHERE user_id = ?'); +$log = $query->execute(array(OCP\User::getUser()))->fetchAll(); + +$output = new OCP\Template('files_sharing_log', 'index', 'user'); +$output->assign('log', $log); +$output->printPage(); diff --git a/apps/files_sharing_log/log.php b/apps/files_sharing_log/log.php new file mode 100644 index 0000000000..e6a12b9fb1 --- /dev/null +++ b/apps/files_sharing_log/log.php @@ -0,0 +1,34 @@ +execute(array($source, $target))->fetchAll(); + $info = $info[0]; + //var_dump($info); + $query = OCP\DB::prepare("INSERT INTO *PREFIX*sharing_log VALUES (?,?,?,?,?)"); + $query->execute(array($info['uid_owner'], $source, OCP\User::getUser(), time(), $mode)); + //die; + } +} diff --git a/apps/files_sharing_log/templates/index.php b/apps/files_sharing_log/templates/index.php new file mode 100644 index 0000000000..55bfc1d6a3 --- /dev/null +++ b/apps/files_sharing_log/templates/index.php @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + +
t('File') ?>t('Who') ?>t('When') ?>t('What') ?>
+ + + + + + + t('Read'); + break; + case 'put': + echo $l->t('Write'); + break; + default: + if (strpos('r', $log['mode']) !== false): + echo $l->t('Read'); + else: + echo $l->t('Write'); + endif; + endswitch; + ?> +
From 5a2c93ec2d3383da9f945cd71763a519f1cf462f Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 20 Jun 2012 15:11:14 +0200 Subject: [PATCH 06/16] use sanitizeHTML() function --- apps/calendar/ajax/events.php | 2 +- apps/calendar/js/calendar.js | 2 +- apps/calendar/lib/object.php | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/calendar/ajax/events.php b/apps/calendar/ajax/events.php index 39130a6a98..845cea8df8 100644 --- a/apps/calendar/ajax/events.php +++ b/apps/calendar/ajax/events.php @@ -31,4 +31,4 @@ $output = array(); foreach($events as $event){ $output = array_merge($output, OC_Calendar_App::generateEventOutput($event, $start, $end)); } -OCP\JSON::encodedPrint($output); +OCP\JSON::encodedPrint(OCP\Util::sanitizeHTML($output)); diff --git a/apps/calendar/js/calendar.js b/apps/calendar/js/calendar.js index 5136c3e774..3b1be59381 100644 --- a/apps/calendar/js/calendar.js +++ b/apps/calendar/js/calendar.js @@ -869,7 +869,7 @@ $(document).ready(function(){ eventDrop: Calendar.UI.moveEvent, eventResize: Calendar.UI.resizeEvent, eventRender: function(event, element) { - element.find('.fc-event-title').html(element.find('.fc-event-title').text()); + element.find('.fc-event-title').html(element.find('.fc-event-title').html()); element.tipsy({ className: 'tipsy-event', opacity: 0.9, diff --git a/apps/calendar/lib/object.php b/apps/calendar/lib/object.php index 9e4806227b..4212bf5a32 100644 --- a/apps/calendar/lib/object.php +++ b/apps/calendar/lib/object.php @@ -600,8 +600,8 @@ class OC_Calendar_Object{ public static function updateVCalendarFromRequest($request, $vcalendar) { - $title = strip_tags($request["title"]); - $location = strip_tags($request["location"]); + $title = $request["title"]; + $location = $request["location"]; $categories = $request["categories"]; $allday = isset($request["allday"]); $from = $request["from"]; @@ -611,7 +611,7 @@ class OC_Calendar_Object{ $totime = $request['totime']; } $vevent = $vcalendar->VEVENT; - $description = strip_tags($request["description"]); + $description = $request["description"]; $repeat = $request["repeat"]; if($repeat != 'doesnotrepeat'){ $rrule = ''; From e52230d11c5cef0e6105166b7d704c8c69f60425 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 20 Jun 2012 15:41:05 +0200 Subject: [PATCH 07/16] no need to escape the title --- 3rdparty/fullcalendar/js/fullcalendar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rdparty/fullcalendar/js/fullcalendar.js b/3rdparty/fullcalendar/js/fullcalendar.js index 779a313c76..314f8c8a1a 100644 --- a/3rdparty/fullcalendar/js/fullcalendar.js +++ b/3rdparty/fullcalendar/js/fullcalendar.js @@ -4662,7 +4662,7 @@ function DayEventRenderer() { ""; } html += - "" + htmlEscape(event.title) + "" + + "" + event.title + "" + ""; if (seg.isEnd && isEventResizable(event)) { html += From 6644511124d0f93ca6636344db5455da6d160c3d Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 20 Jun 2012 16:29:19 +0200 Subject: [PATCH 08/16] remove unnecessary comment --- lib/public/util.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/public/util.php b/lib/public/util.php index 7c0cb66607..c611d59a53 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)); } } From 5c8e774cea24bd964632ae96357a308272753513 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 20 Jun 2012 08:57:21 +0200 Subject: [PATCH 09/16] Small code reorder --- lib/util.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/util.php b/lib/util.php index 5492587862..f0999b6d20 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 )){ From cd934d5d8924b51d719ac20025b5fa034c74c3fb Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Tue, 19 Jun 2012 17:38:04 +0200 Subject: [PATCH 10/16] Adjust OC_Filesystem use in hooks to string, so the class is loaded as late as possible --- apps/files_versions/appinfo/app.php | 2 +- apps/gallery/lib/hooks_handlers.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/files_versions/appinfo/app.php b/apps/files_versions/appinfo/app.php index 49f1573f7c..8b891848c5 100644 --- a/apps/files_versions/appinfo/app.php +++ b/apps/files_versions/appinfo/app.php @@ -6,4 +6,4 @@ OCP\App::registerAdmin('files_versions', 'settings'); OCP\Util::addscript('files_versions', 'versions'); // Listen to write signals -OCP\Util::connectHook(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_write, "OCA_Versions\Storage", "write_hook"); +OCP\Util::connectHook('OC_Filesystem', 'post_write', "OCA_Versions\Storage", "write_hook"); diff --git a/apps/gallery/lib/hooks_handlers.php b/apps/gallery/lib/hooks_handlers.php index a9f4dc6aff..093979834d 100644 --- a/apps/gallery/lib/hooks_handlers.php +++ b/apps/gallery/lib/hooks_handlers.php @@ -21,7 +21,7 @@ * */ -OCP\Util::connectHook(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_delete, "OC_Gallery_Hooks_Handlers", "removePhoto"); +OCP\Util::connectHook('OC_Filesystem', 'delete', "OC_Gallery_Hooks_Handlers", "removePhoto"); //OCP\Util::connectHook(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_rename, "OC_Gallery_Hooks_Handlers", "renamePhoto"); require_once(OC::$CLASSPATH['Pictures_Managers']); From 6404476bec76a5c4bc2c6d3bb1508bb1c6c025f2 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Tue, 19 Jun 2012 17:38:04 +0200 Subject: [PATCH 11/16] 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(-) diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index ea3a9da6f7..bbb753d5e6 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 6e209afebd..b6ca19568f 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 0d0943d363..aeeb012f37 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 f0999b6d20..46c9e0ef92 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)); } } From 7a3d606cacb68c23d7972d078370c58d4a8f8a2c Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 20 Jun 2012 17:10:17 +0200 Subject: [PATCH 12/16] Prefer requested app before redirecting to default page --- lib/util.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/util.php b/lib/util.php index 46c9e0ef92..7792f96d44 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(); From c244daac897cf8a9e50297b8c9a643dcc9651338 Mon Sep 17 00:00:00 2001 From: Sam Tuke Date: Wed, 20 Jun 2012 16:24:49 +0100 Subject: [PATCH 13/16] 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(-) diff --git a/apps/files_archive/lib/storage.php b/apps/files_archive/lib/storage.php index 2f10d6a3e4..8676166361 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 9174334383..1a6942ad16 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 bf353bb0cc..71ef4aed00 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); From 72215a818d0e222af80000909f9fa78243112533 Mon Sep 17 00:00:00 2001 From: Sam Tuke Date: Wed, 20 Jun 2012 18:25:12 +0100 Subject: [PATCH 14/16] 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 +++ .../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 diff --git a/apps/files_versions/ajax/expireAll.php b/apps/files_versions/ajax/expireAll.php new file mode 100644 index 0000000000..f9cd74aed0 --- /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 8b891848c5..ef2f54dd3f 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 0000000000..d9456f3f2a --- /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 0000000000..db80172979 --- /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 0000000000..7ff016b585 --- /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 6feb0cbb9c..7522538caf 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 27794fe17c..44a2ab0f63 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); From 4b231c15d567104619c9bd38c3a07f005512cf5b Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 20 Jun 2012 16:31:22 +0200 Subject: [PATCH 15/16] bookmarks: make read later-button draggable again, fixes oc-944 --- apps/bookmarks/css/bookmarks.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/bookmarks/css/bookmarks.css b/apps/bookmarks/css/bookmarks.css index 3a3e0fbf6b..a67afcd44f 100644 --- a/apps/bookmarks/css/bookmarks.css +++ b/apps/bookmarks/css/bookmarks.css @@ -1,5 +1,5 @@ #content { overflow: auto; height: 100%; } -#firstrun { width: 80%; margin: 5em auto auto auto; text-align: center; font-weight:bold; font-size:1.5em; color:#777;} +#firstrun { width: 80%; margin: 5em auto auto auto; text-align: center; font-weight:bold; font-size:1.5em; color:#777; position: relative;} #firstrun small { display: block; font-weight: normal; font-size: 0.5em; margin-bottom: 1.5em; } #firstrun .button { font-size: 0.7em; } #firstrun #selections { font-size:0.8em; font-weight: normal; width: 100%; margin: 2em auto auto auto; clear: both; } From f255ac8b3a82bcf9e77c3bc0db7583d1492df44c Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 20 Jun 2012 20:03:25 +0200 Subject: [PATCH 16/16] make bookmarks bookmarklet work again, kudos to Victor Dubiniuk --- apps/bookmarks/addBm.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/bookmarks/addBm.php b/apps/bookmarks/addBm.php index 866fa1e7b1..4df93c8b05 100644 --- a/apps/bookmarks/addBm.php +++ b/apps/bookmarks/addBm.php @@ -5,20 +5,20 @@ * * @author Arthur Schiwon * @copyright 2011 Arthur Schiwon blizzz@arthur-schiwon.de -* +* * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either +* License as published by the Free Software Foundation; either * version 3 of the License, or any later version. -* +* * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Lesser General Public +* +* You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . -* +* */ @@ -28,6 +28,6 @@ OCP\User::checkLoggedIn(); OCP\App::checkAppEnabled('bookmarks'); require_once('bookmarksHelper.php'); -addBookmark($_POST['url'], '', 'Read-Later'); +addBookmark($_GET['url'], '', 'Read-Later'); include 'templates/addBm.php';