Skip to content

Sha256 algo in checkjs #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ php-uni
=======
[![Build Status](https://travis-ci.org/CleanTalk/php-uni.svg)](https://travis-ci.org/CleanTalk/php-uni)

# Version 2.5.3
# Version 2.5.4

Module for any CMS
## Installation
Expand Down
3 changes: 2 additions & 1 deletion cleantalk/cleantalk.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
return;
}

$apbct_checkjs_val = md5($apikey);
global $apbct_salt;
$apbct_checkjs_val = apbct_checkjs_hash($apikey, $apbct_salt);
global $apbct_checkjs_val;
global $antispam_activity_status;
if ($spam_firewall == 1) {
Expand Down
35 changes: 32 additions & 3 deletions cleantalk/inc/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function install( $files, $api_key, $cms, $exclusions ){
function install_config( $modified_files, $api_key, $cms, $exclusions ){

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

$pass = 'NO PASS';
Expand Down Expand Up @@ -119,8 +119,8 @@ function install_config( $modified_files, $api_key, $cms, $exclusions ){
);
}

File::inject__variable( $path_to_config, 'salt', $salt );
File::inject__variable( $path_to_config, 'security', hash( 'sha256', '0(o_O)0' . $salt ) );
File::inject__variable( $path_to_config, 'salt', $apbct_salt );
File::inject__variable( $path_to_config, 'security', hash( 'sha256', '0(o_O)0' . $apbct_salt ) );
File::inject__variable( $path_to_config, 'modified_files', $modified_files, true );
if( $exclusions )
File::inject__variable( $path_to_config, 'exclusions', $exclusions, true );
Expand Down Expand Up @@ -215,6 +215,9 @@ function detect_cms( $path_to_index, $out = 'Unknown' ){
$out = 'ShopScript';
if (preg_match('/(DATALIFEENGINE.*?)/', $index_file))
$out = 'DLE';
// CsCart
if (preg_match('/(Kalynyak.*?)/', $index_file))
$out = 'cscart';
}

return $out;
Expand All @@ -235,3 +238,29 @@ function apbct__plugin_update_message() {
echo '<p class="text-center">You are using the latest version '. APBCT_VERSION . '</p>';
}
}

/**
* Print Block with CSCart Js Snippet
*/
function apbct__cscart_js_snippet() {
global $apikey, $apbct_salt, $detected_cms;

// Only for CsCart
if ($detected_cms != 'cscart') return;

$apbct_checkjs_hash = apbct_checkjs_hash($apikey, $apbct_salt);
?>

<div class="highlight">
<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>
<pre tabindex="0" class="chroma">
<code class="language-html" data-lang="html">
&lt;script&gt;var apbct_checkjs_val="<?= $apbct_checkjs_hash; ?>";&lt;/script&gt;
&lt;script src="/cleantalk/js/ct_js_test.js"&gt;&lt;/script&gt;
&lt;script src="/cleantalk/js/ct_js_test.js"&gt;&lt;/script&gt;
</code>
</pre>
</div>

<?php
}
9 changes: 8 additions & 1 deletion cleantalk/inc/common.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

define('APBCT_PLUGIN', 'uni');
define('APBCT_VERSION', '2.5.3');
define('APBCT_VERSION', '2.5.4');
define('APBCT_AGENT', APBCT_PLUGIN . '-' . str_replace( '.', '', APBCT_VERSION ) );
define('APBCT_USER_AGENT', 'Cleantalk-Antispam-Universal-Plugin/' . APBCT_VERSION);

Expand Down Expand Up @@ -36,3 +36,10 @@ function apbct_restore_include_path(){
require_once CLEANTALK_ROOT . 'inc' . DS . 'cron_functions.php'; // File with cron wrappers
$cron->runTasks();
unset( $cron );

/**
* Generate value for checking JS
*/
function apbct_checkjs_hash($apikey, $salt) {
return hash('sha256', $apikey . $salt);
}
7 changes: 5 additions & 2 deletions cleantalk/inc/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,12 @@ function apbct_obfuscate_param($value = null)
* return null|0|1;
*/
function apbct_js_test(){
global $apikey;
global $apikey, $apbct_salt, $detected_cms;
if(isset($_COOKIE['apbct_checkjs'])){
if($_COOKIE['apbct_checkjs'] == md5($apikey))
if(
$_COOKIE['apbct_checkjs'] == apbct_checkjs_hash($apikey, $apbct_salt) ||
($detected_cms === 'cscart' && $_COOKIE['apbct_checkjs'] == md5($apikey))
)
return 1;
else
return 0;
Expand Down
4 changes: 2 additions & 2 deletions cleantalk/lib/Cleantalk/ApbctUni/SFW.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ public function logs__update($ip, $result) {
if($ip === NULL || $result === NULL)
return;

global $salt;
global $apbct_salt;

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

if( file_exists( $log_path ) ){

Expand Down
11 changes: 11 additions & 0 deletions cleantalk/lib/Cleantalk/Updater/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,4 +308,15 @@ private function rollback(){
}else
return false;
}

/**
* Update 2.5.3
*/
function update_to_2_5_3()
{
global $apikey, $apbct_salt;

File::clean__variable(CLEANTALK_CONFIG_FILE, 'apbct_salt');
File::inject__variable(CLEANTALK_CONFIG_FILE, 'apbct_salt', apbct_checkjs_hash($apikey, $apbct_salt));
}
}
5 changes: 5 additions & 0 deletions cleantalk/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@
</form>

<?php
/**
* CsCart JS Snippet
*/
apbct__cscart_js_snippet();

/**
* Plugin version section
*/
Expand Down