From 4a20b66c92cedc7e08fa3b1518474afdabab5c20 Mon Sep 17 00:00:00 2001 From: jokob-sk Date: Thu, 19 Sep 2024 15:43:16 +1000 Subject: [PATCH] Clear NEW flag setting --- front/js/modal.js | 1 + front/php/templates/language/cs_cz.json | 2 ++ front/php/templates/language/de_de.json | 2 ++ front/php/templates/language/en_us.json | 6 ++++-- front/php/templates/language/es_es.json | 4 +++- front/php/templates/language/fr_fr.json | 2 ++ front/php/templates/language/it_it.json | 2 ++ front/php/templates/language/nb_no.json | 2 ++ front/php/templates/language/pl_pl.json | 2 ++ front/php/templates/language/pt_br.json | 2 ++ front/php/templates/language/ru_ru.json | 2 ++ front/php/templates/language/tr_tr.json | 2 ++ front/php/templates/language/zh_cn.json | 2 ++ front/plugins/db_cleanup/script.py | 16 ++++++++++++++-- server/initialise.py | 1 + 15 files changed, 43 insertions(+), 5 deletions(-) diff --git a/front/js/modal.js b/front/js/modal.js index 5f9abf7a..f7fe4202 100755 --- a/front/js/modal.js +++ b/front/js/modal.js @@ -295,6 +295,7 @@ function checkNotification() { console.log(response); // After marking the notification as read, check for the next one checkNotification(); + hideSpinner(); }, error: function(xhr, status, error) { console.error("Error marking notification as read:", status, error); diff --git a/front/php/templates/language/cs_cz.json b/front/php/templates/language/cs_cz.json index fc0437d7..149f2583 100755 --- a/front/php/templates/language/cs_cz.json +++ b/front/php/templates/language/cs_cz.json @@ -56,6 +56,8 @@ "BackDevices_Restore_okay": "", "BackDevices_darkmode_disabled": "", "BackDevices_darkmode_enabled": "", + "CLEAR_NEW_FLAG_description": "", + "CLEAR_NEW_FLAG_name": "", "DAYS_TO_KEEP_EVENTS_description": "", "DAYS_TO_KEEP_EVENTS_name": "", "DevDetail_Copy_Device_Title": "", diff --git a/front/php/templates/language/de_de.json b/front/php/templates/language/de_de.json index cbd7c71c..0894abc5 100755 --- a/front/php/templates/language/de_de.json +++ b/front/php/templates/language/de_de.json @@ -68,6 +68,8 @@ "BackDevices_Restore_okay": "Die Wiederherstellung wurde erfolgreich ausgeführt.", "BackDevices_darkmode_disabled": "Heller Modus aktiviert.", "BackDevices_darkmode_enabled": "Dunkler Modus aktiviert.", + "CLEAR_NEW_FLAG_description": "", + "CLEAR_NEW_FLAG_name": "", "DAYS_TO_KEEP_EVENTS_description": "Dies ist eine Wartungseinstellung. Spezifiziert wie viele Tage Events gespeichert bleiben. Alle älteren Events werden periodisch gelöscht. Wird auch auf die Plugins History angewendet.", "DAYS_TO_KEEP_EVENTS_name": "Lösche Events älter als", "DevDetail_Copy_Device_Title": " Details von Gerät kopieren", diff --git a/front/php/templates/language/en_us.json b/front/php/templates/language/en_us.json index 158dd6a2..e6b4473a 100755 --- a/front/php/templates/language/en_us.json +++ b/front/php/templates/language/en_us.json @@ -56,6 +56,8 @@ "BackDevices_Restore_okay": "Restore executed successfully.", "BackDevices_darkmode_disabled": "Darkmode Disabled", "BackDevices_darkmode_enabled": "Darkmode Enabled", + "CLEAR_NEW_FLAG_description": "If enabled (0 is disabled), devices flagged as New Device will be unflagged if the time limit (specified in hours) exceeds their First Session time.", + "CLEAR_NEW_FLAG_name": "Clear new flag", "DAYS_TO_KEEP_EVENTS_description": "This is a maintenance setting. This specifies the number of days worth of event entries that will be kept. All older events will be deleted periodically. Also applies on Plugin Events History.", "DAYS_TO_KEEP_EVENTS_name": "Delete events older than", "DevDetail_Copy_Device_Title": " Copy details from device", @@ -303,8 +305,8 @@ "Gen_Work_In_Progress": "Work in progress, good time to feedback on https://github.com/jokob-sk/NetAlertX/issues", "General_display_name": "General", "General_icon": "", - "HRS_TO_KEEP_NEWDEV_description": "This is a maintenance setting. If enabled (0 is disabled), devices marked as New Device will be deleted if their First Session time was older than the specified hours in this setting. Use this setting if you want to auto-delete New Devices after X hours.", - "HRS_TO_KEEP_NEWDEV_name": "Keep new devices for", + "HRS_TO_KEEP_NEWDEV_description": "This is a maintenance setting DELETING devices. If enabled (0 is disabled), devices marked as New Device will be deleted if their First Session time was older than the specified hours in this setting. Use this setting if you want to auto-delete New Devices after X hours.", + "HRS_TO_KEEP_NEWDEV_name": "Delete new devices after", "HelpFAQ_Cat_Detail": "Details", "HelpFAQ_Cat_Detail_300_head": "What means ", "HelpFAQ_Cat_Detail_300_text_a": "means a network device (a device of the type AP, Gateway, Firewall, Hypervisor, Powerline, Switch, WLAN, PLC, Router,USB LAN Adapter, USB WIFI Adapter, or Internet). Custom types can be added via the NETWORK_DEVICE_TYPES setting.", diff --git a/front/php/templates/language/es_es.json b/front/php/templates/language/es_es.json index e702ef57..9ea1a865 100755 --- a/front/php/templates/language/es_es.json +++ b/front/php/templates/language/es_es.json @@ -66,6 +66,8 @@ "BackDevices_Restore_okay": "Restauración ejecutado con éxito.", "BackDevices_darkmode_disabled": "Darkmode Desactivado", "BackDevices_darkmode_enabled": "Darkmode Activado", + "CLEAR_NEW_FLAG_description": "", + "CLEAR_NEW_FLAG_name": "", "DAYS_TO_KEEP_EVENTS_description": "Esta es una configuración de mantenimiento. Esto especifica el número de días de entradas de eventos que se guardarán. Todos los eventos anteriores se eliminarán periódicamente.", "DAYS_TO_KEEP_EVENTS_name": "Eliminar eventos anteriores a", "DevDetail_Copy_Device_Title": " Copiar detalles del dispositivo", @@ -773,4 +775,4 @@ "settings_update_item_warning": "Actualice el valor a continuación. Tenga cuidado de seguir el formato anterior. O la validación no se realiza.", "test_event_icon": "fa-vial-circle-check", "test_event_tooltip": "Guarda tus cambios antes de probar nuevos ajustes." -} +} \ No newline at end of file diff --git a/front/php/templates/language/fr_fr.json b/front/php/templates/language/fr_fr.json index 95f8767f..a507c247 100755 --- a/front/php/templates/language/fr_fr.json +++ b/front/php/templates/language/fr_fr.json @@ -56,6 +56,8 @@ "BackDevices_Restore_okay": "Restauration exécutée avec succès.", "BackDevices_darkmode_disabled": "Mode sombre désactivé", "BackDevices_darkmode_enabled": "Mode sombre activé", + "CLEAR_NEW_FLAG_description": "", + "CLEAR_NEW_FLAG_name": "", "DAYS_TO_KEEP_EVENTS_description": "Il s'agit d'un paramètre de maintenance. Il indique le nombre de jours pendant lesquels les entrées d'événements seront conservées. Tous les événements plus anciens seront supprimés périodiquement. S'applique également à l'historique des événements du plugin.", "DAYS_TO_KEEP_EVENTS_name": "Supprimer les événements plus anciens que", "DevDetail_Copy_Device_Title": " Copier les détails de l'appareil", diff --git a/front/php/templates/language/it_it.json b/front/php/templates/language/it_it.json index d7ee8f62..9c6a1570 100755 --- a/front/php/templates/language/it_it.json +++ b/front/php/templates/language/it_it.json @@ -56,6 +56,8 @@ "BackDevices_Restore_okay": "Ripristino eseguito correttamente.", "BackDevices_darkmode_disabled": "Modalità scura disabilitata", "BackDevices_darkmode_enabled": "Modalità scura abilitata", + "CLEAR_NEW_FLAG_description": "", + "CLEAR_NEW_FLAG_name": "", "DAYS_TO_KEEP_EVENTS_description": "Questa è un'impostazione di manutenzione. Specifica il numero di giorni delle voci degli eventi che verranno conservati. Tutti gli eventi più vecchi verranno eliminati periodicamente. Si applica anche alla cronologia degli eventi del plugin (Plugin Events History).", "DAYS_TO_KEEP_EVENTS_name": "Elimina eventi più vecchi di", "DevDetail_Copy_Device_Title": " Copia dettagli dal dispositivo", diff --git a/front/php/templates/language/nb_no.json b/front/php/templates/language/nb_no.json index aebe5869..6f4493e8 100755 --- a/front/php/templates/language/nb_no.json +++ b/front/php/templates/language/nb_no.json @@ -56,6 +56,8 @@ "BackDevices_Restore_okay": "Gjenoppretting utført.", "BackDevices_darkmode_disabled": "Mørk modus Deaktivert", "BackDevices_darkmode_enabled": "Mørk modus Aktivert", + "CLEAR_NEW_FLAG_description": "", + "CLEAR_NEW_FLAG_name": "", "DAYS_TO_KEEP_EVENTS_description": "Dette er en vedlikeholdsinnstilling. Dette spesifiserer antall dager verdt med hendelsesoppføringer som vil beholdes. Alle eldre hendelser vil bli slettet med jevne mellomrom. Gjelder også for plugin-hendelseshistorikk.", "DAYS_TO_KEEP_EVENTS_name": "Slett hendelser eldre enn", "DevDetail_Copy_Device_Title": " Kopier detaljer fra enhet", diff --git a/front/php/templates/language/pl_pl.json b/front/php/templates/language/pl_pl.json index 4296be57..2405799d 100755 --- a/front/php/templates/language/pl_pl.json +++ b/front/php/templates/language/pl_pl.json @@ -56,6 +56,8 @@ "BackDevices_Restore_okay": "Przywracanie wykonane z sukcesem.", "BackDevices_darkmode_disabled": "Tryb ciemny Wyłączony", "BackDevices_darkmode_enabled": "Tryb ciemny Włączony", + "CLEAR_NEW_FLAG_description": "", + "CLEAR_NEW_FLAG_name": "", "DAYS_TO_KEEP_EVENTS_description": "To jest ustawienie konserwacji. Określa ile dni mają być utrzymywane wpisy wydarzeń. Wszystkie starsze wpisy wydarzeń zostaną usunięte okresowo. Dotyczy także Historii Wydarzeń Pluginów.", "DAYS_TO_KEEP_EVENTS_name": "Usuń wydarzenia starsze niż", "DevDetail_Copy_Device_Title": "Kopiuj opis z urządzenia", diff --git a/front/php/templates/language/pt_br.json b/front/php/templates/language/pt_br.json index 148c2b39..96f497a3 100755 --- a/front/php/templates/language/pt_br.json +++ b/front/php/templates/language/pt_br.json @@ -56,6 +56,8 @@ "BackDevices_Restore_okay": "Restauração executada com sucesso.", "BackDevices_darkmode_disabled": "Modo Noturno Desabilitado", "BackDevices_darkmode_enabled": "Modo Noturno Habilitado", + "CLEAR_NEW_FLAG_description": "", + "CLEAR_NEW_FLAG_name": "", "DAYS_TO_KEEP_EVENTS_description": "Esta é uma definição de manutenção. Especifica o número de dias de entradas de eventos que serão mantidas. Todos os eventos mais antigos serão eliminados periodicamente. Também se aplica ao Histórico de eventos do plug-in.", "DAYS_TO_KEEP_EVENTS_name": "Excluir eventos mais antigos que", "DevDetail_Copy_Device_Title": " Copiar detalhes do dispositivo", diff --git a/front/php/templates/language/ru_ru.json b/front/php/templates/language/ru_ru.json index ec3b543a..716a3493 100755 --- a/front/php/templates/language/ru_ru.json +++ b/front/php/templates/language/ru_ru.json @@ -56,6 +56,8 @@ "BackDevices_Restore_okay": "Восстановление выполнено успешно.", "BackDevices_darkmode_disabled": "Темный режим отключен", "BackDevices_darkmode_enabled": "Темный режим включен", + "CLEAR_NEW_FLAG_description": "", + "CLEAR_NEW_FLAG_name": "", "DAYS_TO_KEEP_EVENTS_description": "Это настройка обслуживания. Здесь указывается количество дней, в течение которых будут храниться записи о событиях. Все старые события будут периодически удаляться. Также применимо к истории событий плагина.", "DAYS_TO_KEEP_EVENTS_name": "Удалить события старше", "DevDetail_Copy_Device_Title": " Скопировать данные с устройства", diff --git a/front/php/templates/language/tr_tr.json b/front/php/templates/language/tr_tr.json index 598d9e05..02d35a5f 100755 --- a/front/php/templates/language/tr_tr.json +++ b/front/php/templates/language/tr_tr.json @@ -56,6 +56,8 @@ "BackDevices_Restore_okay": "", "BackDevices_darkmode_disabled": "", "BackDevices_darkmode_enabled": "", + "CLEAR_NEW_FLAG_description": "", + "CLEAR_NEW_FLAG_name": "", "DAYS_TO_KEEP_EVENTS_description": "", "DAYS_TO_KEEP_EVENTS_name": "", "DevDetail_Copy_Device_Title": "", diff --git a/front/php/templates/language/zh_cn.json b/front/php/templates/language/zh_cn.json index 7423d098..ec16b547 100755 --- a/front/php/templates/language/zh_cn.json +++ b/front/php/templates/language/zh_cn.json @@ -56,6 +56,8 @@ "BackDevices_Restore_okay": "已成功恢复。", "BackDevices_darkmode_disabled": "暗黑模式已禁用", "BackDevices_darkmode_enabled": "已启用暗黑模式", + "CLEAR_NEW_FLAG_description": "", + "CLEAR_NEW_FLAG_name": "", "DAYS_TO_KEEP_EVENTS_description": "这是维护设置。它指定将保留的事件条目的天数。所有较旧的事件将被定期删除。也适用于插件事件历史记录。", "DAYS_TO_KEEP_EVENTS_name": "删除早于", "DevDetail_Copy_Device_Title": " 从设备复制详细信息", diff --git a/front/plugins/db_cleanup/script.py b/front/plugins/db_cleanup/script.py index d88a4d1b..c08fd269 100755 --- a/front/plugins/db_cleanup/script.py +++ b/front/plugins/db_cleanup/script.py @@ -44,12 +44,13 @@ def main(): HRS_TO_KEEP_NEWDEV = int(values.hourstokeepnewdevice.split('=')[1]) DAYS_TO_KEEP_EVENTS = int(values.daystokeepevents.split('=')[1]) PHOLUS_DAYS_DATA = get_setting_value("PHOLUS_DAYS_DATA") + CLEAR_NEW_FLAG = get_setting_value("CLEAR_NEW_FLAG") mylog('verbose', [f'[{pluginName}] In script']) # Execute cleanup/upkeep - cleanup_database(fullDbPath, DAYS_TO_KEEP_EVENTS, PHOLUS_DAYS_DATA, HRS_TO_KEEP_NEWDEV, PLUGINS_KEEP_HIST) + cleanup_database(fullDbPath, DAYS_TO_KEEP_EVENTS, PHOLUS_DAYS_DATA, HRS_TO_KEEP_NEWDEV, PLUGINS_KEEP_HIST, CLEAR_NEW_FLAG) mylog('verbose', [f'[{pluginName}] Cleanup complete']) @@ -58,7 +59,7 @@ def main(): #=============================================================================== # Cleanup / upkeep database #=============================================================================== -def cleanup_database (dbPath, DAYS_TO_KEEP_EVENTS, PHOLUS_DAYS_DATA, HRS_TO_KEEP_NEWDEV, PLUGINS_KEEP_HIST): +def cleanup_database (dbPath, DAYS_TO_KEEP_EVENTS, PHOLUS_DAYS_DATA, HRS_TO_KEEP_NEWDEV, PLUGINS_KEEP_HIST, CLEAR_NEW_FLAG): """ Cleaning out old records from the tables that don't need to keep all data. """ @@ -151,6 +152,17 @@ def cleanup_database (dbPath, DAYS_TO_KEEP_EVENTS, PHOLUS_DAYS_DATA, HRS_TO_KEEP mylog('verbose', [f'[{pluginName}] Query: {query} ']) cursor.execute (query) + # ----------------------------------------------------- + # Clear New Flag + if CLEAR_NEW_FLAG != 0: + mylog('verbose', [f'[{pluginName}] Devices: Clear "New Device" flag for all devices older than {str(CLEAR_NEW_FLAG)} hours (CLEAR_NEW_FLAG setting)']) + query = f"""UPDATE Devices SET dev_NewDevice = 0 WHERE dev_NewDevice = 1 AND date(dev_FirstConnection, '+{str(CLEAR_NEW_FLAG)} hour') < date('now')""" + # select * from Devices where dev_NewDevice = 1 AND date(dev_FirstConnection, '+3 hour' ) < date('now') + mylog('verbose', [f'[{pluginName}] Query: {query} ']) + cursor.execute(query) + + + # ----------------------------------------------------- # Cleanup Pholus_Scan if PHOLUS_DAYS_DATA != "" and PHOLUS_DAYS_DATA != 0: diff --git a/server/initialise.py b/server/initialise.py index feba2caf..f5c06590 100755 --- a/server/initialise.py +++ b/server/initialise.py @@ -145,6 +145,7 @@ def importConfigs (db, all_plugins): conf.REPORT_DASHBOARD_URL = ccd('REPORT_DASHBOARD_URL', 'http://netalertx/' , c_d, 'NetAlertX URL', '{"dataType":"string", "elements": [{"elementType" : "input", "elementOptions" : [] ,"transformers": []}]}', '[]', 'General') conf.DAYS_TO_KEEP_EVENTS = ccd('DAYS_TO_KEEP_EVENTS', 90 , c_d, 'Delete events days', '{"dataType":"integer", "elements": [{"elementType" : "input", "elementOptions" : [{"type": "number"}] ,"transformers": []}]}', '[]', 'General') conf.HRS_TO_KEEP_NEWDEV = ccd('HRS_TO_KEEP_NEWDEV', 0 , c_d, 'Keep new devices for', '{"dataType":"integer", "elements": [{"elementType" : "input", "elementOptions" : [{"type": "number"}] ,"transformers": []}]}', "[]", 'General') + conf.CLEAR_NEW_FLAG = ccd('CLEAR_NEW_FLAG', 0 , c_d, 'Clear new flag', '{"dataType":"integer", "elements": [{"elementType" : "input", "elementOptions" : [{"type": "number"}] ,"transformers": []}]}', "[]", 'General') conf.API_CUSTOM_SQL = ccd('API_CUSTOM_SQL', 'SELECT * FROM Devices WHERE dev_PresentLastScan = 0' , c_d, 'Custom endpoint', '{"dataType":"string", "elements": [{"elementType" : "input", "elementOptions" : [] ,"transformers": []}]}', '[]', 'General') conf.VERSION = ccd('VERSION', '' , c_d, 'Version', '{"dataType":"string", "elements": [{"elementType" : "input", "elementOptions" : [{ "readonly": "true" }] ,"transformers": []}]}', '', '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', '{"dataType":"array","elements":[{"elementType":"input","elementOptions":[{"placeholder":"Enter value"},{"suffix":"_in"},{"cssClasses":"col-sm-10"},{"prefillValue":"null"}],"transformers":[]},{"elementType":"button","elementOptions":[{"sourceSuffixes":["_in"]},{"separator":""},{"cssClasses":"col-xs-12"},{"onClick":"addList(this,false)"},{"getStringKey":"Gen_Add"}],"transformers":[]},{"elementType":"select", "elementHasInputValue":1,"elementOptions":[{"multiple":"true"},{"readonly":"true"},{"editable":"true"}],"transformers":[]},{"elementType":"button","elementOptions":[{"sourceSuffixes":[]},{"separator":""},{"cssClasses":"col-xs-6"},{"onClick":"removeAllOptions(this)"},{"getStringKey":"Gen_Remove_All"}],"transformers":[]},{"elementType":"button","elementOptions":[{"sourceSuffixes":[]},{"separator":""},{"cssClasses":"col-xs-6"},{"onClick":"removeFromList(this)"},{"getStringKey":"Gen_Remove_Last"}],"transformers":[]}]}', '[]', 'General')