From 58d6d10ca94585d943e154778c4f4bfa68087892 Mon Sep 17 00:00:00 2001 From: Marcus Furlong Date: Thu, 2 Jan 2025 15:05:31 -0500 Subject: [PATCH] fix logo handling --- openvpn_monitor/app.py | 19 ++++++++++++++++++- openvpn_monitor/templates/navbar.html | 4 +--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/openvpn_monitor/app.py b/openvpn_monitor/app.py index 212b347..3723913 100644 --- a/openvpn_monitor/app.py +++ b/openvpn_monitor/app.py @@ -21,7 +21,7 @@ import secrets import sys from datetime import datetime -from flask import Flask, request, render_template +from flask import Flask, request, render_template, send_file, current_app from flask_wtf import CSRFProtect from humanize import naturalsize from pprint import pformat @@ -167,6 +167,23 @@ def inject_settings(): datetime_format=datetime_format, ) + @app.route('/images/logo', methods=['GET']) + def get_logo(): + logo = settings.get('logo') + if logo.startswith('http'): + logging.info(f'Using `{logo}` for logo (http link)') + return logo + logo_file = os.path.join('/etc/openvpn-monitor', logo) + if os.path.isfile(logo_file) and os.access(logo_file, os.R_OK): + logging.info(f'Using `{logo_file}` for logo') + return send_file(logo_file) + logo_file = os.path.join(cwd, 'static/images', logo) + if os.path.isfile(logo_file) and os.access(logo_file, os.R_OK): + static_logo = f'images/{logo}' + logging.info(f'Using `{logo_file}` for logo (static)') + return current_app.send_static_file(static_logo) + logging.error(f'Logo defined but image not found, skipping') + @app.route('/', methods=['GET', 'POST']) def handle_root(): vpn_data = VPNDataCollector(loaded_vpns, geoip_db.gi) diff --git a/openvpn_monitor/templates/navbar.html b/openvpn_monitor/templates/navbar.html index 7125c6b..898f4a4 100644 --- a/openvpn_monitor/templates/navbar.html +++ b/openvpn_monitor/templates/navbar.html @@ -23,10 +23,8 @@ {% if maps %}
  • Map View
  • {% endif %} {% if logo %} - {% set logo_path = 'images/' + logo %} - Logo + Logo {% endif %}