tis-meshagent-template

0.2.1.3-65
Mesh Agent Service
23 downloads
Download
View on luti logo
tis-meshagent-template icon

  Description 

  • package : tis-meshagent-template
  • version : 0.2.1.3-65
  • architecture : all
  • categories : System and network
  • maintainer : WAPT Team,Tranquil IT,Jimmy PELÉ,Hubert TOUVET
  • description : Mesh Agent Service
  • locale :
  • target_os : windows
  • min_wapt_version : 2.0
  • sources :
  • installed_size : 4158016
  • impacted_process : MeshAgent
  • description_fr :
  • description_pl :
  • description_de :
  • description_es :
  • description_pt :
  • description_it :
  • description_nl :
  • description_ru :
  • editor :
  • licence : Apache 2.0
  • signature_date : 2022-02-24T04:11:55.396816
  • Conflicts :

  Setup.py 

# -*- coding: utf-8 -*-
from setuphelpers import *
import time

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

    // 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.

Place your Mesh Agent binaries in the package and adapt mesh_ variables corresponding to your Mesh Central configuration (on a minimal configuration you may just have to edit mesh_deviceGroup variable corresponding to the device group you defined).

"""
# Declaring global variables - Warnings: 1) WAPT context is only available in package functions; 2) Global variables are not persistent between calls
mesh_server = "srvmesh.domain.lan:443"
mesh_deviceGroup = "computers"
# mesh_displayName = 'MeshCentral Agent'
mesh_companyName = "Mesh Agent"
mesh_serviceName = "Mesh Agent"
mesh_fileName = "meshagent"

# Generic variables
silent_args = "-fullinstall"
app_uninstallkey = mesh_serviceName
bin_name_x86 = "%s32-%s.exe" % (mesh_fileName, mesh_deviceGroup)
bin_name_x64 = "%s64-%s.exe" % (mesh_fileName, mesh_deviceGroup)
app_exe = mesh_fileName + ".exe"
if mesh_companyName != mesh_serviceName:
    app_dir = makepath(programfiles, mesh_companyName, mesh_serviceName)
else:
    app_dir = makepath(programfiles, mesh_companyName)
app_path = makepath(app_dir, app_exe)
impacted_process_list = ["MeshAgent", app_exe]


def install():
    # declaring local variables
    package_version = control.get_software_version()
    app_name = control.name
    if iswin64():
        bin_name = bin_name_x64
    else:
        bin_name = bin_name_x86

    if not running_as_system():
        print("WARNING: %s will NOT be installed as SYSTEM account, it may cause issues" % app_name)

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

    # installing the package
    print("Installing: %s" % bin_name)
    install_exe_if_needed(
        bin_name,
        silentflags=silent_args,
        key=mesh_serviceName,
        min_version=package_version,
        killbefore=impacted_process_list,
        get_version=get_app_version,
        accept_returncodes=[0, 1, 3010, 3221226356],
    )


def uninstall():
    # uninstalling the package
    if installed_softwares(uninstallkey=mesh_serviceName):
        killalltasks(impacted_process_list)
        run('"%s" %s' % (app_path, "-fulluninstall"))
        time.sleep(30)
    if not installed_softwares(uninstallkey=mesh_serviceName):
        if isdir(app_dir):
            remove_tree(app_dir)
        else:
            error("ERROR: %s seems not correctly uninstalled" % control.name)
        sub_app_dir = app_dir.rsplit("\\", 1)[0]
        if dir_is_empty(sub_app_dir):
            remove_tree(sub_app_dir)
    else:
        error("ERROR: %s is not uninstalled" % control.name)


def audit():
    # Declaring local variables
    app_name = control.name
    mesh_regkey = r"SOFTWARE\Open Source\%s" % mesh_serviceName
    meshserverurl = registry_readstring(HKEY_LOCAL_MACHINE, mesh_regkey, "MeshServerUrl")
    nodeid = registry_readstring(HKEY_LOCAL_MACHINE, mesh_regkey, "NodeId")
    remotedesktopurl = "https://%s/?viewmode=11&gotonode=%s&hide=25" % (mesh_server, nodeid)
    print(remotedesktopurl)

    # nodeid = run([app_path, "-nodeid"]).splitlines()[0]
    state = run('"%s" %s' % (app_path, "state"), accept_returncodes=[0, 1, 2, 3, 4, 5, 6, 7, 100])
    state_str = state.splitlines()[0]
    print("%s service state is: %s" % (app_name, state_str))
    if state_str.lower() == "RUNNING".lower():
        result = "OK"
    elif state_str.lower() == "NOT INSTALLED".lower():
        result = "WARNING"
        # https://github.com/Ylianst/MeshAgent/issues/87
        print(
            'INFO: "Not installed" Service state may be incorrect status, you may need to update your Mesh Server (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: no audit")
        result = "ERROR"

    return result


def update_package():
    # Declaring local variables
    result = False
    proxies = get_proxies()
    if not proxies:
        proxies = get_proxies_from_wapt_console()
    app_name = control.name
    package_version = control.get_software_version()
    version = get_version_from_binary(bin_name_x86, "FileVersion")
    if not version:
        version = package_version

    # Changing version of the package
    if Version(version) > Version(control.get_software_version()):
        print("Software version updated (from: %s to: %s)" % (control.get_software_version(), Version(version)))
        result = True
    else:
        print("Software version up-to-date (%s)" % Version(version))
    control.version = "%s-%s" % (Version(version), control.version.split("-", 1)[-1])
    # control.set_software_version(version)
    control.save_control_to_wapt()

    # Validating update-package-sources
    return result

										

  Changelog 



No changelog.txt.
									
  manifest.sha256