add --nocgi and --direxc
This commit is contained in:
parent
57124b797d
commit
e25d062322
20
esgd.py
20
esgd.py
|
@ -109,9 +109,11 @@ class GopherServerLogic:
|
||||||
ret = "gophermap"
|
ret = "gophermap"
|
||||||
gph = True
|
gph = True
|
||||||
elif os.path.isdir(file):
|
elif os.path.isdir(file):
|
||||||
ret = file + "/gophermap"
|
if file[-1] != "/": ret = file + "/gophermap"
|
||||||
|
else: ret = file + "gophermap"
|
||||||
gph = True
|
gph = True
|
||||||
elif os.path.isfile(file): ret = file
|
elif os.path.isfile(file):
|
||||||
|
ret = file
|
||||||
else: raise RequestError("unreachable state")
|
else: raise RequestError("unreachable state")
|
||||||
return (ret, gph)
|
return (ret, gph)
|
||||||
|
|
||||||
|
@ -119,6 +121,11 @@ class GopherServerLogic:
|
||||||
return os.access(file, os.F_OK|os.R_OK)
|
return os.access(file, os.F_OK|os.R_OK)
|
||||||
|
|
||||||
def fileCGI(self, file):
|
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)
|
return os.access(file, os.F_OK|os.R_OK|os.X_OK)
|
||||||
|
|
||||||
def notFound(self):
|
def notFound(self):
|
||||||
|
@ -172,7 +179,8 @@ class GopherServerLogic:
|
||||||
return returned
|
return returned
|
||||||
|
|
||||||
def serveFile(self, file, query, gph):
|
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):
|
elif self.fileSendable(file):
|
||||||
fa = self.fileToFileArray(file)
|
fa = self.fileToFileArray(file)
|
||||||
else:
|
else:
|
||||||
|
@ -216,6 +224,10 @@ def parseArgs():
|
||||||
help="port to host on")
|
help="port to host on")
|
||||||
parse.add_argument("-d", "--dir", default="/var/gopher",
|
parse.add_argument("-d", "--dir", default="/var/gopher",
|
||||||
help="directory to host from")
|
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()
|
return parse.parse_args()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -227,6 +239,8 @@ if __name__ == "__main__":
|
||||||
host = args.host
|
host = args.host
|
||||||
port = args.port
|
port = args.port
|
||||||
location = args.dir
|
location = args.dir
|
||||||
|
exempt = args.direxc
|
||||||
|
nocgi = args.nocgi
|
||||||
log.log("arguments good")
|
log.log("arguments good")
|
||||||
try:
|
try:
|
||||||
with TCPServer((host, port), GopherHandler) as server:
|
with TCPServer((host, port), GopherHandler) as server:
|
||||||
|
|
Loading…
Reference in New Issue