2011-03-12 01:30:12 +00:00
import proxy
import optparse
def get_common_options ( options ) :
2011-03-20 04:31:54 +00:00
stickycookie , stickyauth = None , None
2011-03-12 01:30:12 +00:00
if options . stickycookie_all :
stickycookie = " .* "
elif options . stickycookie_filt :
2011-03-12 02:14:25 +00:00
stickycookie = options . stickycookie_filt
2011-03-20 04:31:54 +00:00
if options . stickyauth_all :
stickyauth = " .* "
elif options . stickyauth_filt :
stickyauth = options . stickyauth_filt
2011-03-12 01:30:12 +00:00
return dict (
2011-05-13 22:44:25 +00:00
anticache = options . anticache ,
2011-07-15 03:21:04 +00:00
anticomp = options . anticomp ,
2011-07-22 03:22:13 +00:00
autodecode = options . autodecode ,
2011-05-13 22:44:25 +00:00
client_replay = options . client_replay ,
2011-07-23 00:57:54 +00:00
eventlog = options . eventlog ,
2011-05-13 22:44:25 +00:00
kill = options . kill ,
no_server = options . no_server ,
refresh_server_playback = not options . norefresh ,
rheaders = options . rheaders ,
2011-05-14 23:54:12 +00:00
rfile = options . rfile ,
2011-03-12 01:30:12 +00:00
server_replay = options . server_replay ,
2011-08-03 01:20:36 +00:00
script = options . script ,
2011-03-12 01:30:12 +00:00
stickycookie = stickycookie ,
2011-03-20 04:31:54 +00:00
stickyauth = stickyauth ,
2011-05-13 22:44:25 +00:00
wfile = options . wfile ,
verbosity = options . verbose ,
2011-03-12 01:30:12 +00:00
)
def common_options ( parser ) :
parser . add_option (
" -a " ,
action = " store " , type = " str " , dest = " addr " , default = ' ' ,
help = " Address to bind proxy to (defaults to all interfaces) "
)
2011-08-03 01:20:36 +00:00
parser . add_option (
" --anticache " ,
action = " store_true " , dest = " anticache " , default = False ,
help = " Strip out request headers that might cause the server to return 304-not-modified. "
)
parser . add_option (
" --confdir " ,
action = " store " , type = " str " , dest = " confdir " , default = ' ~/.mitmproxy ' ,
help = " Configuration directory. (~/.mitmproxy) "
)
2011-07-22 03:22:13 +00:00
parser . add_option (
" -d " ,
action = " store_true " , dest = " autodecode " ,
help = " Automatically decode compressed server responses. "
)
2011-07-23 00:57:54 +00:00
parser . add_option (
" -e " ,
action = " store_true " , dest = " eventlog " ,
help = " Show event log. "
)
2011-05-13 22:44:25 +00:00
parser . add_option (
" -n " ,
action = " store_true " , dest = " no_server " ,
help = " Don ' t start a proxy server. "
)
2011-03-12 01:30:12 +00:00
parser . add_option (
" -p " ,
action = " store " , type = " int " , dest = " port " , default = 8080 ,
help = " Proxy service port. "
)
parser . add_option (
" -q " ,
action = " store_true " , dest = " quiet " ,
help = " Quiet. "
)
2011-05-14 23:54:12 +00:00
parser . add_option (
" -r " ,
action = " store " , dest = " rfile " , default = None ,
help = " Read flows from file. "
)
2011-03-12 01:30:12 +00:00
parser . add_option (
2011-08-03 01:20:36 +00:00
" -s " ,
action = " store " , dest = " script " , default = None ,
help = " Run a script. "
2011-03-12 01:30:12 +00:00
)
parser . add_option (
" -t " ,
action = " store_true " , dest = " stickycookie_all " , default = None ,
help = " Set sticky cookie for all requests. "
)
parser . add_option (
" -T " ,
action = " store " , dest = " stickycookie_filt " , default = None , metavar = " FILTER " ,
help = " Set sticky cookie filter. Matched against requests. "
)
2011-03-20 04:31:54 +00:00
parser . add_option (
" -u " ,
action = " store_true " , dest = " stickyauth_all " , default = None ,
help = " Set sticky auth for all requests. "
)
parser . add_option (
" -U " ,
action = " store " , dest = " stickyauth_filt " , default = None , metavar = " FILTER " ,
help = " Set sticky auth filter. Matched against requests. "
)
2011-03-12 01:30:12 +00:00
parser . add_option (
" -v " ,
action = " count " , dest = " verbose " , default = 1 ,
help = " Increase verbosity. Can be passed multiple times. "
)
parser . add_option (
" -w " ,
action = " store " , dest = " wfile " , default = None ,
help = " Write flows to file. "
)
2011-07-15 03:21:04 +00:00
parser . add_option (
" -z " ,
2011-07-17 02:36:38 +00:00
action = " store_true " , dest = " anticomp " , default = False ,
2011-07-15 03:21:04 +00:00
help = " Try to convince servers to send us un-compressed data. "
)
2011-03-12 01:30:12 +00:00
group = optparse . OptionGroup ( parser , " Client Replay " )
group . add_option (
" -c " ,
action = " store " , dest = " client_replay " , default = None , metavar = " PATH " ,
help = " Replay client requests from a saved file. "
)
parser . add_option_group ( group )
2011-06-27 04:10:17 +00:00
parser . add_option (
2011-07-09 08:07:22 +00:00
" --cert-wait-time " , type = " float " ,
2011-06-27 04:10:17 +00:00
action = " store " , dest = " cert_wait_time " , default = 0 ,
help = " Wait for specified number of seconds after a new cert is generated. This can smooth over small discrepancies between the client and server times. "
)
2011-03-12 01:30:12 +00:00
group = optparse . OptionGroup ( parser , " Server Replay " )
group . add_option (
2011-08-03 01:20:36 +00:00
" -S " ,
2011-03-12 01:30:12 +00:00
action = " store " , dest = " server_replay " , default = None , metavar = " PATH " ,
help = " Replay server responses from a saved file. "
)
group . add_option (
" -k " ,
action = " store_true " , dest = " kill " , default = False ,
help = " Kill extra requests during replay. "
)
group . add_option (
" --rheader " ,
action = " append " , dest = " rheaders " , type = " str " ,
help = " Request headers to be considered during replay. "
" Can be passed multiple times. "
)
group . add_option (
" --norefresh " ,
action = " store_true " , dest = " norefresh " , default = False ,
help = " Disable response refresh, "
" which updates times in cookies and headers for replayed responses. "
)
parser . add_option_group ( group )
proxy . certificate_option_group ( parser )