From 05279fa64fefeee3dae11ef61983d090a9e14032 Mon Sep 17 00:00:00 2001 From: Aidaho Date: Thu, 12 Dec 2024 16:21:50 +0300 Subject: [PATCH] v8.1.3: Refactor server identification in certs and autocomplete logic Updated routes and JavaScript logic to use server IDs instead of server IPs for cert and backend lookups. This improves consistency and simplifies request handling. Minor fixes in formatting and structure were also applied. --- app/routes/add/routes.py | 12 +++----- app/routes/runtime/routes.py | 2 +- app/static/js/add.js | 33 ++++++++++++++++++---- app/views/service/haproxy_section_views.py | 4 +-- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/app/routes/add/routes.py b/app/routes/add/routes.py index 51dccdcf..d05bcf29 100644 --- a/app/routes/add/routes.py +++ b/app/routes/add/routes.py @@ -188,14 +188,10 @@ def delete_saved_server(server_id): return roxywi_common.handler_exceptions_for_json_data(e, 'Cannot delete server') -@bp.route('/certs/') -@bp.route('/certs/') -@validate() -def get_certs(server_ip: Union[IPvAnyAddress, DomainName, int]): - if isinstance(server_ip, int): - server = server_sql.get_server(server_ip) - server_ip = server.ip - return add_mod.get_ssl_certs(str(server_ip)) +@bp.route('/certs/') +def get_certs(server_id: int): + server_ip = server_sql.get_server(server_id).ip + return add_mod.get_ssl_certs(server_ip) @bp.route('/cert//', methods=['DELETE', 'GET']) diff --git a/app/routes/runtime/routes.py b/app/routes/runtime/routes.py index e58362c7..3571f763 100644 --- a/app/routes/runtime/routes.py +++ b/app/routes/runtime/routes.py @@ -30,7 +30,7 @@ def runtimeapi(): @bp.route('/backends/') @bp.route('/backends/') @validate() -def show_backends(server_ip: Union[IPvAnyAddress, DomainName, int]): +def show_backends(server_ip: Union[int, IPvAnyAddress, DomainName]): if isinstance(server_ip, int): server = server_sql.get_server(server_ip) server_ip = server.ip diff --git a/app/static/js/add.js b/app/static/js/add.js index 6eec8932..f151d2a4 100644 --- a/app/static/js/add.js +++ b/app/static/js/add.js @@ -191,7 +191,7 @@ $( function() { }); $("#backends").autocomplete({ source: function (request, response) { - if (!checkIsServerFiled('#serv')) return false; + if (!checkIsServerFiled('#serv2')) return false; if (request.term === "") { request.term = 1 } @@ -205,6 +205,26 @@ $( function() { autoFocus: true, minLength: -1 }); + $("#frontend_acl_then_value").autocomplete({ + source: function (request, response) { + if ($('#frontend_acl_then').val() === '5') { + if (!checkIsServerFiled('#serv2')) return false; + if (request.term === "") { + request.term = 1 + } + $.ajax({ + url: "/runtimeapi/backends/" + $("#serv2").val(), + success: function (data) { + response(data.split('
')); + } + }); + } else { + return false; + } + }, + autoFocus: true, + minLength: -1 + }); $("#new-option").autocomplete({ source: availableTags, autoFocus: true, @@ -668,9 +688,10 @@ $( function() { }); $("#path-cert-" + section_type).autocomplete({ source: function (request, response) { + let server = $("#add-" + section_type + " select[name='server'] option:selected"); if (!checkIsServerFiled("#add-" + section_type + " select[name='server'] option:selected")) return false; $.ajax({ - url: "/add/certs/" + $('#serv2').val(), + url: "/add/certs/" + server.val(), success: function (data) { data = data.replace(/\s+/g, ' '); response(data.split(" ")); @@ -1431,14 +1452,14 @@ function confirmDeleting(deleting_thing, id, dialog_id, color) { }); } function deleteId(id) { - $('#'+id).remove(); - if ($('#listen_bind > p').length == 0) { + $('#' + id).remove(); + if ($('#listen_bind > p').length == 0) { $('#listen_bind').hide(); } - if ($('#frontend_bind > p').length == 0) { + if ($('#frontend_bind > p').length == 0) { $('#frontend_bind').hide(); } - if ($('#backend_bind > p').length == 0) { + if ($('#backend_bind > p').length == 0) { $('#backend_bind').hide(); } } diff --git a/app/views/service/haproxy_section_views.py b/app/views/service/haproxy_section_views.py index 50632c70..5638abe8 100644 --- a/app/views/service/haproxy_section_views.py +++ b/app/views/service/haproxy_section_views.py @@ -38,8 +38,8 @@ class HaproxySectionView(MethodView): try: section = add_sql.get_section(server_id, section_type, section_name) - output = {'server_id': section.server_id.server_id, **model_to_dict(section, recurse=False)} - output['id'] = f'{server_id}-{section_name}' + output = {'server_id': section.server_id.server_id, **model_to_dict(section, recurse=False), + 'id': f'{server_id}-{section_name}'} output.update(section.config) return jsonify(output) except Exception as e: