use an abstraction for file system functions to allow premisions and multiply storage backends

This commit is contained in:
Robin 2010-05-07 22:50:59 +02:00
parent ede1c64edd
commit 565410d8e2
8 changed files with 656 additions and 310 deletions

View File

@ -42,7 +42,7 @@ function return_bytes($val) {
header('Content-type: application/xml'); header('Content-type: application/xml');
$dir=isset($_GET['dir'])?$_GET['dir']:''; $dir=isset($_GET['dir'])?$_GET['dir']:'';
$files=OC_FILES::getdirectorycontent(realpath($CONFIG_DATADIRECTORY.'/'.$dir)); $files=OC_FILES::getdirectorycontent($dir);
$dirname=(isset($files[0]))?$files[0]['directory']:''; $dirname=(isset($files[0]))?$files[0]['directory']:'';
$dirname=substr($dirname,strrpos($dirname,'/')); $dirname=substr($dirname,strrpos($dirname,'/'));
$max_upload=min(return_bytes(ini_get('post_max_size')),return_bytes(ini_get('upload_max_filesize'))); $max_upload=min(return_bytes(ini_get('post_max_size')),return_bytes(ini_get('upload_max_filesize')));

View File

@ -24,40 +24,19 @@
require_once('../inc/lib_base.php'); require_once('../inc/lib_base.php');
function get_mime_type($filename, $mimePath = '../etc') {
$fileext = substr(strrchr($filename, '.'), 1);
if (empty($fileext)) return (false);
$regex = "/^([\w\+\-\.\/]+)\s+(\w+\s)*($fileext\s)/i";
$lines = file("$mimePath/mime.types");
foreach($lines as $line) {
if (substr($line, 0, 1) == '#') continue; // skip comments
$line = rtrim($line) . " ";
if (!preg_match($regex, $line, $matches)) continue; // no match to the extension
return ($matches[1]);
}
return (false); // no match at all
}
$file=$_GET['file']; $file=$_GET['file'];
$dir=(isset($_GET['dir']))?$_GET['dir']:''; $dir=(isset($_GET['dir']))?$_GET['dir']:'';
if(strstr($file,'..') or strstr($dir,'..')){ if(strstr($file,'..') or strstr($dir,'..')){
die(); die();
} }
$filename=$CONFIG_DATADIRECTORY.'/'.$dir.'/'.$file; $filename=$dir.'/'.$file;
// $ftype='application/octet-stream'; $ftype=OC_FILESYSTEM::getMimeType($filename);
// $finfo=new finfo(FILEINFO_MIME);
// $fres=@$finfo->file($filename);
// if (is_string($fres) && !empty($fres)) {
// $ftype = $fres;
// }
$ftype=get_mime_type($filename);
ob_end_clean(); ob_end_clean();
// echo $ftype;
// die();
header('Content-Type: '.$ftype); header('Content-Type: '.$ftype);
header('Expires: 0'); header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public'); header('Pragma: public');
header('Content-Length: ' . filesize($filename)); header('Content-Length: ' . OC_FILESYSTEM::filesize($filename));
readfile($filename);
OC_FILESYSTEM::readfile($filename);
?> ?>

View File

@ -1255,7 +1255,6 @@ class HTTP_WebDAV_Server
return; return;
} }
} }
$options["stream"] = fopen("php://input", "r"); $options["stream"] = fopen("php://input", "r");
$stat = $this->PUT($options); $stat = $this->PUT($options);

View File

@ -107,7 +107,7 @@
function PROPFIND(&$options, &$files) function PROPFIND(&$options, &$files)
{ {
// get absolute fs path to requested resource // get absolute fs path to requested resource
$fspath = $this->base . $options["path"]; $fspath = $options["path"];
// sanity check // sanity check
if (!file_exists($fspath)) { if (!file_exists($fspath)) {
@ -121,13 +121,13 @@
$files["files"][] = $this->fileinfo($options["path"]); $files["files"][] = $this->fileinfo($options["path"]);
// information for contained resources requested? // information for contained resources requested?
if (!empty($options["depth"]) && is_dir($fspath) && is_readable($fspath)) { if (!empty($options["depth"]) && OC_FILESYSTEM::is_dir($fspath) && OC_FILESYSTEM::is_readable($fspath)) {
// make sure path ends with '/' // make sure path ends with '/'
$options["path"] = $this->_slashify($options["path"]); $options["path"] = $this->_slashify($options["path"]);
// try to open directory // try to open directory
$handle = @opendir($fspath); $handle = @OC_FILESYSTEM::opendir($fspath);
if ($handle) { if ($handle) {
// ok, now get all its contents // ok, now get all its contents
@ -153,39 +153,39 @@
function fileinfo($path) function fileinfo($path)
{ {
// map URI path to filesystem path // map URI path to filesystem path
$fspath = $this->base . $path; $fspath =$path;
// create result array // create result array
$info = array(); $info = array();
// TODO remove slash append code when base clase is able to do it itself // TODO remove slash append code when base clase is able to do it itself
$info["path"] = is_dir($fspath) ? $this->_slashify($path) : $path; $info["path"] = OC_FILESYSTEM::is_dir($fspath) ? $this->_slashify($path) : $path;
$info["props"] = array(); $info["props"] = array();
// no special beautified displayname here ... // no special beautified displayname here ...
$info["props"][] = $this->mkprop("displayname", strtoupper($path)); $info["props"][] = $this->mkprop("displayname", strtoupper($path));
// creation and modification time // creation and modification time
$info["props"][] = $this->mkprop("creationdate", filectime($fspath)); $info["props"][] = $this->mkprop("creationdate", OC_FILESYSTEM::filectime($fspath));
$info["props"][] = $this->mkprop("getlastmodified", filemtime($fspath)); $info["props"][] = $this->mkprop("getlastmodified", OC_FILESYSTEM::filemtime($fspath));
// Microsoft extensions: last access time and 'hidden' status // Microsoft extensions: last access time and 'hidden' status
$info["props"][] = $this->mkprop("lastaccessed", fileatime($fspath)); $info["props"][] = $this->mkprop("lastaccessed", OC_FILESYSTEM::fileatime($fspath));
$info["props"][] = $this->mkprop("ishidden", ('.' === substr(basename($fspath), 0, 1))); $info["props"][] = $this->mkprop("ishidden", ('.' === substr(basename($fspath), 0, 1)));
// type and size (caller already made sure that path exists) // type and size (caller already made sure that path exists)
if (is_dir($fspath)) { if ( OC_FILESYSTEM::is_dir($fspath)) {
// directory (WebDAV collection) // directory (WebDAV collection)
$info["props"][] = $this->mkprop("resourcetype", "collection"); $info["props"][] = $this->mkprop("resourcetype", "collection");
$info["props"][] = $this->mkprop("getcontenttype", "httpd/unix-directory"); $info["props"][] = $this->mkprop("getcontenttype", "httpd/unix-directory");
} else { } else {
// plain file (WebDAV resource) // plain file (WebDAV resource)
$info["props"][] = $this->mkprop("resourcetype", ""); $info["props"][] = $this->mkprop("resourcetype", "");
if (is_readable($fspath)) { if ( OC_FILESYSTEM::is_readable($fspath)) {
$info["props"][] = $this->mkprop("getcontenttype", $this->_mimetype($fspath)); $info["props"][] = $this->mkprop("getcontenttype", $this->_mimetype($fspath));
} else { } else {
$info["props"][] = $this->mkprop("getcontenttype", "application/x-non-readable"); $info["props"][] = $this->mkprop("getcontenttype", "application/x-non-readable");
} }
$info["props"][] = $this->mkprop("getcontentlength", filesize($fspath)); $info["props"][] = $this->mkprop("getcontentlength", OC_FILESYSTEM::filesize($fspath));
} }
// get additional properties from database // get additional properties from database
@ -251,62 +251,7 @@
*/ */
function _mimetype($fspath) function _mimetype($fspath)
{ {
if (@is_dir($fspath)) { return OC_FILESYSTEM::getMimeType($fspath);
// directories are easy
return "httpd/unix-directory";
} else if (function_exists("mime_content_type")) {
// use mime magic extension if available
$mime_type = mime_content_type($fspath);
} else if ($this->_can_execute("file")) {
// it looks like we have a 'file' command,
// lets see it it does have mime support
$fp = popen("file -i '$fspath' 2>/dev/null", "r");
$reply = fgets($fp);
pclose($fp);
// popen will not return an error if the binary was not found
// and find may not have mime support using "-i"
// so we test the format of the returned string
// the reply begins with the requested filename
if (!strncmp($reply, "$fspath: ", strlen($fspath)+2)) {
$reply = substr($reply, strlen($fspath)+2);
// followed by the mime type (maybe including options)
if (preg_match('|^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*|', $reply, $matches)) {
$mime_type = $matches[0];
}
}
}
if (empty($mime_type)) {
// Fallback solution: try to guess the type by the file extension
// TODO: add more ...
// TODO: it has been suggested to delegate mimetype detection
// to apache but this has at least three issues:
// - works only with apache
// - needs file to be within the document tree
// - requires apache mod_magic
// TODO: can we use the registry for this on Windows?
// OTOH if the server is Windos the clients are likely to
// be Windows, too, and tend do ignore the Content-Type
// anyway (overriding it with information taken from
// the registry)
// TODO: have a seperate PEAR class for mimetype detection?
switch (strtolower(strrchr(basename($fspath), "."))) {
case ".html":
$mime_type = "text/html";
break;
case ".gif":
$mime_type = "image/gif";
break;
case ".jpg":
$mime_type = "image/jpeg";
break;
default:
$mime_type = "application/octet-stream";
break;
}
}
return $mime_type; return $mime_type;
} }
@ -320,10 +265,10 @@
function HEAD(&$options) function HEAD(&$options)
{ {
// get absolute fs path to requested resource // get absolute fs path to requested resource
$fspath = $this->base . $options["path"]; $fspath = $options["path"];
// sanity check // sanity check
if (!file_exists($fspath)) return false; if (! OC_FILESYSTEM::file_exists($fspath)) return false;
// detect resource type // detect resource type
$options['mimetype'] = $this->_mimetype($fspath); $options['mimetype'] = $this->_mimetype($fspath);
@ -332,10 +277,10 @@
// see rfc2518, section 13.7 // see rfc2518, section 13.7
// some clients seem to treat this as a reverse rule // some clients seem to treat this as a reverse rule
// requiering a Last-Modified header if the getlastmodified header was set // requiering a Last-Modified header if the getlastmodified header was set
$options['mtime'] = filemtime($fspath); $options['mtime'] = OC_FILESYSTEM::filemtime($fspath);
// detect resource size // detect resource size
$options['size'] = filesize($fspath); $options['size'] = OC_FILESYSTEM::filesize($fspath);
return true; return true;
} }
@ -348,11 +293,11 @@
*/ */
function GET(&$options) function GET(&$options)
{ {
// get absolute fs path to requested resource // get absolute fs path to requested resource)
$fspath = $this->base . $options["path"]; $fspath = $options["path"];
error_log("get '$fspath'");
// is this a collection? // is this a collection?
if (is_dir($fspath)) { if (OC_FILESYSTEM::is_dir($fspath)) {
return $this->GetDir($fspath, $options); return $this->GetDir($fspath, $options);
} }
@ -362,7 +307,7 @@
} }
// no need to check result here, it is handled by the base class // no need to check result here, it is handled by the base class
$options['stream'] = fopen($fspath, "r"); $options['stream'] = OC_FILESYSTEM::fopen($fspath, "r");
return true; return true;
} }
@ -387,11 +332,11 @@
// fixed width directory column format // fixed width directory column format
$format = "%15s %-19s %-s\n"; $format = "%15s %-19s %-s\n";
if (!is_readable($fspath)) { if (!OC_FILESYSTEM::is_readable($fspath)) {
return false; return false;
} }
$handle = opendir($fspath); $handle = OC_FILESYSTEM::opendir($fspath);
if (!$handle) { if (!$handle) {
return false; return false;
} }
@ -432,26 +377,25 @@
*/ */
function PUT(&$options) function PUT(&$options)
{ {
$fspath = $this->base . $options["path"]; $fspath = $options["path"];
$dir = dirname($fspath); $dir = dirname($fspath);
if (!file_exists($dir) || !is_dir($dir)) { if (!OC_FILESYSTEM::file_exists($dir) || !OC_FILESYSTEM::is_dir($dir)) {
return "409 Conflict"; // TODO right status code for both? return "409 Conflict"; // TODO right status code for both?
} }
$options["new"] = ! file_exists($fspath); $options["new"] = ! OC_FILESYSTEM::file_exists($fspath);
if ($options["new"] && !is_writeable($dir)) { if ($options["new"] && !OC_FILESYSTEM::is_writeable($dir)) {
return "403 Forbidden"; return "403 Forbidden";
} }
if (!$options["new"] && !is_writeable($fspath)) { if (!$options["new"] && !OC_FILESYSTEM::is_writeable($fspath)) {
return "403 Forbidden"; return "403 Forbidden";
} }
if (!$options["new"] && is_dir($fspath)) { if (!$options["new"] && OC_FILESYSTEM::is_dir($fspath)) {
return "403 Forbidden"; return "403 Forbidden";
} }
$fp = OC_FILESYSTEM::fopen($fspath, "w");
$fp = fopen($fspath, "w");
return $fp; return $fp;
} }
@ -465,19 +409,19 @@
*/ */
function MKCOL($options) function MKCOL($options)
{ {
$path = $this->base .$options["path"]; $path = $options["path"];
$parent = dirname($path); $parent = dirname($path);
$name = basename($path); $name = basename($path);
if (!file_exists($parent)) { if (!OC_FILESYSTEM::file_exists($parent)) {
return "409 Conflict"; return "409 Conflict";
} }
if (!is_dir($parent)) { if (!OC_FILESYSTEM::is_dir($parent)) {
return "403 Forbidden"; return "403 Forbidden";
} }
if ( file_exists($parent."/".$name) ) { if ( OC_FILESYSTEM::file_exists($parent."/".$name) ) {
return "405 Method not allowed"; return "405 Method not allowed";
} }
@ -485,7 +429,7 @@
return "415 Unsupported media type"; return "415 Unsupported media type";
} }
$stat = mkdir($parent."/".$name, 0777); $stat = OC_FILESYSTEM::mkdir($parent."/".$name, 0777);
if (!$stat) { if (!$stat) {
return "403 Forbidden"; return "403 Forbidden";
} }
@ -502,18 +446,20 @@
*/ */
function DELETE($options) function DELETE($options)
{ {
$path = $this->base . "/" .$options["path"]; $path =$options["path"];
if (!file_exists($path)) { if (!OC_FILESYSTEM::file_exists($path)) {
return "404 Not found"; return "404 Not found";
} }
if (is_dir($path)) { if (OC_FILESYSTEM::is_dir($path)) {
$query = "DELETE FROM properties WHERE path LIKE '".$this->_slashify($options["path"])."%'"; $query = "DELETE FROM properties WHERE path LIKE '".$this->_slashify($options["path"])."%'";
OC_DB::query($query); OC_DB::query($query);
System::rm(array("-rf, $path")); // System::rm(array("-rf, $path"));
error_log('delTree');
OC_FILESYSTEM::delTree($path);
} else { } else {
unlink($path); OC_FILESYSTEM::unlink($path);
} }
$query = "DELETE FROM properties WHERE path = '$options[path]'"; $query = "DELETE FROM properties WHERE path = '$options[path]'";
OC_DB::query($query); OC_DB::query($query);
@ -552,12 +498,12 @@
return "502 bad gateway"; return "502 bad gateway";
} }
$source = $this->base . $options["path"]; $source = $options["path"];
if (!file_exists($source)) { if (!OC_FILESYSTEM::file_exists($source)) {
return "404 Not found"; return "404 Not found";
} }
if (is_dir($source)) { // resource is a collection if (OC_FILESYSTEM::is_dir($source)) { // resource is a collection
switch ($options["depth"]) { switch ($options["depth"]) {
case "infinity": // valid case "infinity": // valid
break; break;
@ -572,24 +518,24 @@
} }
} }
$dest = $this->base . $options["dest"]; $dest = $options["dest"];
$destdir = dirname($dest); $destdir = dirname($dest);
if (!file_exists($destdir) || !is_dir($destdir)) { if (!OC_FILESYSTEM::file_exists($destdir) || !OC_FILESYSTEM::is_dir($destdir)) {
return "409 Conflict"; return "409 Conflict";
} }
$new = !file_exists($dest); $new = !OC_FILESYSTEM::file_exists($dest);
$existing_col = false; $existing_col = false;
if (!$new) { if (!$new) {
if ($del && is_dir($dest)) { if ($del && OC_FILESYSTEM::is_dir($dest)) {
if (!$options["overwrite"]) { if (!$options["overwrite"]) {
return "412 precondition failed"; return "412 precondition failed";
} }
$dest .= basename($source); $dest .= basename($source);
if (file_exists($dest)) { if (OC_FILESYSTEM::file_exists($dest)) {
$options["dest"] .= basename($source); $options["dest"] .= basename($source);
} else { } else {
$new = true; $new = true;
@ -610,7 +556,7 @@
} }
if ($del) { if ($del) {
if (!rename($source, $dest)) { if (!OC_FILESYSTEM::rename($source, $dest)) {
return "500 Internal server error"; return "500 Internal server error";
} }
$destpath = $this->_unslashify($options["dest"]); $destpath = $this->_unslashify($options["dest"]);
@ -626,8 +572,8 @@
WHERE path = '".$options["path"]."'"; WHERE path = '".$options["path"]."'";
OC_DB::query($query); OC_DB::query($query);
} else { } else {
if (is_dir($source)) { if (OC_FILESYSTEM::is_dir($source)) {
$files = System::find($source); $files = OC_FILESYSTEM::find($source);
$files = array_reverse($files); $files = array_reverse($files);
} else { } else {
$files = array($source); $files = array($source);
@ -639,26 +585,26 @@
foreach ($files as $file) { foreach ($files as $file) {
if (is_dir($file)) { if (OC_FILESYSTEM::is_dir($file)) {
$file = $this->_slashify($file); $file = $this->_slashify($file);
} }
$destfile = str_replace($source, $dest, $file); $destfile = str_replace($source, $dest, $file);
if (is_dir($file)) { if (OC_FILESYSTEM::is_dir($file)) {
if (!file_exists($destfile)) { if (!OC_FILESYSTEM::file_exists($destfile)) {
if (!is_writeable(dirname($destfile))) { if (!OC_FILESYSTEM::is_writeable(dirname($destfile))) {
return "403 Forbidden"; return "403 Forbidden";
} }
if (!mkdir($destfile)) { if (!OC_FILESYSTEM::mkdir($destfile)) {
return "409 Conflict"; return "409 Conflict";
} }
} else if (!is_dir($destfile)) { } else if (!OC_FILESYSTEM::is_dir($destfile)) {
return "409 Conflict"; return "409 Conflict";
} }
} else { } else {
if (!copy($file, $destfile)) { if (!OC_FILESYSTEM::copy($file, $destfile)) {
return "409 Conflict"; return "409 Conflict";
} }
} }
@ -712,7 +658,7 @@
function LOCK(&$options) function LOCK(&$options)
{ {
// get absolute fs path to requested resource // get absolute fs path to requested resource
$fspath = $this->base . $options["path"]; $fspath = $options["path"];
// TODO recursive locks on directories not supported yet // TODO recursive locks on directories not supported yet
// makes litmus test "32. lock_collection" fail // makes litmus test "32. lock_collection" fail
@ -731,7 +677,7 @@
OC_DB::free_result($res); OC_DB::free_result($res);
if (is_array($row)) { if (is_array($row)) {
$query = "UPDATE locks SET expires = '$options[timeout]', modified = ".time()." $where"; $query = "UPDATE `locks` SET `expires` = '$options[timeout]', `modified` = ".time()." $where";
OC_DB::query($query); OC_DB::query($query);
$options['owner'] = $row['owner']; $options['owner'] = $row['owner'];
@ -744,14 +690,14 @@
} }
} }
$query = "INSERT INTO locks $query = "INSERT INTO `locks`
SET token = '$options[locktoken]' SET `token` = '$options[locktoken]'
, path = '$options[path]' , `path` = '$options[path]'
, created = ".time()." , `created` = ".time()."
, modified = ".time()." , `modified` = ".time()."
, owner = '$options[owner]' , `owner` = '$options[owner]'
, expires = '$options[timeout]' , `expires` = '$options[timeout]'
, exclusivelock = " .($options['scope'] === "exclusive" ? "1" : "0") , `exclusivelock` = " .($options['scope'] === "exclusive" ? "1" : "0")
; ;
OC_DB::query($query); OC_DB::query($query);
@ -783,15 +729,13 @@
function checkLock($path) function checkLock($path)
{ {
$result = false; $result = false;
$query = "SELECT *
$query = "SELECT owner, token, created, modified, expires, exclusivelock
FROM locks FROM locks
WHERE path = '$path' WHERE path = '$path'
"; ";
$res = OC_DB::query($query); $res = OC_DB::select($query);
if ($res) { if ($res) {
$row = OC_DB::fetch_assoc($res); $row=$res[0];
OC_DB::free_result($res); OC_DB::free_result($res);
if ($row) { if ($row) {

View File

@ -68,6 +68,7 @@ if(isset($CONFIG_HTTPFORCESSL) and $CONFIG_HTTPFORCESSL){
// load core libs // load core libs
oc_require_once('lib_files.php'); oc_require_once('lib_files.php');
oc_require_once('lib_filesystem.php');
oc_require_once('lib_log.php'); oc_require_once('lib_log.php');
oc_require_once('lib_config.php'); oc_require_once('lib_config.php');
oc_require_once('lib_user.php'); oc_require_once('lib_user.php');
@ -85,6 +86,8 @@ if(OC_USER::isLoggedIn()){
if(!is_dir($CONFIG_DATADIRECTORY)){ if(!is_dir($CONFIG_DATADIRECTORY)){
mkdir($CONFIG_DATADIRECTORY); mkdir($CONFIG_DATADIRECTORY);
} }
$rootStorage=new OC_FILESTORAGE_LOCAL(array('datadir'=>$CONFIG_DATADIRECTORY));
OC_FILESYSTEM::mount($rootStorage,'/');
} }
// load plugins // load plugins

View File

@ -28,7 +28,7 @@
* *
*/ */
class OC_FILES { class OC_FILES {
static $tmpFiles=array();
/** /**
* show a web GUI filebrowser * show a web GUI filebrowser
* *
@ -44,28 +44,32 @@ class OC_FILES {
* @param dir $directory * @param dir $directory
*/ */
public static function getdirectorycontent($directory){ public static function getdirectorycontent($directory){
global $CONFIG_DATADIRECTORY;
if(strpos($directory,$CONFIG_DATADIRECTORY)===0){
$directory=substr($directory,strlen($CONFIG_DATADIRECTORY));
}
$filesfound=true; $filesfound=true;
$content=array(); $content=array();
$dirs=array(); $dirs=array();
$file=array(); $file=array();
$files=array(); $files=array();
if (is_dir($directory)) { if (OC_FILESYSTEM::is_dir($directory)) {
if ($dh = opendir($directory)) { if ($dh = OC_FILESYSTEM::opendir($directory)) {
while (($filename = readdir($dh)) !== false) { while (($filename = readdir($dh)) !== false) {
if($filename<>'.' and $filename<>'..'){ if($filename<>'.' and $filename<>'..' and substr($filename,0,1)!='.'){
$file=array(); $file=array();
$filesfound=true; $filesfound=true;
$file['name']=$filename; $file['name']=$filename;
$file['directory']=$directory; $file['directory']=$directory;
$stat=stat($directory.'/'.$filename); $stat=OC_FILESYSTEM::stat($directory.'/'.$filename);
$file=array_merge($file,$stat); $file=array_merge($file,$stat);
$file['mime']=OC_FILES::getMimeType($directory .'/'. $filename); $file['mime']=OC_FILES::getMimeType($directory .'/'. $filename);
$file['type']=filetype($directory .'/'. $filename); $file['type']=OC_FILESYSTEM::filetype($directory .'/'. $filename);
if($file['type']=='dir'){ if($file['type']=='dir'){
$dirs[$file['name']]=$file; $dirs[$file['name']]=$file;
}else{ }else{
$files[$file['name']]=$file; $files[$file['name']]=$file;
} }
} }
} }
closedir($dh); closedir($dh);
@ -90,10 +94,6 @@ class OC_FILES {
* @param file $file * @param file $file
*/ */
public static function get($dir,$files){ public static function get($dir,$files){
global $CONFIG_DATADIRECTORY;
if(strstr($files,'..') or strstr($dir,'..')){
die();
}
if(strpos($files,';')){ if(strpos($files,';')){
$files=explode(';',$files); $files=explode(';',$files);
} }
@ -104,39 +104,45 @@ class OC_FILES {
exit("cannot open <$filename>\n"); exit("cannot open <$filename>\n");
} }
foreach($files as $file){ foreach($files as $file){
$file=$CONFIG_DATADIRECTORY.'/'.$dir.'/'.$file; $file=$dir.'/'.$file;
if(is_file($file)){ if(OC_FILESYSTEM::is_file($file)){
$zip->addFile($file,basename($file)); $tmpFile=OC_FILESYSTEM::toTmpFile($file);
}elseif(is_dir($file)){ self::$tmpFiles[]=$tmpFile;
$zip->addFile($tmpFile,basename($file));
}elseif(OC_FILESYSTEM::is_dir($file)){
zipAddDir($file,$zip); zipAddDir($file,$zip);
} }
} }
$zip->close(); $zip->close();
}elseif(is_dir($CONFIG_DATADIRECTORY.'/'.$dir.'/'.$files)){ }elseif(OC_FILESYSTEM::is_dir($dir.'/'.$files)){
$zip = new ZipArchive(); $zip = new ZipArchive();
$filename = sys_get_temp_dir()."/ownCloud.zip"; $filename = sys_get_temp_dir()."/ownCloud.zip";
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) { if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
exit("cannot open <$filename>\n"); exit("cannot open <$filename>\n");
} }
$file=$CONFIG_DATADIRECTORY.'/'.$dir.'/'.$files; $file=$dir.'/'.$files;
zipAddDir($file,$zip); zipAddDir($file,$zip);
$zip->close(); $zip->close();
}else{ }else{
$zip=false; $zip=false;
$filename=$CONFIG_DATADIRECTORY.'/'.$dir.'/'.$files; $filename=$dir.'/'.$files;
} }
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($filename)); header('Content-Disposition: attachment; filename='.basename($filename));
header('Content-Transfer-Encoding: binary'); header('Content-Transfer-Encoding: binary');
header('Expires: 0'); header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public'); header('Pragma: public');
header('Content-Length: ' . filesize($filename)); header('Content-Length: ' . filesize($filename));
if(!$zip){
$filename=OC_FILESYSTEM::toTmpFile($filename);
}
ob_end_clean(); ob_end_clean();
readfile($filename); readfile($filename);
if($zip){ unlink($filename);
unlink($filename); foreach(self::$tmpFiles as $tmpFile){
if(file_exists($tmpFile) and is_file($tmpFile)){
unlink($tmpFile);
}
} }
} }
@ -149,11 +155,10 @@ class OC_FILES {
* @param file $target * @param file $target
*/ */
public static function move($sourceDir,$source,$targetDir,$target){ public static function move($sourceDir,$source,$targetDir,$target){
global $CONFIG_DATADIRECTORY; if(OC_USER::isLoggedIn()){
if(OC_USER::isLoggedIn() and strpos($sourceDir,'..')===false and strpos($source,'..')===false and strpos($targetDir,'..')===false and strpos($target,'..')===false){ $targetFile=$targetDir.'/'.$target;
$targetFile=$CONFIG_DATADIRECTORY.'/'.$targetDir.'/'.$target; $sourceFile=$sourceDir.'/'.$source;
$sourceFile=$CONFIG_DATADIRECTORY.'/'.$sourceDir.'/'.$source; OC_FILESYSTEM::rename($sourceFile,$targetFile);
rename($sourceFile,$targetFile);
} }
} }
@ -165,13 +170,12 @@ class OC_FILES {
* @param type $type * @param type $type
*/ */
public static function newfile($dir,$name,$type){ public static function newfile($dir,$name,$type){
global $CONFIG_DATADIRECTORY; if(OC_USER::isLoggedIn()){
if(OC_USER::isLoggedIn() and strpos($dir,'..')===false and strpos($name,'..')===false){ $file=$dir.'/'.$name;
$file=$CONFIG_DATADIRECTORY.'/'.$dir.'/'.$name;
if($type=='dir'){ if($type=='dir'){
mkdir($file); OC_FILESYSTEM::mkdir($file);
}elseif($type=='file'){ }elseif($type=='file'){
$fileHandle=fopen($file, 'w') or die("can't open file"); $fileHandle=OC_FILESYSTEM::fopen($file, 'w') or die("can't open file");
fclose($fileHandle); fclose($fileHandle);
} }
} }
@ -184,13 +188,12 @@ class OC_FILES {
* @param file $name * @param file $name
*/ */
public static function delete($dir,$file){ public static function delete($dir,$file){
global $CONFIG_DATADIRECTORY; if(OC_USER::isLoggedIn()){
if(OC_USER::isLoggedIn() and strpos($dir,'..')===false){ $file=$dir.'/'.$file;
$file=$CONFIG_DATADIRECTORY.'/'.$dir.'/'.$file; if(OC_FILESYSTEM::is_file($file)){
if(is_file($file)){ OC_FILESYSTEM::unlink($file);
unlink($file); }elseif(OC_FILESYSTEM::is_dir($file)){
}elseif(is_dir($file)){ OC_FILESYSTEM::delTree($file);
rmdir($file);
} }
} }
} }
@ -198,108 +201,11 @@ class OC_FILES {
/** /**
* try to detect the mime type of a file * try to detect the mime type of a file
* *
* @param string file path * @param string path
* @return string guessed mime type * @return string guessed mime type
*/ */
function getMimeType($fspath){ function getMimeType($path){
if (@is_dir($fspath)) { return OC_FILESYSTEM::getMimeType($path);
// directories are easy
return "httpd/unix-directory";
} else if (function_exists("mime_content_type")) {
// use mime magic extension if available
$mime_type = mime_content_type($fspath);
} else if (OC_FILES::canExecute("file")) {
// it looks like we have a 'file' command,
// lets see it it does have mime support
$fp = popen("file -i '$fspath' 2>/dev/null", "r");
$reply = fgets($fp);
pclose($fp);
// popen will not return an error if the binary was not found
// and find may not have mime support using "-i"
// so we test the format of the returned string
// the reply begins with the requested filename
if (!strncmp($reply, "$fspath: ", strlen($fspath)+2)) {
$reply = substr($reply, strlen($fspath)+2);
// followed by the mime type (maybe including options)
if (preg_match('/^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*/', $reply, $matches)) {
$mime_type = $matches[0];
}
}
}
if (empty($mime_type)) {
// Fallback solution: try to guess the type by the file extension
// TODO: add more ...
switch (strtolower(strrchr(basename($fspath), "."))) {
case ".html":
$mime_type = "text/html";
break;
case ".txt":
$mime_type = "text/plain";
break;
case ".css":
$mime_type = "text/css";
break;
case ".gif":
$mime_type = "image/gif";
break;
case ".jpg":
$mime_type = "image/jpeg";
break;
case ".jpg":
$mime_type = "png/jpeg";
break;
default:
$mime_type = "application/octet-stream";
break;
}
}
return $mime_type;
}
/**
* detect if a given program is found in the search PATH
*
* helper function used by _mimetype() to detect if the
* external 'file' utility is available
*
* @param string program name
* @param string optional search path, defaults to $PATH
* @return bool true if executable program found in path
*/
function canExecute($name, $path = false)
{
// path defaults to PATH from environment if not set
if ($path === false) {
$path = getenv("PATH");
}
// check method depends on operating system
if (!strncmp(PHP_OS, "WIN", 3)) {
// on Windows an appropriate COM or EXE file needs to exist
$exts = array(".exe", ".com");
$check_fn = "file_exists";
} else {
// anywhere else we look for an executable file of that name
$exts = array("");
$check_fn = "is_executable";
}
// now check the directories in the path for the program
foreach (explode(PATH_SEPARATOR, $path) as $dir) {
// skip invalid path entries
if (!file_exists($dir)) continue;
if (!is_dir($dir)) continue;
// and now look for the file
foreach ($exts as $ext) {
if ($check_fn("$dir/$name".$ext)) return true;
}
}
return false;
} }
} }
@ -312,9 +218,11 @@ function zipAddDir($dir,$zip,$internalDir=''){
foreach($files as $file){ foreach($files as $file){
$filename=$file['name']; $filename=$file['name'];
$file=$dir.'/'.$filename; $file=$dir.'/'.$filename;
if(is_file($file)){ if(OC_FILESYSTEM::is_file($file)){
$zip->addFile($file,$internalDir.$filename); $tmpFile=OC_FILESYSTEM::toTmpFile($file);
}elseif(is_dir($file)){ OC_FILES::$tmpFiles[]=$tmpFile;
$zip->addFile($tmpFile,$internalDir.$filename);
}elseif(OC_FILESYSTEM::is_dir($file)){
zipAddDir($file,$zip,$internalDir); zipAddDir($file,$zip,$internalDir);
} }
} }

511
inc/lib_filesystem.php Executable file
View File

@ -0,0 +1,511 @@
<?php
/**
* ownCloud
*
* @author Frank Karlitschek
* @copyright 2010 Frank Karlitschek karlitschek@kde.org
*
* 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
* 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
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* Class for abstraction of filesystem functions
* This class won't call any filesystem functions for itself but but will pass them to the correct OC_FILESTORAGE object
* this class should also handle all the file premission related stuff
*/
class OC_FILESYSTEM{
static private $storages=array();
/**
* check if the current users has the right premissions to read a file
* @param string path
* @return bool
*/
static private function canRead(){
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
}
/**
* check if the current users has the right premissions to write a file
* @param string path
* @return bool
*/
static private function canWrite(){
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
}
/**
* mount an OC_FILESTORAGE in our virtual filesystem
* @param OC_FILESTORAGE storage
* @param string mountpoint
*/
static public function mount($storage,$mountpoint){
if(substr($mountpoint,0,1)!=='/'){
$mountpoint='/'.$mountpoint;
}
self::$storages[$mountpoint]=$storage;
}
/**
* get the storage object for a path
* @param string path
* @return OC_FILESTORAGE
*/
static private function getStorage($path){
$mountpoint=self::getMountPoint($path);
if($mountpoint){
return self::$storages[$mountpoint];
}
}
/**
* get the mountpoint of the storage object for a path
* @param string path
* @return string
*/
static private function getMountPoint($path){
if(!$path){
$path='/';
}
if(substr($path,0,1)!=='/'){
$path='/'.$path;
}
$foundMountPoint='';
foreach(self::$storages as $mountpoint=>$storage){
if($mountpoint==$path){
return $mountpoint;
}
if(strpos($path,$mountpoint)===0 and strlen($mountpoint)>strlen($foundMountPoint)){
$foundMountPoint=$mountpoint;
}
}
return $foundMountPoint;
}
static public function mkdir($path){
$parent=substr($path,0,strrpos($path,'/'));
if(self::canWrite($parent) and $storage=self::getStorage($path)){
return $storage->mkdir(substr($path,strlen(self::getMountPoint($path))));
}
}
static public function rmdir($path){
if(self::canWrite($path) and $storage=self::getStorage($path)){
return $storage->rmdir(substr($path,strlen(self::getMountPoint($path))));
}
}
static public function opendir($path){
if(self::canRead($path) and $storage=self::getStorage($path)){
return $storage->opendir(substr($path,strlen(self::getMountPoint($path))));
}
}
static public function is_dir($path){
if($path=='/'){
return true;
}
if(self::canRead($path) and $storage=self::getStorage($path)){
return $storage->is_dir(substr($path,strlen(self::getMountPoint($path))));
}
}
static public function is_file($path){
if($path=='/'){
return false;
}
if(self::canRead($path) and $storage=self::getStorage($path)){
return $storage->is_file(substr($path,strlen(self::getMountPoint($path))));
}
}
static public function stat($path){
if(self::canRead($path) and $storage=self::getStorage($path)){
return $storage->stat(substr($path,strlen(self::getMountPoint($path))));
}
}
static public function filetype($path){
if(self::canRead($path) and $storage=self::getStorage($path)){
return $storage->filetype(substr($path,strlen(self::getMountPoint($path))));
}
}
static public function filesize($path){
if(self::canRead($path) and $storage=self::getStorage($path)){
return $storage->filesize(substr($path,strlen(self::getMountPoint($path))));
}
}
static public function readfile($path){
if(self::canRead($path) and $storage=self::getStorage($path)){
return $storage->readfile(substr($path,strlen(self::getMountPoint($path))));
}
}
static public function is_readable($path){
if(self::canRead($path) and $storage=self::getStorage($path)){
return $storage->is_readable(substr($path,strlen(self::getMountPoint($path))));
}
return false;
}
static public function is_writeable($path){
if(self::canWrite($path) and $storage=self::getStorage($path)){
return $storage->is_writeable(substr($path,strlen(self::getMountPoint($path))));
}
return false;
}
static public function file_exists($path){
if($path=='/'){
return true;
}
if(self::canWrite($path) and $storage=self::getStorage($path)){
return $storage->file_exists(substr($path,strlen(self::getMountPoint($path))));
}
return false;
}
static public function filectime($path){
if($storage=self::getStorage($path)){
return $storage->filectime(substr($path,strlen(self::getMountPoint($path))));
}
}
static public function filemtime($path){
if($storage=self::getStorage($path)){
return $storage->filemtime(substr($path,strlen(self::getMountPoint($path))));
}
}
static public function fileatime($path){
if($storage=self::getStorage($path)){
return $storage->fileatime(substr($path,strlen(self::getMountPoint($path))));
}
}
static public function file_get_contents($path){
if(self::canRead($path) and $storage=self::getStorage($path)){
return $storage->file_get_contents(substr($path,strlen(self::getMountPoint($path))));
}
}
static public function file_put_contents($path){
if(self::canWrite($path) and $storage=self::getStorage($path)){
return $storage->file_put_contents(substr($path,strlen(self::getMountPoint($path))));
}
}
static public function unlink($path){
if(self::canWrite($path) and $storage=self::getStorage($path)){
return $storage->unlink(substr($path,strlen(self::getMountPoint($path))));
}
}
static public function rename($path1,$path2){
if(self::canWrite($path1) and self::canWrite($path2)){
$mp1=self::getMountPoint($path1);
$mp2=self::getMountPoint($path2);
if($mp1==$mp2){
if($storage=self::getStorage($path1)){
return $storage->rename(substr($path1,strlen($mp1)),substr($path2,strlen($mp2)));
}
}elseif($storage1=self::getStorage($path1) and $storage2=self::getStorage($path2)){
$tmpFile=$storage1->toTmpFile(substr($path1,strlen($mp1)));
$result=$storage2->fromTmpFile($tmpFile,substr($path2,strlen($mp2)));
$storage1->unlink(substr($path1,strlen($mp1)));
return $result;
}
}
}
static public function copy($path1,$path2){
if(self::canRead($path1) and self::canWrite($path2)){
$mp1=self::getMountPoint($path1);
$mp2=self::getMountPoint($path2);
if($mp1==$mp2){
if($storage=self::getStorage($path1)){
return $storage->copy(substr($path1,strlen($mp1)),substr($path2,strlen($mp2)));
}
}elseif($storage1=self::getStorage($path1) and $storage2=self::getStorage($path2)){
$tmpFile=$storage1->toTmpFile(substr($path1,strlen($mp1)));
return $storage2->fromTmpFile($tmpFile,substr($path2,strlen($mp2)));
}
}
}
static public function fopen($path,$mode){
$allowed=((strpos($path,'r')===false and strpos($path,'r+')!==false and self::canRead) or self::canWrite($path));
if($allowed){
if($storage=self::getStorage($path)){
return $storage->fopen(substr($path,strlen(self::getMountPoint($path))),$mode);
}
}
}
static public function toTmpFile($path){
if(self::canRead($path) and $storage=self::getStorage($path)){
return $storage->toTmpFile(substr($path,strlen(self::getMountPoint($path))));
}
}
static public function fromTmpFile($tmpFile,$path){
if(self::canWrite($path) and $storage=self::getStorage($path)){
return $storage->fromTmpFile($tmpFile,substr($path,strlen(self::getMountPoint($path))));
}
}
static public function getMimeType($path){
if(self::canRead($path) and $storage=self::getStorage($path)){
return $storage->getMimeType(substr($path,strlen(self::getMountPoint($path))));
}
}
static public function delTree($path){
if(self::canWrite($path) and $storage=self::getStorage($path)){
return $storage->delTree(substr($path,strlen(self::getMountPoint($path))));
}
}
static public function find($path){
if($storage=self::getStorage($path)){
return $storage->find(substr($path,strlen(self::getMountPoint($path))));
}
}
}
/**
* Privde a common interface to all different storage options
*/
interface OC_FILESTORAGE{
public function __construct($parameters);
public function mkdir($path);
public function rmdir($path);
public function opendir($path);
public function is_dir($path);
public function is_file($path);
public function stat($path);
public function filetype($path);
public function filesize($path);
public function is_readable($path);
public function is_writeable($path);
public function file_exists($path);
public function readfile($path);
public function filectime($path);
public function filemtime($path);
public function fileatime($path);
public function file_get_contents($path);
public function file_put_contents($path);
public function unlink($path);
public function rename($path1,$path2);
public function copy($path1,$path2);
public function fopen($path,$mode);
public function toTmpFile($path);//copy the file to a temporary file, used for cross-storage file actions
public function fromTmpFile($tmpPath,$path);//copy a file from a temporary file, used for cross-storage file actions
public function getMimeType($path);
public function delTree($path);
public function find($path);
}
/**
* for local filestore, we only have to map the paths
*/
class OC_FILESTORAGE_LOCAL implements OC_FILESTORAGE{
private $datadir;
public function __construct($arguments){
$this->datadir=$arguments['datadir'];
if(substr($this->datadir,-1)!=='/'){
$this->datadir.='/';
}
}
public function mkdir($path){
return mkdir($this->datadir.$path);
}
public function rmdir($path){
return rmdir($this->datadir.$path);
}
public function opendir($path){
return opendir($this->datadir.$path);
}
public function is_dir($path){
return is_dir($this->datadir.$path);
}
public function is_file($path){
return is_file($this->datadir.$path);
}
public function stat($path){
return stat($this->datadir.$path);
}
public function filetype($path){
return filetype($this->datadir.$path);
}
public function filesize($path){
return filesize($this->datadir.$path);
}
public function is_readable($path){
return is_readable($this->datadir.$path);
}
public function is_writeable($path){
return is_writeable($this->datadir.$path);
}
public function file_exists($path){
return file_exists($this->datadir.$path);
}
public function readfile($path){
return readfile($this->datadir.$path);
}
public function filectime($path){
return filectime($this->datadir.$path);
}
public function filemtime($path){
return filemtime($this->datadir.$path);
}
public function fileatime($path){
return fileatime($this->datadir.$path);
}
public function file_get_contents($path){
return file_get_contents($this->datadir.$path);
}
public function file_put_contents($path){
return file_put_contents($this->datadir.$path);
}
public function unlink($path){
return unlink($this->datadir.$path);
}
public function rename($path1,$path2){
return rename($this->datadir.$path1,$this->datadir.$path2);
}
public function copy($path1,$path2){
return copy($this->datadir.$path1,$this->datadir.$path2);
}
public function fopen($path,$mode){
return fopen($this->datadir.$path,$mode);
}
public function getMimeType($fspath){
if (@is_dir($this->datadir.$fspath)) {
// directories are easy
return "httpd/unix-directory";
} else if (function_exists("mime_content_type")) {
// use mime magic extension if available
$mime_type = mime_content_type($this->datadir.$fspath);
} else if (self::canExecute("file")) {
// it looks like we have a 'file' command,
// lets see it it does have mime support
$fp = popen("file -i '$fspath' 2>/dev/null", "r");
$reply = fgets($fp);
pclose($fp);
// popen will not return an error if the binary was not found
// and find may not have mime support using "-i"
// so we test the format of the returned string
// the reply begins with the requested filename
if (!strncmp($reply, "$fspath: ", strlen($fspath)+2)) {
$reply = substr($reply, strlen($fspath)+2);
// followed by the mime type (maybe including options)
if (preg_match('/^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*/', $reply, $matches)) {
$mime_type = $matches[0];
}
}
}
if (empty($mime_type)) {
// Fallback solution: try to guess the type by the file extension
// TODO: add more ...
switch (strtolower(strrchr(basename($fspath), "."))) {
case ".html":
$mime_type = "text/html";
break;
case ".txt":
$mime_type = "text/plain";
break;
case ".css":
$mime_type = "text/css";
break;
case ".gif":
$mime_type = "image/gif";
break;
case ".jpg":
$mime_type = "image/jpeg";
break;
case ".jpeg":
$mime_type = "image/jpeg";
break;
case ".png":
$mime_type = "image/png";
break;
default:
$mime_type = "application/octet-stream";
break;
}
}
return $mime_type;
}
/**
* detect if a given program is found in the search PATH
*
* helper function used by _mimetype() to detect if the
* external 'file' utility is available
*
* @param string program name
* @param string optional search path, defaults to $PATH
* @return bool true if executable program found in path
*/
private function canExecute($name, $path = false)
{
// path defaults to PATH from environment if not set
if ($path === false) {
$path = getenv("PATH");
}
// check method depends on operating system
if (!strncmp(PHP_OS, "WIN", 3)) {
// on Windows an appropriate COM or EXE file needs to exist
$exts = array(".exe", ".com");
$check_fn = "file_exists";
} else {
// anywhere else we look for an executable file of that name
$exts = array("");
$check_fn = "is_executable";
}
// now check the directories in the path for the program
foreach (explode(PATH_SEPARATOR, $path) as $dir) {
// skip invalid path entries
if (!file_exists($dir)) continue;
if (!is_dir($dir)) continue;
// and now look for the file
foreach ($exts as $ext) {
if ($check_fn("$dir/$name".$ext)) return true;
}
}
return false;
}
public function toTmpFile($path){
$tmpFolder=sys_get_temp_dir();
$filename=tempnam($tmpFolder,'OC_TEMP_FILE_'.substr($path,strrpos($path,'.')));
copy($this->datadir.$path,$filename);
return $filename;
}
public function fromTmpFile($tmpFile,$path){
copy($tmpFile,$this->datadir.$path);
unlink($tmpFile);
}
public function delTree($dir) {
$dirRelative=$dir;
$dir=$this->datadir.$dir;
if (!file_exists($dir)) return true;
if (!is_dir($dir) || is_link($dir)) return unlink($dir);
foreach (scandir($dir) as $item) {
if ($item == '.' || $item == '..') continue;
if(is_file($dir.'/'.$item)){
unlink($dir.'/'.$item);
}elseif(is_dir($dir.'/'.$item)){
if (!$this->delTree($dirRelative. "/" . $item)){
return false;
};
}
}
return rmdir($dir);
}
public function find($path){
return System::find($this->datadir.$path);
}
}
?>

View File

@ -43,6 +43,8 @@ if(OC_USER::login($user,$passwd)){
if(!is_dir($CONFIG_DATADIRECTORY)){ if(!is_dir($CONFIG_DATADIRECTORY)){
mkdir($CONFIG_DATADIRECTORY); mkdir($CONFIG_DATADIRECTORY);
} }
$rootStorage=new OC_FILESTORAGE_LOCAL(array('datadir'=>$CONFIG_DATADIRECTORY));
OC_FILESYSTEM::mount($rootStorage,'/');
$server = new HTTP_WebDAV_Server_Filesystem(); $server = new HTTP_WebDAV_Server_Filesystem();
$server->db_name = $CONFIG_DBNAME; $server->db_name = $CONFIG_DBNAME;
$server->ServeRequest($CONFIG_DATADIRECTORY); $server->ServeRequest($CONFIG_DATADIRECTORY);