Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6bf62a5

Browse files
committed
Implement server auto-discovery and improve client-server connection
1 parent23cb6ff commit6bf62a5

File tree

6 files changed

+124
-21
lines changed

6 files changed

+124
-21
lines changed

‎README.md‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@
3131
-[Performance Optimization](#performance-optimization)
3232
-[📊 Examples](#-examples)
3333
-[🚀 Installation](#-installation)
34-
-[🐋 Docker Installation (Recommended)](#-docker-installation-recommended)
35-
-[🔧 Manual Installation](#-manual-installation)
34+
-[Option 1: Quick Start with Docker Hub (Recommended)](#option-1-quick-start-with-docker-hub-recommended)
35+
-[Option 2: Build from Source](#option-2-build-from-source)
36+
-[Option 3: Manual Installation](#option-3-manual-installation)
37+
-[🔄 Updates](#-updates)
38+
-[Option 1: Using Watchtower (Automatic)](#option-1-using-watchtower-automatic)
39+
-[Option 2: Manual Update](#option-2-manual-update)
3640
-[📁 Project Structure](#-project-structure)
3741
-[⚙️ Configuration](#️-configuration)
3842
-[Service Configuration](#service-configuration)
@@ -163,7 +167,7 @@ docker run -d \
163167
# The application will be available at:
164168
# - API Server: http://0.0.0.0:5000 (all interfaces)
165169
# - Web Interface: http://0.0.0.0:8080 (all interfaces)
166-
#
170+
#
167171
# You can also access it via:
168172
# - http://localhost:5000 and http://localhost:8080
169173
# - http://your-ip:5000 and http://your-ip:8080
@@ -195,6 +199,7 @@ docker run -d \
195199
<summary>Click to expand manual installation steps</summary>
196200

197201
1. Clone repository and install dependencies:
202+
198203
```bash
199204
# Clone repository
200205
git clone https://github.com/cansolele/exploit-seek.git
@@ -214,6 +219,7 @@ pip install -r requirements.txt
214219
```
215220

216221
2. Build and start the client:
222+
217223
```bash
218224
# Build client
219225
cd ../client
@@ -225,6 +231,7 @@ npx serve -s dist -l tcp://0.0.0.0:8080
225231
```
226232

227233
3. Start the server (in a new terminal):
234+
228235
```bash
229236
# Activate virtual environment
230237
cd exploit-seek
@@ -237,6 +244,7 @@ gunicorn --worker-class geventwebsocket.gunicorn.workers.GeventWebSocketWorker \
237244
```
238245

239246
The application will be available at:
247+
240248
- API Server:http://0.0.0.0:5000 (all interfaces)
241249
- Web Interface:http://0.0.0.0:8080 (all interfaces)
242250

@@ -379,7 +387,8 @@ Configure proxy settings in the application settings after installation.
379387
##📱 Usage
380388

381389
1.**Initial Setup**
382-
- Configure server address
390+
- Server address is automatically detected when client and server are on the same host
391+
- If needed, configure server address manually in settings
383392
- Set up API keys (NVD, VulnCheck)
384393
- Choose interface language (English/Russian)
385394
- Select theme mode (Dark/Light)

‎client/src/App.jsx‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,21 @@ import Header from "./components/Header/Header";
66
importExploitsTablefrom"./components/ExploitsTable/ExploitsTable";
77
importAuthfrom"./components/Auth/Auth";
88
importThemefrom"./Theme";
9-
importuseSocketfrom"./hooks/useSocket";
9+
import{useSocket}from"./hooks/useSocket";
1010
import{useSettings}from"./hooks/useSettings";
11+
import{useServerDiscovery}from"./hooks/useServerDiscovery";
1112
importaxiosfrom"axios";
1213

1314
axios.defaults.withCredentials=true;
1415

1516
constApp=()=>{
16-
const[serverAddress,setServerAddress]=useState(
17-
localStorage.getItem("serverAddress")||""
18-
);
17+
const{
18+
serverAddress,
19+
setServerAddress,
20+
isDiscovering,
21+
error:discoveryError,
22+
}=useServerDiscovery();
23+
1924
const[isAuthenticated,setIsAuthenticated]=useState(false);
2025
const[user,setUser]=useState(null);
2126

@@ -109,10 +114,8 @@ const App = () => {
109114
setMode={(mode)=>handleUpdateSettings({ mode})}
110115
currentLanguage={settings.language}
111116
setCurrentLanguage={(language)=>handleUpdateSettings({ language})}
112-
serverAddress={settings.serverAddress}
113-
setServerAddress={(serverAddress)=>
114-
handleUpdateSettings({ serverAddress})
115-
}
117+
serverAddress={serverAddress}
118+
setServerAddress={setServerAddress}
116119
ollamaApiAddress={settings.ollamaApiAddress}
117120
setOllamaApiAddress={(ollamaApiAddress)=>
118121
handleUpdateSettings({ ollamaApiAddress})
@@ -138,15 +141,17 @@ const App = () => {
138141
/>
139142
{!isAuthenticated ?(
140143
<Auth
141-
serverAddress={settings.serverAddress}
144+
serverAddress={serverAddress}
142145
currentLanguage={settings.language}
143146
onLogin={handleLogin}
147+
isDiscovering={isDiscovering}
148+
discoveryError={discoveryError}
144149
/>
145150
) :(
146151
<ExploitsTable
147152
socket={socket}
148153
currentLanguage={settings.language}
149-
serverAddress={settings.serverAddress}
154+
serverAddress={serverAddress}
150155
vulnCheckToken={settings.vulnCheckToken}
151156
nvdApiKey={settings.nvdApiKey}
152157
proxyEnabled={settings.proxyEnabled}

‎client/src/components/Auth/Auth.jsx‎

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const messages = {
3030
registrationSuccess:"Registration successful! Please login.",
3131
serverRequired:
3232
"Server address is not specified. Please set it in the settings using the gear icon above.",
33+
serverDiscovering:"Server discovery in progress...",
3334
},
3435
RU:{
3536
welcome:"Добро пожаловать",
@@ -46,10 +47,17 @@ const messages = {
4647
registrationSuccess:"Регистрация успешна! Пожалуйста, войдите.",
4748
serverRequired:
4849
"Адрес сервера не указан. Пожалуйста, укажите его в настройках, нажав на иконку шестерёнки сверху.",
50+
serverDiscovering:"Обнаружение сервера в процессе...",
4951
},
5052
};
5153

52-
constAuth=({ serverAddress, currentLanguage, onLogin})=>{
54+
constAuth=({
55+
serverAddress,
56+
onLogin,
57+
currentLanguage,
58+
isDiscovering,
59+
discoveryError,
60+
})=>{
5361
consttheme=useTheme();
5462
const[isLogin,setIsLogin]=useState(true);
5563
const[formData,setFormData]=useState({
@@ -65,8 +73,12 @@ const Auth = ({ serverAddress, currentLanguage, onLogin }) => {
6573

6674
consthandleSubmit=async(e)=>{
6775
e.preventDefault();
76+
if(isDiscovering){
77+
setError(msg.serverDiscovering);
78+
return;
79+
}
6880
if(!serverAddress?.trim()){
69-
setError(msg.serverRequired);
81+
setError(discoveryError||msg.serverRequired);
7082
return;
7183
}
7284

@@ -130,19 +142,23 @@ const Auth = ({ serverAddress, currentLanguage, onLogin }) => {
130142
{isLogin ?msg.welcome :msg.createAccount}
131143
</Typography>
132144

133-
{(!serverAddress?.trim()||error)&&(
145+
{(!serverAddress?.trim()||error||isDiscovering)&&(
134146
<Alert
135147
severity={
136-
!serverAddress?.trim()
148+
isDiscovering
149+
?"info"
150+
:!serverAddress?.trim()
137151
?"warning"
138152
:error.startsWith("success:")
139153
?"success"
140154
:"error"
141155
}
142156
sx={{mb:2}}
143157
>
144-
{!serverAddress?.trim()
145-
?msg.serverRequired
158+
{isDiscovering
159+
?msg.serverDiscovering
160+
:!serverAddress?.trim()
161+
?discoveryError||msg.serverRequired
146162
:error.startsWith("success:")
147163
?error.substring(8)
148164
:error}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import{useState,useEffect}from"react";
2+
importaxiosfrom"axios";
3+
4+
exportfunctionuseServerDiscovery(){
5+
const[serverAddress,setServerAddress]=useState(
6+
localStorage.getItem("serverAddress")||""
7+
);
8+
const[isDiscovering,setIsDiscovering]=useState(false);
9+
const[error,setError]=useState(null);
10+
11+
constdiscoverServer=async()=>{
12+
setIsDiscovering(true);
13+
setError(null);
14+
15+
constcurrentHost=window.location.hostname;
16+
constport=5000;
17+
constaddress=`http://${currentHost}:${port}`;
18+
19+
try{
20+
constresponse=awaitaxios.get(`${address}/discovery`,{
21+
timeout:2000,
22+
headers:{
23+
Accept:"application/json",
24+
"Content-Type":"application/json",
25+
},
26+
});
27+
28+
if(response.data.service==="exploit-seek"){
29+
setServerAddress(address);
30+
localStorage.setItem("serverAddress",address);
31+
setIsDiscovering(false);
32+
setError(null);
33+
returntrue;
34+
}
35+
}catch(err){
36+
setError("Could not discover server automatically");
37+
setIsDiscovering(false);
38+
returnfalse;
39+
}
40+
};
41+
42+
useEffect(()=>{
43+
if(!serverAddress){
44+
discoverServer();
45+
}
46+
},[]);
47+
48+
return{
49+
serverAddress,
50+
setServerAddress,
51+
isDiscovering,
52+
error,
53+
discoverServer,
54+
};
55+
}

‎client/src/hooks/useSocket.jsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import{useEffect,useState}from"react";
22
import{io}from"socket.io-client";
33

4-
exportdefaultfunctionuseSocket(serverAddress){
4+
exportfunctionuseSocket(serverAddress){
55
const[socket,setSocket]=useState(null);
66

77
useEffect(()=>{

‎server/server.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
fromconstantsimportDATA_ROOT
1010
fromlogger_configimportget_logger
1111
importos
12+
importsocket
1213

1314
# Patch gevent before all other imports
1415
monkey.patch_all()
@@ -167,6 +168,23 @@ def verify_connection():
167168
)
168169
returnresponse,200
169170

171+
@app.route("/discovery")
172+
defdiscover():
173+
"""Service discovery endpoint"""
174+
logger=get_logger()
175+
logger.info("Processing discovery request")
176+
hostname=socket.gethostname()
177+
logger.debug(f"Hostname:{hostname}")
178+
response_data= {
179+
"status":"success",
180+
"service":"exploit-seek",
181+
"version":"1.0",
182+
"hostname":hostname,
183+
"port":5000,
184+
}
185+
logger.debug(f"Discovery response:{response_data}")
186+
returnjsonify(response_data),200
187+
170188
# Create all database tables
171189
withapp.app_context():
172190
logger.info("Creating database tables")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp