Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
socket.on('createTerminal', function(term_id, func)
{
var name = term_id.split('§')[0]
term_id = tid++
console.log('docker', ['-H', config.endpoint, 'exec', '-it', name, '/bin/bash'].join(' '))
var term = pty.spawn('docker', ['-H', config.endpoint, 'exec', '-it', name, '/bin/bash'], {cwd: '/'})
// console.log('docker', ['-H', config.endpoint, 'exec', '-it', name, '/bin/bash'])
.on('data', function(data){
socket.emit('data'+ term_id, data)
})
.on('exit', function(){
socket.emit('exit', {})
})
socket.on('data'+ term_id, function(data){
term.write(data)
})
.on('resize'+term_id, function(data){
term.resize(data.cols, data.rows)
})
.on('disconnect', function(){
term.destroy()
io.on('connection', function(socket){
var request = socket.request;
console.log((new Date()) + ' Connection accepted.');
// Initiate session
var term;
var entrypoint = config.shellEntrypoint(request);
term = pty.spawn(entrypoint.script, entrypoint.args, {
name: 'xterm-256color',
cols: 80,
rows: 30
});
// Loop
term.on('data', function(data) {
socket.emit('output', data);
});
term.on('exit', function(code) {
console.log((new Date()) + " PID=" + term.pid + " ENDED");
socket.emit('exit', config.proxy_pass_prefix + '/logout');
});
socket.on('resize', function(data) {
term.resize(data.col, data.row);
});
ShareTerm.prototype.connected = function () {
var self = this;
// Create the bash session
var term = self.term = Pty.spawn("bash", [], {
name: "xterm-color",
cols: process.stdout.columns,
rows: process.stdout.rows,
cwd: ".",
env: process.env
});
// Pipe standard input and output
term.pipe(process.stdout);
process.stdin.pipe(term);
// Listen for Pty data
term.on("data", function (data) {
self.socket.emit("_termData", data);
});
var stdin = process.openStdin();
process.stdin.setRawMode(true);
const output = fs.createWriteStream('.log', {'flags': 'a'});
const myconsole = new console.Console(output, output);
var _log = console.log;
console.log = myconsole.log;
// initial terminal size
var COLS = 80;
var ROWS = 25;
// spawn a new pseudoterminal
var ptyterm = pty.spawn('bash', [], {
name: 'xterm',
cols: COLS,
rows: ROWS,
cwd: process.env.HOME,
env: process.env
});
// create terminal emulator and parser
var terminal = new AnsiTerminal(COLS, ROWS, 50000);
terminal.debug = true;
var parser = new AnsiParser(terminal);
function printTerminal() {
process.stdout.write('\x1b[2;2H');
var debug_out = '';
for (var i=0; i
const args = process.argv.slice(2);
const HEIGHT = process.stdout.rows;
const WIDTH = process.stdout.columns;
const LEFTWALL = 10;
const RIGHTWALL = 10;
const MIDWIDTH = ~~(WIDTH / 2);
const MIDHEIGHT = ~~(HEIGHT / 2);
const FPS = 15;
const FRAMERATE = ~~(1000 / FPS);
const DIFFICULTY = 50; // out of 100
const STARTTIME = new Date().getTime();
const PLAYERLINE = ~~(HEIGHT / 4 + HEIGHT / 2);
let ALIVE = true;
var npm = pty.spawn('npm', args, {
cwd: process.cwd()
})
const installingPackages = {};
npm.stdout.on('data', d => {
// New npm
const bits = d.toString().match(/:[a-zA-Z0-9\-_]+/)
if (bits) {
const packName = bits[0].slice(1);
installingPackages[packName] = 1;
}
});
npm.stdout.on('end', d => {
gameOver(true);
sio.sockets.on('connection', function (socket) {
console.log('A socket connected!');
var term = pty.spawn('bash', [], {
name: 'xterm-color',
cols: 80,
rows: 30,
cwd: "./",
env: process.env
});
term.on('data', function(data) {
socket.emit('output', btoa(data));
});
socket.on('input', function (data) {
term.write(atob(data));
});
socket.on('resize', function (data) {
/**
* Copyright 2014 Simon Edwards
*/
var pty = require('pty.js');
var flexbuffer = require('./flexbuffer');
var inputbuffer = new flexbuffer.FlexBuffer();
var term = pty.spawn('bash', [], {
name: 'xterm-color',
cols: 80,
rows: 30,
cwd: process.env.HOME,
env: process.env
});
term.on('data', function(data) {
process.stdout.write(data);
});
term.on('exit', function() {
console.log("pty_bridge: term process exited.");
process.exit(0);
});
parent.config.user,
parent.config.build.memory,
parent.config.build.io || 500,
portMap,
Userid.uid(parent.config.user),
parent.buildPath(),
(parent.config.plugin === 'bungeecord' || parent.config.plugin === 'minecraft-pre') ? 'pufferpanel/minecraft:latest' : 'pufferpanel/' + parent.config.plugin + ':latest'
);
}
} catch (ex) {
Logger.error('Error on attempting to create container', ex);
}
Logger.verbose(Util.format('Executing cmd: %s %s', 'docker', dockerProcessParams));
parent.ps = Pty.spawn('docker', dockerProcessParams.match(/\S+/g));
parent.ps.on('data', function (data) {
parent.emit('installer', StripANSI(data));
});
parent.ps.on('exit', function (code) {
if (code !== 0) {
return callback(new Error('docker create command exited with non-zero error code [' + code + '].'));
}
Logger.verbose(Util.format('Successfully added a new docker container for %s.', parent.config.name));
return callback();
});
}
socket.disconnect();
return;
}
if(match[1] == "pipeline"){
sshhost = pipe_details.ip;
sshpass = pipe_details.pass;
sshuser = 'root';
term = pty.spawn('sshpass', ['-p', sshpass, 'ssh', sshuser + '@' + sshhost, '-p', sshport, '-o', 'StrictHostKeyChecking=no', '-o', 'GlobalKnownHostsFile=/dev/null', '-o', 'UserKnownHostsFile=/dev/null', '-q'], {
name: 'xterm-256color',
cols: 80,
rows: 30
});
} else if (match[1] == "container") {
console.log((new Date()) + ' Trying to exec kubectl exec for pod: ' + pipe_details.pod_id);
term = pty.spawn('kubectl', ['exec', '-it', pipe_details.pod_id, '/bin/bash'], {
name: 'xterm-256color',
cols: 80,
rows: 30
});
} else {
socket.disconnect();
return;
}
}
else {
socket.disconnect();
return;
}
console.log((new Date()) + " PID=" + term.pid + " STARTED to IP=" + sshhost + ", RUNNO=" + pipeline_id + " on behalf of user=" + sshuser);
}
var auth_key = socket.handshake.headers['token'];
pipe_details = get_pipe_details(pipeline_id, auth_key)
if (!pipe_details || !pipe_details.ip || !pipe_details.pass)
{
console.log((new Date()) + " Cannot get ip/pass for a run #" + pipeline_id);
socket.disconnect();
return;
}
if(match[1] == "pipeline"){
sshhost = pipe_details.ip;
sshpass = pipe_details.pass;
sshuser = 'root';
term = pty.spawn('sshpass', ['-p', sshpass, 'ssh', sshuser + '@' + sshhost, '-p', sshport, '-o', 'StrictHostKeyChecking=no', '-o', 'GlobalKnownHostsFile=/dev/null', '-o', 'UserKnownHostsFile=/dev/null', '-q'], {
name: 'xterm-256color',
cols: 80,
rows: 30
});
} else if (match[1] == "container") {
console.log((new Date()) + ' Trying to exec kubectl exec for pod: ' + pipe_details.pod_id);
term = pty.spawn('kubectl', ['exec', '-it', pipe_details.pod_id, '/bin/bash'], {
name: 'xterm-256color',
cols: 80,
rows: 30
});
} else {
socket.disconnect();
return;
}
}