Skip to content

Add SCRIPT_NAME prefix to images directory path #118

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
21 changes: 12 additions & 9 deletions openvpn-monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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']:
Expand All @@ -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())

Expand Down Expand Up @@ -588,7 +589,7 @@ def print_html_header(self):
if self.logo:
output('<a href="#" class="pull-right"><img alt="Logo" ')
output('style="max-height:46px; padding-top:3px;" ')
output('src="images/{0!s}"></a>'.format(self.logo))
output('src="{0}images/{1!s}"></a>'.format(self.script_name, self.logo))

output('</div></div></nav>')
output('<div class="container-fluid">')
Expand Down Expand Up @@ -720,7 +721,7 @@ def print_server_session(self, vpn_id, session, show_disconnect):
if session['location'] == 'RFC1918':
output('<td>RFC1918</td>')
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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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('/<filename:re:.*\.(jpg|png)>', method='GET')
def get_images(filename):
Expand Down