mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-01-30 23:09:44 +00:00
Basic web service and options
This commit is contained in:
parent
adfaa1ed5b
commit
6812d304a1
@ -314,23 +314,23 @@ def common_options(parser):
|
||||
help="Override the HTTP request form sent upstream by the proxy"
|
||||
)
|
||||
|
||||
group = parser.add_argument_group("Web App")
|
||||
group = parser.add_argument_group("Onboarding App")
|
||||
group.add_argument(
|
||||
"-a",
|
||||
action="store_false", dest="app", default=True,
|
||||
help="Disable the mitmproxy web app."
|
||||
help="Disable the mitmproxy onboarding app."
|
||||
)
|
||||
group.add_argument(
|
||||
"--app-host",
|
||||
action="store", dest="app_host", default=APP_HOST, metavar="host",
|
||||
help="Domain to serve the app from. For transparent mode, use an IP when\
|
||||
help="Domain to serve the onboarding app from. For transparent mode, use an IP when\
|
||||
a DNS entry for the app domain is not present. Default: %s" % APP_HOST
|
||||
|
||||
)
|
||||
group.add_argument(
|
||||
"--app-port",
|
||||
action="store", dest="app_port", default=APP_PORT, type=int, metavar="80",
|
||||
help="Port to serve the app from."
|
||||
help="Port to serve the onboarding app from."
|
||||
)
|
||||
|
||||
group = parser.add_argument_group("Client Replay")
|
||||
|
@ -170,8 +170,28 @@ def mitmweb_cmdline():
|
||||
parser.add_argument(
|
||||
'--version',
|
||||
action='version',
|
||||
version=version.NAMEVERSION
|
||||
version="mitmweb" + " " + version.VERSION
|
||||
)
|
||||
|
||||
group = parser.add_argument_group("Mitmweb")
|
||||
group.add_argument(
|
||||
"--wport",
|
||||
action="store", type=int, dest="wport", default=8081,
|
||||
metavar="PORT",
|
||||
help="Mitmweb port."
|
||||
)
|
||||
group.add_argument(
|
||||
"--wiface",
|
||||
action="store", dest="wiface", default="127.0.0.1",
|
||||
metavar="IFACE",
|
||||
help="Mitmweb interface."
|
||||
)
|
||||
group.add_argument(
|
||||
"--wdebug",
|
||||
action="store_true", dest="wdebug",
|
||||
help="Turn on mitmweb debugging"
|
||||
)
|
||||
|
||||
cmdline.common_options(parser)
|
||||
group = parser.add_argument_group(
|
||||
"Filters",
|
||||
@ -189,6 +209,10 @@ def mitmweb_cmdline():
|
||||
|
||||
proxy_config = process_proxy_options(parser, options)
|
||||
web_options = web.Options(**cmdline.get_common_options(options))
|
||||
web_options.intercept = options.intercept
|
||||
web_options.wdebug = options.wdebug
|
||||
web_options.wiface = options.wiface
|
||||
web_options.wport = options.wport
|
||||
return web_options, proxy_config
|
||||
|
||||
|
||||
@ -197,7 +221,7 @@ def mitmweb(): # pragma: nocover
|
||||
|
||||
check_versions()
|
||||
assert_utf8_env()
|
||||
web_options, proxy_config = mitmproxy_cmdline()
|
||||
web_options, proxy_config = mitmweb_cmdline()
|
||||
server = get_server(web_options.no_server, proxy_config)
|
||||
|
||||
m = web.WebMaster(server, web_options)
|
||||
|
@ -2,6 +2,7 @@
|
||||
import tornado.ioloop
|
||||
import tornado.httpserver
|
||||
from .. import controller, utils, flow, script, proxy
|
||||
import app
|
||||
|
||||
|
||||
class Stop(Exception):
|
||||
@ -40,6 +41,10 @@ class Options(object):
|
||||
"verbosity",
|
||||
"wfile",
|
||||
"nopop",
|
||||
|
||||
"wdebug",
|
||||
"wport",
|
||||
"wiface",
|
||||
]
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
@ -52,6 +57,7 @@ class Options(object):
|
||||
|
||||
class WebMaster(flow.FlowMaster):
|
||||
def __init__(self, server, options):
|
||||
self.options = options
|
||||
flow.FlowMaster.__init__(self, server, WebState())
|
||||
|
||||
def tick(self):
|
||||
@ -63,6 +69,12 @@ class WebMaster(flow.FlowMaster):
|
||||
controller.Channel(self.masterq, self.should_exit)
|
||||
)
|
||||
iol = tornado.ioloop.IOLoop.instance()
|
||||
|
||||
http_server = tornado.httpserver.HTTPServer(
|
||||
app.Application(self.options.wdebug)
|
||||
)
|
||||
http_server.listen(self.options.wport)
|
||||
|
||||
tornado.ioloop.PeriodicCallback(self.tick, 5).start()
|
||||
try:
|
||||
iol.start()
|
||||
|
18
libmproxy/web/app.py
Normal file
18
libmproxy/web/app.py
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
import os.path
|
||||
import tornado.web
|
||||
|
||||
|
||||
class Application(tornado.web.Application):
|
||||
def __init__(self, debug):
|
||||
handlers = [
|
||||
]
|
||||
settings = dict(
|
||||
template_path=os.path.join(os.path.dirname(__file__), "templates"),
|
||||
static_path=os.path.join(os.path.dirname(__file__), "static"),
|
||||
xsrf_cookies=True,
|
||||
cookie_secret="__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__",
|
||||
debug=debug,
|
||||
)
|
||||
tornado.web.Application.__init__(self, handlers, **settings)
|
||||
|
Loading…
Reference in New Issue
Block a user