Browse Source

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

septs 2 years ago
parent
commit
9fa3f46122
2 changed files with 16 additions and 10 deletions
  1. 3 0
      plugins/shell-proxy/.editorconfig
  2. 13 10
      plugins/shell-proxy/ssh-proxy.py

+ 3 - 0
plugins/shell-proxy/.editorconfig

@@ -0,0 +1,3 @@
+[*.py]
+indent_size = 4
+indent_style = space

+ 13 - 10
plugins/shell-proxy/ssh-proxy.py

@@ -20,14 +20,17 @@ proxy_protocols = {
 if parsed.scheme not in proxy_protocols:
     raise TypeError('unsupported proxy protocol: "{}"'.format(parsed.scheme))
 
-argv = [
-    "nc",
-    "-X",
-    proxy_protocols[parsed.scheme], # Supported protocols are 4 (SOCKS v4), 5 (SOCKS v5) and connect (HTTP proxy). Default SOCKS v5 is used.
-    "-x",
-    parsed.netloc,  # proxy-host:proxy-port
-    sys.argv[1],  # host
-    sys.argv[2],  # port
-]
+def make_argv():
+    yield "nc"
+    if sys.platform == 'linux':
+        # caveats: macOS built-in netcat command not supported proxy-type
+        yield "-X" # --proxy-type
+        # Supported protocols are 4 (SOCKS v4), 5 (SOCKS v5) and connect (HTTP proxy).
+        # Default SOCKS v5 is used.
+        yield proxy_protocols[parsed.scheme]
+    yield "-x" # --proxy
+    yield parsed.netloc # proxy-host:proxy-port
+    yield sys.argv[1] # host
+    yield sys.argv[2] # port
 
-subprocess.call(argv)
+subprocess.call(make_argv())