From d525b4a91e91de611f8217b3c23be5b13d6123cf Mon Sep 17 00:00:00 2001 From: swee Date: Fri, 10 Jan 2025 18:54:51 -0800 Subject: [PATCH] Update modules/ban_engine.py --- modules/ban_engine.py | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/modules/ban_engine.py b/modules/ban_engine.py index 156861a..a979f7f 100644 --- a/modules/ban_engine.py +++ b/modules/ban_engine.py @@ -12,26 +12,29 @@ class IRCatModule: self.useSQLengine = True self.SQLengine = sql def onValidate(self, socket, ip): - print("IP is banned, killing connection now...") - reason = " ".join(i.split(" ")[1:]) - host = self.host - socket.sendall(bytes(f":{host} 465 * :You are banned from this server\r\n","UTF-8")) - socket.sendall(bytes(f"ERROR :Closing Link: {ip} (K-Lined: {reason})\r\n","UTF-8")) - raise Exception("K-Lined: " + " ".join(i.split(" ")[1:])) - def onSocket(self, socket, value, ip, cachedNick=None): - if self.useSQLengine: - pass - else: - bans = open(self.ban_provider).read().split("\n") - for i in bans: - if ip in i.split(" ")[0]: - print("IP is banned, killing connection now...") - reason = " ".join(i.split(" ")[1:]) - host = self.host - socket.sendall(bytes(f":{host} 465 * :You are banned from this server\r\n","UTF-8")) - socket.sendall(bytes(f"ERROR :Closing Link: {ip} (K-Lined: {reason})\r\n","UTF-8")) - raise Exception("Banned: " + " ".join(i.split(" ")[1:])) - pass + bans = open(self.ban_provider).read().split("\n") + for i in bans: + if ip in i.split(" ")[0]: + print("IP is banned, killing connection now...") + reason = " ".join(i.split(" ")[1:]) + host = self.host + socket.sendall(bytes(f":{host} 465 * :You are banned from this server\r\n","UTF-8")) + socket.sendall(bytes(f"ERROR :Closing Link: {ip} (K-Lined: {reason})\r\n","UTF-8")) + raise Exception("K-Lined: " + " ".join(i.split(" ")[1:])) + def onSocket(self, socket, value, ip, cachedNick=None, validated=False): + if validated: + if self.useSQLengine: + pass + else: + bans = open(self.ban_provider).read().split("\n") + for i in bans: + if ip in i.split(" ")[0]: + print("IP is banned, killing connection now...") + reason = " ".join(i.split(" ")[1:]) + host = self.host + socket.sendall(bytes(f":{host} 465 * :You are banned from this server\r\n","UTF-8")) + socket.sendall(bytes(f"ERROR :Closing Link: {ip} (K-Lined: {reason})\r\n","UTF-8")) + raise Exception("Banned: " + " ".join(i.split(" ")[1:])) def ban(self, target_mask, reason="The ban() hammer has spoken!"): if self.useSQLengine: cur = self.SQLengine.conn.cursor()