Un pacchetto esiste già sullo store Wapt, ma l'ho modificato in modo che l'aggiornamento sia completamente automatico grazie alla funzione di audit (eliminando la necessità della funzione update_package). L'obiettivo è distribuire l'aggiornamento il più rapidamente possibile e senza intervento umano.
Probabilmente il codice è confuso: è la prima volta che manipolo date e orari
Prerequisiti:
Ogni agente WAPT cercherà il binario mpam-fe.exe nel proprio repository WAPT per evitare di saturare il collegamento Internet.
Sul server WAPT, è quindi necessario aggiungere, ad esempio, la seguente riga a crontab:
Un breve riassunto di cosa fa l'audit del pacchetto:00 20 * * * wget --user-agent="Mozilla" -O /var/www/waptwua/mpam-fe.exe 'https://go.microsoft.com/fwlink/?LinkID=121721&arch=x64'
Verifica confrontando la data del binario disponibile nel repository e il binario memorizzato nella cache in c:\windows\temp\mpam-fe.xe per vedere se è disponibile una nuova versione del binario.
Se il file binario non esiste ancora in "c:\windows\temp\mpam-fe.exe", falsifica la data per forzare il download.
Se la data è diversa, scarica il nuovo binario e poi controlla la firma del binario (deve provenire da 'Microsoft Corporation').
Quindi installa il nuovo binario.
Non resta che configurare la frequenza di controllo
setup.py:
Codice: Seleziona tutto
# -*- coding: utf-8 -*-
from setuphelpers import *
import requests
import os
from datetime import datetime, timedelta
import time
import waptlicences
r"""
Usable WAPT package functions: install(), uninstall(), session_setup(), audit(), update_package()
"""
# Declaring global variables - Warnings: 1) WAPT context is only available in package functions; 2) Global variables are not persistent between calls
def install():
pass
def audit():
# Declaring local variables
osversion = get_os_version()
repo_url = [r for r in WAPT.repositories if r.name == 'wapt'][0].repo_url
repo_headers = WAPT.waptserver.head('waptwua/mpam-fe.exe')
repo_last_modified = repo_headers.get('last-modified')
repo_last_modified_pattern = "%a, %d %b %Y %H:%M:%S %Z"
repo_last_modified_date = datetime.strptime(repo_last_modified, repo_last_modified_pattern)
repo_last_modified_date_loc = repo_last_modified_date + timedelta(hours=1)
if isfile(r'c:\windows\temp\mpam-fe.exe') :
file_modTimesinceEpoc = os.path.getmtime(r'c:\windows\temp\mpam-fe.exe')
else :
# fake modification time if no bin
file_modTimesinceEpoc = int(float('1002387810.4883926'))
file_modificationTime_str = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(file_modTimesinceEpoc))
file_modificationTime_date = datetime.strptime(file_modificationTime_str, '%Y-%m-%d %H:%M:%S')
# Downloading new bin
if repo_last_modified_date_loc != file_modificationTime_date :
with WAPT.waptserver.get_requests_session() as session:
wget("%swua/mpam-fe.exe" % repo_url, r'c:\windows\temp\mpam-fe.exe', requests_session=session)
# Check signature bin
expected_issuer = 'Microsoft Corporation'
sign_name = waptlicences.check_msi_signature(r'c:\windows\temp\mpam-fe.exe')[0]
if sign_name != expected_issuer:
error('Bad issuer %s != %s ' % (sign_name,expected_issuer))
# Installing bin
versionfile = get_file_properties(r'c:\windows\temp\mpam-fe.exe')['ProductVersion']
if get_windows_defender_version() < versionfile:
run(r'c:\windows\temp\mpam-fe.exe /s')
if get_windows_defender_version() < versionfile:
error('AntivirusSignatureVersion not in %s' % versionfile)
print(r'OK: Definition Version is %s' % versionfile)
return "OK"
def get_windows_defender_version():
for i in get_antivirus_info():
if not i["name"] == "Windows Defender":
continue
return Version(i['AntivirusSignatureVersion'])
return Version('0')
