From 9a0837656bd0586a8ef16e648671f48ca5b41058 Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Tue, 17 Aug 2021 11:06:34 +0200 Subject: [PATCH] UI: Add hide/show component for credentials --- .../cc/services/config_schema/basic.py | 4 +- .../configuration-components/UiSchema.js | 8 ++++ .../src/components/ui-components/HideInput.js | 44 +++++++++++++++++++ .../ui/src/styles/components/HideInput.scss | 3 ++ 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 monkey/monkey_island/cc/ui/src/components/ui-components/HideInput.js create mode 100644 monkey/monkey_island/cc/ui/src/styles/components/HideInput.scss diff --git a/monkey/monkey_island/cc/services/config_schema/basic.py b/monkey/monkey_island/cc/services/config_schema/basic.py index aba80e08a..27b8f1d6f 100644 --- a/monkey/monkey_island/cc/services/config_schema/basic.py +++ b/monkey/monkey_island/cc/services/config_schema/basic.py @@ -48,7 +48,9 @@ BASIC = { "title": "Exploit password list", "type": "array", "uniqueItems": True, - "items": {"type": "string"}, + "items": { + "type": "string", + }, "default": [ "root", "123456", diff --git a/monkey/monkey_island/cc/ui/src/components/configuration-components/UiSchema.js b/monkey/monkey_island/cc/ui/src/components/configuration-components/UiSchema.js index 38e7ad244..9263ba772 100644 --- a/monkey/monkey_island/cc/ui/src/components/configuration-components/UiSchema.js +++ b/monkey/monkey_island/cc/ui/src/components/configuration-components/UiSchema.js @@ -3,6 +3,7 @@ import PbaInput from './PbaInput'; import {API_PBA_LINUX, API_PBA_WINDOWS} from '../pages/ConfigurePage'; import InfoBox from './InfoBox'; import TextBox from './TextBox'; +import HideInput from '../ui-components/HideInput'; export default function UiSchema(props) { const UiSchema = { @@ -13,6 +14,13 @@ export default function UiSchema(props) { classNames: 'config-template-no-header', 'ui:widget': AdvancedMultiSelect } + }, + credentials : { + exploit_password_list: { + items: { + 'ui:widget': HideInput + } + } } }, basic_network: { diff --git a/monkey/monkey_island/cc/ui/src/components/ui-components/HideInput.js b/monkey/monkey_island/cc/ui/src/components/ui-components/HideInput.js new file mode 100644 index 000000000..148e9dac3 --- /dev/null +++ b/monkey/monkey_island/cc/ui/src/components/ui-components/HideInput.js @@ -0,0 +1,44 @@ +import React from 'react'; +import {InputGroup, FormControl} from 'react-bootstrap'; +import '../../styles/components/HideInput.scss' + +class HideInput extends React.PureComponent { + constructor(props) { + super(props); + + this.state = { + hidden: false + }; + this.toggleShow = this.toggleShow.bind(this); + } + + toggleShow() { + this.setState({hidden: ! this.state.hidden}); + } + + onChange(e) { + var value = e.target.value; + return this.props.onChange(value === '' ? this.props.options.emptyValue : value); + } + + render() { + return ( +
+ + this.onChange(event)} + /> + + + + + + +
+ ); + } +} + +export default HideInput; diff --git a/monkey/monkey_island/cc/ui/src/styles/components/HideInput.scss b/monkey/monkey_island/cc/ui/src/styles/components/HideInput.scss new file mode 100644 index 000000000..85898638c --- /dev/null +++ b/monkey/monkey_island/cc/ui/src/styles/components/HideInput.scss @@ -0,0 +1,3 @@ +.eye-button{ + padding: 5px !important; +}