Skip to content

Commit 8bd7e4e

Browse files
authored
Merge pull request #33 from chechojgb/terminal
style: actualizacion altura terminal
2 parents 4d4f87b + 5fa32fc commit 8bd7e4e

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

microservicio-ssh/index.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// index.js (backend Node.js)
12
const WebSocket = require('ws');
23
const { Client } = require('ssh2');
34

@@ -15,14 +16,23 @@ wss.on('connection', function connection(ws) {
1516
const data = JSON.parse(message);
1617
console.log("📥 Mensaje recibido del front:", data);
1718

19+
if (!data?.type) return;
20+
1821
// 🔌 Conexión SSH
1922
if (data.type === 'connect') {
20-
const { host, port, username, password } = data.payload;
23+
const payload = data.payload;
24+
25+
if (!payload) {
26+
console.error("❌ connect recibido sin payload");
27+
ws.send("❌ connect recibido sin payload\n");
28+
return;
29+
}
30+
31+
const { host, port, username, password } = payload;
2132

2233
if (!host || !port || !username || !password) {
2334
console.error("❌ Faltan datos de conexión SSH");
2435
ws.send("❌ Datos incompletos para conectar al servidor SSH\n");
25-
ws.close();
2636
return;
2737
}
2838

@@ -35,32 +45,28 @@ wss.on('connection', function connection(ws) {
3545
if (err) {
3646
console.error("❌ Error al iniciar shell SSH:", err);
3747
ws.send("❌ Error al iniciar shell SSH\n");
38-
ws.close();
3948
return;
4049
}
4150

4251
sshStream = stream;
4352

4453
stream
45-
.on('data', (chunk) => {
46-
ws.send(chunk.toString());
47-
})
54+
.on('data', (chunk) => ws.send(chunk.toString()))
4855
.on('close', () => {
4956
console.log("🔌 Shell cerrada");
5057
sshClient.end();
5158
});
5259

53-
stream.stderr?.on('data', (chunk) => {
54-
console.error("🛑 STDERR:", chunk.toString());
55-
});
60+
stream.stderr?.on('data', (chunk) =>
61+
console.error("🛑 STDERR:", chunk.toString())
62+
);
5663

5764
ws.send("🟢 Conectado al servidor SSH\n");
5865
});
5966
})
6067
.on('error', (err) => {
6168
console.error("❌ Error en SSH:", err);
6269
ws.send(`❌ Error de conexión SSH: ${err.message}\n`);
63-
ws.close();
6470
})
6571
.on('end', () => {
6672
console.log("🔚 Conexión SSH finalizada");
@@ -75,11 +81,9 @@ wss.on('connection', function connection(ws) {
7581
}
7682

7783
// 📐 Redimensionar ventana
78-
if (data.type === 'resize') {
84+
if (data.type === 'resize' && sshStream && data.payload) {
7985
const { cols, rows } = data.payload;
80-
if (sshStream) {
81-
sshStream.setWindow(rows, cols, rows * 24, cols * 8);
82-
}
86+
sshStream.setWindow(rows, cols, rows * 24, cols * 8);
8387
}
8488

8589
} catch (err) {
@@ -90,9 +94,7 @@ wss.on('connection', function connection(ws) {
9094

9195
ws.on('close', () => {
9296
console.log("🔴 Cliente WebSocket desconectado");
93-
if (sshClient) {
94-
sshClient.end();
95-
}
97+
if (sshClient) sshClient.end();
9698
});
9799

98100
ws.on('error', (err) => {

resources/js/components/terminal/XTermSSH.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export default function XTermSSH() {
9090
}, [session]);
9191

9292
return (
93-
<div className="flex-grow w-full min-h-0">
93+
<div className="w-full h-screen">
9494
<div
9595
ref={terminalRef}
9696
className="w-full h-full"

resources/js/pages/XTermSSH.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default function TableAgents() {
2020
return (
2121
<AppLayout breadcrumbs={breadcrumbs}>
2222
<Head title="Terminal" />
23-
<div className="h-screen w-screen flex flex-col bg-black">
23+
<div className="w-full h-full bg-black">
2424
<XTermSSH sessionId={sessionId} />
2525
</div>
2626
</AppLayout>

0 commit comments

Comments
 (0)