import main from modules import provision from utils.logging.log import * from utils.logging.debug import * 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 def registerAccount(net, num): debug("Attempting to register: %s - %i" % (net, num)) alias = main.alias[num] nickname = alias["nick"] username = nickname+"/"+net password = main.network[net].aliases[num]["password"] inst = selectInst(net) 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): inst = selectInst(net) entity = inst["entity"] cmd = inst["confirm"] cmd = cmd.replace("{token}", token) name = net+str(num) main.IRCPool[name].msg(entity, cmd) enableAuthentication(net, num) 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") 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") 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