示例#1
0
 /**
  * This method is called before any HTTP method and validates there is enough free space to store the file
  *
  * @param string $uri
  * @param null $data
  * @throws \Sabre\DAV\Exception\InsufficientStorage
  * @return bool
  */
 public function checkQuota($uri, $data = null)
 {
     $length = $this->getLength();
     if ($length) {
         if (substr($uri, 0, 1) !== '/') {
             $uri = '/' . $uri;
         }
         list($parentUri, $newName) = URLUtil::splitPath($uri);
         $req = $this->server->httpRequest;
         if ($req->getHeader('OC-Chunked')) {
             $info = OC_FileChunking::decodeName($newName);
             $chunkHandler = new OC_FileChunking($info);
             // subtract the already uploaded size to see whether
             // there is still enough space for the remaining chunks
             $length -= $chunkHandler->getCurrentSize();
         }
         $freeSpace = $this->getFreeSpace($parentUri);
         if ($freeSpace !== \OCP\Files\FileInfo::SPACE_UNKNOWN && $length > $freeSpace) {
             if (isset($chunkHandler)) {
                 $chunkHandler->cleanup();
             }
             throw new \Sabre\DAV\Exception\InsufficientStorage();
         }
     }
     return true;
 }
示例#2
0
 /**
  * serialize
  *
  * @param DAV\Server $server
  * @param \DOMElement $dom
  * @return void
  */
 public function serialize(DAV\Server $server, \DOMElement $dom)
 {
     $document = $dom->ownerDocument;
     $properties = $this->responseProperties;
     $xresponse = $document->createElement('d:response');
     $dom->appendChild($xresponse);
     $uri = 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 DAV\PropertyInterface) {
                 $propertyValue->serialize($server, $currentProperty);
             } elseif (!is_null($propertyValue)) {
                 throw new DAV\Exception('Unknown property value type: ' . gettype($propertyValue) . ' for property: ' . $propertyName);
             }
         }
         $xpropstat->appendChild($document->createElement('d:status', $server->httpResponse->getStatusMessage($httpStatus)));
     }
 }
示例#3
0
 /**
  * Renames the node
  *
  * @param string $name The new name
  * @return void
  */
 public function setName($name)
 {
     list($parentPath, ) = DAV\URLUtil::splitPath($this->path);
     list(, $newName) = DAV\URLUtil::splitPath($name);
     $newPath = $parentPath . '/' . $newName;
     rename($this->path, $newPath);
     $this->path = $newPath;
 }
 public function getName()
 {
     if ($this->isLink) {
         return $this->sharedItem->getName();
     } else {
         list(, $name) = \Sabre\DAV\URLUtil::splitPath($this->linkPath);
         return $name;
     }
 }
 /**
  * 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) = DAV\URLUtil::splitPath($path);
         $contentType = $this->getContentType($fileName);
         if ($contentType) {
             $properties[200]['{DAV:}getcontenttype'] = $contentType;
             unset($properties[404]['{DAV:}getcontenttype']);
         }
     }
 }
示例#6
0
 /**
  * Returns a specific principal, specified by it's path.
  *
  * @param string $path
  * @return array
  */
 public function getPrincipalByPath($path)
 {
     list($prefix, $user) = DAV\URLUtil::splitPath($path);
     if ($prefix != 'principals') {
         throw new DAV\Exception\NotFound('Invalid principal prefix path ' . $prefix);
     }
     if ($this->_auth->hasCapability('list') && !$this->_auth->exists($user) && $user != '-system-') {
         throw new DAV\Exception\NotFound('User ' . $user . ' does not exist');
     }
     return $this->_getUserInfo($user);
 }
示例#7
0
 /**
  * Returns the list of addressbooks for a specific user.
  *
  * @param string $principalUri
  * @return array
  */
 public function getAddressBooksForUser($principalUri)
 {
     list($prefix, $user) = DAV\URLUtil::splitPath($principalUri);
     if ($prefix != 'principals') {
         throw new DAV\Exception\NotFound('Invalid principal prefix path ' . $prefix);
     }
     try {
         return $this->_registry->callAppMethod($this->_contacts(), 'davGetCollections', array('args' => array($user)));
     } catch (Horde_Exception $e) {
         throw new DAV\Exception($e->getMessage(), $e->getCode(), $e);
     }
 }
示例#8
0
 public function beforeCreateFile($uri, $data)
 {
     list($dir, $name) = \Sabre\DAV\URLUtil::splitPath($uri);
     $currentNode = null;
     foreach (explode('/', trim($dir, '/')) as $pathPart) {
         $parentNode = $currentNode;
         $currentNode = \SiteCollection::getByHandle($pathPart, $parentNode ? $parentNode->ID : null);
         if (!$currentNode) {
             $currentNode = \SiteCollection::create($pathPart, $parentNode);
         }
     }
 }
示例#9
0
 /**
  * Serializes this property.
  *
  * It will additionally prepend the href property with the server's base uri.
  *
  * @param DAV\Server $server
  * @param \DOMElement $dom
  * @return void
  */
 function serialize(DAV\Server $server, \DOMElement $dom)
 {
     $prefix = $server->xmlNamespaces['DAV:'];
     $elem = $dom->ownerDocument->createElement($prefix . ':href');
     if ($this->autoPrefix) {
         $value = $server->getBaseUri() . DAV\URLUtil::encodePath($this->href);
     } else {
         $value = $this->href;
     }
     $elem->appendChild($dom->ownerDocument->createTextNode($value));
     $dom->appendChild($elem);
 }
示例#10
0
 /**
  * Returns the list of groups a principal is a member of
  *
  * @param string $principal
  * @return array
  */
 public function getGroupMembership($principal)
 {
     list($prefix, $name) = \Sabre\DAV\URLUtil::splitPath($principal);
     $group_membership = array();
     if ($prefix == 'principals') {
         $principal = $this->getPrincipalByPath($principal);
         if (!$principal) {
             throw new \Sabre\DAV\Exception('Principal not found');
         }
         // TODO: for now the user principal has only its own groups
         return array('principals/' . $name . '/calendar-proxy-read', 'principals/' . $name . '/calendar-proxy-write');
     }
     return $group_membership;
 }
示例#11
0
 public function checkPreconditions($handleAsGET = false)
 {
     // chunked upload handling
     if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
         $filePath = parent::getRequestUri();
         list($path, $name) = \Sabre\DAV\URLUtil::splitPath($filePath);
         $info = OC_FileChunking::decodeName($name);
         if (!empty($info)) {
             $filePath = $path . '/' . $info['name'];
             $this->overLoadedUri = $filePath;
         }
     }
     $result = parent::checkPreconditions($handleAsGET);
     $this->overLoadedUri = null;
     return $result;
 }
示例#12
0
 /**
  * Returns a list of calendars for a principal.
  *
  * @param string $principalUri
  * @return array
  */
 public function getCalendarsForUser($principalUri)
 {
     list($prefix, $user) = DAV\URLUtil::splitPath($principalUri);
     if ($prefix != 'principals') {
         throw new DAV\Exception\NotFound('Invalid principal prefix path ' . $prefix);
     }
     $collections = array();
     foreach ($this->_interfaces as $interface) {
         try {
             $collections = array_merge($collections, (array) $this->_registry->callAppMethod($interface, 'davGetCollections', array('args' => array($user))));
         } catch (Horde_Exception $e) {
             throw new DAV\Exception($e->getMessage(), $e->getCode(), $e);
         }
     }
     return $collections;
 }
示例#13
0
 /**
  * @param string $filePath
  * @param \Sabre\DAV\INode $node
  * @throws \Sabre\DAV\Exception\BadRequest
  */
 public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null)
 {
     // chunked upload handling
     if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
         list($path, $name) = \Sabre\DAV\URLUtil::splitPath($filePath);
         $info = OC_FileChunking::decodeName($name);
         if (!empty($info)) {
             $filePath = $path . '/' . $info['name'];
         }
     }
     // we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder
     if (!$this->server->tree->nodeExists($filePath)) {
         return;
     }
     $node = $this->server->tree->getNodeForPath($filePath);
     if ($node instanceof OC_Connector_Sabre_Node) {
         $fileId = $node->getFileId();
         if (!is_null($fileId)) {
             $this->server->httpResponse->setHeader('OC-FileId', $fileId);
         }
     }
 }
示例#14
0
 /**
  * Renames the node
  *
  * @param string $name The new name
  * @return void
  */
 public function setName($name)
 {
     list($parentPath, ) = DAV\URLUtil::splitPath($this->path);
     list(, $newName) = 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);
 }
示例#15
0
文件: File.php 项目: raz0rsdge/horde
 /**
  * Returns the name of the node.
  *
  * This is used to generate the url.
  *
  * @return string
  */
 public function getName()
 {
     list($dir, $base) = DAV\URLUtil::splitPath($this->_path);
     return $base;
 }
示例#16
0
 /**
  * @brief Renames the directory.
  *
  * @todo handle duplicate directory name
  *
  * @throw \Sabre\DAV\Exception\Forbidden
  * @param string $name The new name of the directory.
  * @return void
  */
 public function setName($name)
 {
     logger('old name ' . basename($this->red_path) . ' -> ' . $name, LOGGER_DATA);
     if (!$name || !$this->auth->owner_id) {
         logger('permission denied ' . $name);
         throw new DAV\Exception\Forbidden('Permission denied.');
     }
     if (!perm_is_allowed($this->auth->owner_id, $this->auth->observer, 'write_storage')) {
         logger('permission denied ' . $name);
         throw new DAV\Exception\Forbidden('Permission denied.');
     }
     list($parent_path, ) = DAV\URLUtil::splitPath($this->red_path);
     $new_path = $parent_path . '/' . $name;
     $r = q("UPDATE attach SET filename = '%s' WHERE hash = '%s' AND uid = %d", dbesc($name), dbesc($this->folder_hash), intval($this->auth->owner_id));
     $ch = channelx_by_n($this->auth->owner_id);
     if ($ch) {
         $sync = attach_export_data($ch, $this->folder_hash);
         if ($sync) {
             build_sync_packet($ch['channel_id'], array('file' => array($sync)));
         }
     }
     $this->red_path = $new_path;
 }
示例#17
0
 /**
  * Returns this principals name.
  *
  * @return string
  */
 public function getName()
 {
     $uri = $this->principalProperties['uri'];
     list(, $name) = DAV\URLUtil::splitPath($uri);
     return $name;
 }
示例#18
0
 /**
  * Copies a file or directory.
  *
  * This method must work recursively and delete the destination
  * if it exists
  *
  * @param string $source
  * @param string $destination
  * @throws \Sabre\DAV\Exception\ServiceUnavailable
  * @return void
  */
 public function copy($source, $destination)
 {
     if (!$this->fileView) {
         throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup');
     }
     try {
         if ($this->fileView->is_file($source)) {
             $this->fileView->copy($source, $destination);
         } else {
             $this->fileView->mkdir($destination);
             $dh = $this->fileView->opendir($source);
             if (is_resource($dh)) {
                 while (($subNode = readdir($dh)) !== false) {
                     if ($subNode == '.' || $subNode == '..') {
                         continue;
                     }
                     $this->copy($source . '/' . $subNode, $destination . '/' . $subNode);
                 }
             }
         }
     } catch (\OCP\Files\StorageNotAvailableException $e) {
         throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
     }
     list($destinationDir, ) = \Sabre\DAV\URLUtil::splitPath($destination);
     $this->markDirty($destinationDir);
 }
示例#19
0
 /**
  * @param resource $data
  * @return null|string
  */
 private function createFileChunked($data)
 {
     list($path, $name) = \Sabre\DAV\URLUtil::splitPath($this->path);
     $info = OC_FileChunking::decodeName($name);
     if (empty($info)) {
         throw new \Sabre\DAV\Exception\NotImplemented();
     }
     $chunk_handler = new OC_FileChunking($info);
     $bytesWritten = $chunk_handler->store($info['index'], $data);
     //detect aborted upload
     if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT') {
         if (isset($_SERVER['CONTENT_LENGTH'])) {
             $expected = $_SERVER['CONTENT_LENGTH'];
             if ($bytesWritten != $expected) {
                 $chunk_handler->remove($info['index']);
                 throw new \Sabre\DAV\Exception\BadRequest('expected filesize ' . $expected . ' got ' . $bytesWritten);
             }
         }
     }
     if ($chunk_handler->isComplete()) {
         // we first assembly the target file as a part file
         $partFile = $path . '/' . $info['name'] . '.ocTransferId' . $info['transferid'] . '.part';
         $chunk_handler->file_assemble($partFile);
         // here is the final atomic rename
         $targetPath = $path . '/' . $info['name'];
         $renameOkay = $this->fileView->rename($partFile, $targetPath);
         $fileExists = $this->fileView->file_exists($targetPath);
         if ($renameOkay === false || $fileExists === false) {
             \OC_Log::write('webdav', '\\OC\\Files\\Filesystem::rename() failed', \OC_Log::ERROR);
             // only delete if an error occurred and the target file was already created
             if ($fileExists) {
                 $this->fileView->unlink($targetPath);
             }
             throw new \Sabre\DAV\Exception('Could not rename part file assembled from chunks');
         }
         // allow sync clients to send the mtime along in a header
         $mtime = OC_Request::hasModificationTime();
         if ($mtime !== false) {
             if ($this->fileView->touch($targetPath, $mtime)) {
                 header('X-OC-MTime: accepted');
             }
         }
         $info = $this->fileView->getFileInfo($targetPath);
         return $info->getEtag();
     }
     return null;
 }
示例#20
0
 /**
  * @brief Creates the directory listing for the given path.
  *
  * @param string $path which should be displayed
  */
 public function generateDirectoryIndex($path)
 {
     // (owner_id = channel_id) is visitor owner of this directory?
     $is_owner = local_channel() && $this->auth->owner_id == local_channel() ? true : false;
     if ($this->auth->getTimezone()) {
         date_default_timezone_set($this->auth->getTimezone());
     }
     require_once 'include/conversation.php';
     require_once 'include/text.php';
     if ($this->auth->owner_nick) {
         $html = profile_tabs(get_app(), $is_owner ? true : false, $this->auth->owner_nick);
     }
     $files = $this->server->getPropertiesForPath($path, array('{DAV:}displayname', '{DAV:}resourcetype', '{DAV:}getcontenttype', '{DAV:}getcontentlength', '{DAV:}getlastmodified'), 1);
     $parent = $this->server->tree->getNodeForPath($path);
     $parentpath = array();
     // only show parent if not leaving /cloud/; TODO how to improve this?
     if ($path && $path != "cloud") {
         list($parentUri) = DAV\URLUtil::splitPath($path);
         $fullPath = DAV\URLUtil::encodePath($this->server->getBaseUri() . $parentUri);
         $parentpath['icon'] = $this->enableAssets ? '<a href="' . $fullPath . '"><img src="' . $this->getAssetUrl('icons/parent' . $this->iconExtension) . '" width="24" alt="' . t('parent') . '"></a>' : '';
         $parentpath['path'] = $fullPath;
     }
     $f = array();
     foreach ($files as $file) {
         $ft = array();
         $type = null;
         // This is the current directory, we can skip it
         if (rtrim($file['href'], '/') == $path) {
             continue;
         }
         list(, $name) = DAV\URLUtil::splitPath($file['href']);
         if (isset($file[200]['{DAV:}resourcetype'])) {
             $type = $file[200]['{DAV:}resourcetype']->getValue();
             // resourcetype can have multiple values
             if (!is_array($type)) {
                 $type = array($type);
             }
             foreach ($type as $k => $v) {
                 // Some name mapping is preferred
                 switch ($v) {
                     case '{DAV:}collection':
                         $type[$k] = t('Collection');
                         break;
                     case '{DAV:}principal':
                         $type[$k] = t('Principal');
                         break;
                     case '{urn:ietf:params:xml:ns:carddav}addressbook':
                         $type[$k] = t('Addressbook');
                         break;
                     case '{urn:ietf:params:xml:ns:caldav}calendar':
                         $type[$k] = t('Calendar');
                         break;
                     case '{urn:ietf:params:xml:ns:caldav}schedule-inbox':
                         $type[$k] = t('Schedule Inbox');
                         break;
                     case '{urn:ietf:params:xml:ns:caldav}schedule-outbox':
                         $type[$k] = t('Schedule Outbox');
                         break;
                     case '{http://calendarserver.org/ns/}calendar-proxy-read':
                         $type[$k] = 'Proxy-Read';
                         break;
                     case '{http://calendarserver.org/ns/}calendar-proxy-write':
                         $type[$k] = 'Proxy-Write';
                         break;
                 }
             }
             $type = implode(', ', $type);
         }
         // 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 = t('Unknown');
         }
         $size = isset($file[200]['{DAV:}getcontentlength']) ? (int) $file[200]['{DAV:}getcontentlength'] : '';
         $lastmodified = isset($file[200]['{DAV:}getlastmodified']) ? $file[200]['{DAV:}getlastmodified']->getTime()->format('Y-m-d H:i:s') : '';
         $fullPath = DAV\URLUtil::encodePath('/' . trim($this->server->getBaseUri() . ($path ? $path . '/' : '') . $name, '/'));
         $displayName = isset($file[200]['{DAV:}displayname']) ? $file[200]['{DAV:}displayname'] : $name;
         $displayName = $this->escapeHTML($displayName);
         $type = $this->escapeHTML($type);
         $icon = '';
         if ($this->enableAssets) {
             $node = $this->server->tree->getNodeForPath(($path ? $path . '/' : '') . $name);
             foreach (array_reverse($this->iconMap) as $class => $iconName) {
                 if ($node instanceof $class) {
                     $icon = '<a href="' . $fullPath . '"><img src="' . $this->getAssetUrl($iconName . $this->iconExtension) . '" alt="" width="24"></a>';
                     break;
                 }
             }
         }
         $parentHash = '';
         $owner = $this->auth->owner_id;
         $splitPath = explode('/', $fullPath);
         if (count($splitPath) > 3) {
             for ($i = 3; $i < count($splitPath); $i++) {
                 $attachName = urldecode($splitPath[$i]);
                 $attachHash = $this->findAttachHash($owner, $parentHash, $attachName);
                 $parentHash = $attachHash;
             }
         }
         $attachIcon = "";
         // "<a href=\"attach/".$attachHash."\" title=\"".$displayName."\"><i class=\"icon-download\"></i></a>";
         // put the array for this file together
         $ft['attachId'] = $this->findAttachIdByHash($attachHash);
         $ft['fileStorageUrl'] = substr($fullPath, 0, strpos($fullPath, "cloud/")) . "filestorage/" . $this->auth->getCurrentUser();
         $ft['icon'] = $icon;
         $ft['attachIcon'] = $size ? $attachIcon : '';
         // @todo Should this be an item value, not a global one?
         $ft['is_owner'] = $is_owner;
         $ft['fullPath'] = $fullPath;
         $ft['displayName'] = $displayName;
         $ft['type'] = $type;
         $ft['size'] = $size;
         $ft['sizeFormatted'] = userReadableSize($size);
         $ft['lastmodified'] = $lastmodified ? datetime_convert('UTC', date_default_timezone_get(), $lastmodified) : '';
         $ft['iconFromType'] = getIconFromType($type);
         $f[] = $ft;
     }
     $output = '';
     if ($this->enablePost) {
         $this->server->broadcastEvent('onHTMLActionsPanel', array($parent, &$output));
     }
     $html .= replace_macros(get_markup_template('cloud.tpl'), array('$header' => t('Files') . ": " . $this->escapeHTML($path) . "/", '$total' => t('Total'), '$actionspanel' => $output, '$shared' => t('Shared'), '$create' => t('Create'), '$upload' => t('Upload'), '$is_owner' => $is_owner, '$parentpath' => $parentpath, '$entries' => $f, '$name' => t('Name'), '$type' => t('Type'), '$size' => t('Size'), '$lastmod' => t('Last Modified'), '$parent' => t('parent'), '$edit' => t('Edit'), '$delete' => t('Delete'), '$nick' => $this->auth->getCurrentUser()));
     $a = get_app();
     $a->page['content'] = $html;
     load_pdl($a);
     $theme_info_file = "view/theme/" . current_theme() . "/php/theme.php";
     if (file_exists($theme_info_file)) {
         require_once $theme_info_file;
         if (function_exists(str_replace('-', '_', current_theme()) . '_init')) {
             $func = str_replace('-', '_', current_theme()) . '_init';
             $func($a);
         }
     }
     construct_page($a);
 }
示例#21
0
 /**
  * Returns the name of this object
  *
  * @return string
  */
 public function getName()
 {
     list(, $name) = DAV\URLUtil::splitPath($this->principalInfo['uri']);
     return $name;
 }
示例#22
0
 /**
  * @brief gets the userid from a principal path
  * @param string $principaluri
  * @return string
  */
 public function userIDByPrincipal($principaluri)
 {
     list(, $userid) = \Sabre\DAV\URLUtil::splitPath($principaluri);
     return $userid;
 }
示例#23
0
 public function generateDirectoryIndex($path)
 {
     $html = "<html>\n<head>\n  <title>Index for " . $this->escapeHTML($path) . "/ - SabreDAV " . DAV\Version::VERSION . "</title>\n  <style type=\"text/css\"> body { Font-family: arial}</style>\n</head>\n<body>\n  <h1>Index for " . $this->escapeHTML($path) . "/</h1>\n  <table>\n    <tr><th>Name</th><th>Type</th><th>Size</th><th>Last modified</th></tr>\n    <tr><td colspan=\"4\"><hr /></td></tr>";
     $files = $this->server->getPropertiesForPath($path, array('{DAV:}displayname', '{DAV:}resourcetype', '{DAV:}getcontenttype', '{DAV:}getcontentlength', '{DAV:}getlastmodified'), 1);
     $parent = $this->server->tree->getNodeForPath($path);
     if ($path) {
         list($parentUri) = DAV\URLUtil::splitPath($path);
         $fullPath = DAV\URLUtil::encodePath($this->server->getBaseUri() . $parentUri);
         $html .= "<tr>\n<td><a href=\"{$fullPath}\">..</a></td>\n<td>[parent]</td>\n<td></td>\n<td></td>\n</tr>";
     }
     foreach ($files as $k => $file) {
         // This is the current directory, we can skip it
         if (rtrim($file['href'], '/') == $path) {
             continue;
         }
         list(, $name) = 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 = array($type);
             }
             foreach ($type as $k => $v) {
                 // Some name mapping is preferred
                 switch ($v) {
                     case '{DAV:}collection':
                         $type[$k] = 'Collection';
                         break;
                     case '{DAV:}principal':
                         $type[$k] = 'Principal';
                         break;
                     case '{urn:ietf:params:xml:ns:carddav}addressbook':
                         $type[$k] = 'Addressbook';
                         break;
                     case '{urn:ietf:params:xml:ns:caldav}calendar':
                         $type[$k] = 'Calendar';
                         break;
                 }
             }
             $type = implode(', ', $type);
         }
         // 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 = 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>\n<td><a href=\"{$fullPath}\">{$displayName}</a></td>\n<td>{$type}</td>\n<td>{$size}</td>\n<td>{$lastmodified}</td>\n</tr>";
     }
     $html .= "<tr><td colspan=\"4\"><hr /></td></tr>";
     if ($this->enablePost && $parent instanceof DAV\ICollection) {
         $html .= '<tr><td>
         <form method="post" action="" enctype="multipart/form-data">
         <h3>Upload file</h3>
         <input type="hidden" name="sabreAction" 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>\n  <address>Generated by SabreDAV " . DAV\Version::VERSION . "-" . DAV\Version::STABILITY . " (c)2007-2012 <a href=\"http://code.google.com/p/sabredav/\">http://code.google.com/p/sabredav/</a></address>\n</body>\n</html>";
     return $html;
 }
示例#24
0
 /**
  * @brief gets the userid from a principal path
  * @return string
  */
 public static function extractUserID($principaluri)
 {
     list($prefix, $userid) = \Sabre\DAV\URLUtil::splitPath($principaluri);
     return $userid;
 }
示例#25
0
 /**
  * Generates the html directory index for a given url
  *
  * @param string $path
  * @return string
  */
 public function generateDirectoryIndex($path)
 {
     $version = '';
     if (DAV\Server::$exposeVersion) {
         $version = DAV\Version::VERSION . "-" . DAV\Version::STABILITY;
     }
     $html = "<html>\n<head>\n  <title>Index for " . $this->escapeHTML($path) . "/ - SabreDAV " . $version . "</title>\n  <style type=\"text/css\">\n  body { Font-family: arial}\n  h1 { font-size: 150% }\n  </style>\n        ";
     if ($this->enableAssets) {
         $html .= '<link rel="shortcut icon" href="' . $this->getAssetUrl('favicon.ico') . '" type="image/vnd.microsoft.icon" />';
     }
     $html .= "</head>\n<body>\n  <h1>Index for " . $this->escapeHTML($path) . "/</h1>\n  <table>\n    <tr><th width=\"24\"></th><th>Name</th><th>Type</th><th>Size</th><th>Last modified</th></tr>\n    <tr><td colspan=\"5\"><hr /></td></tr>";
     $files = $this->server->getPropertiesForPath($path, array('{DAV:}displayname', '{DAV:}resourcetype', '{DAV:}getcontenttype', '{DAV:}getcontentlength', '{DAV:}getlastmodified'), 1);
     $parent = $this->server->tree->getNodeForPath($path);
     if ($path) {
         list($parentUri) = DAV\URLUtil::splitPath($path);
         $fullPath = DAV\URLUtil::encodePath($this->server->getBaseUri() . $parentUri);
         $icon = $this->enableAssets ? '<a href="' . $fullPath . '"><img src="' . $this->getAssetUrl('icons/parent' . $this->iconExtension) . '" width="24" alt="Parent" /></a>' : '';
         $html .= "<tr>\n    <td>{$icon}</td>\n    <td><a href=\"{$fullPath}\">..</a></td>\n    <td>[parent]</td>\n    <td></td>\n    <td></td>\n    </tr>";
     }
     foreach ($files as $file) {
         // This is the current directory, we can skip it
         if (rtrim($file['href'], '/') == $path) {
             continue;
         }
         list(, $name) = 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 = array($type);
             }
             foreach ($type as $k => $v) {
                 // Some name mapping is preferred
                 switch ($v) {
                     case '{DAV:}collection':
                         $type[$k] = 'Collection';
                         break;
                     case '{DAV:}principal':
                         $type[$k] = 'Principal';
                         break;
                     case '{urn:ietf:params:xml:ns:carddav}addressbook':
                         $type[$k] = 'Addressbook';
                         break;
                     case '{urn:ietf:params:xml:ns:caldav}calendar':
                         $type[$k] = 'Calendar';
                         break;
                     case '{urn:ietf:params:xml:ns:caldav}schedule-inbox':
                         $type[$k] = 'Schedule Inbox';
                         break;
                     case '{urn:ietf:params:xml:ns:caldav}schedule-outbox':
                         $type[$k] = 'Schedule Outbox';
                         break;
                     case '{http://calendarserver.org/ns/}calendar-proxy-read':
                         $type[$k] = 'Proxy-Read';
                         break;
                     case '{http://calendarserver.org/ns/}calendar-proxy-write':
                         $type[$k] = 'Proxy-Write';
                         break;
                 }
             }
             $type = implode(', ', $type);
         }
         // 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 = DAV\URLUtil::encodePath('/' . trim($this->server->getBaseUri() . ($path ? $path . '/' : '') . $name, '/'));
         $displayName = isset($file[200]['{DAV:}displayname']) ? $file[200]['{DAV:}displayname'] : $name;
         $displayName = $this->escapeHTML($displayName);
         $type = $this->escapeHTML($type);
         $icon = '';
         if ($this->enableAssets) {
             $node = $this->server->tree->getNodeForPath(($path ? $path . '/' : '') . $name);
             foreach (array_reverse($this->iconMap) as $class => $iconName) {
                 if ($node instanceof $class) {
                     $icon = '<a href="' . $fullPath . '"><img src="' . $this->getAssetUrl($iconName . $this->iconExtension) . '" alt="" width="24" /></a>';
                     break;
                 }
             }
         }
         $html .= "<tr>\n    <td>{$icon}</td>\n    <td><a href=\"{$fullPath}\">{$displayName}</a></td>\n    <td>{$type}</td>\n    <td>{$size}</td>\n    <td>{$lastmodified}</td>\n    </tr>";
     }
     $html .= "<tr><td colspan=\"5\"><hr /></td></tr>";
     $output = '';
     if ($this->enablePost) {
         $this->server->broadcastEvent('onHTMLActionsPanel', array($parent, &$output));
     }
     $html .= $output;
     $html .= "</table>\n        <address>Generated by SabreDAV " . $version . " (c)2007-2014 <a href=\"http://code.google.com/p/sabredav/\">http://code.google.com/p/sabredav/</a></address>\n        </body>\n        </html>";
     return $html;
 }
示例#26
0
 /**
  * get Path info from request, not urldecoded
  * @throws Exception
  * @return string Path info or false when not found
  */
 public static function getRawPathInfo()
 {
     $requestUri = $_SERVER['REQUEST_URI'];
     // remove too many leading slashes - can be caused by reverse proxy configuration
     if (strpos($requestUri, '/') === 0) {
         $requestUri = '/' . ltrim($requestUri, '/');
     }
     // Remove the query string from REQUEST_URI
     if ($pos = strpos($requestUri, '?')) {
         $requestUri = substr($requestUri, 0, $pos);
     }
     $scriptName = $_SERVER['SCRIPT_NAME'];
     $path_info = $requestUri;
     // strip off the script name's dir and file name
     list($path, $name) = \Sabre\DAV\URLUtil::splitPath($scriptName);
     if (!empty($path)) {
         if ($path === $path_info || strpos($path_info, $path . '/') === 0) {
             $path_info = substr($path_info, strlen($path));
         } else {
             throw new Exception("The requested uri({$requestUri}) cannot be processed by the script '{$scriptName}')");
         }
     }
     if (strpos($path_info, '/' . $name) === 0) {
         $path_info = substr($path_info, strlen($name) + 1);
     }
     if (strpos($path_info, $name) === 0) {
         $path_info = substr($path_info, strlen($name));
     }
     if ($path_info === '/') {
         return '';
     } else {
         return $path_info;
     }
 }
示例#27
0
文件: PDO.php 项目: biggtfish/cms
 /**
  * This method is used to search for principals matching a set of
  * properties.
  *
  * This search is specifically used by RFC3744's principal-property-search
  * REPORT. You should at least allow searching on
  * http://sabredav.org/ns}email-address.
  *
  * The actual search should be a unicode-non-case-sensitive search. The
  * keys in searchProperties are the WebDAV property names, while the values
  * are the property values to search on.
  *
  * If multiple properties are being searched on, the search should be
  * AND'ed.
  *
  * This method should simply return an array with full principal uri's.
  *
  * If somebody attempted to search on a property the backend does not
  * support, you should simply return 0 results.
  *
  * You can also just return 0 results if you choose to not support
  * searching at all, but keep in mind that this may stop certain features
  * from working.
  *
  * @param string $prefixPath
  * @param array $searchProperties
  * @return array
  */
 public function searchPrincipals($prefixPath, array $searchProperties)
 {
     $query = 'SELECT uri FROM ' . $this->tableName . ' WHERE 1=1 ';
     $values = array();
     foreach ($searchProperties as $property => $value) {
         switch ($property) {
             case '{DAV:}displayname':
                 $query .= ' AND displayname LIKE ?';
                 $values[] = '%' . $value . '%';
                 break;
             case '{http://sabredav.org/ns}email-address':
                 $query .= ' AND email LIKE ?';
                 $values[] = '%' . $value . '%';
                 break;
             default:
                 // Unsupported property
                 return array();
         }
     }
     $stmt = $this->pdo->prepare($query);
     $stmt->execute($values);
     $principals = array();
     while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
         // Checking if the principal is in the prefix
         list($rowPrefix) = DAV\URLUtil::splitPath($row['uri']);
         if ($rowPrefix !== $prefixPath) {
             continue;
         }
         $principals[] = $row['uri'];
     }
     return $principals;
 }
示例#28
0
文件: node.php 项目: Combustible/core
 /**
  * Renames the node
  * @param string $name The new name
  * @throws \Sabre\DAV\Exception\BadRequest
  * @throws \Sabre\DAV\Exception\Forbidden
  */
 public function setName($name)
 {
     // rename is only allowed if the update privilege is granted
     if (!$this->info->isUpdateable()) {
         throw new \Sabre\DAV\Exception\Forbidden();
     }
     list($parentPath, ) = URLUtil::splitPath($this->path);
     list(, $newName) = URLUtil::splitPath($name);
     if (!\OCP\Util::isValidFileName($newName)) {
         throw new \Sabre\DAV\Exception\BadRequest();
     }
     $newPath = $parentPath . '/' . $newName;
     $oldPath = $this->path;
     $this->fileView->rename($this->path, $newPath);
     $this->path = $newPath;
     $query = OC_DB::prepare('UPDATE `*PREFIX*properties` SET `propertypath` = ?' . ' WHERE `userid` = ? AND `propertypath` = ?');
     $query->execute(array($newPath, OC_User::getUser(), $oldPath));
     $this->refreshInfo();
 }
示例#29
0
 /**
  * Serializes the property into a DOMElement.
  *
  * @param DAV\Server $server
  * @param \DOMElement $node
  * @return void
  */
 public function serialize(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() . DAV\URLUtil::encodePath($this->href);
             $node->appendChild($href);
             break;
     }
 }
示例#30
0
 /**
  * Triggered before a node is deleted
  *
  * This allows us to check permissions for any operation that will delete
  * an existing node.
  *
  * @param string $uri
  * @return void
  */
 public function beforeUnbind($uri)
 {
     list($parentUri, $nodeName) = DAV\URLUtil::splitPath($uri);
     $this->checkPrivileges($parentUri, '{DAV:}unbind', self::R_RECURSIVEPARENTS);
 }