mirror of https://github.com/Aidaho12/haproxy-wi
v8.1.8: Refactor exception handling and minor UI updates.
Removed redundant try-except blocks to streamline code and improve readability. Added new fields to JavaScript variables for UI consistency and adjusted HTML structure for better semantics. Removed an unused error message constant.pull/418/head
parent
e36050d8fd
commit
a218caa56c
|
@ -10,8 +10,6 @@ from pytz import timezone
|
|||
|
||||
import app.modules.db.sql as sql
|
||||
|
||||
error_mess = 'error: All fields must be completed'
|
||||
|
||||
|
||||
def _convert_to_time_zone(date: datetime) -> datetime:
|
||||
"""
|
||||
|
|
|
@ -17,10 +17,7 @@ def common_action(server_ip: str, action: str, service: str) -> None:
|
|||
'waf_nginx': action_nginx_waf
|
||||
}
|
||||
|
||||
try:
|
||||
action_functions[service](server_ip, action, service)
|
||||
except Exception as e:
|
||||
raise e
|
||||
action_functions[service](server_ip, action, service)
|
||||
|
||||
|
||||
def service_action(server_ip: str, action: str, service: str) -> None:
|
||||
|
@ -30,10 +27,7 @@ def service_action(server_ip: str, action: str, service: str) -> None:
|
|||
:param service: The name of the service on which the action will be performed.
|
||||
:return: A string indicating the success or failure of the action.
|
||||
"""
|
||||
try:
|
||||
service_common.is_protected(server_ip, action)
|
||||
except Exception as e:
|
||||
raise e
|
||||
service_common.is_protected(server_ip, action)
|
||||
server_id = server_sql.get_server_by_ip(server_ip).server_id
|
||||
|
||||
if service_common.is_not_allowed_to_restart(server_id, service, action):
|
||||
|
@ -72,11 +66,7 @@ def get_action_command(service: str, action: str, server_id: int) -> str:
|
|||
|
||||
|
||||
def action_haproxy_waf(server_ip: str, action: str, service: str) -> None:
|
||||
try:
|
||||
service_common.is_protected(server_ip, action)
|
||||
except Exception as e:
|
||||
raise e
|
||||
|
||||
service_common.is_protected(server_ip, action)
|
||||
roxywi_common.logging(
|
||||
server_ip, f'HAProxy WAF service has been {action}ed', keep_history=1, service='haproxy'
|
||||
)
|
||||
|
@ -85,13 +75,8 @@ def action_haproxy_waf(server_ip: str, action: str, service: str) -> None:
|
|||
|
||||
|
||||
def action_nginx_waf(server_ip: str, action: str, service: str) -> None:
|
||||
service_common.is_protected(server_ip, action)
|
||||
config_dir = common.return_nice_path(sql.get_setting('nginx_dir'))
|
||||
|
||||
try:
|
||||
service_common.is_protected(server_ip, action)
|
||||
except Exception as e:
|
||||
raise e
|
||||
|
||||
waf_new_state = 'on' if action == 'start' else 'off'
|
||||
waf_old_state = 'off' if action == 'start' else 'on'
|
||||
|
||||
|
|
|
@ -114,10 +114,7 @@ def create_s3_backup(data: S3BackupRequest, is_api: bool) -> tuple:
|
|||
if backup_sql.check_exists_backup(data.server_id, 's3'):
|
||||
raise RoxywiConflictError('S3 backup for this server already exists')
|
||||
|
||||
try:
|
||||
create_s3_backup_inv(data, 'add')
|
||||
except Exception as e:
|
||||
raise e
|
||||
create_s3_backup_inv(data, 'add')
|
||||
|
||||
try:
|
||||
last_id = backup_sql.insert_s3_backup_job(**data.model_dump(mode='json'))
|
||||
|
@ -144,10 +141,7 @@ def delete_s3_backup(data: S3BackupRequest, backup_id: int) -> None:
|
|||
def create_git_backup(data: GitBackupRequest, is_api: bool) -> tuple:
|
||||
server_ip = server_sql.get_server(data.server_id).ip
|
||||
service_name = service_sql.select_service_name_by_id(data.service_id).lower()
|
||||
try:
|
||||
create_git_backup_inv(data, server_ip, service_name)
|
||||
except Exception as e:
|
||||
raise Exception(e)
|
||||
create_git_backup_inv(data, server_ip, service_name)
|
||||
|
||||
try:
|
||||
last_id = backup_sql.insert_new_git(server_id=data.server_id, service_id=data.service_id, repo=data.repo, branch=data.branch, time=data.time,
|
||||
|
@ -176,14 +170,7 @@ def create_git_backup(data: GitBackupRequest, is_api: bool) -> tuple:
|
|||
def delete_git_backup(data: GitBackupRequest, backup_id: int) -> tuple:
|
||||
server_ip = server_sql.get_server(data.server_id).ip
|
||||
service_name = service_sql.select_service_name_by_id(data.service_id).lower()
|
||||
try:
|
||||
create_git_backup_inv(data, server_ip, service_name, 1)
|
||||
except Exception as e:
|
||||
raise Exception(e)
|
||||
|
||||
try:
|
||||
backup_sql.delete_backup(backup_id, 'git')
|
||||
except Exception as e:
|
||||
raise Exception(e)
|
||||
create_git_backup_inv(data, server_ip, service_name, 1)
|
||||
backup_sql.delete_backup(backup_id, 'git')
|
||||
|
||||
return BaseResponse().model_dump(mode='json'), 204
|
||||
|
|
|
@ -259,7 +259,7 @@ def runtime_command(serv: str, enable: str, backend: str, save: str) -> str:
|
|||
return f'{e}'
|
||||
else:
|
||||
if enable != "show":
|
||||
roxywi_common.logging(serv, f'Has been {enable}ed {backend}', login=1, keep_history=1, service='haproxy')
|
||||
roxywi_common.logging(serv, f'Has been {enable}ed {backend}', keep_history=1, service='haproxy')
|
||||
return f'<center><h3>You {enable} {backend} on HAProxy {serv}.</center> {output}'
|
||||
else:
|
||||
return output
|
||||
|
|
|
@ -12,6 +12,8 @@ const edit_word = translate_div.attr('data-edit');
|
|||
const delete_word = translate_div.attr('data-delete');
|
||||
const back_word = translate_div.attr('data-back');
|
||||
const nice_service_name = {'keepalived': 'HA Custer', 'haproxy': 'HAProxy', 'nginx': 'NGINX', 'apache': 'Apache'};
|
||||
const value_word = translate_div.attr('data-value');
|
||||
const name_word = translate_div.attr('data-name');
|
||||
|
||||
// JS scripts URL
|
||||
const scriptPath = "/static/js"
|
||||
|
@ -29,7 +31,7 @@ const csrf_token = Cookies.get('csrf_access_token');
|
|||
const api_prefix = '/api'
|
||||
|
||||
// Add page
|
||||
const add_server_var = '<br /><input name="servers" title="Backend IP" size=14 placeholder="xxx.xxx.xxx.xxx" class="form-control second-server" style="margin: 2px 0 4px 0;">: ' +
|
||||
const add_server_var = '<p><input name="servers" title="Backend IP" size=14 placeholder="xxx.xxx.xxx.xxx" class="form-control second-server" style="margin: 2px 0 4px 0;">: ' +
|
||||
'<input name="server_port" required title="Backend port" size=3 placeholder="yyy" class="form-control second-server add_server_number" type="number"> ' +
|
||||
'Port check: <input name="port_check" required title="Maxconn. Default 200" size=5 value="200" class="form-control add_server_number" type="number">' +
|
||||
' maxconn: <input name="server_maxconn" required title="Maxconn. Default 200" size=5 value="200" class="form-control add_server_number" type="number">'
|
||||
|
|
Loading…
Reference in New Issue