# -*- coding: utf-8 -*- from setuphelpers import * from cryptography.fernet import Fernet import json uninstallkey = [] variables = { 'fusinv_servers': [ 'https://glpi.lan.local/plugins/fusioninventory' ] } # Read local variables file if available if isfile(makepath(programfiles32,'wapt','private','symetric.txt')) and isfile(makepath(programfiles32,'wapt','private','variables.txt')): print('Reading local encrypted variables file') f = Fernet(open(makepath(programfiles32,'wapt','private','symetric.txt'),'r').read()) variables.update(json.loads(f.decrypt(open(makepath(programfiles32,'wapt','private','variables.txt'),'r').read()))) def install(): parameters = '/S /acceptlicense /server="%s" /execmode=service /runnow' % (','.join(variables['fusinv_servers'])) if 'fusinv_user' in variables and 'fusinv_pass' in variables: parameters = parameters + ' /user="%s" /password="%s"' % (variables['fusinv_user'],variables['fusinv_pass']) print('Installing FusionInventory Agent') versionpaquet = control['version'].split('-',1)[0] if iswin64(): install_exe_if_needed("fusioninventory-agent_windows-x64_%s.exe" % versionpaquet,parameters,key='FusionInventory-Agent',min_version=versionpaquet) else: install_exe_if_needed("fusioninventory-agent_windows-x86_%s.exe" % versionpaquet,parameters,key='FusionInventory-Agent',min_version=versionpaquet) def update_package(): import BeautifulSoup,requests,re from waptpackage import PackageEntry verify=True pe = PackageEntry() pe.load_control_from_wapt(os.getcwd()) current_version = pe['version'].split('-',1)[0] verify=True url = 'https://github.com/fusioninventory/fusioninventory-agent/releases' import requests,BeautifulSoup page = requests.get(url + '/latest',headers={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64)'},verify=verify).text bs = BeautifulSoup.BeautifulSoup(page) bs_raw_string = str(bs.find('span',{'class':'css-truncate-target'}).text) version = bs_raw_string url64 = url + "/download/" + version + "/fusioninventory-agent_windows-x64_%s.exe" % version url86 = url + "/download/" + version + "/fusioninventory-agent_windows-x86_%s.exe" % version filenamex86 = "fusioninventory-agent_windows-x86_%s.exe" % version filenamex64 = "fusioninventory-agent_windows-x64_%s.exe" % version if not isfile( filenamex64 ) : wget( url64 ) if not isfile( filenamex86 ) : wget( url86 ) for fileexe in glob.glob('fusioninventory-agent_windows-x64*.exe'): if fileexe != filenamex64 : print('Delete ' + fileexe) remove_file(fileexe) for fileexe in glob.glob('fusioninventory-agent_windows-x86*.exe'): if fileexe != filenamex86 : print('Delete ' + fileexe) remove_file(fileexe) if not isfile(filenamex64): print('Download ' + url64) wget(url64,filenamex64) if not isfile(filenamex86): print('Download ' + url86) wget(url86,filenamex86) def audit(): if not registry_readstring(HKEY_LOCAL_MACHINE,makepath('SOFTWARE','FusionInventory-Agent'),'server'): print(r"key HKEY_LOCAL_MACHINE\SOFTWARE\FusionInventory-Agent\server doesn't exist") return "ERROR" val_server = registry_readstring(HKEY_LOCAL_MACHINE,makepath('SOFTWARE','FusionInventory-Agent'),'server') if val_server != variables['fusinv_servers'] : print("server config is not %, it's % instead" % (variables['fusinv_servers'], val_server) ) return "WARNING" if 'fusinv_user' in variables and 'fusinv_pass' in variables: if not registry_readstring(HKEY_LOCAL_MACHINE,makepath('SOFTWARE','FusionInventory-Agent'),'user'): print(r"key HKEY_LOCAL_MACHINE\SOFTWARE\FusionInventory-Agent\user doesn't exist") return "ERROR" val_user = registry_readstring(HKEY_LOCAL_MACHINE,makepath('SOFTWARE','FusionInventory-Agent'),'user') if val_user != variables['fusinv_user'] : print("user config is not %s, it's %s instead" % (variables['fusinv_user'],val_user) ) return "WARNING" if not registry_readstring(HKEY_LOCAL_MACHINE,makepath('SOFTWARE','FusionInventory-Agent'),'password'): print(r"key HKEY_LOCAL_MACHINE\SOFTWARE\FusionInventory-Agent\password doesn't exist") return "ERROR" val_pass = registry_readstring(HKEY_LOCAL_MACHINE,makepath('SOFTWARE','FusionInventory-Agent'),'password') if val_pass != variables['fusinv_pass'] : print("password doesn't match what's set") return "WARNING" return "OK" if __name__ == '__main__': update_package()