Exemple #1
0
function list_rrd()
{
    global $config, $item_rows, $ds_actions, $rra_path, $hash_version_codes;
    /* suppress warnings */
    error_reporting(0);
    /* install the rrdclean error handler */
    set_error_handler('rrdclean_error_handler');
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request('page'));
    input_validate_input_number(get_request_var_request('age'));
    input_validate_input_number(get_request_var_request('rows'));
    /* ==================================================== */
    /* clean up search string */
    if (isset($_REQUEST['filter'])) {
        $_REQUEST['filter'] = sanitize_search_string(get_request_var('filter'));
    }
    /* clean up sort_column string */
    if (isset($_REQUEST['sort_column'])) {
        $_REQUEST['sort_column'] = sanitize_search_string(get_request_var('sort_column'));
    }
    /* clean up sort_direction string */
    if (isset($_REQUEST['sort_direction'])) {
        $_REQUEST['sort_direction'] = sanitize_search_string(get_request_var('sort_direction'));
    }
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST['clear_x'])) {
        kill_session_var('sess_rrdclean_current_page');
        kill_session_var('sess_rrdclean_age');
        kill_session_var('sess_default_rows');
        kill_session_var('sess_rrdclean_filter');
        kill_session_var('sess_rrdclean_sort_column');
        kill_session_var('sess_rrdclean_sort_direction');
        unset($_REQUEST['page']);
        unset($_REQUEST['age']);
        unset($_REQUEST['rows']);
        unset($_REQUEST['filter']);
        unset($_REQUEST['sort_column']);
        unset($_REQUEST['sort_direction']);
    }
    /* remember these search fields in session vars so we don't have to keep passing them around */
    load_current_session_value('page', 'sess_rrdclean_current_page', '1');
    load_current_session_value('age', 'sess_rrdclean_current_age', '1');
    load_current_session_value('rows', 'sess_rrdclean_rows', read_config_option('num_rows_table'));
    load_current_session_value('filter', 'sess_rrdclean_filter', '');
    load_current_session_value('sort_column', 'sess_rrdclean_sort_column', 'name');
    load_current_session_value('sort_direction', 'sess_rrdclean_sort_direction', 'ASC');
    $width = '100%';
    if (isset($hash_version_codes[$config['cacti_version']])) {
        if ($hash_version_codes[$config['cacti_version']] > 13) {
            $width = '100%';
        }
    }
    html_start_box('<strong>RRD Cleaner</strong>', $width, '', '3', 'center', '');
    filter();
    html_end_box();
    $sql_where = 'WHERE in_cacti=0';
    /* form the 'where' clause for our main sql query */
    if ($_REQUEST['filter'] != '') {
        $sql_where .= " AND (rc.name LIKE '%" . $_REQUEST['filter'] . "%' OR rc.name_cache LIKE '%" . $_REQUEST['filter'] . "%' OR dt.name LIKE '%" . $_REQUEST['filter'] . "%')";
    }
    $secsback = $_REQUEST['age'];
    if ($REQUEST['age'] != 0) {
        $sql_where .= " AND last_mod>='" . date("Y-m-d H:i:s", time() - 86400 * 7) . "'";
    } else {
        $sql_where .= " AND last_mod<='" . date("Y-m-d H:i:s", time() - $secsback) . "'";
    }
    print "<form action='rrdcleaner.php' method='post'>\n";
    html_start_box('', $width, '', '3', 'center', '');
    $total_rows = db_fetch_cell("SELECT COUNT(rc.name) \n\t\tFROM data_source_purge_temp AS rc\n\t\tLEFT JOIN data_template AS dt\n\t\tON dt.id = rc.data_template_id\n\t\t{$sql_where}");
    $total_size = db_fetch_cell("SELECT ROUND(SUM(size),2) \n\t\tFROM data_source_purge_temp AS rc\n\t\tLEFT JOIN data_template AS dt\n\t\tON dt.id = rc.data_template_id\n\t\t{$sql_where}");
    $file_list = db_fetch_assoc("SELECT rc.id, rc.name, rc.last_mod, rc.size, \n\t\trc.name_cache, rc.local_data_id, rc.data_template_id, dt.name AS data_template_name\n\t\tFROM data_source_purge_temp AS rc\n\t\tLEFT JOIN data_template AS dt\n\t\tON dt.id = rc.data_template_id\n\t\t{$sql_where} \n\t\tORDER BY " . $_REQUEST['sort_column'] . ' ' . $_REQUEST['sort_direction'] . '
		LIMIT ' . $_REQUEST['rows'] * ($_REQUEST['page'] - 1) . ',' . $_REQUEST['rows']);
    $nav = html_nav_bar($config['url_path'] . 'rrdcleaner.php?filter' . get_request_var_request('filter'), MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('rows'), $total_rows, 8, 'RRD Files', 'page', 'main');
    print $nav;
    $display_text = array('name' => array('RRD File Name', 'ASC'), 'name_cache' => array('DS Name', 'ASC'), 'local_data_id' => array('DS ID', 'ASC'), 'data_template_id' => array('Template ID', 'ASC'), 'data_template_name' => array('Template', 'ASC'), 'last_mod' => array('Last Modified', 'DESC'), 'size' => array('Size [KB]', 'DESC'));
    html_header_sort_checkbox($display_text, $_REQUEST['sort_column'], $_REQUEST['sort_direction'], false);
    if (sizeof($file_list)) {
        foreach ($file_list as $file) {
            $data_template_name = empty($file['data_template_name']) ? '<em>None</em>' : $file['data_template_name'];
            form_alternate_row('line' . $file['id'], true);
            form_selectable_cell(($_REQUEST['filter'] != '' ? eregi_replace('(' . preg_quote($_REQUEST['filter']) . ')', "<span class='filteredValue'>\\1</span>", $file['name']) : $file['name']) . '</a>', $file['id']);
            form_selectable_cell($file['local_data_id'] != 0 ? "<a class='linkEditMain' href='../../data_sources.php?action=ds_edit&id=" . $file['local_data_id'] . "'>" . ($_REQUEST['filter'] != '' ? eregi_replace('(' . preg_quote($_REQUEST['filter']) . ')', "<span class='filteredValue'>\\1</span>", title_trim(htmlentities($file['name_cache']), read_config_option('max_title_length'))) : title_trim(htmlentities($file['name_cache']), read_config_option('max_title_length'))) . '</a>' : '<i>Deleted</i>', $file['id']);
            form_selectable_cell($file['local_data_id'] > 0 ? $file['local_data_id'] : '<i>Deleted</i>', $file['id']);
            form_selectable_cell($file['data_template_id'] > 0 ? $file['data_template_id'] : '<i>Deleted</i>', $file['id']);
            form_selectable_cell($file['data_template_id'] > 0 ? $_REQUEST['filter'] != '' ? eregi_replace('(' . preg_quote($_REQUEST['filter']) . ')', "<span class='filteredValue'>\\1</span>", $file['data_template_name']) . '</a>' : $file['data_template_name'] : '<i>Deleted</i>', $file['id']);
            form_selectable_cell($file['last_mod'], $file['id']);
            form_selectable_cell($file['size'], $file['id']);
            form_checkbox_cell($file['id'], $file['id']);
            form_end_row();
            $i++;
        }
        /* put the nav bar on the bottom as well */
        print $nav;
    } else {
        print "<tr><td><em>No unused RRD Files</em></td></tr>\n";
    }
    html_end_box(false);
    rrdcleaner_legend($total_size);
    draw_actions_dropdown($ds_actions);
    print "</form>\n";
    /* restore original error handler */
    restore_error_handler();
}
Exemple #2
0
function list_rrd()
{
    global $config, $item_rows, $ds_actions, $rra_path, $colors, $hash_version_codes;
    /* suppress warnings */
    error_reporting(0);
    /* install the rrdclean error handler */
    set_error_handler("rrdclean_error_handler");
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("page"));
    input_validate_input_number(get_request_var_request("rows"));
    /* ==================================================== */
    /* clean up search string */
    if (isset($_REQUEST["filter"])) {
        $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
    }
    /* clean up sort_column string */
    if (isset($_REQUEST["sort_column"])) {
        $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column"));
    }
    /* clean up sort_direction string */
    if (isset($_REQUEST["sort_direction"])) {
        $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction"));
    }
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST["clear_x"])) {
        kill_session_var("sess_rrdclean_current_page");
        kill_session_var("sess_rrdclean_rows");
        kill_session_var("sess_rrdclean_filter");
        kill_session_var("sess_rrdclean_sort_column");
        kill_session_var("sess_rrdclean_sort_direction");
        unset($_REQUEST["page"]);
        unset($_REQUEST["rows"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["sort_column"]);
        unset($_REQUEST["sort_direction"]);
    }
    /* remember these search fields in session vars so we don't have to keep passing them around */
    load_current_session_value("page", "sess_rrdclean_current_page", "1");
    load_current_session_value("rows", "sess_rrdclean_rows", read_config_option("num_rows_device"));
    load_current_session_value("filter", "sess_rrdclean_filter", "");
    load_current_session_value("sort_column", "sess_rrdclean_sort_column", "name");
    load_current_session_value("sort_direction", "sess_rrdclean_sort_direction", "ASC");
    $width = "100%";
    if (isset($hash_version_codes[$config["cacti_version"]])) {
        if ($hash_version_codes[$config["cacti_version"]] > 13) {
            $width = "100%";
        }
    }
    html_start_box("<strong>RRD Cleaner</strong>", $width, $colors["header"], "8", "center", "");
    include $config["base_path"] . "/plugins/rrdclean/inc_rrdclean_filter_table.php";
    html_end_box();
    /* form the 'where' clause for our main sql query */
    $sql_where = "WHERE " . "(plugin_rrdclean.name like '%%" . $_REQUEST["filter"] . "%%') OR " . "(plugin_rrdclean.name_cache like '%%" . $_REQUEST["filter"] . "%%') OR " . "(plugin_rrdclean.data_template_name like '%%" . $_REQUEST["filter"] . "%%')";
    ?>
	<script type="text/javascript">
	<!--

	function applyFilterChange(objForm) {
		strURL = '?rows=' + objForm.rows.value;
		document.location = strURL;
	}

	-->
	</script>
	<?php 
    html_start_box("", $width, $colors["header"], "3", "center", "");
    $total_rows = db_fetch_cell("SELECT COUNT(plugin_rrdclean.name) FROM plugin_rrdclean {$sql_where}");
    $total_size = db_fetch_cell("SELECT\tROUND(SUM(plugin_rrdclean.size),2) FROM plugin_rrdclean {$sql_where}");
    $file_list = db_fetch_assoc("SELECT " . "plugin_rrdclean.id, " . "plugin_rrdclean.name, " . "plugin_rrdclean.last_mod, " . "plugin_rrdclean.size, " . "plugin_rrdclean.name_cache, " . "plugin_rrdclean.local_data_id, " . "plugin_rrdclean.data_template_id, " . "plugin_rrdclean.data_template_name " . "FROM (plugin_rrdclean) " . "{$sql_where} " . "ORDER BY " . $_REQUEST['sort_column'] . " " . $_REQUEST['sort_direction'] . " LIMIT " . $_REQUEST["rows"] * ($_REQUEST["page"] - 1) . "," . $_REQUEST["rows"]);
    /* generate page list */
    $url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, $_REQUEST["rows"], $total_rows, "rrdcleaner.php?filter=" . $_REQUEST["filter"]);
    $nav = "<tr bgcolor='#" . $colors["header"] . "'>\r\n\r\n\t<td colspan='8'>\r\n\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\r\n\t\t\t<tr>\r\n\t\t\t\t<td align='left' class='textHeaderDark'>\r\n\t\t\t\t\t\t<strong>&lt;&lt; ";
    if ($_REQUEST["page"] > 1) {
        $nav .= "<a class='linkOverDark' href='rrdcleaner.php?filter=" . $_REQUEST["filter"] . "&page=" . ($_REQUEST["page"] - 1) . "'>";
    }
    $nav .= "Previous";
    if ($_REQUEST["page"] > 1) {
        $nav .= "</a>";
    }
    $nav .= "</strong>\r\n\t\t\t\t</td>\n\r\n\t\t\t\t<td align='center' class='textHeaderDark'>\r\n\t\t\t\t\t\tShowing Rows " . ($_REQUEST["rows"] * ($_REQUEST["page"] - 1) + 1) . " to " . ($total_rows < $_REQUEST["rows"] || $total_rows < $_REQUEST["rows"] * $_REQUEST["page"] ? $total_rows : $_REQUEST["rows"] * $_REQUEST["page"]) . " of {$total_rows} [{$url_page_select}]\r\n\t\t\t\t</td>\n\r\n\t\t\t\t<td align='right' class='textHeaderDark'>\r\n\t\t\t\t\t\t<strong>";
    if ($_REQUEST["page"] * $_REQUEST["rows"] < $total_rows) {
        $nav .= "<a class='linkOverDark' href='rrdcleaner.php?filter=" . $_REQUEST["filter"] . "&page=" . ($_REQUEST["page"] + 1) . "'>";
    }
    $nav .= "Next";
    if ($_REQUEST["page"] * $_REQUEST["rows"] < $total_rows) {
        $nav .= "</a>";
    }
    $nav .= " &gt;&gt;</strong>\r\n\t\t\t\t</td>\n\r\n\t\t\t</tr>\r\n\t\t</table>\r\n\t</td>\r\n\t</tr>\n";
    print $nav;
    $display_text = array("name" => array("RRD File Name<br>[" . $rra_path . "]   ", "ASC"), "name_cache" => array("DS Name", "ASC"), "local_data_id" => array("DS ID", "ASC"), "data_template_id" => array("Template ID", "ASC"), "data_template_name" => array("Template Name", "ASC"), "last_mod" => array("Last Modified<br>[YYYY-MM-DD HH:MM:SS]", "ASC"), "size" => array("Size<br>[MB]", "ASC"));
    html_header_sort_checkbox($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]);
    $i = 0;
    if (sizeof($file_list) > 0) {
        foreach ($file_list as $file) {
            $data_template_name = empty($file["data_template_name"]) ? "<em>None</em>" : $file["data_template_name"];
            form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $file['id']);
            $i++;
            form_selectable_cell(($_REQUEST["filter"] != "" ? eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $file['name']) : $file['name']) . "</a>", $file['id']);
            form_selectable_cell($file["local_data_id"] != 0 ? "<a class='linkEditMain' href='../../data_sources.php?action=ds_edit&id=" . $file['local_data_id'] . "'>" . ($_REQUEST["filter"] != "" ? eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", title_trim(htmlentities($file["name_cache"]), read_config_option("max_title_data_source"))) : title_trim(htmlentities($file["name_cache"]), read_config_option("max_title_data_source"))) . "</a>" : $file["name_cache"], $file['id']);
            form_selectable_cell($file['local_data_id'], $file['id']);
            form_selectable_cell($file['data_template_id'], $file['id']);
            form_selectable_cell(($_REQUEST["filter"] != "" ? eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $file['data_template_name']) : $file['data_template_name']) . "</a>", $file['id']);
            form_selectable_cell($file['last_mod'], $file['id']);
            form_selectable_cell($file['size'], $file['id']);
            form_checkbox_cell($file["id"], $file['id']);
            form_end_row();
            $i++;
        }
        /* put the nav bar on the bottom as well */
        print $nav;
    } else {
        print "<tr><td><em>No unused RRD Files</em></td></tr>\n";
    }
    html_end_box(false);
    rrdcleaner_legend($total_size);
    draw_actions_dropdown($ds_actions);
    print "</form>\n";
    /* restore original error handler */
    restore_error_handler();
}