From a567041fbad102a4a76dd94999c3fa7b147f58f6 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Wed, 8 Dec 2021 10:14:46 +0200 Subject: [PATCH] Island, UI: bugfixes related to stopping of the agents --- monkey/monkey_island/cc/models/monkey.py | 2 +- .../cc/resources/agent_controls/stop_all_agents.py | 4 ++-- monkey/monkey_island/cc/services/infection_lifecycle.py | 6 +++--- monkey/monkey_island/cc/ui/src/components/pages/MapPage.js | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/monkey/monkey_island/cc/models/monkey.py b/monkey/monkey_island/cc/models/monkey.py index 8e7dccc98..af17e45a2 100644 --- a/monkey/monkey_island/cc/models/monkey.py +++ b/monkey/monkey_island/cc/models/monkey.py @@ -108,7 +108,7 @@ class Monkey(Document): def get_parent(self): if self.has_parent(): - Monkey.objects(guid=self.parent[0][0]).first() + return Monkey.objects(guid=self.parent[0][0]).first() else: raise ParentNotFoundError(f"No parent was found for agent with GUID {self.guid}") diff --git a/monkey/monkey_island/cc/resources/agent_controls/stop_all_agents.py b/monkey/monkey_island/cc/resources/agent_controls/stop_all_agents.py index d84ef2f8b..1b41f0cff 100644 --- a/monkey/monkey_island/cc/resources/agent_controls/stop_all_agents.py +++ b/monkey/monkey_island/cc/resources/agent_controls/stop_all_agents.py @@ -5,7 +5,7 @@ from flask import make_response, request from monkey_island.cc.resources.auth.auth import jwt_required from monkey_island.cc.resources.utils.semaphores import AGENT_KILLING_SEMAPHORE -from monkey_island.cc.services.infection_lifecycle import set_stop_all, was_monkey_killed +from monkey_island.cc.services.infection_lifecycle import set_stop_all, should_agent_die class StopAllAgents(flask_restful.Resource): @@ -20,4 +20,4 @@ class StopAllAgents(flask_restful.Resource): return make_response({}, 400) def get(self, monkey_guid): - return {"stop_agent": was_monkey_killed(monkey_guid)} + return {"stop_agent": should_agent_die(monkey_guid)} diff --git a/monkey/monkey_island/cc/services/infection_lifecycle.py b/monkey/monkey_island/cc/services/infection_lifecycle.py index 25cb76c47..e766d2e14 100644 --- a/monkey/monkey_island/cc/services/infection_lifecycle.py +++ b/monkey/monkey_island/cc/services/infection_lifecycle.py @@ -24,12 +24,12 @@ def set_stop_all(time: float): def should_agent_die(guid: int) -> bool: - monkey = Monkey.objects(guid=guid).first() - return _is_monkey_marked_dead(monkey) or _is_monkey_killed_manually() + monkey = Monkey.objects(guid=str(guid)).first() + return _is_monkey_marked_dead(monkey) or _is_monkey_killed_manually(monkey) def _is_monkey_marked_dead(monkey: Monkey) -> bool: - return monkey.config.alive + return not monkey.config.alive def _is_monkey_killed_manually(monkey: Monkey) -> bool: diff --git a/monkey/monkey_island/cc/ui/src/components/pages/MapPage.js b/monkey/monkey_island/cc/ui/src/components/pages/MapPage.js index 8dcfe0ce6..3c1350f58 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/MapPage.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/MapPage.js @@ -84,7 +84,7 @@ class MapPageComponent extends AuthComponent { } killAllMonkeys = () => { - this.authFetch('/api/agent_control/stop-all-agents', + this.authFetch('/api/monkey_control/stop-all-agents', { method: 'POST', headers: {'Content-Type': 'application/json'},