diff --git a/core.py b/core.py index 3a82f1c..84cde84 100644 --- a/core.py +++ b/core.py @@ -14,6 +14,12 @@ def clear_screen(): os.system("cls" if system() == "Windows" else "clear") +def check_dependency(command): + """Check if a system command exists.""" + from shutil import which + return which(command) is not None + + def validate_input(ip, val_range): val_range = val_range or [] try: @@ -60,36 +66,44 @@ def show_info(self): if self.PROJECT_URL: desc += '\n\t[*] ' desc += self.PROJECT_URL - os.system(f'echo "{desc}"|boxes -d boy | lolcat') + + if check_dependency("boxes") and check_dependency("lolcat"): + os.system(f'echo "{desc}"|boxes -d boy | lolcat') + else: + print(f"\n{desc}\n") def show_options(self, parent = None): - clear_screen() - self.show_info() - for index, option in enumerate(self.OPTIONS): - print(f"[{index + 1}] {option[0]}") - if self.PROJECT_URL: - print(f"[{98}] Open project page") - print(f"[{99}] Back to {parent.TITLE if parent is not None else 'Exit'}") - option_index = input("Select an option : ") - try: - option_index = int(option_index) - if option_index - 1 in range(len(self.OPTIONS)): - ret_code = self.OPTIONS[option_index - 1][1]() - if ret_code != 99: + while True: + clear_screen() + self.show_info() + for index, option in enumerate(self.OPTIONS): + print(f"[{index + 1}] {option[0]}") + if self.PROJECT_URL: + print(f"[{98}] Open project page") + print(f"[{99}] Back to {parent.TITLE if parent is not None else 'Exit'}") + option_index = input("Select an option : ") + try: + option_index = int(option_index) + if 1 <= option_index <= len(self.OPTIONS): + ret_code = self.OPTIONS[option_index - 1][1]() + if ret_code == 99: + return 99 + input("\n\nPress ENTER to continue:") + elif option_index == 98: + self.show_project_page() + elif option_index == 99: + if parent is None: + sys.exit() + return 99 + else: + print("Please enter a valid option") input("\n\nPress ENTER to continue:") - elif option_index == 98: - self.show_project_page() - elif option_index == 99: - if parent is None: - sys.exit() - return 99 - except (TypeError, ValueError): - print("Please enter a valid option") - input("\n\nPress ENTER to continue:") - except Exception: - print_exc() - input("\n\nPress ENTER to continue:") - return self.show_options(parent = parent) + except (TypeError, ValueError): + print("Please enter a valid option") + input("\n\nPress ENTER to continue:") + except Exception: + print_exc() + input("\n\nPress ENTER to continue:") def before_install(self): pass @@ -148,31 +162,35 @@ def __init__(self): pass def show_info(self): - os.system("figlet -f standard -c {} | lolcat".format(self.TITLE)) - # os.system(f'echo "{self.DESCRIPTION}"|boxes -d boy | lolcat') - # print(self.DESCRIPTION) + if check_dependency("figlet") and check_dependency("lolcat"): + os.system("figlet -f standard -c {} | lolcat".format(self.TITLE)) + else: + print(f"\n{'='*20} {self.TITLE} {'='*20}\n") def show_options(self, parent = None): - clear_screen() - self.show_info() - for index, tool in enumerate(self.TOOLS): - print(f"[{index} {tool.TITLE}") - print(f"[{99}] Back to {parent.TITLE if parent is not None else 'Exit'}") - tool_index = input("Choose a tool to proceed: ") - try: - tool_index = int(tool_index) - if tool_index in range(len(self.TOOLS)): - ret_code = self.TOOLS[tool_index].show_options(parent = self) - if ret_code != 99: + while True: + clear_screen() + self.show_info() + for index, tool in enumerate(self.TOOLS): + print(f"[{index + 1}] {tool.TITLE}") + print(f"[{99}] Back to {parent.TITLE if parent is not None else 'Exit'}") + tool_index = input("Choose a tool to proceed: ") + try: + tool_index = int(tool_index) + if 1 <= tool_index <= len(self.TOOLS): + ret_code = self.TOOLS[tool_index - 1].show_options(parent = self) + if ret_code == 99: + continue + elif tool_index == 99: + if parent is None: + sys.exit() + return 99 + else: + print("Please enter a valid option") input("\n\nPress ENTER to continue:") - elif tool_index == 99: - if parent is None: - sys.exit() - return 99 - except (TypeError, ValueError): - print("Please enter a valid option") - input("\n\nPress ENTER to continue:") - except Exception: - print_exc() - input("\n\nPress ENTER to continue:") - return self.show_options(parent = parent) + except (TypeError, ValueError): + print("Please enter a valid option") + input("\n\nPress ENTER to continue:") + except Exception: + print_exc() + input("\n\nPress ENTER to continue:") diff --git a/cybersec.py b/cybersec.py index 7d6daa8..11d605c 100644 --- a/cybersec.py +++ b/cybersec.py @@ -75,9 +75,15 @@ def show_info(self): if __name__ == "__main__": try: - if system() == 'Linux': - fpath = "/home/cybersec.txt" - if not os.path.exists(fpath): + home_dir = os.path.expanduser("~") + fpath = os.path.join(home_dir, ".cybersec_path.txt") + + if system() == "Windows": + print("\033[91m [!] Warning: Most tools in this collection are designed for Linux (Debian).") + print(" [!] Some functions may not work correctly on Windows.\033[0m") + sleep(1) + + if not os.path.exists(fpath): os.system('clear') # run.menu() print("""\033[36m @@ -113,38 +119,28 @@ def show_info(self): """) choice = input("CodingRanjith =>> ") - if choice == "1": - inpath = input("Enter Path (with Directory Name) >> ") - with open(fpath, "w") as f: - f.write(inpath) - print(f"Successfully Set Path to: {inpath}") - elif choice == "2": - autopath = "/home/cybersec/" - with open(fpath, "w") as f: - f.write(autopath) - print(f"Your Default Path Is: {autopath}") - sleep(3) - else: - print("Try Again..!!") - exit(0) - - with open(fpath) as f: - archive = f.readline() - if not os.path.exists(archive): - os.mkdir(archive) - os.chdir(archive) - AllTools().show_options() - - # If not Linux and probably Windows - elif system() == "Windows": - print( - r"\033[91m Please Run This Tool On A Debian System For Best Results\e[00m" - ) - sleep(2) - webbrowser.open_new_tab("https://tinyurl.com/y522modc") - - else: - print("Please Check Your System or Open New Issue ...") + if choice == "1": + inpath = input("Enter Path (with Directory Name) >> ") + inpath = os.path.abspath(inpath) + with open(fpath, "w") as f: + f.write(inpath) + print(f"Successfully Set Path to: {inpath}") + elif choice == "2": + autopath = os.path.join(home_dir, "cybersec") + with open(fpath, "w") as f: + f.write(autopath) + print(f"Your Default Path Is: {autopath}") + sleep(2) + else: + print("Try Again..!!") + exit(0) + + with open(fpath) as f: + archive = f.readline().strip() + if not os.path.exists(archive): + os.makedirs(archive, exist_ok=True) + os.chdir(archive) + AllTools().show_options() except KeyboardInterrupt: print("\nExiting ..!!!") diff --git a/requirement.txt b/requirements.txt similarity index 100% rename from requirement.txt rename to requirements.txt