]> Git repositories of Nishi - tewi.git/commitdiff
add ShowPort/HidePort
authorNishi <nishi@nishi.boats>
Sun, 22 Sep 2024 13:43:47 +0000 (13:43 +0000)
committerNishi <nishi@nishi.boats>
Sun, 22 Sep 2024 13:43:47 +0000 (13:43 +0000)
git-svn-id: file:///raid/svn-personal/tewi/trunk@123 8739d7e6-ffea-ec47-b151-bdff447c6205

Manpage/tewi.conf.5.tmpl
Server/config.c
Server/server.c
Server/tw_config.h
Server/tw_version.h

index 77434df728fabb1c5e5bc8ad991dc4fb699cc8fb..6280a17b6e6505fc3cef73b59beab94f855e5a60 100644 (file)
@@ -18,6 +18,8 @@ Specifies the port(s) to be listened on.
 Specifies the document root.
 .It Pa "LoadModule"
 Loads the module.
+.It Pa "HidePort" "ShowPort"
+Shows/Hides the port in directory listing, and the default error page.
 .It Pa "MIMEType"
 Specifies the MIME type for files.
 \fBall\fR can be used instead of the extension if you want to make all extensions appear as same MIME.
index a61ded1b0754dfe8e3d368723e87cac851dd3f0f..9fd3fb0eef96d86c3fc9ce183fbbd1cfa045732f 100644 (file)
@@ -84,6 +84,7 @@ void tw_config_init(void) {
        config.root.icon_count = 0;
        config.root.index_count = 0;
        config.root.readme_count = 0;
+       config.root.hideport = 0;
        config.vhost_count = 0;
        config.module_count = 0;
        config.extension = NULL;
@@ -185,6 +186,7 @@ int tw_config_read(const char* path) {
                                                                current->icon_count = 0;
                                                                current->index_count = 0;
                                                                current->readme_count = 0;
+                                                               current->hideport = -1;
                                                                int i;
                                                                current->name = cm_strdup(vhost);
                                                                current->port = -1;
@@ -216,6 +218,10 @@ int tw_config_read(const char* path) {
                                                                ;
                                                        config.ports[j] = port;
                                                }
+                                       } else if(cm_strcaseequ(r[0], "HidePort")) {
+                                               current->hideport = 1;
+                                       } else if(cm_strcaseequ(r[0], "ShowPort")) {
+                                               current->hideport = 0;
                                        } else if(cm_strcaseequ(r[0], "SSLKey")) {
                                                if(r[1] == NULL) {
                                                        cm_log("Config", "Missing path at line %d", ln);
index 43516152e523c11ba656b409e0ec18c7a164d245..4a4857ca76d6744ac9bb8768999a2f45de20a394 100644 (file)
@@ -284,9 +284,14 @@ const char* tw_http_status(int code) {
        }
 }
 
-char* tw_http_default_error(int code, char* name, int port) {
+char* tw_http_default_error(int code, char* name, int port, struct tw_config_entry* vhost) {
        char address[1024];
-       sprintf(address, "<address>%s Server at %s Port %d</address>", tw_server, name, port);
+
+       if((vhost->hideport == -1 ? config.root.hideport : vhost->hideport) == 1) {
+               sprintf(address, "<address>%s Server at %s</address>", tw_server, name, port);
+       } else {
+               sprintf(address, "<address>%s Server at %s Port %d</address>", tw_server, name, port);
+       }
 
        char* st = cm_strdup(tw_http_status(code));
        char* st2;
@@ -305,8 +310,8 @@ char* tw_http_default_error(int code, char* name, int port) {
        return buffer;
 }
 
-void tw_http_error(SSL* ssl, int sock, int error, char* name, int port) {
-       char* str = tw_http_default_error(error, name, port);
+void tw_http_error(SSL* ssl, int sock, int error, char* name, int port, struct tw_config_entry* vhost) {
+       char* str = tw_http_default_error(error, name, port, vhost);
        tw_process_page(ssl, sock, tw_http_status(error), "text/html", NULL, str, strlen(str), 0, 0);
        free(str);
 }
@@ -525,7 +530,7 @@ int32_t tw_server_pass(void* ptr) {
                                        break;
                                }
                                if(co == _TW_MODULE_ERROR) {
-                                       tw_http_error(s, sock, (ret & 0xffff00) >> 8, name, port);
+                                       tw_http_error(s, sock, (ret & 0xffff00) >> 8, name, port, vhost_entry);
                                        break;
                                }
                        }
@@ -565,7 +570,7 @@ int32_t tw_server_pass(void* ptr) {
                        struct stat st;
                        if(!rej && stat(path, &st) == 0) {
                                if(!tw_permission_allowed(path, addr, req, vhost_entry)) {
-                                       tw_http_error(s, sock, 403, name, port);
+                                       tw_http_error(s, sock, 403, name, port, vhost_entry);
                                } else if(S_ISDIR(st.st_mode)) {
                                        if(req.path[strlen(req.path) - 1] != '/') {
                                                cm_log("Server", "Accessing directory without the slash at the end");
@@ -737,7 +742,12 @@ int32_t tw_server_pass(void* ptr) {
                                                                free(fpth);
                                                        }
                                                        addstring(&str, "               <hr>\n");
-                                                       addstring(&str, "               <address>%s Server at %s Port %d</address>\n", tw_server, name, port);
+                                                       int hp = vhost_entry->hideport == -1 ? config.root.hideport : vhost_entry->hideport;
+                                                       if(hp == 0) {
+                                                               addstring(&str, "               <address>%s Server at %s Port %d</address>\n", tw_server, name, port);
+                                                       } else {
+                                                               addstring(&str, "               <address>%s Server at %s</address>\n", tw_server, name, port);
+                                                       }
                                                        addstring(&str, "       </body>\n");
                                                        addstring(&str, "</html>\n");
                                                        tw_process_page(s, sock, tw_http_status(200), "text/html", NULL, str, strlen(str), 0, 0);
@@ -761,7 +771,7 @@ int32_t tw_server_pass(void* ptr) {
                                        fclose(f);
                                }
                        } else {
-                               tw_http_error(s, sock, 404, name, port);
+                               tw_http_error(s, sock, 404, name, port, vhost_entry);
                        }
                        free(path);
                }
@@ -769,7 +779,7 @@ int32_t tw_server_pass(void* ptr) {
                free(host);
        } else if(ret == -1) {
        } else {
-               tw_http_error(s, sock, 400, name, port);
+               tw_http_error(s, sock, 400, name, port, &config.root);
        }
        tw_free_request(&req);
 cleanup:
index 27afb4cca4b48a54f2a602669bf3ce4a0e7e8360..1ba9826ccacc9c3a51c890c0c0f7db6cd9bb26a7 100644 (file)
@@ -60,6 +60,7 @@ struct tw_config_entry {
        char* sslkey;
        char* sslcert;
        char* root;
+       int hideport;
        struct tw_dir_entry dirs[MAX_DIRS];
        int dir_count;
        struct tw_mime_entry mimes[MAX_DIRS];
index 640f0dba1923377bc503dbd8c389ea78b5c0b0b7..fb05dca441b4efeeff9c606966b6b0b4825cb45c 100644 (file)
@@ -3,7 +3,7 @@
 #ifndef __TW_VERSION_H__
 #define __TW_VERSION_H__
 
-#define TW_VERSION "1.02A\0"
+#define TW_VERSION "1.03\0"
 
 const char* tw_get_version(void);
 const char* tw_get_platform(void);