// Email recipient for all emails
$GLOBALS['ctracker_email'] = 'you@domain.invalid';
-
-// [EOF]
-?>
}
// Database error detected
-function crackerTrackerDatabaseError ($F, $L) {
+function crackerTrackerDatabaseError (string $file, int $line) {
// Should we debug?
if (isCrackerTrackerDebug()) {
// Output error
- print 'Function : ' . $F . '<br />';
- print 'Line : ' . $L . '<br />';
- if (isset($GLOBALS['ctracker_link'])) {
- print 'MySQL error : ' . mysqli_error($GLOBALS['ctracker_link']) . '<br />';
+ print 'Function : ' . $file . '<br />' . PHP_EOL;
+ print 'Line : ' . $line . '<br />' . PHP_EOL;
+ if (isset($GLOBALS['ctracker_link']) && $GLOBALS['ctracker_link'] !== false) {
+ print 'MySQL error : ' . mysqli_error($GLOBALS['ctracker_link']) . '<br />' . PHP_EOL;
} else {
- print 'No MySQLi available.<br />';
+ print 'No MySQLi available.<br />' . PHP_EOL;
+ }
+ if (isset($GLOBALS['ctracker_last_sql'])) {
+ print 'Last SQL : '. $GLOBALS['ctracker_last_sql'] . '<br />' . PHP_EOL;
+ } else {
+ print 'No last SQL command available.<br />' . PHP_EOL;
}
- print 'Last SQL : '. $GLOBALS['ctracker_last_sql'] . '<br />';
}
// Currently only die here
}
// Inserts given array, if IP/check_get combination was not found
-function crackerTrackerInsertArray ($table, array $rowData) {
+function crackerTrackerInsertArray (string $table, array $rowData) {
// Is it found?
if (!isCrackerTrackerEntryFound($rowData)) {
// Reset insert id
- $GLOBALS['ctracker_last_insert_id'] = FALSE;
+ $GLOBALS['ctracker_last_insert_id'] = false;
// Run it
runCrackerTrackerSql(sprintf("INSERT INTO `%s` (`%s`) VALUES(%s)",
}
// Updates a given entry by just counting it up
-function updateCrackerTrackerEntry (array $rowData, $countColumn = 'count') {
+function updateCrackerTrackerEntry (array $rowData, string $countColumn = 'count') {
// The link should be up here
if (!isCrackerTrackerDatabaseLinkUp()) {
// Throw exception
}
// Escapes the string
-function crackerTrackerEscapeString ($string) {
+function crackerTrackerEscapeString (string $string) {
// Is the link up?
if (!isCrackerTrackerDatabaseLinkUp()) {
// Then we cant use mysqli_real_escape_string!
}
// Runs an SQL query and checks for errors
-function runCrackerTrackerSql ($sqlString, $function, $line) {
+function runCrackerTrackerSql (string $sqlString, string $function, int $line) {
// Is the link up?
if (!isCrackerTrackerDatabaseLinkUp()) {
// Abort here
}
// Checks wether a table was found
-function isCrackerTrackerTableCreated ($table) {
+function isCrackerTrackerTableCreated (string $table) {
// Default is not found
- $found = FALSE;
+ $found = false;
// Run the query
$result = runCrackerTrackerSql('SHOW TABLES', __FUNCTION__, __LINE__);
// Is the table there?
if ($tab == $table) {
// Okay, found. So abort
- $found = TRUE;
+ $found = true;
break;
}
}
}
// Creates the given table with columns
-function crackerTrackerCreateTable ($table, array $columns, array $keys) {
+function crackerTrackerCreateTable (string $table, array $columns, array $keys) {
// Begin the SQL
$sqlString = 'CREATE TABLE IF NOT EXISTS `' . $table . '` (';
$sqlString .= 'PRIMARY KEY (`' . $table . '`), ';
// Add keys
- foreach ($keys as $key=>$type) {
+ foreach ($keys as $key => $type) {
// Add this entry
$sqlString .= '' . $type . ' (`' . $key . '`), ';
}
}
// Inits a table by inserting
-function crackerTrackerInitTable ($table) {
+function crackerTrackerInitTable (string $table) {
// Prepare SQL and run it
runCrackerTrackerSql('INSERT INTO `' . $table . '` (`' . $table . '`) VALUES (NULL)');
}
}
// Getter for config
-function getCrackerTrackerConfig ($entry) {
+function getCrackerTrackerConfig (string $entry) {
// Is the config entry there?
if (!isset($GLOBALS['ctracker_config'][$entry])) {
// Then better die here, else we may have an endless loop
// Skip this silently if we have not config
if (!isCrackerTrackerDatabaseLinkUp()) {
// Skip this step silently, all is not suspicious
- return FALSE;
+ return false;
}
// Check if an entry is there
$found = ($rows > 0);
// And again?
- if ($found === TRUE) {
+ if ($found === true) {
// Yes, one is found, then load it
$result = runCrackerTrackerSql("SELECT SQL_SMALL_RESULT * FROM `ctracker_data` USE INDEX (`remote_proxy_last`) WHERE `remote_addr`='" . determineCrackerTrackerRealRemoteAddress() . "' OR `proxy_addr`='" . getenv('REMOTE_ADDR') . "' ORDER BY `last_attempt` DESC LIMIT 1", __FUNCTION__, __LINE__);
$found = (mysqli_num_rows($result) == 1);
// And again?
- if ($found === TRUE) {
+ if ($found === true) {
// Cache the ticket data
$GLOBALS['ctracker_last_ticket'] = mysqli_fetch_array($result);
}
// Also block these requests (mostly you don't want CONNECT to some SMTP sites)
$GLOBALS['ctracker_blocked_methods'] = [
- 'CONNECT' => TRUE,
+ 'CONNECT' => true,
];
// Init more elements
// Checks for worms
function isCrackerTrackerWormDetected () {
// 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)));
+ $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)));
/*
* If it differs to original and the *whole* request string is not in
*/
$isWorm = (
(
- $GLOBALS['ctracker_checked_get'] != crackerTrackerQueryString(TRUE) && (!in_array(crackerTrackerQueryString(TRUE), $GLOBALS['ctracker_whitelist']))
+ $GLOBALS['ctracker_checked_get'] != crackerTrackerQueryString(true) && (!in_array(crackerTrackerQueryString(true), $GLOBALS['ctracker_whitelist']))
) || (
- $GLOBALS['ctracker_checked_ua'] != crackerTrackerUserAgent(TRUE)
+ $GLOBALS['ctracker_checked_ua'] != crackerTrackerUserAgent(true)
) || (
isset($GLOBALS['ctracker_blocked_methods'][crackerTrackerRequestMethod()])
)
}
// Sends a mail out
-function crackerTrackerSendMail ($mail, $recipient = NULL, $subject = NULL) {
+function crackerTrackerSendMail (string $mail, string $recipient = NULL, string $subject = NULL) {
// Construct dummy array
$rowData = [
'remote_addr' => determineCrackerTrackerRealRemoteAddress(),
print 'Recipient=' . $recipient . '<br />Subject=' . $subject . '<br />Text=<pre>' . $mail . '</pre>';
// All fine
- return TRUE;
+ return true;
} elseif (!is_null($recipient)) {
// Recipient specified
return mail($recipient, $subject, $mail, $GLOBALS['ctracker_header']);
print 'Recipient=' . $recipient . '<br />Subject=' . $subject . '<br />Text=<pre>' . $mail . '</pre>';
// All fine
- return TRUE;
+ return true;
}
}
// Sleeps for a random time and aborts the script
function crackerTrackerDie () {
- // Close database link
- crackerTrackerCloseDatabaseLink();
+ // Check if link is up
+ if (isCrackerTrackerDatabaseLinkUp()) {
+ // Close database link
+ crackerTrackerCloseDatabaseLink();
+ }
// Do only sleep if debug/developer mode is not enabled
if (!isCrackerTrackerDebug()) {
*/
// Implode recursive a multi-dimension array, taken from www.php.net
-function implode_r ($glue, $array, $array_name = NULL) {
+function implode_r (string $glue, array $array, string $array_name = NULL) {
$return = [];
while (list($key,$value) = @each($array)) {
if (is_array($value)) {
// Getter for ctracker_debug_enabled
function isCrackerTrackerDebug () {
// Is it set?
- $result = ((isset($GLOBALS['ctracker_debug_enabled'])) && ($GLOBALS['ctracker_debug_enabled'] === TRUE));
+ $result = ((isset($GLOBALS['ctracker_debug_enabled'])) && ($GLOBALS['ctracker_debug_enabled'] === true));
// Debug message
//* DEBUG: */ error_log('result=' . intval($result));
}
// Detects the user-agent string
-function crackerTrackerUserAgent ($sanitize = FALSE) {
+function crackerTrackerUserAgent (bool $sanitize = false) {
// Default is 'unknown'
$ua = 'unknown';
}
// Sanitize it?
- if ($sanitize === TRUE) {
+ if ($sanitize === true) {
// Sanitize ...
$ua = crackerTrackerSanitize($ua);
}
}
// Detects the script name
-function crackerTrackerScriptName ($sanitize = FALSE) {
+function crackerTrackerScriptName (bool $sanitize = false) {
// Default is NULL
$scriptName = NULL;
}
// Sanitize it?
- if ($sanitize === TRUE) {
+ if ($sanitize === true) {
// Sanitize ...
$scriptName = crackerTrackerSanitize($scriptName);
}
}
// Detects the query string
-function crackerTrackerQueryString ($sanitize = FALSE) {
+function crackerTrackerQueryString (bool $sanitize = false) {
// Default is NULL
$query = NULL;
}
// Sanitize it?
- if ((!empty($query)) && ($sanitize === TRUE)) {
+ if ((!empty($query)) && ($sanitize === true)) {
// Sanitize ...
$query = crackerTrackerSanitize($query);
}
}
// Detects the server's name
-function crackerTrackerServerName ($sanitize = FALSE) {
+function crackerTrackerServerName (bool $sanitize = false) {
// Default is NULL
$serverName = NULL;
}
// Sanitize it?
- if ($sanitize === TRUE) {
+ if ($sanitize === true) {
// Sanitize ...
$serverName = crackerTrackerSanitize($serverName);
}
}
// Detects the referer
-function crackerTrackerReferer ($sanitize = FALSE) {
+function crackerTrackerReferer (bool $sanitize = false) {
// Default is a dash
$referer = '-';
}
// Sanitize it?
- if ($sanitize === TRUE) {
+ if ($sanitize === true) {
// Sanitize ...
$referer = crackerTrackerSanitize($referer);
}
function sendCrackerTrackerCookie () {
// Set the cookie
// @TODO Why can't domain be set to value from crackerTrackerServerName() ?
- setcookie('ctracker_ticket', getCrackerTrackerTicketId(), (time() + 60*60*24), '/', '', crackerTrackerSecured(), TRUE);
+ setcookie('ctracker_ticket', getCrackerTrackerTicketId(), (time() + 60*60*24), '/', '', crackerTrackerSecured(), true);
$_COOKIE['ctracker_ticket'] = getCrackerTrackerTicketId();
}
// check if running on IIS < 6 with CGI-PHP
if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) &&
- (strpos($_SERVER['GATEWAY_INTERFACE'],'CGI') !== FALSE) &&
+ (strpos($_SERVER['GATEWAY_INTERFACE'],'CGI') !== false) &&
(preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) &&
($matches[1] < 6)) {
// Send the IIS header
// Is request method POST?
if (crackerTrackerRequestMethod() != 'POST') {
// Cannot be given
- return FALSE;
+ return false;
}
// Walk through all fields
// Is one found?
if (in_array($fieldName, $_POST) && !empty($_POST[$fieldName])) {
// Filled out!
- return TRUE;
+ return true;
}
}
}