}
// 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);
}