From 69ab810005b0edc588ea26620be48a44d3d41574 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 22 Jun 2010 16:13:45 +0200 Subject: [PATCH 01/14] fix checkboxes in filebrowser in konqueror --- js/lib_drag.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/js/lib_drag.js b/js/lib_drag.js index bc6a8610500..5e6ae8ccadc 100755 --- a/js/lib_drag.js +++ b/js/lib_drag.js @@ -258,7 +258,6 @@ document.drag.update=function(event){ if(document.drag.active && document.drag.node){ document.drag.node.drag.update.call(document.drag.node,event); } - return false; } /** @@ -269,7 +268,6 @@ document.drag.stop=function(event){ if(document.drag.active && document.drag.node){ document.drag.node.drag.stop.call(document.drag.node,event); } - return false; } document.events.add(document,'onmousemove',document.drag.update); document.events.add(document,'onmouseup',document.drag.stop); From 23d006fc259cc3a57074a8202d337fbeab0f5a5a Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 25 Jun 2010 13:24:27 +0200 Subject: [PATCH 02/14] fix users being to able to read files outside the datadir --- inc/lib_files.php | 29 +++++++++++++++++++---------- inc/lib_filesystem.php | 16 ++++++++++++++-- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/inc/lib_files.php b/inc/lib_files.php index 763873733b2..1702ef20de6 100755 --- a/inc/lib_files.php +++ b/inc/lib_files.php @@ -130,19 +130,28 @@ class OC_FILES { $zip=false; $filename=$dir.'/'.$files; } - header('Content-Disposition: attachment; filename='.basename($filename)); - header('Content-Transfer-Encoding: binary'); - header('Expires: 0'); - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - header('Pragma: public'); - header('Content-Length: ' . filesize($filename)); - if(!$zip){ - $filename=OC_FILESYSTEM::toTmpFile($filename); + if($zip or OC_FILESYSTEM::is_readable($filename)){ + header('Content-Disposition: attachment; filename='.basename($filename)); + header('Content-Transfer-Encoding: binary'); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header('Pragma: public'); + header('Content-Length: ' . filesize($filename)); + }elseif($zip or !OC_FILESYSTEM::file_exists($filename)){ + header("HTTP/1.0 404 Not Found"); + die('404 Not Found'); + }else{ + header("HTTP/1.0 403 Forbidden"); + die('403 Forbidden'); } ob_end_clean(); OC_LOG::event($_SESSION['username'],3,"$dir/$files"); - readfile($filename); - unlink($filename); + if($zip){ + readfile($filename); + unlink($filename); + }else{ + OC_FILESYSTEM::readfile($filename); + } foreach(self::$tmpFiles as $tmpFile){ if(file_exists($tmpFile) and is_file($tmpFile)){ unlink($tmpFile); diff --git a/inc/lib_filesystem.php b/inc/lib_filesystem.php index 1e50ab34ae9..f441d55e7f8 100755 --- a/inc/lib_filesystem.php +++ b/inc/lib_filesystem.php @@ -34,7 +34,13 @@ class OC_FILESYSTEM{ * @param string path * @return bool */ - static private function canRead(){ + static private function canRead($path){ + if(substr($path,0,1)!=='/'){ + $path='/'.$path; + } + if(strstr($path,'/../')){ + return false; + } return true;//dummy untill premissions are correctly implemented, also the correcty value because for now users are locked in their seperate data dir and can read/write everything in there } /** @@ -42,7 +48,13 @@ class OC_FILESYSTEM{ * @param string path * @return bool */ - static private function canWrite(){ + static private function canWrite($path){ + if(substr($path,0,1)!=='/'){ + $path='/'.$path; + } + if(strstr($path,'/../')){ + return false; + } return true;//dummy untill premissions are correctly implemented, also the correcty value because for now users are locked in their seperate data dir and can read/write everything in there } From a0088cfea61f7964f92ab4c576ce19f523abc5cb Mon Sep 17 00:00:00 2001 From: Sandro Date: Sun, 27 Jun 2010 00:16:09 +0200 Subject: [PATCH 03/14] right WEBROOT --- inc/lib_base.php | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/inc/lib_base.php b/inc/lib_base.php index cd622f1f5b6..0e12a0bacf3 100755 --- a/inc/lib_base.php +++ b/inc/lib_base.php @@ -35,31 +35,12 @@ session_start(); $SERVERROOT=substr(__FILE__,0,-17); $DOCUMENTROOT=$_SERVER['DOCUMENT_ROOT']; $SERVERROOT=str_replace("\\",'/',$SERVERROOT); -if(strpos($SERVERROOT,$DOCUMENTROOT)===0){ - //if the serverroot is a subdir of the documentroot we can use this - $count=strlen($DOCUMENTROOT); - $WEBROOT=substr($SERVERROOT,$count); -}else{ - //try some common patterns - $WEBROOT=''; - if(strpos($_SERVER['REQUEST_URI'],'/~')!==false){ - //owncloud is probable installed in a users home folder, extract the username from the uri and use it as base for the webroot - $part=substr($_SERVER['REQUEST_URI'],strpos($_SERVER['REQUEST_URI'],'/~')+1); - $part=substr($part,0,strpos($part,'/')); - $WEBROOT.='/'.$part; - } - if(strpos($SERVERROOT,'public_html')!==false){ - //a common used folder name for websevers to store their sites - if($WEBROOT{strlen($WEBROOT)-1}!=='/'){ - $WEBROOT.='/'; - } - $WEBROOT.=substr($SERVERROOT,strpos($SERVERROOT,'public_html')+strlen('public_html')); - } -} -if($WEBROOT{0}!=='/' and $WEBROOT!=''){ +$SUBURI=substr($_SERVER["SCRIPT_FILENAME"],strlen($SERVERROOT)); +$WEBROOT=substr($_SERVER["SCRIPT_NAME"],0,strlen($_SERVER["SCRIPT_NAME"])-strlen($SUBURI)); + +if($WEBROOT!='' and $WEBROOT[0]!=='/'){ $WEBROOT='/'.$WEBROOT; } -// $WEBROOT='http://localhost'.$WEBROOT; // set the right include path // set_include_path(get_include_path().PATH_SEPARATOR.$SERVERROOT.PATH_SEPARATOR.$SERVERROOT.'/inc'.PATH_SEPARATOR.$SERVERROOT.'/config'); @@ -619,4 +600,4 @@ function chmodr($path, $filemode) { return FALSE; } -?> \ No newline at end of file +?> From 0ba0f226276c72b5c7b5ce8fc6e025da347fd178 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 27 Jun 2010 18:09:59 +0200 Subject: [PATCH 04/14] fix webroot when using symlinks --- inc/lib_base.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/inc/lib_base.php b/inc/lib_base.php index 0e12a0bacf3..aa14d3cec00 100755 --- a/inc/lib_base.php +++ b/inc/lib_base.php @@ -33,11 +33,12 @@ session_start(); // calculate the documentroot $SERVERROOT=substr(__FILE__,0,-17); -$DOCUMENTROOT=$_SERVER['DOCUMENT_ROOT']; +$DOCUMENTROOT=realpath($_SERVER['DOCUMENT_ROOT']); $SERVERROOT=str_replace("\\",'/',$SERVERROOT); -$SUBURI=substr($_SERVER["SCRIPT_FILENAME"],strlen($SERVERROOT)); +$SUBURI=substr(realpath($_SERVER["SCRIPT_FILENAME"]),strlen($SERVERROOT)); $WEBROOT=substr($_SERVER["SCRIPT_NAME"],0,strlen($_SERVER["SCRIPT_NAME"])-strlen($SUBURI)); + if($WEBROOT!='' and $WEBROOT[0]!=='/'){ $WEBROOT='/'.$WEBROOT; } From 2a5bcbe7219e52dfd66ab54454ea87fa20d3c8df Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 29 Jun 2010 04:00:01 +0200 Subject: [PATCH 05/14] change target directory for uploads when changing folders in web-frontend --- js/filebrowser.js | 5 ++++- js/lib_files.js | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/js/filebrowser.js b/js/filebrowser.js index 9900ce69902..aae6cdf7720 100755 --- a/js/filebrowser.js +++ b/js/filebrowser.js @@ -309,6 +309,9 @@ OC_FILES.browser.show_callback=function(content){ OC_FILES.browser.breadcrumb.show(null,dir); OC_FILES.browser.files.show(null,content); } + if(OC_FILES.uploadForm){ + OC_FILES.uploadForm.setAttribute('action','files/upload.php?dir='+dir); + } } OC_FILES.browser.handleDropOn=function(event,node){ @@ -437,7 +440,7 @@ OC_FILES.browser.showuploader=function(dir,parent,max_upload){ file.name='file'; file.setAttribute('id','fileSelector'); file.setAttribute('type','file'); - file.addEvent('onchange',OC_FILES.upload,[dir,iframeId]); + file.addEvent('onchange',OC_FILES.upload,[iframeId]); OC_FILES.uploadForm.appendChild(document.createTextNode('Upload file: ')); OC_FILES.uploadForm.appendChild(file); parent.appendChild(OC_FILES.uploadForm); diff --git a/js/lib_files.js b/js/lib_files.js index 74a636cc0bc..68c3c611291 100755 --- a/js/lib_files.js +++ b/js/lib_files.js @@ -91,7 +91,8 @@ OC_FILES.get=function(dir,file){ window.location='files/api.php?action=get&dir='+encodeURIComponent(dir)+'&file='+encodeURIComponent(file); } -OC_FILES.upload=function(dir,iframeId){ +OC_FILES.upload=function(iframeId){ + var dir=OC_FILES.dir; var file=new Object; var fileSelector=document.getElementById('fileSelector'); var max_upload=document.getElementById('max_upload').value; @@ -110,8 +111,7 @@ OC_FILES.upload=function(dir,iframeId){ if(fileSelector.files && fileSelector.files[0].type){ var mime=fileSelector.files[0].type; } - file.dir=dir; - file.dir=dir; + file.dir=OC_FILES.dir; file.name=name; file.type='file'; file.size=size; From 1d01d542050b75559af786d3fdc379e6c5e89b7c Mon Sep 17 00:00:00 2001 From: "Aldo \"xoen\" Giambelluca" Date: Tue, 29 Jun 2010 17:09:47 +0200 Subject: [PATCH 06/14] Specified character encoding Valitating produce a warning --- inc/templates/header.php | 1 + 1 file changed, 1 insertion(+) diff --git a/inc/templates/header.php b/inc/templates/header.php index 1cce6c5433a..e016cd9f021 100755 --- a/inc/templates/header.php +++ b/inc/templates/header.php @@ -2,6 +2,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> + ownCloud Date: Tue, 29 Jun 2010 17:35:04 +0200 Subject: [PATCH 07/14] Fixed some validation error in /settings * Form action not specified * An input field was not closed * Made an input field child of a div --- inc/templates/configform.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/templates/configform.php b/inc/templates/configform.php index 709e8f14296..64499b9ed95 100755 --- a/inc/templates/configform.php +++ b/inc/templates/configform.php @@ -18,8 +18,8 @@ changepassset=function(){ } } -
- + +
Date: Wed, 30 Jun 2010 14:24:36 +0200 Subject: [PATCH 08/14] Font size now respect user preferences This is made using em unit instead of pt for font-size. "New" sizes are relative to the font-size choosen by the user. Changed 9pt in 0.95em, 8pt in 0.8em and 7pt in 0.7em, tested on Firefox. This should fix zoom in/out in IE. --- css/default.php | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/css/default.php b/css/default.php index 7d65820c42b..6500b31cb6d 100755 --- a/css/default.php +++ b/css/default.php @@ -2,12 +2,13 @@ header('Content-Type: text/css'); require_once('../inc/lib_base.php'); ?> -html,body { - background-color: #F9F9F9; - margin:0px; - height:100%; - width:100%; - position:absolute; +html, body { + background-color: #F9F9F9; + margin: 0px; + height: 100%; + width: 100%; + position: absolute; + font-size: 100%; } #mainlayout{ width:100%; @@ -47,7 +48,7 @@ html,body { body.error {background-color: #F0F0F0;} td.error{color:#FF0000; text-align:center} -body,th,td,ul,li,a,div,p,pre {color:#333333; font-family:Verdana,"Bitstream Vera Sans",Arial,Helvetica,Sans,"Bitstream Vera Serif"; font-size:9.0pt;} +body,th,td,ul,li,a,div,p,pre {color:#333333; font-family:Verdana,"Bitstream Vera Sans",Arial,Helvetica,Sans,"Bitstream Vera Serif"; font-size: 0.95em;} a img { border:none; @@ -97,22 +98,22 @@ td.nametext{ display:block; } -.nametext a, .breadcrumb a{color:#333333; font-size:8pt; font-weight:bold; text-decoration:none;} -.errortext {color:#CC3333; font-size:9pt; font-weight:bold; text-decoration:none;} -.highlighttext {color:#333333; font-size:9pt; font-weight:bold; text-decoration:none;} -.datetext {color:#333333; font-size:7pt;} +.nametext a, .breadcrumb a{color:#333333; font-size: 0.8em; font-weight:bold; text-decoration:none;} +.errortext {color:#CC3333; font-size: 0.95em; font-weight:bold; text-decoration:none;} +.highlighttext {color:#333333; font-size: 0.95em; font-weight:bold; text-decoration:none;} +.datetext {color:#333333; font-size: 0.7em;} .sizetext{ color:#333333; - font-size:7pt; + font-size: 0.7em; } -.footer {color:#999999; text-align:center; font-size:9pt; margin-top:4em;} +.footer {color:#999999; text-align:center; font-size: 0.95em; margin-top:4em;} .footer a {color:#999999; text-decoration:none;} -.hint {color:#AAAAAA; text-align:center; font-size:8pt; margin-top:10px;} -.hint a{color:#AAAAAA; text-align:center; font-size:8pt;} +.hint {color:#AAAAAA; text-align:center; font-size: 0.8em; margin-top:10px;} +.hint a{color:#AAAAAA; text-align:center; font-size: 0.8em;} .formstyle { font-weight:normal; - font-size: 8.0pt; + font-size: 0.8em; color: #555555; background-color: #FFFFFF; border: 1px solid #DDDDDD; @@ -140,7 +141,7 @@ td.nametext{ .navigationitem1 { background-color: #EEEEEE; color:#555555; - font-size:9pt; + font-size: 0.95em; font-weight:bold; } @@ -173,13 +174,13 @@ td.nametext{ .navigationitem a { text-decoration:none; color: #333333; - font-size: 8.0pt; + font-size: 0.8em; } .navigationitemselected a { text-decoration:none; color: #333333; - font-size: 8.0pt; + font-size: 0.8em; font-weight:bold; } From a857c7a04c21b1be21fd4665d954bb5c4998f916 Mon Sep 17 00:00:00 2001 From: "Aldo \"xoen\" Giambelluca" Date: Sun, 4 Jul 2010 05:36:05 +0200 Subject: [PATCH 09/14] Made first run a valid XHTML document ;) * form action specified * attribute checked of checkboxes was minimized (http://www.w3.org/TR/xhtml1/#h-4.5) --- inc/templates/adminform.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/inc/templates/adminform.php b/inc/templates/adminform.php index c22c78768b0..81b02ac45fc 100755 --- a/inc/templates/adminform.php +++ b/inc/templates/adminform.php @@ -49,7 +49,7 @@ function dbtypechange(){ } } - +
- + @@ -107,17 +107,17 @@ foreach($dbtypes as $dbtype){ - + - +
force ssl:>
force ssl:>
enable automatic backup:>
backup directory:
date format:
database user:
database password:(leave empty to keep current password)
retype database password:
create database and user: onchange='showDBAdmin()'>
create database and user: onchange='showDBAdmin()'>
database administrative user:
database administrative password:
automaticly fill initial database:>
automaticly fill initial database:>


-
+ From 8c8979f11e1f454d3b0e866880a4be6d7daf7f82 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 4 Jul 2010 09:54:54 +0200 Subject: [PATCH 10/14] fix potential infinite loop --- inc/HTTP/WebDAV/Server/Filesystem.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/inc/HTTP/WebDAV/Server/Filesystem.php b/inc/HTTP/WebDAV/Server/Filesystem.php index 000831f6fef..7826a690a55 100755 --- a/inc/HTTP/WebDAV/Server/Filesystem.php +++ b/inc/HTTP/WebDAV/Server/Filesystem.php @@ -177,15 +177,15 @@ $info["props"][] = $this->mkprop("resourcetype", ""); if ( OC_FILESYSTEM::is_readable($fspath)) { $info["props"][] = $this->mkprop("getcontenttype", $this->_mimetype($fspath)); - } else { + } else { "SELECT ns, name, value FROM properties WHERE path = '$path'"; $info["props"][] = $this->mkprop("getcontenttype", "application/x-non-readable"); } $info["props"][] = $this->mkprop("getcontentlength", OC_FILESYSTEM::filesize($fspath)); } // get additional properties from database - $query = "SELECT ns, name, value FROM properties WHERE path = '$path'"; - $res = OC_DB::select($query); - while ($row = $res[0]) { + $query = "SELECT ns, name, value FROM properties WHERE path = '$path'"; + $res = OC_DB::select($query); + foreach($res as $row){ $info["props"][] = $this->mkprop($row["ns"], $row["name"], $row["value"]); } return $info; From 0d299885befea3005d24330d32c0fa40075a2c94 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 4 Jul 2010 10:02:10 +0200 Subject: [PATCH 11/14] fix silly mistake in previous commit --- inc/HTTP/WebDAV/Server/Filesystem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/HTTP/WebDAV/Server/Filesystem.php b/inc/HTTP/WebDAV/Server/Filesystem.php index 7826a690a55..6c8382b4467 100755 --- a/inc/HTTP/WebDAV/Server/Filesystem.php +++ b/inc/HTTP/WebDAV/Server/Filesystem.php @@ -177,7 +177,7 @@ $info["props"][] = $this->mkprop("resourcetype", ""); if ( OC_FILESYSTEM::is_readable($fspath)) { $info["props"][] = $this->mkprop("getcontenttype", $this->_mimetype($fspath)); - } else { "SELECT ns, name, value FROM properties WHERE path = '$path'"; + } else { $info["props"][] = $this->mkprop("getcontenttype", "application/x-non-readable"); } $info["props"][] = $this->mkprop("getcontentlength", OC_FILESYSTEM::filesize($fspath)); From baf7e00a943afbbb62f374b63d9d4280a5aa22d1 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 4 Jul 2010 16:01:31 +0200 Subject: [PATCH 12/14] fix wrong header sent as response when overwriting files in webdav --- inc/HTTP/WebDAV/Server/Filesystem.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/inc/HTTP/WebDAV/Server/Filesystem.php b/inc/HTTP/WebDAV/Server/Filesystem.php index 6c8382b4467..11e7630d797 100755 --- a/inc/HTTP/WebDAV/Server/Filesystem.php +++ b/inc/HTTP/WebDAV/Server/Filesystem.php @@ -493,8 +493,6 @@ $stat = $this->DELETE(array("path" => $options["dest"])); if (($stat{0} != "2") && (substr($stat, 0, 3) != "404")) { return $stat; - }else{ - $new=true; } } else { return "412 precondition failed"; @@ -553,10 +551,7 @@ } } } - - $query = "INSERT INTO properties SELECT * FROM properties WHERE path = '".$options['path']."'"; } - return ($new && !$existing_col) ? "201 Created" : "204 No Content"; } From d374bcddc10874c89afbd63311819adaad72bc17 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 4 Jul 2010 18:08:35 +0200 Subject: [PATCH 13/14] fix recursive copying of folders with webdav --- inc/HTTP/WebDAV/Server/Filesystem.php | 9 ++------- inc/lib_filestorage.php | 23 +++++++++++++++++++++++ inc/lib_filesystem.php | 14 ++++++++++++++ 3 files changed, 39 insertions(+), 7 deletions(-) mode change 100644 => 100755 inc/lib_filestorage.php diff --git a/inc/HTTP/WebDAV/Server/Filesystem.php b/inc/HTTP/WebDAV/Server/Filesystem.php index 11e7630d797..72e747439d5 100755 --- a/inc/HTTP/WebDAV/Server/Filesystem.php +++ b/inc/HTTP/WebDAV/Server/Filesystem.php @@ -241,7 +241,6 @@ { // get absolute fs path to requested resource) $fspath = $options["path"]; - error_log("get $fspath"); // is this a collection? if (OC_FILESYSTEM::is_dir($fspath)) { return $this->GetDir($fspath, $options); @@ -358,7 +357,6 @@ $path = $options["path"]; $parent = dirname($path); $name = basename($path); - if (!OC_FILESYSTEM::file_exists($parent)) { return "409 Conflict"; } @@ -393,7 +391,6 @@ function DELETE($options) { $path =$options["path"]; - if (!OC_FILESYSTEM::file_exists($path)) { return "404 Not found"; } @@ -501,7 +498,7 @@ if ($del) { if (!OC_FILESYSTEM::rename($source, $dest)) { - return "500 Internal server error 1"; + return "500 Internal server error"; } $destpath = $this->_unslashify($options["dest"]); if (is_dir($source)) { @@ -517,8 +514,7 @@ OC_DB::query($query); } else { if (OC_FILESYSTEM::is_dir($source)) { - $files = OC_FILESYSTEM::find($source); - $files = array_reverse($files); + $files = OC_FILESYSTEM::getTree($source); } else { $files = array($source); } @@ -576,7 +572,6 @@ } else { if (isset($prop["val"])) { $query = "REPLACE INTO properties SET path = '$options[path]', name = '$prop[name]', ns= '$prop[ns]', value = '$prop[val]'"; - error_log($query); } else { $query = "DELETE FROM properties WHERE path = '$options[path]' AND name = '$prop[name]' AND ns = '$prop[ns]'"; } diff --git a/inc/lib_filestorage.php b/inc/lib_filestorage.php old mode 100644 new mode 100755 index 8448eddd74a..85382a44447 --- a/inc/lib_filestorage.php +++ b/inc/lib_filestorage.php @@ -72,6 +72,7 @@ class OC_FILESTORAGE{ public function getMimeType($path){} public function delTree($path){} public function find($path){} + public function getTree($path){} } /** @@ -364,5 +365,27 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ } return $return; } + + public function getTree($dir) { + if(substr($dir,-1,1)=='/'){ + $dir=substr($dir,0,-1); + } + $tree=array(); + $tree[]=$dir; + $dirRelative=$dir; + $dir=$this->datadir.$dir; + if (!file_exists($dir)) return true; + foreach (scandir($dir) as $item) { + if ($item == '.' || $item == '..') continue; + if(is_file($dir.'/'.$item)){ + $tree[]=$dirRelative.'/'.$item; + }elseif(is_dir($dir.'/'.$item)){ + if ($subTree=$this->getTree($dirRelative. "/" . $item)){ + $tree=array_merge($tree,$subTree); + } + } + } + return $tree; + } } ?> \ No newline at end of file diff --git a/inc/lib_filesystem.php b/inc/lib_filesystem.php index f441d55e7f8..6eb317f442e 100755 --- a/inc/lib_filesystem.php +++ b/inc/lib_filesystem.php @@ -278,5 +278,19 @@ class OC_FILESYSTEM{ } return $return; } + static public function getTree($path){ + if(self::canRead($path) and $storage=self::getStorage($path)){ + $mp=self::getMountPoint($path); + $return=$storage->getTree(substr($path,strlen($mp))); + echo "mp: $mp"; + foreach($return as &$file){ + if(substr($file,0,1)=='/'){ + $file=substr($file,1); + } + $file=$mp.$file; + } + return $return; + } + } } ?> From 3d2f68c43f4ed3b3bcf1f8a7d7fe17139a4604f1 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 5 Jul 2010 00:39:38 +0200 Subject: [PATCH 14/14] mayor improvements in the handling of locks in webdav --- inc/HTTP/WebDAV/Server/Filesystem.php | 88 +++++++++++++++++++++------ 1 file changed, 70 insertions(+), 18 deletions(-) diff --git a/inc/HTTP/WebDAV/Server/Filesystem.php b/inc/HTTP/WebDAV/Server/Filesystem.php index 72e747439d5..b96fb414c27 100755 --- a/inc/HTTP/WebDAV/Server/Filesystem.php +++ b/inc/HTTP/WebDAV/Server/Filesystem.php @@ -323,7 +323,6 @@ function PUT(&$options) { $fspath = $options["path"]; - $dir = dirname($fspath); if (!OC_FILESYSTEM::file_exists($dir) || !OC_FILESYSTEM::is_dir($dir)) { return "409 Conflict"; // TODO right status code for both? @@ -394,7 +393,14 @@ if (!OC_FILESYSTEM::file_exists($path)) { return "404 Not found"; } - + $lock=self::checkLock($path); + if(is_array($lock)){ + $owner=$options['owner']; + $lockOwner=$lock['owner']; + if($owner==$lockOwner){ + return "423 Locked"; + } + } if (OC_FILESYSTEM::is_dir($path)) { $query = "DELETE FROM properties WHERE path LIKE '".$this->_slashify($options["path"])."%'"; OC_DB::query($query); @@ -593,11 +599,19 @@ { // get absolute fs path to requested resource $fspath = $options["path"]; - // TODO recursive locks on directories not supported yet // makes litmus test "32. lock_collection" fail - if (is_dir($fspath) && !empty($options["depth"])) { - return "409 Conflict"; + if (OC_FILESYSTEM::is_dir($fspath) && !empty($options["depth"])) { + switch($options["depth"]){ + case 'infinity': + $recursion=1; + break; + case '0': + $recursion=0; + break; + } + }else{ + $recursion=0; } $options["timeout"] = time()+300; // 5min. hardcoded @@ -606,11 +620,10 @@ $where = "WHERE path = '$options[path]' AND token = '$options[update]'"; $query = "SELECT owner, exclusivelock FROM locks $where"; - $res = OC_DB::query($query); - $row = OC_DB::fetch_assoc($res); - OC_DB::free_result($res); + $res = OC_DB::select($query); - if (is_array($row)) { + if (is_array($res) and isset($res[0])) { + $row=$res[0]; $query = "UPDATE `locks` SET `expires` = '$options[timeout]', `modified` = ".time()." $where"; OC_DB::query($query); @@ -619,8 +632,23 @@ $options['type'] = $row["exclusivelock"] ? "write" : "read"; return true; - } else { - return false; + } else {//check for indirect refresh + $query = "SELECT * + FROM locks + WHERE recursive = 1 + "; + $res = OC_DB::select($query); + foreach($res as $row){ + if(strpos($options['path'],$row['path'])==0){//are we a child of a folder with an recursive lock + $where = "WHERE path = '$row[path]' AND token = '$options[update]'"; + $query = "UPDATE `locks` SET `expires` = '$options[timeout]', `modified` = ".time()." $where"; + OC_DB::query($query); + $options['owner'] = $row['owner']; + $options['scope'] = $row["exclusivelock"] ? "exclusive" : "shared"; + $options['type'] = $row["exclusivelock"] ? "write" : "read"; + return true; + } + } } } @@ -631,11 +659,14 @@ , `modified` = ".time()." , `owner` = '$options[owner]' , `expires` = '$options[timeout]' - , `exclusivelock` = " .($options['scope'] === "exclusive" ? "1" : "0") - ; + , `exclusivelock` = " .($options['scope'] === "exclusive" ? "1" : "0")." + , `recursive` = $recursion"; OC_DB::query($query); - - return OC_DB::affected_rows() ? "200 OK" : "409 Conflict"; + $rows=OC_DB::affected_rows(); + if(!OC_FILESYSTEM::file_exists($fspath) and $rows>0) { + return "201 Created"; + } + return OC_DB::affected_rows($rows) ? "200 OK" : "409 Conflict"; } /** @@ -668,9 +699,8 @@ WHERE path = '$path' "; $res = OC_DB::select($query); - if ($res) { + if (is_array($res) and isset($res[0])) { $row=$res[0]; - OC_DB::free_result($res); if ($row) { $result = array( "type" => "write", @@ -680,8 +710,30 @@ "token" => $row['token'], "created" => $row['created'], "modified" => $row['modified'], - "expires" => $row['expires'] + "expires" => $row['expires'], + "recursive" => $row['recursive'] + ); + } + }else{ + //check for recursive locks; + $query = "SELECT * + FROM locks + WHERE recursive = 1 + "; + $res = OC_DB::select($query); + foreach($res as $row){ + if(strpos($path,$row['path'])==0){//are we a child of a folder with an recursive lock + $result = array( "type" => "write", + "scope" => $row["exclusivelock"] ? "exclusive" : "shared", + "depth" => 0, + "owner" => $row['owner'], + "token" => $row['token'], + "created" => $row['created'], + "modified" => $row['modified'], + "expires" => $row['expires'], + "recursive" => $row['recursive'] ); + } } }
Create new user:
user name