From 415d2f4a4faf6b6e4fce3b7753babc6d576d6959 Mon Sep 17 00:00:00 2001 From: "BlackHeart.Goon" Date: Tue, 2 Jan 2024 21:23:10 -0500 Subject: [PATCH 1/6] Update configcheck.py --- modules/configcheck.py | 188 +++++++++++++++++++++-------------------- 1 file changed, 96 insertions(+), 92 deletions(-) diff --git a/modules/configcheck.py b/modules/configcheck.py index 954b8fc..37d6999 100644 --- a/modules/configcheck.py +++ b/modules/configcheck.py @@ -15,7 +15,7 @@ # def configC(language_module): # checks if the nesasary files exist - if os.path.exists("./config/config.ini") == True: + if os.path.exists("./config/config.ini"): print(language_module.config1) else: print(language_module.error5) @@ -24,7 +24,7 @@ def configC(language_module): f.write(language_module.status3) exec(open("./update.py").read()) - if os.path.exists("./update.py") == True: + if os.path.exists("./update.py"): print(language_module.config2) else: print(language_module.error5) @@ -43,9 +43,9 @@ def colorSchemeGrabber(config): color = config.get("Personalizations", "colorScheme").upper() color_code = getattr(Fore, color) return color_code - except: - print("Could not read configuration file") - return "RED" + except configparser.Error as e: + print(f"Could not read configuration file: {e}") + return Fore.RED def delete_pycache(root_dir): @@ -64,99 +64,104 @@ def delete_pycache(root_dir): shutil.rmtree(pycache_path) +def ask_update_check(config, colorScheme, language_module): + try: + cfu = input(language_module.config4) + if cfu.lower() in ("y", "yes"): + exec(open("./update.py").read()) + elif cfu.lower() in ("n", "no"): + print(language_module.prompt5) + print_separator() + else: + print(language_module.idk2) + print_separator() + except KeyboardInterrupt: + outstanding_config_updates(config) + exit(1) + + +def random_enable_updates(config, language_module): + getNum = random.randint(1, 10) + # asks the user if they want to enable updates + if getNum == 7 and config.get("main", "checkforupdates") == "no": + changeconfig = input("Updates Are Disabed. Wanna Renable Them? [y/n]: ⤷ ") + # pharses it + if changeconfig.lower() in ("y", "yes"): + config.set("main", "checkforupdates", "yes") + print(language_module.updates) + save_config(config) + elif changeconfig.lower() in ("n", "no"): + print(language_module.prompt5) + else: + print(language_module.idk2) + + def configUpdateStuff(colorScheme, config, browser, language_module, argument): config.read("./config/config.ini") - # this is just something Alfred can use to return something when it needs to return nothing - holder = 0 + print_first_launch_messages(config, colorScheme, language_module) + decide_random_events(config, colorScheme, language_module) + is_first_launch(config, browser, language_module) - # checks to see if the user is running a Pre or if its Alfreds first launch. + # Handle arguments to prevent update prompts + if any(vars(argument).values()): + return + + if config.get("main", "checkforupdates") == "yes": + ask_update_check(config, colorScheme, language_module) + + random_enable_updates(config, language_module) + display_random_tip(config, language_module) + + +def display_random_tip(config, language_module): + if config.get("Personalizations", "showtips") == "yes": + # this gets the random tip to display on the screen + randomTip = random.choice(open("./config/tips.txt").readlines()) + print(randomTip) + + +def is_first_launch(config, browser, language_module): if config.get("main", "firstlaunch") == "yes": - print( - colorScheme + language_module.note + Fore.RESET + language_module.warning3 - ) - print("") - if config.get("main", "prerelease") == "yes": - print( - colorScheme + language_module.note + Fore.RESET + language_module.warning4 - ) - print(language_module.prompt2) - print("") - # this is the function to update the code + outstanding_config_updates(config, browser) + + +def outstanding_config_updates(config, browser=None): + if browser and browser == "MSEdgeHTM": + config.set("main", "browser", "Edge") + config.set("main", "firstlaunch", "no") + save_config(config) + + +def decide_random_events(config, colorScheme, language_module): x = random.randint(1, 4) - if x == 3 and config.get("main", "checkforupdates") == "yes": + if x == 3: print(language_module.prompt3) - if x == 2: + elif x == 2: print(language_module.prompt4) - # desides if arguments are being used. if so, it wont ask to update. - if any(vars(argument).values()): - holder = 1 - else: - if config.get("main", "checkforupdates") == "yes": - try: - cfu = input(language_module.config4) - if "Y" in cfu or "y" in cfu: - exec(open("./update.py").read()) - elif "N" in cfu or "n" in cfu: - print(language_module.prompt5) - print( - Fore.RESET - + """ -=========================================================================== - """ - ) - else: - print(language_module.idk2) - print( - Fore.RESET - + """ + + +def print_first_launch_messages(config, colorScheme, language_module): + if config.get("main", "firstlaunch") == "yes": + print(colorScheme + language_module.note + Fore.RESET + language_module.warning3) + print() + if config.get("main", "prerelease") == "yes": + print(colorScheme + language_module.note + Fore.RESET + language_module.warning4) + print(language_module.prompt2) + print() + + +def print_separator(): + print( + Fore.RESET + + """ =========================================================================== - """ - ) - except KeyboardInterrupt: - config.set("main", "firstlaunch", "no") - if browser == "MSEdgeHTM": - browser = "Edge" - config.set("main", "browser", browser) - with open("./config/config.ini", "w") as f: - config.write(f) - exit(1) - getNum = random.randint(1, 10) - if any(vars(argument).values()): - holder = 1 - else: - # asks the user if they want to enable updates - if config.get("main", "checkforupdates") == "no": - if getNum == 7: - changeconfig = input( - "Updates Are Disabed. Wanna Renable Them? [y/n]: ⤷ " - ) - # pharses it - if "Y" in changeconfig or "y" in changeconfig: - config.set("main", "checkforupdates", "yes") - print(language_module.updates) - with open("./config/config.ini", "w") as f: - config.write(f) - elif "N" in changeconfig or "n" in changeconfig: - print(language_module.prompt5) - else: - print(language_module.idk2) - - if config.get("main", "firstlaunch") == "yes": - config.set("main", "firstlaunch", "no") - if browser == "MSEdgeHTM": - browser = "Edge" - config.set("main", "browser", browser) - with open("./config/config.ini", "w") as f: - config.write(f) - - if ( - getNum == 3 - or getNum == 5 - and config.get("Personalizations", "showtips") == "yes" - ): - # this gets the random tip to display on the screen - randomTip = random.choice(open("./config/tips.txt").readlines()) - print(randomTip) + """ + ) + + +def save_config(config): + with open("./config/config.ini", "w") as f: + config.write(f) def syskeys(config): @@ -218,8 +223,7 @@ def display_options(config, section, language_module): def update_config(config, section, option_key, new_value): config.set(section, option_key, str(new_value)) - with open("./config/config.ini", "w") as f: - config.write(f) + save_config(config) def config_editor(config, language_module): From d6fd5ad67b8bff3dc269fc892746969fd4549443 Mon Sep 17 00:00:00 2001 From: EliteGreyIT67 Date: Wed, 3 Jan 2024 02:26:06 +0000 Subject: [PATCH 2/6] format fix --- modules/configcheck.py | 20 ++++++++++++-------- modules/lang.py | 3 +++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/modules/configcheck.py b/modules/configcheck.py index 37d6999..1195ebe 100644 --- a/modules/configcheck.py +++ b/modules/configcheck.py @@ -105,13 +105,13 @@ def configUpdateStuff(colorScheme, config, browser, language_module, argument): # Handle arguments to prevent update prompts if any(vars(argument).values()): return - + if config.get("main", "checkforupdates") == "yes": ask_update_check(config, colorScheme, language_module) - + random_enable_updates(config, language_module) display_random_tip(config, language_module) - + def display_random_tip(config, language_module): if config.get("Personalizations", "showtips") == "yes": @@ -131,7 +131,7 @@ def outstanding_config_updates(config, browser=None): config.set("main", "firstlaunch", "no") save_config(config) - + def decide_random_events(config, colorScheme, language_module): x = random.randint(1, 4) if x == 3: @@ -142,18 +142,22 @@ def decide_random_events(config, colorScheme, language_module): def print_first_launch_messages(config, colorScheme, language_module): if config.get("main", "firstlaunch") == "yes": - print(colorScheme + language_module.note + Fore.RESET + language_module.warning3) + print( + colorScheme + language_module.note + Fore.RESET + language_module.warning3 + ) print() if config.get("main", "prerelease") == "yes": - print(colorScheme + language_module.note + Fore.RESET + language_module.warning4) + print( + colorScheme + language_module.note + Fore.RESET + language_module.warning4 + ) print(language_module.prompt2) print() def print_separator(): print( - Fore.RESET + - """ + Fore.RESET + + """ =========================================================================== """ ) diff --git a/modules/lang.py b/modules/lang.py index 5371eef..e4550a2 100644 --- a/modules/lang.py +++ b/modules/lang.py @@ -5,6 +5,7 @@ CONFIG_INI_PATH = "./config/config.ini" LANG_PATH = "./lang/" + def load_language(language_code): try: language_path = f"{LANG_PATH}{language_code}.py" @@ -17,6 +18,7 @@ def load_language(language_code): print(f"Language file not found for {language_code}. Using default.") return None + def get_language(config): try: with open(CONFIG_INI_PATH, "r") as config_file: @@ -30,5 +32,6 @@ def get_language(config): raise return lang + language_code = get_language(config) language_m = load_language(language_code) From 33e8e908581346d09c305661f92e826d584c6855 Mon Sep 17 00:00:00 2001 From: EliteGreyIT67 Date: Wed, 3 Jan 2024 04:56:16 +0000 Subject: [PATCH 3/6] Refactor code --- brib.py | 21 ++-- modules/crypt.py | 89 ++++++++-------- update.py | 264 ++++++++++++++--------------------------------- 3 files changed, 132 insertions(+), 242 deletions(-) diff --git a/brib.py b/brib.py index 558cd19..1db6c2e 100755 --- a/brib.py +++ b/brib.py @@ -74,23 +74,16 @@ print(language_module.browser + browser) # gets the version of Alfred version = versionToPass +# Initialize the encryption key and cipher suite +encryption_key = generate_encryption_key() +cipher_suite = create_cipher(encryption_key) # gets the info to encrypt -syskey = ( - platform.system() - + platform.release() - + "-AlfredVer-" - + version - + "-" - + platform.python_version() - + "-" - + browser - + language_code -) +sys_info = f"{platform.system()}{platform.release()}-AlfredVer-{version}-{platform.python_version()}-{browser}{language_code}" # encrypts the key -encrypted_text = encrypt(syskey) +encrypted_sys_info = encrypt_text(cipher_suite, sys_info) print(language_module.encrypt1) # logs the key -saveInfo(config, encrypted_text) +save_encryption_info(config, encryption_key, encrypted_sys_info) # this prints the start up screen and passes the verion varaible in logo(colorScheme, "", version, config) # does config stuff @@ -301,7 +294,7 @@ # prints ui stuff print(Fore.GREEN + f"{language_module.scan1}" + uname + Fore.RESET) print("===========================================================") -if webscrape == True: +if webscrape: print(Fore.RED + language_module.note + Fore.RESET + language_module.warning2) print("===========================================================") print("") diff --git a/modules/crypt.py b/modules/crypt.py index 0c8c8e1..c06cc9d 100644 --- a/modules/crypt.py +++ b/modules/crypt.py @@ -1,61 +1,68 @@ import platform from configparser import ConfigParser - from cryptography.fernet import Fernet - from modules.configcheck import * from modules.lang import * config = ConfigParser() - - language_module = language_m +config.read("./config/config.ini") +versionToPass = configC(language_module) -def print_encrypted_and_decrypted_text(decrypted_text): - print("Decrypted text:", decrypted_text) - - -def saveInfo(config, syskey): - config.read("./config/config.ini") - config.set("main", "privatekey", str(key)) - config.set("main", "syscrypt", str(syskey)) - with open("./config/config.ini", "w") as f: - config.write(f) +def generate_encryption_key(): + """Generates a random encryption key for Fernet cipher.""" + return Fernet.generate_key() -# Generate a random key -key = Fernet.generate_key() -print("Encryption Key:", key.decode()) # Convert the key to a string for printing +def create_cipher(key): + """Creates a Fernet cipher suite using the specified key.""" + return Fernet(key) -# Create a Fernet object with the key -cipher_suite = Fernet(key) +def encrypt_text(cipher_suite, text): + """Encrypts the given text using the Fernet cipher suite.""" + return cipher_suite.encrypt(text.encode()) -def encrypt(text): - encrypted_text = cipher_suite.encrypt(text.encode()) - return encrypted_text +def decrypt_text(cipher_suite, encrypted_text): + """Decrypts the encrypted text using the Fernet cipher suite.""" + return cipher_suite.decrypt(encrypted_text).decode() -def decrypt(encrypted_text): - decrypted_text = cipher_suite.decrypt(encrypted_text).decode() - return decrypted_text +def print_encrypted_and_decrypted(encrypted_text, decrypted_text): + """Prints the encrypted and decrypted versions of the text.""" + print("Encrypted text:", encrypted_text) + print("Decrypted text:", decrypted_text) -versionToPass = configC(language_module) -config.read("./config/config.ini") -browser = config.get("main", "browser") -syskey = ( - platform.system() - + platform.release() - + "-AlfredVer-" - + versionToPass - + "-" - + platform.python_version() - + "-" - + browser -) - -encrypted_text = encrypt(syskey) -decrypted_text = decrypt(encrypted_text) +def save_encryption_info(config, private_key, sys_encrypted_key): + """Saves the private key and system encrypted key to the configuration file.""" + config.set("main", "privatekey", str(private_key)) + config.set("main", "syscrypt", str(sys_encrypted_key)) + with open("./config/config.ini", "w") as configfile: + config.write(configfile) + + +def main(): + """Main function to handle encryption and decryption tasks.""" + key = generate_encryption_key() + print("Encryption Key:", key.decode()) + cipher_suite = create_cipher(key) + sys_info = ( + platform.system() + + platform.release() + + "-AlfredVer-" + + versionToPass + + "-" + + platform.python_version() + + "-" + + config.get("main", "browser") + ) + encrypted_sys_info = encrypt_text(cipher_suite, sys_info) + decrypted_sys_info = decrypt_text(cipher_suite, encrypted_sys_info) + print_encrypted_and_decrypted(encrypted_sys_info.decode(), decrypted_sys_info) + save_encryption_info(config, key, encrypted_sys_info) + +if __name__ == "__main__": + main() diff --git a/update.py b/update.py index 5ae5274..fbcf7dd 100755 --- a/update.py +++ b/update.py @@ -1,213 +1,103 @@ import os import time - import requests -# variables -version = "" -alfred_version = "" -alfred_update_path = ( - "https://raw.githubusercontent.com/Alfredredbird/alfred/main/config/version.cfg" -) -alfred_install_path = "/alfred/" -gitfile_loc = "https://raw.githubusercontent.com/Alfredredbird/alfred/main/" -udfl = [] -dlfl = "" -fl = [] -fh = [] -dlcount = 0 - - -def chart(): - file_path = "config/udfl" - - with open(file_path, "r") as file: - lines = file.readlines() - third_length = (len(lines) + 2) // 3 - - max_length_left = max(len(line.strip()) for line in lines[:third_length]) - max_length_middle = max( - len(line.strip()) for line in lines[third_length : 2 * third_length] - ) - max_length_right = max(len(line.strip()) for line in lines[2 * third_length :]) - - print( - f"+{'-' * (max_length_left + 2)}+{'-' * (max_length_middle + 2)}+{'-' * (max_length_right + 2)}+" - ) - for left, middle, right in zip( - lines[:third_length], - lines[third_length : 2 * third_length], - lines[2 * third_length :], - ): - left = left.strip().ljust(max_length_left) - middle = middle.strip().ljust(max_length_middle) - right = right.strip().ljust(max_length_right) - print(f"| {left} | {middle} | {right} |") - print( - f"+{'-' * (max_length_left + 2)}+{'-' * (max_length_middle + 2)}+{'-' * (max_length_right + 2)}+" - ) - -def progress_bar_manual(dlcount, total_items, length=40, fill="#"): - percent_complete = (dlcount / total_items) * 100 - bar_length = length - filled_length = int(length * percent_complete / 100) - bar = fill * filled_length + "-" * (length - filled_length) - print(f"\rProgress: [{bar}] {percent_complete:.2f}% Complete", end="\r", flush=True) - - -def update(alfred_update_path): - global udfl # Ensure we use the global variable - - # READS ALFRED VERSION - with open("./config/version.cfg", "r") as fp: - version = fp.read() - - # gets the version number - try: - alfred_version = requests.get(alfred_update_path).text - print(alfred_version) - except requests.ConnectionError: - print("Failed To Fetch Updates. (-1)") +# Refactor global variables +config_version_path = "./config/version.cfg" +config_udfl_path = "./config/udfl" +alfred_update_path = "https://raw.githubusercontent.com/Alfredredbird/alfred/main/config/version.cfg" +alfred_install_path = "/alfred/" +gitfile_location = "https://raw.githubusercontent.com/Alfredredbird/alfred/main/" +dl_count = 0 - # checks for updates - if alfred_version != version: - print("Fetching Updates!") - with open("./config/udfl") as file: - udfl = [line.rstrip() for line in file] +class Updater: + def __init__(self): + self.version = self.read_file(config_version_path) + self.udfl_list = self.read_file_lines(config_udfl_path) - chart() + def read_file(self, file_path): + with open(file_path, 'r') as file: + return file.read().strip() - # deletes the files listed in udfl - for item in udfl: - if "/update.py" not in item: - try: - os.remove(item) - except FileNotFoundError: - print("Skipping: " + item) + def read_file_lines(self, file_path): + with open(file_path, 'r') as file: + return [line.strip() for line in file] - # downloads a new file manager copy + def save_file_from_url(self, url, destination): try: - time.sleep(3) - response = requests.get(gitfile_loc + "config/udfl") - with open("./config/udfl", "wb") as file: + response = requests.get(url, allow_redirects=True) + os.makedirs(os.path.dirname(destination), exist_ok=True) + with open(destination, 'wb') as file: file.write(response.content) - except requests.ConnectionError: - print("Failed To Fetch Update Files. (-2)") + return True + except Exception as e: + print(f"Error saving file from {url}: {e}") + return False + def update(self): try: - # reads the udfl file - with open("./config/udfl") as file: - fl = [line.rstrip() for line in file] - time.sleep(2) - print("Downloading Files") - - # downloads the files from udfl - for item in fl: - url = gitfile_loc + item + remote_version = requests.get(alfred_update_path).text.strip() + except requests.ConnectionError: + print("Failed to fetch updates. (-1)") + return + if remote_version != self.version: + self.process_update(remote_version) + else: + print("You're on the latest version!") + + def process_update(self, remote_version): + print("Fetching Updates!") + self.delete_files() + self.save_file_from_url(gitfile_location + 'config/udfl', config_udfl_path) + udfl = self.read_file_lines(config_udfl_path) + self.download_files(udfl) + self.verify_and_exec(udfl) + + def delete_files(self): + for file_path in self.udfl_list: + if "update.py" not in file_path: try: - response = requests.get(url, allow_redirects=True) - with open(item, "wb") as file: - file.write(response.content) - fl.remove(item) - dlcount += 1.90001 - progress_bar_manual(dlcount, len(udfl)) + os.remove(file_path) except FileNotFoundError: - print("Can't Find: " + item + " Skipping!") - except OSError: - print("Permission Error") - - # checks to see if the file exists, if not it reinstalls it - with open("./config/udfl") as file: - fh = [line.rstrip() for line in file] - - while True: - for item in fh: - if not os.path.exists(item): - response = requests.get( - gitfile_loc + item, allow_redirects=True - ) - with open(item, "wb") as file: - file.write(response.content) - fh.remove(item) - if not fh: # All files exist - print("Update Done!") - exec(open("brib.py").read()) - break - except requests.ConnectionError: - print("Failed To Download Update Files. (-3)") - else: - print("You're On The Latest Version!") - + print(f"Skipping: {file_path}") -def reinstall(gitfile_loc, progress_bar_func): - print("Reinstalling.....!") - - # Read update file list (udfl) and display chart - with open("./config/udfl") as file: - udfl = [line.rstrip() for line in file] - chart() - - # Delete the files listed in udfl - for item in udfl: - if "/update.py" not in item: - try: - os.remove(item) - except FileNotFoundError: - print(f"skipping: {item}") - - # Download a new file manager copy - try: - time.sleep(3) - response = requests.get(gitfile_loc + "config/udfl") - with open("./config/udfl", "wb") as file: - file.write(response.content) - except requests.ConnectionError: - print("Failed To Fetch Update Files. (-2)") - - # Download the files - try: - with open("./config/udfl") as file: - fl = [line.rstrip() for line in file] + def download_files(self, file_list): + global dl_count print("Downloading Files") - total_items = len(udfl) - - for item in fl: - url = gitfile_loc + item - try: - response = requests.get(url, allow_redirects=True) - os.makedirs(os.path.dirname(item), exist_ok=True) - with open(item, "wb") as file: - file.write(response.content) - dlcount += 1 - progress_bar_func(dlcount, total_items, length=40, fill="#") - except FileNotFoundError: - print(f"Can't Find: {item} Skipping!") - except OSError: - print("Permission Error") - - # Verify all files exist, and re-download missing files if necessary - with open("./config/udfl") as file: - fh = [line.rstrip() for line in file] - for item in fh: - if not os.path.exists(item): - response = requests.get(gitfile_loc + item, allow_redirects=True) - with open(item, "wb") as file: - file.write(response.content) - - if all(os.path.exists(item) for item in fh): - print("Reinstallation Complete!") - time.sleep(1) + for file_path in file_list: + url = gitfile_location + file_path + if self.save_file_from_url(url, file_path): + dl_count += 1 + self.progress_bar_manual(dl_count, len(file_list)) + + def verify_and_exec(self, file_list): + missing_files = [f for f in file_list if not os.path.exists(f)] + for file_path in missing_files: + self.save_file_from_url(gitfile_location + file_path, file_path) + if not missing_files: + print("Update Done!") exec(open("brib.py").read()) - except requests.ConnectionError: - print("Failed To Download Update Files. (-3)") + def progress_bar_manual(self, current, total, length=40, fill="#"): + percent = (current / total) * 100 + filled_length = int(length * percent / 100) + bar = fill * filled_length + '-' * (length - filled_length) + print(f"\rProgress: [{bar}] {percent:.2f}% Complete", end="\r", flush=True) + def reinstall(self): + print("Reinstalling.....!") + self.delete_files() + self.save_file_from_url(gitfile_location + 'config/udfl', config_udfl_path) + self.download_files(self.udfl_list) + self.verify_and_exec(self.udfl_list) +# Usage of the class choice = input("Update or reinstall? [U/r]: ").lower() +updater = Updater() if choice == "u": - update(alfred_update_path) + updater.update() elif choice == "r": - reinstall(gitfile_loc, progress_bar_manual) + updater.reinstall() else: print("Not sure what you meant... I'll ask later") From 5761e7c8e05c77a08512aa7be128f734b792f907 Mon Sep 17 00:00:00 2001 From: EliteGreyIT67 Date: Wed, 3 Jan 2024 04:58:07 +0000 Subject: [PATCH 4/6] clean up --- modules/crypt.py | 1 + update.py | 18 +++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/modules/crypt.py b/modules/crypt.py index c06cc9d..2ee1113 100644 --- a/modules/crypt.py +++ b/modules/crypt.py @@ -64,5 +64,6 @@ def main(): print_encrypted_and_decrypted(encrypted_sys_info.decode(), decrypted_sys_info) save_encryption_info(config, key, encrypted_sys_info) + if __name__ == "__main__": main() diff --git a/update.py b/update.py index fbcf7dd..d73f4f8 100755 --- a/update.py +++ b/update.py @@ -6,29 +6,32 @@ # Refactor global variables config_version_path = "./config/version.cfg" config_udfl_path = "./config/udfl" -alfred_update_path = "https://raw.githubusercontent.com/Alfredredbird/alfred/main/config/version.cfg" +alfred_update_path = ( + "https://raw.githubusercontent.com/Alfredredbird/alfred/main/config/version.cfg" +) alfred_install_path = "/alfred/" gitfile_location = "https://raw.githubusercontent.com/Alfredredbird/alfred/main/" dl_count = 0 + class Updater: def __init__(self): self.version = self.read_file(config_version_path) self.udfl_list = self.read_file_lines(config_udfl_path) def read_file(self, file_path): - with open(file_path, 'r') as file: + with open(file_path, "r") as file: return file.read().strip() def read_file_lines(self, file_path): - with open(file_path, 'r') as file: + with open(file_path, "r") as file: return [line.strip() for line in file] def save_file_from_url(self, url, destination): try: response = requests.get(url, allow_redirects=True) os.makedirs(os.path.dirname(destination), exist_ok=True) - with open(destination, 'wb') as file: + with open(destination, "wb") as file: file.write(response.content) return True except Exception as e: @@ -49,7 +52,7 @@ def update(self): def process_update(self, remote_version): print("Fetching Updates!") self.delete_files() - self.save_file_from_url(gitfile_location + 'config/udfl', config_udfl_path) + self.save_file_from_url(gitfile_location + "config/udfl", config_udfl_path) udfl = self.read_file_lines(config_udfl_path) self.download_files(udfl) self.verify_and_exec(udfl) @@ -82,16 +85,17 @@ def verify_and_exec(self, file_list): def progress_bar_manual(self, current, total, length=40, fill="#"): percent = (current / total) * 100 filled_length = int(length * percent / 100) - bar = fill * filled_length + '-' * (length - filled_length) + bar = fill * filled_length + "-" * (length - filled_length) print(f"\rProgress: [{bar}] {percent:.2f}% Complete", end="\r", flush=True) def reinstall(self): print("Reinstalling.....!") self.delete_files() - self.save_file_from_url(gitfile_location + 'config/udfl', config_udfl_path) + self.save_file_from_url(gitfile_location + "config/udfl", config_udfl_path) self.download_files(self.udfl_list) self.verify_and_exec(self.udfl_list) + # Usage of the class choice = input("Update or reinstall? [U/r]: ").lower() updater = Updater() From 7c9151daf298290b1db602884bb477ba687f31b0 Mon Sep 17 00:00:00 2001 From: EliteGreyIT67 Date: Wed, 3 Jan 2024 10:30:06 +0000 Subject: [PATCH 5/6] Bug fix --- modules/configcheck.py | 44 ++++++++++++++++++++++-------------------- modules/crypt.py | 40 ++++++++++++++++---------------------- 2 files changed, 40 insertions(+), 44 deletions(-) diff --git a/modules/configcheck.py b/modules/configcheck.py index 1195ebe..26126bd 100644 --- a/modules/configcheck.py +++ b/modules/configcheck.py @@ -18,12 +18,14 @@ def configC(language_module): if os.path.exists("./config/config.ini"): print(language_module.config1) else: + # If not found, alert the user and attempt to update print(language_module.error5) time.sleep(4) with open("./config/version.cfg", "w") as f: f.write(language_module.status3) exec(open("./update.py").read()) - + + # Check if update.py script exists if os.path.exists("./update.py"): print(language_module.config2) else: @@ -35,7 +37,7 @@ def configC(language_module): version = fp.read() return version - +# Get the color scheme from the config file def colorSchemeGrabber(config): print("Grabbing Color Configuration") try: @@ -47,7 +49,7 @@ def colorSchemeGrabber(config): print(f"Could not read configuration file: {e}") return Fore.RED - +# Delete __pycache__ directories def delete_pycache(root_dir): """ Recursively searches for and deletes __pycache__ folders within the specified directory. @@ -63,7 +65,7 @@ def delete_pycache(root_dir): # Delete the __pycache__ folder shutil.rmtree(pycache_path) - +# Ask user about update checks def ask_update_check(config, colorScheme, language_module): try: cfu = input(language_module.config4) @@ -79,7 +81,7 @@ def ask_update_check(config, colorScheme, language_module): outstanding_config_updates(config) exit(1) - +# Prompt user at random to enable updates def random_enable_updates(config, language_module): getNum = random.randint(1, 10) # asks the user if they want to enable updates @@ -95,7 +97,7 @@ def random_enable_updates(config, language_module): else: print(language_module.idk2) - +# Process various config-related tasks def configUpdateStuff(colorScheme, config, browser, language_module, argument): config.read("./config/config.ini") print_first_launch_messages(config, colorScheme, language_module) @@ -112,26 +114,26 @@ def configUpdateStuff(colorScheme, config, browser, language_module, argument): random_enable_updates(config, language_module) display_random_tip(config, language_module) - +# Display a random tip if enabled in config def display_random_tip(config, language_module): if config.get("Personalizations", "showtips") == "yes": # this gets the random tip to display on the screen randomTip = random.choice(open("./config/tips.txt").readlines()) print(randomTip) - +# Check if this is the first application launch def is_first_launch(config, browser, language_module): if config.get("main", "firstlaunch") == "yes": outstanding_config_updates(config, browser) - +# Perform outstanding config updates def outstanding_config_updates(config, browser=None): if browser and browser == "MSEdgeHTM": config.set("main", "browser", "Edge") config.set("main", "firstlaunch", "no") save_config(config) - +# Make random decisions/events at app launch def decide_random_events(config, colorScheme, language_module): x = random.randint(1, 4) if x == 3: @@ -139,7 +141,7 @@ def decide_random_events(config, colorScheme, language_module): elif x == 2: print(language_module.prompt4) - +# Print messages on the first launch def print_first_launch_messages(config, colorScheme, language_module): if config.get("main", "firstlaunch") == "yes": print( @@ -153,7 +155,7 @@ def print_first_launch_messages(config, colorScheme, language_module): print(language_module.prompt2) print() - +# Print a separator in command line interface def print_separator(): print( Fore.RESET @@ -162,30 +164,30 @@ def print_separator(): """ ) - +# Save the updated configuration def save_config(config): with open("./config/config.ini", "w") as f: config.write(f) - +# Print system keys from configuration def syskeys(config): print("Here are your system keys.") print(str(config.get("main", "privatekey"))) print(str(config.get("main", "syscrypt"))) - +# Get global default download path from configuration def globalPath(config): config.read("./config/config.ini") path = config.get("main", "defaultDlPath") return path - +# Clearing directory contents def dirDump(mydir): filelist = [f for f in os.listdir(mydir)] for f in filelist: os.remove(os.path.join(mydir, f)) - +# Create needed folders on startup def create_folders(folder_list, language_module): for folder in folder_list: if not os.path.exists(folder): @@ -195,7 +197,7 @@ def create_folders(folder_list, language_module): print(f"{language_module.config8}{folder}") -# this is the module that edits the configuration file. needs to be cleaned up tho +# VALID_CHOICES holds possible valid inputs for configuration VALID_CHOICES = { "checkforupdates": ["yes", "no"], "showtips": ["yes", "no"], @@ -205,7 +207,7 @@ def create_folders(folder_list, language_module): "colorscheme": ["RED", "GREEN", "BLUE", "WHITE", "YELLOW", "BLACK"], } - +# Display config options def display_options(config, section, language_module): print("Options:") print("=====================================================") @@ -224,12 +226,12 @@ def display_options(config, section, language_module): print(f"{language_module.configOptionB} ") print("=====================================================") - +# Update configuration with new values def update_config(config, section, option_key, new_value): config.set(section, option_key, str(new_value)) save_config(config) - +# Editor function to modify config settings def config_editor(config, language_module): selected_option_key = { "1": ("main", "checkforupdates"), diff --git a/modules/crypt.py b/modules/crypt.py index 2ee1113..1ac32d7 100644 --- a/modules/crypt.py +++ b/modules/crypt.py @@ -44,26 +44,20 @@ def save_encryption_info(config, private_key, sys_encrypted_key): config.write(configfile) -def main(): - """Main function to handle encryption and decryption tasks.""" - key = generate_encryption_key() - print("Encryption Key:", key.decode()) - cipher_suite = create_cipher(key) - sys_info = ( - platform.system() - + platform.release() - + "-AlfredVer-" - + versionToPass - + "-" - + platform.python_version() - + "-" - + config.get("main", "browser") - ) - encrypted_sys_info = encrypt_text(cipher_suite, sys_info) - decrypted_sys_info = decrypt_text(cipher_suite, encrypted_sys_info) - print_encrypted_and_decrypted(encrypted_sys_info.decode(), decrypted_sys_info) - save_encryption_info(config, key, encrypted_sys_info) - - -if __name__ == "__main__": - main() +key = generate_encryption_key() +print("Encryption Key:", key.decode()) +cipher_suite = create_cipher(key) +sys_info = ( + platform.system() + + platform.release() + + "-AlfredVer-" + + versionToPass + + "-" + + platform.python_version() + + "-" + + config.get("main", "browser") +) +encrypted_sys_info = encrypt_text(cipher_suite, sys_info) +decrypted_sys_info = decrypt_text(cipher_suite, encrypted_sys_info) +print_encrypted_and_decrypted(encrypted_sys_info.decode(), decrypted_sys_info) +save_encryption_info(config, key, encrypted_sys_info) From 122c8084d226e417466e96e511614263d6581581 Mon Sep 17 00:00:00 2001 From: EliteGreyIT67 Date: Sat, 6 Jan 2024 08:19:11 +0000 Subject: [PATCH 6/6] Refactor modules.py --- modules/modules.py | 149 +++++++++++++++++++-------------------------- 1 file changed, 62 insertions(+), 87 deletions(-) diff --git a/modules/modules.py b/modules/modules.py index 061c7ef..2e97918 100644 --- a/modules/modules.py +++ b/modules/modules.py @@ -40,83 +40,47 @@ def redirects1(modes, input1): def list_proxys(colorScheme): + # Dictionary to map proxy types to file names + proxy_types = { + "http": "http.txt", + "socks4": "socks4.txt", + "socks5": "socks5.txt", + } + input2 = input("TYPE: ⤷ ") - # check if the directory exists if input2 == "": lol = 1 - if input2 == "http": - if os.path.exists("./proxys/http.txt"): - file1 = open("./proxys/http.txt", "r") - Lines = file1.readlines() - - count = 0 - L = [Lines] - - for line in Lines: - count += 1 - print("Proxy {}: {}".format(count, line.strip())) + # Retrieve file name from dictionary + file_name = proxy_types.get(input2) + if file_name: + file_path = f"./proxys/{file_name}" + if os.path.exists(file_path): + with open(file_path, "r") as file: + Lines = file.readlines() + for count, line in enumerate(Lines, 1): + print(f"Proxy {count}: {line.strip()}") else: - print(colorScheme + "Cant Find The Proxy File!") - print(Fore.RESET) - - elif input2 == "socks4": - if os.path.exists("./proxys/socks4.txt"): - file1 = open("./proxys/socks4.txt", "r") - Lines = file1.readlines() - - count = 0 - L = [Lines] - - for line in Lines: - count += 1 - print("Proxy {}: {}".format(count, line.strip())) - else: - print(colorScheme + "Cant Find The Proxy File!") - print(Fore.RESET) - - elif input2 == "socks5": - if os.path.exists("./proxys/socks5.txt"): - file1 = open("./proxys/socks5.txt", "r") - Lines = file1.readlines() - - count = 0 - L = [Lines] - - for line in Lines: - count += 1 - print("Proxy {}: {}".format(count, line.strip())) - - else: - print(colorScheme + "Cant Find The Proxy File!") + print(colorScheme + f"Cant Find The Proxy File for {input2}!") print(Fore.RESET) + else: + # Case for invalid type + print(colorScheme + "Invalid proxy type!") + print(Fore.RESET) def read_save(colorScheme, slectpath): - if slectpath == "": - dir_path = Path.home() / "Downloads" - - file_name = "usernames.alfred" - file_path = os.path.join(dir_path, file_name) - if slectpath != "": - file_path = os.path.join(slectpath) - # check if the directory exists + # Determine file path based on the select_path input + file_path = Path.home() / "Downloads" / "usernames.alfred" if slectpath == "" else slectpath + + # Check if the file exists and read it if os.path.exists(file_path): - # reads the file - file = open(file_path, "r+") - file1 = open(file_path, "r") - Lines = file1.readlines() - - count = 0 - L = [Lines] - - for line in Lines: - count += 1 - print("Captured {}: {}".format(count, line.strip())) - - file.close() - + with open(file_path, "r") as file: + lines = file.readlines() + + for line_number, line in enumerate(lines, start=1): + print(f"Captured {line_number}: {line.strip()}") else: - print(colorScheme + "Cant Find The Save File!") + print(colorScheme + "Can't Find The Save File!") print(Fore.RESET) @@ -146,10 +110,10 @@ def ping(colorScheme): def qexit(): - exitInput = input("Exit? [Y/N]") - if exitInput == "Y" or exitInput == "y": + exitInput = input("Exit? [Y/N]").lower() + if exitInput == "y": exit(0) - if exitInput == "N" or exitInput == "n": + if exitInput == "n": print("Continuing....") @@ -175,13 +139,13 @@ def proxyCheck(colorScheme, modes, input1): print("") print(" Save Proxy To File?") - saveProxy = input(" [Y/n]? ⤷ ") - if saveProxy == "Y" or saveProxy == "y": + saveProxy = input(" [Y/n]? ⤷ ").lower() + if saveProxy == "y": with open("proxyList.txt", "a") as fp: fp.write(" \n" + input2 + ":" + input3) fp.close() - elif saveProxy == "N" or saveProxy == "n": + elif saveProxy == "n": print( "Continuing" + Fore.RED @@ -283,28 +247,28 @@ def darkAlfred(colorScheme, console, uname): if input1 != "": # if there is a problem with this code its prob this if "-tp" in input1: - torPassword = input("Tor Password: ⤷") + torPassword = input("Tor Password: ⤷").lower() if "-s" in input1: - input2 = input("Are You Sure? [Y/N]? ⤷ ") + input2 = input("Are You Sure? [Y/N]? ⤷ ").lower() if input2 == "": lol = 1 if input2 != "": - if input2 == "Y" or input2 == "y": - input3 = input("100% Sure? [Y/N]? ⤷ ") + if input2 == "y": + input3 = input("100% Sure? [Y/N]? ⤷ ").lower() if input2 != "": - if input2 == "Y" or input2 == "y": + if input2 == "y": # modes += input1 # inputnum += input2 print("Ok..") start = True - if input2 == "N" or input2 == "n": + if input2 == "n": test = False input1 = "" print("Ok! Returing To Alfred.") time.sleep(2) return test - if input2 == "N" or input2 == "n": + if input2 == "n": test = False input1 = "" print("Ok! Returing To Alfred.") @@ -314,7 +278,7 @@ def darkAlfred(colorScheme, console, uname): if "" in input1 and inputnum != "": test = True inputnum = "" - if start == True: + if start: try: with open("sites.json", "r") as f: for jsonObj in f: @@ -363,7 +327,7 @@ def darkAlfred(colorScheme, console, uname): ) f.write("[" + "+" + "] " + siteN + uname + "\n") - except ConnectionError(): + except ConnectionError: print("Connection Error!") @@ -482,21 +446,32 @@ def get_random_string(length): def emptyModule(): - """This Module is empty and does nothing. Its for when Alfred needs to return something""" + """ + This Module is empty and does nothing. Its for when Alfred needs to return something + """ return True def parse_args(): parser = argparse.ArgumentParser(description="Alfred OSINT Tool (Command-Line)") - parser.add_argument("-s", "--scan", action="store_true", help="Run Alfred scan") parser.add_argument( - "-u", "--username", help="Specify target username(s) (comma-separated)" + "-s", "--scan", + action="store_true", + help="Run Alfred scan") + parser.add_argument( + "-u", "--username", + type=str, + help="Specify target username(s) (comma-separated)" ) parser.add_argument( - "-f", "--fast", action="store_true", help="Run Alfred with a fast scan" + "-f", "--fast", + action="store_true", + help="Run Alfred with a fast scan" ) parser.add_argument( - "-w", "--webscrape", action="store_true", help="Run Alfred with the webscraper" + "-w", "--webscrape", + action="store_true", + help="Run Alfred with the webscraper" ) return parser.parse_args()