# -*- mode: python -*- # -*- coding: utf-8 -*- ############################################################################## # # Gestion scolarite IUT # # Copyright (c) 1999 - 2022 Emmanuel Viennet. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Emmanuel Viennet emmanuel.viennet@viennet.net # ############################################################################## """ Verification version logiciel vs version "stable" sur serveur N'effectue pas la mise à jour automatiquement, mais permet un affichage d'avertissement. """ import json import requests import time from flask import current_app import app.scodoc.sco_utils as scu from sco_version import SCOVERSION, SCONAME def is_up_to_date() -> str: """Check installed version vs last release. Returns html message, empty of ok. """ diag = "" try: response = requests.get(scu.SCO_UP2DATE) except requests.exceptions.ConnectionError: current_app.logger.debug("is_up_to_date: %s", diag) return f"""
Attention: installation de {SCONAME} non fonctionnelle.
Détails: pas de connexion à {scu.SCO_WEBSITE}. Vérifier paramètrages réseau, voir la documentation.
""" except: current_app.logger.debug("is_up_to_date: %s", diag) return f"""
Attention: installation de {SCONAME} non fonctionnelle.
Détails: erreur inconnue lors de la connexion à {scu.SCO_WEBSITE}. Vérifier paramètrages réseau, voir la documentation.
""" if response.status_code != 200: current_app.logger.debug( f"is_up_to_date: invalid response code ({response.status_code})" ) return f"""
Attention: réponse invalide de {scu.SCO_WEBSITE}
(erreur http {response.status_code}).
""" try: infos = json.loads(response.text) except json.decoder.JSONDecodeError: current_app.logger.debug(f"is_up_to_date: invalid response (json)") return f"""
Attention: réponse invalide de {scu.SCO_WEBSITE}
(erreur json).
""" # nb: si de nouveaux paquets sont publiés chaque jour, le décalage ne sera jamais signalé. # mais en régime "normal", on aura une alerte après 24h sans mise à jour. days_since_last_package = (time.time() - infos["publication_time"]) / (24 * 60 * 60) if (infos["version"] != SCOVERSION) and (days_since_last_package > 1.0): return f"""
Attention: {SCONAME} version ({SCOVERSION}) non à jour ({infos["version"]} disponible).
Contacter votre administrateur système (documentation).
""" return "" # ok