SQL fixes
pull/375/head
Aidaho 2024-03-04 09:34:24 +03:00
parent d1a81f937b
commit 666fc39e1d
12 changed files with 39 additions and 23 deletions

View File

@ -34,7 +34,7 @@ def _replace_config_path_to_correct(config_path: str) -> str:
try:
return config_path.replace('92', '/')
except Exception as e:
roxywi_common.handle_exceptions(e, 'Roxy-WI server', f'Cannot sanitize config file', roxywi=1)
roxywi_common.handle_exceptions(e, 'Roxy-WI server', 'Cannot sanitize config file', roxywi=1)
def get_config(server_ip, cfg, service='haproxy', **kwargs):
@ -136,7 +136,7 @@ def _generate_command(service: str, server_id: int, just_save: str, config_path:
reload_or_restart_command = ''
else:
if service_common.is_not_allowed_to_restart(server_id, service, just_save):
raise Exception(f'error: This server is not allowed to be restarted')
raise Exception('error: This server is not allowed to be restarted')
if service == 'waf':
commands = f'{move_config} {reload_or_restart_command}'
@ -227,7 +227,7 @@ def upload_and_restart(server_ip: str, cfg: str, just_save: str, service: str, *
try:
upload(server_ip, tmp_file, cfg)
except Exception as e:
roxywi_common.handle_exceptions(e, 'Roxy-WI server', f'Cannot upload config', login=login)
roxywi_common.handle_exceptions(e, 'Roxy-WI server', 'Cannot upload config', login=login)
try:
if just_save != 'test':

View File

@ -51,13 +51,6 @@ def get_user_pd_by_group(group):
out_error(e)
def get_user_pd_by_group(group):
try:
return PD.select().where(PD.groups == group).execute()
except Exception as e:
out_error(e)
def get_pd_by_ip(ip):
query = PD.select().join(Server, on=(Server.groups == PD.groups)).where(Server.ip == ip)
try:

View File

@ -6,8 +6,7 @@ import app.modules.roxy_wi_tools as roxy_wi_tools
def insert_config_version(server_id: int, user_id: int, service: str, local_path: str, remote_path: str, diff: str):
time_zone = get_setting('time_zone')
get_date = roxy_wi_tools.GetDate(time_zone)
get_date = roxy_wi_tools.GetDate(get_setting('time_zone'))
cur_date = get_date.return_date('regular')
try:
ConfigVersion.insert(
@ -62,4 +61,4 @@ def select_remote_path_from_version(server_ip: str, service: str, local_path: st
except Exception as e:
out_error(e)
else:
return query_res
return query_res

View File

@ -90,3 +90,30 @@ def delete_action_history_for_period():
query.execute()
except Exception as e:
out_error(e)
def select_action_history_by_server_id(server_id: int):
try:
return ActionHistory.select().where(ActionHistory.server_id == server_id).execute()
except Exception as e:
out_error(e)
def select_action_history_by_user_id(user_id: int):
try:
return ActionHistory.select().where(ActionHistory.user_id == user_id).execute()
except Exception as e:
out_error(e)
def select_action_history_by_server_id_and_service(server_id: int, service: str):
query = ActionHistory.select().where(
(ActionHistory.server_id == server_id)
& (ActionHistory.service == service)
)
try:
query_res = query.execute()
except Exception as e:
out_error(e)
else:
return query_res

View File

@ -645,6 +645,7 @@ def count_agents() -> int:
def delete_smon_history():
get_date = roxy_wi_tools.GetDate(get_setting('time_zone'))
cur_date = get_date.return_date('regular', timedelta_minus=1)
query = SmonHistory.delete().where(SmonHistory.date < cur_date)
try:

View File

@ -39,7 +39,7 @@ def service_action(server_ip: str, action: str, service: str) -> str:
server_id = server_sql.select_server_id_by_ip(server_ip=server_ip)
if service_common.is_not_allowed_to_restart(server_id, service, action):
return f'error: This server is not allowed to be restarted'
return 'error: This server is not allowed to be restarted'
try:
if service != 'keepalived':

View File

@ -1,6 +1,5 @@
import json
import app.modules.db.sql as sql
import app.modules.db.server as server_sql
import app.modules.db.ha_cluster as ha_sql
import app.modules.db.service as service_sql

View File

@ -6,7 +6,7 @@ from flask_login import login_required
from app.routes.add import bp
import app.modules.db.sql as sql
import app.modules.db.add as add_sql
from middleware import check_services, get_user_params
from app.middleware import check_services, get_user_params
import app.modules.config.add as add_mod
import app.modules.common.common as common
import app.modules.roxywi.auth as roxywi_auth
@ -128,7 +128,7 @@ def add_haproxy():
else:
return 'error: The name cannot be empty'
if request.form.get('backends') != '':
if request.form.get('backends') != '' and request.form.get('backends'):
backend = f" default_backend {request.form.get('backends')}\n"
if request.form.get('maxconn'):

View File

@ -4,8 +4,7 @@ from flask import render_template, g, request, jsonify
from flask_login import login_required
from app.routes.ha import bp
from middleware import get_user_params, check_services
import app.modules.db.sql as sql
from app.middleware import get_user_params, check_services
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

View File

@ -3,7 +3,6 @@ from flask_login import login_required
from app.routes.portscanner import bp
from app.middleware import get_user_params
import app.modules.db.sql as sql
import app.modules.db.server as server_sql
import app.modules.db.portscanner as ps_sql
import app.modules.common.common as common

View File

@ -2,7 +2,7 @@ from flask import render_template, request, g
from flask_login import login_required
from app.routes.runtime import bp
from middleware import get_user_params
from app.middleware import get_user_params
import app.modules.common.common as common
import app.modules.config.runtime as runtime
import app.modules.service.haproxy as service_haproxy
@ -11,7 +11,7 @@ import app.modules.service.haproxy as service_haproxy
@bp.before_request
@login_required
def before_request():
""" Protect all of the admin endpoints. """
""" Protect all the admin endpoints. """
pass

View File

@ -4,7 +4,6 @@ from flask import render_template, request
from flask_login import login_required
from app.routes.server import bp
import app.modules.db.sql as sql
import app.modules.db.cred as cred_sql
import app.modules.db.group as group_sql
import app.modules.db.server as server_sql