nagiosql/admin/logbook.php

141 lines
5.4 KiB
PHP
Raw Normal View History

2017-05-22 11:24:21 +02:00
<?php
///////////////////////////////////////////////////////////////////////////////
//
// NagiosQL
//
///////////////////////////////////////////////////////////////////////////////
//
2019-04-17 11:40:50 +02:00
// (c) 2005-2018 by Martin Willisegger
2017-05-22 11:24:21 +02:00
//
// Project : NagiosQL
// Component : Admin logbook
2019-04-17 11:40:50 +02:00
// Website : https://sourceforge.net/projects/nagiosql/
// Version : 3.4.0
// GIT Repo : https://gitlab.com/wizonet/NagiosQL
2017-05-22 11:24:21 +02:00
//
///////////////////////////////////////////////////////////////////////////////
//
2019-04-17 11:40:50 +02:00
// Path settings
// ===================
$strPattern = '(admin/[^/]*.php)';
$preRelPath = preg_replace($strPattern, '', filter_input(INPUT_SERVER, 'PHP_SELF', FILTER_SANITIZE_STRING));
$preBasePath = preg_replace($strPattern, '', filter_input(INPUT_SERVER, 'SCRIPT_FILENAME', FILTER_SANITIZE_STRING));
//
2017-05-22 11:24:21 +02:00
// Define common variables
// =======================
2019-04-17 11:40:50 +02:00
$prePageId = 37;
$preContent = 'admin/logbook.htm.tpl';
$preAccess = 1;
$preFieldvars = 1;
2017-05-22 11:24:21 +02:00
//
// Include preprocessing files
// ===========================
2019-04-17 11:40:50 +02:00
require $preBasePath.'functions/prepend_adm.php';
require $preBasePath.'functions/prepend_content.php';
2017-05-22 11:24:21 +02:00
//
// Delete log entries
// ==================
2019-04-17 11:40:50 +02:00
$strWhere = '';
if ($chkTfValue1 != '') {
$strWhere .= "AND `time` > '$chkTfValue1 00:00:00'";
}
if ($chkTfValue2 != '') {
$strWhere .= "AND `time` < '$chkTfValue2 23:59:59'";
}
if ($strWhere != '') {
$strSQL = 'DELETE FROM `tbl_logbook` WHERE 1=1 ';
$strSQL .= $strWhere;
$booReturn = $myDBClass->insertData($strSQL);
if ($booReturn == false) {
$myVisClass->processMessage(translate('Error while selecting data from database:'), $strErrorMessage);
$myVisClass->processMessage($myDBClass->strErrorMessage, $strErrorMessage);
} else {
$myVisClass->processMessage(translate('Dataset successfully deleted. Affected rows:'). ' ' .
$myDBClass->intAffectedRows, $strInfoMessage);
}
2017-05-22 11:24:21 +02:00
}
//
// Search data
// ===========
2019-04-17 11:40:50 +02:00
if ($chkTfSearch != '') {
$strWhere = "WHERE `user` LIKE '%$chkTfSearch%' OR `ipadress` LIKE '%$chkTfSearch%' "
. "OR `domain` LIKE '%$chkTfSearch%' OR `entry` LIKE '%$chkTfSearch%'";
2017-05-22 11:24:21 +02:00
} else {
2019-04-17 11:40:50 +02:00
$strWhere = '';
2017-05-22 11:24:21 +02:00
}
//
// Get data
// ========
$intNumRows = $myDBClass->getFieldData("SELECT count(*) FROM `tbl_logbook` $strWhere");
2019-04-17 11:40:50 +02:00
if ($intNumRows <= $chkFromLine) {
$chkFromLine = 0;
}
$strSQL = "SELECT DATE_FORMAT(time,'%Y-%m-%d %H:%i:%s') AS `time`, `user`, `ipadress`, `domain`, `entry` "
. "FROM `tbl_logbook` $strWhere ORDER BY `time` DESC LIMIT $chkFromLine,".$SETS['common']['pagelines'];
$booReturn = $myDBClass->hasDataArray($strSQL, $arrDataLines, $intDataCount);
2017-05-22 11:24:21 +02:00
if ($booReturn == false) {
2019-04-17 11:40:50 +02:00
$myVisClass->processMessage(translate('Error while selecting data from database:'), $strErrorMessage);
$myVisClass->processMessage($myDBClass->strErrorMessage, $strErrorMessage);
2017-05-22 11:24:21 +02:00
}
//
// Start content
// =============
2019-04-17 11:40:50 +02:00
$conttp->setVariable('TITLE', translate('View logbook'));
foreach ($arrDescription as $elem) {
$conttp->setVariable($elem['name'], $elem['string']);
2017-05-22 11:24:21 +02:00
}
2019-04-17 11:40:50 +02:00
$conttp->setVariable('LANG_ENTRIES_BEFORE', translate('Delete logentries between:'));
$conttp->setVariable('LOCALE', $SETS['data']['locale']);
$conttp->setVariable('LANG_SELECT_DATE', translate('Please supply a start or a stop time at least'));
$conttp->setVariable('LANG_DELETELOG', translate('Do you really want to delete all log entries between the '
. 'selected dates?'));
$conttp->setVariable('DAT_SEARCH', $chkTfSearch);
2017-05-22 11:24:21 +02:00
// Legende einblenden
if ($chkFromLine > 1) {
2019-04-17 11:40:50 +02:00
$intPrevNumber = $chkFromLine - 20;
$conttp->setVariable('LANG_PREVIOUS', '<a href="' .filter_input(INPUT_SERVER, 'PHP_SELF', FILTER_SANITIZE_STRING).
'?from_line=' .$intPrevNumber. '"><< ' .translate('previous 20 entries'). '</a>');
2017-05-22 11:24:21 +02:00
} else {
2019-04-17 11:40:50 +02:00
$conttp->setVariable('LANG_PREVIOUS', '');
2017-05-22 11:24:21 +02:00
}
if ($chkFromLine < $intNumRows-20) {
2019-04-17 11:40:50 +02:00
$intNextNumber = $chkFromLine + 20;
$conttp->setVariable('LANG_NEXT', '<a href="' .filter_input(INPUT_SERVER, 'PHP_SELF', FILTER_SANITIZE_STRING).
'?from_line=' .$intNextNumber. '">' .translate('next 20 entries'). ' >></a>');
2017-05-22 11:24:21 +02:00
} else {
2019-04-17 11:40:50 +02:00
$conttp->setVariable('LANG_NEXT', '');
2017-05-22 11:24:21 +02:00
}
2019-04-17 11:40:50 +02:00
//
2017-05-22 11:24:21 +02:00
// Output log data
// ===============
if ($intDataCount != 0) {
2019-04-17 11:40:50 +02:00
for ($i = 0; $i < $intDataCount; $i++) {
// Set default values
if ($arrDataLines[$i]['ipadress'] == '') {
$arrDataLines[$i]['ipadress'] = '&nbsp;';
}
// Insert data values
$conttp->setVariable('DAT_TIME', $arrDataLines[$i]['time']);
$conttp->setVariable('DAT_ACCOUNT', $arrDataLines[$i]['user']);
$conttp->setVariable('DAT_ACTION', $arrDataLines[$i]['entry']);
$conttp->setVariable('DAT_IPADRESS', $arrDataLines[$i]['ipadress']);
$conttp->setVariable('DAT_DOMAIN', $arrDataLines[$i]['domain']);
$conttp->parse('logdatacell');
}
2017-05-22 11:24:21 +02:00
}
2019-04-17 11:40:50 +02:00
$conttp->setVariable('ERRORMESSAGE', '<br>' .$strErrorMessage);
$conttp->setVariable('INFOMESSAGE', '<br>' .$strInfoMessage);
2017-05-22 11:24:21 +02:00
// Check access rights for adding new objects
2019-04-17 11:40:50 +02:00
if ($myVisClass->checkAccountGroup($prePageKey, 'write') != 0) {
$conttp->setVariable('ADD_CONTROL', 'disabled="disabled"');
}
$conttp->parse('logbooksite');
$conttp->show('logbooksite');
2017-05-22 11:24:21 +02:00
//
// Process footer
// ==============
2019-04-17 11:40:50 +02:00
$maintp->setVariable('VERSION_INFO', "<a href='https://sourceforge.net/projects/nagiosql/' "
. "target='_blank'>NagiosQL</a> $setFileVersion");
$maintp->parse('footer');
$maintp->show('footer');