mirror of
https://github.com/house-of-vanity/yggman.git
synced 2025-10-23 12:49:09 +00:00
Added agent
This commit is contained in:
481
static/edit.html
Normal file
481
static/edit.html
Normal file
@@ -0,0 +1,481 @@
|
||||
<!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>
|
@@ -125,11 +125,17 @@
|
||||
background: #6c757d;
|
||||
}
|
||||
|
||||
button.small {
|
||||
button.small, a.button.small {
|
||||
padding: 6px 12px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
a.button {
|
||||
display: inline-block;
|
||||
text-decoration: none;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
button.danger {
|
||||
background: #dc3545;
|
||||
}
|
||||
@@ -362,6 +368,19 @@
|
||||
|
||||
<div id="status-message"></div>
|
||||
|
||||
<div class="controls">
|
||||
<h2>Listen Template Settings</h2>
|
||||
<p style="margin-bottom: 15px; color: #6c757d; font-size: 14px;">
|
||||
Configure the default listen endpoints that will be applied to new nodes.
|
||||
</p>
|
||||
<div id="template-entries"></div>
|
||||
<button class="small secondary" onclick="addTemplateEntry()">Add Template Entry</button>
|
||||
<div style="margin-top: 15px;">
|
||||
<button onclick="saveListenTemplate()">Save Template</button>
|
||||
<button class="secondary" onclick="loadListenTemplate()">Reset to Current</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="controls">
|
||||
<h2 id="form-title">Add New Node</h2>
|
||||
<div class="form-section">
|
||||
@@ -584,7 +603,7 @@
|
||||
<div class="node-id">${nodeConfig.node_id}</div>
|
||||
</div>
|
||||
<div class="node-actions">
|
||||
<button class="small" onclick="editNode('${nodeConfig.node_id}')">Edit</button>
|
||||
<a href="/edit/${nodeConfig.node_id}" class="button small">Edit</a>
|
||||
<button class="small danger" onclick="deleteNode('${nodeConfig.node_id}', '${nodeConfig.node_name}')">Delete</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -676,85 +695,147 @@
|
||||
});
|
||||
|
||||
// Edit node function
|
||||
async function editNode(nodeId) {
|
||||
// Listen template management
|
||||
let templateEntryCount = 0;
|
||||
|
||||
async function loadListenTemplate() {
|
||||
try {
|
||||
// Get node data first
|
||||
const response = await fetch(`/api/nodes/${nodeId}`);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to get node: ${response.status}`);
|
||||
}
|
||||
const nodeData = await response.json();
|
||||
const response = await fetch('/api/settings/listen-template');
|
||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||||
|
||||
// Populate form with existing data
|
||||
document.getElementById('node-name').value = nodeData.name;
|
||||
|
||||
// Clear existing listen entries
|
||||
const container = document.getElementById('listen-entries');
|
||||
container.innerHTML = '';
|
||||
|
||||
// Add listen entries from existing data
|
||||
nodeData.listen.forEach((listenAddr, index) => {
|
||||
addListenEntry();
|
||||
const entries = document.querySelectorAll('.listen-entry');
|
||||
const entry = entries[entries.length - 1]; // Get the last added entry
|
||||
if (entry) {
|
||||
populateListenEntry(entry, listenAddr);
|
||||
}
|
||||
});
|
||||
|
||||
// Change form title and button
|
||||
document.getElementById('form-title').textContent = 'Edit Node';
|
||||
const submitBtn = document.querySelector('button[onclick="addNode()"]');
|
||||
submitBtn.textContent = 'Update Node';
|
||||
submitBtn.onclick = () => updateNode(nodeId);
|
||||
|
||||
// Scroll to form
|
||||
document.querySelector('.controls').scrollIntoView({ behavior: 'smooth' });
|
||||
const data = await response.json();
|
||||
populateTemplateEntries(data.template);
|
||||
|
||||
} catch (error) {
|
||||
showStatus('Failed to load node for editing: ' + error.message, 'error');
|
||||
showStatus('Failed to load listen template: ' + error.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// Update node function
|
||||
async function updateNode(nodeId) {
|
||||
const name = document.getElementById('node-name').value.trim();
|
||||
function populateTemplateEntries(template) {
|
||||
const container = document.getElementById('template-entries');
|
||||
container.innerHTML = '';
|
||||
templateEntryCount = 0;
|
||||
|
||||
if (!name) {
|
||||
showStatus('Please enter a node name', 'error');
|
||||
return;
|
||||
if (template && template.length > 0) {
|
||||
template.forEach(listenAddr => {
|
||||
addTemplateEntry();
|
||||
const entries = document.querySelectorAll('.template-entry');
|
||||
const entry = entries[entries.length - 1];
|
||||
if (entry) {
|
||||
populateTemplateEntry(entry, listenAddr);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// Add default entry if no template exists
|
||||
addTemplateEntry();
|
||||
}
|
||||
}
|
||||
|
||||
function addTemplateEntry() {
|
||||
const container = document.getElementById('template-entries');
|
||||
const index = templateEntryCount++;
|
||||
|
||||
const entry = document.createElement('div');
|
||||
entry.className = 'template-entry 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="0.0.0.0" />
|
||||
<input type="number" class="port" placeholder="Port" value="9001" min="1" max="65535" />
|
||||
<button class="small danger" onclick="removeTemplateEntry(${index})">Remove</button>
|
||||
`;
|
||||
|
||||
container.appendChild(entry);
|
||||
}
|
||||
|
||||
function removeTemplateEntry(index) {
|
||||
const entry = document.querySelector(`.template-entry[data-index="${index}"]`);
|
||||
if (entry) {
|
||||
entry.remove();
|
||||
}
|
||||
}
|
||||
|
||||
function populateTemplateEntry(entry, listenAddr) {
|
||||
const [protocol, rest] = listenAddr.split('://');
|
||||
const protocolSelect = entry.querySelector('.protocol-select');
|
||||
protocolSelect.value = protocol;
|
||||
|
||||
let address, port;
|
||||
if (protocol === 'unix') {
|
||||
address = rest;
|
||||
port = '';
|
||||
} else {
|
||||
[address, port] = parseAddressPort(rest);
|
||||
}
|
||||
|
||||
// Extract addresses from listen endpoints
|
||||
const addresses = [];
|
||||
entry.querySelector('.bind-address').value = address || '0.0.0.0';
|
||||
if (port) {
|
||||
entry.querySelector('.port').value = port;
|
||||
}
|
||||
}
|
||||
|
||||
function parseAddressPort(addressPort) {
|
||||
const lastColonIndex = addressPort.lastIndexOf(':');
|
||||
if (lastColonIndex === -1) return [addressPort, ''];
|
||||
|
||||
const listen = collectListenEndpoints();
|
||||
const potentialPort = addressPort.substring(lastColonIndex + 1);
|
||||
if (/^\d+$/.test(potentialPort)) {
|
||||
return [addressPort.substring(0, lastColonIndex), potentialPort];
|
||||
} else {
|
||||
return [addressPort, ''];
|
||||
}
|
||||
}
|
||||
|
||||
function collectTemplateEndpoints() {
|
||||
const entries = document.querySelectorAll('.template-entry');
|
||||
const endpoints = [];
|
||||
|
||||
if (listen.length === 0) {
|
||||
showStatus('Please configure at least one listen endpoint', 'error');
|
||||
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 saveListenTemplate() {
|
||||
const template = collectTemplateEndpoints();
|
||||
|
||||
if (template.length === 0) {
|
||||
showStatus('Please configure at least one template entry', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/nodes/${nodeId}`, {
|
||||
const response = await fetch('/api/settings/listen-template', {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
name: name,
|
||||
listen: listen,
|
||||
addresses: addresses
|
||||
})
|
||||
body: JSON.stringify({ template })
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
showStatus('Node updated successfully!', 'success');
|
||||
resetForm();
|
||||
loadConfigurations();
|
||||
showStatus('Listen template saved successfully!', 'success');
|
||||
} else {
|
||||
const error = await response.text();
|
||||
showStatus('Failed to update node: ' + error, 'error');
|
||||
showStatus('Failed to save template: ' + error, 'error');
|
||||
}
|
||||
} catch (error) {
|
||||
showStatus('Network error: ' + error.message, 'error');
|
||||
@@ -907,6 +988,12 @@
|
||||
updateProtocolOptions(document.querySelector('.listen-entry'));
|
||||
listenEntryIndex = 1; // Reset the global index
|
||||
}
|
||||
|
||||
// Initialize page
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
await loadListenTemplate();
|
||||
await loadConfigurations();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user