fix nats reload for old agents, fix domain parsing for non standard domains

This commit is contained in:
wh1te909 2020-11-27 22:41:32 +00:00
parent 56fbf8ae0c
commit da163d44e7
1 changed files with 12 additions and 4 deletions

View File

@ -1,7 +1,7 @@
import json import json
import os import os
import subprocess import subprocess
import tldextract from loguru import logger
from django.conf import settings from django.conf import settings
from rest_framework import status from rest_framework import status
@ -9,6 +9,8 @@ from rest_framework.response import Response
from agents.models import Agent from agents.models import Agent
logger.configure(**settings.LOG_CONFIG)
notify_error = lambda msg: Response(msg, status=status.HTTP_400_BAD_REQUEST) notify_error = lambda msg: Response(msg, status=status.HTTP_400_BAD_REQUEST)
@ -16,11 +18,17 @@ def reload_nats():
users = [{"user": "tacticalrmm", "password": settings.SECRET_KEY}] users = [{"user": "tacticalrmm", "password": settings.SECRET_KEY}]
agents = Agent.objects.prefetch_related("user").only("pk", "agent_id") agents = Agent.objects.prefetch_related("user").only("pk", "agent_id")
for agent in agents: for agent in agents:
users.append({"user": agent.agent_id, "password": agent.user.auth_token.key}) try:
users.append(
{"user": agent.agent_id, "password": agent.user.auth_token.key}
)
except:
logger.critical(
f"{agent.hostname} does not have a user account, NATS will not work"
)
if not settings.DOCKER_BUILD: if not settings.DOCKER_BUILD:
tld = tldextract.extract(settings.ALLOWED_HOSTS[0]) domain = settings.ALLOWED_HOSTS[0].split(".", 1)[1]
domain = tld.domain + "." + tld.suffix
cert_path = f"/etc/letsencrypt/live/{domain}" cert_path = f"/etc/letsencrypt/live/{domain}"
else: else:
cert_path = "/opt/tactical/certs" cert_path = "/opt/tactical/certs"