114 lines
5.2 KiB
Python
114 lines
5.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
from setuphelpers import *
|
|
|
|
uninstallkey = []
|
|
|
|
variables = {
|
|
'glpi_inv_servers': [ 'https://glpi.lan.local/front/inventory.php' ]
|
|
}
|
|
|
|
# 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(bytes(open(makepath(programfiles32,'wapt','private','symetric.txt'),'r').read(), 'utf-8'))
|
|
variables.update(yaml.safe_load(f.decrypt(bytes(open(makepath(programfiles32,'wapt','private','variables.txt'),'r').read(), 'utf-8'))))
|
|
|
|
def install():
|
|
props = {
|
|
'ADDLOCAL': 'feat_AGENT',
|
|
'HTTPD_IP': '127.0.0.1',
|
|
'NO_P2P': '1',
|
|
'RUNNOW': '1'
|
|
}
|
|
if 'glpi_inv_servers' in variables:
|
|
if isinstance(variables['glpi_inv_servers'], str):
|
|
print('Found servers %s in settings' % variables['glpi_inv_servers'])
|
|
props['SERVER'] = variables['glpi_inv_servers']
|
|
|
|
elif isinstance(variables['glpi_inv_servers'], list):
|
|
print('Found servers %s in settings' % (','.join(variables['glpi_inv_servers'])))
|
|
props['SERVER'] = ','.join(variables['glpi_inv_servers'])
|
|
|
|
if 'glpi_inv_user' in variables and 'glpi_inv_pass' in variables:
|
|
print('Found user %s in settings' % variables['glpi_inv_user'])
|
|
props['USER'] = variables['glpi_inv_user']
|
|
props['PASSWORD'] = variables['glpi_inv_pass']
|
|
|
|
print('Installing GLPI Agent')
|
|
version = control['version'].split('-',1)[0]
|
|
if iswin64():
|
|
msi = 'GLPI-Agent-%s-x64.msi' % version
|
|
else:
|
|
msi = 'GLPI-Agent-%s-x86.msi' % version
|
|
|
|
install_msi_if_needed(msi,min_version=version,properties=props)
|
|
|
|
|
|
def update_package():
|
|
print('Updating GLPI Agent package')
|
|
import requests,json
|
|
from waptpackage import PackageEntry
|
|
|
|
latest = json.loads(requests.get('https://api.github.com/repos/glpi-project/glpi-agent/releases/latest').text.encode('utf-8'))
|
|
version = latest['tag_name']
|
|
print('Last version is %s' % version)
|
|
pe = PackageEntry();
|
|
control = pe.load_control_from_wapt('.')
|
|
bin_found = []
|
|
for arch in ['86','64']:
|
|
for asset in latest['assets']:
|
|
if asset['name'] == 'GLPI-Agent-%s-x%s.msi' % (version, arch) and not isfile('GLPI-Agent-%s-x%s.msi' % (version, arch)):
|
|
url = asset['browser_download_url']
|
|
print('Downloading GLPI Agent %s for x%s from %s' % (version, arch ,url))
|
|
wget(url,'GLPI-Agent-%s-x%s.msi' % (version, arch))
|
|
bin_found.append(arch)
|
|
for file in glob.glob('GLPI-Agent*%s*.msi' % arch):
|
|
if file != 'GLPI-Agent-x%s-%s.msi' % (arch, version) and file != 'GLPI-Agent-%s-x%s.msi' % (version, arch):
|
|
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','GLPI-Agent'),'server'):
|
|
print(r"key HKEY_LOCAL_MACHINE\SOFTWARE\GLPI-Agent\server doesn't exist")
|
|
return "ERROR"
|
|
val_server = registry_readstring(HKEY_LOCAL_MACHINE,makepath('SOFTWARE','GLPI-Agent'),'server')
|
|
|
|
if 'fusinv_servers' in variables:
|
|
if isinstance(variables['fusinv_servers'], str):
|
|
if val_server != variables['fusinv_servers']:
|
|
print("server config is not %, it's % instead" % (variables['fusinv_servers'], val_server) )
|
|
return "WARNING"
|
|
elif isinstance(variables['fusinv_servers'], list):
|
|
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','GLPI-Agent'),'user'):
|
|
print(r"key HKEY_LOCAL_MACHINE\SOFTWARE\GLPI-Agent\user doesn't exist")
|
|
return "ERROR"
|
|
val_user = registry_readstring(HKEY_LOCAL_MACHINE,makepath('SOFTWARE','GLPI-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','GLPI-Agent'),'password'):
|
|
print(r"key HKEY_LOCAL_MACHINE\SOFTWARE\GLPI-Agent\password doesn't exist")
|
|
return "ERROR"
|
|
val_pass = registry_readstring(HKEY_LOCAL_MACHINE,makepath('SOFTWARE','GLPI-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()
|
|
|