diff --git a/monkey_island/cc/resources/root.py b/monkey_island/cc/resources/root.py index 3f5ee9dd4..d553e8727 100644 --- a/monkey_island/cc/resources/root.py +++ b/monkey_island/cc/resources/root.py @@ -6,6 +6,7 @@ import flask_restful from cc.database import mongo from cc.services.config import ConfigService from cc.services.node import NodeService +from cc.services.report import ReportService from cc.utils import local_ip_addresses @@ -26,6 +27,7 @@ class Root(flask_restful.Resource): mongo.db.telemetry.drop() mongo.db.node.drop() mongo.db.edge.drop() + mongo.db.report.drop() ConfigService.init_config() return jsonify(status='OK') elif action == "killall": @@ -37,5 +39,6 @@ class Root(flask_restful.Resource): def get_completed_steps(self): is_any_exists = NodeService.is_any_monkey_exists() - is_any_alive = NodeService.is_any_monkey_alive() - return dict(run_server=True, run_monkey=is_any_exists, infection_done=(is_any_exists and not is_any_alive)) + infection_done = NodeService.is_monkey_finished_running() + report_done = ReportService.is_report_generated() + return dict(run_server=True, run_monkey=is_any_exists, infection_done=infection_done, report_done=report_done) diff --git a/monkey_island/cc/services/node.py b/monkey_island/cc/services/node.py index a6ce09438..47cfba8d9 100644 --- a/monkey_island/cc/services/node.py +++ b/monkey_island/cc/services/node.py @@ -281,6 +281,10 @@ class NodeService: def is_any_monkey_exists(): return mongo.db.monkey.find_one({}) is not None + @staticmethod + def is_monkey_finished_running(): + return NodeService.is_any_monkey_exists() and not NodeService.is_any_monkey_alive() + @staticmethod def add_credentials_to_monkey(monkey_id, creds): mongo.db.monkey.update( diff --git a/monkey_island/cc/services/report.py b/monkey_island/cc/services/report.py index ac445ac6a..0fcb71990 100644 --- a/monkey_island/cc/services/report.py +++ b/monkey_island/cc/services/report.py @@ -362,13 +362,27 @@ class ReportService: return warnings_byte_array + @staticmethod + def is_report_generated(): + generated_report = mongo.db.report.find_one({'name': 'generated_report'}) + if generated_report is None: + return False + return generated_report['value'] + + @staticmethod + def set_report_generated(): + mongo.db.report.update( + {'name': 'generated_report'}, + {'$set': {'value': True}}, + upsert=True) + @staticmethod def get_report(): issues = ReportService.get_issues() config_users = ReportService.get_config_users() config_passwords = ReportService.get_config_passwords() - return \ + report = \ { 'overview': { @@ -395,6 +409,12 @@ class ReportService: } } + finished_run = NodeService.is_monkey_finished_running() + if finished_run: + ReportService.set_report_generated() + + return report + @staticmethod def did_exploit_type_succeed(exploit_type): return mongo.db.edge.count( diff --git a/monkey_island/cc/ui/src/components/Main.js b/monkey_island/cc/ui/src/components/Main.js index dd143ea3a..83e2b4042 100644 --- a/monkey_island/cc/ui/src/components/Main.js +++ b/monkey_island/cc/ui/src/components/Main.js @@ -28,7 +28,8 @@ class AppComponent extends React.Component { completedSteps: { run_server: true, run_monkey: false, - infection_done: false + infection_done: false, + report_done: false } }; } @@ -102,6 +103,9 @@ class AppComponent extends React.Component { 4. Security Report + { this.state.completedSteps.report_done ? + + : ''}