diff --git a/commands/auto.py b/commands/auto.py new file mode 100644 index 0000000..3d29a85 --- /dev/null +++ b/commands/auto.py @@ -0,0 +1,29 @@ +import main +from modules import provision + +class AutoCommand: + def __init__(self, *args): + self.auto(*args) + + def auto(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): + if authed: + if length == 3: + if not spl[1] in main.network.keys(): + failure("No such network: %s" % spl[1]) + return + if not spl[2].isdigit(): + failure("Must be integer, not %s" % spl[2]) + return + + id, alias = main.network[spl[1]].add_relay(int(spl[2])) + success("Successfully created relay %s on network %s with alias %s" % (str(id), spl[1], alias)) + main.saveConf("network") + rtrn = provision.provisionRelay(int(spl[2]), spl[1]) + success("Started provisioning network %s on relay %s for alias %s" % (spl[1], spl[2], rtrn)) + return + + else: + incUsage("auto") + return + else: + incUsage(None) diff --git a/commands/cmd.py b/commands/cmd.py index 819789b..858dc15 100644 --- a/commands/cmd.py +++ b/commands/cmd.py @@ -8,16 +8,12 @@ class CmdCommand: def cmd(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length > 4: - if not spl[1] in main.network.keys(): - failure("No such network: %s" % spl[1]) + if not spl[1].isdigit(): + failure("Must be integer, not %s" % spl[1]) return - if not int(spl[2]) in main.network[spl[1]].relays.keys(): - failure("No such relay: %s on network: %s" % (spl[2], spl[1])) - return - - commands = {spl[4]: [" ".join(spl[5:])]} + commands = {spl[3]: [" ".join(spl[4:])]} success("Sending commands to relay %s as user %s" % (spl[2], spl[3])) - deliverRelayCommands(main.network[spl[1]].relays[spl[2]], commands, user=spl[3]+"/"+spl[1]) + deliverRelayCommands(int(spl[1]), commands, user=spl[2]) return else: incUsage("cmd") diff --git a/commands/enable.py b/commands/enable.py index e25857b..0e88dce 100644 --- a/commands/enable.py +++ b/commands/enable.py @@ -11,16 +11,18 @@ class EnableCommand: if not spl[1] in main.network.keys(): failure("No such network: %s" % spl[1]) return + if not spl[2].isdigit(): + failure("Must be a number, not %s" % spl[2]) + return if not int(spl[2]) in main.network[spl[1]].relays.keys(): - failure("No such relay: %s in network %s" % (spl[2], spl[1])) + failure("No such relay on %s: %s" % (spl[2], spl[1])) return main.network[spl[1]].relays[int(spl[2])]["enabled"] = True - user = main.network[spl[1]].aliases[int(spl[2])] + user = main.network[spl[1]].aliases[int(spl[2])]["nick"] network = spl[1] - relay = main.network[spl[1]].relays[int(spl[2])] commands = {"status": ["Connect"]} - deliverRelayCommands(relay, commands, user=user+"/"+network) + deliverRelayCommands(int(spl[2]), commands, user=user+"/"+network) main.saveConf("network") if not spl[1]+spl[2] in main.IRCPool.keys(): main.network[spl[1]].start_bot(int(spl[2])) diff --git a/commands/get.py b/commands/get.py deleted file mode 100644 index b56f5dc..0000000 --- a/commands/get.py +++ /dev/null @@ -1,22 +0,0 @@ -import main - -class GetCommand: - def __init__(self, *args): - self.get(*args) - - def get(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): - if authed: - if length == 3: - if not spl[1] in main.pool.keys(): - failure("Name does not exist: %s" % spl[1]) - return - if not spl[1] in main.IRCPool.keys(): - failure("Name has no instance: %s" % spl[1]) - return - info(str(main.IRCPool[spl[1]].get(spl[2]))) - return - else: - incUsage("get") - return - else: - incUsage(None) diff --git a/commands/join.py b/commands/join.py index 2f36ab4..ff912bc 100644 --- a/commands/join.py +++ b/commands/join.py @@ -11,7 +11,7 @@ class JoinCommand: failure("Network does not exist: %s" % spl[1]) return if not int(spl[2]) in main.network[spl[1]].relays.keys(): - failure("Relay % does not exist on network %", (spl[2], spl[1])) + failure("Relay %s does not exist on network %s" % (spl[2], spl[1])) return if not spl[1]+spl[2] in main.IRCPool.keys(): failure("Name has no instance: %s" % spl[1]) diff --git a/commands/network.py b/commands/network.py index a4d04f2..b9cfbfd 100644 --- a/commands/network.py +++ b/commands/network.py @@ -23,7 +23,7 @@ class NetworkCommand: failure("Auth must be sasl, ns or none, not %s" % spl[5]) return else: - main.network[spl[2]] = Network(spl[2], spl[3], spl[4], spl[5].lower(), spl[6].lower()) + main.network[spl[2]] = Network(spl[2], spl[3], int(spl[4]), spl[5].lower(), spl[6].lower()) success("Successfully created network: %s" % spl[2]) main.saveConf("network") return diff --git a/commands/provision.py b/commands/provision.py deleted file mode 100644 index 459efd8..0000000 --- a/commands/provision.py +++ /dev/null @@ -1,60 +0,0 @@ -import main -from modules import provision - -class ProvisionCommand: - def __init__(self, *args): - self.provision(*args) - - def provision(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): - if authed: - if length == 4 or length == 3: - if not spl[1] in main.relay.keys(): - failure("No such relay: %s" % spl[1]) - return - if not spl[2] in main.alias.keys(): - failure("No such alias: %s" % spl[2]) - return - if length == 4: # provision for relay, alias and network - if not spl[3] in main.network.keys(): - failure("No such network: %s" % spl[3]) - return - - #if "users" in main.relay[spl[1]]: - # if not spl[2] in main.relay[spl[1]]["users"]: - # failure("Relay %s not provisioned for alias %s" % (spl[1], spl[2])) - # return - #else: - # failure("Relay %s not provisioned for alias %s" % (spl[1], spl[2])) - # return - - rtrn = provision.provisionRelayForNetwork(spl[1], spl[2], spl[3]) - #if rtrn == "PROVISIONED": - # failure("Relay %s already provisioned for alias %s on network %s" % (spl[1], spl[2], spl[3])) - # return - #elif rtrn == "DUPLICATE": - # failure("Instance with relay %s and alias %s already exists for network %s" % (spl[1], spl[2], spl[3])) - # return - if rtrn: - success("Started provisioning network %s on relay %s for alias %s" % (spl[3], spl[1], spl[2])) - info("Instance name is %s" % rtrn) - return - else: - failure("Failure while provisioning relay %s" % spl[1]) - return - if length == 3: # provision for relay and alias only - rtrn = provision.provisionRelayForAlias(spl[1], spl[2]) - #if rtrn == "PROVISIONED": - # failure("Relay %s already provisioned for alias %s" % (spl[1], spl[2])) - # return - if rtrn: - success("Started provisioning relay %s for alias %s" % (spl[1], spl[2])) - return - else: - failure("Failure while provisioning relay %s" % spl[1]) - return - - else: - incUsage("provision") - return - else: - incUsage(None) diff --git a/commands/relay.py b/commands/relay.py index 4736950..49dca97 100644 --- a/commands/relay.py +++ b/commands/relay.py @@ -7,29 +7,47 @@ class RelayCommand: def relay(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: - if length == 7: + if length == 3: if spl[1] == "add": - if spl[2] not in main.network.keys(): - failure("No such network: %s" % spl[2]) - return - if not spl[4].isdigit(): - failure("Port must be an integer, not %s" % spl[4]) - return - else: - id, alias = main.network[spl[2]].add_relay(spl[3], spl[4], spl[5], spl[6]) + if spl[2] in main.network.keys(): + id, alias = main.network[spl[2]].add_relay() success("Successfully created relay %s on network %s with alias %s" % (str(id), spl[2], alias)) main.saveConf("network") return + else: + failure("No such network: %s" % spl[2]) + return + elif spl[1] == "list": + if spl[2] not in main.network.keys(): + failure("No such network: %s" % spl[2]) + return + info(dump(main.network[spl[2]].relays)) + return else: incUsage("relay") return elif length == 4: - if spl[1] == "del": - if spl[2] not in main.network.keys(): + if spl[1] == "add": + if spl[2] in main.network.keys(): + if not spl[3].isdigit(): + failure("Must be a number, not %s" % spl[3]) + return + id, alias = main.network[spl[2]].add_relay(int(spl[3])) + success("Successfully created relay %s on network %s with alias %s" % (str(id), spl[2], alias)) + main.saveConf("network") + return + else: failure("No such network: %s" % spl[2]) return - if int(spl[3]) not in main.network[spl[2]].relays.keys(): + elif spl[1] == "del": + if not spl[2] in main.network.keys(): + failure("No such network: %s" % spl[2]) + return + if not spl[3].isdigit(): + failure("Must be a number, not %s" % spl[3]) + return + if not int(spl[3]) in main.network[spl[2]].relays.keys(): failure("No such relay: %s on network %s" % (spl[3], spl[2])) return main.network[spl[2]].delete_relay(int(spl[3])) @@ -39,16 +57,6 @@ class RelayCommand: else: incUsage("relay") return - elif length == 3: - if spl[1] == "list": - if spl[2] not in main.network.keys(): - failure("No such network: %s" % spl[2]) - return - info(dump(main.network[spl[2]].relays)) - return - else: - incUsage("relay") - return else: incUsage("relay") return diff --git a/commands/swho.py b/commands/swho.py new file mode 100644 index 0000000..b03ca61 --- /dev/null +++ b/commands/swho.py @@ -0,0 +1,40 @@ +import main + +class SwhoCommand: + def __init__(self, *args): + self.swho(*args) + + def swho(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): + if authed: + if length == 2: + if not spl[1] in main.network.keys(): + failure("Network does not exist: %s" % spl[1]) + return + for i in main.IRCPool.keys(): + if spl[1] in i: + for x in main.IRCPool[i].channels: + main.IRCPool[i].who(x) + success("Sent WHO to all channels on all networks on %s" % spl[1]) + return + elif length == 3: + if not spl[1] in main.network.keys(): + failure("Network does not exist: %s" % spl[1]) + return + matches = [] + for i in main.IRCPool.keys(): + if spl[1] in i: + for x in main.IRCPool[i].channels: + if x == spl[2]: + main.IRCPool[i].who(x) + matches.append(i) + if matches == []: + failure("No matches found for channel %s" % spl[2]) + return + success("Sent WHO to %s on: %s" % (spl[2], ", ".join(matches))) + return + + else: + incUsage("swho") + return + else: + incUsage(None) diff --git a/conf/example/config.json b/conf/example/config.json index a595963..0e6117d 100644 --- a/conf/example/config.json +++ b/conf/example/config.json @@ -4,7 +4,7 @@ "Address": "127.0.0.1", "UseSSL": true }, - "Relay": { + "RelayAPI": { "Enabled": true, "Port": 13868, "Address": "127.0.0.1", @@ -16,6 +16,12 @@ "UsePassword": true, "ConnectOnCreate": false, "Debug": false, + "Relay": { + "Host": "127.0.0.1", + "Port": "201x", + "User": "sir", + "Password": "sir" + }, "Dist": { "Enabled": true, "SendOutput": false, diff --git a/conf/help.json b/conf/help.json index 2f81c57..e58bfe1 100644 --- a/conf/help.json +++ b/conf/help.json @@ -1,27 +1,27 @@ { "pass": "pass ", "logout": "logout", - "del": "del ", - "mod": "mod ", - "get": "get ", + "del": "del ", + "mod": "mod [] []", "who": "who ", - "join": "join []", - "part": "part ", - "enable": "enable ", - "disable": "disable ", + "join": "join []", + "part": "part ", + "enable": "enable ", + "disable": "disable ", + "list": "list", "stats": "stats []", "save": "save <(file)|list|all>", "load": "load <(file)|list|all>", "dist": "dist", "loadmod": "loadmod ", - "msg": "msg ", + "msg": "msg ", "mon": "mon -h", "chans": "chans [ ...]", "users": "users [ ...]", - "relay": "relay [ | | ]", + "relay": "relay [] []", "network": "network [
]", - "provision": "provision []", - "cmd": "cmd ", + "auto": "auto ", + "cmd": "cmd ", "token": "token [] []", "all": "all ", "allc": "allc <(network)|(alias)> " diff --git a/conf/masterbuf.json b/conf/masterbuf.json deleted file mode 100644 index fe51488..0000000 --- a/conf/masterbuf.json +++ /dev/null @@ -1 +0,0 @@ -[] diff --git a/core/bot.py b/core/bot.py index 701714f..52c8044 100644 --- a/core/bot.py +++ b/core/bot.py @@ -14,6 +14,7 @@ from modules import monitor from core.relay import sendRelayNotification from utils.dedup import dedup +from utils.getrelay import getRelay import main from utils.logging.log import * @@ -21,33 +22,34 @@ from utils.logging.send import * from twisted.internet.ssl import DefaultOpenSSLContextFactory -def deliverRelayCommands(relay, relayCommands, user=None, stage2=None): +def deliverRelayCommands(num, relayCommands, user=None, stage2=None): # where relay is a dictionary extracted from the Network object keyFN = main.certPath+main.config["Key"] certFN = main.certPath+main.config["Certificate"] contextFactory = DefaultOpenSSLContextFactory(keyFN.encode("utf-8", "replace"), certFN.encode("utf-8", "replace")) - bot = IRCBotFactory(None, relay, relayCommands, user, stage2) - rct = reactor.connectSSL(relay["host"], - int(relay["port"]), + bot = IRCBotFactory(net=None, num=num, relayCommands=relayCommands, user=user, stage2=stage2) + host, port = getRelay(num) + rct = reactor.connectSSL(host, + port, bot, contextFactory) class IRCRelay(IRCClient): - def __init__(self, relay, relayCommands, user, stage2): + def __init__(self, num, relayCommands, user, stage2): self.connected = False self.buffer = "" if user == None: - self.user = relay["user"] + self.user = main.config["Relay"]["User"] else: self.user = user - password = relay["password"] - self.nickname = self.user - self.realname = self.user + password = main.config["Relay"]["Password"] + self.nickname = "relay" + self.realname = "relay" self.username = self.user self.password = self.user+":"+password self.relayCommands = relayCommands - self.relay = relay + self.num = num self.stage2 = stage2 def parsen(self, user): @@ -67,15 +69,16 @@ class IRCRelay(IRCClient): if nick[0] == main.config["Tweaks"]["ZNC"]["Prefix"]: nick = nick[1:] if nick in self.relayCommands.keys(): - sendAll("[%s] %s -> %s" % (self.relay, nick, msg)) + sendAll("[%s] %s -> %s" % (self.num, nick, msg)) def irc_ERR_PASSWDMISMATCH(self, prefix, params): - log("%s: relay password mismatch" % self.relay) - sendAll("%s: relay password mismatch" % self.relay) + print(', '.join("%s: %s" % item for item in vars(self).items())) + log("%s: relay password mismatch" % self.num) + sendAll("%s: relay password mismatch" % self.num) def signedOn(self): self.connected = True - log("signed on as a relay: %s" % self.relay) + log("signed on as a relay: %s" % self.num) #sendRelayNotification("Relay", {"type": "conn", "status": "connected"}) nobody actually cares for i in self.relayCommands.keys(): for x in self.relayCommands[i]: @@ -85,25 +88,24 @@ class IRCRelay(IRCClient): user = self.stage2[0].pop(0) commands = self.stage2[0].pop(0) del self.stage2[0] - deliverRelayCommands(self.relay, commands, user, self.stage2) + deliverRelayCommands(self.num, commands, user, self.stage2) deferLater(reactor, 1, self.transport.loseConnection) return class IRCBot(IRCClient): - def __init__(self, name, relay): + def __init__(self, net, num): self.connected = False self.channels = [] - self.net = "".join([x for x in name if not x in digits]) - if self.net == "": - error("Network with all numbers: %s" % name) + self.net = net + self.num = num self.buffer = "" - self.name = name - alias = relay["alias"] - + self.name = net + str(num) + alias = main.network[self.net].aliases[num] + relay = main.network[self.net].relays[num] self.nickname = alias["nick"] self.realname = alias["realname"] self.username = alias["nick"]+"/"+relay["net"] - self.password = relay["password"] + self.password = main.config["Relay"]["Password"] self.userinfo = None self.fingerReply = None self.versionName = None @@ -445,26 +447,30 @@ class IRCBot(IRCClient): self.event(type="mode", muser=user, target=channel, modes=m, status=toset, modeargs=a) class IRCBotFactory(ReconnectingClientFactory): - def __init__(self, name, relay=None, relayCommands=None, user=None, stage2=None): - if not name == None: - self.name = name - self.net = "".join([x for x in self.name if not x in digits]) + def __init__(self, net, num=None, relayCommands=None, user=None, stage2=None): + if net == None: + self.num = num + self.name = "Relay to %i" % num + self.relay = True else: - self.name = "Relay to "+relay["net"]+relay["id"] + self.name = net + str(num) + self.num = num + self.net = net + self.relay = False self.client = None self.maxDelay = main.config["Tweaks"]["Delays"]["MaxDelay"] self.initialDelay = main.config["Tweaks"]["Delays"]["InitialDelay"] self.factor = main.config["Tweaks"]["Delays"]["Factor"] self.jitter = main.config["Tweaks"]["Delays"]["Jitter"] - self.relay, self.relayCommands, self.user, self.stage2 = relay, relayCommands, user, stage2 + self.relayCommands, self.user, self.stage2 = relayCommands, user, stage2 def buildProtocol(self, addr): - if self.relay == None: - entry = IRCBot(self.name, self.relay) - main.IRCPool[self.name] = entry + if self.net == None: + entry = IRCRelay(self.num, self.relayCommands, self.user, self.stage2) else: - entry = IRCRelay(self.relay, self.relayCommands, self.user, self.stage2) + entry = IRCBot(self.net, self.num) + main.IRCPool[self.name] = entry self.client = entry return entry diff --git a/core/relay.py b/core/relay.py index 4067ee0..ef20155 100644 --- a/core/relay.py +++ b/core/relay.py @@ -108,7 +108,7 @@ class Relay(Protocol): return def connectionMade(self): - log("Connection from %s:%s" % (self.addr.host, self.addr.port)) + log("Relay connection from %s:%s" % (self.addr.host, self.addr.port)) #self.send("Greetings.") def connectionLost(self, reason): diff --git a/modules/network.py b/modules/network.py index 5a89126..b6f0cfc 100644 --- a/modules/network.py +++ b/modules/network.py @@ -1,14 +1,16 @@ +from twisted.internet.ssl import DefaultOpenSSLContextFactory import json + import modules.alias as alias from twisted.internet import reactor from core.bot import IRCBot, IRCBotFactory -from twisted.internet.ssl import DefaultOpenSSLContextFactory import main from utils.logging.log import * +from utils.getrelay import getRelay class Network: - def __init__(self, name, host, port, security, auth): - self.name = name + def __init__(self, net, host, port, security, auth): + self.net = net self.host = host self.port = port self.security = security @@ -18,40 +20,39 @@ class Network: self.relays = {} self.aliases = {} - def add_relay(self, host, port, user, password): - self.last += 1 - self.relays[self.last] = { - "host": host, - "port": port, - "user": user, - "password": password, + def add_relay(self, num=None): + if not num: + self.last += 1 + num = self.last + self.relays[num] = { "enabled": False, - "net": self.name, - "id": self.last + "net": self.net, + "id": num } - self.aliases[self.last] = alias.generate_alias() - return self.last, self.aliases[self.last]["nick"] + self.aliases[num] = alias.generate_alias() + return num, self.aliases[num]["nick"] def delete_relay(self, id): del self.relays[id] del self.aliases[id] - def start_bot(self, relay): + def start_bot(self, num): # a single name is given to relays in the backend # e.g. freenode1 for the first relay on freenode network - name = self.name + relay keyFN = main.certPath+main.config["Key"] certFN = main.certPath+main.config["Certificate"] contextFactory = DefaultOpenSSLContextFactory(keyFN.encode("utf-8", "replace"), certFN.encode("utf-8", "replace")) - bot = IRCBotFactory(name) - rct = reactor.connectSSL(k, port, bot, contextFactory) - + bot = IRCBotFactory(self.net, num) + #host, port = self.relays[num]["host"], self.relays[num]["port"] + host, port = getRelay(num) + rct = reactor.connectSSL(host, port, bot, contextFactory) + name = self.net + str(num) main.ReactorPool[name] = rct main.FactoryPool[name] = bot - log("Started bot on relay %s on %s", (relay, self.host)) + log("Started bot on relay %s on %s" % (num, self.host)) def start_bots(self): - for relay in self.relays: - if relay["enabled"]: - start_bot(relay) + for num in self.relays.keys(): + if self.relays[num]["enabled"]: + self.start_bot(num) diff --git a/modules/provision.py b/modules/provision.py index fb3ea9c..d2aad53 100644 --- a/modules/provision.py +++ b/modules/provision.py @@ -1,36 +1,35 @@ 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): +def provisionUserData(num, nick, altnick, ident, realname, unused): # last field is password, which we don't want to inherit here, but still want to use * expansion, so this is a bit of a hack 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) + commands["controlpanel"].append("AddUser %s %s" % (nick, main.config["Relay"]["Password"])) + commands["controlpanel"].append("Set Nick %s %s" % (nick, nick)) + commands["controlpanel"].append("Set Altnick %s %s" % (nick, altnick)) + commands["controlpanel"].append("Set Ident %s %s" % (nick, ident)) + commands["controlpanel"].append("Set RealName %s %s" % (nick, realname)) + deliverRelayCommands(num, commands) return -def provisionNetworkData(relay, alias, network, host, port, security, auth, password): +def provisionNetworkData(num, nick, network, host, port, security, auth, password): commands = {} stage2commands = {} stage3commands = {} commands["controlpanel"] = [] - commands["controlpanel"].append("AddNetwork %s %s" % (alias, network)) + commands["controlpanel"].append("AddNetwork %s %s" % (nick, 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)) + commands["controlpanel"].append("SetNetwork TrustAllCerts %s %s true" % (nick, network)) # Don't judge me + commands["controlpanel"].append("AddServer %s %s %s +%s" % (nick, network, host, port)) elif security == "plain": - commands["controlpanel"].append("AddServer %s %s %s %s" % (alias, network, host, port)) + commands["controlpanel"].append("AddServer %s %s %s %s" % (nick, 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)) + stage2commands["sasl"].append("Set %s %s" % (nick, password)) elif auth == "ns": stage2commands["status"] = [] stage2commands["nickserv"] = [] @@ -43,60 +42,23 @@ def provisionNetworkData(relay, alias, network, host, port, security, auth, pass stage2commands["status"] = [] stage2commands["status"].append("LoadMod disconkick") stage2commands["status"].append("LoadMod chansaver") - deliverRelayCommands(relay, commands, - stage2=[[alias+"/"+network, stage2commands], - [alias+"/"+network, stage3commands]]) + deliverRelayCommands(num, commands, + stage2=[[nick+"/"+network, stage2commands], + [nick+"/"+network, stage3commands]]) 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(num, alias, network): + provisionNetworkData(num, alias, network, + main.network[network].host, + main.network[network].port, + main.network[network].security, + main.network[network].auth, + main.network[network].aliases[num]["password"]) + return -def provisionRelayForNetwork(relay, alias, network): - #if set(["users", "networks"]).issubset(main.relay[relay].keys()): - # if network in main.relay[relay]["networks"] and alias in main.relay[relay]["users"]: - # 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("Iteration limit exceeded 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 +def provisionRelay(num, network): + aliasObj = main.network[network].aliases[num] + alias = aliasObj["nick"] + provisionUserData(num, *aliasObj.values()) + provisionRelayForNetwork(num, alias, network) + return alias diff --git a/threshold b/threshold index 29a19c4..c5a3cc3 100755 --- a/threshold +++ b/threshold @@ -29,14 +29,14 @@ if __name__ == "__main__": else: reactor.listenTCP(main.config["Listener"]["Port"], listener, interface=main.config["Listener"]["Address"]) log("Threshold running on %s:%s" % (main.config["Listener"]["Address"], main.config["Listener"]["Port"])) - if main.config["Relay"]["Enabled"]: + if main.config["RelayAPI"]["Enabled"]: relay = RelayFactory() - if main.config["Relay"]["UseSSL"] == True: - reactor.listenSSL(main.config["Relay"]["Port"], relay, DefaultOpenSSLContextFactory(main.certPath+main.config["Key"], main.certPath+main.config["Certificate"]), interface=main.config["Relay"]["Address"]) - log("Threshold relay running with SSL on %s:%s" % (main.config["Relay"]["Address"], main.config["Relay"]["Port"])) + if main.config["RelayAPI"]["UseSSL"] == True: + reactor.listenSSL(main.config["RelayAPI"]["Port"], relay, DefaultOpenSSLContextFactory(main.certPath+main.config["Key"], main.certPath+main.config["Certificate"]), interface=main.config["RelayAPI"]["Address"]) + log("Threshold relay running with SSL on %s:%s" % (main.config["RelayAPI"]["Address"], main.config["RelayAPI"]["Port"])) else: - reactor.listenTCP(main.config["Relay"]["Port"], relay, interface=main.config["Relay"]["Address"]) - log("Threshold relay running on %s:%s" % (main.config["Relay"]["Address"], main.config["Relay"]["Port"])) + reactor.listenTCP(main.config["RelayAPI"]["Port"], relay, interface=main.config["RelayAPI"]["Address"]) + log("Threshold relay running on %s:%s" % (main.config["RelayAPI"]["Address"], main.config["RelayAPI"]["Port"])) for net in main.network.keys(): main.network[net].start_bots() modules.counters.setupCounterLoop() diff --git a/utils/getrelay.py b/utils/getrelay.py new file mode 100644 index 0000000..043ce44 --- /dev/null +++ b/utils/getrelay.py @@ -0,0 +1,12 @@ +import main + +def getRelay(num): + host = main.config["Relay"]["Host"].replace("x", str(num)) + port = int(str(main.config["Relay"]["Port"]).replace("x", str(num))) + user = main.config["Relay"]["User"] + password = main.config["Relay"]["Password"] + try: + port = int(port) + except ValueError: + return False + return [host, port] diff --git a/utils/loaders/command_loader.py b/utils/loaders/command_loader.py index 360671d..031f2aa 100644 --- a/utils/loaders/command_loader.py +++ b/utils/loaders/command_loader.py @@ -1,6 +1,7 @@ from os import listdir from utils.logging.debug import debug +from utils.logging.log import * import commands from main import CommandMap