diff --git a/app/modules/common/common.py b/app/modules/common/common.py index fb3e7337..86a06575 100644 --- a/app/modules/common/common.py +++ b/app/modules/common/common.py @@ -41,14 +41,21 @@ def checkAjaxInput(ajax_input: str): return quote(ajax_input.rstrip()) -def return_nice_path(return_path: str) -> str: +def check_is_service_folder(service_path: str) -> bool: if ( - 'nginx' not in return_path - and 'haproxy' not in return_path - and 'apache2' not in return_path - and 'httpd' not in return_path - and 'keepalived' not in return_path - ): + 'nginx' not in service_path + and 'haproxy' not in service_path + and 'apache2' not in service_path + and 'httpd' not in service_path + and 'keepalived' not in service_path + ) or '..' in service_path: + return False + else: + return True + + +def return_nice_path(return_path: str) -> str: + if not check_is_service_folder(return_path): return 'error: The path must contain the name of the service. Check it in Roxy-WI settings' if return_path[-1] != '/': @@ -57,6 +64,14 @@ def return_nice_path(return_path: str) -> str: return return_path +def check_is_conf(config_path: str) -> bool: + if check_is_service_folder(config_path): + if 'conf' in config_path or 'cfg' in config_path: + return True + + return False + + def string_to_dict(dict_string) -> dict: from ast import literal_eval return literal_eval(dict_string) diff --git a/app/modules/config/config.py b/app/modules/config/config.py index 3f447bca..956ef88a 100644 --- a/app/modules/config/config.py +++ b/app/modules/config/config.py @@ -34,8 +34,8 @@ def get_config(server_ip, cfg, **kwargs): else: config_path = sql.get_setting('haproxy_config_path') - if '..' in config_path: - return 'error: nice try' + if not common.check_is_conf(config_path): + raise Exception('error: nice try 2') try: with mod_ssh.ssh_connect(server_ip) as ssh: @@ -451,14 +451,11 @@ def show_config(server_ip: str) -> None: if form.getvalue('configver') is None: cfg = f"{configs_dir}{server_ip}-{get_date.return_date('config')}{cfg}" - if service == 'nginx': - get_config(server_ip, cfg, nginx=1, config_file_name=form.getvalue('config_file_name')) - elif service == 'apache': - get_config(server_ip, cfg, apache=1, config_file_name=form.getvalue('config_file_name')) - elif service == 'keepalived': - get_config(server_ip, cfg, keepalived=1) - else: - get_config(server_ip, cfg) + try: + get_config(server_ip, cfg, service=service, config_file_name=form.getvalue('config_file_name')) + except Exception as e: + print(e) + return else: cfg = configs_dir + form.getvalue('configver') try: diff --git a/app/templates/add.html b/app/templates/add.html index b373fad7..abaa359f 100644 --- a/app/templates/add.html +++ b/app/templates/add.html @@ -697,7 +697,7 @@