From: Nishi Date: Mon, 16 Sep 2024 12:52:47 +0000 (+0000) Subject: can show readme on index now X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=369394be1170eb2bdf62b471b361d04e7c0885d6;p=tewi.git can show readme on index now git-svn-id: file:///raid/svn-personal/tewi/trunk@33 8739d7e6-ffea-ec47-b151-bdff447c6205 --- diff --git a/Server/config.c b/Server/config.c index a87b1de..95592fd 100644 --- a/Server/config.c +++ b/Server/config.c @@ -83,6 +83,7 @@ void tw_config_init(void) { config.root.dir_count = 0; config.root.icon_count = 0; config.root.index_count = 0; + config.root.readme_count = 0; config.vhost_count = 0; config.module_count = 0; config.extension = NULL; @@ -183,6 +184,7 @@ int tw_config_read(const char* path) { current->mime_count = 0; current->icon_count = 0; current->index_count = 0; + current->readme_count = 0; int i; current->name = cm_strdup(vhost); current->port = -1; @@ -288,6 +290,10 @@ int tw_config_read(const char* path) { for(i = 1; r[i] != NULL; i++) { current->indexes[current->index_count++] = cm_strdup(r[i]); } + } else if(cm_strcaseequ(r[0], "Readme")) { + for(i = 1; r[i] != NULL; i++) { + current->readmes[current->readme_count++] = cm_strdup(r[i]); + } } else { if(r[0] != NULL) { cm_log("Config", "Unknown directive `%s' at line %d", r[0], ln); diff --git a/Server/server.c b/Server/server.c index 2ae66d7..ed6ee5b 100644 --- a/Server/server.c +++ b/Server/server.c @@ -512,10 +512,14 @@ void tw_server_pass(int sock, bool ssl, int port, SOCKADDR addr) { addstring(&str, " MIME\n"); addstring(&str, " Size\n"); addstring(&str, " \n"); + int readme = -1; + char** readmes = vhost_entry->readme_count == 0 ? config.root.readmes : vhost_entry->readmes; + int readme_count = vhost_entry->readme_count == 0 ? config.root.readme_count : vhost_entry->readme_count; if(items != NULL) { int phase = 0; doit: for(i = 0; items[i] != NULL; i++) { + int j; char* fpth = cm_strcat3(path, "/", items[i]); struct stat s; char size[512]; @@ -528,6 +532,18 @@ void tw_server_pass(int sock, bool ssl, int port, SOCKADDR addr) { free(fpth); continue; } + if(readme == -1) { + for(j = 0; j < readme_count; j++) { + if(strcmp(items[i], readmes[j]) == 0) { + readme = j; + break; + } + } + if(readme != -1) { + free(fpth); + continue; + } + } if(s.st_size < 1024ULL) { sprintf(size, "%d", (int)s.st_size); } else if(s.st_size < 1024ULL * 1024) { @@ -543,7 +559,6 @@ void tw_server_pass(int sock, bool ssl, int port, SOCKADDR addr) { free(fpth); char* ext = NULL; - int j; for(j = strlen(items[i]) - 1; j >= 0; j--) { if(items[i][j] == '.') { ext = cm_strdup(items[i] + j); @@ -594,6 +609,20 @@ void tw_server_pass(int sock, bool ssl, int port, SOCKADDR addr) { free(items); } addstring(&str, " \n"); + if(readme != -1) { + addstring(&str, "
\n"); + char* fpth = cm_strcat3(path, "/", readmes[readme]); + struct stat s; + stat(fpth, &s); + FILE* fr = fopen(fpth, "r"); + if(fr != NULL) { + char* rmbuf = malloc(s.st_size + 1); + rmbuf[s.st_size] = 0; + fread(rmbuf, s.st_size, 1, fr); + addstring(&str, "
%h
\n", rmbuf); + fclose(fr); + } + } addstring(&str, "
\n"); addstring(&str, "
%s Server at %s Port %d
\n", tw_server, name, port); addstring(&str, " \n"); diff --git a/Server/tw_config.h b/Server/tw_config.h index 98bf244..4975d0e 100644 --- a/Server/tw_config.h +++ b/Server/tw_config.h @@ -28,6 +28,7 @@ #define MAX_MIME 1024 #define MAX_ICON 1024 #define MAX_INDEX 1024 +#define MAX_README 8 enum TW_DIR_TYPE { TW_DIR_ALLOW = 0, @@ -64,6 +65,8 @@ struct tw_config_entry { int icon_count; char* indexes[MAX_INDEX]; int index_count; + char* readmes[MAX_README]; + int readme_count; }; struct tw_config { diff --git a/Server/version.c b/Server/version.c index b68d001..8c753e8 100644 --- a/Server/version.c +++ b/Server/version.c @@ -4,7 +4,7 @@ #include "tw_version.h" -const char* tw_version = "0.00"; +const char* tw_version = "1.00"; const char* tw_platform = #if defined(PLATFORM) diff --git a/example.conf b/example.conf index 1a19160..e64da91 100644 --- a/example.conf +++ b/example.conf @@ -3,8 +3,8 @@ #LoadModule /home/nishi/SVN/tewi/trunk/Module/mod_example.so -Listen 8080 -#ListenSSL 443 +Listen 80 +ListenSSL 443 SSLKey key.pem SSLCertificate cert.pem @@ -22,6 +22,8 @@ Icon misc/parent /icons/parent.png DirectoryIndex index.html +Readme README + DocumentRoot /var/www BeginDirectory /