Final_Installer_Merged/marged.py
2024-10-25 11:19:11 +05:30

447 lines
16 KiB
Python

import subprocess
import tkinter as tk
from tkinter import messagebox
import threading
# # Function to run device check before showing the wizard window
# def device_check():
# try:
# subprocess.run(['python3', 'intaller.py'], check=True)
# return True
# except subprocess.CalledProcessError as e:
# print(f"Error running device check script: {e}")
# return False
class DeviceCheckWizard:
def __init__(self, master):
self.master = master
self.step = 0 # Tracks the current step in the wizard
# Set up the wizard window
self.master.title("Device Check Wizard")
self.master.geometry("400x300")
self.label = tk.Label(self.master, text="Welcome to the Device Check Wizard")
self.label.pack(pady=20)
self.back_button = tk.Button(self.master, text="Back", command=self.previous_step, state="disabled")
self.back_button.pack(side=tk.LEFT, padx=20, pady=10) # Initially disabled
self.next_button = tk.Button(self.master, text="Next", command=self.next_step)
self.next_button.pack(side=tk.RIGHT, padx=20, pady=10)
self.result_label = tk.Label(self.master, text="")
self.result_label.pack(pady=20)
self.progress_label = tk.Label(self.master, text="")
self.progress_label.pack(pady=10)
def next_step(self):
# Hide the "Next" button and update labels for the current step
self.next_button.config(state="disabled") # Disable the "Next" button after it's clicked
self.hide_previous_content() # Clear previous content
self.progress_label.config(text="Running... Please wait.")
self.progress_label.pack(pady=10)
# Enable the Back button after the first step
if self.step > 0:
self.back_button.config(state="normal")
# Proceed to the respective step (DDoS, Malware, etc.)
if self.step == 0:
self.run_async(self.run_ddos)
elif self.step == 1:
self.run_async(self.run_malware)
elif self.step == 2:
self.run_async(self.run_ransomware)
else:
messagebox.showinfo("Info", "All checks completed.")
self.master.quit()
self.step += 1
def previous_step(self):
# Hide the "Back" button if the user goes back to the first step
self.step -= 1
if self.step == 0:
self.back_button.config(state="disabled")
# Handle going to the previous step
if self.step == 0:
self.result_label.config(text="Running DDoS check again.")
self.run_async(self.run_ddos)
elif self.step == 1:
self.result_label.config(text="Running Malware check again.")
self.run_async(self.run_malware)
elif self.step == 2:
self.result_label.config(text="Running Ransomware check again.")
self.run_async(self.run_ransomware)
def hide_previous_content(self):
# Hide the current widgets by removing them from the window
self.result_label.pack_forget()
self.progress_label.pack_forget()
def run_async(self, func):
# Run the function in a separate thread
thread = threading.Thread(target=func)
thread.start()
def run_ddos(self):
try:
process = subprocess.Popen(['python3', 'runn.py'])
self.result_label.config(text="DDoS check running in the background.")
self.result_label.pack(pady=20)
self.check_process(process, "DDoS")
except Exception as e:
self.result_label.config(text=f"Error running DDoS script: {e}")
finally:
self.on_process_complete()
def run_malware(self):
try:
process = subprocess.Popen(['python3', 'Final_Malware.py'])
self.result_label.config(text="Malware check running in the background.")
self.result_label.pack(pady=20)
self.check_process(process, "Malware")
except Exception as e:
self.result_label.config(text=f"Error running malware script: {e}")
finally:
self.on_process_complete()
def run_ransomware(self):
try:
process = subprocess.Popen(['python3', 'Ransomware_Type.py'])
self.result_label.config(text="Ransomware check running in the background.")
self.result_label.pack(pady=20)
self.check_process(process, "Ransomware")
except Exception as e:
self.result_label.config(text=f"Error running ransomware script: {e}")
finally:
self.on_process_complete()
def check_process(self, process, name):
def poll():
if process.poll() is None:
# If the process is still running, check again after 500ms
self.master.after(500, poll)
else:
# Process has completed
if process.returncode == 0:
self.result_label.config(text=f"{name} check completed successfully.")
else:
self.result_label.config(text=f"{name} check failed.")
self.on_process_complete()
# Start polling the process
poll()
def on_process_complete(self):
# Re-enable the Next button after the process is done
self.next_button.config(state="normal")
self.next_button.pack(pady=10)
self.progress_label.config(text="Process completed. Click Next to proceed.")
self.progress_label.pack(pady=10)
# # # Main logic to run the device check before starting the wizard
# # if __name__ == "__main__":
# # if device_check():
# # # If device check is successful, initialize the Tkinter window
# # root = tk.Tk()
# # wizard = DeviceCheckWizard(root)
# # root.mainloop()
# # else:
# # # If the device check fails, show an error message and exit
# # print("Device check failed. Exiting program.")
# # messagebox.showerror("Error", "Device check failed. The wizard will not start.")
# Initialize the Tkinter window
root = tk.Tk()
wizard = DeviceCheckWizard(root)
root.mainloop()
# import tkinter as tk
# from tkinter import ttk, messagebox
# import subprocess
# import threading
# import sys
# class DeviceCheckWizard:
# def __init__(self, master):
# self.master = master
# self.step = 0 # Tracks the current step in the wizard
# self.is_running = False # Flag to check if a process is running
# # Set up the wizard window
# self.master.title("Device Check Wizard")
# self.master.geometry("600x450") # Adjusted for better visibility
# # Step title
# self.step_label = tk.Label(self.master, text="Step 1: Welcome", font=("Helvetica", 16, "bold"))
# self.step_label.pack(pady=10)
# # Description label for each step
# self.description_label = tk.Label(self.master, text="This wizard will guide you through device checks.")
# self.description_label.pack(pady=5)
# # Progress bar for visual feedback
# self.progress_bar = ttk.Progressbar(self.master, orient='horizontal', mode='determinate', length=400)
# self.progress_bar.pack(pady=10)
# # Frame for output
# self.output_frame = tk.Frame(self.master, padx=10, pady=10)
# self.output_frame.pack(pady=10)
# self.output_text = tk.Text(self.output_frame, height=10, width=60)
# self.output_text.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
# self.scrollbar = ttk.Scrollbar(self.output_frame, command=self.output_text.yview)
# self.scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
# self.output_text.config(yscrollcommand=self.scrollbar.set, bg="#f0f0f0", borderwidth=1, relief="solid")
# # Navigation buttons
# self.button_frame = tk.Frame(self.master)
# self.button_frame.pack(pady=20)
# self.back_button = ttk.Button(self.button_frame, text="Back", command=self.previous_step, state="disabled")
# self.back_button.grid(row=0, column=0, padx=20)
# self.next_button = ttk.Button(self.button_frame, text="Next", command=self.next_step)
# self.next_button.grid(row=0, column=1, padx=20)
# def update_step(self):
# """Updates step labels, progress bar, and description."""
# steps_info = [
# ("Step 1: Welcome", "Welcome to the Device Check Wizard."),
# ("Step 2: DDoS Check", "Checking for any Distributed Denial of Service attacks."),
# ("Step 3: Malware Check", "Running a Malware scan on the device."),
# ("Step 4: Ransomware Check", "Checking for Ransomware on the device."),
# ]
# self.step_label.config(text=steps_info[self.step][0])
# self.description_label.config(text=steps_info[self.step][1])
# self.progress_bar['value'] = (self.step + 1) * 25 # Progress increment based on steps (0 to 100)
# def next_step(self):
# # Check if a process is running
# if self.is_running:
# messagebox.showinfo("Info", "A process is currently running. Please wait.")
# return
# # Proceed to the respective step (DDoS, Malware, etc.)
# if self.step == 0:
# self.output_text.delete(1.0, tk.END)
# self.output_text.insert(tk.END, "Running DDoS check...\n")
# self.run_async(self.run_ddos)
# elif self.step == 1:
# self.output_text.delete(1.0, tk.END)
# self.output_text.insert(tk.END, "Running Malware check...\n")
# self.run_async(self.run_malware)
# elif self.step == 2:
# self.output_text.delete(1.0, tk.END)
# self.output_text.insert(tk.END, "Running Ransomware check...\n")
# self.run_async(self.run_ransomware)
# else:
# messagebox.showinfo("Info", "All checks completed.")
# self.master.quit()
# self.step += 1
# self.update_step() # Update the UI for the next step
# # Enable the back button after the first step
# if self.step > 0:
# self.back_button.config(state="normal")
# def previous_step(self):
# if self.is_running:
# messagebox.showinfo("Info", "A process is currently running. Please wait.")
# return
# self.step -= 1
# if self.step < 0:
# self.step = 0
# self.back_button.config(state="disabled")
# self.update_step() # Update the UI for the previous step
# def run_async(self, func):
# # Set the flag to indicate a process is running
# self.is_running = True
# thread = threading.Thread(target=func)
# thread.start()
# def run_ddos(self):
# self.run_process(['python3', 'runn.py'], "DDoS")
# def run_malware(self):
# self.run_process(['python3', 'Final_Malware.py'], "Malware")
# def run_ransomware(self):
# self.run_process(['python3', 'Ransomware_Type.py'], "Ransomware")
# def run_process(self, command, name):
# self.output_text.insert(tk.END, f"{name} check started...\n")
# self.output_text.see(tk.END) # Scroll to the end
# try:
# # Using Popen for real-time output
# process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
# # Read the output line by line
# for line in process.stdout:
# self.output_text.insert(tk.END, line) # Display stdout
# self.output_text.see(tk.END) # Auto-scroll to the end
# # Wait for the process to complete and get return code
# return_code = process.wait()
# if return_code == 0:
# self.output_text.insert(tk.END, f"{name} check completed successfully.\n")
# else:
# self.output_text.insert(tk.END, f"Error running {name} script. Return code: {return_code}\n")
# except Exception as e:
# self.output_text.insert(tk.END, f"Exception running {name} script: {str(e)}\n")
# finally:
# self.is_running = False # Reset the flag
# self.on_process_complete()
# def on_process_complete(self):
# self.description_label.config(text="Process completed. You can proceed to the next step.")
# # Initialize the Tkinter window
# root = tk.Tk()
# wizard = DeviceCheckWizard(root)
# root.mainloop()
# import subprocess
# import tkinter as tk
# from concurrent.futures import ThreadPoolExecutor
# def devicecheck():
# try:
# # Call the subprocess to run the installer.py script
# result = subprocess.run(['python3', 'intaller.py'], check=True, capture_output=True, text=True)
# print("Device check successful.")
# print("Installer output:", result.stdout)
# print("Installer errors (if any):", result.stderr)
# # Use ThreadPoolExecutor to call all functions in parallel
# with ThreadPoolExecutor() as executor:
# # Start the function calls
# futures = {
# 'ddos': executor.submit(ddos),
# 'malware': executor.submit(malware),
# 'ransomware': executor.submit(ransomware),
# 'ransomware_model': executor.submit(ransomware_model),
# }
# # Wait for all functions to complete and print their results
# for name, future in futures.items():
# try:
# result = future.result() # This will block until the function completes
# print(f"{name.capitalize()} check result: {result}")
# except Exception as e:
# print(f"Error in {name}: {e}")
# except subprocess.CalledProcessError as e:
# print(f"Error running installer.py: {e}")
# print(f"Installer returned error output: {e.stderr}")
# def ddos():
# try:
# subprocess.run(['python3', '/home/tech4biz-001/Desktop/umais-code/Final_DDOS_UBUNTU_Tested/run.py'], check=True)
# print("DDOS check successful.")
# return True
# except subprocess.CalledProcessError as e:
# print(f"Error running DDoS script: {e}")
# return False
# def malware():
# try:
# subprocess.run(['python3', 'Final_Malware.py'], check=True)
# print("Malware check successful.")
# return True
# except subprocess.CalledProcessError as e:
# print(f"Error running malware script: {e}")
# return False
# def ransomware():
# try:
# subprocess.run(['python3', 'Ransomware_Type.py'], check=True)
# print("Ransomware check successful.")
# return True
# except subprocess.CalledProcessError as e:
# print(f"Error running ransomware script: {e}")
# return False
# def ransomware_model():
# try:
# subprocess.run(['python3', 'Ransomware_Audit.py'], check=True)
# print("Ransomware model check successful.")
# return True
# except subprocess.CalledProcessError as e:
# print(f"Error running ransomware model script: {e}")
# return False
# # Initialize the Tkinter window
# root = tk.Tk()
# root.title("Marged App")
# root.geometry("400x300")
# label = tk.Label(root, text="Tkinter Application for Device Check")
# label.pack(pady=20)
# # Add a button to trigger the devicecheck function
# button = tk.Button(root, text="Start Device Check", command=devicecheck)
# button.pack(pady=10)
# # Start the Tkinter main loop
# root.mainloop()