X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/93a99dac870584ed4ea78f1c2f262db8b5460962..d23bda42456bd092751deb24d8295c27a15721e8:/test/interactive-helper/aptwebserver.cc
diff --git a/test/interactive-helper/aptwebserver.cc b/test/interactive-helper/aptwebserver.cc
index 6c5634de6..94f63bb39 100644
--- a/test/interactive-helper/aptwebserver.cc
+++ b/test/interactive-helper/aptwebserver.cc
@@ -198,7 +198,17 @@ void sendRedirect(int const client, int const httpcode, std::string const &uri,/
addDataHeaders(headers, response);
std::string location("Location: ");
if (strncmp(uri.c_str(), "http://", 7) != 0)
- location.append("http://").append(LookupTag(request, "Host")).append("/").append(uri);
+ {
+ location.append("http://").append(LookupTag(request, "Host")).append("/");
+ if (strncmp("/home/", uri.c_str(), strlen("/home/")) == 0 && uri.find("/public_html/") != std::string::npos)
+ {
+ std::string homeuri = SubstVar(uri, "/home/", "~");
+ homeuri = SubstVar(homeuri, "/public_html/", "/");
+ location.append(homeuri);
+ }
+ else
+ location.append(uri);
+ }
else
location.append(uri);
headers.push_back(location);
@@ -267,7 +277,7 @@ void sendDirectoryListing(int const client, std::string const &dir, /*{{{*/
<< "" << std::endl
<< "
Index of " << dir << "
" << std::endl
<< "# | Name | Size | Last-Modified |
" << std::endl;
- if (dir != ".")
+ if (dir != "./")
listing << "d | Parent Directory | - | - |
";
for (int i = 0; i < counter; ++i) {
struct stat fs;
@@ -298,7 +308,7 @@ void sendDirectoryListing(int const client, std::string const &dir, /*{{{*/
}
/*}}}*/
bool parseFirstLine(int const client, std::string const &request, /*{{{*/
- std::string &filename, bool &sendContent,
+ std::string &filename, std::string ¶ms, bool &sendContent,
bool &closeConnection)
{
if (strncmp(request.c_str(), "HEAD ", 5) == 0)
@@ -365,6 +375,14 @@ bool parseFirstLine(int const client, std::string const &request, /*{{{*/
sendError(client, 400, request, sendContent, "Request is absolutePath, but configured to not accept that");
return false;
}
+
+ size_t paramspos = filename.find('?');
+ if (paramspos != std::string::npos)
+ {
+ params = filename.substr(paramspos + 1);
+ filename.erase(paramspos);
+ }
+
filename = DeQuoteString(filename);
// this is not a secure server, but at least prevent the obvious â¦
@@ -380,7 +398,32 @@ 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] == '~')
+ {
+ // /home/user is actually not entirely correct, but good enough for now
+ size_t dashpos = filename.find('/');
+ if (dashpos != std::string::npos)
+ {
+ std::string home = filename.substr(1, filename.find('/') - 1);
+ std::string pubhtml = filename.substr(filename.find('/') + 1);
+ filename = "/home/" + home + "/public_html/" + pubhtml;
+ }
+ 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;
}
/*}}}*/
@@ -519,6 +562,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 messages;
int client;
@@ -669,7 +713,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);