#11807 fixed pdf exports in hardening

This commit is contained in:
Daniel Cebrian 2023-09-14 17:56:19 +02:00
parent 8ecb57a498
commit 977a18b829
4 changed files with 198 additions and 62 deletions

View File

@ -252,6 +252,18 @@ $hack_metaconsole = (is_metaconsole() === true) ? '../../' : '';
echo $chart->render(true); echo $chart->render(true);
break; break;
case 'line_graph':
$params['pdf'] = true;
$params['options']['width'] = '100%';
$params['options']['height'] = 200;
$chart = get_build_setup_charts(
'LINE',
$params['options'],
$params['chart_data']
);
echo $chart->render(true);
break;
case 'slicebar': case 'slicebar':
// TO-DO Cambiar esto para que se pase por POST, NO SE PUEDE PASAR POR GET. // TO-DO Cambiar esto para que se pase por POST, NO SE PUEDE PASAR POR GET.
$params['graph_data'] = json_decode(io_safe_output($config[$params['tokem_config']]), true); $params['graph_data'] = json_decode(io_safe_output($config[$params['tokem_config']]), true);

View File

@ -959,7 +959,8 @@ function reporting_make_reporting_data(
case 'vul_by_cat': case 'vul_by_cat':
$report['contents'][] = reporting_vul_by_categories( $report['contents'][] = reporting_vul_by_categories(
$report, $report,
$content $content,
$type
); );
break; break;
@ -980,7 +981,8 @@ function reporting_make_reporting_data(
case 'evolution': case 'evolution':
$report['contents'][] = reporting_evolution_hardening( $report['contents'][] = reporting_evolution_hardening(
$report, $report,
$content $content,
$type
); );
break; break;

View File

@ -528,20 +528,29 @@ function reporting_evolution_graph($table, $item)
* *
* @param object $table Head table or false if it comes from pdf. * @param object $table Head table or false if it comes from pdf.
* @param array $item Items data. * @param array $item Items data.
* @param boolean $pdf If it comes from pdf.
* *
* @return void * @return string
*/ */
function reporting_html_scoring($table, $item) function reporting_html_scoring($table, $item, $pdf=0)
{ {
global $config; global $config;
$table->width = '99%';
$table->styleTable = 'border: 0px;';
$table->colspan[2][0] = 3;
$table1 = new stdClass(); $table1 = new stdClass();
$table1->width = '100%'; $table1->headstyle[0] = 'text-align: left';
$table1->class = 'databox filters'; $table1->headstyle[1] = 'text-align: left';
$table1->styleTable = 'border: 0px;'; $table1->headstyle[2] = 'text-align: left';
$table1->data[0][0] = '<b>'.__('Date').'</b>'; $table1->width = '99%';
$table1->data[0][1] = '<b>'.__('Agent').'</b>'; $table1->class = 'info_table';
$table1->data[0][2] = '<b>'.__('Score').'</b>'; $table1->titleclass = 'title_table_pdf';
$table1->rowclass[0] = '';
$table1->head[0] = '<b>'.__('Id').'</b>';
$table1->head[1] = '<b>'.__('Category').'</b>';
$table1->head[2] = '<b>'.__('Total Failed').'</b>';
$row = 1; $row = 1;
foreach ($item['data'] as $key => $check) { foreach ($item['data'] as $key => $check) {
$table1->data[$row][1] = date($config['date_format'], $check['date']); $table1->data[$row][1] = date($config['date_format'], $check['date']);
@ -550,8 +559,17 @@ function reporting_html_scoring($table, $item)
$row++; $row++;
} }
$table->colspan[2][0] = 3; if ($pdf === 1) {
$table1->title = $item['title'];
$table1->titleclass = 'title_table_pdf';
$table1->titlestyle = 'text-align:left;';
}
$table->data[2][0] = html_print_table($table1, true); $table->data[2][0] = html_print_table($table1, true);
if ($pdf === 1) {
return html_print_table($table1, true);
}
} }
@ -560,27 +578,47 @@ function reporting_html_scoring($table, $item)
* *
* @param object $table Head table or false if it comes from pdf. * @param object $table Head table or false if it comes from pdf.
* @param array $item Items data. * @param array $item Items data.
* @param boolean $pdf If it comes from pdf.
* *
* @return void * @return string
*/ */
function reporting_html_list_checks($table, $item) function reporting_html_list_checks($table, $item, $pdf=0)
{ {
$table->rowclass[0] = ''; $table->width = '99%';
$table->colspan[0][1] = 2; $table->styleTable = 'border: 0px;';
$table->align[3] = 'center'; $table->colspan[2][0] = 4;
$table->data[1][0] = '<b>'.__('Id').'</b>'; $table1 = new stdClass();
$table->data[1][1] = '<b>'.__('Title').'</b>'; $table1->width = '99%';
$table->data[1][2] = '<b>'.__('Category').'</b>'; $table1->headstyle[0] = 'text-align: left';
$table->data[1][3] = '<b>'.__('Status').'</b>'; $table1->headstyle[1] = 'text-align: left';
$table1->headstyle[2] = 'text-align: left';
$table1->class = 'info_table';
$table1->titleclass = 'title_table_pdf';
$table1->rowclass[0] = '';
$table1->head[0] = '<b>'.__('Id').'</b>';
$table1->head[1] = '<b>'.__('Title').'</b>';
$table1->head[2] = '<b>'.__('Category').'</b>';
$table1->head[3] = '<b>'.__('Status').'</b>';
$row = 2; $row = 2;
foreach ($item['data'] as $key => $check) { foreach ($item['data'] as $key => $check) {
$table->data[$row][0] = $check['id']; $table1->data[$row][0] = $check['id'];
$table->data[$row][1] = $check['title']; $table1->data[$row][1] = $check['title'];
$table->data[$row][2] = $check['category']; $table1->data[$row][2] = $check['category'];
$table->data[$row][3] = $check['status']; $table1->data[$row][3] = $check['status'];
$row++; $row++;
} }
if ($pdf === 1) {
$table1->title = $item['title'];
$table1->titleclass = 'title_table_pdf';
$table1->titlestyle = 'text-align:left;';
}
$table->data[2][0] = html_print_table($table1, true);
if ($pdf === 1) {
return html_print_table($table1, true);
}
} }
@ -589,23 +627,45 @@ function reporting_html_list_checks($table, $item)
* *
* @param object $table Head table or false if it comes from pdf. * @param object $table Head table or false if it comes from pdf.
* @param array $item Items data. * @param array $item Items data.
* @param boolean $pdf If it comes from pdf.
* *
* @return void * @return string
*/ */
function reporting_html_top_n_categories_checks($table, $item) function reporting_html_top_n_categories_checks($table, $item, $pdf=0)
{ {
$table->rowclass[0] = ''; $table->width = '99%';
$table->data[1][0] = '<b>'.__('Id').'</b>'; $table->styleTable = 'border: 0px;';
$table->data[1][1] = '<b>'.__('Category').'</b>'; $table->colspan[2][0] = 3;
$table->data[1][2] = '<b>'.__('Total Failed').'</b>'; $table1 = new stdClass();
$table1->width = '99%';
$table1->headstyle[0] = 'text-align: left';
$table1->headstyle[1] = 'text-align: left';
$table1->headstyle[2] = 'text-align: left';
$table1->class = 'info_table';
$table1->titleclass = 'title_table_pdf';
$table1->rowclass[0] = '';
$table1->head[0] = '<b>'.__('Id').'</b>';
$table1->head[1] = '<b>'.__('Category').'</b>';
$table1->head[2] = '<b>'.__('Total Failed').'</b>';
$row = 2; $row = 2;
foreach ($item['data'] as $key => $check) { foreach ($item['data'] as $key => $check) {
$table->data[$row][0] = $check['id']; $table1->data[$row][0] = $check['id'];
$table->data[$row][1] = $check['category']; $table1->data[$row][1] = $check['category'];
$table->data[$row][2] = $check['total']; $table1->data[$row][2] = $check['total'];
$row++; $row++;
} }
if ($pdf === 1) {
$table1->title = $item['title'];
$table1->titleclass = 'title_table_pdf';
$table1->titlestyle = 'text-align:left;';
}
$table->data[2][0] = html_print_table($table1, true);
if ($pdf === 1) {
return html_print_table($table1, true);
}
} }
@ -614,24 +674,46 @@ function reporting_html_top_n_categories_checks($table, $item)
* *
* @param object $table Head table or false if it comes from pdf. * @param object $table Head table or false if it comes from pdf.
* @param array $item Items data. * @param array $item Items data.
* @param boolean $pdf If it comes from pdf.
* *
* @return void * @return string
*/ */
function reporting_html_top_n_checks_failed($table, $item) function reporting_html_top_n_checks_failed($table, $item, $pdf=0)
{ {
global $config; $table->width = '99%';
$table->rowclass[0] = ''; $table->styleTable = 'border: 0px;';
$table->data[1][1] = '<b>'.__('Title').'</b>'; $table->colspan[2][0] = 3;
$table->data[1][2] = '<b>'.__('Total Failed').'</b>'; $table1 = new stdClass();
$table->data[1][3] = '<b>'.__('Description').'</b>'; $table1->width = '99%';
$table1->headstyle[0] = 'text-align: left';
$table1->headstyle[2] = 'text-align: left';
$table1->class = 'info_table';
$table1->titleclass = 'title_table_pdf';
$table1->headstyle[1] = 'width: 10%; text-align: center;';
$table1->style[2] = 'text-align: center;';
$table1->rowclass[0] = '';
$table1->head[0] = '<b>'.__('Title').'</b>';
$table1->head[1] = '<b>'.__('Total Failed').'</b>';
$table1->head[2] = '<b>'.__('Description').'</b>';
$row = 2; $row = 2;
foreach ($item['data'] as $key => $check) { foreach ($item['data'] as $key => $check) {
$table->data[$row][1] = $check['title']; $table1->data[$row][1] = $check['title'];
$table->data[$row][2] = $check['total']; $table1->data[$row][2] = $check['total'];
$table->data[$row][3] = $check['description']; $table1->data[$row][3] = $check['description'];
$row++; $row++;
} }
if ($pdf === 1) {
$table1->title = $item['title'];
$table1->titleclass = 'title_table_pdf';
$table1->titlestyle = 'text-align:left;';
}
$table->data[2][0] = html_print_table($table1, true);
if ($pdf === 1) {
return html_print_table($table1, true);
}
} }
@ -657,24 +739,44 @@ function reporting_vul_by_cat_graph($table, $item)
* *
* @param object $table Head table or false if it comes from pdf. * @param object $table Head table or false if it comes from pdf.
* @param array $item Items data. * @param array $item Items data.
* @param boolean $pdf If it comes from pdf.
* *
* @return void * @return string
*/ */
function reporting_html_top_n_agents_sh($table, $item) function reporting_html_top_n_agents_sh($table, $item, $pdf=0)
{ {
global $config; global $config;
$table->rowclass[0] = ''; $table->width = '99%';
$table->data[1][0] = '<b>'.__('Agent').'</b>'; $table->styleTable = 'border: 0px;';
$table->data[1][1] = '<b>'.__('Last audit scan').'</b>'; $table->colspan[2][0] = 3;
$table->data[1][2] = '<b>'.__('Score').'</b>'; $table1 = new stdClass();
$table1->headstyle = [];
$table1->width = '99%';
$table1->class = 'info_table';
$table1->titleclass = 'title_table_pdf';
$table1->rowclass[0] = '';
$table1->head[0] = '<b>'.__('Agent').'</b>';
$table1->head[1] = '<b>'.__('Last audit scan').'</b>';
$table1->head[2] = '<b>'.__('Score').'</b>';
$row = 2; $row = 2;
foreach ($item['data'] as $key => $agent) { foreach ($item['data'] as $key => $agent) {
$table->data[$row][0] = $agent['alias']; $table1->data[$row][0] = $agent['alias'];
$table->data[$row][1] = date($config['date_format'], $agent['utimestamp']); $table1->data[$row][1] = date($config['date_format'], $agent['utimestamp']);
$table->data[$row][2] = $agent['datos'].' %'; $table1->data[$row][2] = $agent['datos'].' %';
$row++; $row++;
} }
if ($pdf === 1) {
$table1->title = $item['title'];
$table1->titleclass = 'title_table_pdf';
$table1->titlestyle = 'text-align:left;';
}
$table->data[2][0] = html_print_table($table1, true);
if ($pdf === 1) {
return html_print_table($table, true);
}
} }

View File

@ -515,6 +515,26 @@ function line_graph(
$chart_data, $chart_data,
$options $options
) { ) {
if (empty($chart_data) === true) {
if (isset($options['ttl']) === true
&& (int) $options['ttl'] === 2
) {
$options['base64'] = true;
}
return graph_nodata_image($options);
}
if (isset($options['ttl']) === true && (int) $options['ttl'] === 2) {
$params = [
'chart_data' => $chart_data,
'options' => $options,
'return_img_base_64' => true,
];
return generator_chart_to_pdf('line_graph', $params);
}
$chart = get_build_setup_charts('LINE', $options, $chart_data); $chart = get_build_setup_charts('LINE', $options, $chart_data);
return $chart->render(true, true); return $chart->render(true, true);
} }