2015-11-26 13:58:08 +00:00
|
|
|
from __future__ import absolute_import, division
|
2015-04-14 21:43:15 +00:00
|
|
|
import os
|
2015-09-11 10:26:52 +00:00
|
|
|
import traceback
|
2015-09-12 11:49:16 +00:00
|
|
|
import sys
|
|
|
|
|
2015-11-26 13:58:08 +00:00
|
|
|
import math
|
2012-02-07 03:39:37 +00:00
|
|
|
import urwid
|
2015-07-29 09:39:53 +00:00
|
|
|
|
2015-04-13 23:58:10 +00:00
|
|
|
from netlib import odict
|
2015-09-16 16:45:22 +00:00
|
|
|
from netlib.http import CONTENT_MISSING, Headers
|
2015-09-02 18:28:25 +00:00
|
|
|
from . import common, grideditor, signals, searchable, tabs
|
2015-03-29 06:21:54 +00:00
|
|
|
from . import flowdetailview
|
2015-09-12 11:49:16 +00:00
|
|
|
from .. import utils, controller, contentviews
|
2015-08-30 13:27:29 +00:00
|
|
|
from ..models import HTTPRequest, HTTPResponse, decoded
|
2015-09-11 10:26:52 +00:00
|
|
|
from ..exceptions import ContentViewException
|
2012-02-07 03:39:37 +00:00
|
|
|
|
2014-01-19 00:23:38 +00:00
|
|
|
|
2015-04-14 21:43:15 +00:00
|
|
|
class SearchError(Exception):
|
|
|
|
pass
|
2014-01-19 00:23:38 +00:00
|
|
|
|
|
|
|
|
2012-02-08 08:47:39 +00:00
|
|
|
def _mkhelp():
|
|
|
|
text = []
|
|
|
|
keys = [
|
2012-02-20 23:42:43 +00:00
|
|
|
("A", "accept all intercepted flows"),
|
|
|
|
("a", "accept this intercepted flow"),
|
2012-02-08 08:47:39 +00:00
|
|
|
("b", "save request/response body"),
|
2012-02-18 11:32:20 +00:00
|
|
|
("D", "duplicate flow"),
|
2015-10-11 14:04:18 +00:00
|
|
|
("d", "delete flow"),
|
2016-01-13 11:07:28 +00:00
|
|
|
("E", "export"),
|
2012-02-08 08:47:39 +00:00
|
|
|
("e", "edit request/response"),
|
2012-04-08 08:16:25 +00:00
|
|
|
("f", "load full body data"),
|
2012-04-01 22:30:35 +00:00
|
|
|
("m", "change body display mode for this entity"),
|
2015-05-30 00:03:28 +00:00
|
|
|
(None,
|
|
|
|
common.highlight_key("automatic", "a") +
|
|
|
|
[("text", ": automatic detection")]
|
|
|
|
),
|
|
|
|
(None,
|
|
|
|
common.highlight_key("hex", "e") +
|
|
|
|
[("text", ": Hex")]
|
|
|
|
),
|
|
|
|
(None,
|
|
|
|
common.highlight_key("html", "h") +
|
|
|
|
[("text", ": HTML")]
|
|
|
|
),
|
|
|
|
(None,
|
|
|
|
common.highlight_key("image", "i") +
|
|
|
|
[("text", ": Image")]
|
|
|
|
),
|
|
|
|
(None,
|
|
|
|
common.highlight_key("javascript", "j") +
|
|
|
|
[("text", ": JavaScript")]
|
|
|
|
),
|
|
|
|
(None,
|
|
|
|
common.highlight_key("json", "s") +
|
|
|
|
[("text", ": JSON")]
|
|
|
|
),
|
|
|
|
(None,
|
|
|
|
common.highlight_key("urlencoded", "u") +
|
|
|
|
[("text", ": URL-encoded data")]
|
|
|
|
),
|
|
|
|
(None,
|
|
|
|
common.highlight_key("raw", "r") +
|
|
|
|
[("text", ": raw data")]
|
|
|
|
),
|
|
|
|
(None,
|
|
|
|
common.highlight_key("xml", "x") +
|
|
|
|
[("text", ": XML")]
|
|
|
|
),
|
2012-04-01 22:30:35 +00:00
|
|
|
("M", "change default body display mode"),
|
|
|
|
("p", "previous flow"),
|
2015-04-07 03:59:38 +00:00
|
|
|
("P", "copy response(content/headers) to clipboard"),
|
2012-04-01 22:30:35 +00:00
|
|
|
("r", "replay request"),
|
2012-02-18 01:45:22 +00:00
|
|
|
("V", "revert changes to request"),
|
2012-02-08 08:47:39 +00:00
|
|
|
("v", "view body in external viewer"),
|
2012-02-08 09:55:48 +00:00
|
|
|
("w", "save all flows matching current limit"),
|
|
|
|
("W", "save this flow"),
|
2012-05-16 06:16:44 +00:00
|
|
|
("x", "delete body"),
|
2012-02-08 08:47:39 +00:00
|
|
|
("z", "encode/decode a request/response"),
|
2015-03-29 22:53:10 +00:00
|
|
|
("tab", "next tab"),
|
2015-03-31 21:34:58 +00:00
|
|
|
("h, l", "previous tab, next tab"),
|
2012-02-08 08:47:39 +00:00
|
|
|
("space", "next flow"),
|
2012-02-08 09:28:15 +00:00
|
|
|
("|", "run script on this flow"),
|
2015-03-29 22:53:10 +00:00
|
|
|
("/", "search (case sensitive)"),
|
2014-02-22 03:36:35 +00:00
|
|
|
("n", "repeat search forward"),
|
|
|
|
("N", "repeat search backwards"),
|
2012-02-08 08:47:39 +00:00
|
|
|
]
|
|
|
|
text.extend(common.format_keyvals(keys, key="key", val="text", indent=4))
|
|
|
|
return text
|
|
|
|
help_context = _mkhelp()
|
|
|
|
|
2012-03-22 01:57:57 +00:00
|
|
|
footer = [
|
|
|
|
('heading_key', "?"), ":help ",
|
|
|
|
('heading_key', "q"), ":back ",
|
|
|
|
]
|
2012-02-08 08:47:39 +00:00
|
|
|
|
2012-02-07 03:39:37 +00:00
|
|
|
|
2015-03-13 12:03:46 +00:00
|
|
|
class FlowViewHeader(urwid.WidgetWrap):
|
2016-01-27 09:12:18 +00:00
|
|
|
|
2012-02-07 03:39:37 +00:00
|
|
|
def __init__(self, master, f):
|
|
|
|
self.master, self.flow = master, f
|
2015-03-22 04:33:25 +00:00
|
|
|
self._w = common.format_flow(
|
|
|
|
f,
|
|
|
|
False,
|
|
|
|
extended=True,
|
|
|
|
padding=0,
|
|
|
|
hostheader=self.master.showhost
|
|
|
|
)
|
2015-03-22 02:58:32 +00:00
|
|
|
signals.flow_change.connect(self.sig_flow_change)
|
|
|
|
|
|
|
|
def sig_flow_change(self, sender, flow):
|
|
|
|
if flow == self.flow:
|
|
|
|
self._w = common.format_flow(
|
|
|
|
flow,
|
|
|
|
False,
|
|
|
|
extended=True,
|
|
|
|
padding=0,
|
|
|
|
hostheader=self.master.showhost
|
|
|
|
)
|
2012-02-07 03:39:37 +00:00
|
|
|
|
|
|
|
|
2015-03-22 08:00:41 +00:00
|
|
|
cache = utils.LRUCache(200)
|
2012-02-07 03:39:37 +00:00
|
|
|
|
2015-03-29 04:40:43 +00:00
|
|
|
TAB_REQ = 0
|
|
|
|
TAB_RESP = 1
|
2012-02-07 03:39:37 +00:00
|
|
|
|
2015-04-14 21:43:15 +00:00
|
|
|
|
2015-03-29 04:40:43 +00:00
|
|
|
class FlowView(tabs.Tabs):
|
2013-12-25 03:57:54 +00:00
|
|
|
highlight_color = "focusfield"
|
2013-12-25 03:50:29 +00:00
|
|
|
|
2015-03-29 04:40:43 +00:00
|
|
|
def __init__(self, master, state, flow, tab_offset):
|
2012-02-07 03:39:37 +00:00
|
|
|
self.master, self.state, self.flow = master, state, flow
|
2015-03-29 04:40:43 +00:00
|
|
|
tabs.Tabs.__init__(self,
|
2015-05-30 00:03:28 +00:00
|
|
|
[
|
|
|
|
(self.tab_request, self.view_request),
|
|
|
|
(self.tab_response, self.view_response),
|
|
|
|
(self.tab_details, self.view_details),
|
|
|
|
],
|
|
|
|
tab_offset
|
|
|
|
)
|
2015-03-29 04:40:43 +00:00
|
|
|
self.show()
|
2013-12-25 03:50:29 +00:00
|
|
|
self.last_displayed_body = None
|
2015-03-22 02:58:32 +00:00
|
|
|
signals.flow_change.connect(self.sig_flow_change)
|
|
|
|
|
2015-03-29 04:40:43 +00:00
|
|
|
def tab_request(self):
|
|
|
|
if self.flow.intercepted and not self.flow.reply.acked and not self.flow.response:
|
|
|
|
return "Request intercepted"
|
|
|
|
else:
|
|
|
|
return "Request"
|
|
|
|
|
|
|
|
def tab_response(self):
|
|
|
|
if self.flow.intercepted and not self.flow.reply.acked and self.flow.response:
|
|
|
|
return "Response intercepted"
|
|
|
|
else:
|
|
|
|
return "Response"
|
|
|
|
|
2015-03-29 06:21:54 +00:00
|
|
|
def tab_details(self):
|
|
|
|
return "Detail"
|
|
|
|
|
2015-03-29 04:40:43 +00:00
|
|
|
def view_request(self):
|
|
|
|
return self.conn_text(self.flow.request)
|
|
|
|
|
|
|
|
def view_response(self):
|
|
|
|
return self.conn_text(self.flow.response)
|
|
|
|
|
2015-03-29 06:21:54 +00:00
|
|
|
def view_details(self):
|
|
|
|
return flowdetailview.flowdetails(self.state, self.flow)
|
2015-03-29 04:40:43 +00:00
|
|
|
|
2015-03-22 02:58:32 +00:00
|
|
|
def sig_flow_change(self, sender, flow):
|
|
|
|
if flow == self.flow:
|
2015-03-29 04:40:43 +00:00
|
|
|
self.show()
|
2012-02-07 03:39:37 +00:00
|
|
|
|
2015-09-12 11:49:16 +00:00
|
|
|
def content_view(self, viewmode, message):
|
2015-09-26 15:41:14 +00:00
|
|
|
if message.content == CONTENT_MISSING:
|
2015-03-22 08:08:18 +00:00
|
|
|
msg, body = "", [urwid.Text([("error", "[content missing]")])]
|
2015-09-12 11:49:16 +00:00
|
|
|
return msg, body
|
2012-04-08 07:23:05 +00:00
|
|
|
else:
|
2015-03-22 08:08:18 +00:00
|
|
|
full = self.state.get_flow_setting(
|
|
|
|
self.flow,
|
2015-03-29 04:40:43 +00:00
|
|
|
(self.tab_offset, "fullcontents"),
|
2015-03-22 08:08:18 +00:00
|
|
|
False
|
|
|
|
)
|
|
|
|
if full:
|
2015-05-30 00:03:28 +00:00
|
|
|
limit = sys.maxsize
|
2013-12-26 04:04:18 +00:00
|
|
|
else:
|
2015-09-12 11:49:16 +00:00
|
|
|
limit = contentviews.VIEW_CUTOFF
|
2015-09-11 11:37:52 +00:00
|
|
|
return cache.get(
|
2015-09-11 10:26:52 +00:00
|
|
|
self._get_content_view,
|
2015-04-14 21:43:15 +00:00
|
|
|
viewmode,
|
2015-09-12 11:49:16 +00:00
|
|
|
message,
|
2015-09-19 09:50:02 +00:00
|
|
|
limit,
|
|
|
|
(bytes(message.headers), message.content) # Cache invalidation
|
2015-04-14 21:43:15 +00:00
|
|
|
)
|
2013-12-24 01:28:20 +00:00
|
|
|
|
2015-09-19 09:50:02 +00:00
|
|
|
def _get_content_view(self, viewmode, message, max_lines, _):
|
2015-09-12 11:49:16 +00:00
|
|
|
|
2015-09-11 10:26:52 +00:00
|
|
|
try:
|
2015-09-12 11:49:16 +00:00
|
|
|
description, lines = contentviews.get_content_view(
|
2015-09-26 15:41:14 +00:00
|
|
|
viewmode, message.content, headers=message.headers
|
2015-09-11 10:26:52 +00:00
|
|
|
)
|
|
|
|
except ContentViewException:
|
|
|
|
s = "Content viewer failed: \n" + traceback.format_exc()
|
|
|
|
signals.add_event(s, "error")
|
2015-09-12 11:49:16 +00:00
|
|
|
description, lines = contentviews.get_content_view(
|
2015-09-26 15:41:14 +00:00
|
|
|
contentviews.get("Raw"), message.content, headers=message.headers
|
2015-09-11 10:26:52 +00:00
|
|
|
)
|
2015-09-11 11:37:52 +00:00
|
|
|
description = description.replace("Raw", "Couldn't parse: falling back to Raw")
|
2015-09-12 11:49:16 +00:00
|
|
|
|
|
|
|
# Give hint that you have to tab for the response.
|
|
|
|
if description == "No content" and isinstance(message, HTTPRequest):
|
|
|
|
description = "No request content (press tab to view response)"
|
|
|
|
|
2015-11-26 13:58:08 +00:00
|
|
|
# If the users has a wide terminal, he gets fewer lines; this should not be an issue.
|
|
|
|
chars_per_line = 80
|
|
|
|
max_chars = max_lines * chars_per_line
|
|
|
|
total_chars = 0
|
2015-09-12 11:49:16 +00:00
|
|
|
text_objects = []
|
|
|
|
for line in lines:
|
2015-11-26 13:58:08 +00:00
|
|
|
txt = []
|
|
|
|
for (style, text) in line:
|
|
|
|
if total_chars + len(text) > max_chars:
|
2016-01-27 09:12:18 +00:00
|
|
|
text = text[:max_chars - total_chars]
|
2015-11-26 13:58:08 +00:00
|
|
|
txt.append((style, text))
|
|
|
|
total_chars += len(text)
|
|
|
|
if total_chars == max_chars:
|
|
|
|
break
|
|
|
|
|
|
|
|
# round up to the next line.
|
|
|
|
total_chars = int(math.ceil(total_chars / chars_per_line) * chars_per_line)
|
|
|
|
|
|
|
|
text_objects.append(urwid.Text(txt))
|
|
|
|
if total_chars == max_chars:
|
2015-09-12 11:49:16 +00:00
|
|
|
text_objects.append(urwid.Text([
|
|
|
|
("highlight", "Stopped displaying data after %d lines. Press " % max_lines),
|
|
|
|
("key", "f"),
|
|
|
|
("highlight", " to load all data.")
|
|
|
|
]))
|
|
|
|
break
|
|
|
|
|
2015-09-11 11:37:52 +00:00
|
|
|
return description, text_objects
|
2015-09-11 10:26:52 +00:00
|
|
|
|
2015-03-29 02:27:17 +00:00
|
|
|
def viewmode_get(self):
|
|
|
|
override = self.state.get_flow_setting(
|
|
|
|
self.flow,
|
2015-03-29 04:40:43 +00:00
|
|
|
(self.tab_offset, "prettyview")
|
2015-03-29 02:27:17 +00:00
|
|
|
)
|
2013-12-26 04:04:18 +00:00
|
|
|
return self.state.default_body_view if override is None else override
|
|
|
|
|
2015-03-29 02:54:29 +00:00
|
|
|
def conn_text(self, conn):
|
|
|
|
if conn:
|
|
|
|
txt = common.format_keyvals(
|
2015-09-05 18:45:58 +00:00
|
|
|
[(h + ":", v) for (h, v) in conn.headers.fields],
|
2015-04-14 21:43:15 +00:00
|
|
|
key = "header",
|
|
|
|
val = "text"
|
|
|
|
)
|
2015-03-29 02:54:29 +00:00
|
|
|
viewmode = self.viewmode_get()
|
|
|
|
msg, body = self.content_view(viewmode, conn)
|
2012-04-01 23:10:55 +00:00
|
|
|
|
2015-04-14 21:43:15 +00:00
|
|
|
cols = [
|
|
|
|
urwid.Text(
|
2015-03-29 02:54:29 +00:00
|
|
|
[
|
|
|
|
("heading", msg),
|
|
|
|
]
|
2015-09-12 11:49:16 +00:00
|
|
|
),
|
2015-04-14 21:43:15 +00:00
|
|
|
urwid.Text(
|
|
|
|
[
|
2015-03-29 02:54:29 +00:00
|
|
|
" ",
|
|
|
|
('heading', "["),
|
|
|
|
('heading_key', "m"),
|
2015-05-30 00:03:28 +00:00
|
|
|
('heading', (":%s]" % viewmode.name)),
|
2015-03-29 02:54:29 +00:00
|
|
|
],
|
|
|
|
align="right"
|
|
|
|
)
|
2015-09-12 11:49:16 +00:00
|
|
|
]
|
2015-03-29 02:54:29 +00:00
|
|
|
title = urwid.AttrWrap(urwid.Columns(cols), "heading")
|
2013-12-24 01:28:20 +00:00
|
|
|
|
2015-03-29 02:54:29 +00:00
|
|
|
txt.append(title)
|
|
|
|
txt.extend(body)
|
|
|
|
else:
|
|
|
|
txt = [
|
|
|
|
urwid.Text(""),
|
|
|
|
urwid.Text(
|
|
|
|
[
|
|
|
|
("highlight", "No response. Press "),
|
|
|
|
("key", "e"),
|
|
|
|
("highlight", " and edit any aspect to add one."),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
]
|
|
|
|
return searchable.Searchable(self.state, txt)
|
2012-02-07 03:39:37 +00:00
|
|
|
|
2012-02-08 20:38:11 +00:00
|
|
|
def set_method_raw(self, m):
|
|
|
|
if m:
|
|
|
|
self.flow.request.method = m
|
2015-03-22 02:58:32 +00:00
|
|
|
signals.flow_change.send(self, flow = self.flow)
|
2012-02-08 20:38:11 +00:00
|
|
|
|
2012-02-07 03:39:37 +00:00
|
|
|
def edit_method(self, m):
|
2012-02-08 20:38:11 +00:00
|
|
|
if m == "e":
|
2015-03-22 00:32:24 +00:00
|
|
|
signals.status_prompt.send(
|
2015-03-22 00:59:34 +00:00
|
|
|
prompt = "Method",
|
2015-03-22 00:32:24 +00:00
|
|
|
text = self.flow.request.method,
|
|
|
|
callback = self.set_method_raw
|
|
|
|
)
|
2012-02-08 20:38:11 +00:00
|
|
|
else:
|
2015-02-10 18:24:21 +00:00
|
|
|
for i in common.METHOD_OPTIONS:
|
2012-02-08 20:38:11 +00:00
|
|
|
if i[1] == m:
|
|
|
|
self.flow.request.method = i[0].upper()
|
2015-03-22 02:58:32 +00:00
|
|
|
signals.flow_change.send(self, flow = self.flow)
|
2012-02-07 03:39:37 +00:00
|
|
|
|
|
|
|
def set_url(self, url):
|
|
|
|
request = self.flow.request
|
2014-09-03 21:44:54 +00:00
|
|
|
try:
|
|
|
|
request.url = str(url)
|
|
|
|
except ValueError:
|
2012-02-07 03:39:37 +00:00
|
|
|
return "Invalid URL."
|
2015-03-22 02:58:32 +00:00
|
|
|
signals.flow_change.send(self, flow = self.flow)
|
2012-02-07 03:39:37 +00:00
|
|
|
|
|
|
|
def set_resp_code(self, code):
|
|
|
|
response = self.flow.response
|
|
|
|
try:
|
2015-09-17 13:16:33 +00:00
|
|
|
response.status_code = int(code)
|
2012-02-07 03:39:37 +00:00
|
|
|
except ValueError:
|
|
|
|
return None
|
|
|
|
import BaseHTTPServer
|
2015-05-30 00:03:28 +00:00
|
|
|
if int(code) in BaseHTTPServer.BaseHTTPRequestHandler.responses:
|
|
|
|
response.msg = BaseHTTPServer.BaseHTTPRequestHandler.responses[
|
|
|
|
int(code)][0]
|
2015-03-22 02:58:32 +00:00
|
|
|
signals.flow_change.send(self, flow = self.flow)
|
2012-02-07 03:39:37 +00:00
|
|
|
|
|
|
|
def set_resp_msg(self, msg):
|
|
|
|
response = self.flow.response
|
|
|
|
response.msg = msg
|
2015-03-22 02:58:32 +00:00
|
|
|
signals.flow_change.send(self, flow = self.flow)
|
2012-02-07 03:39:37 +00:00
|
|
|
|
2015-09-05 18:45:58 +00:00
|
|
|
def set_headers(self, fields, conn):
|
|
|
|
conn.headers = Headers(fields)
|
2015-03-22 04:28:13 +00:00
|
|
|
signals.flow_change.send(self, flow = self.flow)
|
2012-02-08 03:43:11 +00:00
|
|
|
|
2012-02-09 03:47:32 +00:00
|
|
|
def set_query(self, lst, conn):
|
2015-04-13 23:58:10 +00:00
|
|
|
conn.set_query(odict.ODict(lst))
|
2015-03-22 04:28:13 +00:00
|
|
|
signals.flow_change.send(self, flow = self.flow)
|
2012-02-09 03:47:32 +00:00
|
|
|
|
2012-08-19 01:15:54 +00:00
|
|
|
def set_path_components(self, lst, conn):
|
2015-04-17 00:54:29 +00:00
|
|
|
conn.set_path_components(lst)
|
2015-03-22 04:28:13 +00:00
|
|
|
signals.flow_change.send(self, flow = self.flow)
|
2012-08-19 01:15:54 +00:00
|
|
|
|
2012-02-10 01:35:23 +00:00
|
|
|
def set_form(self, lst, conn):
|
2015-04-13 23:58:10 +00:00
|
|
|
conn.set_form_urlencoded(odict.ODict(lst))
|
2015-03-22 04:28:13 +00:00
|
|
|
signals.flow_change.send(self, flow = self.flow)
|
2012-02-10 01:35:23 +00:00
|
|
|
|
2012-02-23 03:27:08 +00:00
|
|
|
def edit_form(self, conn):
|
2012-03-18 21:12:06 +00:00
|
|
|
self.master.view_grideditor(
|
2015-03-22 04:28:13 +00:00
|
|
|
grideditor.URLEncodedFormEditor(
|
|
|
|
self.master,
|
|
|
|
conn.get_form_urlencoded().lst,
|
|
|
|
self.set_form,
|
|
|
|
conn
|
|
|
|
)
|
2012-03-18 21:12:06 +00:00
|
|
|
)
|
2012-02-23 03:27:08 +00:00
|
|
|
|
|
|
|
def edit_form_confirm(self, key, conn):
|
|
|
|
if key == "y":
|
|
|
|
self.edit_form(conn)
|
|
|
|
|
2015-04-14 21:43:15 +00:00
|
|
|
def set_cookies(self, lst, conn):
|
|
|
|
od = odict.ODict(lst)
|
|
|
|
conn.set_cookies(od)
|
|
|
|
signals.flow_change.send(self, flow = self.flow)
|
|
|
|
|
2015-04-17 00:54:29 +00:00
|
|
|
def set_setcookies(self, data, conn):
|
|
|
|
conn.set_cookies(data)
|
2015-04-15 22:57:12 +00:00
|
|
|
signals.flow_change.send(self, flow = self.flow)
|
|
|
|
|
2012-02-07 03:39:37 +00:00
|
|
|
def edit(self, part):
|
2015-03-29 04:40:43 +00:00
|
|
|
if self.tab_offset == TAB_REQ:
|
2014-12-23 22:14:55 +00:00
|
|
|
message = self.flow.request
|
2012-02-07 03:39:37 +00:00
|
|
|
else:
|
|
|
|
if not self.flow.response:
|
2014-03-10 16:01:30 +00:00
|
|
|
self.flow.response = HTTPResponse(
|
2015-09-17 13:16:33 +00:00
|
|
|
self.flow.request.http_version,
|
2015-09-05 18:45:58 +00:00
|
|
|
200, "OK", Headers(), ""
|
2013-06-08 23:14:34 +00:00
|
|
|
)
|
|
|
|
self.flow.response.reply = controller.DummyReply()
|
2014-12-23 22:14:55 +00:00
|
|
|
message = self.flow.response
|
2012-02-07 03:39:37 +00:00
|
|
|
|
|
|
|
self.flow.backup()
|
2015-04-14 21:43:15 +00:00
|
|
|
if message == self.flow.request and part == "c":
|
|
|
|
self.master.view_grideditor(
|
|
|
|
grideditor.CookieEditor(
|
|
|
|
self.master,
|
|
|
|
message.get_cookies().lst,
|
|
|
|
self.set_cookies,
|
|
|
|
message
|
|
|
|
)
|
|
|
|
)
|
2015-04-15 22:57:12 +00:00
|
|
|
if message == self.flow.response and part == "c":
|
|
|
|
self.master.view_grideditor(
|
|
|
|
grideditor.SetCookieEditor(
|
|
|
|
self.master,
|
2015-04-17 00:54:29 +00:00
|
|
|
message.get_cookies(),
|
2015-04-15 22:57:12 +00:00
|
|
|
self.set_setcookies,
|
|
|
|
message
|
|
|
|
)
|
|
|
|
)
|
2012-02-09 03:40:31 +00:00
|
|
|
if part == "r":
|
2014-12-23 22:14:55 +00:00
|
|
|
with decoded(message):
|
2015-03-22 04:33:25 +00:00
|
|
|
# Fix an issue caused by some editors when editing a
|
|
|
|
# request/response body. Many editors make it hard to save a
|
|
|
|
# file without a terminating newline on the last line. When
|
|
|
|
# editing message bodies, this can cause problems. For now, I
|
|
|
|
# just strip the newlines off the end of the body when we return
|
|
|
|
# from an editor.
|
2014-12-23 22:14:55 +00:00
|
|
|
c = self.master.spawn_editor(message.content or "")
|
|
|
|
message.content = c.rstrip("\n")
|
2012-02-10 01:35:23 +00:00
|
|
|
elif part == "f":
|
2014-12-23 22:14:55 +00:00
|
|
|
if not message.get_form_urlencoded() and message.content:
|
2015-03-22 00:32:24 +00:00
|
|
|
signals.status_prompt_onekey.send(
|
|
|
|
prompt = "Existing body is not a URL-encoded form. Clear and edit?",
|
|
|
|
keys = [
|
2012-02-23 03:27:08 +00:00
|
|
|
("yes", "y"),
|
|
|
|
("no", "n"),
|
|
|
|
],
|
2015-03-22 00:32:24 +00:00
|
|
|
callback = self.edit_form_confirm,
|
|
|
|
args = (message,)
|
2012-02-23 03:27:08 +00:00
|
|
|
)
|
|
|
|
else:
|
2014-12-23 22:14:55 +00:00
|
|
|
self.edit_form(message)
|
2012-02-07 03:39:37 +00:00
|
|
|
elif part == "h":
|
2015-03-22 04:28:13 +00:00
|
|
|
self.master.view_grideditor(
|
|
|
|
grideditor.HeaderEditor(
|
|
|
|
self.master,
|
2015-09-05 18:45:58 +00:00
|
|
|
message.headers.fields,
|
2015-03-22 04:28:13 +00:00
|
|
|
self.set_headers,
|
|
|
|
message
|
|
|
|
)
|
|
|
|
)
|
2012-08-19 01:15:54 +00:00
|
|
|
elif part == "p":
|
2014-12-23 22:14:55 +00:00
|
|
|
p = message.get_path_components()
|
2015-03-22 04:33:25 +00:00
|
|
|
self.master.view_grideditor(
|
|
|
|
grideditor.PathEditor(
|
|
|
|
self.master,
|
|
|
|
p,
|
|
|
|
self.set_path_components,
|
|
|
|
message
|
|
|
|
)
|
|
|
|
)
|
2012-02-09 03:47:32 +00:00
|
|
|
elif part == "q":
|
2015-03-22 04:33:25 +00:00
|
|
|
self.master.view_grideditor(
|
|
|
|
grideditor.QueryEditor(
|
|
|
|
self.master,
|
|
|
|
message.get_query().lst,
|
|
|
|
self.set_query, message
|
|
|
|
)
|
|
|
|
)
|
2015-03-29 22:53:10 +00:00
|
|
|
elif part == "u":
|
2015-03-22 00:32:24 +00:00
|
|
|
signals.status_prompt.send(
|
2015-03-22 00:59:34 +00:00
|
|
|
prompt = "URL",
|
2015-03-22 00:32:24 +00:00
|
|
|
text = message.url,
|
|
|
|
callback = self.set_url
|
|
|
|
)
|
2015-03-29 22:53:10 +00:00
|
|
|
elif part == "m":
|
2015-03-22 00:32:24 +00:00
|
|
|
signals.status_prompt_onekey.send(
|
|
|
|
prompt = "Method",
|
|
|
|
keys = common.METHOD_OPTIONS,
|
|
|
|
callback = self.edit_method
|
|
|
|
)
|
2015-04-14 21:43:15 +00:00
|
|
|
elif part == "o":
|
2015-03-22 00:32:24 +00:00
|
|
|
signals.status_prompt.send(
|
2015-03-22 00:59:34 +00:00
|
|
|
prompt = "Code",
|
2015-09-17 13:16:33 +00:00
|
|
|
text = str(message.status_code),
|
2015-03-22 00:32:24 +00:00
|
|
|
callback = self.set_resp_code
|
|
|
|
)
|
2015-03-29 22:53:10 +00:00
|
|
|
elif part == "m":
|
2015-03-22 00:32:24 +00:00
|
|
|
signals.status_prompt.send(
|
2015-03-22 00:59:34 +00:00
|
|
|
prompt = "Message",
|
2015-03-22 00:32:24 +00:00
|
|
|
text = message.msg,
|
|
|
|
callback = self.set_resp_msg
|
|
|
|
)
|
2015-03-22 02:58:32 +00:00
|
|
|
signals.flow_change.send(self, flow = self.flow)
|
2012-02-07 03:39:37 +00:00
|
|
|
|
2012-02-08 01:07:17 +00:00
|
|
|
def _view_nextprev_flow(self, np, flow):
|
|
|
|
try:
|
|
|
|
idx = self.state.view.index(flow)
|
|
|
|
except IndexError:
|
|
|
|
return
|
|
|
|
if np == "next":
|
|
|
|
new_flow, new_idx = self.state.get_next(idx)
|
|
|
|
else:
|
|
|
|
new_flow, new_idx = self.state.get_prev(idx)
|
2013-07-28 06:00:49 +00:00
|
|
|
if new_flow is None:
|
2015-03-20 22:19:20 +00:00
|
|
|
signals.status_message.send(message="No more flows!")
|
2015-03-22 04:18:53 +00:00
|
|
|
else:
|
|
|
|
signals.pop_view_state.send(self)
|
2015-03-29 04:40:43 +00:00
|
|
|
self.master.view_flow(new_flow, self.tab_offset)
|
2012-02-08 01:07:17 +00:00
|
|
|
|
|
|
|
def view_next_flow(self, flow):
|
|
|
|
return self._view_nextprev_flow("next", flow)
|
|
|
|
|
|
|
|
def view_prev_flow(self, flow):
|
|
|
|
return self._view_nextprev_flow("prev", flow)
|
|
|
|
|
2012-04-01 22:30:35 +00:00
|
|
|
def change_this_display_mode(self, t):
|
2014-11-10 16:35:28 +00:00
|
|
|
self.state.add_flow_setting(
|
|
|
|
self.flow,
|
2015-03-29 04:40:43 +00:00
|
|
|
(self.tab_offset, "prettyview"),
|
2015-09-12 11:49:16 +00:00
|
|
|
contentviews.get_by_shortcut(t)
|
2014-11-10 16:35:28 +00:00
|
|
|
)
|
2015-03-22 02:58:32 +00:00
|
|
|
signals.flow_change.send(self, flow = self.flow)
|
2012-03-19 22:11:53 +00:00
|
|
|
|
2012-05-16 06:16:44 +00:00
|
|
|
def delete_body(self, t):
|
|
|
|
if t == "m":
|
2014-03-09 20:59:53 +00:00
|
|
|
val = CONTENT_MISSING
|
2012-05-16 06:16:44 +00:00
|
|
|
else:
|
|
|
|
val = None
|
2015-03-29 04:40:43 +00:00
|
|
|
if self.tab_offset == TAB_REQ:
|
2012-05-16 06:16:44 +00:00
|
|
|
self.flow.request.content = val
|
|
|
|
else:
|
|
|
|
self.flow.response.content = val
|
2015-03-22 02:58:32 +00:00
|
|
|
signals.flow_change.send(self, flow = self.flow)
|
2012-05-16 06:16:44 +00:00
|
|
|
|
2012-02-07 03:39:37 +00:00
|
|
|
def keypress(self, size, key):
|
2015-03-31 20:25:50 +00:00
|
|
|
key = super(self.__class__, self).keypress(size, key)
|
|
|
|
|
2012-02-07 03:39:37 +00:00
|
|
|
if key == " ":
|
2012-02-08 01:07:17 +00:00
|
|
|
self.view_next_flow(self.flow)
|
2012-03-27 21:21:48 +00:00
|
|
|
return
|
2012-02-07 03:39:37 +00:00
|
|
|
|
|
|
|
key = common.shortcuts(key)
|
2015-03-29 04:40:43 +00:00
|
|
|
if self.tab_offset == TAB_REQ:
|
2012-02-07 03:39:37 +00:00
|
|
|
conn = self.flow.request
|
2015-03-29 22:53:10 +00:00
|
|
|
elif self.tab_offset == TAB_RESP:
|
2012-02-07 03:39:37 +00:00
|
|
|
conn = self.flow.response
|
2015-03-29 22:53:10 +00:00
|
|
|
else:
|
|
|
|
conn = None
|
2012-02-07 03:39:37 +00:00
|
|
|
|
2015-03-31 20:25:50 +00:00
|
|
|
if key in ("up", "down", "page up", "page down"):
|
2012-02-07 03:39:37 +00:00
|
|
|
# Why doesn't this just work??
|
2015-03-13 12:03:46 +00:00
|
|
|
self._w.keypress(size, key)
|
2012-02-07 03:39:37 +00:00
|
|
|
elif key == "a":
|
2014-12-23 19:33:42 +00:00
|
|
|
self.flow.accept_intercept(self.master)
|
2015-10-08 02:31:33 +00:00
|
|
|
signals.flow_change.send(self, flow = self.flow)
|
2012-02-07 03:39:37 +00:00
|
|
|
elif key == "A":
|
|
|
|
self.master.accept_all()
|
2015-10-08 02:31:33 +00:00
|
|
|
signals.flow_change.send(self, flow = self.flow)
|
2012-02-09 04:00:37 +00:00
|
|
|
elif key == "d":
|
|
|
|
if self.state.flow_count() == 1:
|
2012-02-20 23:42:43 +00:00
|
|
|
self.master.view_flowlist()
|
2015-05-30 00:03:28 +00:00
|
|
|
elif self.state.view.index(self.flow) == len(self.state.view) - 1:
|
2012-02-09 04:00:37 +00:00
|
|
|
self.view_prev_flow(self.flow)
|
|
|
|
else:
|
|
|
|
self.view_next_flow(self.flow)
|
|
|
|
f = self.flow
|
|
|
|
f.kill(self.master)
|
|
|
|
self.state.delete_flow(f)
|
2012-02-18 11:32:20 +00:00
|
|
|
elif key == "D":
|
|
|
|
f = self.master.duplicate_flow(self.flow)
|
|
|
|
self.master.view_flow(f)
|
2015-03-20 22:19:20 +00:00
|
|
|
signals.status_message.send(message="Duplicated.")
|
2012-04-01 22:30:35 +00:00
|
|
|
elif key == "p":
|
|
|
|
self.view_prev_flow(self.flow)
|
|
|
|
elif key == "r":
|
|
|
|
r = self.master.replay_request(self.flow)
|
|
|
|
if r:
|
2015-03-20 22:19:20 +00:00
|
|
|
signals.status_message.send(message=r)
|
2015-03-22 02:58:32 +00:00
|
|
|
signals.flow_change.send(self, flow = self.flow)
|
2012-02-18 01:45:22 +00:00
|
|
|
elif key == "V":
|
2012-04-03 21:47:57 +00:00
|
|
|
if not self.flow.modified():
|
2015-03-20 22:19:20 +00:00
|
|
|
signals.status_message.send(message="Flow not modified.")
|
2012-04-03 21:47:57 +00:00
|
|
|
return
|
2012-02-07 03:39:37 +00:00
|
|
|
self.state.revert(self.flow)
|
2015-03-22 02:58:32 +00:00
|
|
|
signals.flow_change.send(self, flow = self.flow)
|
2015-03-20 22:19:20 +00:00
|
|
|
signals.status_message.send(message="Reverted.")
|
2012-02-07 03:39:37 +00:00
|
|
|
elif key == "W":
|
2015-03-22 00:59:34 +00:00
|
|
|
signals.status_prompt_path.send(
|
|
|
|
prompt = "Save this flow",
|
2015-03-22 00:32:24 +00:00
|
|
|
callback = self.master.save_one_flow,
|
|
|
|
args = (self.flow,)
|
2012-02-07 03:39:37 +00:00
|
|
|
)
|
2015-10-11 14:04:18 +00:00
|
|
|
elif key == "E":
|
|
|
|
signals.status_prompt_onekey.send(
|
|
|
|
self,
|
|
|
|
prompt = "Export",
|
|
|
|
keys = (
|
|
|
|
("as curl command", "c"),
|
2016-01-13 11:07:28 +00:00
|
|
|
("as python code", "p"),
|
2016-01-13 13:51:13 +00:00
|
|
|
("as raw request", "r"),
|
2015-10-11 14:04:18 +00:00
|
|
|
),
|
|
|
|
callback = common.export_prompt,
|
|
|
|
args = (self.flow,)
|
|
|
|
)
|
2012-02-07 03:39:37 +00:00
|
|
|
elif key == "|":
|
2015-03-22 00:59:34 +00:00
|
|
|
signals.status_prompt_path.send(
|
|
|
|
prompt = "Send flow to script",
|
2015-03-22 00:32:24 +00:00
|
|
|
callback = self.master.run_script_once,
|
|
|
|
args = (self.flow,)
|
2012-02-07 03:39:37 +00:00
|
|
|
)
|
2015-03-29 22:53:10 +00:00
|
|
|
|
2015-03-31 20:25:50 +00:00
|
|
|
if not conn and key in set(list("befgmxvz")):
|
2015-03-29 22:53:10 +00:00
|
|
|
signals.status_message.send(
|
|
|
|
message = "Tab to the request or response",
|
|
|
|
expire = 1
|
2012-05-16 06:16:44 +00:00
|
|
|
)
|
2015-03-29 22:53:10 +00:00
|
|
|
elif conn:
|
|
|
|
if key == "b":
|
|
|
|
if self.tab_offset == TAB_REQ:
|
2015-04-14 21:43:15 +00:00
|
|
|
common.ask_save_body(
|
|
|
|
"q", self.master, self.state, self.flow
|
|
|
|
)
|
2015-03-29 22:53:10 +00:00
|
|
|
else:
|
2015-04-14 21:43:15 +00:00
|
|
|
common.ask_save_body(
|
|
|
|
"s", self.master, self.state, self.flow
|
|
|
|
)
|
2015-03-29 22:53:10 +00:00
|
|
|
elif key == "e":
|
|
|
|
if self.tab_offset == TAB_REQ:
|
|
|
|
signals.status_prompt_onekey.send(
|
|
|
|
prompt = "Edit request",
|
|
|
|
keys = (
|
2015-04-15 22:57:12 +00:00
|
|
|
("cookies", "c"),
|
2015-03-29 22:53:10 +00:00
|
|
|
("query", "q"),
|
|
|
|
("path", "p"),
|
|
|
|
("url", "u"),
|
|
|
|
("header", "h"),
|
|
|
|
("form", "f"),
|
|
|
|
("raw body", "r"),
|
|
|
|
("method", "m"),
|
|
|
|
),
|
|
|
|
callback = self.edit
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
signals.status_prompt_onekey.send(
|
|
|
|
prompt = "Edit response",
|
|
|
|
keys = (
|
2015-04-15 22:57:12 +00:00
|
|
|
("cookies", "c"),
|
2015-04-14 21:43:15 +00:00
|
|
|
("code", "o"),
|
2015-03-29 22:53:10 +00:00
|
|
|
("message", "m"),
|
|
|
|
("header", "h"),
|
|
|
|
("raw body", "r"),
|
|
|
|
),
|
|
|
|
callback = self.edit
|
|
|
|
)
|
|
|
|
key = None
|
|
|
|
elif key == "f":
|
|
|
|
signals.status_message.send(message="Loading all body data...")
|
|
|
|
self.state.add_flow_setting(
|
|
|
|
self.flow,
|
|
|
|
(self.tab_offset, "fullcontents"),
|
|
|
|
True
|
|
|
|
)
|
|
|
|
signals.flow_change.send(self, flow = self.flow)
|
|
|
|
signals.status_message.send(message="")
|
2015-04-07 03:59:38 +00:00
|
|
|
elif key == "P":
|
2015-03-29 22:53:10 +00:00
|
|
|
if self.tab_offset == TAB_REQ:
|
|
|
|
scope = "q"
|
|
|
|
else:
|
|
|
|
scope = "s"
|
|
|
|
common.ask_copy_part(scope, self.flow, self.master, self.state)
|
|
|
|
elif key == "m":
|
2015-09-12 11:49:16 +00:00
|
|
|
p = list(contentviews.view_prompts)
|
2015-03-29 22:53:10 +00:00
|
|
|
p.insert(0, ("Clear", "C"))
|
|
|
|
signals.status_prompt_onekey.send(
|
|
|
|
self,
|
|
|
|
prompt = "Display mode",
|
|
|
|
keys = p,
|
|
|
|
callback = self.change_this_display_mode
|
|
|
|
)
|
|
|
|
key = None
|
|
|
|
elif key == "x":
|
|
|
|
signals.status_prompt_onekey.send(
|
|
|
|
prompt = "Delete body",
|
|
|
|
keys = (
|
|
|
|
("completely", "c"),
|
|
|
|
("mark as missing", "m"),
|
|
|
|
),
|
|
|
|
callback = self.delete_body
|
|
|
|
)
|
|
|
|
key = None
|
|
|
|
elif key == "v":
|
|
|
|
if conn.content:
|
2015-09-05 18:45:58 +00:00
|
|
|
t = conn.headers.get("content-type")
|
2015-05-30 00:03:28 +00:00
|
|
|
if "EDITOR" in os.environ or "PAGER" in os.environ:
|
2015-03-29 22:53:10 +00:00
|
|
|
self.master.spawn_external_viewer(conn.content, t)
|
|
|
|
else:
|
|
|
|
signals.status_message.send(
|
|
|
|
message = "Error! Set $EDITOR or $PAGER."
|
|
|
|
)
|
|
|
|
elif key == "z":
|
2012-04-03 21:47:57 +00:00
|
|
|
self.flow.backup()
|
2015-09-05 18:45:58 +00:00
|
|
|
e = conn.headers.get("content-encoding", "identity")
|
2012-08-18 06:14:30 +00:00
|
|
|
if e != "identity":
|
2013-07-29 06:14:11 +00:00
|
|
|
if not conn.decode():
|
2015-03-22 04:33:25 +00:00
|
|
|
signals.status_message.send(
|
|
|
|
message = "Could not decode - invalid data?"
|
|
|
|
)
|
2012-02-07 03:39:37 +00:00
|
|
|
else:
|
2015-03-22 00:32:24 +00:00
|
|
|
signals.status_prompt_onekey.send(
|
|
|
|
prompt = "Select encoding: ",
|
|
|
|
keys = (
|
2012-02-07 03:39:37 +00:00
|
|
|
("gzip", "z"),
|
|
|
|
("deflate", "d"),
|
|
|
|
),
|
2015-03-22 00:32:24 +00:00
|
|
|
callback = self.encode_callback,
|
|
|
|
args = (conn,)
|
2012-02-07 03:39:37 +00:00
|
|
|
)
|
2015-03-22 02:58:32 +00:00
|
|
|
signals.flow_change.send(self, flow = self.flow)
|
2015-03-31 20:25:50 +00:00
|
|
|
return key
|
2012-02-07 03:39:37 +00:00
|
|
|
|
|
|
|
def encode_callback(self, key, conn):
|
|
|
|
encoding_map = {
|
|
|
|
"z": "gzip",
|
|
|
|
"d": "deflate",
|
|
|
|
}
|
|
|
|
conn.encode(encoding_map[key])
|
2015-03-22 02:58:32 +00:00
|
|
|
signals.flow_change.send(self, flow = self.flow)
|