tis-meshagent-template

0.2.1.3-82
Run update-package-sources then build-upload and deploy
1069 téléchargements
Télécharger
Voir le résultat de la construction Voir l'analyse de VirusTotal
tis-meshagent-template icon
  • package : tis-meshagent-template
  • name : Mesh Agent Template
  • version : 0.2.1.3-82
  • categories : System and network
  • maintainer : WAPT Team,Tranquil IT,Jimmy PELÉ,Hubert TOUVET
  • installed_size : 4158016
  • editor :
  • licence : Apache 2.0
  • signature_date : 2022-09-24T18:02:30.955468
  • size : 13.39 Ko
  • locale : all
  • target_os : windows
  • impacted_process : MeshAgent,meshagent
  • architecture : all
  • Conflits :
package           : tis-meshagent-template
version           : 0.2.1.3-82
architecture      : all
section           : base
priority          : optional
name              : Mesh Agent Template
categories        : System and network
maintainer        : WAPT Team,Tranquil IT,Jimmy PELÉ,Hubert TOUVET
description       : Run update-package-sources then build-upload and deploy
depends           : 
conflicts         : tis-mesh_agent_service
maturity          : PROD
locale            : all
target_os         : windows
min_wapt_version  : 2.1
sources           : 
installed_size    : 4158016
impacted_process  : MeshAgent,meshagent
description_fr    : 
description_pl    : 
description_de    : 
description_es    : 
description_pt    : 
description_it    : 
description_nl    : 
description_ru    : 
audit_schedule    : 
editor            : 
keywords          : 
licence           : Apache 2.0
homepage          : 
package_uuid      : 2ef68660-c913-412e-a5e2-0d386b713f56
valid_from        : 
valid_until       : 
forced_install_on : 
changelog         : 
min_os_version    : 
max_os_version    : 
icon_sha256sum    : 75919930641ca94d1e743ff8f41ac4f2f853ca4a4582c9bac1e8aa749fd735c1
signer            : Tranquil IT
signer_fingerprint: 8c5127a75392be9cc9afd0dbae1222a673072c308c14d88ab246e23832e8c6bb
signature         : CiV7tW0yNamtZF+2/q2iwvE2MrcpSIFnO4UzLNAJ4wM7ErhP9YIlvEtrtb4sOlQ8TnMxVi2DkyjMRq1vbJeFctgzNLLbcDQAwWsTdnu0ma9m3y1M9BtN5tUqr6jbiuTjoPA3PvlA0hRWQ7ji4R4T9ZU0aO8PbvjGryQKF5/KcArdK5+0to6hlQGmOTobVhXrBtTLVJdWK2v176hkGDxZQgdjuyQnGKDYFLvJvwevJm0fGhuQ9YXipY10QsQcHa6XsyGIn1h1SCC5mkEjK5TsdUfmKruq/u1Vw4xSF7QkI/TWJCgJsmLyq/iwIjzR4OjOPovTvQ9Z2j5dS0/N1rb41g==
signature_date    : 2022-09-24T18:02:30.955468
signed_attributes : package,version,architecture,section,priority,name,categories,maintainer,description,depends,conflicts,maturity,locale,target_os,min_wapt_version,sources,installed_size,impacted_process,description_fr,description_pl,description_de,description_es,description_pt,description_it,description_nl,description_ru,audit_schedule,editor,keywords,licence,homepage,package_uuid,valid_from,valid_until,forced_install_on,changelog,min_os_version,max_os_version,icon_sha256sum,signer,signer_fingerprint,signature_date,signed_attributes
# -*- coding: utf-8 -*-
from setuphelpers import *

config_file = "mesh-conf.json"


def install():
    # Declaring local variables
    package_version = control.get_software_version()
    app_name = control.name
    mesh_config_dict = json_load_file(get_persistent_package_file(config_file))
    if mesh_config_dict["mesh_companyName"] != mesh_config_dict["mesh_serviceName"]:
        app_dir = makepath(programfiles, mesh_config_dict["mesh_companyName"], mesh_config_dict["mesh_serviceName"])
    else:
        app_dir = makepath(programfiles, mesh_config_dict["mesh_companyName"])
    app_path = makepath(app_dir, mesh_config_dict["mesh_fileName"] + ".exe")
    app_uninstallkey = mesh_config_dict["mesh_serviceName"]

    if iswin64():
        bin_name = glob.glob("*64-*.exe")[0]
    else:
        bin_name = glob.glob("*32-*.exe")[0]

    if not running_as_system():
        print(
            f'WARNING: {app_name} will NOT be installed as SYSTEM account, that will cause issues since it is installed as user: {get_current_user()} ("Waiting for key: {mesh_config_dict["mesh_serviceName"]}" will not complete), please uninstall it manually before deployment'
        )

    def get_app_version(key):
        return get_version_from_binary(app_path, "FileVersion")

    # Installing the software
    install_exe_if_needed(
        bin_name,
        silentflags="-fullinstall",
        key=app_uninstallkey,
        min_version=package_version,
        get_version=get_app_version,
        accept_returncodes=[0, 1, 3010, 3221226356],
    )

    # Adding QuietUninstallString in registry for software
    quiet_uninstall_string = f'"{app_path}" {"-fulluninstall"}'
    wait_uninstallkey_present(app_uninstallkey)
    register_uninstall(app_uninstallkey, quiet_uninstall_string=quiet_uninstall_string)


def uninstall():
    # Declaring local variables
    mesh_config_dict = json_load_file(get_persistent_package_file(config_file))
    app_dir = makepath(programfiles, mesh_config_dict["mesh_companyName"])
    app_uninstallkey = mesh_config_dict["mesh_serviceName"]

    # Removing remaining folders if possible
    if isdir(app_dir):
        killalltasks(control.get_impacted_process_list())
        wait_uninstallkey_absent(app_uninstallkey)
        print("Removing: %s" % (app_dir))
        remove_tree(app_dir)


def audit():
    # Declaring local variables
    mesh_config_dict = json_load_file(get_persistent_package_file(config_file))
    if mesh_config_dict["mesh_companyName"] != mesh_config_dict["mesh_serviceName"]:
        app_dir = makepath(programfiles, mesh_config_dict["mesh_companyName"], mesh_config_dict["mesh_serviceName"])
    else:
        app_dir = makepath(programfiles, mesh_config_dict["mesh_companyName"])
    app_path = makepath(app_dir, mesh_config_dict["mesh_fileName"] + ".exe")
    app_name = mesh_config_dict["mesh_displayName"]
    mesh_regkey = r"SOFTWARE\Open Source\%s" % mesh_config_dict["mesh_serviceName"]
    meshserverurl = registry_readstring(HKEY_LOCAL_MACHINE, mesh_regkey, "MeshServerUrl")
    nodeid = registry_readstring(HKEY_LOCAL_MACHINE, mesh_regkey, "NodeId")
    remotedesktopurl = "https://%s:%s/?viewmode=11&gotonode=%s&hide=25" % (mesh_config_dict["mesh_server"], mesh_config_dict["mesh_port"], nodeid)

    print(remotedesktopurl)
    """
    // SERVICE_STOPPED				  1    The service is not running.
    // SERVICE_START_PENDING		  2    The service is starting.
    // SERVICE_STOP_PENDING			  3    The service is stopping.
    // SERVICE_RUNNING				  4    The service is running.
    // SERVICE_CONTINUE_PENDING		  5    The service continue is pending.
    // SERVICE_PAUSE_PENDING		  6    The service pause is pending.
    // SERVICE_PAUSED				  7    The service is paused.
    // SERVICE_NOT_INSTALLED		100    The service is not installed.
    """
    # nodeid = run([app_path, "-nodeid"]).splitlines()[0]
    # run(f'"{app_path}" -exec "console.log(_MSH().meshServiceName);process.exit();"')
    state = run(f'"{app_path}" {"state"}')  # , accept_returncodes=[0, 1, 2, 3, 4, 5, 6, 7, 100]
    state_str = state.strip()
    print("%s service state is:" % app_name)
    print(state_str)
    if state_str.lower() == "RUNNING".lower():
        result = "OK"
    elif state_str.lower() == "NOT INSTALLED".lower():
        result = "WARNING"
        print(
            'INFO: "Not installed" Service state may be incorrect status, you may need to update your Mesh Server and Mesh Agent (more info here: https://github.com/Ylianst/MeshAgent/issues/87)'
        )
    else:
        result = "WARNING"

    try:
        WAPT.write_audit_data_if_changed("mesh", "meshserverurl", meshserverurl, keep_days=365)
        WAPT.write_audit_data_if_changed("mesh", "nodeid", nodeid, keep_days=365)
        WAPT.write_audit_data_if_changed("mesh", "agenthash", registry_readstring(HKEY_LOCAL_MACHINE, mesh_regkey, "AgentHash"), keep_days=365)
        WAPT.write_audit_data_if_changed("mesh", "remotedesktopurl", remotedesktopurl, keep_days=365)
    except:
        print("ERROR: write_audit_data failed")
        result = "ERROR"

    return result


def get_persistent_package_file(fname):
    if isdir(makepath(os.getcwd(), "WAPT", "persistent")):
        return makepath(os.getcwd(), "WAPT", "persistent", fname)
    else:
        return makepath(WAPT.persistent_root_dir, control.package_uuid, fname)


def get_persistent_package_dir():
    if isdir(makepath(os.getcwd(), "WAPT", "persistent")):
        return makepath(os.getcwd(), "WAPT", "persistent")
    else:
        return makepath(WAPT.persistent_root_dir, control.package_uuid)
# -*- coding: utf-8 -*-
from setuphelpers import *
import waptguihelper
import json


def get_persistent_package_file(fname):
    if isdir(makepath(os.getcwd(), "WAPT", "persistent")):
        return makepath(os.getcwd(), "WAPT", "persistent", fname)
    else:
        return makepath(WAPT.persistent_root_dir, control.package_uuid, fname)


config_file = "mesh-conf.json"
mesh_config_dict_old = json_load_file(get_persistent_package_file(config_file))


def update_package():
    # Declaring local variables
    package_updated = False

    # Gathering informations for the package
    if "template" in control.package:
        package = waptguihelper.input_dialog(
            control.package, "Please change the template suffix with a term corresponding to your Mesh Agent", control.package
        )
        control.package = package
        control.save_control_to_wapt()

    dialog_response = waptguihelper.grid_dialog(
        "Adapt your Agent parameters (corresponding to: meshcentral-data/config.json)",
        format_dict_to_grid(mesh_config_dict_old),
        0,
        '{"columns":[{"propertyname":"parameter","datatype":"String","required":false,"readonly":true,"width":153},{"propertyname":"value","datatype":"String","required":false,"readonly":false,"width":172}]}',
    )
    json_write_file(get_persistent_package_file(config_file), format_grid_to_dict(dialog_response))
    mesh_config_dict = json_load_file(get_persistent_package_file(config_file))

    # Getting binaries
    if glob.glob("*.exe"):
        ask_for_binaries = waptguihelper.message_dialog(control.package, "Do you want to deploy new Mesh Agent binaries ?", waptguihelper.MB_YESNO)
    else:
        ask_for_binaries = 6

    # Deleting binaries
    if ask_for_binaries == 6:
        for f in glob.glob("*.exe") + glob.glob("*.msi"):
            print("Removing: %s" % f)
            remove_file(f)

        bin_path_x86 = waptguihelper.filename_dialog(
            "Please provide x86 Mesh Agent",
            "",
            "%s32-%s.exe" % (mesh_config_dict["mesh_fileName"].replace(" ", ""), mesh_config_dict["mesh_deviceGroup"].replace(" ", "")),
            "EXE Files|*.exe",
        )
        bin_path_x64 = waptguihelper.filename_dialog(
            "Please provide x64 Mesh Agent",
            "",
            "%s64-%s.exe" % (mesh_config_dict["mesh_fileName"].replace(" ", ""), mesh_config_dict["mesh_deviceGroup"].replace(" ", "")),
            "EXE Files|*.exe",
        )
        bin_name_x64 = bin_path_x64.split(os.sep)[-1].split(".")[0]
        if bin_path_x86:
            bin_name_x86 = bin_path_x86.split(os.sep)[-1].split(".")[0]
            filecopyto(bin_path_x86, basedir)
            if not bin_name_x86 in control.impacted_process:
                control.impacted_process = control.impacted_process + "," + bin_name_x86
                control.save_control_to_wapt()
        filecopyto(bin_path_x64, basedir)
        if not bin_name_x64 in control.impacted_process:
            control.impacted_process = control.impacted_process + "," + bin_name_x64
            control.save_control_to_wapt()

        # Changing version of the package
        version = get_file_properties(bin_path_x64).get("FileVersion", control.get_software_version())
        if Version(version) > Version(control.get_software_version()):
            print("Software version updated (from: %s to: %s)" % (control.get_software_version(), Version(version)))
            package_updated = True
        else:
            print("Software version up-to-date (%s)" % Version(version))
        control.set_software_version(version)
        control.save_control_to_wapt()
    if not mesh_config_dict["mesh_fileName"] in control.impacted_process:
        control.impacted_process = control.impacted_process + "," + mesh_config_dict["mesh_fileName"]
        control.save_control_to_wapt()

    # Editing control
    if not "template" in control.package:
        control.name = mesh_config_dict["mesh_displayName"]
        control.description = mesh_config_dict["mesh_displayName"]
        control.save_control_to_wapt()

    # Validating or not update-package-sources
    return package_updated


def format_dict_to_grid(dict_data, key_name="parameter", value_name="value"):
    dict_list_data = []
    for section in dict_data:
        dict_list_data.append({key_name: section, value_name: dict_data[section]})
    return json.dumps(dict_list_data)


def format_grid_to_dict(dict_list_data, key_name="parameter", value_name="value"):
    dict_data = {}
    for entry in dict_list_data:
        dict_data.update({entry[key_name]: entry[value_name]})
    return dict_data
4cd62dada82b6bcb161275f1b94f6da8e1655ffc2ec675e8be9e2f41def234fa : setup.py
a1e856f29393cb2906d5431d3dc5da639291a8885412907ab9c1a46ff122ae7d : update_package.py
75919930641ca94d1e743ff8f41ac4f2f853ca4a4582c9bac1e8aa749fd735c1 : WAPT/icon.png
df263c72463ec99b91797ea95d4086c5f618f6b18d1d82eaa851eb186491810d : WAPT/persistent/mesh-conf.json
a5a97261381e1d0ad46ee15916abec9c2631d0201f5cc50ceb0197a165a0bbbf : WAPT/certificate.crt
c93319868827d9ec45281e366ae3118b62d3138ddb93892f2088e7976364b36f : WAPT/changelog.txt
5e65a46f894a3419f62e9b3ff00dbfb77a07c8559bab4978bbde603c7d648ac1 : luti.json
ee20631645baa8d961c83e98bb345dcdf5e33818593a0f667f61d0eeec3e6ea2 : WAPT/control
0.2.1.3-81

Package can now be fully customized interactively with update_package
Configuration is now based on JSON file "mesh-conf.json" graphically edited in update_package
Now using persistent folder to call JSON file locally with get_persistent_package_file()
Autofilling impacted_process
Fix uninstall by adding QuietUninstallString 
Reverse waptguihelper.grid_dialog for easy editing
Now asking for port instead of mixing it with server