diff --git a/monkey/monkey_island/cc/resources/attack_config.py b/monkey/monkey_island/cc/resources/attack_config.py index 482c3b5fe..ad94f209e 100644 --- a/monkey/monkey_island/cc/resources/attack_config.py +++ b/monkey/monkey_island/cc/resources/attack_config.py @@ -3,7 +3,7 @@ import json from flask import jsonify, request from monkey_island.cc.auth import jwt_required -from monkey_island.cc.services.attack.attack_config import * +import monkey_island.cc.services.attack.attack_config as attack_config __author__ = "VakarisZ" @@ -11,7 +11,7 @@ __author__ = "VakarisZ" class AttackConfiguration(flask_restful.Resource): @jwt_required() def get(self): - return jsonify(configuration=get_config()['properties']) + return jsonify(configuration=attack_config.get_config()['properties']) @jwt_required() def post(self): @@ -21,10 +21,10 @@ class AttackConfiguration(flask_restful.Resource): """ config_json = json.loads(request.data) if 'reset_attack_matrix' in config_json: - reset_config() - return jsonify(configuration=get_config()['properties']) + attack_config.reset_config() + return jsonify(configuration=attack_config.get_config()['properties']) else: - update_config({'properties': json.loads(request.data)}) - apply_to_monkey_config() + attack_config.update_config({'properties': json.loads(request.data)}) + attack_config.apply_to_monkey_config() return {} diff --git a/monkey/monkey_island/cc/ui/src/components/attack/MatrixComponent.js b/monkey/monkey_island/cc/ui/src/components/attack/MatrixComponent.js index 1803a7cd9..fa25307db 100644 --- a/monkey/monkey_island/cc/ui/src/components/attack/MatrixComponent.js +++ b/monkey/monkey_island/cc/ui/src/components/attack/MatrixComponent.js @@ -46,13 +46,7 @@ let parseTechniques = function (data, maxLen) { class MatrixComponent extends AuthComponent { constructor(props) { super(props); - // Copy ATT&CK configuration and parse it for ATT&CK matrix table - let configCopy = JSON.parse(JSON.stringify(this.props.configuration)); - this.state = {lastAction: 'none', - configData: this.props.configuration, - maxTechniques: findMaxTechniques(Object.values(configCopy))}; - this.state.matrixTableData = parseTechniques(Object.values(configCopy), this.state.maxTechniques); - this.state.columns = this.getColumns(this.state.matrixTableData) + this.state = this.getStateFromConfig(this.props.configuration, 'none'); }; getColumns(matrixData) { @@ -68,7 +62,7 @@ class MatrixComponent extends AuthComponent { renderTechnique(technique) { if (technique == null){ - return (
) + return (
) } else { return ( { + this.setState(this.getStateFromConfig(config, lastAction)); + }; + + getStateFromConfig = (config, lastAction) => { let configCopy = JSON.parse(JSON.stringify(config)); let maxTechniques = findMaxTechniques(Object.values(configCopy)); let matrixTableData = parseTechniques(Object.values(configCopy), maxTechniques); let columns = this.getColumns(matrixTableData); - this.setState({ + return { lastAction: lastAction, configData: config, maxTechniques: maxTechniques, matrixTableData: matrixTableData, columns: columns - }); + }; }; // Handles change in technique, when user toggles it diff --git a/monkey/monkey_island/cc/ui/src/components/ui-components/checkbox.js b/monkey/monkey_island/cc/ui/src/components/ui-components/checkbox.js index 0b3f357d9..cde3435ed 100644 --- a/monkey/monkey_island/cc/ui/src/components/ui-components/checkbox.js +++ b/monkey/monkey_island/cc/ui/src/components/ui-components/checkbox.js @@ -1,7 +1,7 @@ import '../../styles/Checkbox.scss' import React from 'react'; -class Checkbox extends React.PureComponent { +class CheckboxComponent extends React.PureComponent { componentDidUpdate(prevProps) { if (this.props.checked !== prevProps.checked) { @@ -20,7 +20,7 @@ class Checkbox extends React.PureComponent { this.ping = this.ping.bind(this); this.composeStateClasses = this.composeStateClasses.bind(this); } - + toggleChecked() { if (this.state.isAnimating) return false; this.setState({ @@ -63,4 +63,4 @@ class Checkbox extends React.PureComponent { } } -export default Checkbox; +export default CheckboxComponent;