def export(line): """ Write the full request/response of a request/response to a file. Usage: export [req|rsp] <reqid(s)> """ args = shlex.split(line) if len(args) < 2: print 'Requires req/rsp and and request id(s)' defer.returnValue(None) if args[0] not in ('req', 'rsp'): raise PappyException('Request or response not specified') reqs = yield load_reqlist(args[1]) for req in reqs: try: if args[0] == 'req': fname = 'req_%s.txt'%req.reqid with open(fname, 'w') as f: f.write(req.full_request) print 'Full request written to %s' % fname elif args[0] == 'rsp': fname = 'rsp_%s.txt'%req.reqid with open(fname, 'w') as f: f.write(req.full_response) print 'Full response written to %s' % fname except PappyException as e: print 'Unable to export %s: %s' % (req.reqid, e)
def untag(line): """ Remove a tag from requests Usage: untag <tag> <request ids> You can provide as many request ids as you want and the tag will be removed from all of them. If no ids are given, the tag will be removed from all in-context requests. """ args = shlex.split(line) if len(args) == 0: raise PappyException("Tag and request ids are required") tag = args[0] ids = [] if len(args) > 1: reqids = yield load_reqlist(args[1], False, ids_only=True) print 'Removing tag %s from %s' % (tag, ', '.join(reqids)) else: print "Removing tag %s from all in-context requests" % tag reqids = yield main_context_ids() for reqid in reqids: req = yield Request.load_request(reqid) if tag in req.tags: req.tags.discard(tag) if req.saved: yield req.async_save() if ids: print 'Tag %s removed from %s' % (tag, ', '.join(ids))
def export(line): """ Write the full request/response of a request/response to a file. Usage: export [req|rsp] <reqid(s)> """ args = shlex.split(line) if len(args) < 2: print 'Requires req/rsp and and request id(s)' defer.returnValue(None) if args[0] not in ('req', 'rsp'): raise PappyException('Request or response not specified') reqs = yield load_reqlist(args[1]) for req in reqs: try: if args[0] == 'req': fname = 'req_%s.txt' % req.reqid with open(fname, 'w') as f: f.write(req.full_request) print 'Full request written to %s' % fname elif args[0] == 'rsp': fname = 'rsp_%s.txt' % req.reqid with open(fname, 'w') as f: f.write(req.full_response) print 'Full response written to %s' % fname except PappyException as e: print 'Unable to export %s: %s' % (req.reqid, e)
def tag(line): """ Add a tag to requests. Usage: tag <tag> [request ids] You can tag as many requests as you want at the same time. If no ids are given, the tag will be applied to all in-context requests. """ args = shlex.split(line) if len(args) == 0: raise PappyException('Tag name is required') tag = args[0] if len(args) > 1: reqids = yield load_reqlist(args[1], False, ids_only=True) print 'Tagging %s with %s' % (', '.join(reqids), tag) else: print "Tagging all in-context requests with %s" % tag reqids = yield main_context_ids() for reqid in reqids: req = yield Request.load_request(reqid) if tag not in req.tags: req.tags.add(tag) if req.saved: yield req.async_save() else: print 'Request %s already has tag %s' % (req.reqid, tag)
def rpy(line): """ Copy python object definitions of requests. Usage: rpy <reqs> """ reqs = yield load_reqlist(line) for req in reqs: print pappyproxy.macros.req_obj_def(req)
def pretty_print_request(line): """ Print the body of the request pretty printed. Usage: pretty_print_request <format> <reqid(s)> """ args = shlex.split(line) if len(args) < 2: raise PappyException("Usage: pretty_print_request <format> <reqid(s)>") reqids = args[1] reqs = yield load_reqlist(reqids) for req in reqs: pretty_print_body(args[0], req.body)
def view_response_headers(line): """ View the headers of the response Usage: view_response_headers <reqid> """ reqs = yield load_reqlist(line) for req in reqs: if req.response: if len(reqs) > 1: print '-'*15 + (' %s ' % req.reqid) + '-'*15 view_full_message(req.response, True) else: print "Request %s does not have a response" % req.reqid
def view_full_response(line): """ View the full data of the response associated with a request Usage: view_full_response <reqid> """ reqs = yield load_reqlist(line) for req in reqs: if req.response: if len(reqs) > 1: print '-'*15 + (' %s ' % req.reqid) + '-'*15 view_full_message(req.response) else: print "Request %s does not have a response" % req.reqid
def view_response_bytes(line): """ View the full data of the response associated with a request Usage: view_request_bytes <reqid(s)> """ reqs = yield load_reqlist(line) for req in reqs: if req.response: if len(reqs) > 1: print '-' * 15 + (' %s ' % req.reqid) + '-' * 15 print req.response.full_message else: print "Request %s does not have a response" % req.reqid
def view_response_headers(line): """ View the headers of the response Usage: view_response_headers <reqid(s)> """ reqs = yield load_reqlist(line) for req in reqs: if req.response: if len(reqs) > 1: print '-' * 15 + (' %s ' % req.reqid) + '-' * 15 view_full_message(req.response, True) else: print "Request %s does not have a response" % req.reqid
def view_request_info(line): """ View information about request Usage: view_request_info <reqid(s)> """ args = shlex.split(line) reqids = args[0] reqs = yield load_reqlist(reqids) for req in reqs: print '' print_request_extended(req) print ''
def pretty_print_response(line): """ Print the body of the request pretty printed. Usage: pretty_print_request <format> <reqid(s)> """ args = shlex.split(line) if len(args) < 2: raise PappyException("Usage: pretty_print_request <format> <reqid(s)>") reqids = args[1] reqs = yield load_reqlist(reqids) for req in reqs: if req.response: pretty_print_body(args[0], req.response.body) else: print 'No response associated with request %s' % req.reqid
def view_full_request(line): """ View the full data of the request Usage: view_full_request <reqid(s)> """ args = shlex.split(line) reqid = args[0] reqs = yield load_reqlist(reqid) for req in reqs: if len(reqs) > 1: print 'Request %s:' % req.reqid view_full_message(req) if len(reqs) > 1: print '-' * 30 print ''
def view_full_request(line): """ View the full data of the request Usage: view_full_request <reqid(s)> """ args = shlex.split(line) reqid = args[0] reqs = yield load_reqlist(reqid) for req in reqs: if len(reqs) > 1: print 'Request %s:' % req.reqid view_full_message(req) if len(reqs) > 1: print '-'*30 print ''
def view_request_bytes(line): """ View the raw bytes of the request. Use this if you want to redirect output to a file. Usage: view_request_bytes <reqid(s)> """ args = shlex.split(line) reqid = args[0] reqs = yield load_reqlist(reqid) for req in reqs: if len(reqs) > 1: print 'Request %s:' % req.reqid print req.full_message if len(reqs) > 1: print '-'*30 print ''
def view_request_bytes(line): """ View the raw bytes of the request. Use this if you want to redirect output to a file. Usage: view_request_bytes <reqid(s)> """ args = shlex.split(line) reqid = args[0] reqs = yield load_reqlist(reqid) for req in reqs: if len(reqs) > 1: print 'Request %s:' % req.reqid print req.full_message if len(reqs) > 1: print '-' * 30 print ''
def view_request_info(line): """ View information about request Usage: view_request_info <reqid> [u] If 'u' is given as an additional argument, the unmangled version of the request will be displayed. """ args = shlex.split(line) reqids = args[0] reqs = yield load_reqlist(reqids) for req in reqs: print '' print_request_extended(req) print ''
def clrtag(line): """ Clear all the tags from requests Usage: clrtag <request ids> """ args = shlex.split(line) if len(args) == 0: raise PappyException('No request IDs given') reqs = yield load_reqlist(args[0], False) for req in reqs: if req.tags: req.tags = set() print 'Tags cleared from request %s' % (req.reqid) if req.saved: yield req.async_save()
def generate_macro(line): """ Generate a macro script with request objects Usage: generate_macro <name> [reqs] """ if line == '': raise PappyException('Macro name is required') args = shlex.split(line) name = args[0] if len(args) > 1: reqs = yield load_reqlist(args[1]) else: reqs = [] script_str = macro_from_requests(reqs) fname = 'macro_%s.py' % name with open(fname, 'wc') as f: f.write(script_str) print 'Wrote script to %s' % fname
def view_full_request(line): """ View the full data of the request Usage: view_full_request <reqid> [u] If 'u' is given as an additional argument, the unmangled version of the request will be displayed. """ args = shlex.split(line) reqid = args[0] reqs = yield load_reqlist(reqid) for req in reqs: if len(reqs) > 1: print 'Request %s:' % req.reqid print '' view_full_message(req) if len(reqs) > 1: print '-'*30
def print_params_cmd(line): """ View the headers of the request Usage: view_request_headers <reqid(s)> """ args = shlex.split(line) reqid = args[0] if len(args) > 1: keys = args[1:] else: keys = None reqs = yield load_reqlist(reqid) for req in reqs: if len(reqs) > 1: print 'Request %s:' % req.reqid print_params(req, keys) if len(reqs) > 1: print '-'*30
def print_params_cmd(line): """ View the headers of the request Usage: view_request_headers <reqid(s)> """ args = shlex.split(line) reqid = args[0] if len(args) > 1: keys = args[1:] else: keys = None reqs = yield load_reqlist(reqid) for req in reqs: if len(reqs) > 1: print 'Request %s:' % req.reqid print_params(req, keys) if len(reqs) > 1: print '-' * 30
def save(line): args = shlex.split(line) reqids = args[0] reqs = yield load_reqlist(reqids) for req in reqs: yield req.async_deep_save()