Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c15ace0
TEMPORARY commit
Glomberg Oct 4, 2024
8133526
Merge remote-tracking branch 'origin/dev' into New-React-Structure
Glomberg Oct 14, 2024
f4b56a9
React components rebuilding...
Glomberg Oct 17, 2024
19b12bb
Tabs layout started.
Glomberg Oct 21, 2024
10d208a
Merge remote-tracking branch 'origin/dev' into New-React-Structure
Glomberg Oct 21, 2024
c69e63a
Tabs sections layout started.
Glomberg Oct 23, 2024
08f5a93
Tabs sections layout getting content.
Glomberg Oct 23, 2024
e8a1135
Sections and Tabs fixed.
Glomberg Oct 25, 2024
b42e77b
Merge remote-tracking branch 'origin/dev' into New-React-Structure
Glomberg Oct 26, 2024
e0dc147
Fix. API example provided.
Glomberg Oct 26, 2024
1d87f51
Merge remote-tracking branch 'origin/dev' into New-React-Structure
Glomberg Oct 28, 2024
244a540
First try to implement tables.
Glomberg Oct 30, 2024
dddc0c9
Upd. Table component implemented.
Glomberg Oct 31, 2024
c138c6c
Merge branch 'refs/heads/New-React-Structure' into new_react_structrue
alexandergull Mar 28, 2025
61a42b6
Code. React. Sync button updates.
alexandergull Apr 8, 2025
d3bcb97
Code. React. PNG added.
alexandergull Apr 21, 2025
8fa7a3b
Code. React. Debug removed.
alexandergull Apr 21, 2025
bda2156
Mod. React. Combining project structures
AntonV1211 Apr 22, 2025
e06a149
Mod. React. Combining project structures
AntonV1211 Apr 22, 2025
db7eb86
Merge branch 'dev' of https://github.com/CleanTalk/security-malware-f…
AntonV1211 Apr 22, 2025
74eb102
Mod. React. Combining project structures
AntonV1211 Apr 22, 2025
f6a7668
Merge branch 'dev' of https://github.com/CleanTalk/security-malware-f…
AntonV1211 Apr 29, 2025
f698c81
Fix. Code. Editing the Texdomain error
AntonV1211 Apr 29, 2025
5d36403
Mod. ReactApp. Changing the App class to a function
AntonV1211 Apr 30, 2025
1bb7f87
Fix. SettingsReact. Edits for psalm errors
AntonV1211 Apr 30, 2025
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
7 changes: 7 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This is a sample .env file for Jest configuration.
JEST_VAR__APP_ROOT="" # URL to the WordPress admin page, example: "https://your-domain/wp-admin/options-general.php"
JEST_VAR__WP_LOGIN="" # WordPress admin username
JEST_VAR__WP_PASSWORD="" # WordPress admin password
JEST_VAR__CHROME_EXECUTABLE="" # Path to the Chrome executable, example: "C:\Program Files\Google\Chrome\Application\chrome.exe"
JEST_VAR__CHROME_SET_UA="" # User-Agent string to set for the browser, example: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
JEST_VAR__HEADLESS="" # Set to "1" for headless mode, "0" for normal mode
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ backups
composer.lock
psalm.xml
.editorconfig
.env
/lib/CleantalkSP/Common/Scanner/HeuristicAnalyser/tests/
/lib/CleantalkSP/Common/Scanner/SignaturesAnalyser/tests/
/lib/CleantalkSP/Common/Scanner/SignaturesAnalyser/.github/
Expand Down
75 changes: 75 additions & 0 deletions inc/settings-react/spbct-settings-react.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

require_once 'spbct-sync-react.php';

function spbc_admin_add_react_page()
{
add_options_page(
__(' Settings via React', 'security-malware-firewall'),
'SPBC Settings via React',
'manage_options',
'spbct',
function () {
echo "<div id='spbct_root'
data-nonce='" . esc_attr(wp_create_nonce('spbc_secret_nonce')) . "'
data-ajaxurl='" . esc_attr(admin_url('admin-ajax.php')) . "'
></div>";
}
);
}

add_action('wp_ajax_spbct_get_tab_data', 'spbct_get_tab_data');
function spbct_get_tab_data()
{
spbc_check_ajax_referer('spbc_secret_nonce', 'security');

$tab_name = sanitize_text_field($_POST['tab_name']);
$function_name = "spbct_get_tab_data_{$tab_name}";

if ( function_exists($function_name) ) {
$res = $function_name();
} else {
$res = [
'request_malware_removal' => false,
'data_type' => 'text',
'data' => $tab_name,
'tab_settings' => []
];
}

wp_send_json($res);
}
function spbct_get_tab_data_firewall()
{
global $wpdb, $spbc;
$request_per = isset($spbc->settings['traffic_control__autoblock_timeframe'])
? (int)$spbc->settings['traffic_control__autoblock_timeframe'] / 60
: 5;
$columns = [
'ip_entry' => esc_html__('IP', 'security-malware-firewall'),
'country_code' => esc_html__('Country', 'security-malware-firewall'),
'entry_timestamp' => esc_html__('Last Request', 'security-malware-firewall'),
'status' => esc_html__('Status', 'security-malware-firewall'),
'requests' => esc_html__('Requests and attempts', 'security-malware-firewall'),
'requests_per' => sprintf(esc_html__('Requests per %s minutes', 'security-malware-firewall'), $request_per),
'page_url' => esc_html__('Page', 'security-malware-firewall'),
'http_user_agent' => esc_html__('User Agent', 'security-malware-firewall')
];
$query = 'SELECT ' . trim(implode(',', array_keys($columns)), ',')
. ' FROM ' . SPBC_TBL_FIREWALL_LOG
. ' ORDER BY entry_timestamp desc '
. ' LIMIT %d ';
$prepared_query = $wpdb->prepare($query, [SPBC_LAST_ACTIONS_TO_VIEW]);
$results = $wpdb->get_results($prepared_query);
$table_data = [
'columns' => $columns,
'rows' => $results
];
$output = [
'request_malware_removal' => false,
'data_type' => 'table',
'data' => $table_data,
'tab_settings' => [],
];
return $output;
}
180 changes: 180 additions & 0 deletions inc/settings-react/spbct-sync-react.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
<?php

use CleantalkSP\SpbctWP\AdjustToEnvironmentModule\AdjustToEnvironmentHandler;

add_action('wp_ajax_spbc_react_access_key_check', 'spbc_react_access_key_check');
add_action('wp_ajax_spbc_react_secfw_update_init', 'spbc_react_secfw_update_init');
add_action('wp_ajax_spbc_react_settings_exclusions', 'spbc_react_settings_exclusions');
add_action('wp_ajax_spbc_react_run_ajusting_env', 'spbc_react_run_ajusting_env');
add_action('wp_ajax_spbc_react_signatures_update', 'spbc_react_signatures_update');
add_action('wp_ajax_spbc_react_run_vulnerability_check', 'spbc_react_run_vulnerability_check');

function spbc_react_access_key_check()
{
global $spbc;
spbc_check_ajax_referer('spbc_secret_nonce', 'security');

//Clearing all errors
$spbc->error_delete_all('and_save_data');

$account_is_ok = false;

// If key provided by super admin
if ( $spbc->is_mainsite || $spbc->ms__work_mode != 2 ) {
// Checking account status
$account_is_ok = spbc_check_account_status($spbc->api_key);
}

/*$out = array(
'success' => true,
'reload' => $spbc->data['key_changed'] || !empty($spbc->errors),
);*/

$spbc->data['key_changed'] = false;
$spbc->save('data');

$res = [
'error' => false,
'message' => 'Test message',
'success' => $account_is_ok,
];

wp_send_json($res);
}

function spbc_react_secfw_update_init()
{
global $spbc;

spbc_check_ajax_referer('spbc_secret_nonce', 'security');

$result = spbc_send_logs($spbc->api_key);
if ( empty($result['error']) ) {
$spbc->data['logs_last_sent'] = current_time('timestamp');
$spbc->data['last_sent_events_count'] = $result;
$spbc->error_delete('send_logs');
} else {
$spbc->error_add('send_logs', $result);
}

// Sending FW logs
$result = spbc_send_firewall_logs($spbc->api_key);
if ( empty($result['error']) ) {
$spbc->fw_stats['last_send'] = current_time('timestamp');
$spbc->fw_stats['last_send_count'] = $result;
$spbc->error_delete('send_firewall_logs');
} else {
$spbc->error_add('send_firewall_logs', $result);
}

// Get custom message for security firewall
$result_service_get = spbct_perform_service_get();
if ( ! empty($result_service_get['error']) ) {
if ($result_service_get['error_no'] !== 403) {
$spbc->error_add('service_customize', $result_service_get['error']);
}
}

// Updating FW
//Reset last call of update_sec_fw
$spbc->remote_calls['update_security_firewall']['last_call'] = 0;
$spbc->save('remote_calls', true, false);

$result = spbc_security_firewall_update__init();

if ( ! empty($result['error']) ) {
$spbc->error_add('firewall_update', $result['error']);
}

$spbc->save('data');
$spbc->save('fw_stats', true, false);

$res = [
'error' => false,
'message' => 'Test message',
'success' => true,
];

wp_send_json($res);
}

function spbc_react_signatures_update()
{
global $spbc;

spbc_check_ajax_referer('spbc_secret_nonce', 'security');

// If key provided by super admin
if ( is_main_site() ) {
// Updating signtaures
$result = spbc_scanner__signatures_update();
empty($result['error'])
? $spbc->error_delete('scanner_update_signatures', 'save')
: $spbc->error_add('scanner_update_signatures', $result);
}

$res = [
'error' => false,
'message' => 'Test message',
'success' => true,
];

wp_send_json($res);
}

function spbc_react_settings_exclusions()
{
global $spbc;

spbc_check_ajax_referer('spbc_secret_nonce', 'security');

// Update scan settings exclusions
$result_update_exclusions = spbc_update_scan_settings_exclusions();

\CleantalkSP\SpbctWP\Cron::updateTask('update_scan_settings_exclusions', 'spbc_update_scan_settings_exclusions', 86400);
if ( ! empty($result_update_exclusions['error']) ) {
$spbc->error_add('update_exclusions', $result_update_exclusions['error']);
}


$res = [
'error' => false,
'message' => 'Test message',
'success' => true,
];

wp_send_json($res);
}

function spbc_react_run_ajusting_env()
{
spbc_check_ajax_referer('spbc_secret_nonce', 'security');

// Try to adjust to environment
$adjust = new AdjustToEnvironmentHandler();
$adjust->handle();

$res = [
'error' => false,
'message' => 'Test message',
'success' => true,
];

wp_send_json($res);
}

function spbc_react_run_vulnerability_check()
{
spbc_check_ajax_referer('spbc_secret_nonce', 'security');

// Set cron task calling right now
\CleantalkSP\SpbctWP\Cron::updateTask('check_vulnerabilities', 'spbc_security_check_vulnerabilities', 86400, time());

$res = [
'error' => false,
'message' => 'Test message',
'success' => true,
];

wp_send_json($res);
}
9 changes: 7 additions & 2 deletions inc/spbc-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -1303,9 +1303,14 @@ function spbc_settings__draw_elements($elems_to_draw = null, $direct_call = fals
if ( ! $direct_call && Post::getString('security')) {
spbc_settings__register();
spbc_check_ajax_referer('spbc_secret_nonce', 'security');
if (Post::getString('tab_name')) {
if (Post::get('tab_name')) {
if ( $_POST['tab_name'] === 'firewall' ) {
$tab_name = 'traffic_control';
} else {
$tab_name = $_POST['tab_name'];
}
/** @psalm-suppress InvalidArrayOffset */
$elems_to_draw = array($_POST['tab_name'] => $spbc->settings__elements[ Post::getString('tab_name') ]);
$elems_to_draw = array($tab_name => $spbc->settings__elements[$tab_name]);
}
}

Expand Down
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading