diff --git a/.gitignore b/.gitignore index 3384f7f..238e99b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,4 @@ # ignore les fichiers et dossiers - - - *.orig *.bak *.BAK @@ -16,11 +13,11 @@ *.DS_Store npm-debug.log Thumbs.db +.idea +.vscode .sass-cache __pycache__ .coverage pylint.txt package-lock.json - -venv/ -__pycache__ \ No newline at end of file +venv \ No newline at end of file diff --git a/App.py b/App.py index 282fe89..0fb643f 100644 --- a/App.py +++ b/App.py @@ -5,9 +5,8 @@ # * @modify date 2021-06-18 10:37:22 # */ - - -import platform, json +import platform +import json import os import re import subprocess @@ -20,34 +19,37 @@ class Application(): filesOS = [] i18n = {} + def Initialisation(self): - - #Initialisation du language en premier + + # Initialisation du language en premier self.DetectionLanguages() - print("*"*5, self.i18n['START'] , "*"*5) + print("*"*5, self.i18n['START'], "*"*5) self.DetectionSysteme() def DetectionLanguages(self): """Détection de la langue du system""" - if platform.system() == "Linux": - f = open(os.path.join('lang',os.getenv('LANG') + ".json"), 'r', encoding='utf8') + f = open(os.path.join('lang', os.getenv( + 'LANG') + ".json"), 'r', encoding='utf8') elif platform.system() == "Windows": - f = open(os.path.join('lang',locale.getdefaultlocale()[0] + ".json"), 'r', encoding='utf8') - + f = open(os.path.join('lang', locale.getdefaultlocale() + [0] + ".json"), 'r', encoding='utf8') + self.i18n = json.loads(f.read()) - + def DetectionSysteme(self): """Détection du system Host et lance le script approprier """ self.ListFileSystemOS() print("System :", platform.system(), self.i18n['BASE']['detected']) - print("Language:", locale.getdefaultlocale()[0], self.i18n['BASE']['detected']) - + print("Language:", locale.getdefaultlocale() + [0], self.i18n['BASE']['detected']) + if platform.system() == "Linux": self.LinuxDetecter() @@ -55,7 +57,8 @@ def DetectionSysteme(self): self.WindowsDetecter() else: - print(str(self.i18n['ERROR']['no_charge_sytem']).format(platform.system(), platform.release())) + print(str(self.i18n['ERROR']['no_charge_sytem']).format( + platform.system(), platform.release())) return False def LinuxDetecter(self): @@ -64,15 +67,15 @@ def LinuxDetecter(self): choix = str(input("utiliser le Benchmarck par défault y/n: ")) if choix == "y" or choix == "Y": - + os_release = dict(Mylib.read_os_releases()) for n, f in enumerate(self.filesOS): if(re.search(os_release.get('ID')+"_"+os_release.get('VERSION_ID'), f)): subprocess.run(['python', f]) else: - print("Votre system", platform.system(), platform.release() ,"na pas encore de CIS benchmarck ") - + print("Votre system", platform.system(), + platform.release(), "na pas encore de CIS benchmarck ") elif choix == "n" or choix == "N": for n, f in enumerate(self.filesOS): @@ -83,16 +86,17 @@ def LinuxDetecter(self): def WindowsDetecter(self): """Vérification du systeme windows détection""" - + choix = str(input(str(self.i18n['INPUT']['choise_benchmarck']))) if choix == "y" or choix == "Y": - - for n,f in enumerate(self.filesOS): + + for n, f in enumerate(self.filesOS): if(re.search(platform.win32_ver()[0], f)): - subprocess.run(['python',f]) + subprocess.run(['python', f]) else: - print(str(self.i18n['ERROR']['no_benchmarck_system']).format(platform.system(), platform.release())) + print(str(self.i18n['ERROR']['no_benchmarck_system']).format( + platform.system(), platform.release())) elif choix == "n" or choix == "N": for n, f in enumerate(self.filesOS): @@ -117,4 +121,4 @@ def ListFileSystemOS(self): if __name__ == '__main__': app = Application() - app.Initialisation() + app.Initialisation() \ No newline at end of file diff --git a/CIS/Windows/windows_2012ServerR2.py b/CIS/Windows/windows_2012ServerR2.py index 73e3e78..0ba524e 100644 --- a/CIS/Windows/windows_2012ServerR2.py +++ b/CIS/Windows/windows_2012ServerR2.py @@ -1,4 +1,6 @@ import subprocess +import json + class CIS(): diff --git a/Controllers/Controller.py b/Controllers/Controller.py new file mode 100644 index 0000000..7f1e4b4 --- /dev/null +++ b/Controllers/Controller.py @@ -0,0 +1,5 @@ + +class Controller(object): + def __init__(self, view): + super().__init__() + self.view = view diff --git a/Controllers/Home.py b/Controllers/Home.py new file mode 100644 index 0000000..3bce40f --- /dev/null +++ b/Controllers/Home.py @@ -0,0 +1,24 @@ +import platform +from .Controller import Controller + + +class HomeController(Controller): + + def DetectionSystem(self): + """Détection du system Host et lance le script approprier """ + + if platform.system() == "Linux": + self.LinuxStartScript() + + elif platform.system() == "Windows": + self.WindowsStartScript() + else: + self.view.NoPlatformSupport + + + def WindowsStartScript(self): + pass + + + def LinuxStartScript(self): + pass \ No newline at end of file diff --git a/CIS/pop_Linux_20.04.py b/Controllers/__init__.py similarity index 100% rename from CIS/pop_Linux_20.04.py rename to Controllers/__init__.py diff --git a/Main.py b/Main.py new file mode 100644 index 0000000..da2aa2f --- /dev/null +++ b/Main.py @@ -0,0 +1,118 @@ +import locale +import platform +import tkinter as tk +import os +import json + +from Views.Widget import NavBar, DisclaimerPage, SettingPage +from Views.HomePage import MainPage + + +class Application(tk.Tk): + + # Initialisation de la fenetre + def __init__(self): + super().__init__() + self.SETTING = setting + self.title("Extractor Configuration") + main_frame = tk.Frame(self, width=setting.GUI['WIDTH'], height=setting.GUI['HEIGHT']) + main_frame.pack_propagate(0) + main_frame.pack(fill="both", expand=True) + self.resizable(0, 0) + self.geometry(f"{setting.GUI['WIDTH']}x{setting.GUI['HEIGHT']}") + + # Menu de l'applications + menubar = NavBar(parent=self) + self.config(menu=menubar) + + # Frame de l'applications + self.frames = {} + pages = (MainPage,) # TODO Liste des Pages + + for page in pages: + frame = page(parent=main_frame, setting=self.SETTING) + self.frames[page] = frame + frame.place(rely=0, relx=0) + + self.show_frame(MainPage) + + def show_frame(self, frame_name): + """Affiche la page passer en parameter.""" + frame = self.frames[frame_name] + frame.tkraise() + + def ChangeLanguageAndTheme(self, args={}): + """Récuper un tableau d'argument pour l'envoie a la class setting""" + if args is not None: + setting.ChangeSetting(args) + + def OpenSettingPage(self): + SettingPage(parent=self) + + def OpenDisclaimerPage(self): + DisclaimerPage(parent=self) + + +class Setting(): + """Class qui stock l'ensemble des paramètre du fichier setting.json""" + + def __init__(self): + self.APP = [] + self.GUI = [] + self.THEME = [] + self.MODE_DARK = 0 + self.LANG = [] + + self.InitSettings() + self.InitLanguages() + + def InitSettings(self): + """Chargement du fichier setting.json""" + with open(os.path.join('setting.json')) as Settings: + data = json.load(Settings) + self.APP = data['APP'] + self.GUI = data['GUI'] + self.MODE_DARK = data['GUI']['MODE_DARK'] + + # check le dark mode si il est Activer dans le fichier setting.json + if self.MODE_DARK == 1: + self.THEME = data['GUI']['THEME_DARK'] + else: + self.THEME = data['GUI']['THEME_LIGHT'] + + if self.APP["AUTO_LANG"] == 1 and platform.system() == "Windows": + self.APP["LANG"] = locale.getdefaultlocale()[0] + elif self.APP["AUTO_LANG"] == 1 and platform.system() == "Linux": + self.APP["LANG"] = os.getenv('LANG') + + + def InitLanguages(self): + """Chargement du language dans le fichier setting.json""" + with open(os.path.join('lang', self.APP['LANG'] + ".json"), 'r', encoding='utf8') as lang: + data = json.load(lang) + self.LANG = data + + def ChangeSetting(self, args={}): + data = [] + + #Récuper tout le fichier setting.json pour le stocké dans data + with open(os.path.join('setting.json'), 'r', encoding='utf8')as r_file: + data = json.load(r_file) + + #Réécrie les donnéés avant de les sauvegarders + with open(os.path.join('setting.json'), 'w') as w_file: + try: + data["APP"]["LANG"] = args["LANG"] + data["APP"]["AUTO_LANG"] = args["AUTO_LANG"] + data["GUI"]["MODE_DARK"] = args["MODE_DARK"] + + json.dump(data, w_file) + except print(0): + print("File Setting no save") + + + +if __name__ == "__main__": + setting = Setting() + root = Application() + root.mainloop() diff --git a/Models/Model.py b/Models/Model.py new file mode 100644 index 0000000..0d57131 --- /dev/null +++ b/Models/Model.py @@ -0,0 +1,2 @@ +class Model: + uuid = [] \ No newline at end of file diff --git a/CIS/ubuntu_Linux_20.04.py b/Models/__init__.py similarity index 100% rename from CIS/ubuntu_Linux_20.04.py rename to Models/__init__.py diff --git a/Models/language.py b/Models/language.py new file mode 100644 index 0000000..e69de29 diff --git a/Views/HomePage.py b/Views/HomePage.py new file mode 100644 index 0000000..418c612 --- /dev/null +++ b/Views/HomePage.py @@ -0,0 +1,49 @@ +import platform +import tkinter as tk +from tkinter import LabelFrame, Label, messagebox + +from Controllers.Home import HomeController + +class MainPage(tk.Frame): + def __init__(self, parent, setting): + super().__init__(parent) + self.setting = setting + + self.controller = HomeController(view=self) + self.controller.DetectionSystem() + + + ##########################################:: INTERFACE ::#################################### + + #Frame information sur la platform + frame_InfoSystem = LabelFrame(parent, text=setting.LANG["info_platform"]) + frame_InfoSystem.grid(pady=10, padx=10) + + label_PlatformSystem = Label(frame_InfoSystem, text=str("• " + setting.LANG["system_detected"]).format(platform.system() + " " + platform.release())) + label_PlatformSystem.pack(padx=5, pady=5) + + label_BuildSystem = Label(frame_InfoSystem,text=str("• "+"Build: " + platform.version())) + label_BuildSystem.pack(padx=5, pady=5) + + ##########################################:: END INTERFACE ::#################################### + + ##########################################:: FUNCTION ::#################################### + + def IsAutoStartScriptPlatform(self): + """Si dans le controller,si il exist un script pour la platform en question + ont demande a l'utilisateur de choisir si ont veux exécuter + [Return] Boolean + """ + msg_IsAutoScrip = messagebox.askyesnocancel(title=self.setting.LANG["WARNING"]["information"], + message=self.setting.LANG["WARNING"]["is_detect_scrip_auto_start"]) + + return msg_IsAutoScrip + + + def NoPlatformSupport(self): + """Affiche un messageBox pour avertir que le script n'est pas compatible""" + + msgBox_PlatformNoSupport = messagebox.askyesnocancel(title=self.setting.LANG["ERROR"]["error"], + message=self.setting.LANG["ERROR"]["no_support_platform"]) + return msgBox_PlatformNoSupport + ##########################################:: END FUNCTION ::#################################### diff --git a/Views/Widget.py b/Views/Widget.py new file mode 100644 index 0000000..7794a74 --- /dev/null +++ b/Views/Widget.py @@ -0,0 +1,127 @@ +import tkinter as tk +from tkinter import * +from tkinter import messagebox + +class NavBar(tk.Menu): + """ Barre de Navigation + """ + + def __init__(self, parent): + super().__init__(parent) + + # Option + menu_option = tk.Menu(self, tearoff=0) + self.add_cascade( + label=parent.SETTING.LANG['SYSTEM']['parameter'], menu=menu_option) + menu_option.add_command( + label=parent.SETTING.LANG['SYSTEM']['option'], command=parent.OpenSettingPage) + menu_option.add_command( + label=parent.SETTING.LANG['SYSTEM']['about'], command=parent.OpenDisclaimerPage) + menu_option.add_separator() + menu_option.add_command( + label=parent.SETTING.LANG['SYSTEM']['exit'], command=parent.quit) + +class BaseWindow(tk.Toplevel): + """ + Classe pour faire de l'éritage pour + les sous fenètres de l'application + """ + + def __init__(self): + super().__init__() + self.base_frame = tk.Frame(self) + self.base_frame.pack_propagate(0) + self.base_frame.pack(fill="both", expand=True) + self.fonts = ("sans-serif", 9) + self.geometry("600x200") + self.resizable(0, 0) + +class SettingPage(BaseWindow): + """ Page des Options de l'application + """ + + def __init__(self, parent): + super().__init__() + self.parent = parent + self.geometry("400x200") + self.title(parent.SETTING.LANG['SYSTEM']['option']) + + #Contener padding + self.base_frame.pack(padx=5, pady=20) + + # Language + label_language = Label( + self.base_frame, text=parent.SETTING.LANG['SYSTEM']['language'] + ':', font=('Arial', 10), width=10) + label_language.grid(row=0, column=0) + + # CheckBox Auto Language System + self.check_langAuto_Var = IntVar() + self.check_langAuto_Var.set(parent.SETTING.APP['AUTO_LANG']) + check_langAuto = Checkbutton(self.base_frame, text=parent.SETTING.LANG['active_detected_language'], + variable=self.check_langAuto_Var) + check_langAuto.grid(row=0, column=2) + + #Récuper la string dans le tableau language + self.drop_language_Var = StringVar() + self.drop_language_Var.set(parent.SETTING.APP['LANG']) + + #List des languages dans le fichier lang + language = ["fr_FR", "en_EN"] + + #Selection de la langue et la stock dans (drop_language_Var) + drop_language = OptionMenu( + self.base_frame, self.drop_language_Var, *language) + drop_language.grid(row=0, column=1) + + # Theme App + label_theme = Label(self.base_frame, text="Theme:", + font=("Arial", 10), width=10) + label_theme.grid(row=1, column=0) + + # Checkbox Theme dark + self.check_theme_Var = IntVar() + self.check_theme_Var.set(parent.SETTING.GUI['MODE_DARK']) + check_theme = Checkbutton(self.base_frame, text=parent.SETTING.LANG['mode_dark'], variable=self.check_theme_Var) + check_theme.grid(row=1, column=1) + + # Btn Submit + btn_valide_theme = Button( + self.base_frame, text="Appliquer", command=self.CommitDataSetting) + btn_valide_theme.grid(row=3, column=1) + + def CommitDataSetting(self): + data = { + "LANG":self.drop_language_Var.get(), + "MODE_DARK":self.check_theme_Var.get(), + "AUTO_LANG": self.check_langAuto_Var.get()} + + self.parent.ChangeLanguageAndTheme(data) + messagebox.showinfo(title=self.parent.SETTING.LANG["INDEX"]["system"], + message=self.parent.SETTING.LANG["WARNING"]["warning"], + detail=self.parent.SETTING.LANG["WARNING"]["restart_application_change"] + ) + +class DisclaimerPage(BaseWindow): + """ Page du à propos + """ + def __init__(self, parent): + super().__init__() + self.title(parent.SETTING.LANG['SYSTEM']['about']) + self.geometry("400x200") + label_title = Label(self.base_frame, text=parent.SETTING.LANG["START"], font=('Arial Bold', 11)) + label_title.grid(row=0, column=0, columnspan=2, pady=15, padx=50) + + label_createBy = Label(self.base_frame, text="Create by:") + label_createBy.grid(row=1, column=0) + label_author = Label(self.base_frame, text=parent.SETTING.APP["AUTHOR"]["NAME"]) + label_author.grid(row=1, column=1) + + label_email = Label(self.base_frame, text="Email:") + label_email.grid(row=2, column=0) + label_author_email = Label(self.base_frame, text=parent.SETTING.APP["AUTHOR"]["EMAIL"]) + label_author_email.grid(row=2, column=1) + + label_version = Label(self.base_frame, text="version:") + label_version.grid(row=3, column=0) + label_version_current = Label(self.base_frame, text=parent.SETTING.APP['VERSION']) + label_version_current.grid(row=3, column=1) diff --git a/Views/__init__.py b/Views/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/lang/en_EN.json b/lang/en_EN.json new file mode 100644 index 0000000..9757a9e --- /dev/null +++ b/lang/en_EN.json @@ -0,0 +1,40 @@ +{ + "START": "Extractor of config server / workstation ", + "SYSTEM": { + "parameter":"Parameter", + "option": "Option", + "valide": "valider", + "applicate": "Applicate", + "delete": "Delete", + "detected": "Detected", + "about": "About", + "language": "Language", + "exit":"Exit" + }, + "INPUT": { + "choise_benchmarck": "utiliser le Benchmarck par défault y/n: ", + "enter_number" : "Entre le numéro: " + }, + "WARNING": { + "warning": "Attention !", + "information": "Information!", + "restart_application_change": "You must restart the application to support the changes", + "is_detect_scrip_auto_start": "We have detected that your system is supported, do you want to run the audit automatically ?" + }, + "ERROR": { + "error": "Error", + "no_charge_sytem": "votre system {} {} n'est pas pris en charge, contacter un des développeurs !", + "no_benchmarck_system" : "Nous avons pas de CIS Benchmarck pour votre system {} {} ❌", + "no_support_platform": "You system is not support" + }, + "INDEX": { + "system": "system" + }, + "active_detected_language": "Detected is system language", + "info_platform" : "Information is the platform", + "system_detected": "System {} detected", + "mode_dark":"mode dark", + "dark": "dark", + "mode_light":"mode light", + "light": "light" +} \ No newline at end of file diff --git a/lang/fr_FR.json b/lang/fr_FR.json index afec87d..c0de16c 100644 --- a/lang/fr_FR.json +++ b/lang/fr_FR.json @@ -1,19 +1,40 @@ { "START": "Extracteur de config serveur / workstation ", - "BASE": { + "SYSTEM": { + "parameter":"Paramètre", + "option": "Option", "valide": "valider", - "delete": "suprimmer", - "detected": "detecter" + "applicate": "Appliquer", + "delete": "Suprimmer", + "detected": "detecter", + "about": "À propos", + "language": "Langue", + "exit":"Quitter" }, "INPUT": { "choise_benchmarck": "utiliser le Benchmarck par défault y/n: ", "enter_number" : "Entre le numéro: " }, + "WARNING": { + "warning": "Attention", + "information": "Information", + "restart_application_change": "Vous devez redémarrer l'application pour prendre en charge les changements", + "is_detect_scrip_auto_start": "Nous avons détecter que votre system est pris en charge, voulez vous lancé l'audit automatiquement?" + }, "ERROR": { + "error": "Erreur", "no_charge_sytem": "votre system {} {} n'est pas pris en charge, contacter un des développeurs !", - "no_benchmarck_system" : "Nous avons pas de CIS Benchmarck pour votre system {} {} ❌" + "no_benchmarck_system" : "Nous avons pas de CIS Benchmarck pour votre system {} {} ❌", + "no_support_platform": "Votre system n'est pas supporter !" }, "INDEX": { - "SYSTEM": "system" - } + "system": "system" + }, + "active_detected_language": "Détection du langage system", + "info_platform" : "Information sur la platform", + "system_detected": "System {} détecter", + "mode_dark":"mode sombre", + "dark": "sombre", + "mode_light":"mode claire", + "light": "blanc" } \ No newline at end of file diff --git a/readme.md b/readme.md index 094de71..ecb9005 100644 --- a/readme.md +++ b/readme.md @@ -1,24 +1,28 @@ # Extractor Config Server and workstation +Extract Config est une application qui est basé sur les +CIS Benchmark. +L'application remonte tout les informations relative au document CIS selon la platform ou est exécuter l'application. +Grace à cela nous pouvons faire des audits sur les différends module de configuration sur un serveur ou un poste. -## install dependance +## Développement -``pip install -r requirements.txt`` +#### installe dépendance +Python => 3.6 -Start programme +``pip install -r requirements.txt`` -``python App.py`` +``python Main.py`` # CIS Benchmarck - -## Linux +### Linux - ubuntu server 20.04 : Dev 🚧 - popOS 20.04 : Dev 🚧 -## Windows +### Windows - Windows 2012 server R2 : Dev 🚧 - Windows 10 : Dev 🚧 \ No newline at end of file diff --git a/setting.json b/setting.json new file mode 100644 index 0000000..3626c55 --- /dev/null +++ b/setting.json @@ -0,0 +1 @@ +{"APP": {"LANG": "fr_FR", "AUTO_LANG": 0, "VERSION": "0.1.5", "AUTHOR": {"NAME": "Jahleel Lacascade", "EMAIL": "jahleel.lacascade@caeirus.com"}}, "GUI": {"WIDTH": 1024, "HEIGHT": 600, "MODE_DARK": 0, "THEME_LIGHT": {"COLOR-PRIMARY": "", "COLOR-SECONDE": "", "COLOR-TEXT-PRIMARY": "", "COLOR-TEXT-SECONDE": ""}, "THEME_DARK": {"COLOR-PRIMARY": "50514F", "COLOR-SECONDE": "247BA0", "COLOR-TEXT-PRIMARY": "", "COLOR-TEXT-SECONDE": ""}}} \ No newline at end of file