feat: Finish v1 of plugins
All checks were successful
Build Docker / Build Image (push) Successful in 32s
All checks were successful
Build Docker / Build Image (push) Successful in 32s
This commit is contained in:
164
main.py
164
main.py
@@ -11,6 +11,7 @@ from flask_qrcode import QRcode
|
||||
import domainLookup
|
||||
import urllib.parse
|
||||
import importlib
|
||||
import plugin as plugins_module
|
||||
|
||||
dotenv.load_dotenv()
|
||||
|
||||
@@ -91,10 +92,17 @@ def index():
|
||||
domain_count = len(domains)
|
||||
domains = render.domains(domains)
|
||||
|
||||
plugins = ""
|
||||
dashFunctions = plugins_module.getDashboardFunctions()
|
||||
for function in dashFunctions:
|
||||
functionOutput = plugins_module.runPluginFunction(function["plugin"],function["function"],{},account_module.check_account(request.cookies.get("account")))
|
||||
plugins += render.plugin_output_dash(functionOutput,plugins_module.getPluginFunctionReturns(function["plugin"],function["function"]))
|
||||
|
||||
|
||||
|
||||
|
||||
return render_template("index.html", account=account, available=available,
|
||||
total=total, pending=pending, domains=domains,
|
||||
total=total, pending=pending, domains=domains, plugins=plugins,
|
||||
domain_count=domain_count, sync=account_module.getNodeSync(),
|
||||
sort_price=sort_price,sort_expiry=sort_expiry,
|
||||
sort_domain=sort_domain,sort_price_next=sort_price_next,
|
||||
@@ -320,10 +328,20 @@ def search():
|
||||
|
||||
dns = render.dns(dns)
|
||||
txs = render.txs(txs)
|
||||
|
||||
plugins = "<div class='container-fluid'>"
|
||||
# Execute domain plugins
|
||||
searchFunctions = plugins_module.getSearchFunctions()
|
||||
for function in searchFunctions:
|
||||
functionOutput = plugins_module.runPluginFunction(function["plugin"],function["function"],{"domain":search_term},account_module.check_account(request.cookies.get("account")))
|
||||
plugins += render.plugin_output(functionOutput,plugins_module.getPluginFunctionReturns(function["plugin"],function["function"]))
|
||||
|
||||
plugins += "</div>"
|
||||
|
||||
return render_template("search.html", account=account, sync=account_module.getNodeSync(),
|
||||
search_term=search_term,domain=domain['info']['name'],
|
||||
raw=domain,state=state, next=next, owner=owner,
|
||||
dns=dns, txs=txs)
|
||||
dns=dns, txs=txs,plugins=plugins)
|
||||
|
||||
@app.route('/manage/<domain>')
|
||||
def manage(domain: str):
|
||||
@@ -373,20 +391,11 @@ def manage(domain: str):
|
||||
|
||||
plugins = "<div class='container-fluid'>"
|
||||
# Execute domain plugins
|
||||
plugin_links = os.listdir("plugins")
|
||||
for plugin in plugin_links:
|
||||
if os.path.isdir("plugins/" + plugin):
|
||||
module = importlib.import_module("plugins." + plugin + ".main")
|
||||
moduleFunctions = module.listFunctions()
|
||||
for moduleFunction in moduleFunctions:
|
||||
data = moduleFunctions[moduleFunction]
|
||||
if "type" in data:
|
||||
if data["type"] == "domain":
|
||||
# Run function
|
||||
print(data)
|
||||
functionOutput = module.runFunction(moduleFunction,{"domain":domain},account_module.check_account(request.cookies.get("account")))
|
||||
print(functionOutput)
|
||||
plugins += render.plugin_output(functionOutput,data['returns'])
|
||||
domainFunctions = plugins_module.getDomainFunctions()
|
||||
for function in domainFunctions:
|
||||
functionOutput = plugins_module.runPluginFunction(function["plugin"],function["function"],{"domain":domain},account_module.check_account(request.cookies.get("account")))
|
||||
plugins += render.plugin_output(functionOutput,plugins_module.getPluginFunctionReturns(function["plugin"],function["function"]))
|
||||
|
||||
plugins += "</div>"
|
||||
|
||||
|
||||
@@ -1053,21 +1062,7 @@ def plugins_index():
|
||||
if not account:
|
||||
return redirect("/logout")
|
||||
|
||||
plugin_links = os.listdir("plugins")
|
||||
plugins = []
|
||||
for plugin in plugin_links:
|
||||
if os.path.isdir("plugins/" + plugin):
|
||||
if os.path.isfile("plugins/" + plugin + "/"+plugin+".json"):
|
||||
with open("plugins/" + plugin + "/"+plugin+".json") as f:
|
||||
data = json.load(f)
|
||||
data['link'] = plugin
|
||||
if 'name' not in data:
|
||||
data['name'] = plugin
|
||||
if 'description' not in data:
|
||||
data['description'] = "No description provided"
|
||||
plugins.append(data)
|
||||
|
||||
plugins = render.plugins(plugins)
|
||||
plugins = render.plugins(plugins_module.listPlugins())
|
||||
|
||||
return render_template("plugins.html", account=account, sync=account_module.getNodeSync(),
|
||||
plugins=plugins)
|
||||
@@ -1082,37 +1077,22 @@ def plugin(plugin):
|
||||
if not account:
|
||||
return redirect("/logout")
|
||||
|
||||
if not os.path.isdir("plugins/" + plugin):
|
||||
if not plugins_module.pluginExists(plugin):
|
||||
return redirect("/plugins")
|
||||
|
||||
if not os.path.isfile("plugins/" + plugin + "/"+plugin+".json"):
|
||||
return redirect("/plugins")
|
||||
data = plugins_module.getPluginData(plugin)
|
||||
|
||||
with open("plugins/" + plugin + "/"+plugin+".json") as f:
|
||||
data = json.load(f)
|
||||
data['link'] = plugin
|
||||
if 'name' not in data:
|
||||
data['name'] = plugin
|
||||
if 'description' not in data:
|
||||
data['description'] = "No description provided"
|
||||
|
||||
|
||||
functions = []
|
||||
|
||||
if os.path.isfile("plugins/" + plugin + "/main.py"):
|
||||
# Get plugin/main.py listfunctions()
|
||||
print("Loading plugin: " + plugin)
|
||||
module = importlib.import_module("plugins." + plugin + ".main")
|
||||
functions = module.listFunctions()
|
||||
functions = render.plugin_functions(functions,plugin)
|
||||
functions = plugins_module.getPluginFunctions(plugin)
|
||||
functions = render.plugin_functions(functions,plugin)
|
||||
|
||||
error = request.args.get("error")
|
||||
if error == None:
|
||||
error = ""
|
||||
|
||||
return render_template("plugin.html", account=account, sync=account_module.getNodeSync(),
|
||||
name=data['name'],description=data['description'],functions=functions,
|
||||
error=error)
|
||||
name=data['name'],description=data['description'],
|
||||
author=data['author'],version=data['version'],
|
||||
functions=functions,error=error)
|
||||
|
||||
@app.route('/plugin/<plugin>/<function>', methods=["POST"])
|
||||
def plugin_function(plugin,function):
|
||||
@@ -1124,59 +1104,45 @@ def plugin_function(plugin,function):
|
||||
if not account:
|
||||
return redirect("/logout")
|
||||
|
||||
if not os.path.isdir("plugins/" + plugin):
|
||||
if not plugins_module.pluginExists(plugin):
|
||||
return redirect("/plugins")
|
||||
|
||||
if not os.path.isfile("plugins/" + plugin + "/"+plugin+".json"):
|
||||
return redirect("/plugins")
|
||||
data = plugins_module.getPluginData(plugin)
|
||||
|
||||
with open("plugins/" + plugin + "/"+plugin+".json") as f:
|
||||
data = json.load(f)
|
||||
data['link'] = plugin
|
||||
if 'name' not in data:
|
||||
data['name'] = plugin
|
||||
if 'description' not in data:
|
||||
data['description'] = "No description provided"
|
||||
|
||||
if os.path.isfile("plugins/" + plugin + "/main.py"):
|
||||
# Get plugin/main.py listfunctions()
|
||||
print("Loading plugin: " + plugin)
|
||||
module = importlib.import_module("plugins." + plugin + ".main")
|
||||
if function in module.listFunctions():
|
||||
inputs = module.listFunctions()[function]["params"]
|
||||
request_data = {}
|
||||
for input in inputs:
|
||||
request_data[input] = request.form.get(input)
|
||||
|
||||
if inputs[input]['type'] == "address":
|
||||
# Handle hip2
|
||||
address_check = account_module.check_address(request_data[input],True,True)
|
||||
if not address_check:
|
||||
return redirect("/plugin/" + plugin + "?error=Invalid address")
|
||||
request_data[input] = address_check
|
||||
elif inputs[input]['type'] == "dns":
|
||||
# Handle URL encoding of DNS
|
||||
request_data[input] = urllib.parse.unquote(request_data[input])
|
||||
|
||||
|
||||
|
||||
|
||||
response = module.runFunction(function,request_data,request.cookies.get("account"))
|
||||
if not response:
|
||||
return redirect("/plugin/" + plugin + "?error=An error occurred")
|
||||
if 'error' in response:
|
||||
return redirect("/plugin/" + plugin + "?error=" + response['error'])
|
||||
# Get plugin/main.py listfunctions()
|
||||
if function in plugins_module.getPluginFunctions(plugin):
|
||||
inputs = plugins_module.getPluginFunctionInputs(plugin,function)
|
||||
request_data = {}
|
||||
for input in inputs:
|
||||
request_data[input] = request.form.get(input)
|
||||
|
||||
response = render.plugin_output(response,module.listFunctions()[function]["returns"])
|
||||
|
||||
return render_template("plugin-output.html", account=account, sync=account_module.getNodeSync(),
|
||||
name=data['name'],description=data['description'],output=response)
|
||||
if inputs[input]['type'] == "address":
|
||||
# Handle hip2
|
||||
address_check = account_module.check_address(request_data[input],True,True)
|
||||
if not address_check:
|
||||
return redirect("/plugin/" + plugin + "?error=Invalid address")
|
||||
request_data[input] = address_check
|
||||
elif inputs[input]['type'] == "dns":
|
||||
# Handle URL encoding of DNS
|
||||
request_data[input] = urllib.parse.unquote(request_data[input])
|
||||
|
||||
|
||||
else:
|
||||
return jsonify({"error": "Function not found"})
|
||||
|
||||
return jsonify({"error": "Plugin not found"})
|
||||
|
||||
response = plugins_module.runPluginFunction(plugin,function,request_data,request.cookies.get("account"))
|
||||
if not response:
|
||||
return redirect("/plugin/" + plugin + "?error=An error occurred")
|
||||
if 'error' in response:
|
||||
return redirect("/plugin/" + plugin + "?error=" + response['error'])
|
||||
|
||||
response = render.plugin_output(response,plugins_module.getPluginFunctionReturns(plugin,function))
|
||||
|
||||
return render_template("plugin-output.html", account=account, sync=account_module.getNodeSync(),
|
||||
name=data['name'],description=data['description'],output=response)
|
||||
|
||||
|
||||
else:
|
||||
return jsonify({"error": "Function not found"})
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user