From e214f91fd015616562c72e81184e41dd9eb40b82 Mon Sep 17 00:00:00 2001 From: AntonV1211 Date: Fri, 26 Jun 2026 14:25:15 +0700 Subject: [PATCH] New. SFW. Edits for adding personal SFW lists --- Db.php | 26 +++++++++++++++++++------- Schema.php | 8 ++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Db.php b/Db.php index 3e47724..518ea51 100644 --- a/Db.php +++ b/Db.php @@ -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) diff --git a/Schema.php b/Schema.php index 7991e45..2c3dd5d 100644 --- a/Schema.php +++ b/Schema.php @@ -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',