From 11f1b2bf75d5a2fec62ee684bb252977bc627604 Mon Sep 17 00:00:00 2001 From: davydovct Date: Fri, 22 Dec 2017 13:15:31 +0500 Subject: [PATCH 1/3] Update version Support Cloudflare CDN --- CHANGELOG | 4 ++++ README.md | 2 +- RoboFile.php | 2 +- cleantalkMod.php | 2 +- lib/CleantalkSFW.php | 49 ++++++++++++++++++++++++++++++++++---------- modification.xml | 2 +- package-info.xml | 42 ++++++++++++++++++++++++++++++------- readme.txt | 2 +- readme_russian.txt | 2 +- 9 files changed, 83 insertions(+), 24 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index c0fd309..42f48af 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +Version 2.19 December 24, 2017 +------------------------------ +- Support Cloudflare CDN + Version 2.18 October 30, 2017 ------------------------------ - Bug fixes and other minor improvements diff --git a/README.md b/README.md index a1d9f7b..279890d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # SMF Antispam mod -* **Version:** 2.18 +* **Version:** 2.19 * **License:** GNU General Public License * **Compatible with:** SMF 2.0 and up * **Languages:** English, Russian diff --git a/RoboFile.php b/RoboFile.php index d8f0efe..9c2ea2c 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -8,7 +8,7 @@ class RoboFile extends \Robo\Tasks { const PACKAGE = 'antispam_cleantalk_smf'; - const VERSION = '2.18'; + const VERSION = '2.19'; const SMF_VERSION = '2.0.14'; // for forumPrepare diff --git a/cleantalkMod.php b/cleantalkMod.php index 8e05887..6ff2eb8 100644 --- a/cleantalkMod.php +++ b/cleantalkMod.php @@ -24,7 +24,7 @@ require_once(dirname(__FILE__) . '/CleantalkSFW.php'); // Common CleanTalk options -define('CT_AGENT_VERSION', 'smf-218'); +define('CT_AGENT_VERSION', 'smf-219'); define('CT_SERVER_URL', 'http://moderate.cleantalk.org'); define('CT_DEBUG', false); diff --git a/lib/CleantalkSFW.php b/lib/CleantalkSFW.php index 922252b..c9ba71b 100644 --- a/lib/CleantalkSFW.php +++ b/lib/CleantalkSFW.php @@ -26,7 +26,22 @@ class CleantalkSFW private $query; private $db_result; private $db_result_data = array(); - + private $cdn_cf = array( + '103.21.244.0/22', + '103.22.200.0/22', + '103.31.4.0/22', + '104.16.0.0/12', + '108.162.192.0/18', + '131.0.72.0/22', + '141.101.64.0/18', + '162.158.0.0/15', + '172.64.0.0/13', + '173.245.48.0/20', + '188.114.96.0/20', + '190.93.240.0/20', + '197.234.240.0/22', + '198.41.128.0/17', + ); public function __construct() { global $db_connection, $db_prefix; @@ -68,24 +83,29 @@ public function unversal_fetch_all() public function get_ip(){ $result=Array(); - + $cdn = $this->cdn_cf; + // Getting IP $the_ip = filter_var( $_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ); - $result[] = $the_ip; + $result['remote_addr'] = $the_ip; $this->ip_str_array[]=$the_ip; $this->ip_array[]=sprintf("%u", ip2long($the_ip)); - // Getting proxy IP + // Getting Cloudflare IP $headers = function_exists('apache_request_headers') ? apache_request_headers() : self::apache_request_headers(); - if( isset($headers['X-Forwarded-For']) ){ - $the_ip = explode(",", trim($headers['X-Forwarded-For'])); - $the_ip = trim($the_ip[0]); - $result[] = filter_var( $the_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ); - $this->ip_str_array[]=$the_ip; - $this->ip_array[]=sprintf("%u", ip2long($the_ip)); + if(isset($headers['Cf_Connecting_Ip'])){ + foreach ($cdn as $cidr) + { + if ($this->ip_mask_match($result['remote_addr'],$cidr)){ + $result['cf_connecting_ip'] = filter_var( $_SERVER['Cf_Connecting_Ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ); + $this->ip_array[] = sprintf("%u", ip2long($result['cf_connecting_ip'])); + unset($result['remote_addr']); + break; + } + } } // Getting test IP @@ -98,7 +118,14 @@ public function get_ip(){ return array_unique($result); } - + + public function ip_mask_match($ip, $cidr){ + $exploded = explode ('/', $cidr); + $net = $exploded[0]; + $mask = 4294967295 << (32 - $exploded[1]); + return (ip2long($ip) & $mask) == (ip2long($net) & $mask); + } + /* * Checks IP via Database */ diff --git a/modification.xml b/modification.xml index 995364d..d45e3c0 100644 --- a/modification.xml +++ b/modification.xml @@ -2,7 +2,7 @@ cleantalk:antispam - 2.18 + 2.19 diff --git a/package-info.xml b/package-info.xml index 279e892..1273d43 100644 --- a/package-info.xml +++ b/package-info.xml @@ -4,7 +4,7 @@ cleantalk:antispam Anti-spam by CleanTalk modification - 2.18 + 2.19 readme.txt readme_russian.txt @@ -43,7 +43,7 @@ - This upgrade for Antispam by Cleantalk to 2.18 version: + This upgrade for Antispam by Cleantalk to 2.19 version: - Fix SFW update on save settings - Change SFW template - Remove plugin settings on uninstall @@ -52,6 +52,7 @@ - IPv6 support - Update sfw_networks on plugin install - First post checking now checking all messages from users with newbie group + - Support Cloudflare CDN - Bug fixes and other minor improvements Обновление Анти-спама от Cleantalk до версии 2.18: @@ -63,6 +64,7 @@ - Поддержка IPV6 - Обновление баз SpamFireWall при установке плагина - Опция "Проверки первого сообщения" изменена на проверку всех сообщений от новых пользователей + - Поддержка Cloudflare CDN - Устранение багов и остальные незначительные улучшения @@ -86,18 +88,20 @@ - This upgrade for Antispam by Cleantalk from 2.16 to 2.18 version: + This upgrade for Antispam by Cleantalk from 2.16 to 2.19 version: - Fix create_table for sql_lite - IPv6 support - Update sfw_networks on plugin install - - First post checking now checking all messages from users with newbie group + - First post checking now checking all messages from users with newbie group + - Support Cloudflare CDN - Bug fixes and other minor improvements - Обновление Анти-спама от Cleantalk с версии 2.16 до 2.18: + Обновление Анти-спама от Cleantalk с версии 2.16 до 2.19: - Исправлен скрипт создания таблиц для sql_lite - Поддержка IPV6 - Обновление баз SpamFireWall при установке плагина - Опция "Проверки первого сообщения" изменена на проверку всех сообщений от новых пользователей + - Поддержка Cloudflare CDN - Устранение багов и остальные незначительные улучшения @@ -114,10 +118,12 @@ - This upgrade for Antispam by Cleantalk from 2.17 to 2.18 version: + This upgrade for Antispam by Cleantalk from 2.17 to 2.19 version: + - Support Cloudflare CDN - Bug fixes and other minor improvements - Обновление Анти-спама от Cleantalk с версии 2.17 до 2.18: + Обновление Анти-спама от Cleantalk с версии 2.17 до 2.19: + - Поддержка Cloudflare CDN - Устранение багов и остальные незначительные улучшения @@ -132,4 +138,26 @@ you are being redirected to this mod configuration settings. + + This upgrade for Antispam by Cleantalk from 2.18 to 2.19 version: + - Support Cloudflare CDN + - Bug fixes and other minor improvements + + Обновление Анти-спама от Cleantalk с версии 2.18 до 2.19: + - Поддержка Cloudflare CDN + - Устранение багов и остальные незначительные улучшения + + + Mod main file + SFW class + modification.xml + languages/english.xml + languages/english-utf8.xml + languages/russian.xml + languages/russian-utf8.xml + install.php + Please stand by while + you are being redirected to this mod configuration settings. + + diff --git a/readme.txt b/readme.txt index 67cbc45..783cc45 100644 --- a/readme.txt +++ b/readme.txt @@ -1,5 +1,5 @@ MOD [b]Anti-spam by CleanTalk[/b] -Version: 2.18 +Version: 2.19 Anti-spam by CleanTalk mod with protection against spam bots and manual spam. No Captcha, no questions, no counting animals, no puzzles, no math. diff --git a/readme_russian.txt b/readme_russian.txt index 7d37009..203a6c1 100644 --- a/readme_russian.txt +++ b/readme_russian.txt @@ -1,5 +1,5 @@ MOD [b]Анти-спам от Cleantalk[/b] -Версия: 2.18 +Версия: 2.19 Анти-спам от Cleantalk с защитой против автоматического и ручного спама. Без капчи, без вопросов, без подсчета животных, без паззлов и т.д From 4ce02403e51ed5127e0976cdcea23b030296135e Mon Sep 17 00:00:00 2001 From: davydovct Date: Fri, 22 Dec 2017 14:23:23 +0500 Subject: [PATCH 2/3] get_ip fix --- lib/CleantalkSFW.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/CleantalkSFW.php b/lib/CleantalkSFW.php index c9ba71b..9e58366 100644 --- a/lib/CleantalkSFW.php +++ b/lib/CleantalkSFW.php @@ -111,7 +111,7 @@ public function get_ip(){ // Getting test IP $sfw_test_ip = isset($_GET['sfw_test_ip']) ? $_GET['sfw_test_ip'] : null; if($sfw_test_ip){ - $result[] = filter_var( $sfw_test_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ); + $result['remote_addr'] = filter_var( $sfw_test_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ); $this->ip_str_array[]=$sfw_test_ip; $this->ip_array[]=sprintf("%u", ip2long($sfw_test_ip)); } From 6996bb387bf9c740a66d9f7472f757ee60fc5a26 Mon Sep 17 00:00:00 2001 From: davydovct Date: Thu, 11 Jan 2018 09:48:37 +0500 Subject: [PATCH 3/3] Correct package-info --- package-info.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package-info.xml b/package-info.xml index 1273d43..62fd46e 100644 --- a/package-info.xml +++ b/package-info.xml @@ -55,7 +55,7 @@ - Support Cloudflare CDN - Bug fixes and other minor improvements - Обновление Анти-спама от Cleantalk до версии 2.18: + Обновление Анти-спама от Cleantalk до версии 2.19: - Исправлено обновление базы SpamFireWall при сохранении настроек - Изменен шаблон для SpamFireWall - Удаление настроек из БД при удалении плагина