diff --git a/README.md b/README.md index 1f4d56c2..f223ffb1 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ Requisites - [Git](https://git-scm.com) - The following executables should be correctly installed in your shell environment: - `ssh`: Any recent version of the OpenSSH ssh client (required by `resin sync` and `resin ssh`) + - if you need `ssh` to work behind the proxy you also need `proxytunnel`[http://proxytunnel.sourceforge.net/] installed (available as `proxytunnel` package for Ubuntu, for example) - `rsync`: >= 2.6.9 (required by `resin sync`) ##### Windows Support @@ -26,6 +27,7 @@ If you still want to use `cmd.exe` you will have to use a package manager like M 2. Install the `msys-rsync` and `msys-openssh` packages. 3. Add MinGW to the `%PATH%` if this hasn't been done by the installer already. The location where the binaries are places is usually `C:\MinGW\msys\1.0\bin`, but it can vary if you selected a different location in the installer. 4. Copy your SSH keys to `%homedrive%%homepath\.ssh`. +5. Install [proxytunnel](http://proxytunnel.sourceforge.net/) Getting Started --------------- diff --git a/build/actions/local/common.js b/build/actions/local/common.js index e1539495..512e5903 100644 --- a/build/actions/local/common.js +++ b/build/actions/local/common.js @@ -94,18 +94,4 @@ exports.pipeContainerStream = Promise.method(function(arg) { }); }); -exports.getSubShellCommand = function(command) { - var os; - os = require('os'); - if (os.platform() === 'win32') { - return { - program: 'cmd.exe', - args: ['/s', '/c', command] - }; - } else { - return { - program: '/bin/sh', - args: ['-c', command] - }; - } -}; +exports.getSubShellCommand = require('../../utils/helpers'); diff --git a/build/actions/ssh.js b/build/actions/ssh.js index d5451f90..163950f8 100644 --- a/build/actions/ssh.js +++ b/build/actions/ssh.js @@ -17,21 +17,7 @@ limitations under the License. */ var getSubShellCommand; -getSubShellCommand = function(command) { - var os; - os = require('os'); - if (os.platform() === 'win32') { - return { - program: 'cmd.exe', - args: ['/s', '/c', command] - }; - } else { - return { - program: '/bin/sh', - args: ['-c', command] - }; - } -}; +getSubShellCommand = require('../utils/helpers').getSubShellCommand; module.exports = { signature: 'ssh [uuid]', @@ -73,7 +59,7 @@ module.exports = { } return patterns.inferOrSelectDevice(); }).then(function(uuid) { - console.info("Connecting with: " + uuid); + console.info("Connecting to: " + uuid); return resin.models.device.get(uuid); }).then(function(device) { if (!device.is_online) { @@ -91,8 +77,17 @@ module.exports = { throw new Error('Did not find running application container'); } return Promise["try"](function() { - var command, subShellCommand; - command = "ssh " + verbose + " -t -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ControlMaster=no -p " + options.port + " " + username + "@ssh." + proxyUrl + " enter " + uuid + " " + containerId; + var command, proxyAuth, proxyConfig, proxyHost, proxytunnelCommand, sshProxyCommand, subShellCommand; + sshProxyCommand = ''; + proxyConfig = global.PROXY_CONFIG; + if (proxyConfig) { + proxyAuth = proxyConfig.proxyAuth; + proxyHost = "-p " + proxyConfig.host + ":" + proxyConfig.port; + proxyAuth = proxyAuth ? "-P " + proxyAuth : ''; + proxytunnelCommand = "proxytunnel " + proxyHost + " " + proxyAuth + " -d %h:%p"; + sshProxyCommand = "-o ProxyCommand='" + proxytunnelCommand + "'"; + } + command = "ssh " + verbose + " -t -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ControlMaster=no " + sshProxyCommand + " -p " + options.port + " " + username + "@ssh." + proxyUrl + " enter " + uuid + " " + containerId; subShellCommand = getSubShellCommand(command); return child_process.spawn(subShellCommand.program, subShellCommand.args, { stdio: 'inherit' diff --git a/build/app.js b/build/app.js index d964d9ce..9873a88d 100644 --- a/build/app.js +++ b/build/app.js @@ -47,6 +47,8 @@ try { globalTunnel.initialize(proxy); +global.PROXY_CONFIG = globalTunnel.proxyConfig; + _ = require('lodash'); Promise = require('bluebird'); diff --git a/build/utils/helpers.js b/build/utils/helpers.js index defef6e3..647c3566 100644 --- a/build/utils/helpers.js +++ b/build/utils/helpers.js @@ -110,3 +110,19 @@ exports.getAppInfo = function(application) { return app; }); }; + +exports.getSubShellCommand = function(command) { + var os; + os = require('os'); + if (os.platform() === 'win32') { + return { + program: 'cmd.exe', + args: ['/s', '/c', command] + }; + } else { + return { + program: '/bin/sh', + args: ['-c', command] + }; + } +}; diff --git a/lib/actions/local/common.coffee b/lib/actions/local/common.coffee index df2d1a85..02d636e4 100644 --- a/lib/actions/local/common.coffee +++ b/lib/actions/local/common.coffee @@ -58,21 +58,4 @@ exports.pipeContainerStream = Promise.method ({ deviceIp, name, outStream, follo return console.log(chalk.red.bold("Container '#{name}' not found.")) throw err -# A function to reliably execute a command -# in all supported operating systems, including -# different Windows environments like `cmd.exe` -# and `Cygwin` should be encapsulated in a -# re-usable package. -exports.getSubShellCommand = (command) -> - os = require('os') - - if os.platform() is 'win32' - return { - program: 'cmd.exe' - args: [ '/s', '/c', command ] - } - else - return { - program: '/bin/sh' - args: [ '-c', command ] - } +exports.getSubShellCommand = require('../../utils/helpers') diff --git a/lib/actions/ssh.coffee b/lib/actions/ssh.coffee index dcd37e9a..a703ca50 100644 --- a/lib/actions/ssh.coffee +++ b/lib/actions/ssh.coffee @@ -14,26 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ### -# TODO: A function to reliably execute a command -# in all supported operating systems, including -# different Windows environments like `cmd.exe` -# and `Cygwin` should be encapsulated in a -# re-usable package. -# This is literally copy-pasted from the `resin-sync` -# module. -getSubShellCommand = (command) -> - os = require('os') - - if os.platform() is 'win32' - return { - program: 'cmd.exe' - args: [ '/s', '/c', command ] - } - else - return { - program: '/bin/sh' - args: [ '-c', command ] - } +{ getSubShellCommand } = require('../utils/helpers') module.exports = signature: 'ssh [uuid]' @@ -68,12 +49,11 @@ module.exports = ] action: (params, options, done) -> child_process = require('child_process') - Promise = require 'bluebird' + Promise = require('bluebird') resin = require('resin-sdk-preconfigured') patterns = require('../utils/patterns') - if not options.port? - options.port = 22 + options.port ?= 22 verbose = if options.verbose then '-vvv' else '' @@ -84,7 +64,7 @@ module.exports = return params.uuid if uuidExists return patterns.inferOrSelectDevice() .then (uuid) -> - console.info("Connecting with: #{uuid}") + console.info("Connecting to: #{uuid}") resin.models.device.get(uuid) .then (device) -> throw new Error('Device is not online') if not device.is_online @@ -98,11 +78,20 @@ module.exports = .then ({ username, uuid, containerId, proxyUrl }) -> throw new Error('Did not find running application container') if not containerId? Promise.try -> + sshProxyCommand = '' + proxyConfig = global.PROXY_CONFIG + if proxyConfig + { proxyAuth } = proxyConfig + proxyHost = "-p #{proxyConfig.host}:#{proxyConfig.port}" + proxyAuth = if proxyAuth then "-P #{proxyAuth}" else '' + proxytunnelCommand = "proxytunnel #{proxyHost} #{proxyAuth} -d %h:%p" + sshProxyCommand = "-o ProxyCommand='#{proxytunnelCommand}'" command = "ssh #{verbose} -t \ -o LogLevel=ERROR \ -o StrictHostKeyChecking=no \ -o UserKnownHostsFile=/dev/null \ -o ControlMaster=no \ + #{sshProxyCommand} \ -p #{options.port} #{username}@ssh.#{proxyUrl} enter #{uuid} #{containerId}" subShellCommand = getSubShellCommand(command) diff --git a/lib/app.coffee b/lib/app.coffee index f36f17dc..91854165 100644 --- a/lib/app.coffee +++ b/lib/app.coffee @@ -38,6 +38,9 @@ catch # If that is not set as well the initialize will do nothing globalTunnel.initialize(proxy) +# TODO: make this a feature of capitano +global.PROXY_CONFIG = globalTunnel.proxyConfig + _ = require('lodash') Promise = require('bluebird') capitano = require('capitano') diff --git a/lib/utils/helpers.coffee b/lib/utils/helpers.coffee index 72fb5a96..11d05578 100644 --- a/lib/utils/helpers.coffee +++ b/lib/utils/helpers.coffee @@ -105,3 +105,21 @@ exports.getAppInfo = (application) -> app.arch = config.arch return app ) + +# A function to reliably execute a command +# in all supported operating systems, including +# different Windows environments like `cmd.exe` +# and `Cygwin`. +exports.getSubShellCommand = (command) -> + os = require('os') + + if os.platform() is 'win32' + return { + program: 'cmd.exe' + args: [ '/s', '/c', command ] + } + else + return { + program: '/bin/sh' + args: [ '-c', command ] + } diff --git a/package.json b/package.json index 309072d5..77cf76b3 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "dockerode": "^2.4.2", "drivelist": "^5.0.16", "etcher-image-write": "^9.0.3", - "global-tunnel-ng": "^2.0.0", + "global-tunnel-ng": "emirotin/global-tunnel#fix-auth", "inquirer": "^3.0.6", "is-root": "^1.0.0", "js-yaml": "^3.7.0",