/** * Returns the XML representation of a live property. * * Returns a DOMElement, representing the content of the given $property. * The newly created element is also appended as a child to the given * $parentElement. * * This method only takes care for {@link ezcWebdavGetContentTypeProperty} * and does not add the "charset=..." part to the generated XML output, * since Nautilus does not display this nicely. All other properties are * dispatched to the default {@link ezcWebdavPropertyHandler}. * * @param ezcWebdavLiveProperty $property * @param DOMElement $parentElement * @return DOMElement */ protected function serializeLiveProperty(ezcWebdavLiveProperty $property, DOMElement $parentElement) { switch (get_class($property)) { case 'ezcWebdavGetContentTypeProperty': $elementName = 'getcontenttype'; $elementValue = $property->mime !== null ? $property->mime : null; break; default: return parent::serializeLiveProperty($property, $parentElement); } $propertyElement = $parentElement->appendChild(ezcWebdavServer::getInstance()->xmlTool->createDomElement($parentElement->ownerDocument, $elementName, $property->namespace)); if ($elementValue instanceof DOMDocument) { $propertyElement->appendChild($dom->importNode($elementValue->documentElement, true)); } else { if (is_array($elementValue)) { foreach ($elementValue as $subValue) { $propertyElement->appendChild($subValue); } } else { if (is_scalar($elementValue)) { $propertyElement->nodeValue = $elementValue; } } } return $propertyElement; }
/** * testAuthentication * * @param mixed $input * @param mixed $output * @return void * * @dataProvider provideTestData */ public function testAuthentication($input, $output) { static $num = 0; $num++; $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_BODY'] = $input['body']; $_SERVER = array_merge($this->serverBase, $input['server']); $backend = $this->getBackend(); ezcWebdavServer::getInstance()->handle($backend); if (isset($GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_HEADERS']['WWW-Authenticate'])) { // Replace nounce value with standard one, since this should not be predictable $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_HEADERS']['WWW-Authenticate']['digest'] = preg_replace('(nonce="[^"]+")', 'nonce="testnonce"', $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_HEADERS']['WWW-Authenticate']['digest']); } // Check for broken DateTime in PHP versions (timestamp time zone issue) if (version_compare(PHP_VERSION, '5.2.6', '<')) { if ($input['server']['REQUEST_METHOD'] === 'PROPFIND') { // PROPFIND responses contain dates in XML $this->markTestSkipped('PHP DateTime broken in versions < 5.2.6'); return; } if (isset($output['headers']['ETag'])) { unset($output['headers']['ETag']); unset($GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_HEADERS']['ETag']); } } $this->assertEquals($output['status'], $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_STATUS']); $this->assertEquals($output['headers'], $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_HEADERS']); $this->assertEquals($output['body'], $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_BODY']); }
public function tearDown() { $server = ezcWebdavServer::getInstance(); $server->auth = null; $server->pluginRegistry->unregisterPlugin(new ezcWebdavLockPluginConfiguration()); $this->backend = null; $this->removeTempDir(); }
protected function performTestSetRun(array $request) { ezcWebdavTestTransportInjector::reset(); ezcWebdavTestTransportInjector::$requestBody = $request['body']; $_SERVER = $request['server']; // ini_set( 'xdebug.collect_return', 1 ); // xdebug_start_trace( './traces/' . basename( $testSetName ) ); $this->server->handle($this->backend); // xdebug_stop_trace(); $response['status'] = ezcWebdavTestTransportInjector::$responseStatus; $response['headers'] = ezcWebdavTestTransportInjector::$responseHeaders; $response['body'] = ezcWebdavTestTransportInjector::$responseBody; return $response; }
protected function getServer(ezcWebdavPathFactory $pathFactory) { $server = ezcWebdavServer::getInstance(); $server->reset(); foreach ($server->configurations as $id => $cfg) { // Prepare mock classes, if not done, yet if (!class_exists($mockClass = "{$cfg->transportClass}Mock")) { eval(sprintf($this->mockClassSource, $cfg->transportClass, $cfg->transportClass)); } // Mock all transports $server->configurations[$id]->transportClass = "{$cfg->transportClass}Mock"; $server->configurations[$id]->pathFactory = $pathFactory; } $server->auth = new ezcWebdavTestAuth(); return $server; }
protected function performTestSetRun(array $request) { $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_BODY'] = $request['body']; $_SERVER = $request['server']; // ini_set( 'xdebug.collect_return', 1 ); // xdebug_start_trace( './traces/' . basename( $testSetName ) ); $this->server->handle($this->backend); // xdebug_stop_trace(); $response['body'] = $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_BODY']; $response['headers'] = $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_HEADERS']; $response['status'] = $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_STATUS']; // Reset globals unset($GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_BODY']); unset($GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_BODY']); unset($GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_HEADERS']); unset($GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_STATUS']); return $response; }
/** * Handles responses generated by the backend. * * @param ezcWebdavPluginParameters $params * @return ezcWebdavResponse|null */ public function generatedResponse(ezcWebdavPluginParameters $params) { if (isset($this->handler)) { $res = null; try { $res = $this->handler->generatedResponse($params['response']); } catch (Exception $e) { if ($this->handler->needsBackendLock) { ezcWebdavServer::getInstance()->backend->unlock(); } throw $e; } if ($this->handler->needsBackendLock) { ezcWebdavServer::getInstance()->backend->unlock(); } return $res; } }
/** * Initialize the plugin. * * This method is called after the server has be initialized to make the * plugin setup necessary objects and to retreive necessary information * from the server. * * @return void */ public function init() { $srv = ezcWebdavServer::getInstance(); if (!$srv->backend instanceof ezcWebdavLockBackend) { throw new ezcWebdavPluginPreconditionFailedException($this->getNamespace(), 'Backend does not implement ezcWebdavLockBackend.'); } if (!is_object($srv->auth) || !$srv->auth instanceof ezcWebdavLockAuthorizer) { throw new ezcWebdavPluginPreconditionFailedException($this->getNamespace(), 'No authorizer available or authorizer does not implement ezcWebdavLockAuthorizer.'); } // @TODO: Check if more sanity checks must be tested? }
protected function assertSetPropertyFailure($propertyName, array $propertyValues, $exceptionClass) { foreach ($propertyValues as $value) { try { $srv = ezcWebdavServer::getInstance(); $srv->{$propertyName} = $value; $this->fail("Exception not thrown on invalid ___set() value for property '{$propertyName}'."); } catch (Exception $e) { $this->assertTrue($e instanceof $exceptionClass, "Exception thrown on invalid value set for property '{$propertyName}'. '" . get_class($e) . "' instead of '{$exceptionClass}'."); } } }
public function move(ezcWebdavMoveRequest $request) { global $prefs; global $filegallib; include_once 'lib/filegals/filegallib.php'; print_debug("-- HTTP method: MOVE --\n"); $this->acquireLock(); // Indicates wheather a destiantion resource has been replaced or not. // The success response code depends on this. $replaced = false; // Extract paths from request $source = $request->requestUri; $dest = $request->getHeader('Destination'); // Check authorization // Need to do this before checking of node existence is checked, to // avoid leaking information if (!ezcWebdavServer::getInstance()->isAuthorized($dest, $request->getHeader('Authorization'), ezcWebdavAuthorizer::ACCESS_WRITE)) { $this->freeLock(); return $this->createUnauthorizedResponse($dest, $request->getHeader('Authorization')); } // Check if resource is available if (!$this->nodeExists($source)) { $this->freeLock(); return new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_404, $source); } // If source and destination are equal, the request should always fail. if ($source === $dest) { $this->freeLock(); return new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_403, $source); } // Check if destination resource exists and throw error, when // overwrite header is F if ($request->getHeader('Overwrite') === 'F' && $this->nodeExists($dest)) { $this->freeLock(); return new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_412, $dest); } // Check if the destination parent directory already exists, otherwise // bail out. if (!$this->nodeExists($destDir = dirname($dest))) { $this->freeLock(); return new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_409, $dest); } // Verify If-[None-]Match headers on the $dest if it exists if ($this->nodeExists($dest) && ($res = $this->checkIfMatchHeaders($request, $dest)) !== null) { $this->freeLock(); return $res; } elseif (($res = $this->checkIfMatchHeaders($request, $destDir)) !== null) { // Verify If-[None-]Match headers on the on $dests parent dir, if it // does not exist $this->freeLock(); return $res; } // The destination resource should be deleted if it exists and the // overwrite headers is T if ($request->getHeader('Overwrite') === 'T' && $this->nodeExists($dest)) { // Check sub-sequent authorization on destination $authState = $this->recursiveAuthCheck($request, $dest, ezcWebdavAuthorizer::ACCESS_WRITE, true); if (count($authState['errors']) !== 0) { // Permission denied on deleting destination $this->freeLock(); return $authState['errors'][0]; } $replaced = true; if (count($delteErrors = $this->performDelete($dest)) > 0) { $this->freeLock(); return new ezcWebdavMultistatusResponse($delteErrors); } } // All checks are passed, we can actually move now. $infos = array(); $doRename = false; $doMove = false; foreach (array('source', 'dest') as $k) { // Get source and dest infos if (($infos[$k] = $filegallib->get_objectid_from_virtual_path(${$k})) !== false) { switch ($infos[$k]['type']) { case 'filegal': $infos[$k]['infos'] = $filegallib->get_file_gallery_info($infos[$k]['id']); $infos[$k]['parentId'] = $infos[$k]['infos']['parentId']; $infos[$k]['name'] = $infos[$k]['infos']['name']; break; case 'file': ///TODO: Throw an error if dest is a file, but source is a filegal $infos[$k]['infos'] = $filegallib->get_file($infos[$k]['id']); $infos[$k]['parentId'] = $infos[$k]['infos']['galleryId']; $infos[$k]['name'] = $infos[$k]['infos']['filename']; break; } } elseif ($k == 'dest') { // If dest doesn't exist, it usually means that the file / filegal has to be renamed ///TODO: Throw an error if dest is a new filegal, but source is a file if (($objectId = $filegallib->get_objectid_from_virtual_path(dirname(${$k}))) !== false && $objectId['type'] == 'filegal') { $infos[$k] = array('id' => $infos['source']['id'], 'type' => $infos['source']['type'], 'infos' => $infos['source']['infos'], 'parentId' => $objectId['id'], 'name' => basename(${$k})); switch ($infos[$k]['type']) { case 'filegal': $infos[$k]['infos']['name'] = $infos[$k]['name']; $infos[$k]['infos']['parentId'] = $infos[$k]['parentId']; break; case 'file': $infos[$k]['infos']['name'] = $infos[$k]['name']; $infos[$k]['infos']['filename'] = $infos[$k]['name']; $infos[$k]['infos']['galleryId'] = $infos[$k]['parentId']; break; } $doRename = true; } } else { // If source doesn't exist, we stop here break; } } $doMove = $infos['source']['parentId'] != $infos['dest']['parentId']; $noErrors = true; switch ($infos['source']['type']) { case 'filegal': if ($doRename) { $noErrors = (bool) $filegallib->replace_file_gallery($infos['dest']['infos']); } elseif ($doMove) { // Move is not needed if the rename occurred, since filegal renaming function handle the move already $noErrors = (bool) $filegallib->move_file_gallery($infos['source']['id'], $infos['dest']['parentId']); } break; case 'file': if ($doRename) { if ($prefs['fgal_use_db'] === 'n') { $newPath = md5($infos['dest']['name']); do { $newPath = md5(uniqid($newPath)); } while (file_exists($this->root . '/' . $newPath)); if (@rename($this->root . '/' . $infos['source']['infos']['path'], $this->root . '/' . $newPath) === false || @file_put_contents($this->root . '/' . $infos['source']['infos']['path'], '') === false) { $this->freeLock(); return false; } } else { $newPath = ''; } global $user; $noErrors = (bool) $filegallib->replace_file($infos['source']['id'], $infos['dest']['name'], $infos['source']['infos']['description'], $infos['dest']['name'], $infos['source']['infos']['data'], $infos['source']['infos']['filesize'], $infos['source']['infos']['filetype'], $user, $newPath, '', $filegallib->get_file_gallery_info($infos['source']['parentId']), false, $infos['source']['infos']['author'], $infos['source']['infos']['created'], $infos['source']['infos']['lockedby']); } if ($doMove && $noErrors) { $noErrors = (bool) $filegallib->set_file_gallery($infos['source']['id'], $infos['dest']['parentId']); } break; } $this->freeLock(); // Send proper response on success if ($noErrors) { $return = new ezcWebdavMoveResponse($replaced); } else { $return = new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_500); } print_debug("-- HTTP method: MOVE end --\n"); return $return; }
/** * Initialializes the WebDAV server used for capturing. * * Retrieves the global server singleton and replaces all configured * transports with their corresponding mock. * * @param ezcWebdavPathFactory $pathFactory * @return void */ protected function initServer($ie, $lockPlugin) { $pathFactory = new ezcWebdavBasicPathFactory('http://' . $_SERVER['HTTP_HOST'] . $this->baseUri); $this->server = ezcWebdavServer::getInstance(); foreach ($this->server->configurations as $id => $transportCfg) { // Prepare mock classes, if not done, yet if (!class_exists($mockClass = $transportCfg->transportClass . 'Mock', false)) { eval(sprintf($this->mockClassSource, $mockClass, $transportCfg->transportClass)); } // Replace with mock config $this->server->configurations[$id]->transportClass = $mockClass; $this->server->configurations[$id]->pathFactory = $pathFactory; } $this->server->auth = $ie ? new ezcWebdavTestAuthIe() : new ezcWebdavTestAuth(); if ($lockPlugin) { $this->server->pluginRegistry->registerPlugin(new ezcWebdavLockPluginConfiguration(new ezcWebdavLockPluginOptions(array('backendLockTimeout' => 2000000)))); } $this->server->auth->tokenAssignement = file_exists($this->tokenFile = TMP_DIR . '/tokens.ser') ? unserialize(file_get_contents($this->tokenFile)) : array(); }
protected function setUp() { ezcWebdavServer::getInstance()->reset(); }
public function authenticateAnonymous(ezcWebdavAnonymousAuth $data) { // added by @ds to fix problems with IE6 SP2 $path = ezcWebdavServer::getInstance()->pathFactory->parseUriToPath($_SERVER['REQUEST_URI']); return $path === '/'; }
protected function tearDown() { ezcWebdavServer::getInstance()->reset(); }
/** * Extracts active lock tokens from a lockdiscovery property. * * Returns an array of string lock tokens, that are active on the affected * resource and owned by the currently active user. * * @param ezcWebdavLockDiscoveryProperty $lockDiscovery * @param ezcWebdavAuth $authHeader * @return array(string) */ protected function extractActiveTokens(ezcWebdavLockDiscoveryProperty $lockDiscovery = null, ezcWebdavAuth $authHeader) { $auth = ezcWebdavServer::getInstance()->auth; $activeLockTokens = array(); foreach ($lockDiscovery->activeLock as $activeLock) { $token = (string) $activeLock->token; if ($auth->ownsLock($authHeader->username, $token)) { $activeLockTokens[] = $token; } } return $activeLockTokens; }
/** * Updates the lock properties on the target. * * Performs the neccessary PROPPATCH requests to update the lock properties * on the target (parent is locked or was lock null before). */ protected function updateLockProperties() { if (!$this->isParentProp) { // No need to update return null; } $lockDiscoveryProp = $this->lockDiscoveryProp !== null ? clone $this->lockDiscoveryProp : new ezcWebdavLockDiscoveryProperty(); $destParent = dirname($this->request->requestUri); foreach ($lockDiscoveryProp->activeLock as $id => $activeLock) { if ($activeLock->depth !== ezcWebdavRequest::DEPTH_INFINITY) { unset($lockDiscoveryProp->activeLock[$id]); continue; } if ($activeLock->baseUri === null) { $activeLock->baseUri = $destParent; $activeLock->lastAccess = null; } } $propPatchReq = new ezcWebdavPropPatchRequest($this->request->requestUri); ezcWebdavLockTools::cloneRequestHeaders($this->request, $propPatchReq); $propPatchReq->validateHeaders(); $propPatchReq->updates->attach($lockDiscoveryProp, ezcWebdavPropPatchRequest::SET); $propPatchRes = ezcWebdavServer::getInstance()->backend->propPatch($propPatchReq); if (!$propPatchRes instanceof ezcWebdavPropPatchResponse) { throw new ezcWebdavInconsistencyException('Could not patch lock properties on newly created resource/collection.'); } }
/** * Serializes an object of new ezcWebdavPropertyStorage to XML. * * Attaches all properties of the $storage to the $parentElement XML * element in their XML representation. * * @param ezcWebdavPropertyStorage $storage * @param DOMElement $parentElement * @return void */ public final function serializeProperties(ezcWebdavPropertyStorage $storage, DOMElement $parentElement) { foreach ($storage as $property) { if ($property instanceof ezcWebdavLiveProperty) { $propertyElement = $this->serializeLiveProperty($property, $parentElement); // Attempt plugins to parse an unknown live property if ($propertyElement === null) { // Plugin hook beforeSerializeLiveProperty $propertyElement = ezcWebdavServer::getInstance()->pluginRegistry->announceHook(__CLASS__, 'serializeUnknownLiveProperty', new ezcWebdavPluginParameters(array('property' => $property, 'xmlTool' => $this->getXmlTool(), 'parentElement' => $parentElement))); } } else { // Plugin hook serializeDeadProperty $propertyElement = ezcWebdavServer::getInstance()->pluginRegistry->announceHook(__CLASS__, 'serializeDeadProperty', new ezcWebdavPluginParameters(array('property' => $property, 'xmlTool' => $this->getXmlTool()))); // No plugin wanted to serialize the propery if ($propertyElement === null) { if ($property === false) { var_dump($storage); } $propertyElement = $this->serializeDeadProperty($property, $parentElement); } } if ($propertyElement instanceof DOMNode) { $parentElement->appendChild($propertyElement); } } }
/** * Configures the server for handling a request. * * This method takes the instance of {@link ezcWebdavServer} in $server and * configures this instance according to the configuration represented. * After calling this method, the {@link ezcWebdavServer} instance in * $server is ready to handle a request. * * This method is not intended to be called directly, but by {@link * ezcWebdavServerConfigurationManager}, when requested to configure the * server. * * @param ezcWebdavServer $server * @return void */ public function configure(ezcWebdavServer $server) { $this->checkClasses(); $xmlTool = new $this->xmlToolClass(); $propertyHandler = new $this->propertyHandlerClass(); $headerHandler = new $this->headerHandlerClass(); $transport = new $this->transportClass(); $pathFactory = $this->pathFactory; $server->init($pathFactory, $xmlTool, $propertyHandler, $headerHandler, $transport); }
public function testGetTransportInstanceSuccessNonDefaultCtor() { $cfg = new ezcWebdavServerConfiguration('(.*Nautilus.*)', 'fooCustomTransport', 'fooCustomXmlTool', 'fooCustomPropertyHandler', 'fooCustomHeaderHandler', new ezcWebdavBasicPathFactory('http://foo.example.com/webdav/')); $server = ezcWebdavServer::getInstance(); $cfg->configure($server); $xmlTool = new fooCustomXmlTool(); $pathFactory = new ezcWebdavBasicPathFactory('http://foo.example.com/webdav/'); $propertyHandler = new fooCustomPropertyHandler(); $headerHandler = new fooCustomHeaderHandler(); $transport = new fooCustomTransport(); $this->assertEquals($xmlTool, $server->xmlTool); $this->assertEquals($pathFactory, $server->pathFactory); $this->assertEquals($propertyHandler, $server->propertyHandler); $this->assertEquals($transport, $server->transport); }
/** * Performs unlocking. * * Performs a PROPFIND request with the $depth of the lock with $token on * the given $path (which must be the lock base). All affected resources * get the neccessary properties updated to reflect the change. Lock null * resources in the lock are removed. * * @param ezcWebdavUnlockRequest $request * @param string $token * @param int $depth * @return ezcWebdavResponse */ protected function performUnlock(ezcWebdavUnlockRequest $request, $token, $depth) { $path = $request->requestUri; $backend = ezcWebdavServer::getInstance()->backend; // Find alle resources affected by the unlock, including affected properties $propFindReq = new ezcWebdavPropFindRequest($path); $propFindReq->prop = new ezcWebdavBasicPropertyStorage(); $propFindReq->prop->attach(new ezcWebdavLockDiscoveryProperty()); ezcWebdavLockTools::cloneRequestHeaders($request, $propFindReq); $propFindReq->setHeader('Depth', $depth); $propFindReq->validateHeaders(); $propFindMultistatusRes = $backend->propFind($propFindReq); // Remove lock information for the lock identified by $token from each affected resource foreach ($propFindMultistatusRes->responses as $propFindRes) { // Takes properties to be updated $changeProps = new ezcWebdavFlaggedPropertyStorage(); foreach ($propFindRes->responses as $propStatRes) { if ($propStatRes->status === ezcWebdavResponse::STATUS_200) { // Remove affected active lock part from lockdiscovery property if ($propStatRes->storage->contains('lockdiscovery')) { $lockDiscoveryProp = clone $propStatRes->storage->get('lockdiscovery'); foreach ($lockDiscoveryProp->activeLock as $id => $activeLock) { if ($activeLock->token == $token) { $lockDiscoveryProp->activeLock->offsetUnset($id); $changeProps->attach($lockDiscoveryProp, ezcWebdavPropPatchRequest::SET); break; } } } } } // Perform the PROPPATCH if (count($changeProps) > 0) { $propPatchReq = new ezcWebdavPropPatchRequest($propFindRes->node->path); $propPatchReq->updates = $changeProps; ezcWebdavLockTools::cloneRequestHeaders($request, $propPatchReq); $propPatchReq->validateHeaders(); $propPatchRes = $backend->propPatch($propPatchReq); if (!$propPatchRes instanceof ezcWebdavPropPatchResponse) { throw new ezcWebdavInconsistencyException("Lock token {$token} could not be unlocked on resource {$propFindRes->node->path}."); } } } return new ezcWebdavUnlockResponse(ezcWebdavResponse::STATUS_204); }
if ($_SERVER['REQUEST_URI'] == '' or $_SERVER['REQUEST_URI'] == '/' or $_SERVER['REQUEST_URI'] == '/webdav.php/' or $_SERVER['REQUEST_URI'] == '/webdav.php') { // $requestUri = $_SERVER['REQUEST_URI']; // if ( $requestUri == '' ) // { // $requestUri = '/'; // } // if ( $requestUri == '/webdav.php' ) // { // $requestUri = '/webdav.php/'; // } $server = ezcWebdavServer::getInstance(); $backend = new eZWebDAVContentBackend(); $server->handle($backend); } else { // Create & initialize a new instance of the content server. $server = ezcWebdavServer::getInstance(); $server->pluginRegistry->registerPlugin(new ezcWebdavLockPluginConfiguration()); $backend = new eZWebDAVContentBackend(); $server->auth = new eZWebDAVContentBackendAuth(); // Get the name of the site that is being browsed. $currentSite = $backend->currentSiteFromPath($_SERVER['REQUEST_URI']); // Proceed only if the current site is valid: if ($currentSite) { $backend->setCurrentSite($currentSite); // Process the request. $server->handle($backend); } else { header("HTTP/1.1 404 Not Found"); } } eZExecution::cleanExit();
protected function getPropertyStorage($path) { print_debug('getPropertyStorage ' . $path . "\n"); if (@file_exists($storagePath = $this->options->propertyStoragePath . '/properties-' . md5($path))) { $xml = ezcWebdavServer::getInstance()->xmlTool->createDom(@file_get_contents($storagePath)); } else { $xml = ezcWebdavServer::getInstance()->xmlTool->createDom(); } $handler = new ezcWebdavPropertyHandler(new ezcWebdavXmlTool()); try { $handler->extractProperties($xml->getElementsByTagNameNS('DAV:', '*'), $this->propertyStorage); } catch (Exception $e) { } return $this->propertyStorage; }
/** * Creates a lock-null resource. * * In case a LOCK request is issued on a resource, that does not exists, a * so-called lock-null resource is created. This resource must support some * of the WebDAV requests, but not all. In case an MKCOL or PUT request is * issued to such a resource, it is switched to be a real resource. In case * the lock is released, all null-lock resources in it are removed. * * @param ezcWebdavLockRequest $request * @return ezcWebdavResponse */ protected function createLockNullResource(ezcWebdavLockRequest $request) { $backend = ezcWebdavServer::getInstance()->backend; // Check parent directory for locks and other violations $violation = $this->tools->checkViolations(new ezcWebdavLockCheckInfo(dirname($request->requestUri), ezcWebdavRequest::DEPTH_ZERO, $request->getHeader('If'), $request->getHeader('Authorization'), ezcWebdavAuthorizer::ACCESS_WRITE)); if ($violation !== null) { return $this->createLockError($violation); } // Create lock null resource $putReq = new ezcWebdavPutRequest($request->requestUri, ''); ezcWebdavLockTools::cloneRequestHeaders($request, $putReq, array('If')); $putReq->setHeader('Content-Length', '0'); $putReq->validateHeaders(); $putRes = $backend->put($putReq); if (!$putRes instanceof ezcWebdavPutResponse) { return $this->createLockError($putRes); } // Attention, recursion! $res = $this->acquireLock($request); if ($res->status !== ezcWebdavResponse::STATUS_200) { return $res; } $res->status = ezcWebdavResponse::STATUS_201; return $res; }
/** * Handles the current request. * * This method is the absolute heart of the Webdav component. It is called * to make the server instance handle the current request. This means, a * {@link ezcWebdavTransport} is selected and instantiated through the * {@link ezcWebdavServerConfigurationManager} in {@link $configurations}. * This transport (and all other objects, created from the configuration) * is used to parse the incoming request into an instance of {@link * ezcWebdavRequest}, which is then handed to the submitted $backend for * handling. The resulting {@link ezcWebdavResponse} is serialized by the * {@link ezcWebdavTransport} and send back to the client. * * The method receives at least an instance of {@link ezcWebdavBackend}, * which is used to server the request. Optionally, the request URI can be * submitted in $uri. If this is not the case, the request URI is * determined by the server variables * <ul> * <li>$_SERVER['SERVER_NAME']</li> * <li>$_SERVER['REQUEST_URI']</li> * </ul> * * @param ezcWebdavBackend $backend * @param string $uri * * @return void */ public final function handle(ezcWebdavBackend $backend, $uri = null) { $uri = $uri === null ? 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] : $uri; // Perform final setup $this->properties['backend'] = $backend; if (!isset($_SERVER['HTTP_USER_AGENT'])) { throw new ezcWebdavMissingHeaderException('User-Agent'); } // Configure the server according to the requesting client $this->configurations->configure($this, $_SERVER['HTTP_USER_AGENT']); // Initialize all plugins $this->pluginRegistry->initPlugins(); // Parse request into request object $request = $this->transport->parseRequest($uri); // Perform authentication / authorization on the given request, // if it is known by the server. if ($request instanceof ezcWebdavRequest && is_object($this->properties['auth'])) { $res = $this->authenticate($request); if ($res !== null) { $request = $res; } } if ($request instanceof ezcWebdavRequest) { // Plugin hook receivedRequest $pluginRes = ezcWebdavServer::getInstance()->pluginRegistry->announceHook(__CLASS__, 'receivedRequest', new ezcWebdavPluginParameters(array('request' => $request))); if (is_object($pluginRes) && $pluginRes instanceof ezcWebdavResponse) { // Plugin already took care about processing the request $response = $pluginRes; } else { // Let backend process the request $response = $this->backend->performRequest($request); } } else { // The transport layer or auth mechanism already issued an error. $response = $request; } // Plugin hook generatedResponse ezcWebdavServer::getInstance()->pluginRegistry->announceHook(__CLASS__, 'generatedResponse', new ezcWebdavPluginParameters(array('response' => $response))); $this->transport->handleResponse($response); }
/** * Parses the tag of a tagged list. * * @param string $content * @param int $len * @param int $i * @return string * * @throws ezcWebdavInvalidHeaderException * if any unexpected character occurs while parsing. */ protected function parseTagPath($content, $len, &$i) { $uri = ''; while ($i < $len && $content[$i] !== '>') { $uri .= $content[$i++]; } ++$i; return ezcWebdavServer::getInstance()->pathFactory->parseUriToPath($uri); }
/** * Creates a new lock purger. * * $backend must be the back end used in the Webdav environment. Note, that * you should have the {@link ezcWebdavServer} configured, before you use * the administrator class. Some actions will check for the lock plugin and * use the options set for it. In case the lock plugin is not registered in * the server, it will be registered before an action takes place and * unregistered afterwards. * * @param ezcWebdavBackend $backend */ public function __construct(ezcWebdavBackend $backend) { $this->server = ezcWebdavServer::getInstance(); $this->backend = $backend; }
/** * Processes a lock response into a korresponding display information struct. * * The struct ist the processed by {@link * ezcWebdavTransport::flattenResponse()} and send by {@link * ezcWebdavTransport::sendResponse()}. * * @param ezcWebdavLockResponse $response * @return ezcWebdavXmlDisplayInformation */ protected function processLockResponse(ezcWebdavLockResponse $response) { $xmlTool = ezcWebdavServer::getInstance()->xmlTool; $dom = $xmlTool->createDom(); $propElement = $dom->appendChild($xmlTool->createDomElement($dom, 'prop')); $this->propertyHandler->serializeLiveProperty($response->lockDiscovery, $propElement, $xmlTool); return new ezcWebdavXmlDisplayInformation($response, $dom); }
/** * Initialializes the WebDAV server used for capturing. * * Retrieves the global server singleton and replaces all configured * transports with their corresponding mock. * * @param ezcWebdavPathFactory $pathFactory * @return void */ protected function initServer(ezcWebdavPathFactory $pathFactory, $ie, $lockPlugin) { $this->server = ezcWebdavServer::getInstance(); foreach ($this->server->configurations as $id => $transportCfg) { // Prepare mock classes, if not done, yet if (!class_exists($mockClass = $transportCfg->transportClass . 'Mock', false)) { eval(sprintf($this->mockClassSource, $mockClass, $transportCfg->transportClass)); } // Replace with mock config $this->server->configurations[$id]->transportClass = $mockClass; $this->server->configurations[$id]->pathFactory = $pathFactory; } $this->server->auth = $ie ? new ezcWebdavTestAuthIe() : new ezcWebdavTestAuth(); if ($lockPlugin) { $this->server->pluginRegistry->registerPlugin(new ezcWebdavLockPluginConfiguration(new ezcWebdavLockPluginOptions(array('backendLockTimeout' => 2000000)))); } }
public function testCreateTransportFailure() { $dp = new ezcWebdavServerConfigurationManager(); unset($dp[0]); unset($dp[0]); unset($dp[0]); unset($dp[0]); try { $dp->configure(ezcWebdavServer::getInstance(), 'Fooo Bar'); $this->fail('Creating transport does not fail without any configs.'); } catch (ezcWebdavMissingTransportConfigurationException $e) { } $unmatching = new ezcWebdavServerConfiguration('(^.*micro\\$oft.*)i'); $dp[] = $unmatching; try { $dp->configure(ezcWebdavServer::getInstance(), 'Fooo Bar'); $this->fail('Creating transport does not fail without any configs.'); } catch (ezcWebdavMissingTransportConfigurationException $e) { } $dp->configure(ezcWebdavServer::getInstance(), 'some MiCrO$OfT client'); $this->assertEquals(new ezcWebdavTransport(), ezcWebdavServer::getInstance()->transport, 'Transport not created correctly with match.'); }
/** * Returns if plugin data is available in the storage. * * This method checks if there is data available for the given plugin * $namespace and data $key. If the given $namespace is unknown by the * global {@link ezcWebdavPluginRegistry} an {@link * ezcBaseValueException} will be thrown. If data (not null) is * assigned to the given key this method returns true, otherwise false. * * @param string $namespace * @param string $key * @return bool * * @throws ezcBaseValueException * if the $namespace is unknown by the {@link * ezcWebdavPluginRegistry} or if $key is not a string. */ public function hasPluginData($namespace, $key) { if (!ezcWebdavServer::getInstance()->pluginRegistry->hasPlugin($namespace)) { throw new ezcBaseValueException('namespace', $namespace, 'known by ezcWebdavPluginRegistry'); } if (!is_string($key)) { throw new ezcBaseValueException('key', $key, 'string'); } return isset($this->pluginData[$namespace][$key]); }