diff --git a/classes/logstreamdisk.class.php b/classes/logstreamdisk.class.php index 6c991fb..28f638b 100644 --- a/classes/logstreamdisk.class.php +++ b/classes/logstreamdisk.class.php @@ -154,6 +154,7 @@ class LogStreamDisk extends LogStream { if (($pos = strpos($this->_buffer, "\n", $this->_p_buffer)) !== false) { $uID = $this->_currentStartPos; $logLine = $line . substr($this->_buffer, $this->_p_buffer, $pos - $this->_p_buffer); + $arrProperitesOut[SYSLOG_DATE] = ''; $arrProperitesOut[SYSLOG_FACILITY] = ''; $arrProperitesOut[SYSLOG_FACILITY_TEXT] = ''; $arrProperitesOut[SYSLOG_SEVERITY] = ''; diff --git a/include/constants_logstream.php b/include/constants_logstream.php new file mode 100644 index 0000000..caa6125 --- /dev/null +++ b/include/constants_logstream.php @@ -0,0 +1,66 @@ + www.phplogcon.org <- * + * * + * Use this script at your own risk! * + * ----------------------------------------------------------------- * + * Some constants * + * * + * -> Stuff which has to be static and predefined * + * * + * All directives are explained within this file * + ********************************************************************* +*/ + +// --- Avoid directly accessing this file! +if ( !defined('IN_PHPLOGCON') ) +{ + die('Hacking attempt'); + exit; +} +// --- + +// --- Some custom defines + +// Properties we need from the stream class +define('SYSLOG_DATE', 'timereported'); +define('SYSLOG_FACILITY', 'syslogfacility'); +define('SYSLOG_FACILITY_TEXT', 'syslogfacility-text'); +define('SYSLOG_SEVERITY', 'syslogseverity'); +define('SYSLOG_SEVERITY_TEXT','syslogseverity-text'); +define('SYSLOG_HOST', 'FROMHOST'); +define('SYSLOG_SYSLOGTAG', 'syslogtag'); +define('SYSLOG_MESSAGE', 'msg'); +define('SYSLOG_MESSAGETRUNSCATED', 'msgtrunscated'); +define('SYSLOG_MESSAGETYPE', 'IUT'); + +// MonitorWare InfoUnit Defines +define('IUT_Unknown', '0'); +define('IUT_Syslog', '1'); +define('IUT_Heartbeat', '2'); +define('IUT_NT_EventReport', '3'); +define('IUT_SNMP_Trap', '4'); +define('IUT_File_Monitor', '5'); +define('IUT_PingProbe', '8'); +define('IUT_Port_Probe', '9'); +define('IUT_NTService_Monitor', '10'); +define('IUT_DiskSpace_Monitor', '11'); +define('IUT_DB_Monitor', '12'); +define('IUT_Serial_Monitor', '13'); +define('IUT_CPU_Monitor', '14'); +define('IUT_AliveMonRequest', '16'); +define('IUT_SMTPProbe', '17'); +define('IUT_FTPProbe', '18'); +define('IUT_HTTPProbe', '19'); +define('IUT_POP3Probe', '20'); +define('IUT_IMAPProbe', '21'); +define('IUT_NNTPProbe', '22'); +define('IUT_WEVTMONV2', '23'); +define('IUT_SMTPLISTENER', '24'); +define('IUT_AliveMonECHO', '1999998'); +define('IUT_MIAP_Receiver', '1999999'); + +// --- +?> \ No newline at end of file diff --git a/include/functions_common.php b/include/functions_common.php index eda9fff..65aa2c3 100644 --- a/include/functions_common.php +++ b/include/functions_common.php @@ -24,10 +24,12 @@ if ( !defined('IN_PHPLOGCON') ) // --- Basic Includes include($gl_root_path . 'include/constants_general.php'); +include($gl_root_path . 'config.php'); + +include($gl_root_path . 'classes/class_template.php'); include($gl_root_path . 'include/functions_themes.php'); include($gl_root_path . 'include/functions_db.php'); -include($gl_root_path . 'classes/class_template.php'); -include($gl_root_path . 'config.php'); +include($gl_root_path . 'include/functions_config.php'); // --- // --- Define Basic vars diff --git a/include/functions_config.php b/include/functions_config.php new file mode 100644 index 0000000..c85a2cb --- /dev/null +++ b/include/functions_config.php @@ -0,0 +1,87 @@ + www.phplogcon.org <- * + * * + * Use this script at your own risk! * + * ----------------------------------------------------------------- * + * Maintain and read Source Configurations * + * * + * -> Configuration need variables for the Database connection * + ********************************************************************* + */ + + // --- Avoid directly accessing this file! + if ( !defined('IN_PHPLOGCON') ) + { + die('Hacking attempt'); + exit; + } + // --- + + require_once('classes/logstreamconfig.class.php'); + require_once('classes/logstreamconfigdisk.class.php'); + + function InitSourceConfigs() + { + global $CFG, $Sources, $currentSourceID; + + // Init Source Configs! + if ( isset($CFG['Sources']) ) + { + $iCount = count($CFG['Sources']); + for ( $i = 0; $i< $iCount; $i++ ) + { + if ( isset($CFG['Sources'][$i]['SourceType']) ) + { + // Set Array Index, TODO: Check for invalid characters! + $iSourceID = $CFG['Sources'][$i]['ID']; + if ( !isset($Sources[$iSourceID]) ) + { + // Copy general properties + $Sources[$iSourceID]['Name'] = $CFG['Sources'][$i]['Name']; + $Sources[$iSourceID]['SourceType'] = $CFG['Sources'][$i]['SourceType']; + + // Create Config instance! + if ( $CFG['Sources'][$i]['SourceType'] == SOURCE_DISK ) + { + $Sources[$iSourceID]['ObjRef'] = new LogStreamConfigDisk(); + $Sources[$iSourceID]['ObjRef']->FileName = $CFG['Sources'][$i]['DiskFile']; + } + else if ( $CFG['Sources'][$i]['SourceType'] == SOURCE_MYSQLDB ) + { + // TODO! + die( "Not supported yet!" ); + } + else + { + // UNKNOWN, remove config entry! + unset($Sources[$iSourceID]); + + // TODO: Output CONFIG WARNING + } + + // Set default SourceID here! + if ( isset($Sources[$iSourceID]) && !isset($currentSourceID) ) + $currentSourceID = $iSourceID; + } + else + { + // TODO: OUTPUT CONFIG WARNING - duplicated ID! + } + } + } + } + + // Set Source from session if available! + if ( isset($_SESSION['currentSourceID']) && isset($Sources[$_SESSION['currentSourceID']]) ) + $currentSourceID = $_SESSION['currentSourceID']; + else + { + // No Source stored in session, then to so now! + $_SESSION['currentSourceID'] = $currentSourceID; + } + } + +?> \ No newline at end of file diff --git a/include/functions_parser.php b/include/functions_parser.php deleted file mode 100644 index cb8765d..0000000 --- a/include/functions_parser.php +++ /dev/null @@ -1,60 +0,0 @@ - www.phplogcon.org <- * - * * - * Use this script at your own risk! * - * ----------------------------------------------------------------- * - * Parser functions * - * * - * All directives are explained within this file * - ********************************************************************* -*/ - -// --- Avoid directly accessing this file! -if ( !defined('IN_PHPLOGCON') ) -{ - die('Hacking attempt'); - exit; -} -// --- - -function ParseSyslogHeader($szLogLine) -{ - // Init values - $syslogDate = "Feb 7 17:56:24"; - $syslogFacility = 16; - $syslogFacilityText = "kernel"; - $syslogSeverity = 5; - $syslogSeverityText = "notice"; - $syslogTag = "syslog"; - $syslogHost = "localhost"; - $syslogMsg = $szLogLine; - $syslogIUT = IUT_Syslog; - - // Parse from logline! - //SAMPLE: Mar 10 14:45:39 debandre syslogd 1.4.1#18: restart. - //SAMPLE: Mar 10 14:45:44 debandre anacron[3226]: Job `cron.daily' terminated (mailing output) - //'<' % text($pri) & '>' & date2text($datereceived, rfc3339) & $hostname & tolower($msg) - -SYSLOG_DATE => $syslogDate, - array ( SYSLOG_FACILITY, SYSLOG_FACILITY_TEXT, SYSLOG_SEVERITY, SYSLOG_SEVERITY_TEXT, SYSLOG_HOST, SYSLOG_SYSLOGTAG, SYSLOG_MESSAGE, SYSLOG_MESSAGETYPE ); - - // return results - return array ( - SYSLOG_DATE => $syslogDate, - SYSLOG_FACILITY => $syslogFacility, - SYSLOG_FACILITY_TEXT => $syslogFacilityText, - SYSLOG_SEVERITY => $syslogSeverity, - SYSLOG_SEVERITY_TEXT => $syslogSeverityText, - SYSLOG_HOST => $syslogHost, - SYSLOG_SYSLOGTAG => $syslogTag, - SYSLOG_MESSAGE => $syslogMsg, - SYSLOG_MESSAGETRUNSCATED => strlen($syslogMsg) > 100 ? substr($syslogMsg, 0, 100 ) . " ..." : $syslogMsg, - SYSLOG_MESSAGETYPE => $syslogIUT - ); -} - - -?> \ No newline at end of file diff --git a/index.php b/index.php index 3a77060..a585b68 100644 --- a/index.php +++ b/index.php @@ -18,10 +18,10 @@ define('IN_PHPLOGCON', true); $gl_root_path = './'; include($gl_root_path . 'include/functions_common.php'); -include($gl_root_path . 'include/functions_parser.php'); include($gl_root_path . 'include/functions_frontendhelpers.php'); InitPhpLogCon(); +InitSourceConfigs(); InitFrontEndDefaults(); // Only in WebFrontEnd // *** *** // @@ -33,27 +33,38 @@ InitFrontEndDefaults(); // Only in WebFrontEnd // --- // --- BEGIN Custom Code -if ( $CFG['SourceType'] == SOURCE_DISK ) +if ( isset($Sources[$currentSourceID]) && $Sources[$currentSourceID]['SourceType'] == SOURCE_DISK ) { require_once('classes/enums.class.php'); require_once('classes/logstream.class.php'); - require_once('classes/logstreamconfig.class.php'); - require_once('classes/logstreamconfigdisk.class.php'); require_once('classes/logstreamdisk.class.php'); require_once('include/constants_errors.php'); - $stream_config = new LogStreamConfigDisk(); - $stream_config->FileName = $CFG['DiskFile']; + require_once('include/constants_logstream.php'); + + + // Obtain Config Object + $stream_config = $Sources[$currentSourceID]['ObjRef']; + + // Create LogStream Object $stream = $stream_config->LogStreamFactory($stream_config); - $stream->Open(null, true); + $stream->Open( array ( SYSLOG_DATE, SYSLOG_FACILITY, SYSLOG_FACILITY_TEXT, SYSLOG_SEVERITY, SYSLOG_SEVERITY_TEXT, SYSLOG_HOST, SYSLOG_SYSLOGTAG, SYSLOG_MESSAGE, SYSLOG_MESSAGETYPE ), true); $uID = -1; - $logLine = ''; $counter = 0; - $stream->SetReadDirection(EnumReadDirection::Backward); +// $stream->SetReadDirection(EnumReadDirection::Backward); - while ($stream->ReadNext($uID, $logLine) == 0 && $counter <= 30) + while ($stream->ReadNext($uID, $logArray) == 0 && $counter <= 30) { - $content['syslogmessages'][] = ParseSyslogHeader($logLine); + // Copy Obtained array + $content['syslogmessages'][] = $logArray; + + // Set truncasted message for display + if ( isset($logArray[SYSLOG_MESSAGE]) ) + $content['syslogmessages'][$counter][SYSLOG_MESSAGETRUNSCATED] = strlen($logArray[SYSLOG_MESSAGE]) > 100 ? substr($logArray[SYSLOG_MESSAGE], 0, 100 ) . " ..." : $logArray[SYSLOG_MESSAGE]; + else + $content['syslogmessages'][$counter][SYSLOG_MESSAGETRUNSCATED] = ""; + + // Increment Counter $counter++; }