Implement API for authentication management actions
This commit is contained in:
parent
5123941c79
commit
eba2c387f0
33
api/views.py
33
api/views.py
|
@ -213,6 +213,39 @@ class API(object):
|
|||
network["records"] = userinfo.getNumWhoEntries(net)
|
||||
return dumps(network)
|
||||
|
||||
@app.route("/irc/network/auth/", methods=["POST"])
|
||||
@login_required
|
||||
def irc_network_recheckauth(self, request):
|
||||
try:
|
||||
data = loads(request.content.read())
|
||||
except JSONDecodeError:
|
||||
return "Invalid JSON"
|
||||
if "func" not in data:
|
||||
return dumps({"success": False, "reason": "no function specified."})
|
||||
func = data["func"]
|
||||
|
||||
if "net" not in data:
|
||||
return dumps({"success": False, "reason": "no net specified."})
|
||||
net = data["net"]
|
||||
if not net or net == "None":
|
||||
nets = main.network.keys()
|
||||
else:
|
||||
if net not in main.network.keys():
|
||||
return dumps({"success": False, "reason": "no such net."})
|
||||
nets = [net]
|
||||
for net_name in nets:
|
||||
conns = helpers.get_connected_relays(net_name)
|
||||
if not conns:
|
||||
return dumps({"success": False, "reason": f"failed to get instances for {net_name}."})
|
||||
if func == "recheckauth":
|
||||
for conn in conns:
|
||||
conn.regPing()
|
||||
elif func == "resetauth":
|
||||
for conn in conns:
|
||||
conn.authenticated = False
|
||||
conn.regPing()
|
||||
return dumps({"success": True})
|
||||
|
||||
@app.route("/irc/network/<net>/", methods=["DELETE"])
|
||||
@login_required
|
||||
def irc_network_delete(self, request, net):
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import main
|
||||
|
||||
from utils.get import getRelay
|
||||
|
||||
|
||||
class GetstrCommand:
|
||||
def __init__(self, *args):
|
||||
self.getstr(*args)
|
||||
|
@ -11,7 +11,7 @@ class GetstrCommand:
|
|||
if length == 3:
|
||||
net = spl[1]
|
||||
num = spl[2]
|
||||
if not net in main.network.keys():
|
||||
if net not in main.network.keys():
|
||||
failure("Network does not exist: %s" % net)
|
||||
return
|
||||
if not num.isdigit():
|
||||
|
|
12
core/bot.py
12
core/bot.py
|
@ -55,7 +55,7 @@ class IRCBot(IRCClient):
|
|||
self.isconnected = False
|
||||
self.channels = []
|
||||
self.net = net
|
||||
self.authenticated = not regproc.needToRegister(self.net)
|
||||
self.authenticated = not regproc.needToAuth(self.net)
|
||||
self.num = num
|
||||
self.buffer = ""
|
||||
self.name = net + str(num)
|
||||
|
@ -621,8 +621,9 @@ class IRCBot(IRCClient):
|
|||
def regPing(self, negativepass=None):
|
||||
if self.authenticated:
|
||||
return
|
||||
if not regproc.needToRegister(self.net):
|
||||
if not regproc.needToAuth(self.net):
|
||||
self.authenticated = True
|
||||
return
|
||||
sinst = regproc.substitute(self.net, self.num)
|
||||
if not sinst:
|
||||
error(f"regPing() {self.net}: registration ping failed for {self.num}")
|
||||
|
@ -649,7 +650,12 @@ class IRCBot(IRCClient):
|
|||
if sinst["negative"]:
|
||||
self._negativePass = None
|
||||
self.msg(sinst["entity"], sinst["negativemsg"])
|
||||
debug(f"regPing() {self.net}: sent negativemsg '{sinst['negativemsg']}' to {sinst['entity']} - {self.num}")
|
||||
debug(
|
||||
(
|
||||
f"regPing() {self.net}: sent negativemsg "
|
||||
f"'{sinst['negativemsg']}' to {sinst['entity']} - {self.num}"
|
||||
)
|
||||
)
|
||||
return
|
||||
else:
|
||||
self._negativePass = True
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import main
|
||||
from modules import chankeep
|
||||
from utils.logging.debug import debug
|
||||
|
||||
# from utils.logging.debug import debug
|
||||
|
||||
|
||||
def get_first_relay(net):
|
||||
|
@ -53,3 +54,19 @@ def get_active_relays(net):
|
|||
if name in main.IRCPool.keys():
|
||||
active_insts.append(main.IRCPool[name])
|
||||
return active_insts
|
||||
|
||||
|
||||
def get_connected_relays(net):
|
||||
"""
|
||||
Get all connected instances for the network.
|
||||
:param net: the network
|
||||
:return: list of active instances
|
||||
:rtype: list of IRCPool instances
|
||||
"""
|
||||
active_nums = chankeep.getConnectedRelays(net)
|
||||
active_insts = []
|
||||
for num in active_nums:
|
||||
name = net + str(num)
|
||||
if name in main.IRCPool.keys():
|
||||
active_insts.append(main.IRCPool[name])
|
||||
return active_insts
|
||||
|
|
|
@ -21,6 +21,13 @@ def needToRegister(net):
|
|||
return False
|
||||
|
||||
|
||||
def needToAuth(net):
|
||||
networkObj = main.network[net]
|
||||
if networkObj.auth == "none":
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def selectInst(net):
|
||||
if net in main.irc.keys():
|
||||
inst = deepcopy(main.irc[net])
|
||||
|
@ -159,28 +166,53 @@ def registerTest(c):
|
|||
confirmRegistration(
|
||||
c["net"], c["num"], negativepass=False
|
||||
) # Not passed negative check, report back
|
||||
debug(f"registerTest() {net} - {num} not passed negative:checknegativemsg check, {sinst['checknegativemsg']} present in message")
|
||||
debug(
|
||||
(
|
||||
f"registerTest() {net} - {num} not passed negative:checknegativemsg "
|
||||
f"check, {sinst['checknegativemsg']} present in message"
|
||||
)
|
||||
)
|
||||
return
|
||||
if sinst["checkendnegative"] in c["msg"]:
|
||||
confirmRegistration(
|
||||
c["net"], c["num"], negativepass=True
|
||||
) # Passed the negative check, report back
|
||||
debug(f"registerTest() {net} - {num} passed negative:checkendnegative check, {sinst['checkendnegative']} present in message")
|
||||
debug(
|
||||
(
|
||||
f"registerTest() {net} - {num} passed negative:checkendnegative "
|
||||
f"check, {sinst['checkendnegative']} present in message"
|
||||
)
|
||||
)
|
||||
return
|
||||
if sinst["ping"]:
|
||||
if sinst["checkmsg2"] in c["msg"] and c["nick"] == sinst["entity"]:
|
||||
confirmRegistration(c["net"], c["num"])
|
||||
debug(f"registerTest() {net} - {num} passed ping:checkmsg2 check, {sinst['checkmsg2']} present in message")
|
||||
debug(
|
||||
(
|
||||
f"registerTest() {net} - {num} passed ping:checkmsg2 "
|
||||
f"check, {sinst['checkmsg2']} present in message"
|
||||
)
|
||||
)
|
||||
return
|
||||
if sinst["checktype"] == "msg":
|
||||
if sinst["checkmsg"] in c["msg"]:
|
||||
confirmRegistration(c["net"], c["num"])
|
||||
debug(f"registerTest() {net} - {num} passed checktype:msg:checkmsg check, {sinst['checkmsg']} present in message")
|
||||
debug(
|
||||
(
|
||||
f"registerTest() {net} - {num} passed checktype:msg:checkmsg check, "
|
||||
f"{sinst['checkmsg']} present in message"
|
||||
)
|
||||
)
|
||||
return
|
||||
elif sinst["checktype"] == "mode":
|
||||
if c["type"] == "self":
|
||||
if c["mtype"] == "mode":
|
||||
if sinst["checkmode"] in c["mode"] and c["status"] is True:
|
||||
confirmRegistration(c["net"], c["num"])
|
||||
debug(f"registerTest() {net} - {num} passed checktype:mode:checkmost check, {sinst['checkmode']} present in mode")
|
||||
debug(
|
||||
(
|
||||
f"registerTest() {net} - {num} passed checktype:mode:checkmost check, "
|
||||
f"{sinst['checkmode']} present in mode"
|
||||
)
|
||||
)
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue