Esempio n. 1
0
function utilities_view_logfile()
{
    global $log_tail_lines, $page_refresh_interval, $refresh;
    $logfile = read_config_option('path_cactilog');
    if ($logfile == '') {
        $logfile = './log/rrd.log';
    }
    /* helps determine output color */
    $linecolor = True;
    input_validate_input_number(get_request_var_request('tail_files'));
    input_validate_input_number(get_request_var_request('message_type'));
    input_validate_input_number(get_request_var_request('refresh'));
    input_validate_input_number(get_request_var_request('reverse'));
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST['clear_x'])) {
        kill_session_var('sess_logfile_tail_lines');
        kill_session_var('sess_logfile_message_type');
        kill_session_var('sess_logfile_filter');
        kill_session_var('sess_logfile_refresh');
        kill_session_var('sess_logfile_reverse');
        unset($_REQUEST['tail_lines']);
        unset($_REQUEST['message_type']);
        unset($_REQUEST['filter']);
        unset($_REQUEST['refresh']);
        unset($_REQUEST['reverse']);
    }
    load_current_session_value('tail_lines', 'sess_logfile_tail_lines', read_config_option('num_rows_log'));
    load_current_session_value('message_type', 'sess_logfile_message_type', '-1');
    load_current_session_value('filter', 'sess_logfile_filter', '');
    load_current_session_value('refresh', 'sess_logfile_refresh', read_config_option('log_refresh_interval'));
    load_current_session_value('reverse', 'sess_logfile_reverse', 1);
    load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table'));
    $_REQUEST['page_referrer'] = 'view_logfile';
    load_current_session_value('page_referrer', 'page_referrer', 'view_logfile');
    $refresh['seconds'] = get_request_var_request('refresh');
    $refresh['page'] = 'utilities.php?action=view_logfile';
    top_header();
    ?>
	<script type="text/javascript">
	<!--

	function purgeLog() {
		strURL = '?action=view_logfile&purge_x=1&header=false';
		$.get(strURL, function(data) {
			$('#main').html(data);
			applySkin();
		});
	}

	$(function() {
		$('#refreshme').click(function() {
			applyFilter();
		});

		$('#clear').click(function() {
			clearFilter();
		});

		$('#purge').click(function() {
			purgeLog();
		});

		$('#form_logfile').submit(function(event) {
			event.preventDefault();
			applyFilter();
		});
	});

	function applyFilter() {
		strURL = '?tail_lines=' + $('#tail_lines').val();
		strURL = strURL + '&message_type=' + $('#message_type').val();
		strURL = strURL + '&refresh=' + $('#refresh').val();
		strURL = strURL + '&reverse=' + $('#reverse').val();
		strURL = strURL + '&filter=' + $('#filter').val();
		strURL = strURL + '&action=view_logfile';
		strURL = strURL + '&header=false';
		refreshMSeconds=$('#refresh').val()*1000;
		$.get(strURL, function(data) {
			$('#main').html(data);
			applySkin();
		});
	}

	function clearFilter() {
		strURL = '?clear_x=1';
		strURL = strURL + '&action=view_logfile';
		strURL = strURL + '&header=false';
		$.get(strURL, function(data) {
			$('#main').html(data);
			applySkin();
		});
	}

	-->
	</script>
	<?php 
    html_start_box('<strong>Log File Filters</strong>', '100%', '', '3', 'center', '');
    ?>
	<tr class='even noprint'>
		<td>
		<form id="form_logfile" action="utilities.php">
			<table cellpadding="2" cellspacing="0" border="0">
				<tr>
					<td style='white-space: nowrap;' width="80">
						Tail Lines
					</td>
					<td>
						<select id='tail_lines' name="tail_lines" onChange="applyFilter()">
							<?php 
    foreach ($log_tail_lines as $tail_lines => $display_text) {
        print "<option value='" . $tail_lines . "'";
        if (get_request_var_request('tail_lines') == $tail_lines) {
            print ' selected';
        }
        print '>' . $display_text . "</option>\n";
    }
    ?>
						</select>
					</td>
					<td style='white-space: nowrap;'>
						Message Type
					</td>
					<td>
						<select id='message_type' name="message_type" onChange="applyFilter()">
							<option value="-1"<?php 
    if (get_request_var_request('message_type') == '-1') {
        ?>
 selected<?php 
    }
    ?>
>All</option>
							<option value="1"<?php 
    if (get_request_var_request('message_type') == '1') {
        ?>
 selected<?php 
    }
    ?>
>Stats</option>
							<option value="2"<?php 
    if (get_request_var_request('message_type') == '2') {
        ?>
 selected<?php 
    }
    ?>
>Warnings</option>
							<option value="3"<?php 
    if (get_request_var_request('message_type') == '3') {
        ?>
 selected<?php 
    }
    ?>
>Errors</option>
							<option value="4"<?php 
    if (get_request_var_request('message_type') == '4') {
        ?>
 selected<?php 
    }
    ?>
>Debug</option>
							<option value="5"<?php 
    if (get_request_var_request('message_type') == '5') {
        ?>
 selected<?php 
    }
    ?>
>SQL Calls</option>
						</select>
					</td>
					<td>
						<input type="button" id='refreshme' name="go" value="Go" title="Set/Refresh Filters">
					</td>
					<td>
						<input type="button" id='clear' name="clear_x" value="Clear" title="Clear Filters">
					</td>
					<td>
						<input type="button" id='purge' name="purge_x" value="Purge" title="Purge Log File">
					</td>
				</tr>
				<tr>
					<td>
						Refresh
					</td>
					<td>
						<select id='refresh' name="refresh" onChange="applyFilter()">
							<?php 
    foreach ($page_refresh_interval as $seconds => $display_text) {
        print "<option value='" . $seconds . "'";
        if (get_request_var_request('refresh') == $seconds) {
            print ' selected';
        }
        print '>' . $display_text . "</option>\n";
    }
    ?>
						</select>
					</td>
					<td style='white-space: nowrap;'>
						Display Order
					</td>
					<td>
						<select id='reverse' name="reverse" onChange="applyFilter()">
							<option value="1"<?php 
    if (get_request_var_request('reverse') == '1') {
        ?>
 selected<?php 
    }
    ?>
>Newest First</option>
							<option value="2"<?php 
    if (get_request_var_request('reverse') == '2') {
        ?>
 selected<?php 
    }
    ?>
>Oldest First</option>
						</select>
					</td>
				</tr>
			</table>
			<table cellpadding="2" cellspacing="0" border="0">
				<tr>
					<td width="80">
						Search
					</td>
					<td>
						<input id='filter' type="text" name="filter" size="75" value="<?php 
    print htmlspecialchars(get_request_var_request('filter'));
    ?>
">
					</td>
				</tr>
			</table>
			<input type='hidden' name='action' value='view_logfile'>
		</form>
		</td>
	</tr>
	<?php 
    html_end_box();
    /* read logfile into an array and display */
    $logcontents = tail_file($logfile, get_request_var_request('tail_lines'), get_request_var_request('message_type'), get_request_var_request('filter'));
    if (get_request_var_request('reverse') == 1) {
        $logcontents = array_reverse($logcontents);
    }
    if (get_request_var_request('message_type') > 0) {
        $start_string = '<strong>Log File</strong> [Total Lines: ' . sizeof($logcontents) . ' - Non-Matching Items Hidden]';
    } else {
        $start_string = '<strong>Log File</strong> [Total Lines: ' . sizeof($logcontents) . ' - All Items Shown]';
    }
    html_start_box($start_string, '100%', '', '3', 'center', '');
    $i = 0;
    $j = 0;
    $linecolor = false;
    foreach ($logcontents as $item) {
        $host_start = strpos($item, 'Device[');
        $ds_start = strpos($item, 'DS[');
        $new_item = '';
        if (!$host_start && !$ds_start) {
            $new_item = $item;
        } else {
            while ($host_start) {
                $host_end = strpos($item, ']', $host_start);
                $host_id = substr($item, $host_start + 5, $host_end - ($host_start + 5));
                $new_item = $new_item . substr($item, 0, $host_start + 5) . "<a href='" . htmlspecialchars('host.php?action=edit&id=' . $host_id) . "'>" . substr($item, $host_start + 5, $host_end - ($host_start + 5)) . '</a>';
                $item = substr($item, $host_end);
                $host_start = strpos($item, 'Device[');
            }
            $ds_start = strpos($item, 'DS[');
            while ($ds_start) {
                $ds_end = strpos($item, ']', $ds_start);
                $ds_id = substr($item, $ds_start + 3, $ds_end - ($ds_start + 3));
                $new_item = $new_item . substr($item, 0, $ds_start + 3) . "<a href='" . htmlspecialchars('data_sources.php?action=ds_edit&id=' . $ds_id) . "'>" . substr($item, $ds_start + 3, $ds_end - ($ds_start + 3)) . '</a>';
                $item = substr($item, $ds_end);
                $ds_start = strpos($item, 'DS[');
            }
            $new_item = $new_item . $item;
        }
        /* get the background color */
        if (substr_count($new_item, 'ERROR') || substr_count($new_item, 'FATAL')) {
            $bgcolor = 'FF3932';
        } elseif (substr_count($new_item, 'WARN')) {
            $bgcolor = 'EACC00';
        } elseif (substr_count($new_item, ' SQL ')) {
            $bgcolor = '6DC8FE';
        } elseif (substr_count($new_item, 'DEBUG')) {
            $bgcolor = 'C4FD3D';
        } elseif (substr_count($new_item, 'STATS')) {
            $bgcolor = '96E78A';
        } else {
            if ($linecolor) {
                $bgcolor = 'CCCCCC';
            } else {
                $bgcolor = 'FFFFFF';
            }
            $linecolor = !$linecolor;
        }
        ?>
		<tr bgcolor='#<?php 
        print $bgcolor;
        ?>
'>
			<td>
				<?php 
        print $new_item;
        ?>
			</td>
		</tr>
		<?php 
        $j++;
        $i++;
        if ($j > 1000) {
            ?>
			<tr bgcolor='#EACC00'>
				<td>
					<?php 
            print '>>>>  LINE LIMIT OF 1000 LINES REACHED!!  <<<<';
            ?>
				</td>
			</tr>
			<?php 
            break;
        }
    }
    html_end_box();
    bottom_footer();
}
Esempio n. 2
0
function utilities_view_logfile()
{
    global $log_tail_lines, $page_refresh_interval, $refresh;
    $logfile = read_config_option("path_cactilog");
    if ($logfile == "") {
        $logfile = "./log/rrd.log";
    }
    /* helps determine output color */
    $linecolor = True;
    input_validate_input_number(get_request_var_request("tail_files"));
    input_validate_input_number(get_request_var_request("message_type"));
    input_validate_input_number(get_request_var_request("refresh"));
    input_validate_input_number(get_request_var_request("reverse"));
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST["clear_x"])) {
        kill_session_var("sess_logfile_tail_lines");
        kill_session_var("sess_logfile_message_type");
        kill_session_var("sess_logfile_filter");
        kill_session_var("sess_logfile_refresh");
        kill_session_var("sess_logfile_reverse");
        unset($_REQUEST["tail_lines"]);
        unset($_REQUEST["message_type"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["refresh"]);
        unset($_REQUEST["reverse"]);
    }
    load_current_session_value("tail_lines", "sess_logfile_tail_lines", read_config_option("num_rows_log"));
    load_current_session_value("message_type", "sess_logfile_message_type", "-1");
    load_current_session_value("filter", "sess_logfile_filter", "");
    load_current_session_value("refresh", "sess_logfile_refresh", read_config_option("log_refresh_interval"));
    load_current_session_value("reverse", "sess_logfile_reverse", 1);
    $_REQUEST['page_referrer'] = 'view_logfile';
    load_current_session_value('page_referrer', 'page_referrer', 'view_logfile');
    $refresh["seconds"] = get_request_var_request("refresh");
    $refresh["page"] = "utilities.php?action=view_logfile";
    include_once "./include/top_header.php";
    ?>
	<script type="text/javascript">
	<!--

	function applyViewLogFilterChange(objForm) {
		strURL = '?tail_lines=' + objForm.tail_lines.value;
		strURL = strURL + '&message_type=' + objForm.message_type.value;
		strURL = strURL + '&refresh=' + objForm.refresh.value;
		strURL = strURL + '&reverse=' + objForm.reverse.value;
		strURL = strURL + '&filter=' + objForm.filter.value;
		strURL = strURL + '&action=view_logfile';
		document.location = strURL;
	}

	-->
	</script>
	<?php 
    html_start_box("<strong>Log File Filters</strong>", "100%", "", "3", "center", "");
    ?>
	<tr class='even noprint'>
		<td>
		<form name="form_logfile" action="utilities.php">
			<table cellpadding="1" cellspacing="0">
				<tr>
					<td nowrap style='white-space: nowrap;' width="80">
						Tail Lines:&nbsp;
					</td>
					<td width="1">
						<select name="tail_lines" onChange="applyViewLogFilterChange(document.form_logfile)">
							<?php 
    foreach ($log_tail_lines as $tail_lines => $display_text) {
        print "<option value='" . $tail_lines . "'";
        if (get_request_var_request("tail_lines") == $tail_lines) {
            print " selected";
        }
        print ">" . $display_text . "</option>\n";
    }
    ?>
						</select>
					</td>
					<td nowrap style='white-space: nowrap;' width="100">
						&nbsp;Message Type:&nbsp;
					</td>
					<td width="1">
						<select name="message_type" onChange="applyViewLogFilterChange(document.form_logfile)">
							<option value="-1"<?php 
    if (get_request_var_request("message_type") == '-1') {
        ?>
 selected<?php 
    }
    ?>
>All</option>
							<option value="1"<?php 
    if (get_request_var_request("message_type") == '1') {
        ?>
 selected<?php 
    }
    ?>
>Stats</option>
							<option value="2"<?php 
    if (get_request_var_request("message_type") == '2') {
        ?>
 selected<?php 
    }
    ?>
>Warnings</option>
							<option value="3"<?php 
    if (get_request_var_request("message_type") == '3') {
        ?>
 selected<?php 
    }
    ?>
>Errors</option>
							<option value="4"<?php 
    if (get_request_var_request("message_type") == '4') {
        ?>
 selected<?php 
    }
    ?>
>Debug</option>
							<option value="5"<?php 
    if (get_request_var_request("message_type") == '5') {
        ?>
 selected<?php 
    }
    ?>
>SQL Calls</option>
						</select>
					</td>
					<td nowrap style='white-space: nowrap;'>
						&nbsp;<input type="submit" name="go" value="Go" title="Set/Refresh Filters">
						<input type="submit" name="clear_x" value="Clear" title="Clear Filters">
						<input type="submit" name="purge_x" value="Purge" title="Purge Log File">
					</td>
				</tr>
				<tr>
					<td nowrap style='white-space: nowrap;' width="80">
						Refresh:&nbsp;
					</td>
					<td width="1">
						<select name="refresh" onChange="applyViewLogFilterChange(document.form_logfile)">
							<?php 
    foreach ($page_refresh_interval as $seconds => $display_text) {
        print "<option value='" . $seconds . "'";
        if (get_request_var_request("refresh") == $seconds) {
            print " selected";
        }
        print ">" . $display_text . "</option>\n";
    }
    ?>
						</select>
					</td>
					<td nowrap style='white-space: nowrap;' width="100">
						&nbsp;Display Order:&nbsp;
					</td>
					<td width="1">
						<select name="reverse" onChange="applyViewLogFilterChange(document.form_logfile)">
							<option value="1"<?php 
    if (get_request_var_request("reverse") == '1') {
        ?>
 selected<?php 
    }
    ?>
>Newest First</option>
							<option value="2"<?php 
    if (get_request_var_request("reverse") == '2') {
        ?>
 selected<?php 
    }
    ?>
>Oldest First</option>
						</select>
					</td>
				</tr>
			</table>
			<table cellpadding="1" cellspacing="0">
				<tr>
					<td nowrap style='white-space: nowrap;' width="80">
						Search:&nbsp;
					</td>
					<td width="1">
						<input type="text" name="filter" size="75" value="<?php 
    print htmlspecialchars(get_request_var_request("filter"));
    ?>
">
					</td>
				</tr>
			</table>
			<input type='hidden' name='page' value='1'>
			<input type='hidden' name='action' value='view_logfile'>
		</form>
		</td>
	</tr>
	<?php 
    html_end_box();
    /* read logfile into an array and display */
    $logcontents = tail_file($logfile, get_request_var_request("tail_lines"), get_request_var_request("message_type"), get_request_var_request("filter"));
    if (get_request_var_request("reverse") == 1) {
        $logcontents = array_reverse($logcontents);
    }
    if (get_request_var_request("message_type") > 0) {
        $start_string = "<strong>Log File</strong> [Total Lines: " . sizeof($logcontents) . " - Non-Matching Items Hidden]";
    } else {
        $start_string = "<strong>Log File</strong> [Total Lines: " . sizeof($logcontents) . " - All Items Shown]";
    }
    html_start_box($start_string, "100%", "", "3", "center", "");
    $i = 0;
    $j = 0;
    $linecolor = false;
    foreach ($logcontents as $item) {
        $host_start = strpos($item, "Host[");
        $ds_start = strpos($item, "DS[");
        $new_item = "";
        if (!$host_start && !$ds_start) {
            $new_item = $item;
        } else {
            while ($host_start) {
                $host_end = strpos($item, "]", $host_start);
                $host_id = substr($item, $host_start + 5, $host_end - ($host_start + 5));
                $new_item = $new_item . substr($item, 0, $host_start + 5) . "<a href='" . htmlspecialchars("host.php?action=edit&id=" . $host_id) . "'>" . substr($item, $host_start + 5, $host_end - ($host_start + 5)) . "</a>";
                $item = substr($item, $host_end);
                $host_start = strpos($item, "Host[");
            }
            $ds_start = strpos($item, "DS[");
            while ($ds_start) {
                $ds_end = strpos($item, "]", $ds_start);
                $ds_id = substr($item, $ds_start + 3, $ds_end - ($ds_start + 3));
                $new_item = $new_item . substr($item, 0, $ds_start + 3) . "<a href='" . htmlspecialchars("data_sources.php?action=ds_edit&id=" . $ds_id) . "'>" . substr($item, $ds_start + 3, $ds_end - ($ds_start + 3)) . "</a>";
                $item = substr($item, $ds_end);
                $ds_start = strpos($item, "DS[");
            }
            $new_item = $new_item . $item;
        }
        /* get the background color */
        if (substr_count($new_item, "ERROR") || substr_count($new_item, "FATAL")) {
            $bgcolor = "FF3932";
        } elseif (substr_count($new_item, "WARN")) {
            $bgcolor = "EACC00";
        } elseif (substr_count($new_item, " SQL ")) {
            $bgcolor = "6DC8FE";
        } elseif (substr_count($new_item, "DEBUG")) {
            $bgcolor = "C4FD3D";
        } elseif (substr_count($new_item, "STATS")) {
            $bgcolor = "96E78A";
        } else {
            if ($linecolor) {
                $bgcolor = "CCCCCC";
            } else {
                $bgcolor = "FFFFFF";
            }
            $linecolor = !$linecolor;
        }
        ?>
		<tr bgcolor='#<?php 
        print $bgcolor;
        ?>
'>
			<td>
				<?php 
        print $new_item;
        ?>
			</td>
		</tr>
		<?php 
        $j++;
        $i++;
        if ($j > 1000) {
            ?>
			<tr bgcolor='#EACC00'>
				<td>
					<?php 
            print ">>>>  LINE LIMIT OF 1000 LINES REACHED!!  <<<<";
            ?>
				</td>
			</tr>
			<?php 
            break;
        }
    }
    html_end_box();
    include_once "./include/bottom_footer.php";
}
Esempio n. 3
0
function utilities_view_logfile()
{
    global $colors, $log_tail_lines, $page_refresh_interval;
    $logfile = read_config_option("path_cactilog");
    if ($logfile == "") {
        $logfile = "./log/rrd.log";
    }
    /* helps determine output color */
    $linecolor = True;
    input_validate_input_number(get_request_var_request("tail_files"));
    input_validate_input_number(get_request_var_request("message_type"));
    input_validate_input_number(get_request_var_request("refresh"));
    input_validate_input_number(get_request_var_request("reverse"));
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST["clear_x"])) {
        kill_session_var("sess_logfile_tail_lines");
        kill_session_var("sess_logfile_message_type");
        kill_session_var("sess_logfile_filter");
        kill_session_var("sess_logfile_refresh");
        kill_session_var("sess_logfile_reverse");
        unset($_REQUEST["tail_lines"]);
        unset($_REQUEST["message_type"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["refresh"]);
        unset($_REQUEST["reverse"]);
    }
    load_current_session_value("tail_lines", "sess_logfile_tail_lines", read_config_option("num_rows_log"));
    load_current_session_value("message_type", "sess_logfile_message_type", "-1");
    load_current_session_value("filter", "sess_logfile_filter", "");
    load_current_session_value("refresh", "sess_logfile_refresh", read_config_option("log_refresh_interval"));
    load_current_session_value("reverse", "sess_logfile_reverse", 1);
    $_REQUEST['page_referrer'] = 'view_logfile';
    load_current_session_value('page_referrer', 'page_referrer', 'view_logfile');
    $refresh["seconds"] = $_REQUEST["refresh"];
    $refresh["page"] = "utilities.php?action=view_logfile";
    include_once "./include/top_header.php";
    ?>
	<script type="text/javascript">
	<!--

	function applyViewLogFilterChange(objForm) {
		strURL = '?tail_lines=' + objForm.tail_lines.value;
		strURL = strURL + '&message_type=' + objForm.message_type.value;
		strURL = strURL + '&refresh=' + objForm.refresh.value;
		strURL = strURL + '&reverse=' + objForm.reverse.value;
		strURL = strURL + '&filter=' + objForm.filter.value;
		strURL = strURL + '&action=view_logfile';
		document.location = strURL;
	}

	-->
	</script>
	<?php 
    html_start_box("<strong>Log File Filters</strong>", "100%", $colors["header"], "3", "center", "");
    include "./include/html/inc_view_logfile_table.php";
    html_end_box();
    /* read logfile into an array and display */
    $logcontents = tail_file($logfile, $_REQUEST["tail_lines"]);
    if ($_REQUEST["reverse"] == 1) {
        $logcontents = array_reverse($logcontents);
    }
    if ($_REQUEST["message_type"] > 0) {
        $start_string = "<strong>Log File</strong> [Total Lines: " . sizeof($logcontents) . " - Non-Matching Items Hidden]";
    } else {
        $start_string = "<strong>Log File</strong> [Total Lines: " . sizeof($logcontents) . " - All Items Shown]";
    }
    html_start_box($start_string, "100%", $colors["header"], "3", "center", "");
    $i = 0;
    $j = 0;
    $linecolor = false;
    foreach ($logcontents as $item) {
        $host_start = strpos($item, "Host[");
        $ds_start = strpos($item, "DS[");
        $new_item = "";
        if (!$host_start && !$ds_start) {
            $new_item = $item;
        } else {
            if ($host_start) {
                $host_end = strpos($item, "]", $host_start);
                $host_id = substr($item, $host_start + 5, $host_end - ($host_start + 5));
                $new_item = $new_item . substr($item, 0, $host_start + 5) . "<a href='host.php?action=edit&id=" . $host_id . "'>" . substr($item, $host_start + 5, $host_end - ($host_start + 5)) . "</a>";
                $item = substr($item, $host_end);
            }
            $ds_start = strpos($item, "DS[");
            if ($ds_start) {
                $ds_end = strpos($item, "]", $ds_start);
                $ds_id = substr($item, $ds_start + 3, $ds_end - ($ds_start + 3));
                $new_item = $new_item . substr($item, 0, $ds_start + 3) . "<a href='data_sources.php?action=ds_edit&id=" . $ds_id . "'>" . substr($item, $ds_start + 3, $ds_end - ($ds_start + 3)) . "</a>";
                $item = substr($item, $ds_end);
                $new_item = $new_item . $item;
            } else {
                $new_item = $new_item . $item;
            }
        }
        /* determine if we are to display the line */
        switch ($_REQUEST["message_type"]) {
            case -1:
                /* all */
                $display = true;
                break;
            case 5:
                /* sql calls */
                if (substr_count($new_item, " SQL ")) {
                    $display = true;
                } else {
                    $display = false;
                }
                break;
            case 1:
                /* stats */
                if (substr_count($new_item, "STATS")) {
                    $display = true;
                } else {
                    $display = false;
                }
                break;
            case 2:
                /* warnings */
                if (substr_count($new_item, "WARN")) {
                    $display = true;
                } else {
                    $display = false;
                }
                break;
            case 3:
                /* errors */
                if (substr_count($new_item, "ERROR")) {
                    $display = true;
                } else {
                    $display = false;
                }
                break;
            case 4:
                /* debug */
                if (substr_count($new_item, "DEBUG")) {
                    $display = true;
                } else {
                    $display = false;
                }
                if (substr_count($new_item, " SQL ")) {
                    $display = false;
                }
                break;
            default:
                /* all other lines */
                $display = true;
                break;
        }
        /* match any lines that match the search string */
        if (strlen($_REQUEST["filter"])) {
            if (substr_count(strtolower($new_item), strtolower($_REQUEST["filter"])) || @preg_match($_REQUEST["filter"], $new_item)) {
                $display = true;
            } else {
                $display = false;
            }
        }
        /* get the background color */
        if (substr_count($new_item, "ERROR") || substr_count($new_item, "FATAL")) {
            $bgcolor = "FF3932";
        } elseif (substr_count($new_item, "WARN")) {
            $bgcolor = "EACC00";
        } elseif (substr_count($new_item, " SQL ")) {
            $bgcolor = "6DC8FE";
        } elseif (substr_count($new_item, "DEBUG")) {
            $bgcolor = "C4FD3D";
        } elseif (substr_count($new_item, "STATS")) {
            $bgcolor = "96E78A";
        } else {
            if ($linecolor) {
                $bgcolor = "CCCCCC";
            } else {
                $bgcolor = "FFFFFF";
            }
            $linecolor = !$linecolor;
        }
        if ($display) {
            ?>
			<tr bgcolor='#<?php 
            print $bgcolor;
            ?>
'>
				<td>
					<?php 
            print $new_item;
            ?>
				</td>
			</tr>
			<?php 
            $j++;
        }
        $i++;
        if ($j > 1000) {
            ?>
			<tr bgcolor='#EACC00'>
				<td>
					<?php 
            print ">>>>  LINE LIMIT OF 1000 LINES REACHED!!  <<<<";
            ?>
				</td>
			</tr>
			<?php 
            break;
        }
    }
    html_end_box();
    include_once "./include/bottom_footer.php";
}
Esempio n. 4
0
function utilities_view_logfile() {
	global $colors, $log_tail_lines, $page_refresh_interval;

	$logfile = read_config_option("path_cactilog");

	if ($logfile == "") {
		$logfile = "./log/rrd.log";
	}

	/* helps determine output color */
	$linecolor = True;

	input_validate_input_number(get_request_var_request("tail_files"));
	input_validate_input_number(get_request_var_request("message_type"));
	input_validate_input_number(get_request_var_request("refresh"));
	input_validate_input_number(get_request_var_request("reverse"));

	/* if the user pushed the 'clear' button */
	if (isset($_REQUEST["clear_x"])) {
		kill_session_var("sess_logfile_tail_lines");
		kill_session_var("sess_logfile_message_type");
		kill_session_var("sess_logfile_filter");
		kill_session_var("sess_logfile_refresh");
		kill_session_var("sess_logfile_reverse");

		unset($_REQUEST["tail_lines"]);
		unset($_REQUEST["message_type"]);
		unset($_REQUEST["filter"]);
		unset($_REQUEST["refresh"]);
		unset($_REQUEST["reverse"]);
	}

	load_current_session_value("tail_lines", "sess_logfile_tail_lines", read_config_option("num_rows_log"));
	load_current_session_value("message_type", "sess_logfile_message_type", "-1");
	load_current_session_value("filter", "sess_logfile_filter", "");
	load_current_session_value("refresh", "sess_logfile_refresh", read_config_option("log_refresh_interval"));
	load_current_session_value("reverse", "sess_logfile_reverse", 1);

	$_REQUEST['page_referrer'] = 'view_logfile';
	load_current_session_value('page_referrer', 'page_referrer', 'view_logfile');

	$refresh["seconds"] = $_REQUEST["refresh"];
	$refresh["page"] = "utilities.php?action=view_logfile";

	include_once(CACTI_BASE_PATH . "/include/top_header.php");

	?>
	<script type="text/javascript">
	<!--

	function applyViewLogFilterChange(objForm) {
		strURL = '?tail_lines=' + objForm.tail_lines.value;
		strURL = strURL + '&message_type=' + objForm.message_type.value;
		strURL = strURL + '&refresh=' + objForm.refresh.value;
		strURL = strURL + '&reverse=' + objForm.reverse.value;
		strURL = strURL + '&filter=' + objForm.filter.value;
		strURL = strURL + '&action=view_logfile';
		strURL = strURL + '&page=1';
		document.location = strURL;
	}

	-->
	</script>
	<?php

	html_start_box("<strong>" . __("Log File Filters") . "</strong>", "100", $colors["header"], "3", "center", "", true);
	?>
	<tr class='rowAlternate2'>
		<td>
			<form name="form_logfile" action="utilities.php">
			<table cellpadding="1" cellspacing="0">
				<tr>
					<td class="nw80">
						&nbsp;<?php print __("Tail Lines:");?>&nbsp;
					</td>
					<td class="w1">
						<select name="tail_lines" onChange="applyViewLogFilterChange(document.form_logfile)">
							<?php
							foreach($log_tail_lines AS $tail_lines => $display_text) {
								print "<option value='" . $tail_lines . "'"; if (get_request_var_request("tail_lines") == $tail_lines) { print " selected"; } print ">" . $display_text . "</option>\n";
							}
							?>
						</select>
					</td>
					<td class="nw100">
						&nbsp;<?php print __("Message Type:");?>&nbsp;
					</td>
					<td class="w1">
						<select name="message_type" onChange="applyViewLogFilterChange(document.form_logfile)">
							<option value="-1"<?php if (get_request_var_request('message_type') == '-1') {?> selected<?php }?>><?php print __("All");?></option>
							<option value="1"<?php if (get_request_var_request('message_type') == '1') {?> selected<?php }?>><?php print __("Stats");?></option>
							<option value="2"<?php if (get_request_var_request('message_type') == '2') {?> selected<?php }?>><?php print __("Warnings");?></option>
							<option value="3"<?php if (get_request_var_request('message_type') == '3') {?> selected<?php }?>><?php print __("Errors");?></option>
							<option value="4"<?php if (get_request_var_request('message_type') == '4') {?> selected<?php }?>><?php print __("Debug");?></option>
							<option value="5"<?php if (get_request_var_request('message_type') == '5') {?> selected<?php }?>><?php print __("SQL Calls");?></option>
						</select>
					</td>
					<td class="nw200">
						&nbsp;<input type="submit" Value="<?php print __("Go");?>" name="go" align="middle">
						<input type="submit" Value="<?php print __("Clear");?>" name="clear_x" align="middle">
						<input type="submit" Value="<?php print __("Purge");?>" name="purge_x" align="middle">
					</td>
				</tr>
				<tr>
					<td class="nw80">
						&nbsp;<?php print __("Refresh:");?>&nbsp;
					</td>
					<td class="w1">
						<select name="refresh" onChange="applyViewLogFilterChange(document.form_logfile)">
							<?php
							foreach($page_refresh_interval AS $seconds => $display_text) {
								print "<option value='" . $seconds . "'"; if (get_request_var_request("refresh") == $seconds) { print " selected"; } print ">" . $display_text . "</option>\n";
							}
							?>
						</select>
					</td>
					<td class="nw100">

						&nbsp;<?php print __("Display Order:");?>&nbsp;
					</td>
					<td class="w1">
						<select name="reverse" onChange="applyViewLogFilterChange(document.form_logfile)">
							<option value="1"<?php if (get_request_var_request('reverse') == '1') {?> selected<?php }?>><?php print __("Newest First");?></option>
							<option value="2"<?php if (get_request_var_request('reverse') == '2') {?> selected<?php }?>><?php print __("Oldest First");?></option>
						</select>
					</td>
				</tr>
			</table>
			<table cellpadding="1" cellspacing="0">
				<tr>
					<td class="nw80">
						&nbsp;<?php print __("Search:");?>&nbsp;
					</td>
					<td class="w1">
						<input type="text" name="filter" size="75" value="<?php print $_REQUEST["filter"];?>">
					</td>
				</tr>
			</table>
			<div><input type='hidden' name='page' value='1'></div>
			<div><input type='hidden' name='action' value='view_logfile'></div>
			</form>
		</td>
	</tr>
	<?php
	html_end_box(false);

	/* read logfile into an array and display */
	$logcontents = tail_file($logfile, $_REQUEST["tail_lines"], $_REQUEST["message_type"], $_REQUEST["filter"]);

	if (get_request_var_request("reverse") == 1) {
		$logcontents = array_reverse($logcontents);
	}

	if (get_request_var_request("message_type") > 0) {
		$start_string = "<strong>" . __("Log File") . "</strong> [" . __("Total Lines:") . " " . sizeof($logcontents) . " - " . __("Non-Matching Items Hidden") . "]";
	}else{
		$start_string = "<strong>" . __("Log File") . "</strong> [" . __("Total Lines:") . " " . sizeof($logcontents) . " - " . __("All Items Shown") . "]";
	}

	html_start_box($start_string, "100", $colors["header"], "0", "center", "");

	$i = 0;
	$j = 0;
	$linecolor = false;
	foreach ($logcontents as $item) {
		$device_start = strpos($item, "Host[");
		$ds_start   = strpos($item, "DS[");

		$new_item = "";

		if ((!$device_start) && (!$ds_start)) {
			$new_item = $item;
		}else{
			while ($device_start) {
				$device_end   = strpos($item, "]", $device_start);
				$device_id    = substr($item, $device_start+5, $device_end-($device_start+5));
				$new_item   = $new_item . substr($item, 0, $device_start + 5) . "<a href='" . htmlspecialchars("devices.php?action=edit&id=" . $device_id) . "'>" . substr($item, $device_start + 5, $device_end-($device_start + 5)) . "</a>";
				$item       = substr($item, $device_end);
				$device_start = strpos($item, "Host[");
			}

			$ds_start = strpos($item, "DS[");
			while ($ds_start) {
				$ds_end   = strpos($item, "]", $ds_start);
				$ds_id    = substr($item, $ds_start+3, $ds_end-($ds_start+3));
				$new_item = $new_item . substr($item, 0, $ds_start + 3) . "<a href='" . htmlspecialchars("data_sources.php?action=ds_edit&id=" . $ds_id) . "'>" . substr($item, $ds_start + 3, $ds_end-($ds_start + 3)) . "</a>";
				$item     = substr($item, $ds_end);
				$ds_start = strpos($item, "DS[");
			}

			$new_item = $new_item . $item;
		}

		/* get the background color */
		if ((substr_count($new_item, "ERROR")) || (substr_count($new_item, "FATAL"))) {
			$bgcolor = "FF3932";
		}elseif (substr_count($new_item, "WARN")) {
			$bgcolor = "EACC00";
		}elseif (substr_count($new_item, " SQL ")) {
			$bgcolor = "6DC8FE";
		}elseif (substr_count($new_item, "DEBUG")) {
			$bgcolor = "C4FD3D";
		}elseif (substr_count($new_item, "STATS")) {
			$bgcolor = "96E78A";
		}else{
			if ($linecolor) {
				$bgcolor = "CCCCCC";
			}else{
				$bgcolor = "FFFFFF";
			}
			$linecolor = !$linecolor;
		}

		?>
		<tr bgcolor='#<?php print $bgcolor;?>'>
			<td>
				<?php print $new_item;?>
			</td>
		</tr>
		<?php
		$j++;
		$i++;

		if ($j > 1000) {
			?>
			<tr bgcolor='#EACC00'>
				<td>
					<?php print ">>>>  " . __("LINE LIMIT OF 1000 LINES REACHED!!") . "  <<<<";?>
				</td>
			</tr>
			<?php

			break;
		}
	}

	html_end_box();

	include_once(CACTI_BASE_PATH . "/include/bottom_footer.php");
}
Esempio n. 5
0
function macro_Referer($formatter, $value, &$options)
{
    global $DBInfo;
    if (empty($DBInfo->use_referer)) {
        return "[[Referer macro: {$use_referer} is off.]]";
    }
    $referer_log_filename = $DBInfo->cache_dir . "/referer/referer.log";
    if ($value !== true) {
        // [[referer]] or ?action=referer
        $needle = $formatter->page->urlname;
    } else {
        // [[referer()]]
        unset($needle);
    }
    if ($needle and false) {
        // so slow XXX
        $handle = fopen($referer_log_filename, 'r');
        if (!is_resource($handle)) {
            return '';
        }
        $logs = array();
        while (!feof($handle)) {
            $line = fgets($handle);
            list(, $pagename, ) = explode("\t", $line);
            if ($pagename == $needle) {
                $logs[] = $line;
            }
            if ($count > 100) {
                break;
            }
            $count++;
        }
        fclose($handle);
        $logs = array_reverse($logs);
    } else {
        $number_of_lines = 200;
        // XXX
        $logs = tail_file($referer_log_filename, $number_of_lines);
    }
    $log = array();
    $counter = 10;
    // XXX
    $count = 0;
    foreach ($logs as $line) {
        list(, $pagename, ) = explode("\t", $line);
        if (strcmp($pagename, $needle) == 0) {
            $log[] = $line;
        }
        if ($count > $counter) {
            break;
        }
        $count++;
    }
    $logs = $log;
    $tz_offset = $formatter->tz_offset;
    $length = sizeof($logs);
    for ($c = 0; $c < $length; $c++) {
        $fields = explode("\t", $logs[$c]);
        $fields[0] = date("Y-m-d H:i:s", strtotime($fields[0]) + $tz_offset);
        $fields[1] = $formatter->link_tag(_rawurlencode($fields[1]), "", urldecode($fields[1]));
        $found = '';
        if (ereg("[?&][pqQ](uery)?=([^&]+)&?", $fields[2], $regs)) {
            $check = strpos($regs[2], '%');
            # is it urlecnoded ?
            if ($check !== false) {
                $found = urldecode($regs[2]);
                if (function_exists('iconv')) {
                    $test = false;
                    if (strcasecmp('utf-8', $DBInfo->charset) != 0) {
                        $test = iconv('utf-8', $DBInfo->charset, $found);
                        if ($test !== false) {
                            $found = $test;
                        }
                    }
                    if ($test === false and !empty($DBInfo->url_encodings)) {
                        $cs = explode(',', $DBInfo->url_encodings);
                        foreach ($cs as $c) {
                            $test = @iconv($c, $DBInfo->charset, $found);
                            if ($test !== false) {
                                $found = $test;
                                break;
                            }
                        }
                    }
                }
            } else {
                $found = $regs[2];
            }
        }
        $fields[2] = (!empty($found) ? "[ {$found} ] " : '') . "<a href='{$fields['2']}'>" . urldecode($fields[2]) . "</a>";
        if (isset($needle)) {
            unset($fields[1]);
        }
        $logs[$c] = "<td class='date' style='width:20%'>" . implode("</td><td>", $fields) . "<td>";
    }
    $ret = '';
    if ($length > 0) {
        $ret = "\n<table>";
        $ret .= "<caption>" . _("Referer history") . "</caption>";
        $ret .= "<tr>";
        $ret .= implode("</tr>\n<tr>", $logs);
        $ret .= "</tr></table>\n";
    }
    return '<div class="Referer">' . $ret . '</div>';
}
Esempio n. 6
0
function clog_view_logfile()
{
    global $config, $colors, $log_tail_lines, $page_refresh_interval, $refresh;
    $logfile = read_config_option('path_cactilog');
    if ($logfile == '') {
        $logfile = './log/cacti.log';
    }
    /* helps determine output color */
    $linecolor = true;
    input_validate_input_number(get_request_var_request('tail_files'));
    input_validate_input_number(get_request_var_request('message_type'));
    input_validate_input_number(get_request_var_request('refresh'));
    input_validate_input_number(get_request_var_request('reverse'));
    /* enable page refreshes */
    kill_session_var('custom');
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST['clear'])) {
        kill_session_var('sess_clog_tail_lines');
        kill_session_var('sess_clog_message_type');
        kill_session_var('sess_clog_filter');
        kill_session_var('sess_clog_refresh');
        kill_session_var('sess_clog_reverse');
        unset($_REQUEST['tail_lines']);
        unset($_REQUEST['message_type']);
        unset($_REQUEST['filter']);
        unset($_REQUEST['refresh']);
        unset($_REQUEST['reverse']);
    }
    load_current_session_value('tail_lines', 'sess_clog_tail_lines', read_config_option('num_rows_log'));
    load_current_session_value('message_type', 'sess_clog_message_type', '-1');
    load_current_session_value('filter', 'sess_clog_filter', '');
    load_current_session_value('refresh', 'sess_clog_refresh', read_config_option('log_refresh_interval'));
    load_current_session_value('reverse', 'sess_clog_reverse', 1);
    $_REQUEST['page_referrer'] = 'view_logfile';
    load_current_session_value('page_referrer', 'page_referrer', 'view_logfile');
    $refresh['seconds'] = $_REQUEST['refresh'];
    $refresh['page'] = $config['url_path'] . 'clog.php';
    if (isset($_REQUEST['purge_continue']) && clog_admin()) {
        clog_purge_logfile();
    }
    general_header();
    if (isset($_REQUEST['purge']) && clog_admin()) {
        html_start_box('<strong>Purge</strong>', '50%', '', '3', 'center', '');
        print "\t\n\t\t\t<form action='clog.php' autocomplete='off' method='post'>\n\t\t\t<tr>\n\t\t\t\t<td class='textArea'>\n\t\t\t\t\t<p>Click \"Continue\" to purge the cacti log file.<br><br><br>Note: If logging is set to Cacti and Syslog, the log information will remain in Syslog.</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td colspan='2' align='right' bgcolor='#eaeaea'>\n\t\t\t\t\t<input id='cancel' type='button' value='Cancel'>&nbsp\n\t\t\t\t\t<input id='pc' type='button' name='purge_continue' value='Continue' title='Purge cacti.log'>\n\t\t\t\t\t<script type='text/javascript'>\n\t\t\t\t\t\$('#pc').click(function() {\n\t\t\t\t\t\turl='?purge_continue=1&header=false';\n\t\t\t\t\t\t\$.get(location.pathname+url, function(data) {\n\t\t\t\t\t\t\t\$('#main').html(data);\n\t\t\t\t\t\t\tapplySkin();\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\n\t\t\t\t\t\$('#cancel').click(function() {\n\t\t\t\t\t\turl='?header=false';\n\t\t\t\t\t\t\$.get(location.pathname+url, function(data) {\n\t\t\t\t\t\t\t\$('#main').html(data);\n\t\t\t\t\t\t\tapplySkin();\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\n\t\t\t\t\t\$(function() {\n\t\t\t\t\t\tapplySkin();\n\t\t\t\t\t});\n\t\t\t\t\t</script>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t";
        html_end_box();
        return;
    }
    html_start_box('<strong>Log File Filters</strong>', '100%', $colors['header'], '3', 'center', '');
    filter();
    html_end_box();
    /* read logfile into an array and display */
    $logcontents = tail_file($logfile, $_REQUEST['tail_lines'], $_REQUEST['message_type'], $_REQUEST['filter']);
    $exclude_regex = read_config_option('clog_exclude', true);
    if ($_REQUEST['reverse'] == 1) {
        $logcontents = array_reverse($logcontents);
    }
    if (!clog_admin()) {
        if (strlen($exclude_regex)) {
            $ad_filter = ' - Admin Filter in Affect';
        } else {
            $ad_filter = ' - No Admin Filter in Affect';
        }
    } else {
        $ad_filter = ' - Admin View';
    }
    if ($_REQUEST['message_type'] > 0) {
        $start_string = '<strong>Log File</strong> [Total Lines: ' . sizeof($logcontents) . $ad_filter . ' - Additional Filter in Affect]';
    } else {
        $start_string = '<strong>Log File</strong> [Total Lines: ' . sizeof($logcontents) . $ad_filter . ' - No Other Filter in Affect]';
    }
    html_start_box($start_string, '100%', $colors['header'], '3', 'center', '');
    $i = 0;
    $j = 0;
    $linecolor = false;
    foreach ($logcontents as $item) {
        $host_start = strpos($item, 'Device[');
        $ds_start = strpos($item, 'DS[');
        $new_item = '';
        if (!$host_start && !$ds_start) {
            $new_item = $item;
        } else {
            while ($host_start) {
                $host_end = strpos($item, ']', $host_start);
                $host_id = substr($item, $host_start + 7, $host_end - ($host_start + 7));
                $new_item .= substr($item, 0, $host_start + 7) . "<a href='" . $config['url_path'] . 'host.php?action=edit&id=' . $host_id . "'>" . substr($item, $host_start + 5, $host_end - ($host_start + 7)) . '</a>';
                $host_description = db_fetch_cell("SELECT description FROM host WHERE id={$host_id}");
                $new_item .= '] Description[' . $host_description . '';
                $item = substr($item, $host_end);
                $host_start = strpos($item, 'Device[');
            }
            $ds_start = strpos($item, 'DS[');
            while ($ds_start) {
                $ds_end = strpos($item, ']', $ds_start);
                $ds_id = substr($item, $ds_start + 3, $ds_end - ($ds_start + 3));
                $graph_ids = clog_get_graphs_from_datasource($ds_id);
                $graph_add = '&graph_add=';
                if (sizeof($graph_ids)) {
                    $new_item .= substr($item, 0, $ds_start + 3) . "<a href='" . $config['url_path'] . 'data_sources.php?action=ds_edit&id=' . $ds_id . "'>" . substr($item, $ds_start + 3, $ds_end - ($ds_start + 3)) . '</a>' . "] Graphs[<a href='" . $config['url_path'] . 'graph_view.php?page=1&style=selective&action=preview';
                    $i = 0;
                    $titles = '';
                    foreach ($graph_ids as $key => $title) {
                        $new_item .= '&graph_' . $key . '=' . $key;
                        $graph_add .= ($i > 0 ? htmlspecialchars('%2C') : '') . $key;
                        $i++;
                        if (strlen($titles)) {
                            $titles .= ",'" . $title . "'";
                        } else {
                            $titles .= "'" . $title . "'";
                        }
                    }
                    $new_item .= $graph_add . "' title='View Graphs'>" . $titles . '</a>';
                }
                $item = substr($item, $ds_end);
                $ds_start = strpos($item, 'DS[');
            }
            $new_item = $new_item . $item;
        }
        /* get the background color */
        if (substr_count($new_item, 'ERROR') || substr_count($new_item, 'FATAL')) {
            $bgcolor = 'FF3932';
        } elseif (substr_count($new_item, 'WARN')) {
            $bgcolor = 'EACC00';
        } elseif (substr_count($new_item, ' SQL ')) {
            $bgcolor = '6DC8FE';
        } elseif (substr_count($new_item, 'DEBUG')) {
            $bgcolor = 'C4FD3D';
        } elseif (substr_count($new_item, 'STATS')) {
            $bgcolor = '96E78A';
        } else {
            if ($linecolor) {
                $bgcolor = 'CCCCCC';
            } else {
                $bgcolor = 'FFFFFF';
            }
            $linecolor = !$linecolor;
        }
        /* respect the exclusion filter */
        $show = true;
        if (!clog_admin() && @preg_match($exclude_regex, $new_item)) {
            $show = false;
        }
        if ($show) {
            ?>
		<tr bgcolor='#<?php 
            print $bgcolor;
            ?>
'>
			<td>
				<?php 
            print $new_item;
            ?>
			</td>
		</tr>
		<?php 
            $j++;
            $i++;
        }
        if ($j > 1000) {
            ?>
			<tr class='even'>
				<td>
					<?php 
            print '>>>>  LINE LIMIT OF 1000 LINES REACHED!!  <<<<';
            ?>
				</td>
			</tr>
			<?php 
            break;
        }
    }
    html_end_box();
    bottom_footer();
}
Esempio n. 7
0
function utilities_view_logfile() {
	global $colors, $log_tail_lines, $page_refresh_interval;

	$logfile = read_config_option("path_cactilog");

	if ($logfile == "") {
		$logfile = "./log/rrd.log";
	}

	/* helps determine output color */
	$linecolor = True;

	input_validate_input_number(get_request_var_request("tail_files"));
	input_validate_input_number(get_request_var_request("message_type"));
	input_validate_input_number(get_request_var_request("refresh"));
	input_validate_input_number(get_request_var_request("reverse"));

	/* clean up search filter */
	if (isset($_REQUEST["filter"])) {
		$_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
	}

	/* if the user pushed the 'clear' button */
	if (isset($_REQUEST["clear_x"])) {
		kill_session_var("sess_logfile_tail_lines");
		kill_session_var("sess_logfile_message_type");
		kill_session_var("sess_logfile_filter");
		kill_session_var("sess_logfile_refresh");
		kill_session_var("sess_logfile_reverse");

		unset($_REQUEST["tail_lines"]);
		unset($_REQUEST["message_type"]);
		unset($_REQUEST["filter"]);
		unset($_REQUEST["refresh"]);
		unset($_REQUEST["reverse"]);
	}

	load_current_session_value("tail_lines", "sess_logfile_tail_lines", read_config_option("num_rows_log"));
	load_current_session_value("message_type", "sess_logfile_message_type", "-1");
	load_current_session_value("filter", "sess_logfile_filter", "");
	load_current_session_value("refresh", "sess_logfile_refresh", read_config_option("log_refresh_interval"));
	load_current_session_value("reverse", "sess_logfile_reverse", 1);

	$_REQUEST['page_referrer'] = 'view_logfile';
	load_current_session_value('page_referrer', 'page_referrer', 'view_logfile');

	$refresh["seconds"] = $_REQUEST["refresh"];
	$refresh["page"] = "utilities.php?action=view_logfile";

	include_once("./include/top_header.php");

	html_start_box("<strong>Log File Filters</strong>", "98%", $colors["header"], "3", "center", "");

	include("./include/html/inc_view_logfile_table.php");

	html_end_box();

	/* read logfile into an array and display */
	$logcontents = tail_file($logfile, $_REQUEST["tail_lines"]);

	if ($_REQUEST["reverse"] == 1) {
		$logcontents = array_reverse($logcontents);
	}

	if ($_REQUEST["message_type"] > 0) {
		$start_string = "<strong>Log File</strong> [Total Lines: " . sizeof($logcontents) . " - Non-Matching Items Hidden]";
	}else{
		$start_string = "<strong>Log File</strong> [Total Lines: " . sizeof($logcontents) . " - All Items Shown]";
	}

	html_start_box($start_string, "98%", $colors["header"], "3", "center", "");

	$i = 0;
	$linecolor = false;
	foreach ($logcontents as $item) {
        $host_start = strpos($item, "Host[");
        $ds_start = strpos($item, "DS[");

        $new_item = "";

		if ((!$host_start) && (!$ds_start)) {
			$new_item = $item;
		}else{
	        if ($host_start) {
    	    	$host_end = strpos($item, "]", $host_start);
        		$host_id = substr($item, $host_start+5, $host_end-($host_start+5));
				$new_item = $new_item . substr($item, 0, $host_start + 5) . "<a href='host.php?action=edit&id=" . $host_id . "'>" . substr($item, $host_start + 5, $host_end-($host_start + 5)) . "</a>";
				$item = substr($item, $host_end);
			}

			$ds_start = strpos($item, "DS[");
			if ($ds_start) {
				$ds_end = strpos($item, "]", $ds_start);
				$ds_id = substr($item, $ds_start+3, $ds_end-($ds_start+3));
				$new_item = $new_item . substr($item, 0, $ds_start + 3) . "<a href='data_sources.php?action=ds_edit&id=" . $ds_id . "'>" . substr($item, $ds_start + 3, $ds_end-($ds_start + 3)) . "</a>";
				$item = substr($item, $ds_end);
				$new_item = $new_item . $item;
			}else{
				$new_item = $new_item . $item;
			}
		}

		/* determine if we are to display the line */
		switch ($_REQUEST["message_type"]) {
		case -1: /* all */
			$display = true;
			break;
		case 5: /* sql calls */
			if (substr_count($new_item, " SQL ")) {
				$display=true;
			}else{
				$display=false;
			}

			break;
		case 1: /* stats */
			if (substr_count($new_item, "STATS")) {
				$display=true;
			}else{
				$display=false;
			}

			break;
		case 2: /* warnings */
			if (substr_count($new_item, "WARN")) {
				$display=true;
			}else{
				$display=false;
			}

			break;
		case 3: /* errors */
			if (substr_count($new_item, "ERROR")) {
				$display=true;
			}else{
				$display=false;
			}

			break;
		case 4: /* debug */
			if (substr_count($new_item, "DEBUG")) {
				$display=true;
			}else{
				$display=false;
			}

			if (substr_count($new_item, " SQL ")) {
				$display=false;
			}

			break;
		default: /* all other lines */
			$display=true;
			break;
		}

		/* get the background color */
		if ((substr_count($new_item, "ERROR")) || (substr_count($new_item, "FATAL"))) {
			$bgcolor = "FF3932";
		}elseif (substr_count($new_item, "WARN")) {
			$bgcolor = "EACC00";
		}elseif (substr_count($new_item, " SQL ")) {
			$bgcolor = "6DC8FE";
		}elseif (substr_count($new_item, "DEBUG")) {
			$bgcolor = "C4FD3D";
		}elseif (substr_count($new_item, "STATS")) {
			$bgcolor = "96E78A";
		}else{
			if ($linecolor) {
				$bgcolor = "CCCCCC";
			}else{
				$bgcolor = "FFFFFF";
			}
			$linecolor = !$linecolor;
		}

		if ($display) {
			?>
			<tr bgcolor='#<?php print $bgcolor;?>'>
				<td>
					<?php print $new_item;?>
				</td>
			</tr>
			<?php
		}

		$i++;
	}

	html_end_box();

	include_once("./include/bottom_footer.php");
}