2021-06-19 12:38:43 +02:00
|
|
|
###
|
2021-08-26 13:52:34 +02:00
|
|
|
# Copyright (c) 2021, mogad0n and Georg Pfuetzenreuter <georg@lysergic.dev>
|
2021-06-19 12:38:43 +02:00
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are met:
|
|
|
|
#
|
|
|
|
# * Redistributions of source code must retain the above copyright notice,
|
|
|
|
# this list of conditions, and the following disclaimer.
|
|
|
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
# this list of conditions, and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
# * Neither the name of the author of this software nor the name of
|
|
|
|
# contributors to this software may be used to endorse or promote products
|
|
|
|
# derived from this software without specific prior written consent.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
###
|
|
|
|
|
2023-05-03 16:43:41 +02:00
|
|
|
from supybot import (
|
|
|
|
ircutils,
|
|
|
|
callbacks,
|
|
|
|
ircmsgs,
|
|
|
|
)
|
2021-06-19 12:38:43 +02:00
|
|
|
from supybot.commands import *
|
2023-05-03 16:43:41 +02:00
|
|
|
|
2021-06-19 12:38:43 +02:00
|
|
|
try:
|
|
|
|
from supybot.i18n import PluginInternationalization
|
2023-05-03 16:43:41 +02:00
|
|
|
|
|
|
|
_ = PluginInternationalization("SnoParser")
|
2021-06-19 12:38:43 +02:00
|
|
|
except ImportError:
|
|
|
|
# Placeholder that allows to run the plugin on a bot
|
|
|
|
# without the i18n module
|
|
|
|
_ = lambda x: x
|
|
|
|
|
|
|
|
import re
|
2021-08-26 11:41:41 +02:00
|
|
|
import redis
|
|
|
|
import json
|
2021-08-26 12:50:25 +02:00
|
|
|
from datetime import timedelta
|
2021-08-26 11:41:41 +02:00
|
|
|
from ipwhois import IPWhois
|
2024-10-05 19:48:09 +02:00
|
|
|
from ipwhois.exceptions import IPDefinedError
|
2021-06-19 12:38:43 +02:00
|
|
|
|
2023-05-03 16:43:41 +02:00
|
|
|
|
2021-06-19 12:38:43 +02:00
|
|
|
class SnoParser(callbacks.Plugin):
|
|
|
|
"""Parses the Server Notices from ErgoIRCd"""
|
2023-05-03 16:43:41 +02:00
|
|
|
|
2021-06-19 12:38:43 +02:00
|
|
|
threaded = True
|
|
|
|
|
2024-10-05 19:48:25 +02:00
|
|
|
def _redis_connect(self, db) -> redis.client.Redis:
|
2021-08-26 11:41:41 +02:00
|
|
|
try:
|
2024-10-05 19:48:25 +02:00
|
|
|
redis_client = redis.Redis(
|
2023-05-03 16:43:41 +02:00
|
|
|
host=self.registryValue("redis.host"),
|
|
|
|
port=self.registryValue("redis.port"),
|
|
|
|
password=self.registryValue("redis.password"),
|
|
|
|
username=self.registryValue("redis.username"),
|
2024-10-05 19:48:25 +02:00
|
|
|
db=self.registryValue(f"redis.db.{db}"),
|
2023-05-03 16:43:41 +02:00
|
|
|
socket_timeout=int(self.registryValue("redis.timeout")),
|
2021-08-26 11:41:41 +02:00
|
|
|
)
|
2024-10-05 19:48:25 +02:00
|
|
|
ping = redis_client.ping()
|
2021-08-26 11:41:41 +02:00
|
|
|
if ping is True:
|
2024-10-05 19:48:25 +02:00
|
|
|
return redis_client
|
2021-08-26 19:18:14 +02:00
|
|
|
except redis.AuthenticationError:
|
|
|
|
print("Could not authenticate to Redis backend.")
|
|
|
|
|
2021-08-26 16:36:34 +02:00
|
|
|
def __init__(self, irc):
|
|
|
|
super().__init__(irc)
|
2024-10-05 19:48:25 +02:00
|
|
|
self.redis_clients = {
|
|
|
|
'ips': self._redis_connect("ips"),
|
|
|
|
'nicks': self._redis_connect("nicks"),
|
|
|
|
'whois': self._redis_connect("whois"),
|
|
|
|
}
|
|
|
|
|
|
|
|
def _get_from_cache(self, db, key):
|
|
|
|
""" Get value from Redis cache """
|
|
|
|
|
|
|
|
return self.redis_clients[db].get(key)
|
2021-08-26 16:36:34 +02:00
|
|
|
|
|
|
|
def whois_fresh(self, sourceip: str) -> dict:
|
2021-08-27 15:55:27 +02:00
|
|
|
"""Data from WHOIS backend (IANA or respective RIR)."""
|
2024-10-05 19:48:25 +02:00
|
|
|
|
2021-08-26 11:41:41 +02:00
|
|
|
asn = 0
|
2023-05-03 16:43:41 +02:00
|
|
|
subnet = ""
|
2021-08-26 11:41:41 +02:00
|
|
|
try:
|
2021-08-26 17:30:38 +02:00
|
|
|
whois = IPWhois(sourceip)
|
2023-05-03 16:43:41 +02:00
|
|
|
whoisres = whois.lookup_rdap(depth=1, retry_count=0)
|
2021-08-26 17:30:38 +02:00
|
|
|
results = whoisres
|
2023-05-03 16:43:41 +02:00
|
|
|
if self.registryValue("whois.debug"):
|
2021-08-26 17:30:38 +02:00
|
|
|
print(results)
|
2023-05-03 16:43:41 +02:00
|
|
|
asn = whoisres["asn_registry"]
|
|
|
|
country = whoisres["asn_country_code"]
|
|
|
|
description = whoisres["asn_description"]
|
|
|
|
whoisout = asn + " " + country + " " + description
|
2024-10-05 19:48:09 +02:00
|
|
|
except IPDefinedError:
|
2023-05-03 16:43:41 +02:00
|
|
|
whoisout = "RFC 4291 (Local)"
|
2021-08-26 11:41:41 +02:00
|
|
|
|
2021-08-26 12:50:25 +02:00
|
|
|
response = whoisout
|
|
|
|
return response
|
2021-08-26 11:41:41 +02:00
|
|
|
|
2021-08-26 16:36:34 +02:00
|
|
|
def whois_set_cache(self, key: str, value: str) -> bool:
|
2021-08-26 11:41:41 +02:00
|
|
|
"""Data to Redis."""
|
|
|
|
|
2024-10-05 19:48:25 +02:00
|
|
|
return self.redis_clients['whois'].setex(
|
2023-05-03 16:43:41 +02:00
|
|
|
key,
|
2024-10-05 19:48:25 +02:00
|
|
|
timedelta(seconds=int(self.registryValue("whois.ttl"))),
|
2023-05-03 16:43:41 +02:00
|
|
|
value=value,
|
|
|
|
)
|
2021-08-26 11:41:41 +02:00
|
|
|
|
2021-08-26 16:36:34 +02:00
|
|
|
def whois_run(self, sourceip: str) -> dict:
|
2021-08-26 13:51:26 +02:00
|
|
|
"""Whois query router."""
|
|
|
|
|
2024-10-05 19:48:25 +02:00
|
|
|
data = self._get_from_cache("whois", sourceip)
|
2021-08-26 11:41:41 +02:00
|
|
|
if data is not None:
|
|
|
|
data = json.loads(data)
|
2023-05-03 16:43:41 +02:00
|
|
|
if self.registryValue("whois.debug"):
|
2021-08-26 17:30:38 +02:00
|
|
|
print("SNOPARSER DEBUG - WHOIS_RUN WITH CACHE: TRUE")
|
|
|
|
print(data)
|
|
|
|
print(sourceip)
|
2021-08-26 11:41:41 +02:00
|
|
|
return data
|
|
|
|
else:
|
2021-08-26 16:36:34 +02:00
|
|
|
data = self.whois_fresh(sourceip)
|
2023-05-03 16:43:41 +02:00
|
|
|
if self.registryValue("whois.debug"):
|
2021-08-26 17:30:38 +02:00
|
|
|
print("SNOPARSER DEBUG - WHOIS_RUN WITH CACHE: FALSE")
|
|
|
|
print(data)
|
|
|
|
print(sourceip)
|
|
|
|
if data.startswith:
|
2023-05-03 16:43:41 +02:00
|
|
|
if self.registryValue("whois.debug"):
|
|
|
|
print(
|
|
|
|
"SNOPARSER DEBUG - WHOIS_RUN WITH CACHE: FALSE AND CORRECT STARTING CHARACTER"
|
|
|
|
)
|
2021-08-26 17:30:38 +02:00
|
|
|
print(data)
|
2021-08-26 11:41:41 +02:00
|
|
|
data = json.dumps(data)
|
2021-08-26 16:36:34 +02:00
|
|
|
state = self.whois_set_cache(key=sourceip, value=data)
|
2021-08-31 16:29:17 +02:00
|
|
|
|
2021-08-26 11:41:41 +02:00
|
|
|
if state is True:
|
|
|
|
return json.loads(data)
|
2021-08-26 12:50:25 +02:00
|
|
|
else:
|
2023-05-03 16:43:41 +02:00
|
|
|
if self.registryValue("whois.debug"):
|
|
|
|
print(
|
|
|
|
"SNOPARSER DEBUG _ WHOIS_RUN WITH CACHE: FALSE AND WRONG STARTING CHARACTER"
|
|
|
|
)
|
2021-08-26 17:30:38 +02:00
|
|
|
print(data)
|
2021-08-26 11:41:41 +02:00
|
|
|
return data
|
|
|
|
|
2021-08-26 19:18:14 +02:00
|
|
|
def nick_run(self, nickname: str) -> dict:
|
|
|
|
"""Tracks nicknames"""
|
|
|
|
|
2024-10-05 19:48:25 +02:00
|
|
|
data = self._get_from_cache("nicks", nickname)
|
2021-08-26 19:18:14 +02:00
|
|
|
|
|
|
|
if data is not None:
|
2023-05-03 16:43:41 +02:00
|
|
|
if self.registryValue("debug"):
|
2021-08-26 19:18:14 +02:00
|
|
|
print("SNOPARSER DEBUG - NICK_RUN, SEEN: TRUE")
|
|
|
|
print(nickname)
|
|
|
|
print(data)
|
2024-10-05 19:48:25 +02:00
|
|
|
self.redis_clients['nicks'].incrby(nickname, amount=1)
|
2021-08-26 19:18:14 +02:00
|
|
|
if data:
|
2023-05-03 16:43:41 +02:00
|
|
|
decoded = data.decode("utf-8")
|
2021-08-26 19:18:14 +02:00
|
|
|
return decoded
|
|
|
|
else:
|
|
|
|
return 0
|
|
|
|
else:
|
2023-05-03 16:43:41 +02:00
|
|
|
if self.registryValue("debug"):
|
2021-08-26 19:18:14 +02:00
|
|
|
print("SNOPARSER DEBUG _ NICK_RUN, SEEN: FALSE")
|
|
|
|
print(nickname)
|
|
|
|
print(data)
|
2024-10-05 19:48:25 +02:00
|
|
|
self.redis_clients['nicks'].set(nickname, value="1")
|
2021-08-26 19:18:14 +02:00
|
|
|
if data:
|
2023-05-03 16:43:41 +02:00
|
|
|
decoded = data.decode("utf-8")
|
2021-08-26 19:18:14 +02:00
|
|
|
return decoded
|
|
|
|
else:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def ip_run(self, ipaddress: str) -> dict:
|
|
|
|
"""Tracks IP addresses"""
|
|
|
|
|
2024-10-06 17:20:07 +02:00
|
|
|
data = self._get_from_cache("ips", ipaddress)
|
2021-08-26 19:18:14 +02:00
|
|
|
if data is not None:
|
2023-05-03 16:43:41 +02:00
|
|
|
if self.registryValue("debug"):
|
2021-08-26 19:18:14 +02:00
|
|
|
print("SNOPARSER DEBUG - IP_RUN, SEEN: TRUE")
|
|
|
|
print(ipaddress)
|
|
|
|
print(data)
|
2024-10-05 19:48:25 +02:00
|
|
|
self.redis_clients['ips'].incrby(ipaddress, amount=1)
|
2021-08-26 19:18:14 +02:00
|
|
|
if data:
|
2023-05-03 16:43:41 +02:00
|
|
|
decoded = data.decode("utf-8")
|
2021-08-26 19:18:14 +02:00
|
|
|
return decoded
|
|
|
|
else:
|
|
|
|
return 0
|
|
|
|
else:
|
2023-05-03 16:43:41 +02:00
|
|
|
if self.registryValue("debug"):
|
2021-08-26 19:18:14 +02:00
|
|
|
print("SNOPARSER DEBUG _ IP_RUN, SEEN: FALSE")
|
|
|
|
print(ipaddress)
|
|
|
|
print(data)
|
2024-10-05 19:48:25 +02:00
|
|
|
self.redis_clients['ips'].set(ipaddress, value="1")
|
2021-08-26 19:18:14 +02:00
|
|
|
if data:
|
2023-05-03 16:43:41 +02:00
|
|
|
decoded = data.decode("utf-8")
|
2021-08-26 19:18:14 +02:00
|
|
|
return decoded
|
|
|
|
else:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def ipquery(self, irc, msg, args, ipaddress):
|
2021-08-26 16:36:34 +02:00
|
|
|
"""<IP address>
|
|
|
|
Queries the cache for an address.
|
|
|
|
"""
|
|
|
|
|
2024-10-06 17:21:10 +02:00
|
|
|
data = self.redis_clients['whois'].get(ipaddress)
|
|
|
|
if data is not None:
|
|
|
|
data = data.decode("utf-8")
|
2024-10-05 19:48:25 +02:00
|
|
|
ttl = self.redis_clients['whois'].ttl(ipaddress)
|
|
|
|
count = self.redis_clients['ips'].get(ipaddress)
|
2024-10-06 17:21:10 +02:00
|
|
|
if count is not None:
|
|
|
|
count = count.decode("utf-8")
|
2023-05-03 16:43:41 +02:00
|
|
|
print("SnoParser manual query: ", data, " ", ttl)
|
2024-10-06 17:21:10 +02:00
|
|
|
irc.reply(f"{data} - Count: {count} - Remaining: {ttl}s")
|
2021-08-26 16:36:34 +02:00
|
|
|
|
2023-05-03 16:43:41 +02:00
|
|
|
ipquery = wrap(ipquery, ["ip"])
|
2021-08-26 11:41:41 +02:00
|
|
|
|
2021-06-19 12:38:43 +02:00
|
|
|
def doNotice(self, irc, msg):
|
|
|
|
(target, text) = msg.args
|
2021-08-26 11:41:41 +02:00
|
|
|
|
2021-06-19 12:38:43 +02:00
|
|
|
if target == irc.nick:
|
2023-05-03 16:43:41 +02:00
|
|
|
# server notices CONNECT, KILL, XLINE, NICK, ACCOUNT, OPER, QUIT,
|
2021-06-19 12:38:43 +02:00
|
|
|
text = ircutils.stripFormatting(text)
|
2021-10-16 10:29:54 +02:00
|
|
|
# if 'CONNECT' in text:
|
2023-05-03 16:43:41 +02:00
|
|
|
RE_CLICONN = re.compile(
|
|
|
|
r"^-CONNECT- Client connected \[(.+)\] \[u\:~(.+)\] \[h\:(.+)\] \[ip\:(.+)\] \[r\:(.+)\]$"
|
|
|
|
)
|
2021-10-16 10:29:54 +02:00
|
|
|
couple = RE_CLICONN.match(text)
|
|
|
|
# check `if couple:` ie was there a match even? if yes proceed
|
|
|
|
if couple:
|
2021-06-19 12:38:43 +02:00
|
|
|
nickname = couple.group(1)
|
|
|
|
username = couple.group(2)
|
|
|
|
host = couple.group(3)
|
2023-05-03 16:43:41 +02:00
|
|
|
if self.registryValue("whois.sample"):
|
|
|
|
ip = self.registryValue("whois.sample")
|
2021-08-26 16:58:04 +02:00
|
|
|
else:
|
|
|
|
ip = couple.group(4)
|
2021-06-19 12:38:43 +02:00
|
|
|
realname = couple.group(5)
|
2021-08-26 11:41:41 +02:00
|
|
|
|
2021-08-26 19:18:14 +02:00
|
|
|
ip_seen = self.ip_run(ipaddress=ip)
|
|
|
|
nick_seen = self.nick_run(nickname=nickname)
|
|
|
|
whois = self.whois_run(sourceip=ip)
|
|
|
|
|
2023-05-03 16:43:41 +02:00
|
|
|
snote_dict = {
|
|
|
|
"notice": "connect",
|
|
|
|
"nickname": nickname,
|
|
|
|
"username": username,
|
|
|
|
"host": host,
|
|
|
|
"ip": ip,
|
|
|
|
"realname": realname,
|
|
|
|
"ipCount": ip_seen,
|
|
|
|
"nickCount": nick_seen,
|
|
|
|
}
|
2021-10-16 10:29:54 +02:00
|
|
|
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']}"
|
2021-08-26 11:41:41 +02:00
|
|
|
|
2021-06-19 12:38:43 +02:00
|
|
|
self._sendSnotice(irc, msg, repl)
|
2021-10-16 10:29:54 +02:00
|
|
|
# if 'XLINE' in text and 'temporary' in text:
|
2023-05-03 16:43:41 +02:00
|
|
|
RE_XLINE = re.compile(
|
|
|
|
r"^-XLINE- (.+) \[(.+)\] added temporary \((.+)\) (K-Line|D-Line) for (.+)$"
|
|
|
|
)
|
2021-10-16 10:29:54 +02:00
|
|
|
couple = RE_XLINE.match(text)
|
|
|
|
if couple:
|
2021-06-19 12:38:43 +02:00
|
|
|
who = couple.group(1)
|
|
|
|
who_operator = couple.group(2)
|
|
|
|
duration = couple.group(3)
|
|
|
|
which_line = couple.group(4)
|
|
|
|
host_or_ip = couple.group(5)
|
2023-05-03 16:43:41 +02:00
|
|
|
snote_dict = {
|
|
|
|
"notice": "tempban",
|
|
|
|
"who": who,
|
|
|
|
"operator": who_operator,
|
|
|
|
"duration": duration,
|
|
|
|
"type": which_line,
|
|
|
|
"target": host_or_ip,
|
|
|
|
}
|
2021-10-16 10:29:54 +02:00
|
|
|
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']}"
|
2021-06-19 12:38:43 +02:00
|
|
|
self._sendSnotice(irc, msg, repl)
|
|
|
|
# WHY THE FUCK IS IT elif ??
|
2023-05-03 16:43:41 +02:00
|
|
|
elif "XLINE" in text and "temporary" not in text and "removed" not in text:
|
|
|
|
perm_xline_regex = (
|
|
|
|
"^-XLINE- (.+) \[(.+)\] added (D-Line|K-Line) for (.+)$"
|
|
|
|
)
|
2021-06-19 12:38:43 +02:00
|
|
|
couple = re.match(perm_xline_regex, text)
|
|
|
|
who = couple.group(1)
|
|
|
|
who_operator = couple.group(2)
|
|
|
|
which_line = couple.group(3)
|
|
|
|
host_or_ip = couple.group(4)
|
2023-05-03 16:43:41 +02:00
|
|
|
snote_dict = {
|
|
|
|
"notice": "Permaban",
|
|
|
|
"who": who,
|
|
|
|
"operator": who_operator,
|
|
|
|
"type": which_line,
|
|
|
|
"target": host_or_ip,
|
|
|
|
}
|
2021-10-16 10:29:54 +02:00
|
|
|
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']}"
|
2021-06-19 12:38:43 +02:00
|
|
|
self._sendSnotice(irc, msg, repl)
|
2023-05-03 16:43:41 +02:00
|
|
|
elif "XLINE" in text and "removed" in text:
|
2021-06-19 12:38:43 +02:00
|
|
|
unxlineregex = "^-XLINE- (.+) removed (D-Line|K-Line) for (.+)$"
|
|
|
|
couple = re.match(unxlineregex, text)
|
|
|
|
who = couple.group(1)
|
|
|
|
which_line = couple.group(2)
|
|
|
|
host_or_ip = couple.group(3)
|
2023-05-03 16:43:41 +02:00
|
|
|
snote_dict = {
|
|
|
|
"notice": "unxline",
|
|
|
|
"who": who,
|
|
|
|
"type": which_line,
|
|
|
|
"target": host_or_ip,
|
|
|
|
}
|
2021-10-16 10:29:54 +02:00
|
|
|
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']}"
|
2021-06-19 12:38:43 +02:00
|
|
|
self._sendSnotice(irc, msg, repl)
|
2023-05-03 16:43:41 +02:00
|
|
|
if "KILL" in text:
|
2021-06-19 12:38:43 +02:00
|
|
|
killregex = "^-KILL- (.+) \[(.+)\] killed (\d) clients with a (KLINE|DLINE) \[(.+)\]$"
|
|
|
|
couple = re.match(killregex, text)
|
|
|
|
who = couple.group(1)
|
|
|
|
who_operator = couple.group(2)
|
|
|
|
clients = couple.group(3)
|
|
|
|
which_line = couple.group(4)
|
|
|
|
nick = couple.group(5)
|
2023-05-03 16:43:41 +02:00
|
|
|
snote_dict = {
|
|
|
|
"notice": "kill",
|
|
|
|
"who": who,
|
|
|
|
"operator": who_operator,
|
|
|
|
"client": clients,
|
|
|
|
"type": which_line,
|
|
|
|
"nick": nick,
|
|
|
|
}
|
2021-10-16 10:29:54 +02:00
|
|
|
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']}"
|
2021-06-19 12:38:43 +02:00
|
|
|
self._sendSnotice(irc, msg, repl)
|
2023-05-03 16:43:41 +02:00
|
|
|
if "NICK" in text and "changed nickname to" in text:
|
2021-06-19 12:38:43 +02:00
|
|
|
nickregex = "^-NICK- (.+) changed nickname to (.+)$"
|
|
|
|
couple = re.match(nickregex, text)
|
|
|
|
old_nick = couple.group(1)
|
|
|
|
new_nick = couple.group(2)
|
2023-05-03 16:43:41 +02:00
|
|
|
snote_dict = {
|
|
|
|
"notice": "nick change",
|
|
|
|
"old_nick": old_nick,
|
|
|
|
"new_nick": new_nick,
|
|
|
|
}
|
2021-10-16 10:29:54 +02:00
|
|
|
repl = f"\x02\x1FNOTICE: {snote_dict['notice']} ==> {snote_dict['old_nick']} changed their nick to {snote_dict['new_nick']}"
|
2021-06-19 12:38:43 +02:00
|
|
|
self._sendSnotice(irc, msg, repl)
|
2023-05-03 16:43:41 +02:00
|
|
|
if "QUIT" in text and "exited" in text:
|
2021-06-19 12:38:43 +02:00
|
|
|
quitregex = "^-QUIT- (.+) exited the network$"
|
|
|
|
couple = re.match(quitregex, text)
|
|
|
|
nick = couple.group(1)
|
2023-05-03 16:43:41 +02:00
|
|
|
snote_dict = {"notice": "quit", "nick": nick}
|
2021-06-19 12:38:43 +02:00
|
|
|
repl = f"\x02\x1FNOTICE: quit nick: {nick} has exited the network"
|
|
|
|
self._sendSnotice(irc, msg, repl)
|
2023-05-03 16:43:41 +02:00
|
|
|
if "ACCOUNT" in text and "registered account" in text:
|
2021-08-20 10:31:27 +02:00
|
|
|
accregex = "^-ACCOUNT- Client \[(.*)\] registered account \[(.*)\] from IP (.*)$"
|
|
|
|
couple = re.match(accregex, text)
|
|
|
|
hostmask = couple.group(1)
|
|
|
|
account = couple.group(2)
|
|
|
|
ip = couple.group(3)
|
2023-05-03 16:43:41 +02:00
|
|
|
snote_dict = {
|
|
|
|
"notice": "accreg",
|
|
|
|
"hostmask": hostmask,
|
|
|
|
"account": account,
|
|
|
|
"ip": ip,
|
|
|
|
}
|
2021-08-20 10:31:27 +02:00
|
|
|
repl = f"\x02\x1FNOTICE: accreg -> [{account}] was registered by hostmask [{hostmask}] from IP {ip}"
|
2021-08-31 16:29:17 +02:00
|
|
|
|
2021-08-20 13:44:44 +02:00
|
|
|
# Trigger HS SET
|
|
|
|
self._setvhost(irc, msg, account)
|
2021-08-20 10:31:27 +02:00
|
|
|
self._sendSnotice(irc, msg, repl)
|
2023-05-03 16:43:41 +02:00
|
|
|
|
|
|
|
if (
|
|
|
|
"ACCOUNT" in text
|
|
|
|
and "registered account" in text
|
|
|
|
and "SAREGISTER" in text
|
|
|
|
):
|
2021-08-20 10:31:27 +02:00
|
|
|
accregex = "^-ACCOUNT- Operator \[(.*)\] registered account \[(.*)\] with SAREGISTER$"
|
|
|
|
couple = re.match(accregex, text)
|
|
|
|
oper = couple.group(1)
|
|
|
|
account = couple.group(2)
|
2023-05-03 16:43:41 +02:00
|
|
|
snote_dict = {"notice": "sareg", "oper": oper, "account": account}
|
2021-08-20 10:31:27 +02:00
|
|
|
repl = f"\x02\x1FNOTICE: sareg -> [{account}] was registered by operator [{oper}]"
|
2021-08-31 16:29:17 +02:00
|
|
|
|
2021-08-20 13:44:44 +02:00
|
|
|
self._setvhost(irc, msg, account)
|
2021-08-20 10:31:27 +02:00
|
|
|
self._sendSnotice(irc, msg, repl)
|
2021-06-19 12:38:43 +02:00
|
|
|
|
2023-05-03 16:43:41 +02:00
|
|
|
if "OPER" in text and "Client opered up" in text:
|
2024-10-06 16:45:27 +02:00
|
|
|
operregex = "^-OPER- Client opered up \[(.*), (.*)\]$"
|
2021-08-29 00:13:44 +02:00
|
|
|
couple = re.match(operregex, text)
|
2021-08-31 16:29:17 +02:00
|
|
|
hostmask = couple.group(1)
|
|
|
|
oper = couple.group(2)
|
|
|
|
|
|
|
|
print(couple)
|
|
|
|
|
2023-05-03 16:43:41 +02:00
|
|
|
snote_dict = {"notice": "opered", "hostmask": hostmask, "oper": oper}
|
2021-08-31 16:29:17 +02:00
|
|
|
repl = f"\x02\x1FNOTICE:\x0F [{hostmask}] opered up as [{oper}]."
|
2021-08-29 00:13:44 +02:00
|
|
|
|
|
|
|
self._sendSnotice(irc, msg, repl)
|
|
|
|
|
2023-05-03 16:43:41 +02:00
|
|
|
if "OPER" in text and "Client deopered" in text:
|
2021-08-29 00:13:44 +02:00
|
|
|
operregex = "^-OPER- Client deopered \[(.*)\]"
|
|
|
|
couple = re.match(operregex, text)
|
|
|
|
account = couple.group(1)
|
2023-05-03 16:43:41 +02:00
|
|
|
snote_dict = {"notice": "deopered", "name": account}
|
2021-08-29 00:13:44 +02:00
|
|
|
repl = f"\x02\x1FNOTICE:\x0F [{account}] opered down."
|
|
|
|
|
|
|
|
self._sendSnotice(irc, msg, repl)
|
|
|
|
|
2021-08-20 13:44:44 +02:00
|
|
|
# Post Registration
|
2021-08-31 16:29:17 +02:00
|
|
|
|
2021-08-20 13:44:44 +02:00
|
|
|
def _setvhost(self, irc, msg, account):
|
2023-05-03 16:43:41 +02:00
|
|
|
arg = ["SET"]
|
2021-08-20 13:44:44 +02:00
|
|
|
arg.append(account)
|
2023-05-03 16:43:41 +02:00
|
|
|
vhost = self.registryValue("AutoVhost")
|
|
|
|
arg.append(f"{vhost}{account}")
|
|
|
|
irc.sendMsg(msg=ircmsgs.IrcMsg(command="HS", args=arg))
|
2021-08-20 13:44:44 +02:00
|
|
|
|
2021-08-31 16:29:17 +02:00
|
|
|
# Send formatted SNO to channel
|
2021-06-19 12:38:43 +02:00
|
|
|
|
|
|
|
def _sendSnotice(self, irc, msg, repl):
|
2021-08-20 13:44:44 +02:00
|
|
|
try:
|
2023-05-03 16:43:41 +02:00
|
|
|
channel = self.registryValue("targetChannel")
|
2021-09-07 16:33:00 +02:00
|
|
|
if irc.isChannel(channel):
|
2023-05-03 16:43:41 +02:00
|
|
|
irc.queueMsg(msg=ircmsgs.IrcMsg(command="NOTICE", args=(channel, repl)))
|
2021-08-20 13:44:44 +02:00
|
|
|
# what sort of exception does one raise
|
|
|
|
except:
|
|
|
|
pass
|
2021-08-31 16:29:17 +02:00
|
|
|
|
2021-06-19 12:38:43 +02:00
|
|
|
|
|
|
|
Class = SnoParser
|
|
|
|
|
|
|
|
|
|
|
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|