Ejemplo n.º 1
0
function mikrotik_devices()
{
    global $config, $colors, $item_rows;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request('status'));
    input_validate_input_number(get_request_var_request('page'));
    input_validate_input_number(get_request_var_request('rows'));
    /* ==================================================== */
    /* clean up sort_column */
    if (isset($_REQUEST['sort_column'])) {
        $_REQUEST['sort_column'] = sanitize_search_string(get_request_var_request('sort_column'));
    }
    /* clean up sort_direction */
    if (isset($_REQUEST['sort_direction'])) {
        $_REQUEST['sort_direction'] = sanitize_search_string(get_request_var_request('sort_direction'));
    }
    /* clean up filter string */
    if (isset($_REQUEST['filter'])) {
        $_REQUEST['filter'] = sanitize_search_string(get_request_var_request('filter'));
    }
    if (isset($_REQUEST['reset'])) {
        kill_session_var('sess_mikrotik_device_sort_column');
        kill_session_var('sess_mikrotik_device_sort_direction');
        kill_session_var('sess_mikrotik_device_status');
        kill_session_var('sess_mikrotik_device_filter');
        kill_session_var('sess_default_rows');
        kill_session_var('sess_mikrotik_device_current_page');
    } elseif (isset($_REQUEST['clear'])) {
        kill_session_var('sess_mikrotik_device_sort_column');
        kill_session_var('sess_mikrotik_device_sort_direction');
        kill_session_var('sess_mikrotik_device_status');
        kill_session_var('sess_mikrotik_device_filter');
        kill_session_var('sess_default_rows');
        kill_session_var('sess_mikrotik_device_current_page');
        unset($_REQUEST['sort_column']);
        unset($_REQUEST['sort_direction']);
        unset($_REQUEST['status']);
        unset($_REQUEST['filter']);
        unset($_REQUEST['rows']);
        unset($_REQUEST['page']);
    } else {
        /* if any of the settings changed, reset the page number */
        $changed = false;
        $changed += mikrotik_check_changed('status', 'sess_mikrotik_device_status');
        $changed += mikrotik_check_changed('filter', 'sess_mikrotik_device_filter');
        $changed += mikrotik_check_changed('rows', 'sess_default_rows');
        if ($changed) {
            $_REQUEST['page'] = '1';
        }
    }
    load_current_session_value('page', 'sess_mikrotik_device_current_page', '1');
    load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table'));
    load_current_session_value('sort_column', 'sess_mikrotik_device_sort_column', 'description');
    load_current_session_value('sort_direction', 'sess_mikrotik_device_sort_direction', 'ASC');
    load_current_session_value('status', 'sess_mikrotik_device_status', '-1');
    load_current_session_value('filter', 'sess_mikrotik_device_filter', '');
    ?>
	<script type='text/javascript'>
	function applyFilter() {
		strURL  = '?action=devices';
		strURL += '&status='   + $('#status').val();
		strURL += '&filter='   + $('#filter').val();
		strURL += '&rows='     + $('#rows').val();
		strURL += '&header=false';
		loadPageNoHeader(strURL);
	}

	function clearFilter() {
		strURL  = '?action=devices&clear=&header=false';
		loadPageNoHeader(strURL);
	}

	$(function() {
		$('#form_devices').submit(function(event) {
			event.preventDefault();
			applyFilter();
		});
	});
	</script>
	<?php 
    html_start_box('<strong>Device Filter</strong>', '100%', $colors['header'], '3', 'center', '');
    ?>
	<tr class='even noprint'>
		<td>
		<form id='form_devices' action='mikrotik.php?action=devices'>
			<table class='filterTable'>
				<tr>
					<td>
						Search
					</td>
					<td>
						<input id='filter' type='text' size='25' value='<?php 
    print get_request_var_request('filter');
    ?>
'>
					</td>
					<td>
						Status
					</td>
					<td>
						<select id='status' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var_request('type') == '-1') {
        ?>
 selected<?php 
    }
    ?>
>All</option>
							<?php 
    $statuses = db_fetch_assoc('SELECT DISTINCT status
								FROM host
								INNER JOIN plugin_mikrotik_system
								ON host.id=plugin_mikrotik_system.host_id');
    $statuses = array_merge($statuses, array('-2' => array('status' => '-2')));
    if (sizeof($statuses)) {
        foreach ($statuses as $s) {
            switch ($s['status']) {
                case '0':
                    $status = 'Unknown';
                    break;
                case '1':
                    $status = 'Down';
                    break;
                case '2':
                    $status = 'Recovering';
                    break;
                case '3':
                    $status = 'Up';
                    break;
                case '-2':
                    $status = 'Disabled';
                    break;
            }
            echo "<option value='" . $s['status'] . "' " . (get_request_var_request('status') == $s['status'] ? 'selected' : '') . '>' . $status . '</option>';
        }
    }
    ?>
						</select>
					</td>
					<td>
						Devices
					</td>
					<td>
						<select id='rows' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var_request('rows') == '-1') {
        ?>
 selected<?php 
    }
    ?>
>Default</option>
							<?php 
    if (sizeof($item_rows)) {
        foreach ($item_rows as $key => $name) {
            echo "<option value='" . $key . "' " . (get_request_var_request('rows') == $key ? 'selected' : '') . '>' . $name . '</option>';
        }
    }
    ?>
						</select>
					</td>
					<td>
						<input id='refresh' type='button' onClick='applyFilter()' value='Go'>
					</td>
					<td>
						<input id='clear' type='button' onClick='clearFilter()' value='Clear'>
					</td>
				</tr>
			</table>
			<input type='hidden' id='page' name='page' value='<?php 
    print $_REQUEST['page'];
    ?>
'>
			</form>
		</td>
	</tr>
	<?php 
    html_end_box();
    html_start_box('', '100%', $colors['header'], '3', 'center', '');
    if ($_REQUEST['rows'] == '-1') {
        $num_rows = read_config_option('num_rows_table');
    } else {
        $num_rows = get_request_var_request('rows');
    }
    $limit = ' LIMIT ' . $num_rows * (get_request_var_request('page') - 1) . ',' . $num_rows;
    $sql_where = '';
    if ($_REQUEST['status'] != '-1') {
        $sql_where .= (strlen($sql_where) ? ' AND' : 'WHERE') . ' hrs.host_status=' . $_REQUEST['status'];
    }
    $sql_join = '';
    if ($_REQUEST['filter'] != '') {
        $sql_where .= (strlen($sql_where) ? ' AND' : 'WHERE') . " h.description LIKE '%" . $_REQUEST['filter'] . "%' OR\n\t\t\th.hostname LIKE '%" . $_REQUEST['filter'] . "%'";
    }
    $sql = "SELECT hrs.*, h.hostname, h.description, h.disabled, trees.trees, queues.queues\n\t\tFROM plugin_mikrotik_system AS hrs\n\t\tINNER JOIN host AS h \n\t\tON h.id=hrs.host_id\n\t\tLEFT JOIN (SELECT host_id AS hid, count(*) AS trees FROM plugin_mikrotik_trees GROUP BY host_id) AS trees\n\t\tON trees.hid=hrs.host_id\n\t\tLEFT JOIN (SELECT host_id AS hid, count(*) AS queues FROM plugin_mikrotik_queues GROUP BY host_id) AS queues\n\t\tON queues.hid=hrs.host_id\n\t\t{$sql_join}\n\t\t{$sql_where}\n\t\tORDER BY " . get_request_var_request("sort_column") . " " . get_request_var_request("sort_direction") . " " . $limit;
    //echo $sql;
    $rows = db_fetch_assoc($sql);
    $total_rows = db_fetch_cell("SELECT COUNT(*)\n\t\tFROM plugin_mikrotik_system AS hrs\n\t\tINNER JOIN host AS h\n\t\tON h.id=hrs.host_id\n\t\t{$sql_join}\n\t\t{$sql_where}");
    $nav = html_nav_bar('mikrotik.php?action=devices', MAX_DISPLAY_PAGES, get_request_var_request('page'), $num_rows, $total_rows, 15, 'Devices', 'page', 'main');
    print $nav;
    $display_text = array('nosort' => array('display' => 'Actions', 'sort' => 'ASC', 'align' => 'left'), 'description' => array('display' => 'Name', 'sort' => 'ASC', 'align' => 'left'), 'host_status' => array('display' => 'Status', 'sort' => 'DESC', 'align' => 'center'), 'firmwareVersion' => array('display' => 'FW Ver', 'sort' => 'DESC', 'align' => 'right'), 'licVersion' => array('display' => 'Lic Ver', 'sort' => 'DESC', 'align' => 'right'), 'uptime' => array('display' => 'Uptime(d:h:m)', 'sort' => 'DESC', 'align' => 'right'), 'trees' => array('display' => 'Trees', 'sort' => 'DESC', 'align' => 'right'), 'users' => array('display' => 'Users', 'sort' => 'DESC', 'align' => 'right'), 'cpuPercent' => array('display' => 'CPU %', 'sort' => 'DESC', 'align' => 'right'), 'numCpus' => array('display' => 'CPUs', 'sort' => 'DESC', 'align' => 'right'), 'processes' => array('display' => 'Processes', 'sort' => 'DESC', 'align' => 'right'), 'memSize' => array('display' => 'Total Mem', 'sort' => 'DESC', 'align' => 'right'), 'memUsed' => array('display' => 'Used Mem', 'sort' => 'DESC', 'align' => 'right'), 'diskSize' => array('display' => 'Total Disk', 'sort' => 'DESC', 'align' => 'right'), 'diskUsed' => array('display' => 'Used Disk', 'sort' => 'DESC', 'align' => 'right'));
    html_header_sort($display_text, get_request_var_request('sort_column'), get_request_var_request('sort_direction'), 'false');
    /* set some defaults */
    $url = $config['url_path'] . 'plugins/mikrotik/mikrotik.php';
    $users = $config['url_path'] . 'plugins/mikrotik/images/view_users.gif';
    $usersn = $config['url_path'] . 'plugins/mikrotik/images/view_users_none.gif';
    $host = $config['url_path'] . 'plugins/mikrotik/images/view_hosts.gif';
    $trees = $config['url_path'] . 'plugins/mikrotik/images/view_trees.gif';
    $treesn = $config['url_path'] . 'plugins/mikrotik/images/view_trees_none.gif';
    $queues = $config['url_path'] . 'plugins/mikrotik/images/view_queues.gif';
    $queuesn = $config['url_path'] . 'plugins/mikrotik/images/view_queues_none.gif';
    $interfaces = $config['url_path'] . 'plugins/mikrotik/images/view_interfaces.gif';
    $dashboard = $config['url_path'] . 'plugins/mikrotik/images/view_dashboard.gif';
    $graphs = $config['url_path'] . 'plugins/mikrotik/images/view_graphs.gif';
    $nographs = $config['url_path'] . 'plugins/mikrotik/images/view_graphs_disabled.gif';
    $hcpudq = read_config_option('mikrotik_dq_host_cpu');
    if (sizeof($rows)) {
        foreach ($rows as $row) {
            $days = intval($row['uptime'] / (60 * 60 * 24 * 100));
            $remainder = $row['uptime'] % (60 * 60 * 24 * 100);
            $hours = intval($remainder / (60 * 60 * 100));
            $remainder = $remainder % (60 * 60 * 100);
            $minutes = intval($remainder / (60 * 100));
            $found = db_fetch_cell('SELECT COUNT(*) FROM graph_local WHERE host_id=' . $row['host_id']);
            form_alternate_row();
            echo "<td style='white-space:nowrap;min-width:115px;text-align:left;'>";
            //echo "<a style='padding:1px;' href='" . htmlspecialchars("$url?action=dashboard&reset=1&device=" . $row["host_id"]) . "'><img src='$dashboard' title='View Dashboard' align='absmiddle' border='0'></a>";
            if ($row['users'] > 0) {
                echo "<a class='hyperLink' href='" . htmlspecialchars("{$url}?action=users&reset=1&device=" . $row['host_id']) . "'><img src='{$users}' title='View Users' align='absmiddle' border='0' alt=''></a>";
            } else {
                echo "<img style='border:0px;padding:3px;' src='{$usersn}' title='No Users Found' align='absmiddle' alt=''>";
            }
            if ($row['queues'] > 0) {
                echo "<a class='hyperLink' href='" . htmlspecialchars("{$url}?action=queues&reset=1&device=" . $row['host_id']) . "'><img src='{$queues}' title='View Simple Queue' align='absmiddle' border='0' alt=''></a>";
            } else {
                echo "<img style='border:0px;padding:3px;' src='{$queuesn}' title='No Simple Queues Found' align='absmiddle' alt=''>";
            }
            if ($row['trees'] > 0) {
                echo "<a class='hyperLink' href='" . htmlspecialchars("{$url}?action=trees&reset=1&device=" . $row['host_id']) . "'><img src='{$trees}' title='View Queue Trees' align='absmiddle' border='0' alt=''></a>";
            } else {
                echo "<img style='border:0px;padding:3px;' src='{$treesn}' title='No Queue Trees Found' align='absmiddle' alt=''>";
            }
            echo "<a class='hyperLink' href='" . htmlspecialchars("{$url}?action=interfaces&reset=1&device=" . $row['host_id']) . "'><img src='{$interfaces}' title='View Interfaces' align='absmiddle' border='0' alt=''></a>";
            if ($found) {
                echo "<a class='hyperLink' href='" . htmlspecialchars("{$url}?action=graphs&reset=1&host_id=" . $row['host_id'] . "&style=selective&graph_add=&graph_list=&graph_template_id=0&filter=") . "'><img  src='{$graphs}' title='View Graphs' align='absmiddle' border='0' alt=''></a>";
            } else {
                echo "<img src='{$nographs}' title='No Graphs Defined' align='absmiddle' border='0'>";
            }
            $graph_cpu = mikrotik_get_graph_url($hcpudq, $row['host_id'], '', $row['numCpus'], false);
            $graph_cpup = mikrotik_get_graph_template_url(mikrotik_template_by_hash('7df474393f58bae8e8d6b85f10efad71'), $row['host_id'], round($row['cpuPercent'], 2), false);
            $graph_users = mikrotik_get_graph_template_url(mikrotik_template_by_hash('99e37ff13139f586d257ba9a637d7340'), $row['host_id'], empty($rows['users']) ? '-' : $row['users'], false);
            $graph_aproc = mikrotik_get_graph_template_url(mikrotik_template_by_hash('e797d967db24fd86341a8aa8c60fa9e0'), $row['host_id'], $row['host_status'] < 2 ? 'N/A' : $row['processes'], false);
            $graph_disk = mikrotik_get_graph_template_url(mikrotik_template_by_hash('0ece13b90785aa04d1f554a093685948'), $row['host_id'], $row['host_status'] < 2 ? 'N/A' : round($row['diskUsed'], 2), false);
            $graph_mem = mikrotik_get_graph_template_url(mikrotik_template_by_hash('4396ae857c4f9bc5ed1f26b5361e42d9'), $row['host_id'], $row['host_status'] < 2 ? 'N/A' : round($row['memUsed'], 2), false);
            $graph_upt = mikrotik_get_graph_template_url(mikrotik_template_by_hash('7d8dc3050621a2cb937cac3895bc5d5b'), $row['host_id'], $row['host_status'] < 2 ? 'N/A' : mikrotik_format_uptime($days, $hours, $minutes), false);
            if (api_plugin_user_realm_auth('host.php')) {
                $host_url = "<a class='hyperLink' href='" . htmlspecialchars($config['url_path'] . 'host.php?action=edit&id=' . $row['host_id']) . "' title='Edit Hosts'>" . $row['hostname'] . '</a>';
            } else {
                $host_url = $row['hostname'];
            }
            echo '</td>';
            echo "<td style='text-align:left;white-space:nowrap;'><strong>" . (strlen($_REQUEST['filter']) ? preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", $row['description'] . '</strong> [' . $host_url . ']') : $row['description'] . '</strong> [' . $host_url . ']') . '</td>';
            echo "<td style='text-align:center;'>" . get_colored_device_status($row['disabled'] == 'on' ? true : false, $row['host_status']) . '</td>';
            echo "<td style='text-align:right;'>" . $row['firmwareVersion'] . '</td>';
            echo "<td style='text-align:right;'>" . $row['licVersion'] . '</td>';
            echo "<td style='text-align:right;'>" . $graph_upt . '</td>';
            echo "<td style='text-align:right;'>" . (!empty($row['trees']) ? $row['trees'] : '-') . '</td>';
            echo "<td style='text-align:right;'>" . $graph_users . '</td>';
            echo "<td style='text-align:right;'>" . ($row['host_status'] < 2 ? 'N/A' : $graph_cpup) . '</td>';
            echo "<td style='text-align:right;'>" . ($row['host_status'] < 2 ? 'N/A' : $graph_cpu) . '</td>';
            echo "<td style='text-align:right;'>" . $graph_aproc . '</td>';
            echo "<td style='text-align:right;'>" . mikrotik_memory($row['memSize']) . '</td>';
            echo "<td style='text-align:right;'>" . $graph_mem . ' %</td>';
            echo "<td style='text-align:right;'>" . mikrotik_memory($row['diskSize']) . '</td>';
            echo "<td style='text-align:right;'>" . $graph_disk . ' %</td>';
            form_end_row();
        }
        print $nav;
    } else {
        print '<tr><td colspan="5"><em>No Devices Found</em></td></tr>';
    }
    html_end_box();
}
Ejemplo n.º 2
0
function mikrotik_view_graphs()
{
    global $current_user, $colors, $config;
    if (file_exists("./lib/timespan_settings.php")) {
        include "./lib/timespan_settings.php";
    } else {
        include "./include/html/inc_timespan_settings.php";
    }
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var("rra_id"));
    input_validate_input_number(get_request_var("host"));
    input_validate_input_number(get_request_var("cols"));
    input_validate_input_regex(get_request_var_request('graph_list'), "^([\\,0-9]+)\$");
    input_validate_input_regex(get_request_var_request('graph_add'), "^([\\,0-9]+)\$");
    input_validate_input_regex(get_request_var_request('graph_remove'), "^([\\,0-9]+)\$");
    /* ==================================================== */
    define("ROWS_PER_PAGE", read_graph_config_option("preview_graphs_per_page"));
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("graph_template_id"));
    input_validate_input_number(get_request_var_request("page"));
    /* ==================================================== */
    /* clean up search string */
    if (isset($_REQUEST["filter"])) {
        $_REQUEST["filter"] = sanitize_search_string(get_request_var_request("filter"));
    }
    /* clean up styl string */
    if (isset($_REQUEST["style"])) {
        $_REQUEST["style"] = sanitize_search_string(get_request_var_request("style"));
    }
    /* clean up styl string */
    if (isset($_REQUEST["thumb"])) {
        $_REQUEST["thumb"] = sanitize_search_string(get_request_var_request("thumb"));
    }
    $sql_or = "";
    $sql_where = "";
    $sql_join = "";
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST["reset"])) {
        kill_session_var("sess_mikrotik_graph_current_page");
        kill_session_var("sess_mikrotik_graph_filter");
        kill_session_var("sess_mikrotik_graph_host");
        kill_session_var("sess_mikrotik_graph_cols");
        kill_session_var("sess_mikrotik_graph_thumb");
        kill_session_var("sess_mikrotik_graph_add");
        kill_session_var("sess_mikrotik_graph_style");
        kill_session_var("sess_mikrotik_graph_graph_template");
    } elseif (isset($_REQUEST["clear"])) {
        kill_session_var("sess_mikrotik_graph_current_page");
        kill_session_var("sess_mikrotik_graph_filter");
        kill_session_var("sess_mikrotik_graph_host");
        kill_session_var("sess_mikrotik_graph_cols");
        kill_session_var("sess_mikrotik_graph_thumb");
        kill_session_var("sess_mikrotik_graph_add");
        kill_session_var("sess_mikrotik_graph_style");
        kill_session_var("sess_mikrotik_graph_graph_template");
        unset($_REQUEST["page"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["host"]);
        unset($_REQUEST["cols"]);
        unset($_REQUEST["thumb"]);
        unset($_REQUEST["graph_template_id"]);
        unset($_REQUEST["graph_list"]);
        unset($_REQUEST["graph_add"]);
        unset($_REQUEST["style"]);
        unset($_REQUEST["graph_remove"]);
    } else {
        /* if any of the settings changed, reset the page number */
        $changed = false;
        $changed += mikrotik_check_changed("fitler", "sess_mikrotik_graph_filter");
        $changed += mikrotik_check_changed("host", "sess_mikrotik_graph_host");
        $changed += mikrotik_check_changed("style", "sess_mikrotik_graph_style");
        $changed += mikrotik_check_changed("graph_add", "sess_mikrotik_graph_add");
        $changed += mikrotik_check_changed("graph_template_id", "sess_mikrotik_graph_graph_template");
        if ($changed) {
            $_REQUEST["page"] = "1";
            $_REQUEST["style"] = "";
            $_REQUEST["graph_add"] = "";
        }
    }
    load_current_session_value("graph_template_id", "sess_mikrotik_graph_graph_template", "0");
    load_current_session_value("host", "sess_mikrotik_graph_host", "0");
    load_current_session_value("cols", "sess_mikrotik_graph_cols", "2");
    load_current_session_value("thumb", "sess_mikrotik_graph_thumb", "true");
    load_current_session_value("graph_add", "sess_mikrotik_graph_add", "");
    load_current_session_value("style", "sess_mikrotik_graph_style", "");
    load_current_session_value("filter", "sess_mikrotik_graph_filter", "");
    load_current_session_value("page", "sess_mikrotik_graph_current_page", "1");
    if ($_REQUEST["graph_add"] != "") {
        $_REQUEST["style"] = "selective";
    }
    /* graph permissions */
    if (read_config_option("auth_method") != 0) {
        $sql_where = "WHERE " . get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]);
        $sql_join = "LEFT JOIN host ON (host.id=graph_local.host_id)\n\t\t\tLEFT JOIN graph_templates\n\t\t\tON (graph_templates.id=graph_local.graph_template_id)\n\t\t\tLEFT JOIN user_auth_perms\n\t\t\tON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id\n\t\t\tAND user_auth_perms.type=1\n\t\t\tAND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ")\n\t\t\tOR (host.id=user_auth_perms.item_id AND user_auth_perms.type=3 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ")\n\t\t\tOR (graph_templates.id=user_auth_perms.item_id AND user_auth_perms.type=4 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))";
    } else {
        $sql_where = "";
        $sql_join = "";
    }
    /* the user select a bunch of graphs of the 'list' view and wants them dsplayed here */
    if (isset($_REQUEST["style"])) {
        if ($_REQUEST["style"] == "selective") {
            /* process selected graphs */
            if (!empty($_REQUEST["graph_list"])) {
                foreach (explode(",", $_REQUEST["graph_list"]) as $item) {
                    $graph_list[$item] = 1;
                }
            } else {
                $graph_list = array();
            }
            if (!empty($_REQUEST["graph_add"])) {
                foreach (explode(",", $_REQUEST["graph_add"]) as $item) {
                    $graph_list[$item] = 1;
                }
            }
            /* remove items */
            if (!empty($_REQUEST["graph_remove"])) {
                foreach (explode(",", $_REQUEST["graph_remove"]) as $item) {
                    unset($graph_list[$item]);
                }
            }
            $i = 0;
            foreach ($graph_list as $item => $value) {
                $graph_array[$i] = $item;
                $i++;
            }
            if (isset($graph_array) && sizeof($graph_array) > 0) {
                /* build sql string including each graph the user checked */
                $sql_or = "AND " . array_to_sql_or($graph_array, "graph_templates_graph.local_graph_id");
                /* clear the filter vars so they don't affect our results */
                $_REQUEST["filter"] = "";
                $set_rra_id = empty($rra_id) ? read_graph_config_option("default_rra_id") : $_REQUEST["rra_id"];
            }
        }
    }
    $sql_base = "FROM (graph_templates_graph,graph_local)\n\t\t{$sql_join}\n\t\t{$sql_where}\n\t\t" . (empty($sql_where) ? "WHERE" : "AND") . "   graph_templates_graph.local_graph_id > 0\n\t\tAND graph_templates_graph.local_graph_id=graph_local.id\n\t\t" . (strlen($_REQUEST["filter"]) ? "AND graph_templates_graph.title_cache like '%%" . $_REQUEST["filter"] . "%%'" : "") . "\n\t\t" . (empty($_REQUEST["graph_template_id"]) ? "" : " and graph_local.graph_template_id=" . $_REQUEST["graph_template_id"]) . "\n\t\t" . (empty($_REQUEST["host"]) ? "" : " and graph_local.host_id=" . $_REQUEST["host"]) . "\n\t\t{$sql_or}";
    $total_rows = count(db_fetch_assoc("SELECT\n\t\tgraph_templates_graph.local_graph_id\n\t\t{$sql_base}"));
    /* reset the page if you have changed some settings */
    if (ROWS_PER_PAGE * ($_REQUEST["page"] - 1) >= $total_rows) {
        $_REQUEST["page"] = "1";
    }
    $graphs = db_fetch_assoc("SELECT\n\t\tgraph_templates_graph.local_graph_id,\n\t\tgraph_templates_graph.title_cache\n\t\t{$sql_base}\n\t\tGROUP BY graph_templates_graph.local_graph_id\n\t\tORDER BY graph_templates_graph.title_cache\n\t\tLIMIT " . ROWS_PER_PAGE * ($_REQUEST["page"] - 1) . "," . ROWS_PER_PAGE);
    ?>
	<script type="text/javascript">
	<!--
	function applyGraphWReset(objForm) {
		strURL = '?action=graphs&reset=1&graph_template_id=' + objForm.graph_template_id.value;
		strURL = strURL + '&host=' + objForm.host.value;
		strURL = strURL + '&cols=' + objForm.cols.value;
		strURL = strURL + '&thumb=' + objForm.thumb.checked;
		strURL = strURL + '&filter=' + objForm.filter.value;
		document.location = strURL;
	}
	function applyGraphWOReset(objForm) {
		strURL = '?action=graphs&graph_template_id=' + objForm.graph_template_id.value;
		strURL = strURL + '&host=' + objForm.host.value;
		strURL = strURL + '&cols=' + objForm.cols.value;
		strURL = strURL + '&thumb=' + objForm.thumb.checked;
		strURL = strURL + '&filter=' + objForm.filter.value;
		document.location = strURL;
	}
	-->
	</script>
	<?php 
    html_start_box("<strong>Host MIB Graphs" . ($_REQUEST["style"] == "selective" ? " (Custom Selective Filter)" : "") . "</strong>", "100%", $colors["header"], "1", "center", "");
    mikrotik_graph_view_filter();
    /* include time span selector */
    if (read_graph_config_option("timespan_sel") == "on") {
        mikrotik_timespan_selector();
    }
    html_end_box();
    /* do some fancy navigation url construction so we don't have to try and rebuild the url string */
    if (ereg("page=[0-9]+", basename($_SERVER["QUERY_STRING"]))) {
        $nav_url = str_replace("page=" . $_REQUEST["page"], "page=<PAGE>", basename($_SERVER["PHP_SELF"]) . "?" . $_SERVER["QUERY_STRING"]);
    } else {
        $nav_url = basename($_SERVER["PHP_SELF"]) . "?" . $_SERVER["QUERY_STRING"] . "&page=<PAGE>";
    }
    $nav_url = ereg_replace("((\\?|&)filter=[a-zA-Z0-9]*)", "", $nav_url);
    html_start_box("", "100%", $colors["header"], "3", "center", "");
    mikrotik_nav_bar($_REQUEST["page"], ROWS_PER_PAGE, $total_rows, $nav_url);
    mikrotik_graph_area($graphs, "", "graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end(), "", $_REQUEST["cols"], $_REQUEST["thumb"]);
    if ($total_rows) {
        mikrotik_nav_bar($_REQUEST["page"], ROWS_PER_PAGE, $total_rows, $nav_url);
    }
    html_end_box();
}