aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2017-03-09 13:52:58 +1300
committerAldo Cortesi <aldo@corte.si>2017-03-14 08:32:19 +1300
commit0c6663d0d5335e666598807c2e5d8f105803eac0 (patch)
treee6782b2e102aca959ad6e30739f816dbad89cbb9 /examples
parentee65894d40f5a9f73125a8d3e73ba50540939e5b (diff)
downloadmitmproxy-0c6663d0d5335e666598807c2e5d8f105803eac0.tar.gz
mitmproxy-0c6663d0d5335e666598807c2e5d8f105803eac0.tar.bz2
mitmproxy-0c6663d0d5335e666598807c2e5d8f105803eac0.zip
Enable custom options for addons
- Add an options parameter to the start() event. This is to be used by addons on startup to add custom options. - Add a running() event that is called once the proxy is up and running. - With the new paradigm we can't log during master __init__, so add a tiny termstatus addon to print proxy status to terminal once we're running.
Diffstat (limited to 'examples')
-rw-r--r--examples/complex/dns_spoofing.py17
-rw-r--r--examples/complex/har_dump.py2
-rw-r--r--examples/complex/remote_debug.py2
-rw-r--r--examples/complex/tls_passthrough.py2
-rw-r--r--examples/simple/add_header_class.py2
-rw-r--r--examples/simple/custom_contentview.py2
-rw-r--r--examples/simple/custom_option.py10
-rw-r--r--examples/simple/filter_flows.py2
-rw-r--r--examples/simple/io_write_dumpfile.py2
-rw-r--r--examples/simple/log_events.py2
-rw-r--r--examples/simple/modify_body_inject_iframe.py2
-rw-r--r--examples/simple/script_arguments.py2
-rw-r--r--examples/simple/wsgi_flask_app.py2
13 files changed, 30 insertions, 19 deletions
diff --git a/examples/complex/dns_spoofing.py b/examples/complex/dns_spoofing.py
index 2fd6b699..ca2bcd35 100644
--- a/examples/complex/dns_spoofing.py
+++ b/examples/complex/dns_spoofing.py
@@ -1,11 +1,12 @@
"""
-This script makes it possible to use mitmproxy in scenarios where IP spoofing has been used to redirect
-connections to mitmproxy. The way this works is that we rely on either the TLS Server Name Indication (SNI) or the
-Host header of the HTTP request.
-Of course, this is not foolproof - if an HTTPS connection comes without SNI, we don't
-know the actual target and cannot construct a certificate that looks valid.
-Similarly, if there's no Host header or a spoofed Host header, we're out of luck as well.
-Using transparent mode is the better option most of the time.
+This script makes it possible to use mitmproxy in scenarios where IP spoofing
+has been used to redirect connections to mitmproxy. The way this works is that
+we rely on either the TLS Server Name Indication (SNI) or the Host header of the
+HTTP request. Of course, this is not foolproof - if an HTTPS connection comes
+without SNI, we don't know the actual target and cannot construct a certificate
+that looks valid. Similarly, if there's no Host header or a spoofed Host header,
+we're out of luck as well. Using transparent mode is the better option most of
+the time.
Usage:
mitmproxy
@@ -53,5 +54,5 @@ class Rerouter:
flow.request.port = port
-def start():
+def start(opts):
return Rerouter()
diff --git a/examples/complex/har_dump.py b/examples/complex/har_dump.py
index 86a33684..9a86e45e 100644
--- a/examples/complex/har_dump.py
+++ b/examples/complex/har_dump.py
@@ -25,7 +25,7 @@ HAR = {}
SERVERS_SEEN = set()
-def start():
+def start(opts):
"""
Called once on script startup before any other events.
"""
diff --git a/examples/complex/remote_debug.py b/examples/complex/remote_debug.py
index fb864f78..ae0dffc1 100644
--- a/examples/complex/remote_debug.py
+++ b/examples/complex/remote_debug.py
@@ -14,6 +14,6 @@ Usage:
"""
-def start():
+def start(opts):
import pydevd
pydevd.settrace("localhost", port=5678, stdoutToServer=True, stderrToServer=True)
diff --git a/examples/complex/tls_passthrough.py b/examples/complex/tls_passthrough.py
index 40c1051d..6dba7ca1 100644
--- a/examples/complex/tls_passthrough.py
+++ b/examples/complex/tls_passthrough.py
@@ -112,7 +112,7 @@ class TlsFeedback(TlsLayer):
tls_strategy = None
-def start():
+def start(opts):
global tls_strategy
if len(sys.argv) == 2:
tls_strategy = ProbabilisticStrategy(float(sys.argv[1]))
diff --git a/examples/simple/add_header_class.py b/examples/simple/add_header_class.py
index 6443798a..9270be09 100644
--- a/examples/simple/add_header_class.py
+++ b/examples/simple/add_header_class.py
@@ -3,5 +3,5 @@ class AddHeader:
flow.response.headers["newheader"] = "foo"
-def start():
+def start(opts):
return AddHeader()
diff --git a/examples/simple/custom_contentview.py b/examples/simple/custom_contentview.py
index 1f3a38ec..4bc17af0 100644
--- a/examples/simple/custom_contentview.py
+++ b/examples/simple/custom_contentview.py
@@ -20,7 +20,7 @@ class ViewSwapCase(contentviews.View):
view = ViewSwapCase()
-def start():
+def start(opts):
contentviews.add(view)
diff --git a/examples/simple/custom_option.py b/examples/simple/custom_option.py
new file mode 100644
index 00000000..e9c34850
--- /dev/null
+++ b/examples/simple/custom_option.py
@@ -0,0 +1,10 @@
+from mitmproxy import ctx
+
+
+def start(options):
+ ctx.log.info("Registering option 'custom'")
+ options.add_option("custom", str, "default", "A custom option")
+
+
+def configure(options, updated):
+ ctx.log.info("custom option value: %s" % options.custom)
diff --git a/examples/simple/filter_flows.py b/examples/simple/filter_flows.py
index 29d0a9b8..24e8b6c1 100644
--- a/examples/simple/filter_flows.py
+++ b/examples/simple/filter_flows.py
@@ -17,7 +17,7 @@ class Filter:
print(flow)
-def start():
+def start(opts):
if len(sys.argv) != 2:
raise ValueError("Usage: -s 'filt.py FILTER'")
return Filter(sys.argv[1])
diff --git a/examples/simple/io_write_dumpfile.py b/examples/simple/io_write_dumpfile.py
index ff1fd0f4..311950af 100644
--- a/examples/simple/io_write_dumpfile.py
+++ b/examples/simple/io_write_dumpfile.py
@@ -23,7 +23,7 @@ class Writer:
self.w.add(flow)
-def start():
+def start(opts):
if len(sys.argv) != 2:
raise ValueError('Usage: -s "flowriter.py filename"')
return Writer(sys.argv[1])
diff --git a/examples/simple/log_events.py b/examples/simple/log_events.py
index ab1baf75..a81892aa 100644
--- a/examples/simple/log_events.py
+++ b/examples/simple/log_events.py
@@ -7,6 +7,6 @@ If you want to help us out: https://github.com/mitmproxy/mitmproxy/issues/1530 :
from mitmproxy import ctx
-def start():
+def start(opts):
ctx.log.info("This is some informative text.")
ctx.log.error("This is an error.")
diff --git a/examples/simple/modify_body_inject_iframe.py b/examples/simple/modify_body_inject_iframe.py
index e3d5fee9..ab5abf27 100644
--- a/examples/simple/modify_body_inject_iframe.py
+++ b/examples/simple/modify_body_inject_iframe.py
@@ -23,7 +23,7 @@ class Injector:
flow.response.content = str(html).encode("utf8")
-def start():
+def start(opts):
if len(sys.argv) != 2:
raise ValueError('Usage: -s "iframe_injector.py url"')
return Injector(sys.argv[1])
diff --git a/examples/simple/script_arguments.py b/examples/simple/script_arguments.py
index 70851192..b46a1960 100644
--- a/examples/simple/script_arguments.py
+++ b/examples/simple/script_arguments.py
@@ -9,7 +9,7 @@ class Replacer:
flow.response.replace(self.src, self.dst)
-def start():
+def start(opts):
parser = argparse.ArgumentParser()
parser.add_argument("src", type=str)
parser.add_argument("dst", type=str)
diff --git a/examples/simple/wsgi_flask_app.py b/examples/simple/wsgi_flask_app.py
index f95c41e5..db3b1adf 100644
--- a/examples/simple/wsgi_flask_app.py
+++ b/examples/simple/wsgi_flask_app.py
@@ -14,7 +14,7 @@ def hello_world():
return 'Hello World!'
-def start():
+def start(opts):
# Host app at the magic domain "proxapp" on port 80. Requests to this
# domain and port combination will now be routed to the WSGI app instance.
return wsgiapp.WSGIApp(app, "proxapp", 80)