Actualiser setup.py
This commit is contained in:
59
setup.py
59
setup.py
@@ -2,6 +2,17 @@
|
||||
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():
|
||||
@@ -29,7 +40,12 @@ 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)
|
||||
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
|
||||
@@ -43,4 +59,45 @@ def audit():
|
||||
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}")
|
||||
|
||||
Reference in New Issue
Block a user