Skip to content

Commit

Permalink
Merge pull request #457 from CleanTalk/сure_bulk_fixed.ag
Browse files Browse the repository at this point in the history
Cure improvements
  • Loading branch information
alexandergull authored Dec 26, 2024
2 parents 8c26f08 + 4c7f9f0 commit 0bed380
Show file tree
Hide file tree
Showing 14 changed files with 448 additions and 209 deletions.
2 changes: 1 addition & 1 deletion css/spbc-settings.min.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions css/src/spbc-settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

.spbc---gray{color: gray;}
.spbc---red{color: red;}
.spbc---green{color: #037603;}

.spbc_bold{font-weight: 800;}

Expand Down
20 changes: 10 additions & 10 deletions inc/spbc-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -4407,11 +4407,11 @@ function spbc_list_table__get_args_by_type($table_type)
'if_empty_items' => __('There are no automatically cured files.', 'security-malware-firewall'),
'columns' => array(
'cb' => array('heading' => '<input type=checkbox>', 'class' => 'check-column', 'width_percent' => 2),
'real_path' => array('heading' => 'Path','primary' => true,),
'last_cure_date' => array('heading' => 'Cure date',),
'cured' => array('heading' => 'Status',),
'cci_cured' => array('heading' => 'Threats cured count',),
'fail_reason' => array('heading' => 'Reason of fail',),
'real_path' => array('heading' => 'Path','primary' => true, 'width_percent' => 27),
'last_cure_date' => array('heading' => 'Cure date', 'width_percent' => 10),
'cured' => array('heading' => 'Status', 'width_percent' => 13),
'weak_spots_cured' => array('heading' => 'Threats cured', 'width_percent' => 24),
'weak_spots_uncured' => array('heading' => 'Threats uncured', 'width_percent' => 24),
),
'order_by' => array('real_path' => 'asc'),
'pagination' => array(
Expand All @@ -4422,7 +4422,7 @@ function spbc_list_table__get_args_by_type($table_type)

$cure_log = new Scanner\CureLog\CureLog();
if ( !$cure_log->hasFailedCureTries() ) {
unset($args['columns']['fail_reason']);
unset($args['columns']['weak_spots_uncured']);
}
break;
case 'skipped':
Expand Down Expand Up @@ -5785,7 +5785,7 @@ function spbc_scanner__cure_log_data_prepare(&$table)
if ($table->items_count) {
foreach ($table->rows as $_key => $row) {
// Add Cure action if file was not cure
if ($row->cured !== 'FAILED') {
if ($row->cured === 'CURED') {
unset($row->actions['cure']);
}

Expand All @@ -5799,9 +5799,9 @@ function spbc_scanner__cure_log_data_prepare(&$table)
'actions' => $row->actions,
'real_path' => $row->real_path,
'last_cure_date' => $row->last_cure_date,
'cured' => $cure_status_string,
'cci_cured' => $row->cci_cured,
'fail_reason' => $row->fail_reason,
'cured' => $cure_status_string,
'weak_spots_cured' => $row->weak_spots_cured,
'weak_spots_uncured' => $row->weak_spots_uncured,
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion js/spbc-table.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/spbc-table.min.js.map

Large diffs are not rendered by default.

54 changes: 45 additions & 9 deletions js/src/spbc-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,12 @@ function spbcTblBulkActionsListen() {
status: self.parents('.tbl-root').attr('type'),
};

if (action === 'cure' || action === 'restore') {
if (action === 'cure') {
spbcScannerCureBulk(self, true);
return;
}

if (action === 'restore') {
const selectedItems = self.closest('#spbc_tbl__scanner_cure_log').find('.cb-select');
let selectedIds = [];

Expand Down Expand Up @@ -198,7 +203,7 @@ function spbcTblBulkActionsListen() {
}

if (action === 'cure') {
spbcScannerCureSelected(jQuery(this));
spbcScannerCureBulk(jQuery(this), false);
return;
}

Expand Down Expand Up @@ -274,13 +279,16 @@ function spbcTblBulkActionsListen() {
/**
* Cure selected files
* @param {obj} current
* @param {boolean} allItems
*/
function spbcScannerCureSelected(current) {
const selectedItems = current.closest('#spbc_tbl__scanner_cure_log').find('.cb-select:checked');
function spbcScannerCureBulk(current, allItems = false) {
let selectedIds = [];
const selector = allItems ? '.cb-select' : '.cb-select:checked';
const selectedItems = current.closest('#spbc_tbl__scanner_cure_log').find(selector);

if (selectedItems.length === 0) {
alert('Please, select elements.');
return;
}

selectedItems.each(function(index, element) {
Expand Down Expand Up @@ -308,14 +316,42 @@ function spbcScannerCureSelected(current) {
.closest('#spbc_tbl__scanner_cure_log')
.find('.tbl-button---white_blue .tbl-preloader--in_button')
.hide();
const displayData = result.data;
// prepare output
let divWrapper = document.createElement('div');
let pMessage = document.createElement('p');
let pCounters = document.createElement('p');
let divFiles = document.createElement('div');
const failedToCure = displayData.hasOwnProperty('failed_to_cure') ? displayData.failed_to_cure : [];
if (failedToCure.length > 0) {
divFiles.innerHTML = failedToCure.join('</br>');
}
pMessage.innerHTML = displayData.message;
pCounters.innerHTML += 'Cured: ' +
(
displayData.hasOwnProperty('cured_on_request') ?
displayData.cured_on_request :
0
);
pCounters.innerHTML += ', already cured: ' +
(
displayData.hasOwnProperty('skipped') ?
displayData.skipped :
0
);
pCounters.innerHTML += ', failed to cure: ' + failedToCure.length;

divWrapper.append(pMessage);
divWrapper.append(pCounters);
divWrapper.append(divFiles);
if (result.success) {
spbcModal.open().put(result.data);
document.addEventListener('spbcModalClosed', function( e ) {
document.location.reload();
});
spbcModal.open().put(divWrapper.outerHTML);
} else {
spbcModal.open().putError(result.data);
spbcModal.open().putError(divWrapper.outerHTML);
}
document.addEventListener('spbcModalClosed', function( e ) {
spbcReloadAccordion();
});
},
});
}
Expand Down
9 changes: 5 additions & 4 deletions lib/CleantalkSP/Common/Helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,23 @@ public static function isRegexp($signature, $delimiters = '#/')
* @param string $signature_body Character position
* @param bool $is_regexp Flag. Is signature is regular expression?
*
* @return int String number
* @return array Array of lines number with needle
*/
public static function getNeedleStringNumberFromFile($file_path, $signature_body, $is_regexp = false)
public static function getNeedleStringsNumberFromFile($file_path, $signature_body, $is_regexp = false)
{
$file = file($file_path);
$out = 1;
$out_line_numbers = array();

foreach ( $file as $number => $line ) {
if (
($is_regexp && preg_match($signature_body, $line)) ||
( ! $is_regexp && strripos($line, stripslashes($signature_body)) !== false)
) {
$out = $number + 1;
$out_line_numbers[] = $out;
}
}

return $out;
return $out_line_numbers;
}
}
14 changes: 10 additions & 4 deletions lib/CleantalkSP/Common/Scanner/SignaturesAnalyser/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,20 @@ function_exists('md5') &&
if (
( $is_regexp && preg_match($signature['body'], $file_content) ) ||
( ! $is_regexp &&
( strripos($file_content, stripslashes($signature['body'])) !== false ||
strripos($file_content, $signature['body']) !== false) )
(
strripos($file_content, stripslashes($signature['body'])) !== false ||
strripos($file_content, $signature['body']) !== false
)
)
) {
$line_number = Helper::getNeedleStringNumberFromFile(
$line_numbers = Helper::getNeedleStringsNumberFromFile(
$root_path . $file_info->path,
$signature['body'],
$is_regexp
);
$verdict['SIGNATURES'][$line_number][] = $signature['id'];
foreach ($line_numbers as $line_number) {
$verdict['SIGNATURES'][$line_number][] = $signature['id'];
}
}
}
}
Expand All @@ -109,6 +114,7 @@ function_exists('md5') &&
$file_info->weak_spots,
true
) : array();

if ( isset($file_info->weak_spots['SIGNATURES']) ) {
unset($file_info->weak_spots['SIGNATURES']);
}
Expand Down
3 changes: 3 additions & 0 deletions lib/CleantalkSP/SpbctWP/DB/SQLSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,11 @@ class SQLSchema extends \CleantalkSP\Common\DB\SQLSchema
'columns' => array(
array('field' => 'fast_hash', 'type' => 'varchar(32)', 'null' => 'no'),
array('field' => 'full_hash', 'type' => 'char(32)', 'null' => 'no'),
array('field' => 'cured_hash', 'type' => 'char(32)', 'null' => 'no'),
array('field' => 'real_path', 'type' => 'varchar(512)', 'null' => 'no'),
array('field' => 'cured', 'type' => 'tinyint', 'null' => 'no',),
array('field' => 'weak_spots_cured', 'type' => 'varchar(512)', 'null' => 'no',),
array('field' => 'weak_spots_uncured', 'type' => 'varchar(512)', 'null' => 'no',),
array('field' => 'has_backup', 'type' => 'tinyint', 'null' => 'no',),
array('field' => 'cci_cured', 'type' => 'tinyint', 'null' => 'yes', 'default' => 'NULL'),
array('field' => 'fail_reason', 'type' => 'varchar(512)', 'null' => 'yes', 'default' => 'NULL'),
Expand Down
3 changes: 2 additions & 1 deletion lib/CleantalkSP/SpbctWP/ListTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,8 @@ public static function ajaxBulkActionHandler()
$out = spbc_scanner_pscan_check_analysis_status(true, $ids);
break;
case 'cure':
$out = Cure::cureAll($_POST['selectedIds']);
//this method has own ajax handler
Cure::cureSelectedAction();
break;
case 'restore':
$out = Cure::restoreSelectedAction();
Expand Down
Loading

0 comments on commit 0bed380

Please sign in to comment.