2022-07-21 12:40:01 +00:00
|
|
|
from twisted.internet import reactor
|
2022-07-21 12:40:09 +00:00
|
|
|
|
|
|
|
import main
|
2022-07-21 12:40:01 +00:00
|
|
|
import modules.regproc
|
2022-07-21 12:40:09 +00:00
|
|
|
from utils.deliver_relay_commands import deliverRelayCommands
|
2022-08-11 18:22:09 +00:00
|
|
|
from utils.logging.log import warn
|
2019-01-26 01:57:24 +00:00
|
|
|
|
2022-07-21 12:39:41 +00:00
|
|
|
|
2022-07-21 12:40:03 +00:00
|
|
|
def provisionUserNetworkData(
|
|
|
|
num, nick, altnick, ident, realname, emails, network, host, port, security, auth, password
|
|
|
|
):
|
2019-01-26 01:57:24 +00:00
|
|
|
commands = {}
|
2020-05-30 20:37:22 +00:00
|
|
|
stage2commands = {}
|
|
|
|
stage2commands["status"] = []
|
2019-01-26 01:57:24 +00:00
|
|
|
commands["controlpanel"] = []
|
2020-10-28 22:30:04 +00:00
|
|
|
user = nick.lower()
|
2022-07-21 12:40:01 +00:00
|
|
|
commands["controlpanel"].append("AddUser %s %s" % (user, main.config["Relay"]["Password"]))
|
2020-10-28 22:30:04 +00:00
|
|
|
commands["controlpanel"].append("AddNetwork %s %s" % (user, network))
|
|
|
|
commands["controlpanel"].append("Set Nick %s %s" % (user, nick))
|
|
|
|
commands["controlpanel"].append("Set Altnick %s %s" % (user, altnick))
|
|
|
|
commands["controlpanel"].append("Set Ident %s %s" % (user, ident))
|
|
|
|
commands["controlpanel"].append("Set RealName %s %s" % (user, realname))
|
2020-05-30 20:37:22 +00:00
|
|
|
if security == "ssl":
|
2022-07-21 12:40:01 +00:00
|
|
|
commands["controlpanel"].append("SetNetwork TrustAllCerts %s %s true" % (user, network)) # Don't judge me
|
|
|
|
commands["controlpanel"].append("AddServer %s %s %s +%s" % (user, network, host, port))
|
2020-05-30 20:37:22 +00:00
|
|
|
elif security == "plain":
|
2022-07-21 12:40:01 +00:00
|
|
|
commands["controlpanel"].append("AddServer %s %s %s %s" % (user, network, host, port))
|
2020-05-30 20:37:22 +00:00
|
|
|
if not main.config["ConnectOnCreate"]:
|
|
|
|
stage2commands["status"].append("Disconnect")
|
|
|
|
if main.config["Toggles"]["CycleChans"]:
|
|
|
|
stage2commands["status"].append("LoadMod disconkick")
|
|
|
|
stage2commands["status"].append("LoadMod chansaver")
|
2020-11-01 03:39:32 +00:00
|
|
|
inst = modules.regproc.selectInst(network)
|
|
|
|
if "setmode" in inst.keys():
|
|
|
|
stage2commands["status"].append("LoadMod perform")
|
2022-07-21 12:39:41 +00:00
|
|
|
# stage2commands["perform"].append("add mode %nick% +"+inst["setmode"])
|
|
|
|
deliverRelayCommands(num, commands, stage2=[[user + "/" + network, stage2commands]])
|
|
|
|
|
2019-12-28 17:51:03 +00:00
|
|
|
|
|
|
|
def provisionAuthenticationData(num, nick, network, security, auth, password):
|
|
|
|
commands = {}
|
2020-05-30 20:37:22 +00:00
|
|
|
commands["status"] = []
|
2020-10-28 22:30:04 +00:00
|
|
|
user = nick.lower()
|
2019-12-28 17:51:03 +00:00
|
|
|
if auth == "sasl":
|
|
|
|
commands["sasl"] = []
|
|
|
|
commands["status"].append("LoadMod sasl")
|
|
|
|
commands["sasl"].append("Mechanism plain")
|
|
|
|
commands["sasl"].append("Set %s %s" % (nick, password))
|
|
|
|
elif auth == "ns":
|
|
|
|
commands["nickserv"] = []
|
|
|
|
commands["status"].append("LoadMod nickserv")
|
|
|
|
commands["nickserv"].append("Set %s" % password)
|
2020-11-01 03:39:32 +00:00
|
|
|
inst = modules.regproc.selectInst(network)
|
|
|
|
if "setmode" in inst.keys():
|
2022-08-13 18:20:29 +00:00
|
|
|
# perform is loaded above
|
2022-07-21 12:39:41 +00:00
|
|
|
# commands["status"].append("LoadMod perform")
|
|
|
|
commands["perform"] = ["add mode %nick% +" + inst["setmode"]]
|
|
|
|
deliverRelayCommands(num, commands, user=user + "/" + network)
|
2019-01-26 01:57:24 +00:00
|
|
|
|
|
|
|
|
2022-07-21 12:39:41 +00:00
|
|
|
def provisionRelay(num, network): # provision user and network data
|
2020-05-30 20:37:22 +00:00
|
|
|
aliasObj = main.alias[num]
|
2022-07-21 12:40:05 +00:00
|
|
|
# alias = aliasObj["nick"]
|
2022-07-21 12:39:41 +00:00
|
|
|
provisionUserNetworkData(
|
|
|
|
num,
|
|
|
|
*aliasObj.values(),
|
|
|
|
network,
|
|
|
|
main.network[network].host,
|
|
|
|
main.network[network].port,
|
|
|
|
main.network[network].security,
|
|
|
|
main.network[network].auth,
|
2022-08-11 18:22:09 +00:00
|
|
|
main.network[network].aliases[num]["password"],
|
2022-07-21 12:39:41 +00:00
|
|
|
)
|
2019-09-29 21:45:16 +00:00
|
|
|
if main.config["ConnectOnCreate"]:
|
2019-10-11 12:07:57 +00:00
|
|
|
reactor.callLater(10, main.network[network].start_bot, num)
|
2019-10-08 20:11:04 +00:00
|
|
|
|
2022-07-21 12:39:41 +00:00
|
|
|
|
2019-10-08 20:11:04 +00:00
|
|
|
def provisionMultipleRelays(net, relaysNeeded):
|
2022-08-13 17:40:13 +00:00
|
|
|
if not relaysNeeded:
|
|
|
|
return []
|
2022-08-11 18:22:09 +00:00
|
|
|
if not main.config["ChanKeep"]["Provision"]:
|
|
|
|
warn(f"Asked to create {relaysNeeded} relays for {net}, but provisioning is disabled")
|
2022-08-11 19:29:01 +00:00
|
|
|
return []
|
2019-10-12 20:40:50 +00:00
|
|
|
numsProvisioned = []
|
2019-10-11 12:07:57 +00:00
|
|
|
for i in range(relaysNeeded):
|
2019-10-08 20:11:04 +00:00
|
|
|
num, alias = main.network[net].add_relay()
|
2019-10-12 20:40:50 +00:00
|
|
|
numsProvisioned.append(num)
|
2019-10-08 20:11:04 +00:00
|
|
|
provisionRelay(num, net)
|
|
|
|
main.saveConf("network")
|
2019-10-12 20:40:50 +00:00
|
|
|
return numsProvisioned
|