From 8c116d25f9d7386d02b5b076027b7cc310cb9c08 Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Wed, 25 Mar 2009 17:56:19 +0100 Subject: [PATCH] Added support for administrating and configuring custom database mappings This makes it possible to support a wider range of database table layouts. --- src/admin/dbmappings.php | 598 ++++++++++++++++++++++ src/classes/logstreamdb.class.php | 50 +- src/classes/logstreampdo.class.php | 54 +- src/include/constants_logstream.php | 44 +- src/include/db_update_v8.txt | 11 + src/include/functions_common.php | 6 +- src/include/functions_config.php | 68 +++ src/include/functions_db.php | 2 +- src/lang/en/admin.php | 29 +- src/templates/admin/admin_dbmappings.html | 133 +++++ src/templates/admin/admin_menu.html | 5 +- 11 files changed, 922 insertions(+), 78 deletions(-) create mode 100644 src/admin/dbmappings.php create mode 100644 src/include/db_update_v8.txt create mode 100644 src/templates/admin/admin_dbmappings.html diff --git a/src/admin/dbmappings.php b/src/admin/dbmappings.php new file mode 100644 index 0000000..653e469 --- /dev/null +++ b/src/admin/dbmappings.php @@ -0,0 +1,598 @@ + Helps administrating custom database mappings + * + * All directives are explained within this file + * + * Copyright (C) 2008 Adiscon GmbH. + * + * This file is part of phpLogCon. + * + * PhpLogCon is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * PhpLogCon is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with phpLogCon. If not, see . + * + * A copy of the GPL can be found in the file "COPYING" in this + * distribution + ********************************************************************* +*/ + +// *** Default includes and procedures *** // +define('IN_PHPLOGCON', true); +$gl_root_path = './../'; + +// Now include necessary include files! +include($gl_root_path . 'include/functions_common.php'); +include($gl_root_path . 'include/functions_frontendhelpers.php'); +include($gl_root_path . 'include/functions_filters.php'); + +// Set PAGE to be ADMINPAGE! +define('IS_ADMINPAGE', true); +$content['IS_ADMINPAGE'] = true; +InitPhpLogCon(); +InitSourceConfigs(); +InitFrontEndDefaults(); // Only in WebFrontEnd +InitFilterHelpers(); // Helpers for frontend filtering! + +// Init admin langauge file now! +IncludeLanguageFile( $gl_root_path . '/lang/' . $LANG . '/admin.php' ); +// --- + +// --- BEGIN Custom Code + +// Only if the user is an admin! +if ( !isset($_SESSION['SESSION_ISADMIN']) || $_SESSION['SESSION_ISADMIN'] == 0 ) + DieWithFriendlyErrorMsg( $content['LN_ADMIN_ERROR_NOTALLOWED'] ); + +// Init helper variable to empty string +$content['FormUrlAddOP'] = ""; + +if ( isset($_GET['op']) ) +{ + if ($_GET['op'] == "add") + { + // Set Mode to add + $content['ISEDITORNEWDBMP'] = "true"; + $content['DBMP_FORMACTION'] = "addnewdbmp"; + $content['DBMP_SENDBUTTON'] = $content['LN_DBMP_ADD']; + + //PreInit these values + $content['DisplayName'] = ""; + $content['DBMPID'] = ""; + $content['FormUrlAddOP'] = "?op=add"; + } + else if ($_GET['op'] == "edit") + { + // Set Mode to edit + $content['ISEDITORNEWDBMP'] = "true"; + $content['DBMP_FORMACTION'] = "editdbmp"; + $content['DBMP_SENDBUTTON'] = $content['LN_DBMP_EDIT']; + + // Copy Views array for further modifications + $content['DBMP'] = $dbmapping; + + // View must be loaded as well already! + if ( isset($_GET['id']) && isset($content['DBMP'][$_GET['id']]) ) + { + //PreInit these values + $content['DBMPID'] = DB_RemoveBadChars($_GET['id']); + if ( isset($content['DBMP'][ $content['DBMPID'] ]) ) + { + //Set the FormAdd URL + $content['FormUrlAddOP'] = "?op=edit&id=" . $content['DBMPID']; + + $mymapping = $content['DBMP'][ $content['DBMPID'] ]; + $content['DisplayName'] = $mymapping['DisplayName'] ; + $content['SUBMAPPINGS'] = $mymapping['DBMAPPINGS']; + } + else + { + $content['ISEDITORNEWDBMP'] = false; + $content['ISERROR'] = true; + $content['ERROR_MSG'] = GetAndReplaceLangStr( $content['LN_DBMP_ERROR_IDNOTFOUND'], $content['DBMPID'] ); + } + } + else + { + $content['ISEDITORNEWDBMP'] = false; + $content['ISERROR'] = true; + $content['ERROR_MSG'] = GetAndReplaceLangStr( $content['LN_DBMP_ERROR_INVALIDID'], isset($_GET['id']) ? $_GET['id'] : "" ); + } + } + else if ($_GET['op'] == "delete") + { + if ( isset($_GET['id']) ) + { + //PreInit these values + $content['DBMPID'] = DB_RemoveBadChars($_GET['id']); + + // Get UserInfo + $result = DB_Query("SELECT DisplayName FROM " . DB_MAPPINGS . " WHERE ID = " . $content['DBMPID'] ); + $myrow = DB_GetSingleRow($result, true); + if ( !isset($myrow['DisplayName']) ) + { + $content['ISERROR'] = true; + $content['ERROR_MSG'] = GetAndReplaceLangStr( $content['LN_DBMP_ERROR_IDNOTFOUND'], $content['DBMPID'] ); + } + + // --- 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_DBMP_WARNDELETEMAPPING'], $myrow['DisplayName'] ), $content['LN_DELETEYES'], $content['LN_DELETENO'] ); + } + // --- + + // do the delete! + $result = DB_Query( "DELETE FROM " . DB_MAPPINGS . " WHERE ID = " . $content['DBMPID'] ); + if ($result == FALSE) + { + $content['ISERROR'] = true; + $content['ERROR_MSG'] = GetAndReplaceLangStr( $content['LN_DBMP_ERROR_DELSEARCH'], $content['DBMPID'] ); + } + else + DB_FreeQuery($result); + + // Do the final redirect + RedirectResult( GetAndReplaceLangStr( $content['LN_DBMP_ERROR_HASBEENDEL'], $myrow['DisplayName'] ) , "dbmappings.php" ); + } + else + { + $content['ISERROR'] = true; + $content['ERROR_MSG'] = $content['LN_DBMP_ERROR_INVALIDID']; + } + } +} + +// --- Additional work todo for the edit view +if ( isset($content['ISEDITORNEWDBMP']) && $content['ISEDITORNEWDBMP'] ) +{ + // If Columns are send using POST we use them, otherwise we try to use from the view itself, if available + if ( isset($_POST['Mappings']) ) + $AllMappings = $_POST['Mappings']; + else if ( isset($content['SUBMAPPINGS']) ) + $AllMappings = $content['SUBMAPPINGS']; + + // Read Columns from FORM data! + if ( isset($AllMappings) ) + { + // --- Read Columns from Formdata + if ( is_array($AllMappings) ) + { + // Copy columns ID's + foreach ($AllMappings as $myColKey => $myFieldName) // $myColKey) + { + if ( !is_numeric($myColKey) ) + $content['SUBMAPPINGS'][$myColKey] = array( 'MappingFieldID' => $myColKey, 'MappingDbFieldName' => $myFieldName ); + else + $content['SUBMAPPINGS'][$myFieldName] = array( 'MappingFieldID' => $myFieldName ); + } + } + else // One element only + $content['SUBMAPPINGS'][$AllColumns]['MappingFieldID'] = $AllColumns; + // --- + + // --- Process Columns for display + $i = 0; // Help counter! + foreach ($content['SUBMAPPINGS'] as $key => &$myColumn ) + { + // Set Fieldcaption + if ( isset($fields[$key]) && isset($fields[$key]['FieldCaption']) ) + $myColumn['MappingCaption'] = $fields[$key]['FieldCaption']; + else + $myColumn['MappingCaption'] = $key; + + // Append Internal FieldID + $myColumn['MappingInternalID'] = $fields[$key]['FieldDefine']; + + // Set Mapping Fieldname + if ( isset( $_POST[ $myColumn['MappingFieldID'] ]) ) + $myColumn['MappingDbFieldName'] = $_POST[ $myColumn['MappingFieldID'] ]; + else if ( !isset($myColumn['MappingDbFieldName']) && strlen($myColumn['MappingDbFieldName']) > 0) + $myColumn['MappingDbFieldName'] = ""; + + // --- Set CSS Class + if ( $i % 2 == 0 ) + $myColumn['colcssclass'] = "line1"; + else + $myColumn['colcssclass'] = "line2"; + $i++; + // --- + } + // --- + + } + + // --- Copy fields data array + $content['FIELDS'] = $fields; + + // removed already added fields + if ( isset($content['SUBMAPPINGS']) ) + { + foreach ($content['SUBMAPPINGS'] as $key => &$myColumn ) + { + if ( isset($content['FIELDS'][$key]) ) + unset($content['FIELDS'][$key]); + } + } + + // set fieldcaption + foreach ($content['FIELDS'] as $key => &$myField ) + { + // Set Fieldcaption + if ( isset($myField['FieldCaption']) ) + $myField['FieldCaption'] = $myField['FieldCaption']; + else + $myField['FieldCaption'] = $key; + + // Append Internal FieldID + $myField['FieldCaption'] .= " (" . $fields[$key]['FieldDefine'] . ")"; + } + // --- +} +// --- + +// --- Process POST Form Data +if ( isset($_POST['op']) ) +{ + if ( isset ($_POST['id']) ) { $content['DBMPID'] = DB_RemoveBadChars($_POST['id']); } else {$content['DBMPID'] = ""; } + if ( isset ($_POST['DisplayName']) ) { $content['DisplayName'] = DB_StripSlahes($_POST['DisplayName']); } else {$content['DisplayName'] = ""; } + + // --- Check mandotary values + if ( $content['DisplayName'] == "" ) + { + $content['ISERROR'] = true; + $content['ERROR_MSG'] = $content['LN_DBMP_ERROR_DISPLAYNAMEEMPTY']; + } + // --- + + if ( !isset($content['ISERROR']) ) + { + // Check subop's first! + if ( isset($_POST['subop']) ) + { + if ( isset($_POST['newmapping']) ) + { + // Get NewColID + $szColId = DB_RemoveBadChars($_POST['newmapping']); + + // Add a new Column into our list! + if ( $_POST['subop'] == $content['LN_DBMP_ADDMAPPING'] && isset($_POST['newmapping']) ) + { + // Add New entry into columnlist + $content['SUBMAPPINGS'][$szColId]['MappingFieldID'] = $szColId; + + // Set Internal FieldID + $content['SUBMAPPINGS'][$szColId]['MappingInternalID'] = $fields[$szColId]['FieldDefine']; + + // Set default for DbFieldName + $content['SUBMAPPINGS'][$szColId]['MappingDbFieldName'] = ""; + + // Set Fieldcaption + if ( isset($fields[$szColId]['FieldCaption']) ) + $content['SUBMAPPINGS'][$szColId]['MappingCaption'] = $fields[$szColId]['FieldCaption']; + else + $content['SUBMAPPINGS'][$szColId]['MappingCaption'] = $szColId; + + // Set CSSClass + $content['SUBMAPPINGS'][$szColId]['colcssclass'] = count($content['SUBMAPPINGS']) % 2 == 0 ? "line1" : "line2"; + + // Remove from fields list as well + if ( isset($content['FIELDS'][$szColId]) ) + unset($content['FIELDS'][$szColId]); + } + } + } + else if ( isset($_POST['subop_edit']) ) + { + // Actually nothing todo ;), the edit is performed automatically when the SUBMAPPINGS array is created. + } + else if ( isset($_POST['subop_delete']) ) + { + // Get Column ID + $szColId = DB_RemoveBadChars($_POST['subop_delete']); + + // Remove Entry from Columnslist + if ( isset($content['SUBMAPPINGS'][$szColId]) ) + unset($content['SUBMAPPINGS'][$szColId]); + + // Add removed entry to field list + $content['FIELDS'][$szColId] = $fields[$szColId]; + + // Set Fieldcaption + if ( isset($content['FIELDS'][$szColId]['FieldCaption']) ) + $content['FIELDS'][$szColId]['FieldCaption'] = $content['FIELDS'][$szColId]['FieldCaption']; + else + $content['FIELDS'][$szColId]['FieldCaption'] = $szColId; + + // Append Internal FieldID + $content['FIELDS'][$szColId]['FieldCaption'] .= " (" . $content['FIELDS'][$szColId]['FieldDefine'] . ")"; + } + else if ( isset($_POST['subop_moveup']) ) + { + // Get Column ID + $szColId = DB_RemoveBadChars($_POST['subop_moveup']); + + // --- Move Entry one UP in Columnslist + // Find the entry in the array + $iArrayNum = 0; + foreach ($content['SUBMAPPINGS'] as $key => &$myColumn ) + { + if ( $key == $szColId ) + break; + + $iArrayNum++; + } + + // If found move up + if ( $iArrayNum > 0 ) + { + // Extract Entry from the array + $EntryTwoMove = array_slice($content['SUBMAPPINGS'], $iArrayNum, 1); + + // Unset Entry from the array + unset( $content['SUBMAPPINGS'][$szColId] ); + + // Splice the array order! + array_splice($content['SUBMAPPINGS'], $iArrayNum-1, 0, $EntryTwoMove); + } + // --- + } + else if ( isset($_POST['subop_movedown']) ) + { + // Get Column ID + $szColId = DB_RemoveBadChars($_POST['subop_movedown']); + + // --- Move Entry one DOWN in Columnslist + // Find the entry in the array + $iArrayNum = 0; + foreach ($content['SUBMAPPINGS'] as $key => &$myColumn ) + { + if ( $key == $szColId ) + break; + + $iArrayNum++; + } + + // If found move down + if ( $iArrayNum < count($content['SUBMAPPINGS']) ) + { + // Extract Entry from the array + $EntryTwoMove = array_slice($content['SUBMAPPINGS'], $iArrayNum, 1); + + // Unset Entry from the array + unset( $content['SUBMAPPINGS'][$szColId] ); + + // Splice the array order! + array_splice($content['SUBMAPPINGS'], $iArrayNum+1, 0, $EntryTwoMove); + } + // --- + } + else // Now SUBOP means normal processing! + { + // Now we convert fr DB insert! + $content['DisplayName'] = DB_RemoveBadChars($_POST['DisplayName']); + + // Everything was alright, so we go to the next step! + if ( $_POST['op'] == "addnewdbmp" ) + { + // Create Columnlist comma seperated! + if ( isset($_POST['Mappings']) && is_array($_POST['Mappings']) ) + { + // Copy columns ID's + foreach ($_POST['Mappings'] as $myColKey) + { + if ( isset($_POST[$myColKey]) && strlen($_POST[$myColKey]) > 0 ) + { + // Get FieldName + $myMappingFieldName = DB_StripSlahes($_POST[$myColKey]); + + if ( isset($content['SUBMAPPINGS']) ) + $content['SUBMAPPINGS'] .= "," . $myColKey; + else + $content['SUBMAPPINGS'] = $myColKey; + + // Append Fieldname + $content['SUBMAPPINGS'] .= "=>" . $myMappingFieldName; + } + else + { + // Report error! + $content['ISEDITORNEWDBMP'] = false; + $content['ISERROR'] = true; + $content['ERROR_MSG'] = GetAndReplaceLangStr( $content['LN_DBMP_ERROR_MISSINGFIELDNAME'], $myColKey ); + + // Abort loop + break; + } + } + + // Only perform if no error occured + if ( !isset($content['ISERROR']) ) + { + // Add custom search now! + $sqlquery = "INSERT INTO " . DB_MAPPINGS. " (DisplayName, Mappings) + VALUES ('" . $content['DisplayName'] . "', + '" . $content['SUBMAPPINGS'] . "' + )"; + $result = DB_Query($sqlquery); + DB_FreeQuery($result); + + // Do the final redirect + RedirectResult( GetAndReplaceLangStr( $content['LN_DBMP_HASBEENADDED'], DB_StripSlahes($content['DisplayName']) ) , "dbmappings.php" ); + } + } + else + { + $content['ISERROR'] = true; + $content['ERROR_MSG'] = $content['LN_DBMP_ERROR_NOCOLUMNS']; + } + } + else if ( $_POST['op'] == "editdbmp" ) + { + // Now we convert fr DB insert! + $content['DisplayName'] = DB_RemoveBadChars($_POST['DisplayName']); + + $result = DB_Query("SELECT ID FROM " . DB_MAPPINGS . " WHERE ID = " . $content['DBMPID']); + $myrow = DB_GetSingleRow($result, true); + if ( !isset($myrow['ID']) ) + { + $content['ISERROR'] = true; + $content['ERROR_MSG'] = GetAndReplaceLangStr( $content['LN_DBMP_ERROR_IDNOTFOUND'], $content['DBMPID'] ); + } + else + { + // Create Columnlist comma seperated! + if ( isset($_POST['Mappings']) && is_array($_POST['Mappings']) ) + { + // Copy columns ID's + unset($content['SUBMAPPINGS']); + foreach ($_POST['Mappings'] as $myColKey) + { + if ( isset($_POST[$myColKey]) && strlen($_POST[$myColKey]) > 0 ) + { + // Get FieldName + $myMappingFieldName = DB_StripSlahes($_POST[$myColKey]); + + if ( isset($content['SUBMAPPINGS']) ) + $content['SUBMAPPINGS'] .= "," . $myColKey; + else + $content['SUBMAPPINGS'] = $myColKey; + + // Append Fieldname + $content['SUBMAPPINGS'] .= "=>" . $myMappingFieldName; + } + else + { + // Report error! + $content['ISEDITORNEWDBMP'] = false; + $content['ISERROR'] = true; + $content['ERROR_MSG'] = GetAndReplaceLangStr( $content['LN_DBMP_ERROR_MISSINGFIELDNAME'], $myColKey ); + + // Abort loop + break; + } + } + + // Only perform if no error occured + if ( !isset($content['ISERROR']) ) + { + // Edit the Search Entry now! + $result = DB_Query("UPDATE " . DB_MAPPINGS . " SET + DisplayName = '" . $content['DisplayName'] . "', + Mappings = '" . $content['SUBMAPPINGS'] . "' + WHERE ID = " . $content['DBMPID']); + DB_FreeQuery($result); + + // Done redirect! + RedirectResult( GetAndReplaceLangStr( $content['LN_DBMP_HASBEENEDIT'], DB_StripSlahes($content['DisplayName']) ) , "dbmappings.php" ); + } + } + else + { + $content['ISERROR'] = true; + $content['ERROR_MSG'] = $content['LN_DBMP_ERROR_NOCOLUMNS']; + } + } + } + } + } +} + +if ( !isset($_POST['op']) && !isset($_GET['op']) ) +{ + // Default Mode = List Searches + $content['LISTDBMAPPINGS'] = "true"; + + // Copy Views array for further modifications + $content['DBMP'] = $dbmapping; + + // --- Process Views + $i = 0; // Help counter! + foreach ($content['DBMP'] as &$myMappings ) + { + // So internal Views can not be edited but seen + if ( is_numeric($myMappings['ID']) ) + { + $myMappings['ActionsAllowed'] = true; + + // --- Set Image for Type + $myMappings['ViewTypeImage'] = $content["MENU_GLOBAL"]; + $myMappings['ViewTypeText'] = $content["LN_GEN_GLOBAL"]; + + // Check if is ADMIN User, deny if normal user! + if ( !isset($_SESSION['SESSION_ISADMIN']) || $_SESSION['SESSION_ISADMIN'] == 0 ) + $myMappings['ActionsAllowed'] = false; + // --- + } + else + { + $myMappings['ActionsAllowed'] = false; + + $myMappings['ViewTypeImage'] = $content["MENU_INTERNAL"]; + $myMappings['ViewTypeText'] = $content["LN_GEN_INTERNAL"]; + } + + // --- Add DisplayNames to columns + $iBegin = true; + foreach ($myMappings['DBMAPPINGS'] as $myKey => &$myMapping ) + { + // Set Fieldcaption + if ( isset($fields[$myKey]) && isset($fields[$myKey]['FieldCaption']) ) + $myMappings['MYMAPPINGS'][$myKey]['FieldCaption'] = $fields[$myKey]['FieldCaption']; + else + $myMappings['MYMAPPINGS'][$myKey]['FieldCaption'] = $myKey; + + // Set other fields + $myMappings['MYMAPPINGS'][$myKey]['FieldID'] = $myKey; + $myMappings['MYMAPPINGS'][$myKey]['FieldMapping'] = $myMapping; + + // Set seperator + if ( $iBegin ) + { + $myMappings['MYMAPPINGS'][$myKey]['CaptionSeperator'] = ""; + $iBegin = false; + } + else + $myMappings['MYMAPPINGS'][$myKey]['CaptionSeperator'] = ", "; + } + // --- + + // --- Set CSS Class + if ( $i % 2 == 0 ) + $myMappings['cssclass'] = "line1"; + else + $myMappings['cssclass'] = "line2"; + $i++; + // --- + } + // --- +} +// --- END Custom Code + +// --- BEGIN CREATE TITLE +$content['TITLE'] = InitPageTitle(); +$content['TITLE'] .= " :: " . $content['LN_ADMINMENU_DBMAPPINGOPT']; +// --- END CREATE TITLE + +// --- Parsen and Output +InitTemplateParser(); +$page -> parser($content, "admin/admin_dbmappings.html"); +$page -> output(); +// --- + +?> \ No newline at end of file diff --git a/src/classes/logstreamdb.class.php b/src/classes/logstreamdb.class.php index 5cdf750..4b42bba 100644 --- a/src/classes/logstreamdb.class.php +++ b/src/classes/logstreamdb.class.php @@ -249,10 +249,10 @@ class LogStreamDB extends LogStream { foreach ( $this->_arrProperties as $property ) { // Check if mapping exists - if ( isset($dbmapping[$szTableType][$property]) ) + if ( isset($dbmapping[$szTableType]['DBMAPPINGS'][$property]) ) { // Copy property if available! - $dbfieldname = $dbmapping[$szTableType][$property]; + $dbfieldname = $dbmapping[$szTableType]['DBMAPPINGS'][$property]; if ( isset($this->bufferedRecords[$this->_currentRecordNum][$dbfieldname]) ) { if ( isset($fields[$property]['FieldType']) && $fields[$property]['FieldType'] == FILTER_TYPE_DATE ) // Handle as date! @@ -278,7 +278,7 @@ class LogStreamDB extends LogStream { } // Set uID to the PropertiesOut! //DEBUG -> $this->_currentRecordNum; - $uID = $arrProperitesOut[SYSLOG_UID] = $this->bufferedRecords[$this->_currentRecordNum][$dbmapping[$szTableType][SYSLOG_UID]]; + $uID = $arrProperitesOut[SYSLOG_UID] = $this->bufferedRecords[$this->_currentRecordNum][$dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_UID]]; // Increment $_currentRecordNum $this->_currentRecordNum++; @@ -440,7 +440,7 @@ class LogStreamDB extends LogStream { if ( strlen($this->_SQLwhereClause) > 0 && !$this->_logStreamConfigObj->DBEnableRowCounting ) return $this->_firstPageUID; - $szSql = "SELECT MAX(" . $dbmapping[$szTableType][SYSLOG_UID] . ") FROM " . $this->_logStreamConfigObj->DBTableName . $this->_SQLwhereClause; + $szSql = "SELECT MAX(" . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_UID] . ") FROM " . $this->_logStreamConfigObj->DBTableName . $this->_SQLwhereClause; $myQuery = mysql_query($szSql, $this->_dbhandle); if ($myQuery) { @@ -472,7 +472,7 @@ class LogStreamDB extends LogStream { if ( strlen($this->_SQLwhereClause) > 0 && !$this->_logStreamConfigObj->DBEnableRowCounting ) return $this->_lastPageUID; - $szSql = "SELECT MIN(" . $dbmapping[$szTableType][SYSLOG_UID] . ") FROM " . $this->_logStreamConfigObj->DBTableName . $this->_SQLwhereClause; + $szSql = "SELECT MIN(" . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_UID] . ") FROM " . $this->_logStreamConfigObj->DBTableName . $this->_SQLwhereClause; $myQuery = mysql_query($szSql, $this->_dbhandle); if ($myQuery) { @@ -625,7 +625,7 @@ class LogStreamDB extends LogStream { if ( $this->_dbhandle != null ) { // SHOW TABLE STATUS FROM - $szSql = "SELECT count(" . $dbmapping[$szTableType][SYSLOG_UID] . ") as Counter FROM " . $this->_logStreamConfigObj->DBTableName; + $szSql = "SELECT count(" . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_UID] . ") as Counter FROM " . $this->_logStreamConfigObj->DBTableName; $myQuery = mysql_query($szSql, $this->_dbhandle); if ($myQuery) { @@ -663,7 +663,7 @@ class LogStreamDB extends LogStream { { // Create WHERE attachment if ( $nDateTimeStamp > 0 ) - $szWhere = " WHERE UNIX_TIMESTAMP(" . $dbmapping[$szTableType][SYSLOG_DATE] . ") < " . $nDateTimeStamp; + $szWhere = " WHERE UNIX_TIMESTAMP(" . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_DATE] . ") < " . $nDateTimeStamp; else $szWhere = ""; @@ -699,10 +699,10 @@ class LogStreamDB extends LogStream { // Copy helper variables, this is just for better readability $szTableType = $this->_logStreamConfigObj->DBTableType; - if ( isset($dbmapping[$szTableType][$szFieldId]) ) + if ( isset($dbmapping[$szTableType]['DBMAPPINGS'][$szFieldId]) ) { // Set DB Field name first! - $myDBFieldName = $dbmapping[$szTableType][$szFieldId]; + $myDBFieldName = $dbmapping[$szTableType]['DBMAPPINGS'][$szFieldId]; $myDBQueryFieldName = $myDBFieldName; $mySelectFieldName = $myDBFieldName; @@ -777,7 +777,7 @@ class LogStreamDB extends LogStream { foreach( $this->_filters[$propertyname] as $myfilter ) { // Only perform if database mapping is available for this filter! - if ( isset($dbmapping[$szTableType][$propertyname]) ) + if ( isset($dbmapping[$szTableType]['DBMAPPINGS'][$propertyname]) ) { switch( $myfilter[FILTER_TYPE] ) { @@ -842,11 +842,11 @@ class LogStreamDB extends LogStream { // Now Create LIKE Filters if ( isset($tmpfilters[$propertyname]) ) - $tmpfilters[$propertyname][FILTER_VALUE] .= $addor . $dbmapping[$szTableType][$propertyname] . $addnod . $szSearchBegin . DB_RemoveBadChars($myfilter[FILTER_VALUE]) . $szSearchEnd; + $tmpfilters[$propertyname][FILTER_VALUE] .= $addor . $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . $addnod . $szSearchBegin . DB_RemoveBadChars($myfilter[FILTER_VALUE]) . $szSearchEnd; else { $tmpfilters[$propertyname][FILTER_TYPE] = FILTER_TYPE_STRING; - $tmpfilters[$propertyname][FILTER_VALUE] = $dbmapping[$szTableType][$propertyname] . $addnod . $szSearchBegin . DB_RemoveBadChars($myfilter[FILTER_VALUE]) . $szSearchEnd; + $tmpfilters[$propertyname][FILTER_VALUE] = $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . $addnod . $szSearchBegin . DB_RemoveBadChars($myfilter[FILTER_VALUE]) . $szSearchEnd; } break; case FILTER_TYPE_NUMBER: @@ -860,7 +860,7 @@ class LogStreamDB extends LogStream { else { $tmpfilters[$szArrayKey][FILTER_TYPE] = FILTER_TYPE_NUMBER; - $tmpfilters[$szArrayKey][FILTER_VALUE] = $dbmapping[$szTableType][$propertyname] . " NOT IN (" . DB_RemoveBadChars($myfilter[FILTER_VALUE]); + $tmpfilters[$szArrayKey][FILTER_VALUE] = $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " NOT IN (" . DB_RemoveBadChars($myfilter[FILTER_VALUE]); } } else @@ -871,7 +871,7 @@ class LogStreamDB extends LogStream { else { $tmpfilters[$propertyname][FILTER_TYPE] = FILTER_TYPE_NUMBER; - $tmpfilters[$propertyname][FILTER_VALUE] = $dbmapping[$szTableType][$propertyname] . " IN (" . DB_RemoveBadChars($myfilter[FILTER_VALUE]); + $tmpfilters[$propertyname][FILTER_VALUE] = $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " IN (" . DB_RemoveBadChars($myfilter[FILTER_VALUE]); } } // --- @@ -908,19 +908,19 @@ class LogStreamDB extends LogStream { } // Append filter - $tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType][$propertyname] . " > '" . date("Y-m-d H:i:s", $nNowTimeStamp) . "'"; + $tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " > '" . date("Y-m-d H:i:s", $nNowTimeStamp) . "'"; } else if ( $myfilter[FILTER_DATEMODE] == DATEMODE_RANGE_FROM ) { // Obtain Event struct for the time! $myeventtime = GetEventTime($myfilter[FILTER_VALUE]); - $tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType][$propertyname] . " > '" . date("Y-m-d H:i:s", $myeventtime[EVTIME_TIMESTAMP]) . "'"; + $tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " > '" . date("Y-m-d H:i:s", $myeventtime[EVTIME_TIMESTAMP]) . "'"; } else if ( $myfilter[FILTER_DATEMODE] == DATEMODE_RANGE_TO ) { // Obtain Event struct for the time! $myeventtime = GetEventTime($myfilter[FILTER_VALUE]); - $tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType][$propertyname] . " < '" . date("Y-m-d H:i:s", $myeventtime[EVTIME_TIMESTAMP]) . "'"; + $tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " < '" . date("Y-m-d H:i:s", $myeventtime[EVTIME_TIMESTAMP]) . "'"; } break; @@ -1154,9 +1154,9 @@ class LogStreamDB extends LogStream { // Create Basic SQL String if ( $this->_logStreamConfigObj->DBEnableRowCounting ) // with SQL_CALC_FOUND_ROWS - $sqlString = "SELECT SQL_CALC_FOUND_ROWS " . $dbmapping[$szTableType][SYSLOG_UID]; + $sqlString = "SELECT SQL_CALC_FOUND_ROWS " . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_UID]; else // without row calc - $sqlString = "SELECT " . $dbmapping[$szTableType][SYSLOG_UID]; + $sqlString = "SELECT " . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_UID]; // Append fields if needed if ( $includeFields && $this->_arrProperties != null ) @@ -1165,10 +1165,10 @@ class LogStreamDB extends LogStream { foreach ( $this->_arrProperties as $myproperty ) { // SYSLOG_UID already added! - if ( $myproperty != SYSLOG_UID && isset($dbmapping[$szTableType][$myproperty]) ) + if ( $myproperty != SYSLOG_UID && isset($dbmapping[$szTableType]['DBMAPPINGS'][$myproperty]) ) { // Append field! - $sqlString .= ", " . $dbmapping[$szTableType][$myproperty]; + $sqlString .= ", " . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty]; } } } @@ -1188,16 +1188,16 @@ class LogStreamDB extends LogStream { $myOperator = "<="; if ( strlen($this->_SQLwhereClause) > 0 ) - $sqlString .= " AND " . $dbmapping[$szTableType][SYSLOG_UID] . " $myOperator $uID"; + $sqlString .= " AND " . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_UID] . " $myOperator $uID"; else - $sqlString .= " WHERE " . $dbmapping[$szTableType][SYSLOG_UID] . " $myOperator $uID"; + $sqlString .= " WHERE " . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_UID] . " $myOperator $uID"; } // Append ORDER clause if ( $this->_readDirection == EnumReadDirection::Forward ) - $sqlString .= " ORDER BY " . $dbmapping[$szTableType][$szSortColumn]; + $sqlString .= " ORDER BY " . $dbmapping[$szTableType]['DBMAPPINGS'][$szSortColumn]; else if ( $this->_readDirection == EnumReadDirection::Backward ) - $sqlString .= " ORDER BY " . $dbmapping[$szTableType][$szSortColumn] . " DESC"; + $sqlString .= " ORDER BY " . $dbmapping[$szTableType]['DBMAPPINGS'][$szSortColumn] . " DESC"; // return SQL result string: return $sqlString; diff --git a/src/classes/logstreampdo.class.php b/src/classes/logstreampdo.class.php index 04b8142..d8d3e2a 100644 --- a/src/classes/logstreampdo.class.php +++ b/src/classes/logstreampdo.class.php @@ -191,7 +191,7 @@ class LogStreamPDO extends LogStream { try { // This is one way to check if the table exists! But I don't really like it tbh -.- - $szIdField = $dbmapping[$this->_logStreamConfigObj->DBTableType][SYSLOG_UID]; + $szIdField = $dbmapping[$this->_logStreamConfigObj->DBTableType]['DBMAPPINGS'][SYSLOG_UID]; $szTestQuery = "SELECT MAX(" . $szIdField . ") FROM " . $this->_logStreamConfigObj->DBTableName; $tmpStmnt = $this->_dbhandle->prepare( $szTestQuery ); $tmpStmnt->execute(); @@ -296,10 +296,10 @@ class LogStreamPDO extends LogStream { foreach ( $this->_arrProperties as $property ) { // Check if mapping exists - if ( isset($dbmapping[$szTableType][$property]) ) + if ( isset($dbmapping[$szTableType]['DBMAPPINGS'][$property]) ) { // Copy property if available! - $dbfieldname = $dbmapping[$szTableType][$property]; + $dbfieldname = $dbmapping[$szTableType]['DBMAPPINGS'][$property]; if ( isset($this->bufferedRecords[$this->_currentRecordNum][$dbfieldname]) ) { if ( isset($fields[$property]['FieldType']) && $fields[$property]['FieldType'] == FILTER_TYPE_DATE ) // Handle as date! @@ -325,7 +325,7 @@ class LogStreamPDO extends LogStream { } // Set uID to the PropertiesOut! //DEBUG -> $this->_currentRecordNum; - $uID = $arrProperitesOut[SYSLOG_UID] = $this->bufferedRecords[$this->_currentRecordNum][$dbmapping[$szTableType][SYSLOG_UID]]; + $uID = $arrProperitesOut[SYSLOG_UID] = $this->bufferedRecords[$this->_currentRecordNum][$dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_UID]]; // Increment $_currentRecordNum $this->_currentRecordNum++; @@ -474,7 +474,7 @@ class LogStreamPDO extends LogStream { global $querycount, $dbmapping; $szTableType = $this->_logStreamConfigObj->DBTableType; - $szSql = "SELECT MAX(" . $dbmapping[$szTableType][SYSLOG_UID] . ") FROM " . $this->_logStreamConfigObj->DBTableName . $this->_SQLwhereClause; + $szSql = "SELECT MAX(" . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_UID] . ") FROM " . $this->_logStreamConfigObj->DBTableName . $this->_SQLwhereClause; $myQuery = $this->_dbhandle->query($szSql); if ( $myQuery ) { @@ -504,7 +504,7 @@ class LogStreamPDO extends LogStream { global $querycount, $dbmapping; $szTableType = $this->_logStreamConfigObj->DBTableType; - $szSql = "SELECT MIN(" . $dbmapping[$szTableType][SYSLOG_UID] . ") FROM " . $this->_logStreamConfigObj->DBTableName . $this->_SQLwhereClause; + $szSql = "SELECT MIN(" . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_UID] . ") FROM " . $this->_logStreamConfigObj->DBTableName . $this->_SQLwhereClause; $myQuery = $this->_dbhandle->query($szSql); if ( $myQuery ) { @@ -572,7 +572,7 @@ class LogStreamPDO extends LogStream { // SHOW TABLE STATUS FROM $stats = NULL; - $szSql = "SELECT count(" . $dbmapping[$szTableType][SYSLOG_UID] . ") as Counter FROM " . $this->_logStreamConfigObj->DBTableName; + $szSql = "SELECT count(" . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_UID] . ") as Counter FROM " . $this->_logStreamConfigObj->DBTableName; $myQuery = $this->_dbhandle->query($szSql); if ( $myQuery ) { @@ -617,7 +617,7 @@ class LogStreamPDO extends LogStream { if ( $this->_dbhandle != null ) { // Get Total Rowcount - $szSql = "SELECT count(" . $dbmapping[$szTableType][SYSLOG_UID] . ") as Counter FROM " . $this->_logStreamConfigObj->DBTableName; + $szSql = "SELECT count(" . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_UID] . ") as Counter FROM " . $this->_logStreamConfigObj->DBTableName; $myQuery = $this->_dbhandle->query($szSql); if ( $myQuery ) { @@ -654,7 +654,7 @@ class LogStreamPDO extends LogStream { { // Create WHERE attachment if ( $nDateTimeStamp > 0 ) - $szWhere = " WHERE " . $dbmapping[$szTableType][SYSLOG_DATE] . " < '" . date('Y-m-d H:i:s', $nDateTimeStamp) . "'"; + $szWhere = " WHERE " . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_DATE] . " < '" . date('Y-m-d H:i:s', $nDateTimeStamp) . "'"; else $szWhere = ""; @@ -690,10 +690,10 @@ class LogStreamPDO extends LogStream { // Copy helper variables, this is just for better readability $szTableType = $this->_logStreamConfigObj->DBTableType; - if ( isset($dbmapping[$szTableType][$szFieldId]) ) + if ( isset($dbmapping[$szTableType]['DBMAPPINGS'][$szFieldId]) ) { // Set DB Field name first! - $myDBFieldName = $dbmapping[$szTableType][$szFieldId]; + $myDBFieldName = $dbmapping[$szTableType]['DBMAPPINGS'][$szFieldId]; $myDBQueryFieldName = $myDBFieldName; $mySelectFieldName = $myDBFieldName; @@ -795,7 +795,7 @@ class LogStreamPDO extends LogStream { foreach( $this->_filters[$propertyname] as $myfilter ) { // Only perform if database mapping is available for this filter! - if ( isset($dbmapping[$szTableType][$propertyname]) ) + if ( isset($dbmapping[$szTableType]['DBMAPPINGS'][$propertyname]) ) { switch( $myfilter[FILTER_TYPE] ) { @@ -890,11 +890,11 @@ class LogStreamPDO extends LogStream { // Not create LIKE Filters if ( isset($tmpfilters[$propertyname]) ) - $tmpfilters[$propertyname][FILTER_VALUE] .= $addor . $dbmapping[$szTableType][$propertyname] . $addnod . $szSearchBegin . DB_RemoveBadChars($myfilter[FILTER_VALUE], $this->_logStreamConfigObj->DBType) . $szSearchEnd; + $tmpfilters[$propertyname][FILTER_VALUE] .= $addor . $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . $addnod . $szSearchBegin . DB_RemoveBadChars($myfilter[FILTER_VALUE], $this->_logStreamConfigObj->DBType) . $szSearchEnd; else { $tmpfilters[$propertyname][FILTER_TYPE] = FILTER_TYPE_STRING; - $tmpfilters[$propertyname][FILTER_VALUE] = $dbmapping[$szTableType][$propertyname] . $addnod . $szSearchBegin . DB_RemoveBadChars($myfilter[FILTER_VALUE], $this->_logStreamConfigObj->DBType) . $szSearchEnd; + $tmpfilters[$propertyname][FILTER_VALUE] = $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . $addnod . $szSearchBegin . DB_RemoveBadChars($myfilter[FILTER_VALUE], $this->_logStreamConfigObj->DBType) . $szSearchEnd; } break; case FILTER_TYPE_NUMBER: @@ -908,7 +908,7 @@ class LogStreamPDO extends LogStream { else { $tmpfilters[$szArrayKey][FILTER_TYPE] = FILTER_TYPE_NUMBER; - $tmpfilters[$szArrayKey][FILTER_VALUE] = $dbmapping[$szTableType][$propertyname] . " NOT IN (" . DB_RemoveBadChars($myfilter[FILTER_VALUE], $this->_logStreamConfigObj->DBType); + $tmpfilters[$szArrayKey][FILTER_VALUE] = $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " NOT IN (" . DB_RemoveBadChars($myfilter[FILTER_VALUE], $this->_logStreamConfigObj->DBType); } } else @@ -919,7 +919,7 @@ class LogStreamPDO extends LogStream { else { $tmpfilters[$propertyname][FILTER_TYPE] = FILTER_TYPE_NUMBER; - $tmpfilters[$propertyname][FILTER_VALUE] = $dbmapping[$szTableType][$propertyname] . " IN (" . DB_RemoveBadChars($myfilter[FILTER_VALUE], $this->_logStreamConfigObj->DBType); + $tmpfilters[$propertyname][FILTER_VALUE] = $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " IN (" . DB_RemoveBadChars($myfilter[FILTER_VALUE], $this->_logStreamConfigObj->DBType); } } // --- @@ -956,19 +956,19 @@ class LogStreamPDO extends LogStream { } // Append filter - $tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType][$propertyname] . " > '" . date("Y-m-d H:i:s", $nNowTimeStamp) . "'"; + $tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " > '" . date("Y-m-d H:i:s", $nNowTimeStamp) . "'"; } else if ( $myfilter[FILTER_DATEMODE] == DATEMODE_RANGE_FROM ) { // Obtain Event struct for the time! $myeventtime = GetEventTime($myfilter[FILTER_VALUE]); - $tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType][$propertyname] . " > '" . date("Y-m-d H:i:s", $myeventtime[EVTIME_TIMESTAMP]) . "'"; + $tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " > '" . date("Y-m-d H:i:s", $myeventtime[EVTIME_TIMESTAMP]) . "'"; } else if ( $myfilter[FILTER_DATEMODE] == DATEMODE_RANGE_TO ) { // Obtain Event struct for the time! $myeventtime = GetEventTime($myfilter[FILTER_VALUE]); - $tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType][$propertyname] . " < '" . date("Y-m-d H:i:s", $myeventtime[EVTIME_TIMESTAMP]) . "'"; + $tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " < '" . date("Y-m-d H:i:s", $myeventtime[EVTIME_TIMESTAMP]) . "'"; } break; @@ -1153,7 +1153,7 @@ class LogStreamPDO extends LogStream { // if ( $this->_logStreamConfigObj->DBEnableRowCounting ) // with SQL_CALC_FOUND_ROWS // $sqlString = "SELECT SQL_CALC_FOUND_ROWS " . $dbmapping[$szTableType][SYSLOG_UID]; // else // without row calc - $sqlString = "SELECT " . $dbmapping[$szTableType][SYSLOG_UID]; + $sqlString = "SELECT " . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_UID]; // Append fields if needed if ( $includeFields && $this->_arrProperties != null ) @@ -1162,10 +1162,10 @@ class LogStreamPDO extends LogStream { foreach ( $this->_arrProperties as $myproperty ) { // SYSLOG_UID already added! - if ( $myproperty != SYSLOG_UID && isset($dbmapping[$szTableType][$myproperty]) ) + if ( $myproperty != SYSLOG_UID && isset($dbmapping[$szTableType]['DBMAPPINGS'][$myproperty]) ) { // Append field! - $sqlString .= ", " . $dbmapping[$szTableType][$myproperty]; + $sqlString .= ", " . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty]; } } } @@ -1185,16 +1185,16 @@ class LogStreamPDO extends LogStream { $myOperator = "<="; if ( strlen($this->_SQLwhereClause) > 0 ) - $sqlString .= " AND " . $dbmapping[$szTableType][SYSLOG_UID] . " $myOperator $uID"; + $sqlString .= " AND " . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_UID] . " $myOperator $uID"; else - $sqlString .= " WHERE " . $dbmapping[$szTableType][SYSLOG_UID] . " $myOperator $uID"; + $sqlString .= " WHERE " . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_UID] . " $myOperator $uID"; } // Append ORDER clause if ( $this->_readDirection == EnumReadDirection::Forward ) - $sqlString .= " ORDER BY " . $dbmapping[$szTableType][$szSortColumn]; + $sqlString .= " ORDER BY " . $dbmapping[$szTableType]['DBMAPPINGS'][$szSortColumn]; else if ( $this->_readDirection == EnumReadDirection::Backward ) - $sqlString .= " ORDER BY " . $dbmapping[$szTableType][$szSortColumn] . " DESC"; + $sqlString .= " ORDER BY " . $dbmapping[$szTableType]['DBMAPPINGS'][$szSortColumn] . " DESC"; //echo $sqlString; //exit; @@ -1263,7 +1263,7 @@ class LogStreamPDO extends LogStream { $szTableType = $this->_logStreamConfigObj->DBTableType; // Create Statement and perform query! - $szSql = "SELECT count(" . $dbmapping[$szTableType][SYSLOG_UID] . ") FROM " . $this->_logStreamConfigObj->DBTableName . $this->_SQLwhereClause; + $szSql = "SELECT count(" . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_UID] . ") FROM " . $this->_logStreamConfigObj->DBTableName . $this->_SQLwhereClause; $myQuery = $this->_dbhandle->query($szSql); if ($myQuery) { diff --git a/src/include/constants_logstream.php b/src/include/constants_logstream.php index cdb4320..6bd9742 100644 --- a/src/include/constants_logstream.php +++ b/src/include/constants_logstream.php @@ -299,33 +299,37 @@ $fields[SYSLOG_MESSAGE]['SearchOnline'] = false; // --- // --- Define default Database field mappings! -$dbmapping['monitorware'][SYSLOG_UID] = "ID"; -$dbmapping['monitorware'][SYSLOG_DATE] = "DeviceReportedTime"; -$dbmapping['monitorware'][SYSLOG_HOST] = "FromHost"; -$dbmapping['monitorware'][SYSLOG_MESSAGETYPE] = "InfoUnitID"; -$dbmapping['monitorware'][SYSLOG_MESSAGE] = "Message"; -$dbmapping['monitorware'][SYSLOG_FACILITY] = "Facility"; -$dbmapping['monitorware'][SYSLOG_SEVERITY] = "Priority"; -$dbmapping['monitorware'][SYSLOG_SYSLOGTAG] = "SysLogTag"; -$dbmapping['monitorware'][SYSLOG_EVENT_ID] = "EventID"; -$dbmapping['monitorware'][SYSLOG_EVENT_LOGTYPE] = "EventLogType"; -$dbmapping['monitorware'][SYSLOG_EVENT_SOURCE] = "EventSource"; -$dbmapping['monitorware'][SYSLOG_EVENT_CATEGORY] = "EventCategory"; -$dbmapping['monitorware'][SYSLOG_EVENT_USER] = "EventUser"; +$dbmapping['monitorware']['ID'] = "monitorware"; +$dbmapping['monitorware']['DisplayName'] = "MonitorWare"; +$dbmapping['monitorware']['DBMAPPINGS'][SYSLOG_UID] = "ID"; +$dbmapping['monitorware']['DBMAPPINGS'][SYSLOG_DATE] = "DeviceReportedTime"; +$dbmapping['monitorware']['DBMAPPINGS'][SYSLOG_HOST] = "FromHost"; +$dbmapping['monitorware']['DBMAPPINGS'][SYSLOG_MESSAGETYPE] = "InfoUnitID"; +$dbmapping['monitorware']['DBMAPPINGS'][SYSLOG_MESSAGE] = "Message"; +$dbmapping['monitorware']['DBMAPPINGS'][SYSLOG_FACILITY] = "Facility"; +$dbmapping['monitorware']['DBMAPPINGS'][SYSLOG_SEVERITY] = "Priority"; +$dbmapping['monitorware']['DBMAPPINGS'][SYSLOG_SYSLOGTAG] = "SysLogTag"; +$dbmapping['monitorware']['DBMAPPINGS'][SYSLOG_EVENT_ID] = "EventID"; +$dbmapping['monitorware']['DBMAPPINGS'][SYSLOG_EVENT_LOGTYPE] = "EventLogType"; +$dbmapping['monitorware']['DBMAPPINGS'][SYSLOG_EVENT_SOURCE] = "EventSource"; +$dbmapping['monitorware']['DBMAPPINGS'][SYSLOG_EVENT_CATEGORY] = "EventCategory"; +$dbmapping['monitorware']['DBMAPPINGS'][SYSLOG_EVENT_USER] = "EventUser"; -$dbmapping['syslogng'][SYSLOG_UID] = "seq"; -$dbmapping['syslogng'][SYSLOG_DATE] = "datetime"; -$dbmapping['syslogng'][SYSLOG_HOST] = "host"; -$dbmapping['syslogng'][SYSLOG_MESSAGE] = "msg"; +$dbmapping['syslogng']['ID'] = "syslogng"; +$dbmapping['syslogng']['DisplayName'] = "SyslogNG"; +$dbmapping['syslogng']['DBMAPPINGS'][SYSLOG_UID] = "seq"; +$dbmapping['syslogng']['DBMAPPINGS'][SYSLOG_DATE] = "datetime"; +$dbmapping['syslogng']['DBMAPPINGS'][SYSLOG_HOST] = "host"; +$dbmapping['syslogng']['DBMAPPINGS'][SYSLOG_MESSAGE] = "msg"; //NOT POSSIBLE YET $dbmapping['syslogng'][SYSLOG_FACILITY] = "Facility"; //NOT POSSIBLE YET $dbmapping['syslogng'][SYSLOG_SEVERITY] = "Priority"; -$dbmapping['syslogng'][SYSLOG_SYSLOGTAG] = "tag"; -$dbmapping['syslogng'][SYSLOG_PROCESSID] = "program"; +$dbmapping['syslogng']['DBMAPPINGS'][SYSLOG_SYSLOGTAG] = "tag"; +$dbmapping['syslogng']['DBMAPPINGS'][SYSLOG_PROCESSID] = "program"; // Convert all fieldnames to lowercase to avoid problems with case sensitive array keys later foreach( $dbmapping as &$myMapping ) { - foreach( $myMapping as &$myField ) + foreach( $myMapping['DBMAPPINGS'] as &$myField ) $myField = strtolower($myField); } diff --git a/src/include/db_update_v8.txt b/src/include/db_update_v8.txt new file mode 100644 index 0000000..811eb0d --- /dev/null +++ b/src/include/db_update_v8.txt @@ -0,0 +1,11 @@ +-- New Database Structure Updates +CREATE TABLE `logcon_dbmappings` ( + `ID` int(11) NOT NULL auto_increment, + `DisplayName` varchar(64) NOT NULL, + `Mappings` varchar(1024) NOT NULL, + PRIMARY KEY (`ID`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; + +-- Insert data + +-- Updated Data diff --git a/src/include/functions_common.php b/src/include/functions_common.php index be953a1..f6a2128 100644 --- a/src/include/functions_common.php +++ b/src/include/functions_common.php @@ -332,8 +332,7 @@ function CreateDBMappingsList( $selectedDBTableType ) foreach ( $dbmapping as $mykey => $myMapping ) { $content['DBMAPPINGS'][$mykey]['type'] = $mykey; - $content['DBMAPPINGS'][$mykey]['DisplayName'] = $mykey; - + if ( isset($myMapping['DisplayName']) ) {$content['DBMAPPINGS'][$mykey]['DisplayName'] = $myMapping['DisplayName']; } else { $content['DBMAPPINGS'][$mykey]['DisplayName'] = $mykey; } if ( $selectedDBTableType == $mykey ) { $content['DBMAPPINGS'][$mykey]['selected'] = "selected"; } else { $content['DBMAPPINGS'][$mykey]['selected'] = ""; } } } @@ -771,6 +770,9 @@ function InitConfigurationValues() // Load Configured Views LoadViewsFromDatabase(); + // Load Configured Mappings + LoadDBMappingsFromDatabase(); + // Load Configured Sources LoadSourcesFromDatabase(); } diff --git a/src/include/functions_config.php b/src/include/functions_config.php index edb94c0..4b5923f 100644 --- a/src/include/functions_config.php +++ b/src/include/functions_config.php @@ -430,6 +430,7 @@ function InitPhpLogConConfigFile($bHandleMissing = true) define('DB_USERS', $tblPref . "users"); define('DB_VIEWS', $tblPref . "views"); define('DB_CHARTS', $tblPref . "charts"); + define('DB_MAPPINGS', $tblPref . "dbmappings"); // Legacy support for old columns definition format! if ( isset($CFG['Columns']) && is_array($CFG['Columns']) ) @@ -463,6 +464,73 @@ function InitPhpLogConConfigFile($bHandleMissing = true) } } + +/* +* Helper function to load configured dbmappings from the database +*/ +function LoadDBMappingsFromDatabase() +{ + // Needed to make global + global $dbmapping, $content, $fields; + + // Abort reading fields if the database version is below version 8!, because prior v8, there were no dbmappings table + if ( $content['database_installedversion'] < 8 ) + return; + + // --- Preprocess fields in loop + foreach ($dbmapping as &$myMapping ) + { + // Set Field to be internal! + $myMapping['IsInternalMapping'] = true; + $myMapping['MappingFromDB'] = false; + } + // --- + + // --- Create SQL Query + $sqlquery = " SELECT " . + DB_MAPPINGS . ".ID, " . + DB_MAPPINGS . ".DisplayName, " . + DB_MAPPINGS . ".Mappings " . + " FROM " . DB_MAPPINGS . + " ORDER BY " . DB_MAPPINGS . ".DisplayName"; + + // Get Views from DB now! + $result = DB_Query($sqlquery); + $myrows = DB_GetAllRows($result, true); + if ( isset($myrows) && count($myrows) > 0 ) + { + // Unpack the Columns and append to Views Array + foreach ($myrows as &$myMappings) + { + // Split into array + $tmpMappings = explode( ",", $myMappings['Mappings'] ); + + //Loop through mappings + foreach ($tmpMappings as &$myMapping ) + { + // Split subvalues + $tmpMapping = explode( "=>", $myMapping ); + + // check if field is valid + $fieldId = trim($tmpMapping[0]); + if ( isset($fields[$fieldId]) ) + { + // Assign mappings + $myMappings['DBMAPPINGS'][$fieldId] = trim($tmpMapping[1]); + } + } + + // Add Mapping to array + $dbmapping[ $myMappings['ID'] ] = $myMappings; + + // Set FromDB to true + $dbmapping[ $myMappings['ID'] ]['MappingFromDB'] = true; + } + } + // --- +} + + /* * Helper function to load configured fields from the database */ diff --git a/src/include/functions_db.php b/src/include/functions_db.php index af0318c..48d11f7 100644 --- a/src/include/functions_db.php +++ b/src/include/functions_db.php @@ -45,7 +45,7 @@ $errdesc = ""; $errno = 0; // --- Current Database Version, this is important for automated database Updates! -$content['database_internalversion'] = "7"; // Whenever incremented, a database upgrade is needed +$content['database_internalversion'] = "8"; // Whenever incremented, a database upgrade is needed $content['database_installedversion'] = "0"; // 0 is default which means Prior Versioning Database // --- diff --git a/src/lang/en/admin.php b/src/lang/en/admin.php index 919c82d..18a13fc 100644 --- a/src/lang/en/admin.php +++ b/src/lang/en/admin.php @@ -37,6 +37,7 @@ $content['LN_ADMINMENU_USEROPT'] = "Users"; $content['LN_ADMINMENU_GROUPOPT'] = "Groups"; $content['LN_ADMINMENU_CHARTOPT'] = "Charts"; $content['LN_ADMINMENU_FIELDOPT'] = "Fields"; + $content['LN_ADMINMENU_DBMAPPINGOPT'] = "DBMappings"; $content['LN_ADMINMENU_MSGPARSERSOPT'] = "Message Parsers"; $content['LN_ADMIN_CENTER'] = "Admin center"; $content['LN_ADMIN_UNKNOWNSTATE'] = "Unknown State"; @@ -201,9 +202,35 @@ $content['LN_VIEWS_COLUMN'] = "Column"; $content['LN_VIEWS_COLUMN_REMOVE'] = "Remove Column"; $content['LN_VIEWS_HASBEENADDED'] = "The Custom View '%1' has been successfully added."; $content['LN_VIEWS_ERROR_NOCOLUMNS'] = "You need to add at least one column in order to add a new Custom View."; -$content['LN_VIEWS_HASBEENEDIT'] = "The Custom Search '%1' has been successfully edited."; +$content['LN_VIEWS_HASBEENEDIT'] = "The Custom View '%1' has been successfully edited."; $content['LN_VIEWS_'] = ""; +// Custom DBMappings center +$content['LN_DBMP_CENTER'] = "Database Field Mappings Options"; +$content['LN_DBMP_ID'] = "ID"; +$content['LN_DBMP_NAME'] = "Database Mappingname"; +$content['LN_DBMP_DBMAPPINGS'] = "Database Mappings"; +$content['LN_DBMP_ADD'] = "Add new Database Mapping"; +$content['LN_DBMP_EDIT'] = "Edit Database Mapping"; +$content['LN_DBMP_ERROR_IDNOTFOUND'] = "A Database Mapping with ID '%1' could not be found."; +$content['LN_DBMP_ERROR_INVALIDID'] = "The Database Mapping with ID '%1' is not a valid Database Mapping."; +$content['LN_DBMP_WARNDELETEMAPPING'] = "Are you sure that you want to delete the Database Mapping '%1'? This cannot be undone!"; +$content['LN_DBMP_ERROR_DELSEARCH'] = "Deleting of the Database Mapping with id '%1' failed!"; +$content['LN_DBMP_ERROR_HASBEENDEL'] = "The Database Mapping '%1' has been successfully deleted!"; +$content['LN_DBMP_ADDEDIT'] = "Add / Edit Database Mapping"; +$content['LN_DBMP_DBMAPPINGSLIST'] = "Configured Mappings"; +$content['LN_DBMP_ADDMAPPING'] = "Add Field Mapping into list"; +$content['LN_DBMP_ERROR_DISPLAYNAMEEMPTY'] = "The DisplayName cannot be empty."; +$content['LN_DBMP_MAPPING'] = "Mapping"; +$content['LN_DBMP_MAPPING_REMOVE'] = "Remove Mapping"; +$content['LN_DBMP_MAPPING_EDIT'] = "Edit Mapping"; +$content['LN_DBMP_HASBEENADDED'] = "The Custom Database Mapping '%1' has been successfully added."; +$content['LN_DBMP_ERROR_NOCOLUMNS'] = "You need to add at least one column in order to add a new Custom Database Mapping."; +$content['LN_DBMP_HASBEENEDIT'] = "The Custom Database Mapping '%1' has been successfully edited."; +$content['LN_DBMP_HASBEENEDIT'] = "The Custom Database Mapping '%1' has been successfully edited."; +$content['LN_DBMP_ERROR_MISSINGFIELDNAME'] = "Missing mapping for the '%1' field."; + + // Custom Sources center $content['LN_SOURCES_CENTER'] = "Sources Options"; $content['LN_SOURCES_EDIT'] = "Edit Source"; diff --git a/src/templates/admin/admin_dbmappings.html b/src/templates/admin/admin_dbmappings.html new file mode 100644 index 0000000..823f176 --- /dev/null +++ b/src/templates/admin/admin_dbmappings.html @@ -0,0 +1,133 @@ + + + +

+
+
+
{LN_GEN_ERRORDETAILS}
+

{ERROR_MSG}

+
+

+ {LN_GEN_ERRORRETURNPREV} +
+

+ + + + + + + + + +
{LN_DBMP_CENTER}
+

+ + + + + + + + + + + + + + + + + + + + +
{LN_DBMP_ID}{LN_DBMP_NAME}{LN_DBMP_DBMAPPINGS}{LN_GEN_ACTIONS}
{ID} + + {DisplayName} + + + {DisplayName} + + + {CaptionSeperator}{FieldCaption} => {FieldMapping} + + +   +   + + +   +   + +
 {LN_DBMP_ADD}
+ + + +
+ + + + + + + + +
{LN_DBMP_ADDEDIT}
{LN_DBMP_NAME}
+
+ + + + + + + + + + + + + + + + + +
{LN_DBMP_DBMAPPINGSLIST}
{LN_DBMP_MAPPING} {ZAEHLER}: + + {MappingCaption} ({MappingInternalID}) + + + + + + + +
+ + + +
+
+ + + + +
+
+ + + +

+
+
+ + +

+ +
+ + \ No newline at end of file diff --git a/src/templates/admin/admin_menu.html b/src/templates/admin/admin_menu.html index bb69b32..bd9e693 100644 --- a/src/templates/admin/admin_menu.html +++ b/src/templates/admin/admin_menu.html @@ -12,8 +12,9 @@ {LN_ADMINMENU_MSGPARSERSOPT} - {LN_ADMINMENU_USEROPT} - {LN_ADMINMENU_GROUPOPT} + {LN_ADMINMENU_DBMAPPINGOPT} + {LN_ADMINMENU_USEROPT} + {LN_ADMINMENU_GROUPOPT}