Implement updating registration via API
This commit is contained in:
parent
dd67e9cc8b
commit
291968fbc7
43
api/views.py
43
api/views.py
|
@ -6,7 +6,7 @@ from klein import Klein
|
||||||
from twisted.web.server import Request
|
from twisted.web.server import Request
|
||||||
|
|
||||||
import main
|
import main
|
||||||
from modules import chankeep, helpers, provision, userinfo
|
from modules import chankeep, helpers, provision, regproc, userinfo
|
||||||
from modules.network import Network
|
from modules.network import Network
|
||||||
from utils.logging.log import warn
|
from utils.logging.log import warn
|
||||||
|
|
||||||
|
@ -207,6 +207,7 @@ class API(object):
|
||||||
network["port"] = inst.port
|
network["port"] = inst.port
|
||||||
network["security"] = inst.security
|
network["security"] = inst.security
|
||||||
network["relays"] = len(inst.relays)
|
network["relays"] = len(inst.relays)
|
||||||
|
network["chanlimit"] = inst.chanlimit
|
||||||
network["channels"] = userinfo.getTotalChanNum(net)
|
network["channels"] = userinfo.getTotalChanNum(net)
|
||||||
network["records"] = userinfo.getNumWhoEntries(net)
|
network["records"] = userinfo.getNumWhoEntries(net)
|
||||||
return dumps(network)
|
return dumps(network)
|
||||||
|
@ -247,6 +248,14 @@ class API(object):
|
||||||
if not port.isdigit():
|
if not port.isdigit():
|
||||||
return dumps({"success": False, "reason": "invalid port: not a number."})
|
return dumps({"success": False, "reason": "invalid port: not a number."})
|
||||||
port = int(port)
|
port = int(port)
|
||||||
|
elif item == "chanlimit":
|
||||||
|
chanlimit = data[item][0]
|
||||||
|
if chanlimit == "None":
|
||||||
|
chanlimit = None
|
||||||
|
elif not chanlimit.isdigit():
|
||||||
|
return dumps({"success": False, "reason": "invalid chanlimit: not a number."})
|
||||||
|
else:
|
||||||
|
chanlimit = int(chanlimit)
|
||||||
elif item == "security":
|
elif item == "security":
|
||||||
security = data[item][0]
|
security = data[item][0]
|
||||||
if security not in ["ssl", "plain"]:
|
if security not in ["ssl", "plain"]:
|
||||||
|
@ -256,6 +265,7 @@ class API(object):
|
||||||
inst.last = last
|
inst.last = last
|
||||||
inst.port = port
|
inst.port = port
|
||||||
inst.security = security
|
inst.security = security
|
||||||
|
inst.chanlimit = chanlimit
|
||||||
main.saveConf("network")
|
main.saveConf("network")
|
||||||
|
|
||||||
return dumps({"success": True})
|
return dumps({"success": True})
|
||||||
|
@ -535,3 +545,34 @@ class API(object):
|
||||||
if name not in main.IRCPool.keys():
|
if name not in main.IRCPool.keys():
|
||||||
return dumps({"success": False, "reason": f"relay {num} not on {net}"})
|
return dumps({"success": False, "reason": f"relay {num} not on {net}"})
|
||||||
return dumps({"nickname": main.IRCPool[name].nickname})
|
return dumps({"nickname": main.IRCPool[name].nickname})
|
||||||
|
|
||||||
|
@app.route("/irc/reg/<net>/", methods=["GET"])
|
||||||
|
@login_required
|
||||||
|
def irc_get_unreg_net(self, request, net):
|
||||||
|
if net not in main.network.keys():
|
||||||
|
return dumps({"success": False, "reason": "no such net."})
|
||||||
|
unreg = regproc.get_unregistered_relays(net)
|
||||||
|
return dumps({"success": True, "unreg": unreg})
|
||||||
|
|
||||||
|
@app.route("/irc/reg/", methods=["GET"])
|
||||||
|
@login_required
|
||||||
|
def irc_get_unreg(self, request):
|
||||||
|
unreg = regproc.get_unregistered_relays()
|
||||||
|
return dumps({"success": True, "unreg": unreg})
|
||||||
|
|
||||||
|
@app.route("/irc/reg/", methods=["PUT"])
|
||||||
|
@login_required
|
||||||
|
def irc_confirm_accounts(self, request):
|
||||||
|
try:
|
||||||
|
data = loads(request.content.read())
|
||||||
|
except JSONDecodeError:
|
||||||
|
return "Invalid JSON"
|
||||||
|
for item, token in data.items():
|
||||||
|
if "|" not in item:
|
||||||
|
return dumps({"success": False, "reason": f"malformed item: {item}"})
|
||||||
|
spl = item.split("|")
|
||||||
|
if not len(spl) == 2:
|
||||||
|
return dumps({"success": False, "reason": f"malformed item: {item}"})
|
||||||
|
net, num = spl
|
||||||
|
regproc.confirmAccount(net, num, token)
|
||||||
|
return dumps({"success": True})
|
||||||
|
|
|
@ -120,6 +120,29 @@ def enableAuthentication(net, num):
|
||||||
confirmRegistration(net, num)
|
confirmRegistration(net, num)
|
||||||
|
|
||||||
|
|
||||||
|
def get_unregistered_relays(net=None):
|
||||||
|
"""
|
||||||
|
Get a dict of unregistereed relays, either globally or
|
||||||
|
for a network.
|
||||||
|
Returns:
|
||||||
|
{"net": [["nick1", 1], ["nick2", 2], ...]}
|
||||||
|
"""
|
||||||
|
unreg = {}
|
||||||
|
if net:
|
||||||
|
nets = [net]
|
||||||
|
else:
|
||||||
|
nets = main.network.keys()
|
||||||
|
for i in nets:
|
||||||
|
for num in main.network[i].relays.keys():
|
||||||
|
if not main.network[i].relays[num]["registered"]:
|
||||||
|
nick = main.alias[num]["nick"]
|
||||||
|
if net in unreg:
|
||||||
|
unreg[i].append([nick, num])
|
||||||
|
else:
|
||||||
|
unreg[i] = [[nick, num]]
|
||||||
|
return unreg
|
||||||
|
|
||||||
|
|
||||||
def registerTest(c):
|
def registerTest(c):
|
||||||
sinst = substitute(c["net"], c["num"])
|
sinst = substitute(c["net"], c["num"])
|
||||||
name = c["net"] + str(c["num"])
|
name = c["net"] + str(c["num"])
|
||||||
|
|
Loading…
Reference in New Issue