-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'config2_ui2' into develop
- Loading branch information
Showing
48 changed files
with
3,634 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
src/rust/lqosd/src/node_manager/js_build/src/config/config_helper.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
export function loadConfig(onComplete) { | ||
$.get("/local-api/getConfig", (data) => { | ||
window.config = data; | ||
onComplete(); | ||
}); | ||
} | ||
|
||
export function saveConfig(onComplete) { | ||
$.ajax({ | ||
type: "POST", | ||
url: "/local-api/updateConfig", | ||
data: JSON.stringify(window.config), | ||
contentType: 'application/json', | ||
success: () => { | ||
onComplete(); | ||
}, | ||
error: () => { | ||
alert("That didn't work"); | ||
} | ||
}); | ||
} | ||
|
||
export function saveNetworkAndDevices(network_json, shaped_devices, onComplete) { | ||
// Validate network_json structure | ||
if (!network_json || typeof network_json !== 'object') { | ||
alert("Invalid network configuration"); | ||
return; | ||
} | ||
|
||
// Validate shaped_devices structure | ||
if (!Array.isArray(shaped_devices)) { | ||
alert("Invalid shaped devices configuration"); | ||
return; | ||
} | ||
|
||
// Validate individual shaped devices | ||
const validationErrors = []; | ||
const validNodes = validNodeList(network_json); | ||
console.log(validNodes); | ||
|
||
shaped_devices.forEach((device, index) => { | ||
// Required fields | ||
if (!device.circuit_id || device.circuit_id.trim() === "") { | ||
validationErrors.push(`Device ${index + 1}: Circuit ID is required`); | ||
} | ||
if (!device.device_id || device.device_id.trim() === "") { | ||
validationErrors.push(`Device ${index + 1}: Device ID is required`); | ||
} | ||
|
||
// Parent node validation | ||
if (device.parent_node && validNodes.length > 0 && !validNodes.includes(device.parent_node)) { | ||
validationErrors.push(`Device ${index + 1}: Parent node '${device.parent_node}' does not exist`); | ||
} | ||
|
||
// Bandwidth validation | ||
if (device.download_min_mbps < 1 || device.upload_min_mbps < 1 || | ||
device.download_max_mbps < 1 || device.upload_max_mbps < 1) { | ||
validationErrors.push(`Device ${index + 1}: Bandwidth values must be greater than 0`); | ||
} | ||
}); | ||
|
||
if (validationErrors.length > 0) { | ||
alert("Validation errors:\n" + validationErrors.join("\n")); | ||
return; | ||
} | ||
|
||
// Prepare data for submission | ||
const submission = { | ||
network_json, | ||
shaped_devices | ||
}; | ||
console.log(submission); | ||
|
||
// Send to server with enhanced error handling | ||
/*$.ajax({ | ||
type: "POST", | ||
url: "/local-api/updateNetworkAndDevices", | ||
contentType: 'application/json', | ||
data: JSON.stringify(submission), | ||
dataType: 'json', // Expect JSON response | ||
success: (response) => { | ||
try { | ||
if (response && response.success) { | ||
if (onComplete) onComplete(true, "Saved successfully"); | ||
} else { | ||
const msg = response?.message || "Unknown error occurred"; | ||
if (onComplete) onComplete(false, msg); | ||
alert("Failed to save: " + msg); | ||
} | ||
} catch (e) { | ||
console.error("Error parsing response:", e); | ||
if (onComplete) onComplete(false, "Invalid server response"); | ||
alert("Invalid server response format"); | ||
} | ||
}, | ||
error: (xhr) => { | ||
let errorMsg = "Request failed"; | ||
try { | ||
if (xhr.responseText) { | ||
const json = JSON.parse(xhr.responseText); | ||
errorMsg = json.message || xhr.responseText; | ||
} else if (xhr.statusText) { | ||
errorMsg = xhr.statusText; | ||
} | ||
console.error("AJAX Error:", { | ||
status: xhr.status, | ||
statusText: xhr.statusText, | ||
response: xhr.responseText | ||
}); | ||
} catch (e) { | ||
console.error("Error parsing error response:", e); | ||
errorMsg = "Unknown error occurred"; | ||
} | ||
if (onComplete) onComplete(false, errorMsg); | ||
alert("Error saving configuration: " + errorMsg); | ||
} | ||
});*/ | ||
} | ||
|
||
export function validNodeList(network_json) { | ||
let nodes = []; | ||
|
||
function iterate(data, level) { | ||
for (const [key, value] of Object.entries(data)) { | ||
nodes.push(key); | ||
if (value.children != null) | ||
iterate(value.children, level+1); | ||
} | ||
} | ||
|
||
iterate(network_json, 0); | ||
|
||
return nodes; | ||
} |
42 changes: 42 additions & 0 deletions
42
src/rust/lqosd/src/node_manager/js_build/src/config_anon.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import {saveConfig, loadConfig} from "./config/config_helper"; | ||
|
||
function validateConfig() { | ||
// Validate server address format if provided | ||
const server = document.getElementById("anonymousServer").value.trim(); | ||
if (server) { | ||
const parts = server.split(':'); | ||
if (parts.length !== 2 || isNaN(parseInt(parts[1]))) { | ||
alert("Statistics Server must be in format HOST:PORT"); | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
function updateConfig() { | ||
// Update only the usage stats section | ||
window.config.usage_stats.send_anonymous = document.getElementById("sendAnonymous").checked; | ||
window.config.usage_stats.anonymous_server = document.getElementById("anonymousServer").value.trim(); | ||
} | ||
|
||
loadConfig(() => { | ||
// window.config now contains the configuration. | ||
// Populate form fields with config values | ||
if (window.config && window.config.usage_stats) { | ||
// Required fields | ||
document.getElementById("sendAnonymous").checked = window.config.usage_stats.send_anonymous ?? true; | ||
document.getElementById("anonymousServer").value = window.config.usage_stats.anonymous_server ?? "stats.libreqos.io:9125"; | ||
|
||
// Add save button click handler | ||
document.getElementById('saveButton').addEventListener('click', () => { | ||
if (validateConfig()) { | ||
updateConfig(); | ||
saveConfig(() => { | ||
alert("Configuration saved successfully!"); | ||
}); | ||
} | ||
}); | ||
} else { | ||
console.error("Usage statistics configuration not found in window.config"); | ||
} | ||
}); |
Oops, something went wrong.