fix w deployu na mikrotik
This commit is contained in:
parent
46d9635d1e
commit
528b49f78e
42
app.py
42
app.py
@ -1296,7 +1296,7 @@ def deploy_mikrotik(host, hosts_content):
|
|||||||
exported = stdout.read().decode('utf-8').splitlines()
|
exported = stdout.read().decode('utf-8').splitlines()
|
||||||
existing_dns = {}
|
existing_dns = {}
|
||||||
|
|
||||||
# Przetwarzamy aktualne wpisy z urządzenia
|
# Parsujemy aktualne wpisy z urządzenia (format: "add address=... name=...")
|
||||||
for line in exported:
|
for line in exported:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if not line.startswith('add '):
|
if not line.startswith('add '):
|
||||||
@ -1314,26 +1314,39 @@ def deploy_mikrotik(host, hosts_content):
|
|||||||
existing_dns[name_val] = address_val
|
existing_dns[name_val] = address_val
|
||||||
|
|
||||||
desired_dns = {}
|
desired_dns = {}
|
||||||
# Parsujemy zawartość backupu w taki sam sposób jak wpisy aktualne
|
# Parsujemy zawartość backupu/wdrażaną treść – obsługujemy dwa formaty:
|
||||||
|
# 1. Format z tokenami ("add address=... name=...")
|
||||||
|
# 2. Prosty format ("ip hostname")
|
||||||
for line in hosts_content.splitlines():
|
for line in hosts_content.splitlines():
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if not line:
|
if not line:
|
||||||
continue
|
continue
|
||||||
if line.startswith('add '):
|
# Pomijamy linie nagłówkowe/stopowe
|
||||||
line = line[4:].strip() # usuwamy "add "
|
|
||||||
if line.startswith('#') or 'Auto-hosts_upload:' in line or 'End_of_auto-hosts_upload:' in line:
|
if line.startswith('#') or 'Auto-hosts_upload:' in line or 'End_of_auto-hosts_upload:' in line:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
parts = line.split()
|
if "address=" in line and "name=" in line:
|
||||||
address_val = None
|
# Format: "add address=... name=..."
|
||||||
name_val = None
|
# Jeśli linia zaczyna się od "add ", usuńmy go, choć może już być usunięty
|
||||||
for part in parts:
|
if line.startswith('add '):
|
||||||
if part.startswith('address='):
|
line = line[4:].strip()
|
||||||
address_val = part.replace('address=', '')
|
parts = line.split()
|
||||||
elif part.startswith('name='):
|
address_val = None
|
||||||
name_val = part.replace('name=', '')
|
name_val = None
|
||||||
if address_val and name_val:
|
for part in parts:
|
||||||
desired_dns[name_val] = address_val
|
if part.startswith('address='):
|
||||||
|
address_val = part.replace('address=', '')
|
||||||
|
elif part.startswith('name='):
|
||||||
|
name_val = part.replace('name=', '')
|
||||||
|
if address_val and name_val:
|
||||||
|
desired_dns[name_val] = address_val
|
||||||
|
else:
|
||||||
|
# Zakładamy prosty format: "ip hostname" (przynajmniej dwa tokeny)
|
||||||
|
parts = line.split()
|
||||||
|
if len(parts) >= 2:
|
||||||
|
ip = parts[0]
|
||||||
|
hostname = parts[1]
|
||||||
|
desired_dns[hostname] = ip
|
||||||
|
|
||||||
# Dodajemy lub aktualizujemy wpisy, a zbędne usuwamy
|
# Dodajemy lub aktualizujemy wpisy, a zbędne usuwamy
|
||||||
for name_val, ip_val in desired_dns.items():
|
for name_val, ip_val in desired_dns.items():
|
||||||
@ -1354,7 +1367,6 @@ def deploy_mikrotik(host, hosts_content):
|
|||||||
|
|
||||||
ssh.close()
|
ssh.close()
|
||||||
|
|
||||||
|
|
||||||
@app.route('/deploy-now')
|
@app.route('/deploy-now')
|
||||||
def deploy_now():
|
def deploy_now():
|
||||||
if 'user_id' not in session:
|
if 'user_id' not in session:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user