add --nocgi and --direxc

This commit is contained in:
randomuser 2021-07-23 20:12:36 -05:00
parent 57124b797d
commit e25d062322
1 changed files with 17 additions and 3 deletions

20
esgd.py
View File

@ -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: