From e25d06232265ceea286e02d59cc012e741a4d7b9 Mon Sep 17 00:00:00 2001 From: randomuser Date: Fri, 23 Jul 2021 20:12:36 -0500 Subject: [PATCH] add --nocgi and --direxc --- esgd.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/esgd.py b/esgd.py index 9669ad7..fd9eca8 100644 --- a/esgd.py +++ b/esgd.py @@ -109,9 +109,11 @@ class GopherServerLogic: ret = "gophermap" gph = True elif os.path.isdir(file): - ret = file + "/gophermap" + if file[-1] != "/": ret = file + "/gophermap" + else: ret = file + "gophermap" gph = True - elif os.path.isfile(file): ret = file + elif os.path.isfile(file): + ret = file else: raise RequestError("unreachable state") return (ret, gph) @@ -119,6 +121,11 @@ class GopherServerLogic: return os.access(file, os.F_OK|os.R_OK) def fileCGI(self, file): + if exempt != None: + for i in exempt: + if i in file: return False + if nocgi: + return False return os.access(file, os.F_OK|os.R_OK|os.X_OK) def notFound(self): @@ -172,7 +179,8 @@ class GopherServerLogic: return returned def serveFile(self, file, query, gph): - if self.fileCGI(file): fa = self.cgi(file, query) + if self.fileCGI(file): + fa = self.cgi(file, query) elif self.fileSendable(file): fa = self.fileToFileArray(file) else: @@ -216,6 +224,10 @@ def parseArgs(): help="port to host on") parse.add_argument("-d", "--dir", default="/var/gopher", help="directory to host from") + parse.add_argument("-ndx", "--direxc", + action="extend", nargs="*", + help="make directory-wide exception for file execution") + parse.add_argument("-nx", "--nocgi", action="store_true") return parse.parse_args() if __name__ == "__main__": @@ -227,6 +239,8 @@ if __name__ == "__main__": host = args.host port = args.port location = args.dir + exempt = args.direxc + nocgi = args.nocgi log.log("arguments good") try: with TCPServer((host, port), GopherHandler) as server: