fix chart_generator pdf pandora_enterprise#12382
This commit is contained in:
parent
e80b590214
commit
0f9facb999
|
@ -1720,3 +1720,4 @@ include/functions_integriaims.php
|
||||||
include/ajax/integria_incidents.ajax.php
|
include/ajax/integria_incidents.ajax.php
|
||||||
enterprise/operation/log/log_source.php
|
enterprise/operation/log/log_source.php
|
||||||
enterprise/include/class/LogSource.class.php
|
enterprise/include/class/LogSource.class.php
|
||||||
|
include/chart_generator.php
|
|
@ -1,324 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Generate charts with given parameters.
|
|
||||||
*
|
|
||||||
* @category ChartGenerator.
|
|
||||||
* @package Pandora FMS
|
|
||||||
* @subpackage Opensource.
|
|
||||||
* @version 1.0.0
|
|
||||||
* @license See below
|
|
||||||
*
|
|
||||||
* ______ ___ _______ _______ ________
|
|
||||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
|
||||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
|
||||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
|
||||||
*
|
|
||||||
* ============================================================================
|
|
||||||
* Copyright (c) 2005-2023 Pandora FMS
|
|
||||||
* Please see https://pandorafms.com/community/ for full contribution list
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License
|
|
||||||
* as published by the Free Software Foundation for version 2.
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
* ============================================================================
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Begin.
|
|
||||||
require_once __DIR__.'/config.php';
|
|
||||||
require_once __DIR__.'/functions.php';
|
|
||||||
require_once __DIR__.'/functions_db.php';
|
|
||||||
require_once __DIR__.'/auth/mysql.php';
|
|
||||||
require_once $config['homedir'].'/include/lib/User.php';
|
|
||||||
require_once $config['homedir'].'/include/functions_reporting.php';
|
|
||||||
require_once $config['homedir'].'/include/functions_graph.php';
|
|
||||||
require_once $config['homedir'].'/include/functions_custom_graphs.php';
|
|
||||||
require_once $config['homedir'].'/include/functions_modules.php';
|
|
||||||
require_once $config['homedir'].'/include/functions_agents.php';
|
|
||||||
require_once $config['homedir'].'/include/functions_tags.php';
|
|
||||||
|
|
||||||
$data_raw = get_parameter('data');
|
|
||||||
$data_decoded = json_decode(io_safe_output($data_raw), true);
|
|
||||||
if (json_last_error() === JSON_ERROR_NONE) {
|
|
||||||
$data = $data_decoded['data'];
|
|
||||||
$session_id = $data_decoded['session_id'];
|
|
||||||
$type_graph_pdf = $data_decoded['type_graph_pdf'];
|
|
||||||
$id_user = $data_decoded['id_user'];
|
|
||||||
$slicebar = $data_decoded['slicebar'];
|
|
||||||
$slicebar_value = $data_decoded['slicebar_value'];
|
|
||||||
|
|
||||||
$data_combined = [];
|
|
||||||
if (isset($data_decoded['data_combined']) === true) {
|
|
||||||
$data_combined = $data_decoded['data_combined'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$data_module_list = [];
|
|
||||||
if (isset($data_decoded['data_module_list']) === true) {
|
|
||||||
$data_module_list = $data_decoded['data_module_list'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize session.
|
|
||||||
global $config;
|
|
||||||
|
|
||||||
// Care whit this!!! check_login not working if you remove this.
|
|
||||||
$config['id_user'] = $id_user;
|
|
||||||
$_SESSION['id_usuario'] = $id_user;
|
|
||||||
|
|
||||||
// Checks for server api req.
|
|
||||||
$bypassLogin = false;
|
|
||||||
if ($data_decoded['apipass'] !== null
|
|
||||||
&& ($config['server_unique_identifier'] === $_SESSION['id_usuario'])
|
|
||||||
) {
|
|
||||||
$apiPassword = io_output_password(
|
|
||||||
db_get_value_filter(
|
|
||||||
'value',
|
|
||||||
'tconfig',
|
|
||||||
['token' => 'api_password']
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
if ($apiPassword === $data_decoded['apipass']) {
|
|
||||||
$bypassLogin = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($config[$slicebar])) {
|
|
||||||
$config[$slicebar] = $slicebar_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to initialize session using existing php session id.
|
|
||||||
$user = new PandoraFMS\User(['phpsessionid' => $session_id]);
|
|
||||||
|
|
||||||
if (check_login(false) === false && $bypassLogin !== true) {
|
|
||||||
// Error handler.
|
|
||||||
?>
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
||||||
<title>Access denied</title>
|
|
||||||
<link rel="stylesheet" href="styles/pandora.css?v=<?php echo $config['current_package']; ?>" type="text/css" />
|
|
||||||
<link rel="stylesheet" href="styles/pandora_minimal.css?v=<?php echo $config['current_package']; ?>" type="text/css" />
|
|
||||||
<link rel="stylesheet" href="styles/js/jquery-ui.min.css?v=<?php echo $config['current_package']; ?>" type="text/css" />
|
|
||||||
<link rel="stylesheet" href="styles/js/jquery-ui_custom.css?v=<?php echo $config['current_package']; ?>" type="text/css" />
|
|
||||||
<script language="javascript" type='text/javascript' src='javascript/pandora.js?v=<?php echo $config['current_package']; ?>'></script>
|
|
||||||
<script language="javascript" type='text/javascript' src='javascript/pandora_ui.js?v=<?php echo $config['current_package']; ?>'></script>
|
|
||||||
<script language="javascript" type='text/javascript' src='javascript/jquery.current.js?v=<?php echo $config['current_package']; ?>'></script>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>Access is not granted</h1>
|
|
||||||
<div id="container-chart-generator-item" style="display:none; margin:0px;width:100px;height:100px;">
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
||||||
<?php
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Access granted.
|
|
||||||
$params = $data;
|
|
||||||
if (isset($params['backgroundColor']) === false) {
|
|
||||||
$params['backgroundColor'] = 'inherit';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Metaconsole connection to the node.
|
|
||||||
$server_id = 0;
|
|
||||||
if (isset($params['server_id']) === true) {
|
|
||||||
$server_id = $params['server_id'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_metaconsole() === true && empty($server_id) === false) {
|
|
||||||
$server = metaconsole_get_connection_by_id($server_id);
|
|
||||||
// Error connecting.
|
|
||||||
if (metaconsole_connect($server) !== NOERR) {
|
|
||||||
?>
|
|
||||||
<html>
|
|
||||||
<body>
|
|
||||||
<?php
|
|
||||||
ui_print_error_message(
|
|
||||||
__('There was a problem connecting with the node')
|
|
||||||
);
|
|
||||||
?>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
<?php
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$user_language = get_user_language($config['id_user']);
|
|
||||||
if (file_exists('languages/'.$user_language.'.mo') === true) {
|
|
||||||
$cfr = new CachedFileReader('languages/'.$user_language.'.mo');
|
|
||||||
$l10n = new gettext_reader($cfr);
|
|
||||||
$l10n->load_tables();
|
|
||||||
}
|
|
||||||
|
|
||||||
$hack_metaconsole = (is_metaconsole() === true) ? '../../' : '';
|
|
||||||
?>
|
|
||||||
<!DOCTYPE>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
||||||
<title>Pandora FMS Graph</title>
|
|
||||||
<link rel="stylesheet" href="<?php echo ui_get_full_url($hack_metaconsole.'include/styles/pandora.css'); ?>?v=<?php echo $config['current_package']; ?>" type="text/css" />
|
|
||||||
<link rel="stylesheet" href="<?php echo ui_get_full_url($hack_metaconsole.'include/styles/pandora_minimal.css'); ?>?v=<?php echo $config['current_package']; ?>" type="text/css" />
|
|
||||||
<link rel="stylesheet" href="<?php echo ui_get_full_url($hack_metaconsole.'include/styles/js/jquery-ui.min.css'); ?>?v=<?php echo $config['current_package']; ?>" type="text/css" />
|
|
||||||
<link rel="stylesheet" href="<?php echo ui_get_full_url($hack_metaconsole.'include/styles/js/jquery-ui_custom.css'); ?>?v=<?php echo $config['current_package']; ?>" type="text/css" />
|
|
||||||
<script language="javascript" type='text/javascript' src='<?php echo ui_get_full_url($hack_metaconsole.'include/javascript/pandora_ui.js'); ?>?v=<?php echo $config['current_package']; ?>'></script>
|
|
||||||
<script language="javascript" type='text/javascript' src='<?php echo ui_get_full_url($hack_metaconsole.'include/javascript/jquery.current.js'); ?>?v=<?php echo $config['current_package']; ?>'></script>
|
|
||||||
<script language="javascript" type='text/javascript' src='<?php echo ui_get_full_url($hack_metaconsole.'include/javascript/jquery.pandora.js'); ?>?v=<?php echo $config['current_package']; ?>'></script>
|
|
||||||
<script language="javascript" type='text/javascript' src='<?php echo ui_get_full_url($hack_metaconsole.'include/javascript/jquery-ui.min.js'); ?>?v=<?php echo $config['current_package']; ?>'></script>
|
|
||||||
<script language="javascript" type='text/javascript' src='<?php echo ui_get_full_url($hack_metaconsole.'include/javascript/pandora.js'); ?>?v=<?php echo $config['current_package']; ?>'></script>
|
|
||||||
<script language="javascript" type="text/javascript" src="<?php echo ui_get_full_url($hack_metaconsole.'include/graphs/flot/jquery.flot.js'); ?>?v=<?php echo $config['current_package']; ?>"></script>
|
|
||||||
<script language="javascript" type="text/javascript" src="<?php echo ui_get_full_url($hack_metaconsole.'include/graphs/flot/jquery.flot.min.js'); ?>?v=<?php echo $config['current_package']; ?>"></script>
|
|
||||||
<script language="javascript" type="text/javascript" src="<?php echo ui_get_full_url($hack_metaconsole.'include/graphs/flot/jquery.flot.time.js'); ?>?v=<?php echo $config['current_package']; ?>"></script>
|
|
||||||
<script language="javascript" type="text/javascript" src="<?php echo ui_get_full_url($hack_metaconsole.'include/graphs/flot/jquery.flot.pie.js'); ?>?v=<?php echo $config['current_package']; ?>"></script>
|
|
||||||
<script language="javascript" type="text/javascript" src="<?php echo ui_get_full_url($hack_metaconsole.'include/graphs/flot/jquery.flot.crosshair.min.js'); ?>?v=<?php echo $config['current_package']; ?>"></script>
|
|
||||||
<script language="javascript" type="text/javascript" src="<?php echo ui_get_full_url($hack_metaconsole.'include/graphs/flot/jquery.flot.stack.min.js'); ?>?v=<?php echo $config['current_package']; ?>"></script>
|
|
||||||
<script language="javascript" type="text/javascript" src="<?php echo ui_get_full_url($hack_metaconsole.'include/graphs/flot/jquery.flot.selection.min.js'); ?>?v=<?php echo $config['current_package']; ?>"></script>
|
|
||||||
<script language="javascript" type="text/javascript" src="<?php echo ui_get_full_url($hack_metaconsole.'include/graphs/flot/jquery.flot.resize.min.js'); ?>?v=<?php echo $config['current_package']; ?>"></script>
|
|
||||||
<script language="javascript" type="text/javascript" src="<?php echo ui_get_full_url($hack_metaconsole.'include/graphs/flot/jquery.flot.threshold.js'); ?>?v=<?php echo $config['current_package']; ?>"></script>
|
|
||||||
<script language="javascript" type="text/javascript" src="<?php echo ui_get_full_url($hack_metaconsole.'include/graphs/flot/jquery.flot.threshold.multiple.js'); ?>?v=<?php echo $config['current_package']; ?>"></script>
|
|
||||||
<script language="javascript" type="text/javascript" src="<?php echo ui_get_full_url($hack_metaconsole.'include/graphs/flot/jquery.flot.symbol.min.js'); ?>?v=<?php echo $config['current_package']; ?>"></script>
|
|
||||||
<script language="javascript" type="text/javascript" src="<?php echo ui_get_full_url($hack_metaconsole.'include/graphs/flot/jquery.flot.exportdata.pandora.js'); ?>?v=<?php echo $config['current_package']; ?>"></script>
|
|
||||||
<script language="javascript" type="text/javascript" src="<?php echo ui_get_full_url($hack_metaconsole.'include/graphs/flot/jquery.flot.axislabels.js'); ?>?v=<?php echo $config['current_package']; ?>"></script>
|
|
||||||
<script type="text/javascript">
|
|
||||||
var phpTimezone = "<?php echo date_default_timezone_get(); ?>";
|
|
||||||
</script>
|
|
||||||
<script language="javascript" type="text/javascript" src="<?php echo ui_get_full_url($hack_metaconsole.'include/graphs/flot/pandora.flot.js'); ?>?v=<?php echo $config['current_package']; ?>"></script>
|
|
||||||
<script language="javascript" type="text/javascript" src="<?php echo ui_get_full_url($hack_metaconsole.'include/graphs/chartjs/chart.js'); ?>?v=<?php echo $config['current_package']; ?>"></script>
|
|
||||||
<script language="javascript" type="text/javascript" src="<?php echo ui_get_full_url($hack_metaconsole.'include/graphs/chartjs/chartjs-plugin-datalabels.min.js'); ?>?v=<?php echo $config['current_package']; ?>"></script>
|
|
||||||
</head>
|
|
||||||
<body style='width:794px; margin: 0px; background-color: <?php echo $params['backgroundColor']; ?>;'>
|
|
||||||
<?php
|
|
||||||
$params['only_image'] = false;
|
|
||||||
$params['menu'] = false;
|
|
||||||
|
|
||||||
$params['disable_black'] = true;
|
|
||||||
$params_combined = $data_combined;
|
|
||||||
$module_list = $data_module_list;
|
|
||||||
|
|
||||||
$viewport = [
|
|
||||||
'width' => 0,
|
|
||||||
'height' => 0,
|
|
||||||
];
|
|
||||||
|
|
||||||
$style = 'width:100%;';
|
|
||||||
if (isset($params['options']['viewport']) === true) {
|
|
||||||
$viewport = $params['options']['viewport'];
|
|
||||||
if (empty($viewport['width']) === false) {
|
|
||||||
$style .= 'width:'.$viewport['width'].'px;';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($viewport['height']) === false) {
|
|
||||||
$style .= 'height:'.$viewport['height'].'px;';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
echo '<div id="container-chart-generator-item" style="'.$style.' margin:0px;">';
|
|
||||||
switch ($type_graph_pdf) {
|
|
||||||
case 'combined':
|
|
||||||
$params['pdf'] = true;
|
|
||||||
$result = graphic_combined_module(
|
|
||||||
$module_list,
|
|
||||||
$params,
|
|
||||||
$params_combined
|
|
||||||
);
|
|
||||||
|
|
||||||
echo $result;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'sparse':
|
|
||||||
$params['pdf'] = true;
|
|
||||||
echo grafico_modulo_sparse($params);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'pie_graph':
|
|
||||||
$params['pdf'] = true;
|
|
||||||
$chart = get_build_setup_charts(
|
|
||||||
'PIE',
|
|
||||||
$params['options'],
|
|
||||||
$params['chart_data']
|
|
||||||
);
|
|
||||||
|
|
||||||
echo $chart->render(true);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'vbar_graph':
|
|
||||||
$params['pdf'] = true;
|
|
||||||
$chart = get_build_setup_charts(
|
|
||||||
'BAR',
|
|
||||||
$params['options'],
|
|
||||||
$params['chart_data']
|
|
||||||
);
|
|
||||||
|
|
||||||
echo $chart->render(true);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'ring_graph':
|
|
||||||
$params['pdf'] = true;
|
|
||||||
$params['options']['width'] = 500;
|
|
||||||
$params['options']['height'] = 500;
|
|
||||||
|
|
||||||
$chart = get_build_setup_charts(
|
|
||||||
'DOUGHNUT',
|
|
||||||
$params['options'],
|
|
||||||
$params['chart_data']
|
|
||||||
);
|
|
||||||
|
|
||||||
echo $chart->render(true);
|
|
||||||
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':
|
|
||||||
// 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);
|
|
||||||
delete_config_token($params['tokem_config']);
|
|
||||||
echo flot_slicesbar_graph(
|
|
||||||
$params['graph_data'],
|
|
||||||
$params['period'],
|
|
||||||
$params['width'],
|
|
||||||
$params['height'],
|
|
||||||
$params['legend'],
|
|
||||||
$params['colors'],
|
|
||||||
$params['fontpath'],
|
|
||||||
$params['round_corner'],
|
|
||||||
$params['homeurl'],
|
|
||||||
$params['watermark'],
|
|
||||||
$params['adapt_key'],
|
|
||||||
$params['stat_winalse'],
|
|
||||||
$params['id_agent'],
|
|
||||||
$params['full_legend_daterray'],
|
|
||||||
$params['not_interactive'],
|
|
||||||
$params['ttl'],
|
|
||||||
$params['sizeForTicks'],
|
|
||||||
$params['show'],
|
|
||||||
$params['date_to'],
|
|
||||||
$params['server_id']
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
// Code...
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
echo '</div>';
|
|
||||||
?>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -4310,48 +4310,22 @@ function generator_chart_to_pdf(
|
||||||
$module_list=false
|
$module_list=false
|
||||||
) {
|
) {
|
||||||
global $config;
|
global $config;
|
||||||
|
$hack_metaconsole = '';
|
||||||
if (is_metaconsole()) {
|
if (is_metaconsole() === true) {
|
||||||
$hack_metaconsole = '../..';
|
$hack_metaconsole = '../..';
|
||||||
} else {
|
|
||||||
$hack_metaconsole = '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$url = ui_get_full_url(false).$hack_metaconsole.'/include/chart_generator.php';
|
|
||||||
|
|
||||||
if (!$params['return_img_base_64']) {
|
if (!$params['return_img_base_64']) {
|
||||||
$img_file = 'img_'.uniqid().'.png';
|
$img_file = 'img_'.uniqid().'.png';
|
||||||
$img_path = $config['homedir'].'/attachment/'.$img_file;
|
$img_path = $config['homedir'].'/attachment/'.$img_file;
|
||||||
$img_url = ui_get_full_url(false).$hack_metaconsole.'/attachment/'.$img_file;
|
$img_url = ui_get_full_url(false).$hack_metaconsole.'/attachment/'.$img_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
$session_id = session_id();
|
if ($type_graph_pdf !== 'combined') {
|
||||||
if ($type_graph_pdf === 'combined') {
|
$params_combined = [];
|
||||||
$data = [
|
$module_list = [];
|
||||||
'data' => $params,
|
|
||||||
'session_id' => $session_id,
|
|
||||||
'type_graph_pdf' => $type_graph_pdf,
|
|
||||||
'data_module_list' => $module_list,
|
|
||||||
'data_combined' => $params_combined,
|
|
||||||
'id_user' => $config['id_user'],
|
|
||||||
'slicebar' => $_SESSION['slicebar'],
|
|
||||||
'slicebar_value' => $config[$_SESSION['slicebar']],
|
|
||||||
'apipass' => get_parameter('apipass', null),
|
|
||||||
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
$data = [
|
|
||||||
'data' => $params,
|
|
||||||
'session_id' => $session_id,
|
|
||||||
'type_graph_pdf' => $type_graph_pdf,
|
|
||||||
'id_user' => $config['id_user'],
|
|
||||||
'slicebar' => $_SESSION['slicebar'],
|
|
||||||
'slicebar_value' => $config[$_SESSION['slicebar']],
|
|
||||||
'apipass' => get_parameter('apipass', null),
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($data['data']['graph_data']);
|
|
||||||
// If not install chromium avoid 500 convert tu images no data to show.
|
// If not install chromium avoid 500 convert tu images no data to show.
|
||||||
$chromium_dir = io_safe_output($config['chromium_path']);
|
$chromium_dir = io_safe_output($config['chromium_path']);
|
||||||
$result_ejecution = exec($chromium_dir.' --version');
|
$result_ejecution = exec($chromium_dir.' --version');
|
||||||
|
@ -4371,22 +4345,16 @@ function generator_chart_to_pdf(
|
||||||
|
|
||||||
// Creates a new page.
|
// Creates a new page.
|
||||||
$page = $browser->createPage();
|
$page = $browser->createPage();
|
||||||
$curl = curl_init();
|
|
||||||
|
|
||||||
curl_setopt($curl, CURLOPT_URL, $url);
|
// Generate Html.
|
||||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
$html = chart_generator(
|
||||||
curl_setopt($curl, CURLOPT_POSTFIELDS, ['data' => json_encode($data)]);
|
$type_graph_pdf,
|
||||||
|
$params,
|
||||||
|
$params_combined,
|
||||||
|
$module_list
|
||||||
|
);
|
||||||
|
|
||||||
$response = curl_exec($curl);
|
$page->setHtml($html);
|
||||||
|
|
||||||
curl_close($curl);
|
|
||||||
|
|
||||||
$page->setHtml($response);
|
|
||||||
/*
|
|
||||||
//For debug url with parameters.
|
|
||||||
$navigation = $page->navigate($url.'?data='.urlencode(json_encode($data)));
|
|
||||||
$navigation->waitForNavigation(Page::DOM_CONTENT_LOADED);
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Dynamic.
|
// Dynamic.
|
||||||
$dynamic_height = $page->evaluate('document.getElementById("container-chart-generator-item").clientHeight')->getReturnValue();
|
$dynamic_height = $page->evaluate('document.getElementById("container-chart-generator-item").clientHeight')->getReturnValue();
|
||||||
|
@ -4433,6 +4401,211 @@ function generator_chart_to_pdf(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Html print chart for chromium
|
||||||
|
*
|
||||||
|
* @param string $type_graph_pdf Chart mode.
|
||||||
|
* @param array $params Params.
|
||||||
|
* @param array $params_combined Params Combined charts.
|
||||||
|
* @param array $module_list Module list Combined charts.
|
||||||
|
*
|
||||||
|
* @return string Output Html.
|
||||||
|
*/
|
||||||
|
function chart_generator(
|
||||||
|
string $type_graph_pdf,
|
||||||
|
array $params,
|
||||||
|
array $params_combined=[],
|
||||||
|
array $module_list=[]
|
||||||
|
) : string {
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
include_once $config['homedir'].'/include/graphs/functions_d3.php';
|
||||||
|
|
||||||
|
if (isset($params['backgroundColor']) === false) {
|
||||||
|
$params['backgroundColor'] = 'inherit';
|
||||||
|
}
|
||||||
|
|
||||||
|
$hack_metaconsole = (is_metaconsole() === true) ? '../../' : '';
|
||||||
|
|
||||||
|
$output = '<!DOCTYPE>';
|
||||||
|
$output .= '<html>';
|
||||||
|
$output .= '<head>';
|
||||||
|
$output .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
|
||||||
|
$output .= '<title>Pandora FMS Graph</title>';
|
||||||
|
$output .= '<script type="text/javascript">';
|
||||||
|
$output .= 'var phpTimezone = "'.date_default_timezone_get().'";';
|
||||||
|
$output .= 'var configHomeurl = "'.((is_metaconsole() === false) ? $config['homeurl'] : '../../').'";';
|
||||||
|
$output .= '</script>';
|
||||||
|
|
||||||
|
$css_files = [
|
||||||
|
'pandora' => 'include/styles/',
|
||||||
|
'pandora_minimal' => 'include/styles/',
|
||||||
|
'jquery-ui.min' => 'include/styles/js/',
|
||||||
|
'jquery-ui_custom' => 'include/styles/js/',
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($css_files as $name => $path) {
|
||||||
|
$output .= ui_require_css_file($name, $path, true, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$js_files = [
|
||||||
|
'pandora_ui' => 'include/javascript/',
|
||||||
|
'jquery.current' => 'include/javascript/',
|
||||||
|
'jquery.pandora' => 'include/javascript/',
|
||||||
|
'jquery-ui.min' => 'include/javascript/',
|
||||||
|
'date' => 'include/javascript/timezone/src/',
|
||||||
|
'pandora' => 'include/javascript/',
|
||||||
|
'jquery.flot' => 'include/graphs/flot/',
|
||||||
|
'jquery.flot.min' => 'include/graphs/flot/',
|
||||||
|
'jquery.flot.time' => 'include/graphs/flot/',
|
||||||
|
'jquery.flot.pie' => 'include/graphs/flot/',
|
||||||
|
'jquery.flot.crosshair.min' => 'include/graphs/flot/',
|
||||||
|
'jquery.flot.stack.min' => 'include/graphs/flot/',
|
||||||
|
'jquery.flot.selection.min' => 'include/graphs/flot/',
|
||||||
|
'jquery.flot.resize.min' => 'include/graphs/flot/',
|
||||||
|
'jquery.flot.threshold' => 'include/graphs/flot/',
|
||||||
|
'jquery.flot.threshold.multiple' => 'include/graphs/flot/',
|
||||||
|
'jquery.flot.symbol.min' => 'include/graphs/flot/',
|
||||||
|
'jquery.flot.exportdata.pandora' => 'include/graphs/flot/',
|
||||||
|
'jquery.flot.axislabels' => 'include/graphs/flot/',
|
||||||
|
'pandora.flot' => 'include/graphs/flot/',
|
||||||
|
'chart' => 'include/graphs/chartjs/',
|
||||||
|
'chartjs-plugin-datalabels.min' => 'include/graphs/chartjs/',
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($js_files as $name => $path) {
|
||||||
|
$output .= ui_require_javascript_file($name, $path, true, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$output .= include_javascript_d3(true, true);
|
||||||
|
|
||||||
|
$output .= '</head>';
|
||||||
|
$output .= '<body style="width:794px; margin: 0px; background-color:'.$params['backgroundColor'].';">';
|
||||||
|
$params['only_image'] = false;
|
||||||
|
$params['menu'] = false;
|
||||||
|
$params['disable_black'] = true;
|
||||||
|
|
||||||
|
$viewport = [
|
||||||
|
'width' => 0,
|
||||||
|
'height' => 0,
|
||||||
|
];
|
||||||
|
|
||||||
|
$style = 'width:100%;';
|
||||||
|
if (isset($params['options']['viewport']) === true) {
|
||||||
|
$viewport = $params['options']['viewport'];
|
||||||
|
if (empty($viewport['width']) === false) {
|
||||||
|
$style .= 'width:'.$viewport['width'].'px;';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($viewport['height']) === false) {
|
||||||
|
$style .= 'height:'.$viewport['height'].'px;';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$output .= '<div id="container-chart-generator-item" style="'.$style.' margin:0px;">';
|
||||||
|
switch ($type_graph_pdf) {
|
||||||
|
case 'combined':
|
||||||
|
$params['pdf'] = true;
|
||||||
|
$result = graphic_combined_module(
|
||||||
|
$module_list,
|
||||||
|
$params,
|
||||||
|
$params_combined
|
||||||
|
);
|
||||||
|
|
||||||
|
$output .= $result;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'sparse':
|
||||||
|
$params['pdf'] = true;
|
||||||
|
$output .= grafico_modulo_sparse($params);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'pie_graph':
|
||||||
|
$params['pdf'] = true;
|
||||||
|
$chart = get_build_setup_charts(
|
||||||
|
'PIE',
|
||||||
|
$params['options'],
|
||||||
|
$params['chart_data']
|
||||||
|
);
|
||||||
|
|
||||||
|
$output .= $chart->render(true);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'vbar_graph':
|
||||||
|
$params['pdf'] = true;
|
||||||
|
$chart = get_build_setup_charts(
|
||||||
|
'BAR',
|
||||||
|
$params['options'],
|
||||||
|
$params['chart_data']
|
||||||
|
);
|
||||||
|
|
||||||
|
$output .= $chart->render(true);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'ring_graph':
|
||||||
|
$params['pdf'] = true;
|
||||||
|
$params['options']['width'] = 500;
|
||||||
|
$params['options']['height'] = 500;
|
||||||
|
|
||||||
|
$chart = get_build_setup_charts(
|
||||||
|
'DOUGHNUT',
|
||||||
|
$params['options'],
|
||||||
|
$params['chart_data']
|
||||||
|
);
|
||||||
|
|
||||||
|
$output .= $chart->render(true);
|
||||||
|
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']
|
||||||
|
);
|
||||||
|
$output .= $chart->render(true);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'slicebar':
|
||||||
|
$output .= flot_slicesbar_graph(
|
||||||
|
$params['graph_data'],
|
||||||
|
$params['period'],
|
||||||
|
$params['width'],
|
||||||
|
$params['height'],
|
||||||
|
$params['legend'],
|
||||||
|
$params['colors'],
|
||||||
|
$params['fontpath'],
|
||||||
|
$params['round_corner'],
|
||||||
|
$params['homeurl'],
|
||||||
|
$params['watermark'],
|
||||||
|
$params['adapt_key'],
|
||||||
|
$params['stat_winalse'],
|
||||||
|
$params['id_agent'],
|
||||||
|
$params['full_legend_daterray'],
|
||||||
|
$params['not_interactive'],
|
||||||
|
$params['ttl'],
|
||||||
|
$params['sizeForTicks'],
|
||||||
|
$params['show'],
|
||||||
|
$params['date_to'],
|
||||||
|
$params['server_id']
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Code...
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$output .= '</div>';
|
||||||
|
$output .= '</body>';
|
||||||
|
$output .= '</html>';
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the product name.
|
* Get the product name.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1976,15 +1976,21 @@ function ui_print_help_icon(
|
||||||
*
|
*
|
||||||
* @return boolean True if the file was added. False if the file doesn't exist.
|
* @return boolean True if the file was added. False if the file doesn't exist.
|
||||||
*/
|
*/
|
||||||
function ui_require_css_file($name, $path='include/styles/', $echo_tag=false)
|
function ui_require_css_file($name, $path='include/styles/', $echo_tag=false, $return=false)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
$filename = $path.$name.'.css';
|
$filename = $path.$name.'.css';
|
||||||
|
|
||||||
if ($echo_tag === true) {
|
if ($echo_tag === true) {
|
||||||
echo '<link type="text/css" rel="stylesheet" href="'.ui_get_full_url($filename, false, false, false).'">';
|
$filename .= '?v='.$config['current_package'];
|
||||||
return null;
|
$tag_name = '<link type="text/css" rel="stylesheet" href="'.ui_get_full_url($filename, false, false, false).'">';
|
||||||
|
if ($return === false) {
|
||||||
|
echo $tag_name;
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return $tag_name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! isset($config['css'])) {
|
if (! isset($config['css'])) {
|
||||||
|
@ -2033,15 +2039,20 @@ function ui_require_css_file($name, $path='include/styles/', $echo_tag=false)
|
||||||
*
|
*
|
||||||
* @return boolean True if the file was added. False if the file doesn't exist.
|
* @return boolean True if the file was added. False if the file doesn't exist.
|
||||||
*/
|
*/
|
||||||
function ui_require_javascript_file($name, $path='include/javascript/', $echo_tag=false)
|
function ui_require_javascript_file($name, $path='include/javascript/', $echo_tag=false, $return=false)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
$filename = $path.$name.'.js';
|
$filename = $path.$name.'.js';
|
||||||
|
|
||||||
if ($echo_tag) {
|
if ($echo_tag === true) {
|
||||||
echo '<script type="text/javascript" src="'.ui_get_full_url($filename, false, false, false).'"></script>';
|
$filename .= '?v='.$config['current_package'];
|
||||||
return null;
|
$tag_name = '<script type="text/javascript" src="'.ui_get_full_url($filename, false, false, false).'"></script>';
|
||||||
|
if ($return === false) {
|
||||||
|
echo $tag_name;
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return $tag_name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! isset($config['js'])) {
|
if (! isset($config['js'])) {
|
||||||
|
|
|
@ -11,14 +11,14 @@
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU General Public License for more details.
|
// GNU General Public License for more details.
|
||||||
function include_javascript_d3($return=false)
|
function include_javascript_d3($return=false, $force=false)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
static $is_include_javascript = false;
|
static $is_include_javascript = false;
|
||||||
|
|
||||||
$output = '';
|
$output = '';
|
||||||
if (!$is_include_javascript) {
|
if (!$is_include_javascript || $force === true) {
|
||||||
$is_include_javascript = true;
|
$is_include_javascript = true;
|
||||||
|
|
||||||
$output .= '<script type="text/javascript" src="';
|
$output .= '<script type="text/javascript" src="';
|
||||||
|
|
|
@ -756,9 +756,8 @@ function flot_slicesbar_graph(
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
if ($ttl == 2) {
|
if ($ttl == 2) {
|
||||||
$tokem_config = uniqid('slicebar');
|
|
||||||
$params = [
|
$params = [
|
||||||
'tokem_config' => $tokem_config,
|
'graph_data' => $graph_data,
|
||||||
'period' => $period,
|
'period' => $period,
|
||||||
'width' => $width,
|
'width' => $width,
|
||||||
'height' => $height,
|
'height' => $height,
|
||||||
|
@ -781,9 +780,6 @@ function flot_slicesbar_graph(
|
||||||
'server_id' => $server_id,
|
'server_id' => $server_id,
|
||||||
];
|
];
|
||||||
|
|
||||||
update_check_config_token($tokem_config, json_encode($graph_data));
|
|
||||||
$_SESSION['slicebar'] = $tokem_config;
|
|
||||||
$_SESSION['slicebar_value'] = json_encode($graph_data);
|
|
||||||
$graph = '<img src="data:image/png;base64,';
|
$graph = '<img src="data:image/png;base64,';
|
||||||
$graph .= generator_chart_to_pdf('slicebar', $params);
|
$graph .= generator_chart_to_pdf('slicebar', $params);
|
||||||
$graph .= '" />';
|
$graph .= '" />';
|
||||||
|
|
Loading…
Reference in New Issue