Fixed a problem when adding a mysql logstream source.

Due a problem of how php mysql_connect function handels second conenctions,
the Verify of a newly added logstream source could cause the first database
connection to be overwritten. The following error is, that the wrong
database was used for the UserDB after the new logstream was verified.

Also added a check into the redirect function to STOP redirecting if an
error happened in the UserDB before.
This commit is contained in:
Andre Lorbach 2008-10-24 15:14:58 +02:00
parent b68ecbec22
commit 3b49279a8a
7 changed files with 260 additions and 169 deletions

View File

@ -118,6 +118,7 @@ class LogStreamDB extends LogStream {
*/
public function Close()
{
if ($this->_dbhandle)
mysql_close($this->_dbhandle);
return SUCCESS;
}
@ -131,7 +132,8 @@ class LogStreamDB extends LogStream {
// Try to connect to the database
if ( $this->_dbhandle == null )
{
$this->_dbhandle = @mysql_connect($this->_logStreamConfigObj->DBServer,$this->_logStreamConfigObj->DBUser,$this->_logStreamConfigObj->DBPassword);
// Forces to open a new link in all cases!
$this->_dbhandle = @mysql_connect($this->_logStreamConfigObj->DBServer,$this->_logStreamConfigObj->DBUser,$this->_logStreamConfigObj->DBPassword, true);
if (!$this->_dbhandle)
{
if ( isset($php_errormsg) )

View File

@ -72,10 +72,71 @@ class MsgParser_wireless extends MsgParser {
//trim the msg first to remove spaces from begin and end
$szMsg = trim($szMsg);
//return ERROR_MSG_NOMATCH;
// Sample: Oct 14 21:05:52 script,info INICIO; Madrid-arturosoria ;wlan1 ;00:1F:3A:66:70:09 ;192.168.10.117 ;24Mbps ;36Mbps ;15:50:56 ;00:00:00.080 ;-80dBm@1Mbps ;21 ;78 ;43351,126437 ;2959,377
if ( preg_match('/(...)(?:.|..)([0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}) (.*?),(.*?) (.*?);(.|.*?);(.|.*?);(.|.*?);(.|.*?);(.|.*?);(.|.*?);(.|.*?);(.|.*?);(.|.*?);(.|.*?);(.|.*?);(.|.*?)$/', $szMsg, $out) )
if ( preg_match('/(.*?);(.|.*?);(.|.*?);(.|.*?);(.|.*?);(.|.*?);(.|.*?);(.|.*?);(.|.*?);(.|.*?);(.|.*?);(.|.*?);(.|.*?)$/', $szMsg, $out) )
{
$arrArguments[SYSLOG_HOST] = $out[1];
// Set wlan log specific properties!
$arrArguments[SYSLOG_NET_INTERFACE] = trim($out[2]);
$arrArguments[SYSLOG_NET_MAC_ADDRESS] = trim($out[3]);
$arrArguments[SYSLOG_NET_LASTIP] = trim($out[4]);
$arrArguments[SYSLOG_NET_RXRATE] = trim($out[5]);
$arrArguments[SYSLOG_NET_TXRATE] = trim($out[6]);
$arrArguments[SYSLOG_NET_UPTIME] = trim($out[7]);
$arrArguments[SYSLOG_NET_LASTACTIVITY] = trim($out[8]);
$arrArguments[SYSLOG_NET_SIGNALSTRENGTH] = trim($out[9]);
// Number based fields
$arrArguments[SYSLOG_NET_SIGNALTONOISE] = $out[10];
$arrArguments[SYSLOG_NET_TXCCQ] = $out[11];
// Set msg to whole logline
$arrArguments[SYSLOG_MESSAGE] = $out[0];
// Get additional parameters!
if ( preg_match('/(.|.*?[0-9]{1,12}.*?),(.|.*?[0-9]{1,12}.*?);(.|.*?[0-9]{1,12}.*?),(.|.*?[0-9]{1,12}.*?)$/', $out[12], $out2) )
{
$arrArguments[SYSLOG_NET_BYTESRECIEVED] = $out2[1];
$arrArguments[SYSLOG_NET_BYTESSEND] = $out2[2];
$arrArguments[SYSLOG_NET_PACKETSRECIEVED] = $out2[3];
$arrArguments[SYSLOG_NET_PACKETSSEND] = $out2[4];
}
else
{
$arrArguments[SYSLOG_NET_BYTESRECIEVED] = "";
$arrArguments[SYSLOG_NET_BYTESSEND] = "";
$arrArguments[SYSLOG_NET_PACKETSRECIEVED] = "";
$arrArguments[SYSLOG_NET_PACKETSSEND] = "";
}
if ( $this->_MsgNormalize == 1 )
{
//Init tmp msg
$szTmpMsg = "";
// Create Field Array to prepend into msg! Reverse Order here
$myFields = array( SYSLOG_NET_PACKETSSEND, SYSLOG_NET_PACKETSRECIEVED, SYSLOG_NET_BYTESSEND, SYSLOG_NET_BYTESRECIEVED, SYSLOG_NET_TXCCQ, SYSLOG_NET_SIGNALTONOISE, SYSLOG_NET_UPTIME, SYSLOG_NET_SIGNALSTRENGTH, SYSLOG_NET_LASTACTIVITY, SYSLOG_NET_TXRATE, SYSLOG_NET_RXRATE, SYSLOG_NET_LASTIP, SYSLOG_NET_MAC_ADDRESS, SYSLOG_NET_INTERFACE, SYSLOG_HOST );
foreach ( $myFields as $myField )
{
// Set Field Caption
if ( isset($fields[$myField]['FieldCaption']) )
$szFieldName = $fields[$myField]['FieldCaption'];
else
$szFieldName = $myField;
// Append Field into msg
$szTmpMsg = $szFieldName . ": '" . $arrArguments[$myField] . "'\n" . $szTmpMsg;
}
// copy finished MSG back!
$arrArguments[SYSLOG_MESSAGE] = $szTmpMsg;
}
}
// Sample: Madrid-arturosoria ;wlan1 ;00:1F:3A:66:70:09 ;192.168.10.117 ;24Mbps ;36Mbps ;15:50:56 ;00:00:00.080 ;-80dBm@1Mbps ;21 ;78 ;43351,126437 ;2959,377
else if ( preg_match('/(...)(?:.|..)([0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}) (.*?),(.*?) (.*?);(.|.*?);(.|.*?);(.|.*?);(.|.*?);(.|.*?);(.|.*?);(.|.*?);(.|.*?);(.|.*?);(.|.*?);(.|.*?);(.|.*?)$/', $szMsg, $out) )
{
//print_r ( $out );

View File

@ -892,14 +892,14 @@ function DieWithErrorMsg( $szerrmsg )
echo
"<html><title>phpLogCon :: Critical Error occured</title><head>" .
"<link rel=\"stylesheet\" href=\"" . $gl_root_path . "themes/default/main.css\" type=\"text/css\"></head><body><br><br>" .
"<table width=\"600\" align=\"center\" class=\"with_border_alternate ErrorMsg\"><tr>".
"<table width=\"600\" align=\"center\" class=\"with_border_alternate ErrorMsg\" cellpadding=\"2\"><tr>".
"<td class=\"PriorityError\" align=\"center\" colspan=\"2\">" .
"<H3>Critical Error occured</H3>" .
"</td></tr>" .
"<tr><td class=\"cellmenu1\" align=\"left\">Errordetails:</td>" .
"<td class=\"tableBackground\" align=\"left\">" .
"<tr><td class=\"cellmenu1_naked\" align=\"left\">Errordetails:</td>" .
"<td class=\"tableBackground\" align=\"left\"><br>" .
$szerrmsg .
"</td></tr></table>" .
"<br><br></td></tr></table>" .
"</body></html>";
exit;
}
@ -910,14 +910,14 @@ function DieWithFriendlyErrorMsg( $szerrmsg )
echo
"<html><title>phpLogCon :: Error occured</title><head>" .
"<link rel=\"stylesheet\" href=\"" . $gl_root_path . "themes/default/main.css\" type=\"text/css\"></head><body><br><br>" .
"<table width=\"600\" align=\"center\" class=\"with_border_alternate ErrorMsg\"><tr>".
"<table width=\"600\" align=\"center\" class=\"with_border_alternate ErrorMsg\" cellpadding=\"2\"><tr>".
"<td class=\"PriorityWarning\" align=\"center\" colspan=\"2\">" .
"<H3>Error occured</H3>" .
"</td></tr>" .
"<tr><td class=\"cellmenu1\" align=\"left\">Errordetails:</td>" .
"<td class=\"tableBackground\" align=\"left\">" .
"<tr><td class=\"cellmenu1_naked\" align=\"left\">Errordetails:</td>" .
"<td class=\"tableBackground\" align=\"left\"><br>" .
$szerrmsg .
"</td></tr></table>" .
"<br><br></td></tr></table>" .
"</body></html>";
exit;
}
@ -1005,6 +1005,12 @@ function RedirectPage( $newpage )
function RedirectResult( $szMsg, $newpage )
{
global $content;
if ( defined('PHPLOGCON_INERROR') )
DieWithErrorMsg( GetAndReplaceLangStr($content["LN_ERROR_REDIRECTABORTED"], $newpage) );
// Perform redirect!
header("Location: result.php?msg=" . urlencode($szMsg) . "&redir=" . urlencode($newpage));
exit;
}
@ -1507,6 +1513,22 @@ function list_files($directory, $failOnError = true)
}
}
/*
* Helper function to flush html output to avoid redirects if errors happen!
*/
function FlushHtmlOutput()
{
global $RUNMODE;
// not needed in console mode
if ( $RUNMODE == RUNMODE_COMMANDLINE )
return;
//Flush php output
@flush();
@ob_flush();
}
/*
* Helper function to get the errorCode
*/

View File

@ -216,6 +216,9 @@ function DB_PrintError($MyErrorMsg, $DieOrNot)
$errdesc = mysql_error();
$errno = mysql_errno();
// Define global variable so we know an error has occured!
define('PHPLOGCON_INERROR', true);
$errormsg="Database error: $MyErrorMsg $linesep";
$errormsg.="mysql error: $errdesc $linesep";
$errormsg.="mysql error number: $errno $linesep";

View File

@ -97,6 +97,7 @@ $content['LN_ERROR_NORECORDS'] = "Es wurden keine syslog-Eintr&auml;ge gefunden.
$content['LN_WARNING_LOGSTREAMDISK_TIMEOUT'] = "While reading the logstream, the php script timeout forced me to abort at this point.<br><br> If you want to avoid this, please increase the phpLogCon script timeout in your config.php. If the user system is installed, you can do that in Admin center.";
$content['LN_WARNING_DBUPGRADE'] = "Database Upgrade required";
$content['LN_WARNING_DBUPGRADE_TEXT'] = "The current installed database version is '%1'.<br>An update to version '%2' is available.";
$content['LN_ERROR_REDIRECTABORTED'] = 'Automatic redirect to the <a href="%1">page</a> was aborted, as an internal error occured. Please see the error details above and contact our support forums if you need assistance.';
// Topmenu Entries
$content['LN_MENU_SEARCH'] = "Suchen";

View File

@ -99,6 +99,7 @@ $content['LN_ERROR_DB_DBFIELDNOTFOUND'] = "Database Field mapping for at least o
$content['LN_ERROR_FILE_NOMORETIME'] = "No more time for processing left";
$content['LN_WARNING_DBUPGRADE'] = "Database Upgrade required";
$content['LN_WARNING_DBUPGRADE_TEXT'] = "The current installed database version is '%1'.<br>An update to version '%2' is available.";
$content['LN_ERROR_REDIRECTABORTED'] = 'Automatic redirect to the <a href="%1">page</a> was aborted, as an internal error occured. Please see the error details above and contact our support forums if you need assistance.';
// Topmenu Entries
$content['LN_MENU_SEARCH'] = "Search";

View File

@ -101,6 +101,7 @@ $content['LN_ERROR_NORECORDS'] = "Sem mensagens encontradas.";
$content['LN_WARNING_LOGSTREAMDISK_TIMEOUT'] = "While reading the logstream, the php script timeout forced me to abort at this point.<br><br> If you want to avoid this, please increase the phpLogCon script timeout in your config.php. If the user system is installed, you can do that in Admin center.";
$content['LN_WARNING_DBUPGRADE'] = "Database Upgrade required";
$content['LN_WARNING_DBUPGRADE_TEXT'] = "The current installed database version is '%1'.<br>An update to version '%2' is available.";
$content['LN_ERROR_REDIRECTABORTED'] = 'Automatic redirect to the <a href="%1">page</a> was aborted, as an internal error occured. Please see the error details above and contact our support forums if you need assistance.';
// Topmenu Entries
$content['LN_MENU_SEARCH'] = "Search";