';
$tv .= '
'.$title.'
';
} else {
$tv .= '
';
}
foreach ($tags as $tag) {
$tv .= '
';
$tv .= '';
$tv .= $tag['title'];
$tv .= '';
$tv .= '';
$tv .= $tag['value'];
$tv .= '';
$tv .= '
';
}
$tv .= '
';
echo $tv;
}
/**
* Gets the link to open a snapshot into a new page.
*
* @param array $params Params to build the link (see $default_params).
* @param boolean $only_params Flag to choose de return value:
* true: Get the four params required in the function of pandora.js winopen_var (js use)
* false: Get an inline winopen_var function call (php user).
*
* @return string Link.
*/
function ui_get_snapshot_link($params, $only_params=false)
{
global $config;
$default_params = [
// Id_agente_modulo.
'id_module' => 0,
'module_name' => '',
'interval' => 300,
'timestamp' => 0,
'id_node' => 0,
];
// Merge default params with passed params.
$params = array_merge($default_params, $params);
// First parameter of js winopeng_var.
$page = ui_get_full_url('operation/agentes/snapshot_view.php', false, false, false);
$url = $page.'?id='.$params['id_module'].'&label='.rawurlencode(urlencode(io_safe_output($params['module_name']))).'&id_node='.$params['id_node'];
if ($params['timestamp'] != 0) {
$url .= '×tamp='.$params['timestamp'];
}
if ($params['interval'] != 0) {
$url .= '&refr='.$params['interval'];
}
// Second parameter of js winopeng_var.
$win_handle = dechex(crc32('snapshot_'.$params['id_module']));
$link_parts = [
$url,
$win_handle,
700,
480,
];
// Return only the params to js execution.
if ($only_params) {
return $link_parts;
}
// Return the function call to inline js execution.
return "winopeng_var('".implode("', '", $link_parts)."')";
}
/**
* Get the snapshot image with the link to open a snapshot into a new page
*
* @param string $link Built link.
* @param boolean $is_image Picture image or list image.
*
* @return string HTML anchor link with image.
*/
function ui_get_snapshot_image($link, $is_image)
{
$image_name = ($is_image) ? 'photo.png' : 'default_list.png';
$link = '
'.html_print_image(
'images/'.$image_name,
true,
[
'border' => '0',
'alt' => '',
'title' => __('Snapshot view'),
'style' => 'max-height: 20px; vertical-align: middle;',
'class' => 'invert_filter',
]
).'';
return $link;
}
/**
* Show warning timezone missmatch.
*
* @param string $tag Tag.
* @param boolean $return Return.
*
* @return string HTML.
*/
function ui_get_using_system_timezone_warning($tag='h3', $return=true)
{
global $config;
$user_offset = ((-get_fixed_offset() / 60) / 60);
if ($config['timezone'] != date_default_timezone_get()) {
$message = sprintf(
__('These controls are using the timezone of the system (%s) instead of yours (%s). The difference with your time zone in hours is %s.'),
$config['timezone'],
date_default_timezone_get(),
($user_offset > 0) ? '+'.$user_offset : $user_offset
);
return ui_print_info_message($message, '', $return, $tag);
} else {
return '';
}
}
/**
* Get the custom docs logo
*
* @return string with the path to logo. False if it should not be displayed.
*/
function ui_get_docs_logo()
{
global $config;
// Default logo to open version (enterprise_installed function only works in login status).
if (!file_exists(ENTERPRISE_DIR.'/load_enterprise.php') || !isset($config['custom_docs_logo'])) {
if (is_metaconsole() === true) {
return '../../images/icono_docs.png';
}
return 'images/icono_docs.png';
}
if ($config['custom_docs_logo'] === '') {
return false;
}
return 'enterprise/images/custom_general_logos/'.$config['custom_docs_logo'];
}
/**
* Get the custom support logo
*
* @return string with the path to logo. False if it should not be displayed.
*/
function ui_get_support_logo()
{
global $config;
// Default logo to open version (enterprise_installed function only works in login status).
if (!file_exists(ENTERPRISE_DIR.'/load_enterprise.php') || !isset($config['custom_support_logo'])) {
if (is_metaconsole() === true) {
return '../../images/icono_support.png';
}
return 'images/icono_support.png';
}
if ($config['custom_support_logo'] === '') {
return false;
}
return 'enterprise/images/custom_general_logos/'.$config['custom_support_logo'];
}
/**
* Get the custom header logo
*
* @param boolean $white_bg Using white bg or not.
*
* @return string with the path to logo. If it is not set, return the default value.
*/
function ui_get_custom_header_logo($white_bg=false)
{
global $config;
if (empty($config['enterprise_installed'])) {
return 'images/pandora_tinylogo_open.png';
}
$stored_logo = (is_metaconsole()) ? (($white_bg) ? $config['meta_custom_logo_white_bg'] : $config['meta_custom_logo']) : (($white_bg) ? $config['custom_logo_white_bg'] : $config['custom_logo']);
if (empty($stored_logo)) {
return 'images/pandora_tinylogo.png';
}
return 'enterprise/images/custom_logo/'.$stored_logo;
}
/**
* Get the central networkmap logo
*
* @return string with the path to logo. If it is not set, return the default.
*/
function ui_get_logo_to_center_networkmap()
{
global $config;
if ((!enterprise_installed()) || empty($config['custom_network_center_logo'])) {
return 'images/networkmap/bola_pandora_network_maps.png';
}
return 'enterprise/images/custom_general_logos/'.$config['custom_support_logo'];
}
/**
* Get the mobile console login logo
*
* @return string with the path to logo. If it is not set, return the default.
*/
function ui_get_mobile_login_icon()
{
global $config;
if ((!enterprise_installed()) || empty($config['custom_mobile_console_logo'])) {
return is_metaconsole() ? 'mobile/images/metaconsole_mobile.png' : 'mobile/images/pandora_mobile_console.png';
}
return 'enterprise/images/custom_general_logos/'.$config['custom_mobile_console_logo'];
}
/**
* Get the favicon
*
* @return string with the path to logo. If it is not set, return the default.
*/
function ui_get_favicon()
{
global $config;
if (empty($config['custom_favicon'])) {
return (!is_metaconsole()) ? 'images/pandora.ico' : 'enterprise/meta/images/favicon_meta.ico';
}
return 'images/custom_favicon/'.$config['custom_favicon'];
}
/**
* Show sorting arrows for tables
*
* @param string $url_up Url_up.
* @param string $url_down Url_down.
* @param string $selectUp SelectUp.
* @param string $selectDown SelectDown.
*
* @return string HTML anchor link with the arrow icon.
*/
function ui_get_sorting_arrows($url_up, $url_down, $selectUp, $selectDown)
{
$arrow_up = 'images/sort_up_black.png';
$arrow_down = 'images/sort_down_black.png';
// Green arrows for the selected.
if ($selectUp === true) {
$arrow_up = 'images/sort_up_green.png';
}
if ($selectDown === true) {
$arrow_down = 'images/sort_down_green.png';
}
if (is_metaconsole()) {
$arrow_up = 'images/sort_up.png';
$arrow_down = 'images/sort_down.png';
}
return '
'.html_print_image($arrow_up, true, ['alt' => 'up']).'
'.html_print_image($arrow_down, true, ['alt' => 'down']).'
';
}
/**
* Show breadcrums in the page titles
*
* @param string $tab_name Tab name.
*
* @return string HTML anchor with the name of the section.
*/
function ui_print_breadcrums($tab_name)
{
if (is_array($tab_name)) {
return join(' / ', $tab_name);
} else if ($tab_name != '') {
$section = str_replace('_', ' ', $tab_name);
$section = ucwords($section);
$section = ' / '.___($section);
}
return $section;
}
/**
* Show last comment
*
* @param string $comments String with comments.
*
* @return string HTML string with the last comment of the events.
*/
function ui_print_comments($comments)
{
global $config;
$comments = explode('
', $comments);
$comments = str_replace(["\n", '
'], '
', $comments);
if (is_array($comments)) {
foreach ($comments as $comm) {
if (empty($comm)) {
continue;
}
$comments_array[] = io_safe_output(json_decode($comm, true));
}
}
$last_comment = [];
foreach ($comments_array as $comm) {
// Show the comments more recent first.
if (is_array($comm)) {
$order_utimestamp = array_reduce(
$comm,
function ($carry, $item) {
$carry[$item['utimestamp']] = $item;
return $carry;
}
);
$key_max_utimestamp = max(array_keys($order_utimestamp));
$last_comment = $order_utimestamp[$key_max_utimestamp];
}
}
if (empty($last_comment) === true) {
return '';
}
// Only show the last comment. If commment its too long,the comment will short with ...
// If $config['prominent_time'] is timestamp the date show Month, day, hour and minutes.
// Else show comments hours ago
if ($last_comment['action'] != 'Added comment') {
$last_comment['comment'] = $last_comment['action'];
}
$short_comment = substr($last_comment['comment'], 0, 20);
if ($config['prominent_time'] == 'timestamp') {
$comentario = '
'.date($config['date_format'], $last_comment['utimestamp']).' ('.$last_comment['id_user'].'): '.$last_comment['comment'].'';
if (strlen($comentario) > '200px') {
$comentario = ''.date($config['date_format'], $last_comment['utimestamp']).' ('.$last_comment['id_user'].'): '.$short_comment.'...';
}
} else {
$rest_time = (time() - $last_comment['utimestamp']);
$time_last = (($rest_time / 60) / 60);
$comentario = ''.number_format($time_last, 0, $config['decimal_separator'], ($config['thousand_separator'] ?? ',')).' Hours ('.$last_comment['id_user'].'): '.$last_comment['comment'].'';
if (strlen($comentario) > '200px') {
$comentario = ''.number_format($time_last, 0, $config['decimal_separator'], ($config['thousand_separator'] ?? ',')).' Hours ('.$last_comment['id_user'].'): '.$short_comment.'...';
}
}
return io_safe_output($comentario);
}
/**
* Get complete external pandora url.
*
* @param string $url Url to be parsed.
*
* @return string Full url.
*/
function ui_get_full_external_url(string $url)
{
$url_parsed = parse_url($url);
if ($url_parsed) {
if (!isset($url_parsed['scheme'])) {
$url = 'http://'.$url;
}
}
return $url;
}
function ui_print_message_dialog($title, $text, $id='', $img='', $text_button='', $hidden=true)
{
if ($hidden == true) {
$style = 'display:none';
}
echo '';
echo '
';
echo '
';
echo html_print_image($img, true, ['alt' => $title, 'border' => 0]);
echo '
';
echo '
';
echo '
';
echo '
'.$title.'
';
echo '
'.$text.'
';
echo '
';
echo '
';
echo '
';
echo '
';
echo '
';
}
/**
* Build a Query-Result editor structure
*
* @param string $name Name of the structure
*
* @return null
*/
function ui_query_result_editor($name='default')
{
$editorSubContainer = html_print_div(
[
'id' => $name.'_editor_title',
'content' => ''.__('Query').'
',
],
true
);
$editorSubContainer .= html_print_div(
[
'id' => $name.'_editor',
'class' => 'query_result_editor',
],
true
);
$editorSubContainer .= html_print_div(
[
'class' => 'action-buttons edit-button',
'content' => html_print_submit_button(
__('Execute query'),
'execute_query',
false,
['icon' => 'next'],
true
),
],
true
);
$editorContainer = html_print_div(
[
'id' => $name.'_editor_container',
'class' => 'query_result_editor_container',
'content' => $editorSubContainer,
],
true
);
$viewSubContainer = html_print_div(
[
'id' => $name.'_view_title',
'content' => '
'.__('Results').'
',
],
true
);
$viewSubContainer .= html_print_div(
[
'id' => $name.'_view',
'class' => 'query_result_view',
],
true
);
$viewSubContainer .= html_print_div(
[
'class' => 'action-buttons',
'content' => '',
],
true
);
$viewContainer = html_print_div(
[
'id' => $name.'_view_container',
'class' => 'query_result_view_container',
'content' => $viewSubContainer,
],
true
);
html_print_div(
[
'id' => 'query_result_container',
'class' => 'databox',
'content' => $editorContainer.$viewContainer,
]
);
// This is needed for Javascript
html_print_div(
[
'id' => 'pandora_full_url',
'hidden' => true,
'content' => ui_get_full_url(false, false, false, false),
]
);
}
/**
* Generate a button for reveal the content of the password field.
*
* @param string $name Name of the field.
* @param boolean $return If true, return the string with the formed element.
*
* @return string
*/
function ui_print_reveal_password(string $name, bool $return=false)
{
if (is_metaconsole()) {
$imagePath = '../../images/';
} else {
$imagePath = 'images/';
}
$output = '
';
if ($return === true) {
return $output;
}
echo $output;
}
/**
* Generate a spinner box for waiting times
* TIP: It's made for Massive Operations, but it migth used in entire project.
*
* @param string $text Text for show in spinner. English term Loading for default.
* @param boolean $return If true, return the string with the formed element.
*
* @return string
*/
function ui_print_spinner(string $text='Loading', bool $return=false)
{
$output = '';
$output .= '
';
$output .= html_print_div(
[
'id' => 'loading_spinner',
'class' => 'white_box invisible',
'content' => ''.$text.'...'.html_print_image(
'images/spinner.gif',
true,
[
'class' => 'main_menu_icon',
'border' => '0',
'width' => '25px',
'heigth' => '25px',
]
),
],
true
);
$output .= '';
$output .= '
';
if ($return === true) {
return $output;
} else {
echo $output;
}
}
/**
* Return a formed server type icon.
*
* @param integer $id Id of server type.
*
* @return string.
*/
function ui_print_servertype_icon(int $id)
{
switch ($id) {
case MODULE_DATA:
$title = __('Data server');
$image = 'images/data-server@svg.svg';
break;
case MODULE_NETWORK:
$title = __('Network server');
$image = 'images/network-server@os.svg';
break;
case MODULE_PLUGIN:
$title = __('Plugin server');
$image = 'images/plugins@svg.svg';
break;
case MODULE_PREDICTION:
$title = __('Prediction server');
$image = 'images/prediction@svg.svg';
break;
case MODULE_WMI:
$title = __('WMI server');
$image = 'images/WMI@svg.svg';
break;
case MODULE_WEB:
$title = __('WEB server');
$image = 'images/server-web@svg.svg';
break;
case MODULE_WUX:
$title = __('WUX server');
$image = 'images/wux@svg.svg';
break;
case MODULE_WIZARD:
$title = __('Wizard Module');
$image = 'images/wizard@svg.svg';
break;
default:
$title = '';
$image = '';
break;
}
if (empty($title) === true && empty($image) === true) {
$return = '--';
} else {
$return = html_print_image(
$image,
true,
[
'title' => sprintf('%s %s', get_product_name(), $title),
'class' => 'invert_filter main_menu_icon',
]
);
}
return $return;
}
function ui_get_inventory_module_add_form(
$form_action,
$form_buttons='',
$inventory_module_id=0,
$os_id=false,
$target=false,
$interval=3600,
$username='',
$password='',
$custom_fields_enabled=false,
$custom_fields=[]
) {
$table = new stdClass();
$table->id = 'inventory-module-form';
$table->width = '100%';
$table->class = 'databox filters filter-table-adv';
$table->size['module'] = '50%';
$table->size['interval'] = '50%';
$table->size['target'] = '50%';
$table->size['chkbx-custom-fields'] = '50%';
$table->size['username'] = '50%';
$table->size['password'] = '50%';
$table->rowstyle = [];
$table->rowstyle['hidden-custom-field-row'] = 'display: none;';
$table->rowstyle['custom-fields-button'] = 'display: none;';
// $table->colspan = [];
// $table->colspan['custom-fields-row'] = [];
// $table->colspan['custom-fields-row']['custom-fields-column'] = 2;
$table->data = [];
$row = [];
if (empty($inventory_module_id)) {
if (empty($os_id)) {
$sql = 'SELECT mi.id_module_inventory AS id, mi.name AS name, co.name AS os
FROM tmodule_inventory mi, tconfig_os co
WHERE co.id_os = mi.id_os
ORDER BY co.name, mi.name';
$inventory_modules_raw = db_get_all_rows_sql($sql);
$inventory_modules = [];
foreach ($inventory_modules_raw as $im) {
$inventory_modules[$im['id']] = [
'name' => $im['name'],
'optgroup' => $im['os'],
];
}
} else {
$sql = sprintf(
'SELECT id_module_inventory AS id, name
FROM tmodule_inventory
WHERE id_os = %d
ORDER BY name',
$os_id
);
$inventory_modules_raw = db_get_all_rows_sql($sql);
$inventory_modules = [];
foreach ($inventory_modules_raw as $im) {
$inventory_modules[$im['id']] = $im['name'];
}
}
$row['module'] = html_print_label_input_block(
__('Module'),
html_print_select(
$inventory_modules,
'id_module_inventory',
0,
'',
__('Select inventory module'),
0,
true,
false,
false,
'w100p',
false,
'width: 100%'
)
);
} else {
$row['module'] = html_print_label_input_block(
__('Module'),
db_get_sql('SELECT name FROM tmodule_inventory WHERE id_module_inventory = '.$inventory_module_id)
);
}
$row['interval'] = html_print_label_input_block(
__('Interval'),
html_print_extended_select_for_time(
'interval',
$interval,
'',
'',
'',
false,
true,
false,
true,
'w100p'
)
);
$table->data['first-row'] = $row;
$row = [];
if ($target !== false) {
$row['target'] = html_print_label_input_block(
__('Target'),
html_print_input_text(
'target',
$target,
'',
25,
40,
true,
false,
false,
'',
'w100p'
)
);
}
$row['chkbx-custom-fields'] = html_print_label_input_block(
__('Use custom fields'),
html_print_checkbox(
'custom_fields_enabled',
1,
$custom_fields_enabled,
true
)
);
$table->data['second-row'] = $row;
$row = [];
$row['username'] = html_print_label_input_block(
__('Username'),
html_print_input_text(
'username',
$username,
'',
25,
40,
true,
false,
false,
'',
'w100p'
)
);
$row['password'] = html_print_label_input_block(
__('Password'),
html_print_input_password(
'password',
$password,
'',
25,
40,
true,
false,
false,
'w100p'
)
);
$table->data['userpass-row'] = $row;
$row = [];
$row['hidden-title'] = '';
$row['hidden-input'] = html_print_input_hidden('hidden-custom-field-name', '', true);
$row['hidden-input'] .= html_print_input_hidden('hidden-custom-field-is-secure', 0, true);
$row['hidden-input'] .= html_print_input_text(
'hidden-custom-field-input',
'',
'',
25,
40,
true,
false,
false,
'',
'w93p'
);
$row['hidden-input'] .= html_print_image(
'images/delete.svg',
true,
[
'border' => '0',
'title' => __('Remove'),
'style' => 'cursor: pointer;',
'class' => 'remove-custom-field invert_filter',
]
);
$table->data['hidden-custom-field-row'] = $row;
if ($custom_fields_enabled) {
foreach ($custom_fields as $i => $field) {
$row = [];
$row['title'] = '
'.$field['name'].'';
$row['input'] = html_print_input_hidden(
'custom_fields['.$i.'][name]',
$field['name'],
true
);
$row['input'] .= html_print_input_hidden(
'custom_fields['.$i.'][secure]',
$field['secure'],
true
);
if ($field['secure']) {
$row['input'] .= html_print_input_password(
'custom_fields['.$i.'][value]',
$field['value'],
'',
25,
40,
true
);
} else {
$row['input'] .= html_print_input_text(
'custom_fields['.$i.'][value]',
$field['value'],
'',
25,
40,
true
);
}
$row['input'] .= '
';
$row['input'] .= html_print_image(
'images/delete.svg',
true,
[
'border' => '0',
'title' => __('Remove'),
'style' => 'cursor: pointer;',
'class' => 'remove-custom-field invert_filter',
]
);
$table->data['custom-field-row-'.$i] = $row;
}
}
$row = [];
$row['custom-fields-column'] = html_print_label_input_block(
__('Field name'),
'
'.html_print_input_text(
'field-name',
'',
'',
25,
40,
true,
false,
false,
'',
'w60p mrgn_right_10px'
).html_print_checkbox(
'field-is-password',
1,
false,
true
).' '.__("It's a password").'
'
);
$table->data['custom-fields-row'] = $row;
$row = [];
$row['custom-fields-button-title'] = '';
$row['custom-fields-button'] = html_print_button(
__('Add field'),
'add-field',
false,
'',
[
'class' => 'mini float-right',
'icon' => 'plus',
],
true
);
$table->data['custom-fields-button'] = $row;
ob_start();
echo '
';
?>
'.__('Refresh').'';
$select = html_print_select(
get_refresh_time_array(),
'refresh',
(int) get_parameter('refresh'),
'',
'',
0,
true,
false,
false,
'',
false,
'margin-top: 3px;'
);
$vcRefrDivContent = [];
$vcRefrDivContent[] = html_print_div(['class' => 'vc-countdown inline_line'], true);
$vcRefrDivContent[] = html_print_div(
[
'id' => 'vc-refr-form',
'content' => $title.$select,
],
true
);
// Floating menu - Start.
$menuTabContent[] = '
';
// Quit fullscreen.
$menuTabContent[] = '- ';
$menuTabContent[] = html_print_anchor(
[
'href' => $url,
'content' => html_print_image(
'images/exit_fullscreen@svg.svg',
true,
[
'title' => __($normalScreenTitle),
'class' => 'invert_filter main_menu_icon',
]
),
],
true
);
$menuTabContent[] = '
';
// Countdown.
$menuTabContent[] = '- ';
$menuTabContent[] = html_print_div(
[
'class' => 'vc-refr',
'content' => implode('', $vcRefrDivContent),
],
true
);
$menuTabContent[] = '
';
// Console name.
$menuTabContent[] = '- ';
$menuTabContent[] = html_print_div(
[
'class' => 'vc-title',
'content' => __($mainTitle),
],
true
);
$menuTabContent[] = '
';
$menuTabContent[] = '
';
return html_print_div(
[
'id' => 'menu_tab',
'class' => 'full_screen_control_bar',
'content' => implode('', $menuTabContent),
],
$return
);
}
function ui_print_status_div($status)
{
switch ((int) $status) {
case 0:
$return = '
';
break;
case 1:
$return = '
';
break;
default:
$return = '
';
break;
}
return $return;
}
function ui_print_fav_menu($id_element, $url, $label, $section)
{
global $config;
$label = io_safe_output($label);
if (strlen($label) > 18) {
$label = io_safe_input(substr($label, 0, 18).'...');
}
$fav = db_get_row_filter(
'tfavmenu_user',
[
'url' => $url,
'id_user' => $config['id_user'],
],
['*']
);
$config_fav_menu = [
'id_element' => $id_element,
'url' => $url,
'label' => $label,
'section' => $section,
];
$output = '';
$output .= '';
return $output;
}