Update app/server.js
Browse files- app/server.js +16 -8
app/server.js
CHANGED
@@ -35,22 +35,27 @@ function onRequest(req, res) {
|
|
35 |
// Setup WebSocket connection
|
36 |
io.on('connection', (socket) => {
|
37 |
const conn = new SSHClient();
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
39 |
// On SSH connection ready
|
40 |
conn.on('ready', () => {
|
41 |
socket.emit('data', '\r\n*** SSH CONNECTION ESTABLISHED ***\r\n');
|
42 |
-
|
43 |
// Start shell session
|
44 |
conn.shell((err, stream) => {
|
45 |
if (err) {
|
46 |
return socket.emit('data', '\r\n*** SSH SHELL ERROR: ' + err.message + ' ***\r\n');
|
47 |
}
|
48 |
-
|
49 |
// When data is received from the client, write to the stream
|
50 |
socket.on('data', (data) => {
|
51 |
stream.write(data);
|
52 |
});
|
53 |
-
|
54 |
// Send data back to the client when received from the SSH session
|
55 |
stream.on('data', (d) => {
|
56 |
socket.emit('data', d.toString('binary'));
|
@@ -63,13 +68,16 @@ io.on('connection', (socket) => {
|
|
63 |
socket.emit('data', '\r\n*** SSH CONNECTION CLOSED ***\r\n');
|
64 |
})
|
65 |
.on('error', (err) => {
|
|
|
66 |
socket.emit('data', '\r\n*** SSH CONNECTION ERROR: ' + err.message + ' ***\r\n');
|
67 |
})
|
68 |
.connect({
|
69 |
-
host: process.env.REMOTE_HOST,
|
70 |
-
port: 22,
|
71 |
-
username: process.env.REMOTE_USERNAME,
|
72 |
-
password: process.env.REMOTE_PASSWORD
|
|
|
|
|
73 |
});
|
74 |
});
|
75 |
|
|
|
35 |
// Setup WebSocket connection
|
36 |
io.on('connection', (socket) => {
|
37 |
const conn = new SSHClient();
|
38 |
+
|
39 |
+
// Debug logging
|
40 |
+
conn.on('debug', (msg) => {
|
41 |
+
console.log('DEBUG:', msg);
|
42 |
+
});
|
43 |
+
|
44 |
// On SSH connection ready
|
45 |
conn.on('ready', () => {
|
46 |
socket.emit('data', '\r\n*** SSH CONNECTION ESTABLISHED ***\r\n');
|
47 |
+
|
48 |
// Start shell session
|
49 |
conn.shell((err, stream) => {
|
50 |
if (err) {
|
51 |
return socket.emit('data', '\r\n*** SSH SHELL ERROR: ' + err.message + ' ***\r\n');
|
52 |
}
|
53 |
+
|
54 |
// When data is received from the client, write to the stream
|
55 |
socket.on('data', (data) => {
|
56 |
stream.write(data);
|
57 |
});
|
58 |
+
|
59 |
// Send data back to the client when received from the SSH session
|
60 |
stream.on('data', (d) => {
|
61 |
socket.emit('data', d.toString('binary'));
|
|
|
68 |
socket.emit('data', '\r\n*** SSH CONNECTION CLOSED ***\r\n');
|
69 |
})
|
70 |
.on('error', (err) => {
|
71 |
+
console.error('SSH Connection Error:', err);
|
72 |
socket.emit('data', '\r\n*** SSH CONNECTION ERROR: ' + err.message + ' ***\r\n');
|
73 |
})
|
74 |
.connect({
|
75 |
+
host: process.env.REMOTE_HOST,
|
76 |
+
port: 22,
|
77 |
+
username: process.env.REMOTE_USERNAME,
|
78 |
+
password: process.env.REMOTE_PASSWORD,
|
79 |
+
readyTimeout: 60000,
|
80 |
+
debug: (msg) => console.log('DEBUG:', msg) // Enable debug logging
|
81 |
});
|
82 |
});
|
83 |
|