Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
safronik authored and safronik committed Dec 6, 2021
2 parents 3493ee4 + 91dcd16 commit 949a79e
Show file tree
Hide file tree
Showing 14 changed files with 327 additions and 94 deletions.
4 changes: 2 additions & 2 deletions uniforce/inc/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
*
* Sets all main constants
*
* Version: 3.5.0
* Version: 3.6.0
*/

use Cleantalk\USP\Variables\Server;
use Cleantalk\USP\Common\RemoteCalls;

if( ! defined( 'SPBCT_PLUGIN' ) ) define( 'SPBCT_PLUGIN', 'uniforce' );
if( ! defined( 'SPBCT_VERSION' ) ) define( 'SPBCT_VERSION', '3.5.0' );
if( ! defined( 'SPBCT_VERSION' ) ) define( 'SPBCT_VERSION', '3.6.0' );
if( ! defined( 'SPBCT_AGENT' ) ) define( 'SPBCT_AGENT', SPBCT_PLUGIN . '-' . str_replace( '.', '', SPBCT_VERSION ) );
if( ! defined( 'SPBCT_USER_AGENT' ) ) define( 'SPBCT_USER_AGENT', 'Cleantalk-Security-Universal-Plugin/' . SPBCT_VERSION );

Expand Down
2 changes: 1 addition & 1 deletion uniforce/inc/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function usp_settings__show_fw_statistics( $out = '' )
? date('M d Y H:i:s', $fw_stats->last_update)
: 'never'
) . '<br>';
echo 'Security FireWall contains: ' . ( $fw_stats->entries ? $fw_stats->entries : 'no' ). ' entires. '
echo 'Security FireWall contains: ' . ( $fw_stats->entries ? $fw_stats->entries : 'no' ). ' entries. '
. ( State::getInstance()->fw_stats->updating ? '<b>Under updating now: ' . State::getInstance()->fw_stats->update_percent. '%</b>' : '' )
. '<br>';
echo 'Security FireWall logs were sent: ' . ( $fw_stats->logs_sent_time
Expand Down
2 changes: 1 addition & 1 deletion uniforce/index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Version: 3.5.0
* Version: 3.6.0
*/
$file_availability = true;
$site_index_file = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '/index.php';
Expand Down
10 changes: 10 additions & 0 deletions uniforce/js/ct_ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ class CTAJAX{

success( response ){

// Hide spinner
if( this.spinner ){
if( typeof this.spinner == 'function' )
this.spinner();
if( typeof this.spinner == 'object' ){
this.spinner = jQuery( this.spinner );
this.spinner.css('display', 'none');
}
}

if( !! response.error ){

this.error(
Expand Down
17 changes: 13 additions & 4 deletions uniforce/js/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ jQuery(document).ready(function(){
// TABLE BULK ACTIONS
spbc_bulk_action = null;
function spbc_tbl__bulk_actions__listen(){
jQuery('.tbl-bulk_actions--apply').on('click', function(){
jQuery('.tbl-bulk_actions--apply')
.off('click')
.on('click', function(){

if(!spbc_bulk_action && !confirm(spbc_TableData.warning_bulk))
return;
Expand All @@ -36,7 +38,9 @@ function spbc_tbl__bulk_actions__listen(){

// TABLE ROW ACTIONS
function spbc_tbl__row_actions__listen(){
jQuery('.tbl-row_action--ajax').on('click', function(){
jQuery('.tbl-row_action--ajax')
.off('click')
.on('click', function(){
console.log('spbc_tbl__row_actions__listen click');
var self = jQuery(this);
var data = {
Expand Down Expand Up @@ -79,6 +83,7 @@ function spbc_tbl__row_actions__callback( result, data, obj ){
obj.html(result.temp_html);
setTimeout(function(){
obj.html(tmp).css({background: 'inherit'}).find('.column-primary .row-actions .tbl-row_action--'+data.add_action).remove();
usp_showHide__listen();
},5000);
}
if(spbc_bulk_action)
Expand Down Expand Up @@ -167,8 +172,12 @@ function spbc_tbl__sort__listen(){

// Shows/hides full text
function usp_showHide__listen(){
jQuery('.spbcShortText').on('mouseover', function(){ jQuery(this).next().show(); })
jQuery('.spbcFullText').on('mouseout', function(){ jQuery(this).hide(); });
jQuery('.spbcShortText')
.off('mouseover' )
.on('mouseover', function(){ jQuery(this).next().show(); });
jQuery('.spbcFullText')
.off('mouseout' )
.on('mouseout', function(){ jQuery(this).hide(); });
}

// Callback for TABLE SORT ACTIONS
Expand Down
2 changes: 1 addition & 1 deletion uniforce/lib/Cleantalk/USP/Common/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ static public function method__security_mscan_files($api_key, $file_path, $file,
'path_to_sfile' => $file_path,
'attached_sfile' => $file,
'md5sum_sfile' => $file_md5,
'dangerous_code' => $weak_spots,
'dangerous_code' => json_encode( $weak_spots ),
);

$result = static::send_request($request);
Expand Down
176 changes: 162 additions & 14 deletions uniforce/lib/Cleantalk/USP/Common/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -672,8 +672,49 @@ static public function http__get_data_from_remote_gz( $url ){

return $data;
}

public static function http__download_remote_file( $url, $tmp_folder ){

/**
* Wrapper for http_request
* Requesting HTTP response code for $url
*
* @param string $path
*
* @return array|mixed|string
*/
public static function get_data_from_local_gz( $path ){

if ( file_exists( $path ) ) {

if ( is_readable( $path ) ) {

$data = file_get_contents( $path );

if ( $data !== false ){

if( static::get_mime_type( $data, 'application/x-gzip' ) ){

if( function_exists('gzdecode') ) {

$data = gzdecode( $data );

if ( $data !== false ){
return $data;
}else
return array( 'error' => 'Can not unpack datafile');

}else
return array( 'error' => 'Function gzdecode not exists. Please update your PHP at least to version 5.4 ' . $data['error'] );
}else
return array('error' => 'WRONG_REMOTE_FILE_MIME_TYPE');
}else
return array( 'error' => 'Couldn\'t get data' );
}else
return array( 'error' => 'File is not readable: ' . $path );
}else
return array( 'error' => 'File doesn\'t exists: ' . $path );
}

public static function http__download_remote_file( $url, $tmp_folder ){

$result = self::http__request( $url, array(), 'get_file' );

Expand All @@ -692,8 +733,88 @@ public static function http__download_remote_file( $url, $tmp_folder ){
}else
return $result;
}

/**

/**
* Do multi curl requests.
*
* @param array $urls Array of URLs to requests
* @param string $write_to Path to the writing files dir
*
* @return array
* @psalm-suppress PossiblyUnusedMethod
*/
public static function http__download_remote_file__multi( $urls, $write_to = '' )
{
if( ! is_array( $urls ) || empty( $urls ) ) {
return array( 'error' => 'CURL_MULTI: Parameter is not an array.' );
}

foreach( $urls as $url ) {
if( ! is_string( $url ) ) {
return array( 'error' => 'CURL_MULTI: Parameter elements must be strings.' );
}
}

$urls_count = count( $urls );
$curl_arr = array();
$master = curl_multi_init();

for($i = 0; $i < $urls_count; $i++)
{
$url =$urls[$i];
$curl_arr[$i] = curl_init($url);
$opts = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT_MS => 10000,
CURLOPT_FORBID_REUSE => true,
CURLOPT_USERAGENT => self::DEFAULT_USER_AGENT . '; ' . ( isset( $_SERVER['REMOTE_ADDR'] ) ? $_SERVER['REMOTE_ADDR'] : 'UNKNOWN_HOST' ),
CURLOPT_HTTPHEADER => array('Expect:'), // Fix for large data and old servers http://php.net/manual/ru/function.curl-setopt.php#82418
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 5,
);
curl_setopt_array($curl_arr[$i], $opts);
curl_multi_add_handle($master, $curl_arr[$i]);
}

do {
curl_multi_exec($master,$running);
// @ToDo place here sleep(500) to avoid possible CPU overusing
} while($running > 0);

$results = array();

for($i = 0; $i < $urls_count; $i++)
{
$info = curl_getinfo($curl_arr[$i], CURLINFO_HTTP_CODE);
if( 200 == $info ) {
if( ! empty( $write_to ) && is_dir( $write_to ) && is_writable( $write_to ) ) {
$results[] = file_put_contents( $write_to . DS . self::getFilenameFromUrl( $urls[$i] ), curl_multi_getcontent( $curl_arr[$i] ) )
? 'success'
: 'error';
} else {
$results[] = curl_multi_getcontent( $curl_arr[$i] );
}

} else {
$results[] = 'error';
}
}
return $results;
}

/**
* @param $url string
*
* @return string
*/
public static function getFilenameFromUrl( $url )
{
$array = explode( '/', $url );
return end( $array );
}


/**
* Gets every HTTP_ headers from $_SERVER
*
* If Apache web server is missing then making
Expand Down Expand Up @@ -917,15 +1038,27 @@ static function get_mime_type( $data, $type = '' )
}
return $type;
}

/**

/**
* Pops line from the csv buffer and fromat it by map to array
*
* @param $csv
* @param array $map
*
* @return array|false
*/
public static function buffer__csv__get_map( &$csv ){
$line = static::buffer__csv__pop_line( $csv );
return explode( ',', $line );
}

/**
* Parse Comma-separated values
*
* @param $buffer
*
* @return false|string[]
*/

static function buffer__parse__csv( $buffer ){
$buffer = explode( "\n", $buffer );
$buffer = self::buffer__trim_and_clear_from_empty_lines( $buffer );
Expand All @@ -945,6 +1078,12 @@ static function buffer__parse__csv( $buffer ){
static function buffer__parse__nsv( $buffer ){
$buffer = str_replace( array( "\r\n", "\n\r", "\r", "\n" ), "\n", $buffer );
$buffer = explode( "\n", $buffer );
foreach( $buffer as $key => &$value ){
if( $value === '' ){
unset( $buffer[ $key ] );
}
}
unset( $value );
return $buffer;
}

Expand All @@ -955,11 +1094,11 @@ static function buffer__parse__nsv( $buffer ){
*
* @return false|string
*/
static public function buffer__csv__pop_line( &$csv ){
$pos = strpos( $csv, "\n" );
$first_line = substr( $csv, 0, $pos );
$csv = substr_replace( $csv, '', 0, $pos + 1 );
return $first_line;
public static function buffer__csv__pop_line( &$csv ){
$pos = strpos( $csv, "\n" );
$line = substr( $csv, 0, $pos );
$csv = substr_replace( $csv, '', 0, $pos + 1 );
return $line;
}

/**
Expand All @@ -970,10 +1109,19 @@ static public function buffer__csv__pop_line( &$csv ){
*
* @return array|false
*/
static public function buffer__csv__pop_line_to_array( &$csv, $map = array() ){
static public function buffer__csv__pop_line_to_array( &$csv, $map = array(), $stripslashes = false ){
$line = trim( static::buffer__csv__pop_line( $csv ) );
$line = str_getcsv( $line, ',', '\'' );
$line = strpos( $line, '\'' ) === 0
? str_getcsv( $line, ',', '\'' )
: explode( ',', $line );

if( $stripslashes ){
$line = array_map( function( $elem ){
return stripslashes( $elem );
},
$line
);
}
if( $map )
$line = array_combine( $map, $line );

Expand Down
3 changes: 0 additions & 3 deletions uniforce/lib/Cleantalk/USP/Common/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,6 @@ class State extends \Cleantalk\USP\Common\Storage{
'cured' => array(),
),
'2fa_keys' => array(),

// Crunch
'updated_to_350' => true,
);

public $default_remote_calls = array(
Expand Down
13 changes: 9 additions & 4 deletions uniforce/lib/Cleantalk/USP/Common/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,12 @@ protected function get($option_name)
$out = isset( $$option_name ) ? $$option_name : array();
break;
case 'csv':
$data = file_get_contents( $filename );
$out = \Cleantalk\USP\Uniforce\Helper::buffer__csv__to_array( $data, $this->map );
$out = array();
$fd = fopen( $filename, 'r' );
while( $line = fgetcsv( $fd, 2000, ',', '\'', '' ) ){
$out[] = array_combine($this->map, $line);
}
fclose( $fd );
break;
}
}
Expand Down Expand Up @@ -116,8 +120,9 @@ public function save()

case 'csv':
$fp = fopen( $filename, 'w' );
foreach( $this->convertToArray() as $field )
fputcsv( $fp, $field, ',', '\'' );
foreach( $this->convertToArray() as &$field ){
fputcsv( $fp, $field, ',', '\'' );
}
fclose( $fp );
break;
}
Expand Down
Loading

0 comments on commit 949a79e

Please sign in to comment.