00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 include_once( "lib/ezwebdav/classes/ezwebdavserver.php" );
00046 include_once( "lib/ezutils/classes/ezmimetype.php" );
00047
00048
00049 function getDirEntries( $targetPath )
00050 {
00051 $files = array();
00052
00053
00054 if ( $handle = opendir( $targetPath ) )
00055 {
00056
00057 while ( false !== ( $file = readdir( $handle ) ) )
00058 {
00059 if ( $file != "." && $file != ".." )
00060 {
00061 $files[] = $file;
00062 }
00063 }
00064 closedir( $handle );
00065 }
00066
00067 else
00068 {
00069 return false;
00070 }
00071
00072
00073 return $files;
00074 }
00075
00076
00077 function copyDir( $source, $destination )
00078 {
00079
00080 $status = mkdir( $destination );
00081
00082
00083 if ( !$status )
00084 {
00085 return false;
00086 }
00087
00088
00089 $entries = getDirEntries( $source );
00090
00091
00092 if ( $entries == false )
00093 {
00094 return false;
00095 }
00096
00097 else
00098 {
00099
00100 foreach ( $entries as $entry )
00101 {
00102 if ( $entry )
00103 {
00104 $from = "$source/$entry";
00105 $to = "$destination/$entry";
00106
00107
00108 if ( is_dir( $from ) )
00109 {
00110 $status = copyDir( $from, $to );
00111 if (!$status)
00112 {
00113 return false;
00114 }
00115 }
00116
00117 else
00118 {
00119 $status = copy( $from, $to );
00120 if (!$status)
00121 {
00122 return false;
00123 }
00124 }
00125 }
00126 }
00127
00128 }
00129
00130
00131 return true;
00132 }
00133
00134
00135 function delDir( $dir )
00136 {
00137
00138 $currentDir = opendir( $dir );
00139
00140
00141 if ( $currentDir == false )
00142 {
00143 return false;
00144 }
00145
00146 else
00147 {
00148
00149 while ( false !== ( $entry = readdir( $currentDir ) ) )
00150 {
00151
00152 if ( is_dir( "$dir/$entry" ) and
00153 ( $entry != "." and $entry!="..") )
00154 {
00155
00156 $status = deldir( "${dir}/${entry}" );
00157
00158
00159 if ( !$status )
00160 {
00161 return false;
00162 }
00163 }
00164
00165 elseif ( $entry != "." and $entry != ".." )
00166 {
00167
00168 $status = unlink( "${dir}/${entry}" );
00169
00170
00171 if ( !$status )
00172 {
00173 return false;
00174 }
00175 }
00176 }
00177 }
00178
00179
00180 closedir( $currentDir );
00181
00182
00183
00184 $status = rmdir( ${dir} );
00185
00186 return $status;
00187 }
00188
00189
00190
00191
00192
00193 function getFileInfo( $dir, $file )
00194 {
00195 append_to_log( "inside getFileInfo, dir: $dir, file: $file");
00196 $realPath = $dir.'/'.$file;
00197 $fileInfo = array();
00198
00199 $fileInfo["name"] = $file;
00200
00201
00202 if ( is_dir( $realPath ) )
00203 {
00204 $fileInfo["size"] = 0;
00205 $fileInfo["mimetype"] = "httpd/unix-directory";
00206
00207
00208 $fileInfo["ctime"] = filectime( $realPath.'/.' );
00209 $fileInfo["mtime"] = filemtime( $realPath.'/.' );
00210
00211 }
00212
00213 else
00214 {
00215
00216 $fileInfo["ctime"] = filectime( $realPath );
00217 $fileInfo["mtime"] = filemtime( $realPath );
00218
00219
00220 $fileInfo["size"] = filesize( $realPath );
00221
00222
00223 if ( is_readable( $realPath ) )
00224 {
00225
00226 $mimeInfo = eZMimeType::findByURL( $dir . '/' . $file );
00227 $fileInfo['mimetype'] = $mimeInfo['name'];
00228 }
00229
00230 else
00231 {
00232 $fileInfo["mimetype"] = "application/x-non-readable";
00233 }
00234 }
00235
00236
00237 return $fileInfo;
00238 }
00239
00240
00241 class eZWebDAVFileServer extends eZWebDAVServer
00242 {
00243 function eZWebDAVFileServer()
00244 {
00245 $this->eZWebDAVServer();
00246 }
00247
00248
00249
00250
00251
00252 function head( $target )
00253 {
00254
00255 $realPath = $_SERVER["DOCUMENT_ROOT"].$target;
00256
00257 append_to_log( "HEAD: realPath is $realPath");
00258
00259
00260 if ( file_exists( $realPath ) )
00261 {
00262 return EZ_WEBDAV_OK_CREATED;
00263 }
00264 else
00265 {
00266 return EZ_WEBDAV_FAILED_NOT_FOUND;
00267 }
00268 }
00269
00270
00271
00272
00273
00274 function put( $target, $tempFile )
00275 {
00276
00277 $realPath = $_SERVER["DOCUMENT_ROOT"].$target;
00278
00279 append_to_log( "PUT: realPath is $realPath" );
00280 append_to_log( "PUT: tempfile is $tempFile" );
00281
00282
00283 include_once( 'lib/ezfile/classes/ezfile.php' );
00284 eZFile::rename( $tempFile, $realPath );
00285
00286
00287 if ( $status )
00288 {
00289 append_to_log( "move of tempfile was OK" );
00290 return EZ_WEBDAV_OK_CREATED;
00291 }
00292 else
00293 {
00294 append_to_log( "move of tempfile FAILED" );
00295 return EZ_WEBDAV_FAILED_FORBIDDEN;
00296 }
00297 }
00298
00299
00300
00301
00302
00303 function get( $target )
00304 {
00305 $result = array();
00306 $result["data"] = false;
00307 $result["file"] = false;
00308
00309
00310 $result["file"] = $_SERVER["DOCUMENT_ROOT"] . $target;
00311
00312 append_to_log( "GET: file is ".$result["file"]);
00313
00314 return $result;
00315 }
00316
00317
00318
00319
00320
00321 function mkcol( $target )
00322 {
00323
00324 $realPath = $_SERVER["DOCUMENT_ROOT"].$target;
00325
00326 append_to_log( "attempting to create dir: $realPath" );
00327
00328
00329 if ( !file_exists( $realPath ) )
00330 {
00331
00332 $status = mkdir( $realPath );
00333
00334
00335 if ( $status )
00336 {
00337
00338 return EZ_WEBDAV_OK_CREATED;
00339 }
00340 else
00341 {
00342
00343 return EZ_WEBDAV_FAILED_FORBIDDEN;
00344 }
00345 }
00346
00347 else
00348 {
00349 return EZ_WEBDAV_FAILED_EXISTS;
00350 }
00351 }
00352
00353
00354
00355
00356
00357 function delete( $target )
00358 {
00359
00360 $realPath = $_SERVER["DOCUMENT_ROOT"] . $target;
00361
00362 append_to_log( "attempting to DELETE: $realPath" );
00363
00364
00365 if ( file_exists( $realPath ) )
00366 {
00367 append_to_log( "File/dir exists..." );
00368
00369 if ( is_dir( $realPath ) )
00370 {
00371
00372 $status = delDir( $realPath );
00373 }
00374 else
00375 {
00376 append_to_log( "File is a file..." );
00377
00378
00379 $status = unlink( $realPath );
00380 }
00381
00382
00383 if ( $status )
00384 {
00385 append_to_log( "delete was OK" );
00386 return EZ_WEBDAV_OK;
00387 }
00388 else
00389 {
00390 append_to_log( "delete FAILED" );
00391 return EZ_WEBDAV_FAILED_FORBIDDEN;
00392 }
00393 }
00394 else
00395 {
00396 return EZ_WEBDAV_FAILED_NOT_FOUND;
00397 }
00398 }
00399
00400
00401
00402
00403
00404 function move( $source, $destination )
00405 {
00406 append_to_log( "Source: $source Destination: $destination" );
00407
00408
00409 $realSource = $_SERVER["DOCUMENT_ROOT"] . $source;
00410 $realDestination = $_SERVER["DOCUMENT_ROOT"] . $destination;
00411
00412 append_to_log( "RealSource: $realSource RealDestination: $realDestination" );
00413 include_once( 'lib/ezfile/classes/ezfile.php' );
00414 $status = eZFile::rename( $realSource, $realDestination );
00415
00416 if ( $status )
00417 {
00418 append_to_log( "move was OK" );
00419 return EZ_WEBDAV_OK_CREATED;
00420 }
00421 else
00422 {
00423 append_to_log( "move FAILED" );
00424 return EZ_WEBDAV_FAILED_CONFLICT;
00425 }
00426 }
00427
00428
00429
00430
00431
00432 function copy( $source, $destination )
00433 {
00434 append_to_log( "Source: $source Destination: $destination" );
00435 ob_start(); var_dump( $_SERVER ); $m = ob_get_contents(); ob_end_clean(); append_to_log( $m );
00436
00437
00438 $realSource = $_SERVER["DOCUMENT_ROOT"] . $source;
00439 $realDestination = $_SERVER["DOCUMENT_ROOT"] . $destination;
00440
00441 append_to_log( "RealSource: $realSource RealDestination: $realDestination" );
00442 $status = copyDir( $realSource, $realDestination );
00443
00444 if ( $status )
00445 {
00446 append_to_log( "copy was OK" );
00447 return EZ_WEBDAV_OK_CREATED;
00448 }
00449 else
00450 {
00451 append_to_log( "copy FAILED" );
00452 return EZ_WEBDAV_FAILED_CONFLICT;
00453 }
00454 }
00455
00456
00457
00458
00459
00460 function getCollectionContent( $dir )
00461 {
00462 $directory = dirname( $_SERVER["PATH_TRANSLATED"] ) . $dir;
00463
00464 $files = array();
00465
00466 append_to_log( "inside getDirectoryContent, dir: $directory" );
00467 $handle = opendir( $directory );
00468
00469
00470 while ( false !== ( $filename = readdir( $handle ) ) )
00471 {
00472
00473 if ( $filename == '.' or $filename == '..' )
00474 continue;
00475 $files[] = getFileInfo( $directory, $filename );
00476 append_to_log( "inside getDirectoryContent, dir: $directory, fil: $filename" );
00477 }
00478 return $files;
00479 }
00480 }
00481 ?>