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,8 +1,15 @@
|
||||
from twisted.internet.protocol import Protocol, Factory, ClientFactory
|
||||
from json import dumps, loads
|
||||
from copy import deepcopy
|
||||
from datetime import datetime
|
||||
|
||||
import main
|
||||
from utils.logging.log import *
|
||||
|
||||
validTypes = ["msg", "notice", "action", "who", "part", "join", "kick", "quit", "nick", "topic", "mode", "conn", "znc", "query", "self", "highlight", "monitor", "err"]
|
||||
|
||||
selfTypes = ["query", "self", "highlight"]
|
||||
|
||||
class Relay(Protocol):
|
||||
def __init__(self, addr):
|
||||
self.addr = addr
|
||||
@@ -40,11 +47,19 @@ class Relay(Protocol):
|
||||
return
|
||||
elif parsed["type"] == "control":
|
||||
if "subscribe" in parsed.keys():
|
||||
self.handleSubscribe(parsed["subscribe"])
|
||||
return
|
||||
if self.authed:
|
||||
self.handleSubscribe(parsed["subscribe"])
|
||||
return
|
||||
else:
|
||||
self.sendErr("DENIED")
|
||||
return
|
||||
elif "unsubscribe" in parsed.keys():
|
||||
self.handleUnsubscribe(parsed["unsubscribe"])
|
||||
return
|
||||
if self.authed:
|
||||
self.handleUnsubscribe(parsed["unsubscribe"])
|
||||
return
|
||||
else:
|
||||
self.sendErr("DENIED")
|
||||
return
|
||||
else:
|
||||
self.sendErr("UNCLEAR")
|
||||
return
|
||||
@@ -57,7 +72,7 @@ class Relay(Protocol):
|
||||
self.sendErr("NOTLIST")
|
||||
return
|
||||
for i in lst:
|
||||
if not i in ["msg", "notice", "action", "who", "part", "join", "kick", "quit", "nick", "topic", "mode"]:
|
||||
if not i in validTypes:
|
||||
self.sendErr("NONEXISTANT")
|
||||
return
|
||||
if i in self.subscriptions:
|
||||
@@ -72,7 +87,7 @@ class Relay(Protocol):
|
||||
self.sendErr("NOTLIST")
|
||||
return
|
||||
for i in lst:
|
||||
if not i in ["msg", "notice", "action", "who", "part", "join", "kick", "quit", "nick", "topic", "mode"]:
|
||||
if not i in validTypes:
|
||||
self.sendErr("NONEXISTANT")
|
||||
return
|
||||
if not i in self.subscriptions:
|
||||
@@ -118,3 +133,12 @@ class RelayFactory(Factory):
|
||||
connection.send(data)
|
||||
else:
|
||||
return
|
||||
|
||||
def sendRelayNotification(name, cast):
|
||||
for i in main.relayConnections.keys():
|
||||
if main.relayConnections[i].authed:
|
||||
if cast["type"] in main.relayConnections[i].subscriptions or set(main.relayConnections[i].subscriptions).issubset(cast):
|
||||
newCast = deepcopy(cast)
|
||||
newCast["name"] = name
|
||||
newCast["time"] = datetime.now()
|
||||
main.relayConnections[i].send(dumps(newCast))
|
||||
|
||||
Reference in New Issue
Block a user