2022-07-21 12:40:09 +00:00
|
|
|
from copy import deepcopy
|
|
|
|
from random import choice
|
|
|
|
|
2020-05-30 20:40:10 +00:00
|
|
|
import main
|
|
|
|
from modules import provision
|
2022-07-21 12:40:05 +00:00
|
|
|
from utils.logging.debug import debug
|
2022-07-21 12:40:09 +00:00
|
|
|
from utils.logging.log import error
|
2022-07-21 12:39:41 +00:00
|
|
|
|
2022-07-21 12:40:03 +00:00
|
|
|
|
2020-06-07 16:26:53 +00:00
|
|
|
def needToRegister(net):
|
2022-07-21 12:39:56 +00:00
|
|
|
# Check if the network does not support authentication
|
|
|
|
networkObj = main.network[net]
|
|
|
|
if networkObj.auth == "none":
|
|
|
|
return False
|
|
|
|
# Check if the IRC network definition has registration disabled
|
2020-06-07 16:26:53 +00:00
|
|
|
inst = selectInst(net)
|
|
|
|
if "register" in inst.keys():
|
|
|
|
if inst["register"]:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
2022-07-21 12:39:41 +00:00
|
|
|
|
2020-05-31 12:23:09 +00:00
|
|
|
def selectInst(net):
|
|
|
|
if net in main.irc.keys():
|
|
|
|
inst = deepcopy(main.irc[net])
|
|
|
|
for i in main.irc["_"].keys():
|
2022-07-21 12:40:05 +00:00
|
|
|
if i not in inst:
|
2020-05-31 12:23:09 +00:00
|
|
|
inst[i] = main.irc["_"][i]
|
|
|
|
else:
|
|
|
|
inst = main.irc["_"]
|
|
|
|
return inst
|
2020-05-30 20:40:10 +00:00
|
|
|
|
2022-07-21 12:39:41 +00:00
|
|
|
|
2020-10-31 16:49:37 +00:00
|
|
|
def substitute(net, num, token=None):
|
|
|
|
inst = selectInst(net)
|
2020-05-30 20:40:10 +00:00
|
|
|
alias = main.alias[num]
|
2022-07-21 12:39:52 +00:00
|
|
|
gotemail = False
|
|
|
|
if "emails" in alias:
|
2022-07-21 12:39:46 +00:00
|
|
|
# First priority is explicit email lists
|
2022-07-21 12:39:52 +00:00
|
|
|
if alias["emails"]:
|
|
|
|
email = choice(alias["emails"])
|
|
|
|
gotemail = True
|
|
|
|
if "domains" in inst:
|
|
|
|
if inst["domains"]:
|
|
|
|
if not gotemail:
|
|
|
|
domain = choice(inst["domains"])
|
|
|
|
email = f"{alias['nickname']}@{domain}"
|
|
|
|
gotemail = True
|
|
|
|
if not gotemail:
|
|
|
|
error(f"Could not get email for {net} - {num}")
|
|
|
|
return False
|
2020-05-30 20:40:10 +00:00
|
|
|
nickname = alias["nick"]
|
2022-07-21 12:40:05 +00:00
|
|
|
# username = nickname + "/" + net
|
2020-05-30 20:40:10 +00:00
|
|
|
password = main.network[net].aliases[num]["password"]
|
2022-07-21 12:40:03 +00:00
|
|
|
# inst["email"] = inst["email"].replace("{nickname}", nickname)
|
2020-10-31 16:49:37 +00:00
|
|
|
for i in inst.keys():
|
|
|
|
if not isinstance(inst[i], str):
|
|
|
|
continue
|
|
|
|
inst[i] = inst[i].replace("{nickname}", nickname)
|
|
|
|
inst[i] = inst[i].replace("{password}", password)
|
2022-07-21 12:39:46 +00:00
|
|
|
inst[i] = inst[i].replace("{email}", email)
|
2020-10-31 16:49:37 +00:00
|
|
|
if token:
|
|
|
|
inst[i] = inst[i].replace("{token}", token)
|
|
|
|
return inst
|
|
|
|
|
2022-07-21 12:39:41 +00:00
|
|
|
|
2020-10-31 16:49:37 +00:00
|
|
|
def registerAccount(net, num):
|
|
|
|
debug("Attempting to register: %s - %i" % (net, num))
|
|
|
|
sinst = substitute(net, num)
|
2022-07-21 12:39:52 +00:00
|
|
|
if not sinst:
|
|
|
|
error(f"Register account failed for {net} - {num}")
|
|
|
|
return
|
2020-10-31 23:58:03 +00:00
|
|
|
if not sinst["register"]:
|
2020-05-30 20:40:10 +00:00
|
|
|
error("Cannot register for %s: function disabled" % (net))
|
|
|
|
return False
|
2022-07-21 12:39:41 +00:00
|
|
|
name = net + str(num)
|
2020-10-31 16:49:37 +00:00
|
|
|
main.IRCPool[name].msg(sinst["entity"], sinst["registermsg"])
|
2020-05-30 20:40:10 +00:00
|
|
|
|
2022-07-21 12:39:41 +00:00
|
|
|
|
2020-05-30 20:40:10 +00:00
|
|
|
def confirmAccount(net, num, token):
|
2020-10-31 16:49:37 +00:00
|
|
|
sinst = substitute(net, num, token=token)
|
2022-07-21 12:39:41 +00:00
|
|
|
name = net + str(num)
|
2020-10-31 16:49:37 +00:00
|
|
|
main.IRCPool[name].msg(sinst["entity"], sinst["confirm"])
|
2020-05-30 20:40:10 +00:00
|
|
|
enableAuthentication(net, num)
|
|
|
|
|
2022-07-21 12:39:41 +00:00
|
|
|
|
2020-10-31 16:49:37 +00:00
|
|
|
def confirmRegistration(net, num, negativepass=None):
|
2020-05-31 20:52:56 +00:00
|
|
|
obj = main.network[net]
|
2022-07-21 12:39:41 +00:00
|
|
|
name = net + str(num)
|
2020-05-31 20:52:56 +00:00
|
|
|
if name in main.IRCPool.keys():
|
2022-07-21 12:40:05 +00:00
|
|
|
if negativepass is not None:
|
2020-10-31 16:49:37 +00:00
|
|
|
main.IRCPool[name].regPing(negativepass=negativepass)
|
|
|
|
return
|
2022-07-21 12:39:41 +00:00
|
|
|
debug("Relay authenticated: %s - %i" % (net, num))
|
2020-05-31 20:52:56 +00:00
|
|
|
main.IRCPool[name].authenticated = True
|
2020-06-07 16:26:53 +00:00
|
|
|
main.IRCPool[name].recheckList()
|
2020-05-31 20:52:56 +00:00
|
|
|
if obj.relays[num]["registered"]:
|
|
|
|
return
|
|
|
|
if name in main.IRCPool.keys():
|
|
|
|
if main.IRCPool[name]._regAttempt:
|
2020-10-31 23:58:03 +00:00
|
|
|
try:
|
|
|
|
main.IRCPool[name]._regAttempt.cancel()
|
2022-07-21 12:40:05 +00:00
|
|
|
except: # noqa
|
2020-10-31 23:58:03 +00:00
|
|
|
pass
|
2020-05-31 20:52:56 +00:00
|
|
|
obj.relays[num]["registered"] = True
|
|
|
|
main.saveConf("network")
|
|
|
|
|
2022-07-21 12:39:41 +00:00
|
|
|
|
2020-05-30 20:40:10 +00:00
|
|
|
def enableAuthentication(net, num):
|
|
|
|
obj = main.network[net]
|
|
|
|
nick = main.alias[num]["nick"]
|
|
|
|
security = obj.security
|
|
|
|
auth = obj.auth
|
|
|
|
password = obj.aliases[num]["password"]
|
2022-07-21 12:40:05 +00:00
|
|
|
# uname = main.alias[num]["nick"] + "/" + net
|
2022-07-21 12:40:01 +00:00
|
|
|
provision.provisionAuthenticationData(num, nick, net, security, auth, password) # Set up for auth
|
|
|
|
main.IRCPool[net + str(num)].msg(main.config["Tweaks"]["ZNC"]["Prefix"] + "status", "Jump")
|
2022-07-21 12:40:05 +00:00
|
|
|
if selectInst(net)["check"] is False:
|
2020-05-31 20:52:56 +00:00
|
|
|
confirmRegistration(net, num)
|
|
|
|
|
2022-07-21 12:39:41 +00:00
|
|
|
|
2020-05-31 20:52:56 +00:00
|
|
|
def registerTest(c):
|
2020-11-01 22:19:03 +00:00
|
|
|
sinst = substitute(c["net"], c["num"])
|
2022-07-21 12:39:41 +00:00
|
|
|
name = c["net"] + str(c["num"])
|
2022-07-21 12:40:05 +00:00
|
|
|
if sinst["check"] is False:
|
2020-05-31 20:52:56 +00:00
|
|
|
return
|
2022-07-21 12:40:05 +00:00
|
|
|
if "msg" in c.keys() and not c["msg"] is None:
|
2020-11-01 22:19:03 +00:00
|
|
|
if sinst["negative"]:
|
2020-10-31 16:49:37 +00:00
|
|
|
if name in main.IRCPool.keys():
|
2022-07-21 12:40:05 +00:00
|
|
|
if main.IRCPool[name]._negativePass is not True:
|
2020-11-01 22:19:03 +00:00
|
|
|
if c["type"] == "query" and c["nick"] == sinst["entity"]:
|
|
|
|
if sinst["checknegativemsg"] in c["msg"]:
|
2022-07-21 12:40:03 +00:00
|
|
|
confirmRegistration(
|
|
|
|
c["net"], c["num"], negativepass=False
|
|
|
|
) # Not passed negative check, report back
|
2020-10-31 16:49:37 +00:00
|
|
|
return
|
2020-11-01 22:19:03 +00:00
|
|
|
if sinst["checkendnegative"] in c["msg"]:
|
2022-07-21 12:40:03 +00:00
|
|
|
confirmRegistration(
|
|
|
|
c["net"], c["num"], negativepass=True
|
|
|
|
) # Passed the negative check, report back
|
2020-10-31 16:49:37 +00:00
|
|
|
return
|
2020-11-01 22:19:03 +00:00
|
|
|
if sinst["ping"]:
|
|
|
|
if sinst["checkmsg2"] in c["msg"] and c["nick"] == sinst["entity"]:
|
2020-10-31 16:49:37 +00:00
|
|
|
confirmRegistration(c["net"], c["num"])
|
|
|
|
return
|
2020-11-01 22:19:03 +00:00
|
|
|
if sinst["checktype"] == "msg":
|
2022-07-21 12:39:41 +00:00
|
|
|
if sinst["checkmsg"] in c["msg"]:
|
|
|
|
confirmRegistration(c["net"], c["num"])
|
|
|
|
return
|
2020-11-01 22:19:03 +00:00
|
|
|
elif sinst["checktype"] == "mode":
|
2020-06-07 16:26:53 +00:00
|
|
|
if c["type"] == "self":
|
|
|
|
if c["mtype"] == "mode":
|
2022-07-21 12:40:05 +00:00
|
|
|
if sinst["checkmode"] in c["mode"] and c["status"] is True:
|
2020-06-07 16:26:53 +00:00
|
|
|
confirmRegistration(c["net"], c["num"])
|
|
|
|
return
|