forked from p15670423/monkey
Use mongoengine for latest modify time
This commit is contained in:
parent
12eeea68a4
commit
f8004a6b08
|
@ -41,6 +41,10 @@ class Monkey(Document):
|
|||
except IndexError:
|
||||
raise MonkeyNotFoundError("id: {0}".format(str(db_id)))
|
||||
|
||||
@staticmethod
|
||||
def get_latest_modifytime():
|
||||
return Monkey.objects.order_by('-modifytime').first().modifytime
|
||||
|
||||
def is_dead(self):
|
||||
monkey_is_dead = False
|
||||
if self.dead:
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import logging
|
||||
|
||||
from monkey_island.cc.models import Monkey
|
||||
from monkey_island.cc.services.attack.technique_reports import T1210, T1197, T1110
|
||||
from monkey_island.cc.services.attack.attack_config import AttackConfig
|
||||
from monkey_island.cc.database import mongo
|
||||
from monkey_island.cc.services.node import NodeService
|
||||
|
||||
__author__ = "VakarisZ"
|
||||
|
||||
|
@ -29,7 +30,7 @@ class AttackReportService:
|
|||
report =\
|
||||
{
|
||||
'techniques': {},
|
||||
'meta': {'latest_monkey_modifytime': NodeService.get_latest_modified_monkey()[0]['modifytime']},
|
||||
'meta': {'latest_monkey_modifytime': Monkey.get_latest_modifytime()},
|
||||
'name': REPORT_NAME
|
||||
}
|
||||
|
||||
|
@ -50,7 +51,7 @@ class AttackReportService:
|
|||
:return: report dict.
|
||||
"""
|
||||
if AttackReportService.is_report_generated():
|
||||
monkey_modifytime = NodeService.get_latest_modified_monkey()[0]['modifytime']
|
||||
monkey_modifytime = Monkey.get_latest_modifytime()
|
||||
latest_report = mongo.db.attack_report.find_one({'name': REPORT_NAME})
|
||||
report_modifytime = latest_report['meta']['latest_monkey_modifytime']
|
||||
if monkey_modifytime and report_modifytime and monkey_modifytime == report_modifytime:
|
||||
|
|
|
@ -308,10 +308,6 @@ class NodeService:
|
|||
def is_monkey_finished_running():
|
||||
return NodeService.is_any_monkey_exists() and not NodeService.is_any_monkey_alive()
|
||||
|
||||
@staticmethod
|
||||
def get_latest_modified_monkey():
|
||||
return mongo.db.monkey.find({}).sort('modifytime', -1).limit(1)
|
||||
|
||||
@staticmethod
|
||||
def add_credentials_to_monkey(monkey_id, creds):
|
||||
mongo.db.monkey.update(
|
||||
|
|
|
@ -10,6 +10,7 @@ from enum import Enum
|
|||
from six import text_type
|
||||
|
||||
from monkey_island.cc.database import mongo
|
||||
from monkey_island.cc.models import Monkey
|
||||
from monkey_island.cc.report_exporter_manager import ReportExporterManager
|
||||
from monkey_island.cc.services.config import ConfigService
|
||||
from monkey_island.cc.services.edge import EdgeService
|
||||
|
@ -714,7 +715,7 @@ class ReportService:
|
|||
config_users = ReportService.get_config_users()
|
||||
config_passwords = ReportService.get_config_passwords()
|
||||
cross_segment_issues = ReportService.get_cross_segment_issues()
|
||||
monkey_latest_modify_time = list(NodeService.get_latest_modified_monkey())[0]['modifytime']
|
||||
monkey_latest_modify_time = Monkey.get_latest_modifytime()
|
||||
|
||||
report = \
|
||||
{
|
||||
|
@ -779,7 +780,7 @@ class ReportService:
|
|||
|
||||
if latest_report_doc:
|
||||
report_latest_modifytime = latest_report_doc['meta']['latest_monkey_modifytime']
|
||||
latest_monkey_modifytime = NodeService.get_latest_modified_monkey()[0]['modifytime']
|
||||
latest_monkey_modifytime = Monkey.get_latest_modifytime()
|
||||
return report_latest_modifytime == latest_monkey_modifytime
|
||||
|
||||
return False
|
||||
|
|
Loading…
Reference in New Issue