Remove provisioning restrictions, move all user tracking code to monitoring module, fix proper network name not being passed to the relay
This commit is contained in:
parent
51b89b9d05
commit
1ec0e1f7e6
|
@ -19,22 +19,22 @@ class Provision:
|
||||||
failure("No such network: %s" % spl[3])
|
failure("No such network: %s" % spl[3])
|
||||||
return
|
return
|
||||||
|
|
||||||
if "users" in main.relay[spl[1]]:
|
#if "users" in main.relay[spl[1]]:
|
||||||
if not spl[2] in main.relay[spl[1]]["users"]:
|
# if not spl[2] in main.relay[spl[1]]["users"]:
|
||||||
failure("Relay %s not provisioned for alias %s" % (spl[1], spl[2]))
|
# failure("Relay %s not provisioned for alias %s" % (spl[1], spl[2]))
|
||||||
return
|
# return
|
||||||
else:
|
#else:
|
||||||
failure("Relay %s not provisioned for alias %s" % (spl[1], spl[2]))
|
# failure("Relay %s not provisioned for alias %s" % (spl[1], spl[2]))
|
||||||
return
|
# return
|
||||||
|
|
||||||
rtrn = provision.provisionRelayForNetwork(spl[1], spl[2], spl[3])
|
rtrn = provision.provisionRelayForNetwork(spl[1], spl[2], spl[3])
|
||||||
if rtrn == "PROVISIONED":
|
#if rtrn == "PROVISIONED":
|
||||||
failure("Relay %s already provisioned for alias %s on network %s" % (spl[1], spl[2], spl[3]))
|
# failure("Relay %s already provisioned for alias %s on network %s" % (spl[1], spl[2], spl[3]))
|
||||||
return
|
# return
|
||||||
elif rtrn == "DUPLICATE":
|
#elif rtrn == "DUPLICATE":
|
||||||
failure("Instance with relay %s and alias %s already exists for network %s" % (spl[1], spl[2], spl[3]))
|
# failure("Instance with relay %s and alias %s already exists for network %s" % (spl[1], spl[2], spl[3]))
|
||||||
return
|
# return
|
||||||
elif rtrn:
|
if rtrn:
|
||||||
success("Started provisioning network %s on relay %s for alias %s" % (spl[3], spl[1], spl[2]))
|
success("Started provisioning network %s on relay %s for alias %s" % (spl[3], spl[1], spl[2]))
|
||||||
info("Instance name is %s" % rtrn)
|
info("Instance name is %s" % rtrn)
|
||||||
return
|
return
|
||||||
|
@ -43,10 +43,10 @@ class Provision:
|
||||||
return
|
return
|
||||||
if length == 3: # provision for relay and alias only
|
if length == 3: # provision for relay and alias only
|
||||||
rtrn = provision.provisionRelayForAlias(spl[1], spl[2])
|
rtrn = provision.provisionRelayForAlias(spl[1], spl[2])
|
||||||
if rtrn == "PROVISIONED":
|
#if rtrn == "PROVISIONED":
|
||||||
failure("Relay %s already provisioned for alias %s" % (spl[1], spl[2]))
|
# failure("Relay %s already provisioned for alias %s" % (spl[1], spl[2]))
|
||||||
return
|
# return
|
||||||
elif rtrn:
|
if rtrn:
|
||||||
success("Started provisioning relay %s for alias %s" % (spl[1], spl[2]))
|
success("Started provisioning relay %s for alias %s" % (spl[1], spl[2]))
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
|
57
core/bot.py
57
core/bot.py
|
@ -139,7 +139,8 @@ class IRCBot(IRCClient):
|
||||||
del cast[i]
|
del cast[i]
|
||||||
if "muser" in cast.keys():
|
if "muser" in cast.keys():
|
||||||
cast["nick"], cast["ident"], cast["host"] = self.parsen(cast["muser"])
|
cast["nick"], cast["ident"], cast["host"] = self.parsen(cast["muser"])
|
||||||
del cast["muser"]
|
#if not cast["type"] in ["nick", "kick", "quit", "part", "join"]:
|
||||||
|
# del cast["muser"]
|
||||||
if set(["nick", "ident", "host", "message"]).issubset(set(cast)):
|
if set(["nick", "ident", "host", "message"]).issubset(set(cast)):
|
||||||
if "message" in cast.keys():
|
if "message" in cast.keys():
|
||||||
if cast["ident"] == "znc" and cast["host"] == "znc.in":
|
if cast["ident"] == "znc" and cast["host"] == "znc.in":
|
||||||
|
@ -181,12 +182,10 @@ class IRCBot(IRCClient):
|
||||||
castDup["name"] = self.name
|
castDup["name"] = self.name
|
||||||
self.event(**castDup)
|
self.event(**castDup)
|
||||||
|
|
||||||
if "name" not in cast.keys():
|
if not "name" in cast.keys():
|
||||||
cast["name"] = self.net
|
cast["name"] = self.net
|
||||||
if cast["type"] in ["msg", "notice", "action"]:
|
|
||||||
userinfo.editUser(self.net, cast["nick"]+"!"+cast["ident"]+"@"+cast["host"])
|
|
||||||
count.event(self.net, cast["type"])
|
count.event(self.net, cast["type"])
|
||||||
monitor.event(self.net, self.name, cast)
|
monitor.event(cast)
|
||||||
|
|
||||||
def privmsg(self, user, channel, msg):
|
def privmsg(self, user, channel, msg):
|
||||||
self.event(type="msg", muser=user, target=channel, message=msg)
|
self.event(type="msg", muser=user, target=channel, message=msg)
|
||||||
|
@ -214,10 +213,8 @@ class IRCBot(IRCClient):
|
||||||
return newnick
|
return newnick
|
||||||
|
|
||||||
def nickChanged(self, olduser, newnick):
|
def nickChanged(self, olduser, newnick):
|
||||||
oldnick, ident, host = self.parsen(olduser)
|
|
||||||
userinfo.renameUser(self.net, oldnick, olduser, newnick, newnick+"!"+ident+"@"+host)
|
|
||||||
self.nickname = newnick
|
self.nickname = newnick
|
||||||
self.event(type="self", mtype="nick", nick=oldnick, ident=ident, host=host, user=newnick)
|
self.event(type="self", mtype="nick", muser=olduser, user=newnick)
|
||||||
|
|
||||||
def irc_ERR_NICKNAMEINUSE(self, prefix, params):
|
def irc_ERR_NICKNAMEINUSE(self, prefix, params):
|
||||||
self._attemptedNick = self.alterCollidedNick(self._attemptedNick)
|
self._attemptedNick = self.alterCollidedNick(self._attemptedNick)
|
||||||
|
@ -397,59 +394,47 @@ class IRCBot(IRCClient):
|
||||||
lc = self._getWho[channel]
|
lc = self._getWho[channel]
|
||||||
lc.stop()
|
lc.stop()
|
||||||
del self._getWho[channel]
|
del self._getWho[channel]
|
||||||
userinfo.delChannel(self.net, channel)
|
userinfo.delChannel(self.net, channel) # < we do not need to deduplicate this
|
||||||
log("Can no longer cover %s, removing records" % channel)
|
log("Can no longer cover %s, removing records" % channel) # as it will only be matched once --
|
||||||
|
# other bots have different nicknames so
|
||||||
def left(self, user, channel, message):
|
def left(self, user, channel, message): # even if they saw it, they wouldn't react
|
||||||
self.event(type="part", muser=user, target=channel, message=message)
|
self.event(type="part", muser=user, target=channel, message=message)
|
||||||
self.botLeft(channel)
|
self.botLeft(channel)
|
||||||
|
|
||||||
def userJoined(self, user, channel):
|
def userJoined(self, user, channel):
|
||||||
nick, ident, host = self.parsen(user)
|
self.event(type="join", muser=user, target=channel)
|
||||||
userinfo.addUser(self.net, channel, nick, user)
|
|
||||||
self.event(type="join", nick=nick, ident=ident, host=host, target=channel)
|
|
||||||
|
|
||||||
def userLeft(self, user, channel, message):
|
def userLeft(self, user, channel, message):
|
||||||
nick, ident, host = self.parsen(user)
|
self.event(type="part", muser=user, target=channel, message=message)
|
||||||
userinfo.delUser(self.net, channel, nick, user)
|
|
||||||
self.event(type="part", nick=nick, ident=ident, host=host, target=channel, message=message)
|
|
||||||
|
|
||||||
def userQuit(self, user, quitMessage):
|
def userQuit(self, user, quitMessage):
|
||||||
nick, ident, host = self.parsen(user)
|
self.chanlessEvent(type="quit", muser=user, message=quitMessage)
|
||||||
self.chanlessEvent(type="quit", nick=nick, ident=ident, host=host, message=quitMessage)
|
|
||||||
userinfo.delUserByNetwork(self.net, nick, user)
|
|
||||||
|
|
||||||
def userKicked(self, kickee, channel, kicker, message):
|
def userKicked(self, kickee, channel, kicker, message):
|
||||||
nick, ident, host = self.parsen(kicker)
|
if kickee.lower() == self.nickname.lower():
|
||||||
userinfo.editUser(self.net, kicker)
|
|
||||||
userinfo.delUserByNick(self.net, channel, kickee)
|
|
||||||
if kickee.lower == self.nickname.lower:
|
|
||||||
self.botLeft(channel)
|
self.botLeft(channel)
|
||||||
self.event(type="kick", nick=nick, ident=ident, host=host, target=channel, message=message, user=kickee)
|
self.event(type="kick", muser=kicker, target=channel, message=message, user=kickee)
|
||||||
|
|
||||||
def chanlessEvent(self, **cast):
|
def chanlessEvent(self, **cast):
|
||||||
chans = userinfo.getChansSingle(self.net, cast["nick"])
|
chans = userinfo.getChansSingle(self.net, cast["nick"])
|
||||||
if chans == None:
|
if chans == None:
|
||||||
self.event(**cast)
|
self.event(**cast)
|
||||||
return
|
return
|
||||||
|
# getChansSingle returns all channels of the user, we only want to use
|
||||||
|
# ones we have common with them
|
||||||
|
realChans = set(chans).intersection(set(self.channels))
|
||||||
for i in chans:
|
for i in chans:
|
||||||
cast["target"] = i
|
cast["target"] = i
|
||||||
self.event(**cast)
|
self.event(**cast)
|
||||||
|
|
||||||
def userRenamed(self, oldname, newname):
|
def userRenamed(self, oldname, newname):
|
||||||
nick, ident, host = self.parsen(oldname)
|
self.chanlessEvent(type="nick", muser=oldname, user=newname)
|
||||||
self.chanlessEvent(type="nick", nick=nick, ident=ident, host=host, user=newname)
|
|
||||||
userinfo.renameUser(self.net, nick, oldname, newname, newname+"!"+ident+"@"+host)
|
|
||||||
|
|
||||||
def topicUpdated(self, user, channel, newTopic):
|
def topicUpdated(self, user, channel, newTopic):
|
||||||
nick, ident, host = self.parsen(user)
|
self.event(type="topic", muser=user, target=channel, message= newTopic)
|
||||||
userinfo.editUser(self.net, user)
|
|
||||||
|
|
||||||
self.event(type="topic", nick=nick, ident=ident, host=host, target=channel, message= newTopic)
|
|
||||||
|
|
||||||
def modeChanged(self, user, channel, toset, modes, args):
|
def modeChanged(self, user, channel, toset, modes, args):
|
||||||
nick, ident, host = self.parsen(user)
|
nick, ident, host = self.parsen(user)
|
||||||
userinfo.editUser(self.net, user)
|
|
||||||
argList = list(args)
|
argList = list(args)
|
||||||
modeList = [i for i in modes]
|
modeList = [i for i in modes]
|
||||||
for a, m in zip(argList, modeList):
|
for a, m in zip(argList, modeList):
|
||||||
|
@ -490,7 +475,7 @@ class IRCBotFactory(ReconnectingClientFactory):
|
||||||
log("%s: connection lost: %s" % (self.name, error))
|
log("%s: connection lost: %s" % (self.name, error))
|
||||||
if not self.relay:
|
if not self.relay:
|
||||||
sendAll("%s: connection lost: %s" % (self.name, error))
|
sendAll("%s: connection lost: %s" % (self.name, error))
|
||||||
sendRelayNotification(self.name, {"type": "conn", "status": "lost", "message": error})
|
sendRelayNotification({"type": "conn", "name": self.name, "status": "lost", "message": error})
|
||||||
self.retry(connector)
|
self.retry(connector)
|
||||||
#ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
|
#ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
|
||||||
|
|
||||||
|
@ -502,7 +487,7 @@ class IRCBotFactory(ReconnectingClientFactory):
|
||||||
log("%s: connection failed: %s" % (self.name, error))
|
log("%s: connection failed: %s" % (self.name, error))
|
||||||
if not self.relay:
|
if not self.relay:
|
||||||
sendAll("%s: connection failed: %s" % (self.name, error))
|
sendAll("%s: connection failed: %s" % (self.name, error))
|
||||||
sendRelayNotification(self.name, {"type": "conn", "status": "failed", "message": error})
|
sendRelayNotification({"type": "conn", "name": self.name, "status": "failed", "message": error})
|
||||||
self.retry(connector)
|
self.retry(connector)
|
||||||
#ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
|
#ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
|
||||||
|
|
||||||
|
|
|
@ -132,11 +132,10 @@ class RelayFactory(Factory):
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
def sendRelayNotification(name, cast):
|
def sendRelayNotification(cast):
|
||||||
for i in main.relayConnections.keys():
|
for i in main.relayConnections.keys():
|
||||||
if main.relayConnections[i].authed:
|
if main.relayConnections[i].authed:
|
||||||
if cast["type"] in main.relayConnections[i].subscriptions:
|
if cast["type"] in main.relayConnections[i].subscriptions:
|
||||||
newCast = deepcopy(cast)
|
newCast = deepcopy(cast)
|
||||||
newCast["name"] = name
|
|
||||||
newCast["time"] = str(datetime.now().isoformat())
|
newCast["time"] = str(datetime.now().isoformat())
|
||||||
main.relayConnections[i].send(dumps(newCast))
|
main.relayConnections[i].send(dumps(newCast))
|
||||||
|
|
|
@ -3,6 +3,7 @@ from json import dumps
|
||||||
|
|
||||||
import main
|
import main
|
||||||
from core.relay import sendRelayNotification
|
from core.relay import sendRelayNotification
|
||||||
|
from modules import userinfo
|
||||||
|
|
||||||
def testNetTarget(name, target):
|
def testNetTarget(name, target):
|
||||||
called = False
|
called = False
|
||||||
|
@ -50,28 +51,49 @@ def magicFunction(A, B):
|
||||||
else:
|
else:
|
||||||
return all(A[k] in B[k] for k in set(A) & set(B)) and set(B) <= set(A)
|
return all(A[k] in B[k] for k in set(A) & set(B)) and set(B) <= set(A)
|
||||||
|
|
||||||
def event(name, numberedName, cast, event=None):
|
def event(c): # yes I'm using a short variable because otherwise it goes off the screen
|
||||||
if "target" in cast.keys():
|
if not "target" in c.keys():
|
||||||
target = cast["target"]
|
c["target"] = None
|
||||||
else:
|
|
||||||
target = None
|
|
||||||
|
|
||||||
sendRelayNotification(name, cast)
|
# metadata scraping
|
||||||
monitorGroups = testNetTarget(name, target)
|
# need to check if this was received from a relay
|
||||||
|
# in which case, do not do this
|
||||||
|
if c["type"] in ["msg", "notice", "action", "topic", "mode"]:
|
||||||
|
userinfo.editUser(c["name"], c["muser"])
|
||||||
|
elif c["type"] == "nick":
|
||||||
|
userinfo.renameUser(c["name"], c["nick"], c["muser"], c["user"], c["user"]+"!"+c["ident"]+"@"+c["host"])
|
||||||
|
elif c["type"] == "kick":
|
||||||
|
userinfo.editUser(c["name"], c["muser"])
|
||||||
|
userinfo.delUserByNick(c["name"], c["target"], c["user"])
|
||||||
|
elif c["type"] == "quit":
|
||||||
|
userinfo.delUserByNetwork(c["name"], c["nick"], c["muser"])
|
||||||
|
elif c["type"] == "join":
|
||||||
|
userinfo.addUser(c["name"], c["target"], c["nick"], c["user"])
|
||||||
|
elif c["type"] == "part":
|
||||||
|
userinfo.delUser(c["name"], c["target"], c["nick"], c["user"])
|
||||||
|
|
||||||
|
if "mtype" in c.keys():
|
||||||
|
if c["mtype"] == "nick":
|
||||||
|
userinfo.renameUser(c["name"], c["nick"], c["muser"], c["user"], c["user"]+"!"+c["ident"]+"@"+c["host"])
|
||||||
|
|
||||||
|
if "muser" in c.keys():
|
||||||
|
del c["muser"]
|
||||||
|
sendRelayNotification(c)
|
||||||
|
monitorGroups = testNetTarget(c["name"], c["target"])
|
||||||
if monitorGroups == False:
|
if monitorGroups == False:
|
||||||
return
|
return
|
||||||
for monitorGroup in monitorGroups:
|
for monitorGroup in monitorGroups:
|
||||||
matcher = magicFunction(deepcopy(cast), deepcopy(main.monitor[monitorGroup]))
|
matcher = magicFunction(deepcopy(c), deepcopy(main.monitor[monitorGroup]))
|
||||||
if matcher == True:
|
if matcher == True:
|
||||||
cast["monitor"] = True
|
c["monitor"] = True
|
||||||
if "send" in main.monitor[monitorGroup].keys():
|
if "send" in main.monitor[monitorGroup].keys():
|
||||||
for i in main.monitor[monitorGroup]["send"].keys():
|
for i in main.monitor[monitorGroup]["send"].keys():
|
||||||
if isinstance(main.monitor[monitorGroup]["send"][i], bool):
|
if isinstance(main.monitor[monitorGroup]["send"][i], bool):
|
||||||
sendRelayNotification(name, {"type": "err", "name": name, "target": target, "message": cast, "reason": "errdeliv"})
|
sendRelayNotification({"type": "err", "name": name, "target": target, "message": c, "reason": "errdeliv"})
|
||||||
continue
|
continue
|
||||||
if not i in main.pool.keys():
|
if not i in main.pool.keys():
|
||||||
sendRelayNotification(name, {"type": "err", "name": name, "target": target, "message": cast, "reason": "noname"})
|
sendRelayNotification({"type": "err", "name": name, "target": target, "message": c, "reason": "noname"})
|
||||||
if not i in main.IRCPool.keys():
|
if not i in main.IRCPool.keys():
|
||||||
sendRelayNotification(name, {"type": "err", "name": name, "target": target, "message": cast, "reason": "noinstance"})
|
sendRelayNotification({"type": "err", "name": name, "target": target, "message": c, "reason": "noinstance"})
|
||||||
for x in main.monitor[monitorGroup]["send"][i]:
|
for x in main.monitor[monitorGroup]["send"][i]:
|
||||||
main.IRCPool[i].msg(x, "monitor [%s] (%s) %s" % (monitorGroup, name, cast))
|
main.IRCPool[i].msg(x, "monitor [%s] (%s) %s" % (monitorGroup, c["name"], c))
|
||||||
|
|
|
@ -48,40 +48,40 @@ def provisionNetworkData(relay, alias, network, host, port, security, auth, pass
|
||||||
return
|
return
|
||||||
|
|
||||||
def provisionRelayForAlias(relay, alias):
|
def provisionRelayForAlias(relay, alias):
|
||||||
if "users" in main.relay[relay].keys():
|
#if "users" in main.relay[relay].keys():
|
||||||
if alias in main.relay[relay]["users"]:
|
# if alias in main.relay[relay]["users"]:
|
||||||
return "PROVISIONED"
|
# return "PROVISIONED"
|
||||||
else:
|
#else:
|
||||||
main.relay[relay]["users"] = []
|
# main.relay[relay]["users"] = []
|
||||||
main.relay[relay]["users"].append(alias)
|
#main.relay[relay]["users"].append(alias)
|
||||||
provisionUserData(relay, alias, main.alias[alias]["nick"],
|
provisionUserData(relay, alias, main.alias[alias]["nick"],
|
||||||
main.alias[alias]["altnick"],
|
main.alias[alias]["altnick"],
|
||||||
main.alias[alias]["ident"],
|
main.alias[alias]["ident"],
|
||||||
main.alias[alias]["realname"],
|
main.alias[alias]["realname"],
|
||||||
main.relay[relay]["password"])
|
main.relay[relay]["password"])
|
||||||
main.saveConf("relay")
|
#main.saveConf("relay")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def provisionRelayForNetwork(relay, alias, network):
|
def provisionRelayForNetwork(relay, alias, network):
|
||||||
if set(["users", "networks"]).issubset(main.relay[relay].keys()):
|
#if set(["users", "networks"]).issubset(main.relay[relay].keys()):
|
||||||
if network in main.relay[relay]["networks"] and alias in main.relay[relay]["users"]:
|
# if network in main.relay[relay]["networks"] and alias in main.relay[relay]["users"]:
|
||||||
return "PROVISIONED"
|
# return "PROVISIONED"
|
||||||
else:
|
#else:
|
||||||
main.relay[relay]["networks"] = []
|
# main.relay[relay]["networks"] = []
|
||||||
main.relay[relay]["networks"].append(network)
|
#main.relay[relay]["networks"].append(network)
|
||||||
provisionNetworkData(relay, alias, network,
|
provisionNetworkData(relay, alias, network,
|
||||||
main.network[network]["host"],
|
main.network[network]["host"],
|
||||||
main.network[network]["port"],
|
main.network[network]["port"],
|
||||||
main.network[network]["security"],
|
main.network[network]["security"],
|
||||||
main.network[network]["auth"],
|
main.network[network]["auth"],
|
||||||
main.alias[alias]["password"])
|
main.alias[alias]["password"])
|
||||||
main.saveConf("relay")
|
#main.saveConf("relay")
|
||||||
storedNetwork = False
|
storedNetwork = False
|
||||||
num = 1
|
num = 1
|
||||||
while not storedNetwork:
|
while not storedNetwork:
|
||||||
i = str(num)
|
i = str(num)
|
||||||
if num == 1000:
|
if num == 1000:
|
||||||
error("Too many iterations in while trying to choose name for r: %s a: %s n: %s" % (relay, alias, network))
|
error("Iteration limit exceeded while trying to choose name for r: %s a: %s n: %s" % (relay, alias, network))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if network+i in main.pool.keys():
|
if network+i in main.pool.keys():
|
||||||
|
|
Loading…
Reference in New Issue