This commit is contained in:
commit
aa92220756
2
.gitignore
vendored
2
.gitignore
vendored
@ -10,3 +10,5 @@ ignore/
|
|||||||
plugins/signatures.json
|
plugins/signatures.json
|
||||||
|
|
||||||
.venv/
|
.venv/
|
||||||
|
|
||||||
|
user_data/
|
3
main.py
3
main.py
@ -1040,6 +1040,9 @@ def settings():
|
|||||||
if success == None:
|
if success == None:
|
||||||
success = ""
|
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()
|
info = gitinfo.get_git_info()
|
||||||
branch = info['refs']
|
branch = info['refs']
|
||||||
if branch != "main":
|
if branch != "main":
|
||||||
|
26
plugin.py
26
plugin.py
@ -5,7 +5,6 @@ import sys
|
|||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def listPlugins():
|
def listPlugins():
|
||||||
plugins = []
|
plugins = []
|
||||||
for file in os.listdir("plugins"):
|
for file in os.listdir("plugins"):
|
||||||
@ -27,7 +26,7 @@ def listPlugins():
|
|||||||
# Write a new signatures file
|
# Write a new signatures file
|
||||||
with open("plugins/signatures.json", "w") as f:
|
with open("plugins/signatures.json", "w") as f:
|
||||||
json.dump(signatures, f)
|
json.dump(signatures, f)
|
||||||
|
|
||||||
for plugin in plugins:
|
for plugin in plugins:
|
||||||
# Hash the plugin file
|
# Hash the plugin file
|
||||||
pluginHash = hashPlugin(plugin["link"])
|
pluginHash = hashPlugin(plugin["link"])
|
||||||
@ -45,6 +44,7 @@ def pluginExists(plugin: str):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def verifyPlugin(plugin: str):
|
def verifyPlugin(plugin: str):
|
||||||
signatures = []
|
signatures = []
|
||||||
try:
|
try:
|
||||||
@ -73,12 +73,6 @@ def hashPlugin(plugin: str):
|
|||||||
break
|
break
|
||||||
sha256.update(data)
|
sha256.update(data)
|
||||||
return sha256.hexdigest()
|
return sha256.hexdigest()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def getPluginData(pluginStr: str):
|
def getPluginData(pluginStr: str):
|
||||||
@ -101,18 +95,20 @@ def getPluginData(pluginStr: str):
|
|||||||
info["verified"] = False
|
info["verified"] = False
|
||||||
else:
|
else:
|
||||||
info["verified"] = True
|
info["verified"] = True
|
||||||
|
|
||||||
return info
|
return info
|
||||||
|
|
||||||
|
|
||||||
def getPluginFunctions(plugin: str):
|
def getPluginFunctions(plugin: str):
|
||||||
plugin = importlib.import_module("plugins."+plugin)
|
plugin = importlib.import_module("plugins."+plugin)
|
||||||
return plugin.functions
|
return plugin.functions
|
||||||
|
|
||||||
|
|
||||||
def runPluginFunction(plugin: str, function: str, params: dict, authentication: str):
|
def runPluginFunction(plugin: str, function: str, params: dict, authentication: str):
|
||||||
plugin_module = importlib.import_module("plugins."+plugin)
|
plugin_module = importlib.import_module("plugins."+plugin)
|
||||||
if function not in plugin_module.functions:
|
if function not in plugin_module.functions:
|
||||||
return {"error": "Function not found"}
|
return {"error": "Function not found"}
|
||||||
|
|
||||||
if not hasattr(plugin_module, function):
|
if not hasattr(plugin_module, function):
|
||||||
return {"error": "Function not found"}
|
return {"error": "Function not found"}
|
||||||
|
|
||||||
@ -134,7 +130,6 @@ def runPluginFunction(plugin: str, function: str, params: dict, authentication:
|
|||||||
if pluginHash not in signatures:
|
if pluginHash not in signatures:
|
||||||
return {"error": "Plugin not verified"}
|
return {"error": "Plugin not verified"}
|
||||||
|
|
||||||
|
|
||||||
# Call the function with provided parameters
|
# Call the function with provided parameters
|
||||||
try:
|
try:
|
||||||
result = plugin_function(params, authentication)
|
result = plugin_function(params, authentication)
|
||||||
@ -144,14 +139,17 @@ def runPluginFunction(plugin: str, function: str, params: dict, authentication:
|
|||||||
return {"error": str(e)}
|
return {"error": str(e)}
|
||||||
# return plugin.runFunction(function, params, authentication)
|
# return plugin.runFunction(function, params, authentication)
|
||||||
|
|
||||||
|
|
||||||
def getPluginFunctionInputs(plugin: str, function: str):
|
def getPluginFunctionInputs(plugin: str, function: str):
|
||||||
plugin = importlib.import_module("plugins."+plugin)
|
plugin = importlib.import_module("plugins."+plugin)
|
||||||
return plugin.functions[function]["params"]
|
return plugin.functions[function]["params"]
|
||||||
|
|
||||||
|
|
||||||
def getPluginFunctionReturns(plugin: str, function: str):
|
def getPluginFunctionReturns(plugin: str, function: str):
|
||||||
plugin = importlib.import_module("plugins."+plugin)
|
plugin = importlib.import_module("plugins."+plugin)
|
||||||
return plugin.functions[function]["returns"]
|
return plugin.functions[function]["returns"]
|
||||||
|
|
||||||
|
|
||||||
def getDomainFunctions():
|
def getDomainFunctions():
|
||||||
plugins = listPlugins()
|
plugins = listPlugins()
|
||||||
domainFunctions = []
|
domainFunctions = []
|
||||||
@ -166,6 +164,7 @@ def getDomainFunctions():
|
|||||||
})
|
})
|
||||||
return domainFunctions
|
return domainFunctions
|
||||||
|
|
||||||
|
|
||||||
def getSearchFunctions():
|
def getSearchFunctions():
|
||||||
plugins = listPlugins()
|
plugins = listPlugins()
|
||||||
searchFunctions = []
|
searchFunctions = []
|
||||||
@ -180,6 +179,7 @@ def getSearchFunctions():
|
|||||||
})
|
})
|
||||||
return searchFunctions
|
return searchFunctions
|
||||||
|
|
||||||
|
|
||||||
def getDashboardFunctions():
|
def getDashboardFunctions():
|
||||||
plugins = listPlugins()
|
plugins = listPlugins()
|
||||||
dashboardFunctions = []
|
dashboardFunctions = []
|
||||||
@ -192,4 +192,4 @@ def getDashboardFunctions():
|
|||||||
"function": function,
|
"function": function,
|
||||||
"description": functions[function]["description"]
|
"description": functions[function]["description"]
|
||||||
})
|
})
|
||||||
return dashboardFunctions
|
return dashboardFunctions
|
||||||
|
@ -34,6 +34,45 @@ functions = {
|
|||||||
"type": "text"
|
"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):
|
def automation(params, authentication):
|
||||||
global started
|
global started
|
||||||
|
|
||||||
|
wallet = authentication.split(":")[0]
|
||||||
|
if os.path.exists(f"user_data/{wallet}.autoRenew"):
|
||||||
|
return {"Status": "Automations disabled"}
|
||||||
|
|
||||||
if started:
|
if started:
|
||||||
return {"Status": "Auto Renews running"}
|
return {"Status": "Automations running"}
|
||||||
started = True
|
started = True
|
||||||
|
|
||||||
threading.Thread(target=automations_background, args=(authentication,)).start()
|
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(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):
|
||||||
|
# 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
|
# Background function to run the automations
|
||||||
def automations_background(authentication):
|
def automations_background(authentication):
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
print("Running automations")
|
|
||||||
# Get account details
|
# Get account details
|
||||||
account_name = account.check_account(authentication)
|
account_name = account.check_account(authentication)
|
||||||
password = ":".join(authentication.split(":")[1:])
|
password = ":".join(authentication.split(":")[1:])
|
||||||
@ -63,13 +129,18 @@ def automations_background(authentication):
|
|||||||
"message": "Invalid account"
|
"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:
|
||||||
# Try to select and login to the wallet
|
# Try to select and login to the wallet
|
||||||
response = account.hsw.rpc_selectWallet(account_name)
|
response = account.hsw.rpc_selectWallet(account_name)
|
||||||
if response['error'] is not None:
|
if response['error'] is not None:
|
||||||
return
|
return
|
||||||
response = account.hsw.rpc_walletPassphrase(password,10)
|
response = account.hsw.rpc_walletPassphrase(password,30)
|
||||||
if response['error'] is not None:
|
if response['error'] is not None:
|
||||||
return
|
return
|
||||||
# Try to send the batch of all renew, reveal and redeem actions
|
# Try to send the batch of all renew, reveal and redeem actions
|
||||||
|
Loading…
Reference in New Issue
Block a user