Actualiser setup.py

This commit is contained in:
2024-04-22 09:03:06 +00:00
parent 08178a1fa5
commit b5bdaf5d6d

149
setup.py
View File

@@ -1,46 +1,103 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from setuphelpers import * from setuphelpers import *
import subprocess import subprocess
from waptcrypto import * from waptcrypto import *
import string
import random
def install(): import platform
# Installing the software
install_exe_if_needed( try:
"rustdesk.exe", import waptcrypto
silentflags="--silent-install",
key="RustDesk", if "encrypted_data_str" in dir(waptcrypto):
min_version=control.get_software_version(), from waptcrypto import encrypted_data_str as rsa_encrypted_data_str
) except:
# Create the uninstall key pass
uninstallkey.clear()
def install():
def uninstall(): # Installing the software
run_notfatal(r'"C:\Program Files\RustDesk\RustDesk.exe" --uninstall') install_exe_if_needed(
remove_tree( "rustdesk.exe",
r"C:\Windows\ServiceProfiles\LocalService\AppData\Roaming\RustDesk", silentflags="--silent-install",
ignore_errors=True, key="RustDesk",
) min_version=control.get_software_version(),
)
# Create the uninstall key
def audit(): uninstallkey.clear()
## 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(): def uninstall():
# Run the command and capture its output run_notfatal(r'"C:\Program Files\RustDesk\RustDesk.exe" --uninstall')
result = subprocess.run(["C:\\Program Files\\RustDesk\\rustdesk.exe", "--get-id"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) remove_tree(
# Check if the command was successful r"C:\Windows\ServiceProfiles\LocalService\AppData\Roaming\RustDesk",
if result.returncode == 0: ignore_errors=True,
# Store the output in a variable )
rustdesk_id = result.stdout
final_id = rustdesk_id.rstrip()
# Print the output for verification def audit():
print(final_id)
else: ## Pour ajouter dans les outils externe wapt : nom :Rustdesk, Executable : C:\Program Files\RustDesk\rustdesk.exe , --connect {{host_audit/RustDesk/id/value}}
# If there was an error, print the error message def get_rustdesk_id():
print("Error:", result.stderr) # Run the command and capture its output
return final_id result = subprocess.run(
["C:\\Program Files\\RustDesk\\rustdesk.exe", "--get-id"],
WAPT.write_audit_data("RustDesk", "id", get_rustdesk_id(), max_count=3) stdout=subprocess.PIPE,
return "OK" 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}")