function getSftp (callback) { if (sftpClient) return callback(null, sftpClient) ctx.connect().ready(function () { ssh.sftp(function (err, sftp) { if (err) return callback(err) sftpClient = sftp callback(null, sftp) }) }) }
through.obj(function (file, encoding, callback) { ctx.ready(function () { ssh.sftp(function (err, sftp) { if (err) return callback(new gutil.PluginError(packageName, err)) options.autoClose = true var write = sftp.createWriteStream(filePath, options) write .on('error', function (error) { err = error }) .on('finish', function () { sftp.end() if (err) callback(err) else callback(null, file) }) if (file.isStream()) file.pipe(write) else if (file.isBuffer()) write.end(file.contents); else { err = new gutil.PluginError(packageName, 'file error!') write.end() } }) }) })
ctx.ready(function () { ssh.sftp(function (err, sftp) { if (err) return outStream.emit('error', new gutil.PluginError(packageName, err)) var read = sftp.createReadStream(filePath, options) options.base = options.base || '' read .on('data', function (chunk) { chunkSize += chunk.length chunks.push(chunk) }) .on('error', function (err) { outStream.emit('error', err) }) .on('end', function () { outStream.push(new gutil.File({ cwd: __dirname, base: __dirname, path: path.join(__dirname, options.filePath || filePath), contents: Buffer.concat(chunks, chunkSize) })) outStream.end() this.close() }) .on('close', function () { sftp.end() }) }) })
sshServer.listen(SSH_PORT, SSH_IP, function() { console.log('Listening on port ' + this.address().port); });
disconnect() { return super.disconnect().then(() => this.client.end()); }
server.listen(parseInt(process.env.GitPort),'127.0.0.1',()=>{ console.log(chalk.green.bold("Running GIT daemon on : "+process.env.GitPort)); });
constructor(options) { super(); let client = new SshClient(), connectOptions = Object.assign({ host: '127.0.0.1', port: 10022 }, options); this.client = client; this.host = connectOptions.host; this.port = connectOptions.port; client.on('ready', () => { client.shell(false, (err, stream) => { if(err) super.emit('error', err); else super.streamSetup(stream, stream); }); }); client.connect(connectOptions); }
save_config() }) }).on('tcp connection', function(info, accept, deny) { let stream = accept() stream.pause() stream.on('error', function(err) { console.log(err) }) let socket = net.connect(lport, '::', function () { stream.pipe(socket) socket.pipe(stream) stream.resume() }) socket.on('error', function(err) { console.log(err) }) }).on('error', function(err) { console.log(err) event.sender.send('stopped-client', err.message) }).connect(ssh_config) } catch (err) { console.log(err)
client.on('authentication', function(ctx) { if (ctx.username != 'git') { return ctx.reject(); if (ctx.method === 'publickey') { if (ctx.signature) { AUTHENTICATOR.checkSSHAuthorization(ctx.key.algo, ctx.key.data, ctx.sigAlgo, ctx.blob, ctx.signature) .then(function(authorization) { if (authorization) { client.user = { username: ctx.username, authorization: authorization }; ctx.accept(); } else { ctx.reject(); ctx.reject(); }); } else { ctx.accept(); ctx.reject(); }).on('ready', function() { logger.info('SSH Client authenticated'); client.on('session', function(accept, reject) { var session = accept();
start() { new ssh2.Server({ hostKeys: [fs.readFileSync(__dirname + '/../etc/ssh2.private.key')], banner: 'Hi there!', ident: 'OpenSSH_7.6' }, (client) => { client.on('authentication', (ctx) => { if (ctx.method !== 'password') return ctx.reject(['password']); else if (ctx.method === 'password') { if (client._client_info) { this.emit('data', { 'username': ctx.username, 'password': ctx.password, 'ip': client._client_info.ip, 'service': this.name, 'request': (ctx.username && ctx.username.length !== '') ? this.name + ' ' + ctx.username + '@' + config.server_ip + ':' + this.port : this.name + ' ' + config.server_ip + ':' + this.port, 'request_headers': helper.formatHeaders(client._client_info.header) }); ctx.accept(); client.end(); }).on('ready', () => { client.end(); }).on('error', () => { client.end(); }); }).on('connection', (client, info) => { client._client_info = info; }).on('error', (err) => {
conn.on('ready', function() { Object.keys(server).forEach(function(k){ if(conn[k]){ conn.connect(server); conn.on('error',function(stderr){ if(stderr) debug(''+stderr); done(stderr, null); var superEnd = conn.end; conn.end = function(){ debug('end connection %s', conn.pendingStreams.length); conn.pendingStreams.forEach(function(stream, i){ debug('kill stream %s', i); stream.kill(conn.pendingStreams.length); }); conn.pendingStreams = []; superEnd.call(conn); }; conn.end(); }; process.on('SIGINT', sigIntSent); conn.on('close',function(){ try{ process.removeListener('SIGINT', sigIntSent); }catch(ex){} });
.on('ready', function() { c.exec(cmd, function(err, stream) { if (err){ console.error(err); .on('close', function(code, signal) { c.end(); resolve(buffer); }) .on('data', function(data) { if( verbose ) .stderr.on('data', function(data) { console.log('STDERR: ' + data); reject(); }); }) .connect({ host: '127.0.0.1', port: sshConfig.port,
conn.on('ready', function() { conn.forwardOut(sock.remoteAddress, sock.remotePort, proxy_remote, squid_port, function(err, stream) { if (err) { conn.end() return deny() stream.pipe(sock).on('error', function (err) { deny() }).on('close', function (err) { conn.end(); }).pipe(stream).on('error', function (err) { deny() }).on('close', function() { conn.end() }) }) }).on('error', function(err) { deny() }).connect(ssh_config) }).listen(squid_port, '::', () => { if (!proxy_ports.indexOf(squid_port) > -1) { proxy_ports.push(squid_port) } conn.on('ready', function() { conn.forwardOut(sock.remoteAddress, sock.remotePort, proxy_remote, socks_port, function(err, stream) { if (err) { conn.end() return deny() stream.pipe(sock).on('error', function (err) {
describe('SSH Server', function() { it('should reject if username is not git', function(done) { var conn = new Client(); conn.on('error', function(err) { err.message.should.equal('All configured authentication methods failed'); done(); }).connect({ host: '127.0.0.1', port: SSH_PORT, conn.on('error', function(err) { err.message.should.equal('All configured authentication methods failed'); done(); }).connect({ host: '127.0.0.1', port: SSH_PORT, TestAuthenticator.SSH_VALID = false; var conn = new Client(); conn.on('error', function(err) { err.message.should.equal('All configured authentication methods failed'); done(); }).connect({ host: '127.0.0.1', port: SSH_PORT, TestAuthenticator.SSH_VALID = true; var conn = new Client(); conn.on('ready', function(err) { done();
sshServer.listen(SSH_PORT, SSH_IP, function() { logger.info('Listening SSH on port ' + this.address().port); });