Page 1 of 1

[SOLVED] Script proposal for RustDesk

Published: August 8, 2024 - 11:11
by jlatieule
Good morning,


As a replacement for TeamViewer, we use a RustDesk server accessible only to our workstations. It's a private relay.
For installing a private relay, you have a great installation and update script on https://github.com/techahold/rustdeskinstall
I need to update all clients to the new version.
For this purpose, I created the following package (see code at the end of the message)... installation is done using the EXE format: rustdesk-1.2.7-x86_64.exe

After installation, I modify two options before restarting the service.
This section is completely unoptimized, and I've commented on what's missing
However, since RustDesk handles it well (multiple test scenarios), I'll stop there for now

The update_package, uninstall, and audit files are missing

Denis or Simon, could you take ownership of this and add it to the store so that it can be reused by others?
I certainly assume that you will be more comfortable than me with finalizing the "options" section more neatly and with managing the update_package (I have indicated the URL to query)

Thank you in advance

Code: Select all

# -*- coding: utf-8 -*-
from setuphelpers import *
import time, string, secrets

r"""
Usable WAPT package functions: install(), uninstall(), session_setup(), audit(), update_package()

"""
# Declaring global variables - Warnings: 1) WAPT context is only available in package functions; 2) Global variables are not persistent between calls

# Création d'un mot de passe aléatoire
alphabet = string.ascii_letters + string.digits
rustdesk_pw = ''.join(secrets.choice(alphabet) for i in range(12))

# Configuration réseau pour RustDesk à importer
# Si vide ou invalide, la configuration réseau restera inchangée
rustdesk_cfg = "METTEZ-VOTRE-CONFIG-ENTRE-LES-GUILLEMETS"

def install():
    # Récupération de l'exécutable
    bin_name = glob.glob("rustdesk-*.exe")[0]

    # Désactivé car pas de détection de fin d'installation
##    install_exe_if_needed(
##        bin_name,
##        silentflags="--silent-install",
##        key="RustDesk",
##        min_version=control.get_software_version(),
##    )
    # Méthode manuelle
    # Si n'est pas installé ou version est inférieure à celle du paquet
    if ( not installed_softwares ('rustdesk') or
    Version(installed_softwares('rustdesk')[0]["version"]) < Version(control['version'].split('-',1)[0]) ):
        print("Installation de %s %s" % ( control['name'], control['version'].split('-',1)[0] ) )
        # Timeout pour sortir sans erreur... ajouter une pause de 10s si on n'utilise plus cette méthode
        run_notfatal( '%s --silent-install' % (bin_name), timeout=15 )
    else:
        print("%s %s est déjà installé" % ( control['name'], control['version'].split('-',1)[0] ) )

    # Récupération du dossier d'installation
    software = installed_softwares ('rustdesk')
    install_location = software[0]["install_location"]

    # Exécution ou installation du service
    if service_installed ("rustdesk"):
        if not service_is_running ("rustdesk"):
            print ('Démarrage du service')
            service_start('rustdesk')
    else:
        print ("Installation du service RustDesk")
        run_notfatal( '"%s\\rustdesk.exe" --install-service -wait -Verbose' % (install_location), timeout = 20 )

    print("Patientez quelques secondes avant que l'installation se poursuive")
    time.sleep(10)

    print("Application de la configuration réseau")
    run_notfatal( '"%s\\rustdesk.exe" --config %s' % (install_location, rustdesk_cfg) )
    print("Définition d'un mot de passe permanent aléatoire")
    run( '"%s\\rustdesk.exe" --password %s' % (install_location, rustdesk_pw) )
    # ID de RustDesk
    rustdesk_id = run_notfatal( '"%s\\rustdesk.exe" --get-id' % (install_location) )

    # Arrêt du service Rustdesk pour modifications des options
    if service_installed("rustdesk"):
        if service_is_running("rustdesk"):
            print("Arrêt du service Rustdesk")
            service_stop("rustdesk")

    # Ajout d'option personnalisé à la configuration
    # inifile_writestring ne peut pas être utiliser suite à mauvaise en-tête dans le fichier
    # En cas de ligne en doublon dans le fichier RustDesk2.toml, les dernières seront prise en compte... mais pas toujours !!!
    # Point d'amélioration :
        # Supprimer les fichier %appdata%\RustDesk\config de tous les profile
        # Chercher et remplacer les chaînes concernée
        # Si absent, créer les chaînes au lieu de le faire systématiquement
    toml = makepath("c:", "Windows", "ServiceProfiles", "LocalService", "AppData", "Roaming", "RustDesk", "config", "RustDesk2.toml")
    f = open( toml, 'a')
    f.write("\n" + "direct-server = 'Y'")
    f.write("\n" + "direct-access-port = '21118'")
    f.close

    # Redémarrage du service Rustdesk
    if service_installed("rustdesk"):
        if service_is_stopped("rustdesk"):
            print("Démarrage du service RustDesk")
            service_start("rustdesk")
    else:
        print ("Installation du service RustDesk")
        run_notfatal( '"%s\\rustdesk.exe" --install-service -wait -Verbose' % (install_location), timeout = 20 )

    # Retour sur la console de l'ID et du mot de passe permanent
    print ( "-------------------" )
    print ( "ID RustDesk : %s" % rustdesk_id )
    print ( "Mot de passe : %s" % rustdesk_pw )
    print ( "-------------------" )



def session_setup():
    # Créer le session_setup



def update_package():
    # Créer l'update package
    # curl latest sur https://www.github.com//rustdesk/rustdesk/releases/latest
    # fichier lastest avec $RDLATEST sur https://github.com/rustdesk/rustdesk/releases/download/$RDLATEST/rustdesk-$RDLATEST-x86_64.exe



def uninstall():
    # Créer l'uninstall



def audit():
    # Créer l'audit
    # Vérifier si service fonctionne
    # Vérifier configuration dans makepath("c:", "Windows", "ServiceProfiles", "LocalService", "AppData", "Roaming", "RustDesk", "config", "RustDesk2.toml")



Re: Script proposal for RustDesk

Published: August 14, 2024 - 09:34
by rmaurisso
Hello,
thank you @jlatieule for this script.
When using external tools in wapt, is it possible to use "rustdesk_id" as an argument? This would simplify the connection to the selected computer (as TightVNC would).
Thank you.

Re: Script proposal for RustDesk

Published: August 14, 2024 - 8:50 PM
by jlatieule
For now, I don't know how to retrieve the ID displayed in the installation logs to feed into wapt.

By default, I've enabled IP address-based login. It works perfectly with external wapt tools.

P.S.: GDPR reminder: no connection without the user's consent. The permanent password available in the logs is only for system maintenance when no user is logged in.

Re: Script proposal for RustDesk

Published: August 22, 2024 - 6:05 PM
by sfonteneau
Hello @jlatieule,

thank you for your suggestion.

I've started working on RustDesk.

There are three packages:

tis-rustdesk-server (to install the RustDesk server on Linux or Windows)

, tis-rustdesk (to install the RustDesk agent on Linux, Windows, or Mac without configuration),

and tis-rustdesk-config-template (configures the RustDesk agent; requires running an update package to provide the configuration).

The random password is transmitted in encrypted form.

We'll look into adding a small native integration to the right-click menu to simplify its use. ;)

Re: Script proposal for RustDesk

Published: August 22, 2024 - 6:44 PM
by jlatieule
Excellent, Simon! I'm very curious to see the server side of things. We had to do some research to optimize the installation on Debian.

When I get back from vacation, I can send you my server installation procedure; perhaps you'll find some tips on how to set it up... let me know which communication method you prefer.

PS: When I was an IT specialist at Victor Hugo middle school in Narbonne, I contributed to the forum under the pseudonym "percherie." I imagine you remember me, and like back then, I sincerely believe in sharing to help the community move forward.

Re: Script proposal for RustDesk

Published: August 23, 2024 - 09:57
by sfonteneau
jlatieule wrote: August 22, 2024 - 6:44 PM PS: When I was an ICT specialist at Victor Hugo Middle School in Narbonne, I contributed to the forum under the pseudonym percherie. I imagine you remember me, and like back then, I sincerely believe in sharing to move the collective forward.
Of course I remember ;)If you're ever in Nantes, come see us, I'd love to hear from you (I'm not often in Narbonne) :D )
jlatieule wrote: August 22, 2024 - 6:44 PM I'm very curious to see the server side. We had to do some research to optimize the installation on Debian.
Nothing extraordinary, I just reproduced the Python script found in their documentation and here: https://github.com/techahold/rustdeskin ... install.sh

And for the Windows server, I just replaced nssm with angelize

And for the rustdesk macos client, it's not great in my tests, we'll probably have to come back to it.

Re: Script proposal for RustDesk

Published: September 5, 2024 - 4:10 PM
by rmaurisso
Hello,
thank you both.
It works well for external tools with the IP address and for the template. ;)

Re: Script proposal for RustDesk

Published: September 9, 2024 - 3:46 PM
by dcardon
Hello Régis,

thank you for the feedback. :-) I'm marking the topic as resolved.

Regards,

Denis