mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
🔃 Sync Hub v0.6
This commit is contained in:
@@ -860,6 +860,7 @@ def collect_lang_strings(json, pref, stringSqlParams):
|
|||||||
# return decrypted_data
|
# return decrypted_data
|
||||||
|
|
||||||
# pycryptodome -------------------------------------------------------------------------
|
# pycryptodome -------------------------------------------------------------------------
|
||||||
|
|
||||||
def prepare_key(encryption_key):
|
def prepare_key(encryption_key):
|
||||||
key = hashlib.sha256(encryption_key.encode()).digest()
|
key = hashlib.sha256(encryption_key.encode()).digest()
|
||||||
return key
|
return key
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from collections import namedtuple
|
|||||||
import conf
|
import conf
|
||||||
from const import pluginsPath, logPath, applicationPath, reportTemplatesPath
|
from const import pluginsPath, logPath, applicationPath, reportTemplatesPath
|
||||||
from logger import mylog
|
from logger import mylog
|
||||||
from helper import timeNowTZ, updateState, get_file_content, write_file, get_setting, get_setting_value
|
from helper import timeNowTZ, updateState, get_file_content, write_file, get_setting, get_setting_value, decrypt_data
|
||||||
from api import update_api
|
from api import update_api
|
||||||
from plugin_utils import logEventStatusCounts, get_plugin_string, get_plugin_setting_obj, print_plugin_info, list_to_csv, combine_plugin_objects, resolve_wildcards_arr, handle_empty, custom_plugin_decoder
|
from plugin_utils import logEventStatusCounts, get_plugin_string, get_plugin_setting_obj, print_plugin_info, list_to_csv, combine_plugin_objects, resolve_wildcards_arr, handle_empty, custom_plugin_decoder
|
||||||
from notification import Notification_obj
|
from notification import Notification_obj
|
||||||
@@ -225,12 +225,47 @@ def execute_plugin(db, all_plugins, plugin, pluginsState = plugins_state() ):
|
|||||||
newLines = []
|
newLines = []
|
||||||
|
|
||||||
# Create the file path
|
# Create the file path
|
||||||
file_path = os.path.join(pluginsPath, plugin["code_name"], 'last_result.log')
|
file_dir = os.path.join(pluginsPath, plugin["code_name"])
|
||||||
|
file_prefix = 'last_result'
|
||||||
|
|
||||||
|
# key to decrypt data if available
|
||||||
|
encryption_key = get_setting_value('SYNC_encryption_key')
|
||||||
|
|
||||||
|
# Check for files starting with the specified prefix
|
||||||
|
matching_files = [f for f in os.listdir(file_dir) if f.startswith(file_prefix)]
|
||||||
|
|
||||||
|
for filename in matching_files:
|
||||||
|
# Create the full file path
|
||||||
|
file_path = os.path.join(file_dir, filename)
|
||||||
|
|
||||||
# Check if the file exists
|
# Check if the file exists
|
||||||
if os.path.exists(file_path):
|
if os.path.exists(file_path):
|
||||||
# File exists, open it and read its contents
|
|
||||||
|
# Check if the file name contains "encoded"
|
||||||
|
if '.encoded.' in filename and encryption_key != '':
|
||||||
|
|
||||||
|
# Decrypt the entire file
|
||||||
with open(file_path, 'r+') as f:
|
with open(file_path, 'r+') as f:
|
||||||
|
encrypted_data = f.read()
|
||||||
|
decrypted_data = decrypt_data(encrypted_data, encryption_key)
|
||||||
|
|
||||||
|
# Write the decrypted data back to the file
|
||||||
|
f.seek(0)
|
||||||
|
f.write(decrypted_data)
|
||||||
|
f.truncate()
|
||||||
|
|
||||||
|
# Rename the file
|
||||||
|
new_filename = filename.replace('.encoded.', '.decoded.')
|
||||||
|
os.rename(file_path, os.path.join(file_dir, new_filename))
|
||||||
|
|
||||||
|
elif filename == 'last_result.log' :
|
||||||
|
new_filename = filename
|
||||||
|
else:
|
||||||
|
# skipping decoded and other files
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Open the decrypted file and process its contents
|
||||||
|
with open(os.path.join(file_dir, new_filename), 'r') as f:
|
||||||
newLines = f.read().split('\n')
|
newLines = f.read().split('\n')
|
||||||
|
|
||||||
# if the script produced some outpout, clean it up to ensure it's the correct format
|
# if the script produced some outpout, clean it up to ensure it's the correct format
|
||||||
@@ -267,6 +302,10 @@ def execute_plugin(db, all_plugins, plugin, pluginsState = plugins_state() ):
|
|||||||
else:
|
else:
|
||||||
mylog('debug', [f'[Plugins] The file {file_path} does not exist'])
|
mylog('debug', [f'[Plugins] The file {file_path} does not exist'])
|
||||||
|
|
||||||
|
# TODO: delete processed files
|
||||||
|
# os.rename(file_path, os.path.join(file_dir, new_filename))
|
||||||
|
|
||||||
|
|
||||||
# app-db-query
|
# app-db-query
|
||||||
if plugin['data_source'] == 'app-db-query':
|
if plugin['data_source'] == 'app-db-query':
|
||||||
# replace single quotes wildcards
|
# replace single quotes wildcards
|
||||||
|
|||||||
Reference in New Issue
Block a user