poprawka w format_host

This commit is contained in:
Mateusz Gruszczyński 2025-03-10 14:53:42 +01:00
parent e0f739e9a9
commit 847e46bf02

19
app.py
View File

@ -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))