From 4214577eeaeb2a71b066e31152eeb53b0e1f1d4e Mon Sep 17 00:00:00 2001 From: danielmaya Date: Tue, 19 Jun 2018 18:27:04 +0200 Subject: [PATCH 1/5] Added new token for static graph height --- pandora_console/godmode/setup/setup_visuals.php | 4 ++++ pandora_console/include/functions.php | 2 +- pandora_console/include/functions_config.php | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pandora_console/godmode/setup/setup_visuals.php b/pandora_console/godmode/setup/setup_visuals.php index 5f0791c401..637f1e5ad8 100755 --- a/pandora_console/godmode/setup/setup_visuals.php +++ b/pandora_console/godmode/setup/setup_visuals.php @@ -685,6 +685,10 @@ $options_full_escale[2] = __('On Boolean graphs'); $table_chars->data[$row][1] = html_print_select($options_full_escale, 'full_scale_option', $config["full_scale_option"], '', '', 0, true, false, false); $row++; +$table_chars->data[$row][0] = __('Graph image height'); +$table_chars->data[$row][1] = html_print_input_text ('graph_image_height', $config['graph_image_height'], '', 20, 20, true); +$row++; + /* $table_font->data[$row][0] = __('Font path'); $fonts = load_fonts(); diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 334ac4b2fc..f19da0c53a 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -3223,7 +3223,7 @@ function generator_chart_to_pdf($type_graph_pdf, $params, $params_combined = fal $img_url = $config["homeurl"] . "attachment/" . $img_file; $width_img = 500; - $height_img = 450; + $height_img = (isset($config['graph_image_height'])) ? $config['graph_image_height'] : 350; $params_encode_json = urlencode(json_encode($params)); diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 8b9607533b..ebb09671e1 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -627,6 +627,9 @@ function config_update_config () { if (!config_update_value ('full_scale_option', (int) get_parameter('full_scale_option', 0))) $error_update[] = __('Default full scale (TIP)'); + + if (!config_update_value ('graph_image_height', (int) get_parameter('graph_image_height', 0))) + $error_update[] = __('Default height of the chart image'); if (!config_update_value ('classic_menu', (bool) get_parameter('classic_menu', false))) $error_update[] = __('Classic menu mode'); @@ -1851,6 +1854,10 @@ function config_process_config () { config_update_value ('render_proc', 0); } + if (!isset($config['graph_image_height'])) { + config_update_value ('graph_image_height', 350); + } + if (!isset($config["render_proc_ok"])) { config_update_value ('render_proc_ok', __('Ok') ); } From b625f2e5c81f7d6c5b15ecae571574c6309286f3 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 19 Jun 2018 19:07:36 +0200 Subject: [PATCH 2/5] Changed GET to POST in web2image --- pandora_console/include/chart_generator.php | 18 +++++------ pandora_console/include/web2image.js | 34 ++++++++++----------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/pandora_console/include/chart_generator.php b/pandora_console/include/chart_generator.php index 86388515f2..45d0582cb5 100644 --- a/pandora_console/include/chart_generator.php +++ b/pandora_console/include/chart_generator.php @@ -13,9 +13,9 @@ // GNU General Public License for more details. // Global & session manageme -session_id($_GET["session_id"]); +session_id($_REQUEST["session_id"]); if (file_exists(session_save_path() . "/pansess_" . session_id())) { - $user = file_get_contents(session_save_path() . "/pansess_" . session_id()); + $user = file_request_contents(session_save_path() . "/pansess_" . session_id()); } session_start(); if (isset($user)) { @@ -39,12 +39,12 @@ check_login(); global $config; -$params = json_decode($_GET['data'], true); +$params = json_decode($_REQUEST['data'], true); // Metaconsole connection to the node $server_id = $params['server_id']; if ($config["metaconsole"] && !empty($server_id)) { - $server = metaconsole_get_connection_by_id($server_id); + $server = metaconsole_request_connection_by_id($server_id); // Error connecting if (metaconsole_connect($server) !== NOERR) { echo ""; @@ -68,7 +68,7 @@ if (file_exists ('languages/'.$user_language.'.mo')) { - Pandora FMS Graph (<?php echo agents_get_alias($agent_id) . ' - ' . $interface_name; ?>) + Pandora FMS Graph (<?php echo agents_request_alias($agent_id) . ' - ' . $interface_name; ?>) @@ -95,13 +95,13 @@ if (file_exists ('languages/'.$user_language.'.mo')) { '; diff --git a/pandora_console/include/web2image.js b/pandora_console/include/web2image.js index 1dab3be266..f5fd552e5c 100644 --- a/pandora_console/include/web2image.js +++ b/pandora_console/include/web2image.js @@ -4,7 +4,7 @@ if (system.args.length < 3 || system.args.length > 11) { phantom.exit(1); } -var webPage = require('webpage'); +var webPage = require('webpage'); var page = webPage.create(); var url = system.args[1]; var type_graph_pdf = system.args[2]; @@ -12,39 +12,37 @@ var url_params = system.args[3]; var url_params_comb = system.args[4]; var url_module_list = system.args[5]; var output_filename = system.args[6]; -var _width = system.args[7]; -var _height = system.args[8]; +var viewport_width = system.args[7]; +var viewport_height = system.args[8]; var session_id = system.args[9]; var base_64 = system.args[10]; -if (!_width) { - _width = 750; +if (!viewport_width) { + viewport_width = 750; } -if (!_height) { - _height = 350; +if (!viewport_height) { + viewport_height = 350; } if(type_graph_pdf == 'combined'){ - finish_url = url + "?" + "data=" + url_params + - "&data_combined=" + url_params_comb + - "&data_module_list=" + url_module_list + - "&type_graph_pdf=" + type_graph_pdf + - "&session_id=" + session_id; + post_data = "data=" + url_params + + "&data_combined=" + url_params_comb + + "&data_module_list=" + url_module_list + + "&type_graph_pdf=" + type_graph_pdf + + "&session_id=" + session_id; } else{ - finish_url = url + "?" + "data=" + url_params + - "&type_graph_pdf=" + type_graph_pdf + - "&session_id=" + session_id; + post_data = "data=" + url_params + + "&type_graph_pdf=" + type_graph_pdf + + "&session_id=" + session_id; } page.viewportSize = { width: _width, height: _height }; //page.zoomFactor = 1.75; -page.open(finish_url, function start(status) { - -}); +page.open(post_data, 'POST', post_data, function start(status) {}); page.onLoadFinished = function (status) { if(!base_64){ From 73567f1859c8a5d5d5ae1223ca59ab7344c8491b Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 19 Jun 2018 19:19:38 +0200 Subject: [PATCH 3/5] Trying to adjust graph render sizes --- pandora_console/include/chart_generator.php | 6 +++++- pandora_console/include/functions.php | 5 ++++- pandora_console/include/web2image.js | 6 ++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/pandora_console/include/chart_generator.php b/pandora_console/include/chart_generator.php index 45d0582cb5..3291cd2519 100644 --- a/pandora_console/include/chart_generator.php +++ b/pandora_console/include/chart_generator.php @@ -96,9 +96,13 @@ if (file_exists ('languages/'.$user_language.'.mo')) { $params['only_image'] = false; - $params['width'] = '1048'; + $params['width'] = (int) $_REQUEST['viewport_width']; $params['menu'] = false; + if((!isset($params['width']) || ($params['width'] <= 0)) { + $params['width'] = 1048; + } + $params_combined = json_decode($_REQUEST['data_combined'], true); $module_list = json_decode($_REQUEST['data_module_list'], true); $type_graph_pdf = $_REQUEST['type_graph_pdf']; diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index f19da0c53a..36ec32f746 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -3252,11 +3252,14 @@ function generator_chart_to_pdf($type_graph_pdf, $params, $params_combined = fal $result = exec($cmd); if($params['return_img_base_64']){ + // To be used in alerts + $width_img = 500; return $result; } else{ + // to be used in PDF files $config["temp_images"][] = $img_path; - return ''; + return ''; } } diff --git a/pandora_console/include/web2image.js b/pandora_console/include/web2image.js index f5fd552e5c..8b548fcbd1 100644 --- a/pandora_console/include/web2image.js +++ b/pandora_console/include/web2image.js @@ -31,12 +31,14 @@ if(type_graph_pdf == 'combined'){ "&data_combined=" + url_params_comb + "&data_module_list=" + url_module_list + "&type_graph_pdf=" + type_graph_pdf + - "&session_id=" + session_id; + "&session_id=" + session_id + + "&viewport_width=" + viewport_width; } else{ post_data = "data=" + url_params + "&type_graph_pdf=" + type_graph_pdf + - "&session_id=" + session_id; + "&session_id=" + session_id + + "&viewport_width=" + viewport_width; } page.viewportSize = { width: _width, height: _height }; From aa4f13d17ac65f39ccbefbd02d51bcaf61a40050 Mon Sep 17 00:00:00 2001 From: daniel Date: Wed, 20 Jun 2018 11:31:43 +0200 Subject: [PATCH 4/5] fixed errors in graphs --- pandora_console/include/chart_generator.php | 21 ++++++++++++------- pandora_console/include/functions.php | 6 ++++-- .../include/graphs/flot/pandora.flot.js | 11 +++++++--- .../include/graphs/functions_flot.php | 2 +- pandora_console/include/web2image.js | 18 +++++++++------- 5 files changed, 38 insertions(+), 20 deletions(-) diff --git a/pandora_console/include/chart_generator.php b/pandora_console/include/chart_generator.php index 3291cd2519..f23107f39c 100644 --- a/pandora_console/include/chart_generator.php +++ b/pandora_console/include/chart_generator.php @@ -14,8 +14,8 @@ // Global & session manageme session_id($_REQUEST["session_id"]); -if (file_exists(session_save_path() . "/pansess_" . session_id())) { - $user = file_request_contents(session_save_path() . "/pansess_" . session_id()); +if (file_exists(session_save_path() . "/pansess_" . session_id()) ) { + $user = file_get_contents(session_save_path() . "/pansess_" . session_id()); } session_start(); if (isset($user)) { @@ -24,6 +24,7 @@ if (isset($user)) { session_write_close(); + require_once ('config.php'); require_once ($config['homedir'] . '/include/auth/mysql.php'); require_once ($config['homedir'] . '/include/functions.php'); @@ -38,13 +39,15 @@ require_once ($config['homedir'] . '/include/functions_tags.php'); check_login(); global $config; +//get_parameter(array)('data', ''); $params = json_decode($_REQUEST['data'], true); + // Metaconsole connection to the node $server_id = $params['server_id']; if ($config["metaconsole"] && !empty($server_id)) { - $server = metaconsole_request_connection_by_id($server_id); + $server = metaconsole_get_connection_by_id($server_id); // Error connecting if (metaconsole_connect($server) !== NOERR) { echo ""; @@ -68,7 +71,7 @@ if (file_exists ('languages/'.$user_language.'.mo')) { - Pandora FMS Graph (<?php echo agents_request_alias($agent_id) . ' - ' . $interface_name; ?>) + Pandora FMS Graph (<?php echo agents_get_alias($agent_id) . ' - ' . $interface_name; ?>) @@ -94,12 +97,11 @@ if (file_exists ('languages/'.$user_language.'.mo')) { '; echo graphic_combined_module( @@ -121,6 +126,8 @@ if (file_exists ('languages/'.$user_language.'.mo')) { echo grafico_modulo_sparse($params); echo ''; } + + $config['font_size'] = $aux_font_size; ?> diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 36ec32f746..854d7ef9cf 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -3217,7 +3217,7 @@ function generator_chart_to_pdf($type_graph_pdf, $params, $params_combined = fal global $config; $file_js = $config["homedir"] . "/include/web2image.js"; - $url = $config["homeurl"] . "/include/chart_generator.php"; + $url = $config["homeurl"] . "include/chart_generator.php"; $img_file = "img_". uniqid() .".png"; $img_path = $config["homedir"] . "/attachment/" . $img_file; $img_url = $config["homeurl"] . "attachment/" . $img_file; @@ -3225,6 +3225,8 @@ function generator_chart_to_pdf($type_graph_pdf, $params, $params_combined = fal $width_img = 500; $height_img = (isset($config['graph_image_height'])) ? $config['graph_image_height'] : 350; + $params['height'] = $height_img; + $params_encode_json = urlencode(json_encode($params)); if($params_combined){ @@ -3259,7 +3261,7 @@ function generator_chart_to_pdf($type_graph_pdf, $params, $params_combined = fal else{ // to be used in PDF files $config["temp_images"][] = $img_path; - return ''; + return ''; } } diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js index 796d17c196..06e6174e64 100644 --- a/pandora_console/include/graphs/flot/pandora.flot.js +++ b/pandora_console/include/graphs/flot/pandora.flot.js @@ -1638,7 +1638,8 @@ function pandoraFlotArea( graph_id, values, legend, font: { size: font_size + 2, color: legend_color, - family: font+'Font' + family: font+'Font', + variant: "small-caps" }, }, yaxes: [{ @@ -1933,9 +1934,8 @@ function pandoraFlotArea( graph_id, values, legend, $('#legend_' + graph_id).height()); $('#timestamp_'+graph_id).css('color', legend_color); - $('#timestamp_'+graph_id).css('font-size', font_size + 2); + $('#timestamp_'+graph_id).css('font-size', font_size + 2+'px'); $('#timestamp_'+graph_id).css('font-family', font + 'Font'); - $('#timestamp_'+graph_id).css('color', legend_color); if (timesize+timenewpos > canvaslimit) { $('#timestamp_'+graph_id).css('left', timenewpos - timesize); @@ -1998,6 +1998,8 @@ function pandoraFlotArea( graph_id, values, legend, } $('#legend_' + graph_id + ' .legendLabel').eq(i).css('color', legend_color); + $('#legend_' + graph_id + ' .legendLabel').eq(i).css('font-size', font_size + 2 +'px'); + $('#legend_' + graph_id + ' .legendLabel').eq(i).css('font-family', font + 'Font'); i++; } @@ -2164,6 +2166,9 @@ function pandoraFlotArea( graph_id, values, legend, .eq(i).html(label_aux); } $('#legend_' + graph_id + ' .legendLabel').css('color', legend_color); + $('#legend_' + graph_id + ' .legendLabel').css('font-size', font_size + 2 +'px'); + $('#legend_' + graph_id + ' .legendLabel').css('font-family', font + 'Font'); + plot.clearCrosshair(); if(!vconsole){ overview.clearCrosshair(); diff --git a/pandora_console/include/graphs/functions_flot.php b/pandora_console/include/graphs/functions_flot.php index 7e403efba8..87e7b0d9ea 100644 --- a/pandora_console/include/graphs/functions_flot.php +++ b/pandora_console/include/graphs/functions_flot.php @@ -137,7 +137,7 @@ function flot_area_graph ( $return = "
"; // Set some containers to legend, graph, timestamp tooltip, etc. if($params['show_legend']){ - $return .= "

"; + $return .= "

"; } if(isset($params['graph_combined']) && $params['graph_combined'] && (!isset($params['from_interface']) || !$params['from_interface']) ){ diff --git a/pandora_console/include/web2image.js b/pandora_console/include/web2image.js index 8b548fcbd1..6c2edeb47c 100644 --- a/pandora_console/include/web2image.js +++ b/pandora_console/include/web2image.js @@ -31,20 +31,23 @@ if(type_graph_pdf == 'combined'){ "&data_combined=" + url_params_comb + "&data_module_list=" + url_module_list + "&type_graph_pdf=" + type_graph_pdf + - "&session_id=" + session_id + - "&viewport_width=" + viewport_width; + "&session_id=" + session_id; } else{ post_data = "data=" + url_params + "&type_graph_pdf=" + type_graph_pdf + - "&session_id=" + session_id + - "&viewport_width=" + viewport_width; + "&session_id=" + session_id; } -page.viewportSize = { width: _width, height: _height }; -//page.zoomFactor = 1.75; +page.viewportSize = { + width: viewport_width, + height: viewport_height +}; +page.zoomFactor = 1; -page.open(post_data, 'POST', post_data, function start(status) {}); +page.open(url, 'POST', post_data, function start(status) { + +}); page.onLoadFinished = function (status) { if(!base_64){ @@ -52,6 +55,7 @@ page.onLoadFinished = function (status) { } else{ var base64 = page.renderBase64('png'); + //XXXX console.log(base64); } phantom.exit(); From 2ae0dc6c520351adae8c87b039d44d53b01b3d7a Mon Sep 17 00:00:00 2001 From: daniel Date: Wed, 20 Jun 2018 11:54:03 +0200 Subject: [PATCH 5/5] fixed minor error default graph for pdf or email 320 --- pandora_console/include/functions_config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index ebb09671e1..76f646bce2 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -1855,7 +1855,7 @@ function config_process_config () { } if (!isset($config['graph_image_height'])) { - config_update_value ('graph_image_height', 350); + config_update_value ('graph_image_height', 320); } if (!isset($config["render_proc_ok"])) {