feat: Add automation plugin
All checks were successful
Build Docker / Build Image (push) Successful in 23s

This commit is contained in:
Nathan Woodburn 2024-02-12 21:53:17 +11:00
parent 360ca7bfe9
commit 4f163756de
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
2 changed files with 83 additions and 21 deletions

View File

@ -63,32 +63,13 @@ def verifyPlugin(plugin: str):
def hashPlugin(plugin: str): def hashPlugin(plugin: str):
BUF_SIZE = 65536 BUF_SIZE = 65536
# Initializing the sha256() method
sha256 = hashlib.sha256() sha256 = hashlib.sha256()
# Opening the file provided as the first
# commandline argument
with open("plugins/"+plugin+".py", 'rb') as f: with open("plugins/"+plugin+".py", 'rb') as f:
while True: while True:
# reading data = BUF_SIZE from the
# file and saving it in a variable
data = f.read(BUF_SIZE) data = f.read(BUF_SIZE)
# True if eof = 1
if not data: if not data:
break break
# Passing that data to that sh256 hash
# function (updating the function with that data)
sha256.update(data) sha256.update(data)
# sha256.hexdigest() hashes all the input data passed
# to the sha256() via sha256.update()
# Acts as a finalize method, after which
# all the input data gets hashed
# hexdigest() hashes the data, and returns
# the output in hexadecimal format
return sha256.hexdigest() return sha256.hexdigest()
@ -114,8 +95,6 @@ def getPluginData(pluginStr: str):
info = plugin.info info = plugin.info
# Hash the plugin file # Hash the plugin file
pluginHash = hashPlugin(pluginStr) pluginHash = hashPlugin(pluginStr)
print(pluginHash)
print(signatures)
if pluginHash not in signatures: if pluginHash not in signatures:
info["verified"] = False info["verified"] = False
else: else:

83
plugins/automations.py Normal file
View File

@ -0,0 +1,83 @@
import json
import account
import requests
import threading
import os
import datetime
APIKEY = os.environ.get("hsd_api")
ip = os.getenv("hsd_ip")
if ip is None:
ip = "localhost"
# Plugin Data
info = {
"name": "Automations",
"description": "This plugin will automatically renew domains, reveal and redeem bids.",
"version": "1.0",
"author": "Nathan.Woodburn/"
}
# Functions
functions = {
"automation":{
"name": "Function to automate",
"type": "dashboard",
"description": "This used type dashboard to trigger the function whenever you access the dashboard.",
"params": {},
"returns": {
"Status":
{
"name": "Status of the automation",
"type": "text"
}
}
}
}
started = 0
# Main entry point only lets the main function run every 5 mins
def automation(params, authentication):
global started
now = datetime.datetime.now().timestamp()
# Add 5 mins
now = now - 300
if now < started:
return {"Status": "Waiting before checking for new actions"}
started = datetime.datetime.now().timestamp()
threading.Thread(target=automations_background, args=(authentication,)).start()
return {"Status": "Checking for actions"}
# Background function to run the automations
def automations_background(authentication):
print("Running automations")
# Get account details
account_name = account.check_account(authentication)
password = ":".join(authentication.split(":")[1:])
if account_name == False:
return {
"error": {
"message": "Invalid account"
}
}
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)
if response['error'] is not None:
return
# Try to send the batch of all renew, reveal and redeem actions
response = requests.post(f"http://x:{APIKEY}@{ip}:12039",json={
"method": "sendbatch",
"params": [[["RENEW"], ["REVEAL"], ["REDEEM"]]]
}).json()
print(response)
except Exception as e:
print(e)