From 847e46bf02da3c78b3fa20801d9a293dd9516ca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Gruszczy=C5=84ski?= Date: Mon, 10 Mar 2025 14:53:42 +0100 Subject: [PATCH] poprawka w format_host --- app.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 9fe2732..2a0a827 100644 --- a/app.py +++ b/app.py @@ -165,6 +165,23 @@ def get_user_dynamic_variables(user_id): user_variables = UserDynamicVariables.query.filter_by(user_id=user_id).all() return {var.variable_name: var.variable_value for var in user_variables} +def ensure_local_defaults(content, user_id): + default_entries = LocalDefaultEntry.query.filter_by(user_id=user_id).all() + required_lines = [] + + for entry in default_entries: + if entry.ip_address and entry.hostname: + required_lines.append(f"{entry.ip_address} {entry.hostname}".strip()) + + lines = [l.rstrip() for l in content.splitlines() if l.strip()] + lines = [line for line in lines if not any(line.startswith(e.split()[0]) for e in required_lines)] + + lines = required_lines + lines + + final_content = "\n".join(lines) + "\n" + + return final_content + def format_host(host): resolved_name = None # Priorytet dla Linux Daemon @@ -1250,7 +1267,7 @@ def deploy_user(user_id): else: chosen_file = default_file - # Nowa logika: jeśli `disable_local_default` jest włączone, pomijamy lokalne ustawienia + # Jeśli `disable_local_default` jest włączone, pomijamy lokalne ustawienia final_content = ("" if h.disable_regex_deploy else regex_lines) + \ ("" if h.disable_local_default else ensure_local_defaults(chosen_file.content, user_id))