From c4941a26c1f1d127a7eaa315705aedc439edb15d Mon Sep 17 00:00:00 2001 From: Georg Date: Thu, 26 Aug 2021 11:41:41 +0200 Subject: Init Signed-off-by: Georg --- plugin.py | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 94 insertions(+), 4 deletions(-) (limited to 'plugin.py') diff --git a/plugin.py b/plugin.py index 8c3717e..7cab169 100644 --- a/plugin.py +++ b/plugin.py @@ -43,17 +43,87 @@ import os import sys import time import sqlite3 +import redis +import json +from ipwhois import IPWhois +import ipwhois class SnoParser(callbacks.Plugin): """Parses the Server Notices from ErgoIRCd""" threaded = True + def redis_connect() -> redis.client.Redis: + try: + redis_client = redis.Redis( + host="localhost", + port=6378, + #password="test", + db=0, + socket_timeout=5, + ) + ping = redis_client.ping() + if ping is True: + return redis_client + except redis.AuthenticationError: + print("Could not authenticate to Redis backend.") + + redis_client = redis_connect() + + def whois_fresh(coordinates: str) -> dict: + """Data from cache.""" + asn = 0 + subnet = '' + try: + whois = IPWhois(coordinates) + whoisres = whois.lookup_rdap(depth=1,retry_count=0) + results = whoisres + print(results) + asn = whoisres['asn_registry'] + country = whoisres['asn_country_code'] + description = whoisres['asn_description'] + whoisout = asn + ' ' + country + ' ' + description + except ipwhois.exceptions.IPDefinedError: + whoisout = 'RFC 4291 (Local)' + + rr = f"{results}" + response = SnoParser.redis_client.get(rr) + return response.json() + + def whois_get_cache(key: str) -> str: + """Data from Redis.""" + + val = SnoParser.redis_client.get(key) + return val + + def whois_set_cache(key: str, value: str) -> bool: + """Data to Redis.""" + + state = client.setex(key, timedelta(seconds=3600), value=value,) + return state + + def whois_run(coordinates: str) -> dict: + data = SnoParser.whois_get_cache(key=coordinates) + if data is not None: + data = json.loads(data) + data["cache"] = True + return data + else: + data = SnoParser.whois_fresh(coordinates) + if data.get("code") == "Ok": + data["cache"] = False + data = json.dumps(data) + state = self.whois_set_cache(key=coordinates, value=data) + + if state is True: + return json.loads(data) + return data + + def doNotice(self, irc, msg): (target, text) = msg.args + if target == irc.nick: - # server notices CONNECT, KILL, XLINE, NICK, ACCOUNT - text = ircutils.stripFormatting(text) if 'CONNECT' in text: connregex = "^-CONNECT- Client connected \[(.+)\] \[u\:~(.+)\] \[h\:(.+)\] \[ip\:(.+)\] \[r\:(.+)\]$" @@ -61,12 +131,32 @@ class SnoParser(callbacks.Plugin): nickname = couple.group(1) username = couple.group(2) host = couple.group(3) - ip = couple.group(4) + #ip = couple.group(4) + ip = '81.217.9.47' realname = couple.group(5) ip_seen = 0 nick_seen = 0 + asn = 0 + subnet = '' + + SnoParser.whois_run(coordinates=ip) + +# try: +# #whois = IPWhois(ip) +# #whoisres = whois.lookup_rdap(depth=1,retry_count=0) +# #results = whoisres +# whoisres = data +# print(results) +# asn = whoisres['asn_registry'] +# country = whoisres['asn_country_code'] +# description = whoisres['asn_description'] +# whoisout = asn + ' ' + country + ' ' + description +# except ipwhois.exceptions.IPDefinedError: +# whoisout = 'RFC 4291 (Local)' DictFromSnotice = {'notice': 'connect', 'nickname': nickname, 'username': username, 'host': host, 'ip': ip, 'realname': realname, 'ipCount': ip_seen, 'nickCount': nick_seen} - repl = f"\x02\x1FNOTICE: {DictFromSnotice['notice']} \x0F\x11\x0303==>>\x0F \x02Nick:\x0F {DictFromSnotice['nickname']} \x02Username:\x0F {DictFromSnotice['username']} \x02Hostname:\x0F {DictFromSnotice['host']} \x02IP:\x0F {DictFromSnotice['ip']} \x02Realname:\x0F {DictFromSnotice['realname']} \x02IPcount:\x0F {DictFromSnotice['ipCount']} \x02NickCount:\x0F {DictFromSnotice['nickCount']}" + #repl = f"\x02\x1FNOTICE: {DictFromSnotice['notice']} \x0F\x11\x0303==>>\x0F \x02Nick:\x0F {DictFromSnotice['nickname']} \x02Username:\x0F {DictFromSnotice['username']} \x02Hostname:\x0F {DictFromSnotice['host']} \x02IP:\x0F {DictFromSnotice['ip']} \x02Realname:\x0F {DictFromSnotice['realname']} \x02IPcount:\x0F {DictFromSnotice['ipCount']} \x02NickCount:\x0F {DictFromSnotice['nickCount']}" + repl = f"\x02\x1F{DictFromSnotice['notice']} \x0F\x11\x0303==>>\x0F \x02Nick:\x0F {DictFromSnotice['nickname']} \x02Username:\x0F {DictFromSnotice['username']} \x02Hostname:\x0F {DictFromSnotice['host']} \x02IP:\x0F {DictFromSnotice['ip']} {whoisout} \x02Realname:\x0F {DictFromSnotice['realname']} \x02IPcount:\x0F {DictFromSnotice['ipCount']} \x02NickCount:\x0F {DictFromSnotice['nickCount']}" + self._sendSnotice(irc, msg, repl) if 'XLINE' in text and 'temporary' in text: xlineregex = "^-XLINE- (.+) \[(.+)\] added temporary \((.+)\) (K-Line|D-Line) for (.+)$" -- cgit v1.2.3 From f796a296911f71edc80e9e24e33413ce91af9003 Mon Sep 17 00:00:00 2001 From: Georg Date: Thu, 26 Aug 2021 12:50:25 +0200 Subject: First working Redis cache Signed-off-by: Georg --- plugin.py | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) (limited to 'plugin.py') diff --git a/plugin.py b/plugin.py index 7cab169..bfa31a9 100644 --- a/plugin.py +++ b/plugin.py @@ -45,6 +45,7 @@ import time import sqlite3 import redis import json +from datetime import timedelta from ipwhois import IPWhois import ipwhois @@ -81,13 +82,16 @@ class SnoParser(callbacks.Plugin): asn = whoisres['asn_registry'] country = whoisres['asn_country_code'] description = whoisres['asn_description'] - whoisout = asn + ' ' + country + ' ' + description + whoisout = 'WHOIS ' + asn + ' ' + country + ' ' + description except ipwhois.exceptions.IPDefinedError: whoisout = 'RFC 4291 (Local)' - rr = f"{results}" - response = SnoParser.redis_client.get(rr) - return response.json() +# rr = f"{results}" +# response = rr +# return response.json() +# response = results + response = whoisout + return response def whois_get_cache(key: str) -> str: """Data from Redis.""" @@ -98,24 +102,37 @@ class SnoParser(callbacks.Plugin): def whois_set_cache(key: str, value: str) -> bool: """Data to Redis.""" - state = client.setex(key, timedelta(seconds=3600), value=value,) + state = SnoParser.redis_client.setex(key, timedelta(seconds=3600), value=value,) return state def whois_run(coordinates: str) -> dict: data = SnoParser.whois_get_cache(key=coordinates) if data is not None: data = json.loads(data) - data["cache"] = True + #data["cache"] = True + print("DEBUG - CACHE: TRUE") + print(data) + print(coordinates) return data else: data = SnoParser.whois_fresh(coordinates) - if data.get("code") == "Ok": - data["cache"] = False + print("ELSE WHOIS_FRESH CALLED") + print(data) + print(coordinates) + if data.startswith("WHOIS"): + #data["cache"] = False + print("DEBUG - CACHE: FALSE") data = json.dumps(data) - state = self.whois_set_cache(key=coordinates, value=data) + state = SnoParser.whois_set_cache(key=coordinates, value=data) + + print(data) + print(coordinates) if state is True: return json.loads(data) + else: + print("Data does not start with correct string") + print(data) return data @@ -132,14 +149,18 @@ class SnoParser(callbacks.Plugin): username = couple.group(2) host = couple.group(3) #ip = couple.group(4) - ip = '81.217.9.47' + ip = '::1' realname = couple.group(5) ip_seen = 0 nick_seen = 0 asn = 0 subnet = '' - SnoParser.whois_run(coordinates=ip) +# SnoParser.whois_run(coordinates=ip) + whoisout = SnoParser.whois_run(ip) +# whoisout = SnoParser.whois_run(whoisout) +# SnoParser.whois_run(ip) +# whoisout = SnoParser.whois_run.coordinates # try: # #whois = IPWhois(ip) -- cgit v1.2.3 From 415d5df94ce6ed024302852dd3fca6bc07dcaf99 Mon Sep 17 00:00:00 2001 From: Georg Date: Thu, 26 Aug 2021 13:51:26 +0200 Subject: First prettifications of Redis cached whois Signed-off-by: Georg --- plugin.py | 56 +++++++++++++++++++------------------------------------- 1 file changed, 19 insertions(+), 37 deletions(-) (limited to 'plugin.py') diff --git a/plugin.py b/plugin.py index bfa31a9..6b29756 100644 --- a/plugin.py +++ b/plugin.py @@ -56,11 +56,12 @@ class SnoParser(callbacks.Plugin): def redis_connect() -> redis.client.Redis: try: redis_client = redis.Redis( - host="localhost", - port=6378, - #password="test", - db=0, - socket_timeout=5, + host = .registryValue('whois.redis.host'), + port = self.registryValue('whois.redis.port'), + password = self.registryValue('whois.redis.password'), + username = self.registryValue('whois.redis.username'), + db = self.registryValue('whois.redis.db'), + socket_timeout = self.registryValue('whois.redis.timeout') ) ping = redis_client.ping() if ping is True: @@ -70,12 +71,12 @@ class SnoParser(callbacks.Plugin): redis_client = redis_connect() - def whois_fresh(coordinates: str) -> dict: + def whois_fresh(sourceip: str) -> dict: """Data from cache.""" asn = 0 subnet = '' try: - whois = IPWhois(coordinates) + whois = IPWhois(sourceip) whoisres = whois.lookup_rdap(depth=1,retry_count=0) results = whoisres print(results) @@ -86,10 +87,6 @@ class SnoParser(callbacks.Plugin): except ipwhois.exceptions.IPDefinedError: whoisout = 'RFC 4291 (Local)' -# rr = f"{results}" -# response = rr -# return response.json() -# response = results response = whoisout return response @@ -105,28 +102,30 @@ class SnoParser(callbacks.Plugin): state = SnoParser.redis_client.setex(key, timedelta(seconds=3600), value=value,) return state - def whois_run(coordinates: str) -> dict: - data = SnoParser.whois_get_cache(key=coordinates) + def whois_run(sourceip: str) -> dict: + """Whois query router.""" + + data = SnoParser.whois_get_cache(key=sourceip) if data is not None: data = json.loads(data) #data["cache"] = True print("DEBUG - CACHE: TRUE") print(data) - print(coordinates) + print(sourceip) return data else: - data = SnoParser.whois_fresh(coordinates) - print("ELSE WHOIS_FRESH CALLED") + data = SnoParser.whois_fresh(sourceip) + print("DEBUG - ELSE WHOIS_FRESH CALLED") print(data) - print(coordinates) + print(sourceip) if data.startswith("WHOIS"): #data["cache"] = False print("DEBUG - CACHE: FALSE") data = json.dumps(data) - state = SnoParser.whois_set_cache(key=coordinates, value=data) + state = SnoParser.whois_set_cache(key=sourceip, value=data) print(data) - print(coordinates) + print(sourceip) if state is True: return json.loads(data) @@ -149,31 +148,14 @@ class SnoParser(callbacks.Plugin): username = couple.group(2) host = couple.group(3) #ip = couple.group(4) - ip = '::1' + ip = '2a03:4000:55:d20::' realname = couple.group(5) ip_seen = 0 nick_seen = 0 asn = 0 subnet = '' -# SnoParser.whois_run(coordinates=ip) whoisout = SnoParser.whois_run(ip) -# whoisout = SnoParser.whois_run(whoisout) -# SnoParser.whois_run(ip) -# whoisout = SnoParser.whois_run.coordinates - -# try: -# #whois = IPWhois(ip) -# #whoisres = whois.lookup_rdap(depth=1,retry_count=0) -# #results = whoisres -# whoisres = data -# print(results) -# asn = whoisres['asn_registry'] -# country = whoisres['asn_country_code'] -# description = whoisres['asn_description'] -# whoisout = asn + ' ' + country + ' ' + description -# except ipwhois.exceptions.IPDefinedError: -# whoisout = 'RFC 4291 (Local)' DictFromSnotice = {'notice': 'connect', 'nickname': nickname, 'username': username, 'host': host, 'ip': ip, 'realname': realname, 'ipCount': ip_seen, 'nickCount': nick_seen} #repl = f"\x02\x1FNOTICE: {DictFromSnotice['notice']} \x0F\x11\x0303==>>\x0F \x02Nick:\x0F {DictFromSnotice['nickname']} \x02Username:\x0F {DictFromSnotice['username']} \x02Hostname:\x0F {DictFromSnotice['host']} \x02IP:\x0F {DictFromSnotice['ip']} \x02Realname:\x0F {DictFromSnotice['realname']} \x02IPcount:\x0F {DictFromSnotice['ipCount']} \x02NickCount:\x0F {DictFromSnotice['nickCount']}" repl = f"\x02\x1F{DictFromSnotice['notice']} \x0F\x11\x0303==>>\x0F \x02Nick:\x0F {DictFromSnotice['nickname']} \x02Username:\x0F {DictFromSnotice['username']} \x02Hostname:\x0F {DictFromSnotice['host']} \x02IP:\x0F {DictFromSnotice['ip']} {whoisout} \x02Realname:\x0F {DictFromSnotice['realname']} \x02IPcount:\x0F {DictFromSnotice['ipCount']} \x02NickCount:\x0F {DictFromSnotice['nickCount']}" -- cgit v1.2.3 From a8665607bbef6f96955ef53e1c14a4aa85a1f8d8 Mon Sep 17 00:00:00 2001 From: Georg Date: Thu, 26 Aug 2021 13:52:34 +0200 Subject: Adding name to license blocks Signed-off-by: Georg --- plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugin.py') diff --git a/plugin.py b/plugin.py index 6b29756..997b2bd 100644 --- a/plugin.py +++ b/plugin.py @@ -1,5 +1,5 @@ ### -# Copyright (c) 2021, mogad0n +# Copyright (c) 2021, mogad0n and Georg Pfuetzenreuter # All rights reserved. # # Redistribution and use in source and binary forms, with or without -- cgit v1.2.3 From 7d9db9dd9d75b5a3aaff4617b95563125d9c1bdf Mon Sep 17 00:00:00 2001 From: Georg Date: Thu, 26 Aug 2021 16:36:34 +0200 Subject: Moving Redis options to config values Signed-off-by: Georg --- plugin.py | 50 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 15 deletions(-) (limited to 'plugin.py') diff --git a/plugin.py b/plugin.py index 997b2bd..39e2457 100644 --- a/plugin.py +++ b/plugin.py @@ -53,25 +53,27 @@ class SnoParser(callbacks.Plugin): """Parses the Server Notices from ErgoIRCd""" threaded = True - def redis_connect() -> redis.client.Redis: + def redis_connect(self) -> redis.client.Redis: try: redis_client = redis.Redis( - host = .registryValue('whois.redis.host'), + host = self.registryValue('whois.redis.host'), port = self.registryValue('whois.redis.port'), password = self.registryValue('whois.redis.password'), username = self.registryValue('whois.redis.username'), db = self.registryValue('whois.redis.db'), - socket_timeout = self.registryValue('whois.redis.timeout') + socket_timeout = int(self.registryValue('whois.redis.timeout')) ) ping = redis_client.ping() if ping is True: return redis_client except redis.AuthenticationError: print("Could not authenticate to Redis backend.") - - redis_client = redis_connect() - def whois_fresh(sourceip: str) -> dict: + def __init__(self, irc): + super().__init__(irc) + self.redis_client = self.redis_connect() + + def whois_fresh(self, sourceip: str) -> dict: """Data from cache.""" asn = 0 subnet = '' @@ -90,22 +92,26 @@ class SnoParser(callbacks.Plugin): response = whoisout return response - def whois_get_cache(key: str) -> str: + def whois_get_cache(self, key: str) -> str: """Data from Redis.""" - val = SnoParser.redis_client.get(key) + k = self.redis_client.get(key) + +# self = SnoParser() +# val = self.redis_client.get(key) + val = k return val - def whois_set_cache(key: str, value: str) -> bool: + def whois_set_cache(self, key: str, value: str) -> bool: """Data to Redis.""" - state = SnoParser.redis_client.setex(key, timedelta(seconds=3600), value=value,) + state = self.redis_client.setex(key, timedelta(seconds=3600), value=value,) return state - def whois_run(sourceip: str) -> dict: + def whois_run(self, sourceip: str) -> dict: """Whois query router.""" - data = SnoParser.whois_get_cache(key=sourceip) + data = self.whois_get_cache(key=sourceip) if data is not None: data = json.loads(data) #data["cache"] = True @@ -114,7 +120,7 @@ class SnoParser(callbacks.Plugin): print(sourceip) return data else: - data = SnoParser.whois_fresh(sourceip) + data = self.whois_fresh(sourceip) print("DEBUG - ELSE WHOIS_FRESH CALLED") print(data) print(sourceip) @@ -122,7 +128,7 @@ class SnoParser(callbacks.Plugin): #data["cache"] = False print("DEBUG - CACHE: FALSE") data = json.dumps(data) - state = SnoParser.whois_set_cache(key=sourceip, value=data) + state = self.whois_set_cache(key=sourceip, value=data) print(data) print(sourceip) @@ -134,6 +140,20 @@ class SnoParser(callbacks.Plugin): print(data) return data + def query(self, irc, msg, args, ipaddress): + """ + Queries the cache for an address. + """ + + data = self.whois_get_cache(key=ipaddress) + ttl = self.redis_client.get(ipaddress) + + print(data, ' ', ttl) + #irc.reply(str(data), ' Remaining: ', int(ttl), 's') + irc.reply(data, ttl) + + query = wrap(query, ['anything']) + def doNotice(self, irc, msg): (target, text) = msg.args @@ -155,7 +175,7 @@ class SnoParser(callbacks.Plugin): asn = 0 subnet = '' - whoisout = SnoParser.whois_run(ip) + whoisout = self.whois_run(sourceip=ip) DictFromSnotice = {'notice': 'connect', 'nickname': nickname, 'username': username, 'host': host, 'ip': ip, 'realname': realname, 'ipCount': ip_seen, 'nickCount': nick_seen} #repl = f"\x02\x1FNOTICE: {DictFromSnotice['notice']} \x0F\x11\x0303==>>\x0F \x02Nick:\x0F {DictFromSnotice['nickname']} \x02Username:\x0F {DictFromSnotice['username']} \x02Hostname:\x0F {DictFromSnotice['host']} \x02IP:\x0F {DictFromSnotice['ip']} \x02Realname:\x0F {DictFromSnotice['realname']} \x02IPcount:\x0F {DictFromSnotice['ipCount']} \x02NickCount:\x0F {DictFromSnotice['nickCount']}" repl = f"\x02\x1F{DictFromSnotice['notice']} \x0F\x11\x0303==>>\x0F \x02Nick:\x0F {DictFromSnotice['nickname']} \x02Username:\x0F {DictFromSnotice['username']} \x02Hostname:\x0F {DictFromSnotice['host']} \x02IP:\x0F {DictFromSnotice['ip']} {whoisout} \x02Realname:\x0F {DictFromSnotice['realname']} \x02IPcount:\x0F {DictFromSnotice['ipCount']} \x02NickCount:\x0F {DictFromSnotice['nickCount']}" -- cgit v1.2.3 From a458460cec77aceefdcd9b966e5c1813ea16c883 Mon Sep 17 00:00:00 2001 From: Georg Date: Thu, 26 Aug 2021 16:58:04 +0200 Subject: Adding option for sample IP Signed-off-by: Georg --- plugin.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'plugin.py') diff --git a/plugin.py b/plugin.py index 39e2457..10eddb5 100644 --- a/plugin.py +++ b/plugin.py @@ -85,7 +85,7 @@ class SnoParser(callbacks.Plugin): asn = whoisres['asn_registry'] country = whoisres['asn_country_code'] description = whoisres['asn_description'] - whoisout = 'WHOIS ' + asn + ' ' + country + ' ' + description + whoisout = '# ' + asn + ' ' + country + ' ' + description except ipwhois.exceptions.IPDefinedError: whoisout = 'RFC 4291 (Local)' @@ -124,7 +124,7 @@ class SnoParser(callbacks.Plugin): print("DEBUG - ELSE WHOIS_FRESH CALLED") print(data) print(sourceip) - if data.startswith("WHOIS"): + if data.startswith("#"): #data["cache"] = False print("DEBUG - CACHE: FALSE") data = json.dumps(data) @@ -167,8 +167,10 @@ class SnoParser(callbacks.Plugin): nickname = couple.group(1) username = couple.group(2) host = couple.group(3) - #ip = couple.group(4) - ip = '2a03:4000:55:d20::' + if self.registryValue('whois.sample'): + ip = self.registryValue('whois.sample') + else: + ip = couple.group(4) realname = couple.group(5) ip_seen = 0 nick_seen = 0 -- cgit v1.2.3 From 708e4b70755ecb71e63602077f2424965f277049 Mon Sep 17 00:00:00 2001 From: Georg Date: Thu, 26 Aug 2021 17:30:38 +0200 Subject: Improved debug and manual query Signed-off-by: Georg --- plugin.py | 59 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 29 insertions(+), 30 deletions(-) (limited to 'plugin.py') diff --git a/plugin.py b/plugin.py index 10eddb5..d47440f 100644 --- a/plugin.py +++ b/plugin.py @@ -78,16 +78,17 @@ class SnoParser(callbacks.Plugin): asn = 0 subnet = '' try: - whois = IPWhois(sourceip) - whoisres = whois.lookup_rdap(depth=1,retry_count=0) - results = whoisres - print(results) - asn = whoisres['asn_registry'] - country = whoisres['asn_country_code'] - description = whoisres['asn_description'] - whoisout = '# ' + asn + ' ' + country + ' ' + description + whois = IPWhois(sourceip) + whoisres = whois.lookup_rdap(depth=1,retry_count=0) + results = whoisres + if self.registryValue('whois.debug'): + print(results) + asn = whoisres['asn_registry'] + country = whoisres['asn_country_code'] + description = whoisres['asn_description'] + whoisout = asn + ' ' + country + ' ' + description except ipwhois.exceptions.IPDefinedError: - whoisout = 'RFC 4291 (Local)' + whoisout = 'RFC 4291 (Local)' response = whoisout return response @@ -114,30 +115,30 @@ class SnoParser(callbacks.Plugin): data = self.whois_get_cache(key=sourceip) if data is not None: data = json.loads(data) - #data["cache"] = True - print("DEBUG - CACHE: TRUE") - print(data) - print(sourceip) + if self.registryValue('whois.debug'): + print("SNOPARSER DEBUG - WHOIS_RUN WITH CACHE: TRUE") + print(data) + print(sourceip) return data else: data = self.whois_fresh(sourceip) - print("DEBUG - ELSE WHOIS_FRESH CALLED") - print(data) - print(sourceip) - if data.startswith("#"): - #data["cache"] = False - print("DEBUG - CACHE: FALSE") + if self.registryValue('whois.debug'): + print("SNOPARSER DEBUG - WHOIS_RUN WITH CACHE: FALSE") + print(data) + print(sourceip) + if data.startswith: + if self.registryValue('whois.debug'): + print("SNOPARSER DEBUG - WHOIS_RUN WITH CACHE: FALSE AND CORRECT STARTING CHARACTER") + print(data) data = json.dumps(data) state = self.whois_set_cache(key=sourceip, value=data) - print(data) - print(sourceip) - if state is True: return json.loads(data) else: - print("Data does not start with correct string") - print(data) + if self.registryValue('whois.debug'): + print("SNOPARSER DEBUG _ WHOIS_RUN WITH CACHE: FALSE AND WRONG STARTING CHARACTER") + print(data) return data def query(self, irc, msg, args, ipaddress): @@ -146,11 +147,11 @@ class SnoParser(callbacks.Plugin): """ data = self.whois_get_cache(key=ipaddress) - ttl = self.redis_client.get(ipaddress) + decoded = data.decode('utf-8') + ttl = self.redis_client.ttl(ipaddress) - print(data, ' ', ttl) - #irc.reply(str(data), ' Remaining: ', int(ttl), 's') - irc.reply(data, ttl) + print('SnoParser manual query: ', data, ' ', ttl) + irc.reply(f'{decoded} - Remaining: {ttl}s') query = wrap(query, ['anything']) @@ -174,8 +175,6 @@ class SnoParser(callbacks.Plugin): realname = couple.group(5) ip_seen = 0 nick_seen = 0 - asn = 0 - subnet = '' whoisout = self.whois_run(sourceip=ip) DictFromSnotice = {'notice': 'connect', 'nickname': nickname, 'username': username, 'host': host, 'ip': ip, 'realname': realname, 'ipCount': ip_seen, 'nickCount': nick_seen} -- cgit v1.2.3 From 78161bda7f95cfd72b1386ab7bb93c4aad7b741c Mon Sep 17 00:00:00 2001 From: Georg Date: Thu, 26 Aug 2021 19:18:14 +0200 Subject: Added nickname and IP address counting Signed-off-by: Georg --- plugin.py | 135 ++++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 114 insertions(+), 21 deletions(-) (limited to 'plugin.py') diff --git a/plugin.py b/plugin.py index d47440f..4d9a797 100644 --- a/plugin.py +++ b/plugin.py @@ -53,25 +53,60 @@ class SnoParser(callbacks.Plugin): """Parses the Server Notices from ErgoIRCd""" threaded = True - def redis_connect(self) -> redis.client.Redis: + def redis_connect_whois(self) -> redis.client.Redis: try: - redis_client = redis.Redis( - host = self.registryValue('whois.redis.host'), - port = self.registryValue('whois.redis.port'), - password = self.registryValue('whois.redis.password'), - username = self.registryValue('whois.redis.username'), + redis_client_whois = redis.Redis( + host = self.registryValue('redis.host'), + port = self.registryValue('redis.port'), + password = self.registryValue('redis.password'), + username = self.registryValue('redis.username'), db = self.registryValue('whois.redis.db'), - socket_timeout = int(self.registryValue('whois.redis.timeout')) + socket_timeout = int(self.registryValue('redis.timeout')) ) - ping = redis_client.ping() + ping = redis_client_whois.ping() if ping is True: - return redis_client + return redis_client_whois except redis.AuthenticationError: print("Could not authenticate to Redis backend.") + def redis_connect_nicks(self) -> redis.client.Redis: + try: + redis_client_nicks = redis.Redis( + host = self.registryValue('redis.host'), + port = self.registryValue('redis.port'), + password = self.registryValue('redis.password'), + username = self.registryValue('redis.username'), + db = self.registryValue('redis.db1'), + socket_timeout = int(self.registryValue('redis.timeout')) + ) + ping = redis_client_nicks.ping() + if ping is True: + return redis_client_nicks + except redis.AuthenticationError: + print("Could not authenticate to Redis backend.") + + def redis_connect_ips(self) -> redis.client.Redis: + try: + redis_client_ips = redis.Redis( + host = self.registryValue('redis.host'), + port = self.registryValue('redis.port'), + password = self.registryValue('redis.password'), + username = self.registryValue('redis.username'), + db = self.registryValue('redis.db2'), + socket_timeout = int(self.registryValue('redis.timeout')) + ) + ping = redis_client_ips.ping() + if ping is True: + return redis_client_ips + except redis.AuthenticationError: + print("Could not authenticate to Redis backend.") + + def __init__(self, irc): super().__init__(irc) - self.redis_client = self.redis_connect() + self.redis_client_whois = self.redis_connect_whois() + self.redis_client_nicks = self.redis_connect_nicks() + self.redis_client_ips = self.redis_connect_ips() def whois_fresh(self, sourceip: str) -> dict: """Data from cache.""" @@ -96,17 +131,17 @@ class SnoParser(callbacks.Plugin): def whois_get_cache(self, key: str) -> str: """Data from Redis.""" - k = self.redis_client.get(key) + k = self.redis_client_whois.get(key) # self = SnoParser() -# val = self.redis_client.get(key) +# val = self.redis_client_whois.get(key) val = k return val def whois_set_cache(self, key: str, value: str) -> bool: """Data to Redis.""" - state = self.redis_client.setex(key, timedelta(seconds=3600), value=value,) + state = self.redis_client_whois.setex(key, timedelta(seconds=3600), value=value,) return state def whois_run(self, sourceip: str) -> dict: @@ -141,19 +176,76 @@ class SnoParser(callbacks.Plugin): print(data) return data - def query(self, irc, msg, args, ipaddress): + def nick_run(self, nickname: str) -> dict: + """Tracks nicknames""" + + data = self.redis_client_nicks.get(nickname) + + if data is not None: + if self.registryValue('debug'): + print("SNOPARSER DEBUG - NICK_RUN, SEEN: TRUE") + print(nickname) + print(data) + self.redis_client_nicks.incrby(nickname,amount=1) + if data: + decoded = data.decode('utf-8') + return decoded + else: + return 0 + else: + if self.registryValue('debug'): + print("SNOPARSER DEBUG _ NICK_RUN, SEEN: FALSE") + print(nickname) + print(data) + self.redis_client_nicks.set(nickname,value='1') + if data: + decoded = data.decode('utf-8') + return decoded + else: + return 0 + + def ip_run(self, ipaddress: str) -> dict: + """Tracks IP addresses""" + + data = self.redis_client_ips.get(ipaddress) + + if data is not None: + if self.registryValue('debug'): + print("SNOPARSER DEBUG - IP_RUN, SEEN: TRUE") + print(ipaddress) + print(data) + self.redis_client_ips.incrby(ipaddress,amount=1) + if data: + decoded = data.decode('utf-8') + return decoded + else: + return 0 + else: + if self.registryValue('debug'): + print("SNOPARSER DEBUG _ IP_RUN, SEEN: FALSE") + print(ipaddress) + print(data) + self.redis_client_ips.set(ipaddress,value='1') + if data: + decoded = data.decode('utf-8') + return decoded + else: + return 0 + + def ipquery(self, irc, msg, args, ipaddress): """ Queries the cache for an address. """ data = self.whois_get_cache(key=ipaddress) decoded = data.decode('utf-8') - ttl = self.redis_client.ttl(ipaddress) + ttl = self.redis_client_whois.ttl(ipaddress) + count = self.redis_client_ips.get(ipaddress) print('SnoParser manual query: ', data, ' ', ttl) - irc.reply(f'{decoded} - Remaining: {ttl}s') + irc.reply(f'{decoded} - Count: {count} - Remaining: {ttl}s') - query = wrap(query, ['anything']) + ipquery = wrap(ipquery, ['anything']) def doNotice(self, irc, msg): @@ -173,13 +265,14 @@ class SnoParser(callbacks.Plugin): else: ip = couple.group(4) realname = couple.group(5) - ip_seen = 0 - nick_seen = 0 - whoisout = self.whois_run(sourceip=ip) + ip_seen = self.ip_run(ipaddress=ip) + nick_seen = self.nick_run(nickname=nickname) + whois = self.whois_run(sourceip=ip) + DictFromSnotice = {'notice': 'connect', 'nickname': nickname, 'username': username, 'host': host, 'ip': ip, 'realname': realname, 'ipCount': ip_seen, 'nickCount': nick_seen} #repl = f"\x02\x1FNOTICE: {DictFromSnotice['notice']} \x0F\x11\x0303==>>\x0F \x02Nick:\x0F {DictFromSnotice['nickname']} \x02Username:\x0F {DictFromSnotice['username']} \x02Hostname:\x0F {DictFromSnotice['host']} \x02IP:\x0F {DictFromSnotice['ip']} \x02Realname:\x0F {DictFromSnotice['realname']} \x02IPcount:\x0F {DictFromSnotice['ipCount']} \x02NickCount:\x0F {DictFromSnotice['nickCount']}" - repl = f"\x02\x1F{DictFromSnotice['notice']} \x0F\x11\x0303==>>\x0F \x02Nick:\x0F {DictFromSnotice['nickname']} \x02Username:\x0F {DictFromSnotice['username']} \x02Hostname:\x0F {DictFromSnotice['host']} \x02IP:\x0F {DictFromSnotice['ip']} {whoisout} \x02Realname:\x0F {DictFromSnotice['realname']} \x02IPcount:\x0F {DictFromSnotice['ipCount']} \x02NickCount:\x0F {DictFromSnotice['nickCount']}" + repl = f"\x02\x1F{DictFromSnotice['notice']} \x0F\x11\x0303==>>\x0F \x02Nick:\x0F {DictFromSnotice['nickname']} \x02Username:\x0F {DictFromSnotice['username']} \x02Hostname:\x0F {DictFromSnotice['host']} \x02IP:\x0F {DictFromSnotice['ip']} {whois} \x02Realname:\x0F {DictFromSnotice['realname']} \x02IPcount:\x0F {DictFromSnotice['ipCount']} \x02NickCount:\x0F {DictFromSnotice['nickCount']}" self._sendSnotice(irc, msg, repl) if 'XLINE' in text and 'temporary' in text: -- cgit v1.2.3 From c5a37126bc71f8330db54376f46d1ef0d5251c83 Mon Sep 17 00:00:00 2001 From: Georg Date: Thu, 26 Aug 2021 19:32:58 +0200 Subject: Improved `ipcounting` Signed-off-by: Georg --- plugin.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'plugin.py') diff --git a/plugin.py b/plugin.py index 4d9a797..4b16961 100644 --- a/plugin.py +++ b/plugin.py @@ -141,7 +141,8 @@ class SnoParser(callbacks.Plugin): def whois_set_cache(self, key: str, value: str) -> bool: """Data to Redis.""" - state = self.redis_client_whois.setex(key, timedelta(seconds=3600), value=value,) + duration = self.registryValue('whois.ttl') + state = self.redis_client_whois.setex(key, timedelta(seconds=duration), value=value,) return state def whois_run(self, sourceip: str) -> dict: @@ -238,12 +239,13 @@ class SnoParser(callbacks.Plugin): """ data = self.whois_get_cache(key=ipaddress) - decoded = data.decode('utf-8') + decoded_data = data.decode('utf-8') ttl = self.redis_client_whois.ttl(ipaddress) count = self.redis_client_ips.get(ipaddress) + decoded_count = count.decode('utf-8') print('SnoParser manual query: ', data, ' ', ttl) - irc.reply(f'{decoded} - Count: {count} - Remaining: {ttl}s') + irc.reply(f'{decoded_data} - Count: {decoded_count} - Remaining: {ttl}s') ipquery = wrap(ipquery, ['anything']) -- cgit v1.2.3 From 9a035edef35d10d5c477a2ec7660d0c69e96729a Mon Sep 17 00:00:00 2001 From: Georg Date: Fri, 27 Aug 2021 15:55:27 +0200 Subject: Fixing timedelta Signed-off-by: Georg --- plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'plugin.py') diff --git a/plugin.py b/plugin.py index 4b16961..1adf2ef 100644 --- a/plugin.py +++ b/plugin.py @@ -109,7 +109,7 @@ class SnoParser(callbacks.Plugin): self.redis_client_ips = self.redis_connect_ips() def whois_fresh(self, sourceip: str) -> dict: - """Data from cache.""" + """Data from WHOIS backend (IANA or respective RIR).""" asn = 0 subnet = '' try: @@ -141,7 +141,7 @@ class SnoParser(callbacks.Plugin): def whois_set_cache(self, key: str, value: str) -> bool: """Data to Redis.""" - duration = self.registryValue('whois.ttl') + duration = int(self.registryValue('whois.ttl')) state = self.redis_client_whois.setex(key, timedelta(seconds=duration), value=value,) return state -- cgit v1.2.3 From 14e7d4e74e77ee92b55e5c117d7e17477b83ef8a Mon Sep 17 00:00:00 2001 From: Georg Date: Sun, 29 Aug 2021 00:13:44 +0200 Subject: OPER and DEOPER notices Signed-off-by: Georg --- plugin.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'plugin.py') diff --git a/plugin.py b/plugin.py index 1adf2ef..cf2e05c 100644 --- a/plugin.py +++ b/plugin.py @@ -358,6 +358,26 @@ class SnoParser(callbacks.Plugin): self._setvhost(irc, msg, account) self._sendSnotice(irc, msg, repl) + if 'OPER' in text and 'Client opered up' in text: + + operregex = "^-OPER- Client opered up \[(.*)\]" + couple = re.match(operregex, text) + account = couple.group(1) + DictFromSnotice = {'notice': 'oper'} + repl = f"\x02\x1FNOTICE:\x0F [{account}] opered up." + + self._sendSnotice(irc, msg, repl) + + if 'OPER' in text and 'Client deopered' in text: + + operregex = "^-OPER- Client deopered \[(.*)\]" + couple = re.match(operregex, text) + account = couple.group(1) + DictFromSnotice = {'notice': 'oper'} + repl = f"\x02\x1FNOTICE:\x0F [{account}] opered down." + + self._sendSnotice(irc, msg, repl) + # Post Registration -- cgit v1.2.3 From 46596e0b33a9a5dc086028f8e0e023a4b599bc95 Mon Sep 17 00:00:00 2001 From: Georg Date: Tue, 31 Aug 2021 16:29:17 +0200 Subject: ipquery IP validation + repaired config integers Signed-off-by: Georg --- plugin.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'plugin.py') diff --git a/plugin.py b/plugin.py index cf2e05c..d10c8e0 100644 --- a/plugin.py +++ b/plugin.py @@ -168,7 +168,7 @@ class SnoParser(callbacks.Plugin): print(data) data = json.dumps(data) state = self.whois_set_cache(key=sourceip, value=data) - + if state is True: return json.loads(data) else: @@ -243,11 +243,10 @@ class SnoParser(callbacks.Plugin): ttl = self.redis_client_whois.ttl(ipaddress) count = self.redis_client_ips.get(ipaddress) decoded_count = count.decode('utf-8') - print('SnoParser manual query: ', data, ' ', ttl) irc.reply(f'{decoded_data} - Count: {decoded_count} - Remaining: {ttl}s') - - ipquery = wrap(ipquery, ['anything']) + + ipquery = wrap(ipquery, ['ip']) def doNotice(self, irc, msg): @@ -342,7 +341,7 @@ class SnoParser(callbacks.Plugin): ip = couple.group(3) DictFromSnotice = {'notice': 'accreg', 'hostmask': hostmask, 'account': account, 'ip': ip} repl = f"\x02\x1FNOTICE: accreg -> [{account}] was registered by hostmask [{hostmask}] from IP {ip}" - + # Trigger HS SET self._setvhost(irc, msg, account) @@ -354,17 +353,20 @@ class SnoParser(callbacks.Plugin): account = couple.group(2) DictFromSnotice = {'notice': 'sareg', 'oper': oper, 'account': account} repl = f"\x02\x1FNOTICE: sareg -> [{account}] was registered by operator [{oper}]" - + self._setvhost(irc, msg, account) self._sendSnotice(irc, msg, repl) if 'OPER' in text and 'Client opered up' in text: - - operregex = "^-OPER- Client opered up \[(.*)\]" + operregex = "^-OPER- Client opered up \[(.*)\, \ (.*)\]$" couple = re.match(operregex, text) - account = couple.group(1) - DictFromSnotice = {'notice': 'oper'} - repl = f"\x02\x1FNOTICE:\x0F [{account}] opered up." + hostmask = couple.group(1) + oper = couple.group(2) + + print(couple) + + DictFromSnotice = {'notice': 'opered', 'hostmask': hostmask, 'oper': oper} + repl = f"\x02\x1FNOTICE:\x0F [{hostmask}] opered up as [{oper}]." self._sendSnotice(irc, msg, repl) @@ -373,14 +375,14 @@ class SnoParser(callbacks.Plugin): operregex = "^-OPER- Client deopered \[(.*)\]" couple = re.match(operregex, text) account = couple.group(1) - DictFromSnotice = {'notice': 'oper'} + DictFromSnotice = {'notice': 'deopered', 'name': account} repl = f"\x02\x1FNOTICE:\x0F [{account}] opered down." self._sendSnotice(irc, msg, repl) # Post Registration - + def _setvhost(self, irc, msg, account): arg = ['SET'] arg.append(account) @@ -390,18 +392,18 @@ class SnoParser(callbacks.Plugin): args=arg)) - # Send formatted SNO to channel + # Send formatted SNO to channel def _sendSnotice(self, irc, msg, repl): try: channel = self.registryValue('targetChannel') if channel[0] == '#': irc.queueMsg(msg=ircmsgs.IrcMsg(command='NOTICE', - args=(channel, repl))) + args=(channel, repl))) # what sort of exception does one raise except: pass - + Class = SnoParser -- cgit v1.2.3 From ca02bba8c341b00973497e6f37a8ee34d75fcf0a Mon Sep 17 00:00:00 2001 From: Pratyush Desai Date: Tue, 7 Sep 2021 16:33:00 +0200 Subject: TargetChannel config + requirements.txt (#17) Added requirements.txt Updated configuration value errors Reviewed-on: https://git.com.de/LimnoriaPlugins/SnoParser/pulls/17 Co-authored-by: Pratyush Desai Co-committed-by: Pratyush Desai --- plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugin.py') diff --git a/plugin.py b/plugin.py index d10c8e0..c06a6e4 100644 --- a/plugin.py +++ b/plugin.py @@ -397,7 +397,7 @@ class SnoParser(callbacks.Plugin): def _sendSnotice(self, irc, msg, repl): try: channel = self.registryValue('targetChannel') - if channel[0] == '#': + if irc.isChannel(channel): irc.queueMsg(msg=ircmsgs.IrcMsg(command='NOTICE', args=(channel, repl))) # what sort of exception does one raise -- cgit v1.2.3 From 8cacf16cb94920033b8d0c491eb7d931d552e98c Mon Sep 17 00:00:00 2001 From: Pratyush Desai Date: Sat, 16 Oct 2021 11:43:34 +0530 Subject: fix target chan issues Signed-off-by: Pratyush Desai --- plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'plugin.py') diff --git a/plugin.py b/plugin.py index c06a6e4..dcb4c11 100644 --- a/plugin.py +++ b/plugin.py @@ -253,7 +253,7 @@ class SnoParser(callbacks.Plugin): (target, text) = msg.args if target == irc.nick: - # server notices CONNECT, KILL, XLINE, NICK, ACCOUNT + # server notices CONNECT, KILL, XLINE, NICK, ACCOUNT, OPER, QUIT, text = ircutils.stripFormatting(text) if 'CONNECT' in text: connregex = "^-CONNECT- Client connected \[(.+)\] \[u\:~(.+)\] \[h\:(.+)\] \[ip\:(.+)\] \[r\:(.+)\]$" @@ -344,8 +344,8 @@ class SnoParser(callbacks.Plugin): # Trigger HS SET self._setvhost(irc, msg, account) - self._sendSnotice(irc, msg, repl) + if 'ACCOUNT' in text and 'registered account' in text and 'SAREGISTER' in text: accregex = "^-ACCOUNT- Operator \[(.*)\] registered account \[(.*)\] with SAREGISTER$" couple = re.match(accregex, text) -- cgit v1.2.3 From 25ab2849ae83b084cc0c51166437cb6eb271e58f Mon Sep 17 00:00:00 2001 From: Pratyush Desai Date: Sat, 16 Oct 2021 13:59:54 +0530 Subject: regex efficiency wip need to look up SNO list Signed-off-by: Pratyush Desai --- plugin.py | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) (limited to 'plugin.py') diff --git a/plugin.py b/plugin.py index dcb4c11..b496806 100644 --- a/plugin.py +++ b/plugin.py @@ -255,9 +255,11 @@ class SnoParser(callbacks.Plugin): if target == irc.nick: # server notices CONNECT, KILL, XLINE, NICK, ACCOUNT, OPER, QUIT, text = ircutils.stripFormatting(text) - if 'CONNECT' in text: - connregex = "^-CONNECT- Client connected \[(.+)\] \[u\:~(.+)\] \[h\:(.+)\] \[ip\:(.+)\] \[r\:(.+)\]$" - couple = re.match(connregex, text) + # if 'CONNECT' in text: + RE_CLICONN = re.compile(r"^-CONNECT- Client connected \[(.+)\] \[u\:~(.+)\] \[h\:(.+)\] \[ip\:(.+)\] \[r\:(.+)\]$") + couple = RE_CLICONN.match(text) + # check `if couple:` ie was there a match even? if yes proceed + if couple: nickname = couple.group(1) username = couple.group(2) host = couple.group(3) @@ -271,21 +273,21 @@ class SnoParser(callbacks.Plugin): nick_seen = self.nick_run(nickname=nickname) whois = self.whois_run(sourceip=ip) - DictFromSnotice = {'notice': 'connect', 'nickname': nickname, 'username': username, 'host': host, 'ip': ip, 'realname': realname, 'ipCount': ip_seen, 'nickCount': nick_seen} - #repl = f"\x02\x1FNOTICE: {DictFromSnotice['notice']} \x0F\x11\x0303==>>\x0F \x02Nick:\x0F {DictFromSnotice['nickname']} \x02Username:\x0F {DictFromSnotice['username']} \x02Hostname:\x0F {DictFromSnotice['host']} \x02IP:\x0F {DictFromSnotice['ip']} \x02Realname:\x0F {DictFromSnotice['realname']} \x02IPcount:\x0F {DictFromSnotice['ipCount']} \x02NickCount:\x0F {DictFromSnotice['nickCount']}" - repl = f"\x02\x1F{DictFromSnotice['notice']} \x0F\x11\x0303==>>\x0F \x02Nick:\x0F {DictFromSnotice['nickname']} \x02Username:\x0F {DictFromSnotice['username']} \x02Hostname:\x0F {DictFromSnotice['host']} \x02IP:\x0F {DictFromSnotice['ip']} {whois} \x02Realname:\x0F {DictFromSnotice['realname']} \x02IPcount:\x0F {DictFromSnotice['ipCount']} \x02NickCount:\x0F {DictFromSnotice['nickCount']}" + snote_dict = {'notice': 'connect', 'nickname': nickname, 'username': username, 'host': host, 'ip': ip, 'realname': realname, 'ipCount': ip_seen, 'nickCount': nick_seen} + repl = f"\x02\x1F{snote_dict['notice']} \x0F\x11\x0303==>>\x0F \x02Nick:\x0F {snote_dict['nickname']} \x02Username:\x0F {snote_dict['username']} \x02Hostname:\x0F {snote_dict['host']} \x02IP:\x0F {snote_dict['ip']} {whois} \x02Realname:\x0F {snote_dict['realname']} \x02IPcount:\x0F {snote_dict['ipCount']} \x02NickCount:\x0F {snote_dict['nickCount']}" self._sendSnotice(irc, msg, repl) - if 'XLINE' in text and 'temporary' in text: - xlineregex = "^-XLINE- (.+) \[(.+)\] added temporary \((.+)\) (K-Line|D-Line) for (.+)$" - couple = re.match(xlineregex, text) + # if 'XLINE' in text and 'temporary' in text: + RE_XLINE = re.compile(r"^-XLINE- (.+) \[(.+)\] added temporary \((.+)\) (K-Line|D-Line) for (.+)$") + couple = RE_XLINE.match(text) + if couple: who = couple.group(1) who_operator = couple.group(2) duration = couple.group(3) which_line = couple.group(4) host_or_ip = couple.group(5) - DictFromSnotice = {'notice': 'tempban', 'who': who, 'operator': who_operator, 'duration': duration, 'type': which_line, 'target': host_or_ip} - repl = f"\x02\x1FNOTICE: {DictFromSnotice['notice']}\x0F \x11\x0303 X_X \x0F \x02BannedBy:\x0F {DictFromSnotice['who']} \x02BannedByOper:\x0F {DictFromSnotice['operator']} \x02Duration:\x0F {DictFromSnotice['duration']} \x02XLINE Type:\x0F {DictFromSnotice['type']} \x02Nick:\x0F {DictFromSnotice['target']}" + snote_dict = {'notice': 'tempban', 'who': who, 'operator': who_operator, 'duration': duration, 'type': which_line, 'target': host_or_ip} + repl = f"\x02\x1FNOTICE: {snote_dict['notice']}\x0F \x11\x0303 X_X \x0F \x02BannedBy:\x0F {snote_dict['who']} \x02BannedByOper:\x0F {snote_dict['operator']} \x02Duration:\x0F {snote_dict['duration']} \x02XLINE Type:\x0F {snote_dict['type']} \x02Nick:\x0F {snote_dict['target']}" self._sendSnotice(irc, msg, repl) # WHY THE FUCK IS IT elif ?? elif 'XLINE' in text and 'temporary' not in text and 'removed' not in text: @@ -295,8 +297,8 @@ class SnoParser(callbacks.Plugin): who_operator = couple.group(2) which_line = couple.group(3) host_or_ip = couple.group(4) - DictFromSnotice = {'notice': 'Permaban', 'who': who, 'operator': who_operator, 'type': which_line, 'target': host_or_ip} - repl = f"\x02\x1FNOTICE: {DictFromSnotice['notice']} \x0F \x11\x0303 X_X \x0F \x02BannedBy:\x0F {DictFromSnotice['who']} \x02BannedByOper:\x0F {DictFromSnotice['operator']} \x02XLINE Type:\x0F {DictFromSnotice['type']} \x02Host/IP:\x0F {DictFromSnotice['target']}" + snote_dict = {'notice': 'Permaban', 'who': who, 'operator': who_operator, 'type': which_line, 'target': host_or_ip} + repl = f"\x02\x1FNOTICE: {snote_dict['notice']} \x0F \x11\x0303 X_X \x0F \x02BannedBy:\x0F {snote_dict['who']} \x02BannedByOper:\x0F {snote_dict['operator']} \x02XLINE Type:\x0F {snote_dict['type']} \x02Host/IP:\x0F {snote_dict['target']}" self._sendSnotice(irc, msg, repl) elif 'XLINE' in text and 'removed' in text: unxlineregex = "^-XLINE- (.+) removed (D-Line|K-Line) for (.+)$" @@ -304,8 +306,8 @@ class SnoParser(callbacks.Plugin): who = couple.group(1) which_line = couple.group(2) host_or_ip = couple.group(3) - DictFromSnotice = {'notice': 'unxline', 'who': who, 'type': which_line, 'target': host_or_ip} - repl = f"\x02\x1FNOTICE: {DictFromSnotice['notice']} \x0F\x11\x0303 :=D\x0F \x02UnbannedBy:\x0F {DictFromSnotice['who']} \x02XLINE type:\x0F {DictFromSnotice['type']} \x02Host/IP:\x0F {DictFromSnotice['target']}" + snote_dict = {'notice': 'unxline', 'who': who, 'type': which_line, 'target': host_or_ip} + repl = f"\x02\x1FNOTICE: {snote_dict['notice']} \x0F\x11\x0303 :=D\x0F \x02UnbannedBy:\x0F {snote_dict['who']} \x02XLINE type:\x0F {snote_dict['type']} \x02Host/IP:\x0F {snote_dict['target']}" self._sendSnotice(irc, msg, repl) if 'KILL' in text: killregex = "^-KILL- (.+) \[(.+)\] killed (\d) clients with a (KLINE|DLINE) \[(.+)\]$" @@ -315,22 +317,22 @@ class SnoParser(callbacks.Plugin): clients = couple.group(3) which_line = couple.group(4) nick = couple.group(5) - DictFromSnotice = {'notice': 'kill', 'who': who, 'operator': who_operator, "client": clients, 'type': which_line, 'nick': nick} - repl = f"\x02\x1FNOTICE: {DictFromSnotice['notice']} \x0F\x11\x0303☠\x0F \x02KilledBy:\x0F {DictFromSnotice['who']} \x02KilledByOper:\x0F {DictFromSnotice['operator']} \x02NumofClientsAffected:\x0F {DictFromSnotice['client']} \x02XLINE Type:\x0F {DictFromSnotice['type']} \x02Nick:\x0F {DictFromSnotice['nick']}" + snote_dict = {'notice': 'kill', 'who': who, 'operator': who_operator, "client": clients, 'type': which_line, 'nick': nick} + repl = f"\x02\x1FNOTICE: {snote_dict['notice']} \x0F\x11\x0303☠\x0F \x02KilledBy:\x0F {snote_dict['who']} \x02KilledByOper:\x0F {snote_dict['operator']} \x02NumofClientsAffected:\x0F {snote_dict['client']} \x02XLINE Type:\x0F {snote_dict['type']} \x02Nick:\x0F {snote_dict['nick']}" self._sendSnotice(irc, msg, repl) if 'NICK' in text and 'changed nickname to' in text: nickregex = "^-NICK- (.+) changed nickname to (.+)$" couple = re.match(nickregex, text) old_nick = couple.group(1) new_nick = couple.group(2) - DictFromSnotice = {'notice': 'nick change', 'old_nick': old_nick, 'new_nick': new_nick} - repl = f"\x02\x1FNOTICE: {DictFromSnotice['notice']} ==> {DictFromSnotice['old_nick']} changed their nick to {DictFromSnotice['new_nick']}" + snote_dict = {'notice': 'nick change', 'old_nick': old_nick, 'new_nick': new_nick} + repl = f"\x02\x1FNOTICE: {snote_dict['notice']} ==> {snote_dict['old_nick']} changed their nick to {snote_dict['new_nick']}" self._sendSnotice(irc, msg, repl) if 'QUIT' in text and 'exited' in text: quitregex = "^-QUIT- (.+) exited the network$" couple = re.match(quitregex, text) nick = couple.group(1) - DictFromSnotice = {'notice': 'quit', 'nick': nick} + snote_dict = {'notice': 'quit', 'nick': nick} repl = f"\x02\x1FNOTICE: quit nick: {nick} has exited the network" self._sendSnotice(irc, msg, repl) if 'ACCOUNT' in text and 'registered account' in text: @@ -339,7 +341,7 @@ class SnoParser(callbacks.Plugin): hostmask = couple.group(1) account = couple.group(2) ip = couple.group(3) - DictFromSnotice = {'notice': 'accreg', 'hostmask': hostmask, 'account': account, 'ip': ip} + snote_dict = {'notice': 'accreg', 'hostmask': hostmask, 'account': account, 'ip': ip} repl = f"\x02\x1FNOTICE: accreg -> [{account}] was registered by hostmask [{hostmask}] from IP {ip}" # Trigger HS SET @@ -351,7 +353,7 @@ class SnoParser(callbacks.Plugin): couple = re.match(accregex, text) oper = couple.group(1) account = couple.group(2) - DictFromSnotice = {'notice': 'sareg', 'oper': oper, 'account': account} + snote_dict = {'notice': 'sareg', 'oper': oper, 'account': account} repl = f"\x02\x1FNOTICE: sareg -> [{account}] was registered by operator [{oper}]" self._setvhost(irc, msg, account) @@ -365,7 +367,7 @@ class SnoParser(callbacks.Plugin): print(couple) - DictFromSnotice = {'notice': 'opered', 'hostmask': hostmask, 'oper': oper} + snote_dict = {'notice': 'opered', 'hostmask': hostmask, 'oper': oper} repl = f"\x02\x1FNOTICE:\x0F [{hostmask}] opered up as [{oper}]." self._sendSnotice(irc, msg, repl) @@ -375,7 +377,7 @@ class SnoParser(callbacks.Plugin): operregex = "^-OPER- Client deopered \[(.*)\]" couple = re.match(operregex, text) account = couple.group(1) - DictFromSnotice = {'notice': 'deopered', 'name': account} + snote_dict = {'notice': 'deopered', 'name': account} repl = f"\x02\x1FNOTICE:\x0F [{account}] opered down." self._sendSnotice(irc, msg, repl) -- cgit v1.2.3