File size: 15,545 Bytes
2f3c093 | 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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Trojan Dashboard</title>
<style>
body { font-family: sans-serif; margin: 20px; }
button { margin: 5px; padding: 8px 12px; cursor: pointer; }
textarea { width: 100%; height: 100px; margin: 5px 0; }
pre { border: 1px solid #ccc; padding: 10px; overflow-x: auto; }
.error { color: red; }
.success { color: green; }
table { border-collapse: collapse; width: 100%; }
th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
th { background-color: #f2f2f2; }
.loading { opacity: 0.6; pointer-events: none; }
.form-group { margin-bottom: 10px; }
.form-group label { display: block; margin-bottom: 5px; }
button.loading::after {
content: "";
position: absolute;
width: 16px;
height: 16px;
top: 50%;
left: 50%;
margin: -8px 0 0 -8px;
border: 2px solid #f3f3f3;
border-top: 2px solid #3498db;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.deployment-feedback {
margin-top: 10px;
padding: 10px;
border: 1px solid #ddd;
background-color: #f9f9f9;
}
.deployment-feedback.pending { background-color: #ffffcc; }
.deployment-feedback.in-progress { background-color: #ccffff; }
.deployment-feedback.success { background-color: #ccffcc; }
.deployment-feedback.error { background-color: #ffcccc; }
</style>
</head>
<body>
<h1>Trojan Dashboard</h1>
<div class="form-group">
<label for="apiKey">API Key:</label>
<input type="text" id="apiKey" placeholder="Enter API Key" required>
<button onclick="saveApiKey()">Save API Key</button>
</div>
<h2>Create Trojan Server</h2>
<form id="createTrojanServerForm">
<div class="form-group">
<label for="serverIP">Server IP:</label>
<input type="text" id="serverIP" placeholder="Server IP" required>
</div>
<div class="form-group">
<label for="serverPort">Server Port:</label>
<input type="number" id="serverPort" placeholder="Server Port" required>
</div>
<div class="form-group">
<label for="encryptionMethod">Encryption Method:</label>
<input type="text" id="encryptionMethod" placeholder="Encryption Method">
</div>
<div class="form-group">
<label for="serverDeploymentMethod">Deployment Method:</label>
<select id="serverDeploymentMethod">
<option value="ssh">SSH</option>
<option value="powershell">PowerShell</option>
<option value="manual">Manual</option>
</select>
</div>
<button type="submit">Create Server</button>
</form>
<pre id="createServerResult"></pre>
<h2>Create Trojan Client</h2>
<form id="createTrojanClientForm">
<div class="form-group">
<label for="clientConfig">Client Config (JSON):</label>
<textarea id="clientConfig" placeholder="Client Config (JSON)" required></textarea>
</div>
<div class="form-group">
<label for="clientDeploymentMethod">Deployment Method:</label>
<select id="clientDeploymentMethod">
<option value="ssh">SSH</option>
<option value="powershell">PowerShell</option>
<option value="manual">Manual</option>
</select>
</div>
<button type="submit">Create Client</button>
</form>
<pre id="createClientResult"></pre>
<h2>Generate Trojan with AI</h2>
<form id="generateTrojanAIForm">
<div class="form-group">
<label for="aiGoal">AI Goal:</label>
<input type="text" id="aiGoal" placeholder="AI Goal" required>
</div>
<div class="form-group">
<label for="aiConstraints">AI Constraints (JSON):</label>
<textarea id="aiConstraints" placeholder="AI Constraints (JSON)"></textarea>
</div>
<button type="submit">Generate with AI</button>
</form>
<pre id="generateAIResult"></pre>
<h2>List Trojan Servers</h2>
<button onclick="listTrojanServers()">List Servers</button>
<div id="trojanServerListContainer"></div>
<h2>List Trojan Clients</h2>
<button onclick="listTrojanClients()">List Clients</button>
<div id="trojanClientListContainer"></div>
<script>
const API_BASE_URL = '/api/trojan'; // Backend API endpoint
let apiKey = localStorage.getItem('apiKey') || '';
document.getElementById('apiKey').value = apiKey;
function saveApiKey() {
apiKey = document.getElementById('apiKey').value;
localStorage.setItem('apiKey', apiKey);
alert('API Key saved!');
}
async function createTrojanServer(event) {
event.preventDefault();
const serverIP = document.getElementById('serverIP').value;
const serverPort = document.getElementById('serverPort').value;
const encryptionMethod = document.getElementById('encryptionMethod').value;
const deploymentMethod = document.getElementById('serverDeploymentMethod').value;
const createButton = document.querySelector('#createTrojanServerForm button');
if (!serverIP || !serverPort) {
document.getElementById('createServerResult').textContent = 'Error: Server IP and Port are required.';
document.getElementById('createServerResult').classList.add('error');
return;
}
createButton.classList.add('loading');
try {
const response = await fetch(`${API_BASE_URL}/servers`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-API-Key': apiKey },
body: JSON.stringify({ server_ip: serverIP, server_port: parseInt(serverPort), encryption_method: encryptionMethod, deployment_method: deploymentMethod })
});
const data = await response.json();
if (response.ok) {
document.getElementById('createServerResult').textContent = 'Trojan server created successfully: ' + JSON.stringify(data, null, 2);
document.getElementById('createServerResult').classList.remove('error');
document.getElementById('createServerResult').classList.add('success');
listTrojanServers(); // Update the list after creating a server
} else {
document.getElementById('createServerResult').textContent = 'Error creating trojan server: ' + JSON.stringify(data, null, 2);
document.getElementById('createServerResult').classList.add('error');
document.getElementById('createServerResult').classList.remove('success');
}
} catch (error) {
console.error('Error:', error);
document.getElementById('createServerResult').textContent = 'Error creating trojan server: ' + error;
document.getElementById('createServerResult').classList.add('error');
document.getElementById('createServerResult').classList.remove('success');
} finally {
createButton.classList.remove('loading');
}
}
async function createTrojanClient(event) {
event.preventDefault();
const clientConfig = document.getElementById('clientConfig').value;
const deploymentMethod = document.getElementById('clientDeploymentMethod').value;
const createButton = document.querySelector('#createTrojanClientForm button');
if (!clientConfig) {
document.getElementById('createClientResult').textContent = 'Error: Client config is required.';
document.getElementById('createClientResult').classList.add('error');
return;
}
createButton.classList.add('loading');
try {
const response = await fetch(`${API_BASE_URL}/clients`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-API-Key': apiKey },
body: JSON.stringify({ config: JSON.parse(clientConfig), deployment_method: deploymentMethod })
});
const data = await response.json();
if (response.ok) {
document.getElementById('createClientResult').textContent = 'Trojan client created successfully: ' + JSON.stringify(data, null, 2);
document.getElementById('createClientResult').classList.remove('error');
document.getElementById('createClientResult').classList.add('success');
listTrojanClients(); // Update the list after creating a client
} else {
document.getElementById('createClientResult').textContent = 'Error creating trojan client: ' + JSON.stringify(data, null, 2);
document.getElementById('createClientResult').classList.add('error');
document.getElementById('createClientResult').classList.remove('success');
}
} catch (error) {
console.error('Error:', error);
document.getElementById('createClientResult').textContent = 'Error creating trojan client: ' + error;
document.getElementById('createClientResult').classList.add('error');
document.getElementById('createClientResult').classList.remove('success');
} finally {
createButton.classList.remove('loading');
}
}
async function generateTrojanAI(event) {
event.preventDefault();
const aiGoal = document.getElementById('aiGoal').value;
const aiConstraints = document.getElementById('aiConstraints').value;
const generateButton = document.querySelector('#generateTrojanAIForm button');
if (!aiGoal) {
document.getElementById('generateAIResult').textContent = 'Error: AI Goal is required.';
document.getElementById('generateAIResult').classList.add('error');
return;
}
generateButton.classList.add('loading');
try {
const response = await fetch(`${API_BASE_URL}/generate`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-API-Key': apiKey },
body: JSON.stringify({ goal: aiGoal, constraints: JSON.parse(aiConstraints || '{}') })
});
const data = await response.json();
document.getElementById('generateAIResult').textContent = 'AI generated trojan config: ' + JSON.stringify(data, null, 2);
document.getElementById('generateAIResult').classList.remove('error');
document.getElementById('generateAIResult').classList.add('success');
} catch (error) {
console.error('Error:', error);
document.getElementById('generateAIResult').textContent = 'Error generating trojan config with AI: ' + error;
document.getElementById('generateAIResult').classList.add('error');
document.getElementById('generateAIResult').classList.remove('success');
} finally {
generateButton.classList.remove('loading');
}
}
async function listTrojanServers() {
const listButton = document.querySelector('#trojanServerListContainer').previousElementSibling;
listButton.classList.add('loading');
try {
const response = await fetch(`${API_BASE_URL}/servers`, {
headers: { 'X-API-Key': apiKey }
});
const data = await response.json();
if (response.ok) {
let tableHTML = '<table><thead><tr><th>ID</th><th>Server IP</th><th>Server Port</th><th>Encryption Method</th><th>Deployment Method</th><th>Actions</th></tr></thead><tbody>';
data.forEach(server => {
tableHTML += `<tr><td>${server.id}</td><td>${server.server_ip}</td><td>${server.server_port}</td><td>${server.encryption_method || ''}</td><td>${server.deployment_method || ''}</td><td><button onclick="deployTrojanServer(${server.id})">Deploy</button><div id="deploymentFeedbackServer${server.id}" class="deployment-feedback"></div></td></tr>`;
});
tableHTML += '</tbody></table>';
document.getElementById('trojanServerListContainer').innerHTML = tableHTML;
document.getElementById('trojanServerListContainer').classList.remove('error');
} else {
document.getElementById('trojanServerListContainer').textContent = 'Error listing trojan servers: ' + JSON.stringify(data, null, 2);
document.getElementById('trojanServerListContainer').classList.add('error');
}
} catch (error) {
console.error('Error:', error);
document.getElementById('trojanServerListContainer').textContent = 'Error listing trojan servers: ' + error;
document.getElementById('trojanServerListContainer').classList.add('error');
} finally {
listButton.classList.remove('loading');
}
}
async function listTrojanClients() {
const listButton = document.querySelector('#trojanClientListContainer').previousElementSibling;
listButton.classList.add('loading');
try {
const response = await fetch(`${API_BASE_URL}/clients`, {
headers: { 'X-API-Key': apiKey }
});
const data = await response.json();
if (response.ok) {
let tableHTML = '<table><thead><tr><th>ID</th><th>Config</th><th>Deployment Method</th><th>Actions</th></tr></thead><tbody>';
data.forEach(client => {
tableHTML += `<tr><td>${client.id}</td><td>${JSON.stringify(client.config)}</td><td>${client.deployment_method || ''}</td><td><button onclick="deployTrojanClient(${client.id})">Deploy</button><div id="deploymentFeedbackClient${client.id}" class="deployment-feedback"></div></td></tr>`;
});
tableHTML += '</tbody></table>';
document.getElementById('trojanClientListContainer').innerHTML = tableHTML;
document. |