'.$t_text.''; } else { $return = ''.$t_text.''; } } else { $return = ui_print_truncate_text($text); } } return $return; } /** * Truncate a text to num chars (pass as parameter) and if flag show tooltip is * true the html artifal to show the tooltip with rest of text. * * @param string $text The text to truncate. * @param mixed $numChars Number chars (-3 for char "[...]") max the text. Or the strings "agent_small", "agent_medium", "module_small", "module_medium", "description" or "generic" for to take the values from user config. * @param boolean $showTextInAToopTip Flag to show the tooltip. * @param boolean $return Flag to return as string or not. * @param boolean $showTextInTitle Flag to show the text on title. * @param string $suffix String at the end of a strimmed string. * @param string $style Style associated to the text. * * @return string Truncated text. */ function ui_print_truncate_text($text, $numChars=GENERIC_SIZE_TEXT, $showTextInAToopTip=true, $return=true, $showTextInTitle=true, $suffix='…', $style=false) { global $config; if (is_string($numChars)) { switch ($numChars) { case 'agent_small': $numChars = $config['agent_size_text_small']; break; case 'agent_medium': $numChars = $config['agent_size_text_medium']; break; case 'module_small': $numChars = $config['module_size_text_small']; break; case 'module_medium': $numChars = $config['module_size_text_medium']; break; case 'description': $numChars = $config['description_size_text']; break; case 'item_title': $numChars = $config['item_title_size_text']; break; default: $numChars = (int) $numChars; break; } } if ($numChars == 0) { if ($return == true) { return $text; } else { echo $text; } } $text_html_decoded = io_safe_output($text); $text_has_entities = $text != $text_html_decoded; if (mb_strlen($text_html_decoded, 'UTF-8') > ($numChars)) { // '/2' because [...] is in the middle of the word. $half_length = intval(($numChars - 3) / 2); // Depending on the strange behavior of mb_strimwidth() itself, // the 3rd parameter is not to be $numChars but the length of // original text (just means 'large enough'). $truncateText2 = mb_strimwidth( $text_html_decoded, (mb_strlen($text_html_decoded, 'UTF-8') - $half_length), mb_strlen($text_html_decoded, 'UTF-8'), '', 'UTF-8' ); $truncateText = mb_strimwidth( $text_html_decoded, 0, ($numChars - $half_length), '', 'UTF-8' ); // Recover the html entities to avoid XSS attacks. $truncateText = ($text_has_entities) ? io_safe_input($truncateText).$suffix.io_safe_input($truncateText2) : $truncateText.$suffix.$truncateText2; if ($showTextInTitle) { if ($style === null) { $truncateText = $truncateText; } else if ($style !== false) { $truncateText = ''.$truncateText.''; } else { $truncateText = ''.$truncateText.''; } } if ($showTextInAToopTip) { if (is_string($showTextInAToopTip)) { $text = ui_print_truncate_text($showTextInAToopTip, ($numChars * 2), false, true, false); } $truncateText = $truncateText.ui_print_help_tip(htmlspecialchars($text), true); } else { if ($style !== false) { $truncateText = ''.$truncateText.''; } } } else { if ($style !== false) { $truncateText = ''.$text.''; } else { $truncateText = $text; } } if ($return == true) { return $truncateText; } else { echo $truncateText; } } /** * Print a string with a smaller font depending on its size. * * @param string $string String to be display with a smaller font. * @param boolean $return Flag to return as string or not. * * @return string HTML. */ function printSmallFont($string, $return=true) { $str = io_safe_output($string); $length = strlen($str); if ($length >= 30) { $size = 0.7; } else if ($length >= 20) { $size = 0.8; } else if ($length >= 10) { $size = 0.9; } else if ($length < 10) { $size = 1; } $s = ''; $s .= $string; $s .= ''; if ($return) { return $s; } else { echo $s; } } /** * Prints a generic message between tags. * * @param mixed $message The string message or array [ * 'title', 'message', 'icon', 'no_close', 'force_style'] to be displayed. * @param string $class The class to be used. * @param string $attributes Any other attributes to be set for the tag. * @param boolean $return Whether to output the string or return it. * @param string $tag What tag to use (you could specify something else * than h3 like div or h2). * * @return string HTML code if return parameter is true. */ function ui_print_message($message, $class='', $attributes='', $return=false, $tag='h3') { static $first_execution = true; $text_title = ''; $text_message = ''; $icon_image = ''; $no_close_bool = false; $force_style = ''; $force_class = ''; if (is_array($message)) { if (!empty($message['title'])) { $text_title = $message['title']; } if (!empty($message['message'])) { $text_message = $message['message']; } if (!empty($message['icon'])) { $icon_image = $message['icon']; } if (!empty($message['no_close'])) { $no_close_bool = $message['no_close']; } if (!empty($message['force_style'])) { $force_style = $message['force_style']; } if (empty($message['force_class']) === false) { $force_class = $message['force_class']; } } else { $text_message = $message; } if (empty($text_title)) { switch ($class) { default: case 'info': $text_title = __('Information'); break; case 'error': $text_title = __('Error'); break; case 'suc': $text_title = __('Success'); break; case 'warning': $text_title = __('Warning'); break; } } if (empty($icon_image)) { switch ($class) { default: case 'info': $icon_image = 'images/information_big.png'; break; case 'error': $icon_image = 'images/err.png'; break; case 'suc': $icon_image = 'images/suc.png'; break; case 'warning': $icon_image = 'images/warning_big.png'; break; } $icon_image = $icon_image; } $id = 'info_box_'.uniqid(); if (empty($force_class) === false) { $class = $class.' '.$force_class; } // Use the no_meta parameter because this image is only in the base console. $output = ''; if (($first_execution) && (!$no_close_bool)) { $first_execution = false; $output .= ' '; } if ($return) { return $output; } else { echo $output; } return ''; } /** * Prints an error message. * * @param mixed $message The string error message or array * ('title', 'message', 'icon', 'no_close') to be displayed. * @param string $attributes Any other attributes to be set for the tag. * @param boolean $return Whether to output the string or return it. * @param string $tag What tag to use (you could specify something else * than h3 like div or h2). * * @return string HTML code if return parameter is true. */ function ui_print_error_message($message, $attributes='', $return=false, $tag='h3') { return ui_print_message($message, 'error', $attributes, $return, $tag); } /** * Prints an operation success message. * * @param mixed $message The string message or array * ('title', 'message', 'icon', 'no_close') to be displayed. * @param string $attributes Any other attributes to be set for the tag. * @param boolean $return Whether to output the string or return it. * @param string $tag What tag to use (you could specify something else * than h3 like div or h2). * * @return string HTML code if return parameter is true. */ function ui_print_success_message($message, $attributes='', $return=false, $tag='h3') { return ui_print_message($message, 'suc', $attributes, $return, $tag); } /** * Prints an operation info message. * * @param mixed $message The string message or array * ('title', 'message', 'icon', 'no_close') to be displayed. * @param string $attributes Any other attributes to be set for the tag. * @param boolean $return Whether to output the string or return it. * @param string $tag What tag to use (you could specify something else * than h3 like div or h2). * * @return string HTML code if return parameter is true. */ function ui_print_info_message($message, $attributes='', $return=false, $tag='h3') { return ui_print_message($message, 'info', $attributes, $return, $tag); } /** * Prints an operation info message - empty data. * * @param mixed $message The string message or array * ('title', 'message', 'icon', 'no_close') to be displayed. * @param string $attributes Any other attributes to be set for the tag. * @param boolean $return Whether to output the string or return it. * @param string $tag What tag to use (you could specify something else * than h3 like div or h2). * * @return string HTML code if return parameter is true. */ function ui_print_empty_data($message, $attributes='', $return=false, $tag='h3') { return ui_print_message($message, 'info', $attributes, $return, $tag); } /** * Evaluates a result using empty() and then prints an error or success message * * @param mixed $result The results to evaluate. 0, NULL, false, '' or * array() is bad, the rest is good. * @param mixed $good The string or array ('title', 'message') to be * displayed if the result was good. * @param mixed $bad The string or array ('title', 'message') to be * displayed if the result was bad. * @param string $attributes Any other attributes to be set for the h3. * @param boolean $return Whether to output the string or return it. * @param string $tag What tag to use (you could specify something else * than h3 like div or h2). * * @return string HTML code if return parameter is true. */ function ui_print_result_message($result, $good='', $bad='', $attributes='', $return=false, $tag='h3') { if ($good == '' || $good === false) { $good = __('Request successfully processed'); } if ($bad == '' || $bad === false) { $bad = __('Error processing request'); } if (empty($result)) { return ui_print_error_message($bad, $attributes, $return, $tag); } else { return ui_print_success_message($good, $attributes, $return, $tag); } } /** * Prints an warning message. * * @param mixed $message The string message or array * ('title', 'message', 'icon', 'no_close') to be displayed. * @param string $attributes Any other attributes to be set for the tag. * @param boolean $return Whether to output the string or return it. * @param string $tag What tag to use (you could specify something else * than h3 like div or h2). * * @return string HTML code if return parameter is true. */ function ui_print_warning_message($message, $attributes='', $return=false, $tag='h3') { return ui_print_message($message, 'warning', $attributes, $return, $tag); } /** * Evaluates a unix timestamp and returns a span (or whatever tag specified) * with as title the correctly formatted full timestamp and a time comparation * in the tag * * @param integer $unixtime Any type of timestamp really, but we prefer unixtime. * @param boolean $return Whether to output the string or return it. * @param array $option An array with different options for this function * Key html_attr: which html attributes to add (defaults to none) * Key tag: Which html tag to use (defaults to span) * Key prominent: Overrides user preference and display "comparation" or "timestamp" * key units: The type of units. * * @return string HTML code if return parameter is true. */ function ui_print_timestamp($unixtime, $return=false, $option=[]) { global $config; // TODO: Add/use a javascript timer for the seconds so it automatically // updates as time passes by. if (isset($option['html_attr'])) { $attributes = $option['html_attr']; } else { $attributes = ''; } if (isset($option['tag'])) { $tag = $option['tag']; } else { $tag = 'span'; } if (empty($option['style'])) { $style = 'class="nowrap"'; } else { $style = 'style="'.$option['style'].'"'; } if (!empty($option['prominent'])) { $prominent = $option['prominent']; } else { $prominent = $config['prominent_time']; } if (!is_numeric($unixtime)) { $unixtime = time_w_fixed_tz($unixtime); } // Prominent_time is either timestamp or comparation. if ($unixtime <= 0) { $title = __('Unknown').'/'.__('Never'); $data = __('Unknown'); } else if ($prominent == 'timestamp') { pandora_setlocale(); $title = human_time_comparation($unixtime); $date = new DateTime(); $date->setTimestamp($unixtime); $data = $date->format($config['date_format']); } else if ($prominent == 'compact') { $units = 'tiny'; $title = date($config['date_format'], $unixtime); $data = human_time_comparation($unixtime, $units); } else { $title = date($config['date_format'], $unixtime); $units = 'large'; if (isset($option['units'])) { $units = $option['units']; } $data = human_time_comparation($unixtime, $units); } $output = '<'.$tag; switch ($tag) { default: // Usually tags have title attributes, so by default we add, // then fall through to add attributes and data. $output .= ' title="'.$title.'" '.$style.'>'.$data.''; break; case 'h1': case 'h2': case 'h3': // Above tags don't have title attributes. $output .= ' '.$attributes.' '.$style.'>'.$data.''; break; } if ($return) { return $output; } echo $output; } /** * Prints a username with real name, link to the user_edit page etc. * * @param string $username The username to render. * @param boolean $return Whether to return or print. * * @return string HTML code if return parameter is true. */ function ui_print_username($username, $return=false) { $string = ''.get_user_fullname($username).''; if ($return) { return $string; } echo $string; } /** * Show a notification. * * @param boolean $return Return or direct echo. * * @return string HTML. */ function ui_print_tags_warning($return=false) { $msg = '
'; $msg .= __('Is possible that this view uses part of information which your user has not access'); $msg .= '
'; if ($return) { return $msg; } else { echo $msg; } } /** * Print group icon within a link * * @param integer $id_group Group id. * @param boolean $return Whether to return or print. * @param string $path What path to use (relative to images/). * Defaults to groups_small. * @param string $style Style for group image. * @param boolean $link Whether the group have link or not. * @param boolean $force_show_image Force show image. * @param boolean $show_as_image Show as image. * * @return string HTML code if return parameter is true. */ function ui_print_group_icon($id_group, $return=false, $path='groups_small', $style='', $link=true, $force_show_image=false, $show_as_image=false) { global $config; if ($id_group > 0) { $icon = (string) db_get_value('icon', 'tgrupo', 'id_grupo', (int) $id_group); } else { $icon = 'world'; } $output = ''; // Don't show link in metaconsole. if (defined('METACONSOLE')) { $link = false; } if ($link) { $output = ''; } if ($config['show_group_name']) { $output .= ''.groups_get_name($id_group, true).' '; } else { if (empty($icon)) { $output .= '  '; } else { $class = 'bot'; if ($icon === 'transmit') { $class .= ' invert_filter'; } $output .= html_print_image( 'images/'.$path.'/'.$icon.'.png', true, [ 'style' => $style, 'class' => $class, 'alt' => groups_get_name($id_group, true), 'title' => groups_get_name($id_group, true), ], false, false, false, true ); } } if ($link) { $output .= ''; } if (!$return) { echo $output; } return $output; } /** * Print group icon within a link. Other version. * * @param integer $id_group Group id. * @param boolean $return Whether to return or print. * @param string $path What path to use (relative to images/). * Defaults to groups_small. * @param string $style Extra styles. * @param boolean $link Add anchor. * * @return string HTML code if return parameter is true. */ function ui_print_group_icon_path($id_group, $return=false, $path='images/groups_small', $style='', $link=true) { if ($id_group > 0) { $icon = (string) db_get_value('icon', 'tgrupo', 'id_grupo', (int) $id_group); } else { $icon = 'world'; } if ($style == '') { $style = 'width: 16px; height: 16px;'; } $output = ''; if ($link) { $output = ''; } if (empty($icon)) { $output .= ' - '; } else { $output .= ''.groups_get_name($id_group, true).''; } if ($link) { $output .= ''; } if (!$return) { echo $output; } return $output; } /** * Get the icon of an operating system. * * @param integer $id_os Operating system id. * @param boolean $name Whether to also append the name of OS after icon. * @param boolean $return Whether to return or echo the result. * @param boolean $apply_skin Whether to apply skin or not. * @param boolean $networkmap Networkmap. * @param boolean $only_src Only_src. * @param boolean $relative Relative. * @param boolean $options Options. * @param boolean $big_icons Big_icons. * * @return string HTML with icon of the OS */ function ui_print_os_icon( $id_os, $name=true, $return=false, $apply_skin=true, $networkmap=false, $only_src=false, $relative=false, $options=false, $big_icons=false ) { $subfolder = 'os_icons'; if ($networkmap) { $subfolder = 'networkmap'; } if ($big_icons) { $subfolder .= '/so_big_icons'; } if (is_metaconsole()) { $no_in_meta = false; } else { $no_in_meta = true; } $icon = (string) db_get_value('icon_name', 'tconfig_os', 'id_os', (int) $id_os); $os_name = get_os_name($id_os); if (empty($icon)) { if ($only_src) { $output = html_print_image( 'images/'.$subfolder.'/unknown.png', true, $options, true, $relative, $no_in_meta, true ); } else { return '-'; } } else if ($apply_skin) { if ($only_src) { $output = html_print_image('images/'.$subfolder.'/'.$icon, true, $options, true, $relative, $no_in_meta, true); } else { if (!isset($options['title'])) { $options['title'] = $os_name; } $output = html_print_image('images/'.$subfolder.'/'.$icon, true, $options, false, $relative, $no_in_meta, true); } } else { // $output = "" . $os_name . ""; $output = 'images/'.$subfolder.'/'.$icon; } if ($name === true) { $output .= '  '.$os_name; } if (!$return) { echo $output; } return $output; } /** * Print type agent icon. * * @param boolean $id_os Id_os. * @param boolean $remote_contact Remote_contact. * @param boolean $contact Contact. * @param boolean $return Return. * @param integer $remote Remote. * @param string $version Version. * * @return string HTML. */ function ui_print_type_agent_icon( $id_os=false, $remote_contact=false, $contact=false, $return=false, $remote=0, $version='' ) { global $config; if ($id_os == 19) { // Satellite. $options['title'] = __('Satellite'); $output = html_print_image('images/satellite.png', true, ['class' => 'invert_filter'], false, false, false, true); } else if ($remote_contact == $contact && $remote == 0 && $version == '') { // Network. $options['title'] = __('Network'); $output = html_print_image('images/network.png', true, ['class' => 'invert_filter'], false, false, false, true); } else { // Software. $options['title'] = __('Software'); $output = html_print_image('images/data.png', true, ['class' => 'invert_filter'], false, false, false, true); } return $output; } /** * Prints an agent name with the correct link * * @param integer $id_agent Agent id. * @param boolean $return Whether to return the string or echo it too. * @param integer $cutoff Now uses styles to accomplish this. * @param string $style Style of name in css. * @param boolean $cutname Cut names. * @param string $server_url Server url to concatenate at the begin of the link. * @param string $extra_params Extra parameters to concatenate in the link. * @param string $known_agent_name Name of the agent to avoid the query in some cases. * @param boolean $link If the agent will provided with link or not. * @param boolean $alias Use the agent alias or the name. * * @return string HTML with agent name and link */ function ui_print_agent_name( $id_agent, $return=false, $cutoff='agent_medium', $style='', $cutname=false, $server_url='', $extra_params='', $known_agent_name=false, $link=true, $alias=true ) { if ($known_agent_name === false) { if ($alias) { $agent_name = (string) agents_get_alias($id_agent); } else { $agent_name = (string) agents_get_name($id_agent); } } else { $agent_name = $known_agent_name; } if ($alias) { $agent_name_full = (string) agents_get_name($id_agent); } else { $agent_name_full = $agent_name; } if ($cutname) { $agent_name = ui_print_truncate_text($agent_name, $cutoff, true, true, true, '[…]', $style); } if ($link) { $url = $server_url.'index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$id_agent.$extra_params; $output = ''.$agent_name.''; } else { $output = ''.$agent_name.''; } // TODO: Add a pretty javascript (using jQuery) popup-box with agent details. if ($return) { return $output; } echo $output; } /** * Formats a row from the alert table and returns an array usable in the table function * * @param array $alert A valid (non empty) row from the alert table. * @param boolean $agent Whether or not this is a combined alert. * @param string $url Tab where the function was called from (used for urls). * @param mixed $agent_style Style for agent name or default (false). * * @return array A formatted array with proper html for use in $table->data (6 columns) */ function ui_format_alert_row( $alert, $agent=true, $url='', $agent_style=false ) { global $config; if (!isset($alert['server_data'])) { $server_name = ''; $server_id = ''; $url_hash = ''; $console_url = ''; } else { $server_data = $alert['server_data']; $server_name = $server_data['server_name']; $server_id = $server_data['id']; $console_url = $server_data['server_url'].'/'; $url_hash = metaconsole_get_servers_url_hash($server_data); } $actionText = ''; include_once $config['homedir'].'/include/functions_alerts.php'; $isFunctionPolicies = enterprise_include_once('include/functions_policies.php'); $id_group = (int) get_parameter('ag_group', 0); // 0 is the All group (selects all groups). if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK) { if ($agent) { $index = [ 'policy' => 0, 'standby' => 1, 'force_execution' => 2, 'agent_name' => 3, 'module_name' => 4, 'description' => 5, 'template' => 5, 'action' => 6, 'last_fired' => 7, 'status' => 8, 'validate' => 9, ]; } else { $index = [ 'policy' => 0, 'standby' => 1, 'force_execution' => 2, 'agent_name' => 3, 'module_name' => 3, 'description' => 4, 'template' => 4, 'action' => 5, 'last_fired' => 6, 'status' => 7, 'validate' => 8, ]; } } else { if ($agent) { $index = [ 'standby' => 0, 'force_execution' => 1, 'agent_name' => 2, 'module_name' => 3, 'description' => 4, 'template' => 4, 'action' => 5, 'last_fired' => 6, 'status' => 7, 'validate' => 8, ]; } else { $index = [ 'standby' => 0, 'force_execution' => 1, 'agent_name' => 2, 'module_name' => 2, 'description' => 3, 'template' => 3, 'action' => 4, 'last_fired' => 5, 'status' => 6, 'validate' => 7, ]; } } if ($alert['disabled']) { $disabledHtmlStart = ''; $disabledHtmlEnd = ''; $styleDisabled = 'font-style: italic; color: #aaaaaa;'; } else { $disabledHtmlStart = ''; $disabledHtmlEnd = ''; $styleDisabled = ''; } if (empty($alert) === true) { if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK) { return [ '', '', '', '', '', '', '', '', ]; } else { return [ '', '', '', '', '', '', '', ]; } } if (is_metaconsole() === true && (int) $server_id !== 0) { $server = db_get_row('tmetaconsole_setup', 'id', $alert['server_data']['id']); if (metaconsole_connect($server) == NOERR) { // Get agent data from node. $agente = db_get_row('tagente', 'id_agente', $alert['id_agent']); metaconsole_restore_db(); } } else { // Get agent id. $id_agent = modules_get_agentmodule_agent($alert['id_agent_module']); $agente = db_get_row('tagente', 'id_agente', $id_agent); } $template = alerts_get_alert_template($alert['id_alert_template']); $description = io_safe_output($template['name']); $data = []; // Validate checkbox. if (is_metaconsole() === false) { if (check_acl($config['id_user'], $id_group, 'LW') || check_acl($config['id_user'], $id_group, 'LM') ) { $data[$index['validate']] = ''; $data[$index['validate']] .= html_print_checkbox( 'validate[]', $alert['id'], false, true, false, '', true ); } } if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK) { if (is_metaconsole() === true && (int) $alert['server_data']['id'] !== 0) { $node = metaconsole_get_connection_by_id($alert['server_data']['id']); if (metaconsole_load_external_db($node) !== NOERR) { // Restore the default connection. metaconsole_restore_db(); $errors++; return false; } } $policyInfo = policies_is_alert_in_policy2($alert['id'], false); $module_linked = policies_is_module_linked($alert['id_agent_module']); if (is_array($policyInfo) === false && $module_linked === false) { $data[$index['policy']] = ''; } else { $module_linked = policies_is_module_linked($alert['id_agent_module']); if ($module_linked === '0') { $img = 'images/unlinkpolicy.png'; } else { $img = 'images/policies_mc.png'; } if (is_metaconsole() === false) { $data[$index['policy']] = ''.html_print_image($img, true, ['title' => $policyInfo['name']]).''; } else { $data[$index['policy']] = ''.html_print_image($img, true, ['title' => $policyInfo['name']]).''; } } if (is_metaconsole() === true) { metaconsole_restore_db(); } } // Standby. $data[$index['standby']] = ''; if (isset($alert['standby']) && $alert['standby'] == 1) { $data[$index['standby']] = html_print_image('images/bell_pause.png', true, ['title' => __('Standby on')]); } if (is_metaconsole() === false) { // Force alert execution. if (check_acl($config['id_user'], $id_group, 'AW') || check_acl($config['id_user'], $id_group, 'LM')) { if ($alert['force_execution'] == 0) { $data[$index['force_execution']] = ''.html_print_image('images/target.png', true, ['border' => '0', 'title' => __('Force'), 'class' => 'invert_filter']).''; } else { $data[$index['force_execution']] = ''.html_print_image('images/refresh.png', true, ['class' => 'invert_filter']).''; } } } $data[$index['agent_name']] = $disabledHtmlStart; if ($agent == 0) { $data[$index['module_name']] .= ui_print_truncate_text(isset($alert['agent_module_name']) ? $alert['agent_module_name'] : modules_get_agentmodule_name($alert['id_agent_module']), 'module_small', false, true, true, '[…]', ''); } else { if (is_metaconsole() === true) { $agent_name = $alert['agent_name']; $id_agent = $alert['id_agent']; } else { $agent_name = false; $id_agent = modules_get_agentmodule_agent($alert['id_agent_module']); } if (is_metaconsole() === true) { // Do not show link if user cannot access node if ((bool) can_user_access_node() === true) { $url = $server['server_url'].'/index.php?'.'sec=estado&'.'sec2=operation/agentes/ver_agente&'.'id_agente='.$agente['id_agente']; $data[$index['agent_name']] .= ''.''.$agente['alias'].''; } else { $data[$index['agent_name']] .= ''.$agente['alias'].''; } } else { if ($agent_style !== false) { $data[$index['agent_name']] .= ' '.$agente['alias'].''; } else { $data[$index['agent_name']] .= ' '.$agente['alias'].''; } } $data[$index['module_name']] = ui_print_truncate_text(isset($alert['agent_module_name']) ? $alert['agent_module_name'] : modules_get_agentmodule_name($alert['id_agent_module']), 'module_small', false, true, true, '[…]', ''); } $data[$index['agent_name']] .= $disabledHtmlEnd; $data[$index['description']] = ''; if (is_metaconsole() === true) { $data[$index['template']] .= ''; } else { $data[$index['template']] .= ''; } $data[$index['template']] .= html_print_image('images/zoom.png', true, ['class' => 'invert_filter']); $data[$index['template']] .= ' '; $actionDefault = db_get_value_sql( 'SELECT id_alert_action FROM talert_templates WHERE id = '.$alert['id_alert_template'] ); $data[$index['description']] .= $disabledHtmlStart.ui_print_truncate_text(io_safe_output($description), 'description', false, true, true, '[…]', '').$disabledHtmlEnd; $actions = alerts_get_alert_agent_module_actions($alert['id'], false, $alert['server_data']['id']); if (empty($actions) === false || $actionDefault != '') { $actionText = '
'; if ($actionDefault != '') { $actionText .= db_get_sql( sprintf( 'SELECT name FROM talert_actions WHERE id = %d', $actionDefault ) ).' ('.__('Default').')'; } } $data[$index['action']] = $actionText; $data[$index['last_fired']] = $disabledHtmlStart.ui_print_timestamp($alert['last_fired'], true).$disabledHtmlEnd; $status = STATUS_ALERT_NOT_FIRED; $title = ''; if ($alert['times_fired'] > 0) { $status = STATUS_ALERT_FIRED; $title = __('Alert fired').' '.$alert['internal_counter'].' '.__('time(s)'); } else if ($alert['disabled'] > 0) { $status = STATUS_ALERT_DISABLED; $title = __('Alert disabled'); } else { $status = STATUS_ALERT_NOT_FIRED; $title = __('Alert not fired'); } $data[$index['status']] = ui_print_status_image($status, $title, true); return $data; } /** * Prints a substracted string, length specified by cutoff, the full string will be in a rollover. * * @param string $string The string to be cut.. * @param integer $cutoff At how much characters to cut. * @param boolean $return Whether to return or print it out. * @param integer $fontsize Size font (fixed) in px, applyed as CSS style (optional). * * @return string HTML string. */ function ui_print_string_substr($string, $cutoff=16, $return=false, $fontsize=0) { if (empty($string)) { return ''; } $string2 = io_safe_output($string); if (mb_strlen($string2, 'UTF-8') > $cutoff) { $string3 = '...'; } else { $string3 = ''; } $font_size_mod = ''; if ($fontsize > 0) { $font_size_mod = "style='font-size: ".$fontsize."pt'"; } $string = ''; $string .= mb_substr($string2, 0, $cutoff, 'UTF-8').$string3.''; if ($return === false) { echo $string; } return $string; } /** * Gets a helper text explaining the requirement needs for an alert template * to get it fired. * * @param integer $id_alert_template Alert template id. * @param boolean $return Wheter to return or print it out. * @param boolean $print_values Wheter to put the values in the string or not. * * @return An HTML string if return was true. */ function ui_print_alert_template_example($id_alert_template, $return=false, $print_values=true) { $output = ''; $output .= html_print_image('images/information.png', true, ['class' => 'invert_filter']); $output .= ''; $template = alerts_get_alert_template($id_alert_template); switch ($template['type']) { case 'equal': // Do not translate the HTML attributes. $output .= __('The alert would fire when the value is '); break; case 'not_equal': // Do not translate the HTML attributes. $output .= __('The alert would fire when the value is not '); break; case 'regex': if ($template['matches_value']) { // Do not translate the HTML attributes. $output .= __('The alert would fire when the value matches '); } else { // End if. $output .= __('The alert would fire when the value doesn\'t match '); } $value = $template['value']; break; case 'max_min': if ($template['matches_value']) { // Do not translate the HTML attributes. $output .= __('The alert would fire when the value is between and '); } else { // End if. $output .= __('The alert would fire when the value is not between and '); } break; case 'max': // Do not translate the HTML attributes. $output .= __('The alert would fire when the value is over '); break; case 'min': // Do not translate the HTML attributes. $output .= __('The alert would fire when the value is under '); break; case 'warning': // Do not translate the HTML attributes. $output .= __('The alert would fire when the module is in warning status'); break; case 'critical': // Do not translate the HTML attributes. $output .= __('The alert would fire when the module is in critical status'); break; default: // Do nothing. $output .= __('Unknown option.'); break; } if ($print_values) { /* * Replace span elements with real values. This is done in such way to avoid * duplicating strings and make it easily modificable via Javascript. */ $output = str_replace('', $template['value'], $output); $output = str_replace('', $template['max_value'], $output); $output = str_replace('', $template['min_value'], $output); } $output .= ''; if ($return) { return $output; } echo $output; } /** * Prints a help tip icon. * * @param string $help_id Id of the help article. * @param boolean $return Whether to return or output the result. * @param string $home_url Home url if its necessary. * @param string $image Image path. * @param boolean $is_relative Route is relative or not. * @param string $id Target id. * * @return string The help tip */ function ui_print_help_icon( $help_id, $return=false, $home_url='', $image='images/help_green.png', $is_relative=false, $id='' ) { global $config; // Do not display the help icon if help is disabled. if ($config['disable_help']) { return ''; } if (empty($home_url)) { $home_url = ''; } if (defined('METACONSOLE')) { $home_url = '../../'.$home_url; } $url = get_help_info($help_id); $b = base64_encode($url); $help_handler = 'index.php?sec=view&sec2=general/help_feedback'; // Needs to use url encoded to avoid anchor lost. $help_handler .= '&b='.$b; $help_handler .= '&pure=1&url='.$url; $output = html_print_image( $image, true, [ 'class' => 'img_help', 'title' => __('Help'), 'onclick' => "open_help ('".ui_get_full_url($help_handler)."')", 'id' => $id, ], false, $is_relative && is_metaconsole() ); if (!$return) { echo $output; } return $output; } /** * Add a CSS file to the HTML head tag. * * To make a CSS file available just put it in include/styles. The * file name should be like "name.css". The "name" would be the value * needed to pass to this function. * * @param string $name Script name to add without the "jquery." prefix and the ".js" * suffix. Example: * * ui_require_css_file ('pandora'); * // Would include include/styles/pandora.js * . * @param string $path Path where script is placed. * * @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) { global $config; $filename = $path.$name.'.css'; if ($echo_tag === true) { echo ''; return null; } if (! isset($config['css'])) { $config['css'] = []; } if (isset($config['css'][$name])) { return true; } if (! file_exists($filename) && ! file_exists($config['homedir'].'/'.$filename) && ! file_exists($config['homedir'].'/'.ENTERPRISE_DIR.'/'.$filename) ) { return false; } if (is_metaconsole() && (isset($config['requirements_use_base_url']) === false || $config['requirements_use_base_url'] === false) ) { $config['css'][$name] = '/../../'.$filename; } else { $config['css'][$name] = $filename; } return true; } /** * Add a javascript file to the HTML head tag. * * To make a javascript file available just put it in include/javascript. The * file name should be like "name.js". The "name" would be the value * needed to pass to this function. * * @param string $name Script name to add without the "jquery." prefix and the ".js" * suffix. Example: * * ui_require_javascript_file ('pandora'); * // Would include include/javascript/pandora.js * . * @param string $path Path where script is placed. * @param boolean $echo_tag Just echo the script tag of the file. * * @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) { global $config; $filename = $path.$name.'.js'; if ($echo_tag) { echo ''; return null; } if (! isset($config['js'])) { $config['js'] = []; } if (isset($config['js'][$name])) { return true; } // We checks two paths because it may fails on enterprise. if (! file_exists($filename) && ! file_exists($config['homedir'].'/'.$filename)) { return false; } if (is_metaconsole() && (isset($config['requirements_use_base_url']) === false || $config['requirements_use_base_url'] === false) ) { $config['js'][$name] = '../../'.$filename; } else { $config['js'][$name] = $filename; } return true; } /** * Add a enteprise javascript file to the HTML head tag. * * * THIS FUNCTION COULD PRODUCE ISSUES WHILE INCLUDING JS FILES. * * USE ui_require_javascript_file('file', ENTERPRISE_DIR.'/location') INSTEAD. * * To make a javascript file available just put it in /include/javascript. The * file name should be like "name.js". The "name" would be the value * needed to pass to this function. * * @param string $name Script name to add without the "jquery." * prefix and the ".js" * suffix. Example: * * ui_require_javascript_file ('pandora'); * // Would include include/javascript/pandora.js * . * @param boolean $disabled_metaconsole Disabled metaconsole. * * @return boolean True if the file was added. False if the file doesn't exist. */ function ui_require_javascript_file_enterprise($name, $disabled_metaconsole=false) { global $config; $metaconsole_hack = ''; if ($disabled_metaconsole) { $metaconsole_hack = '../../'; } $filename = $metaconsole_hack.ENTERPRISE_DIR.'/include/javascript/'.$name.'.js'; if (! isset($config['js'])) { $config['js'] = []; } if (isset($config['js'][$name])) { return true; } // We checks two paths because it may fails on enterprise. if (!file_exists($filename) && !file_exists($config['homedir'].'/'.$filename) ) { return false; } $config['js'][$name] = $filename; return true; } /** * Add a jQuery file to the HTML head tag. * * To make a jQuery script available just put it in include/javascript. The * file name should be like "jquery.name.js". The "name" would be the value * needed to pass to this function. Notice that this function does not manage * jQuery denpendencies. * * @param string $name Script name to add without the "jquery." prefix and the ".js" * suffix. Example: * * ui_require_jquery_file ('form'); * // Would include include/javascript/jquery.form.js * . * @param string $path Path where script is placed. * @param boolean $echo_tag Just echo the script tag of the file. * * @return boolean True if the file was added. False if the file doesn't exist. */ function ui_require_jquery_file($name, $path='include/javascript/', $echo_tag=false) { global $config; $filename = $path.'jquery.'.$name.'.js'; if ($echo_tag) { echo ''; return null; } if (! isset($config['jquery'])) { $config['jquery'] = []; } if (isset($config['jquery'][$name])) { return true; } // We checks two paths because it may fails on enterprise. if (! file_exists($filename) && ! file_exists($config['homedir'].'/'.$filename) ) { return false; } $config['jquery'][$name] = $filename; return true; } /** * Callback function to add stuff to the head. This allows us to add scripts * to the header after the fact as well as extensive validation. * * DO NOT CALL print_f, echo, ob_start, ob_flush, ob_end functions here. * * To add css just put them in include/styles and then add them to the * $config['css'] array * * @param string $string Callback will fill this with the current buffer. * @param mixed $bitfield Callback will fill this with a bitfield (see ob_start). * * @return string String to return to the browser */ function ui_process_page_head($string, $bitfield) { global $config; global $vc_public_view; if (isset($config['ignore_callback']) && $config['ignore_callback'] == true) { return ''; } $output = ''; $config_refr = -1; if (isset($config['refr'])) { $config_refr = $config['refr']; } // If user is logged or displayed view is the public view of visual console. if ($config_refr > 0 && (isset($config['id_user']) || $vc_public_view == 1) ) { if ($config['enable_refr'] || $_GET['sec2'] == 'operation/agentes/estado_agente' || $_GET['sec2'] == 'operation/agentes/tactical' || $_GET['sec2'] == 'operation/agentes/group_view' || $_GET['sec2'] == 'operation/events/events' || $_GET['sec2'] == 'operation/snmpconsole/snmp_view' || $_GET['sec2'] == 'operation/dashboard/dashboard' ) { $query = ui_get_url_refresh(false, false); /* * $output .= ''; */ // End. } } $text_subtitle = isset($config['rb_product_name_alt']) ? '' : ' - '.__('the Flexible Monitoring System'); $output .= "\n\t"; $output .= ''.get_product_name().$text_subtitle.' '; $output .= ''; $output .= ' '; if ($config['language'] != 'en') { // Load translated strings - load them last so they overload all // the objects. ui_require_javascript_file('time_'.$config['language']); ui_require_javascript_file('date'.$config['language']); ui_require_javascript_file('countdown_'.$config['language']); } $output .= "\n\t"; /* * Load CSS */ if (empty($config['css'])) { $config['css'] = []; } $login_ok = true; if (! isset($config['id_user']) && isset($_GET['login'])) { if (isset($_POST['nick']) && isset($_POST['pass'])) { $nick = get_parameter_post('nick'); // This is the variable with the login. $pass = get_parameter_post('pass'); // This is the variable with the password. $nick = db_escape_string_sql($nick); $pass = db_escape_string_sql($pass); // Process_user_login is a virtual function which should be defined // in each auth file. // It accepts username and password. The rest should be internal to // the auth file. // The auth file can set $config["auth_error"] to an informative // error output or reference their internal error messages to it // process_user_login should return false in case of errors or // invalid login, the nickname if correct. $nick_in_db = process_user_login($nick, $pass); if ($nick_in_db === false) { $login_ok = false; } } } // First, if user has assigned a skin then try to use css files of // skin subdirectory. $isFunctionSkins = enterprise_include_once('include/functions_skins.php'); if (!$login_ok) { if ($isFunctionSkins !== ENTERPRISE_NOT_HOOK) { enterprise_hook('skins_cleanup'); } } $exists_css = false; if ($login_ok && $isFunctionSkins !== ENTERPRISE_NOT_HOOK) { // Checks if user's skin is available. $exists_skin = enterprise_hook('skins_is_path_set'); if ($exists_skin) { $skin_path = enterprise_hook('skins_get_skin_path'); $skin_styles = themes_get_css($skin_path.'include/styles/'); $exists_css = !empty($skin_styles); } } // Add the jquery UI styles CSS. $config['css']['jquery-UI'] = 'include/styles/js/jquery-ui.min.css'; $config['css']['jquery-UI-custom'] = 'include/styles/js/jquery-ui_custom.css'; // Add the dialog styles CSS. $config['css']['dialog'] = 'include/styles/dialog.css'; // Add the dialog styles CSS. $config['css']['dialog'] = 'include/styles/js/introjs.css'; // If the theme is the default, we don't load it twice. if ($config['style'] !== 'pandora') { // It loads the last of all. $config['css']['theme'] = 'include/styles/'.$config['style'].'.css'; } // If skin's css files exists then add them. if ($exists_css) { foreach ($skin_styles as $filename => $name) { $style = substr($filename, 0, (strlen($filename) - 4)); $config['css'][$style] = $skin_path.'include/styles/'.$filename; } } else { // Otherwise assign default and user's css. // User style should go last so it can rewrite common styles. $config['css'] = array_merge( [ 'common' => 'include/styles/common.css', 'menu' => 'include/styles/menu.css', 'tables' => 'include/styles/tables.css', 'general' => 'include/styles/pandora.css', ], $config['css'] ); } // We can't load empty and we loaded (conditionally) ie. $loaded = [ '', 'ie', ]; foreach ($config['css'] as $name => $filename) { if (in_array($name, $loaded)) { continue; } array_push($loaded, $name); $url_css = ui_get_full_url($filename, false, false, false); $output .= ''."\n\t"; } /* * End load CSS */ /* * Load jQuery */ if (empty($config['jquery'])) { $config['jquery'] = []; // If it's empty, false or not init set array to empty just in case. } // Pandora specific jquery should go first. $black_list_pages_old_jquery = ['operation/gis_maps/index']; if (in_array(get_parameter('sec2'), $black_list_pages_old_jquery)) { $config['jquery'] = array_merge( [ 'jquery' => 'include/javascript/jquery.js', 'ui' => 'include/javascript/jquery.ui.core.js', 'dialog' => 'include/javascript/jquery.ui.dialog.js', 'pandora' => 'include/javascript/jquery.pandora.js', ], $config['jquery'] ); } else { $config['jquery'] = array_merge( [ 'jquery' => 'include/javascript/jquery.current.js', 'pandora' => 'include/javascript/jquery.pandora.js', 'jquery-ui' => 'include/javascript/jquery-ui.min.js', ], $config['jquery'] ); } // Include the datapicker language if exists. if (file_exists('include/languages/datepicker/jquery.ui.datepicker-'.$config['language'].'.js')) { $config['jquery']['datepicker_language'] = 'include/languages/datepicker/jquery.ui.datepicker-'.$config['language'].'.js'; } // Include countdown library. $config['jquery']['countdown'] = 'include/javascript/jquery.countdown.js'; // Then add each script as necessary. $loaded = ['']; foreach ($config['jquery'] as $name => $filename) { if (in_array($name, $loaded)) { continue; } array_push($loaded, $name); $url_js = ui_get_full_url($filename, false, false, false); $output .= ''."\n\t"; } /* * End load JQuery */ /* * Load JS */ if (empty($config['js'])) { $config['js'] = []; // If it's empty, false or not init set array to empty just in case. } // Pandora specific JavaScript should go first. $config['js'] = array_merge( [ 'pandora' => 'include/javascript/pandora.js', 'pandora_ui' => 'include/javascript/pandora_ui.js', ], $config['js'] ); // Load base64 javascript library. $config['js']['base64'] = 'include/javascript/encode_decode_base64.js'; // Load qrcode library. $config['js']['qrcode'] = 'include/javascript/qrcode.js'; // Load intro.js library (for bubbles and clippy). $config['js']['intro'] = 'include/javascript/intro.js'; $config['js']['clippy'] = 'include/javascript/clippy.js'; // Load Underscore.js library. $config['js']['underscore'] = 'include/javascript/underscore-min.js'; // Load other javascript. // We can't load empty. $loaded = ['']; foreach ($config['js'] as $name => $filename) { if (in_array($name, $loaded)) { continue; } array_push($loaded, $name); $url_js = ui_get_full_url($filename, false, false, false); $output .= ''."\n\t"; } /* * End load JS */ include_once __DIR__.'/graphs/functions_flot.php'; $output .= include_javascript_dependencies_flot_graph(true); $output .= ''; $output .= $string; return $output; } /** * Callback function to add stuff to the body * * @param string $string Callback will fill this with the current buffer. * @param mixed $bitfield Callback will fill this with a bitfield (see ob_start). * * @return string String to return to the browser */ function ui_process_page_body($string, $bitfield) { global $config; if (isset($config['ignore_callback']) && $config['ignore_callback'] == true ) { return null; } // Show custom background. $output = ''; $output .= $string; $output .= ''; return $output; } /** * Prints a pagination menu to browse into a collection of data. * * @param integer $count Number of elements in the collection. * @param string $url URL of the pagination links. It must include all form * values as GET form. * @param integer $offset Current offset for the pagination. Default value would be * taken from $_REQUEST['offset']. * @param integer $pagination Current pagination size. If a user requests a larger * pagination than config["block_size"]. * @param boolean $return Whether to return or print this. * @param string $offset_name The name of parameter for the offset. * @param boolean $print_total_items Show the text with the total items. By default true. * @param mixed $other_class Other_class. * @param mixed $script Script. * @param mixed $parameter_script Parameter_script. * @param string $set_id Set id of div. * * @return string The pagination div or nothing if no pagination needs to be done */ function ui_pagination( $count, $url=false, $offset=0, $pagination=0, $return=false, $offset_name='offset', $print_total_items=true, $other_class='', $script='', $parameter_script=[ 'count' => '', 'offset' => 'offset_param', ], $set_id='' ) { global $config; if (empty($pagination)) { $pagination = (int) $config['block_size']; } if (is_string($offset)) { $offset_name = $offset; $offset = (int) get_parameter($offset_name); } if (empty($offset)) { $offset = (int) get_parameter($offset_name); } if (empty($url)) { $url = ui_get_url_refresh([$offset_name => false]); } if (!empty($set_id)) { $set_id = " id = '".$set_id."'"; } // Pagination links for users include delete, create and other params, // now not use these params, and not retry the previous action when go to // pagination link. $remove = [ 'user_del', 'disable_user', 'delete_user', ]; // Check if url has blankspace and replace it. preg_replace('/\ /', '%20', $url); $url = explode('&', $url); $finalUrl = []; foreach ($url as $key => $value) { if (strpos($value, $remove[0]) === false && strpos($value, $remove[1]) === false && strpos($value, $remove[2]) === false ) { array_push($finalUrl, $value); } } $url = implode('&', $finalUrl); /* URL passed render links with some parameter &offset - Offset records passed to next page &counter - Number of items to be blocked Pagination needs $url to build the base URL to render links, its a base url, like " http://pandora/index.php?sec=godmode&sec2=godmode/admin_access_logs " */ $block_limit = PAGINATION_BLOCKS_LIMIT; // Visualize only $block_limit blocks. if ($count <= $pagination) { if ($print_total_items) { $output = "'; if ($return === false) { echo $output; } return $output; } return false; } $number_of_pages = ceil($count / $pagination); $actual_page = floor($offset / $pagination); $ini_page = (floor($actual_page / $block_limit) * $block_limit); $end_page = ($ini_page + $block_limit - 1); if ($end_page >= $number_of_pages) { $end_page = ($number_of_pages - 1); } $output = "