Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/fix' into dev
Browse files Browse the repository at this point in the history
# Conflicts:
#	security-malware-firewall.php
  • Loading branch information
Glomberg committed Oct 10, 2024
2 parents e5f72ae + 538a014 commit 9ad3568
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 12 deletions.
50 changes: 47 additions & 3 deletions inc/spbc-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -4596,7 +4596,11 @@ function spbc_sanitize_settings($settings)
}

// Scanner custom start time logic
if ( empty($spbc->errors['configuration']) && $spbc->settings['scanner__auto_start_manual_time']) {
if (
empty($spbc->errors['configuration']) &&
$settings['scanner__auto_start_manual_time'] &&
$settings['scanner__auto_start_manual_time'] != $spbc->settings['scanner__auto_start_manual_time']
) {
//if ( empty($spbc->errors['configuration']) ) {
$scanner_launch_data = spbc_get_custom_scanner_launch_data(false, $settings);
\CleantalkSP\SpbctWP\Cron::updateTask(
Expand Down Expand Up @@ -5220,6 +5224,10 @@ function spbc_settings__get_description()
'title' => IP::getOptionLongDescriptionArray()['title'],
'desc' => IP::getOptionLongDescriptionArray()['desc'],
),
'sending_for_analysis_rules' => array(
'title' => 'Sending for cloud analysis',
'desc' => spbc__get_accordion_tab_info_block_html('sending_for_analysis_rules'),
),
'no_description' => array(
'title' => esc_html($setting_id),
'desc' => __('No description provided yet for this item. We are sorry about this. Please, contact [email protected] for further help.', 'security-malware-firewall'),
Expand Down Expand Up @@ -5736,7 +5744,7 @@ function spbc_get_next_scan_launch_time_text()
) {
return sprintf(
' ' . __('The next automatic scan is scheduled on %s %s.', 'security-malware-firewall'),
date('M d Y H:i:s', $task['next_call']),
date('M d Y H:i:s', $task['next_call'] + ((float)get_option('gmt_offset') * 3600)),
spbc_wp_timezone_string()
);
}
Expand Down Expand Up @@ -5828,7 +5836,7 @@ function spbc__get_accordion_tab_info_block_html($for)
%MAIN_TEXT%
<ul style="list-style-type: circle; padding-left: 2%">
<li>%OPTION_1%</li>
<li>%OPTION_2%</li>
<li>%OPTION_2%<i setting="sending_for_analysis_rules" class="spbc_long_description__show spbc-icon-help-circled"></i></li>
</ul>
</div>
';
Expand All @@ -5846,6 +5854,42 @@ function spbc__get_accordion_tab_info_block_html($for)
$info_block_out = $template;
$classes = 'notice notice-info';
break;
case 'sending_for_analysis_rules':
$template = '
<div>
<p>%MAIN_TEXT_1%</p>
<p>%MAIN_TEXT_2%</p>
<ul style="list-style-type: disc; padding-left: 5%">
<li>%OPTION_1%</li>
<li>%OPTION_2%</li>
<li>%OPTION_3%</li>
</ul>
<p>%MAIN_TEXT_3%</p>
<ul style="list-style-type: disc; padding-left: 5%">
<li>%OPTION_4%</li>
</ul>
<p>%MAIN_TEXT_4%</p>
</div>
';
$main_text_1 = __('Send the file for cloud analysis. After the file is sent, the file is available in the tab "Analysis log". Read more about analysis results in the appropriate tab. ', 'security-malware-firewall');
$main_text_2 = __('The file sent for analysis must meet the following requirements:', 'security-malware-firewall');
$main_text_3 = __('For "Unknown" files category, file extension should be from the list of allowed extensions:', 'security-malware-firewall');
$main_text_4 = __('If any of requirements are not met, the action for file is not available.', 'security-malware-firewall');
$option1 = __('the file was not ever denied or approved by CleanTalk team', 'security-malware-firewall');
$option2 = __('the file sending is not already scheduled during common scan process', 'security-malware-firewall');
$option3 = __('the file size is larger than zero and less than 1Mb', 'security-malware-firewall');
$option4 = __('.php*, .html, .htm, .phtml, shtml, .phar, .odf', 'security-malware-firewall');
$template = str_replace('%MAIN_TEXT_1%', $main_text_1, $template);
$template = str_replace('%MAIN_TEXT_2%', $main_text_2, $template);
$template = str_replace('%MAIN_TEXT_3%', $main_text_3, $template);
$template = str_replace('%MAIN_TEXT_4%', $main_text_4, $template);
$template = str_replace('%OPTION_1%', $option1, $template);
$template = str_replace('%OPTION_2%', $option2, $template);
$template = str_replace('%OPTION_3%', $option3, $template);
$template = str_replace('%OPTION_4%', $option4, $template);
$info_block_out = Escape::escKsesPreset($template, 'spbc_settings__sending_for_analysis_rules');
$classes = '';
break;
case 'skipped':
$template = '
<div>
Expand Down
17 changes: 10 additions & 7 deletions inc/spbc-tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,16 +509,19 @@ function spbc_get_custom_scanner_launch_data($first_start = false, $settings = a
$period = $first_start ? 43200 : 86400;

$settings = empty($settings) ? $spbc->settings : $settings;
$period = $settings['scanner__auto_start__set_period'] ?: $period;
$period = (int)$settings['scanner__auto_start__set_period'] ?: $period;

$timezone = $settings['scanner__auto_start_manual_tz'] ?: (int) Post::get('spbc_settings[scanner__auto_start_manual_tz]');
// this is a shift in seconds to adjust the time, provided only for cases when the start time is customized
$timezone_shift = 0;

$hour_minutes = $settings['scanner__auto_start_manual_time']
? explode(':', $settings['scanner__auto_start_manual_time'])
: explode(':', (string)current_time('H:i'));
$start_time = mktime((int)$hour_minutes[0], (int)$hour_minutes[1]) - $timezone * 3600 + $period;
if ($settings['scanner__auto_start_manual_time']) {
$hour_minutes = explode(':', (string)$settings['scanner__auto_start_manual_time']);
$timezone_shift = $spbc->data['site_utc_offset_in_seconds'] ?: 0;
} else {
$hour_minutes = explode(':', date('H:i'));
}

// Hard fix - increments one more $period if the $start_time calculated in the past
$start_time = mktime((int)$hour_minutes[0], (int)$hour_minutes[1]) - $timezone_shift + $period;
if ( time() > $start_time ) {
$start_time += $period;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/CleantalkSP/Common/DNS.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static function getResponseTime($host)
{
// Skip localhost ping cause it raise error at fsockopen.
// And return minimum value
if ($host === 'localhost') {
if ($host === 'localhost' || !function_exists('fsockopen')) {
return 0.001;
}

Expand Down
4 changes: 4 additions & 0 deletions lib/CleantalkSP/Common/Helpers/HTTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ public static function sortHostsByResponseTime($hosts)
*/
public static function ping($host)
{
if ($host === 'localhost' || !function_exists('fsockopen')) {
return 0.001;
}

$starttime = microtime(true);
$file = @fsockopen($host, 80, $errno, $errstr, 1500 / 1000);
$stoptime = microtime(true);
Expand Down
8 changes: 8 additions & 0 deletions lib/CleantalkSP/SpbctWP/Escape.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ public static function escKsesPreset($string, $preset = null, $_allowed_protocol
'alt' => true,
'style' => true,
),
),
'spbc_settings__sending_for_analysis_rules' => array(
'div' => array(),
'p' => array(),
'li' => array(),
'ul' => array(
'style' => true,
),
)
);

Expand Down
5 changes: 4 additions & 1 deletion security-malware-firewall.php
Original file line number Diff line number Diff line change
Expand Up @@ -1926,7 +1926,10 @@ function spbc_check_account_status($api_key)
}

// Disable/enable the collecting backend PHP log depends on the extra package data
$spbc->settings['misc__backend_logs_enable'] = (int) $spbc->data['extra_package']['backend_logs'];
$spbc->settings['misc__backend_logs_enable'] = (int)(
$spbc->data['extra_package']['backend_logs'] == 1 &&
$spbc->settings['misc__backend_logs_enable'] == 1
);
$spbc->save('settings');
$spbc->save('data');

Expand Down

0 comments on commit 9ad3568

Please sign in to comment.