v8.1.8: Refactor service settings template and logging logic.

Simplify and consolidate service settings template by introducing reusable variables and reducing code redundancy. Remove unnecessary imports and streamline logging logic to eliminate redundant parameters.
pull/418/head
Aidaho 2025-05-01 10:47:03 +03:00
parent 3b8cc74065
commit 9e2b5ec058
2 changed files with 55 additions and 140 deletions

View File

@ -2,7 +2,7 @@ from typing import Union
import distro
from flask import render_template, request, g
from flask_jwt_extended import jwt_required, get_jwt
from flask_jwt_extended import jwt_required
from flask_pydantic import validate
from pydantic import IPvAnyAddress
@ -10,7 +10,6 @@ from app import cache
from app.routes.service import bp
import app.modules.db.sql as sql
import app.modules.db.waf as waf_sql
import app.modules.db.user as user_sql
import app.modules.db.ha_cluster as ha_sql
import app.modules.db.server as server_sql
import app.modules.db.service as service_sql
@ -164,10 +163,8 @@ def cpu_ram_metrics(server_ip: Union[IPvAnyAddress, DomainName], server_id: int,
return_out = ''
servers = [[name, str(server_ip), return_out]]
claims = get_jwt()
kwargs = {
'service_status': sorted(servers, key=common.get_key),
'role': user_sql.get_user_role_in_group(claims['user_id'], claims['group']),
'id': server_id,
'service_page': service,
'lang': g.user_params['lang']
@ -238,23 +235,23 @@ def save_service_settings(service):
if service == 'haproxy':
if service_sql.insert_or_update_service_setting(server_id, service, 'haproxy_enterprise', haproxy_enterprise):
if haproxy_enterprise == '1':
roxywi_common.logging(server_ip, 'Service has been flagged as an Enterprise version', roxywi=1, login=1,
roxywi_common.logging(server_ip, 'Service has been flagged as an Enterprise version',
keep_history=1, service=service)
else:
roxywi_common.logging(server_ip, 'Service has been flagged as a community version', roxywi=1, login=1,
roxywi_common.logging(server_ip, 'Service has been flagged as a community version',
keep_history=1, service=service)
if service_sql.insert_or_update_service_setting(server_id, service, 'dockerized', service_dockerized):
if service_dockerized == '1':
roxywi_common.logging(server_ip, service_docker, roxywi=1, login=1, keep_history=1, service=service)
roxywi_common.logging(server_ip, service_docker, keep_history=1, service=service)
else:
roxywi_common.logging(server_ip, service_systemd, roxywi=1, login=1, keep_history=1, service=service)
roxywi_common.logging(server_ip, service_systemd, keep_history=1, service=service)
if service_sql.insert_or_update_service_setting(server_id, service, 'restart', service_restart):
if service_restart == '1':
roxywi_common.logging(server_ip, disable_restart, roxywi=1, login=1, keep_history=1, service=service)
roxywi_common.logging(server_ip, disable_restart, keep_history=1, service=service)
else:
roxywi_common.logging(server_ip, enable_restart, roxywi=1, login=1, keep_history=1, service=service)
roxywi_common.logging(server_ip, enable_restart, keep_history=1, service=service)
return 'ok'
@ -269,8 +266,7 @@ def update_tools_enable(service):
metrics = request.form.get('metrics')
service_sql.update_hapwi_server(server_id, alert, metrics, active, service)
server_ip = server_sql.get_server(server_id).ip
roxywi_common.logging(server_ip, f'The server {name} has been updated ', roxywi=1, login=1, keep_history=1,
service=service)
roxywi_common.logging(server_ip, f'The server {name} has been updated ', keep_history=1, service=service)
return 'ok'

View File

@ -1,4 +1,5 @@
{% from 'include/input_macros.html' import checkbox %}
{% set nice_service_name = {'haproxy': 'HAProxy', 'nginx': 'NGINX', 'apache': 'Apache'} %}
<table class="overview">
{% if service == 'haproxy' %}
{% if settings %}
@ -16,31 +17,6 @@
</td>
</tr>
{% endif %}
{% if s.dockerized != '' and s.setting == 'dockerized' %}
<tr>
<td class="padding20 help_cursor" style="width: 70%"
title="If you use HAProxy inside Docker, check this. Roxy-WI is starting managing it as Docker container">HAProxy dockerized</td>
<td>
{% if s.value == '1' and s.setting == 'dockerized' %}
{{ checkbox('haproxy_dockerized', checked='checked', title='This service is running inside a Docker container') }}
{% elif s.setting == 'dockerized' %}
{{ checkbox('haproxy_dockerized', title='This server will be used as Docker container') }}
{% endif %}
</td>
</tr>
{% endif %}
{% if s.restart != '' and s.setting == 'restart' %}
<tr>
<td class="padding20 help_cursor" style="width: 70%" title="If enabled, the restart button disabled">Disable restart</td>
<td>
{% if s.value == '1' and s.setting == 'restart' %}
{{ checkbox('haproxy_restart', checked='checked', title='Restart option is disabled for this server') }}
{% elif s.setting == 'restart' %}
{{ checkbox('haproxy_restart', title='Only the reload button will be active') }}
{% endif %}
</td>
</tr>
{% endif %}
{% endfor %}
{% else %}
<tr>
@ -50,110 +26,53 @@
{{ checkbox('haproxy_enterprise', title='This server uses HAProxy community') }}
</td>
</tr>
<tr>
<td class="padding20 help_cursor" style="width: 70%"
title="If you use HAProxy inside Docker, check this. Roxy-WI is starting managing it as Docker container">HAProxy dockerized</td>
<td>
{{ checkbox('haproxy_dockerized', title='This server will be used as Docker container') }}
</td>
</tr>
<tr>
<td class="padding20 help_cursor" style="width: 70%"
title="If enabled, the restart button disabled">Disable restart</td>
<td>
{{ checkbox('haproxy_restart', title='Only the reload button will be active') }}
</td>
</tr>
{% endif %}
{% endif %}
{% if service == 'nginx' %}
{% if settings %}
{% for s in settings %}
{% if s.dockerized != '' and s.setting == 'dockerized' %}
<tr>
<td class="padding20 help_cursor" style="width: 70%"
title="If you use NGINX inside Docker, check this. Roxy-WI is starting managing it as Docker container">NGINX dockerized</td>
<td>
{% if s.value == '1' and s.setting == 'dockerized' %}
{{ checkbox('nginx_dockerized', checked='checked', title='This service is running inside a Docker container') }}
{% else %}
{{ checkbox('nginx_dockerized', title='This server will be used as Docker container') }}
{% endif %}
</td>
</tr>
{% endif %}
{% if s.restart != '' and s.setting == 'restart' %}
<tr>
<td class="padding20 help_cursor" style="width: 70%" title="If enabled, the restart button disabled">Disable restart</td>
<td>
{% if s.value == '1' and s.setting == 'restart' %}
{{ checkbox('nginx_restart', checked='checked', title='Restart option is disabled for this server') }}
{% elif s.setting == 'restart' %}
{{ checkbox('nginx_restart', title='Only the reload button will be active') }}
{% endif %}
</td>
</tr>
{% endif %}
{% endfor %}
{% else %}
<tr>
<td class="padding20 help_cursor" style="width: 70%"
title="If you use NGINX inside Docker, check this. Roxy-WI is starting managing it as Docker container">NGINX dockerized</td>
<td>
{{ checkbox('nginx_dockerized', title='This server will be used as Docker container') }}
</td>
</tr>
<tr>
<td class="padding20 help_cursor" style="width: 70%" title="If enabled, the restart button disabled">Disable restart</td>
<td>
{{ checkbox('nginx_restart', title='Only the reload button will be active') }}
</td>
</tr>
{% endif %}
{% endif %}
{% if service == 'apache' %}
{% if settings %}
{% for s in settings %}
{% if s.dockerized != '' and s.setting == 'dockerized' %}
<tr>
<td class="padding20 help_cursor" style="width: 70%"
title="If you use Apache inside Docker, check this. Roxy-WI is starting managing it as Docker container">Apache dockerized</td>
<td>
{% if s.value == '1' and s.setting == 'dockerized' %}
{{ checkbox('apache_dockerized', checked='checked', title='This service is running inside a Docker container') }}
{% else %}
{{ checkbox('apache_dockerized', title='This server will be used as Docker container') }}
{% endif %}
</td>
</tr>
{% endif %}
{% if s.restart != '' and s.setting == 'restart' %}
<tr>
<td class="padding20 help_cursor" style="width: 70%" title="If enabled, the restart button disabled">Disable restart</td>
<td>
{% if s.value == '1' and s.setting == 'restart' %}
{{ checkbox('apache_restart', checked='checked', title='Restart option is disabled for this server') }}
{% elif s.setting == 'restart' %}
{{ checkbox('apache_restart', title='Only the reload button will be active') }}
{% endif %}
</td>
</tr>
{% endif %}
{% endfor %}
{% else %}
<tr>
<td class="padding20 help_cursor" style="width: 70%"
title="If you use Apache inside Docker, check this. Roxy-WI is starting managing it as Docker container">Apache dockerized</td>
<td>
{{ checkbox('apache_dockerized', title='This server will be used as Docker container') }}
</td>
</tr>
<tr>
<td class="padding20 help_cursor" style="width: 70%" title="If enabled, the restart button disabled">Disable restart</td>
<td>
{{ checkbox('apache_restart', title='Only the reload button will be active') }}
</td>
</tr>
{% endif %}
{% if settings %}
{% for s in settings %}
{% if s.dockerized != '' and s.setting == 'dockerized' %}
<tr>
<td class="padding20 help_cursor" style="width: 70%"
title="If you use {{ nice_service_name[service] }} inside Docker, check this. Roxy-WI is starting managing it as Docker container">{{ nice_service_name[service] }} dockerized</td>
<td>
{% set id = service + '_dockerized' %}
{% if s.value == '1' and s.setting == 'dockerized' %}
{{ checkbox(id, checked='checked', title='This service is running inside a Docker container') }}
{% else %}
{{ checkbox(id, title='This server will be used as Docker container') }}
{% endif %}
</td>
</tr>
{% endif %}
{% if s.restart != '' and s.setting == 'restart' %}
<tr>
<td class="padding20 help_cursor" style="width: 70%" title="If enabled, the restart button disabled">Disable restart</td>
<td>
{% set id = service + '_restart' %}
{% if s.value == '1' and s.setting == 'restart' %}
{{ checkbox(id, checked='checked', title='Restart option is disabled for this server') }}
{% elif s.setting == 'restart' %}
{{ checkbox(id, title='Only the reload button will be active') }}
{% endif %}
</td>
</tr>
{% endif %}
{% endfor %}
{% else %}
<tr>
<td class="padding20 help_cursor" style="width: 70%"
title="If you use {{ nice_service_name[service] }} inside Docker, check this. Roxy-WI is starting managing it as Docker container">{{ nice_service_name[service] }} dockerized</td>
<td>
{% set id = service + '_dockerized' %}
{{ checkbox(id, title='This server will be used as Docker container') }}
</td>
</tr>
<tr>
<td class="padding20 help_cursor" style="width: 70%" title="If enabled, the restart button disabled">Disable restart</td>
<td>
{% set id = service + '_restart' %}
{{ checkbox(id, title='Only the reload button will be active') }}
</td>
</tr>
{% endif %}
</table>