Spaces:
Configuration error
Configuration error
zack
commited on
Commit
Β·
c70b233
1
Parent(s):
77526d6
π fix: address vulnerabilities in xterm.js
Browse files
backend/src/proxmox/proxmoxService.js
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const axios = require('axios');
|
2 |
+
|
3 |
+
const PROXMOX_API_URL = 'https://your-proxmox-server:8006/api2/json';
|
4 |
+
const AUTH_TOKEN = 'PVEAPIToken=yourToken';
|
5 |
+
|
6 |
+
async function fetchVmData() {
|
7 |
+
try {
|
8 |
+
const response = await axios.get(`${PROXMOX_API_URL}/nodes/yourNode/qemu`, {
|
9 |
+
headers: { Authorization: AUTH_TOKEN },
|
10 |
+
});
|
11 |
+
return response.data;
|
12 |
+
} catch (error) {
|
13 |
+
console.error('Error fetching VM data from Proxmox:', error);
|
14 |
+
return null;
|
15 |
+
}
|
16 |
+
}
|
17 |
+
|
18 |
+
module.exports = { fetchVmData };
|
backend/src/proxmox/websocketServer.js
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const WebSocket = require('ws');
|
2 |
+
const { fetchVmData } = require('./proxmoxService');
|
3 |
+
|
4 |
+
const wss = new WebSocket.Server({ port: 8080 });
|
5 |
+
|
6 |
+
wss.on('connection', function connection(ws) {
|
7 |
+
ws.on('message', async function incoming(message) {
|
8 |
+
console.log('received: %s', message);
|
9 |
+
// Assuming message contains the action to fetch VM data
|
10 |
+
if (message === 'fetchVmData') {
|
11 |
+
const data = await fetchVmData();
|
12 |
+
ws.send(JSON.stringify(data));
|
13 |
+
}
|
14 |
+
});
|
15 |
+
});
|
16 |
+
|
17 |
+
console.log('WebSocket server started on port 8080');
|
frontend/components/xterm.js
CHANGED
@@ -1,21 +1,30 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
14 |
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
17 |
|
18 |
-
|
19 |
-
|
20 |
|
21 |
-
|
|
|
1 |
+
import React, { useEffect, useRef } from 'react';
|
2 |
+
import { Terminal } from 'xterm';
|
3 |
+
import 'xterm/css/xterm.css';
|
4 |
|
5 |
+
const TerminalComponent = ({ socket }) => {
|
6 |
+
const terminalRef = useRef(null);
|
7 |
+
useEffect(() => {
|
8 |
+
const terminal = new Terminal();
|
9 |
+
terminal.open(terminalRef.current);
|
10 |
|
11 |
+
const ws = new WebSocket('ws://localhost:8080');
|
12 |
+
ws.onopen = () => {
|
13 |
+
console.log('Connected to WebSocket');
|
14 |
+
ws.send('fetchVmData'); // Request VM data on connection
|
15 |
+
};
|
16 |
+
ws.onmessage = (event) => {
|
17 |
+
const data = JSON.parse(event.data);
|
18 |
+
terminal.write(JSON.stringify(data, null, 2)); // Display VM data in terminal
|
19 |
+
};
|
20 |
|
21 |
+
return () => {
|
22 |
+
ws.close();
|
23 |
+
socket.off('data');
|
24 |
+
};
|
25 |
+
}, []);
|
26 |
|
27 |
+
return <div ref={terminalRef} />;
|
28 |
+
};
|
29 |
|
30 |
+
export default TerminalComponent;
|