Skip to content

Commit 7bc9f30

Browse files
authored
Merge pull request #506 from CleanTalk/New-React-Structure
New react structure
2 parents 1a20b2c + 1bb7f87 commit 7bc9f30

71 files changed

Lines changed: 2283 additions & 61 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env.sample

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This is a sample .env file for Jest configuration.
2+
JEST_VAR__APP_ROOT="" # URL to the WordPress admin page, example: "https://your-domain/wp-admin/options-general.php"
3+
JEST_VAR__WP_LOGIN="" # WordPress admin username
4+
JEST_VAR__WP_PASSWORD="" # WordPress admin password
5+
JEST_VAR__CHROME_EXECUTABLE="" # Path to the Chrome executable, example: "C:\Program Files\Google\Chrome\Application\chrome.exe"
6+
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
7+
JEST_VAR__HEADLESS="" # Set to "1" for headless mode, "0" for normal mode

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ backups
1111
composer.lock
1212
psalm.xml
1313
.editorconfig
14+
.env
1415
/lib/CleantalkSP/Common/Scanner/HeuristicAnalyser/tests/
1516
/lib/CleantalkSP/Common/Scanner/SignaturesAnalyser/tests/
1617
/lib/CleantalkSP/Common/Scanner/SignaturesAnalyser/.github/
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
require_once 'spbct-sync-react.php';
4+
5+
function spbc_admin_add_react_page()
6+
{
7+
add_options_page(
8+
__(' Settings via React', 'security-malware-firewall'),
9+
'SPBC Settings via React',
10+
'manage_options',
11+
'spbct',
12+
function () {
13+
echo "<div id='spbct_root'
14+
data-nonce='" . esc_attr(wp_create_nonce('spbc_secret_nonce')) . "'
15+
data-ajaxurl='" . esc_attr(admin_url('admin-ajax.php')) . "'
16+
></div>";
17+
}
18+
);
19+
}
20+
21+
add_action('wp_ajax_spbct_get_tab_data', 'spbct_get_tab_data');
22+
function spbct_get_tab_data()
23+
{
24+
spbc_check_ajax_referer('spbc_secret_nonce', 'security');
25+
26+
$tab_name = sanitize_text_field($_POST['tab_name']);
27+
$function_name = "spbct_get_tab_data_{$tab_name}";
28+
29+
if ( function_exists($function_name) ) {
30+
$res = $function_name();
31+
} else {
32+
$res = [
33+
'request_malware_removal' => false,
34+
'data_type' => 'text',
35+
'data' => $tab_name,
36+
'tab_settings' => []
37+
];
38+
}
39+
40+
wp_send_json($res);
41+
}
42+
function spbct_get_tab_data_firewall()
43+
{
44+
global $wpdb, $spbc;
45+
$request_per = isset($spbc->settings['traffic_control__autoblock_timeframe'])
46+
? (int)$spbc->settings['traffic_control__autoblock_timeframe'] / 60
47+
: 5;
48+
$columns = [
49+
'ip_entry' => esc_html__('IP', 'security-malware-firewall'),
50+
'country_code' => esc_html__('Country', 'security-malware-firewall'),
51+
'entry_timestamp' => esc_html__('Last Request', 'security-malware-firewall'),
52+
'status' => esc_html__('Status', 'security-malware-firewall'),
53+
'requests' => esc_html__('Requests and attempts', 'security-malware-firewall'),
54+
'requests_per' => sprintf(esc_html__('Requests per %s minutes', 'security-malware-firewall'), $request_per),
55+
'page_url' => esc_html__('Page', 'security-malware-firewall'),
56+
'http_user_agent' => esc_html__('User Agent', 'security-malware-firewall')
57+
];
58+
$query = 'SELECT ' . trim(implode(',', array_keys($columns)), ',')
59+
. ' FROM ' . SPBC_TBL_FIREWALL_LOG
60+
. ' ORDER BY entry_timestamp desc '
61+
. ' LIMIT %d ';
62+
$prepared_query = $wpdb->prepare($query, [SPBC_LAST_ACTIONS_TO_VIEW]);
63+
$results = $wpdb->get_results($prepared_query);
64+
$table_data = [
65+
'columns' => $columns,
66+
'rows' => $results
67+
];
68+
$output = [
69+
'request_malware_removal' => false,
70+
'data_type' => 'table',
71+
'data' => $table_data,
72+
'tab_settings' => [],
73+
];
74+
return $output;
75+
}
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
<?php
2+
3+
use CleantalkSP\SpbctWP\AdjustToEnvironmentModule\AdjustToEnvironmentHandler;
4+
5+
add_action('wp_ajax_spbc_react_access_key_check', 'spbc_react_access_key_check');
6+
add_action('wp_ajax_spbc_react_secfw_update_init', 'spbc_react_secfw_update_init');
7+
add_action('wp_ajax_spbc_react_settings_exclusions', 'spbc_react_settings_exclusions');
8+
add_action('wp_ajax_spbc_react_run_ajusting_env', 'spbc_react_run_ajusting_env');
9+
add_action('wp_ajax_spbc_react_signatures_update', 'spbc_react_signatures_update');
10+
add_action('wp_ajax_spbc_react_run_vulnerability_check', 'spbc_react_run_vulnerability_check');
11+
12+
function spbc_react_access_key_check()
13+
{
14+
global $spbc;
15+
spbc_check_ajax_referer('spbc_secret_nonce', 'security');
16+
17+
//Clearing all errors
18+
$spbc->error_delete_all('and_save_data');
19+
20+
$account_is_ok = false;
21+
22+
// If key provided by super admin
23+
if ( $spbc->is_mainsite || $spbc->ms__work_mode != 2 ) {
24+
// Checking account status
25+
$account_is_ok = spbc_check_account_status($spbc->api_key);
26+
}
27+
28+
/*$out = array(
29+
'success' => true,
30+
'reload' => $spbc->data['key_changed'] || !empty($spbc->errors),
31+
);*/
32+
33+
$spbc->data['key_changed'] = false;
34+
$spbc->save('data');
35+
36+
$res = [
37+
'error' => false,
38+
'message' => 'Test message',
39+
'success' => $account_is_ok,
40+
];
41+
42+
wp_send_json($res);
43+
}
44+
45+
function spbc_react_secfw_update_init()
46+
{
47+
global $spbc;
48+
49+
spbc_check_ajax_referer('spbc_secret_nonce', 'security');
50+
51+
$result = spbc_send_logs($spbc->api_key);
52+
if ( empty($result['error']) ) {
53+
$spbc->data['logs_last_sent'] = current_time('timestamp');
54+
$spbc->data['last_sent_events_count'] = $result;
55+
$spbc->error_delete('send_logs');
56+
} else {
57+
$spbc->error_add('send_logs', $result);
58+
}
59+
60+
// Sending FW logs
61+
$result = spbc_send_firewall_logs($spbc->api_key);
62+
if ( empty($result['error']) ) {
63+
$spbc->fw_stats['last_send'] = current_time('timestamp');
64+
$spbc->fw_stats['last_send_count'] = $result;
65+
$spbc->error_delete('send_firewall_logs');
66+
} else {
67+
$spbc->error_add('send_firewall_logs', $result);
68+
}
69+
70+
// Get custom message for security firewall
71+
$result_service_get = spbct_perform_service_get();
72+
if ( ! empty($result_service_get['error']) ) {
73+
if ($result_service_get['error_no'] !== 403) {
74+
$spbc->error_add('service_customize', $result_service_get['error']);
75+
}
76+
}
77+
78+
// Updating FW
79+
//Reset last call of update_sec_fw
80+
$spbc->remote_calls['update_security_firewall']['last_call'] = 0;
81+
$spbc->save('remote_calls', true, false);
82+
83+
$result = spbc_security_firewall_update__init();
84+
85+
if ( ! empty($result['error']) ) {
86+
$spbc->error_add('firewall_update', $result['error']);
87+
}
88+
89+
$spbc->save('data');
90+
$spbc->save('fw_stats', true, false);
91+
92+
$res = [
93+
'error' => false,
94+
'message' => 'Test message',
95+
'success' => true,
96+
];
97+
98+
wp_send_json($res);
99+
}
100+
101+
function spbc_react_signatures_update()
102+
{
103+
global $spbc;
104+
105+
spbc_check_ajax_referer('spbc_secret_nonce', 'security');
106+
107+
// If key provided by super admin
108+
if ( is_main_site() ) {
109+
// Updating signtaures
110+
$result = spbc_scanner__signatures_update();
111+
empty($result['error'])
112+
? $spbc->error_delete('scanner_update_signatures', 'save')
113+
: $spbc->error_add('scanner_update_signatures', $result);
114+
}
115+
116+
$res = [
117+
'error' => false,
118+
'message' => 'Test message',
119+
'success' => true,
120+
];
121+
122+
wp_send_json($res);
123+
}
124+
125+
function spbc_react_settings_exclusions()
126+
{
127+
global $spbc;
128+
129+
spbc_check_ajax_referer('spbc_secret_nonce', 'security');
130+
131+
// Update scan settings exclusions
132+
$result_update_exclusions = spbc_update_scan_settings_exclusions();
133+
134+
\CleantalkSP\SpbctWP\Cron::updateTask('update_scan_settings_exclusions', 'spbc_update_scan_settings_exclusions', 86400);
135+
if ( ! empty($result_update_exclusions['error']) ) {
136+
$spbc->error_add('update_exclusions', $result_update_exclusions['error']);
137+
}
138+
139+
140+
$res = [
141+
'error' => false,
142+
'message' => 'Test message',
143+
'success' => true,
144+
];
145+
146+
wp_send_json($res);
147+
}
148+
149+
function spbc_react_run_ajusting_env()
150+
{
151+
spbc_check_ajax_referer('spbc_secret_nonce', 'security');
152+
153+
// Try to adjust to environment
154+
$adjust = new AdjustToEnvironmentHandler();
155+
$adjust->handle();
156+
157+
$res = [
158+
'error' => false,
159+
'message' => 'Test message',
160+
'success' => true,
161+
];
162+
163+
wp_send_json($res);
164+
}
165+
166+
function spbc_react_run_vulnerability_check()
167+
{
168+
spbc_check_ajax_referer('spbc_secret_nonce', 'security');
169+
170+
// Set cron task calling right now
171+
\CleantalkSP\SpbctWP\Cron::updateTask('check_vulnerabilities', 'spbc_security_check_vulnerabilities', 86400, time());
172+
173+
$res = [
174+
'error' => false,
175+
'message' => 'Test message',
176+
'success' => true,
177+
];
178+
179+
wp_send_json($res);
180+
}

inc/spbc-settings.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,9 +1303,14 @@ function spbc_settings__draw_elements($elems_to_draw = null, $direct_call = fals
13031303
if ( ! $direct_call && Post::getString('security')) {
13041304
spbc_settings__register();
13051305
spbc_check_ajax_referer('spbc_secret_nonce', 'security');
1306-
if (Post::getString('tab_name')) {
1306+
if (Post::get('tab_name')) {
1307+
if ( $_POST['tab_name'] === 'firewall' ) {
1308+
$tab_name = 'traffic_control';
1309+
} else {
1310+
$tab_name = $_POST['tab_name'];
1311+
}
13071312
/** @psalm-suppress InvalidArrayOffset */
1308-
$elems_to_draw = array($_POST['tab_name'] => $spbc->settings__elements[ Post::getString('tab_name') ]);
1313+
$elems_to_draw = array($tab_name => $spbc->settings__elements[$tab_name]);
13091314
}
13101315
}
13111316

0 commit comments

Comments
 (0)