Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,27 @@ public function getLastError()
return 'Not implemented';
}

public function sfwGetFromBlacklist($table_name, $needles, $current_ip_v4)
public function sfwGetFromBlacklist($table_name, $personal_table_name, $needles, $current_ip_v4)
{
return "SELECT
network, mask, status, source
FROM " . $table_name . "
$query = "(SELECT
network, mask, status, source, 0 as is_personal
FROM " . $table_name . "
WHERE network IN (" . implode(',', $needles) . ")
AND network = " . $current_ip_v4 . " & mask
AND " . rand(1, 100000) . "
ORDER BY status DESC LIMIT 1)";

// Add personal table UNION if available
if ( $personal_table_name && $this->isTableExists($personal_table_name) ) {
$query .= " UNION (SELECT
network, mask, status, NULL as source, 1 as is_personal
FROM " . $personal_table_name . "
WHERE network IN (" . implode(',', $needles) . ")
AND network = " . $current_ip_v4 . " & mask
AND " . rand(1, 100000) . "
ORDER BY status DESC LIMIT 1";
AND network = " . $current_ip_v4 . " & mask
AND " . rand(1, 100000) . "
ORDER BY status DESC LIMIT 1)";
};
return $query;
}

public function acGetFromBlacklist($table, $ip, $sign)
Expand Down
8 changes: 8 additions & 0 deletions Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ class Schema
'__indexes' => 'PRIMARY KEY (`id`), INDEX ( `network` , `mask` )',
'__createkey' => 'INT unsigned primary KEY AUTO_INCREMENT FIRST'
),
'sfw_personal' => array(
'id' => 'INT NOT NULL AUTO_INCREMENT',
'network' => 'INT unsigned NOT NULL',
'mask' => 'INT unsigned NOT NULL',
'status' => 'TINYINT NOT NULL DEFAULT 0',
'__indexes' => 'PRIMARY KEY (`id`), INDEX ( `network` , `mask` )',
'__createkey' => 'INT unsigned primary KEY AUTO_INCREMENT FIRST'
),
'ua_bl' => array(
'id' => 'INT NOT NULL',
'ua_template' => 'VARCHAR(255) NULL DEFAULT NULL',
Expand Down