mirror of
https://github.com/iio612/DEFENDER.git
synced 2026-02-13 19:24:23 +00:00
Update parse_uid, now it returns MUser object.
This commit is contained in:
@@ -1186,35 +1186,15 @@ class Inspircd(IProtocol):
|
|||||||
# COMMON IRC PARSER
|
# COMMON IRC PARSER
|
||||||
# ------------------------------------------------------------------------
|
# ------------------------------------------------------------------------
|
||||||
|
|
||||||
def parse_uid(self, server_msg: list[str]) -> dict[str, str]:
|
def parse_uid(self, server_msg: list[str]) -> Optional['MUser']:
|
||||||
"""Parse UID and return dictionary.
|
"""Parse UID and return dictionary.
|
||||||
|
>>> [':97K', 'UID', '97KAAAAAC', '1762113659', 'adator_', '172.18.128.1', '172.18.128.1', '...', '...', '172.18.128.1', '1762113659', '+', ':...']
|
||||||
Args:
|
Args:
|
||||||
server_msg (list[str]): _description_
|
server_msg (list[str]): _description_
|
||||||
"""
|
"""
|
||||||
umodes = str(server_msg[11])
|
scopy = server_msg.copy()
|
||||||
remote_ip = server_msg[9] if 'S' not in umodes else '127.0.0.1'
|
uid = scopy[2]
|
||||||
|
return self._User.get_user(uid)
|
||||||
# Extract Geoip information
|
|
||||||
pattern = r'^.*geoip=cc=(\S{2}).*$'
|
|
||||||
geoip_match = match(pattern, server_msg[0])
|
|
||||||
geoip = geoip_match.group(1) if geoip_match else None
|
|
||||||
|
|
||||||
response = {
|
|
||||||
'uid': str(server_msg[2]),
|
|
||||||
'nickname': str(server_msg[4]),
|
|
||||||
'username': str(server_msg[7]),
|
|
||||||
'hostname': str(server_msg[5]),
|
|
||||||
'umodes': umodes,
|
|
||||||
'vhost': str(server_msg[6]),
|
|
||||||
'ip': remote_ip,
|
|
||||||
'realname': ' '.join(server_msg[12:]).lstrip(':'),
|
|
||||||
'geoip': geoip,
|
|
||||||
'reputation_score': 0,
|
|
||||||
'iswebirc': True if 'webirc' in server_msg[0] else False,
|
|
||||||
'iswebsocket': True if 'websocket' in server_msg[0] else False
|
|
||||||
}
|
|
||||||
return response
|
|
||||||
|
|
||||||
def parse_quit(self, server_msg: list[str]) -> dict[str, str]:
|
def parse_quit(self, server_msg: list[str]) -> dict[str, str]:
|
||||||
"""Parse quit and return dictionary.
|
"""Parse quit and return dictionary.
|
||||||
|
|||||||
@@ -316,14 +316,14 @@ class IProtocol(ABC):
|
|||||||
# ------------------------------------------------------------------------
|
# ------------------------------------------------------------------------
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def parse_uid(self, serverMsg: list[str]) -> dict[str, str]:
|
def parse_uid(self, serverMsg: list[str]) -> Optional['MUser']:
|
||||||
"""Parse UID and return dictionary.
|
"""Parse UID and return dictionary.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
serverMsg (list[str]): The UID IRCD message
|
serverMsg (list[str]): The UID IRCD message
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict[str, str]: The response as dictionary.
|
Optional[MUser]: The MUser object or None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
|||||||
@@ -630,35 +630,18 @@ class Unrealircd6(IProtocol):
|
|||||||
# COMMON IRC PARSER
|
# COMMON IRC PARSER
|
||||||
# ------------------------------------------------------------------------
|
# ------------------------------------------------------------------------
|
||||||
|
|
||||||
def parse_uid(self, serverMsg: list[str]) -> dict[str, str]:
|
def parse_uid(self, serverMsg: list[str]) -> Optional['MUser']:
|
||||||
"""Parse UID and return dictionary.
|
"""Parse UID and return dictionary.
|
||||||
>>> ['@s2s-md/geoip=cc=GBtag...', ':001', 'UID', 'albatros', '0', '1721564597', 'albatros', 'hostname...', '001HB8G04', '0', '+iwxz', 'hostname-vhost', 'hostname-vhost', 'MyZBwg==', ':...']
|
>>> ['@s2s-md/geoip=cc=GBtag...', ':001', 'UID', 'albatros', '0', '1721564597', 'albatros', 'hostname...', '001HB8G04', '0', '+iwxz', 'hostname-vhost', 'hostname-vhost', 'MyZBwg==', ':...']
|
||||||
Args:
|
Args:
|
||||||
serverMsg (list[str]): The UID ircd response
|
serverMsg (list[str]): The UID ircd response
|
||||||
"""
|
"""
|
||||||
umodes = str(serverMsg[10])
|
scopy = serverMsg.copy()
|
||||||
remote_ip = self._Base.decode_ip(str(serverMsg[13])) if 'S' not in umodes else '127.0.0.1'
|
if '@' in scopy[0]:
|
||||||
|
scopy.pop(0)
|
||||||
|
|
||||||
# Extract Geoip information
|
uid = scopy[7]
|
||||||
pattern = r'^.*geoip=cc=(\S{2}).*$'
|
return self._User.get_user(uid)
|
||||||
geoip_match = match(pattern, serverMsg[0])
|
|
||||||
geoip = geoip_match.group(1) if geoip_match else None
|
|
||||||
|
|
||||||
response = {
|
|
||||||
'uid': str(serverMsg[8]),
|
|
||||||
'nickname': str(serverMsg[3]),
|
|
||||||
'username': str(serverMsg[6]),
|
|
||||||
'hostname': str(serverMsg[7]),
|
|
||||||
'umodes': umodes,
|
|
||||||
'vhost': str(serverMsg[11]),
|
|
||||||
'ip': remote_ip,
|
|
||||||
'realname': ' '.join(serverMsg[12:]).lstrip(':'),
|
|
||||||
'geoip': geoip,
|
|
||||||
'reputation_score': 0,
|
|
||||||
'iswebirc': True if 'webirc' in serverMsg[0] else False,
|
|
||||||
'iswebsocket': True if 'websocket' in serverMsg[0] else False
|
|
||||||
}
|
|
||||||
return response
|
|
||||||
|
|
||||||
def parse_quit(self, serverMsg: list[str]) -> dict[str, str]:
|
def parse_quit(self, serverMsg: list[str]) -> dict[str, str]:
|
||||||
"""Parse quit and return dictionary.
|
"""Parse quit and return dictionary.
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ def handle_on_uid(uplink: 'Defender', srvmsg: list[str]):
|
|||||||
uplink (Defender): The Defender instance
|
uplink (Defender): The Defender instance
|
||||||
srvmsg (list[str]): The Server MSG
|
srvmsg (list[str]): The Server MSG
|
||||||
"""
|
"""
|
||||||
parser_uid = uplink.Protocol.parse_uid(srvmsg)
|
_User = uplink.Protocol.parse_uid(srvmsg)
|
||||||
gconfig = uplink.Config
|
gconfig = uplink.Config
|
||||||
irc = uplink.Irc
|
irc = uplink.Irc
|
||||||
confmodel = uplink.ModConfig
|
confmodel = uplink.ModConfig
|
||||||
@@ -222,10 +222,8 @@ def handle_on_uid(uplink: 'Defender', srvmsg: list[str]):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
# Get User information
|
# Get User information
|
||||||
_User = irc.User.get_user(parser_uid.get('uid', None))
|
|
||||||
|
|
||||||
if _User is None:
|
if _User is None:
|
||||||
irc.Logs.warning(f'This UID: [{parser_uid.get("uid", None)}] is not available please check why')
|
irc.Logs.warning(f'Error when parsing UID', exc_info=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
# If user is not service or IrcOp then scan them
|
# If user is not service or IrcOp then scan them
|
||||||
|
|||||||
Reference in New Issue
Block a user