monolith/modules/regproc.py

120 lines
4.3 KiB
Python
Raw Normal View History

import main
from modules import provision
from utils.logging.log import *
from utils.logging.debug import *
from copy import deepcopy
def needToRegister(net):
inst = selectInst(net)
if "register" in inst.keys():
if inst["register"]:
return True
else:
return False
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 substitute(net, num, token=None):
inst = selectInst(net)
alias = main.alias[num]
nickname = alias["nick"]
username = nickname+"/"+net
password = main.network[net].aliases[num]["password"]
inst["email"] = inst["email"].replace("{nickname}", nickname)
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)
inst[i] = inst[i].replace("{email}", inst["email"])
if token:
inst[i] = inst[i].replace("{token}", token)
return inst
def registerAccount(net, num):
debug("Attempting to register: %s - %i" % (net, num))
sinst = substitute(net, num)
if not sinst["register"]:
error("Cannot register for %s: function disabled" % (net))
return False
name = net+str(num)
main.IRCPool[name].msg(sinst["entity"], sinst["registermsg"])
def confirmAccount(net, num, token):
sinst = substitute(net, num, token=token)
name = net+str(num)
main.IRCPool[name].msg(sinst["entity"], sinst["confirm"])
enableAuthentication(net, num)
def confirmRegistration(net, num, negativepass=None):
obj = main.network[net]
name = net+str(num)
if name in main.IRCPool.keys():
if not negativepass == None:
main.IRCPool[name].regPing(negativepass=negativepass)
return
debug("Relay authenticated: %s - %i" %(net, num))
main.IRCPool[name].authenticated = True
main.IRCPool[name].recheckList()
if obj.relays[num]["registered"]:
return
if name in main.IRCPool.keys():
if main.IRCPool[name]._regAttempt:
try:
main.IRCPool[name]._regAttempt.cancel()
except:
pass
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"])
name = c["net"]+str(c["num"])
if inst["check"] == False:
return
if "msg" in c.keys() and not c["msg"] == None:
if inst["negative"]:
if name in main.IRCPool.keys():
if not main.IRCPool[name]._negativePass == True:
if c["type"] == "query" and c["nick"] == inst["entity"]:
if inst["checknegativemsg"] in c["msg"]:
confirmRegistration(c["net"], c["num"], negativepass=False) # Not passed negative check, report back
return
if inst["checkendnegative"] in c["msg"]:
confirmRegistration(c["net"], c["num"], negativepass=True) # Passed the negative check, report back
return
if inst["ping"]:
if inst["checkmsg2"] in c["msg"] and c["nick"] == inst["entity"]:
confirmRegistration(c["net"], c["num"])
return
if inst["checktype"] == "msg":
if inst["checkmsg"] in c["msg"]:
confirmRegistration(c["net"], c["num"])
return
elif inst["checktype"] == "mode":
if c["type"] == "self":
if c["mtype"] == "mode":
if inst["checkmode"] in c["mode"] and c["status"] == True:
confirmRegistration(c["net"], c["num"])
return