From 9fa3f4612224ed1db75d2e3cf1fc8d09d76adb45 Mon Sep 17 00:00:00 2001 From: septs Date: Tue, 12 Apr 2022 19:26:22 +0800 Subject: [PATCH] fix(shell-proxy): make ssh-proxy compatible with macOS (#10640) --- plugins/shell-proxy/.editorconfig | 3 +++ plugins/shell-proxy/ssh-proxy.py | 23 +++++++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 plugins/shell-proxy/.editorconfig diff --git a/plugins/shell-proxy/.editorconfig b/plugins/shell-proxy/.editorconfig new file mode 100644 index 000000000..b7c70d16d --- /dev/null +++ b/plugins/shell-proxy/.editorconfig @@ -0,0 +1,3 @@ +[*.py] +indent_size = 4 +indent_style = space diff --git a/plugins/shell-proxy/ssh-proxy.py b/plugins/shell-proxy/ssh-proxy.py index 6773a77bc..a498c84bc 100755 --- a/plugins/shell-proxy/ssh-proxy.py +++ b/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())