Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
svfcode committed Jun 28, 2024
2 parents 89d30da + 9ec73f4 commit c5318cc
Show file tree
Hide file tree
Showing 24 changed files with 1,315 additions and 1,081 deletions.
58 changes: 58 additions & 0 deletions uniforce/css/settings-scanner.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,61 @@
#spbc_estimated_output, #spbc_elapsed_output {
font-weight: 600;
}

.spbc_progressbar_counter{
position: absolute;
height: 22px;
width: 100%;
left: 0;
top: 0;
text-align: center;
}
.spbc_progressbar_counter span{
vertical-align: sub;
line-height: 22px;
font-weight: 600;
font-size: 18px;
}
.ui-progressbar-value{ background-image: url(../img/pbar-ani.gif) !important; }

.spbc_view_file_row_wrapper { line-height: 19px; }
.spbc_view_file_row_wrapper:nth-child(odd) { background: #ccc; }
.spbc_view_file_row_wrapper:nth-child(even) { background: #ddd; }
.spbc_view_file_row_num { display: inline-block; width: 30px; margin: 0 0 0 5px; border-right: 1px solid black; }
.spbc_view_file_row { display: inline; margin: 0 0 0 5px; }
.spbc_view_file_row_wrapper_weak_spots { background-color: #f00; }

#spbc_estimated_time_hint
{
width: 100%;
text-align: right;
vertical-align: sub;
font-weight: 400;
font-size: 12px;
}

#spbc_estimated_time_block{
border: 1px solid #ddd;
padding: 10px;
border-radius: 3px;
}

.spbc_estimated_item {
width: 50%;
text-align: left;
vertical-align: sub;
font-weight: 400;
font-size: 14px;
}

#spbc_estimated_output, #spbc_elapsed_output {
font-weight: 600;
}

.spbc_scan_results_div {
margin-top: 15px; margin-bottom: 15px; padding: 5px; border-radius: 3px; background: #f8f8f8
}

.spbc_scan_results_item {
margin: 0px; padding: 5px;
}
10 changes: 9 additions & 1 deletion uniforce/inc/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

if( Post::get( 'security' ) === md5( Server::get( 'SERVER_NAME' ) ) ) {

if (Post::get( 'isUFLite' ) == 1) {
usp_handle_uflite_restrictions();
}

switch( Post::get( 'action' ) ) {

case 'key_validate' :
Expand All @@ -26,6 +30,10 @@
usp_do_install();
break;

case 'spbc_tbl-pagination':
call_user_func( '\Cleantalk\USP\Layout\ListTable::ajax__pagination_handler' );
break;

default:
die(Err::add('Unknown action')->get_last( 'as_json' ));
break;
Expand Down Expand Up @@ -78,7 +86,7 @@
}
die(json_encode( $result, true ));
break;

default:
die(Err::add('Unknown action')->get_last( 'as_json' ));
break;
Expand Down
29 changes: 29 additions & 0 deletions uniforce/inc/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -800,3 +800,32 @@ function processValidKeyState($usp, $result)
$usp->data->key_is_ok = $usp->data->moderate && $usp->data->valid ? 1 : 0;
usp_install_cron();
}

/**
* Handle restricted actions for UniForce lite
* @return void
*/
function usp_handle_uflite_restrictions()
{
$error = 'To perform actions with files, please purchase the full version of Universal Security Plugin.';
//get template from views
require_once CT_USP_ROOT . 'view' . DIRECTORY_SEPARATOR . 'uf_lite_requires_full.php';
if (!isset($usp_purchase_hrefs)) {
$usp_purchase_hrefs = $error;
} else {
$purchase_link = 'https://p.cleantalk.org/?featured=&product_id=4';
$install_link = 'https://cleantalk.org/help/install-uniforce-security';
$usp_purchase_hrefs = sprintf(
$usp_purchase_hrefs,
$error,
$purchase_link,
$install_link
);
}
$json_uf_lite_answer = array(
'success' => false,
'error' => $error,
'uflite_hrefs' => $usp_purchase_hrefs
);
die(json_encode($json_uf_lite_answer));
}
14 changes: 11 additions & 3 deletions uniforce/inc/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* Sets all main constants
*
* Version: 3.10.0
* Version: 3.11.0
*/

use Cleantalk\USP\Common\Err;
Expand All @@ -14,18 +14,26 @@
use Cleantalk\USP\Common\RemoteCalls;

if( ! defined( 'SPBCT_PLUGIN' ) ) define( 'SPBCT_PLUGIN', 'uniforce' );
if( ! defined( 'SPBCT_VERSION' ) ) define( 'SPBCT_VERSION', '3.10.0' );
if( ! defined( 'SPBCT_VERSION' ) ) define( 'SPBCT_VERSION', '3.11.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 );

if ( ! defined('DS') ) {
define( 'DS', DIRECTORY_SEPARATOR );
}

// Uniforce Lite installer
define('CT_USP_UNIFORCE_LITE', isset($_GET['uniforce_lite']) && $_GET['uniforce_lite'] === '1');

// Directories
define( 'CT_USP_INC', realpath(__DIR__ ) . DS );
define( 'CT_USP_ROOT', realpath( CT_USP_INC . '..') . DS );
define( 'CT_USP_SITE_ROOT', realpath( CT_USP_ROOT . '..') . DS );

$site_root = CT_USP_UNIFORCE_LITE
? dirname(dirname(realpath( CT_USP_ROOT . '..')))
: realpath( CT_USP_ROOT . '..');

define( 'CT_USP_SITE_ROOT', $site_root . DS );
define( 'CT_USP_LIB', CT_USP_ROOT . 'lib' . DS );
define( 'CT_USP_VIEW', CT_USP_ROOT . DS . 'view' . DS );
define( 'CT_USP_DATA', CT_USP_ROOT . 'data' . DS );
Expand Down
119 changes: 57 additions & 62 deletions uniforce/inc/scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function spbc_scanner_file_send( $file_id = null ){
$decoded_signatures = array();
foreach ($signatures as $signature => $value){
$decoded_signatures[$signature] = $value;
$decoded_signatures[$signature]['body'] = base64_decode($signature['body']);
$decoded_signatures[$signature]['body'] = base64_decode($value['body']);
}
$result_sign = Scanner::file__scan__for_signatures($root_path, $file_info, $decoded_signatures);
if(!empty($result['error'])){
Expand Down Expand Up @@ -425,20 +425,20 @@ function usp_scanner__display(){
}

// Info about last scanning
echo '<p class="spbc_hint text-center">';
if( !$usp->data->stat->scanner->last_scan )
echo uniforce_translate('System hasn\'t been scanned yet. Please, perform the scan to secure the website. ', 'security-malware-firewall');
else{
if ( $usp->data->stat->scanner->last_scan < time() - 86400 * 7 )
echo uniforce_translate('Website hasn\'t been scanned for a long time.', 'security-malware-firewall');
printf(
uniforce_translate('Website last scan was performed on %s, %d files were scanned. ', 'security-malware-firewall'),
date( 'M d Y H:i:s', $usp->data->stat->scanner->last_scan ),
$usp->data->stat->scanner->last_scan_amount
);
echo '<p class="spbc_hint text-center">';
if( !$usp->data->stat->scanner->last_scan )
echo uniforce_translate('System hasn\'t been scanned yet. Please, perform the scan to secure the website. ', 'security-malware-firewall');
else{
if ( $usp->data->stat->scanner->last_scan < time() - 86400 * 7 )
echo uniforce_translate('Website hasn\'t been scanned for a long time.', 'security-malware-firewall');
printf(
uniforce_translate('Website last scan was performed on %s, %d files were scanned. ', 'security-malware-firewall'),
date( 'M d Y H:i:s', $usp->data->stat->scanner->last_scan ),
$usp->data->stat->scanner->last_scan_amount
);

}
echo '</p>';
}
echo '</p>';

//background log layout
$background_log = is_object($usp->data->stat->scanner_background_log) && !empty($usp->data->stat->scanner_background_log->convertToArray())
Expand Down Expand Up @@ -532,7 +532,7 @@ function usp_scanner__display(){
.'<button id="spbc_perform_scan" class="btn btn-setup" type="button">'
.uniforce_translate('Perform scan', 'security-malware-firewall')
.'</button>'
.'<img class="preloader" src="'.CT_USP_URI.'img/preloader.gif" />'
.'<img class="preloader" src="'.CT_USP_URI.'php-usp-For-uniforce-lite/uniforce/img/preloader.gif" />'
.'</div>'
.'<br>';

Expand Down Expand Up @@ -755,29 +755,6 @@ function usp_scanner__display___no_sql(){

$usp = State::getInstance();

// Key is bad
if(!$usp->valid) {

$button = '<input type="button" class="button button-primary" value="' . uniforce_translate( 'To setting', 'security-malware-firewall' ) . '" />';
$link = sprintf(
'<a href="#" onclick="usp_switchTab(\'settings\', {target: \'#ctusp_field---key\', action: \'highlight\', times: 3});">%s</a>',
$button
);
echo '<div style="margin: 10px auto; text-align: center;"><h3 style="margin: 5px; display: inline-block;">' . uniforce_translate( 'Please, enter valid API key.', 'security-malware-firewall' ) . '</h3>' . $link . '</div>';

return;
}

// Key is ok
if ( $usp->valid && ! $usp->moderate ) {

$button = '<input type="button" class="button button-primary" value="' . uniforce_translate( 'RENEW', 'security-malware-firewall' ) . '" />';
$link = sprintf( '<a target="_blank" href="https://cleantalk.org/my/bill/security?cp_mode=security&utm_source=wp-backend&utm_medium=cpc&utm_campaign=WP%%20backend%%20trial_security&user_token=%s">%s</a>', $usp->user_token, $button );
echo '<div style="margin-top: 10px;"><h3 style="margin: 5px; display: inline-block;">' . uniforce_translate( 'Please renew your security license.', 'security-malware-firewall' ) . '</h3>' . $link . '</div>';

return;
}

// Key is ok
if ( ! $usp->settings->scanner_heuristic_analysis && ! $usp->settings->scanner_signature_analysis ) {

Expand All @@ -791,37 +768,55 @@ function usp_scanner__display___no_sql(){
return;
}

// Info about last scanning
echo '<p class="spbc_hint text-center">';
if( !$usp->data->stat->scanner->last_scan )
echo uniforce_translate('System hasn\'t been scanned yet. Please, perform the scan to secure the website. ', 'security-malware-firewall');
else{
if ( $usp->data->stat->scanner->last_scan < time() - 86400 * 7 )
echo uniforce_translate('Website hasn\'t been scanned for a long time.', 'security-malware-firewall');
printf(
uniforce_translate('Website last scan was performed on %s, %d files were scanned. ', 'security-malware-firewall'),
date( 'M d Y H:i:s', $usp->data->stat->scanner->last_scan ),
$usp->data->stat->scanner->last_scan_amount
);

}
echo '</p>';
// Info about last scanning
echo '<div class="spbc_hint text-center">';
if( !$usp->data->stat->scanner->last_scan )
echo uniforce_translate('System hasn\'t been scanned yet. Please, perform the scan to secure the website. ', 'security-malware-firewall');
else{
if ( $usp->data->stat->scanner->last_scan < time() - 86400 * 7 ) {
echo uniforce_translate('Website hasn\'t been scanned for a long time.', 'security-malware-firewall');
}
$scan_results_tmpl = '
Website last scan was performed on %s.
<div class="spbc_scan_results_div">
<p class="spbc_scan_results_item">Total site files<b>*</b> %d, files scanned<b>*</b> %d, suspicious files detected %d
</div>
<div style="text-align: left; font-size: 12px">
<p><b>*</b>Total site files - only executable files (%s) except for the quarantined files, files of zero size and files larger than the acceptable size (2 MB).</p>
<p><b>*</b>Files scanned - files have been checked. Some files will be added to the scan if the scanner deems it necessary.</p>
</div>
';
$total_files_count = !empty($usp->data->stat->scanner->uflite_total_files_count)
? $usp->data->stat->scanner->uflite_total_files_count
: $usp->data->stat->scanner->last_scan_amount;
printf(
$scan_results_tmpl,
date( 'M d Y H:i:s', $usp->data->stat->scanner->last_scan ),
$total_files_count,
max($usp->data->stat->scanner->uflite_files_scanned_signatures, $usp->data->stat->scanner->uflite_files_scanned_heuristics),
$usp->data->stat->scanner->uflite_suspicious_files_detected,
$usp->data->stat->scanner->uflite_file_extensions_applied,
);
}
echo '</div>';

// Statistics link
echo '<p class="spbc_hint text-center">';
echo sprintf(
uniforce_translate('%sView all scan results for this website%s', 'security-malware-firewall'),
'<a target="blank" href="https://cleantalk.org/my/logs_mscan?service='.$usp->service_id . '&user_token='. Cleantalk\USP\Common\State::getInstance()->user_token .'">',
'</a>'
);
echo '</p>';
if ( ! CT_USP_UNIFORCE_LITE ) {
// Statistics link
echo '<p class="spbc_hint text-center">';
echo sprintf(
uniforce_translate('%sView all scan results for this website%s', 'security-malware-firewall'),
'<a target="blank" href="https://cleantalk.org/my/logs_mscan?service='.$usp->service_id . '&user_token='. Cleantalk\USP\Common\State::getInstance()->user_token .'">',
'</a>'
);
echo '</p>';
}

// Start scan button
echo '<div style="text-align: center;">'
.'<button id="spbc_perform_scan" class="btn btn-setup" type="button">'
.uniforce_translate('Perform scan', 'security-malware-firewall')
.'</button>'
.'<img class="preloader" src="'.CT_USP_URI.'img/preloader.gif" />'
.'<img class="preloader" src="'.CT_USP_URI.'php-usp-For-uniforce-lite/uniforce/img/preloader.gif" />'
.'</div>';
echo '<br>';

Expand Down
2 changes: 1 addition & 1 deletion uniforce/inc/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function usp_settings__plugin_state()
if (! empty($usp->plugin_meta->latest_version) ) {
if ( version_compare($usp->plugin_meta->version, $usp->plugin_meta->latest_version) === -1 ) {
echo '<p class="text-center">There is a newer version. Update to the latest ' . $usp->plugin_meta->latest_version . '</p>';
echo '<p class="text-center"><button id="btn-update" form="none" class="btn btn-setup" value="">Update</button><img class="preloader" src="img/preloader.gif"></p>';
echo '<p class="text-center"><button id="btn-update" form="none" class="btn btn-setup" value="">Update</button><img class="preloader" src="php-usp-For-uniforce-lite/uniforce/img/preloader.gif"></p>';
} elseif ( version_compare($usp->plugin_meta->version, $usp->plugin_meta->latest_version) === 1 ) {
echo '<p class="text-center">You are using more than the latest version ' . $usp->plugin_meta->version . ' < ' . $usp->plugin_meta->latest_version . '</p>';
} else {
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.10.0
* Version: 3.11.0
*/
$file_availability = true;
$site_index_file = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '/index.php';
Expand Down
20 changes: 17 additions & 3 deletions uniforce/js/ct_ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ class CTAJAX{
console.log( '%c ' + xhr.responseText, 'color: pink;' );
}else {
var error_string = 'Unexpected error: ' + status;
var do_replace_text = true;
//UFlite
if (
xhr.hasOwnProperty('response_obj') &&
xhr.response_obj.hasOwnProperty('uflite_hrefs') &&
typeof(xhr.response_obj.uflite_hrefs) === 'string'
) {
error_string = '';
$('#error-msg')[0].outerHTML = xhr.response_obj.uflite_hrefs;
do_replace_text = false;
}
//common
if (
xhr.hasOwnProperty('response_obj') &&
xhr.response_obj.hasOwnProperty('additional_html') &&
Expand All @@ -127,7 +139,7 @@ class CTAJAX{
if( typeof error !== 'undefined' ) {
error_string += ' Additional info: ' + error;
}
errorOutput( error_string );
errorOutput( error_string, do_replace_text);
}
}else if(xhr.status === 500){
errorOutput( 'Internal server error.');
Expand All @@ -141,9 +153,11 @@ class CTAJAX{

};

errorOutput( msg ){
errorOutput( msg, replace_text ){
jQuery('.alert-danger').show(300);
jQuery('#error-msg').text( msg );
if (replace_text) {
jQuery('#error-msg').text( msg );
}
};

call(){
Expand Down
7 changes: 7 additions & 0 deletions uniforce/js/scanner-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,13 @@ class spbc_Scanner{
background_scan_stop: true,
};

// Check UniforceLite installer
let uriParams = new URL(document.location.toString()).searchParams;
let uniforceLite = uriParams.get("uniforce_lite");
if ( uniforceLite === '1' ) {
data.uniforce_lite = 1;
}

var params = {
data: data,
type: 'GET',
Expand Down
Loading

0 comments on commit c5318cc

Please sign in to comment.