docs + fixes to CustomProps

This commit is contained in:
jokob-sk
2025-01-02 10:15:58 +11:00
parent 2799d3598b
commit 729c24029f
10 changed files with 113 additions and 58 deletions

View File

@@ -358,51 +358,51 @@
showSpinner();
// Update data to server using POST
$.post('php/server/devices.php?action=setDeviceData', {
mac: $('#NEWDEV_devMac').val(),
name: encodeURIComponent($('#NEWDEV_devName').val().replace(/'/g, "")),
owner: encodeURIComponent($('#NEWDEV_devOwner').val().replace(/'/g, "")),
type: $('#NEWDEV_devType').val().replace(/'/g, ""),
vendor: encodeURIComponent($('#NEWDEV_devVendor').val().replace(/'/g, "")),
icon: encodeURIComponent($('#NEWDEV_devIcon').val()),
favorite: ($('#NEWDEV_devFavorite')[0].checked * 1),
group: encodeURIComponent($('#NEWDEV_devGroup').val().replace(/'/g, "")),
location: encodeURIComponent($('#NEWDEV_devLocation').val().replace(/'/g, "")),
comments: encodeURIComponent(encodeSpecialChars($('#NEWDEV_devComments').val())),
networknode: $('#NEWDEV_devParentMAC').val(),
networknodeport: $('#NEWDEV_devParentPort').val(),
ssid: $('#NEWDEV_devSSID').val(),
networksite: $('#NEWDEV_devSite').val(),
staticIP: ($('#NEWDEV_devStaticIP')[0].checked * 1),
scancycle: "1",
alertevents: ($('#NEWDEV_devAlertEvents')[0].checked * 1),
alertdown: ($('#NEWDEV_devAlertDown')[0].checked * 1),
skiprepeated: $('#NEWDEV_devSkipRepeated').val().split(' ')[0],
newdevice: ($('#NEWDEV_devIsNew')[0].checked * 1),
archived: ($('#NEWDEV_devIsArchived')[0].checked * 1),
devFirstConnection: ($('#NEWDEV_devFirstConnection').val()),
devLastConnection: ($('#NEWDEV_devLastConnection').val()),
devCustomProps: btoa(JSON.stringify(collectTableData("#NEWDEV_devCustomProps_table"))),
ip: ($('#NEWDEV_devLastIP').val()),
createNew: createNew
}, function(msg) {
showMessage(msg);
$.post('php/server/devices.php?action=setDeviceData', {
mac: $('#NEWDEV_devMac').val(),
name: encodeURIComponent($('#NEWDEV_devName').val().replace(/'/g, "")),
owner: encodeURIComponent($('#NEWDEV_devOwner').val().replace(/'/g, "")),
type: $('#NEWDEV_devType').val().replace(/'/g, ""),
vendor: encodeURIComponent($('#NEWDEV_devVendor').val().replace(/'/g, "")),
icon: encodeURIComponent($('#NEWDEV_devIcon').val()),
favorite: ($('#NEWDEV_devFavorite')[0].checked * 1),
group: encodeURIComponent($('#NEWDEV_devGroup').val().replace(/'/g, "")),
location: encodeURIComponent($('#NEWDEV_devLocation').val().replace(/'/g, "")),
comments: encodeURIComponent(encodeSpecialChars($('#NEWDEV_devComments').val())),
networknode: $('#NEWDEV_devParentMAC').val(),
networknodeport: $('#NEWDEV_devParentPort').val(),
ssid: $('#NEWDEV_devSSID').val(),
networksite: $('#NEWDEV_devSite').val(),
staticIP: ($('#NEWDEV_devStaticIP')[0].checked * 1),
scancycle: "1",
alertevents: ($('#NEWDEV_devAlertEvents')[0].checked * 1),
alertdown: ($('#NEWDEV_devAlertDown')[0].checked * 1),
skiprepeated: $('#NEWDEV_devSkipRepeated').val().split(' ')[0],
newdevice: ($('#NEWDEV_devIsNew')[0].checked * 1),
archived: ($('#NEWDEV_devIsArchived')[0].checked * 1),
devFirstConnection: ($('#NEWDEV_devFirstConnection').val()),
devLastConnection: ($('#NEWDEV_devLastConnection').val()),
devCustomProps: btoa(JSON.stringify(collectTableData("#NEWDEV_devCustomProps_table"))),
ip: ($('#NEWDEV_devLastIP').val()),
createNew: createNew
}, function(msg) {
showMessage(msg);
// Remove navigation prompt "Are you sure you want to leave..."
window.onbeforeunload = null;
somethingChanged = false;
// Remove navigation prompt "Are you sure you want to leave..."
window.onbeforeunload = null;
somethingChanged = false;
// refresh API
updateApi("devices,appevents");
// refresh API
updateApi("devices,appevents");
// Callback function
if (typeof refreshCallback == 'function') {
refreshCallback(direction);
}
// Callback function
if (typeof refreshCallback == 'function') {
refreshCallback(direction);
}
// Everything loaded
hideSpinner();
});
// Everything loaded
hideSpinner();
});
}

View File

@@ -897,7 +897,7 @@ function getMacsOfShownDevices() {
function renderCustomProps(custProps, mac) {
// Decode and parse the custom properties
// console.log(custProps);
console.log(custProps);
const props = JSON.parse(atob(custProps));
let html = "";

View File

@@ -0,0 +1,55 @@
<?php
// ---- IMPORTS ----
//------------------------------------------------------------------------------
// Check if authenticated
require_once $_SERVER['DOCUMENT_ROOT'] . '/php/templates/security.php';
// Get init.php
require dirname(__FILE__).'/../server/init.php';
// ---- IMPORTS ----
global $fullConfPath;
//------------------------------------------------------------------------------
// Handle incoming requests
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Access the 'config' parameter from the POST request
$base64Data = $_POST['config'] ?? null;
if (!$base64Data) {
$msg = "Missing 'config' parameter.";
echo $msg;
http_response_code(400); // Bad request
die($msg);
}
// Decode incoming base64 data
$input = base64_decode($base64Data, true);
if ($input === false) {
$msg = "Invalid base64 data.";
echo $msg;
http_response_code(400); // Bad request
die($msg);
}
// Backup the original file
if (file_exists($fullConfPath)) {
copy($fullConfPath, $fullConfPath . ".bak");
}
// Write the new configuration
$file = fopen($fullConfPath, "w");
if (!$file) {
$msg = "Unable to open file!";
echo $msg;
http_response_code(500); // Server error
die($msg);
}
fwrite($file, $input);
fclose($file);
echo "Configuration saved successfully.";
}
?>

View File

@@ -285,7 +285,7 @@
"Events_Tablelenght": "Show _MENU_ entries",
"Events_Tablelenght_all": "All",
"Events_Title": "Events",
"GRAPHQL_PORT_description": "The port number of the GraphQL server.",
"GRAPHQL_PORT_description": "The port number of the GraphQL server. Make sure the port is unique across all your applications on this host and NetAlertX instances.",
"GRAPHQL_PORT_name": "GraphQL port",
"Gen_Action": "Action",
"Gen_Add": "Add",
@@ -489,7 +489,7 @@
"Maintenance_themeselector_lable": "Select Skin",
"Maintenance_themeselector_text": "The change takes place on the server side, so it affects all devices in use.",
"Maintenance_version": "App updates",
"NETWORK_DEVICE_TYPES_description": "Which device types are allowed to be used as network devices in the Network view. The device type has to match exactly the <code>Type</code> setting on a specific device in Device details. Do not remove existing types, only add new ones.",
"NETWORK_DEVICE_TYPES_description": "Which device types are allowed to be used as network devices in the Network view. The device type has to match exactly the <code>Type</code> setting on a specific device in Device details. Add it on teh Device via the <code>+</code> button. Do not remove existing types, only add new ones.",
"NETWORK_DEVICE_TYPES_name": "Network device types",
"Navigation_About": "About",
"Navigation_Devices": "Devices",

View File

@@ -716,7 +716,7 @@
"description": [
{
"language_code": "en_us",
"string": "The type of the device."
"string": "The type of the device. Custom Network device types from the <code>NETWORK_DEVICE_TYPES</code> setting are not automatically added, you need to add it via the <code>+</code> button onthe device itself."
}
]
},
@@ -1330,7 +1330,7 @@
"description": [
{
"language_code": "en_us",
"string": "Indicates whether the device is archived. The default value of the <code>Archived</code> checkbox."
"string": "Indicates whether the device is archived. If you archive a device and the device is offline it will be hidden from My Devices."
}
]
},