Add a --nocraft option to pathod that turns off crafting.
This commit is contained in:
parent
622a2b5607
commit
190392ea13
|
@ -18,6 +18,19 @@ class PathodHandler(tcp.BaseHandler):
|
||||||
def handle_sni(self, connection):
|
def handle_sni(self, connection):
|
||||||
self.sni = connection.get_servername()
|
self.sni = connection.get_servername()
|
||||||
|
|
||||||
|
def serve_crafted(self, crafted, request_log):
|
||||||
|
response_log = crafted.serve(self.wfile, self.server.check_size)
|
||||||
|
self.server.add_log(
|
||||||
|
dict(
|
||||||
|
type = "crafted",
|
||||||
|
request=request_log,
|
||||||
|
response=response_log
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if response_log["disconnect"]:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def handle_request(self):
|
def handle_request(self):
|
||||||
"""
|
"""
|
||||||
Returns True if handling should continue.
|
Returns True if handling should continue.
|
||||||
|
@ -39,9 +52,18 @@ class PathodHandler(tcp.BaseHandler):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
method, path, httpversion = parts
|
|
||||||
|
|
||||||
|
method, path, httpversion = parts
|
||||||
headers = http.read_headers(self.rfile)
|
headers = http.read_headers(self.rfile)
|
||||||
|
request_log = dict(
|
||||||
|
path = path,
|
||||||
|
method = method,
|
||||||
|
headers = headers.lst,
|
||||||
|
httpversion = httpversion,
|
||||||
|
sni = self.sni,
|
||||||
|
remote_address = self.client_address,
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
content = http.read_http_body_request(
|
content = http.read_http_body_request(
|
||||||
self.rfile, self.wfile, headers, httpversion, None
|
self.rfile, self.wfile, headers, httpversion, None
|
||||||
|
@ -57,12 +79,11 @@ class PathodHandler(tcp.BaseHandler):
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
crafted = None
|
|
||||||
for i in self.server.anchors:
|
for i in self.server.anchors:
|
||||||
if i[0].match(path):
|
if i[0].match(path):
|
||||||
crafted = i[1]
|
return self.serve_crafted(i[1], request_log)
|
||||||
|
|
||||||
if not crafted and path.startswith(self.server.prefix):
|
if not self.server.nocraft and path.startswith(self.server.prefix):
|
||||||
spec = urllib.unquote(path)[len(self.server.prefix):]
|
spec = urllib.unquote(path)[len(self.server.prefix):]
|
||||||
try:
|
try:
|
||||||
crafted = rparse.parse_response(self.server.request_settings, spec)
|
crafted = rparse.parse_response(self.server.request_settings, spec)
|
||||||
|
@ -73,29 +94,8 @@ class PathodHandler(tcp.BaseHandler):
|
||||||
)
|
)
|
||||||
except rparse.FileAccessDenied:
|
except rparse.FileAccessDenied:
|
||||||
crafted = rparse.PathodErrorResponse("Access Denied")
|
crafted = rparse.PathodErrorResponse("Access Denied")
|
||||||
|
return self.serve_crafted(crafted, request_log)
|
||||||
request_log = dict(
|
elif self.server.noweb:
|
||||||
path = path,
|
|
||||||
method = method,
|
|
||||||
headers = headers.lst,
|
|
||||||
sni = self.sni,
|
|
||||||
remote_address = self.client_address,
|
|
||||||
httpversion = httpversion,
|
|
||||||
)
|
|
||||||
if crafted:
|
|
||||||
response_log = crafted.serve(self.wfile, self.server.check_size)
|
|
||||||
self.server.add_log(
|
|
||||||
dict(
|
|
||||||
type = "crafted",
|
|
||||||
request=request_log,
|
|
||||||
response=response_log
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if response_log["disconnect"]:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
if self.server.noweb:
|
|
||||||
crafted = rparse.PathodErrorResponse("Access Denied")
|
crafted = rparse.PathodErrorResponse("Access Denied")
|
||||||
crafted.serve(self.wfile, self.server.check_size)
|
crafted.serve(self.wfile, self.server.check_size)
|
||||||
return False
|
return False
|
||||||
|
@ -150,7 +150,7 @@ class Pathod(tcp.TCPServer):
|
||||||
LOGBUF = 500
|
LOGBUF = 500
|
||||||
def __init__( self,
|
def __init__( self,
|
||||||
addr, ssloptions=None, prefix="/p/", staticdir=None, anchors=None,
|
addr, ssloptions=None, prefix="/p/", staticdir=None, anchors=None,
|
||||||
sizelimit=None, noweb=False
|
sizelimit=None, noweb=False, nocraft=False
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
addr: (address, port) tuple. If port is 0, a free port will be
|
addr: (address, port) tuple. If port is 0, a free port will be
|
||||||
|
@ -168,6 +168,7 @@ class Pathod(tcp.TCPServer):
|
||||||
self.sizelimit = sizelimit
|
self.sizelimit = sizelimit
|
||||||
self.app = app.app
|
self.app = app.app
|
||||||
self.noweb = noweb
|
self.noweb = noweb
|
||||||
|
self.nocraft = nocraft
|
||||||
self.app.config["pathod"] = self
|
self.app.config["pathod"] = self
|
||||||
self.log = []
|
self.log = []
|
||||||
self.logid = 0
|
self.logid = 0
|
||||||
|
|
7
pathod
7
pathod
|
@ -30,6 +30,10 @@ if __name__ == "__main__":
|
||||||
"--noweb", dest='noweb', default=False, action="store_true",
|
"--noweb", dest='noweb', default=False, action="store_true",
|
||||||
help='Disable web interface and API.'
|
help='Disable web interface and API.'
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--nocraft", dest='nocraft', default=False, action="store_true",
|
||||||
|
help='Disable response crafting. If anchors are specified, they still work.'
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--keyfile", dest='ssl_keyfile', default=None, type=str,
|
"--keyfile", dest='ssl_keyfile', default=None, type=str,
|
||||||
help='SSL key file. If not specified, a default key is used.'
|
help='SSL key file. If not specified, a default key is used.'
|
||||||
|
@ -85,7 +89,8 @@ if __name__ == "__main__":
|
||||||
staticdir = args.staticdir,
|
staticdir = args.staticdir,
|
||||||
anchors = alst,
|
anchors = alst,
|
||||||
sizelimit = sizelimit,
|
sizelimit = sizelimit,
|
||||||
noweb = args.noweb
|
noweb = args.noweb,
|
||||||
|
nocraft = args.nocraft
|
||||||
)
|
)
|
||||||
except pathod.PathodError, v:
|
except pathod.PathodError, v:
|
||||||
parser.error(str(v))
|
parser.error(str(v))
|
||||||
|
|
Loading…
Reference in New Issue