summaryrefslogtreecommitdiff
path: root/plugins/shell-proxy
diff options
context:
space:
mode:
authorTuowen Zhao <ztuowen@gmail.com>2022-01-01 02:26:11 -0600
committerTuowen Zhao <ztuowen@gmail.com>2022-01-01 02:26:11 -0600
commit49edbf438ed690c76e6b2af80368c59404cf0167 (patch)
tree129b3adb2f5f39a1329a426a3b7d51ed2c2290c1 /plugins/shell-proxy
parent1bc186dabe12b3d01b2257e82f3a104c48b8b3c7 (diff)
parent78c91ccbf99c77bd4d9cdb74279a40776721f66d (diff)
downloadzsh-49edbf438ed690c76e6b2af80368c59404cf0167.tar.gz
zsh-49edbf438ed690c76e6b2af80368c59404cf0167.tar.bz2
zsh-49edbf438ed690c76e6b2af80368c59404cf0167.zip
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'plugins/shell-proxy')
-rwxr-xr-xplugins/shell-proxy/ssh-proxy.py21
1 files changed, 18 insertions, 3 deletions
diff --git a/plugins/shell-proxy/ssh-proxy.py b/plugins/shell-proxy/ssh-proxy.py
index 5efd5fd21..6773a77bc 100755
--- a/plugins/shell-proxy/ssh-proxy.py
+++ b/plugins/shell-proxy/ssh-proxy.py
@@ -2,15 +2,30 @@
import os
import subprocess
import sys
-import urllib.parse
+from urllib.parse import urlparse
proxy = next(os.environ[_] for _ in ("HTTP_PROXY", "HTTPS_PROXY") if _ in os.environ)
+
+parsed = urlparse(proxy)
+
+proxy_protocols = {
+ "http": "connect",
+ "https": "connect",
+ "socks": "5",
+ "socks5": "5",
+ "socks4": "4",
+ "socks4a": "4",
+}
+
+if parsed.scheme not in proxy_protocols:
+ raise TypeError('unsupported proxy protocol: "{}"'.format(parsed.scheme))
+
argv = [
"nc",
"-X",
- "connect",
+ proxy_protocols[parsed.scheme], # Supported protocols are 4 (SOCKS v4), 5 (SOCKS v5) and connect (HTTP proxy). Default SOCKS v5 is used.
"-x",
- urllib.parse.urlparse(proxy).netloc, # proxy-host:proxy-port
+ parsed.netloc, # proxy-host:proxy-port
sys.argv[1], # host
sys.argv[2], # port
]