import main from core.bot import deliverRelayCommands from utils.logging.log import * from core.helper import startBot def provisionUserData(relay, alias, nick, altnick, ident, realname, password): commands = {} commands["controlpanel"] = [] commands["controlpanel"].append("AddUser %s %s" % (alias, password)) commands["controlpanel"].append("Set Nick %s %s" % (alias, nick)) commands["controlpanel"].append("Set Altnick %s %s" % (alias, altnick)) commands["controlpanel"].append("Set Ident %s %s" % (alias, ident)) commands["controlpanel"].append("Set RealName %s %s" % (alias, realname)) deliverRelayCommands(relay, commands) return def provisionNetworkData(relay, alias, network, host, port, security, auth, password): commands = {} stage2commands = {} commands["controlpanel"] = [] commands["controlpanel"].append("AddNetwork %s %s" % (alias, network)) if security == "ssl": commands["controlpanel"].append("SetNetwork TrustAllCerts %s %s true" % (alias, network)) # Don't judge me commands["controlpanel"].append("AddServer %s %s %s +%s" % (alias, network, host, port)) elif security == "plain": commands["controlpanel"].append("AddServer %s %s %s %s" % (alias, network, host, port)) if auth == "sasl": stage2commands["status"] = [] stage2commands["sasl"] = [] stage2commands["status"].append("LoadMod sasl") stage2commands["sasl"].append("Mechanism plain") stage2commands["sasl"].append("Set %s %s" % (alias, password)) elif auth == "ns": stage2commands["status"] = [] stage2commands["nickserv"] = [] stage2commands["status"].append("LoadMod NickServ") stage2commands["nickserv"].append("Set %s" % password) deliverRelayCommands(relay, commands, stage2=[[alias+"/"+network, stage2commands]]) return def provisionRelayForAlias(relay, alias): if "users" in main.relay[relay].keys(): if alias in main.relay[relay]["users"]: return "PROVISIONED" else: main.relay[relay]["users"] = [] main.relay[relay]["users"].append(alias) provisionUserData(relay, alias, main.alias[alias]["nick"], main.alias[alias]["altnick"], main.alias[alias]["ident"], main.alias[alias]["realname"], main.relay[relay]["password"]) main.saveConf("relay") return True def provisionRelayForNetwork(relay, alias, network): if "networks" in main.relay[relay].keys(): if network in main.relay[relay]["networks"]: return "PROVISIONED" else: main.relay[relay]["networks"] = [] main.relay[relay]["networks"].append(network) provisionNetworkData(relay, alias, network, main.network[network]["host"], main.network[network]["port"], main.network[network]["security"], main.network[network]["auth"], main.alias[alias]["password"]) main.saveConf("relay") storedNetwork = False num = 1 while not storedNetwork: i = str(num) if num == 1000: error("Too many iterations in while trying to choose name for r: %s a: %s n: %s" % (relay, alias, network)) return False if network+i in main.pool.keys(): if main.pool[network+i]["alias"] == alias and main.pool[network+i]["relay"] == relay: return "DUPLICATE" num += 1 else: main.pool[network+i] = {"relay": relay, "alias": alias, "network": network, "enabled": main.config["ConnectOnCreate"]} main.saveConf("pool") if main.config["ConnectOnCreate"]: startBot(network+i) storedNetwork = True return network+i