Implement editing networks via the API

This commit is contained in:
Mark Veidemanis 2022-07-27 08:59:17 +01:00
parent 4f141b976a
commit 8050484b6f
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 39 additions and 0 deletions

View File

@ -209,6 +209,45 @@ class API(object):
network["records"] = userinfo.getNumWhoEntries(net) network["records"] = userinfo.getNumWhoEntries(net)
return dumps(network) return dumps(network)
@app.route("/irc/network/<net>/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/<net>/relays/", methods=["POST"]) @app.route("/irc/network/<net>/relays/", methods=["POST"])
@login_required @login_required
def irc_network_relays(self, request, net): def irc_network_relays(self, request, net):