diff --git a/app/api/routes/routes.py b/app/api/routes/routes.py index 8fab10d..9f63ddd 100644 --- a/app/api/routes/routes.py +++ b/app/api/routes/routes.py @@ -8,7 +8,8 @@ from app.views.install.views import InstallView from app.views.server.views import ServerView, ServerGroupView, ServerGroupsView, ServersView, ServerIPView from app.views.server.cred_views import CredView, CredsView from app.views.server.backup_vews import BackupView, S3BackupView, GitBackupView -from app.views.service.views import ServiceView, ServiceActionView, ServiceBackendView, ServiceConfigView, ServiceConfigVersionsView +from app.views.service.views import (ServiceView, ServiceActionView, ServiceBackendView, ServiceConfigView, + ServiceConfigVersionsView, ServiceConfigList) from app.views.ha.views import HAView, HAVIPView, HAVIPsView from app.views.user.views import UserView, UserGroupView, UserRoles from app.views.udp.views import UDPListener, UDPListeners, UDPListenerActionView @@ -53,8 +54,10 @@ bp.add_url_rule('//listeners', view_func=UDPListeners.as_view('listener register_api_id_ip(ServiceView, 'service', '/status', ['GET']) register_api_id_ip(ServiceBackendView, 'service_backend', '/backend', ['GET']) -register_api_id_ip(ServiceConfigView, 'config_view') +register_api_id_ip(ServiceConfigView, 'config_view', '/config') register_api_id_ip(ServiceConfigVersionsView, 'config_version', '/versions', methods=['GET', 'DELETE']) +bp.add_url_rule('/service///config/list', view_func=ServiceConfigList.as_view('config_list_ip'), methods=['GET']) +bp.add_url_rule('/service///config/list', view_func=ServiceConfigList.as_view('config_list'), methods=['GET']) register_api_id_ip(CheckerView, 'checker', '/tools') register_api_id_ip(InstallView, 'install', '/install', methods=['POST']) register_api_id_ip(ServiceActionView, 'service_action', '/', methods=['GET']) diff --git a/app/views/service/views.py b/app/views/service/views.py index 9581d2f..c6cc1ad 100644 --- a/app/views/service/views.py +++ b/app/views/service/views.py @@ -435,6 +435,78 @@ class ServiceConfigView(MethodView): return DataStrResponse(data=stderr).model_dump(mode='json'), 201 +class ServiceConfigList(MethodView): + methods = ['GET'] + decorators = [jwt_required(), get_user_params(), check_services, page_for_admin(level=3), check_group()] + + def get(self, service: str, server_id: Union[int, str]): + """ + Retrieve the list of configuration files for the given service + --- + tags: + - Service configs list + parameters: + - name: service + in: path + type: string + required: true + enum: ['nginx', 'apache'] + description: Type of service (nginx or apache) + - name: server_id + in: path + type: string + required: true + description: Server ID or IP address + responses: + 200: + description: List of configuration files + schema: + type: object + properties: + data: + type: array + items: + type: string + example: [ + "/etc/nginx/conf.d/default.conf", + "/etc/nginx/waf/modsecurity.conf", + "/etc/nginx/waf/rulescrs-setup.conf", + "/etc/nginx/waf/waf.conf", + "/etc/nginx/nginx.conf" + ] + """ + try: + server_ip = SupportClass(False).return_server_ip_or_id(server_id) + except Exception as e: + return roxywi_common.handler_exceptions_for_json_data(e, 'Cannot find the server') + + files = [] + service_config_dir = sql.get_setting(f'{service}_dir') + + try: + return_files = server_mod.get_remote_files(server_ip, service_config_dir, 'conf') + except Exception as e: + return roxywi_common.handler_exceptions_for_json_data(e, 'Cannot get configs') + + return_files = return_files.split('\t\t') + for file in return_files: + if '\r\n' in file: + for f in file.split('\r\n'): + if f == '': + continue + elif '\t' in f: + for f1 in f.split('\t'): + files.append(f1) + else: + files.append(f) + elif file == '': + continue + else: + files.append(file) + files.append(sql.get_setting(f'{service}_config_path')) + return DataResponse(data=files).model_dump(mode='json') + + class ServiceConfigVersionsView(MethodView): methods = ['GET', 'POST', 'DELETE'] decorators = [jwt_required(), get_user_params(), check_services, page_for_admin(level=4), check_group()]