'.$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, $forced_title=false ) { global $config; $truncate_at_end = false; if (is_string($numChars)) { switch ($numChars) { case 'agent_small': $numChars = $config['agent_size_text_small']; $truncate_at_end = (bool) $config['truncate_agent_at_end']; break; case 'agent_medium': $numChars = $config['agent_size_text_medium']; $truncate_at_end = (bool) $config['truncate_agent_at_end']; break; case 'module_small': $numChars = $config['module_size_text_small']; $truncate_at_end = (bool) $config['truncate_module_at_end']; break; case 'module_medium': $numChars = $config['module_size_text_medium']; $truncate_at_end = (bool) $config['truncate_module_at_end']; 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); if ($truncate_at_end === true) { // Recover the html entities to avoid XSS attacks. $truncateText = ($text_has_entities) ? io_safe_input(substr($text_html_decoded, 0, $numChars)) : substr($text_html_decoded, 0, $numChars); if (strlen($text_html_decoded) > $numChars) { $truncateText .= '...'; } } else { // 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 ($forced_title === true) { $truncateText = ''; $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') { global $config; static $first_execution = true; $text_title = ''; $text_message = ''; $icon_image = ''; $no_close_bool = false; $force_style = ''; $force_class = ''; $classes = []; $autoclose = ($class === 'suc'); if (is_array($message) === true) { if (empty($message['title']) === false) { $text_title = $message['title']; } if (empty($message['message']) === false) { $text_message = $message['message']; } if (empty($message['icon']) === false) { $icon_image = $message['icon']; } if (empty($message['no_close']) === false) { // Workaround. $no_close_bool = false; // $no_close_bool = (bool) $message['no_close']; } if (empty($message['force_style']) === false) { $force_style = $message['force_style']; } if (empty($message['force_class']) === false) { $force_class = $message['force_class']; } if (isset($message['autoclose']) === true) { if ($message['autoclose'] === true) { $autoclose = true; } else { $autoclose = false; } } } else { $text_message = $message; } if (empty($text_title) === true) { switch ($class) { default: case 'info': $classes[] = 'info_box_information'; $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) === true) { 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; } if ($no_close_bool === false) { // Use the no_meta parameter because this image is only in // the base console. $iconCloseButton = html_print_anchor( [ 'href' => 'javascript: close_info_box(\''.$id.'\')', 'content' => html_print_image( 'images/close@svg.svg', true, false, false, false, ), ], true ); $closeButton = html_print_div( [ 'class' => 'icon right pdd_r_3px', 'content' => $iconCloseButton, ], true ); } else { $closeButton = ''; } $messageTable = new stdClass(); $messageTable->cellpadding = 0; $messageTable->cellspacing = 0; $messageTable->id = 'table_'.$id; $messageTable->class = 'info_box '.$class.' textodialogo'; $messageTable->styleTable = $force_style; $messageTable->rowclass = []; $messageTable->rowclass[0] = 'title font_16pt text_left'; $messageTable->rowclass[1] = 'black font_10pt invert_filter'; $messageTable->colspan[1][0] = 2; $messageTable->data = []; $messageTable->data[0][0] = ''.$text_title.''; $messageTable->data[0][1] = $closeButton; $messageTable->data[1][0] = ''.$text_message.''; // JavaScript help vars. $messageCreated = html_print_table($messageTable, true); $autocloseTime = ((int) $config['notification_autoclose_time'] * 1000); if (empty($message['div_class']) === false) { $classes[] = $message['div_class']; } else { $classes[] = 'info_box_container'; } $classes[] = (($autoclose === true) && ($autocloseTime > 0)) ? ' info_box_autoclose' : ''; // This session var is defined in index. if (isset($_SESSION['info_box_count']) === false) { $_SESSION['info_box_count'] = 1; } else { $_SESSION['info_box_count']++; } $position = (20 + ((int) $_SESSION['info_box_count'] * 100)); $output = html_print_div( [ 'id' => $id, 'style' => 'top: '.$position.'px;', 'class' => implode(' ', $classes), 'content' => $messageCreated, ], true ); if ($return === true) { return $output; } else { echo $output; } } /** * 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 (empty($good) === true || $good === false) { $good = __('Request successfully processed'); } if (empty($bad) === true || $bad === false) { $bad = __('Error processing request'); } if (empty($result) === true) { 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']) === true) { $attributes = $option['html_attr']; } else { $attributes = ''; } if (isset($option['tag']) === true) { $tag = $option['tag']; } else { $tag = 'span'; } if (empty($option['class']) === false) { $class = 'class="nowrap '.$option['class'].'"'; } else { $class = 'class="nowrap"'; } if (empty($option['style']) === false) { $style = 'style="'.$option['style'].'"'; } else { $style = 'style=""'; } $style .= ' '.$class; if (empty($option['prominent']) === false) { $prominent = $option['prominent']; } else { $prominent = $config['prominent_time']; } if (is_numeric($unixtime) === false) { $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']) === true) { $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 === true) { return $output; } else { echo $output; } } /** * Prints a username with real name, link to the user_edit page etc. * * @param string $username The username to render. * @param boolean $fullname If true, returns the user fullname. * @param boolean $return Whether to return or print. * * @return void|string HTML code if return parameter is true. */ function ui_print_username($username, $fullname=false, $return=false) { return html_print_anchor( [ 'href' => sprintf('index.php?sec=gusuarios&sec2=godmode/users/configure_user&edit_user=1&pure=0&id_user=%s', $username), 'content' => ($fullname === true) ? get_user_fullname($username) : $username, ], $return ); } /** * 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. * @param string $class Overrides the default class. * * @return string HTML code if return parameter is true. */ function ui_print_group_icon($id_group, $return=false, $path='', $style='', $link=true, $force_show_image=false, $show_as_image=false, $class='', $tactical_view=false) { global $config; $output = ''; $icon = 'world@svg.svg'; if ($id_group > 0) { $icon = db_get_value('icon', 'tgrupo', 'id_grupo', (int) $id_group); if (empty($icon) === true) { $icon = 'unknown@groups.svg'; } } $extension = pathinfo($icon, PATHINFO_EXTENSION); if (empty($extension) === true) { $icon .= '.png'; } // Don't show link in metaconsole. if (is_metaconsole() === true) { $link = false; } if ($link === true) { if ($tactical_view === true) { $output = ''; } else { $output = ''; } } if ((bool) $config['show_group_name'] === true) { $output .= ''.groups_get_name($id_group, true).' '; } else { if (empty($icon) === true) { $output .= ''; $output .= ''; $output .= html_print_image( 'images/unknown@groups.svg', true, [ 'style' => $style, 'class' => 'main_menu_icon invert_filter '.$class, 'alt' => groups_get_name($id_group, true), 'title' => groups_get_name($id_group, true), ], false, false, false, true ); $output .= '
'; } else { if (empty($class) === true) { $class = 'bot'; if ($icon === 'transmit') { $class .= ' invert_filter'; } } $icon = (str_contains($icon, '.svg') === true || str_contains($icon, '.png') === true) ? $icon : $icon.'.svg'; $folder = ''; if (str_contains($icon, '.png')) { $folder = 'groups_small/'; } $output .= html_print_image( 'images/'.$folder.$icon, true, [ 'style' => $style, 'class' => 'main_menu_icon invert_filter '.$class, 'alt' => groups_get_name($id_group, true), 'title' => groups_get_name($id_group, true), ], false, false, false, true ); } } if ($link === true) { $output .= ''; } if ($return === false) { echo $output; } else { 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', $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=[], $big_icons=false ) { $subfolder = '.'; if ($networkmap) { $subfolder = 'networkmap'; } if ($big_icons) { $subfolder .= '/so_big_icons'; } if (isset($options['class']) === false) { $options['class'] = 'main_menu_icon invert_filter'; } $no_in_meta = (is_metaconsole() === false); $icon = (string) db_get_value('icon_name', 'tconfig_os', 'id_os', (int) $id_os); $extension = pathinfo($icon, PATHINFO_EXTENSION); if (empty($extension) === true) { $icon .= '.png'; } if (empty($extension) === true || $extension === 'png' || $extension === 'jpg' || $extension === 'gif' && $subfolder === '.' ) { $subfolder = 'os_icons'; } $os_name = get_os_name($id_os); if (empty($icon) === true) { 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 ((int) $id_os === SATELLITE_OS_ID) { // Satellite. $options['title'] = __('Satellite'); $output = html_print_image( 'images/satellite@os.svg', true, [ 'class' => 'main_menu_icon invert_filter', 'style' => 'padding-right: 10px;', ], false, false, false, true ); } else if ($remote_contact === $contact && $remote === 0 && empty($version) === true) { // Network. $options['title'] = __('Network'); $output = html_print_image( 'images/network-server@os.svg', true, [ 'class' => 'main_menu_icon invert_filter', 'style' => 'padding-right: 10px;', ], false, false, false, true ); } else { // Software. $options['title'] = __('Software'); $output = html_print_image( 'images/data-server@svg.svg', true, [ 'class' => 'main_menu_icon invert_filter', 'style' => 'padding-right: 10px;', ], 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' => 6, 'action' => 7, 'last_fired' => 8, 'status' => 9, 'validate' => 10, 'actions' => 11, ]; } else { $index = [ 'policy' => 0, 'standby' => 1, 'force_execution' => 2, 'agent_name' => 3, 'module_name' => 4, 'description' => 5, 'template' => 6, 'action' => 7, 'last_fired' => 8, 'status' => 9, 'validate' => 10, ]; } } else { if ($agent) { $index = [ 'standby' => 0, 'force_execution' => 1, 'agent_name' => 2, 'module_name' => 3, 'description' => 4, 'template' => 5, 'action' => 6, 'last_fired' => 7, 'status' => 8, 'validate' => 9, ]; } else { $index = [ 'standby' => 0, 'force_execution' => 1, 'agent_name' => 2, 'module_name' => 3, 'description' => 4, 'template' => 5, 'action' => 6, 'last_fired' => 7, 'status' => 8, 'validate' => 9, ]; } } 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) || (is_array($policyInfo) === false && $module_linked === '1') ) { $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/policy@svg.svg'; } if (is_metaconsole() === false) { $data[$index['policy']] = ''.html_print_image($img, true, ['title' => $policyInfo['name'], 'class' => 'invert_filter main_menu_icon']).''; } else { $data[$index['policy']] = ''.html_print_image($img, true, ['title' => $policyInfo['name'], 'class' => 'invert_filter main_menu_icon']).''; } } 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 ((bool) check_acl($config['id_user'], $id_group, 'AW') === true || (bool) check_acl($config['id_user'], $id_group, 'LM') === true) { if ((int) $alert['force_execution'] === 0) { $forceTitle = __('Force check'); $additionUrl = '&force_execution=1'; } else { $forceTitle = __('Refresh'); $additionUrl = ''; } $forceExecButtons['force_check'] = html_print_anchor( [ 'href' => $url.'&id_alert='.$alert['id'].'&refr=60'.$additionUrl, 'content' => html_print_image( 'images/force@svg.svg', true, [ 'title' => $forceTitle, 'class' => 'main_menu_icon invert_filter', ] ), ], true ); } $forceExecButtons['template'] = html_print_anchor( [ 'href' => 'ajax.php?page=godmode/alerts/alert_templates&get_template_tooltip=1&id_template='.$template['id'], 'style' => 'margin-left: 5px;', 'class' => 'template_details', 'content' => html_print_image( 'images/details.svg', true, ['class' => 'main_menu_icon invert_filter'] ), ], true ); } else { $forceExecButtons['template'] = html_print_anchor( [ 'href' => ui_get_full_url('/', false, false, false).'/ajax.php?page=enterprise/meta/include/ajax/tree_view.ajax&action=get_template_tooltip&id_template='.$template['id'].'&server_name='.$alert['server_data']['server_name'], 'style' => 'margin-left: 5px;', 'class' => 'template_details', 'content' => html_print_image( 'images/details.svg', true, ['class' => 'main_menu_icon invert_filter'] ), ], true ); } if (isset($forceExecButtons['force_check'])) { $data[$index['force_execution']] = html_print_div( [ 'class' => 'table_action_buttons flex', 'content' => $forceExecButtons['force_check'], ], true ); } if (isset($forceExecButtons['template'])) { $data[$index['template']] = $forceExecButtons['template']; } $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']] .= html_print_anchor( [ 'href' => $url, 'content' => ''.$agente['alias'].'', ], true ); } else { $data[$index['agent_name']] .= ''.$agente['alias'].''; } } else { $data[$index['agent_name']] .= html_print_anchor( [ 'href' => 'index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$id_agent, 'content' => ''.$agente['alias'].'', ], true ); } $alert_module_name = isset($alert['agent_module_name']) ? $alert['agent_module_name'] : modules_get_agentmodule_name($alert['id_agent_module']); $data[$index['module_name']] = ui_print_truncate_text($alert_module_name, 'module_small', false, true, true, '[…]', ''); } $data[$index['agent_name']] .= $disabledHtmlEnd; $data[$index['description']] = ''; $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; if (is_metaconsole()) { if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) { $connection = metaconsole_get_connection($agente['server_name']); if (metaconsole_load_external_db($connection) !== NOERR) { echo json_encode(false); // Restore db connection. metaconsole_restore_db(); return; } } } $actions = alerts_get_alert_agent_module_actions($alert['id'], false, -1, true); if (is_metaconsole()) { // Restore db connection. metaconsole_restore_db(); } if (empty($actions) === false || $actionDefault != '') { $actionText = '
'; if ($actionDefault !== '' && $actionDefault !== false) { $actionDefault_name = db_get_sql( sprintf( 'SELECT name FROM talert_actions WHERE id = %d', $actionDefault ) ); foreach ($actions as $action) { if ($actionDefault_name === $action['name']) { $hide_actionDefault = true; } else { $hide_actionDefault = false; } } if ($hide_actionDefault !== true) { $actionText .= $actionDefault_name.' ('.__('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); $data[$index['status']] .= '