reorganisation
This commit is contained in:
44
WAPT/control
Normal file
44
WAPT/control
Normal file
@@ -0,0 +1,44 @@
|
||||
package : comi-apps-to-update-on-wapt-server
|
||||
version : 0-16
|
||||
architecture : all
|
||||
section : base
|
||||
priority : optional
|
||||
name : json-update
|
||||
categories : Utilities
|
||||
maintainer : Comitari,pcosson
|
||||
description : Package to audit the wapt-server and generate a json with applications that are not up to date
|
||||
depends :
|
||||
conflicts :
|
||||
maturity : PROD
|
||||
locale : all
|
||||
target_os : all
|
||||
min_wapt_version : 2.3
|
||||
sources :
|
||||
installed_size :
|
||||
impacted_process :
|
||||
description_fr : Package pour auditer le serveur wapt et générer un json avec les applications qui ne sont pas à jour
|
||||
description_pl : Pakiet do audytu serwera wapt i generowania pliku json z aplikacjami, które nie są aktualne
|
||||
description_de : Paket zur Überprüfung des wapt-Servers und zur Erstellung eines json mit Anwendungen, die nicht auf dem neuesten Stand sind
|
||||
description_es : Paquete para auditar el servidor wapt y generar un json con las aplicaciones que no están actualizadas
|
||||
description_pt : Pacote para auditar o wapt-server e gerar um json com as aplicações que não estão atualizadas
|
||||
description_it : Pacchetto per verificare il server wapt e generare un json con le applicazioni che non sono aggiornate
|
||||
description_nl : Pakket om de wapt-server te controleren en een json te genereren met applicaties die niet up-to-date zijn
|
||||
description_ru : Пакет для аудита wapt-сервера и генерации json с неактуальными приложениями
|
||||
audit_schedule :
|
||||
editor :
|
||||
keywords :
|
||||
licence : opensource_free,wapt_public
|
||||
homepage :
|
||||
package_uuid : 56be0e6d-4573-4d1f-ad99-1cc5d5d4c718
|
||||
valid_from :
|
||||
valid_until :
|
||||
forced_install_on :
|
||||
changelog :
|
||||
min_os_version :
|
||||
max_os_version :
|
||||
icon_sha256sum : d642b35ce6441158dc071677fb958ad01830271d373c332d64e48dec67f80834
|
||||
signer : pcosson_key
|
||||
signer_fingerprint: a25582410cf03bad179a60c189f459a0b03821c92c0cedf209e82448a66a9b4e
|
||||
signature_date : 2024-04-30T15:04:28.000000
|
||||
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==
|
||||
BIN
WAPT/icon.png
Normal file
BIN
WAPT/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.7 KiB |
@@ -2,6 +2,7 @@
|
||||
from setuphelpers import *
|
||||
import requests
|
||||
import json
|
||||
import smtplib
|
||||
from configparser import ConfigParser
|
||||
from waptpackage import HostCapabilities
|
||||
from waptpackage import WaptRemoteRepo
|
||||
|
||||
180
setup.py
Normal file
180
setup.py
Normal file
@@ -0,0 +1,180 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from setuphelpers import *
|
||||
import requests
|
||||
import json
|
||||
import smtplib
|
||||
from configparser import ConfigParser
|
||||
from waptpackage import HostCapabilities
|
||||
from waptpackage import WaptRemoteRepo
|
||||
from waptpackage import PackageVersion
|
||||
|
||||
all_package = {}
|
||||
|
||||
dict_host_capa = {
|
||||
"ubuntu22frx64": HostCapabilities(
|
||||
architecture="x64",
|
||||
language="fr",
|
||||
os="ubuntu",
|
||||
packages_locales=["fr", "en", "es", "de", "it"],
|
||||
tags=["debian", "debian_based", "linux", "unix", "debian11", "ubuntu-22"],
|
||||
os_version="11",
|
||||
),
|
||||
"ubuntu20frx64": HostCapabilities(
|
||||
architecture="x64",
|
||||
language="fr",
|
||||
os="ubuntu",
|
||||
packages_locales=["fr", "en", "es", "de", "it"],
|
||||
tags=["debian", "debian_based", "linux", "unix", "debian11", "ubuntu-20"],
|
||||
os_version="11",
|
||||
),
|
||||
"debian11frx64": HostCapabilities(
|
||||
architecture="x64",
|
||||
language="fr",
|
||||
os="debian",
|
||||
packages_locales=["fr", "en", "es", "de", "it"],
|
||||
tags=["debian-bullseye", "debian", "debian_based", "linux", "unix", "debian11", "debian-11"],
|
||||
os_version="11",
|
||||
),
|
||||
"debian12frx64": HostCapabilities(
|
||||
architecture="x64",
|
||||
language="fr",
|
||||
os="debian",
|
||||
packages_locales=["fr", "en", "es", "de", "it"],
|
||||
tags=["debian-bookworm", "debian", "debian_based", "linux", "unix", "debian12", "debian-12"],
|
||||
os_version="11",
|
||||
),
|
||||
"win10x64fr": HostCapabilities(
|
||||
architecture="x64",
|
||||
language="fr",
|
||||
os="windows",
|
||||
packages_locales=["fr", "en", "es", "de", "it"],
|
||||
tags=["windows-10", "win-10", "w-10", "windows10", "win10", "w10", "windows", "win", "w"],
|
||||
os_version="10.0.19043",
|
||||
),
|
||||
}
|
||||
webhook_url="https://chat.comitari.fr/hooks/64d4d02760b38508f62a5bcb/ncKSYRiLM9oNXagK5c7G3KWX2qEzET3kbFFXKnNAhtfZQEQ9"
|
||||
|
||||
def install():
|
||||
plugin_inifiles = glob.glob("*.ini")
|
||||
|
||||
for file in plugin_inifiles:
|
||||
if not isfile(makepath(WAPT.private_dir,file.split("\\")[-1])) :
|
||||
print(f"copie de {file} dans {WAPT.private_dir}")
|
||||
filecopyto(file, WAPT.private_dir)
|
||||
|
||||
def audit():
|
||||
plugin_inifile = makepath(WAPT.private_dir, "wapt_api.ini")
|
||||
conf_wapt = ConfigParser()
|
||||
conf_wapt.read(plugin_inifile)
|
||||
wapt_url = conf_wapt.get("wapt", "wapt_url")
|
||||
wapt_user = conf_wapt.get("wapt", "wapt_username")
|
||||
wapt_password = conf_wapt.get("wapt", "wapt_password")
|
||||
|
||||
app_to_update_json_path = makepath(WAPT.private_dir, "app_to_update.json")
|
||||
if isfile(app_to_update_json_path):
|
||||
print("suppression de l'ancienne version du fichier json")
|
||||
remove_file(app_to_update_json_path)
|
||||
|
||||
store = WaptRemoteRepo(name="main", url="https://wapt.tranquil.it/wapt", timeout=4, verify_cert=False)
|
||||
localstore = WaptRemoteRepo(name="main", url="https://srvwapt.comitari.fr/wapt", timeout=4, verify_cert=False)
|
||||
# Download JSON data from the URL
|
||||
online_package_list = {}
|
||||
local_package_list = {}
|
||||
for hc in dict_host_capa:
|
||||
online_package_version = {}
|
||||
for packageentry in store.packages():
|
||||
if dict_host_capa[hc].is_matching_package(packageentry):
|
||||
if not packageentry.package in online_package_version:
|
||||
online_package_version[packageentry.package] = "0"
|
||||
if PackageVersion(online_package_version[packageentry.package]) < PackageVersion(packageentry.version):
|
||||
online_package_version[packageentry.package] = packageentry.version
|
||||
online_package_list[hc] = online_package_version
|
||||
|
||||
for hc in dict_host_capa:
|
||||
local_package_version = {}
|
||||
for packageentry in localstore.packages():
|
||||
if dict_host_capa[hc].is_matching_package(packageentry):
|
||||
if not packageentry.package in local_package_version:
|
||||
local_package_version[packageentry.package] = "0"
|
||||
if PackageVersion(local_package_version[packageentry.package]) < PackageVersion(packageentry.version):
|
||||
local_package_version[packageentry.package] = packageentry.version
|
||||
local_package_list[hc] = local_package_version
|
||||
|
||||
list_app_to_update = []
|
||||
for hc in dict_host_capa:
|
||||
for app in local_package_list[hc]:
|
||||
if "-" in app:
|
||||
if "tis-" + app.split("-", 1)[1] in online_package_list[hc]:
|
||||
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}'
|
||||
)
|
||||
list_app_to_update.append(
|
||||
{
|
||||
"package": app,
|
||||
"old_version": local_package_list[hc][app],
|
||||
"new_version": online_package_list[hc]["tis-" + app.split("-", 1)[1]],
|
||||
}
|
||||
)
|
||||
WAPT.write_audit_data_if_changed("apps_to_upgrade", "list", list_app_to_update, max_count=3)
|
||||
|
||||
|
||||
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("smtp", "from_addr")
|
||||
to_addr = conf_wapt.get("smtp", "to_addr")
|
||||
password = conf_wapt.get("smtp", "password")
|
||||
smtpserver = conf_wapt.get("smtp", "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
smtp.ini
Normal file
5
smtp.ini
Normal file
@@ -0,0 +1,5 @@
|
||||
[wapt]
|
||||
from_addr =
|
||||
to_addr =
|
||||
password =
|
||||
smtpserver =
|
||||
4
wapt_api.ini
Normal file
4
wapt_api.ini
Normal file
@@ -0,0 +1,4 @@
|
||||
[wapt]
|
||||
wapt_username = xxxxx
|
||||
wapt_password = xxxxx
|
||||
wapt_url =xxxxx
|
||||
Reference in New Issue
Block a user