forked from p15670423/monkey
Merge pull request #201 from guardicore/fix/bugfix_for_1.6
Fix/bugfix for 1.6
This commit is contained in:
commit
15f56dce97
|
@ -1,6 +1,7 @@
|
||||||
from __future__ import print_function # In python 2.7
|
from __future__ import print_function # In python 2.7
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import os.path
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
|
@ -12,7 +13,8 @@ if BASE_PATH not in sys.path:
|
||||||
|
|
||||||
from cc.island_logger import json_setup_logging
|
from cc.island_logger import json_setup_logging
|
||||||
# This is here in order to catch EVERYTHING, some functions are being called on imports the log init needs to be on top.
|
# This is here in order to catch EVERYTHING, some functions are being called on imports the log init needs to be on top.
|
||||||
json_setup_logging(default_path='.\\monkey_island\\cc\\island_logger_default_config.json', default_level=logging.DEBUG)
|
json_setup_logging(default_path=os.path.join(BASE_PATH, 'cc', 'island_logger_default_config.json'),
|
||||||
|
default_level=logging.DEBUG)
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
from cc.app import init_app
|
from cc.app import init_app
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import flask_restful
|
import flask_restful
|
||||||
from flask import request, jsonify
|
from flask import request, jsonify, abort
|
||||||
|
|
||||||
from cc.auth import jwt_required
|
from cc.auth import jwt_required
|
||||||
from cc.services.config import ConfigService
|
from cc.services.config import ConfigService
|
||||||
|
@ -20,5 +20,6 @@ class MonkeyConfiguration(flask_restful.Resource):
|
||||||
if 'reset' in config_json:
|
if 'reset' in config_json:
|
||||||
ConfigService.reset_config()
|
ConfigService.reset_config()
|
||||||
else:
|
else:
|
||||||
ConfigService.update_config(config_json, should_encrypt=True)
|
if not ConfigService.update_config(config_json, should_encrypt=True):
|
||||||
|
abort(400)
|
||||||
return self.get()
|
return self.get()
|
||||||
|
|
|
@ -977,9 +977,14 @@ class ConfigService:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def update_config(config_json, should_encrypt):
|
def update_config(config_json, should_encrypt):
|
||||||
if should_encrypt:
|
if should_encrypt:
|
||||||
ConfigService.encrypt_config(config_json)
|
try:
|
||||||
|
ConfigService.encrypt_config(config_json)
|
||||||
|
except KeyError as e:
|
||||||
|
logger.error('Bad configuration file was submitted.')
|
||||||
|
return False
|
||||||
mongo.db.config.update({'name': 'newconfig'}, {"$set": config_json}, upsert=True)
|
mongo.db.config.update({'name': 'newconfig'}, {"$set": config_json}, upsert=True)
|
||||||
logger.info('monkey config was updated')
|
logger.info('monkey config was updated')
|
||||||
|
return True
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def init_default_config():
|
def init_default_config():
|
||||||
|
|
|
@ -50,6 +50,13 @@ class ConfigurePageComponent extends AuthComponent {
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
body: JSON.stringify(this.state.configuration)
|
body: JSON.stringify(this.state.configuration)
|
||||||
})
|
})
|
||||||
|
.then(res => {
|
||||||
|
if (!res.ok)
|
||||||
|
{
|
||||||
|
throw Error()
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
})
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(res => {
|
.then(res => {
|
||||||
this.setState({
|
this.setState({
|
||||||
|
@ -58,6 +65,9 @@ class ConfigurePageComponent extends AuthComponent {
|
||||||
configuration: res.configuration
|
configuration: res.configuration
|
||||||
});
|
});
|
||||||
this.props.onStatusChange();
|
this.props.onStatusChange();
|
||||||
|
}).catch(error => {
|
||||||
|
console.log('bad configuration');
|
||||||
|
this.setState({lastAction: 'invalid_configuration'});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -217,6 +227,12 @@ class ConfigurePageComponent extends AuthComponent {
|
||||||
Failed importing configuration. Invalid config file.
|
Failed importing configuration. Invalid config file.
|
||||||
</div>
|
</div>
|
||||||
: ''}
|
: ''}
|
||||||
|
{ this.state.lastAction === 'invalid_configuration' ?
|
||||||
|
<div className="alert alert-danger">
|
||||||
|
<i className="glyphicon glyphicon-exclamation-sign" style={{'marginRight': '5px'}}/>
|
||||||
|
An invalid configuration file was imported and submitted, probably outdated.
|
||||||
|
</div>
|
||||||
|
: ''}
|
||||||
{ this.state.lastAction === 'import_success' ?
|
{ this.state.lastAction === 'import_success' ?
|
||||||
<div className="alert alert-success">
|
<div className="alert alert-success">
|
||||||
<i className="glyphicon glyphicon-ok-sign" style={{'marginRight': '5px'}}/>
|
<i className="glyphicon glyphicon-ok-sign" style={{'marginRight': '5px'}}/>
|
||||||
|
|
Loading…
Reference in New Issue