remove phamtomjs pandora_enterprise#9554

This commit is contained in:
Daniel Barbero 2022-12-20 12:23:18 +01:00
parent b4d306b9b1
commit 3e071a7d33
18 changed files with 358 additions and 429 deletions

View File

@ -258,6 +258,7 @@ console_dependencies=" \
mod_ssl \
libzstd \
openldap-clients \
chromium \
http://firefly.artica.es/centos8/phantomjs-2.1.1-1.el7.x86_64.rpm"
execute_cmd "yum install -y $console_dependencies" "Installing Pandora FMS Console dependencies"

View File

@ -312,6 +312,7 @@ console_dependencies=" \
mod_ssl \
libzstd \
openldap-clients \
chromium \
http://firefly.artica.es/centos8/perl-Net-Telnet-3.04-1.el8.noarch.rpm \
http://firefly.artica.es/centos7/wmic-1.4-1.el7.x86_64.rpm \
http://firefly.artica.es/centos8/phantomjs-2.1.1-1.el7.x86_64.rpm"

View File

@ -271,6 +271,8 @@ echo -en "${cyan}Installing phantomjs...${reset}"
/usr/bin/phantomjs --version &>> "$LOGFILE"
check_cmd_status "Error Installing phanromjs"
# Chromium
execute_cmd "apt install -y chromium-browser" "Instaling chromium browser"
# SDK VMware perl dependencies
vmware_dependencies=" \

View File

@ -262,13 +262,11 @@ RUN dnf install -y --setopt=tsflags=nodocs \
http://firefly.artica.es/centos7/wmic-1.4-1.el7.x86_64.rpm
# Install utils
RUN dnf install -y supervisor crontabs http://firefly.artica.es/centos8/phantomjs-2.1.1-1.el7.x86_64.rpm --setopt=tsflags=nodocs
RUN dnf install -y supervisor chromium crontabs http://firefly.artica.es/centos8/phantomjs-2.1.1-1.el7.x86_64.rpm --setopt=tsflags=nodocs
# SDK VMware perl dependencies
RUN dnf install -y http://firefly.artica.es/centos8/perl-Crypt-OpenSSL-AES-0.02-1.el8.x86_64.rpm http://firefly.artica.es/centos8/perl-Crypt-SSLeay-0.73_07-1.gf.el8.x86_64.rpm perl-Net-HTTP perl-libwww-perl openssl-devel perl-Crypt-CBC perl-Bytes-Random-Secure perl-Crypt-Random-Seed perl-Math-Random-ISAAC perl-JSON http://firefly.artica.es/centos8/VMware-vSphere-Perl-SDK-6.5.0-4566394.x86_64.rpm
# Instant client Oracle
RUN dnf install -y https://download.oracle.com/otn_software/linux/instantclient/19800/oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm https://download.oracle.com/otn_software/linux/instantclient/19800/oracle-instantclient19.8-sqlplus-19.8.0.0.0-1.x86_64.rpm
# Install Phantom
RUN dnf install -y supervisor crontabs http://firefly.artica.es/centos8/phantomjs-2.1.1-1.el7.x86_64.rpm --setopt=tsflags=nodocs
EXPOSE 80 443 41121 162/udp

View File

@ -1677,3 +1677,5 @@ enterprise/operation/agentes/manage_transmap.php
enterprise/operation/agentes/manage_transmap_creation.php
enterprise/operation/agentes/manage_transmap_creation_phases_data.php
enterprise/operation/agentes/transactional_map.php
include/test.js
include/web2image.js

View File

@ -684,23 +684,6 @@ $table_other->data[$i++][1] = html_print_input_text(
true
);
if (enterprise_installed() === true) {
$table_other->data[$i][0] = __('PhantomJS cache cleanup ').$tip;
$table_other->data[$i++][1] = html_print_input(
[
'type' => 'select',
'name' => 'phantomjs_cache_interval',
'return' => true,
'fields' => [
PHANTOM_CACHE_CLEANUP_ONCE => __('No scheduled'),
PHANTOM_CACHE_CLEANUP_WEEKLY => __('Each week'),
PHANTOM_CACHE_CLEANUP_DAILY => __('Each day'),
],
'selected' => ($config['phantomjs_cache_interval'] ?? PHANTOM_CACHE_CLEANUP_ONCE),
]
);
}
// Agent Wizard defaults.
$defaultAgentWizardOptions = json_decode(io_safe_output($config['agent_wizard_defaults']));
$tableSnmpWizard = new stdClass();

View File

@ -95,11 +95,11 @@ $table->data[$i++][1] = html_print_input_text(
true
);
$table->data[$i][0] = __('Phantomjs bin directory');
$table->data[$i][0] = __('Chromium path');
$table->data[$i++][1] = html_print_input_text(
'phantomjs_bin',
'chromium_path',
io_safe_output(
$config['phantomjs_bin']
$config['chromium_path']
),
'',
30,

View File

@ -167,7 +167,7 @@ class ConsoleSupervisor
* NOTIF.PHP.UPLOAD_MAX_FILESIZE
* NOTIF.PHP.MEMORY_LIMIT
* NOTIF.PHP.DISABLE_FUNCTIONS
* NOTIF.PHP.PHANTOMJS
* NOTIF.PHP.CHROMIUM
* NOTIF.PHP.VERSION
*/
@ -349,7 +349,7 @@ class ConsoleSupervisor
* NOTIF.PHP.UPLOAD_MAX_FILESIZE
* NOTIF.PHP.MEMORY_LIMIT
* NOTIF.PHP.DISABLE_FUNCTIONS
* NOTIF.PHP.PHANTOMJS
* NOTIF.PHP.CHROMIUM
* NOTIF.PHP.VERSION
*/
@ -528,11 +528,7 @@ class ConsoleSupervisor
*/
public function maintenanceOperations()
{
/*
* Process cache clean if needed.
*/
$this->checkCleanPhantomCache();
}
@ -688,7 +684,7 @@ class ConsoleSupervisor
case 'NOTIF.PHP.UPLOAD_MAX_FILESIZE':
case 'NOTIF.PHP.MEMORY_LIMIT':
case 'NOTIF.PHP.DISABLE_FUNCTIONS':
case 'NOTIF.PHP.PHANTOMJS':
case 'NOTIF.PHP.CHROMIUM':
case 'NOTIF.PHP.VERSION':
case 'NOTIF.HISTORYDB':
case 'NOTIF.PANDORADB':
@ -1431,9 +1427,9 @@ class ConsoleSupervisor
$PHPmemory_limit_min = config_return_in_bytes('-1');
}
// PhantomJS status.
$phantomjs_dir = io_safe_output($config['phantomjs_bin']);
$result_ejecution = exec($phantomjs_dir.'/phantomjs --version');
// Chromium status.
$chromium_dir = io_safe_output($config['chromium_path']);
$result_ejecution = exec($chromium_dir.' --version');
// PHP version checks.
$php_version = phpversion();
@ -1577,21 +1573,20 @@ class ConsoleSupervisor
}
if (!isset($result_ejecution) || $result_ejecution == '') {
$url = 'https://pandorafms.com/manual/en/documentation/02_installation/04_configuration#Phantomjs';
if ($config['language'] == 'es') {
$url = 'https://pandorafms.com/manual/es/documentation/02_installation/04_configuration#Phantomjs';
}
$url = 'https://www.chromium.org/getting-involved/download-chromium/';
// if ($config['language'] == 'es') {
// $url = 'https://pandorafms.com/manual/es/documentation/02_installation/04_configuration#Phantomjs';
// }
$this->notify(
[
'type' => 'NOTIF.PHP.PHANTOMJS',
'title' => __('PhantomJS is not installed'),
'message' => __('To be able to create images of the graphs for PDFs, please install the PhantomJS extension. For that, it is necessary to follow these steps:'),
'type' => 'NOTIF.PHP.CHROMIUM',
'title' => __('chromium is not installed'),
'message' => __('To be able to create images of the graphs for PDFs, please install the chromium extension. For that, it is necessary to follow these steps:'),
'url' => $url,
]
);
} else {
$this->cleanNotifications('NOTIF.PHP.PHANTOMJS');
$this->cleanNotifications('NOTIF.PHP.CHROMIUM');
}
if ($php_version_array[0] < 8) {
@ -2698,34 +2693,6 @@ class ConsoleSupervisor
}
/**
* Clean Phantom cache if needed.
*
* @return void
*/
public function checkCleanPhantomCache()
{
global $config;
if (isset($config['clean_phantomjs_cache']) !== true
|| (int) $config['clean_phantomjs_cache'] !== 1
) {
return;
}
$cache_dir = $config['homedir'].'/attachment/cache';
if (is_dir($cache_dir) === true) {
Files::rmrf($cache_dir);
}
// Clean process has ended.
config_update_value(
'clean_phantomjs_cache',
0
);
}
/**
* Verifies the status of synchronization queue and warns if something is
* not working as expected.

View File

@ -113,13 +113,6 @@ define('SECONDS_1YEAR', 31536000);
define('SECONDS_2YEARS', 63072000);
define('SECONDS_3YEARS', 94608000);
// PhantomJS Cache cleanup intervals.
define('PHANTOM_CACHE_CLEANUP_ONCE', 0);
define('PHANTOM_CACHE_CLEANUP_WEEKLY', SECONDS_1WEEK);
define('PHANTOM_CACHE_CLEANUP_DAILY', SECONDS_1DAY);
// Separator constats.
define('SEPARATOR_COLUMN', ';');
define('SEPARATOR_ROW', chr(10));

View File

@ -4242,7 +4242,7 @@ function generator_chart_to_pdf(
}
try {
$browserFactory = new BrowserFactory('chromium-browser');
$browserFactory = new BrowserFactory($config['chromium_path']);
// Starts headless chrome.
$browser = $browserFactory->createBrowser(['noSandbox' => true]);
@ -4250,8 +4250,6 @@ function generator_chart_to_pdf(
// Creates a new page.
$page = $browser->createPage();
hd($url.'?data='.urlencode(json_encode($data)), true);
// Navigate to an URL.
$navigation = $page->navigate($url.'?data='.urlencode(json_encode($data)));
$navigation->waitForNavigation(Page::DOM_CONTENT_LOADED);
@ -4281,10 +4279,6 @@ function generator_chart_to_pdf(
$dynamic_width = $params['options']['viewport']['width'];
}
hd('Tomando el Clip', true);
hd('Width: ['.$dynamic_width.']', true);
hd('Height: ['.$dynamic_height.']', true);
$clip = new Clip(0, 0, $dynamic_width, $dynamic_height);
if ($params['return_img_base_64']) {
@ -4298,7 +4292,7 @@ function generator_chart_to_pdf(
return '<img src="'.$img_url.'" />';
}
} catch (\Throwable $th) {
hd($th, true);
error_log($th);
} finally {
$browser->close();
}

View File

@ -184,8 +184,8 @@ function config_update_config()
$error_update[] = __('Remote config directory');
}
if (config_update_value('phantomjs_bin', (string) get_parameter('phantomjs_bin'), true) === false) {
$error_update[] = __('phantomjs config directory');
if (config_update_value('chromium_path', (string) get_parameter('chromium_path'), true) === false) {
$error_update[] = __('Chromium config directory');
}
if (config_update_value('loginhash_pwd', io_input_password((string) get_parameter('loginhash_pwd')), true) === false) {
@ -926,25 +926,6 @@ function config_update_config()
if (config_update_value('agent_wizard_defaults', json_encode($selectedAgentWizardOptions), true) === false) {
$error_update[] = __('SNMP Interface Agent Wizard');
}
$pjs = get_parameter('phantomjs_cache_interval');
switch ($pjs) {
case $config['phantomjs_cache_interval']:
default;
// No changes.
break;
case PHANTOM_CACHE_CLEANUP_ONCE:
case PHANTOM_CACHE_CLEANUP_DAILY:
case PHANTOM_CACHE_CLEANUP_WEEKLY:
enterprise_hook('phantomjs_cache_interval_schedule', [$pjs]);
break;
}
if (config_update_value('phantomjs_cache_interval', get_parameter('phantomjs_cache_interval'), true) === false
) {
$error_update[] = __('PhantomJS cache interval');
}
break;
case 'vis':
@ -1975,14 +1956,9 @@ function config_process_config()
config_update_value('remote_config', $default);
}
if (!isset($config['phantomjs_bin'])) {
if ($is_windows) {
$default = 'C:\PandoraFMS\Pandora_Server\bin';
} else {
$default = '/usr/bin';
}
config_update_value('phantomjs_bin', $default);
if (isset($config['chromium_path']) === false) {
$default = '/usr/bin/chromium-browser';
config_update_value('chromium_path', $default);
}
if (!isset($config['date_format'])) {

View File

@ -2282,6 +2282,19 @@ function graphic_combined_module(
$options['axis'] = 'y';
}
if ((bool) $params['pdf'] === true) {
$options['dataLabel'] = ['display' => 'auto'];
if ($params_combined['stacked'] == CUSTOM_GRAPH_HBARS) {
$options['layout'] = [
'padding' => ['right' => 35],
];
} else {
$options['layout'] = [
'padding' => ['top' => 35],
];
}
}
$output = '<div style="display: flex; flex-direction:row; justify-content: center; align-items: center; align-content: center; width:100%; height:100%;">';
$output .= '<div style="flex: 0 0 auto; width:99%; height:100%;">';
$output .= vbar_graph($graph_values, $options);
@ -2344,10 +2357,12 @@ function graphic_combined_module(
$label = io_safe_output($alias.': '.$data_module['nombre']);
}
$temp[$label] = [
'value' => $value,
'unit' => $data_module['unit'],
];
if ((bool) $params['pdf'] === true) {
$value = (empty($value) === false) ? $value : 0;
$label .= ' ('.$value.')';
}
$temp[$label] = $value;
if (is_metaconsole() === true) {
metaconsole_restore_db();
@ -2363,7 +2378,6 @@ function graphic_combined_module(
$water_mark = false;
}
// TODO: XXX chartjs.
$color = color_graph_array();
$width = null;
$height = null;
@ -2375,8 +2389,23 @@ function graphic_combined_module(
'ttl' => $ttl,
'background' => $background_color,
'pdf' => $params['pdf'],
'legend' => [
'display' => (bool) $params['show_legend'],
'position' => 'right',
'align' => 'center',
],
];
if ((bool) $params['pdf'] === true) {
$options['dataLabel'] = ['display' => 'auto'];
$options['layout'] = [
'padding' => [
'top' => 20,
'bottom' => 20,
],
];
}
$output = '<div style="display: flex; flex-direction:row; justify-content: center; align-items: center; align-content: center; width:100%; height:100%;">';
$output .= '<div style="flex: 0 0 auto; width:99%; height:100%;">';
$output .= ring_graph($graph_values, $options);
@ -3506,10 +3535,9 @@ function graph_custom_sql_graph(
}
$output = '';
$output .= '<div style="height:'.($height).'px; width: 99%; margin: 0 auto;">';
if ((int) $ttl === 2) {
$output .= '<img src="data:image/png;base64,';
} else {
$output .= '<div style="height:'.($height).'px; margin: 0 auto;">';
}
switch ($type) {
@ -3561,8 +3589,8 @@ function graph_custom_sql_graph(
$options['dataLabel'] = ['display' => 'auto'];
$options['layout'] = [
'padding' => [
'top' => 12,
'bottom' => 12,
'top' => 20,
'bottom' => 20,
],
];
}
@ -3577,10 +3605,10 @@ function graph_custom_sql_graph(
if ((int) $ttl === 2) {
$output .= '" />';
} else {
$output .= '</div>';
}
$output .= '</div>';
return $output;
}
@ -4741,6 +4769,13 @@ function graph_nodata_image($options)
$height = $options['height'];
}
if ($options['base64'] === true) {
$dataImg = file_get_contents(
$config['homedir'].'/images/image_problem_area_150.png'
);
return base64_encode($dataImg);
}
return html_print_image(
'images/image_problem_area.png',
true,
@ -4749,46 +4784,6 @@ function graph_nodata_image($options)
'style' => 'height:'.$height.'px;',
]
);
/*
if ($base64 === true) {
$dataImg = file_get_contents(
$config['homedir'].'/images/image_problem_area_150.png'
);
return base64_encode($dataImg);
}
$image = ui_get_full_url(
'images/image_problem_area.png',
false,
false,
false
);
$style = 'text-align:center; padding: 30px 0; display:block; font-size:9.5pt;';
$text_div = '<div class="nodata_text" style="'.$style.'">';
$text_div .= $text;
$text_div .= '</div>';
$style = 'background-size: contain;background-image: url(\''.$image.'\');';
$image_div = '<div class="nodata_container" style="'.$style.'"></div>';
if ($percent === true) {
$div = $image_div;
} else {
if (strpos($width, '%') === false) {
$width = 'width: '.$width.'px;';
} else {
$width = 'width: '.$width.';';
}
$style = $width.' height:'.$height.'px;';
$style .= 'margin: 0 auto;';
$div = '<div style="'.$style.'">'.$image_div.'</div>';
}
return $div;
*/
}

View File

@ -134,7 +134,7 @@ function notifications_get_subtypes(?string $source=null)
'NOTIF.PHP.UPLOAD_MAX_FILESIZE',
'NOTIF.PHP.MEMORY_LIMIT',
'NOTIF.PHP.DISABLE_FUNCTIONS',
'NOTIF.PHP.PHANTOMJS',
'NOTIF.PHP.CHROMIUM',
'NOTIF.PHP.VERSION',
'NOTIF.HISTORYDB',
'NOTIF.PANDORADB',

View File

@ -1902,9 +1902,15 @@ function reporting_event_top_n(
}
}
$data_pie_graph[$item_name] = $data_top[$key_an];
$data_hbar[io_safe_output($item_name)] = $data_top[$key_an];
if ((int) $ttl === 2) {
$data_top[$key_an] = (empty($data_top[$key_an]) === false) ? $data_top[$key_an] : 0;
$item_name .= ' ('.$data_top[$key_an].')';
}
$data_pie_graph[$item_name] = $data_top[$key_an];
$divisor = get_data_multiplier($units[$key_an]);
if ($show_graph == 0 || $show_graph == 1) {
@ -1954,6 +1960,16 @@ function reporting_event_top_n(
'ttl' => $ttl,
];
if ((int) $ttl === 2) {
$options_charts['dataLabel'] = ['display' => 'auto'];
$options_charts['layout'] = [
'padding' => [
'top' => 15,
'bottom' => 15,
],
];
}
if ((int) $ttl === 2) {
$return['charts']['pie'] = '<img src="data:image/png;base64,';
} else {
@ -1987,6 +2003,13 @@ function reporting_event_top_n(
],
];
if ((int) $ttl === 2) {
$options['dataLabel'] = ['display' => 'auto'];
$options['layout'] = [
'padding' => ['right' => 35],
];
}
if ((int) $ttl === 2) {
$return['charts']['bars'] = '<img src="data:image/png;base64,';
} else {
@ -2219,6 +2242,16 @@ function reporting_event_report_group(
'ttl' => $ttl,
];
if ($pdf === true) {
$options_charts['dataLabel'] = ['display' => 'auto'];
$options_charts['layout'] = [
'padding' => [
'top' => 15,
'bottom' => 15,
],
];
}
if ($event_graph_by_agent) {
$data_graph_by_agent = [];
if (empty($data) === false) {
@ -2234,6 +2267,15 @@ function reporting_event_report_group(
$data_graph_by_agent[$k] = 1;
}
}
if ($pdf === true) {
$result_data_graph_by_agent = [];
foreach ($data_graph_by_agent as $key => $value) {
$result_data_graph_by_agent[$key.' ('.$value.')'] = $value;
}
$data_graph_by_agent = $result_data_graph_by_agent;
}
}
if ($pdf === true) {
@ -2256,6 +2298,15 @@ function reporting_event_report_group(
if ($event_graph_by_user_validator) {
$data_graph_by_user = events_get_count_events_validated_by_user($data);
if ($pdf === true) {
$result_data_graph_by_user = [];
foreach ($data_graph_by_user as $key => $value) {
$result_data_graph_by_user[$key.' ('.$value.')'] = $value;
}
$data_graph_by_user = $result_data_graph_by_user;
}
if ($pdf === true) {
$return['chart']['by_user_validator'] = '<img src="data:image/png;base64,';
} else {
@ -2285,10 +2336,19 @@ function reporting_event_report_group(
$data_graph_by_criticity[$k] = 1;
}
}
}
$colors = get_criticity_pie_colors($data_graph_by_criticity);
$options_charts['colors'] = array_values($colors);
$colors = get_criticity_pie_colors($data_graph_by_criticity);
$options_charts['colors'] = array_values($colors);
if ($pdf === true) {
$result_data_graph_by_criticity = [];
foreach ($data_graph_by_criticity as $key => $value) {
$result_data_graph_by_criticity[$key.' ('.$value.')'] = $value;
}
$data_graph_by_criticity = $result_data_graph_by_criticity;
}
}
if ($pdf === true) {
$return['chart']['by_criticity'] = '<img src="data:image/png;base64,';
@ -2325,6 +2385,15 @@ function reporting_event_report_group(
$data_graph_by_status[$k] = 1;
}
}
if ($pdf === true) {
$result_data_graph_by_status = [];
foreach ($data_graph_by_status as $key => $value) {
$result_data_graph_by_status[$key.' ('.$value.')'] = $value;
}
$data_graph_by_status = $result_data_graph_by_status;
}
}
if ($pdf === true) {
@ -3853,26 +3922,6 @@ function reporting_exception(
}
);
$data_pie_graph = [];
$data_hbar = [];
foreach ($items as $key => $item) {
if ($show_graph == 1 || $show_graph == 2) {
// TODO: Find a better way to show the graphs.
$data_hbar[io_safe_output($item['agent'].' - '.$item['operation'])] = $item['value'];
$data_pie_graph[$item['agent'].' - '.$item['operation']] = $item['value'];
}
if ($show_graph == 0 || $show_graph == 1) {
$data = [];
$data['agent'] = $item['agent'];
$data['module'] = $item['module'];
$data['operation'] = __($item['operation']);
$data['value'] = $item['value'];
$data['formated_value'] = format_for_graph($item['value'], 2).' '.$item['unit'];
$return['data'][] = $data;
}
}
if ($show_graph == 1 || $show_graph == 2) {
reporting_set_conf_charts(
$width,
@ -3883,6 +3932,31 @@ function reporting_exception(
$ttl
);
$data_pie_graph = [];
$data_hbar = [];
foreach ($items as $key => $item) {
if ($show_graph == 1 || $show_graph == 2) {
$label = $item['agent'].' - '.$item['operation'];
$data_hbar[io_safe_output($label)] = $item['value'];
if ((int) $ttl === 2) {
$item['value'] = (empty($item['value']) === false) ? $item['value'] : 0;
$label .= ' ('.$item['value'].')';
}
$data_pie_graph[$label] = $item['value'];
}
if ($show_graph == 0 || $show_graph == 1) {
$data = [];
$data['agent'] = $item['agent'];
$data['module'] = $item['module'];
$data['operation'] = __($item['operation']);
$data['value'] = $item['value'];
$data['formated_value'] = format_for_graph($item['value'], 2).' '.$item['unit'];
$return['data'][] = $data;
}
}
if (!empty($force_width_chart)) {
$width = $force_width_chart;
}
@ -3892,18 +3966,24 @@ function reporting_exception(
}
$options_charts = [
'viewport' => [
'width' => 500,
'height' => 0,
],
'legend' => [
'legend' => [
'display' => true,
'position' => 'right',
'align' => 'center',
],
'ttl' => $ttl,
'ttl' => $ttl,
];
if ((int) $ttl === 2) {
$options_charts['dataLabel'] = ['display' => 'auto'];
$options_charts['layout'] = [
'padding' => [
'top' => 15,
'bottom' => 15,
],
];
}
if ((int) $ttl === 2) {
$return['chart']['pie'] = '<img src="data:image/png;base64,';
} else {
@ -3943,6 +4023,13 @@ function reporting_exception(
],
];
if ((int) $ttl === 2) {
$options['dataLabel'] = ['display' => 'auto'];
$options['layout'] = [
'padding' => ['right' => 35],
];
}
$return['chart']['hbar'] .= vbar_graph(
$data_hbar,
$options
@ -4301,8 +4388,27 @@ function reporting_event_report_agent(
'ttl' => $ttl,
];
if ((int) $ttl === 2) {
$options_charts['dataLabel'] = ['display' => 'auto'];
$options_charts['layout'] = [
'padding' => [
'top' => 15,
'bottom' => 15,
],
];
}
if ($event_graph_by_user_validator) {
$data_graph_by_user = events_get_count_events_validated_by_user($return['data']);
if ((int) $ttl === 2) {
$result_data_graph_by_user = [];
foreach ($data_graph_by_user as $key => $value) {
$result_data_graph_by_user[$key.' ('.$value.')'] = $value;
}
$data_graph_by_user = $result_data_graph_by_user;
}
if ((int) $ttl === 2) {
$return['chart']['by_user_validator'] = '<img src="data:image/png;base64,';
} else {
@ -4332,10 +4438,19 @@ function reporting_event_report_agent(
$data_graph_by_criticity[$k] = 1;
}
}
}
$colors = get_criticity_pie_colors($data_graph_by_criticity);
$options_charts['colors'] = array_values($colors);
$colors = get_criticity_pie_colors($data_graph_by_criticity);
$options_charts['colors'] = array_values($colors);
if ((int) $ttl === 2) {
$result_data_graph_by_criticity = [];
foreach ($data_graph_by_criticity as $key => $value) {
$result_data_graph_by_criticity[$key.' ('.$value.')'] = $value;
}
$data_graph_by_criticity = $result_data_graph_by_criticity;
}
}
if ((int) $ttl === 2) {
$return['chart']['by_criticity'] = '<img src="data:image/png;base64,';
@ -4365,13 +4480,22 @@ function reporting_event_report_agent(
0 => __('Not validated'),
];
foreach ($return['data'] as $value) {
$k = $status[$value['estado']];
$k = $status[$value['status']];
if (isset($data_graph_by_status[$k]) === true) {
$data_graph_by_status[$k]++;
} else {
$data_graph_by_status[$k] = 1;
}
}
if ((int) $ttl === 2) {
$result_data_graph_by_status = [];
foreach ($data_graph_by_status as $key => $value) {
$result_data_graph_by_status[$key.' ('.$value.')'] = $value;
}
$data_graph_by_status = $result_data_graph_by_status;
}
}
if ((int) $ttl === 2) {
@ -5272,20 +5396,44 @@ function reporting_custom_render($report, $content, $type='dinamic', $pdf=0)
],
];
if ($pdf === true) {
$options['dataLabel'] = ['display' => 'auto'];
$options['layout'] = [
'padding' => [
'top' => 15,
'bottom' => 15,
],
];
}
$data = array_reduce(
$data_query,
function ($carry, $item) {
$carry[$item['label']] = $item['value'];
function ($carry, $item) use ($pdf) {
if ($pdf === true) {
$carry[$item['label'].' ('.$item['value'].')'] = $item['value'];
} else {
$carry[$item['label']] = $item['value'];
}
return $carry;
},
[]
);
$value_query = '<div style="width:'.$width.'px;">';
if ($pdf === true) {
$value_query .= '<img src="data:image/png;base64,';
}
$value_query .= pie_graph(
$data,
$options
);
if ($pdf === true) {
$value_query .= '" />';
}
$value_query .= '</div>';
}
}
@ -5398,6 +5546,10 @@ function agents_get_network_interfaces_array(
$row_data['agent'] = $agent['name'];
$row_data['interfaces'] = [];
foreach ($agent['interfaces'] as $interface_name => $interface) {
if (isset($interface['traffic']) === false) {
$interface['traffic'] = [];
}
$row_interface = [];
$row_interface['name'] = $interface_name;
$row_interface['ip'] = $interface['ip'];
@ -10934,8 +11086,27 @@ function reporting_get_module_detailed_event(
'ttl' => $ttl,
];
if ((int) $ttl === 2) {
$options_charts['dataLabel'] = ['display' => 'auto'];
$options_charts['layout'] = [
'padding' => [
'top' => 15,
'bottom' => 15,
],
];
}
if ($event_graph_by_user_validator) {
$data_graph_by_user = events_get_count_events_validated_by_user($event['data']);
if ((int) $ttl === 2) {
$result_data_graph_by_user = [];
foreach ($data_graph_by_user as $key => $value) {
$result_data_graph_by_user[$key.' ('.$value.')'] = $value;
}
$data_graph_by_user = $result_data_graph_by_user;
}
if ((int) $ttl === 2) {
$event['chart']['by_user_validator'] = '<img src="data:image/png;base64,';
} else {
@ -10965,10 +11136,19 @@ function reporting_get_module_detailed_event(
$data_graph_by_criticity[$k] = 1;
}
}
}
$colors = get_criticity_pie_colors($data_graph_by_criticity);
$options_charts['colors'] = array_values($colors);
$colors = get_criticity_pie_colors($data_graph_by_criticity);
$options_charts['colors'] = array_values($colors);
if ((int) $ttl === 2) {
$result_data_graph_by_criticity = [];
foreach ($data_graph_by_criticity as $key => $value) {
$result_data_graph_by_criticity[$key.' ('.$value.')'] = $value;
}
$data_graph_by_criticity = $result_data_graph_by_criticity;
}
}
if ((int) $ttl === 2) {
$event['chart']['by_criticity'] = '<img src="data:image/png;base64,';
@ -11005,6 +11185,15 @@ function reporting_get_module_detailed_event(
$data_graph_by_status[$k] = 1;
}
}
if ((int) $ttl === 2) {
$result_data_graph_by_status = [];
foreach ($data_graph_by_status as $key => $value) {
$result_data_graph_by_status[$key.' ('.$value.')'] = $value;
}
$data_graph_by_status = $result_data_graph_by_status;
}
}
if ((int) $ttl === 2) {

View File

@ -162,12 +162,15 @@ function progressbar(
*/
function vbar_graph(
array $chart_data,
array $options,
int $ttl=1
array $options
) {
global $config;
if (empty($chart_data) === true) {
if (isset($options['ttl']) === true
&& (int) $options['ttl'] === 2
) {
$options['base64'] = true;
}
return graph_nodata_image($options);
}
@ -386,6 +389,12 @@ function pie_graph(
$options
) {
if (empty($chart_data) === true) {
if (isset($options['ttl']) === true
&& (int) $options['ttl'] === 2
) {
$options['base64'] = true;
}
return graph_nodata_image($options);
}
@ -605,10 +614,11 @@ function get_build_setup_charts($type, $options, $data)
$chart->setWidth($options['width']);
}
// Fonts.
$chart->defaults()->getFonts()->setFamily($config['fontpath']);
// Fonts defaults.
$chart->defaults()->getFonts()->setFamily((empty($config['fontpath']) === true) ? 'Lato' : $config['fontpath']);
$chart->defaults()->getFonts()->setStyle('normal');
$chart->defaults()->getFonts()->setSize(($config['font_size']) + 2);
$chart->defaults()->getFonts()->setWeight(600);
$chart->defaults()->getFonts()->setSize(((int) $config['font_size'] + 2));
if (isset($options['waterMark']) === true
&& empty($options['waterMark']) === false
@ -768,7 +778,11 @@ function get_build_setup_charts($type, $options, $data)
$dataLabel->setFormatter($dataLabelFormatter);
$dataLabel->getFonts()->setSize(8);
// Defaults fonts datalabel.
$dataLabel->getFonts()->setFamily((empty($config['fontpath']) === true) ? 'Lato' : $config['fontpath']);
$dataLabel->getFonts()->setStyle('normal');
$dataLabel->getFonts()->setWeight(600);
$dataLabel->getFonts()->setSize(((int) $config['font_size'] + 2));
if (isset($options['dataLabel']['fonts']) === true
&& empty($options['dataLabel']['fonts']) === false
@ -782,6 +796,10 @@ function get_build_setup_charts($type, $options, $data)
$dataLabel->getFonts()->setStyle($options['dataLabel']['fonts']['style']);
}
if (isset($options['dataLabel']['fonts']['weight']) === true) {
$dataLabel->getFonts()->setWeight($options['dataLabel']['fonts']['weight']);
}
if (isset($options['dataLabel']['fonts']['family']) === true) {
$dataLabel->getFonts()->setFamily($options['dataLabel']['fonts']['family']);
}
@ -793,48 +811,50 @@ function get_build_setup_charts($type, $options, $data)
&& empty($options['title']) === false
&& is_array($options['title']) === true
) {
$chartTitle = $chart->options()->getPlugins()->getTitle();
$display = false;
if (isset($options['title']['display']) === true) {
$display = $options['title']['display'];
}
$chart->options()->getPlugins()->getTitle()->setDisplay($display);
$chartTitle->setDisplay($display);
$text = __('Title');
if (isset($options['title']['text']) === true) {
$text = $options['title']['text'];
}
$chart->options()->getPlugins()->getTitle()->setText($text);
$chartTitle->setText($text);
$position = 'top';
if (isset($options['title']['position']) === true) {
$position = $options['title']['position'];
}
$chart->options()->getPlugins()->getTitle()->setPosition($position);
$chartTitle->setPosition($position);
$color = 'top';
if (isset($options['title']['color']) === true) {
$color = $options['title']['color'];
}
$chart->options()->getPlugins()->getTitle()->setColor($color);
$chartTitle->setColor($color);
if (isset($options['title']['fonts']) === true
&& empty($options['title']['fonts']) === false
&& is_array($options['title']['fonts']) === true
) {
if (isset($options['title']['fonts']['size']) === true) {
$chart->options()->getPlugins()->getTitle()->getFonts()->setSize($options['title']['fonts']['size']);
$chartTitle->getFonts()->setSize($options['title']['fonts']['size']);
}
if (isset($options['title']['fonts']['style']) === true) {
$chart->options()->getPlugins()->getTitle()->getFonts()->setStyle($options['title']['fonts']['style']);
$chartTitle->getFonts()->setStyle($options['title']['fonts']['style']);
}
if (isset($options['title']['fonts']['family']) === true) {
$chart->options()->getPlugins()->getTitle()->getFonts()->setFamily($options['title']['fonts']['family']);
$chartTitle->getFonts()->setFamily($options['title']['fonts']['family']);
}
}
}
@ -865,6 +885,21 @@ function get_build_setup_charts($type, $options, $data)
&& is_array($options['scales']) === true
) {
$scales = $chart->options()->getScales();
// Defaults scalesFont X.
$scalesXFonts = $scales->getX()->ticks()->getFonts();
$scalesXFonts->setFamily((empty($config['fontpath']) === true) ? 'Lato' : $config['fontpath']);
$scalesXFonts->setStyle('normal');
$scalesXFonts->setWeight(600);
$scalesXFonts->setSize(((int) $config['font_size'] + 2));
// Defaults scalesFont Y.
$scalesYFonts = $scales->getY()->ticks()->getFonts();
$scalesYFonts->setFamily((empty($config['fontpath']) === true) ? 'Lato' : $config['fontpath']);
$scalesYFonts->setStyle('normal');
$scalesYFonts->setWeight(600);
$scalesYFonts->setSize(((int) $config['font_size'] + 2));
if (isset($options['scales']['x']) === true
&& empty($options['scales']['x']) === false
&& is_array($options['scales']['x']) === true
@ -1007,7 +1042,7 @@ function get_build_setup_charts($type, $options, $data)
break;
default:
// code...
// Not possible.
break;
}

View File

@ -1,19 +0,0 @@
var webPage = require("webpage");
var page = webPage.create();
var url =
"http://nova/pandora_console/operation/agentes/stat_win.php?type=sparse&period=86400&id=136574&label=QXJ0aWNhJiN4MjA7d2ViJiN4MjA7cGFnZSYjeDIwO2V4YW1wbGU%3D&refresh=600&draw_events=0";
var r = page.addCookie({
name: "PHPSESSID" /* required property */,
value: "23qu7l1sgb3iq3bkaedr724hp3" /* required property */,
path: "/pandora_console",
domain: "nova"
});
console.log(r);
page.viewportSize = { width: 750, height: 350 };
page.open(url, function start(status) {
page.render("output.jpeg", { format: "jpeg", quality: "100" });
phantom.exit();
});

View File

@ -1,189 +0,0 @@
var system = require("system");
/* global phantom */
if (system.args.length < 3 || system.args.length > 11) {
phantom.exit(1);
}
var url = system.args[1];
var type_graph_pdf = system.args[2];
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 viewport_width = system.args[7];
var viewport_height = system.args[8];
var session_id = system.args[9];
var base_64 = system.args[10];
var post_data = "";
if (!viewport_width) {
viewport_width = 750;
}
if (!viewport_height) {
viewport_height = 350;
}
if (type_graph_pdf == "combined") {
post_data = {
data: url_params,
session_id: session_id,
type_graph_pdf: type_graph_pdf,
data_module_list: url_module_list,
data_combined: url_params_comb
};
} else {
post_data = {
data: url_params,
session_id: session_id,
type_graph_pdf: type_graph_pdf
};
}
/* DEBUG
page.onAlert = function() {
console.log("onAlert");
};
page.onCallback = function() {
console.log("onCallback");
};
page.onClosing = function() {
console.log("onClosing");
};
page.onConfirm = function() {
console.log("onConfirm");
};
page.onConsoleMessage = function() {
console.log("onConsoleMessage");
};
page.onError = function() {
console.log("onError");
};
page.onFilePicker = function() {
console.log("onFilePicker");
};
page.onInitialized = function() {
console.log("onInitialized");
};
page.onLoadFinished = function() {
console.log("onLoadFinished");
};
page.onLoadStarted = function() {
console.log("onLoadStarted");
};
page.onNavigationRequested = function() {
console.log("onNavigationRequested");
};
page.onPageCreated = function() {
console.log("onPageCreated");
};
page.onPrompt = function() {
console.log("onPrompt");
};
page.onResourceError = function() {
console.log("onResourceError");
};
page.onResourceReceived = function(res) {
console.log("onResourceReceived" + ";" + res.url + ";" + res.status);
};
page.onResourceRequested = function(res) {
console.log("onResourceRequested" + ";" + res.url);
};
page.onResourceTimeout = function() {
console.log("onResourceTimeout");
};
page.onUrlChanged = function(url) {
console.log("onUrlChanged" + ";" + url);
};
*/
var page = require("webpage").create();
page.onResourceError = function(resourceError) {
console.log(
"Unable to load resource (#" +
resourceError.id +
"URL:" +
resourceError.url +
")"
);
console.log(
"Error code: " +
resourceError.errorCode +
". Description: " +
resourceError.errorString
);
phantom.exit(1);
};
// Not supposed to be prompted messages.
page.onPrompt = function() {
console.log("Prompt message detected.");
phantom.exit(1);
};
page.viewportSize = {
width: viewport_width,
height: viewport_height
};
page.zoomFactor = 1;
page.settings.userAgent =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36";
page.settings.resourceTimeout = 120000;
page.settings.localToRemoteUrlAccessEnabled = true;
page.onConsoleMessage = function(msg) {
console.log(msg);
page.close();
phantom.exit();
};
page.onError = function(msg) {
console.log(msg);
page.close();
phantom.exit();
};
page.onCallback = function() {
if (!base_64) {
page.render(output_filename, { format: "png" });
} else {
page.settings.loadImages = false;
var base64 = page.renderBase64("png");
// do not remove this console.output
console.log(base64);
}
phantom.exit();
};
page.open(url, "POST", "data=" + btoa(JSON.stringify(post_data)), function(
status
) {
if (status == "fail") {
console.out("Failed to generate chart.");
phantom.exit();
}
});
phantom.onError = function(msg, trace) {
var msgStack = ["PHANTOM ERROR: " + msg];
if (trace && trace.length) {
msgStack.push("TRACE:");
trace.forEach(function(t) {
msgStack.push(
" -> " +
(t.file || t.sourceURL) +
": " +
t.line +
(t.function ? " (in function " + t.function + ")" : "")
);
});
}
console.log(msgStack.join("\n"));
phantom.exit(1);
};

View File

@ -92,6 +92,7 @@ RUN dnf install -y vim wget bzip2 curl && \
libstdc++ \
gettext \
wmic \
chromium \
cpanminus && \
cpanm Geo::IP && \
mkdir -p /opt/phantomjs/bin && cd /opt/phantomjs/bin && \