-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added addon for pre-configured docker proxy
- Loading branch information
1 parent
5c4c665
commit b2cfd6f
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import logging | ||
import shutil | ||
import subprocess | ||
import tempfile | ||
import json | ||
import os | ||
from mitmproxy import command | ||
from mitmproxy import ctx | ||
from mitmproxy.log import ALERT | ||
|
||
|
||
class Docker: | ||
|
||
@command.command("docker.enable") | ||
def enable(self) -> None: | ||
# def start(self) -> None: | ||
""" | ||
Enable docker proxy to started [Make sure to run `docker.disable` when done] | ||
Rebuild container after enabling this option | ||
""" | ||
if not shutil.which("docker"): | ||
logging.log( | ||
ALERT, "Docker not installed or not avaialble in path" | ||
) | ||
return | ||
|
||
config = {} | ||
config_path = os.path.join(os.path.expanduser('~'),".docker","config.json") | ||
with open(config_path,"r") as file: | ||
config = json.load(file) | ||
config['proxies'] = { | ||
"default" : { | ||
"httpProxy": 'http://host.docker.internal:{}/'.format(ctx.options.listen_port or "8080"), | ||
"httpsProxy": 'https://host.docker.internal:{}/'.format(ctx.options.listen_port or "8080"), | ||
} | ||
} | ||
logging.debug(config) | ||
|
||
with open(config_path,"w") as file: | ||
json.dump(config,file) | ||
|
||
logging.log(ALERT,"Enabled proxy [updated:~/.docker/config.json]") | ||
|
||
@command.command("docker.disable") | ||
def disable(self) -> None: | ||
# def start(self) -> None: | ||
""" | ||
Disable docker proxy [Rebuild container after disabling this option] | ||
""" | ||
if not shutil.which("docker"): | ||
logging.log( | ||
ALERT, "Docker not installed or not avaialble in path" | ||
) | ||
return | ||
|
||
config = {} | ||
config_path = os.path.join(os.path.expanduser('~'),".docker","config.json") | ||
with open(config_path,"r") as file: | ||
config = json.load(file) | ||
config['proxies'] = {} | ||
logging.debug(config) | ||
|
||
with open(config_path,"w") as file: | ||
json.dump(config,file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import subprocess | ||
from shutil import which | ||
|
||
l = subprocess.Popen(["docker","run","mitm"]) | ||
|
||
if (which("docker")): | ||
print(l) |