From ffe3240b2769bf956c54d85e3d65a1e83514c047 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Mon, 19 Oct 2020 03:31:37 +0000 Subject: [PATCH] more agent prep --- api/tacticalrmm/agents/models.py | 25 +++++++++++ api/tacticalrmm/agents/tasks.py | 58 ++++++------------------- api/tacticalrmm/apiv3/views.py | 2 +- api/tacticalrmm/tacticalrmm/settings.py | 3 ++ 4 files changed, 43 insertions(+), 45 deletions(-) diff --git a/api/tacticalrmm/agents/models.py b/api/tacticalrmm/agents/models.py index 3622be86..2f1a047b 100644 --- a/api/tacticalrmm/agents/models.py +++ b/api/tacticalrmm/agents/models.py @@ -84,6 +84,31 @@ class Agent(BaseAuditModel): return CoreSettings.objects.first().default_time_zone + @property + def arch(self): + if self.operating_system is not None: + if "64bit" in self.operating_system: + return "64" + elif "32bit" in self.operating_system: + return "32" + return "64" + + @property + def winagent_dl(self): + return settings.DL_64 if self.arch == "64" else settings.DL_32 + + @property + def winsalt_dl(self): + return settings.SALT_64 if self.arch == "64" else settings.SALT_32 + + @property + def win_inno_exe(self): + return ( + f"winagent-v{settings.LATEST_AGENT_VER}.exe" + if self.arch == "64" + else f"winagent-v{settings.LATEST_AGENT_VER}-x86.exe" + ) + @property def status(self): offline = dt.datetime.now(dt.timezone.utc) - dt.timedelta(minutes=6) diff --git a/api/tacticalrmm/agents/tasks.py b/api/tacticalrmm/agents/tasks.py index 5dc7fe4e..28a78c1e 100644 --- a/api/tacticalrmm/agents/tasks.py +++ b/api/tacticalrmm/agents/tasks.py @@ -29,28 +29,13 @@ def send_agent_update_task(pks, version): for chunk in chunks: for pk in chunk: agent = Agent.objects.get(pk=pk) - if agent.operating_system is not None: - if "64bit" in agent.operating_system: - arch = "64" - elif "32bit" in agent.operating_system: - arch = "32" - else: - arch = "64" - - url = settings.DL_64 if arch == "64" else settings.DL_32 - inno = ( - f"winagent-v{version}.exe" - if arch == "64" - else f"winagent-v{version}-x86.exe" - ) - - r = agent.salt_api_async( - func="win_agent.do_agent_update_v2", - kwargs={ - "inno": inno, - "url": url, - }, - ) + r = agent.salt_api_async( + func="win_agent.do_agent_update_v2", + kwargs={ + "inno": agent.win_inno_exe, + "url": agent.winagent_dl, + }, + ) sleep(10) @@ -72,28 +57,13 @@ def auto_self_agent_update_task(): for chunk in chunks: for pk in chunk: agent = Agent.objects.get(pk=pk) - if agent.operating_system is not None: - if "64bit" in agent.operating_system: - arch = "64" - elif "32bit" in agent.operating_system: - arch = "32" - else: - arch = "64" - - url = settings.DL_64 if arch == "64" else settings.DL_32 - inno = ( - f"winagent-v{settings.LATEST_AGENT_VER}.exe" - if arch == "64" - else f"winagent-v{settings.LATEST_AGENT_VER}-x86.exe" - ) - - r = agent.salt_api_async( - func="win_agent.do_agent_update_v2", - kwargs={ - "inno": inno, - "url": url, - }, - ) + r = agent.salt_api_async( + func="win_agent.do_agent_update_v2", + kwargs={ + "inno": agent.win_inno_exe, + "url": agent.winagent_dl, + }, + ) sleep(10) diff --git a/api/tacticalrmm/apiv3/views.py b/api/tacticalrmm/apiv3/views.py index 21501e91..c1ad2c9d 100644 --- a/api/tacticalrmm/apiv3/views.py +++ b/api/tacticalrmm/apiv3/views.py @@ -181,7 +181,7 @@ class SaltMinion(APIView): "latestVer": settings.LATEST_SALT_VER, "currentVer": agent.salt_ver, "salt_id": agent.salt_id, - "downloadURL": "changeme", # TODO + "downloadURL": agent.winsalt_dl, } return Response(ret) diff --git a/api/tacticalrmm/tacticalrmm/settings.py b/api/tacticalrmm/tacticalrmm/settings.py index 9084fcea..fceec399 100644 --- a/api/tacticalrmm/tacticalrmm/settings.py +++ b/api/tacticalrmm/tacticalrmm/settings.py @@ -21,6 +21,9 @@ LATEST_AGENT_VER = "0.11.2" DL_64 = f"https://github.com/wh1te909/winagent/releases/download/v{LATEST_AGENT_VER}/winagent-v{LATEST_AGENT_VER}.exe" DL_32 = f"https://github.com/wh1te909/winagent/releases/download/v{LATEST_AGENT_VER}/winagent-v{LATEST_AGENT_VER}-x86.exe" +SALT_64 = f"https://github.com/wh1te909/salt/releases/download/{LATEST_SALT_VER}/salt-minion-setup.exe" +SALT_32 = f"https://github.com/wh1te909/salt/releases/download/{LATEST_SALT_VER}/salt-minion-setup-x86.exe" + try: from .local_settings import * except ImportError: