install.py and installation.py:

Fix method to check python version
irc.py:
    Do not log a user with different nickname, even if the password is correct
This commit is contained in:
adator
2024-08-22 14:51:06 +02:00
parent 88b9b056ca
commit 290d7123fd
4 changed files with 55 additions and 33 deletions

View File

@@ -24,26 +24,26 @@ Il permet aux opérateurs de gérer efficacement un canal, tout en offrant aux u
# Installation automatique sur une machine Debian/Ubuntu # Installation automatique sur une machine Debian/Ubuntu
Prérequis: Prérequis:
- Système d'exploitation Linux (Windows non supporté) - Système d'exploitation Linux (Windows non supporté)
- Droits d'administrateur (root) pour l'exécution du script - Droits d'administrateur (root) pour l'exécution du script
- Python version 3.10 ou supérieure - Python version 3.10 ou supérieure
Bash Bash
$ git clone https://github.com/adator85/IRC_DEFENDER_MODULES.git $ git clone https://github.com/adator85/IRC_DEFENDER_MODULES.git
- Renommer le fichier exemple_configuration.json en configuration.json - Renommer le fichier exemple_configuration.json en configuration.json
- Configurer le fichier configuration.json - Configurer le fichier configuration.json
$ sudo python3 install.py $ sudo python3 install.py
Si votre configuration est bonne, votre service est censé etre connecté a votre réseau IRC Si votre configuration est bonne, votre service est censé etre connecté a votre réseau IRC
# Installation manuelle: # Installation manuelle:
Bash Bash
$ git clone https://github.com/adator85/IRC_DEFENDER_MODULES.git $ git clone https://github.com/adator85/IRC_DEFENDER_MODULES.git
$ cd IRC_DEFENDER_MODULES $ cd IRC_DEFENDER_MODULES
$ python3 -m venv .pyenv $ python3 -m venv .pyenv
$ source .pyenv/bin/activate $ source .pyenv/bin/activate
- Créer un service nommé "Defender.service" pour votre service et placer le dans "/etc/systemd/system/" - Créer un service nommé "Defender.service" pour votre service et placer le dans "/etc/systemd/system/"
$ sudo systemctl start Defender $ sudo systemctl start Defender
# Configuration # Configuration

View File

@@ -1,6 +1,6 @@
from importlib.util import find_spec from importlib.util import find_spec
from subprocess import check_call, run, CalledProcessError from subprocess import check_call, run, CalledProcessError
from platform import python_version from platform import python_version, python_version_tuple
from sys import exit from sys import exit
import os import os
@@ -28,14 +28,19 @@ class Install:
Returns: Returns:
bool: True si la version de python est autorisé sinon False bool: True si la version de python est autorisé sinon False
""" """
python_required_version = self.PYTHON_MIN_VERSION.split('.') # Current system version
python_current_version = python_version().split('.') sys_major, sys_minor, sys_patch = python_version_tuple()
if int(python_current_version[0]) < int(python_required_version[0]): # min python version required
python_required_version = self.PYTHON_MIN_VERSION.split('.')
min_major, min_minor = tuple((python_required_version[0], python_required_version[1]))
if int(sys_major) < int(min_major):
print(f"## Your python version must be greather than or equal to {self.PYTHON_MIN_VERSION} ##") print(f"## Your python version must be greather than or equal to {self.PYTHON_MIN_VERSION} ##")
return False return False
elif int(python_current_version[1]) < int(python_required_version[1]):
print(f"### Your python version must be greather than or equal to {self.PYTHON_MIN_VERSION} ###") elif (int(sys_major) <= int(min_major)) and (int(sys_minor) < int(min_minor)):
print(f"## Your python version must be greather than or equal to {self.PYTHON_MIN_VERSION} ##")
return False return False
print(f"===> Version of python : {python_version()} ==> OK") print(f"===> Version of python : {python_version()} ==> OK")

View File

@@ -28,8 +28,8 @@ class Irc:
# 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', 'uptime'],
1: ['load','reload','unload', 'deauth', 'uptime', 'checkversion'], 1: ['load','reload','unload', 'deauth', 'checkversion'],
2: ['show_modules', 'show_timers', 'show_threads', 'show_channels'], 2: ['show_modules', 'show_timers', 'show_threads', 'show_channels'],
3: ['quit', 'restart','addaccess','editaccess', 'delaccess'] 3: ['quit', 'restart','addaccess','editaccess', 'delaccess']
} }
@@ -887,8 +887,8 @@ class Irc:
def _hcmds(self, user: str, cmd:list, fullcmd: list = []) -> None: def _hcmds(self, user: str, cmd:list, fullcmd: list = []) -> None:
fromuser = self.User.get_nickname(user) # Nickname qui a lancé la commande fromuser = self.User.get_nickname(user) # Nickname qui a lancé la commande
uid = self.User.get_uid(fromuser) # Récuperer le uid de l'utilisateur uid = self.User.get_uid(fromuser) # Récuperer le uid de l'utilisateur
# Defender information # Defender information
dnickname = self.Config.SERVICE_NICKNAME # Defender nickname dnickname = self.Config.SERVICE_NICKNAME # Defender nickname
@@ -931,6 +931,11 @@ class Irc:
user_to_log = self.User.get_nickname(cmd[1]) user_to_log = self.User.get_nickname(cmd[1])
password = cmd[2] password = cmd[2]
if fromuser != user_to_log:
# If the current nickname is different from the nickname you want to log in with
self.send2socket(f":{self.Config.SERVICE_NICKNAME} NOTICE {fromuser} :Your current nickname is different from the nickname you want to log in with")
return False
if not user_to_log is None: if not user_to_log is None:
mes_donnees = {'user': user_to_log, 'password': self.Base.crypt_password(password)} mes_donnees = {'user': user_to_log, 'password': self.Base.crypt_password(password)}
query = f"SELECT id, level FROM {self.Config.table_admin} WHERE user = :user AND password = :password" query = f"SELECT id, level FROM {self.Config.table_admin} WHERE user = :user AND password = :password"

View File

@@ -1,8 +1,12 @@
from subprocess import check_call, run, CalledProcessError, PIPE from subprocess import check_call, run, CalledProcessError, PIPE
from platform import python_version from platform import python_version, python_version_tuple, system
from sys import exit from sys import exit
import os, logging, shutil, pwd import os, logging, shutil
try:
import pwd
except ModuleNotFoundError as err:
print(err)
class Install: class Install:
@@ -16,6 +20,7 @@ class Install:
self.venv_dependencies: list[str] = ['sqlalchemy','psutil','requests'] self.venv_dependencies: list[str] = ['sqlalchemy','psutil','requests']
self.install_folder = os.getcwd() self.install_folder = os.getcwd()
self.osname = os.name self.osname = os.name
self.system_name = system()
self.cmd_linux_requirements: list[str] = ['apt', 'install', '-y', 'python3', 'python3-pip', 'python3-venv'] self.cmd_linux_requirements: list[str] = ['apt', 'install', '-y', 'python3', 'python3-pip', 'python3-venv']
self.venv_pip_full_path = os.path.join(self.venv_name, f'bin{os.sep}pip') self.venv_pip_full_path = os.path.join(self.venv_name, f'bin{os.sep}pip')
self.venv_python_full_path = os.path.join(self.venv_name, f'bin{os.sep}python') self.venv_python_full_path = os.path.join(self.venv_name, f'bin{os.sep}python')
@@ -28,6 +33,7 @@ class Install:
if self.osname == 'nt': if self.osname == 'nt':
print('/!\\ Windows OS is not supported by this automatic installation /!\\') print('/!\\ Windows OS is not supported by this automatic installation /!\\')
self.Logs.critical('/!\\ Windows OS is not supported by this automatic install /!\\') self.Logs.critical('/!\\ Windows OS is not supported by this automatic install /!\\')
print(self.system_name)
exit(5) exit(5)
if not self.is_root(): if not self.is_root():
@@ -47,7 +53,7 @@ class Install:
self.install_linux_dependencies() self.install_linux_dependencies()
# Check python version # Check python version
self.checkPythonVersion() self.check_python_version()
# Create systemd service file # Create systemd service file
self.create_service_file() self.create_service_file()
@@ -142,23 +148,29 @@ class Install:
self.Logs.critical(f"Command failed :{e.returncode}") self.Logs.critical(f"Command failed :{e.returncode}")
exit(5) exit(5)
def checkPythonVersion(self) -> bool: def check_python_version(self) -> bool:
"""Test si la version de python est autorisée ou non """Test si la version de python est autorisée ou non
Returns: Returns:
bool: True si la version de python est autorisé sinon False bool: True si la version de python est autorisé sinon False
""" """
python_required_version = self.python_min_version.split('.')
python_current_version = python_version().split('.')
self.Logs.debug(f'The current python version is: {python_version()}') self.Logs.debug(f'The current python version is: {python_version()}')
if int(python_current_version[0]) < int(python_required_version[0]): # Current system version
print(f"## Your python version must be greather than or equal to {self.python_min_version} ##") sys_major, sys_minor, sys_patch = python_version_tuple()
# min python version required
python_required_version = self.PYTHON_MIN_VERSION.split('.')
min_major, min_minor = tuple((python_required_version[0], python_required_version[1]))
if int(sys_major) < int(min_major):
print(f"## Your python version must be greather than or equal to {self.PYTHON_MIN_VERSION} ##")
self.Logs.critical(f'Your python version must be greather than or equal to {self.python_min_version}') self.Logs.critical(f'Your python version must be greather than or equal to {self.python_min_version}')
return False return False
elif int(python_current_version[1]) < int(python_required_version[1]):
print(f"### Your python version must be greather than or equal to {self.python_min_version} ###") elif (int(sys_major) <= int(min_major)) and (int(sys_minor) < int(min_minor)):
print(f"## Your python version must be greather than or equal to {self.PYTHON_MIN_VERSION} ##")
self.Logs.critical(f'Your python version must be greather than or equal to {self.python_min_version}') self.Logs.critical(f'Your python version must be greather than or equal to {self.python_min_version}')
return False return False