diff --git a/gui.py b/gui_firewall.py similarity index 82% rename from gui.py rename to gui_firewall.py index 203d669..d8eb0e6 100644 --- a/gui.py +++ b/gui_firewall.py @@ -1,31 +1,10 @@ +import subprocess +import os +import sys import tkinter as tk from tkinter import ttk, filedialog, messagebox from datetime import datetime from threading import Thread -import subprocess -import os -import sys - -# Chemin -BASE_DIR = os.path.dirname(os.path.abspath(__file__)) - -FIREWALL_DIR = os.path.join( - BASE_DIR, - "Parseurs_config_Firewall" -) - -FIREWALL_MAIN = os.path.join( - FIREWALL_DIR, - "src", - "main.py" -) - -HELP_FILE_FW = os.path.join(BASE_DIR, "help_Firewall.md") - -OUTPUT_DIR = os.path.join(FIREWALL_DIR, "src", "output") -os.makedirs(OUTPUT_DIR, exist_ok=True) - -PYTHON_EXEC = sys.executable class ToolTip: def __init__(self, widget, text): @@ -65,21 +44,24 @@ class ToolTip: self.tipwindow.destroy() self.tipwindow = None -# Fenêtre principale -root = tk.Tk() -root.title("Analyse Réseau") -root.geometry("650x350") -root.resizable(False, False) - - -def open_switch_gui(): - messagebox.showinfo( - "Analyse log Switch", - "L'analyse log switch n'est pas encore disponible." +# Contenu fenêtre Analyse Firewall +def open_firewall_gui(root, BASE_DIR): + FIREWALL_DIR = os.path.join( + BASE_DIR, + "Parseurs_config_Firewall" ) -# Fenêtre Firewall -def open_firewall_gui(): + FIREWALL_MAIN = os.path.join( + FIREWALL_DIR, + "src", + "main.py" + ) + + HELP_FILE_FW = os.path.join(BASE_DIR, "help_Firewall.md") + + OUTPUT_DIR = os.path.join(FIREWALL_DIR, "src", "output") + os.makedirs(OUTPUT_DIR, exist_ok=True) + app = tk.Toplevel(root) app.title("Analyse Configuration Firewall") app.geometry("800x400") @@ -171,7 +153,7 @@ def open_firewall_gui(): app.update_idletasks() def process(): cmd = [ - PYTHON_EXEC, + sys.executable, FIREWALL_MAIN, firewall_var.get(), input_var.get() @@ -316,54 +298,4 @@ def open_firewall_gui(): command=run_parser ).pack(pady=15) - app.mainloop() - -# Contenu fenêtre principale -ttk.Label( - root, - text="Analyse Réseau", - font=("Arial", 16, "bold") -).pack(pady=20) - -ttk.Label( - root, - text="Sélectionnez le type d'analyse à effectuer :", - font=("Arial", 11) -).pack(pady=10) - -ttk.Button( - root, - text="Analyse configuration Firewall", - width=30, - command=open_firewall_gui -).pack(pady=5) - -ttk.Label( - root, - text="(Convertir les données au format normalisé Yang dans un fichier JSON)" \ - "\n + possibilité de générer une matrice de flux en Excel" \ - "\n + possibilité de générer une matrice de routage en Excel (route statique uniquement)", - font=("Arial", 9, "italic"), - anchor="center", - justify="center" -).pack(pady=5) - -ttk.Separator(root, orient="horizontal").pack(fill="x", pady=10) - -ttk.Button( - root, - text="Analyse log Switch", - width=30, - command=open_switch_gui -).pack(pady=5) - -ttk.Label( - root, - text="(Convertir les données au format normalisé Yang dans un fichier JSON)" \ - "\n + possibilité de générer un schéma réseau", - font=("Arial", 9, "italic"), - anchor="center", - justify="center" -).pack(pady=5) - -root.mainloop() + app.mainloop() \ No newline at end of file diff --git a/gui_switch.py b/gui_switch.py new file mode 100644 index 0000000..6604d13 --- /dev/null +++ b/gui_switch.py @@ -0,0 +1,9 @@ +import tkinter as tk +from tkinter import ttk, filedialog, messagebox + +# Contenu fenêtre Analyse Switch +def open_switch_gui(root, BASE_DIR): + messagebox.showinfo( + "Analyse log Switch", + "L'analyse log switch n'est pas encore disponible." + ) \ No newline at end of file diff --git a/help_Firewall.md b/help_Firewall.md index 371d8b7..eb044af 100644 --- a/help_Firewall.md +++ b/help_Firewall.md @@ -10,12 +10,10 @@ Il founit également la possibilité de générer une **matrice de routage au fo ## Utilisation ### Pré-requis -```bash -cd .\Parseurs_config_Firewall\ -python -m venv .venv -.\.venv\Scripts\activate -pip install -r .\Parseurs_config_Firewall\src\requirements.txt -``` - Mettre le/les fichier(s) et/ou dossier(s) de configurations dans le dossier `/Parseurs_config_Firewall/src/input/` -- Modifier le fichier `site.json` de données dans `/Parseurs_config_Firewall/src/data/` \ No newline at end of file +- Modifier le fichier `site.json` de données dans `/Parseurs_config_Firewall/src/data/` + +```bash +python3 ./main.py +``` diff --git a/help_Switch.md b/help_Switch.md new file mode 100644 index 0000000..e69de29 diff --git a/main.py b/main.py new file mode 100644 index 0000000..6bb0fc5 --- /dev/null +++ b/main.py @@ -0,0 +1,133 @@ +import subprocess +import os +import sys +import venv +import tkinter as tk +from tkinter import ttk +from gui_firewall import open_firewall_gui +from gui_switch import open_switch_gui + +BASE_DIR = os.path.dirname(os.path.abspath(__file__)) +VENV_DIR = os.path.join(BASE_DIR, "venv") +REQ_FILE = os.path.join(BASE_DIR, "requirements.txt") + +def venv_python(): + if sys.platform == "win32": + return os.path.join(VENV_DIR, "Scripts", "python.exe") + return os.path.join(VENV_DIR, "bin", "python") + +def in_venv(): + return sys.prefix != sys.base_prefix + +def create_venv(): + print("[INFO] Création de l'environnement virtuel…") + venv.EnvBuilder(with_pip=True).create(VENV_DIR) + +def install_requirements(): + print("[INFO] Vérification / installation des dépendances…") + subprocess.check_call([ + venv_python(), + "-m", + "pip", + "install", + "--upgrade", + "pip", + "setuptools", + "wheel" + ]) + + subprocess.check_call([ + venv_python(), + "-m", + "pip", + "install", + "-r", + REQ_FILE + ]) + +def bootstrap_venv(): + if not os.path.isdir(VENV_DIR): + print("[INFO] Aucun venv détecté") + create_venv() + install_requirements() + return + + print("[INFO] Environnement virtuel détecté") + install_requirements() + + +def relaunch_in_venv(): + print("[INFO] Relance du script dans le venv…") + subprocess.check_call([ + venv_python(), + __file__ + ]) + sys.exit(0) + +# Contenu fenêtre principale +def open_main_gui(): + root = tk.Tk() + root.title("Analyse Réseau") + root.geometry("650x350") + root.resizable(False, False) + + ttk.Label( + root, + text="Analyse Réseau", + font=("Arial", 16, "bold") + ).pack(pady=20) + + ttk.Label( + root, + text="Sélectionnez le type d'analyse à effectuer :", + font=("Arial", 11) + ).pack(pady=10) + + ttk.Button( + root, + text="Analyse configuration Firewall", + width=30, + command=lambda: open_firewall_gui(root, BASE_DIR) + ).pack(pady=5) + + ttk.Label( + root, + text="(Convertir les données au format normalisé Yang dans un fichier JSON)" \ + "\n + possibilité de générer une matrice de flux en Excel" \ + "\n + possibilité de générer une matrice de routage en Excel (route statique uniquement)", + font=("Arial", 9, "italic"), + anchor="center", + justify="center" + ).pack(pady=5) + + ttk.Separator(root, orient="horizontal").pack(fill="x", pady=10) + + ttk.Button( + root, + text="Analyse log Switch", + width=30, + command=lambda: open_switch_gui(root, BASE_DIR) + ).pack(pady=5) + + ttk.Label( + root, + text="(Convertir les données au format normalisé Yang dans un fichier JSON)" \ + "\n + possibilité de générer un schéma réseau", + font=("Arial", 9, "italic"), + anchor="center", + justify="center" + ).pack(pady=5) + + root.mainloop() + +def main(): + if not in_venv(): + bootstrap_venv() + relaunch_in_venv() + + print("[INFO] Environnement prêt") + + open_main_gui() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/Parseurs_config_Firewall/requirements.txt b/requirements.txt similarity index 100% rename from Parseurs_config_Firewall/requirements.txt rename to requirements.txt