summaryrefslogtreecommitdiff
path: root/test/interactive-helper
diff options
context:
space:
mode:
authorDavid Kalnischkies <kalnischkies@gmail.com>2013-10-16 18:43:21 +0200
committerDavid Kalnischkies <kalnischkies@gmail.com>2013-11-30 12:38:26 +0100
commit3c16b5fe7950e32a0a13ad7544ed531ace535316 (patch)
tree77efe01129095b9fbb7865c9bd7d2b0f5b7f0725 /test/interactive-helper
parenteab3a9b2e233d7a142c0fa90bd1ed16a3c0e6cc6 (diff)
webserver: add directoryIndex support defaulting to index.html
Git-Dch: Ignore
Diffstat (limited to 'test/interactive-helper')
-rw-r--r--test/interactive-helper/aptwebserver.cc18
1 files changed, 15 insertions, 3 deletions
diff --git a/test/interactive-helper/aptwebserver.cc b/test/interactive-helper/aptwebserver.cc
index 4ea1794bb..0e04826c5 100644
--- a/test/interactive-helper/aptwebserver.cc
+++ b/test/interactive-helper/aptwebserver.cc
@@ -277,7 +277,7 @@ void sendDirectoryListing(int const client, std::string const &dir, /*{{{*/
<< "</head>" << std::endl
<< "<body><h1>Index of " << dir << "</h1>" << std::endl
<< "<table><tr><th>#</th><th>Name</th><th>Size</th><th>Last-Modified</th></tr>" << std::endl;
- if (dir != ".")
+ if (dir != "./")
listing << "<tr><td>d</td><td><a href=\"..\">Parent Directory</a></td><td>-</td><td>-</td></tr>";
for (int i = 0; i < counter; ++i) {
struct stat fs;
@@ -390,7 +390,7 @@ bool parseFirstLine(int const client, std::string const &request, /*{{{*/
// nuke the first character which is a / as we assured above
filename.erase(0, 1);
if (filename.empty() == true)
- filename = ".";
+ filename = "./";
// support ~user/ uris to refer to /home/user/public_html/ as a kind-of special directory
else if (filename[0] == '~')
{
@@ -405,6 +405,17 @@ bool parseFirstLine(int const client, std::string const &request, /*{{{*/
else
filename = "/home/" + filename.substr(1) + "/public_html/";
}
+
+ // if no filename is given, but a valid directory see if we can use an index or
+ // have to resort to a autogenerated directory listing later on
+ if (DirectoryExists(filename) == true)
+ {
+ std::string const directoryIndex = _config->Find("aptwebserver::directoryindex");
+ if (directoryIndex.empty() == false && directoryIndex == flNotDir(directoryIndex) &&
+ RealFileExists(filename + directoryIndex) == true)
+ filename += directoryIndex;
+ }
+
return true;
}
/*}}}*/
@@ -543,6 +554,7 @@ int main(int const argc, const char * argv[])
_config->CndSet("aptwebserver::response-header::Server", "APT webserver");
_config->CndSet("aptwebserver::response-header::Accept-Ranges", "bytes");
+ _config->CndSet("aptwebserver::directoryindex", "index.html");
std::vector<std::string> messages;
int client;
@@ -693,7 +705,7 @@ int main(int const argc, const char * argv[])
}
else if (DirectoryExists(filename) == true)
{
- if (filename == "." || filename[filename.length()-1] == '/')
+ if (filename[filename.length()-1] == '/')
sendDirectoryListing(client, filename, *m, sendContent);
else
sendRedirect(client, 301, filename.append("/"), *m, sendContent);