'uniqueid', * 'href' => 'value', * 'title' => 'title', * 'callback' => true|false, * 'class' => 'fa fa-icon' * ), * ... * ); * * If the callback is true, the Cacti attribute will be added to the href * to present only the contents and not to include both the headers. If * the link must go off page, simply make sure $callback is false. There * is a requirement to use fontawesome icon sets for this class, but it * can include other classes. In addition, the href can be a hash '#' if * your page has a ready function that has it's own javascript. * @param $add_label - used with legacy behavior to add specific text to the link. * This parameter is only used in the legacy behavior. */ function html_start_box($title, $width, $div, $cell_padding, $align, $add_text, $add_label = false) { global $config; static $table_suffix = 1; static $help_count = 0; static $mode_count = 0; static $beta_count = 0; if ($add_label === false) { $add_label = __('Add'); } if (!is_cacti_release() && $title != '' && $beta_count == 0) { $title .= ' [ ' . CACTI_VERSION_BRIEF_FULL . ' ]'; $beta_count++; } if ($config['poller_id'] > 1 && $title != '' && $mode_count == 0) { $title .= ' [ ' . __('Remote Server') . ': '; if ($config['connection'] == 'offline') { $title .= '' . __('Offline') . ''; } elseif ($config['connection'] == 'recovery') { $title .= '' . __('Recovering') . ''; } else { $title .= __('Online'); } $title .= ' ]'; $mode_count++; } $table_prefix = basename(get_current_page(), '.php'); if (!isempty_request_var('action')) { $table_prefix .= '_' . clean_up_name(get_nfilter_request_var('action')); } elseif (!isempty_request_var('report')) { $table_prefix .= '_' . clean_up_name(get_nfilter_request_var('report')); } elseif (!isempty_request_var('tab')) { $table_prefix .= '_' . clean_up_name(get_nfilter_request_var('tab')); } $table_id = $table_prefix . $table_suffix; if ($title != '') { print "
"; print '
'; print "
" . ($title != '' ? $title:'') . '
'; print "
"; $page = get_current_page(); $help_file = html_help_page($page); if ($help_file === false) { if (isset_request_var('tab')) { $tpage = $page . ':' . get_nfilter_request_var('tab'); $help_file = html_help_page($tpage); } } if ($help_file === false) { if (isset_request_var('action')) { $tpage = $page . ':' . get_nfilter_request_var('action'); $help_file = html_help_page($tpage); } } if ($help_file !== false && $help_count == 0 && is_realm_allowed(28)) { print ""; $help_count++; } if ($add_text != '' && !is_array($add_text)) { print ""; } else { if (is_array($add_text)) { if (cacti_sizeof($add_text)) { foreach ($add_text as $icon) { if (isset($icon['callback']) && $icon['callback'] === true) { $classo = 'linkOverDark'; } else { $classo = ''; } if (isset($icon['class']) && $icon['class'] !== '') { $classi = $icon['class']; } else { $classi = 'fa fa-plus'; } if (isset($icon['href'])) { $href = html_escape($icon['href']); } else { $href = '#'; } if (isset($icon['title'])) { $title = $icon['title']; } else { $title = $add_label; } print ""; } } } else { print ' '; } } print '
'; if ($div === true) { print "
"; } else { print ""; } } else { print "
"; if ($div === true) { print "
"; } else { print "
"; } } $table_suffix++; } /** * html_sub_tabs - Creates a memory persistent sub-tab interface * for a page or pages using a simple method to lay those tabs * out. * * @param array - An associative array of tab variables and names * Alternatively an array of names that can be converted * using the strtoupper() function to titles. * @param string - A string of URL parameters like 'action=edit&id=x' * @param string - An option session variable to use to store * the current tab status. Defaults to the page * name and the suffic of current_tab * * @return null - Output is printed to standard output */ function html_sub_tabs($tabs, $uri = '', $session_var = '') { /* determine the session variables if not set */ if ($session_var == '') { $session_var = basename(get_current_page(), '.php') . '_current_tab'; } $page_name = get_current_page() . '?' . $uri . ($uri != '' ? '&':''); /* set the default settings category */ if (!isset_request_var('tab')) { /* there is no selected tab; select the first one */ if (isset($_SESSION[$session_var])) { $current_tab = $_SESSION[$session_var]; } else { $current_tab = array_keys($tabs)[0]; } } else { $current_tab = get_request_var('tab'); } /* Check to see if the tab exists, and if not, use the default */ if (!isset($tabs[$current_tab])) { $current_tab = array_keys($tabs)[0]; } $_SESSION[$session_var] = $current_tab; set_request_var('tab', $current_tab); /* draw the categories tabs on the top of the page */ print '
'; print "
'; print '
'; } /** * html_end_box - draws the end of an HTML box * * @param $trailing_br (bool) - whether to draw a trailing
tag after ending * @param $div (bool) - whether type of box is div or table */ function html_end_box($trailing_br = true, $div = false) { if ($div) { print ''; } else { print '
'; } if ($trailing_br == true) { print "
"; } } /** * html_graph_template_multiselect - consistent multiselect javascript library for cacti. */ function html_graph_template_multiselect() { ?> var msWidth = 200; $('#graph_template_id').hide().multiselect({ menuHeight: $(window).height()*.7, menuWidth: 'auto', linkInfo: faIcons, buttonWidth: 'auto', noneSelectedText: '', selectedText: function(numChecked, numTotal, checkedItems) { myReturn = numChecked + ' '; $.each(checkedItems, function(index, value) { if (value.value == '-1') { myReturn=''; return false; } else if (value.value == '0') { myReturn=''; return false; } }); return myReturn; }, checkAllText: '', uncheckAllText: '', uncheckAll: function() { $(this).multiselect('widget').find(':checkbox:first').each(function() { $(this).prop('checked', true); }); }, close: function(event, ui) { applyGraphFilter(); }, open: function(event, ui) { $("input[type='search']:first").focus(); }, click: function(event, ui) { checked=$(this).multiselect('widget').find('input:checked').length; if (ui.value == -1 || ui.value == 0) { if (ui.checked == true) { $('#graph_template_id').multiselect('uncheckAll'); if (ui.value == -1) { $(this).multiselect('widget').find(':checkbox:first').prop('checked', true); } else { $(this).multiselect('widget').find(':checkbox[value="0"]').prop('checked', true); } } } else if (checked == 0) { $(this).multiselect('widget').find(':checkbox:first').each(function() { $(this).click(); }); } else if ($(this).multiselect('widget').find('input:checked:first').val() == '-1') { if (checked > 0) { $(this).multiselect('widget').find(':checkbox:first').each(function() { $(this).click(); $(this).prop('disable', true); }); } } else { $(this).multiselect('widget').find(':checkbox[value="0"]').prop('checked', false); } } }).multiselectfilter({ label: '', placeholder: '', width: msWidth }); 0) { if ($header != '') { print $header; } foreach ($graph_array as $graph) { if (!isset($graph['host_id'])) { list($graph['host_id'], $graph['disabled']) = db_fetch_row_prepared('SELECT host_id, disabled FROM graph_local AS gl LEFT JOIN host AS h ON gl.host_id = h.id WHERE gl.id = ?', array($graph['local_graph_id'])); } if ($i == 0) { print ""; } ?> ' style='width:%;'>
' graph_width='' graph_height='' title_font_size=''>
" . html_escape($graph['title_cache']) . '' : '');?>
' class='noprint graphDrillDown'>
'; } } while (($i % $columns) != 0) { print ""; $i++; } print ''; } else { if ($no_graphs_message != '') { print "$no_graphs_message"; } } } /** * html_graph_thumbnail_area - draws an area the contains thumbnail sized graphs * * @param $graph_array - the array to contains graph information. for each graph in the * array, the following two keys must exist * $arr[0]["local_graph_id"] // graph id * $arr[0]["title_cache"] // graph title * @param $no_graphs_message - display this message if no graphs are found in $graph_array * @param $extra_url_args - extra arguments to append to the url * @param $header - html to use as a header * @param $columns - the number of columns to present * @param $tree_id - the tree id if this is a tree thumbnail * @param $branch_id - the branch id if this is a tree thumbnail */ function html_graph_thumbnail_area(&$graph_array, $no_graphs_message = '', $extra_url_args = '', $header = '', $columns = 0, $tree_id = 0, $branch_id = 0) { global $config; $i = 0; $k = 0; $j = 0; $num_graphs = cacti_sizeof($graph_array); if ($columns == 0) { $columns = read_user_setting('num_columns'); } ?> 0) { if ($header != '') { print $header; } $start = true; foreach ($graph_array as $graph) { if (!isset($graph['host_id'])) { list($graph['host_id'], $graph['disabled']) = db_fetch_row_prepared('SELECT host_id, disabled FROM graph_local AS gl LEFT JOIN host AS h ON gl.host_id = h.id WHERE gl.id = ?', array($graph['local_graph_id'])); } if (isset($graph['graph_template_name'])) { if (isset($prev_graph_template_name)) { if ($prev_graph_template_name != $graph['graph_template_name']) { $prev_graph_template_name = $graph['graph_template_name']; } } else { $prev_graph_template_name = $graph['graph_template_name']; } } elseif (isset($graph['data_query_name'])) { if (isset($prev_data_query_name)) { if ($prev_data_query_name != $graph['data_query_name']) { $print = true; $prev_data_query_name = $graph['data_query_name']; } else { $print = false; } } else { $print = true; $prev_data_query_name = $graph['data_query_name']; } if ($print) { if (!$start) { while (($i % $columns) != 0) { print ""; $i++; } print ''; } print " " . __('Data Query:') . ' ' . $graph['data_query_name'] . ' '; $i = 0; } } if ($i == 0) { print ""; $start = false; } ?> ' style='width:%;'>
' graph_width='' graph_height=''>
" . html_escape($graph['title_cache']) . '' : '');?>
' class='noprint graphDrillDown'>
'; $start = true; } } if (!$start) { while (($i % $columns) != 0) { print ""; $i++; } print ''; } } else { if ($no_graphs_message != '') { print "$no_graphs_message"; } } } function graph_drilldown_icons($local_graph_id, $type = 'graph_buttons', $tree_id = 0, $branch_id = 0) { global $config; static $rand = 0; $aggregate_url = aggregate_build_children_url($local_graph_id); $graph_template_id = db_fetch_cell_prepared('SELECT graph_template_id FROM graph_local WHERE id = ?', array($local_graph_id)); print "
"; print "
"; print "
"; print "
"; if (is_realm_allowed(3)) { $host_id = db_fetch_cell_prepared('SELECT host_id FROM graph_local WHERE id = ?', array($local_graph_id)); if ($host_id > 0) { print ""; print '
'; $rand++; } } if (is_realm_allowed(10) && $graph_template_id > 0) { print ""; print '
'; } if (read_config_option('realtime_enabled') == 'on' && is_realm_allowed(25)) { if (read_user_setting('realtime_mode') == '' || read_user_setting('realtime_mode') == '1') { print "
"; } else { print "
"; } } if (is_realm_allowed(1043)) { print ""; print '
'; } if ($aggregate_url != '') { print $aggregate_url; } api_plugin_hook($type, array( 'hook' => $type, 'local_graph_id' => $local_graph_id, 'rra' => 0, 'view_type' => $tree_id > 0 ? 'tree':'preview', 'tree_id' => $tree_id, 'branch_id' => $branch_id) ); print '
'; } /** * html_nav_bar - draws a navigation bar which includes previous/next links as well as current * page information * * @param $base_url - the base URL will all filter options except page (should include url_path) * @param $max_pages - the maximum number of pages to display * @param $current_page - the current page in the navigation system * @param $rows_per_page - the number of rows that are displayed on a single page * @param $total_rows - the total number of rows in the navigation system * @param $object - the object types that is being displayed * @param $page_var - the object types that is being displayed * @param $return_to - paint the resulting page into this dom object * @param $page_count - provide a page count */ function html_nav_bar($base_url, $max_pages, $current_page, $rows_per_page, $total_rows, $colspan=30, $object = '', $page_var = 'page', $return_to = '', $page_count = true) { if ($object == '') { $object = __('Rows'); } if ($total_rows >= $rows_per_page && $page_count) { if (substr_count($base_url, '?') == 0) { $base_url = trim($base_url) . '?'; } else { $base_url = trim($base_url) . '&'; } $url_page_select = get_page_list($current_page, $max_pages, $rows_per_page, $total_rows, $base_url, $page_var, $return_to); $nav = "'; } elseif ($total_rows > 0) { if ($page_count || ($total_rows < $rows_per_page && $current_page == 1)) { $nav = "\n"; } else { if (substr_count($base_url, '?') == 0) { $base_url = trim($base_url) . '?'; } else { $base_url = trim($base_url) . '&'; } $url_page_select = "
    "; //for the same height as write in get_page_list() $url_page_select .= "
  • $current_page
  • "; $url_page_select .= '
'; $nav = "\n"; if ($return_to == '') { $return_to = 'main'; } $url = $base_url . $page_var; $nav .= ""; } } else { $nav = "'; } return $nav; } /** * html_header_sort - draws a header row suitable for display inside of a box element. When * a user selects a column header, the callback function "filename" will be called to handle * the sort the column and display the altered results. * * @param $header_items - an array containing a list of column items to display. The * format is similar to the html_header, with the exception that it has three * dimensions associated with each element (db_column => display_text, default_sort_order) * alternatively (db_column => array('display' = 'blah', 'align' = 'blah', 'sort' = 'blah')) * @param $sort_column - the value of current sort column. * @param $sort_direction - the value the current sort direction. The actual sort direction * will be opposite this direction if the user selects the same named column. * @param $last_item_colspan - the TD 'colspan' to apply to the last cell in the row * @param $url - a base url to redirect sort actions to * @param $return_to - the id of the object to inject output into as a result of the sort action */ function html_header_sort($header_items, $sort_column, $sort_direction, $last_item_colspan = 1, $url = '', $return_to = '') { static $page_count = 0; /* reverse the sort direction */ if ($sort_direction == 'ASC') { $new_sort_direction = 'DESC'; } else { $new_sort_direction = 'ASC'; } $page = $page_count . '_' . str_replace('.php', '', basename($_SERVER['SCRIPT_NAME'])); if (isset_request_var('action')) { $page .= '_' . get_request_var('action'); } if (isset_request_var('tab')) { $page .= '_' . get_request_var('tab'); } if (isset($_SESSION['sort_data'][$page])) { $order_data = $_SESSION['sort_data'][$page]; } else { $order_data = array(get_request_var('sort_column') => get_request_var('sort_direction')); } foreach ($order_data as $key => $direction) { $primarySort = $key; break; } print ""; $i = 1; foreach ($header_items as $db_column => $display_array) { $isSort = ''; if (isset($display_array['nohide'])) { $nohide = 'nohide'; } else { $nohide = ''; } if (array_key_exists('display', $display_array)) { $display_text = $display_array['display']; if ($sort_column == $db_column) { $icon = $sort_direction; $direction = $new_sort_direction; if ($db_column == $primarySort) { $isSort = 'primarySort'; } else { $isSort = 'secondarySort'; } } else { if (isset($order_data[$db_column])) { $icon = $order_data[$db_column]; if ($order_data[$db_column] == 'DESC') { $direction = 'ASC'; } else { $direction = 'DESC'; } if ($db_column == $primarySort) { $isSort = 'primarySort'; } else { $isSort = 'secondarySort'; } } else { $icon = ''; if (isset($display_array['sort'])) { $direction = $display_array['sort']; } else { $direction = 'ASC'; } } } if (isset($display_array['align'])) { $align = $display_array['align']; } else { $align = 'left'; } if (isset($display_array['tip'])) { $tip = $display_array['tip']; } else { $tip = ''; } } else { /* by default, you will always sort ascending, with the exception of an already sorted column */ if ($sort_column == $db_column) { $icon = $sort_direction; $direction = $new_sort_direction; $display_text = $display_array[0]; if ($db_column == $primarySort) { $isSort = 'primarySort'; } else { $isSort = 'secondarySort'; } } else { if (isset($order_data[$db_column])) { $icon = $order_data[$db_column]; if ($order_data[$db_column] == 'DESC') { $direction = 'ASC'; } else { $direction = 'DESC'; } if ($db_column == $primarySort) { $isSort = 'primarySort'; } else { $isSort = 'secondarySort'; } } else { $icon = ''; $direction = $display_array[1]; } $display_text = $display_array[0]; } $align = 'left'; $tip = ''; } if (strtolower($icon) == 'asc') { $icon = 'fa fa-sort-up'; } elseif (strtolower($icon) == 'desc') { $icon = 'fa fa-sort-down'; } else { $icon = 'fa fa-sort'; } if (($db_column == '') || (substr_count($db_column, 'nosort'))) { print '' . $display_text . ''; } else { print '"; print "
" . $display_text . "
"; } $i++; } print ''; $page_count++; } /** * html_header_sort_checkbox - draws a header row with a 'select all' checkbox in the last cell * suitable for display inside of a box element. When a user selects a column header, * the callback function "filename" will be called to handle the sort the column and display * the altered results. * * @param $header_items - an array containing a list of column items to display. The * fonrmat is similar to the html_header, with the exception that it has three * dimensions associated with each element (db_column => display_text, default_sort_order) * alternatively (db_column => array('display' = 'blah', 'align' = 'blah', 'sort' = 'blah')) * @param $sort_column - the value of current sort column. * @param $sort_direction - the value the current sort direction. The actual sort direction * will be opposite this direction if the user selects the same named column. * @param $form_action - the url to post the 'select all' form to * @param $return_to - the id of the object to inject output into as a result of the sort action */ function html_header_sort_checkbox($header_items, $sort_column, $sort_direction, $include_form = true, $form_action = '', $return_to = '', $prefix = 'chk') { static $page_count = 0; /* reverse the sort direction */ if ($sort_direction == 'ASC') { $new_sort_direction = 'DESC'; } else { $new_sort_direction = 'ASC'; } $page = $page_count . '_' . str_replace('.php', '', basename($_SERVER['SCRIPT_NAME'])); if (isset_request_var('action')) { $page .= '_' . get_request_var('action'); } if (isset_request_var('tab')) { $page .= '_' . get_request_var('tab'); } if (isset($_SESSION['sort_data'][$page])) { $order_data = $_SESSION['sort_data'][$page]; } else { $order_data = array(get_request_var('sort_column') => get_request_var('sort_direction')); } foreach ($order_data as $key => $direction) { $primarySort = $key; break; } /* default to the 'current' file */ if ($form_action == '') { $form_action = get_current_page(); } print ""; foreach ($header_items as $db_column => $display_array) { $isSort = ''; if (isset($display_array['nohide'])) { $nohide = 'nohide'; } else { $nohide = ''; } $icon = ''; if (array_key_exists('display', $display_array)) { $display_text = $display_array['display']; if ($sort_column == $db_column) { $icon = $sort_direction; $direction = $new_sort_direction; if ($db_column == $primarySort) { $isSort = 'primarySort'; } else { $isSort = 'secondarySort'; } } else { if (isset($order_data[$db_column])) { $icon = $order_data[$db_column]; if ($order_data[$db_column] == 'DESC') { $direction = 'ASC'; } else { $direction = 'DESC'; } if ($db_column == $primarySort) { $isSort = 'primarySort'; } else { $isSort = 'secondarySort'; } } else { $icon = ''; if (isset($display_array['sort'])) { $direction = $display_array['sort']; } else { $direction = 'ASC'; } } } if (isset($display_array['align'])) { $align = $display_array['align']; } else { $align = 'left'; } if (isset($display_array['tip'])) { $tip = $display_array['tip']; } else { $tip = ''; } } else { /* by default, you will always sort ascending, with the exception of an already sorted column */ if ($sort_column == $db_column) { $icon = $sort_direction; $direction = $new_sort_direction; $display_text = $display_array[0]; if ($db_column == $primarySort) { $isSort = 'primarySort'; } else { $isSort = 'secondarySort'; } } else { if (isset($order_data[$db_column])) { $icon = $order_data[$db_column]; if ($order_data[$db_column] == 'DESC') { $direction = 'ASC'; } else { $direction = 'DESC'; } if ($db_column == $primarySort) { $isSort = 'primarySort'; } else { $isSort = 'secondarySort'; } } else { $icon = ''; $direction = $display_array[1]; } $display_text = $display_array[0]; } $align = 'left'; $tip = ''; } if (strtolower($icon) == 'asc') { $icon = 'fa fa-sort-up'; } elseif (strtolower($icon) == 'desc') { $icon = 'fa fa-sort-down'; } else { $icon = 'fa fa-sort'; } if (($db_column == '') || (substr_count($db_column, 'nosort'))) { print '" . $display_text . ''; } else { print '"; print "
" . $display_text . "
"; } } print "" . ($include_form ? "
":''); print ''; $page_count++; } /** * html_header - draws a header row suitable for display inside a box element * * @param $header_items - an array containing a list of items to be included in the header * alternatively and array of header names and alignment array('display' = 'blah', 'align' = 'blah') * @param $last_item_colspan - the TD 'colspan' to apply to the last cell in the row */ function html_header($header_items, $last_item_colspan = 1) { print ""; $i = 0; foreach ($header_items as $item) { if (is_array($item)) { if (isset($item['nohide'])) { $nohide = 'nohide'; } else { $nohide = ''; } if (isset($item['align'])) { $align = $item['align']; } else { $align = 'left'; } if (isset($item['tip'])) { $tip = $item['tip']; } else { $tip = ''; } print '' . html_escape($item['display']) . ''; } else { print '' . html_escape($item) . ''; } $i++; } print ''; } /** * html_section_header - draws a header row suitable for display inside a box element * but for display as a section title and not as a series of table header columns * * @param $header_name - an array of the display name of the header for the section and * optional alignment. * @param $last_item_colspan - the TD 'colspan' to apply to the last cell in the row */ function html_section_header($header_item, $last_item_colspan = 1) { print ""; if (is_array($header_item) && isset($header_item['display'])) { print '" . $header_item['display'] . ''; } else { print "" . $header_item . ''; } print ''; } /** * html_header_checkbox - draws a header row with a 'select all' checkbox in the last cell * suitable for display inside a box element * * @param $header_items - an array containing a list of items to be included in the header * alternatively and array of header names and alignment array('display' = 'blah', 'align' = 'blah') * @param $form_action - the url to post the 'select all' form to */ function html_header_checkbox($header_items, $include_form = true, $form_action = '', $resizable = true, $prefix = 'chk') { /* default to the 'current' file */ if ($form_action == '') { $form_action = get_current_page(); } print ""; foreach ($header_items as $item) { if (is_array($item)) { if (isset($item['nohide'])) { $nohide = 'nohide'; } else { $nohide = ''; } if (isset($item['align'])) { $align = $item['align']; } else { $align = 'left'; } if (isset($item['tip'])) { $tip = $item['tip']; } else { $tip = ''; } print '" . html_escape($item['display']) . ''; } else { print "" . html_escape($item) . ''; } } print "" . ($include_form ? "":''); print ''; } /** * html_create_list - draws the items for a html dropdown given an array of data * * @param $form_data - an array containing data for this dropdown. it can be formatted * in one of two ways: * $array["id"] = "value"; * -- or -- * $array[0]["id"] = 43; * $array[0]["name"] = "Red"; * @param $column_display - used to identify the key to be used for display data. this * is only applicable if the array is formatted using the second method above * @param $column_id - used to identify the key to be used for id data. this * is only applicable if the array is formatted using the second method above * @param $form_previous_value - the current value of this form element */ function html_create_list($form_data, $column_display, $column_id, $form_previous_value) { if (empty($column_display)) { if (cacti_sizeof($form_data)) { foreach (array_keys($form_data) as $id) { print ''; } } } else { if (cacti_sizeof($form_data)) { foreach ($form_data as $row) { print "'; } else { print '>' . html_escape(null_out_substitutions($row[$column_display])) . ''; } } } } } /** * html_escape_request_var - sanitizes a request variable for display * * @param $string - string the request variable to escape * * @return $new_string - the escaped request variable to be returned. */ function html_escape_request_var($string) { return html_escape(get_request_var($string)); } /** * html_escape - sanitizes a string for display * * @param $string - string the string to escape * * @return $new_string - the escaped string to be returned. */ function html_escape($string) { static $charset; if ($charset == '') { $charset = ini_get('default_charset'); } if ($charset == '') { $charset = 'UTF-8'; } // Grave Accent character can lead to xss if ($string !== null) { $string = str_replace('`', '`', $string); return htmlspecialchars($string, ENT_QUOTES | ENT_HTML5, $charset, false); } else { return $string; } } /** * html_split_string - takes a string and breaks it into a number of
separated segments * * @param $string - string to be modified and returned * @param $length - the maximal string length to split to * @param $forgiveness - the maximum number of characters to walk back from to determine * the correct break location. * * @return $new_string - the modified string to be returned. */ function html_split_string($string, $length = 90, $forgiveness = 10) { $new_string = ''; $j = 0; $done = false; while (!$done) { if (mb_strlen($string, 'UTF-8') > $length) { for ($i = 0; $i < $forgiveness; $i++) { if (substr($string, $length - $i, 1) == ' ') { $new_string .= mb_substr($string, 0, $length - $i, 'UTF-8') . '
'; break; } } $string = mb_substr($string, $length - $i, null, 'UTF-8'); } else { $new_string .= $string; $done = true; } $j++; if ($j > 4) { break; } } return $new_string; } /** * draw_graph_items_list - draws a nicely formatted list of graph items for display * on an edit form * * @param $item_list - an array representing the list of graph items. this array should * come directly from the output of db_fetch_assoc() * @param $filename - the filename to use when referencing any external url * @param $url_data - any extra GET url information to pass on when referencing any * external url * @param $disable_controls - whether to hide all edit/delete functionality on this form */ function draw_graph_items_list($item_list, $filename, $url_data, $disable_controls) { global $config; include(CACTI_PATH_INCLUDE . '/global_arrays.php'); print ""; DrawMatrixHeaderItem(__('Graph Item'),'',1); DrawMatrixHeaderItem(__('#'), '', 1); DrawMatrixHeaderItem(__('Data Source'),'',1); DrawMatrixHeaderItem(__('Graph Item Type'),'',1); DrawMatrixHeaderItem(__('CF Type'),'',1); DrawMatrixHeaderItem(__('GPrint'),'',1); DrawMatrixHeaderItem(__('CDEF'),'',1); DrawMatrixHeaderItem(__('VDEF'),'',1); DrawMatrixHeaderItem(__('Alpha %'),'',1); DrawMatrixHeaderItem(__('Item Color'),'',4); print ''; $group_counter = 0; $_graph_type_name = ''; $i = 0; if (cacti_sizeof($item_list)) { foreach ($item_list as $item) { /* graph grouping display logic */ $this_row_style = ''; $use_custom_class = false; $hard_return = ''; if (!preg_match('/(GPRINT|TEXTALIGN|HRULE|VRULE|TICK)/', $graph_item_types[$item['graph_type_id']])) { $this_row_style = 'font-weight: bold;'; $use_custom_class = true; $item['gprint_name'] = __('N/A'); if ($group_counter % 2 == 0) { $customClass = 'graphItem'; } else { $customClass = 'graphItemAlternate'; } $group_counter++; } $_graph_type_name = $graph_item_types[$item['graph_type_id']]; /* alternating row color */ if ($use_custom_class == false) { print ""; } else { print ""; } print ''; if ($disable_controls == false) { print ""; } print __('Item # %d', ($i + 1)); if ($disable_controls == false) { print ''; } print ''; print '' . $item['sequence'] . ''; if (empty($item['data_source_name'])) { $item['data_source_name'] = __('No Source'); } switch (true) { case preg_match('/(TEXTALIGN)/', $_graph_type_name): $matrix_title = 'TEXTALIGN: ' . ucfirst($item['textalign']); break; case preg_match('/(TICK)/', $_graph_type_name): $matrix_title = $item['data_source_name'] . ': ' . $item['text_format']; break; case preg_match('/(AREA|STACK|GPRINT|LINE[123])/', $_graph_type_name): $matrix_title = $item['data_source_name'] . ': ' . $item['text_format']; break; case preg_match('/(HRULE)/', $_graph_type_name): $matrix_title = 'HRULE: ' . $item['value']; break; case preg_match('/(VRULE)/', $_graph_type_name): $matrix_title = 'VRULE: ' . $item['value']; break; case preg_match('/(COMMENT)/', $_graph_type_name): $matrix_title = 'COMMENT: ' . $item['text_format']; break; } if (preg_match('/(TEXTALIGN)/', $_graph_type_name)) { $hard_return = ''; } elseif ($item['hard_return'] == 'on') { $hard_return = "<HR>"; } /* data source */ print "" . html_escape($matrix_title) . $hard_return . ''; /* graph item type */ print "" . $graph_item_types[$item['graph_type_id']] . ''; if (!preg_match('/(TICK|TEXTALIGN|HRULE|VRULE)/', $_graph_type_name)) { print "" . $consolidation_functions[$item['consolidation_function_id']] . ''; } else { print '' . __('N/A') . ''; } print ""; print $item['gprint_name']; print ''; print ""; print $item['cdef_name']; print ''; print ""; print $item['vdef_name']; print ''; /* alpha type */ if (preg_match('/(AREA|STACK|TICK|LINE[123])/', $_graph_type_name)) { print "" . round((hexdec($item['alpha']) / 255) * 100) . '%'; } else { print ""; } /* color name */ if (!preg_match('/(TEXTALIGN)/', $_graph_type_name)) { print "'; print "" . $item['hex'] . ''; } else { print ''; } if ($disable_controls == false) { print ""; if ($i != cacti_sizeof($item_list) - 1) { print ""; } else { print ""; } if ($i > 0) { print ""; } else { print ""; } print ''; print ""; print ""; print ''; } print ''; $i++; } } else { print "" . __('No Items') . ''; } } /** * is_menu_pick_active - determines if current selection is active * * @param $menu_url - url of current page * * @return true if active, false if not */ function is_menu_pick_active($menu_url) { static $url_array, $url_parts; $menu_parts = array(); /* special case for host.php?action=edit&create=true */ if (strpos($_SERVER['REQUEST_URI'], 'host.php?action=edit&create=true') !== false) { if (strpos($menu_url, 'host.php?action=edit&create=true') !== false) { return true; } else { return false; } } elseif (!is_array($url_array) || (is_array($url_array) && !cacti_sizeof($url_array))) { /* break out the URL and variables */ $url_array = parse_url($_SERVER['REQUEST_URI']); if (isset($url_array['query'])) { parse_str($url_array['query'], $url_parts); } else { $url_parts = array(); } } // Host requires another check if (strpos($menu_url, 'host.php?action=edit&create=true') !== false) { return false; } $menu_array = parse_url($menu_url); if ($menu_array === false) { return false; } if (! array_key_exists('path', $menu_array)) { return false; } if (basename($url_array['path']) == basename($menu_array['path'])) { if (isset($menu_array['query'])) { parse_str($menu_array['query'], $menu_parts); } else { $menu_parts = array(); } if (isset($menu_parts['id'])) { if (isset($url_parts['id'])) { if ($menu_parts['id'] == $url_parts['id']) { return true; } } } elseif (isset($menu_parts['action'])) { if (isset($url_parts['action'])) { if ($menu_parts['action'] == $url_parts['action']) { return true; } } } else { return true; } } return false; } /** * draw_menu - draws the cacti menu for display in the console * * @param string - the user menu to display */ function draw_menu($user_menu = '') { global $config, $user_auth_realm_filenames, $menu, $menu_glyphs; if (!is_array($user_menu)) { $user_menu = $menu; } print "
'; } /** * draw_actions_dropdown - draws a table the allows the user to select an action to perform * on one or more data elements * * @param $actions_array - an array that contains a list of possible actions. this array should * be compatible with the form_dropdown() function * @param $delete_action - if there is a delete action that should suppress removal of rows * specify it here. If you don't want any delete actions, set to 0. */ function draw_actions_dropdown($actions_array, $delete_action = 1) { global $config; if ($actions_array === null || cacti_sizeof($actions_array) == 0) { return; } if (!isset($actions_array[0])) { $my_actions[0] = __('Choose an action'); $my_actions += $actions_array; $actions_array = $my_actions; } ?>
' alt=''> ' title=''>
$children) { if (cacti_sizeof($children)) { foreach ($children as $page => $name) { if (basename($page) == $basename) { return true; } } } } } return false; } function html_show_tabs_left() { global $config, $tabs_left; $realm_allowed = array(); $realm_allowed[7] = is_realm_allowed(7); $realm_allowed[8] = is_realm_allowed(8); $realm_allowed[18] = is_realm_allowed(18); $realm_allowed[19] = is_realm_allowed(19); $realm_allowed[21] = is_realm_allowed(21); $realm_allowed[22] = is_realm_allowed(22); if ($realm_allowed[8]) { $show_console_tab = true; } else { $show_console_tab = false; } if (get_selected_theme() == 'classic') { if ($show_console_tab == true) { $console_selected = (is_console_page(get_current_page()) ? " class='selected'":''); $console_image = (is_console_page(get_current_page()) ? 'images/tab_console.gif':'images/tab_console_down.gif'); ?> href='index.php'>' alt=''> 1 && $config['connection'] != 'online') { // Don't show graphs tab when offline } else { $file = get_current_page(); if ($file == 'graph_view.php' || $file == 'graph.php') { print "" . __("; } else { print "" . __("; } } } if ($realm_allowed[21] || $realm_allowed[22]) { if ($config['poller_id'] > 1) { // Don't show reports table if not poller 1 } else { if (substr_count($_SERVER['REQUEST_URI'], 'reports_')) { print '' . __('Reporting') . ''; } else { print '' . __('Reporting') . ''; } } } if ($realm_allowed[18] || $realm_allowed[19]) { if (substr_count($_SERVER['REQUEST_URI'], 'clog')) { print '' . __('Logs'). ''; } else { print '' . __('Logs') . ''; } } api_plugin_hook('top_graph_header_tabs'); if ($config['poller_id'] > 1 && $config['connection'] != 'online') { // Only show external links when online } else { $external_links = db_fetch_assoc('SELECT id, title FROM external_links WHERE style="TAB" AND enabled="on" ORDER BY sortorder'); if (cacti_sizeof($external_links)) { foreach ($external_links as $tab) { if (is_realm_allowed($tab['id'] + 10000)) { $parsed_url = parse_url($_SERVER['REQUEST_URI']); $down = false; if (basename($parsed_url['path']) == 'link.php') { if (isset($parsed_url['query'])) { $queries = explode('&', $parsed_url['query']); foreach ($queries as $q) { list($var, $value) = explode('=', $q); if ($var == 'id') { if ($value == $tab['id']) { $down = true; break; } } } } } print '' . $tab['title'] . ''; } } } } } else { if ($show_console_tab) { $tabs_left[] = array( 'title' => __('Console'), 'id' => 'tab-console', 'url' => CACTI_PATH_URL . 'index.php', ); } if ($realm_allowed[7]) { if ($config['poller_id'] > 1 && $config['connection'] != 'online') { // Don't show the graphs tab when offline } else { $tabs_left[] = array( 'title' => __('Graphs'), 'id' => 'tab-graphs', 'url' => CACTI_PATH_URL . 'graph_view.php', ); } } if ($realm_allowed[21] || $realm_allowed[22]) { if ($config['poller_id'] > 1) { // Don't show the reports tab on other pollers } else { $tabs_left[] = array( 'title' => __('Reporting'), 'id' => 'tab-reports', 'url' => CACTI_PATH_URL . ($realm_allowed[21] ? 'reports_admin.php':'reports_user.php'), ); } } if ($realm_allowed[18] || $realm_allowed[19]) { $tabs_left[] = array( 'title' => __('Logs'), 'id' => 'tab-logs', 'url' => CACTI_PATH_URL . ($realm_allowed[18] ? 'clog.php':'clog_user.php'), ); } // Get Plugin Text Out of Band ob_start(); api_plugin_hook('top_graph_header_tabs'); $tab_text = trim(ob_get_clean()); $tab_text = str_replace('', '|', $tab_text); $tab_text = str_replace('', '', $tab_text); $elements = explode('|', $tab_text); $count = 0; foreach ($elements as $p) { $p = trim($p); if ($p == '') { continue; } $altpos = strpos($p, 'alt='); $hrefpos = strpos($p, 'href='); $idpos = strpos($p, 'id='); if ($altpos !== false) { $alt = substr($p, $altpos + 4); $parts = explode("'", $alt); if ($parts[0] == '') { $alt = $parts[1]; } else { $alt = $parts[0]; } } else { $alt = __('Title'); } if ($hrefpos !== false) { $href = substr($p, $hrefpos + 5); $parts = explode("'", $href); if ($parts[0] == '') { $href = $parts[1]; } else { $href = $parts[0]; } } else { $href = 'unknown'; } if ($idpos !== false) { $id = substr($p, $idpos + 3); $parts = explode("'", $id); if ($parts[0] == '') { $id = $parts[1]; } else { $id = $parts[0]; } } else { $id = 'unknown' . $count; $count++; } $tabs_left[] = array('title' => ucwords($alt), 'id' => 'tab-' . $id, 'url' => $href); } if ($config['poller_id'] > 1 && $config['connection'] != 'online') { // Only show external links when online } else { $external_links = db_fetch_assoc('SELECT id, title FROM external_links WHERE style="TAB" AND enabled="on" ORDER BY sortorder'); if (cacti_sizeof($external_links)) { foreach ($external_links as $tab) { if (is_realm_allowed($tab['id'] + 10000)) { $tabs_left[] = array( 'title' => $tab['title'], 'id' => 'tab-link' . $tab['id'], 'url' => CACTI_PATH_URL . 'link.php?id=' . $tab['id'] ); } } } } $i = 0; $me_base = get_current_page(); foreach ($tabs_left as $tab) { $tab_base = basename($tab['url']); if ($tab_base == 'graph_view.php' && ($me_base == 'graph_view.php' || $me_base == 'graph.php')) { $tabs_left[$i]['selected'] = true; } elseif (isset_request_var('id') && ($tab_base == 'link.php?id=' . get_nfilter_request_var('id')) && $me_base == 'link.php') { $tabs_left[$i]['selected'] = true; } elseif ($tab_base == 'index.php' && is_console_page($me_base)) { $tabs_left[$i]['selected'] = true; } elseif ($tab_base == $me_base) { $tabs_left[$i]['selected'] = true; } $i++; } $i = 0; print "
'; } } function html_graph_tabs_right() { global $config, $tabs_right; $theme = get_selected_theme(); if ($theme == 'classic') { if (is_view_allowed('show_tree')) { ?>'>.gif' title='' alt=''>'>.gif' title='' alt=''>'>.gif' title='' alt=''> 
__('Tree View'), 'image' => get_theme_paths('%s', 'images/tab_tree.gif'), 'id' => 'tree', 'url' => 'graph_view.php?action=tree', ); } if (is_view_allowed('show_list')) { $tabs_right[] = array( 'title' => __('List View'), 'image' => get_theme_paths('%s', 'images/tab_list.gif'), 'id' => 'list', 'url' => 'graph_view.php?action=list', ); } if (is_view_allowed('show_preview')) { $tabs_right[] = array( 'title' => __('Preview'), 'image' => get_theme_paths('%s', 'images/tab_preview.gif'), 'id' => 'preview', 'url' => 'graph_view.php?action=preview', ); } $i = 0; foreach ($tabs_right as $tab) { if ($tab['id'] == 'tree') { if (isset_request_var('action') && get_nfilter_request_var('action') == 'tree') { $tabs_right[$i]['selected'] = true; } } elseif ($tab['id'] == 'list') { if (isset_request_var('action') && get_nfilter_request_var('action') == 'list') { $tabs_right[$i]['selected'] = true; } } elseif ($tab['id'] == 'preview') { if (isset_request_var('action') && get_nfilter_request_var('action') == 'preview') { $tabs_right[$i]['selected'] = true; } } elseif (strstr(get_current_page(false), $tab['url'])) { $tabs_right[$i]['selected'] = true; } $i++; } print "
'; } } function html_host_filter($host_id = '-1', $call_back = 'applyFilter', $sql_where = '', $noany = false, $nonone = false) { $theme = get_selected_theme(); if (strpos($call_back, '()') === false) { $call_back .= '()'; } if ($host_id == '-1' && isset_request_var('host_id')) { $host_id = get_filter_request_var('host_id'); } if ($theme == 'classic' || !read_config_option('autocomplete_enabled')) { ?> 0) { $hostname = db_fetch_cell_prepared('SELECT description FROM host WHERE id = ?', array($host_id)); } elseif ($host_id == 0) { $hostname = __('None'); } else { $hostname = __('Any'); } ?> ";?> '; $output .= ''; if (!empty($icon)) { $output .= ""; } $output .= "$text"; if (!empty($subitem)) { $output .= "
    $subitem
"; } $output .= ''; return $output; } function html_spikekill_menu($local_graph_id) { global $settings; $ravgnan1 = html_spikekill_menu_item(__('Average'), html_spikekill_setting('spikekill_avgnan') == 'avg' ? 'fa fa-check':'fa', 'skmethod', 'method_avg'); $ravgnan2 = html_spikekill_menu_item(__('NaN\'s'), html_spikekill_setting('spikekill_avgnan') == 'nan' ? 'fa fa-check':'fa', 'skmethod', 'method_nan'); $ravgnan3 = html_spikekill_menu_item(__('Last Known Good'), html_spikekill_setting('spikekill_avgnan') == 'last' ? 'fa fa-check':'fa', 'skmethod', 'method_last'); $ravgnan = html_spikekill_menu_item(__('Replacement Method'), '', '', '', '', $ravgnan1 . $ravgnan2 . $ravgnan3); $rstddev = ''; foreach ($settings['spikes']['spikekill_deviations']['array'] as $key => $value) { $rstddev .= html_spikekill_menu_item($value, html_spikekill_setting('spikekill_deviations') == $key ? 'fa fa-check':'fa', 'skstddev', 'stddev_' . $key); } $rstddev = html_spikekill_menu_item(__('Standard Deviations'), '', '', '', '', $rstddev); $rvarpct = ''; foreach ($settings['spikes']['spikekill_percent']['array'] as $key => $value) { $rvarpct .= html_spikekill_menu_item($value, html_spikekill_setting('spikekill_percent') == $key ? 'fa fa-check':'fa', 'skvarpct', 'varpct_' . $key); } $rvarpct = html_spikekill_menu_item(__('Variance Percentage'), '', '', '', '', $rvarpct); $rvarout = ''; foreach ($settings['spikes']['spikekill_outliers']['array'] as $key => $value) { $rvarout .= html_spikekill_menu_item($value, html_spikekill_setting('spikekill_outliers') == $key ? 'fa fa-check':'fa', 'skvarout', 'varout_' . $key); } $rvarout = html_spikekill_menu_item(__('Variance Outliers'), '', '', '', '', $rvarout); $rkills = ''; foreach ($settings['spikes']['spikekill_number']['array'] as $key => $value) { $rkills .= html_spikekill_menu_item($value,html_spikekill_setting('spikekill_number') == $key ? 'fa fa-check':'fa', 'skills', 'kills_' . $key); } $rkills = html_spikekill_menu_item(__('Kills Per RRA'), '', '', '', '', $rkills); $rabsmax = ''; foreach ($settings['spikes']['spikekill_absmax']['array'] as $key => $value) { $rabsmax .= html_spikekill_menu_item($value, html_spikekill_setting('spikekill_absmax') == $key ? 'fa fa-check':'fa', 'skabsmax', 'absmax_' . $key); } $rabsmax = html_spikekill_menu_item(__('Absolute Max Value'), '', '', '', '', $rabsmax); ?>