From c1af528b87729b3c5bfbcfea320a96cf476d55d9 Mon Sep 17 00:00:00 2001 From: nightwing Date: Tue, 12 Apr 2016 00:46:39 +0000 Subject: [PATCH] use proxy command --- node_modules/c9/ssh.js | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/node_modules/c9/ssh.js b/node_modules/c9/ssh.js index bad37da0..a7969951 100644 --- a/node_modules/c9/ssh.js +++ b/node_modules/c9/ssh.js @@ -12,6 +12,21 @@ var fs = require("fs"); var tmp = require("tmp"); var debug = require("debug")("ssh"); +function quote(str) { + return "'" + str.replace(/'/g, "'\\''") + "'"; +} + +function addProxyCommand(args, proxy) { + var m = /^(.+)(?::(\d+))?$/.exec(proxy); + if (!m) + return; + var proxyHost = m[1]; + var proxyPort = parseInt(m[2], 10) || 22; + args.push( + "-o", "ProxyCommand=ssh -W %h:%p -p " + proxyPort + " " + quote(proxyHost) + ); +} + exports.buildArgs = function(prvkeyFile, host, proxy) { var args = [ "-o", "PasswordAuthentication=no", @@ -27,21 +42,15 @@ exports.buildArgs = function(prvkeyFile, host, proxy) { "-o", "ConnectTimeout=10" // default timeout is 2 minutes, which is quite long ]; + if (proxy) + addProxyCommand(args, proxy); + if (host) { host = host.split(":"); args.push("-p", host[1] || 22); args.push(host[0]); } - if (proxy) { - args.push( - "ssh", - "-o", "UserKnownHostsFile=/dev/null", - "-o", "StrictHostKeyChecking=no", - "-o", "IdentitiesOnly=yes", - proxy - ); - } return args; };