diff options
author | Marc Liyanage <reg.gitcommit@entropy.ch> | 2013-06-02 12:43:49 -0700 |
---|---|---|
committer | Marc Liyanage <reg.gitcommit@entropy.ch> | 2013-06-02 12:43:49 -0700 |
commit | 09c95ece52456dc008283e626dd2a8b8ce2a0eec (patch) | |
tree | a0bd06b686588bf16ab906babf12046bd41f5f46 /examples/mitmproxywrapper.py | |
parent | ceafd411f34c15fe271ab4d6ec9b4aca19c7881a (diff) | |
download | mitmproxy-09c95ece52456dc008283e626dd2a8b8ce2a0eec.tar.gz mitmproxy-09c95ece52456dc008283e626dd2a8b8ce2a0eec.tar.bz2 mitmproxy-09c95ece52456dc008283e626dd2a8b8ce2a0eec.zip |
Re-run mitmproxywrapper.py with sudo if necessary.
Diffstat (limited to 'examples/mitmproxywrapper.py')
-rwxr-xr-x | examples/mitmproxywrapper.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/examples/mitmproxywrapper.py b/examples/mitmproxywrapper.py index 751332b7..344cd53b 100755 --- a/examples/mitmproxywrapper.py +++ b/examples/mitmproxywrapper.py @@ -11,6 +11,8 @@ import subprocess import re import argparse import contextlib +import os +import sys class Wrapper(object): @@ -104,6 +106,12 @@ class Wrapper(object): self.disable_proxy_for_service(service_name) @classmethod + def ensure_superuser(cls): + if os.getuid() != 0: + print 'Relaunching with sudo...' + os.execv('/usr/bin/sudo', ['/usr/bin/sudo'] + sys.argv) + + @classmethod def main(cls): parser = argparse.ArgumentParser(description='Helper tool for OS X proxy configuration and mitmproxy') parser.add_argument('-t', '--toggle', action='store_true', help='just toggle the proxy configuration') @@ -122,5 +130,6 @@ class Wrapper(object): if __name__ == '__main__': + Wrapper.ensure_superuser() Wrapper.main() |