Skip to content

Commit

Permalink
Version 2.7.0
Browse files Browse the repository at this point in the history
* Fix. Install. Insert code after `namespace` anf `declare` directives declaration.

* Fix. Public. JS relative path fixed.

* Fix. apbct_restore_include_path. Now works on most types of servers.

* Fix. apbct_set_include_path. Protect constant owerwriting tries.

* New. Moodle integration. Detect CMS.

* New. Moodle integration. Modify signup page to protect registrations.

* Fix. Code. Constant definition fix.

* Fix. Code. Die page fixed and refactored.

* New. Moodle integration. Custom login page exclusion logic.

* Fix. Updater. PHP notices fixed.

* Fix. Server variables getting from $_SERVER instead of filter_input.

* Fix. Common Helper. Add rule for decbin - int type.

* Fix: checking the version of the curl for the correct choice of the type of request

* Fix. Helper. Curl options fixed.

* Fix: file_exists before unlink

* Added params for cookies

* Fixed cookie_secure

* Fix: Fixed installation

* Mod. PHP 8.1. Settings and Get fields any

* CRLF -> LF

* Mod. PHP 8.1 compatibility.

* New. SFW. CustomDB implemented. (#15)

* New. SFW. CustomDB implemented.

* Fix. SFW. Update delay time.

* Fix after review.

* Fix. Common. Err class fixed.

---------

Co-authored-by: Glomberg <bazz@bk.ru>

* Fix. SFW. PHP 8.1 notices fixed.

* Upd. Version number was increased to 2.7.0.

* Fix. Btree. PHP 8.1 notice fixed.

---------

Co-authored-by: alexandergull <alex.g@cleantalk.org>
Co-authored-by: alexandergull <galyshev@cleantalk.org>
Co-authored-by: Alex <45482252+alexandergull@users.noreply.github.com>
Co-authored-by: svfcode <svfcode@mail.ru>
Co-authored-by: Artem Anoshin <artem-anoshin@yandex.ru>
  • Loading branch information
6 people authored Oct 5, 2023
1 parent fadffdd commit 2e4370e
Show file tree
Hide file tree
Showing 31 changed files with 3,020 additions and 441 deletions.
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.6.0
# Version 2.7.0

Module for any CMS
## Installation
Expand Down
60 changes: 43 additions & 17 deletions cleantalk/cleantalk.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@

if ($is_sfw_check)
{
$sfw->ip_check();
$sfw->check();

if($sfw->test){
$sfw->logs__update(current(current($sfw->blocked_ips)), 'blocked');
$sfw->sfw_die($apikey, '', '', 'test');
}
if (!empty($sfw->blocked_ips)) {
if($sfw->test){
$sfw->logs__update(current(current($sfw->blocked_ips)), 'blocked');
$sfw->sfw_die($apikey, '', '', 'test');
}

if ($sfw->pass === false)
{
$sfw->logs__update(current(current($sfw->blocked_ips)), 'blocked');
$sfw->sfw_die($apikey);
if ($sfw->pass === false)
{
$sfw->logs__update(current(current($sfw->blocked_ips)), 'blocked');
$sfw->sfw_die($apikey);
}
}
}

Expand All @@ -68,8 +70,8 @@ function ct_attach_js($buffer){
){
$html_addition =
'<script>var apbct_checkjs_val = "' . $apbct_checkjs_val . '";</script>'
.'<script src="/cleantalk/js/ct_js_test.js"></script>'
.'<script src="/cleantalk/js/ct_ajax_catch.js"></script>';
.'<script src="cleantalk/js/ct_js_test.js"></script>'
.'<script src="cleantalk/js/ct_ajax_catch.js"></script>';
$buffer = preg_replace(
'/<\/body>\s*<\/html>/i',
$html_addition.'</body></html>',
Expand Down Expand Up @@ -122,11 +124,35 @@ function ct_attach_js($buffer){

// Set Cookies test for cookie test
$apbct_timestamp = time();
setcookie('apbct_timestamp', $apbct_timestamp, 0, '/');
setcookie('apbct_cookies_test', md5($apikey.$apbct_timestamp), 0, '/');
setcookie('apbct_timezone', '0', 0, '/');
setcookie('apbct_fkp_timestamp', '0', 0, '/');
setcookie('apbct_pointer_data', '0', 0, '/');
setcookie('apbct_ps_timestamp', '0', 0, '/');

$cookie_secure = (isset($_SERVER['HTTPS']) && !in_array($_SERVER['HTTPS'], ['off', ''])) || (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT']) === 443;

// For PHP 7.3+ and above
if (version_compare(phpversion(), '7.3.0', '>=')) {
$params = array(
'expires' => 0,
'path' => '/',
'domain' => '',
'secure' => $cookie_secure,
'httponly' => true,
'samesite' => 'Lax'
);

setcookie('apbct_timestamp', $apbct_timestamp, $params);
setcookie('apbct_cookies_test', md5($apikey.$apbct_timestamp), $params);
setcookie('apbct_timezone', '0', $params);
setcookie('apbct_fkp_timestamp', '0', $params);
setcookie('apbct_pointer_data', '0', $params);
setcookie('apbct_ps_timestamp', '0', $params);

// For PHP 5.6 - 7.2
} else {
setcookie('apbct_timestamp', $apbct_timestamp, 0, '/', '', $cookie_secure, true);
setcookie('apbct_cookies_test', md5($apikey.$apbct_timestamp), 0, '/', '', $cookie_secure, true);
setcookie('apbct_timezone', '0', 0, '/', '', $cookie_secure, true);
setcookie('apbct_fkp_timestamp', '0', 0, '/', '', $cookie_secure, true);
setcookie('apbct_pointer_data', '0', 0, '/', '', $cookie_secure, true);
setcookie('apbct_ps_timestamp', '0', 0, '/', '', $cookie_secure, true);
}

apbct_restore_include_path();
42 changes: 42 additions & 0 deletions cleantalk/fw_nets_meta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
$fw_nets_meta = array (
'line_length' => 26,
'cols' =>
array (
'network' =>
array (
'type' => 'int',
'length' => 11,
),
'mask' =>
array (
'type' => 'int',
'length' => 11,
),
'status' =>
array (
'type' => 'int',
'length' => 2,
),
'is_personal' =>
array (
'type' => 'int',
'length' => 2,
),
),
'description' => 'Test',
'indexes' =>
array (
0 =>
array (
'columns' =>
array (
0 => 'network',
),
'status' => 'ready',
'type' => 'btree',
),
),
'cols_num' => 4,
'rows' => 0,
);
55 changes: 48 additions & 7 deletions cleantalk/inc/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,42 @@
require_once 'common.php';

function install( $files, $api_key, $cms, $exclusions ){
if( $files ){
$tmp = array();
foreach ( $files as $file_to_mod ){

// Check for absolute paths
if(
preg_match( '/^[\/\\\\].*/', $file_to_mod) || // Root for *nix systems
preg_match( '/^[A-Za-z]:\/.*/', $file_to_mod) // Root for windows systems
){
Err::add( 'File paths should be relative' );
break;
}

// Check for .. upper directory access
if(
preg_match( '/^\.\.[\/\\\\].*/', $file_to_mod) // Access to upper levels
){
Err::add( 'Script for modification should be in the current folder or lower. You can not access upper leveled folders.' );
break;
}

$file = CLEANTALK_SITE_ROOT . trim( $file_to_mod );
if( file_exists($file) )
$tmp[] = $file;
}
$files = $tmp;
}

foreach ($files as $file){

$file_content = file_get_contents( $file );
$php_open_tags = preg_match_all("/(<\?)/", $file_content);
$php_close_tags = preg_match_all("/(\?>)/", $file_content);
$first_php_start = strpos($file_content, '<?');
$contains_namespace_declaration = strpos($file_content, 'namespace');
$contains_declare_declaration = strpos($file_content, 'declare');

// Adding <?php to the start if it's not there
if($first_php_start !== 0)
Expand All @@ -28,13 +57,21 @@ function install( $files, $api_key, $cms, $exclusions ){

if( ! Err::check() ){

// Addition to the top of the script
File::inject__code(
$file,
"\trequire_once( '" . CLEANTALK_SITE_ROOT . "cleantalk/cleantalk.php');",
'(<\?php)|(<\?)',
'top_code'
);
if( $contains_namespace_declaration !== false ) {
$needle = 'namespace\s?[a-zA-Z_\\x80-\\xff\\x5c][a-zA-Z0-9\\x80-\\xff\\x5c]*\s*;';
} elseif ( $contains_declare_declaration !== false ) {
$needle = 'declare\s*\({1}.*\){1};';
} else {
$needle = '(<\?php)|(<\?)';
}

// Addition to the top of the script
File::inject__code(
$file,
"\trequire_once( '" . CLEANTALK_SITE_ROOT . "cleantalk/cleantalk.php');",
$needle,
'top_code'
);

if( ! Err::check() ){

Expand Down Expand Up @@ -221,6 +258,10 @@ function detect_cms( $path_to_index, $out = 'Unknown' ){
// CsCart
if (preg_match('/(Kalynyak.*?)/', $index_file))
$out = 'cscart';
//moodle moodle
if ( preg_match('/(moodle.*?)/', $index_file) ) {
$out = 'moodle';
}
}

return $out;
Expand Down
32 changes: 26 additions & 6 deletions cleantalk/inc/common.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
<?php

use Cleantalk\ApbctUni\RemoteCalls;
use Cleantalk\Variables\Server;

define('APBCT_PLUGIN', 'uni');
define('APBCT_VERSION', '2.6.0');
define('APBCT_VERSION', '2.7.0');
define('APBCT_AGENT', APBCT_PLUGIN . '-' . str_replace( '.', '', APBCT_VERSION ) );
define('APBCT_USER_AGENT', 'Cleantalk-Antispam-Universal-Plugin/' . APBCT_VERSION);
define('APBCT_INITIAL_INCLUDE_PATH', get_include_path());

function apbct_set_include_path(){
set_include_path( CLEANTALK_ROOT );
function apbct_set_include_path()
{
defined('APBCT_INCLUDE_PATH_ON_FIRST_SET_CALL') or define('APBCT_INCLUDE_PATH_ON_FIRST_SET_CALL', get_include_path());
set_include_path(CLEANTALK_ROOT);
}

function apbct_restore_include_path(){
set_include_path( get_include_path() );
function apbct_restore_include_path()
{
set_include_path(get_include_path());
if ( get_include_path() === CLEANTALK_ROOT ) {
if ( defined(APBCT_INCLUDE_PATH_ON_FIRST_SET_CALL) ) {
set_include_path(APBCT_INCLUDE_PATH_ON_FIRST_SET_CALL);
} else {
set_include_path(APBCT_INITIAL_INCLUDE_PATH);
}
}
}

$ds = DIRECTORY_SEPARATOR;
Expand All @@ -29,6 +43,10 @@ function apbct_restore_include_path(){
require_once CLEANTALK_LIB . 'autoloader.php';
require_once CLEANTALK_ROOT . 'config.php';

define('CT_URI', 'http://' . Server::get('HTTP_HOST') . preg_replace( '/^(\/.*?\/).*/', '$1', parse_url(Server::get('REQUEST_URI'), PHP_URL_PATH)));
$result = parse_url(Server::get('REQUEST_URI'));
define('CT_AJAX_URI', isset($result['path']) ? $result['path'] : '/cleantalk/cleantalk.php');

// Create empty error object
\Cleantalk\Common\Err::getInstance();
// Run scheduled tasks
Expand All @@ -44,4 +62,6 @@ function apbct_restore_include_path(){
*/
function apbct_checkjs_hash($apikey, $salt) {
return hash('sha256', $apikey . $salt);
}
}

RemoteCalls::check() && RemoteCalls::perform();
Loading

0 comments on commit 2e4370e

Please sign in to comment.