10 Commits

Author SHA1 Message Date
adator
22cec8a0ef Merge pull request #13 from adator85/dev
patch V4.0.4
2024-08-03 21:14:53 +02:00
adator
1837edf1c2 patch V4.0.4 2024-08-03 21:14:28 +02:00
adator
62b10313a4 Merge pull request #12 from adator85/dev
Patch V4.0.3
2024-08-03 21:05:56 +02:00
adator
c369d86a22 Patch V4.0.3 2024-08-03 21:04:38 +02:00
adator
61813e38ae Merge pull request #11 from adator85/dev
convert version string to int
2024-08-03 20:25:37 +02:00
adator
743069f8e0 convert version string to int 2024-08-03 20:24:58 +02:00
adator
de69a1af63 Merge pull request #10 from adator85/dev
Move checkversion command to admin commands
2024-08-03 20:13:03 +02:00
adator
c8c5f782d7 Move checkversion command to admin commands 2024-08-03 20:12:19 +02:00
adator
a639964701 Merge pull request #9 from adator85/dev
Dev
2024-08-03 19:22:30 +02:00
adator
ff0f880fcd V4.0.0 2024-08-03 19:21:30 +02:00
4 changed files with 93 additions and 50 deletions

View File

@@ -3,7 +3,6 @@ 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.configuration 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
} }
if token == '':
response = requests.get(json_url) 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)

View File

@@ -3,7 +3,6 @@ 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.configuration import Config
from core.sys_configuration import SysConfig
from core.base import Base from core.base import Base
class Irc: class Irc:
@@ -26,12 +25,11 @@ class Irc:
self.SSL_VERSION = None # Version SSL self.SSL_VERSION = None # Version SSL
self.Config = Config() self.Config = Config()
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']
} }
@@ -183,7 +181,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,11 +629,12 @@ 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 +730,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 +745,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,9 +756,12 @@ 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
# self.send2socket(f':{self.Config.SERVICE_ID} PING :{hsid}') # self.send2socket(f':{self.Config.SERVICE_ID} PING :{hsid}')
@@ -842,7 +849,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 +869,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 +1248,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 +1266,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

View File

@@ -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

View File

@@ -1,3 +1,3 @@
{ {
"version": "4.0.0" "version": "4.0.4"
} }