cc: Extract ransomware report's exploitation stats component to a separate function

This commit is contained in:
Shreya 2021-07-12 16:47:32 +05:30 committed by Mike Salvatore
parent 3b7d35868a
commit c8e0104985
1 changed files with 17 additions and 11 deletions

View File

@ -22,9 +22,23 @@ class RansomwareReport extends React.Component {
getExploitationStats() { getExploitationStats() {
let num_scanned = this.props.report.propagation_stats.num_scanned_nodes; let num_scanned = this.props.report.propagation_stats.num_scanned_nodes;
let num_exploited = this.props.report.propagation_stats.num_exploited_nodes; let num_exploited = this.props.report.propagation_stats.num_exploited_nodes;
return (
<div>
<p>
The Monkey discovered <span className='badge badge-warning'>{num_scanned}</span> machines
and successfully breached <span className='badge badge-danger'>{num_exploited}</span> of them.
</p>
{this.getExploitationStatsPerExploit()}
</div>
)
}
getExploitationStatsPerExploit() {
let exploit_counts = this.props.report.propagation_stats.num_exploited_per_exploit; let exploit_counts = this.props.report.propagation_stats.num_exploited_per_exploit;
let exploitation_details = []; let exploitation_details = [];
for (let exploit in exploit_counts) { for (let exploit in exploit_counts) {
let count = exploit_counts[exploit]; let count = exploit_counts[exploit];
if (count === 1) { if (count === 1) {
@ -33,7 +47,7 @@ class RansomwareReport extends React.Component {
<span className='badge badge-danger'>{count}</span> machine was exploited by <span className='badge badge-danger'>{count}</span> machine was exploited by
the <span className='badge badge-danger'>{exploit}</span>. the <span className='badge badge-danger'>{exploit}</span>.
</div> </div>
) );
} }
else { else {
exploitation_details.push( exploitation_details.push(
@ -41,19 +55,11 @@ class RansomwareReport extends React.Component {
<span className='badge badge-danger'>{count}</span> machines were exploited by <span className='badge badge-danger'>{count}</span> machines were exploited by
the <span className='badge badge-danger'>{exploit}</span>. the <span className='badge badge-danger'>{exploit}</span>.
</div> </div>
) );
} }
} }
return ( return exploitation_details;
<div>
<p>
The Monkey discovered <span className='badge badge-warning'>{num_scanned}</span> machines
and successfully breached <span className='badge badge-danger'>{num_exploited}</span> of them.
</p>
{exploitation_details}
</div>
)
} }
render() { render() {