diff --git a/src/admin/sources.php b/src/admin/sources.php index e95d6de..080bd13 100644 --- a/src/admin/sources.php +++ b/src/admin/sources.php @@ -281,9 +281,8 @@ if ( isset($_POST['op']) ) if ( isset($_POST['SourceDBPassword']) ) { $content['SourceDBPassword'] = DB_RemoveBadChars($_POST['SourceDBPassword']); } else {$content['SourceDBPassword'] = ""; } if ( isset($_POST['SourceDBEnableRowCounting']) ) { $content['SourceDBEnableRowCounting'] = DB_RemoveBadChars($_POST['SourceDBEnableRowCounting']); } // Extra Check for this property - if ( $_SESSION['SourceDBEnableRowCounting'] != "true" ) - $_SESSION['SourceDBEnableRowCounting'] = "false"; - + if ( $content['SourceDBEnableRowCounting'] != "true" ) + $content['SourceDBEnableRowCounting'] = "false"; } } @@ -337,26 +336,27 @@ if ( isset($_POST['op']) ) else { // Get plain filename for testing! - $szFileName = DB_StripSlahes($content['SourceDiskFile']); + $content['SourceDiskFileTesting'] = DB_StripSlahes($content['SourceDiskFile']); // Take as it is if rootpath! if ( - ( ($pos = strpos($szFileName, "/")) !== FALSE && $pos == 0) || - ( ($pos = strpos($szFileName, ":\\")) !== FALSE ) || - ( ($pos = strpos($szFileName, ":/")) !== FALSE ) + ( ($pos = strpos($content['SourceDiskFileTesting'], "/")) !== FALSE && $pos == 0) || + ( ($pos = strpos($content['SourceDiskFileTesting'], ":\\")) !== FALSE ) || + ( ($pos = strpos($content['SourceDiskFileTesting'], ":/")) !== FALSE ) ) { // Nothing really todo - $szFileName = $szFileName; + true; } else // prepend basepath! - $szFileName = $gl_root_path . $szFileName; - - if ( !is_file($szFileName) ) + $content['SourceDiskFileTesting'] = $gl_root_path . $content['SourceDiskFileTesting']; +/* + if ( !is_file($content['SourceDiskFileTesting']) ) { $content['ISERROR'] = true; $content['ERROR_MSG'] = GetAndReplaceLangStr( $content['LN_SOURCES_ERROR_NOTAVALIDFILE'], $szFileName ); } +*/ } } // DB Params @@ -398,6 +398,52 @@ if ( isset($_POST['op']) ) $content['ISERROR'] = true; $content['ERROR_MSG'] = GetAndReplaceLangStr( $content['LN_SOURCES_ERROR_UNKNOWNSOURCE'], $content['SourceDBType'] ); } + + // --- Verify the Source and report and error if needed! + + // Include LogStream facility + include($gl_root_path . 'classes/logstream.class.php'); + + // First create a tmp source array + $tmpSource['ID'] = $content['SOURCEID']; + $tmpSource['Name'] = $content['Name']; + $tmpSource['SourceType']= $content['SourceType']; + $tmpSource['ViewID'] = $content['SourceViewID']; + if ( $tmpSource['SourceType'] == SOURCE_DISK ) + { + $tmpSource['LogLineType'] = $content['SourceLogLineType']; + $tmpSource['DiskFile'] = $content['SourceDiskFileTesting']; // use SourceDiskFileTesting rather then SourceDiskFile as it is corrected + } + // DB Params + else if ( $tmpSource['SourceType'] == SOURCE_DB || $tmpSource['SourceType'] == SOURCE_PDO ) + { + $tmpSource['DBType'] = $content['SourceDBType']; + $tmpSource['DBName'] = $content['SourceDBName']; + $tmpSource['DBTableType'] = $content['SourceDBTableType']; + $tmpSource['DBServer'] = $content['SourceDBServer']; + $tmpSource['DBTableName'] = $content['SourceDBTableName']; + $tmpSource['DBUser'] = $content['SourceDBUser']; + $tmpSource['DBPassword'] = $content['SourceDBPassword']; + $tmpSource['DBEnableRowCounting'] = $content['SourceDBEnableRowCounting']; + $tmpSource['userid'] = $content['userid']; + $tmpSource['groupid'] = $content['groupid']; + } + + // Init the source + InitSource($tmpSource); + + // Create LogStream Object + $stream = $tmpSource['ObjRef']->LogStreamFactory($tmpSource['ObjRef']); + $res = $stream->Verify(); + if ( $res != SUCCESS ) + { + $content['ISERROR'] = true; + $content['ERROR_MSG'] = GetAndReplaceLangStr( $content['LN_SOURCES_ERROR_WITHINSOURCE'], $tmpSource['Name'], GetErrorMessage($res) ); + + if ( isset($extraErrorDescription) ) + $content['ERROR_MSG'] .= "

" . GetAndReplaceLangStr( $content['LN_SOURCES_ERROR_EXTRAMSG'], $extraErrorDescription); + } + // --- } // --- Now ADD/EDIT do the processing! diff --git a/src/classes/logstream.class.php b/src/classes/logstream.class.php index b308764..2513ce9 100644 --- a/src/classes/logstream.class.php +++ b/src/classes/logstream.class.php @@ -68,6 +68,13 @@ abstract class LogStream { */ public abstract function Close(); + /** + * Verifies the logstream source + * + * @return integer Error stat + */ + public abstract function Verify(); + /** * Read the next data from the current stream. If it reads * forwards or backwards depends on the current read direction. diff --git a/src/classes/logstreamconfigdisk.class.php b/src/classes/logstreamconfigdisk.class.php index 00698b0..8f957e6 100644 --- a/src/classes/logstreamconfigdisk.class.php +++ b/src/classes/logstreamconfigdisk.class.php @@ -63,7 +63,7 @@ class LogStreamConfigDisk extends LogStreamConfig { require_once($gl_root_path . 'classes/logstreamlineparser.class.php'); // Probe if file exists then include it! - $strIncludeFile = 'classes/logstreamlineparser' . $this->LineParserType . '.class.php'; + $strIncludeFile = $gl_root_path . 'classes/logstreamlineparser' . $this->LineParserType . '.class.php'; $strClassName = "LogStreamLineParser" . $this->LineParserType; if ( is_file($strIncludeFile) ) diff --git a/src/classes/logstreamdb.class.php b/src/classes/logstreamdb.class.php index af1375c..3122609 100644 --- a/src/classes/logstreamdb.class.php +++ b/src/classes/logstreamdb.class.php @@ -84,15 +84,11 @@ class LogStreamDB extends LogStream { { global $dbmapping; - // Try to connect to the database - $this->_dbhandle = mysql_connect($this->_logStreamConfigObj->DBServer,$this->_logStreamConfigObj->DBUser,$this->_logStreamConfigObj->DBPassword); - if (!$this->_dbhandle) - return ERROR_DB_CONNECTFAILED; + // Verify database connection (This also opens the database!) + $res = $this->Verify(); + if ( $res != SUCCESS ) + return $res; - $bRet = mysql_select_db($this->_logStreamConfigObj->DBName, $this->_dbhandle); - if(!$bRet) - return ERROR_DB_CANNOTSELECTDB; - // Copy the Property Array $this->_arrProperties = $arrProperties; @@ -121,6 +117,52 @@ class LogStreamDB extends LogStream { return SUCCESS; } + /** + * Verify if the database connection exists! + * + * @return integer Error state + */ + public function Verify() { + // Try to connect to the database + if ( $this->_dbhandle == null ) + { + $this->_dbhandle = @mysql_connect($this->_logStreamConfigObj->DBServer,$this->_logStreamConfigObj->DBUser,$this->_logStreamConfigObj->DBPassword); + if (!$this->_dbhandle) + { + if ( isset($php_errormsg) ) + { + global $extraErrorDescription; + $extraErrorDescription = $php_errormsg; + } + + // Return error code + return ERROR_DB_CONNECTFAILED; + } + } + + // Select the database now! + $bRet = @mysql_select_db($this->_logStreamConfigObj->DBName, $this->_dbhandle); + if(!$bRet) + { + if ( isset($php_errormsg) ) + { + global $extraErrorDescription; + $extraErrorDescription = $php_errormsg; + } + + // Return error code + return ERROR_DB_CANNOTSELECTDB; + } + + // Check if the table exists! + $numTables = @mysql_num_rows( mysql_query("SHOW TABLES LIKE '%" . $this->_logStreamConfigObj->DBTableName . "%'")); + if( $numTables <= 0 ) + return ERROR_DB_TABLENOTFOUND; + + // reached this point means success ;)! + return SUCCESS; + } + /** * Read the data from a specific uID which means in this * case beginning with from the Database ID diff --git a/src/classes/logstreamdisk.class.php b/src/classes/logstreamdisk.class.php index 7f4ee03..f5ba74a 100644 --- a/src/classes/logstreamdisk.class.php +++ b/src/classes/logstreamdisk.class.php @@ -74,18 +74,14 @@ class LogStreamDisk extends LogStream { * @return integer Error stat */ public function Open($arrProperties) { + // Check if file exists! - if(!file_exists($this->_logStreamConfigObj->FileName)) { - return ERROR_FILE_NOT_FOUND; - } - - // Check if file is readable! - if(!is_readable($this->_logStreamConfigObj->FileName)) { - return ERROR_FILE_NOT_READABLE; - } + $result = $this->Verify(); + if ( $result != SUCCESS) + return $result; + // Now open the file $this->_fp = fopen($this->_logStreamConfigObj->FileName, 'r'); - $this->_currentOffset = ftell($this->_fp); $this->_currentStartPos = $this->_currentOffset; $this->_arrProperties = $arrProperties; @@ -111,6 +107,27 @@ class LogStreamDisk extends LogStream { return SUCCESS; } + /** + * Verify if the file exists! + * + * @return integer Error state + */ + public function Verify() { + // Check if file exists! + if(!file_exists($this->_logStreamConfigObj->FileName)) { + return ERROR_FILE_NOT_FOUND; + } + + // Check if file is readable! + if(!is_readable($this->_logStreamConfigObj->FileName)) { + return ERROR_FILE_NOT_READABLE; + } + + // reached this point means success ;)! + return SUCCESS; + } + + private function ReadNextBlock() { $this->_bEOS = false; $bCheckForLastLf = false; diff --git a/src/classes/logstreampdo.class.php b/src/classes/logstreampdo.class.php index 5354cb6..4ed509c 100644 --- a/src/classes/logstreampdo.class.php +++ b/src/classes/logstreampdo.class.php @@ -87,38 +87,11 @@ class LogStreamPDO extends LogStream { { global $dbmapping; - // Create DSN String - $myDBDriver = $this->_logStreamConfigObj->GetPDODatabaseType(); - $myDsn = $this->_logStreamConfigObj->CreateConnectDSN(); - if ( strlen($myDsn) > 0 ) - { - // Check if configured driver is actually loaded! - //print_r(PDO::getAvailableDrivers()); - if ( !in_array($myDBDriver, PDO::getAvailableDrivers()) ) - { - $this->PrintDebugError('PDO Database Driver not loaded: ' . $myDBDriver . "
Please check your php configuration extensions"); - return ERROR_DB_INVALIDDBDRIVER; - } + // Verify database driver and connection (This also opens the database!) + $res = $this->Verify(); + if ( $res != SUCCESS ) + return $res; - try - { - // Try to connect to the database - $this->_dbhandle = new PDO( $myDsn, $this->_logStreamConfigObj->DBUser, $this->_logStreamConfigObj->DBPassword); - -//$handle->setAttribute(PDO::ATTR_TIMEOUT, 3); - } - catch (PDOException $e) - { - $this->PrintDebugError('PDO Database Connection failed: ' . $e->getMessage() . "
DSN: " . $myDsn); - return ERROR_DB_CONNECTFAILED; - } - } - else - { - // Invalid DB Driver! - return ERROR_DB_INVALIDDBDRIVER; - } - // Copy the Property Array $this->_arrProperties = $arrProperties; @@ -155,6 +128,73 @@ class LogStreamPDO extends LogStream { return true; } + /** + * Verify if the database connection exists! + * + * @return integer Error state + */ + public function Verify() { + // Create DSN String + $myDBDriver = $this->_logStreamConfigObj->GetPDODatabaseType(); + $myDsn = $this->_logStreamConfigObj->CreateConnectDSN(); + if ( strlen($myDsn) > 0 ) + { + // Check if configured driver is actually loaded! + //print_r(PDO::getAvailableDrivers()); + if ( !in_array($myDBDriver, PDO::getAvailableDrivers()) ) + { + global $extraErrorDescription; + $extraErrorDescription = "PDO Database Driver not loaded: " . $myDBDriver . "
Please check your php configuration extensions"; + // $this->PrintDebugError($extraErrorDescription); + + // return error code + return ERROR_DB_INVALIDDBDRIVER; + } + + try + { + // Try to connect to the database + $this->_dbhandle = new PDO( $myDsn, $this->_logStreamConfigObj->DBUser, $this->_logStreamConfigObj->DBPassword /*, array(PDO::ATTR_TIMEOUT =>25)*/); + //$this->_dbhandle->setAttribute(PDO::ATTR_TIMEOUT, 25); + } + catch (PDOException $e) + { + global $extraErrorDescription; + $extraErrorDescription = "PDO Database Connection failed: " . $e->getMessage() . "
DSN: " . $myDsn; + // $this->PrintDebugError($extraErrorDescription); + + // return error code + return ERROR_DB_CONNECTFAILED; + } + + try + { + // This is one way to check if the table exists! But I don't really like it tbh -.- + $tmpStmnt = $this->_dbhandle->prepare("SELECT ID FROM " . $this->_logStreamConfigObj->DBTableName . " WHERE ID=1"); + $tmpStmnt->execute(); + $colcount = $tmpStmnt->columnCount(); + if ( $colcount <= 0 ) + return ERROR_DB_TABLENOTFOUND; + } + catch (PDOException $e) + { + global $extraErrorDescription; + $extraErrorDescription = "Could not find table: " . $e->getMessage(); + + // return error code + return ERROR_DB_TABLENOTFOUND; + } + } + else + { + // Invalid DB Driver! + return ERROR_DB_INVALIDDBDRIVER; + } + + // reached this point means success ;)! + return SUCCESS; + } + /** * Read the data from a specific uID which means in this * case beginning with from the Database ID diff --git a/src/include/constants_errors.php b/src/include/constants_errors.php index 6ca7855..f3e1361 100644 --- a/src/include/constants_errors.php +++ b/src/include/constants_errors.php @@ -45,6 +45,7 @@ define('ERROR_FILE_NOT_FOUND', 2); define('ERROR_FILE_CANT_CLOSE', 3); define('ERROR_FILE_EOF', 4); define('ERROR_FILE_BOF', 5); +define('ERROR_FILE_NOT_READABLE', 15); define('ERROR_UNDEFINED', 6); define('ERROR_EOS', 7); define('ERROR_NOMORERECORDS', 8); @@ -56,8 +57,8 @@ define('ERROR_DB_QUERYFAILED', 12); define('ERROR_DB_NOPROPERTIES', 13); define('ERROR_DB_INVALIDDBMAPPING', 14); define('ERROR_DB_INVALIDDBDRIVER', 16); +define('ERROR_DB_TABLENOTFOUND', 17); -define('ERROR_FILE_NOT_READABLE', 15); ?> diff --git a/src/include/functions_common.php b/src/include/functions_common.php index 85b5cc9..936fbcb 100644 --- a/src/include/functions_common.php +++ b/src/include/functions_common.php @@ -53,8 +53,12 @@ include($gl_root_path . 'include/functions_config.php'); $RUNMODE = RUNMODE_WEBSERVER; $DEBUGMODE = DEBUG_INFO; -// --- Disable ARGV setting @webserver! -ini_set( "register_argc_argv", "Off" ); +// --- Change some runtime variables +// Disable ARGV setting @webserver! +@ini_set( "register_argc_argv", "Off" ); + +// Enable error tracking +@ini_set( "track_errors", "On" ); // --- // Default language @@ -1133,4 +1137,52 @@ function GetConfigSetting($szSettingName, $szDefaultValue = "", $DesiredConfigLe return $szDefaultValue; } +/* +* Helper function to get the errorCode +*/ +function GetErrorMessage($errorCode) +{ + global $content; + + switch( $errorCode ) + { + case ERROR_FILE_NOT_FOUND: + return $content['LN_ERROR_FILE_NOT_FOUND']; + case ERROR_FILE_NOT_READABLE: + return $content['LN_ERROR_FILE_NOT_READABLE']; + case ERROR_FILE_EOF: + return $content['LN_ERROR_FILE_EOF']; + case ERROR_FILE_BOF: + return $content['LN_ERROR_FILE_BOF']; + case ERROR_FILE_CANT_CLOSE: + return $content['LN_ERROR_FILE_CANT_CLOSE']; + case ERROR_UNDEFINED: + return $content['LN_ERROR_UNDEFINED']; + case ERROR_EOS: + return $content['LN_ERROR_EOS']; + case ERROR_NOMORERECORDS: + return $content['LN_ERROR_NORECORDS']; + case ERROR_FILTER_NOT_MATCH: + return $content['LN_ERROR_FILTER_NOT_MATCH']; + case ERROR_DB_CONNECTFAILED: + return $content['LN_ERROR_DB_CONNECTFAILED']; + case ERROR_DB_CANNOTSELECTDB: + return $content['LN_ERROR_DB_CANNOTSELECTDB']; + case ERROR_DB_QUERYFAILED: + return $content['LN_ERROR_DB_QUERYFAILED']; + case ERROR_DB_NOPROPERTIES: + return $content['LN_ERROR_DB_NOPROPERTIES']; + case ERROR_DB_INVALIDDBMAPPING: + return $content['LN_ERROR_DB_INVALIDDBMAPPING']; + case ERROR_DB_INVALIDDBDRIVER: + return $content['LN_ERROR_DB_INVALIDDBDRIVER']; + case ERROR_DB_TABLENOTFOUND: + return $content['LN_ERROR_DB_TABLENOTFOUND']; + + + default: + return GetAndReplaceLangStr( $content['LN_ERROR_UNKNOWN'], $errorCode ); + } +} + ?> \ No newline at end of file diff --git a/src/include/functions_config.php b/src/include/functions_config.php index d884c12..a6d71d5 100644 --- a/src/include/functions_config.php +++ b/src/include/functions_config.php @@ -41,141 +41,152 @@ if ( !defined('IN_PHPLOGCON') ) require_once($gl_root_path . 'classes/logstreamconfig.class.php'); // --- +function InitSource(&$mysource) +{ + global $CFG, $content, $gl_root_path, $currentSourceID; + + if ( isset($mysource['SourceType']) ) + { + // Set Array Index, TODO: Check for invalid characters! + $iSourceID = $mysource['ID']; + + // --- Set defaults if not set! + if ( !isset($mysource['LogLineType']) ) + { + $CFG['Sources'][$iSourceID]['LogLineType'] = "syslog"; + $content['Sources'][$iSourceID]['LogLineType'] = "syslog"; + } + + if ( !isset($mysource['userid']) ) + { + $CFG['Sources'][$iSourceID]['userid'] = null; + $content['Sources'][$iSourceID]['userid'] = null; + } + if ( !isset($mysource['groupid']) ) + { + $CFG['Sources'][$iSourceID]['groupid'] = null; + $content['Sources'][$iSourceID]['groupid'] = null; + } + // --- + + // Set default view id to source + $tmpVar = GetConfigSetting("DefaultViewsID", "", CFGLEVEL_USER); + $szDefaultViewID = strlen($tmpVar) > 0 ? $tmpVar : "SYSLOG"; + + if ( isset($_SESSION[$iSourceID . "-View"]) ) + { + // check if view is valid + $UserSessionViewID = $_SESSION[$iSourceID . "-View"]; + + if ( isset($content['Views'][$UserSessionViewID]) ) + { + // Overwrite configured view! + $content['Sources'][$iSourceID]['ViewID'] = $_SESSION[$iSourceID . "-View"]; + } + else + $content['Sources'][$iSourceID]['ViewID'] = $szDefaultViewID; + } + else + { + if ( isset($mysource['ViewID']) && strlen($mysource['ViewID']) > 0 && isset($content['Views'][ $mysource['ViewID'] ]) ) + // Set to configured Source ViewID + $content['Sources'][$iSourceID]['ViewID'] = $mysource['ViewID']; + else + // Not configured, maybe old legacy cfg. Set default view. + $content['Sources'][$iSourceID]['ViewID'] = $szDefaultViewID; + } + + // Only for the display box + $content['Sources'][$iSourceID]['selected'] = ""; + + // Create Config instance! + if ( $mysource['SourceType'] == SOURCE_DISK ) + { + // Perform necessary include + require_once($gl_root_path . 'classes/logstreamconfigdisk.class.php'); + $mysource['ObjRef'] = new LogStreamConfigDisk(); + $mysource['ObjRef']->FileName = $mysource['DiskFile']; + $mysource['ObjRef']->LineParserType = $mysource['LogLineType']; + } + else if ( $mysource['SourceType'] == SOURCE_DB ) + { + // Perform necessary include + require_once($gl_root_path . 'classes/logstreamconfigdb.class.php'); + + $mysource['ObjRef'] = new LogStreamConfigDB(); + $mysource['ObjRef']->DBServer = $mysource['DBServer']; + $mysource['ObjRef']->DBName = $mysource['DBName']; + // Workaround a little bug from the installer script + if ( isset($mysource['DBType']) ) + $mysource['ObjRef']->DBType = $mysource['DBType']; + else + $mysource['ObjRef']->DBType = DB_MYSQL; + + $mysource['ObjRef']->DBTableName = $mysource['DBTableName']; + + // Legacy handling for tabletype! + if ( isset($mysource['DBTableType']) && strtolower($mysource['DBTableType']) == "winsyslog" ) + $mysource['ObjRef']->DBTableType = "monitorware"; // Convert to MonitorWare! + else + $mysource['ObjRef']->DBTableType = strtolower($mysource['DBTableType']); + + // Optional parameters! + if ( isset($mysource['DBPort']) ) { $mysource['ObjRef']->DBPort = $mysource['DBPort']; } + if ( isset($mysource['DBUser']) ) { $mysource['ObjRef']->DBUser = $mysource['DBUser']; } + if ( isset($mysource['DBPassword']) ) { $mysource['ObjRef']->DBPassword = $mysource['DBPassword']; } + if ( isset($mysource['DBEnableRowCounting']) ) { $mysource['ObjRef']->DBEnableRowCounting = $mysource['DBEnableRowCounting']; } + } + else if ( $mysource['SourceType'] == SOURCE_PDO ) + { + // Perform necessary include + require_once($gl_root_path . 'classes/logstreamconfigpdo.class.php'); + + $mysource['ObjRef'] = new LogStreamConfigPDO(); + $mysource['ObjRef']->DBServer = $mysource['DBServer']; + $mysource['ObjRef']->DBName = $mysource['DBName']; + $mysource['ObjRef']->DBType = $mysource['DBType']; + $mysource['ObjRef']->DBTableName = $mysource['DBTableName']; + $mysource['ObjRef']->DBTableType = strtolower($mysource['DBTableType']); + + // Optional parameters! + if ( isset($mysource['DBPort']) ) { $mysource['ObjRef']->DBPort = $mysource['DBPort']; } + if ( isset($mysource['DBUser']) ) { $mysource['ObjRef']->DBUser = $mysource['DBUser']; } + if ( isset($mysource['DBPassword']) ) { $mysource['ObjRef']->DBPassword = $mysource['DBPassword']; } + if ( isset($mysource['DBEnableRowCounting']) ) { $mysource['ObjRef']->DBEnableRowCounting = $mysource['DBEnableRowCounting']; } + } + else + { + // UNKNOWN, remove config entry! + unset($content['Sources'][$iSourceID]); + + // Output CRITICAL WARNING + DieWithFriendlyErrorMsg( GetAndReplaceLangStr($content['LN_GEN_CRITERROR_UNKNOWNTYPE'], $mysource['SourceType']) ); + } + + // Set generic configuration options + $mysource['ObjRef']->_pageCount = GetConfigSetting("ViewEntriesPerPage", 50); + + // Set default SourceID here! + if ( isset($content['Sources'][$iSourceID]) && !isset($currentSourceID) ) + $currentSourceID = $iSourceID; + + // Copy Object REF into CFG and content Array as well! + $content['Sources'][$iSourceID]['ObjRef'] = $mysource['ObjRef']; + $CFG['Sources'][$iSourceID]['ObjRef'] = $mysource['ObjRef']; + } +} + function InitSourceConfigs() { - global $CFG, $content, $currentSourceID, $gl_root_path; + global $CFG, $content, $currentSourceID; // Init Source Configs! if ( isset($CFG['Sources']) ) { - $iCount = count($CFG['Sources']); foreach( $CFG['Sources'] as &$mysource ) { - if ( isset($mysource['SourceType']) ) - { - // Set Array Index, TODO: Check for invalid characters! - $iSourceID = $mysource['ID']; - - // --- Set defaults if not set! - if ( !isset($mysource['LogLineType']) ) - { - $CFG['Sources'][$iSourceID]['LogLineType'] = "syslog"; - $content['Sources'][$iSourceID]['LogLineType'] = "syslog"; - } - - if ( !isset($mysource['userid']) ) - { - $CFG['Sources'][$iSourceID]['userid'] = null; - $content['Sources'][$iSourceID]['userid'] = null; - } - if ( !isset($mysource['groupid']) ) - { - $CFG['Sources'][$iSourceID]['groupid'] = null; - $content['Sources'][$iSourceID]['groupid'] = null; - } - // --- - - // Set default view id to source - $tmpVar = GetConfigSetting("DefaultViewsID", "", CFGLEVEL_USER); - $szDefaultViewID = strlen($tmpVar) > 0 ? $tmpVar : "SYSLOG"; - - if ( isset($_SESSION[$iSourceID . "-View"]) ) - { - // check if view is valid - $UserSessionViewID = $_SESSION[$iSourceID . "-View"]; - - if ( isset($content['Views'][$UserSessionViewID]) ) - { - // Overwrite configured view! - $content['Sources'][$iSourceID]['ViewID'] = $_SESSION[$iSourceID . "-View"]; - } - else - $content['Sources'][$iSourceID]['ViewID'] = $szDefaultViewID; - } - else - { - if ( isset($mysource['ViewID']) && strlen($mysource['ViewID']) > 0 && isset($content['Views'][ $mysource['ViewID'] ]) ) - // Set to configured Source ViewID - $content['Sources'][$iSourceID]['ViewID'] = $mysource['ViewID']; - else - // Not configured, maybe old legacy cfg. Set default view. - $content['Sources'][$iSourceID]['ViewID'] = $szDefaultViewID; - } - - // Only for the display box - $content['Sources'][$iSourceID]['selected'] = ""; - - // Create Config instance! - if ( $mysource['SourceType'] == SOURCE_DISK ) - { - // Perform necessary include - require_once($gl_root_path . 'classes/logstreamconfigdisk.class.php'); - $content['Sources'][$iSourceID]['ObjRef'] = new LogStreamConfigDisk(); - $content['Sources'][$iSourceID]['ObjRef']->FileName = $mysource['DiskFile']; - $content['Sources'][$iSourceID]['ObjRef']->LineParserType = $mysource['LogLineType']; - } - else if ( $mysource['SourceType'] == SOURCE_DB ) - { - // Perform necessary include - require_once($gl_root_path . 'classes/logstreamconfigdb.class.php'); - - $content['Sources'][$iSourceID]['ObjRef'] = new LogStreamConfigDB(); - $content['Sources'][$iSourceID]['ObjRef']->DBServer = $mysource['DBServer']; - $content['Sources'][$iSourceID]['ObjRef']->DBName = $mysource['DBName']; - // Workaround a little bug from the installer script - if ( isset($mysource['DBType']) ) - $content['Sources'][$iSourceID]['ObjRef']->DBType = $mysource['DBType']; - else - $content['Sources'][$iSourceID]['ObjRef']->DBType = DB_MYSQL; - - $content['Sources'][$iSourceID]['ObjRef']->DBTableName = $mysource['DBTableName']; - - // Legacy handling for tabletype! - if ( isset($mysource['DBTableType']) && strtolower($mysource['DBTableType']) == "winsyslog" ) - $content['Sources'][$iSourceID]['ObjRef']->DBTableType = "monitorware"; // Convert to MonitorWare! - else - $content['Sources'][$iSourceID]['ObjRef']->DBTableType = strtolower($mysource['DBTableType']); - - // Optional parameters! - if ( isset($mysource['DBPort']) ) { $content['Sources'][$iSourceID]['ObjRef']->DBPort = $mysource['DBPort']; } - if ( isset($mysource['DBUser']) ) { $content['Sources'][$iSourceID]['ObjRef']->DBUser = $mysource['DBUser']; } - if ( isset($mysource['DBPassword']) ) { $content['Sources'][$iSourceID]['ObjRef']->DBPassword = $mysource['DBPassword']; } - if ( isset($mysource['DBEnableRowCounting']) ) { $content['Sources'][$iSourceID]['ObjRef']->DBEnableRowCounting = $mysource['DBEnableRowCounting']; } - } - else if ( $mysource['SourceType'] == SOURCE_PDO ) - { - // Perform necessary include - require_once($gl_root_path . 'classes/logstreamconfigpdo.class.php'); - - $content['Sources'][$iSourceID]['ObjRef'] = new LogStreamConfigPDO(); - $content['Sources'][$iSourceID]['ObjRef']->DBServer = $mysource['DBServer']; - $content['Sources'][$iSourceID]['ObjRef']->DBName = $mysource['DBName']; - $content['Sources'][$iSourceID]['ObjRef']->DBType = $mysource['DBType']; - $content['Sources'][$iSourceID]['ObjRef']->DBTableName = $mysource['DBTableName']; - $content['Sources'][$iSourceID]['ObjRef']->DBTableType = strtolower($mysource['DBTableType']); - - // Optional parameters! - if ( isset($mysource['DBPort']) ) { $content['Sources'][$iSourceID]['ObjRef']->DBPort = $mysource['DBPort']; } - if ( isset($mysource['DBUser']) ) { $content['Sources'][$iSourceID]['ObjRef']->DBUser = $mysource['DBUser']; } - if ( isset($mysource['DBPassword']) ) { $content['Sources'][$iSourceID]['ObjRef']->DBPassword = $mysource['DBPassword']; } - if ( isset($mysource['DBEnableRowCounting']) ) { $content['Sources'][$iSourceID]['ObjRef']->DBEnableRowCounting = $mysource['DBEnableRowCounting']; } - } - else - { - // UNKNOWN, remove config entry! - unset($content['Sources'][$iSourceID]); - - // Output CRITICAL WARNING - DieWithFriendlyErrorMsg( GetAndReplaceLangStr($content['LN_GEN_CRITERROR_UNKNOWNTYPE'], $mysource['SourceType']) ); - } - - // Set generic configuration options - $content['Sources'][$iSourceID]['ObjRef']->_pageCount = GetConfigSetting("ViewEntriesPerPage", 50); - - // Set default SourceID here! - if ( isset($content['Sources'][$iSourceID]) && !isset($currentSourceID) ) - $currentSourceID = $iSourceID; - } + // Init each source using this function! + InitSource($mysource); } } diff --git a/src/index.php b/src/index.php index 8ab2091..c7aea25 100644 --- a/src/index.php +++ b/src/index.php @@ -104,89 +104,6 @@ $content['searchstr'] = ""; $content['highlightstr'] = ""; $content['EXPAND_HIGHLIGHT'] = "false"; -// --- BEGIN Define Helper functions -function HighLightString($highlightArray, $strmsg) -{ - if ( isset($highlightArray) ) - { - // TODO OPTIMIZE - USING FONT TAG as SPAN is HIDDEN if MESSAGE POPUP is ENABNLED! - foreach( $highlightArray as $highlightword ) - $strmsg = preg_replace( "/(" . $highlightword['highlight'] . ")/i", '\\1', $strmsg ); - } - - // return result - return $strmsg; -} - -function PrepareStringForSearch($myString) -{ - return str_replace(" ", "+", $myString); -} -// --- - -// --- Read and process filters from search dialog! -if ( (isset($_POST['search']) || isset($_GET['search'])) || (isset($_POST['filter']) || isset($_GET['filter'])) ) -{ - // Copy search over - if ( isset($_POST['search']) ) - $mysearch = $_POST['search']; - else if ( isset($_GET['search']) ) - $mysearch = $_GET['search']; - - if ( isset($_POST['filter']) ) - $myfilter = $_POST['filter']; - else if ( isset($_GET['filter']) ) - $myfilter = $_GET['filter']; - - // Optionally read highlight words - if ( isset($_POST['highlight']) ) - $content['highlightstr'] = $_POST['highlight']; - else if ( isset($_GET['highlight']) ) - $content['highlightstr'] = $_GET['highlight']; - -// else if ( $mysearch == $content['LN_SEARCH']) - { - // Message is just appended - if ( isset($myfilter) && strlen($myfilter) > 0 ) - $content['searchstr'] = $myfilter; - } - - if ( strlen($content['highlightstr']) > 0 ) - { - $searchArray = array("\\", "/", ".", ">"); - $replaceArray = array("\\\\", "\/", "\.", ">"); - - // user also wants to highlight words! - if ( strpos($content['highlightstr'], ",") === false) - { - - $content['highlightwords'][0]['highlight_raw'] = $content['highlightstr']; - $content['highlightwords'][0]['highlight'] = str_replace( $searchArray, $replaceArray, $content['highlightstr']); - $content['highlightwords'][0]['cssclass'] = "highlight_1"; - $content['highlightwords'][0]['htmlcode'] = '' . $content['highlightwords'][0]['highlight']. ''; - } - else - { - // Split array into words - $tmparray = explode( ",", $content['highlightstr'] ); - foreach( $tmparray as $word ) - $content['highlightwords'][]['highlight_raw'] = $word; - - // Assign other variables needed for this array entry - for ($i = 0; $i < count($content['highlightwords']); $i++) - { - $content['highlightwords'][$i]['highlight'] = str_replace( $searchArray, $replaceArray, $content['highlightwords'][$i]['highlight_raw']); - $content['highlightwords'][$i]['cssclass'] = "highlight_" . ($i+1); - $content['highlightwords'][$i]['htmlcode'] = '' . $content['highlightwords'][$i]['highlight']. ''; - } - } - - // Default expand Highlight Arrea! - $content['EXPAND_HIGHLIGHT'] = "true"; - } -} -// --- - // --- BEGIN CREATE TITLE $content['TITLE'] = InitPageTitle(); @@ -272,7 +189,7 @@ if ( isset($content['Sources'][$currentSourceID]) ) // && $content['Sources'][$c { // This will disable to Main SyslogView and show an error message $content['syslogmessagesenabled'] = "false"; - $content['detailederror'] = "No syslog messages found."; + $content['detailederror'] = $content['LN_ERROR_NORECORDS']; } // --- @@ -713,13 +630,10 @@ if ( isset($content['Sources'][$currentSourceID]) ) // && $content['Sources'][$c { // This will disable to Main SyslogView and show an error message $content['syslogmessagesenabled'] = "false"; + $content['detailederror'] = GetErrorMessage($res); - if ( $res == ERROR_FILE_NOT_FOUND ) - $content['detailederror'] = "Syslog file could not be found."; - else if ( $res == ERROR_FILE_NOT_READABLE ) - $content['detailederror'] = "Syslog file is not readable, read access may be denied. "; - else - $content['detailederror'] = "Unknown or unhandled error occured (Error Code " . $res . ") "; + if ( isset($extraErrorDescription) ) + $content['detailederror'] .= "

" . GetAndReplaceLangStr( $content['LN_SOURCES_ERROR_EXTRAMSG'], $extraErrorDescription); } // Close file! @@ -733,4 +647,87 @@ $page -> parser($content, "index.html"); $page -> output(); // --- +// --- BEGIN Define Helper functions +function HighLightString($highlightArray, $strmsg) +{ + if ( isset($highlightArray) ) + { + // TODO OPTIMIZE - USING FONT TAG as SPAN is HIDDEN if MESSAGE POPUP is ENABNLED! + foreach( $highlightArray as $highlightword ) + $strmsg = preg_replace( "/(" . $highlightword['highlight'] . ")/i", '\\1', $strmsg ); + } + + // return result + return $strmsg; +} + +function PrepareStringForSearch($myString) +{ + return str_replace(" ", "+", $myString); +} +// --- + +// --- Read and process filters from search dialog! +if ( (isset($_POST['search']) || isset($_GET['search'])) || (isset($_POST['filter']) || isset($_GET['filter'])) ) +{ + // Copy search over + if ( isset($_POST['search']) ) + $mysearch = $_POST['search']; + else if ( isset($_GET['search']) ) + $mysearch = $_GET['search']; + + if ( isset($_POST['filter']) ) + $myfilter = $_POST['filter']; + else if ( isset($_GET['filter']) ) + $myfilter = $_GET['filter']; + + // Optionally read highlight words + if ( isset($_POST['highlight']) ) + $content['highlightstr'] = $_POST['highlight']; + else if ( isset($_GET['highlight']) ) + $content['highlightstr'] = $_GET['highlight']; + +// else if ( $mysearch == $content['LN_SEARCH']) + { + // Message is just appended + if ( isset($myfilter) && strlen($myfilter) > 0 ) + $content['searchstr'] = $myfilter; + } + + if ( strlen($content['highlightstr']) > 0 ) + { + $searchArray = array("\\", "/", ".", ">"); + $replaceArray = array("\\\\", "\/", "\.", ">"); + + // user also wants to highlight words! + if ( strpos($content['highlightstr'], ",") === false) + { + + $content['highlightwords'][0]['highlight_raw'] = $content['highlightstr']; + $content['highlightwords'][0]['highlight'] = str_replace( $searchArray, $replaceArray, $content['highlightstr']); + $content['highlightwords'][0]['cssclass'] = "highlight_1"; + $content['highlightwords'][0]['htmlcode'] = '' . $content['highlightwords'][0]['highlight']. ''; + } + else + { + // Split array into words + $tmparray = explode( ",", $content['highlightstr'] ); + foreach( $tmparray as $word ) + $content['highlightwords'][]['highlight_raw'] = $word; + + // Assign other variables needed for this array entry + for ($i = 0; $i < count($content['highlightwords']); $i++) + { + $content['highlightwords'][$i]['highlight'] = str_replace( $searchArray, $replaceArray, $content['highlightwords'][$i]['highlight_raw']); + $content['highlightwords'][$i]['cssclass'] = "highlight_" . ($i+1); + $content['highlightwords'][$i]['htmlcode'] = '' . $content['highlightwords'][$i]['highlight']. ''; + } + } + + // Default expand Highlight Arrea! + $content['EXPAND_HIGHLIGHT'] = "true"; + } +} +// --- + ?> \ No newline at end of file diff --git a/src/lang/de/main.php b/src/lang/de/main.php index 1844500..4a56a87 100644 --- a/src/lang/de/main.php +++ b/src/lang/de/main.php @@ -60,6 +60,10 @@ $content['LN_GEN_SOURCE_DB'] = "Datenbank"; $content['LN_GEN_ERRORRETURNPREV'] = "Click here to return to the previous site."; $content['LN_GEN_ERRORDETAILS'] = "Error Details:"; + $content['LN_SOURCES_ERROR_WITHINSOURCE'] = "The source '%1' checking returned with an error: '%2'"; +$content['LN_ERROR_NORECORDS'] = "Es wurden keine syslog-Einträge gefunden."; + + // Topmenu Entries $content['LN_MENU_SEARCH'] = "Suchen"; $content['LN_MENU_SHOWEVENTS'] = "Show Events"; @@ -102,8 +106,6 @@ $content['LN_AUTORELOAD_PRECONFIGURED'] = "Preconfigured auto reload "; $content['LN_AUTORELOAD_SECONDS'] = "seconds"; $content['LN_AUTORELOAD_MINUTES'] = "minutes"; -$content['LN_ERROR_NORECORDS'] = "Es wurden keine syslog-Einträge gefunden."; - // Filter Options $content['LN_FILTER_DATE'] = "Zeitliche Abgrenzung"; $content['LN_FILTER_DATEMODE'] = "Zeitraum auswählen"; diff --git a/src/lang/en/main.php b/src/lang/en/main.php index a330118..c4873bf 100644 --- a/src/lang/en/main.php +++ b/src/lang/en/main.php @@ -61,6 +61,27 @@ $content['LN_GEN_DB_SQLITE'] = "SQLite 2"; $content['LN_GEN_ERRORRETURNPREV'] = "Click here to return to the previous site."; $content['LN_GEN_ERRORDETAILS'] = "Error Details:"; + $content['LN_SOURCES_ERROR_WITHINSOURCE'] = "The source '%1' checking returned with an error:
%2"; + $content['LN_SOURCES_ERROR_EXTRAMSG'] = "Extra Error Details:
%1"; +$content['LN_ERROR_NORECORDS'] = "No syslog records found"; +$content['LN_ERROR_FILE_NOT_FOUND'] = "Syslog file could not be found"; +$content['LN_ERROR_FILE_NOT_READABLE'] = "Syslog file is not readable, read access may be denied"; +$content['LN_ERROR_UNKNOWN'] = "Unknown or unhandled error occured (Error Code '%1')"; +$content['LN_ERROR_FILE_EOF'] = "End of File reached"; +$content['LN_ERROR_FILE_BOF'] = "Begin of File reeached"; +$content['LN_ERROR_FILE_CANT_CLOSE'] = "Can't close File"; +$content['LN_ERROR_UNDEFINED'] = "Undefined Error"; +$content['LN_ERROR_EOS'] = "End of stream reached"; +$content['LN_ERROR_FILTER_NOT_MATCH'] = "Filter does not match any results"; +$content['LN_ERROR_DB_CONNECTFAILED'] = "Connection to the database server failed"; +$content['LN_ERROR_DB_CANNOTSELECTDB'] = "Could not find the configured database"; +$content['LN_ERROR_DB_QUERYFAILED'] = "Dataquery failed to execute"; +$content['LN_ERROR_DB_NOPROPERTIES'] = "No database properties found"; +$content['LN_ERROR_DB_INVALIDDBMAPPING'] = "Invalid datafield mappings"; +$content['LN_ERROR_DB_INVALIDDBDRIVER'] = "Invalid database driver selected"; +$content['LN_ERROR_DB_TABLENOTFOUND'] = "Could not find the configured table, maybe misspelled or the tablenames are case sensitive"; +$content['LN_ERROR_'] = ""; + // Topmenu Entries $content['LN_MENU_SEARCH'] = "Search"; $content['LN_MENU_SHOWEVENTS'] = "Show Events"; @@ -102,8 +123,6 @@ $content['LN_AUTORELOAD_PRECONFIGURED'] = "Preconfigured auto reload "; $content['LN_AUTORELOAD_SECONDS'] = "seconds"; $content['LN_AUTORELOAD_MINUTES'] = "minutes"; -$content['LN_ERROR_NORECORDS'] = "No syslog records found."; - // Filter Options $content['LN_FILTER_DATE'] = "Datetime Range"; $content['LN_FILTER_DATEMODE'] = "Select mode"; diff --git a/src/lang/pt_BR/main.php b/src/lang/pt_BR/main.php index f4e46e9..9980e20 100644 --- a/src/lang/pt_BR/main.php +++ b/src/lang/pt_BR/main.php @@ -64,6 +64,10 @@ $content['LN_GEN_SELECTVIEW'] = "Visão"; $content['LN_GEN_ERRORRETURNPREV'] = "Click here to return to the previous site."; $content['LN_GEN_ERRORDETAILS'] = "Error Details:"; + $content['LN_SOURCES_ERROR_WITHINSOURCE'] = "The source '%1' checking returned with an error: '%2'"; +$content['LN_ERROR_NORECORDS'] = "Sem mensagens encontradas."; + + // Topmenu Entries $content['LN_MENU_SEARCH'] = "Search"; $content['LN_MENU_SHOWEVENTS'] = "Show Events"; @@ -105,8 +109,6 @@ $content['LN_AUTORELOAD_PRECONFIGURED'] = "Auto recarregamento pré-config $content['LN_AUTORELOAD_SECONDS'] = "segundos"; $content['LN_AUTORELOAD_MINUTES'] = "minutos"; -$content['LN_ERROR_NORECORDS'] = "Sem mensagens encontradas."; - // Filter Options $content['LN_FILTER_DATE'] = "Intervalo Data/Hora"; $content['LN_FILTER_DATEMODE'] = "Selecionar Modo"; diff --git a/src/templates/admin/admin_groups.html b/src/templates/admin/admin_groups.html index 39fb83f..9b9af7b 100644 --- a/src/templates/admin/admin_groups.html +++ b/src/templates/admin/admin_groups.html @@ -1,12 +1,16 @@ -
+

-

{LN_GEN_ERRORDETAILS} {ERROR_MSG}

-{LN_GEN_ERRORRETURNPREV} +
+
{LN_GEN_ERRORDETAILS}
+

{ERROR_MSG}

+
+

+ {LN_GEN_ERRORRETURNPREV}
-
+

diff --git a/src/templates/admin/admin_searches.html b/src/templates/admin/admin_searches.html index 8154bae..5476310 100644 --- a/src/templates/admin/admin_searches.html +++ b/src/templates/admin/admin_searches.html @@ -1,12 +1,16 @@ -
+

-

{LN_GEN_ERRORDETAILS} {ERROR_MSG}

-{LN_GEN_ERRORRETURNPREV} +
+
{LN_GEN_ERRORDETAILS}
+

{ERROR_MSG}

+
+

+ {LN_GEN_ERRORRETURNPREV}
-
+

diff --git a/src/templates/admin/admin_sources.html b/src/templates/admin/admin_sources.html index 3a33998..ad835af 100644 --- a/src/templates/admin/admin_sources.html +++ b/src/templates/admin/admin_sources.html @@ -30,12 +30,16 @@ -
+

-

{LN_GEN_ERRORDETAILS} {ERROR_MSG}

-{LN_GEN_ERRORRETURNPREV} +
+
{LN_GEN_ERRORDETAILS}
+

{ERROR_MSG}

+
+

+ {LN_GEN_ERRORRETURNPREV}
-
+

diff --git a/src/templates/admin/admin_users.html b/src/templates/admin/admin_users.html index 71e897f..4e2a3f0 100644 --- a/src/templates/admin/admin_users.html +++ b/src/templates/admin/admin_users.html @@ -1,12 +1,16 @@ -
+

-

{LN_GEN_ERRORDETAILS} {ERROR_MSG}

-{LN_GEN_ERRORRETURNPREV} +
+
{LN_GEN_ERRORDETAILS}
+

{ERROR_MSG}

+
+

+ {LN_GEN_ERRORRETURNPREV}
-
+

diff --git a/src/templates/admin/admin_views.html b/src/templates/admin/admin_views.html index d302e8a..3c0ba98 100644 --- a/src/templates/admin/admin_views.html +++ b/src/templates/admin/admin_views.html @@ -1,12 +1,16 @@ -
+

-

{LN_GEN_ERRORDETAILS} {ERROR_MSG}

-{LN_GEN_ERRORRETURNPREV} +
+
{LN_GEN_ERRORDETAILS}
+

{ERROR_MSG}

+
+

+ {LN_GEN_ERRORRETURNPREV}
-
+

diff --git a/src/templates/admin/result.html b/src/templates/admin/result.html index 7238dac..de4f0dc 100644 --- a/src/templates/admin/result.html +++ b/src/templates/admin/result.html @@ -1,7 +1,7 @@

-
+
@@ -9,10 +9,11 @@
{LN_ADMIN_CENTER}
-

- {SZMSG} -

+

+ {SZMSG} +

You will be redirected to the this page on {REDIRSECONDS} seconds. +