From a1a57ffefaf7de27459c96494a6642f1d186849e Mon Sep 17 00:00:00 2001 From: Chuck Stewart Date: Thu, 31 Oct 2019 13:38:52 -0400 Subject: [PATCH] Add SCRIPT_NAME prefix to images directory path We need to at the SCRIPT_NAME prefix to the images directory to properly handle serving the flag images from a UWSGI + NGINX subdirectory path. --- openvpn-monitor.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/openvpn-monitor.py b/openvpn-monitor.py index d04d502..0e4f8e7 100755 --- a/openvpn-monitor.py +++ b/openvpn-monitor.py @@ -72,7 +72,6 @@ def output(s): def info(*objs): print("INFO:", *objs, file=sys.stderr) - def warning(*objs): print("WARNING:", *objs, file=sys.stderr) @@ -470,8 +469,8 @@ def parse_version(data): class OpenvpnHtmlPrinter(object): - def __init__(self, cfg, monitor): - self.init_vars(cfg.settings, monitor) + def __init__(self, cfg, monitor, script_name): + self.init_vars(cfg.settings, monitor, script_name) self.print_html_header() for key, vpn in self.vpns: if vpn['socket_connected']: @@ -482,7 +481,9 @@ def __init__(self, cfg, monitor): self.print_maps_html() self.print_html_footer() - def init_vars(self, settings, monitor): + def init_vars(self, settings, monitor, script_name): + + self.script_name = script_name self.vpns = list(monitor.vpns.items()) @@ -588,7 +589,7 @@ def print_html_header(self): if self.logo: output('Logo'.format(self.logo)) + output('src="{0}images/{1!s}">'.format(self.script_name, self.logo)) output('') output('
') @@ -720,7 +721,7 @@ def print_server_session(self, vpn_id, session, show_disconnect): if session['location'] == 'RFC1918': output('RFC1918') else: - flag = 'images/flags/{0!s}.png'.format(session['location'].lower()) + flag = '{0}images/flags/{1!s}.png'.format(self.script_name, session['location'].lower()) if 'country' in session and session['country'] is not None: country = session['country'] full_location = country @@ -826,7 +827,7 @@ def print_html_footer(self): def main(**kwargs): cfg = ConfigLoader(args.config) monitor = OpenvpnMgmtInterface(cfg, **kwargs) - OpenvpnHtmlPrinter(cfg, monitor) + OpenvpnHtmlPrinter(cfg, monitor, kwargs['script_name']) if args.debug: pretty_vpns = pformat((dict(monitor.vpns))) debug("=== begin vpns\n{0!s}\n=== end vpns".format(pretty_vpns)) @@ -876,15 +877,17 @@ def strip_slash(): @app.route('/', method='GET') def get_slash(): - return render() + script_name = request.script_name + return render(script_name=script_name) @app.route('/', method='POST') def post_slash(): + script_name = request.script_name vpn_id = request.forms.get('vpn_id') ip = request.forms.get('ip') port = request.forms.get('port') client_id = request.forms.get('client_id') - return render(vpn_id=vpn_id, ip=ip, port=port, client_id=client_id) + return render(script_name=script_name, vpn_id=vpn_id, ip=ip, port=port, client_id=client_id) @app.route('/', method='GET') def get_images(filename):