mirror of
https://github.com/iio612/DEFENDER.git
synced 2026-02-14 19:54:21 +00:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b0325d4db5 | ||
|
|
b9e4878764 | ||
|
|
22cec8a0ef | ||
|
|
1837edf1c2 | ||
|
|
62b10313a4 | ||
|
|
c369d86a22 | ||
|
|
61813e38ae | ||
|
|
743069f8e0 | ||
|
|
de69a1af63 | ||
|
|
c8c5f782d7 | ||
|
|
a639964701 | ||
|
|
ff0f880fcd |
75
core/base.py
75
core/base.py
@@ -2,8 +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
|
||||||
from core.sys_configuration import SysConfig
|
|
||||||
|
|
||||||
class Base:
|
class Base:
|
||||||
|
|
||||||
@@ -17,13 +16,16 @@ class Base:
|
|||||||
'modules': 'sys_modules'
|
'modules': 'sys_modules'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEFENDER_VERSION = '' # MAJOR.MINOR.BATCH
|
||||||
|
LATEST_DEFENDER_VERSION = '' # Latest Version of Defender in git
|
||||||
|
DEFENDER_DB_PATH = 'db' + os.sep # Séparateur en fonction de l'OS
|
||||||
|
DEFENDER_DB_NAME = 'defender' # Le nom de la base de données principale
|
||||||
|
|
||||||
def __init__(self, Config: Config) -> None:
|
def __init__(self, Config: Config) -> None:
|
||||||
|
|
||||||
self.Config = Config # Assigner l'objet de configuration
|
self.Config = Config # Assigner l'objet de configuration
|
||||||
self.SysConfig = SysConfig() # Importer les information pour le systeme
|
|
||||||
self.init_log_system() # Demarrer le systeme de log
|
self.init_log_system() # Demarrer le systeme de log
|
||||||
|
self.check_for_new_version() # Verifier si une nouvelle version est disponible
|
||||||
self.get_latest_defender_version()
|
|
||||||
|
|
||||||
self.running_timers:list[threading.Timer] = [] # Liste des timers en cours
|
self.running_timers:list[threading.Timer] = [] # Liste des timers en cours
|
||||||
self.running_threads:list[threading.Thread] = [] # Liste des threads en cours
|
self.running_threads:list[threading.Thread] = [] # Liste des threads en cours
|
||||||
@@ -37,19 +39,36 @@ class Base:
|
|||||||
|
|
||||||
self.db_create_first_admin() # Créer un nouvel admin si la base de données est vide
|
self.db_create_first_admin() # Créer un nouvel admin si la base de données est vide
|
||||||
|
|
||||||
def get_latest_defender_version(self) -> None:
|
def __set_current_defender_version(self) -> None:
|
||||||
|
"""This will put the current version of Defender
|
||||||
|
located in version.json
|
||||||
|
"""
|
||||||
|
|
||||||
|
version_filename = f'.{os.sep}version.json'
|
||||||
|
with open(version_filename, 'r') as version_data:
|
||||||
|
current_version:dict[str, str] = json.load(version_data)
|
||||||
|
|
||||||
|
self.DEFENDER_VERSION = current_version["version"]
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
def __get_latest_defender_version(self) -> None:
|
||||||
try:
|
try:
|
||||||
#token = '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'
|
token = ''
|
||||||
token = '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'
|
json_url = f'https://raw.githubusercontent.com/adator85/IRC_DEFENDER_MODULES/main/version.json'
|
||||||
json_url = f'https://github.com/adator85/IRC_DEFENDER_MODULES/blob/e27a027ae99a6c11171635b2a120803e8682aac6/version.json'
|
|
||||||
headers = {
|
headers = {
|
||||||
'Authorization': f'token {token}',
|
'Authorization': f'token {token}',
|
||||||
'Accept': 'application/vnd.github.v3.raw' # Indique à GitHub que nous voulons le contenu brut du fichier
|
'Accept': 'application/vnd.github.v3.raw' # Indique à GitHub que nous voulons le contenu brut du fichier
|
||||||
}
|
}
|
||||||
response = requests.get(json_url)
|
|
||||||
|
if token == '':
|
||||||
|
response = requests.get(json_url)
|
||||||
|
else:
|
||||||
|
response = requests.get(json_url, headers=headers)
|
||||||
|
|
||||||
response.raise_for_status() # Vérifie si la requête a réussi
|
response.raise_for_status() # Vérifie si la requête a réussi
|
||||||
json_response:dict = response.json()
|
json_response:dict = response.json()
|
||||||
self.SysConfig.LATEST_DEFENDER_VERSION = json_response["version"]
|
self.LATEST_DEFENDER_VERSION = json_response["version"]
|
||||||
|
|
||||||
return None
|
return None
|
||||||
except requests.HTTPError as err:
|
except requests.HTTPError as err:
|
||||||
@@ -57,6 +76,36 @@ class Base:
|
|||||||
except:
|
except:
|
||||||
self.logs.warning(f'Github not available to fetch latest version')
|
self.logs.warning(f'Github not available to fetch latest version')
|
||||||
|
|
||||||
|
def check_for_new_version(self) -> bool:
|
||||||
|
try:
|
||||||
|
# Assigner la version actuelle de Defender
|
||||||
|
self.__set_current_defender_version()
|
||||||
|
# Récuperer la dernier version disponible dans github
|
||||||
|
self.__get_latest_defender_version()
|
||||||
|
|
||||||
|
isNewVersion = False
|
||||||
|
latest_version = self.LATEST_DEFENDER_VERSION
|
||||||
|
current_version = self.DEFENDER_VERSION
|
||||||
|
|
||||||
|
curr_major , curr_minor, curr_patch = current_version.split('.')
|
||||||
|
last_major, last_minor, last_patch = latest_version.split('.')
|
||||||
|
|
||||||
|
if int(last_major) > int(curr_major):
|
||||||
|
self.logs.info(f'New version available: {current_version} >>> {latest_version}')
|
||||||
|
isNewVersion = True
|
||||||
|
elif int(last_major) == int(curr_major) and int(last_minor) > int(curr_minor):
|
||||||
|
self.logs.info(f'New version available: {current_version} >>> {latest_version}')
|
||||||
|
isNewVersion = True
|
||||||
|
elif int(last_major) == int(curr_major) and int(last_minor) == int(curr_minor) and int(last_patch) > int(curr_patch):
|
||||||
|
self.logs.info(f'New version available: {current_version} >>> {latest_version}')
|
||||||
|
isNewVersion = True
|
||||||
|
else:
|
||||||
|
isNewVersion = False
|
||||||
|
|
||||||
|
return isNewVersion
|
||||||
|
except ValueError as ve:
|
||||||
|
self.logs.error(f'Impossible to convert in version number : {ve}')
|
||||||
|
|
||||||
def get_unixtime(self) -> int:
|
def get_unixtime(self) -> int:
|
||||||
"""
|
"""
|
||||||
Cette fonction retourne un UNIXTIME de type 12365456
|
Cette fonction retourne un UNIXTIME de type 12365456
|
||||||
@@ -299,8 +348,8 @@ class Base:
|
|||||||
|
|
||||||
def db_init(self) -> tuple[Engine, Connection]:
|
def db_init(self) -> tuple[Engine, Connection]:
|
||||||
|
|
||||||
db_directory = self.SysConfig.DEFENDER_DB_PATH
|
db_directory = self.DEFENDER_DB_PATH
|
||||||
full_path_db = self.SysConfig.DEFENDER_DB_PATH + self.SysConfig.DEFENDER_DB_NAME
|
full_path_db = self.DEFENDER_DB_PATH + self.DEFENDER_DB_NAME
|
||||||
|
|
||||||
if not os.path.exists(db_directory):
|
if not os.path.exists(db_directory):
|
||||||
os.makedirs(db_directory)
|
os.makedirs(db_directory)
|
||||||
|
|||||||
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
|
|
||||||
}
|
|
||||||
55
core/irc.py
55
core/irc.py
@@ -2,8 +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.sys_configuration import SysConfig
|
|
||||||
from core.base import Base
|
from core.base import Base
|
||||||
|
|
||||||
class Irc:
|
class Irc:
|
||||||
@@ -25,13 +24,12 @@ 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
|
||||||
self.SysConfig = SysConfig()
|
|
||||||
|
|
||||||
# Liste des commandes internes du bot
|
# Liste des commandes internes du bot
|
||||||
self.commands_level = {
|
self.commands_level = {
|
||||||
0: ['help', 'auth', 'copyright'],
|
0: ['help', 'auth', 'copyright'],
|
||||||
1: ['load','reload','unload', 'deauth', 'uptime'],
|
1: ['load','reload','unload', 'deauth', 'uptime', 'checkversion'],
|
||||||
2: ['show_modules', 'show_timers', 'show_threads', 'sentinel'],
|
2: ['show_modules', 'show_timers', 'show_threads', 'sentinel'],
|
||||||
3: ['quit', 'restart','addaccess','editaccess', 'delaccess']
|
3: ['quit', 'restart','addaccess','editaccess', 'delaccess']
|
||||||
}
|
}
|
||||||
@@ -113,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()
|
||||||
@@ -183,7 +186,7 @@ class Irc:
|
|||||||
sid = self.Config.SERVEUR_ID
|
sid = self.Config.SERVEUR_ID
|
||||||
service_id = self.Config.SERVICE_ID
|
service_id = self.Config.SERVICE_ID
|
||||||
|
|
||||||
version = self.SysConfig.DEFENDER_VERSION
|
version = self.Base.DEFENDER_VERSION
|
||||||
unixtime = self.Base.get_unixtime()
|
unixtime = self.Base.get_unixtime()
|
||||||
|
|
||||||
# Envoyer un message d'identification
|
# Envoyer un message d'identification
|
||||||
@@ -631,12 +634,13 @@ class Irc:
|
|||||||
|
|
||||||
def debug(self, debug_msg:str) -> None:
|
def debug(self, debug_msg:str) -> None:
|
||||||
|
|
||||||
if self.Config.DEBUG == 1:
|
# if self.Config.DEBUG == 1:
|
||||||
if type(debug_msg) == list:
|
# if type(debug_msg) == list:
|
||||||
if debug_msg[0] != 'PING':
|
# if debug_msg[0] != 'PING':
|
||||||
print(f"[{self.Base.get_datetime()}] - {debug_msg}")
|
# print(f"[{self.Base.get_datetime()}] - {debug_msg}")
|
||||||
else:
|
# else:
|
||||||
print(f"[{self.Base.get_datetime()}] - {debug_msg}")
|
#
|
||||||
|
print(f"[{self.Base.get_datetime()}] - {debug_msg}")
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -731,6 +735,11 @@ class Irc:
|
|||||||
hsid = str(cmd[0]).replace(':','')
|
hsid = str(cmd[0]).replace(':','')
|
||||||
if hsid == self.HSID:
|
if hsid == self.HSID:
|
||||||
if self.INIT == 1:
|
if self.INIT == 1:
|
||||||
|
if self.Base.check_for_new_version():
|
||||||
|
version = f'{self.Base.DEFENDER_VERSION} >>> {self.Base.LATEST_DEFENDER_VERSION}'
|
||||||
|
else:
|
||||||
|
version = f'{self.Base.DEFENDER_VERSION}'
|
||||||
|
|
||||||
self.send2socket(f"MODE {self.Config.SERVICE_NICKNAME} +B")
|
self.send2socket(f"MODE {self.Config.SERVICE_NICKNAME} +B")
|
||||||
self.send2socket(f"JOIN {self.Config.SERVICE_CHANLOG}")
|
self.send2socket(f"JOIN {self.Config.SERVICE_CHANLOG}")
|
||||||
print(f"################### DEFENDER ###################")
|
print(f"################### DEFENDER ###################")
|
||||||
@@ -741,7 +750,7 @@ class Irc:
|
|||||||
print(f"# SSL VER : {self.SSL_VERSION} ")
|
print(f"# SSL VER : {self.SSL_VERSION} ")
|
||||||
print(f"# NICKNAME : {self.Config.SERVICE_NICKNAME} ")
|
print(f"# NICKNAME : {self.Config.SERVICE_NICKNAME} ")
|
||||||
print(f"# CHANNEL : {self.Config.SERVICE_CHANLOG} ")
|
print(f"# CHANNEL : {self.Config.SERVICE_CHANLOG} ")
|
||||||
print(f"# VERSION : {self.SysConfig.DEFENDER_VERSION} ")
|
print(f"# VERSION : {version} ")
|
||||||
print(f"################################################")
|
print(f"################################################")
|
||||||
|
|
||||||
self.Base.logs.info(f"################### DEFENDER ###################")
|
self.Base.logs.info(f"################### DEFENDER ###################")
|
||||||
@@ -752,8 +761,11 @@ class Irc:
|
|||||||
self.Base.logs.info(f"# SSL VER : {self.SSL_VERSION} ")
|
self.Base.logs.info(f"# SSL VER : {self.SSL_VERSION} ")
|
||||||
self.Base.logs.info(f"# NICKNAME : {self.Config.SERVICE_NICKNAME} ")
|
self.Base.logs.info(f"# NICKNAME : {self.Config.SERVICE_NICKNAME} ")
|
||||||
self.Base.logs.info(f"# CHANNEL : {self.Config.SERVICE_CHANLOG} ")
|
self.Base.logs.info(f"# CHANNEL : {self.Config.SERVICE_CHANLOG} ")
|
||||||
self.Base.logs.info(f"# VERSION : {self.SysConfig.DEFENDER_VERSION} ")
|
self.Base.logs.info(f"# VERSION : {version} ")
|
||||||
self.Base.logs.info(f"################################################")
|
self.Base.logs.info(f"################################################")
|
||||||
|
|
||||||
|
if self.Base.check_for_new_version():
|
||||||
|
self.send2socket(f":{self.Config.SERVICE_NICKNAME} PRIVMSG {self.Config.SERVICE_CHANLOG} : New Version available {version}")
|
||||||
|
|
||||||
# Initialisation terminé aprés le premier PING
|
# Initialisation terminé aprés le premier PING
|
||||||
self.INIT = 0
|
self.INIT = 0
|
||||||
@@ -842,7 +854,7 @@ class Irc:
|
|||||||
arg = convert_to_string.split()
|
arg = convert_to_string.split()
|
||||||
arg.remove(f':{self.Config.SERVICE_PREFIX}')
|
arg.remove(f':{self.Config.SERVICE_PREFIX}')
|
||||||
if not arg[0].lower() in self.commands:
|
if not arg[0].lower() in self.commands:
|
||||||
self.debug(f"This command {arg[0]} is not available")
|
self.Base.logs.debug(f"This command {arg[0]} is not available")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
cmd_to_send = convert_to_string.replace(':','')
|
cmd_to_send = convert_to_string.replace(':','')
|
||||||
@@ -862,7 +874,7 @@ class Irc:
|
|||||||
|
|
||||||
# Réponse a un CTCP VERSION
|
# Réponse a un CTCP VERSION
|
||||||
if arg[0] == '\x01VERSION\x01':
|
if arg[0] == '\x01VERSION\x01':
|
||||||
self.send2socket(f':{dnickname} NOTICE {user_trigger} :\x01VERSION Service {self.Config.SERVICE_NICKNAME} V{self.SysConfig.DEFENDER_VERSION}\x01')
|
self.send2socket(f':{dnickname} NOTICE {user_trigger} :\x01VERSION Service {self.Config.SERVICE_NICKNAME} V{self.Base.DEFENDER_VERSION}\x01')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Réponse a un TIME
|
# Réponse a un TIME
|
||||||
@@ -1241,7 +1253,7 @@ class Irc:
|
|||||||
self.send2socket(f':{dnickname} NOTICE {fromuser} : {uptime}')
|
self.send2socket(f':{dnickname} NOTICE {fromuser} : {uptime}')
|
||||||
|
|
||||||
case 'copyright':
|
case 'copyright':
|
||||||
self.send2socket(f':{dnickname} NOTICE {fromuser} : # Defender V.{self.SysConfig.DEFENDER_VERSION} Developped by adator® and dktmb® #')
|
self.send2socket(f':{dnickname} NOTICE {fromuser} : # Defender V.{self.Base.DEFENDER_VERSION} Developped by adator® and dktmb® #')
|
||||||
|
|
||||||
case 'sentinel':
|
case 'sentinel':
|
||||||
# .sentinel on
|
# .sentinel on
|
||||||
@@ -1259,5 +1271,14 @@ class Irc:
|
|||||||
if not chan in channel_to_dont_quit:
|
if not chan in channel_to_dont_quit:
|
||||||
self.send2socket(f":{service_id} PART {chan}")
|
self.send2socket(f":{service_id} PART {chan}")
|
||||||
|
|
||||||
|
case 'checkversion':
|
||||||
|
|
||||||
|
if self.Base.check_for_new_version():
|
||||||
|
self.send2socket(f':{dnickname} NOTICE {fromuser} : New Version available : {self.Base.DEFENDER_VERSION} >>> {self.Base.LATEST_DEFENDER_VERSION}')
|
||||||
|
self.send2socket(f':{dnickname} NOTICE {fromuser} : Please run (git pull origin main) in the current folder')
|
||||||
|
else:
|
||||||
|
self.send2socket(f':{dnickname} NOTICE {fromuser} : You have the latest version of defender')
|
||||||
|
pass
|
||||||
|
|
||||||
case _:
|
case _:
|
||||||
pass
|
pass
|
||||||
|
|||||||
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,22 +0,0 @@
|
|||||||
import os, json
|
|
||||||
|
|
||||||
####################################################################################################
|
|
||||||
# DO NOT TOUCH THIS FILE #
|
|
||||||
####################################################################################################
|
|
||||||
|
|
||||||
class SysConfig:
|
|
||||||
|
|
||||||
DEFENDER_VERSION = '4.0.0' # MAJOR.MINOR.BATCH
|
|
||||||
LATEST_DEFENDER_VERSION = '0.0.0' # Latest Version of Defender in git
|
|
||||||
DEFENDER_DB_PATH = 'db' + os.sep # Séparateur en fonction de l'OS
|
|
||||||
DEFENDER_DB_NAME = 'defender' # Le nom de la base de données principale
|
|
||||||
|
|
||||||
def __init__(self) -> None:
|
|
||||||
|
|
||||||
version_filename = f'.{os.sep}version.json'
|
|
||||||
with open(version_filename, 'r') as version_data:
|
|
||||||
self.global_configuration:dict[str, str] = json.load(version_data)
|
|
||||||
|
|
||||||
self.DEFENDER_VERSION = self.global_configuration["version"]
|
|
||||||
|
|
||||||
return None
|
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
"version": "4.0.0"
|
"version": "4.1.0"
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user