diff --git a/monkey_island/cc/resources/monkey_configuration.py b/monkey_island/cc/resources/monkey_configuration.py index 091d1e8a7..6d622b1cd 100644 --- a/monkey_island/cc/resources/monkey_configuration.py +++ b/monkey_island/cc/resources/monkey_configuration.py @@ -15,6 +15,9 @@ class MonkeyConfiguration(flask_restful.Resource): def post(self): config_json = json.loads(request.data) - ConfigService.update_config(config_json) + if config_json.has_key('reset'): + ConfigService.reset_config() + else: + ConfigService.update_config(config_json) return self.get() diff --git a/monkey_island/cc/services/config.py b/monkey_island/cc/services/config.py index 268dad49a..2a7016310 100644 --- a/monkey_island/cc/services/config.py +++ b/monkey_island/cc/services/config.py @@ -816,6 +816,10 @@ class ConfigService: def init_config(): if ConfigService.get_config() != {}: return + ConfigService.reset_config() + + @staticmethod + def reset_config(): config = ConfigService.get_default_config() ConfigService.set_server_ips_in_config(config) ConfigService.update_config(config) diff --git a/monkey_island/cc/ui/src/components/pages/ConfigurePage.js b/monkey_island/cc/ui/src/components/pages/ConfigurePage.js index 6b3465320..9bb4c4eeb 100644 --- a/monkey_island/cc/ui/src/components/pages/ConfigurePage.js +++ b/monkey_island/cc/ui/src/components/pages/ConfigurePage.js @@ -14,6 +14,7 @@ class ConfigurePageComponent extends React.Component { schema: {}, configuration: {}, saved: false, + reset: false, sections: [], selectedSection: 'basic' }; @@ -46,6 +47,7 @@ class ConfigurePageComponent extends React.Component { .then(res => { this.setState({ saved: true, + reset: false, schema: res.schema, configuration: res.configuration }); @@ -65,7 +67,7 @@ class ConfigurePageComponent extends React.Component { } this.setState({configuration: newConfig}); }; - + setSelectedSection = (key) => { this.updateConfigSection(); this.currentSection = key; @@ -74,9 +76,27 @@ class ConfigurePageComponent extends React.Component { }); }; + resetConfig = () => { + fetch('/api/configuration', + { + method: 'POST', + headers: {'Content-Type': 'application/json'}, + body: JSON.stringify({'reset': true}) + }) + .then(res => res.json()) + .then(res => { + this.setState({ + reset: true, + saved: false, + schema: res.schema, + configuration: res.configuration + }); + this.props.onStatusChange(); + }); + }; + render() { let displayedSchema = {}; - if (this.state.schema.hasOwnProperty('properties')) { displayedSchema = this.state.schema["properties"][this.state.selectedSection]; displayedSchema["definitions"] = this.state.schema["definitions"]; @@ -100,12 +120,18 @@ class ConfigurePageComponent extends React.Component { onSubmit={this.onSubmit} onChange={this.onChange} /> : ''} - + Reset to defaults
This configuration will only apply to new infections.
+ { this.state.reset ? +
+ + Configuration reset successfully. +
+ : ''} { this.state.saved ?