Update Dockerfile
Browse files- Dockerfile +81 -33
Dockerfile
CHANGED
|
@@ -1,39 +1,87 @@
|
|
| 1 |
-
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
chown -R 1001:0 /app
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
ENV REMOTE_HOST=your.remote.host
|
| 35 |
-
ENV REMOTE_USERNAME=username
|
| 36 |
-
ENV REMOTE_PASSWORD=password
|
| 37 |
-
|
| 38 |
-
# Start the Node.js server
|
| 39 |
-
CMD [ "node", "server.js" ]
|
|
|
|
| 1 |
+
const fs = require('fs');
|
| 2 |
+
const path = require('path');
|
| 3 |
+
const http = require('http');
|
| 4 |
+
const SSHClient = require('ssh2').Client;
|
| 5 |
+
const socketIO = require('socket.io');
|
| 6 |
|
| 7 |
+
// Create HTTP server
|
| 8 |
+
const server = http.createServer(onRequest);
|
| 9 |
|
| 10 |
+
// Attach Socket.IO to the server
|
| 11 |
+
const io = socketIO(server);
|
| 12 |
|
| 13 |
+
// Load static files into memory
|
| 14 |
+
let staticFiles = {};
|
| 15 |
+
let basePath = path.join(require.resolve('xterm'), '..');
|
| 16 |
+
staticFiles['/xterm.css'] = fs.readFileSync(path.join(basePath, '../css/xterm.css'));
|
| 17 |
+
staticFiles['/xterm.js'] = fs.readFileSync(path.join(basePath, 'xterm.js'));
|
| 18 |
+
basePath = path.join(require.resolve('xterm-addon-fit'), '..');
|
| 19 |
+
staticFiles['/xterm-addon-fit.js'] = fs.readFileSync(path.join(basePath, 'xterm-addon-fit.js'));
|
| 20 |
+
staticFiles['/'] = fs.readFileSync('index.html');
|
| 21 |
|
| 22 |
+
// Handle static file serving
|
| 23 |
+
function onRequest(req, res) {
|
| 24 |
+
let file;
|
| 25 |
+
if (req.method === 'GET' && (file = staticFiles[req.url])) {
|
| 26 |
+
res.writeHead(200, {
|
| 27 |
+
'Content-Type': 'text/' + (/css$/.test(req.url) ? 'css' : (/js$/.test(req.url) ? 'javascript' : 'html'))
|
| 28 |
+
});
|
| 29 |
+
return res.end(file);
|
| 30 |
+
}
|
| 31 |
+
res.writeHead(404);
|
| 32 |
+
res.end();
|
| 33 |
+
}
|
|
|
|
| 34 |
|
| 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'));
|
| 62 |
+
}).on('close', () => {
|
| 63 |
+
conn.end();
|
| 64 |
+
});
|
| 65 |
+
});
|
| 66 |
+
})
|
| 67 |
+
.on('close', () => {
|
| 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, // Use environment variable
|
| 76 |
+
port: 22, // Default SSH port
|
| 77 |
+
username: process.env.REMOTE_USERNAME, // Use environment variable
|
| 78 |
+
password: process.env.REMOTE_PASSWORD, // Use environment variable (or use privateKey if required)
|
| 79 |
+
readyTimeout: 60000, // Increase timeout to 60 seconds
|
| 80 |
+
debug: (msg) => console.log('DEBUG:', msg) // Enable debug logging
|
| 81 |
+
});
|
| 82 |
+
});
|
| 83 |
|
| 84 |
+
// Start the server
|
| 85 |
+
const port = 8000;
|
| 86 |
+
console.log('Listening on port', port);
|
| 87 |
+
server.listen(port);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|