forked from p15670423/monkey
ui: rework logic to remove unsafeOptionsConfirmed
This commit is contained in:
parent
95af08a5fa
commit
dd7c1bb08c
|
@ -42,15 +42,15 @@ class ConfigurePageComponent extends AuthComponent {
|
||||||
this.sectionsOrder = ['attack', 'basic', 'basic_network', 'monkey', 'internal'];
|
this.sectionsOrder = ['attack', 'basic', 'basic_network', 'monkey', 'internal'];
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
schema: {},
|
|
||||||
configuration: {},
|
|
||||||
attackConfig: {},
|
attackConfig: {},
|
||||||
|
configuration: {},
|
||||||
|
importCandidateConfig: null,
|
||||||
lastAction: 'none',
|
lastAction: 'none',
|
||||||
|
schema: {},
|
||||||
sections: [],
|
sections: [],
|
||||||
selectedSection: 'attack',
|
selectedSection: 'attack',
|
||||||
showAttackAlert: false,
|
showAttackAlert: false,
|
||||||
showUnsafeOptionsConfirmation: false,
|
showUnsafeOptionsConfirmation: false
|
||||||
unsafeOptionsConfirmed: false
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,16 +95,13 @@ class ConfigurePageComponent extends AuthComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
onUnsafeConfirmationContinueClick = () => {
|
onUnsafeConfirmationContinueClick = () => {
|
||||||
this.setState(
|
this.setState({showUnsafeOptionsConfirmation: false});
|
||||||
{unsafeOptionsConfirmed: true, showUnsafeOptionsConfirmation: false},
|
|
||||||
() => {
|
if (this.state.lastAction == 'submit_attempt') {
|
||||||
if (this.state.lastAction == 'submit_attempt') {
|
this.configSubmit();
|
||||||
this.attemptConfigSubmit();
|
} else if (this.state.lastAction == 'import_attempt') {
|
||||||
} else if (this.state.lastAction == 'import_attempt') {
|
this.setConfigFromImportCandidate();
|
||||||
this.attemptSetConfigFromCandidateJson(this.state.candidateConfigJson);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateConfig = () => {
|
updateConfig = () => {
|
||||||
|
@ -125,7 +122,7 @@ class ConfigurePageComponent extends AuthComponent {
|
||||||
};
|
};
|
||||||
|
|
||||||
canSafelySubmitConfig(config) {
|
canSafelySubmitConfig(config) {
|
||||||
return !this.unsafeOptionsSelected(config) || this.state.unsafeOptionsConfirmed;
|
return !this.unsafeOptionsSelected(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafeOptionsSelected(config) {
|
unsafeOptionsSelected(config) {
|
||||||
|
@ -182,15 +179,17 @@ class ConfigurePageComponent extends AuthComponent {
|
||||||
|
|
||||||
attemptConfigSubmit() {
|
attemptConfigSubmit() {
|
||||||
this.updateConfigSection();
|
this.updateConfigSection();
|
||||||
this.setState({lastAction: 'submit_attempt'}, this.configSubmit);
|
this.setState({lastAction: 'submit_attempt'}, () => {
|
||||||
|
if (this.canSafelySubmitConfig(this.state.configuration)) {
|
||||||
|
this.configSubmit()
|
||||||
|
} else {
|
||||||
|
this.setState({showUnsafeOptionsConfirmation: true});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
configSubmit() {
|
configSubmit() {
|
||||||
if (!this.canSafelySubmitConfig(this.state.configuration)) {
|
|
||||||
this.setState({showUnsafeOptionsConfirmation: true});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.sendConfig()
|
this.sendConfig()
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(res => {
|
.then(res => {
|
||||||
|
@ -205,8 +204,6 @@ class ConfigurePageComponent extends AuthComponent {
|
||||||
console.log('Bad configuration: ' + error.toString());
|
console.log('Bad configuration: ' + error.toString());
|
||||||
this.setState({lastAction: 'invalid_configuration'});
|
this.setState({lastAction: 'invalid_configuration'});
|
||||||
});
|
});
|
||||||
|
|
||||||
this.setState({unsafeOptionsConfirmed: false})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alters attack configuration when user toggles technique
|
// Alters attack configuration when user toggles technique
|
||||||
|
@ -359,37 +356,33 @@ class ConfigurePageComponent extends AuthComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
setConfigOnImport = (event) => {
|
setConfigOnImport = (event) => {
|
||||||
this.attemptSetConfigFromCandidateJson(event.target.result);
|
|
||||||
}
|
|
||||||
|
|
||||||
attemptSetConfigFromCandidateJson(newConfigCandidateJson){
|
|
||||||
this.setState({lastAction: 'import_attempt', candidateConfigJson: newConfigCandidateJson},
|
|
||||||
this.setConfigFromCandidateJson
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
setConfigFromCandidateJson(){
|
|
||||||
try {
|
try {
|
||||||
let newConfig = JSON.parse(this.state.candidateConfigJson);
|
var newConfig = JSON.parse(event.target.result);
|
||||||
|
|
||||||
if (!this.canSafelySubmitConfig(newConfig)) {
|
|
||||||
this.setState({showUnsafeOptionsConfirmation: true});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setState({
|
|
||||||
configuration: newConfig,
|
|
||||||
lastAction: 'import_success'
|
|
||||||
}, () => {
|
|
||||||
this.sendConfig();
|
|
||||||
this.setInitialConfig(newConfig)
|
|
||||||
});
|
|
||||||
this.currentFormData = {};
|
|
||||||
} catch (SyntaxError) {
|
} catch (SyntaxError) {
|
||||||
this.setState({lastAction: 'import_failure'});
|
this.setState({lastAction: 'import_failure'});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState({unsafeOptionsConfirmed: false})
|
this.setState({lastAction: 'import_attempt', importCandidateConfig: newConfig},
|
||||||
|
() => {
|
||||||
|
if (this.canSafelySubmitConfig(newConfig)) {
|
||||||
|
this.setConfigFromImportCandidate();
|
||||||
|
} else {
|
||||||
|
this.setState({showUnsafeOptionsConfirmation: true});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
setConfigFromImportCandidate(){
|
||||||
|
this.setState({
|
||||||
|
configuration: this.state.importCandidateConfig,
|
||||||
|
lastAction: 'import_success'
|
||||||
|
}, () => {
|
||||||
|
this.sendConfig();
|
||||||
|
this.setInitialConfig(this.state.importCandidateConfig)
|
||||||
|
});
|
||||||
|
this.currentFormData = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
exportConfig = () => {
|
exportConfig = () => {
|
||||||
|
|
Loading…
Reference in New Issue