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/ezxml/classes/ezxml.php' );
00046 include_once( "lib/ezutils/classes/ezmimetype.php" );
00047 include_once( 'lib/ezfile/classes/ezdir.php' );
00048
00049
00050 define( "EZ_WEBDAV_OK", 10 );
00051 define( "EZ_WEBDAV_OK_SILENT", 11 );
00052 define( "EZ_WEBDAV_OK_CREATED", 12 );
00053 define( "EZ_WEBDAV_OK_OVERWRITE", 13 );
00054
00055
00056 define( "EZ_WEBDAV_FAILED_FORBIDDEN", 30 );
00057 define( "EZ_WEBDAV_FAILED_NOT_FOUND", 31 );
00058 define( "EZ_WEBDAV_FAILED_EXISTS", 32 );
00059 define( "EZ_WEBDAV_FAILED_CONFLICT", 33 );
00060 define( "EZ_WEBDAV_FAILED_PRECONDITION", 34 );
00061 define( "EZ_WEBDAV_FAILED_LOCKED", 35 );
00062 define( "EZ_WEBDAV_FAILED_BAD_GATEWAY", 36 );
00063 define( "EZ_WEBDAV_FAILED_STORAGE_FULL", 37 );
00064 define( "EZ_WEBDAV_FAILED_UNSUPPORTED", 38 );
00065
00066
00067
00068
00069 define( "EZ_WEBDAV_CTIME_FORMAT", "Y-m-d\\TH:i:s\\Z" );
00070 define( "EZ_WEBDAV_MTIME_FORMAT", "D, d M Y H:i:s" );
00071
00072
00073
00074 $varDir = eZSys::varDirectory();
00075
00076
00077
00078 define( "EZ_WEBDAV_TEMP_DIRECTORY", $varDir . "/webdav/tmp" );
00079 define( "EZ_WEBDAV_ROOT_DIRECTORY", $varDir . "/webdav/root" );
00080 define( "EZ_WEBDAV_TEMP_FILE_PREFIX", "eZWebDAVUpload_" );
00081
00082
00083
00084 if ( !file_exists( EZ_WEBDAV_TEMP_DIRECTORY ) )
00085 {
00086 eZDir::mkdir( EZ_WEBDAV_TEMP_DIRECTORY, eZDir::directoryPermission(), true);
00087 }
00088
00089
00090 if ( !file_exists( EZ_WEBDAV_ROOT_DIRECTORY ) )
00091 {
00092 eZDir::mkdir( EZ_WEBDAV_ROOT_DIRECTORY, eZDir::directoryPermission(), true);
00093 }
00094
00095
00096
00097
00098
00099
00100 function eZWebDavCheckLogSetting()
00101 {
00102 return eZWebDAVServer::isLoggingEnabled();
00103 }
00104
00105
00106
00107
00108
00109
00110 function append_to_log( $logString )
00111 {
00112 return eZWebDAVServer::appendLogEntry( $logString );
00113 }
00114
00115
00116
00117
00118
00119
00120 function eZWebDavAppendToLog( $logString )
00121 {
00122 return eZWebDAVServer::appendLogEntry( $logString );
00123 }
00124
00125 class eZWebDAVServer
00126 {
00127
00128
00129
00130 function eZWebDAVServer()
00131 {
00132 $this->setupXMLOutputCharset();
00133 }
00134
00135 function setServerRoot( $rootDir )
00136 {
00137 if ( file_exists ( $rootDir ) )
00138 {
00139 $this->ServerRootDir = $rootDir;
00140
00141 return true;
00142 }
00143 else
00144 {
00145 return false;
00146 }
00147 }
00148
00149
00150
00151
00152
00153
00154 function processClientRequest()
00155 {
00156 $this->appendLogEntry( "WebDAV server started...", 'processClientRequest' );
00157 $this->XMLBodyRead = false;
00158
00159
00160 $this->headers();
00161
00162
00163 clearstatcache();
00164
00165
00166 $target = urldecode( $_SERVER["REQUEST_URI"] );
00167 $target = $this->processURL( $target );
00168
00169 $this->appendLogEntry( "----------------------------------------" );
00170 $this->appendLogEntry( "Client says: " . $_SERVER["REQUEST_METHOD"], 'processClientRequest' );
00171 $this->appendLogEntry( "Target: " . $_SERVER["REQUEST_URI"], 'processClientRequest' );
00172 $this->appendLogEntry( "----------------------------------------" );
00173
00174 $status = EZ_WEBDAV_FAILED_NOT_FOUND;
00175
00176 switch ( $_SERVER["REQUEST_METHOD"] )
00177 {
00178
00179 case "OPTIONS":
00180 {
00181 $this->appendLogEntry( "OPTIONS was issued from client.", 'processClientRequest' );
00182 $options = $this->options( $target );
00183 $status = $this->outputOptions( $options );
00184 } break;
00185
00186
00187 case "PROPFIND":
00188 {
00189 $this->appendLogEntry( "PROPFIND was issued from client.", 'processClientRequest' );
00190
00191 $depth = $_SERVER['HTTP_DEPTH'];
00192 if ( $depth != 0 and $depth != 1 and $depth != "infinity" )
00193 $depth = "infinity";
00194 $this->appendLogEntry( "Depth: $depth.", 'processClientRequest' );
00195
00196
00197
00198 $xml = new eZXML();
00199 $bodyTree = $xml->domTree( $this->xmlBody() );
00200 $requestedProperties = array();
00201 if ( $bodyTree )
00202 {
00203 $propfindNode =& $bodyTree->root();
00204 $propNode =& $propfindNode->elementByName( 'prop' );
00205 if ( $propNode )
00206 {
00207 $propList = $propNode->children();
00208 foreach ( $propList as $node )
00209 {
00210 $name = $node->name();
00211 $requestedProperties[] = $name;
00212 }
00213 }
00214 else
00215 {
00216 $allpropNode =& $propfindNode->elementByName( 'allprop' );
00217 if ( $allpropNode )
00218 {
00219
00220 $requestedProperties = true;
00221 }
00222 else
00223 {
00224 $propnameNode =& $propfindNode->elementByName( 'propname' );
00225 if ( $propnameNode )
00226 {
00227
00228 $requestedProperties = false;
00229 }
00230 }
00231 }
00232 }
00233
00234 $collection = $this->getCollectionContent( $target, $depth, $requestedProperties );
00235 if ( is_array( $collection ) )
00236 {
00237 $status = $this->outputCollectionContent( $collection, $requestedProperties );
00238 }
00239 else
00240 {
00241 $status = $collection;
00242 }
00243 } break;
00244
00245
00246 case "HEAD":
00247 {
00248 $this->appendLogEntry( "HEAD was issued from client.", 'processClientRequest' );
00249 $data = $this->get( $target );
00250 $status = $this->outputSendDataToClient( $data, true );
00251 } break;
00252
00253
00254 case "GET":
00255 {
00256 $this->appendLogEntry( "GET was issued from client.", 'processClientRequest' );
00257 $data = $this->get( $target );
00258 $status = $this->outputSendDataToClient( $data );
00259 } break;
00260
00261
00262 case "PUT":
00263 {
00264 $this->appendLogEntry( "PUT was issued from client.", 'processClientRequest' );
00265 $status = EZ_WEBDAV_OK_CREATED;
00266
00267
00268 $tempFile = $this->storeUploadedFile( $target );
00269
00270
00271 if ( $tempFile )
00272 {
00273
00274 $status = $this->put( $target, $tempFile );
00275
00276 unlink( $tempFile );
00277 include_once( 'lib/ezfile/classes/ezdir.php' );
00278 eZDir::cleanupEmptyDirectories( dirname( $tempFile ) );
00279 }
00280
00281 else
00282 {
00283 $status = EZ_WEBDAV_FAILED_FORBIDDEN;
00284 }
00285
00286 } break;
00287
00288
00289 case "MKCOL":
00290 {
00291 $this->appendLogEntry( "MKCOL was issued from client.", 'processClientRequest' );
00292 if ( strlen( $this->xmlBody() ) > 0 )
00293 {
00294 $this->appendLogEntry( "MKCOL body error.", 'processClientRequest' );
00295 $status = EZ_WEBDAV_FAILED_FORBIDDEN;
00296 }
00297 else
00298 {
00299 $status = $this->mkcol( $target );
00300 }
00301 } break;
00302
00303
00304 case "COPY":
00305 {
00306 $this->appendLogEntry( "COPY was issued from client.", 'processClientRequest' );
00307
00308 $source = $target;
00309 $url = parse_url( $_SERVER["HTTP_DESTINATION"] );
00310 $destination = urldecode( $url["path"] );
00311 $destination = $this->processURL( $destination );
00312 $status = $this->copy( $source, $destination );
00313 } break;
00314
00315
00316 case "MOVE":
00317 {
00318 $this->appendLogEntry( "MOVE was issued from client.", 'processClientRequest' );
00319 $source = $target;
00320 $url = parse_url( $_SERVER["HTTP_DESTINATION"] );
00321 $destination = urldecode( $url["path"] );
00322 $destination = $this->processURL( $destination );
00323 $status = $this->move( $source, $destination );
00324 } break;
00325
00326
00327 case "DELETE":
00328 {
00329 $this->appendLogEntry( "DELETE was issued from client.", 'processClientRequest' );
00330 $status = $this->delete( $target );
00331 } break;
00332
00333
00334 default:
00335 {
00336
00337 } break;
00338 }
00339
00340
00341 if ( !$this->XMLBodyRead )
00342 $this->flushXMLBody();
00343
00344
00345 $this->handle( $status );
00346 }
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358 function outputOptions( $options )
00359 {
00360
00361 $methods = array( 'OPTIONS', 'GET', 'HEAD', 'POST', 'DELETE', 'TRACE', 'PROPFIND', 'PROPPATCH', 'COPY', 'MOVE', 'LOCK', 'UNLOCK' );
00362 $versions = array( '1', '2', '<http://apache.org/dav/propset/fs/1>' );
00363
00364 if ( isset( $options['methods'] ) )
00365 $methods = $options['methods'];
00366 if ( isset( $options['versions'] ) )
00367 $versions = $options['versions'];
00368
00369 header( 'Content-Length: 0' );
00370 header( 'MS-Author-Via: DAV' );
00371 header( 'Allow: ' . implode( ', ', $methods ) );
00372 header( 'DAV: ' . implode( ',', $versions ) );
00373 header( 'Content-Type: text/plain; charset=iso-8859-1' );
00374
00375 return EZ_WEBDAV_OK_SILENT;
00376 }
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391 function outputCollectionContent( $collection, $requestedProperties )
00392 {
00393
00394
00395
00396 if( !is_array( $requestedProperties ) || count( $requestedProperties ) == 0 )
00397 {
00398 $requestedProperties = array( 'displayname',
00399 'creationdate',
00400 'getlastmodified',
00401 'getcontenttype',
00402 'getcontentlength',
00403 'resourcetype' );
00404 }
00405
00406
00407
00408
00409 if( !in_array( 'getcontenttype', $requestedProperties ) )
00410 {
00411 $requestedProperties[] = 'getcontenttype';
00412 }
00413
00414 $this->appendLogEntry( 'Client requested ' .
00415 count( $requestedProperties ) .
00416 ' properties.', 'outputCollectionContent' );
00417
00418 $dataCharset = eZWebDAVServer::dataCharset();
00419 $xmlCharset = $this->XMLOutputCharset();
00420
00421 $xmlText = "<?xml version=\"1.0\" encoding=\"$xmlCharset\"?>\n" .
00422 "<D:multistatus xmlns:D=\"DAV:\">\n";
00423
00424
00425 $nameMap = array( 'displayname' => 'name',
00426 'creationdate' => 'ctime',
00427 'getlastmodified' => 'mtime',
00428 'getcontenttype' => 'mimetype',
00429 'getcontentlength' => 'size' );
00430
00431 foreach ( $requestedProperties as $requestedProperty )
00432 {
00433 if ( !isset( $nameMap[$requestedProperty] ) )
00434 $nameMap[$requestedProperty] = $requestedProperty;
00435 }
00436
00437
00438
00439
00440
00441
00442
00443 foreach ( $collection as $entry )
00444 {
00445
00446 $creationTime = date( EZ_WEBDAV_CTIME_FORMAT, $entry['ctime'] );
00447 $modificationTime = date( EZ_WEBDAV_MTIME_FORMAT, $entry['mtime'] );
00448
00449
00450
00451 $href = $entry['href'];
00452 $pathArray = split( '/', eZWebDAVServer::recode( "$href", $dataCharset, $xmlCharset ) );
00453
00454 $encodedPath = '/';
00455
00456 foreach( $pathArray as $pathElement )
00457 {
00458 if( $pathElement != '' )
00459 {
00460 $encodedPath .= rawurlencode( $pathElement );
00461 $encodedPath .= '/';
00462 }
00463 }
00464
00465 $isCollection = $entry['mimetype'] == 'httpd/unix-directory';
00466
00467
00468
00469 if ( !$isCollection )
00470 $encodedPath = rtrim($encodedPath, '/');
00471
00472 $xmlText .= "<D:response>\n" .
00473 " <D:href>" . $encodedPath ."</D:href>\n" .
00474 " <D:propstat>\n" .
00475 " <D:prop>\n";
00476
00477 $unknownProperties = array();
00478
00479 foreach ( $requestedProperties as $requestedProperty )
00480 {
00481 $name = $nameMap[$requestedProperty];
00482 if ( isset( $entry[$name] ) )
00483 {
00484 if ( $requestedProperty == 'creationdate' )
00485 {
00486 $creationTime = date( EZ_WEBDAV_CTIME_FORMAT, $entry['ctime'] );
00487 $xmlText .= " <D:" . $requestedProperty . ">" . $creationTime . "</D:" . $requestedProperty . ">\n";
00488 }
00489 else if ( $requestedProperty == 'getlastmodified' )
00490 {
00491 $modificationTime = date( EZ_WEBDAV_MTIME_FORMAT, $entry['mtime'] );
00492 $xmlText .= " <D:" . $requestedProperty . ">" . $modificationTime . "</D:" . $requestedProperty . ">\n";
00493 }
00494 else if ( $isCollection and $requestedProperty == 'getcontenttype' )
00495 {
00496
00497 $xmlText .= ( " <D:resourcetype>\n" .
00498 " <D:collection />\n" .
00499 " </D:resourcetype>\n" );
00500
00501 $unknownProperties[] = $requestedProperty;
00502 }
00503 else
00504 {
00505 $xmlText .= " <D:" . $requestedProperty . ">" . htmlspecialchars( eZWebDAVServer::recode( "$entry[$name]", $dataCharset, $xmlCharset ) ) . "</D:" . $requestedProperty . ">\n";
00506 }
00507 }
00508 else if ( $requestedProperty != 'resourcetype' or !$isCollection )
00509 {
00510 $unknownProperties[] = $requestedProperty;
00511 }
00512 }
00513
00514 $xmlText .= ( " <D:lockdiscovery/>\n" );
00515
00516 $xmlText .= ( " </D:prop>\n" .
00517 " <D:status>HTTP/1.1 200 OK</D:status>\n" .
00518 " </D:propstat>\n" );
00519
00520
00521
00522
00523
00524
00525 $xmlText .= " <D:propstat>\n";
00526 $xmlText .= " <D:prop>\n";
00527 foreach ( $unknownProperties as $unknownProperty )
00528 {
00529 $xmlText .= " <D:" . $unknownProperty . " />\n";
00530 }
00531 $xmlText .= " </D:prop>\n";
00532 $xmlText .= " <D:status>HTTP/1.1 404 Not Found</D:status>\n";
00533 $xmlText .= " </D:propstat>\n";
00534
00535 $xmlText .= "</D:response>\n";
00536 }
00537
00538 $xmlText .= "</D:multistatus>\n";
00539
00540 header( 'HTTP/1.1 207 Multi-Status' );
00541 header( 'Content-Type: text/xml' );
00542
00543
00544
00545
00546
00547 $text = @ob_get_contents();
00548 if ( strlen( $text ) != 0 )
00549 $this->appendLogEntry( $text, "DAV: PHP Output" );
00550 while ( @ob_end_clean() );
00551
00552
00553
00554
00555
00556 print( $xmlText );
00557
00558 $xml = new eZXML();
00559 $domTree = $xml->domTree( $xmlText );
00560 if ( $domTree )
00561 $this->appendLogEntry( "XML was parsed", 'outputCollectionContent' );
00562 else
00563 $this->appendLogEntry( "XML was NOT parsed $xmlText", 'outputCollectionContent' );
00564
00565
00566 return EZ_WEBDAV_OK_SILENT;
00567 }
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577 function outputSendDataToClient( $output, $headers_only = false )
00578 {
00579 if ( !$output )
00580 {
00581 $this->appendLogEntry( "outputData: no data available", 'outputSendDataToClient' );
00582 return EZ_WEBDAV_FAILED_NOT_FOUND;
00583 }
00584
00585
00586 if ( $output["data"] )
00587 {
00588 $this->appendLogEntry( "outputData: DATA is a string...", 'outputSendDataToClient' );
00589 }
00590
00591 elseif ( $output["file"] )
00592 {
00593 $this->appendLogEntry( "outputData: DATA is a file...", 'outputSendDataToClient' );
00594 $realPath = $output["file"];
00595
00596
00597 if ( ( file_exists( $realPath ) ) && ( is_readable( $realPath ) ) )
00598 {
00599 $this->appendLogEntry( "outputData: file exists on server...", 'outputSendDataToClient' );
00600
00601
00602 $eTag = md5_file( $realPath );
00603 $size = filesize( $realPath );
00604
00605 $dir = dirname( $realPath );
00606 $file = basename( $realPath );
00607
00608 $mimeInfo = eZMimeType::findByURL( $dir . '/' . $file );
00609 $mimeType = $mimeInfo['name'];
00610
00611
00612 header( 'HTTP/1.1 200 OK' );
00613 header( 'Accept-Ranges: bytes' );
00614 header( 'Content-Length: '.$size );
00615 header( 'Content-Type: '.$mimeType );
00616 header( 'ETag: '.$eTag );
00617
00618 $text = @ob_get_contents();
00619 if ( strlen( $text ) != 0 )
00620 $this->appendLogEntry( $text, "DAV: PHP Output" );
00621 while ( @ob_end_clean() );
00622
00623 if ( !$headers_only )
00624 {
00625
00626 $fp = fopen( $realPath, "rb" );
00627
00628
00629 $status = fpassthru( $fp );
00630
00631
00632 if ( $status == $size)
00633 {
00634 return EZ_WEBDAV_OK_SILENT;
00635 }
00636 else
00637 {
00638 return EZ_WEBDAV_FAILED_FORBIDDEN;
00639 }
00640 }
00641 else
00642 {
00643 return EZ_WEBDAV_OK_SILENT;
00644 }
00645 }
00646
00647 else
00648 {
00649 $this->appendLogEntry( "outputData: file DOES NOT exists on server...", 'outputSendDataToClient' );
00650 return EZ_WEBDAV_FAILED_NOT_FOUND;
00651 }
00652 }
00653 else
00654 {
00655 $this->appendLogEntry( "outputData: No file specified", 'outputSendDataToClient' );
00656
00657 $text = @ob_get_contents();
00658 if ( strlen( $text ) != 0 )
00659 $this->appendLogEntry( $text, "DAV: PHP Output" );
00660 while ( @ob_end_clean() );
00661
00662 return EZ_WEBDAV_FAILED_NOT_FOUND;
00663 }
00664 }
00665
00666
00667
00668
00669
00670
00671
00672 function storeUploadedFile( $target )
00673 {
00674 $dir = EZ_WEBDAV_TEMP_DIRECTORY . '/' . md5( microtime() . '-' . $target );
00675 $filePath = $dir . '/' . basename( $target );
00676
00677 if ( !file_exists( $dir ) )
00678 {
00679 include_once( 'lib/ezfile/classes/ezdir.php' );
00680 eZDir::mkdir( $dir, false, true );
00681 }
00682
00683 $result = copy( "php://input", $filePath );
00684 if ( !$result )
00685 {
00686 $result = file_exists( $filePath );
00687 }
00688
00689 if ( $result )
00690 {
00691 header( "HTTP/1.1 201 Created" );
00692 return $filePath;
00693 }
00694 return false;
00695 }
00696
00697
00698
00699
00700 function xmlBody()
00701 {
00702 $xmlBody = file_get_contents( "php://input" );
00703
00704 $this->XMLBodyRead = true;
00705 return $xmlBody;
00706 }
00707
00708
00709
00710
00711 function flushXMLBody()
00712 {
00713
00714
00715 $xmlBody = file_get_contents( "php://input" );
00716 }
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726 function processURL( $url )
00727 {
00728 return $url;
00729 }
00730
00731
00732
00733
00734
00735
00736 function headers()
00737 {
00738 }
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749 function options( $target )
00750 {
00751 }
00752
00753
00754
00755
00756
00757
00758
00759
00760 function getCollectionContent( $collection, $depth, $properties )
00761 {
00762 }
00763
00764
00765
00766
00767
00768 function head( $target )
00769 {
00770 }
00771
00772
00773
00774
00775
00776
00777 function get( $target )
00778 {
00779 }
00780
00781
00782
00783
00784
00785
00786 function put( $target, $tempFile )
00787 {
00788 }
00789
00790
00791
00792
00793
00794
00795 function mkcol( $target )
00796 {
00797 }
00798
00799
00800
00801
00802
00803
00804 function copy( $source, $destination )
00805 {
00806 }
00807
00808
00809
00810
00811
00812
00813 function move( $source, $destination )
00814 {
00815 }
00816
00817
00818
00819
00820
00821
00822 function delete( $target )
00823 {
00824 }
00825
00826
00827
00828
00829
00830 function handle( $status )
00831 {
00832 $this->appendLogEntry( "handle function was called with status: $status", 'handle' );
00833
00834
00835 switch ( $status )
00836 {
00837
00838 case EZ_WEBDAV_OK:
00839 {
00840 header( "HTTP/1.1 200 OK" );
00841 } break;
00842
00843
00844 case EZ_WEBDAV_OK_SILENT:
00845 {
00846
00847 } break;
00848
00849
00850 case EZ_WEBDAV_OK_CREATED:
00851 {
00852 header( "HTTP/1.1 201 Created" );
00853 } break;
00854
00855
00856 case EZ_WEBDAV_OK_OVERWRITE:
00857 {
00858 header( "HTTP/1.1 204 No Content");
00859 } break;
00860
00861
00862 case EZ_WEBDAV_FAILED_FORBIDDEN:
00863 {
00864 header( "HTTP/1.1 403 Forbidden");
00865 } break;
00866
00867
00868 case EZ_WEBDAV_FAILED_NOT_FOUND:
00869 {
00870 header( "HTTP/1.1 404 Not Found" );
00871 } break;
00872
00873
00874 case EZ_WEBDAV_FAILED_EXISTS:
00875 {
00876 header( "HTTP/1.1 405 Method not allowed" );
00877 } break;
00878
00879
00880 case EZ_WEBDAV_FAILED_CONFLICT:
00881 {
00882 header( "HTTP/1.1 409 Conflict" );
00883 }break;
00884
00885
00886 case EZ_WEBDAV_FAILED_PRECONDITION:
00887 {
00888 header( "HTTP/1.1 412 Precondition Failed" );
00889 } break;
00890
00891
00892 case EZ_WEBDAV_FAILED_LOCKED:
00893 {
00894 header( "HTTP/1.1 423 Locked" );
00895 } break;
00896
00897
00898 case EZ_WEBDAV_FAILED_BAD_GATEWAY:
00899 {
00900 header( "HTTP/1.1 502 Bad Gateway" );
00901 } break;
00902
00903
00904 case EZ_WEBDAV_FAILED_STORAGE_FULL:
00905 {
00906 header( "HTTP/1.1 507 Insufficient Storage" );
00907 } break;
00908
00909
00910 case EZ_WEBDAV_FAILED_UNSUPPORTED:
00911 {
00912 header( "HTTP/1.1 415 Unsupported Media Type" );
00913 } break;
00914
00915
00916 default:
00917 {
00918 $this->appendLogEntry( "HTTP 500, THIS SHOULD NOT HAPPEN!", 'handle' );
00919 header( "HTTP/1.1 500 Internal Server Error" );
00920 } break;
00921 }
00922
00923 $text = @ob_get_contents();
00924 if ( strlen( $text ) != 0 )
00925 $this->appendLogEntry( $text, "DAV: PHP Output" );
00926 while ( @ob_end_clean() );
00927 }
00928
00929
00930
00931
00932
00933
00934 function appendLogEntry( $logString, $label = false )
00935 {
00936 if ( !eZWebDAVServer::isLoggingEnabled() )
00937 return false;
00938
00939 $varDir = eZSys::varDirectory();
00940
00941 $logDir = 'log';
00942 $logName = 'webdav.log';
00943 $fileName = $varDir . '/' . $logDir . '/' . $logName;
00944 if ( !file_exists( $varDir . '/' . $logDir ) )
00945 {
00946 include_once( 'lib/ezfile/classes/ezdir.php' );
00947 eZDir::mkdir( $varDir . '/' . $logDir, 0775, true );
00948 }
00949
00950 $logFile = fopen( $fileName, 'a' );
00951 $nowTime = date( "Y-m-d H:i:s : " );
00952 $text = $nowTime . $logString;
00953 if ( $label )
00954 $text .= ' [' . $label . ']';
00955 fwrite( $logFile, $text . "\n" );
00956 fclose( $logFile );
00957 }
00958
00959
00960
00961
00962
00963 function isLoggingEnabled()
00964 {
00965 $useLogging =& $GLOBALS['eZWebDavLogging'];
00966 if ( !isset( $useLogging ) )
00967 {
00968 $ini =& eZINI::instance( 'webdav.ini' );
00969 $useLogging = $ini->variable( 'GeneralSettings', 'Logging' ) == 'enabled';
00970 }
00971 return $useLogging;
00972 }
00973
00974
00975
00976
00977 function setupXMLOutputCharset()
00978 {
00979 $charset = eZWebDAVServer::dataCharset();
00980
00981 $userAgent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : false;
00982 $pattern = eZWebDAVServer::userAgentPattern();
00983 $userAgentSettings = eZWebDAVServer::userAgentSettings();
00984
00985 if ( preg_match( $pattern, $userAgent, $matches ) && isset( $userAgentSettings[$matches[0]] ) )
00986 {
00987 $agentSettings = $userAgentSettings[$matches[0]];
00988 if ( isset( $agentSettings['xmlCharset'] ) && $agentSettings['xmlCharset'] != '' )
00989 $charset = $agentSettings['xmlCharset'];
00990 }
00991
00992 $this->setXMLOutputCharset( $charset );
00993 }
00994
00995
00996
00997
00998 function setXMLOutputCharset( $charset )
00999 {
01000 if ( $charset == '' )
01001 {
01002 $this->appendLogEntry( "Error: unable to set empty charset for outputted xml.", 'setXMLOutputCharset' );
01003 return false;
01004 }
01005
01006 $this->XMLOutputCharset = $charset;
01007 return true;
01008 }
01009
01010
01011
01012
01013 function XMLOutputCharset()
01014 {
01015 return $this->XMLOutputCharset;
01016 }
01017
01018
01019
01020
01021
01022
01023 function dataCharset()
01024 {
01025 $ini =& eZINI::instance( 'i18n.ini' );
01026 $charset = $ini->variable('CharacterSettings', 'Charset' );
01027 return $charset;
01028 }
01029
01030
01031
01032
01033
01034 function userAgentPattern()
01035 {
01036 $pattern = '//';
01037
01038 $userAgentSettings = eZWebDAVServer::userAgentSettings();
01039 if( count( $userAgentSettings ) > 0 )
01040 {
01041 $pattern = '/';
01042
01043 foreach( $userAgentSettings as $agent => $settings )
01044 $pattern .= $agent . '|';
01045
01046 $pattern[strlen($pattern)-1] = '/';
01047 }
01048
01049 return $pattern;
01050 }
01051
01052
01053
01054
01055
01056 function userAgentSettings()
01057 {
01058 return array( 'WebDrive' => array( 'xmlCharset' => 'utf-8' ),
01059 'Microsoft Data Access Internet Publishing Provider' => array( 'xmlCharset' => 'utf-8' )
01060 );
01061 }
01062
01063
01064
01065
01066
01067 function recode( $string, $fromCharset, $toCharset, $stop = false )
01068 {
01069 include_once( 'lib/ezi18n/classes/eztextcodec.php' );
01070 $codec =& eZTextCodec::instance( $fromCharset, $toCharset, false );
01071 if ( $codec )
01072 $string = $codec->convertString( $string );
01073
01074 return $string;
01075 }
01076
01077
01078 var $ServerRootDir = "";
01079 var $XMLBodyRead = false;
01080 var $XMLOutputCharset = 'utf-8';
01081 }
01082 ?>