mikrotik services config

This commit is contained in:
Mateusz Gruszczyński
2025-10-27 09:38:17 +01:00
parent 561a3b23f6
commit 0a4f4bf1d4

View File

@@ -317,10 +317,10 @@ class MikroTikManager(SSHManager):
# Certificate is current, check services
logger.info("Certificate is current. Verifying services...")
cert_name = "letsencrypt.pem_0"
cert_names = ["letsencrypt.pem_0", "letsencrypt", "letsencrypt.pem"]
services_need_update = False
for service in services:
success, stdout, stderr = self.execute_command(
f'/ip service print where name="{service}"',
@@ -328,23 +328,32 @@ class MikroTikManager(SSHManager):
)
if success and stdout:
if f'certificate={cert_name}' not in stdout and 'certificate=letsencrypt' not in stdout:
logger.warning(f"Service {service} not using correct certificate")
logger.debug(f"Service {service} output:\n{stdout}")
# Check if ANY of the expected certificate names appears in output
# (works for both tabular and key=value format)
cert_found = False
for cert_name in cert_names:
if cert_name in stdout:
cert_found = True
logger.info(f"✓ Service {service} using certificate: {cert_name}")
break
if not cert_found:
logger.warning(f"Service {service} not using letsencrypt certificate")
services_need_update = True
else:
logger.info(f"✓ Service {service} properly configured")
else:
logger.warning(f"Could not check service {service}")
services_need_update = True
if services_need_update:
logger.info("Services need reconfiguration. Updating...")
self.configure_services(services, cert_name)
self.configure_services(services, "letsencrypt.pem_0")
return False
logger.info("✓ Certificate and services are current. Skipping.")
logger.info("✓ Certificate and services are current.")
return False
except Exception as e:
logger.warning(f"Error checking: {e}")
return True