From 3e787323331e01258ed9619fdbb260ff57ffb824 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 21 Nov 2024 16:30:44 +1100 Subject: [PATCH 1/4] fix: Check if .git dir exists before trying to read it --- main.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main.py b/main.py index f039e08..18abf79 100644 --- a/main.py +++ b/main.py @@ -1040,6 +1040,9 @@ def settings(): if success == None: success = "" + if not os.path.exists(".git"): + return render_template("settings.html", account=account,sync=account_module.getNodeSync(), + error=error,success=success,version="Error") info = gitinfo.get_git_info() branch = info['refs'] if branch != "main": From 9f1f7fb18e861b483010416b339eef0286b36466 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 21 Nov 2024 19:30:19 +1100 Subject: [PATCH 2/4] feat: Add wallet blacklisting to automations plugin --- .gitignore | 2 + plugins/automations.py | 83 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 79 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 397f345..33a7451 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ ignore/ plugins/signatures.json .venv/ + +user_data/ \ No newline at end of file diff --git a/plugins/automations.py b/plugins/automations.py index 9324224..584f9fb 100644 --- a/plugins/automations.py +++ b/plugins/automations.py @@ -34,6 +34,45 @@ functions = { "type": "text" } } + }, + "disable":{ + "name": "Disable Automations", + "type": "default", + "description": "Disable Automations for this wallet", + "params": {}, + "returns": { + "Status": + { + "name": "Status", + "type": "text" + } + } + }, + "enable":{ + "name": "Enable Automations", + "type": "default", + "description": "Enable Automations for this wallet", + "params": {}, + "returns": { + "Status": + { + "name": "Status", + "type": "text" + } + } + }, + "list":{ + "name": "List Disabled Wallets", + "type": "default", + "description": "List wallets with automations disabled", + "params": {}, + "returns": { + "wallets": + { + "name": "List of wallets", + "type": "list" + } + } } } @@ -43,16 +82,43 @@ started = False def automation(params, authentication): global started + wallet = authentication.split(":")[0] + if os.path.exists(f"user_data/{wallet}.autoRenew"): + return {"Status": "Automations disabled"} + if started: - return {"Status": "Auto Renews running"} - started = True + return {"Status": "Automations running"} + started = True + threading.Thread(target=automations_background, args=(authentication,)).start() - return {"Status": "Started Auto Renews"} + return {"Status": "Starting Automations..."} + +def disable(params, authentication): + # Create walletname file in user_data + wallet = authentication.split(":")[0] + with open(f"user_data/{wallet}.autoRenew", "w") as f: + f.write("disabled") + return {"Status": "Disabled Automations"} + +def enable(params, authentication): + # Delete walletname file in user_data + wallet = authentication.split(":")[0] + if os.path.exists(f"user_data/{wallet}.autoRenew"): + os.remove(f"user_data/{wallet}.autoRenew") + + return {"Status": "Enabled Automations"} + +def list(params, authentication): + wallets = [] + for file in os.listdir("user_data"): + if file.endswith(".autoRenew"): + wallets.append(file[:-10]) + return {"wallets": wallets} # Background function to run the automations def automations_background(authentication): + while True: - print("Running automations") # Get account details account_name = account.check_account(authentication) password = ":".join(authentication.split(":")[1:]) @@ -63,13 +129,18 @@ def automations_background(authentication): "message": "Invalid account" } } - + + if os.path.exists(f"user_data/{account_name}.autoRenew"): + print("Skipping Automations") + time.sleep(300) + continue + print("Running automations") try: # Try to select and login to the wallet response = account.hsw.rpc_selectWallet(account_name) if response['error'] is not None: return - response = account.hsw.rpc_walletPassphrase(password,10) + response = account.hsw.rpc_walletPassphrase(password,30) if response['error'] is not None: return # Try to send the batch of all renew, reveal and redeem actions From 40f520ba5e091f35dec8bf5c62a0ac5c8fbb8746 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 21 Nov 2024 19:33:10 +1100 Subject: [PATCH 3/4] feat: Updated automations blacklist file to make it clearer --- plugins/automations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/automations.py b/plugins/automations.py index 584f9fb..a85e9b5 100644 --- a/plugins/automations.py +++ b/plugins/automations.py @@ -97,7 +97,7 @@ def disable(params, authentication): # Create walletname file in user_data wallet = authentication.split(":")[0] with open(f"user_data/{wallet}.autoRenew", "w") as f: - f.write("disabled") + f.write(f"This file is used to disable automations for '{wallet}' wallet.\nDelete this file to enable automations.") return {"Status": "Disabled Automations"} def enable(params, authentication): From 3290240a25c92af0aa2fe75fb26605711842937b Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 21 Nov 2024 19:35:33 +1100 Subject: [PATCH 4/4] fix: Cleanup plugin.py --- plugin.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/plugin.py b/plugin.py index 659c43e..c2d5edc 100644 --- a/plugin.py +++ b/plugin.py @@ -5,7 +5,6 @@ import sys import hashlib - def listPlugins(): plugins = [] for file in os.listdir("plugins"): @@ -27,7 +26,7 @@ def listPlugins(): # Write a new signatures file with open("plugins/signatures.json", "w") as f: json.dump(signatures, f) - + for plugin in plugins: # Hash the plugin file pluginHash = hashPlugin(plugin["link"]) @@ -45,6 +44,7 @@ def pluginExists(plugin: str): return True return False + def verifyPlugin(plugin: str): signatures = [] try: @@ -73,12 +73,6 @@ def hashPlugin(plugin: str): break sha256.update(data) return sha256.hexdigest() - - - - - - def getPluginData(pluginStr: str): @@ -101,18 +95,20 @@ def getPluginData(pluginStr: str): info["verified"] = False else: info["verified"] = True - - return info + + return info + def getPluginFunctions(plugin: str): plugin = importlib.import_module("plugins."+plugin) return plugin.functions + def runPluginFunction(plugin: str, function: str, params: dict, authentication: str): plugin_module = importlib.import_module("plugins."+plugin) if function not in plugin_module.functions: return {"error": "Function not found"} - + if not hasattr(plugin_module, function): return {"error": "Function not found"} @@ -134,7 +130,6 @@ def runPluginFunction(plugin: str, function: str, params: dict, authentication: if pluginHash not in signatures: return {"error": "Plugin not verified"} - # Call the function with provided parameters try: result = plugin_function(params, authentication) @@ -144,14 +139,17 @@ def runPluginFunction(plugin: str, function: str, params: dict, authentication: return {"error": str(e)} # return plugin.runFunction(function, params, authentication) + def getPluginFunctionInputs(plugin: str, function: str): plugin = importlib.import_module("plugins."+plugin) return plugin.functions[function]["params"] + def getPluginFunctionReturns(plugin: str, function: str): plugin = importlib.import_module("plugins."+plugin) return plugin.functions[function]["returns"] + def getDomainFunctions(): plugins = listPlugins() domainFunctions = [] @@ -166,6 +164,7 @@ def getDomainFunctions(): }) return domainFunctions + def getSearchFunctions(): plugins = listPlugins() searchFunctions = [] @@ -180,6 +179,7 @@ def getSearchFunctions(): }) return searchFunctions + def getDashboardFunctions(): plugins = listPlugins() dashboardFunctions = [] @@ -192,4 +192,4 @@ def getDashboardFunctions(): "function": function, "description": functions[function]["description"] }) - return dashboardFunctions \ No newline at end of file + return dashboardFunctions