mirror of
https://github.com/iio612/DEFENDER.git
synced 2026-02-13 19:24:23 +00:00
Remove json configuration and replace it by yaml configuration files.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,6 +6,7 @@ db/
|
|||||||
logs/
|
logs/
|
||||||
__pycache__/
|
__pycache__/
|
||||||
configuration.json
|
configuration.json
|
||||||
|
configuration.yaml
|
||||||
configuration_inspircd.json
|
configuration_inspircd.json
|
||||||
configuration_unreal6.json
|
configuration_unreal6.json
|
||||||
*.log
|
*.log
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
{
|
|
||||||
"SERVEUR_IP": "YOUR.SERVER.IP",
|
|
||||||
"SERVEUR_HOSTNAME": "YOUR.SERVER.HOST",
|
|
||||||
"SERVEUR_LINK": "LINK.DE.TON.SERVER",
|
|
||||||
"SERVEUR_PORT": 7002,
|
|
||||||
"SERVEUR_PASSWORD": "YOUR_LINK_PASSWORD",
|
|
||||||
"SERVEUR_ID": "006",
|
|
||||||
"SERVEUR_SSL": true,
|
|
||||||
|
|
||||||
"SERVICE_NAME": "defender",
|
|
||||||
"SERVICE_NICKNAME": "PyDefender",
|
|
||||||
"SERVICE_REALNAME": "Python Defender Security",
|
|
||||||
"SERVICE_USERNAME": "PyDefender",
|
|
||||||
"SERVICE_HOST": "HOST.DE.TON.DEFENDER",
|
|
||||||
"SERVICE_INFO": "Network IRC Service",
|
|
||||||
"SERVICE_CHANLOG": "#services",
|
|
||||||
"SERVICE_SMODES": "+ioqBS",
|
|
||||||
"SERVICE_CMODES": "ntsOP",
|
|
||||||
"SERVICE_UMODES": "o",
|
|
||||||
"SERVICE_PREFIX": "!",
|
|
||||||
|
|
||||||
"OWNER": "TON_NICK_NAME",
|
|
||||||
"PASSWORD": "TON_PASSWORD",
|
|
||||||
|
|
||||||
"JSONRPC_URL": "https://your.domaine.com:8600/api",
|
|
||||||
"JSONRPC_PATH_TO_SOCKET_FILE": "/PATH/TO/YOUR/IRCD/data/rpc.socket",
|
|
||||||
"JSONRPC_METHOD": "socket",
|
|
||||||
"JSONRPC_USER": "YOUR_RPC_USER",
|
|
||||||
"JSONRPC_PASSWORD": "YOUR_RPC_PASSWORD",
|
|
||||||
|
|
||||||
"SALON_JAIL": "#jail",
|
|
||||||
"SALON_JAIL_MODES": "sS",
|
|
||||||
"SALON_LIBERER": "#welcome",
|
|
||||||
|
|
||||||
"CLONE_CHANNEL": "#clones",
|
|
||||||
"CLONE_CMODES": "+nts",
|
|
||||||
"CLONE_LOG_HOST_EXEMPT": ["HOST.TO.SKIP"],
|
|
||||||
"CLONE_CHANNEL_PASSWORD": "YOUR_CHANNEL_PASSWORD",
|
|
||||||
|
|
||||||
"API_TIMEOUT": 2,
|
|
||||||
|
|
||||||
"PORTS_TO_SCAN": [3028, 8080, 1080, 1085, 4145, 9050],
|
|
||||||
"WHITELISTED_IP": ["127.0.0.1"],
|
|
||||||
"GLINE_DURATION": "30",
|
|
||||||
|
|
||||||
"DEBUG_LEVEL": 20,
|
|
||||||
"DEBUG_HARD": true
|
|
||||||
}
|
|
||||||
47
config/exemple_configuration.yaml
Normal file
47
config/exemple_configuration.yaml
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
configuration:
|
||||||
|
SERVEUR_IP: "YOUR.SERVER.IP"
|
||||||
|
SERVEUR_HOSTNAME: "YOUR.SERVER.HOST"
|
||||||
|
SERVEUR_LINK: "LINK.DE.TON.SERVER"
|
||||||
|
SERVEUR_PORT: 7002
|
||||||
|
SERVEUR_PASSWORD: "YOUR_LINK_PASSWORD"
|
||||||
|
SERVEUR_ID: "006"
|
||||||
|
SERVEUR_SSL: true
|
||||||
|
|
||||||
|
SERVICE_NAME: "defender"
|
||||||
|
SERVICE_NICKNAME: "PyDefender"
|
||||||
|
SERVICE_REALNAME: "Python Defender Security"
|
||||||
|
SERVICE_USERNAME: "PyDefender"
|
||||||
|
SERVICE_HOST: "HOST.DE.TON.DEFENDER"
|
||||||
|
SERVICE_INFO: "Network IRC Service"
|
||||||
|
SERVICE_CHANLOG: "#services"
|
||||||
|
SERVICE_SMODES: "+ioqBS"
|
||||||
|
SERVICE_CMODES: "ntsOP"
|
||||||
|
SERVICE_UMODES: "o"
|
||||||
|
SERVICE_PREFIX: "!"
|
||||||
|
|
||||||
|
OWNER: "TON_NICK_NAME"
|
||||||
|
PASSWORD: "TON_PASSWORD"
|
||||||
|
|
||||||
|
JSONRPC_URL: "https://your.domaine.com:8600/api"
|
||||||
|
JSONRPC_PATH_TO_SOCKET_FILE: "/PATH/TO/YOUR/IRCD/data/rpc.socket"
|
||||||
|
JSONRPC_METHOD: "socket"
|
||||||
|
JSONRPC_USER: "YOUR_RPC_USER"
|
||||||
|
JSONRPC_PASSWORD: "YOUR_RPC_PASSWORD"
|
||||||
|
|
||||||
|
SALON_JAIL: "#jail"
|
||||||
|
SALON_JAIL_MODES: "sS"
|
||||||
|
SALON_LIBERER: "#welcome"
|
||||||
|
|
||||||
|
CLONE_CHANNEL: "#clones"
|
||||||
|
CLONE_CMODES: "+nts"
|
||||||
|
CLONE_LOG_HOST_EXEMPT: ["HOST.TO.SKIP"]
|
||||||
|
CLONE_CHANNEL_PASSWORD: "YOUR_CHANNEL_PASSWORD"
|
||||||
|
|
||||||
|
API_TIMEOUT: 2
|
||||||
|
|
||||||
|
PORTS_TO_SCAN: [3028 8080 1080 1085 4145 9050]
|
||||||
|
WHITELISTED_IP: ["127.0.0.1"]
|
||||||
|
GLINE_DURATION: "30"
|
||||||
|
|
||||||
|
DEBUG_LEVEL: 20
|
||||||
|
DEBUG_HARD: true
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import sys
|
||||||
|
import yaml
|
||||||
from json import load
|
from json import load
|
||||||
from sys import exit
|
from sys import exit
|
||||||
from os import sep
|
from os import sep
|
||||||
@@ -13,49 +15,43 @@ class Configuration:
|
|||||||
|
|
||||||
self.Loader = loader
|
self.Loader = loader
|
||||||
self.Logs = loader.Logs
|
self.Logs = loader.Logs
|
||||||
self._config_model: MConfig = self.__load_service_configuration()
|
self.configuration_model = self.__load_service_configuration()
|
||||||
loader.ServiceLogging.set_file_handler_level(self._config_model.DEBUG_LEVEL)
|
loader.ServiceLogging.set_file_handler_level(self._config_model.DEBUG_LEVEL)
|
||||||
loader.ServiceLogging.set_stdout_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)
|
loader.ServiceLogging.update_handler_format(self._config_model.DEBUG_HARD)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_config_model(self) -> MConfig:
|
@property
|
||||||
|
def configuration_model(self) -> MConfig:
|
||||||
return self._config_model
|
return self._config_model
|
||||||
|
|
||||||
def __load_json_service_configuration(self) -> Optional[dict[str, Any]]:
|
@configuration_model.setter
|
||||||
|
def configuration_model(self, conf_model: MConfig):
|
||||||
|
self._config_model = conf_model
|
||||||
|
|
||||||
|
def __load_config_file(self) -> Optional[dict[str, Any]]:
|
||||||
try:
|
try:
|
||||||
conf_filename = f'config{sep}configuration.json'
|
conf_filename = f'config{sep}configuration.yaml'
|
||||||
with open(conf_filename, 'r') as configuration_data:
|
with open(conf_filename, 'r') as conf:
|
||||||
configuration: dict[str, Union[str, int, list, dict]] = load(configuration_data)
|
configuration: dict[str, dict[str, Any]] = yaml.safe_load(conf)
|
||||||
|
|
||||||
return configuration
|
|
||||||
|
|
||||||
|
return configuration.get('configuration', None)
|
||||||
except FileNotFoundError as fe:
|
except FileNotFoundError as fe:
|
||||||
self.Logs.error(f'FileNotFound: {fe}')
|
self.Logs.error(f'FileNotFound: {fe}')
|
||||||
self.Logs.error('Configuration file not found please create config/configuration.json')
|
self.Logs.error('Configuration file not found please create config/configuration.yaml')
|
||||||
exit(0)
|
exit("Configuration file not found please create config/configuration.yaml")
|
||||||
except KeyError as ke:
|
|
||||||
self.Logs.error(f'Key Error: {ke}')
|
|
||||||
self.Logs.error('The key must be defined in core/configuration.json')
|
|
||||||
|
|
||||||
def __load_service_configuration(self) -> MConfig:
|
def __load_service_configuration(self) -> MConfig:
|
||||||
try:
|
try:
|
||||||
import_config = self.__load_json_service_configuration()
|
import_config = self.__load_config_file()
|
||||||
|
if import_config is None:
|
||||||
|
self.Logs.error("Error While importing configuration file!", exc_info=True)
|
||||||
|
raise Exception("Error While importing yaml configuration")
|
||||||
|
|
||||||
model_keys = MConfig().to_dict()
|
list_key_to_remove: list[str] = [key_to_del for key_to_del in import_config if key_to_del not in MConfig().get_attributes()]
|
||||||
model_key_list: list = []
|
for key_to_remove in list_key_to_remove:
|
||||||
json_config_key_list: list = []
|
import_config.pop(key_to_remove, None)
|
||||||
|
self.Logs.warning(f"[!] The key {key_to_remove} is not expected, it has been removed from the system ! please remove it from configuration.json file [!]")
|
||||||
for key in model_keys:
|
|
||||||
model_key_list.append(key)
|
|
||||||
|
|
||||||
for key in import_config:
|
|
||||||
json_config_key_list.append(key)
|
|
||||||
|
|
||||||
for json_conf in json_config_key_list:
|
|
||||||
if not json_conf in model_key_list:
|
|
||||||
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 [!]")
|
|
||||||
|
|
||||||
self.Logs.debug(f"[LOADING CONFIGURATION]: Loading configuration with {len(import_config)} parameters!")
|
self.Logs.debug(f"[LOADING CONFIGURATION]: Loading configuration with {len(import_config)} parameters!")
|
||||||
return MConfig(**import_config)
|
return MConfig(**import_config)
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ def restart_service(uplink: 'Irc', reason: str = "Restarting with no reason!") -
|
|||||||
uplink.Logs.warning('-- Waiting for socket to close ...')
|
uplink.Logs.warning('-- Waiting for socket to close ...')
|
||||||
|
|
||||||
# Reload configuration
|
# Reload configuration
|
||||||
uplink.Loader.Config = uplink.Loader.ConfModule.Configuration(uplink.Loader).get_config_model()
|
uplink.Loader.Config = uplink.Loader.ConfModule.Configuration(uplink.Loader).configuration_model
|
||||||
uplink.Loader.Base = uplink.Loader.BaseModule.Base(uplink.Loader)
|
uplink.Loader.Base = uplink.Loader.BaseModule.Base(uplink.Loader)
|
||||||
|
|
||||||
for mod in REHASH_MODULES:
|
for mod in REHASH_MODULES:
|
||||||
@@ -77,7 +77,7 @@ def rehash_service(uplink: 'Irc', nickname: str) -> None:
|
|||||||
channel=uplink.Config.SERVICE_CHANLOG
|
channel=uplink.Config.SERVICE_CHANLOG
|
||||||
)
|
)
|
||||||
uplink.Utils = sys.modules['core.utils']
|
uplink.Utils = sys.modules['core.utils']
|
||||||
uplink.Config = uplink.Loader.ConfModule.Configuration(uplink.Loader).get_config_model()
|
uplink.Config = uplink.Loader.ConfModule.Configuration(uplink.Loader).configuration_model
|
||||||
uplink.Config.HSID = config_model_bakcup.HSID
|
uplink.Config.HSID = config_model_bakcup.HSID
|
||||||
uplink.Config.DEFENDER_INIT = config_model_bakcup.DEFENDER_INIT
|
uplink.Config.DEFENDER_INIT = config_model_bakcup.DEFENDER_INIT
|
||||||
uplink.Config.DEFENDER_RESTART = config_model_bakcup.DEFENDER_RESTART
|
uplink.Config.DEFENDER_RESTART = config_model_bakcup.DEFENDER_RESTART
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class Loader:
|
|||||||
|
|
||||||
self.Logs: Logger = self.ServiceLogging.get_logger()
|
self.Logs: Logger = self.ServiceLogging.get_logger()
|
||||||
|
|
||||||
self.Config: df.MConfig = self.ConfModule.Configuration(self).get_config_model()
|
self.Config: df.MConfig = self.ConfModule.Configuration(self).configuration_model
|
||||||
|
|
||||||
self.Settings.global_lang = self.Config.LANG if self.Config.LANG else "EN"
|
self.Settings.global_lang = self.Config.LANG if self.Config.LANG else "EN"
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,7 @@ from core import installation
|
|||||||
#############################################
|
#############################################
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
installation.Install()
|
installation.Install()
|
||||||
|
|
||||||
from core.loader import Loader
|
from core.loader import Loader
|
||||||
loader = Loader()
|
loader = Loader()
|
||||||
loader.Irc.init_irc()
|
loader.Irc.init_irc()
|
||||||
|
|||||||
Reference in New Issue
Block a user