Skip to content

Commit

Permalink
release 2.24
Browse files Browse the repository at this point in the history
  • Loading branch information
davydovct committed Oct 1, 2018
1 parent de2d855 commit 3ca5ed8
Show file tree
Hide file tree
Showing 19 changed files with 737 additions and 383 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: php
php:
- 5.6
- 7.0
script: phpunit --configuration tests/phpunit.xml --coverage-text
7 changes: 7 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Version 2.24 Oct 10, 2018
------------------------------
- CDN support
- Lib class updated
- Move mod settings to a separate tab
- Bug fixes and other minor improvements

Version 2.23 June 9, 2018
------------------------------
- Bug fixes and other minor improvements
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# SMF Antispam mod
* **Version:** 2.23
================
[![Build Status](https://travis-ci.org/CleanTalk/smf-antispam.svg)](https://travis-ci.org/CleanTalk/smf-antispam)

* **Version:** 2.24
* **License:** GNU General Public License
* **Compatible with:** SMF 2.0 and up
* **Languages:** English, Russian
Expand Down
2 changes: 1 addition & 1 deletion RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class RoboFile extends \Robo\Tasks
{
const PACKAGE = 'antispam_cleantalk_smf';
const VERSION = '2.23';
const VERSION = '2.24';

const SMF_VERSION = '2.0.14'; // for forumPrepare

Expand Down
127 changes: 54 additions & 73 deletions cleantalkMod.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
require_once(dirname(__FILE__) . '/CleantalkSFW.php');

// Common CleanTalk options
define('CT_AGENT_VERSION', 'smf-223');
define('CT_AGENT_VERSION', 'smf-224');
define('CT_SERVER_URL', 'http://moderate.cleantalk.org');
define('CT_DEBUG', false);

Expand All @@ -37,7 +37,7 @@ function cleantalk_sfw_check()
global $modSettings, $language;
if (!empty($modSettings['cleantalk_api_key_is_ok']))
{
CookieTest();
cleantalk_cookies_set();
if(!empty($modSettings['cleantalk_sfw']) ){

$sfw = new CleantalkSFW();
Expand Down Expand Up @@ -102,7 +102,9 @@ function cleantalk_sfw_check()
$ct_request->agent = CT_AGENT_VERSION;
$ct_request->sender_email = $sender_email;

$ct_request->sender_ip = $ct->cleantalk_get_real_ip();
$ct_request->sender_ip = CleantalkHelper::ip_get(array('real'), false);
$ct_request->x_forwarded_for = CleantalkHelper::ip_get(array('x_forwarded_for'), false);
$ct_request->x_real_ip = CleantalkHelper::ip_get(array('x_real_ip'), false);

$ct_request->sender_nickname = $sender_nickname;
$ct_request->message = $message;
Expand All @@ -120,9 +122,9 @@ function cleantalk_sfw_check()
'js_timezone' => isset($_COOKIE['ct_timezone']) ? $_COOKIE['ct_timezone'] : null,
'mouse_cursor_positions' => isset($_COOKIE['ct_pointer_data']) ? $_COOKIE['ct_pointer_data'] : null,
'key_press_timestamp' => !empty($_COOKIE['ct_fkp_timestamp']) ? $_COOKIE['ct_fkp_timestamp'] : null,
'page_set_timestamp' => !empty($_COOKIE['apbct_timestamp']) ? $_COOKIE['apbct_timestamp'] : null,
'REFFERRER_PREVIOUS' => isset($_COOKIE['apbct_prev_referer'])? $_COOKIE['apbct_prev_referer']: null,
'cookies_enabled' => apbct_cookies_test(),
'page_set_timestamp' => !empty($_COOKIE['ct_ps_timestamp']) ? $_COOKIE['ct_ps_timestamp'] : null,
'REFFERRER_PREVIOUS' => isset($_COOKIE['ct_prev_referer'])? $_COOKIE['ct_prev_referer']: null,
'cookies_enabled' => cleantalk_cookies_test(),
)
);
$ct_result = $ct->isAllowMessage($ct_request);
Expand Down Expand Up @@ -352,54 +354,48 @@ function obfuscate_param($value = null) {
* Cookie test
* @return
*/
function CookieTest() {
function cleantalk_cookies_set() {
// Cookie names to validate
$cookie_test_value = array(
'cookies_names' => array(),
'check_value' => cleantalk_get_api_key(),
);

// Submit time
$apbct_timestamp = time();
setcookie('apbct_timestamp', $apbct_timestamp, 0, '/');
$cookie_test_value['cookies_names'][] = 'apbct_timestamp';
$cookie_test_value['check_value'] .= $apbct_timestamp;

// Pervious referer
if(!empty($_SERVER['HTTP_REFERER'])){
setcookie('apbct_prev_referer', $_SERVER['HTTP_REFERER'], 0, '/');
$cookie_test_value['cookies_names'][] = 'apbct_prev_referer';
setcookie('ct_prev_referer', $_SERVER['HTTP_REFERER'], 0, '/');
$cookie_test_value['cookies_names'][] = 'ct_prev_referer';
$cookie_test_value['check_value'] .= $_SERVER['HTTP_REFERER'];
}
// Cookies test
$cookie_test_value['check_value'] = md5($cookie_test_value['check_value']);
setcookie('apbct_cookies_test', json_encode($cookie_test_value), 0, '/');
setcookie('ct_cookies_test', json_encode($cookie_test_value), 0, '/');
}
/**
* Cookies test for sender
* Also checks for valid timestamp in $_COOKIE['apbct_timestamp'] and other apbct_ COOKIES
* @return null|0|1;
*/
function apbct_cookies_test()
{
if(isset($_COOKIE['apbct_cookies_test'])){

$cookie_test = json_decode(stripslashes($_COOKIE['apbct_cookies_test']), true);

$check_srting = cleantalk_get_api_key();
foreach($cookie_test['cookies_names'] as $cookie_name){
$check_srting .= isset($_COOKIE[$cookie_name]) ? $_COOKIE[$cookie_name] : '';
} unset($cokie_name);

if($cookie_test['check_value'] == md5($check_srting)){
return 1;
}else{
return 0;
}
/**
* Cookies test for sender
* Also checks for valid timestamp in $_COOKIE['ct_timestamp'] and other ct_ COOKIES
* @return null|0|1;
*/
function cleantalk_cookies_test()
{
if(isset($_COOKIE['ct_cookies_test'])){

$cookie_test = json_decode(stripslashes($_COOKIE['ct_cookies_test']), true);

$check_srting = cleantalk_get_api_key();
foreach($cookie_test['cookies_names'] as $cookie_name){
$check_srting .= isset($_COOKIE[$cookie_name]) ? $_COOKIE[$cookie_name] : '';
} unset($cokie_name);

if($cookie_test['check_value'] == md5($check_srting)){
return 1;
}else{
return null;
return 0;
}
}else{
return null;
}
}
/**
* CleanTalk integrate register hook
* @param array $regOptions
Expand Down Expand Up @@ -427,7 +423,9 @@ function cleantalk_check_register(&$regOptions, $theme_vars){
$ct_request->agent = CT_AGENT_VERSION;
$ct_request->sender_email = isset($regOptions['email']) ? $regOptions['email'] : '';

$ct_request->sender_ip = $ct->cleantalk_get_real_ip();
$ct_request->sender_ip = CleantalkHelper::ip_get(array('real'), false);
$ct_request->x_forwarded_for = CleantalkHelper::ip_get(array('x_forwarded_for'), false);
$ct_request->x_real_ip = CleantalkHelper::ip_get(array('x_real_ip'), false);

$ct_request->sender_nickname = isset($regOptions['username']) ? $regOptions['username'] : '';

Expand All @@ -443,9 +441,9 @@ function cleantalk_check_register(&$regOptions, $theme_vars){
'js_timezone' => !empty($_COOKIE['ct_timezone']) ? $_COOKIE['ct_timezone'] : null,
'mouse_cursor_positions' => !empty($_COOKIE['ct_pointer_data']) ? $_COOKIE['ct_pointer_data'] : null,
'key_press_timestamp' => !empty($_COOKIE['ct_fkp_timestamp']) ? $_COOKIE['ct_fkp_timestamp'] : null,
'page_set_timestamp' => !empty($_COOKIE['apbct_timestamp']) ? $_COOKIE['apbct_timestamp'] : null,
'REFFERRER_PREVIOUS' => isset($_COOKIE['apbct_prev_referer'])? $_COOKIE['apbct_prev_referer']: null,
'cookies_enabled' => apbct_cookies_test(),
'page_set_timestamp' => !empty($_COOKIE['ct_ps_timestamp']) ? $_COOKIE['ct_ps_timestamp'] : null,
'REFFERRER_PREVIOUS' => isset($_COOKIE['ct_prev_referer'])? $_COOKIE['ct_prev_referer']: null,
'cookies_enabled' => cleantalk_cookies_test(),
)
);

Expand Down Expand Up @@ -528,7 +526,9 @@ function cleantalk_check_message(&$msgOptions, $topicOptions, $posterOptions){
$ct_request->agent = CT_AGENT_VERSION;
$ct_request->sender_email = isset($posterOptions['email']) ? $posterOptions['email'] : '';

$ct_request->sender_ip = $ct->cleantalk_get_real_ip();
$ct_request->sender_ip = CleantalkHelper::ip_get(array('real'), false);
$ct_request->x_forwarded_for = CleantalkHelper::ip_get(array('x_forwarded_for'), false);
$ct_request->x_real_ip = CleantalkHelper::ip_get(array('x_real_ip'), false);

$ct_request->sender_nickname = isset($posterOptions['name']) ? $posterOptions['name'] : '';
$ct_request->message = isset($msgOptions['subject']) ? preg_replace('/\s+/', ' ',str_replace("<br />", " ", $msgOptions['subject']))."\n".preg_replace('/\s+/', ' ',str_replace("<br />", " ", $msgOptions['body'])) : preg_replace('/\s+/', ' ',str_replace("<br />", " ", $msgOptions['body']));
Expand All @@ -546,9 +546,9 @@ function cleantalk_check_message(&$msgOptions, $topicOptions, $posterOptions){
'js_timezone' => isset($_COOKIE['ct_timezone']) ? $_COOKIE['ct_timezone'] : null,
'mouse_cursor_positions' => isset($_COOKIE['ct_pointer_data']) ? $_COOKIE['ct_pointer_data'] : null,
'key_press_timestamp' => !empty($_COOKIE['ct_fkp_timestamp']) ? $_COOKIE['ct_fkp_timestamp'] : null,
'page_set_timestamp' => !empty($_COOKIE['apbct_timestamp']) ? $_COOKIE['apbct_timestamp'] : null,
'REFFERRER_PREVIOUS' => isset($_COOKIE['apbct_prev_referer'])? $_COOKIE['apbct_prev_referer']: null,
'cookies_enabled' => apbct_cookies_test(),
'page_set_timestamp' => !empty($_COOKIE['ct_ps_timestamp']) ? $_COOKIE['ct_ps_timestamp'] : null,
'REFFERRER_PREVIOUS' => isset($_COOKIE['ct_prev_referer'])? $_COOKIE['ct_prev_referer']: null,
'cookies_enabled' => cleantalk_cookies_test(),
)
);

Expand Down Expand Up @@ -718,26 +718,6 @@ function cleantalk_get_api_key(){
return isset($modSettings['cleantalk_api_key']) ? $modSettings['cleantalk_api_key'] : null;
}

/**
* Add CleanTalk setting into admin panel
* @param array $config_vars
*/
function cleantalk_general_mod_settings(&$config_vars){

global $txt, $boardurl;

$config_vars[] = array('title', 'cleantalk_settings');
$config_vars[] = array('text', 'cleantalk_api_key');
$config_vars[] = array('check', 'cleantalk_first_post_checking', 'subtext' => $txt['cleantalk_first_post_checking_postinput']);
$config_vars[] = array('check', 'cleantalk_logging', 'subtext' => sprintf($txt['cleantalk_logging_postinput'], $boardurl));
$config_vars[] = array('check', 'cleantalk_email_notifications', 'subtext' => $txt['cleantalk_email_notifications']);
$config_vars[] = array('check', 'cleantalk_ccf_checking', 'subtext' => $txt['cleantalk_ccf_checking']);
$config_vars[] = array('check', 'cleantalk_tell_others', 'subtext' => $txt['cleantalk_tell_others_postinput']);
$config_vars[] = array('check', 'cleantalk_sfw', 'subtext' => $txt['cleantalk_sfw_postinput']);
$config_vars[] = array('desc', 'cleantalk_api_key_description');
$config_vars[] = array('desc', 'cleantalk_check_users');
}

/**
* Return CleanTalk javascript verify code
*/
Expand All @@ -756,6 +736,7 @@ function cleantalk_print_js_input()
function ctSetCookie(c_name, value) {
document.cookie = c_name + "=" + encodeURIComponent(value) + "; path=/";
}
ctSetCookie("ct_ps_timestamp", Math.floor(new Date().getTime()/1000));
ctSetCookie("ct_fkp_timestamp", "0");
ctSetCookie("ct_pointer_data", "0");
ctSetCookie("ct_timezone", "0");
Expand Down Expand Up @@ -861,8 +842,8 @@ function cleantalk_store_form_start_time()
*/
function cleantalk_get_form_submit_time()
{
$cookie_submit_time = isset($_COOKIE['apbct_timestamp']) ? time() - intval($_COOKIE['apbct_timestamp']): 0;
if ($cookie_submit_time > 2)
$cookie_submit_time = isset($_COOKIE['ct_ps_timestamp']) ? time() - intval($_COOKIE['ct_ps_timestamp']): 0;
if ($cookie_submit_time > 3)
return $cookie_submit_time;
else
return isset($_SESSION['ct_form_start_time']) ? time() - intval($_SESSION['ct_form_start_time']) : 0;
Expand Down Expand Up @@ -910,7 +891,7 @@ function cleantalk_load()
// Getting key automatically
if(!empty($_GET['ctgetautokey'])){

$result = CleantalkHelper::getApiKey($user_info['email'], $_SERVER['SERVER_NAME'], 'smf');
$result = CleantalkHelper::api_method__get_api_key($user_info['email'], $_SERVER['SERVER_NAME'], 'smf');

if (empty($result['error'])){

Expand Down Expand Up @@ -946,7 +927,7 @@ function cleantalk_load()
if($_POST['cleantalk_api_key'] != $curr_key){

$key_to_validate = strval($_POST['cleantalk_api_key']);
$result = CleantalkHelper::noticeValidateKey($key_to_validate);
$result = CleantalkHelper::api_method__notice_validate_key($key_to_validate);

if(empty($result['error'])){

Expand Down Expand Up @@ -1063,7 +1044,7 @@ function cleantalk_load()
/* Cron for account status */
if(!empty($modSettings['cleantalk_api_key_is_ok']) && isset($modSettings['cleantalk_last_account_check']) && $modSettings['cleantalk_last_account_check'] < time() || !empty($doing_cron)){

$result = CleantalkHelper::noticePaidTill($modSettings['cleantalk_api_key']);
$result = CleantalkHelper::api_method__notice_paid_till($modSettings['cleantalk_api_key']);

if(empty($result['error'])){
$settings_array = array(
Expand Down Expand Up @@ -1259,7 +1240,7 @@ function cleantalk_buffer($buffer)
}

// Request
$api_result = CleantalkHelper::spamCheckCms(cleantalk_get_api_key(), $data);
$api_result = CleantalkHelper::api_method__spam_check_cms(cleantalk_get_api_key(), $data);

// Error handling
if(!empty($api_result['error'])){
Expand Down Expand Up @@ -1408,7 +1389,7 @@ function cleantalk_buffer($buffer)

if(!isset($modSettings['cleantalk_api_key_is_ok'])){

$result = CleantalkHelper::noticeValidateKey($modSettings['cleantalk_api_key']);
$result = CleantalkHelper::api_method__notice_validate_key($modSettings['cleantalk_api_key']);

if(empty($result['error'])){

Expand Down
72 changes: 72 additions & 0 deletions cleantalkModAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* CleanTalk SMF mod
*
* @package Cleantalk
* @subpackage SMF
* @author CleanTalk ([email protected])
* @copyright (C) 2014 Сleantalk team (http://cleantalk.org)
* @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
*/

if (!defined('SMF')) {
die('Hacking attempt...');
}

/**
* Add CleanTalk mod admin area
* @param $admin_areas
*/
function cleantalk_admin_area(&$admin_areas)
{
global $txt;

$admin_areas['config']['areas']['modsettings']['subsections']['cleantalk'] = array($txt['cleantalk_name']);
}

/**
* Add CleanTalk mod admin action
* @param $subActions
*/
function cleantalk_admin_action(&$subActions)
{
$subActions['cleantalk'] = 'cleantalk_general_mod_settings';
}

/**
* Add CleanTalk mod settings area
* @param bool $return_config
* @return array
*/
function cleantalk_general_mod_settings($return_config = false)
{
global $txt, $scripturl, $context, $boardurl;

$context['page_title'] = $txt['cleantalk_settings'];
$context['post_url'] = $scripturl . '?action=admin;area=modsettings;save;sa=cleantalk';

$config_vars = array(
array('title', 'cleantalk_settings'),
array('text', 'cleantalk_api_key'),
array('check', 'cleantalk_first_post_checking', 'subtext' => $txt['cleantalk_first_post_checking_postinput']),
array('check', 'cleantalk_logging', 'subtext' => sprintf($txt['cleantalk_logging_postinput'], $boardurl)),
array('check', 'cleantalk_email_notifications', 'subtext' => $txt['cleantalk_email_notifications']),
array('check', 'cleantalk_ccf_checking', 'subtext' => $txt['cleantalk_ccf_checking_postinput']),
array('check', 'cleantalk_tell_others', 'subtext' => $txt['cleantalk_tell_others_postinput']),
array('check', 'cleantalk_sfw', 'subtext' => $txt['cleantalk_sfw_postinput']),
array('desc', 'cleantalk_api_key_description'),
array('desc', 'cleantalk_check_users'),
);

if ($return_config) {
return $config_vars;
}

if (isset($_GET['save'])) {
checkSession();
saveDBSettings($config_vars);
redirectexit('action=admin;area=modsettings;sa=cleantalk');
}

prepareDBSettingContext($config_vars);
}
4 changes: 3 additions & 1 deletion install.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
'integrate_pre_include' => '$sourcedir/cleantalk/cleantalkMod.php',
'integrate_pre_load' => 'cleantalk_sfw_check',
'integrate_register' => 'cleantalk_check_register',
'integrate_general_mod_settings' => 'cleantalk_general_mod_settings',
'integrate_load_theme' => 'cleantalk_load',
'integrate_exit' => 'cleantalk_exit',
'integrate_buffer' => 'cleantalk_buffer',
'integrate_admin_include' => '$sourcedir/cleantalk/cleantalkModAdmin.php',
'integrate_admin_areas' => 'cleantalk_admin_area',
'integrate_modify_modifications' => 'cleantalk_admin_action',
);

$isInstalling = empty($context['uninstalling']);
Expand Down
Loading

0 comments on commit 3ca5ed8

Please sign in to comment.