Show upload form directly in directory listing

This commit is contained in:
Thomas Kolb 2013-08-19 22:57:59 +02:00
parent b6a76a3d43
commit e439138146
3 changed files with 12 additions and 31 deletions

View File

@ -89,18 +89,4 @@
" </ul>" \
FOOTER
#define UPLOAD_FORM \
HEADER1 \
" <title>Upload</title>" \
HEADER2 \
" <h1>Upload</h1>" \
" <p>You can upload a file to the current directory here.<p>" \
" <p>" \
" <form method=\"POST\" action=\".\" enctype=\"multipart/form-data\">" \
" <input name=\"data\" type=\"file\" size=\"30\">" \
" <input type=\"submit\" value=\"Go!\">" \
" </form>" \
" </p>" \
FOOTER
#endif // TEMPLATES_H

View File

@ -201,11 +201,21 @@ char* gen_html(const char *url, struct Entry *entries, size_t numentries, int up
if(uploadEnabled) {
strcat(result, "<h2>Upload</h2>");
strcat(result, "<p><a href=\"?upload=1\">Upload a file to this directory</a></p>");
strcat(result, "<p>Upload a file to this directory:</p>");
strcat(result,
"<p>"
" <form method=\"POST\" action=\".\" enctype=\"multipart/form-data\">"
" <input name=\"data\" type=\"file\" size=\"30\">"
" <input type=\"submit\" value=\"Go!\">"
" </form>"
"</p>"
);
}
strcat(result, FOOTER);
LOG(LVL_DEBUG, "result string (files) usage: %lu/%lu bytes", strlen(result), allocated);
return result;
}

View File

@ -49,7 +49,6 @@ struct MHD_Response *error403Response;
struct MHD_Response *error404Response;
struct MHD_Response *error500Response;
struct MHD_Response *faviconResponse;
struct MHD_Response *uploadFormResponse;
#ifdef HAVE_MAGIC
magic_t magicCookie;
@ -466,11 +465,7 @@ static int connection_handler(void * cls,
if(S_ISREG(connstate->targetStat.st_mode)) {
return serv_regular_file(connection, connstate);
} else if(S_ISDIR(connstate->targetStat.st_mode)) {
if(uploadEnabled && connstate->uploadRequest) {
return MHD_queue_response(connection, MHD_HTTP_OK, uploadFormResponse);
} else {
return serv_directory(connection, connstate);
}
return serv_directory(connection, connstate);
} else {
LOG(LVL_WARN,
"%s is neither a directory nor a regular file. Don't allow the access.",
@ -704,15 +699,6 @@ int main(int argc, char ** argv) {
MHD_add_response_header(error404Response, MHD_HTTP_HEADER_CONTENT_TYPE, "text/html");
MHD_add_response_header(error500Response, MHD_HTTP_HEADER_CONTENT_TYPE, "text/html");
// static response for upload form
uploadFormResponse = MHD_create_response_from_data(
strlen(UPLOAD_FORM),
(void*) UPLOAD_FORM,
MHD_NO,
MHD_NO);
MHD_add_response_header(uploadFormResponse, MHD_HTTP_HEADER_CONTENT_TYPE, "text/html");
// static response for favicon
faviconResponse = create_favicon_response();
@ -763,7 +749,6 @@ int main(int argc, char ** argv) {
MHD_destroy_response(error404Response);
MHD_destroy_response(error500Response);
MHD_destroy_response(faviconResponse);
MHD_destroy_response(uploadFormResponse);
#ifdef HAVE_MAGIC
magic_close(magicCookie);