Skip to content

Commit 432a4d9

Browse files
author
jokob-sk
committed
Initial commit on next_release branch
1 parent f5713d4 commit 432a4d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1510
-220
lines changed

back/workflows.json

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
[
2+
{
3+
"name": "Sample Device Update Workflow",
4+
"trigger": {
5+
"object_type": "Devices",
6+
"event_type": "update"
7+
},
8+
"conditions": [
9+
{
10+
"logic": "AND",
11+
"conditions": [
12+
{
13+
"field": "devVendor",
14+
"operator": "contains",
15+
"value": "Google"
16+
},
17+
{
18+
"field": "devIsNew",
19+
"operator": "equals",
20+
"value": "1"
21+
},
22+
{
23+
"logic": "OR",
24+
"conditions": [
25+
{
26+
"field": "devIsNew",
27+
"operator": "equals",
28+
"value": "1"
29+
},
30+
{
31+
"field": "devName",
32+
"operator": "contains",
33+
"value": "Google"
34+
}
35+
]
36+
}
37+
]
38+
}
39+
],
40+
"actions": [
41+
{
42+
"type": "update_field",
43+
"field": "devIsNew",
44+
"value": "0"
45+
},
46+
{
47+
"type": "run_plugin",
48+
"plugin": "SMTP",
49+
"params": {
50+
"message": "New device from Google detected."
51+
}
52+
}
53+
]
54+
},
55+
{
56+
"name": "Sample Plugin Object Workflow",
57+
"trigger": {
58+
"object_type": "Plugins_Objects",
59+
"event_type": "create"
60+
},
61+
"conditions": [
62+
{
63+
"logic": "AND",
64+
"conditions": [
65+
{
66+
"field": "Plugin",
67+
"operator": "equals",
68+
"value": "ARPSCAN"
69+
},
70+
{
71+
"field": "Status",
72+
"operator": "equals",
73+
"value": "missing-in-last-scan"
74+
}
75+
]
76+
}
77+
],
78+
"actions": [
79+
]
80+
}
81+
]

docker-compose.yml

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ services:
6161
- ${DEV_LOCATION}/front/cloud_services.php:/app/front/cloud_services.php
6262
- ${DEV_LOCATION}/front/report.php:/app/front/report.php
6363
- ${DEV_LOCATION}/front/workflows.php:/app/front/workflows.php
64+
- ${DEV_LOCATION}/front/workflowsCore.php:/app/front/workflowsCore.php
65+
- ${DEV_LOCATION}/front/appEvents.php:/app/front/appEvents.php
6466
- ${DEV_LOCATION}/front/appEventsCore.php:/app/front/appEventsCore.php
6567
- ${DEV_LOCATION}/front/multiEditCore.php:/app/front/multiEditCore.php
6668
- ${DEV_LOCATION}/front/plugins:/app/front/plugins

dockerfiles/init.sh

+6-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export INSTALL_DIR=/app # Specify the installation directory here
3737
# DO NOT CHANGE ANYTHING BELOW THIS LINE!
3838

3939
CONF_FILE="app.conf"
40+
WF_FILE="workflows.json"
4041
NGINX_CONF_FILE=netalertx.conf
4142
DB_FILE="app.db"
4243
FULL_FILEDB_PATH="${INSTALL_DIR}/db/${DB_FILE}"
@@ -54,8 +55,6 @@ if [[ $EUID -ne 0 ]]; then
5455
exit 1
5556
fi
5657

57-
echo "[INSTALL] Copy starter ${DB_FILE} and ${CONF_FILE} if they don't exist"
58-
5958
# DANGER ZONE: ALWAYS_FRESH_INSTALL
6059
if [ "$ALWAYS_FRESH_INSTALL" = true ]; then
6160
echo "[INSTALL] ❗ ALERT /db and /config folders are cleared because the ALWAYS_FRESH_INSTALL is set to: $ALWAYS_FRESH_INSTALL"
@@ -96,8 +95,11 @@ if [ -f "${INSTALL_DIR_OLD}/config/${OLD_APP_NAME}.conf" ]; then
9695
fi
9796
# 🔺 FOR BACKWARD COMPATIBILITY - REMOVE AFTER 12/12/2025
9897

99-
# Copy starter .db and .conf if they don't exist
98+
echo "[INSTALL] Copy starter ${DB_FILE} and ${CONF_FILE} if they don't exist"
99+
100+
# Copy starter app.db, app.conf, workflows.json if they don't exist
100101
cp -na "${INSTALL_DIR}/back/${CONF_FILE}" "${INSTALL_DIR}/config/${CONF_FILE}"
102+
cp -na "${INSTALL_DIR}/back/${WF_FILE}" "${INSTALL_DIR}/config/${WF_FILE}"
101103
cp -na "${INSTALL_DIR}/back/${DB_FILE}" "${FULL_FILEDB_PATH}"
102104

103105
# if custom variables not set we do not need to do anything
@@ -143,6 +145,7 @@ fi
143145
# Create the execution_queue.log and app_front.log files if they don't exist
144146
touch "${INSTALL_DIR}"/log/{app.log,execution_queue.log,app_front.log,app.php_errors.log,stderr.log,stdout.log,db_is_locked.log}
145147
touch "${INSTALL_DIR}"/api/user_notifications.json
148+
146149
# Create plugins sub-directory if it doesn't exist in case a custom log folder is used
147150
mkdir -p "${INSTALL_DIR}"/log/plugins
148151

front/appEvents.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
require 'php/templates/header.php';
4+
require 'php/templates/notification.php';
5+
?>
6+
<!-- ----------------------------------------------------------------------- -->
7+
8+
9+
<!-- Page ------------------------------------------------------------------ -->
10+
<div class="content-wrapper">
11+
12+
<?php
13+
require 'appEventsCore.php';
14+
?>
15+
16+
17+
</div>
18+
19+
<?php
20+
require 'php/templates/footer.php';
21+
?>

front/appEventsCore.php

+104-69
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<section class="content">
2-
<div class="nav-tabs-custom app-event-content" style="margin-bottom: 0px;">
3-
<ul id="tabs-location" class="nav nav-tabs col-sm-2">
4-
<li class="left-nav"><a class="col-sm-12" href="#" id="" data-toggle="tab">Events</a></li>
5-
</ul>
6-
<div id="tabs-content-location" class="tab-content col-sm-10">
7-
<table class="table table-striped" id="appevents-table" data-my-dbtable="AppEvents"></table>
8-
</div>
2+
<div class="nav-tabs-custom app-event-content" style="margin-bottom: 0px;">
3+
<ul id="tabs-location" class="nav nav-tabs col-sm-2 hidden">
4+
<li class="left-nav"><a class="col-sm-12" href="#" id="" data-toggle="tab">Events</a></li>
5+
</ul>
6+
<div id="tabs-content-location" class="tab-content col-sm-12">
7+
<table class="table table-striped" id="appevents-table" data-my-dbtable="AppEvents"></table>
98
</div>
9+
</div>
1010
</section>
1111

1212

@@ -18,75 +18,110 @@
1818
1919
$(document).ready(function() {
2020
21-
// Load JSON data from the provided URL
22-
$.getJSON('/php/server/query_json.php?file=table_appevents.json', function(data) {
23-
// Process the JSON data and generate UI dynamically
24-
processData(data)
21+
// Load JSON data from the provided URL
22+
$.getJSON('/php/server/query_json.php?file=table_appevents.json', function(data) {
23+
// Process the JSON data and generate UI dynamically
24+
processData(data)
2525
26-
// hide loading dialog
27-
hideSpinner()
28-
});
26+
// hide loading dialog
27+
hideSpinner()
28+
});
2929
});
3030
3131
function processData(data) {
32-
// Create an object to store unique ObjectType values as app event identifiers
33-
var appEventIdentifiers = {};
32+
// Create an object to store unique ObjectType values as app event identifiers
33+
var appEventIdentifiers = {};
3434
35-
// Array to accumulate data for DataTable
36-
var allData = [];
35+
// Array to accumulate data for DataTable
36+
var allData = [];
3737
38-
// Iterate through the data and generate tabs and content dynamically
39-
$.each(data.data, function(index, item) {
40-
41-
// Accumulate data for DataTable
42-
allData.push(item);
43-
44-
});
45-
46-
// Initialize DataTable for all app events
38+
// Iterate through the data and generate tabs and content dynamically
39+
$.each(data.data, function(index, item) {
40+
41+
// Accumulate data for DataTable
42+
allData.push(item);
4743
48-
$('#appevents-table').DataTable({
49-
data: allData,
50-
paging: true,
51-
lengthChange: true,
52-
lengthMenu: [[10, 25, 50, 100, 500, -1], [10, 25, 50, 100, 500, 'All']],
53-
searching: true,
54-
ordering: true,
55-
info: true,
56-
autoWidth: false,
57-
pageLength: 25, // Set the default paging to 25
58-
columns: [
59-
{ data: 'DateTimeCreated', title: getString('AppEvents_DateTimeCreated') },
60-
{ data: 'AppEventType', title: getString('AppEvents_Type') },
61-
{ data: 'ObjectType', title: getString('AppEvents_ObjectType') },
62-
{ data: 'ObjectPrimaryID', title: getString('AppEvents_ObjectPrimaryID') },
63-
{ data: 'ObjectSecondaryID', title: getString('AppEvents_ObjectSecondaryID') },
64-
{ data: 'ObjectStatus', title: getString('AppEvents_ObjectStatus') },
65-
{ data: 'Extra', title: getString('AppEvents_Extra') },
66-
{ data: 'ObjectPlugin', title: getString('AppEvents_Plugin') },
67-
// Add other columns as needed
68-
],
69-
// Add column-specific configurations if needed
70-
columnDefs: [
71-
{ className: 'text-center', targets: [3] },
72-
{ width: '80px', targets: [6] },
73-
// ... Add other columnDefs as needed
74-
// Full MAC
75-
{targets: [3, 4],
76-
'createdCell': function (td, cellData, rowData, row, col) {
77-
if (!emptyArr.includes(cellData)){
78-
$(td).html (createDeviceLink(cellData));
79-
} else {
80-
$(td).html ('');
81-
}
82-
} },
83-
]
84-
});
85-
86-
87-
// Activate the first tab
88-
$('#tabs-location li:first-child').addClass('active');
89-
$('#tabs-content-location .tab-pane:first-child').addClass('active');
44+
});
45+
46+
console.log(allData);
47+
48+
49+
// Initialize DataTable for all app events
50+
51+
$('#appevents-table').DataTable({
52+
data: allData,
53+
paging: true,
54+
lengthChange: true,
55+
lengthMenu: [[10, 25, 50, 100, 500, -1], [10, 25, 50, 100, 500, 'All']],
56+
searching: true,
57+
ordering: true,
58+
info: true,
59+
autoWidth: false,
60+
pageLength: 25, // Set the default paging to 25
61+
columns: [
62+
{ data: 'DateTimeCreated', title: getString('AppEvents_DateTimeCreated') },
63+
{ data: 'AppEventProcessed', title: getString('AppEvents_AppEventProcessed') },
64+
{ data: 'AppEventType', title: getString('AppEvents_Type') },
65+
{ data: 'ObjectType', title: getString('AppEvents_ObjectType') },
66+
{ data: 'ObjectPrimaryID', title: getString('AppEvents_ObjectPrimaryID') },
67+
{ data: 'ObjectSecondaryID', title: getString('AppEvents_ObjectSecondaryID') },
68+
{ data: 'ObjectStatus', title: getString('AppEvents_ObjectStatus') },
69+
{ data: 'ObjectPlugin', title: getString('AppEvents_Plugin') },
70+
{ data: 'ObjectGUID', title: "GUID" },
71+
// Add other columns as needed
72+
],
73+
// Add column-specific configurations if needed
74+
columnDefs: [
75+
{ className: 'text-center', targets: [4] },
76+
{ width: '80px', targets: [7] },
77+
// ... Add other columnDefs as needed
78+
// Full MAC
79+
{targets: [4, 5],
80+
'createdCell': function (td, cellData, rowData, row, col) {
81+
if (!emptyArr.includes(cellData)){
82+
$(td).html (createDeviceLink(cellData));
83+
} else {
84+
$(td).html ('');
85+
}
86+
} },
87+
// Processed
88+
{targets: [1],
89+
'createdCell': function (td, cellData, rowData, row, col) {
90+
// console.log(cellData);
91+
$(td).html (cellData);
92+
}
93+
},
94+
// Datetime
95+
{targets: [0],
96+
'createdCell': function (td, cellData, rowData, row, col) {
97+
let timezone = $("#NAX_TZ").html(); // e.g., 'Europe/Berlin'
98+
let utcDate = new Date(cellData + ' UTC'); // Adding ' UTC' makes it interpreted as UTC time
99+
100+
// Format the date in the desired timezone
101+
let options = {
102+
year: 'numeric',
103+
month: 'short',
104+
day: '2-digit',
105+
hour: '2-digit',
106+
minute: '2-digit',
107+
second: '2-digit',
108+
hour12: false, // Use 24-hour format
109+
timeZone: timezone // Use the specified timezone
110+
};
111+
112+
let localDate = new Intl.DateTimeFormat('en-GB', options).format(utcDate);
113+
114+
// Update the table cell
115+
$(td).html(localDate);
116+
}
117+
},
118+
]
119+
});
120+
121+
122+
// Activate the first tab
123+
$('#tabs-location li:first-child').addClass('active');
124+
$('#tabs-content-location .tab-pane:first-child').addClass('active');
90125
}
91126
92127
</script>

front/css/app.css

+41
Original file line numberDiff line numberDiff line change
@@ -1840,6 +1840,47 @@ input[readonly] {
18401840
height:50px;
18411841
}
18421842

1843+
/* -----------------------------------------------------------------------------
1844+
Workflows
1845+
----------------------------------------------------------------------------- */
1846+
1847+
#workflowContainerWrap .panel-collapse
1848+
{
1849+
padding: 5px;
1850+
}
1851+
1852+
.workflows .btn-secondary{
1853+
color: #000;
1854+
}
1855+
1856+
.workflows .condition-list button
1857+
{
1858+
margin: 2px;
1859+
}
1860+
1861+
.workflows button
1862+
{
1863+
/* width:100%; */
1864+
}
1865+
1866+
#workflowContainerWrap
1867+
{
1868+
display: contents;
1869+
}
1870+
1871+
.workflow-card, .condition-list, .actions-list
1872+
{
1873+
display: grid;
1874+
padding: 5px;
1875+
padding-left: 10px;
1876+
}
1877+
1878+
.condition
1879+
{
1880+
padding: 5px;
1881+
padding-left: 10px;
1882+
}
1883+
18431884
/* -----------------------------------------------------------------------------
18441885
Floating edit button
18451886
----------------------------------------------------------------------------- */

0 commit comments

Comments
 (0)