Skip to content

Commit

Permalink
Notification Report page rewrite v0.2 + cleanup📩
Browse files Browse the repository at this point in the history
  • Loading branch information
jokob-sk committed Oct 26, 2023
1 parent fd162ff commit 536ef9e
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 8 deletions.
4 changes: 3 additions & 1 deletion front/php/templates/language/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,9 @@
"ENABLE_PLUGINS_name" : "Enable Plugins",
"ENABLE_PLUGINS_description" : "Enables the <a target=\"_blank\" href=\"https://github.com/jokob-sk/Pi.Alert/tree/main/front/plugins\">plugins</a> functionality. Loading plugins requires more hardware resources so you might want to disable them on low-powered system.",
"PLUGINS_KEEP_HIST_name" : "Plugins History",
"PLUGINS_KEEP_HIST_description" : "How many entries of Plugins History scan results should be kept (per Plugin, not device specific).",
"PLUGINS_KEEP_HIST_description" : "How many entries of Plugins History scan results should be kept (per Plugin, and not device specific).",
"DBCLNP_NOTIFI_HIST_name" : "Notifications History",
"DBCLNP_NOTIFI_HIST_description" : "How many historical entries of Notifications should be kept.",
"PIALERT_WEB_PROTECTION_name" : "Enable login",
"PIALERT_WEB_PROTECTION_description" : "When enabled a login dialog is displayed. Read below carefully if you get locked out of your instance.",
"PIALERT_WEB_PASSWORD_name" : "Login password",
Expand Down
3 changes: 2 additions & 1 deletion front/plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,8 @@ The UI will adjust how columns are displayed in the UI based on the resolvers de
| `url` | The value is considered to be a URL, so a link is generated. |
| `textbox_save` | Generates an editable and saveable text box that saves values in the database. Primarily intended for the `UserData` database column in the `Plugins_Objects` table. |
| `url_http_https` | Generates two links with the `https` and `http` prefix as lock icons. |
| `eval` | Evaluates as JavaScript. Use the variable `value` to use the given column value as input (e.g. ``<b>${value}<b>`` ) |
> [!NOTE]
> Supports chaining. You can chain multiple resolvers with `.`. For example `regex.url_http_https`. This will apply the `regex` resolver and then the `url_http_https` resolver.
Expand Down
2 changes: 1 addition & 1 deletion front/plugins/_publisher_apprise/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
"options": [
{
"type": "eval",
"param": "`<a href='/report?guid=${value}'>${value}</a>`"
"param": "`<a href='/report.php?guid=${value}'>${value}</a>`"
}
],
"localized": ["name"],
Expand Down
2 changes: 1 addition & 1 deletion front/plugins/_publisher_email/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
"options": [
{
"type": "eval",
"param": "`<a href='/report?guid=${value}'>${value}</a>`"
"param": "`<a href='/report.php?guid=${value}'>${value}</a>`"
}
],
"localized": [
Expand Down
2 changes: 1 addition & 1 deletion front/plugins/_publisher_ntfy/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"options": [
{
"type": "eval",
"param": "`<a href='/report?guid=${value}'>${value}</a>`"
"param": "`<a href='/report.php?guid=${value}'>${value}</a>`"
}
],
"localized": ["name"],
Expand Down
2 changes: 1 addition & 1 deletion front/plugins/_publisher_pushsafer/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"options": [
{
"type": "eval",
"param": "`<a href='/report?guid=${value}'>${value}</a>`"
"param": "`<a href='/report.php?guid=${value}'>${value}</a>`"
}
],
"localized": ["name"],
Expand Down
2 changes: 1 addition & 1 deletion front/plugins/_publisher_webhook/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"options": [
{
"type": "eval",
"param": "`<a href='/report?guid=${value}'>${value}</a>`"
"param": "`<a href='/report.php?guid=${value}'>${value}</a>`"
}
],
"localized": ["name"],
Expand Down
17 changes: 17 additions & 0 deletions front/plugins/db_cleanup/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,23 @@ def cleanup_database (dbPath, DAYS_TO_KEEP_EVENTS, PHOLUS_DAYS_DATA, HRS_TO_KEEP

cursor.execute(delete_query)

# Trim Notifications entries to less than DBCLNP_NOTIFI_HIST setting
mylog('verbose', [f'[DBCLNP] Plugins_History: Trim Notifications entries to less than {str(get_setting_value('DBCLNP_NOTIFI_HIST'))} )'])

# Build the SQL query to delete entries
delete_query = f"""DELETE FROM Notifications
WHERE "Index" NOT IN (
SELECT "Index"
FROM (
SELECT "Index",
ROW_NUMBER() OVER(PARTITION BY "Notifications" ORDER BY DateTimeCreated DESC) AS row_num
FROM Notifications
) AS ranked_objects
WHERE row_num <= {str(get_setting_value('DBCLNP_NOTIFI_HIST'))}
);"""

cursor.execute(delete_query)

# Cleanup Pholus_Scan
if PHOLUS_DAYS_DATA != 0:
mylog('verbose', ['[DBCLNP] Pholus_Scan: Delete all older than ' + str(PHOLUS_DAYS_DATA) + ' days (PHOLUS_DAYS_DATA setting)'])
Expand Down
3 changes: 2 additions & 1 deletion front/pluginsCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ function processColumnValue(dbColumnDef, value, index, type) {

for (const option of dbColumnDef.options) {
if (option.type === type) {
value = eval(value);
console.log(option.param)
value = eval(option.param);
}
}
break;
Expand Down
1 change: 1 addition & 0 deletions pialert/initialise.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def importConfigs (db):
conf.UI_PRESENCE = ccd('UI_PRESENCE', ['online', 'offline', 'archived'] , c_d, 'Include in presence', 'text.multiselect', "['online', 'offline', 'archived']", 'General')
conf.DAYS_TO_KEEP_EVENTS = ccd('DAYS_TO_KEEP_EVENTS', 90 , c_d, 'Delete events days', 'integer', '', 'General')
conf.HRS_TO_KEEP_NEWDEV = ccd('HRS_TO_KEEP_NEWDEV', 0 , c_d, 'Keep new devices for', 'integer', "0", 'General')
conf.DBCLNP_NOTIFI_HIST = ccd('DBCLNP_NOTIFI_HIST', 100 , c_d, 'Keep notification', 'integer', "0", 'General')
conf.API_CUSTOM_SQL = ccd('API_CUSTOM_SQL', 'SELECT * FROM Devices WHERE dev_PresentLastScan = 0' , c_d, 'Custom endpoint', 'text', '', 'General')
conf.NETWORK_DEVICE_TYPES = ccd('NETWORK_DEVICE_TYPES', ['AP', 'Gateway', 'Firewall', 'Hypervisor', 'Powerline', 'Switch', 'WLAN', 'PLC', 'Router','USB LAN Adapter', 'USB WIFI Adapter', 'Internet'] , c_d, 'Network device types', 'list', '', 'General')

Expand Down

0 comments on commit 536ef9e

Please sign in to comment.