Skip to content

Commit e7f140e

Browse files
authored
Merge pull request #11 from CleanTalk/dev
Dev
2 parents 3edc1ca + 3948194 commit e7f140e

File tree

8 files changed

+124
-20
lines changed

8 files changed

+124
-20
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ php-uni
22
=======
33
[![Build Status](https://travis-ci.org/CleanTalk/php-uni.svg)](https://travis-ci.org/CleanTalk/php-uni)
44

5-
# Version 2.5.2
5+
# Version 2.5.4
66

77
Module for any CMS
88
## Installation

cleantalk/cleantalk.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
return;
99
}
1010

11-
$apbct_checkjs_val = md5($apikey);
12-
global $apbct_checkjs_val;
13-
global $antispam_activity_status;
11+
global $apbct_salt, $apbct_checkjs_val, $antispam_activity_status, $general_postdata_test, $detected_cms;
12+
$apbct_checkjs_val = apbct_checkjs_hash($apikey, $apbct_salt);
13+
1414
if ($spam_firewall == 1) {
1515
$is_sfw_check = true;
1616
$sfw = new \Cleantalk\ApbctUni\SFW();
@@ -105,6 +105,16 @@ function ct_attach_js($buffer){
105105
}
106106
}
107107

108+
// Test for search form cscart
109+
if (
110+
$detected_cms === 'cscart' &&
111+
$general_postdata_test &&
112+
isset($_GET['dispatch']) &&
113+
$_GET['dispatch'] === 'products.search'
114+
) {
115+
apbct_spam_test($_GET);
116+
}
117+
108118
// General spam test
109119
if(!empty($_POST)){
110120
apbct_spam_test($_POST);

cleantalk/inc/admin.php

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function install( $files, $api_key, $cms, $exclusions ){
4141
// Addition to index.php Bottom (JavaScript test)
4242
File::inject__code(
4343
$file,
44-
"\tob_end_flush();\n"
44+
"\t\nif(ob_get_contents()){\nob_end_flush();\n}\n"
4545
."\tif(isset(\$_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower(\$_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){\n"
4646
."\t\tdie();\n"
4747
."\t}",
@@ -70,7 +70,7 @@ function install( $files, $api_key, $cms, $exclusions ){
7070
function install_config( $modified_files, $api_key, $cms, $exclusions ){
7171

7272
$path_to_config = CLEANTALK_ROOT . 'config.php';
73-
$salt = str_pad(rand(0, getrandmax()), 6, '0').str_pad(rand(0, getrandmax()), 6, '0');
73+
$apbct_salt = str_pad(rand(0, getrandmax()), 6, '0').str_pad(rand(0, getrandmax()), 6, '0');
7474
// Attention. Backwards order because inserting it step by step
7575

7676
$pass = 'NO PASS';
@@ -119,8 +119,8 @@ function install_config( $modified_files, $api_key, $cms, $exclusions ){
119119
);
120120
}
121121

122-
File::inject__variable( $path_to_config, 'salt', $salt );
123-
File::inject__variable( $path_to_config, 'security', hash( 'sha256', '0(o_O)0' . $salt ) );
122+
File::inject__variable( $path_to_config, 'salt', $apbct_salt );
123+
File::inject__variable( $path_to_config, 'security', hash( 'sha256', '0(o_O)0' . $apbct_salt ) );
124124
File::inject__variable( $path_to_config, 'modified_files', $modified_files, true );
125125
if( $exclusions )
126126
File::inject__variable( $path_to_config, 'exclusions', $exclusions, true );
@@ -215,6 +215,9 @@ function detect_cms( $path_to_index, $out = 'Unknown' ){
215215
$out = 'ShopScript';
216216
if (preg_match('/(DATALIFEENGINE.*?)/', $index_file))
217217
$out = 'DLE';
218+
// CsCart
219+
if (preg_match('/(Kalynyak.*?)/', $index_file))
220+
$out = 'cscart';
218221
}
219222

220223
return $out;
@@ -235,3 +238,29 @@ function apbct__plugin_update_message() {
235238
echo '<p class="text-center">You are using the latest version '. APBCT_VERSION . '</p>';
236239
}
237240
}
241+
242+
/**
243+
* Print Block with CSCart Js Snippet
244+
*/
245+
function apbct__cscart_js_snippet() {
246+
global $apikey, $apbct_salt, $detected_cms;
247+
248+
// Only for CsCart
249+
if ($detected_cms != 'cscart') return;
250+
251+
$apbct_checkjs_hash = apbct_checkjs_hash($apikey, $apbct_salt);
252+
?>
253+
254+
<div class="highlight">
255+
<h4>Add this code to all pages of the site (use the basic template). Detailed instruction is <a href="https://blog.cleantalk.org/protecting-cs-cart-website-from-spam/">here</a></h4>
256+
<pre tabindex="0" class="chroma">
257+
<code class="language-html" data-lang="html">
258+
&lt;script&gt;var apbct_checkjs_val="<?= $apbct_checkjs_hash; ?>";&lt;/script&gt;
259+
&lt;script src="/cleantalk/js/ct_js_test.js"&gt;&lt;/script&gt;
260+
&lt;script src="/cleantalk/js/ct_js_test.js"&gt;&lt;/script&gt;
261+
</code>
262+
</pre>
263+
</div>
264+
265+
<?php
266+
}

cleantalk/inc/common.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<?php
22

3-
define( 'CLEANTALK_INITIAL_INCLUDE_PATH', get_include_path() );
43
define('APBCT_PLUGIN', 'uni');
5-
define('APBCT_VERSION', '2.5.2');
4+
define('APBCT_VERSION', '2.5.4');
65
define('APBCT_AGENT', APBCT_PLUGIN . '-' . str_replace( '.', '', APBCT_VERSION ) );
76
define('APBCT_USER_AGENT', 'Cleantalk-Antispam-Universal-Plugin/' . APBCT_VERSION);
87

@@ -11,7 +10,7 @@ function apbct_set_include_path(){
1110
}
1211

1312
function apbct_restore_include_path(){
14-
set_include_path( CLEANTALK_INITIAL_INCLUDE_PATH );
13+
set_include_path( get_include_path() );
1514
}
1615

1716
$ds = DIRECTORY_SEPARATOR;
@@ -37,3 +36,10 @@ function apbct_restore_include_path(){
3736
require_once CLEANTALK_ROOT . 'inc' . DS . 'cron_functions.php'; // File with cron wrappers
3837
$cron->runTasks();
3938
unset( $cron );
39+
40+
/**
41+
* Generate value for checking JS
42+
*/
43+
function apbct_checkjs_hash($apikey, $salt) {
44+
return hash('sha256', $apikey . $salt);
45+
}

cleantalk/inc/functions.php

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,15 @@ function apbct_spam_test($data){
3232
// Flags
3333
$registration = isset($msg_data['reg']) ? $msg_data['reg'] : false;
3434
$skip = isset($msg_data['skip']) ? $msg_data['skip'] : false;
35-
35+
36+
// Check registration for CsCart
37+
if (
38+
$detected_cms === 'cscart' &&
39+
isset($data['user_data']['password1'], $data['user_data']['password2'])
40+
) {
41+
$registration = true;
42+
}
43+
3644
// Skip check if
3745
if(
3846
$skip || // Skip flag set by apbct_get_fields_any()
@@ -70,7 +78,7 @@ function apbct_spam_test($data){
7078

7179
$comment_type = 'feedback';
7280

73-
if (strpos($_SERVER['HTTP_REFERER'], 'checkout') !== false) {
81+
if (isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], 'checkout') !== false) {
7482
$comment_type = 'order';
7583
}
7684

@@ -113,7 +121,7 @@ function apbct_get_sender_info($data)
113121
// Common
114122
'remote_addr' => $_SERVER['REMOTE_ADDR'],
115123
'USER_AGENT' => htmlspecialchars($_SERVER['HTTP_USER_AGENT']),
116-
'REFFERRER' => htmlspecialchars($_SERVER['HTTP_REFERER']),
124+
'REFFERRER' => isset($_SERVER['HTTP_REFERER']) ? htmlspecialchars($_SERVER['HTTP_REFERER']) : '',
117125
'page_url' => isset($_SERVER['SERVER_NAME'], $_SERVER['REQUEST_URI']) ? htmlspecialchars($_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']) : null,
118126
// 'cms_lang' => substr(locale_get_default(), 0, 2),
119127

@@ -382,7 +390,7 @@ function apbct_get_fields_any($arr, $message=array(), $email = null, $nickname =
382390
$message[$prev_key.$key] = $value;
383391
}
384392

385-
}else if(!is_object($value)&&@get_class($value)!='WP_User'){
393+
}else if(!is_object($value)){
386394

387395
$prev_key_original = $prev_key;
388396
$prev_key = ($prev_key === '' ? $key.'_' : $prev_key.$key.'_');
@@ -446,9 +454,12 @@ function apbct_obfuscate_param($value = null)
446454
* return null|0|1;
447455
*/
448456
function apbct_js_test(){
449-
global $apikey;
457+
global $apikey, $apbct_salt, $detected_cms;
450458
if(isset($_COOKIE['apbct_checkjs'])){
451-
if($_COOKIE['apbct_checkjs'] == md5($apikey))
459+
if(
460+
$_COOKIE['apbct_checkjs'] == apbct_checkjs_hash($apikey, $apbct_salt) ||
461+
($detected_cms === 'cscart' && $_COOKIE['apbct_checkjs'] == md5($apikey))
462+
)
452463
return 1;
453464
else
454465
return 0;
@@ -615,5 +626,37 @@ function apbct_check__exclusions() {
615626
return true;
616627
}
617628

629+
# Exclude unnecessary requests when filling out an order
630+
if(
631+
$detected_cms === 'cscart' &&
632+
apbct_check__exclusions_in_post(
633+
array(
634+
'dispatch' => 'products.quick_view'
635+
)
636+
) ||
637+
apbct_check__exclusions_in_post(
638+
array(
639+
'dispatch' => 'checkout.customer_info'
640+
)
641+
) ||
642+
apbct_check__exclusions_in_post(
643+
array(
644+
'dispatch' => 'checkout.update_steps'
645+
)
646+
) ||
647+
apbct_check__exclusions_in_post(
648+
array(
649+
'dispatch' => 'products.view'
650+
)
651+
) ||
652+
apbct_check__exclusions_in_post(
653+
array(
654+
'dispatch' => 'categories.view'
655+
)
656+
)
657+
) {
658+
return true;
659+
}
660+
618661
return false;
619662
}

cleantalk/lib/Cleantalk/ApbctUni/SFW.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ public function logs__update($ip, $result) {
7979
if($ip === NULL || $result === NULL)
8080
return;
8181

82-
global $salt;
82+
global $apbct_salt;
8383

8484
$time = time();
85-
$log_path = CLEANTALK_ROOT . 'data/sfw_logs/'. hash('sha256', $ip . $salt) .'.log';
85+
$log_path = CLEANTALK_ROOT . 'data/sfw_logs/'. hash('sha256', $ip . $apbct_salt) .'.log';
8686

8787
if( file_exists( $log_path ) ){
8888

cleantalk/lib/Cleantalk/Updater/Updater.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,4 +308,15 @@ private function rollback(){
308308
}else
309309
return false;
310310
}
311+
312+
/**
313+
* Update 2.5.3
314+
*/
315+
function update_to_2_5_3()
316+
{
317+
global $apikey, $apbct_salt;
318+
319+
File::clean__variable(CLEANTALK_CONFIG_FILE, 'apbct_salt');
320+
File::inject__variable(CLEANTALK_CONFIG_FILE, 'apbct_salt', apbct_checkjs_hash($apikey, $apbct_salt));
321+
}
311322
}

cleantalk/settings.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,11 @@
290290
</form>
291291

292292
<?php
293+
/**
294+
* CsCart JS Snippet
295+
*/
296+
apbct__cscart_js_snippet();
297+
293298
/**
294299
* Plugin version section
295300
*/
@@ -315,7 +320,7 @@
315320
<script src="js/custom.js?v=<?php echo APBCT_VERSION; ?>"></script>
316321
<script src="js/overhang.min.js"></script>
317322
<script type='text/javascript'>
318-
var security = '<?php echo $security ?>';
323+
var security = '<?php if (isset($security)) echo $security ?>';
319324
var ajax_url = location.href;
320325
</script>
321326

0 commit comments

Comments
 (0)