mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-30 11:19:23 +00:00
add option to expose webapp externally, remove distinct ip setting
This commit is contained in:
parent
729677cd85
commit
bb4748fb8f
@ -4,8 +4,8 @@ import argparse
|
|||||||
import shlex
|
import shlex
|
||||||
import os
|
import os
|
||||||
|
|
||||||
APP_DOMAIN = "mitm"
|
APP_HOST = "mitm"
|
||||||
APP_IP = "1.1.1.1"
|
APP_PORT = 80
|
||||||
|
|
||||||
class ParseException(Exception): pass
|
class ParseException(Exception): pass
|
||||||
class OptionException(Exception): pass
|
class OptionException(Exception): pass
|
||||||
@ -130,8 +130,9 @@ def get_common_options(options):
|
|||||||
|
|
||||||
return dict(
|
return dict(
|
||||||
app = options.app,
|
app = options.app,
|
||||||
app_ip = options.app_ip,
|
app_host = options.app_host,
|
||||||
app_domain = options.app_domain,
|
app_port = options.app_port,
|
||||||
|
app_external = options.app_external,
|
||||||
|
|
||||||
anticache = options.anticache,
|
anticache = options.anticache,
|
||||||
anticomp = options.anticomp,
|
anticomp = options.anticomp,
|
||||||
@ -263,15 +264,19 @@ def common_options(parser):
|
|||||||
help="Enable the mitmproxy web app."
|
help="Enable the mitmproxy web app."
|
||||||
)
|
)
|
||||||
group.add_argument(
|
group.add_argument(
|
||||||
"--appdomain",
|
"--app-host",
|
||||||
action="store", dest="app_domain", default=APP_DOMAIN, metavar="domain",
|
action="store", dest="app_host", default=APP_HOST, metavar="host",
|
||||||
help="Domain to serve the app from."
|
help="Domain to serve the app from. For transparent mode, use an IP when a DNS entry for the app domain is not present."
|
||||||
)
|
)
|
||||||
group.add_argument(
|
group.add_argument(
|
||||||
"--appip",
|
"--app-port",
|
||||||
action="store", dest="app_ip", default=APP_IP, metavar="ip",
|
action="store", dest="app_port", default=APP_PORT, type=int, metavar="80",
|
||||||
help="""IP to serve the app from. Useful for transparent mode, when a DNS
|
help="Port to serve the app from."
|
||||||
entry for the app domain is not present."""
|
)
|
||||||
|
group.add_argument(
|
||||||
|
"--app-external",
|
||||||
|
action="store_true", dest="app_external",
|
||||||
|
help="Serve the app outside of the proxy."
|
||||||
)
|
)
|
||||||
|
|
||||||
group = parser.add_argument_group("Client Replay")
|
group = parser.add_argument_group("Client Replay")
|
||||||
|
@ -423,7 +423,7 @@ class ConsoleMaster(flow.FlowMaster):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if options.app:
|
if options.app:
|
||||||
self.start_app(options.app_domain, options.app_ip)
|
self.start_app(self.o.app_host, self.o.app_port, self.o.app_external)
|
||||||
|
|
||||||
def start_stream(self, path):
|
def start_stream(self, path):
|
||||||
path = os.path.expanduser(path)
|
path = os.path.expanduser(path)
|
||||||
|
@ -128,7 +128,7 @@ class DumpMaster(flow.FlowMaster):
|
|||||||
self.add_event("Flow file corrupted. Stopped loading.")
|
self.add_event("Flow file corrupted. Stopped loading.")
|
||||||
|
|
||||||
if self.o.app:
|
if self.o.app:
|
||||||
self.start_app(self.o.app_domain, self.o.app_ip)
|
self.start_app(self.o.app_host, self.o.app_port, self.o.app_external)
|
||||||
|
|
||||||
def _readflow(self, path):
|
def _readflow(self, path):
|
||||||
path = os.path.expanduser(path)
|
path = os.path.expanduser(path)
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
This module provides more sophisticated flow tracking. These match requests
|
This module provides more sophisticated flow tracking. These match requests
|
||||||
with their responses, and provide filtering and interception facilities.
|
with their responses, and provide filtering and interception facilities.
|
||||||
"""
|
"""
|
||||||
import hashlib, Cookie, cookielib, copy, re, urlparse, os
|
import hashlib, Cookie, cookielib, copy, re, urlparse, os, threading
|
||||||
import time, urllib
|
import time, urllib
|
||||||
import tnetstring, filt, script, utils, encoding, proxy
|
import tnetstring, filt, script, utils, encoding, proxy
|
||||||
from email.utils import parsedate_tz, formatdate, mktime_tz
|
from email.utils import parsedate_tz, formatdate, mktime_tz
|
||||||
@ -1367,17 +1367,19 @@ class FlowMaster(controller.Master):
|
|||||||
self.stream = None
|
self.stream = None
|
||||||
app.mapp.config["PMASTER"] = self
|
app.mapp.config["PMASTER"] = self
|
||||||
|
|
||||||
def start_app(self, domain, ip):
|
def start_app(self, host, port, external):
|
||||||
|
if not external:
|
||||||
self.server.apps.add(
|
self.server.apps.add(
|
||||||
app.mapp,
|
app.mapp,
|
||||||
domain,
|
host,
|
||||||
80
|
port
|
||||||
)
|
|
||||||
self.server.apps.add(
|
|
||||||
app.mapp,
|
|
||||||
ip,
|
|
||||||
80
|
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
print host
|
||||||
|
threading.Thread(target=app.mapp.run,kwargs={
|
||||||
|
"use_reloader": False,
|
||||||
|
"host": host,
|
||||||
|
"port": port}).start()
|
||||||
|
|
||||||
def add_event(self, e, level="info"):
|
def add_event(self, e, level="info"):
|
||||||
"""
|
"""
|
||||||
|
@ -2,11 +2,9 @@ import threading, Queue
|
|||||||
import flask
|
import flask
|
||||||
import libpathod.test, libpathod.pathoc
|
import libpathod.test, libpathod.pathoc
|
||||||
from libmproxy import proxy, flow, controller
|
from libmproxy import proxy, flow, controller
|
||||||
|
from libmproxy.cmdline import APP_HOST, APP_PORT
|
||||||
import tutils
|
import tutils
|
||||||
|
|
||||||
APP_DOMAIN = "mitm"
|
|
||||||
APP_IP = "1.1.1.1"
|
|
||||||
|
|
||||||
testapp = flask.Flask(__name__)
|
testapp = flask.Flask(__name__)
|
||||||
|
|
||||||
@testapp.route("/")
|
@testapp.route("/")
|
||||||
@ -31,7 +29,7 @@ class TestMaster(flow.FlowMaster):
|
|||||||
flow.FlowMaster.__init__(self, s, state)
|
flow.FlowMaster.__init__(self, s, state)
|
||||||
self.testq = testq
|
self.testq = testq
|
||||||
self.clear_log()
|
self.clear_log()
|
||||||
self.start_app(APP_DOMAIN, APP_IP)
|
self.start_app(APP_HOST, APP_PORT, False)
|
||||||
|
|
||||||
def handle_request(self, m):
|
def handle_request(self, m):
|
||||||
flow.FlowMaster.handle_request(self, m)
|
flow.FlowMaster.handle_request(self, m)
|
||||||
|
Loading…
Reference in New Issue
Block a user