forked from p34709852/monkey
Island: add "was monkey killed by user" endpoint
Using this endpoint monkey can check if kill command was issues and if it should die
This commit is contained in:
parent
6dfa34a133
commit
31cdd29edb
|
@ -10,9 +10,13 @@ from monkey_island.cc.services.infection_lifecycle import set_stop_all
|
|||
class StopAllAgents(flask_restful.Resource):
|
||||
@jwt_required
|
||||
def post(self):
|
||||
data = json.loads(request.data)
|
||||
if data["kill_time"]:
|
||||
set_stop_all(data["kill_time"])
|
||||
return make_response({}, 200)
|
||||
else:
|
||||
return make_response({}, 400)
|
||||
with AGENT_KILLING_SEMAPHORE:
|
||||
data = json.loads(request.data)
|
||||
if data["kill_time"]:
|
||||
set_stop_all(data["kill_time"])
|
||||
return make_response({}, 200)
|
||||
else:
|
||||
return make_response({}, 400)
|
||||
|
||||
def get(self, monkey_guid):
|
||||
return {"stop_agent": was_monkey_killed(monkey_guid)}
|
||||
|
|
|
@ -23,16 +23,8 @@ def set_stop_all(time: float):
|
|||
agent_controls.save()
|
||||
|
||||
|
||||
def should_agent_die(guid: int) -> bool:
|
||||
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
|
||||
|
||||
|
||||
def _is_monkey_killed_manually(monkey: Monkey) -> bool:
|
||||
def was_monkey_killed(guid: int) -> bool:
|
||||
monkey = Monkey.objects(guid=guid).first()
|
||||
if monkey.has_parent():
|
||||
launch_timestamp = monkey.get_parent().launch_time
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue