From: Roland Häder Date: Sun, 6 Jul 2025 14:57:45 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=239973c315a20d2384bbf4c139d752a38cb6786a;p=ctracker.git Continued: - added return types --- diff --git a/libs/lib_connect.php b/libs/lib_connect.php index b6344a9..d217437 100644 --- a/libs/lib_connect.php +++ b/libs/lib_connect.php @@ -23,7 +23,7 @@ */ // Function to aquire a database link -function aquireCrackerTrackerDatabaseLink () { +function aquireCrackerTrackerDatabaseLink (): void { // Is the link up? if ((!isCrackerTrackerDatabaseLinkUp()) && (!empty($GLOBALS['ctracker_host'])) && (!empty($GLOBALS['ctracker_dbname'])) && (!empty($GLOBALS['ctracker_user']))) { // Then connect to the database @@ -44,7 +44,7 @@ function aquireCrackerTrackerDatabaseLink () { } // Inits a fake configurtation -function crackerTrackerInitFakeConfig () { +function crackerTrackerInitFakeConfig (): void { // Set the array $GLOBALS['ctracker_config'] = [ 'ctracker_alert_user' => 'Y', @@ -52,7 +52,7 @@ function crackerTrackerInitFakeConfig () { } // Checks if the link is up -function isCrackerTrackerDatabaseLinkUp () { +function isCrackerTrackerDatabaseLinkUp (): bool { // Is the instance at least set? if (isset($GLOBALS['ctracker_link'])) { // Debug message @@ -66,7 +66,7 @@ function isCrackerTrackerDatabaseLinkUp () { } // Database error detected -function crackerTrackerDatabaseError (string $file, int $line) { +function crackerTrackerDatabaseError (string $file, int $line): void { // Should we debug? if (isCrackerTrackerDebug()) { // Output error @@ -89,7 +89,7 @@ function crackerTrackerDatabaseError (string $file, int $line) { } // Closes a maybe open database link -function crackerTrackerCloseDatabaseLink () { +function crackerTrackerCloseDatabaseLink (): void { // The link should be up here if (!isCrackerTrackerDatabaseLinkUp()) { // Throw exception @@ -104,7 +104,7 @@ function crackerTrackerCloseDatabaseLink () { } // Inserts given array, if IP/check_get combination was not found -function crackerTrackerInsertArray (string $table, array $rowData) { +function crackerTrackerInsertArray (string $table, array $rowData): void { // Is it found? if (!isCrackerTrackerEntryFound($rowData)) { // Reset insert id @@ -126,7 +126,7 @@ function crackerTrackerInsertArray (string $table, array $rowData) { } // Updates a given entry by just counting it up -function updateCrackerTrackerEntry (array $rowData, string $countColumn = 'count') { +function updateCrackerTrackerEntry (array $rowData, string $countColumn = 'count'): void { // The link should be up here if (!isCrackerTrackerDatabaseLinkUp()) { // Throw exception @@ -143,7 +143,7 @@ function updateCrackerTrackerEntry (array $rowData, string $countColumn = 'count } // Checks if an entry with IP/check_get/domain combination is there -function isCrackerTrackerEntryFound (array $rowData) { +function isCrackerTrackerEntryFound (array $rowData): bool { // The link should be up here if (!isCrackerTrackerDatabaseLinkUp()) { // Throw exception @@ -163,7 +163,7 @@ function isCrackerTrackerEntryFound (array $rowData) { } // Escapes the string -function crackerTrackerEscapeString (string $string) { +function crackerTrackerEscapeString (string $string): string { // Is the link up? if (!isCrackerTrackerDatabaseLinkUp()) { // Then we cant use mysqli_real_escape_string! @@ -199,7 +199,7 @@ function runCrackerTrackerSql (string $sqlString, string $function, int $line) { } // Checks wether a table was found -function isCrackerTrackerTableCreated (string $table) { +function isCrackerTrackerTableCreated (string $table): bool { // Default is not found $found = false; @@ -227,7 +227,7 @@ function isCrackerTrackerTableCreated (string $table) { } // Creates the given table with columns -function crackerTrackerCreateTable (string $table, array $columns, array $keys) { +function crackerTrackerCreateTable (string $table, array $columns, array $keys): void { // Begin the SQL $sqlString = 'CREATE TABLE IF NOT EXISTS `' . $table . '` ('; @@ -257,7 +257,7 @@ function crackerTrackerCreateTable (string $table, array $columns, array $keys) } // Inits a table by inserting -function crackerTrackerInitTable (string $table) { +function crackerTrackerInitTable (string $table): void { // Prepare SQL and run it runCrackerTrackerSql(sprintf("INSERT INTO `%s` (`%s`) VALUES (NULL)'", $table, @@ -266,7 +266,7 @@ function crackerTrackerInitTable (string $table) { } // Updates the database scheme automatically -function crackerTrackerUpdateDatabaseScheme () { +function crackerTrackerUpdateDatabaseScheme (): void { // Is a link there? if (!isCrackerTrackerDatabaseLinkUp()) { // Abort here silently @@ -306,7 +306,7 @@ function crackerTrackerUpdateDatabaseScheme () { } // Load the configuration -function crackerTrackerLoadConfig () { +function crackerTrackerLoadConfig (): void { // Construct SQL command and run it $result = runCrackerTrackerSql('SELECT * FROM `ctracker_config` WHERE `ctracker_config`=1 LIMIT 1', __FUNCTION__, __LINE__); @@ -336,7 +336,7 @@ function getCrackerTrackerConfig (string $entry) { } // Did the current IP already generated blocked attempts? -function isCrackerTrackerIpSuspicious () { +function isCrackerTrackerIpSuspicious (): bool { // Skip this silently if we have not config if (!isCrackerTrackerDatabaseLinkUp()) { // Skip this step silently, all is not suspicious @@ -369,7 +369,7 @@ function isCrackerTrackerIpSuspicious () { } // Does the current IP have a ticket? -function ifCrackerTrackerIpHasTicket () { +function ifCrackerTrackerIpHasTicket (): bool { // We only give one ticket per IP! $result = runCrackerTrackerSql("SELECT * FROM `ctracker_ticket` WHERE `ctracker_ticket_remote_addr`='" . determineCrackerTrackerRealRemoteAddress() . "' OR `ctracker_ticket_proxy_addr`='" . getenv('REMOTE_ADDR') . "' LIMIT 1", __FUNCTION__, __LINE__); @@ -390,7 +390,7 @@ function ifCrackerTrackerIpHasTicket () { } // Adds a ticket based on given (mostly $_POST) data -function addCrackerTrackerTicket (array $data) { +function addCrackerTrackerTicket (array $data): void { // Prepare the array $GLOBALS['ctracker_last_ticket'] = [ 'ctracker_ticket_remote_addr' => determineCrackerTrackerRealRemoteAddress(), @@ -436,7 +436,7 @@ function addCrackerTrackerTicket (array $data) { } // Frees given result instance -function freeCrackerTrackerResult (mysqli_result $result) { +function freeCrackerTrackerResult (mysqli_result $result): void { // Free result $result->free(); } diff --git a/libs/lib_detector.php b/libs/lib_detector.php index a9b2d04..c3973e6 100644 --- a/libs/lib_detector.php +++ b/libs/lib_detector.php @@ -23,7 +23,7 @@ */ // Initializes all detector arrays -function initCrackerTrackerArrays () { +function initCrackerTrackerArrays (): void { // Set error_reporting if (isCrackerTrackerDebug()) { // For debugging purposes, this is fine @@ -256,7 +256,7 @@ function initCrackerTrackerArrays () { } // Checks for worms -function isCrackerTrackerWormDetected () { +function isCrackerTrackerWormDetected (): bool { // Check against the whole list $GLOBALS['ctracker_checked_get'] = urldecode(str_ireplace($GLOBALS['ctracker_get_blacklist'], '*', crackerTrackerQueryString(true))); $GLOBALS['ctracker_checked_ua'] = urldecode(str_ireplace($GLOBALS['ctracker_ua_blacklist'], '*', crackerTrackerUserAgent(true))); @@ -281,7 +281,7 @@ function isCrackerTrackerWormDetected () { } // Checks POST data -function isCrackerTrackerPostAttackDetected () { +function isCrackerTrackerPostAttackDetected (): bool { // Implode recursive the whole $_POST array $GLOBALS['ctracker_post_track'] = urldecode(implode_r('&', $_POST)); @@ -293,7 +293,7 @@ function isCrackerTrackerPostAttackDetected () { } // Prepares a mail and send it out -function sendCrackerTrackerMail () { +function sendCrackerTrackerMail (): void { // Log the attack crackerTrackerLogAttack(); @@ -319,7 +319,7 @@ Referrer : ' . crackerTrackerReferer() . ' } // Sends the ticket emails out -function sendCrackerTrackerTicketMails () { +function sendCrackerTrackerTicketMails (): void { // Load user template $mail = crackerTrackerLoadEmailTemplate('user_add_ticket', $GLOBALS['ctracker_last_ticket']); @@ -334,7 +334,7 @@ function sendCrackerTrackerTicketMails () { } // Sends a mail out -function crackerTrackerSendMail (string $mail, string $recipient = NULL, string $subject = NULL) { +function crackerTrackerSendMail (string $mail, string $recipient = NULL, string $subject = NULL): bool { // Construct dummy array $rowData = [ 'remote_addr' => determineCrackerTrackerRealRemoteAddress(), @@ -373,7 +373,7 @@ function crackerTrackerSendMail (string $mail, string $recipient = NULL, string } // Sends a detected POST attack mail -function sendCrackerTrackerPostMail () { +function sendCrackerTrackerPostMail (): void { // Log the attack crackerTrackerLogAttack(); @@ -402,7 +402,7 @@ Filtered POST string : ' . $GLOBALS['ctracker_checked_post'] . ' } // Sleeps for a random time and aborts the script -function crackerTrackerDie () { +function crackerTrackerDie (): void { // Check if link is up if (isCrackerTrackerDatabaseLinkUp()) { // Close database link @@ -428,7 +428,7 @@ function crackerTrackerDie () { } // Logs the attack attempt -function crackerTrackerLogAttack () { +function crackerTrackerLogAttack (): void { // Aquire database link aquireCrackerTrackerDatabaseLink(); @@ -455,7 +455,7 @@ function crackerTrackerLogAttack () { } // Increases count of spam-bot accesses for the current IP -function ctrackerIncreaseAntiSpambotCount () { +function ctrackerIncreaseAntiSpambotCount (): void { // Init row data $rowData = [ 'remote_addr' => determineCrackerTrackerRealRemoteAddress(), @@ -467,7 +467,7 @@ function ctrackerIncreaseAntiSpambotCount () { } // Alerts the current user about malicious/suspicious traffic -function crackerTrackerAlertCurrentUser () { +function crackerTrackerAlertCurrentUser (): void { // Is there some data? if (isset($GLOBALS['ctracker_last_suspicious_entry'])) { // Does the user have a ticket? diff --git a/libs/lib_general.php b/libs/lib_general.php index 1adec47..f5c892d 100644 --- a/libs/lib_general.php +++ b/libs/lib_general.php @@ -516,7 +516,7 @@ function crackerTrackerRedirectSameUrl () { * @link http://support.microsoft.com/kb/q176113/ * @author Andreas Gohr */ -function crackerTrackerSendRawRedirect (string $url) { +function crackerTrackerSendRawRedirect (string $url): void { // Better remove any data by ctracker unsetCtrackerData(); @@ -541,7 +541,7 @@ function crackerTrackerSendRawRedirect (string $url) { } // Removes all ctracker-related data from global space -function unsetCtrackerData () { +function unsetCtrackerData (): void { // Debug message //* DEBUG: */ error_log(__FUNCTION__ . ': CALLED!'); @@ -577,16 +577,16 @@ function unsetCtrackerData () { } // Sanitizes string -function crackerTrackerSanitize (string $str) { +function crackerTrackerSanitize (string $str): string { return str_replace(array('//', '/./'), array('/', '/'), $str); } -function crackerTrackerIsConsole () { +function crackerTrackerIsConsole (): bool { return (php_sapi_name() == 'cli'); } // Add anti-spam field in contact form -function ctrackerAntiSpamField () { +function ctrackerAntiSpamField (): string { // Get all fields $fields = ctrackerGetAntiSpamFields(); @@ -597,7 +597,7 @@ function ctrackerAntiSpamField () { return $fieldName; } -function ctrackerGetAntiSpamFields () { +function ctrackerGetAntiSpamFields (): array { return [ // URLs 'ctracker_blog', @@ -615,7 +615,7 @@ function ctrackerGetAntiSpamFields () { ]; } -function ifCtrackerTrackerAntiSpamFieldGiven () { +function ifCtrackerTrackerAntiSpamFieldGiven (): bool { // Is request method POST? if (crackerTrackerRequestMethod() != 'POST') { // Cannot be given diff --git a/libs/lib_updates.php b/libs/lib_updates.php index 2a84cd9..980a675 100644 --- a/libs/lib_updates.php +++ b/libs/lib_updates.php @@ -23,7 +23,7 @@ */ // Init all updates -function crackerTrackerInitUpdates () { +function crackerTrackerInitUpdates (): void { // Add all $GLOBALS['ctracker_updates'] = [ // Ticket system: @@ -139,7 +139,7 @@ FOREIGN KEY ( `ctracker_data_id` ) REFERENCES `' . $GLOBALS['ctracker_dbname'] . } // Runs the given updates at number X -function runCrackerTrackerUpdates (int $update) { +function runCrackerTrackerUpdates (int $update): void { // We assume it is set foreach ($GLOBALS['ctracker_updates'][$update] as $sql) { // Run the SQL command