From 372dd38dbf2e5acd62c978b4b2568b6961e7736d Mon Sep 17 00:00:00 2001 From: Stefan Hagen Date: Thu, 30 Aug 2018 00:06:12 +0200 Subject: [PATCH] Move configuration to config.h Fix Fix --- Makefile | 6 +++++- README | 7 +++++-- config.def.h | 4 ++++ gopherproxy.c | 5 +++-- 4 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 config.def.h diff --git a/Makefile b/Makefile index ab0d675..50c8b2b 100644 --- a/Makefile +++ b/Makefile @@ -10,12 +10,16 @@ LDFLAGS += -static # Linux #CPPFLAGS += -D_DEFAULT_SOURCE -all: $(BIN) +all: config.h $(BIN) $(BIN): $(OBJ) $(CC) $(OBJ) $(LDFLAGS) -o $@ +config.h: + $(CP) config.def.h config.h + $(OBJ): Makefile clean: rm -f $(BIN) $(OBJ) + diff --git a/README b/README index 485688d..f9c207f 100644 --- a/README +++ b/README @@ -58,9 +58,12 @@ Notes Tor support: To accept tor gopher browsing, remove the -static flag from LDFLAGS in the -Makefile and modify the isblacklisted() function in gopherproxy.c to allow -.onion addresses. +Makefile set allow_tor to 1 in config.h to allow .onion addresses. +Port restriction: + +For security reasons, only port 70 and 7070 are accepted as valid gopher ports. +If you want allow all ports, set allow_all_ports in config.h Nginx buffering issues: diff --git a/config.def.h b/config.def.h new file mode 100644 index 0000000..88eb35f --- /dev/null +++ b/config.def.h @@ -0,0 +1,4 @@ +/* gopherproxy config file */ + +static int allow_tor = 0; +static int allow_all_ports = 0; diff --git a/gopherproxy.c b/gopherproxy.c index e23c85d..63075cd 100644 --- a/gopherproxy.c +++ b/gopherproxy.c @@ -10,6 +10,7 @@ #include #include #include +#include "config.h" #define MAX_RESPONSETIMEOUT 10 /* timeout in seconds */ #define MAX_RESPONSESIZ 4000000 /* max download size in bytes */ @@ -134,9 +135,9 @@ isblacklisted(const char *host, const char *port, const char *path) { char *p; - if (strcmp(port, "70") && strcmp(port, "7070")) + if (allow_all_ports || (strcmp(port, "70") && strcmp(port, "7070"))) return 1; - if ((p = strstr(host, ".onion")) && strlen(p) == strlen(".onion")) + if (!allow_tor || ((p = strstr(host, ".onion")) && strlen(p) == strlen(".onion"))) return 1; return 0; } -- 2.18.0