mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 18:18:25 +00:00
Import cache store control into console controller
This commit is contained in:
parent
d11dd742d8
commit
061cea89da
@ -19,6 +19,7 @@ import cStringIO
|
|||||||
import urwid.curses_display
|
import urwid.curses_display
|
||||||
import urwid
|
import urwid
|
||||||
import controller, utils, filt, proxy, flow
|
import controller, utils, filt, proxy, flow
|
||||||
|
import recorder
|
||||||
|
|
||||||
|
|
||||||
class Stop(Exception): pass
|
class Stop(Exception): pass
|
||||||
@ -707,6 +708,7 @@ class ConsoleState(flow.State):
|
|||||||
flow.State.__init__(self)
|
flow.State.__init__(self)
|
||||||
self.focus = None
|
self.focus = None
|
||||||
self.beep = None
|
self.beep = None
|
||||||
|
self.store = None
|
||||||
|
|
||||||
self.view_body_mode = VIEW_BODY_RAW
|
self.view_body_mode = VIEW_BODY_RAW
|
||||||
self.view_flow_mode = VIEW_FLOW_REQUEST
|
self.view_flow_mode = VIEW_FLOW_REQUEST
|
||||||
@ -727,6 +729,8 @@ class ConsoleState(flow.State):
|
|||||||
return flow.State.add_request(self, req)
|
return flow.State.add_request(self, req)
|
||||||
|
|
||||||
def add_response(self, resp):
|
def add_response(self, resp):
|
||||||
|
if self.store is not None:
|
||||||
|
self.store.save_response(resp)
|
||||||
f = flow.State.add_response(self, resp)
|
f = flow.State.add_response(self, resp)
|
||||||
if self.focus is None:
|
if self.focus is None:
|
||||||
self.set_focus(0)
|
self.set_focus(0)
|
||||||
@ -737,6 +741,9 @@ class ConsoleState(flow.State):
|
|||||||
self.set_focus(self.focus)
|
self.set_focus(self.focus)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
def start_recording(self, recorder):
|
||||||
|
self.store = recorder
|
||||||
|
|
||||||
def get_focus(self):
|
def get_focus(self):
|
||||||
if not self.view or self.focus is None:
|
if not self.view or self.focus is None:
|
||||||
return None, None
|
return None, None
|
||||||
@ -815,6 +822,9 @@ class ConsoleMaster(controller.Master):
|
|||||||
self.stickycookie = None
|
self.stickycookie = None
|
||||||
self.stickyhosts = {}
|
self.stickyhosts = {}
|
||||||
|
|
||||||
|
if options.cache is not None:
|
||||||
|
self.state.start_recording(recorder.Recorder(options))
|
||||||
|
|
||||||
def spawn_external_viewer(self, data, contenttype):
|
def spawn_external_viewer(self, data, contenttype):
|
||||||
if contenttype:
|
if contenttype:
|
||||||
ext = mimetypes.guess_extension(contenttype) or ""
|
ext = mimetypes.guess_extension(contenttype) or ""
|
||||||
|
@ -101,7 +101,10 @@ class Recorder:
|
|||||||
for cookie in options.cookies:
|
for cookie in options.cookies:
|
||||||
self.cookies[cookie] = True
|
self.cookies[cookie] = True
|
||||||
except AttributeError: pass
|
except AttributeError: pass
|
||||||
|
try:
|
||||||
self.verbosity = options.verbose
|
self.verbosity = options.verbose
|
||||||
|
except AttributeError:
|
||||||
|
self.verbosity = False
|
||||||
self.storedir = options.cache
|
self.storedir = options.cache
|
||||||
self.patterns = []
|
self.patterns = []
|
||||||
self.indexfp = None
|
self.indexfp = None
|
||||||
@ -253,6 +256,7 @@ class Recorder:
|
|||||||
print >> self.indexfp, 'cookies:', ','.join(self.cookies)
|
print >> self.indexfp, 'cookies:', ','.join(self.cookies)
|
||||||
print >> self.indexfp , path
|
print >> self.indexfp , path
|
||||||
print >> self.indexfp , ""
|
print >> self.indexfp , ""
|
||||||
|
self.indexfp.flush()
|
||||||
|
|
||||||
|
|
||||||
def get_response(self, request):
|
def get_response(self, request):
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
import re, os, subprocess, datetime, textwrap
|
import re, os, subprocess, datetime, textwrap, errno
|
||||||
|
|
||||||
|
|
||||||
def format_timestamp(s):
|
def format_timestamp(s):
|
||||||
@ -341,3 +341,12 @@ def make_bogus_cert(path):
|
|||||||
stdin=subprocess.PIPE
|
stdin=subprocess.PIPE
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def mkdir_p(path):
|
||||||
|
try:
|
||||||
|
os.makedirs(path)
|
||||||
|
except OSError as exc:
|
||||||
|
if exc.errno == errno.EEXIST:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
|
22
mitmproxy
22
mitmproxy
@ -72,6 +72,23 @@ if __name__ == '__main__':
|
|||||||
)
|
)
|
||||||
parser.add_option_group(group)
|
parser.add_option_group(group)
|
||||||
|
|
||||||
|
group = OptionGroup(
|
||||||
|
parser,
|
||||||
|
"Recorder",
|
||||||
|
"Options controlling recorder behavior"
|
||||||
|
)
|
||||||
|
group.add_option(
|
||||||
|
"-w", "--store", action="store",
|
||||||
|
type = "str", dest="cache", default=None,
|
||||||
|
help = "Session store location"
|
||||||
|
)
|
||||||
|
group.add_option(
|
||||||
|
"-C", "--cookies", action="append",
|
||||||
|
type = "str", dest="cookies", default=[],
|
||||||
|
help = "Persistent client cookies already set or generated in client"
|
||||||
|
)
|
||||||
|
parser.add_option_group(group)
|
||||||
|
|
||||||
options, args = parser.parse_args()
|
options, args = parser.parse_args()
|
||||||
certpath = os.path.expanduser(options.cert)
|
certpath = os.path.expanduser(options.cert)
|
||||||
|
|
||||||
@ -82,6 +99,11 @@ if __name__ == '__main__':
|
|||||||
proxy.config = proxy.Config(
|
proxy.config = proxy.Config(
|
||||||
certpath
|
certpath
|
||||||
)
|
)
|
||||||
|
if options.cache is not None:
|
||||||
|
utils.mkdir_p(options.cache)
|
||||||
|
if os.path.exists(options.cache + "/index.txt"):
|
||||||
|
print >> sys.stderr, "ERROR: data already recorded in %s"%options.cache
|
||||||
|
sys.exit(1)
|
||||||
server = proxy.ProxyServer(options.port, options.addr)
|
server = proxy.ProxyServer(options.port, options.addr)
|
||||||
m = console.ConsoleMaster(server, options)
|
m = console.ConsoleMaster(server, options)
|
||||||
|
|
||||||
|
13
mitmrecord
13
mitmrecord
@ -18,20 +18,11 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import sys, os.path, os, errno
|
import sys, os.path
|
||||||
from libmproxy import proxy, controller, record, utils
|
from libmproxy import proxy, controller, record, utils
|
||||||
from libmproxy import VERSION
|
from libmproxy import VERSION
|
||||||
from optparse import OptionParser, OptionGroup
|
from optparse import OptionParser, OptionGroup
|
||||||
|
|
||||||
def mkdir_p(path):
|
|
||||||
try:
|
|
||||||
os.makedirs(path)
|
|
||||||
except OSError as exc:
|
|
||||||
if exc.errno == errno.EEXIST:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
raise
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = OptionParser(
|
parser = OptionParser(
|
||||||
usage = "%prog [options] output",
|
usage = "%prog [options] output",
|
||||||
@ -85,7 +76,7 @@ if __name__ == '__main__':
|
|||||||
certpath
|
certpath
|
||||||
)
|
)
|
||||||
server = proxy.ProxyServer(options.port)
|
server = proxy.ProxyServer(options.port)
|
||||||
mkdir_p(options.cache)
|
utils.mkdir_p(options.cache)
|
||||||
if os.path.exists(options.cache + "/index.txt"):
|
if os.path.exists(options.cache + "/index.txt"):
|
||||||
print >> sys.stderr, "ERROR: data already recorded in %s"%options.cache
|
print >> sys.stderr, "ERROR: data already recorded in %s"%options.cache
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
Loading…
Reference in New Issue
Block a user