This commit is contained in:
2024-07-05 10:24:01 +02:00
parent c7a4db9914
commit aadf88afa6
3 changed files with 191 additions and 126 deletions

View File

@@ -1,5 +1,5 @@
package : comi-apps-to-update-on-wapt-server package : comi-apps-to-update-on-wapt-server
version : 0-13 version : 0-16
architecture : all architecture : all
section : base section : base
priority : optional priority : optional
@@ -29,15 +29,16 @@ editor :
keywords : keywords :
licence : opensource_free,wapt_public licence : opensource_free,wapt_public
homepage : homepage :
package_uuid : package_uuid : 56be0e6d-4573-4d1f-ad99-1cc5d5d4c718
valid_from : valid_from :
valid_until : valid_until :
forced_install_on : forced_install_on :
changelog : changelog :
min_os_version : min_os_version :
max_os_version : max_os_version :
icon_sha256sum : icon_sha256sum : d642b35ce6441158dc071677fb958ad01830271d373c332d64e48dec67f80834
signer : signer : pcosson_key
signer_fingerprint: signer_fingerprint: a25582410cf03bad179a60c189f459a0b03821c92c0cedf209e82448a66a9b4e
signature_date : signature_date : 2024-04-30T15:04:28.000000
signed_attributes : signed_attributes : package,version,architecture,section,priority,name,categories,maintainer,description,depends,conflicts,maturity,locale,target_os,min_wapt_version,sources,installed_size,impacted_process,description_fr,description_pl,description_de,description_es,description_pt,description_it,description_nl,description_ru,audit_schedule,editor,keywords,licence,homepage,package_uuid,valid_from,valid_until,forced_install_on,changelog,min_os_version,max_os_version,icon_sha256sum,signer,signer_fingerprint,signature_date,signed_attributes
signature : MaKQmI6kWy/jfJDWUJ7FQlwYyIU0FyH6GHi06Tj7DcPOMJgkliC2zCrQtT+d2YGs1kC6HjkPFHMm4zOhk8j4IMUESQH+X7MgYIGizCAXTbyQfxecR9MwvRyQ7flF+d7+i5KHWBYNJmHz/4ng37a6viFyqPfK8uZ5kQC/w+BWMIV+kJFDmxtSWppSVLa27nq8N4sk6r+6R8Of/bY+o1rHpTbzr76b8WK48OFtEUNJ+2NM5l68bJB1t6lgF+4R0SDpMykL+/h4t77jpS8ZCAuoOuBVGrUuvwyIuXQx15Nk7zKgIQ60ePDY8rrTe4PsT5f+BK7ow/6Oe88rUu0Zw8WQ6g==

View File

@@ -1,119 +1,178 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from setuphelpers import * from setuphelpers import *
import requests import requests
import json import json
from configparser import ConfigParser from configparser import ConfigParser
from waptpackage import HostCapabilities from waptpackage import HostCapabilities
from waptpackage import WaptRemoteRepo from waptpackage import WaptRemoteRepo
from waptpackage import PackageVersion from waptpackage import PackageVersion
all_package = {} all_package = {}
dict_host_capa = { dict_host_capa = {
"ubuntu22frx64": HostCapabilities( "ubuntu22frx64": HostCapabilities(
architecture="x64", architecture="x64",
language="fr", language="fr",
os="ubuntu", os="ubuntu",
packages_locales=["fr", "en", "es", "de", "it"], packages_locales=["fr", "en", "es", "de", "it"],
tags=["debian", "debian_based", "linux", "unix", "debian11", "ubuntu-22"], tags=["debian", "debian_based", "linux", "unix", "debian11", "ubuntu-22"],
os_version="11", os_version="11",
), ),
"ubuntu20frx64": HostCapabilities( "ubuntu20frx64": HostCapabilities(
architecture="x64", architecture="x64",
language="fr", language="fr",
os="ubuntu", os="ubuntu",
packages_locales=["fr", "en", "es", "de", "it"], packages_locales=["fr", "en", "es", "de", "it"],
tags=["debian", "debian_based", "linux", "unix", "debian11", "ubuntu-20"], tags=["debian", "debian_based", "linux", "unix", "debian11", "ubuntu-20"],
os_version="11", os_version="11",
), ),
"debian11frx64": HostCapabilities( "debian11frx64": HostCapabilities(
architecture="x64", architecture="x64",
language="fr", language="fr",
os="debian", os="debian",
packages_locales=["fr", "en", "es", "de", "it"], packages_locales=["fr", "en", "es", "de", "it"],
tags=["debian-bullseye", "debian", "debian_based", "linux", "unix", "debian11", "debian-11"], tags=["debian-bullseye", "debian", "debian_based", "linux", "unix", "debian11", "debian-11"],
os_version="11", os_version="11",
), ),
"win10x64fr": HostCapabilities( "debian12frx64": HostCapabilities(
architecture="x64", architecture="x64",
language="fr", language="fr",
os="windows", os="debian",
packages_locales=["fr", "en", "es", "de", "it"], packages_locales=["fr", "en", "es", "de", "it"],
tags=["windows-10", "win-10", "w-10", "windows10", "win10", "w10", "windows", "win", "w"], tags=["debian-bookworm", "debian", "debian_based", "linux", "unix", "debian12", "debian-12"],
os_version="10.0.19043", os_version="11",
), ),
} "win10x64fr": HostCapabilities(
architecture="x64",
language="fr",
def install(): os="windows",
plugin_inifile = makepath(WAPT.private_dir, "wapt_api.ini") packages_locales=["fr", "en", "es", "de", "it"],
tags=["windows-10", "win-10", "w-10", "windows10", "win10", "w10", "windows", "win", "w"],
if not isfile(plugin_inifile): os_version="10.0.19043",
filecopyto("wapt_api.ini", WAPT.private_dir) ),
}
webhook_url="https://chat.comitari.fr/hooks/64d4d02760b38508f62a5bcb/ncKSYRiLM9oNXagK5c7G3KWX2qEzET3kbFFXKnNAhtfZQEQ9"
def audit():
plugin_inifile = makepath(WAPT.private_dir, "wapt_api.ini") def install():
conf_wapt = ConfigParser() plugin_inifiles = glob.glob("*.ini")
conf_wapt.read(plugin_inifile)
wapt_url = conf_wapt.get("wapt", "wapt_url") for file in plugin_plugin_inifiles:
wapt_user = conf_wapt.get("wapt", "wapt_username") if not isfile(makepath(WAPT.private_dir,file.split("\")[-1])):
wapt_password = conf_wapt.get("wapt", "wapt_password") filecopyto(file, WAPT.private_dir)
app_to_update_json_path = makepath(WAPT.private_dir, "app_to_update.json") def audit():
if isfile(app_to_update_json_path): plugin_inifile = makepath(WAPT.private_dir, "wapt_api.ini")
print("suppression de l'ancienne version du fichier json") conf_wapt = ConfigParser()
remove_file(app_to_update_json_path) conf_wapt.read(plugin_inifile)
wapt_url = conf_wapt.get("wapt", "wapt_url")
store = WaptRemoteRepo(name="main", url="https://wapt.tranquil.it/wapt", timeout=4, verify_cert=False) wapt_user = conf_wapt.get("wapt", "wapt_username")
localstore = WaptRemoteRepo(name="main", url="https://srvwapt.comitari.fr/wapt", timeout=4, verify_cert=False) wapt_password = conf_wapt.get("wapt", "wapt_password")
# Download JSON data from the URL
online_package_list = {} app_to_update_json_path = makepath(WAPT.private_dir, "app_to_update.json")
local_package_list = {} if isfile(app_to_update_json_path):
for hc in dict_host_capa: print("suppression de l'ancienne version du fichier json")
online_package_version = {} remove_file(app_to_update_json_path)
for packageentry in store.packages():
if dict_host_capa[hc].is_matching_package(packageentry): store = WaptRemoteRepo(name="main", url="https://wapt.tranquil.it/wapt", timeout=4, verify_cert=False)
if not packageentry.package in online_package_version: localstore = WaptRemoteRepo(name="main", url="https://srvwapt.comitari.fr/wapt", timeout=4, verify_cert=False)
online_package_version[packageentry.package] = "0" # Download JSON data from the URL
if PackageVersion(online_package_version[packageentry.package]) < PackageVersion(packageentry.version): online_package_list = {}
online_package_version[packageentry.package] = packageentry.version local_package_list = {}
online_package_list[hc] = online_package_version for hc in dict_host_capa:
online_package_version = {}
for hc in dict_host_capa: for packageentry in store.packages():
local_package_version = {} if dict_host_capa[hc].is_matching_package(packageentry):
for packageentry in localstore.packages(): if not packageentry.package in online_package_version:
if dict_host_capa[hc].is_matching_package(packageentry): online_package_version[packageentry.package] = "0"
if not packageentry.package in local_package_version: if PackageVersion(online_package_version[packageentry.package]) < PackageVersion(packageentry.version):
local_package_version[packageentry.package] = "0" online_package_version[packageentry.package] = packageentry.version
if PackageVersion(local_package_version[packageentry.package]) < PackageVersion(packageentry.version): online_package_list[hc] = online_package_version
local_package_version[packageentry.package] = packageentry.version
local_package_list[hc] = local_package_version for hc in dict_host_capa:
local_package_version = {}
list_app_to_update = [] for packageentry in localstore.packages():
for hc in dict_host_capa: if dict_host_capa[hc].is_matching_package(packageentry):
for app in local_package_list[hc]: if not packageentry.package in local_package_version:
if "-" in app: local_package_version[packageentry.package] = "0"
if "tis-" + app.split("-", 1)[1] in online_package_list[hc]: if PackageVersion(local_package_version[packageentry.package]) < PackageVersion(packageentry.version):
if PackageVersion(local_package_list[hc][app]) < PackageVersion(online_package_list[hc]["tis-" + app.split("-", 1)[1]]) and app not in list_app_to_update: local_package_version[packageentry.package] = packageentry.version
print( local_package_list[hc] = local_package_version
f'{app} new version detected from {local_package_list[hc][app]} to {online_package_list[hc]["tis-"+app.split("-", 1)[1]]} for {hc}'
) list_app_to_update = []
list_app_to_update.append( for hc in dict_host_capa:
{ for app in local_package_list[hc]:
"package": app, if "-" in app:
"old_version": local_package_list[hc][app], if "tis-" + app.split("-", 1)[1] in online_package_list[hc]:
"new_version": online_package_list[hc]["tis-" + app.split("-", 1)[1]], if PackageVersion(local_package_list[hc][app]) < PackageVersion(online_package_list[hc]["tis-" + app.split("-", 1)[1]]) and app not in list_app_to_update:
} print(
) f'{app} new version detected from {local_package_list[hc][app]} to {online_package_list[hc]["tis-"+app.split("-", 1)[1]]} for {hc}'
WAPT.write_audit_data_if_changed("apps_to_upgrade", "list", list_app_to_update, max_count=3) )
list_app_to_update.append(
with open(app_to_update_json_path, "w") as json_file: {
json.dump(list_app_to_update, json_file) "package": app,
"old_version": local_package_list[hc][app],
if not list_app_to_update: "new_version": online_package_list[hc]["tis-" + app.split("-", 1)[1]],
print("your repository seems up to date") }
return "OK" )
else: WAPT.write_audit_data_if_changed("apps_to_upgrade", "list", list_app_to_update, max_count=3)
print("you need to update some packages")
return "WARNING"
if not list_app_to_update:
message="your repository seems up to date"
print(message)
send_to_rocket(webhook_url,message)
return "OK"
else:
message="you need to update some packages"
print(message)
send_to_rocket(webhook_url,message)
return "WARNING"
def send_to_rocket(webhook_url, message_text, attachments=None):
"""
Envoie un message à Rocket.Chat via un webhook.
:param webhook_url: URL du webhook Rocket.Chat
:param message_text: Texte du message à envoyer
:param attachments: Liste de pièces jointes (facultatif)
"""
# Construire le message
message = {
'text': message_text
}
if attachments:
message['attachments'] = attachments
# Envoyer la requête POST
response = requests.post(webhook_url, data=json.dumps(message), headers={'Content-Type': 'application/json'})
# Vérifier la réponse
if response.status_code == 200:
print('Message envoyé avec succès.')
else:
print(f'Échec de l\'envoi du message. Statut de la réponse : {response.status_code}')
print(f'Erreur : {response.text}')
def send_mail(body,subject):
smtp_inifile = makepath(WAPT.private_dir, "smtp.ini")
conf_wapt = ConfigParser()
conf_wapt.read(smtp_inifile)
from_addr = conf_wapt.get("wapt", "from_addr")
to_addr = conf_wapt.get("wapt", "to_addr")
password = conf_wapt.get("wapt", "password")
smtpserver = conf_wapt.get("wapt", "smtpserver")
print(from_addr)
message = f"Subject: {subject}\n\n{body}"
server = smtplib.SMTP(smtpserver, 587)
server.starttls()
server.login(from_addr, password)
server.sendmail(from_addr, to_addr, message)
server.quit()
return "OK"

5
all/smtp.ini Normal file
View File

@@ -0,0 +1,5 @@
[wapt]
from_addr =
to_addr =
password =
smtpserver =