mirror of
https://github.com/iio612/DEFENDER.git
synced 2026-02-13 19:24:23 +00:00
V4.1.0 change configuration systeme
This commit is contained in:
@@ -2,7 +2,7 @@ import time, threading, os, random, socket, hashlib, ipaddress, logging, request
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from sqlalchemy import create_engine, Engine, Connection, CursorResult
|
from sqlalchemy import create_engine, Engine, Connection, CursorResult
|
||||||
from sqlalchemy.sql import text
|
from sqlalchemy.sql import text
|
||||||
from core.configuration import Config
|
from core.loadConf import Config
|
||||||
|
|
||||||
class Base:
|
class Base:
|
||||||
|
|
||||||
|
|||||||
48
core/exemple_configuration.json
Normal file
48
core/exemple_configuration.json
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
{
|
||||||
|
"SERVEUR_IP": "0.0.0.0",
|
||||||
|
"SERVEUR_HOSTNAME": "your.host.name",
|
||||||
|
"SERVEUR_LINK": "your.link.to.server",
|
||||||
|
"SERVEUR_PORT": 7002,
|
||||||
|
"SERVEUR_PASSWORD": "link_password",
|
||||||
|
"SERVEUR_ID": "006",
|
||||||
|
"SERVEUR_SSL": true,
|
||||||
|
|
||||||
|
"SERVICE_NAME": "defender",
|
||||||
|
"SERVICE_NICKNAME": "BotNickname",
|
||||||
|
"SERVICE_REALNAME": "BotRealname",
|
||||||
|
"SERVICE_USERNAME": "BotUsername",
|
||||||
|
"SERVICE_HOST": "your.service.hostname",
|
||||||
|
"SERVICE_INFO": "Network IRC Service",
|
||||||
|
"SERVICE_CHANLOG": "#services",
|
||||||
|
"SERVICE_SMODES": "+ioqBS",
|
||||||
|
"SERVICE_CMODES": "ntsO",
|
||||||
|
"SERVICE_UMODES": "o",
|
||||||
|
"SERVICE_PREFIX": "!",
|
||||||
|
|
||||||
|
"OWNER": "admin",
|
||||||
|
"PASSWORD": "password",
|
||||||
|
|
||||||
|
"SALON_JAIL": "#jail",
|
||||||
|
"SALON_JAIL_MODES": "sS",
|
||||||
|
"SALON_LIBERER": "#welcome",
|
||||||
|
|
||||||
|
"API_TIMEOUT": 2,
|
||||||
|
|
||||||
|
"PORTS_TO_SCAN": [3028, 8080, 1080, 1085, 4145, 9050],
|
||||||
|
"WHITELISTED_IP": ["127.0.0.1"],
|
||||||
|
"GLINE_DURATION": "30",
|
||||||
|
|
||||||
|
"DEBUG_LEVEL": 20,
|
||||||
|
|
||||||
|
"CONFIG_COLOR": {
|
||||||
|
"blanche": "\\u0003\\u0030",
|
||||||
|
"noire": "\\u0003\\u0031",
|
||||||
|
"bleue": "\\u0003\\u0020",
|
||||||
|
"verte": "\\u0003\\u0033",
|
||||||
|
"rouge": "\\u0003\\u0034",
|
||||||
|
"jaune": "\\u0003\\u0036",
|
||||||
|
"gras": "\\u0002",
|
||||||
|
"nogc": "\\u0002\\u0003"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
##########################################
|
|
||||||
# CONFIGURATION FILE : #
|
|
||||||
# Rename file to : configuration.py #
|
|
||||||
##########################################
|
|
||||||
|
|
||||||
class Config:
|
|
||||||
|
|
||||||
SERVEUR_IP = '0.0.0.0' # IP ou host du serveur à rejoindre
|
|
||||||
SERVEUR_HOSTNAME = 'your hostname' # Le hostname du serveur IRC
|
|
||||||
SERVEUR_LINK = 'your link' # Host attendu par votre IRCd (ex. dans votre link block pour Unrealircd)
|
|
||||||
SERVEUR_PORT = 6666 # Port du link
|
|
||||||
SERVEUR_PASSWORD = 'your link password' # Mot de passe du link (Privilégiez argon2 sur Unrealircd)
|
|
||||||
SERVEUR_ID = '002' # SID (identification) du bot en tant que Services
|
|
||||||
SERVEUR_SSL = True # Activer / Desactiver la connexion SSL
|
|
||||||
|
|
||||||
SERVICE_NAME = 'defender' # Le nom du service
|
|
||||||
SERVICE_NICKNAME = 'BotName' # Nick du bot sur IRC
|
|
||||||
SERVICE_REALNAME = 'BotRealname' # Realname du bot
|
|
||||||
SERVICE_USERNAME = 'BotIdent' # Ident du bot
|
|
||||||
SERVICE_HOST = 'your service host' # Host du bot
|
|
||||||
SERVICE_INFO = 'Network IRC Service' # swhois du bot
|
|
||||||
SERVICE_CHANLOG = '#services' # Salon des logs et autres messages issus du bot
|
|
||||||
SERVICE_SMODES = '+ioqBS' # Mode du service
|
|
||||||
SERVICE_CMODES = 'ntsO' # Mode du salon (#ChanLog) que le bot appliquera à son entrée
|
|
||||||
SERVICE_UMODES = 'o' # Mode que le bot pourra se donner à sa connexion au salon chanlog
|
|
||||||
SERVICE_PREFIX = '.' # Prefix pour envoyer les commandes au bot
|
|
||||||
SERVICE_ID = SERVEUR_ID + 'AAAAAB' # L'identifiant du service
|
|
||||||
|
|
||||||
OWNER = 'admin' # Identifiant du compte admin
|
|
||||||
PASSWORD = 'password' # Mot de passe du compte admin
|
|
||||||
|
|
||||||
SALON_JAIL = '#JAIL' # Salon pot de miel
|
|
||||||
SALON_JAIL_MODES = 'sS' # Mode du salon pot de miel
|
|
||||||
SALON_LIBERER = '#welcome' # Le salon ou sera envoyé l'utilisateur clean
|
|
||||||
|
|
||||||
API_TIMEOUT = 2 # Timeout des api's
|
|
||||||
|
|
||||||
PORTS_TO_SCAN = [3028, 8080, 1080, 1085, 4145, 9050] # Liste des ports a scanné pour une detection de proxy
|
|
||||||
WHITELISTED_IP = ['127.0.0.1'] # IP a ne pas scanner
|
|
||||||
GLINE_DURATION = '1d' # La durée du gline
|
|
||||||
|
|
||||||
DEBUG_LEVEL = 10 # Le niveau des logs DEBUG 10 | INFO 20 | WARNING 30 | ERROR 40 | CRITICAL 50
|
|
||||||
|
|
||||||
CONFIG_COLOR = {
|
|
||||||
'blanche': '\x0300', # Couleur blanche
|
|
||||||
'noire': '\x0301', # Couleur noire
|
|
||||||
'bleue': '\x0302', # Couleur Bleue
|
|
||||||
'verte': '\x0303', # Couleur Verte
|
|
||||||
'rouge': '\x0304', # Couleur rouge
|
|
||||||
'jaune': '\x0306', # Couleur jaune
|
|
||||||
'gras': '\x02', # Gras
|
|
||||||
'nogc': '\x02\x03' # Retirer gras et couleur
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,7 @@ import ssl, re, importlib, sys, time, threading, socket
|
|||||||
from ssl import SSLSocket
|
from ssl import SSLSocket
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from typing import Union
|
from typing import Union
|
||||||
from core.configuration import Config
|
from core.loadConf import Config
|
||||||
from core.base import Base
|
from core.base import Base
|
||||||
|
|
||||||
class Irc:
|
class Irc:
|
||||||
@@ -24,7 +24,7 @@ class Irc:
|
|||||||
self.CHARSET = ['utf-8', 'iso-8859-1'] # Charset utiliser pour décoder/encoder les messages
|
self.CHARSET = ['utf-8', 'iso-8859-1'] # Charset utiliser pour décoder/encoder les messages
|
||||||
self.SSL_VERSION = None # Version SSL
|
self.SSL_VERSION = None # Version SSL
|
||||||
|
|
||||||
self.Config = Config()
|
self.Config = Config().ConfigModel
|
||||||
|
|
||||||
# Liste des commandes internes du bot
|
# Liste des commandes internes du bot
|
||||||
self.commands_level = {
|
self.commands_level = {
|
||||||
@@ -111,6 +111,11 @@ class Irc:
|
|||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
self.Base.logs.warning('--> Waiting for socket to close ...')
|
self.Base.logs.warning('--> Waiting for socket to close ...')
|
||||||
|
|
||||||
|
# Reload configuration
|
||||||
|
self.Base.logs.debug('Reloading configuration')
|
||||||
|
self.Config = Config().ConfigModel
|
||||||
|
self.Base = Base(self.Config)
|
||||||
|
|
||||||
self.__create_socket()
|
self.__create_socket()
|
||||||
self.__link(self.IrcSocket)
|
self.__link(self.IrcSocket)
|
||||||
self.load_existing_modules()
|
self.load_existing_modules()
|
||||||
|
|||||||
105
core/loadConf.py
Normal file
105
core/loadConf.py
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
import json, os
|
||||||
|
from typing import Union
|
||||||
|
from dataclasses import dataclass, field
|
||||||
|
|
||||||
|
##########################################
|
||||||
|
# CONFIGURATION FILE #
|
||||||
|
##########################################
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class ConfigDataModel:
|
||||||
|
|
||||||
|
SERVEUR_IP: str
|
||||||
|
SERVEUR_HOSTNAME: str # Le hostname du serveur IRC
|
||||||
|
SERVEUR_LINK: str # Host attendu par votre IRCd (ex. dans votre link block pour Unrealircd)
|
||||||
|
SERVEUR_PORT: int # Port du link
|
||||||
|
SERVEUR_PASSWORD: str # Mot de passe du link (Privilégiez argon2 sur Unrealircd)
|
||||||
|
SERVEUR_ID: str # SID (identification) du bot en tant que Services
|
||||||
|
SERVEUR_SSL: bool # Activer la connexion SSL
|
||||||
|
|
||||||
|
SERVICE_NAME: str # Le nom du service
|
||||||
|
SERVICE_NICKNAME: str # Nick du bot sur IRC
|
||||||
|
SERVICE_REALNAME: str # Realname du bot
|
||||||
|
SERVICE_USERNAME: str # Ident du bot
|
||||||
|
SERVICE_HOST: str # Host du bot
|
||||||
|
SERVICE_INFO: str # swhois du bot
|
||||||
|
SERVICE_CHANLOG: str # Salon des logs et autres messages issus du bot
|
||||||
|
SERVICE_SMODES: str # Mode du service
|
||||||
|
SERVICE_CMODES: str # Mode du salon (#ChanLog) que le bot appliquera à son entrée
|
||||||
|
SERVICE_UMODES: str # Mode que le bot pourra se donner à sa connexion au salon chanlog
|
||||||
|
SERVICE_PREFIX: str # Prefix pour envoyer les commandes au bot
|
||||||
|
SERVICE_ID: str = field(init=False) # L'identifiant du service
|
||||||
|
|
||||||
|
OWNER: str # Identifiant du compte admin
|
||||||
|
PASSWORD: str # Mot de passe du compte admin
|
||||||
|
|
||||||
|
SALON_JAIL: str # Salon pot de miel
|
||||||
|
SALON_JAIL_MODES: str # Mode du salon pot de miel
|
||||||
|
SALON_LIBERER: str # Le salon ou sera envoyé l'utilisateur clean
|
||||||
|
|
||||||
|
API_TIMEOUT: int # Timeout des api's
|
||||||
|
|
||||||
|
PORTS_TO_SCAN: list # Liste des ports a scanné pour une detection de proxy
|
||||||
|
WHITELISTED_IP: list # IP a ne pas scanner
|
||||||
|
GLINE_DURATION: str # La durée du gline
|
||||||
|
|
||||||
|
DEBUG_LEVEL: int # Le niveau des logs DEBUG 10 | INFO 20 | WARNING 30 | ERROR 40 | CRITICAL 50
|
||||||
|
|
||||||
|
CONFIG_COLOR: dict
|
||||||
|
|
||||||
|
def __post_init__(self):
|
||||||
|
# Initialiser SERVICE_ID après la création de l'objet
|
||||||
|
self.SERVICE_ID:str = f"{self.SERVEUR_ID}AAAAAB"
|
||||||
|
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
|
||||||
|
import_config = self.__load_json_configuration()
|
||||||
|
|
||||||
|
ConfigModel = ConfigDataModel(
|
||||||
|
SERVEUR_IP=import_config["SERVEUR_IP"],
|
||||||
|
SERVEUR_HOSTNAME=import_config["SERVEUR_HOSTNAME"],
|
||||||
|
SERVEUR_LINK=import_config["SERVEUR_LINK"],
|
||||||
|
SERVEUR_PORT=import_config["SERVEUR_PORT"],
|
||||||
|
SERVEUR_PASSWORD=import_config["SERVEUR_PASSWORD"],
|
||||||
|
SERVEUR_ID=import_config["SERVEUR_ID"],
|
||||||
|
SERVEUR_SSL=import_config["SERVEUR_SSL"],
|
||||||
|
SERVICE_NAME=import_config["SERVICE_NAME"],
|
||||||
|
SERVICE_NICKNAME=import_config["SERVICE_NICKNAME"],
|
||||||
|
SERVICE_REALNAME=import_config["SERVICE_REALNAME"],
|
||||||
|
SERVICE_USERNAME=import_config["SERVICE_USERNAME"],
|
||||||
|
SERVICE_HOST=import_config["SERVICE_HOST"],
|
||||||
|
SERVICE_INFO=import_config["SERVICE_INFO"],
|
||||||
|
SERVICE_CHANLOG=import_config["SERVICE_CHANLOG"],
|
||||||
|
SERVICE_SMODES=import_config["SERVICE_SMODES"],
|
||||||
|
SERVICE_CMODES=import_config["SERVICE_CMODES"],
|
||||||
|
SERVICE_UMODES=import_config["SERVICE_UMODES"],
|
||||||
|
SERVICE_PREFIX=import_config["SERVICE_PREFIX"],
|
||||||
|
OWNER=import_config["OWNER"],
|
||||||
|
PASSWORD=import_config["PASSWORD"],
|
||||||
|
SALON_JAIL=import_config["SALON_JAIL"],
|
||||||
|
SALON_JAIL_MODES=import_config["SALON_JAIL_MODES"],
|
||||||
|
SALON_LIBERER=import_config["SALON_LIBERER"],
|
||||||
|
API_TIMEOUT=import_config["API_TIMEOUT"],
|
||||||
|
PORTS_TO_SCAN=import_config["PORTS_TO_SCAN"],
|
||||||
|
WHITELISTED_IP=import_config["WHITELISTED_IP"],
|
||||||
|
GLINE_DURATION=import_config["GLINE_DURATION"],
|
||||||
|
DEBUG_LEVEL=import_config["DEBUG_LEVEL"],
|
||||||
|
CONFIG_COLOR=import_config["CONFIG_COLOR"]
|
||||||
|
)
|
||||||
|
|
||||||
|
self.ConfigModel = ConfigModel
|
||||||
|
return None
|
||||||
|
|
||||||
|
def __load_json_configuration(self):
|
||||||
|
|
||||||
|
conf_filename = f'core{os.sep}configuration.json'
|
||||||
|
with open(conf_filename, 'r') as configuration_data:
|
||||||
|
configuration:dict[str, Union[str, int, list, dict]] = json.load(configuration_data)
|
||||||
|
|
||||||
|
for key, value in configuration['CONFIG_COLOR'].items():
|
||||||
|
configuration['CONFIG_COLOR'][key] = value.encode('utf-8').decode('unicode_escape')
|
||||||
|
|
||||||
|
return configuration
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
"version": "4.0.4"
|
"version": "4.1.0"
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user