monkey/monkey_island/cc/resources/root.py

40 lines
1.2 KiB
Python
Raw Normal View History

2017-08-25 22:47:08 +08:00
from datetime import datetime
2017-08-29 19:12:07 +08:00
from flask import request, make_response, jsonify
2017-08-25 22:47:08 +08:00
import flask_restful
from cc.database import mongo
from cc.services.config import ConfigService
2017-08-25 22:47:08 +08:00
from cc.utils import local_ip_addresses
2017-08-25 22:47:08 +08:00
__author__ = 'Barak'
class Root(flask_restful.Resource):
def get(self, action=None):
if not action:
action = request.args.get('action')
2017-08-29 19:12:07 +08:00
2017-08-25 22:47:08 +08:00
if not action:
2017-09-18 19:18:57 +08:00
return jsonify(ip_addresses=local_ip_addresses(), mongo=str(mongo.db), completed_steps=self.get_completed_steps())
2017-08-29 19:12:07 +08:00
2017-08-25 22:47:08 +08:00
elif action == "reset":
mongo.db.config.drop()
mongo.db.monkey.drop()
mongo.db.telemetry.drop()
mongo.db.node.drop()
mongo.db.edge.drop()
ConfigService.init_config()
2017-08-29 19:12:07 +08:00
return jsonify(status='OK')
2017-08-25 22:47:08 +08:00
elif action == "killall":
mongo.db.monkey.update({}, {'$set': {'config.alive': False, 'modifytime': datetime.now()}}, upsert=False,
multi=True)
2017-08-29 19:12:07 +08:00
return 200
2017-08-25 22:47:08 +08:00
else:
2017-08-29 19:12:07 +08:00
return make_response(400, {'error': 'unknown action'})
2017-09-18 19:18:57 +08:00
def get_completed_steps(self):
# TODO implement
return dict(run_server=True, run_monkey=False, infection_done=False)