From 8050484b6f3057ccc52cee678594a4f9402ab0a5 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Wed, 27 Jul 2022 08:59:17 +0100 Subject: [PATCH] Implement editing networks via the API --- api/views.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/api/views.py b/api/views.py index 38566e0..8b56948 100644 --- a/api/views.py +++ b/api/views.py @@ -209,6 +209,45 @@ class API(object): network["records"] = userinfo.getNumWhoEntries(net) return dumps(network) + @app.route("/irc/network//edit/", methods=["POST"]) + @login_required + def irc_network_edit(self, request, net): + try: + data = loads(request.content.read()) + except JSONDecodeError: + return "Invalid JSON" + if net not in main.network.keys(): + return dumps(False) + inst = main.network[net] + for item in data: + if item == "auth": + auth = data[item][0] + if auth not in ["sasl", "ns", "none"]: + return dumps({"success": False, "reason": "invalid auth."}) + elif item == "host": + host = data[item][0] + elif item == "last": + last = data[item][0] + if not last.isdigit(): + return dumps({"success": False, "reason": "invalid last: not a number."}) + elif item == "port": + port = data[item][0] + if not port.isdigit(): + return dumps({"success": False, "reason": "invalid port: not a number."}) + port = int(port) + elif item == "security": + security = data[item][0] + if security not in ["ssl", "plain"]: + return dumps({"success": False, "reason": "invalid security."}) + inst.auth = auth + inst.host = host + inst.last = last + inst.port = port + inst.security = security + main.saveConf("network") + + return dumps({"success": True}) + @app.route("/irc/network//relays/", methods=["POST"]) @login_required def irc_network_relays(self, request, net):