Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into sfw-localize
Browse files Browse the repository at this point in the history
  • Loading branch information
Glomberg committed Sep 9, 2024
2 parents 6117d08 + 7a29b86 commit 79f7e9a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Modules/AntiCrawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,6 @@ private static function clearDataTable($db, $db__table__data)
return array('error' => 'COULD_NOT_CLEAR_UA_BL_TABLE'); // throw an error
}
}
$db->execute("ALTER TABLE {$db__table__data} AUTO_INCREMENT = 1;"); // Drop AUTO INCREMENT
$db->resetAutoIncrement($db__table__data);
}
}
41 changes: 6 additions & 35 deletions Modules/Sfw.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,7 @@ public function check()
}
$needles = array_unique($needles);

$query = "SELECT
network, mask, status, source
FROM " . $this->db__table__data . "
WHERE network IN (" . implode(',', $needles) . ")
AND network = " . $current_ip_v4 . " & mask
AND " . rand(1, 100000) . "
ORDER BY status DESC LIMIT 1";
$query = $this->db->sfwGetFromBlacklist($this->db__table__data, $needles, $current_ip_v4);

$db_results = $this->db->fetchAll($query);

Expand Down Expand Up @@ -218,33 +212,10 @@ public function check()
*/
public function updateLog($ip, $status, $network = 'NULL', $source = 'NULL')
{
$id = md5($ip . $this->module_name);
$time = time();
$query = $this->db->getUpdateLogQuery($this->db__table__logs, $this->module_name, $status, $ip, $source);

$this->db->prepareAndExecute(
"INSERT INTO " . $this->db__table__logs . "
SET
id = '$id',
ip = '$ip',
status = '$status',
all_entries = 1,
blocked_entries = " . (strpos($status, 'DENY') !== false ? 1 : 0) . ",
entries_timestamp = '" . $time . "',
ua_name = %s,
source = $source,
network = %s,
first_url = %s,
last_url = %s
ON DUPLICATE KEY
UPDATE
status = '$status',
source = $source,
all_entries = all_entries + 1,
blocked_entries = blocked_entries" . (strpos($status, 'DENY') !== false ? ' + 1' : '') . ",
entries_timestamp = '" . $time . "',
ua_name = %s,
network = %s,
last_url = %s",
$query,
array(
Server::get('HTTP_USER_AGENT'),
$network,
Expand Down Expand Up @@ -683,7 +654,7 @@ public static function updateWriteToDbExclusions($db, $db__table__data, $exclusi
/** @var \Cleantalk\Common\Helper\Helper $helper_class */
$helper_class = Mloader::get('Helper');

$query = 'INSERT INTO `' . $db__table__data . '` (network, mask, status) VALUES ';
$query = 'INSERT INTO ' . $db__table__data . ' (network, mask, status) VALUES ';

//Exclusion for servers IP (SERVER_ADDR)
if ( Server::get('HTTP_HOST') ) {
Expand Down Expand Up @@ -801,8 +772,8 @@ public static function renameDataTablesFromTempToMain($db, $table_names)
//return array('error' => 'RENAME TABLE: MAIN TABLE IS STILL EXISTS: ' . $table_name);
}

$alter_res = $db->execute('ALTER TABLE `' . $table_name__temp . '` RENAME `' . $table_name . '`;');
if ( ! $alter_res ) {
$rename_res = $db->renameTable($table_name__temp, $table_name);
if ( !$rename_res ) {
return array(
'error' => 'RENAME TABLE: FAILED TO RENAME: ' . $table_name
. ' DB Error: ' . $db->getLastError()
Expand Down

0 comments on commit 79f7e9a

Please sign in to comment.