diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b2be90..64877b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ Control panel: * Resetting a user's password now forces them to log in again everywhere. * Status checks were not working if an ssh server was not installed. * SSL certificate validation now uses the Python cryptography module in some places where openssl was used. +* There is a new tab to show the installed version of Mail-in-a-Box and to fetch the latest released version. System: * The munin system monitoring tool is now installed and accessible at /admin/munin. diff --git a/management/daemon.py b/management/daemon.py index e821ce3..88dd9a4 100755 --- a/management/daemon.py +++ b/management/daemon.py @@ -340,6 +340,24 @@ def web_update(): # System +@app.route('/system/version', methods=["GET"]) +@authorized_personnel_only +def system_version(): + from status_checks import what_version_is_this + try: + return what_version_is_this(env) + except Exception as e: + return (str(e), 500) + +@app.route('/system/latest-upstream-version', methods=["POST"]) +@authorized_personnel_only +def system_latest_upstream_version(): + from status_checks import get_latest_miab_version + try: + return get_latest_miab_version() + except Exception as e: + return (str(e), 500) + @app.route('/system/status', methods=["POST"]) @authorized_personnel_only def system_status(): diff --git a/management/status_checks.py b/management/status_checks.py index a8edcf5..a8df755 100755 --- a/management/status_checks.py +++ b/management/status_checks.py @@ -789,6 +789,20 @@ def list_apt_updates(apt_update=True): return pkgs +def what_version_is_this(env): + # This function runs `git describe` on the Mail-in-a-Box installation directory. + # Git may not be installed and Mail-in-a-Box may not have been cloned from github, + # so this function may raise all sorts of exceptions. + miab_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + tag = shell("check_output", ["/usr/bin/git", "describe"], env={"GIT_DIR": os.path.join(miab_dir, '.git')}).strip() + return tag + +def get_latest_miab_version(): + # This pings https://mailinabox.email/bootstrap.sh and extracts the tag named in + # the script to determine the current product version. + import urllib.request + return re.search(b'TAG=(.*)', urllib.request.urlopen("https://mailinabox.email/bootstrap.sh?ping=1").read()).group(1).decode("utf8") + def run_and_output_changes(env, pool, send_via_email): import json from difflib import SequenceMatcher @@ -969,3 +983,6 @@ if __name__ == "__main__": if cert_status != "OK": sys.exit(1) sys.exit(0) + + elif sys.argv[1] == "--version": + print(what_version_is_this(env)) diff --git a/management/templates/index.html b/management/templates/index.html index 8419582..6e97076 100644 --- a/management/templates/index.html +++ b/management/templates/index.html @@ -114,6 +114,7 @@
  • Contacts/Calendar
  • Web
  • +
  • Version