From 864f0904f5d7aebb6d2ae1e11bea4aca251fbf4e Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Mon, 1 Aug 2022 19:34:35 +0100 Subject: [PATCH] Implement automatic provisioning --- api/views.py | 20 ++++++++++++++++++-- modules/provision.py | 1 - 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/api/views.py b/api/views.py index ba45d7a..5b6b5c2 100644 --- a/api/views.py +++ b/api/views.py @@ -5,7 +5,7 @@ from klein import Klein from twisted.web.server import Request import main -from modules import chankeep, userinfo +from modules import chankeep, provision, userinfo from utils.logging.log import warn @@ -396,10 +396,26 @@ class API(object): if alias not in main.alias.keys(): return dumps({"success": False, "reason": "alias does not exist."}) if fields: - main.alias[alias] = fields + for field in fields: + if field in main.alias[alias]: + main.alias[alias][field] = fields[field] if "emails" in fields: if not fields["emails"]: main.alias[alias]["emails"] = [] main.saveConf("alias") return dumps({"success": True}) + + @app.route("/irc/auto//", methods=["POST"]) + @login_required + def irc_auto_network(self, request, net): + print(repr(main.network[net].relays.keys())) + if net not in main.network.keys(): + return dumps({"success": False, "reason": "no such net."}) + if 1 in main.network[net].relays.keys(): + return dumps({"success": False, "reason": f"First relay exists on {net}"}) + num, alias = main.network[net].add_relay(1) + provision.provisionRelay(num, net) + main.saveConf("network") + + return dumps({"success": True, f"message": "Created relay {num} with alias {alias} on {net}"}) diff --git a/modules/provision.py b/modules/provision.py index e1e740e..6681a78 100644 --- a/modules/provision.py +++ b/modules/provision.py @@ -63,7 +63,6 @@ def provisionAuthenticationData(num, nick, network, security, auth, password): def provisionRelay(num, network): # provision user and network data aliasObj = main.alias[num] - print("ALIASOBJ FALUES", aliasObj.values()) # alias = aliasObj["nick"] provisionUserNetworkData( num,