diff options
author | Maximilian Hils <git@maximilianhils.com> | 2016-02-12 23:35:16 +0100 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2016-02-12 23:35:16 +0100 |
commit | bd68b4f6781dfb7f2e147fdcfcd8466cbb747ab3 (patch) | |
tree | 2f41497d96e874b652ab2e0fd023b025bc7a1f19 /libmproxy/web/__init__.py | |
parent | 1f4d031a60606fce2fd7118267a724c7f931d886 (diff) | |
parent | 195ea8e15ac3822c1524ee4742ec42ca76638876 (diff) | |
download | mitmproxy-bd68b4f6781dfb7f2e147fdcfcd8466cbb747ab3.tar.gz mitmproxy-bd68b4f6781dfb7f2e147fdcfcd8466cbb747ab3.tar.bz2 mitmproxy-bd68b4f6781dfb7f2e147fdcfcd8466cbb747ab3.zip |
Merge pull request #929 from ganguera/ganguera/basic_auth
Added Basic Auth support for MITMWeb interface
Diffstat (limited to 'libmproxy/web/__init__.py')
-rw-r--r-- | libmproxy/web/__init__.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/libmproxy/web/__init__.py b/libmproxy/web/__init__.py index c48b3d09..50c49e8d 100644 --- a/libmproxy/web/__init__.py +++ b/libmproxy/web/__init__.py @@ -3,6 +3,8 @@ import collections import tornado.ioloop import tornado.httpserver +from netlib.http import authentication + from .. import controller, flow from . import app @@ -113,6 +115,9 @@ class Options(object): "wdebug", "wport", "wiface", + "wauthenticator", + "wsingleuser", + "whtpasswd", ] def __init__(self, **kwargs): @@ -122,13 +127,30 @@ class Options(object): if not hasattr(self, i): setattr(self, i, None) + def process_web_options(self, parser): + if self.wsingleuser or self.whtpasswd: + if self.wsingleuser: + if len(self.wsingleuser.split(':')) != 2: + return parser.error( + "Invalid single-user specification. Please use the format username:password" + ) + username, password = self.wsingleuser.split(':') + self.wauthenticator = authentication.PassManSingleUser(username, password) + elif self.whtpasswd: + try: + self.wauthenticator = authentication.PassManHtpasswd(self.whtpasswd) + except ValueError as v: + return parser.error(v.message) + else: + self.wauthenticator = None + class WebMaster(flow.FlowMaster): def __init__(self, server, options): self.options = options super(WebMaster, self).__init__(server, WebState()) - self.app = app.Application(self, self.options.wdebug) + self.app = app.Application(self, self.options.wdebug, self.options.wauthenticator) if options.rfile: try: self.load_flows_file(options.rfile) |