9fa3f4612224ed1db75d2e3cf1fc8d09d76adb45

Author
septs <github@septs.pw>
Committer
GitHub <noreply@github.com>
Date

Message

fix(shell-proxy): make ssh-proxy compatible with macOS (#10640)

Diff

 1diff --git a/plugins/shell-proxy/.editorconfig b/plugins/shell-proxy/.editorconfig
 2new file mode 100644
 3index 0000000000000000000000000000000000000000..b7c70d16d9255b12be0315eb3530b62824d0b0e4
 4--- /dev/null
 5+++ b/plugins/shell-proxy/.editorconfig
 6@@ -0,0 +1,3 @@
 7+[*.py]
 8+indent_size = 4
 9+indent_style = space
10diff --git a/plugins/shell-proxy/ssh-proxy.py b/plugins/shell-proxy/ssh-proxy.py
11index 6773a77bc0d14620ba009f4952f13972613f9c5d..a498c84bc8c8fc643a65f65df206f698180eb112 100755
12--- a/plugins/shell-proxy/ssh-proxy.py
13+++ b/plugins/shell-proxy/ssh-proxy.py
14@@ -20,14 +20,17 @@ proxy_protocols = {
15 if parsed.scheme not in proxy_protocols:
16     raise TypeError('unsupported proxy protocol: "{}"'.format(parsed.scheme))
17 
18-argv = [
19-    "nc",
20-    "-X",
21-    proxy_protocols[parsed.scheme], # Supported protocols are 4 (SOCKS v4), 5 (SOCKS v5) and connect (HTTP proxy). Default SOCKS v5 is used.
22-    "-x",
23-    parsed.netloc,  # proxy-host:proxy-port
24-    sys.argv[1],  # host
25-    sys.argv[2],  # port
26-]
27+def make_argv():
28+    yield "nc"
29+    if sys.platform == 'linux':
30+        # caveats: macOS built-in netcat command not supported proxy-type
31+        yield "-X" # --proxy-type
32+        # Supported protocols are 4 (SOCKS v4), 5 (SOCKS v5) and connect (HTTP proxy).
33+        # Default SOCKS v5 is used.
34+        yield proxy_protocols[parsed.scheme]
35+    yield "-x" # --proxy
36+    yield parsed.netloc # proxy-host:proxy-port
37+    yield sys.argv[1] # host
38+    yield sys.argv[2] # port
39 
40-subprocess.call(argv)
41+subprocess.call(make_argv())