Remove keyword system, implement ZNC notifications to relay, remove exact from cast fields and fix security bug in relay
This commit is contained in:
@@ -1,121 +0,0 @@
|
||||
import main
|
||||
from utils.logging.log import *
|
||||
import modules.counters as count
|
||||
|
||||
def sendMaster(data):
|
||||
if not len(main.MonitorPool) == 0:
|
||||
hasMonitors = True
|
||||
else:
|
||||
hasMonitors = False
|
||||
|
||||
if main.config["Master"] == [None, None]:
|
||||
if hasMonitors:
|
||||
for i in main.MonitorPool:
|
||||
main.connections[i].send(data)
|
||||
return
|
||||
else:
|
||||
main.masterbuf.append(data)
|
||||
main.saveConf("masterbuf")
|
||||
return
|
||||
|
||||
if main.config["Master"][0] in main.IRCPool.keys():
|
||||
if main.config["Master"][1] in main.IRCPool[main.config["Master"][0]].channels:
|
||||
main.IRCPool[main.config["Master"][0]].msg(main.config["Master"][1], data)
|
||||
else:
|
||||
if not hasMonitors:
|
||||
main.masterbuf.append(data)
|
||||
main.saveConf("masterbuf")
|
||||
else:
|
||||
if not hasMonitors:
|
||||
main.masterbuf.append(data)
|
||||
main.saveConf("masterbuf")
|
||||
|
||||
for i in main.MonitorPool:
|
||||
main.connections[i].send(data)
|
||||
|
||||
def isKeyword(msg):
|
||||
if msg == None:
|
||||
return
|
||||
message = msg.lower()
|
||||
messageDuplicate = message
|
||||
toUndo = False
|
||||
uniqueNum = 0
|
||||
totalNum = 0
|
||||
for i in main.keyconf["Keywords"]:
|
||||
if i in message:
|
||||
if i in main.keyconf["KeywordsExcept"].keys():
|
||||
for x in main.keyconf["KeywordsExcept"][i]:
|
||||
if x in message:
|
||||
toUndo = True
|
||||
messageDuplicate = messageDuplicate.replace(x, "\0\r\n\n\0")
|
||||
for y in main.keyconf["Keywords"]:
|
||||
if i in messageDuplicate:
|
||||
totalNum += messageDuplicate.count(i)
|
||||
message = messageDuplicate.replace(i, "{"+i+"}")
|
||||
message = message.replace("\0\r\n\n\0", x)
|
||||
uniqueNum += 1
|
||||
|
||||
if toUndo == False:
|
||||
totalNum += message.count(i)
|
||||
message = message.replace(i, "{"+i+"}")
|
||||
uniqueNum += 1
|
||||
|
||||
toUndo = False
|
||||
|
||||
if totalNum == 0:
|
||||
return False
|
||||
else:
|
||||
return [message, uniqueNum, totalNum]
|
||||
|
||||
def actKeyword(user, channel, message, nickname, actType, name):
|
||||
if message == None:
|
||||
return
|
||||
toSend = isKeyword(message)
|
||||
if name == main.config["Master"][0] and channel == main.config["Master"][1]:
|
||||
pass
|
||||
else:
|
||||
msgLower = message.lower()
|
||||
nickLower = nickname.lower()
|
||||
if nickLower in msgLower: # Someone has said the bot's nickname
|
||||
msgLower = msgLower.replace(nickLower, "{"+nickLower+"}")
|
||||
count.event(name, "nickhighlight")
|
||||
if main.config["Notifications"]["Highlight"]:
|
||||
sendMaster("NICK %s %s (T:%s): (%s/%s) %s" % (actType, name, msgLower.count(nickLower), user, channel, msgLower))
|
||||
if not channel == None:
|
||||
chanLower = channel.lower()
|
||||
if nickLower == chanLower: # I received a message directed only at me
|
||||
ZNCAlreadySent = False
|
||||
if main.config["Notifications"]["Query"]:
|
||||
if user == main.config["Tweaks"]["ZNC"]["Prefix"] + "status!znc@znc.in":
|
||||
if main.config["Compat"]["ZNC"]:
|
||||
sendMaster("ZNC %s %s: %s" % (actType, name, msgLower))
|
||||
ZNCAlreadySent = True
|
||||
else:
|
||||
sendMaster("QUERY %s %s: (%s) %s" % (actType, name, user, msgLower))
|
||||
else:
|
||||
sendMaster("QUERY %s %s: (%s) %s" % (actType, name, user, msgLower))
|
||||
if not ZNCAlreadySent == True:
|
||||
if main.config["Compat"]["ZNC"]:
|
||||
if user == main.config["Tweaks"]["ZNC"]["Prefix"] + "status!znc@znc.in":
|
||||
sendMaster("ZNC %s %s: %s" % (actType, name, msgLower))
|
||||
if toSend:
|
||||
sendMaster("MATCH %s %s (U:%s T:%s): (%s/%s) %s" % (actType, name, toSend[1], toSend[2], user, channel, toSend[0]))
|
||||
count.event(name, "keymatch")
|
||||
|
||||
def addKeyword(keyword):
|
||||
if keyword in main.keyconf["Keywords"]:
|
||||
return "EXISTS"
|
||||
else:
|
||||
for i in main.keyconf["Keywords"]:
|
||||
if i in keyword or keyword in i:
|
||||
return "ISIN"
|
||||
main.keyconf["Keywords"].append(keyword)
|
||||
main.saveConf("keyconf")
|
||||
return True
|
||||
|
||||
def delKeyword(keyword):
|
||||
if not keyword in main.keyconf["Keywords"]:
|
||||
return "NOKEY"
|
||||
main.keyconf["Keywords"].remove(keyword)
|
||||
main.saveConf("keyconf")
|
||||
return True
|
||||
@@ -1,8 +1,9 @@
|
||||
import main
|
||||
import modules.keyword as keyword
|
||||
from copy import deepcopy
|
||||
from json import dumps
|
||||
|
||||
import main
|
||||
from core.relay import sendRelayNotification
|
||||
|
||||
def testNetTarget(name, target):
|
||||
called = False
|
||||
for i in main.monitor.keys():
|
||||
@@ -49,32 +50,33 @@ def magicFunction(A, B):
|
||||
else:
|
||||
return all(A[k] in B[k] for k in set(A) & set(B)) and set(B) <= set(A)
|
||||
|
||||
def event(name, target, cast):
|
||||
for i in main.relayConnections.keys():
|
||||
if main.relayConnections[i].authed and cast["type"] in main.relayConnections[i].subscriptions:
|
||||
newCast = deepcopy(cast)
|
||||
if not target == None:
|
||||
newCast["target"] = target
|
||||
if "exact" in newCast.keys():
|
||||
del newCast["exact"]
|
||||
newCast["name"] = name
|
||||
main.relayConnections[i].send(dumps(newCast))
|
||||
def event(name, cast, event=None):
|
||||
if "target" in cast.keys():
|
||||
target = cast["target"]
|
||||
else:
|
||||
target = None
|
||||
if set(["nick", "ident", "host", "message"]).issubset(set(cast)):
|
||||
if main.config["Compat"]["ZNC"] and "message" in cast.keys():
|
||||
if cast["nick"][0] == main.config["Tweaks"]["ZNC"]["Prefix"] and cast["ident"] == "znc" and cast["host"] == "znc.in":
|
||||
sendRelayNotification(name, {"type": "znc", "message": cast["message"]})
|
||||
return
|
||||
|
||||
sendRelayNotification(name, cast)
|
||||
monitorGroups = testNetTarget(name, target)
|
||||
if monitorGroups == False:
|
||||
return
|
||||
for monitorGroup in monitorGroups:
|
||||
matcher = magicFunction(deepcopy(cast), deepcopy(main.monitor[monitorGroup]))
|
||||
if matcher == True:
|
||||
cast["monitor"] = True
|
||||
if "send" in main.monitor[monitorGroup].keys():
|
||||
for i in main.monitor[monitorGroup]["send"].keys():
|
||||
if isinstance(main.monitor[monitorGroup]["send"][i], bool):
|
||||
keyword.sendMaster("ERRDELIV MONITOR [%s] (%s/%s) %s " % (monitorGroup, name, target, cast))
|
||||
sendRelayNotification(name, {"type": "err", "name": name, "target": target, "message": cast, "reason": "errdeliv"})
|
||||
continue
|
||||
if not i in main.pool.keys():
|
||||
keyword.sendMaster("ERROR on monitor %s: No such name: %s" % (monitorGroup, i))
|
||||
sendRelayNotification(name, {"type": "err", "name": name, "target": target, "message": cast, "reason": "noname"})
|
||||
if not i in main.IRCPool.keys():
|
||||
keyword.sendMaster("ERROR on monitor %s: No such instance: %s" % (monitorGroup, i))
|
||||
sendRelayNotification(name, {"type": "err", "name": name, "target": target, "message": cast, "reason": "noinstance"})
|
||||
for x in main.monitor[monitorGroup]["send"][i]:
|
||||
main.IRCPool[i].msg(x, "MONITOR [%s] (%s/%s) %s" % (monitorGroup, name, target, cast))
|
||||
else:
|
||||
keyword.sendMaster("MONITOR [%s] (%s/%s) %s " % (monitorGroup, name, target, cast))
|
||||
main.IRCPool[i].msg(x, "monitor [%s] (%s) %s" % (monitorGroup, name, cast))
|
||||
|
||||
Reference in New Issue
Block a user