diff --git a/src/admin/sources.php b/src/admin/sources.php index fd251fb..56d5d90 100644 --- a/src/admin/sources.php +++ b/src/admin/sources.php @@ -324,12 +324,64 @@ if ( isset($_GET['op']) ) $content['ROWCOUNT'] = $stream->GetLogStreamTotalRowCount(); if ( isset($content['ROWCOUNT']) ) { - // Allow Deleting by Date - $content['DELETE_ALLOWDETAIL'] = true; + // Check for suboperations + if ( isset($_POST['subop']) ) + { + if ( $_POST['subop'] == "all" ) + { + $timestamp = 0; + } + else if ( $_POST['subop'] == "since" && isset($_POST['olderthan']) ) + { + // Take current time and subtract Seconds + $nSecondsSubtract = $_POST['olderthan']; + $timestamp = time() - $nSecondsSubtract; + } + else if ( $_POST['subop'] == "date" && isset($_POST['olderdate_year']) && isset($_POST['olderdate_month']) && isset($_POST['olderdate_day']) ) + { + // Generate Timestamp + $timestamp = mktime( 0, 0, 0, intval($_POST['olderdate_month']), intval($_POST['olderdate_day']), intval($_POST['olderdate_year']) ); + } + // Continue with delete only inif wherequery is set! + if ( isset($timestamp) ) + { + // --- Ask for deletion first! + if ( (!isset($_GET['verify']) || $_GET['verify'] != "yes") ) + { + // This will print an additional secure check which the user needs to confirm and exit the script execution. + PrintSecureUserCheck( GetAndReplaceLangStr( $content['LN_SOURCES_WARNDELETEDATA'], $content['DisplayName'] ), $content['LN_DELETEYES'], $content['LN_DELETENO'] ); + } + // --- - // Create Lists - CreateOlderThanList( 3600 ); - CreateOlderDateFields(); + // Now perform the data cleanup! + $content['affectedrows'] = $stream->CleanupLogdataByDate($timestamp); + + if ( !isset($content['affectedrows']) ) + { + $content['ISERROR'] = true; + $content['ERROR_MSG'] = GetAndReplaceLangStr( $content['LN_SOURCES_ERROR_DELDATA'], $content['SOURCEID'] ); + } + else + { + // Do the final redirect + RedirectResult( GetAndReplaceLangStr( $content['LN_SOURCES_HASBEENDELDATA'], $content['DisplayName'], $content['affectedrows'] ) , "sources.php" ); + } + } + else + { + $content['ISERROR'] = true; + $content['ERROR_MSG'] = GetAndReplaceLangStr( $content['LN_SOURCES_ERROR_INVALIDCLEANUP'], $content['DisplayName'] ); + } + } + else + { + // Allow Deleting by Date + $content['DELETE_ALLOWDETAIL'] = true; + + // Create Lists + CreateOlderThanList( 3600 ); + CreateOlderDateFields(); + } } else diff --git a/src/classes/logstream.class.php b/src/classes/logstream.class.php index 9b439ac..a643977 100644 --- a/src/classes/logstream.class.php +++ b/src/classes/logstream.class.php @@ -224,6 +224,13 @@ abstract class LogStream { */ public abstract function GetLogStreamTotalRowCount(); + + /** + * Helper function to cleanup all logdata which is older then the nDateTimeStamp! + */ + public abstract function CleanupLogdataByDate( $nDateTimeStamp ); + + /* * Helper functino to trigger initialisation of MsgParsers */ diff --git a/src/classes/logstreamdb.class.php b/src/classes/logstreamdb.class.php index 270a09b..c32cc90 100644 --- a/src/classes/logstreamdb.class.php +++ b/src/classes/logstreamdb.class.php @@ -635,6 +635,45 @@ class LogStreamDB extends LogStream { } + /** + * Implementation of the CleanupLogdataByDate function! Returns affected rows! + */ + public function CleanupLogdataByDate( $nDateTimeStamp ) + { + global $querycount, $dbmapping; + $szTableType = $this->_logStreamConfigObj->DBTableType; + + // Set default rowcount + $rowcount = null; + + + // Perform if Connection is true! + if ( $this->_dbhandle != null ) + { + // Create WHERE attachment + if ( $nDateTimeStamp > 0 ) + $szWhere = " WHERE UNIX_TIMESTAMP(" . $dbmapping[$szTableType][SYSLOG_DATE] . ") < " . $nDateTimeStamp; + else + $szWhere = ""; + + // DELETE DATA NOW! + $szSql = "DELETE FROM " . $this->_logStreamConfigObj->DBTableName . $szWhere; + $myQuery = mysql_query($szSql, $this->_dbhandle); + if ($myQuery) + { + // Get affected rows and return! + $rowcount = mysql_affected_rows(); + + // Free query now + mysql_free_result ($myQuery); + } + } + + //return affected rows + return $rowcount; + } + + /** * Implementation of GetCountSortedByField * diff --git a/src/classes/logstreamdisk.class.php b/src/classes/logstreamdisk.class.php index 897321b..1791256 100644 --- a/src/classes/logstreamdisk.class.php +++ b/src/classes/logstreamdisk.class.php @@ -620,6 +620,30 @@ class LogStreamDisk extends LogStream { } + /** + * Implementation of GetLogStreamTotalRowCount + * + * not implemented yet! + */ + public function GetLogStreamTotalRowCount() + { + //not implemented + return null; + } + + + /** + * Implementation of the CleanupLogdataByDate + * + * not implemented yet! + */ + public function CleanupLogdataByDate( $nDateTimeStamp ) + { + //not implemented + return null; + } + + /** * Implementation of GetCountSortedByField * diff --git a/src/classes/logstreampdo.class.php b/src/classes/logstreampdo.class.php index 132bb1d..8c54411 100644 --- a/src/classes/logstreampdo.class.php +++ b/src/classes/logstreampdo.class.php @@ -569,8 +569,6 @@ class LogStreamPDO extends LogStream { // Free query now $myQuery->closeCursor(); - - // Increment for the Footer Stats $querycount++; } @@ -583,6 +581,82 @@ class LogStreamPDO extends LogStream { } + /** + * Implementation of GetLogStreamTotalRowCount + * + * Returns the total amount of rows in the main datatable + */ + public function GetLogStreamTotalRowCount() + { + global $querycount, $dbmapping; + $szTableType = $this->_logStreamConfigObj->DBTableType; + + // Set default rowcount + $rowcount = null; + + // Perform if Connection is true! + if ( $this->_dbhandle != null ) + { + // Get Total Rowcount + $szSql = "SELECT count(" . $dbmapping[$szTableType][SYSLOG_UID] . ") as Counter FROM " . $this->_logStreamConfigObj->DBTableName; + $myQuery = $this->_dbhandle->query($szSql); + if ( $myQuery ) + { + // Obtain RowCount! + $myRow = $myQuery->fetchColumn(); + $rowcount = $myRow; + + // Free query now + $myQuery->closeCursor(); + + // Increment for the Footer Stats + $querycount++; + } + } + + //return result + return $rowcount; + } + + + /** + * Implementation of the CleanupLogdataByDate function! Returns affected rows! + */ + public function CleanupLogdataByDate( $nDateTimeStamp ) + { + global $querycount, $dbmapping; + $szTableType = $this->_logStreamConfigObj->DBTableType; + + // Set default rowcount + $rowcount = null; + + // Perform if Connection is true! + if ( $this->_dbhandle != null ) + { + // Create WHERE attachment + if ( $nDateTimeStamp > 0 ) + $szWhere = " WHERE " . $dbmapping[$szTableType][SYSLOG_DATE] . " < '" . date('Y-m-d H:i:s', $nDateTimeStamp) . "'"; + else + $szWhere = ""; + + // DELETE DATA NOW! + $szSql = "DELETE FROM " . $this->_logStreamConfigObj->DBTableName . $szWhere; + $myQuery = $this->_dbhandle->query($szSql); + if ( $myQuery ) + { + // Get affected rows and return! + $rowcount = $myQuery->rowCount(); + + // Free query now + $myQuery->closeCursor(); + } + } + + //return affected rows + return $rowcount; + } + + /** * Implementation of GetCountSortedByField * diff --git a/src/lang/de/admin.php b/src/lang/de/admin.php index 84ea314..16f4956 100644 --- a/src/lang/de/admin.php +++ b/src/lang/de/admin.php @@ -241,6 +241,10 @@ $content['LN_SOURCES_CLEAR_HELPTEXT'] = "Attention! Be carefull with deleting da $content['LN_SOURCES_CLEARSINCE'] = "Clear all data older than ... "; $content['LN_SOURCES_CLEARDATE'] = "Clear all data which is older than ... "; $content['LN_SOURCES_CLEARDATA_SEND'] = "Clear selected data range"; +$content['LN_SOURCES_ERROR_INVALIDCLEANUP'] = "Invalid Data Cleanup type"; +$content['LN_SOURCES_WARNDELETEDATA'] = "Are you sure that you want to clear logdata in the '%1' source? This cannot be undone!"; +$content['LN_SOURCES_ERROR_DELDATA'] = "Could not delete data in the '%1' source"; +$content['LN_SOURCES_HASBEENDELDATA'] = "Successfully deleted data from the '%1' source, '%2' rows were affected. "; // Database Upgrade $content['LN_DBUPGRADE_TITLE'] = "phpLogCon Database Update"; diff --git a/src/lang/en/admin.php b/src/lang/en/admin.php index 311618f..70699d4 100644 --- a/src/lang/en/admin.php +++ b/src/lang/en/admin.php @@ -246,6 +246,10 @@ $content['LN_SOURCES_CLEAR_HELPTEXT'] = "Attention! Be carefull with deleting da $content['LN_SOURCES_CLEARSINCE'] = "Clear all data older than ... "; $content['LN_SOURCES_CLEARDATE'] = "Clear all data which is older than ... "; $content['LN_SOURCES_CLEARDATA_SEND'] = "Clear selected data range"; +$content['LN_SOURCES_ERROR_INVALIDCLEANUP'] = "Invalid Data Cleanup type"; +$content['LN_SOURCES_WARNDELETEDATA'] = "Are you sure that you want to clear logdata in the '%1' source? This cannot be undone!"; +$content['LN_SOURCES_ERROR_DELDATA'] = "Could not delete data in the '%1' source"; +$content['LN_SOURCES_HASBEENDELDATA'] = "Successfully deleted data from the '%1' source, '%2' rows were affected. "; // Database Upgrade $content['LN_DBUPGRADE_TITLE'] = "phpLogCon Database Update"; diff --git a/src/lang/pt_BR/admin.php b/src/lang/pt_BR/admin.php index 84ea314..16f4956 100644 --- a/src/lang/pt_BR/admin.php +++ b/src/lang/pt_BR/admin.php @@ -241,6 +241,10 @@ $content['LN_SOURCES_CLEAR_HELPTEXT'] = "Attention! Be carefull with deleting da $content['LN_SOURCES_CLEARSINCE'] = "Clear all data older than ... "; $content['LN_SOURCES_CLEARDATE'] = "Clear all data which is older than ... "; $content['LN_SOURCES_CLEARDATA_SEND'] = "Clear selected data range"; +$content['LN_SOURCES_ERROR_INVALIDCLEANUP'] = "Invalid Data Cleanup type"; +$content['LN_SOURCES_WARNDELETEDATA'] = "Are you sure that you want to clear logdata in the '%1' source? This cannot be undone!"; +$content['LN_SOURCES_ERROR_DELDATA'] = "Could not delete data in the '%1' source"; +$content['LN_SOURCES_HASBEENDELDATA'] = "Successfully deleted data from the '%1' source, '%2' rows were affected. "; // Database Upgrade $content['LN_DBUPGRADE_TITLE'] = "phpLogCon Database Update"; diff --git a/src/templates/admin/admin_sources.html b/src/templates/admin/admin_sources.html index 24a0be1..4640410 100644 --- a/src/templates/admin/admin_sources.html +++ b/src/templates/admin/admin_sources.html @@ -154,13 +154,13 @@ - - - -