From 447739c644dfa85c5f742bb8ebab8953eacfc963 Mon Sep 17 00:00:00 2001 From: Aidaho Date: Sat, 24 Feb 2024 11:05:31 +0300 Subject: [PATCH] v7.2.0.0 Small bugs fix --- app/modules/db/sql.py | 8 +---- app/modules/roxywi/common.py | 13 +++---- app/modules/roxywi/metrics.py | 4 +-- app/modules/roxywi/user.py | 2 +- app/modules/server/ssh.py | 17 +++++---- app/modules/server/ssh_connection.py | 3 +- app/routes/metric/routes.py | 11 +++--- app/routes/server/routes.py | 30 +++++++++++++--- app/routes/smon/routes.py | 3 +- app/static/css/style-6.3.9.css | 11 +++--- app/templates/ajax/new_ssh.html | 2 +- app/templates/ajax/smon/smon_dashboard.html | 6 ++-- app/templates/config.html | 4 +-- app/templates/smon/dashboard.html | 3 -- config_other/logrotate/backup | 2 +- config_other/logrotate/roxy-wi | 19 ++++++++++ inc/metrics.js | 40 ++++++++++----------- inc/smon.js | 5 ++- 18 files changed, 105 insertions(+), 78 deletions(-) create mode 100644 config_other/logrotate/roxy-wi diff --git a/app/modules/db/sql.py b/app/modules/db/sql.py index af2d791..a7e4772 100755 --- a/app/modules/db/sql.py +++ b/app/modules/db/sql.py @@ -962,9 +962,6 @@ def insert_new_ssh(name, enable, group, username, password): Cred.insert(name=name, enable=enable, groups=group, username=username, password=password).execute() except Exception as e: out_error(e) - return False - else: - return True def delete_ssh(ssh_id): @@ -3027,7 +3024,7 @@ def select_remote_path_from_version(server_ip: str, service: str, local_path: st def insert_system_info( - server_id: int, os_info: str, sys_info: str, cpu: str, ram: str, network: str, disks: str + server_id: int, os_info: str, sys_info: dict, cpu: dict, ram: dict, network: dict, disks: dict ): try: SystemInfo.insert( @@ -3112,9 +3109,6 @@ def insert_user_name(user_name): UserName.insert(UserName=user_name).execute() except Exception as e: out_error(e) - return False - else: - return True def select_user_name(): diff --git a/app/modules/roxywi/common.py b/app/modules/roxywi/common.py index 40f2b39..15a442f 100644 --- a/app/modules/roxywi/common.py +++ b/app/modules/roxywi/common.py @@ -16,7 +16,7 @@ def return_error_message(): return 'error: All fields must be completed' -def get_user_group(**kwargs) -> str: +def get_user_group(**kwargs) -> int: user_group = '' try: @@ -104,8 +104,6 @@ def get_files(folder, file_format, server_ip=None) -> list: def logging(server_ip: str, action: str, **kwargs) -> None: - login = '' - cur_date = get_date.return_date('logs') cur_date_in_log = get_date.return_date('date_in_log') log_path = get_config_var.get_config_var('main', 'log_path') @@ -126,18 +124,17 @@ def logging(server_ip: str, action: str, **kwargs) -> None: user_uuid = request.cookies.get('uuid') login = sql.get_user_name_by_uuid(user_uuid) except Exception: - if kwargs.get('login'): - login = kwargs.get('login') + login = '' if kwargs.get('roxywi') == 1: if kwargs.get('login'): mess = f"{cur_date_in_log} from {ip} user: {login}, group: {user_group}, {action} on: {server_ip}\n" else: mess = f"{cur_date_in_log} {action} from {ip}\n" - log_file = f"{log_path}/roxy-wi-{cur_date}.log" + log_file = f"{log_path}/roxy-wi.log" else: - mess = f"{cur_date_in_log} from {ip} user: {login}, group: {user_group}, {action} on: {server_ip}\n" - log_file = f"{log_path}/config_edit-{cur_date}.log" + mess = f"{cur_date_in_log} from {ip} user: {login}, group: {user_group}, {action} on: {server_ip} {kwargs.get('service')}\n" + log_file = f"{log_path}/config_edit.log" if kwargs.get('keep_history'): try: diff --git a/app/modules/roxywi/metrics.py b/app/modules/roxywi/metrics.py index dcaeeac..d9b4c87 100644 --- a/app/modules/roxywi/metrics.py +++ b/app/modules/roxywi/metrics.py @@ -1,7 +1,7 @@ import psutil -import modules.db.sql as sql -import modules.server.server as server_mod +import app.modules.db.sql as sql +import app.modules.server.server as server_mod def show_ram_metrics(metrics_type: str) -> dict: diff --git a/app/modules/roxywi/user.py b/app/modules/roxywi/user.py index bbaa7be..079158b 100644 --- a/app/modules/roxywi/user.py +++ b/app/modules/roxywi/user.py @@ -28,7 +28,7 @@ def create_user(new_user: str, email: str, password: str, role: str, activeuser: except Exception as e: roxywi_common.logging('error: Cannot send email for a new user', e, roxywi=1, login=1) except Exception as e: - roxywi_common.handle_exceptions(e, 'Roxy-WI server', f'Cannot create a new user', roxywi=1, login=1) + roxywi_common.handle_exceptions(e, 'Roxy-WI server', 'Cannot create a new user', roxywi=1, login=1) def delete_user(user_id: int) -> str: diff --git a/app/modules/server/ssh.py b/app/modules/server/ssh.py index 35d49aa..fe386b8 100644 --- a/app/modules/server/ssh.py +++ b/app/modules/server/ssh.py @@ -4,11 +4,11 @@ from cryptography.fernet import Fernet import paramiko from flask import render_template, request -import modules.db.sql as sql -import modules.common.common as common +import app.modules.db.sql as sql +import app.modules.common.common as common from app.modules.server import ssh_connection -import modules.roxywi.common as roxywi_common -import modules.roxy_wi_tools as roxy_wi_tools +import app.modules.roxywi.common as roxywi_common +import app.modules.roxy_wi_tools as roxy_wi_tools error_mess = common.error_mess get_config = roxy_wi_tools.GetConfigVar() @@ -82,9 +82,12 @@ def create_ssh_cred() -> str: if username is None or name is None: return error_mess else: - if sql.insert_new_ssh(name, enable, group, username, password): - roxywi_common.logging('Roxy-WI server', f'New SSH credentials {name} has been created', roxywi=1, login=1) - return render_template('ajax/new_ssh.html', groups=sql.select_groups(), sshs=sql.select_ssh(name=name), page=page, lang=lang) + try: + sql.insert_new_ssh(name, enable, group, username, password) + except Exception as e: + roxywi_common.handle_exceptions(e, 'Roxy-WI server', 'Cannot create new SSH credentials', roxywi=1, login=1) + roxywi_common.logging('Roxy-WI server', f'New SSH credentials {name} has been created', roxywi=1, login=1) + return render_template('ajax/new_ssh.html', groups=sql.select_groups(), sshs=sql.select_ssh(name=name), page=page, lang=lang) def create_ssh_cread_api(name: str, enable: str, group: str, username: str, password: str) -> bool: diff --git a/app/modules/server/ssh_connection.py b/app/modules/server/ssh_connection.py index 6a85391..32ae3dd 100644 --- a/app/modules/server/ssh_connection.py +++ b/app/modules/server/ssh_connection.py @@ -16,6 +16,7 @@ class SshConnection: self.ssh_key_name = ssh_settings['key'] self.ssh_passphrase = ssh_settings['passphrase'] + # noinspection PyExceptClausesOrder def __enter__(self): kwargs = { 'hostname': self.server_ip, @@ -112,7 +113,7 @@ class SshConnection: yield stdout.channel.recv(len(stdout.channel.in_buffer)) # chunked read to prevent stalls - while (not channel.closed or channel.recv_ready() or channel.recv_stderr_ready()): + while not channel.closed or channel.recv_ready() or channel.recv_stderr_ready(): # stop if channel was closed prematurely, # and there is no data in the buffers. got_chunk = False diff --git a/app/routes/metric/routes.py b/app/routes/metric/routes.py index b648e12..e4e98ee 100644 --- a/app/routes/metric/routes.py +++ b/app/routes/metric/routes.py @@ -4,7 +4,7 @@ from flask_login import login_required from app.routes.metric import bp import app.modules.db.sql as sql -from middleware import check_services, get_user_params +from app.middleware import check_services, get_user_params import app.modules.common.common as common import app.modules.server.server as server_mod import app.modules.roxywi.metrics as metric @@ -14,7 +14,7 @@ import app.modules.roxywi.common as roxywi_common @bp.before_request @login_required def before_request(): - """ Protect all of the admin endpoints. """ + """ Protect all the admin endpoints. """ pass @@ -86,15 +86,14 @@ def table_metrics(service): group_id = roxywi_common.get_user_group(id=1) if service in ('nginx', 'apache'): - metrics = sql.select_service_table_metrics(service, group_id) + table_stat = sql.select_service_table_metrics(service, group_id) else: - metrics = sql.select_table_metrics(group_id) + table_stat = sql.select_table_metrics(group_id) - return render_template('ajax/table_metrics.html', table_stat=metrics, service=service, lang=lang) + return render_template('ajax/table_metrics.html', table_stat=table_stat, service=service, lang=lang) @bp.post('//') -@check_services def show_metric(service, server_ip): server_ip = common.is_ip_or_dns(server_ip) hostname = sql.get_hostname_by_server_ip(server_ip) diff --git a/app/routes/server/routes.py b/app/routes/server/routes.py index 84d6afc..ffe4a39 100644 --- a/app/routes/server/routes.py +++ b/app/routes/server/routes.py @@ -83,12 +83,32 @@ def create_server(): user_subscription = roxywi_common.return_unsubscribed_user_status() roxywi_common.logging('Roxy-WI server', f'Cannot get a user plan: {e}', roxywi=1) - try: - if add_to_smon: + if add_to_smon: + try: user_group = roxywi_common.get_user_group(id=1) - smon_mod.create_smon(hostname, ip, 0, 1, 0, 0, hostname, desc, 0, 0, 0, 56, 'ping', 0, 0, user_group, 0) - except Exception as e: - roxywi_common.logging(ip, f'error: Cannot add server {hostname} to SMON: {e}') + json_data = { + "name": hostname, + "ip": ip, + "port": "0", + "enabled": "1", + "url": "", + "body": "", + "group": hostname, + "desc": f"Ping {hostname}", + "tg": "0", + "slack": "0", + "pd": "0", + "resolver": "", + "record_type": "", + "packet_size": "56", + "http_method": "", + "check_type": "ping", + "agent_id": "1", + "interval": "120", + } + smon_mod.create_smon(json_data, user_group) + except Exception as e: + roxywi_common.logging(ip, f'error: Cannot add server {hostname} to SMON: {e}', roxywi=1) roxywi_common.logging(ip, f'A new server {hostname} has been created', roxywi=1, login=1, keep_history=1, service='server') diff --git a/app/routes/smon/routes.py b/app/routes/smon/routes.py index 0c54956..1c767c5 100644 --- a/app/routes/smon/routes.py +++ b/app/routes/smon/routes.py @@ -4,7 +4,7 @@ from flask_login import login_required from datetime import datetime from app.routes.smon import bp -from middleware import get_user_params +from app.middleware import get_user_params from app.modules.db.db_model import conn import app.modules.db.sql as sql import app.modules.db.smon as smon_sql @@ -44,6 +44,7 @@ def smon_main_dashboard(): 'telegrams': sql.get_user_telegram_by_group(group_id), 'slacks': sql.get_user_pd_by_group(group_id), 'pds': sql.get_user_slack_by_group(group_id), + 'sort': request.args.get('sort', None) } return render_template('smon/dashboard.html', **kwargs) diff --git a/app/static/css/style-6.3.9.css b/app/static/css/style-6.3.9.css index 582fef5..68442b6 100644 --- a/app/static/css/style-6.3.9.css +++ b/app/static/css/style-6.3.9.css @@ -63,7 +63,7 @@ ul#browse_history li:before { ul#browse_history li+li:before { content: "->"; color: #767676; - margin: 0 5px 0px 5px; + margin: 0 5px 0 5px; } #browse_history a { color: #767676; @@ -669,9 +669,6 @@ ul{ .ui-corner-all { border-radius: 3px !important; } -/*.ui-visual-focus {*/ -/* box-shadow: none !important;*/ -/*}*/ .ui-state-focus { border: none !important; } @@ -872,7 +869,7 @@ label { width: 5px; height: 5px; display: inline-block; - margin-bottom: 0px; + margin-bottom: 0; } .server-action { float: right; @@ -965,6 +962,7 @@ label { width: 48.8%; float: left; margin-left: var(--indent); + margin-bottom: var(--indent); } .chart-container_overview { width: 93.3%; @@ -1132,7 +1130,7 @@ label { } #logo_span img { width: 250px; - margin: 35px 0px auto 120px; + margin: 35px 0 auto 120px; } .wrong-login { margin-right: -150px; @@ -1378,7 +1376,6 @@ label { } .portlet-header { cursor: move; - margin-right: -10px; margin-left: 10px; position: relative; bottom: 3px; diff --git a/app/templates/ajax/new_ssh.html b/app/templates/ajax/new_ssh.html index 4fde612..6b77a71 100644 --- a/app/templates/ajax/new_ssh.html +++ b/app/templates/ajax/new_ssh.html @@ -11,7 +11,7 @@ {% endif %} - {% if page != "servers.py" %} + {% if page != "servers" %}