diff --git a/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js b/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js index bb369fa73..c63356788 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js @@ -74,19 +74,7 @@ class ConfigurePageComponent extends AuthComponent { onSubmit = ({formData}) => { this.currentFormData = formData; this.updateConfigSection(); - this.authFetch('/api/configuration/island', - { - method: 'POST', - headers: {'Content-Type': 'application/json'}, - body: JSON.stringify(this.state.configuration) - }) - .then(res => { - if (!res.ok) - { - throw Error() - } - return res; - }) + this.sendConfig() .then(res => res.json()) .then(res => { this.setState({ @@ -162,7 +150,7 @@ class ConfigurePageComponent extends AuthComponent { configuration: JSON.parse(event.target.result), selectedSection: 'basic', lastAction: 'import_success' - }); + }, () => {this.sendConfig()}); this.currentSection = 'basic'; this.currentFormData = {}; } catch(SyntaxError) { @@ -175,6 +163,26 @@ class ConfigurePageComponent extends AuthComponent { fileDownload(JSON.stringify(this.state.configuration, null, 2), 'monkey.conf'); }; + sendConfig() { + return ( + this.authFetch('/api/configuration/island', + { + method: 'POST', + headers: {'Content-Type': 'application/json'}, + body: JSON.stringify(this.state.configuration) + }) + .then(res => { + if (!res.ok) + { + throw Error() + } + return res; + }).catch(error => { + console.log('bad configuration'); + this.setState({lastAction: 'invalid_configuration'}); + })); + }; + importConfig = (event) => { let reader = new FileReader(); reader.onload = this.onReadFile; @@ -251,13 +259,12 @@ class ConfigurePageComponent extends AuthComponent { } static getFullPBAfile(filename){ - let pbaFile = [{ + return [{ source: filename, options: { type: 'limbo' } }]; - return pbaFile } static getMockPBAfile(mockFile){ @@ -355,7 +362,7 @@ class ConfigurePageComponent extends AuthComponent { { this.state.lastAction === 'invalid_configuration' ?
- An invalid configuration file was imported and submitted, probably outdated. + An invalid configuration file was imported or submitted.
: ''} { this.state.lastAction === 'import_success' ?