Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty key actions #242

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions inc/spbc-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -4005,6 +4005,12 @@ function spbc_sanitize_settings($settings)
$settings['spbc_key'] = is_main_site() || $spbc->ms__work_mode != 2 ? $settings['spbc_key'] : $spbc->network_settings['spbc_key'];
$spbc->data['key_changed'] = $settings['spbc_key'] !== $spbc->settings['spbc_key'];
$spbc->data['key_is_ok'] = spbc_api_key__is_correct($settings['spbc_key']);

if ($settings['spbc_key'] === '' && $spbc->data['key_changed']) {
$spbc = spbc_drop_to_defaults_on_key_clearance($spbc);
\CleantalkSP\SpbctWP\Cron::removeAllTasks();
}

$spbc->save('data');

if ($spbc->is_network && $spbc->is_mainsite) {
Expand Down Expand Up @@ -5083,3 +5089,33 @@ function spbc__check_if_manual_analysis_results_exist()
"SELECT COUNT(*) FROM " . SPBC_TBL_SCAN_FILES . " WHERE analysis_status IS NOT NULL;"
);
}

/**
* Drop current data to defaults from state->default_data.
* On exceptions roll back to old current state.
* Attention! This function does not save the state to options,
* only the current state object will be handled.
* @param \CleantalkSP\SpbctWP\State $spbc current state
* @return \CleantalkSP\SpbctWP\State state dropped
*/
function spbc_drop_to_defaults_on_key_clearance(\CleantalkSP\SpbctWP\State $spbc)
{
$old_data = $spbc->data;
try {
$keep_data_keys = array(
'scanner',
'display_scanner_warnings',
'errors'
);
$spbc->error_delete_all(true);
foreach ( $spbc->default_data as $key => $value) {
if (!in_array($key, $keep_data_keys)) {
$spbc->data[$key] = $value;
}
}
} catch (Exception $e) {
$spbc->data = $old_data;
}

return $spbc;
}
9 changes: 9 additions & 0 deletions lib/CleantalkSP/SpbctWP/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,13 @@ public static function updateTask($task, $handler, $period, $first_call = null,

return self::addTask($task, $handler, $period, $first_call, $params);
}

/**
* Delete all the cron tasks.
* @return void
*/
public static function removeAllTasks()
{
update_option(self::CRON_OPTION_NAME, array());
}
}
7 changes: 6 additions & 1 deletion security-malware-firewall.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,12 @@
spbc_firewall__check();
}
} elseif ( isset($spbc->errors) && ! isset($spbc->errors['apikey']) ) {
$spbc->error_add('apikey', __('Unknown access key.', 'security-malware-firewall'));
if ($spbc->settings['spbc_key'] === '') {
$text = __('Access key is empty.', 'security-malware-firewall');
} else {
$text = __('Unknown access key.', 'security-malware-firewall');
}
$spbc->error_add('apikey', $text);
}

// Disable XMLRPC if setting is enabled
Expand Down
Loading