Skip to content

Commit

Permalink
New. Scan. Added OSCron module.
Browse files Browse the repository at this point in the history
  • Loading branch information
svfcode committed Oct 15, 2024
1 parent 1329b04 commit a30b65e
Show file tree
Hide file tree
Showing 16 changed files with 240 additions and 35 deletions.
138 changes: 138 additions & 0 deletions inc/spbc-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -2905,6 +2905,100 @@ function spbc_field_scanner__prepare_data__analysis_log(&$table)
}
}

/**
* Count found in os cron.
* @return int
*/
function spbc_scanner_oscron_count_found()
{
return count(spbc_scanner_oscron_get_scanned());
}

/**
* Get data for oscron.
* @return array
*/
function spbc_scanner_oscron_get_scanned()
{
$result = get_option('spbc_oscron_result', []);

if (!empty($result)) {
$result = json_decode($result, true);
}

if (is_null($result)) {
$result = [];
}


return $result;
}

/**
* Prepare data for oscron.
* @param $table
*/
function spbc_scanner_oscron_prepare_data(&$table)
{
foreach ($table->rows as $key => $row) {
$table->items[$key] = array(
'uid' => $row['id'],
'cb' => $row['id'],
'id' => $row['id'],
'repeat' => spbc_scanner_oscron_time_to_human_readable($row['repeat']),
'command' => $row['command'],
// 'actions' => $row['actions'],
);
}
}

/**
* Convert cron time to human readable.
* @param $time
* @return string
*/
function spbc_scanner_oscron_time_to_human_readable($time)
{
$cronParts = explode(' ', $time);

if (count($cronParts) !== 5) {
return __('Invalid cron expression', 'security-malware-firewall');
}

list($minute, $hour, $dayOfMonth, $month, $dayOfWeek) = $cronParts;

$humanReadable = __('At ', 'security-malware-firewall');

// Handle minutes
if ($minute === '*') {
$humanReadable .= __('every minute', 'security-malware-firewall');
} else {
$humanReadable .= __('minute', 'security-malware-firewall') . ' ' . $minute;
}

// Handle hours
if ($hour !== '*') {
$humanReadable .= __(' past hour ', 'security-malware-firewall') . $hour;
}

// Handle days of the month
if ($dayOfMonth !== '*') {
$humanReadable .= __(' on day ', 'security-malware-firewall') . $dayOfMonth;
}

// Handle months
if ($month !== '*') {
$humanReadable .= __(' of month ', 'security-malware-firewall') . $month;
}

// Handle days of the week
if ($dayOfWeek !== '*') {
$humanReadable .= __(' on day of the week ', 'security-malware-firewall') . $dayOfWeek;
}

return $humanReadable;
}

function spbc_field_scanner__prepare_data__files_quarantine(&$table)
{
global $spbc;
Expand Down Expand Up @@ -3265,6 +3359,10 @@ function spbc_field_scanner()
echo '<span class="spbc_overall_scan_status_auto_cure">' . __('Curing', 'security-malware-firewall') . '</span> -> ';
}

if ($spbc->settings['scanner__os_cron_analysis']) {
echo '<span class="spbc_overall_scan_status_os_cron_analysis">' . __('OS Cron Analysis', 'security-malware-firewall') . '</span> -> ';
}

if ($spbc->settings['scanner__outbound_links']) {
echo '<span class="spbc_overall_scan_status_outbound_links">' . __('Scanning links', 'security-malware-firewall') . '</span> -> ';
}
Expand Down Expand Up @@ -3480,6 +3578,10 @@ function spbc_field_scanner__show_accordion($direct_call = false)
$tables_files['unknown'] = $unknown_files_description;
}

if ($spbc->settings['scanner__os_cron_analysis']) {
$tables_files['oscron'] = __('OS Cron Analysis', 'security-malware-firewall');
}

if ($spbc->settings['scanner__list_approved_by_cleantalk']) {
$tables_files['approved_by_cloud'] = __('Approved by CleanTalk Team or Clout files list. To disable this list view, please disable the `Show approved by CleanTalk Cloud` option.', 'security-malware-firewall');
}
Expand Down Expand Up @@ -3522,6 +3624,15 @@ function spbc_field_scanner__show_accordion($direct_call = false)
'files_listing',
),
),
'os_cron_analysis' => array(
'category_description' => __('OS Cron Analysis', 'security-malware-firewall'),
'types' => array(
'oscron',
'oscron_quarantined',
'oscron_approved',
),
'display' => true
),
'pages' => array(
'category_description' => __('Pages scan results', 'security-malware-firewall'),
'types' => array(
Expand Down Expand Up @@ -3999,6 +4110,33 @@ function spbc_list_table__get_args_by_type($table_type)
$args['actions']['send'] = array('name' => 'Send for Analysis',);
break;

case 'oscron':
$args = array_replace_recursive(
array(
'func_data_total' => 'spbc_scanner_oscron_count_found',
'func_data_get' => 'spbc_scanner_oscron_get_scanned',
'func_data_prepare' => 'spbc_scanner_oscron_prepare_data',
'if_empty_items' => '<p class="spbc_hint">' . __('Crontab not found.', 'security-malware-firewall') . '</p>',
'columns' => array(
'cb' => array('heading' => '<input type=checkbox>', 'class' => 'check-column', 'width_percent' => 5),
'id' => array('heading' => 'id', 'primary' => true, 'width_percent' => 15),
'repeat' => array('heading' => 'repeat', 'primary' => true, 'width_percent' => 15),
'command' => array('heading' => 'command', 'primary' => true, 'width_percent' => 65),
),
'actions' => array(
'delete' => array('name' => 'Delete',),
'quarantine' => array('name' => 'Quarantine',),
'approve' => array('name' => 'Approve',),
),
'bulk_actions' => array(
'delete' => array('name' => 'Delete',),
'quarantine' => array('name' => 'Quarantine',),
'approve' => array('name' => 'Approve',),
),
)
);
break;

case 'approved':
$args = array_replace_recursive(
$accordion_default_args,
Expand Down
2 changes: 1 addition & 1 deletion js/spbc-common.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a30b65e

Please sign in to comment.