-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.html
More file actions
197 lines (186 loc) · 6.94 KB
/
test.html
File metadata and controls
197 lines (186 loc) · 6.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>VPN Management System - Test</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
min-height: 100vh;
}
.container {
max-width: 1200px;
margin: 0 auto;
background: rgba(255, 255, 255, 0.1);
padding: 30px;
border-radius: 15px;
backdrop-filter: blur(10px);
}
h1 {
text-align: center;
margin-bottom: 30px;
font-size: 2.5em;
}
.status-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 20px;
margin-bottom: 30px;
}
.status-card {
background: rgba(255, 255, 255, 0.2);
padding: 20px;
border-radius: 10px;
text-align: center;
}
.status-card h3 {
margin-top: 0;
color: #ffd700;
}
.status-indicator {
width: 20px;
height: 20px;
border-radius: 50%;
display: inline-block;
margin-right: 10px;
}
.status-online { background-color: #4CAF50; }
.status-offline { background-color: #f44336; }
.test-button {
background: #4CAF50;
color: white;
padding: 15px 30px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
margin: 10px;
transition: background 0.3s;
}
.test-button:hover {
background: #45a049;
}
.test-button:disabled {
background: #cccccc;
cursor: not-allowed;
}
.result {
margin-top: 20px;
padding: 15px;
background: rgba(0, 0, 0, 0.3);
border-radius: 5px;
white-space: pre-wrap;
}
.success { border-left: 4px solid #4CAF50; }
.error { border-left: 4px solid #f44336; }
</style>
</head>
<body>
<div class="container">
<h1>🚀 VPN Management System</h1>
<div class="status-grid">
<div class="status-card">
<h3>API Status</h3>
<span class="status-indicator status-offline" id="api-status"></span>
<span id="api-text">Checking...</span>
</div>
<div class="status-card">
<h3>WireGuard</h3>
<span class="status-indicator status-offline" id="wg-status"></span>
<span id="wg-text">Checking...</span>
</div>
<div class="status-card">
<h3>Database</h3>
<span class="status-indicator status-offline" id="db-status"></span>
<span id="db-text">Checking...</span>
</div>
</div>
<div style="text-align: center;">
<button class="test-button" onclick="testAPI()">Test API Connection</button>
<button class="test-button" onclick="testHealth()">Test Health Endpoint</button>
<button class="test-button" onclick="testClients()">Test Clients Endpoint</button>
<button class="test-button" onclick="testLogin()">Test Login</button>
</div>
<div id="result" class="result" style="display: none;"></div>
</div>
<script>
const API_BASE = 'http://localhost:8080';
function showResult(message, isError = false) {
const result = document.getElementById('result');
result.textContent = message;
result.className = `result ${isError ? 'error' : 'success'}`;
result.style.display = 'block';
}
function updateStatus(elementId, isOnline, text) {
const indicator = document.getElementById(elementId);
const textElement = document.getElementById(elementId.replace('-status', '-text'));
indicator.className = `status-indicator ${isOnline ? 'status-online' : 'status-offline'}`;
textElement.textContent = text;
}
async function testAPI() {
try {
showResult('Testing API connection...');
const response = await fetch(`${API_BASE}/health`);
if (response.ok) {
const data = await response.json();
updateStatus('api-status', true, 'Online');
showResult(`✅ API is working!\nResponse: ${JSON.stringify(data, null, 2)}`);
} else {
throw new Error(`HTTP ${response.status}`);
}
} catch (error) {
updateStatus('api-status', false, 'Offline');
showResult(`❌ API connection failed: ${error.message}`, true);
}
}
async function testHealth() {
try {
showResult('Testing health endpoint...');
const response = await fetch(`${API_BASE}/health`);
const data = await response.json();
showResult(`✅ Health check successful!\nStatus: ${data.status}\nMessage: ${data.message}`);
} catch (error) {
showResult(`❌ Health check failed: ${error.message}`, true);
}
}
async function testClients() {
try {
showResult('Testing clients endpoint...');
const response = await fetch(`${API_BASE}/api/clients`);
const data = await response.json();
showResult(`✅ Clients endpoint working!\nFound ${data.length} clients:\n${JSON.stringify(data, null, 2)}`);
} catch (error) {
showResult(`❌ Clients endpoint failed: ${error.message}`, true);
}
}
async function testLogin() {
try {
showResult('Testing login endpoint...');
const response = await fetch(`${API_BASE}/api/auth/login`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
username: 'admin',
password: 'admin123'
})
});
const data = await response.json();
showResult(`✅ Login test successful!\nToken: ${data.access_token}\nUser: ${data.user.username}`);
} catch (error) {
showResult(`❌ Login test failed: ${error.message}`, true);
}
}
// Auto-test on page load
window.onload = function() {
testAPI();
};
</script>
</body>
</html>