From f574af4225c3e9608f7e4fab7e2baae38d67c7ee Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Fri, 16 Jul 2021 13:12:02 +0200 Subject: [PATCH 1/3] ui: Fix bug where we can't change tab from attack to another tab in configure --- .../ui/src/components/pages/ConfigurePage.js | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 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 c7c84e327d9..6f376036c7a 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js @@ -59,6 +59,8 @@ class ConfigurePageComponent extends AuthComponent { getSectionsOrder() { let islandMode = this.props.islandMode ? this.props.islandMode : 'advanced' + // TODO delete the following line before merging + islandMode = 'advanced' return CONFIGURATION_TABS_PER_MODE[islandMode]; } @@ -234,7 +236,11 @@ class ConfigurePageComponent extends AuthComponent { updateConfigSection = () => { let newConfig = this.state.configuration; - if (Object.keys(this.state.currentFormData).length > 0) { + + if (this.currentSection === 'attack' && this.state.currentFormData === undefined) { + this.state.currentFormData = this.state.attackConfig; + } + else if (Object.keys(this.state.currentFormData).length > 0) { newConfig[this.currentSection] = this.state.currentFormData; } this.setState({configuration: newConfig, lastAction: 'none'}); @@ -309,10 +315,16 @@ class ConfigurePageComponent extends AuthComponent { } userChangedConfig() { - if (JSON.stringify(this.state.configuration) === JSON.stringify(this.initialConfig)) { - if (Object.keys(this.state.currentFormData).length === 0 || - JSON.stringify(this.initialConfig[this.currentSection]) === JSON.stringify(this.state.currentFormData)) { - return false; + try { + if (JSON.stringify(this.state.configuration) === JSON.stringify(this.initialConfig)) { + if (Object.keys(this.state.currentFormData).length === 0 || + JSON.stringify(this.initialConfig[this.currentSection]) === JSON.stringify(this.state.currentFormData)) { + return false; + } + } + } catch (TypeError) { + if (JSON.stringify(this.initialConfig[this.currentSection]) === JSON.stringify(this.state.currentFormData)){ + return false; } } return true; @@ -330,10 +342,12 @@ class ConfigurePageComponent extends AuthComponent { } this.updateConfigSection(); this.currentSection = key; + this.setState({ selectedSection: key, currentFormData: this.state.configuration[key] }); + }; resetConfig = () => { From f376c12db1f74a804fa0ba1ced9be090701b8998 Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Fri, 16 Jul 2021 13:12:02 +0200 Subject: [PATCH 2/3] ui: Fix bug where we can't change tab from attack to another tab in configure --- .../cc/ui/src/components/pages/ConfigurePage.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 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 6f376036c7a..d7caea15491 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js @@ -59,13 +59,13 @@ class ConfigurePageComponent extends AuthComponent { getSectionsOrder() { let islandMode = this.props.islandMode ? this.props.islandMode : 'advanced' - // TODO delete the following line before merging - islandMode = 'advanced' return CONFIGURATION_TABS_PER_MODE[islandMode]; } setInitialConfig(config) { // Sets a reference to know if config was changed + config['attack'] = {} + this.currentFormData = {} this.initialConfig = JSON.parse(JSON.stringify(config)); } @@ -230,6 +230,9 @@ class ConfigurePageComponent extends AuthComponent { onChange = ({formData}) => { let configuration = this.state.configuration; + if (this.state.selectedSection === 'attack'){ + formData = {}; + } configuration[this.state.selectedSection] = formData; this.setState({currentFormData: formData, configuration: configuration}); }; @@ -237,10 +240,7 @@ class ConfigurePageComponent extends AuthComponent { updateConfigSection = () => { let newConfig = this.state.configuration; - if (this.currentSection === 'attack' && this.state.currentFormData === undefined) { - this.state.currentFormData = this.state.attackConfig; - } - else if (Object.keys(this.state.currentFormData).length > 0) { + if (Object.keys(this.state.currentFormData).length > 0) { newConfig[this.currentSection] = this.state.currentFormData; } this.setState({configuration: newConfig, lastAction: 'none'}); @@ -340,14 +340,13 @@ class ConfigurePageComponent extends AuthComponent { this.setState({showAttackAlert: true}); return; } + this.updateConfigSection(); this.currentSection = key; - this.setState({ selectedSection: key, currentFormData: this.state.configuration[key] }); - }; resetConfig = () => { @@ -359,6 +358,7 @@ class ConfigurePageComponent extends AuthComponent { }) .then(res => res.json()) .then(res => { + res.configuration['attack'] = {} this.setState({ lastAction: 'reset', schema: res.schema, From 491c44a13bacc6c14c08d7ddde331812c07b00a1 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Mon, 19 Jul 2021 12:23:49 +0300 Subject: [PATCH 3/3] Island UI: remove unnecessary setting of this.currentFormData in ConfigurePage.js because it's a state variable --- monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js | 1 - 1 file changed, 1 deletion(-) 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 d7caea15491..4d7fdd2d08d 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js @@ -65,7 +65,6 @@ class ConfigurePageComponent extends AuthComponent { setInitialConfig(config) { // Sets a reference to know if config was changed config['attack'] = {} - this.currentFormData = {} this.initialConfig = JSON.parse(JSON.stringify(config)); }