From 6e2da3c4a5e153a5954feae713a8e82408a48166 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Fri, 28 May 2021 13:15:42 +0300 Subject: [PATCH] Sketched out the infrastructure of configuration import modal window --- .../ImportConfigModal.tsx | 104 ++++++++++++++++++ .../ui/src/components/pages/ConfigurePage.js | 17 ++- 2 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 monkey/monkey_island/cc/ui/src/components/configuration-components/ImportConfigModal.tsx diff --git a/monkey/monkey_island/cc/ui/src/components/configuration-components/ImportConfigModal.tsx b/monkey/monkey_island/cc/ui/src/components/configuration-components/ImportConfigModal.tsx new file mode 100644 index 000000000..68f2bdea9 --- /dev/null +++ b/monkey/monkey_island/cc/ui/src/components/configuration-components/ImportConfigModal.tsx @@ -0,0 +1,104 @@ +import {Button, Modal, Form} from 'react-bootstrap'; +import React, {useState} from 'react'; + +import AuthComponent from '../AuthComponent'; +import '../../styles/components/configuration-components/ExportConfigModal.scss'; + + +type Props = { + show: boolean, + onClick: () => void +} + +const ConfigImportModal = (props: Props) => { + // TODO implement the back end + const configExportEndpoint = '/api/configuration/export'; + + const [pass, setPass] = useState(''); + const [radioValue, setRadioValue] = useState('password'); + const authComponent = new AuthComponent({}); + + function isExportBtnDisabled() { + return pass === '' && radioValue === 'password'; + } + + function onSubmit() { + authComponent.authFetch(configExportEndpoint, + { + method: 'POST', + headers: {'Content-Type': 'application/json'}, + body: JSON.stringify({ + should_encrypt: (radioValue === 'password'), + password: pass + }) + } + ) + } + + return ( + + + Configuration import + + +
+
+ + + +
+
+ + + +
) +} + +const PasswordInput = (props: { + onChange: (passValue) => void +}) => { + return ( +
+

Encrypt with a password:

+ (props.onChange(evt.target.value))}/> +
+ ) +} + +const ExportPlaintextChoiceField = (props: { + radioValue: string, + onChange: (radioValue) => void +}) => { + return ( +
+ { + props.onChange(evt.target.value); + }} + /> +

+ Configuration might contain stolen credentials or sensitive data.
+ It is advised to use password encryption option. +

+
+ ) +} + + +export default ConfigImportModal; 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 9b2251cd8..55484b175 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js @@ -15,6 +15,7 @@ import UnsafeOptionsConfirmationModal from '../configuration-components/UnsafeOp import UnsafeOptionsWarningModal from '../configuration-components/UnsafeOptionsWarningModal.js'; import isUnsafeOptionSelected from '../utils/SafeOptionValidator.js'; import ConfigExportModal from '../configuration-components/ExportConfigModal'; +import ConfigImportModal from '../configuration-components/ImportConfigModal'; const ATTACK_URL = '/api/attack'; const CONFIG_URL = '/api/configuration/island'; @@ -42,7 +43,8 @@ class ConfigurePageComponent extends AuthComponent { showAttackAlert: false, showUnsafeOptionsConfirmation: false, showUnsafeAttackOptionsWarning: false, - showConfigExportModal: false + showConfigExportModal: false, + showConfigImportModal: false }; } @@ -230,6 +232,14 @@ class ConfigurePageComponent extends AuthComponent { this.setState({showConfigExportModal: false}) } + renderConfigImportModal = () => { + return ()} + + onImport = () => { + this.setState({showConfigImportModal: false}) + } + renderAttackAlertModal = () => { return ( { this.setState({showAttackAlert: false}) @@ -499,6 +509,7 @@ class ConfigurePageComponent extends AuthComponent { lg={{offset: 3, span: 8}} xl={{offset: 2, span: 8}} className={'main'}> {this.renderConfigExportModal()} + {this.renderConfigImportModal()} {this.renderAttackAlertModal()} {this.renderUnsafeOptionsConfirmationModal()} {this.renderUnsafeAttackOptionsWarningModal()} @@ -514,12 +525,10 @@ class ConfigurePageComponent extends AuthComponent {
- -