🔃 Sync Hub v0.4
This commit is contained in:
@@ -14,7 +14,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"])
|
||||
from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64
|
||||
from plugin_utils import get_plugins_configs
|
||||
from logger import mylog
|
||||
from helper import timeNowTZ, get_setting_value
|
||||
from helper import timeNowTZ, get_setting_value, encrypt_data
|
||||
|
||||
# Define the current path and log file paths
|
||||
CUR_PATH = str(pathlib.Path(__file__).parent.resolve())
|
||||
@@ -23,12 +23,6 @@ RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log')
|
||||
|
||||
pluginName = 'SYNC'
|
||||
|
||||
# Function to encrypt data using a password
|
||||
def encrypt_data(data, password):
|
||||
key = hashlib.sha256(password.encode()).digest()
|
||||
cipher = hashlib.pbkdf2_hmac('sha256', data.encode(), key, 100000)
|
||||
return cipher.hex()
|
||||
|
||||
def main():
|
||||
mylog('verbose', [f'[{pluginName}] In script'])
|
||||
|
||||
@@ -38,7 +32,8 @@ def main():
|
||||
|
||||
# Retrieve configuration settings
|
||||
plugins_to_sync = get_setting_value('SYNC_plugins')
|
||||
api_token = get_setting_value('SYNC_api_token') # Use an API token instead of a password
|
||||
api_token = get_setting_value('SYNC_api_token')
|
||||
encryption_key = get_setting_value('SYNC_encryption_key')
|
||||
hub_url = get_setting_value('SYNC_hub_url')
|
||||
node_name = get_setting_value('SYNC_node_name')
|
||||
|
||||
@@ -63,9 +58,14 @@ def main():
|
||||
if os.path.exists(file_path):
|
||||
# Read the content of the log file
|
||||
with open(file_path, 'r') as f:
|
||||
newLines = f.read()
|
||||
# Encrypt the log data using the API token
|
||||
encrypted_data = encrypt_data(newLines, api_token)
|
||||
file_content = f.read()
|
||||
|
||||
mylog('verbose', [f'[{pluginName}] Sending file_content: "{file_content}"'])
|
||||
|
||||
# Encrypt the log data using the encryption_key
|
||||
encrypted_data = encrypt_data(file_content, encryption_key)
|
||||
|
||||
mylog('verbose', [f'[{pluginName}] Sending encrypted_data: "{encrypted_data}"'])
|
||||
|
||||
# Prepare the data payload for the POST request
|
||||
data = {
|
||||
@@ -84,7 +84,7 @@ def main():
|
||||
if response.status_code == 200:
|
||||
mylog('verbose', [f'[{pluginName}] Data for "{plugin_folder}" sent successfully'])
|
||||
else:
|
||||
mylog('error', [f'[{pluginName}] Failed to send data for "{plugin_folder}"'])
|
||||
mylog('verbose', [f'[{pluginName}] Failed to send data for "{plugin_folder}"'])
|
||||
|
||||
# log result
|
||||
plugin_objects.add_object(
|
||||
|
||||
Reference in New Issue
Block a user