0
AND data_template_rrd.local_data_id = ?', array($local_data_id)), 'id', 'name');
}
function clog_purge_logfile() {
global $config;
$logfile = read_config_option('path_cactilog');
if ($logfile == '') {
$logfile = $config['base_path'] . '/log/cacti.log';
}
if (file_exists($logfile)) {
if (is_writable($logfile)) {
$timestamp = date('Y-m-d H:i:s');
$log_fh = fopen($logfile, 'w');
fwrite($log_fh, "$timestamp - WEBUI: Cacti Log Cleared from Web Management Interface\n");
fclose($log_fh);
raise_message('clog_purged');
}else{
raise_message('clog_permissions');
}
}else{
raise_message('clog_missing');
}
}
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 validation and session storage ================= */
$filters = array(
'tail_lines' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => read_config_option('num_rows_log')
),
'message_type' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '-1'
),
'refresh' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => read_config_option('log_refresh_interval')
),
'reverse' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'rfilter' => array(
'filter' => FILTER_VALIDATE_IS_REGEX,
'default' => ''
)
);
validate_store_request_vars($filters, 'sess_clog');
/* ================= input validation ================= */
/* enable page refreshes */
kill_session_var('custom');
set_request_var('page_referrer', 'view_logfile');
load_current_session_value('page_referrer', 'page_referrer', 'view_logfile');
$refresh['seconds'] = get_request_var('refresh');
$refresh['page'] = $config['url_path'] . 'clog' . (!clog_admin() ? '_user':'') . '.php?header=false';
if ((isset_request_var('purge_continue')) && (clog_admin())) clog_purge_logfile();
general_header();
if ((isset_request_var('purge')) && (clog_admin())) {
form_start('clog.php');
html_start_box(__('Purge'), '50%', '', '3', 'center', '');
print "
|
" . __('Click \'Continue\' to purge the Cacti log file.
Note: If logging is set to Cacti and Syslog, the log information will remain in Syslog.') . "
|
|
 
|
\n";
html_end_box();
form_end();
return;
}
html_start_box(__('Log File Filters'), '100%', '', '3', 'center', '');
filter();
html_end_box();
/* read logfile into an array and display */
$logcontents = tail_file($logfile, get_request_var('tail_lines'), get_request_var('message_type'), get_request_var('rfilter'));
$exclude_regex = read_config_option('clog_exclude', true);
if (get_request_var('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 (get_request_var('message_type') > 0) {
$start_string = __('Log File [Total Lines: %d %s - Additional Filter in Affect]', sizeof($logcontents), $ad_filter);
}else{
$start_string = __('Log File [Total Lines: %d %s - No Other Filter in Affect]', sizeof($logcontents), $ad_filter);
}
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 = cacti_htmlspecialchars($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 .= cacti_htmlspecialchars(substr($item, 0, $host_start + 7)) . "$host_id";
$host_description = db_fetch_cell_prepared('SELECT description FROM host WHERE id = ?', array($host_id));
$new_item .= '] Description[' . cacti_htmlspecialchars($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 = $config['url_path'] . 'graph_view.php?page=1&style=selective&action=preview&graph_add=';
if (sizeof($graph_ids)) {
$new_item .= substr($item, 0, $ds_start + 3) .
"" . cacti_htmlspecialchars(substr($item, $ds_start + 3, $ds_end-($ds_start + 3))) . '' .
"] Graphs[ $title) {
$graph_add .= ($i > 0 ? '%2C' : '') . $key;
$i++;
if (strlen($titles)) {
$titles .= ",'" . cacti_htmlspecialchars($title) . "'";
}else{
$titles .= "'" . cacti_htmlspecialchars($title) . "'";
}
}
$new_item .= cacti_htmlspecialchars($graph_add) . "' title='" . __('View Graphs') . "'>" . $titles . '';
}
$item = substr($item, $ds_end);
$ds_start = strpos($item, 'DS[');
}
$new_item .= cacti_htmlspecialchars($item);
}
/* get the background color */
if ((substr_count($new_item, 'ERROR')) || (substr_count($new_item, 'FATAL'))) {
$class = 'clogError';
}elseif (substr_count($new_item, 'WARN')) {
$class = 'clogWarning';
}elseif (substr_count($new_item, ' SQL ')) {
$class = 'clogSQL';
}elseif (substr_count($new_item, 'DEBUG')) {
$class = 'clogDebug';
}elseif (substr_count($new_item, 'STATS')) {
$class = 'clogStats';
}else{
if ($linecolor) {
$class = 'odd';
}else{
$class = 'even';
}
$linecolor = !$linecolor;
}
/* respect the exclusion filter */
$show = true;
if ((!clog_admin()) && (@preg_match($exclude_regex, $new_item))) {
$show = false;
}
if ($show) {
?>
|
|
1000) {
?>
|
>>> ' . __('LINE LIMIT OF 1000 LINES REACHED!!') . ' <<<<';?>
|
|
|