UNPKG

domotz-remote-pawn

Version:

Domotz Agent

69 lines (60 loc) 2.39 kB
/** This file is part of Domotz Agent. * Copyright (C) 2016 Domotz Ltd * * Domotz Agent is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Domotz Agent is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Domotz Agent. If not, see <http://www.gnu.org/licenses/>. **/ /** * Created by Iacopo Papalini <ipapalini@domotz.com> on 24/04/15. * */ var startSshTunnel = function (message, resourceLocator) { var ssh = resourceLocator.networkTools.ssh; var payload = message.payload; var ttl = payload.ttl; var deviceHost = payload.device.host; var devicePort = payload.device.port; var user = payload.server.user; var host = payload.server.host; var port = payload.server.port; var password = payload.server.password; var privateListeningPort = payload.server.private_listening_port; var options = { user: user, password: password, host: host, port: port, remote_port_forwarding: '0.0.0.0:' + privateListeningPort + ':' + deviceHost + ':' + devicePort, disable_remote_command: true, ttl: ttl * 1000, log_prefix: message.correlationId, host_key_checking: 'no', server_alive_interval: 60, server_alive_count_max: 5 }; function describeTunnel() { return [user, '@', host, ':', port, ' ', privateListeningPort, ':', deviceHost, ':', devicePort].join(''); } return { describe: function () { // 'cid - startSshTunnel - domotz@zbx01.cloudserver.it:22 8080:192.168.5.64:5000' return message.correlationId + ' - startSshTunnel - ' + describeTunnel(); }, execute: function (callback) { ssh.exec(null, options); callback(); } }; }; module.exports.command = startSshTunnel;