Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix logo handling #304

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion openvpn_monitor/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions openvpn_monitor/templates/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
{% if maps %}<li><a href="#map_canvas">Map View</a></li>{% endif %}
</ul>
{% if logo %}
{% set logo_path = 'images/' + logo %}
<a href="#" class="pull-right">
<img alt="Logo" style="max-height:46px; padding-top:3px;"
src={% if logo.startswith('http') %}"{{ logo }}"{% else %}"{{ url_for('static', filename=logo_path) }}"{% endif %}>
<img alt="Logo" style="max-height:46px; padding-top:3px;" src="images/logo">
</a>
{% endif %}
</div>
Expand Down
Loading