-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
110 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const path = require('path'); | ||
const ssh = require('ssh2').Client; | ||
const TextDecoder = require('text-encoding').TextDecoder; | ||
const config = require('read-config')(path.resolve(__dirname, '../config.json')); | ||
|
||
exports.connection = function(socket) { | ||
var conn = new ssh(); | ||
|
||
// ssh 连接相关配置 | ||
config.ssh = socket.request.session.ssh; | ||
|
||
conn.on('banner', function(d) { | ||
//need to convert to cr/lf for proper formatting | ||
d = d.replace(/\r?\n/g, '\r\n'); | ||
socket.emit('data', d.toString('binary')); | ||
}).on('ready', function() { | ||
|
||
// TODO | ||
|
||
}).on('end', function() { | ||
socket.disconnect(); | ||
}).on('close', function() { | ||
socket.disconnect(); | ||
}).on('error', function(err) { | ||
console.error('Error: ' + err); | ||
}).connect({ | ||
host: config.ssh.host, | ||
port: config.ssh.port, | ||
username: config.ssh.username, | ||
password: config.ssh.password | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React from 'react'; | ||
|
||
import './index.css'; | ||
|
||
export default class Term extends React.Component { | ||
|
||
componentDidMount() { | ||
this.init(); | ||
} | ||
|
||
init = () => { | ||
const terminalContainer = document.getElementById('terminal-container'); | ||
const term = new Terminal({ cursorBlink: true }); | ||
var socket; | ||
|
||
term.open(terminalContainer); | ||
term.fit(); | ||
|
||
if (document.location.pathname) { | ||
var parts = document.location.pathname.split('/'), | ||
base = parts.slice(0, parts.length - 1).join('/') + '/', | ||
resource = base.substring(1) + 'socket.io'; | ||
socket = io.connect('/shell', { resource: resource }); | ||
} else { | ||
socket = io.connect('/shell'); | ||
} | ||
|
||
socket.on('connect', function() { | ||
|
||
socket.emit('size', term.cols, term.rows); | ||
|
||
term.on('data', function(data) { | ||
socket.emit('data', data); | ||
}); | ||
|
||
socket.on('title', function(data) { | ||
document.title = data; | ||
}).on('status', function(data) { | ||
document.getElementById('status').innerHTML = data; | ||
}).on('footer', function(data) { | ||
document.getElementById('footer').innerHTML = data; | ||
}).on('statusBackground', function(data) { | ||
document.getElementById('status').style.backgroundColor = data; | ||
}).on('data', function(data) { | ||
term.write(data); | ||
}).on('disconnect', function(err) { | ||
document.getElementById('status').style.backgroundColor = 'red'; | ||
document.getElementById('status').innerHTML = 'WEBSOCKET SERVER DISCONNECTED' + err; | ||
socket.io.reconnection(false); | ||
}).on('error', function(err) { | ||
document.getElementById('status').style.backgroundColor = 'red'; | ||
document.getElementById('status').innerHTML = 'ERROR ' + err; | ||
}); | ||
|
||
}); | ||
|
||
} | ||
|
||
render() { | ||
return ( | ||
<div className="box"> | ||
<div id="header"></div> | ||
<div id="terminal-container" className="terminal"></div> | ||
<div id="bottomdiv"> | ||
<div id="status"></div> | ||
<div id="footer"></div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters