Skip to content

Commit

Permalink
Merge pull request #304 from furlongm/logo
Browse files Browse the repository at this point in the history
fix logo handling
  • Loading branch information
furlongm authored Jan 2, 2025
2 parents 459c5d3 + 58d6d10 commit 6a7a744
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
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

0 comments on commit 6a7a744

Please sign in to comment.