forked from p15670423/monkey
Added custom config validation errors
This commit is contained in:
parent
026daba3e0
commit
0be9b19186
|
@ -0,0 +1,14 @@
|
||||||
|
import {IP, IP_RANGE} from "./ValidationFormats";
|
||||||
|
|
||||||
|
export default function transformErrors(errors) {
|
||||||
|
return errors.map(error => {
|
||||||
|
if (error.name === "type") {
|
||||||
|
error.message = "Field can't be empty."
|
||||||
|
} else if (error.name === "format" && error.params.format === IP_RANGE) {
|
||||||
|
error.message = "Invalid IP range, refer to description for valid examples."
|
||||||
|
} else if (error.name === "format" && error.params.format === IP) {
|
||||||
|
error.message = "Invalid IP."
|
||||||
|
}
|
||||||
|
return error;
|
||||||
|
});
|
||||||
|
}
|
|
@ -2,12 +2,16 @@ const ipRegex = '((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0
|
||||||
const cidrNotationRegex = '([0-9]|1[0-9]|2[0-9]|3[0-2])'
|
const cidrNotationRegex = '([0-9]|1[0-9]|2[0-9]|3[0-2])'
|
||||||
const hostnameRegex = '^([A-Za-z0-9]*[A-Za-z]+[A-Za-z0-9]*.?)*([A-Za-z0-9]*[A-Za-z]+[A-Za-z0-9]*)$'
|
const hostnameRegex = '^([A-Za-z0-9]*[A-Za-z]+[A-Za-z0-9]*.?)*([A-Za-z0-9]*[A-Za-z]+[A-Za-z0-9]*)$'
|
||||||
|
|
||||||
|
export const IP_RANGE = 'ip-range';
|
||||||
|
export const IP = 'ip';
|
||||||
|
|
||||||
export const formValidationFormats = {
|
export const formValidationFormats = {
|
||||||
'ip-range': buildIpRangeRegex(),
|
[IP_RANGE]: buildIpRangeRegex(),
|
||||||
'ip': buildIpRegex(),
|
[IP]: buildIpRegex()
|
||||||
};
|
};
|
||||||
|
|
||||||
function buildIpRangeRegex(){
|
function buildIpRangeRegex(){
|
||||||
|
console.log(formValidationFormats);
|
||||||
return new RegExp([
|
return new RegExp([
|
||||||
'^'+ipRegex+'$|', // Single: IP
|
'^'+ipRegex+'$|', // Single: IP
|
||||||
'^'+ipRegex+'-'+ipRegex+'$|', // IP range: IP-IP
|
'^'+ipRegex+'-'+ipRegex+'$|', // IP range: IP-IP
|
||||||
|
|
|
@ -10,6 +10,7 @@ import {faInfoCircle} from '@fortawesome/free-solid-svg-icons/faInfoCircle';
|
||||||
import {faCheck} from '@fortawesome/free-solid-svg-icons/faCheck';
|
import {faCheck} from '@fortawesome/free-solid-svg-icons/faCheck';
|
||||||
import {faExclamationCircle} from '@fortawesome/free-solid-svg-icons/faExclamationCircle';
|
import {faExclamationCircle} from '@fortawesome/free-solid-svg-icons/faExclamationCircle';
|
||||||
import {formValidationFormats} from '../configuration-components/ValidationFormats';
|
import {formValidationFormats} from '../configuration-components/ValidationFormats';
|
||||||
|
import transformErrors from '../configuration-components/ValidationErrorMessages';
|
||||||
import InternalConfig from '../configuration-components/InternalConfig';
|
import InternalConfig from '../configuration-components/InternalConfig';
|
||||||
|
|
||||||
const ATTACK_URL = '/api/attack';
|
const ATTACK_URL = '/api/attack';
|
||||||
|
@ -258,8 +259,6 @@ class ConfigurePageComponent extends AuthComponent {
|
||||||
this.setState({attackConfig: res.configuration});
|
this.setState({attackConfig: res.configuration});
|
||||||
this.setInitialAttackConfig(res.configuration);
|
this.setInitialAttackConfig(res.configuration);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
removePBAfile(apiEndpoint, setFilenameFnc) {
|
removePBAfile(apiEndpoint, setFilenameFnc) {
|
||||||
|
@ -341,11 +340,12 @@ class ConfigurePageComponent extends AuthComponent {
|
||||||
setPbaFilenameLinux: this.setPbaFilenameLinux,
|
setPbaFilenameLinux: this.setPbaFilenameLinux,
|
||||||
selectedSection: this.state.selectedSection
|
selectedSection: this.state.selectedSection
|
||||||
})
|
})
|
||||||
formProperties['formData'] = this.state.configuration[this.state.selectedSection]
|
formProperties['formData'] = this.state.configuration[this.state.selectedSection];
|
||||||
formProperties['onChange'] = this.onChange
|
formProperties['onChange'] = this.onChange;
|
||||||
formProperties['customFormats'] = formValidationFormats
|
formProperties['customFormats'] = formValidationFormats;
|
||||||
formProperties['className'] = 'config-form'
|
formProperties['transformErrors'] = transformErrors;
|
||||||
formProperties['liveValidate'] = true
|
formProperties['className'] = 'config-form';
|
||||||
|
formProperties['liveValidate'] = true;
|
||||||
|
|
||||||
if (this.state.selectedSection === 'internal') {
|
if (this.state.selectedSection === 'internal') {
|
||||||
return (<InternalConfig {...formProperties}/>)
|
return (<InternalConfig {...formProperties}/>)
|
||||||
|
|
Loading…
Reference in New Issue