Enhancement to add #11

This commit is contained in:
2018-09-26 10:41:20 -04:00
parent dde7409f01
commit 684d1e4b19
6 changed files with 38 additions and 15 deletions

View File

@ -48,8 +48,6 @@ use Monolog\Handler\StreamHandler;
set_time_limit(0);
$db = new db();
$checklists = [];
$x = 0;
$emass_ccis = null;
$log_level = convert_log_level();
$chk_hosts = filter_input_array(INPUT_POST, 'chk_host');
@ -204,7 +202,6 @@ foreach ($findings as $worksheet_name => $data) {
foreach ($data['stigs'] as $stig_id => $tgt_status) {
$log->debug("Running through STIG $stig_id", $tgt_status);
$ia_controls_string = null;
$notes = '';
// If $do_rmf is set, replace CCIs w/ eMASS RMF Control and build string to
// insert into IA Controls cell, otherwise just use CCIs.
@ -231,7 +228,7 @@ foreach ($findings as $worksheet_name => $data) {
->setCellValue("B{$row}", $tgt_status['echecklist']->get_VMS_ID())
->setCellValue("C{$row}", $tgt_status['echecklist']->get_Cat_Level_String())
->setCellValue("D{$row}", $ia_controls_string)
->setCellValue("E{$row}", str_replace("\\n", "\n", html_entity_decode($tgt_status['echecklist']->get_Short_Title())));
->setCellValue("E{$row}", deduplicateString($tgt_status['echecklist']->get_Short_Title()));
$log->debug("Added STIG info ($stig_id), not to targets");
foreach ($data['target_list'] as $host_name => $col_id) {
@ -262,8 +259,8 @@ foreach ($findings as $worksheet_name => $data) {
->setConditionalStyles([$conditions['true'], $conditions['false']]);
//->setDataValidation($validation['true_false']);
$sheet->setCellValue($notes_col . $row, html_entity_decode($tgt_status['echecklist']->get_Notes()))
->setCellValue($check_contents_col . $row, str_replace("\\n", "\n", html_entity_decode($tgt_status['echecklist']->get_Check_Contents())));
$sheet->setCellValue($notes_col . $row, deduplicateString($tgt_status['echecklist']->get_Notes()))
->setCellValue($check_contents_col . $row, deduplicateString($tgt_status['echecklist']->get_Check_Contents()));
$log->debug("Added remaining cells");
$row++;
@ -489,3 +486,20 @@ function updateHostHeader($sheet, $tgts, &$db) {
->setCellValue('C6', $not_applicable)
->setCellValue('C7', $not_reviewed);
}
/**
* Method to split a string into an array (by new line \n) and use array_unique to remove duplicate strings
*
* @param string $str
*
* @return string
*/
function deduplicateString($str)
{
$ret = null;
$ret = str_replace(["\\n", PHP_EOL], "\r", $str);
$ret = array_unique(explode("\r", $ret));
$ret = html_entity_decode(implode("\r", $ret));
return $ret;
}