Files
yggman/static/edit.html

481 lines
16 KiB
HTML
Raw Normal View History

2025-08-26 13:08:43 +03:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Edit Node - Yggdrasil Manager</title>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
line-height: 1.6;
color: #333;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 800px;
margin: 0 auto;
background: rgba(255, 255, 255, 0.95);
border-radius: 15px;
padding: 30px;
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
backdrop-filter: blur(10px);
}
h1 {
color: #667eea;
text-align: center;
margin-bottom: 30px;
font-size: 2.5rem;
font-weight: 700;
}
.form-section {
background: #f8f9ff;
padding: 20px;
border-radius: 10px;
margin-bottom: 20px;
border: 1px solid #e1e8ff;
}
.form-section h3 {
color: #495057;
margin-bottom: 15px;
font-size: 1.2rem;
font-weight: 600;
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: 600;
color: #495057;
}
input[type="text"], input[type="number"], select {
width: 100%;
padding: 12px;
border: 2px solid #d1dfff;
border-radius: 8px;
font-size: 14px;
transition: border-color 0.3s ease;
}
input:focus, select:focus {
outline: none;
border-color: #667eea;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
.listen-entry {
display: grid;
grid-template-columns: 120px 1fr 100px auto;
gap: 10px;
align-items: center;
margin-bottom: 10px;
padding: 10px;
background: white;
border-radius: 8px;
border: 1px solid #e1e8ff;
}
.address-list {
margin-top: 10px;
}
.address-item {
background: white;
padding: 10px;
border-radius: 8px;
border: 1px solid #e1e8ff;
margin-bottom: 8px;
display: flex;
justify-content: space-between;
align-items: center;
}
.address-badge {
font-family: monospace;
color: #667eea;
font-weight: 500;
}
button {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
padding: 12px 24px;
border-radius: 25px;
cursor: pointer;
font-size: 16px;
font-weight: 600;
transition: all 0.3s ease;
text-transform: uppercase;
letter-spacing: 0.5px;
}
button:hover {
transform: translateY(-2px);
box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
}
button.secondary {
background: #6c757d;
}
button.secondary:hover {
background: #5a6268;
}
button.danger {
background: #dc3545;
}
button.danger:hover {
background: #c82333;
box-shadow: 0 10px 20px rgba(220, 53, 69, 0.3);
}
button.small {
padding: 6px 12px;
font-size: 12px;
min-width: auto;
}
.button-group {
display: flex;
gap: 15px;
justify-content: center;
margin-top: 30px;
}
.status {
position: fixed;
top: 20px;
right: 20px;
padding: 15px 20px;
border-radius: 8px;
font-weight: 600;
z-index: 1000;
transform: translateX(400px);
transition: transform 0.3s ease;
}
.status.show {
transform: translateX(0);
}
.status.success {
background: #d4edda;
color: #155724;
border: 1px solid #c3e6cb;
}
.status.error {
background: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
.back-link {
display: inline-flex;
align-items: center;
color: #667eea;
text-decoration: none;
font-weight: 600;
margin-bottom: 20px;
transition: color 0.3s ease;
}
.back-link:hover {
color: #5a6fd8;
}
.back-link::before {
content: '←';
margin-right: 8px;
font-size: 1.2em;
}
</style>
</head>
<body>
<div class="container">
<a href="/" class="back-link">Back to Dashboard</a>
<h1>Edit Node</h1>
<div class="form-section">
<h3>Node Information</h3>
<div class="form-group">
<label for="node-name">Node Name</label>
<input type="text" id="node-name" required>
</div>
</div>
<div class="form-section">
<h3>Listen Endpoints</h3>
<div id="listen-entries"></div>
<button class="small secondary" onclick="addListenEntry()">Add Listen Endpoint</button>
</div>
<div class="form-section">
<h3>Node Addresses</h3>
<p style="margin-bottom: 10px; color: #6c757d; font-size: 14px;">
These addresses are automatically discovered by the agent running on this node.
</p>
<div id="addresses-list"></div>
</div>
<div class="button-group">
<button onclick="updateNode()">Update Node</button>
<button class="danger" onclick="deleteNode()">Delete Node</button>
<button class="secondary" onclick="window.location.href='/'">Cancel</button>
</div>
</div>
<div id="status" class="status"></div>
<script>
const nodeId = '{{NODE_ID}}';
let nodeData = null;
let listenEntryCount = 0;
// Load node data on page load
document.addEventListener('DOMContentLoaded', async () => {
await loadNodeData();
});
async function loadNodeData() {
try {
const response = await fetch(`/api/nodes/${nodeId}`);
if (!response.ok) {
throw new Error(`Failed to load node: ${response.status}`);
}
nodeData = await response.json();
populateForm();
} catch (error) {
showStatus('Failed to load node data: ' + error.message, 'error');
}
}
function populateForm() {
if (!nodeData) return;
// Set node name
document.getElementById('node-name').value = nodeData.name;
// Clear and populate listen entries
const container = document.getElementById('listen-entries');
container.innerHTML = '';
listenEntryCount = 0;
nodeData.listen.forEach(listenAddr => {
addListenEntry();
const entries = document.querySelectorAll('.listen-entry');
const entry = entries[entries.length - 1];
if (entry) {
populateListenEntry(entry, listenAddr);
}
});
// Populate addresses
const addressesList = document.getElementById('addresses-list');
addressesList.innerHTML = '';
if (nodeData.addresses && nodeData.addresses.length > 0) {
nodeData.addresses.forEach(address => {
const addressItem = document.createElement('div');
addressItem.className = 'address-item';
addressItem.innerHTML = `
<span class="address-badge">${address}</span>
`;
addressesList.appendChild(addressItem);
});
} else {
addressesList.innerHTML = '<div class="address-item"><span style="color: #6c757d; font-style: italic;">No addresses discovered yet</span></div>';
}
}
function addListenEntry() {
const container = document.getElementById('listen-entries');
const index = listenEntryCount++;
const entry = document.createElement('div');
entry.className = 'listen-entry';
entry.dataset.index = index;
entry.innerHTML = `
<select class="protocol-select">
<option value="tcp">TCP</option>
<option value="tls">TCP+TLS</option>
<option value="quic">QUIC+TLS</option>
<option value="unix">UNIX Socket</option>
<option value="ws">WebSocket</option>
<option value="wss">WebSocket+TLS</option>
</select>
<input type="text" class="bind-address" placeholder="Bind address" value="[::]" />
<input type="number" class="port" placeholder="Port" value="9001" min="1" max="65535" />
<button class="small danger" onclick="removeListenEntry(${index})">Remove</button>
`;
container.appendChild(entry);
}
function removeListenEntry(index) {
const entry = document.querySelector(`.listen-entry[data-index="${index}"]`);
if (entry) {
entry.remove();
}
}
function populateListenEntry(entry, listenAddr) {
const [protocol, rest] = listenAddr.split('://');
const protocolSelect = entry.querySelector('.protocol-select');
protocolSelect.value = protocol;
let address, port, params = '';
if (protocol === 'unix') {
address = rest;
port = '';
} else {
const paramIndex = rest.indexOf('?');
if (paramIndex !== -1) {
params = rest.substring(paramIndex + 1);
const addressPort = rest.substring(0, paramIndex);
[address, port] = parseAddressPort(addressPort);
} else {
[address, port] = parseAddressPort(rest);
}
}
entry.querySelector('.bind-address').value = address || '[::]';
if (port) {
entry.querySelector('.port').value = port;
}
}
function parseAddressPort(addressPort) {
const lastColonIndex = addressPort.lastIndexOf(':');
if (lastColonIndex === -1) return [addressPort, ''];
const potentialPort = addressPort.substring(lastColonIndex + 1);
if (/^\d+$/.test(potentialPort)) {
return [addressPort.substring(0, lastColonIndex), potentialPort];
} else {
return [addressPort, ''];
}
}
function collectListenEndpoints() {
const entries = document.querySelectorAll('.listen-entry');
const endpoints = [];
entries.forEach(entry => {
const protocol = entry.querySelector('.protocol-select').value;
const address = entry.querySelector('.bind-address').value.trim();
const port = entry.querySelector('.port').value.trim();
if (protocol && address) {
if (protocol === 'unix') {
endpoints.push(`${protocol}://${address}`);
} else if (port) {
endpoints.push(`${protocol}://${address}:${port}`);
}
}
});
return endpoints;
}
async function updateNode() {
const name = document.getElementById('node-name').value.trim();
if (!name) {
showStatus('Please enter a node name', 'error');
return;
}
const listen = collectListenEndpoints();
if (listen.length === 0) {
showStatus('Please configure at least one listen endpoint', 'error');
return;
}
try {
const response = await fetch(`/api/nodes/${nodeId}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: name,
listen: listen,
addresses: nodeData.addresses || []
})
});
if (response.ok) {
showStatus('Node updated successfully!', 'success');
// Reload node data to show updated values
setTimeout(() => loadNodeData(), 1000);
} else {
const error = await response.text();
showStatus('Failed to update node: ' + error, 'error');
}
} catch (error) {
showStatus('Network error: ' + error.message, 'error');
}
}
async function deleteNode() {
if (!nodeData) return;
if (!confirm(`Are you sure you want to delete node "${nodeData.name}"? This action cannot be undone.`)) {
return;
}
try {
const response = await fetch(`/api/nodes/${nodeId}`, {
method: 'DELETE'
});
if (response.ok) {
showStatus('Node deleted successfully!', 'success');
// Redirect to main page after successful deletion
setTimeout(() => window.location.href = '/', 1500);
} else {
const error = await response.text();
showStatus('Failed to delete node: ' + error, 'error');
}
} catch (error) {
showStatus('Network error: ' + error.message, 'error');
}
}
function showStatus(message, type) {
const status = document.getElementById('status');
status.textContent = message;
status.className = `status ${type} show`;
setTimeout(() => {
status.classList.remove('show');
}, 4000);
}
</script>
</body>
</html>