diff --git a/setup.py b/setup.py index 087546f..5134341 100644 --- a/setup.py +++ b/setup.py @@ -1,46 +1,103 @@ -# -*- coding: utf-8 -*- -from setuphelpers import * -import subprocess -from waptcrypto import * - - -def install(): - # Installing the software - install_exe_if_needed( - "rustdesk.exe", - silentflags="--silent-install", - key="RustDesk", - min_version=control.get_software_version(), - ) - # Create the uninstall key - uninstallkey.clear() - - -def uninstall(): - run_notfatal(r'"C:\Program Files\RustDesk\RustDesk.exe" --uninstall') - remove_tree( - r"C:\Windows\ServiceProfiles\LocalService\AppData\Roaming\RustDesk", - ignore_errors=True, - ) - - -def audit(): - - ## Pour ajouter dans les outils externe wapt : nom :Rustdesk, Executable : C:\Program Files\RustDesk\rustdesk.exe , --connect {{host_audit/RustDesk/id/value}} - def get_rustdesk_id(): - # Run the command and capture its output - result = subprocess.run(["C:\\Program Files\\RustDesk\\rustdesk.exe", "--get-id"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) - # Check if the command was successful - if result.returncode == 0: - # Store the output in a variable - rustdesk_id = result.stdout - final_id = rustdesk_id.rstrip() - # Print the output for verification - print(final_id) - else: - # If there was an error, print the error message - print("Error:", result.stderr) - return final_id - - WAPT.write_audit_data("RustDesk", "id", get_rustdesk_id(), max_count=3) - return "OK" +# -*- coding: utf-8 -*- +from setuphelpers import * +import subprocess +from waptcrypto import * +import string +import random +import platform + +try: + import waptcrypto + + if "encrypted_data_str" in dir(waptcrypto): + from waptcrypto import encrypted_data_str as rsa_encrypted_data_str +except: + pass + + +def install(): + # Installing the software + install_exe_if_needed( + "rustdesk.exe", + silentflags="--silent-install", + key="RustDesk", + min_version=control.get_software_version(), + ) + # Create the uninstall key + uninstallkey.clear() + + +def uninstall(): + run_notfatal(r'"C:\Program Files\RustDesk\RustDesk.exe" --uninstall') + remove_tree( + r"C:\Windows\ServiceProfiles\LocalService\AppData\Roaming\RustDesk", + ignore_errors=True, + ) + + +def audit(): + + ## Pour ajouter dans les outils externe wapt : nom :Rustdesk, Executable : C:\Program Files\RustDesk\rustdesk.exe , --connect {{host_audit/RustDesk/id/value}} + def get_rustdesk_id(): + # Run the command and capture its output + result = subprocess.run( + ["C:\\Program Files\\RustDesk\\rustdesk.exe", "--get-id"], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True, + ) + # Check if the command was successful + if result.returncode == 0: + # Store the output in a variable + rustdesk_id = result.stdout + final_id = rustdesk_id.rstrip() + # Print the output for verification + print(final_id) + else: + # If there was an error, print the error message + print("Error:", result.stderr) + return final_id + + WAPT.write_audit_data("RustDesk", "id", get_rustdesk_id(), max_count=3) + + randompassword = password_generator( + size=random.randint(10, 16), chars=string.ascii_letters + string.digits + ) + change_rustdesk_password(randompassword) + WAPT.write_audit_data_if_changed( + "RustDesk", + "password", + rsa_encrypted_data_str(randompassword, [WAPT.public_certs_dir]), + max_count=3, + ) + + return "OK" + + +def password_generator(size=16, chars=string.ascii_letters + string.digits): + """ + Returns a string of random characters, useful in generating temporary + passwords for automated password resets. + + size: default=8; override to provide smaller/larger passwords + chars: default=A-Za-z0-9; override to provide more/less diversity + + Credit: Ignacio Vasquez-Abrams + Source: http://stackoverflow.com/a/2257449 + """ + return "".join(random.choice(chars) for i in range(size)) + + +def change_rustdesk_password(password): + system = platform.system() + if system == "Windows": + rustdesk_bin_path = makepath( + "C:", '"Program Files"', "rustdesk", "rustdesk.exe" + ) + # elif system == "Linux": + # rustdesk_bin_path = os.path.expanduser("/root/.config/rustdesk/RustDesk.toml") + # elif system == "Darwin": + # rustdesk_bin_path = os.path.expanduser("/Library/Preferences/com.carriez.RustDesk/RustDesk.toml") + else: + raise ValueError(f"Unsupported operating system: {system}") + run(f"{rustdesk_bin_path} --password {password}")