wapt-fusioninventory/setup.py

113 lines
4.8 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
from setuphelpers import *
from cryptography.fernet import Fernet
2018-11-29 18:09:32 +01:00
import json
uninstallkey = []
2018-12-04 15:44:38 +01:00
print('Reading variables')
key = open(makepath(programfiles32,'wapt','private','symetric.txt'),'r').read()
f = Fernet(key)
variables = json.loads(f.decrypt(open(makepath(programfiles32,'wapt','private','variables.txt'),'r').read()))
if not 'fusinv_server' in variables:
error('Missing fusinv_server variable')
def install():
print('Reading variables')
key = open(makepath(programfiles32,'wapt','private','symetric.txt'),'r').read()
f = Fernet(key)
variables = json.loads(f.decrypt(open(makepath(programfiles32,'wapt','private','variables.txt'),'r').read()))
2018-11-29 18:09:32 +01:00
if not 'fusinv_server' in variables:
2018-12-04 15:44:38 +01:00
error('Missing fusinv_server variable')
2018-11-29 18:09:32 +01:00
parameters = '/S /acceptlicense /server="%s" /execmode=service /runnow' % (variables['fusinv_server'])
if 'fusinv_user' in variables and 'fusinv_pass' in variables:
parameters = parameters + ' /user="%s" /password="%s"' % (variables['fusinv_user'],variables['fusinv_pass'])
print('installing Fusion inventory 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)
2018-11-29 18:09:32 +01:00
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)
2018-12-04 15:44:38 +01:00
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_server'] :
print("server config is not %, it's % instead" % (variables['fusinv_server'], 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()