Update modules/ban_engine.py
This commit is contained in:
parent
7961f0c769
commit
7d7fd5a32c
1 changed files with 29 additions and 5 deletions
|
@ -1,15 +1,39 @@
|
||||||
import os, sys
|
import os, sys, sqlite3
|
||||||
from __main__ import config
|
from __main__ import config
|
||||||
__ircat_type__ = "allsocket"
|
__ircat_type__ = "allsocket"
|
||||||
__ircat_requires__ = "ban-provider"
|
__ircat_requires__ = ["ban-provider", "host"]
|
||||||
class IRCatModule:
|
class IRCatModule:
|
||||||
memory = {} # {ip: [content]}
|
memory = {} # {ip: [content]}
|
||||||
useSQLengine = False
|
useSQLengine = False
|
||||||
def __init__(self, ban_provider):
|
def __init__(self, ban_provider, host):
|
||||||
self.ban_provider = ban_provider
|
self.ban_provider = ban_provider
|
||||||
if ban_provider = "sql":
|
if ban_provider = "sql":
|
||||||
|
self.host = host
|
||||||
self.useSQLengine = True
|
self.useSQLengine = True
|
||||||
|
self.SQLengine = config
|
||||||
def onValidate(self, socket, ip):
|
def onValidate(self, socket, ip):
|
||||||
pass
|
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):
|
def onSocket(self, socket, value, ip, cachedNick=None):
|
||||||
pass
|
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
|
||||||
|
def ban(self, target_mask, reason="The ban() hammer has spoken!"):
|
||||||
|
if self.useSQLengine:
|
||||||
|
cur = self.SQLengine.conn.cursor()
|
||||||
|
else:
|
||||||
|
open(self.ban_provider, "a").write(f"\n{target_mask} {reason}")
|
Loading…
Reference in a new issue