/** * @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) = \Sabre\HTTP\URLUtil::splitPath($path); $fullPath = \Sabre\HTTP\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) = \Sabre\HTTP\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 = \Sabre\HTTP\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=\"fa fa-arrow-circle-o-down\"></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->emit('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(); \App::$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); }
/** * serialize * * @param DAV\Server $server * @param \DOMElement $dom * @return void */ function serialize(DAV\Server $server, \DOMElement $dom) { $document = $dom->ownerDocument; $properties = $this->responseProperties; $xresponse = $document->createElement('d:response'); $dom->appendChild($xresponse); $uri = URLUtil::encodePath($this->href); if ($uri === '/') { $uri = ''; } // Adding the baseurl to the beginning of the url $uri = $server->getBaseUri() . $uri; $xresponse->appendChild($document->createElement('d:href', $uri)); if ($this->httpStatus) { $statusString = "HTTP/1.1 " . $this->httpStatus . " " . HTTP\Response::$statusCodes[$this->httpStatus]; $xresponse->appendChild($document->createElement('d:status', $statusString)); } // 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)) { if ($propertyValue !== '') { // we want a self-closing xml element for empty strings. $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', 'HTTP/1.1 ' . $httpStatus . ' ' . HTTP\Response::$statusCodes[$httpStatus])); } }
/** * Generates the html directory index for a given url * * @param string $path * @return string */ function generateDirectoryIndex($path) { $version = ''; if (DAV\Server::$exposeVersion) { $version = DAV\Version::VERSION; } $vars = ['path' => $this->escapeHTML($path), 'favicon' => $this->escapeHTML($this->getAssetUrl('favicon.ico')), 'style' => $this->escapeHTML($this->getAssetUrl('sabredav.css')), 'iconstyle' => $this->escapeHTML($this->getAssetUrl('openiconic/open-iconic.css')), 'logo' => $this->escapeHTML($this->getAssetUrl('sabredav.png')), 'baseUrl' => $this->server->getBaseUri()]; $html = <<<HTML <!DOCTYPE html> <html> <head> <title>{$vars['path']}/ - sabre/dav {$version}</title> <link rel="shortcut icon" href="{$vars['favicon']}" type="image/vnd.microsoft.icon" /> <link rel="stylesheet" href="{$vars['style']}" type="text/css" /> <link rel="stylesheet" href="{$vars['iconstyle']}" type="text/css" /> </head> <body> <header> <div class="logo"> <a href="{$vars['baseUrl']}"><img src="{$vars['logo']}" alt="sabre/dav" /> {$vars['path']}/</a> </div> </header> <nav> HTML; // If the path is empty, there's no parent. if ($path) { list($parentUri) = URLUtil::splitPath($path); $fullPath = URLUtil::encodePath($this->server->getBaseUri() . $parentUri); $html .= '<a href="' . $fullPath . '" class="btn">⇤ Go to parent</a>'; } else { $html .= '<span class="btn disabled">⇤ Go to parent</span>'; } $html .= "</nav>"; $node = $this->server->tree->getNodeForPath($path); if ($node instanceof DAV\ICollection) { $html .= "<section><h1>Nodes</h1>\n"; $html .= "<table class=\"nodeTable\">"; $subNodes = $this->server->getPropertiesForChildren($path, ['{DAV:}displayname', '{DAV:}resourcetype', '{DAV:}getcontenttype', '{DAV:}getcontentlength', '{DAV:}getlastmodified']); foreach ($subNodes as $subPath => $subProps) { $subNode = $this->server->tree->getNodeForPath($subPath); $fullPath = URLUtil::encodePath($this->server->getBaseUri() . $subPath); list(, $displayPath) = URLUtil::splitPath($subPath); $subNodes[$subPath]['subNode'] = $subNode; $subNodes[$subPath]['fullPath'] = $fullPath; $subNodes[$subPath]['displayPath'] = $displayPath; } uasort($subNodes, [$this, 'compareNodes']); foreach ($subNodes as $subProps) { $type = ['string' => 'Unknown', 'icon' => 'cog']; if (isset($subProps['{DAV:}resourcetype'])) { $type = $this->mapResourceType($subProps['{DAV:}resourcetype']->getValue(), $subProps['subNode']); } $html .= '<tr>'; $html .= '<td class="nameColumn"><a href="' . $this->escapeHTML($subProps['fullPath']) . '"><span class="oi" data-glyph="' . $type['icon'] . '"></span> ' . $this->escapeHTML($subProps['displayPath']) . '</a></td>'; $html .= '<td class="typeColumn">' . $type['string'] . '</td>'; $html .= '<td>'; if (isset($subProps['{DAV:}getcontentlength'])) { $html .= $subProps['{DAV:}getcontentlength'] . ' bytes'; } $html .= '</td><td>'; if (isset($subProps['{DAV:}getlastmodified'])) { $lastMod = $subProps['{DAV:}getlastmodified']->getTime(); $html .= $lastMod->format('F j, Y, g:i a'); } $html .= '</td></tr>'; } $html .= '</table>'; } $html .= "</section>"; $html .= "<section><h1>Properties</h1>"; $html .= "<table class=\"propTable\">"; // Allprops request $propFind = new PropFindAll($path); $properties = $this->server->getPropertiesByNode($propFind, $node); $properties = $propFind->getResultForMultiStatus()[200]; foreach ($properties as $propName => $propValue) { $html .= $this->drawPropertyRow($propName, $propValue); } $html .= "</table>"; $html .= "</section>"; /* Start of generating actions */ $output = ''; if ($this->enablePost) { $this->server->emit('onHTMLActionsPanel', [$node, &$output]); } if ($output) { $html .= "<section><h1>Actions</h1>"; $html .= "<div class=\"actions\">\n"; $html .= $output; $html .= "</div>\n"; $html .= "</section>\n"; } $html .= "\n <footer>Generated by SabreDAV " . $version . " (c)2007-2014 <a href=\"http://sabre.io/\">http://sabre.io/</a></footer>\n </body>\n </html>"; $this->server->httpResponse->setHeader('Content-Security-Policy', "img-src 'self'; style-src 'self';"); return $html; }
/** * Generates the first block of HTML, including the <head> tag and page * header. * * Returns footer. * * @param string $title * @param string $path * @return void */ function generateHeader($title, $path = null) { $version = DAV\Version::VERSION; $vars = ['title' => $this->escapeHTML($title), 'favicon' => $this->escapeHTML($this->getAssetUrl('favicon.ico')), 'style' => $this->escapeHTML($this->getAssetUrl('sabredav.css')), 'iconstyle' => $this->escapeHTML($this->getAssetUrl('openiconic/open-iconic.css')), 'logo' => $this->escapeHTML($this->getAssetUrl('sabredav.png')), 'baseUrl' => $this->server->getBaseUri()]; $html = <<<HTML <!DOCTYPE html> <html> <head> <title>{$vars['title']} - sabre/dav {$version}</title> <link rel="shortcut icon" href="{$vars['favicon']}" type="image/vnd.microsoft.icon" /> <link rel="stylesheet" href="{$vars['style']}" type="text/css" /> <link rel="stylesheet" href="{$vars['iconstyle']}" type="text/css" /> </head> <body> <header> <div class="logo"> <a href="{$vars['baseUrl']}"><img src="{$vars['logo']}" alt="sabre/dav" /> {$vars['title']}</a> </div> </header> <nav> HTML; // If the path is empty, there's no parent. if ($path) { list($parentUri) = URLUtil::splitPath($path); $fullPath = $this->server->getBaseUri() . URLUtil::encodePath($parentUri); $html .= '<a href="' . $fullPath . '" class="btn">⇤ Go to parent</a>'; } else { $html .= '<span class="btn disabled">⇤ Go to parent</span>'; } $html .= ' <a href="?sabreAction=plugins" class="btn"><span class="oi" data-glyph="puzzle-piece"></span> Plugins</a>'; $html .= "</nav>"; return $html; }
public function generateDirectoryIndex($path) { $version = DAV\Server::$exposeVersion ? DAV\Version::VERSION : ''; $node = $this->server->tree->getNodeForPath($path); $html = <<<HTML <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Index for {$this->escapeHTML($path)}/ - SambaDAV</title> <link rel="stylesheet" href="{$this->server->getBaseUri()}style.css"/> <link rel="shortcut icon" href="{$this->server->getBaseUri()}favicon.ico" type="image/vnd.microsoft.icon"/> </head> <body> HTML; if ($this->config->anonymous_only === false) { $html .= "\n <p id=\"logout\"><a href=\"?logout\">switch user (logout)</a></p>"; } $html .= <<<HTML <h1>{$this->escapeHTML($node->uri->uriFull())}</h1> <table id="actions"> <tbody> HTML; $output = ''; if ($this->enablePost) { $this->server->emit('onHTMLActionsPanel', [$node, &$output]); } if ($output) { $html .= $output; } $html .= <<<HTML </tbody> </table> <table> <colgroup> <col width="15px"/> <col/> <col/> <col/> <col/> </colgroup> <thead> <tr> <th></th> <th>Name</th> <th>Type</th> <th>Size</th> <th>Last modified</th> HTML; if ($this->config->browserplugin_enable_delete === true) { $html .= "<th>Delete</th>"; } $html .= <<<HTML </tr> </thead> <tbody> HTML; // If path is empty, there is no parent: if ($path) { list($parentUri) = URLUtil::splitPath($path); $fullPath = URLUtil::encodePath($this->server->getBaseUri() . $parentUri); $html .= <<<HTML <tr class="dir"> <td><a href="{$fullPath}"><img src="{$this->server->getBaseUri()}dir.png" alt="Parent"/></a></td> <td><a href="{$fullPath}">..</a></td> <td>[parent]</td> <td></td> <td></td> HTML; if ($this->config->browserplugin_enable_delete === true) { $html .= "<td></td>"; } $html .= <<<HTML </tr> HTML; } if ($node instanceof DAV\ICollection) { $subNodes = $this->server->getPropertiesForChildren($path, ['{DAV:}displayname', '{DAV:}resourcetype', '{DAV:}getcontenttype', '{DAV:}getcontentlength', '{DAV:}getlastmodified']); foreach ($subNodes as $subPath => $subProps) { $subNode = $this->server->tree->getNodeForPath($subPath); $fullPath = URLUtil::encodePath($this->server->getBaseUri() . $subPath); list(, $displayPath) = URLUtil::splitPath($subPath); $subNodes[$subPath]['subNode'] = $subNode; $subNodes[$subPath]['fullPath'] = $fullPath; $subNodes[$subPath]['displayPath'] = $displayPath; } uasort($subNodes, [$this, 'compareNodes']); foreach ($subNodes as $subProps) { $size = isset($subProps['{DAV:}getcontentlength']) ? $subProps['{DAV:}getcontentlength'] : ''; $lastmodified = isset($subProps['{DAV:}getlastmodified']) ? $subProps['{DAV:}getlastmodified']->getTime()->format('F j, Y, H:i:s') : ''; $fullPath_decoded = URLUtil::decodePath($subProps['fullPath']); $fullPath = $this->escapeHTML($subProps['fullPath']); if (isset($subProps['{DAV:}resourcetype']) && in_array('{DAV:}collection', $subProps['{DAV:}resourcetype']->getValue())) { $trclass = 'class="dir"'; $icon = 'dir.png'; $type = 'Directory'; } else { $trclass = 'class="file"'; $icon = 'file.png'; $type = isset($subProps['{DAV:}getcontenttype']) ? $subProps['{DAV:}getcontenttype'] : 'Unknown'; } $html .= " <tr {$trclass}>\n"; $html .= " <td><a href=\"{$fullPath}\"><img src=\"{$this->server->getBaseUri()}{$icon}\" alt=\"\"/></a></td>\n"; $html .= " <td><a href=\"{$fullPath}\">{$subProps['displayPath']}</a></td>\n"; $html .= " <td>{$type}</td>\n"; $html .= " <td>{$size}</td>\n"; $html .= " <td>{$lastmodified}</td>\n"; if ($this->config->browserplugin_enable_delete === true) { $html .= " <td>\n"; $html .= " <form method=\"post\" enctype=\"multipart/form-data\" onsubmit=\"return confirm('Are you sure you want to delete " . $subProps['displayPath'] . "');\">\n"; $html .= " <input name=\"sabreActionExtra\" value=\"del\" type=\"hidden\">\n"; $html .= " <input name=\"path\" value=\"{$fullPath_decoded}\" type=\"hidden\">\n"; $html .= " <input value=\"Delete\" type=\"submit\">\n"; $html .= " </form>\n"; $html .= " </td>\n"; } $html .= " </tr>\n"; } } $html .= <<<HTML </tbody> </table> <img src="{$this->server->getBaseUri()}logo-sambadav.png" id="sambadav-logo"/><address>Generated by SabreDAV {$version}</address> </body> </html> HTML; $this->server->httpResponse->setHeader('Content-Security-Policy', "img-src 'self'; style-src 'self';"); return $html; }