forked from p34709852/monkey
Small pr refactoring
This commit is contained in:
parent
b17dbdc9de
commit
7c3ba14100
|
@ -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 {}
|
||||
|
||||
|
|
|
@ -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 (<div></div>)
|
||||
return (<div />)
|
||||
} else {
|
||||
return (<Tooltip content={technique.description} direction="down">
|
||||
<Checkbox checked={technique.value}
|
||||
|
@ -119,17 +113,21 @@ class MatrixComponent extends AuthComponent {
|
|||
|
||||
// Updates state based on values in config supplied.
|
||||
updateStateFromConfig = (config, lastAction = '') => {
|
||||
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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue