proba naprawy

This commit is contained in:
Mateusz Gruszczyński 2025-03-10 15:29:41 +01:00
parent 88583dba31
commit 125599e86a

22
app.py
View File

@ -424,6 +424,17 @@ def format_host(host):
resolved_name = host.resolved_hostname or host.hostname resolved_name = host.resolved_hostname or host.hostname
return f"{resolved_name} ({host.raw_ip})" return f"{resolved_name} ({host.raw_ip})"
def remove_local_defaults(content, user_id):
local_defaults = LocalDefaultEntry.query.filter_by(user_id=user_id).all()
lines = content.splitlines()
cleaned_lines = []
for line in lines:
stripped_line = line.strip()
if not any(stripped_line.startswith(f"{entry.ip_address} {entry.hostname}") for entry in local_defaults):
cleaned_lines.append(stripped_line)
return "\n".join(cleaned_lines) + "\n"
# ------------------- # -------------------
# LOGOWANIE, REJESTRACJA, ZMIANA HASŁA # LOGOWANIE, REJESTRACJA, ZMIANA HASŁA
@ -1271,13 +1282,14 @@ def deploy_user(user_id):
else: else:
chosen_file = default_file chosen_file = default_file
# 🛠 Jeśli disable_local_default jest włączone → wgraj tylko wybrany plik hosts # Wstępna zawartość - pobrany plik hosts
final_content = chosen_file.content.strip()
# Jeśli disable_local_default jest włączone → usuwamy local-defaults, ale reszta pozostaje
if h.disable_local_default: if h.disable_local_default:
final_content = chosen_file.content.strip() final_content = remove_local_defaults(final_content, user_id)
else: else:
# W przeciwnym wypadku dodaj regex i ensure_local_defaults # Dodaj regex, jeśli nie jest wyłączony
final_content = chosen_file.content.strip()
if not h.disable_regex_deploy and regex_lines.strip(): if not h.disable_regex_deploy and regex_lines.strip():
final_content = regex_lines + "\n" + final_content final_content = regex_lines + "\n" + final_content