diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index bf924fd2..1c35bf66 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,7 +4,7 @@
-
+
@@ -64,6 +64,7 @@
"npm.run_start_vite.executor": "Run",
"npm.start.executor": "Run",
"settings.editor.selected.configurable": "ml.llm.LLMConfigurable",
+ "ts.external.directory.path": "D:\\Program Files (x86)\\Applications\\Jetbrains Webstorm\\WebStorm 2024.3.1\\plugins\\javascript-plugin\\jsLanguageServicesImpl\\external",
"vue.rearranger.settings.migration": "true"
}
}]]>
@@ -114,7 +115,7 @@
1733439468142
-
+
@@ -164,7 +165,15 @@
1733450304640
-
+
+
+ 1733450681262
+
+
+
+ 1733450681262
+
+
@@ -175,6 +184,7 @@
-
+
+
\ No newline at end of file
diff --git a/backend/server.js b/backend/server.js
index ee2d8ea2..83b70fa6 100644
--- a/backend/server.js
+++ b/backend/server.js
@@ -1,5 +1,5 @@
const WebSocket = require('ws');
-const ssh2 = require('ssh2');
+const SSH = require('ssh2-promise');
const http = require('http');
const server = http.createServer((req, res) => {
@@ -11,105 +11,81 @@ const wss = new WebSocket.Server({ server });
wss.on('connection', (ws) => {
console.log('WebSocket connection established');
- let conn = null;
- let termDimensions = { rows: 0, cols: 0, height: 0, width: 0 }; // Store terminal dimensions
+ let ssh = null;
+ let termDimensions = { rows: 0, cols: 0, height: 0, weight: 0 };
+
+ ws.on('message', async (message) => {
+ try {
+ const data = JSON.parse(message);
+ if (data.type === 'resize') {
+ termDimensions = data;
+ } else if (data.username && data.password) {
+ ssh = new SSH({
+ host: data.host,
+ username: data.username,
+ password: data.password
+ });
+
+ try {
+ await ssh.connect();
+ const stream = await ssh.shell();
+
+ stream.on('data', (data) => {
+ const dataString = data.toString();
+ ws.send(dataString);
+ });
+
+ stream.stderr.on('data', (data) => {
+ const errorString = data.toString();
+ console.error('SSH error:', errorString);
+ });
+
+ ws.on('message', (message) => {
+ try {
+ const data = JSON.parse(message);
+ if (data.type === 'resize') {
+ termDimensions = data;
+ }
+ } catch (err) {
+ stream.write(message);
+ }
+ });
+
+ stream.on('close', () => {
+ console.log('Stream closed');
+ ssh.close();
+ });
+ } catch (err) {
+ console.error('SSH connection error:', err);
+ }
+ }
+ } catch (err) {
+ console.error('Message processing error:', err);
+ }
+ });
+
+ ws.on('close', () => {
+ console.log('WebSocket closed');
+ if (ssh) {
+ ssh.close();
+ }
+ });
+
+ ws.on('error', (err) => {
+ console.error('WebSocket error:', err);
+ });
+
+ // Ping-pong is used to keep the connection alive.
const interval = setInterval(() => {
if (ws.readyState === WebSocket.OPEN) {
ws.ping();
} else {
clearInterval(interval);
}
- }, 15000);
-
- ws.on('pong', () => {
- console.log('Received pong from client');
- });
-
- ws.on('message', (message) => {
- try {
- const data = JSON.parse(message);
-
- if (data.host && data.username && data.password) {
- if (conn) {
- conn.end();
- }
-
- conn = new ssh2.Client();
-
- conn
- .on('ready', () => {
- console.log('SSH Connection established');
- conn.shell((err, stream) => {
- if (err) {
- ws.send(`Error: ${err.message}`);
- return;
- }
-
- stream.on('data', (data) => {
- const dataString = data.toString();
- ws.send(dataString);
-
- if (exitCode === 0) {
- stream.setWindow(termDimensions.rows, termDimensions.cols, termDimensions.height, termDimensions.width);
- }
- });
-
- stream.stderr.on('data', (data) => {
- console.error('SSH stderr:', data.toString())
- })
-
- stream.on('close', () => {
- console.log('SSH Stream closed');
- conn.end();
- ws.send(JSON.stringify({ type: 'process_closed' })); // Signal process has closed
- });
-
- ws.on('message', (message) => {
- try {
- const data = JSON.parse(message);
- if (data.type === 'resize' && data.rows && data.cols) {
- console.log('Resize event received:', data);
- termDimensions = data; // Store received dimensions
- stream.setWindow(data.rows, data.cols, data.height, data.width);
- }
- } catch (err) {
- console.log('User Input:', message);
- stream.write(message);
- }
- });
- });
- })
- .on('error', (err) => {
- console.log('SSH Error:', err.message);
- ws.send(`SSH Error: ${err.message}`);
- })
- .on('close', () => {
- console.log('SSH Connection closed');
- })
- .connect({
- host: data.host,
- port: 22,
- username: data.username,
- password: data.password,
- keepaliveInterval: 20000,
- keepaliveCountMax: 5,
- });
- }
- } catch (error) {
- console.log('Non-JSON message received:', message);
- }
- });
-
- ws.on('close', () => {
- console.log('WebSocket closed');
- clearInterval(interval);
- if (conn) {
- conn.end();
- }
- });
+ }, 5000);
});
-server.listen(8081, () => {
- console.log('WebSocket server is running on ws://localhost:8081');
+server.listen(8000, () => {
+ console.log('Server listening on port 8000');
});
\ No newline at end of file
diff --git a/info.txt b/info.txt
index 0c91e9cf..19771237 100644
--- a/info.txt
+++ b/info.txt
@@ -2,6 +2,7 @@ Currently:
Fix issue after nano where the input no longer goes down to the bottom.
Fix issue where SSH randomly disconnects
ntfy notifcation after build push
+numbers dont work in ssh
Overall Features:
SSH/RDP(?)/VNC(?)