Finished PBA refactoring
This commit is contained in:
parent
aad9e5069e
commit
fda600eb60
|
@ -9,7 +9,6 @@ class PbaInput extends AuthComponent {
|
|||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
console.log("Constructor called");
|
||||
// set schema from server
|
||||
this.state = this.getStateFromProps(this.props);
|
||||
}
|
||||
|
@ -18,35 +17,24 @@ class PbaInput extends AuthComponent {
|
|||
let options = props.options
|
||||
// set schema from server
|
||||
return {
|
||||
PBAFile: options.PbaFile,
|
||||
filename: options.filename,
|
||||
apiEndpoint: options.apiEndpoint,
|
||||
setPbaFile: options.setPbaFile
|
||||
setPbaFilename: options.setPbaFilename
|
||||
};
|
||||
}
|
||||
|
||||
getPBAfile() {
|
||||
if (this.state.PBAFile.length !== 0) {
|
||||
return this.state.PBAFile
|
||||
return PbaInput.getMockPBAfile(this.state.PBAFile)
|
||||
} else if (this.state.filename) {
|
||||
return PbaInput.getFullPBAfile(this.state.filename)
|
||||
componentDidUpdate(prevProps, prevState, snapshot) {
|
||||
if(prevProps.options.filename !== this.props.options.filename && this.props.options.filename === ""){
|
||||
this.setState({filename: this.props.options.filename})
|
||||
}
|
||||
}
|
||||
|
||||
static getMockPBAfile(mockFile) {
|
||||
let pbaFile = [{
|
||||
name: mockFile.name,
|
||||
source: mockFile.name,
|
||||
options: {
|
||||
type: 'limbo'
|
||||
}
|
||||
}];
|
||||
pbaFile[0].options.file = mockFile;
|
||||
return pbaFile
|
||||
getPBAfile() {
|
||||
if (this.state.filename) {
|
||||
return PbaInput.getFullPBAfile(this.state.filename)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static getFullPBAfile(filename) {
|
||||
return [{
|
||||
source: filename,
|
||||
|
@ -78,9 +66,9 @@ class PbaInput extends AuthComponent {
|
|||
files={this.getPBAfile()}
|
||||
onupdatefiles={fileItems => {
|
||||
if (fileItems.length > 0) {
|
||||
this.state.setPbaFile([fileItems[0].file], fileItems[0].file.name)
|
||||
this.state.setPbaFilename(fileItems[0].file.name)
|
||||
} else {
|
||||
this.state.setPbaFile([], "")
|
||||
this.state.setPbaFilename("")
|
||||
}
|
||||
}}
|
||||
/>)
|
||||
|
|
|
@ -22,10 +22,9 @@ export default function UiSchema(props) {
|
|||
PBA_linux_file: {
|
||||
'ui:widget': PbaInput,
|
||||
'ui:options': {
|
||||
PbaFile: props.configuration.PBAlinuxFile,
|
||||
filename: props.configuration.configuration.monkey.behaviour.PBA_linux_filename,
|
||||
filename: props.PBA_linux_filename,
|
||||
apiEndpoint: API_PBA_LINUX,
|
||||
setPbaFile: props.setPbaFileLinux
|
||||
setPbaFilename: props.setPbaFilenameLinux
|
||||
}
|
||||
},
|
||||
custom_PBA_windows_cmd: {
|
||||
|
@ -35,10 +34,9 @@ export default function UiSchema(props) {
|
|||
PBA_windows_file: {
|
||||
'ui:widget': PbaInput,
|
||||
'ui:options': {
|
||||
PbaFile: props.configuration.PBAwindowsFile,
|
||||
filename: props.configuration.configuration.monkey.behaviour.PBA_windows_filename,
|
||||
filename: props.PBA_windows_filename,
|
||||
apiEndpoint: API_PBA_WINDOWS,
|
||||
setPbaFile: props.setPbaFileWindows
|
||||
setPbaFilename: props.setPbaFilenameWindows
|
||||
}
|
||||
},
|
||||
PBA_linux_filename: {
|
||||
|
@ -66,5 +64,5 @@ export default function UiSchema(props) {
|
|||
}
|
||||
}
|
||||
}
|
||||
return UiSchema[props.configuration.selectedSection]
|
||||
return UiSchema[props.selectedSection]
|
||||
}
|
||||
|
|
|
@ -33,9 +33,6 @@ class ConfigurePageComponent extends AuthComponent {
|
|||
sections: [],
|
||||
selectedSection: 'attack',
|
||||
showAttackAlert: false,
|
||||
|
||||
PBAwindowsFile: [],
|
||||
PBAlinuxFile: []
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -245,7 +242,10 @@ class ConfigurePageComponent extends AuthComponent {
|
|||
this.setInitialConfig(res.configuration);
|
||||
this.props.onStatusChange();
|
||||
}
|
||||
);
|
||||
).then(() => {
|
||||
this.removePBAfile(API_PBA_WINDOWS, this.setPbaFilenameWindows)
|
||||
this.removePBAfile(API_PBA_LINUX, this.setPbaFilenameLinux)
|
||||
});
|
||||
this.authFetch(ATTACK_URL, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
|
@ -257,13 +257,12 @@ class ConfigurePageComponent extends AuthComponent {
|
|||
this.setInitialAttackConfig(res.configuration);
|
||||
})
|
||||
|
||||
this.removePBAfile(API_PBA_WINDOWS, this.setPbaFileWindows)
|
||||
this.removePBAfile(API_PBA_LINUX, this.setPbaFileLinux)
|
||||
|
||||
};
|
||||
|
||||
removePBAfile(apiEndpoint, setParamsFnc) {
|
||||
removePBAfile(apiEndpoint, setFilenameFnc) {
|
||||
this.sendPbaRemoveRequest(apiEndpoint)
|
||||
setParamsFnc([], "")
|
||||
setFilenameFnc("")
|
||||
}
|
||||
|
||||
sendPbaRemoveRequest(apiEndpoint) {
|
||||
|
@ -335,9 +334,11 @@ class ConfigurePageComponent extends AuthComponent {
|
|||
{this.renderBasicNetworkWarning()}
|
||||
<Form schema={displayedSchema}
|
||||
uiSchema={UiSchema({
|
||||
configuration: this.state,
|
||||
setPbaFileWindows: this.setPbaFileWindows,
|
||||
setPbaFileLinux: this.setPbaFileLinux,
|
||||
PBA_linux_filename: this.state.configuration.monkey.behaviour.PBA_linux_filename,
|
||||
PBA_windows_filename: this.state.configuration.monkey.behaviour.PBA_windows_filename,
|
||||
setPbaFilenameWindows: this.setPbaFilenameWindows,
|
||||
setPbaFilenameLinux: this.setPbaFilenameLinux,
|
||||
selectedSection: this.state.selectedSection
|
||||
})}
|
||||
formData={this.state.configuration[this.state.selectedSection]}
|
||||
onChange={this.onChange}
|
||||
|
@ -348,23 +349,18 @@ class ConfigurePageComponent extends AuthComponent {
|
|||
</div>)
|
||||
};
|
||||
|
||||
setPbaFileWindows = (pbaFile, filename) => {
|
||||
let pbaFileDeepCopy = JSON.parse(JSON.stringify(pbaFile))
|
||||
setPbaFilenameWindows = (filename) => {
|
||||
let config = this.state.configuration
|
||||
config.monkey.behaviour.PBA_windows_filename = filename
|
||||
this.setState({
|
||||
PBAwindowsFile: pbaFileDeepCopy,
|
||||
configuration: config
|
||||
})
|
||||
}
|
||||
|
||||
setPbaFileLinux = (pbaFile, filename) => {
|
||||
let pbaFileDeepCopy = JSON.parse(JSON.stringify(pbaFile))
|
||||
setPbaFilenameLinux = (filename) => {
|
||||
let config = this.state.configuration
|
||||
config.monkey.behaviour.PBA_linux_filename = filename
|
||||
console.log(config);
|
||||
this.setState({
|
||||
PBAlinuxFile: pbaFileDeepCopy,
|
||||
configuration: config
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue