Skip to content

Commit 151a106

Browse files
authored
Merge pull request #10 from CleanTalk/sha256-algo-in-checkjs
Sha256 algo in checkjs
2 parents 250fcac + a9404f5 commit 151a106

File tree

8 files changed

+66
-10
lines changed

8 files changed

+66
-10
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.3
5+
# Version 2.5.4
66

77
Module for any CMS
88
## Installation

cleantalk/cleantalk.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
return;
99
}
1010

11-
$apbct_checkjs_val = md5($apikey);
11+
global $apbct_salt;
12+
$apbct_checkjs_val = apbct_checkjs_hash($apikey, $apbct_salt);
1213
global $apbct_checkjs_val;
1314
global $antispam_activity_status;
1415
if ($spam_firewall == 1) {

cleantalk/inc/admin.php

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
define('APBCT_PLUGIN', 'uni');
4-
define('APBCT_VERSION', '2.5.3');
4+
define('APBCT_VERSION', '2.5.4');
55
define('APBCT_AGENT', APBCT_PLUGIN . '-' . str_replace( '.', '', APBCT_VERSION ) );
66
define('APBCT_USER_AGENT', 'Cleantalk-Antispam-Universal-Plugin/' . APBCT_VERSION);
77

@@ -36,3 +36,10 @@ function apbct_restore_include_path(){
3636
require_once CLEANTALK_ROOT . 'inc' . DS . 'cron_functions.php'; // File with cron wrappers
3737
$cron->runTasks();
3838
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: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,12 @@ function apbct_obfuscate_param($value = null)
446446
* return null|0|1;
447447
*/
448448
function apbct_js_test(){
449-
global $apikey;
449+
global $apikey, $apbct_salt, $detected_cms;
450450
if(isset($_COOKIE['apbct_checkjs'])){
451-
if($_COOKIE['apbct_checkjs'] == md5($apikey))
451+
if(
452+
$_COOKIE['apbct_checkjs'] == apbct_checkjs_hash($apikey, $apbct_salt) ||
453+
($detected_cms === 'cscart' && $_COOKIE['apbct_checkjs'] == md5($apikey))
454+
)
452455
return 1;
453456
else
454457
return 0;

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: 5 additions & 0 deletions
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
*/

0 commit comments

Comments
 (0)