Version 3.2.3

This commit is contained in:
Neo committed 2025-12-19 00:34:03 -08:00
1 parent ae5c01cc78
commit 78706903a2
2641 files changed
+228363 -201264

No files matched your search

@@ -0,0 +1,49 @@
<?php
/**
* This is the base class for any authentication object.
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
abstract class Sabre_DAV_Auth_Backend_Abstract {
/**
* Authenticates the user based on the current request.
*
* If authentication is succesful, true must be returned.
* If authentication fails, an exception must be thrown.
*
* @return bool
*/
abstract public function authenticate(Sabre_DAV_Server $server,$realm);
/**
* Returns information about the currently logged in user.
*
* If nobody is currently logged in, this method should return null.
*
* @return array|null
*/
abstract public function getCurrentUser();
/**
* Returns the full list of users.
*
* This method must at least return a uri for each user.
*
* It is optional to implement this.
*
* @return array
*/
public function getUsers() {
return array();
}
}
@@ -0,0 +1,85 @@
<?php
/**
* HTTP Basic authentication backend class
*
* This class can be used by authentication objects wishing to use HTTP Basic
* Most of the digest logic is handled, implementors just need to worry about
* the authenticateInternal and getUserInfo methods
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author James David Low (http://jameslow.com/)
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
abstract class Sabre_DAV_Auth_Backend_AbstractBasic extends Sabre_DAV_Auth_Backend_Abstract {
/**
* This variable holds information about the currently
* logged in user.
*
* @var array|null
*/
protected $currentUser;
/**
* Validates a username and password
*
* If the username and password were correct, this method must return
* an array with at least a 'uri' key.
*
* If the credentials are incorrect, this method must return false.
*
* @return bool|array
*/
abstract protected function validateUserPass($username, $password);
/**
* Returns information about the currently logged in user.
*
* If nobody is currently logged in, this method should return null.
*
* @return array|null
*/
public function getCurrentUser() {
return $this->currentUser;
}
/**
* Authenticates the user based on the current request.
*
* If authentication is succesful, true must be returned.
* If authentication fails, an exception must be thrown.
*
* @throws Sabre_DAV_Exception_NotAuthenticated
* @return bool
*/
public function authenticate(Sabre_DAV_Server $server,$realm) {
$auth = new Sabre_HTTP_BasicAuth();
$auth->setHTTPRequest($server->httpRequest);
$auth->setHTTPResponse($server->httpResponse);
$auth->setRealm($realm);
$userpass = $auth->getUserPass();
if (!$userpass) {
$auth->requireLogin();
throw new Sabre_DAV_Exception_NotAuthenticated('No basic authentication headers were found');
}
// Authenticates the user
if (!($userData = $this->validateUserPass($userpass[0],$userpass[1]))) {
$auth->requireLogin();
throw new Sabre_DAV_Exception_NotAuthenticated('Username or password does not match');
}
if (!isset($userData['uri'])) {
throw new Sabre_DAV_Exception('The returned array from validateUserPass must contain at a uri element');
}
$this->currentUser = $userData;
return true;
}
}
@@ -0,0 +1,105 @@
<?php
/**
* HTTP Digest authentication backend class
*
* This class can be used by authentication objects wishing to use HTTP Digest
* Most of the digest logic is handled, implementors just need to worry about
* the getUserInfo method
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
abstract class Sabre_DAV_Auth_Backend_AbstractDigest extends Sabre_DAV_Auth_Backend_Abstract {
/**
* This variable holds information about the currently
* logged in user.
*
* @var array|null
*/
protected $currentUser;
/**
* Returns a users information based on its username
*
* The returned struct must contain at least a uri
* element (which can be identical to username) as well as a digestHash
* element.
*
* If the user was not known, false must be returned.
*
* @param string $realm
* @param string $username
* @return array
*/
abstract public function getUserInfo($realm, $username);
/**
* Authenticates the user based on the current request.
*
* If authentication is succesful, true must be returned.
* If authentication fails, an exception must be thrown.
*
* @throws Sabre_DAV_Exception_NotAuthenticated
* @return bool
*/
public function authenticate(Sabre_DAV_Server $server,$realm) {
$digest = new Sabre_HTTP_DigestAuth();
// Hooking up request and response objects
$digest->setHTTPRequest($server->httpRequest);
$digest->setHTTPResponse($server->httpResponse);
$digest->setRealm($realm);
$digest->init();
$username = $digest->getUsername();
// No username was given
if (!$username) {
$digest->requireLogin();
throw new Sabre_DAV_Exception_NotAuthenticated('No digest authentication headers were found');
}
$userData = $this->getUserInfo($realm, $username);
// If this was false, the user account didn't exist
if ($userData===false) {
$digest->requireLogin();
throw new Sabre_DAV_Exception_NotAuthenticated('The supplied username was not on file');
}
if (!is_array($userData)) {
throw new Sabre_DAV_Exception('The returntype for getUserInfo must be either false or an array');
}
if (!isset($userData['uri']) || !isset($userData['digestHash'])) {
throw new Sabre_DAV_Exception('The returned array from getUserInfo must contain at least a uri and digestHash element');
}
// If this was false, the password or part of the hash was incorrect.
if (!$digest->validateA1($userData['digestHash'])) {
$digest->requireLogin();
throw new Sabre_DAV_Exception_NotAuthenticated('Incorrect username');
}
$this->currentUser = $userData;
return true;
}
/**
* Returns information about the currently logged in user.
*
* @return array|null
*/
public function getCurrentUser() {
return $this->currentUser;
}
}
@@ -0,0 +1,77 @@
<?php
/**
* Apache authenticator
*
* This authentication backend assumes that auhtentication has been
* conifgured in apache, rather than within SabreDAV.
*
* Make sure apache is properly configured for this to work.
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Auth_Backend_Apache extends Sabre_DAV_Auth_Backend_Abstract {
/**
* Current apache user
*
* @var string
*/
protected $remoteUser;
/**
* Authenticates the user based on the current request.
*
* If authentication is succesful, true must be returned.
* If authentication fails, an exception must be thrown.
*
* @return bool
*/
public function authenticate(Sabre_DAV_Server $server,$realm) {
$remoteUser = $server->httpRequest->getRawServerValue('REMOTE_USER');
if (is_null($remoteUser)) {
throw new Sabre_DAV_Exception('We did not receive the $_SERVER[REMOTE_USER] property. This means that apache might have been misconfigured');
}
$this->remoteUser = $remoteUser;
return true;
}
/**
* Returns information about the currently logged in user.
*
* If nobody is currently logged in, this method should return null.
*
* @return array|null
*/
public function getCurrentUser() {
return array(
'uri' => 'principals/' . $this->remoteUser,
);
}
/**
* Returns the full list of users.
*
* This method must at least return a uri for each user.
*
* It is optional to implement this.
*
* @return array
*/
public function getUsers() {
return array($this->getCurrentUser());
}
}
@@ -0,0 +1,102 @@
<?php
/**
* This is an authentication backend that uses a file to manage passwords.
*
* The backend file must conform to Apache's htdigest format
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Auth_Backend_File extends Sabre_DAV_Auth_Backend_AbstractDigest {
/**
* List of users
*
* @var array
*/
protected $users = array();
/**
* Creates the backend object.
*
* If the filename argument is passed in, it will parse out the specified file fist.
*
* @param string $filename
* @return void
*/
public function __construct($filename=null) {
if (!is_null($filename))
$this->loadFile($filename);
}
/**
* Loads an htdigest-formatted file. This method can be called multiple times if
* more than 1 file is used.
*
* @param string $filename
* @return void
*/
public function loadFile($filename) {
foreach(file($filename,FILE_IGNORE_NEW_LINES) as $line) {
if (substr_count($line, ":") !== 2)
throw new Sabre_DAV_Exception('Malformed htdigest file. Every line should contain 2 colons');
list($username,$realm,$A1) = explode(':',$line);
if (!preg_match('/^[a-zA-Z0-9]{32}$/', $A1))
throw new Sabre_DAV_Exception('Malformed htdigest file. Invalid md5 hash');
$this->users[$username] = array(
'digestHash' => $A1,
'uri' => 'principals/' . $username
);
}
}
/**
* Returns a users' information
*
* @param string $realm
* @param string $username
* @return string
*/
public function getUserInfo($realm, $username) {
return isset($this->users[$username])?$this->users[$username]:false;
}
/**
* Returns the full list of users.
*
* This method must at least return a uri for each user.
*
* @return array
*/
public function getUsers() {
$re = array();
foreach($this->users as $userName=>$A1) {
$re[] = array(
'uri'=>'principals/' . $userName
);
}
return $re;
}
}
@@ -0,0 +1,79 @@
<?php
/**
* This is an authentication backend that uses a file to manage passwords.
*
* The backend file must conform to Apache's htdigest format
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Auth_Backend_PDO extends Sabre_DAV_Auth_Backend_AbstractDigest {
private $pdo;
/**
* Creates the backend object.
*
* If the filename argument is passed in, it will parse out the specified file fist.
*
* @param string $filename
* @return void
*/
public function __construct(PDO $pdo) {
$this->pdo = $pdo;
}
/**
* Returns a users' information
*
* @param string $realm
* @param string $username
* @return string
*/
public function getUserInfo($realm,$username) {
$stmt = $this->pdo->prepare('SELECT username, digesta1, email FROM users WHERE username = ?');
$stmt->execute(array($username));
$result = $stmt->fetchAll();
if (!count($result)) return false;
$user = array(
'uri' => 'principals/' . $result[0]['username'],
'digestHash' => $result[0]['digesta1'],
);
if ($result[0]['email']) $user['{http://sabredav.org/ns}email-address'] = $result[0]['email'];
return $user;
}
/**
* Returns a list of all users
*
* @return array
*/
public function getUsers() {
$result = $this->pdo->query('SELECT username, email FROM users')->fetchAll();
$rv = array();
foreach($result as $user) {
$r = array(
'uri' => 'principals/' . $user['username'],
);
if ($user['email']) $r['{http://sabredav.org/ns}email-address'] = $user['email'];
$rv[] = $r;
}
return $rv;
}
}
@@ -0,0 +1,10 @@
<html>
<head><title>IP.Board - Bulletin Board System</title></head>
<body>
<h1>403: IP.Board -&gt; Forbidden</h1>
<hr>
You have reached this page in error, please use your back button to return to the forum.
<hr>
<a href="http://www.invisionpower.com/">IP.Board</a>
</body>
</html>
@@ -0,0 +1,434 @@
<?php
/**
* This plugin provides Authentication for a WebDAV server.
*
* It relies on a Backend object, which provides user information.
*
* Additionally, it provides support for:
* * {DAV:}current-user-principal property from RFC5397
* * {DAV:}principal-collection-set property from RFC3744
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Auth_Plugin extends Sabre_DAV_ServerPlugin {
/**
* Reference to main server object
*
* @var Sabre_DAV_Server
*/
private $server;
/**
* Authentication backend
*
* @var Sabre_DAV_Auth_Backend_Abstract
*/
private $authBackend;
/**
* The authentication realm.
*
* @var string
*/
private $realm;
/**
* __construct
*
* @param Sabre_DAV_Auth_Backend_Abstract $authBackend
* @param string $realm
* @return void
*/
public function __construct(Sabre_DAV_Auth_Backend_Abstract $authBackend, $realm) {
$this->authBackend = $authBackend;
$this->realm = $realm;
}
/**
* Initializes the plugin. This function is automatically called by the server
*
* @param Sabre_DAV_Server $server
* @return void
*/
public function initialize(Sabre_DAV_Server $server) {
$this->server = $server;
$this->server->subscribeEvent('beforeMethod',array($this,'beforeMethod'),10);
$this->server->subscribeEvent('afterGetProperties',array($this,'afterGetProperties'));
$this->server->subscribeEvent('report',array($this,'report'));
}
/**
* This method intercepts calls to PROPFIND and similar lookups
*
* This is done to inject the current-user-principal if this is requested.
*
* @todo support for 'unauthenticated'
* @return void
*/
public function afterGetProperties($href, &$properties) {
if (array_key_exists('{DAV:}current-user-principal', $properties[404])) {
if ($ui = $this->authBackend->getCurrentUser()) {
$properties[200]['{DAV:}current-user-principal'] = new Sabre_DAV_Property_Principal(Sabre_DAV_Property_Principal::HREF, $ui['uri']);
} else {
$properties[200]['{DAV:}current-user-principal'] = new Sabre_DAV_Property_Principal(Sabre_DAV_Property_Principal::UNAUTHENTICATED);
}
unset($properties[404]['{DAV:}current-user-principal']);
}
if (array_key_exists('{DAV:}principal-collection-set', $properties[404])) {
$properties[200]['{DAV:}principal-collection-set'] = new Sabre_DAV_Property_Href('principals');
unset($properties[404]['{DAV:}principal-collection-set']);
}
if (array_key_exists('{DAV:}supported-report-set', $properties[200])) {
$properties[200]['{DAV:}supported-report-set']->addReport(array(
'{DAV:}expand-property',
));
}
}
/**
* This method is called before any HTTP method and forces users to be authenticated
*
* @param string $method
* @throws Sabre_DAV_Exception_NotAuthenticated
* @return bool
*/
public function beforeMethod($method, $uri) {
$this->authBackend->authenticate($this->server,$this->realm);
}
/**
* This functions handles REPORT requests
*
* @param string $reportName
* @param DOMNode $dom
* @return bool|null
*/
public function report($reportName,$dom) {
switch($reportName) {
case '{DAV:}expand-property' :
$this->expandPropertyReport($dom);
return false;
case '{DAV:}principal-property-search' :
if ($this->server->getRequestUri()==='principals') {
$this->principalPropertySearchReport($dom);
return false;
}
break;
case '{DAV:}principal-search-property-set' :
if ($this->server->getRequestUri()==='principals') {
$this->principalSearchPropertySetReport($dom);
return false;
}
break;
}
}
/**
* The expand-property report is defined in RFC3253 section 3-8.
*
* This report is very similar to a standard PROPFIND. The difference is
* that it has the additional ability to look at properties containing a
* {DAV:}href element, follow that property and grab additional elements
* there.
*
* Other rfc's, such as ACL rely on this report, so it made sense to put
* it in this plugin.
*
* @param DOMElement $dom
* @return void
*/
protected function expandPropertyReport($dom) {
$requestedProperties = $this->parseExpandPropertyReportRequest($dom->firstChild->firstChild);
$depth = $this->server->getHTTPDepth(0);
$requestUri = $this->server->getRequestUri();
$result = $this->expandProperties($requestUri,$requestedProperties,$depth);
$dom = new DOMDocument('1.0','utf-8');
$dom->formatOutput = true;
$multiStatus = $dom->createElement('d:multistatus');
$dom->appendChild($multiStatus);
// Adding in default namespaces
foreach($this->server->xmlNamespaces as $namespace=>$prefix) {
$multiStatus->setAttribute('xmlns:' . $prefix,$namespace);
}
foreach($result as $entry) {
$entry->serialize($this->server,$multiStatus);
}
$xml = $dom->saveXML();
$this->server->httpResponse->setHeader('Content-Type','application/xml; charset=utf-8');
$this->server->httpResponse->sendStatus(207);
$this->server->httpResponse->sendBody($xml);
// Make sure the event chain is broken
return false;
}
/**
* This method is used by expandPropertyReport to parse
* out the entire HTTP request.
*
* @param DOMElement $node
* @return array
*/
protected function parseExpandPropertyReportRequest($node) {
$requestedProperties = array();
do {
if (Sabre_DAV_XMLUtil::toClarkNotation($node)!=='{DAV:}property') continue;
if ($node->firstChild) {
$children = $this->parseExpandPropertyReportRequest($node->firstChild);
} else {
$children = array();
}
$namespace = $node->getAttribute('namespace');
if (!$namespace) $namespace = 'DAV:';
$propName = '{'.$namespace.'}' . $node->getAttribute('name');
$requestedProperties[$propName] = $children;
} while ($node = $node->nextSibling);
return $requestedProperties;
}
/**
* This method expands all the properties and returns
* a list with property values
*
* @param array $path
* @param array $requestedProperties the list of required properties
* @param array $depth
*/
protected function expandProperties($path,array $requestedProperties,$depth) {
$foundProperties = $this->server->getPropertiesForPath($path,array_keys($requestedProperties),$depth);
$result = array();
foreach($foundProperties as $node) {
foreach($requestedProperties as $propertyName=>$childRequestedProperties) {
// We're only traversing if sub-properties were requested
if(count($childRequestedProperties)===0) continue;
// We only have to do the expansion if the property was found
// and it contains an href element.
if (!array_key_exists($propertyName,$node[200])) continue;
if (!($node[200][$propertyName] instanceof Sabre_DAV_Property_IHref)) continue;
$href = $node[200][$propertyName]->getHref();
list($node[200][$propertyName]) = $this->expandProperties($href,$childRequestedProperties,0);
}
$result[] = new Sabre_DAV_Property_Response($path, $node);
}
return $result;
}
protected function principalSearchPropertySetReport(DOMDocument $dom) {
$searchProperties = array(
'{DAV:}displayname' => 'display name'
);
$httpDepth = $this->server->getHTTPDepth(0);
if ($httpDepth!==0) {
throw new Sabre_DAV_Exception_BadRequest('This report is only defined when Depth: 0');
}
if ($dom->firstChild->hasChildNodes())
throw new Sabre_DAV_Exception_BadRequest('The principal-search-property-set report element is not allowed to have child elements');
$dom = new DOMDocument('1.0','utf-8');
$dom->formatOutput = true;
$root = $dom->createElement('d:principal-search-property-set');
$dom->appendChild($root);
// Adding in default namespaces
foreach($this->server->xmlNamespaces as $namespace=>$prefix) {
$root->setAttribute('xmlns:' . $prefix,$namespace);
}
$nsList = $this->server->xmlNamespaces;
foreach($searchProperties as $propertyName=>$description) {
$psp = $dom->createElement('d:principal-search-property');
$root->appendChild($psp);
$prop = $dom->createElement('d:prop');
$psp->appendChild($prop);
$propName = null;
preg_match('/^{([^}]*)}(.*)$/',$propertyName,$propName);
//if (!isset($nsList[$propName[1]])) {
// $nsList[$propName[1]] = 'x' . count($nsList);
//}
// If the namespace was defined in the top-level xml namespaces, it means
// there was already a namespace declaration, and we don't have to worry about it.
//if (isset($server->xmlNamespaces[$propName[1]])) {
$currentProperty = $dom->createElement($nsList[$propName[1]] . ':' . $propName[2]);
//} else {
// $currentProperty = $dom->createElementNS($propName[1],$nsList[$propName[1]].':' . $propName[2]);
//}
$prop->appendChild($currentProperty);
$descriptionElem = $dom->createElement('d:description');
$descriptionElem->setAttribute('xml:lang','en');
$descriptionElem->appendChild($dom->createTextNode($description));
$psp->appendChild($descriptionElem);
}
$this->server->httpResponse->setHeader('Content-Type','application/xml; charset=utf-8');
$this->server->httpResponse->sendStatus(200);
$this->server->httpResponse->sendBody($dom->saveXML());
}
protected function principalPropertySearchReport($dom) {
$searchableProperties = array(
'{DAV:}displayname' => 'display name'
);
list($searchProperties, $requestedProperties) = $this->parsePrincipalPropertySearchReportRequest($dom);
$uri = $this->server->getRequestUri();
$result = array();
$lookupResults = $this->server->getPropertiesForPath($uri, array_keys($searchProperties), 1);
// The first item in the results is the parent, so we get rid of it.
array_shift($lookupResults);
$matches = array();
foreach($lookupResults as $lookupResult) {
foreach($searchProperties as $searchProperty=>$searchValue) {
if (!isset($searchableProperties[$searchProperty])) {
throw new Sabre_DAV_Exception_BadRequest('Searching for ' . $searchProperty . ' is not supported');
}
if (isset($lookupResult[200][$searchProperty]) &&
mb_stripos($lookupResult[200][$searchProperty], $searchValue, 0, 'UTF-8')!==false) {
$matches[] = $lookupResult['href'];
}
}
}
$matchProperties = array();
foreach($matches as $match) {
list($result) = $this->server->getPropertiesForPath($match, $requestedProperties, 0);
$matchProperties[] = $result;
}
$xml = $this->server->generateMultiStatus($matchProperties);
$this->server->httpResponse->setHeader('Content-Type','application/xml; charset=utf-8');
$this->server->httpResponse->sendStatus(207);
$this->server->httpResponse->sendBody($xml);
}
protected function parsePrincipalPropertySearchReportRequest($dom) {
$httpDepth = $this->server->getHTTPDepth(0);
if ($httpDepth!==0) {
throw new Sabre_DAV_Exception_BadRequest('This report is only defined when Depth: 0');
}
$searchProperties = array();
// Parsing the search request
foreach($dom->firstChild->childNodes as $searchNode) {
if (Sabre_DAV_XMLUtil::toClarkNotation($searchNode)!=='{DAV:}property-search')
continue;
$propertyName = null;
$propertyValue = null;
foreach($searchNode->childNodes as $childNode) {
switch(Sabre_DAV_XMLUtil::toClarkNotation($childNode)) {
case '{DAV:}prop' :
$property = Sabre_DAV_XMLUtil::parseProperties($searchNode);
reset($property);
$propertyName = key($property);
break;
case '{DAV:}match' :
$propertyValue = $childNode->textContent;
break;
}
}
if (is_null($propertyName) || is_null($propertyValue))
throw new Sabre_DAV_Exception_BadRequest('Invalid search request. propertyname: ' . $propertyName . '. propertvvalue: ' . $propertyValue);
$searchProperties[$propertyName] = $propertyValue;
}
return array($searchProperties, array_keys(Sabre_DAV_XMLUtil::parseProperties($dom->firstChild)));
}
}
@@ -0,0 +1,147 @@
<?php
/**
* Principal class
*
* This class represents a user in the directory tree.
* Many WebDAV specs require a user to show up in the directory
* structure. The principal is defined in RFC 3744.
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Auth_Principal extends Sabre_DAV_Node implements Sabre_DAV_IProperties {
/**
* Full uri for this principal resource
*
* @var string
*/
protected $principalUri;/*noLibHook*/
/**
* Struct with principal information.
*
* @var array
*/
protected $principalProperties;
/**
* Creates the principal object
*
* @param string $principalUri Full uri to the principal resource
* @param array $principalProperties
*/
public function __construct($principalUri,array $principalProperties = array()) {
$this->principalUri = $principalUri;
$this->principalProperties = $principalProperties;
}
/**
* Returns the name of the element
*
* @return void
*/
public function getName() {
list(, $name) = Sabre_DAV_URLUtil::splitPath($this->principalUri);
return $name;
}
/**
* Returns the name of the user
*
* @return void
*/
public function getDisplayName() {
if (isset($this->principalProperties['{DAV:}displayname'])) {
return $this->principalProperties['{DAV:}displayname'];
} else {
return $this->getName();
}
}
/**
* Returns a list of properties
*
* @param array $requestedProperties
* @return void
*/
public function getProperties($requestedProperties) {
if (!count($requestedProperties)) {
// If all properties were requested
// we will only returns properties from this list
$requestedProperties = array(
'{DAV:}resourcetype',
'{DAV:}displayname',
);
}
// We need to always return the resourcetype
// This is a bug in the core server, but it is easier to do it this way for now
$newProperties = array(
'{DAV:}resourcetype' => new Sabre_DAV_Property_ResourceType('{DAV:}principal')
);
foreach($requestedProperties as $propName) switch($propName) {
case '{DAV:}alternate-URI-set' :
if (isset($this->principalProperties['{http://sabredav.org/ns}email-address'])) {
$href = 'mailto:' . $this->principalProperties['{http://sabredav.org/ns}email-address'];
$newProperties[$propName] = new Sabre_DAV_Property_Href($href);
} else {
$newProperties[$propName] = null;
}
break;
case '{DAV:}group-member-set' :
case '{DAV:}group-membership' :
$newProperties[$propName] = null;
break;
case '{DAV:}principal-URL' :
$newProperties[$propName] = new Sabre_DAV_Property_Href($this->principalUri);
break;
case '{DAV:}displayname' :
$newProperties[$propName] = $this->getDisplayName();
break;
default :
if (isset($this->principalProperties[$propName])) {
$newProperties[$propName] = $this->principalProperties[$propName];
}
break;
}
return $newProperties;
}
/**
* Updates this principals properties.
*
* Currently this is not supported
*
* @param array $properties
* @see Sabre_DAV_IProperties::updateProperties
* @return bool|array
*/
public function updateProperties($properties) {
return false;
}
}
@@ -0,0 +1,74 @@
<?php
/**
* Principals Collection
*
* This collection represents a list of users. It uses
* Sabre_DAV_Auth_Backend to determine which users are available on the list.
*
* The users are instances of Sabre_DAV_Auth_Principal
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Auth_PrincipalCollection extends Sabre_DAV_Directory {
/**
* The name of this object. It is not adviced to change this.
* The plugins that depend on the principals collection to exist need to
* be have a common name to find it.
*/
const NODENAME = 'principals';
/**
* Authentication backend
*
* @var Sabre_DAV_Auth_Backend
*/
protected $authBackend;
/**
* Creates the object
*
* @param Sabre_DAV_Auth_Backend_Abstract $authBackend
*/
public function __construct(Sabre_DAV_Auth_Backend_Abstract $authBackend) {
$this->authBackend = $authBackend;
}
/**
* Returns the name of this collection.
*
* @return string
*/
public function getName() {
return self::NODENAME;
}
/**
* Retursn the list of users
*
* @return void
*/
public function getChildren() {
$children = array();
foreach($this->authBackend->getUsers() as $principalInfo) {
$principalUri = $principalInfo['uri'] . '/';
$children[] = new Sabre_DAV_Auth_Principal($principalUri,$principalInfo);
}
return $children;
}
}
@@ -0,0 +1,10 @@
<html>
<head><title>IP.Board - Bulletin Board System</title></head>
<body>
<h1>403: IP.Board -&gt; Forbidden</h1>
<hr>
You have reached this page in error, please use your back button to return to the forum.
<hr>
<a href="http://www.invisionpower.com/">IP.Board</a>
</body>
</html>
@@ -0,0 +1,97 @@
<?php
/**
* GuessContentType plugin
*
* A lot of the built-in File objects just return application/octet-stream
* as a content-type by default. This is a problem for some clients, because
* they expect a correct contenttype.
*
* There's really no accurate, fast and portable way to determine the contenttype
* so this extension does what the rest of the world does, and guesses it based
* on the file extension.
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Browser_GuessContentType extends Sabre_DAV_ServerPlugin {
/**
* List of recognized file extensions
*
* Feel free to add more
*
* @var array
*/
public $extensionMap = array(
// images
'jpg' => 'image/jpeg',
'gif' => 'image/gif',
'png' => 'image/png',
// groupware
'ics' => 'text/calendar',
'vcf' => 'text/x-vcard',
// text
'txt' => 'text/plain',
);
/**
* Initializes the plugin
*
* @param Sabre_DAV_Server $server
* @return void
*/
public function initialize(Sabre_DAV_Server $server) {
// Using a relatively low priority (200) to allow other extensions
// to set the content-type first.
$server->subscribeEvent('afterGetProperties',array($this,'afterGetProperties'),200);
}
/**
* Handler for teh afterGetProperties event
*
* @param string $path
* @param array $properties
* @return void
*/
public function afterGetProperties($path, &$properties) {
if (array_key_exists('{DAV:}getcontenttype', $properties[404])) {
list(, $fileName) = Sabre_DAV_URLUtil::splitPath($path);
$contentType = $this->getContentType($fileName);
if ($contentType) {
$properties[200]['{DAV:}getcontenttype'] = $contentType;
unset($properties[404]['{DAV:}getcontenttype']);
}
}
}
/**
* Simple method to return the contenttype
*
* @param string $fileName
* @return string
*/
protected function getContentType($fileName) {
// Just grabbing the extension
$extension = substr($fileName,strrpos($fileName,'.')+1);
if (isset($this->extensionMap[$extension]))
return $this->extensionMap[$extension];
}
}
@@ -0,0 +1,54 @@
<?php
/**
* This is a simple plugin that will map any GET request for non-files to
* PROPFIND allprops-requests.
*
* This should allow easy debugging of PROPFIND
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Browser_MapGetToPropFind extends Sabre_DAV_ServerPlugin {
/**
* reference to server class
*
* @var Sabre_DAV_Server
*/
protected $server;
/**
* Initializes the plugin and subscribes to events
*
* @param Sabre_DAV_Server $server
* @return void
*/
public function initialize(Sabre_DAV_Server $server) {
$this->server = $server;
$this->server->subscribeEvent('beforeMethod',array($this,'httpGetInterceptor'));
}
/**
* This method intercepts GET requests to non-files, and changes it into an HTTP PROPFIND request
*
* @param string $method
* @return bool
*/
public function httpGetInterceptor($method, $uri) {
if ($method!='GET') return true;
$node = $this->server->tree->getNodeForPath($uri);
if ($node instanceof Sabre_DAV_IFile) return;
$this->server->invokeMethod('PROPFIND',$uri);
return false;
}
}
@@ -0,0 +1,248 @@
<?php
/**
* Browser Plugin
*
* This plugin provides a html representation, so that a WebDAV server may be accessed
* using a browser.
*
* The class intercepts GET requests to collection resources and generates a simple
* html index.
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Browser_Plugin extends Sabre_DAV_ServerPlugin {
/**
* reference to server class
*
* @var Sabre_DAV_Server
*/
protected $server;
/**
* enableEditing
*
* @var bool
*/
protected $enablePost = true;
/**
* Creates the object.
*
* By default it will allow file creation and uploads.
* Specify the first argument as false to disable this
*
* @param bool $enablePost
* @return void
*/
public function __construct($enablePost=true) {
$this->enablePost = $enablePost;
}
/**
* Initializes the plugin and subscribes to events
*
* @param Sabre_DAV_Server $server
* @return void
*/
public function initialize(Sabre_DAV_Server $server) {
$this->server = $server;
$this->server->subscribeEvent('beforeMethod',array($this,'httpGetInterceptor'));
if ($this->enablePost) $this->server->subscribeEvent('unknownMethod',array($this,'httpPOSTHandler'));
}
/**
* This method intercepts GET requests to collections and returns the html
*
* @param string $method
* @return bool
*/
public function httpGetInterceptor($method, $uri) {
if ($method!='GET') return true;
$node = $this->server->tree->getNodeForPath($uri);
if ($node instanceof Sabre_DAV_IFile) return true;
$this->server->httpResponse->sendStatus(200);
$this->server->httpResponse->setHeader('Content-Type','text/html; charset=utf-8');
$this->server->httpResponse->sendBody(
$this->generateDirectoryIndex($uri)
);
return false;
}
/**
* Handles POST requests for tree operations
*
* This method is not yet used.
*
* @param string $method
* @return bool
*/
public function httpPOSTHandler($method, $uri) {
if ($method!='POST') return true;
if (isset($_POST['action'])) switch($_POST['action']) {
case 'mkcol' :
if (isset($_POST['name']) && trim($_POST['name'])) {
// Using basename() because we won't allow slashes
list(, $folderName) = Sabre_DAV_URLUtil::splitPath(trim($_POST['name']));
$this->server->createDirectory($uri . '/' . $folderName);
}
break;
case 'put' :
if ($_FILES) $file = current($_FILES);
else break;
$newName = trim($file['name']);
list(, $newName) = Sabre_DAV_URLUtil::splitPath(trim($file['name']));
if (isset($_POST['name']) && trim($_POST['name']))
$newName = trim($_POST['name']);
// Making sure we only have a 'basename' component
list(, $newName) = Sabre_DAV_URLUtil::splitPath($newName);
if (is_uploaded_file($file['tmp_name'])) {
$parent = $this->server->tree->getNodeForPath(trim($uri,'/'));
$parent->createFile($newName,fopen($file['tmp_name'],'r'));
}
}
$this->server->httpResponse->setHeader('Location',$this->server->httpRequest->getUri());
return false;
}
/**
* Escapes a string for html.
*
* @param string $value
* @return void
*/
public function escapeHTML($value) {
return htmlspecialchars($value,ENT_QUOTES,'UTF-8');
}
/**
* Generates the html directory index for a given url
*
* @param string $path
* @return string
*/
public function generateDirectoryIndex($path) {
$html = "<html>
<head>
<title>Index for " . $this->escapeHTML($path) . "/ - SabreDAV " . Sabre_DAV_Version::VERSION . "</title>
<style type=\"text/css\"> body { Font-family: arial}</style>
</head>
<body>
<h1>Index for " . $this->escapeHTML($path) . "/</h1>
<table>
<tr><th>Name</th><th>Type</th><th>Size</th><th>Last modified</th></tr>
<tr><td colspan=\"4\"><hr /></td></tr>";
$files = $this->server->getPropertiesForPath($path,array(
'{DAV:}displayname',
'{DAV:}resourcetype',
'{DAV:}getcontenttype',
'{DAV:}getcontentlength',
'{DAV:}getlastmodified',
),1);
foreach($files as $k=>$file) {
// This is the current directory, we can skip it
if (rtrim($file['href'],'/')==$path) continue;
list(, $name) = Sabre_DAV_URLUtil::splitPath($file['href']);
$type = null;
if (isset($file[200]['{DAV:}resourcetype'])) {
$type = $file[200]['{DAV:}resourcetype']->getValue();
// resourcetype can have multiple values
if (is_array($type)) {
$type = implode(', ', $type);
}
// Some name mapping is preferred
switch($type) {
case '{DAV:}collection' :
$type = 'Collection';
break;
}
}
// If no resourcetype was found, we attempt to use
// the contenttype property
if (!$type && isset($file[200]['{DAV:}getcontenttype'])) {
$type = $file[200]['{DAV:}getcontenttype'];
}
if (!$type) $type = 'Unknown';
$size = isset($file[200]['{DAV:}getcontentlength'])?(int)$file[200]['{DAV:}getcontentlength']:'';
$lastmodified = isset($file[200]['{DAV:}getlastmodified'])?$file[200]['{DAV:}getlastmodified']->getTime()->format(DateTime::ATOM):'';
$fullPath = Sabre_DAV_URLUtil::encodePath('/' . trim($this->server->getBaseUri() . ($path?$path . '/':'') . $name,'/'));
$displayName = isset($file[200]['{DAV:}displayname'])?$file[200]['{DAV:}displayname']:$name;
$name = $this->escapeHTML($name);
$displayName = $this->escapeHTML($displayName);
$type = $this->escapeHTML($type);
$html.= "<tr>
<td><a href=\"{$fullPath}\">{$displayName}</a></td>
<td>{$type}</td>
<td>{$size}</td>
<td>{$lastmodified}</td>
</tr>";
}
$html.= "<tr><td colspan=\"4\"><hr /></td></tr>";
if ($this->enablePost) {
$html.= '<tr><td><form method="post" action="">
<h3>Create new folder</h3>
<input type="hidden" name="action" value="mkcol" />
Name: <input type="text" name="name" /><br />
<input type="submit" value="create" />
</form>
<form method="post" action="" enctype="multipart/form-data">
<h3>Upload file</h3>
<input type="hidden" name="action" value="put" />
Name (optional): <input type="text" name="name" /><br />
File: <input type="file" name="file" /><br />
<input type="submit" value="upload" />
</form>
</td></tr>';
}
$html.= "</table>
<address>Generated by SabreDAV " . Sabre_DAV_Version::VERSION ."-". Sabre_DAV_Version::STABILITY . " (c)2007-2010 <a href=\"http://code.google.com/p/sabredav/\">http://code.google.com/p/sabredav/</a></address>
</body>
</html>";
return $html;
}
}
@@ -0,0 +1,10 @@
<html>
<head><title>IP.Board - Bulletin Board System</title></head>
<body>
<h1>403: IP.Board -&gt; Forbidden</h1>
<hr>
You have reached this page in error, please use your back button to return to the forum.
<hr>
<a href="http://www.invisionpower.com/">IP.Board</a>
</body>
</html>
@@ -0,0 +1,90 @@
<?php
/**
* Directory class
*
* This is a helper class, that should aid in getting directory classes setup.
* Most of its methods are implemented, and throw permission denied exceptions
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
abstract class Sabre_DAV_Directory extends Sabre_DAV_Node implements Sabre_DAV_ICollection {
/**
* Returns a child object, by its name.
*
* This method makes use of the getChildren method to grab all the child nodes, and compares the name.
* Generally its wise to override this, as this can usually be optimized
*
* @param string $name
* @throws Sabre_DAV_Exception_FileNotFound
* @return Sabre_DAV_INode
*/
public function getChild($name) {
foreach($this->getChildren() as $child) {
if ($child->getName()==$name) return $child;
}
throw new Sabre_DAV_Exception_FileNotFound('File not found: ' . $name);
}
/**
* Checks is a child-node exists.
*
* It is generally a good idea to try and override this. Usually it can be optimized.
*
* @param string $name
* @return bool
*/
public function childExists($name) {
try {
$this->getChild($name);
return true;
} catch(Sabre_DAV_Exception_FileNotFound $e) {
return false;
}
}
/**
* Creates a new file in the directory
*
* @param string $name Name of the file
* @param resource $data Initial payload, passed as a readable stream resource.
* @throws Sabre_DAV_Exception_Forbidden
* @return void
*/
public function createFile($name, $data = null) {
throw new Sabre_DAV_Exception_Forbidden('Permission denied to create file (filename ' . $name . ')');
}
/**
* Creates a new subdirectory
*
* @param string $name
* @throws Sabre_DAV_Exception_Forbidden
* @return void
*/
public function createDirectory($name) {
throw new Sabre_DAV_Exception_Forbidden('Permission denied to create directory');
}
}
@@ -0,0 +1,63 @@
<?php
/**
* SabreDAV base exception
*
* This is SabreDAV's base exception file, use this to implement your own exception.
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
/**
* Main Exception class.
*
* This class defines a getHTTPCode method, which should return the appropriate HTTP code for the Exception occured.
* The default for this is 500.
*
* This class also allows you to generate custom xml data for your exceptions. This will be displayed
* in the 'error' element in the failing response.
*/
class Sabre_DAV_Exception extends Exception {
/**
* Returns the HTTP statuscode for this exception
*
* @return int
*/
public function getHTTPCode() {
return 500;
}
/**
* This method allows the exception to include additonal information into the WebDAV error response
*
* @param Sabre_DAV_Server $server
* @param DOMElement $errorNode
* @return void
*/
public function serialize(Sabre_DAV_Server $server,DOMElement $errorNode) {
}
/**
* This method allows the exception to return any extra HTTP response headers.
*
* The headers must be returned as an array.
*
* @return array
*/
public function getHTTPHeaders(Sabre_DAV_Server $server) {
return array();
}
}
@@ -0,0 +1,28 @@
<?php
/**
* BadRequest
*
* The BadRequest is thrown when the user submitted an invalid HTTP request
* BadRequest
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Exception_BadRequest extends Sabre_DAV_Exception {
/**
* Returns the HTTP statuscode for this exception
*
* @return int
*/
public function getHTTPCode() {
return 400;
}
}
@@ -0,0 +1,28 @@
<?php
/**
* Conflict
*
* A 409 Conflict is thrown when a user tried to make a directory over an existing
* file or in a parent directory that doesn't exist.
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Exception_Conflict extends Sabre_DAV_Exception {
/**
* Returns the HTTP statuscode for this exception
*
* @return int
*/
public function getHTTPCode() {
return 409;
}
}
@@ -0,0 +1,35 @@
<?php
/**
* ConflictingLock
*
* Similar to Exception_Locked, this exception thrown when a LOCK request
* was made, on a resource which was already locked
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Exception_ConflictingLock extends Sabre_DAV_Exception_Locked {
/**
* This method allows the exception to include additonal information into the WebDAV error response
*
* @param Sabre_DAV_Server $server
* @param DOMElement $errorNode
* @return void
*/
public function serialize(Sabre_DAV_Server $server,DOMElement $errorNode) {
if ($this->lock) {
$error = $errorNode->ownerDocument->createElementNS('DAV:','d:no-conflicting-lock');
$errorNode->appendChild($error);
if (!is_object($this->lock)) var_dump($this->lock);
$error->appendChild($errorNode->ownerDocument->createElementNS('DAV:','d:href',$this->lock->uri));
}
}
}
@@ -0,0 +1,28 @@
<?php
/**
* FileNotFound
*
* This Exception is thrown when a Node couldn't be found. It returns HTTP error code 404
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Exception_FileNotFound extends Sabre_DAV_Exception {
/**
* Returns the HTTP statuscode for this exception
*
* @return int
*/
public function getHTTPCode() {
return 404;
}
}
@@ -0,0 +1,27 @@
<?php
/**
* Forbidden
*
* This exception is thrown whenever a user tries to do an operation he's not allowed to
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Exception_Forbidden extends Sabre_DAV_Exception {
/**
* Returns the HTTP statuscode for this exception
*
* @return int
*/
public function getHTTPCode() {
return 403;
}
}
@@ -0,0 +1,27 @@
<?php
/**
* InsufficientStorage
*
* This Exception can be thrown, when for example a harddisk is full or a quota is exceeded
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Exception_InsufficientStorage extends Sabre_DAV_Exception {
/**
* Returns the HTTP statuscode for this exception
*
* @return int
*/
public function getHTTPCode() {
return 507;
}
}
@@ -0,0 +1,33 @@
<?php
/**
* InvalidResourceType
*
* This exception is thrown when the user tried to create a new collection, with
* a special resourcetype value that was not recognized by the server.
*
* See RFC5689 section 3.3
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Exception_InvalidResourceType extends Sabre_DAV_Exception_Forbidden {
/**
* This method allows the exception to include additonal information into the WebDAV error response
*
* @param Sabre_DAV_Server $server
* @param DOMElement $errorNode
* @return void
*/
public function serialize(Sabre_DAV_Server $server,DOMElement $errorNode) {
$error = $errorNode->ownerDocument->createElementNS('DAV:','d:valid-resourcetype');
$errorNode->appendChild($error);
}
}
@@ -0,0 +1,39 @@
<?php
/**
* LockTokenMatchesRequestUri
*
* This exception is thrown by UNLOCK if a supplied lock-token is invalid
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Exception_LockTokenMatchesRequestUri extends Sabre_DAV_Exception_Conflict {
/**
* Creates the exception
*/
public function __construct() {
$this->message = 'The locktoken supplied does not match any locks on this entity';
}
/**
* This method allows the exception to include additonal information into the WebDAV error response
*
* @param Sabre_DAV_Server $server
* @param DOMElement $errorNode
* @return void
*/
public function serialize(Sabre_DAV_Server $server,DOMElement $errorNode) {
$error = $errorNode->ownerDocument->createElementNS('DAV:','d:lock-token-matches-request-uri');
$errorNode->appendChild($error);
}
}
@@ -0,0 +1,67 @@
<?php
/**
* Locked
*
* The 423 is thrown when a client tried to access a resource that was locked, without supplying a valid lock token
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Exception_Locked extends Sabre_DAV_Exception {
/**
* Lock information
*
* @var Sabre_DAV_Locks_LockInfo
*/
protected $lock;
/**
* Creates the exception
*
* A LockInfo object should be passed if the user should be informed
* which lock actually has the file locked.
*
* @param Sabre_DAV_Locks_LockInfo $lock
*/
public function __construct(Sabre_DAV_Locks_LockInfo $lock = null) {
$this->lock = $lock;
}
/**
* Returns the HTTP statuscode for this exception
*
* @return int
*/
public function getHTTPCode() {
return 423;
}
/**
* This method allows the exception to include additonal information into the WebDAV error response
*
* @param Sabre_DAV_Server $server
* @param DOMElement $errorNode
* @return void
*/
public function serialize(Sabre_DAV_Server $server,DOMElement $errorNode) {
if ($this->lock) {
$error = $errorNode->ownerDocument->createElementNS('DAV:','d:lock-token-submitted');
$errorNode->appendChild($error);
if (!is_object($this->lock)) var_dump($this->lock);
$error->appendChild($errorNode->ownerDocument->createElementNS('DAV:','d:href',$this->lock->uri));
}
}
}
@@ -0,0 +1,44 @@
<?php
/**
* MethodNotAllowed
*
* The 405 is thrown when a client tried to create a directory on an already existing directory
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Exception_MethodNotAllowed extends Sabre_DAV_Exception {
/**
* Returns the HTTP statuscode for this exception
*
* @return int
*/
public function getHTTPCode() {
return 405;
}
/**
* This method allows the exception to return any extra HTTP response headers.
*
* The headers must be returned as an array.
*
* @return array
*/
public function getHTTPHeaders(Sabre_DAV_Server $server) {
$methods = $server->getAllowedMethods($server->getRequestUri());
return array(
'Allow' => strtoupper(implode(', ',$methods)),
);
}
}
@@ -0,0 +1,28 @@
<?php
/**
* NotAuthenticated
*
* This exception is thrown when the client did not provide valid
* authentication credentials.
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Exception_NotAuthenticated extends Sabre_DAV_Exception {
/**
* Returns the HTTP statuscode for this exception
*
* @return int
*/
public function getHTTPCode() {
return 401;
}
}
@@ -0,0 +1,27 @@
<?php
/**
* NotImplemented
*
* This exception is thrown when the client tried to call an unsupported HTTP method or other feature
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Exception_NotImplemented extends Sabre_DAV_Exception {
/**
* Returns the HTTP statuscode for this exception
*
* @return int
*/
public function getHTTPCode() {
return 501;
}
}
@@ -0,0 +1,69 @@
<?php
/**
* PreconditionFailed
*
* This exception is normally thrown when a client submitted a conditional request,
* like for example an If, If-None-Match or If-Match header, which caused the HTTP
* request to not execute (the condition of the header failed)
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Exception_PreconditionFailed extends Sabre_DAV_Exception {
/**
* When this exception is thrown, the header-name might be set.
*
* This allows the exception-catching code to determine which HTTP header
* caused the exception.
*
* @var string
*/
public $header = null;
/**
* Create the exception
*
* @param string $message
* @param string $header
*/
public function __construct($message, $header=null) {
parent::__construct($message);
$this->header = $header;
}
/**
* Returns the HTTP statuscode for this exception
*
* @return int
*/
public function getHTTPCode() {
return 412;
}
/**
* This method allows the exception to include additonal information into the WebDAV error response
*
* @param Sabre_DAV_Server $server
* @param DOMElement $errorNode
* @return void
*/
public function serialize(Sabre_DAV_Server $server,DOMElement $errorNode) {
if ($this->header) {
$prop = $errorNode->ownerDocument->createElement('s:header');
$prop->nodeValue = $this->header;
$errorNode->appendChild($prop);
}
}
}
@@ -0,0 +1,30 @@
<?php
/**
* ReportNotImplemented
*
* This exception is thrown when the client requested an unknown report through the REPORT method
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Exception_ReportNotImplemented extends Sabre_DAV_Exception_NotImplemented {
/**
* This method allows the exception to include additonal information into the WebDAV error response
*
* @param Sabre_DAV_Server $server
* @param DOMElement $errorNode
* @return void
*/
public function serialize(Sabre_DAV_Server $server,DOMElement $errorNode) {
$error = $errorNode->ownerDocument->createElementNS('DAV:','d:supported-report');
$errorNode->appendChild($error);
}
}
@@ -0,0 +1,29 @@
<?php
/**
* RequestedRangeNotSatisfiable
*
* This exception is normally thrown when the user
* request a range that is out of the entity bounds.
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Exception_RequestedRangeNotSatisfiable extends Sabre_DAV_Exception {
/**
* returns the http statuscode for this exception
*
* @return int
*/
public function getHTTPCode() {
return 416;
}
}
@@ -0,0 +1,28 @@
<?php
/**
* UnSupportedMediaType
*
* The 415 Unsupported Media Type status code is generally sent back when the client
* tried to call an HTTP method, with a body the server didn't understand
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Exception_UnsupportedMediaType extends Sabre_DAV_Exception {
/**
* returns the http statuscode for this exception
*
* @return int
*/
public function getHTTPCode() {
return 415;
}
}
@@ -0,0 +1,10 @@
<html>
<head><title>IP.Board - Bulletin Board System</title></head>
<body>
<h1>403: IP.Board -&gt; Forbidden</h1>
<hr>
You have reached this page in error, please use your back button to return to the forum.
<hr>
<a href="http://www.invisionpower.com/">IP.Board</a>
</body>
</html>
@@ -0,0 +1,121 @@
<?php
/**
* Directory class
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_FS_Directory extends Sabre_DAV_FS_Node implements Sabre_DAV_ICollection, Sabre_DAV_IQuota {
/**
* Creates a new file in the directory
*
* data is a readable stream resource
*
* @param string $name Name of the file
* @param resource $data Initial payload
* @return void
*/
public function createFile($name, $data = null) {
$newPath = $this->path . '/' . $name;
file_put_contents($newPath,$data);
}
/**
* Creates a new subdirectory
*
* @param string $name
* @return void
*/
public function createDirectory($name) {
$newPath = $this->path . '/' . $name;
mkdir($newPath);
}
/**
* Returns a specific child node, referenced by its name
*
* @param string $name
* @throws Sabre_DAV_Exception_FileNotFound
* @return Sabre_DAV_INode
*/
public function getChild($name) {
$path = $this->path . '/' . $name;
if (!file_exists($path)) throw new Sabre_DAV_Exception_FileNotFound('File with name ' . $path . ' could not be located');
if (is_dir($path)) {
return new Sabre_DAV_FS_Directory($path);
} else {
return new Sabre_DAV_FS_File($path);
}
}
/**
* Returns an array with all the child nodes
*
* @return Sabre_DAV_INode[]
*/
public function getChildren() {
$nodes = array();
foreach(scandir($this->path) as $node) if($node!='.' && $node!='..') $nodes[] = $this->getChild($node);
return $nodes;
}
/**
* Checks if a child exists.
*
* @param string $name
* @return bool
*/
public function childExists($name) {
$path = $this->path . '/' . $name;
return file_exists($path);
}
/**
* Deletes all files in this directory, and then itself
*
* @return void
*/
public function delete() {
foreach($this->getChildren() as $child) $child->delete();
rmdir($this->path);
}
/**
* Returns available diskspace information
*
* @return array
*/
public function getQuotaInfo() {
return array(
disk_total_space($this->path)-disk_free_space($this->path),
disk_free_space($this->path)
);
}
}
@@ -0,0 +1,89 @@
<?php
/**
* File class
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_FS_File extends Sabre_DAV_FS_Node implements Sabre_DAV_IFile {
/**
* Updates the data
*
* @param resource $data
* @return void
*/
public function put($data) {
file_put_contents($this->path,$data);
}
/**
* Returns the data
*
* @return string
*/
public function get() {
return fopen($this->path,'r');
}
/**
* Delete the current file
*
* @return void
*/
public function delete() {
unlink($this->path);
}
/**
* Returns the size of the node, in bytes
*
* @return int
*/
public function getSize() {
return filesize($this->path);
}
/**
* Returns the ETag for a file
*
* An ETag is a unique identifier representing the current version of the file. If the file changes, the ETag MUST change.
* The ETag is an arbritrary string, but MUST be surrounded by double-quotes.
*
* Return null if the ETag can not effectively be determined
*
* @return mixed
*/
public function getETag() {
return null;
}
/**
* Returns the mime-type for a file
*
* If null is returned, we'll assume application/octet-stream
*
* @return mixed
*/
public function getContentType() {
return null;
}
}
@@ -0,0 +1,81 @@
<?php
/**
* Base node-class
*
* The node class implements the method used by both the File and the Directory classes
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
abstract class Sabre_DAV_FS_Node implements Sabre_DAV_INode {
/**
* The path to the current node
*
* @var string
*/
protected $path;
/**
* Sets up the node, expects a full path name
*
* @param string $path
* @return void
*/
public function __construct($path) {
$this->path = $path;
}
/**
* Returns the name of the node
*
* @return string
*/
public function getName() {
list(, $name) = Sabre_DAV_URLUtil::splitPath($this->path);
return $name;
}
/**
* Renames the node
*
* @param string $name The new name
* @return void
*/
public function setName($name) {
list($parentPath, ) = Sabre_DAV_URLUtil::splitPath($this->path);
list(, $newName) = Sabre_DAV_URLUtil::splitPath($name);
$newPath = $parentPath . '/' . $newName;
rename($this->path,$newPath);
$this->path = $newPath;
}
/**
* Returns the last modification time, as a unix timestamp
*
* @return int
*/
public function getLastModified() {
return filemtime($this->path);
}
}
@@ -0,0 +1,10 @@
<html>
<head><title>IP.Board - Bulletin Board System</title></head>
<body>
<h1>403: IP.Board -&gt; Forbidden</h1>
<hr>
You have reached this page in error, please use your back button to return to the forum.
<hr>
<a href="http://www.invisionpower.com/">IP.Board</a>
</body>
</html>
@@ -0,0 +1,135 @@
<?php
/**
* Directory class
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_FSExt_Directory extends Sabre_DAV_FSExt_Node implements Sabre_DAV_ICollection, Sabre_DAV_IQuota {
/**
* Creates a new file in the directory
*
* @param string $name Name of the file
* @param resource $data Initial payload
* @return void
*/
public function createFile($name, $data = null) {
// We're not allowing dots
if ($name=='.' || $name=='..') throw new Sabre_DAV_Exception_Forbidden('Permission denied to . and ..');
$newPath = $this->path . '/' . $name;
file_put_contents($newPath,$data);
}
/**
* Creates a new subdirectory
*
* @param string $name
* @return void
*/
public function createDirectory($name) {
// We're not allowing dots
if ($name=='.' || $name=='..') throw new Sabre_DAV_Exception_Forbidden('Permission denied to . and ..');
$newPath = $this->path . '/' . $name;
mkdir($newPath);
}
/**
* Returns a specific child node, referenced by its name
*
* @param string $name
* @throws Sabre_DAV_Exception_FileNotFound
* @return Sabre_DAV_INode
*/
public function getChild($name) {
$path = $this->path . '/' . $name;
if (!file_exists($path)) throw new Sabre_DAV_Exception_FileNotFound('File could not be located');
if ($name=='.' || $name=='..') throw new Sabre_DAV_Exception_Forbidden('Permission denied to . and ..');
if (is_dir($path)) {
return new Sabre_DAV_FSExt_Directory($path);
} else {
return new Sabre_DAV_FSExt_File($path);
}
}
/**
* Checks if a child exists.
*
* @param string $name
* @return bool
*/
public function childExists($name) {
if ($name=='.' || $name=='..')
throw new Sabre_DAV_Exception_Forbidden('Permission denied to . and ..');
$path = $this->path . '/' . $name;
return file_exists($path);
}
/**
* Returns an array with all the child nodes
*
* @return Sabre_DAV_INode[]
*/
public function getChildren() {
$nodes = array();
foreach(scandir($this->path) as $node) if($node!='.' && $node!='..' && $node!='.sabredav') $nodes[] = $this->getChild($node);
return $nodes;
}
/**
* Deletes all files in this directory, and then itself
*
* @return void
*/
public function delete() {
// Deleting all children
foreach($this->getChildren() as $child) $child->delete();
// Removing resource info, if its still around
if (file_exists($this->path . '/.sabredav')) unlink($this->path . '/.sabredav');
// Removing the directory itself
rmdir($this->path);
return parent::delete();
}
/**
* Returns available diskspace information
*
* @return array
*/
public function getQuotaInfo() {
return array(
disk_total_space($this->path)-disk_free_space($this->path),
disk_free_space($this->path)
);
}
}
@@ -0,0 +1,88 @@
<?php
/**
* File class
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_FSExt_File extends Sabre_DAV_FSExt_Node implements Sabre_DAV_IFile {
/**
* Updates the data
*
* data is a readable stream resource.
*
* @param resource $data
* @return void
*/
public function put($data) {
file_put_contents($this->path,$data);
}
/**
* Returns the data
*
* @return string
*/
public function get() {
return fopen($this->path,'r');
}
/**
* Delete the current file
*
* @return void
*/
public function delete() {
unlink($this->path);
return parent::delete();
}
/**
* Returns the ETag for a file
*
* An ETag is a unique identifier representing the current version of the file. If the file changes, the ETag MUST change.
* The ETag is an arbritrary string, but MUST be surrounded by double-quotes.
*
* Return null if the ETag can not effectively be determined
*/
public function getETag() {
return '"' . md5_file($this->path). '"';
}
/**
* Returns the mime-type for a file
*
* If null is returned, we'll assume application/octet-stream
*/
public function getContentType() {
return null;
}
/**
* Returns the size of the file, in bytes
*
* @return int
*/
public function getSize() {
return filesize($this->path);
}
}
@@ -0,0 +1,276 @@
<?php
/**
* Base node-class
*
* The node class implements the method used by both the File and the Directory classes
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
abstract class Sabre_DAV_FSExt_Node extends Sabre_DAV_FS_Node implements Sabre_DAV_ILockable, Sabre_DAV_IProperties {
/**
* Returns all the locks on this node
*
* @return array
*/
function getLocks() {
$resourceData = $this->getResourceData();
$locks = $resourceData['locks'];
foreach($locks as $k=>$lock) {
if (time() > $lock->timeout + $lock->created) unset($locks[$k]);
}
return $locks;
}
/**
* Locks this node
*
* @param Sabre_DAV_Locks_LockInfo $lockInfo
* @return void
*/
function lock(Sabre_DAV_Locks_LockInfo $lockInfo) {
// We're making the lock timeout 30 minutes
$lockInfo->timeout = 1800;
$lockInfo->created = time();
$resourceData = $this->getResourceData();
if (!isset($resourceData['locks'])) $resourceData['locks'] = array();
$current = null;
foreach($resourceData['locks'] as $k=>$lock) {
if ($lock->token === $lockInfo->token) $current = $k;
}
if (!is_null($current)) $resourceData['locks'][$current] = $lockInfo;
else $resourceData['locks'][] = $lockInfo;
$this->putResourceData($resourceData);
}
/**
* Removes a lock from this node
*
* @param Sabre_DAV_Locks_LockInfo $lockInfo
* @return bool
*/
function unlock(Sabre_DAV_Locks_LockInfo $lockInfo) {
//throw new Sabre_DAV_Exception('bla');
$resourceData = $this->getResourceData();
foreach($resourceData['locks'] as $k=>$lock) {
if ($lock->token === $lockInfo->token) {
unset($resourceData['locks'][$k]);
$this->putResourceData($resourceData);
return true;
}
}
return false;
}
/**
* Updates properties on this node,
*
* @param array $mutations
* @see Sabre_DAV_IProperties::updateProperties
* @return bool|array
*/
public function updateProperties($properties) {
$resourceData = $this->getResourceData();
$result = array();
foreach($properties as $propertyName=>$propertyValue) {
// If it was null, we need to delete the property
if (is_null($propertyValue)) {
if (isset($resourceData['properties'][$propertyName])) {
unset($resourceData['properties'][$propertyName]);
}
} else {
$resourceData['properties'][$propertyName] = $propertyValue;
}
}
$this->putResourceData($resourceData);
return true;
}
/**
* Returns a list of properties for this nodes.;
*
* The properties list is a list of propertynames the client requested, encoded as xmlnamespace#tagName, for example: http://www.example.org/namespace#author
* If the array is empty, all properties should be returned
*
* @param array $properties
* @return void
*/
function getProperties($properties) {
$resourceData = $this->getResourceData();
// if the array was empty, we need to return everything
if (!$properties) return $resourceData['properties'];
$props = array();
foreach($properties as $property) {
if (isset($resourceData['properties'][$property])) $props[$property] = $resourceData['properties'][$property];
}
return $props;
}
/**
* Returns the path to the resource file
*
* @return string
*/
protected function getResourceInfoPath() {
list($parentDir) = Sabre_DAV_URLUtil::splitPath($this->path);
return $parentDir . '/.sabredav';
}
/**
* Returns all the stored resource information
*
* @return array
*/
protected function getResourceData() {
$path = $this->getResourceInfoPath();
if (!file_exists($path)) return array('locks'=>array(), 'properties' => array());
// opening up the file, and creating a shared lock
$handle = fopen($path,'r');
flock($handle,LOCK_SH);
$data = '';
// Reading data until the eof
while(!feof($handle)) {
$data.=fread($handle,8192);
}
// We're all good
fclose($handle);
// Unserializing and checking if the resource file contains data for this file
$data = unserialize($data);
if (!isset($data[$this->getName()])) {
return array('locks'=>array(), 'properties' => array());
}
$data = $data[$this->getName()];
if (!isset($data['locks'])) $data['locks'] = array();
if (!isset($data['properties'])) $data['properties'] = array();
return $data;
}
/**
* Updates the resource information
*
* @param array $newData
* @return void
*/
protected function putResourceData(array $newData) {
$path = $this->getResourceInfoPath();
// opening up the file, and creating a shared lock
$handle = fopen($path,'a+');
flock($handle,LOCK_EX);
$data = '';
rewind($handle);
// Reading data until the eof
while(!feof($handle)) {
$data.=fread($handle,8192);
}
// Unserializing and checking if the resource file contains data for this file
$data = unserialize($data);
$data[$this->getName()] = $newData;
ftruncate($handle,0);
rewind($handle);
fwrite($handle,serialize($data));
fclose($handle);
}
/**
* Renames the node
*
* @param string $name The new name
* @return void
*/
public function setName($name) {
list($parentPath, ) = Sabre_DAV_URLUtil::splitPath($this->path);
list(, $newName) = Sabre_DAV_URLUtil::splitPath($name);
$newPath = $parentPath . '/' . $newName;
// We're deleting the existing resourcedata, and recreating it
// for the new path.
$resourceData = $this->getResourceData();
$this->deleteResourceData();
rename($this->path,$newPath);
$this->path = $newPath;
$this->putResourceData($resourceData);
}
public function deleteResourceData() {
// When we're deleting this node, we also need to delete any resource information
$path = $this->getResourceInfoPath();
if (!file_exists($path)) return true;
// opening up the file, and creating a shared lock
$handle = fopen($path,'a+');
flock($handle,LOCK_EX);
$data = '';
rewind($handle);
// Reading data until the eof
while(!feof($handle)) {
$data.=fread($handle,8192);
}
// Unserializing and checking if the resource file contains data for this file
$data = unserialize($data);
if (isset($data[$this->getName()])) unset($data[$this->getName()]);
ftruncate($handle,0);
rewind($handle);
fwrite($handle,serialize($data));
fclose($handle);
}
public function delete() {
return $this->deleteResourceData();
}
}
@@ -0,0 +1,10 @@
<html>
<head><title>IP.Board - Bulletin Board System</title></head>
<body>
<h1>403: IP.Board -&gt; Forbidden</h1>
<hr>
You have reached this page in error, please use your back button to return to the forum.
<hr>
<a href="http://www.invisionpower.com/">IP.Board</a>
</body>
</html>
@@ -0,0 +1,81 @@
<?php
/**
* File class
*
* This is a helper class, that should aid in getting file classes setup.
* Most of its methods are implemented, and throw permission denied exceptions
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
abstract class Sabre_DAV_File extends Sabre_DAV_Node implements Sabre_DAV_IFile {
/**
* Updates the data
*
* data is a readable stream resource.
*
* @param resource $data
* @return void
*/
public function put($data) {
throw new Sabre_DAV_Exception_Forbidden('Permission denied to change data');
}
/**
* Returns the data
*
* This method may either return a string or a readable stream resource
*
* @return mixed
*/
public function get() {
throw new Sabre_DAV_Exception_Forbidden('Permission denied to read this file');
}
/**
* Returns the size of the file, in bytes.
*
* @return int
*/
public function getSize() {
return 0;
}
/**
* Returns the ETag for a file
*
* An ETag is a unique identifier representing the current version of the file. If the file changes, the ETag MUST change.
* The ETag is an arbritrary string, but MUST be surrounded by double-quotes.
*
* Return null if the ETag can not effectively be determined
*/
public function getETag() {
return null;
}
/**
* Returns the mime-type for a file
*
* If null is returned, we'll assume application/octet-stream
*/
public function getContentType() {
return null;
}
}
@@ -0,0 +1,58 @@
<?php
/**
* The ICollection Interface
*
* This interface should be implemented by each class that represents a collection
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
interface Sabre_DAV_ICollection extends Sabre_DAV_INode {
/**
* Creates a new file in the directory
*
* data is a readable stream resource
*
* @param string $name Name of the file
* @param resource $data Initial payload
* @return void
*/
function createFile($name, $data = null);
/**
* Creates a new subdirectory
*
* @param string $name
* @return void
*/
function createDirectory($name);
/**
* Returns a specific child node, referenced by its name
*
* @param string $name
* @return Sabre_DAV_INode
*/
function getChild($name);
/**
* Returns an array with all the child nodes
*
* @return Sabre_DAV_INode[]
*/
function getChildren();
/**
* Checks if a child-node with the specified name exists
*
* @return bool
*/
function childExists($name);
}
@@ -0,0 +1,28 @@
<?php
/**
* The IExtendedCollection interface.
*
* This interface can be used to create special-type of collection-resources
* as defined by RFC 5689.
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
interface Sabre_DAV_IExtendedCollection extends Sabre_DAV_ICollection {
/**
* Creates a new collection
*
* @param string $name
* @param array $resourceType
* @param array $properties
* @return void
*/
function createExtendedCollection($name, array $resourceType, array $properties);
}
@@ -0,0 +1,63 @@
<?php
/**
* This interface represents a file or leaf in the tree.
*
* The nature of a file is, as you might be aware of, that it doesn't contain sub-nodes and has contents
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
interface Sabre_DAV_IFile extends Sabre_DAV_INode {
/**
* Updates the data
*
* The data argument is a readable stream resource.
*
* @param resource $data
* @return void
*/
function put($data);
/**
* Returns the data
*
* This method may either return a string or a readable stream resource
*
* @return mixed
*/
function get();
/**
* Returns the mime-type for a file
*
* If null is returned, we'll assume application/octet-stream
*
* @return void
*/
function getContentType();
/**
* Returns the ETag for a file
*
* An ETag is a unique identifier representing the current version of the file. If the file changes, the ETag MUST change.
*
* Return null if the ETag can not effectively be determined
*
* @return void
*/
function getETag();
/**
* Returns the size of the node, in bytes
*
* @return int
*/
function getSize();
}
@@ -0,0 +1,38 @@
<?php
/**
* Implement this class to support locking
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
interface Sabre_DAV_ILockable extends Sabre_DAV_INode {
/**
* Returns an array with locks currently on the node
*
* @return Sabre_DAV_Locks_LockInfo[]
*/
function getLocks();
/**
* Creates a new lock on the file.
*
* @param Sabre_DAV_Locks_LockInfo $lockInfo The lock information
* @return void
*/
function lock(Sabre_DAV_Locks_LockInfo $lockInfo);
/**
* Unlocks a file
*
* @param Sabre_DAV_Locks_LockInfo $lockInfo The lock information
* @return void
*/
function unlock(Sabre_DAV_Locks_LockInfo $lockInfo);
}
@@ -0,0 +1,44 @@
<?php
/**
* The INode interface is the base interface, and the parent class of both ICollection and IFile
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
interface Sabre_DAV_INode {
/**
* Deleted the current node
*
* @return void
*/
function delete();
/**
* Returns the name of the node
*
* @return string
*/
function getName();
/**
* Renames the node
*
* @param string $name The new name
* @return void
*/
function setName($name);
/**
* Returns the last modification time, as a unix timestamp
*
* @return int
*/
function getLastModified();
}
@@ -0,0 +1,67 @@
<?php
/**
* IProperties interface
*
* Implement this interface to support custom WebDAV properties requested and sent from clients.
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
interface Sabre_DAV_IProperties extends Sabre_DAV_INode {
/**
* Updates properties on this node,
*
* The properties array uses the propertyName in clark-notation as key,
* and the array value for the property value. In the case a property
* should be deleted, the property value will be null.
*
* This method must be atomic. If one property cannot be changed, the
* entire operation must fail.
*
* If the operation was successful, true can be returned.
* If the operation failed, false can be returned.
*
* Deletion of a non-existant property is always succesful.
*
* Lastly, it is optional to return detailed information about any
* failures. In this case an array should be returned with the following
* structure:
*
* array(
* 403 => array(
* '{DAV:}displayname' => null,
* ),
* 424 => array(
* '{DAV:}owner' => null,
* )
* )
*
* In this example it was forbidden to update {DAV:}displayname.
* (403 Forbidden), which in turn also caused {DAV:}owner to fail
* (424 Failed Dependency) because the request needs to be atomic.
*
* @param array $mutations
* @return bool|array
*/
function updateProperties($properties);
/**
* Returns a list of properties for this nodes.
*
* The properties list is a list of propertynames the client requested,
* encoded in clark-notation {xmlnamespace}tagname
*
* If the array is empty, it means 'all properties' were requested.
*
* @param array $properties
* @return void
*/
function getProperties($properties);
}
@@ -0,0 +1,27 @@
<?php
/**
* IQuota interface
*
* Implement this interface to add the ability to return quota information. The ObjectTree
* will check for quota information on any given node. If the information is not available it will
* attempt to fetch the information from the root node.
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
interface Sabre_DAV_IQuota extends Sabre_DAV_ICollection {
/**
* Returns the quota information
*
* This method MUST return an array with 2 values, the first being the total used space,
* the second the available space (in bytes)
*/
function getQuotaInfo();
}
@@ -0,0 +1,46 @@
<?php
/**
* The Lock manager allows you to handle all file-locks centrally.
*
* This is an alternative approach to doing this on a per-node basis
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
abstract class Sabre_DAV_Locks_Backend_Abstract {
/**
* Returns a list of Sabre_DAV_Locks_LockInfo objects
*
* This method should return all the locks for a particular uri, including
* locks that might be set on a parent uri.
*
* @param string $uri
* @return array
*/
abstract function getLocks($uri);
/**
* Locks a uri
*
* @param string $uri
* @param Sabre_DAV_Locks_LockInfo $lockInfo
* @return bool
*/
abstract function lock($uri,Sabre_DAV_Locks_LockInfo $lockInfo);
/**
* Removes a lock from a uri
*
* @param string $uri
* @param Sabre_DAV_Locks_LockInfo $lockInfo
* @return bool
*/
abstract function unlock($uri,Sabre_DAV_Locks_LockInfo $lockInfo);
}
@@ -0,0 +1,180 @@
<?php
/**
* The Lock manager allows you to handle all file-locks centrally.
*
* This Lock Manager stores all its data in the filesystem. By default it will do this in PHP's standard temporary session directory,
* but this can be overriden by specifiying an alternative path in the contructor
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Locks_Backend_FS extends Sabre_DAV_Locks_Backend_Abstract {
/**
* The default data directory
*
* @var string
*/
private $dataDir;
public function __construct($dataDir) {
$this->dataDir = $dataDir;
}
protected function getFileNameForUri($uri) {
return $this->dataDir . '/sabredav_' . md5($uri) . '.locks';
}
/**
* Returns a list of Sabre_DAV_Locks_LockInfo objects
*
* This method should return all the locks for a particular uri, including
* locks that might be set on a parent uri.
*
* @param string $uri
* @return array
*/
public function getLocks($uri) {
$lockList = array();
$currentPath = '';
foreach(explode('/',$uri) as $uriPart) {
// weird algorithm that can probably be improved, but we're traversing the path top down
if ($currentPath) $currentPath.='/';
$currentPath.=$uriPart;
$uriLocks = $this->getData($currentPath);
foreach($uriLocks as $uriLock) {
// Unless we're on the leaf of the uri-tree we should ingore locks with depth 0
if($uri==$currentPath || $uriLock->depth!=0) {
$uriLock->uri = $currentPath;
$lockList[] = $uriLock;
}
}
}
// Checking if we can remove any of these locks
foreach($lockList as $k=>$lock) {
if (time() > $lock->timeout + $lock->created) unset($lockList[$k]);
}
return $lockList;
}
/**
* Locks a uri
*
* @param string $uri
* @param Sabre_DAV_Locks_LockInfo $lockInfo
* @return bool
*/
public function lock($uri,Sabre_DAV_Locks_LockInfo $lockInfo) {
// We're making the lock timeout 30 minutes
$lockInfo->timeout = 1800;
$lockInfo->created = time();
$locks = $this->getLocks($uri);
foreach($locks as $k=>$lock) {
if ($lock->token == $lockInfo->token) unset($locks[$k]);
}
$locks[] = $lockInfo;
$this->putData($uri,$locks);
return true;
}
/**
* Removes a lock from a uri
*
* @param string $uri
* @param Sabre_DAV_Locks_LockInfo $lockInfo
* @return bool
*/
public function unlock($uri,Sabre_DAV_Locks_LockInfo $lockInfo) {
$locks = $this->getLocks($uri);
foreach($locks as $k=>$lock) {
if ($lock->token == $lockInfo->token) {
unset($locks[$k]);
$this->putData($uri,$locks);
return true;
}
}
return false;
}
/**
* Returns the stored data for a uri
*
* @param string $uri
* @return array
*/
protected function getData($uri) {
$path = $this->getFilenameForUri($uri);
if (!file_exists($path)) return array();
// opening up the file, and creating a shared lock
$handle = fopen($path,'r');
flock($handle,LOCK_SH);
$data = '';
// Reading data until the eof
while(!feof($handle)) {
$data.=fread($handle,8192);
}
// We're all good
fclose($handle);
// Unserializing and checking if the resource file contains data for this file
$data = unserialize($data);
if (!$data) return array();
return $data;
}
/**
* Updates the lock information
*
* @param string $uri
* @param array $newData
* @return void
*/
protected function putData($uri,array $newData) {
$path = $this->getFileNameForUri($uri);
// opening up the file, and creating a shared lock
$handle = fopen($path,'a+');
flock($handle,LOCK_EX);
ftruncate($handle,0);
rewind($handle);
fwrite($handle,serialize($newData));
fclose($handle);
}
}
@@ -0,0 +1,141 @@
<?php
/**
* The Lock manager allows you to handle all file-locks centrally.
*
* This Lock Manager stores all its data in a database. You must pass a PDO
* connection object in the constructor.
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Locks_Backend_PDO extends Sabre_DAV_Locks_Backend_Abstract {
/**
* The PDO connection object
*
* @var pdo
*/
private $pdo;
public function __construct(PDO $pdo) {
$this->pdo = $pdo;
}
/**
* Returns a list of Sabre_DAV_Locks_LockInfo objects
*
* This method should return all the locks for a particular uri, including
* locks that might be set on a parent uri.
*
* @param string $uri
* @return array
*/
public function getLocks($uri) {
// NOTE: the following 10 lines or so could be easily replaced by
// pure sql. MySQL's non-standard string concatination prevents us
// from doing this though.
$query = 'SELECT owner, token, timeout, created, scope, depth, uri FROM locks WHERE ((created + timeout) > CAST(? AS UNSIGNED INTEGER)) AND ((uri = ?)';
$params = array(time(),$uri);
// We need to check locks for every part in the uri.
$uriParts = explode('/',$uri);
// We already covered the last part of the uri
array_pop($uriParts);
$currentPath='';
foreach($uriParts as $part) {
if ($currentPath) $currentPath.='/';
$currentPath.=$part;
$query.=' OR (depth!=0 AND uri = ?)';
$params[] = $currentPath;
}
$query.=')';
$stmt = $this->pdo->prepare($query);
$stmt->execute($params);
$result = $stmt->fetchAll();
$lockList = array();
foreach($result as $row) {
$lockInfo = new Sabre_DAV_Locks_LockInfo();
$lockInfo->owner = $row['owner'];
$lockInfo->token = $row['token'];
$lockInfo->timeout = $row['timeout'];
$lockInfo->created = $row['created'];
$lockInfo->scope = $row['scope'];
$lockInfo->depth = $row['depth'];
$lockInfo->uri = $row['uri'];
$lockList[] = $lockInfo;
}
return $lockList;
}
/**
* Locks a uri
*
* @param string $uri
* @param Sabre_DAV_Locks_LockInfo $lockInfo
* @return bool
*/
public function lock($uri,Sabre_DAV_Locks_LockInfo $lockInfo) {
// We're making the lock timeout 30 minutes
$lockInfo->timeout = 30*60;
$lockInfo->created = time();
$lockInfo->uri = $uri;
$locks = $this->getLocks($uri);
$exists = false;
foreach($locks as $k=>$lock) {
if ($lock->token == $lockInfo->token) $exists = true;
}
if ($exists) {
$stmt = $this->pdo->prepare('UPDATE locks SET owner = ?, timeout = ?, scope = ?, depth = ?, uri = ?, created = ? WHERE token = ?');
$stmt->execute(array($lockInfo->owner,$lockInfo->timeout,$lockInfo->scope,$lockInfo->depth,$uri,$lockInfo->created,$lockInfo->token));
} else {
$stmt = $this->pdo->prepare('INSERT INTO locks (owner,timeout,scope,depth,uri,created,token) VALUES (?,?,?,?,?,?,?)');
$stmt->execute(array($lockInfo->owner,$lockInfo->timeout,$lockInfo->scope,$lockInfo->depth,$uri,$lockInfo->created,$lockInfo->token));
}
return true;
}
/**
* Removes a lock from a uri
*
* @param string $uri
* @param Sabre_DAV_Locks_LockInfo $lockInfo
* @return bool
*/
public function unlock($uri,Sabre_DAV_Locks_LockInfo $lockInfo) {
$stmt = $this->pdo->prepare('DELETE FROM locks WHERE uri = ? AND token = ?');
$stmt->execute(array($uri,$lockInfo->token));
return $stmt->rowCount()===1;
}
}
@@ -0,0 +1,10 @@
<html>
<head><title>IP.Board - Bulletin Board System</title></head>
<body>
<h1>403: IP.Board -&gt; Forbidden</h1>
<hr>
You have reached this page in error, please use your back button to return to the forum.
<hr>
<a href="http://www.invisionpower.com/">IP.Board</a>
</body>
</html>
@@ -0,0 +1,81 @@
<?php
/**
* LockInfo class
*
* An object of the LockInfo class holds all the information relevant to a
* single lock.
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Locks_LockInfo {
/**
* A shared lock
*/
const SHARED = 1;
/**
* An exclusive lock
*/
const EXCLUSIVE = 2;
/**
* A never expiring timeout
*/
const TIMEOUT_INFINITE = -1;
/**
* The owner of the lock
*
* @var string
*/
public $owner;
/**
* The locktoken
*
* @var string
*/
public $token;
/**
* How long till the lock is expiring
*
* @var int
*/
public $timeout;
/**
* UNIX Timestamp of when this lock was created
*
* @var int
*/
public $created;
/**
* Exclusive or shared lock
*
* @var int
*/
public $scope = self::EXCLUSIVE;
/**
* Depth of lock, can be 0 or Sabre_DAV_Server::DEPTH_INFINITY
*/
public $depth = 0;
/**
* The uri this lock locks
*
* TODO: This value is not always set
* @var mixed
*/
public $uri;
}
@@ -0,0 +1,653 @@
<?php
/**
* Locking plugin
*
* This plugin provides locking support to a WebDAV server.
* The easiest way to get started, is by hooking it up as such:
*
* $lockBackend = new Sabre_DAV_Locks_Backend_FS('./my_lock_directory');
* $lockPlugin = new Sabre_DAV_Locks_Plugin($lockBackend);
* $server->addPlugin($lockPlugin);
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Locks_Plugin extends Sabre_DAV_ServerPlugin {
/**
* locksBackend
*
* @var Sabre_DAV_Locks_Backend_Abstract
*/
private $locksBackend;
/**
* server
*
* @var Sabre_DAV_Server
*/
private $server;
/**
* __construct
*
* @param Sabre_DAV_Locks_Backend_Abstract $locksBackend
* @return void
*/
public function __construct(Sabre_DAV_Locks_Backend_Abstract $locksBackend = null) {
$this->locksBackend = $locksBackend;
}
/**
* Initializes the plugin
*
* This method is automatically called by the Server class after addPlugin.
*
* @param Sabre_DAV_Server $server
* @return void
*/
public function initialize(Sabre_DAV_Server $server) {
$this->server = $server;
$server->subscribeEvent('unknownMethod',array($this,'unknownMethod'));
$server->subscribeEvent('beforeMethod',array($this,'beforeMethod'),50);
$server->subscribeEvent('afterGetProperties',array($this,'afterGetProperties'));
}
/**
* This method is called by the Server if the user used an HTTP method
* the server didn't recognize.
*
* This plugin intercepts the LOCK and UNLOCK methods.
*
* @param string $method
* @return bool
*/
public function unknownMethod($method, $uri) {
switch($method) {
case 'LOCK' : $this->httpLock($uri); return false;
case 'UNLOCK' : $this->httpUnlock($uri); return false;
}
}
/**
* This method is called after most properties have been found
* it allows us to add in any Lock-related properties
*
* @param string $path
* @param array $properties
* @return bool
*/
public function afterGetProperties($path,&$newProperties) {
foreach($newProperties[404] as $propName=>$discard) {
$node = null;
switch($propName) {
case '{DAV:}supportedlock' :
$val = false;
if ($this->locksBackend) $val = true;
else {
if (!$node) $node = $this->server->tree->getNodeForPath($path);
if ($node instanceof Sabre_DAV_ILockable) $val = true;
}
$newProperties[200][$propName] = new Sabre_DAV_Property_SupportedLock($val);
unset($newProperties[404][$propName]);
break;
case '{DAV:}lockdiscovery' :
$newProperties[200][$propName] = new Sabre_DAV_Property_LockDiscovery($this->getLocks($path));
unset($newProperties[404][$propName]);
break;
}
}
return true;
}
/**
* This method is called before the logic for any HTTP method is
* handled.
*
* This plugin uses that feature to intercept access to locked resources.
*
* @param string $method
* @param string $uri
* @return bool
*/
public function beforeMethod($method, $uri) {
switch($method) {
case 'DELETE' :
case 'MKCOL' :
case 'PROPPATCH' :
case 'PUT' :
$lastLock = null;
if (!$this->validateLock($uri,$lastLock))
throw new Sabre_DAV_Exception_Locked($lastLock);
break;
case 'MOVE' :
$lastLock = null;
if (!$this->validateLock(array(
$uri,
$this->server->calculateUri($this->server->httpRequest->getHeader('Destination')),
),$lastLock))
throw new Sabre_DAV_Exception_Locked($lastLock);
break;
case 'COPY' :
$lastLock = null;
if (!$this->validateLock(
$this->server->calculateUri($this->server->httpRequest->getHeader('Destination')),
$lastLock))
throw new Sabre_DAV_Exception_Locked($lastLock);
break;
}
return true;
}
/**
* Use this method to tell the server this plugin defines additional
* HTTP methods.
*
* This method is passed a uri. It should only return HTTP methods that are
* available for the specified uri.
*
* @param string $uri
* @return array
*/
public function getHTTPMethods($uri) {
if ($this->locksBackend ||
$this->server->tree->getNodeForPath($uri) instanceof Sabre_DAV_ILocks) {
return array('LOCK','UNLOCK');
}
return array();
}
/**
* Returns a list of features for the HTTP OPTIONS Dav: header.
*
* In this case this is only the number 2. The 2 in the Dav: header
* indicates the server supports locks.
*
* @return array
*/
public function getFeatures() {
return array(2);
}
/**
* Returns all lock information on a particular uri
*
* This function should return an array with Sabre_DAV_Locks_LockInfo objects. If there are no locks on a file, return an empty array.
*
* Additionally there is also the possibility of locks on parent nodes, so we'll need to traverse every part of the tree
*
* @param string $uri
* @return array
*/
public function getLocks($uri) {
$lockList = array();
$currentPath = '';
foreach(explode('/',$uri) as $uriPart) {
$uriLocks = array();
if ($currentPath) $currentPath.='/';
$currentPath.=$uriPart;
try {
$node = $this->server->tree->getNodeForPath($currentPath);
if ($node instanceof Sabre_DAV_ILockable) $uriLocks = $node->getLocks();
} catch (Sabre_DAV_Exception_FileNotFound $e){
// In case the node didn't exist, this could be a lock-null request
}
foreach($uriLocks as $uriLock) {
// Unless we're on the leaf of the uri-tree we should ingore locks with depth 0
if($uri==$currentPath || $uriLock->depth!=0) {
$uriLock->uri = $currentPath;
$lockList[] = $uriLock;
}
}
}
if ($this->locksBackend) $lockList = array_merge($lockList,$this->locksBackend->getLocks($uri));
return $lockList;
}
/**
* Locks an uri
*
* The WebDAV lock request can be operated to either create a new lock on a file, or to refresh an existing lock
* If a new lock is created, a full XML body should be supplied, containing information about the lock such as the type
* of lock (shared or exclusive) and the owner of the lock
*
* If a lock is to be refreshed, no body should be supplied and there should be a valid If header containing the lock
*
* Additionally, a lock can be requested for a non-existant file. In these case we're obligated to create an empty file as per RFC4918:S7.3
*
* @param string $uri
* @return void
*/
protected function httpLock($uri) {
$lastLock = null;
if (!$this->validateLock($uri,$lastLock)) {
// If the existing lock was an exclusive lock, we need to fail
if (!$lastLock || $lastLock->scope == Sabre_DAV_Locks_LockInfo::EXCLUSIVE) {
//var_dump($lastLock);
throw new Sabre_DAV_Exception_ConflictingLock($lastLock);
}
}
if ($body = $this->server->httpRequest->getBody(true)) {
// This is a new lock request
$lockInfo = $this->parseLockRequest($body);
$lockInfo->depth = $this->server->getHTTPDepth();
$lockInfo->uri = $uri;
if($lastLock && $lockInfo->scope != Sabre_DAV_Locks_LockInfo::SHARED) throw new Sabre_DAV_Exception_ConflictingLock($lastLock);
} elseif ($lastLock) {
// This must have been a lock refresh
$lockInfo = $lastLock;
// The resource could have been locked through another uri.
if ($uri!=$lockInfo->uri) $uri = $lockInfo->uri;
} else {
// There was neither a lock refresh nor a new lock request
throw new Sabre_DAV_Exception_BadRequest('An xml body is required for lock requests');
}
if ($timeout = $this->getTimeoutHeader()) $lockInfo->timeout = $timeout;
$newFile = false;
// If we got this far.. we should go check if this node actually exists. If this is not the case, we need to create it first
try {
$node = $this->server->tree->getNodeForPath($uri);
// We need to call the beforeWriteContent event for RFC3744
$this->server->broadcastEvent('beforeWriteContent',array($uri));
} catch (Sabre_DAV_Exception_FileNotFound $e) {
// It didn't, lets create it
$this->server->createFile($uri,fopen('php://memory','r'));
$newFile = true;
}
$this->lockNode($uri,$lockInfo);
$this->server->httpResponse->setHeader('Content-Type','application/xml; charset=utf-8');
$this->server->httpResponse->setHeader('Lock-Token','<opaquelocktoken:' . $lockInfo->token . '>');
$this->server->httpResponse->sendStatus($newFile?201:200);
$this->server->httpResponse->sendBody($this->generateLockResponse($lockInfo));
}
/**
* Unlocks a uri
*
* This WebDAV method allows you to remove a lock from a node. The client should provide a valid locktoken through the Lock-token http header
* The server should return 204 (No content) on success
*
* @param string $uri
* @return void
*/
protected function httpUnlock($uri) {
$lockToken = $this->server->httpRequest->getHeader('Lock-Token');
// If the locktoken header is not supplied, we need to throw a bad request exception
if (!$lockToken) throw new Sabre_DAV_Exception_BadRequest('No lock token was supplied');
$locks = $this->getLocks($uri);
// We're grabbing the node information, just to rely on the fact it will throw a 404 when the node doesn't exist
//$this->server->tree->getNodeForPath($uri);
foreach($locks as $lock) {
if ('<opaquelocktoken:' . $lock->token . '>' == $lockToken) {
$this->unlockNode($uri,$lock);
$this->server->httpResponse->setHeader('Content-Length','0');
$this->server->httpResponse->sendStatus(204);
return;
}
}
// If we got here, it means the locktoken was invalid
throw new Sabre_DAV_Exception_LockTokenMatchesRequestUri();
}
/**
* Locks a uri
*
* All the locking information is supplied in the lockInfo object. The object has a suggested timeout, but this can be safely ignored
* It is important that if the existing timeout is ignored, the property is overwritten, as this needs to be sent back to the client
*
* @param string $uri
* @param Sabre_DAV_Locks_LockInfo $lockInfo
* @return void
*/
public function lockNode($uri,Sabre_DAV_Locks_LockInfo $lockInfo) {
if (!$this->server->broadcastEvent('beforeLock',array($uri,$lockInfo))) return;
try {
$node = $this->server->tree->getNodeForPath($uri);
if ($node instanceof Sabre_DAV_ILockable) return $node->lock($lockInfo);
} catch (Sabre_DAV_Exception_FileNotFound $e) {
// In case the node didn't exist, this could be a lock-null request
}
if ($this->locksBackend) return $this->locksBackend->lock($uri,$lockInfo);
throw new Sabre_DAV_Exception_MethodNotAllowed('Locking support is not enabled for this resource. No Locking backend was found so if you didn\'t expect this error, please check your configuration.');
}
/**
* Unlocks a uri
*
* This method removes a lock from a uri. It is assumed all the supplied information is correct and verified
*
* @param string $uri
* @param Sabre_DAV_Locks_LockInfo $lockInfo
* @return void
*/
public function unlockNode($uri,Sabre_DAV_Locks_LockInfo $lockInfo) {
if (!$this->server->broadcastEvent('beforeUnlock',array($uri,$lockInfo))) return;
try {
$node = $this->server->tree->getNodeForPath($uri);
if ($node instanceof Sabre_DAV_ILockable) return $node->unlock($lockInfo);
} catch (Sabre_DAV_Exception_FileNotFound $e) {
// In case the node didn't exist, this could be a lock-null request
}
if ($this->locksBackend) return $this->locksBackend->unlock($uri,$lockInfo);
}
/**
* Returns the contents of the HTTP Timeout header.
*
* The method formats the header into an integer.
*
* @return int
*/
public function getTimeoutHeader() {
$header = $this->server->httpRequest->getHeader('Timeout');
if ($header) {
if (stripos($header,'second-')===0) $header = (int)(substr($header,7));
else if (strtolower($header)=='infinite') $header=Sabre_DAV_Locks_LockInfo::TIMEOUT_INFINITE;
else throw new Sabre_DAV_Exception_BadRequest('Invalid HTTP timeout header');
} else {
$header = 0;
}
return $header;
}
/**
* Generates the response for successfull LOCK requests
*
* @param Sabre_DAV_Locks_LockInfo $lockInfo
* @return string
*/
protected function generateLockResponse(Sabre_DAV_Locks_LockInfo $lockInfo) {
$dom = new DOMDocument('1.0','utf-8');
$dom->formatOutput = true;
$prop = $dom->createElementNS('DAV:','d:prop');
$dom->appendChild($prop);
$lockDiscovery = $dom->createElementNS('DAV:','d:lockdiscovery');
$prop->appendChild($lockDiscovery);
$lockObj = new Sabre_DAV_Property_LockDiscovery(array($lockInfo),true);
$lockObj->serialize($this->server,$lockDiscovery);
return $dom->saveXML();
}
/**
* validateLock should be called when a write operation is about to happen
* It will check if the requested url is locked, and see if the correct lock tokens are passed
*
* @param mixed $urls List of relevant urls. Can be an array, a string or nothing at all for the current request uri
* @param mixed $lastLock This variable will be populated with the last checked lock object (Sabre_DAV_Locks_LockInfo)
* @return bool
*/
protected function validateLock($urls = null,&$lastLock = null) {
if (is_null($urls)) {
$urls = array($this->server->getRequestUri());
} elseif (is_string($urls)) {
$urls = array($urls);
} elseif (!is_array($urls)) {
throw new Sabre_DAV_Exception('The urls parameter should either be null, a string or an array');
}
$conditions = $this->getIfConditions();
// We're going to loop through the urls and make sure all lock conditions are satisfied
foreach($urls as $url) {
$locks = $this->getLocks($url);
// If there were no conditions, but there were locks, we fail
if (!$conditions && $locks) {
reset($locks);
$lastLock = current($locks);
return false;
}
// If there were no locks or conditions, we go to the next url
if (!$locks && !$conditions) continue;
foreach($conditions as $condition) {
$conditionUri = $condition['uri']?$this->server->calculateUri($condition['uri']):'';
// If the condition has a url, and it isn't part of the affected url at all, check the next condition
if ($conditionUri && strpos($url,$conditionUri)!==0) continue;
// The tokens array contians arrays with 2 elements. 0=true/false for normal/not condition, 1=locktoken
// At least 1 condition has to be satisfied
foreach($condition['tokens'] as $conditionToken) {
$etagValid = true;
$lockValid = true;
// key 2 can contain an etag
if ($conditionToken[2]) {
$uri = $conditionUri?$conditionUri:$this->server->getRequestUri();
$node = $this->server->tree->getNodeForPath($uri);
$etagValid = $node->getETag()==$conditionToken[2];
}
// key 1 can contain a lock token
if ($conditionToken[1]) {
$lockValid = false;
// Match all the locks
foreach($locks as $lockIndex=>$lock) {
$lockToken = 'opaquelocktoken:' . $lock->token;
// Checking NOT
if (!$conditionToken[0] && $lockToken != $conditionToken[1]) {
// Condition valid, onto the next
$lockValid = true;
break;
}
if ($conditionToken[0] && $lockToken == $conditionToken[1]) {
$lastLock = $lock;
// Condition valid and lock matched
unset($locks[$lockIndex]);
$lockValid = true;
break;
}
}
}
// If, after checking both etags and locks they are stil valid,
// we can continue with the next condition.
if ($etagValid && $lockValid) continue 2;
}
// No conditions matched, so we fail
throw new Sabre_DAV_Exception_PreconditionFailed('The tokens provided in the if header did not match','If');
}
// Conditions were met, we'll also need to check if all the locks are gone
if (count($locks)) {
reset($locks);
// There's still locks, we fail
$lastLock = current($locks);
return false;
}
}
// We got here, this means every condition was satisfied
return true;
}
/**
* This method is created to extract information from the WebDAV HTTP 'If:' header
*
* The If header can be quite complex, and has a bunch of features. We're using a regex to extract all relevant information
* The function will return an array, containg structs with the following keys
*
* * uri - the uri the condition applies to. This can be an empty string for 'every relevant url'
* * tokens - The lock token. another 2 dimensional array containg 2 elements (0 = true/false.. If this is a negative condition its set to false, 1 = the actual token)
* * etag - an etag, if supplied
*
* @return void
*/
public function getIfConditions() {
$header = $this->server->httpRequest->getHeader('If');
if (!$header) return array();
$matches = array();
$regex = '/(?:\<(?P<uri>.*?)\>\s)?\((?P<not>Not\s)?(?:\<(?P<token>[^\>]*)\>)?(?:\s?)(?:\[(?P<etag>[^\]]*)\])?\)/im';
preg_match_all($regex,$header,$matches,PREG_SET_ORDER);
$conditions = array();
foreach($matches as $match) {
$condition = array(
'uri' => $match['uri'],
'tokens' => array(
array($match['not']?0:1,$match['token'],isset($match['etag'])?$match['etag']:'')
),
);
if (!$condition['uri'] && count($conditions)) $conditions[count($conditions)-1]['tokens'][] = array(
$match['not']?0:1,
$match['token'],
isset($match['etag'])?$match['etag']:''
);
else {
$conditions[] = $condition;
}
}
return $conditions;
}
/**
* Parses a webdav lock xml body, and returns a new Sabre_DAV_Locks_LockInfo object
*
* @param string $body
* @return Sabre_DAV_Locks_LockInfo
*/
protected function parseLockRequest($body) {
$xml = simplexml_load_string($body,null,LIBXML_NOWARNING);
$xml->registerXPathNamespace('d','DAV:');
$lockInfo = new Sabre_DAV_Locks_LockInfo();
$lockInfo->owner = (string)$xml->owner;
$lockToken = '44445502';
$id = md5(microtime() . 'somethingrandom');
$lockToken.='-' . substr($id,0,4) . '-' . substr($id,4,4) . '-' . substr($id,8,4) . '-' . substr($id,12,12);
$lockInfo->token = $lockToken;
$lockInfo->scope = count($xml->xpath('d:lockscope/d:exclusive'))>0?Sabre_DAV_Locks_LockInfo::EXCLUSIVE:Sabre_DAV_Locks_LockInfo::SHARED;
return $lockInfo;
}
}
@@ -0,0 +1,10 @@
<html>
<head><title>IP.Board - Bulletin Board System</title></head>
<body>
<h1>403: IP.Board -&gt; Forbidden</h1>
<hr>
You have reached this page in error, please use your back button to return to the forum.
<hr>
<a href="http://www.invisionpower.com/">IP.Board</a>
</body>
</html>
@@ -0,0 +1,79 @@
<?php
/**
* This plugin provides support for RFC4709: Mounting WebDAV servers
*
* Simply append ?mount to any collection to generate the davmount response.
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
*/
class Sabre_DAV_Mount_Plugin extends Sabre_DAV_ServerPlugin {
/**
* Reference to Server class
*
* @var Sabre_DAV_Server
*/
private $server;
/**
* Initializes the plugin and registers event handles
*
* @param Sabre_DAV_Server $server
* @return void
*/
public function initialize(Sabre_DAV_Server $server) {
$this->server = $server;
$this->server->subscribeEvent('beforeMethod',array($this,'beforeMethod'), 90);
}
/**
* 'beforeMethod' event handles. This event handles intercepts GET requests ending
* with ?mount
*
* @param string $method
* @return void
*/
public function beforeMethod($method, $uri) {
if ($method!='GET') return;
if ($this->server->httpRequest->getQueryString()!='mount') return;
$currentUri = $this->server->httpRequest->getAbsoluteUri();
// Stripping off everything after the ?
list($currentUri) = explode('?',$currentUri);
$this->davMount($currentUri);
// Returning false to break the event chain
return false;
}
/**
* Generates the davmount response
*
* @param string $uri absolute uri
* @return void
*/
public function davMount($uri) {
$this->server->httpResponse->sendStatus(200);
$this->server->httpResponse->setHeader('Content-Type','application/davmount+xml');
ob_start();
echo '<?xml version="1.0"?>', "\n";
echo "<dm:mount xmlns:dm=\"http://purl.org/NET/webdav/mount\">\n";
echo " <dm:url>", htmlspecialchars($uri, ENT_NOQUOTES, 'UTF-8'), "</dm:url>\n";
echo "</dm:mount>";
$this->server->httpResponse->sendBody(ob_get_clean());
}
}
@@ -0,0 +1,10 @@
<html>
<head><title>IP.Board - Bulletin Board System</title></head>
<body>
<h1>403: IP.Board -&gt; Forbidden</h1>
<hr>
You have reached this page in error, please use your back button to return to the forum.
<hr>
<a href="http://www.invisionpower.com/">IP.Board</a>
</body>
</html>
@@ -0,0 +1,55 @@
<?php
/**
* Node class
*
* This is a helper class, that should aid in getting nodes setup.
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
abstract class Sabre_DAV_Node implements Sabre_DAV_INode {
/**
* Returns the last modification time
*
* In this case, it will simply return the current time
*
* @return int
*/
public function getLastModified() {
return time();
}
/**
* Deleted the current node
*
* @throws Sabre_DAV_Exception_Forbidden
* @return void
*/
public function delete() {
throw new Sabre_DAV_Exception_Forbidden('Permission denied to delete node');
}
/**
* Renames the node
*
* @throws Sabre_DAV_Exception_Forbidden
* @param string $name The new name
* @return void
*/
public function setName($name) {
throw new Sabre_DAV_Exception_Forbidden('Permission denied to rename file');
}
}
@@ -0,0 +1,149 @@
<?php
/**
* ObjectTree class
*
* This implementation of the Tree class makes use of the INode, IFile and ICollection API's
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_ObjectTree extends Sabre_DAV_Tree {
/**
* The root node
*
* @var Sabre_DAV_ICollection
*/
protected $rootNode;
/**
* This is the node cache. Accessed nodes are stored here
*
* @var array
*/
protected $cache = array();
/**
* Creates the object
*
* This method expects the rootObject to be passed as a parameter
*
* @param Sabre_DAV_ICollection $rootNode
* @return void
*/
public function __construct(Sabre_DAV_ICollection $rootNode) {
$this->rootNode = $rootNode;
}
/**
* Returns the INode object for the requested path
*
* @param string $path
* @return Sabre_DAV_INode
*/
public function getNodeForPath($path) {
$path = trim($path,'/');
if (isset($this->cache[$path])) return $this->cache[$path];
//if (!$path || $path=='.') return $this->rootNode;
$currentNode = $this->rootNode;
$i=0;
// We're splitting up the path variable into folder/subfolder components and traverse to the correct node..
foreach(explode('/',$path) as $pathPart) {
// If this part of the path is just a dot, it actually means we can skip it
if ($pathPart=='.' || $pathPart=='') continue;
if (!($currentNode instanceof Sabre_DAV_ICollection))
throw new Sabre_DAV_Exception_FileNotFound('Could not find node at path: ' . $path);
$currentNode = $currentNode->getChild($pathPart);
}
$this->cache[$path] = $currentNode;
return $currentNode;
}
/**
* This function allows you to check if a node exists.
*
* @param string $path
* @return bool
*/
public function nodeExists($path) {
try {
list($parent, $base) = Sabre_DAV_URLUtil::splitPath($path);
$parentNode = $this->getNodeForPath($parent);
return $parentNode->childExists($base);
} catch (Sabre_DAV_Exception_FileNotFound $e) {
return false;
}
}
/**
* Returns a list of childnodes for a given path.
*
* @param string $path
* @return array
*/
public function getChildren($path) {
$node = $this->getNodeForPath($path);
$children = $node->getChildren();
foreach($children as $child) {
$this->cache[trim($path,'/') . '/' . $child->getName()] = $child;
}
return $children;
}
/**
* This method is called with every tree update
*
* Examples of tree updates are:
* * node deletions
* * node creations
* * copy
* * move
* * renaming nodes
*
* If Tree classes implement a form of caching, this will allow
* them to make sure caches will be expired.
*
* If a path is passed, it is assumed that the entire subtree is dirty
*
* @param string $path
* @return void
*/
public function markDirty($path) {
// We don't care enough about sub-paths
// flushing the entire cache
$path = trim($path,'/');
foreach($this->cache as $nodePath=>$node) {
if ($nodePath == $path || strpos($nodePath,$path.'/')===0)
unset($this->cache[$nodePath]);
}
}
}
@@ -0,0 +1,25 @@
<?php
/**
* Abstract property class
*
* Extend this class to create custom complex properties
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
abstract class Sabre_DAV_Property {
abstract function serialize(Sabre_DAV_Server $server, DOMElement $prop);
static function unserialize(DOMElement $prop) {
return null;
}
}
@@ -0,0 +1,75 @@
<?php
/**
* This property represents the {DAV:}getlastmodified property.
*
* Although this is normally a simple property, windows requires us to add
* some new attributes.
*
* This class uses unix timestamps internally, and converts them to RFC 1123 times for
* serialization
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Property_GetLastModified extends Sabre_DAV_Property {
/**
* time
*
* @var int
*/
public $time;
/**
* __construct
*
* @param int|DateTime $time
* @return void
*/
public function __construct($time) {
if ($time instanceof DateTime) {
$this->time = $time;
} elseif (is_int($time) || ctype_digit($time)) {
$this->time = new DateTime('@' . $time);
} else {
$this->time = new DateTime($time);
}
// Setting timezone to UTC
$this->time->setTimezone(new DateTimeZone('UTC'));
}
/**
* serialize
*
* @param DOMElement $prop
* @return void
*/
public function serialize(Sabre_DAV_Server $server, DOMElement $prop) {
$doc = $prop->ownerDocument;
$prop->setAttribute('xmlns:b','urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/');
$prop->setAttribute('b:dt','dateTime.rfc1123');
$prop->nodeValue = $this->time->format(DateTime::RFC1123);
}
/**
* getTime
*
* @return DateTime
*/
public function getTime() {
return $this->time;
}
}
@@ -0,0 +1,91 @@
<?php
/**
* Href property
*
* The href property represpents a url within a {DAV:}href element.
* This is used by many WebDAV extensions, but not really within the WebDAV core spec
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Property_Href extends Sabre_DAV_Property implements Sabre_DAV_Property_IHref {
/**
* href
*
* @var string
*/
private $href;
/**
* Automatically prefix the url with the server base directory
*
* @var bool
*/
private $autoPrefix = true;
/**
* __construct
*
* @param string $href
* @return void
*/
public function __construct($href, $autoPrefix = true) {
$this->href = $href;
$this->autoPrefix = $autoPrefix;
}
/**
* Returns the uri
*
* @return string
*/
public function getHref() {
return $this->href;
}
/**
* Serializes this property.
*
* It will additionally prepend the href property with the server's base uri.
*
* @param Sabre_DAV_Server $server
* @param DOMElement $dom
* @return void
*/
public function serialize(Sabre_DAV_Server $server,DOMElement $dom) {
$prefix = $server->xmlNamespaces['DAV:'];
$elem = $dom->ownerDocument->createElement($prefix . ':href');
$elem->nodeValue = ($this->autoPrefix?$server->getBaseUri():'') . $this->href;
$dom->appendChild($elem);
}
/**
* Unserializes this property from a DOM Element
*
* This method returns an instance of this class.
* It will only decode {DAV:}href values. For non-compatible elements null will be returned.
*
* @param DOMElement $dom
* @return Sabre_DAV_Property_Href
*/
static function unserialize(DOMElement $dom) {
if (Sabre_DAV_XMLUtil::toClarkNotation($dom->firstChild)==='{DAV:}href') {
return new self($dom->firstChild->textContent,false);
}
}
}
@@ -0,0 +1,25 @@
<?php
/**
* IHref interface
*
* Any property implementing this interface can expose a related url.
* This is used by certain subsystems to aquire more information about for example
* the owner of a file
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
interface Sabre_DAV_Property_IHref {
/**
* getHref
*
* @return string
*/
function getHref();
}
@@ -0,0 +1,85 @@
<?php
/**
* Represents {DAV:}lockdiscovery property
*
* This property contains all the open locks on a given resource
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Property_LockDiscovery extends Sabre_DAV_Property {
/**
* locks
*
* @var array
*/
public $locks;
/**
* Should we show the locktoken as well?
*
* @var bool
*/
public $revealLockToken;
/**
* __construct
*
* @param array $locks
* @param bool $revealLockToken
* @return void
*/
public function __construct($locks,$revealLockToken = false) {
$this->locks = $locks;
$this->revealLockToken = $revealLockToken;
}
/**
* serialize
*
* @param DOMElement $prop
* @return void
*/
public function serialize(Sabre_DAV_Server $server,DOMElement $prop) {
$doc = $prop->ownerDocument;
foreach($this->locks as $lock) {
$activeLock = $doc->createElementNS('DAV:','d:activelock');
$prop->appendChild($activeLock);
$lockScope = $doc->createElementNS('DAV:','d:lockscope');
$activeLock->appendChild($lockScope);
$lockScope->appendChild($doc->createElementNS('DAV:','d:' . ($lock->scope==Sabre_DAV_Locks_LockInfo::EXCLUSIVE?'exclusive':'shared')));
$lockType = $doc->createElementNS('DAV:','d:locktype');
$activeLock->appendChild($lockType);
$lockType->appendChild($doc->createElementNS('DAV:','d:write'));
$activeLock->appendChild($doc->createElementNS('DAV:','d:depth',($lock->depth == Sabre_DAV_Server::DEPTH_INFINITY?'infinity':$lock->depth)));
$activeLock->appendChild($doc->createElementNS('DAV:','d:timeout','Second-' . $lock->timeout));
if ($this->revealLockToken) {
$lockToken = $doc->createElementNS('DAV:','d:locktoken');
$activeLock->appendChild($lockToken);
$lockToken->appendChild($doc->createElementNS('DAV:','d:href','opaquelocktoken:' . $lock->token));
}
$activeLock->appendChild($doc->createElementNS('DAV:','d:owner',$lock->owner));
}
}
}
@@ -0,0 +1,126 @@
<?php
/**
* Principal property
*
* The principal property represents a principal from RFC3744 (ACL).
* The property can be used to specify a principal or pseudo principals.
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Property_Principal extends Sabre_DAV_Property implements Sabre_DAV_Property_IHref {
/**
* To specify a not-logged-in user, use the UNAUTHENTICTED principal
*/
const UNAUTHENTICATED = 1;
/**
* To specify any principal that is logged in, use AUTHENTICATED
*/
const AUTHENTICATED = 2;
/**
* Specific princpals can be specified with the HREF
*/
const HREF = 3;
/**
* Principal-type
*
* Must be one of the UNAUTHENTICATED, AUTHENTICATED or HREF constants.
*
* @var int
*/
private $type;
/**
* Url to principal
*
* This value is only used for the HREF principal type.
*
* @var string
*/
private $href;
/**
* Creates the property.
*
* The 'type' argument must be one of the type constants defined in this class.
*
* 'href' is only required for the HREF type.
*
* @param int $type
* @param string $href
* @return void
*/
public function __construct($type, $href = null) {
$this->type = $type;
if ($type===self::HREF && is_null($href)) {
throw new Sabre_DAV_Exception('The href argument must be specified for the HREF principal type.');
}
$this->href = $href;
}
/**
* Returns the principal type
*
* @return int
*/
public function getType() {
return $this->type;
}
/**
* Returns the principal uri.
*
* @return string
*/
public function getHref() {
return $this->href;
}
/**
* Serializes the property into a DOMElement.
*
* @param Sabre_DAV_Server $server
* @param DOMElement $node
* @return void
*/
public function serialize(Sabre_DAV_Server $server, DOMElement $node) {
$prefix = $server->xmlNamespaces['DAV:'];
switch($this->type) {
case self::UNAUTHENTICATED :
$node->appendChild(
$node->ownerDocument->createElement($prefix . ':unauthenticated')
);
break;
case self::AUTHENTICATED :
$node->appendChild(
$node->ownerDocument->createElement($prefix . ':authenticated')
);
break;
case self::HREF :
$href = $node->ownerDocument->createElement($prefix . ':href');
$href->nodeValue = $server->getBaseUri() . $this->href;
$node->appendChild($href);
break;
}
}
}
@@ -0,0 +1,80 @@
<?php
/**
* This class represents the {DAV:}resourcetype property
*
* Normally for files this is empty, and for collection {DAV:}collection.
* However, other specs define different values for this.
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Property_ResourceType extends Sabre_DAV_Property {
/**
* resourceType
*
* @var string
*/
public $resourceType = null;
/**
* __construct
*
* @param mixed $resourceType
* @return void
*/
public function __construct($resourceType = null) {
if ($resourceType === Sabre_DAV_Server::NODE_FILE)
$this->resourceType = null;
elseif ($resourceType === Sabre_DAV_Server::NODE_DIRECTORY)
$this->resourceType = '{DAV:}collection';
else
$this->resourceType = $resourceType;
}
/**
* serialize
*
* @param DOMElement $prop
* @return void
*/
public function serialize(Sabre_DAV_Server $server,DOMElement $prop) {
$propName = null;
$rt = $this->resourceType;
if (!is_array($rt)) $rt = array($rt);
foreach($rt as $resourceType) {
if (preg_match('/^{([^}]*)}(.*)$/',$resourceType,$propName)) {
if (isset($server->xmlNamespaces[$propName[1]])) {
$prop->appendChild($prop->ownerDocument->createElement($server->xmlNamespaces[$propName[1]] . ':' . $propName[2]));
} else {
$prop->appendChild($prop->ownerDocument->createElementNS($propName[1],'custom:' . $propName[2]));
}
}
}
}
/**
* Returns the value in clark-notation
*
* For example '{DAV:}collection'
*
* @return string
*/
public function getValue() {
return $this->resourceType;
}
}
@@ -0,0 +1,156 @@
<?php
/**
* Response property
*
* This class represents the {DAV:}response XML element.
* This is used by the Server class to encode individual items within a multistatus
* response.
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Property_Response extends Sabre_DAV_Property implements Sabre_DAV_Property_IHref {
/**
* Url for the response
*
* @var string
*/
private $href;
/**
* Propertylist, ordered by HTTP status code
*
* @var array
*/
private $responseProperties;
/**
* The responseProperties argument is a list of properties
* within an array with keys representing HTTP status codes
*
* @param string $href
* @param array $responseProperties
* @return void
*/
public function __construct($href,array $responseProperties) {
$this->href = $href;
$this->responseProperties = $responseProperties;
}
/**
* Returns the url
*
* @return string
*/
public function getHref() {
return $this->href;
}
/**
* Returns the property list
*
* @return array
*/
public function getResponseProperties() {
return $this->responseProperties;
}
/**
* serialize
*
* @param Sabre_DAV_Server $server
* @param DOMElement $dom
* @return void
*/
public function serialize(Sabre_DAV_Server $server,DOMElement $dom) {
$document = $dom->ownerDocument;
$properties = $this->responseProperties;
$xresponse = $document->createElement('d:response');
$dom->appendChild($xresponse);
$uri = Sabre_DAV_URLUtil::encodePath($this->href);
// Adding the baseurl to the beginning of the url
$uri = $server->getBaseUri() . $uri;
$xresponse->appendChild($document->createElement('d:href',$uri));
// The properties variable is an array containing properties, grouped by
// HTTP status
foreach($properties as $httpStatus=>$propertyGroup) {
// The 'href' is also in this array, and it's special cased.
// We will ignore it
if ($httpStatus=='href') continue;
// If there are no properties in this group, we can also just carry on
if (!count($propertyGroup)) continue;
$xpropstat = $document->createElement('d:propstat');
$xresponse->appendChild($xpropstat);
$xprop = $document->createElement('d:prop');
$xpropstat->appendChild($xprop);
$nsList = $server->xmlNamespaces;
foreach($propertyGroup as $propertyName=>$propertyValue) {
$propName = null;
preg_match('/^{([^}]*)}(.*)$/',$propertyName,$propName);
// special case for empty namespaces
if ($propName[1]=='') {
$currentProperty = $document->createElement($propName[2]);
$xprop->appendChild($currentProperty);
$currentProperty->setAttribute('xmlns','');
} else {
if (!isset($nsList[$propName[1]])) {
$nsList[$propName[1]] = 'x' . count($nsList);
}
// If the namespace was defined in the top-level xml namespaces, it means
// there was already a namespace declaration, and we don't have to worry about it.
if (isset($server->xmlNamespaces[$propName[1]])) {
$currentProperty = $document->createElement($nsList[$propName[1]] . ':' . $propName[2]);
} else {
$currentProperty = $document->createElementNS($propName[1],$nsList[$propName[1]].':' . $propName[2]);
}
$xprop->appendChild($currentProperty);
}
if (is_scalar($propertyValue)) {
$text = $document->createTextNode($propertyValue);
$currentProperty->appendChild($text);
} elseif ($propertyValue instanceof Sabre_DAV_Property) {
$propertyValue->serialize($server,$currentProperty);
} elseif (!is_null($propertyValue)) {
throw new Sabre_DAV_Exception('Unknown property value type: ' . gettype($propertyValue) . ' for property: ' . $propertyName);
}
}
$xpropstat->appendChild($document->createElement('d:status',$server->httpResponse->getStatusMessage($httpStatus)));
}
}
}
@@ -0,0 +1,76 @@
<?php
/**
* This class represents the {DAV:}supportedlock property
*
* This property contains information about what kind of locks
* this server supports.
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Property_SupportedLock extends Sabre_DAV_Property {
/**
* supportsLocks
*
* @var mixed
*/
public $supportsLocks = false;
/**
* __construct
*
* @param mixed $supportsLocks
* @return void
*/
public function __construct($supportsLocks) {
$this->supportsLocks = $supportsLocks;
}
/**
* serialize
*
* @param DOMElement $prop
* @return void
*/
public function serialize(Sabre_DAV_Server $server,DOMElement $prop) {
$doc = $prop->ownerDocument;
if (!$this->supportsLocks) return null;
$lockEntry1 = $doc->createElementNS('DAV:','d:lockentry');
$lockEntry2 = $doc->createElementNS('DAV:','d:lockentry');
$prop->appendChild($lockEntry1);
$prop->appendChild($lockEntry2);
$lockScope1 = $doc->createElementNS('DAV:','d:lockscope');
$lockScope2 = $doc->createElementNS('DAV:','d:lockscope');
$lockType1 = $doc->createElementNS('DAV:','d:locktype');
$lockType2 = $doc->createElementNS('DAV:','d:locktype');
$lockEntry1->appendChild($lockScope1);
$lockEntry1->appendChild($lockType1);
$lockEntry2->appendChild($lockScope2);
$lockEntry2->appendChild($lockType2);
$lockScope1->appendChild($doc->createElementNS('DAV:','d:exclusive'));
$lockScope2->appendChild($doc->createElementNS('DAV:','d:shared'));
$lockType1->appendChild($doc->createElementNS('DAV:','d:write'));
$lockType2->appendChild($doc->createElementNS('DAV:','d:write'));
//$frag->appendXML('<d:lockentry><d:lockscope><d:exclusive /></d:lockscope><d:locktype><d:write /></d:locktype></d:lockentry>');
//$frag->appendXML('<d:lockentry><d:lockscope><d:shared /></d:lockscope><d:locktype><d:write /></d:locktype></d:lockentry>');
}
}
@@ -0,0 +1,110 @@
<?php
/**
* supported-report-set property.
*
* This property is defined in RFC3253, but since it's
* so common in other webdav-related specs, it is part of the core server.
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Property_SupportedReportSet extends Sabre_DAV_Property {
/**
* List of reports
*
* @var array
*/
protected $reports = array();
/**
* Creates the property
*
* Any reports passed in the constructor
* should be valid report-types in clark-notation.
*
* Either a string or an array of strings must be passed.
*
* @param mixed $reports
* @return void
*/
public function __construct($report = null) {
if (!is_null($report))
$this->addReport($reports);
}
/**
* Adds a report to this property
*
* The report must be a string in clark-notation.
* Multiple reports can be specified as an array.
*
* @param mixed $report
* @return void
*/
public function addReport($report) {
if (!is_array($report)) $report = array($report);
foreach($report as $r) {
if (!preg_match('/^{([^}]*)}(.*)$/',$r))
throw new Sabre_DAV_Exception('Reportname must be in clark-notation');
$this->reports[] = $r;
}
}
/**
* Returns the list of supported reports
*
* @return array
*/
public function getValue() {
return $this->reports;
}
/**
* Serializes the node
*
* @param Sabre_DAV_Server $server
* @param DOMElement $prop
* @return void
*/
public function serialize(Sabre_DAV_Server $server,DOMElement $prop) {
foreach($this->reports as $reportName) {
$supportedReport = $prop->ownerDocument->createElement('d:supported-report');
$prop->appendChild($supportedReport);
$report = $prop->ownerDocument->createElement('d:report');
$supportedReport->appendChild($report);
preg_match('/^{([^}]*)}(.*)$/',$reportName,$matches);
list(, $namespace, $element) = $matches;
$prefix = isset($server->xmlNamespaces[$namespace])?$server->xmlNamespaces[$namespace]:null;
if ($prefix) {
$report->appendChild($prop->ownerDocument->createElement($prefix . ':' . $element));
} else {
$report->appendChild($prop->ownerDocument->createElementNS($namespace, 'x:' . $element));
}
}
}
}
@@ -0,0 +1,10 @@
<html>
<head><title>IP.Board - Bulletin Board System</title></head>
<body>
<h1>403: IP.Board -&gt; Forbidden</h1>
<hr>
You have reached this page in error, please use your back button to return to the forum.
<hr>
<a href="http://www.invisionpower.com/">IP.Board</a>
</body>
</html>
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,60 @@
<?php
/**
* The baseclass for all server plugins.
*
* Plugins can modify or extend the servers behaviour.
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
abstract class Sabre_DAV_ServerPlugin {
/**
* This initializes the plugin.
*
* This function is called by Sabre_DAV_Server, after
* addPlugin is called.
*
* This method should set up the requires event subscriptions.
*
* @param Sabre_DAV_Server $server
* @return void
*/
abstract public function initialize(Sabre_DAV_Server $server);
/**
* This method should return a list of server-features.
*
* This is for example 'versioning' and is added to the DAV: header
* in an OPTIONS response.
*
* @return array
*/
public function getFeatures() {
return array();
}
/**
* Use this method to tell the server this plugin defines additional
* HTTP methods.
*
* This method is passed a uri. It should only return HTTP methods that are
* available for the specified uri.
*
* @param string $uri
* @return array
*/
public function getHTTPMethods($uri) {
return array();
}
}
@@ -0,0 +1,106 @@
<?php
/**
* SimpleDirectory
*
* The SimpleDirectory is used to quickly setup static directory structures.
* Just create the object with a proper name, and add children to use it.
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_SimpleDirectory extends Sabre_DAV_Directory {
/**
* List of childnodes
*
* @var array
*/
protected $children = array();
/**
* Name of this resource
*
* @var string
*/
protected $name;
/**
* Creates this node
*
* The name of the node must be passed, child nodes can also be bassed.
* This nodes must be instances of Sabre_DAV_INode
*
* @param string $name
* @param array $children
* @return void
*/
public function __construct($name,array $children = array()) {
$this->name = $name;
foreach($children as $child) {
if (!($child instanceof Sabre_DAV_INode)) throw new Sabre_DAV_Exception('Only instances of Sabre_DAV_INode are allowed to be passed in the children argument');
$this->addChild($child);
}
}
/**
* Adds a new childnode to this collection
*
* @param Sabre_DAV_INode $child
* @return void
*/
public function addChild(Sabre_DAV_INode $child) {
$this->children[$child->getName()] = $child;
}
/**
* Returns the name of the collection
*
* @return string
*/
public function getName() {
return $this->name;
}
/**
* Returns a child object, by its name.
*
* This method makes use of the getChildren method to grab all the child nodes, and compares the name.
* Generally its wise to override this, as this can usually be optimized
*
* @param string $name
* @throws Sabre_DAV_Exception_FileNotFound
* @return Sabre_DAV_INode
*/
public function getChild($name) {
if (isset($this->children[$name])) return $this->children[$name];
throw new Sabre_DAV_Exception_FileNotFound('File not found: ' . $name);
}
/**
* Returns a list of children for this collection
*
* @return array
*/
public function getChildren() {
return array_values($this->children);
}
}
@@ -0,0 +1,279 @@
<?php
/**
* Temporary File Filter Plugin
*
* The purpose of this filter is to intercept some of the garbage files
* operation systems and applications tend to generate when mounting
* a WebDAV share as a disk.
*
* It will intercept these files and place them in a separate directory.
* these files are not deleted automatically, so it is adviceable to
* delete these after they are not accessed for 24 hours.
*
* Currently it supports:
* * OS/X style resource forks and .DS_Store
* * desktop.ini and Thumbs.db (windows)
* * .*.swp (vim temporary files)
* * .dat.* (smultron temporary files)
*
* Additional patterns can be added, by adding on to the
* temporaryFilePatterns property.
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_TemporaryFileFilterPlugin extends Sabre_DAV_ServerPlugin {
/**
* This is the list of patterns we intercept.
* If new patterns are added, they must be valid patterns for preg_match.
*
* @var array
*/
public $temporaryFilePatterns = array(
'/^\._(.*)$/', // OS/X resource forks
'/^.DS_Store$/', // OS/X custom folder settings
'/^desktop.ini$/', // Windows custom folder settings
'/^Thumbs.db$/', // Windows thumbnail cache
'/^.(.*).swp$/', // ViM temporary files
'/^\.dat(.*)$/', // Smultron seems to create these
'/^~lock.(.*)#$/', // Windows 7 lockfiles
);
/**
* This is the directory where this plugin
* will store it's files.
*
* @var string
*/
private $dataDir;
/**
* A reference to the main Server class
*
* @var Sabre_DAV_Server
*/
private $server;
/**
* Creates the plugin.
*
* Make sure you specify a directory for your files. If you don't, we
* will use PHP's directory for session-storage instead, and you might
* not want that.
*
* @param string $dataDir
* @return void
*/
public function __construct($dataDir = null) {
if (!$dataDir) $dataDir = ini_get('session.save_path').'/sabredav/';
if (!is_dir($dataDir)) mkdir($dataDir);
$this->dataDir = $dataDir;
}
/**
* Initialize the plugin
*
* This is called automatically be the Server class after this plugin is
* added with Sabre_DAV_Server::addPlugin()
*
* @param Sabre_DAV_Server $server
* @return void
*/
public function initialize(Sabre_DAV_Server $server) {
$this->server = $server;
$server->subscribeEvent('beforeMethod',array($this,'beforeMethod'));
$server->subscribeEvent('beforeCreateFile',array($this,'beforeCreateFile'));
}
/**
* This method is called before any HTTP method handler
*
* This method intercepts any GET, DELETE, PUT and PROPFIND calls to
* filenames that are known to match the 'temporary file' regex.
*
* @param string $method
* @return bool
*/
public function beforeMethod($method, $uri) {
if (!$tempLocation = $this->isTempFile($uri))
return true;
switch($method) {
case 'GET' :
return $this->httpGet($tempLocation);
case 'PUT' :
return $this->httpPut($tempLocation);
case 'PROPFIND' :
return $this->httpPropfind($tempLocation, $uri);
case 'DELETE' :
return $this->httpDelete($tempLocation);
}
return true;
}
/**
* This method is invoked if some subsystem creates a new file.
*
* This is used to deal with HTTP LOCK requests which create a new
* file.
*
* @param string $uri
* @param resource $data
* @return bool
*/
public function beforeCreateFile($uri,$data) {
if ($tempPath = $this->isTempFile($uri)) {
$hR = $this->server->httpResponse;
$hR->setHeader('X-Sabre-Temp','true');
file_put_contents($tempPath,$data);
return false;
}
return true;
}
/**
* This method will check if the url matches the temporary file pattern
* if it does, it will return an path based on $this->dataDir for the
* temporary file storage.
*
* @param string $path
* @return boolean|string
*/
protected function isTempFile($path) {
// We're only interested in the basename.
list(, $tempPath) = Sabre_DAV_URLUtil::splitPath($path);
foreach($this->temporaryFilePatterns as $tempFile) {
if (preg_match($tempFile,$tempPath)) {
return $this->dataDir . '/sabredav_' . md5($path) . '.tempfile';
}
}
return false;
}
/**
* This method handles the GET method for temporary files.
* If the file doesn't exist, it will return false which will kick in
* the regular system for the GET method.
*
* @param string $tempLocation
* @return bool
*/
public function httpGet($tempLocation) {
if (!file_exists($tempLocation)) return true;
$hR = $this->server->httpResponse;
$hR->setHeader('Content-Type','application/octet-stream');
$hR->setHeader('Content-Length',filesize($tempLocation));
$hR->setHeader('X-Sabre-Temp','true');
$hR->sendStatus(200);
$hR->sendBody(fopen($tempLocation,'r'));
return false;
}
/**
* This method handles the PUT method.
*
* @param string $tempLocation
* @return bool
*/
public function httpPut($tempLocation) {
$hR = $this->server->httpResponse;
$hR->setHeader('X-Sabre-Temp','true');
$newFile = !file_exists($tempLocation);
if (!$newFile && ($this->server->httpRequest->getHeader('If-None-Match'))) {
throw new Sabre_DAV_Exception_PreconditionFailed('The resource already exists, and an If-None-Match header was supplied');
}
file_put_contents($tempLocation,$this->server->httpRequest->getBody());
$hR->sendStatus($newFile?201:200);
return false;
}
/**
* This method handles the DELETE method.
*
* If the file didn't exist, it will return false, which will make the
* standard HTTP DELETE handler kick in.
*
* @param string $tempLocation
* @return bool
*/
public function httpDelete($tempLocation) {
if (!file_exists($tempLocation)) return true;
unlink($tempLocation);
$hR = $this->server->httpResponse;
$hR->setHeader('X-Sabre-Temp','true');
$hR->sendStatus(204);
return false;
}
/**
* This method handles the PROPFIND method.
*
* It's a very lazy method, it won't bother checking the request body
* for which properties were requested, and just sends back a default
* set of properties.
*
* @param string $tempLocation
* @return void
*/
public function httpPropfind($tempLocation, $uri) {
if (!file_exists($tempLocation)) return true;
$hR = $this->server->httpResponse;
$hR->setHeader('X-Sabre-Temp','true');
$hR->sendStatus(207);
$hR->setHeader('Content-Type','application/xml; charset=utf-8');
$requestedProps = $this->server->parsePropFindRequest($this->server->httpRequest->getBody(true));
$properties = array(
'href' => $uri,
200 => array(
'{DAV:}getlastmodified' => new Sabre_DAV_Property_GetLastModified(filemtime($tempLocation)),
'{DAV:}getcontentlength' => filesize($tempLocation),
'{DAV:}resourcetype' => new Sabre_DAV_Property_ResourceType(null),
'{'.Sabre_DAV_Server::NS_SABREDAV.'}tempFile' => true,
),
);
$data = $this->server->generateMultiStatus(array($properties));
$hR->sendBody($data);
return false;
}
}
+192
View File
@@ -0,0 +1,192 @@
<?php
/**
* Abstract tree object
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
abstract class Sabre_DAV_Tree {
/**
* This function must return an INode object for a path
* If a Path doesn't exist, thrown an Exception_FileNotFound
*
* @param string $path
* @throws Exception_FileNotFound
* @return Sabre_DAV_INode
*/
abstract function getNodeForPath($path);
/**
* This function allows you to check if a node exists.
*
* Implementors of this class should override this method to make
* it cheaper.
*
* @param string $path
* @return bool
*/
public function nodeExists($path) {
try {
$this->getNodeForPath($path);
return true;
} catch (Sabre_DAV_Exception_FileNotFound $e) {
return false;
}
}
/**
* Copies a file from path to another
*
* @param string $sourcePath The source location
* @param string $destinationPath The full destination path
* @return void
*/
public function copy($sourcePath, $destinationPath) {
$sourceNode = $this->getNodeForPath($sourcePath);
// grab the dirname and basename components
list($destinationDir, $destinationName) = Sabre_DAV_URLUtil::splitPath($destinationPath);
$destinationParent = $this->getNodeForPath($destinationDir);
$this->copyNode($sourceNode,$destinationParent,$destinationName);
$this->markDirty($destinationDir);
}
/**
* Moves a file from one location to another
*
* @param string $sourcePath The path to the file which should be moved
* @param string $destinationPath The full destination path, so not just the destination parent node
* @return int
*/
public function move($sourcePath, $destinationPath) {
list($sourceDir, $sourceName) = Sabre_DAV_URLUtil::splitPath($sourcePath);
list($destinationDir, $destinationName) = Sabre_DAV_URLUtil::splitPath($destinationPath);
if ($sourceDir===$destinationDir) {
$renameable = $this->getNodeForPath($sourcePath);
$renameable->setName($destinationName);
} else {
$this->copy($sourcePath,$destinationPath);
$this->getNodeForPath($sourcePath)->delete();
}
$this->markDirty($sourceDir);
$this->markDirty($destinationDir);
}
/**
* Deletes a node from the tree
*
* @param string $path
* @return void
*/
public function delete($path) {
$node = $this->getNodeForPath($path);
$node->delete();
list($parent) = Sabre_DAV_URLUtil::splitPath($path);
$this->markDirty($parent);
}
/**
* Returns a list of childnodes for a given path.
*
* @param string $path
* @return array
*/
public function getChildren($path) {
$node = $this->getNodeForPath($path);
return $node->getChildren();
}
/**
* This method is called with every tree update
*
* Examples of tree updates are:
* * node deletions
* * node creations
* * copy
* * move
* * renaming nodes
*
* If Tree classes implement a form of caching, this will allow
* them to make sure caches will be expired.
*
* If a path is passed, it is assumed that the entire subtree is dirty
*
* @param string $path
* @return void
*/
public function markDirty($path) {
}
/**
* copyNode
*
* @param Sabre_DAV_INode $source
* @param Sabre_DAV_ICollection $destination
* @return void
*/
protected function copyNode(Sabre_DAV_INode $source,Sabre_DAV_ICollection $destinationParent,$destinationName = null) {
if (!$destinationName) $destinationName = $source->getName();
if ($source instanceof Sabre_DAV_IFile) {
$data = $source->get();
// If the body was a string, we need to convert it to a stream
if (is_string($data)) {
$stream = fopen('php://temp','r+');
fwrite($stream,$data);
rewind($stream);
$data = $stream;
}
$destinationParent->createFile($destinationName,$data);
$destination = $destinationParent->getChild($destinationName);
} elseif ($source instanceof Sabre_DAV_ICollection) {
$destinationParent->createDirectory($destinationName);
$destination = $destinationParent->getChild($destinationName);
foreach($source->getChildren() as $child) {
$this->copyNode($child,$destination);
}
}
if ($source instanceof Sabre_DAV_IProperties && $destination instanceof Sabre_DAV_IProperties) {
$props = $source->getProperties(array());
$destination->updateProperties($props);
}
}
}
@@ -0,0 +1,124 @@
<?php
/**
* Sabre_DAV_Tree_Filesystem
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Tree_Filesystem extends Sabre_DAV_Tree {
/**
* Base url on the filesystem.
*
* @var string
*/
protected $basePath;
/**
* Creates this tree
*
* Supply the path you'd like to share.
*
* @param string $basePath
* @return void
*/
public function __construct($basePath) {
$this->basePath = $basePath;
}
/**
* Returns a new node for the given path
*
* @param string $path
* @return void
*/
public function getNodeForPath($path) {
$realPath = $this->getRealPath($path);
if (!file_exists($realPath)) throw new Sabre_DAV_Exception_FileNotFound('File at location ' . $realPath . ' not found');
if (is_dir($realPath)) {
return new Sabre_DAV_FS_Directory($path);
} else {
return new Sabre_DAV_FS_File($path);
}
}
/**
* Returns the real filesystem path for a webdav url.
*
* @param string $publicPath
* @return string
*/
protected function getRealPath($publicPath) {
return rtrim($this->basePath,'/') . '/' . trim($publicPath,'/');
}
/**
* Copies a file or directory.
*
* This method must work recursively and delete the destination
* if it exists
*
* @param string $source
* @param string $destination
* @return void
*/
public function copy($source,$destination) {
$source = $this->getRealPath($source);
$destination = $this->getRealPath($destination);
$this->realCopy($source,$destination);
}
/**
* Used by self::copy
*
* @param string $source
* @param string $destination
* @return void
*/
protected function realCopy($source,$destination) {
if (is_file($source)) {
copy($source,$destination);
} else {
mkdir($destination);
foreach(scandir($source) as $subnode) {
if ($subnode=='.' || $subnode=='..') continue;
$this->realCopy($source.'/'.$subnode,$destination.'/'.$subnode);
}
}
}
/**
* Moves a file or directory recursively.
*
* If the destination exists, delete it first.
*
* @param string $source
* @param string $destination
* @return void
*/
public function move($source,$destination) {
$source = $this->getRealPath($source);
$destination = $this->getRealPath($destination);
rename($source,$destination);
}
}
@@ -0,0 +1,10 @@
<html>
<head><title>IP.Board - Bulletin Board System</title></head>
<body>
<h1>403: IP.Board -&gt; Forbidden</h1>
<hr>
You have reached this page in error, please use your back button to return to the forum.
<hr>
<a href="http://www.invisionpower.com/">IP.Board</a>
</body>
</html>
@@ -0,0 +1,141 @@
<?php
/**
* URL utility class
*
* This class provides methods to deal with encoding and decoding url (percent encoded) strings.
*
* It was not possible to use PHP's built-in methods for this, because some clients don't like
* encoding of certain characters.
*
* Specifically, it was found that GVFS (gnome's webdav client) does not like encoding of ( and
* ). Since these are reserved, but don't have a reserved meaning in url, these characters are
* kept as-is.
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_URLUtil {
/**
* Encodes the path of a url.
*
* slashes (/) are treated as path-separators.
*
* @param string $path
* @return string
*/
static function encodePath($path) {
$path = explode('/',$path);
return implode('/',array_map(array('Sabre_DAV_URLUtil','encodePathSegment'), $path));
}
/**
* Encodes a 1 segment of a path
*
* Slashes are considered part of the name, and are encoded as %2f
*
* @param string $pathSegment
* @return string
*/
static function encodePathSegment($pathSegment) {
$newStr = '';
for($i=0;$i<strlen($pathSegment);$i++) {
$c = ord($pathSegment[$i]);
if(
/* Unreserved chacaters */
($c>=0x41 /* A */ && $c<=0x5a /* Z */) ||
($c>=0x61 /* a */ && $c<=0x7a /* z */) ||
($c>=0x30 /* 0 */ && $c<=0x39 /* 9 */) ||
$c===0x5f /* _ */ ||
$c===0x2d /* - */ ||
$c===0x2e /* . */ ||
$c===0x7E /* ~ */ ||
/* Reserved, but no reserved purpose */
$c===0x28 /* ( */ ||
$c===0x29 /* ) */
) {
$newStr.=$pathSegment[$i];
} else {
$newStr.='%' . str_pad(dechex($c), 2, '0', STR_PAD_LEFT);
}
}
return $newStr;
}
/**
* Decodes a url-encoded path
*
* @param string $path
* @return string
*/
static function decodePath($path) {
return self::decodePathSegment($path);
}
/**
* Decodes a url-encoded path segment
*
* @param string $path
* @return string
*/
static function decodePathSegment($path) {
$path = urldecode($path);
$encoding = mb_detect_encoding($path, array('UTF-8','ISO-8859-1'));
switch($encoding) {
case 'ISO-8859-1' :
$path = utf8_encode($path);
}
return $path;
}
/**
* Returns the 'dirname' and 'basename' for a path.
*
* The reason there is a custom function for this purpose, is because
* basename() is locale aware (behaviour changes if C locale or a UTF-8 locale is used)
* and we need a method that just operates on UTF-8 characters.
*
* In addition basename and dirname are platform aware, and will treat backslash (\) as a
* directory separator on windows.
*
* This method returns the 2 components as an array.
*
* If there is no dirname, it will return an empty string. Any / appearing at the end of the
* string is stripped off.
*
* @param string $path
* @return array
*/
static function splitPath($path) {
$matches = array();
if(preg_match('/^(?:(?:(.*)(?:\/+))?([^\/]+))(?:\/?)$/u',$path,$matches)) {
return array($matches[1],$matches[2]);
} else {
return array(null,null);
}
}
}
@@ -0,0 +1,24 @@
<?php
/**
* This class contains the SabreDAV version constants.
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_Version {
/**
* Full version number
*/
const VERSION = '1.3.0';
/**
* Stability : alpha, beta, stable
*/
const STABILITY = 'stable';
}
@@ -0,0 +1,160 @@
<?php
/**
* XML utilities for WebDAV
*
* @package Sabre
* @subpackage DAV
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_DAV_XMLUtil {
/**
* Returns the 'clark notation' for an element.
*
* For example, and element encoded as:
* <b:myelem xmlns:b="http://www.example.org/" />
* will be returned as:
* {http://www.example.org}myelem
*
* This format is used throughout the SabreDAV sourcecode.
* Elements encoded with the urn:DAV namespace will
* be returned as if they were in the DAV: namespace. This is to avoid
* compatibility problems.
*
* This function will return null if a nodetype other than an Element is passed.
*
* @param DOMElement $dom
* @return string
*/
static function toClarkNotation(DOMNode $dom) {
if ($dom->nodeType !== XML_ELEMENT_NODE) return null;
// Mapping back to the real namespace, in case it was dav
if ($dom->namespaceURI=='urn:DAV') $ns = 'DAV:'; else $ns = $dom->namespaceURI;
// Mapping to clark notation
return '{' . $ns . '}' . $dom->localName;
}
/**
* This method takes an XML document (as string) and converts all instances of the
* DAV: namespace to urn:DAV
*
* This is unfortunately needed, because the DAV: namespace violates the xml namespaces
* spec, and causes the DOM to throw errors
*/
static function convertDAVNamespace($xmlDocument) {
// This is used to map the DAV: namespace to urn:DAV. This is needed, because the DAV:
// namespace is actually a violation of the XML namespaces specification, and will cause errors
return preg_replace("/xmlns(:[A-Za-z0-9_]*)?=(\"|\')DAV:(\\2)/","xmlns\\1=\\2urn:DAV\\2",$xmlDocument);
}
/**
* This method provides a generic way to load a DOMDocument for WebDAV use.
*
* This method throws a Sabre_DAV_Exception_BadRequest exception for any xml errors.
* It does not preserve whitespace, and it converts the DAV: namespace to urn:DAV.
*
* @param string $xml
* @throws Sabre_DAV_Exception_BadRequest
* @return DOMDocument
*/
static function loadDOMDocument($xml) {
if (empty($xml))
throw new Sabre_DAV_Exception_BadRequest('Empty XML document sent');
// The BitKinex client sends xml documents as UTF-16. PHP 5.3.1 (and presumably lower)
// does not support this, so we must intercept this and convert to UTF-8.
if (substr($xml,0,12) === "\x3c\x00\x3f\x00\x78\x00\x6d\x00\x6c\x00\x20\x00") {
// Note: the preceeding byte sequence is "<?xml" encoded as UTF_16, without the BOM.
$xml = iconv('UTF-16LE','UTF-8',$xml);
// Because the xml header might specify the encoding, we must also change this.
// This regex looks for the string encoding="UTF-16" and replaces it with
// encoding="UTF-8".
$xml = preg_replace('|<\?xml([^>]*)encoding="UTF-16"([^>]*)>|u','<?xml\1encoding="UTF-8"\2>',$xml);
}
// Retaining old error setting
$oldErrorSetting = libxml_use_internal_errors(true);
// Clearing any previous errors
libxml_clear_errors();
$dom = new DOMDocument();
$dom->loadXML(self::convertDAVNamespace($xml),LIBXML_NOWARNING | LIBXML_NOERROR);
// We don't generally care about any whitespace
$dom->preserveWhiteSpace = false;
if ($error = libxml_get_last_error()) {
libxml_clear_errors();
throw new Sabre_DAV_Exception_BadRequest('The request body had an invalid XML body. (message: ' . $error->message . ', errorcode: ' . $error->code . ', line: ' . $error->line . ')');
}
// Restoring old mechanism for error handling
if ($oldErrorSetting===false) libxml_use_internal_errors(false);
return $dom;
}
/**
* Parses all WebDAV properties out of a DOM Element
*
* Generally WebDAV properties are encloded in {DAV:}prop elements. This
* method helps by going through all these and pulling out the actual
* propertynames, making them array keys and making the property values,
* well.. the array values.
*
* If no value was given (self-closing element) null will be used as the
* value. This is used in for example PROPFIND requests.
*
* Complex values are supported through the propertyMap argument. The
* propertyMap should have the clark-notation properties as it's keys, and
* classnames as values.
*
* When any of these properties are found, the unserialize() method will be
* (statically) called. The result of this method is used as the value.
*
* @param DOMElement $parentNode
* @param array $propertyMap
* @return array
*/
static function parseProperties(DOMElement $parentNode, array $propertyMap = array()) {
$propList = array();
foreach($parentNode->childNodes as $propNode) {
if (Sabre_DAV_XMLUtil::toClarkNotation($propNode)!=='{DAV:}prop') continue;
foreach($propNode->childNodes as $propNodeData) {
/* If there are no elements in here, we actually get 1 text node, this special case is dedicated to netdrive */
if ($propNodeData->nodeType != XML_ELEMENT_NODE) continue;
$propertyName = Sabre_DAV_XMLUtil::toClarkNotation($propNodeData);
if (isset($propertyMap[$propertyName])) {
$propList[$propertyName] = call_user_func(array($propertyMap[$propertyName],'unserialize'),$propNodeData);
} else {
$propList[$propertyName] = $propNodeData->textContent;
}
}
}
return $propList;
}
}
@@ -0,0 +1,10 @@
<html>
<head><title>IP.Board - Bulletin Board System</title></head>
<body>
<h1>403: IP.Board -&gt; Forbidden</h1>
<hr>
You have reached this page in error, please use your back button to return to the forum.
<hr>
<a href="http://www.invisionpower.com/">IP.Board</a>
</body>
</html>