PluginProbe
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… / 2.11.2
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… v2.11.2
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.11.2, at admin/class-admin.php

8,046 lines 516.1 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 use Vigilante_Admin_Recovery_Ajax;
32
33 /**
34 * Settings instance
35 *
36 * @var Vigilante_Settings
37 */
38 private $settings;
39
40 /**
41 * Database instance
42 *
43 * @var Vigilante_Database
44 */
45 private $database;
46
47 /**
48 * Activity log instance
49 *
50 * @var Vigilante_Activity_Log
51 */
52 private $activity_log;
53
54 /**
55 * Current tab
56 *
57 * @var string
58 */
59 private $current_tab = 'dashboard';
60
61 /**
62 * Available tabs
63 *
64 * @var array
65 */
66 private $tabs = array();
67
68 /**
69 * Constructor
70 *
71 * @param Vigilante_Settings $settings Settings instance.
72 * @param Vigilante_Database $database Database instance.
73 * @param Vigilante_Activity_Log $activity_log Activity log instance.
74 */
75 public function __construct( $settings, $database, $activity_log ) {
76 $this->settings = $settings;
77 $this->database = $database;
78 $this->activity_log = $activity_log;
79
80 $this->setup_tabs();
81 $this->init_hooks();
82 }
83
84 /**
85 * Setup available tabs
86 */
87 private function setup_tabs() {
88 $this->tabs = array(
89 'dashboard' => __( 'Dashboard', 'vigilante' ),
90 'firewall' => __( 'Firewall', 'vigilante' ),
91 'headers' => __( 'Security Headers', 'vigilante' ),
92 'login' => __( 'Login Security', 'vigilante' ),
93 'rest-api' => __( 'REST API', 'vigilante' ),
94 'users' => __( 'User Security', 'vigilante' ),
95 'wp-hardening' => __( 'WP Hardening', 'vigilante' ),
96 'file-integrity' => __( 'File Integrity', 'vigilante' ),
97 'activity-log' => __( 'Security Audit', 'vigilante' ),
98 'tools' => __( 'Settings & Tools', 'vigilante' ),
99 );
100 }
101
102 /**
103 * Initialize hooks
104 */
105 private function init_hooks() {
106 add_action( 'admin_menu', array( $this, 'add_menu' ) );
107 add_action( 'admin_init', array( $this, 'redirect_submenu_shortcuts' ) );
108 add_action( 'admin_init', array( $this, 'register_settings' ) );
109 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
110 add_action( 'admin_notices', array( $this, 'show_admin_notices' ) );
111
112 // Highlight correct submenu based on active tab
113 add_filter( 'submenu_file', array( $this, 'highlight_submenu_tab' ) );
114
115 // Set browser tab title to show plugin name and active tab
116 add_filter( 'admin_title', array( $this, 'set_admin_page_title' ), 10, 2 );
117
118 // AJAX handlers
119 add_action( 'wp_ajax_vigilante_save_settings', array( $this, 'ajax_save_settings' ) );
120 add_action( 'wp_ajax_vigilante_apply_preset', array( $this, 'ajax_apply_preset' ) );
121 add_action( 'wp_ajax_vigilante_reset_section', array( $this, 'ajax_reset_section' ) );
122 add_action( 'wp_ajax_vigilante_clear_lockouts', array( $this, 'ajax_clear_lockouts' ) );
123 add_action( 'wp_ajax_vigilante_clear_logs', array( $this, 'ajax_clear_logs' ) );
124 add_action( 'wp_ajax_vigilante_run_scan', array( $this, 'ajax_run_scan' ) );
125 add_action( 'wp_ajax_vigilante_clear_scan', array( $this, 'ajax_clear_scan' ) );
126 add_action( 'wp_ajax_vigilante_ignore_file', array( $this, 'ajax_ignore_file' ) );
127 add_action( 'wp_ajax_vigilante_unignore_file', array( $this, 'ajax_unignore_file' ) );
128 add_action( 'wp_ajax_vigilante_bulk_ignore_files', array( $this, 'ajax_bulk_ignore_files' ) );
129 add_action( 'wp_ajax_vigilante_bulk_unignore_files', array( $this, 'ajax_bulk_unignore_files' ) );
130 add_action( 'wp_ajax_vigilante_clear_ignored', array( $this, 'ajax_clear_ignored' ) );
131 add_action( 'wp_ajax_vigilante_ignore_closed_plugin', array( $this, 'ajax_ignore_closed_plugin' ) );
132 add_action( 'wp_ajax_vigilante_unignore_closed_plugin', array( $this, 'ajax_unignore_closed_plugin' ) );
133 add_action( 'wp_ajax_vigilante_clear_ignored_closed_plugins', array( $this, 'ajax_clear_ignored_closed_plugins' ) );
134 add_action( 'wp_ajax_vigilante_approve_critical_file', array( $this, 'ajax_approve_critical_file' ) );
135 add_action( 'wp_ajax_vigilante_export_settings', array( $this, 'ajax_export_settings' ) );
136 add_action( 'wp_ajax_vigilante_import_settings', array( $this, 'ajax_import_settings' ) );
137 add_action( 'wp_ajax_vigilante_get_logs', array( $this, 'ajax_get_logs' ) );
138 add_action( 'wp_ajax_vigilante_test_headers', array( $this, 'ajax_test_headers' ) );
139 add_action( 'wp_ajax_vigilante_download_files_backup', array( $this, 'ajax_download_files_backup' ) );
140
141 // 2FA AJAX handlers
142 add_action( 'wp_ajax_vigilante_search_users_2fa', array( $this, 'ajax_search_users_2fa' ) );
143 add_action( 'wp_ajax_vigilante_send_2fa_notification', array( $this, 'ajax_send_2fa_notification' ) );
144 add_action( 'wp_ajax_vigilante_search_totp_users', array( $this, 'ajax_search_totp_users' ) );
145 add_action( 'wp_ajax_vigilante_reset_totp_users', array( $this, 'ajax_reset_totp_users' ) );
146 add_action( 'wp_ajax_vigilante_totp_get_setup', array( $this, 'ajax_totp_get_setup' ) );
147 add_action( 'wp_ajax_vigilante_notify_login_url', array( $this, 'ajax_notify_login_url' ) );
148
149 // Password Reset AJAX handlers
150 add_action( 'wp_ajax_vigilante_search_users_password_reset', array( $this, 'ajax_search_users_password_reset' ) );
151 add_action( 'wp_ajax_vigilante_force_password_reset', array( $this, 'ajax_force_password_reset' ) );
152 add_action( 'wp_ajax_vigilante_force_password_reset_all', array( $this, 'ajax_force_password_reset_all' ) );
153 add_action( 'wp_ajax_vigilante_force_password_reset_by_role', array( $this, 'ajax_force_password_reset_by_role' ) );
154
155 // User approval AJAX handlers
156 add_action( 'wp_ajax_vigilante_approve_user', array( $this, 'ajax_approve_user' ) );
157 add_action( 'wp_ajax_vigilante_reject_user', array( $this, 'ajax_reject_user' ) );
158
159 // Session management AJAX handlers
160 add_action( 'wp_ajax_vigilante_get_user_sessions', array( $this, 'ajax_get_user_sessions' ) );
161 add_action( 'wp_ajax_vigilante_revoke_session', array( $this, 'ajax_revoke_session' ) );
162 add_action( 'wp_ajax_vigilante_revoke_all_sessions', array( $this, 'ajax_revoke_all_sessions' ) );
163
164 // Under Attack mode AJAX handlers
165 add_action( 'wp_ajax_vigilante_activate_under_attack', array( $this, 'ajax_activate_under_attack' ) );
166 add_action( 'wp_ajax_vigilante_deactivate_under_attack', array( $this, 'ajax_deactivate_under_attack' ) );
167 add_action( 'wp_ajax_vigilante_under_attack_status', array( $this, 'ajax_under_attack_status' ) );
168
169 // Database backup AJAX handlers
170 add_action( 'wp_ajax_vigilante_get_db_tables', array( $this, 'ajax_get_db_tables' ) );
171 add_action( 'wp_ajax_vigilante_download_db_backup', array( $this, 'ajax_download_db_backup' ) );
172
173 // Database prefix AJAX handlers
174 add_action( 'wp_ajax_vigilante_generate_prefix', array( $this, 'ajax_generate_prefix' ) );
175 add_action( 'wp_ajax_vigilante_change_prefix', array( $this, 'ajax_change_prefix' ) );
176
177 // Firewall list management from activity log popup
178 add_action( 'wp_ajax_vigilante_add_to_firewall_list', array( $this, 'ajax_add_to_firewall_list' ) );
179 add_action( 'wp_ajax_vigilante_unblock_firewall_ip', array( $this, 'ajax_unblock_firewall_ip' ) );
180
181 // Security Analyzer AJAX handlers (v2.1.0)
182 add_action( 'wp_ajax_vigilante_analyzer_run', array( $this, 'ajax_analyzer_run' ) );
183 add_action( 'wp_ajax_vigilante_analyzer_history', array( $this, 'ajax_analyzer_history' ) );
184 add_action( 'wp_ajax_vigilante_analyzer_dismiss_notice', array( $this, 'ajax_analyzer_dismiss_notice' ) );
185 add_action( 'wp_ajax_vigilante_analyzer_save_settings', array( $this, 'ajax_analyzer_save_settings' ) );
186
187 // Security Headers settings recovery (2.10.0)
188 add_action( 'wp_ajax_vigilante_headers_recovery_restore', array( $this, 'ajax_headers_recovery_restore' ) );
189 add_action( 'wp_ajax_vigilante_headers_recovery_undo', array( $this, 'ajax_headers_recovery_undo' ) );
190 add_action( 'wp_ajax_vigilante_headers_recovery_dismiss', array( $this, 'ajax_headers_recovery_dismiss' ) );
191
192 // Shared "Send test email" handler — Notification settings, File Integrity, Audit Alerts (v2.8.0)
193 add_action( 'wp_ajax_vigilante_send_test_email', array( $this, 'ajax_send_test_email' ) );
194
195 // Run migrations on admin load
196 add_action( 'admin_init', array( $this, 'run_migrations' ) );
197 }
198
199 /**
200 * Run database migrations based on stored version
201 */
202 public function run_migrations() {
203 $db_version = get_option( 'vigilante_db_version', '0' );
204
205 // 1.2.3: Fix IP lists corrupted by sanitize_text_field stripping newlines
206 if ( version_compare( $db_version, '1.2.3', '<' ) ) {
207 $this->migrate_fix_ip_lists();
208 update_option( 'vigilante_db_version', '1.2.3' );
209 }
210
211 // 1.3.0: Add request_method column to activity log table
212 if ( version_compare( $db_version, '1.3.0', '<' ) ) {
213 $this->database->run_migrations();
214 }
215
216 // 1.9.0: Re-apply wp-config constants (performance constants removed from managed list)
217 if ( version_compare( $db_version, '1.9.0', '<' ) ) {
218 if ( $this->settings->is_module_enabled( 'wp_hardening' ) ) {
219 require_once VIGILANTE_INCLUDES_DIR . 'class-wpconfig-security.php';
220 $wpconfig = new Vigilante_Wpconfig_Security( $this->settings );
221 $wpconfig->apply_security_constants();
222 }
223 update_option( 'vigilante_db_version', '1.9.0' );
224 }
225
226 // 1.10.0: Clean up orphaned email fields (centralized notification recipients)
227 if ( version_compare( $db_version, '1.10.0', '<' ) ) {
228 $this->migrate_cleanup_email_fields();
229 update_option( 'vigilante_db_version', '1.10.0' );
230 }
231
232 // 1.11.0: Remove stale 'enabled' key from activity_log settings
233 // + Convert additional_recipients from string to array
234 if ( version_compare( $db_version, '1.11.0', '<' ) ) {
235 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
236 $changed = false;
237
238 if ( isset( $options['activity_log']['enabled'] ) ) {
239 unset( $options['activity_log']['enabled'] );
240 $changed = true;
241 }
242
243 // Convert corrupted string to array for additional_recipients
244 if ( isset( $options['email']['additional_recipients'] ) && is_string( $options['email']['additional_recipients'] ) ) {
245 $raw = trim( $options['email']['additional_recipients'] );
246 if ( ! empty( $raw ) ) {
247 $emails = array_filter( array_map( 'trim', preg_split( '/[\r\n,; ]+/', $raw ) ) );
248 $options['email']['additional_recipients'] = array_values( array_filter( $emails, 'is_email' ) );
249 } else {
250 $options['email']['additional_recipients'] = array();
251 }
252 $changed = true;
253 }
254
255 if ( $changed ) {
256 update_option( Vigilante_Settings::OPTION_NAME, $options );
257 }
258 update_option( 'vigilante_db_version', '1.11.0' );
259 }
260
261 // 1.12.1: Regenerate htaccess (WooCommerce IPN exclusion in bot blocking rule)
262 if ( version_compare( $db_version, '1.12.1', '<' ) ) {
263 if ( ! empty( $this->settings->get_section( 'firewall' )['block_bad_bots'] ) ) {
264 require_once VIGILANTE_INCLUDES_DIR . 'class-htaccess-protection.php';
265 $htaccess = new Vigilante_Htaccess_Protection( $this->settings );
266 $htaccess->apply_rules();
267 }
268 update_option( 'vigilante_db_version', '1.12.1' );
269 }
270
271 // 1.14.0: Generate critical config files baseline (wp-config.php, .htaccess)
272 if ( version_compare( $db_version, '1.14.0', '<' ) ) {
273 if ( ! class_exists( 'Vigilante_File_Integrity' ) ) {
274 require_once VIGILANTE_INCLUDES_DIR . 'class-file-integrity.php';
275 }
276 $fi = new Vigilante_File_Integrity( $this->settings, $this->database, $this->activity_log );
277 $fi->regenerate_all_baselines();
278 update_option( 'vigilante_db_version', '1.14.0' );
279 }
280
281 // 2.0.0: Move hide_server_signature and remove_fingerprinting_headers
282 // from firewall section to security_headers section
283 if ( version_compare( $db_version, '2.0.0', '<' ) ) {
284 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
285 $changed = false;
286
287 foreach ( array( 'hide_server_signature', 'remove_fingerprinting_headers' ) as $key ) {
288 if ( isset( $options['firewall'][ $key ] ) ) {
289 if ( ! isset( $options['security_headers'][ $key ] ) ) {
290 $options['security_headers'][ $key ] = $options['firewall'][ $key ];
291 }
292 unset( $options['firewall'][ $key ] );
293 $changed = true;
294 }
295 }
296
297 if ( $changed ) {
298 update_option( Vigilante_Settings::OPTION_NAME, $options );
299 }
300 update_option( 'vigilante_db_version', '2.0.0' );
301 }
302
303 // 2.6.1: Two things happen here.
304 //
305 // 1. Re-apply wp-config constants so the block is rewritten with
306 // "if ( ! defined() )" guards around every define(). Without guards,
307 // non-standard setups that pre-define WordPress constants outside
308 // wp-config.php (custom bootstraps that load constants from .env or
309 // similar) hit a fatal "Constant already defined" when wp-config.php
310 // is parsed and reaches our block.
311 //
312 // 2. Drop the cached Security Check report. The cached "max" per
313 // category was frozen at scan time; with the internal category
314 // bumping from 22 to 28 points (closed_plugins added in 2.6.0),
315 // the cached report would keep displaying 22/22 until the next
316 // full scan. Clearing it forces a fresh scan with the new caps.
317 if ( version_compare( $db_version, '2.6.1', '<' ) ) {
318 if ( $this->settings->is_module_enabled( 'wp_hardening' ) ) {
319 require_once VIGILANTE_INCLUDES_DIR . 'class-wpconfig-security.php';
320 $wpconfig = new Vigilante_Wpconfig_Security( $this->settings );
321 $wpconfig->apply_security_constants();
322 }
323 delete_option( 'vigilante_analyzer_last_scan' );
324
325 // Schedule an immediate background scan so the dashboard widget
326 // doesn't display "Last scan: never" right after the upgrade.
327 // Reuses the same hook the post-Under-Attack flow uses.
328 if ( ! wp_next_scheduled( 'vigilante_under_attack_post_scan' ) ) {
329 wp_schedule_single_event( time() + 5, 'vigilante_under_attack_post_scan' );
330 }
331
332 update_option( 'vigilante_db_version', '2.6.1' );
333 }
334
335 // 2.9.3: Regenerate the .htaccess protection block. The bad-bots
336 // User-Agent list dropped substring-prone tokens that 403'd
337 // legitimate clients (e.g. "rma" matched inside "Performance" and
338 // blocked WP Rocket's page fetch), and the blocking rules now honour
339 // the firewall IP / User-Agent whitelists as negated exceptions.
340 // Existing sites only rewrite the block when Server Protection is
341 // saved, so the upgrade has to refresh it once itself (same pattern
342 // as the 1.12.1 WooCommerce IPN migration).
343 if ( version_compare( $db_version, '2.9.3', '<' ) ) {
344 require_once VIGILANTE_INCLUDES_DIR . 'class-htaccess-protection.php';
345 $htaccess = new Vigilante_Htaccess_Protection( $this->settings );
346
347 if ( $htaccess->are_rules_active() ) {
348 $htaccess->apply_rules();
349 }
350
351 update_option( 'vigilante_db_version', '2.9.3' );
352 }
353
354 /*
355 * 2.9.8: the mixed content handling changes shape. "Upgrade Insecure
356 * Requests" becomes a setting of its own, and Fix Mixed Content ships
357 * off, where before it shipped on and carried the directive with it.
358 * Both have to be written down for sites that are updating, so their
359 * pages keep loading exactly what they loaded yesterday.
360 *
361 * Read the RAW stored options, not get_section(): that one merges the
362 * defaults, so a site that never stored the key would be read with the
363 * new default and silently lose the behaviour it had. Absent means the
364 * site was running on the old default, which was on.
365 */
366 if ( version_compare( $db_version, '2.9.8', '<' ) ) {
367 $raw = get_option( Vigilante_Settings::OPTION_NAME, array() );
368 $stored = ( is_array( $raw ) && isset( $raw['security_headers'] ) && is_array( $raw['security_headers'] ) ) ? $raw['security_headers'] : array();
369 $had_fix = array_key_exists( 'fix_mixed_content', $stored ) ? ! empty( $stored['fix_mixed_content'] ) : true;
370
371 /*
372 * Merge, never replace. update_section() overwrites the whole
373 * section, so passing just these two keys wiped every other header
374 * setting the site had stored (HSTS, CSP, cross-origin policies,
375 * the HTTPS switches, Server Identity) and left the screen showing
376 * factory defaults while the .htaccess kept serving the old values.
377 */
378 $this->settings->update_section(
379 'security_headers',
380 array_merge(
381 $stored,
382 array(
383 'fix_mixed_content' => $had_fix,
384 'upgrade_insecure_requests' => $had_fix,
385 )
386 )
387 );
388
389 update_option( 'vigilante_db_version', '2.9.8' );
390 }
391
392 /*
393 * 2.9.9: drop the settings that no code has read for versions.
394 *
395 * They were carried in the defaults and therefore written into every
396 * saved configuration, they show up in an exported configuration, and
397 * anyone reading them assumes a feature exists behind them. Removing
398 * them from the defaults is not enough: the stored copies survive, so
399 * they are swept here too. Nothing reads them, so nothing changes.
400 */
401 if ( version_compare( $db_version, '2.9.9', '<' ) ) {
402 $raw = get_option( Vigilante_Settings::OPTION_NAME, array() );
403 $dead = array(
404 'firewall' => array( 'country_blocking', 'protected_file_extensions' ),
405 'file_integrity' => array( 'suspicious_patterns' ),
406 'backup' => array( 'auto_backup', 'backup_before_update' ),
407 'advanced' => array( 'block_author_archives', 'disable_embeds', 'uninstall_cleanup', 'debug_mode' ),
408 );
409
410 $changed = false;
411 foreach ( $dead as $section => $keys ) {
412 if ( ! isset( $raw[ $section ] ) || ! is_array( $raw[ $section ] ) ) {
413 continue;
414 }
415 foreach ( $keys as $key ) {
416 if ( array_key_exists( $key, $raw[ $section ] ) ) {
417 unset( $raw[ $section ][ $key ] );
418 $changed = true;
419 }
420 }
421 }
422
423 if ( $changed ) {
424 update_option( Vigilante_Settings::OPTION_NAME, $raw );
425 }
426
427 update_option( 'vigilante_db_version', '2.9.9' );
428 }
429
430 /*
431 * 2.11.0: security release (audit of 28 Aug 2026). Runs here and not
432 * from Vigilante_Database::needs_update(): this option is shared with
433 * that class, and on any updated site it already holds a plugin version
434 * (2.9.9 or later), so a bump of DB_VERSION would never fire.
435 * create_tables() widens the email code column through dbDelta (varchar
436 * 6 to 64, the code is stored hashed since 2.11.0) and purge_for_2_11_0()
437 * does what dbDelta cannot: it empties the trusted devices, which were
438 * identified by User-Agent until now (S1), and the pending email codes,
439 * stored in clear until now (S11). Every remembered device asks for the
440 * second factor once more after this update, and the changelog says so.
441 */
442 if ( version_compare( $db_version, '2.11.0', '<' ) ) {
443 $this->database->create_tables();
444 $this->database->purge_for_2_11_0();
445
446 update_option( 'vigilante_db_version', '2.11.0' );
447 }
448 }
449
450 /**
451 * Migration: Remove orphaned email fields from saved options
452 *
453 * v1.10.0 centralized notification recipients into email section.
454 * Old per-module notify_email fields and dead email section fields
455 * are removed to avoid confusion.
456 */
457 private function migrate_cleanup_email_fields() {
458 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
459 $modified = false;
460
461 // Remove orphaned fields from email section
462 $dead_email_keys = array( 'enabled', 'from_name', 'from_email', 'admin_email', 'send_activation_email', 'custom_email' );
463 if ( isset( $options['email'] ) && is_array( $options['email'] ) ) {
464 foreach ( $dead_email_keys as $key ) {
465 if ( array_key_exists( $key, $options['email'] ) ) {
466 unset( $options['email'][ $key ] );
467 $modified = true;
468 }
469 }
470 // Ensure new fields exist with defaults
471 if ( ! array_key_exists( 'send_to_admin_email', $options['email'] ) ) {
472 $options['email']['send_to_admin_email'] = true;
473 $modified = true;
474 }
475 if ( ! array_key_exists( 'additional_recipients', $options['email'] ) ) {
476 $options['email']['additional_recipients'] = '';
477 $modified = true;
478 }
479 }
480
481 // Remove notify_email from login_security
482 if ( isset( $options['login_security']['notify_email'] ) ) {
483 unset( $options['login_security']['notify_email'] );
484 $modified = true;
485 }
486
487 // Remove notify_email from file_integrity
488 if ( isset( $options['file_integrity']['notify_email'] ) ) {
489 unset( $options['file_integrity']['notify_email'] );
490 $modified = true;
491 }
492
493 if ( $modified ) {
494 update_option( Vigilante_Settings::OPTION_NAME, $options );
495 // Clear settings cache so the plugin uses clean data immediately
496 $this->settings->clear_cache();
497 }
498 }
499
500 /**
501 * Migration: Fix IP whitelist/blacklist entries merged into single line
502 *
503 * Prior to 1.2.3, sanitize_text_field() stripped newlines from textarea data,
504 * causing multiple IPs to be stored as a single space-separated string.
505 */
506 private function migrate_fix_ip_lists() {
507 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
508 $fixed = false;
509
510 foreach ( array( 'ip_whitelist', 'ip_blacklist' ) as $key ) {
511 if ( ! empty( $options['firewall'][ $key ] ) && is_array( $options['firewall'][ $key ] ) ) {
512 $new_list = array();
513 foreach ( $options['firewall'][ $key ] as $entry ) {
514 // Split entries that were joined by spaces
515 $parts = preg_split( '/\s+/', trim( $entry ) );
516 foreach ( $parts as $part ) {
517 $part = trim( $part );
518 if ( '' !== $part ) {
519 $new_list[] = $part;
520 }
521 }
522 }
523 if ( count( $new_list ) !== count( $options['firewall'][ $key ] ) ) {
524 $options['firewall'][ $key ] = array_unique( $new_list );
525 $fixed = true;
526 }
527 }
528 }
529
530 if ( $fixed ) {
531 update_option( Vigilante_Settings::OPTION_NAME, $options );
532 // Clear settings cache so changes take effect immediately
533 $this->settings->clear_cache();
534 }
535 }
536
537 /**
538 * Add admin menu page in last position
539 */
540 public function add_menu() {
541 $menu_title = __( 'Vigilant', 'vigilante' );
542
543 // Count pending approvals (separate concern, always red if present)
544 $pending_count = $this->get_pending_approvals_count();
545
546 // Get security issues with severity
547 $security_status = $this->get_security_status_for_badge();
548
549 // Total count for badge
550 $total_badge = $pending_count + $security_status['count'];
551
552 if ( $total_badge > 0 ) {
553 // Determine badge color:
554 // - Red (awaiting-mod): pending approvals OR critical modules disabled
555 // - Orange (update-plugins): only non-critical modules disabled
556 if ( $pending_count > 0 || $security_status['has_critical'] ) {
557 $badge_class = 'awaiting-mod';
558 } else {
559 $badge_class = 'update-plugins vigilante-badge-warning';
560 }
561
562 $menu_title .= sprintf(
563 ' <span class="%s count-%d"><span class="pending-count">%d</span></span>',
564 esc_attr( $badge_class ),
565 $total_badge,
566 $total_badge
567 );
568 }
569
570 add_menu_page(
571 __( 'Vigilant', 'vigilante' ),
572 $menu_title,
573 'manage_options',
574 'vigilante',
575 array( $this, 'render_settings_page' ),
576 'dashicons-shield',
577 999
578 );
579
580 // Rename auto-generated first submenu to "Dashboard"
581 add_submenu_page(
582 'vigilante',
583 __( 'Dashboard', 'vigilante' ),
584 __( 'Dashboard', 'vigilante' ),
585 'manage_options',
586 'vigilante',
587 array( $this, 'render_settings_page' )
588 );
589
590 // Security Audit shortcut
591 add_submenu_page(
592 'vigilante',
593 __( 'Security Audit', 'vigilante' ),
594 __( 'Security Audit', 'vigilante' ),
595 'manage_options',
596 'vigilante-activity-log',
597 array( $this, 'redirect_to_tab' )
598 );
599
600 // File Integrity shortcut
601 add_submenu_page(
602 'vigilante',
603 __( 'File Integrity', 'vigilante' ),
604 __( 'File Integrity', 'vigilante' ),
605 'manage_options',
606 'vigilante-file-integrity',
607 array( $this, 'redirect_to_tab' )
608 );
609 }
610
611 /**
612 * Redirect submenu shortcuts early, before headers are sent
613 */
614 public function redirect_submenu_shortcuts() {
615 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Just reading page slug for redirect
616 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
617
618 $tab_map = array(
619 'vigilante-activity-log' => 'activity-log',
620 'vigilante-file-integrity' => 'file-integrity',
621 );
622
623 if ( isset( $tab_map[ $page ] ) ) {
624 wp_safe_redirect( admin_url( 'admin.php?page=vigilante&tab=' . $tab_map[ $page ] ) );
625 exit;
626 }
627 }
628
629 /**
630 * Fallback redirect for submenu shortcuts (JS-based)
631 */
632 public function redirect_to_tab() {
633 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Just reading page slug for redirect
634 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
635
636 $tab_map = array(
637 'vigilante-activity-log' => 'activity-log',
638 'vigilante-file-integrity' => 'file-integrity',
639 );
640
641 if ( isset( $tab_map[ $page ] ) ) {
642 $url = admin_url( 'admin.php?page=vigilante&tab=' . $tab_map[ $page ] );
643 echo '<script>window.location.replace(' . wp_json_encode( esc_url( $url ) ) . ');</script>';
644 }
645 }
646
647 /**
648 * Highlight the correct submenu item based on active tab
649 *
650 * @param string $submenu_file Current submenu file.
651 * @return string
652 */
653 public function highlight_submenu_tab( $submenu_file ) {
654 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading tab for menu highlight only
655 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
656 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
657 $tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : '';
658
659 if ( 'vigilante' !== $page || empty( $tab ) ) {
660 return $submenu_file;
661 }
662
663 $tab_to_submenu = array(
664 'activity-log' => 'vigilante-activity-log',
665 'file-integrity' => 'vigilante-file-integrity',
666 );
667
668 if ( isset( $tab_to_submenu[ $tab ] ) ) {
669 return $tab_to_submenu[ $tab ];
670 }
671
672 return $submenu_file;
673 }
674
675 /**
676 * Set browser tab title to show plugin name and active tab
677 *
678 * Changes "Dashboard ‹ Site Name — WordPress" to
679 * "Vigilant > Dashboard ‹ Site Name — WordPress"
680 *
681 * @param string $admin_title Full admin title.
682 * @param string $title Page title from add_menu_page/add_submenu_page.
683 * @return string Modified title.
684 */
685 public function set_admin_page_title( $admin_title, $title ) {
686 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading page slug for title only
687 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
688
689 // Only modify on Vigilante pages
690 if ( 0 !== strpos( $page, 'vigilante' ) ) {
691 return $admin_title;
692 }
693
694 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
695 $tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'dashboard';
696
697 if ( isset( $this->tabs[ $tab ] ) ) {
698 $tab_label = $this->tabs[ $tab ];
699 } else {
700 $tab_label = __( 'Dashboard', 'vigilante' );
701 }
702
703 $plugin_title = __( 'Vigilant', 'vigilante' ) . ' &rsaquo; ' . $tab_label;
704
705 // Replace the original page title portion
706 return str_replace( $title, $plugin_title, $admin_title );
707 }
708
709 /**
710 * Get count of users pending approval
711 *
712 * @return int Count of pending users.
713 */
714 private function get_pending_approvals_count() {
715 // Prevent early execution before WordPress is ready
716 if ( ! did_action( 'plugins_loaded' ) ) {
717 return 0;
718 }
719
720 $registration_approval = $this->settings->get_section( 'user_security' );
721 $approval_settings = $registration_approval['registration_approval'] ?? array();
722
723 if ( empty( $approval_settings['enabled'] ) ) {
724 return 0;
725 }
726
727 // phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_key, WordPress.DB.SlowDBQuery.slow_db_query_meta_value -- Limited results in admin context.
728 $pending_users = get_users( array(
729 'meta_key' => 'vigilante_pending_approval',
730 'meta_value' => '1',
731 'fields' => 'ID',
732 ) );
733 // phpcs:enable WordPress.DB.SlowDBQuery.slow_db_query_meta_key, WordPress.DB.SlowDBQuery.slow_db_query_meta_value
734
735 return count( $pending_users );
736 }
737
738 /**
739 * Calculate comprehensive security score (0-100)
740 *
741 * @param array $options Plugin options.
742 * @return int Security score.
743 */
744 private function calculate_security_score( $options ) {
745 $score = 0;
746 $max_score = 0;
747
748 // Module scores (60 points total)
749 $module_weights = array(
750 'firewall' => 10,
751 'security_headers' => 8,
752 'login_security' => 10,
753 'rest_api_security' => 6,
754 'user_security' => 8,
755 'wp_hardening' => 8,
756 'file_integrity' => 5,
757 'activity_log' => 5,
758 );
759
760 foreach ( $module_weights as $module => $weight ) {
761 $max_score += $weight;
762 if ( ! empty( $options['modules'][ $module ] ) ) {
763 $score += $weight;
764 }
765 }
766
767 // Firewall details (10 points)
768 if ( ! empty( $options['modules']['firewall'] ) ) {
769 $firewall = $options['firewall'] ?? array();
770 $max_score += 10;
771
772 $firewall_checks = array(
773 'block_sql_injection',
774 'block_xss_attacks',
775 'block_bad_query_strings',
776 'block_file_inclusion',
777 'block_directory_traversal',
778 );
779
780 $firewall_enabled = 0;
781 foreach ( $firewall_checks as $check ) {
782 if ( ! empty( $firewall[ $check ] ) ) {
783 $firewall_enabled++;
784 }
785 }
786 $score += min( 10, $firewall_enabled * 2 );
787 }
788
789 // Login security details (10 points)
790 if ( ! empty( $options['modules']['login_security'] ) ) {
791 $login = $options['login_security'] ?? array();
792 $max_score += 10;
793
794 // Max attempts configured
795 if ( isset( $login['max_attempts'] ) && $login['max_attempts'] <= 5 ) {
796 $score += 3;
797 }
798 // XML-RPC disabled
799 if ( ! empty( $login['disable_xmlrpc'] ) ) {
800 $score += 3;
801 }
802 // 2FA enabled
803 if ( ! empty( $login['two_factor']['enabled'] ) ) {
804 $score += 4;
805 }
806 }
807
808 // Security headers details (10 points)
809 if ( ! empty( $options['modules']['security_headers'] ) ) {
810 $headers = $options['security_headers'] ?? array();
811 $max_score += 10;
812
813 if ( ! empty( $headers['x_frame_options'] ) ) {
814 $score += 2;
815 }
816 if ( ! empty( $headers['x_content_type_options'] ) ) {
817 $score += 2;
818 }
819 if ( ! empty( $headers['hsts']['enabled'] ) ) {
820 $score += 3;
821 }
822 if ( ! empty( $headers['csp']['enabled'] ) ) {
823 $score += 3;
824 }
825 }
826
827 // User security details (10 points)
828 if ( ! empty( $options['modules']['user_security'] ) ) {
829 $user = $options['user_security'] ?? array();
830 $max_score += 10;
831
832 if ( ! empty( $user['block_insecure_usernames'] ) ) {
833 $score += 3;
834 }
835 if ( ! empty( $user['force_strong_passwords'] ) ) {
836 $score += 3;
837 }
838 if ( ! empty( $user['password_expiration']['enabled'] ) ) {
839 $score += 2;
840 }
841 if ( ! empty( $user['email_verification']['enabled'] ) ) {
842 $score += 2;
843 }
844 }
845
846 // Audit alerts details (6 points) - only when Security Audit is on,
847 // because the alerting layer rides on top of the activity log. Leaving
848 // both alert legs off keeps these points unearned.
849 if ( ! empty( $options['modules']['activity_log'] ) ) {
850 $alerts = isset( $options['audit_alerts'] ) ? (array) $options['audit_alerts'] : array();
851 $max_score += 6;
852 if ( Vigilante_Audit_Alerts::immediate_is_active( $alerts ) ) {
853 $score += 3;
854 }
855 if ( Vigilante_Audit_Alerts::threshold_is_active( $alerts ) ) {
856 $score += 3;
857 }
858 }
859
860 // Environment checks (8 points) - penalize insecure server configuration
861 $max_score += 8;
862 $env_score = 8;
863
864 // WP_DEBUG active in production is a security risk (exposes paths, errors)
865 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
866 $env_score -= 5;
867 }
868
869 // Accounts with insecure usernames (targeted by brute force attacks)
870 $insecure_admins = $this->get_insecure_admin_usernames();
871 if ( ! empty( $insecure_admins ) ) {
872 $env_score -= 3;
873 }
874
875 $score += max( 0, $env_score );
876
877 return $max_score > 0 ? round( ( $score / $max_score ) * 100 ) : 0;
878 }
879
880 /**
881 * Get security recommendations based on current settings
882 *
883 * @param array $options Plugin options.
884 * @return array Array of recommendations.
885 */
886 private function get_security_recommendations( $options ) {
887 $recommendations = array();
888
889 // Critical: Firewall disabled
890 if ( empty( $options['modules']['firewall'] ) ) {
891 $recommendations[] = array(
892 'icon' => 'warning',
893 'priority' => 'critical',
894 'message' => __( 'Enable Firewall to protect against common attacks.', 'vigilante' ),
895 );
896 }
897
898 // Critical: Login security disabled
899 if ( empty( $options['modules']['login_security'] ) ) {
900 $recommendations[] = array(
901 'icon' => 'warning',
902 'priority' => 'critical',
903 'message' => __( 'Enable Login Security to prevent brute force attacks.', 'vigilante' ),
904 );
905 }
906
907 // High: Security headers disabled
908 if ( empty( $options['modules']['security_headers'] ) ) {
909 $recommendations[] = array(
910 'icon' => 'admin-generic',
911 'priority' => 'high',
912 'message' => __( 'Enable Security Headers to protect against clickjacking and XSS.', 'vigilante' ),
913 );
914 }
915
916 // High: User security disabled
917 if ( empty( $options['modules']['user_security'] ) ) {
918 $recommendations[] = array(
919 'icon' => 'admin-users',
920 'priority' => 'high',
921 'message' => __( 'Enable User Security to enforce password policies and username protection.', 'vigilante' ),
922 );
923 }
924
925 // High: 2FA not enabled (only if login security is active)
926 $login = $options['login_security'] ?? array();
927 if ( ! empty( $options['modules']['login_security'] ) && empty( $login['two_factor']['enabled'] ) ) {
928 $recommendations[] = array(
929 'icon' => 'shield',
930 'priority' => 'high',
931 'message' => __( 'Enable Two-Factor Authentication for enhanced login security.', 'vigilante' ),
932 'tab' => 'login',
933 );
934 }
935
936 // Medium: REST API security disabled
937 if ( empty( $options['modules']['rest_api_security'] ) ) {
938 $recommendations[] = array(
939 'icon' => 'rest-api',
940 'priority' => 'medium',
941 'message' => __( 'Enable REST API Security to control API access and prevent enumeration.', 'vigilante' ),
942 );
943 }
944
945 // Medium: WP Hardening disabled
946 if ( empty( $options['modules']['wp_hardening'] ) ) {
947 $recommendations[] = array(
948 'icon' => 'lock',
949 'priority' => 'medium',
950 'message' => __( 'Enable WP Hardening to remove version info and protect core files.', 'vigilante' ),
951 );
952 }
953
954 // Medium: File integrity disabled
955 if ( empty( $options['modules']['file_integrity'] ) ) {
956 $recommendations[] = array(
957 'icon' => 'media-text',
958 'priority' => 'medium',
959 'message' => __( 'Enable File Integrity to detect unauthorized file changes.', 'vigilante' ),
960 );
961 }
962
963 // Medium: Security Audit disabled
964 if ( empty( $options['modules']['activity_log'] ) ) {
965 $recommendations[] = array(
966 'icon' => 'list-view',
967 'priority' => 'medium',
968 'message' => __( 'Enable Security Audit to track security events.', 'vigilante' ),
969 );
970 }
971
972 // Low: XML-RPC enabled (only if login security is active)
973 if ( ! empty( $options['modules']['login_security'] ) && empty( $login['disable_xmlrpc'] ) ) {
974 $recommendations[] = array(
975 'icon' => 'info',
976 'priority' => 'low',
977 'message' => __( 'Disable XML-RPC if not needed (reduces attack surface).', 'vigilante' ),
978 'tab' => 'login',
979 );
980 }
981
982 // Low: Strong passwords not enforced (only if user security is active)
983 $user = $options['user_security'] ?? array();
984 if ( ! empty( $options['modules']['user_security'] ) && empty( $user['force_strong_passwords'] ) ) {
985 $recommendations[] = array(
986 'icon' => 'admin-users',
987 'priority' => 'low',
988 'message' => __( 'Enforce strong passwords for all users.', 'vigilante' ),
989 'tab' => 'users',
990 );
991 }
992
993 // High: WP_DEBUG active in production (regardless of Vigilante settings)
994 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
995 $recommendations[] = array(
996 'icon' => 'warning',
997 'priority' => 'high',
998 'message' => __( 'WP_DEBUG is active. Debug mode exposes sensitive information and should be disabled in production.', 'vigilante' ),
999 'tab' => 'wp-hardening',
1000 );
1001 }
1002
1003 // Low: Users with display name matching login username (only if user security active)
1004 if ( ! empty( $options['modules']['user_security'] ) ) {
1005 $exposed_users = $this->get_users_with_exposed_login();
1006 if ( ! empty( $exposed_users ) ) {
1007 $recommendations[] = array(
1008 'icon' => 'admin-users',
1009 'priority' => 'low',
1010 'message' => sprintf(
1011 /* translators: %s: Comma-separated list of usernames */
1012 __( 'These users have their login username as display name (publicly visible): %s', 'vigilante' ),
1013 implode( ', ', $exposed_users )
1014 ),
1015 'tab' => 'users',
1016 );
1017 }
1018 }
1019
1020 // High: Accounts with insecure usernames (regardless of module status)
1021 $insecure_admins = $this->get_insecure_admin_usernames();
1022 if ( ! empty( $insecure_admins ) ) {
1023 $recommendations[] = array(
1024 'icon' => 'warning',
1025 'priority' => 'high',
1026 'message' => sprintf(
1027 /* translators: %s: Comma-separated list of usernames */
1028 __( 'Insecure usernames detected: %s. These are commonly targeted in brute force attacks. Create new accounts with unique usernames and remove these.', 'vigilante' ),
1029 implode( ', ', $insecure_admins )
1030 ),
1031 );
1032 }
1033
1034 // Critical: Closed or removed plugins detected by the daily check.
1035 // Reads from the cached state map populated by Vigilante_Plugin_Status, so
1036 // there is no extra HTTP call here. Ignored slugs are filtered out so the
1037 // recommendation respects the user's per-slug Ignore decisions.
1038 if ( ! empty( $options['modules']['file_integrity'] ) && ! empty( $options['file_integrity']['check_closed_plugins'] ) ) {
1039 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
1040 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
1041 }
1042 $closed_checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
1043 $closed_active = $closed_checker->get_closed_plugins();
1044 if ( ! empty( $closed_active ) ) {
1045 $names = array();
1046 foreach ( $closed_active as $slug => $entry ) {
1047 $names[] = isset( $entry['name'] ) ? $entry['name'] : $slug;
1048 }
1049 $recommendations[] = array(
1050 'icon' => 'warning',
1051 'priority' => 'critical',
1052 'message' => sprintf(
1053 /* translators: 1: count, 2: comma-separated plugin names */
1054 _n(
1055 '%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.',
1056 '%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.',
1057 count( $closed_active ),
1058 'vigilante'
1059 ),
1060 count( $closed_active ),
1061 implode( ', ', $names )
1062 ),
1063 'tab' => 'file-integrity',
1064 );
1065 }
1066 }
1067
1068 // Medium: Security Audit is on but no audit alert is configured. The
1069 // alerting layer only makes sense while the activity log is running.
1070 if ( ! empty( $options['modules']['activity_log'] ) ) {
1071 $alerts = isset( $options['audit_alerts'] ) ? (array) $options['audit_alerts'] : array();
1072 if ( ! Vigilante_Audit_Alerts::has_active_alerts( $alerts ) ) {
1073 $recommendations[] = array(
1074 'icon' => 'email-alt',
1075 'priority' => 'medium',
1076 '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' ),
1077 'tab' => 'activity-log',
1078 );
1079 }
1080 }
1081
1082 // Sort by priority
1083 $priority_order = array( 'critical' => 0, 'high' => 1, 'medium' => 2, 'low' => 3 );
1084 usort( $recommendations, function( $a, $b ) use ( $priority_order ) {
1085 return ( $priority_order[ $a['priority'] ] ?? 99 ) - ( $priority_order[ $b['priority'] ] ?? 99 );
1086 } );
1087
1088 return $recommendations;
1089 }
1090
1091 /**
1092 * Get users whose display name matches their login username
1093 *
1094 * Limited to administrators and editors for performance and relevance.
1095 * Cached with transient to avoid repeated queries on every dashboard load.
1096 *
1097 * @return array Array of usernames with exposed login.
1098 */
1099 private function get_users_with_exposed_login() {
1100 $cache_key = 'vigilante_exposed_display_names';
1101 $cached = get_transient( $cache_key );
1102
1103 if ( false !== $cached ) {
1104 return $cached;
1105 }
1106
1107 $exposed = array();
1108 $users = get_users( array(
1109 'role__in' => array( 'administrator', 'editor' ),
1110 'fields' => array( 'ID', 'user_login', 'display_name' ),
1111 ) );
1112
1113 foreach ( $users as $user ) {
1114 if ( strcasecmp( $user->display_name, $user->user_login ) === 0 ) {
1115 $exposed[] = $user->user_login;
1116 }
1117 }
1118
1119 // Cache for 12 hours
1120 set_transient( $cache_key, $exposed, 12 * HOUR_IN_SECONDS );
1121
1122 return $exposed;
1123 }
1124
1125 /**
1126 * Get accounts with insecure usernames
1127 *
1128 * Checks for common default usernames that are targeted by brute force attacks.
1129 * Detects any user regardless of role (consistent with username creation blocking).
1130 * Uses WordPress object cache via get_user_by() so no transient needed.
1131 *
1132 * @return array Array of insecure usernames found.
1133 */
1134 private function get_insecure_admin_usernames() {
1135 $priority_usernames = array( 'admin', 'administrator', 'root', 'test', 'user', 'guest', 'info', 'sysadmin', 'webmaster' );
1136 $found = array();
1137
1138 foreach ( $priority_usernames as $username ) {
1139 $user = get_user_by( 'login', $username );
1140 if ( $user ) {
1141 $found[] = $username;
1142 }
1143 }
1144
1145 return $found;
1146 }
1147
1148 /**
1149 * Get security status for menu badge
1150 *
1151 * Returns count of disabled modules and whether there are critical issues.
1152 * Critical = Firewall or Login Security disabled.
1153 *
1154 * @return array Array with 'count' and 'has_critical'.
1155 */
1156 public function get_security_status_for_badge() {
1157 $options = $this->settings->get_all_options();
1158 $modules = $options['modules'] ?? array();
1159
1160 // Count disabled modules
1161 $disabled_count = 0;
1162 $has_critical = false;
1163
1164 // Critical modules - if disabled, badge is red
1165 $critical_modules = array( 'firewall', 'login_security' );
1166
1167 foreach ( $modules as $module => $enabled ) {
1168 // Handle both boolean and string values ('1', '0', true, false)
1169 $is_enabled = filter_var( $enabled, FILTER_VALIDATE_BOOLEAN );
1170
1171 if ( ! $is_enabled ) {
1172 $disabled_count++;
1173
1174 // Check if this is a critical module
1175 if ( in_array( $module, $critical_modules, true ) ) {
1176 $has_critical = true;
1177 }
1178 }
1179 }
1180
1181 return array(
1182 'count' => $disabled_count,
1183 'has_critical' => $has_critical,
1184 );
1185 }
1186
1187 /**
1188 * Get count of security issues for menu badge (deprecated, use get_security_status_for_badge)
1189 *
1190 * @return int Count of critical/high issues.
1191 */
1192 public function get_security_issues_count() {
1193 $status = $this->get_security_status_for_badge();
1194 return $status['count'];
1195 }
1196
1197 /**
1198 * Register settings
1199 */
1200 public function register_settings() {
1201 register_setting(
1202 'vigilante_options',
1203 Vigilante_Settings::OPTION_NAME,
1204 array( $this->settings, 'validate_options' )
1205 );
1206 }
1207
1208 /**
1209 * Index behind the settings search box.
1210 *
1211 * Each entry points at one settings row. The search matches on the label,
1212 * on its English original and on 'keywords', which are extra terms someone
1213 * might type instead of the label itself.
1214 *
1215 * Those keywords are wrapped in _x() with the context "settings search
1216 * keywords" so every locale can supply its own: the source strings are in
1217 * English, and a Spanish user typing "contrasena" or a German one typing
1218 * "Kennwort" only reaches the password settings if that locale translated
1219 * them. Translators can add, drop or replace terms freely, one per space;
1220 * they are never displayed, only matched against what the user types.
1221 *
1222 * The list is maintained by hand, so a new settings row needs an entry here
1223 * or it cannot be found. It had drifted to 68 of 131 rows before 2.9.7.
1224 *
1225 * @return array
1226 */
1227 private function get_search_index() {
1228 return array(
1229 // Firewall - Main
1230 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' => _x( 'block bad bots blocking blocked deny malicious harmful bot crawler crawlers spider scraper robots', 'settings search keywords', 'vigilante' ) ),
1231 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' => _x( 'block malicious requests blocking blocked deny attack attacks exploit injection sqli xss rfi lfi request traffic', 'settings search keywords', 'vigilante' ) ),
1232 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' => _x( 'rate limiting throttle flood burst limit limits', 'settings search keywords', 'vigilante' ) ),
1233 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' => _x( 'brute force protection bruteforce login', 'settings search keywords', 'vigilante' ) ),
1234 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' => _x( 'ip whitelist ips address addresses cidr ipv4 ipv6 allowlist allowed trusted', 'settings search keywords', 'vigilante' ) ),
1235 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' => _x( 'ip blacklist ips address addresses cidr ipv4 ipv6 blocklist denylist banned', 'settings search keywords', 'vigilante' ) ),
1236 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' => _x( 'user-agent whitelist ua useragent browser allowlist allowed trusted user', 'settings search keywords', 'vigilante' ) ),
1237 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' => _x( 'user-agent blacklist ua useragent browser blocklist denylist banned user', 'settings search keywords', 'vigilante' ) ),
1238 // Firewall - Server Protection
1239 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' => _x( 'directory browsing folder folders listing indexing index', 'settings search keywords', 'vigilante' ) ),
1240 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' => _x( 'protect wp-config php protection secure lock', 'settings search keywords', 'vigilante' ) ),
1241 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' => _x( 'protect wp-cron php protection secure lock cron scheduled tasks block spam', 'settings search keywords', 'vigilante' ) ),
1242 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' => _x( 'protect wp-includes protection secure lock', 'settings search keywords', 'vigilante' ) ),
1243 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' => _x( 'php in uploads media upload', 'settings search keywords', 'vigilante' ) ),
1244 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' => _x( 'sensitive files private secret file log', 'settings search keywords', 'vigilante' ) ),
1245 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' => _x( 'limit http methods', 'settings search keywords', 'vigilante' ) ),
1246 // Security Headers
1247 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' => _x( 'x-frame-options headers', 'settings search keywords', 'vigilante' ) ),
1248 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' => _x( 'x-content-type-options content headers', 'settings search keywords', 'vigilante' ) ),
1249 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' => _x( 'referrer-policy headers', 'settings search keywords', 'vigilante' ) ),
1250 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'HSTS', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'HSTS', 'vigilante' ), 'label_en' => 'HSTS', 'keywords' => _x( 'hsts strict transport security ssl tls https headers', 'settings search keywords', 'vigilante' ) ),
1251 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' => _x( 'content security policy csp xss headers', 'settings search keywords', 'vigilante' ) ),
1252 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' => _x( 'server signature fingerprint banner', 'settings search keywords', 'vigilante' ) ),
1253 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' => _x( 'remove fingerprinting headers fingerprint banner header http', 'settings search keywords', 'vigilante' ) ),
1254 // Security Headers - Cross-Origin Policies
1255 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Cross-Origin Policies', 'vigilante' ), 'anchor' => 'vigilante-section-headers-cross-origin', 'label' => __( 'Cross-Origin-Opener-Policy (COOP)', 'vigilante' ), 'label_en' => 'Cross-Origin-Opener-Policy (COOP)', 'keywords' => _x( 'coop cross-origin opener policy popup popups window opener tag assistant google isolation browsing context headers', 'settings search keywords', 'vigilante' ) ),
1256 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Cross-Origin Policies', 'vigilante' ), 'anchor' => 'vigilante-section-headers-cross-origin', 'label' => __( 'Cross-Origin-Embedder-Policy (COEP)', 'vigilante' ), 'label_en' => 'Cross-Origin-Embedder-Policy (COEP)', 'keywords' => _x( 'coep cross-origin embedder policy require-corp credentialless embed embeds iframe fonts headers', 'settings search keywords', 'vigilante' ) ),
1257 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Cross-Origin Policies', 'vigilante' ), 'anchor' => 'vigilante-section-headers-cross-origin', 'label' => __( 'Cross-Origin-Resource-Policy (CORP)', 'vigilante' ), 'label_en' => 'Cross-Origin-Resource-Policy (CORP)', 'keywords' => _x( 'corp cross-origin resource policy hotlink hotlinking cdn images assets headers', 'settings search keywords', 'vigilante' ) ),
1258 // Login Security
1259 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' => _x( 'custom login url signin log-in access slug', 'settings search keywords', 'vigilante' ) ),
1260 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' => _x( 'two-factor authentication 2fa mfa otp totp authenticator', 'settings search keywords', 'vigilante' ) ),
1261 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( '2FA', 'vigilante' ), 'label_en' => '2FA', 'keywords' => _x( '2fa two-factor mfa otp totp authenticator', 'settings search keywords', 'vigilante' ) ),
1262 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' => _x( 'failed login attempts signin log-in access tries retries', 'settings search keywords', 'vigilante' ) ),
1263 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Lockout', 'vigilante' ), 'label_en' => 'Lockout', 'keywords' => _x( 'lockout lock ban block login', 'settings search keywords', 'vigilante' ) ),
1264 // REST API
1265 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' => _x( 'access mode rest api', 'settings search keywords', 'vigilante' ) ),
1266 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' => _x( 'block user enumeration blocking blocked deny users account author slug', 'settings search keywords', 'vigilante' ) ),
1267 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' => _x( 'disable jsonp', 'settings search keywords', 'vigilante' ) ),
1268 // User Security
1269 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' => _x( 'username protection admin', 'settings search keywords', 'vigilante' ) ),
1270 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' => _x( 'password strength passwords credentials', 'settings search keywords', 'vigilante' ) ),
1271 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' => _x( 'admin monitoring administrator administrators', 'settings search keywords', 'vigilante' ) ),
1272 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' => _x( 'registration approval signup register approve moderate', 'settings search keywords', 'vigilante' ) ),
1273 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' => _x( 'session limits sessions concurrent', 'settings search keywords', 'vigilante' ) ),
1274 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' => _x( 'password expiration passwords credentials expiry expire caducity', 'settings search keywords', 'vigilante' ) ),
1275 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' => _x( 'email verification mail notification notify verify confirm', 'settings search keywords', 'vigilante' ) ),
1276 // WP Hardening
1277 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' => _x( 'database hardening db mysql tables', 'settings search keywords', 'vigilante' ) ),
1278 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' => _x( 'database prefix db mysql tables table', 'settings search keywords', 'vigilante' ) ),
1279 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' => _x( 'disable file editing files editor edit', 'settings search keywords', 'vigilante' ) ),
1280 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' => _x( 'disable plugin theme installation install', 'settings search keywords', 'vigilante' ) ),
1281 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' => _x( 'force ssl admin bruteforce administrator administrators tls https', 'settings search keywords', 'vigilante' ) ),
1282 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' => _x( 'disable wp cron scheduled tasks wp-cron', 'settings search keywords', 'vigilante' ) ),
1283 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' => _x( 'comment security comments spam honeypot url', 'settings search keywords', 'vigilante' ) ),
1284 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' => _x( 'header cleanup headers http meta generator rsd wlwmanifest', 'settings search keywords', 'vigilante' ) ),
1285 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' => _x( 'remove wordpress version generator meta', 'settings search keywords', 'vigilante' ) ),
1286 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' => _x( 'remove version from assets', 'settings search keywords', 'vigilante' ) ),
1287 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-xmlrpc', 'label' => __( 'Disable XML-RPC', 'vigilante' ), 'label_en' => 'Disable XML-RPC', 'keywords' => _x( 'disable xml-rpc xmlrpc rpc remote jetpack app pingback trackback', 'settings search keywords', 'vigilante' ) ),
1288 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' => _x( 'rss feed settings feeds atom', 'settings search keywords', 'vigilante' ) ),
1289 // File Integrity
1290 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' => _x( 'file integrity monitoring files checksum checksums tamper', 'settings search keywords', 'vigilante' ) ),
1291 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' => _x( 'scan schedule scans scanning check cron', 'settings search keywords', 'vigilante' ) ),
1292 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' => _x( 'instant alert alerts notification warning email', 'settings search keywords', 'vigilante' ) ),
1293 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' => _x( 'ignored files file exclude', 'settings search keywords', 'vigilante' ) ),
1294 // Security Audit
1295 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' => _x( 'retention keep days storage log', 'settings search keywords', 'vigilante' ) ),
1296 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' => _x( 'events to log', 'settings search keywords', 'vigilante' ) ),
1297 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' => _x( 'option tracking', 'settings search keywords', 'vigilante' ) ),
1298 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' => _x( 'exclusions roles ip', 'settings search keywords', 'vigilante' ) ),
1299 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' => _x( 'audit alerts email mail warning critical', 'settings search keywords', 'vigilante' ) ),
1300 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' => _x( 'immediate alerts email mail critical warning', 'settings search keywords', 'vigilante' ) ),
1301 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' => _x( 'threshold alerts email mail login', 'settings search keywords', 'vigilante' ) ),
1302 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' => _x( 'recent activity log', 'settings search keywords', 'vigilante' ) ),
1303 // Settings & Tools
1304 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' => _x( 'notification settings email', 'settings search keywords', 'vigilante' ) ),
1305 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' => _x( 'additional recipients email recipient', 'settings search keywords', 'vigilante' ) ),
1306 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' => _x( 'export settings json', 'settings search keywords', 'vigilante' ) ),
1307 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' => _x( 'import settings json', 'settings search keywords', 'vigilante' ) ),
1308 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' => _x( 'reset to defaults', 'settings search keywords', 'vigilante' ) ),
1309 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' => _x( 'create backup', 'settings search keywords', 'vigilante' ) ),
1310 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' => _x( 'database backup db mysql tables', 'settings search keywords', 'vigilante' ) ),
1311 // Entradas anadidas en la 2.9.7 tras comprobar que el indice cubria 68 de
1312 // las 131 filas de ajustes: buscar XML-RPC, por ejemplo, no devolvia nada.
1313 // El indice se mantiene a mano, asi que al anadir una fila de ajustes hay
1314 // que anadirla tambien aqui.
1315 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Notification settings', 'vigilante' ), 'anchor' => 'vigilante-section-tools-notifications', 'label' => __( 'WordPress Admin Email', 'vigilante' ), 'label_en' => 'WordPress Admin Email', 'keywords' => _x( 'wordpress admin email administrator administrators mail notification notify', 'settings search keywords', 'vigilante' ) ),
1316 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Notification settings', 'vigilante' ), 'anchor' => 'vigilante-section-tools-notifications', 'label' => __( 'Plugin Deactivation', 'vigilante' ), 'label_en' => 'Plugin Deactivation', 'keywords' => _x( 'plugin deactivation', 'settings search keywords', 'vigilante' ) ),
1317 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Block Bad Query Strings', 'vigilante' ), 'label_en' => 'Block Bad Query Strings', 'keywords' => _x( 'block bad query strings blocking blocked deny malicious harmful', 'settings search keywords', 'vigilante' ) ),
1318 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'SQL Injection Protection', 'vigilante' ), 'label_en' => 'SQL Injection Protection', 'keywords' => _x( 'sql injection protection', 'settings search keywords', 'vigilante' ) ),
1319 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'XSS Protection', 'vigilante' ), 'label_en' => 'XSS Protection', 'keywords' => _x( 'xss protection', 'settings search keywords', 'vigilante' ) ),
1320 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'File Inclusion Protection', 'vigilante' ), 'label_en' => 'File Inclusion Protection', 'keywords' => _x( 'file inclusion protection files', 'settings search keywords', 'vigilante' ) ),
1321 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Directory Traversal Protection', 'vigilante' ), 'label_en' => 'Directory Traversal Protection', 'keywords' => _x( 'directory traversal protection folder folders', 'settings search keywords', 'vigilante' ) ),
1322 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Enable Rate Limiting', 'vigilante' ), 'label_en' => 'Enable Rate Limiting', 'keywords' => _x( 'enable rate limiting throttle flood burst limit limits', 'settings search keywords', 'vigilante' ) ),
1323 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Requests per Minute', 'vigilante' ), 'label_en' => 'Requests per Minute', 'keywords' => _x( 'requests per minute request traffic', 'settings search keywords', 'vigilante' ) ),
1324 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Block Duration (seconds)', 'vigilante' ), 'label_en' => 'Block Duration (seconds)', 'keywords' => _x( 'block duration seconds blocking blocked deny', 'settings search keywords', 'vigilante' ) ),
1325 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Progressive Blocking', 'vigilante' ), 'label_en' => 'Progressive Blocking', 'keywords' => _x( 'progressive blocking', 'settings search keywords', 'vigilante' ) ),
1326 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Maximum Block Duration', 'vigilante' ), 'label_en' => 'Maximum Block Duration', 'keywords' => _x( 'maximum block duration blocking blocked deny', 'settings search keywords', 'vigilante' ) ),
1327 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Visitor IP detection', 'vigilante' ), 'label_en' => 'Visitor IP detection', 'keywords' => _x( 'visitor ip detection ips address addresses cidr ipv4 ipv6', 'settings search keywords', 'vigilante' ) ),
1328 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Max Login Attempts', 'vigilante' ), 'label_en' => 'Max Login Attempts', 'keywords' => _x( 'max login attempts signin log-in access tries retries', 'settings search keywords', 'vigilante' ) ),
1329 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Lockout Duration', 'vigilante' ), 'label_en' => 'Lockout Duration', 'keywords' => _x( 'lockout duration lock ban block', 'settings search keywords', 'vigilante' ) ),
1330 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Progressive Lockout', 'vigilante' ), 'label_en' => 'Progressive Lockout', 'keywords' => _x( 'progressive lockout lock ban block', 'settings search keywords', 'vigilante' ) ),
1331 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Hide Login Errors', 'vigilante' ), 'label_en' => 'Hide Login Errors', 'keywords' => _x( 'hide login errors signin log-in access error debug log', 'settings search keywords', 'vigilante' ) ),
1332 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Disable Application Passwords', 'vigilante' ), 'label_en' => 'Disable Application Passwords', 'keywords' => _x( 'disable application passwords password credentials', 'settings search keywords', 'vigilante' ) ),
1333 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Login URL Slug', 'vigilante' ), 'label_en' => 'Login URL Slug', 'keywords' => _x( 'login url slug signin log-in access path', 'settings search keywords', 'vigilante' ) ),
1334 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Notify users', 'vigilante' ), 'label_en' => 'Notify users', 'keywords' => _x( 'notify users notification alert email user accounts', 'settings search keywords', 'vigilante' ) ),
1335 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Notify on Lockout', 'vigilante' ), 'label_en' => 'Notify on Lockout', 'keywords' => _x( 'notify on lockout notification alert email lock ban block', 'settings search keywords', 'vigilante' ) ),
1336 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Notify on Admin Login', 'vigilante' ), 'label_en' => 'Notify on Admin Login', 'keywords' => _x( 'notify on admin login notification alert email administrator administrators signin log-in access', 'settings search keywords', 'vigilante' ) ),
1337 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Current settings', 'vigilante' ), 'label_en' => 'Current settings', 'keywords' => _x( 'current settings', 'settings search keywords', 'vigilante' ) ),
1338 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Blocked IPs', 'vigilante' ), 'label_en' => 'Blocked IPs', 'keywords' => _x( 'blocked ips', 'settings search keywords', 'vigilante' ) ),
1339 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Enable 2FA', 'vigilante' ), 'label_en' => 'Enable 2FA', 'keywords' => _x( 'enable 2fa two-factor mfa otp totp authenticator', 'settings search keywords', 'vigilante' ) ),
1340 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Verification method', 'vigilante' ), 'label_en' => 'Verification method', 'keywords' => _x( 'verification method verify confirm', 'settings search keywords', 'vigilante' ) ),
1341 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Enforce for roles', 'vigilante' ), 'label_en' => 'Enforce for roles', 'keywords' => _x( 'enforce for roles role capabilities', 'settings search keywords', 'vigilante' ) ),
1342 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Exclude specific users', 'vigilante' ), 'label_en' => 'Exclude specific users', 'keywords' => _x( 'exclude specific users user accounts', 'settings search keywords', 'vigilante' ) ),
1343 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Remember device', 'vigilante' ), 'label_en' => 'Remember device', 'keywords' => _x( 'remember device', 'settings search keywords', 'vigilante' ) ),
1344 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Grace period', 'vigilante' ), 'label_en' => 'Grace period', 'keywords' => _x( 'grace period', 'settings search keywords', 'vigilante' ) ),
1345 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Email sender name', 'vigilante' ), 'label_en' => 'Email sender name', 'keywords' => _x( 'email sender name mail notification notify names', 'settings search keywords', 'vigilante' ) ),
1346 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Reset user TOTP', 'vigilante' ), 'label_en' => 'Reset user TOTP', 'keywords' => _x( 'reset user totp users account 2fa authenticator app', 'settings search keywords', 'vigilante' ) ),
1347 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Notify on enable', 'vigilante' ), 'label_en' => 'Notify on enable', 'keywords' => _x( 'notify on enable notification alert email', 'settings search keywords', 'vigilante' ) ),
1348 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Enable CSP', 'vigilante' ), 'label_en' => 'Enable CSP', 'keywords' => _x( 'enable csp content security policy', 'settings search keywords', 'vigilante' ) ),
1349 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Report Only Mode', 'vigilante' ), 'label_en' => 'Report Only Mode', 'keywords' => _x( 'report only mode', 'settings search keywords', 'vigilante' ) ),
1350 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Redirect HTTP to HTTPS', 'vigilante' ), 'label_en' => 'Redirect HTTP to HTTPS', 'keywords' => _x( 'redirect http to https redirection forward ssl tls secure', 'settings search keywords', 'vigilante' ) ),
1351 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Fix Mixed Content', 'vigilante' ), 'label_en' => 'Fix Mixed Content', 'keywords' => _x( 'fix mixed content insecure http', 'settings search keywords', 'vigilante' ) ),
1352 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'field-upgrade-insecure-requests', 'label' => __( 'Upgrade Insecure Requests', 'vigilante' ), 'label_en' => 'Upgrade Insecure Requests', 'keywords' => _x( 'upgrade insecure requests mixed content csp https external resources', 'settings search keywords', 'vigilante' ) ),
1353 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Rewrite Site Address on Activation', 'vigilante' ), 'label_en' => 'Rewrite Site Address on Activation', 'keywords' => _x( 'rewrite site address on activation', 'settings search keywords', 'vigilante' ) ),
1354 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Enable HSTS', 'vigilante' ), 'label_en' => 'Enable HSTS', 'keywords' => _x( 'enable hsts strict transport security', 'settings search keywords', 'vigilante' ) ),
1355 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Max Age', 'vigilante' ), 'label_en' => 'Max Age', 'keywords' => _x( 'max age', 'settings search keywords', 'vigilante' ) ),
1356 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Include Subdomains', 'vigilante' ), 'label_en' => 'Include Subdomains', 'keywords' => _x( 'include subdomains', 'settings search keywords', 'vigilante' ) ),
1357 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Block Insecure Usernames', 'vigilante' ), 'label_en' => 'Block Insecure Usernames', 'keywords' => _x( 'block insecure usernames blocking blocked deny weak unsafe', 'settings search keywords', 'vigilante' ) ),
1358 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Enforce Strong Passwords', 'vigilante' ), 'label_en' => 'Enforce Strong Passwords', 'keywords' => _x( 'enforce strong passwords complexity password credentials', 'settings search keywords', 'vigilante' ) ),
1359 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Minimum Password Length', 'vigilante' ), 'label_en' => 'Minimum Password Length', 'keywords' => _x( 'minimum password length passwords credentials characters', 'settings search keywords', 'vigilante' ) ),
1360 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Password Requirements', 'vigilante' ), 'label_en' => 'Password Requirements', 'keywords' => _x( 'password requirements passwords credentials', 'settings search keywords', 'vigilante' ) ),
1361 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Apply Password Rules To', 'vigilante' ), 'label_en' => 'Apply Password Rules To', 'keywords' => _x( 'apply password rules to passwords credentials', 'settings search keywords', 'vigilante' ) ),
1362 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Block Author Scanning', 'vigilante' ), 'label_en' => 'Block Author Scanning', 'keywords' => _x( 'block author scanning blocking blocked deny authors enumeration probing', 'settings search keywords', 'vigilante' ) ),
1363 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Display Name Protection', 'vigilante' ), 'label_en' => 'Display Name Protection', 'keywords' => _x( 'display name protection public visible names', 'settings search keywords', 'vigilante' ) ),
1364 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Admin monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-users-admin-monitoring', 'label' => __( 'New Administrator Alert', 'vigilante' ), 'label_en' => 'New Administrator Alert', 'keywords' => _x( 'new administrator alert alerts notification warning', 'settings search keywords', 'vigilante' ) ),
1365 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Admin monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-users-admin-monitoring', 'label' => __( 'Admin Email Change Alert', 'vigilante' ), 'label_en' => 'Admin Email Change Alert', 'keywords' => _x( 'admin email change alert administrator administrators mail notification notify alerts warning', 'settings search keywords', 'vigilante' ) ),
1366 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Admin monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-users-admin-monitoring', 'label' => __( 'Permission Elevation Alert', 'vigilante' ), 'label_en' => 'Permission Elevation Alert', 'keywords' => _x( 'permission elevation alert alerts notification warning', 'settings search keywords', 'vigilante' ) ),
1367 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Admin monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-users-admin-monitoring', 'label' => __( 'Admin Password Change Alert', 'vigilante' ), 'label_en' => 'Admin Password Change Alert', 'keywords' => _x( 'admin password change alert administrator administrators passwords credentials alerts notification warning', 'settings search keywords', 'vigilante' ) ),
1368 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Registration approval', 'vigilante' ), 'anchor' => 'vigilante-section-users-registration', 'label' => __( 'Enable Registration Approval', 'vigilante' ), 'label_en' => 'Enable Registration Approval', 'keywords' => _x( 'enable registration approval signup register approve moderate', 'settings search keywords', 'vigilante' ) ),
1369 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Registration approval', 'vigilante' ), 'anchor' => 'vigilante-section-users-registration', 'label' => __( 'Notify Admin', 'vigilante' ), 'label_en' => 'Notify Admin', 'keywords' => _x( 'notify admin notification alert email administrator administrators', 'settings search keywords', 'vigilante' ) ),
1370 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Registration approval', 'vigilante' ), 'anchor' => 'vigilante-section-users-registration', 'label' => __( 'Auto-reject After', 'vigilante' ), 'label_en' => 'Auto-reject After', 'keywords' => _x( 'auto-reject after', 'settings search keywords', 'vigilante' ) ),
1371 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Session limits', 'vigilante' ), 'anchor' => 'vigilante-section-users-sessions', 'label' => __( 'Enable Session Limits', 'vigilante' ), 'label_en' => 'Enable Session Limits', 'keywords' => _x( 'enable session limits sessions concurrent', 'settings search keywords', 'vigilante' ) ),
1372 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Session limits', 'vigilante' ), 'anchor' => 'vigilante-section-users-sessions', 'label' => __( 'Maximum Sessions', 'vigilante' ), 'label_en' => 'Maximum Sessions', 'keywords' => _x( 'maximum sessions session concurrent', 'settings search keywords', 'vigilante' ) ),
1373 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Session limits', 'vigilante' ), 'anchor' => 'vigilante-section-users-sessions', 'label' => __( 'When Limit Exceeded', 'vigilante' ), 'label_en' => 'When Limit Exceeded', 'keywords' => _x( 'when limit exceeded', 'settings search keywords', 'vigilante' ) ),
1374 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Session limits', 'vigilante' ), 'anchor' => 'vigilante-section-users-sessions', 'label' => __( 'Exclude Administrators', 'vigilante' ), 'label_en' => 'Exclude Administrators', 'keywords' => _x( 'exclude administrators', 'settings search keywords', 'vigilante' ) ),
1375 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Enable Password Expiration', 'vigilante' ), 'label_en' => 'Enable Password Expiration', 'keywords' => _x( 'enable password expiration passwords credentials expiry expire caducity', 'settings search keywords', 'vigilante' ) ),
1376 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Expire After', 'vigilante' ), 'label_en' => 'Expire After', 'keywords' => _x( 'expire after', 'settings search keywords', 'vigilante' ) ),
1377 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Warning Period', 'vigilante' ), 'label_en' => 'Warning Period', 'keywords' => _x( 'warning period', 'settings search keywords', 'vigilante' ) ),
1378 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Password History', 'vigilante' ), 'label_en' => 'Password History', 'keywords' => _x( 'password history passwords credentials reuse previous', 'settings search keywords', 'vigilante' ) ),
1379 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Email Reminder', 'vigilante' ), 'label_en' => 'Email Reminder', 'keywords' => _x( 'email reminder mail notification notify', 'settings search keywords', 'vigilante' ) ),
1380 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Affected Roles', 'vigilante' ), 'label_en' => 'Affected Roles', 'keywords' => _x( 'affected roles role capabilities', 'settings search keywords', 'vigilante' ) ),
1381 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Exclude specific users', 'vigilante' ), 'label_en' => 'Exclude specific users', 'keywords' => _x( 'exclude specific users user accounts', 'settings search keywords', 'vigilante' ) ),
1382 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Email verification', 'vigilante' ), 'anchor' => 'vigilante-section-users-email-verify', 'label' => __( 'Enable Email Verification', 'vigilante' ), 'label_en' => 'Enable Email Verification', 'keywords' => _x( 'enable email verification mail notification notify verify confirm', 'settings search keywords', 'vigilante' ) ),
1383 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Email verification', 'vigilante' ), 'anchor' => 'vigilante-section-users-email-verify', 'label' => __( 'Link Expiration', 'vigilante' ), 'label_en' => 'Link Expiration', 'keywords' => _x( 'link expiration expiry expire caducity', 'settings search keywords', 'vigilante' ) ),
1384 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Email verification', 'vigilante' ), 'anchor' => 'vigilante-section-users-email-verify', 'label' => __( 'Allow Resend', 'vigilante' ), 'label_en' => 'Allow Resend', 'keywords' => _x( 'allow resend', 'settings search keywords', 'vigilante' ) ),
1385 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Email verification', 'vigilante' ), 'anchor' => 'vigilante-section-users-email-verify', 'label' => __( 'Auto-delete Unverified', 'vigilante' ), 'label_en' => 'Auto-delete Unverified', 'keywords' => _x( 'auto-delete unverified', 'settings search keywords', 'vigilante' ) ),
1386 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Database Hardening', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-database', 'label' => __( 'Current prefix', 'vigilante' ), 'label_en' => 'Current prefix', 'keywords' => _x( 'current prefix database db table tables mysql', 'settings search keywords', 'vigilante' ) ),
1387 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Database Hardening', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-database', 'label' => __( 'New prefix', 'vigilante' ), 'label_en' => 'New prefix', 'keywords' => _x( 'new prefix database db table tables mysql', 'settings search keywords', 'vigilante' ) ),
1388 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'wp-config.php Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-wpconfig', 'label' => __( 'Disable File Editor', 'vigilante' ), 'label_en' => 'Disable File Editor', 'keywords' => _x( 'disable file editor files edit editing', 'settings search keywords', 'vigilante' ) ),
1389 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'wp-config.php Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-wpconfig', 'label' => __( 'Disable File Modifications', 'vigilante' ), 'label_en' => 'Disable File Modifications', 'keywords' => _x( 'disable file modifications files modify install update', 'settings search keywords', 'vigilante' ) ),
1390 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'wp-config.php Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-wpconfig', 'label' => __( 'Hide PHP errors from visitors', 'vigilante' ), 'label_en' => 'Hide PHP errors from visitors', 'keywords' => _x( 'hide php errors from visitors error debug log', 'settings search keywords', 'vigilante' ) ),
1391 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'XML-RPC', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-xmlrpc', 'label' => __( 'XML-RPC access', 'vigilante' ), 'label_en' => 'XML-RPC access', 'keywords' => _x( 'xml-rpc access xmlrpc rpc remote jetpack app', 'settings search keywords', 'vigilante' ) ),
1392 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Comment Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-comments', 'label' => __( 'Disable Pingbacks', 'vigilante' ), 'label_en' => 'Disable Pingbacks', 'keywords' => _x( 'disable pingbacks pingback ping', 'settings search keywords', 'vigilante' ) ),
1393 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Comment Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-comments', 'label' => __( 'Disable Trackbacks', 'vigilante' ), 'label_en' => 'Disable Trackbacks', 'keywords' => _x( 'disable trackbacks trackback ping', 'settings search keywords', 'vigilante' ) ),
1394 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Comment Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-comments', 'label' => __( 'Require Moderation', 'vigilante' ), 'label_en' => 'Require Moderation', 'keywords' => _x( 'require moderation moderate approve', 'settings search keywords', 'vigilante' ) ),
1395 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Comment Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-comments', 'label' => __( 'Close Old Comments', 'vigilante' ), 'label_en' => 'Close Old Comments', 'keywords' => _x( 'close old comments comment discussion', 'settings search keywords', 'vigilante' ) ),
1396 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Comment Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-comments', 'label' => __( 'Honeypot Protection', 'vigilante' ), 'label_en' => 'Honeypot Protection', 'keywords' => _x( 'honeypot protection spam bots trap', 'settings search keywords', 'vigilante' ) ),
1397 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-headers', 'label' => __( 'Remove Generator', 'vigilante' ), 'label_en' => 'Remove Generator', 'keywords' => _x( 'remove generator version meta', 'settings search keywords', 'vigilante' ) ),
1398 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-headers', 'label' => __( 'Remove RSD Link', 'vigilante' ), 'label_en' => 'Remove RSD Link', 'keywords' => _x( 'remove rsd link discovery', 'settings search keywords', 'vigilante' ) ),
1399 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-headers', 'label' => __( 'Remove WLW Manifest', 'vigilante' ), 'label_en' => 'Remove WLW Manifest', 'keywords' => _x( 'remove wlw manifest wlwmanifest', 'settings search keywords', 'vigilante' ) ),
1400 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-headers', 'label' => __( 'Remove Shortlink', 'vigilante' ), 'label_en' => 'Remove Shortlink', 'keywords' => _x( 'remove shortlink link', 'settings search keywords', 'vigilante' ) ),
1401 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-headers', 'label' => __( 'Remove REST API Link', 'vigilante' ), 'label_en' => 'Remove REST API Link', 'keywords' => _x( 'remove rest api link json endpoint', 'settings search keywords', 'vigilante' ) ),
1402 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'RSS Feed Settings', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-rss', 'label' => __( 'Disable Feeds', 'vigilante' ), 'label_en' => 'Disable Feeds', 'keywords' => _x( 'disable feeds feed rss atom syndication', 'settings search keywords', 'vigilante' ) ),
1403 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'RSS Feed Settings', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-rss', 'label' => __( 'Disable If No Content', 'vigilante' ), 'label_en' => 'Disable If No Content', 'keywords' => _x( 'disable if no content', 'settings search keywords', 'vigilante' ) ),
1404 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'RSS Feed Settings', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-rss', 'label' => __( 'Remove Feed Version', 'vigilante' ), 'label_en' => 'Remove Feed Version', 'keywords' => _x( 'remove feed version feeds rss atom', 'settings search keywords', 'vigilante' ) ),
1405 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Audit Alerts', 'vigilante' ), 'anchor' => 'vigilante-section-audit-alerts', 'label' => __( 'Alert on severity', 'vigilante' ), 'label_en' => 'Alert on severity', 'keywords' => _x( 'alert on severity alerts notification warning level critical', 'settings search keywords', 'vigilante' ) ),
1406 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Audit Alerts', 'vigilante' ), 'anchor' => 'vigilante-section-audit-alerts', 'label' => __( 'Time window', 'vigilante' ), 'label_en' => 'Time window', 'keywords' => _x( 'time window', 'settings search keywords', 'vigilante' ) ),
1407 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Audit Alerts', 'vigilante' ), 'anchor' => 'vigilante-section-audit-alerts', 'label' => __( 'Thresholds per category', 'vigilante' ), 'label_en' => 'Thresholds per category', 'keywords' => _x( 'thresholds per category threshold limit', 'settings search keywords', 'vigilante' ) ),
1408 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Audit Alerts', 'vigilante' ), 'anchor' => 'vigilante-section-audit-alerts', 'label' => __( 'Recipients', 'vigilante' ), 'label_en' => 'Recipients', 'keywords' => _x( 'recipients email recipient', 'settings search keywords', 'vigilante' ) ),
1409 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Automatic Scans', 'vigilante' ), 'label_en' => 'Automatic Scans', 'keywords' => _x( 'automatic scans scan scanning', 'settings search keywords', 'vigilante' ) ),
1410 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Scan Frequency', 'vigilante' ), 'label_en' => 'Scan Frequency', 'keywords' => _x( 'scan frequency scans scanning check', 'settings search keywords', 'vigilante' ) ),
1411 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Email Notifications', 'vigilante' ), 'label_en' => 'Email Notifications', 'keywords' => _x( 'email notifications mail notification notify', 'settings search keywords', 'vigilante' ) ),
1412 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Test email', 'vigilante' ), 'label_en' => 'Test email', 'keywords' => _x( 'test email mail notification notify', 'settings search keywords', 'vigilante' ) ),
1413 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Scan Scope', 'vigilante' ), 'label_en' => 'Scan Scope', 'keywords' => _x( 'scan scope scans scanning check', 'settings search keywords', 'vigilante' ) ),
1414 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Excluded Paths', 'vigilante' ), 'label_en' => 'Excluded Paths', 'keywords' => _x( 'excluded paths exclude exclusions ignore ignored path folder folders', 'settings search keywords', 'vigilante' ) ),
1415 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Excluded Extensions', 'vigilante' ), 'label_en' => 'Excluded Extensions', 'keywords' => _x( 'excluded extensions exclude exclusions ignore ignored extension filetype', 'settings search keywords', 'vigilante' ) ),
1416 );
1417 }
1418
1419 /**
1420 * Enqueue admin assets
1421 *
1422 * @param string $hook Current admin page.
1423 */
1424 public function enqueue_assets( $hook ) {
1425 // toplevel_page_vigilante for top-level menu page
1426 if ( 'toplevel_page_vigilante' !== $hook ) {
1427 return;
1428 }
1429
1430 wp_enqueue_style(
1431 'vigilante-admin',
1432 VIGILANTE_ASSETS_URL . 'css/admin.css',
1433 array(),
1434 VIGILANTE_VERSION
1435 );
1436
1437 wp_enqueue_script(
1438 'vigilante-admin',
1439 VIGILANTE_ASSETS_URL . 'js/admin.js',
1440 array( 'jquery' ),
1441 VIGILANTE_VERSION,
1442 true
1443 );
1444
1445 wp_localize_script( 'vigilante-admin', 'vigilanteAdmin', array(
1446 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
1447 'nonce' => wp_create_nonce( 'vigilante_admin_nonce' ),
1448 'currentUserId' => get_current_user_id(),
1449 'logoutUrl' => wp_logout_url( wp_login_url() ),
1450 'adminUrl' => admin_url( 'admin.php?page=vigilante' ),
1451 'searchIndex' => $this->get_search_index(),
1452 'underAttack' => array(
1453 'active' => ( new Vigilante_Under_Attack( $this->settings, $this->activity_log ) )->is_active(),
1454 'remaining' => ( new Vigilante_Under_Attack( $this->settings, $this->activity_log ) )->get_remaining_time(),
1455 ),
1456 'strings' => array(
1457 'saving' => __( 'Saving...', 'vigilante' ),
1458 'sendingTest' => __( 'Sending...', 'vigilante' ),
1459 'saved' => __( 'Settings saved', 'vigilante' ),
1460 'error' => __( 'Error saving settings', 'vigilante' ),
1461 'confirm' => __( 'Are you sure?', 'vigilante' ),
1462 'scanning' => __( 'Scanning...', 'vigilante' ),
1463 'scanComplete' => __( 'Scan complete', 'vigilante' ),
1464 'loading' => __( 'Loading...', 'vigilante' ),
1465 'searching' => __( 'Searching...', 'vigilante' ),
1466 'noUsersFound' => __( 'No users found', 'vigilante' ),
1467 'searchError' => __( 'Error searching users', 'vigilante' ),
1468 'sending' => __( 'Sending...', 'vigilante' ),
1469 'sendNotification' => __( 'Send notification now', 'vigilante' ),
1470 'notificationsSent' => __( 'notifications sent', 'vigilante' ),
1471 'skipped' => __( 'skipped', 'vigilante' ),
1472 'failed' => __( 'failed', 'vigilante' ),
1473 'customConfig' => __( 'Custom Configuration', 'vigilante' ),
1474 // Header tester strings
1475 'testHeaders' => __( 'Test Headers', 'vigilante' ),
1476 'testing' => __( 'Testing...', 'vigilante' ),
1477 'score' => __( 'Score', 'vigilante' ),
1478 'enabledHeaders' => __( 'Enabled headers', 'vigilante' ),
1479 'missingHeaders' => __( 'Missing headers', 'vigilante' ),
1480 'warnings' => __( 'Warnings', 'vigilante' ),
1481 // File integrity scan results strings
1482 'scanResults' => __( 'Scan Results', 'vigilante' ),
1483 'ok' => __( 'OK', 'vigilante' ),
1484 'modified' => __( 'Modified', 'vigilante' ),
1485 'suspicious' => __( 'Suspicious', 'vigilante' ),
1486 'totalScanned' => __( 'Total Scanned', 'vigilante' ),
1487 'suspiciousFiles' => __( 'Suspicious Files', 'vigilante' ),
1488 'suspiciousWarning' => __( 'These files may contain malicious code or are in unexpected locations. Review immediately!', 'vigilante' ),
1489 'file' => __( 'File', 'vigilante' ),
1490 'reason' => __( 'Reason', 'vigilante' ),
1491 'type' => __( 'Type', 'vigilante' ),
1492 'unknown' => __( 'Unknown', 'vigilante' ),
1493 'modifiedFiles' => __( 'Modified Files', 'vigilante' ),
1494 'modifiedDescription' => __( 'These files (apparently) differ from the original WordPress or plugin versions.', 'vigilante' ),
1495 'extraFiles' => __( 'Extra Files', 'vigilante' ),
1496 'extra' => __( 'Extra', 'vigilante' ),
1497 'ignored' => __( 'Ignored', 'vigilante' ),
1498 'extraDescription' => __( 'PHP files found in plugins or themes that are not part of the original distribution from WordPress.org.', 'vigilante' ),
1499 'actions' => __( 'Actions', 'vigilante' ),
1500 'ignore' => __( 'Ignore', 'vigilante' ),
1501 'ignoring' => __( 'Ignoring...', 'vigilante' ),
1502 'fileIgnored' => __( 'File added to ignored list.', 'vigilante' ),
1503 'fileUnignored' => __( 'File removed from ignored list.', 'vigilante' ),
1504 'confirmClearIgnored' => __( 'Remove all files from the ignored list? They will appear in scan results again.', 'vigilante' ),
1505 'ignoredCleared' => __( 'Ignored files list cleared. Page will reload...', 'vigilante' ),
1506 'selectAll' => __( 'Select all', 'vigilante' ),
1507 'bulkIgnoreSelected' => __( 'Ignore selected', 'vigilante' ),
1508 'bulkUnignoreSelected'=> __( 'Stop ignoring selected', 'vigilante' ),
1509 'bulkNoSelection' => __( 'Select at least one file first.', 'vigilante' ),
1510 'bulkConfirmIgnore' => __( 'Ignore the selected files? They will be hidden from future scan results until you remove them from the ignored list.', 'vigilante' ),
1511 'bulkConfirmUnignore' => __( 'Remove the selected files from the ignored list? They will appear in scan results again.', 'vigilante' ),
1512 'bulkProcessing' => __( 'Processing...', 'vigilante' ),
1513 /* translators: %d: number of files selected for bulk action. */
1514 'bulkSelectedCount' => __( '%d selected', 'vigilante' ),
1515 'allClear' => __( 'All files verified - no issues found!', 'vigilante' ),
1516 'criticalConfigTitle' => __( 'Critical config files modified', 'vigilante' ),
1517 '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' ),
1518 'approve' => __( 'Approve', 'vigilante' ),
1519 'approving' => __( 'Approving...', 'vigilante' ),
1520 'criticalApproved' => __( 'Change approved. Next scan will use the current state as baseline.', 'vigilante' ),
1521 'reviewChanges' => __( 'Review changes', 'vigilante' ),
1522 'hideChanges' => __( 'Hide changes', 'vigilante' ),
1523 'changes' => __( 'Changes', 'vigilante' ),
1524 'diffUnavailable' => __( 'Diff not available for this file (baseline was created before diff tracking was added). Approve to enable diff on future changes.', 'vigilante' ),
1525 'diffEmpty' => __( 'No line-level changes detected (may be whitespace or reordering).', 'vigilante' ),
1526 'diffLines' => __( 'lines', 'vigilante' ),
1527 // Under Attack mode strings
1528 'underAttackConfirmActivate' => __( 'Activate Under Attack mode? All visitors will see a verification page for the next 4 hours.', 'vigilante' ),
1529 'underAttackConfirmDeactivate' => __( 'Deactivate Under Attack mode?', 'vigilante' ),
1530 'underAttackActivating' => __( 'Activating...', 'vigilante' ),
1531 'underAttackDeactivating' => __( 'Deactivating...', 'vigilante' ),
1532 // Database backup strings
1533 'dbBackupDownloading' => __( 'Generating backup...', 'vigilante' ),
1534 'dbBackupNoTables' => __( 'Please select at least one table.', 'vigilante' ),
1535 'dbBackupSuccess' => __( 'Database backup downloaded successfully.', 'vigilante' ),
1536 // Firewall unblock
1537 'confirmUnblockIp' => __( 'Unblock this IP from firewall rate limiting?', 'vigilante' ),
1538 // Database prefix strings
1539 'dbPrefixConfirm' => __( 'This operation will change your database prefix. It is irreversible. Make sure you have a current database backup before proceeding.', 'vigilante' ),
1540 'dbPrefixChanging' => __( 'Changing prefix...', 'vigilante' ),
1541 'dbPrefixSuccess' => __( 'Database prefix changed successfully. The page will reload now.', 'vigilante' ),
1542 'dbPrefixCheckbox' => __( 'You must confirm that you have a database backup.', 'vigilante' ),
1543 /* translators: 1: Hours, 2: Minutes */
1544 'underAttackRemaining' => __( '%1$dh %2$dm remaining', 'vigilante' ),
1545 'underAttackLabel' => __( 'Under Attack', 'vigilante' ),
1546 'standardLabel' => __( 'Standard', 'vigilante' ),
1547 'maximumLabel' => __( 'Maximum Security', 'vigilante' ),
1548 'deactivate' => __( 'Deactivate', 'vigilante' ),
1549 'underAttackActivate' => __( 'Activate for 4 hours', 'vigilante' ),
1550 // Settings strings
1551 'saveSettings' => __( 'Save Settings', 'vigilante' ),
1552 'settingsResetDefaults' => __( 'Settings reset to defaults.', 'vigilante' ),
1553 'confirmOverwrite' => __( 'This will overwrite your current settings.', 'vigilante' ),
1554 'importFailed' => __( 'Could not import settings. Check the file and try again.', 'vigilante' ),
1555 /* translators: 1: tests passed, 2: total tests in this category */
1556 'testsCounter' => __( '%1$d/%2$d tests', 'vigilante' ),
1557 'confirmResetAll' => __( 'This will reset ALL settings to defaults.', 'vigilante' ),
1558 'couldNotDetermineSection' => __( 'Could not determine section.', 'vigilante' ),
1559 'confirmResetSection' => __( 'Reset this section to default values? This cannot be undone.', 'vigilante' ),
1560 'sectionResetDefaults' => __( 'Section reset to defaults.', 'vigilante' ),
1561 /* translators: %s: preset name */
1562 'confirmApplyPreset' => __( 'Apply the "%s" preset?', 'vigilante' ),
1563 // Scan strings
1564 'scanFailed' => __( 'Scan failed', 'vigilante' ),
1565 /* translators: %s: error message */
1566 'scanError' => __( 'Scan error: %s', 'vigilante' ),
1567 'runScanNow' => __( 'Run Scan Now', 'vigilante' ),
1568 'confirmClearScan' => __( 'Are you sure you want to clear all scan results?', 'vigilante' ),
1569 'clearing' => __( 'Clearing...', 'vigilante' ),
1570 'scanResultsCleared' => __( 'Scan results cleared. Page will reload...', 'vigilante' ),
1571 'failedClearResults' => __( 'Failed to clear results', 'vigilante' ),
1572 /* translators: %s: error message */
1573 'ajaxError' => __( 'AJAX Error: %s', 'vigilante' ),
1574 // Activity log popup strings
1575 'logRequest' => __( 'Request', 'vigilante' ),
1576 'logDate' => __( 'Date', 'vigilante' ),
1577 'logMethod' => __( 'Method', 'vigilante' ),
1578 'logType' => __( 'Type', 'vigilante' ),
1579 'logAction' => __( 'Action', 'vigilante' ),
1580 'logSeverity' => __( 'Severity', 'vigilante' ),
1581 'logMessage' => __( 'Message', 'vigilante' ),
1582 'logRequestUri' => __( 'Address', 'vigilante' ),
1583 'logClient' => __( 'Client', 'vigilante' ),
1584 'logUser' => __( 'User', 'vigilante' ),
1585 'logIpAddress' => __( 'IP Address', 'vigilante' ),
1586 'logUserAgent' => __( 'User Agent', 'vigilante' ),
1587 'logIpLabel' => __( 'IP:', 'vigilante' ),
1588 'logUaLabel' => __( 'UA:', 'vigilante' ),
1589 'logWhitelist' => __( 'Whitelist', 'vigilante' ),
1590 'logBlacklist' => __( 'Blacklist', 'vigilante' ),
1591 'logInWhitelist' => __( 'In whitelist', 'vigilante' ),
1592 'logInBlacklist' => __( 'In blacklist', 'vigilante' ),
1593 'logAdded' => __( 'Added!', 'vigilante' ),
1594 'logErrorAddingToList' => __( 'Error adding to list', 'vigilante' ),
1595 'logRequestFailed' => __( 'Request failed', 'vigilante' ),
1596 // Activity log table strings
1597 'noLogEntries' => __( 'No log entries found.', 'vigilante' ),
1598 'view' => __( 'View', 'vigilante' ),
1599 'confirmClearLogs' => __( 'This will delete all audit logs.', 'vigilante' ),
1600 // Export logs strings
1601 'exporting' => __( 'Exporting...', 'vigilante' ),
1602 /* translators: %d: number of entries */
1603 'logsExported' => __( 'Logs exported (%d entries)', 'vigilante' ),
1604 'noLogsToExport' => __( 'No logs to export', 'vigilante' ),
1605 'exportFailed' => __( 'Export failed', 'vigilante' ),
1606 'exportLogs' => __( 'Export Logs', 'vigilante' ),
1607 // Backup strings
1608 'backupCreated' => __( 'Backup created successfully.', 'vigilante' ),
1609 'createBackupNow' => __( 'Download Backup', 'vigilante' ),
1610 'downloadBackup' => __( 'Download Backup (.zip)', 'vigilante' ),
1611 /* translators: %d: number of tables */
1612 'tablesCount' => __( '%d tables', 'vigilante' ),
1613 /* translators: 1: table count, 2: human-readable size */
1614 'dbTablesTotal' => __( '%1$d tables total (%2$s)', 'vigilante' ),
1615 /* translators: 1: selected count, 2: human-readable size */
1616 'dbTablesSelected' => __( '%1$d tables selected (%2$s)', 'vigilante' ),
1617 // Settings search strings
1618 'searchNoResults' => __( 'No matching settings found.', 'vigilante' ),
1619 /* translators: %d: number of results that did not fit in the list. */
1620 'searchMoreResults' => __( '%d more results. Refine the search to see them.', 'vigilante' ),
1621 'searchInTab' => __( 'in', 'vigilante' ),
1622 // Modules string
1623 /* translators: 1: enabled count, 2: total count */
1624 'modulesEnabled' => __( '%1$d / %2$d modules enabled', 'vigilante' ),
1625 // Activity log label maps for JS rendering
1626 'eventTypeLabels' => array(
1627 'login' => __( 'Login', 'vigilante' ),
1628 'user' => __( 'User', 'vigilante' ),
1629 'content' => __( 'Content', 'vigilante' ),
1630 'plugin' => __( 'Plugin', 'vigilante' ),
1631 'theme' => __( 'Theme', 'vigilante' ),
1632 'settings' => __( 'Settings', 'vigilante' ),
1633 'comment' => __( 'Comment', 'vigilante' ),
1634 'media' => __( 'Media', 'vigilante' ),
1635 'firewall' => __( 'Firewall', 'vigilante' ),
1636 'file' => __( 'File', 'vigilante' ),
1637 'security' => __( 'Security', 'vigilante' ),
1638 'system' => __( 'System', 'vigilante' ),
1639 ),
1640 'severityLabels' => array(
1641 'info' => __( 'Info', 'vigilante' ),
1642 'warning' => __( 'Warning', 'vigilante' ),
1643 'critical' => __( 'Critical', 'vigilante' ),
1644 ),
1645 // Password reset strings
1646 'noUsersFoundSearch' => __( 'No users found', 'vigilante' ),
1647 /* translators: %d: number of users */
1648 'confirmForceReset' => __( 'Force password reset for %d user(s)? A password reset email will be sent to each user.', 'vigilante' ),
1649 'warningResettingSelf' => __( 'WARNING: You are including yourself. Your session will end and you will need to set a new password.', 'vigilante' ),
1650 'processing' => __( 'Processing...', 'vigilante' ),
1651 'anErrorOccurred' => __( 'An error occurred', 'vigilante' ),
1652 'forceResetSelected' => __( 'Force Reset for Selected Users', 'vigilante' ),
1653 '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' ),
1654 'warningResettingSelfAll' => __( 'WARNING: You are including yourself. Your session will end immediately.', 'vigilante' ),
1655 'forceResetAll' => __( 'Force Reset for ALL Users', 'vigilante' ),
1656 // Role-based password reset strings
1657 /* translators: %d: number of users */
1658 'confirmForceResetByRole' => __( 'Force password reset for %d user(s) with the selected roles? A password reset email will be sent to each user.', 'vigilante' ),
1659 'noRolesSelected' => __( 'Please select at least one role.', 'vigilante' ),
1660 'forceResetByRole' => __( 'Force Reset for Selected Roles', 'vigilante' ),
1661 // User approval strings
1662 'confirmApprove' => __( 'Approve this user?', 'vigilante' ),
1663 'approve' => __( 'Approve', 'vigilante' ),
1664 'rejectReason' => __( 'Enter rejection reason (optional):', 'vigilante' ),
1665 'reject' => __( 'Reject', 'vigilante' ),
1666 'noPending' => __( 'No pending registrations.', 'vigilante' ),
1667 // Session management strings
1668 'confirmRevoke' => __( 'Revoke this session?', 'vigilante' ),
1669 'confirmRevokeAll' => __( 'Revoke all other sessions?', 'vigilante' ),
1670 'revokeOthers' => __( 'Revoke All Other Sessions', 'vigilante' ),
1671 'confirmRevokeAllUser' => __( 'Revoke ALL sessions for this user? They will be logged out everywhere.', 'vigilante' ),
1672 'sessionsFor' => __( 'Sessions for:', 'vigilante' ),
1673 'noSessions' => __( 'No active sessions', 'vigilante' ),
1674 'revoke' => __( 'Revoke', 'vigilante' ),
1675 'noUsers' => __( 'No users found', 'vigilante' ),
1676 // Time ago strings
1677 'timeYear' => __( 'year', 'vigilante' ),
1678 'timeYears' => __( 'years', 'vigilante' ),
1679 'timeMonth' => __( 'month', 'vigilante' ),
1680 'timeMonths' => __( 'months', 'vigilante' ),
1681 'timeDay' => __( 'day', 'vigilante' ),
1682 'timeDays' => __( 'days', 'vigilante' ),
1683 'timeHour' => __( 'hour', 'vigilante' ),
1684 'timeHours' => __( 'hours', 'vigilante' ),
1685 'timeMinute' => __( 'minute', 'vigilante' ),
1686 'timeMinutes' => __( 'minutes', 'vigilante' ),
1687 /* translators: %1$d: count, %2$s: time unit */
1688 'timeAgo' => __( '%1$d %2$s ago', 'vigilante' ),
1689 'justNow' => __( 'Just now', 'vigilante' ),
1690 // Pagination strings
1691 /* translators: 1: first item number, 2: last item number, 3: total items */
1692 'paginationOf' => __( '%1$d–%2$d of %3$d', 'vigilante' ),
1693 'paginationEmpty' => __( '0 items', 'vigilante' ),
1694 // Security Analyzer strings
1695 'analyzerScanNow' => __( 'Scan now', 'vigilante' ),
1696 'analyzerScanning' => __( 'Scanning…', 'vigilante' ),
1697 'analyzerFastPhase' => __( 'Running fast checks…', 'vigilante' ),
1698 'analyzerSlowPhase' => __( 'Running remote checks…', 'vigilante' ),
1699 'analyzerScanComplete' => __( 'Security scan complete.', 'vigilante' ),
1700 'analyzerScanFailed' => __( 'Security scan failed.', 'vigilante' ),
1701 'analyzerShowDetails' => __( 'Show detailed breakdown', 'vigilante' ),
1702 'analyzerHideDetails' => __( 'Hide detailed breakdown', 'vigilante' ),
1703 'analyzerGoToSetting' => __( 'Go to setting', 'vigilante' ),
1704 'analyzerNoData' => __( 'No data yet — run a scan to populate this category.', 'vigilante' ),
1705 'analyzerJustNow' => __( 'just now', 'vigilante' ),
1706 'analyzerAgo' => __( 'ago', 'vigilante' ),
1707 'analyzerSettingsSaved' => __( 'Analyzer settings saved.', 'vigilante' ),
1708 'analyzerLastScanJustNow' => __( 'Last scan just now', 'vigilante' ),
1709 'analyzerQualityExcellent' => __( 'Excellent', 'vigilante' ),
1710 'analyzerQualityGood' => __( 'Good', 'vigilante' ),
1711 'analyzerQualityFair' => __( 'Fair', 'vigilante' ),
1712 'analyzerQualityPoor' => __( 'Poor', 'vigilante' ),
1713 'analyzerQualityCritical' => __( 'Critical', 'vigilante' ),
1714 'analyzerPts' => __( 'pts', 'vigilante' ),
1715 'analyzerLearnMore' => __( 'Learn more', 'vigilante' ),
1716 'analyzerInfoAllClear' => __( 'All clear', 'vigilante' ),
1717 /* translators: %d: number of findings in an info-only category */
1718 'analyzerInfoFindings' => __( '%d findings', 'vigilante' ),
1719 ),
1720 ) );
1721
1722 // 2FA Admin assets
1723 wp_enqueue_style(
1724 'vigilante-2fa-admin',
1725 VIGILANTE_ASSETS_URL . 'css/two-factor-admin.css',
1726 array( 'vigilante-admin' ),
1727 VIGILANTE_VERSION
1728 );
1729
1730 wp_enqueue_script(
1731 'vigilante-2fa-admin',
1732 VIGILANTE_ASSETS_URL . 'js/two-factor-admin.js',
1733 array( 'jquery', 'vigilante-admin' ),
1734 VIGILANTE_VERSION,
1735 true
1736 );
1737 }
1738
1739 /**
1740 * Show admin notices
1741 */
1742 public function show_admin_notices() {
1743 // Activation notice
1744 if ( get_transient( 'vigilante_activated' ) ) {
1745 ?>
1746 <div class="notice notice-success is-dismissible vigilante-activation-notice">
1747 <p>
1748 <span class="dashicons dashicons-shield vigilante-notice-icon"></span>
1749 <strong><?php esc_html_e( 'Vigilant activated successfully!', 'vigilante' ); ?></strong>
1750 <?php esc_html_e( 'Security protection is now active.', 'vigilante' ); ?>
1751 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante' ) ); ?>">
1752 <?php esc_html_e( 'Configure settings', 'vigilante' ); ?>
1753 </a>
1754 </p>
1755 </div>
1756 <?php
1757 delete_transient( 'vigilante_activated' );
1758 }
1759
1760 // Under Attack mode notice (non-dismissible, shown on all admin pages)
1761 $ua_status = get_option( Vigilante_Under_Attack::OPTION_NAME, array() );
1762 if ( ! empty( $ua_status['active'] ) ) {
1763 $ua_remaining = ( $ua_status['activated_at'] + $ua_status['duration'] ) - time();
1764 if ( $ua_remaining > 0 ) {
1765 $ua_hours = floor( $ua_remaining / 3600 );
1766 $ua_mins = floor( ( $ua_remaining % 3600 ) / 60 );
1767 $dashboard_url = admin_url( 'admin.php?page=vigilante' );
1768 ?>
1769 <div class="notice notice-warning vigilante-ua-notice">
1770 <p>
1771 <span class="dashicons dashicons-shield"></span>
1772 <strong><?php esc_html_e( 'Under Attack mode is active', 'vigilante' ); ?></strong>
1773 &mdash;
1774 <?php
1775 printf(
1776 /* translators: 1: Hours, 2: Minutes */
1777 esc_html__( '%1$dh %2$dm remaining.', 'vigilante' ),
1778 absint( $ua_hours ),
1779 absint( $ua_mins )
1780 );
1781 ?>
1782 <a href="<?php echo esc_url( $dashboard_url ); ?>">
1783 <?php esc_html_e( 'Go to Vigilant dashboard', 'vigilante' ); ?>
1784 </a>
1785 </p>
1786 <p>
1787 <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>
1788 </p>
1789 <?php
1790 // The cache-bypass rules could not be written (a host where
1791 // WordPress cannot write files by itself, a held lock, a
1792 // failed read-back): show them, so they can be added by hand.
1793 $ua_instance = new Vigilante_Under_Attack( $this->settings, $this->activity_log );
1794 if ( $ua_instance->cache_rules_missing() ) :
1795 ?>
1796 <p>
1797 <strong><?php esc_html_e( 'The cache-bypass rules could not be written to your .htaccess.', 'vigilante' ); ?></strong>
1798 <?php esc_html_e( 'Without them a page cache may keep serving stored pages during the attack. Add this block at the top of the .htaccess in your site root (the activity log records why it was not written):', 'vigilante' ); ?>
1799 </p>
1800 <textarea readonly rows="9" class="large-text code" onclick="this.select();"><?php echo esc_textarea( Vigilante_Under_Attack::get_cache_bypass_block() ); ?></textarea>
1801 <?php endif; ?>
1802 </div>
1803 <?php
1804 }
1805 }
1806
1807 // Proxy/CDN detection: if IP detection is set to "direct" but requests
1808 // arrive with a forwarded-for header carrying a different valid IP, the
1809 // site is very likely behind a proxy/CDN that has not been declared, so
1810 // the firewall is seeing the proxy IP for every visitor. Guide the admin.
1811 //
1812 // Two deliberate silencers (2.9.2):
1813 // - A loopback forwarded IP (::1 / 127.x) means the person browsing IS
1814 // the machine itself: that only happens in local development stacks
1815 // (Local's nginx router, Docker...), never behind a production
1816 // proxy/CDN, so the notice would be pure noise there.
1817 // - The notice is dismissible and the dismissal persists site-wide via
1818 // the vigilante_dismissed_notices option (the admin evaluated it and
1819 // decided; nagging forever helps nobody).
1820 $dismissed_notices = get_option( 'vigilante_dismissed_notices', array() );
1821 if (
1822 current_user_can( 'manage_options' )
1823 && '' === Vigilante_IP_Utils::trusted_proxy_header()
1824 && ! isset( $dismissed_notices['proxy_detection'] )
1825 ) {
1826 $remote = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '';
1827 $detected = '';
1828 foreach ( Vigilante_IP_Utils::trusted_header_map() as $proxy_label => $server_key ) {
1829 if ( empty( $_SERVER[ $server_key ] ) ) {
1830 continue;
1831 }
1832 $candidate = sanitize_text_field( wp_unslash( $_SERVER[ $server_key ] ) );
1833 if ( false !== strpos( $candidate, ',' ) ) {
1834 $parts = explode( ',', $candidate );
1835 $candidate = trim( $parts[0] );
1836 }
1837 if ( ! filter_var( $candidate, FILTER_VALIDATE_IP ) || $candidate === $remote ) {
1838 continue;
1839 }
1840 // Loopback forwarded IP = local development, not a real proxy.
1841 if ( '::1' === $candidate || 0 === strpos( $candidate, '127.' ) ) {
1842 continue;
1843 }
1844 $detected = $proxy_label;
1845 break;
1846 }
1847
1848 if ( '' !== $detected ) {
1849 $firewall_url = admin_url( 'admin.php?page=vigilante&tab=firewall' );
1850 $detail_message = sprintf(
1851 /* translators: %s: detected forwarded header name wrapped in a code tag. */
1852 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' ),
1853 '<code>' . esc_html( strtoupper( $detected ) ) . '</code>'
1854 );
1855 ?>
1856 <div class="notice notice-warning is-dismissible vigilante-proxy-notice">
1857 <p>
1858 <span class="dashicons dashicons-shield"></span>
1859 <strong><?php esc_html_e( 'Vigilant: this site looks like it is behind a proxy or CDN', 'vigilante' ); ?></strong>
1860 </p>
1861 <p><?php echo wp_kses_post( $detail_message ); ?></p>
1862 <p>
1863 <a href="<?php echo esc_url( $firewall_url ); ?>" class="button button-secondary">
1864 <?php esc_html_e( 'Set your proxy in Firewall settings', 'vigilante' ); ?>
1865 </a>
1866 </p>
1867 </div>
1868 <script>
1869 jQuery( function ( $ ) {
1870 $( document ).on( 'click', '.vigilante-proxy-notice .notice-dismiss', function () {
1871 $.post( ajaxurl, {
1872 action: 'vigilante_dismiss_notice',
1873 notice_id: 'proxy_detection',
1874 nonce: <?php echo wp_json_encode( wp_create_nonce( 'vigilante_dismiss_notice' ) ); ?>
1875 } );
1876 } );
1877 } );
1878 </script>
1879 <?php
1880 }
1881 }
1882 }
1883
1884 /**
1885 * Render settings page
1886 */
1887 public function render_settings_page() {
1888 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
1889 $this->current_tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'dashboard';
1890
1891 if ( ! array_key_exists( $this->current_tab, $this->tabs ) ) {
1892 $this->current_tab = 'dashboard';
1893 }
1894 ?>
1895 <div class="wrap vigilante-admin-wrap">
1896 <div class="vigilante-header-row">
1897 <h1 class="vigilante-page-title">
1898 <img src="<?php echo esc_url( VIGILANTE_ASSETS_URL . 'images/icon.png' ); ?>" alt="Vigilante" class="vigilante-title-icon">
1899 <?php esc_html_e( 'Vigilant', 'vigilante' ); ?>
1900 <span class="vigilante-version">v<?php echo esc_html( VIGILANTE_VERSION ); ?></span>
1901 </h1>
1902 <div class="vigilante-search-wrapper">
1903 <div class="vigilante-search-input-wrap">
1904 <span class="vigilante-search-icon dashicons dashicons-search" aria-hidden="true"></span>
1905 <input type="search" id="vigilante-settings-search" class="vigilante-settings-search" aria-label="<?php esc_attr_e( 'Search settings', 'vigilante' ); ?>" placeholder="<?php esc_attr_e( 'Search settings…', 'vigilante' ); ?>" autocomplete="off">
1906 <span class="vigilante-search-shortcut" aria-hidden="true">/</span>
1907 </div>
1908 <div id="vigilante-settings-search-results" class="vigilante-search-results" hidden role="listbox"></div>
1909 </div>
1910 </div>
1911
1912 <?php $this->render_tabs(); ?>
1913
1914 <div class="vigilante-content">
1915 <div class="vigilante-main">
1916 <?php $this->render_tab_content(); ?>
1917 </div>
1918 <div class="vigilante-sidebar">
1919 <?php $this->render_sidebar(); ?>
1920 </div>
1921 </div>
1922 </div>
1923 <?php
1924 }
1925
1926 /**
1927 * Render tabs navigation
1928 */
1929 private function render_tabs() {
1930 $options = $this->settings->get_all_options();
1931
1932 // Map tabs to modules
1933 $tab_to_module = array(
1934 'firewall' => 'firewall',
1935 'headers' => 'security_headers',
1936 'login' => 'login_security',
1937 'rest-api' => 'rest_api_security',
1938 'users' => 'user_security',
1939 'wp-hardening' => 'wp_hardening',
1940 'file-integrity' => 'file_integrity',
1941 'activity-log' => 'activity_log',
1942 );
1943 ?>
1944 <nav class="nav-tab-wrapper vigilante-nav-tabs">
1945 <?php foreach ( $this->tabs as $tab_id => $tab_name ) :
1946 $is_disabled = false;
1947 $module = isset( $tab_to_module[ $tab_id ] ) ? $tab_to_module[ $tab_id ] : null;
1948 if ( $module && empty( $options['modules'][ $module ] ) ) {
1949 $is_disabled = true;
1950 }
1951 ?>
1952 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=' . $tab_id ) ); ?>"
1953 class="nav-tab <?php echo $this->current_tab === $tab_id ? 'nav-tab-active' : ''; ?> <?php echo $is_disabled ? 'vigilante-tab-disabled' : ''; ?>"
1954 <?php if ( $is_disabled ) : ?>title="<?php esc_attr_e( 'Module Disabled', 'vigilante' ); ?>"<?php endif; ?>>
1955 <?php echo esc_html( $tab_name ); ?>
1956 <?php if ( $is_disabled ) : ?><span class="vigilante-tab-off">OFF</span><?php endif; ?>
1957 </a>
1958 <?php endforeach; ?>
1959 </nav>
1960 <?php
1961 }
1962
1963 /**
1964 * Render current tab content
1965 */
1966 private function render_tab_content() {
1967 $method = 'render_tab_' . str_replace( '-', '_', $this->current_tab );
1968
1969 if ( method_exists( $this, $method ) ) {
1970 $this->$method();
1971 } else {
1972 $this->render_tab_coming_soon();
1973 }
1974 }
1975
1976 /**
1977 * Render coming soon placeholder
1978 */
1979 private function render_tab_coming_soon() {
1980 ?>
1981 <div class="vigilante-settings-section">
1982 <h2><?php esc_html_e( 'Coming Soon', 'vigilante' ); ?></h2>
1983 <p><?php esc_html_e( 'This section is under development.', 'vigilante' ); ?></p>
1984 </div>
1985 <?php
1986 }
1987
1988 /**
1989 * Values to display for a section that this site does not control
1990 *
1991 * On a subsite the stored options are its own copy, which nothing acts on:
1992 * wp-config.php and .htaccess are written from the main site. Painting the
1993 * local copy describes a configuration that is not running, so a subsite
1994 * admin sees a box ticked here and the constant absent from the file, or the
1995 * other way round. Read the main site's values instead, which are the ones in
1996 * force, and fall back to the local ones if they cannot be read.
1997 *
1998 * @since 2.9.8
1999 *
2000 * @param string $section Settings section.
2001 * @return array
2002 */
2003 private function get_section_for_display( $section ) {
2004 $local = $this->settings->get_section( $section );
2005
2006 if ( ! $this->shared_files_locked() ) {
2007 return $local;
2008 }
2009
2010 // shared_files_locked() is only true on multisite, where get_blog_option() exists.
2011 $main = get_blog_option( get_main_site_id(), Vigilante_Settings::OPTION_NAME, array() );
2012
2013 if ( ! is_array( $main ) || empty( $main[ $section ] ) || ! is_array( $main[ $section ] ) ) {
2014 return $local;
2015 }
2016
2017 return wp_parse_args( $main[ $section ], $local );
2018 }
2019
2020 /**
2021 * Whether the sections that write wp-config.php and .htaccess are read-only here
2022 *
2023 * True on a network when this is not the main site, or the user is not a
2024 * network administrator. See Vigilante_Settings::can_write_shared_files().
2025 *
2026 * @since 2.9.8
2027 *
2028 * @return bool
2029 */
2030 private function shared_files_locked() {
2031 return ! Vigilante_Settings::can_write_shared_files();
2032 }
2033
2034 /**
2035 * Print the shared-files notice for a section that cannot be edited here
2036 *
2037 * @since 2.9.8
2038 */
2039 private function render_shared_files_notice() {
2040 if ( ! $this->shared_files_locked() ) {
2041 return;
2042 }
2043 ?>
2044 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
2045 <p style="margin:0;"><?php echo esc_html( Vigilante_Settings::get_shared_files_notice() ); ?></p>
2046 </div>
2047 <?php
2048 }
2049
2050 /**
2051 * Acting on another user's account needs permission over that user
2052 *
2053 * Since 2.10.3 the handlers behind these tools ask for edit_user over the
2054 * target, which is the rule WordPress itself applies. On a network the core
2055 * grants edit_user only to network administrators, so for anybody else these
2056 * controls do nothing. Better to say so than to paint a button that silently
2057 * skips every user.
2058 *
2059 * @since 2.10.4
2060 * @return bool
2061 */
2062 private function user_actions_locked() {
2063 return is_multisite() && ! current_user_can( 'manage_network_users' );
2064 }
2065
2066 /**
2067 * Print the notice for user tools that cannot be used from this site
2068 *
2069 * @since 2.10.4
2070 */
2071 private function render_user_actions_notice() {
2072 if ( ! $this->user_actions_locked() ) {
2073 return;
2074 }
2075 ?>
2076 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
2077 <p style="margin:0;"><?php esc_html_e( 'These tools act on user accounts, which on a network belong to the whole network rather than to one site. WordPress reserves that to network administrators, so they are managed from the network admin.', 'vigilante' ); ?></p>
2078 </div>
2079 <?php
2080 }
2081
2082 /**
2083 * Check if module is disabled and render warning
2084 *
2085 * @param string $module_key Module key.
2086 * @return bool True if disabled.
2087 */
2088 private function render_module_disabled_notice( $module_key ) {
2089 if ( $this->settings->is_module_enabled( $module_key ) ) {
2090 return false;
2091 }
2092
2093 $module_labels = $this->settings->get_module_labels();
2094 $module_name = isset( $module_labels[ $module_key ] ) ? $module_labels[ $module_key ] : $module_key;
2095 ?>
2096 <div class="notice notice-warning vigilante-module-disabled-notice">
2097 <p>
2098 <strong><?php esc_html_e( 'Module Disabled', 'vigilante' ); ?></strong> -
2099 <?php
2100 printf(
2101 /* translators: %s: Module name */
2102 esc_html__( 'The %s module is currently disabled. Enable it from the Dashboard to use these settings.', 'vigilante' ),
2103 esc_html( $module_name )
2104 );
2105 ?>
2106 </p>
2107 <p>
2108 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=dashboard' ) ); ?>" class="button">
2109 <?php esc_html_e( 'Go to Dashboard', 'vigilante' ); ?>
2110 </a>
2111 </p>
2112 </div>
2113 <?php
2114 return true;
2115 }
2116
2117 /**
2118 * Render the Security Analyzer (Security Check) widget + expandable full report.
2119 *
2120 * Lives in the Dashboard tab between the Configuration Score status card and
2121 * the modules grid. Uses the last persisted scan to hydrate server-side so the
2122 * first paint shows real data; "Scan now" runs the 2-phase AJAX to refresh.
2123 *
2124 * @param array $last_scan Result of Vigilante_Security_Analyzer::get_last_scan().
2125 * @param array $history Score history (oldest first).
2126 * @param array $categories_def Category metadata (slug => label/max).
2127 * @param array $analyzer_settings Settings subsection for weekly cron + email.
2128 */
2129 private function render_analyzer_widget( $last_scan, $history, $categories_def, $analyzer_settings ) {
2130 $has_data = ! empty( $last_scan['ran_at'] );
2131 $score = isset( $last_scan['score'] ) ? (int) $last_scan['score'] : 0;
2132 $grade = isset( $last_scan['grade'] ) ? (string) $last_scan['grade'] : '';
2133 $counts = isset( $last_scan['counts'] ) && is_array( $last_scan['counts'] ) ? $last_scan['counts'] : array();
2134 $ran_at_human = $has_data
2135 ? sprintf(
2136 /* translators: %s: relative time like "2 hours" */
2137 __( 'Last scan %s ago', 'vigilante' ),
2138 human_time_diff( (int) $last_scan['ran_at'], time() )
2139 )
2140 : __( 'Never scanned', 'vigilante' );
2141 $categories = isset( $last_scan['categories'] ) && is_array( $last_scan['categories'] ) ? $last_scan['categories'] : array();
2142 $weekly_enabled = ! isset( $analyzer_settings['weekly_scan_enabled'] ) || ! empty( $analyzer_settings['weekly_scan_enabled'] );
2143 $email_enabled = ! empty( $analyzer_settings['email_on_regression'] );
2144
2145 $quality = self::analyzer_quality_tag( $score );
2146 ?>
2147 <div class="vigilante-analyzer" id="vigilante-analyzer"
2148 data-has-data="<?php echo $has_data ? '1' : '0'; ?>">
2149 <div class="vigilante-analyzer-header">
2150 <div class="vigilante-analyzer-title">
2151 <h2>
2152 <span class="dashicons dashicons-shield-alt" aria-hidden="true"></span>
2153 <?php esc_html_e( 'Security Check', 'vigilante' ); ?>
2154 </h2>
2155 <p class="description">
2156 <?php esc_html_e( 'On-demand audit of what an attacker would see right now, plus 13 internal checks impossible from the outside.', 'vigilante' ); ?>
2157 </p>
2158 <p class="vigilante-analyzer-last-scan" data-role="ran-at">
2159 <span class="dashicons dashicons-clock" aria-hidden="true"></span>
2160 <?php echo esc_html( $ran_at_human ); ?>
2161 </p>
2162 </div>
2163 <div class="vigilante-analyzer-actions">
2164 <button type="button" class="button button-primary" id="vigilante-analyzer-scan">
2165 <span class="dashicons dashicons-update" aria-hidden="true"></span>
2166 <?php esc_html_e( 'Scan now', 'vigilante' ); ?>
2167 </button>
2168 </div>
2169 </div>
2170
2171 <div class="vigilante-analyzer-summary">
2172 <div class="vigilante-analyzer-score-card">
2173 <?php if ( $has_data && $grade ) : ?>
2174 <div class="vigilante-score-circle vigilante-grade-<?php echo esc_attr( strtolower( $grade ) ); ?>">
2175 <span class="vigilante-grade"><?php echo esc_html( $grade ); ?></span>
2176 <span class="vigilante-score-text"><?php echo esc_html( $score ); ?>%</span>
2177 </div>
2178 <?php else : ?>
2179 <div class="vigilante-score-circle vigilante-grade-empty">
2180 <span class="vigilante-grade">—</span>
2181 <span class="vigilante-score-text"><?php esc_html_e( 'N/A', 'vigilante' ); ?></span>
2182 </div>
2183 <?php endif; ?>
2184 <div class="vigilante-analyzer-score-meta">
2185 <p class="vigilante-analyzer-score-label">
2186 <?php esc_html_e( 'Security Score', 'vigilante' ); ?>
2187 </p>
2188 <span class="vigilante-analyzer-quality-tag vigilante-analyzer-quality-<?php echo esc_attr( $quality['slug'] ); ?>"
2189 data-role="quality-tag">
2190 <?php echo esc_html( $quality['label'] ); ?>
2191 </span>
2192 </div>
2193 </div>
2194
2195 <div class="vigilante-analyzer-counts">
2196 <span class="vigilante-analyzer-count vigilante-analyzer-count--pass">
2197 <span class="dashicons dashicons-yes-alt" aria-hidden="true"></span>
2198 <strong data-role="pass"><?php echo esc_html( isset( $counts['pass'] ) ? $counts['pass'] : 0 ); ?></strong>
2199 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Passed', 'vigilante' ); ?></span>
2200 </span>
2201 <span class="vigilante-analyzer-count vigilante-analyzer-count--warn">
2202 <span class="dashicons dashicons-warning" aria-hidden="true"></span>
2203 <strong data-role="warn"><?php echo esc_html( isset( $counts['warn'] ) ? $counts['warn'] : 0 ); ?></strong>
2204 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Warnings', 'vigilante' ); ?></span>
2205 </span>
2206 <span class="vigilante-analyzer-count vigilante-analyzer-count--fail">
2207 <span class="dashicons dashicons-dismiss" aria-hidden="true"></span>
2208 <strong data-role="fail"><?php echo esc_html( isset( $counts['fail'] ) ? $counts['fail'] : 0 ); ?></strong>
2209 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Failing', 'vigilante' ); ?></span>
2210 </span>
2211 </div>
2212
2213 <?php
2214 // Sparkline of recent scores. Require at least 3 data points so the trend
2215 // is meaningful (2 points is just a line between dots, no real trend).
2216 $hist_points = array();
2217 foreach ( $history as $h ) {
2218 $hist_points[] = (int) $h['score'];
2219 }
2220 $hist_count = count( $hist_points );
2221 if ( $hist_count >= 3 ) :
2222 $current_score = (int) end( $hist_points );
2223 $previous_score = (int) $hist_points[ $hist_count - 2 ];
2224 $delta = $current_score - $previous_score;
2225 $delta_class = $delta > 0 ? 'vigilante-analyzer-delta--up' : ( $delta < 0 ? 'vigilante-analyzer-delta--down' : 'vigilante-analyzer-delta--flat' );
2226 $delta_icon = $delta > 0 ? 'arrow-up-alt' : ( $delta < 0 ? 'arrow-down-alt' : 'minus' );
2227 if ( 0 === $delta ) {
2228 $delta_text = __( 'No change', 'vigilante' );
2229 } else {
2230 $delta_text = sprintf(
2231 /* translators: %s: signed delta, e.g. "+3" or "-5" */
2232 _n( '%s pt vs. previous scan', '%s pts vs. previous scan', abs( $delta ), 'vigilante' ),
2233 ( $delta > 0 ? '+' : '' ) . (int) $delta
2234 );
2235 }
2236 ?>
2237 <div class="vigilante-analyzer-sparkline-wrap">
2238 <div class="vigilante-analyzer-sparkline-head">
2239 <span class="vigilante-analyzer-sparkline-label">
2240 <?php
2241 echo esc_html( sprintf(
2242 /* translators: %d: number of scans */
2243 _n( 'Score trend (last %d scan)', 'Score trend (last %d scans)', $hist_count, 'vigilante' ),
2244 $hist_count
2245 ) );
2246 ?>
2247 </span>
2248 <span class="vigilante-analyzer-delta <?php echo esc_attr( $delta_class ); ?>">
2249 <span class="dashicons dashicons-<?php echo esc_attr( $delta_icon ); ?>" aria-hidden="true"></span>
2250 <?php echo esc_html( $delta_text ); ?>
2251 </span>
2252 </div>
2253 <div class="vigilante-analyzer-sparkline" data-role="sparkline"
2254 data-points="<?php echo esc_attr( wp_json_encode( $hist_points ) ); ?>">
2255 <?php echo self::sparkline_svg( $hist_points ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Safe SVG from helper ?>
2256 </div>
2257 </div>
2258 <?php elseif ( $has_data ) : ?>
2259 <div class="vigilante-analyzer-sparkline-wrap vigilante-analyzer-sparkline-wrap--placeholder">
2260 <span class="vigilante-analyzer-sparkline-label">
2261 <?php esc_html_e( 'Score trend', 'vigilante' ); ?>
2262 </span>
2263 <p class="vigilante-analyzer-sparkline-hint">
2264 <span class="dashicons dashicons-chart-line" aria-hidden="true"></span>
2265 <?php
2266 $needed = 3 - $hist_count;
2267 echo esc_html( sprintf(
2268 /* translators: %d: number of additional scans needed */
2269 _n( '%d more scan needed to show a trend.', '%d more scans needed to show a trend.', $needed, 'vigilante' ),
2270 $needed
2271 ) );
2272 ?>
2273 </p>
2274 </div>
2275 <?php endif; ?>
2276 </div>
2277
2278 <div class="vigilante-analyzer-toggle-row">
2279 <button type="button" class="button-link vigilante-analyzer-toggle" aria-expanded="false">
2280 <?php esc_html_e( 'Show detailed breakdown', 'vigilante' ); ?>
2281 <span class="vigilante-analyzer-toggle-chevron" aria-hidden="true"></span>
2282 </button>
2283 </div>
2284
2285 <div class="vigilante-analyzer-details" hidden>
2286 <div class="vigilante-analyzer-categories" data-role="categories">
2287 <?php foreach ( $categories_def as $slug => $meta ) :
2288 $cat = isset( $categories[ $slug ] ) ? $categories[ $slug ] : array();
2289 $earned = isset( $cat['earned'] ) ? (int) $cat['earned'] : 0;
2290 // Always use the declared meta as the source of truth for the maximum.
2291 // The cached scan may carry an old max if a check was added/removed
2292 // between releases (see 2.6.1: closed_plugins raised internal from 22 to 28
2293 // but cached scans still reported max=22 until reset).
2294 $cat_max = (int) $meta['max'];
2295 $info_only = ! empty( $meta['info_only'] ) || 0 === (int) $meta['max'];
2296 $cat_pct = $cat_max > 0 ? (int) round( ( $earned / $cat_max ) * 100 ) : 0;
2297 $checks = isset( $cat['checks'] ) ? (array) $cat['checks'] : array();
2298 $cat_counts = isset( $cat['counts'] ) && is_array( $cat['counts'] ) ? $cat['counts'] : array( 'pass' => 0, 'warn' => 0, 'fail' => 0, 'info' => 0 );
2299 $cat_quality = self::analyzer_quality_tag( $cat_pct );
2300 $info_count = isset( $cat_counts['info'] ) ? (int) $cat_counts['info'] : 0;
2301 ?>
2302 <details class="vigilante-analyzer-category<?php echo $info_only ? ' vigilante-analyzer-category--info' : ''; ?>"
2303 data-category="<?php echo esc_attr( $slug ); ?>"
2304 data-info-only="<?php echo $info_only ? '1' : '0'; ?>">
2305 <summary class="vigilante-analyzer-category-summary">
2306 <span class="vigilante-analyzer-category-chevron" aria-hidden="true"></span>
2307 <span class="vigilante-analyzer-category-label"><?php echo esc_html( $meta['label'] ); ?></span>
2308 <?php if ( $info_only ) : ?>
2309 <span class="vigilante-analyzer-category-quality vigilante-analyzer-quality-info"
2310 data-role="category-quality"
2311 title="<?php esc_attr_e( 'Informational — does not affect the security score.', 'vigilante' ); ?>">
2312 <span class="dashicons dashicons-info-outline" aria-hidden="true"></span>
2313 <?php esc_html_e( 'Informational', 'vigilante' ); ?>
2314 </span>
2315 <?php else :
2316 $passed_count = (int) ( $cat_counts['pass'] ?? 0 );
2317 $scored_total = $passed_count
2318 + (int) ( $cat_counts['warn'] ?? 0 )
2319 + (int) ( $cat_counts['fail'] ?? 0 );
2320 ?>
2321 <span class="vigilante-analyzer-category-quality vigilante-analyzer-quality-<?php echo esc_attr( $cat_quality['slug'] ); ?>"
2322 data-role="category-quality">
2323 <span data-role="category-quality-label"><?php echo esc_html( $cat_quality['label'] ); ?></span>
2324 <span class="vigilante-analyzer-category-quality-sep" aria-hidden="true">·</span>
2325 <span class="vigilante-analyzer-category-tests" data-role="category-tests"
2326 data-passed="<?php echo esc_attr( $passed_count ); ?>"
2327 data-total="<?php echo esc_attr( $scored_total ); ?>">
2328 <?php
2329 echo esc_html( sprintf(
2330 /* translators: 1: tests passed, 2: total tests in this category */
2331 __( '%1$d/%2$d tests', 'vigilante' ),
2332 $passed_count,
2333 $scored_total
2334 ) );
2335 ?>
2336 </span>
2337 </span>
2338 <?php endif; ?>
2339 <?php if ( $info_only ) : ?>
2340 <span class="vigilante-analyzer-category-states" data-role="category-states">
2341 <?php if ( $info_count > 0 ) : ?>
2342 <span class="vigilante-analyzer-category-state vigilante-analyzer-category-state--info" title="<?php esc_attr_e( 'Informational', 'vigilante' ); ?>">
2343 <span data-role="state-info"><?php echo esc_html( $info_count ); ?></span><span class="dashicons dashicons-info-outline" aria-hidden="true"></span>
2344 </span>
2345 <?php endif; ?>
2346 </span>
2347 <?php endif; ?>
2348 <?php if ( ! $info_only ) : ?>
2349 <span class="vigilante-analyzer-category-score">
2350 <span data-role="earned"><?php echo esc_html( $earned ); ?></span><span class="vigilante-analyzer-category-score-sep">/</span><?php echo esc_html( $cat_max ); ?>
2351 <span class="vigilante-analyzer-category-score-unit"><?php esc_html_e( 'pts', 'vigilante' ); ?></span>
2352 </span>
2353 <span class="vigilante-analyzer-category-bar" aria-hidden="true">
2354 <span class="vigilante-analyzer-category-bar-fill vigilante-analyzer-category-bar-fill--<?php echo esc_attr( $cat_quality['slug'] ); ?>"
2355 style="width: <?php echo esc_attr( $cat_pct ); ?>%"
2356 data-role="category-bar"></span>
2357 </span>
2358 <?php else :
2359 $info_warn = isset( $cat_counts['warn'] ) ? (int) $cat_counts['warn'] : 0;
2360 $info_fail = isset( $cat_counts['fail'] ) ? (int) $cat_counts['fail'] : 0;
2361 $info_issues = $info_warn + $info_fail;
2362 if ( $info_issues > 0 ) : ?>
2363 <span class="vigilante-analyzer-category-status vigilante-analyzer-category-status--attention" data-role="info-status">
2364 <span class="dashicons dashicons-warning" aria-hidden="true"></span>
2365 <?php
2366 echo esc_html( sprintf(
2367 /* translators: %d: number of findings */
2368 _n( '%d finding', '%d findings', $info_issues, 'vigilante' ),
2369 $info_issues
2370 ) );
2371 ?>
2372 </span>
2373 <?php else : ?>
2374 <span class="vigilante-analyzer-category-status vigilante-analyzer-category-status--clear" data-role="info-status">
2375 <span class="dashicons dashicons-yes-alt" aria-hidden="true"></span>
2376 <?php esc_html_e( 'All clear', 'vigilante' ); ?>
2377 </span>
2378 <?php endif; ?>
2379 <?php endif; ?>
2380 </summary>
2381 <ul class="vigilante-analyzer-check-list" data-role="check-list">
2382 <?php if ( empty( $checks ) ) : ?>
2383 <li class="vigilante-analyzer-check-empty">
2384 <?php esc_html_e( 'No data yet — run a scan to populate this category.', 'vigilante' ); ?>
2385 </li>
2386 <?php else : ?>
2387 <?php foreach ( $checks as $c ) : ?>
2388 <?php echo self::render_analyzer_check_row( $c ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped inside helper ?>
2389 <?php endforeach; ?>
2390 <?php endif; ?>
2391 </ul>
2392 </details>
2393 <?php endforeach; ?>
2394 </div>
2395
2396 <div class="vigilante-analyzer-weekly">
2397 <h3><?php esc_html_e( 'Automatic weekly scan', 'vigilante' ); ?></h3>
2398 <p class="description">
2399 <?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' ); ?>
2400 </p>
2401 <label class="vigilante-analyzer-toggle-option">
2402 <input type="checkbox"
2403 name="security_analyzer[weekly_scan_enabled]"
2404 value="1"
2405 <?php checked( $weekly_enabled ); ?>>
2406 <?php esc_html_e( 'Run a weekly automatic scan', 'vigilante' ); ?>
2407 </label>
2408 <label class="vigilante-analyzer-toggle-option">
2409 <input type="checkbox"
2410 name="security_analyzer[email_on_regression]"
2411 value="1"
2412 <?php checked( $email_enabled ); ?>>
2413 <?php esc_html_e( 'Email me when the score drops significantly', 'vigilante' ); ?>
2414 </label>
2415 </div>
2416 </div>
2417 </div>
2418 <?php
2419 }
2420
2421 /**
2422 * Map a 0-100 percentage to a quality tag { label, slug } aligned with the
2423 * Dashboard grade palette (a/b/c/d/e).
2424 *
2425 * @param int $pct 0..100.
2426 * @return array{label:string,slug:string}
2427 */
2428 public static function analyzer_quality_tag( $pct ) {
2429 $pct = max( 0, min( 100, (int) $pct ) );
2430 // "Excellent" is reserved for a perfect score — a single missing point drops to Good.
2431 if ( 100 === $pct ) {
2432 return array( 'label' => __( 'Excellent', 'vigilante' ), 'slug' => 'a' );
2433 }
2434 if ( $pct >= 70 ) {
2435 return array( 'label' => __( 'Good', 'vigilante' ), 'slug' => 'b' );
2436 }
2437 if ( $pct >= 50 ) {
2438 return array( 'label' => __( 'Fair', 'vigilante' ), 'slug' => 'c' );
2439 }
2440 if ( $pct >= 30 ) {
2441 return array( 'label' => __( 'Poor', 'vigilante' ), 'slug' => 'd' );
2442 }
2443 return array( 'label' => __( 'Critical', 'vigilante' ), 'slug' => 'e' );
2444 }
2445
2446 /**
2447 * Render a single analyzer check row (used both server-side and via JS template).
2448 *
2449 * @param array $check Check result array (from Vigilante_SA_Check_Result::to_array()).
2450 * @return string HTML (escaped).
2451 */
2452 private static function render_analyzer_check_row( $check ) {
2453 $id = isset( $check['id'] ) ? $check['id'] : '';
2454 $state = isset( $check['state'] ) ? $check['state'] : 'skip';
2455 $label = isset( $check['label'] ) ? $check['label'] : '';
2456 $detail = isset( $check['detail'] ) ? $check['detail'] : '';
2457 $score = isset( $check['score'] ) ? (int) $check['score'] : 0;
2458 $max = isset( $check['max'] ) ? (int) $check['max'] : 0;
2459 $fix_link = isset( $check['fix_link'] ) ? $check['fix_link'] : '';
2460
2461 $icons = array(
2462 'pass' => 'yes-alt',
2463 'warn' => 'warning',
2464 'fail' => 'dismiss',
2465 'info' => 'info',
2466 'skip' => 'minus',
2467 );
2468 $icon = isset( $icons[ $state ] ) ? $icons[ $state ] : 'minus';
2469
2470 $html = '<li class="vigilante-analyzer-check vigilante-analyzer-check--' . esc_attr( $state ) . '"';
2471 $html .= ' data-check-id="' . esc_attr( $id ) . '">';
2472 $html .= '<span class="vigilante-analyzer-check-icon dashicons dashicons-' . esc_attr( $icon ) . '" aria-hidden="true"></span>';
2473 $html .= '<div class="vigilante-analyzer-check-body">';
2474 $html .= '<div class="vigilante-analyzer-check-label">';
2475 $html .= '<span>' . esc_html( $label ) . '</span>';
2476 if ( $max > 0 && 'info' !== $state && 'skip' !== $state ) {
2477 $html .= '<span class="vigilante-analyzer-check-score">'
2478 . esc_html( $score . '/' . $max )
2479 . ' <span class="vigilante-analyzer-check-score-unit">' . esc_html__( 'pts', 'vigilante' ) . '</span>'
2480 . '</span>';
2481 }
2482 $html .= '</div>';
2483 if ( $detail ) {
2484 $html .= '<p class="vigilante-analyzer-check-detail">' . esc_html( $detail ) . '</p>';
2485 }
2486 if ( $fix_link && in_array( $state, array( 'fail', 'warn' ), true ) ) {
2487 $html .= '<a href="' . esc_url( $fix_link ) . '" class="vigilante-analyzer-fix-link">'
2488 . esc_html__( 'Go to setting', 'vigilante' )
2489 . '<span class="vigilante-analyzer-fix-arrow" aria-hidden="true">&rarr;</span></a>';
2490 } elseif ( $fix_link && 'info' === $state ) {
2491 // Info rows (e.g. DNSBL lookups) get an external "Learn more" link instead.
2492 $is_external = 0 === strpos( $fix_link, 'http' );
2493 $html .= '<a href="' . esc_url( $fix_link ) . '" class="vigilante-analyzer-fix-link"'
2494 . ( $is_external ? ' target="_blank" rel="noopener noreferrer"' : '' ) . '>'
2495 . esc_html__( 'Learn more', 'vigilante' )
2496 . '<span class="vigilante-analyzer-fix-arrow" aria-hidden="true">&rarr;</span></a>';
2497 }
2498 $html .= '</div>';
2499 $html .= '</li>';
2500 return $html;
2501 }
2502
2503 /**
2504 * Build a minimal SVG sparkline for the score history.
2505 *
2506 * @param int[] $points Score values (0..100), oldest to newest.
2507 * @return string SVG markup.
2508 */
2509 private static function sparkline_svg( $points ) {
2510 $points = array_map( 'intval', (array) $points );
2511 $count = count( $points );
2512 if ( $count < 2 ) {
2513 return '';
2514 }
2515 $width = 280;
2516 $height = 60;
2517 $padding = 4;
2518
2519 $usable_w = $width - ( $padding * 2 );
2520 $usable_h = $height - ( $padding * 2 );
2521
2522 $step = $usable_w / max( 1, $count - 1 );
2523 $max = 100; // Fixed scale — scores are 0..100.
2524
2525 $coords = array();
2526 foreach ( $points as $i => $v ) {
2527 $x = $padding + ( $i * $step );
2528 $y = $padding + ( $usable_h - ( ( $v / $max ) * $usable_h ) );
2529 $coords[] = round( $x, 2 ) . ',' . round( $y, 2 );
2530 }
2531 $path = 'M ' . implode( ' L ', $coords );
2532 $last = end( $points );
2533 $last_x = $padding + ( ( $count - 1 ) * $step );
2534 $last_y = $padding + ( $usable_h - ( ( $last / $max ) * $usable_h ) );
2535
2536 $svg = '<svg viewBox="0 0 ' . $width . ' ' . $height . '" preserveAspectRatio="none" role="img" aria-label="' . esc_attr__( 'Security Score history', 'vigilante' ) . '" focusable="false">';
2537 $svg .= '<path d="' . esc_attr( $path ) . '" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>';
2538 $svg .= '<circle cx="' . esc_attr( round( $last_x, 2 ) ) . '" cy="' . esc_attr( round( $last_y, 2 ) ) . '" r="3" fill="currentColor"/>';
2539 $svg .= '</svg>';
2540 return $svg;
2541 }
2542
2543 /**
2544 * Render dashboard tab
2545 */
2546 private function render_tab_dashboard() {
2547 $options = $this->settings->get_all_options();
2548 $module_labels = $this->settings->get_module_labels();
2549 $module_descriptions = $this->settings->get_module_descriptions();
2550 $presets = $this->settings->get_presets();
2551 $active_preset = get_option( 'vigilante_active_preset', '' );
2552
2553 // Calculate security score with more factors
2554 $security_score = $this->calculate_security_score( $options );
2555
2556 // Security Analyzer (v2.1.0) — hydrate widget with the last persisted scan, if any.
2557 if ( ! class_exists( 'Vigilante_Security_Analyzer' ) ) {
2558 require_once VIGILANTE_INCLUDES_DIR . 'class-security-analyzer.php';
2559 }
2560 $analyzer_instance = new Vigilante_Security_Analyzer( $this->settings, $this->activity_log );
2561 $analyzer_last_scan = $analyzer_instance->get_last_scan();
2562 $analyzer_history = $analyzer_instance->get_score_history();
2563 $analyzer_categories_def = Vigilante_Security_Analyzer::get_categories();
2564 $analyzer_settings = isset( $options['security_analyzer'] ) ? $options['security_analyzer'] : array();
2565 ?>
2566 <div class="vigilante-dashboard">
2567 <div class="vigilante-status-card">
2568 <h2><?php esc_html_e( 'Configuration Score', 'vigilante' ); ?></h2>
2569 <p class="vigilante-score-kind description">
2570 <?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' ); ?>
2571 </p>
2572 <div class="vigilante-security-score">
2573 <?php
2574 // Grade thresholds: A (90+), B (70-89), C (50-69), D (30-49), E (0-29)
2575 if ( $security_score >= 90 ) {
2576 $grade = 'A';
2577 } elseif ( $security_score >= 70 ) {
2578 $grade = 'B';
2579 } elseif ( $security_score >= 50 ) {
2580 $grade = 'C';
2581 } elseif ( $security_score >= 30 ) {
2582 $grade = 'D';
2583 } else {
2584 $grade = 'E';
2585 }
2586 ?>
2587 <div class="vigilante-score-circle vigilante-grade-<?php echo esc_attr( strtolower( $grade ) ); ?>">
2588 <span class="vigilante-grade"><?php echo esc_html( $grade ); ?></span>
2589 <span class="vigilante-score-text"><?php echo esc_html( $security_score ); ?>%</span>
2590 </div>
2591 <div class="vigilante-config-status">
2592 <?php if ( $active_preset && isset( $presets[ $active_preset ] ) ) : ?>
2593 <span class="vigilante-preset-badge vigilante-preset-<?php echo esc_attr( $active_preset ); ?>">
2594 <?php echo esc_html( $presets[ $active_preset ]['name'] ); ?>
2595 </span>
2596 <?php else : ?>
2597 <span class="vigilante-preset-badge vigilante-preset-custom">
2598 <?php esc_html_e( 'Custom Configuration', 'vigilante' ); ?>
2599 </span>
2600 <?php endif; ?>
2601 </div>
2602 </div>
2603
2604 <?php
2605 $recommendations = $this->get_security_recommendations( $options );
2606 if ( ! empty( $recommendations ) ) :
2607 ?>
2608 <div class="vigilante-recommendations">
2609 <h4><?php esc_html_e( 'Recommendations', 'vigilante' ); ?></h4>
2610 <ul class="vigilante-recommendations-grid">
2611 <?php foreach ( $recommendations as $rec ) : ?>
2612 <li>
2613 <span class="dashicons dashicons-<?php echo esc_attr( $rec['icon'] ); ?> vigilante-priority-<?php echo esc_attr( $rec['priority'] ); ?>"></span>
2614 <?php echo esc_html( $rec['message'] ); ?>
2615 <?php if ( ! empty( $rec['tab'] ) ) : ?>
2616 <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>
2617 <?php endif; ?>
2618 </li>
2619 <?php endforeach; ?>
2620 </ul>
2621 </div>
2622 <?php endif; ?>
2623 </div>
2624
2625 <?php $this->render_analyzer_widget( $analyzer_last_scan, $analyzer_history, $analyzer_categories_def, $analyzer_settings ); ?>
2626
2627 <div class="vigilante-modules-grid">
2628 <h2 id="vigilante-section-dashboard-modules"><?php esc_html_e( 'Security Modules', 'vigilante' ); ?></h2>
2629 <p class="description"><?php esc_html_e( 'Enable or disable security modules. Each module controls a tab with detailed settings.', 'vigilante' ); ?></p>
2630 <div class="vigilante-modules-list">
2631 <?php foreach ( $options['modules'] as $module => $enabled ) :
2632 $label = isset( $module_labels[ $module ] ) ? $module_labels[ $module ] : ucwords( str_replace( '_', ' ', $module ) );
2633 $description = isset( $module_descriptions[ $module ] ) ? $module_descriptions[ $module ] : '';
2634 ?>
2635 <div class="vigilante-module-item <?php echo $enabled ? 'enabled' : 'disabled'; ?>">
2636 <div class="vigilante-module-header">
2637 <span class="vigilante-module-status"></span>
2638 <span class="vigilante-module-name"><?php echo esc_html( $label ); ?></span>
2639 <label class="vigilante-toggle">
2640 <?php
2641 /* translators: %s: Security module name, for example Firewall. */
2642 $toggle_label = sprintf( __( 'Enable %s', 'vigilante' ), $label );
2643 ?>
2644 <input type="checkbox"
2645 name="modules[<?php echo esc_attr( $module ); ?>]"
2646 value="1"
2647 <?php checked( $enabled ); ?>
2648 aria-label="<?php echo esc_attr( $toggle_label ); ?>"
2649 data-module="<?php echo esc_attr( $module ); ?>">
2650 <span class="vigilante-toggle-slider"></span>
2651 </label>
2652 </div>
2653 <?php if ( $description ) : ?>
2654 <p class="vigilante-module-desc"><?php echo esc_html( $description ); ?></p>
2655 <?php endif; ?>
2656 </div>
2657 <?php endforeach; ?>
2658 </div>
2659 </div>
2660
2661 <div class="vigilante-presets-card">
2662 <h2><?php esc_html_e( 'Quick Configuration Presets', 'vigilante' ); ?></h2>
2663 <p><?php esc_html_e( 'Apply a preset to quickly set up recommended settings for standard or maximum security level.', 'vigilante' ); ?></p>
2664 <div class="vigilante-presets-grid">
2665 <?php foreach ( $presets as $preset_id => $preset ) :
2666 $is_active = ( $active_preset === $preset_id );
2667 ?>
2668 <div class="vigilante-preset-card <?php echo $is_active ? 'vigilante-preset-active' : ''; ?>">
2669 <?php if ( $is_active ) : ?>
2670 <span class="vigilante-active-indicator"><?php esc_html_e( 'Active', 'vigilante' ); ?></span>
2671 <?php endif; ?>
2672 <h3><?php echo esc_html( $preset['name'] ); ?></h3>
2673 <p><?php echo esc_html( $preset['description'] ); ?></p>
2674 <button type="button" class="button vigilante-preset-btn <?php echo $is_active ? 'button-primary' : ''; ?>" data-preset="<?php echo esc_attr( $preset_id ); ?>">
2675 <?php esc_html_e( 'Apply Preset', 'vigilante' ); ?>
2676 </button>
2677 </div>
2678 <?php endforeach; ?>
2679
2680 <?php
2681 // Under Attack mode card
2682 $under_attack = new Vigilante_Under_Attack( $this->settings, $this->activity_log );
2683 $ua_active = $under_attack->is_active();
2684 $ua_remaining = $under_attack->get_remaining_time();
2685 $ua_remaining_hours = floor( $ua_remaining / 3600 );
2686 $ua_remaining_mins = floor( ( $ua_remaining % 3600 ) / 60 );
2687 ?>
2688 <div class="vigilante-preset-card vigilante-under-attack-card <?php echo $ua_active ? 'vigilante-under-attack-active' : ''; ?>">
2689 <h3 id="vigilante-section-dashboard-under-attack">
2690 <span class="dashicons dashicons-shield"></span>
2691 <?php esc_html_e( 'Under Attack', 'vigilante' ); ?>
2692 </h3>
2693 <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>
2694 <?php if ( $ua_active ) : ?>
2695 <div class="vigilante-ua-countdown" data-expires="<?php echo esc_attr( $under_attack->get_status()['activated_at'] + $under_attack->get_status()['duration'] ); ?>">
2696 <span class="dashicons dashicons-clock"></span>
2697 <span class="vigilante-ua-time">
2698 <?php
2699 printf(
2700 /* translators: 1: Hours, 2: Minutes */
2701 esc_html__( '%1$dh %2$dm remaining', 'vigilante' ),
2702 absint( $ua_remaining_hours ),
2703 absint( $ua_remaining_mins )
2704 );
2705 ?>
2706 </span>
2707 </div>
2708 <button type="button" class="button vigilante-ua-btn vigilante-ua-deactivate">
2709 <?php esc_html_e( 'Deactivate', 'vigilante' ); ?>
2710 </button>
2711 <?php else : ?>
2712 <button type="button" class="button vigilante-ua-btn vigilante-ua-activate">
2713 <?php esc_html_e( 'Activate for 4 hours', 'vigilante' ); ?>
2714 </button>
2715 <?php endif; ?>
2716 </div>
2717 </div>
2718 </div>
2719 </div>
2720 <?php
2721 }
2722
2723 /**
2724 * Render tools tab
2725 */
2726 private function render_tab_tools() {
2727 // Get current settings for notification summary
2728 $email_options = $this->settings->get_section( 'email' );
2729 $login_options = $this->settings->get_section( 'login_security' );
2730 $user_options = $this->settings->get_section( 'user_security' );
2731 $fi_options = $this->settings->get_section( 'file_integrity' );
2732 $alerts_options = $this->settings->get_section( 'audit_alerts' );
2733 $monitoring = $user_options['admin_monitoring'] ?? array();
2734 $registration = $user_options['registration_approval'] ?? array();
2735 $current_admin = get_option( 'admin_email' );
2736 $send_to_admin = ! isset( $email_options['send_to_admin_email'] ) || ! empty( $email_options['send_to_admin_email'] );
2737 $additional_raw = $email_options['additional_recipients'] ?? array();
2738 $additional = is_array( $additional_raw ) ? implode( "\n", $additional_raw ) : trim( $additional_raw );
2739 ?>
2740
2741 <!-- Notification Settings -->
2742 <div id="vigilante-section-tools-notifications" class="vigilante-settings-section vigilante-notification-section">
2743 <h2><?php esc_html_e( 'Notification settings', 'vigilante' ); ?></h2>
2744 <p><?php esc_html_e( 'Configure who receives all administrative email notifications from Vigilant. Individual notifications are enabled in their respective tabs.', 'vigilante' ); ?></p>
2745
2746 <div class="vigilante-notification-layout">
2747
2748 <!-- Left column: Recipients settings -->
2749 <div class="vigilante-notification-settings">
2750 <form class="vigilante-settings-form" data-section="email">
2751
2752 <table class="form-table vigilante-compact-form">
2753 <tr>
2754 <th scope="row"><?php esc_html_e( 'WordPress Admin Email', 'vigilante' ); ?></th>
2755 <td>
2756 <label>
2757 <input type="checkbox" name="email[send_to_admin_email]" value="1" <?php checked( $send_to_admin ); ?>>
2758 <?php
2759 printf(
2760 /* translators: %s: Admin email address */
2761 esc_html__( 'Send to admin email (%s)', 'vigilante' ),
2762 '<code>' . esc_html( $current_admin ) . '</code>'
2763 );
2764 ?>
2765 </label>
2766 </td>
2767 </tr>
2768 <tr>
2769 <th scope="row"><label for="vigilante-f-email-additional-recipients"><?php esc_html_e( 'Additional Recipients', 'vigilante' ); ?></label></th>
2770 <td>
2771 <textarea id="vigilante-f-email-additional-recipients" name="email[additional_recipients]" rows="3" class="large-text code" placeholder="maintenance@example.com&#10;security@example.com"><?php echo esc_textarea( $additional ); ?></textarea>
2772 <p class="description"><?php esc_html_e( 'One email per line.', 'vigilante' ); ?></p>
2773 </td>
2774 </tr>
2775 <tr>
2776 <th scope="row"><?php esc_html_e( 'Plugin Deactivation', 'vigilante' ); ?></th>
2777 <td>
2778 <label>
2779 <input type="checkbox" name="email[send_deactivation_email]" value="1" <?php checked( ! empty( $email_options['send_deactivation_email'] ) ); ?>>
2780 <?php esc_html_e( 'Send email when Vigilant is deactivated', 'vigilante' ); ?>
2781 </label>
2782 </td>
2783 </tr>
2784 </table>
2785
2786 <p class="submit vigilante-notification-submit">
2787 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
2788 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
2789 </button>
2790 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
2791 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
2792 </button>
2793 <span class="vigilante-test-email-result" style="margin-left:8px;vertical-align:middle;"></span>
2794 </p>
2795 <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>
2796
2797 </form>
2798 </div>
2799
2800 <!-- Right column: Active notifications summary -->
2801 <div class="vigilante-notification-summary">
2802 <h4><?php esc_html_e( 'Active notifications', 'vigilante' ); ?></h4>
2803
2804 <table class="widefat striped">
2805 <thead>
2806 <tr>
2807 <th><?php esc_html_e( 'Notification', 'vigilante' ); ?></th>
2808 <th style="width: 1%; white-space: nowrap; text-align: center;"><?php esc_html_e( 'Status', 'vigilante' ); ?></th>
2809 <th style="width: 50px; text-align: center;"></th>
2810 </tr>
2811 </thead>
2812 <tbody>
2813 <?php
2814 $notifications = array(
2815 array(
2816 'label' => __( 'Login lockout', 'vigilante' ),
2817 'active' => ! empty( $login_options['notify_on_lockout'] ),
2818 'tab' => 'login',
2819 ),
2820 array(
2821 'label' => __( 'Administrator login', 'vigilante' ),
2822 'active' => ! empty( $login_options['notify_on_admin_login'] ),
2823 'tab' => 'login',
2824 ),
2825 array(
2826 'label' => __( 'New administrator created', 'vigilante' ),
2827 'active' => ! empty( $monitoring['alert_new_admin'] ),
2828 'tab' => 'users',
2829 ),
2830 array(
2831 'label' => __( 'Administrator email changed', 'vigilante' ),
2832 'active' => ! empty( $monitoring['alert_admin_email_change'] ),
2833 'tab' => 'users',
2834 ),
2835 array(
2836 'label' => __( 'Permission elevation', 'vigilante' ),
2837 'active' => ! empty( $monitoring['alert_permission_elevation'] ),
2838 'tab' => 'users',
2839 ),
2840 array(
2841 'label' => __( 'Admin password changed', 'vigilante' ),
2842 'active' => ! empty( $monitoring['alert_admin_password_change'] ),
2843 'tab' => 'users',
2844 ),
2845 array(
2846 'label' => __( 'Registration pending approval', 'vigilante' ),
2847 'active' => ! empty( $registration['enabled'] ) && ! empty( $registration['notify_admin'] ),
2848 'tab' => 'users',
2849 ),
2850 array(
2851 'label' => __( 'File integrity scan report', 'vigilante' ),
2852 'active' => ( $fi_options['notify_level'] ?? 'disabled' ) !== 'disabled',
2853 'tab' => 'file-integrity',
2854 ),
2855 array(
2856 'label' => __( 'File integrity instant alert', 'vigilante' ),
2857 'active' => ! empty( $fi_options['instant_alert'] ),
2858 'tab' => 'file-integrity',
2859 ),
2860 array(
2861 'label' => __( 'Audit alert: immediate', 'vigilante' ),
2862 'active' => Vigilante_Audit_Alerts::immediate_is_active( $alerts_options ),
2863 'tab' => 'activity-log',
2864 'anchor' => 'vigilante-section-audit-alerts',
2865 ),
2866 array(
2867 'label' => __( 'Audit alert: threshold', 'vigilante' ),
2868 'active' => Vigilante_Audit_Alerts::threshold_is_active( $alerts_options ),
2869 'tab' => 'activity-log',
2870 'anchor' => 'vigilante-section-audit-alerts',
2871 ),
2872 array(
2873 'label' => __( 'Under Attack mode', 'vigilante' ),
2874 'active' => true,
2875 'tab' => '',
2876 'note' => __( 'Always active', 'vigilante' ),
2877 ),
2878 array(
2879 'label' => __( 'Plugin deactivation', 'vigilante' ),
2880 'active' => ! empty( $email_options['send_deactivation_email'] ),
2881 'tab' => 'tools',
2882 ),
2883 );
2884
2885 foreach ( $notifications as $notif ) :
2886 $status_class = $notif['active'] ? 'vigilante-status-active' : 'vigilante-status-inactive';
2887 $status_label = $notif['active'] ? __( 'Active', 'vigilante' ) : __( 'Inactive', 'vigilante' );
2888 if ( ! empty( $notif['note'] ) ) {
2889 $status_label = $notif['note'];
2890 }
2891 ?>
2892 <tr>
2893 <td><?php echo esc_html( $notif['label'] ); ?></td>
2894 <td style="text-align: center; white-space: nowrap;">
2895 <span class="<?php echo esc_attr( $status_class ); ?>"><?php echo esc_html( $status_label ); ?></span>
2896 </td>
2897 <td style="text-align: center;">
2898 <?php if ( ! empty( $notif['tab'] ) ) : ?>
2899 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=' . $notif['tab'] ) . ( ! empty( $notif['anchor'] ) ? '#' . $notif['anchor'] : '' ) ); ?>" class="button button-small">
2900 <span class="dashicons dashicons-admin-generic" style="font-size: 14px; line-height: 1.8;"></span>
2901 </a>
2902 <?php else : ?>
2903 &mdash;
2904 <?php endif; ?>
2905 </td>
2906 </tr>
2907 <?php endforeach; ?>
2908 </tbody>
2909 </table>
2910 </div>
2911
2912 </div>
2913 </div>
2914
2915 <h2 id="vigilante-section-tools-main" class="vigilante-tools-heading"><?php esc_html_e( 'Tools', 'vigilante' ); ?></h2>
2916
2917 <?php
2918 // Warn that during Under Attack mode the export/import operate against
2919 // the temporary hardened config and any imported changes will be
2920 // reverted when the mode ends.
2921 $ua_status = get_option( Vigilante_Under_Attack::OPTION_NAME, array() );
2922 if ( ! empty( $ua_status['active'] ) ) :
2923 ?>
2924 <div class="vigilante-ua-tools-notice-wrap">
2925 <div class="notice notice-warning inline vigilante-ua-tools-notice">
2926 <p>
2927 <strong><?php esc_html_e( 'Under Attack mode is active.', 'vigilante' ); ?></strong>
2928 <?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' ); ?>
2929 </p>
2930 </div>
2931 </div>
2932 <?php
2933 endif;
2934 ?>
2935
2936 <div class="vigilante-tools-grid">
2937 <div class="vigilante-tool-card">
2938 <h3><?php esc_html_e( 'Export Settings', 'vigilante' ); ?></h3>
2939 <p><?php esc_html_e( 'Download your current security settings as a JSON file.', 'vigilante' ); ?></p>
2940 <button type="button" class="button vigilante-export-settings">
2941 <?php esc_html_e( 'Export Settings', 'vigilante' ); ?>
2942 </button>
2943 </div>
2944
2945 <div class="vigilante-tool-card">
2946 <h3><?php esc_html_e( 'Import Settings', 'vigilante' ); ?></h3>
2947 <p><?php esc_html_e( 'Import settings from a previously exported JSON file.', 'vigilante' ); ?></p>
2948 <input type="file" id="vigilante-import-file" aria-label="<?php esc_attr_e( 'Configuration file to import', 'vigilante' ); ?>" accept=".json" style="display: none;">
2949 <button type="button" class="button vigilante-import-settings">
2950 <?php esc_html_e( 'Import Settings', 'vigilante' ); ?>
2951 </button>
2952 </div>
2953
2954 <div class="vigilante-tool-card">
2955 <h3><?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?></h3>
2956 <p><?php esc_html_e( 'Reset all the Vigilant security settings to default values. Your IP lists, custom login address, two-factor setup, scan exclusions and extra alert recipients are kept.', 'vigilante' ); ?></p>
2957 <button type="button" class="button vigilante-reset-settings" style="color: #a00;">
2958 <?php esc_html_e( 'Reset All Settings', 'vigilante' ); ?>
2959 </button>
2960 </div>
2961
2962 <div class="vigilante-tool-card">
2963 <h3><?php esc_html_e( 'Download Config Backup', 'vigilante' ); ?></h3>
2964 <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>
2965 <?php if ( $this->shared_files_locked() ) : ?>
2966 <p class="description"><?php esc_html_e( 'Both files belong to the whole network, and wp-config.php carries the database credentials and the authentication salts of every site. The copy is taken from the main site.', 'vigilante' ); ?></p>
2967 <?php else : ?>
2968 <button type="button" class="button vigilante-create-backup">
2969 <?php esc_html_e( 'Download Backup', 'vigilante' ); ?>
2970 </button>
2971 <?php endif; ?>
2972 </div>
2973
2974 <?php if ( ! $this->shared_files_locked() ) : ?>
2975
2976 <div class="vigilante-tool-card vigilante-tool-card-wide">
2977 <h3><?php esc_html_e( 'Database Backup', 'vigilante' ); ?></h3>
2978 <p><?php esc_html_e( 'Download a backup of your database as a ZIP file. Select which tables to include.', 'vigilante' ); ?></p>
2979 <button type="button" class="button vigilante-db-backup-toggle">
2980 <?php esc_html_e( 'Download Database Backup', 'vigilante' ); ?>
2981 </button>
2982
2983 <div class="vigilante-db-backup-panel" style="display: none;">
2984 <div class="vigilante-db-tables-loading">
2985 <span class="spinner is-active"></span>
2986 <?php esc_html_e( 'Loading tables...', 'vigilante' ); ?>
2987 </div>
2988
2989 <div class="vigilante-db-tables-content" style="display: none;">
2990 <div class="vigilante-db-tables-controls">
2991 <label>
2992 <input type="checkbox" id="vigilante-db-select-all" checked>
2993 <strong><?php esc_html_e( 'Select / deselect all', 'vigilante' ); ?></strong>
2994 </label>
2995 <span class="vigilante-db-tables-info"></span>
2996 </div>
2997
2998 <div class="vigilante-db-tables-group">
2999 <h4><?php esc_html_e( 'WordPress core tables', 'vigilante' ); ?></h4>
3000 <div class="vigilante-db-tables-list" id="vigilante-db-core-tables"></div>
3001 </div>
3002
3003 <div class="vigilante-db-tables-group" id="vigilante-db-other-group" style="display: none;">
3004 <h4><?php esc_html_e( 'Plugin and custom tables', 'vigilante' ); ?></h4>
3005 <div class="vigilante-db-tables-list" id="vigilante-db-other-tables"></div>
3006 </div>
3007
3008 <div class="vigilante-db-backup-actions">
3009 <button type="button" class="button button-primary vigilante-db-backup-download">
3010 <?php esc_html_e( 'Download Backup (.zip)', 'vigilante' ); ?>
3011 </button>
3012 </div>
3013 </div>
3014 </div>
3015 </div>
3016 <?php else : ?>
3017 <div class="vigilante-tool-card vigilante-tool-card-wide">
3018 <h3><?php esc_html_e( 'Database Backup', 'vigilante' ); ?></h3>
3019 <p><?php esc_html_e( 'Download a backup of your database as a ZIP file. Select which tables to include.', 'vigilante' ); ?></p>
3020 <p class="description"><?php esc_html_e( 'The database is shared by the whole network, so a backup taken here would carry every other site and all of the network users. The copy is taken from the main site.', 'vigilante' ); ?></p>
3021 </div>
3022 <?php endif; ?>
3023 </div>
3024 <?php
3025 }
3026
3027 /**
3028 * Render firewall tab
3029 */
3030 private function render_tab_firewall() {
3031 $is_disabled = $this->render_module_disabled_notice( 'firewall' );
3032 $options = $this->settings->get_section( 'firewall' );
3033 ?>
3034 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="firewall" <?php echo $is_disabled ? 'inert' : ''; ?>>
3035 <div id="vigilante-section-firewall-main" class="vigilante-settings-section">
3036 <h2>
3037 <?php esc_html_e( 'Firewall Protection', 'vigilante' ); ?>
3038 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
3039 </h2>
3040 <p><?php esc_html_e( 'PHP-based request filtering. Analyzes each request before WordPress loads.', 'vigilante' ); ?></p>
3041 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
3042 <p style="margin:0;">
3043 <?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' ); ?>
3044 </p>
3045 </div>
3046
3047 <table class="form-table">
3048 <tr>
3049 <th scope="row"><?php esc_html_e( 'Block Bad Query Strings', 'vigilante' ); ?></th>
3050 <td>
3051 <label>
3052 <input type="checkbox" name="firewall[block_bad_query_strings]" value="1" <?php checked( ! empty( $options['block_bad_query_strings'] ) ); ?>>
3053 <?php esc_html_e( 'Block malicious query string patterns', 'vigilante' ); ?>
3054 </label>
3055 </td>
3056 </tr>
3057 <tr>
3058 <th scope="row"><?php esc_html_e( 'SQL Injection Protection', 'vigilante' ); ?></th>
3059 <td>
3060 <label>
3061 <input type="checkbox" name="firewall[block_sql_injection]" value="1" <?php checked( ! empty( $options['block_sql_injection'] ) ); ?>>
3062 <?php esc_html_e( 'Block SQL injection attempts', 'vigilante' ); ?>
3063 </label>
3064 </td>
3065 </tr>
3066 <tr>
3067 <th scope="row"><?php esc_html_e( 'XSS Protection', 'vigilante' ); ?></th>
3068 <td>
3069 <label>
3070 <input type="checkbox" name="firewall[block_xss_attacks]" value="1" <?php checked( ! empty( $options['block_xss_attacks'] ) ); ?>>
3071 <?php esc_html_e( 'Block cross-site scripting attacks', 'vigilante' ); ?>
3072 </label>
3073 </td>
3074 </tr>
3075 <tr>
3076 <th scope="row"><?php esc_html_e( 'File Inclusion Protection', 'vigilante' ); ?></th>
3077 <td>
3078 <label>
3079 <input type="checkbox" name="firewall[block_file_inclusion]" value="1" <?php checked( ! empty( $options['block_file_inclusion'] ) ); ?>>
3080 <?php esc_html_e( 'Block local/remote file inclusion attempts', 'vigilante' ); ?>
3081 </label>
3082 </td>
3083 </tr>
3084 <tr>
3085 <th scope="row"><?php esc_html_e( 'Directory Traversal Protection', 'vigilante' ); ?></th>
3086 <td>
3087 <label>
3088 <input type="checkbox" name="firewall[block_directory_traversal]" value="1" <?php checked( ! empty( $options['block_directory_traversal'] ) ); ?>>
3089 <?php esc_html_e( 'Block path traversal attempts', 'vigilante' ); ?>
3090 </label>
3091 </td>
3092 </tr>
3093 <tr>
3094 <th scope="row"><?php esc_html_e( 'Block Bad Bots', 'vigilante' ); ?></th>
3095 <td>
3096 <label>
3097 <input type="checkbox" name="firewall[block_bad_bots]" value="1" <?php checked( ! empty( $options['block_bad_bots'] ) ); ?>>
3098 <?php esc_html_e( 'Block known malicious bots and scanners', 'vigilante' ); ?>
3099 </label>
3100 </td>
3101 </tr>
3102 </table>
3103
3104 <h3><?php esc_html_e( 'Rate Limiting', 'vigilante' ); ?></h3>
3105 <table class="form-table">
3106 <tr>
3107 <th scope="row"><?php esc_html_e( 'Enable Rate Limiting', 'vigilante' ); ?></th>
3108 <td>
3109 <label>
3110 <input type="checkbox" name="firewall[rate_limiting][enabled]" value="1" <?php checked( ! empty( $options['rate_limiting']['enabled'] ) ); ?>>
3111 <?php esc_html_e( 'Limit requests per IP address', 'vigilante' ); ?>
3112 </label>
3113 </td>
3114 </tr>
3115 <tr>
3116 <th scope="row"><label for="vigilante-f-firewall-rate-limiting-requests-per-minute"><?php esc_html_e( 'Requests per Minute', 'vigilante' ); ?></label></th>
3117 <td>
3118 <input id="vigilante-f-firewall-rate-limiting-requests-per-minute" 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">
3119 <p class="description">
3120 <?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' ); ?>
3121 </p>
3122 </td>
3123 </tr>
3124 <tr>
3125 <th scope="row"><label for="vigilante-f-firewall-rate-limiting-block-duration"><?php esc_html_e( 'Block Duration (seconds)', 'vigilante' ); ?></label></th>
3126 <td>
3127 <input id="vigilante-f-firewall-rate-limiting-block-duration" 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">
3128 </td>
3129 </tr>
3130 <tr>
3131 <th scope="row"><?php esc_html_e( 'Progressive Blocking', 'vigilante' ); ?></th>
3132 <td>
3133 <label>
3134 <input type="checkbox" name="firewall[rate_limiting][progressive]" value="1" <?php checked( ! empty( $options['rate_limiting']['progressive'] ) ); ?>>
3135 <?php esc_html_e( 'Double block duration on each repeat offense', 'vigilante' ); ?>
3136 </label>
3137 <p class="description">
3138 <?php
3139 $base = absint( $options['rate_limiting']['block_duration'] ?? 300 );
3140 printf(
3141 /* translators: 1: First block duration, 2: Second, 3: Third */
3142 esc_html__( 'Example: %1$s → %2$s → %3$s and so on, up to the maximum.', 'vigilante' ),
3143 esc_html( human_time_diff( 0, $base ) ),
3144 esc_html( human_time_diff( 0, $base * 2 ) ),
3145 esc_html( human_time_diff( 0, $base * 4 ) )
3146 );
3147 ?>
3148 </p>
3149 </td>
3150 </tr>
3151 <tr>
3152 <th scope="row"><label for="vigilante-f-firewall-rate-limiting-max-block-duration"><?php esc_html_e( 'Maximum Block Duration', 'vigilante' ); ?></label></th>
3153 <td>
3154 <select id="vigilante-f-firewall-rate-limiting-max-block-duration" name="firewall[rate_limiting][max_block_duration]">
3155 <?php
3156 $max_options = array(
3157 3600 => __( '1 hour', 'vigilante' ),
3158 21600 => __( '6 hours', 'vigilante' ),
3159 43200 => __( '12 hours', 'vigilante' ),
3160 86400 => __( '24 hours', 'vigilante' ),
3161 604800 => __( '7 days', 'vigilante' ),
3162 );
3163 $current_max = absint( $options['rate_limiting']['max_block_duration'] ?? 86400 );
3164 foreach ( $max_options as $val => $label ) :
3165 ?>
3166 <option value="<?php echo esc_attr( $val ); ?>" <?php selected( $current_max, $val ); ?>>
3167 <?php echo esc_html( $label ); ?>
3168 </option>
3169 <?php endforeach; ?>
3170 </select>
3171 <p class="description"><?php esc_html_e( 'Upper limit for progressive blocking.', 'vigilante' ); ?></p>
3172 </td>
3173 </tr>
3174 </table>
3175
3176 <?php
3177 // Currently blocked IPs from rate limiting
3178 $active_blocks = Vigilante_Firewall::get_active_blocks();
3179 if ( ! empty( $active_blocks ) ) :
3180 ?>
3181 <div class="vigilante-settings-section vigilante-lockout-section" style="margin-top:20px;">
3182 <h3><?php esc_html_e( 'Currently Blocked IPs', 'vigilante' ); ?></h3>
3183 <table class="wp-list-table widefat fixed striped" style="max-width:800px;">
3184 <thead>
3185 <tr>
3186 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
3187 <th><?php esc_html_e( 'Blocked', 'vigilante' ); ?></th>
3188 <th><?php esc_html_e( 'Expires in', 'vigilante' ); ?></th>
3189 <th><?php esc_html_e( 'Strikes', 'vigilante' ); ?></th>
3190 <th><?php esc_html_e( 'Action', 'vigilante' ); ?></th>
3191 </tr>
3192 </thead>
3193 <tbody>
3194 <?php foreach ( $active_blocks as $blocked_ip => $block_data ) : ?>
3195 <tr>
3196 <td><code><?php echo esc_html( $blocked_ip ); ?></code></td>
3197 <td><?php echo esc_html( human_time_diff( $block_data['blocked_at'] ) . ' ' . __( 'ago', 'vigilante' ) ); ?></td>
3198 <td><?php echo esc_html( human_time_diff( time(), $block_data['expires'] ) ); ?></td>
3199 <td><?php echo esc_html( $block_data['strikes'] ?? 1 ); ?></td>
3200 <td>
3201 <button type="button" class="button button-small vigilante-unblock-firewall-ip"
3202 data-ip="<?php echo esc_attr( $blocked_ip ); ?>">
3203 <?php esc_html_e( 'Unblock', 'vigilante' ); ?>
3204 </button>
3205 </td>
3206 </tr>
3207 <?php endforeach; ?>
3208 </tbody>
3209 </table>
3210 </div>
3211 <?php endif; ?>
3212
3213 <h3><?php esc_html_e( 'IP Lists', 'vigilante' ); ?></h3>
3214 <p class="description">
3215 <?php
3216 printf(
3217 /* translators: %s: Current visitor IP address */
3218 esc_html__( 'Your current IP address: %s', 'vigilante' ),
3219 '<code>' . esc_html( $this->database->get_client_ip() ) . '</code>'
3220 );
3221 ?>
3222 </p>
3223 <table class="form-table">
3224 <tr>
3225 <th scope="row"><label for="vigilante-f-firewall-trusted-proxy-header"><?php esc_html_e( 'Visitor IP detection', 'vigilante' ); ?></label></th>
3226 <td>
3227 <?php $proxy_header = $options['trusted_proxy_header'] ?? ''; ?>
3228 <select id="vigilante-f-firewall-trusted-proxy-header" name="firewall[trusted_proxy_header]">
3229 <option value="" <?php selected( $proxy_header, '' ); ?>><?php esc_html_e( 'Direct connection, only REMOTE_ADDR (recommended)', 'vigilante' ); ?></option>
3230 <option value="cf-connecting-ip" <?php selected( $proxy_header, 'cf-connecting-ip' ); ?>><?php esc_html_e( 'Behind Cloudflare (CF-Connecting-IP)', 'vigilante' ); ?></option>
3231 <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>
3232 <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>
3233 </select>
3234 <p class="description">
3235 <?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' ); ?>
3236 </p>
3237 </td>
3238 </tr>
3239 <tr>
3240 <th scope="row"><label for="vigilante-f-firewall-ip-whitelist"><?php esc_html_e( 'IP Whitelist', 'vigilante' ); ?></label></th>
3241 <td>
3242 <textarea id="vigilante-f-firewall-ip-whitelist" 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>
3243 <p class="description">
3244 <?php esc_html_e( 'One IP per line. These IPs bypass the firewall checks, and they also reach wp-admin when the login URL is hidden, so remote managers such as MainWP or ManageWP are not turned away with a 404. The hidden login form itself stays hidden for every IP, this one included.', 'vigilante' ); ?>
3245 <br>
3246 <?php
3247 printf(
3248 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the IP, CIDR and wildcard examples. */
3249 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' ),
3250 '<code>',
3251 '</code>'
3252 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
3253 ?>
3254 </p>
3255 </td>
3256 </tr>
3257 <tr>
3258 <th scope="row"><label for="vigilante-f-firewall-ip-blacklist"><?php esc_html_e( 'IP Blacklist', 'vigilante' ); ?></label></th>
3259 <td>
3260 <textarea id="vigilante-f-firewall-ip-blacklist" 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>
3261 <p class="description">
3262 <?php esc_html_e( 'One IP per line. These IPs will be blocked immediately.', 'vigilante' ); ?>
3263 <br>
3264 <?php
3265 printf(
3266 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the IP, CIDR and wildcard examples. */
3267 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' ),
3268 '<code>',
3269 '</code>'
3270 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
3271 ?>
3272 </p>
3273 </td>
3274 </tr>
3275 </table>
3276
3277 <h3><?php esc_html_e( 'User-Agent Lists', 'vigilante' ); ?></h3>
3278 <p><?php esc_html_e( 'Partial matching: enter a keyword and any User-Agent containing it will be matched.', 'vigilante' ); ?></p>
3279 <table class="form-table">
3280 <tr>
3281 <th scope="row"><label for="vigilante-f-firewall-ua-whitelist"><?php esc_html_e( 'User-Agent Whitelist', 'vigilante' ); ?></label></th>
3282 <td>
3283 <textarea id="vigilante-f-firewall-ua-whitelist" name="firewall[ua_whitelist]" rows="4" class="large-text code"><?php echo esc_textarea( implode( "\n", $options['ua_whitelist'] ?? array() ) ); ?></textarea>
3284 <p class="description"><?php esc_html_e( 'One User-Agent per line. These will bypass all firewall checks. Example: ManageWP, MainWP, UptimeRobot.', 'vigilante' ); ?></p>
3285 </td>
3286 </tr>
3287 <tr>
3288 <th scope="row"><label for="vigilante-f-firewall-ua-blacklist"><?php esc_html_e( 'User-Agent Blacklist', 'vigilante' ); ?></label></th>
3289 <td>
3290 <textarea id="vigilante-f-firewall-ua-blacklist" name="firewall[ua_blacklist]" rows="4" class="large-text code"><?php echo esc_textarea( implode( "\n", $options['ua_blacklist'] ?? array() ) ); ?></textarea>
3291 <p class="description"><?php esc_html_e( 'One User-Agent per line. These will be blocked immediately.', 'vigilante' ); ?></p>
3292 </td>
3293 </tr>
3294 </table>
3295 </div>
3296
3297 <?php
3298 $vg_shared_locked = $this->shared_files_locked();
3299 // Paint what is actually in force, not this site's unused copy.
3300 $vg_local_options = $options;
3301 $options = $this->get_section_for_display( 'firewall' );
3302 ?>
3303 <?php $this->render_shared_files_notice(); ?>
3304 <div id="vigilante-section-firewall-server" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
3305 <h2>
3306 <?php esc_html_e( 'Server Protection', 'vigilante' ); ?>
3307 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
3308 </h2>
3309 <p><?php esc_html_e( 'Server-level rules for Apache/LiteSpeed. These rules are processed before PHP.', 'vigilante' ); ?></p>
3310
3311 <table class="form-table">
3312 <tr id="field-disable-directory-browsing">
3313 <th scope="row"><?php esc_html_e( 'Directory Browsing', 'vigilante' ); ?></th>
3314 <td>
3315 <label>
3316 <input type="checkbox" name="firewall[disable_directory_browsing]" value="1" <?php checked( ! empty( $options['disable_directory_browsing'] ) ); ?>>
3317 <?php esc_html_e( 'Disable directory listing (Options -Indexes)', 'vigilante' ); ?>
3318 </label>
3319 </td>
3320 </tr>
3321 <tr>
3322 <th scope="row"><?php esc_html_e( 'Protect wp-config.php', 'vigilante' ); ?></th>
3323 <td>
3324 <label>
3325 <input type="checkbox" name="firewall[protect_wp_config]" value="1" <?php checked( ! empty( $options['protect_wp_config'] ) ); ?>>
3326 <?php esc_html_e( 'Block direct HTTP access to wp-config.php', 'vigilante' ); ?>
3327 </label>
3328 </td>
3329 </tr>
3330 <tr id="field-protect-wp-cron">
3331 <th scope="row"><?php esc_html_e( 'Protect wp-cron.php', 'vigilante' ); ?></th>
3332 <td>
3333 <label>
3334 <input type="checkbox" name="firewall[protect_wp_cron]" value="1" <?php checked( ! empty( $options['protect_wp_cron'] ) ); ?>>
3335 <?php esc_html_e( 'Block direct HTTP access to wp-cron.php (prevents cron-spam DoS abuse)', 'vigilante' ); ?>
3336 </label>
3337 <p class="description"><?php
3338 printf(
3339 /* translators: 1: opening <strong>, 2: closing </strong> */
3340 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' ),
3341 '<strong>',
3342 '</strong>',
3343 '<code>',
3344 '</code>'
3345 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
3346 ?></p>
3347 </td>
3348 </tr>
3349 <tr>
3350 <th scope="row"><?php esc_html_e( 'Protect wp-includes', 'vigilante' ); ?></th>
3351 <td>
3352 <label>
3353 <input type="checkbox" name="firewall[protect_wp_includes]" value="1" <?php checked( ! empty( $options['protect_wp_includes'] ) ); ?>>
3354 <?php esc_html_e( 'Block direct access to PHP files in wp-includes', 'vigilante' ); ?>
3355 </label>
3356 </td>
3357 </tr>
3358 <tr>
3359 <th scope="row"><?php esc_html_e( 'PHP in Uploads', 'vigilante' ); ?></th>
3360 <td>
3361 <label>
3362 <input type="checkbox" name="firewall[protect_uploads_php]" value="1" <?php checked( ! empty( $options['protect_uploads_php'] ) ); ?>>
3363 <?php esc_html_e( 'Block PHP execution in wp-content/uploads', 'vigilante' ); ?>
3364 </label>
3365 </td>
3366 </tr>
3367 <tr>
3368 <th scope="row"><?php esc_html_e( 'Sensitive Files', 'vigilante' ); ?></th>
3369 <td>
3370 <label>
3371 <input type="checkbox" name="firewall[protect_sensitive_files]" value="1" <?php checked( ! empty( $options['protect_sensitive_files'] ) ); ?>>
3372 <?php esc_html_e( 'Block access to .sql, .bak, .log, .ini, readme.html, license.txt, licencia.txt', 'vigilante' ); ?>
3373 </label>
3374 </td>
3375 </tr>
3376 <tr>
3377 <th scope="row"><?php esc_html_e( 'Limit HTTP Methods', 'vigilante' ); ?></th>
3378 <td>
3379 <label>
3380 <input type="checkbox" name="firewall[limit_http_methods]" value="1" <?php checked( ! empty( $options['limit_http_methods'] ) ); ?>>
3381 <?php esc_html_e( 'Allow only GET, POST, HEAD (blocks PUT, DELETE, TRACE, etc.)', 'vigilante' ); ?>
3382 </label>
3383 </td>
3384 </tr>
3385 </table>
3386 </div>
3387 <?php $options = $vg_local_options; ?>
3388
3389 <p class="submit vigilante-submit-buttons">
3390 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
3391 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
3392 </button>
3393 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
3394 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
3395 </button>
3396 </p>
3397 </form>
3398 <?php
3399 }
3400
3401 /**
3402 * Render login security tab
3403 */
3404 private function render_tab_login() {
3405 $is_disabled = $this->render_module_disabled_notice( 'login_security' );
3406 $options = $this->settings->get_section( 'login_security' );
3407 $lockouts = $this->database->get_active_lockouts();
3408 ?>
3409 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="login_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
3410 <div id="vigilante-section-login-main" class="vigilante-settings-section">
3411 <h2>
3412 <?php esc_html_e( 'Login Protection', 'vigilante' ); ?>
3413 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
3414 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
3415 </h2>
3416 <p><?php esc_html_e( 'Brute force protection and WordPress login hardening.', 'vigilante' ); ?></p>
3417
3418 <table class="form-table">
3419 <tr id="field-max-attempts">
3420 <th scope="row"><label for="vigilante-f-login-security-max-attempts"><?php esc_html_e( 'Max Login Attempts', 'vigilante' ); ?></label></th>
3421 <td>
3422 <input id="vigilante-f-login-security-max-attempts" type="number" name="login_security[max_attempts]" value="<?php echo esc_attr( $options['max_attempts'] ?? 5 ); ?>" min="1" max="20" class="small-text">
3423 <p class="description"><?php esc_html_e( 'Number of failed attempts before lockout.', 'vigilante' ); ?></p>
3424 </td>
3425 </tr>
3426 <tr>
3427 <th scope="row"><label for="vigilante-f-login-security-lockout-duration"><?php esc_html_e( 'Lockout Duration', 'vigilante' ); ?></label></th>
3428 <td>
3429 <input id="vigilante-f-login-security-lockout-duration" type="number" name="login_security[lockout_duration]" value="<?php echo esc_attr( ( $options['lockout_duration'] ?? 1800 ) / 60 ); ?>" min="1" max="1440" class="small-text">
3430 <?php esc_html_e( 'minutes', 'vigilante' ); ?>
3431 </td>
3432 </tr>
3433 <tr>
3434 <th scope="row"><?php esc_html_e( 'Progressive Lockout', 'vigilante' ); ?></th>
3435 <td>
3436 <label>
3437 <input type="checkbox" name="login_security[lockout_increment]" value="1" <?php checked( ! empty( $options['lockout_increment'] ) ); ?>>
3438 <?php esc_html_e( 'Double lockout duration for repeat offenders', 'vigilante' ); ?>
3439 </label>
3440 </td>
3441 </tr>
3442 <tr>
3443 <th scope="row"><?php esc_html_e( 'Hide Login Errors', 'vigilante' ); ?></th>
3444 <td>
3445 <label>
3446 <input type="checkbox" name="login_security[hide_login_errors]" value="1" <?php checked( ! empty( $options['hide_login_errors'] ) ); ?>>
3447 <?php esc_html_e( 'Show generic error message instead of specific errors', 'vigilante' ); ?>
3448 </label>
3449 </td>
3450 </tr>
3451 <tr>
3452 <th scope="row"><?php esc_html_e( 'Disable Application Passwords', 'vigilante' ); ?></th>
3453 <td>
3454 <label>
3455 <input type="checkbox" name="login_security[disable_application_passwords]" value="1" <?php checked( ! empty( $options['disable_application_passwords'] ) ); ?>>
3456 <?php esc_html_e( 'Disable WordPress application passwords feature', 'vigilante' ); ?>
3457 </label>
3458 </td>
3459 </tr>
3460 </table>
3461
3462 <h3><?php esc_html_e( 'Custom Login URL', 'vigilante' ); ?></h3>
3463 <table class="form-table">
3464 <tr id="field-custom-login-url">
3465 <th scope="row"><?php esc_html_e( 'Login URL Slug', 'vigilante' ); ?></th>
3466 <td>
3467 <code><?php echo esc_url( home_url( '/' ) ); ?></code>
3468 <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' ); ?>">
3469 <p class="description">
3470 <?php esc_html_e( '&#9432; Leave empty to use default wp-login.php. Use only lowercase letters, numbers and hyphens.', 'vigilante' ); ?>
3471 </p>
3472 <div class="vigilante-login-url-preview" <?php echo empty( $options['custom_login_url'] ) ? 'style="display:none;"' : ''; ?>>
3473 <p class="description">
3474 <strong><?php esc_html_e( 'Your login URL:', 'vigilante' ); ?></strong>
3475 <code class="vigilante-login-url-display"><?php echo esc_url( home_url( sanitize_title( $options['custom_login_url'] ?? '' ) . '/' ) ); ?></code>
3476 </p>
3477 <p class="description">
3478 <?php esc_html_e( 'Direct access to wp-login.php and wp-admin will return a 404 error for non-logged users.', 'vigilante' ); ?>
3479 </p>
3480 <p class="description">
3481 <?php esc_html_e( 'An IP in the firewall whitelist is still allowed into wp-admin, so remote managers keep working, but it does not get the login form: the hidden URL is the only way in for everyone.', 'vigilante' ); ?>
3482 </p>
3483 </div>
3484 </td>
3485 </tr>
3486 </table>
3487
3488 <div class="vigilante-login-url-notify-wrapper <?php echo empty( $options['custom_login_url'] ) ? 'vigilante-login-url-notify-disabled' : ''; ?>">
3489 <table class="form-table">
3490 <tr>
3491 <th scope="row"><?php esc_html_e( 'Notify users', 'vigilante' ); ?></th>
3492 <td>
3493 <label>
3494 <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 ); ?>>
3495 <?php esc_html_e( 'Notify affected users when the login URL changes', 'vigilante' ); ?>
3496 </label>
3497 <div class="vigilante-login-url-send-notification" style="margin-top:12px;">
3498 <button type="button" id="vigilante_notify_login_url" class="button">
3499 <?php esc_html_e( 'Send notification now', 'vigilante' ); ?>
3500 </button>
3501 <span class="vigilante-login-url-notify-status"></span>
3502 <p class="description"><?php esc_html_e( 'Sends the new URL to administrators, editors, authors, and contributors.', 'vigilante' ); ?></p>
3503 </div>
3504 </td>
3505 </tr>
3506 </table>
3507 </div>
3508
3509 <?php $this->render_2fa_settings( $options ); ?>
3510
3511 <h3><?php esc_html_e( 'Notifications', 'vigilante' ); ?></h3>
3512 <table class="form-table">
3513 <tr>
3514 <th scope="row"><?php esc_html_e( 'Notify on Lockout', 'vigilante' ); ?></th>
3515 <td>
3516 <label>
3517 <input type="checkbox" name="login_security[notify_on_lockout]" value="1" <?php checked( ! empty( $options['notify_on_lockout'] ) ); ?>>
3518 <?php esc_html_e( 'Send email when an IP is locked out', 'vigilante' ); ?>
3519 </label>
3520 </td>
3521 </tr>
3522 <tr>
3523 <th scope="row"><?php esc_html_e( 'Notify on Admin Login', 'vigilante' ); ?></th>
3524 <td>
3525 <label>
3526 <input type="checkbox" name="login_security[notify_on_admin_login]" value="1" <?php checked( ! empty( $options['notify_on_admin_login'] ) ); ?>>
3527 <?php esc_html_e( 'Send email when an administrator logs in', 'vigilante' ); ?>
3528 </label>
3529 </td>
3530 </tr>
3531 </table>
3532
3533 <p class="description">
3534 <?php
3535 printf(
3536 /* translators: %s: Link to notification settings */
3537 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
3538 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
3539 );
3540 ?>
3541 </p>
3542 </div>
3543
3544 <p class="submit vigilante-submit-buttons">
3545 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
3546 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
3547 </button>
3548 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
3549 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
3550 </button>
3551 </p>
3552 </form>
3553
3554 <?php $this->render_lockout_info_section( $options, $lockouts ); ?>
3555 <?php
3556 }
3557
3558 /**
3559 * Render lockout information and blocked IPs section
3560 *
3561 * @param array $options Login security options.
3562 * @param array $lockouts Currently locked out IPs.
3563 */
3564 private function render_lockout_info_section( $options, $lockouts ) {
3565 $max_attempts = absint( $options['max_attempts'] ?? 5 );
3566 $lockout_duration = absint( $options['lockout_duration'] ?? 1800 );
3567 $lockout_increment = ! empty( $options['lockout_increment'] );
3568 $max_lockout = absint( $options['max_lockout_duration'] ?? 86400 );
3569 $two_factor = $options['two_factor'] ?? array();
3570 $two_factor_enabled = ! empty( $two_factor['enabled'] );
3571 ?>
3572 <div class="vigilante-settings-section vigilante-lockout-section">
3573 <h2 id="vigilante-section-login-status"><?php esc_html_e( 'Login Protection Status', 'vigilante' ); ?></h2>
3574
3575 <table class="form-table">
3576 <tr>
3577 <th scope="row"><?php esc_html_e( 'Current settings', 'vigilante' ); ?></th>
3578 <td>
3579 <?php
3580 printf(
3581 /* translators: 1: Maximum login attempts, 2: Lockout duration in minutes */
3582 esc_html__( 'After %1$d failed login attempts, the IP address is blocked for %2$d minutes.', 'vigilante' ),
3583 absint( $max_attempts ),
3584 absint( ceil( $lockout_duration / 60 ) )
3585 );
3586
3587 if ( $lockout_increment ) {
3588 echo '<br>';
3589 printf(
3590 /* translators: %d: Maximum lockout duration in hours */
3591 esc_html__( 'Progressive lockout enabled (max: %d hours).', 'vigilante' ),
3592 absint( ceil( $max_lockout / 3600 ) )
3593 );
3594 }
3595
3596 if ( $two_factor_enabled ) {
3597 echo '<br>';
3598 esc_html_e( 'Failed 2FA codes also count toward the lockout limit.', 'vigilante' );
3599 }
3600 ?>
3601 </td>
3602 </tr>
3603 <tr>
3604 <th scope="row"><?php esc_html_e( 'Blocked IPs', 'vigilante' ); ?></th>
3605 <td>
3606 <?php if ( ! empty( $lockouts ) ) : ?>
3607 <div class="vigilante-paginated-section">
3608 <div class="vigilante-fi-pagination-wrap"></div>
3609 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
3610 <thead>
3611 <tr>
3612 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
3613 <th><?php esc_html_e( 'Attempts', 'vigilante' ); ?></th>
3614 <th><?php esc_html_e( 'Blocked Until', 'vigilante' ); ?></th>
3615 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
3616 </tr>
3617 </thead>
3618 <tbody>
3619 <?php foreach ( $lockouts as $lockout ) :
3620 $lockout_time = strtotime( $lockout->locked_until );
3621 $remaining_seconds = $lockout_time - time();
3622 $remaining_text = $this->format_remaining_time( $remaining_seconds );
3623 ?>
3624 <tr>
3625 <td><code><?php echo esc_html( $lockout->ip_address ); ?></code></td>
3626 <td><?php echo esc_html( $lockout->attempts ); ?></td>
3627 <td>
3628 <?php echo esc_html( wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $lockout_time ) ); ?>
3629 <br>
3630 <small class="description">
3631 <?php
3632 printf(
3633 /* translators: %s: Remaining time */
3634 esc_html__( '%s remaining', 'vigilante' ),
3635 esc_html( $remaining_text )
3636 );
3637 ?>
3638 </small>
3639 </td>
3640 <td>
3641 <button type="button" class="button button-small vigilante-clear-lockout" data-ip="<?php echo esc_attr( $lockout->ip_address ); ?>">
3642 <?php esc_html_e( 'Unblock', 'vigilante' ); ?>
3643 </button>
3644 </td>
3645 </tr>
3646 <?php endforeach; ?>
3647 </tbody>
3648 </table>
3649 </div>
3650 <p class="description" style="margin-top: 10px;">
3651 <button type="button" class="button vigilante-clear-all-lockouts">
3652 <?php esc_html_e( 'Unblock All IPs', 'vigilante' ); ?>
3653 </button>
3654 <span style="margin-left: 10px;">
3655 <?php
3656 printf(
3657 /* translators: %d: Number of blocked IPs */
3658 esc_html( _n( '%d IP currently blocked', '%d IPs currently blocked', count( $lockouts ), 'vigilante' ) ),
3659 count( $lockouts )
3660 );
3661 ?>
3662 </span>
3663 </p>
3664 <?php else : ?>
3665 <span class="dashicons dashicons-yes-alt" style="color: #00a32a; font-size: 20px; width: 20px; height: 20px; vertical-align: middle;"></span>
3666 <span style="vertical-align: middle; margin-left: 5px;"><?php esc_html_e( 'No IPs are currently blocked. All clear!', 'vigilante' ); ?></span>
3667 <?php endif; ?>
3668 </td>
3669 </tr>
3670 </table>
3671 </div>
3672 <?php
3673 }
3674
3675 /**
3676 * Format remaining lockout time in human readable format
3677 *
3678 * @param int $seconds Remaining seconds.
3679 * @return string Formatted time string.
3680 */
3681 private function format_remaining_time( $seconds ) {
3682 if ( $seconds <= 0 ) {
3683 return __( 'expired', 'vigilante' );
3684 }
3685
3686 if ( $seconds < 60 ) {
3687 return sprintf(
3688 /* translators: %d: Number of seconds */
3689 _n( '%d second', '%d seconds', $seconds, 'vigilante' ),
3690 $seconds
3691 );
3692 }
3693
3694 if ( $seconds < 3600 ) {
3695 $minutes = ceil( $seconds / 60 );
3696 return sprintf(
3697 /* translators: %d: Number of minutes */
3698 _n( '%d minute', '%d minutes', $minutes, 'vigilante' ),
3699 $minutes
3700 );
3701 }
3702
3703 $hours = floor( $seconds / 3600 );
3704 $remaining_minutes = ceil( ( $seconds % 3600 ) / 60 );
3705
3706 if ( $remaining_minutes > 0 ) {
3707 return sprintf(
3708 /* translators: 1: Number of hours, 2: Number of minutes */
3709 __( '%1$d hours %2$d minutes', 'vigilante' ),
3710 $hours,
3711 $remaining_minutes
3712 );
3713 }
3714
3715 return sprintf(
3716 /* translators: %d: Number of hours */
3717 _n( '%d hour', '%d hours', $hours, 'vigilante' ),
3718 $hours
3719 );
3720 }
3721
3722 /**
3723 * Render 2FA settings section
3724 *
3725 * @param array $options Login security options.
3726 */
3727 private function render_2fa_settings( $options ) {
3728 $two_factor = $options['two_factor'] ?? array();
3729 $all_roles = wp_roles()->roles;
3730 $enforced = $two_factor['enforced_roles'] ?? array( 'administrator', 'editor' );
3731 $excluded = $two_factor['excluded_users'] ?? array();
3732 $method = $two_factor['method'] ?? 'email';
3733 $grace_days = $two_factor['grace_period_days'] ?? 3;
3734 ?>
3735 <h3 id="vigilante-section-login-2fa">
3736 <?php esc_html_e( 'Two-Factor Authentication (2FA)', 'vigilante' ); ?>
3737 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
3738 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
3739 </h3>
3740 <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>
3741
3742 <table class="form-table">
3743 <tr>
3744 <th scope="row"><?php esc_html_e( 'Enable 2FA', 'vigilante' ); ?></th>
3745 <td>
3746 <label>
3747 <input type="checkbox" name="login_security[two_factor][enabled]" id="vigilante_2fa_enabled" value="1" <?php checked( ! empty( $two_factor['enabled'] ) ); ?>>
3748 <?php esc_html_e( 'Enable two-factor authentication', 'vigilante' ); ?>
3749 </label>
3750 </td>
3751 </tr>
3752 </table>
3753
3754 <div class="vigilante-2fa-settings-wrapper <?php echo empty( $two_factor['enabled'] ) ? 'vigilante-2fa-settings-disabled' : ''; ?>">
3755 <table class="form-table">
3756 <tr>
3757 <th scope="row"><?php esc_html_e( 'Verification method', 'vigilante' ); ?></th>
3758 <td>
3759 <fieldset class="vigilante-2fa-method-selector">
3760 <label class="vigilante-2fa-method-option <?php echo 'email' === $method ? 'selected' : ''; ?>">
3761 <input type="radio" name="login_security[two_factor][method]" value="email" <?php checked( $method, 'email' ); ?>>
3762 <span class="dashicons dashicons-email"></span>
3763 <span class="method-info">
3764 <strong><?php esc_html_e( 'Email code', 'vigilante' ); ?></strong>
3765 <span><?php esc_html_e( 'Users receive a 6-digit code via email after entering their password.', 'vigilante' ); ?></span>
3766 </span>
3767 </label>
3768 <label class="vigilante-2fa-method-option <?php echo 'totp' === $method ? 'selected' : ''; ?>">
3769 <input type="radio" name="login_security[two_factor][method]" value="totp" <?php checked( $method, 'totp' ); ?>>
3770 <span class="dashicons dashicons-smartphone"></span>
3771 <span class="method-info">
3772 <strong><?php esc_html_e( 'Authenticator app (TOTP)', 'vigilante' ); ?></strong>
3773 <span><?php esc_html_e( 'Users verify with a time-based code from Google Authenticator, Authy, etc.', 'vigilante' ); ?></span>
3774 </span>
3775 </label>
3776 </fieldset>
3777 </td>
3778 </tr>
3779 <tr>
3780 <th scope="row"><?php esc_html_e( 'Enforce for roles', 'vigilante' ); ?></th>
3781 <td>
3782 <div class="vigilante-2fa-roles">
3783 <?php foreach ( $all_roles as $role_slug => $role_data ) :
3784 $user_count = count( get_users( array( 'role' => $role_slug, 'fields' => 'ID' ) ) );
3785 ?>
3786 <label>
3787 <input type="checkbox"
3788 name="login_security[two_factor][enforced_roles][]"
3789 value="<?php echo esc_attr( $role_slug ); ?>"
3790 <?php checked( in_array( $role_slug, $enforced, true ) ); ?>>
3791 <span class="role-name"><?php echo esc_html( translate_user_role( $role_data['name'] ) ); ?></span>
3792 <span class="role-count">(<?php echo esc_html( $user_count ); ?>)</span>
3793 </label>
3794 <?php endforeach; ?>
3795 </div>
3796 <p class="description"><?php esc_html_e( 'Users with these roles will be required to verify with the selected method.', 'vigilante' ); ?></p>
3797 </td>
3798 </tr>
3799 <tr>
3800 <th scope="row"><?php esc_html_e( 'Exclude specific users', 'vigilante' ); ?></th>
3801 <td>
3802 <div class="vigilante-2fa-user-search-container">
3803 <div class="vigilante-2fa-user-search">
3804 <span class="search-icon"></span>
3805 <input type="text"
3806 id="vigilante_2fa_user_search"
3807 placeholder="<?php esc_attr_e( 'Search users by name or email...', 'vigilante' ); ?>"
3808 autocomplete="off">
3809 <div class="vigilante-2fa-search-results"></div>
3810 </div>
3811 <div class="vigilante-2fa-excluded-users">
3812 <?php
3813 foreach ( $excluded as $user_id ) :
3814 $user = get_user_by( 'ID', $user_id );
3815 if ( ! $user ) continue;
3816 ?>
3817 <div class="vigilante-2fa-excluded-user" data-user-id="<?php echo esc_attr( $user_id ); ?>">
3818 <span class="user-display"><?php echo esc_html( $user->display_name . ' (' . $user->user_email . ')' ); ?></span>
3819 <button type="button" class="remove-user" aria-label="<?php esc_attr_e( 'Remove', 'vigilante' ); ?>">&times;</button>
3820 <input type="hidden" name="login_security[two_factor][excluded_users][]" value="<?php echo esc_attr( $user_id ); ?>">
3821 </div>
3822 <?php endforeach; ?>
3823 </div>
3824 </div>
3825 <p class="description"><?php esc_html_e( 'These users will not be required to use 2FA regardless of their role.', 'vigilante' ); ?></p>
3826 </td>
3827 </tr>
3828
3829 <!-- Remember device option -->
3830 <tr>
3831 <th scope="row"><?php esc_html_e( 'Remember device', 'vigilante' ); ?></th>
3832 <td>
3833 <label>
3834 <input type="checkbox" name="login_security[two_factor][allow_remember_device]" value="1" <?php checked( ! empty( $two_factor['allow_remember_device'] ) ); ?>>
3835 <?php esc_html_e( 'Allow users to skip 2FA verification on trusted devices', 'vigilante' ); ?>
3836 </label>
3837 <p class="description">
3838 <?php
3839 printf(
3840 /* translators: %d: Number of days */
3841 esc_html__( 'When enabled, users can check "Remember this device" on the verification screen to skip 2FA for %d days.', 'vigilante' ),
3842 absint( $two_factor['remember_device_days'] ?? 30 )
3843 );
3844 ?>
3845 </p>
3846 </td>
3847 </tr>
3848
3849 <!-- TOTP-specific: Grace period -->
3850 <tr class="vigilante-2fa-totp-only" <?php echo 'totp' !== $method ? 'style="display:none;"' : ''; ?>>
3851 <th scope="row"><label for="vigilante-f-login-security-two-factor-grace-period-days"><?php esc_html_e( 'Grace period', 'vigilante' ); ?></label></th>
3852 <td>
3853 <input id="vigilante-f-login-security-two-factor-grace-period-days" type="number"
3854 name="login_security[two_factor][grace_period_days]"
3855 value="<?php echo esc_attr( $grace_days ); ?>"
3856 min="0" max="30" class="small-text">
3857 <?php esc_html_e( 'days', 'vigilante' ); ?>
3858 <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>
3859 </td>
3860 </tr>
3861
3862 <!-- Email-specific: Sender name -->
3863 <tr class="vigilante-2fa-email-only" <?php echo 'email' !== $method ? 'style="display:none;"' : ''; ?>>
3864 <th scope="row"><label for="vigilante-f-login-security-two-factor-email-from-name"><?php esc_html_e( 'Email sender name', 'vigilante' ); ?></label></th>
3865 <td>
3866 <input id="vigilante-f-login-security-two-factor-email-from-name" type="text"
3867 name="login_security[two_factor][email_from_name]"
3868 value="<?php echo esc_attr( $two_factor['email_from_name'] ?? '' ); ?>"
3869 class="regular-text vigilante-2fa-email-from"
3870 placeholder="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>">
3871 <p class="description"><?php esc_html_e( 'Name shown in verification emails. Leave empty to use site name.', 'vigilante' ); ?></p>
3872 </td>
3873 </tr>
3874
3875 <!-- TOTP-specific: Reset users -->
3876 <tr class="vigilante-2fa-totp-only" <?php echo 'totp' !== $method ? 'style="display:none;"' : ''; ?>>
3877 <th scope="row"><?php esc_html_e( 'Reset user TOTP', 'vigilante' ); ?></th>
3878 <td>
3879 <div class="vigilante-totp-reset-container">
3880 <div class="vigilante-2fa-user-search">
3881 <span class="search-icon"></span>
3882 <input type="text"
3883 id="vigilante_totp_reset_search"
3884 placeholder="<?php esc_attr_e( 'Search users with TOTP configured...', 'vigilante' ); ?>"
3885 autocomplete="off">
3886 <div class="vigilante-totp-reset-results"></div>
3887 </div>
3888 <div class="vigilante-totp-reset-selected"></div>
3889 <button type="button" id="vigilante_totp_reset_btn" class="button" style="display:none;">
3890 <?php esc_html_e( 'Reset selected', 'vigilante' ); ?>
3891 </button>
3892 <span class="vigilante-totp-reset-status"></span>
3893 </div>
3894 <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>
3895 </td>
3896 </tr>
3897 </table>
3898
3899 <h3><?php esc_html_e( 'User notification', 'vigilante' ); ?></h3>
3900 <table class="form-table">
3901 <tr>
3902 <th scope="row"><?php esc_html_e( 'Notify on enable', 'vigilante' ); ?></th>
3903 <td>
3904 <label>
3905 <input type="checkbox" name="login_security[two_factor][notify_on_enable]" value="1" <?php checked( $two_factor['notify_on_enable'] ?? true ); ?>>
3906 <?php esc_html_e( 'Send notification email to affected users when 2FA is enabled', 'vigilante' ); ?>
3907 </label>
3908
3909 <div class="vigilante-2fa-notification-options">
3910 <label>
3911 <input type="radio" name="vigilante_2fa_notify_mode" value="all" checked>
3912 <?php esc_html_e( 'Send to all affected users', 'vigilante' ); ?>
3913 </label>
3914 <label>
3915 <input type="radio" name="vigilante_2fa_notify_mode" value="new">
3916 <?php esc_html_e( 'Send only to users not previously notified', 'vigilante' ); ?>
3917 </label>
3918 </div>
3919
3920 <div class="vigilante-2fa-send-notification">
3921 <button type="button" id="vigilante_2fa_send_notification" class="button">
3922 <?php esc_html_e( 'Send notification now', 'vigilante' ); ?>
3923 </button>
3924 <span class="vigilante-2fa-notification-status"></span>
3925 </div>
3926 </td>
3927 </tr>
3928 </table>
3929 </div>
3930 <?php
3931 }
3932
3933 /**
3934 * Render security headers tab
3935 */
3936 /**
3937 * Offer back the header settings the 2.9.8 migration wiped.
3938 *
3939 * Rendered outside the settings form on purpose, so its buttons can never
3940 * submit it, and only when there is something to actually change. Shows the
3941 * difference before anything is written: nothing is applied that the owner
3942 * has not seen first.
3943 *
3944 * @since 2.10.0
3945 */
3946 private function render_headers_recovery_offer() {
3947 /*
3948 * On a network the .htaccess belongs to every site and only the main one
3949 * writes it, so this is not a decision a subsite gets to make. Its own
3950 * security_headers options are inert anyway: what the network serves
3951 * comes from the file the main site owns. Without this gate a subsite
3952 * administrator was shown a Restore button that could only ever answer
3953 * with a permission error, which is worse than showing nothing.
3954 */
3955 if ( ! Vigilante_Settings::can_write_shared_files() ) {
3956 return;
3957 }
3958
3959 if ( ! Vigilante_Htaccess_Recovery::is_available() ) {
3960 /*
3961 * Already restored. Offer to take it back for as long as the previous
3962 * section is still stored: a restore that cannot be undone is a second
3963 * irreversible change on top of the one being repaired.
3964 */
3965 if ( Vigilante_Htaccess_Recovery::has_undo() ) {
3966 ?>
3967 <div class="notice notice-info inline" id="vigilante-headers-recovery-undo">
3968 <p>
3969 <?php esc_html_e( 'The Security Headers settings were restored from the copy Vigilant had kept of your .htaccess.', 'vigilante' ); ?>
3970 <button type="button" class="button button-small" id="vigilante-recovery-undo">
3971 <?php esc_html_e( 'Undo the restore', 'vigilante' ); ?>
3972 </button>
3973 </p>
3974 </div>
3975 <?php
3976 }
3977
3978 return;
3979 }
3980
3981 $rows = Vigilante_Htaccess_Recovery::get_diff( $this->settings );
3982
3983 if ( empty( $rows ) ) {
3984 return;
3985 }
3986
3987 $snapshot = Vigilante_Htaccess_Recovery::get_snapshot();
3988 $taken = isset( $snapshot['time'] ) ? (int) $snapshot['time'] : 0;
3989 $block = Vigilante_Htaccess_Recovery::get_raw_block();
3990 ?>
3991 <div class="vigilante-settings-section" id="vigilante-headers-recovery">
3992 <h2><?php esc_html_e( 'Recover your previous header settings', 'vigilante' ); ?></h2>
3993 <p>
3994 <?php esc_html_e( 'Updating to 2.9.8 reset this tab to factory values: the migration replaced the whole section instead of merging into it. Your server kept sending the right headers, because the .htaccess had not been rewritten yet, so Vigilant saved a copy of that file before touching it. These are the settings it found in that copy.', 'vigilante' ); ?>
3995 </p>
3996 <?php if ( $taken ) : ?>
3997 <p class="description">
3998 <?php
3999 printf(
4000 /* translators: %s: date and time the .htaccess copy was taken. */
4001 esc_html__( 'Copy taken on %s.', 'vigilante' ),
4002 esc_html( wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $taken ) )
4003 );
4004 ?>
4005 </p>
4006 <?php endif; ?>
4007
4008 <table class="widefat striped">
4009 <thead>
4010 <tr>
4011 <th scope="col"><?php esc_html_e( 'Setting', 'vigilante' ); ?></th>
4012 <th scope="col"><?php esc_html_e( 'Now', 'vigilante' ); ?></th>
4013 <th scope="col"><?php esc_html_e( 'Would be restored to', 'vigilante' ); ?></th>
4014 </tr>
4015 </thead>
4016 <tbody>
4017 <?php foreach ( $rows as $row ) : ?>
4018 <tr>
4019 <th scope="row"><?php echo esc_html( $row['label'] ); ?></th>
4020 <td><?php echo esc_html( $row['current'] ); ?></td>
4021 <td>
4022 <?php echo esc_html( $row['recovered'] ); ?>
4023 <?php if ( ! empty( $row['detail'] ) ) : ?>
4024 <br><span class="description"><?php echo esc_html( $row['detail'] ); ?></span>
4025 <?php endif; ?>
4026 </td>
4027 </tr>
4028 <?php endforeach; ?>
4029 </tbody>
4030 </table>
4031
4032 <p class="description">
4033 <?php esc_html_e( 'Only these settings are written. The .htaccess is then rebuilt from them, the same way saving this tab rebuilds it. The stored copy of the file is never written back, so nothing your host, your cache plugin or your CDN added to it is touched.', 'vigilante' ); ?>
4034 </p>
4035
4036 <?php if ( '' !== $block ) : ?>
4037 <details>
4038 <summary><?php esc_html_e( 'Show the saved .htaccess block', 'vigilante' ); ?></summary>
4039 <textarea readonly rows="12" class="large-text code" onclick="this.select();"><?php echo esc_textarea( $block ); ?></textarea>
4040 </details>
4041 <?php endif; ?>
4042
4043 <p class="submit vigilante-submit-buttons">
4044 <button type="button" class="button button-primary" id="vigilante-recovery-restore">
4045 <?php esc_html_e( 'Restore these settings', 'vigilante' ); ?>
4046 </button>
4047 <button type="button" class="button" id="vigilante-recovery-dismiss">
4048 <?php esc_html_e( 'No thanks, keep what I have', 'vigilante' ); ?>
4049 </button>
4050 </p>
4051 <div id="vigilante-recovery-result"></div>
4052 </div>
4053 <?php
4054 }
4055
4056 private function render_tab_headers() {
4057 $is_disabled = $this->render_module_disabled_notice( 'security_headers' );
4058 // Every setting on this tab ends up in .htaccess, so on a subsite the
4059 // whole tab is somebody else's, values included.
4060 $vg_shared_locked = $this->shared_files_locked();
4061 $options = $this->get_section_for_display( 'security_headers' );
4062 ?>
4063 <?php $this->render_headers_recovery_offer(); ?>
4064
4065 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="security_headers" <?php echo $is_disabled ? 'inert' : ''; ?>>
4066 <?php $this->render_shared_files_notice(); ?>
4067 <div id="vigilante-section-headers-main" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
4068 <h2>
4069 <?php esc_html_e( 'Security Headers', 'vigilante' ); ?>
4070 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
4071 </h2>
4072 <p><?php esc_html_e( 'HTTP headers sent with every response via .htaccess (mod_headers).', 'vigilante' ); ?></p>
4073
4074 <table class="form-table">
4075 <tr>
4076 <th scope="row"><label for="vigilante-f-security-headers-x-frame-options"><?php esc_html_e( 'X-Frame-Options', 'vigilante' ); ?></label></th>
4077 <td>
4078 <select id="vigilante-f-security-headers-x-frame-options" name="security_headers[x_frame_options]">
4079 <option value="" <?php selected( empty( $options['x_frame_options'] ) ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
4080 <option value="SAMEORIGIN" <?php selected( $options['x_frame_options'] ?? '', 'SAMEORIGIN' ); ?>>SAMEORIGIN</option>
4081 <option value="DENY" <?php selected( $options['x_frame_options'] ?? '', 'DENY' ); ?>>DENY</option>
4082 </select>
4083 <p class="description"><?php esc_html_e( '&#9432; Prevents clickjacking attacks. Also sets CSP frame-ancestors automatically.', 'vigilante' ); ?></p>
4084 </td>
4085 </tr>
4086 <tr>
4087 <th scope="row"><?php esc_html_e( 'X-Content-Type-Options', 'vigilante' ); ?></th>
4088 <td>
4089 <label>
4090 <input type="checkbox" name="security_headers[x_content_type_options]" value="1" <?php checked( ! empty( $options['x_content_type_options'] ) ); ?>>
4091 <?php esc_html_e( 'Add nosniff header to prevent MIME type sniffing', 'vigilante' ); ?>
4092 </label>
4093 </td>
4094 </tr>
4095 <tr>
4096 <th scope="row"><label for="vigilante-f-security-headers-referrer-policy"><?php esc_html_e( 'Referrer-Policy', 'vigilante' ); ?></label></th>
4097 <td>
4098 <select id="vigilante-f-security-headers-referrer-policy" name="security_headers[referrer_policy]">
4099 <option value="" <?php selected( empty( $options['referrer_policy'] ) ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
4100 <option value="no-referrer" <?php selected( $options['referrer_policy'] ?? '', 'no-referrer' ); ?>>no-referrer</option>
4101 <option value="strict-origin-when-cross-origin" <?php selected( $options['referrer_policy'] ?? '', 'strict-origin-when-cross-origin' ); ?>>strict-origin-when-cross-origin</option>
4102 <option value="same-origin" <?php selected( $options['referrer_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
4103 </select>
4104 </td>
4105 </tr>
4106 </table>
4107
4108 <h3 id="vigilante-section-headers-csp"><?php esc_html_e( 'Content Security Policy', 'vigilante' ); ?></h3>
4109 <table class="form-table">
4110 <tr>
4111 <th scope="row"><?php esc_html_e( 'Enable CSP', 'vigilante' ); ?></th>
4112 <td>
4113 <label>
4114 <input type="checkbox" name="security_headers[csp][enabled]" value="1" <?php checked( ! empty( $options['csp']['enabled'] ) ); ?>>
4115 <?php esc_html_e( 'Enable Content Security Policy', 'vigilante' ); ?>
4116 </label>
4117 </td>
4118 </tr>
4119 <tr>
4120 <th scope="row"><?php esc_html_e( 'Report Only Mode', 'vigilante' ); ?></th>
4121 <td>
4122 <label>
4123 <input type="checkbox" name="security_headers[csp][report_only]" value="1" <?php checked( ! empty( $options['csp']['report_only'] ) ); ?>>
4124 <?php esc_html_e( 'Report violations without blocking (for testing)', 'vigilante' ); ?>
4125 </label>
4126 </td>
4127 </tr>
4128 </table>
4129
4130 <h3 id="vigilante-section-headers-force-https"><?php esc_html_e( 'HTTPS', 'vigilante' ); ?></h3>
4131 <p class="description"><?php esc_html_e( 'HTTPS is strongly recommended, but Vigilant will not impose it. Enable only what your site already supports.', 'vigilante' ); ?></p>
4132 <table class="form-table">
4133 <tr>
4134 <th scope="row"><?php esc_html_e( 'Redirect HTTP to HTTPS', 'vigilante' ); ?></th>
4135 <td>
4136 <label>
4137 <input type="checkbox" name="security_headers[redirect_http_to_https]" value="1" <?php checked( ! empty( $options['redirect_http_to_https'] ) ); ?>>
4138 <?php esc_html_e( 'Send visitors arriving over HTTP to the HTTPS address', 'vigilante' ); ?>
4139 </label>
4140 <p class="description"><?php esc_html_e( 'Only applies when the site address is already an https:// one. On a site still published over HTTP it does nothing, so it cannot leave the site unreachable.', 'vigilante' ); ?></p>
4141 </td>
4142 </tr>
4143 <tr>
4144 <th scope="row"><?php esc_html_e( 'Fix Mixed Content', 'vigilante' ); ?></th>
4145 <td>
4146 <label>
4147 <input type="checkbox" name="security_headers[fix_mixed_content]" value="1" <?php checked( ! empty( $options['fix_mixed_content'] ) ); ?>>
4148 <?php esc_html_e( 'Rewrite this site http:// resources to https://', 'vigilante' ); ?>
4149 </label>
4150 <p class="description"><?php esc_html_e( 'Off by default. Only touches addresses of this same site, and only when the site is already served over HTTPS, so it cannot break an external resource. Useful right after moving a site to HTTPS, when old content still points at http:// addresses.', 'vigilante' ); ?></p>
4151 </td>
4152 </tr>
4153 <tr id="field-upgrade-insecure-requests">
4154 <th scope="row"><?php esc_html_e( 'Upgrade Insecure Requests', 'vigilante' ); ?></th>
4155 <td>
4156 <label>
4157 <input type="checkbox" name="security_headers[upgrade_insecure_requests]" value="1" <?php checked( ! empty( $options['upgrade_insecure_requests'] ) ); ?>>
4158 <?php esc_html_e( 'Ask browsers to upgrade every http:// request to https://', 'vigilante' ); ?>
4159 </label>
4160 <p class="description"><?php esc_html_e( '&#9888; Off by default. This one also covers resources hosted elsewhere: anything served from a domain with no HTTPS stops loading instead of loading insecurely. Turn it on once you know every external resource the site uses is available over HTTPS.', 'vigilante' ); ?></p>
4161 </td>
4162 </tr>
4163 <tr>
4164 <th scope="row"><?php esc_html_e( 'Rewrite Site Address on Activation', 'vigilante' ); ?></th>
4165 <td>
4166 <label>
4167 <input type="checkbox" name="security_headers[force_https]" value="1" <?php checked( ! empty( $options['force_https'] ) ); ?>>
4168 <?php esc_html_e( 'Change the WordPress and site addresses to https:// when the plugin is activated', 'vigilante' ); ?>
4169 </label>
4170 <p class="description"><?php esc_html_e( '&#9888; Off by default. This writes to the WordPress Address and Site Address settings, and turning the plugin off later does not undo it. It only runs on activation, and only when the site answers over HTTPS.', 'vigilante' ); ?></p>
4171 </td>
4172 </tr>
4173 </table>
4174
4175 <h3 id="vigilante-section-headers-hsts"><?php esc_html_e( 'HSTS (HTTP Strict Transport Security)', 'vigilante' ); ?></h3>
4176 <?php $vig_home_https = ( 0 === strpos( (string) get_option( 'home' ), 'https://' ) ); ?>
4177 <p class="description"><?php esc_html_e( 'Tells browsers to reach this site over HTTPS and never over HTTP, for as long as the max age below.', 'vigilante' ); ?></p>
4178 <?php if ( ! $vig_home_https ) : ?>
4179 <p class="description" style="color:#b32d2e"><strong><?php esc_html_e( 'Unavailable: the site address still starts with http://. Enabling HSTS on a site not published over HTTPS would make it unreachable in any browser that honours it.', 'vigilante' ); ?></strong></p>
4180 <?php endif; ?>
4181 <table class="form-table">
4182 <tr>
4183 <th scope="row"><?php esc_html_e( 'Enable HSTS', 'vigilante' ); ?></th>
4184 <td>
4185 <?php if ( ! $vig_home_https ) : ?>
4186 <?php /* A disabled checkbox is not submitted, and a boolean missing from the post is treated as unticked, so saving the tab would silently switch HSTS off. Carry the stored value instead. */ ?>
4187 <input type="hidden" name="security_headers[hsts][enabled]" value="<?php echo ! empty( $options['hsts']['enabled'] ) ? '1' : '0'; ?>">
4188 <?php endif; ?>
4189 <label>
4190 <input type="checkbox" name="security_headers[hsts][enabled]" value="1" <?php checked( ! empty( $options['hsts']['enabled'] ) ); ?> <?php disabled( ! $vig_home_https ); ?>>
4191 <?php esc_html_e( 'Send the Strict-Transport-Security header', 'vigilante' ); ?>
4192 </label>
4193 <p class="description"><?php esc_html_e( '&#9888; Hard to undo: browsers remember it for the whole max age even if you turn it off later, so a site that loses its certificate stays unreachable until it expires. Start with a short max age.', 'vigilante' ); ?></p>
4194 </td>
4195 </tr>
4196 <tr>
4197 <th scope="row"><label for="vigilante-f-security-headers-hsts-max-age"><?php esc_html_e( 'Max Age', 'vigilante' ); ?></label></th>
4198 <td>
4199 <select id="vigilante-f-security-headers-hsts-max-age" name="security_headers[hsts][max_age]">
4200 <option value="86400" <?php selected( $options['hsts']['max_age'] ?? 31536000, 86400 ); ?>><?php esc_html_e( '1 day (testing)', 'vigilante' ); ?></option>
4201 <option value="2592000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 2592000 ); ?>><?php esc_html_e( '30 days', 'vigilante' ); ?></option>
4202 <option value="31536000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 31536000 ); ?>><?php esc_html_e( '1 year (recommended)', 'vigilante' ); ?></option>
4203 <option value="63072000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 63072000 ); ?>><?php esc_html_e( '2 years', 'vigilante' ); ?></option>
4204 </select>
4205 </td>
4206 </tr>
4207 <tr>
4208 <th scope="row"><?php esc_html_e( 'Include Subdomains', 'vigilante' ); ?></th>
4209 <td>
4210 <label>
4211 <input type="checkbox" name="security_headers[hsts][include_subdomains]" value="1" <?php checked( ! empty( $options['hsts']['include_subdomains'] ) ); ?>>
4212 <?php esc_html_e( 'Apply HSTS to all subdomains', 'vigilante' ); ?>
4213 </label>
4214 </td>
4215 </tr>
4216 </table>
4217
4218 <h3 id="vigilante-section-headers-fingerprint"><?php esc_html_e( 'Server Identity', 'vigilante' ); ?></h3>
4219 <p class="description"><?php esc_html_e( 'Hide identifying information that servers expose in responses.', 'vigilante' ); ?></p>
4220 <table class="form-table">
4221 <tr>
4222 <th scope="row"><?php esc_html_e( 'Server Signature', 'vigilante' ); ?></th>
4223 <td>
4224 <label>
4225 <input type="checkbox" name="security_headers[hide_server_signature]" value="1" <?php checked( ! empty( $options['hide_server_signature'] ) ); ?>>
4226 <?php esc_html_e( 'Hide server signature (ServerSignature Off)', 'vigilante' ); ?>
4227 </label>
4228 </td>
4229 </tr>
4230 <tr>
4231 <th scope="row"><?php esc_html_e( 'Remove Fingerprinting Headers', 'vigilante' ); ?></th>
4232 <td>
4233 <label>
4234 <input type="checkbox" name="security_headers[remove_fingerprinting_headers]" value="1" <?php checked( ! empty( $options['remove_fingerprinting_headers'] ) ); ?>>
4235 <?php esc_html_e( 'Remove X-Powered-By and Server headers', 'vigilante' ); ?>
4236 </label>
4237 </td>
4238 </tr>
4239 </table>
4240 </div>
4241
4242 <?php $vg_cop = ( isset( $options['cross_origin_policies'] ) && is_array( $options['cross_origin_policies'] ) ) ? $options['cross_origin_policies'] : array(); ?>
4243 <div id="vigilante-section-headers-cross-origin" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
4244 <h2>
4245 <?php esc_html_e( 'Cross-Origin Policies', 'vigilante' ); ?>
4246 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
4247 </h2>
4248 <p><?php esc_html_e( 'Control how other origins may open, embed or fetch your site. Vigilant already sends these headers with the values below.', 'vigilante' ); ?></p>
4249
4250 <table class="form-table">
4251 <tr>
4252 <th scope="row"><label for="vigilante-f-security-headers-coop"><?php esc_html_e( 'Cross-Origin-Opener-Policy (COOP)', 'vigilante' ); ?></label></th>
4253 <td>
4254 <select id="vigilante-f-security-headers-coop" name="security_headers[cross_origin_policies][opener_policy]">
4255 <option value="" <?php selected( empty( $vg_cop['opener_policy'] ) ); ?>><?php esc_html_e( 'Disabled (header not sent)', 'vigilante' ); ?></option>
4256 <option value="unsafe-none" <?php selected( $vg_cop['opener_policy'] ?? '', 'unsafe-none' ); ?>>unsafe-none</option>
4257 <option value="same-origin-allow-popups" <?php selected( $vg_cop['opener_policy'] ?? '', 'same-origin-allow-popups' ); ?>><?php esc_html_e( 'same-origin-allow-popups (recommended)', 'vigilante' ); ?></option>
4258 <option value="same-origin" <?php selected( $vg_cop['opener_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
4259 </select>
4260 <p class="description"><?php esc_html_e( '&#9432; Cuts the link between your site and a window from another origin that opened it. Side effect: external tools that open your site in a new tab and talk to it through window.opener, such as Google Tag Assistant, will report that they cannot connect. Pick unsafe-none or Disabled if you need those tools.', 'vigilante' ); ?></p>
4261 </td>
4262 </tr>
4263 <tr>
4264 <th scope="row"><label for="vigilante-f-security-headers-coep"><?php esc_html_e( 'Cross-Origin-Embedder-Policy (COEP)', 'vigilante' ); ?></label></th>
4265 <td>
4266 <select id="vigilante-f-security-headers-coep" name="security_headers[cross_origin_policies][embedder_policy]">
4267 <option value="unsafe-none" <?php selected( ( $vg_cop['embedder_policy'] ?? 'unsafe-none' ), 'unsafe-none' ); ?>><?php esc_html_e( 'unsafe-none (header not sent)', 'vigilante' ); ?></option>
4268 <option value="credentialless" <?php selected( $vg_cop['embedder_policy'] ?? '', 'credentialless' ); ?>>credentialless</option>
4269 <option value="require-corp" <?php selected( $vg_cop['embedder_policy'] ?? '', 'require-corp' ); ?>>require-corp</option>
4270 </select>
4271 <p class="description"><?php esc_html_e( '&#9432; Requires every cross-origin resource to opt in. require-corp can block third-party images, fonts, videos and embeds that do not send their own CORP or CORS headers.', 'vigilante' ); ?></p>
4272 </td>
4273 </tr>
4274 <tr>
4275 <th scope="row"><label for="vigilante-f-security-headers-corp"><?php esc_html_e( 'Cross-Origin-Resource-Policy (CORP)', 'vigilante' ); ?></label></th>
4276 <td>
4277 <select id="vigilante-f-security-headers-corp" name="security_headers[cross_origin_policies][resource_policy]">
4278 <option value="" <?php selected( empty( $vg_cop['resource_policy'] ) ); ?>><?php esc_html_e( 'Disabled (header not sent)', 'vigilante' ); ?></option>
4279 <option value="same-site" <?php selected( $vg_cop['resource_policy'] ?? '', 'same-site' ); ?>>same-site</option>
4280 <option value="same-origin" <?php selected( $vg_cop['resource_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
4281 <option value="cross-origin" <?php selected( $vg_cop['resource_policy'] ?? '', 'cross-origin' ); ?>><?php esc_html_e( 'cross-origin (recommended)', 'vigilante' ); ?></option>
4282 </select>
4283 <p class="description"><?php esc_html_e( '&#9432; Declares who may load resources from this site. same-origin stops hotlinking, but it also breaks CDNs, feed readers and any external service that fetches your images or files.', 'vigilante' ); ?></p>
4284 </td>
4285 </tr>
4286 </table>
4287 </div>
4288
4289 <p class="submit vigilante-submit-buttons">
4290 <?php if ( ! $vg_shared_locked ) : ?>
4291 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4292 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4293 </button>
4294 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4295 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4296 </button>
4297 <?php endif; ?>
4298 <?php /* Testing what the server actually sends is read-only and useful from any site of a network. */ ?>
4299 <button type="button" class="button vigilante-test-headers">
4300 <?php esc_html_e( 'Test Headers', 'vigilante' ); ?>
4301 </button>
4302 </p>
4303 </form>
4304
4305 <div id="vigilante-headers-result"></div>
4306 <?php
4307 }
4308
4309 /**
4310 * Render REST API tab
4311 */
4312 private function render_tab_rest_api() {
4313 $is_disabled = $this->render_module_disabled_notice( 'rest_api_security' );
4314 $options = $this->settings->get_section( 'rest_api_security' );
4315 ?>
4316 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="rest_api_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
4317 <div id="vigilante-section-rest-api-main" class="vigilante-settings-section">
4318 <h2>
4319 <?php esc_html_e( 'REST API Security', 'vigilante' ); ?>
4320 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4321 </h2>
4322 <p><?php esc_html_e( 'Control access to WordPress REST API endpoints.', 'vigilante' ); ?></p>
4323
4324 <table class="form-table">
4325 <tr>
4326 <th scope="row"><label for="vigilante-f-rest-api-security-mode"><?php esc_html_e( 'Access Mode', 'vigilante' ); ?></label></th>
4327 <td>
4328 <select id="vigilante-f-rest-api-security-mode" name="rest_api_security[mode]">
4329 <option value="open" <?php selected( $options['mode'] ?? 'selective', 'open' ); ?>><?php esc_html_e( 'Open - Allow all requests', 'vigilante' ); ?></option>
4330 <option value="selective" <?php selected( $options['mode'] ?? 'selective', 'selective' ); ?>><?php esc_html_e( 'Selective - Protect sensitive endpoints', 'vigilante' ); ?></option>
4331 <option value="authenticated_only" <?php selected( $options['mode'] ?? 'selective', 'authenticated_only' ); ?>><?php esc_html_e( 'Authenticated - Require login for all', 'vigilante' ); ?></option>
4332 </select>
4333 <p class="description"><?php esc_html_e( 'Selective mode is recommended.', 'vigilante' ); ?></p>
4334 </td>
4335 </tr>
4336 <tr id="field-block-user-enumeration">
4337 <th scope="row"><?php esc_html_e( 'Block User Enumeration', 'vigilante' ); ?></th>
4338 <td>
4339 <label>
4340 <input type="checkbox" name="rest_api_security[block_user_enumeration]" value="1" <?php checked( ! empty( $options['block_user_enumeration'] ) ); ?>>
4341 <?php esc_html_e( 'Protect /wp/v2/users endpoint for unauthenticated users', 'vigilante' ); ?>
4342 </label>
4343 </td>
4344 </tr>
4345 <tr>
4346 <th scope="row"><?php esc_html_e( 'Disable JSONP', 'vigilante' ); ?></th>
4347 <td>
4348 <label>
4349 <input type="checkbox" name="rest_api_security[disable_jsonp]" value="1" <?php checked( ! empty( $options['disable_jsonp'] ) ); ?>>
4350 <?php esc_html_e( 'Disable JSONP support in REST API', 'vigilante' ); ?>
4351 </label>
4352 </td>
4353 </tr>
4354 </table>
4355 </div>
4356
4357 <p class="submit vigilante-submit-buttons">
4358 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4359 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4360 </button>
4361 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4362 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4363 </button>
4364 </p>
4365 </form>
4366 <?php
4367 }
4368
4369 /**
4370 * Render User Security tab
4371 */
4372 private function render_tab_users() {
4373 $is_disabled = $this->render_module_disabled_notice( 'user_security' );
4374 $options = $this->settings->get_section( 'user_security' );
4375 $monitoring = $options['admin_monitoring'] ?? array();
4376 $registration = $options['registration_approval'] ?? array();
4377 $session_limits = $options['session_limits'] ?? array();
4378 $password_exp = $options['password_expiration'] ?? array();
4379 $email_verify = $options['email_verification'] ?? array();
4380 ?>
4381
4382 <!-- ============================================================
4383 SETTINGS SECTION - Single form for all configuration
4384 ============================================================ -->
4385 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="user_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
4386
4387 <!-- Username & Password Protection -->
4388 <div id="vigilante-section-users-password" class="vigilante-settings-section">
4389 <h2>
4390 <?php esc_html_e( 'Username & password protection', 'vigilante' ); ?>
4391 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4392 </h2>
4393 <p><?php esc_html_e( 'Enforce secure username and password policies.', 'vigilante' ); ?></p>
4394
4395 <table class="form-table">
4396 <tr>
4397 <th scope="row"><?php esc_html_e( 'Block Insecure Usernames', 'vigilante' ); ?></th>
4398 <td>
4399 <label>
4400 <input type="checkbox" name="user_security[block_insecure_usernames]" value="1" <?php checked( ! empty( $options['block_insecure_usernames'] ) ); ?>>
4401 <?php esc_html_e( 'Prevent creation of users with common usernames (admin, administrator, etc.)', 'vigilante' ); ?>
4402 </label>
4403 </td>
4404 </tr>
4405 <?php
4406 $pw_policy = wp_parse_args(
4407 ( isset( $options['password_policy'] ) && is_array( $options['password_policy'] ) ) ? $options['password_policy'] : array(),
4408 array(
4409 'require_uppercase' => false,
4410 'require_lowercase' => false,
4411 'require_number' => false,
4412 'require_special' => false,
4413 'block_common' => true,
4414 'block_username' => true,
4415 'affected_roles' => array(),
4416 )
4417 );
4418 $pw_policy_roles = (array) $pw_policy['affected_roles'];
4419 ?>
4420 <tr>
4421 <th scope="row"><?php esc_html_e( 'Enforce Strong Passwords', 'vigilante' ); ?></th>
4422 <td>
4423 <label>
4424 <input type="checkbox" name="user_security[force_strong_passwords]" value="1" <?php checked( ! empty( $options['force_strong_passwords'] ) ); ?>>
4425 <?php esc_html_e( 'Check passwords against the requirements below when a user sets or changes one', 'vigilante' ); ?>
4426 </label>
4427 </td>
4428 </tr>
4429 <tr>
4430 <th scope="row"><label for="vigilante-f-user-security-min-password-length"><?php esc_html_e( 'Minimum Password Length', 'vigilante' ); ?></label></th>
4431 <td>
4432 <input id="vigilante-f-user-security-min-password-length" 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">
4433 <?php esc_html_e( 'characters', 'vigilante' ); ?>
4434 </td>
4435 </tr>
4436 <tr>
4437 <th scope="row"><?php esc_html_e( 'Password Requirements', 'vigilante' ); ?></th>
4438 <td>
4439 <label style="display:block;margin-bottom:5px;">
4440 <input type="checkbox" name="user_security[password_policy][require_uppercase]" value="1" <?php checked( ! empty( $pw_policy['require_uppercase'] ) ); ?>>
4441 <?php esc_html_e( 'Require an uppercase letter (A-Z)', 'vigilante' ); ?>
4442 </label>
4443 <label style="display:block;margin-bottom:5px;">
4444 <input type="checkbox" name="user_security[password_policy][require_lowercase]" value="1" <?php checked( ! empty( $pw_policy['require_lowercase'] ) ); ?>>
4445 <?php esc_html_e( 'Require a lowercase letter (a-z)', 'vigilante' ); ?>
4446 </label>
4447 <label style="display:block;margin-bottom:5px;">
4448 <input type="checkbox" name="user_security[password_policy][require_number]" value="1" <?php checked( ! empty( $pw_policy['require_number'] ) ); ?>>
4449 <?php esc_html_e( 'Require a number (0-9)', 'vigilante' ); ?>
4450 </label>
4451 <label style="display:block;margin-bottom:5px;">
4452 <input type="checkbox" name="user_security[password_policy][require_special]" value="1" <?php checked( ! empty( $pw_policy['require_special'] ) ); ?>>
4453 <?php esc_html_e( 'Require a special character (!, @, #, ...)', 'vigilante' ); ?>
4454 </label>
4455 <label style="display:block;margin-bottom:5px;">
4456 <input type="checkbox" name="user_security[password_policy][block_common]" value="1" <?php checked( ! empty( $pw_policy['block_common'] ) ); ?>>
4457 <?php esc_html_e( 'Reject well-known common passwords', 'vigilante' ); ?>
4458 </label>
4459 <label style="display:block;margin-bottom:5px;">
4460 <input type="checkbox" name="user_security[password_policy][block_username]" value="1" <?php checked( ! empty( $pw_policy['block_username'] ) ); ?>>
4461 <?php esc_html_e( 'Do not allow the username inside the password', 'vigilante' ); ?>
4462 </label>
4463 <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>
4464 </td>
4465 </tr>
4466 <tr>
4467 <th scope="row"><?php esc_html_e( 'Apply Password Rules To', 'vigilante' ); ?></th>
4468 <td>
4469 <?php foreach ( wp_roles()->get_names() as $role_slug => $role_name ) : ?>
4470 <label style="display:block;margin-bottom:5px;">
4471 <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 ) ); ?>>
4472 <?php echo esc_html( translate_user_role( $role_name ) ); ?>
4473 </label>
4474 <?php endforeach; ?>
4475 <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>
4476 </td>
4477 </tr>
4478 <tr id="field-block-author-scanning">
4479 <th scope="row"><?php esc_html_e( 'Block Author Scanning', 'vigilante' ); ?></th>
4480 <td>
4481 <label>
4482 <input type="checkbox" name="user_security[block_author_scanning]" value="1" <?php checked( ! empty( $options['block_author_scanning'] ) ); ?>>
4483 <?php esc_html_e( 'Prevent username discovery via ?author=N URLs', 'vigilante' ); ?>
4484 </label>
4485 </td>
4486 </tr>
4487 <tr>
4488 <th scope="row"><?php esc_html_e( 'Display Name Protection', 'vigilante' ); ?></th>
4489 <td>
4490 <label>
4491 <input type="checkbox" name="user_security[prevent_display_name_login_match]" value="1" <?php checked( ! empty( $options['prevent_display_name_login_match'] ) ); ?>>
4492 <?php esc_html_e( 'Prevent users from saving a display name that matches their login username', 'vigilante' ); ?>
4493 </label>
4494 <p class="description"><?php esc_html_e( 'The display name is publicly visible and should not reveal the login username.', 'vigilante' ); ?></p>
4495 </td>
4496 </tr>
4497 </table>
4498 </div>
4499
4500 <!-- Admin Monitoring -->
4501 <div id="vigilante-section-users-admin-monitoring" class="vigilante-settings-section">
4502 <h2>
4503 <?php esc_html_e( 'Admin monitoring', 'vigilante' ); ?>
4504 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4505 </h2>
4506 <p><?php esc_html_e( 'Receive email alerts when administrator accounts are modified. All events are always logged to the Security Audit.', 'vigilante' ); ?></p>
4507
4508 <table class="form-table">
4509 <tr>
4510 <th scope="row"><?php esc_html_e( 'New Administrator Alert', 'vigilante' ); ?></th>
4511 <td>
4512 <label>
4513 <input type="checkbox" name="user_security[admin_monitoring][alert_new_admin]" value="1" <?php checked( ! empty( $monitoring['alert_new_admin'] ) ); ?>>
4514 <?php esc_html_e( 'Send email alert when a new administrator account is created', 'vigilante' ); ?>
4515 </label>
4516 </td>
4517 </tr>
4518 <tr>
4519 <th scope="row"><?php esc_html_e( 'Admin Email Change Alert', 'vigilante' ); ?></th>
4520 <td>
4521 <label>
4522 <input type="checkbox" name="user_security[admin_monitoring][alert_admin_email_change]" value="1" <?php checked( ! empty( $monitoring['alert_admin_email_change'] ) ); ?>>
4523 <?php esc_html_e( 'Send email alert when an administrator email address is changed', 'vigilante' ); ?>
4524 </label>
4525 </td>
4526 </tr>
4527 <tr>
4528 <th scope="row"><?php esc_html_e( 'Permission Elevation Alert', 'vigilante' ); ?></th>
4529 <td>
4530 <label>
4531 <input type="checkbox" name="user_security[admin_monitoring][alert_permission_elevation]" value="1" <?php checked( ! empty( $monitoring['alert_permission_elevation'] ) ); ?>>
4532 <?php esc_html_e( 'Send email alert when a user is elevated to administrator role', 'vigilante' ); ?>
4533 </label>
4534 </td>
4535 </tr>
4536 <tr>
4537 <th scope="row"><?php esc_html_e( 'Admin Password Change Alert', 'vigilante' ); ?></th>
4538 <td>
4539 <label>
4540 <input type="checkbox" name="user_security[admin_monitoring][alert_admin_password_change]" value="1" <?php checked( ! empty( $monitoring['alert_admin_password_change'] ) ); ?>>
4541 <?php esc_html_e( 'Send email alert when an administrator password is changed', 'vigilante' ); ?>
4542 </label>
4543 </td>
4544 </tr>
4545 </table>
4546
4547 <p class="description">
4548 <?php
4549 printf(
4550 /* translators: %s: Link to notification settings */
4551 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
4552 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
4553 );
4554 ?>
4555 </p>
4556 </div>
4557
4558 <!-- Registration Approval -->
4559 <div id="vigilante-section-users-registration" class="vigilante-settings-section">
4560 <h2>
4561 <?php esc_html_e( 'Registration approval', 'vigilante' ); ?>
4562 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4563 </h2>
4564 <p><?php esc_html_e( 'Require manual approval for new user registrations.', 'vigilante' ); ?></p>
4565
4566 <table class="form-table">
4567 <tr>
4568 <th scope="row"><?php esc_html_e( 'Enable Registration Approval', 'vigilante' ); ?></th>
4569 <td>
4570 <label>
4571 <input type="checkbox" name="user_security[registration_approval][enabled]" value="1" <?php checked( ! empty( $registration['enabled'] ) ); ?>>
4572 <?php esc_html_e( 'New users must be approved by an administrator before they can log in', 'vigilante' ); ?>
4573 </label>
4574 </td>
4575 </tr>
4576 <tr>
4577 <th scope="row"><?php esc_html_e( 'Notify Admin', 'vigilante' ); ?></th>
4578 <td>
4579 <label>
4580 <input type="checkbox" name="user_security[registration_approval][notify_admin]" value="1" <?php checked( ! empty( $registration['notify_admin'] ) ); ?>>
4581 <?php esc_html_e( 'Send email notification when a new user registers', 'vigilante' ); ?>
4582 </label>
4583 <p class="description"><?php esc_html_e( 'Disable on high-traffic sites to avoid email overload.', 'vigilante' ); ?></p>
4584 </td>
4585 </tr>
4586 <tr>
4587 <th scope="row"><label for="vigilante-f-user-security-registration-approval-auto-reject-days"><?php esc_html_e( 'Auto-reject After', 'vigilante' ); ?></label></th>
4588 <td>
4589 <input id="vigilante-f-user-security-registration-approval-auto-reject-days" 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">
4590 <?php esc_html_e( 'days (0 = never)', 'vigilante' ); ?>
4591 <p class="description"><?php esc_html_e( 'Automatically reject pending registrations after this many days.', 'vigilante' ); ?></p>
4592 </td>
4593 </tr>
4594 </table>
4595 </div>
4596
4597 <!-- Session Limits -->
4598 <div id="vigilante-section-users-sessions" class="vigilante-settings-section">
4599 <h2>
4600 <?php esc_html_e( 'Session limits', 'vigilante' ); ?>
4601 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4602 </h2>
4603 <p><?php esc_html_e( 'Limit the number of simultaneous sessions per user.', 'vigilante' ); ?></p>
4604
4605 <table class="form-table">
4606 <tr>
4607 <th scope="row"><?php esc_html_e( 'Enable Session Limits', 'vigilante' ); ?></th>
4608 <td>
4609 <label>
4610 <input type="checkbox" name="user_security[session_limits][enabled]" value="1" <?php checked( ! empty( $session_limits['enabled'] ) ); ?>>
4611 <?php esc_html_e( 'Limit the number of active sessions per user', 'vigilante' ); ?>
4612 </label>
4613 </td>
4614 </tr>
4615 <tr>
4616 <th scope="row"><label for="vigilante-f-user-security-session-limits-max-sessions"><?php esc_html_e( 'Maximum Sessions', 'vigilante' ); ?></label></th>
4617 <td>
4618 <input id="vigilante-f-user-security-session-limits-max-sessions" 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">
4619 <?php esc_html_e( 'sessions per user', 'vigilante' ); ?>
4620 </td>
4621 </tr>
4622 <tr>
4623 <th scope="row"><label for="vigilante-f-user-security-session-limits-behavior"><?php esc_html_e( 'When Limit Exceeded', 'vigilante' ); ?></label></th>
4624 <td>
4625 <select id="vigilante-f-user-security-session-limits-behavior" name="user_security[session_limits][behavior]">
4626 <option value="block_new" <?php selected( ( $session_limits['behavior'] ?? 'close_oldest' ), 'block_new' ); ?>><?php esc_html_e( 'Block new login', 'vigilante' ); ?></option>
4627 <option value="close_oldest" <?php selected( ( $session_limits['behavior'] ?? 'close_oldest' ), 'close_oldest' ); ?>><?php esc_html_e( 'Close oldest session', 'vigilante' ); ?></option>
4628 </select>
4629 <p class="description"><?php esc_html_e( '"Close oldest" is recommended for security - ensures attackers cannot lock out legitimate users.', 'vigilante' ); ?></p>
4630 </td>
4631 </tr>
4632 <tr>
4633 <th scope="row"><?php esc_html_e( 'Exclude Administrators', 'vigilante' ); ?></th>
4634 <td>
4635 <label>
4636 <input type="checkbox" name="user_security[session_limits][exclude_admins]" value="1" <?php checked( ! empty( $session_limits['exclude_admins'] ) ); ?>>
4637 <?php esc_html_e( 'Do not apply session limits to administrators', 'vigilante' ); ?>
4638 </label>
4639 </td>
4640 </tr>
4641 </table>
4642 </div>
4643
4644 <!-- Password Expiration -->
4645 <div id="vigilante-section-users-password-exp" class="vigilante-settings-section">
4646 <h2>
4647 <?php esc_html_e( 'Password expiration', 'vigilante' ); ?>
4648 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4649 </h2>
4650 <p><?php esc_html_e( 'Force users to change their password periodically.', 'vigilante' ); ?></p>
4651
4652 <table class="form-table">
4653 <tr>
4654 <th scope="row"><?php esc_html_e( 'Enable Password Expiration', 'vigilante' ); ?></th>
4655 <td>
4656 <label>
4657 <input type="checkbox" name="user_security[password_expiration][enabled]" value="1" <?php checked( ! empty( $password_exp['enabled'] ) ); ?>>
4658 <?php esc_html_e( 'Force password change after a set number of days', 'vigilante' ); ?>
4659 </label>
4660 </td>
4661 </tr>
4662 <tr>
4663 <th scope="row"><label for="vigilante-f-user-security-password-expiration-expire-days"><?php esc_html_e( 'Expire After', 'vigilante' ); ?></label></th>
4664 <td>
4665 <input id="vigilante-f-user-security-password-expiration-expire-days" 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">
4666 <?php esc_html_e( 'days', 'vigilante' ); ?>
4667 <p class="description"><?php esc_html_e( 'PCI-DSS recommends 90 days.', 'vigilante' ); ?></p>
4668 </td>
4669 </tr>
4670 <tr>
4671 <th scope="row"><label for="vigilante-f-user-security-password-expiration-warning-days"><?php esc_html_e( 'Warning Period', 'vigilante' ); ?></label></th>
4672 <td>
4673 <input id="vigilante-f-user-security-password-expiration-warning-days" 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">
4674 <?php esc_html_e( 'days before expiration', 'vigilante' ); ?>
4675 <p class="description"><?php esc_html_e( 'Show warning notice this many days before password expires.', 'vigilante' ); ?></p>
4676 </td>
4677 </tr>
4678 <tr>
4679 <th scope="row"><label for="vigilante-f-user-security-password-expiration-password-history"><?php esc_html_e( 'Password History', 'vigilante' ); ?></label></th>
4680 <td>
4681 <input id="vigilante-f-user-security-password-expiration-password-history" 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">
4682 <?php esc_html_e( 'passwords to remember', 'vigilante' ); ?>
4683 <p class="description"><?php esc_html_e( 'Prevent reusing recent passwords. Set to 0 to disable.', 'vigilante' ); ?></p>
4684 </td>
4685 </tr>
4686 <tr>
4687 <th scope="row"><?php esc_html_e( 'Email Reminder', 'vigilante' ); ?></th>
4688 <td>
4689 <label>
4690 <input type="checkbox" name="user_security[password_expiration][send_reminder]" value="1" <?php checked( ! empty( $password_exp['send_reminder'] ) ); ?>>
4691 <?php esc_html_e( 'Send email reminder when password is about to expire', 'vigilante' ); ?>
4692 </label>
4693 <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>
4694 </td>
4695 </tr>
4696 <tr>
4697 <th scope="row"><?php esc_html_e( 'Affected Roles', 'vigilante' ); ?></th>
4698 <td>
4699 <?php
4700 $affected_roles = $password_exp['affected_roles'] ?? array( 'administrator', 'editor' );
4701 $all_roles = wp_roles()->get_names();
4702 foreach ( $all_roles as $role_slug => $role_name ) :
4703 ?>
4704 <label style="display: block; margin-bottom: 5px;">
4705 <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 ) ); ?>>
4706 <?php echo esc_html( translate_user_role( $role_name ) ); ?>
4707 </label>
4708 <?php endforeach; ?>
4709 </td>
4710 </tr>
4711 <tr>
4712 <th scope="row"><?php esc_html_e( 'Exclude specific users', 'vigilante' ); ?></th>
4713 <td>
4714 <?php $pwexp_excluded = $password_exp['excluded_users'] ?? array(); ?>
4715 <div class="vigilante-2fa-user-search-container">
4716 <div class="vigilante-2fa-user-search">
4717 <span class="search-icon"></span>
4718 <input type="text"
4719 id="vigilante_pwexp_user_search"
4720 placeholder="<?php esc_attr_e( 'Search users by name or email...', 'vigilante' ); ?>"
4721 autocomplete="off">
4722 <div class="vigilante-pwexp-search-results"></div>
4723 </div>
4724 <div class="vigilante-pwexp-excluded-users">
4725 <?php
4726 foreach ( $pwexp_excluded as $pwexp_excluded_id ) :
4727 $excluded_user = get_user_by( 'ID', $pwexp_excluded_id );
4728 if ( ! $excluded_user ) {
4729 continue;
4730 }
4731 ?>
4732 <div class="vigilante-pwexp-excluded-user" data-user-id="<?php echo esc_attr( $pwexp_excluded_id ); ?>">
4733 <span class="user-display"><?php echo esc_html( $excluded_user->display_name . ' (' . $excluded_user->user_email . ')' ); ?></span>
4734 <button type="button" class="remove-user" aria-label="<?php esc_attr_e( 'Remove', 'vigilante' ); ?>">&times;</button>
4735 <input type="hidden" name="user_security[password_expiration][excluded_users][]" value="<?php echo esc_attr( $pwexp_excluded_id ); ?>">
4736 </div>
4737 <?php endforeach; ?>
4738 </div>
4739 </div>
4740 <p class="description"><?php esc_html_e( 'Listed users will be excluded from password expiration regardless of their role.', 'vigilante' ); ?></p>
4741 </td>
4742 </tr>
4743 </table>
4744 </div>
4745
4746 <!-- Email Verification -->
4747 <div id="vigilante-section-users-email-verify" class="vigilante-settings-section">
4748 <h2>
4749 <?php esc_html_e( 'Email verification', 'vigilante' ); ?>
4750 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4751 </h2>
4752 <p><?php esc_html_e( 'Require new users to verify their email address before logging in.', 'vigilante' ); ?></p>
4753
4754 <table class="form-table">
4755 <tr>
4756 <th scope="row"><?php esc_html_e( 'Enable Email Verification', 'vigilante' ); ?></th>
4757 <td>
4758 <label>
4759 <input type="checkbox" name="user_security[email_verification][enabled]" value="1" <?php checked( ! empty( $email_verify['enabled'] ) ); ?>>
4760 <?php esc_html_e( 'New users must verify their email before logging in', 'vigilante' ); ?>
4761 </label>
4762 </td>
4763 </tr>
4764 <tr>
4765 <th scope="row"><label for="vigilante-f-user-security-email-verification-token-expiry-hours"><?php esc_html_e( 'Link Expiration', 'vigilante' ); ?></label></th>
4766 <td>
4767 <input id="vigilante-f-user-security-email-verification-token-expiry-hours" 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">
4768 <?php esc_html_e( 'hours', 'vigilante' ); ?>
4769 </td>
4770 </tr>
4771 <tr>
4772 <th scope="row"><?php esc_html_e( 'Allow Resend', 'vigilante' ); ?></th>
4773 <td>
4774 <label>
4775 <input type="checkbox" name="user_security[email_verification][allow_resend]" value="1" <?php checked( ! empty( $email_verify['allow_resend'] ) ); ?>>
4776 <?php esc_html_e( 'Allow users to request a new verification email', 'vigilante' ); ?>
4777 </label>
4778 </td>
4779 </tr>
4780 <tr>
4781 <th scope="row"><label for="vigilante-f-user-security-email-verification-auto-delete-days"><?php esc_html_e( 'Auto-delete Unverified', 'vigilante' ); ?></label></th>
4782 <td>
4783 <input id="vigilante-f-user-security-email-verification-auto-delete-days" 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">
4784 <?php esc_html_e( 'days (0 = never)', 'vigilante' ); ?>
4785 <p class="description"><?php esc_html_e( 'Automatically delete users who never verify their email.', 'vigilante' ); ?></p>
4786 </td>
4787 </tr>
4788 </table>
4789 </div>
4790
4791 <p class="submit vigilante-submit-buttons">
4792 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4793 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4794 </button>
4795 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4796 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4797 </button>
4798 </p>
4799 </form>
4800
4801 <!-- ============================================================
4802 TOOLS SECTION - Actions and utilities (no save button)
4803 ============================================================ -->
4804 <div class="vigilante-tools-section">
4805 <h2 class="vigilante-tools-header">
4806 <?php esc_html_e( 'User security tools', 'vigilante' ); ?>
4807 </h2>
4808
4809 <?php $this->render_user_actions_notice(); ?>
4810 <?php if ( ! $this->user_actions_locked() ) : ?>
4811
4812 <!-- Force Password Reset -->
4813 <div class="vigilante-tool-box">
4814 <h3><?php esc_html_e( 'Force password reset', 'vigilante' ); ?></h3>
4815 <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>
4816
4817 <!-- Reset Specific Users -->
4818 <div class="vigilante-password-reset-box">
4819 <h4><?php esc_html_e( 'Reset specific users', 'vigilante' ); ?></h4>
4820
4821 <div class="vigilante-user-search-wrapper">
4822 <input type="text" id="vigilante-password-reset-search" class="regular-text" placeholder="<?php esc_attr_e( 'Search by username, email, or display name...', 'vigilante' ); ?>">
4823 <div id="vigilante-password-reset-results" class="vigilante-user-search-results" style="display: none;"></div>
4824 </div>
4825
4826 <div id="vigilante-password-reset-selected" class="vigilante-selected-users" style="display: none;">
4827 <strong><?php esc_html_e( 'Selected Users:', 'vigilante' ); ?></strong>
4828 <ul class="vigilante-selected-users-list"></ul>
4829 </div>
4830
4831 <p class="description" style="margin-top: 15px;">
4832 <span class="dashicons dashicons-email-alt" style="color: #2271b1;"></span>
4833 <?php esc_html_e( 'Selected users will receive an email with a password reset link.', 'vigilante' ); ?>
4834 </p>
4835
4836 <p class="submit">
4837 <button type="button" id="vigilante-reset-selected-users" class="button button-primary" disabled>
4838 <?php esc_html_e( 'Force Reset for Selected Users', 'vigilante' ); ?>
4839 </button>
4840 </p>
4841 </div>
4842
4843 <!-- Reset by Role -->
4844 <div class="vigilante-password-reset-box" style="margin-top: 20px; padding-top: 20px; border-top: 1px solid #ddd;">
4845 <h4><?php esc_html_e( 'Reset by role', 'vigilante' ); ?></h4>
4846 <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>
4847
4848 <?php
4849 $wp_roles = wp_roles();
4850 $user_counts = count_users();
4851 $avail_roles = $user_counts['avail_roles'] ?? array();
4852 $current_user = wp_get_current_user();
4853 $current_roles = $current_user->roles;
4854 ?>
4855
4856 <fieldset class="vigilante-role-checkboxes" style="margin-top: 10px;">
4857 <?php foreach ( $wp_roles->roles as $role_slug => $role_data ) :
4858 $count = $avail_roles[ $role_slug ] ?? 0;
4859 if ( 0 === $count ) {
4860 continue;
4861 }
4862 $role_name = translate_user_role( $role_data['name'] );
4863 ?>
4864 <label style="display: block; margin-bottom: 6px;">
4865 <input type="checkbox"
4866 class="vigilante-reset-role-checkbox"
4867 value="<?php echo esc_attr( $role_slug ); ?>"
4868 data-count="<?php echo absint( $count ); ?>">
4869 <?php
4870 printf(
4871 /* translators: 1: Role name, 2: Number of users */
4872 '%1$s <span class="description">(%2$d)</span>',
4873 esc_html( $role_name ),
4874 absint( $count )
4875 );
4876 ?>
4877 <?php if ( in_array( $role_slug, $current_roles, true ) ) : ?>
4878 <em class="description"><?php esc_html_e( '(includes you)', 'vigilante' ); ?></em>
4879 <?php endif; ?>
4880 </label>
4881 <?php endforeach; ?>
4882 </fieldset>
4883
4884 <div id="vigilante-reset-role-summary" style="display: none; margin-top: 10px;">
4885 <p>
4886 <span class="dashicons dashicons-groups" style="color: #2271b1;"></span>
4887 <strong id="vigilante-reset-role-count">0</strong>
4888 <?php esc_html_e( 'user(s) will be affected.', 'vigilante' ); ?>
4889 </p>
4890 </div>
4891
4892 <div class="vigilante-password-reset-options" id="vigilante-reset-role-self-option" style="display: none; margin-top: 10px;">
4893 <label>
4894 <input type="checkbox" id="vigilante-reset-role-include-self" value="1">
4895 <?php esc_html_e( 'Include myself (your current session will end)', 'vigilante' ); ?>
4896 </label>
4897 </div>
4898
4899 <p class="submit">
4900 <button type="button" id="vigilante-reset-by-role" class="button button-primary" disabled>
4901 <?php esc_html_e( 'Force Reset for Selected Roles', 'vigilante' ); ?>
4902 </button>
4903 </p>
4904 </div>
4905
4906 <!-- Reset All Users -->
4907 <div class="vigilante-password-reset-box" style="margin-top: 20px; padding-top: 20px; border-top: 1px solid #ddd;">
4908 <h4><?php esc_html_e( 'Reset all users', 'vigilante' ); ?></h4>
4909
4910 <?php
4911 $total_users = count_users();
4912 $total_count = $total_users['total_users'];
4913 ?>
4914 <p>
4915 <?php
4916 printf(
4917 /* translators: %d: Number of users */
4918 esc_html__( 'This will affect %d user(s).', 'vigilante' ),
4919 absint( $total_count )
4920 );
4921 ?>
4922 </p>
4923
4924 <p class="description" style="color: #d63638;">
4925 <span class="dashicons dashicons-warning"></span>
4926 <?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' ); ?>
4927 </p>
4928
4929 <div class="vigilante-password-reset-options" style="margin-top: 10px;">
4930 <label>
4931 <input type="checkbox" id="vigilante-reset-all-include-self" value="1">
4932 <?php esc_html_e( 'Include myself (your current session will end)', 'vigilante' ); ?>
4933 </label>
4934 </div>
4935
4936 <p class="submit">
4937 <button type="button" id="vigilante-reset-all-users" class="button" style="color: #d63638; border-color: #d63638;">
4938 <?php esc_html_e( 'Force Reset for ALL Users', 'vigilante' ); ?>
4939 </button>
4940 </p>
4941 </div>
4942 </div>
4943
4944 <!-- Pending Registrations -->
4945 <?php
4946 $user_security = new Vigilante_User_Security( $this->settings, $this->activity_log );
4947 $pending_users = $user_security->get_pending_users();
4948 ?>
4949 <div id="vigilante-section-users-pending" class="vigilante-tool-box vigilante-pending-users-section">
4950 <h3>
4951 <?php esc_html_e( 'Pending registrations', 'vigilante' ); ?>
4952 <?php if ( count( $pending_users ) > 0 ) : ?>
4953 <span class="vigilante-badge vigilante-badge-warning"><?php echo esc_html( count( $pending_users ) ); ?></span>
4954 <?php endif; ?>
4955 </h3>
4956
4957 <?php if ( empty( $registration['enabled'] ) ) : ?>
4958 <p class="description">
4959 <span class="dashicons dashicons-info" style="color: #72aee6;"></span>
4960 <?php esc_html_e( 'Registration approval is disabled. Enable it in the settings above to require manual approval for new users.', 'vigilante' ); ?>
4961 </p>
4962 <?php elseif ( empty( $pending_users ) ) : ?>
4963 <div class="vigilante-no-lockouts">
4964 <span class="dashicons dashicons-yes-alt"></span>
4965 <p><?php esc_html_e( 'No pending registrations.', 'vigilante' ); ?></p>
4966 </div>
4967 <?php else : ?>
4968 <table class="wp-list-table widefat fixed striped vigilante-pending-users-table">
4969 <thead>
4970 <tr>
4971 <th><?php esc_html_e( 'User', 'vigilante' ); ?></th>
4972 <th><?php esc_html_e( 'Email', 'vigilante' ); ?></th>
4973 <th><?php esc_html_e( 'Registered', 'vigilante' ); ?></th>
4974 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
4975 </tr>
4976 </thead>
4977 <tbody>
4978 <?php foreach ( $pending_users as $pending_user ) :
4979 $pending_since = get_user_meta( $pending_user->ID, 'vigilante_pending_since', true );
4980 ?>
4981 <tr data-user-id="<?php echo esc_attr( $pending_user->ID ); ?>">
4982 <td>
4983 <?php echo get_avatar( $pending_user->ID, 32 ); ?>
4984 <strong><?php echo esc_html( $pending_user->user_login ); ?></strong>
4985 </td>
4986 <td><?php echo esc_html( $pending_user->user_email ); ?></td>
4987 <td>
4988 <?php
4989 if ( $pending_since ) {
4990 /* translators: %s: Time ago */
4991 printf( esc_html__( '%s ago', 'vigilante' ), esc_html( human_time_diff( $pending_since ) ) );
4992 } else {
4993 echo esc_html( $pending_user->user_registered );
4994 }
4995 ?>
4996 </td>
4997 <td>
4998 <button type="button" class="button button-small vigilante-approve-user" data-user-id="<?php echo esc_attr( $pending_user->ID ); ?>">
4999 <?php esc_html_e( 'Approve', 'vigilante' ); ?>
5000 </button>
5001 <button type="button" class="button button-small vigilante-reject-user" data-user-id="<?php echo esc_attr( $pending_user->ID ); ?>" style="color: #d63638;">
5002 <?php esc_html_e( 'Reject', 'vigilante' ); ?>
5003 </button>
5004 </td>
5005 </tr>
5006 <?php endforeach; ?>
5007 </tbody>
5008 </table>
5009 <?php endif; ?>
5010 </div>
5011
5012 <!-- Active Sessions Management -->
5013 <div class="vigilante-tool-box vigilante-session-management-section">
5014 <h3><?php esc_html_e( 'Active sessions', 'vigilante' ); ?></h3>
5015 <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>
5016
5017 <!-- Current user sessions -->
5018 <h4><?php esc_html_e( 'Your sessions', 'vigilante' ); ?></h4>
5019 <?php
5020 $current_user_id = get_current_user_id();
5021 $my_sessions = $user_security->get_user_sessions( $current_user_id );
5022 $has_corrupted = $user_security->has_corrupted_sessions( $current_user_id );
5023 $raw_count = $user_security->get_raw_session_count( $current_user_id );
5024 ?>
5025
5026 <?php if ( $has_corrupted && $raw_count > 0 ) : ?>
5027 <div class="notice notice-warning inline" style="margin: 10px 0;">
5028 <p>
5029 <span class="dashicons dashicons-warning" style="color: #dba617;"></span>
5030 <?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' ); ?>
5031 </p>
5032 </div>
5033 <?php endif; ?>
5034
5035 <?php if ( empty( $my_sessions ) ) : ?>
5036 <p class="description"><?php esc_html_e( 'No active sessions found.', 'vigilante' ); ?></p>
5037 <?php if ( $has_corrupted ) : ?>
5038 <p style="margin-top: 10px;">
5039 <button type="button" class="button vigilante-revoke-other-sessions" data-user-id="<?php echo esc_attr( $current_user_id ); ?>">
5040 <?php esc_html_e( 'Clean Up Corrupted Sessions', 'vigilante' ); ?>
5041 </button>
5042 </p>
5043 <?php endif; ?>
5044 <?php else : ?>
5045 <div class="vigilante-paginated-section">
5046 <div class="vigilante-fi-pagination-wrap"></div>
5047 <table class="wp-list-table widefat fixed striped vigilante-sessions-table vigilante-fi-paginated">
5048 <thead>
5049 <tr>
5050 <th><?php esc_html_e( 'Browser', 'vigilante' ); ?></th>
5051 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
5052 <th><?php esc_html_e( 'Login Time', 'vigilante' ); ?></th>
5053 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5054 </tr>
5055 </thead>
5056 <tbody>
5057 <?php foreach ( $my_sessions as $session ) : ?>
5058 <tr data-token="<?php echo esc_attr( $session['token_hash'] ); ?>">
5059 <td><?php echo esc_html( $session['browser'] ); ?></td>
5060 <td><code><?php echo esc_html( $session['ip'] ); ?></code></td>
5061 <td>
5062 <?php
5063 if ( $session['login'] ) {
5064 /* translators: %s: Time ago */
5065 printf( esc_html__( '%s ago', 'vigilante' ), esc_html( human_time_diff( $session['login'] ) ) );
5066 } else {
5067 esc_html_e( 'Unknown', 'vigilante' );
5068 }
5069 ?>
5070 </td>
5071 <td>
5072 <?php if ( ! $session['is_current'] ) : ?>
5073 <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'] ); ?>">
5074 <?php esc_html_e( 'Revoke', 'vigilante' ); ?>
5075 </button>
5076 <?php else : ?>
5077 <span class="description"><?php esc_html_e( 'Current session', 'vigilante' ); ?></span>
5078 <?php endif; ?>
5079 </td>
5080 </tr>
5081 <?php endforeach; ?>
5082 </tbody>
5083 </table>
5084 </div>
5085
5086 <?php if ( count( $my_sessions ) > 1 || $has_corrupted ) : ?>
5087 <p style="margin-top: 10px;">
5088 <button type="button" class="button vigilante-revoke-other-sessions" data-user-id="<?php echo esc_attr( $current_user_id ); ?>">
5089 <?php esc_html_e( 'Revoke All Other Sessions', 'vigilante' ); ?>
5090 </button>
5091 </p>
5092 <?php endif; ?>
5093 <?php endif; ?>
5094
5095 <!-- Search user sessions (admin only) -->
5096 <h4 style="margin-top: 30px;"><?php esc_html_e( 'Manage user sessions', 'vigilante' ); ?></h4>
5097 <p class="description"><?php esc_html_e( 'Search for a user to view and manage their sessions.', 'vigilante' ); ?></p>
5098
5099 <div class="vigilante-user-search-wrapper" style="margin-top: 10px;">
5100 <input type="text" id="vigilante-session-user-search" class="regular-text" placeholder="<?php esc_attr_e( 'Search by username or email...', 'vigilante' ); ?>">
5101 <div id="vigilante-session-search-results" class="vigilante-user-search-results" style="display: none;"></div>
5102 </div>
5103
5104 <div id="vigilante-user-sessions-container" style="display: none; margin-top: 20px;">
5105 <h4 id="vigilante-sessions-user-name"></h4>
5106 <table class="wp-list-table widefat fixed striped vigilante-sessions-table">
5107 <thead>
5108 <tr>
5109 <th><?php esc_html_e( 'Browser', 'vigilante' ); ?></th>
5110 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
5111 <th><?php esc_html_e( 'Login Time', 'vigilante' ); ?></th>
5112 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5113 </tr>
5114 </thead>
5115 <tbody id="vigilante-user-sessions-list">
5116 </tbody>
5117 </table>
5118 <p style="margin-top: 10px;">
5119 <button type="button" class="button vigilante-revoke-all-user-sessions" style="color: #d63638;">
5120 <?php esc_html_e( 'Revoke All Sessions', 'vigilante' ); ?>
5121 </button>
5122 </p>
5123 </div>
5124 </div>
5125
5126 <?php endif; ?>
5127 </div>
5128 <?php
5129 }
5130
5131 /**
5132 * Render WordPress Hardening tab
5133 */
5134 private function render_tab_wp_hardening() {
5135 $is_disabled = $this->render_module_disabled_notice( 'wp_hardening' );
5136 $options = $this->settings->get_section( 'wp_hardening' );
5137 ?>
5138 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="wp_hardening" <?php echo $is_disabled ? 'inert' : ''; ?>>
5139 <!-- Database Hardening (outside form save flow - uses its own AJAX action) -->
5140 <?php $vg_shared_locked = $this->shared_files_locked(); ?>
5141 <?php $this->render_shared_files_notice(); ?>
5142 <div id="vigilante-section-hardening-database" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
5143 <h2>
5144 <?php esc_html_e( 'Database Hardening', 'vigilante' ); ?>
5145 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
5146 <span class="vigilante-method-badge config"><?php esc_html_e( 'WP-CONFIG', 'vigilante' ); ?></span>
5147 </h2>
5148 <p><?php esc_html_e( 'Change the database table prefix to prevent SQL injection attacks that target default WordPress tables.', 'vigilante' ); ?></p>
5149
5150 <?php
5151 $db_prefix = new Vigilante_Database_Prefix();
5152 $current_prefix = $db_prefix->get_current_prefix();
5153 $is_default = $db_prefix->is_default_prefix();
5154 ?>
5155
5156 <?php if ( is_multisite() && ! $vg_shared_locked ) : ?>
5157 <div class="notice notice-warning inline" style="margin:10px 0 16px;padding:8px 12px;">
5158 <p style="margin:0;"><?php esc_html_e( 'Network-wide operation: it renames the tables of every site in the network and rewrites the wp-config.php they all share. Back up the whole database first, not just the main site.', 'vigilante' ); ?></p>
5159 </div>
5160 <?php endif; ?>
5161
5162 <table class="form-table">
5163 <tr>
5164 <th scope="row"><?php esc_html_e( 'Current prefix', 'vigilante' ); ?></th>
5165 <td>
5166 <code class="vigilante-db-current-prefix"><?php echo esc_html( $current_prefix ); ?></code>
5167 <?php if ( $is_default ) : ?>
5168 <span class="vigilante-inline-warning">
5169 <span class="dashicons dashicons-warning"></span>
5170 <?php esc_html_e( 'Default prefix detected. Changing it adds a layer of protection against automated SQL injection attacks.', 'vigilante' ); ?>
5171 </span>
5172 <?php else : ?>
5173 <span class="vigilante-inline-ok">
5174 <span class="dashicons dashicons-yes-alt"></span>
5175 <?php esc_html_e( 'Custom prefix in use.', 'vigilante' ); ?>
5176 </span>
5177 <?php endif; ?>
5178 </td>
5179 </tr>
5180 <tr>
5181 <th scope="row"><?php esc_html_e( 'New prefix', 'vigilante' ); ?></th>
5182 <td>
5183 <div class="vigilante-db-prefix-row">
5184 <code class="vigilante-db-new-prefix" id="vigilante-new-prefix"><?php echo esc_html( $db_prefix->generate_prefix() ); ?></code>
5185 <button type="button" class="button button-small vigilante-db-regenerate-prefix" title="<?php esc_attr_e( 'Generate new prefix', 'vigilante' ); ?>">
5186 <span class="dashicons dashicons-update"></span>
5187 </button>
5188 </div>
5189 </td>
5190 </tr>
5191 <tr>
5192 <th scope="row"></th>
5193 <td>
5194 <div class="vigilante-db-prefix-confirm">
5195 <label>
5196 <input type="checkbox" id="vigilante-prefix-backup-confirm">
5197 <?php esc_html_e( 'I understand this operation is irreversible and I have a current database backup', 'vigilante' ); ?>
5198 </label>
5199 <p class="description">
5200 <?php
5201 printf(
5202 /* translators: %s: Link to tools tab */
5203 esc_html__( 'Need a backup? %s first.', 'vigilante' ),
5204 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Download a database backup', 'vigilante' ) . '</a>'
5205 );
5206 ?>
5207 </p>
5208 </div>
5209 <button type="button" class="button button-primary vigilante-db-change-prefix" disabled data-original-text="<?php esc_attr_e( 'Change Database Prefix', 'vigilante' ); ?>">
5210 <?php esc_html_e( 'Change Database Prefix', 'vigilante' ); ?>
5211 </button>
5212 </td>
5213 </tr>
5214 </table>
5215 </div>
5216
5217 <!-- wp-config Security -->
5218 <?php
5219 $vg_shared_locked = $this->shared_files_locked();
5220 // Paint what is actually in force, not this site's unused copy.
5221 $vg_local_options = $options;
5222 $options = $this->get_section_for_display( 'wp_hardening' );
5223 ?>
5224 <?php $this->render_shared_files_notice(); ?>
5225 <div id="vigilante-section-hardening-wpconfig" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
5226 <h2>
5227 <?php esc_html_e( 'wp-config.php Security', 'vigilante' ); ?>
5228 <span class="vigilante-method-badge config"><?php esc_html_e( 'WP-CONFIG', 'vigilante' ); ?></span>
5229 </h2>
5230 <p><?php esc_html_e( 'Security constants added directly to wp-config.php file.', 'vigilante' ); ?></p>
5231
5232 <table class="form-table">
5233 <tr>
5234 <th scope="row"><?php esc_html_e( 'Disable File Editor', 'vigilante' ); ?></th>
5235 <td>
5236 <label>
5237 <input type="checkbox" name="wp_hardening[disallow_file_edit]" value="1" <?php checked( ! empty( $options['disallow_file_edit'] ) ); ?>>
5238 <?php esc_html_e( 'Disable plugin and theme editor in admin (DISALLOW_FILE_EDIT)', 'vigilante' ); ?>
5239 </label>
5240 </td>
5241 </tr>
5242 <tr>
5243 <th scope="row"><?php esc_html_e( 'Disable File Modifications', 'vigilante' ); ?></th>
5244 <td>
5245 <label>
5246 <input type="checkbox" name="wp_hardening[disallow_file_mods]" value="1" <?php checked( ! empty( $options['disallow_file_mods'] ) ); ?>>
5247 <?php esc_html_e( 'Disable all file modifications including updates (DISALLOW_FILE_MODS)', 'vigilante' ); ?>
5248 </label>
5249 <p class="description"><?php esc_html_e( '&#9888; Warning: This prevents automatic updates.', 'vigilante' ); ?></p>
5250 </td>
5251 </tr>
5252 <tr id="field-force-ssl-admin">
5253 <th scope="row"><?php esc_html_e( 'Force SSL Admin', 'vigilante' ); ?></th>
5254 <td>
5255 <label>
5256 <input type="checkbox" name="wp_hardening[force_ssl_admin]" value="1" <?php checked( ! empty( $options['force_ssl_admin'] ) ); ?>>
5257 <?php esc_html_e( 'Force HTTPS for admin area (FORCE_SSL_ADMIN)', 'vigilante' ); ?>
5258 </label>
5259 <p class="description"><?php esc_html_e( '&#9888; Warning: Only enable if your site fully supports HTTPS.', 'vigilante' ); ?></p>
5260 </td>
5261 </tr>
5262 <tr id="field-wp-debug">
5263 <th scope="row"><?php esc_html_e( 'Hide PHP errors from visitors', 'vigilante' ); ?></th>
5264 <td>
5265 <label>
5266 <input type="checkbox" name="wp_hardening[wp_debug]" value="1" <?php checked( ! empty( $options['wp_debug'] ) ); ?>>
5267 <?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' ); ?>
5268 </label>
5269 </td>
5270 </tr>
5271 <tr id="field-disable-wp-cron">
5272 <th scope="row"><?php esc_html_e( 'Disable WP Cron', 'vigilante' ); ?></th>
5273 <td>
5274 <label>
5275 <input type="checkbox" name="wp_hardening[disable_wp_cron]" value="1" <?php checked( ! empty( $options['disable_wp_cron'] ) ); ?>>
5276 <?php esc_html_e( 'Disable WordPress\'s page-view cron trigger (DISABLE_WP_CRON)', 'vigilante' ); ?>
5277 </label>
5278 <p class="description"><?php
5279 printf(
5280 /* translators: 1: opening <strong>, 2: closing </strong>, 3: opening <code>, 4: closing </code> */
5281 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' ),
5282 '<strong>',
5283 '</strong>',
5284 '<code>',
5285 '</code>'
5286 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
5287 ?></p>
5288 </td>
5289 </tr>
5290 </table>
5291 </div>
5292 <?php $options = $vg_local_options; ?>
5293
5294 <!-- Comment Security -->
5295 <div id="vigilante-section-hardening-xmlrpc" class="vigilante-settings-section">
5296 <h2>
5297 <?php esc_html_e( 'XML-RPC', 'vigilante' ); ?>
5298 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5299 </h2>
5300 <p><?php esc_html_e( 'The legacy remote interface. It is what the WordPress mobile app, Jetpack and remote managers talk to, and also the way pingback amplification and password guessing reach a site.', 'vigilante' ); ?></p>
5301
5302 <table class="form-table">
5303 <tr id="field-disable-xmlrpc">
5304 <th scope="row"><label for="vigilante-f-wp-hardening-xmlrpc-mode"><?php esc_html_e( 'XML-RPC access', 'vigilante' ); ?></label></th>
5305 <td>
5306 <?php $vig_xmlrpc_mode = Vigilante_Comment_Security::resolve_xmlrpc_mode( $this->settings ); ?>
5307 <select id="vigilante-f-wp-hardening-xmlrpc-mode" name="wp_hardening[xmlrpc_mode]">
5308 <option value="none" <?php selected( $vig_xmlrpc_mode, 'none' ); ?>>
5309 <?php esc_html_e( 'Leave XML-RPC enabled', 'vigilante' ); ?>
5310 </option>
5311 <option value="pingback" <?php selected( $vig_xmlrpc_mode, 'pingback' ); ?>>
5312 <?php esc_html_e( 'Block the pingback methods only', 'vigilante' ); ?>
5313 </option>
5314 <option value="full" <?php selected( $vig_xmlrpc_mode, 'full' ); ?>>
5315 <?php esc_html_e( 'Disable XML-RPC completely (recommended)', 'vigilante' ); ?>
5316 </option>
5317 </select>
5318 <p class="description"><?php esc_html_e( 'Disable it completely unless something still needs it, such as the WordPress mobile app, Jetpack or a remote manager; in that case block only the pingback methods, which closes the amplification vector and leaves the rest working. Pingbacks are also covered by the Comment Security setting just below, which additionally closes them for comments.', 'vigilante' ); ?></p>
5319 </td>
5320 </tr>
5321 </table>
5322 </div>
5323
5324 <div id="vigilante-section-hardening-comments" class="vigilante-settings-section">
5325 <h2>
5326 <?php esc_html_e( 'Comment Security', 'vigilante' ); ?>
5327 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5328 <span class="vigilante-method-badge settings"><?php esc_html_e( 'Settings', 'vigilante' ); ?></span>
5329 </h2>
5330 <p><?php esc_html_e( 'Comment protection using WordPress settings and PHP hooks.', 'vigilante' ); ?></p>
5331
5332 <table class="form-table">
5333 <tr>
5334 <th scope="row"><?php esc_html_e( 'Disable Pingbacks', 'vigilante' ); ?></th>
5335 <td>
5336 <label>
5337 <input type="checkbox" name="wp_hardening[disable_pingbacks]" value="1" <?php checked( ! empty( $options['disable_pingbacks'] ) ); ?>>
5338 <?php esc_html_e( 'Disable pingbacks (commonly exploited for DDoS)', 'vigilante' ); ?>
5339 </label>
5340 </td>
5341 </tr>
5342 <tr>
5343 <th scope="row"><?php esc_html_e( 'Disable Trackbacks', 'vigilante' ); ?></th>
5344 <td>
5345 <label>
5346 <input type="checkbox" name="wp_hardening[disable_trackbacks]" value="1" <?php checked( ! empty( $options['disable_trackbacks'] ) ); ?>>
5347 <?php esc_html_e( 'Disable trackbacks (rarely used legitimately)', 'vigilante' ); ?>
5348 </label>
5349 </td>
5350 </tr>
5351 <tr>
5352 <th scope="row"><?php esc_html_e( 'Require Moderation', 'vigilante' ); ?></th>
5353 <td>
5354 <label>
5355 <input type="checkbox" name="wp_hardening[require_comment_moderation]" value="1" <?php checked( ! empty( $options['require_comment_moderation'] ) ); ?>>
5356 <?php esc_html_e( 'All comments must be manually approved', 'vigilante' ); ?>
5357 </label>
5358 </td>
5359 </tr>
5360 <tr>
5361 <th scope="row"><?php esc_html_e( 'Close Old Comments', 'vigilante' ); ?></th>
5362 <td>
5363 <label>
5364 <input type="checkbox" name="wp_hardening[close_old_comments]" value="1" <?php checked( ! empty( $options['close_old_comments'] ) ); ?>>
5365 <?php esc_html_e( 'Automatically close comments on old posts after', 'vigilante' ); ?>
5366 </label>
5367 <input type="number" id="vigilante-f-wp-hardening-close-comments-after-days" 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">
5368 <label for="vigilante-f-wp-hardening-close-comments-after-days"><?php esc_html_e( 'days', 'vigilante' ); ?></label>
5369 </td>
5370 </tr>
5371 <tr>
5372 <th scope="row"><?php esc_html_e( 'Honeypot Protection', 'vigilante' ); ?></th>
5373 <td>
5374 <label>
5375 <input type="checkbox" name="wp_hardening[honeypot_comments]" value="1" <?php checked( ! empty( $options['honeypot_comments'] ) ); ?>>
5376 <?php esc_html_e( 'Add hidden honeypot field to catch bots', 'vigilante' ); ?>
5377 </label>
5378 </td>
5379 </tr>
5380 </table>
5381 </div>
5382
5383 <!-- Head Cleaner -->
5384 <div id="vigilante-section-hardening-headers" class="vigilante-settings-section">
5385 <h2>
5386 <?php esc_html_e( 'Header Cleanup', 'vigilante' ); ?>
5387 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5388 </h2>
5389 <p><?php esc_html_e( 'Remove meta tags from HTML head.', 'vigilante' ); ?></p>
5390
5391 <table class="form-table">
5392 <tr>
5393 <th scope="row"><?php esc_html_e( 'Remove Generator', 'vigilante' ); ?></th>
5394 <td>
5395 <label>
5396 <input type="checkbox" name="wp_hardening[remove_wp_generator]" value="1" <?php checked( ! empty( $options['remove_wp_generator'] ) ); ?>>
5397 <?php esc_html_e( 'Remove WordPress version from HTML head', 'vigilante' ); ?>
5398 </label>
5399 </td>
5400 </tr>
5401 <tr id="field-remove-wp-version-assets">
5402 <th scope="row"><?php esc_html_e( 'Remove version from assets', 'vigilante' ); ?></th>
5403 <td>
5404 <label>
5405 <input type="checkbox" name="wp_hardening[remove_wp_version_assets]" value="1" <?php checked( ! empty( $options['remove_wp_version_assets'] ) ); ?>>
5406 <?php esc_html_e( 'Remove WordPress version from script/style URLs (?ver=)', 'vigilante' ); ?>
5407 </label>
5408 <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>
5409 </td>
5410 </tr>
5411 <tr>
5412 <th scope="row"><?php esc_html_e( 'Remove RSD Link', 'vigilante' ); ?></th>
5413 <td>
5414 <label>
5415 <input type="checkbox" name="wp_hardening[remove_rsd_link]" value="1" <?php checked( ! empty( $options['remove_rsd_link'] ) ); ?>>
5416 <?php esc_html_e( 'Remove Really Simple Discovery link', 'vigilante' ); ?>
5417 </label>
5418 </td>
5419 </tr>
5420 <tr>
5421 <th scope="row"><?php esc_html_e( 'Remove WLW Manifest', 'vigilante' ); ?></th>
5422 <td>
5423 <label>
5424 <input type="checkbox" name="wp_hardening[remove_wlw_manifest]" value="1" <?php checked( ! empty( $options['remove_wlw_manifest'] ) ); ?>>
5425 <?php esc_html_e( 'Remove Windows Live Writer manifest link', 'vigilante' ); ?>
5426 </label>
5427 </td>
5428 </tr>
5429 <tr>
5430 <th scope="row"><?php esc_html_e( 'Remove Shortlink', 'vigilante' ); ?></th>
5431 <td>
5432 <label>
5433 <input type="checkbox" name="wp_hardening[remove_shortlink]" value="1" <?php checked( ! empty( $options['remove_shortlink'] ) ); ?>>
5434 <?php esc_html_e( 'Remove shortlink tag from header', 'vigilante' ); ?>
5435 </label>
5436 </td>
5437 </tr>
5438 <tr>
5439 <th scope="row"><?php esc_html_e( 'Remove REST API Link', 'vigilante' ); ?></th>
5440 <td>
5441 <label>
5442 <input type="checkbox" name="wp_hardening[remove_rest_api_link]" value="1" <?php checked( ! empty( $options['remove_rest_api_link'] ) ); ?>>
5443 <?php esc_html_e( 'Remove REST API discovery link from header', 'vigilante' ); ?>
5444 </label>
5445 <p class="description"><?php esc_html_e( '&#9888; Notice: Some plugins may need this link.', 'vigilante' ); ?></p>
5446 </td>
5447 </tr>
5448 </table>
5449 </div>
5450
5451 <!-- Feed Manager -->
5452 <div id="vigilante-section-hardening-rss" class="vigilante-settings-section">
5453 <h2>
5454 <?php esc_html_e( 'RSS Feed Settings', 'vigilante' ); ?>
5455 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5456 </h2>
5457 <p><?php esc_html_e( 'Control RSS/Atom feeds.', 'vigilante' ); ?></p>
5458
5459 <table class="form-table">
5460 <tr>
5461 <th scope="row"><?php esc_html_e( 'Disable Feeds', 'vigilante' ); ?></th>
5462 <td>
5463 <label>
5464 <input type="checkbox" name="wp_hardening[disable_feeds]" value="1" <?php checked( ! empty( $options['disable_feeds'] ) ); ?>>
5465 <?php esc_html_e( 'Completely disable RSS/Atom feeds', 'vigilante' ); ?>
5466 </label>
5467 </td>
5468 </tr>
5469 <tr>
5470 <th scope="row"><?php esc_html_e( 'Disable If No Content', 'vigilante' ); ?></th>
5471 <td>
5472 <label>
5473 <input type="checkbox" name="wp_hardening[disable_if_no_content]" value="1" <?php checked( ! empty( $options['disable_if_no_content'] ) ); ?>>
5474 <?php esc_html_e( 'Only disable feeds if site has no published posts', 'vigilante' ); ?>
5475 </label>
5476 </td>
5477 </tr>
5478 <tr>
5479 <th scope="row"><?php esc_html_e( 'Remove Feed Version', 'vigilante' ); ?></th>
5480 <td>
5481 <label>
5482 <input type="checkbox" name="wp_hardening[remove_feed_version]" value="1" <?php checked( ! empty( $options['remove_feed_version'] ) ); ?>>
5483 <?php esc_html_e( 'Remove WordPress version from feed generator tag', 'vigilante' ); ?>
5484 </label>
5485 </td>
5486 </tr>
5487 </table>
5488 </div>
5489
5490 <p class="submit vigilante-submit-buttons">
5491 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5492 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5493 </button>
5494 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5495 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5496 </button>
5497 </p>
5498 </form>
5499 <?php
5500 }
5501
5502 /**
5503 * Render activity log tab
5504 */
5505 private function render_tab_activity_log() {
5506 $is_disabled = $this->render_module_disabled_notice( 'activity_log' );
5507 $options = $this->settings->get_section( 'activity_log' );
5508 ?>
5509 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="activity_log" <?php echo $is_disabled ? 'inert' : ''; ?>>
5510 <div id="vigilante-section-audit-settings" class="vigilante-settings-section">
5511 <h2>
5512 <?php esc_html_e( 'Security Audit Settings', 'vigilante' ); ?>
5513 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5514 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
5515 </h2>
5516 <p><?php esc_html_e( 'Security event logging and auditing.', 'vigilante' ); ?></p>
5517
5518 <table class="form-table">
5519 <tr>
5520 <th scope="row"><?php esc_html_e( 'Retention', 'vigilante' ); ?></th>
5521 <td>
5522 <input type="number" id="vigilante-f-activity-log-retention-days" name="activity_log[retention_days]" value="<?php echo esc_attr( $options['retention_days'] ?? 30 ); ?>" min="7" max="365" class="small-text">
5523 <label for="vigilante-f-activity-log-retention-days"><?php esc_html_e( 'days', 'vigilante' ); ?></label>
5524 &nbsp;&nbsp;
5525 <input type="number" id="vigilante-f-activity-log-max-entries" name="activity_log[max_entries]" value="<?php echo esc_attr( $options['max_entries'] ?? 10000 ); ?>" min="100" max="100000" step="100" class="small-text">
5526 <label for="vigilante-f-activity-log-max-entries"><?php esc_html_e( 'max entries', 'vigilante' ); ?></label>
5527 <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>
5528 </td>
5529 </tr>
5530 <tr>
5531 <th scope="row"><?php esc_html_e( 'Events to Log', 'vigilante' ); ?></th>
5532 <td>
5533 <fieldset style="display:grid; grid-template-columns:repeat(auto-fit, minmax(240px, 1fr)); gap:6px 24px; max-width:600px;">
5534 <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>
5535 <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>
5536 <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>
5537 <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>
5538 <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>
5539 <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>
5540 <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>
5541 <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>
5542 <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>
5543 <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>
5544 </fieldset>
5545 <div class="notice notice-info inline" style="margin:10px 0 0;padding:8px 12px;">
5546 <p style="margin:0;">
5547 <?php esc_html_e( 'Firewall blocks, security events, and Vigilant settings changes are always logged regardless of the above selections.', 'vigilante' ); ?>
5548 </p>
5549 </div>
5550 </td>
5551 </tr>
5552 <tr>
5553 <th scope="row"><label for="vigilante-f-activity-log-tracked-options"><?php esc_html_e( 'Option Tracking', 'vigilante' ); ?></label></th>
5554 <td>
5555 <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>
5556 <br>
5557 <label><?php esc_html_e( 'Additional options to track:', 'vigilante' ); ?></label><br>
5558 <textarea id="vigilante-f-activity-log-tracked-options" 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>
5559 <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>
5560 </td>
5561 </tr>
5562 <tr>
5563 <th scope="row"><?php esc_html_e( 'Exclusions', 'vigilante' ); ?></th>
5564 <td>
5565 <div style="display:grid; grid-template-columns:repeat(auto-fit, minmax(220px, 1fr)); gap:16px; max-width:600px;">
5566 <div>
5567 <label for="vigilante-f-activity-log-excluded-users"><?php esc_html_e( 'Excluded user IDs:', 'vigilante' ); ?></label><br>
5568 <textarea id="vigilante-f-activity-log-excluded-users" name="activity_log[excluded_users]" rows="3" cols="25"><?php echo esc_textarea( implode( "\n", $options['excluded_users'] ?? array() ) ); ?></textarea>
5569 <p class="description"><?php esc_html_e( 'One user ID per line. Actions by these users will not be logged.', 'vigilante' ); ?></p>
5570 </div>
5571 <div>
5572 <label for="vigilante-f-activity-log-excluded-ips"><?php esc_html_e( 'Excluded IPs:', 'vigilante' ); ?></label><br>
5573 <textarea id="vigilante-f-activity-log-excluded-ips" name="activity_log[excluded_ips]" rows="3" cols="25"><?php echo esc_textarea( implode( "\n", $options['excluded_ips'] ?? array() ) ); ?></textarea>
5574 <p class="description"><?php esc_html_e( 'One IP per line. Requests from these IPs will not be logged.', 'vigilante' ); ?></p>
5575 </div>
5576 </div>
5577 </td>
5578 </tr>
5579 </table>
5580 </div>
5581
5582 <p class="submit vigilante-submit-buttons">
5583 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5584 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5585 </button>
5586 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5587 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5588 </button>
5589 </p>
5590 </form>
5591
5592 <?php
5593 // Audit Alerts — alerting layer on top of Security Audit. Its own
5594 // settings section and form, rendered right after the logging settings
5595 // so the tab reads as "log this, exclude that, and alert me about this".
5596 $alerts = $this->settings->get_section( 'audit_alerts' );
5597 $immediate = isset( $alerts['immediate'] ) ? $alerts['immediate'] : array();
5598 $threshold = isset( $alerts['threshold'] ) ? $alerts['threshold'] : array();
5599 $alert_severity = isset( $immediate['min_severity'] ) ? $immediate['min_severity'] : 'critical';
5600 $alert_window = isset( $threshold['window'] ) ? $threshold['window'] : '1h';
5601 $threshold_cats = isset( $threshold['categories'] ) ? (array) $threshold['categories'] : array();
5602 $cat_labels = Vigilante_Audit_Alerts::category_labels();
5603 ?>
5604 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="audit_alerts" <?php echo $is_disabled ? 'inert' : ''; ?>>
5605 <div id="vigilante-section-audit-alerts" class="vigilante-settings-section">
5606 <h2>
5607 <?php esc_html_e( 'Audit Alerts', 'vigilante' ); ?>
5608 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5609 </h2>
5610 <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>
5611
5612 <table class="form-table">
5613 <tr id="field-audit-alerts-immediate">
5614 <th scope="row"><?php esc_html_e( 'Immediate alerts', 'vigilante' ); ?></th>
5615 <td>
5616 <label>
5617 <input type="checkbox" name="audit_alerts[immediate][enabled]" value="1" <?php checked( ! empty( $immediate['enabled'] ) ); ?>>
5618 <?php esc_html_e( 'Email me as soon as a serious event is logged', 'vigilante' ); ?>
5619 </label>
5620 <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>
5621 </td>
5622 </tr>
5623 <tr>
5624 <th scope="row"><label for="vigilante-f-audit-alerts-immediate-min-severity"><?php esc_html_e( 'Alert on severity', 'vigilante' ); ?></label></th>
5625 <td>
5626 <select id="vigilante-f-audit-alerts-immediate-min-severity" name="audit_alerts[immediate][min_severity]">
5627 <option value="critical" <?php selected( $alert_severity, 'critical' ); ?>><?php esc_html_e( 'Critical only (recommended)', 'vigilante' ); ?></option>
5628 <option value="warning" <?php selected( $alert_severity, 'warning' ); ?>><?php esc_html_e( 'Warning and Critical', 'vigilante' ); ?></option>
5629 </select>
5630 <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>
5631 </td>
5632 </tr>
5633 <tr id="field-audit-alerts-threshold">
5634 <th scope="row"><?php esc_html_e( 'Threshold alerts', 'vigilante' ); ?></th>
5635 <td>
5636 <label>
5637 <input type="checkbox" name="audit_alerts[threshold][enabled]" value="1" <?php checked( ! empty( $threshold['enabled'] ) ); ?>>
5638 <?php esc_html_e( 'Email me when a category spikes within a time window', 'vigilante' ); ?>
5639 </label>
5640 <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>
5641 </td>
5642 </tr>
5643 <tr>
5644 <th scope="row"><label for="vigilante-f-audit-alerts-threshold-window"><?php esc_html_e( 'Time window', 'vigilante' ); ?></label></th>
5645 <td>
5646 <select id="vigilante-f-audit-alerts-threshold-window" name="audit_alerts[threshold][window]">
5647 <option value="30m" <?php selected( $alert_window, '30m' ); ?>><?php esc_html_e( '30 minutes', 'vigilante' ); ?></option>
5648 <option value="1h" <?php selected( $alert_window, '1h' ); ?>><?php esc_html_e( '1 hour', 'vigilante' ); ?></option>
5649 <option value="6h" <?php selected( $alert_window, '6h' ); ?>><?php esc_html_e( '6 hours', 'vigilante' ); ?></option>
5650 <option value="24h" <?php selected( $alert_window, '24h' ); ?>><?php esc_html_e( '24 hours', 'vigilante' ); ?></option>
5651 </select>
5652 <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>
5653 </td>
5654 </tr>
5655 <tr>
5656 <th scope="row"><?php esc_html_e( 'Thresholds per category', 'vigilante' ); ?></th>
5657 <td>
5658 <fieldset style="display:grid; grid-template-columns:repeat(auto-fit, minmax(200px, 1fr)); gap:8px 24px; max-width:760px;">
5659 <?php
5660 foreach ( $cat_labels as $cat_slug => $cat_label ) :
5661 $cat_value = isset( $threshold_cats[ $cat_slug ] ) ? (int) $threshold_cats[ $cat_slug ] : 0;
5662 ?>
5663 <label style="display:flex;align-items:center;gap:8px;justify-content:space-between;">
5664 <span><?php echo esc_html( $cat_label ); ?></span>
5665 <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">
5666 </label>
5667 <?php endforeach; ?>
5668 </fieldset>
5669 <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>
5670 </td>
5671 </tr>
5672 <tr>
5673 <th scope="row"><?php esc_html_e( "Don't repeat alerts", 'vigilante' ); ?></th>
5674 <td>
5675 <input type="number" id="vigilante-f-audit-alerts-cooldown-minutes" 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">
5676 <label for="vigilante-f-audit-alerts-cooldown-minutes"><?php esc_html_e( 'minutes', 'vigilante' ); ?></label>
5677 <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>
5678 </td>
5679 </tr>
5680
5681 <tr>
5682 <th scope="row"><?php esc_html_e( 'Recipients', 'vigilante' ); ?></th>
5683 <td>
5684 <p class="description" style="margin-top:0;">
5685 <?php
5686 printf(
5687 /* translators: %s: Link to notification settings */
5688 esc_html__( 'Alerts go to the recipients configured in %s.', 'vigilante' ),
5689 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
5690 );
5691 ?>
5692 </p>
5693 <p style="margin:8px 0 0;">
5694 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
5695 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
5696 </button>
5697 <span class="vigilante-test-email-result" style="margin-left:8px;"></span>
5698 </p>
5699 <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>
5700 </td>
5701 </tr>
5702 </table>
5703 </div>
5704
5705 <p class="submit vigilante-submit-buttons">
5706 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5707 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5708 </button>
5709 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5710 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5711 </button>
5712 </p>
5713 </form>
5714
5715 <div id="vigilante-section-audit-recent" class="vigilante-settings-section">
5716 <h2><?php esc_html_e( 'Recent Activity', 'vigilante' ); ?></h2>
5717
5718 <?php
5719 $logs = $this->activity_log->get_logs( array( 'per_page' => 20 ) );
5720 $total_logs = $this->activity_log->get_logs_count();
5721
5722 // Label maps for translated display
5723 $type_labels = array(
5724 'login' => __( 'Login', 'vigilante' ),
5725 'user' => __( 'User', 'vigilante' ),
5726 'content' => __( 'Content', 'vigilante' ),
5727 'plugin' => __( 'Plugin', 'vigilante' ),
5728 'theme' => __( 'Theme', 'vigilante' ),
5729 'settings' => __( 'Settings', 'vigilante' ),
5730 'comment' => __( 'Comment', 'vigilante' ),
5731 'media' => __( 'Media', 'vigilante' ),
5732 'firewall' => __( 'Firewall', 'vigilante' ),
5733 'file' => __( 'File', 'vigilante' ),
5734 'security' => __( 'Security', 'vigilante' ),
5735 'system' => __( 'System', 'vigilante' ),
5736 );
5737 $severity_labels = array(
5738 'info' => __( 'Info', 'vigilante' ),
5739 'warning' => __( 'Warning', 'vigilante' ),
5740 'critical' => __( 'Critical', 'vigilante' ),
5741 );
5742
5743 $firewall_options = $this->settings->get_section( 'firewall' );
5744 $ip_whitelist = $firewall_options['ip_whitelist'] ?? array();
5745 $ip_blacklist = $firewall_options['ip_blacklist'] ?? array();
5746 $ua_whitelist = $firewall_options['ua_whitelist'] ?? array();
5747 $ua_blacklist = $firewall_options['ua_blacklist'] ?? array();
5748 ?>
5749
5750 <div class="vigilante-log-filters">
5751 <input type="text" id="vigilante-log-search" aria-label="<?php esc_attr_e( 'Search the activity log', 'vigilante' ); ?>" size="1" placeholder="<?php esc_attr_e( 'Search logs (min. 3 characters)...', 'vigilante' ); ?>" class="vigilante-log-search-input">
5752 <select id="vigilante-log-type-filter" aria-label="<?php esc_attr_e( 'Filter the log by event type', 'vigilante' ); ?>">
5753 <option value=""><?php esc_html_e( 'All Types', 'vigilante' ); ?></option>
5754 <option value="login"><?php esc_html_e( 'Login', 'vigilante' ); ?></option>
5755 <option value="user"><?php esc_html_e( 'User', 'vigilante' ); ?></option>
5756 <option value="content"><?php esc_html_e( 'Content', 'vigilante' ); ?></option>
5757 <option value="plugin"><?php esc_html_e( 'Plugin', 'vigilante' ); ?></option>
5758 <option value="theme"><?php esc_html_e( 'Theme', 'vigilante' ); ?></option>
5759 <option value="settings"><?php esc_html_e( 'Settings', 'vigilante' ); ?></option>
5760 <option value="comment"><?php esc_html_e( 'Comment', 'vigilante' ); ?></option>
5761 <option value="media"><?php esc_html_e( 'Media', 'vigilante' ); ?></option>
5762 <option value="firewall"><?php esc_html_e( 'Firewall', 'vigilante' ); ?></option>
5763 <option value="file"><?php esc_html_e( 'File', 'vigilante' ); ?></option>
5764 <option value="security"><?php esc_html_e( 'Security', 'vigilante' ); ?></option>
5765 <option value="system"><?php esc_html_e( 'System', 'vigilante' ); ?></option>
5766 </select>
5767 <select id="vigilante-log-severity-filter" aria-label="<?php esc_attr_e( 'Filter the log by severity', 'vigilante' ); ?>">
5768 <option value=""><?php esc_html_e( 'All Severities', 'vigilante' ); ?></option>
5769 <option value="info"><?php esc_html_e( 'Info', 'vigilante' ); ?></option>
5770 <option value="warning"><?php esc_html_e( 'Warning', 'vigilante' ); ?></option>
5771 <option value="critical"><?php esc_html_e( 'Critical', 'vigilante' ); ?></option>
5772 </select>
5773 <select id="vigilante-log-method-filter" aria-label="<?php esc_attr_e( 'Filter the log by HTTP method', 'vigilante' ); ?>">
5774 <option value=""><?php esc_html_e( 'All Methods', 'vigilante' ); ?></option>
5775 <option value="GET">GET</option>
5776 <option value="POST">POST</option>
5777 <option value="PUT">PUT</option>
5778 <option value="DELETE">DELETE</option>
5779 <option value="PATCH">PATCH</option>
5780 <option value="OPTIONS">OPTIONS</option>
5781 <option value="HEAD">HEAD</option>
5782 </select>
5783 <button type="button" id="vigilante-log-refresh" class="button"><?php esc_html_e( 'Refresh', 'vigilante' ); ?></button>
5784 <span class="vigilante-pagination" id="vigilante-log-pagination" data-total="<?php echo esc_attr( $total_logs ); ?>" data-per-page="20" data-page="1">
5785 <?php if ( $total_logs > 20 ) : ?>
5786 <button type="button" class="vigilante-page-first" title="<?php esc_attr_e( 'First page', 'vigilante' ); ?>" disabled>&laquo;</button>
5787 <button type="button" class="vigilante-page-prev" title="<?php esc_attr_e( 'Previous page', 'vigilante' ); ?>" disabled>&lsaquo;</button>
5788 <?php endif; ?>
5789 <span class="vigilante-page-info">
5790 <?php
5791 $showing = min( 20, $total_logs );
5792 printf(
5793 /* translators: 1: first item, 2: last item, 3: total items */
5794 esc_html__( '%1$d–%2$d of %3$d', 'vigilante' ),
5795 $total_logs > 0 ? 1 : 0,
5796 absint( $showing ),
5797 absint( $total_logs )
5798 );
5799 ?>
5800 </span>
5801 <?php if ( $total_logs > 20 ) : ?>
5802 <button type="button" class="vigilante-page-next" title="<?php esc_attr_e( 'Next page', 'vigilante' ); ?>">&rsaquo;</button>
5803 <button type="button" class="vigilante-page-last" title="<?php esc_attr_e( 'Last page', 'vigilante' ); ?>">&raquo;</button>
5804 <?php endif; ?>
5805 </span>
5806 </div>
5807
5808 <div class="vigilante-log-table-wrap">
5809 <table id="vigilante-activity-log-table" class="wp-list-table widefat striped">
5810 <thead>
5811 <tr>
5812 <th class="column-date"><?php esc_html_e( 'Date', 'vigilante' ); ?></th>
5813 <th class="column-type"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
5814 <th class="column-method"><?php esc_html_e( 'Method', 'vigilante' ); ?></th>
5815 <th class="column-severity"><?php esc_html_e( 'Severity', 'vigilante' ); ?></th>
5816 <th class="column-message"><?php esc_html_e( 'Message', 'vigilante' ); ?></th>
5817 <th class="column-user"><?php esc_html_e( 'User', 'vigilante' ); ?></th>
5818 <th class="column-ip"><?php esc_html_e( 'IP', 'vigilante' ); ?></th>
5819 <th class="column-details"><?php esc_html_e( 'Details', 'vigilante' ); ?></th>
5820 </tr>
5821 </thead>
5822 <tbody>
5823 <?php
5824 if ( empty( $logs ) ) :
5825 ?>
5826 <tr><td colspan="8"><?php esc_html_e( 'No log entries found.', 'vigilante' ); ?></td></tr>
5827 <?php else : ?>
5828 <?php foreach ( $logs as $log ) :
5829 $request_method = isset( $log->request_method ) ? $log->request_method : '';
5830 // Prepare details as a simple object
5831 $ip_val = (string) ( $log->ip_address ?? '' );
5832 $ua_val = (string) ( $log->user_agent ?? '' );
5833 $details = array(
5834 'id' => (int) $log->id,
5835 'type' => (string) ( $log->event_type ?? '' ),
5836 'action' => (string) ( $log->event_action ?? '' ),
5837 'message' => (string) ( $log->event_message ?? '' ),
5838 'user' => (string) ( $log->user_login ?? '' ),
5839 'ip' => $ip_val,
5840 'user_agent' => $ua_val,
5841 'request_method' => (string) $request_method,
5842 'request_uri' => Vigilante_Activity_Log::extract_request_uri( $log->extra_data ?? '' ),
5843 'date' => (string) ( $log->created_at ?? '' ),
5844 'severity' => (string) ( $log->severity ?? 'info' ),
5845 'is_ip_whitelisted' => ( '' !== $ip_val && in_array( $ip_val, $ip_whitelist, true ) ),
5846 'is_ip_blacklisted' => ( '' !== $ip_val && in_array( $ip_val, $ip_blacklist, true ) ),
5847 'is_ua_whitelisted' => ( '' !== $ua_val && in_array( $ua_val, $ua_whitelist, true ) ),
5848 'is_ua_blacklisted' => ( '' !== $ua_val && in_array( $ua_val, $ua_blacklist, true ) ),
5849 );
5850 $display_type = isset( $type_labels[ $log->event_type ] ) ? $type_labels[ $log->event_type ] : $log->event_type;
5851 $display_severity = isset( $severity_labels[ $log->severity ] ) ? $severity_labels[ $log->severity ] : $log->severity;
5852 ?>
5853 <tr class="vigilante-severity-<?php echo esc_attr( $log->severity ); ?>">
5854 <td><?php echo esc_html( $log->created_at ); ?></td>
5855 <td><?php echo esc_html( $display_type ); ?></td>
5856 <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>
5857 <td><span class="vigilante-badge vigilante-badge-<?php echo esc_attr( $log->severity ); ?>"><?php echo esc_html( $display_severity ); ?></span></td>
5858 <td><?php echo esc_html( $log->event_message ); ?></td>
5859 <td><?php echo esc_html( $log->user_login ?? '-' ); ?></td>
5860 <td><code><?php echo esc_html( $log->ip_address ); ?></code></td>
5861 <td>
5862 <button type="button" class="button button-small vigilante-view-log-details"
5863 data-details='<?php echo esc_attr( wp_json_encode( $details, JSON_HEX_APOS | JSON_HEX_QUOT ) ); ?>'>
5864 <?php esc_html_e( 'View', 'vigilante' ); ?>
5865 </button>
5866 </td>
5867 </tr>
5868 <?php endforeach; ?>
5869 <?php endif; ?>
5870 </tbody>
5871 </table>
5872 </div>
5873
5874 <!-- Log Details Modal -->
5875 <div id="vigilante-log-details-modal" class="vigilante-modal" style="display: none;">
5876 <div class="vigilante-modal-content">
5877 <span class="vigilante-modal-close">&times;</span>
5878 <h3><?php esc_html_e( 'Log Entry Details', 'vigilante' ); ?></h3>
5879 <div id="vigilante-log-details-content"></div>
5880 </div>
5881 </div>
5882
5883 <p>
5884 <button type="button" class="button vigilante-export-logs"><?php esc_html_e( 'Export Audit Log', 'vigilante' ); ?></button>
5885 <button type="button" class="button vigilante-clear-logs" style="color: #a00;"><?php esc_html_e( 'Clear All Logs', 'vigilante' ); ?></button>
5886 </p>
5887 </div>
5888 <?php
5889 }
5890
5891 /**
5892 * Render File Integrity tab
5893 */
5894 private function render_tab_file_integrity() {
5895 $is_disabled = $this->render_module_disabled_notice( 'file_integrity' );
5896 $options = $this->settings->get_section( 'file_integrity' );
5897 $last_scan = get_option( 'vigilante_last_integrity_scan' );
5898 $last_results = get_option( 'vigilante_last_integrity_results' );
5899 $ignored_files = get_option( 'vigilante_ignored_files', array() );
5900
5901 // Backward compat: convert old notify_on_changes to notify_level
5902 $notify_level = $options['notify_level'] ?? '';
5903 if ( empty( $notify_level ) ) {
5904 $notify_level = ! empty( $options['notify_on_changes'] ) ? 'all' : 'disabled';
5905 }
5906
5907 // Closed + Removed plugins data. Surfaced inside Last Scan Results so the
5908 // user sees file findings and plugin closures together (same tier of risk,
5909 // same UI), and as the trigger to keep Last Scan Results open even when no
5910 // file scan has run yet (the daily cron may have populated this section).
5911 //
5912 // Gating by last_check_time > 0 is how "Clear Previous Results" visually
5913 // resets this block: the option vigilante_plugin_status_last_check is
5914 // deleted on Clear, but the state map and the ignored list survive so the
5915 // next scan reconstructs without degrading a 'removed' slug. While
5916 // last_check is 0, we treat the plugin_status data as if it didn't exist.
5917 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
5918 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
5919 }
5920 $closed_checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
5921 $closed_last_check = $closed_checker->get_last_check_time();
5922 if ( $closed_last_check > 0 ) {
5923 $closed_plugins = $closed_checker->get_closed_plugins();
5924 $ignored_closed_plugins = $closed_checker->get_ignored_closed_plugins();
5925 } else {
5926 $closed_plugins = array();
5927 $ignored_closed_plugins = array();
5928 }
5929 $has_closed = ! empty( $closed_plugins );
5930 $datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
5931 ?>
5932 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="file_integrity" <?php echo $is_disabled ? 'inert' : ''; ?>>
5933 <div id="vigilante-section-fi-monitoring" class="vigilante-settings-section">
5934 <h2>
5935 <?php esc_html_e( 'File Integrity Monitoring', 'vigilante' ); ?>
5936 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5937 </h2>
5938 <p><?php esc_html_e( 'Detects file modifications using WordPress.org checksums.', 'vigilante' ); ?></p>
5939
5940 <table class="form-table">
5941 <tr>
5942 <th scope="row"><?php esc_html_e( 'Automatic Scans', 'vigilante' ); ?></th>
5943 <td>
5944 <label>
5945 <input type="checkbox" name="file_integrity[auto_scan]" value="1" <?php checked( ! empty( $options['auto_scan'] ) ); ?>>
5946 <?php esc_html_e( 'Enable scheduled file integrity scans', 'vigilante' ); ?>
5947 </label>
5948 </td>
5949 </tr>
5950 <tr>
5951 <th scope="row"><label for="vigilante-f-file-integrity-scan-frequency"><?php esc_html_e( 'Scan Frequency', 'vigilante' ); ?></label></th>
5952 <td>
5953 <select id="vigilante-f-file-integrity-scan-frequency" name="file_integrity[scan_frequency]">
5954 <option value="daily" <?php selected( $options['scan_frequency'] ?? 'daily', 'daily' ); ?>><?php esc_html_e( 'Daily', 'vigilante' ); ?></option>
5955 <option value="weekly" <?php selected( $options['scan_frequency'] ?? 'daily', 'weekly' ); ?>><?php esc_html_e( 'Weekly', 'vigilante' ); ?></option>
5956 </select>
5957 </td>
5958 </tr>
5959 <tr>
5960 <th scope="row"><label for="vigilante-f-file-integrity-notify-level"><?php esc_html_e( 'Email Notifications', 'vigilante' ); ?></label></th>
5961 <td>
5962 <select id="vigilante-f-file-integrity-notify-level" name="file_integrity[notify_level]">
5963 <option value="all" <?php selected( $notify_level, 'all' ); ?>><?php esc_html_e( 'All issues (modified + suspicious)', 'vigilante' ); ?></option>
5964 <option value="suspicious_only" <?php selected( $notify_level, 'suspicious_only' ); ?>><?php esc_html_e( 'Suspicious files only', 'vigilante' ); ?></option>
5965 <option value="disabled" <?php selected( $notify_level, 'disabled' ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
5966 </select>
5967 <p class="description"><?php esc_html_e( '"Suspicious files only" reduces noise by skipping modified file notifications. Recommended for most sites.', 'vigilante' ); ?></p>
5968 </td>
5969 </tr>
5970 <tr>
5971 <th scope="row"><?php esc_html_e( 'Instant Alert', 'vigilante' ); ?></th>
5972 <td>
5973 <label>
5974 <input type="checkbox" name="file_integrity[instant_alert]" value="1" <?php checked( ! empty( $options['instant_alert'] ) ); ?>>
5975 <?php esc_html_e( 'Send immediate alert when modified, suspicious or additional files are detected, or when a closed plugin is found', 'vigilante' ); ?>
5976 </label>
5977 <p class="description"><?php esc_html_e( 'Fires even if the Email Notifications setting above is set to Disabled.', 'vigilante' ); ?></p>
5978 <p class="description">
5979 <?php
5980 printf(
5981 /* translators: %s: Link to notification settings */
5982 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
5983 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
5984 );
5985 ?>
5986 </p>
5987 </td>
5988 </tr>
5989 <tr>
5990 <th scope="row"><?php esc_html_e( 'Test email', 'vigilante' ); ?></th>
5991 <td>
5992 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
5993 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
5994 </button>
5995 <span class="vigilante-test-email-result" style="margin-left:8px;"></span>
5996 <p class="description"><?php esc_html_e( 'Sends a test message to the configured recipients to confirm email delivery works.', 'vigilante' ); ?></p>
5997 </td>
5998 </tr>
5999 <tr>
6000 <th scope="row"><?php esc_html_e( 'Scan Scope', 'vigilante' ); ?></th>
6001 <td>
6002 <fieldset>
6003 <label>
6004 <input type="checkbox" name="file_integrity[scan_core]" value="1" <?php checked( $options['scan_core'] ?? true ); ?>>
6005 <?php esc_html_e( 'Core files (compare against WordPress.org checksums)', 'vigilante' ); ?>
6006 </label>
6007 <br>
6008 <label>
6009 <input type="checkbox" name="file_integrity[scan_plugins]" value="1" <?php checked( $options['scan_plugins'] ?? true ); ?>>
6010 <?php esc_html_e( 'Plugins (WordPress.org repository plugins)', 'vigilante' ); ?>
6011 </label>
6012 <br>
6013 <label>
6014 <input type="checkbox" name="file_integrity[scan_themes]" value="1" <?php checked( $options['scan_themes'] ?? true ); ?>>
6015 <?php esc_html_e( 'Themes (WordPress.org repository themes)', 'vigilante' ); ?>
6016 </label>
6017 <br>
6018 <label>
6019 <input type="checkbox" name="file_integrity[scan_uploads]" value="1" <?php checked( $options['scan_uploads'] ?? true ); ?>>
6020 <?php esc_html_e( 'Uploads directory (detect PHP files, double extensions, .htaccess)', 'vigilante' ); ?>
6021 </label>
6022 <br>
6023 <label>
6024 <input type="checkbox" name="file_integrity[scan_critical_config]" value="1" <?php checked( $options['scan_critical_config'] ?? true ); ?>>
6025 <?php esc_html_e( 'Critical config files (wp-config.php, .htaccess baseline monitoring)', 'vigilante' ); ?>
6026 </label>
6027 <br>
6028 <label>
6029 <input type="checkbox" name="file_integrity[check_closed_plugins]" value="1" <?php checked( $options['check_closed_plugins'] ?? true ); ?>>
6030 <?php esc_html_e( 'Closed plugins (daily check against the WordPress.org repository)', 'vigilante' ); ?>
6031 </label>
6032 </fieldset>
6033 </td>
6034 </tr>
6035 <tr>
6036 <th scope="row"><label for="vigilante-f-file-integrity-excluded-paths"><?php esc_html_e( 'Excluded Paths', 'vigilante' ); ?></label></th>
6037 <td>
6038 <textarea id="vigilante-f-file-integrity-excluded-paths" 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>
6039 <p class="description"><?php esc_html_e( 'One path per line, relative to the WordPress root. A path such as wp-content/cache excludes exactly that folder and everything under it. A name on its own, such as cache, excludes any folder called exactly that, wherever it is.', 'vigilante' ); ?></p>
6040 </td>
6041 </tr>
6042 <tr>
6043 <th scope="row"><label for="vigilante-f-file-integrity-excluded-extensions"><?php esc_html_e( 'Excluded Extensions', 'vigilante' ); ?></label></th>
6044 <td>
6045 <textarea id="vigilante-f-file-integrity-excluded-extensions" 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>
6046 <p class="description">
6047 <?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' ); ?>
6048 <br>
6049 <?php
6050 printf(
6051 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the scoped-extension example. */
6052 esc_html__( 'An extension on its own applies to the whole site. To limit it to one folder, write it as %1$swp-content/languages/*.json%2$s, which leaves the same extension watched everywhere else.', 'vigilante' ),
6053 '<code>',
6054 '</code>'
6055 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
6056 ?>
6057 </p>
6058 </td>
6059 </tr>
6060 </table>
6061 </div>
6062
6063 <p class="submit vigilante-submit-buttons">
6064 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
6065 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
6066 </button>
6067 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
6068 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
6069 </button>
6070 <span class="vigilante-buttons-separator"></span>
6071 <button type="button" class="button button-primary vigilante-run-scan">
6072 <?php esc_html_e( 'Run Scan Now', 'vigilante' ); ?>
6073 </button>
6074 <button type="button" class="button vigilante-clear-scan-btn vigilante-clear-scan">
6075 <?php esc_html_e( 'Clear Previous Results', 'vigilante' ); ?>
6076 </button>
6077 </p>
6078 </form>
6079
6080 <div id="vigilante-scan-results" class="vigilante-settings-section" style="display:none;"></div>
6081
6082 <?php if ( $last_scan || $has_closed || $closed_last_check > 0 ) : ?>
6083 <div id="vigilante-section-fi-last-scan" class="vigilante-settings-section">
6084 <h2><?php esc_html_e( 'Last Scan Results', 'vigilante' ); ?></h2>
6085 <?php if ( $last_scan ) : ?>
6086 <p>
6087 <?php
6088 // Build the "X files scanned" hint inline with the date so it doesn't
6089 // need its own stat box (keeps the row compact when closed plugins are
6090 // present).
6091 $scanned_total = 0;
6092 if ( $last_results ) {
6093 $scanned_total = (int) ( $last_results['ok'] ?? 0 )
6094 + count( $last_results['modified'] ?? array() )
6095 + count( $last_results['suspicious'] ?? array() )
6096 + count( $last_results['extra'] ?? array() )
6097 + count( $ignored_files );
6098 }
6099 if ( $scanned_total > 0 ) {
6100 printf(
6101 /* translators: 1: date and time of last scan, 2: formatted file count */
6102 esc_html__( 'Last scan: %1$s (%2$s files scanned)', 'vigilante' ),
6103 esc_html( wp_date( $datetime_format, $last_scan ) ),
6104 esc_html( number_format_i18n( $scanned_total ) )
6105 );
6106 } else {
6107 printf(
6108 /* translators: %s: date and time of last scan */
6109 esc_html__( 'Last scan: %s', 'vigilante' ),
6110 esc_html( wp_date( $datetime_format, $last_scan ) )
6111 );
6112 }
6113 if ( $closed_last_check > 0 && $closed_last_check !== (int) $last_scan ) {
6114 echo ' &middot; ';
6115 printf(
6116 /* translators: %s: date and time of last closed plugins check */
6117 esc_html__( 'Closed plugins last checked: %s', 'vigilante' ),
6118 esc_html( wp_date( $datetime_format, $closed_last_check ) )
6119 );
6120 }
6121 ?>
6122 </p>
6123 <?php elseif ( $closed_last_check > 0 ) : ?>
6124 <p>
6125 <?php
6126 printf(
6127 /* translators: %s: date and time of last closed plugins check */
6128 esc_html__( 'Closed plugins last checked: %s &middot; the daily cron is running, no full integrity scan yet.', 'vigilante' ),
6129 esc_html( wp_date( $datetime_format, $closed_last_check ) )
6130 );
6131 ?>
6132 </p>
6133 <?php endif; ?>
6134 <div id="vigilante-last-scan-results">
6135 <?php if ( $last_results || $has_closed ) : ?>
6136 <div class="vigilante-scan-summary">
6137 <?php if ( $last_results ) : ?>
6138 <div class="vigilante-scan-stat vigilante-stat-ok">
6139 <span class="vigilante-stat-number"><?php echo esc_html( $last_results['ok'] ?? 0 ); ?></span>
6140 <span class="vigilante-stat-label"><?php esc_html_e( 'OK', 'vigilante' ); ?></span>
6141 </div>
6142 <div class="vigilante-scan-stat vigilante-stat-modified">
6143 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['modified'] ?? array() ) ); ?></span>
6144 <span class="vigilante-stat-label"><?php esc_html_e( 'Modified', 'vigilante' ); ?></span>
6145 </div>
6146 <div class="vigilante-scan-stat vigilante-stat-suspicious">
6147 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['suspicious'] ?? array() ) ); ?></span>
6148 <span class="vigilante-stat-label"><?php esc_html_e( 'Suspicious', 'vigilante' ); ?></span>
6149 </div>
6150 <div class="vigilante-scan-stat vigilante-stat-extra">
6151 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['extra'] ?? array() ) ); ?></span>
6152 <span class="vigilante-stat-label"><?php esc_html_e( 'Extra', 'vigilante' ); ?></span>
6153 </div>
6154 <?php endif; ?>
6155 <?php if ( $has_closed ) : ?>
6156 <div class="vigilante-scan-stat vigilante-stat-suspicious">
6157 <span class="vigilante-stat-number" style="color: #d63638;"><?php echo (int) count( $closed_plugins ); ?></span>
6158 <span class="vigilante-stat-label"><?php esc_html_e( 'Closed/Removed', 'vigilante' ); ?></span>
6159 </div>
6160 <?php endif; ?>
6161 <?php if ( ! empty( $ignored_files ) ) : ?>
6162 <div class="vigilante-scan-stat vigilante-stat-ignored">
6163 <span class="vigilante-stat-number"><?php echo esc_html( count( $ignored_files ) ); ?></span>
6164 <span class="vigilante-stat-label"><?php esc_html_e( 'Ignored', 'vigilante' ); ?></span>
6165 </div>
6166 <?php endif; ?>
6167 </div>
6168
6169 <?php if ( ! empty( $last_results['suspicious'] ) ) : ?>
6170 <div class="vigilante-file-list vigilante-suspicious-files vigilante-paginated-section" data-bulk-mode="ignore">
6171 <h3 style="color: #d63638;"><?php esc_html_e( 'Suspicious Files', 'vigilante' ); ?></h3>
6172 <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>
6173 <div class="vigilante-fi-bulk-bar">
6174 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
6175 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
6176 </div>
6177 <div class="vigilante-fi-pagination-wrap"></div>
6178 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
6179 <thead>
6180 <tr>
6181 <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>
6182 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6183 <th style="width: 250px;"><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
6184 <th style="width: 120px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
6185 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6186 </tr>
6187 </thead>
6188 <tbody>
6189 <?php
6190 foreach ( $last_results['suspicious'] as $item ) {
6191 $file_path = '';
6192 $file_reason = __( 'Unknown', 'vigilante' );
6193 $file_type = 'unknown';
6194
6195 if ( is_array( $item ) ) {
6196 if ( isset( $item['file'] ) ) {
6197 $file_path = $item['file'];
6198 }
6199 if ( isset( $item['reason'] ) ) {
6200 $file_reason = $item['reason'];
6201 }
6202 if ( isset( $item['type'] ) ) {
6203 $file_type = $item['type'];
6204 }
6205 } else {
6206 $file_path = (string) $item;
6207 }
6208 ?>
6209 <tr>
6210 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
6211 <td><code style="color: #d63638;"><?php echo esc_html( $file_path ); ?></code></td>
6212 <td><?php echo esc_html( $file_reason ); ?></td>
6213 <td><?php echo esc_html( $file_type ); ?></td>
6214 <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>
6215 </tr>
6216 <?php
6217 }
6218 ?>
6219 </tbody>
6220 </table>
6221 </div>
6222 <?php endif; ?>
6223
6224 <?php if ( ! empty( $last_results['extra'] ) ) : ?>
6225 <div class="vigilante-file-list vigilante-extra-files vigilante-paginated-section" data-bulk-mode="ignore">
6226 <h3 style="color: #b32d2e;"><?php esc_html_e( 'Extra Files', 'vigilante' ); ?></h3>
6227 <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>
6228 <div class="vigilante-fi-bulk-bar">
6229 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
6230 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
6231 </div>
6232 <div class="vigilante-fi-pagination-wrap"></div>
6233 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
6234 <thead>
6235 <tr>
6236 <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>
6237 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6238 <th style="width: 250px;"><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
6239 <th style="width: 120px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
6240 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6241 </tr>
6242 </thead>
6243 <tbody>
6244 <?php
6245 foreach ( $last_results['extra'] as $item ) {
6246 $file_path = is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item;
6247 $file_reason = is_array( $item ) ? ( $item['reason'] ?? __( 'Unknown', 'vigilante' ) ) : __( 'Unknown', 'vigilante' );
6248 $file_type = is_array( $item ) ? ( $item['type'] ?? 'unknown' ) : 'unknown';
6249 ?>
6250 <tr>
6251 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
6252 <td><code style="color: #b32d2e;"><?php echo esc_html( $file_path ); ?></code></td>
6253 <td><?php echo esc_html( $file_reason ); ?></td>
6254 <td><?php echo esc_html( $file_type ); ?></td>
6255 <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>
6256 </tr>
6257 <?php
6258 }
6259 ?>
6260 </tbody>
6261 </table>
6262 </div>
6263 <?php endif; ?>
6264
6265 <?php
6266 // Split critical config files from regular modified files.
6267 // Computed unconditionally so the three sub-sections that consume
6268 // these arrays (Critical Config, Closed + Removed, Modified Files)
6269 // can render independently and in the order the team picked.
6270 $critical_modified = array();
6271 $regular_modified = array();
6272 if ( $last_results && ! empty( $last_results['modified'] ) ) {
6273 foreach ( $last_results['modified'] as $item ) {
6274 if ( is_array( $item ) && isset( $item['type'] ) && 'critical_config' === $item['type'] ) {
6275 $critical_modified[] = $item;
6276 } else {
6277 $regular_modified[] = $item;
6278 }
6279 }
6280 }
6281 ?>
6282
6283 <?php if ( ! empty( $critical_modified ) ) : ?>
6284 <div class="vigilante-file-list vigilante-critical-config-files">
6285 <h3 style="color: #e36210;"><?php esc_html_e( 'Critical config files modified', 'vigilante' ); ?></h3>
6286 <p class="description">
6287 <?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' ); ?>
6288 </p>
6289 <table class="wp-list-table widefat fixed striped">
6290 <thead>
6291 <tr>
6292 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6293 <th style="width: 200px;"><?php esc_html_e( 'Changes', 'vigilante' ); ?></th>
6294 <th style="width: 220px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6295 </tr>
6296 </thead>
6297 <tbody>
6298 <?php foreach ( $critical_modified as $crit_item ) :
6299 $crit_file = $crit_item['file'] ?? '';
6300 $crit_baseline_size = $crit_item['baseline_size'] ?? 0;
6301 $crit_current_size = $crit_item['current_size'] ?? 0;
6302 $crit_diff = $crit_item['diff'] ?? array();
6303 $crit_id = sanitize_html_class( $crit_file );
6304 $added_count = is_array( $crit_diff ) ? count( $crit_diff['added'] ?? array() ) : 0;
6305 $removed_count = is_array( $crit_diff ) ? count( $crit_diff['removed'] ?? array() ) : 0;
6306 $diff_unavailable = is_array( $crit_diff ) && ! empty( $crit_diff['unavailable'] );
6307 ?>
6308 <tr>
6309 <td><code style="color: #e36210;"><?php echo esc_html( $crit_file ); ?></code></td>
6310 <td>
6311 <?php if ( ! $diff_unavailable ) : ?>
6312 <span style="color: #007017;">+<?php echo (int) $added_count; ?></span>
6313 <span style="color: #b32d2e;">-<?php echo (int) $removed_count; ?></span>
6314 <?php esc_html_e( 'lines', 'vigilante' ); ?><br>
6315 <?php endif; ?>
6316 <small style="color: #50575e;">
6317 <?php
6318 printf(
6319 /* translators: 1: baseline size, 2: current size */
6320 esc_html__( '%1$s &rarr; %2$s bytes', 'vigilante' ),
6321 esc_html( number_format_i18n( $crit_baseline_size ) ),
6322 esc_html( number_format_i18n( $crit_current_size ) )
6323 );
6324 ?>
6325 </small>
6326 </td>
6327 <td>
6328 <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' ); ?>">
6329 <?php esc_html_e( 'Review changes', 'vigilante' ); ?>
6330 </button>
6331 <button type="button" class="button button-small button-primary vigilante-approve-critical-file" data-file="<?php echo esc_attr( $crit_file ); ?>">
6332 <?php esc_html_e( 'Approve', 'vigilante' ); ?>
6333 </button>
6334 </td>
6335 </tr>
6336 <tr id="vigilante-critical-content-<?php echo esc_attr( $crit_id ); ?>" class="vigilante-critical-content-row" style="display:none;">
6337 <td colspan="3" style="padding: 0;">
6338 <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;">
6339 <?php if ( $diff_unavailable ) : ?>
6340 <p style="color: #50575e; font-style: italic; margin: 0;">
6341 <?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' ); ?>
6342 </p>
6343 <?php elseif ( empty( $crit_diff['added'] ) && empty( $crit_diff['removed'] ) ) : ?>
6344 <p style="color: #50575e; font-style: italic; margin: 0;">
6345 <?php esc_html_e( 'No line-level changes detected (may be whitespace or reordering).', 'vigilante' ); ?>
6346 </p>
6347 <?php else : ?>
6348 <?php if ( ! empty( $crit_diff['removed'] ) ) : ?>
6349 <?php foreach ( $crit_diff['removed'] as $rline ) : ?>
6350 <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>
6351 <?php endforeach; ?>
6352 <?php endif; ?>
6353 <?php if ( ! empty( $crit_diff['added'] ) ) : ?>
6354 <?php foreach ( $crit_diff['added'] as $aline ) : ?>
6355 <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>
6356 <?php endforeach; ?>
6357 <?php endif; ?>
6358 <?php endif; ?>
6359 </div>
6360 </td>
6361 </tr>
6362 <?php endforeach; ?>
6363 </tbody>
6364 </table>
6365 </div>
6366 <?php endif; ?>
6367
6368 <?php if ( $has_closed ) : ?>
6369 <div class="vigilante-file-list vigilante-closed-plugins">
6370 <h3 id="vigilante-section-fi-closed-plugins" style="color: #d63638;"><?php esc_html_e( 'Closed + Removed Plugins', 'vigilante' ); ?></h3>
6371 <p class="description" style="color: #d63638;">
6372 <?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' ); ?>
6373 </p>
6374 <table class="wp-list-table widefat striped">
6375 <thead>
6376 <tr>
6377 <th><?php esc_html_e( 'Plugin', 'vigilante' ); ?></th>
6378 <th style="width: 70px;"><?php esc_html_e( 'Version', 'vigilante' ); ?></th>
6379 <th style="width: 90px;"><?php esc_html_e( 'State', 'vigilante' ); ?></th>
6380 <th style="width: 110px;"><?php esc_html_e( 'Closed date', 'vigilante' ); ?></th>
6381 <th><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
6382 <th style="width: 130px;"><?php esc_html_e( 'Detected', 'vigilante' ); ?></th>
6383 <th style="width: 90px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6384 </tr>
6385 </thead>
6386 <tbody>
6387 <?php foreach ( $closed_plugins as $cp_slug => $cp_entry ) :
6388 $cp_state = $cp_entry['state'] ?? '';
6389 $cp_state_label = 'closed' === $cp_state ? __( 'Closed', 'vigilante' ) : __( 'Removed', 'vigilante' );
6390 $cp_state_color = 'closed' === $cp_state ? '#d63638' : '#b32d2e';
6391 $cp_reason = '';
6392 if ( ! empty( $cp_entry['closed_reason_text'] ) ) {
6393 $cp_reason = $cp_entry['closed_reason_text'];
6394 } elseif ( 'removed' === $cp_state ) {
6395 $cp_reason = __( 'Removed from repository (metadata hidden, typical of Security Issue closures)', 'vigilante' );
6396 }
6397 $cp_detected = isset( $cp_entry['first_detected'] ) ? (int) $cp_entry['first_detected'] : 0;
6398 ?>
6399 <tr>
6400 <td>
6401 <strong><?php echo esc_html( $cp_entry['name'] ?? $cp_slug ); ?></strong><br>
6402 <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>
6403 </td>
6404 <td><?php echo esc_html( $cp_entry['version'] ?? '' ); ?></td>
6405 <td><span style="color: <?php echo esc_attr( $cp_state_color ); ?>; font-weight: 600;"><?php echo esc_html( $cp_state_label ); ?></span></td>
6406 <td><?php echo esc_html( $cp_entry['closed_date'] ?? '' ); ?></td>
6407 <td><?php echo esc_html( $cp_reason ); ?></td>
6408 <td>
6409 <?php echo $cp_detected > 0 ? esc_html( wp_date( $datetime_format, $cp_detected ) ) : '&mdash;'; ?>
6410 </td>
6411 <td>
6412 <button type="button" class="button button-small vigilante-ignore-closed-plugin" data-slug="<?php echo esc_attr( $cp_slug ); ?>">
6413 <?php esc_html_e( 'Ignore', 'vigilante' ); ?>
6414 </button>
6415 </td>
6416 </tr>
6417 <?php endforeach; ?>
6418 </tbody>
6419 </table>
6420 </div>
6421 <?php endif; ?>
6422
6423 <?php if ( ! empty( $regular_modified ) ) : ?>
6424 <div class="vigilante-file-list vigilante-paginated-section" data-bulk-mode="ignore">
6425 <h3><?php esc_html_e( 'Modified Files', 'vigilante' ); ?></h3>
6426 <p class="description"><?php esc_html_e( 'These files (apparently) differ from the original WordPress or plugin versions.', 'vigilante' ); ?></p>
6427 <div class="vigilante-fi-bulk-bar">
6428 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
6429 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
6430 </div>
6431 <div class="vigilante-fi-pagination-wrap"></div>
6432 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
6433 <thead>
6434 <tr>
6435 <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>
6436 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6437 <th style="width: 100px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
6438 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6439 </tr>
6440 </thead>
6441 <tbody>
6442 <?php
6443 foreach ( $regular_modified as $item ) {
6444 $file_path = '';
6445 $file_type = 'unknown';
6446
6447 if ( is_array( $item ) ) {
6448 if ( isset( $item['file'] ) ) {
6449 $file_path = $item['file'];
6450 }
6451 if ( isset( $item['type'] ) ) {
6452 $file_type = $item['type'];
6453 }
6454 } else {
6455 $file_path = (string) $item;
6456 }
6457 ?>
6458 <tr>
6459 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
6460 <td><code><?php echo esc_html( $file_path ); ?></code></td>
6461 <td><?php echo esc_html( $file_type ); ?></td>
6462 <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>
6463 </tr>
6464 <?php
6465 }
6466 ?>
6467 </tbody>
6468 </table>
6469 </div>
6470 <?php endif; ?>
6471
6472 <?php if ( $last_results && empty( $last_results['modified'] ) && empty( $last_results['suspicious'] ) && empty( $last_results['extra'] ) && ! $has_closed ) : ?>
6473 <p class="vigilante-all-clear" style="color: #00a32a; font-weight: bold;">
6474 <?php esc_html_e( 'Good Job! All files passed integrity check. No issues found.', 'vigilante' ); ?>
6475 </p>
6476 <?php endif; ?>
6477 <?php endif; ?>
6478 </div>
6479 </div>
6480 <?php endif; ?>
6481
6482 <?php if ( ! empty( $ignored_closed_plugins ) ) : ?>
6483 <div id="vigilante-section-fi-ignored-closed" class="vigilante-settings-section">
6484 <h2><?php esc_html_e( 'Ignored Closed + Removed Plugins', 'vigilante' ); ?></h2>
6485 <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>
6486 <table class="wp-list-table widefat fixed striped">
6487 <thead>
6488 <tr>
6489 <th><?php esc_html_e( 'Plugin', 'vigilante' ); ?></th>
6490 <th style="width: 110px;"><?php esc_html_e( 'State', 'vigilante' ); ?></th>
6491 <th style="width: 120px;"><?php esc_html_e( 'Closed date', 'vigilante' ); ?></th>
6492 <th style="width: 130px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6493 </tr>
6494 </thead>
6495 <tbody>
6496 <?php foreach ( $ignored_closed_plugins as $icp_slug => $icp_entry ) :
6497 $icp_state = $icp_entry['state'] ?? '';
6498 $icp_state_label = 'closed' === $icp_state ? __( 'Closed', 'vigilante' ) : __( 'Removed', 'vigilante' );
6499 ?>
6500 <tr>
6501 <td>
6502 <strong><?php echo esc_html( $icp_entry['name'] ?? $icp_slug ); ?></strong><br>
6503 <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>
6504 </td>
6505 <td><?php echo esc_html( $icp_state_label ); ?></td>
6506 <td><?php echo esc_html( $icp_entry['closed_date'] ?? '' ); ?></td>
6507 <td>
6508 <button type="button" class="button button-small vigilante-unignore-closed-plugin" data-slug="<?php echo esc_attr( $icp_slug ); ?>">
6509 <?php esc_html_e( 'Stop ignoring', 'vigilante' ); ?>
6510 </button>
6511 </td>
6512 </tr>
6513 <?php endforeach; ?>
6514 </tbody>
6515 </table>
6516 <p style="margin-top: 10px;">
6517 <button type="button" class="button vigilante-clear-ignored-closed-plugins"><?php esc_html_e( 'Clear All Ignored Closed + Removed Plugins', 'vigilante' ); ?></button>
6518 </p>
6519 </div>
6520 <?php endif; ?>
6521
6522 <?php if ( ! empty( $ignored_files ) ) : ?>
6523 <div id="vigilante-section-fi-ignored" class="vigilante-settings-section">
6524 <h2><?php esc_html_e( 'Ignored Files', 'vigilante' ); ?></h2>
6525 <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>
6526 <div class="vigilante-paginated-section" data-bulk-mode="unignore">
6527 <div class="vigilante-fi-bulk-bar">
6528 <button type="button" class="button vigilante-bulk-unignore" disabled><?php esc_html_e( 'Stop ignoring selected', 'vigilante' ); ?></button>
6529 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
6530 </div>
6531 <div class="vigilante-fi-pagination-wrap"></div>
6532 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
6533 <thead>
6534 <tr>
6535 <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>
6536 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6537 <th style="width: 120px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6538 </tr>
6539 </thead>
6540 <tbody>
6541 <?php foreach ( $ignored_files as $file ) : ?>
6542 <tr>
6543 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file ); ?>"></th>
6544 <td><code><?php echo esc_html( $file ); ?></code></td>
6545 <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>
6546 </tr>
6547 <?php endforeach; ?>
6548 </tbody>
6549 </table>
6550 </div>
6551 <p style="margin-top: 10px;">
6552 <button type="button" class="button vigilante-clear-ignored"><?php esc_html_e( 'Clear All Ignored Files', 'vigilante' ); ?></button>
6553 </p>
6554 </div>
6555 <?php endif; ?>
6556 <?php
6557 }
6558
6559 /**
6560 * Render sidebar with promotional widgets
6561 */
6562 private function render_sidebar() {
6563 $promo_banner = new Vigilante_Promo_Banner( 'vigilante' );
6564 $promo_banner->render();
6565 }
6566
6567 /**
6568 * AJAX: Download a ZIP backup of the critical config files.
6569 *
6570 * Streams wp-config.php and .htaccess (and robots.txt if present) as a
6571 * downloadable archive. Config backups are no longer left as files under the
6572 * web root, so this hands the admin the archive directly.
6573 */
6574 public function ajax_download_files_backup() {
6575 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
6576
6577 if ( ! current_user_can( 'manage_options' ) ) {
6578 wp_die( esc_html__( 'Permission denied.', 'vigilante' ), 403 );
6579 }
6580
6581 // The archive carries wp-config.php, which a whole network shares. On a
6582 // network manage_options is held by every subsite administrator, so the
6583 // same gate the writers use applies here.
6584 if ( ! Vigilante_Settings::can_write_shared_files() ) {
6585 wp_die( esc_html( Vigilante_Settings::get_shared_files_notice() ), 403 );
6586 }
6587
6588 $backup_manager = new Vigilante_Backup_Manager();
6589 $result = $backup_manager->stream_files_zip();
6590
6591 // stream_files_zip() exits on success; only a WP_Error returns here.
6592 if ( is_wp_error( $result ) ) {
6593 wp_die( esc_html( $result->get_error_message() ), 500 );
6594 }
6595 }
6596
6597 /**
6598 * AJAX: Save settings
6599 */
6600 public function ajax_save_settings() {
6601 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
6602
6603 if ( ! current_user_can( 'manage_options' ) ) {
6604 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
6605 }
6606
6607 $section = isset( $_POST['section'] ) ? sanitize_key( $_POST['section'] ) : '';
6608
6609 // Handle $_POST['data'] based on type
6610 if ( isset( $_POST['data'] ) && is_array( $_POST['data'] ) ) {
6611 $data = map_deep( wp_unslash( $_POST['data'] ), 'sanitize_text_field' );
6612 } elseif ( isset( $_POST['data'] ) ) {
6613 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
6614 $raw_data = wp_unslash( $_POST['data'] );
6615 parse_str( $raw_data, $data );
6616 $data = map_deep( $data, 'sanitize_textarea_field' );
6617 } else {
6618 $data = array();
6619 }
6620
6621 if ( empty( $section ) ) {
6622 wp_send_json_error( __( 'Invalid section.', 'vigilante' ) );
6623 }
6624
6625 // Check if 2FA is being enabled or method changed (for notification sending)
6626 $send_2fa_notification = false;
6627 $send_login_url_notification = false;
6628
6629 if ( 'login_security' === $section ) {
6630 // Read old state from DB
6631 $db_options = get_option( Vigilante_Settings::OPTION_NAME, array() );
6632 $old_2fa_enabled = ! empty( $db_options['login_security']['two_factor']['enabled'] );
6633 $old_method = $db_options['login_security']['two_factor']['method'] ?? 'email';
6634
6635 // Check new state from submitted data
6636 $new_2fa_enabled = false;
6637 $notify_on_enable = false;
6638 $new_method = isset( $data['login_security']['two_factor']['method'] )
6639 ? sanitize_key( $data['login_security']['two_factor']['method'] )
6640 : 'email';
6641
6642 if ( isset( $data['login_security']['two_factor']['enabled'] ) ) {
6643 $new_2fa_enabled = filter_var( $data['login_security']['two_factor']['enabled'], FILTER_VALIDATE_BOOLEAN );
6644 }
6645 if ( isset( $data['login_security']['two_factor']['notify_on_enable'] ) ) {
6646 $notify_on_enable = filter_var( $data['login_security']['two_factor']['notify_on_enable'], FILTER_VALIDATE_BOOLEAN );
6647 }
6648
6649 // Send notification if:
6650 // 1. 2FA is being enabled (was off, now on) OR
6651 // 2. Method changed while 2FA is enabled
6652 if ( $notify_on_enable && $new_2fa_enabled ) {
6653 if ( ! $old_2fa_enabled || ( $old_2fa_enabled && $old_method !== $new_method ) ) {
6654 $send_2fa_notification = true;
6655 }
6656 }
6657
6658 // Check if login URL changed and notification is enabled
6659 $old_login_url = $db_options['login_security']['custom_login_url'] ?? '';
6660 $new_login_url = isset( $data['login_security']['custom_login_url'] )
6661 ? sanitize_title( $data['login_security']['custom_login_url'] )
6662 : '';
6663 $notify_on_url_change = isset( $data['login_security']['notify_on_login_url_change'] )
6664 ? filter_var( $data['login_security']['notify_on_login_url_change'], FILTER_VALIDATE_BOOLEAN )
6665 : false;
6666
6667 if ( $notify_on_url_change && ! empty( $new_login_url ) && $new_login_url !== $old_login_url ) {
6668 $send_login_url_notification = true;
6669 }
6670 }
6671
6672 // Get defaults
6673 $defaults = $this->settings->get_default_options();
6674
6675 // Read ONLY saved options from database (not merged with defaults)
6676 $saved_options = get_option( Vigilante_Settings::OPTION_NAME, array() );
6677
6678 $rejected_ips = array();
6679
6680 // Handle modules
6681 if ( 'modules' === $section && isset( $data['modules'] ) ) {
6682 if ( ! isset( $saved_options['modules'] ) ) {
6683 $saved_options['modules'] = array();
6684 }
6685 foreach ( $data['modules'] as $module => $enabled ) {
6686 $module = sanitize_key( $module );
6687 $saved_options['modules'][ $module ] = in_array( $enabled, array( '1', 1, 'true', true ), true );
6688 }
6689 // Clear active preset when modules change
6690 update_option( 'vigilante_active_preset', '' );
6691 } else {
6692 // Process primary section
6693 if ( isset( $data[ $section ] ) && is_array( $data[ $section ] ) ) {
6694 $section_defaults = isset( $defaults[ $section ] ) ? $defaults[ $section ] : array();
6695 $current_section = isset( $saved_options[ $section ] ) ? $saved_options[ $section ] : array();
6696
6697 // Process the submitted data
6698 $processed = $this->process_section_data( $data[ $section ], $section_defaults, $current_section );
6699
6700 // The IP boxes are free text and, until 2.9.9, whatever was typed
6701 // went straight into the option. An entry the matcher can never
6702 // match still sits in a security list looking like protection,
6703 // so the ones that cannot match are dropped and reported back
6704 // instead of being stored in silence.
6705 $rejected_ips = $this->filter_ip_lists( $section, $processed );
6706
6707 // Save the processed section
6708 $saved_options[ $section ] = $processed;
6709
6710 // Clear active preset when any section settings change
6711 update_option( 'vigilante_active_preset', '' );
6712 }
6713 }
6714
6715 // Clear cache before saving
6716 wp_cache_delete( Vigilante_Settings::OPTION_NAME, 'options' );
6717
6718 // Save to database
6719 update_option( Vigilante_Settings::OPTION_NAME, $saved_options );
6720
6721 // Clear the settings cache
6722 $this->settings->clear_cache();
6723
6724 // Apply changes based on section
6725 $this->apply_section_changes( $section, $saved_options );
6726
6727 // Send 2FA notifications after settings are saved
6728 $notification_result = null;
6729 if ( $send_2fa_notification ) {
6730 $notification_result = $this->send_2fa_enable_notifications();
6731 }
6732
6733 // Send login URL notifications after settings are saved
6734 $login_url_result = null;
6735 if ( $send_login_url_notification ) {
6736 $login_url_result = $this->send_login_url_notifications();
6737 }
6738
6739 // Build success message
6740 $message = __( 'Settings saved successfully.', 'vigilante' );
6741
6742 if ( $notification_result && $notification_result['sent'] > 0 ) {
6743 $message .= ' ' . sprintf(
6744 /* translators: %d: Number of emails sent */
6745 _n(
6746 '2FA notification sent to %d user.',
6747 '2FA notifications sent to %d users.',
6748 $notification_result['sent'],
6749 'vigilante'
6750 ),
6751 $notification_result['sent']
6752 );
6753 }
6754
6755 if ( $login_url_result && $login_url_result['sent'] > 0 ) {
6756 $message .= ' ' . sprintf(
6757 /* translators: %d: Number of emails sent */
6758 _n(
6759 'Login URL notification sent to %d user.',
6760 'Login URL notifications sent to %d users.',
6761 $login_url_result['sent'],
6762 'vigilante'
6763 ),
6764 $login_url_result['sent']
6765 );
6766 }
6767
6768 if ( ! empty( $rejected_ips ) ) {
6769 $message .= ' ' . sprintf(
6770 /* translators: %s: comma separated list of the entries that were not saved. */
6771 _n(
6772 'This entry is not a valid IP, CIDR range or wildcard, so it was not saved: %s',
6773 'These entries are not valid IPs, CIDR ranges or wildcards, so they were not saved: %s',
6774 count( $rejected_ips ),
6775 'vigilante'
6776 ),
6777 implode( ', ', array_map( 'esc_html', $rejected_ips ) )
6778 );
6779 }
6780
6781 wp_send_json_success( $message );
6782 }
6783
6784 /**
6785 * Keep only the IP patterns the matcher can actually match
6786 *
6787 * @since 2.9.9
6788 *
6789 * @param string $section Section being saved.
6790 * @param array $processed Section data, edited in place.
6791 * @return array Entries that were dropped, for the message back to the user.
6792 */
6793 private function filter_ip_lists( $section, &$processed ) {
6794 $lists = array(
6795 'firewall' => array( 'ip_whitelist', 'ip_blacklist' ),
6796 'login_security' => array( 'ip_whitelist' ),
6797 );
6798
6799 if ( ! isset( $lists[ $section ] ) ) {
6800 return array();
6801 }
6802
6803 $rejected = array();
6804
6805 foreach ( $lists[ $section ] as $key ) {
6806 if ( ! isset( $processed[ $key ] ) || ! is_array( $processed[ $key ] ) ) {
6807 continue;
6808 }
6809
6810 $split = Vigilante_IP_Utils::split_list( $processed[ $key ] );
6811 $processed[ $key ] = $split['valid'];
6812 $rejected = array_merge( $rejected, $split['rejected'] );
6813 }
6814
6815 return array_values( array_unique( $rejected ) );
6816 }
6817
6818 /**
6819 * Send 2FA enable notifications to users
6820 *
6821 * @return array Result with 'sent' and 'failed' counts.
6822 */
6823 private function send_2fa_enable_notifications() {
6824 $result = array(
6825 'sent' => 0,
6826 'failed' => 0,
6827 );
6828
6829 // Get settings for roles and method
6830 $login_security = $this->settings->get_section( 'login_security' );
6831 $two_factor = isset( $login_security['two_factor'] ) ? $login_security['two_factor'] : array();
6832 $roles = isset( $two_factor['enforced_roles'] ) ? $two_factor['enforced_roles'] : array( 'administrator' );
6833 $method = isset( $two_factor['method'] ) ? $two_factor['method'] : 'email';
6834
6835 if ( empty( $roles ) ) {
6836 $roles = array( 'administrator' );
6837 }
6838
6839 $excluded = isset( $two_factor['excluded_users'] ) ? array_map( 'absint', $two_factor['excluded_users'] ) : array();
6840
6841 // Get users with these roles
6842 $args = array(
6843 'role__in' => $roles,
6844 );
6845 if ( ! empty( $excluded ) ) {
6846 // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- Small excluded users list from settings.
6847 $args['exclude'] = $excluded;
6848 }
6849 $users = get_users( $args );
6850
6851 if ( empty( $users ) ) {
6852 return $result;
6853 }
6854
6855 $site_name = get_bloginfo( 'name' );
6856 $from_name = ! empty( $two_factor['email_from_name'] ) ? $two_factor['email_from_name'] : $site_name;
6857
6858 if ( 'totp' === $method ) {
6859 // Use TOTP class for styled HTML emails
6860 if ( ! class_exists( 'Vigilante_Two_Factor_TOTP' ) ) {
6861 require_once VIGILANTE_INCLUDES_DIR . 'class-two-factor-totp.php';
6862 }
6863 $totp = new Vigilante_Two_Factor_TOTP( $this->settings, $this->database, $this->activity_log );
6864
6865 foreach ( $users as $user ) {
6866 // Skip users who already have TOTP configured
6867 $totp_data = $this->database->get_totp_data( $user->ID );
6868 if ( $totp_data && ! empty( $totp_data['is_configured'] ) ) {
6869 continue;
6870 }
6871
6872 $sent = $totp->send_activation_email( $user, $site_name, $from_name );
6873
6874 if ( $sent ) {
6875 $this->database->mark_2fa_notified( $user->ID );
6876 $result['sent']++;
6877 } else {
6878 $result['failed']++;
6879 }
6880 }
6881 } else {
6882 // Email method - use existing email 2FA class
6883 if ( ! class_exists( 'Vigilante_Two_Factor_Email' ) ) {
6884 require_once VIGILANTE_INCLUDES_DIR . 'class-two-factor-email.php';
6885 }
6886 $email_2fa = new Vigilante_Two_Factor_Email( $this->settings, $this->database, $this->activity_log );
6887 return $email_2fa->send_activation_notifications( false );
6888 }
6889
6890 return $result;
6891 }
6892
6893 /**
6894 * Send login URL change notifications to users with admin access
6895 *
6896 * @return array Result with 'sent' and 'failed' counts.
6897 */
6898 private function send_login_url_notifications() {
6899 $login_options = $this->settings->get_section( 'login_security' );
6900 $custom_url = ! empty( $login_options['custom_login_url'] ) ? sanitize_title( $login_options['custom_login_url'] ) : '';
6901
6902 if ( empty( $custom_url ) ) {
6903 return array( 'sent' => 0, 'failed' => 0 );
6904 }
6905
6906 $login_url = home_url( $custom_url . '/' );
6907 $site_name = get_bloginfo( 'name' );
6908
6909 $admin_roles = array( 'administrator', 'editor', 'author', 'contributor' );
6910 $users = get_users( array( 'role__in' => $admin_roles ) );
6911
6912 if ( empty( $users ) ) {
6913 return array( 'sent' => 0, 'failed' => 0 );
6914 }
6915
6916 $subject = sprintf(
6917 /* translators: %s: Site name */
6918 __( '[%s] Your login URL has changed', 'vigilante' ),
6919 $site_name
6920 );
6921
6922 $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' ) );
6923 $body .= Vigilante_Email_Template::url_box( $login_url, __( 'Your new login URL:', 'vigilante' ) );
6924 $body .= Vigilante_Email_Template::alert_box( __( 'The old login address (wp-login.php) will no longer work.', 'vigilante' ) );
6925 $body .= Vigilante_Email_Template::button( $login_url, __( 'Go to login', 'vigilante' ) );
6926
6927 $sent = 0;
6928 $failed = 0;
6929
6930 foreach ( $users as $user ) {
6931 $result = Vigilante_Email_Template::send(
6932 $user->user_email,
6933 $subject,
6934 __( 'Login URL changed', 'vigilante' ),
6935 $body
6936 );
6937 if ( $result ) {
6938 $sent++;
6939 } else {
6940 $failed++;
6941 }
6942 }
6943
6944 if ( $this->activity_log ) {
6945 $this->activity_log->log(
6946 'login',
6947 'login_url_notified',
6948 sprintf(
6949 /* translators: 1: Sent count, 2: Failed count */
6950 __( 'Login URL notification sent on save: %1$d sent, %2$d failed', 'vigilante' ),
6951 $sent,
6952 $failed
6953 )
6954 );
6955 }
6956
6957 return array( 'sent' => $sent, 'failed' => $failed );
6958 }
6959
6960 /**
6961 * Process section data maintaining proper types from defaults
6962 *
6963 * @param array $submitted_data Data submitted from form.
6964 * @param array $defaults Default values for this section.
6965 * @param array $current Current saved values.
6966 * @param string $section_name Section name for special handling.
6967 * @return array Processed data.
6968 */
6969 private function process_section_data( $submitted_data, $defaults, $current, $section_name = '' ) {
6970 // Start with defaults, then merge current saved values
6971 $result = array_replace_recursive( $defaults, $current );
6972
6973 // Process each submitted value
6974 foreach ( $submitted_data as $key => $value ) {
6975 $key = sanitize_key( $key );
6976
6977 if ( is_array( $value ) ) {
6978 // Nested array (like rate_limiting)
6979 $nested_defaults = isset( $defaults[ $key ] ) && is_array( $defaults[ $key ] ) ? $defaults[ $key ] : array();
6980 $nested_current = isset( $result[ $key ] ) && is_array( $result[ $key ] ) ? $result[ $key ] : array();
6981 $result[ $key ] = $this->process_section_data( $value, $nested_defaults, $nested_current, $key );
6982 } else {
6983 // Determine type from default value
6984 $default_value = isset( $defaults[ $key ] ) ? $defaults[ $key ] : null;
6985
6986 if ( null === $default_value ) {
6987 // No default, check current value type or use as string
6988 $current_value = isset( $current[ $key ] ) ? $current[ $key ] : null;
6989 if ( is_bool( $current_value ) ) {
6990 $result[ $key ] = in_array( $value, array( '1', 1, 'true', true ), true );
6991 } elseif ( is_int( $current_value ) ) {
6992 $result[ $key ] = intval( $value );
6993 } elseif ( is_array( $current_value ) ) {
6994 $result[ $key ] = is_string( $value ) ? array_filter( array_map( 'trim', explode( "\n", $value ) ) ) : (array) $value;
6995 } else {
6996 $result[ $key ] = sanitize_text_field( $value );
6997 }
6998 } elseif ( is_bool( $default_value ) ) {
6999 // Boolean: '1', 1, 'true' become true; '0', 0, '', 'false' become false
7000 $result[ $key ] = in_array( $value, array( '1', 1, 'true', true ), true );
7001 } elseif ( is_int( $default_value ) ) {
7002 // Integer - with special handling for time fields shown in minutes
7003 $int_value = intval( $value );
7004
7005 // Convert minutes to seconds for login_security duration fields
7006 // These are displayed as minutes in the form but stored as seconds
7007 if ( in_array( $key, array( 'lockout_duration', 'max_lockout_duration' ), true ) ) {
7008 $int_value = $int_value * 60;
7009 }
7010
7011 $result[ $key ] = $int_value;
7012 } elseif ( is_array( $default_value ) ) {
7013 // Array from textarea (e.g., IP lists)
7014 if ( is_string( $value ) ) {
7015 $result[ $key ] = array_filter( array_map( 'trim', explode( "\n", $value ) ) );
7016 } else {
7017 $result[ $key ] = (array) $value;
7018 }
7019 } else {
7020 // String - preserve newlines for textarea fields
7021 if ( is_string( $value ) && ( strpos( $value, "\n" ) !== false || strpos( $value, "\r" ) !== false ) ) {
7022 $result[ $key ] = sanitize_textarea_field( $value );
7023 } else {
7024 $result[ $key ] = sanitize_text_field( $value );
7025 }
7026 }
7027 }
7028 }
7029
7030 // Handle unchecked checkboxes: HTML forms don't submit unchecked boxes
7031 // If a boolean field exists in defaults but NOT in submitted_data, set it to false
7032 //
7033 // EXCEPTION: the top-level 'enabled' flag of every section is the
7034 // module's master switch and is controlled by the Dashboard module
7035 // toggle, NOT by a checkbox inside the section's form. Treating it
7036 // like a regular checkbox here would silently switch the module off
7037 // every time the user saves the tab — see the REST API enabled=false
7038 // regression. We only skip it at the top level (when section_name is
7039 // empty); nested 'enabled' fields like security_headers.csp.enabled
7040 // are real checkboxes and must keep the auto-unset behaviour.
7041 $preserve_top_level = array( 'enabled' );
7042
7043 foreach ( $defaults as $key => $default_value ) {
7044 if ( '' === $section_name && in_array( $key, $preserve_top_level, true ) ) {
7045 continue;
7046 }
7047 if ( is_bool( $default_value ) && ! array_key_exists( $key, $submitted_data ) ) {
7048 $result[ $key ] = false;
7049 } elseif ( is_array( $default_value ) && ! isset( $submitted_data[ $key ] ) ) {
7050 // Check if this is a flat value list (like excluded_users, enforced_roles, ip_whitelist)
7051 // vs a nested settings group (like rate_limiting, two_factor)
7052 // Flat lists: default is empty array OR all values are scalar
7053 $is_value_list = empty( $default_value );
7054 if ( ! $is_value_list ) {
7055 $is_value_list = true;
7056 foreach ( $default_value as $dv ) {
7057 if ( ! is_scalar( $dv ) ) {
7058 $is_value_list = false;
7059 break;
7060 }
7061 }
7062 }
7063
7064 if ( $is_value_list ) {
7065 // All items removed - reset to empty array
7066 $result[ $key ] = array();
7067 } else {
7068 // Nested settings group - handle boolean children
7069 foreach ( $default_value as $nested_key => $nested_default ) {
7070 if ( is_bool( $nested_default ) && isset( $result[ $key ] ) && is_array( $result[ $key ] ) ) {
7071 $nested_submitted = isset( $submitted_data[ $key ] ) && is_array( $submitted_data[ $key ] )
7072 ? $submitted_data[ $key ]
7073 : array();
7074 if ( ! array_key_exists( $nested_key, $nested_submitted ) ) {
7075 $result[ $key ][ $nested_key ] = false;
7076 }
7077 }
7078 }
7079 }
7080 }
7081 }
7082
7083 return $result;
7084 }
7085
7086 /**
7087 * AJAX: Export settings
7088 */
7089 public function ajax_export_settings() {
7090 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7091
7092 if ( ! current_user_can( 'manage_options' ) ) {
7093 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7094 }
7095
7096 $options = $this->settings->get_all_options();
7097 $filename = 'vigilante-settings-' . gmdate( 'Y-m-d-His' ) . '.json';
7098
7099 wp_send_json_success( array(
7100 'content' => wp_json_encode( $options, JSON_PRETTY_PRINT ),
7101 'filename' => $filename,
7102 ) );
7103 }
7104
7105 /**
7106 * AJAX: Import settings
7107 */
7108 public function ajax_import_settings() {
7109 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7110
7111 if ( ! current_user_can( 'manage_options' ) ) {
7112 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7113 }
7114
7115 // Accept both 'settings' (from JS) and 'content' (legacy).
7116 // Do NOT run sanitize_text_field() on the raw payload: it calls
7117 // wp_strip_all_tags() internally, which removes any "<...>" substring
7118 // and turns a valid export JSON into garbage if any stored value
7119 // contains < or > (htaccess snippets, email templates, etc.). The
7120 // real sanitization happens after json_decode(), via map_deep() on
7121 // the parsed array.
7122 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash
7123 $content = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : '';
7124 if ( empty( $content ) ) {
7125 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash
7126 $content = isset( $_POST['content'] ) ? wp_unslash( $_POST['content'] ) : '';
7127 }
7128
7129 if ( empty( $content ) || ! is_string( $content ) ) {
7130 wp_send_json_error( __( 'No content provided.', 'vigilante' ) );
7131 }
7132
7133 $imported = json_decode( $content, true );
7134
7135 if ( json_last_error() !== JSON_ERROR_NONE || ! is_array( $imported ) ) {
7136 wp_send_json_error( __( 'Invalid JSON format.', 'vigilante' ) );
7137 }
7138
7139 // Sanitize imported data recursively
7140 $imported = map_deep( $imported, 'sanitize_text_field' );
7141
7142 // Validate structure: only sections and keys of the schema survive, and
7143 // every value takes the type of its default. Until 2.11.0 this was an
7144 // array_replace_recursive() of the file over the defaults, so any key in
7145 // the file, known or not, landed in vigilante_options (S7). Sections
7146 // the file does not carry keep their defaults; a section it does carry
7147 // replaces the default one whole, because validate_options() has
7148 // already filled in whatever the file left out.
7149 $defaults = $this->settings->get_default_options();
7150 $validated = $this->settings->validate_options( $imported );
7151 $merged = $defaults;
7152
7153 foreach ( $validated as $section => $data ) {
7154 if ( is_array( $data ) ) {
7155 $merged[ $section ] = $data;
7156 }
7157 }
7158
7159 // Save
7160 update_option( Vigilante_Settings::OPTION_NAME, $merged );
7161 $this->settings->clear_cache();
7162
7163 // Re-evaluate the active preset marker. The imported config may match
7164 // a known preset exactly, partially, or not at all — without this step
7165 // the dashboard would keep showing whatever preset was active before
7166 // the import even if the new config no longer matches it.
7167 $matched_preset = $this->detect_matching_preset( $merged );
7168 if ( null === $matched_preset ) {
7169 delete_option( 'vigilante_active_preset' );
7170 } else {
7171 update_option( 'vigilante_active_preset', $matched_preset );
7172 }
7173
7174 // Apply file changes after import
7175 $this->apply_all_file_changes( $merged );
7176
7177 // Refresh the Security Analyzer score so the dashboard widget reflects
7178 // the imported config rather than the pre-import scan. Reuse the
7179 // post-Under-Attack scan hook (same job: full scan, async).
7180 if ( ! wp_next_scheduled( 'vigilante_under_attack_post_scan' ) ) {
7181 wp_schedule_single_event( time() + 5, 'vigilante_under_attack_post_scan' );
7182 }
7183
7184 wp_send_json_success( __( 'Settings imported successfully.', 'vigilante' ) );
7185 }
7186
7187 /**
7188 * Detect whether a vigilante_options array matches a known preset.
7189 *
7190 * A preset matches when every field the preset explicitly declares is
7191 * present in the config with the same (normalised) value. Fields outside
7192 * the preset are ignored — they may have been modified by the user before
7193 * applying the preset and do not invalidate the match. This mirrors how
7194 * apply_preset() now layers presets on top of the user's existing config.
7195 *
7196 * @param array $options The current/imported vigilante_options.
7197 * @return string|null Preset id ('standard', 'maximum') or null if custom.
7198 */
7199 private function detect_matching_preset( $options ) {
7200 if ( ! is_array( $options ) ) {
7201 return null;
7202 }
7203
7204 $presets = $this->settings->get_presets();
7205
7206 foreach ( $presets as $preset_id => $preset_data ) {
7207 unset( $preset_data['name'], $preset_data['description'] );
7208 if ( $this->preset_subset_matches( $preset_data, $options ) ) {
7209 return $preset_id;
7210 }
7211 }
7212
7213 return null;
7214 }
7215
7216 /**
7217 * Check whether every leaf value inside $preset_subset exists with the
7218 * same (normalised) value at the same path inside $config.
7219 *
7220 * @param mixed $preset_subset Branch of the preset definition.
7221 * @param mixed $config Same branch in the live/imported config.
7222 * @return bool
7223 */
7224 private function preset_subset_matches( $preset_subset, $config ) {
7225 if ( is_array( $preset_subset ) ) {
7226 if ( ! is_array( $config ) ) {
7227 return false;
7228 }
7229 foreach ( $preset_subset as $key => $value ) {
7230 if ( ! array_key_exists( $key, $config ) ) {
7231 return false;
7232 }
7233 if ( ! $this->preset_subset_matches( $value, $config[ $key ] ) ) {
7234 return false;
7235 }
7236 }
7237 return true;
7238 }
7239
7240 return $this->normalise_scalar_for_compare( $preset_subset ) === $this->normalise_scalar_for_compare( $config );
7241 }
7242
7243 /**
7244 * Normalise a scalar value so that the variants WordPress and the form
7245 * layer routinely produce ('1' / 1 / true → "1"; '' / '0' / 0 / false /
7246 * null → "") compare equal. Other values become strings unchanged.
7247 *
7248 * @param mixed $value
7249 * @return string
7250 */
7251 private function normalise_scalar_for_compare( $value ) {
7252 if ( is_bool( $value ) ) {
7253 return $value ? '1' : '';
7254 }
7255 if ( null === $value ) {
7256 return '';
7257 }
7258 if ( is_int( $value ) || is_float( $value ) ) {
7259 return (string) $value;
7260 }
7261 if ( is_string( $value ) ) {
7262 if ( 'true' === $value ) {
7263 return '1';
7264 }
7265 if ( 'false' === $value ) {
7266 return '';
7267 }
7268 return $value;
7269 }
7270 // Arrays and objects shouldn't reach here (handled by recursion above),
7271 // but if they do, fall back to a stable comparable representation.
7272 return wp_json_encode( $value );
7273 }
7274
7275 /**
7276 * AJAX: Apply preset
7277 */
7278 public function ajax_apply_preset() {
7279 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7280
7281 if ( ! current_user_can( 'manage_options' ) ) {
7282 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7283 }
7284
7285 $preset = isset( $_POST['preset'] ) ? sanitize_key( $_POST['preset'] ) : '';
7286
7287 // Handle reset to defaults
7288 if ( 'reset' === $preset ) {
7289 $defaults = Vigilante_Settings::get_defaults_preserving_user_data( get_option( Vigilante_Settings::OPTION_NAME, array() ) );
7290 update_option( Vigilante_Settings::OPTION_NAME, $defaults );
7291 $this->settings->clear_cache();
7292
7293 // Clear active preset
7294 update_option( 'vigilante_active_preset', '' );
7295
7296 // Apply file changes after reset
7297 $this->apply_all_file_changes( $defaults );
7298
7299 wp_send_json_success( __( 'Settings reset to defaults.', 'vigilante' ) );
7300 return;
7301 }
7302
7303 $presets = $this->settings->get_presets();
7304
7305 if ( ! isset( $presets[ $preset ] ) ) {
7306 wp_send_json_error( __( 'Invalid preset.', 'vigilante' ) );
7307 }
7308
7309 $preset_options = $presets[ $preset ];
7310 unset( $preset_options['name'], $preset_options['description'] );
7311
7312 // Layer the preset on top of the user's CURRENT configuration, not on
7313 // top of defaults. This way applying a preset only changes the fields
7314 // the preset explicitly mentions; everything else stays as the user
7315 // had it. For example, applying Maximum will not flip HSTS off if the
7316 // user had it on — Maximum doesn't touch HSTS, so it's left alone.
7317 // Use "Reset to Defaults" if a clean slate is needed.
7318 $current = get_option( Vigilante_Settings::OPTION_NAME, array() );
7319 if ( ! is_array( $current ) ) {
7320 $current = array();
7321 }
7322 // Make sure all known keys exist before merging — the merge does not
7323 // invent keys that are missing on both sides.
7324 $current = Vigilante_Settings::merge_preset( $this->settings->get_default_options(), $current );
7325
7326 $merged = Vigilante_Settings::merge_preset( $current, $preset_options );
7327
7328 update_option( Vigilante_Settings::OPTION_NAME, $merged );
7329 $this->settings->clear_cache();
7330
7331 // Save active preset
7332 update_option( 'vigilante_active_preset', $preset );
7333
7334 // Apply file changes after preset
7335 $this->apply_all_file_changes( $merged );
7336
7337 wp_send_json_success( __( 'Preset applied successfully.', 'vigilante' ) );
7338 }
7339
7340 /**
7341 * AJAX: Reset a specific section to defaults
7342 */
7343 public function ajax_reset_section() {
7344 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7345
7346 if ( ! current_user_can( 'manage_options' ) ) {
7347 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7348 }
7349
7350 $section = isset( $_POST['section'] ) ? sanitize_key( $_POST['section'] ) : '';
7351
7352 if ( empty( $section ) ) {
7353 wp_send_json_error( __( 'No section specified.', 'vigilante' ) );
7354 }
7355
7356 // Get current options and defaults. get_defaults_preserving_user_data()
7357 // applies the tweaks a fresh installation gets, so the button and a new
7358 // install agree, and keeps whatever the owner typed in.
7359 $current_options = $this->settings->get_all_options();
7360 $defaults = Vigilante_Settings::get_defaults_preserving_user_data( $current_options );
7361
7362 // Check if section exists in defaults
7363 if ( ! isset( $defaults[ $section ] ) ) {
7364 wp_send_json_error( __( 'Invalid section.', 'vigilante' ) );
7365 }
7366
7367 $new_values = $defaults[ $section ];
7368
7369 /*
7370 * On a subsite, the settings written to wp-config.php and .htaccess are
7371 * the main site's business. Resetting the local copy of those would only
7372 * make this screen disagree with the file, so they are carried over
7373 * untouched, and a section that is nothing but shared settings is not
7374 * reset at all.
7375 */
7376 if ( ! Vigilante_Settings::can_write_shared_files() ) {
7377 $shared = Vigilante_Settings::get_shared_file_settings();
7378
7379 if ( isset( $shared[ $section ] ) ) {
7380 if ( true === $shared[ $section ] ) {
7381 wp_send_json_error( Vigilante_Settings::get_shared_files_notice() );
7382 }
7383
7384 foreach ( $shared[ $section ] as $shared_key ) {
7385 if ( array_key_exists( $shared_key, (array) $current_options[ $section ] ) ) {
7386 $new_values[ $shared_key ] = $current_options[ $section ][ $shared_key ];
7387 }
7388 }
7389 }
7390 }
7391
7392 $current_options[ $section ] = $new_values;
7393
7394 // Save
7395 update_option( Vigilante_Settings::OPTION_NAME, $current_options );
7396 $this->settings->clear_cache();
7397
7398 // Apply file changes if needed
7399 $this->apply_section_changes( $section, $current_options );
7400
7401 wp_send_json_success( array(
7402 'message' => __( 'Section reset to defaults.', 'vigilante' ),
7403 'section' => $section,
7404 'reload' => true,
7405 ) );
7406 }
7407
7408 /**
7409 * AJAX: Clear lockouts
7410 */
7411 public function ajax_clear_lockouts() {
7412 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7413
7414 if ( ! current_user_can( 'manage_options' ) ) {
7415 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7416 }
7417
7418 $ip = isset( $_POST['ip'] ) ? sanitize_text_field( wp_unslash( $_POST['ip'] ) ) : '';
7419
7420 if ( ! empty( $ip ) ) {
7421 $this->database->clear_lockout( $ip );
7422 } else {
7423 $this->database->clear_all_lockouts();
7424 }
7425
7426 wp_send_json_success( __( 'Lockouts cleared.', 'vigilante' ) );
7427 }
7428
7429 /**
7430 * AJAX: Clear logs
7431 */
7432 public function ajax_clear_logs() {
7433 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7434
7435 if ( ! current_user_can( 'manage_options' ) ) {
7436 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7437 }
7438
7439 if ( $this->activity_log ) {
7440 $result = $this->activity_log->clear_all_logs();
7441 if ( $result ) {
7442 wp_send_json_success( __( 'Logs cleared.', 'vigilante' ) );
7443 } else {
7444 wp_send_json_error( __( 'Failed to clear logs.', 'vigilante' ) );
7445 }
7446 } else {
7447 wp_send_json_error( __( 'Activity log not available.', 'vigilante' ) );
7448 }
7449 }
7450
7451 /**
7452 * AJAX: Run file integrity scan.
7453 *
7454 * Triggers the file integrity scan, which now also runs the closed plugins
7455 * check at the end when the `check_closed_plugins` toggle is on. Activity
7456 * log is passed through so Security Audit entries (both file-level and
7457 * plugin-status) are recorded from this entry point.
7458 */
7459 public function ajax_run_scan() {
7460 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7461
7462 if ( ! current_user_can( 'manage_options' ) ) {
7463 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7464 }
7465
7466 // Clear previous results before running new scan
7467 delete_option( 'vigilante_last_integrity_results' );
7468 delete_option( 'vigilante_last_integrity_scan' );
7469
7470 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database, $this->activity_log );
7471 $results = $file_integrity->run_scan();
7472
7473 // Save new results
7474 update_option( 'vigilante_last_integrity_scan', time() );
7475 update_option( 'vigilante_last_integrity_results', $results );
7476
7477 wp_send_json_success( array(
7478 'message' => __( 'Scan completed.', 'vigilante' ),
7479 'results' => $results,
7480 'ignored_count' => count( get_option( 'vigilante_ignored_files', array() ) ),
7481 ) );
7482 }
7483
7484 /**
7485 * AJAX: Clear scan results.
7486 *
7487 * Wipes visually everything inside "Last Scan Results": file scan findings
7488 * (Suspicious / Modified / Extra / Critical Config), file hashes and the
7489 * Closed + Removed Plugins block.
7490 *
7491 * Implementation detail to keep persistence intact:
7492 * - We delete the file scan options + hashes outright.
7493 * - For plugin status we ONLY delete the last_check timestamp — the state
7494 * map and the ignore list are preserved in DB. The render gates the
7495 * plugin_status subsections on last_check > 0, so they hide after
7496 * Clear (visual reset) and reappear on the next Run Scan Now with the
7497 * state intact. This avoids degrading a 'removed' slug (404 without
7498 * metadata) back to 'not_in_repo' on the next scan, which would
7499 * silently lose the alert.
7500 *
7501 * The Ignored Files list and the Ignored Closed + Removed Plugins list
7502 * are preserved on purpose; each has its own explicit "Clear All …"
7503 * button.
7504 */
7505 public function ajax_clear_scan() {
7506 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7507
7508 if ( ! current_user_can( 'manage_options' ) ) {
7509 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7510 }
7511
7512 delete_option( 'vigilante_last_integrity_results' );
7513 delete_option( 'vigilante_last_integrity_scan' );
7514
7515 if ( $this->database ) {
7516 $this->database->clear_file_hashes();
7517 }
7518
7519 // Visual reset of plugin_status block without touching the state map
7520 // or the ignored list. See PHPDoc above for the rationale.
7521 delete_option( 'vigilante_plugin_status_last_check' );
7522
7523 wp_send_json_success( __( 'Scan results cleared.', 'vigilante' ) );
7524 }
7525
7526 /**
7527 * AJAX: Ignore a file from scan results
7528 */
7529 public function ajax_ignore_file() {
7530 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7531
7532 if ( ! current_user_can( 'manage_options' ) ) {
7533 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7534 }
7535
7536 $file = isset( $_POST['file'] ) ? sanitize_text_field( wp_unslash( $_POST['file'] ) ) : '';
7537
7538 if ( empty( $file ) ) {
7539 wp_send_json_error( __( 'No file specified.', 'vigilante' ) );
7540 }
7541
7542 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7543 $file_integrity->ignore_file( $file );
7544
7545 // Also remove the file from stored scan results so UI updates
7546 $results = get_option( 'vigilante_last_integrity_results' );
7547 if ( $results ) {
7548 foreach ( array( 'modified', 'suspicious', 'extra' ) as $category ) {
7549 if ( ! empty( $results[ $category ] ) ) {
7550 $results[ $category ] = array_values(
7551 array_filter(
7552 $results[ $category ],
7553 function ( $item ) use ( $file ) {
7554 return ( is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item ) !== $file;
7555 }
7556 )
7557 );
7558 }
7559 }
7560 update_option( 'vigilante_last_integrity_results', $results );
7561 }
7562
7563 wp_send_json_success( __( 'File added to ignored list.', 'vigilante' ) );
7564 }
7565
7566 /**
7567 * AJAX: Stop ignoring a file
7568 */
7569 public function ajax_unignore_file() {
7570 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7571
7572 if ( ! current_user_can( 'manage_options' ) ) {
7573 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7574 }
7575
7576 $file = isset( $_POST['file'] ) ? sanitize_text_field( wp_unslash( $_POST['file'] ) ) : '';
7577
7578 if ( empty( $file ) ) {
7579 wp_send_json_error( __( 'No file specified.', 'vigilante' ) );
7580 }
7581
7582 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7583 $file_integrity->unignore_file( $file );
7584
7585 wp_send_json_success( __( 'File removed from ignored list.', 'vigilante' ) );
7586 }
7587
7588 /**
7589 * AJAX: Bulk ignore multiple files at once
7590 *
7591 * Processes a single batch into ignored list and prunes them from the
7592 * stored scan results so the UI updates without a re-scan.
7593 */
7594 public function ajax_bulk_ignore_files() {
7595 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7596
7597 if ( ! current_user_can( 'manage_options' ) ) {
7598 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7599 }
7600
7601 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized below per-item.
7602 $raw_files = isset( $_POST['files'] ) ? wp_unslash( $_POST['files'] ) : array();
7603 if ( ! is_array( $raw_files ) ) {
7604 wp_send_json_error( __( 'Invalid request.', 'vigilante' ) );
7605 }
7606
7607 $files = array();
7608 foreach ( $raw_files as $f ) {
7609 $clean = sanitize_text_field( $f );
7610 if ( '' !== $clean ) {
7611 $files[] = $clean;
7612 }
7613 }
7614
7615 if ( empty( $files ) ) {
7616 wp_send_json_error( __( 'No files selected.', 'vigilante' ) );
7617 }
7618
7619 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7620 $count = 0;
7621 foreach ( $files as $file ) {
7622 $file_integrity->ignore_file( $file );
7623 $count++;
7624 }
7625
7626 // Also prune the stored scan results so the UI matches the new ignore list.
7627 $results = get_option( 'vigilante_last_integrity_results' );
7628 if ( $results ) {
7629 $files_set = array_flip( $files );
7630 foreach ( array( 'modified', 'suspicious', 'extra' ) as $category ) {
7631 if ( ! empty( $results[ $category ] ) ) {
7632 $results[ $category ] = array_values(
7633 array_filter(
7634 $results[ $category ],
7635 function ( $item ) use ( $files_set ) {
7636 $path = is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item;
7637 return ! isset( $files_set[ $path ] );
7638 }
7639 )
7640 );
7641 }
7642 }
7643 update_option( 'vigilante_last_integrity_results', $results );
7644 }
7645
7646 wp_send_json_success(
7647 array(
7648 'count' => $count,
7649 'message' => sprintf(
7650 /* translators: %d: number of files added to the ignored list */
7651 _n( '%d file added to ignored list.', '%d files added to ignored list.', $count, 'vigilante' ),
7652 $count
7653 ),
7654 )
7655 );
7656 }
7657
7658 /**
7659 * AJAX: Bulk un-ignore multiple files at once
7660 */
7661 public function ajax_bulk_unignore_files() {
7662 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7663
7664 if ( ! current_user_can( 'manage_options' ) ) {
7665 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7666 }
7667
7668 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized below per-item.
7669 $raw_files = isset( $_POST['files'] ) ? wp_unslash( $_POST['files'] ) : array();
7670 if ( ! is_array( $raw_files ) ) {
7671 wp_send_json_error( __( 'Invalid request.', 'vigilante' ) );
7672 }
7673
7674 $files = array();
7675 foreach ( $raw_files as $f ) {
7676 $clean = sanitize_text_field( $f );
7677 if ( '' !== $clean ) {
7678 $files[] = $clean;
7679 }
7680 }
7681
7682 if ( empty( $files ) ) {
7683 wp_send_json_error( __( 'No files selected.', 'vigilante' ) );
7684 }
7685
7686 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7687 $count = 0;
7688 foreach ( $files as $file ) {
7689 $file_integrity->unignore_file( $file );
7690 $count++;
7691 }
7692
7693 wp_send_json_success(
7694 array(
7695 'count' => $count,
7696 'message' => sprintf(
7697 /* translators: %d: number of files removed from the ignored list */
7698 _n( '%d file removed from ignored list.', '%d files removed from ignored list.', $count, 'vigilante' ),
7699 $count
7700 ),
7701 )
7702 );
7703 }
7704
7705 /**
7706 * AJAX: Clear all ignored files
7707 */
7708 public function ajax_clear_ignored() {
7709 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7710
7711 if ( ! current_user_can( 'manage_options' ) ) {
7712 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7713 }
7714
7715 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7716 $file_integrity->clear_ignored_files();
7717
7718 wp_send_json_success( __( 'Ignored files list cleared.', 'vigilante' ) );
7719 }
7720
7721 /**
7722 * AJAX: Ignore a closed/removed plugin slug so it stops appearing in the
7723 * main list and email digests. The plugin keeps running on the site;
7724 * silencing is purely cosmetic and reversible.
7725 */
7726 public function ajax_ignore_closed_plugin() {
7727 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7728
7729 if ( ! current_user_can( 'manage_options' ) ) {
7730 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7731 }
7732
7733 $slug = isset( $_POST['slug'] ) ? sanitize_key( wp_unslash( $_POST['slug'] ) ) : '';
7734 if ( '' === $slug ) {
7735 wp_send_json_error( __( 'No slug specified.', 'vigilante' ) );
7736 }
7737
7738 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
7739 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
7740 }
7741 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
7742 $checker->ignore_slug( $slug );
7743
7744 wp_send_json_success( __( 'Plugin added to the ignored list.', 'vigilante' ) );
7745 }
7746
7747 /**
7748 * AJAX: Stop ignoring a previously-ignored closed/removed plugin slug.
7749 */
7750 public function ajax_unignore_closed_plugin() {
7751 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7752
7753 if ( ! current_user_can( 'manage_options' ) ) {
7754 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7755 }
7756
7757 $slug = isset( $_POST['slug'] ) ? sanitize_key( wp_unslash( $_POST['slug'] ) ) : '';
7758 if ( '' === $slug ) {
7759 wp_send_json_error( __( 'No slug specified.', 'vigilante' ) );
7760 }
7761
7762 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
7763 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
7764 }
7765 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
7766 $checker->unignore_slug( $slug );
7767
7768 wp_send_json_success( __( 'Plugin removed from the ignored list.', 'vigilante' ) );
7769 }
7770
7771 /**
7772 * AJAX: Clear the entire ignored-closed-plugins list.
7773 */
7774 public function ajax_clear_ignored_closed_plugins() {
7775 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7776
7777 if ( ! current_user_can( 'manage_options' ) ) {
7778 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7779 }
7780
7781 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
7782 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
7783 }
7784 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
7785 $checker->clear_ignored();
7786
7787 wp_send_json_success( __( 'Ignored closed plugins list cleared.', 'vigilante' ) );
7788 }
7789
7790 /**
7791 * AJAX: Test security headers
7792 */
7793 public function ajax_test_headers() {
7794 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7795
7796 if ( ! current_user_can( 'manage_options' ) ) {
7797 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7798 }
7799
7800 // Get security grade from settings (not from actual HTTP request)
7801 $security_headers = new Vigilante_Security_Headers( $this->settings );
7802 $results = $security_headers->get_security_grade();
7803
7804 wp_send_json_success( $results );
7805 }
7806
7807 /**
7808 * Sanitize section data (kept for compatibility)
7809 *
7810 * @param string $section Section name.
7811 * @param array $data Section data.
7812 * @return array
7813 */
7814 private function sanitize_section_data( $section, $data ) {
7815 $sanitized = array();
7816
7817 foreach ( $data as $key => $value ) {
7818 $key = sanitize_key( $key );
7819
7820 if ( is_array( $value ) ) {
7821 $sanitized[ $key ] = $this->sanitize_section_data( $key, $value );
7822 } elseif ( is_numeric( $value ) ) {
7823 $sanitized[ $key ] = intval( $value );
7824 } else {
7825 $sanitized[ $key ] = sanitize_text_field( $value );
7826 }
7827 }
7828
7829 return $sanitized;
7830 }
7831
7832 /**
7833 * Apply changes after saving settings
7834 *
7835 * @param string $section Section that was updated.
7836 * @param array $all_options All options.
7837 */
7838 private function apply_section_changes( $section, $all_options ) {
7839 // Create fresh settings instance to ensure we have the latest data
7840 $fresh_settings = new Vigilante_Settings();
7841
7842 // The shared Vigilant .htaccess block carries BOTH the firewall's
7843 // file-protection rules and the server-signature / fingerprinting rules
7844 // that are configured under Security Headers. So it must be regenerated
7845 // whenever either section (or the module toggles) changes, not only on
7846 // the firewall save — otherwise toggling "Hide server signature" or
7847 // "Remove fingerprinting headers" never reaches the .htaccess.
7848 if ( in_array( $section, array( 'firewall', 'security_headers', 'modules' ), true ) ) {
7849 $htaccess = new Vigilante_Htaccess_Protection( $fresh_settings );
7850 $sh = $fresh_settings->get_section( 'security_headers' );
7851 $needs_htaccess_block = ! empty( $all_options['modules']['firewall'] )
7852 || ! empty( $sh['hide_server_signature'] )
7853 || ! empty( $sh['remove_fingerprinting_headers'] );
7854
7855 if ( $needs_htaccess_block ) {
7856 $htaccess->apply_rules();
7857 } else {
7858 $htaccess->remove_rules();
7859 }
7860 }
7861
7862 // Regenerate the HTTP security headers (sent by PHP) for the headers section.
7863 if ( 'security_headers' === $section || 'modules' === $section ) {
7864 $security_headers = new Vigilante_Security_Headers( $fresh_settings );
7865 $headers_enabled = ! empty( $all_options['modules']['security_headers'] );
7866
7867 if ( $headers_enabled ) {
7868 $security_headers->apply_rules();
7869 } else {
7870 $security_headers->remove_rules();
7871 }
7872 }
7873
7874 // Regenerate wp-config for wp_hardening section
7875 if ( 'wp_hardening' === $section || 'modules' === $section ) {
7876 $wpconfig = new Vigilante_Wpconfig_Security( $fresh_settings );
7877 $hardening_enabled = ! empty( $all_options['modules']['wp_hardening'] );
7878
7879 if ( $hardening_enabled ) {
7880 $wpconfig->apply_security_constants();
7881 } else {
7882 $wpconfig->remove_constants();
7883 }
7884
7885 // Apply WordPress options for comments/pingbacks
7886 $hardening_options = $all_options['wp_hardening'] ?? array();
7887
7888 if ( $hardening_enabled ) {
7889 // Pingbacks
7890 if ( ! empty( $hardening_options['disable_pingbacks'] ) ) {
7891 update_option( 'default_pingback_flag', 0 );
7892 } else {
7893 // Restore default: pingbacks enabled
7894 update_option( 'default_pingback_flag', 1 );
7895 }
7896
7897 // Trackbacks and ping status
7898 // Only close if either pingbacks OR trackbacks are disabled
7899 if ( ! empty( $hardening_options['disable_pingbacks'] ) || ! empty( $hardening_options['disable_trackbacks'] ) ) {
7900 update_option( 'default_ping_status', 'closed' );
7901 } else {
7902 // Restore default: pings open
7903 update_option( 'default_ping_status', 'open' );
7904 }
7905
7906 // Comment moderation
7907 if ( ! empty( $hardening_options['require_comment_moderation'] ) ) {
7908 update_option( 'comment_moderation', 1 );
7909 } else {
7910 // Restore default: no moderation required
7911 update_option( 'comment_moderation', 0 );
7912 }
7913 }
7914 }
7915
7916 // Trim activity log entries immediately when limits change
7917 if ( 'activity_log' === $section && $this->activity_log ) {
7918 $this->activity_log->cleanup_old_logs();
7919 }
7920
7921 // Flush rewrite rules if login URL changed
7922 if ( 'login_security' === $section ) {
7923 $login_options = $all_options['login_security'] ?? array();
7924 if ( ! empty( $login_options['custom_login_url'] ) ) {
7925 delete_option( 'vigilante_login_rules_version' );
7926 }
7927 }
7928
7929 // Log the settings change with readable section name
7930 if ( $this->activity_log ) {
7931 $section_names = array(
7932 'firewall' => __( 'Firewall', 'vigilante' ),
7933 'login_security' => __( 'Login Security', 'vigilante' ),
7934 'security_headers' => __( 'Security Headers', 'vigilante' ),
7935 'rest_api_security'=> __( 'REST API Security', 'vigilante' ),
7936 'user_security' => __( 'User Security', 'vigilante' ),
7937 'wp_hardening' => __( 'WP Hardening', 'vigilante' ),
7938 'activity_log' => __( 'Security Audit', 'vigilante' ),
7939 'file_integrity' => __( 'File Integrity', 'vigilante' ),
7940 'email' => __( 'Notification Settings', 'vigilante' ),
7941 'backup' => __( 'Backup', 'vigilante' ),
7942 'advanced' => __( 'Advanced', 'vigilante' ),
7943 'modules' => __( 'Modules', 'vigilante' ),
7944 );
7945 $display_name = isset( $section_names[ $section ] ) ? $section_names[ $section ] : $section;
7946
7947 $this->activity_log->log(
7948 'settings',
7949 'settings_updated',
7950 sprintf(
7951 /* translators: %s: Section name */
7952 __( 'Settings updated: %s', 'vigilante' ),
7953 $display_name
7954 ),
7955 array( 'section' => $section ),
7956 'info'
7957 );
7958 }
7959 }
7960
7961 /**
7962 * Apply all file changes (htaccess, wp-config) based on current options
7963 *
7964 * Used after preset, import, or reset operations
7965 *
7966 * @param array $all_options All plugin options.
7967 */
7968 private function apply_all_file_changes( $all_options ) {
7969 // Refresh settings cache first
7970 $this->settings->clear_cache();
7971
7972 // Create fresh settings instance
7973 $fresh_settings = new Vigilante_Settings();
7974
7975 // Apply firewall htaccess changes
7976 $htaccess = new Vigilante_Htaccess_Protection( $fresh_settings );
7977 $firewall_enabled = ! empty( $all_options['modules']['firewall'] );
7978
7979 if ( $firewall_enabled ) {
7980 $htaccess->apply_rules();
7981 } else {
7982 $htaccess->remove_rules();
7983 }
7984
7985 // Apply security headers htaccess changes
7986 $security_headers = new Vigilante_Security_Headers( $fresh_settings );
7987 $headers_enabled = ! empty( $all_options['modules']['security_headers'] );
7988
7989 if ( $headers_enabled ) {
7990 $security_headers->apply_rules();
7991 } else {
7992 $security_headers->remove_rules();
7993 }
7994
7995 // Apply wp-config changes
7996 $wpconfig = new Vigilante_Wpconfig_Security( $fresh_settings );
7997 $hardening_enabled = ! empty( $all_options['modules']['wp_hardening'] );
7998
7999 if ( $hardening_enabled ) {
8000 $wpconfig->apply_security_constants();
8001 } else {
8002 $wpconfig->remove_constants();
8003 }
8004
8005 // Apply WordPress options for comments/pingbacks
8006 $hardening_options = $all_options['wp_hardening'] ?? array();
8007
8008 if ( $hardening_enabled ) {
8009 // Pingbacks
8010 if ( ! empty( $hardening_options['disable_pingbacks'] ) ) {
8011 update_option( 'default_pingback_flag', 0 );
8012 } else {
8013 // Restore default: pingbacks enabled
8014 update_option( 'default_pingback_flag', 1 );
8015 }
8016
8017 // Trackbacks and ping status
8018 // Only close if either pingbacks OR trackbacks are disabled
8019 if ( ! empty( $hardening_options['disable_pingbacks'] ) || ! empty( $hardening_options['disable_trackbacks'] ) ) {
8020 update_option( 'default_ping_status', 'closed' );
8021 } else {
8022 // Restore default: pings open
8023 update_option( 'default_ping_status', 'open' );
8024 }
8025
8026 // Comment moderation
8027 if ( ! empty( $hardening_options['require_comment_moderation'] ) ) {
8028 update_option( 'comment_moderation', 1 );
8029 } else {
8030 // Restore default: no moderation required
8031 update_option( 'comment_moderation', 0 );
8032 }
8033 }
8034
8035 // Log the change
8036 if ( $this->activity_log ) {
8037 $this->activity_log->log(
8038 'settings',
8039 'bulk_settings_applied',
8040 __( 'Bulk settings applied (preset/import/reset)', 'vigilante' ),
8041 array(),
8042 'info'
8043 );
8044 }
8045 }
8046 }