mirror of
https://github.com/iio612/DEFENDER.git
synced 2026-02-13 19:24:23 +00:00
V6.2.1 Adding main module utils and rehash utils to manager reload/rehash/restart
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
from core.base import Base
|
||||
from core.definition import MAdmin
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -24,7 +23,6 @@ class Admin:
|
||||
|
||||
for record in self.UID_ADMIN_DB:
|
||||
if record.uid == new_admin.uid:
|
||||
# If the admin exist then return False and do not go further
|
||||
self.Logs.debug(f'{record.uid} already exist')
|
||||
return False
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ class Command:
|
||||
DB_COMMANDS: list['MCommand'] = []
|
||||
|
||||
def __init__(self, loader: 'Loader'):
|
||||
self.Loader = loader
|
||||
self.Base = loader.Base
|
||||
|
||||
def build(self, new_command_obj: MCommand) -> bool:
|
||||
@@ -26,7 +27,7 @@ class Command:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def get_command(self, command_name: str, module_name: str) -> Optional[MCommand]:
|
||||
|
||||
for command in self.DB_COMMANDS:
|
||||
@@ -56,4 +57,27 @@ class Command:
|
||||
if cmd.command_level <= level:
|
||||
new_list.append(cmd)
|
||||
|
||||
return new_list
|
||||
return new_list
|
||||
|
||||
def is_client_allowed_to_run_command(self, nickname: str, command_name: str) -> bool:
|
||||
admin = self.Loader.Admin.get_admin(nickname)
|
||||
admin_level = admin.level if admin else 0
|
||||
commands = self.get_commands_by_level(admin_level)
|
||||
|
||||
if command_name in [command.command_name for command in commands]:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def is_command_exist(self, command_name: str) -> bool:
|
||||
"""Check if the command name exist
|
||||
|
||||
Args:
|
||||
command_name (str): The command name you want to check
|
||||
|
||||
Returns:
|
||||
bool: True if the command exist
|
||||
"""
|
||||
if command_name.lower() in [command.command_name.lower() for command in self.get_ordered_commands()]:
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -1,23 +1,32 @@
|
||||
from json import load
|
||||
from sys import exit
|
||||
from os import sep
|
||||
from typing import Union
|
||||
from typing import Any, Optional, Union, TYPE_CHECKING
|
||||
from core.definition import MConfig
|
||||
from logging import Logger
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.loader import Loader
|
||||
|
||||
class Configuration:
|
||||
|
||||
def __init__(self, logs: Logger) -> None:
|
||||
self.Logs = logs
|
||||
self.ConfigObject: MConfig = self.__load_service_configuration()
|
||||
def __init__(self, loader: 'Loader') -> None:
|
||||
|
||||
self.Loader = loader
|
||||
self.Logs = loader.Logs
|
||||
self._config_model: MConfig = self.__load_service_configuration()
|
||||
loader.ServiceLogging.set_file_handler_level(self._config_model.DEBUG_LEVEL)
|
||||
loader.ServiceLogging.set_stdout_handler_level(self._config_model.DEBUG_LEVEL)
|
||||
loader.ServiceLogging.update_handler_format(self._config_model.DEBUG_HARD)
|
||||
return None
|
||||
|
||||
def __load_json_service_configuration(self):
|
||||
def get_config_model(self) -> MConfig:
|
||||
return self._config_model
|
||||
|
||||
def __load_json_service_configuration(self) -> Optional[dict[str, Any]]:
|
||||
try:
|
||||
conf_filename = f'config{sep}configuration.json'
|
||||
with open(conf_filename, 'r') as configuration_data:
|
||||
configuration:dict[str, Union[str, int, list, dict]] = load(configuration_data)
|
||||
configuration: dict[str, Union[str, int, list, dict]] = load(configuration_data)
|
||||
|
||||
return configuration
|
||||
|
||||
@@ -48,11 +57,8 @@ class Configuration:
|
||||
import_config.pop(json_conf, None)
|
||||
self.Logs.warning(f"[!] The key {json_conf} is not expected, it has been removed from the system ! please remove it from configuration.json file [!]")
|
||||
|
||||
ConfigObject: MConfig = MConfig(
|
||||
**import_config
|
||||
)
|
||||
|
||||
return ConfigObject
|
||||
self.Logs.debug(f"[LOADING CONFIGURATION]: Loading configuration with {len(import_config)} parameters!")
|
||||
return MConfig(**import_config)
|
||||
|
||||
except TypeError as te:
|
||||
self.Logs.error(te)
|
||||
@@ -59,8 +59,8 @@ class Inspircd:
|
||||
"""
|
||||
try:
|
||||
batch_size = self.__Config.BATCH_SIZE
|
||||
User_from = self.__Irc.User.get_User(nick_from)
|
||||
User_to = self.__Irc.User.get_User(nick_to) if nick_to is None else None
|
||||
User_from = self.__Irc.User.get_user(nick_from)
|
||||
User_to = self.__Irc.User.get_user(nick_to) if nick_to is None else None
|
||||
|
||||
if User_from is None:
|
||||
self.__Logs.error(f"The sender nickname [{nick_from}] do not exist")
|
||||
@@ -88,8 +88,8 @@ class Inspircd:
|
||||
"""
|
||||
try:
|
||||
batch_size = self.__Config.BATCH_SIZE
|
||||
User_from = self.__Irc.User.get_User(nick_from)
|
||||
User_to = self.__Irc.User.get_User(nick_to)
|
||||
User_from = self.__Irc.User.get_user(nick_from)
|
||||
User_to = self.__Irc.User.get_user(nick_to)
|
||||
|
||||
if User_from is None or User_to is None:
|
||||
self.__Logs.error(f"The sender [{nick_from}] or the Reciever [{nick_to}] do not exist")
|
||||
@@ -188,17 +188,13 @@ class Inspircd:
|
||||
uidornickname (str): The UID or the Nickname
|
||||
reason (str): The reason for the quit
|
||||
"""
|
||||
user_obj = self.__Irc.User.get_User(uidornickname=uid)
|
||||
clone_obj = self.__Irc.Clone.get_clone(uidornickname=uid)
|
||||
user_obj = self.__Irc.User.get_user(uidornickname=uid)
|
||||
reputationObj = self.__Irc.Reputation.get_Reputation(uidornickname=uid)
|
||||
|
||||
if not user_obj is None:
|
||||
self.send2socket(f":{user_obj.uid} QUIT :{reason}", print_log=print_log)
|
||||
self.__Irc.User.delete(user_obj.uid)
|
||||
|
||||
if not clone_obj is None:
|
||||
self.__Irc.Clone.delete(clone_obj.uid)
|
||||
|
||||
if not reputationObj is None:
|
||||
self.__Irc.Reputation.delete(reputationObj.uid)
|
||||
|
||||
@@ -255,7 +251,7 @@ class Inspircd:
|
||||
print_log (bool, optional): Write logs. Defaults to True.
|
||||
"""
|
||||
|
||||
userObj = self.__Irc.User.get_User(uidornickname)
|
||||
userObj = self.__Irc.User.get_user(uidornickname)
|
||||
passwordChannel = password if not password is None else ''
|
||||
|
||||
if userObj is None:
|
||||
@@ -280,7 +276,7 @@ class Inspircd:
|
||||
print_log (bool, optional): Write logs. Defaults to True.
|
||||
"""
|
||||
|
||||
userObj = self.__Irc.User.get_User(uidornickname)
|
||||
userObj = self.__Irc.User.get_user(uidornickname)
|
||||
|
||||
if userObj is None:
|
||||
self.__Logs.error(f"The user [{uidornickname}] is not valid")
|
||||
@@ -311,7 +307,7 @@ class Inspircd:
|
||||
try:
|
||||
# [':adator_', 'UMODE2', '-iwx']
|
||||
|
||||
userObj = self.__Irc.User.get_User(str(serverMsg[0]).lstrip(':'))
|
||||
userObj = self.__Irc.User.get_user(str(serverMsg[0]).lstrip(':'))
|
||||
userMode = serverMsg[2]
|
||||
|
||||
if userObj is None: # If user is not created
|
||||
@@ -346,7 +342,6 @@ class Inspircd:
|
||||
self.__Irc.Channel.delete_user_from_all_channel(uid_who_quit)
|
||||
self.__Irc.User.delete(uid_who_quit)
|
||||
self.__Irc.Reputation.delete(uid_who_quit)
|
||||
self.__Irc.Clone.delete(uid_who_quit)
|
||||
|
||||
return None
|
||||
|
||||
@@ -655,7 +650,7 @@ class Inspircd:
|
||||
"""
|
||||
try:
|
||||
# ['@label=0073', ':0014E7P06', 'VERSION', 'PyDefender']
|
||||
getUser = self.__Irc.User.get_User(self.__Utils.clean_uid(serverMsg[1]))
|
||||
getUser = self.__Irc.User.get_user(self.__Utils.clean_uid(serverMsg[1]))
|
||||
|
||||
if getUser is None:
|
||||
return None
|
||||
@@ -663,7 +658,7 @@ class Inspircd:
|
||||
response_351 = f"{self.__Config.SERVICE_NAME.capitalize()}-{self.__Config.CURRENT_VERSION} {self.__Config.SERVICE_HOST} {self.name}"
|
||||
self.send2socket(f':{self.__Config.SERVICE_HOST} 351 {getUser.nickname} {response_351}')
|
||||
|
||||
modules = self.__Base.get_all_modules()
|
||||
modules = self.__Irc.ModuleUtils.get_all_available_modules()
|
||||
response_005 = ' | '.join(modules)
|
||||
self.send2socket(f':{self.__Config.SERVICE_HOST} 005 {getUser.nickname} {response_005} are supported by this server')
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ from ssl import SSLEOFError, SSLError
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.irc import Irc
|
||||
from core.definition import MClient
|
||||
|
||||
class Unrealircd6:
|
||||
|
||||
@@ -23,7 +24,8 @@ class Unrealircd6:
|
||||
'EOS', 'PRIVMSG', 'MODE', 'UMODE2',
|
||||
'VERSION', 'REPUTATION', 'SVS2MODE',
|
||||
'SLOG', 'NICK', 'PART', 'PONG',
|
||||
'PROTOCTL', 'SERVER', 'SMOD', 'TKL', 'NETINFO'}
|
||||
'PROTOCTL', 'SERVER', 'SMOD', 'TKL', 'NETINFO',
|
||||
'006', '007', '018'}
|
||||
|
||||
self.__Logs.info(f"** Loading protocol [{__name__}]")
|
||||
|
||||
@@ -44,6 +46,40 @@ class Unrealircd6:
|
||||
|
||||
return (-1, None)
|
||||
|
||||
def parse_server_msg(self, server_msg: list[str]) -> Optional[str]:
|
||||
"""Parse the server message and return the command
|
||||
|
||||
Args:
|
||||
server_msg (list[str]): The Original server message >>
|
||||
|
||||
Returns:
|
||||
Union[str, None]: Return the command protocol name
|
||||
"""
|
||||
protocol_exception = ['PING', 'SERVER', 'PROTOCTL']
|
||||
increment = 0
|
||||
server_msg_copy = server_msg.copy()
|
||||
first_index = 0
|
||||
second_index = 0
|
||||
for index, element in enumerate(server_msg_copy):
|
||||
# Handle the protocol exceptions ex. ping, server ....
|
||||
if element in protocol_exception and index == 0:
|
||||
return element
|
||||
|
||||
if element.startswith(':'):
|
||||
increment += 1
|
||||
first_index = index + 1 if increment == 1 else first_index
|
||||
second_index = index if increment == 2 else second_index
|
||||
|
||||
second_index = len(server_msg_copy) if second_index == 0 else second_index
|
||||
|
||||
parsed_msg = server_msg_copy[first_index:second_index]
|
||||
|
||||
for cmd in parsed_msg:
|
||||
if cmd in self.known_protocol:
|
||||
return cmd
|
||||
|
||||
return None
|
||||
|
||||
def send2socket(self, message: str, print_log: bool = True) -> None:
|
||||
"""Envoit les commandes à envoyer au serveur.
|
||||
|
||||
@@ -84,8 +120,8 @@ class Unrealircd6:
|
||||
"""
|
||||
try:
|
||||
batch_size = self.__Config.BATCH_SIZE
|
||||
User_from = self.__Irc.User.get_User(nick_from)
|
||||
User_to = self.__Irc.User.get_User(nick_to) if not nick_to is None else None
|
||||
User_from = self.__Irc.User.get_user(nick_from)
|
||||
User_to = self.__Irc.User.get_user(nick_to) if not nick_to is None else None
|
||||
|
||||
if User_from is None:
|
||||
self.__Logs.error(f"The sender nickname [{nick_from}] do not exist")
|
||||
@@ -115,8 +151,8 @@ class Unrealircd6:
|
||||
"""
|
||||
try:
|
||||
batch_size = self.__Config.BATCH_SIZE
|
||||
User_from = self.__Irc.User.get_User(nick_from)
|
||||
User_to = self.__Irc.User.get_User(nick_to)
|
||||
User_from = self.__Irc.User.get_user(nick_from)
|
||||
User_to = self.__Irc.User.get_user(nick_to)
|
||||
|
||||
if User_from is None or User_to is None:
|
||||
self.__Logs.error(f"The sender [{nick_from}] or the Reciever [{nick_to}] do not exist")
|
||||
@@ -129,40 +165,6 @@ class Unrealircd6:
|
||||
except Exception as err:
|
||||
self.__Logs.error(f"General Error: {err}")
|
||||
|
||||
def parse_server_msg(self, server_msg: list[str]) -> Optional[str]:
|
||||
"""Parse the server message and return the command
|
||||
|
||||
Args:
|
||||
server_msg (list[str]): The Original server message >>
|
||||
|
||||
Returns:
|
||||
Union[str, None]: Return the command protocol name
|
||||
"""
|
||||
protocol_exception = ['PING', 'SERVER', 'PROTOCTL']
|
||||
increment = 0
|
||||
server_msg_copy = server_msg.copy()
|
||||
first_index = 0
|
||||
second_index = 0
|
||||
for index, element in enumerate(server_msg_copy):
|
||||
# Handle the protocol exceptions ex. ping, server ....
|
||||
if element in protocol_exception and index == 0:
|
||||
return element
|
||||
|
||||
if element.startswith(':'):
|
||||
increment += 1
|
||||
first_index = index + 1 if increment == 1 else first_index
|
||||
second_index = index if increment == 2 else second_index
|
||||
|
||||
second_index = len(server_msg_copy) if second_index == 0 else second_index
|
||||
|
||||
parsed_msg = server_msg_copy[first_index:second_index]
|
||||
|
||||
for cmd in parsed_msg:
|
||||
if cmd in self.known_protocol:
|
||||
return cmd
|
||||
|
||||
return None
|
||||
|
||||
def send_link(self):
|
||||
"""Créer le link et envoyer les informations nécessaires pour la
|
||||
connexion au serveur.
|
||||
@@ -217,7 +219,7 @@ class Unrealircd6:
|
||||
"""
|
||||
self.send2socket(f":{self.__Config.SERVICE_NICKNAME} NICK {newnickname}")
|
||||
|
||||
userObj = self.__Irc.User.get_User(self.__Config.SERVICE_NICKNAME)
|
||||
userObj = self.__Irc.User.get_user(self.__Config.SERVICE_NICKNAME)
|
||||
self.__Irc.User.update_nickname(userObj.uid, newnickname)
|
||||
return None
|
||||
|
||||
@@ -275,7 +277,7 @@ class Unrealircd6:
|
||||
"""
|
||||
try:
|
||||
|
||||
userObj = self.__Irc.User.get_User(uidornickname=nick_to_sapart)
|
||||
userObj = self.__Irc.User.get_user(uidornickname=nick_to_sapart)
|
||||
chanObj = self.__Irc.Channel.get_channel(channel_name)
|
||||
service_uid = self.__Config.SERVICE_ID
|
||||
|
||||
@@ -299,7 +301,7 @@ class Unrealircd6:
|
||||
"""
|
||||
try:
|
||||
|
||||
userObj = self.__Irc.User.get_User(uidornickname=nick_to_sajoin)
|
||||
userObj = self.__Irc.User.get_user(uidornickname=nick_to_sajoin)
|
||||
chanObj = self.__Irc.Channel.get_channel(channel_name)
|
||||
service_uid = self.__Config.SERVICE_ID
|
||||
|
||||
@@ -327,25 +329,92 @@ class Unrealircd6:
|
||||
except Exception as err:
|
||||
self.__Logs.error(f"{__name__} - General Error: {err}")
|
||||
|
||||
def send_svs_mode(self, nickname: str, user_mode: str) -> None:
|
||||
try:
|
||||
def send_svspart(self, nick_to_part: str, channels: list[str], reason: str) -> None:
|
||||
user_obj = self.__Irc.User.get_user(nick_to_part)
|
||||
|
||||
userObj = self.__Irc.User.get_User(uidornickname=nickname)
|
||||
if user_obj is None:
|
||||
self.__Logs.debug(f"[SVSPART] The nickname {nick_to_part} do not exist!")
|
||||
return None
|
||||
|
||||
channels_list = ','.join([channel for channel in channels if self.__Irc.Channel.is_valid_channel(channel)])
|
||||
service_id = self.__Config.SERVICE_ID
|
||||
self.send2socket(f':{service_id} SVSPART {user_obj.nickname} {channels_list} {reason}')
|
||||
return None
|
||||
|
||||
def send_svsjoin(self, nick_to_part: str, channels: list[str], keys: list[str]) -> None:
|
||||
user_obj = self.__Irc.User.get_user(nick_to_part)
|
||||
|
||||
if user_obj is None:
|
||||
self.__Logs.debug(f"[SVSJOIN] The nickname {nick_to_part} do not exist!")
|
||||
return None
|
||||
|
||||
channels_list = ','.join([channel for channel in channels if self.__Irc.Channel.is_valid_channel(channel)])
|
||||
keys_list = ','.join([key for key in keys])
|
||||
service_id = self.__Config.SERVICE_ID
|
||||
self.send2socket(f':{service_id} SVSJOIN {user_obj.nickname} {channels_list} {keys_list}')
|
||||
return None
|
||||
|
||||
def send_svsmode(self, nickname: str, user_mode: str) -> None:
|
||||
try:
|
||||
user_obj = self.__Irc.User.get_user(uidornickname=nickname)
|
||||
service_uid = self.__Config.SERVICE_ID
|
||||
|
||||
if userObj is None:
|
||||
# User not exist: leave
|
||||
if user_obj is None:
|
||||
return None
|
||||
|
||||
self.send2socket(f':{service_uid} SVSMODE {nickname} {user_mode}')
|
||||
|
||||
# Update new mode
|
||||
self.__Irc.User.update_mode(userObj.uid, user_mode)
|
||||
self.__Irc.User.update_mode(user_obj.uid, user_mode)
|
||||
|
||||
return None
|
||||
except Exception as err:
|
||||
self.__Logs.error(f"{__name__} - General Error: {err}")
|
||||
|
||||
def send_svs2mode(self, nickname: str, user_mode: str) -> None:
|
||||
try:
|
||||
user_obj = self.__Irc.User.get_user(uidornickname=nickname)
|
||||
service_uid = self.__Config.SERVICE_ID
|
||||
|
||||
if user_obj is None:
|
||||
return None
|
||||
|
||||
self.send2socket(f':{service_uid} SVS2MODE {nickname} {user_mode}')
|
||||
|
||||
# Update new mode
|
||||
self.__Irc.User.update_mode(user_obj.uid, user_mode)
|
||||
|
||||
return None
|
||||
except Exception as err:
|
||||
self.__Logs.error(f"{__name__} - General Error: {err}")
|
||||
|
||||
def send_svslogin(self, client_uid: str, user_account: str) -> None:
|
||||
"""Log a client into his account.
|
||||
|
||||
Args:
|
||||
client_uid (str): Client UID
|
||||
user_account (str): The account of the user
|
||||
"""
|
||||
try:
|
||||
self.send2socket(f":{self.__Irc.Config.SERVEUR_LINK} SVSLOGIN {self.__Settings.MAIN_SERVER_HOSTNAME} {client_uid} {user_account}")
|
||||
except Exception as err:
|
||||
self.__Irc.Logs.error(f'General Error: {err}')
|
||||
|
||||
def send_svslogout(self, client_obj: 'MClient') -> None:
|
||||
"""Logout a client from his account
|
||||
|
||||
Args:
|
||||
client_uid (str): The Client UID
|
||||
"""
|
||||
try:
|
||||
c_uid = client_obj.uid
|
||||
c_nickname = client_obj.nickname
|
||||
self.send2socket(f":{self.__Irc.Config.SERVEUR_LINK} SVSLOGIN {self.__Settings.MAIN_SERVER_HOSTNAME} {c_uid} 0")
|
||||
self.send_svs2mode(c_nickname, '-r')
|
||||
|
||||
except Exception as err:
|
||||
self.__Irc.Logs.error(f'General Error: {err}')
|
||||
|
||||
def send_quit(self, uid: str, reason: str, print_log: True) -> None:
|
||||
"""Send quit message
|
||||
- Delete uid from User object
|
||||
@@ -355,7 +424,7 @@ class Unrealircd6:
|
||||
uidornickname (str): The UID or the Nickname
|
||||
reason (str): The reason for the quit
|
||||
"""
|
||||
user_obj = self.__Irc.User.get_User(uidornickname=uid)
|
||||
user_obj = self.__Irc.User.get_user(uidornickname=uid)
|
||||
reputationObj = self.__Irc.Reputation.get_Reputation(uidornickname=uid)
|
||||
|
||||
if not user_obj is None:
|
||||
@@ -418,7 +487,7 @@ class Unrealircd6:
|
||||
print_log (bool, optional): Write logs. Defaults to True.
|
||||
"""
|
||||
|
||||
userObj = self.__Irc.User.get_User(uidornickname)
|
||||
userObj = self.__Irc.User.get_user(uidornickname)
|
||||
passwordChannel = password if not password is None else ''
|
||||
|
||||
if userObj is None:
|
||||
@@ -458,7 +527,7 @@ class Unrealircd6:
|
||||
print_log (bool, optional): Write logs. Defaults to True.
|
||||
"""
|
||||
|
||||
userObj = self.__Irc.User.get_User(uidornickname)
|
||||
userObj = self.__Irc.User.get_user(uidornickname)
|
||||
|
||||
if userObj is None:
|
||||
self.__Logs.error(f"The user [{uidornickname}] is not valid")
|
||||
@@ -506,7 +575,7 @@ class Unrealircd6:
|
||||
uid_user_to_edit = serverMsg[2]
|
||||
umode = serverMsg[3]
|
||||
|
||||
userObj = self.__Irc.User.get_User(uid_user_to_edit)
|
||||
userObj = self.__Irc.User.get_user(uid_user_to_edit)
|
||||
|
||||
if userObj is None:
|
||||
return None
|
||||
@@ -540,7 +609,7 @@ class Unrealircd6:
|
||||
try:
|
||||
# [':adator_', 'UMODE2', '-iwx']
|
||||
|
||||
userObj = self.__Irc.User.get_User(str(serverMsg[0]).lstrip(':'))
|
||||
userObj = self.__Irc.User.get_user(str(serverMsg[0]).lstrip(':'))
|
||||
userMode = serverMsg[2]
|
||||
|
||||
if userObj is None: # If user is not created
|
||||
@@ -794,8 +863,8 @@ class Unrealircd6:
|
||||
self.__Config.DEFENDER_INIT = 0
|
||||
|
||||
# Send EOF to other modules
|
||||
for classe_name, classe_object in self.__Irc.loaded_classes.items():
|
||||
classe_object.cmd(server_msg_copy)
|
||||
for module in self.__Irc.ModuleUtils.model_get_loaded_modules().copy():
|
||||
module.class_instance.cmd(server_msg_copy)
|
||||
|
||||
return None
|
||||
except IndexError as ie:
|
||||
@@ -907,27 +976,14 @@ class Unrealircd6:
|
||||
"""
|
||||
try:
|
||||
srv_msg = serverMsg.copy()
|
||||
|
||||
cmd = serverMsg.copy()
|
||||
# Supprimer la premiere valeur si MTAGS activé
|
||||
if cmd[0].startswith('@'):
|
||||
cmd.pop(0)
|
||||
|
||||
# Hide auth logs
|
||||
if len(cmd) == 7:
|
||||
if cmd[2] == 'PRIVMSG' and cmd[4] == ':auth':
|
||||
data_copy = cmd.copy()
|
||||
data_copy[6] = '**********'
|
||||
self.__Logs.debug(f">> {data_copy}")
|
||||
else:
|
||||
self.__Logs.debug(f">> {cmd}")
|
||||
else:
|
||||
self.__Logs.debug(f">> {cmd}")
|
||||
|
||||
get_uid_or_nickname = str(cmd[0].replace(':',''))
|
||||
user_trigger = self.__Irc.User.get_nickname(get_uid_or_nickname)
|
||||
dnickname = self.__Config.SERVICE_NICKNAME
|
||||
|
||||
pattern = fr'(:\{self.__Config.SERVICE_PREFIX})(.*)$'
|
||||
hcmds = search(pattern, ' '.join(cmd)) # va matcher avec tout les caractéres aprés le .
|
||||
|
||||
@@ -936,7 +992,7 @@ class Unrealircd6:
|
||||
convert_to_string = ' '.join(liste_des_commandes)
|
||||
arg = convert_to_string.split()
|
||||
arg.remove(f':{self.__Config.SERVICE_PREFIX}')
|
||||
if not arg[0].lower() in self.__Irc.module_commands_list:
|
||||
if not self.__Irc.Commands.is_command_exist(arg[0]):
|
||||
self.__Logs.debug(f"This command {arg[0]} is not available")
|
||||
self.send_notice(
|
||||
nick_from=self.__Config.SERVICE_NICKNAME,
|
||||
@@ -945,6 +1001,15 @@ class Unrealircd6:
|
||||
)
|
||||
return None
|
||||
|
||||
# if not arg[0].lower() in self.__Irc.module_commands_list:
|
||||
# self.__Logs.debug(f"This command {arg[0]} is not available")
|
||||
# self.send_notice(
|
||||
# nick_from=self.__Config.SERVICE_NICKNAME,
|
||||
# nick_to=user_trigger,
|
||||
# msg=f"This command [{self.__Config.COLORS.bold}{arg[0]}{self.__Config.COLORS.bold}] is not available"
|
||||
# )
|
||||
# return None
|
||||
|
||||
cmd_to_send = convert_to_string.replace(':','')
|
||||
self.__Base.log_cmd(user_trigger, cmd_to_send)
|
||||
|
||||
@@ -963,21 +1028,25 @@ class Unrealircd6:
|
||||
# Réponse a un CTCP VERSION
|
||||
if arg[0] == '\x01VERSION\x01':
|
||||
self.on_version(srv_msg)
|
||||
return False
|
||||
return None
|
||||
|
||||
# Réponse a un TIME
|
||||
if arg[0] == '\x01TIME\x01':
|
||||
self.on_time(srv_msg)
|
||||
return False
|
||||
return None
|
||||
|
||||
# Réponse a un PING
|
||||
if arg[0] == '\x01PING':
|
||||
self.on_ping(srv_msg)
|
||||
return False
|
||||
return None
|
||||
|
||||
if not arg[0].lower() in self.__Irc.module_commands_list:
|
||||
if not self.__Irc.Commands.is_command_exist(arg[0]):
|
||||
self.__Logs.debug(f"This command {arg[0]} sent by {user_trigger} is not available")
|
||||
return False
|
||||
return None
|
||||
|
||||
# if not arg[0].lower() in self.__Irc.module_commands_list:
|
||||
# self.__Logs.debug(f"This command {arg[0]} sent by {user_trigger} is not available")
|
||||
# return False
|
||||
|
||||
cmd_to_send = convert_to_string.replace(':','')
|
||||
self.__Base.log_cmd(user_trigger, cmd_to_send)
|
||||
@@ -1011,6 +1080,14 @@ class Unrealircd6:
|
||||
except Exception as err:
|
||||
self.__Logs.error(f"{__name__} - General Error: {err}")
|
||||
|
||||
def on_server(self, serverMsg: list[str]) -> None:
|
||||
try:
|
||||
# ['SERVER', 'irc.local.org', '1', ':U6100-Fhn6OoE-001', 'Local', 'Server']
|
||||
sCopy = serverMsg.copy()
|
||||
self.__Irc.Settings.MAIN_SERVER_HOSTNAME = sCopy[1]
|
||||
except Exception as err:
|
||||
self.__Irc.Logs.error(f'General Error: {err}')
|
||||
|
||||
def on_version(self, serverMsg: list[str]) -> None:
|
||||
"""Sending Server Version to the server
|
||||
|
||||
@@ -1105,7 +1182,7 @@ class Unrealircd6:
|
||||
if '@' in list(serverMsg_copy[0])[0]:
|
||||
serverMsg_copy.pop(0)
|
||||
|
||||
getUser = self.__Irc.User.get_User(self.__Utils.clean_uid(serverMsg_copy[0]))
|
||||
getUser = self.__Irc.User.get_user(self.__Utils.clean_uid(serverMsg_copy[0]))
|
||||
|
||||
if getUser is None:
|
||||
return None
|
||||
@@ -1113,7 +1190,7 @@ class Unrealircd6:
|
||||
response_351 = f"{self.__Config.SERVICE_NAME.capitalize()}-{self.__Config.CURRENT_VERSION} {self.__Config.SERVICE_HOST} {self.name}"
|
||||
self.send2socket(f':{self.__Config.SERVICE_HOST} 351 {getUser.nickname} {response_351}')
|
||||
|
||||
modules = self.__Base.get_all_modules()
|
||||
modules = self.__Irc.ModuleUtils.get_all_available_modules()
|
||||
response_005 = ' | '.join(modules)
|
||||
self.send2socket(f':{self.__Config.SERVICE_HOST} 005 {getUser.nickname} {response_005} are supported by this server')
|
||||
|
||||
|
||||
115
core/classes/rehash.py
Normal file
115
core/classes/rehash.py
Normal file
@@ -0,0 +1,115 @@
|
||||
import importlib
|
||||
import sys
|
||||
import time
|
||||
from typing import TYPE_CHECKING
|
||||
import socket
|
||||
from core.classes.protocol import Protocol
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.irc import Irc
|
||||
|
||||
# Modules impacted by rehashing!
|
||||
REHASH_MODULES = [
|
||||
'core.definition',
|
||||
'core.utils',
|
||||
'core.classes.config',
|
||||
'core.base',
|
||||
'core.classes.commands',
|
||||
'core.classes.protocols.unreal6',
|
||||
'core.classes.protocols.inspircd',
|
||||
'core.classes.protocol'
|
||||
]
|
||||
|
||||
|
||||
def restart_service(uplink: 'Irc', reason: str = "Restarting with no reason!") -> None:
|
||||
|
||||
# reload modules.
|
||||
for module in uplink.ModuleUtils.model_get_loaded_modules().copy():
|
||||
uplink.ModuleUtils.unload_one_module(uplink, module.module_name)
|
||||
|
||||
uplink.ModuleUtils.model_clear() # Clear loaded modules.
|
||||
uplink.User.UID_DB.clear() # Clear User Object
|
||||
uplink.Channel.UID_CHANNEL_DB.clear() # Clear Channel Object
|
||||
uplink.Client.CLIENT_DB.clear() # Clear Client object
|
||||
uplink.Base.garbage_collector_thread()
|
||||
|
||||
# Reload configuration
|
||||
uplink.Config = uplink.Loader.ConfModule.Configuration(uplink.Loader).get_config_model()
|
||||
uplink.Base = uplink.Loader.BaseModule.Base(uplink.Loader)
|
||||
uplink.Protocol = Protocol(uplink.Config.SERVEUR_PROTOCOL, uplink.ircObject).Protocol
|
||||
uplink.Logs.debug(f'[{uplink.Config.SERVICE_NICKNAME} RESTART]: Reloading configuration!')
|
||||
|
||||
uplink.Protocol.send_squit(server_id=uplink.Config.SERVEUR_ID, server_link=uplink.Config.SERVEUR_LINK, reason="Defender Power off")
|
||||
|
||||
uplink.Logs.debug('Restarting Defender ...')
|
||||
uplink.IrcSocket.shutdown(socket.SHUT_RDWR)
|
||||
uplink.IrcSocket.close()
|
||||
|
||||
while uplink.IrcSocket.fileno() != -1:
|
||||
time.sleep(0.5)
|
||||
uplink.Logs.warning('-- Waiting for socket to close ...')
|
||||
|
||||
uplink.init_service_user()
|
||||
uplink.Utils.create_socket(uplink)
|
||||
uplink.Protocol.send_link()
|
||||
uplink.join_saved_channels()
|
||||
uplink.ModuleUtils.db_load_all_existing_modules(uplink)
|
||||
uplink.Config.DEFENDER_RESTART = 0
|
||||
|
||||
def rehash_service(uplink: 'Irc', nickname: str) -> None:
|
||||
need_a_restart = ["SERVEUR_ID"]
|
||||
uplink.Settings.set_cache('db_commands', uplink.Commands.DB_COMMANDS)
|
||||
restart_flag = False
|
||||
config_model_bakcup = uplink.Config
|
||||
mods = REHASH_MODULES
|
||||
for mod in mods:
|
||||
importlib.reload(sys.modules[mod])
|
||||
uplink.Protocol.send_priv_msg(
|
||||
nick_from=uplink.Config.SERVICE_NICKNAME,
|
||||
msg=f'[REHASH] Module [{mod}] reloaded',
|
||||
channel=uplink.Config.SERVICE_CHANLOG
|
||||
)
|
||||
|
||||
uplink.Config = uplink.Loader.ConfModule.Configuration(uplink.Loader).get_config_model()
|
||||
uplink.Config.HSID = config_model_bakcup.HSID
|
||||
uplink.Config.DEFENDER_INIT = config_model_bakcup.DEFENDER_INIT
|
||||
uplink.Config.DEFENDER_RESTART = config_model_bakcup.DEFENDER_RESTART
|
||||
uplink.Config.SSL_VERSION = config_model_bakcup.SSL_VERSION
|
||||
uplink.Config.CURRENT_VERSION = config_model_bakcup.CURRENT_VERSION
|
||||
uplink.Config.LATEST_VERSION = config_model_bakcup.LATEST_VERSION
|
||||
|
||||
conf_bkp_dict: dict = config_model_bakcup.to_dict()
|
||||
config_dict: dict = uplink.Config.to_dict()
|
||||
|
||||
for key, value in conf_bkp_dict.items():
|
||||
if config_dict[key] != value and key != 'COLORS':
|
||||
uplink.Protocol.send_priv_msg(
|
||||
nick_from=uplink.Config.SERVICE_NICKNAME,
|
||||
msg=f'[{key}]: {value} ==> {config_dict[key]}',
|
||||
channel=uplink.Config.SERVICE_CHANLOG
|
||||
)
|
||||
if key in need_a_restart:
|
||||
restart_flag = True
|
||||
|
||||
if config_model_bakcup.SERVICE_NICKNAME != uplink.Config.SERVICE_NICKNAME:
|
||||
uplink.Protocol.send_set_nick(uplink.Config.SERVICE_NICKNAME)
|
||||
|
||||
if restart_flag:
|
||||
uplink.Config.SERVEUR_ID = config_model_bakcup.SERVEUR_ID
|
||||
uplink.Protocol.send_priv_msg(
|
||||
nick_from=uplink.Config.SERVICE_NICKNAME,
|
||||
channel=uplink.Config.SERVICE_CHANLOG,
|
||||
msg='You need to restart defender !')
|
||||
|
||||
# Reload Main Commands Module
|
||||
uplink.Commands = uplink.Loader.CommandModule.Command(uplink.Loader)
|
||||
uplink.Commands.DB_COMMANDS = uplink.Settings.get_cache('db_commands')
|
||||
|
||||
uplink.Base = uplink.Loader.BaseModule.Base(uplink.Loader)
|
||||
uplink.Protocol = Protocol(uplink.Config.SERVEUR_PROTOCOL, uplink.ircObject).Protocol
|
||||
|
||||
# Reload Service modules
|
||||
for module in uplink.ModuleUtils.model_get_loaded_modules().copy():
|
||||
uplink.ModuleUtils.reload_one_module(uplink, module.module_name, nickname)
|
||||
|
||||
return None
|
||||
@@ -18,6 +18,7 @@ class Settings:
|
||||
|
||||
CONSOLE: bool = False
|
||||
|
||||
MAIN_SERVER_HOSTNAME: str = None
|
||||
PROTOCTL_USER_MODES: list[str] = []
|
||||
PROTOCTL_PREFIX: list[str] = []
|
||||
|
||||
|
||||
@@ -25,8 +25,7 @@ class User:
|
||||
bool: True if inserted
|
||||
"""
|
||||
|
||||
user_obj = self.get_User(new_user.uid)
|
||||
|
||||
user_obj = self.get_user(new_user.uid)
|
||||
if not user_obj is None:
|
||||
# User already created return False
|
||||
return False
|
||||
@@ -45,7 +44,7 @@ class User:
|
||||
Returns:
|
||||
bool: True if updated
|
||||
"""
|
||||
user_obj = self.get_User(uidornickname=uid)
|
||||
user_obj = self.get_user(uidornickname=uid)
|
||||
|
||||
if user_obj is None:
|
||||
return False
|
||||
@@ -65,7 +64,7 @@ class User:
|
||||
bool: True if user mode has been updaed
|
||||
"""
|
||||
response = True
|
||||
user_obj = self.get_User(uidornickname=uidornickname)
|
||||
user_obj = self.get_user(uidornickname=uidornickname)
|
||||
|
||||
if user_obj is None:
|
||||
return False
|
||||
@@ -107,7 +106,7 @@ class User:
|
||||
bool: True if deleted
|
||||
"""
|
||||
|
||||
user_obj = self.get_User(uidornickname=uid)
|
||||
user_obj = self.get_user(uidornickname=uid)
|
||||
|
||||
if user_obj is None:
|
||||
return False
|
||||
@@ -116,7 +115,7 @@ class User:
|
||||
|
||||
return True
|
||||
|
||||
def get_User(self, uidornickname: str) -> Optional['MUser']:
|
||||
def get_user(self, uidornickname: str) -> Optional['MUser']:
|
||||
"""Get The User Object model
|
||||
|
||||
Args:
|
||||
@@ -143,7 +142,7 @@ class User:
|
||||
str|None: Return the UID
|
||||
"""
|
||||
|
||||
user_obj = self.get_User(uidornickname=uidornickname)
|
||||
user_obj = self.get_user(uidornickname=uidornickname)
|
||||
|
||||
if user_obj is None:
|
||||
return None
|
||||
@@ -159,7 +158,7 @@ class User:
|
||||
Returns:
|
||||
str|None: the nickname
|
||||
"""
|
||||
user_obj = self.get_User(uidornickname=uidornickname)
|
||||
user_obj = self.get_user(uidornickname=uidornickname)
|
||||
|
||||
if user_obj is None:
|
||||
return None
|
||||
@@ -175,7 +174,7 @@ class User:
|
||||
Returns:
|
||||
Union[dict[str, any], None]: User Object as a dictionary or None
|
||||
"""
|
||||
user_obj = self.get_User(uidornickname=uidornickname)
|
||||
user_obj = self.get_user(uidornickname=uidornickname)
|
||||
|
||||
if user_obj is None:
|
||||
return None
|
||||
@@ -191,7 +190,7 @@ class User:
|
||||
Returns:
|
||||
bool: True if exist
|
||||
"""
|
||||
user_obj = self.get_User(uidornickname=uidornikname)
|
||||
user_obj = self.get_user(uidornickname=uidornikname)
|
||||
|
||||
if user_obj is None:
|
||||
return False
|
||||
@@ -226,7 +225,7 @@ class User:
|
||||
int: How long in minutes has the user been connected?
|
||||
"""
|
||||
|
||||
get_user = self.get_User(uidornickname)
|
||||
get_user = self.get_user(uidornickname)
|
||||
if get_user is None:
|
||||
return 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user