From 20c68ff25c2799cdd2accf9dfeb78b7f804b943a Mon Sep 17 00:00:00 2001 From: vakarisz Date: Tue, 28 Jun 2022 16:14:40 +0300 Subject: [PATCH] UI: Submit config before exporting Previously config was not getting submitted before exporting. This could cause a misunderstanding where user exports a different configuration to the one he sees on the screen --- .../ui/src/components/pages/ConfigurePage.js | 53 ++++++++++--------- 1 file changed, 27 insertions(+), 26 deletions(-) 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 5f67c9010..b2909afd5 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js @@ -23,6 +23,10 @@ const CONFIG_URL = '/api/configuration/island'; export const API_PBA_LINUX = '/api/file-upload/PBAlinux'; export const API_PBA_WINDOWS = '/api/file-upload/PBAwindows'; +const configSubmitAction = 'config-submit'; +const configExportAction = 'config-export'; +const configSaveAction = 'config-saved'; + class ConfigurePageComponent extends AuthComponent { constructor(props) { @@ -87,14 +91,16 @@ class ConfigurePageComponent extends AuthComponent { }; onUnsafeConfirmationCancelClick = () => { - this.setState({showUnsafeOptionsConfirmation: false}); + this.setState({showUnsafeOptionsConfirmation: false, lastAction: 'none'}); } onUnsafeConfirmationContinueClick = () => { this.setState({showUnsafeOptionsConfirmation: false}); - - if (this.state.lastAction === 'submit_attempt') { + if (this.state.lastAction === configSubmitAction) { this.configSubmit(); + } else if (this.state.lastAction === configExportAction) { + this.configSubmit(); + this.setState({showConfigExportModal: true}); } } @@ -113,37 +119,31 @@ class ConfigurePageComponent extends AuthComponent { }; onSubmit = () => { - this.attemptConfigSubmit(); + this.setState({lastAction: configSubmitAction}, this.attemptConfigSubmit) }; canSafelySubmitConfig(config) { return !isUnsafeOptionSelected(this.state.schema, config); } - checkAndShowUnsafeAttackWarning = () => { - if (isUnsafeOptionSelected(this.state.schema, this.state.configuration)) { - this.setState({showUnsafeAttackOptionsWarning: true}); + async attemptConfigSubmit() { + await this.updateConfigSection(); + if (this.canSafelySubmitConfig(this.state.configuration)) { + this.configSubmit(); + if(this.state.lastAction === configExportAction){ + this.setState({showConfigExportModal: true}) + } + } else { + this.setState({showUnsafeOptionsConfirmation: true}); } } - attemptConfigSubmit() { - this.updateConfigSection(); - this.setState({lastAction: 'submit_attempt'}, () => { - if (this.canSafelySubmitConfig(this.state.configuration)) { - this.configSubmit(); - } else { - this.setState({showUnsafeOptionsConfirmation: true}); - } - } - ); - } - configSubmit() { - this.sendConfig() + return this.sendConfig() .then(res => res.json()) .then(res => { this.setState({ - lastAction: 'saved', + lastAction: configSaveAction, schema: res.schema, configuration: res.configuration }); @@ -167,11 +167,12 @@ class ConfigurePageComponent extends AuthComponent { if (Object.keys(this.state.currentFormData).length > 0) { newConfig[this.currentSection] = this.state.currentFormData; } - this.setState({configuration: newConfig, lastAction: 'none'}); + this.setState({configuration: newConfig}); }; renderConfigExportModal = () => { return ( { this.setState({showConfigExportModal: false}); }}/>); @@ -307,9 +308,9 @@ class ConfigurePageComponent extends AuthComponent { this.authFetch(apiEndpoint, request_options); } - exportConfig = () => { - this.updateConfigSection(); - this.setState({showConfigExportModal: true}); + exportConfig = async () => { + await this.setState({lastAction: configExportAction}); + await this.attemptConfigSubmit(); }; sendConfig() { @@ -451,7 +452,7 @@ class ConfigurePageComponent extends AuthComponent { Configuration reset successfully. : ''} - {this.state.lastAction === 'saved' ? + {this.state.lastAction === configSaveAction ?
Configuration saved successfully.