fix uninstall for older agents
This commit is contained in:
		@@ -229,10 +229,11 @@ def batch_sysinfo_task():
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@app.task
 | 
					@app.task
 | 
				
			||||||
def uninstall_agent_task(salt_id):
 | 
					def uninstall_agent_task(salt_id, has_nats):
 | 
				
			||||||
    attempts = 0
 | 
					    attempts = 0
 | 
				
			||||||
    error = False
 | 
					    error = False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if not has_nats:
 | 
				
			||||||
        while 1:
 | 
					        while 1:
 | 
				
			||||||
            try:
 | 
					            try:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -123,7 +123,7 @@ class TestAgentViews(TacticalTestCase):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        nats_cmd.assert_called_with({"func": "uninstall"}, wait=False)
 | 
					        nats_cmd.assert_called_with({"func": "uninstall"}, wait=False)
 | 
				
			||||||
        reload_nats.assert_called_once()
 | 
					        reload_nats.assert_called_once()
 | 
				
			||||||
        mock_task.assert_called_with(self.agent.salt_id)
 | 
					        mock_task.assert_called_with(self.agent.salt_id, True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.check_not_authenticated("delete", url)
 | 
					        self.check_not_authenticated("delete", url)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -61,32 +61,32 @@ def update_agents(request):
 | 
				
			|||||||
@api_view()
 | 
					@api_view()
 | 
				
			||||||
def ping(request, pk):
 | 
					def ping(request, pk):
 | 
				
			||||||
    agent = get_object_or_404(Agent, pk=pk)
 | 
					    agent = get_object_or_404(Agent, pk=pk)
 | 
				
			||||||
    if not agent.has_nats:
 | 
					    status = "offline"
 | 
				
			||||||
        return notify_error("Requires agent version 1.1.0 or greater")
 | 
					    if agent.has_nats:
 | 
				
			||||||
    r = asyncio.run(agent.nats_cmd({"func": "ping"}, timeout=10))
 | 
					        r = asyncio.run(agent.nats_cmd({"func": "ping"}, timeout=5))
 | 
				
			||||||
 | 
					        if r == "pong":
 | 
				
			||||||
 | 
					            status = "online"
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
 | 
					        r = agent.salt_api_cmd(timeout=5, func="test.ping")
 | 
				
			||||||
 | 
					        if isinstance(r, bool) and r:
 | 
				
			||||||
 | 
					            status = "online"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if r == "timeout" or r == "natsdown":
 | 
					    return Response({"name": agent.hostname, "status": status})
 | 
				
			||||||
        return Response({"name": agent.hostname, "status": "offline"})
 | 
					 | 
				
			||||||
    elif r == "pong":
 | 
					 | 
				
			||||||
        return Response({"name": agent.hostname, "status": "online"})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return Response({"name": agent.hostname, "status": "offline"})
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@api_view(["DELETE"])
 | 
					@api_view(["DELETE"])
 | 
				
			||||||
def uninstall(request):
 | 
					def uninstall(request):
 | 
				
			||||||
    agent = get_object_or_404(Agent, pk=request.data["pk"])
 | 
					    agent = get_object_or_404(Agent, pk=request.data["pk"])
 | 
				
			||||||
    if not agent.has_nats:
 | 
					    if agent.has_nats:
 | 
				
			||||||
        return notify_error("Requires agent version 1.1.0 or greater")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        asyncio.run(agent.nats_cmd({"func": "uninstall"}, wait=False))
 | 
					        asyncio.run(agent.nats_cmd({"func": "uninstall"}, wait=False))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    salt_id = agent.salt_id
 | 
					    salt_id = agent.salt_id
 | 
				
			||||||
    name = agent.hostname
 | 
					    name = agent.hostname
 | 
				
			||||||
 | 
					    has_nats = agent.has_nats
 | 
				
			||||||
    agent.delete()
 | 
					    agent.delete()
 | 
				
			||||||
    reload_nats()
 | 
					    reload_nats()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    uninstall_agent_task.delay(salt_id)
 | 
					    uninstall_agent_task.delay(salt_id, has_nats)
 | 
				
			||||||
    return Response(f"{name} will now be uninstalled.")
 | 
					    return Response(f"{name} will now be uninstalled.")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -550,7 +550,7 @@ def install_agent(request):
 | 
				
			|||||||
            "&&",
 | 
					            "&&",
 | 
				
			||||||
            "timeout",
 | 
					            "timeout",
 | 
				
			||||||
            "/t",
 | 
					            "/t",
 | 
				
			||||||
            "20",
 | 
					            "10",
 | 
				
			||||||
            "/nobreak",
 | 
					            "/nobreak",
 | 
				
			||||||
            ">",
 | 
					            ">",
 | 
				
			||||||
            "NUL",
 | 
					            "NUL",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -133,7 +133,7 @@ func main() {
 | 
				
			|||||||
		os.Exit(1)
 | 
							os.Exit(1)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	time.Sleep(20 * time.Second)
 | 
						time.Sleep(10 * time.Second)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fmt.Println("Installation starting.")
 | 
						fmt.Println("Installation starting.")
 | 
				
			||||||
	cmd := exec.Command(tacrmm, cmdArgs...)
 | 
						cmd := exec.Command(tacrmm, cmdArgs...)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -36,7 +36,7 @@ If (Get-Service $serviceName -ErrorAction SilentlyContinue) {
 | 
				
			|||||||
        Invoke-WebRequest -Uri $downloadlink -OutFile $OutPath\$output
 | 
					        Invoke-WebRequest -Uri $downloadlink -OutFile $OutPath\$output
 | 
				
			||||||
        Start-Process -FilePath $OutPath\$output -ArgumentList ('/VERYSILENT /SUPPRESSMSGBOXES') -Wait
 | 
					        Start-Process -FilePath $OutPath\$output -ArgumentList ('/VERYSILENT /SUPPRESSMSGBOXES') -Wait
 | 
				
			||||||
        write-host ('Extracting...')
 | 
					        write-host ('Extracting...')
 | 
				
			||||||
        Start-Sleep -s 20
 | 
					        Start-Sleep -s 10
 | 
				
			||||||
        Start-Process -FilePath "C:\Program Files\TacticalAgent\tacticalrmm.exe" -ArgumentList $installArgs -Wait
 | 
					        Start-Process -FilePath "C:\Program Files\TacticalAgent\tacticalrmm.exe" -ArgumentList $installArgs -Wait
 | 
				
			||||||
        exit 0
 | 
					        exit 0
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,7 +15,7 @@ EXE_DIR = os.path.join(BASE_DIR, "tacticalrmm/private/exe")
 | 
				
			|||||||
AUTH_USER_MODEL = "accounts.User"
 | 
					AUTH_USER_MODEL = "accounts.User"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# latest release
 | 
					# latest release
 | 
				
			||||||
TRMM_VERSION = "0.2.0"
 | 
					TRMM_VERSION = "0.2.1"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# bump this version everytime vue code is changed
 | 
					# bump this version everytime vue code is changed
 | 
				
			||||||
# to alert user they need to manually refresh their browser
 | 
					# to alert user they need to manually refresh their browser
 | 
				
			||||||
@@ -123,9 +123,15 @@ AUTH_PASSWORD_VALIDATORS = [
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
 | 
					        "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    {"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",},
 | 
					    {
 | 
				
			||||||
    {"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",},
 | 
					        "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
 | 
				
			||||||
    {"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",},
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user