I am a newbie on python web programming, still don't know how to integrate mitmproxy with web framework such as flask. I mean is it possible to send a request to start mitmproxy service, another request to stop it, as example below:
app = Flask(__name__)
class MyMaster(flow.FlowMaster):
def run(self):
try:
flow.FlowMaster.run(self)
except KeyboardInterrupt:
self.shutdown()
@controller.handler
def request(self, f):
print("request", f)
@controller.handler
def response(self, f):
print("response", f)
@controller.handler
def error(self, f):
print("error", f)
@controller.handler
def log(self, l):
print("log", l.msg)
opts = options.Options(cadir="~/.mitmproxy/", listen_port=9000)
config = ProxyConfig(opts)
state = flow.State()
server = ProxyServer(config)
m = MyMaster(opts, server, state)
@app.route("/")
def index():
return "hello"
@app.route("/start")
def start():
global m
m.run()
return 'Start!'
def stop():
global m
m.shutdown()
app.run(debug=True)
now I have to divide my application into two parts, the mitmproxy as service be controlled by supervisor, store the data into database, another flask app to display the data from database. actually I want to control the service from the client side.