Added support for administrating and configuring custom database mappings

This makes it possible to support a wider range of database table layouts.
This commit is contained in:
Andre Lorbach 2009-03-25 17:56:19 +01:00
parent b5f528aa26
commit 8c116d25f9
11 changed files with 922 additions and 78 deletions

598
src/admin/dbmappings.php Normal file
View File

@ -0,0 +1,598 @@
<?php
/*
*********************************************************************
* phpLogCon - http://www.phplogcon.org
* -----------------------------------------------------------------
* DBMapping Admin File
*
* -> 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 <http://www.gnu.org/licenses/>.
*
* 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'] : "<unknown>" );
}
}
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();
// ---
?>

View File

@ -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;

View File

@ -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)
{

View File

@ -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);
}

View File

@ -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

View File

@ -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();
}

View File

@ -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
*/

View File

@ -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
// ---

View File

@ -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";

View File

@ -0,0 +1,133 @@
<!-- INCLUDE include_header.html -->
<!-- IF ISERROR="true" -->
<br><br>
<center>
<div class="table_with_border_second ErrorMsg" style="width:600px">
<div class="PriorityError">{LN_GEN_ERRORDETAILS}</div>
<p>{ERROR_MSG}</p>
</div>
<br><br>
<a href="javascript:history.back();" target="_top">{LN_GEN_ERRORRETURNPREV}</a>
</center>
<br><br>
<!-- ENDIF ISERROR="true" -->
<table width="100%" cellpadding="0" cellspacing="0" border="0" align="center" class="with_border">
<tr>
<td colspan="3" class="title" nowrap><B>{LN_DBMP_CENTER}</B></td>
</tr>
<tr>
<td align="center" class="line2">
<br><br>
<!-- IF LISTDBMAPPINGS="true" -->
<table border="0" cellpadding="2" cellspacing="1" bgcolor="#DDDDDD" width="750" class="with_border_alternate">
<tr>
<td align="center" width="50" class="cellmenu1"><b>{LN_DBMP_ID}</b></td>
<td align="center" width="150" class="cellmenu1"><b>{LN_DBMP_NAME}</b></td>
<td align="center" width="275" class="cellmenu1"><b>{LN_DBMP_DBMAPPINGS}</b></td>
<td align="center" width="125" class="cellmenu1"><b>{LN_GEN_ACTIONS}</b></td>
</tr>
<!-- BEGIN DBMP -->
<tr>
<td align="center" class="{cssclass}"><b>{ID}</b></td>
<td align="left" class="{cssclass}">
<!-- IF ActionsAllowed="true" -->
<a href="{BASEPATH}admin/dbmappings.php?op=edit&id={ID}">{DisplayName}</a>
<!-- ENDIF ActionsAllowed="true" -->
<!-- IF ActionsAllowed!="true" -->
<b>{DisplayName}</b>
<!-- ENDIF ActionsAllowed!="true" -->
</td>
<td align="left" class="{cssclass}">
<!-- BEGIN MYMAPPINGS -->{CaptionSeperator}{FieldCaption} => {FieldMapping}<!-- END MYMAPPINGS -->
</td>
<td align="center" class="{cssclass}">
<!-- IF ActionsAllowed="true" -->
&nbsp;<a href="{BASEPATH}admin/dbmappings.php?op=edit&id={ID}"><img src="{MENU_EDIT}" width="16" title="{LN_SEARCH_EDIT}"></a>
&nbsp;<a href="{BASEPATH}admin/dbmappings.php?op=delete&id={ID}"><img src="{MENU_DELETE}" width="16" title="{LN_SEARCH_DELETE}"></a>
<!-- ENDIF ActionsAllowed="true" -->
<!-- IF ActionsAllowed!="true" -->
&nbsp;<img src="{MENU_EDIT_DISABLED}" width="16" title="{LN_GEN_DISABLED}">
&nbsp;<img src="{MENU_DELETE_DISABLED}" width="16" title="{LN_GEN_DISABLED}">
<!-- ENDIF ActionsAllowed!="true" -->
</td>
</tr>
<!-- END DBMP -->
<tr>
<td align="center" colspan="5" class="line0"><b><a href="{BASEPATH}admin/dbmappings.php?op=add"><img src="{MENU_ADD}" title="{LN_DBMP_ADD}">&nbsp;{LN_DBMP_ADD}</a></b></td>
</tr>
</table>
<!-- ENDIF LISTDBMAPPINGS="true" -->
<!-- IF ISEDITORNEWDBMP="true" -->
<form action="{BASEPATH}admin/dbmappings.php{FormUrlAddOP}" method="post">
<table border="0" cellpadding="1" cellspacing="1" bgcolor="#DDDDDD" width="700" class="with_border_alternate">
<tr>
<td align="center" class="cellmenu1" colspan="2"><b>{LN_DBMP_ADDEDIT}</b></td>
</tr>
<tr>
<td align="left" class="cellmenu2" width="250"><b>{LN_DBMP_NAME}</b></td>
<td align="right" class="line1" width="350"><input type="text" name="DisplayName" size="55" maxlength="255" value="{DisplayName}"></td>
</tr>
</table>
<br>
<table border="0" cellpadding="1" cellspacing="1" bgcolor="#DDDDDD" width="600" class="with_border_alternate">
<tr>
<td align="center" class="cellmenu1" colspan="4"><b>{LN_DBMP_DBMAPPINGSLIST}</b></td>
</tr>
<!-- BEGIN SUBMAPPINGS -->
<tr>
<td align="left" class="cellmenu2" width="150"><b>{LN_DBMP_MAPPING} {ZAEHLER}: </b></td>
<td align="left" class="{colcssclass}" width="200">
<input type="hidden" name="Mappings[]" value="{MappingFieldID}">
<b>{MappingCaption} (<I>{MappingInternalID}</I>)</b>
</td>
<td align="left" class="{colcssclass}" width="200">
<input type="text" name="{MappingFieldID}" size="32" maxlength="255" value="{MappingDbFieldName}">
</td>
<td align="center" class="{colcssclass}" width="150">
<button name="subop_edit" type="submit" value="{MappingFieldID}" class="borderlessbuttons" title="{LN_DBMP_MAPPING_EDIT}"><img src="{MENU_EDIT}" width="16" alt="{LN_DBMP_MAPPING_EDIT}"></button>
<button name="subop_moveup" type="submit" value="{MappingFieldID}" class="borderlessbuttons" title="{LN_DBMP_MAPPING_MOVEUP}"><img src="{MENU_MOVE_UP}" width="16" alt="{LN_DBMP_MAPPING_REMOVE}"></button>
<button name="subop_movedown" type="submit" value="{MappingFieldID}" class="borderlessbuttons" title="{LN_DBMP_MAPPING_MOVEDOWN}"><img src="{MENU_MOVE_DOWN}" width="16" alt="{LN_DBMP_MAPPING_REMOVE}"></button>
<button name="subop_delete" type="submit" value="{MappingFieldID}" class="borderlessbuttons" title="{LN_DBMP_MAPPING_REMOVE}"><img src="{MENU_DELETE}" width="16" alt="{LN_DBMP_MAPPING_REMOVE}"></button>
</td>
</tr>
<!-- END SUBMAPPINGS -->
<tr>
<td align="center" class="line2" colspan="4">
<select name="newmapping" size="1" STYLE="width: 200px">
<!-- BEGIN FIELDS -->
<option value="{FieldID}" {group_selected}>{FieldCaption}</option>
<!-- END FIELDS -->
</select>
<input type="submit" name="subop" value="{LN_DBMP_ADDMAPPING}">
</td>
</tr>
</table>
<br>
<table border="0" cellpadding="1" cellspacing="1" bgcolor="#DDDDDD" width="600" class="with_border_alternate">
<tr>
<td align="center" colspan="2" class="line0">
<br>
<input type="submit" value="{DBMP_SENDBUTTON}">
<input type="hidden" name="op" value="{DBMP_FORMACTION}">
<input type="hidden" name="id" value="{DBMPID}">
<br><br>
</td>
</tr>
</table>
</form>
<!-- ENDIF ISEDITORNEWDBMP="true" -->
<br><br>
</td>
</tr>
</table>
<!-- INCLUDE include_footer.html -->

View File

@ -12,8 +12,9 @@
<td class="topmenu2" nowrap align="center" width="125"><a class="topmenu1_link" href="{BASEPATH}admin/parsers.php" target="_top"><img align="left" src="{MENU_INTERNAL}" width="16" height="16" vspace="0">{LN_ADMINMENU_MSGPARSERSOPT}</a></td>
<!-- IF SESSION_ISADMIN="1" -->
<td class="topmenu2" nowrap align="center" width="80"><a class="topmenu1_link" href="{BASEPATH}admin/users.php" target="_top"><img align="left" src="{MENU_ADMINUSERS}" width="16" height="16" vspace="0">{LN_ADMINMENU_USEROPT}</a></td>
<td class="topmenu2" nowrap align="center" width="80"><a class="topmenu1_link" href="{BASEPATH}admin/groups.php" target="_top"><img align="left" src="{MENU_ADMINGROUPS}" width="16" height="16" vspace="0">{LN_ADMINMENU_GROUPOPT}</a></td>
<td class="topmenu2" nowrap align="center" width="100"><a class="topmenu1_link" href="{BASEPATH}admin/dbmappings.php" target="_top"><img align="left" src="{MENU_INTERNAL}" width="16" height="16" vspace="0">{LN_ADMINMENU_DBMAPPINGOPT}</a></td>
<td class="topmenu2" nowrap align="center" width="70"><a class="topmenu1_link" href="{BASEPATH}admin/users.php" target="_top"><img align="left" src="{MENU_ADMINUSERS}" width="16" height="16" vspace="0">{LN_ADMINMENU_USEROPT}</a></td>
<td class="topmenu2" nowrap align="center" width="70"><a class="topmenu1_link" href="{BASEPATH}admin/groups.php" target="_top"><img align="left" src="{MENU_ADMINGROUPS}" width="16" height="16" vspace="0">{LN_ADMINMENU_GROUPOPT}</a></td>
<!-- ENDIF SESSION_ISADMIN="1" -->
<!-- IF SESSION_LOGGEDIN="true" -->