| 
						
						
							
								
							
						
						
					 | 
					@ -6,6 +6,7 @@ import server from 'socket.io'; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import { spawn } from 'node-pty'; | 
					 | 
					 | 
					import { spawn } from 'node-pty'; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import EventEmitter from 'events'; | 
					 | 
					 | 
					import EventEmitter from 'events'; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import favicon from 'serve-favicon'; | 
					 | 
					 | 
					import favicon from 'serve-favicon'; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					import url from 'url'; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					const app = express(); | 
					 | 
					 | 
					const app = express(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					app.use(favicon(`${__dirname}/public/favicon.ico`)); | 
					 | 
					 | 
					app.use(favicon(`${__dirname}/public/favicon.ico`)); | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					@ -36,12 +37,24 @@ function createServer(port, sslopts) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    }); | 
					 | 
					 | 
					    }); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					} | 
					 | 
					 | 
					} | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					function getCommand(socket, sshuser, sshhost, sshport, sshauth, sshkey) { | 
					 | 
					 | 
					function getCommand(socket, sshuser, sshpass, sshhost, sshport, sshauth, sshkey) { | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					  const { request } = socket; | 
					 | 
					 | 
					  const { request } = socket; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					  const match = request.headers.referer.match('.+/ssh/.+$'); | 
					 | 
					 | 
					  const match = request.headers.referer.match('.+/ssh/.+$'); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					  console.log("Match ", match); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					  console.log("user ", sshuser); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					  const sshAddress = sshuser ? `${sshuser}@${sshhost}` : sshhost; | 
					 | 
					 | 
					  const sshAddress = sshuser ? `${sshuser}@${sshhost}` : sshhost; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					  const sshPath = sshuser || match ? 'ssh' : path.join(__dirname, 'bin/ssh'); | 
					 | 
					 | 
					  console.log("Address ", sshAddress); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					  const ssh = match ? `${match[0].split('/ssh/').pop()}@${sshhost}` : sshAddress; | 
					 | 
					 | 
					  const referer = url.parse(request.headers.referer, true); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					  sshpass = referer.query.sshpass ? referer.query.sshpass : sshpass; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					  console.log("PASS ", sshpass); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					  let sshPath = '' | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					  if (!sshpass) | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					    sshPath = sshuser || match ? 'ssh' : path.join(__dirname, 'bin/ssh'); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					  else | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					    sshPath = ['sshpass', '-p', sshpass].join(' '); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					  console.log("PATH ", sshPath); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					  const ssh = match ? `${match[0].split('/ssh/').pop().split('?')[0]}@${sshhost}` : sshAddress; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					  console.log("SSH ", ssh); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					  const sshRemoteOptsBase = [ | 
					 | 
					 | 
					  const sshRemoteOptsBase = [ | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                            sshPath, | 
					 | 
					 | 
					                            sshPath, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                            ssh, | 
					 | 
					 | 
					                            ssh, | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -52,7 +65,7 @@ function getCommand(socket, sshuser, sshhost, sshport, sshauth, sshkey) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                            ] | 
					 | 
					 | 
					                            ] | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					  const sshRemoteOpts = sshkey ? sshRemoteOptsBase.concat(['-i', sshkey]) | 
					 | 
					 | 
					  const sshRemoteOpts = sshkey ? sshRemoteOptsBase.concat(['-i', sshkey]) | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                               : sshRemoteOptsBase | 
					 | 
					 | 
					                               : sshRemoteOptsBase | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					
 | 
					 | 
					 | 
					  console.log(sshRemoteOpts); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					  return [ | 
					 | 
					 | 
					  return [ | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    process.getuid() === 0 && sshhost === 'localhost' | 
					 | 
					 | 
					    process.getuid() === 0 && sshhost === 'localhost' | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					      ? ['login', '-h', socket.client.conn.remoteAddress.split(':')[3]] | 
					 | 
					 | 
					      ? ['login', '-h', socket.client.conn.remoteAddress.split(':')[3]] | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -62,12 +75,14 @@ function getCommand(socket, sshuser, sshhost, sshport, sshauth, sshkey) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					  ]; | 
					 | 
					 | 
					  ]; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					} | 
					 | 
					 | 
					} | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					export default function start(port, sshuser, sshhost, sshport, sshauth, sshkey, sslopts) { | 
					 | 
					 | 
					export default function start(port, sshuser, sshpass, sshhost, sshport, sshauth, sshkey, sslopts) { | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					  console.log("START", port, sshuser, sshpass, sshhost, sshport, sshauth, sshkey, sslopts); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					  const events = new EventEmitter(); | 
					 | 
					 | 
					  const events = new EventEmitter(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					  const io = server(createServer(port, sslopts), { path: '/wetty/socket.io' }); | 
					 | 
					 | 
					  const io = server(createServer(port, sslopts), { path: '/wetty/socket.io' }); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					  io.on('connection', socket => { | 
					 | 
					 | 
					  io.on('connection', socket => { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    console.log(`${new Date()} Connection accepted.`); | 
					 | 
					 | 
					    console.log(`${new Date()} Connection accepted.`); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					    const [args, ssh] = getCommand(socket, sshuser, sshhost, sshport, sshauth, sshkey); | 
					 | 
					 | 
					    const [args, ssh] = getCommand(socket, sshuser, sshpass, sshhost, sshport, sshauth, sshkey); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					    console.log("PIKA PIKA", args, ssh); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    const term = spawn('/usr/bin/env', args, { | 
					 | 
					 | 
					    const term = spawn('/usr/bin/env', args, { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					      name: 'xterm-256color', | 
					 | 
					 | 
					      name: 'xterm-256color', | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					      cols: 80, | 
					 | 
					 | 
					      cols: 80, | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					
  |