more agent prep

This commit is contained in:
wh1te909 2020-10-19 03:31:37 +00:00
parent 2928beb6e5
commit ffe3240b27
4 changed files with 43 additions and 45 deletions

View File

@ -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)

View File

@ -29,26 +29,11 @@ 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,
"inno": agent.win_inno_exe,
"url": agent.winagent_dl,
},
)
sleep(10)
@ -72,26 +57,11 @@ 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,
"inno": agent.win_inno_exe,
"url": agent.winagent_dl,
},
)
sleep(10)

View File

@ -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)

View File

@ -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: