zack commited on
Commit
1808c39
·
1 Parent(s): e99cd9a

🔧 Modified backend and frontend for enhanced functionality

Browse files
backend/app.py CHANGED
@@ -1,5 +1,4 @@
1
  from flask import Flask, jsonify, request
2
- from flask_socketio import SocketIO, emit
3
  from flask_cors import CORS
4
  import socket
5
  import argparse
@@ -7,11 +6,9 @@ import argparse
7
  # import asyncio
8
  # from multiprocessing import Process
9
  import gradio as gr
10
- import requests
11
 
12
  app = Flask(__name__)
13
  CORS(app)
14
- socketio = SocketIO(app, cors_allowed_origins="*")
15
 
16
  def portConnection(port : int):
17
  s = socket.socket(
@@ -100,49 +97,9 @@ def remove_port():
100
 
101
  @app.route("/api/open/ports", methods=["GET"])
102
  def open_ports():
103
- # Assuming 'visable' is a list of open ports information
104
  return jsonify(visable)
105
 
106
- ## Proxmox API
107
-
108
- @app.route('/api/addProxmoxVM', methods=['POST'])
109
- def add_proxmox_vm():
110
- data = request.json
111
- # Placeholder for saving or processing Proxmox VM data
112
- # This should include logic to handle the data received from the frontend
113
- return jsonify({"status": "VM added"}), 200
114
-
115
- @app.route('/api/getVncUrl', methods=['GET'])
116
- def get_vnc_url():
117
- vm_address = request.args.get('vmAddress')
118
- # Placeholder for fetching VNC URL based on VM address
119
- # This should include logic to retrieve the VNC URL for the specified VM
120
- vnc_url = "https://example.com/vnc/" + vm_address # Example VNC URL
121
- return jsonify({"vncUrl": vnc_url})
122
-
123
- @socketio.on('connect')
124
- def handle_connect():
125
- print('Client connected')
126
-
127
- @socketio.on('disconnect')
128
- def handle_disconnect():
129
- print('Client disconnected')
130
-
131
- @socketio.on('fetchVmData')
132
- def handle_fetch_vm_data(data):
133
- # Fetch VM data from Proxmox using the provided VM address
134
- # The actual fetching should be adapted to match your Proxmox setup and API
135
- try:
136
- vm_data = requests.get(f"http://{data['vm_address']}/api2/json", verify=False) # Example request
137
- emit('vmData', vm_data.json())
138
- except requests.exceptions.RequestException as e:
139
- print(f"Error fetching VM data: {e}")
140
- emit('vmData', {'error': 'Failed to fetch VM data'})
141
-
142
- if __name__ == '__main__':
143
- socketio.run(app, debug=True, host='0.0.0.0')
144
-
145
- ## Gradio API
146
  if __name__ == "__main__":
147
 
148
  parser = argparse.ArgumentParser()
@@ -152,3 +109,5 @@ if __name__ == "__main__":
152
 
153
 
154
 
 
 
 
1
  from flask import Flask, jsonify, request
 
2
  from flask_cors import CORS
3
  import socket
4
  import argparse
 
6
  # import asyncio
7
  # from multiprocessing import Process
8
  import gradio as gr
 
9
 
10
  app = Flask(__name__)
11
  CORS(app)
 
12
 
13
  def portConnection(port : int):
14
  s = socket.socket(
 
97
 
98
  @app.route("/api/open/ports", methods=["GET"])
99
  def open_ports():
 
100
  return jsonify(visable)
101
 
102
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  if __name__ == "__main__":
104
 
105
  parser = argparse.ArgumentParser()
 
109
 
110
 
111
 
112
+
113
+
backend/requirements.txt CHANGED
@@ -71,4 +71,5 @@ urllib3==1.26.10
71
  uvicorn==0.18.2
72
  Werkzeug==2.2.0
73
  yarl==1.7.2
74
- zipp==3.8.1
 
 
71
  uvicorn==0.18.2
72
  Werkzeug==2.2.0
73
  yarl==1.7.2
74
+ zipp==3.8.1
75
+ flask-socketio
frontend/src/components/ReactFlow/ReactFlowEnv.js CHANGED
@@ -18,10 +18,12 @@ import {CgMoreVerticalAlt} from 'react-icons/cg'
18
  import {BsFillEraserFill} from 'react-icons/bs'
19
  import {FaRegSave} from 'react-icons/fa'
20
  import ProxmoxVM from '../Proxmox/proxmox.js';
 
21
 
22
  const NODE = {
23
  custom : CustomNodeIframe,
24
  proxmoxVM: ProxmoxVM,
 
25
  }
26
 
27
  const EDGE = {
@@ -137,23 +139,32 @@ export default function ReactEnviorment() {
137
  y: event.clientY - reactFlowBounds.top,
138
  });
139
 
140
- if (type === 'customProxmox') {
141
- const newNode = {
 
 
 
 
 
 
 
 
142
  id: `proxmox-vm-${nodes.length + 1}`,
143
  type: 'customProxmox',
144
  position,
145
  data: { vmAddress: item.vmAddress },
146
  };
147
- setNodes((nds) => nds.concat(newNode));
148
  } else {
149
- const newNode = {
150
  id: `${item.name}-${nodes.length+1}`,
151
  type,
152
  position,
153
  dragHandle : `#draggable`,
154
  data: { label: `${item.name}`, host : `${item.host}`, colour : `${style.colour}`, emoji : `${style.emoji}`, delete : deleteNode },
155
  };
 
156
 
 
157
  setNodes((nds) => nds.concat(newNode));
158
  }
159
  }
 
18
  import {BsFillEraserFill} from 'react-icons/bs'
19
  import {FaRegSave} from 'react-icons/fa'
20
  import ProxmoxVM from '../Proxmox/proxmox.js';
21
+ import EmbedNode from "../Nodes/EmbedNode.js";
22
 
23
  const NODE = {
24
  custom : CustomNodeIframe,
25
  proxmoxVM: ProxmoxVM,
26
+ embed: EmbedNode,
27
  }
28
 
29
  const EDGE = {
 
139
  y: event.clientY - reactFlowBounds.top,
140
  });
141
 
142
+ let newNode;
143
+ if (type === 'embed') {
144
+ newNode = {
145
+ id: `embed-${nodes.length + 1}`,
146
+ type: 'embed',
147
+ position,
148
+ data: { url: item.url, width: item.width, height: item.height },
149
+ };
150
+ } else if (type === 'customProxmox') {
151
+ newNode = {
152
  id: `proxmox-vm-${nodes.length + 1}`,
153
  type: 'customProxmox',
154
  position,
155
  data: { vmAddress: item.vmAddress },
156
  };
 
157
  } else {
158
+ newNode = {
159
  id: `${item.name}-${nodes.length+1}`,
160
  type,
161
  position,
162
  dragHandle : `#draggable`,
163
  data: { label: `${item.name}`, host : `${item.host}`, colour : `${style.colour}`, emoji : `${style.emoji}`, delete : deleteNode },
164
  };
165
+ }
166
 
167
+ if (newNode) {
168
  setNodes((nds) => nds.concat(newNode));
169
  }
170
  }