This commit is contained in:
jokob-sk
2025-03-27 21:23:11 +11:00
parent e996c9eccc
commit 7e5373b2cd
16 changed files with 144 additions and 131 deletions

View File

@@ -1,55 +0,0 @@
[
{
"name": "Sample Device Update Workflow",
"trigger": {
"object_type": "Devices",
"event_type": "update"
},
"conditions": [
{
"logic": "AND",
"conditions": [
{
"field": "devVendor",
"operator": "contains",
"value": "Google"
},
{
"field": "devIsNew",
"operator": "equals",
"value": "1"
},
{
"logic": "OR",
"conditions": [
{
"field": "devIsNew",
"operator": "equals",
"value": "1"
},
{
"field": "devName",
"operator": "contains",
"value": "Google"
}
]
}
]
}
],
"actions": [
{
"type": "update_field",
"field": "devIsNew",
"value": "0"
},
{
"type": "run_plugin",
"plugin": "SMTP",
"params": {
"message": "New device from Google detected."
}
}
]
}
]

View File

@@ -37,7 +37,6 @@ export INSTALL_DIR=/app # Specify the installation directory here
# DO NOT CHANGE ANYTHING BELOW THIS LINE!
CONF_FILE="app.conf"
WF_FILE="workflows.json"
NGINX_CONF_FILE=netalertx.conf
DB_FILE="app.db"
FULL_FILEDB_PATH="${INSTALL_DIR}/db/${DB_FILE}"
@@ -97,9 +96,8 @@ fi
echo "[INSTALL] Copy starter ${DB_FILE} and ${CONF_FILE} if they don't exist"
# Copy starter app.db, app.conf, workflows.json if they don't exist
# Copy starter app.db, app.conf if they don't exist
cp -na "${INSTALL_DIR}/back/${CONF_FILE}" "${INSTALL_DIR}/config/${CONF_FILE}"
cp -na "${INSTALL_DIR}/back/${WF_FILE}" "${INSTALL_DIR}/config/${WF_FILE}"
cp -na "${INSTALL_DIR}/back/${DB_FILE}" "${FULL_FILEDB_PATH}"
# if custom variables not set we do not need to do anything

View File

@@ -1524,10 +1524,11 @@ input[readonly] {
margin:0px;
align-items:center;
border-radius:20px;
width:190px; /* Don't change, smaller causes line break in network view */
display:flex;
/* width:190px; Don't change, smaller causes line break in network view */
/* display:flex; */
flex-direction:column;
justify-content:center;
display: inline-grid;
}
.networkHelpIcon
{
@@ -1597,7 +1598,7 @@ input[readonly] {
.spanNetworkTree {
display: inline-block;
width: 135px;
/* width: 135px; */
white-space: nowrap;
overflow: hidden !important;
text-overflow: ellipsis;
@@ -1871,6 +1872,7 @@ input[readonly] {
.workflows .add-button-wrap .button-container
{
padding-bottom: 5px;
text-align: center;
}
.workflows .actions-list {
@@ -1901,12 +1903,21 @@ input[readonly] {
color: #000;
}
.workflows .button-container button
.workflows .button-container
{
display: inline-table;
display: contents;
text-align: center;
width: 100%;
}
.workflows .panel:hover{
opacity: 1;
}
.workflows .panel{
opacity: 0.8;
}
.workflows .bottom-buttons button
{
margin: 5px;
@@ -1914,8 +1925,8 @@ input[readonly] {
.workflows .button-container
{
padding-right: 5px !important;
padding-left: 5px !important;
padding-right: 0px !important;
padding-left: 0px !important;
}
/* .workflows .condition-list button
@@ -1928,6 +1939,11 @@ input[readonly] {
width:100%;
} */
.workflows .workflow-card
{
display: block;
}
.workflow-card .panel-title
{
padding: 10px;

View File

@@ -744,4 +744,5 @@
.thresholdFormControl
{
color:#000;
}
}

View File

@@ -743,6 +743,7 @@ function initializeDatatable (status) {
'ordering' : true,
'info' : true,
'autoWidth' : false,
'dom': '<"top"f>rtl<"bottom"ip><"clear">',
// Parameters
'pageLength' : tableRows,

File diff suppressed because one or more lines are too long

View File

@@ -440,17 +440,15 @@ function askImportPastedConfig() {
// Upload Settings Config
function UploadConfig()
{
// alert("aaa")
appConf = $('#modal-input-textarea').val()
// encode for import
appConfBase64 = btoa(appConf)
// import
$.post('php/server/query_replace_config.php', { config: appConfBase64 }, function(msg) {
$.post('php/server/query_replace_config.php', { base64data: appConfBase64, fileName: "app.conf" }, function(msg) {
console.log(msg);
// showMessage(msg);
write_notification(`[Maintenance] Settings imported from backup: ${msg}`, 'interrupt');
write_notification(`[Maintenance]: ${msg}`, 'interrupt');
});
}

View File

@@ -465,7 +465,7 @@
?>
<script src="lib/treeviz/bundle.js"></script>
<script src="lib/treeviz/bundle.js.map"></script>
<script defer>

View File

@@ -1,6 +1,6 @@
<?php
ini_set('error_log', '../../log/app.php_errors.log'); // initializing the app.php_errors.log file for the maintenance section
require dirname(__FILE__).'/../templates/timezone.php';
require dirname(__FILE__).'/../templates/globals.php';
require dirname(__FILE__).'/db.php';
require dirname(__FILE__).'/util.php';
require dirname(__FILE__).'/../templates/language/lang.php';

View File

@@ -13,21 +13,23 @@ require dirname(__FILE__).'/../server/init.php';
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
// Get query string parameters ?file=settings_table.json&download=true
$file = isset($_GET['file']) ? $_GET['file'] : null;
$download = isset($_GET['download']) ? $_GET['download'] === 'true' : false;
$download = isset($_GET['download']) && $_GET['download'] === 'true';
// Check if file parameter is provided
if ($file) {
// Define the folder where files are located
$filePath = "/app/config/" . basename($file);
// Check if the file exists
if (file_exists($filePath)) {
// Handle download behavior
// Check if the file exists and is readable
if (file_exists($filePath) && is_readable($filePath)) {
// Determine file extension
$extension = pathinfo($filePath, PATHINFO_EXTENSION);
if ($download) {
// Force file download
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . basename($filePath) . '"');
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
@@ -35,19 +37,29 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
readfile($filePath);
exit;
} else {
// Display file content
header('Content-Type: text/plain');
echo file_get_contents($filePath);
// Serve file based on type
if ($extension === 'json') {
header('Content-Type: application/json');
echo json_encode(json_decode(file_get_contents($filePath), true), JSON_PRETTY_PRINT);
} else {
header('Content-Type: text/plain');
echo file_get_contents($filePath);
}
exit;
}
} else {
// File not found response
http_response_code(404);
header('Content-Type: application/json');
echo json_encode(["error" => "File not found"]);
exit;
}
} else {
// Missing file parameter response
http_response_code(400);
header('Content-Type: application/json');
echo json_encode(["error" => "Missing 'file' parameter"]);
exit;
}
}
?>

View File

@@ -8,16 +8,24 @@ require_once $_SERVER['DOCUMENT_ROOT'] . '/php/templates/security.php';
require dirname(__FILE__).'/../server/init.php';
// ---- IMPORTS ----
global $fullConfPath;
global $configFolderPath;
//------------------------------------------------------------------------------
// Handle incoming requests
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Access the 'config' parameter from the POST request
$base64Data = $_POST['config'] ?? null;
$base64Data = $_POST['base64data'] ?? null;
if (!$base64Data) {
$msg = "Missing 'config' parameter.";
$msg = "Missing 'base64data' parameter.";
echo $msg;
http_response_code(400); // Bad request
die($msg);
}
$fileName = $_POST['fileName'] ?? null;
if (!$fileName) {
$msg = "Missing 'fileName' parameter.";
echo $msg;
http_response_code(400); // Bad request
die($msg);
@@ -33,15 +41,17 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
die($msg);
}
$fullPath = $configFolderPath.$fileName;
// Backup the original file
if (file_exists($fullConfPath)) {
copy($fullConfPath, $fullConfPath . ".bak");
if (file_exists($fullPath)) {
copy($fullPath, $fullPath . ".bak");
}
// Write the new configuration
$file = fopen($fullConfPath, "w");
$file = fopen($fullPath, "w");
if (!$file) {
$msg = "Unable to open file!";
$msg = "Unable to open file: ". $fullPath;
echo $msg;
http_response_code(500); // Server error
die($msg);
@@ -50,6 +60,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
fwrite($file, $input);
fclose($file);
echo "Configuration saved successfully.";
echo "Configuration file saved successfully: " .$fileName ;
}
?>

View File

@@ -8,7 +8,7 @@
# Puche 2021 / 2022+ jokob jokob@duck.com GNU GPLv3
//------------------------------------------------------------------------------
require dirname(__FILE__).'/../templates/timezone.php';
require dirname(__FILE__).'/../templates/globals.php';
require dirname(__FILE__).'/../templates/skinUI.php';
//------------------------------------------------------------------------------

View File

@@ -1,6 +1,6 @@
<?php
require dirname(__FILE__).'/../templates/timezone.php';
require dirname(__FILE__).'/../templates/globals.php';
//------------------------------------------------------------------------------
// check if authenticated

View File

@@ -1,17 +1,21 @@
<?php
// ###################################
// ## TimeZone processing start
// ###################################
// ######################################################################
// ## Global constants and TimeZone processing
// ######################################################################
$configFolderPath = dirname(__FILE__)."/../../../config/";
$config_file = "app.conf";
$configFolderPath = "/app/config/";
$logFolderPath = "/app/log/";
$config_file = "app.conf";
$workflows_file = "workflows.json";
$log_file = "app_front.log";
$default_tz = "Europe/Berlin";
$fullConfPath = $configFolderPath.$config_file;
$fullWorkflowsPath = $configFolderPath.$workflows_file;
$config_file_lines = file($fullConfPath);
$config_file_lines_timezone = array_values(preg_grep('/^TIMEZONE\s.*/', $config_file_lines));
@@ -44,7 +48,7 @@ date_default_timezone_set($timeZone);
$date = new DateTime("now", new DateTimeZone($timeZone) );
$timestamp = $date->format('Y-m-d_H-i-s');
// ###################################
// ## TimeZone processing end
// ###################################
// ######################################################################
// ## Global constants and TimeZone processing
// ######################################################################

View File

@@ -5,19 +5,19 @@
?>
<section class="content workflows col-sm-12">
<div id="workflowContainerWrap" class="bg-grey-dark color-palette col-sm-12 box-default box-info ">
<section class="content workflows col-sm-12 col-xs-12">
<div id="workflowContainerWrap" class="bg-grey-dark color-palette col-sm-12 col-xs-12 box-default box-info ">
<div id="workflowContainer"></div>
</div>
<div id="buttons" class="bottom-buttons col-sm-12">
<div class="add-workflow col-sm-12">
<button type="button" class="btn btn-primary add-workflow-btn col-sm-12" id="save">
<div id="buttons" class="bottom-buttons col-sm-12 col-xs-12">
<div class="add-workflow col-sm-12 col-xs-12">
<button type="button" class="btn btn-primary add-workflow-btn col-sm-12 col-xs-12" id="save">
<?= lang('Gen_Add');?>
</button>
</div>
<div class="save-workflows col-sm-12">
<button type="button" class="btn btn-primary col-sm-12" id="save" onclick="saveWorkflows()">
<div class="save-workflows col-sm-12 col-xs-12">
<button type="button" class="btn btn-primary col-sm-12 col-xs-12" id="save" onclick="saveWorkflows()">
<?= lang('DevDetail_button_Save');?>
</button>
</div>
@@ -46,7 +46,7 @@ let operatorTypes = [
];
let actionTypes = [
"update_field", "run_plugin", "delete_device"
"update_field", "delete_device"
];
// --------------------------------------
@@ -57,13 +57,23 @@ function getData() {
getSetting()
$.get('php/server/query_json.php?file=workflows.json', function (res) {
$.get('php/server/query_json.php?file=workflows.json')
.done(function (res) {
workflows = res;
console.log("here workflows");
console.log(workflows);
updateWorkflowsJson(workflows);
renderWorkflows();
hideSpinner();
})
.fail(function (jqXHR, textStatus, errorThrown) {
console.warn("Failed to load workflows.json:", textStatus, errorThrown);
workflows = []; // Set a default empty array to prevent crashes
updateWorkflowsJson(workflows);
renderWorkflows();
})
.always(function () {
hideSpinner(); // Ensure the spinner is hidden in all cases
});
}
@@ -91,21 +101,21 @@ function renderWorkflows() {
function generateWorkflowUI(wf, wfIndex) {
let $wfContainer = $("<div>", {
class: "workflow-card col-sm-12 col-sx-12",
class: "workflow-card panel col-sm-12 col-sx-12",
id: `wf-${wfIndex}-container`
});
// Workflow Name
let $wfLinkWrap = $("<div>",
{
class: "box box-solid box-primary ",
class: " ",
id: `wf-${wfIndex}-header`
}
)
let $wfHeaderLink = $("<a>",
{
"class": "",
"class": "pointer ",
"data-toggle": "collapse",
"data-parent": "#workflowContainer",
"aria-expanded": false,
@@ -131,7 +141,7 @@ function generateWorkflowUI(wf, wfIndex) {
let $wfCollapsiblePanel = $("<div>", {
class: `box panel-collapse collapse ${isOpen ? 'in' : ''}`,
class: ` panel-collapse collapse ${isOpen ? 'in' : ''}`,
id: `wf-${wfIndex}-collapsible-panel`
});
@@ -185,7 +195,11 @@ function generateWorkflowUI(wf, wfIndex) {
}
).text("Conditions:")
let $conditionsContainer = $("<div>").append($conditionsTitle);
let $conditionsContainer = $("<div>",
{
class: "col-sm-12 col-sx-12"
}
).append($conditionsTitle);
$conditionsContainer.append(renderConditions(wfIndex, `[${wfIndex}]`, 0, wf.conditions));
@@ -229,7 +243,7 @@ function generateWorkflowUI(wf, wfIndex) {
`[${wfIndex}].actions[${actionIndex}].type`,
"Type",
actionTypes,
action.field,
action.type,
`wf-${wfIndex}-actionIndex-${actionIndex}-type`
);
@@ -255,8 +269,8 @@ function generateWorkflowUI(wf, wfIndex) {
class: "fa-solid fa-trash"
});
let $actionRemoveButton = $("<button>", {
class: "btn btn-secondary remove-action btn-orange",
let $actionRemoveButton = $("<div>", {
class: "pointer remove-action ",
actionIndex: actionIndex,
wfIndex: wfIndex
})
@@ -277,8 +291,8 @@ function generateWorkflowUI(wf, wfIndex) {
let $actionAddIcon = $("<i>", {
class: "fa-solid fa-plus"
});
let $actionAddButton = $("<button>", {
class : "btn btn-secondary add-action",
let $actionAddButton = $("<div>", {
class : "pointer add-action",
lastActionIndex : lastActionIndex,
wfIndex: wfIndex
}).append($actionAddIcon).append("Add Action")
@@ -293,8 +307,8 @@ function generateWorkflowUI(wf, wfIndex) {
class: "fa-solid fa-trash"
});
let $wfRemoveButton = $("<button>", {
class: "btn btn-secondary remove-wf",
let $wfRemoveButton = $("<div>", {
class: "pointer remove-wf",
wfIndex: wfIndex
})
.append($wfRemoveIcon) // Add icon
@@ -404,8 +418,8 @@ function renderConditions(wfIndex, parentIndexPath, conditionGroupsIndex, condit
let $conditionRemoveButtonIcon = $("<i>", {
class: "fa-solid fa-trash"
});
let $conditionRemoveButton = $("<button>", {
class : "btn btn-secondary remove-condition ",
let $conditionRemoveButton = $("<div>", {
class : "pointer remove-condition ",
conditionIndex : conditionIndex,
wfIndex: wfIndex,
parentIndexPath: parentIndexPath
@@ -431,8 +445,8 @@ function renderConditions(wfIndex, parentIndexPath, conditionGroupsIndex, condit
let $conditionAddIcon = $("<i>", {
class: "fa-solid fa-plus"
});
let $conditionAddButton = $("<button>", {
class: "btn btn-secondary add-condition col-sx-12",
let $conditionAddButton = $("<div>", {
class: "pointer add-condition col-sx-12",
wfIndex: wfIndex,
parentIndexPath: parentIndexPath
}).append($conditionAddIcon).append("Add Condition");
@@ -443,8 +457,8 @@ function renderConditions(wfIndex, parentIndexPath, conditionGroupsIndex, condit
let $conditionGroupRemoveIcon = $("<i>", {
class: "fa-solid fa-trash"
});
let $conditionGroupRemoveButton = $("<button>", {
class: "btn btn-secondary remove-condition-group col-sx-12",
let $conditionGroupRemoveButton = $("<div>", {
class: "pointer remove-condition-group col-sx-12",
lastConditionIndex: lastConditionIndex,
wfIndex: wfIndex,
parentIndexPath: parentIndexPath
@@ -461,11 +475,11 @@ function renderConditions(wfIndex, parentIndexPath, conditionGroupsIndex, condit
let $conditionsGroupAddIcon = $("<i>", {
class: "fa-solid fa-plus"
});
let $conditionsGroupAddButton = $("<button>", {
class: "btn btn-secondary add-condition-group col-sx-12",
let $conditionsGroupAddButton = $("<div>", {
class: "pointer add-condition-group col-sx-12",
wfIndex: wfIndex,
parentIndexPath: parentIndexPath
}).append($conditionsGroupAddIcon).append("Add Condition Group");
}).append($conditionsGroupAddIcon).append("Add Group");
$conditionsGroupAddWrap.append($conditionsGroupAddButton);
$addButtonWrap.append($conditionsGroupAddWrap);
@@ -910,6 +924,21 @@ function getEmptyWorkflowJson()
}
}
// ---------------------------------------------------
// Save workflows JSON
function saveWorkflows()
{
// encode for import
appConfBase64 = btoa(JSON.stringify(getWorkflowsJson()))
// import
$.post('php/server/query_replace_config.php', { base64data: appConfBase64, fileName: "workflows.json" }, function(msg) {
console.log(msg);
// showMessage(msg);
write_notification(`[WF]: ${msg}`, 'interrupt');
});
}
// ---------------------------------------------------
// Event listeners
$(document).on("click", ".add-workflow-btn", function () {

View File

@@ -87,7 +87,7 @@ class WorkflowManager:
if evaluator.evaluate(trigger): # If any group evaluates to True
mylog('none', [f"[WF] Workflow {workflow["name"]} will be executed - conditions were evalueted as TRUE"])
mylog('none', [f"[WF] Workflow {workflow["name"]} will be executed - conditions were evaluated as TRUE"])
mylog('debug', [f"[WF] Workflow condition_group: {condition_group}"])
self.execute_actions(workflow["actions"], trigger)