diff --git a/.gitignore b/.gitignore index ef932ef..cad9af0 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ fileshare core tags testdir +*.png diff --git a/Makefile b/Makefile index b2af83a..c6e0e84 100644 --- a/Makefile +++ b/Makefile @@ -6,8 +6,8 @@ CFLAGS+=-Wall -pedantic -std=c99 -D_POSIX_C_SOURCE=20120607L -D_FILE_OFFSET_BITS LIBS=-lmicrohttpd $(MAGIC_LIBS) TARGET=fileshare -SOURCE=main.c logger.c dirlisting.c util.c -DEPS=logger.h templates.h dirlisting.h util.h +SOURCE=main.c logger.c dirlisting.c util.c favicon.c +DEPS=logger.h templates.h dirlisting.h util.h favicon.h OBJ=$(patsubst %.c, %.o, $(SOURCE)) diff --git a/favicon.c b/favicon.c new file mode 100644 index 0000000..da49256 --- /dev/null +++ b/favicon.c @@ -0,0 +1,63 @@ +#include + +#include "favicon.h" + +unsigned char favicon_png[] = { + 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, + 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, + 0x08, 0x06, 0x00, 0x00, 0x00, 0x1f, 0xf3, 0xff, 0x61, 0x00, 0x00, 0x00, + 0x04, 0x73, 0x42, 0x49, 0x54, 0x08, 0x08, 0x08, 0x08, 0x7c, 0x08, 0x64, + 0x88, 0x00, 0x00, 0x00, 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0d, + 0xd7, 0x00, 0x00, 0x0d, 0xd7, 0x01, 0x42, 0x28, 0x9b, 0x78, 0x00, 0x00, + 0x00, 0x19, 0x74, 0x45, 0x58, 0x74, 0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, + 0x72, 0x65, 0x00, 0x77, 0x77, 0x77, 0x2e, 0x69, 0x6e, 0x6b, 0x73, 0x63, + 0x61, 0x70, 0x65, 0x2e, 0x6f, 0x72, 0x67, 0x9b, 0xee, 0x3c, 0x1a, 0x00, + 0x00, 0x01, 0x86, 0x49, 0x44, 0x41, 0x54, 0x38, 0x4f, 0x7d, 0x8f, 0xbf, + 0x4b, 0x02, 0x61, 0x1c, 0x87, 0xbf, 0x4b, 0xb4, 0x05, 0xa2, 0x84, 0x10, + 0xe1, 0x52, 0x53, 0xb4, 0x48, 0x04, 0x52, 0x51, 0x46, 0xfd, 0x01, 0xa1, + 0x60, 0xd4, 0x72, 0x39, 0x34, 0xb4, 0x24, 0x04, 0x89, 0x84, 0xbd, 0x41, + 0x53, 0xd2, 0x0f, 0x48, 0x1b, 0xa2, 0xc1, 0xb6, 0x1c, 0x04, 0x0b, 0x07, + 0x33, 0x84, 0xac, 0x08, 0xc1, 0xa5, 0x3f, 0xa1, 0xa0, 0xa0, 0xa1, 0xc0, + 0xb8, 0x88, 0xac, 0xab, 0xfb, 0x74, 0xf7, 0xbe, 0x78, 0x75, 0xde, 0xd9, + 0x03, 0xcf, 0x71, 0xbc, 0x3f, 0x9e, 0xfb, 0x1e, 0xa9, 0x50, 0x41, 0x6b, + 0xd4, 0xd2, 0x54, 0x35, 0x85, 0xff, 0xa0, 0xbf, 0x01, 0xf7, 0xa6, 0x1b, + 0x9e, 0x1d, 0x8f, 0x61, 0xf8, 0x24, 0xdc, 0x7c, 0xde, 0x82, 0x29, 0x10, + 0x2b, 0xc5, 0x90, 0xbe, 0x49, 0x23, 0x99, 0x21, 0xc3, 0x9b, 0x53, 0xc2, + 0x53, 0x59, 0x68, 0x87, 0x29, 0xd0, 0xec, 0xe0, 0x16, 0xe1, 0x51, 0x0b, + 0x3c, 0x17, 0x85, 0x76, 0x98, 0x02, 0xd2, 0xb1, 0x04, 0x76, 0xce, 0xb0, + 0xbc, 0x47, 0x58, 0x48, 0x10, 0x02, 0xb3, 0x84, 0x2e, 0x9f, 0xb6, 0xd7, + 0x67, 0xd5, 0xe1, 0x73, 0xe0, 0xf6, 0xe1, 0xd6, 0x1c, 0xb8, 0xb8, 0xbb, + 0xe0, 0xd5, 0xda, 0x01, 0x21, 0x14, 0x14, 0x07, 0xdb, 0xfa, 0x09, 0xdd, + 0x3e, 0xa1, 0x67, 0xd2, 0x63, 0x98, 0x2f, 0xe7, 0xad, 0x13, 0x34, 0x02, + 0x2f, 0x9b, 0x04, 0xef, 0xa8, 0x08, 0xf4, 0x68, 0x17, 0x23, 0xd3, 0xc2, + 0xe8, 0x76, 0x14, 0xf1, 0x64, 0x1c, 0xc5, 0xeb, 0x22, 0xea, 0x1f, 0x75, + 0x11, 0xd0, 0x1f, 0x95, 0xfb, 0x0a, 0x57, 0xfe, 0x90, 0xf9, 0xa2, 0xbc, + 0x4a, 0x28, 0x2c, 0x10, 0x5c, 0x5e, 0xeb, 0xe8, 0x0d, 0x5d, 0xc3, 0x2e, + 0xd4, 0xe4, 0x9a, 0x08, 0x34, 0xf3, 0xba, 0x48, 0x5c, 0x59, 0xf3, 0x2a, + 0x4c, 0x38, 0x9a, 0x11, 0xe6, 0x4a, 0x39, 0x64, 0xcf, 0xb2, 0xf0, 0xcf, + 0xf9, 0x79, 0x84, 0xed, 0x31, 0xfb, 0xc0, 0x9b, 0x44, 0xdc, 0xa5, 0x09, + 0x42, 0x70, 0xe4, 0xd7, 0xd0, 0x52, 0x08, 0x81, 0x48, 0x00, 0xce, 0x21, + 0x27, 0x0f, 0x64, 0x0a, 0x99, 0xdf, 0x80, 0x92, 0x61, 0x78, 0x9f, 0x22, + 0xc3, 0xc4, 0x98, 0x75, 0xec, 0x86, 0x1d, 0xde, 0x76, 0x48, 0x2b, 0x12, + 0x54, 0x55, 0x35, 0x4f, 0xa0, 0x1c, 0x32, 0xd4, 0xc7, 0x89, 0x5b, 0xd1, + 0xbe, 0x78, 0x69, 0x63, 0x75, 0x63, 0x1e, 0xca, 0x97, 0x62, 0xdc, 0xb1, + 0xfc, 0xc2, 0xd7, 0x3e, 0xc3, 0xe7, 0x00, 0xd9, 0xaa, 0xef, 0x35, 0x63, + 0x09, 0xe8, 0x7c, 0xef, 0x32, 0x28, 0xbd, 0x64, 0x52, 0x5f, 0xb3, 0xc3, + 0x36, 0xa0, 0xa3, 0x26, 0x18, 0xbe, 0x3b, 0x89, 0xab, 0xbf, 0xb7, 0xa2, + 0x65, 0x40, 0x47, 0x5d, 0x67, 0xdc, 0xff, 0xf8, 0x01, 0x31, 0xfd, 0xcd, + 0x11, 0xae, 0x58, 0x62, 0xf5, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, + 0x44, 0xae, 0x42, 0x60, 0x82 +}; +unsigned int favicon_png_len = 521; + +struct MHD_Response* create_favicon_response(void) { + struct MHD_Response *faviconResponse = MHD_create_response_from_data( + favicon_png_len, + (void*)favicon_png, + MHD_NO, + MHD_NO); + + MHD_add_response_header(faviconResponse, MHD_HTTP_HEADER_CONTENT_TYPE, "image/png"); + + return faviconResponse; +} diff --git a/favicon.h b/favicon.h new file mode 100644 index 0000000..89bca84 --- /dev/null +++ b/favicon.h @@ -0,0 +1,8 @@ +#ifndef FAVICON_H +#define FAVICON_H + +struct MHD_Response; + +struct MHD_Response* create_favicon_response(void); + +#endif // FAVICON_H diff --git a/favicon/favicon.svg b/favicon/favicon.svg new file mode 100644 index 0000000..9fae225 --- /dev/null +++ b/favicon/favicon.svg @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + F + S + + diff --git a/main.c b/main.c index 2eff11e..34f6fe7 100644 --- a/main.c +++ b/main.c @@ -26,6 +26,7 @@ #include "logger.h" #include "templates.h" #include "dirlisting.h" +#include "favicon.h" #include "util.h" #define DEFAULT_PORT 8888 @@ -45,6 +46,7 @@ char *shareRoot; struct MHD_Response *error403Response; struct MHD_Response *error404Response; struct MHD_Response *error500Response; +struct MHD_Response *faviconResponse; #ifdef HAVE_MAGIC magic_t magicCookie; @@ -242,7 +244,7 @@ static int connection_handler(void * cls, strncpy(connstate->cleanedURL, url, PATH_MAX); remove_trailing_slash(connstate->cleanedURL); - LOG(LVL_INFO, "New %s request for %s (local: %s)", + LOG(LVL_INFO, "%s %s (local: %s)", method, url, connstate->localFileName); return MHD_YES; @@ -254,6 +256,12 @@ static int connection_handler(void * cls, return MHD_NO; // upload data in a GET!? } + // serv the favicon, if requested + if(strcmp(url, "/favicon.png") == 0) { + LOG(LVL_INFO, "Serving FavIcon request."); + return MHD_queue_response(connection, MHD_HTTP_OK, faviconResponse); + } + // check if url contains a "/.." sequence. If so, block the request as it is // trying to access the parent directory (and may be an attempt to leave the // shared space. @@ -368,6 +376,11 @@ int main(int argc, char ** argv) { logger_init(); +#ifndef DEBUG + // don't show debug output in release build + logger_set_verbosity(LVL_INFO); +#endif + if (argc < 2) { printf("%s []\n", argv[0]); return 1; @@ -451,6 +464,9 @@ 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 favicon + faviconResponse = create_favicon_response(); + d = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION, port, NULL, @@ -497,6 +513,7 @@ int main(int argc, char ** argv) { MHD_destroy_response(error403Response); MHD_destroy_response(error404Response); MHD_destroy_response(error500Response); + MHD_destroy_response(faviconResponse); #ifdef HAVE_MAGIC magic_close(magicCookie); diff --git a/templates.h b/templates.h index 13398d1..37e1c3f 100644 --- a/templates.h +++ b/templates.h @@ -10,6 +10,7 @@ #define HEADER2 \ " " \ + " " \ " " \ " "