2020-05-30 20:40:10 +00:00
|
|
|
import main
|
|
|
|
from modules import provision
|
|
|
|
from utils.logging.log import *
|
2020-05-31 20:52:56 +00:00
|
|
|
from utils.logging.debug import *
|
2020-05-31 12:23:09 +00:00
|
|
|
from copy import deepcopy
|
|
|
|
|
|
|
|
def selectInst(net):
|
|
|
|
if net in main.irc.keys():
|
|
|
|
inst = deepcopy(main.irc[net])
|
|
|
|
for i in main.irc["_"].keys():
|
|
|
|
if not i in inst:
|
|
|
|
inst[i] = main.irc["_"][i]
|
|
|
|
else:
|
|
|
|
inst = main.irc["_"]
|
|
|
|
return inst
|
2020-05-30 20:40:10 +00:00
|
|
|
|
|
|
|
def registerAccount(net, num):
|
2020-05-31 20:52:56 +00:00
|
|
|
debug("Attempting to register: %s - %i" % (net, num))
|
2020-05-30 20:40:10 +00:00
|
|
|
alias = main.alias[num]
|
|
|
|
nickname = alias["nick"]
|
|
|
|
username = nickname+"/"+net
|
|
|
|
password = main.network[net].aliases[num]["password"]
|
2020-05-31 12:23:09 +00:00
|
|
|
inst = selectInst(net)
|
2020-05-30 20:40:10 +00:00
|
|
|
if not inst["register"]:
|
|
|
|
error("Cannot register for %s: function disabled" % (net))
|
|
|
|
return False
|
|
|
|
entity = inst["entity"]
|
|
|
|
email = inst["email"]
|
|
|
|
cmd = inst["register"]
|
|
|
|
email = email.replace("{nickname}", nickname)
|
|
|
|
cmd = cmd.replace("{password}", password)
|
|
|
|
cmd = cmd.replace("{email}", email)
|
|
|
|
name = net+str(num)
|
|
|
|
main.IRCPool[name].msg(entity, cmd)
|
|
|
|
|
|
|
|
def confirmAccount(net, num, token):
|
2020-05-31 12:23:09 +00:00
|
|
|
inst = selectInst(net)
|
2020-05-30 20:40:10 +00:00
|
|
|
entity = inst["entity"]
|
|
|
|
cmd = inst["confirm"]
|
|
|
|
cmd = cmd.replace("{token}", token)
|
|
|
|
name = net+str(num)
|
|
|
|
main.IRCPool[name].msg(entity, cmd)
|
|
|
|
enableAuthentication(net, num)
|
|
|
|
|
2020-05-31 20:52:56 +00:00
|
|
|
def confirmRegistration(net, num):
|
|
|
|
obj = main.network[net]
|
|
|
|
name = net+str(num)
|
|
|
|
if name in main.IRCPool.keys():
|
|
|
|
debug("Relay authenticated: %s - %i" %(net, num))
|
|
|
|
main.IRCPool[name].authenticated = True
|
|
|
|
if obj.relays[num]["registered"]:
|
|
|
|
return
|
|
|
|
if name in main.IRCPool.keys():
|
|
|
|
if main.IRCPool[name]._regAttempt:
|
|
|
|
main.IRCPool[name]._regAttempt.cancel()
|
|
|
|
obj.relays[num]["registered"] = True
|
|
|
|
main.saveConf("network")
|
|
|
|
|
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"]
|
|
|
|
uname = main.alias[num]["nick"]+"/"+net
|
|
|
|
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")
|
2020-05-31 20:52:56 +00:00
|
|
|
if selectInst(net)["check"] == False:
|
|
|
|
confirmRegistration(net, num)
|
|
|
|
|
|
|
|
def registerTest(c):
|
|
|
|
inst = selectInst(c["net"])
|
|
|
|
if inst["check"] == False:
|
|
|
|
return
|
|
|
|
if inst["checktype"] == "msg":
|
|
|
|
if c["type"] == "query":
|
|
|
|
if inst["checkmsg"] in c["msg"] and c["nick"] == inst["entity"]:
|
|
|
|
confirmRegistration(c["net"], c["num"])
|
|
|
|
return
|
|
|
|
elif inst["checktype"] == "mode":
|
|
|
|
if c["type"] == "mode":
|
|
|
|
if inst["checkmode"] in c["modes"] and c["status"] == True:
|
|
|
|
confirmRegistration(c["net"], c["num"])
|
|
|
|
return
|