Beispiel #1
0
 /**
  * Generates the html directory index for a given url
  *
  * @param string $path
  * @return string
  */
 function generateDirectoryIndex($path)
 {
     $html = $this->generateHeader($path ? $path : '/', $path);
     $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 = $this->server->getBaseUri() . URLUtil::encodePath($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="' . $this->escapeHTML($type['icon']) . '"></span> ' . $this->escapeHTML($subProps['displayPath']) . '</a></td>';
             $html .= '<td class="typeColumn">' . $this->escapeHTML($type['string']) . '</td>';
             $html .= '<td>';
             if (isset($subProps['{DAV:}getcontentlength'])) {
                 $html .= $this->escapeHTML($subProps['{DAV:}getcontentlength'] . ' bytes');
             }
             $html .= '</td><td>';
             if (isset($subProps['{DAV:}getlastmodified'])) {
                 $lastMod = $subProps['{DAV:}getlastmodified']->getTime();
                 $html .= $this->escapeHTML($lastMod->format('F j, Y, g:i a'));
             }
             $html .= '</td>';
             $buttonActions = '';
             if ($subNode instanceof DAV\IFile) {
                 $buttonActions = '<a href="' . $this->escapeHTML($subProps['fullPath']) . '?sabreAction=info"><span class="oi" data-glyph="info"></span></a>';
             }
             $this->server->emit('browserButtonActions', [$subProps['fullPath'], $subProps['subNode'], &$buttonActions]);
             $html .= '<td>' . $buttonActions . '</td>';
             $html .= '</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) {
         if (!in_array($propName, $this->uninterestingProperties)) {
             $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 .= $this->generateFooter();
     $this->server->httpResponse->setHeader('Content-Security-Policy', "img-src 'self'; style-src 'self';");
     return $html;
 }
Beispiel #2
0
    /**
     * 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;
    }