PluginProbe
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… / 2.9.4
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… v2.9.4
3.0.0 2.11.12 2.11.11 2.11.10 2.11.9 2.11.7 2.11.8 2.11.6 2.11.5 2.11.4 2.11.3 2.11.1 2.11.2 2.11.0 2.10.5 2.10.4 2.10.3 2.10.2 2.10.1 2.10.0 2.9.9 2.9.8 2.9.6 2.9.7 2.9.5 All 88 releases
vigilante / admin / class-admin.php

class-admin.php in Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… 2.9.4, at admin/class-admin.php

7,302 lines 430.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin Class
4 *
5 * Handles admin interface and settings page
6 *
7 * @package Vigilante
8 */
9
10 // Prevent direct access
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 // Load AJAX trait
16 require_once VIGILANTE_ADMIN_DIR . 'class-admin-ajax.php';
17
18 // Load promotional banner class
19 require_once VIGILANTE_INCLUDES_DIR . 'class-ayudawp-promo-banner.php';
20
21 /**
22 * Class Vigilante_Admin
23 *
24 * Manages the admin settings interface
25 */
26 class Vigilante_Admin {
27
28 use Vigilante_Admin_Ajax;
29 use Vigilante_Admin_Analyzer_Ajax;
30 use Vigilante_Admin_Audit_Alerts_Ajax;
31
32 /**
33 * Settings instance
34 *
35 * @var Vigilante_Settings
36 */
37 private $settings;
38
39 /**
40 * Database instance
41 *
42 * @var Vigilante_Database
43 */
44 private $database;
45
46 /**
47 * Activity log instance
48 *
49 * @var Vigilante_Activity_Log
50 */
51 private $activity_log;
52
53 /**
54 * Current tab
55 *
56 * @var string
57 */
58 private $current_tab = 'dashboard';
59
60 /**
61 * Available tabs
62 *
63 * @var array
64 */
65 private $tabs = array();
66
67 /**
68 * Constructor
69 *
70 * @param Vigilante_Settings $settings Settings instance.
71 * @param Vigilante_Database $database Database instance.
72 * @param Vigilante_Activity_Log $activity_log Activity log instance.
73 */
74 public function __construct( $settings, $database, $activity_log ) {
75 $this->settings = $settings;
76 $this->database = $database;
77 $this->activity_log = $activity_log;
78
79 $this->setup_tabs();
80 $this->init_hooks();
81 }
82
83 /**
84 * Setup available tabs
85 */
86 private function setup_tabs() {
87 $this->tabs = array(
88 'dashboard' => __( 'Dashboard', 'vigilante' ),
89 'firewall' => __( 'Firewall', 'vigilante' ),
90 'headers' => __( 'Security Headers', 'vigilante' ),
91 'login' => __( 'Login Security', 'vigilante' ),
92 'rest-api' => __( 'REST API', 'vigilante' ),
93 'users' => __( 'User Security', 'vigilante' ),
94 'wp-hardening' => __( 'WP Hardening', 'vigilante' ),
95 'file-integrity' => __( 'File Integrity', 'vigilante' ),
96 'activity-log' => __( 'Security Audit', 'vigilante' ),
97 'tools' => __( 'Settings & Tools', 'vigilante' ),
98 );
99 }
100
101 /**
102 * Initialize hooks
103 */
104 private function init_hooks() {
105 add_action( 'admin_menu', array( $this, 'add_menu' ) );
106 add_action( 'admin_init', array( $this, 'redirect_submenu_shortcuts' ) );
107 add_action( 'admin_init', array( $this, 'register_settings' ) );
108 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
109 add_action( 'admin_notices', array( $this, 'show_admin_notices' ) );
110
111 // Highlight correct submenu based on active tab
112 add_filter( 'submenu_file', array( $this, 'highlight_submenu_tab' ) );
113
114 // Set browser tab title to show plugin name and active tab
115 add_filter( 'admin_title', array( $this, 'set_admin_page_title' ), 10, 2 );
116
117 // AJAX handlers
118 add_action( 'wp_ajax_vigilante_save_settings', array( $this, 'ajax_save_settings' ) );
119 add_action( 'wp_ajax_vigilante_apply_preset', array( $this, 'ajax_apply_preset' ) );
120 add_action( 'wp_ajax_vigilante_reset_section', array( $this, 'ajax_reset_section' ) );
121 add_action( 'wp_ajax_vigilante_clear_lockouts', array( $this, 'ajax_clear_lockouts' ) );
122 add_action( 'wp_ajax_vigilante_clear_logs', array( $this, 'ajax_clear_logs' ) );
123 add_action( 'wp_ajax_vigilante_run_scan', array( $this, 'ajax_run_scan' ) );
124 add_action( 'wp_ajax_vigilante_clear_scan', array( $this, 'ajax_clear_scan' ) );
125 add_action( 'wp_ajax_vigilante_ignore_file', array( $this, 'ajax_ignore_file' ) );
126 add_action( 'wp_ajax_vigilante_unignore_file', array( $this, 'ajax_unignore_file' ) );
127 add_action( 'wp_ajax_vigilante_bulk_ignore_files', array( $this, 'ajax_bulk_ignore_files' ) );
128 add_action( 'wp_ajax_vigilante_bulk_unignore_files', array( $this, 'ajax_bulk_unignore_files' ) );
129 add_action( 'wp_ajax_vigilante_clear_ignored', array( $this, 'ajax_clear_ignored' ) );
130 add_action( 'wp_ajax_vigilante_ignore_closed_plugin', array( $this, 'ajax_ignore_closed_plugin' ) );
131 add_action( 'wp_ajax_vigilante_unignore_closed_plugin', array( $this, 'ajax_unignore_closed_plugin' ) );
132 add_action( 'wp_ajax_vigilante_clear_ignored_closed_plugins', array( $this, 'ajax_clear_ignored_closed_plugins' ) );
133 add_action( 'wp_ajax_vigilante_approve_critical_file', array( $this, 'ajax_approve_critical_file' ) );
134 add_action( 'wp_ajax_vigilante_export_settings', array( $this, 'ajax_export_settings' ) );
135 add_action( 'wp_ajax_vigilante_import_settings', array( $this, 'ajax_import_settings' ) );
136 add_action( 'wp_ajax_vigilante_get_logs', array( $this, 'ajax_get_logs' ) );
137 add_action( 'wp_ajax_vigilante_test_headers', array( $this, 'ajax_test_headers' ) );
138 add_action( 'wp_ajax_vigilante_download_files_backup', array( $this, 'ajax_download_files_backup' ) );
139
140 // 2FA AJAX handlers
141 add_action( 'wp_ajax_vigilante_search_users_2fa', array( $this, 'ajax_search_users_2fa' ) );
142 add_action( 'wp_ajax_vigilante_send_2fa_notification', array( $this, 'ajax_send_2fa_notification' ) );
143 add_action( 'wp_ajax_vigilante_search_totp_users', array( $this, 'ajax_search_totp_users' ) );
144 add_action( 'wp_ajax_vigilante_reset_totp_users', array( $this, 'ajax_reset_totp_users' ) );
145 add_action( 'wp_ajax_vigilante_totp_get_setup', array( $this, 'ajax_totp_get_setup' ) );
146 add_action( 'wp_ajax_vigilante_notify_login_url', array( $this, 'ajax_notify_login_url' ) );
147
148 // Password Reset AJAX handlers
149 add_action( 'wp_ajax_vigilante_search_users_password_reset', array( $this, 'ajax_search_users_password_reset' ) );
150 add_action( 'wp_ajax_vigilante_force_password_reset', array( $this, 'ajax_force_password_reset' ) );
151 add_action( 'wp_ajax_vigilante_force_password_reset_all', array( $this, 'ajax_force_password_reset_all' ) );
152 add_action( 'wp_ajax_vigilante_force_password_reset_by_role', array( $this, 'ajax_force_password_reset_by_role' ) );
153
154 // User approval AJAX handlers
155 add_action( 'wp_ajax_vigilante_approve_user', array( $this, 'ajax_approve_user' ) );
156 add_action( 'wp_ajax_vigilante_reject_user', array( $this, 'ajax_reject_user' ) );
157
158 // Session management AJAX handlers
159 add_action( 'wp_ajax_vigilante_get_user_sessions', array( $this, 'ajax_get_user_sessions' ) );
160 add_action( 'wp_ajax_vigilante_revoke_session', array( $this, 'ajax_revoke_session' ) );
161 add_action( 'wp_ajax_vigilante_revoke_all_sessions', array( $this, 'ajax_revoke_all_sessions' ) );
162
163 // Under Attack mode AJAX handlers
164 add_action( 'wp_ajax_vigilante_activate_under_attack', array( $this, 'ajax_activate_under_attack' ) );
165 add_action( 'wp_ajax_vigilante_deactivate_under_attack', array( $this, 'ajax_deactivate_under_attack' ) );
166 add_action( 'wp_ajax_vigilante_under_attack_status', array( $this, 'ajax_under_attack_status' ) );
167
168 // Database backup AJAX handlers
169 add_action( 'wp_ajax_vigilante_get_db_tables', array( $this, 'ajax_get_db_tables' ) );
170 add_action( 'wp_ajax_vigilante_download_db_backup', array( $this, 'ajax_download_db_backup' ) );
171
172 // Database prefix AJAX handlers
173 add_action( 'wp_ajax_vigilante_generate_prefix', array( $this, 'ajax_generate_prefix' ) );
174 add_action( 'wp_ajax_vigilante_change_prefix', array( $this, 'ajax_change_prefix' ) );
175
176 // Firewall list management from activity log popup
177 add_action( 'wp_ajax_vigilante_add_to_firewall_list', array( $this, 'ajax_add_to_firewall_list' ) );
178 add_action( 'wp_ajax_vigilante_unblock_firewall_ip', array( $this, 'ajax_unblock_firewall_ip' ) );
179
180 // Security Analyzer AJAX handlers (v2.1.0)
181 add_action( 'wp_ajax_vigilante_analyzer_run', array( $this, 'ajax_analyzer_run' ) );
182 add_action( 'wp_ajax_vigilante_analyzer_history', array( $this, 'ajax_analyzer_history' ) );
183 add_action( 'wp_ajax_vigilante_analyzer_dismiss_notice', array( $this, 'ajax_analyzer_dismiss_notice' ) );
184 add_action( 'wp_ajax_vigilante_analyzer_save_settings', array( $this, 'ajax_analyzer_save_settings' ) );
185
186 // Shared "Send test email" handler — Notification settings, File Integrity, Audit Alerts (v2.8.0)
187 add_action( 'wp_ajax_vigilante_send_test_email', array( $this, 'ajax_send_test_email' ) );
188
189 // Run migrations on admin load
190 add_action( 'admin_init', array( $this, 'run_migrations' ) );
191 }
192
193 /**
194 * Run database migrations based on stored version
195 */
196 public function run_migrations() {
197 $db_version = get_option( 'vigilante_db_version', '0' );
198
199 // 1.2.3: Fix IP lists corrupted by sanitize_text_field stripping newlines
200 if ( version_compare( $db_version, '1.2.3', '<' ) ) {
201 $this->migrate_fix_ip_lists();
202 update_option( 'vigilante_db_version', '1.2.3' );
203 }
204
205 // 1.3.0: Add request_method column to activity log table
206 if ( version_compare( $db_version, '1.3.0', '<' ) ) {
207 $this->database->run_migrations();
208 }
209
210 // 1.9.0: Re-apply wp-config constants (performance constants removed from managed list)
211 if ( version_compare( $db_version, '1.9.0', '<' ) ) {
212 if ( $this->settings->is_module_enabled( 'wp_hardening' ) ) {
213 require_once VIGILANTE_INCLUDES_DIR . 'class-wpconfig-security.php';
214 $wpconfig = new Vigilante_Wpconfig_Security( $this->settings );
215 $wpconfig->apply_security_constants();
216 }
217 update_option( 'vigilante_db_version', '1.9.0' );
218 }
219
220 // 1.10.0: Clean up orphaned email fields (centralized notification recipients)
221 if ( version_compare( $db_version, '1.10.0', '<' ) ) {
222 $this->migrate_cleanup_email_fields();
223 update_option( 'vigilante_db_version', '1.10.0' );
224 }
225
226 // 1.11.0: Remove stale 'enabled' key from activity_log settings
227 // + Convert additional_recipients from string to array
228 if ( version_compare( $db_version, '1.11.0', '<' ) ) {
229 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
230 $changed = false;
231
232 if ( isset( $options['activity_log']['enabled'] ) ) {
233 unset( $options['activity_log']['enabled'] );
234 $changed = true;
235 }
236
237 // Convert corrupted string to array for additional_recipients
238 if ( isset( $options['email']['additional_recipients'] ) && is_string( $options['email']['additional_recipients'] ) ) {
239 $raw = trim( $options['email']['additional_recipients'] );
240 if ( ! empty( $raw ) ) {
241 $emails = array_filter( array_map( 'trim', preg_split( '/[\r\n,; ]+/', $raw ) ) );
242 $options['email']['additional_recipients'] = array_values( array_filter( $emails, 'is_email' ) );
243 } else {
244 $options['email']['additional_recipients'] = array();
245 }
246 $changed = true;
247 }
248
249 if ( $changed ) {
250 update_option( Vigilante_Settings::OPTION_NAME, $options );
251 }
252 update_option( 'vigilante_db_version', '1.11.0' );
253 }
254
255 // 1.12.1: Regenerate htaccess (WooCommerce IPN exclusion in bot blocking rule)
256 if ( version_compare( $db_version, '1.12.1', '<' ) ) {
257 if ( ! empty( $this->settings->get_section( 'firewall' )['block_bad_bots'] ) ) {
258 require_once VIGILANTE_INCLUDES_DIR . 'class-htaccess-protection.php';
259 $htaccess = new Vigilante_Htaccess_Protection( $this->settings );
260 $htaccess->apply_rules();
261 }
262 update_option( 'vigilante_db_version', '1.12.1' );
263 }
264
265 // 1.14.0: Generate critical config files baseline (wp-config.php, .htaccess)
266 if ( version_compare( $db_version, '1.14.0', '<' ) ) {
267 if ( ! class_exists( 'Vigilante_File_Integrity' ) ) {
268 require_once VIGILANTE_INCLUDES_DIR . 'class-file-integrity.php';
269 }
270 $fi = new Vigilante_File_Integrity( $this->settings, $this->database, $this->activity_log );
271 $fi->regenerate_all_baselines();
272 update_option( 'vigilante_db_version', '1.14.0' );
273 }
274
275 // 2.0.0: Move hide_server_signature and remove_fingerprinting_headers
276 // from firewall section to security_headers section
277 if ( version_compare( $db_version, '2.0.0', '<' ) ) {
278 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
279 $changed = false;
280
281 foreach ( array( 'hide_server_signature', 'remove_fingerprinting_headers' ) as $key ) {
282 if ( isset( $options['firewall'][ $key ] ) ) {
283 if ( ! isset( $options['security_headers'][ $key ] ) ) {
284 $options['security_headers'][ $key ] = $options['firewall'][ $key ];
285 }
286 unset( $options['firewall'][ $key ] );
287 $changed = true;
288 }
289 }
290
291 if ( $changed ) {
292 update_option( Vigilante_Settings::OPTION_NAME, $options );
293 }
294 update_option( 'vigilante_db_version', '2.0.0' );
295 }
296
297 // 2.6.1: Two things happen here.
298 //
299 // 1. Re-apply wp-config constants so the block is rewritten with
300 // "if ( ! defined() )" guards around every define(). Without guards,
301 // non-standard setups that pre-define WordPress constants outside
302 // wp-config.php (custom bootstraps that load constants from .env or
303 // similar) hit a fatal "Constant already defined" when wp-config.php
304 // is parsed and reaches our block.
305 //
306 // 2. Drop the cached Security Check report. The cached "max" per
307 // category was frozen at scan time; with the internal category
308 // bumping from 22 to 28 points (closed_plugins added in 2.6.0),
309 // the cached report would keep displaying 22/22 until the next
310 // full scan. Clearing it forces a fresh scan with the new caps.
311 if ( version_compare( $db_version, '2.6.1', '<' ) ) {
312 if ( $this->settings->is_module_enabled( 'wp_hardening' ) ) {
313 require_once VIGILANTE_INCLUDES_DIR . 'class-wpconfig-security.php';
314 $wpconfig = new Vigilante_Wpconfig_Security( $this->settings );
315 $wpconfig->apply_security_constants();
316 }
317 delete_option( 'vigilante_analyzer_last_scan' );
318
319 // Schedule an immediate background scan so the dashboard widget
320 // doesn't display "Last scan: never" right after the upgrade.
321 // Reuses the same hook the post-Under-Attack flow uses.
322 if ( ! wp_next_scheduled( 'vigilante_under_attack_post_scan' ) ) {
323 wp_schedule_single_event( time() + 5, 'vigilante_under_attack_post_scan' );
324 }
325
326 update_option( 'vigilante_db_version', '2.6.1' );
327 }
328
329 // 2.9.3: Regenerate the .htaccess protection block. The bad-bots
330 // User-Agent list dropped substring-prone tokens that 403'd
331 // legitimate clients (e.g. "rma" matched inside "Performance" and
332 // blocked WP Rocket's page fetch), and the blocking rules now honour
333 // the firewall IP / User-Agent whitelists as negated exceptions.
334 // Existing sites only rewrite the block when Server Protection is
335 // saved, so the upgrade has to refresh it once itself (same pattern
336 // as the 1.12.1 WooCommerce IPN migration).
337 if ( version_compare( $db_version, '2.9.3', '<' ) ) {
338 require_once VIGILANTE_INCLUDES_DIR . 'class-htaccess-protection.php';
339 $htaccess = new Vigilante_Htaccess_Protection( $this->settings );
340
341 if ( $htaccess->are_rules_active() ) {
342 $htaccess->apply_rules();
343 }
344
345 update_option( 'vigilante_db_version', '2.9.3' );
346 }
347 }
348
349 /**
350 * Migration: Remove orphaned email fields from saved options
351 *
352 * v1.10.0 centralized notification recipients into email section.
353 * Old per-module notify_email fields and dead email section fields
354 * are removed to avoid confusion.
355 */
356 private function migrate_cleanup_email_fields() {
357 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
358 $modified = false;
359
360 // Remove orphaned fields from email section
361 $dead_email_keys = array( 'enabled', 'from_name', 'from_email', 'admin_email', 'send_activation_email', 'custom_email' );
362 if ( isset( $options['email'] ) && is_array( $options['email'] ) ) {
363 foreach ( $dead_email_keys as $key ) {
364 if ( array_key_exists( $key, $options['email'] ) ) {
365 unset( $options['email'][ $key ] );
366 $modified = true;
367 }
368 }
369 // Ensure new fields exist with defaults
370 if ( ! array_key_exists( 'send_to_admin_email', $options['email'] ) ) {
371 $options['email']['send_to_admin_email'] = true;
372 $modified = true;
373 }
374 if ( ! array_key_exists( 'additional_recipients', $options['email'] ) ) {
375 $options['email']['additional_recipients'] = '';
376 $modified = true;
377 }
378 }
379
380 // Remove notify_email from login_security
381 if ( isset( $options['login_security']['notify_email'] ) ) {
382 unset( $options['login_security']['notify_email'] );
383 $modified = true;
384 }
385
386 // Remove notify_email from file_integrity
387 if ( isset( $options['file_integrity']['notify_email'] ) ) {
388 unset( $options['file_integrity']['notify_email'] );
389 $modified = true;
390 }
391
392 if ( $modified ) {
393 update_option( Vigilante_Settings::OPTION_NAME, $options );
394 // Clear settings cache so the plugin uses clean data immediately
395 $this->settings->clear_cache();
396 }
397 }
398
399 /**
400 * Migration: Fix IP whitelist/blacklist entries merged into single line
401 *
402 * Prior to 1.2.3, sanitize_text_field() stripped newlines from textarea data,
403 * causing multiple IPs to be stored as a single space-separated string.
404 */
405 private function migrate_fix_ip_lists() {
406 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
407 $fixed = false;
408
409 foreach ( array( 'ip_whitelist', 'ip_blacklist' ) as $key ) {
410 if ( ! empty( $options['firewall'][ $key ] ) && is_array( $options['firewall'][ $key ] ) ) {
411 $new_list = array();
412 foreach ( $options['firewall'][ $key ] as $entry ) {
413 // Split entries that were joined by spaces
414 $parts = preg_split( '/\s+/', trim( $entry ) );
415 foreach ( $parts as $part ) {
416 $part = trim( $part );
417 if ( '' !== $part ) {
418 $new_list[] = $part;
419 }
420 }
421 }
422 if ( count( $new_list ) !== count( $options['firewall'][ $key ] ) ) {
423 $options['firewall'][ $key ] = array_unique( $new_list );
424 $fixed = true;
425 }
426 }
427 }
428
429 if ( $fixed ) {
430 update_option( Vigilante_Settings::OPTION_NAME, $options );
431 // Clear settings cache so changes take effect immediately
432 $this->settings->clear_cache();
433 }
434 }
435
436 /**
437 * Add admin menu page in last position
438 */
439 public function add_menu() {
440 $menu_title = __( 'Vigilant', 'vigilante' );
441
442 // Count pending approvals (separate concern, always red if present)
443 $pending_count = $this->get_pending_approvals_count();
444
445 // Get security issues with severity
446 $security_status = $this->get_security_status_for_badge();
447
448 // Total count for badge
449 $total_badge = $pending_count + $security_status['count'];
450
451 if ( $total_badge > 0 ) {
452 // Determine badge color:
453 // - Red (awaiting-mod): pending approvals OR critical modules disabled
454 // - Orange (update-plugins): only non-critical modules disabled
455 if ( $pending_count > 0 || $security_status['has_critical'] ) {
456 $badge_class = 'awaiting-mod';
457 } else {
458 $badge_class = 'update-plugins vigilante-badge-warning';
459 }
460
461 $menu_title .= sprintf(
462 ' <span class="%s count-%d"><span class="pending-count">%d</span></span>',
463 esc_attr( $badge_class ),
464 $total_badge,
465 $total_badge
466 );
467 }
468
469 add_menu_page(
470 __( 'Vigilant', 'vigilante' ),
471 $menu_title,
472 'manage_options',
473 'vigilante',
474 array( $this, 'render_settings_page' ),
475 'dashicons-shield',
476 999
477 );
478
479 // Rename auto-generated first submenu to "Dashboard"
480 add_submenu_page(
481 'vigilante',
482 __( 'Dashboard', 'vigilante' ),
483 __( 'Dashboard', 'vigilante' ),
484 'manage_options',
485 'vigilante',
486 array( $this, 'render_settings_page' )
487 );
488
489 // Security Audit shortcut
490 add_submenu_page(
491 'vigilante',
492 __( 'Security Audit', 'vigilante' ),
493 __( 'Security Audit', 'vigilante' ),
494 'manage_options',
495 'vigilante-activity-log',
496 array( $this, 'redirect_to_tab' )
497 );
498
499 // File Integrity shortcut
500 add_submenu_page(
501 'vigilante',
502 __( 'File Integrity', 'vigilante' ),
503 __( 'File Integrity', 'vigilante' ),
504 'manage_options',
505 'vigilante-file-integrity',
506 array( $this, 'redirect_to_tab' )
507 );
508 }
509
510 /**
511 * Redirect submenu shortcuts early, before headers are sent
512 */
513 public function redirect_submenu_shortcuts() {
514 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Just reading page slug for redirect
515 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
516
517 $tab_map = array(
518 'vigilante-activity-log' => 'activity-log',
519 'vigilante-file-integrity' => 'file-integrity',
520 );
521
522 if ( isset( $tab_map[ $page ] ) ) {
523 wp_safe_redirect( admin_url( 'admin.php?page=vigilante&tab=' . $tab_map[ $page ] ) );
524 exit;
525 }
526 }
527
528 /**
529 * Fallback redirect for submenu shortcuts (JS-based)
530 */
531 public function redirect_to_tab() {
532 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Just reading page slug for redirect
533 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
534
535 $tab_map = array(
536 'vigilante-activity-log' => 'activity-log',
537 'vigilante-file-integrity' => 'file-integrity',
538 );
539
540 if ( isset( $tab_map[ $page ] ) ) {
541 $url = admin_url( 'admin.php?page=vigilante&tab=' . $tab_map[ $page ] );
542 echo '<script>window.location.replace(' . wp_json_encode( esc_url( $url ) ) . ');</script>';
543 }
544 }
545
546 /**
547 * Highlight the correct submenu item based on active tab
548 *
549 * @param string $submenu_file Current submenu file.
550 * @return string
551 */
552 public function highlight_submenu_tab( $submenu_file ) {
553 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading tab for menu highlight only
554 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
555 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
556 $tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : '';
557
558 if ( 'vigilante' !== $page || empty( $tab ) ) {
559 return $submenu_file;
560 }
561
562 $tab_to_submenu = array(
563 'activity-log' => 'vigilante-activity-log',
564 'file-integrity' => 'vigilante-file-integrity',
565 );
566
567 if ( isset( $tab_to_submenu[ $tab ] ) ) {
568 return $tab_to_submenu[ $tab ];
569 }
570
571 return $submenu_file;
572 }
573
574 /**
575 * Set browser tab title to show plugin name and active tab
576 *
577 * Changes "Dashboard ‹ Site Name — WordPress" to
578 * "Vigilant > Dashboard ‹ Site Name — WordPress"
579 *
580 * @param string $admin_title Full admin title.
581 * @param string $title Page title from add_menu_page/add_submenu_page.
582 * @return string Modified title.
583 */
584 public function set_admin_page_title( $admin_title, $title ) {
585 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading page slug for title only
586 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
587
588 // Only modify on Vigilante pages
589 if ( 0 !== strpos( $page, 'vigilante' ) ) {
590 return $admin_title;
591 }
592
593 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
594 $tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'dashboard';
595
596 if ( isset( $this->tabs[ $tab ] ) ) {
597 $tab_label = $this->tabs[ $tab ];
598 } else {
599 $tab_label = __( 'Dashboard', 'vigilante' );
600 }
601
602 $plugin_title = __( 'Vigilant', 'vigilante' ) . ' &rsaquo; ' . $tab_label;
603
604 // Replace the original page title portion
605 return str_replace( $title, $plugin_title, $admin_title );
606 }
607
608 /**
609 * Get count of users pending approval
610 *
611 * @return int Count of pending users.
612 */
613 private function get_pending_approvals_count() {
614 // Prevent early execution before WordPress is ready
615 if ( ! did_action( 'plugins_loaded' ) ) {
616 return 0;
617 }
618
619 $registration_approval = $this->settings->get_section( 'user_security' );
620 $approval_settings = $registration_approval['registration_approval'] ?? array();
621
622 if ( empty( $approval_settings['enabled'] ) ) {
623 return 0;
624 }
625
626 // phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_key, WordPress.DB.SlowDBQuery.slow_db_query_meta_value -- Limited results in admin context.
627 $pending_users = get_users( array(
628 'meta_key' => 'vigilante_pending_approval',
629 'meta_value' => '1',
630 'fields' => 'ID',
631 ) );
632 // phpcs:enable WordPress.DB.SlowDBQuery.slow_db_query_meta_key, WordPress.DB.SlowDBQuery.slow_db_query_meta_value
633
634 return count( $pending_users );
635 }
636
637 /**
638 * Calculate comprehensive security score (0-100)
639 *
640 * @param array $options Plugin options.
641 * @return int Security score.
642 */
643 private function calculate_security_score( $options ) {
644 $score = 0;
645 $max_score = 0;
646
647 // Module scores (60 points total)
648 $module_weights = array(
649 'firewall' => 10,
650 'security_headers' => 8,
651 'login_security' => 10,
652 'rest_api_security' => 6,
653 'user_security' => 8,
654 'wp_hardening' => 8,
655 'file_integrity' => 5,
656 'activity_log' => 5,
657 );
658
659 foreach ( $module_weights as $module => $weight ) {
660 $max_score += $weight;
661 if ( ! empty( $options['modules'][ $module ] ) ) {
662 $score += $weight;
663 }
664 }
665
666 // Firewall details (10 points)
667 if ( ! empty( $options['modules']['firewall'] ) ) {
668 $firewall = $options['firewall'] ?? array();
669 $max_score += 10;
670
671 $firewall_checks = array(
672 'block_sql_injection',
673 'block_xss_attacks',
674 'block_bad_query_strings',
675 'block_file_inclusion',
676 'block_directory_traversal',
677 );
678
679 $firewall_enabled = 0;
680 foreach ( $firewall_checks as $check ) {
681 if ( ! empty( $firewall[ $check ] ) ) {
682 $firewall_enabled++;
683 }
684 }
685 $score += min( 10, $firewall_enabled * 2 );
686 }
687
688 // Login security details (10 points)
689 if ( ! empty( $options['modules']['login_security'] ) ) {
690 $login = $options['login_security'] ?? array();
691 $max_score += 10;
692
693 // Max attempts configured
694 if ( isset( $login['max_attempts'] ) && $login['max_attempts'] <= 5 ) {
695 $score += 3;
696 }
697 // XML-RPC disabled
698 if ( ! empty( $login['disable_xmlrpc'] ) ) {
699 $score += 3;
700 }
701 // 2FA enabled
702 if ( ! empty( $login['two_factor']['enabled'] ) ) {
703 $score += 4;
704 }
705 }
706
707 // Security headers details (10 points)
708 if ( ! empty( $options['modules']['security_headers'] ) ) {
709 $headers = $options['security_headers'] ?? array();
710 $max_score += 10;
711
712 if ( ! empty( $headers['x_frame_options'] ) ) {
713 $score += 2;
714 }
715 if ( ! empty( $headers['x_content_type_options'] ) ) {
716 $score += 2;
717 }
718 if ( ! empty( $headers['hsts']['enabled'] ) ) {
719 $score += 3;
720 }
721 if ( ! empty( $headers['csp']['enabled'] ) ) {
722 $score += 3;
723 }
724 }
725
726 // User security details (10 points)
727 if ( ! empty( $options['modules']['user_security'] ) ) {
728 $user = $options['user_security'] ?? array();
729 $max_score += 10;
730
731 if ( ! empty( $user['block_insecure_usernames'] ) ) {
732 $score += 3;
733 }
734 if ( ! empty( $user['force_strong_passwords'] ) ) {
735 $score += 3;
736 }
737 if ( ! empty( $user['password_expiration']['enabled'] ) ) {
738 $score += 2;
739 }
740 if ( ! empty( $user['email_verification']['enabled'] ) ) {
741 $score += 2;
742 }
743 }
744
745 // Audit alerts details (6 points) - only when Security Audit is on,
746 // because the alerting layer rides on top of the activity log. Leaving
747 // both alert legs off keeps these points unearned.
748 if ( ! empty( $options['modules']['activity_log'] ) ) {
749 $alerts = isset( $options['audit_alerts'] ) ? (array) $options['audit_alerts'] : array();
750 $max_score += 6;
751 if ( Vigilante_Audit_Alerts::immediate_is_active( $alerts ) ) {
752 $score += 3;
753 }
754 if ( Vigilante_Audit_Alerts::threshold_is_active( $alerts ) ) {
755 $score += 3;
756 }
757 }
758
759 // Environment checks (8 points) - penalize insecure server configuration
760 $max_score += 8;
761 $env_score = 8;
762
763 // WP_DEBUG active in production is a security risk (exposes paths, errors)
764 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
765 $env_score -= 5;
766 }
767
768 // Accounts with insecure usernames (targeted by brute force attacks)
769 $insecure_admins = $this->get_insecure_admin_usernames();
770 if ( ! empty( $insecure_admins ) ) {
771 $env_score -= 3;
772 }
773
774 $score += max( 0, $env_score );
775
776 return $max_score > 0 ? round( ( $score / $max_score ) * 100 ) : 0;
777 }
778
779 /**
780 * Get security recommendations based on current settings
781 *
782 * @param array $options Plugin options.
783 * @return array Array of recommendations.
784 */
785 private function get_security_recommendations( $options ) {
786 $recommendations = array();
787
788 // Critical: Firewall disabled
789 if ( empty( $options['modules']['firewall'] ) ) {
790 $recommendations[] = array(
791 'icon' => 'warning',
792 'priority' => 'critical',
793 'message' => __( 'Enable Firewall to protect against common attacks.', 'vigilante' ),
794 );
795 }
796
797 // Critical: Login security disabled
798 if ( empty( $options['modules']['login_security'] ) ) {
799 $recommendations[] = array(
800 'icon' => 'warning',
801 'priority' => 'critical',
802 'message' => __( 'Enable Login Security to prevent brute force attacks.', 'vigilante' ),
803 );
804 }
805
806 // High: Security headers disabled
807 if ( empty( $options['modules']['security_headers'] ) ) {
808 $recommendations[] = array(
809 'icon' => 'admin-generic',
810 'priority' => 'high',
811 'message' => __( 'Enable Security Headers to protect against clickjacking and XSS.', 'vigilante' ),
812 );
813 }
814
815 // High: User security disabled
816 if ( empty( $options['modules']['user_security'] ) ) {
817 $recommendations[] = array(
818 'icon' => 'admin-users',
819 'priority' => 'high',
820 'message' => __( 'Enable User Security to enforce password policies and username protection.', 'vigilante' ),
821 );
822 }
823
824 // High: 2FA not enabled (only if login security is active)
825 $login = $options['login_security'] ?? array();
826 if ( ! empty( $options['modules']['login_security'] ) && empty( $login['two_factor']['enabled'] ) ) {
827 $recommendations[] = array(
828 'icon' => 'shield',
829 'priority' => 'high',
830 'message' => __( 'Enable Two-Factor Authentication for enhanced login security.', 'vigilante' ),
831 'tab' => 'login',
832 );
833 }
834
835 // Medium: REST API security disabled
836 if ( empty( $options['modules']['rest_api_security'] ) ) {
837 $recommendations[] = array(
838 'icon' => 'rest-api',
839 'priority' => 'medium',
840 'message' => __( 'Enable REST API Security to control API access and prevent enumeration.', 'vigilante' ),
841 );
842 }
843
844 // Medium: WP Hardening disabled
845 if ( empty( $options['modules']['wp_hardening'] ) ) {
846 $recommendations[] = array(
847 'icon' => 'lock',
848 'priority' => 'medium',
849 'message' => __( 'Enable WP Hardening to remove version info and protect core files.', 'vigilante' ),
850 );
851 }
852
853 // Medium: File integrity disabled
854 if ( empty( $options['modules']['file_integrity'] ) ) {
855 $recommendations[] = array(
856 'icon' => 'media-text',
857 'priority' => 'medium',
858 'message' => __( 'Enable File Integrity to detect unauthorized file changes.', 'vigilante' ),
859 );
860 }
861
862 // Medium: Security Audit disabled
863 if ( empty( $options['modules']['activity_log'] ) ) {
864 $recommendations[] = array(
865 'icon' => 'list-view',
866 'priority' => 'medium',
867 'message' => __( 'Enable Security Audit to track security events.', 'vigilante' ),
868 );
869 }
870
871 // Low: XML-RPC enabled (only if login security is active)
872 if ( ! empty( $options['modules']['login_security'] ) && empty( $login['disable_xmlrpc'] ) ) {
873 $recommendations[] = array(
874 'icon' => 'info',
875 'priority' => 'low',
876 'message' => __( 'Disable XML-RPC if not needed (reduces attack surface).', 'vigilante' ),
877 'tab' => 'login',
878 );
879 }
880
881 // Low: Strong passwords not enforced (only if user security is active)
882 $user = $options['user_security'] ?? array();
883 if ( ! empty( $options['modules']['user_security'] ) && empty( $user['force_strong_passwords'] ) ) {
884 $recommendations[] = array(
885 'icon' => 'admin-users',
886 'priority' => 'low',
887 'message' => __( 'Enforce strong passwords for all users.', 'vigilante' ),
888 'tab' => 'users',
889 );
890 }
891
892 // High: WP_DEBUG active in production (regardless of Vigilante settings)
893 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
894 $recommendations[] = array(
895 'icon' => 'warning',
896 'priority' => 'high',
897 'message' => __( 'WP_DEBUG is active. Debug mode exposes sensitive information and should be disabled in production.', 'vigilante' ),
898 'tab' => 'wp-hardening',
899 );
900 }
901
902 // Low: Users with display name matching login username (only if user security active)
903 if ( ! empty( $options['modules']['user_security'] ) ) {
904 $exposed_users = $this->get_users_with_exposed_login();
905 if ( ! empty( $exposed_users ) ) {
906 $recommendations[] = array(
907 'icon' => 'admin-users',
908 'priority' => 'low',
909 'message' => sprintf(
910 /* translators: %s: Comma-separated list of usernames */
911 __( 'These users have their login username as display name (publicly visible): %s', 'vigilante' ),
912 implode( ', ', $exposed_users )
913 ),
914 'tab' => 'users',
915 );
916 }
917 }
918
919 // High: Accounts with insecure usernames (regardless of module status)
920 $insecure_admins = $this->get_insecure_admin_usernames();
921 if ( ! empty( $insecure_admins ) ) {
922 $recommendations[] = array(
923 'icon' => 'warning',
924 'priority' => 'high',
925 'message' => sprintf(
926 /* translators: %s: Comma-separated list of usernames */
927 __( 'Insecure usernames detected: %s. These are commonly targeted in brute force attacks. Create new accounts with unique usernames and remove these.', 'vigilante' ),
928 implode( ', ', $insecure_admins )
929 ),
930 );
931 }
932
933 // Critical: Closed or removed plugins detected by the daily check.
934 // Reads from the cached state map populated by Vigilante_Plugin_Status, so
935 // there is no extra HTTP call here. Ignored slugs are filtered out so the
936 // recommendation respects the user's per-slug Ignore decisions.
937 if ( ! empty( $options['modules']['file_integrity'] ) && ! empty( $options['file_integrity']['check_closed_plugins'] ) ) {
938 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
939 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
940 }
941 $closed_checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
942 $closed_active = $closed_checker->get_closed_plugins();
943 if ( ! empty( $closed_active ) ) {
944 $names = array();
945 foreach ( $closed_active as $slug => $entry ) {
946 $names[] = isset( $entry['name'] ) ? $entry['name'] : $slug;
947 }
948 $recommendations[] = array(
949 'icon' => 'warning',
950 'priority' => 'critical',
951 'message' => sprintf(
952 /* translators: 1: count, 2: comma-separated plugin names */
953 _n(
954 '%1$d closed plugin detected on this site: %2$s. Closures in WordPress.org usually indicate malware, security issues or supply chain compromises. Uninstall and replace as soon as possible.',
955 '%1$d closed plugins detected on this site: %2$s. Closures in WordPress.org usually indicate malware, security issues or supply chain compromises. Uninstall and replace as soon as possible.',
956 count( $closed_active ),
957 'vigilante'
958 ),
959 count( $closed_active ),
960 implode( ', ', $names )
961 ),
962 'tab' => 'file-integrity',
963 );
964 }
965 }
966
967 // Medium: Security Audit is on but no audit alert is configured. The
968 // alerting layer only makes sense while the activity log is running.
969 if ( ! empty( $options['modules']['activity_log'] ) ) {
970 $alerts = isset( $options['audit_alerts'] ) ? (array) $options['audit_alerts'] : array();
971 if ( ! Vigilante_Audit_Alerts::has_active_alerts( $alerts ) ) {
972 $recommendations[] = array(
973 'icon' => 'email-alt',
974 'priority' => 'medium',
975 'message' => __( 'Set up Audit Alerts to get an email when something important happens (a new admin, a closed plugin, or an attack in progress).', 'vigilante' ),
976 'tab' => 'activity-log',
977 );
978 }
979 }
980
981 // Sort by priority
982 $priority_order = array( 'critical' => 0, 'high' => 1, 'medium' => 2, 'low' => 3 );
983 usort( $recommendations, function( $a, $b ) use ( $priority_order ) {
984 return ( $priority_order[ $a['priority'] ] ?? 99 ) - ( $priority_order[ $b['priority'] ] ?? 99 );
985 } );
986
987 return $recommendations;
988 }
989
990 /**
991 * Get users whose display name matches their login username
992 *
993 * Limited to administrators and editors for performance and relevance.
994 * Cached with transient to avoid repeated queries on every dashboard load.
995 *
996 * @return array Array of usernames with exposed login.
997 */
998 private function get_users_with_exposed_login() {
999 $cache_key = 'vigilante_exposed_display_names';
1000 $cached = get_transient( $cache_key );
1001
1002 if ( false !== $cached ) {
1003 return $cached;
1004 }
1005
1006 $exposed = array();
1007 $users = get_users( array(
1008 'role__in' => array( 'administrator', 'editor' ),
1009 'fields' => array( 'ID', 'user_login', 'display_name' ),
1010 ) );
1011
1012 foreach ( $users as $user ) {
1013 if ( strcasecmp( $user->display_name, $user->user_login ) === 0 ) {
1014 $exposed[] = $user->user_login;
1015 }
1016 }
1017
1018 // Cache for 12 hours
1019 set_transient( $cache_key, $exposed, 12 * HOUR_IN_SECONDS );
1020
1021 return $exposed;
1022 }
1023
1024 /**
1025 * Get accounts with insecure usernames
1026 *
1027 * Checks for common default usernames that are targeted by brute force attacks.
1028 * Detects any user regardless of role (consistent with username creation blocking).
1029 * Uses WordPress object cache via get_user_by() so no transient needed.
1030 *
1031 * @return array Array of insecure usernames found.
1032 */
1033 private function get_insecure_admin_usernames() {
1034 $priority_usernames = array( 'admin', 'administrator', 'root', 'test', 'user', 'guest', 'info', 'sysadmin', 'webmaster' );
1035 $found = array();
1036
1037 foreach ( $priority_usernames as $username ) {
1038 $user = get_user_by( 'login', $username );
1039 if ( $user ) {
1040 $found[] = $username;
1041 }
1042 }
1043
1044 return $found;
1045 }
1046
1047 /**
1048 * Get security status for menu badge
1049 *
1050 * Returns count of disabled modules and whether there are critical issues.
1051 * Critical = Firewall or Login Security disabled.
1052 *
1053 * @return array Array with 'count' and 'has_critical'.
1054 */
1055 public function get_security_status_for_badge() {
1056 $options = $this->settings->get_all_options();
1057 $modules = $options['modules'] ?? array();
1058
1059 // Count disabled modules
1060 $disabled_count = 0;
1061 $has_critical = false;
1062
1063 // Critical modules - if disabled, badge is red
1064 $critical_modules = array( 'firewall', 'login_security' );
1065
1066 foreach ( $modules as $module => $enabled ) {
1067 // Handle both boolean and string values ('1', '0', true, false)
1068 $is_enabled = filter_var( $enabled, FILTER_VALIDATE_BOOLEAN );
1069
1070 if ( ! $is_enabled ) {
1071 $disabled_count++;
1072
1073 // Check if this is a critical module
1074 if ( in_array( $module, $critical_modules, true ) ) {
1075 $has_critical = true;
1076 }
1077 }
1078 }
1079
1080 return array(
1081 'count' => $disabled_count,
1082 'has_critical' => $has_critical,
1083 );
1084 }
1085
1086 /**
1087 * Get count of security issues for menu badge (deprecated, use get_security_status_for_badge)
1088 *
1089 * @return int Count of critical/high issues.
1090 */
1091 public function get_security_issues_count() {
1092 $status = $this->get_security_status_for_badge();
1093 return $status['count'];
1094 }
1095
1096 /**
1097 * Register settings
1098 */
1099 public function register_settings() {
1100 register_setting(
1101 'vigilante_options',
1102 Vigilante_Settings::OPTION_NAME,
1103 array( $this->settings, 'validate_options' )
1104 );
1105 }
1106
1107 /**
1108 * Build the settings search index
1109 *
1110 * Flat list of searchable entries consumed by the client-side search.
1111 * Each entry contains tab + section metadata, a translated label and an
1112 * English fallback so locales with partial translation still match.
1113 *
1114 * @return array
1115 */
1116 private function get_search_index() {
1117 return array(
1118 // Firewall - Main
1119 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Block bad bots', 'vigilante' ), 'label_en' => 'Block bad bots', 'keywords' => 'bots robots malos bloquear bad block crawlers arañas scrapers' ),
1120 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Block malicious requests', 'vigilante' ), 'label_en' => 'Block malicious requests', 'keywords' => 'malicioso maliciosas peticiones ataques sqli xss rfi lfi ataque exploit injection inyección' ),
1121 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Rate limiting', 'vigilante' ), 'label_en' => 'Rate limiting', 'keywords' => 'limitar tasa velocidad throttle peticiones minuto abuso flood' ),
1122 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Brute force protection', 'vigilante' ), 'label_en' => 'Brute force protection', 'keywords' => 'fuerza bruta brute force contraseñas ataque login diccionario' ),
1123 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'IP Whitelist', 'vigilante' ), 'label_en' => 'IP Whitelist', 'keywords' => 'lista blanca permitida permitidas whitelist allowlist ip direcciones permitir' ),
1124 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'IP Blacklist', 'vigilante' ), 'label_en' => 'IP Blacklist', 'keywords' => 'lista negra bloqueada bloqueadas blacklist blocklist denylist ip direcciones bloquear' ),
1125 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'User-Agent Whitelist', 'vigilante' ), 'label_en' => 'User-Agent Whitelist', 'keywords' => 'ua user agent agente usuario navegador lista blanca permitida whitelist allowlist' ),
1126 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'User-Agent Blacklist', 'vigilante' ), 'label_en' => 'User-Agent Blacklist', 'keywords' => 'ua user agent agente usuario navegador lista negra bloqueada blacklist blocklist denylist' ),
1127 // Firewall - Server Protection
1128 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Server Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-server', 'label' => __( 'Directory Browsing', 'vigilante' ), 'label_en' => 'Directory Browsing', 'keywords' => 'directorio navegación listado listing indexing indexado carpetas' ),
1129 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Server Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-server', 'label' => __( 'Protect wp-config.php', 'vigilante' ), 'label_en' => 'Protect wp-config.php', 'keywords' => 'proteger wp-config configuración config archivo' ),
1130 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Server Protection', 'vigilante' ), 'anchor' => 'field-protect-wp-cron', 'label' => __( 'Protect wp-cron.php', 'vigilante' ), 'label_en' => 'Protect wp-cron.php', 'keywords' => 'proteger wp-cron cron tareas programadas scheduled tasks bloquear block dos abuse spam htaccess' ),
1131 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Server Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-server', 'label' => __( 'Protect wp-includes', 'vigilante' ), 'label_en' => 'Protect wp-includes', 'keywords' => 'proteger wp-includes includes core núcleo archivos' ),
1132 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Server Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-server', 'label' => __( 'PHP in Uploads', 'vigilante' ), 'label_en' => 'PHP in Uploads', 'keywords' => 'php uploads subidas archivos bloquear ejecución' ),
1133 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Server Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-server', 'label' => __( 'Sensitive Files', 'vigilante' ), 'label_en' => 'Sensitive Files', 'keywords' => 'sensibles sensitive files archivos readme license htaccess log' ),
1134 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Server Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-server', 'label' => __( 'Limit HTTP Methods', 'vigilante' ), 'label_en' => 'Limit HTTP Methods', 'keywords' => 'métodos http limit limitar trace options put delete verbs verbos' ),
1135 // Security Headers
1136 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'X-Frame-Options', 'vigilante' ), 'label_en' => 'X-Frame-Options', 'keywords' => 'xframe clickjacking iframe cabeceras headers' ),
1137 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'X-Content-Type-Options', 'vigilante' ), 'label_en' => 'X-Content-Type-Options', 'keywords' => 'mime sniffing nosniff content type cabeceras headers' ),
1138 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Referrer-Policy', 'vigilante' ), 'label_en' => 'Referrer-Policy', 'keywords' => 'referer referrer política privacidad cabeceras headers' ),
1139 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'HSTS', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'HSTS', 'vigilante' ), 'label_en' => 'HSTS', 'keywords' => 'strict transport security ssl tls https forzar cabeceras headers' ),
1140 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Content Security Policy', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Content Security Policy', 'vigilante' ), 'label_en' => 'Content Security Policy', 'keywords' => 'csp política seguridad contenido xss scripts inline eval cabeceras headers' ),
1141 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Server Identity', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Server Signature', 'vigilante' ), 'label_en' => 'Server Signature', 'keywords' => 'firma servidor server signature identidad apache nginx ocultar hide fingerprint protección servidor' ),
1142 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Server Identity', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Remove Fingerprinting Headers', 'vigilante' ), 'label_en' => 'Remove Fingerprinting Headers', 'keywords' => 'fingerprint huella identificación cabeceras headers x-powered-by server ocultar eliminar protección servidor' ),
1143 // Login Security
1144 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Custom login URL', 'vigilante' ), 'label_en' => 'Custom login URL', 'keywords' => 'url personalizada login acceso entrar wp-login wp-admin slug ocultar esconder' ),
1145 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Two-Factor Authentication', 'vigilante' ), 'label_en' => 'Two-Factor Authentication', 'keywords' => '2fa doble factor autenticación totp google authenticator mfa' ),
1146 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( '2FA', 'vigilante' ), 'label_en' => '2FA', 'keywords' => '2fa doble factor autenticación totp google authenticator mfa two factor' ),
1147 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Failed login attempts', 'vigilante' ), 'label_en' => 'Failed login attempts', 'keywords' => 'intentos fallidos login acceso failed attempts bloqueo bloqueos contraseña errónea' ),
1148 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Lockout', 'vigilante' ), 'label_en' => 'Lockout', 'keywords' => 'bloqueo bloqueado lockout baneo ban duración login' ),
1149 // REST API
1150 array( 'tab' => 'rest-api', 'tab_label' => __( 'REST API', 'vigilante' ), 'section' => __( 'REST API Security', 'vigilante' ), 'anchor' => 'vigilante-section-rest-api-main', 'label' => __( 'Access Mode', 'vigilante' ), 'label_en' => 'Access Mode', 'keywords' => 'modo acceso rest api público privado autenticado' ),
1151 array( 'tab' => 'rest-api', 'tab_label' => __( 'REST API', 'vigilante' ), 'section' => __( 'REST API Security', 'vigilante' ), 'anchor' => 'vigilante-section-rest-api-main', 'label' => __( 'Block User Enumeration', 'vigilante' ), 'label_en' => 'Block User Enumeration', 'keywords' => 'enumeración usuarios users block bloquear autores author slug ?author' ),
1152 array( 'tab' => 'rest-api', 'tab_label' => __( 'REST API', 'vigilante' ), 'section' => __( 'REST API Security', 'vigilante' ), 'anchor' => 'vigilante-section-rest-api-main', 'label' => __( 'Disable JSONP', 'vigilante' ), 'label_en' => 'Disable JSONP', 'keywords' => 'jsonp desactivar deshabilitar disable callback' ),
1153 // User Security
1154 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Username protection', 'vigilante' ), 'label_en' => 'Username protection', 'keywords' => 'nombre usuario username admin reservado prohibido protección' ),
1155 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Password strength', 'vigilante' ), 'label_en' => 'Password strength', 'keywords' => 'fortaleza fuerza contraseña password débil fuerte complejidad requisitos' ),
1156 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Admin monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-users-admin-monitoring', 'label' => __( 'Admin monitoring', 'vigilante' ), 'label_en' => 'Admin monitoring', 'keywords' => 'monitorización administradores admin supervisión alertas cambios' ),
1157 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Registration approval', 'vigilante' ), 'anchor' => 'vigilante-section-users-registration', 'label' => __( 'Registration approval', 'vigilante' ), 'label_en' => 'Registration approval', 'keywords' => 'aprobación registro registration moderación nuevos usuarios signup' ),
1158 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Session limits', 'vigilante' ), 'anchor' => 'vigilante-section-users-sessions', 'label' => __( 'Session limits', 'vigilante' ), 'label_en' => 'Session limits', 'keywords' => 'sesiones limits límite concurrentes sessions simultáneas' ),
1159 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Password expiration', 'vigilante' ), 'label_en' => 'Password expiration', 'keywords' => 'expiración caducidad contraseña password cambiar renovar rotación' ),
1160 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Email verification', 'vigilante' ), 'anchor' => 'vigilante-section-users-email-verify', 'label' => __( 'Email verification', 'vigilante' ), 'label_en' => 'Email verification', 'keywords' => 'verificación correo email confirmación validación' ),
1161 // WP Hardening
1162 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Database Hardening', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-database', 'label' => __( 'Database Hardening', 'vigilante' ), 'label_en' => 'Database Hardening', 'keywords' => 'base datos database db mysql fortalecer hardening endurecer' ),
1163 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Database Hardening', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-database', 'label' => __( 'Database prefix', 'vigilante' ), 'label_en' => 'Database prefix', 'keywords' => 'prefijo base datos database db mysql tabla tablas wp_ cambiar renombrar' ),
1164 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'wp-config.php Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-wpconfig', 'label' => __( 'Disable file editing', 'vigilante' ), 'label_en' => 'Disable file editing', 'keywords' => 'desactivar deshabilitar disable edición editor archivos file edit disallow' ),
1165 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'wp-config.php Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-wpconfig', 'label' => __( 'Disable plugin/theme installation', 'vigilante' ), 'label_en' => 'Disable plugin/theme installation', 'keywords' => 'desactivar deshabilitar disable instalación plugins temas themes install disallow' ),
1166 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'wp-config.php Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-wpconfig', 'label' => __( 'Force SSL admin', 'vigilante' ), 'label_en' => 'Force SSL admin', 'keywords' => 'forzar ssl tls https admin administración certificado' ),
1167 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'wp-config.php Security', 'vigilante' ), 'anchor' => 'field-disable-wp-cron', 'label' => __( 'Disable WP Cron', 'vigilante' ), 'label_en' => 'Disable WP Cron', 'keywords' => 'desactivar deshabilitar disable wp cron tareas programadas scheduled real server crontab pseudo' ),
1168 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Comment Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-comments', 'label' => __( 'Comment Security', 'vigilante' ), 'label_en' => 'Comment Security', 'keywords' => 'comentarios comments spam protección honeypot autores url' ),
1169 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-headers', 'label' => __( 'Header Cleanup', 'vigilante' ), 'label_en' => 'Header Cleanup', 'keywords' => 'limpieza cabeceras headers meta tags wordpress generator rsd wlwmanifest' ),
1170 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-headers', 'label' => __( 'Remove WordPress version', 'vigilante' ), 'label_en' => 'Remove WordPress version', 'keywords' => 'eliminar quitar versión wordpress wp generator meta ocultar hide' ),
1171 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'field-remove-wp-version-assets', 'label' => __( 'Remove version from assets', 'vigilante' ), 'label_en' => 'Remove version from assets', 'keywords' => 'eliminar quitar versión wordpress wp ver query string assets recursos urls scripts styles css js cache busting' ),
1172 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-headers', 'label' => __( 'Disable XML-RPC', 'vigilante' ), 'label_en' => 'Disable XML-RPC', 'keywords' => 'xmlrpc xml-rpc desactivar deshabilitar disable pingback trackback' ),
1173 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'RSS Feed Settings', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-rss', 'label' => __( 'RSS Feed Settings', 'vigilante' ), 'label_en' => 'RSS Feed Settings', 'keywords' => 'rss feed sindicación feeds ajustes configuración' ),
1174 // File Integrity
1175 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'File Integrity Monitoring', 'vigilante' ), 'label_en' => 'File Integrity Monitoring', 'keywords' => 'integridad archivos monitorización supervisión hash checksum malware cambios' ),
1176 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Scan schedule', 'vigilante' ), 'label_en' => 'Scan schedule', 'keywords' => 'escaneo escáner programación planificación horario frecuencia cron' ),
1177 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Instant alert', 'vigilante' ), 'label_en' => 'Instant alert', 'keywords' => 'alerta instantánea inmediata notificación aviso email tiempo real' ),
1178 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'Ignored Files', 'vigilante' ), 'anchor' => 'vigilante-section-fi-ignored', 'label' => __( 'Ignored Files', 'vigilante' ), 'label_en' => 'Ignored Files', 'keywords' => 'ignorados ignorar excluir exclusiones archivos ignored exclude' ),
1179 // Security Audit
1180 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Security Audit Settings', 'vigilante' ), 'anchor' => 'vigilante-section-audit-settings', 'label' => __( 'Retention', 'vigilante' ), 'label_en' => 'Retention', 'keywords' => 'retención días log registro conservación purga auditoría' ),
1181 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Security Audit Settings', 'vigilante' ), 'anchor' => 'vigilante-section-audit-settings', 'label' => __( 'Events to Log', 'vigilante' ), 'label_en' => 'Events to Log', 'keywords' => 'eventos log registro auditoría registrar capturar' ),
1182 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Security Audit Settings', 'vigilante' ), 'anchor' => 'vigilante-section-audit-settings', 'label' => __( 'Option Tracking', 'vigilante' ), 'label_en' => 'Option Tracking', 'keywords' => 'opciones seguimiento rastreo cambios ajustes options tracking' ),
1183 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Security Audit Settings', 'vigilante' ), 'anchor' => 'vigilante-section-audit-settings', 'label' => __( 'Exclusions', 'vigilante' ), 'label_en' => 'Exclusions', 'keywords' => 'exclusiones excluir ignorar usuarios roles ip filtros' ),
1184 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Audit Alerts', 'vigilante' ), 'anchor' => 'vigilante-section-audit-alerts', 'label' => __( 'Audit Alerts', 'vigilante' ), 'label_en' => 'Audit Alerts', 'keywords' => 'alertas avisos aviso notificaciones email correo mail auditoría audit seguridad warning critical destinatarios test prueba' ),
1185 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Audit Alerts', 'vigilante' ), 'anchor' => 'field-audit-alerts-immediate', 'label' => __( 'Immediate alerts', 'vigilante' ), 'label_en' => 'Immediate alerts', 'keywords' => 'alertas inmediatas email correo mail aviso severidad crítico critical warning evento auditoría inmediato' ),
1186 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Audit Alerts', 'vigilante' ), 'anchor' => 'field-audit-alerts-threshold', 'label' => __( 'Threshold alerts', 'vigilante' ), 'label_en' => 'Threshold alerts', 'keywords' => 'alertas umbral pico ráfaga email correo mail aviso categoría ventana threshold auditoría cortafuegos login' ),
1187 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Recent Activity', 'vigilante' ), 'anchor' => 'vigilante-section-audit-recent', 'label' => __( 'Recent Activity', 'vigilante' ), 'label_en' => 'Recent Activity', 'keywords' => 'actividad reciente log registro eventos últimos historial' ),
1188 // Settings & Tools
1189 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Notification settings', 'vigilante' ), 'anchor' => 'vigilante-section-tools-notifications', 'label' => __( 'Notification settings', 'vigilante' ), 'label_en' => 'Notification settings', 'keywords' => 'notificaciones ajustes settings email correo avisos alertas' ),
1190 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Notification settings', 'vigilante' ), 'anchor' => 'vigilante-section-tools-notifications', 'label' => __( 'Additional Recipients', 'vigilante' ), 'label_en' => 'Additional Recipients', 'keywords' => 'destinatarios adicionales correo email cc copia recipients' ),
1191 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Tools', 'vigilante' ), 'anchor' => 'vigilante-section-tools-main', 'label' => __( 'Export Settings', 'vigilante' ), 'label_en' => 'Export Settings', 'keywords' => 'exportar export ajustes configuración settings json' ),
1192 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Tools', 'vigilante' ), 'anchor' => 'vigilante-section-tools-main', 'label' => __( 'Import Settings', 'vigilante' ), 'label_en' => 'Import Settings', 'keywords' => 'importar import ajustes configuración settings json' ),
1193 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Tools', 'vigilante' ), 'anchor' => 'vigilante-section-tools-main', 'label' => __( 'Reset to Defaults', 'vigilante' ), 'label_en' => 'Reset to Defaults', 'keywords' => 'restablecer resetear reset defaults predeterminados valores originales fábrica' ),
1194 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Tools', 'vigilante' ), 'anchor' => 'vigilante-section-tools-main', 'label' => __( 'Create Backup', 'vigilante' ), 'label_en' => 'Create Backup', 'keywords' => 'copia seguridad backup crear generar respaldo' ),
1195 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Tools', 'vigilante' ), 'anchor' => 'vigilante-section-tools-main', 'label' => __( 'Database Backup', 'vigilante' ), 'label_en' => 'Database Backup', 'keywords' => 'base datos database db mysql copia seguridad backup respaldo tablas exportar' ),
1196 );
1197 }
1198
1199 /**
1200 * Enqueue admin assets
1201 *
1202 * @param string $hook Current admin page.
1203 */
1204 public function enqueue_assets( $hook ) {
1205 // toplevel_page_vigilante for top-level menu page
1206 if ( 'toplevel_page_vigilante' !== $hook ) {
1207 return;
1208 }
1209
1210 wp_enqueue_style(
1211 'vigilante-admin',
1212 VIGILANTE_ASSETS_URL . 'css/admin.css',
1213 array(),
1214 VIGILANTE_VERSION
1215 );
1216
1217 wp_enqueue_script(
1218 'vigilante-admin',
1219 VIGILANTE_ASSETS_URL . 'js/admin.js',
1220 array( 'jquery' ),
1221 VIGILANTE_VERSION,
1222 true
1223 );
1224
1225 wp_localize_script( 'vigilante-admin', 'vigilanteAdmin', array(
1226 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
1227 'nonce' => wp_create_nonce( 'vigilante_admin_nonce' ),
1228 'currentUserId' => get_current_user_id(),
1229 'logoutUrl' => wp_logout_url( wp_login_url() ),
1230 'adminUrl' => admin_url( 'admin.php?page=vigilante' ),
1231 'searchIndex' => $this->get_search_index(),
1232 'underAttack' => array(
1233 'active' => ( new Vigilante_Under_Attack( $this->settings, $this->activity_log ) )->is_active(),
1234 'remaining' => ( new Vigilante_Under_Attack( $this->settings, $this->activity_log ) )->get_remaining_time(),
1235 ),
1236 'strings' => array(
1237 'saving' => __( 'Saving...', 'vigilante' ),
1238 'sendingTest' => __( 'Sending...', 'vigilante' ),
1239 'saved' => __( 'Settings saved', 'vigilante' ),
1240 'error' => __( 'Error saving settings', 'vigilante' ),
1241 'confirm' => __( 'Are you sure?', 'vigilante' ),
1242 'scanning' => __( 'Scanning...', 'vigilante' ),
1243 'scanComplete' => __( 'Scan complete', 'vigilante' ),
1244 'loading' => __( 'Loading...', 'vigilante' ),
1245 'searching' => __( 'Searching...', 'vigilante' ),
1246 'noUsersFound' => __( 'No users found', 'vigilante' ),
1247 'searchError' => __( 'Error searching users', 'vigilante' ),
1248 'sending' => __( 'Sending...', 'vigilante' ),
1249 'sendNotification' => __( 'Send notification now', 'vigilante' ),
1250 'notificationsSent' => __( 'notifications sent', 'vigilante' ),
1251 'skipped' => __( 'skipped', 'vigilante' ),
1252 'failed' => __( 'failed', 'vigilante' ),
1253 'customConfig' => __( 'Custom Configuration', 'vigilante' ),
1254 // Header tester strings
1255 'testHeaders' => __( 'Test Headers', 'vigilante' ),
1256 'testing' => __( 'Testing...', 'vigilante' ),
1257 'score' => __( 'Score', 'vigilante' ),
1258 'enabledHeaders' => __( 'Enabled headers', 'vigilante' ),
1259 'missingHeaders' => __( 'Missing headers', 'vigilante' ),
1260 'warnings' => __( 'Warnings', 'vigilante' ),
1261 // File integrity scan results strings
1262 'scanResults' => __( 'Scan Results', 'vigilante' ),
1263 'ok' => __( 'OK', 'vigilante' ),
1264 'modified' => __( 'Modified', 'vigilante' ),
1265 'suspicious' => __( 'Suspicious', 'vigilante' ),
1266 'totalScanned' => __( 'Total Scanned', 'vigilante' ),
1267 'suspiciousFiles' => __( 'Suspicious Files', 'vigilante' ),
1268 'suspiciousWarning' => __( 'These files may contain malicious code or are in unexpected locations. Review immediately!', 'vigilante' ),
1269 'file' => __( 'File', 'vigilante' ),
1270 'reason' => __( 'Reason', 'vigilante' ),
1271 'type' => __( 'Type', 'vigilante' ),
1272 'unknown' => __( 'Unknown', 'vigilante' ),
1273 'modifiedFiles' => __( 'Modified Files', 'vigilante' ),
1274 'modifiedDescription' => __( 'These files (apparently) differ from the original WordPress or plugin versions.', 'vigilante' ),
1275 'extraFiles' => __( 'Extra Files', 'vigilante' ),
1276 'extra' => __( 'Extra', 'vigilante' ),
1277 'ignored' => __( 'Ignored', 'vigilante' ),
1278 'extraDescription' => __( 'PHP files found in plugins or themes that are not part of the original distribution from WordPress.org.', 'vigilante' ),
1279 'actions' => __( 'Actions', 'vigilante' ),
1280 'ignore' => __( 'Ignore', 'vigilante' ),
1281 'ignoring' => __( 'Ignoring...', 'vigilante' ),
1282 'fileIgnored' => __( 'File added to ignored list.', 'vigilante' ),
1283 'fileUnignored' => __( 'File removed from ignored list.', 'vigilante' ),
1284 'confirmClearIgnored' => __( 'Remove all files from the ignored list? They will appear in scan results again.', 'vigilante' ),
1285 'ignoredCleared' => __( 'Ignored files list cleared. Page will reload...', 'vigilante' ),
1286 'selectAll' => __( 'Select all', 'vigilante' ),
1287 'bulkIgnoreSelected' => __( 'Ignore selected', 'vigilante' ),
1288 'bulkUnignoreSelected'=> __( 'Stop ignoring selected', 'vigilante' ),
1289 'bulkNoSelection' => __( 'Select at least one file first.', 'vigilante' ),
1290 'bulkConfirmIgnore' => __( 'Ignore the selected files? They will be hidden from future scan results until you remove them from the ignored list.', 'vigilante' ),
1291 'bulkConfirmUnignore' => __( 'Remove the selected files from the ignored list? They will appear in scan results again.', 'vigilante' ),
1292 'bulkProcessing' => __( 'Processing...', 'vigilante' ),
1293 /* translators: %d: number of files selected for bulk action. */
1294 'bulkSelectedCount' => __( '%d selected', 'vigilante' ),
1295 'allClear' => __( 'All files verified - no issues found!', 'vigilante' ),
1296 'criticalConfigTitle' => __( 'Critical config files modified', 'vigilante' ),
1297 'criticalConfigDesc' => __( 'These files are common targets for code injection. Review the changes and approve if they are legitimate. Vigilant\'s own blocks are excluded from this check.', 'vigilante' ),
1298 'approve' => __( 'Approve', 'vigilante' ),
1299 'approving' => __( 'Approving...', 'vigilante' ),
1300 'criticalApproved' => __( 'Change approved. Next scan will use the current state as baseline.', 'vigilante' ),
1301 'reviewChanges' => __( 'Review changes', 'vigilante' ),
1302 'hideChanges' => __( 'Hide changes', 'vigilante' ),
1303 'changes' => __( 'Changes', 'vigilante' ),
1304 'diffUnavailable' => __( 'Diff not available for this file (baseline was created before diff tracking was added). Approve to enable diff on future changes.', 'vigilante' ),
1305 'diffEmpty' => __( 'No line-level changes detected (may be whitespace or reordering).', 'vigilante' ),
1306 'diffLines' => __( 'lines', 'vigilante' ),
1307 // Under Attack mode strings
1308 'underAttackConfirmActivate' => __( 'Activate Under Attack mode? All visitors will see a verification page for the next 4 hours.', 'vigilante' ),
1309 'underAttackConfirmDeactivate' => __( 'Deactivate Under Attack mode?', 'vigilante' ),
1310 'underAttackActivating' => __( 'Activating...', 'vigilante' ),
1311 'underAttackDeactivating' => __( 'Deactivating...', 'vigilante' ),
1312 // Database backup strings
1313 'dbBackupDownloading' => __( 'Generating backup...', 'vigilante' ),
1314 'dbBackupNoTables' => __( 'Please select at least one table.', 'vigilante' ),
1315 'dbBackupSuccess' => __( 'Database backup downloaded successfully.', 'vigilante' ),
1316 // Firewall unblock
1317 'confirmUnblockIp' => __( 'Unblock this IP from firewall rate limiting?', 'vigilante' ),
1318 // Database prefix strings
1319 'dbPrefixConfirm' => __( 'This operation will change your database prefix. It is irreversible. Make sure you have a current database backup before proceeding.', 'vigilante' ),
1320 'dbPrefixChanging' => __( 'Changing prefix...', 'vigilante' ),
1321 'dbPrefixSuccess' => __( 'Database prefix changed successfully. The page will reload now.', 'vigilante' ),
1322 'dbPrefixCheckbox' => __( 'You must confirm that you have a database backup.', 'vigilante' ),
1323 /* translators: 1: Hours, 2: Minutes */
1324 'underAttackRemaining' => __( '%1$dh %2$dm remaining', 'vigilante' ),
1325 'underAttackLabel' => __( 'Under Attack', 'vigilante' ),
1326 'standardLabel' => __( 'Standard', 'vigilante' ),
1327 'maximumLabel' => __( 'Maximum Security', 'vigilante' ),
1328 'deactivate' => __( 'Deactivate', 'vigilante' ),
1329 'underAttackActivate' => __( 'Activate for 4 hours', 'vigilante' ),
1330 // Settings strings
1331 'saveSettings' => __( 'Save Settings', 'vigilante' ),
1332 'settingsResetDefaults' => __( 'Settings reset to defaults.', 'vigilante' ),
1333 'confirmOverwrite' => __( 'This will overwrite your current settings.', 'vigilante' ),
1334 'importFailed' => __( 'Could not import settings. Check the file and try again.', 'vigilante' ),
1335 /* translators: 1: tests passed, 2: total tests in this category */
1336 'testsCounter' => __( '%1$d/%2$d tests', 'vigilante' ),
1337 'confirmResetAll' => __( 'This will reset ALL settings to defaults.', 'vigilante' ),
1338 'couldNotDetermineSection' => __( 'Could not determine section.', 'vigilante' ),
1339 'confirmResetSection' => __( 'Reset this section to default values? This cannot be undone.', 'vigilante' ),
1340 'sectionResetDefaults' => __( 'Section reset to defaults.', 'vigilante' ),
1341 /* translators: %s: preset name */
1342 'confirmApplyPreset' => __( 'Apply the "%s" preset?', 'vigilante' ),
1343 // Scan strings
1344 'scanFailed' => __( 'Scan failed', 'vigilante' ),
1345 /* translators: %s: error message */
1346 'scanError' => __( 'Scan error: %s', 'vigilante' ),
1347 'runScanNow' => __( 'Run Scan Now', 'vigilante' ),
1348 'confirmClearScan' => __( 'Are you sure you want to clear all scan results?', 'vigilante' ),
1349 'clearing' => __( 'Clearing...', 'vigilante' ),
1350 'scanResultsCleared' => __( 'Scan results cleared. Page will reload...', 'vigilante' ),
1351 'failedClearResults' => __( 'Failed to clear results', 'vigilante' ),
1352 /* translators: %s: error message */
1353 'ajaxError' => __( 'AJAX Error: %s', 'vigilante' ),
1354 // Activity log popup strings
1355 'logRequest' => __( 'Request', 'vigilante' ),
1356 'logDate' => __( 'Date', 'vigilante' ),
1357 'logMethod' => __( 'Method', 'vigilante' ),
1358 'logType' => __( 'Type', 'vigilante' ),
1359 'logAction' => __( 'Action', 'vigilante' ),
1360 'logSeverity' => __( 'Severity', 'vigilante' ),
1361 'logMessage' => __( 'Message', 'vigilante' ),
1362 'logClient' => __( 'Client', 'vigilante' ),
1363 'logUser' => __( 'User', 'vigilante' ),
1364 'logIpAddress' => __( 'IP Address', 'vigilante' ),
1365 'logUserAgent' => __( 'User Agent', 'vigilante' ),
1366 'logIpLabel' => __( 'IP:', 'vigilante' ),
1367 'logUaLabel' => __( 'UA:', 'vigilante' ),
1368 'logWhitelist' => __( 'Whitelist', 'vigilante' ),
1369 'logBlacklist' => __( 'Blacklist', 'vigilante' ),
1370 'logInWhitelist' => __( 'In whitelist', 'vigilante' ),
1371 'logInBlacklist' => __( 'In blacklist', 'vigilante' ),
1372 'logAdded' => __( 'Added!', 'vigilante' ),
1373 'logErrorAddingToList' => __( 'Error adding to list', 'vigilante' ),
1374 'logRequestFailed' => __( 'Request failed', 'vigilante' ),
1375 // Activity log table strings
1376 'noLogEntries' => __( 'No log entries found.', 'vigilante' ),
1377 'view' => __( 'View', 'vigilante' ),
1378 'confirmClearLogs' => __( 'This will delete all audit logs.', 'vigilante' ),
1379 // Export logs strings
1380 'exporting' => __( 'Exporting...', 'vigilante' ),
1381 /* translators: %d: number of entries */
1382 'logsExported' => __( 'Logs exported (%d entries)', 'vigilante' ),
1383 'noLogsToExport' => __( 'No logs to export', 'vigilante' ),
1384 'exportFailed' => __( 'Export failed', 'vigilante' ),
1385 'exportLogs' => __( 'Export Logs', 'vigilante' ),
1386 // Backup strings
1387 'backupCreated' => __( 'Backup created successfully.', 'vigilante' ),
1388 'createBackupNow' => __( 'Download Backup', 'vigilante' ),
1389 'downloadBackup' => __( 'Download Backup (.zip)', 'vigilante' ),
1390 /* translators: %d: number of tables */
1391 'tablesCount' => __( '%d tables', 'vigilante' ),
1392 /* translators: 1: table count, 2: human-readable size */
1393 'dbTablesTotal' => __( '%1$d tables total (%2$s)', 'vigilante' ),
1394 /* translators: 1: selected count, 2: human-readable size */
1395 'dbTablesSelected' => __( '%1$d tables selected (%2$s)', 'vigilante' ),
1396 // Settings search strings
1397 'searchNoResults' => __( 'No matching settings found.', 'vigilante' ),
1398 'searchInTab' => __( 'in', 'vigilante' ),
1399 // Modules string
1400 /* translators: 1: enabled count, 2: total count */
1401 'modulesEnabled' => __( '%1$d / %2$d modules enabled', 'vigilante' ),
1402 // Activity log label maps for JS rendering
1403 'eventTypeLabels' => array(
1404 'login' => __( 'Login', 'vigilante' ),
1405 'user' => __( 'User', 'vigilante' ),
1406 'content' => __( 'Content', 'vigilante' ),
1407 'plugin' => __( 'Plugin', 'vigilante' ),
1408 'theme' => __( 'Theme', 'vigilante' ),
1409 'settings' => __( 'Settings', 'vigilante' ),
1410 'comment' => __( 'Comment', 'vigilante' ),
1411 'media' => __( 'Media', 'vigilante' ),
1412 'firewall' => __( 'Firewall', 'vigilante' ),
1413 'file' => __( 'File', 'vigilante' ),
1414 'security' => __( 'Security', 'vigilante' ),
1415 'system' => __( 'System', 'vigilante' ),
1416 ),
1417 'severityLabels' => array(
1418 'info' => __( 'Info', 'vigilante' ),
1419 'warning' => __( 'Warning', 'vigilante' ),
1420 'critical' => __( 'Critical', 'vigilante' ),
1421 ),
1422 // Password reset strings
1423 'noUsersFoundSearch' => __( 'No users found', 'vigilante' ),
1424 /* translators: %d: number of users */
1425 'confirmForceReset' => __( 'Force password reset for %d user(s)? A password reset email will be sent to each user.', 'vigilante' ),
1426 'warningResettingSelf' => __( 'WARNING: You are including yourself. Your session will end and you will need to set a new password.', 'vigilante' ),
1427 'processing' => __( 'Processing...', 'vigilante' ),
1428 'anErrorOccurred' => __( 'An error occurred', 'vigilante' ),
1429 'forceResetSelected' => __( 'Force Reset for Selected Users', 'vigilante' ),
1430 'confirmForceResetAll' => __( 'This will force ALL users to reset their password. All users will receive a password reset email. Are you sure you want to continue?', 'vigilante' ),
1431 'warningResettingSelfAll' => __( 'WARNING: You are including yourself. Your session will end immediately.', 'vigilante' ),
1432 'forceResetAll' => __( 'Force Reset for ALL Users', 'vigilante' ),
1433 // Role-based password reset strings
1434 /* translators: %d: number of users */
1435 'confirmForceResetByRole' => __( 'Force password reset for %d user(s) with the selected roles? A password reset email will be sent to each user.', 'vigilante' ),
1436 'noRolesSelected' => __( 'Please select at least one role.', 'vigilante' ),
1437 'forceResetByRole' => __( 'Force Reset for Selected Roles', 'vigilante' ),
1438 // User approval strings
1439 'confirmApprove' => __( 'Approve this user?', 'vigilante' ),
1440 'approve' => __( 'Approve', 'vigilante' ),
1441 'rejectReason' => __( 'Enter rejection reason (optional):', 'vigilante' ),
1442 'reject' => __( 'Reject', 'vigilante' ),
1443 'noPending' => __( 'No pending registrations.', 'vigilante' ),
1444 // Session management strings
1445 'confirmRevoke' => __( 'Revoke this session?', 'vigilante' ),
1446 'confirmRevokeAll' => __( 'Revoke all other sessions?', 'vigilante' ),
1447 'revokeOthers' => __( 'Revoke All Other Sessions', 'vigilante' ),
1448 'confirmRevokeAllUser' => __( 'Revoke ALL sessions for this user? They will be logged out everywhere.', 'vigilante' ),
1449 'sessionsFor' => __( 'Sessions for:', 'vigilante' ),
1450 'noSessions' => __( 'No active sessions', 'vigilante' ),
1451 'revoke' => __( 'Revoke', 'vigilante' ),
1452 'noUsers' => __( 'No users found', 'vigilante' ),
1453 // Time ago strings
1454 'timeYear' => __( 'year', 'vigilante' ),
1455 'timeYears' => __( 'years', 'vigilante' ),
1456 'timeMonth' => __( 'month', 'vigilante' ),
1457 'timeMonths' => __( 'months', 'vigilante' ),
1458 'timeDay' => __( 'day', 'vigilante' ),
1459 'timeDays' => __( 'days', 'vigilante' ),
1460 'timeHour' => __( 'hour', 'vigilante' ),
1461 'timeHours' => __( 'hours', 'vigilante' ),
1462 'timeMinute' => __( 'minute', 'vigilante' ),
1463 'timeMinutes' => __( 'minutes', 'vigilante' ),
1464 /* translators: %1$d: count, %2$s: time unit */
1465 'timeAgo' => __( '%1$d %2$s ago', 'vigilante' ),
1466 'justNow' => __( 'Just now', 'vigilante' ),
1467 // Pagination strings
1468 /* translators: 1: first item number, 2: last item number, 3: total items */
1469 'paginationOf' => __( '%1$d–%2$d of %3$d', 'vigilante' ),
1470 'paginationEmpty' => __( '0 items', 'vigilante' ),
1471 // Security Analyzer strings
1472 'analyzerScanNow' => __( 'Scan now', 'vigilante' ),
1473 'analyzerScanning' => __( 'Scanning…', 'vigilante' ),
1474 'analyzerFastPhase' => __( 'Running fast checks…', 'vigilante' ),
1475 'analyzerSlowPhase' => __( 'Running remote checks…', 'vigilante' ),
1476 'analyzerScanComplete' => __( 'Security scan complete.', 'vigilante' ),
1477 'analyzerScanFailed' => __( 'Security scan failed.', 'vigilante' ),
1478 'analyzerShowDetails' => __( 'Show detailed breakdown', 'vigilante' ),
1479 'analyzerHideDetails' => __( 'Hide detailed breakdown', 'vigilante' ),
1480 'analyzerGoToSetting' => __( 'Go to setting', 'vigilante' ),
1481 'analyzerNoData' => __( 'No data yet — run a scan to populate this category.', 'vigilante' ),
1482 'analyzerJustNow' => __( 'just now', 'vigilante' ),
1483 'analyzerAgo' => __( 'ago', 'vigilante' ),
1484 'analyzerSettingsSaved' => __( 'Analyzer settings saved.', 'vigilante' ),
1485 'analyzerLastScanJustNow' => __( 'Last scan just now', 'vigilante' ),
1486 'analyzerQualityExcellent' => __( 'Excellent', 'vigilante' ),
1487 'analyzerQualityGood' => __( 'Good', 'vigilante' ),
1488 'analyzerQualityFair' => __( 'Fair', 'vigilante' ),
1489 'analyzerQualityPoor' => __( 'Poor', 'vigilante' ),
1490 'analyzerQualityCritical' => __( 'Critical', 'vigilante' ),
1491 'analyzerPts' => __( 'pts', 'vigilante' ),
1492 'analyzerLearnMore' => __( 'Learn more', 'vigilante' ),
1493 'analyzerInfoAllClear' => __( 'All clear', 'vigilante' ),
1494 /* translators: %d: number of findings in an info-only category */
1495 'analyzerInfoFindings' => __( '%d findings', 'vigilante' ),
1496 ),
1497 ) );
1498
1499 // 2FA Admin assets
1500 wp_enqueue_style(
1501 'vigilante-2fa-admin',
1502 VIGILANTE_ASSETS_URL . 'css/two-factor-admin.css',
1503 array( 'vigilante-admin' ),
1504 VIGILANTE_VERSION
1505 );
1506
1507 wp_enqueue_script(
1508 'vigilante-2fa-admin',
1509 VIGILANTE_ASSETS_URL . 'js/two-factor-admin.js',
1510 array( 'jquery', 'vigilante-admin' ),
1511 VIGILANTE_VERSION,
1512 true
1513 );
1514 }
1515
1516 /**
1517 * Show admin notices
1518 */
1519 public function show_admin_notices() {
1520 // Activation notice
1521 if ( get_transient( 'vigilante_activated' ) ) {
1522 ?>
1523 <div class="notice notice-success is-dismissible vigilante-activation-notice">
1524 <p>
1525 <span class="dashicons dashicons-shield vigilante-notice-icon"></span>
1526 <strong><?php esc_html_e( 'Vigilant activated successfully!', 'vigilante' ); ?></strong>
1527 <?php esc_html_e( 'Security protection is now active.', 'vigilante' ); ?>
1528 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante' ) ); ?>">
1529 <?php esc_html_e( 'Configure settings', 'vigilante' ); ?>
1530 </a>
1531 </p>
1532 </div>
1533 <?php
1534 delete_transient( 'vigilante_activated' );
1535 }
1536
1537 // Under Attack mode notice (non-dismissible, shown on all admin pages)
1538 $ua_status = get_option( Vigilante_Under_Attack::OPTION_NAME, array() );
1539 if ( ! empty( $ua_status['active'] ) ) {
1540 $ua_remaining = ( $ua_status['activated_at'] + $ua_status['duration'] ) - time();
1541 if ( $ua_remaining > 0 ) {
1542 $ua_hours = floor( $ua_remaining / 3600 );
1543 $ua_mins = floor( ( $ua_remaining % 3600 ) / 60 );
1544 $dashboard_url = admin_url( 'admin.php?page=vigilante' );
1545 ?>
1546 <div class="notice notice-warning vigilante-ua-notice">
1547 <p>
1548 <span class="dashicons dashicons-shield"></span>
1549 <strong><?php esc_html_e( 'Under Attack mode is active', 'vigilante' ); ?></strong>
1550 &mdash;
1551 <?php
1552 printf(
1553 /* translators: 1: Hours, 2: Minutes */
1554 esc_html__( '%1$dh %2$dm remaining.', 'vigilante' ),
1555 absint( $ua_hours ),
1556 absint( $ua_mins )
1557 );
1558 ?>
1559 <a href="<?php echo esc_url( $dashboard_url ); ?>">
1560 <?php esc_html_e( 'Go to Vigilant dashboard', 'vigilante' ); ?>
1561 </a>
1562 </p>
1563 <p>
1564 <em><?php esc_html_e( 'Vigilant has applied the Maximum preset plus extra hardening on top of your previous configuration. Any changes you make to Vigilant settings while this mode is active will be reverted when it ends.', 'vigilante' ); ?></em>
1565 </p>
1566 </div>
1567 <?php
1568 }
1569 }
1570
1571 // Proxy/CDN detection: if IP detection is set to "direct" but requests
1572 // arrive with a forwarded-for header carrying a different valid IP, the
1573 // site is very likely behind a proxy/CDN that has not been declared, so
1574 // the firewall is seeing the proxy IP for every visitor. Guide the admin.
1575 //
1576 // Two deliberate silencers (2.9.2):
1577 // - A loopback forwarded IP (::1 / 127.x) means the person browsing IS
1578 // the machine itself: that only happens in local development stacks
1579 // (Local's nginx router, Docker...), never behind a production
1580 // proxy/CDN, so the notice would be pure noise there.
1581 // - The notice is dismissible and the dismissal persists site-wide via
1582 // the vigilante_dismissed_notices option (the admin evaluated it and
1583 // decided; nagging forever helps nobody).
1584 $dismissed_notices = get_option( 'vigilante_dismissed_notices', array() );
1585 if (
1586 current_user_can( 'manage_options' )
1587 && '' === Vigilante_IP_Utils::trusted_proxy_header()
1588 && ! isset( $dismissed_notices['proxy_detection'] )
1589 ) {
1590 $remote = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '';
1591 $detected = '';
1592 foreach ( Vigilante_IP_Utils::trusted_header_map() as $proxy_label => $server_key ) {
1593 if ( empty( $_SERVER[ $server_key ] ) ) {
1594 continue;
1595 }
1596 $candidate = sanitize_text_field( wp_unslash( $_SERVER[ $server_key ] ) );
1597 if ( false !== strpos( $candidate, ',' ) ) {
1598 $parts = explode( ',', $candidate );
1599 $candidate = trim( $parts[0] );
1600 }
1601 if ( ! filter_var( $candidate, FILTER_VALIDATE_IP ) || $candidate === $remote ) {
1602 continue;
1603 }
1604 // Loopback forwarded IP = local development, not a real proxy.
1605 if ( '::1' === $candidate || 0 === strpos( $candidate, '127.' ) ) {
1606 continue;
1607 }
1608 $detected = $proxy_label;
1609 break;
1610 }
1611
1612 if ( '' !== $detected ) {
1613 $firewall_url = admin_url( 'admin.php?page=vigilante&tab=firewall' );
1614 $detail_message = sprintf(
1615 /* translators: %s: detected forwarded header name wrapped in a code tag. */
1616 esc_html__( 'Requests are arriving with a %s header, but visitor IP detection is set to direct connection. The firewall is reading the proxy address instead of the real visitor IP, which affects the IP lists and rate limiting.', 'vigilante' ),
1617 '<code>' . esc_html( strtoupper( $detected ) ) . '</code>'
1618 );
1619 ?>
1620 <div class="notice notice-warning is-dismissible vigilante-proxy-notice">
1621 <p>
1622 <span class="dashicons dashicons-shield"></span>
1623 <strong><?php esc_html_e( 'Vigilant: this site looks like it is behind a proxy or CDN', 'vigilante' ); ?></strong>
1624 </p>
1625 <p><?php echo wp_kses_post( $detail_message ); ?></p>
1626 <p>
1627 <a href="<?php echo esc_url( $firewall_url ); ?>" class="button button-secondary">
1628 <?php esc_html_e( 'Set your proxy in Firewall settings', 'vigilante' ); ?>
1629 </a>
1630 </p>
1631 </div>
1632 <script>
1633 jQuery( function ( $ ) {
1634 $( document ).on( 'click', '.vigilante-proxy-notice .notice-dismiss', function () {
1635 $.post( ajaxurl, {
1636 action: 'vigilante_dismiss_notice',
1637 notice_id: 'proxy_detection',
1638 nonce: <?php echo wp_json_encode( wp_create_nonce( 'vigilante_dismiss_notice' ) ); ?>
1639 } );
1640 } );
1641 } );
1642 </script>
1643 <?php
1644 }
1645 }
1646 }
1647
1648 /**
1649 * Render settings page
1650 */
1651 public function render_settings_page() {
1652 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
1653 $this->current_tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'dashboard';
1654
1655 if ( ! array_key_exists( $this->current_tab, $this->tabs ) ) {
1656 $this->current_tab = 'dashboard';
1657 }
1658 ?>
1659 <div class="wrap vigilante-admin-wrap">
1660 <div class="vigilante-header-row">
1661 <h1 class="vigilante-page-title">
1662 <img src="<?php echo esc_url( VIGILANTE_ASSETS_URL . 'images/icon.png' ); ?>" alt="Vigilante" class="vigilante-title-icon">
1663 <?php esc_html_e( 'Vigilant', 'vigilante' ); ?>
1664 <span class="vigilante-version">v<?php echo esc_html( VIGILANTE_VERSION ); ?></span>
1665 </h1>
1666 <div class="vigilante-search-wrapper">
1667 <div class="vigilante-search-input-wrap">
1668 <span class="vigilante-search-icon dashicons dashicons-search" aria-hidden="true"></span>
1669 <input type="search" id="vigilante-settings-search" class="vigilante-settings-search" placeholder="<?php esc_attr_e( 'Search settings…', 'vigilante' ); ?>" autocomplete="off">
1670 <span class="vigilante-search-shortcut" aria-hidden="true">/</span>
1671 </div>
1672 <div id="vigilante-settings-search-results" class="vigilante-search-results" hidden role="listbox"></div>
1673 </div>
1674 </div>
1675
1676 <?php $this->render_tabs(); ?>
1677
1678 <div class="vigilante-content">
1679 <div class="vigilante-main">
1680 <?php $this->render_tab_content(); ?>
1681 </div>
1682 <div class="vigilante-sidebar">
1683 <?php $this->render_sidebar(); ?>
1684 </div>
1685 </div>
1686 </div>
1687 <?php
1688 }
1689
1690 /**
1691 * Render tabs navigation
1692 */
1693 private function render_tabs() {
1694 $options = $this->settings->get_all_options();
1695
1696 // Map tabs to modules
1697 $tab_to_module = array(
1698 'firewall' => 'firewall',
1699 'headers' => 'security_headers',
1700 'login' => 'login_security',
1701 'rest-api' => 'rest_api_security',
1702 'users' => 'user_security',
1703 'wp-hardening' => 'wp_hardening',
1704 'file-integrity' => 'file_integrity',
1705 'activity-log' => 'activity_log',
1706 );
1707 ?>
1708 <nav class="nav-tab-wrapper vigilante-nav-tabs">
1709 <?php foreach ( $this->tabs as $tab_id => $tab_name ) :
1710 $is_disabled = false;
1711 $module = isset( $tab_to_module[ $tab_id ] ) ? $tab_to_module[ $tab_id ] : null;
1712 if ( $module && empty( $options['modules'][ $module ] ) ) {
1713 $is_disabled = true;
1714 }
1715 ?>
1716 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=' . $tab_id ) ); ?>"
1717 class="nav-tab <?php echo $this->current_tab === $tab_id ? 'nav-tab-active' : ''; ?> <?php echo $is_disabled ? 'vigilante-tab-disabled' : ''; ?>"
1718 <?php if ( $is_disabled ) : ?>title="<?php esc_attr_e( 'Module Disabled', 'vigilante' ); ?>"<?php endif; ?>>
1719 <?php echo esc_html( $tab_name ); ?>
1720 <?php if ( $is_disabled ) : ?><span class="vigilante-tab-off">OFF</span><?php endif; ?>
1721 </a>
1722 <?php endforeach; ?>
1723 </nav>
1724 <?php
1725 }
1726
1727 /**
1728 * Render current tab content
1729 */
1730 private function render_tab_content() {
1731 $method = 'render_tab_' . str_replace( '-', '_', $this->current_tab );
1732
1733 if ( method_exists( $this, $method ) ) {
1734 $this->$method();
1735 } else {
1736 $this->render_tab_coming_soon();
1737 }
1738 }
1739
1740 /**
1741 * Render coming soon placeholder
1742 */
1743 private function render_tab_coming_soon() {
1744 ?>
1745 <div class="vigilante-settings-section">
1746 <h2><?php esc_html_e( 'Coming Soon', 'vigilante' ); ?></h2>
1747 <p><?php esc_html_e( 'This section is under development.', 'vigilante' ); ?></p>
1748 </div>
1749 <?php
1750 }
1751
1752 /**
1753 * Check if module is disabled and render warning
1754 *
1755 * @param string $module_key Module key.
1756 * @return bool True if disabled.
1757 */
1758 private function render_module_disabled_notice( $module_key ) {
1759 if ( $this->settings->is_module_enabled( $module_key ) ) {
1760 return false;
1761 }
1762
1763 $module_labels = $this->settings->get_module_labels();
1764 $module_name = isset( $module_labels[ $module_key ] ) ? $module_labels[ $module_key ] : $module_key;
1765 ?>
1766 <div class="notice notice-warning vigilante-module-disabled-notice">
1767 <p>
1768 <strong><?php esc_html_e( 'Module Disabled', 'vigilante' ); ?></strong> -
1769 <?php
1770 printf(
1771 /* translators: %s: Module name */
1772 esc_html__( 'The %s module is currently disabled. Enable it from the Dashboard to use these settings.', 'vigilante' ),
1773 esc_html( $module_name )
1774 );
1775 ?>
1776 </p>
1777 <p>
1778 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=dashboard' ) ); ?>" class="button">
1779 <?php esc_html_e( 'Go to Dashboard', 'vigilante' ); ?>
1780 </a>
1781 </p>
1782 </div>
1783 <?php
1784 return true;
1785 }
1786
1787 /**
1788 * Render the Security Analyzer (Security Check) widget + expandable full report.
1789 *
1790 * Lives in the Dashboard tab between the Configuration Score status card and
1791 * the modules grid. Uses the last persisted scan to hydrate server-side so the
1792 * first paint shows real data; "Scan now" runs the 2-phase AJAX to refresh.
1793 *
1794 * @param array $last_scan Result of Vigilante_Security_Analyzer::get_last_scan().
1795 * @param array $history Score history (oldest first).
1796 * @param array $categories_def Category metadata (slug => label/max).
1797 * @param array $analyzer_settings Settings subsection for weekly cron + email.
1798 */
1799 private function render_analyzer_widget( $last_scan, $history, $categories_def, $analyzer_settings ) {
1800 $has_data = ! empty( $last_scan['ran_at'] );
1801 $score = isset( $last_scan['score'] ) ? (int) $last_scan['score'] : 0;
1802 $grade = isset( $last_scan['grade'] ) ? (string) $last_scan['grade'] : '';
1803 $counts = isset( $last_scan['counts'] ) && is_array( $last_scan['counts'] ) ? $last_scan['counts'] : array();
1804 $ran_at_human = $has_data
1805 ? sprintf(
1806 /* translators: %s: relative time like "2 hours" */
1807 __( 'Last scan %s ago', 'vigilante' ),
1808 human_time_diff( (int) $last_scan['ran_at'], time() )
1809 )
1810 : __( 'Never scanned', 'vigilante' );
1811 $categories = isset( $last_scan['categories'] ) && is_array( $last_scan['categories'] ) ? $last_scan['categories'] : array();
1812 $weekly_enabled = ! isset( $analyzer_settings['weekly_scan_enabled'] ) || ! empty( $analyzer_settings['weekly_scan_enabled'] );
1813 $email_enabled = ! empty( $analyzer_settings['email_on_regression'] );
1814
1815 $quality = self::analyzer_quality_tag( $score );
1816 ?>
1817 <div class="vigilante-analyzer" id="vigilante-analyzer"
1818 data-has-data="<?php echo $has_data ? '1' : '0'; ?>">
1819 <div class="vigilante-analyzer-header">
1820 <div class="vigilante-analyzer-title">
1821 <h2>
1822 <span class="dashicons dashicons-shield-alt" aria-hidden="true"></span>
1823 <?php esc_html_e( 'Security Check', 'vigilante' ); ?>
1824 </h2>
1825 <p class="description">
1826 <?php esc_html_e( 'On-demand audit of what an attacker would see right now, plus 13 internal checks impossible from the outside.', 'vigilante' ); ?>
1827 </p>
1828 <p class="vigilante-analyzer-last-scan" data-role="ran-at">
1829 <span class="dashicons dashicons-clock" aria-hidden="true"></span>
1830 <?php echo esc_html( $ran_at_human ); ?>
1831 </p>
1832 </div>
1833 <div class="vigilante-analyzer-actions">
1834 <button type="button" class="button button-primary" id="vigilante-analyzer-scan">
1835 <span class="dashicons dashicons-update" aria-hidden="true"></span>
1836 <?php esc_html_e( 'Scan now', 'vigilante' ); ?>
1837 </button>
1838 </div>
1839 </div>
1840
1841 <div class="vigilante-analyzer-summary">
1842 <div class="vigilante-analyzer-score-card">
1843 <?php if ( $has_data && $grade ) : ?>
1844 <div class="vigilante-score-circle vigilante-grade-<?php echo esc_attr( strtolower( $grade ) ); ?>">
1845 <span class="vigilante-grade"><?php echo esc_html( $grade ); ?></span>
1846 <span class="vigilante-score-text"><?php echo esc_html( $score ); ?>%</span>
1847 </div>
1848 <?php else : ?>
1849 <div class="vigilante-score-circle vigilante-grade-empty">
1850 <span class="vigilante-grade">—</span>
1851 <span class="vigilante-score-text"><?php esc_html_e( 'N/A', 'vigilante' ); ?></span>
1852 </div>
1853 <?php endif; ?>
1854 <div class="vigilante-analyzer-score-meta">
1855 <p class="vigilante-analyzer-score-label">
1856 <?php esc_html_e( 'Security Score', 'vigilante' ); ?>
1857 </p>
1858 <span class="vigilante-analyzer-quality-tag vigilante-analyzer-quality-<?php echo esc_attr( $quality['slug'] ); ?>"
1859 data-role="quality-tag">
1860 <?php echo esc_html( $quality['label'] ); ?>
1861 </span>
1862 </div>
1863 </div>
1864
1865 <div class="vigilante-analyzer-counts">
1866 <span class="vigilante-analyzer-count vigilante-analyzer-count--pass">
1867 <span class="dashicons dashicons-yes-alt" aria-hidden="true"></span>
1868 <strong data-role="pass"><?php echo esc_html( isset( $counts['pass'] ) ? $counts['pass'] : 0 ); ?></strong>
1869 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Passed', 'vigilante' ); ?></span>
1870 </span>
1871 <span class="vigilante-analyzer-count vigilante-analyzer-count--warn">
1872 <span class="dashicons dashicons-warning" aria-hidden="true"></span>
1873 <strong data-role="warn"><?php echo esc_html( isset( $counts['warn'] ) ? $counts['warn'] : 0 ); ?></strong>
1874 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Warnings', 'vigilante' ); ?></span>
1875 </span>
1876 <span class="vigilante-analyzer-count vigilante-analyzer-count--fail">
1877 <span class="dashicons dashicons-dismiss" aria-hidden="true"></span>
1878 <strong data-role="fail"><?php echo esc_html( isset( $counts['fail'] ) ? $counts['fail'] : 0 ); ?></strong>
1879 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Failing', 'vigilante' ); ?></span>
1880 </span>
1881 </div>
1882
1883 <?php
1884 // Sparkline of recent scores. Require at least 3 data points so the trend
1885 // is meaningful (2 points is just a line between dots, no real trend).
1886 $hist_points = array();
1887 foreach ( $history as $h ) {
1888 $hist_points[] = (int) $h['score'];
1889 }
1890 $hist_count = count( $hist_points );
1891 if ( $hist_count >= 3 ) :
1892 $current_score = (int) end( $hist_points );
1893 $previous_score = (int) $hist_points[ $hist_count - 2 ];
1894 $delta = $current_score - $previous_score;
1895 $delta_class = $delta > 0 ? 'vigilante-analyzer-delta--up' : ( $delta < 0 ? 'vigilante-analyzer-delta--down' : 'vigilante-analyzer-delta--flat' );
1896 $delta_icon = $delta > 0 ? 'arrow-up-alt' : ( $delta < 0 ? 'arrow-down-alt' : 'minus' );
1897 if ( 0 === $delta ) {
1898 $delta_text = __( 'No change', 'vigilante' );
1899 } else {
1900 $delta_text = sprintf(
1901 /* translators: %s: signed delta, e.g. "+3" or "-5" */
1902 _n( '%s pt vs. previous scan', '%s pts vs. previous scan', abs( $delta ), 'vigilante' ),
1903 ( $delta > 0 ? '+' : '' ) . (int) $delta
1904 );
1905 }
1906 ?>
1907 <div class="vigilante-analyzer-sparkline-wrap">
1908 <div class="vigilante-analyzer-sparkline-head">
1909 <span class="vigilante-analyzer-sparkline-label">
1910 <?php
1911 echo esc_html( sprintf(
1912 /* translators: %d: number of scans */
1913 _n( 'Score trend (last %d scan)', 'Score trend (last %d scans)', $hist_count, 'vigilante' ),
1914 $hist_count
1915 ) );
1916 ?>
1917 </span>
1918 <span class="vigilante-analyzer-delta <?php echo esc_attr( $delta_class ); ?>">
1919 <span class="dashicons dashicons-<?php echo esc_attr( $delta_icon ); ?>" aria-hidden="true"></span>
1920 <?php echo esc_html( $delta_text ); ?>
1921 </span>
1922 </div>
1923 <div class="vigilante-analyzer-sparkline" data-role="sparkline"
1924 data-points="<?php echo esc_attr( wp_json_encode( $hist_points ) ); ?>">
1925 <?php echo self::sparkline_svg( $hist_points ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Safe SVG from helper ?>
1926 </div>
1927 </div>
1928 <?php elseif ( $has_data ) : ?>
1929 <div class="vigilante-analyzer-sparkline-wrap vigilante-analyzer-sparkline-wrap--placeholder">
1930 <span class="vigilante-analyzer-sparkline-label">
1931 <?php esc_html_e( 'Score trend', 'vigilante' ); ?>
1932 </span>
1933 <p class="vigilante-analyzer-sparkline-hint">
1934 <span class="dashicons dashicons-chart-line" aria-hidden="true"></span>
1935 <?php
1936 $needed = 3 - $hist_count;
1937 echo esc_html( sprintf(
1938 /* translators: %d: number of additional scans needed */
1939 _n( '%d more scan needed to show a trend.', '%d more scans needed to show a trend.', $needed, 'vigilante' ),
1940 $needed
1941 ) );
1942 ?>
1943 </p>
1944 </div>
1945 <?php endif; ?>
1946 </div>
1947
1948 <div class="vigilante-analyzer-toggle-row">
1949 <button type="button" class="button-link vigilante-analyzer-toggle" aria-expanded="false">
1950 <?php esc_html_e( 'Show detailed breakdown', 'vigilante' ); ?>
1951 <span class="vigilante-analyzer-toggle-chevron" aria-hidden="true"></span>
1952 </button>
1953 </div>
1954
1955 <div class="vigilante-analyzer-details" hidden>
1956 <div class="vigilante-analyzer-categories" data-role="categories">
1957 <?php foreach ( $categories_def as $slug => $meta ) :
1958 $cat = isset( $categories[ $slug ] ) ? $categories[ $slug ] : array();
1959 $earned = isset( $cat['earned'] ) ? (int) $cat['earned'] : 0;
1960 // Always use the declared meta as the source of truth for the maximum.
1961 // The cached scan may carry an old max if a check was added/removed
1962 // between releases (see 2.6.1: closed_plugins raised internal from 22 to 28
1963 // but cached scans still reported max=22 until reset).
1964 $cat_max = (int) $meta['max'];
1965 $info_only = ! empty( $meta['info_only'] ) || 0 === (int) $meta['max'];
1966 $cat_pct = $cat_max > 0 ? (int) round( ( $earned / $cat_max ) * 100 ) : 0;
1967 $checks = isset( $cat['checks'] ) ? (array) $cat['checks'] : array();
1968 $cat_counts = isset( $cat['counts'] ) && is_array( $cat['counts'] ) ? $cat['counts'] : array( 'pass' => 0, 'warn' => 0, 'fail' => 0, 'info' => 0 );
1969 $cat_quality = self::analyzer_quality_tag( $cat_pct );
1970 $info_count = isset( $cat_counts['info'] ) ? (int) $cat_counts['info'] : 0;
1971 ?>
1972 <details class="vigilante-analyzer-category<?php echo $info_only ? ' vigilante-analyzer-category--info' : ''; ?>"
1973 data-category="<?php echo esc_attr( $slug ); ?>"
1974 data-info-only="<?php echo $info_only ? '1' : '0'; ?>">
1975 <summary class="vigilante-analyzer-category-summary">
1976 <span class="vigilante-analyzer-category-chevron" aria-hidden="true"></span>
1977 <span class="vigilante-analyzer-category-label"><?php echo esc_html( $meta['label'] ); ?></span>
1978 <?php if ( $info_only ) : ?>
1979 <span class="vigilante-analyzer-category-quality vigilante-analyzer-quality-info"
1980 data-role="category-quality"
1981 title="<?php esc_attr_e( 'Informational — does not affect the security score.', 'vigilante' ); ?>">
1982 <span class="dashicons dashicons-info-outline" aria-hidden="true"></span>
1983 <?php esc_html_e( 'Informational', 'vigilante' ); ?>
1984 </span>
1985 <?php else :
1986 $passed_count = (int) ( $cat_counts['pass'] ?? 0 );
1987 $scored_total = $passed_count
1988 + (int) ( $cat_counts['warn'] ?? 0 )
1989 + (int) ( $cat_counts['fail'] ?? 0 );
1990 ?>
1991 <span class="vigilante-analyzer-category-quality vigilante-analyzer-quality-<?php echo esc_attr( $cat_quality['slug'] ); ?>"
1992 data-role="category-quality">
1993 <span data-role="category-quality-label"><?php echo esc_html( $cat_quality['label'] ); ?></span>
1994 <span class="vigilante-analyzer-category-quality-sep" aria-hidden="true">·</span>
1995 <span class="vigilante-analyzer-category-tests" data-role="category-tests"
1996 data-passed="<?php echo esc_attr( $passed_count ); ?>"
1997 data-total="<?php echo esc_attr( $scored_total ); ?>">
1998 <?php
1999 echo esc_html( sprintf(
2000 /* translators: 1: tests passed, 2: total tests in this category */
2001 __( '%1$d/%2$d tests', 'vigilante' ),
2002 $passed_count,
2003 $scored_total
2004 ) );
2005 ?>
2006 </span>
2007 </span>
2008 <?php endif; ?>
2009 <?php if ( $info_only ) : ?>
2010 <span class="vigilante-analyzer-category-states" data-role="category-states">
2011 <?php if ( $info_count > 0 ) : ?>
2012 <span class="vigilante-analyzer-category-state vigilante-analyzer-category-state--info" title="<?php esc_attr_e( 'Informational', 'vigilante' ); ?>">
2013 <span data-role="state-info"><?php echo esc_html( $info_count ); ?></span><span class="dashicons dashicons-info-outline" aria-hidden="true"></span>
2014 </span>
2015 <?php endif; ?>
2016 </span>
2017 <?php endif; ?>
2018 <?php if ( ! $info_only ) : ?>
2019 <span class="vigilante-analyzer-category-score">
2020 <span data-role="earned"><?php echo esc_html( $earned ); ?></span><span class="vigilante-analyzer-category-score-sep">/</span><?php echo esc_html( $cat_max ); ?>
2021 <span class="vigilante-analyzer-category-score-unit"><?php esc_html_e( 'pts', 'vigilante' ); ?></span>
2022 </span>
2023 <span class="vigilante-analyzer-category-bar" aria-hidden="true">
2024 <span class="vigilante-analyzer-category-bar-fill vigilante-analyzer-category-bar-fill--<?php echo esc_attr( $cat_quality['slug'] ); ?>"
2025 style="width: <?php echo esc_attr( $cat_pct ); ?>%"
2026 data-role="category-bar"></span>
2027 </span>
2028 <?php else :
2029 $info_warn = isset( $cat_counts['warn'] ) ? (int) $cat_counts['warn'] : 0;
2030 $info_fail = isset( $cat_counts['fail'] ) ? (int) $cat_counts['fail'] : 0;
2031 $info_issues = $info_warn + $info_fail;
2032 if ( $info_issues > 0 ) : ?>
2033 <span class="vigilante-analyzer-category-status vigilante-analyzer-category-status--attention" data-role="info-status">
2034 <span class="dashicons dashicons-warning" aria-hidden="true"></span>
2035 <?php
2036 echo esc_html( sprintf(
2037 /* translators: %d: number of findings */
2038 _n( '%d finding', '%d findings', $info_issues, 'vigilante' ),
2039 $info_issues
2040 ) );
2041 ?>
2042 </span>
2043 <?php else : ?>
2044 <span class="vigilante-analyzer-category-status vigilante-analyzer-category-status--clear" data-role="info-status">
2045 <span class="dashicons dashicons-yes-alt" aria-hidden="true"></span>
2046 <?php esc_html_e( 'All clear', 'vigilante' ); ?>
2047 </span>
2048 <?php endif; ?>
2049 <?php endif; ?>
2050 </summary>
2051 <ul class="vigilante-analyzer-check-list" data-role="check-list">
2052 <?php if ( empty( $checks ) ) : ?>
2053 <li class="vigilante-analyzer-check-empty">
2054 <?php esc_html_e( 'No data yet — run a scan to populate this category.', 'vigilante' ); ?>
2055 </li>
2056 <?php else : ?>
2057 <?php foreach ( $checks as $c ) : ?>
2058 <?php echo self::render_analyzer_check_row( $c ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped inside helper ?>
2059 <?php endforeach; ?>
2060 <?php endif; ?>
2061 </ul>
2062 </details>
2063 <?php endforeach; ?>
2064 </div>
2065
2066 <div class="vigilante-analyzer-weekly">
2067 <h3><?php esc_html_e( 'Automatic weekly scan', 'vigilante' ); ?></h3>
2068 <p class="description">
2069 <?php esc_html_e( 'Vigilante runs this check once a week in the background. Enable email alerts to be notified if the score drops by 10 points or more, or if a new critical check starts failing.', 'vigilante' ); ?>
2070 </p>
2071 <label class="vigilante-analyzer-toggle-option">
2072 <input type="checkbox"
2073 name="security_analyzer[weekly_scan_enabled]"
2074 value="1"
2075 <?php checked( $weekly_enabled ); ?>>
2076 <?php esc_html_e( 'Run a weekly automatic scan', 'vigilante' ); ?>
2077 </label>
2078 <label class="vigilante-analyzer-toggle-option">
2079 <input type="checkbox"
2080 name="security_analyzer[email_on_regression]"
2081 value="1"
2082 <?php checked( $email_enabled ); ?>>
2083 <?php esc_html_e( 'Email me when the score drops significantly', 'vigilante' ); ?>
2084 </label>
2085 </div>
2086 </div>
2087 </div>
2088 <?php
2089 }
2090
2091 /**
2092 * Map a 0-100 percentage to a quality tag { label, slug } aligned with the
2093 * Dashboard grade palette (a/b/c/d/e).
2094 *
2095 * @param int $pct 0..100.
2096 * @return array{label:string,slug:string}
2097 */
2098 public static function analyzer_quality_tag( $pct ) {
2099 $pct = max( 0, min( 100, (int) $pct ) );
2100 // "Excellent" is reserved for a perfect score — a single missing point drops to Good.
2101 if ( 100 === $pct ) {
2102 return array( 'label' => __( 'Excellent', 'vigilante' ), 'slug' => 'a' );
2103 }
2104 if ( $pct >= 70 ) {
2105 return array( 'label' => __( 'Good', 'vigilante' ), 'slug' => 'b' );
2106 }
2107 if ( $pct >= 50 ) {
2108 return array( 'label' => __( 'Fair', 'vigilante' ), 'slug' => 'c' );
2109 }
2110 if ( $pct >= 30 ) {
2111 return array( 'label' => __( 'Poor', 'vigilante' ), 'slug' => 'd' );
2112 }
2113 return array( 'label' => __( 'Critical', 'vigilante' ), 'slug' => 'e' );
2114 }
2115
2116 /**
2117 * Render a single analyzer check row (used both server-side and via JS template).
2118 *
2119 * @param array $check Check result array (from Vigilante_SA_Check_Result::to_array()).
2120 * @return string HTML (escaped).
2121 */
2122 private static function render_analyzer_check_row( $check ) {
2123 $id = isset( $check['id'] ) ? $check['id'] : '';
2124 $state = isset( $check['state'] ) ? $check['state'] : 'skip';
2125 $label = isset( $check['label'] ) ? $check['label'] : '';
2126 $detail = isset( $check['detail'] ) ? $check['detail'] : '';
2127 $score = isset( $check['score'] ) ? (int) $check['score'] : 0;
2128 $max = isset( $check['max'] ) ? (int) $check['max'] : 0;
2129 $fix_link = isset( $check['fix_link'] ) ? $check['fix_link'] : '';
2130
2131 $icons = array(
2132 'pass' => 'yes-alt',
2133 'warn' => 'warning',
2134 'fail' => 'dismiss',
2135 'info' => 'info',
2136 'skip' => 'minus',
2137 );
2138 $icon = isset( $icons[ $state ] ) ? $icons[ $state ] : 'minus';
2139
2140 $html = '<li class="vigilante-analyzer-check vigilante-analyzer-check--' . esc_attr( $state ) . '"';
2141 $html .= ' data-check-id="' . esc_attr( $id ) . '">';
2142 $html .= '<span class="vigilante-analyzer-check-icon dashicons dashicons-' . esc_attr( $icon ) . '" aria-hidden="true"></span>';
2143 $html .= '<div class="vigilante-analyzer-check-body">';
2144 $html .= '<div class="vigilante-analyzer-check-label">';
2145 $html .= '<span>' . esc_html( $label ) . '</span>';
2146 if ( $max > 0 && 'info' !== $state && 'skip' !== $state ) {
2147 $html .= '<span class="vigilante-analyzer-check-score">'
2148 . esc_html( $score . '/' . $max )
2149 . ' <span class="vigilante-analyzer-check-score-unit">' . esc_html__( 'pts', 'vigilante' ) . '</span>'
2150 . '</span>';
2151 }
2152 $html .= '</div>';
2153 if ( $detail ) {
2154 $html .= '<p class="vigilante-analyzer-check-detail">' . esc_html( $detail ) . '</p>';
2155 }
2156 if ( $fix_link && in_array( $state, array( 'fail', 'warn' ), true ) ) {
2157 $html .= '<a href="' . esc_url( $fix_link ) . '" class="vigilante-analyzer-fix-link">'
2158 . esc_html__( 'Go to setting', 'vigilante' )
2159 . '<span class="vigilante-analyzer-fix-arrow" aria-hidden="true">&rarr;</span></a>';
2160 } elseif ( $fix_link && 'info' === $state ) {
2161 // Info rows (e.g. DNSBL lookups) get an external "Learn more" link instead.
2162 $is_external = 0 === strpos( $fix_link, 'http' );
2163 $html .= '<a href="' . esc_url( $fix_link ) . '" class="vigilante-analyzer-fix-link"'
2164 . ( $is_external ? ' target="_blank" rel="noopener noreferrer"' : '' ) . '>'
2165 . esc_html__( 'Learn more', 'vigilante' )
2166 . '<span class="vigilante-analyzer-fix-arrow" aria-hidden="true">&rarr;</span></a>';
2167 }
2168 $html .= '</div>';
2169 $html .= '</li>';
2170 return $html;
2171 }
2172
2173 /**
2174 * Build a minimal SVG sparkline for the score history.
2175 *
2176 * @param int[] $points Score values (0..100), oldest to newest.
2177 * @return string SVG markup.
2178 */
2179 private static function sparkline_svg( $points ) {
2180 $points = array_map( 'intval', (array) $points );
2181 $count = count( $points );
2182 if ( $count < 2 ) {
2183 return '';
2184 }
2185 $width = 280;
2186 $height = 60;
2187 $padding = 4;
2188
2189 $usable_w = $width - ( $padding * 2 );
2190 $usable_h = $height - ( $padding * 2 );
2191
2192 $step = $usable_w / max( 1, $count - 1 );
2193 $max = 100; // Fixed scale — scores are 0..100.
2194
2195 $coords = array();
2196 foreach ( $points as $i => $v ) {
2197 $x = $padding + ( $i * $step );
2198 $y = $padding + ( $usable_h - ( ( $v / $max ) * $usable_h ) );
2199 $coords[] = round( $x, 2 ) . ',' . round( $y, 2 );
2200 }
2201 $path = 'M ' . implode( ' L ', $coords );
2202 $last = end( $points );
2203 $last_x = $padding + ( ( $count - 1 ) * $step );
2204 $last_y = $padding + ( $usable_h - ( ( $last / $max ) * $usable_h ) );
2205
2206 $svg = '<svg viewBox="0 0 ' . $width . ' ' . $height . '" preserveAspectRatio="none" role="img" aria-label="' . esc_attr__( 'Security Score history', 'vigilante' ) . '" focusable="false">';
2207 $svg .= '<path d="' . esc_attr( $path ) . '" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>';
2208 $svg .= '<circle cx="' . esc_attr( round( $last_x, 2 ) ) . '" cy="' . esc_attr( round( $last_y, 2 ) ) . '" r="3" fill="currentColor"/>';
2209 $svg .= '</svg>';
2210 return $svg;
2211 }
2212
2213 /**
2214 * Render dashboard tab
2215 */
2216 private function render_tab_dashboard() {
2217 $options = $this->settings->get_all_options();
2218 $module_labels = $this->settings->get_module_labels();
2219 $module_descriptions = $this->settings->get_module_descriptions();
2220 $presets = $this->settings->get_presets();
2221 $active_preset = get_option( 'vigilante_active_preset', '' );
2222
2223 // Calculate security score with more factors
2224 $security_score = $this->calculate_security_score( $options );
2225
2226 // Security Analyzer (v2.1.0) — hydrate widget with the last persisted scan, if any.
2227 if ( ! class_exists( 'Vigilante_Security_Analyzer' ) ) {
2228 require_once VIGILANTE_INCLUDES_DIR . 'class-security-analyzer.php';
2229 }
2230 $analyzer_instance = new Vigilante_Security_Analyzer( $this->settings, $this->activity_log );
2231 $analyzer_last_scan = $analyzer_instance->get_last_scan();
2232 $analyzer_history = $analyzer_instance->get_score_history();
2233 $analyzer_categories_def = Vigilante_Security_Analyzer::get_categories();
2234 $analyzer_settings = isset( $options['security_analyzer'] ) ? $options['security_analyzer'] : array();
2235 ?>
2236 <div class="vigilante-dashboard">
2237 <div class="vigilante-status-card">
2238 <h2><?php esc_html_e( 'Configuration Score', 'vigilante' ); ?></h2>
2239 <p class="vigilante-score-kind description">
2240 <?php esc_html_e( 'How well Vigilante is configured right now. Pair it with the Security Check below to see the real-world result.', 'vigilante' ); ?>
2241 </p>
2242 <div class="vigilante-security-score">
2243 <?php
2244 // Grade thresholds: A (90+), B (70-89), C (50-69), D (30-49), E (0-29)
2245 if ( $security_score >= 90 ) {
2246 $grade = 'A';
2247 } elseif ( $security_score >= 70 ) {
2248 $grade = 'B';
2249 } elseif ( $security_score >= 50 ) {
2250 $grade = 'C';
2251 } elseif ( $security_score >= 30 ) {
2252 $grade = 'D';
2253 } else {
2254 $grade = 'E';
2255 }
2256 ?>
2257 <div class="vigilante-score-circle vigilante-grade-<?php echo esc_attr( strtolower( $grade ) ); ?>">
2258 <span class="vigilante-grade"><?php echo esc_html( $grade ); ?></span>
2259 <span class="vigilante-score-text"><?php echo esc_html( $security_score ); ?>%</span>
2260 </div>
2261 <div class="vigilante-config-status">
2262 <?php if ( $active_preset && isset( $presets[ $active_preset ] ) ) : ?>
2263 <span class="vigilante-preset-badge vigilante-preset-<?php echo esc_attr( $active_preset ); ?>">
2264 <?php echo esc_html( $presets[ $active_preset ]['name'] ); ?>
2265 </span>
2266 <?php else : ?>
2267 <span class="vigilante-preset-badge vigilante-preset-custom">
2268 <?php esc_html_e( 'Custom Configuration', 'vigilante' ); ?>
2269 </span>
2270 <?php endif; ?>
2271 </div>
2272 </div>
2273
2274 <?php
2275 $recommendations = $this->get_security_recommendations( $options );
2276 if ( ! empty( $recommendations ) ) :
2277 ?>
2278 <div class="vigilante-recommendations">
2279 <h4><?php esc_html_e( 'Recommendations', 'vigilante' ); ?></h4>
2280 <ul class="vigilante-recommendations-grid">
2281 <?php foreach ( $recommendations as $rec ) : ?>
2282 <li>
2283 <span class="dashicons dashicons-<?php echo esc_attr( $rec['icon'] ); ?> vigilante-priority-<?php echo esc_attr( $rec['priority'] ); ?>"></span>
2284 <?php echo esc_html( $rec['message'] ); ?>
2285 <?php if ( ! empty( $rec['tab'] ) ) : ?>
2286 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=' . $rec['tab'] ) ); ?>" class="vigilante-rec-link" title="<?php esc_attr_e( 'Go to settings', 'vigilante' ); ?>"><span class="dashicons dashicons-arrow-right-alt2"></span></a>
2287 <?php endif; ?>
2288 </li>
2289 <?php endforeach; ?>
2290 </ul>
2291 </div>
2292 <?php endif; ?>
2293 </div>
2294
2295 <?php $this->render_analyzer_widget( $analyzer_last_scan, $analyzer_history, $analyzer_categories_def, $analyzer_settings ); ?>
2296
2297 <div class="vigilante-modules-grid">
2298 <h2><?php esc_html_e( 'Security Modules', 'vigilante' ); ?></h2>
2299 <p class="description"><?php esc_html_e( 'Enable or disable security modules. Each module controls a tab with detailed settings.', 'vigilante' ); ?></p>
2300 <div class="vigilante-modules-list">
2301 <?php foreach ( $options['modules'] as $module => $enabled ) :
2302 $label = isset( $module_labels[ $module ] ) ? $module_labels[ $module ] : ucwords( str_replace( '_', ' ', $module ) );
2303 $description = isset( $module_descriptions[ $module ] ) ? $module_descriptions[ $module ] : '';
2304 ?>
2305 <div class="vigilante-module-item <?php echo $enabled ? 'enabled' : 'disabled'; ?>">
2306 <div class="vigilante-module-header">
2307 <span class="vigilante-module-status"></span>
2308 <span class="vigilante-module-name"><?php echo esc_html( $label ); ?></span>
2309 <label class="vigilante-toggle">
2310 <input type="checkbox"
2311 name="modules[<?php echo esc_attr( $module ); ?>]"
2312 value="1"
2313 <?php checked( $enabled ); ?>
2314 data-module="<?php echo esc_attr( $module ); ?>">
2315 <span class="vigilante-toggle-slider"></span>
2316 </label>
2317 </div>
2318 <?php if ( $description ) : ?>
2319 <p class="vigilante-module-desc"><?php echo esc_html( $description ); ?></p>
2320 <?php endif; ?>
2321 </div>
2322 <?php endforeach; ?>
2323 </div>
2324 </div>
2325
2326 <div class="vigilante-presets-card">
2327 <h2><?php esc_html_e( 'Quick Configuration Presets', 'vigilante' ); ?></h2>
2328 <p><?php esc_html_e( 'Apply a preset to quickly set up recommended settings for standard or maximum security level.', 'vigilante' ); ?></p>
2329 <div class="vigilante-presets-grid">
2330 <?php foreach ( $presets as $preset_id => $preset ) :
2331 $is_active = ( $active_preset === $preset_id );
2332 ?>
2333 <div class="vigilante-preset-card <?php echo $is_active ? 'vigilante-preset-active' : ''; ?>">
2334 <?php if ( $is_active ) : ?>
2335 <span class="vigilante-active-indicator"><?php esc_html_e( 'Active', 'vigilante' ); ?></span>
2336 <?php endif; ?>
2337 <h3><?php echo esc_html( $preset['name'] ); ?></h3>
2338 <p><?php echo esc_html( $preset['description'] ); ?></p>
2339 <button type="button" class="button vigilante-preset-btn <?php echo $is_active ? 'button-primary' : ''; ?>" data-preset="<?php echo esc_attr( $preset_id ); ?>">
2340 <?php esc_html_e( 'Apply Preset', 'vigilante' ); ?>
2341 </button>
2342 </div>
2343 <?php endforeach; ?>
2344
2345 <?php
2346 // Under Attack mode card
2347 $under_attack = new Vigilante_Under_Attack( $this->settings, $this->activity_log );
2348 $ua_active = $under_attack->is_active();
2349 $ua_remaining = $under_attack->get_remaining_time();
2350 $ua_remaining_hours = floor( $ua_remaining / 3600 );
2351 $ua_remaining_mins = floor( ( $ua_remaining % 3600 ) / 60 );
2352 ?>
2353 <div class="vigilante-preset-card vigilante-under-attack-card <?php echo $ua_active ? 'vigilante-under-attack-active' : ''; ?>">
2354 <h3>
2355 <span class="dashicons dashicons-shield"></span>
2356 <?php esc_html_e( 'Under Attack', 'vigilante' ); ?>
2357 </h3>
2358 <p><?php esc_html_e( 'Emergency mode. JavaScript challenge for all visitors, aggressive rate limiting, and restricted access. Auto-deactivates after 4 hours.', 'vigilante' ); ?></p>
2359 <?php if ( $ua_active ) : ?>
2360 <div class="vigilante-ua-countdown" data-expires="<?php echo esc_attr( $under_attack->get_status()['activated_at'] + $under_attack->get_status()['duration'] ); ?>">
2361 <span class="dashicons dashicons-clock"></span>
2362 <span class="vigilante-ua-time">
2363 <?php
2364 printf(
2365 /* translators: 1: Hours, 2: Minutes */
2366 esc_html__( '%1$dh %2$dm remaining', 'vigilante' ),
2367 absint( $ua_remaining_hours ),
2368 absint( $ua_remaining_mins )
2369 );
2370 ?>
2371 </span>
2372 </div>
2373 <button type="button" class="button vigilante-ua-btn vigilante-ua-deactivate">
2374 <?php esc_html_e( 'Deactivate', 'vigilante' ); ?>
2375 </button>
2376 <?php else : ?>
2377 <button type="button" class="button vigilante-ua-btn vigilante-ua-activate">
2378 <?php esc_html_e( 'Activate for 4 hours', 'vigilante' ); ?>
2379 </button>
2380 <?php endif; ?>
2381 </div>
2382 </div>
2383 </div>
2384 </div>
2385 <?php
2386 }
2387
2388 /**
2389 * Render tools tab
2390 */
2391 private function render_tab_tools() {
2392 // Get current settings for notification summary
2393 $email_options = $this->settings->get_section( 'email' );
2394 $login_options = $this->settings->get_section( 'login_security' );
2395 $user_options = $this->settings->get_section( 'user_security' );
2396 $fi_options = $this->settings->get_section( 'file_integrity' );
2397 $alerts_options = $this->settings->get_section( 'audit_alerts' );
2398 $monitoring = $user_options['admin_monitoring'] ?? array();
2399 $registration = $user_options['registration_approval'] ?? array();
2400 $current_admin = get_option( 'admin_email' );
2401 $send_to_admin = ! isset( $email_options['send_to_admin_email'] ) || ! empty( $email_options['send_to_admin_email'] );
2402 $additional_raw = $email_options['additional_recipients'] ?? array();
2403 $additional = is_array( $additional_raw ) ? implode( "\n", $additional_raw ) : trim( $additional_raw );
2404 ?>
2405
2406 <!-- Notification Settings -->
2407 <div id="vigilante-section-tools-notifications" class="vigilante-settings-section vigilante-notification-section">
2408 <h2><?php esc_html_e( 'Notification settings', 'vigilante' ); ?></h2>
2409 <p><?php esc_html_e( 'Configure who receives all administrative email notifications from Vigilant. Individual notifications are enabled in their respective tabs.', 'vigilante' ); ?></p>
2410
2411 <div class="vigilante-notification-layout">
2412
2413 <!-- Left column: Recipients settings -->
2414 <div class="vigilante-notification-settings">
2415 <form class="vigilante-settings-form" data-section="email">
2416
2417 <table class="form-table vigilante-compact-form">
2418 <tr>
2419 <th scope="row"><?php esc_html_e( 'WordPress Admin Email', 'vigilante' ); ?></th>
2420 <td>
2421 <label>
2422 <input type="checkbox" name="email[send_to_admin_email]" value="1" <?php checked( $send_to_admin ); ?>>
2423 <?php
2424 printf(
2425 /* translators: %s: Admin email address */
2426 esc_html__( 'Send to admin email (%s)', 'vigilante' ),
2427 '<code>' . esc_html( $current_admin ) . '</code>'
2428 );
2429 ?>
2430 </label>
2431 </td>
2432 </tr>
2433 <tr>
2434 <th scope="row"><?php esc_html_e( 'Additional Recipients', 'vigilante' ); ?></th>
2435 <td>
2436 <textarea name="email[additional_recipients]" rows="3" class="large-text code" placeholder="maintenance@example.com&#10;security@example.com"><?php echo esc_textarea( $additional ); ?></textarea>
2437 <p class="description"><?php esc_html_e( 'One email per line.', 'vigilante' ); ?></p>
2438 </td>
2439 </tr>
2440 <tr>
2441 <th scope="row"><?php esc_html_e( 'Plugin Deactivation', 'vigilante' ); ?></th>
2442 <td>
2443 <label>
2444 <input type="checkbox" name="email[send_deactivation_email]" value="1" <?php checked( ! empty( $email_options['send_deactivation_email'] ) ); ?>>
2445 <?php esc_html_e( 'Send email when Vigilant is deactivated', 'vigilante' ); ?>
2446 </label>
2447 </td>
2448 </tr>
2449 </table>
2450
2451 <p class="submit vigilante-notification-submit">
2452 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
2453 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
2454 </button>
2455 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
2456 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
2457 </button>
2458 <span class="vigilante-test-email-result" style="margin-left:8px;vertical-align:middle;"></span>
2459 </p>
2460 <p class="description"><?php esc_html_e( 'The test goes to the recipients above and confirms that email delivery works for every Vigilant notification.', 'vigilante' ); ?></p>
2461
2462 </form>
2463 </div>
2464
2465 <!-- Right column: Active notifications summary -->
2466 <div class="vigilante-notification-summary">
2467 <h4><?php esc_html_e( 'Active notifications', 'vigilante' ); ?></h4>
2468
2469 <table class="widefat striped">
2470 <thead>
2471 <tr>
2472 <th><?php esc_html_e( 'Notification', 'vigilante' ); ?></th>
2473 <th style="width: 1%; white-space: nowrap; text-align: center;"><?php esc_html_e( 'Status', 'vigilante' ); ?></th>
2474 <th style="width: 50px; text-align: center;"></th>
2475 </tr>
2476 </thead>
2477 <tbody>
2478 <?php
2479 $notifications = array(
2480 array(
2481 'label' => __( 'Login lockout', 'vigilante' ),
2482 'active' => ! empty( $login_options['notify_on_lockout'] ),
2483 'tab' => 'login',
2484 ),
2485 array(
2486 'label' => __( 'Administrator login', 'vigilante' ),
2487 'active' => ! empty( $login_options['notify_on_admin_login'] ),
2488 'tab' => 'login',
2489 ),
2490 array(
2491 'label' => __( 'New administrator created', 'vigilante' ),
2492 'active' => ! empty( $monitoring['alert_new_admin'] ),
2493 'tab' => 'users',
2494 ),
2495 array(
2496 'label' => __( 'Administrator email changed', 'vigilante' ),
2497 'active' => ! empty( $monitoring['alert_admin_email_change'] ),
2498 'tab' => 'users',
2499 ),
2500 array(
2501 'label' => __( 'Permission elevation', 'vigilante' ),
2502 'active' => ! empty( $monitoring['alert_permission_elevation'] ),
2503 'tab' => 'users',
2504 ),
2505 array(
2506 'label' => __( 'Admin password changed', 'vigilante' ),
2507 'active' => ! empty( $monitoring['alert_admin_password_change'] ),
2508 'tab' => 'users',
2509 ),
2510 array(
2511 'label' => __( 'Registration pending approval', 'vigilante' ),
2512 'active' => ! empty( $registration['enabled'] ) && ! empty( $registration['notify_admin'] ),
2513 'tab' => 'users',
2514 ),
2515 array(
2516 'label' => __( 'File integrity scan report', 'vigilante' ),
2517 'active' => ( $fi_options['notify_level'] ?? 'disabled' ) !== 'disabled',
2518 'tab' => 'file-integrity',
2519 ),
2520 array(
2521 'label' => __( 'File integrity instant alert', 'vigilante' ),
2522 'active' => ! empty( $fi_options['instant_alert'] ),
2523 'tab' => 'file-integrity',
2524 ),
2525 array(
2526 'label' => __( 'Audit alert: immediate', 'vigilante' ),
2527 'active' => Vigilante_Audit_Alerts::immediate_is_active( $alerts_options ),
2528 'tab' => 'activity-log',
2529 'anchor' => 'vigilante-section-audit-alerts',
2530 ),
2531 array(
2532 'label' => __( 'Audit alert: threshold', 'vigilante' ),
2533 'active' => Vigilante_Audit_Alerts::threshold_is_active( $alerts_options ),
2534 'tab' => 'activity-log',
2535 'anchor' => 'vigilante-section-audit-alerts',
2536 ),
2537 array(
2538 'label' => __( 'Under Attack mode', 'vigilante' ),
2539 'active' => true,
2540 'tab' => '',
2541 'note' => __( 'Always active', 'vigilante' ),
2542 ),
2543 array(
2544 'label' => __( 'Plugin deactivation', 'vigilante' ),
2545 'active' => ! empty( $email_options['send_deactivation_email'] ),
2546 'tab' => 'tools',
2547 ),
2548 );
2549
2550 foreach ( $notifications as $notif ) :
2551 $status_class = $notif['active'] ? 'vigilante-status-active' : 'vigilante-status-inactive';
2552 $status_label = $notif['active'] ? __( 'Active', 'vigilante' ) : __( 'Inactive', 'vigilante' );
2553 if ( ! empty( $notif['note'] ) ) {
2554 $status_label = $notif['note'];
2555 }
2556 ?>
2557 <tr>
2558 <td><?php echo esc_html( $notif['label'] ); ?></td>
2559 <td style="text-align: center; white-space: nowrap;">
2560 <span class="<?php echo esc_attr( $status_class ); ?>"><?php echo esc_html( $status_label ); ?></span>
2561 </td>
2562 <td style="text-align: center;">
2563 <?php if ( ! empty( $notif['tab'] ) ) : ?>
2564 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=' . $notif['tab'] ) . ( ! empty( $notif['anchor'] ) ? '#' . $notif['anchor'] : '' ) ); ?>" class="button button-small">
2565 <span class="dashicons dashicons-admin-generic" style="font-size: 14px; line-height: 1.8;"></span>
2566 </a>
2567 <?php else : ?>
2568 &mdash;
2569 <?php endif; ?>
2570 </td>
2571 </tr>
2572 <?php endforeach; ?>
2573 </tbody>
2574 </table>
2575 </div>
2576
2577 </div>
2578 </div>
2579
2580 <h2 id="vigilante-section-tools-main" class="vigilante-tools-heading"><?php esc_html_e( 'Tools', 'vigilante' ); ?></h2>
2581
2582 <?php
2583 // Warn that during Under Attack mode the export/import operate against
2584 // the temporary hardened config and any imported changes will be
2585 // reverted when the mode ends.
2586 $ua_status = get_option( Vigilante_Under_Attack::OPTION_NAME, array() );
2587 if ( ! empty( $ua_status['active'] ) ) :
2588 ?>
2589 <div class="vigilante-ua-tools-notice-wrap">
2590 <div class="notice notice-warning inline vigilante-ua-tools-notice">
2591 <p>
2592 <strong><?php esc_html_e( 'Under Attack mode is active.', 'vigilante' ); ?></strong>
2593 <?php esc_html_e( 'Exports will reflect the temporary hardened configuration, not your saved one. Imports will apply on top of the hardened config and will be reverted when the mode ends. Consider waiting until you deactivate Under Attack before exporting or importing settings.', 'vigilante' ); ?>
2594 </p>
2595 </div>
2596 </div>
2597 <?php
2598 endif;
2599 ?>
2600
2601 <div class="vigilante-tools-grid">
2602 <div class="vigilante-tool-card">
2603 <h3><?php esc_html_e( 'Export Settings', 'vigilante' ); ?></h3>
2604 <p><?php esc_html_e( 'Download your current security settings as a JSON file.', 'vigilante' ); ?></p>
2605 <button type="button" class="button vigilante-export-settings">
2606 <?php esc_html_e( 'Export Settings', 'vigilante' ); ?>
2607 </button>
2608 </div>
2609
2610 <div class="vigilante-tool-card">
2611 <h3><?php esc_html_e( 'Import Settings', 'vigilante' ); ?></h3>
2612 <p><?php esc_html_e( 'Import settings from a previously exported JSON file.', 'vigilante' ); ?></p>
2613 <input type="file" id="vigilante-import-file" accept=".json" style="display: none;">
2614 <button type="button" class="button vigilante-import-settings">
2615 <?php esc_html_e( 'Import Settings', 'vigilante' ); ?>
2616 </button>
2617 </div>
2618
2619 <div class="vigilante-tool-card">
2620 <h3><?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?></h3>
2621 <p><?php esc_html_e( 'Reset all the Vigilant security settings to default values.', 'vigilante' ); ?></p>
2622 <button type="button" class="button vigilante-reset-settings" style="color: #a00;">
2623 <?php esc_html_e( 'Reset All Settings', 'vigilante' ); ?>
2624 </button>
2625 </div>
2626
2627 <div class="vigilante-tool-card">
2628 <h3><?php esc_html_e( 'Download Config Backup', 'vigilante' ); ?></h3>
2629 <p><?php esc_html_e( 'Download a ZIP backup of your wp-config.php and .htaccess (plus robots.txt if present) before making security changes. The archive is built on the fly and sent to your browser, so nothing is left on the server.', 'vigilante' ); ?></p>
2630 <button type="button" class="button vigilante-create-backup">
2631 <?php esc_html_e( 'Download Backup', 'vigilante' ); ?>
2632 </button>
2633 </div>
2634
2635 <div class="vigilante-tool-card vigilante-tool-card-wide">
2636 <h3><?php esc_html_e( 'Database Backup', 'vigilante' ); ?></h3>
2637 <p><?php esc_html_e( 'Download a backup of your database as a ZIP file. Select which tables to include.', 'vigilante' ); ?></p>
2638 <button type="button" class="button vigilante-db-backup-toggle">
2639 <?php esc_html_e( 'Download Database Backup', 'vigilante' ); ?>
2640 </button>
2641
2642 <div class="vigilante-db-backup-panel" style="display: none;">
2643 <div class="vigilante-db-tables-loading">
2644 <span class="spinner is-active"></span>
2645 <?php esc_html_e( 'Loading tables...', 'vigilante' ); ?>
2646 </div>
2647
2648 <div class="vigilante-db-tables-content" style="display: none;">
2649 <div class="vigilante-db-tables-controls">
2650 <label>
2651 <input type="checkbox" id="vigilante-db-select-all" checked>
2652 <strong><?php esc_html_e( 'Select / deselect all', 'vigilante' ); ?></strong>
2653 </label>
2654 <span class="vigilante-db-tables-info"></span>
2655 </div>
2656
2657 <div class="vigilante-db-tables-group">
2658 <h4><?php esc_html_e( 'WordPress core tables', 'vigilante' ); ?></h4>
2659 <div class="vigilante-db-tables-list" id="vigilante-db-core-tables"></div>
2660 </div>
2661
2662 <div class="vigilante-db-tables-group" id="vigilante-db-other-group" style="display: none;">
2663 <h4><?php esc_html_e( 'Plugin and custom tables', 'vigilante' ); ?></h4>
2664 <div class="vigilante-db-tables-list" id="vigilante-db-other-tables"></div>
2665 </div>
2666
2667 <div class="vigilante-db-backup-actions">
2668 <button type="button" class="button button-primary vigilante-db-backup-download">
2669 <?php esc_html_e( 'Download Backup (.zip)', 'vigilante' ); ?>
2670 </button>
2671 </div>
2672 </div>
2673 </div>
2674 </div>
2675 </div>
2676 <?php
2677 }
2678
2679 /**
2680 * Render firewall tab
2681 */
2682 private function render_tab_firewall() {
2683 $is_disabled = $this->render_module_disabled_notice( 'firewall' );
2684 $options = $this->settings->get_section( 'firewall' );
2685 ?>
2686 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="firewall" <?php echo $is_disabled ? 'inert' : ''; ?>>
2687 <div id="vigilante-section-firewall-main" class="vigilante-settings-section">
2688 <h2>
2689 <?php esc_html_e( 'Firewall Protection', 'vigilante' ); ?>
2690 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
2691 </h2>
2692 <p><?php esc_html_e( 'PHP-based request filtering. Analyzes each request before WordPress loads.', 'vigilante' ); ?></p>
2693 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
2694 <p style="margin:0;">
2695 <?php esc_html_e( 'Full page caching systems that serve cached pages before PHP executes (Varnish, LiteSpeed Cache, NGINX FastCGI Cache, Cloudflare APO) may bypass PHP-level firewall rules for cached requests. The .htaccess rules will still apply on Apache/LiteSpeed servers.', 'vigilante' ); ?>
2696 </p>
2697 </div>
2698
2699 <table class="form-table">
2700 <tr>
2701 <th scope="row"><?php esc_html_e( 'Block Bad Query Strings', 'vigilante' ); ?></th>
2702 <td>
2703 <label>
2704 <input type="checkbox" name="firewall[block_bad_query_strings]" value="1" <?php checked( ! empty( $options['block_bad_query_strings'] ) ); ?>>
2705 <?php esc_html_e( 'Block malicious query string patterns', 'vigilante' ); ?>
2706 </label>
2707 </td>
2708 </tr>
2709 <tr>
2710 <th scope="row"><?php esc_html_e( 'SQL Injection Protection', 'vigilante' ); ?></th>
2711 <td>
2712 <label>
2713 <input type="checkbox" name="firewall[block_sql_injection]" value="1" <?php checked( ! empty( $options['block_sql_injection'] ) ); ?>>
2714 <?php esc_html_e( 'Block SQL injection attempts', 'vigilante' ); ?>
2715 </label>
2716 </td>
2717 </tr>
2718 <tr>
2719 <th scope="row"><?php esc_html_e( 'XSS Protection', 'vigilante' ); ?></th>
2720 <td>
2721 <label>
2722 <input type="checkbox" name="firewall[block_xss_attacks]" value="1" <?php checked( ! empty( $options['block_xss_attacks'] ) ); ?>>
2723 <?php esc_html_e( 'Block cross-site scripting attacks', 'vigilante' ); ?>
2724 </label>
2725 </td>
2726 </tr>
2727 <tr>
2728 <th scope="row"><?php esc_html_e( 'File Inclusion Protection', 'vigilante' ); ?></th>
2729 <td>
2730 <label>
2731 <input type="checkbox" name="firewall[block_file_inclusion]" value="1" <?php checked( ! empty( $options['block_file_inclusion'] ) ); ?>>
2732 <?php esc_html_e( 'Block local/remote file inclusion attempts', 'vigilante' ); ?>
2733 </label>
2734 </td>
2735 </tr>
2736 <tr>
2737 <th scope="row"><?php esc_html_e( 'Directory Traversal Protection', 'vigilante' ); ?></th>
2738 <td>
2739 <label>
2740 <input type="checkbox" name="firewall[block_directory_traversal]" value="1" <?php checked( ! empty( $options['block_directory_traversal'] ) ); ?>>
2741 <?php esc_html_e( 'Block path traversal attempts', 'vigilante' ); ?>
2742 </label>
2743 </td>
2744 </tr>
2745 <tr>
2746 <th scope="row"><?php esc_html_e( 'Block Bad Bots', 'vigilante' ); ?></th>
2747 <td>
2748 <label>
2749 <input type="checkbox" name="firewall[block_bad_bots]" value="1" <?php checked( ! empty( $options['block_bad_bots'] ) ); ?>>
2750 <?php esc_html_e( 'Block known malicious bots and scanners', 'vigilante' ); ?>
2751 </label>
2752 </td>
2753 </tr>
2754 </table>
2755
2756 <h3><?php esc_html_e( 'Rate Limiting', 'vigilante' ); ?></h3>
2757 <table class="form-table">
2758 <tr>
2759 <th scope="row"><?php esc_html_e( 'Enable Rate Limiting', 'vigilante' ); ?></th>
2760 <td>
2761 <label>
2762 <input type="checkbox" name="firewall[rate_limiting][enabled]" value="1" <?php checked( ! empty( $options['rate_limiting']['enabled'] ) ); ?>>
2763 <?php esc_html_e( 'Limit requests per IP address', 'vigilante' ); ?>
2764 </label>
2765 </td>
2766 </tr>
2767 <tr>
2768 <th scope="row"><?php esc_html_e( 'Requests per Minute', 'vigilante' ); ?></th>
2769 <td>
2770 <input type="number" name="firewall[rate_limiting][requests_per_minute]" value="<?php echo esc_attr( $options['rate_limiting']['requests_per_minute'] ?? 120 ); ?>" min="10" max="500" class="small-text">
2771 <p class="description">
2772 <?php esc_html_e( 'Counts only PHP requests to WordPress (pages, admin-ajax, REST, login) from a single IP, not static assets like images, CSS or JS. 120/min suits most sites; sustained traffic above that from one IP is usually a bot. To allow a legitimate service, whitelist its IP instead of raising the limit.', 'vigilante' ); ?>
2773 </p>
2774 </td>
2775 </tr>
2776 <tr>
2777 <th scope="row"><?php esc_html_e( 'Block Duration (seconds)', 'vigilante' ); ?></th>
2778 <td>
2779 <input type="number" name="firewall[rate_limiting][block_duration]" value="<?php echo esc_attr( $options['rate_limiting']['block_duration'] ?? 300 ); ?>" min="60" max="3600" class="small-text">
2780 </td>
2781 </tr>
2782 <tr>
2783 <th scope="row"><?php esc_html_e( 'Progressive Blocking', 'vigilante' ); ?></th>
2784 <td>
2785 <label>
2786 <input type="checkbox" name="firewall[rate_limiting][progressive]" value="1" <?php checked( ! empty( $options['rate_limiting']['progressive'] ) ); ?>>
2787 <?php esc_html_e( 'Double block duration on each repeat offense', 'vigilante' ); ?>
2788 </label>
2789 <p class="description">
2790 <?php
2791 $base = absint( $options['rate_limiting']['block_duration'] ?? 300 );
2792 printf(
2793 /* translators: 1: First block duration, 2: Second, 3: Third */
2794 esc_html__( 'Example: %1$s → %2$s → %3$s and so on, up to the maximum.', 'vigilante' ),
2795 esc_html( human_time_diff( 0, $base ) ),
2796 esc_html( human_time_diff( 0, $base * 2 ) ),
2797 esc_html( human_time_diff( 0, $base * 4 ) )
2798 );
2799 ?>
2800 </p>
2801 </td>
2802 </tr>
2803 <tr>
2804 <th scope="row"><?php esc_html_e( 'Maximum Block Duration', 'vigilante' ); ?></th>
2805 <td>
2806 <select name="firewall[rate_limiting][max_block_duration]">
2807 <?php
2808 $max_options = array(
2809 3600 => __( '1 hour', 'vigilante' ),
2810 21600 => __( '6 hours', 'vigilante' ),
2811 43200 => __( '12 hours', 'vigilante' ),
2812 86400 => __( '24 hours', 'vigilante' ),
2813 604800 => __( '7 days', 'vigilante' ),
2814 );
2815 $current_max = absint( $options['rate_limiting']['max_block_duration'] ?? 86400 );
2816 foreach ( $max_options as $val => $label ) :
2817 ?>
2818 <option value="<?php echo esc_attr( $val ); ?>" <?php selected( $current_max, $val ); ?>>
2819 <?php echo esc_html( $label ); ?>
2820 </option>
2821 <?php endforeach; ?>
2822 </select>
2823 <p class="description"><?php esc_html_e( 'Upper limit for progressive blocking.', 'vigilante' ); ?></p>
2824 </td>
2825 </tr>
2826 </table>
2827
2828 <?php
2829 // Currently blocked IPs from rate limiting
2830 $active_blocks = Vigilante_Firewall::get_active_blocks();
2831 if ( ! empty( $active_blocks ) ) :
2832 ?>
2833 <div class="vigilante-settings-section vigilante-lockout-section" style="margin-top:20px;">
2834 <h3><?php esc_html_e( 'Currently Blocked IPs', 'vigilante' ); ?></h3>
2835 <table class="wp-list-table widefat fixed striped" style="max-width:800px;">
2836 <thead>
2837 <tr>
2838 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
2839 <th><?php esc_html_e( 'Blocked', 'vigilante' ); ?></th>
2840 <th><?php esc_html_e( 'Expires in', 'vigilante' ); ?></th>
2841 <th><?php esc_html_e( 'Strikes', 'vigilante' ); ?></th>
2842 <th><?php esc_html_e( 'Action', 'vigilante' ); ?></th>
2843 </tr>
2844 </thead>
2845 <tbody>
2846 <?php foreach ( $active_blocks as $blocked_ip => $block_data ) : ?>
2847 <tr>
2848 <td><code><?php echo esc_html( $blocked_ip ); ?></code></td>
2849 <td><?php echo esc_html( human_time_diff( $block_data['blocked_at'] ) . ' ' . __( 'ago', 'vigilante' ) ); ?></td>
2850 <td><?php echo esc_html( human_time_diff( time(), $block_data['expires'] ) ); ?></td>
2851 <td><?php echo esc_html( $block_data['strikes'] ?? 1 ); ?></td>
2852 <td>
2853 <button type="button" class="button button-small vigilante-unblock-firewall-ip"
2854 data-ip="<?php echo esc_attr( $blocked_ip ); ?>">
2855 <?php esc_html_e( 'Unblock', 'vigilante' ); ?>
2856 </button>
2857 </td>
2858 </tr>
2859 <?php endforeach; ?>
2860 </tbody>
2861 </table>
2862 </div>
2863 <?php endif; ?>
2864
2865 <h3><?php esc_html_e( 'IP Lists', 'vigilante' ); ?></h3>
2866 <p class="description">
2867 <?php
2868 printf(
2869 /* translators: %s: Current visitor IP address */
2870 esc_html__( 'Your current IP address: %s', 'vigilante' ),
2871 '<code>' . esc_html( $this->database->get_client_ip() ) . '</code>'
2872 );
2873 ?>
2874 </p>
2875 <table class="form-table">
2876 <tr>
2877 <th scope="row"><?php esc_html_e( 'Visitor IP detection', 'vigilante' ); ?></th>
2878 <td>
2879 <?php $proxy_header = $options['trusted_proxy_header'] ?? ''; ?>
2880 <select name="firewall[trusted_proxy_header]">
2881 <option value="" <?php selected( $proxy_header, '' ); ?>><?php esc_html_e( 'Direct connection, only REMOTE_ADDR (recommended)', 'vigilante' ); ?></option>
2882 <option value="cf-connecting-ip" <?php selected( $proxy_header, 'cf-connecting-ip' ); ?>><?php esc_html_e( 'Behind Cloudflare (CF-Connecting-IP)', 'vigilante' ); ?></option>
2883 <option value="x-forwarded-for" <?php selected( $proxy_header, 'x-forwarded-for' ); ?>><?php esc_html_e( 'Behind a reverse proxy or load balancer (X-Forwarded-For)', 'vigilante' ); ?></option>
2884 <option value="x-real-ip" <?php selected( $proxy_header, 'x-real-ip' ); ?>><?php esc_html_e( 'Behind an nginx proxy (X-Real-IP)', 'vigilante' ); ?></option>
2885 </select>
2886 <p class="description">
2887 <?php esc_html_e( 'Where to read the visitor IP from. Leave on "Direct connection" unless your site really sits behind that proxy or CDN. Trusting a forwarded header on a site that is not behind it lets visitors spoof their IP and bypass the IP lists and rate limiting.', 'vigilante' ); ?>
2888 </p>
2889 </td>
2890 </tr>
2891 <tr>
2892 <th scope="row"><?php esc_html_e( 'IP Whitelist', 'vigilante' ); ?></th>
2893 <td>
2894 <textarea name="firewall[ip_whitelist]" rows="4" class="large-text code" placeholder="192.168.1.50&#10;192.168.1.0/24&#10;192.168.1.*"><?php echo esc_textarea( implode( "\n", $options['ip_whitelist'] ?? array() ) ); ?></textarea>
2895 <p class="description">
2896 <?php esc_html_e( 'One IP per line. These IPs will bypass firewall checks.', 'vigilante' ); ?>
2897 <br>
2898 <?php
2899 printf(
2900 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the IP, CIDR and wildcard examples. */
2901 esc_html__( 'Accepts exact IPs (%1$s192.168.1.50%2$s), CIDR ranges (%1$s192.168.1.0/24%2$s, IPv4 and IPv6), and wildcards with %1$s*%2$s (e.g. %1$s192.168.1.*%2$s).', 'vigilante' ),
2902 '<code>',
2903 '</code>'
2904 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
2905 ?>
2906 </p>
2907 </td>
2908 </tr>
2909 <tr>
2910 <th scope="row"><?php esc_html_e( 'IP Blacklist', 'vigilante' ); ?></th>
2911 <td>
2912 <textarea name="firewall[ip_blacklist]" rows="4" class="large-text code" placeholder="203.0.113.42&#10;203.0.113.0/24&#10;203.0.113.*"><?php echo esc_textarea( implode( "\n", $options['ip_blacklist'] ?? array() ) ); ?></textarea>
2913 <p class="description">
2914 <?php esc_html_e( 'One IP per line. These IPs will be blocked immediately.', 'vigilante' ); ?>
2915 <br>
2916 <?php
2917 printf(
2918 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the IP, CIDR and wildcard examples. */
2919 esc_html__( 'Accepts exact IPs (%1$s203.0.113.42%2$s), CIDR ranges (%1$s203.0.113.0/24%2$s, IPv4 and IPv6), and wildcards with %1$s*%2$s (e.g. %1$s203.0.113.*%2$s).', 'vigilante' ),
2920 '<code>',
2921 '</code>'
2922 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
2923 ?>
2924 </p>
2925 </td>
2926 </tr>
2927 </table>
2928
2929 <h3><?php esc_html_e( 'User-Agent Lists', 'vigilante' ); ?></h3>
2930 <p><?php esc_html_e( 'Partial matching: enter a keyword and any User-Agent containing it will be matched.', 'vigilante' ); ?></p>
2931 <table class="form-table">
2932 <tr>
2933 <th scope="row"><?php esc_html_e( 'User-Agent Whitelist', 'vigilante' ); ?></th>
2934 <td>
2935 <textarea name="firewall[ua_whitelist]" rows="4" class="large-text code"><?php echo esc_textarea( implode( "\n", $options['ua_whitelist'] ?? array() ) ); ?></textarea>
2936 <p class="description"><?php esc_html_e( 'One User-Agent per line. These will bypass all firewall checks. Example: ManageWP, MainWP, UptimeRobot.', 'vigilante' ); ?></p>
2937 </td>
2938 </tr>
2939 <tr>
2940 <th scope="row"><?php esc_html_e( 'User-Agent Blacklist', 'vigilante' ); ?></th>
2941 <td>
2942 <textarea name="firewall[ua_blacklist]" rows="4" class="large-text code"><?php echo esc_textarea( implode( "\n", $options['ua_blacklist'] ?? array() ) ); ?></textarea>
2943 <p class="description"><?php esc_html_e( 'One User-Agent per line. These will be blocked immediately.', 'vigilante' ); ?></p>
2944 </td>
2945 </tr>
2946 </table>
2947 </div>
2948
2949 <div id="vigilante-section-firewall-server" class="vigilante-settings-section">
2950 <h2>
2951 <?php esc_html_e( 'Server Protection', 'vigilante' ); ?>
2952 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
2953 </h2>
2954 <p><?php esc_html_e( 'Server-level rules for Apache/LiteSpeed. These rules are processed before PHP.', 'vigilante' ); ?></p>
2955
2956 <table class="form-table">
2957 <tr id="field-disable-directory-browsing">
2958 <th scope="row"><?php esc_html_e( 'Directory Browsing', 'vigilante' ); ?></th>
2959 <td>
2960 <label>
2961 <input type="checkbox" name="firewall[disable_directory_browsing]" value="1" <?php checked( ! empty( $options['disable_directory_browsing'] ) ); ?>>
2962 <?php esc_html_e( 'Disable directory listing (Options -Indexes)', 'vigilante' ); ?>
2963 </label>
2964 </td>
2965 </tr>
2966 <tr>
2967 <th scope="row"><?php esc_html_e( 'Protect wp-config.php', 'vigilante' ); ?></th>
2968 <td>
2969 <label>
2970 <input type="checkbox" name="firewall[protect_wp_config]" value="1" <?php checked( ! empty( $options['protect_wp_config'] ) ); ?>>
2971 <?php esc_html_e( 'Block direct HTTP access to wp-config.php', 'vigilante' ); ?>
2972 </label>
2973 </td>
2974 </tr>
2975 <tr id="field-protect-wp-cron">
2976 <th scope="row"><?php esc_html_e( 'Protect wp-cron.php', 'vigilante' ); ?></th>
2977 <td>
2978 <label>
2979 <input type="checkbox" name="firewall[protect_wp_cron]" value="1" <?php checked( ! empty( $options['protect_wp_cron'] ) ); ?>>
2980 <?php esc_html_e( 'Block direct HTTP access to wp-cron.php (prevents cron-spam DoS abuse)', 'vigilante' ); ?>
2981 </label>
2982 <p class="description"><?php
2983 printf(
2984 /* translators: 1: opening <strong>, 2: closing </strong> */
2985 esc_html__( '%1$sWarning:%2$s Only enable if your host runs a real server-side cron job calling wp-cron.php (most managed WordPress hosts do; check with your provider). Otherwise scheduled tasks — publishing, updates, emails, backups — stop running. Pair with %3$sDISABLE_WP_CRON%4$s in WP Hardening for full coverage.', 'vigilante' ),
2986 '<strong>',
2987 '</strong>',
2988 '<code>',
2989 '</code>'
2990 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
2991 ?></p>
2992 </td>
2993 </tr>
2994 <tr>
2995 <th scope="row"><?php esc_html_e( 'Protect wp-includes', 'vigilante' ); ?></th>
2996 <td>
2997 <label>
2998 <input type="checkbox" name="firewall[protect_wp_includes]" value="1" <?php checked( ! empty( $options['protect_wp_includes'] ) ); ?>>
2999 <?php esc_html_e( 'Block direct access to PHP files in wp-includes', 'vigilante' ); ?>
3000 </label>
3001 </td>
3002 </tr>
3003 <tr>
3004 <th scope="row"><?php esc_html_e( 'PHP in Uploads', 'vigilante' ); ?></th>
3005 <td>
3006 <label>
3007 <input type="checkbox" name="firewall[protect_uploads_php]" value="1" <?php checked( ! empty( $options['protect_uploads_php'] ) ); ?>>
3008 <?php esc_html_e( 'Block PHP execution in wp-content/uploads', 'vigilante' ); ?>
3009 </label>
3010 </td>
3011 </tr>
3012 <tr>
3013 <th scope="row"><?php esc_html_e( 'Sensitive Files', 'vigilante' ); ?></th>
3014 <td>
3015 <label>
3016 <input type="checkbox" name="firewall[protect_sensitive_files]" value="1" <?php checked( ! empty( $options['protect_sensitive_files'] ) ); ?>>
3017 <?php esc_html_e( 'Block access to .sql, .bak, .log, .ini, readme.html, license.txt, licencia.txt', 'vigilante' ); ?>
3018 </label>
3019 </td>
3020 </tr>
3021 <tr>
3022 <th scope="row"><?php esc_html_e( 'Limit HTTP Methods', 'vigilante' ); ?></th>
3023 <td>
3024 <label>
3025 <input type="checkbox" name="firewall[limit_http_methods]" value="1" <?php checked( ! empty( $options['limit_http_methods'] ) ); ?>>
3026 <?php esc_html_e( 'Allow only GET, POST, HEAD (blocks PUT, DELETE, TRACE, etc.)', 'vigilante' ); ?>
3027 </label>
3028 </td>
3029 </tr>
3030 </table>
3031 </div>
3032
3033 <p class="submit vigilante-submit-buttons">
3034 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
3035 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
3036 </button>
3037 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
3038 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
3039 </button>
3040 </p>
3041 </form>
3042 <?php
3043 }
3044
3045 /**
3046 * Render login security tab
3047 */
3048 private function render_tab_login() {
3049 $is_disabled = $this->render_module_disabled_notice( 'login_security' );
3050 $options = $this->settings->get_section( 'login_security' );
3051 $lockouts = $this->database->get_active_lockouts();
3052 ?>
3053 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="login_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
3054 <div id="vigilante-section-login-main" class="vigilante-settings-section">
3055 <h2>
3056 <?php esc_html_e( 'Login Protection', 'vigilante' ); ?>
3057 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
3058 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
3059 </h2>
3060 <p><?php esc_html_e( 'Brute force protection and WordPress login hardening.', 'vigilante' ); ?></p>
3061
3062 <table class="form-table">
3063 <tr id="field-max-attempts">
3064 <th scope="row"><?php esc_html_e( 'Max Login Attempts', 'vigilante' ); ?></th>
3065 <td>
3066 <input type="number" name="login_security[max_attempts]" value="<?php echo esc_attr( $options['max_attempts'] ?? 5 ); ?>" min="1" max="20" class="small-text">
3067 <p class="description"><?php esc_html_e( 'Number of failed attempts before lockout.', 'vigilante' ); ?></p>
3068 </td>
3069 </tr>
3070 <tr>
3071 <th scope="row"><?php esc_html_e( 'Lockout Duration', 'vigilante' ); ?></th>
3072 <td>
3073 <input type="number" name="login_security[lockout_duration]" value="<?php echo esc_attr( ( $options['lockout_duration'] ?? 1800 ) / 60 ); ?>" min="1" max="1440" class="small-text">
3074 <?php esc_html_e( 'minutes', 'vigilante' ); ?>
3075 </td>
3076 </tr>
3077 <tr>
3078 <th scope="row"><?php esc_html_e( 'Progressive Lockout', 'vigilante' ); ?></th>
3079 <td>
3080 <label>
3081 <input type="checkbox" name="login_security[lockout_increment]" value="1" <?php checked( ! empty( $options['lockout_increment'] ) ); ?>>
3082 <?php esc_html_e( 'Double lockout duration for repeat offenders', 'vigilante' ); ?>
3083 </label>
3084 </td>
3085 </tr>
3086 <tr>
3087 <th scope="row"><?php esc_html_e( 'Hide Login Errors', 'vigilante' ); ?></th>
3088 <td>
3089 <label>
3090 <input type="checkbox" name="login_security[hide_login_errors]" value="1" <?php checked( ! empty( $options['hide_login_errors'] ) ); ?>>
3091 <?php esc_html_e( 'Show generic error message instead of specific errors', 'vigilante' ); ?>
3092 </label>
3093 </td>
3094 </tr>
3095 <tr id="field-disable-xmlrpc">
3096 <th scope="row"><?php esc_html_e( 'Disable XML-RPC', 'vigilante' ); ?></th>
3097 <td>
3098 <label>
3099 <input type="checkbox" name="login_security[disable_xmlrpc]" value="1" <?php checked( ! empty( $options['disable_xmlrpc'] ) ); ?>>
3100 <?php esc_html_e( 'Completely disable XML-RPC functionality', 'vigilante' ); ?>
3101 </label>
3102 </td>
3103 </tr>
3104 <tr>
3105 <th scope="row"><?php esc_html_e( 'Disable Application Passwords', 'vigilante' ); ?></th>
3106 <td>
3107 <label>
3108 <input type="checkbox" name="login_security[disable_application_passwords]" value="1" <?php checked( ! empty( $options['disable_application_passwords'] ) ); ?>>
3109 <?php esc_html_e( 'Disable WordPress application passwords feature', 'vigilante' ); ?>
3110 </label>
3111 </td>
3112 </tr>
3113 </table>
3114
3115 <h3><?php esc_html_e( 'Custom Login URL', 'vigilante' ); ?></h3>
3116 <table class="form-table">
3117 <tr id="field-custom-login-url">
3118 <th scope="row"><?php esc_html_e( 'Login URL Slug', 'vigilante' ); ?></th>
3119 <td>
3120 <code><?php echo esc_url( home_url( '/' ) ); ?></code>
3121 <input type="text" name="login_security[custom_login_url]" id="vigilante_custom_login_url" value="<?php echo esc_attr( $options['custom_login_url'] ?? '' ); ?>" class="regular-text" placeholder="<?php esc_attr_e( 'my-secret-login', 'vigilante' ); ?>">
3122 <p class="description">
3123 <?php esc_html_e( '&#9432; Leave empty to use default wp-login.php. Use only lowercase letters, numbers and hyphens.', 'vigilante' ); ?>
3124 </p>
3125 <div class="vigilante-login-url-preview" <?php echo empty( $options['custom_login_url'] ) ? 'style="display:none;"' : ''; ?>>
3126 <p class="description">
3127 <strong><?php esc_html_e( 'Your login URL:', 'vigilante' ); ?></strong>
3128 <code class="vigilante-login-url-display"><?php echo esc_url( home_url( sanitize_title( $options['custom_login_url'] ?? '' ) . '/' ) ); ?></code>
3129 </p>
3130 <p class="description">
3131 <?php esc_html_e( 'Direct access to wp-login.php and wp-admin will return a 404 error for non-logged users.', 'vigilante' ); ?>
3132 </p>
3133 </div>
3134 </td>
3135 </tr>
3136 </table>
3137
3138 <div class="vigilante-login-url-notify-wrapper <?php echo empty( $options['custom_login_url'] ) ? 'vigilante-login-url-notify-disabled' : ''; ?>">
3139 <table class="form-table">
3140 <tr>
3141 <th scope="row"><?php esc_html_e( 'Notify users', 'vigilante' ); ?></th>
3142 <td>
3143 <label>
3144 <input type="checkbox" name="login_security[notify_on_login_url_change]" id="vigilante_notify_login_url_change" value="1" <?php checked( $options['notify_on_login_url_change'] ?? true ); ?>>
3145 <?php esc_html_e( 'Notify affected users when the login URL changes', 'vigilante' ); ?>
3146 </label>
3147 <div class="vigilante-login-url-send-notification" style="margin-top:12px;">
3148 <button type="button" id="vigilante_notify_login_url" class="button">
3149 <?php esc_html_e( 'Send notification now', 'vigilante' ); ?>
3150 </button>
3151 <span class="vigilante-login-url-notify-status"></span>
3152 <p class="description"><?php esc_html_e( 'Sends the new URL to administrators, editors, authors, and contributors.', 'vigilante' ); ?></p>
3153 </div>
3154 </td>
3155 </tr>
3156 </table>
3157 </div>
3158
3159 <?php $this->render_2fa_settings( $options ); ?>
3160
3161 <h3><?php esc_html_e( 'Notifications', 'vigilante' ); ?></h3>
3162 <table class="form-table">
3163 <tr>
3164 <th scope="row"><?php esc_html_e( 'Notify on Lockout', 'vigilante' ); ?></th>
3165 <td>
3166 <label>
3167 <input type="checkbox" name="login_security[notify_on_lockout]" value="1" <?php checked( ! empty( $options['notify_on_lockout'] ) ); ?>>
3168 <?php esc_html_e( 'Send email when an IP is locked out', 'vigilante' ); ?>
3169 </label>
3170 </td>
3171 </tr>
3172 <tr>
3173 <th scope="row"><?php esc_html_e( 'Notify on Admin Login', 'vigilante' ); ?></th>
3174 <td>
3175 <label>
3176 <input type="checkbox" name="login_security[notify_on_admin_login]" value="1" <?php checked( ! empty( $options['notify_on_admin_login'] ) ); ?>>
3177 <?php esc_html_e( 'Send email when an administrator logs in', 'vigilante' ); ?>
3178 </label>
3179 </td>
3180 </tr>
3181 </table>
3182
3183 <p class="description">
3184 <?php
3185 printf(
3186 /* translators: %s: Link to notification settings */
3187 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
3188 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
3189 );
3190 ?>
3191 </p>
3192 </div>
3193
3194 <p class="submit vigilante-submit-buttons">
3195 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
3196 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
3197 </button>
3198 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
3199 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
3200 </button>
3201 </p>
3202 </form>
3203
3204 <?php $this->render_lockout_info_section( $options, $lockouts ); ?>
3205 <?php
3206 }
3207
3208 /**
3209 * Render lockout information and blocked IPs section
3210 *
3211 * @param array $options Login security options.
3212 * @param array $lockouts Currently locked out IPs.
3213 */
3214 private function render_lockout_info_section( $options, $lockouts ) {
3215 $max_attempts = absint( $options['max_attempts'] ?? 5 );
3216 $lockout_duration = absint( $options['lockout_duration'] ?? 1800 );
3217 $lockout_increment = ! empty( $options['lockout_increment'] );
3218 $max_lockout = absint( $options['max_lockout_duration'] ?? 86400 );
3219 $two_factor = $options['two_factor'] ?? array();
3220 $two_factor_enabled = ! empty( $two_factor['enabled'] );
3221 ?>
3222 <div class="vigilante-settings-section vigilante-lockout-section">
3223 <h2><?php esc_html_e( 'Login Protection Status', 'vigilante' ); ?></h2>
3224
3225 <table class="form-table">
3226 <tr>
3227 <th scope="row"><?php esc_html_e( 'Current settings', 'vigilante' ); ?></th>
3228 <td>
3229 <?php
3230 printf(
3231 /* translators: 1: Maximum login attempts, 2: Lockout duration in minutes */
3232 esc_html__( 'After %1$d failed login attempts, the IP address is blocked for %2$d minutes.', 'vigilante' ),
3233 absint( $max_attempts ),
3234 absint( ceil( $lockout_duration / 60 ) )
3235 );
3236
3237 if ( $lockout_increment ) {
3238 echo '<br>';
3239 printf(
3240 /* translators: %d: Maximum lockout duration in hours */
3241 esc_html__( 'Progressive lockout enabled (max: %d hours).', 'vigilante' ),
3242 absint( ceil( $max_lockout / 3600 ) )
3243 );
3244 }
3245
3246 if ( $two_factor_enabled ) {
3247 echo '<br>';
3248 esc_html_e( 'Failed 2FA codes also count toward the lockout limit.', 'vigilante' );
3249 }
3250 ?>
3251 </td>
3252 </tr>
3253 <tr>
3254 <th scope="row"><?php esc_html_e( 'Blocked IPs', 'vigilante' ); ?></th>
3255 <td>
3256 <?php if ( ! empty( $lockouts ) ) : ?>
3257 <div class="vigilante-paginated-section">
3258 <div class="vigilante-fi-pagination-wrap"></div>
3259 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
3260 <thead>
3261 <tr>
3262 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
3263 <th><?php esc_html_e( 'Attempts', 'vigilante' ); ?></th>
3264 <th><?php esc_html_e( 'Blocked Until', 'vigilante' ); ?></th>
3265 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
3266 </tr>
3267 </thead>
3268 <tbody>
3269 <?php foreach ( $lockouts as $lockout ) :
3270 $lockout_time = strtotime( $lockout->locked_until );
3271 $remaining_seconds = $lockout_time - time();
3272 $remaining_text = $this->format_remaining_time( $remaining_seconds );
3273 ?>
3274 <tr>
3275 <td><code><?php echo esc_html( $lockout->ip_address ); ?></code></td>
3276 <td><?php echo esc_html( $lockout->attempts ); ?></td>
3277 <td>
3278 <?php echo esc_html( wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $lockout_time ) ); ?>
3279 <br>
3280 <small class="description">
3281 <?php
3282 printf(
3283 /* translators: %s: Remaining time */
3284 esc_html__( '%s remaining', 'vigilante' ),
3285 esc_html( $remaining_text )
3286 );
3287 ?>
3288 </small>
3289 </td>
3290 <td>
3291 <button type="button" class="button button-small vigilante-clear-lockout" data-ip="<?php echo esc_attr( $lockout->ip_address ); ?>">
3292 <?php esc_html_e( 'Unblock', 'vigilante' ); ?>
3293 </button>
3294 </td>
3295 </tr>
3296 <?php endforeach; ?>
3297 </tbody>
3298 </table>
3299 </div>
3300 <p class="description" style="margin-top: 10px;">
3301 <button type="button" class="button vigilante-clear-all-lockouts">
3302 <?php esc_html_e( 'Unblock All IPs', 'vigilante' ); ?>
3303 </button>
3304 <span style="margin-left: 10px;">
3305 <?php
3306 printf(
3307 /* translators: %d: Number of blocked IPs */
3308 esc_html( _n( '%d IP currently blocked', '%d IPs currently blocked', count( $lockouts ), 'vigilante' ) ),
3309 count( $lockouts )
3310 );
3311 ?>
3312 </span>
3313 </p>
3314 <?php else : ?>
3315 <span class="dashicons dashicons-yes-alt" style="color: #00a32a; font-size: 20px; width: 20px; height: 20px; vertical-align: middle;"></span>
3316 <span style="vertical-align: middle; margin-left: 5px;"><?php esc_html_e( 'No IPs are currently blocked. All clear!', 'vigilante' ); ?></span>
3317 <?php endif; ?>
3318 </td>
3319 </tr>
3320 </table>
3321 </div>
3322 <?php
3323 }
3324
3325 /**
3326 * Format remaining lockout time in human readable format
3327 *
3328 * @param int $seconds Remaining seconds.
3329 * @return string Formatted time string.
3330 */
3331 private function format_remaining_time( $seconds ) {
3332 if ( $seconds <= 0 ) {
3333 return __( 'expired', 'vigilante' );
3334 }
3335
3336 if ( $seconds < 60 ) {
3337 return sprintf(
3338 /* translators: %d: Number of seconds */
3339 _n( '%d second', '%d seconds', $seconds, 'vigilante' ),
3340 $seconds
3341 );
3342 }
3343
3344 if ( $seconds < 3600 ) {
3345 $minutes = ceil( $seconds / 60 );
3346 return sprintf(
3347 /* translators: %d: Number of minutes */
3348 _n( '%d minute', '%d minutes', $minutes, 'vigilante' ),
3349 $minutes
3350 );
3351 }
3352
3353 $hours = floor( $seconds / 3600 );
3354 $remaining_minutes = ceil( ( $seconds % 3600 ) / 60 );
3355
3356 if ( $remaining_minutes > 0 ) {
3357 return sprintf(
3358 /* translators: 1: Number of hours, 2: Number of minutes */
3359 __( '%1$d hours %2$d minutes', 'vigilante' ),
3360 $hours,
3361 $remaining_minutes
3362 );
3363 }
3364
3365 return sprintf(
3366 /* translators: %d: Number of hours */
3367 _n( '%d hour', '%d hours', $hours, 'vigilante' ),
3368 $hours
3369 );
3370 }
3371
3372 /**
3373 * Render 2FA settings section
3374 *
3375 * @param array $options Login security options.
3376 */
3377 private function render_2fa_settings( $options ) {
3378 $two_factor = $options['two_factor'] ?? array();
3379 $all_roles = wp_roles()->roles;
3380 $enforced = $two_factor['enforced_roles'] ?? array( 'administrator', 'editor' );
3381 $excluded = $two_factor['excluded_users'] ?? array();
3382 $method = $two_factor['method'] ?? 'email';
3383 $grace_days = $two_factor['grace_period_days'] ?? 3;
3384 ?>
3385 <h3>
3386 <?php esc_html_e( 'Two-Factor Authentication (2FA)', 'vigilante' ); ?>
3387 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
3388 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
3389 </h3>
3390 <p class="description"><?php esc_html_e( 'Require a second verification step after password. Choose between email codes or an authenticator app (TOTP).', 'vigilante' ); ?></p>
3391
3392 <table class="form-table">
3393 <tr>
3394 <th scope="row"><?php esc_html_e( 'Enable 2FA', 'vigilante' ); ?></th>
3395 <td>
3396 <label>
3397 <input type="checkbox" name="login_security[two_factor][enabled]" id="vigilante_2fa_enabled" value="1" <?php checked( ! empty( $two_factor['enabled'] ) ); ?>>
3398 <?php esc_html_e( 'Enable two-factor authentication', 'vigilante' ); ?>
3399 </label>
3400 </td>
3401 </tr>
3402 </table>
3403
3404 <div class="vigilante-2fa-settings-wrapper <?php echo empty( $two_factor['enabled'] ) ? 'vigilante-2fa-settings-disabled' : ''; ?>">
3405 <table class="form-table">
3406 <tr>
3407 <th scope="row"><?php esc_html_e( 'Verification method', 'vigilante' ); ?></th>
3408 <td>
3409 <fieldset class="vigilante-2fa-method-selector">
3410 <label class="vigilante-2fa-method-option <?php echo 'email' === $method ? 'selected' : ''; ?>">
3411 <input type="radio" name="login_security[two_factor][method]" value="email" <?php checked( $method, 'email' ); ?>>
3412 <span class="dashicons dashicons-email"></span>
3413 <span class="method-info">
3414 <strong><?php esc_html_e( 'Email code', 'vigilante' ); ?></strong>
3415 <span><?php esc_html_e( 'Users receive a 6-digit code via email after entering their password.', 'vigilante' ); ?></span>
3416 </span>
3417 </label>
3418 <label class="vigilante-2fa-method-option <?php echo 'totp' === $method ? 'selected' : ''; ?>">
3419 <input type="radio" name="login_security[two_factor][method]" value="totp" <?php checked( $method, 'totp' ); ?>>
3420 <span class="dashicons dashicons-smartphone"></span>
3421 <span class="method-info">
3422 <strong><?php esc_html_e( 'Authenticator app (TOTP)', 'vigilante' ); ?></strong>
3423 <span><?php esc_html_e( 'Users verify with a time-based code from Google Authenticator, Authy, etc.', 'vigilante' ); ?></span>
3424 </span>
3425 </label>
3426 </fieldset>
3427 </td>
3428 </tr>
3429 <tr>
3430 <th scope="row"><?php esc_html_e( 'Enforce for roles', 'vigilante' ); ?></th>
3431 <td>
3432 <div class="vigilante-2fa-roles">
3433 <?php foreach ( $all_roles as $role_slug => $role_data ) :
3434 $user_count = count( get_users( array( 'role' => $role_slug, 'fields' => 'ID' ) ) );
3435 ?>
3436 <label>
3437 <input type="checkbox"
3438 name="login_security[two_factor][enforced_roles][]"
3439 value="<?php echo esc_attr( $role_slug ); ?>"
3440 <?php checked( in_array( $role_slug, $enforced, true ) ); ?>>
3441 <span class="role-name"><?php echo esc_html( translate_user_role( $role_data['name'] ) ); ?></span>
3442 <span class="role-count">(<?php echo esc_html( $user_count ); ?>)</span>
3443 </label>
3444 <?php endforeach; ?>
3445 </div>
3446 <p class="description"><?php esc_html_e( 'Users with these roles will be required to verify with the selected method.', 'vigilante' ); ?></p>
3447 </td>
3448 </tr>
3449 <tr>
3450 <th scope="row"><?php esc_html_e( 'Exclude specific users', 'vigilante' ); ?></th>
3451 <td>
3452 <div class="vigilante-2fa-user-search-container">
3453 <div class="vigilante-2fa-user-search">
3454 <span class="search-icon"></span>
3455 <input type="text"
3456 id="vigilante_2fa_user_search"
3457 placeholder="<?php esc_attr_e( 'Search users by name or email...', 'vigilante' ); ?>"
3458 autocomplete="off">
3459 <div class="vigilante-2fa-search-results"></div>
3460 </div>
3461 <div class="vigilante-2fa-excluded-users">
3462 <?php
3463 foreach ( $excluded as $user_id ) :
3464 $user = get_user_by( 'ID', $user_id );
3465 if ( ! $user ) continue;
3466 ?>
3467 <div class="vigilante-2fa-excluded-user" data-user-id="<?php echo esc_attr( $user_id ); ?>">
3468 <span class="user-display"><?php echo esc_html( $user->display_name . ' (' . $user->user_email . ')' ); ?></span>
3469 <button type="button" class="remove-user" aria-label="<?php esc_attr_e( 'Remove', 'vigilante' ); ?>">&times;</button>
3470 <input type="hidden" name="login_security[two_factor][excluded_users][]" value="<?php echo esc_attr( $user_id ); ?>">
3471 </div>
3472 <?php endforeach; ?>
3473 </div>
3474 </div>
3475 <p class="description"><?php esc_html_e( 'These users will not be required to use 2FA regardless of their role.', 'vigilante' ); ?></p>
3476 </td>
3477 </tr>
3478
3479 <!-- Remember device option -->
3480 <tr>
3481 <th scope="row"><?php esc_html_e( 'Remember device', 'vigilante' ); ?></th>
3482 <td>
3483 <label>
3484 <input type="checkbox" name="login_security[two_factor][allow_remember_device]" value="1" <?php checked( ! empty( $two_factor['allow_remember_device'] ) ); ?>>
3485 <?php esc_html_e( 'Allow users to skip 2FA verification on trusted devices', 'vigilante' ); ?>
3486 </label>
3487 <p class="description">
3488 <?php
3489 printf(
3490 /* translators: %d: Number of days */
3491 esc_html__( 'When enabled, users can check "Remember this device" on the verification screen to skip 2FA for %d days.', 'vigilante' ),
3492 absint( $two_factor['remember_device_days'] ?? 30 )
3493 );
3494 ?>
3495 </p>
3496 </td>
3497 </tr>
3498
3499 <!-- TOTP-specific: Grace period -->
3500 <tr class="vigilante-2fa-totp-only" <?php echo 'totp' !== $method ? 'style="display:none;"' : ''; ?>>
3501 <th scope="row"><?php esc_html_e( 'Grace period', 'vigilante' ); ?></th>
3502 <td>
3503 <input type="number"
3504 name="login_security[two_factor][grace_period_days]"
3505 value="<?php echo esc_attr( $grace_days ); ?>"
3506 min="0" max="30" class="small-text">
3507 <?php esc_html_e( 'days', 'vigilante' ); ?>
3508 <p class="description"><?php esc_html_e( 'Days users have to set up their authenticator app. During this period they can log in without TOTP. Set to 0 for immediate enforcement.', 'vigilante' ); ?></p>
3509 </td>
3510 </tr>
3511
3512 <!-- Email-specific: Sender name -->
3513 <tr class="vigilante-2fa-email-only" <?php echo 'email' !== $method ? 'style="display:none;"' : ''; ?>>
3514 <th scope="row"><?php esc_html_e( 'Email sender name', 'vigilante' ); ?></th>
3515 <td>
3516 <input type="text"
3517 name="login_security[two_factor][email_from_name]"
3518 value="<?php echo esc_attr( $two_factor['email_from_name'] ?? '' ); ?>"
3519 class="regular-text vigilante-2fa-email-from"
3520 placeholder="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>">
3521 <p class="description"><?php esc_html_e( 'Name shown in verification emails. Leave empty to use site name.', 'vigilante' ); ?></p>
3522 </td>
3523 </tr>
3524
3525 <!-- TOTP-specific: Reset users -->
3526 <tr class="vigilante-2fa-totp-only" <?php echo 'totp' !== $method ? 'style="display:none;"' : ''; ?>>
3527 <th scope="row"><?php esc_html_e( 'Reset user TOTP', 'vigilante' ); ?></th>
3528 <td>
3529 <div class="vigilante-totp-reset-container">
3530 <div class="vigilante-2fa-user-search">
3531 <span class="search-icon"></span>
3532 <input type="text"
3533 id="vigilante_totp_reset_search"
3534 placeholder="<?php esc_attr_e( 'Search users with TOTP configured...', 'vigilante' ); ?>"
3535 autocomplete="off">
3536 <div class="vigilante-totp-reset-results"></div>
3537 </div>
3538 <div class="vigilante-totp-reset-selected"></div>
3539 <button type="button" id="vigilante_totp_reset_btn" class="button" style="display:none;">
3540 <?php esc_html_e( 'Reset selected', 'vigilante' ); ?>
3541 </button>
3542 <span class="vigilante-totp-reset-status"></span>
3543 </div>
3544 <p class="description"><?php esc_html_e( 'Reset TOTP for users who lost access to their authenticator app. They will need to set up again.', 'vigilante' ); ?></p>
3545 </td>
3546 </tr>
3547 </table>
3548
3549 <h3><?php esc_html_e( 'User notification', 'vigilante' ); ?></h3>
3550 <table class="form-table">
3551 <tr>
3552 <th scope="row"><?php esc_html_e( 'Notify on enable', 'vigilante' ); ?></th>
3553 <td>
3554 <label>
3555 <input type="checkbox" name="login_security[two_factor][notify_on_enable]" value="1" <?php checked( $two_factor['notify_on_enable'] ?? true ); ?>>
3556 <?php esc_html_e( 'Send notification email to affected users when 2FA is enabled', 'vigilante' ); ?>
3557 </label>
3558
3559 <div class="vigilante-2fa-notification-options">
3560 <label>
3561 <input type="radio" name="vigilante_2fa_notify_mode" value="all" checked>
3562 <?php esc_html_e( 'Send to all affected users', 'vigilante' ); ?>
3563 </label>
3564 <label>
3565 <input type="radio" name="vigilante_2fa_notify_mode" value="new">
3566 <?php esc_html_e( 'Send only to users not previously notified', 'vigilante' ); ?>
3567 </label>
3568 </div>
3569
3570 <div class="vigilante-2fa-send-notification">
3571 <button type="button" id="vigilante_2fa_send_notification" class="button">
3572 <?php esc_html_e( 'Send notification now', 'vigilante' ); ?>
3573 </button>
3574 <span class="vigilante-2fa-notification-status"></span>
3575 </div>
3576 </td>
3577 </tr>
3578 </table>
3579 </div>
3580 <?php
3581 }
3582
3583 /**
3584 * Render security headers tab
3585 */
3586 private function render_tab_headers() {
3587 $is_disabled = $this->render_module_disabled_notice( 'security_headers' );
3588 $options = $this->settings->get_section( 'security_headers' );
3589 ?>
3590 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="security_headers" <?php echo $is_disabled ? 'inert' : ''; ?>>
3591 <div id="vigilante-section-headers-main" class="vigilante-settings-section">
3592 <h2>
3593 <?php esc_html_e( 'Security Headers', 'vigilante' ); ?>
3594 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
3595 </h2>
3596 <p><?php esc_html_e( 'HTTP headers sent with every response via .htaccess (mod_headers).', 'vigilante' ); ?></p>
3597
3598 <table class="form-table">
3599 <tr>
3600 <th scope="row"><?php esc_html_e( 'X-Frame-Options', 'vigilante' ); ?></th>
3601 <td>
3602 <select name="security_headers[x_frame_options]">
3603 <option value="" <?php selected( empty( $options['x_frame_options'] ) ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
3604 <option value="SAMEORIGIN" <?php selected( $options['x_frame_options'] ?? '', 'SAMEORIGIN' ); ?>>SAMEORIGIN</option>
3605 <option value="DENY" <?php selected( $options['x_frame_options'] ?? '', 'DENY' ); ?>>DENY</option>
3606 </select>
3607 <p class="description"><?php esc_html_e( '&#9432; Prevents clickjacking attacks. Also sets CSP frame-ancestors automatically.', 'vigilante' ); ?></p>
3608 </td>
3609 </tr>
3610 <tr>
3611 <th scope="row"><?php esc_html_e( 'X-Content-Type-Options', 'vigilante' ); ?></th>
3612 <td>
3613 <label>
3614 <input type="checkbox" name="security_headers[x_content_type_options]" value="1" <?php checked( ! empty( $options['x_content_type_options'] ) ); ?>>
3615 <?php esc_html_e( 'Add nosniff header to prevent MIME type sniffing', 'vigilante' ); ?>
3616 </label>
3617 </td>
3618 </tr>
3619 <tr>
3620 <th scope="row"><?php esc_html_e( 'Referrer-Policy', 'vigilante' ); ?></th>
3621 <td>
3622 <select name="security_headers[referrer_policy]">
3623 <option value="" <?php selected( empty( $options['referrer_policy'] ) ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
3624 <option value="no-referrer" <?php selected( $options['referrer_policy'] ?? '', 'no-referrer' ); ?>>no-referrer</option>
3625 <option value="strict-origin-when-cross-origin" <?php selected( $options['referrer_policy'] ?? '', 'strict-origin-when-cross-origin' ); ?>>strict-origin-when-cross-origin</option>
3626 <option value="same-origin" <?php selected( $options['referrer_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
3627 </select>
3628 </td>
3629 </tr>
3630 </table>
3631
3632 <h3><?php esc_html_e( 'HSTS (HTTP Strict Transport Security)', 'vigilante' ); ?></h3>
3633 <table class="form-table">
3634 <tr>
3635 <th scope="row"><?php esc_html_e( 'Enable HSTS', 'vigilante' ); ?></th>
3636 <td>
3637 <label>
3638 <input type="checkbox" name="security_headers[hsts][enabled]" value="1" <?php checked( ! empty( $options['hsts']['enabled'] ) ); ?>>
3639 <?php esc_html_e( 'Force HTTPS connections', 'vigilante' ); ?>
3640 </label>
3641 <p class="description"><?php esc_html_e( '&#9888; Warning: Only enable if your site fully supports HTTPS.', 'vigilante' ); ?></p>
3642 </td>
3643 </tr>
3644 <tr>
3645 <th scope="row"><?php esc_html_e( 'Max Age', 'vigilante' ); ?></th>
3646 <td>
3647 <select name="security_headers[hsts][max_age]">
3648 <option value="86400" <?php selected( $options['hsts']['max_age'] ?? 31536000, 86400 ); ?>><?php esc_html_e( '1 day (testing)', 'vigilante' ); ?></option>
3649 <option value="2592000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 2592000 ); ?>><?php esc_html_e( '30 days', 'vigilante' ); ?></option>
3650 <option value="31536000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 31536000 ); ?>><?php esc_html_e( '1 year (recommended)', 'vigilante' ); ?></option>
3651 <option value="63072000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 63072000 ); ?>><?php esc_html_e( '2 years', 'vigilante' ); ?></option>
3652 </select>
3653 </td>
3654 </tr>
3655 <tr>
3656 <th scope="row"><?php esc_html_e( 'Include Subdomains', 'vigilante' ); ?></th>
3657 <td>
3658 <label>
3659 <input type="checkbox" name="security_headers[hsts][include_subdomains]" value="1" <?php checked( ! empty( $options['hsts']['include_subdomains'] ) ); ?>>
3660 <?php esc_html_e( 'Apply HSTS to all subdomains', 'vigilante' ); ?>
3661 </label>
3662 </td>
3663 </tr>
3664 </table>
3665
3666 <h3><?php esc_html_e( 'Content Security Policy', 'vigilante' ); ?></h3>
3667 <table class="form-table">
3668 <tr>
3669 <th scope="row"><?php esc_html_e( 'Enable CSP', 'vigilante' ); ?></th>
3670 <td>
3671 <label>
3672 <input type="checkbox" name="security_headers[csp][enabled]" value="1" <?php checked( ! empty( $options['csp']['enabled'] ) ); ?>>
3673 <?php esc_html_e( 'Enable Content Security Policy', 'vigilante' ); ?>
3674 </label>
3675 </td>
3676 </tr>
3677 <tr>
3678 <th scope="row"><?php esc_html_e( 'Report Only Mode', 'vigilante' ); ?></th>
3679 <td>
3680 <label>
3681 <input type="checkbox" name="security_headers[csp][report_only]" value="1" <?php checked( ! empty( $options['csp']['report_only'] ) ); ?>>
3682 <?php esc_html_e( 'Report violations without blocking (for testing)', 'vigilante' ); ?>
3683 </label>
3684 </td>
3685 </tr>
3686 </table>
3687
3688 <h3><?php esc_html_e( 'Server Identity', 'vigilante' ); ?></h3>
3689 <p class="description"><?php esc_html_e( 'Hide identifying information that servers expose in responses.', 'vigilante' ); ?></p>
3690 <table class="form-table">
3691 <tr>
3692 <th scope="row"><?php esc_html_e( 'Server Signature', 'vigilante' ); ?></th>
3693 <td>
3694 <label>
3695 <input type="checkbox" name="security_headers[hide_server_signature]" value="1" <?php checked( ! empty( $options['hide_server_signature'] ) ); ?>>
3696 <?php esc_html_e( 'Hide server signature (ServerSignature Off)', 'vigilante' ); ?>
3697 </label>
3698 </td>
3699 </tr>
3700 <tr>
3701 <th scope="row"><?php esc_html_e( 'Remove Fingerprinting Headers', 'vigilante' ); ?></th>
3702 <td>
3703 <label>
3704 <input type="checkbox" name="security_headers[remove_fingerprinting_headers]" value="1" <?php checked( ! empty( $options['remove_fingerprinting_headers'] ) ); ?>>
3705 <?php esc_html_e( 'Remove X-Powered-By and Server headers', 'vigilante' ); ?>
3706 </label>
3707 </td>
3708 </tr>
3709 </table>
3710 </div>
3711
3712 <p class="submit vigilante-submit-buttons">
3713 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
3714 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
3715 </button>
3716 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
3717 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
3718 </button>
3719 <button type="button" class="button vigilante-test-headers">
3720 <?php esc_html_e( 'Test Headers', 'vigilante' ); ?>
3721 </button>
3722 </p>
3723 </form>
3724
3725 <div id="vigilante-headers-result"></div>
3726 <?php
3727 }
3728
3729 /**
3730 * Render REST API tab
3731 */
3732 private function render_tab_rest_api() {
3733 $is_disabled = $this->render_module_disabled_notice( 'rest_api_security' );
3734 $options = $this->settings->get_section( 'rest_api_security' );
3735 ?>
3736 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="rest_api_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
3737 <div id="vigilante-section-rest-api-main" class="vigilante-settings-section">
3738 <h2>
3739 <?php esc_html_e( 'REST API Security', 'vigilante' ); ?>
3740 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
3741 </h2>
3742 <p><?php esc_html_e( 'Control access to WordPress REST API endpoints.', 'vigilante' ); ?></p>
3743
3744 <table class="form-table">
3745 <tr>
3746 <th scope="row"><?php esc_html_e( 'Access Mode', 'vigilante' ); ?></th>
3747 <td>
3748 <select name="rest_api_security[mode]">
3749 <option value="open" <?php selected( $options['mode'] ?? 'selective', 'open' ); ?>><?php esc_html_e( 'Open - Allow all requests', 'vigilante' ); ?></option>
3750 <option value="selective" <?php selected( $options['mode'] ?? 'selective', 'selective' ); ?>><?php esc_html_e( 'Selective - Protect sensitive endpoints', 'vigilante' ); ?></option>
3751 <option value="authenticated_only" <?php selected( $options['mode'] ?? 'selective', 'authenticated_only' ); ?>><?php esc_html_e( 'Authenticated - Require login for all', 'vigilante' ); ?></option>
3752 </select>
3753 <p class="description"><?php esc_html_e( 'Selective mode is recommended.', 'vigilante' ); ?></p>
3754 </td>
3755 </tr>
3756 <tr id="field-block-user-enumeration">
3757 <th scope="row"><?php esc_html_e( 'Block User Enumeration', 'vigilante' ); ?></th>
3758 <td>
3759 <label>
3760 <input type="checkbox" name="rest_api_security[block_user_enumeration]" value="1" <?php checked( ! empty( $options['block_user_enumeration'] ) ); ?>>
3761 <?php esc_html_e( 'Protect /wp/v2/users endpoint for unauthenticated users', 'vigilante' ); ?>
3762 </label>
3763 </td>
3764 </tr>
3765 <tr>
3766 <th scope="row"><?php esc_html_e( 'Disable JSONP', 'vigilante' ); ?></th>
3767 <td>
3768 <label>
3769 <input type="checkbox" name="rest_api_security[disable_jsonp]" value="1" <?php checked( ! empty( $options['disable_jsonp'] ) ); ?>>
3770 <?php esc_html_e( 'Disable JSONP support in REST API', 'vigilante' ); ?>
3771 </label>
3772 </td>
3773 </tr>
3774 </table>
3775 </div>
3776
3777 <p class="submit vigilante-submit-buttons">
3778 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
3779 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
3780 </button>
3781 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
3782 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
3783 </button>
3784 </p>
3785 </form>
3786 <?php
3787 }
3788
3789 /**
3790 * Render User Security tab
3791 */
3792 private function render_tab_users() {
3793 $is_disabled = $this->render_module_disabled_notice( 'user_security' );
3794 $options = $this->settings->get_section( 'user_security' );
3795 $monitoring = $options['admin_monitoring'] ?? array();
3796 $registration = $options['registration_approval'] ?? array();
3797 $session_limits = $options['session_limits'] ?? array();
3798 $password_exp = $options['password_expiration'] ?? array();
3799 $email_verify = $options['email_verification'] ?? array();
3800 ?>
3801
3802 <!-- ============================================================
3803 SETTINGS SECTION - Single form for all configuration
3804 ============================================================ -->
3805 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="user_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
3806
3807 <!-- Username & Password Protection -->
3808 <div id="vigilante-section-users-password" class="vigilante-settings-section">
3809 <h2>
3810 <?php esc_html_e( 'Username & password protection', 'vigilante' ); ?>
3811 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
3812 </h2>
3813 <p><?php esc_html_e( 'Enforce secure username and password policies.', 'vigilante' ); ?></p>
3814
3815 <table class="form-table">
3816 <tr>
3817 <th scope="row"><?php esc_html_e( 'Block Insecure Usernames', 'vigilante' ); ?></th>
3818 <td>
3819 <label>
3820 <input type="checkbox" name="user_security[block_insecure_usernames]" value="1" <?php checked( ! empty( $options['block_insecure_usernames'] ) ); ?>>
3821 <?php esc_html_e( 'Prevent creation of users with common usernames (admin, administrator, etc.)', 'vigilante' ); ?>
3822 </label>
3823 </td>
3824 </tr>
3825 <?php
3826 $pw_policy = wp_parse_args(
3827 ( isset( $options['password_policy'] ) && is_array( $options['password_policy'] ) ) ? $options['password_policy'] : array(),
3828 array(
3829 'require_uppercase' => true,
3830 'require_lowercase' => true,
3831 'require_number' => true,
3832 'require_special' => true,
3833 'block_common' => true,
3834 'block_username' => false,
3835 'affected_roles' => array(),
3836 )
3837 );
3838 $pw_policy_roles = (array) $pw_policy['affected_roles'];
3839 ?>
3840 <tr>
3841 <th scope="row"><?php esc_html_e( 'Enforce Strong Passwords', 'vigilante' ); ?></th>
3842 <td>
3843 <label>
3844 <input type="checkbox" name="user_security[force_strong_passwords]" value="1" <?php checked( ! empty( $options['force_strong_passwords'] ) ); ?>>
3845 <?php esc_html_e( 'Check passwords against the requirements below when a user sets or changes one', 'vigilante' ); ?>
3846 </label>
3847 </td>
3848 </tr>
3849 <tr>
3850 <th scope="row"><?php esc_html_e( 'Minimum Password Length', 'vigilante' ); ?></th>
3851 <td>
3852 <input type="number" name="user_security[min_password_length]" value="<?php echo esc_attr( $options['min_password_length'] ?? 12 ); ?>" min="6" max="32" class="small-text">
3853 <?php esc_html_e( 'characters', 'vigilante' ); ?>
3854 </td>
3855 </tr>
3856 <tr>
3857 <th scope="row"><?php esc_html_e( 'Password Requirements', 'vigilante' ); ?></th>
3858 <td>
3859 <label style="display:block;margin-bottom:5px;">
3860 <input type="checkbox" name="user_security[password_policy][require_uppercase]" value="1" <?php checked( ! empty( $pw_policy['require_uppercase'] ) ); ?>>
3861 <?php esc_html_e( 'Require an uppercase letter (A-Z)', 'vigilante' ); ?>
3862 </label>
3863 <label style="display:block;margin-bottom:5px;">
3864 <input type="checkbox" name="user_security[password_policy][require_lowercase]" value="1" <?php checked( ! empty( $pw_policy['require_lowercase'] ) ); ?>>
3865 <?php esc_html_e( 'Require a lowercase letter (a-z)', 'vigilante' ); ?>
3866 </label>
3867 <label style="display:block;margin-bottom:5px;">
3868 <input type="checkbox" name="user_security[password_policy][require_number]" value="1" <?php checked( ! empty( $pw_policy['require_number'] ) ); ?>>
3869 <?php esc_html_e( 'Require a number (0-9)', 'vigilante' ); ?>
3870 </label>
3871 <label style="display:block;margin-bottom:5px;">
3872 <input type="checkbox" name="user_security[password_policy][require_special]" value="1" <?php checked( ! empty( $pw_policy['require_special'] ) ); ?>>
3873 <?php esc_html_e( 'Require a special character (!, @, #, ...)', 'vigilante' ); ?>
3874 </label>
3875 <label style="display:block;margin-bottom:5px;">
3876 <input type="checkbox" name="user_security[password_policy][block_common]" value="1" <?php checked( ! empty( $pw_policy['block_common'] ) ); ?>>
3877 <?php esc_html_e( 'Reject well-known common passwords', 'vigilante' ); ?>
3878 </label>
3879 <label style="display:block;margin-bottom:5px;">
3880 <input type="checkbox" name="user_security[password_policy][block_username]" value="1" <?php checked( ! empty( $pw_policy['block_username'] ) ); ?>>
3881 <?php esc_html_e( 'Do not allow the username inside the password', 'vigilante' ); ?>
3882 </label>
3883 <p class="description"><?php esc_html_e( 'These rules apply only while "Enforce Strong Passwords" is on. Turn off individual rules to allow, for example, long passphrases without numbers or symbols.', 'vigilante' ); ?></p>
3884 </td>
3885 </tr>
3886 <tr>
3887 <th scope="row"><?php esc_html_e( 'Apply Password Rules To', 'vigilante' ); ?></th>
3888 <td>
3889 <?php foreach ( wp_roles()->get_names() as $role_slug => $role_name ) : ?>
3890 <label style="display:block;margin-bottom:5px;">
3891 <input type="checkbox" name="user_security[password_policy][affected_roles][]" value="<?php echo esc_attr( $role_slug ); ?>" <?php checked( empty( $pw_policy_roles ) || in_array( $role_slug, $pw_policy_roles, true ) ); ?>>
3892 <?php echo esc_html( translate_user_role( $role_name ) ); ?>
3893 </label>
3894 <?php endforeach; ?>
3895 <p class="description"><?php esc_html_e( 'All roles are covered by default. Uncheck a role to exclude it from the password policy.', 'vigilante' ); ?></p>
3896 </td>
3897 </tr>
3898 <tr id="field-block-author-scanning">
3899 <th scope="row"><?php esc_html_e( 'Block Author Scanning', 'vigilante' ); ?></th>
3900 <td>
3901 <label>
3902 <input type="checkbox" name="user_security[block_author_scanning]" value="1" <?php checked( ! empty( $options['block_author_scanning'] ) ); ?>>
3903 <?php esc_html_e( 'Prevent username discovery via ?author=N URLs', 'vigilante' ); ?>
3904 </label>
3905 </td>
3906 </tr>
3907 <tr>
3908 <th scope="row"><?php esc_html_e( 'Display Name Protection', 'vigilante' ); ?></th>
3909 <td>
3910 <label>
3911 <input type="checkbox" name="user_security[prevent_display_name_login_match]" value="1" <?php checked( ! empty( $options['prevent_display_name_login_match'] ) ); ?>>
3912 <?php esc_html_e( 'Prevent users from saving a display name that matches their login username', 'vigilante' ); ?>
3913 </label>
3914 <p class="description"><?php esc_html_e( 'The display name is publicly visible and should not reveal the login username.', 'vigilante' ); ?></p>
3915 </td>
3916 </tr>
3917 </table>
3918 </div>
3919
3920 <!-- Admin Monitoring -->
3921 <div id="vigilante-section-users-admin-monitoring" class="vigilante-settings-section">
3922 <h2>
3923 <?php esc_html_e( 'Admin monitoring', 'vigilante' ); ?>
3924 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
3925 </h2>
3926 <p><?php esc_html_e( 'Receive email alerts when administrator accounts are modified. All events are always logged to the Security Audit.', 'vigilante' ); ?></p>
3927
3928 <table class="form-table">
3929 <tr>
3930 <th scope="row"><?php esc_html_e( 'New Administrator Alert', 'vigilante' ); ?></th>
3931 <td>
3932 <label>
3933 <input type="checkbox" name="user_security[admin_monitoring][alert_new_admin]" value="1" <?php checked( ! empty( $monitoring['alert_new_admin'] ) ); ?>>
3934 <?php esc_html_e( 'Send email alert when a new administrator account is created', 'vigilante' ); ?>
3935 </label>
3936 </td>
3937 </tr>
3938 <tr>
3939 <th scope="row"><?php esc_html_e( 'Admin Email Change Alert', 'vigilante' ); ?></th>
3940 <td>
3941 <label>
3942 <input type="checkbox" name="user_security[admin_monitoring][alert_admin_email_change]" value="1" <?php checked( ! empty( $monitoring['alert_admin_email_change'] ) ); ?>>
3943 <?php esc_html_e( 'Send email alert when an administrator email address is changed', 'vigilante' ); ?>
3944 </label>
3945 </td>
3946 </tr>
3947 <tr>
3948 <th scope="row"><?php esc_html_e( 'Permission Elevation Alert', 'vigilante' ); ?></th>
3949 <td>
3950 <label>
3951 <input type="checkbox" name="user_security[admin_monitoring][alert_permission_elevation]" value="1" <?php checked( ! empty( $monitoring['alert_permission_elevation'] ) ); ?>>
3952 <?php esc_html_e( 'Send email alert when a user is elevated to administrator role', 'vigilante' ); ?>
3953 </label>
3954 </td>
3955 </tr>
3956 <tr>
3957 <th scope="row"><?php esc_html_e( 'Admin Password Change Alert', 'vigilante' ); ?></th>
3958 <td>
3959 <label>
3960 <input type="checkbox" name="user_security[admin_monitoring][alert_admin_password_change]" value="1" <?php checked( ! empty( $monitoring['alert_admin_password_change'] ) ); ?>>
3961 <?php esc_html_e( 'Send email alert when an administrator password is changed', 'vigilante' ); ?>
3962 </label>
3963 </td>
3964 </tr>
3965 </table>
3966
3967 <p class="description">
3968 <?php
3969 printf(
3970 /* translators: %s: Link to notification settings */
3971 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
3972 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
3973 );
3974 ?>
3975 </p>
3976 </div>
3977
3978 <!-- Registration Approval -->
3979 <div id="vigilante-section-users-registration" class="vigilante-settings-section">
3980 <h2>
3981 <?php esc_html_e( 'Registration approval', 'vigilante' ); ?>
3982 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
3983 </h2>
3984 <p><?php esc_html_e( 'Require manual approval for new user registrations.', 'vigilante' ); ?></p>
3985
3986 <table class="form-table">
3987 <tr>
3988 <th scope="row"><?php esc_html_e( 'Enable Registration Approval', 'vigilante' ); ?></th>
3989 <td>
3990 <label>
3991 <input type="checkbox" name="user_security[registration_approval][enabled]" value="1" <?php checked( ! empty( $registration['enabled'] ) ); ?>>
3992 <?php esc_html_e( 'New users must be approved by an administrator before they can log in', 'vigilante' ); ?>
3993 </label>
3994 </td>
3995 </tr>
3996 <tr>
3997 <th scope="row"><?php esc_html_e( 'Notify Admin', 'vigilante' ); ?></th>
3998 <td>
3999 <label>
4000 <input type="checkbox" name="user_security[registration_approval][notify_admin]" value="1" <?php checked( ! empty( $registration['notify_admin'] ) ); ?>>
4001 <?php esc_html_e( 'Send email notification when a new user registers', 'vigilante' ); ?>
4002 </label>
4003 <p class="description"><?php esc_html_e( 'Disable on high-traffic sites to avoid email overload.', 'vigilante' ); ?></p>
4004 </td>
4005 </tr>
4006 <tr>
4007 <th scope="row"><?php esc_html_e( 'Auto-reject After', 'vigilante' ); ?></th>
4008 <td>
4009 <input type="number" name="user_security[registration_approval][auto_reject_days]" value="<?php echo esc_attr( $registration['auto_reject_days'] ?? 0 ); ?>" min="0" max="365" class="small-text">
4010 <?php esc_html_e( 'days (0 = never)', 'vigilante' ); ?>
4011 <p class="description"><?php esc_html_e( 'Automatically reject pending registrations after this many days.', 'vigilante' ); ?></p>
4012 </td>
4013 </tr>
4014 </table>
4015 </div>
4016
4017 <!-- Session Limits -->
4018 <div id="vigilante-section-users-sessions" class="vigilante-settings-section">
4019 <h2>
4020 <?php esc_html_e( 'Session limits', 'vigilante' ); ?>
4021 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4022 </h2>
4023 <p><?php esc_html_e( 'Limit the number of simultaneous sessions per user.', 'vigilante' ); ?></p>
4024
4025 <table class="form-table">
4026 <tr>
4027 <th scope="row"><?php esc_html_e( 'Enable Session Limits', 'vigilante' ); ?></th>
4028 <td>
4029 <label>
4030 <input type="checkbox" name="user_security[session_limits][enabled]" value="1" <?php checked( ! empty( $session_limits['enabled'] ) ); ?>>
4031 <?php esc_html_e( 'Limit the number of active sessions per user', 'vigilante' ); ?>
4032 </label>
4033 </td>
4034 </tr>
4035 <tr>
4036 <th scope="row"><?php esc_html_e( 'Maximum Sessions', 'vigilante' ); ?></th>
4037 <td>
4038 <input type="number" name="user_security[session_limits][max_sessions]" value="<?php echo esc_attr( $session_limits['max_sessions'] ?? 3 ); ?>" min="1" max="10" class="small-text">
4039 <?php esc_html_e( 'sessions per user', 'vigilante' ); ?>
4040 </td>
4041 </tr>
4042 <tr>
4043 <th scope="row"><?php esc_html_e( 'When Limit Exceeded', 'vigilante' ); ?></th>
4044 <td>
4045 <select name="user_security[session_limits][behavior]">
4046 <option value="block_new" <?php selected( ( $session_limits['behavior'] ?? 'close_oldest' ), 'block_new' ); ?>><?php esc_html_e( 'Block new login', 'vigilante' ); ?></option>
4047 <option value="close_oldest" <?php selected( ( $session_limits['behavior'] ?? 'close_oldest' ), 'close_oldest' ); ?>><?php esc_html_e( 'Close oldest session', 'vigilante' ); ?></option>
4048 </select>
4049 <p class="description"><?php esc_html_e( '"Close oldest" is recommended for security - ensures attackers cannot lock out legitimate users.', 'vigilante' ); ?></p>
4050 </td>
4051 </tr>
4052 <tr>
4053 <th scope="row"><?php esc_html_e( 'Exclude Administrators', 'vigilante' ); ?></th>
4054 <td>
4055 <label>
4056 <input type="checkbox" name="user_security[session_limits][exclude_admins]" value="1" <?php checked( ! empty( $session_limits['exclude_admins'] ) ); ?>>
4057 <?php esc_html_e( 'Do not apply session limits to administrators', 'vigilante' ); ?>
4058 </label>
4059 </td>
4060 </tr>
4061 </table>
4062 </div>
4063
4064 <!-- Password Expiration -->
4065 <div id="vigilante-section-users-password-exp" class="vigilante-settings-section">
4066 <h2>
4067 <?php esc_html_e( 'Password expiration', 'vigilante' ); ?>
4068 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4069 </h2>
4070 <p><?php esc_html_e( 'Force users to change their password periodically.', 'vigilante' ); ?></p>
4071
4072 <table class="form-table">
4073 <tr>
4074 <th scope="row"><?php esc_html_e( 'Enable Password Expiration', 'vigilante' ); ?></th>
4075 <td>
4076 <label>
4077 <input type="checkbox" name="user_security[password_expiration][enabled]" value="1" <?php checked( ! empty( $password_exp['enabled'] ) ); ?>>
4078 <?php esc_html_e( 'Force password change after a set number of days', 'vigilante' ); ?>
4079 </label>
4080 </td>
4081 </tr>
4082 <tr>
4083 <th scope="row"><?php esc_html_e( 'Expire After', 'vigilante' ); ?></th>
4084 <td>
4085 <input type="number" name="user_security[password_expiration][expire_days]" value="<?php echo esc_attr( $password_exp['expire_days'] ?? 90 ); ?>" min="7" max="365" class="small-text">
4086 <?php esc_html_e( 'days', 'vigilante' ); ?>
4087 <p class="description"><?php esc_html_e( 'PCI-DSS recommends 90 days.', 'vigilante' ); ?></p>
4088 </td>
4089 </tr>
4090 <tr>
4091 <th scope="row"><?php esc_html_e( 'Warning Period', 'vigilante' ); ?></th>
4092 <td>
4093 <input type="number" name="user_security[password_expiration][warning_days]" value="<?php echo esc_attr( $password_exp['warning_days'] ?? 14 ); ?>" min="1" max="30" class="small-text">
4094 <?php esc_html_e( 'days before expiration', 'vigilante' ); ?>
4095 <p class="description"><?php esc_html_e( 'Show warning notice this many days before password expires.', 'vigilante' ); ?></p>
4096 </td>
4097 </tr>
4098 <tr>
4099 <th scope="row"><?php esc_html_e( 'Password History', 'vigilante' ); ?></th>
4100 <td>
4101 <input type="number" name="user_security[password_expiration][password_history]" value="<?php echo esc_attr( $password_exp['password_history'] ?? 3 ); ?>" min="0" max="24" class="small-text">
4102 <?php esc_html_e( 'passwords to remember', 'vigilante' ); ?>
4103 <p class="description"><?php esc_html_e( 'Prevent reusing recent passwords. Set to 0 to disable.', 'vigilante' ); ?></p>
4104 </td>
4105 </tr>
4106 <tr>
4107 <th scope="row"><?php esc_html_e( 'Email Reminder', 'vigilante' ); ?></th>
4108 <td>
4109 <label>
4110 <input type="checkbox" name="user_security[password_expiration][send_reminder]" value="1" <?php checked( ! empty( $password_exp['send_reminder'] ) ); ?>>
4111 <?php esc_html_e( 'Send email reminder when password is about to expire', 'vigilante' ); ?>
4112 </label>
4113 <p class="description"><?php esc_html_e( 'The reminder is sent once when the warning period starts, using the same number of days configured above.', 'vigilante' ); ?></p>
4114 </td>
4115 </tr>
4116 <tr>
4117 <th scope="row"><?php esc_html_e( 'Affected Roles', 'vigilante' ); ?></th>
4118 <td>
4119 <?php
4120 $affected_roles = $password_exp['affected_roles'] ?? array( 'administrator', 'editor' );
4121 $all_roles = wp_roles()->get_names();
4122 foreach ( $all_roles as $role_slug => $role_name ) :
4123 ?>
4124 <label style="display: block; margin-bottom: 5px;">
4125 <input type="checkbox" name="user_security[password_expiration][affected_roles][]" value="<?php echo esc_attr( $role_slug ); ?>" <?php checked( in_array( $role_slug, $affected_roles, true ) ); ?>>
4126 <?php echo esc_html( translate_user_role( $role_name ) ); ?>
4127 </label>
4128 <?php endforeach; ?>
4129 </td>
4130 </tr>
4131 <tr>
4132 <th scope="row"><?php esc_html_e( 'Exclude specific users', 'vigilante' ); ?></th>
4133 <td>
4134 <?php $pwexp_excluded = $password_exp['excluded_users'] ?? array(); ?>
4135 <div class="vigilante-2fa-user-search-container">
4136 <div class="vigilante-2fa-user-search">
4137 <span class="search-icon"></span>
4138 <input type="text"
4139 id="vigilante_pwexp_user_search"
4140 placeholder="<?php esc_attr_e( 'Search users by name or email...', 'vigilante' ); ?>"
4141 autocomplete="off">
4142 <div class="vigilante-pwexp-search-results"></div>
4143 </div>
4144 <div class="vigilante-pwexp-excluded-users">
4145 <?php
4146 foreach ( $pwexp_excluded as $pwexp_excluded_id ) :
4147 $excluded_user = get_user_by( 'ID', $pwexp_excluded_id );
4148 if ( ! $excluded_user ) {
4149 continue;
4150 }
4151 ?>
4152 <div class="vigilante-pwexp-excluded-user" data-user-id="<?php echo esc_attr( $pwexp_excluded_id ); ?>">
4153 <span class="user-display"><?php echo esc_html( $excluded_user->display_name . ' (' . $excluded_user->user_email . ')' ); ?></span>
4154 <button type="button" class="remove-user" aria-label="<?php esc_attr_e( 'Remove', 'vigilante' ); ?>">&times;</button>
4155 <input type="hidden" name="user_security[password_expiration][excluded_users][]" value="<?php echo esc_attr( $pwexp_excluded_id ); ?>">
4156 </div>
4157 <?php endforeach; ?>
4158 </div>
4159 </div>
4160 <p class="description"><?php esc_html_e( 'Listed users will be excluded from password expiration regardless of their role.', 'vigilante' ); ?></p>
4161 </td>
4162 </tr>
4163 </table>
4164 </div>
4165
4166 <!-- Email Verification -->
4167 <div id="vigilante-section-users-email-verify" class="vigilante-settings-section">
4168 <h2>
4169 <?php esc_html_e( 'Email verification', 'vigilante' ); ?>
4170 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4171 </h2>
4172 <p><?php esc_html_e( 'Require new users to verify their email address before logging in.', 'vigilante' ); ?></p>
4173
4174 <table class="form-table">
4175 <tr>
4176 <th scope="row"><?php esc_html_e( 'Enable Email Verification', 'vigilante' ); ?></th>
4177 <td>
4178 <label>
4179 <input type="checkbox" name="user_security[email_verification][enabled]" value="1" <?php checked( ! empty( $email_verify['enabled'] ) ); ?>>
4180 <?php esc_html_e( 'New users must verify their email before logging in', 'vigilante' ); ?>
4181 </label>
4182 </td>
4183 </tr>
4184 <tr>
4185 <th scope="row"><?php esc_html_e( 'Link Expiration', 'vigilante' ); ?></th>
4186 <td>
4187 <input type="number" name="user_security[email_verification][token_expiry_hours]" value="<?php echo esc_attr( $email_verify['token_expiry_hours'] ?? 24 ); ?>" min="1" max="168" class="small-text">
4188 <?php esc_html_e( 'hours', 'vigilante' ); ?>
4189 </td>
4190 </tr>
4191 <tr>
4192 <th scope="row"><?php esc_html_e( 'Allow Resend', 'vigilante' ); ?></th>
4193 <td>
4194 <label>
4195 <input type="checkbox" name="user_security[email_verification][allow_resend]" value="1" <?php checked( ! empty( $email_verify['allow_resend'] ) ); ?>>
4196 <?php esc_html_e( 'Allow users to request a new verification email', 'vigilante' ); ?>
4197 </label>
4198 </td>
4199 </tr>
4200 <tr>
4201 <th scope="row"><?php esc_html_e( 'Auto-delete Unverified', 'vigilante' ); ?></th>
4202 <td>
4203 <input type="number" name="user_security[email_verification][auto_delete_days]" value="<?php echo esc_attr( $email_verify['auto_delete_days'] ?? 7 ); ?>" min="0" max="365" class="small-text">
4204 <?php esc_html_e( 'days (0 = never)', 'vigilante' ); ?>
4205 <p class="description"><?php esc_html_e( 'Automatically delete users who never verify their email.', 'vigilante' ); ?></p>
4206 </td>
4207 </tr>
4208 </table>
4209 </div>
4210
4211 <p class="submit vigilante-submit-buttons">
4212 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4213 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4214 </button>
4215 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4216 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4217 </button>
4218 </p>
4219 </form>
4220
4221 <!-- ============================================================
4222 TOOLS SECTION - Actions and utilities (no save button)
4223 ============================================================ -->
4224 <div class="vigilante-tools-section">
4225 <h2 class="vigilante-tools-header">
4226 <?php esc_html_e( 'User security tools', 'vigilante' ); ?>
4227 </h2>
4228
4229 <!-- Force Password Reset -->
4230 <div class="vigilante-tool-box">
4231 <h3><?php esc_html_e( 'Force password reset', 'vigilante' ); ?></h3>
4232 <p class="description"><?php esc_html_e( 'Force users to reset their password. Useful after a security incident. Users will receive an email with a reset link.', 'vigilante' ); ?></p>
4233
4234 <!-- Reset Specific Users -->
4235 <div class="vigilante-password-reset-box">
4236 <h4><?php esc_html_e( 'Reset specific users', 'vigilante' ); ?></h4>
4237
4238 <div class="vigilante-user-search-wrapper">
4239 <input type="text" id="vigilante-password-reset-search" class="regular-text" placeholder="<?php esc_attr_e( 'Search by username, email, or display name...', 'vigilante' ); ?>">
4240 <div id="vigilante-password-reset-results" class="vigilante-user-search-results" style="display: none;"></div>
4241 </div>
4242
4243 <div id="vigilante-password-reset-selected" class="vigilante-selected-users" style="display: none;">
4244 <strong><?php esc_html_e( 'Selected Users:', 'vigilante' ); ?></strong>
4245 <ul class="vigilante-selected-users-list"></ul>
4246 </div>
4247
4248 <p class="description" style="margin-top: 15px;">
4249 <span class="dashicons dashicons-email-alt" style="color: #2271b1;"></span>
4250 <?php esc_html_e( 'Selected users will receive an email with a password reset link.', 'vigilante' ); ?>
4251 </p>
4252
4253 <p class="submit">
4254 <button type="button" id="vigilante-reset-selected-users" class="button button-primary" disabled>
4255 <?php esc_html_e( 'Force Reset for Selected Users', 'vigilante' ); ?>
4256 </button>
4257 </p>
4258 </div>
4259
4260 <!-- Reset by Role -->
4261 <div class="vigilante-password-reset-box" style="margin-top: 20px; padding-top: 20px; border-top: 1px solid #ddd;">
4262 <h4><?php esc_html_e( 'Reset by role', 'vigilante' ); ?></h4>
4263 <p class="description"><?php esc_html_e( 'Select one or more roles to force a password reset for all users with those roles. Ideal for security incidents where you need to reset access quickly.', 'vigilante' ); ?></p>
4264
4265 <?php
4266 $wp_roles = wp_roles();
4267 $user_counts = count_users();
4268 $avail_roles = $user_counts['avail_roles'] ?? array();
4269 $current_user = wp_get_current_user();
4270 $current_roles = $current_user->roles;
4271 ?>
4272
4273 <fieldset class="vigilante-role-checkboxes" style="margin-top: 10px;">
4274 <?php foreach ( $wp_roles->roles as $role_slug => $role_data ) :
4275 $count = $avail_roles[ $role_slug ] ?? 0;
4276 if ( 0 === $count ) {
4277 continue;
4278 }
4279 $role_name = translate_user_role( $role_data['name'] );
4280 ?>
4281 <label style="display: block; margin-bottom: 6px;">
4282 <input type="checkbox"
4283 class="vigilante-reset-role-checkbox"
4284 value="<?php echo esc_attr( $role_slug ); ?>"
4285 data-count="<?php echo absint( $count ); ?>">
4286 <?php
4287 printf(
4288 /* translators: 1: Role name, 2: Number of users */
4289 '%1$s <span class="description">(%2$d)</span>',
4290 esc_html( $role_name ),
4291 absint( $count )
4292 );
4293 ?>
4294 <?php if ( in_array( $role_slug, $current_roles, true ) ) : ?>
4295 <em class="description"><?php esc_html_e( '(includes you)', 'vigilante' ); ?></em>
4296 <?php endif; ?>
4297 </label>
4298 <?php endforeach; ?>
4299 </fieldset>
4300
4301 <div id="vigilante-reset-role-summary" style="display: none; margin-top: 10px;">
4302 <p>
4303 <span class="dashicons dashicons-groups" style="color: #2271b1;"></span>
4304 <strong id="vigilante-reset-role-count">0</strong>
4305 <?php esc_html_e( 'user(s) will be affected.', 'vigilante' ); ?>
4306 </p>
4307 </div>
4308
4309 <div class="vigilante-password-reset-options" id="vigilante-reset-role-self-option" style="display: none; margin-top: 10px;">
4310 <label>
4311 <input type="checkbox" id="vigilante-reset-role-include-self" value="1">
4312 <?php esc_html_e( 'Include myself (your current session will end)', 'vigilante' ); ?>
4313 </label>
4314 </div>
4315
4316 <p class="submit">
4317 <button type="button" id="vigilante-reset-by-role" class="button button-primary" disabled>
4318 <?php esc_html_e( 'Force Reset for Selected Roles', 'vigilante' ); ?>
4319 </button>
4320 </p>
4321 </div>
4322
4323 <!-- Reset All Users -->
4324 <div class="vigilante-password-reset-box" style="margin-top: 20px; padding-top: 20px; border-top: 1px solid #ddd;">
4325 <h4><?php esc_html_e( 'Reset all users', 'vigilante' ); ?></h4>
4326
4327 <?php
4328 $total_users = count_users();
4329 $total_count = $total_users['total_users'];
4330 ?>
4331 <p>
4332 <?php
4333 printf(
4334 /* translators: %d: Number of users */
4335 esc_html__( 'This will affect %d user(s).', 'vigilante' ),
4336 absint( $total_count )
4337 );
4338 ?>
4339 </p>
4340
4341 <p class="description" style="color: #d63638;">
4342 <span class="dashicons dashicons-warning"></span>
4343 <?php esc_html_e( 'Warning: All users will receive a password reset email. On sites with many users, this could overwhelm your mail server.', 'vigilante' ); ?>
4344 </p>
4345
4346 <div class="vigilante-password-reset-options" style="margin-top: 10px;">
4347 <label>
4348 <input type="checkbox" id="vigilante-reset-all-include-self" value="1">
4349 <?php esc_html_e( 'Include myself (your current session will end)', 'vigilante' ); ?>
4350 </label>
4351 </div>
4352
4353 <p class="submit">
4354 <button type="button" id="vigilante-reset-all-users" class="button" style="color: #d63638; border-color: #d63638;">
4355 <?php esc_html_e( 'Force Reset for ALL Users', 'vigilante' ); ?>
4356 </button>
4357 </p>
4358 </div>
4359 </div>
4360
4361 <!-- Pending Registrations -->
4362 <?php
4363 $user_security = new Vigilante_User_Security( $this->settings, $this->activity_log );
4364 $pending_users = $user_security->get_pending_users();
4365 ?>
4366 <div class="vigilante-tool-box vigilante-pending-users-section">
4367 <h3>
4368 <?php esc_html_e( 'Pending registrations', 'vigilante' ); ?>
4369 <?php if ( count( $pending_users ) > 0 ) : ?>
4370 <span class="vigilante-badge vigilante-badge-warning"><?php echo esc_html( count( $pending_users ) ); ?></span>
4371 <?php endif; ?>
4372 </h3>
4373
4374 <?php if ( empty( $registration['enabled'] ) ) : ?>
4375 <p class="description">
4376 <span class="dashicons dashicons-info" style="color: #72aee6;"></span>
4377 <?php esc_html_e( 'Registration approval is disabled. Enable it in the settings above to require manual approval for new users.', 'vigilante' ); ?>
4378 </p>
4379 <?php elseif ( empty( $pending_users ) ) : ?>
4380 <div class="vigilante-no-lockouts">
4381 <span class="dashicons dashicons-yes-alt"></span>
4382 <p><?php esc_html_e( 'No pending registrations.', 'vigilante' ); ?></p>
4383 </div>
4384 <?php else : ?>
4385 <table class="wp-list-table widefat fixed striped vigilante-pending-users-table">
4386 <thead>
4387 <tr>
4388 <th><?php esc_html_e( 'User', 'vigilante' ); ?></th>
4389 <th><?php esc_html_e( 'Email', 'vigilante' ); ?></th>
4390 <th><?php esc_html_e( 'Registered', 'vigilante' ); ?></th>
4391 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
4392 </tr>
4393 </thead>
4394 <tbody>
4395 <?php foreach ( $pending_users as $pending_user ) :
4396 $pending_since = get_user_meta( $pending_user->ID, 'vigilante_pending_since', true );
4397 ?>
4398 <tr data-user-id="<?php echo esc_attr( $pending_user->ID ); ?>">
4399 <td>
4400 <?php echo get_avatar( $pending_user->ID, 32 ); ?>
4401 <strong><?php echo esc_html( $pending_user->user_login ); ?></strong>
4402 </td>
4403 <td><?php echo esc_html( $pending_user->user_email ); ?></td>
4404 <td>
4405 <?php
4406 if ( $pending_since ) {
4407 /* translators: %s: Time ago */
4408 printf( esc_html__( '%s ago', 'vigilante' ), esc_html( human_time_diff( $pending_since ) ) );
4409 } else {
4410 echo esc_html( $pending_user->user_registered );
4411 }
4412 ?>
4413 </td>
4414 <td>
4415 <button type="button" class="button button-small vigilante-approve-user" data-user-id="<?php echo esc_attr( $pending_user->ID ); ?>">
4416 <?php esc_html_e( 'Approve', 'vigilante' ); ?>
4417 </button>
4418 <button type="button" class="button button-small vigilante-reject-user" data-user-id="<?php echo esc_attr( $pending_user->ID ); ?>" style="color: #d63638;">
4419 <?php esc_html_e( 'Reject', 'vigilante' ); ?>
4420 </button>
4421 </td>
4422 </tr>
4423 <?php endforeach; ?>
4424 </tbody>
4425 </table>
4426 <?php endif; ?>
4427 </div>
4428
4429 <!-- Active Sessions Management -->
4430 <div class="vigilante-tool-box vigilante-session-management-section">
4431 <h3><?php esc_html_e( 'Active sessions', 'vigilante' ); ?></h3>
4432 <p class="description"><?php esc_html_e( 'View and manage active login sessions. You can revoke sessions to force users to log in again.', 'vigilante' ); ?></p>
4433
4434 <!-- Current user sessions -->
4435 <h4><?php esc_html_e( 'Your sessions', 'vigilante' ); ?></h4>
4436 <?php
4437 $current_user_id = get_current_user_id();
4438 $my_sessions = $user_security->get_user_sessions( $current_user_id );
4439 $has_corrupted = $user_security->has_corrupted_sessions( $current_user_id );
4440 $raw_count = $user_security->get_raw_session_count( $current_user_id );
4441 ?>
4442
4443 <?php if ( $has_corrupted && $raw_count > 0 ) : ?>
4444 <div class="notice notice-warning inline" style="margin: 10px 0;">
4445 <p>
4446 <span class="dashicons dashicons-warning" style="color: #dba617;"></span>
4447 <?php esc_html_e( 'Some session data is corrupted and cannot be displayed. Use "Revoke All Other Sessions" to clean up, then log out and log in again to fix this.', 'vigilante' ); ?>
4448 </p>
4449 </div>
4450 <?php endif; ?>
4451
4452 <?php if ( empty( $my_sessions ) ) : ?>
4453 <p class="description"><?php esc_html_e( 'No active sessions found.', 'vigilante' ); ?></p>
4454 <?php if ( $has_corrupted ) : ?>
4455 <p style="margin-top: 10px;">
4456 <button type="button" class="button vigilante-revoke-other-sessions" data-user-id="<?php echo esc_attr( $current_user_id ); ?>">
4457 <?php esc_html_e( 'Clean Up Corrupted Sessions', 'vigilante' ); ?>
4458 </button>
4459 </p>
4460 <?php endif; ?>
4461 <?php else : ?>
4462 <div class="vigilante-paginated-section">
4463 <div class="vigilante-fi-pagination-wrap"></div>
4464 <table class="wp-list-table widefat fixed striped vigilante-sessions-table vigilante-fi-paginated">
4465 <thead>
4466 <tr>
4467 <th><?php esc_html_e( 'Browser', 'vigilante' ); ?></th>
4468 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
4469 <th><?php esc_html_e( 'Login Time', 'vigilante' ); ?></th>
4470 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
4471 </tr>
4472 </thead>
4473 <tbody>
4474 <?php foreach ( $my_sessions as $session ) : ?>
4475 <tr data-token="<?php echo esc_attr( $session['token_hash'] ); ?>">
4476 <td><?php echo esc_html( $session['browser'] ); ?></td>
4477 <td><code><?php echo esc_html( $session['ip'] ); ?></code></td>
4478 <td>
4479 <?php
4480 if ( $session['login'] ) {
4481 /* translators: %s: Time ago */
4482 printf( esc_html__( '%s ago', 'vigilante' ), esc_html( human_time_diff( $session['login'] ) ) );
4483 } else {
4484 esc_html_e( 'Unknown', 'vigilante' );
4485 }
4486 ?>
4487 </td>
4488 <td>
4489 <?php if ( ! $session['is_current'] ) : ?>
4490 <button type="button" class="button button-small vigilante-revoke-session" data-user-id="<?php echo esc_attr( $current_user_id ); ?>" data-token="<?php echo esc_attr( $session['token_hash'] ); ?>">
4491 <?php esc_html_e( 'Revoke', 'vigilante' ); ?>
4492 </button>
4493 <?php else : ?>
4494 <span class="description"><?php esc_html_e( 'Current session', 'vigilante' ); ?></span>
4495 <?php endif; ?>
4496 </td>
4497 </tr>
4498 <?php endforeach; ?>
4499 </tbody>
4500 </table>
4501 </div>
4502
4503 <?php if ( count( $my_sessions ) > 1 || $has_corrupted ) : ?>
4504 <p style="margin-top: 10px;">
4505 <button type="button" class="button vigilante-revoke-other-sessions" data-user-id="<?php echo esc_attr( $current_user_id ); ?>">
4506 <?php esc_html_e( 'Revoke All Other Sessions', 'vigilante' ); ?>
4507 </button>
4508 </p>
4509 <?php endif; ?>
4510 <?php endif; ?>
4511
4512 <!-- Search user sessions (admin only) -->
4513 <h4 style="margin-top: 30px;"><?php esc_html_e( 'Manage user sessions', 'vigilante' ); ?></h4>
4514 <p class="description"><?php esc_html_e( 'Search for a user to view and manage their sessions.', 'vigilante' ); ?></p>
4515
4516 <div class="vigilante-user-search-wrapper" style="margin-top: 10px;">
4517 <input type="text" id="vigilante-session-user-search" class="regular-text" placeholder="<?php esc_attr_e( 'Search by username or email...', 'vigilante' ); ?>">
4518 <div id="vigilante-session-search-results" class="vigilante-user-search-results" style="display: none;"></div>
4519 </div>
4520
4521 <div id="vigilante-user-sessions-container" style="display: none; margin-top: 20px;">
4522 <h4 id="vigilante-sessions-user-name"></h4>
4523 <table class="wp-list-table widefat fixed striped vigilante-sessions-table">
4524 <thead>
4525 <tr>
4526 <th><?php esc_html_e( 'Browser', 'vigilante' ); ?></th>
4527 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
4528 <th><?php esc_html_e( 'Login Time', 'vigilante' ); ?></th>
4529 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
4530 </tr>
4531 </thead>
4532 <tbody id="vigilante-user-sessions-list">
4533 </tbody>
4534 </table>
4535 <p style="margin-top: 10px;">
4536 <button type="button" class="button vigilante-revoke-all-user-sessions" style="color: #d63638;">
4537 <?php esc_html_e( 'Revoke All Sessions', 'vigilante' ); ?>
4538 </button>
4539 </p>
4540 </div>
4541 </div>
4542 </div>
4543 <?php
4544 }
4545
4546 /**
4547 * Render WordPress Hardening tab
4548 */
4549 private function render_tab_wp_hardening() {
4550 $is_disabled = $this->render_module_disabled_notice( 'wp_hardening' );
4551 $options = $this->settings->get_section( 'wp_hardening' );
4552 ?>
4553 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="wp_hardening" <?php echo $is_disabled ? 'inert' : ''; ?>>
4554 <!-- Database Hardening (outside form save flow - uses its own AJAX action) -->
4555 <div id="vigilante-section-hardening-database" class="vigilante-settings-section">
4556 <h2>
4557 <?php esc_html_e( 'Database Hardening', 'vigilante' ); ?>
4558 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
4559 <span class="vigilante-method-badge config"><?php esc_html_e( 'WP-CONFIG', 'vigilante' ); ?></span>
4560 </h2>
4561 <p><?php esc_html_e( 'Change the database table prefix to prevent SQL injection attacks that target default WordPress tables.', 'vigilante' ); ?></p>
4562
4563 <?php
4564 $db_prefix = new Vigilante_Database_Prefix();
4565 $current_prefix = $db_prefix->get_current_prefix();
4566 $is_default = $db_prefix->is_default_prefix();
4567 ?>
4568
4569 <table class="form-table">
4570 <tr>
4571 <th scope="row"><?php esc_html_e( 'Current prefix', 'vigilante' ); ?></th>
4572 <td>
4573 <code class="vigilante-db-current-prefix"><?php echo esc_html( $current_prefix ); ?></code>
4574 <?php if ( $is_default ) : ?>
4575 <span class="vigilante-inline-warning">
4576 <span class="dashicons dashicons-warning"></span>
4577 <?php esc_html_e( 'Default prefix detected. Changing it adds a layer of protection against automated SQL injection attacks.', 'vigilante' ); ?>
4578 </span>
4579 <?php else : ?>
4580 <span class="vigilante-inline-ok">
4581 <span class="dashicons dashicons-yes-alt"></span>
4582 <?php esc_html_e( 'Custom prefix in use.', 'vigilante' ); ?>
4583 </span>
4584 <?php endif; ?>
4585 </td>
4586 </tr>
4587 <tr>
4588 <th scope="row"><?php esc_html_e( 'New prefix', 'vigilante' ); ?></th>
4589 <td>
4590 <div class="vigilante-db-prefix-row">
4591 <code class="vigilante-db-new-prefix" id="vigilante-new-prefix"><?php echo esc_html( $db_prefix->generate_prefix() ); ?></code>
4592 <button type="button" class="button button-small vigilante-db-regenerate-prefix" title="<?php esc_attr_e( 'Generate new prefix', 'vigilante' ); ?>">
4593 <span class="dashicons dashicons-update"></span>
4594 </button>
4595 </div>
4596 </td>
4597 </tr>
4598 <tr>
4599 <th scope="row"></th>
4600 <td>
4601 <div class="vigilante-db-prefix-confirm">
4602 <label>
4603 <input type="checkbox" id="vigilante-prefix-backup-confirm">
4604 <?php esc_html_e( 'I understand this operation is irreversible and I have a current database backup', 'vigilante' ); ?>
4605 </label>
4606 <p class="description">
4607 <?php
4608 printf(
4609 /* translators: %s: Link to tools tab */
4610 esc_html__( 'Need a backup? %s first.', 'vigilante' ),
4611 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Download a database backup', 'vigilante' ) . '</a>'
4612 );
4613 ?>
4614 </p>
4615 </div>
4616 <button type="button" class="button button-primary vigilante-db-change-prefix" disabled data-original-text="<?php esc_attr_e( 'Change Database Prefix', 'vigilante' ); ?>">
4617 <?php esc_html_e( 'Change Database Prefix', 'vigilante' ); ?>
4618 </button>
4619 </td>
4620 </tr>
4621 </table>
4622 </div>
4623
4624 <!-- wp-config Security -->
4625 <div id="vigilante-section-hardening-wpconfig" class="vigilante-settings-section">
4626 <h2>
4627 <?php esc_html_e( 'wp-config.php Security', 'vigilante' ); ?>
4628 <span class="vigilante-method-badge config"><?php esc_html_e( 'WP-CONFIG', 'vigilante' ); ?></span>
4629 </h2>
4630 <p><?php esc_html_e( 'Security constants added directly to wp-config.php file.', 'vigilante' ); ?></p>
4631
4632 <table class="form-table">
4633 <tr>
4634 <th scope="row"><?php esc_html_e( 'Disable File Editor', 'vigilante' ); ?></th>
4635 <td>
4636 <label>
4637 <input type="checkbox" name="wp_hardening[disallow_file_edit]" value="1" <?php checked( ! empty( $options['disallow_file_edit'] ) ); ?>>
4638 <?php esc_html_e( 'Disable plugin and theme editor in admin (DISALLOW_FILE_EDIT)', 'vigilante' ); ?>
4639 </label>
4640 </td>
4641 </tr>
4642 <tr>
4643 <th scope="row"><?php esc_html_e( 'Disable File Modifications', 'vigilante' ); ?></th>
4644 <td>
4645 <label>
4646 <input type="checkbox" name="wp_hardening[disallow_file_mods]" value="1" <?php checked( ! empty( $options['disallow_file_mods'] ) ); ?>>
4647 <?php esc_html_e( 'Disable all file modifications including updates (DISALLOW_FILE_MODS)', 'vigilante' ); ?>
4648 </label>
4649 <p class="description"><?php esc_html_e( '&#9888; Warning: This prevents automatic updates.', 'vigilante' ); ?></p>
4650 </td>
4651 </tr>
4652 <tr id="field-force-ssl-admin">
4653 <th scope="row"><?php esc_html_e( 'Force SSL Admin', 'vigilante' ); ?></th>
4654 <td>
4655 <label>
4656 <input type="checkbox" name="wp_hardening[force_ssl_admin]" value="1" <?php checked( ! empty( $options['force_ssl_admin'] ) ); ?>>
4657 <?php esc_html_e( 'Force HTTPS for admin area (FORCE_SSL_ADMIN)', 'vigilante' ); ?>
4658 </label>
4659 <p class="description"><?php esc_html_e( '&#9888; Warning: Only enable if your site fully supports HTTPS.', 'vigilante' ); ?></p>
4660 </td>
4661 </tr>
4662 <tr id="field-wp-debug">
4663 <th scope="row"><?php esc_html_e( 'Hide PHP errors from visitors', 'vigilante' ); ?></th>
4664 <td>
4665 <label>
4666 <input type="checkbox" name="wp_hardening[wp_debug]" value="1" <?php checked( ! empty( $options['wp_debug'] ) ); ?>>
4667 <?php esc_html_e( 'Prevents PHP errors and warnings from being displayed publicly. Also avoids exposing a debug.log file in wp-content/ that could leak paths and code. Uncheck only on development or staging sites.', 'vigilante' ); ?>
4668 </label>
4669 </td>
4670 </tr>
4671 <tr id="field-disable-wp-cron">
4672 <th scope="row"><?php esc_html_e( 'Disable WP Cron', 'vigilante' ); ?></th>
4673 <td>
4674 <label>
4675 <input type="checkbox" name="wp_hardening[disable_wp_cron]" value="1" <?php checked( ! empty( $options['disable_wp_cron'] ) ); ?>>
4676 <?php esc_html_e( 'Disable WordPress\'s page-view cron trigger (DISABLE_WP_CRON)', 'vigilante' ); ?>
4677 </label>
4678 <p class="description"><?php
4679 printf(
4680 /* translators: 1: opening <strong>, 2: closing </strong>, 3: opening <code>, 4: closing </code> */
4681 esc_html__( '%1$sWarning:%2$s Only enable if your host runs a real server-side cron job calling wp-cron.php. Otherwise scheduled tasks stop running. This constant only stops the page-view auto-spawn — to also block external HTTP abuse, enable %3$sProtect wp-cron.php%4$s in Firewall &rarr; File Protection.', 'vigilante' ),
4682 '<strong>',
4683 '</strong>',
4684 '<code>',
4685 '</code>'
4686 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
4687 ?></p>
4688 </td>
4689 </tr>
4690 </table>
4691 </div>
4692
4693 <!-- Comment Security -->
4694 <div id="vigilante-section-hardening-comments" class="vigilante-settings-section">
4695 <h2>
4696 <?php esc_html_e( 'Comment Security', 'vigilante' ); ?>
4697 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4698 <span class="vigilante-method-badge settings"><?php esc_html_e( 'Settings', 'vigilante' ); ?></span>
4699 </h2>
4700 <p><?php esc_html_e( 'Comment protection using WordPress settings and PHP hooks.', 'vigilante' ); ?></p>
4701
4702 <table class="form-table">
4703 <tr>
4704 <th scope="row"><?php esc_html_e( 'Disable Pingbacks', 'vigilante' ); ?></th>
4705 <td>
4706 <label>
4707 <input type="checkbox" name="wp_hardening[disable_pingbacks]" value="1" <?php checked( ! empty( $options['disable_pingbacks'] ) ); ?>>
4708 <?php esc_html_e( 'Disable pingbacks (commonly exploited for DDoS)', 'vigilante' ); ?>
4709 </label>
4710 </td>
4711 </tr>
4712 <tr>
4713 <th scope="row"><?php esc_html_e( 'Disable Trackbacks', 'vigilante' ); ?></th>
4714 <td>
4715 <label>
4716 <input type="checkbox" name="wp_hardening[disable_trackbacks]" value="1" <?php checked( ! empty( $options['disable_trackbacks'] ) ); ?>>
4717 <?php esc_html_e( 'Disable trackbacks (rarely used legitimately)', 'vigilante' ); ?>
4718 </label>
4719 </td>
4720 </tr>
4721 <tr>
4722 <th scope="row"><?php esc_html_e( 'Require Moderation', 'vigilante' ); ?></th>
4723 <td>
4724 <label>
4725 <input type="checkbox" name="wp_hardening[require_comment_moderation]" value="1" <?php checked( ! empty( $options['require_comment_moderation'] ) ); ?>>
4726 <?php esc_html_e( 'All comments must be manually approved', 'vigilante' ); ?>
4727 </label>
4728 </td>
4729 </tr>
4730 <tr>
4731 <th scope="row"><?php esc_html_e( 'Close Old Comments', 'vigilante' ); ?></th>
4732 <td>
4733 <label>
4734 <input type="checkbox" name="wp_hardening[close_old_comments]" value="1" <?php checked( ! empty( $options['close_old_comments'] ) ); ?>>
4735 <?php esc_html_e( 'Automatically close comments on old posts after', 'vigilante' ); ?>
4736 </label>
4737 <input type="number" name="wp_hardening[close_comments_after_days]" value="<?php echo esc_attr( $options['close_comments_after_days'] ?? 30 ); ?>" min="1" max="365" class="small-text">
4738 <?php esc_html_e( 'days', 'vigilante' ); ?>
4739 </td>
4740 </tr>
4741 <tr>
4742 <th scope="row"><?php esc_html_e( 'Honeypot Protection', 'vigilante' ); ?></th>
4743 <td>
4744 <label>
4745 <input type="checkbox" name="wp_hardening[honeypot_comments]" value="1" <?php checked( ! empty( $options['honeypot_comments'] ) ); ?>>
4746 <?php esc_html_e( 'Add hidden honeypot field to catch bots', 'vigilante' ); ?>
4747 </label>
4748 </td>
4749 </tr>
4750 </table>
4751 </div>
4752
4753 <!-- Head Cleaner -->
4754 <div id="vigilante-section-hardening-headers" class="vigilante-settings-section">
4755 <h2>
4756 <?php esc_html_e( 'Header Cleanup', 'vigilante' ); ?>
4757 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4758 </h2>
4759 <p><?php esc_html_e( 'Remove meta tags from HTML head.', 'vigilante' ); ?></p>
4760
4761 <table class="form-table">
4762 <tr>
4763 <th scope="row"><?php esc_html_e( 'Remove Generator', 'vigilante' ); ?></th>
4764 <td>
4765 <label>
4766 <input type="checkbox" name="wp_hardening[remove_wp_generator]" value="1" <?php checked( ! empty( $options['remove_wp_generator'] ) ); ?>>
4767 <?php esc_html_e( 'Remove WordPress version from HTML head', 'vigilante' ); ?>
4768 </label>
4769 </td>
4770 </tr>
4771 <tr id="field-remove-wp-version-assets">
4772 <th scope="row"><?php esc_html_e( 'Remove version from assets', 'vigilante' ); ?></th>
4773 <td>
4774 <label>
4775 <input type="checkbox" name="wp_hardening[remove_wp_version_assets]" value="1" <?php checked( ! empty( $options['remove_wp_version_assets'] ) ); ?>>
4776 <?php esc_html_e( 'Remove WordPress version from script/style URLs (?ver=)', 'vigilante' ); ?>
4777 </label>
4778 <p class="description"><?php esc_html_e( 'Hides the exact WordPress version that would otherwise leak in every enqueued asset URL. Versions added by plugins or themes are kept untouched.', 'vigilante' ); ?></p>
4779 </td>
4780 </tr>
4781 <tr>
4782 <th scope="row"><?php esc_html_e( 'Remove RSD Link', 'vigilante' ); ?></th>
4783 <td>
4784 <label>
4785 <input type="checkbox" name="wp_hardening[remove_rsd_link]" value="1" <?php checked( ! empty( $options['remove_rsd_link'] ) ); ?>>
4786 <?php esc_html_e( 'Remove Really Simple Discovery link', 'vigilante' ); ?>
4787 </label>
4788 </td>
4789 </tr>
4790 <tr>
4791 <th scope="row"><?php esc_html_e( 'Remove WLW Manifest', 'vigilante' ); ?></th>
4792 <td>
4793 <label>
4794 <input type="checkbox" name="wp_hardening[remove_wlw_manifest]" value="1" <?php checked( ! empty( $options['remove_wlw_manifest'] ) ); ?>>
4795 <?php esc_html_e( 'Remove Windows Live Writer manifest link', 'vigilante' ); ?>
4796 </label>
4797 </td>
4798 </tr>
4799 <tr>
4800 <th scope="row"><?php esc_html_e( 'Remove Shortlink', 'vigilante' ); ?></th>
4801 <td>
4802 <label>
4803 <input type="checkbox" name="wp_hardening[remove_shortlink]" value="1" <?php checked( ! empty( $options['remove_shortlink'] ) ); ?>>
4804 <?php esc_html_e( 'Remove shortlink tag from header', 'vigilante' ); ?>
4805 </label>
4806 </td>
4807 </tr>
4808 <tr>
4809 <th scope="row"><?php esc_html_e( 'Remove REST API Link', 'vigilante' ); ?></th>
4810 <td>
4811 <label>
4812 <input type="checkbox" name="wp_hardening[remove_rest_api_link]" value="1" <?php checked( ! empty( $options['remove_rest_api_link'] ) ); ?>>
4813 <?php esc_html_e( 'Remove REST API discovery link from header', 'vigilante' ); ?>
4814 </label>
4815 <p class="description"><?php esc_html_e( '&#9888; Notice: Some plugins may need this link.', 'vigilante' ); ?></p>
4816 </td>
4817 </tr>
4818 </table>
4819 </div>
4820
4821 <!-- Feed Manager -->
4822 <div id="vigilante-section-hardening-rss" class="vigilante-settings-section">
4823 <h2>
4824 <?php esc_html_e( 'RSS Feed Settings', 'vigilante' ); ?>
4825 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4826 </h2>
4827 <p><?php esc_html_e( 'Control RSS/Atom feeds.', 'vigilante' ); ?></p>
4828
4829 <table class="form-table">
4830 <tr>
4831 <th scope="row"><?php esc_html_e( 'Disable Feeds', 'vigilante' ); ?></th>
4832 <td>
4833 <label>
4834 <input type="checkbox" name="wp_hardening[disable_feeds]" value="1" <?php checked( ! empty( $options['disable_feeds'] ) ); ?>>
4835 <?php esc_html_e( 'Completely disable RSS/Atom feeds', 'vigilante' ); ?>
4836 </label>
4837 </td>
4838 </tr>
4839 <tr>
4840 <th scope="row"><?php esc_html_e( 'Disable If No Content', 'vigilante' ); ?></th>
4841 <td>
4842 <label>
4843 <input type="checkbox" name="wp_hardening[disable_if_no_content]" value="1" <?php checked( ! empty( $options['disable_if_no_content'] ) ); ?>>
4844 <?php esc_html_e( 'Only disable feeds if site has no published posts', 'vigilante' ); ?>
4845 </label>
4846 </td>
4847 </tr>
4848 <tr>
4849 <th scope="row"><?php esc_html_e( 'Remove Feed Version', 'vigilante' ); ?></th>
4850 <td>
4851 <label>
4852 <input type="checkbox" name="wp_hardening[remove_feed_version]" value="1" <?php checked( ! empty( $options['remove_feed_version'] ) ); ?>>
4853 <?php esc_html_e( 'Remove WordPress version from feed generator tag', 'vigilante' ); ?>
4854 </label>
4855 </td>
4856 </tr>
4857 </table>
4858 </div>
4859
4860 <p class="submit vigilante-submit-buttons">
4861 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4862 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4863 </button>
4864 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4865 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4866 </button>
4867 </p>
4868 </form>
4869 <?php
4870 }
4871
4872 /**
4873 * Render activity log tab
4874 */
4875 private function render_tab_activity_log() {
4876 $is_disabled = $this->render_module_disabled_notice( 'activity_log' );
4877 $options = $this->settings->get_section( 'activity_log' );
4878 ?>
4879 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="activity_log" <?php echo $is_disabled ? 'inert' : ''; ?>>
4880 <div id="vigilante-section-audit-settings" class="vigilante-settings-section">
4881 <h2>
4882 <?php esc_html_e( 'Security Audit Settings', 'vigilante' ); ?>
4883 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4884 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
4885 </h2>
4886 <p><?php esc_html_e( 'Security event logging and auditing.', 'vigilante' ); ?></p>
4887
4888 <table class="form-table">
4889 <tr>
4890 <th scope="row"><?php esc_html_e( 'Retention', 'vigilante' ); ?></th>
4891 <td>
4892 <input type="number" name="activity_log[retention_days]" value="<?php echo esc_attr( $options['retention_days'] ?? 30 ); ?>" min="7" max="365" class="small-text">
4893 <?php esc_html_e( 'days', 'vigilante' ); ?>
4894 &nbsp;&nbsp;
4895 <input type="number" name="activity_log[max_entries]" value="<?php echo esc_attr( $options['max_entries'] ?? 10000 ); ?>" min="100" max="100000" step="100" class="small-text">
4896 <?php esc_html_e( 'max entries', 'vigilante' ); ?>
4897 <p class="description"><?php esc_html_e( 'Whichever limit is reached first takes effect. Changes apply immediately on save; daily maintenance also enforces these limits automatically.', 'vigilante' ); ?></p>
4898 </td>
4899 </tr>
4900 <tr>
4901 <th scope="row"><?php esc_html_e( 'Events to Log', 'vigilante' ); ?></th>
4902 <td>
4903 <fieldset style="display:grid; grid-template-columns:repeat(auto-fit, minmax(240px, 1fr)); gap:6px 24px; max-width:600px;">
4904 <label><input type="checkbox" name="activity_log[log_logins]" value="1" <?php checked( ! empty( $options['log_logins'] ) ); ?>> <?php esc_html_e( 'Successful logins', 'vigilante' ); ?></label>
4905 <label><input type="checkbox" name="activity_log[log_failed_logins]" value="1" <?php checked( ! empty( $options['log_failed_logins'] ) ); ?>> <?php esc_html_e( 'Failed login attempts', 'vigilante' ); ?></label>
4906 <label><input type="checkbox" name="activity_log[log_user_changes]" value="1" <?php checked( ! empty( $options['log_user_changes'] ) ); ?>> <?php esc_html_e( 'User changes', 'vigilante' ); ?></label>
4907 <label><input type="checkbox" name="activity_log[log_post_changes]" value="1" <?php checked( ! empty( $options['log_post_changes'] ) ); ?>> <?php esc_html_e( 'Content changes', 'vigilante' ); ?></label>
4908 <label><input type="checkbox" name="activity_log[log_plugin_changes]" value="1" <?php checked( ! empty( $options['log_plugin_changes'] ) ); ?>> <?php esc_html_e( 'Plugin changes', 'vigilante' ); ?></label>
4909 <label><input type="checkbox" name="activity_log[log_theme_changes]" value="1" <?php checked( ! empty( $options['log_theme_changes'] ) ); ?>> <?php esc_html_e( 'Theme changes', 'vigilante' ); ?></label>
4910 <label><input type="checkbox" name="activity_log[log_comments]" value="1" <?php checked( ! empty( $options['log_comments'] ) ); ?>> <?php esc_html_e( 'Comment changes', 'vigilante' ); ?></label>
4911 <label><input type="checkbox" name="activity_log[log_media]" value="1" <?php checked( ! empty( $options['log_media'] ) ); ?>> <?php esc_html_e( 'Media uploads/deletions', 'vigilante' ); ?></label>
4912 <label><input type="checkbox" name="activity_log[log_file_changes]" value="1" <?php checked( ! empty( $options['log_file_changes'] ) ); ?>> <?php esc_html_e( 'File integrity events', 'vigilante' ); ?></label>
4913 <label><input type="checkbox" name="activity_log[log_option_changes]" value="1" <?php checked( ! empty( $options['log_option_changes'] ) ); ?>> <?php esc_html_e( 'WordPress option changes', 'vigilante' ); ?></label>
4914 </fieldset>
4915 <div class="notice notice-info inline" style="margin:10px 0 0;padding:8px 12px;">
4916 <p style="margin:0;">
4917 <?php esc_html_e( 'Firewall blocks, security events, and Vigilant settings changes are always logged regardless of the above selections.', 'vigilante' ); ?>
4918 </p>
4919 </div>
4920 </td>
4921 </tr>
4922 <tr>
4923 <th scope="row"><?php esc_html_e( 'Option Tracking', 'vigilante' ); ?></th>
4924 <td>
4925 <p class="description" style="margin-top:0;"><?php esc_html_e( 'When "WordPress option changes" is enabled, Vigilant tracks ~30 core WordPress settings (site URL, admin email, registration, active plugins, theme, comments, privacy, etc.). Use the field below to track additional options from other plugins.', 'vigilante' ); ?></p>
4926 <br>
4927 <label><?php esc_html_e( 'Additional options to track:', 'vigilante' ); ?></label><br>
4928 <textarea name="activity_log[tracked_options]" rows="3" cols="50" class="regular-text code" placeholder="woocommerce_&#10;seopress_&#10;wpforms_"><?php echo esc_textarea( implode( "\n", $options['tracked_options'] ?? array() ) ); ?></textarea>
4929 <p class="description"><?php esc_html_e( 'One option name per line. Use a trailing underscore to match all options with that prefix (e.g. "woocommerce_" tracks all WooCommerce settings).', 'vigilante' ); ?></p>
4930 </td>
4931 </tr>
4932 <tr>
4933 <th scope="row"><?php esc_html_e( 'Exclusions', 'vigilante' ); ?></th>
4934 <td>
4935 <div style="display:grid; grid-template-columns:repeat(auto-fit, minmax(220px, 1fr)); gap:16px; max-width:600px;">
4936 <div>
4937 <label><?php esc_html_e( 'Excluded user IDs:', 'vigilante' ); ?></label><br>
4938 <textarea name="activity_log[excluded_users]" rows="3" cols="25"><?php echo esc_textarea( implode( "\n", $options['excluded_users'] ?? array() ) ); ?></textarea>
4939 <p class="description"><?php esc_html_e( 'One user ID per line. Actions by these users will not be logged.', 'vigilante' ); ?></p>
4940 </div>
4941 <div>
4942 <label><?php esc_html_e( 'Excluded IPs:', 'vigilante' ); ?></label><br>
4943 <textarea name="activity_log[excluded_ips]" rows="3" cols="25"><?php echo esc_textarea( implode( "\n", $options['excluded_ips'] ?? array() ) ); ?></textarea>
4944 <p class="description"><?php esc_html_e( 'One IP per line. Requests from these IPs will not be logged.', 'vigilante' ); ?></p>
4945 </div>
4946 </div>
4947 </td>
4948 </tr>
4949 </table>
4950 </div>
4951
4952 <p class="submit vigilante-submit-buttons">
4953 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4954 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4955 </button>
4956 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4957 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4958 </button>
4959 </p>
4960 </form>
4961
4962 <?php
4963 // Audit Alerts — alerting layer on top of Security Audit. Its own
4964 // settings section and form, rendered right after the logging settings
4965 // so the tab reads as "log this, exclude that, and alert me about this".
4966 $alerts = $this->settings->get_section( 'audit_alerts' );
4967 $immediate = isset( $alerts['immediate'] ) ? $alerts['immediate'] : array();
4968 $threshold = isset( $alerts['threshold'] ) ? $alerts['threshold'] : array();
4969 $alert_severity = isset( $immediate['min_severity'] ) ? $immediate['min_severity'] : 'critical';
4970 $alert_window = isset( $threshold['window'] ) ? $threshold['window'] : '1h';
4971 $threshold_cats = isset( $threshold['categories'] ) ? (array) $threshold['categories'] : array();
4972 $cat_labels = Vigilante_Audit_Alerts::category_labels();
4973 ?>
4974 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="audit_alerts" <?php echo $is_disabled ? 'inert' : ''; ?>>
4975 <div id="vigilante-section-audit-alerts" class="vigilante-settings-section">
4976 <h2>
4977 <?php esc_html_e( 'Audit Alerts', 'vigilante' ); ?>
4978 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4979 </h2>
4980 <p><?php esc_html_e( 'Get an email when the events above point to something worth your attention. Both alert types are off by default.', 'vigilante' ); ?></p>
4981
4982 <table class="form-table">
4983 <tr id="field-audit-alerts-immediate">
4984 <th scope="row"><?php esc_html_e( 'Immediate alerts', 'vigilante' ); ?></th>
4985 <td>
4986 <label>
4987 <input type="checkbox" name="audit_alerts[immediate][enabled]" value="1" <?php checked( ! empty( $immediate['enabled'] ) ); ?>>
4988 <?php esc_html_e( 'Email me as soon as a serious event is logged', 'vigilante' ); ?>
4989 </label>
4990 <p class="description"><?php esc_html_e( 'Sends one email per event type, then waits for the cooldown below before repeating, so a burst of the same event is a single notice.', 'vigilante' ); ?></p>
4991 </td>
4992 </tr>
4993 <tr>
4994 <th scope="row"><?php esc_html_e( 'Alert on severity', 'vigilante' ); ?></th>
4995 <td>
4996 <select name="audit_alerts[immediate][min_severity]">
4997 <option value="critical" <?php selected( $alert_severity, 'critical' ); ?>><?php esc_html_e( 'Critical only (recommended)', 'vigilante' ); ?></option>
4998 <option value="warning" <?php selected( $alert_severity, 'warning' ); ?>><?php esc_html_e( 'Warning and Critical', 'vigilante' ); ?></option>
4999 </select>
5000 <p class="description"><?php esc_html_e( 'A new administrator, a closed plugin or a privilege escalation are all logged as Critical, so "Critical only" already covers them.', 'vigilante' ); ?></p>
5001 </td>
5002 </tr>
5003 <tr id="field-audit-alerts-threshold">
5004 <th scope="row"><?php esc_html_e( 'Threshold alerts', 'vigilante' ); ?></th>
5005 <td>
5006 <label>
5007 <input type="checkbox" name="audit_alerts[threshold][enabled]" value="1" <?php checked( ! empty( $threshold['enabled'] ) ); ?>>
5008 <?php esc_html_e( 'Email me when a category spikes within a time window', 'vigilante' ); ?>
5009 </label>
5010 <p class="description"><?php esc_html_e( 'Catches an attack in progress, e.g. hundreds of firewall blocks or login failures in an hour.', 'vigilante' ); ?></p>
5011 </td>
5012 </tr>
5013 <tr>
5014 <th scope="row"><?php esc_html_e( 'Time window', 'vigilante' ); ?></th>
5015 <td>
5016 <select name="audit_alerts[threshold][window]">
5017 <option value="30m" <?php selected( $alert_window, '30m' ); ?>><?php esc_html_e( '30 minutes', 'vigilante' ); ?></option>
5018 <option value="1h" <?php selected( $alert_window, '1h' ); ?>><?php esc_html_e( '1 hour', 'vigilante' ); ?></option>
5019 <option value="6h" <?php selected( $alert_window, '6h' ); ?>><?php esc_html_e( '6 hours', 'vigilante' ); ?></option>
5020 <option value="24h" <?php selected( $alert_window, '24h' ); ?>><?php esc_html_e( '24 hours', 'vigilante' ); ?></option>
5021 </select>
5022 <p class="description"><?php esc_html_e( 'How far back Vigilant looks when counting events. For example, "1 hour" means "more than the number below within the last hour".', 'vigilante' ); ?></p>
5023 </td>
5024 </tr>
5025 <tr>
5026 <th scope="row"><?php esc_html_e( 'Thresholds per category', 'vigilante' ); ?></th>
5027 <td>
5028 <fieldset style="display:grid; grid-template-columns:repeat(auto-fit, minmax(200px, 1fr)); gap:8px 24px; max-width:760px;">
5029 <?php
5030 foreach ( $cat_labels as $cat_slug => $cat_label ) :
5031 $cat_value = isset( $threshold_cats[ $cat_slug ] ) ? (int) $threshold_cats[ $cat_slug ] : 0;
5032 ?>
5033 <label style="display:flex;align-items:center;gap:8px;justify-content:space-between;">
5034 <span><?php echo esc_html( $cat_label ); ?></span>
5035 <input type="number" name="audit_alerts[threshold][categories][<?php echo esc_attr( $cat_slug ); ?>]" value="<?php echo esc_attr( $cat_value ); ?>" min="0" max="100000" step="1" class="small-text">
5036 </label>
5037 <?php endforeach; ?>
5038 </fieldset>
5039 <p class="description"><?php esc_html_e( 'Number of warning/critical events in the window that triggers an alert. 0 disables that category. Routine info-level activity (normal logins, edits) is not counted.', 'vigilante' ); ?></p>
5040 </td>
5041 </tr>
5042 <tr>
5043 <th scope="row"><?php esc_html_e( "Don't repeat alerts", 'vigilante' ); ?></th>
5044 <td>
5045 <input type="number" name="audit_alerts[cooldown_minutes]" value="<?php echo esc_attr( isset( $alerts['cooldown_minutes'] ) ? (int) $alerts['cooldown_minutes'] : 60 ); ?>" min="0" max="1440" class="small-text">
5046 <?php esc_html_e( 'minutes', 'vigilante' ); ?>
5047 <p class="description"><?php esc_html_e( 'After an alert, Vigilant waits this long before sending another about the same thing: the same event type for immediate alerts, or the same category for threshold alerts. This prevents a flood during a sustained attack. Applies to both alert types above.', 'vigilante' ); ?></p>
5048 </td>
5049 </tr>
5050
5051 <tr>
5052 <th scope="row"><?php esc_html_e( 'Recipients', 'vigilante' ); ?></th>
5053 <td>
5054 <p class="description" style="margin-top:0;">
5055 <?php
5056 printf(
5057 /* translators: %s: Link to notification settings */
5058 esc_html__( 'Alerts go to the recipients configured in %s.', 'vigilante' ),
5059 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
5060 );
5061 ?>
5062 </p>
5063 <p style="margin:8px 0 0;">
5064 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
5065 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
5066 </button>
5067 <span class="vigilante-test-email-result" style="margin-left:8px;"></span>
5068 </p>
5069 <p class="description"><?php esc_html_e( 'Heads up: some events (a new admin, a closed plugin) already send their own email from other modules. Enabling alerts for them here too may produce two notices until notifications are unified.', 'vigilante' ); ?></p>
5070 </td>
5071 </tr>
5072 </table>
5073 </div>
5074
5075 <p class="submit vigilante-submit-buttons">
5076 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5077 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5078 </button>
5079 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5080 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5081 </button>
5082 </p>
5083 </form>
5084
5085 <div id="vigilante-section-audit-recent" class="vigilante-settings-section">
5086 <h2><?php esc_html_e( 'Recent Activity', 'vigilante' ); ?></h2>
5087
5088 <?php
5089 $logs = $this->activity_log->get_logs( array( 'per_page' => 20 ) );
5090 $total_logs = $this->activity_log->get_logs_count();
5091
5092 // Label maps for translated display
5093 $type_labels = array(
5094 'login' => __( 'Login', 'vigilante' ),
5095 'user' => __( 'User', 'vigilante' ),
5096 'content' => __( 'Content', 'vigilante' ),
5097 'plugin' => __( 'Plugin', 'vigilante' ),
5098 'theme' => __( 'Theme', 'vigilante' ),
5099 'settings' => __( 'Settings', 'vigilante' ),
5100 'comment' => __( 'Comment', 'vigilante' ),
5101 'media' => __( 'Media', 'vigilante' ),
5102 'firewall' => __( 'Firewall', 'vigilante' ),
5103 'file' => __( 'File', 'vigilante' ),
5104 'security' => __( 'Security', 'vigilante' ),
5105 'system' => __( 'System', 'vigilante' ),
5106 );
5107 $severity_labels = array(
5108 'info' => __( 'Info', 'vigilante' ),
5109 'warning' => __( 'Warning', 'vigilante' ),
5110 'critical' => __( 'Critical', 'vigilante' ),
5111 );
5112
5113 $firewall_options = $this->settings->get_section( 'firewall' );
5114 $ip_whitelist = $firewall_options['ip_whitelist'] ?? array();
5115 $ip_blacklist = $firewall_options['ip_blacklist'] ?? array();
5116 $ua_whitelist = $firewall_options['ua_whitelist'] ?? array();
5117 $ua_blacklist = $firewall_options['ua_blacklist'] ?? array();
5118 ?>
5119
5120 <div class="vigilante-log-filters">
5121 <input type="text" id="vigilante-log-search" size="1" placeholder="<?php esc_attr_e( 'Search logs (min. 3 characters)...', 'vigilante' ); ?>" class="vigilante-log-search-input">
5122 <select id="vigilante-log-type-filter">
5123 <option value=""><?php esc_html_e( 'All Types', 'vigilante' ); ?></option>
5124 <option value="login"><?php esc_html_e( 'Login', 'vigilante' ); ?></option>
5125 <option value="user"><?php esc_html_e( 'User', 'vigilante' ); ?></option>
5126 <option value="content"><?php esc_html_e( 'Content', 'vigilante' ); ?></option>
5127 <option value="plugin"><?php esc_html_e( 'Plugin', 'vigilante' ); ?></option>
5128 <option value="theme"><?php esc_html_e( 'Theme', 'vigilante' ); ?></option>
5129 <option value="settings"><?php esc_html_e( 'Settings', 'vigilante' ); ?></option>
5130 <option value="comment"><?php esc_html_e( 'Comment', 'vigilante' ); ?></option>
5131 <option value="media"><?php esc_html_e( 'Media', 'vigilante' ); ?></option>
5132 <option value="firewall"><?php esc_html_e( 'Firewall', 'vigilante' ); ?></option>
5133 <option value="file"><?php esc_html_e( 'File', 'vigilante' ); ?></option>
5134 <option value="security"><?php esc_html_e( 'Security', 'vigilante' ); ?></option>
5135 <option value="system"><?php esc_html_e( 'System', 'vigilante' ); ?></option>
5136 </select>
5137 <select id="vigilante-log-severity-filter">
5138 <option value=""><?php esc_html_e( 'All Severities', 'vigilante' ); ?></option>
5139 <option value="info"><?php esc_html_e( 'Info', 'vigilante' ); ?></option>
5140 <option value="warning"><?php esc_html_e( 'Warning', 'vigilante' ); ?></option>
5141 <option value="critical"><?php esc_html_e( 'Critical', 'vigilante' ); ?></option>
5142 </select>
5143 <select id="vigilante-log-method-filter">
5144 <option value=""><?php esc_html_e( 'All Methods', 'vigilante' ); ?></option>
5145 <option value="GET">GET</option>
5146 <option value="POST">POST</option>
5147 <option value="PUT">PUT</option>
5148 <option value="DELETE">DELETE</option>
5149 <option value="PATCH">PATCH</option>
5150 <option value="OPTIONS">OPTIONS</option>
5151 <option value="HEAD">HEAD</option>
5152 </select>
5153 <button type="button" id="vigilante-log-refresh" class="button"><?php esc_html_e( 'Refresh', 'vigilante' ); ?></button>
5154 <span class="vigilante-pagination" id="vigilante-log-pagination" data-total="<?php echo esc_attr( $total_logs ); ?>" data-per-page="20" data-page="1">
5155 <?php if ( $total_logs > 20 ) : ?>
5156 <button type="button" class="vigilante-page-first" title="<?php esc_attr_e( 'First page', 'vigilante' ); ?>" disabled>&laquo;</button>
5157 <button type="button" class="vigilante-page-prev" title="<?php esc_attr_e( 'Previous page', 'vigilante' ); ?>" disabled>&lsaquo;</button>
5158 <?php endif; ?>
5159 <span class="vigilante-page-info">
5160 <?php
5161 $showing = min( 20, $total_logs );
5162 printf(
5163 /* translators: 1: first item, 2: last item, 3: total items */
5164 esc_html__( '%1$d–%2$d of %3$d', 'vigilante' ),
5165 $total_logs > 0 ? 1 : 0,
5166 absint( $showing ),
5167 absint( $total_logs )
5168 );
5169 ?>
5170 </span>
5171 <?php if ( $total_logs > 20 ) : ?>
5172 <button type="button" class="vigilante-page-next" title="<?php esc_attr_e( 'Next page', 'vigilante' ); ?>">&rsaquo;</button>
5173 <button type="button" class="vigilante-page-last" title="<?php esc_attr_e( 'Last page', 'vigilante' ); ?>">&raquo;</button>
5174 <?php endif; ?>
5175 </span>
5176 </div>
5177
5178 <div class="vigilante-log-table-wrap">
5179 <table id="vigilante-activity-log-table" class="wp-list-table widefat striped">
5180 <thead>
5181 <tr>
5182 <th class="column-date"><?php esc_html_e( 'Date', 'vigilante' ); ?></th>
5183 <th class="column-type"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
5184 <th class="column-method"><?php esc_html_e( 'Method', 'vigilante' ); ?></th>
5185 <th class="column-severity"><?php esc_html_e( 'Severity', 'vigilante' ); ?></th>
5186 <th class="column-message"><?php esc_html_e( 'Message', 'vigilante' ); ?></th>
5187 <th class="column-user"><?php esc_html_e( 'User', 'vigilante' ); ?></th>
5188 <th class="column-ip"><?php esc_html_e( 'IP', 'vigilante' ); ?></th>
5189 <th class="column-details"><?php esc_html_e( 'Details', 'vigilante' ); ?></th>
5190 </tr>
5191 </thead>
5192 <tbody>
5193 <?php
5194 if ( empty( $logs ) ) :
5195 ?>
5196 <tr><td colspan="8"><?php esc_html_e( 'No log entries found.', 'vigilante' ); ?></td></tr>
5197 <?php else : ?>
5198 <?php foreach ( $logs as $log ) :
5199 $request_method = isset( $log->request_method ) ? $log->request_method : '';
5200 // Prepare details as a simple object
5201 $ip_val = (string) ( $log->ip_address ?? '' );
5202 $ua_val = (string) ( $log->user_agent ?? '' );
5203 $details = array(
5204 'id' => (int) $log->id,
5205 'type' => (string) ( $log->event_type ?? '' ),
5206 'action' => (string) ( $log->event_action ?? '' ),
5207 'message' => (string) ( $log->event_message ?? '' ),
5208 'user' => (string) ( $log->user_login ?? '' ),
5209 'ip' => $ip_val,
5210 'user_agent' => $ua_val,
5211 'request_method' => (string) $request_method,
5212 'date' => (string) ( $log->created_at ?? '' ),
5213 'severity' => (string) ( $log->severity ?? 'info' ),
5214 'is_ip_whitelisted' => ( '' !== $ip_val && in_array( $ip_val, $ip_whitelist, true ) ),
5215 'is_ip_blacklisted' => ( '' !== $ip_val && in_array( $ip_val, $ip_blacklist, true ) ),
5216 'is_ua_whitelisted' => ( '' !== $ua_val && in_array( $ua_val, $ua_whitelist, true ) ),
5217 'is_ua_blacklisted' => ( '' !== $ua_val && in_array( $ua_val, $ua_blacklist, true ) ),
5218 );
5219 $display_type = isset( $type_labels[ $log->event_type ] ) ? $type_labels[ $log->event_type ] : $log->event_type;
5220 $display_severity = isset( $severity_labels[ $log->severity ] ) ? $severity_labels[ $log->severity ] : $log->severity;
5221 ?>
5222 <tr class="vigilante-severity-<?php echo esc_attr( $log->severity ); ?>">
5223 <td><?php echo esc_html( $log->created_at ); ?></td>
5224 <td><?php echo esc_html( $display_type ); ?></td>
5225 <td><?php if ( ! empty( $request_method ) ) : ?><span class="vigilante-method-label vigilante-method-<?php echo esc_attr( strtolower( $request_method ) ); ?>"><?php echo esc_html( $request_method ); ?></span><?php else : ?>-<?php endif; ?></td>
5226 <td><span class="vigilante-badge vigilante-badge-<?php echo esc_attr( $log->severity ); ?>"><?php echo esc_html( $display_severity ); ?></span></td>
5227 <td><?php echo esc_html( $log->event_message ); ?></td>
5228 <td><?php echo esc_html( $log->user_login ?? '-' ); ?></td>
5229 <td><code><?php echo esc_html( $log->ip_address ); ?></code></td>
5230 <td>
5231 <button type="button" class="button button-small vigilante-view-log-details"
5232 data-details='<?php echo esc_attr( wp_json_encode( $details, JSON_HEX_APOS | JSON_HEX_QUOT ) ); ?>'>
5233 <?php esc_html_e( 'View', 'vigilante' ); ?>
5234 </button>
5235 </td>
5236 </tr>
5237 <?php endforeach; ?>
5238 <?php endif; ?>
5239 </tbody>
5240 </table>
5241 </div>
5242
5243 <!-- Log Details Modal -->
5244 <div id="vigilante-log-details-modal" class="vigilante-modal" style="display: none;">
5245 <div class="vigilante-modal-content">
5246 <span class="vigilante-modal-close">&times;</span>
5247 <h3><?php esc_html_e( 'Log Entry Details', 'vigilante' ); ?></h3>
5248 <div id="vigilante-log-details-content"></div>
5249 </div>
5250 </div>
5251
5252 <p>
5253 <button type="button" class="button vigilante-export-logs"><?php esc_html_e( 'Export Audit Log', 'vigilante' ); ?></button>
5254 <button type="button" class="button vigilante-clear-logs" style="color: #a00;"><?php esc_html_e( 'Clear All Logs', 'vigilante' ); ?></button>
5255 </p>
5256 </div>
5257 <?php
5258 }
5259
5260 /**
5261 * Render File Integrity tab
5262 */
5263 private function render_tab_file_integrity() {
5264 $is_disabled = $this->render_module_disabled_notice( 'file_integrity' );
5265 $options = $this->settings->get_section( 'file_integrity' );
5266 $last_scan = get_option( 'vigilante_last_integrity_scan' );
5267 $last_results = get_option( 'vigilante_last_integrity_results' );
5268 $ignored_files = get_option( 'vigilante_ignored_files', array() );
5269
5270 // Backward compat: convert old notify_on_changes to notify_level
5271 $notify_level = $options['notify_level'] ?? '';
5272 if ( empty( $notify_level ) ) {
5273 $notify_level = ! empty( $options['notify_on_changes'] ) ? 'all' : 'disabled';
5274 }
5275
5276 // Closed + Removed plugins data. Surfaced inside Last Scan Results so the
5277 // user sees file findings and plugin closures together (same tier of risk,
5278 // same UI), and as the trigger to keep Last Scan Results open even when no
5279 // file scan has run yet (the daily cron may have populated this section).
5280 //
5281 // Gating by last_check_time > 0 is how "Clear Previous Results" visually
5282 // resets this block: the option vigilante_plugin_status_last_check is
5283 // deleted on Clear, but the state map and the ignored list survive so the
5284 // next scan reconstructs without degrading a 'removed' slug. While
5285 // last_check is 0, we treat the plugin_status data as if it didn't exist.
5286 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
5287 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
5288 }
5289 $closed_checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
5290 $closed_last_check = $closed_checker->get_last_check_time();
5291 if ( $closed_last_check > 0 ) {
5292 $closed_plugins = $closed_checker->get_closed_plugins();
5293 $ignored_closed_plugins = $closed_checker->get_ignored_closed_plugins();
5294 } else {
5295 $closed_plugins = array();
5296 $ignored_closed_plugins = array();
5297 }
5298 $has_closed = ! empty( $closed_plugins );
5299 $datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
5300 ?>
5301 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="file_integrity" <?php echo $is_disabled ? 'inert' : ''; ?>>
5302 <div id="vigilante-section-fi-monitoring" class="vigilante-settings-section">
5303 <h2>
5304 <?php esc_html_e( 'File Integrity Monitoring', 'vigilante' ); ?>
5305 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5306 </h2>
5307 <p><?php esc_html_e( 'Detects file modifications using WordPress.org checksums.', 'vigilante' ); ?></p>
5308
5309 <table class="form-table">
5310 <tr>
5311 <th scope="row"><?php esc_html_e( 'Automatic Scans', 'vigilante' ); ?></th>
5312 <td>
5313 <label>
5314 <input type="checkbox" name="file_integrity[auto_scan]" value="1" <?php checked( ! empty( $options['auto_scan'] ) ); ?>>
5315 <?php esc_html_e( 'Enable scheduled file integrity scans', 'vigilante' ); ?>
5316 </label>
5317 </td>
5318 </tr>
5319 <tr>
5320 <th scope="row"><?php esc_html_e( 'Scan Frequency', 'vigilante' ); ?></th>
5321 <td>
5322 <select name="file_integrity[scan_frequency]">
5323 <option value="daily" <?php selected( $options['scan_frequency'] ?? 'daily', 'daily' ); ?>><?php esc_html_e( 'Daily', 'vigilante' ); ?></option>
5324 <option value="weekly" <?php selected( $options['scan_frequency'] ?? 'daily', 'weekly' ); ?>><?php esc_html_e( 'Weekly', 'vigilante' ); ?></option>
5325 </select>
5326 </td>
5327 </tr>
5328 <tr>
5329 <th scope="row"><?php esc_html_e( 'Email Notifications', 'vigilante' ); ?></th>
5330 <td>
5331 <select name="file_integrity[notify_level]">
5332 <option value="all" <?php selected( $notify_level, 'all' ); ?>><?php esc_html_e( 'All issues (modified + suspicious)', 'vigilante' ); ?></option>
5333 <option value="suspicious_only" <?php selected( $notify_level, 'suspicious_only' ); ?>><?php esc_html_e( 'Suspicious files only', 'vigilante' ); ?></option>
5334 <option value="disabled" <?php selected( $notify_level, 'disabled' ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
5335 </select>
5336 <p class="description"><?php esc_html_e( '"Suspicious files only" reduces noise by skipping modified file notifications. Recommended for most sites.', 'vigilante' ); ?></p>
5337 </td>
5338 </tr>
5339 <tr>
5340 <th scope="row"><?php esc_html_e( 'Instant Alert', 'vigilante' ); ?></th>
5341 <td>
5342 <label>
5343 <input type="checkbox" name="file_integrity[instant_alert]" value="1" <?php checked( ! empty( $options['instant_alert'] ) ); ?>>
5344 <?php esc_html_e( 'Send immediate alert when modified, suspicious or additional files are detected, or when a closed plugin is found', 'vigilante' ); ?>
5345 </label>
5346 <p class="description"><?php esc_html_e( 'Fires even if the Email Notifications setting above is set to Disabled.', 'vigilante' ); ?></p>
5347 <p class="description">
5348 <?php
5349 printf(
5350 /* translators: %s: Link to notification settings */
5351 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
5352 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
5353 );
5354 ?>
5355 </p>
5356 </td>
5357 </tr>
5358 <tr>
5359 <th scope="row"><?php esc_html_e( 'Test email', 'vigilante' ); ?></th>
5360 <td>
5361 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
5362 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
5363 </button>
5364 <span class="vigilante-test-email-result" style="margin-left:8px;"></span>
5365 <p class="description"><?php esc_html_e( 'Sends a test message to the configured recipients to confirm email delivery works.', 'vigilante' ); ?></p>
5366 </td>
5367 </tr>
5368 <tr>
5369 <th scope="row"><?php esc_html_e( 'Scan Scope', 'vigilante' ); ?></th>
5370 <td>
5371 <fieldset>
5372 <label>
5373 <input type="checkbox" name="file_integrity[scan_core]" value="1" <?php checked( $options['scan_core'] ?? true ); ?>>
5374 <?php esc_html_e( 'Core files (compare against WordPress.org checksums)', 'vigilante' ); ?>
5375 </label>
5376 <br>
5377 <label>
5378 <input type="checkbox" name="file_integrity[scan_plugins]" value="1" <?php checked( $options['scan_plugins'] ?? true ); ?>>
5379 <?php esc_html_e( 'Plugins (WordPress.org repository plugins)', 'vigilante' ); ?>
5380 </label>
5381 <br>
5382 <label>
5383 <input type="checkbox" name="file_integrity[scan_themes]" value="1" <?php checked( $options['scan_themes'] ?? true ); ?>>
5384 <?php esc_html_e( 'Themes (WordPress.org repository themes)', 'vigilante' ); ?>
5385 </label>
5386 <br>
5387 <label>
5388 <input type="checkbox" name="file_integrity[scan_uploads]" value="1" <?php checked( $options['scan_uploads'] ?? true ); ?>>
5389 <?php esc_html_e( 'Uploads directory (detect PHP files, double extensions, .htaccess)', 'vigilante' ); ?>
5390 </label>
5391 <br>
5392 <label>
5393 <input type="checkbox" name="file_integrity[scan_critical_config]" value="1" <?php checked( $options['scan_critical_config'] ?? true ); ?>>
5394 <?php esc_html_e( 'Critical config files (wp-config.php, .htaccess baseline monitoring)', 'vigilante' ); ?>
5395 </label>
5396 <br>
5397 <label>
5398 <input type="checkbox" name="file_integrity[check_closed_plugins]" value="1" <?php checked( $options['check_closed_plugins'] ?? true ); ?>>
5399 <?php esc_html_e( 'Closed plugins (daily check against the WordPress.org repository)', 'vigilante' ); ?>
5400 </label>
5401 </fieldset>
5402 </td>
5403 </tr>
5404 <tr>
5405 <th scope="row"><?php esc_html_e( 'Excluded Paths', 'vigilante' ); ?></th>
5406 <td>
5407 <textarea name="file_integrity[excluded_paths]" rows="4" class="large-text code" placeholder="wp-content/cache&#10;wp-content/languages"><?php echo esc_textarea( implode( "\n", $options['excluded_paths'] ?? array() ) ); ?></textarea>
5408 <p class="description"><?php esc_html_e( 'One path per line (relative to WordPress root). Files within these paths will be skipped during scans.', 'vigilante' ); ?></p>
5409 </td>
5410 </tr>
5411 <tr>
5412 <th scope="row"><?php esc_html_e( 'Excluded Extensions', 'vigilante' ); ?></th>
5413 <td>
5414 <textarea name="file_integrity[excluded_extensions]" rows="3" class="large-text code" placeholder=".log&#10;.po&#10;.mo&#10;.pot"><?php echo esc_textarea( implode( "\n", $options['excluded_extensions'] ?? array() ) ); ?></textarea>
5415 <p class="description"><?php esc_html_e( 'One extension per line (e.g. .log, .po, .mo). Files with these extensions will be skipped. Useful to avoid false positives from translation or log files.', 'vigilante' ); ?></p>
5416 </td>
5417 </tr>
5418 </table>
5419 </div>
5420
5421 <p class="submit vigilante-submit-buttons">
5422 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5423 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5424 </button>
5425 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5426 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5427 </button>
5428 <span class="vigilante-buttons-separator"></span>
5429 <button type="button" class="button button-primary vigilante-run-scan">
5430 <?php esc_html_e( 'Run Scan Now', 'vigilante' ); ?>
5431 </button>
5432 <button type="button" class="button vigilante-clear-scan-btn vigilante-clear-scan">
5433 <?php esc_html_e( 'Clear Previous Results', 'vigilante' ); ?>
5434 </button>
5435 </p>
5436 </form>
5437
5438 <div id="vigilante-scan-results" class="vigilante-settings-section" style="display:none;"></div>
5439
5440 <?php if ( $last_scan || $has_closed || $closed_last_check > 0 ) : ?>
5441 <div id="vigilante-section-fi-last-scan" class="vigilante-settings-section">
5442 <h2><?php esc_html_e( 'Last Scan Results', 'vigilante' ); ?></h2>
5443 <?php if ( $last_scan ) : ?>
5444 <p>
5445 <?php
5446 // Build the "X files scanned" hint inline with the date so it doesn't
5447 // need its own stat box (keeps the row compact when closed plugins are
5448 // present).
5449 $scanned_total = 0;
5450 if ( $last_results ) {
5451 $scanned_total = (int) ( $last_results['ok'] ?? 0 )
5452 + count( $last_results['modified'] ?? array() )
5453 + count( $last_results['suspicious'] ?? array() )
5454 + count( $last_results['extra'] ?? array() )
5455 + count( $ignored_files );
5456 }
5457 if ( $scanned_total > 0 ) {
5458 printf(
5459 /* translators: 1: date and time of last scan, 2: formatted file count */
5460 esc_html__( 'Last scan: %1$s (%2$s files scanned)', 'vigilante' ),
5461 esc_html( wp_date( $datetime_format, $last_scan ) ),
5462 esc_html( number_format_i18n( $scanned_total ) )
5463 );
5464 } else {
5465 printf(
5466 /* translators: %s: date and time of last scan */
5467 esc_html__( 'Last scan: %s', 'vigilante' ),
5468 esc_html( wp_date( $datetime_format, $last_scan ) )
5469 );
5470 }
5471 if ( $closed_last_check > 0 && $closed_last_check !== (int) $last_scan ) {
5472 echo ' &middot; ';
5473 printf(
5474 /* translators: %s: date and time of last closed plugins check */
5475 esc_html__( 'Closed plugins last checked: %s', 'vigilante' ),
5476 esc_html( wp_date( $datetime_format, $closed_last_check ) )
5477 );
5478 }
5479 ?>
5480 </p>
5481 <?php elseif ( $closed_last_check > 0 ) : ?>
5482 <p>
5483 <?php
5484 printf(
5485 /* translators: %s: date and time of last closed plugins check */
5486 esc_html__( 'Closed plugins last checked: %s &middot; the daily cron is running, no full integrity scan yet.', 'vigilante' ),
5487 esc_html( wp_date( $datetime_format, $closed_last_check ) )
5488 );
5489 ?>
5490 </p>
5491 <?php endif; ?>
5492 <div id="vigilante-last-scan-results">
5493 <?php if ( $last_results || $has_closed ) : ?>
5494 <div class="vigilante-scan-summary">
5495 <?php if ( $last_results ) : ?>
5496 <div class="vigilante-scan-stat vigilante-stat-ok">
5497 <span class="vigilante-stat-number"><?php echo esc_html( $last_results['ok'] ?? 0 ); ?></span>
5498 <span class="vigilante-stat-label"><?php esc_html_e( 'OK', 'vigilante' ); ?></span>
5499 </div>
5500 <div class="vigilante-scan-stat vigilante-stat-modified">
5501 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['modified'] ?? array() ) ); ?></span>
5502 <span class="vigilante-stat-label"><?php esc_html_e( 'Modified', 'vigilante' ); ?></span>
5503 </div>
5504 <div class="vigilante-scan-stat vigilante-stat-suspicious">
5505 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['suspicious'] ?? array() ) ); ?></span>
5506 <span class="vigilante-stat-label"><?php esc_html_e( 'Suspicious', 'vigilante' ); ?></span>
5507 </div>
5508 <div class="vigilante-scan-stat vigilante-stat-extra">
5509 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['extra'] ?? array() ) ); ?></span>
5510 <span class="vigilante-stat-label"><?php esc_html_e( 'Extra', 'vigilante' ); ?></span>
5511 </div>
5512 <?php endif; ?>
5513 <?php if ( $has_closed ) : ?>
5514 <div class="vigilante-scan-stat vigilante-stat-suspicious">
5515 <span class="vigilante-stat-number" style="color: #d63638;"><?php echo (int) count( $closed_plugins ); ?></span>
5516 <span class="vigilante-stat-label"><?php esc_html_e( 'Closed/Removed', 'vigilante' ); ?></span>
5517 </div>
5518 <?php endif; ?>
5519 <?php if ( ! empty( $ignored_files ) ) : ?>
5520 <div class="vigilante-scan-stat vigilante-stat-ignored">
5521 <span class="vigilante-stat-number"><?php echo esc_html( count( $ignored_files ) ); ?></span>
5522 <span class="vigilante-stat-label"><?php esc_html_e( 'Ignored', 'vigilante' ); ?></span>
5523 </div>
5524 <?php endif; ?>
5525 </div>
5526
5527 <?php if ( ! empty( $last_results['suspicious'] ) ) : ?>
5528 <div class="vigilante-file-list vigilante-suspicious-files vigilante-paginated-section" data-bulk-mode="ignore">
5529 <h3 style="color: #d63638;"><?php esc_html_e( 'Suspicious Files', 'vigilante' ); ?></h3>
5530 <p class="description" style="color: #d63638;"><?php esc_html_e( '&#9888; Warning: These files may contain malicious code or are in unexpected locations. Review immediately!', 'vigilante' ); ?></p>
5531 <div class="vigilante-fi-bulk-bar">
5532 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
5533 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
5534 </div>
5535 <div class="vigilante-fi-pagination-wrap"></div>
5536 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
5537 <thead>
5538 <tr>
5539 <td class="manage-column column-cb check-column"><input type="checkbox" class="vigilante-fi-cb-all" aria-label="<?php esc_attr_e( 'Select all', 'vigilante' ); ?>"></td>
5540 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
5541 <th style="width: 250px;"><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
5542 <th style="width: 120px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
5543 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5544 </tr>
5545 </thead>
5546 <tbody>
5547 <?php
5548 foreach ( $last_results['suspicious'] as $item ) {
5549 $file_path = '';
5550 $file_reason = __( 'Unknown', 'vigilante' );
5551 $file_type = 'unknown';
5552
5553 if ( is_array( $item ) ) {
5554 if ( isset( $item['file'] ) ) {
5555 $file_path = $item['file'];
5556 }
5557 if ( isset( $item['reason'] ) ) {
5558 $file_reason = $item['reason'];
5559 }
5560 if ( isset( $item['type'] ) ) {
5561 $file_type = $item['type'];
5562 }
5563 } else {
5564 $file_path = (string) $item;
5565 }
5566 ?>
5567 <tr>
5568 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
5569 <td><code style="color: #d63638;"><?php echo esc_html( $file_path ); ?></code></td>
5570 <td><?php echo esc_html( $file_reason ); ?></td>
5571 <td><?php echo esc_html( $file_type ); ?></td>
5572 <td><button type="button" class="button button-small vigilante-ignore-file" data-file="<?php echo esc_attr( $file_path ); ?>"><?php esc_html_e( 'Ignore', 'vigilante' ); ?></button></td>
5573 </tr>
5574 <?php
5575 }
5576 ?>
5577 </tbody>
5578 </table>
5579 </div>
5580 <?php endif; ?>
5581
5582 <?php if ( ! empty( $last_results['extra'] ) ) : ?>
5583 <div class="vigilante-file-list vigilante-extra-files vigilante-paginated-section" data-bulk-mode="ignore">
5584 <h3 style="color: #b32d2e;"><?php esc_html_e( 'Extra Files', 'vigilante' ); ?></h3>
5585 <p class="description"><?php esc_html_e( 'PHP files found in plugins or themes that are not part of the original distribution from WordPress.org. May be legitimate customizations or injected backdoors.', 'vigilante' ); ?></p>
5586 <div class="vigilante-fi-bulk-bar">
5587 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
5588 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
5589 </div>
5590 <div class="vigilante-fi-pagination-wrap"></div>
5591 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
5592 <thead>
5593 <tr>
5594 <td class="manage-column column-cb check-column"><input type="checkbox" class="vigilante-fi-cb-all" aria-label="<?php esc_attr_e( 'Select all', 'vigilante' ); ?>"></td>
5595 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
5596 <th style="width: 250px;"><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
5597 <th style="width: 120px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
5598 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5599 </tr>
5600 </thead>
5601 <tbody>
5602 <?php
5603 foreach ( $last_results['extra'] as $item ) {
5604 $file_path = is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item;
5605 $file_reason = is_array( $item ) ? ( $item['reason'] ?? __( 'Unknown', 'vigilante' ) ) : __( 'Unknown', 'vigilante' );
5606 $file_type = is_array( $item ) ? ( $item['type'] ?? 'unknown' ) : 'unknown';
5607 ?>
5608 <tr>
5609 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
5610 <td><code style="color: #b32d2e;"><?php echo esc_html( $file_path ); ?></code></td>
5611 <td><?php echo esc_html( $file_reason ); ?></td>
5612 <td><?php echo esc_html( $file_type ); ?></td>
5613 <td><button type="button" class="button button-small vigilante-ignore-file" data-file="<?php echo esc_attr( $file_path ); ?>"><?php esc_html_e( 'Ignore', 'vigilante' ); ?></button></td>
5614 </tr>
5615 <?php
5616 }
5617 ?>
5618 </tbody>
5619 </table>
5620 </div>
5621 <?php endif; ?>
5622
5623 <?php
5624 // Split critical config files from regular modified files.
5625 // Computed unconditionally so the three sub-sections that consume
5626 // these arrays (Critical Config, Closed + Removed, Modified Files)
5627 // can render independently and in the order the team picked.
5628 $critical_modified = array();
5629 $regular_modified = array();
5630 if ( $last_results && ! empty( $last_results['modified'] ) ) {
5631 foreach ( $last_results['modified'] as $item ) {
5632 if ( is_array( $item ) && isset( $item['type'] ) && 'critical_config' === $item['type'] ) {
5633 $critical_modified[] = $item;
5634 } else {
5635 $regular_modified[] = $item;
5636 }
5637 }
5638 }
5639 ?>
5640
5641 <?php if ( ! empty( $critical_modified ) ) : ?>
5642 <div class="vigilante-file-list vigilante-critical-config-files">
5643 <h3 style="color: #e36210;"><?php esc_html_e( 'Critical config files modified', 'vigilante' ); ?></h3>
5644 <p class="description">
5645 <?php esc_html_e( 'These files are common targets for code injection. Review the changes and approve if they are legitimate. Vigilant\'s own blocks are excluded from this check.', 'vigilante' ); ?>
5646 </p>
5647 <table class="wp-list-table widefat fixed striped">
5648 <thead>
5649 <tr>
5650 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
5651 <th style="width: 200px;"><?php esc_html_e( 'Changes', 'vigilante' ); ?></th>
5652 <th style="width: 220px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5653 </tr>
5654 </thead>
5655 <tbody>
5656 <?php foreach ( $critical_modified as $crit_item ) :
5657 $crit_file = $crit_item['file'] ?? '';
5658 $crit_baseline_size = $crit_item['baseline_size'] ?? 0;
5659 $crit_current_size = $crit_item['current_size'] ?? 0;
5660 $crit_diff = $crit_item['diff'] ?? array();
5661 $crit_id = sanitize_html_class( $crit_file );
5662 $added_count = is_array( $crit_diff ) ? count( $crit_diff['added'] ?? array() ) : 0;
5663 $removed_count = is_array( $crit_diff ) ? count( $crit_diff['removed'] ?? array() ) : 0;
5664 $diff_unavailable = is_array( $crit_diff ) && ! empty( $crit_diff['unavailable'] );
5665 ?>
5666 <tr>
5667 <td><code style="color: #e36210;"><?php echo esc_html( $crit_file ); ?></code></td>
5668 <td>
5669 <?php if ( ! $diff_unavailable ) : ?>
5670 <span style="color: #007017;">+<?php echo (int) $added_count; ?></span>
5671 <span style="color: #b32d2e;">-<?php echo (int) $removed_count; ?></span>
5672 <?php esc_html_e( 'lines', 'vigilante' ); ?><br>
5673 <?php endif; ?>
5674 <small style="color: #50575e;">
5675 <?php
5676 printf(
5677 /* translators: 1: baseline size, 2: current size */
5678 esc_html__( '%1$s &rarr; %2$s bytes', 'vigilante' ),
5679 esc_html( number_format_i18n( $crit_baseline_size ) ),
5680 esc_html( number_format_i18n( $crit_current_size ) )
5681 );
5682 ?>
5683 </small>
5684 </td>
5685 <td>
5686 <button type="button" class="button button-small vigilante-toggle-critical-content" data-target="vigilante-critical-content-<?php echo esc_attr( $crit_id ); ?>" data-label-show="<?php esc_attr_e( 'Review changes', 'vigilante' ); ?>" data-label-hide="<?php esc_attr_e( 'Hide changes', 'vigilante' ); ?>">
5687 <?php esc_html_e( 'Review changes', 'vigilante' ); ?>
5688 </button>
5689 <button type="button" class="button button-small button-primary vigilante-approve-critical-file" data-file="<?php echo esc_attr( $crit_file ); ?>">
5690 <?php esc_html_e( 'Approve', 'vigilante' ); ?>
5691 </button>
5692 </td>
5693 </tr>
5694 <tr id="vigilante-critical-content-<?php echo esc_attr( $crit_id ); ?>" class="vigilante-critical-content-row" style="display:none;">
5695 <td colspan="3" style="padding: 0;">
5696 <div class="vigilante-critical-content" style="max-height: 400px; overflow: auto; background: #fff; padding: 10px; font-size: 12px; line-height: 1.5; font-family: Consolas, Monaco, monospace; border-top: 1px solid #c3c4c7;">
5697 <?php if ( $diff_unavailable ) : ?>
5698 <p style="color: #50575e; font-style: italic; margin: 0;">
5699 <?php esc_html_e( 'Diff not available for this file (baseline was created before diff tracking was added). Approve to enable diff on future changes.', 'vigilante' ); ?>
5700 </p>
5701 <?php elseif ( empty( $crit_diff['added'] ) && empty( $crit_diff['removed'] ) ) : ?>
5702 <p style="color: #50575e; font-style: italic; margin: 0;">
5703 <?php esc_html_e( 'No line-level changes detected (may be whitespace or reordering).', 'vigilante' ); ?>
5704 </p>
5705 <?php else : ?>
5706 <?php if ( ! empty( $crit_diff['removed'] ) ) : ?>
5707 <?php foreach ( $crit_diff['removed'] as $rline ) : ?>
5708 <div style="background: #fbeaea; color: #b32d2e; padding: 1px 4px; white-space: pre-wrap; word-wrap: break-word;"><span style="display: inline-block; width: 50px; color: #999; user-select: none;"><?php echo (int) $rline['line']; ?></span>- <?php echo esc_html( $rline['content'] ); ?></div>
5709 <?php endforeach; ?>
5710 <?php endif; ?>
5711 <?php if ( ! empty( $crit_diff['added'] ) ) : ?>
5712 <?php foreach ( $crit_diff['added'] as $aline ) : ?>
5713 <div style="background: #e6f4e9; color: #007017; padding: 1px 4px; white-space: pre-wrap; word-wrap: break-word;"><span style="display: inline-block; width: 50px; color: #999; user-select: none;"><?php echo (int) $aline['line']; ?></span>+ <?php echo esc_html( $aline['content'] ); ?></div>
5714 <?php endforeach; ?>
5715 <?php endif; ?>
5716 <?php endif; ?>
5717 </div>
5718 </td>
5719 </tr>
5720 <?php endforeach; ?>
5721 </tbody>
5722 </table>
5723 </div>
5724 <?php endif; ?>
5725
5726 <?php if ( $has_closed ) : ?>
5727 <div class="vigilante-file-list vigilante-closed-plugins">
5728 <h3 style="color: #d63638;"><?php esc_html_e( 'Closed + Removed Plugins', 'vigilante' ); ?></h3>
5729 <p class="description" style="color: #d63638;">
5730 <?php esc_html_e( '&#9888; Warning: These plugins have been closed in the WordPress.org repository. Closures usually indicate malware, security issues, guideline violations, or supply chain attacks. Uninstall and replace as soon as possible.', 'vigilante' ); ?>
5731 </p>
5732 <table class="wp-list-table widefat striped">
5733 <thead>
5734 <tr>
5735 <th><?php esc_html_e( 'Plugin', 'vigilante' ); ?></th>
5736 <th style="width: 70px;"><?php esc_html_e( 'Version', 'vigilante' ); ?></th>
5737 <th style="width: 90px;"><?php esc_html_e( 'State', 'vigilante' ); ?></th>
5738 <th style="width: 110px;"><?php esc_html_e( 'Closed date', 'vigilante' ); ?></th>
5739 <th><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
5740 <th style="width: 130px;"><?php esc_html_e( 'Detected', 'vigilante' ); ?></th>
5741 <th style="width: 90px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5742 </tr>
5743 </thead>
5744 <tbody>
5745 <?php foreach ( $closed_plugins as $cp_slug => $cp_entry ) :
5746 $cp_state = $cp_entry['state'] ?? '';
5747 $cp_state_label = 'closed' === $cp_state ? __( 'Closed', 'vigilante' ) : __( 'Removed', 'vigilante' );
5748 $cp_state_color = 'closed' === $cp_state ? '#d63638' : '#b32d2e';
5749 $cp_reason = '';
5750 if ( ! empty( $cp_entry['closed_reason_text'] ) ) {
5751 $cp_reason = $cp_entry['closed_reason_text'];
5752 } elseif ( 'removed' === $cp_state ) {
5753 $cp_reason = __( 'Removed from repository (metadata hidden, typical of Security Issue closures)', 'vigilante' );
5754 }
5755 $cp_detected = isset( $cp_entry['first_detected'] ) ? (int) $cp_entry['first_detected'] : 0;
5756 ?>
5757 <tr>
5758 <td>
5759 <strong><?php echo esc_html( $cp_entry['name'] ?? $cp_slug ); ?></strong><br>
5760 <a href="<?php echo esc_url( 'https://wordpress.org/plugins/' . $cp_slug . '/' ); ?>" target="_blank" rel="noopener noreferrer"><code style="color: #50575e;"><?php echo esc_html( $cp_slug ); ?></code></a>
5761 </td>
5762 <td><?php echo esc_html( $cp_entry['version'] ?? '' ); ?></td>
5763 <td><span style="color: <?php echo esc_attr( $cp_state_color ); ?>; font-weight: 600;"><?php echo esc_html( $cp_state_label ); ?></span></td>
5764 <td><?php echo esc_html( $cp_entry['closed_date'] ?? '' ); ?></td>
5765 <td><?php echo esc_html( $cp_reason ); ?></td>
5766 <td>
5767 <?php echo $cp_detected > 0 ? esc_html( wp_date( $datetime_format, $cp_detected ) ) : '&mdash;'; ?>
5768 </td>
5769 <td>
5770 <button type="button" class="button button-small vigilante-ignore-closed-plugin" data-slug="<?php echo esc_attr( $cp_slug ); ?>">
5771 <?php esc_html_e( 'Ignore', 'vigilante' ); ?>
5772 </button>
5773 </td>
5774 </tr>
5775 <?php endforeach; ?>
5776 </tbody>
5777 </table>
5778 </div>
5779 <?php endif; ?>
5780
5781 <?php if ( ! empty( $regular_modified ) ) : ?>
5782 <div class="vigilante-file-list vigilante-paginated-section" data-bulk-mode="ignore">
5783 <h3><?php esc_html_e( 'Modified Files', 'vigilante' ); ?></h3>
5784 <p class="description"><?php esc_html_e( 'These files (apparently) differ from the original WordPress or plugin versions.', 'vigilante' ); ?></p>
5785 <div class="vigilante-fi-bulk-bar">
5786 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
5787 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
5788 </div>
5789 <div class="vigilante-fi-pagination-wrap"></div>
5790 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
5791 <thead>
5792 <tr>
5793 <td class="manage-column column-cb check-column"><input type="checkbox" class="vigilante-fi-cb-all" aria-label="<?php esc_attr_e( 'Select all', 'vigilante' ); ?>"></td>
5794 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
5795 <th style="width: 100px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
5796 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5797 </tr>
5798 </thead>
5799 <tbody>
5800 <?php
5801 foreach ( $regular_modified as $item ) {
5802 $file_path = '';
5803 $file_type = 'unknown';
5804
5805 if ( is_array( $item ) ) {
5806 if ( isset( $item['file'] ) ) {
5807 $file_path = $item['file'];
5808 }
5809 if ( isset( $item['type'] ) ) {
5810 $file_type = $item['type'];
5811 }
5812 } else {
5813 $file_path = (string) $item;
5814 }
5815 ?>
5816 <tr>
5817 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
5818 <td><code><?php echo esc_html( $file_path ); ?></code></td>
5819 <td><?php echo esc_html( $file_type ); ?></td>
5820 <td><button type="button" class="button button-small vigilante-ignore-file" data-file="<?php echo esc_attr( $file_path ); ?>"><?php esc_html_e( 'Ignore', 'vigilante' ); ?></button></td>
5821 </tr>
5822 <?php
5823 }
5824 ?>
5825 </tbody>
5826 </table>
5827 </div>
5828 <?php endif; ?>
5829
5830 <?php if ( $last_results && empty( $last_results['modified'] ) && empty( $last_results['suspicious'] ) && empty( $last_results['extra'] ) && ! $has_closed ) : ?>
5831 <p class="vigilante-all-clear" style="color: #00a32a; font-weight: bold;">
5832 <?php esc_html_e( 'Good Job! All files passed integrity check. No issues found.', 'vigilante' ); ?>
5833 </p>
5834 <?php endif; ?>
5835 <?php endif; ?>
5836 </div>
5837 </div>
5838 <?php endif; ?>
5839
5840 <?php if ( ! empty( $ignored_closed_plugins ) ) : ?>
5841 <div id="vigilante-section-fi-ignored-closed" class="vigilante-settings-section">
5842 <h2><?php esc_html_e( 'Ignored Closed + Removed Plugins', 'vigilante' ); ?></h2>
5843 <p class="description"><?php esc_html_e( 'These plugins remain closed/removed in WordPress.org but you have chosen to hide them from the main list and from email alerts. They are still installed on the site and still running their code &mdash; the silencing is purely cosmetic.', 'vigilante' ); ?></p>
5844 <table class="wp-list-table widefat fixed striped">
5845 <thead>
5846 <tr>
5847 <th><?php esc_html_e( 'Plugin', 'vigilante' ); ?></th>
5848 <th style="width: 110px;"><?php esc_html_e( 'State', 'vigilante' ); ?></th>
5849 <th style="width: 120px;"><?php esc_html_e( 'Closed date', 'vigilante' ); ?></th>
5850 <th style="width: 130px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5851 </tr>
5852 </thead>
5853 <tbody>
5854 <?php foreach ( $ignored_closed_plugins as $icp_slug => $icp_entry ) :
5855 $icp_state = $icp_entry['state'] ?? '';
5856 $icp_state_label = 'closed' === $icp_state ? __( 'Closed', 'vigilante' ) : __( 'Removed', 'vigilante' );
5857 ?>
5858 <tr>
5859 <td>
5860 <strong><?php echo esc_html( $icp_entry['name'] ?? $icp_slug ); ?></strong><br>
5861 <a href="<?php echo esc_url( 'https://wordpress.org/plugins/' . $icp_slug . '/' ); ?>" target="_blank" rel="noopener noreferrer"><code style="color: #50575e;"><?php echo esc_html( $icp_slug ); ?></code></a>
5862 </td>
5863 <td><?php echo esc_html( $icp_state_label ); ?></td>
5864 <td><?php echo esc_html( $icp_entry['closed_date'] ?? '' ); ?></td>
5865 <td>
5866 <button type="button" class="button button-small vigilante-unignore-closed-plugin" data-slug="<?php echo esc_attr( $icp_slug ); ?>">
5867 <?php esc_html_e( 'Stop ignoring', 'vigilante' ); ?>
5868 </button>
5869 </td>
5870 </tr>
5871 <?php endforeach; ?>
5872 </tbody>
5873 </table>
5874 <p style="margin-top: 10px;">
5875 <button type="button" class="button vigilante-clear-ignored-closed-plugins"><?php esc_html_e( 'Clear All Ignored Closed + Removed Plugins', 'vigilante' ); ?></button>
5876 </p>
5877 </div>
5878 <?php endif; ?>
5879
5880 <?php if ( ! empty( $ignored_files ) ) : ?>
5881 <div id="vigilante-section-fi-ignored" class="vigilante-settings-section">
5882 <h2><?php esc_html_e( 'Ignored Files', 'vigilante' ); ?></h2>
5883 <p class="description"><?php esc_html_e( 'These files are excluded from scan results and email notifications. They will still be scanned but any findings will be hidden.', 'vigilante' ); ?></p>
5884 <div class="vigilante-paginated-section" data-bulk-mode="unignore">
5885 <div class="vigilante-fi-bulk-bar">
5886 <button type="button" class="button vigilante-bulk-unignore" disabled><?php esc_html_e( 'Stop ignoring selected', 'vigilante' ); ?></button>
5887 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
5888 </div>
5889 <div class="vigilante-fi-pagination-wrap"></div>
5890 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
5891 <thead>
5892 <tr>
5893 <td class="manage-column column-cb check-column"><input type="checkbox" class="vigilante-fi-cb-all" aria-label="<?php esc_attr_e( 'Select all', 'vigilante' ); ?>"></td>
5894 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
5895 <th style="width: 120px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5896 </tr>
5897 </thead>
5898 <tbody>
5899 <?php foreach ( $ignored_files as $file ) : ?>
5900 <tr>
5901 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file ); ?>"></th>
5902 <td><code><?php echo esc_html( $file ); ?></code></td>
5903 <td><button type="button" class="button button-small vigilante-unignore-file" data-file="<?php echo esc_attr( $file ); ?>"><?php esc_html_e( 'Stop ignoring', 'vigilante' ); ?></button></td>
5904 </tr>
5905 <?php endforeach; ?>
5906 </tbody>
5907 </table>
5908 </div>
5909 <p style="margin-top: 10px;">
5910 <button type="button" class="button vigilante-clear-ignored"><?php esc_html_e( 'Clear All Ignored Files', 'vigilante' ); ?></button>
5911 </p>
5912 </div>
5913 <?php endif; ?>
5914 <?php
5915 }
5916
5917 /**
5918 * Render sidebar with promotional widgets
5919 */
5920 private function render_sidebar() {
5921 $promo_banner = new Vigilante_Promo_Banner( 'vigilante' );
5922 $promo_banner->render();
5923 }
5924
5925 /**
5926 * AJAX: Download a ZIP backup of the critical config files.
5927 *
5928 * Streams wp-config.php and .htaccess (and robots.txt if present) as a
5929 * downloadable archive. Config backups are no longer left as files under the
5930 * web root, so this hands the admin the archive directly.
5931 */
5932 public function ajax_download_files_backup() {
5933 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
5934
5935 if ( ! current_user_can( 'manage_options' ) ) {
5936 wp_die( esc_html__( 'Permission denied.', 'vigilante' ), 403 );
5937 }
5938
5939 $backup_manager = new Vigilante_Backup_Manager();
5940 $result = $backup_manager->stream_files_zip();
5941
5942 // stream_files_zip() exits on success; only a WP_Error returns here.
5943 if ( is_wp_error( $result ) ) {
5944 wp_die( esc_html( $result->get_error_message() ), 500 );
5945 }
5946 }
5947
5948 /**
5949 * AJAX: Save settings
5950 */
5951 public function ajax_save_settings() {
5952 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
5953
5954 if ( ! current_user_can( 'manage_options' ) ) {
5955 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
5956 }
5957
5958 $section = isset( $_POST['section'] ) ? sanitize_key( $_POST['section'] ) : '';
5959
5960 // Handle $_POST['data'] based on type
5961 if ( isset( $_POST['data'] ) && is_array( $_POST['data'] ) ) {
5962 $data = map_deep( wp_unslash( $_POST['data'] ), 'sanitize_text_field' );
5963 } elseif ( isset( $_POST['data'] ) ) {
5964 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
5965 $raw_data = wp_unslash( $_POST['data'] );
5966 parse_str( $raw_data, $data );
5967 $data = map_deep( $data, 'sanitize_textarea_field' );
5968 } else {
5969 $data = array();
5970 }
5971
5972 if ( empty( $section ) ) {
5973 wp_send_json_error( __( 'Invalid section.', 'vigilante' ) );
5974 }
5975
5976 // Check if 2FA is being enabled or method changed (for notification sending)
5977 $send_2fa_notification = false;
5978 $send_login_url_notification = false;
5979
5980 if ( 'login_security' === $section ) {
5981 // Read old state from DB
5982 $db_options = get_option( Vigilante_Settings::OPTION_NAME, array() );
5983 $old_2fa_enabled = ! empty( $db_options['login_security']['two_factor']['enabled'] );
5984 $old_method = $db_options['login_security']['two_factor']['method'] ?? 'email';
5985
5986 // Check new state from submitted data
5987 $new_2fa_enabled = false;
5988 $notify_on_enable = false;
5989 $new_method = isset( $data['login_security']['two_factor']['method'] )
5990 ? sanitize_key( $data['login_security']['two_factor']['method'] )
5991 : 'email';
5992
5993 if ( isset( $data['login_security']['two_factor']['enabled'] ) ) {
5994 $new_2fa_enabled = filter_var( $data['login_security']['two_factor']['enabled'], FILTER_VALIDATE_BOOLEAN );
5995 }
5996 if ( isset( $data['login_security']['two_factor']['notify_on_enable'] ) ) {
5997 $notify_on_enable = filter_var( $data['login_security']['two_factor']['notify_on_enable'], FILTER_VALIDATE_BOOLEAN );
5998 }
5999
6000 // Send notification if:
6001 // 1. 2FA is being enabled (was off, now on) OR
6002 // 2. Method changed while 2FA is enabled
6003 if ( $notify_on_enable && $new_2fa_enabled ) {
6004 if ( ! $old_2fa_enabled || ( $old_2fa_enabled && $old_method !== $new_method ) ) {
6005 $send_2fa_notification = true;
6006 }
6007 }
6008
6009 // Check if login URL changed and notification is enabled
6010 $old_login_url = $db_options['login_security']['custom_login_url'] ?? '';
6011 $new_login_url = isset( $data['login_security']['custom_login_url'] )
6012 ? sanitize_title( $data['login_security']['custom_login_url'] )
6013 : '';
6014 $notify_on_url_change = isset( $data['login_security']['notify_on_login_url_change'] )
6015 ? filter_var( $data['login_security']['notify_on_login_url_change'], FILTER_VALIDATE_BOOLEAN )
6016 : false;
6017
6018 if ( $notify_on_url_change && ! empty( $new_login_url ) && $new_login_url !== $old_login_url ) {
6019 $send_login_url_notification = true;
6020 }
6021 }
6022
6023 // Get defaults
6024 $defaults = $this->settings->get_default_options();
6025
6026 // Read ONLY saved options from database (not merged with defaults)
6027 $saved_options = get_option( Vigilante_Settings::OPTION_NAME, array() );
6028
6029 // Handle modules
6030 if ( 'modules' === $section && isset( $data['modules'] ) ) {
6031 if ( ! isset( $saved_options['modules'] ) ) {
6032 $saved_options['modules'] = array();
6033 }
6034 foreach ( $data['modules'] as $module => $enabled ) {
6035 $module = sanitize_key( $module );
6036 $saved_options['modules'][ $module ] = in_array( $enabled, array( '1', 1, 'true', true ), true );
6037 }
6038 // Clear active preset when modules change
6039 update_option( 'vigilante_active_preset', '' );
6040 } else {
6041 // Process primary section
6042 if ( isset( $data[ $section ] ) && is_array( $data[ $section ] ) ) {
6043 $section_defaults = isset( $defaults[ $section ] ) ? $defaults[ $section ] : array();
6044 $current_section = isset( $saved_options[ $section ] ) ? $saved_options[ $section ] : array();
6045
6046 // Process the submitted data
6047 $processed = $this->process_section_data( $data[ $section ], $section_defaults, $current_section );
6048
6049 // Save the processed section
6050 $saved_options[ $section ] = $processed;
6051
6052 // Clear active preset when any section settings change
6053 update_option( 'vigilante_active_preset', '' );
6054 }
6055 }
6056
6057 // Clear cache before saving
6058 wp_cache_delete( Vigilante_Settings::OPTION_NAME, 'options' );
6059
6060 // Save to database
6061 update_option( Vigilante_Settings::OPTION_NAME, $saved_options );
6062
6063 // Clear the settings cache
6064 $this->settings->clear_cache();
6065
6066 // Apply changes based on section
6067 $this->apply_section_changes( $section, $saved_options );
6068
6069 // Send 2FA notifications after settings are saved
6070 $notification_result = null;
6071 if ( $send_2fa_notification ) {
6072 $notification_result = $this->send_2fa_enable_notifications();
6073 }
6074
6075 // Send login URL notifications after settings are saved
6076 $login_url_result = null;
6077 if ( $send_login_url_notification ) {
6078 $login_url_result = $this->send_login_url_notifications();
6079 }
6080
6081 // Build success message
6082 $message = __( 'Settings saved successfully.', 'vigilante' );
6083
6084 if ( $notification_result && $notification_result['sent'] > 0 ) {
6085 $message .= ' ' . sprintf(
6086 /* translators: %d: Number of emails sent */
6087 _n(
6088 '2FA notification sent to %d user.',
6089 '2FA notifications sent to %d users.',
6090 $notification_result['sent'],
6091 'vigilante'
6092 ),
6093 $notification_result['sent']
6094 );
6095 }
6096
6097 if ( $login_url_result && $login_url_result['sent'] > 0 ) {
6098 $message .= ' ' . sprintf(
6099 /* translators: %d: Number of emails sent */
6100 _n(
6101 'Login URL notification sent to %d user.',
6102 'Login URL notifications sent to %d users.',
6103 $login_url_result['sent'],
6104 'vigilante'
6105 ),
6106 $login_url_result['sent']
6107 );
6108 }
6109
6110 wp_send_json_success( $message );
6111 }
6112
6113 /**
6114 * Send 2FA enable notifications to users
6115 *
6116 * @return array Result with 'sent' and 'failed' counts.
6117 */
6118 private function send_2fa_enable_notifications() {
6119 $result = array(
6120 'sent' => 0,
6121 'failed' => 0,
6122 );
6123
6124 // Get settings for roles and method
6125 $login_security = $this->settings->get_section( 'login_security' );
6126 $two_factor = isset( $login_security['two_factor'] ) ? $login_security['two_factor'] : array();
6127 $roles = isset( $two_factor['enforced_roles'] ) ? $two_factor['enforced_roles'] : array( 'administrator' );
6128 $method = isset( $two_factor['method'] ) ? $two_factor['method'] : 'email';
6129
6130 if ( empty( $roles ) ) {
6131 $roles = array( 'administrator' );
6132 }
6133
6134 $excluded = isset( $two_factor['excluded_users'] ) ? array_map( 'absint', $two_factor['excluded_users'] ) : array();
6135
6136 // Get users with these roles
6137 $args = array(
6138 'role__in' => $roles,
6139 );
6140 if ( ! empty( $excluded ) ) {
6141 // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- Small excluded users list from settings.
6142 $args['exclude'] = $excluded;
6143 }
6144 $users = get_users( $args );
6145
6146 if ( empty( $users ) ) {
6147 return $result;
6148 }
6149
6150 $site_name = get_bloginfo( 'name' );
6151 $from_name = ! empty( $two_factor['email_from_name'] ) ? $two_factor['email_from_name'] : $site_name;
6152
6153 if ( 'totp' === $method ) {
6154 // Use TOTP class for styled HTML emails
6155 if ( ! class_exists( 'Vigilante_Two_Factor_TOTP' ) ) {
6156 require_once VIGILANTE_INCLUDES_DIR . 'class-two-factor-totp.php';
6157 }
6158 $totp = new Vigilante_Two_Factor_TOTP( $this->settings, $this->database, $this->activity_log );
6159
6160 foreach ( $users as $user ) {
6161 // Skip users who already have TOTP configured
6162 $totp_data = $this->database->get_totp_data( $user->ID );
6163 if ( $totp_data && ! empty( $totp_data['is_configured'] ) ) {
6164 continue;
6165 }
6166
6167 $sent = $totp->send_activation_email( $user, $site_name, $from_name );
6168
6169 if ( $sent ) {
6170 $this->database->mark_2fa_notified( $user->ID );
6171 $result['sent']++;
6172 } else {
6173 $result['failed']++;
6174 }
6175 }
6176 } else {
6177 // Email method - use existing email 2FA class
6178 if ( ! class_exists( 'Vigilante_Two_Factor_Email' ) ) {
6179 require_once VIGILANTE_INCLUDES_DIR . 'class-two-factor-email.php';
6180 }
6181 $email_2fa = new Vigilante_Two_Factor_Email( $this->settings, $this->database, $this->activity_log );
6182 return $email_2fa->send_activation_notifications( false );
6183 }
6184
6185 return $result;
6186 }
6187
6188 /**
6189 * Send login URL change notifications to users with admin access
6190 *
6191 * @return array Result with 'sent' and 'failed' counts.
6192 */
6193 private function send_login_url_notifications() {
6194 $login_options = $this->settings->get_section( 'login_security' );
6195 $custom_url = ! empty( $login_options['custom_login_url'] ) ? sanitize_title( $login_options['custom_login_url'] ) : '';
6196
6197 if ( empty( $custom_url ) ) {
6198 return array( 'sent' => 0, 'failed' => 0 );
6199 }
6200
6201 $login_url = home_url( $custom_url . '/' );
6202 $site_name = get_bloginfo( 'name' );
6203
6204 $admin_roles = array( 'administrator', 'editor', 'author', 'contributor' );
6205 $users = get_users( array( 'role__in' => $admin_roles ) );
6206
6207 if ( empty( $users ) ) {
6208 return array( 'sent' => 0, 'failed' => 0 );
6209 }
6210
6211 $subject = sprintf(
6212 /* translators: %s: Site name */
6213 __( '[%s] Your login URL has changed', 'vigilante' ),
6214 $site_name
6215 );
6216
6217 $body = Vigilante_Email_Template::p( __( 'The login URL for the admin area has been changed. Please save the new URL below and use it from now on.', 'vigilante' ) );
6218 $body .= Vigilante_Email_Template::url_box( $login_url, __( 'Your new login URL:', 'vigilante' ) );
6219 $body .= Vigilante_Email_Template::alert_box( __( 'The old login address (wp-login.php) will no longer work.', 'vigilante' ) );
6220 $body .= Vigilante_Email_Template::button( $login_url, __( 'Go to login', 'vigilante' ) );
6221
6222 $sent = 0;
6223 $failed = 0;
6224
6225 foreach ( $users as $user ) {
6226 $result = Vigilante_Email_Template::send(
6227 $user->user_email,
6228 $subject,
6229 __( 'Login URL changed', 'vigilante' ),
6230 $body
6231 );
6232 if ( $result ) {
6233 $sent++;
6234 } else {
6235 $failed++;
6236 }
6237 }
6238
6239 if ( $this->activity_log ) {
6240 $this->activity_log->log(
6241 'login',
6242 'login_url_notified',
6243 sprintf(
6244 /* translators: 1: Sent count, 2: Failed count */
6245 __( 'Login URL notification sent on save: %1$d sent, %2$d failed', 'vigilante' ),
6246 $sent,
6247 $failed
6248 )
6249 );
6250 }
6251
6252 return array( 'sent' => $sent, 'failed' => $failed );
6253 }
6254
6255 /**
6256 * Process section data maintaining proper types from defaults
6257 *
6258 * @param array $submitted_data Data submitted from form.
6259 * @param array $defaults Default values for this section.
6260 * @param array $current Current saved values.
6261 * @param string $section_name Section name for special handling.
6262 * @return array Processed data.
6263 */
6264 private function process_section_data( $submitted_data, $defaults, $current, $section_name = '' ) {
6265 // Start with defaults, then merge current saved values
6266 $result = array_replace_recursive( $defaults, $current );
6267
6268 // Process each submitted value
6269 foreach ( $submitted_data as $key => $value ) {
6270 $key = sanitize_key( $key );
6271
6272 if ( is_array( $value ) ) {
6273 // Nested array (like rate_limiting)
6274 $nested_defaults = isset( $defaults[ $key ] ) && is_array( $defaults[ $key ] ) ? $defaults[ $key ] : array();
6275 $nested_current = isset( $result[ $key ] ) && is_array( $result[ $key ] ) ? $result[ $key ] : array();
6276 $result[ $key ] = $this->process_section_data( $value, $nested_defaults, $nested_current, $key );
6277 } else {
6278 // Determine type from default value
6279 $default_value = isset( $defaults[ $key ] ) ? $defaults[ $key ] : null;
6280
6281 if ( null === $default_value ) {
6282 // No default, check current value type or use as string
6283 $current_value = isset( $current[ $key ] ) ? $current[ $key ] : null;
6284 if ( is_bool( $current_value ) ) {
6285 $result[ $key ] = in_array( $value, array( '1', 1, 'true', true ), true );
6286 } elseif ( is_int( $current_value ) ) {
6287 $result[ $key ] = intval( $value );
6288 } elseif ( is_array( $current_value ) ) {
6289 $result[ $key ] = is_string( $value ) ? array_filter( array_map( 'trim', explode( "\n", $value ) ) ) : (array) $value;
6290 } else {
6291 $result[ $key ] = sanitize_text_field( $value );
6292 }
6293 } elseif ( is_bool( $default_value ) ) {
6294 // Boolean: '1', 1, 'true' become true; '0', 0, '', 'false' become false
6295 $result[ $key ] = in_array( $value, array( '1', 1, 'true', true ), true );
6296 } elseif ( is_int( $default_value ) ) {
6297 // Integer - with special handling for time fields shown in minutes
6298 $int_value = intval( $value );
6299
6300 // Convert minutes to seconds for login_security duration fields
6301 // These are displayed as minutes in the form but stored as seconds
6302 if ( in_array( $key, array( 'lockout_duration', 'max_lockout_duration' ), true ) ) {
6303 $int_value = $int_value * 60;
6304 }
6305
6306 $result[ $key ] = $int_value;
6307 } elseif ( is_array( $default_value ) ) {
6308 // Array from textarea (e.g., IP lists)
6309 if ( is_string( $value ) ) {
6310 $result[ $key ] = array_filter( array_map( 'trim', explode( "\n", $value ) ) );
6311 } else {
6312 $result[ $key ] = (array) $value;
6313 }
6314 } else {
6315 // String - preserve newlines for textarea fields
6316 if ( is_string( $value ) && ( strpos( $value, "\n" ) !== false || strpos( $value, "\r" ) !== false ) ) {
6317 $result[ $key ] = sanitize_textarea_field( $value );
6318 } else {
6319 $result[ $key ] = sanitize_text_field( $value );
6320 }
6321 }
6322 }
6323 }
6324
6325 // Handle unchecked checkboxes: HTML forms don't submit unchecked boxes
6326 // If a boolean field exists in defaults but NOT in submitted_data, set it to false
6327 //
6328 // EXCEPTION: the top-level 'enabled' flag of every section is the
6329 // module's master switch and is controlled by the Dashboard module
6330 // toggle, NOT by a checkbox inside the section's form. Treating it
6331 // like a regular checkbox here would silently switch the module off
6332 // every time the user saves the tab — see the REST API enabled=false
6333 // regression. We only skip it at the top level (when section_name is
6334 // empty); nested 'enabled' fields like security_headers.csp.enabled
6335 // are real checkboxes and must keep the auto-unset behaviour.
6336 $preserve_top_level = array( 'enabled' );
6337
6338 foreach ( $defaults as $key => $default_value ) {
6339 if ( '' === $section_name && in_array( $key, $preserve_top_level, true ) ) {
6340 continue;
6341 }
6342 if ( is_bool( $default_value ) && ! array_key_exists( $key, $submitted_data ) ) {
6343 $result[ $key ] = false;
6344 } elseif ( is_array( $default_value ) && ! isset( $submitted_data[ $key ] ) ) {
6345 // Check if this is a flat value list (like excluded_users, enforced_roles, ip_whitelist)
6346 // vs a nested settings group (like rate_limiting, two_factor)
6347 // Flat lists: default is empty array OR all values are scalar
6348 $is_value_list = empty( $default_value );
6349 if ( ! $is_value_list ) {
6350 $is_value_list = true;
6351 foreach ( $default_value as $dv ) {
6352 if ( ! is_scalar( $dv ) ) {
6353 $is_value_list = false;
6354 break;
6355 }
6356 }
6357 }
6358
6359 if ( $is_value_list ) {
6360 // All items removed - reset to empty array
6361 $result[ $key ] = array();
6362 } else {
6363 // Nested settings group - handle boolean children
6364 foreach ( $default_value as $nested_key => $nested_default ) {
6365 if ( is_bool( $nested_default ) && isset( $result[ $key ] ) && is_array( $result[ $key ] ) ) {
6366 $nested_submitted = isset( $submitted_data[ $key ] ) && is_array( $submitted_data[ $key ] )
6367 ? $submitted_data[ $key ]
6368 : array();
6369 if ( ! array_key_exists( $nested_key, $nested_submitted ) ) {
6370 $result[ $key ][ $nested_key ] = false;
6371 }
6372 }
6373 }
6374 }
6375 }
6376 }
6377
6378 return $result;
6379 }
6380
6381 /**
6382 * AJAX: Export settings
6383 */
6384 public function ajax_export_settings() {
6385 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
6386
6387 if ( ! current_user_can( 'manage_options' ) ) {
6388 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
6389 }
6390
6391 $options = $this->settings->get_all_options();
6392 $filename = 'vigilante-settings-' . gmdate( 'Y-m-d-His' ) . '.json';
6393
6394 wp_send_json_success( array(
6395 'content' => wp_json_encode( $options, JSON_PRETTY_PRINT ),
6396 'filename' => $filename,
6397 ) );
6398 }
6399
6400 /**
6401 * AJAX: Import settings
6402 */
6403 public function ajax_import_settings() {
6404 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
6405
6406 if ( ! current_user_can( 'manage_options' ) ) {
6407 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
6408 }
6409
6410 // Accept both 'settings' (from JS) and 'content' (legacy).
6411 // Do NOT run sanitize_text_field() on the raw payload: it calls
6412 // wp_strip_all_tags() internally, which removes any "<...>" substring
6413 // and turns a valid export JSON into garbage if any stored value
6414 // contains < or > (htaccess snippets, email templates, etc.). The
6415 // real sanitization happens after json_decode(), via map_deep() on
6416 // the parsed array.
6417 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash
6418 $content = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : '';
6419 if ( empty( $content ) ) {
6420 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash
6421 $content = isset( $_POST['content'] ) ? wp_unslash( $_POST['content'] ) : '';
6422 }
6423
6424 if ( empty( $content ) || ! is_string( $content ) ) {
6425 wp_send_json_error( __( 'No content provided.', 'vigilante' ) );
6426 }
6427
6428 $imported = json_decode( $content, true );
6429
6430 if ( json_last_error() !== JSON_ERROR_NONE || ! is_array( $imported ) ) {
6431 wp_send_json_error( __( 'Invalid JSON format.', 'vigilante' ) );
6432 }
6433
6434 // Sanitize imported data recursively
6435 $imported = map_deep( $imported, 'sanitize_text_field' );
6436
6437 // Validate structure
6438 $defaults = $this->settings->get_default_options();
6439 $merged = array_replace_recursive( $defaults, $imported );
6440
6441 // Save
6442 update_option( Vigilante_Settings::OPTION_NAME, $merged );
6443 $this->settings->clear_cache();
6444
6445 // Re-evaluate the active preset marker. The imported config may match
6446 // a known preset exactly, partially, or not at all — without this step
6447 // the dashboard would keep showing whatever preset was active before
6448 // the import even if the new config no longer matches it.
6449 $matched_preset = $this->detect_matching_preset( $merged );
6450 if ( null === $matched_preset ) {
6451 delete_option( 'vigilante_active_preset' );
6452 } else {
6453 update_option( 'vigilante_active_preset', $matched_preset );
6454 }
6455
6456 // Apply file changes after import
6457 $this->apply_all_file_changes( $merged );
6458
6459 // Refresh the Security Analyzer score so the dashboard widget reflects
6460 // the imported config rather than the pre-import scan. Reuse the
6461 // post-Under-Attack scan hook (same job: full scan, async).
6462 if ( ! wp_next_scheduled( 'vigilante_under_attack_post_scan' ) ) {
6463 wp_schedule_single_event( time() + 5, 'vigilante_under_attack_post_scan' );
6464 }
6465
6466 wp_send_json_success( __( 'Settings imported successfully.', 'vigilante' ) );
6467 }
6468
6469 /**
6470 * Detect whether a vigilante_options array matches a known preset.
6471 *
6472 * A preset matches when every field the preset explicitly declares is
6473 * present in the config with the same (normalised) value. Fields outside
6474 * the preset are ignored — they may have been modified by the user before
6475 * applying the preset and do not invalidate the match. This mirrors how
6476 * apply_preset() now layers presets on top of the user's existing config.
6477 *
6478 * @param array $options The current/imported vigilante_options.
6479 * @return string|null Preset id ('standard', 'maximum') or null if custom.
6480 */
6481 private function detect_matching_preset( $options ) {
6482 if ( ! is_array( $options ) ) {
6483 return null;
6484 }
6485
6486 $presets = $this->settings->get_presets();
6487
6488 foreach ( $presets as $preset_id => $preset_data ) {
6489 unset( $preset_data['name'], $preset_data['description'] );
6490 if ( $this->preset_subset_matches( $preset_data, $options ) ) {
6491 return $preset_id;
6492 }
6493 }
6494
6495 return null;
6496 }
6497
6498 /**
6499 * Check whether every leaf value inside $preset_subset exists with the
6500 * same (normalised) value at the same path inside $config.
6501 *
6502 * @param mixed $preset_subset Branch of the preset definition.
6503 * @param mixed $config Same branch in the live/imported config.
6504 * @return bool
6505 */
6506 private function preset_subset_matches( $preset_subset, $config ) {
6507 if ( is_array( $preset_subset ) ) {
6508 if ( ! is_array( $config ) ) {
6509 return false;
6510 }
6511 foreach ( $preset_subset as $key => $value ) {
6512 if ( ! array_key_exists( $key, $config ) ) {
6513 return false;
6514 }
6515 if ( ! $this->preset_subset_matches( $value, $config[ $key ] ) ) {
6516 return false;
6517 }
6518 }
6519 return true;
6520 }
6521
6522 return $this->normalise_scalar_for_compare( $preset_subset ) === $this->normalise_scalar_for_compare( $config );
6523 }
6524
6525 /**
6526 * Normalise a scalar value so that the variants WordPress and the form
6527 * layer routinely produce ('1' / 1 / true → "1"; '' / '0' / 0 / false /
6528 * null → "") compare equal. Other values become strings unchanged.
6529 *
6530 * @param mixed $value
6531 * @return string
6532 */
6533 private function normalise_scalar_for_compare( $value ) {
6534 if ( is_bool( $value ) ) {
6535 return $value ? '1' : '';
6536 }
6537 if ( null === $value ) {
6538 return '';
6539 }
6540 if ( is_int( $value ) || is_float( $value ) ) {
6541 return (string) $value;
6542 }
6543 if ( is_string( $value ) ) {
6544 if ( 'true' === $value ) {
6545 return '1';
6546 }
6547 if ( 'false' === $value ) {
6548 return '';
6549 }
6550 return $value;
6551 }
6552 // Arrays and objects shouldn't reach here (handled by recursion above),
6553 // but if they do, fall back to a stable comparable representation.
6554 return wp_json_encode( $value );
6555 }
6556
6557 /**
6558 * AJAX: Apply preset
6559 */
6560 public function ajax_apply_preset() {
6561 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
6562
6563 if ( ! current_user_can( 'manage_options' ) ) {
6564 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
6565 }
6566
6567 $preset = isset( $_POST['preset'] ) ? sanitize_key( $_POST['preset'] ) : '';
6568
6569 // Handle reset to defaults
6570 if ( 'reset' === $preset ) {
6571 $defaults = $this->settings->get_default_options();
6572 update_option( Vigilante_Settings::OPTION_NAME, $defaults );
6573 $this->settings->clear_cache();
6574
6575 // Clear active preset
6576 update_option( 'vigilante_active_preset', '' );
6577
6578 // Apply file changes after reset
6579 $this->apply_all_file_changes( $defaults );
6580
6581 wp_send_json_success( __( 'Settings reset to defaults.', 'vigilante' ) );
6582 return;
6583 }
6584
6585 $presets = $this->settings->get_presets();
6586
6587 if ( ! isset( $presets[ $preset ] ) ) {
6588 wp_send_json_error( __( 'Invalid preset.', 'vigilante' ) );
6589 }
6590
6591 $preset_options = $presets[ $preset ];
6592 unset( $preset_options['name'], $preset_options['description'] );
6593
6594 // Layer the preset on top of the user's CURRENT configuration, not on
6595 // top of defaults. This way applying a preset only changes the fields
6596 // the preset explicitly mentions; everything else stays as the user
6597 // had it. For example, applying Maximum will not flip HSTS off if the
6598 // user had it on — Maximum doesn't touch HSTS, so it's left alone.
6599 // Use "Reset to Defaults" if a clean slate is needed.
6600 $current = get_option( Vigilante_Settings::OPTION_NAME, array() );
6601 if ( ! is_array( $current ) ) {
6602 $current = array();
6603 }
6604 // Make sure all known keys exist before merging — array_replace_recursive
6605 // does not invent keys that are missing on both sides.
6606 $current = array_replace_recursive( $this->settings->get_default_options(), $current );
6607
6608 $merged = array_replace_recursive( $current, $preset_options );
6609
6610 update_option( Vigilante_Settings::OPTION_NAME, $merged );
6611 $this->settings->clear_cache();
6612
6613 // Save active preset
6614 update_option( 'vigilante_active_preset', $preset );
6615
6616 // Apply file changes after preset
6617 $this->apply_all_file_changes( $merged );
6618
6619 wp_send_json_success( __( 'Preset applied successfully.', 'vigilante' ) );
6620 }
6621
6622 /**
6623 * AJAX: Reset a specific section to defaults
6624 */
6625 public function ajax_reset_section() {
6626 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
6627
6628 if ( ! current_user_can( 'manage_options' ) ) {
6629 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
6630 }
6631
6632 $section = isset( $_POST['section'] ) ? sanitize_key( $_POST['section'] ) : '';
6633
6634 if ( empty( $section ) ) {
6635 wp_send_json_error( __( 'No section specified.', 'vigilante' ) );
6636 }
6637
6638 // Get current options and defaults
6639 $current_options = $this->settings->get_all_options();
6640 $defaults = $this->settings->get_default_options();
6641
6642 // Check if section exists in defaults
6643 if ( ! isset( $defaults[ $section ] ) ) {
6644 wp_send_json_error( __( 'Invalid section.', 'vigilante' ) );
6645 }
6646
6647 // Reset only this section to defaults
6648 $current_options[ $section ] = $defaults[ $section ];
6649
6650 // Save
6651 update_option( Vigilante_Settings::OPTION_NAME, $current_options );
6652 $this->settings->clear_cache();
6653
6654 // Apply file changes if needed
6655 $this->apply_section_changes( $section, $current_options );
6656
6657 wp_send_json_success( array(
6658 'message' => __( 'Section reset to defaults.', 'vigilante' ),
6659 'section' => $section,
6660 'reload' => true,
6661 ) );
6662 }
6663
6664 /**
6665 * AJAX: Clear lockouts
6666 */
6667 public function ajax_clear_lockouts() {
6668 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
6669
6670 if ( ! current_user_can( 'manage_options' ) ) {
6671 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
6672 }
6673
6674 $ip = isset( $_POST['ip'] ) ? sanitize_text_field( wp_unslash( $_POST['ip'] ) ) : '';
6675
6676 if ( ! empty( $ip ) ) {
6677 $this->database->clear_lockout( $ip );
6678 } else {
6679 $this->database->clear_all_lockouts();
6680 }
6681
6682 wp_send_json_success( __( 'Lockouts cleared.', 'vigilante' ) );
6683 }
6684
6685 /**
6686 * AJAX: Clear logs
6687 */
6688 public function ajax_clear_logs() {
6689 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
6690
6691 if ( ! current_user_can( 'manage_options' ) ) {
6692 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
6693 }
6694
6695 if ( $this->activity_log ) {
6696 $result = $this->activity_log->clear_all_logs();
6697 if ( $result ) {
6698 wp_send_json_success( __( 'Logs cleared.', 'vigilante' ) );
6699 } else {
6700 wp_send_json_error( __( 'Failed to clear logs.', 'vigilante' ) );
6701 }
6702 } else {
6703 wp_send_json_error( __( 'Activity log not available.', 'vigilante' ) );
6704 }
6705 }
6706
6707 /**
6708 * AJAX: Run file integrity scan.
6709 *
6710 * Triggers the file integrity scan, which now also runs the closed plugins
6711 * check at the end when the `check_closed_plugins` toggle is on. Activity
6712 * log is passed through so Security Audit entries (both file-level and
6713 * plugin-status) are recorded from this entry point.
6714 */
6715 public function ajax_run_scan() {
6716 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
6717
6718 if ( ! current_user_can( 'manage_options' ) ) {
6719 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
6720 }
6721
6722 // Clear previous results before running new scan
6723 delete_option( 'vigilante_last_integrity_results' );
6724 delete_option( 'vigilante_last_integrity_scan' );
6725
6726 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database, $this->activity_log );
6727 $results = $file_integrity->run_scan();
6728
6729 // Save new results
6730 update_option( 'vigilante_last_integrity_scan', time() );
6731 update_option( 'vigilante_last_integrity_results', $results );
6732
6733 wp_send_json_success( array(
6734 'message' => __( 'Scan completed.', 'vigilante' ),
6735 'results' => $results,
6736 'ignored_count' => count( get_option( 'vigilante_ignored_files', array() ) ),
6737 ) );
6738 }
6739
6740 /**
6741 * AJAX: Clear scan results.
6742 *
6743 * Wipes visually everything inside "Last Scan Results": file scan findings
6744 * (Suspicious / Modified / Extra / Critical Config), file hashes and the
6745 * Closed + Removed Plugins block.
6746 *
6747 * Implementation detail to keep persistence intact:
6748 * - We delete the file scan options + hashes outright.
6749 * - For plugin status we ONLY delete the last_check timestamp — the state
6750 * map and the ignore list are preserved in DB. The render gates the
6751 * plugin_status subsections on last_check > 0, so they hide after
6752 * Clear (visual reset) and reappear on the next Run Scan Now with the
6753 * state intact. This avoids degrading a 'removed' slug (404 without
6754 * metadata) back to 'not_in_repo' on the next scan, which would
6755 * silently lose the alert.
6756 *
6757 * The Ignored Files list and the Ignored Closed + Removed Plugins list
6758 * are preserved on purpose; each has its own explicit "Clear All …"
6759 * button.
6760 */
6761 public function ajax_clear_scan() {
6762 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
6763
6764 if ( ! current_user_can( 'manage_options' ) ) {
6765 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
6766 }
6767
6768 delete_option( 'vigilante_last_integrity_results' );
6769 delete_option( 'vigilante_last_integrity_scan' );
6770
6771 if ( $this->database ) {
6772 $this->database->clear_file_hashes();
6773 }
6774
6775 // Visual reset of plugin_status block without touching the state map
6776 // or the ignored list. See PHPDoc above for the rationale.
6777 delete_option( 'vigilante_plugin_status_last_check' );
6778
6779 wp_send_json_success( __( 'Scan results cleared.', 'vigilante' ) );
6780 }
6781
6782 /**
6783 * AJAX: Ignore a file from scan results
6784 */
6785 public function ajax_ignore_file() {
6786 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
6787
6788 if ( ! current_user_can( 'manage_options' ) ) {
6789 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
6790 }
6791
6792 $file = isset( $_POST['file'] ) ? sanitize_text_field( wp_unslash( $_POST['file'] ) ) : '';
6793
6794 if ( empty( $file ) ) {
6795 wp_send_json_error( __( 'No file specified.', 'vigilante' ) );
6796 }
6797
6798 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
6799 $file_integrity->ignore_file( $file );
6800
6801 // Also remove the file from stored scan results so UI updates
6802 $results = get_option( 'vigilante_last_integrity_results' );
6803 if ( $results ) {
6804 foreach ( array( 'modified', 'suspicious', 'extra' ) as $category ) {
6805 if ( ! empty( $results[ $category ] ) ) {
6806 $results[ $category ] = array_values(
6807 array_filter(
6808 $results[ $category ],
6809 function ( $item ) use ( $file ) {
6810 return ( is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item ) !== $file;
6811 }
6812 )
6813 );
6814 }
6815 }
6816 update_option( 'vigilante_last_integrity_results', $results );
6817 }
6818
6819 wp_send_json_success( __( 'File added to ignored list.', 'vigilante' ) );
6820 }
6821
6822 /**
6823 * AJAX: Stop ignoring a file
6824 */
6825 public function ajax_unignore_file() {
6826 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
6827
6828 if ( ! current_user_can( 'manage_options' ) ) {
6829 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
6830 }
6831
6832 $file = isset( $_POST['file'] ) ? sanitize_text_field( wp_unslash( $_POST['file'] ) ) : '';
6833
6834 if ( empty( $file ) ) {
6835 wp_send_json_error( __( 'No file specified.', 'vigilante' ) );
6836 }
6837
6838 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
6839 $file_integrity->unignore_file( $file );
6840
6841 wp_send_json_success( __( 'File removed from ignored list.', 'vigilante' ) );
6842 }
6843
6844 /**
6845 * AJAX: Bulk ignore multiple files at once
6846 *
6847 * Processes a single batch into ignored list and prunes them from the
6848 * stored scan results so the UI updates without a re-scan.
6849 */
6850 public function ajax_bulk_ignore_files() {
6851 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
6852
6853 if ( ! current_user_can( 'manage_options' ) ) {
6854 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
6855 }
6856
6857 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized below per-item.
6858 $raw_files = isset( $_POST['files'] ) ? wp_unslash( $_POST['files'] ) : array();
6859 if ( ! is_array( $raw_files ) ) {
6860 wp_send_json_error( __( 'Invalid request.', 'vigilante' ) );
6861 }
6862
6863 $files = array();
6864 foreach ( $raw_files as $f ) {
6865 $clean = sanitize_text_field( $f );
6866 if ( '' !== $clean ) {
6867 $files[] = $clean;
6868 }
6869 }
6870
6871 if ( empty( $files ) ) {
6872 wp_send_json_error( __( 'No files selected.', 'vigilante' ) );
6873 }
6874
6875 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
6876 $count = 0;
6877 foreach ( $files as $file ) {
6878 $file_integrity->ignore_file( $file );
6879 $count++;
6880 }
6881
6882 // Also prune the stored scan results so the UI matches the new ignore list.
6883 $results = get_option( 'vigilante_last_integrity_results' );
6884 if ( $results ) {
6885 $files_set = array_flip( $files );
6886 foreach ( array( 'modified', 'suspicious', 'extra' ) as $category ) {
6887 if ( ! empty( $results[ $category ] ) ) {
6888 $results[ $category ] = array_values(
6889 array_filter(
6890 $results[ $category ],
6891 function ( $item ) use ( $files_set ) {
6892 $path = is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item;
6893 return ! isset( $files_set[ $path ] );
6894 }
6895 )
6896 );
6897 }
6898 }
6899 update_option( 'vigilante_last_integrity_results', $results );
6900 }
6901
6902 wp_send_json_success(
6903 array(
6904 'count' => $count,
6905 'message' => sprintf(
6906 /* translators: %d: number of files added to the ignored list */
6907 _n( '%d file added to ignored list.', '%d files added to ignored list.', $count, 'vigilante' ),
6908 $count
6909 ),
6910 )
6911 );
6912 }
6913
6914 /**
6915 * AJAX: Bulk un-ignore multiple files at once
6916 */
6917 public function ajax_bulk_unignore_files() {
6918 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
6919
6920 if ( ! current_user_can( 'manage_options' ) ) {
6921 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
6922 }
6923
6924 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized below per-item.
6925 $raw_files = isset( $_POST['files'] ) ? wp_unslash( $_POST['files'] ) : array();
6926 if ( ! is_array( $raw_files ) ) {
6927 wp_send_json_error( __( 'Invalid request.', 'vigilante' ) );
6928 }
6929
6930 $files = array();
6931 foreach ( $raw_files as $f ) {
6932 $clean = sanitize_text_field( $f );
6933 if ( '' !== $clean ) {
6934 $files[] = $clean;
6935 }
6936 }
6937
6938 if ( empty( $files ) ) {
6939 wp_send_json_error( __( 'No files selected.', 'vigilante' ) );
6940 }
6941
6942 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
6943 $count = 0;
6944 foreach ( $files as $file ) {
6945 $file_integrity->unignore_file( $file );
6946 $count++;
6947 }
6948
6949 wp_send_json_success(
6950 array(
6951 'count' => $count,
6952 'message' => sprintf(
6953 /* translators: %d: number of files removed from the ignored list */
6954 _n( '%d file removed from ignored list.', '%d files removed from ignored list.', $count, 'vigilante' ),
6955 $count
6956 ),
6957 )
6958 );
6959 }
6960
6961 /**
6962 * AJAX: Clear all ignored files
6963 */
6964 public function ajax_clear_ignored() {
6965 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
6966
6967 if ( ! current_user_can( 'manage_options' ) ) {
6968 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
6969 }
6970
6971 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
6972 $file_integrity->clear_ignored_files();
6973
6974 wp_send_json_success( __( 'Ignored files list cleared.', 'vigilante' ) );
6975 }
6976
6977 /**
6978 * AJAX: Ignore a closed/removed plugin slug so it stops appearing in the
6979 * main list and email digests. The plugin keeps running on the site;
6980 * silencing is purely cosmetic and reversible.
6981 */
6982 public function ajax_ignore_closed_plugin() {
6983 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
6984
6985 if ( ! current_user_can( 'manage_options' ) ) {
6986 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
6987 }
6988
6989 $slug = isset( $_POST['slug'] ) ? sanitize_key( wp_unslash( $_POST['slug'] ) ) : '';
6990 if ( '' === $slug ) {
6991 wp_send_json_error( __( 'No slug specified.', 'vigilante' ) );
6992 }
6993
6994 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
6995 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
6996 }
6997 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
6998 $checker->ignore_slug( $slug );
6999
7000 wp_send_json_success( __( 'Plugin added to the ignored list.', 'vigilante' ) );
7001 }
7002
7003 /**
7004 * AJAX: Stop ignoring a previously-ignored closed/removed plugin slug.
7005 */
7006 public function ajax_unignore_closed_plugin() {
7007 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7008
7009 if ( ! current_user_can( 'manage_options' ) ) {
7010 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7011 }
7012
7013 $slug = isset( $_POST['slug'] ) ? sanitize_key( wp_unslash( $_POST['slug'] ) ) : '';
7014 if ( '' === $slug ) {
7015 wp_send_json_error( __( 'No slug specified.', 'vigilante' ) );
7016 }
7017
7018 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
7019 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
7020 }
7021 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
7022 $checker->unignore_slug( $slug );
7023
7024 wp_send_json_success( __( 'Plugin removed from the ignored list.', 'vigilante' ) );
7025 }
7026
7027 /**
7028 * AJAX: Clear the entire ignored-closed-plugins list.
7029 */
7030 public function ajax_clear_ignored_closed_plugins() {
7031 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7032
7033 if ( ! current_user_can( 'manage_options' ) ) {
7034 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7035 }
7036
7037 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
7038 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
7039 }
7040 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
7041 $checker->clear_ignored();
7042
7043 wp_send_json_success( __( 'Ignored closed plugins list cleared.', 'vigilante' ) );
7044 }
7045
7046 /**
7047 * AJAX: Test security headers
7048 */
7049 public function ajax_test_headers() {
7050 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7051
7052 if ( ! current_user_can( 'manage_options' ) ) {
7053 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7054 }
7055
7056 // Get security grade from settings (not from actual HTTP request)
7057 $security_headers = new Vigilante_Security_Headers( $this->settings );
7058 $results = $security_headers->get_security_grade();
7059
7060 wp_send_json_success( $results );
7061 }
7062
7063 /**
7064 * Sanitize section data (kept for compatibility)
7065 *
7066 * @param string $section Section name.
7067 * @param array $data Section data.
7068 * @return array
7069 */
7070 private function sanitize_section_data( $section, $data ) {
7071 $sanitized = array();
7072
7073 foreach ( $data as $key => $value ) {
7074 $key = sanitize_key( $key );
7075
7076 if ( is_array( $value ) ) {
7077 $sanitized[ $key ] = $this->sanitize_section_data( $key, $value );
7078 } elseif ( is_numeric( $value ) ) {
7079 $sanitized[ $key ] = intval( $value );
7080 } else {
7081 $sanitized[ $key ] = sanitize_text_field( $value );
7082 }
7083 }
7084
7085 return $sanitized;
7086 }
7087
7088 /**
7089 * Apply changes after saving settings
7090 *
7091 * @param string $section Section that was updated.
7092 * @param array $all_options All options.
7093 */
7094 private function apply_section_changes( $section, $all_options ) {
7095 // Create fresh settings instance to ensure we have the latest data
7096 $fresh_settings = new Vigilante_Settings();
7097
7098 // The shared Vigilant .htaccess block carries BOTH the firewall's
7099 // file-protection rules and the server-signature / fingerprinting rules
7100 // that are configured under Security Headers. So it must be regenerated
7101 // whenever either section (or the module toggles) changes, not only on
7102 // the firewall save — otherwise toggling "Hide server signature" or
7103 // "Remove fingerprinting headers" never reaches the .htaccess.
7104 if ( in_array( $section, array( 'firewall', 'security_headers', 'modules' ), true ) ) {
7105 $htaccess = new Vigilante_Htaccess_Protection( $fresh_settings );
7106 $sh = $fresh_settings->get_section( 'security_headers' );
7107 $needs_htaccess_block = ! empty( $all_options['modules']['firewall'] )
7108 || ! empty( $sh['hide_server_signature'] )
7109 || ! empty( $sh['remove_fingerprinting_headers'] );
7110
7111 if ( $needs_htaccess_block ) {
7112 $htaccess->apply_rules();
7113 } else {
7114 $htaccess->remove_rules();
7115 }
7116 }
7117
7118 // Regenerate the HTTP security headers (sent by PHP) for the headers section.
7119 if ( 'security_headers' === $section || 'modules' === $section ) {
7120 $security_headers = new Vigilante_Security_Headers( $fresh_settings );
7121 $headers_enabled = ! empty( $all_options['modules']['security_headers'] );
7122
7123 if ( $headers_enabled ) {
7124 $security_headers->apply_rules();
7125 } else {
7126 $security_headers->remove_rules();
7127 }
7128 }
7129
7130 // Regenerate wp-config for wp_hardening section
7131 if ( 'wp_hardening' === $section || 'modules' === $section ) {
7132 $wpconfig = new Vigilante_Wpconfig_Security( $fresh_settings );
7133 $hardening_enabled = ! empty( $all_options['modules']['wp_hardening'] );
7134
7135 if ( $hardening_enabled ) {
7136 $wpconfig->apply_security_constants();
7137 } else {
7138 $wpconfig->remove_constants();
7139 }
7140
7141 // Apply WordPress options for comments/pingbacks
7142 $hardening_options = $all_options['wp_hardening'] ?? array();
7143
7144 if ( $hardening_enabled ) {
7145 // Pingbacks
7146 if ( ! empty( $hardening_options['disable_pingbacks'] ) ) {
7147 update_option( 'default_pingback_flag', 0 );
7148 } else {
7149 // Restore default: pingbacks enabled
7150 update_option( 'default_pingback_flag', 1 );
7151 }
7152
7153 // Trackbacks and ping status
7154 // Only close if either pingbacks OR trackbacks are disabled
7155 if ( ! empty( $hardening_options['disable_pingbacks'] ) || ! empty( $hardening_options['disable_trackbacks'] ) ) {
7156 update_option( 'default_ping_status', 'closed' );
7157 } else {
7158 // Restore default: pings open
7159 update_option( 'default_ping_status', 'open' );
7160 }
7161
7162 // Comment moderation
7163 if ( ! empty( $hardening_options['require_comment_moderation'] ) ) {
7164 update_option( 'comment_moderation', 1 );
7165 } else {
7166 // Restore default: no moderation required
7167 update_option( 'comment_moderation', 0 );
7168 }
7169 }
7170 }
7171
7172 // Trim activity log entries immediately when limits change
7173 if ( 'activity_log' === $section && $this->activity_log ) {
7174 $this->activity_log->cleanup_old_logs();
7175 }
7176
7177 // Flush rewrite rules if login URL changed
7178 if ( 'login_security' === $section ) {
7179 $login_options = $all_options['login_security'] ?? array();
7180 if ( ! empty( $login_options['custom_login_url'] ) ) {
7181 delete_option( 'vigilante_login_rules_version' );
7182 }
7183 }
7184
7185 // Log the settings change with readable section name
7186 if ( $this->activity_log ) {
7187 $section_names = array(
7188 'firewall' => __( 'Firewall', 'vigilante' ),
7189 'login_security' => __( 'Login Security', 'vigilante' ),
7190 'security_headers' => __( 'Security Headers', 'vigilante' ),
7191 'rest_api_security'=> __( 'REST API Security', 'vigilante' ),
7192 'user_security' => __( 'User Security', 'vigilante' ),
7193 'wp_hardening' => __( 'WP Hardening', 'vigilante' ),
7194 'activity_log' => __( 'Security Audit', 'vigilante' ),
7195 'file_integrity' => __( 'File Integrity', 'vigilante' ),
7196 'email' => __( 'Notification Settings', 'vigilante' ),
7197 'backup' => __( 'Backup', 'vigilante' ),
7198 'advanced' => __( 'Advanced', 'vigilante' ),
7199 'modules' => __( 'Modules', 'vigilante' ),
7200 );
7201 $display_name = isset( $section_names[ $section ] ) ? $section_names[ $section ] : $section;
7202
7203 $this->activity_log->log(
7204 'settings',
7205 'settings_updated',
7206 sprintf(
7207 /* translators: %s: Section name */
7208 __( 'Settings updated: %s', 'vigilante' ),
7209 $display_name
7210 ),
7211 array( 'section' => $section ),
7212 'info'
7213 );
7214 }
7215 }
7216
7217 /**
7218 * Apply all file changes (htaccess, wp-config) based on current options
7219 *
7220 * Used after preset, import, or reset operations
7221 *
7222 * @param array $all_options All plugin options.
7223 */
7224 private function apply_all_file_changes( $all_options ) {
7225 // Refresh settings cache first
7226 $this->settings->clear_cache();
7227
7228 // Create fresh settings instance
7229 $fresh_settings = new Vigilante_Settings();
7230
7231 // Apply firewall htaccess changes
7232 $htaccess = new Vigilante_Htaccess_Protection( $fresh_settings );
7233 $firewall_enabled = ! empty( $all_options['modules']['firewall'] );
7234
7235 if ( $firewall_enabled ) {
7236 $htaccess->apply_rules();
7237 } else {
7238 $htaccess->remove_rules();
7239 }
7240
7241 // Apply security headers htaccess changes
7242 $security_headers = new Vigilante_Security_Headers( $fresh_settings );
7243 $headers_enabled = ! empty( $all_options['modules']['security_headers'] );
7244
7245 if ( $headers_enabled ) {
7246 $security_headers->apply_rules();
7247 } else {
7248 $security_headers->remove_rules();
7249 }
7250
7251 // Apply wp-config changes
7252 $wpconfig = new Vigilante_Wpconfig_Security( $fresh_settings );
7253 $hardening_enabled = ! empty( $all_options['modules']['wp_hardening'] );
7254
7255 if ( $hardening_enabled ) {
7256 $wpconfig->apply_security_constants();
7257 } else {
7258 $wpconfig->remove_constants();
7259 }
7260
7261 // Apply WordPress options for comments/pingbacks
7262 $hardening_options = $all_options['wp_hardening'] ?? array();
7263
7264 if ( $hardening_enabled ) {
7265 // Pingbacks
7266 if ( ! empty( $hardening_options['disable_pingbacks'] ) ) {
7267 update_option( 'default_pingback_flag', 0 );
7268 } else {
7269 // Restore default: pingbacks enabled
7270 update_option( 'default_pingback_flag', 1 );
7271 }
7272
7273 // Trackbacks and ping status
7274 // Only close if either pingbacks OR trackbacks are disabled
7275 if ( ! empty( $hardening_options['disable_pingbacks'] ) || ! empty( $hardening_options['disable_trackbacks'] ) ) {
7276 update_option( 'default_ping_status', 'closed' );
7277 } else {
7278 // Restore default: pings open
7279 update_option( 'default_ping_status', 'open' );
7280 }
7281
7282 // Comment moderation
7283 if ( ! empty( $hardening_options['require_comment_moderation'] ) ) {
7284 update_option( 'comment_moderation', 1 );
7285 } else {
7286 // Restore default: no moderation required
7287 update_option( 'comment_moderation', 0 );
7288 }
7289 }
7290
7291 // Log the change
7292 if ( $this->activity_log ) {
7293 $this->activity_log->log(
7294 'settings',
7295 'bulk_settings_applied',
7296 __( 'Bulk settings applied (preset/import/reset)', 'vigilante' ),
7297 array(),
7298 'info'
7299 );
7300 }
7301 }
7302 }