|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from setuphelpers import *
|
|
|
|
|
|
|
|
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')
|
|
|
|
from cryptography.fernet import Fernet
|
|
|
|
import yaml
|
|
|
|
f = Fernet(open(makepath(programfiles32,'wapt','private','symetric.txt'),'r').read())
|
|
|
|
variables.update(yaml.safe_load(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():
|
|
|
|
print('Updating FusionInventory Agent package')
|
|
|
|
import requests,json
|
|
|
|
|
|
|
|
latest = json.loads(requests.get('https://api.github.com/repos/fusioninventory/fusioninventory-agent/releases/latest').text.encode('utf-8'))
|
|
|
|
version = latest['tag_name']
|
|
|
|
pe = PackageEntry();
|
|
|
|
control = pe.load_control_from_wapt('.')
|
|
|
|
bin_found = []
|
|
|
|
for arch in ['86','64']:
|
|
|
|
for asset in latest['assets']:
|
|
|
|
if asset['name'] == 'fusioninventory-agent_windows-x%s_%s.exe' % (arch, version) and not isfile('fusioninventory-agent_windows-x%s_%s.exe' % (arch, version)):
|
|
|
|
url = asset['browser_download_url']
|
|
|
|
print('Downloading FusionInventory Agent %s for x%s from %s' % (version,arch,url))
|
|
|
|
wget(url,'fusioninventory-agent_windows-x%s_%s.exe' % (arch, version))
|
|
|
|
bin_found.append(arch)
|
|
|
|
for file in glob.glob('fusioninventory-agent_windows-%s_*.exe' % arch):
|
|
|
|
if file != 'fusioninventory-agent_windows-x%s_%s.exe' % (arch, version):
|
|
|
|
print('Removing %s' % file)
|
|
|
|
remove_file(file)
|
|
|
|
if Version(version) > Version(control['version'].split('-',1)[0]) and '86' in bin_found and '64' in bin_found:
|
|
|
|
print('Updating control file with new version %s' % version)
|
|
|
|
pe.version = version + '-0'
|
|
|
|
pe.maturity = 'PREPROD'
|
|
|
|
pe.save_control_to_wapt('.')
|
|
|
|
|
|
|
|
|
|
|
|
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 != ','.join(variables['fusinv_servers']) :
|
|
|
|
print("server config is not %, it's % instead" % (','.join(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()
|
|
|
|
|