]> git.mxchange.org Git - ctracker.git/blobdiff - libs/lib_connect.php
init also this
[ctracker.git] / libs / lib_connect.php
index 175fcbf97bf6566d8a265ac5f603af2edc3cab7e..3a0b4b31974a00ba5bb79cce75fbc33fd32888b1 100644 (file)
@@ -4,7 +4,7 @@
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            3.0.0
- * @copyright  Copyright (c) 2009, 2010 Cracker Tracker Team
+ * @copyright  Copyright (c) 2009 - 2011 Cracker Tracker Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.ship-simu.org
  *
@@ -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__);
 
@@ -37,7 +37,18 @@ function aquireCrackerTrackerDatabaseLink () {
                        // Load the config
                        crackerTrackerLoadConfig();
                }
-       } // END - if
+       } else {
+               // Init fake config
+               crackerTrackerInitFakeConfig();
+       }
+}
+
+// Inits a fake configurtation
+function crackerTrackerInitFakeConfig () {
+       // Set the array
+       $GLOBALS['ctracker_config'] = array(
+               'ctracker_alert_user' => 'Y',
+       );
 }
 
 // Checks if the link is up
@@ -80,6 +91,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 +131,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 +236,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
@@ -282,6 +305,12 @@ function getCrackerTrackerConfig ($entry) {
 
 // Did the current IP already generated blocked attempts?
 function isCrackerTrackerIpSuspicious () {
+       // Skip this silently if we have not config
+       if (!isCrackerTrackerDatabaseLinkUp()) {
+               // Skip this step silently, all is not suspicious
+               return false;
+       } // END - if
+
        // We only need the very last attempt to get!
        $result = runCrackerTrackerSql("SELECT * FROM `ctracker_data` WHERE `remote_addr`='" . determineCrackerTrackerRealRemoteAddress() . "' ORDER BY `last_attempt` DESC LIMIT 1", __FUNCTION__, __LINE__);
 
@@ -340,13 +369,16 @@ function addCrackerTrackerTicket (array $data) {
        if ((isset($GLOBALS['ctracker_last_insert_id'])) && ($GLOBALS['ctracker_last_insert_id'] > 0)) {
                // All fine, so prepare the link between ticket<->data
                $data = array(
-                       'ctracker_ticket => $GLOBALS['ctracker_last_insert_id'],
-                       'ctracker_data_id' => $GLOBALS['ctracker_last_suspicious_entry']['id']
+                       'ctracker_ticket_id' => $GLOBALS['ctracker_last_insert_id'],
+                       'ctracker_data_id'   => $GLOBALS['ctracker_last_suspicious_entry']['id']
                );
 
                // And insert it as well
                crackerTrackerInsertArray('ctracker_ticket_data', $data);
 
+               // Add ticket id again
+               $GLOBALS['ctracker_ticket'] = $data['ctracker_ticket_id'];
+
                // Merge all data for emails
                $GLOBALS['ctracker_last_ticket'] = array_merge($GLOBALS['ctracker_last_ticket'], $data);