From 8d7c6fd65adb38291dcb1953e10dc1d6460837e4 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 8 Jul 2010 21:47:56 +0000 Subject: [PATCH] Updated to allow database-less operation --- ctracker.php | 1 - libs/lib_ | 1 - libs/lib_connect.php | 16 ++++++++++++++-- libs/lib_detector.php | 10 ++++++++-- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/ctracker.php b/ctracker.php index acb5bc5..1f071e3 100644 --- a/ctracker.php +++ b/ctracker.php @@ -1,6 +1,5 @@ * @version 3.0.0 * @copyright Copyright (c) 2009, 2010 Cracker Tracker Team diff --git a/libs/lib_connect.php b/libs/lib_connect.php index 3747416..82e6fe0 100644 --- a/libs/lib_connect.php +++ b/libs/lib_connect.php @@ -25,7 +25,7 @@ // Function to aquire a database link function aquireCrackerTrackerDatabaseLink () { // Is the link up? - if (!isCrackerTrackerDatabaseLinkUp()) { + if ((!isCrackerTrackerDatabaseLinkUp()) && (!empty($GLOBALS['ctracker_host'])) && (!empty($GLOBALS['ctracker_dbname'])) && (!empty($GLOBALS['ctracker_user']))) { // Then connect to the database $GLOBALS['ctracker_link'] = mysql_connect($GLOBALS['ctracker_host'], $GLOBALS['ctracker_user'], $GLOBALS['ctracker_password']) or crackerTrackerDatabaseError(__FUNCTION__, __LINE__); @@ -80,6 +80,12 @@ function crackerTrackerCloseDatabaseLink () { // Inserts given array, if IP/check_worm combination was not found function crackerTrackerInsertArray ($table, $rowData) { + // Is there a link up? + if (!isCrackerTrackerDatabaseLinkUp()) { + // Abort silently here + return false; + } // END - if + // Is it found? if (!isCrackerTrackerEntryFound($rowData)) { // Prepare SQL @@ -114,7 +120,7 @@ function isCrackerTrackerEntryFound ($rowData) { $SQL = 'SELECT `id` FROM `ctracker_data` WHERE `remote_addr`="' . crackerTrackerEscapeString($rowData['remote_addr']) . '" AND `check_worm` = "' . crackerTrackerEscapeString($rowData['check_worm']) . '" AND `server_name`="' . crackerTrackerEscapeString($rowData['server_name']) . '" LIMIT 1'; // Run the SQL and check if we have one line - return (mysql_num_rows(runCrackerTrackerSql($SQL, __FUNCTION__, __LINE__)) == 1); + return ((isCrackerTrackerDatabaseLinkUp()) && (mysql_num_rows(runCrackerTrackerSql($SQL, __FUNCTION__, __LINE__)) == 1)); } // Escapes the string @@ -219,6 +225,12 @@ function crackerTrackerInitTable ($table) { // Updates the database scheme automatically function crackerTrackerUpdateDatabaseScheme () { + // Is a link there? + if (!isCrackerTrackerDatabaseLinkUp()) { + // Abort here silently + return; + } // END - if + // Is the main config table there? if (!isCrackerTrackerTableCreated('ctracker_config')) { // Then do it for us diff --git a/libs/lib_detector.php b/libs/lib_detector.php index ecd95ba..1c16b54 100644 --- a/libs/lib_detector.php +++ b/libs/lib_detector.php @@ -160,7 +160,7 @@ function crackerTrackerSendMail ($mail, $recipient = null, $subject = null) { // Send the email out only in non-debug mode if (isCrackerTrackerDebug()) { // Output message - print 'Recipient='.$recipient.'
Subject='.$subject.'
Text=
' . $mail . '
'; + print 'Recipient=' . $recipient . '
Subject=' . $subject . '
Text=
' . $mail . '
'; // All fine return true; @@ -174,7 +174,13 @@ function crackerTrackerSendMail ($mail, $recipient = null, $subject = null) { // Send it the deprecated way with constant return mail(constant('__CTRACKER_EMAIL'), 'CTracker: Attack detected!', $mail, $GLOBALS['ctracker_header']); } - } // END - if + } elseif (isCrackerTrackerDebug()) { + // Output message + print 'Recipient=' . $recipient . '
Subject=' . $subject . '
Text=
' . $mail . '
'; + + // All fine + return true; + } } // Sends a detected POST attack mail -- 2.39.5