2018-01-15 06:16:04 +00:00
|
|
|
#!/usr/bin/env python3
|
2022-11-17 07:34:58 +00:00
|
|
|
import modules.db.sql as sql
|
|
|
|
import modules.common.common as common
|
|
|
|
import modules.roxywi.auth as roxywi_auth
|
|
|
|
import modules.roxywi.common as roxywi_common
|
|
|
|
|
2018-05-05 12:40:41 +00:00
|
|
|
from jinja2 import Environment, FileSystemLoader
|
2020-02-26 18:10:02 +00:00
|
|
|
env = Environment(loader=FileSystemLoader('templates/'), autoescape=True)
|
2022-08-15 08:50:29 +00:00
|
|
|
template = env.get_template('statsview.html')
|
2022-09-27 19:06:34 +00:00
|
|
|
print('Content-type: text/html\n')
|
|
|
|
|
2022-11-17 07:34:58 +00:00
|
|
|
user_params = roxywi_common.get_users_params(virt=1, haproxy=1)
|
2022-09-27 19:06:34 +00:00
|
|
|
|
2022-11-17 07:34:58 +00:00
|
|
|
form = common.form
|
2022-05-25 08:21:44 +00:00
|
|
|
serv = form.getvalue('serv')
|
|
|
|
service = form.getvalue('service')
|
|
|
|
|
2018-05-05 12:40:41 +00:00
|
|
|
try:
|
2018-05-31 14:25:20 +00:00
|
|
|
if serv is None:
|
2022-11-17 10:18:04 +00:00
|
|
|
first_serv = user_params['servers']
|
2018-05-31 14:25:20 +00:00
|
|
|
for i in first_serv:
|
|
|
|
serv = i[2]
|
|
|
|
break
|
2021-01-18 16:21:51 +00:00
|
|
|
except Exception:
|
2018-05-05 12:40:41 +00:00
|
|
|
pass
|
2019-09-15 11:51:09 +00:00
|
|
|
|
2022-08-15 08:50:29 +00:00
|
|
|
if service in ('haproxy', 'nginx', 'apache'):
|
|
|
|
service_desc = sql.select_service(service)
|
2022-11-17 07:34:58 +00:00
|
|
|
if roxywi_auth.check_login(user_params['user_uuid'], user_params['token'], service=service_desc.service_id):
|
2022-08-15 08:50:29 +00:00
|
|
|
title = f'{service_desc.service} stats page'
|
2022-11-17 07:34:58 +00:00
|
|
|
roxywi_common.get_dick_permit(service=service_desc.slug)
|
2022-05-25 08:21:44 +00:00
|
|
|
else:
|
2022-08-15 08:50:29 +00:00
|
|
|
print('<meta http-equiv="refresh" content="0; url=/app/overview.py">')
|
2018-04-09 10:27:01 +00:00
|
|
|
|
2022-05-25 08:21:44 +00:00
|
|
|
rendered_template = template.render(
|
2022-11-17 07:34:58 +00:00
|
|
|
h2=1, autorefresh=1, title=title, role=user_params['role'], user=user_params['user'], onclick="showStats()",
|
|
|
|
selects=user_params['servers'], serv=serv, service=service, user_services=user_params['user_services'],
|
|
|
|
token=user_params['token'], select_id="serv"
|
2022-05-25 08:21:44 +00:00
|
|
|
)
|
|
|
|
print(rendered_template)
|