PluginProbe
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… / 2.11.7
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… v2.11.7
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 2.9.4 2.9.3 All 86 releases
vigilante / admin / class-admin.php

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

8,167 lines 523.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
278 /*
279 * Only when there is nothing on record. This migration exists to
280 * create the baseline that did not exist, never to discard the one
281 * the owner approved: rebuilding it from the files takes whatever
282 * is on disk right now as approved, so a wp-config.php modified and
283 * awaiting review would be blessed in silence.
284 *
285 * And this is not theory. vigilante_db_version is written on two
286 * different scales into the same option: this file counts in plugin
287 * versions (2.11.0) and Vigilante_Database counts in schema
288 * versions, currently 1.4.0 (class-database.php:322 and :380). For
289 * version_compare, 1.4.0 is LOWER than 1.14.0, so any site whose
290 * option was last written by the schema runs this migration again.
291 * Measured on the Multisite install on 10 sep 2026: one of the three
292 * sites was sitting on 1.4.0.
293 */
294 if ( ! $fi->get_critical_files_baseline() ) {
295 $fi->regenerate_all_baselines();
296 }
297
298 update_option( 'vigilante_db_version', '1.14.0' );
299 }
300
301 // 2.0.0: Move hide_server_signature and remove_fingerprinting_headers
302 // from firewall section to security_headers section
303 if ( version_compare( $db_version, '2.0.0', '<' ) ) {
304 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
305 $changed = false;
306
307 foreach ( array( 'hide_server_signature', 'remove_fingerprinting_headers' ) as $key ) {
308 if ( isset( $options['firewall'][ $key ] ) ) {
309 if ( ! isset( $options['security_headers'][ $key ] ) ) {
310 $options['security_headers'][ $key ] = $options['firewall'][ $key ];
311 }
312 unset( $options['firewall'][ $key ] );
313 $changed = true;
314 }
315 }
316
317 if ( $changed ) {
318 update_option( Vigilante_Settings::OPTION_NAME, $options );
319 }
320 update_option( 'vigilante_db_version', '2.0.0' );
321 }
322
323 // 2.6.1: Two things happen here.
324 //
325 // 1. Re-apply wp-config constants so the block is rewritten with
326 // "if ( ! defined() )" guards around every define(). Without guards,
327 // non-standard setups that pre-define WordPress constants outside
328 // wp-config.php (custom bootstraps that load constants from .env or
329 // similar) hit a fatal "Constant already defined" when wp-config.php
330 // is parsed and reaches our block.
331 //
332 // 2. Drop the cached Security Check report. The cached "max" per
333 // category was frozen at scan time; with the internal category
334 // bumping from 22 to 28 points (closed_plugins added in 2.6.0),
335 // the cached report would keep displaying 22/22 until the next
336 // full scan. Clearing it forces a fresh scan with the new caps.
337 if ( version_compare( $db_version, '2.6.1', '<' ) ) {
338 if ( $this->settings->is_module_enabled( 'wp_hardening' ) ) {
339 require_once VIGILANTE_INCLUDES_DIR . 'class-wpconfig-security.php';
340 $wpconfig = new Vigilante_Wpconfig_Security( $this->settings );
341 $wpconfig->apply_security_constants();
342 }
343 delete_option( 'vigilante_analyzer_last_scan' );
344
345 // Schedule an immediate background scan so the dashboard widget
346 // doesn't display "Last scan: never" right after the upgrade.
347 // Reuses the same hook the post-Under-Attack flow uses.
348 if ( ! wp_next_scheduled( 'vigilante_under_attack_post_scan' ) ) {
349 wp_schedule_single_event( time() + 5, 'vigilante_under_attack_post_scan' );
350 }
351
352 update_option( 'vigilante_db_version', '2.6.1' );
353 }
354
355 // 2.9.3: Regenerate the .htaccess protection block. The bad-bots
356 // User-Agent list dropped substring-prone tokens that 403'd
357 // legitimate clients (e.g. "rma" matched inside "Performance" and
358 // blocked WP Rocket's page fetch), and the blocking rules now honour
359 // the firewall IP / User-Agent whitelists as negated exceptions.
360 // Existing sites only rewrite the block when Server Protection is
361 // saved, so the upgrade has to refresh it once itself (same pattern
362 // as the 1.12.1 WooCommerce IPN migration).
363 if ( version_compare( $db_version, '2.9.3', '<' ) ) {
364 require_once VIGILANTE_INCLUDES_DIR . 'class-htaccess-protection.php';
365 $htaccess = new Vigilante_Htaccess_Protection( $this->settings );
366
367 if ( $htaccess->are_rules_active() ) {
368 $htaccess->apply_rules();
369 }
370
371 update_option( 'vigilante_db_version', '2.9.3' );
372 }
373
374 /*
375 * 2.9.8: the mixed content handling changes shape. "Upgrade Insecure
376 * Requests" becomes a setting of its own, and Fix Mixed Content ships
377 * off, where before it shipped on and carried the directive with it.
378 * Both have to be written down for sites that are updating, so their
379 * pages keep loading exactly what they loaded yesterday.
380 *
381 * Read the RAW stored options, not get_section(): that one merges the
382 * defaults, so a site that never stored the key would be read with the
383 * new default and silently lose the behaviour it had. Absent means the
384 * site was running on the old default, which was on.
385 */
386 if ( version_compare( $db_version, '2.9.8', '<' ) ) {
387 $raw = get_option( Vigilante_Settings::OPTION_NAME, array() );
388 $stored = ( is_array( $raw ) && isset( $raw['security_headers'] ) && is_array( $raw['security_headers'] ) ) ? $raw['security_headers'] : array();
389 $had_fix = array_key_exists( 'fix_mixed_content', $stored ) ? ! empty( $stored['fix_mixed_content'] ) : true;
390
391 /*
392 * Merge, never replace. update_section() overwrites the whole
393 * section, so passing just these two keys wiped every other header
394 * setting the site had stored (HSTS, CSP, cross-origin policies,
395 * the HTTPS switches, Server Identity) and left the screen showing
396 * factory defaults while the .htaccess kept serving the old values.
397 */
398 $this->settings->update_section(
399 'security_headers',
400 array_merge(
401 $stored,
402 array(
403 'fix_mixed_content' => $had_fix,
404 'upgrade_insecure_requests' => $had_fix,
405 )
406 )
407 );
408
409 update_option( 'vigilante_db_version', '2.9.8' );
410 }
411
412 /*
413 * 2.9.9: drop the settings that no code has read for versions.
414 *
415 * They were carried in the defaults and therefore written into every
416 * saved configuration, they show up in an exported configuration, and
417 * anyone reading them assumes a feature exists behind them. Removing
418 * them from the defaults is not enough: the stored copies survive, so
419 * they are swept here too. Nothing reads them, so nothing changes.
420 */
421 if ( version_compare( $db_version, '2.9.9', '<' ) ) {
422 $raw = get_option( Vigilante_Settings::OPTION_NAME, array() );
423 $dead = array(
424 'firewall' => array( 'country_blocking', 'protected_file_extensions' ),
425 'file_integrity' => array( 'suspicious_patterns' ),
426 'backup' => array( 'auto_backup', 'backup_before_update' ),
427 'advanced' => array( 'block_author_archives', 'disable_embeds', 'uninstall_cleanup', 'debug_mode' ),
428 );
429
430 $changed = false;
431 foreach ( $dead as $section => $keys ) {
432 if ( ! isset( $raw[ $section ] ) || ! is_array( $raw[ $section ] ) ) {
433 continue;
434 }
435 foreach ( $keys as $key ) {
436 if ( array_key_exists( $key, $raw[ $section ] ) ) {
437 unset( $raw[ $section ][ $key ] );
438 $changed = true;
439 }
440 }
441 }
442
443 if ( $changed ) {
444 update_option( Vigilante_Settings::OPTION_NAME, $raw );
445 }
446
447 update_option( 'vigilante_db_version', '2.9.9' );
448 }
449
450 /*
451 * 2.11.0: security release (audit of 28 Aug 2026). Runs here and not
452 * from Vigilante_Database::needs_update(): this option is shared with
453 * that class, and on any updated site it already holds a plugin version
454 * (2.9.9 or later), so a bump of DB_VERSION would never fire.
455 * create_tables() widens the email code column through dbDelta (varchar
456 * 6 to 64, the code is stored hashed since 2.11.0) and purge_for_2_11_0()
457 * does what dbDelta cannot: it empties the trusted devices, which were
458 * identified by User-Agent until now (S1), and the pending email codes,
459 * stored in clear until now (S11). Every remembered device asks for the
460 * second factor once more after this update, and the changelog says so.
461 */
462 if ( version_compare( $db_version, '2.11.0', '<' ) ) {
463 $this->database->create_tables();
464 $this->database->purge_for_2_11_0();
465
466 update_option( 'vigilante_db_version', '2.11.0' );
467 }
468 }
469
470 /**
471 * Migration: Remove orphaned email fields from saved options
472 *
473 * v1.10.0 centralized notification recipients into email section.
474 * Old per-module notify_email fields and dead email section fields
475 * are removed to avoid confusion.
476 */
477 private function migrate_cleanup_email_fields() {
478 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
479 $modified = false;
480
481 // Remove orphaned fields from email section
482 $dead_email_keys = array( 'enabled', 'from_name', 'from_email', 'admin_email', 'send_activation_email', 'custom_email' );
483 if ( isset( $options['email'] ) && is_array( $options['email'] ) ) {
484 foreach ( $dead_email_keys as $key ) {
485 if ( array_key_exists( $key, $options['email'] ) ) {
486 unset( $options['email'][ $key ] );
487 $modified = true;
488 }
489 }
490 // Ensure new fields exist with defaults
491 if ( ! array_key_exists( 'send_to_admin_email', $options['email'] ) ) {
492 $options['email']['send_to_admin_email'] = true;
493 $modified = true;
494 }
495 if ( ! array_key_exists( 'additional_recipients', $options['email'] ) ) {
496 $options['email']['additional_recipients'] = '';
497 $modified = true;
498 }
499 }
500
501 // Remove notify_email from login_security
502 if ( isset( $options['login_security']['notify_email'] ) ) {
503 unset( $options['login_security']['notify_email'] );
504 $modified = true;
505 }
506
507 // Remove notify_email from file_integrity
508 if ( isset( $options['file_integrity']['notify_email'] ) ) {
509 unset( $options['file_integrity']['notify_email'] );
510 $modified = true;
511 }
512
513 if ( $modified ) {
514 update_option( Vigilante_Settings::OPTION_NAME, $options );
515 // Clear settings cache so the plugin uses clean data immediately
516 $this->settings->clear_cache();
517 }
518 }
519
520 /**
521 * Migration: Fix IP whitelist/blacklist entries merged into single line
522 *
523 * Prior to 1.2.3, sanitize_text_field() stripped newlines from textarea data,
524 * causing multiple IPs to be stored as a single space-separated string.
525 */
526 private function migrate_fix_ip_lists() {
527 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
528 $fixed = false;
529
530 foreach ( array( 'ip_whitelist', 'ip_blacklist' ) as $key ) {
531 if ( ! empty( $options['firewall'][ $key ] ) && is_array( $options['firewall'][ $key ] ) ) {
532 $new_list = array();
533 foreach ( $options['firewall'][ $key ] as $entry ) {
534 // Split entries that were joined by spaces
535 $parts = preg_split( '/\s+/', trim( $entry ) );
536 foreach ( $parts as $part ) {
537 $part = trim( $part );
538 if ( '' !== $part ) {
539 $new_list[] = $part;
540 }
541 }
542 }
543 if ( count( $new_list ) !== count( $options['firewall'][ $key ] ) ) {
544 $options['firewall'][ $key ] = array_unique( $new_list );
545 $fixed = true;
546 }
547 }
548 }
549
550 if ( $fixed ) {
551 update_option( Vigilante_Settings::OPTION_NAME, $options );
552 // Clear settings cache so changes take effect immediately
553 $this->settings->clear_cache();
554 }
555 }
556
557 /**
558 * Add admin menu page in last position
559 */
560 public function add_menu() {
561 $menu_title = __( 'Vigilant', 'vigilante' );
562
563 // Count pending approvals (separate concern, always red if present)
564 $pending_count = $this->get_pending_approvals_count();
565
566 // Get security issues with severity
567 $security_status = $this->get_security_status_for_badge();
568
569 // Total count for badge
570 $total_badge = $pending_count + $security_status['count'];
571
572 if ( $total_badge > 0 ) {
573 // Determine badge color:
574 // - Red (awaiting-mod): pending approvals OR critical modules disabled
575 // - Orange (update-plugins): only non-critical modules disabled
576 if ( $pending_count > 0 || $security_status['has_critical'] ) {
577 $badge_class = 'awaiting-mod';
578 } else {
579 $badge_class = 'update-plugins vigilante-badge-warning';
580 }
581
582 $menu_title .= sprintf(
583 ' <span class="%s count-%d"><span class="pending-count">%d</span></span>',
584 esc_attr( $badge_class ),
585 $total_badge,
586 $total_badge
587 );
588 }
589
590 add_menu_page(
591 __( 'Vigilant', 'vigilante' ),
592 $menu_title,
593 'manage_options',
594 'vigilante',
595 array( $this, 'render_settings_page' ),
596 'dashicons-shield',
597 999
598 );
599
600 // Rename auto-generated first submenu to "Dashboard"
601 add_submenu_page(
602 'vigilante',
603 __( 'Dashboard', 'vigilante' ),
604 __( 'Dashboard', 'vigilante' ),
605 'manage_options',
606 'vigilante',
607 array( $this, 'render_settings_page' )
608 );
609
610 // Security Audit shortcut
611 add_submenu_page(
612 'vigilante',
613 __( 'Security Audit', 'vigilante' ),
614 __( 'Security Audit', 'vigilante' ),
615 'manage_options',
616 'vigilante-activity-log',
617 array( $this, 'redirect_to_tab' )
618 );
619
620 // File Integrity shortcut
621 add_submenu_page(
622 'vigilante',
623 __( 'File Integrity', 'vigilante' ),
624 __( 'File Integrity', 'vigilante' ),
625 'manage_options',
626 'vigilante-file-integrity',
627 array( $this, 'redirect_to_tab' )
628 );
629 }
630
631 /**
632 * Redirect submenu shortcuts early, before headers are sent
633 */
634 public function redirect_submenu_shortcuts() {
635 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Just reading page slug for redirect
636 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
637
638 $tab_map = array(
639 'vigilante-activity-log' => 'activity-log',
640 'vigilante-file-integrity' => 'file-integrity',
641 );
642
643 if ( isset( $tab_map[ $page ] ) ) {
644 wp_safe_redirect( admin_url( 'admin.php?page=vigilante&tab=' . $tab_map[ $page ] ) );
645 exit;
646 }
647 }
648
649 /**
650 * Fallback redirect for submenu shortcuts (JS-based)
651 */
652 public function redirect_to_tab() {
653 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Just reading page slug for redirect
654 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
655
656 $tab_map = array(
657 'vigilante-activity-log' => 'activity-log',
658 'vigilante-file-integrity' => 'file-integrity',
659 );
660
661 if ( isset( $tab_map[ $page ] ) ) {
662 $url = admin_url( 'admin.php?page=vigilante&tab=' . $tab_map[ $page ] );
663 echo '<script>window.location.replace(' . wp_json_encode( esc_url( $url ) ) . ');</script>';
664 }
665 }
666
667 /**
668 * Highlight the correct submenu item based on active tab
669 *
670 * @param string $submenu_file Current submenu file.
671 * @return string
672 */
673 public function highlight_submenu_tab( $submenu_file ) {
674 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading tab for menu highlight only
675 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
676 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
677 $tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : '';
678
679 if ( 'vigilante' !== $page || empty( $tab ) ) {
680 return $submenu_file;
681 }
682
683 $tab_to_submenu = array(
684 'activity-log' => 'vigilante-activity-log',
685 'file-integrity' => 'vigilante-file-integrity',
686 );
687
688 if ( isset( $tab_to_submenu[ $tab ] ) ) {
689 return $tab_to_submenu[ $tab ];
690 }
691
692 return $submenu_file;
693 }
694
695 /**
696 * Set browser tab title to show plugin name and active tab
697 *
698 * Changes "Dashboard ‹ Site Name — WordPress" to
699 * "Vigilant > Dashboard ‹ Site Name — WordPress"
700 *
701 * @param string $admin_title Full admin title.
702 * @param string $title Page title from add_menu_page/add_submenu_page.
703 * @return string Modified title.
704 */
705 public function set_admin_page_title( $admin_title, $title ) {
706 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading page slug for title only
707 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
708
709 // Only modify on Vigilante pages
710 if ( 0 !== strpos( $page, 'vigilante' ) ) {
711 return $admin_title;
712 }
713
714 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
715 $tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'dashboard';
716
717 if ( isset( $this->tabs[ $tab ] ) ) {
718 $tab_label = $this->tabs[ $tab ];
719 } else {
720 $tab_label = __( 'Dashboard', 'vigilante' );
721 }
722
723 $plugin_title = __( 'Vigilant', 'vigilante' ) . ' &rsaquo; ' . $tab_label;
724
725 // Replace the original page title portion
726 return str_replace( $title, $plugin_title, $admin_title );
727 }
728
729 /**
730 * Get count of users pending approval
731 *
732 * @return int Count of pending users.
733 */
734 private function get_pending_approvals_count() {
735 // Prevent early execution before WordPress is ready
736 if ( ! did_action( 'plugins_loaded' ) ) {
737 return 0;
738 }
739
740 $registration_approval = $this->settings->get_section( 'user_security' );
741 $approval_settings = $registration_approval['registration_approval'] ?? array();
742
743 if ( empty( $approval_settings['enabled'] ) ) {
744 return 0;
745 }
746
747 // phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_key, WordPress.DB.SlowDBQuery.slow_db_query_meta_value -- Limited results in admin context.
748 $pending_users = get_users( array(
749 'meta_key' => 'vigilante_pending_approval',
750 'meta_value' => '1',
751 'fields' => 'ID',
752 ) );
753 // phpcs:enable WordPress.DB.SlowDBQuery.slow_db_query_meta_key, WordPress.DB.SlowDBQuery.slow_db_query_meta_value
754
755 return count( $pending_users );
756 }
757
758 /**
759 * Calculate comprehensive security score (0-100)
760 *
761 * @param array $options Plugin options.
762 * @return int Security score.
763 */
764 private function calculate_security_score( $options ) {
765 $score = 0;
766 $max_score = 0;
767
768 // Module scores (60 points total)
769 $module_weights = array(
770 'firewall' => 10,
771 'security_headers' => 8,
772 'login_security' => 10,
773 'rest_api_security' => 6,
774 'user_security' => 8,
775 'wp_hardening' => 8,
776 'file_integrity' => 5,
777 'activity_log' => 5,
778 );
779
780 foreach ( $module_weights as $module => $weight ) {
781 $max_score += $weight;
782 if ( ! empty( $options['modules'][ $module ] ) ) {
783 $score += $weight;
784 }
785 }
786
787 // Firewall details (10 points)
788 if ( ! empty( $options['modules']['firewall'] ) ) {
789 $firewall = $options['firewall'] ?? array();
790 $max_score += 10;
791
792 $firewall_checks = array(
793 'block_sql_injection',
794 'block_xss_attacks',
795 'block_bad_query_strings',
796 'block_file_inclusion',
797 'block_directory_traversal',
798 );
799
800 $firewall_enabled = 0;
801 foreach ( $firewall_checks as $check ) {
802 if ( ! empty( $firewall[ $check ] ) ) {
803 $firewall_enabled++;
804 }
805 }
806 $score += min( 10, $firewall_enabled * 2 );
807 }
808
809 // Login security details (10 points)
810 if ( ! empty( $options['modules']['login_security'] ) ) {
811 $login = $options['login_security'] ?? array();
812 $max_score += 10;
813
814 // Max attempts configured
815 if ( isset( $login['max_attempts'] ) && $login['max_attempts'] <= 5 ) {
816 $score += 3;
817 }
818 // XML-RPC disabled
819 if ( ! empty( $login['disable_xmlrpc'] ) ) {
820 $score += 3;
821 }
822 // 2FA enabled
823 if ( ! empty( $login['two_factor']['enabled'] ) ) {
824 $score += 4;
825 }
826 }
827
828 // Security headers details (10 points)
829 if ( ! empty( $options['modules']['security_headers'] ) ) {
830 $headers = $options['security_headers'] ?? array();
831 $max_score += 10;
832
833 if ( ! empty( $headers['x_frame_options'] ) ) {
834 $score += 2;
835 }
836 if ( ! empty( $headers['x_content_type_options'] ) ) {
837 $score += 2;
838 }
839 if ( ! empty( $headers['hsts']['enabled'] ) ) {
840 $score += 3;
841 }
842 if ( ! empty( $headers['csp']['enabled'] ) ) {
843 $score += 3;
844 }
845 }
846
847 // User security details (10 points)
848 if ( ! empty( $options['modules']['user_security'] ) ) {
849 $user = $options['user_security'] ?? array();
850 $max_score += 10;
851
852 if ( ! empty( $user['block_insecure_usernames'] ) ) {
853 $score += 3;
854 }
855 if ( ! empty( $user['force_strong_passwords'] ) ) {
856 $score += 3;
857 }
858 if ( ! empty( $user['password_expiration']['enabled'] ) ) {
859 $score += 2;
860 }
861 if ( ! empty( $user['email_verification']['enabled'] ) ) {
862 $score += 2;
863 }
864 }
865
866 // Audit alerts details (6 points) - only when Security Audit is on,
867 // because the alerting layer rides on top of the activity log. Leaving
868 // both alert legs off keeps these points unearned.
869 if ( ! empty( $options['modules']['activity_log'] ) ) {
870 $alerts = isset( $options['audit_alerts'] ) ? (array) $options['audit_alerts'] : array();
871 $max_score += 6;
872 if ( Vigilante_Audit_Alerts::immediate_is_active( $alerts ) ) {
873 $score += 3;
874 }
875 if ( Vigilante_Audit_Alerts::threshold_is_active( $alerts ) ) {
876 $score += 3;
877 }
878 }
879
880 // Environment checks (8 points) - penalize insecure server configuration
881 $max_score += 8;
882 $env_score = 8;
883
884 // WP_DEBUG active in production is a security risk (exposes paths, errors)
885 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
886 $env_score -= 5;
887 }
888
889 // Accounts with insecure usernames (targeted by brute force attacks)
890 $insecure_admins = $this->get_insecure_admin_usernames();
891 if ( ! empty( $insecure_admins ) ) {
892 $env_score -= 3;
893 }
894
895 $score += max( 0, $env_score );
896
897 return $max_score > 0 ? round( ( $score / $max_score ) * 100 ) : 0;
898 }
899
900 /**
901 * Get security recommendations based on current settings
902 *
903 * @param array $options Plugin options.
904 * @return array Array of recommendations.
905 */
906 private function get_security_recommendations( $options ) {
907 $recommendations = array();
908
909 // Critical: Firewall disabled
910 if ( empty( $options['modules']['firewall'] ) ) {
911 $recommendations[] = array(
912 'icon' => 'warning',
913 'priority' => 'critical',
914 'message' => __( 'Enable Firewall to protect against common attacks.', 'vigilante' ),
915 );
916 }
917
918 // Critical: Login security disabled
919 if ( empty( $options['modules']['login_security'] ) ) {
920 $recommendations[] = array(
921 'icon' => 'warning',
922 'priority' => 'critical',
923 'message' => __( 'Enable Login Security to prevent brute force attacks.', 'vigilante' ),
924 );
925 }
926
927 // High: Security headers disabled
928 if ( empty( $options['modules']['security_headers'] ) ) {
929 $recommendations[] = array(
930 'icon' => 'admin-generic',
931 'priority' => 'high',
932 'message' => __( 'Enable Security Headers to protect against clickjacking and XSS.', 'vigilante' ),
933 );
934 }
935
936 // High: User security disabled
937 if ( empty( $options['modules']['user_security'] ) ) {
938 $recommendations[] = array(
939 'icon' => 'admin-users',
940 'priority' => 'high',
941 'message' => __( 'Enable User Security to enforce password policies and username protection.', 'vigilante' ),
942 );
943 }
944
945 // High: 2FA not enabled (only if login security is active)
946 $login = $options['login_security'] ?? array();
947 if ( ! empty( $options['modules']['login_security'] ) && empty( $login['two_factor']['enabled'] ) ) {
948 $recommendations[] = array(
949 'icon' => 'shield',
950 'priority' => 'high',
951 'message' => __( 'Enable Two-Factor Authentication for enhanced login security.', 'vigilante' ),
952 'tab' => 'login',
953 );
954 }
955
956 // Medium: REST API security disabled
957 if ( empty( $options['modules']['rest_api_security'] ) ) {
958 $recommendations[] = array(
959 'icon' => 'rest-api',
960 'priority' => 'medium',
961 'message' => __( 'Enable REST API Security to control API access and prevent enumeration.', 'vigilante' ),
962 );
963 }
964
965 // Medium: WP Hardening disabled
966 if ( empty( $options['modules']['wp_hardening'] ) ) {
967 $recommendations[] = array(
968 'icon' => 'lock',
969 'priority' => 'medium',
970 'message' => __( 'Enable WP Hardening to remove version info and protect core files.', 'vigilante' ),
971 );
972 }
973
974 // Medium: File integrity disabled
975 if ( empty( $options['modules']['file_integrity'] ) ) {
976 $recommendations[] = array(
977 'icon' => 'media-text',
978 'priority' => 'medium',
979 'message' => __( 'Enable File Integrity to detect unauthorized file changes.', 'vigilante' ),
980 );
981 }
982
983 // Medium: Security Audit disabled
984 if ( empty( $options['modules']['activity_log'] ) ) {
985 $recommendations[] = array(
986 'icon' => 'list-view',
987 'priority' => 'medium',
988 'message' => __( 'Enable Security Audit to track security events.', 'vigilante' ),
989 );
990 }
991
992 // Low: XML-RPC enabled (only if login security is active)
993 if ( ! empty( $options['modules']['login_security'] ) && empty( $login['disable_xmlrpc'] ) ) {
994 $recommendations[] = array(
995 'icon' => 'info',
996 'priority' => 'low',
997 'message' => __( 'Disable XML-RPC if not needed (reduces attack surface).', 'vigilante' ),
998 'tab' => 'login',
999 );
1000 }
1001
1002 // Low: Strong passwords not enforced (only if user security is active)
1003 $user = $options['user_security'] ?? array();
1004 if ( ! empty( $options['modules']['user_security'] ) && empty( $user['force_strong_passwords'] ) ) {
1005 $recommendations[] = array(
1006 'icon' => 'admin-users',
1007 'priority' => 'low',
1008 'message' => __( 'Enforce strong passwords for all users.', 'vigilante' ),
1009 'tab' => 'users',
1010 );
1011 }
1012
1013 // High: WP_DEBUG active in production (regardless of Vigilante settings)
1014 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
1015 $recommendations[] = array(
1016 'icon' => 'warning',
1017 'priority' => 'high',
1018 'message' => __( 'WP_DEBUG is active. Debug mode exposes sensitive information and should be disabled in production.', 'vigilante' ),
1019 'tab' => 'wp-hardening',
1020 );
1021 }
1022
1023 // Low: Users with display name matching login username (only if user security active)
1024 if ( ! empty( $options['modules']['user_security'] ) ) {
1025 $exposed_users = $this->get_users_with_exposed_login();
1026 if ( ! empty( $exposed_users ) ) {
1027 $recommendations[] = array(
1028 'icon' => 'admin-users',
1029 'priority' => 'low',
1030 'message' => sprintf(
1031 /* translators: %s: Comma-separated list of usernames */
1032 __( 'These users have their login username as display name (publicly visible): %s', 'vigilante' ),
1033 implode( ', ', $exposed_users )
1034 ),
1035 'tab' => 'users',
1036 );
1037 }
1038 }
1039
1040 // High: Accounts with insecure usernames (regardless of module status)
1041 $insecure_admins = $this->get_insecure_admin_usernames();
1042 if ( ! empty( $insecure_admins ) ) {
1043 $recommendations[] = array(
1044 'icon' => 'warning',
1045 'priority' => 'high',
1046 'message' => sprintf(
1047 /* translators: %s: Comma-separated list of usernames */
1048 __( 'Insecure usernames detected: %s. These are commonly targeted in brute force attacks. Create new accounts with unique usernames and remove these.', 'vigilante' ),
1049 implode( ', ', $insecure_admins )
1050 ),
1051 );
1052 }
1053
1054 // Critical: Closed or removed plugins detected by the daily check.
1055 // Reads from the cached state map populated by Vigilante_Plugin_Status, so
1056 // there is no extra HTTP call here. Ignored slugs are filtered out so the
1057 // recommendation respects the user's per-slug Ignore decisions.
1058 if ( ! empty( $options['modules']['file_integrity'] ) && ! empty( $options['file_integrity']['check_closed_plugins'] ) ) {
1059 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
1060 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
1061 }
1062 $closed_checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
1063 $closed_active = $closed_checker->get_closed_plugins();
1064 if ( ! empty( $closed_active ) ) {
1065 $names = array();
1066 foreach ( $closed_active as $slug => $entry ) {
1067 $names[] = isset( $entry['name'] ) ? $entry['name'] : $slug;
1068 }
1069 $recommendations[] = array(
1070 'icon' => 'warning',
1071 'priority' => 'critical',
1072 'message' => sprintf(
1073 /* translators: 1: count, 2: comma-separated plugin names */
1074 _n(
1075 '%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.',
1076 '%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.',
1077 count( $closed_active ),
1078 'vigilante'
1079 ),
1080 count( $closed_active ),
1081 implode( ', ', $names )
1082 ),
1083 'tab' => 'file-integrity',
1084 );
1085 }
1086 }
1087
1088 // Medium: Security Audit is on but no audit alert is configured. The
1089 // alerting layer only makes sense while the activity log is running.
1090 if ( ! empty( $options['modules']['activity_log'] ) ) {
1091 $alerts = isset( $options['audit_alerts'] ) ? (array) $options['audit_alerts'] : array();
1092 if ( ! Vigilante_Audit_Alerts::has_active_alerts( $alerts ) ) {
1093 $recommendations[] = array(
1094 'icon' => 'email-alt',
1095 'priority' => 'medium',
1096 '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' ),
1097 'tab' => 'activity-log',
1098 );
1099 }
1100 }
1101
1102 // Sort by priority
1103 $priority_order = array( 'critical' => 0, 'high' => 1, 'medium' => 2, 'low' => 3 );
1104 usort( $recommendations, function( $a, $b ) use ( $priority_order ) {
1105 return ( $priority_order[ $a['priority'] ] ?? 99 ) - ( $priority_order[ $b['priority'] ] ?? 99 );
1106 } );
1107
1108 return $recommendations;
1109 }
1110
1111 /**
1112 * Get users whose display name matches their login username
1113 *
1114 * Limited to administrators and editors for performance and relevance.
1115 * Cached with transient to avoid repeated queries on every dashboard load.
1116 *
1117 * @return array Array of usernames with exposed login.
1118 */
1119 private function get_users_with_exposed_login() {
1120 $cache_key = 'vigilante_exposed_display_names';
1121 $cached = get_transient( $cache_key );
1122
1123 if ( false !== $cached ) {
1124 return $cached;
1125 }
1126
1127 $exposed = array();
1128 $users = get_users( array(
1129 'role__in' => array( 'administrator', 'editor' ),
1130 'fields' => array( 'ID', 'user_login', 'display_name' ),
1131 ) );
1132
1133 foreach ( $users as $user ) {
1134 if ( strcasecmp( $user->display_name, $user->user_login ) === 0 ) {
1135 $exposed[] = $user->user_login;
1136 }
1137 }
1138
1139 // Cache for 12 hours
1140 set_transient( $cache_key, $exposed, 12 * HOUR_IN_SECONDS );
1141
1142 return $exposed;
1143 }
1144
1145 /**
1146 * Get accounts with insecure usernames
1147 *
1148 * Checks for common default usernames that are targeted by brute force attacks.
1149 * Detects any user regardless of role (consistent with username creation blocking).
1150 * Uses WordPress object cache via get_user_by() so no transient needed.
1151 *
1152 * @return array Array of insecure usernames found.
1153 */
1154 private function get_insecure_admin_usernames() {
1155 $priority_usernames = array( 'admin', 'administrator', 'root', 'test', 'user', 'guest', 'info', 'sysadmin', 'webmaster' );
1156 $found = array();
1157
1158 foreach ( $priority_usernames as $username ) {
1159 $user = get_user_by( 'login', $username );
1160 if ( $user ) {
1161 $found[] = $username;
1162 }
1163 }
1164
1165 return $found;
1166 }
1167
1168 /**
1169 * Get security status for menu badge
1170 *
1171 * Returns count of disabled modules and whether there are critical issues.
1172 * Critical = Firewall or Login Security disabled.
1173 *
1174 * @return array Array with 'count' and 'has_critical'.
1175 */
1176 public function get_security_status_for_badge() {
1177 $options = $this->settings->get_all_options();
1178 $modules = $options['modules'] ?? array();
1179
1180 // Count disabled modules
1181 $disabled_count = 0;
1182 $has_critical = false;
1183
1184 // Critical modules - if disabled, badge is red
1185 $critical_modules = array( 'firewall', 'login_security' );
1186
1187 foreach ( $modules as $module => $enabled ) {
1188 // Handle both boolean and string values ('1', '0', true, false)
1189 $is_enabled = filter_var( $enabled, FILTER_VALIDATE_BOOLEAN );
1190
1191 if ( ! $is_enabled ) {
1192 $disabled_count++;
1193
1194 // Check if this is a critical module
1195 if ( in_array( $module, $critical_modules, true ) ) {
1196 $has_critical = true;
1197 }
1198 }
1199 }
1200
1201 return array(
1202 'count' => $disabled_count,
1203 'has_critical' => $has_critical,
1204 );
1205 }
1206
1207 /**
1208 * Get count of security issues for menu badge (deprecated, use get_security_status_for_badge)
1209 *
1210 * @return int Count of critical/high issues.
1211 */
1212 public function get_security_issues_count() {
1213 $status = $this->get_security_status_for_badge();
1214 return $status['count'];
1215 }
1216
1217 /**
1218 * Register settings
1219 */
1220 public function register_settings() {
1221 register_setting(
1222 'vigilante_options',
1223 Vigilante_Settings::OPTION_NAME,
1224 array( $this->settings, 'validate_options' )
1225 );
1226 }
1227
1228 /**
1229 * Index behind the settings search box.
1230 *
1231 * Each entry points at one settings row. The search matches on the label,
1232 * on its English original and on 'keywords', which are extra terms someone
1233 * might type instead of the label itself.
1234 *
1235 * Those keywords are wrapped in _x() with the context "settings search
1236 * keywords" so every locale can supply its own: the source strings are in
1237 * English, and a Spanish user typing "contrasena" or a German one typing
1238 * "Kennwort" only reaches the password settings if that locale translated
1239 * them. Translators can add, drop or replace terms freely, one per space;
1240 * they are never displayed, only matched against what the user types.
1241 *
1242 * The list is maintained by hand, so a new settings row needs an entry here
1243 * or it cannot be found. It had drifted to 68 of 131 rows before 2.9.7.
1244 *
1245 * @return array
1246 */
1247 private function get_search_index() {
1248 return array(
1249 // Firewall - Main
1250 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' ) ),
1251 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' ) ),
1252 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' ) ),
1253 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' ) ),
1254 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' ) ),
1255 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' ) ),
1256 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' ) ),
1257 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' ) ),
1258 // Firewall - Server Protection
1259 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' ) ),
1260 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' ) ),
1261 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' ) ),
1262 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' ) ),
1263 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' ) ),
1264 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' ) ),
1265 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' ) ),
1266 // Security Headers
1267 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' ) ),
1268 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' ) ),
1269 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' ) ),
1270 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' ) ),
1271 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' ) ),
1272 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' ) ),
1273 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' ) ),
1274 // Security Headers - Cross-Origin Policies
1275 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' ) ),
1276 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' ) ),
1277 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' ) ),
1278 // Login Security
1279 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' ) ),
1280 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' ) ),
1281 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' ) ),
1282 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' ) ),
1283 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' ) ),
1284 // REST API
1285 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' ) ),
1286 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' ) ),
1287 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' ) ),
1288 // User Security
1289 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' ) ),
1290 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' ) ),
1291 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' ) ),
1292 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' ) ),
1293 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' ) ),
1294 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' ) ),
1295 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' ) ),
1296 // WP Hardening
1297 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' ) ),
1298 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' ) ),
1299 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' ) ),
1300 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' ) ),
1301 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' ) ),
1302 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' ) ),
1303 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' ) ),
1304 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' ) ),
1305 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' ) ),
1306 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' ) ),
1307 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' ) ),
1308 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' ) ),
1309 // File Integrity
1310 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' ) ),
1311 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' ) ),
1312 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' ) ),
1313 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' ) ),
1314 // Security Audit
1315 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' ) ),
1316 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' ) ),
1317 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' ) ),
1318 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' ) ),
1319 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' ) ),
1320 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' ) ),
1321 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' ) ),
1322 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' ) ),
1323 // Settings & Tools
1324 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' ) ),
1325 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' ) ),
1326 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' ) ),
1327 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' ) ),
1328 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' ) ),
1329 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' ) ),
1330 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' ) ),
1331 // Entradas anadidas en la 2.9.7 tras comprobar que el indice cubria 68 de
1332 // las 131 filas de ajustes: buscar XML-RPC, por ejemplo, no devolvia nada.
1333 // El indice se mantiene a mano, asi que al anadir una fila de ajustes hay
1334 // que anadirla tambien aqui.
1335 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' ) ),
1336 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' ) ),
1337 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' ) ),
1338 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' ) ),
1339 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' ) ),
1340 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' ) ),
1341 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' ) ),
1342 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' ) ),
1343 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' ) ),
1344 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' ) ),
1345 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' ) ),
1346 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' ) ),
1347 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' ) ),
1348 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' ) ),
1349 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' ) ),
1350 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' ) ),
1351 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' ) ),
1352 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' ) ),
1353 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' ) ),
1354 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' ) ),
1355 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' ) ),
1356 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' ) ),
1357 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' ) ),
1358 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' ) ),
1359 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' ) ),
1360 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' ) ),
1361 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' ) ),
1362 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' ) ),
1363 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' ) ),
1364 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' ) ),
1365 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' ) ),
1366 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' ) ),
1367 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' ) ),
1368 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' ) ),
1369 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' ) ),
1370 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' ) ),
1371 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' ) ),
1372 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' ) ),
1373 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' ) ),
1374 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' ) ),
1375 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' ) ),
1376 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' ) ),
1377 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' ) ),
1378 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' ) ),
1379 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' ) ),
1380 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' ) ),
1381 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' ) ),
1382 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' ) ),
1383 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' ) ),
1384 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' ) ),
1385 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' ) ),
1386 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' ) ),
1387 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' ) ),
1388 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' ) ),
1389 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' ) ),
1390 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' ) ),
1391 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' ) ),
1392 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' ) ),
1393 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' ) ),
1394 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' ) ),
1395 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' ) ),
1396 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' ) ),
1397 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' ) ),
1398 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' ) ),
1399 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' ) ),
1400 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' ) ),
1401 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' ) ),
1402 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' ) ),
1403 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' ) ),
1404 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' ) ),
1405 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' ) ),
1406 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' ) ),
1407 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' ) ),
1408 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' ) ),
1409 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' ) ),
1410 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' ) ),
1411 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' ) ),
1412 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' ) ),
1413 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' ) ),
1414 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' ) ),
1415 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' ) ),
1416 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' ) ),
1417 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' ) ),
1418 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' ) ),
1419 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' ) ),
1420 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' ) ),
1421 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' ) ),
1422 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' ) ),
1423 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' ) ),
1424 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' ) ),
1425 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' ) ),
1426 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' ) ),
1427 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' ) ),
1428 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' ) ),
1429 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' ) ),
1430 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' ) ),
1431 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' ) ),
1432 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' ) ),
1433 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' ) ),
1434 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' ) ),
1435 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' ) ),
1436 );
1437 }
1438
1439 /**
1440 * Enqueue admin assets
1441 *
1442 * @param string $hook Current admin page.
1443 */
1444 public function enqueue_assets( $hook ) {
1445 // toplevel_page_vigilante for top-level menu page
1446 if ( 'toplevel_page_vigilante' !== $hook ) {
1447 return;
1448 }
1449
1450 wp_enqueue_style(
1451 'vigilante-admin',
1452 VIGILANTE_ASSETS_URL . 'css/admin.css',
1453 array(),
1454 VIGILANTE_VERSION
1455 );
1456
1457 wp_enqueue_script(
1458 'vigilante-admin',
1459 VIGILANTE_ASSETS_URL . 'js/admin.js',
1460 array( 'jquery' ),
1461 VIGILANTE_VERSION,
1462 true
1463 );
1464
1465 wp_localize_script( 'vigilante-admin', 'vigilanteAdmin', array(
1466 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
1467 'nonce' => wp_create_nonce( 'vigilante_admin_nonce' ),
1468 'currentUserId' => get_current_user_id(),
1469 'logoutUrl' => wp_logout_url( wp_login_url() ),
1470 'adminUrl' => admin_url( 'admin.php?page=vigilante' ),
1471 'searchIndex' => $this->get_search_index(),
1472 // The scan repaints this table from JavaScript, so the same gate
1473 // has to travel with it or half the screen keeps the dead button.
1474 'approvalLocked' => $this->critical_approval_locked(),
1475 'underAttack' => array(
1476 'active' => ( new Vigilante_Under_Attack( $this->settings, $this->activity_log ) )->is_active(),
1477 'remaining' => ( new Vigilante_Under_Attack( $this->settings, $this->activity_log ) )->get_remaining_time(),
1478 ),
1479 'strings' => array(
1480 'saving' => __( 'Saving...', 'vigilante' ),
1481 'sendingTest' => __( 'Sending...', 'vigilante' ),
1482 'saved' => __( 'Settings saved', 'vigilante' ),
1483 'error' => __( 'Error saving settings', 'vigilante' ),
1484 'confirm' => __( 'Are you sure?', 'vigilante' ),
1485 'scanning' => __( 'Scanning...', 'vigilante' ),
1486 'scanComplete' => __( 'Scan complete', 'vigilante' ),
1487 'loading' => __( 'Loading...', 'vigilante' ),
1488 'searching' => __( 'Searching...', 'vigilante' ),
1489 'noUsersFound' => __( 'No users found', 'vigilante' ),
1490 'searchError' => __( 'Error searching users', 'vigilante' ),
1491 'sending' => __( 'Sending...', 'vigilante' ),
1492 'sendNotification' => __( 'Send notification now', 'vigilante' ),
1493 'notificationsSent' => __( 'notifications sent', 'vigilante' ),
1494 'skipped' => __( 'skipped', 'vigilante' ),
1495 'failed' => __( 'failed', 'vigilante' ),
1496 'customConfig' => __( 'Custom Configuration', 'vigilante' ),
1497 // Header tester strings
1498 'testHeaders' => __( 'Test Headers', 'vigilante' ),
1499 'testing' => __( 'Testing...', 'vigilante' ),
1500 'score' => __( 'Score', 'vigilante' ),
1501 'enabledHeaders' => __( 'Enabled headers', 'vigilante' ),
1502 'missingHeaders' => __( 'Missing headers', 'vigilante' ),
1503 'warnings' => __( 'Warnings', 'vigilante' ),
1504 // File integrity scan results strings
1505 'scanResults' => __( 'Scan Results', 'vigilante' ),
1506 'ok' => __( 'OK', 'vigilante' ),
1507 'modified' => __( 'Modified', 'vigilante' ),
1508 'suspicious' => __( 'Suspicious', 'vigilante' ),
1509 'totalScanned' => __( 'Total Scanned', 'vigilante' ),
1510 'suspiciousFiles' => __( 'Suspicious Files', 'vigilante' ),
1511 'suspiciousWarning' => __( 'These files may contain malicious code or are in unexpected locations. Review immediately!', 'vigilante' ),
1512 'file' => __( 'File', 'vigilante' ),
1513 'reason' => __( 'Reason', 'vigilante' ),
1514 'type' => __( 'Type', 'vigilante' ),
1515 'unknown' => __( 'Unknown', 'vigilante' ),
1516 'modifiedFiles' => __( 'Modified Files', 'vigilante' ),
1517 'modifiedDescription' => __( 'These files (apparently) differ from the original WordPress or plugin versions.', 'vigilante' ),
1518 'extraFiles' => __( 'Extra Files', 'vigilante' ),
1519 'extra' => __( 'Extra', 'vigilante' ),
1520 'ignored' => __( 'Ignored', 'vigilante' ),
1521 'extraDescription' => __( 'PHP files found in plugins or themes that are not part of the original distribution from WordPress.org.', 'vigilante' ),
1522 'actions' => __( 'Actions', 'vigilante' ),
1523 'ignore' => __( 'Ignore', 'vigilante' ),
1524 'ignoring' => __( 'Ignoring...', 'vigilante' ),
1525 'fileIgnored' => __( 'File added to ignored list.', 'vigilante' ),
1526 'fileUnignored' => __( 'File removed from ignored list.', 'vigilante' ),
1527 'confirmClearIgnored' => __( 'Remove all files from the ignored list? They will appear in scan results again.', 'vigilante' ),
1528 'ignoredCleared' => __( 'Ignored files list cleared. Page will reload...', 'vigilante' ),
1529 'selectAll' => __( 'Select all', 'vigilante' ),
1530 'bulkIgnoreSelected' => __( 'Ignore selected', 'vigilante' ),
1531 'bulkUnignoreSelected'=> __( 'Stop ignoring selected', 'vigilante' ),
1532 'bulkNoSelection' => __( 'Select at least one file first.', 'vigilante' ),
1533 'bulkConfirmIgnore' => __( 'Ignore the selected files? They will be hidden from future scan results until you remove them from the ignored list.', 'vigilante' ),
1534 'bulkConfirmUnignore' => __( 'Remove the selected files from the ignored list? They will appear in scan results again.', 'vigilante' ),
1535 'bulkProcessing' => __( 'Processing...', 'vigilante' ),
1536 /* translators: %d: number of files selected for bulk action. */
1537 'bulkSelectedCount' => __( '%d selected', 'vigilante' ),
1538 'allClear' => __( 'All files verified - no issues found!', 'vigilante' ),
1539 'criticalConfigTitle' => __( 'Critical config files modified', 'vigilante' ),
1540 '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' ),
1541 'approve' => __( 'Approve', 'vigilante' ),
1542 'approving' => __( 'Approving...', 'vigilante' ),
1543 'approvalLockedNotice' => $this->critical_approval_notice(),
1544 'criticalApproved' => __( 'Change approved. Next scan will use the current state as baseline.', 'vigilante' ),
1545 'reviewChanges' => __( 'Review changes', 'vigilante' ),
1546 'hideChanges' => __( 'Hide changes', 'vigilante' ),
1547 'changes' => __( 'Changes', 'vigilante' ),
1548 'diffUnavailable' => __( 'Diff not available for this file (baseline was created before diff tracking was added). Approve to enable diff on future changes.', 'vigilante' ),
1549 'diffEmpty' => __( 'No line-level changes detected (may be whitespace or reordering).', 'vigilante' ),
1550 'diffLines' => __( 'lines', 'vigilante' ),
1551 // Under Attack mode strings
1552 'underAttackConfirmActivate' => __( 'Activate Under Attack mode? All visitors will see a verification page for the next 4 hours.', 'vigilante' ),
1553 'underAttackConfirmDeactivate' => __( 'Deactivate Under Attack mode?', 'vigilante' ),
1554 'underAttackActivating' => __( 'Activating...', 'vigilante' ),
1555 'underAttackDeactivating' => __( 'Deactivating...', 'vigilante' ),
1556 // Database backup strings
1557 'dbBackupDownloading' => __( 'Generating backup...', 'vigilante' ),
1558 'dbBackupNoTables' => __( 'Please select at least one table.', 'vigilante' ),
1559 'dbBackupSuccess' => __( 'Database backup downloaded successfully.', 'vigilante' ),
1560 // Firewall unblock
1561 'confirmUnblockIp' => __( 'Unblock this IP from firewall rate limiting?', 'vigilante' ),
1562 // Database prefix strings
1563 'dbPrefixConfirm' => __( 'This operation will change your database prefix. It is irreversible. Make sure you have a current database backup before proceeding.', 'vigilante' ),
1564 'dbPrefixChanging' => __( 'Changing prefix...', 'vigilante' ),
1565 'dbPrefixSuccess' => __( 'Database prefix changed successfully. The page will reload now.', 'vigilante' ),
1566 'dbPrefixCheckbox' => __( 'You must confirm that you have a database backup.', 'vigilante' ),
1567 /* translators: 1: Hours, 2: Minutes */
1568 'underAttackRemaining' => __( '%1$dh %2$dm remaining', 'vigilante' ),
1569 'underAttackLabel' => __( 'Under Attack', 'vigilante' ),
1570 'standardLabel' => __( 'Standard', 'vigilante' ),
1571 'maximumLabel' => __( 'Maximum Security', 'vigilante' ),
1572 'deactivate' => __( 'Deactivate', 'vigilante' ),
1573 'underAttackActivate' => __( 'Activate for 4 hours', 'vigilante' ),
1574 // Settings strings
1575 'saveSettings' => __( 'Save Settings', 'vigilante' ),
1576 'settingsResetDefaults' => __( 'Settings reset to defaults.', 'vigilante' ),
1577 'confirmOverwrite' => __( 'This will overwrite your current settings.', 'vigilante' ),
1578 'importFailed' => __( 'Could not import settings. Check the file and try again.', 'vigilante' ),
1579 /* translators: 1: tests passed, 2: total tests in this category */
1580 'testsCounter' => __( '%1$d/%2$d tests', 'vigilante' ),
1581 'confirmResetAll' => __( 'This will reset ALL settings to defaults.', 'vigilante' ),
1582 'couldNotDetermineSection' => __( 'Could not determine section.', 'vigilante' ),
1583 'confirmResetSection' => __( 'Reset this section to default values? This cannot be undone.', 'vigilante' ),
1584 'sectionResetDefaults' => __( 'Section reset to defaults.', 'vigilante' ),
1585 /* translators: %s: preset name */
1586 'confirmApplyPreset' => __( 'Apply the "%s" preset?', 'vigilante' ),
1587 // Scan strings
1588 'scanFailed' => __( 'Scan failed', 'vigilante' ),
1589 /* translators: %s: error message */
1590 'scanError' => __( 'Scan error: %s', 'vigilante' ),
1591 'runScanNow' => __( 'Run Scan Now', 'vigilante' ),
1592 'confirmClearScan' => __( 'Are you sure you want to clear all scan results?', 'vigilante' ),
1593 'clearing' => __( 'Clearing...', 'vigilante' ),
1594 'scanResultsCleared' => __( 'Scan results cleared. Page will reload...', 'vigilante' ),
1595 'failedClearResults' => __( 'Failed to clear results', 'vigilante' ),
1596 /* translators: %s: error message */
1597 'ajaxError' => __( 'AJAX Error: %s', 'vigilante' ),
1598 // Activity log popup strings
1599 'logRequest' => __( 'Request', 'vigilante' ),
1600 'logDate' => __( 'Date', 'vigilante' ),
1601 'logMethod' => __( 'Method', 'vigilante' ),
1602 'logType' => __( 'Type', 'vigilante' ),
1603 'logAction' => __( 'Action', 'vigilante' ),
1604 'logSeverity' => __( 'Severity', 'vigilante' ),
1605 'logMessage' => __( 'Message', 'vigilante' ),
1606 'logRequestUri' => __( 'Address', 'vigilante' ),
1607 'logClient' => __( 'Client', 'vigilante' ),
1608 'logUser' => __( 'User', 'vigilante' ),
1609 'logIpAddress' => __( 'IP Address', 'vigilante' ),
1610 'logUserAgent' => __( 'User Agent', 'vigilante' ),
1611 'logIpLabel' => __( 'IP:', 'vigilante' ),
1612 'logUaLabel' => __( 'UA:', 'vigilante' ),
1613 'logWhitelist' => __( 'Whitelist', 'vigilante' ),
1614 'logBlacklist' => __( 'Blacklist', 'vigilante' ),
1615 'logInWhitelist' => __( 'In whitelist', 'vigilante' ),
1616 'logInBlacklist' => __( 'In blacklist', 'vigilante' ),
1617 'logAdded' => __( 'Added!', 'vigilante' ),
1618 'logErrorAddingToList' => __( 'Error adding to list', 'vigilante' ),
1619 'logRequestFailed' => __( 'Request failed', 'vigilante' ),
1620 // Activity log table strings
1621 'noLogEntries' => __( 'No log entries found.', 'vigilante' ),
1622 'view' => __( 'View', 'vigilante' ),
1623 'confirmClearLogs' => __( 'This will delete all audit logs.', 'vigilante' ),
1624 // Export logs strings
1625 'exporting' => __( 'Exporting...', 'vigilante' ),
1626 /* translators: %d: number of entries */
1627 'logsExported' => __( 'Logs exported (%d entries)', 'vigilante' ),
1628 'noLogsToExport' => __( 'No logs to export', 'vigilante' ),
1629 'exportFailed' => __( 'Export failed', 'vigilante' ),
1630 'exportLogs' => __( 'Export Logs', 'vigilante' ),
1631 // Backup strings
1632 'backupCreated' => __( 'Backup created successfully.', 'vigilante' ),
1633 'createBackupNow' => __( 'Download Backup', 'vigilante' ),
1634 'downloadBackup' => __( 'Download Backup (.zip)', 'vigilante' ),
1635 /* translators: %d: number of tables */
1636 'tablesCount' => __( '%d tables', 'vigilante' ),
1637 /* translators: 1: table count, 2: human-readable size */
1638 'dbTablesTotal' => __( '%1$d tables total (%2$s)', 'vigilante' ),
1639 /* translators: 1: selected count, 2: human-readable size */
1640 'dbTablesSelected' => __( '%1$d tables selected (%2$s)', 'vigilante' ),
1641 // Settings search strings
1642 'searchNoResults' => __( 'No matching settings found.', 'vigilante' ),
1643 /* translators: %d: number of results that did not fit in the list. */
1644 'searchMoreResults' => __( '%d more results. Refine the search to see them.', 'vigilante' ),
1645 'searchInTab' => __( 'in', 'vigilante' ),
1646 // Modules string
1647 /* translators: 1: enabled count, 2: total count */
1648 'modulesEnabled' => __( '%1$d / %2$d modules enabled', 'vigilante' ),
1649 // Activity log label maps for JS rendering
1650 'eventTypeLabels' => array(
1651 'login' => __( 'Login', 'vigilante' ),
1652 'user' => __( 'User', 'vigilante' ),
1653 'content' => __( 'Content', 'vigilante' ),
1654 'plugin' => __( 'Plugin', 'vigilante' ),
1655 'theme' => __( 'Theme', 'vigilante' ),
1656 'settings' => __( 'Settings', 'vigilante' ),
1657 'comment' => __( 'Comment', 'vigilante' ),
1658 'media' => __( 'Media', 'vigilante' ),
1659 'firewall' => __( 'Firewall', 'vigilante' ),
1660 'file' => __( 'File', 'vigilante' ),
1661 'security' => __( 'Security', 'vigilante' ),
1662 'system' => __( 'System', 'vigilante' ),
1663 ),
1664 'severityLabels' => array(
1665 'info' => __( 'Info', 'vigilante' ),
1666 'warning' => __( 'Warning', 'vigilante' ),
1667 'critical' => __( 'Critical', 'vigilante' ),
1668 ),
1669 // Password reset strings
1670 'noUsersFoundSearch' => __( 'No users found', 'vigilante' ),
1671 /* translators: %d: number of users */
1672 'confirmForceReset' => __( 'Force password reset for %d user(s)? A password reset email will be sent to each user.', 'vigilante' ),
1673 'warningResettingSelf' => __( 'WARNING: You are including yourself. Your session will end and you will need to set a new password.', 'vigilante' ),
1674 'processing' => __( 'Processing...', 'vigilante' ),
1675 'anErrorOccurred' => __( 'An error occurred', 'vigilante' ),
1676 'forceResetSelected' => __( 'Force Reset for Selected Users', 'vigilante' ),
1677 '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' ),
1678 'warningResettingSelfAll' => __( 'WARNING: You are including yourself. Your session will end immediately.', 'vigilante' ),
1679 'forceResetAll' => __( 'Force Reset for ALL Users', 'vigilante' ),
1680 // Role-based password reset strings
1681 /* translators: %d: number of users */
1682 'confirmForceResetByRole' => __( 'Force password reset for %d user(s) with the selected roles? A password reset email will be sent to each user.', 'vigilante' ),
1683 'noRolesSelected' => __( 'Please select at least one role.', 'vigilante' ),
1684 'forceResetByRole' => __( 'Force Reset for Selected Roles', 'vigilante' ),
1685 // User approval strings
1686 'confirmApprove' => __( 'Approve this user?', 'vigilante' ),
1687 'approve' => __( 'Approve', 'vigilante' ),
1688 'rejectReason' => __( 'Enter rejection reason (optional):', 'vigilante' ),
1689 'reject' => __( 'Reject', 'vigilante' ),
1690 'noPending' => __( 'No pending registrations.', 'vigilante' ),
1691 // Session management strings
1692 'confirmRevoke' => __( 'Revoke this session?', 'vigilante' ),
1693 'confirmRevokeAll' => __( 'Revoke all other sessions?', 'vigilante' ),
1694 'revokeOthers' => __( 'Revoke All Other Sessions', 'vigilante' ),
1695 'confirmRevokeAllUser' => __( 'Revoke ALL sessions for this user? They will be logged out everywhere.', 'vigilante' ),
1696 'sessionsFor' => __( 'Sessions for:', 'vigilante' ),
1697 'noSessions' => __( 'No active sessions', 'vigilante' ),
1698 'revoke' => __( 'Revoke', 'vigilante' ),
1699 'noUsers' => __( 'No users found', 'vigilante' ),
1700 // Time ago strings
1701 'timeYear' => __( 'year', 'vigilante' ),
1702 'timeYears' => __( 'years', 'vigilante' ),
1703 'timeMonth' => __( 'month', 'vigilante' ),
1704 'timeMonths' => __( 'months', 'vigilante' ),
1705 'timeDay' => __( 'day', 'vigilante' ),
1706 'timeDays' => __( 'days', 'vigilante' ),
1707 'timeHour' => __( 'hour', 'vigilante' ),
1708 'timeHours' => __( 'hours', 'vigilante' ),
1709 'timeMinute' => __( 'minute', 'vigilante' ),
1710 'timeMinutes' => __( 'minutes', 'vigilante' ),
1711 /* translators: %1$d: count, %2$s: time unit */
1712 'timeAgo' => __( '%1$d %2$s ago', 'vigilante' ),
1713 'justNow' => __( 'Just now', 'vigilante' ),
1714 // Pagination strings
1715 /* translators: 1: first item number, 2: last item number, 3: total items */
1716 'paginationOf' => __( '%1$d–%2$d of %3$d', 'vigilante' ),
1717 'paginationEmpty' => __( '0 items', 'vigilante' ),
1718 // Security Analyzer strings
1719 'analyzerScanNow' => __( 'Scan now', 'vigilante' ),
1720 'analyzerScanning' => __( 'Scanning…', 'vigilante' ),
1721 'analyzerFastPhase' => __( 'Running fast checks…', 'vigilante' ),
1722 'analyzerSlowPhase' => __( 'Running remote checks…', 'vigilante' ),
1723 'analyzerScanComplete' => __( 'Security scan complete.', 'vigilante' ),
1724 'analyzerScanFailed' => __( 'Security scan failed.', 'vigilante' ),
1725 'analyzerShowDetails' => __( 'Show detailed breakdown', 'vigilante' ),
1726 'analyzerHideDetails' => __( 'Hide detailed breakdown', 'vigilante' ),
1727 'analyzerGoToSetting' => __( 'Go to setting', 'vigilante' ),
1728 'analyzerNoData' => __( 'No data yet — run a scan to populate this category.', 'vigilante' ),
1729 'analyzerJustNow' => __( 'just now', 'vigilante' ),
1730 'analyzerAgo' => __( 'ago', 'vigilante' ),
1731 'analyzerSettingsSaved' => __( 'Analyzer settings saved.', 'vigilante' ),
1732 'analyzerLastScanJustNow' => __( 'Last scan just now', 'vigilante' ),
1733 'analyzerQualityExcellent' => __( 'Excellent', 'vigilante' ),
1734 'analyzerQualityGood' => __( 'Good', 'vigilante' ),
1735 'analyzerQualityFair' => __( 'Fair', 'vigilante' ),
1736 'analyzerQualityPoor' => __( 'Poor', 'vigilante' ),
1737 'analyzerQualityCritical' => __( 'Critical', 'vigilante' ),
1738 'analyzerPts' => __( 'pts', 'vigilante' ),
1739 'analyzerLearnMore' => __( 'Learn more', 'vigilante' ),
1740 'analyzerInfoAllClear' => __( 'All clear', 'vigilante' ),
1741 /* translators: %d: number of findings in an info-only category */
1742 'analyzerInfoFindings' => __( '%d findings', 'vigilante' ),
1743 ),
1744 ) );
1745
1746 // 2FA Admin assets
1747 wp_enqueue_style(
1748 'vigilante-2fa-admin',
1749 VIGILANTE_ASSETS_URL . 'css/two-factor-admin.css',
1750 array( 'vigilante-admin' ),
1751 VIGILANTE_VERSION
1752 );
1753
1754 wp_enqueue_script(
1755 'vigilante-2fa-admin',
1756 VIGILANTE_ASSETS_URL . 'js/two-factor-admin.js',
1757 array( 'jquery', 'vigilante-admin' ),
1758 VIGILANTE_VERSION,
1759 true
1760 );
1761 }
1762
1763 /**
1764 * Show admin notices
1765 */
1766 public function show_admin_notices() {
1767 // Activation notice
1768 if ( get_transient( 'vigilante_activated' ) ) {
1769 ?>
1770 <div class="notice notice-success is-dismissible vigilante-activation-notice">
1771 <p>
1772 <span class="dashicons dashicons-shield vigilante-notice-icon"></span>
1773 <strong><?php esc_html_e( 'Vigilant activated successfully!', 'vigilante' ); ?></strong>
1774 <?php esc_html_e( 'Security protection is now active.', 'vigilante' ); ?>
1775 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante' ) ); ?>">
1776 <?php esc_html_e( 'Configure settings', 'vigilante' ); ?>
1777 </a>
1778 </p>
1779 </div>
1780 <?php
1781 delete_transient( 'vigilante_activated' );
1782 }
1783
1784 // Under Attack mode notice (non-dismissible, shown on all admin pages)
1785 $ua_status = get_option( Vigilante_Under_Attack::OPTION_NAME, array() );
1786 if ( ! empty( $ua_status['active'] ) ) {
1787 $ua_remaining = ( $ua_status['activated_at'] + $ua_status['duration'] ) - time();
1788 if ( $ua_remaining > 0 ) {
1789 $ua_hours = floor( $ua_remaining / 3600 );
1790 $ua_mins = floor( ( $ua_remaining % 3600 ) / 60 );
1791 $dashboard_url = admin_url( 'admin.php?page=vigilante' );
1792 ?>
1793 <div class="notice notice-warning vigilante-ua-notice">
1794 <p>
1795 <span class="dashicons dashicons-shield"></span>
1796 <strong><?php esc_html_e( 'Under Attack mode is active', 'vigilante' ); ?></strong>
1797 &mdash;
1798 <?php
1799 printf(
1800 /* translators: 1: Hours, 2: Minutes */
1801 esc_html__( '%1$dh %2$dm remaining.', 'vigilante' ),
1802 absint( $ua_hours ),
1803 absint( $ua_mins )
1804 );
1805 ?>
1806 <a href="<?php echo esc_url( $dashboard_url ); ?>">
1807 <?php esc_html_e( 'Go to Vigilant dashboard', 'vigilante' ); ?>
1808 </a>
1809 </p>
1810 <p>
1811 <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>
1812 </p>
1813 <?php
1814 // The cache-bypass rules could not be written (a host where
1815 // WordPress cannot write files by itself, a held lock, a
1816 // failed read-back): show them, so they can be added by hand.
1817 $ua_instance = new Vigilante_Under_Attack( $this->settings, $this->activity_log );
1818 if ( $ua_instance->cache_rules_missing() ) :
1819 ?>
1820 <p>
1821 <strong><?php esc_html_e( 'The cache-bypass rules could not be written to your .htaccess.', 'vigilante' ); ?></strong>
1822 <?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' ); ?>
1823 </p>
1824 <textarea readonly rows="9" class="large-text code" onclick="this.select();"><?php echo esc_textarea( Vigilante_Under_Attack::get_cache_bypass_block() ); ?></textarea>
1825 <?php endif; ?>
1826 </div>
1827 <?php
1828 }
1829 }
1830
1831 // Proxy/CDN detection: if IP detection is set to "direct" but requests
1832 // arrive with a forwarded-for header carrying a different valid IP, the
1833 // site is very likely behind a proxy/CDN that has not been declared, so
1834 // the firewall is seeing the proxy IP for every visitor. Guide the admin.
1835 //
1836 // Two deliberate silencers (2.9.2):
1837 // - A loopback forwarded IP (::1 / 127.x) means the person browsing IS
1838 // the machine itself: that only happens in local development stacks
1839 // (Local's nginx router, Docker...), never behind a production
1840 // proxy/CDN, so the notice would be pure noise there.
1841 // - The notice is dismissible and the dismissal persists site-wide via
1842 // the vigilante_dismissed_notices option (the admin evaluated it and
1843 // decided; nagging forever helps nobody).
1844 $dismissed_notices = get_option( 'vigilante_dismissed_notices', array() );
1845 if (
1846 current_user_can( 'manage_options' )
1847 && '' === Vigilante_IP_Utils::trusted_proxy_header()
1848 && ! isset( $dismissed_notices['proxy_detection'] )
1849 ) {
1850 $remote = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '';
1851 $detected = '';
1852 foreach ( Vigilante_IP_Utils::trusted_header_map() as $proxy_label => $server_key ) {
1853 if ( empty( $_SERVER[ $server_key ] ) ) {
1854 continue;
1855 }
1856 $candidate = sanitize_text_field( wp_unslash( $_SERVER[ $server_key ] ) );
1857 if ( false !== strpos( $candidate, ',' ) ) {
1858 $parts = explode( ',', $candidate );
1859 $candidate = trim( $parts[0] );
1860 }
1861 if ( ! filter_var( $candidate, FILTER_VALIDATE_IP ) || $candidate === $remote ) {
1862 continue;
1863 }
1864 // Loopback forwarded IP = local development, not a real proxy.
1865 if ( '::1' === $candidate || 0 === strpos( $candidate, '127.' ) ) {
1866 continue;
1867 }
1868 $detected = $proxy_label;
1869 break;
1870 }
1871
1872 if ( '' !== $detected ) {
1873 $firewall_url = admin_url( 'admin.php?page=vigilante&tab=firewall' );
1874 $detail_message = sprintf(
1875 /* translators: %s: detected forwarded header name wrapped in a code tag. */
1876 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' ),
1877 '<code>' . esc_html( strtoupper( $detected ) ) . '</code>'
1878 );
1879 ?>
1880 <div class="notice notice-warning is-dismissible vigilante-proxy-notice">
1881 <p>
1882 <span class="dashicons dashicons-shield"></span>
1883 <strong><?php esc_html_e( 'Vigilant: this site looks like it is behind a proxy or CDN', 'vigilante' ); ?></strong>
1884 </p>
1885 <p><?php echo wp_kses_post( $detail_message ); ?></p>
1886 <p>
1887 <a href="<?php echo esc_url( $firewall_url ); ?>" class="button button-secondary">
1888 <?php esc_html_e( 'Set your proxy in Firewall settings', 'vigilante' ); ?>
1889 </a>
1890 </p>
1891 </div>
1892 <script>
1893 jQuery( function ( $ ) {
1894 $( document ).on( 'click', '.vigilante-proxy-notice .notice-dismiss', function () {
1895 $.post( ajaxurl, {
1896 action: 'vigilante_dismiss_notice',
1897 notice_id: 'proxy_detection',
1898 nonce: <?php echo wp_json_encode( wp_create_nonce( 'vigilante_dismiss_notice' ) ); ?>
1899 } );
1900 } );
1901 } );
1902 </script>
1903 <?php
1904 }
1905 }
1906 }
1907
1908 /**
1909 * Render settings page
1910 */
1911 public function render_settings_page() {
1912 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
1913 $this->current_tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'dashboard';
1914
1915 if ( ! array_key_exists( $this->current_tab, $this->tabs ) ) {
1916 $this->current_tab = 'dashboard';
1917 }
1918 ?>
1919 <div class="wrap vigilante-admin-wrap">
1920 <div class="vigilante-header-row">
1921 <h1 class="vigilante-page-title">
1922 <img src="<?php echo esc_url( VIGILANTE_ASSETS_URL . 'images/icon.png' ); ?>" alt="Vigilante" class="vigilante-title-icon">
1923 <?php esc_html_e( 'Vigilant', 'vigilante' ); ?>
1924 <span class="vigilante-version">v<?php echo esc_html( VIGILANTE_VERSION ); ?></span>
1925 </h1>
1926 <div class="vigilante-search-wrapper">
1927 <div class="vigilante-search-input-wrap">
1928 <span class="vigilante-search-icon dashicons dashicons-search" aria-hidden="true"></span>
1929 <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">
1930 <span class="vigilante-search-shortcut" aria-hidden="true">/</span>
1931 </div>
1932 <div id="vigilante-settings-search-results" class="vigilante-search-results" hidden role="listbox"></div>
1933 </div>
1934 </div>
1935
1936 <?php $this->render_tabs(); ?>
1937
1938 <div class="vigilante-content">
1939 <div class="vigilante-main">
1940 <?php $this->render_tab_content(); ?>
1941 </div>
1942 <div class="vigilante-sidebar">
1943 <?php $this->render_sidebar(); ?>
1944 </div>
1945 </div>
1946 </div>
1947 <?php
1948 }
1949
1950 /**
1951 * Render tabs navigation
1952 */
1953 private function render_tabs() {
1954 $options = $this->settings->get_all_options();
1955
1956 // Map tabs to modules
1957 $tab_to_module = array(
1958 'firewall' => 'firewall',
1959 'headers' => 'security_headers',
1960 'login' => 'login_security',
1961 'rest-api' => 'rest_api_security',
1962 'users' => 'user_security',
1963 'wp-hardening' => 'wp_hardening',
1964 'file-integrity' => 'file_integrity',
1965 'activity-log' => 'activity_log',
1966 );
1967 ?>
1968 <nav class="nav-tab-wrapper vigilante-nav-tabs">
1969 <?php foreach ( $this->tabs as $tab_id => $tab_name ) :
1970 $is_disabled = false;
1971 $module = isset( $tab_to_module[ $tab_id ] ) ? $tab_to_module[ $tab_id ] : null;
1972 if ( $module && empty( $options['modules'][ $module ] ) ) {
1973 $is_disabled = true;
1974 }
1975 ?>
1976 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=' . $tab_id ) ); ?>"
1977 class="nav-tab <?php echo $this->current_tab === $tab_id ? 'nav-tab-active' : ''; ?> <?php echo $is_disabled ? 'vigilante-tab-disabled' : ''; ?>"
1978 <?php if ( $is_disabled ) : ?>title="<?php esc_attr_e( 'Module Disabled', 'vigilante' ); ?>"<?php endif; ?>>
1979 <?php echo esc_html( $tab_name ); ?>
1980 <?php if ( $is_disabled ) : ?><span class="vigilante-tab-off">OFF</span><?php endif; ?>
1981 </a>
1982 <?php endforeach; ?>
1983 </nav>
1984 <?php
1985 }
1986
1987 /**
1988 * Render current tab content
1989 */
1990 private function render_tab_content() {
1991 $method = 'render_tab_' . str_replace( '-', '_', $this->current_tab );
1992
1993 if ( method_exists( $this, $method ) ) {
1994 $this->$method();
1995 } else {
1996 $this->render_tab_coming_soon();
1997 }
1998 }
1999
2000 /**
2001 * Render coming soon placeholder
2002 */
2003 private function render_tab_coming_soon() {
2004 ?>
2005 <div class="vigilante-settings-section">
2006 <h2><?php esc_html_e( 'Coming Soon', 'vigilante' ); ?></h2>
2007 <p><?php esc_html_e( 'This section is under development.', 'vigilante' ); ?></p>
2008 </div>
2009 <?php
2010 }
2011
2012 /**
2013 * Values to display for a section that this site does not control
2014 *
2015 * On a subsite the stored options are its own copy, which nothing acts on:
2016 * wp-config.php and .htaccess are written from the main site. Painting the
2017 * local copy describes a configuration that is not running, so a subsite
2018 * admin sees a box ticked here and the constant absent from the file, or the
2019 * other way round. Read the main site's values instead, which are the ones in
2020 * force, and fall back to the local ones if they cannot be read.
2021 *
2022 * @since 2.9.8
2023 *
2024 * @param string $section Settings section.
2025 * @return array
2026 */
2027 private function get_section_for_display( $section ) {
2028 $local = $this->settings->get_section( $section );
2029
2030 if ( ! $this->shared_files_locked() ) {
2031 return $local;
2032 }
2033
2034 // shared_files_locked() is only true on multisite, where get_blog_option() exists.
2035 $main = get_blog_option( get_main_site_id(), Vigilante_Settings::OPTION_NAME, array() );
2036
2037 if ( ! is_array( $main ) || empty( $main[ $section ] ) || ! is_array( $main[ $section ] ) ) {
2038 return $local;
2039 }
2040
2041 return wp_parse_args( $main[ $section ], $local );
2042 }
2043
2044 /**
2045 * Whether the sections that write wp-config.php and .htaccess are read-only here
2046 *
2047 * True on a network when this is not the main site, or the user is not a
2048 * network administrator. See Vigilante_Settings::can_write_shared_files().
2049 *
2050 * @since 2.9.8
2051 *
2052 * @return bool
2053 */
2054 private function shared_files_locked() {
2055 return ! Vigilante_Settings::can_write_shared_files();
2056 }
2057
2058 /**
2059 * Whether this is the main site and the user cannot change what it builds the shared files from
2060 *
2061 * See Vigilante_Settings::get_main_site_file_settings(). On a subsite those
2062 * settings only act on that site, so they are never locked there.
2063 *
2064 * @since 2.11.6
2065 *
2066 * @return bool
2067 */
2068 private function main_site_files_locked() {
2069 return $this->shared_files_locked() && Vigilante_Settings::owns_shared_files();
2070 }
2071
2072 /**
2073 * Sentence added to a bulk change when some settings were left as they were
2074 *
2075 * Importing a file, applying a preset and restoring the defaults touch every
2076 * section at once, so the user is told that the shared file settings did
2077 * not move.
2078 *
2079 * @since 2.11.6
2080 *
2081 * @return string Empty when the user can change every setting.
2082 */
2083 private function locked_file_settings_message() {
2084 if ( ! Vigilante_Settings::get_locked_file_settings() ) {
2085 return '';
2086 }
2087
2088 return ' ' . __( 'The settings that end up in wp-config.php or .htaccess were left as they were.', 'vigilante' ) . ' ' . Vigilante_Settings::get_shared_files_notice();
2089 }
2090
2091 /**
2092 * Print the shared-files notice for a section that cannot be edited here
2093 *
2094 * @since 2.9.8
2095 */
2096 private function render_shared_files_notice() {
2097 if ( ! $this->shared_files_locked() ) {
2098 return;
2099 }
2100 ?>
2101 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
2102 <p style="margin:0;"><?php echo esc_html( Vigilante_Settings::get_shared_files_notice() ); ?></p>
2103 </div>
2104 <?php
2105 }
2106
2107 /**
2108 * Acting on another user's account needs permission over that user
2109 *
2110 * Since 2.10.3 the handlers behind these tools ask for edit_user over the
2111 * target, which is the rule WordPress itself applies. On a network the core
2112 * grants edit_user only to network administrators, so for anybody else these
2113 * controls do nothing. Better to say so than to paint a button that silently
2114 * skips every user.
2115 *
2116 * @since 2.10.4
2117 * @return bool
2118 */
2119 private function user_actions_locked() {
2120 return is_multisite() && ! current_user_can( 'manage_network_users' );
2121 }
2122
2123 /**
2124 * Print the notice for user tools that cannot be used from this site
2125 *
2126 * @since 2.10.4
2127 */
2128 private function render_user_actions_notice() {
2129 if ( ! $this->user_actions_locked() ) {
2130 return;
2131 }
2132 ?>
2133 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
2134 <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>
2135 </div>
2136 <?php
2137 }
2138
2139 /**
2140 * Approving a change to the shared config files needs the network
2141 *
2142 * Since 2.11.3 the handler behind the Approve button asks for
2143 * manage_network_options, because the two files it approves, wp-config.php
2144 * and the root .htaccess, belong to the installation, and so does the
2145 * record of them. The button, though, went on being painted for everybody,
2146 * so the administrator of a subsite saw the warning, saw the button,
2147 * pressed it and got "Permission denied" with no explanation. That is
2148 * exactly what user_actions_locked() above exists to avoid, one release
2149 * later and one screen over. Flagged by @calzbert.
2150 *
2151 * @since 2.11.4
2152 * @return bool
2153 */
2154 private function critical_approval_locked() {
2155 return is_multisite() && ! current_user_can( 'manage_network_options' );
2156 }
2157
2158 /**
2159 * The line that replaces the Approve button where it cannot be used
2160 *
2161 * @since 2.11.4
2162 * @return string
2163 */
2164 private function critical_approval_notice() {
2165 return __( 'These files belong to the whole network rather than to this site, so a change to them is approved from the network admin.', 'vigilante' );
2166 }
2167
2168 /**
2169 * Check if module is disabled and render warning
2170 *
2171 * @param string $module_key Module key.
2172 * @return bool True if disabled.
2173 */
2174 private function render_module_disabled_notice( $module_key ) {
2175 if ( $this->settings->is_module_enabled( $module_key ) ) {
2176 return false;
2177 }
2178
2179 $module_labels = $this->settings->get_module_labels();
2180 $module_name = isset( $module_labels[ $module_key ] ) ? $module_labels[ $module_key ] : $module_key;
2181 ?>
2182 <div class="notice notice-warning vigilante-module-disabled-notice">
2183 <p>
2184 <strong><?php esc_html_e( 'Module Disabled', 'vigilante' ); ?></strong> -
2185 <?php
2186 printf(
2187 /* translators: %s: Module name */
2188 esc_html__( 'The %s module is currently disabled. Enable it from the Dashboard to use these settings.', 'vigilante' ),
2189 esc_html( $module_name )
2190 );
2191 ?>
2192 </p>
2193 <p>
2194 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=dashboard' ) ); ?>" class="button">
2195 <?php esc_html_e( 'Go to Dashboard', 'vigilante' ); ?>
2196 </a>
2197 </p>
2198 </div>
2199 <?php
2200 return true;
2201 }
2202
2203 /**
2204 * Render the Security Analyzer (Security Check) widget + expandable full report.
2205 *
2206 * Lives in the Dashboard tab between the Configuration Score status card and
2207 * the modules grid. Uses the last persisted scan to hydrate server-side so the
2208 * first paint shows real data; "Scan now" runs the 2-phase AJAX to refresh.
2209 *
2210 * @param array $last_scan Result of Vigilante_Security_Analyzer::get_last_scan().
2211 * @param array $history Score history (oldest first).
2212 * @param array $categories_def Category metadata (slug => label/max).
2213 * @param array $analyzer_settings Settings subsection for weekly cron + email.
2214 */
2215 private function render_analyzer_widget( $last_scan, $history, $categories_def, $analyzer_settings ) {
2216 $has_data = ! empty( $last_scan['ran_at'] );
2217 $score = isset( $last_scan['score'] ) ? (int) $last_scan['score'] : 0;
2218 $grade = isset( $last_scan['grade'] ) ? (string) $last_scan['grade'] : '';
2219 $counts = isset( $last_scan['counts'] ) && is_array( $last_scan['counts'] ) ? $last_scan['counts'] : array();
2220 $ran_at_human = $has_data
2221 ? sprintf(
2222 /* translators: %s: relative time like "2 hours" */
2223 __( 'Last scan %s ago', 'vigilante' ),
2224 human_time_diff( (int) $last_scan['ran_at'], time() )
2225 )
2226 : __( 'Never scanned', 'vigilante' );
2227 $categories = isset( $last_scan['categories'] ) && is_array( $last_scan['categories'] ) ? $last_scan['categories'] : array();
2228 $weekly_enabled = ! isset( $analyzer_settings['weekly_scan_enabled'] ) || ! empty( $analyzer_settings['weekly_scan_enabled'] );
2229 $email_enabled = ! empty( $analyzer_settings['email_on_regression'] );
2230
2231 $quality = self::analyzer_quality_tag( $score );
2232 ?>
2233 <div class="vigilante-analyzer" id="vigilante-analyzer"
2234 data-has-data="<?php echo $has_data ? '1' : '0'; ?>">
2235 <div class="vigilante-analyzer-header">
2236 <div class="vigilante-analyzer-title">
2237 <h2>
2238 <span class="dashicons dashicons-shield-alt" aria-hidden="true"></span>
2239 <?php esc_html_e( 'Security Check', 'vigilante' ); ?>
2240 </h2>
2241 <p class="description">
2242 <?php esc_html_e( 'On-demand audit of what an attacker would see right now, plus 13 internal checks impossible from the outside.', 'vigilante' ); ?>
2243 </p>
2244 <p class="vigilante-analyzer-last-scan" data-role="ran-at">
2245 <span class="dashicons dashicons-clock" aria-hidden="true"></span>
2246 <?php echo esc_html( $ran_at_human ); ?>
2247 </p>
2248 </div>
2249 <div class="vigilante-analyzer-actions">
2250 <button type="button" class="button button-primary" id="vigilante-analyzer-scan">
2251 <span class="dashicons dashicons-update" aria-hidden="true"></span>
2252 <?php esc_html_e( 'Scan now', 'vigilante' ); ?>
2253 </button>
2254 </div>
2255 </div>
2256
2257 <div class="vigilante-analyzer-summary">
2258 <div class="vigilante-analyzer-score-card">
2259 <?php if ( $has_data && $grade ) : ?>
2260 <div class="vigilante-score-circle vigilante-grade-<?php echo esc_attr( strtolower( $grade ) ); ?>">
2261 <span class="vigilante-grade"><?php echo esc_html( $grade ); ?></span>
2262 <span class="vigilante-score-text"><?php echo esc_html( $score ); ?>%</span>
2263 </div>
2264 <?php else : ?>
2265 <div class="vigilante-score-circle vigilante-grade-empty">
2266 <span class="vigilante-grade">—</span>
2267 <span class="vigilante-score-text"><?php esc_html_e( 'N/A', 'vigilante' ); ?></span>
2268 </div>
2269 <?php endif; ?>
2270 <div class="vigilante-analyzer-score-meta">
2271 <p class="vigilante-analyzer-score-label">
2272 <?php esc_html_e( 'Security Score', 'vigilante' ); ?>
2273 </p>
2274 <span class="vigilante-analyzer-quality-tag vigilante-analyzer-quality-<?php echo esc_attr( $quality['slug'] ); ?>"
2275 data-role="quality-tag">
2276 <?php echo esc_html( $quality['label'] ); ?>
2277 </span>
2278 </div>
2279 </div>
2280
2281 <div class="vigilante-analyzer-counts">
2282 <span class="vigilante-analyzer-count vigilante-analyzer-count--pass">
2283 <span class="dashicons dashicons-yes-alt" aria-hidden="true"></span>
2284 <strong data-role="pass"><?php echo esc_html( isset( $counts['pass'] ) ? $counts['pass'] : 0 ); ?></strong>
2285 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Passed', 'vigilante' ); ?></span>
2286 </span>
2287 <span class="vigilante-analyzer-count vigilante-analyzer-count--warn">
2288 <span class="dashicons dashicons-warning" aria-hidden="true"></span>
2289 <strong data-role="warn"><?php echo esc_html( isset( $counts['warn'] ) ? $counts['warn'] : 0 ); ?></strong>
2290 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Warnings', 'vigilante' ); ?></span>
2291 </span>
2292 <span class="vigilante-analyzer-count vigilante-analyzer-count--fail">
2293 <span class="dashicons dashicons-dismiss" aria-hidden="true"></span>
2294 <strong data-role="fail"><?php echo esc_html( isset( $counts['fail'] ) ? $counts['fail'] : 0 ); ?></strong>
2295 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Failing', 'vigilante' ); ?></span>
2296 </span>
2297 </div>
2298
2299 <?php
2300 // Sparkline of recent scores. Require at least 3 data points so the trend
2301 // is meaningful (2 points is just a line between dots, no real trend).
2302 $hist_points = array();
2303 foreach ( $history as $h ) {
2304 $hist_points[] = (int) $h['score'];
2305 }
2306 $hist_count = count( $hist_points );
2307 if ( $hist_count >= 3 ) :
2308 $current_score = (int) end( $hist_points );
2309 $previous_score = (int) $hist_points[ $hist_count - 2 ];
2310 $delta = $current_score - $previous_score;
2311 $delta_class = $delta > 0 ? 'vigilante-analyzer-delta--up' : ( $delta < 0 ? 'vigilante-analyzer-delta--down' : 'vigilante-analyzer-delta--flat' );
2312 $delta_icon = $delta > 0 ? 'arrow-up-alt' : ( $delta < 0 ? 'arrow-down-alt' : 'minus' );
2313 if ( 0 === $delta ) {
2314 $delta_text = __( 'No change', 'vigilante' );
2315 } else {
2316 $delta_text = sprintf(
2317 /* translators: %s: signed delta, e.g. "+3" or "-5" */
2318 _n( '%s pt vs. previous scan', '%s pts vs. previous scan', abs( $delta ), 'vigilante' ),
2319 ( $delta > 0 ? '+' : '' ) . (int) $delta
2320 );
2321 }
2322 ?>
2323 <div class="vigilante-analyzer-sparkline-wrap">
2324 <div class="vigilante-analyzer-sparkline-head">
2325 <span class="vigilante-analyzer-sparkline-label">
2326 <?php
2327 echo esc_html( sprintf(
2328 /* translators: %d: number of scans */
2329 _n( 'Score trend (last %d scan)', 'Score trend (last %d scans)', $hist_count, 'vigilante' ),
2330 $hist_count
2331 ) );
2332 ?>
2333 </span>
2334 <span class="vigilante-analyzer-delta <?php echo esc_attr( $delta_class ); ?>">
2335 <span class="dashicons dashicons-<?php echo esc_attr( $delta_icon ); ?>" aria-hidden="true"></span>
2336 <?php echo esc_html( $delta_text ); ?>
2337 </span>
2338 </div>
2339 <div class="vigilante-analyzer-sparkline" data-role="sparkline"
2340 data-points="<?php echo esc_attr( wp_json_encode( $hist_points ) ); ?>">
2341 <?php echo self::sparkline_svg( $hist_points ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Safe SVG from helper ?>
2342 </div>
2343 </div>
2344 <?php elseif ( $has_data ) : ?>
2345 <div class="vigilante-analyzer-sparkline-wrap vigilante-analyzer-sparkline-wrap--placeholder">
2346 <span class="vigilante-analyzer-sparkline-label">
2347 <?php esc_html_e( 'Score trend', 'vigilante' ); ?>
2348 </span>
2349 <p class="vigilante-analyzer-sparkline-hint">
2350 <span class="dashicons dashicons-chart-line" aria-hidden="true"></span>
2351 <?php
2352 $needed = 3 - $hist_count;
2353 echo esc_html( sprintf(
2354 /* translators: %d: number of additional scans needed */
2355 _n( '%d more scan needed to show a trend.', '%d more scans needed to show a trend.', $needed, 'vigilante' ),
2356 $needed
2357 ) );
2358 ?>
2359 </p>
2360 </div>
2361 <?php endif; ?>
2362 </div>
2363
2364 <div class="vigilante-analyzer-toggle-row">
2365 <button type="button" class="button-link vigilante-analyzer-toggle" aria-expanded="false">
2366 <?php esc_html_e( 'Show detailed breakdown', 'vigilante' ); ?>
2367 <span class="vigilante-analyzer-toggle-chevron" aria-hidden="true"></span>
2368 </button>
2369 </div>
2370
2371 <div class="vigilante-analyzer-details" hidden>
2372 <div class="vigilante-analyzer-categories" data-role="categories">
2373 <?php foreach ( $categories_def as $slug => $meta ) :
2374 $cat = isset( $categories[ $slug ] ) ? $categories[ $slug ] : array();
2375 $earned = isset( $cat['earned'] ) ? (int) $cat['earned'] : 0;
2376 // Always use the declared meta as the source of truth for the maximum.
2377 // The cached scan may carry an old max if a check was added/removed
2378 // between releases (see 2.6.1: closed_plugins raised internal from 22 to 28
2379 // but cached scans still reported max=22 until reset).
2380 $cat_max = (int) $meta['max'];
2381 $info_only = ! empty( $meta['info_only'] ) || 0 === (int) $meta['max'];
2382 $cat_pct = $cat_max > 0 ? (int) round( ( $earned / $cat_max ) * 100 ) : 0;
2383 $checks = isset( $cat['checks'] ) ? (array) $cat['checks'] : array();
2384 $cat_counts = isset( $cat['counts'] ) && is_array( $cat['counts'] ) ? $cat['counts'] : array( 'pass' => 0, 'warn' => 0, 'fail' => 0, 'info' => 0 );
2385 $cat_quality = self::analyzer_quality_tag( $cat_pct );
2386 $info_count = isset( $cat_counts['info'] ) ? (int) $cat_counts['info'] : 0;
2387 ?>
2388 <details class="vigilante-analyzer-category<?php echo $info_only ? ' vigilante-analyzer-category--info' : ''; ?>"
2389 data-category="<?php echo esc_attr( $slug ); ?>"
2390 data-info-only="<?php echo $info_only ? '1' : '0'; ?>">
2391 <summary class="vigilante-analyzer-category-summary">
2392 <span class="vigilante-analyzer-category-chevron" aria-hidden="true"></span>
2393 <span class="vigilante-analyzer-category-label"><?php echo esc_html( $meta['label'] ); ?></span>
2394 <?php if ( $info_only ) : ?>
2395 <span class="vigilante-analyzer-category-quality vigilante-analyzer-quality-info"
2396 data-role="category-quality"
2397 title="<?php esc_attr_e( 'Informational — does not affect the security score.', 'vigilante' ); ?>">
2398 <span class="dashicons dashicons-info-outline" aria-hidden="true"></span>
2399 <?php esc_html_e( 'Informational', 'vigilante' ); ?>
2400 </span>
2401 <?php else :
2402 $passed_count = (int) ( $cat_counts['pass'] ?? 0 );
2403 $scored_total = $passed_count
2404 + (int) ( $cat_counts['warn'] ?? 0 )
2405 + (int) ( $cat_counts['fail'] ?? 0 );
2406 ?>
2407 <span class="vigilante-analyzer-category-quality vigilante-analyzer-quality-<?php echo esc_attr( $cat_quality['slug'] ); ?>"
2408 data-role="category-quality">
2409 <span data-role="category-quality-label"><?php echo esc_html( $cat_quality['label'] ); ?></span>
2410 <span class="vigilante-analyzer-category-quality-sep" aria-hidden="true">·</span>
2411 <span class="vigilante-analyzer-category-tests" data-role="category-tests"
2412 data-passed="<?php echo esc_attr( $passed_count ); ?>"
2413 data-total="<?php echo esc_attr( $scored_total ); ?>">
2414 <?php
2415 echo esc_html( sprintf(
2416 /* translators: 1: tests passed, 2: total tests in this category */
2417 __( '%1$d/%2$d tests', 'vigilante' ),
2418 $passed_count,
2419 $scored_total
2420 ) );
2421 ?>
2422 </span>
2423 </span>
2424 <?php endif; ?>
2425 <?php if ( $info_only ) : ?>
2426 <span class="vigilante-analyzer-category-states" data-role="category-states">
2427 <?php if ( $info_count > 0 ) : ?>
2428 <span class="vigilante-analyzer-category-state vigilante-analyzer-category-state--info" title="<?php esc_attr_e( 'Informational', 'vigilante' ); ?>">
2429 <span data-role="state-info"><?php echo esc_html( $info_count ); ?></span><span class="dashicons dashicons-info-outline" aria-hidden="true"></span>
2430 </span>
2431 <?php endif; ?>
2432 </span>
2433 <?php endif; ?>
2434 <?php if ( ! $info_only ) : ?>
2435 <span class="vigilante-analyzer-category-score">
2436 <span data-role="earned"><?php echo esc_html( $earned ); ?></span><span class="vigilante-analyzer-category-score-sep">/</span><?php echo esc_html( $cat_max ); ?>
2437 <span class="vigilante-analyzer-category-score-unit"><?php esc_html_e( 'pts', 'vigilante' ); ?></span>
2438 </span>
2439 <span class="vigilante-analyzer-category-bar" aria-hidden="true">
2440 <span class="vigilante-analyzer-category-bar-fill vigilante-analyzer-category-bar-fill--<?php echo esc_attr( $cat_quality['slug'] ); ?>"
2441 style="width: <?php echo esc_attr( $cat_pct ); ?>%"
2442 data-role="category-bar"></span>
2443 </span>
2444 <?php else :
2445 $info_warn = isset( $cat_counts['warn'] ) ? (int) $cat_counts['warn'] : 0;
2446 $info_fail = isset( $cat_counts['fail'] ) ? (int) $cat_counts['fail'] : 0;
2447 $info_issues = $info_warn + $info_fail;
2448 if ( $info_issues > 0 ) : ?>
2449 <span class="vigilante-analyzer-category-status vigilante-analyzer-category-status--attention" data-role="info-status">
2450 <span class="dashicons dashicons-warning" aria-hidden="true"></span>
2451 <?php
2452 echo esc_html( sprintf(
2453 /* translators: %d: number of findings */
2454 _n( '%d finding', '%d findings', $info_issues, 'vigilante' ),
2455 $info_issues
2456 ) );
2457 ?>
2458 </span>
2459 <?php else : ?>
2460 <span class="vigilante-analyzer-category-status vigilante-analyzer-category-status--clear" data-role="info-status">
2461 <span class="dashicons dashicons-yes-alt" aria-hidden="true"></span>
2462 <?php esc_html_e( 'All clear', 'vigilante' ); ?>
2463 </span>
2464 <?php endif; ?>
2465 <?php endif; ?>
2466 </summary>
2467 <ul class="vigilante-analyzer-check-list" data-role="check-list">
2468 <?php if ( empty( $checks ) ) : ?>
2469 <li class="vigilante-analyzer-check-empty">
2470 <?php esc_html_e( 'No data yet — run a scan to populate this category.', 'vigilante' ); ?>
2471 </li>
2472 <?php else : ?>
2473 <?php foreach ( $checks as $c ) : ?>
2474 <?php echo self::render_analyzer_check_row( $c ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped inside helper ?>
2475 <?php endforeach; ?>
2476 <?php endif; ?>
2477 </ul>
2478 </details>
2479 <?php endforeach; ?>
2480 </div>
2481
2482 <div class="vigilante-analyzer-weekly">
2483 <h3><?php esc_html_e( 'Automatic weekly scan', 'vigilante' ); ?></h3>
2484 <p class="description">
2485 <?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' ); ?>
2486 </p>
2487 <label class="vigilante-analyzer-toggle-option">
2488 <input type="checkbox"
2489 name="security_analyzer[weekly_scan_enabled]"
2490 value="1"
2491 <?php checked( $weekly_enabled ); ?>>
2492 <?php esc_html_e( 'Run a weekly automatic scan', 'vigilante' ); ?>
2493 </label>
2494 <label class="vigilante-analyzer-toggle-option">
2495 <input type="checkbox"
2496 name="security_analyzer[email_on_regression]"
2497 value="1"
2498 <?php checked( $email_enabled ); ?>>
2499 <?php esc_html_e( 'Email me when the score drops significantly', 'vigilante' ); ?>
2500 </label>
2501 </div>
2502 </div>
2503 </div>
2504 <?php
2505 }
2506
2507 /**
2508 * Map a 0-100 percentage to a quality tag { label, slug } aligned with the
2509 * Dashboard grade palette (a/b/c/d/e).
2510 *
2511 * @param int $pct 0..100.
2512 * @return array{label:string,slug:string}
2513 */
2514 public static function analyzer_quality_tag( $pct ) {
2515 $pct = max( 0, min( 100, (int) $pct ) );
2516 // "Excellent" is reserved for a perfect score — a single missing point drops to Good.
2517 if ( 100 === $pct ) {
2518 return array( 'label' => __( 'Excellent', 'vigilante' ), 'slug' => 'a' );
2519 }
2520 if ( $pct >= 70 ) {
2521 return array( 'label' => __( 'Good', 'vigilante' ), 'slug' => 'b' );
2522 }
2523 if ( $pct >= 50 ) {
2524 return array( 'label' => __( 'Fair', 'vigilante' ), 'slug' => 'c' );
2525 }
2526 if ( $pct >= 30 ) {
2527 return array( 'label' => __( 'Poor', 'vigilante' ), 'slug' => 'd' );
2528 }
2529 return array( 'label' => __( 'Critical', 'vigilante' ), 'slug' => 'e' );
2530 }
2531
2532 /**
2533 * Render a single analyzer check row (used both server-side and via JS template).
2534 *
2535 * @param array $check Check result array (from Vigilante_SA_Check_Result::to_array()).
2536 * @return string HTML (escaped).
2537 */
2538 private static function render_analyzer_check_row( $check ) {
2539 $id = isset( $check['id'] ) ? $check['id'] : '';
2540 $state = isset( $check['state'] ) ? $check['state'] : 'skip';
2541 $label = isset( $check['label'] ) ? $check['label'] : '';
2542 $detail = isset( $check['detail'] ) ? $check['detail'] : '';
2543 $score = isset( $check['score'] ) ? (int) $check['score'] : 0;
2544 $max = isset( $check['max'] ) ? (int) $check['max'] : 0;
2545 $fix_link = isset( $check['fix_link'] ) ? $check['fix_link'] : '';
2546
2547 $icons = array(
2548 'pass' => 'yes-alt',
2549 'warn' => 'warning',
2550 'fail' => 'dismiss',
2551 'info' => 'info',
2552 'skip' => 'minus',
2553 );
2554 $icon = isset( $icons[ $state ] ) ? $icons[ $state ] : 'minus';
2555
2556 $html = '<li class="vigilante-analyzer-check vigilante-analyzer-check--' . esc_attr( $state ) . '"';
2557 $html .= ' data-check-id="' . esc_attr( $id ) . '">';
2558 $html .= '<span class="vigilante-analyzer-check-icon dashicons dashicons-' . esc_attr( $icon ) . '" aria-hidden="true"></span>';
2559 $html .= '<div class="vigilante-analyzer-check-body">';
2560 $html .= '<div class="vigilante-analyzer-check-label">';
2561 $html .= '<span>' . esc_html( $label ) . '</span>';
2562 if ( $max > 0 && 'info' !== $state && 'skip' !== $state ) {
2563 $html .= '<span class="vigilante-analyzer-check-score">'
2564 . esc_html( $score . '/' . $max )
2565 . ' <span class="vigilante-analyzer-check-score-unit">' . esc_html__( 'pts', 'vigilante' ) . '</span>'
2566 . '</span>';
2567 }
2568 $html .= '</div>';
2569 if ( $detail ) {
2570 $html .= '<p class="vigilante-analyzer-check-detail">' . esc_html( $detail ) . '</p>';
2571 }
2572 if ( $fix_link && in_array( $state, array( 'fail', 'warn' ), true ) ) {
2573 $html .= '<a href="' . esc_url( $fix_link ) . '" class="vigilante-analyzer-fix-link">'
2574 . esc_html__( 'Go to setting', 'vigilante' )
2575 . '<span class="vigilante-analyzer-fix-arrow" aria-hidden="true">&rarr;</span></a>';
2576 } elseif ( $fix_link && 'info' === $state ) {
2577 // Info rows (e.g. DNSBL lookups) get an external "Learn more" link instead.
2578 $is_external = 0 === strpos( $fix_link, 'http' );
2579 $html .= '<a href="' . esc_url( $fix_link ) . '" class="vigilante-analyzer-fix-link"'
2580 . ( $is_external ? ' target="_blank" rel="noopener noreferrer"' : '' ) . '>'
2581 . esc_html__( 'Learn more', 'vigilante' )
2582 . '<span class="vigilante-analyzer-fix-arrow" aria-hidden="true">&rarr;</span></a>';
2583 }
2584 $html .= '</div>';
2585 $html .= '</li>';
2586 return $html;
2587 }
2588
2589 /**
2590 * Build a minimal SVG sparkline for the score history.
2591 *
2592 * @param int[] $points Score values (0..100), oldest to newest.
2593 * @return string SVG markup.
2594 */
2595 private static function sparkline_svg( $points ) {
2596 $points = array_map( 'intval', (array) $points );
2597 $count = count( $points );
2598 if ( $count < 2 ) {
2599 return '';
2600 }
2601 $width = 280;
2602 $height = 60;
2603 $padding = 4;
2604
2605 $usable_w = $width - ( $padding * 2 );
2606 $usable_h = $height - ( $padding * 2 );
2607
2608 $step = $usable_w / max( 1, $count - 1 );
2609 $max = 100; // Fixed scale — scores are 0..100.
2610
2611 $coords = array();
2612 foreach ( $points as $i => $v ) {
2613 $x = $padding + ( $i * $step );
2614 $y = $padding + ( $usable_h - ( ( $v / $max ) * $usable_h ) );
2615 $coords[] = round( $x, 2 ) . ',' . round( $y, 2 );
2616 }
2617 $path = 'M ' . implode( ' L ', $coords );
2618 $last = end( $points );
2619 $last_x = $padding + ( ( $count - 1 ) * $step );
2620 $last_y = $padding + ( $usable_h - ( ( $last / $max ) * $usable_h ) );
2621
2622 $svg = '<svg viewBox="0 0 ' . $width . ' ' . $height . '" preserveAspectRatio="none" role="img" aria-label="' . esc_attr__( 'Security Score history', 'vigilante' ) . '" focusable="false">';
2623 $svg .= '<path d="' . esc_attr( $path ) . '" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>';
2624 $svg .= '<circle cx="' . esc_attr( round( $last_x, 2 ) ) . '" cy="' . esc_attr( round( $last_y, 2 ) ) . '" r="3" fill="currentColor"/>';
2625 $svg .= '</svg>';
2626 return $svg;
2627 }
2628
2629 /**
2630 * Render dashboard tab
2631 */
2632 private function render_tab_dashboard() {
2633 $options = $this->settings->get_all_options();
2634 $module_labels = $this->settings->get_module_labels();
2635 $module_descriptions = $this->settings->get_module_descriptions();
2636 $presets = $this->settings->get_presets();
2637 $active_preset = get_option( 'vigilante_active_preset', '' );
2638
2639 // Calculate security score with more factors
2640 $security_score = $this->calculate_security_score( $options );
2641
2642 // Security Analyzer (v2.1.0) — hydrate widget with the last persisted scan, if any.
2643 if ( ! class_exists( 'Vigilante_Security_Analyzer' ) ) {
2644 require_once VIGILANTE_INCLUDES_DIR . 'class-security-analyzer.php';
2645 }
2646 $analyzer_instance = new Vigilante_Security_Analyzer( $this->settings, $this->activity_log );
2647 $analyzer_last_scan = $analyzer_instance->get_last_scan();
2648 $analyzer_history = $analyzer_instance->get_score_history();
2649 $analyzer_categories_def = Vigilante_Security_Analyzer::get_categories();
2650 $analyzer_settings = isset( $options['security_analyzer'] ) ? $options['security_analyzer'] : array();
2651 ?>
2652 <div class="vigilante-dashboard">
2653 <div class="vigilante-status-card">
2654 <h2><?php esc_html_e( 'Configuration Score', 'vigilante' ); ?></h2>
2655 <p class="vigilante-score-kind description">
2656 <?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' ); ?>
2657 </p>
2658 <div class="vigilante-security-score">
2659 <?php
2660 // Grade thresholds: A (90+), B (70-89), C (50-69), D (30-49), E (0-29)
2661 if ( $security_score >= 90 ) {
2662 $grade = 'A';
2663 } elseif ( $security_score >= 70 ) {
2664 $grade = 'B';
2665 } elseif ( $security_score >= 50 ) {
2666 $grade = 'C';
2667 } elseif ( $security_score >= 30 ) {
2668 $grade = 'D';
2669 } else {
2670 $grade = 'E';
2671 }
2672 ?>
2673 <div class="vigilante-score-circle vigilante-grade-<?php echo esc_attr( strtolower( $grade ) ); ?>">
2674 <span class="vigilante-grade"><?php echo esc_html( $grade ); ?></span>
2675 <span class="vigilante-score-text"><?php echo esc_html( $security_score ); ?>%</span>
2676 </div>
2677 <div class="vigilante-config-status">
2678 <?php if ( $active_preset && isset( $presets[ $active_preset ] ) ) : ?>
2679 <span class="vigilante-preset-badge vigilante-preset-<?php echo esc_attr( $active_preset ); ?>">
2680 <?php echo esc_html( $presets[ $active_preset ]['name'] ); ?>
2681 </span>
2682 <?php else : ?>
2683 <span class="vigilante-preset-badge vigilante-preset-custom">
2684 <?php esc_html_e( 'Custom Configuration', 'vigilante' ); ?>
2685 </span>
2686 <?php endif; ?>
2687 </div>
2688 </div>
2689
2690 <?php
2691 $recommendations = $this->get_security_recommendations( $options );
2692 if ( ! empty( $recommendations ) ) :
2693 ?>
2694 <div class="vigilante-recommendations">
2695 <h4><?php esc_html_e( 'Recommendations', 'vigilante' ); ?></h4>
2696 <ul class="vigilante-recommendations-grid">
2697 <?php foreach ( $recommendations as $rec ) : ?>
2698 <li>
2699 <span class="dashicons dashicons-<?php echo esc_attr( $rec['icon'] ); ?> vigilante-priority-<?php echo esc_attr( $rec['priority'] ); ?>"></span>
2700 <?php echo esc_html( $rec['message'] ); ?>
2701 <?php if ( ! empty( $rec['tab'] ) ) : ?>
2702 <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>
2703 <?php endif; ?>
2704 </li>
2705 <?php endforeach; ?>
2706 </ul>
2707 </div>
2708 <?php endif; ?>
2709 </div>
2710
2711 <?php $this->render_analyzer_widget( $analyzer_last_scan, $analyzer_history, $analyzer_categories_def, $analyzer_settings ); ?>
2712
2713 <div class="vigilante-modules-grid">
2714 <h2 id="vigilante-section-dashboard-modules"><?php esc_html_e( 'Security Modules', 'vigilante' ); ?></h2>
2715 <p class="description"><?php esc_html_e( 'Enable or disable security modules. Each module controls a tab with detailed settings.', 'vigilante' ); ?></p>
2716 <div class="vigilante-modules-list">
2717 <?php foreach ( $options['modules'] as $module => $enabled ) :
2718 $label = isset( $module_labels[ $module ] ) ? $module_labels[ $module ] : ucwords( str_replace( '_', ' ', $module ) );
2719 $description = isset( $module_descriptions[ $module ] ) ? $module_descriptions[ $module ] : '';
2720 $vg_module_locked = $this->main_site_files_locked() && in_array( $module, Vigilante_Settings::get_main_site_file_settings()['modules'], true );
2721 ?>
2722 <div class="vigilante-module-item <?php echo $enabled ? 'enabled' : 'disabled'; ?>">
2723 <div class="vigilante-module-header">
2724 <span class="vigilante-module-status"></span>
2725 <span class="vigilante-module-name"><?php echo esc_html( $label ); ?></span>
2726 <label class="vigilante-toggle">
2727 <?php
2728 /* translators: %s: Security module name, for example Firewall. */
2729 $toggle_label = sprintf( __( 'Enable %s', 'vigilante' ), $label );
2730 ?>
2731 <input type="checkbox"
2732 name="modules[<?php echo esc_attr( $module ); ?>]"
2733 value="1"
2734 <?php checked( $enabled ); ?>
2735 <?php disabled( $vg_module_locked ); ?>
2736 aria-label="<?php echo esc_attr( $toggle_label ); ?>"
2737 data-module="<?php echo esc_attr( $module ); ?>">
2738 <span class="vigilante-toggle-slider"></span>
2739 </label>
2740 </div>
2741 <?php if ( $description ) : ?>
2742 <p class="vigilante-module-desc"><?php echo esc_html( $description ); ?></p>
2743 <?php endif; ?>
2744 <?php if ( $vg_module_locked ) : ?>
2745 <p class="vigilante-module-desc"><?php esc_html_e( 'On the main site of a network this module also writes files every site shares, so only a network administrator can switch it.', 'vigilante' ); ?></p>
2746 <?php endif; ?>
2747 </div>
2748 <?php endforeach; ?>
2749 </div>
2750 </div>
2751
2752 <div class="vigilante-presets-card">
2753 <h2><?php esc_html_e( 'Quick Configuration Presets', 'vigilante' ); ?></h2>
2754 <p><?php esc_html_e( 'Apply a preset to quickly set up recommended settings for standard or maximum security level.', 'vigilante' ); ?></p>
2755 <div class="vigilante-presets-grid">
2756 <?php foreach ( $presets as $preset_id => $preset ) :
2757 $is_active = ( $active_preset === $preset_id );
2758 ?>
2759 <div class="vigilante-preset-card <?php echo $is_active ? 'vigilante-preset-active' : ''; ?>">
2760 <?php if ( $is_active ) : ?>
2761 <span class="vigilante-active-indicator"><?php esc_html_e( 'Active', 'vigilante' ); ?></span>
2762 <?php endif; ?>
2763 <h3><?php echo esc_html( $preset['name'] ); ?></h3>
2764 <p><?php echo esc_html( $preset['description'] ); ?></p>
2765 <button type="button" class="button vigilante-preset-btn <?php echo $is_active ? 'button-primary' : ''; ?>" data-preset="<?php echo esc_attr( $preset_id ); ?>">
2766 <?php esc_html_e( 'Apply Preset', 'vigilante' ); ?>
2767 </button>
2768 </div>
2769 <?php endforeach; ?>
2770
2771 <?php
2772 // Under Attack mode card
2773 $under_attack = new Vigilante_Under_Attack( $this->settings, $this->activity_log );
2774 $ua_active = $under_attack->is_active();
2775 $ua_remaining = $under_attack->get_remaining_time();
2776 $ua_remaining_hours = floor( $ua_remaining / 3600 );
2777 $ua_remaining_mins = floor( ( $ua_remaining % 3600 ) / 60 );
2778 ?>
2779 <div class="vigilante-preset-card vigilante-under-attack-card <?php echo $ua_active ? 'vigilante-under-attack-active' : ''; ?>">
2780 <h3 id="vigilante-section-dashboard-under-attack">
2781 <span class="dashicons dashicons-shield"></span>
2782 <?php esc_html_e( 'Under Attack', 'vigilante' ); ?>
2783 </h3>
2784 <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>
2785 <?php if ( $ua_active ) : ?>
2786 <div class="vigilante-ua-countdown" data-expires="<?php echo esc_attr( $under_attack->get_status()['activated_at'] + $under_attack->get_status()['duration'] ); ?>">
2787 <span class="dashicons dashicons-clock"></span>
2788 <span class="vigilante-ua-time">
2789 <?php
2790 printf(
2791 /* translators: 1: Hours, 2: Minutes */
2792 esc_html__( '%1$dh %2$dm remaining', 'vigilante' ),
2793 absint( $ua_remaining_hours ),
2794 absint( $ua_remaining_mins )
2795 );
2796 ?>
2797 </span>
2798 </div>
2799 <button type="button" class="button vigilante-ua-btn vigilante-ua-deactivate">
2800 <?php esc_html_e( 'Deactivate', 'vigilante' ); ?>
2801 </button>
2802 <?php else : ?>
2803 <button type="button" class="button vigilante-ua-btn vigilante-ua-activate">
2804 <?php esc_html_e( 'Activate for 4 hours', 'vigilante' ); ?>
2805 </button>
2806 <?php endif; ?>
2807 </div>
2808 </div>
2809 </div>
2810 </div>
2811 <?php
2812 }
2813
2814 /**
2815 * Render tools tab
2816 */
2817 private function render_tab_tools() {
2818 // Get current settings for notification summary
2819 $email_options = $this->settings->get_section( 'email' );
2820 $login_options = $this->settings->get_section( 'login_security' );
2821 $user_options = $this->settings->get_section( 'user_security' );
2822 $fi_options = $this->settings->get_section( 'file_integrity' );
2823 $alerts_options = $this->settings->get_section( 'audit_alerts' );
2824 $monitoring = $user_options['admin_monitoring'] ?? array();
2825 $registration = $user_options['registration_approval'] ?? array();
2826 $current_admin = get_option( 'admin_email' );
2827 $send_to_admin = ! isset( $email_options['send_to_admin_email'] ) || ! empty( $email_options['send_to_admin_email'] );
2828 $additional_raw = $email_options['additional_recipients'] ?? array();
2829 $additional = is_array( $additional_raw ) ? implode( "\n", $additional_raw ) : trim( $additional_raw );
2830 ?>
2831
2832 <!-- Notification Settings -->
2833 <div id="vigilante-section-tools-notifications" class="vigilante-settings-section vigilante-notification-section">
2834 <h2><?php esc_html_e( 'Notification settings', 'vigilante' ); ?></h2>
2835 <p><?php esc_html_e( 'Configure who receives all administrative email notifications from Vigilant. Individual notifications are enabled in their respective tabs.', 'vigilante' ); ?></p>
2836
2837 <div class="vigilante-notification-layout">
2838
2839 <!-- Left column: Recipients settings -->
2840 <div class="vigilante-notification-settings">
2841 <form class="vigilante-settings-form" data-section="email">
2842
2843 <table class="form-table vigilante-compact-form">
2844 <tr>
2845 <th scope="row"><?php esc_html_e( 'WordPress Admin Email', 'vigilante' ); ?></th>
2846 <td>
2847 <label>
2848 <input type="checkbox" name="email[send_to_admin_email]" value="1" <?php checked( $send_to_admin ); ?>>
2849 <?php
2850 printf(
2851 /* translators: %s: Admin email address */
2852 esc_html__( 'Send to admin email (%s)', 'vigilante' ),
2853 '<code>' . esc_html( $current_admin ) . '</code>'
2854 );
2855 ?>
2856 </label>
2857 </td>
2858 </tr>
2859 <tr>
2860 <th scope="row"><label for="vigilante-f-email-additional-recipients"><?php esc_html_e( 'Additional Recipients', 'vigilante' ); ?></label></th>
2861 <td>
2862 <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>
2863 <p class="description"><?php esc_html_e( 'One email per line.', 'vigilante' ); ?></p>
2864 </td>
2865 </tr>
2866 <tr>
2867 <th scope="row"><?php esc_html_e( 'Plugin Deactivation', 'vigilante' ); ?></th>
2868 <td>
2869 <label>
2870 <input type="checkbox" name="email[send_deactivation_email]" value="1" <?php checked( ! empty( $email_options['send_deactivation_email'] ) ); ?>>
2871 <?php esc_html_e( 'Send email when Vigilant is deactivated', 'vigilante' ); ?>
2872 </label>
2873 </td>
2874 </tr>
2875 </table>
2876
2877 <p class="submit vigilante-notification-submit">
2878 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
2879 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
2880 </button>
2881 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
2882 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
2883 </button>
2884 <span class="vigilante-test-email-result" style="margin-left:8px;vertical-align:middle;"></span>
2885 </p>
2886 <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>
2887
2888 </form>
2889 </div>
2890
2891 <!-- Right column: Active notifications summary -->
2892 <div class="vigilante-notification-summary">
2893 <h4><?php esc_html_e( 'Active notifications', 'vigilante' ); ?></h4>
2894
2895 <table class="widefat striped">
2896 <thead>
2897 <tr>
2898 <th><?php esc_html_e( 'Notification', 'vigilante' ); ?></th>
2899 <th style="width: 1%; white-space: nowrap; text-align: center;"><?php esc_html_e( 'Status', 'vigilante' ); ?></th>
2900 <th style="width: 50px; text-align: center;"></th>
2901 </tr>
2902 </thead>
2903 <tbody>
2904 <?php
2905 $notifications = array(
2906 array(
2907 'label' => __( 'Login lockout', 'vigilante' ),
2908 'active' => ! empty( $login_options['notify_on_lockout'] ),
2909 'tab' => 'login',
2910 ),
2911 array(
2912 'label' => __( 'Administrator login', 'vigilante' ),
2913 'active' => ! empty( $login_options['notify_on_admin_login'] ),
2914 'tab' => 'login',
2915 ),
2916 array(
2917 'label' => __( 'New administrator created', 'vigilante' ),
2918 'active' => ! empty( $monitoring['alert_new_admin'] ),
2919 'tab' => 'users',
2920 ),
2921 array(
2922 'label' => __( 'Administrator email changed', 'vigilante' ),
2923 'active' => ! empty( $monitoring['alert_admin_email_change'] ),
2924 'tab' => 'users',
2925 ),
2926 array(
2927 'label' => __( 'Permission elevation', 'vigilante' ),
2928 'active' => ! empty( $monitoring['alert_permission_elevation'] ),
2929 'tab' => 'users',
2930 ),
2931 array(
2932 'label' => __( 'Admin password changed', 'vigilante' ),
2933 'active' => ! empty( $monitoring['alert_admin_password_change'] ),
2934 'tab' => 'users',
2935 ),
2936 array(
2937 'label' => __( 'Registration pending approval', 'vigilante' ),
2938 'active' => ! empty( $registration['enabled'] ) && ! empty( $registration['notify_admin'] ),
2939 'tab' => 'users',
2940 ),
2941 array(
2942 'label' => __( 'File integrity scan report', 'vigilante' ),
2943 'active' => ( $fi_options['notify_level'] ?? 'disabled' ) !== 'disabled',
2944 'tab' => 'file-integrity',
2945 ),
2946 array(
2947 'label' => __( 'File integrity instant alert', 'vigilante' ),
2948 'active' => ! empty( $fi_options['instant_alert'] ),
2949 'tab' => 'file-integrity',
2950 ),
2951 array(
2952 'label' => __( 'Audit alert: immediate', 'vigilante' ),
2953 'active' => Vigilante_Audit_Alerts::immediate_is_active( $alerts_options ),
2954 'tab' => 'activity-log',
2955 'anchor' => 'vigilante-section-audit-alerts',
2956 ),
2957 array(
2958 'label' => __( 'Audit alert: threshold', 'vigilante' ),
2959 'active' => Vigilante_Audit_Alerts::threshold_is_active( $alerts_options ),
2960 'tab' => 'activity-log',
2961 'anchor' => 'vigilante-section-audit-alerts',
2962 ),
2963 array(
2964 'label' => __( 'Under Attack mode', 'vigilante' ),
2965 'active' => true,
2966 'tab' => '',
2967 'note' => __( 'Always active', 'vigilante' ),
2968 ),
2969 array(
2970 'label' => __( 'Plugin deactivation', 'vigilante' ),
2971 'active' => ! empty( $email_options['send_deactivation_email'] ),
2972 'tab' => 'tools',
2973 ),
2974 );
2975
2976 foreach ( $notifications as $notif ) :
2977 $status_class = $notif['active'] ? 'vigilante-status-active' : 'vigilante-status-inactive';
2978 $status_label = $notif['active'] ? __( 'Active', 'vigilante' ) : __( 'Inactive', 'vigilante' );
2979 if ( ! empty( $notif['note'] ) ) {
2980 $status_label = $notif['note'];
2981 }
2982 ?>
2983 <tr>
2984 <td><?php echo esc_html( $notif['label'] ); ?></td>
2985 <td style="text-align: center; white-space: nowrap;">
2986 <span class="<?php echo esc_attr( $status_class ); ?>"><?php echo esc_html( $status_label ); ?></span>
2987 </td>
2988 <td style="text-align: center;">
2989 <?php if ( ! empty( $notif['tab'] ) ) : ?>
2990 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=' . $notif['tab'] ) . ( ! empty( $notif['anchor'] ) ? '#' . $notif['anchor'] : '' ) ); ?>" class="button button-small">
2991 <span class="dashicons dashicons-admin-generic" style="font-size: 14px; line-height: 1.8;"></span>
2992 </a>
2993 <?php else : ?>
2994 &mdash;
2995 <?php endif; ?>
2996 </td>
2997 </tr>
2998 <?php endforeach; ?>
2999 </tbody>
3000 </table>
3001 </div>
3002
3003 </div>
3004 </div>
3005
3006 <h2 id="vigilante-section-tools-main" class="vigilante-tools-heading"><?php esc_html_e( 'Tools', 'vigilante' ); ?></h2>
3007
3008 <?php
3009 // Warn that during Under Attack mode the export/import operate against
3010 // the temporary hardened config and any imported changes will be
3011 // reverted when the mode ends.
3012 $ua_status = get_option( Vigilante_Under_Attack::OPTION_NAME, array() );
3013 if ( ! empty( $ua_status['active'] ) ) :
3014 ?>
3015 <div class="vigilante-ua-tools-notice-wrap">
3016 <div class="notice notice-warning inline vigilante-ua-tools-notice">
3017 <p>
3018 <strong><?php esc_html_e( 'Under Attack mode is active.', 'vigilante' ); ?></strong>
3019 <?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' ); ?>
3020 </p>
3021 </div>
3022 </div>
3023 <?php
3024 endif;
3025 ?>
3026
3027 <div class="vigilante-tools-grid">
3028 <div class="vigilante-tool-card">
3029 <h3><?php esc_html_e( 'Export Settings', 'vigilante' ); ?></h3>
3030 <p><?php esc_html_e( 'Download your current security settings as a JSON file.', 'vigilante' ); ?></p>
3031 <button type="button" class="button vigilante-export-settings">
3032 <?php esc_html_e( 'Export Settings', 'vigilante' ); ?>
3033 </button>
3034 </div>
3035
3036 <div class="vigilante-tool-card">
3037 <h3><?php esc_html_e( 'Import Settings', 'vigilante' ); ?></h3>
3038 <p><?php esc_html_e( 'Import settings from a previously exported JSON file.', 'vigilante' ); ?></p>
3039 <input type="file" id="vigilante-import-file" aria-label="<?php esc_attr_e( 'Configuration file to import', 'vigilante' ); ?>" accept=".json" style="display: none;">
3040 <button type="button" class="button vigilante-import-settings">
3041 <?php esc_html_e( 'Import Settings', 'vigilante' ); ?>
3042 </button>
3043 </div>
3044
3045 <div class="vigilante-tool-card">
3046 <h3><?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?></h3>
3047 <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>
3048 <button type="button" class="button vigilante-reset-settings" style="color: #a00;">
3049 <?php esc_html_e( 'Reset All Settings', 'vigilante' ); ?>
3050 </button>
3051 </div>
3052
3053 <div class="vigilante-tool-card">
3054 <h3><?php esc_html_e( 'Download Config Backup', 'vigilante' ); ?></h3>
3055 <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>
3056 <?php if ( $this->shared_files_locked() ) : ?>
3057 <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>
3058 <?php else : ?>
3059 <button type="button" class="button vigilante-create-backup">
3060 <?php esc_html_e( 'Download Backup', 'vigilante' ); ?>
3061 </button>
3062 <?php endif; ?>
3063 </div>
3064
3065 <?php if ( ! $this->shared_files_locked() ) : ?>
3066
3067 <div class="vigilante-tool-card vigilante-tool-card-wide">
3068 <h3><?php esc_html_e( 'Database Backup', 'vigilante' ); ?></h3>
3069 <p><?php esc_html_e( 'Download a backup of your database as a ZIP file. Select which tables to include.', 'vigilante' ); ?></p>
3070 <button type="button" class="button vigilante-db-backup-toggle">
3071 <?php esc_html_e( 'Download Database Backup', 'vigilante' ); ?>
3072 </button>
3073
3074 <div class="vigilante-db-backup-panel" style="display: none;">
3075 <div class="vigilante-db-tables-loading">
3076 <span class="spinner is-active"></span>
3077 <?php esc_html_e( 'Loading tables...', 'vigilante' ); ?>
3078 </div>
3079
3080 <div class="vigilante-db-tables-content" style="display: none;">
3081 <div class="vigilante-db-tables-controls">
3082 <label>
3083 <input type="checkbox" id="vigilante-db-select-all" checked>
3084 <strong><?php esc_html_e( 'Select / deselect all', 'vigilante' ); ?></strong>
3085 </label>
3086 <span class="vigilante-db-tables-info"></span>
3087 </div>
3088
3089 <div class="vigilante-db-tables-group">
3090 <h4><?php esc_html_e( 'WordPress core tables', 'vigilante' ); ?></h4>
3091 <div class="vigilante-db-tables-list" id="vigilante-db-core-tables"></div>
3092 </div>
3093
3094 <div class="vigilante-db-tables-group" id="vigilante-db-other-group" style="display: none;">
3095 <h4><?php esc_html_e( 'Plugin and custom tables', 'vigilante' ); ?></h4>
3096 <div class="vigilante-db-tables-list" id="vigilante-db-other-tables"></div>
3097 </div>
3098
3099 <div class="vigilante-db-backup-actions">
3100 <button type="button" class="button button-primary vigilante-db-backup-download">
3101 <?php esc_html_e( 'Download Backup (.zip)', 'vigilante' ); ?>
3102 </button>
3103 </div>
3104 </div>
3105 </div>
3106 </div>
3107 <?php else : ?>
3108 <div class="vigilante-tool-card vigilante-tool-card-wide">
3109 <h3><?php esc_html_e( 'Database Backup', 'vigilante' ); ?></h3>
3110 <p><?php esc_html_e( 'Download a backup of your database as a ZIP file. Select which tables to include.', 'vigilante' ); ?></p>
3111 <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>
3112 </div>
3113 <?php endif; ?>
3114 </div>
3115 <?php
3116 }
3117
3118 /**
3119 * Render firewall tab
3120 */
3121 private function render_tab_firewall() {
3122 $is_disabled = $this->render_module_disabled_notice( 'firewall' );
3123 $options = $this->settings->get_section( 'firewall' );
3124 ?>
3125 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="firewall" <?php echo $is_disabled ? 'inert' : ''; ?>>
3126 <div id="vigilante-section-firewall-main" class="vigilante-settings-section">
3127 <h2>
3128 <?php esc_html_e( 'Firewall Protection', 'vigilante' ); ?>
3129 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
3130 </h2>
3131 <p><?php esc_html_e( 'PHP-based request filtering. Analyzes each request before WordPress loads.', 'vigilante' ); ?></p>
3132 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
3133 <p style="margin:0;">
3134 <?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' ); ?>
3135 </p>
3136 </div>
3137
3138 <?php $vg_main_locked = $this->main_site_files_locked(); ?>
3139 <?php if ( $vg_main_locked ) : ?>
3140 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
3141 <p style="margin:0;"><?php esc_html_e( 'On the main site of a network, blocking bad bots and bad query strings, the visitor IP detection and the two whitelists also build the .htaccess rules every site shares, so only a network administrator can change them.', 'vigilante' ); ?></p>
3142 </div>
3143 <?php endif; ?>
3144
3145 <table class="form-table">
3146 <tr>
3147 <th scope="row"><?php esc_html_e( 'Block Bad Query Strings', 'vigilante' ); ?></th>
3148 <td>
3149 <label>
3150 <input type="checkbox" name="firewall[block_bad_query_strings]" value="1" <?php disabled( $vg_main_locked ); ?> <?php checked( ! empty( $options['block_bad_query_strings'] ) ); ?>>
3151 <?php esc_html_e( 'Block malicious query string patterns', 'vigilante' ); ?>
3152 </label>
3153 </td>
3154 </tr>
3155 <tr>
3156 <th scope="row"><?php esc_html_e( 'SQL Injection Protection', 'vigilante' ); ?></th>
3157 <td>
3158 <label>
3159 <input type="checkbox" name="firewall[block_sql_injection]" value="1" <?php checked( ! empty( $options['block_sql_injection'] ) ); ?>>
3160 <?php esc_html_e( 'Block SQL injection attempts', 'vigilante' ); ?>
3161 </label>
3162 </td>
3163 </tr>
3164 <tr>
3165 <th scope="row"><?php esc_html_e( 'XSS Protection', 'vigilante' ); ?></th>
3166 <td>
3167 <label>
3168 <input type="checkbox" name="firewall[block_xss_attacks]" value="1" <?php checked( ! empty( $options['block_xss_attacks'] ) ); ?>>
3169 <?php esc_html_e( 'Block cross-site scripting attacks', 'vigilante' ); ?>
3170 </label>
3171 </td>
3172 </tr>
3173 <tr>
3174 <th scope="row"><?php esc_html_e( 'File Inclusion Protection', 'vigilante' ); ?></th>
3175 <td>
3176 <label>
3177 <input type="checkbox" name="firewall[block_file_inclusion]" value="1" <?php checked( ! empty( $options['block_file_inclusion'] ) ); ?>>
3178 <?php esc_html_e( 'Block local/remote file inclusion attempts', 'vigilante' ); ?>
3179 </label>
3180 </td>
3181 </tr>
3182 <tr>
3183 <th scope="row"><?php esc_html_e( 'Directory Traversal Protection', 'vigilante' ); ?></th>
3184 <td>
3185 <label>
3186 <input type="checkbox" name="firewall[block_directory_traversal]" value="1" <?php checked( ! empty( $options['block_directory_traversal'] ) ); ?>>
3187 <?php esc_html_e( 'Block path traversal attempts', 'vigilante' ); ?>
3188 </label>
3189 </td>
3190 </tr>
3191 <tr>
3192 <th scope="row"><?php esc_html_e( 'Block Bad Bots', 'vigilante' ); ?></th>
3193 <td>
3194 <label>
3195 <input type="checkbox" name="firewall[block_bad_bots]" value="1" <?php disabled( $vg_main_locked ); ?> <?php checked( ! empty( $options['block_bad_bots'] ) ); ?>>
3196 <?php esc_html_e( 'Block known malicious bots and scanners', 'vigilante' ); ?>
3197 </label>
3198 </td>
3199 </tr>
3200 </table>
3201
3202 <h3><?php esc_html_e( 'Rate Limiting', 'vigilante' ); ?></h3>
3203 <table class="form-table">
3204 <tr>
3205 <th scope="row"><?php esc_html_e( 'Enable Rate Limiting', 'vigilante' ); ?></th>
3206 <td>
3207 <label>
3208 <input type="checkbox" name="firewall[rate_limiting][enabled]" value="1" <?php checked( ! empty( $options['rate_limiting']['enabled'] ) ); ?>>
3209 <?php esc_html_e( 'Limit requests per IP address', 'vigilante' ); ?>
3210 </label>
3211 </td>
3212 </tr>
3213 <tr>
3214 <th scope="row"><label for="vigilante-f-firewall-rate-limiting-requests-per-minute"><?php esc_html_e( 'Requests per Minute', 'vigilante' ); ?></label></th>
3215 <td>
3216 <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">
3217 <p class="description">
3218 <?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' ); ?>
3219 </p>
3220 </td>
3221 </tr>
3222 <tr>
3223 <th scope="row"><label for="vigilante-f-firewall-rate-limiting-block-duration"><?php esc_html_e( 'Block Duration (seconds)', 'vigilante' ); ?></label></th>
3224 <td>
3225 <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">
3226 </td>
3227 </tr>
3228 <tr>
3229 <th scope="row"><?php esc_html_e( 'Progressive Blocking', 'vigilante' ); ?></th>
3230 <td>
3231 <label>
3232 <input type="checkbox" name="firewall[rate_limiting][progressive]" value="1" <?php checked( ! empty( $options['rate_limiting']['progressive'] ) ); ?>>
3233 <?php esc_html_e( 'Double block duration on each repeat offense', 'vigilante' ); ?>
3234 </label>
3235 <p class="description">
3236 <?php
3237 $base = absint( $options['rate_limiting']['block_duration'] ?? 300 );
3238 printf(
3239 /* translators: 1: First block duration, 2: Second, 3: Third */
3240 esc_html__( 'Example: %1$s → %2$s → %3$s and so on, up to the maximum.', 'vigilante' ),
3241 esc_html( human_time_diff( 0, $base ) ),
3242 esc_html( human_time_diff( 0, $base * 2 ) ),
3243 esc_html( human_time_diff( 0, $base * 4 ) )
3244 );
3245 ?>
3246 </p>
3247 </td>
3248 </tr>
3249 <tr>
3250 <th scope="row"><label for="vigilante-f-firewall-rate-limiting-max-block-duration"><?php esc_html_e( 'Maximum Block Duration', 'vigilante' ); ?></label></th>
3251 <td>
3252 <select id="vigilante-f-firewall-rate-limiting-max-block-duration" name="firewall[rate_limiting][max_block_duration]">
3253 <?php
3254 $max_options = array(
3255 3600 => __( '1 hour', 'vigilante' ),
3256 21600 => __( '6 hours', 'vigilante' ),
3257 43200 => __( '12 hours', 'vigilante' ),
3258 86400 => __( '24 hours', 'vigilante' ),
3259 604800 => __( '7 days', 'vigilante' ),
3260 );
3261 $current_max = absint( $options['rate_limiting']['max_block_duration'] ?? 86400 );
3262 foreach ( $max_options as $val => $label ) :
3263 ?>
3264 <option value="<?php echo esc_attr( $val ); ?>" <?php selected( $current_max, $val ); ?>>
3265 <?php echo esc_html( $label ); ?>
3266 </option>
3267 <?php endforeach; ?>
3268 </select>
3269 <p class="description"><?php esc_html_e( 'Upper limit for progressive blocking.', 'vigilante' ); ?></p>
3270 </td>
3271 </tr>
3272 </table>
3273
3274 <?php
3275 // Currently blocked IPs from rate limiting
3276 $active_blocks = Vigilante_Firewall::get_active_blocks();
3277 if ( ! empty( $active_blocks ) ) :
3278 ?>
3279 <div class="vigilante-settings-section vigilante-lockout-section" style="margin-top:20px;">
3280 <h3><?php esc_html_e( 'Currently Blocked IPs', 'vigilante' ); ?></h3>
3281 <table class="wp-list-table widefat fixed striped" style="max-width:800px;">
3282 <thead>
3283 <tr>
3284 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
3285 <th><?php esc_html_e( 'Blocked', 'vigilante' ); ?></th>
3286 <th><?php esc_html_e( 'Expires in', 'vigilante' ); ?></th>
3287 <th><?php esc_html_e( 'Strikes', 'vigilante' ); ?></th>
3288 <th><?php esc_html_e( 'Action', 'vigilante' ); ?></th>
3289 </tr>
3290 </thead>
3291 <tbody>
3292 <?php foreach ( $active_blocks as $blocked_ip => $block_data ) : ?>
3293 <tr>
3294 <td><code><?php echo esc_html( $blocked_ip ); ?></code></td>
3295 <td><?php echo esc_html( human_time_diff( $block_data['blocked_at'] ) . ' ' . __( 'ago', 'vigilante' ) ); ?></td>
3296 <td><?php echo esc_html( human_time_diff( time(), $block_data['expires'] ) ); ?></td>
3297 <td><?php echo esc_html( $block_data['strikes'] ?? 1 ); ?></td>
3298 <td>
3299 <button type="button" class="button button-small vigilante-unblock-firewall-ip"
3300 data-ip="<?php echo esc_attr( $blocked_ip ); ?>">
3301 <?php esc_html_e( 'Unblock', 'vigilante' ); ?>
3302 </button>
3303 </td>
3304 </tr>
3305 <?php endforeach; ?>
3306 </tbody>
3307 </table>
3308 </div>
3309 <?php endif; ?>
3310
3311 <h3><?php esc_html_e( 'IP Lists', 'vigilante' ); ?></h3>
3312 <p class="description">
3313 <?php
3314 printf(
3315 /* translators: %s: Current visitor IP address */
3316 esc_html__( 'Your current IP address: %s', 'vigilante' ),
3317 '<code>' . esc_html( $this->database->get_client_ip() ) . '</code>'
3318 );
3319 ?>
3320 </p>
3321 <table class="form-table">
3322 <tr>
3323 <th scope="row"><label for="vigilante-f-firewall-trusted-proxy-header"><?php esc_html_e( 'Visitor IP detection', 'vigilante' ); ?></label></th>
3324 <td>
3325 <?php $proxy_header = $options['trusted_proxy_header'] ?? ''; ?>
3326 <select id="vigilante-f-firewall-trusted-proxy-header" name="firewall[trusted_proxy_header]" <?php disabled( $vg_main_locked ); ?>>
3327 <option value="" <?php selected( $proxy_header, '' ); ?>><?php esc_html_e( 'Direct connection, only REMOTE_ADDR (recommended)', 'vigilante' ); ?></option>
3328 <option value="cf-connecting-ip" <?php selected( $proxy_header, 'cf-connecting-ip' ); ?>><?php esc_html_e( 'Behind Cloudflare (CF-Connecting-IP)', 'vigilante' ); ?></option>
3329 <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>
3330 <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>
3331 </select>
3332 <p class="description">
3333 <?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' ); ?>
3334 </p>
3335 </td>
3336 </tr>
3337 <tr>
3338 <th scope="row"><label for="vigilante-f-firewall-ip-whitelist"><?php esc_html_e( 'IP Whitelist', 'vigilante' ); ?></label></th>
3339 <td>
3340 <textarea id="vigilante-f-firewall-ip-whitelist" name="firewall[ip_whitelist]" <?php disabled( $vg_main_locked ); ?> 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>
3341 <p class="description">
3342 <?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' ); ?>
3343 <br>
3344 <?php
3345 printf(
3346 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the IP, CIDR and wildcard examples. */
3347 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' ),
3348 '<code>',
3349 '</code>'
3350 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
3351 ?>
3352 </p>
3353 </td>
3354 </tr>
3355 <tr>
3356 <th scope="row"><label for="vigilante-f-firewall-ip-blacklist"><?php esc_html_e( 'IP Blacklist', 'vigilante' ); ?></label></th>
3357 <td>
3358 <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>
3359 <p class="description">
3360 <?php esc_html_e( 'One IP per line. These IPs will be blocked immediately.', 'vigilante' ); ?>
3361 <br>
3362 <?php
3363 printf(
3364 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the IP, CIDR and wildcard examples. */
3365 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' ),
3366 '<code>',
3367 '</code>'
3368 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
3369 ?>
3370 </p>
3371 </td>
3372 </tr>
3373 </table>
3374
3375 <h3><?php esc_html_e( 'User-Agent Lists', 'vigilante' ); ?></h3>
3376 <p><?php esc_html_e( 'Partial matching: enter a keyword and any User-Agent containing it will be matched.', 'vigilante' ); ?></p>
3377 <table class="form-table">
3378 <tr>
3379 <th scope="row"><label for="vigilante-f-firewall-ua-whitelist"><?php esc_html_e( 'User-Agent Whitelist', 'vigilante' ); ?></label></th>
3380 <td>
3381 <textarea id="vigilante-f-firewall-ua-whitelist" name="firewall[ua_whitelist]" <?php disabled( $vg_main_locked ); ?> rows="4" class="large-text code"><?php echo esc_textarea( implode( "\n", $options['ua_whitelist'] ?? array() ) ); ?></textarea>
3382 <p class="description"><?php esc_html_e( 'One User-Agent per line. These will bypass all firewall checks. Example: ManageWP, MainWP, UptimeRobot.', 'vigilante' ); ?></p>
3383 </td>
3384 </tr>
3385 <tr>
3386 <th scope="row"><label for="vigilante-f-firewall-ua-blacklist"><?php esc_html_e( 'User-Agent Blacklist', 'vigilante' ); ?></label></th>
3387 <td>
3388 <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>
3389 <p class="description"><?php esc_html_e( 'One User-Agent per line. These will be blocked immediately.', 'vigilante' ); ?></p>
3390 </td>
3391 </tr>
3392 </table>
3393 </div>
3394
3395 <?php
3396 $vg_shared_locked = $this->shared_files_locked();
3397 // Paint what is actually in force, not this site's unused copy.
3398 $vg_local_options = $options;
3399 $options = $this->get_section_for_display( 'firewall' );
3400 ?>
3401 <?php $this->render_shared_files_notice(); ?>
3402 <div id="vigilante-section-firewall-server" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
3403 <h2>
3404 <?php esc_html_e( 'Server Protection', 'vigilante' ); ?>
3405 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
3406 </h2>
3407 <p><?php esc_html_e( 'Server-level rules for Apache/LiteSpeed. These rules are processed before PHP.', 'vigilante' ); ?></p>
3408
3409 <table class="form-table">
3410 <tr id="field-disable-directory-browsing">
3411 <th scope="row"><?php esc_html_e( 'Directory Browsing', 'vigilante' ); ?></th>
3412 <td>
3413 <label>
3414 <input type="checkbox" name="firewall[disable_directory_browsing]" value="1" <?php checked( ! empty( $options['disable_directory_browsing'] ) ); ?>>
3415 <?php esc_html_e( 'Disable directory listing (Options -Indexes)', 'vigilante' ); ?>
3416 </label>
3417 </td>
3418 </tr>
3419 <tr>
3420 <th scope="row"><?php esc_html_e( 'Protect wp-config.php', 'vigilante' ); ?></th>
3421 <td>
3422 <label>
3423 <input type="checkbox" name="firewall[protect_wp_config]" value="1" <?php checked( ! empty( $options['protect_wp_config'] ) ); ?>>
3424 <?php esc_html_e( 'Block direct HTTP access to wp-config.php', 'vigilante' ); ?>
3425 </label>
3426 </td>
3427 </tr>
3428 <tr id="field-protect-wp-cron">
3429 <th scope="row"><?php esc_html_e( 'Protect wp-cron.php', 'vigilante' ); ?></th>
3430 <td>
3431 <label>
3432 <input type="checkbox" name="firewall[protect_wp_cron]" value="1" <?php checked( ! empty( $options['protect_wp_cron'] ) ); ?>>
3433 <?php esc_html_e( 'Block direct HTTP access to wp-cron.php (prevents cron-spam DoS abuse)', 'vigilante' ); ?>
3434 </label>
3435 <p class="description"><?php
3436 printf(
3437 /* translators: 1: opening <strong>, 2: closing </strong> */
3438 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' ),
3439 '<strong>',
3440 '</strong>',
3441 '<code>',
3442 '</code>'
3443 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
3444 ?></p>
3445 </td>
3446 </tr>
3447 <tr>
3448 <th scope="row"><?php esc_html_e( 'Protect wp-includes', 'vigilante' ); ?></th>
3449 <td>
3450 <label>
3451 <input type="checkbox" name="firewall[protect_wp_includes]" value="1" <?php checked( ! empty( $options['protect_wp_includes'] ) ); ?>>
3452 <?php esc_html_e( 'Block direct access to PHP files in wp-includes', 'vigilante' ); ?>
3453 </label>
3454 </td>
3455 </tr>
3456 <tr>
3457 <th scope="row"><?php esc_html_e( 'PHP in Uploads', 'vigilante' ); ?></th>
3458 <td>
3459 <label>
3460 <input type="checkbox" name="firewall[protect_uploads_php]" value="1" <?php checked( ! empty( $options['protect_uploads_php'] ) ); ?>>
3461 <?php esc_html_e( 'Block PHP execution in wp-content/uploads', 'vigilante' ); ?>
3462 </label>
3463 </td>
3464 </tr>
3465 <tr>
3466 <th scope="row"><?php esc_html_e( 'Sensitive Files', 'vigilante' ); ?></th>
3467 <td>
3468 <label>
3469 <input type="checkbox" name="firewall[protect_sensitive_files]" value="1" <?php checked( ! empty( $options['protect_sensitive_files'] ) ); ?>>
3470 <?php esc_html_e( 'Block access to .sql, .bak, .log, .ini, readme.html, license.txt, licencia.txt', 'vigilante' ); ?>
3471 </label>
3472 </td>
3473 </tr>
3474 <tr>
3475 <th scope="row"><?php esc_html_e( 'Limit HTTP Methods', 'vigilante' ); ?></th>
3476 <td>
3477 <label>
3478 <input type="checkbox" name="firewall[limit_http_methods]" value="1" <?php checked( ! empty( $options['limit_http_methods'] ) ); ?>>
3479 <?php esc_html_e( 'Allow only GET, POST, HEAD (blocks PUT, DELETE, TRACE, etc.)', 'vigilante' ); ?>
3480 </label>
3481 </td>
3482 </tr>
3483 </table>
3484 </div>
3485 <?php $options = $vg_local_options; ?>
3486
3487 <p class="submit vigilante-submit-buttons">
3488 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
3489 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
3490 </button>
3491 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
3492 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
3493 </button>
3494 </p>
3495 </form>
3496 <?php
3497 }
3498
3499 /**
3500 * Render login security tab
3501 */
3502 private function render_tab_login() {
3503 $is_disabled = $this->render_module_disabled_notice( 'login_security' );
3504 $options = $this->settings->get_section( 'login_security' );
3505 $lockouts = $this->database->get_active_lockouts();
3506 ?>
3507 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="login_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
3508 <div id="vigilante-section-login-main" class="vigilante-settings-section">
3509 <h2>
3510 <?php esc_html_e( 'Login Protection', 'vigilante' ); ?>
3511 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
3512 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
3513 </h2>
3514 <p><?php esc_html_e( 'Brute force protection and WordPress login hardening.', 'vigilante' ); ?></p>
3515
3516 <table class="form-table">
3517 <tr id="field-max-attempts">
3518 <th scope="row"><label for="vigilante-f-login-security-max-attempts"><?php esc_html_e( 'Max Login Attempts', 'vigilante' ); ?></label></th>
3519 <td>
3520 <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">
3521 <p class="description"><?php esc_html_e( 'Number of failed attempts before lockout.', 'vigilante' ); ?></p>
3522 </td>
3523 </tr>
3524 <tr>
3525 <th scope="row"><label for="vigilante-f-login-security-lockout-duration"><?php esc_html_e( 'Lockout Duration', 'vigilante' ); ?></label></th>
3526 <td>
3527 <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">
3528 <?php esc_html_e( 'minutes', 'vigilante' ); ?>
3529 </td>
3530 </tr>
3531 <tr>
3532 <th scope="row"><?php esc_html_e( 'Progressive Lockout', 'vigilante' ); ?></th>
3533 <td>
3534 <label>
3535 <input type="checkbox" name="login_security[lockout_increment]" value="1" <?php checked( ! empty( $options['lockout_increment'] ) ); ?>>
3536 <?php esc_html_e( 'Double lockout duration for repeat offenders', 'vigilante' ); ?>
3537 </label>
3538 </td>
3539 </tr>
3540 <tr>
3541 <th scope="row"><?php esc_html_e( 'Hide Login Errors', 'vigilante' ); ?></th>
3542 <td>
3543 <label>
3544 <input type="checkbox" name="login_security[hide_login_errors]" value="1" <?php checked( ! empty( $options['hide_login_errors'] ) ); ?>>
3545 <?php esc_html_e( 'Show generic error message instead of specific errors', 'vigilante' ); ?>
3546 </label>
3547 </td>
3548 </tr>
3549 <tr>
3550 <th scope="row"><?php esc_html_e( 'Disable Application Passwords', 'vigilante' ); ?></th>
3551 <td>
3552 <label>
3553 <input type="checkbox" name="login_security[disable_application_passwords]" value="1" <?php checked( ! empty( $options['disable_application_passwords'] ) ); ?>>
3554 <?php esc_html_e( 'Disable WordPress application passwords feature', 'vigilante' ); ?>
3555 </label>
3556 </td>
3557 </tr>
3558 </table>
3559
3560 <h3><?php esc_html_e( 'Custom Login URL', 'vigilante' ); ?></h3>
3561 <table class="form-table">
3562 <tr id="field-custom-login-url">
3563 <th scope="row"><?php esc_html_e( 'Login URL Slug', 'vigilante' ); ?></th>
3564 <td>
3565 <code><?php echo esc_url( home_url( '/' ) ); ?></code>
3566 <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' ); ?>">
3567 <p class="description">
3568 <?php esc_html_e( '&#9432; Leave empty to use default wp-login.php. Use only lowercase letters, numbers and hyphens.', 'vigilante' ); ?>
3569 </p>
3570 <div class="vigilante-login-url-preview" <?php echo empty( $options['custom_login_url'] ) ? 'style="display:none;"' : ''; ?>>
3571 <p class="description">
3572 <strong><?php esc_html_e( 'Your login URL:', 'vigilante' ); ?></strong>
3573 <code class="vigilante-login-url-display"><?php echo esc_url( home_url( sanitize_title( $options['custom_login_url'] ?? '' ) . '/' ) ); ?></code>
3574 </p>
3575 <p class="description">
3576 <?php esc_html_e( 'Direct access to wp-login.php and wp-admin will return a 404 error for non-logged users.', 'vigilante' ); ?>
3577 </p>
3578 <p class="description">
3579 <?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' ); ?>
3580 </p>
3581 </div>
3582 </td>
3583 </tr>
3584 </table>
3585
3586 <div class="vigilante-login-url-notify-wrapper <?php echo empty( $options['custom_login_url'] ) ? 'vigilante-login-url-notify-disabled' : ''; ?>">
3587 <table class="form-table">
3588 <tr>
3589 <th scope="row"><?php esc_html_e( 'Notify users', 'vigilante' ); ?></th>
3590 <td>
3591 <label>
3592 <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 ); ?>>
3593 <?php esc_html_e( 'Notify affected users when the login URL changes', 'vigilante' ); ?>
3594 </label>
3595 <div class="vigilante-login-url-send-notification" style="margin-top:12px;">
3596 <button type="button" id="vigilante_notify_login_url" class="button">
3597 <?php esc_html_e( 'Send notification now', 'vigilante' ); ?>
3598 </button>
3599 <span class="vigilante-login-url-notify-status"></span>
3600 <p class="description"><?php esc_html_e( 'Sends the new URL to administrators, editors, authors, and contributors.', 'vigilante' ); ?></p>
3601 </div>
3602 </td>
3603 </tr>
3604 </table>
3605 </div>
3606
3607 <?php $this->render_2fa_settings( $options ); ?>
3608
3609 <h3><?php esc_html_e( 'Notifications', 'vigilante' ); ?></h3>
3610 <table class="form-table">
3611 <tr>
3612 <th scope="row"><?php esc_html_e( 'Notify on Lockout', 'vigilante' ); ?></th>
3613 <td>
3614 <label>
3615 <input type="checkbox" name="login_security[notify_on_lockout]" value="1" <?php checked( ! empty( $options['notify_on_lockout'] ) ); ?>>
3616 <?php esc_html_e( 'Send email when an IP is locked out', 'vigilante' ); ?>
3617 </label>
3618 </td>
3619 </tr>
3620 <tr>
3621 <th scope="row"><?php esc_html_e( 'Notify on Admin Login', 'vigilante' ); ?></th>
3622 <td>
3623 <label>
3624 <input type="checkbox" name="login_security[notify_on_admin_login]" value="1" <?php checked( ! empty( $options['notify_on_admin_login'] ) ); ?>>
3625 <?php esc_html_e( 'Send email when an administrator logs in', 'vigilante' ); ?>
3626 </label>
3627 </td>
3628 </tr>
3629 </table>
3630
3631 <p class="description">
3632 <?php
3633 printf(
3634 /* translators: %s: Link to notification settings */
3635 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
3636 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
3637 );
3638 ?>
3639 </p>
3640 </div>
3641
3642 <p class="submit vigilante-submit-buttons">
3643 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
3644 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
3645 </button>
3646 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
3647 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
3648 </button>
3649 </p>
3650 </form>
3651
3652 <?php $this->render_lockout_info_section( $options, $lockouts ); ?>
3653 <?php
3654 }
3655
3656 /**
3657 * Render lockout information and blocked IPs section
3658 *
3659 * @param array $options Login security options.
3660 * @param array $lockouts Currently locked out IPs.
3661 */
3662 private function render_lockout_info_section( $options, $lockouts ) {
3663 $max_attempts = absint( $options['max_attempts'] ?? 5 );
3664 $lockout_duration = absint( $options['lockout_duration'] ?? 1800 );
3665 $lockout_increment = ! empty( $options['lockout_increment'] );
3666 $max_lockout = absint( $options['max_lockout_duration'] ?? 86400 );
3667 $two_factor = $options['two_factor'] ?? array();
3668 $two_factor_enabled = ! empty( $two_factor['enabled'] );
3669 ?>
3670 <div class="vigilante-settings-section vigilante-lockout-section">
3671 <h2 id="vigilante-section-login-status"><?php esc_html_e( 'Login Protection Status', 'vigilante' ); ?></h2>
3672
3673 <table class="form-table">
3674 <tr>
3675 <th scope="row"><?php esc_html_e( 'Current settings', 'vigilante' ); ?></th>
3676 <td>
3677 <?php
3678 printf(
3679 /* translators: 1: Maximum login attempts, 2: Lockout duration in minutes */
3680 esc_html__( 'After %1$d failed login attempts, the IP address is blocked for %2$d minutes.', 'vigilante' ),
3681 absint( $max_attempts ),
3682 absint( ceil( $lockout_duration / 60 ) )
3683 );
3684
3685 if ( $lockout_increment ) {
3686 echo '<br>';
3687 printf(
3688 /* translators: %d: Maximum lockout duration in hours */
3689 esc_html__( 'Progressive lockout enabled (max: %d hours).', 'vigilante' ),
3690 absint( ceil( $max_lockout / 3600 ) )
3691 );
3692 }
3693
3694 if ( $two_factor_enabled ) {
3695 echo '<br>';
3696 esc_html_e( 'Failed 2FA codes also count toward the lockout limit.', 'vigilante' );
3697 }
3698 ?>
3699 </td>
3700 </tr>
3701 <tr>
3702 <th scope="row"><?php esc_html_e( 'Blocked IPs', 'vigilante' ); ?></th>
3703 <td>
3704 <?php if ( ! empty( $lockouts ) ) : ?>
3705 <div class="vigilante-paginated-section">
3706 <div class="vigilante-fi-pagination-wrap"></div>
3707 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
3708 <thead>
3709 <tr>
3710 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
3711 <th><?php esc_html_e( 'Attempts', 'vigilante' ); ?></th>
3712 <th><?php esc_html_e( 'Blocked Until', 'vigilante' ); ?></th>
3713 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
3714 </tr>
3715 </thead>
3716 <tbody>
3717 <?php foreach ( $lockouts as $lockout ) :
3718 $lockout_time = strtotime( $lockout->locked_until );
3719 $remaining_seconds = $lockout_time - time();
3720 $remaining_text = $this->format_remaining_time( $remaining_seconds );
3721 ?>
3722 <tr>
3723 <td><code><?php echo esc_html( $lockout->ip_address ); ?></code></td>
3724 <td><?php echo esc_html( $lockout->attempts ); ?></td>
3725 <td>
3726 <?php echo esc_html( wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $lockout_time ) ); ?>
3727 <br>
3728 <small class="description">
3729 <?php
3730 printf(
3731 /* translators: %s: Remaining time */
3732 esc_html__( '%s remaining', 'vigilante' ),
3733 esc_html( $remaining_text )
3734 );
3735 ?>
3736 </small>
3737 </td>
3738 <td>
3739 <button type="button" class="button button-small vigilante-clear-lockout" data-ip="<?php echo esc_attr( $lockout->ip_address ); ?>">
3740 <?php esc_html_e( 'Unblock', 'vigilante' ); ?>
3741 </button>
3742 </td>
3743 </tr>
3744 <?php endforeach; ?>
3745 </tbody>
3746 </table>
3747 </div>
3748 <p class="description" style="margin-top: 10px;">
3749 <button type="button" class="button vigilante-clear-all-lockouts">
3750 <?php esc_html_e( 'Unblock All IPs', 'vigilante' ); ?>
3751 </button>
3752 <span style="margin-left: 10px;">
3753 <?php
3754 printf(
3755 /* translators: %d: Number of blocked IPs */
3756 esc_html( _n( '%d IP currently blocked', '%d IPs currently blocked', count( $lockouts ), 'vigilante' ) ),
3757 count( $lockouts )
3758 );
3759 ?>
3760 </span>
3761 </p>
3762 <?php else : ?>
3763 <span class="dashicons dashicons-yes-alt" style="color: #00a32a; font-size: 20px; width: 20px; height: 20px; vertical-align: middle;"></span>
3764 <span style="vertical-align: middle; margin-left: 5px;"><?php esc_html_e( 'No IPs are currently blocked. All clear!', 'vigilante' ); ?></span>
3765 <?php endif; ?>
3766 </td>
3767 </tr>
3768 </table>
3769 </div>
3770 <?php
3771 }
3772
3773 /**
3774 * Format remaining lockout time in human readable format
3775 *
3776 * @param int $seconds Remaining seconds.
3777 * @return string Formatted time string.
3778 */
3779 private function format_remaining_time( $seconds ) {
3780 if ( $seconds <= 0 ) {
3781 return __( 'expired', 'vigilante' );
3782 }
3783
3784 if ( $seconds < 60 ) {
3785 return sprintf(
3786 /* translators: %d: Number of seconds */
3787 _n( '%d second', '%d seconds', $seconds, 'vigilante' ),
3788 $seconds
3789 );
3790 }
3791
3792 if ( $seconds < 3600 ) {
3793 $minutes = ceil( $seconds / 60 );
3794 return sprintf(
3795 /* translators: %d: Number of minutes */
3796 _n( '%d minute', '%d minutes', $minutes, 'vigilante' ),
3797 $minutes
3798 );
3799 }
3800
3801 $hours = floor( $seconds / 3600 );
3802 $remaining_minutes = ceil( ( $seconds % 3600 ) / 60 );
3803
3804 if ( $remaining_minutes > 0 ) {
3805 return sprintf(
3806 /* translators: 1: Number of hours, 2: Number of minutes */
3807 __( '%1$d hours %2$d minutes', 'vigilante' ),
3808 $hours,
3809 $remaining_minutes
3810 );
3811 }
3812
3813 return sprintf(
3814 /* translators: %d: Number of hours */
3815 _n( '%d hour', '%d hours', $hours, 'vigilante' ),
3816 $hours
3817 );
3818 }
3819
3820 /**
3821 * Render 2FA settings section
3822 *
3823 * @param array $options Login security options.
3824 */
3825 private function render_2fa_settings( $options ) {
3826 $two_factor = $options['two_factor'] ?? array();
3827 $all_roles = wp_roles()->roles;
3828 $enforced = $two_factor['enforced_roles'] ?? array( 'administrator', 'editor' );
3829 $excluded = $two_factor['excluded_users'] ?? array();
3830 $method = $two_factor['method'] ?? 'email';
3831 $grace_days = $two_factor['grace_period_days'] ?? 3;
3832 ?>
3833 <h3 id="vigilante-section-login-2fa">
3834 <?php esc_html_e( 'Two-Factor Authentication (2FA)', 'vigilante' ); ?>
3835 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
3836 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
3837 </h3>
3838 <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>
3839
3840 <table class="form-table">
3841 <tr>
3842 <th scope="row"><?php esc_html_e( 'Enable 2FA', 'vigilante' ); ?></th>
3843 <td>
3844 <label>
3845 <input type="checkbox" name="login_security[two_factor][enabled]" id="vigilante_2fa_enabled" value="1" <?php checked( ! empty( $two_factor['enabled'] ) ); ?>>
3846 <?php esc_html_e( 'Enable two-factor authentication', 'vigilante' ); ?>
3847 </label>
3848 </td>
3849 </tr>
3850 </table>
3851
3852 <div class="vigilante-2fa-settings-wrapper <?php echo empty( $two_factor['enabled'] ) ? 'vigilante-2fa-settings-disabled' : ''; ?>">
3853 <table class="form-table">
3854 <tr>
3855 <th scope="row"><?php esc_html_e( 'Verification method', 'vigilante' ); ?></th>
3856 <td>
3857 <fieldset class="vigilante-2fa-method-selector">
3858 <label class="vigilante-2fa-method-option <?php echo 'email' === $method ? 'selected' : ''; ?>">
3859 <input type="radio" name="login_security[two_factor][method]" value="email" <?php checked( $method, 'email' ); ?>>
3860 <span class="dashicons dashicons-email"></span>
3861 <span class="method-info">
3862 <strong><?php esc_html_e( 'Email code', 'vigilante' ); ?></strong>
3863 <span><?php esc_html_e( 'Users receive a 6-digit code via email after entering their password.', 'vigilante' ); ?></span>
3864 </span>
3865 </label>
3866 <label class="vigilante-2fa-method-option <?php echo 'totp' === $method ? 'selected' : ''; ?>">
3867 <input type="radio" name="login_security[two_factor][method]" value="totp" <?php checked( $method, 'totp' ); ?>>
3868 <span class="dashicons dashicons-smartphone"></span>
3869 <span class="method-info">
3870 <strong><?php esc_html_e( 'Authenticator app (TOTP)', 'vigilante' ); ?></strong>
3871 <span><?php esc_html_e( 'Users verify with a time-based code from Google Authenticator, Authy, etc.', 'vigilante' ); ?></span>
3872 </span>
3873 </label>
3874 </fieldset>
3875 </td>
3876 </tr>
3877 <tr>
3878 <th scope="row"><?php esc_html_e( 'Enforce for roles', 'vigilante' ); ?></th>
3879 <td>
3880 <div class="vigilante-2fa-roles">
3881 <?php foreach ( $all_roles as $role_slug => $role_data ) :
3882 $user_count = count( get_users( array( 'role' => $role_slug, 'fields' => 'ID' ) ) );
3883 ?>
3884 <label>
3885 <input type="checkbox"
3886 name="login_security[two_factor][enforced_roles][]"
3887 value="<?php echo esc_attr( $role_slug ); ?>"
3888 <?php checked( in_array( $role_slug, $enforced, true ) ); ?>>
3889 <span class="role-name"><?php echo esc_html( translate_user_role( $role_data['name'] ) ); ?></span>
3890 <span class="role-count">(<?php echo esc_html( $user_count ); ?>)</span>
3891 </label>
3892 <?php endforeach; ?>
3893 </div>
3894 <p class="description"><?php esc_html_e( 'Users with these roles will be required to verify with the selected method.', 'vigilante' ); ?></p>
3895 </td>
3896 </tr>
3897 <tr>
3898 <th scope="row"><?php esc_html_e( 'Exclude specific users', 'vigilante' ); ?></th>
3899 <td>
3900 <div class="vigilante-2fa-user-search-container">
3901 <div class="vigilante-2fa-user-search">
3902 <span class="search-icon"></span>
3903 <input type="text"
3904 id="vigilante_2fa_user_search"
3905 placeholder="<?php esc_attr_e( 'Search users by name or email...', 'vigilante' ); ?>"
3906 autocomplete="off">
3907 <div class="vigilante-2fa-search-results"></div>
3908 </div>
3909 <div class="vigilante-2fa-excluded-users">
3910 <?php
3911 foreach ( $excluded as $user_id ) :
3912 $user = get_user_by( 'ID', $user_id );
3913 if ( ! $user ) continue;
3914 ?>
3915 <div class="vigilante-2fa-excluded-user" data-user-id="<?php echo esc_attr( $user_id ); ?>">
3916 <span class="user-display"><?php echo esc_html( $user->display_name . ' (' . $user->user_email . ')' ); ?></span>
3917 <button type="button" class="remove-user" aria-label="<?php esc_attr_e( 'Remove', 'vigilante' ); ?>">&times;</button>
3918 <input type="hidden" name="login_security[two_factor][excluded_users][]" value="<?php echo esc_attr( $user_id ); ?>">
3919 </div>
3920 <?php endforeach; ?>
3921 </div>
3922 </div>
3923 <p class="description"><?php esc_html_e( 'These users will not be required to use 2FA regardless of their role.', 'vigilante' ); ?></p>
3924 </td>
3925 </tr>
3926
3927 <!-- Remember device option -->
3928 <tr>
3929 <th scope="row"><?php esc_html_e( 'Remember device', 'vigilante' ); ?></th>
3930 <td>
3931 <label>
3932 <input type="checkbox" name="login_security[two_factor][allow_remember_device]" value="1" <?php checked( ! empty( $two_factor['allow_remember_device'] ) ); ?>>
3933 <?php esc_html_e( 'Allow users to skip 2FA verification on trusted devices', 'vigilante' ); ?>
3934 </label>
3935 <p class="description">
3936 <?php
3937 printf(
3938 /* translators: %d: Number of days */
3939 esc_html__( 'When enabled, users can check "Remember this device" on the verification screen to skip 2FA for %d days.', 'vigilante' ),
3940 absint( $two_factor['remember_device_days'] ?? 30 )
3941 );
3942 ?>
3943 </p>
3944 </td>
3945 </tr>
3946
3947 <!-- TOTP-specific: Grace period -->
3948 <tr class="vigilante-2fa-totp-only" <?php echo 'totp' !== $method ? 'style="display:none;"' : ''; ?>>
3949 <th scope="row"><label for="vigilante-f-login-security-two-factor-grace-period-days"><?php esc_html_e( 'Grace period', 'vigilante' ); ?></label></th>
3950 <td>
3951 <input id="vigilante-f-login-security-two-factor-grace-period-days" type="number"
3952 name="login_security[two_factor][grace_period_days]"
3953 value="<?php echo esc_attr( $grace_days ); ?>"
3954 min="0" max="30" class="small-text">
3955 <?php esc_html_e( 'days', 'vigilante' ); ?>
3956 <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>
3957 </td>
3958 </tr>
3959
3960 <!-- Email-specific: Sender name -->
3961 <tr class="vigilante-2fa-email-only" <?php echo 'email' !== $method ? 'style="display:none;"' : ''; ?>>
3962 <th scope="row"><label for="vigilante-f-login-security-two-factor-email-from-name"><?php esc_html_e( 'Email sender name', 'vigilante' ); ?></label></th>
3963 <td>
3964 <input id="vigilante-f-login-security-two-factor-email-from-name" type="text"
3965 name="login_security[two_factor][email_from_name]"
3966 value="<?php echo esc_attr( $two_factor['email_from_name'] ?? '' ); ?>"
3967 class="regular-text vigilante-2fa-email-from"
3968 placeholder="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>">
3969 <p class="description"><?php esc_html_e( 'Name shown in verification emails. Leave empty to use site name.', 'vigilante' ); ?></p>
3970 </td>
3971 </tr>
3972
3973 <!-- TOTP-specific: Reset users -->
3974 <tr class="vigilante-2fa-totp-only" <?php echo 'totp' !== $method ? 'style="display:none;"' : ''; ?>>
3975 <th scope="row"><?php esc_html_e( 'Reset user TOTP', 'vigilante' ); ?></th>
3976 <td>
3977 <div class="vigilante-totp-reset-container">
3978 <div class="vigilante-2fa-user-search">
3979 <span class="search-icon"></span>
3980 <input type="text"
3981 id="vigilante_totp_reset_search"
3982 placeholder="<?php esc_attr_e( 'Search users with TOTP configured...', 'vigilante' ); ?>"
3983 autocomplete="off">
3984 <div class="vigilante-totp-reset-results"></div>
3985 </div>
3986 <div class="vigilante-totp-reset-selected"></div>
3987 <button type="button" id="vigilante_totp_reset_btn" class="button" style="display:none;">
3988 <?php esc_html_e( 'Reset selected', 'vigilante' ); ?>
3989 </button>
3990 <span class="vigilante-totp-reset-status"></span>
3991 </div>
3992 <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>
3993 </td>
3994 </tr>
3995 </table>
3996
3997 <h3><?php esc_html_e( 'User notification', 'vigilante' ); ?></h3>
3998 <table class="form-table">
3999 <tr>
4000 <th scope="row"><?php esc_html_e( 'Notify on enable', 'vigilante' ); ?></th>
4001 <td>
4002 <label>
4003 <input type="checkbox" name="login_security[two_factor][notify_on_enable]" value="1" <?php checked( $two_factor['notify_on_enable'] ?? true ); ?>>
4004 <?php esc_html_e( 'Send notification email to affected users when 2FA is enabled', 'vigilante' ); ?>
4005 </label>
4006
4007 <div class="vigilante-2fa-notification-options">
4008 <label>
4009 <input type="radio" name="vigilante_2fa_notify_mode" value="all" checked>
4010 <?php esc_html_e( 'Send to all affected users', 'vigilante' ); ?>
4011 </label>
4012 <label>
4013 <input type="radio" name="vigilante_2fa_notify_mode" value="new">
4014 <?php esc_html_e( 'Send only to users not previously notified', 'vigilante' ); ?>
4015 </label>
4016 </div>
4017
4018 <div class="vigilante-2fa-send-notification">
4019 <button type="button" id="vigilante_2fa_send_notification" class="button">
4020 <?php esc_html_e( 'Send notification now', 'vigilante' ); ?>
4021 </button>
4022 <span class="vigilante-2fa-notification-status"></span>
4023 </div>
4024 </td>
4025 </tr>
4026 </table>
4027 </div>
4028 <?php
4029 }
4030
4031 /**
4032 * Render security headers tab
4033 */
4034 /**
4035 * Offer back the header settings the 2.9.8 migration wiped.
4036 *
4037 * Rendered outside the settings form on purpose, so its buttons can never
4038 * submit it, and only when there is something to actually change. Shows the
4039 * difference before anything is written: nothing is applied that the owner
4040 * has not seen first.
4041 *
4042 * @since 2.10.0
4043 */
4044 private function render_headers_recovery_offer() {
4045 /*
4046 * On a network the .htaccess belongs to every site and only the main one
4047 * writes it, so this is not a decision a subsite gets to make. Its own
4048 * security_headers options are inert anyway: what the network serves
4049 * comes from the file the main site owns. Without this gate a subsite
4050 * administrator was shown a Restore button that could only ever answer
4051 * with a permission error, which is worse than showing nothing.
4052 */
4053 if ( ! Vigilante_Settings::can_write_shared_files() ) {
4054 return;
4055 }
4056
4057 if ( ! Vigilante_Htaccess_Recovery::is_available() ) {
4058 /*
4059 * Already restored. Offer to take it back for as long as the previous
4060 * section is still stored: a restore that cannot be undone is a second
4061 * irreversible change on top of the one being repaired.
4062 */
4063 if ( Vigilante_Htaccess_Recovery::has_undo() ) {
4064 ?>
4065 <div class="notice notice-info inline" id="vigilante-headers-recovery-undo">
4066 <p>
4067 <?php esc_html_e( 'The Security Headers settings were restored from the copy Vigilant had kept of your .htaccess.', 'vigilante' ); ?>
4068 <button type="button" class="button button-small" id="vigilante-recovery-undo">
4069 <?php esc_html_e( 'Undo the restore', 'vigilante' ); ?>
4070 </button>
4071 </p>
4072 </div>
4073 <?php
4074 }
4075
4076 return;
4077 }
4078
4079 $rows = Vigilante_Htaccess_Recovery::get_diff( $this->settings );
4080
4081 if ( empty( $rows ) ) {
4082 return;
4083 }
4084
4085 $snapshot = Vigilante_Htaccess_Recovery::get_snapshot();
4086 $taken = isset( $snapshot['time'] ) ? (int) $snapshot['time'] : 0;
4087 $block = Vigilante_Htaccess_Recovery::get_raw_block();
4088 ?>
4089 <div class="vigilante-settings-section" id="vigilante-headers-recovery">
4090 <h2><?php esc_html_e( 'Recover your previous header settings', 'vigilante' ); ?></h2>
4091 <p>
4092 <?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' ); ?>
4093 </p>
4094 <?php if ( $taken ) : ?>
4095 <p class="description">
4096 <?php
4097 printf(
4098 /* translators: %s: date and time the .htaccess copy was taken. */
4099 esc_html__( 'Copy taken on %s.', 'vigilante' ),
4100 esc_html( wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $taken ) )
4101 );
4102 ?>
4103 </p>
4104 <?php endif; ?>
4105
4106 <table class="widefat striped">
4107 <thead>
4108 <tr>
4109 <th scope="col"><?php esc_html_e( 'Setting', 'vigilante' ); ?></th>
4110 <th scope="col"><?php esc_html_e( 'Now', 'vigilante' ); ?></th>
4111 <th scope="col"><?php esc_html_e( 'Would be restored to', 'vigilante' ); ?></th>
4112 </tr>
4113 </thead>
4114 <tbody>
4115 <?php foreach ( $rows as $row ) : ?>
4116 <tr>
4117 <th scope="row"><?php echo esc_html( $row['label'] ); ?></th>
4118 <td><?php echo esc_html( $row['current'] ); ?></td>
4119 <td>
4120 <?php echo esc_html( $row['recovered'] ); ?>
4121 <?php if ( ! empty( $row['detail'] ) ) : ?>
4122 <br><span class="description"><?php echo esc_html( $row['detail'] ); ?></span>
4123 <?php endif; ?>
4124 </td>
4125 </tr>
4126 <?php endforeach; ?>
4127 </tbody>
4128 </table>
4129
4130 <p class="description">
4131 <?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' ); ?>
4132 </p>
4133
4134 <?php if ( '' !== $block ) : ?>
4135 <details>
4136 <summary><?php esc_html_e( 'Show the saved .htaccess block', 'vigilante' ); ?></summary>
4137 <textarea readonly rows="12" class="large-text code" onclick="this.select();"><?php echo esc_textarea( $block ); ?></textarea>
4138 </details>
4139 <?php endif; ?>
4140
4141 <p class="submit vigilante-submit-buttons">
4142 <button type="button" class="button button-primary" id="vigilante-recovery-restore">
4143 <?php esc_html_e( 'Restore these settings', 'vigilante' ); ?>
4144 </button>
4145 <button type="button" class="button" id="vigilante-recovery-dismiss">
4146 <?php esc_html_e( 'No thanks, keep what I have', 'vigilante' ); ?>
4147 </button>
4148 </p>
4149 <div id="vigilante-recovery-result"></div>
4150 </div>
4151 <?php
4152 }
4153
4154 private function render_tab_headers() {
4155 $is_disabled = $this->render_module_disabled_notice( 'security_headers' );
4156 // Every setting on this tab ends up in .htaccess, so on a subsite the
4157 // whole tab is somebody else's, values included.
4158 $vg_shared_locked = $this->shared_files_locked();
4159 $options = $this->get_section_for_display( 'security_headers' );
4160 ?>
4161 <?php $this->render_headers_recovery_offer(); ?>
4162
4163 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="security_headers" <?php echo $is_disabled ? 'inert' : ''; ?>>
4164 <?php $this->render_shared_files_notice(); ?>
4165 <div id="vigilante-section-headers-main" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
4166 <h2>
4167 <?php esc_html_e( 'Security Headers', 'vigilante' ); ?>
4168 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
4169 </h2>
4170 <p><?php esc_html_e( 'HTTP headers sent with every response via .htaccess (mod_headers).', 'vigilante' ); ?></p>
4171
4172 <table class="form-table">
4173 <tr>
4174 <th scope="row"><label for="vigilante-f-security-headers-x-frame-options"><?php esc_html_e( 'X-Frame-Options', 'vigilante' ); ?></label></th>
4175 <td>
4176 <select id="vigilante-f-security-headers-x-frame-options" name="security_headers[x_frame_options]">
4177 <option value="" <?php selected( empty( $options['x_frame_options'] ) ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
4178 <option value="SAMEORIGIN" <?php selected( $options['x_frame_options'] ?? '', 'SAMEORIGIN' ); ?>>SAMEORIGIN</option>
4179 <option value="DENY" <?php selected( $options['x_frame_options'] ?? '', 'DENY' ); ?>>DENY</option>
4180 </select>
4181 <p class="description"><?php esc_html_e( '&#9432; Prevents clickjacking attacks. Also sets CSP frame-ancestors automatically.', 'vigilante' ); ?></p>
4182 </td>
4183 </tr>
4184 <tr>
4185 <th scope="row"><?php esc_html_e( 'X-Content-Type-Options', 'vigilante' ); ?></th>
4186 <td>
4187 <label>
4188 <input type="checkbox" name="security_headers[x_content_type_options]" value="1" <?php checked( ! empty( $options['x_content_type_options'] ) ); ?>>
4189 <?php esc_html_e( 'Add nosniff header to prevent MIME type sniffing', 'vigilante' ); ?>
4190 </label>
4191 </td>
4192 </tr>
4193 <tr>
4194 <th scope="row"><label for="vigilante-f-security-headers-referrer-policy"><?php esc_html_e( 'Referrer-Policy', 'vigilante' ); ?></label></th>
4195 <td>
4196 <select id="vigilante-f-security-headers-referrer-policy" name="security_headers[referrer_policy]">
4197 <option value="" <?php selected( empty( $options['referrer_policy'] ) ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
4198 <option value="no-referrer" <?php selected( $options['referrer_policy'] ?? '', 'no-referrer' ); ?>>no-referrer</option>
4199 <option value="strict-origin-when-cross-origin" <?php selected( $options['referrer_policy'] ?? '', 'strict-origin-when-cross-origin' ); ?>>strict-origin-when-cross-origin</option>
4200 <option value="same-origin" <?php selected( $options['referrer_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
4201 </select>
4202 </td>
4203 </tr>
4204 </table>
4205
4206 <h3 id="vigilante-section-headers-csp"><?php esc_html_e( 'Content Security Policy', 'vigilante' ); ?></h3>
4207 <table class="form-table">
4208 <tr>
4209 <th scope="row"><?php esc_html_e( 'Enable CSP', 'vigilante' ); ?></th>
4210 <td>
4211 <label>
4212 <input type="checkbox" name="security_headers[csp][enabled]" value="1" <?php checked( ! empty( $options['csp']['enabled'] ) ); ?>>
4213 <?php esc_html_e( 'Enable Content Security Policy', 'vigilante' ); ?>
4214 </label>
4215 </td>
4216 </tr>
4217 <tr>
4218 <th scope="row"><?php esc_html_e( 'Report Only Mode', 'vigilante' ); ?></th>
4219 <td>
4220 <label>
4221 <input type="checkbox" name="security_headers[csp][report_only]" value="1" <?php checked( ! empty( $options['csp']['report_only'] ) ); ?>>
4222 <?php esc_html_e( 'Report violations without blocking (for testing)', 'vigilante' ); ?>
4223 </label>
4224 </td>
4225 </tr>
4226 </table>
4227
4228 <h3 id="vigilante-section-headers-force-https"><?php esc_html_e( 'HTTPS', 'vigilante' ); ?></h3>
4229 <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>
4230 <table class="form-table">
4231 <tr>
4232 <th scope="row"><?php esc_html_e( 'Redirect HTTP to HTTPS', 'vigilante' ); ?></th>
4233 <td>
4234 <label>
4235 <input type="checkbox" name="security_headers[redirect_http_to_https]" value="1" <?php checked( ! empty( $options['redirect_http_to_https'] ) ); ?>>
4236 <?php esc_html_e( 'Send visitors arriving over HTTP to the HTTPS address', 'vigilante' ); ?>
4237 </label>
4238 <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>
4239 </td>
4240 </tr>
4241 <tr>
4242 <th scope="row"><?php esc_html_e( 'Fix Mixed Content', 'vigilante' ); ?></th>
4243 <td>
4244 <label>
4245 <input type="checkbox" name="security_headers[fix_mixed_content]" value="1" <?php checked( ! empty( $options['fix_mixed_content'] ) ); ?>>
4246 <?php esc_html_e( 'Rewrite this site http:// resources to https://', 'vigilante' ); ?>
4247 </label>
4248 <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>
4249 </td>
4250 </tr>
4251 <tr id="field-upgrade-insecure-requests">
4252 <th scope="row"><?php esc_html_e( 'Upgrade Insecure Requests', 'vigilante' ); ?></th>
4253 <td>
4254 <label>
4255 <input type="checkbox" name="security_headers[upgrade_insecure_requests]" value="1" <?php checked( ! empty( $options['upgrade_insecure_requests'] ) ); ?>>
4256 <?php esc_html_e( 'Ask browsers to upgrade every http:// request to https://', 'vigilante' ); ?>
4257 </label>
4258 <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>
4259 </td>
4260 </tr>
4261 <tr>
4262 <th scope="row"><?php esc_html_e( 'Rewrite Site Address on Activation', 'vigilante' ); ?></th>
4263 <td>
4264 <label>
4265 <input type="checkbox" name="security_headers[force_https]" value="1" <?php checked( ! empty( $options['force_https'] ) ); ?>>
4266 <?php esc_html_e( 'Change the WordPress and site addresses to https:// when the plugin is activated', 'vigilante' ); ?>
4267 </label>
4268 <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>
4269 </td>
4270 </tr>
4271 </table>
4272
4273 <h3 id="vigilante-section-headers-hsts"><?php esc_html_e( 'HSTS (HTTP Strict Transport Security)', 'vigilante' ); ?></h3>
4274 <?php $vig_home_https = ( 0 === strpos( (string) get_option( 'home' ), 'https://' ) ); ?>
4275 <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>
4276 <?php if ( ! $vig_home_https ) : ?>
4277 <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>
4278 <?php endif; ?>
4279 <table class="form-table">
4280 <tr>
4281 <th scope="row"><?php esc_html_e( 'Enable HSTS', 'vigilante' ); ?></th>
4282 <td>
4283 <?php if ( ! $vig_home_https ) : ?>
4284 <?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. */ ?>
4285 <input type="hidden" name="security_headers[hsts][enabled]" value="<?php echo ! empty( $options['hsts']['enabled'] ) ? '1' : '0'; ?>">
4286 <?php endif; ?>
4287 <label>
4288 <input type="checkbox" name="security_headers[hsts][enabled]" value="1" <?php checked( ! empty( $options['hsts']['enabled'] ) ); ?> <?php disabled( ! $vig_home_https ); ?>>
4289 <?php esc_html_e( 'Send the Strict-Transport-Security header', 'vigilante' ); ?>
4290 </label>
4291 <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>
4292 </td>
4293 </tr>
4294 <tr>
4295 <th scope="row"><label for="vigilante-f-security-headers-hsts-max-age"><?php esc_html_e( 'Max Age', 'vigilante' ); ?></label></th>
4296 <td>
4297 <select id="vigilante-f-security-headers-hsts-max-age" name="security_headers[hsts][max_age]">
4298 <option value="86400" <?php selected( $options['hsts']['max_age'] ?? 31536000, 86400 ); ?>><?php esc_html_e( '1 day (testing)', 'vigilante' ); ?></option>
4299 <option value="2592000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 2592000 ); ?>><?php esc_html_e( '30 days', 'vigilante' ); ?></option>
4300 <option value="31536000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 31536000 ); ?>><?php esc_html_e( '1 year (recommended)', 'vigilante' ); ?></option>
4301 <option value="63072000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 63072000 ); ?>><?php esc_html_e( '2 years', 'vigilante' ); ?></option>
4302 </select>
4303 </td>
4304 </tr>
4305 <tr>
4306 <th scope="row"><?php esc_html_e( 'Include Subdomains', 'vigilante' ); ?></th>
4307 <td>
4308 <label>
4309 <input type="checkbox" name="security_headers[hsts][include_subdomains]" value="1" <?php checked( ! empty( $options['hsts']['include_subdomains'] ) ); ?>>
4310 <?php esc_html_e( 'Apply HSTS to all subdomains', 'vigilante' ); ?>
4311 </label>
4312 </td>
4313 </tr>
4314 </table>
4315
4316 <h3 id="vigilante-section-headers-fingerprint"><?php esc_html_e( 'Server Identity', 'vigilante' ); ?></h3>
4317 <p class="description"><?php esc_html_e( 'Hide identifying information that servers expose in responses.', 'vigilante' ); ?></p>
4318 <table class="form-table">
4319 <tr>
4320 <th scope="row"><?php esc_html_e( 'Server Signature', 'vigilante' ); ?></th>
4321 <td>
4322 <label>
4323 <input type="checkbox" name="security_headers[hide_server_signature]" value="1" <?php checked( ! empty( $options['hide_server_signature'] ) ); ?>>
4324 <?php esc_html_e( 'Hide server signature (ServerSignature Off)', 'vigilante' ); ?>
4325 </label>
4326 </td>
4327 </tr>
4328 <tr>
4329 <th scope="row"><?php esc_html_e( 'Remove Fingerprinting Headers', 'vigilante' ); ?></th>
4330 <td>
4331 <label>
4332 <input type="checkbox" name="security_headers[remove_fingerprinting_headers]" value="1" <?php checked( ! empty( $options['remove_fingerprinting_headers'] ) ); ?>>
4333 <?php esc_html_e( 'Remove X-Powered-By and Server headers', 'vigilante' ); ?>
4334 </label>
4335 </td>
4336 </tr>
4337 </table>
4338 </div>
4339
4340 <?php $vg_cop = ( isset( $options['cross_origin_policies'] ) && is_array( $options['cross_origin_policies'] ) ) ? $options['cross_origin_policies'] : array(); ?>
4341 <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' : ''; ?>>
4342 <h2>
4343 <?php esc_html_e( 'Cross-Origin Policies', 'vigilante' ); ?>
4344 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
4345 </h2>
4346 <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>
4347
4348 <table class="form-table">
4349 <tr>
4350 <th scope="row"><label for="vigilante-f-security-headers-coop"><?php esc_html_e( 'Cross-Origin-Opener-Policy (COOP)', 'vigilante' ); ?></label></th>
4351 <td>
4352 <select id="vigilante-f-security-headers-coop" name="security_headers[cross_origin_policies][opener_policy]">
4353 <option value="" <?php selected( empty( $vg_cop['opener_policy'] ) ); ?>><?php esc_html_e( 'Disabled (header not sent)', 'vigilante' ); ?></option>
4354 <option value="unsafe-none" <?php selected( $vg_cop['opener_policy'] ?? '', 'unsafe-none' ); ?>>unsafe-none</option>
4355 <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>
4356 <option value="same-origin" <?php selected( $vg_cop['opener_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
4357 </select>
4358 <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>
4359 </td>
4360 </tr>
4361 <tr>
4362 <th scope="row"><label for="vigilante-f-security-headers-coep"><?php esc_html_e( 'Cross-Origin-Embedder-Policy (COEP)', 'vigilante' ); ?></label></th>
4363 <td>
4364 <select id="vigilante-f-security-headers-coep" name="security_headers[cross_origin_policies][embedder_policy]">
4365 <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>
4366 <option value="credentialless" <?php selected( $vg_cop['embedder_policy'] ?? '', 'credentialless' ); ?>>credentialless</option>
4367 <option value="require-corp" <?php selected( $vg_cop['embedder_policy'] ?? '', 'require-corp' ); ?>>require-corp</option>
4368 </select>
4369 <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>
4370 </td>
4371 </tr>
4372 <tr>
4373 <th scope="row"><label for="vigilante-f-security-headers-corp"><?php esc_html_e( 'Cross-Origin-Resource-Policy (CORP)', 'vigilante' ); ?></label></th>
4374 <td>
4375 <select id="vigilante-f-security-headers-corp" name="security_headers[cross_origin_policies][resource_policy]">
4376 <option value="" <?php selected( empty( $vg_cop['resource_policy'] ) ); ?>><?php esc_html_e( 'Disabled (header not sent)', 'vigilante' ); ?></option>
4377 <option value="same-site" <?php selected( $vg_cop['resource_policy'] ?? '', 'same-site' ); ?>>same-site</option>
4378 <option value="same-origin" <?php selected( $vg_cop['resource_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
4379 <option value="cross-origin" <?php selected( $vg_cop['resource_policy'] ?? '', 'cross-origin' ); ?>><?php esc_html_e( 'cross-origin (recommended)', 'vigilante' ); ?></option>
4380 </select>
4381 <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>
4382 </td>
4383 </tr>
4384 </table>
4385 </div>
4386
4387 <p class="submit vigilante-submit-buttons">
4388 <?php if ( ! $vg_shared_locked ) : ?>
4389 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4390 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4391 </button>
4392 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4393 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4394 </button>
4395 <?php endif; ?>
4396 <?php /* Testing what the server actually sends is read-only and useful from any site of a network. */ ?>
4397 <button type="button" class="button vigilante-test-headers">
4398 <?php esc_html_e( 'Test Headers', 'vigilante' ); ?>
4399 </button>
4400 </p>
4401 </form>
4402
4403 <div id="vigilante-headers-result"></div>
4404 <?php
4405 }
4406
4407 /**
4408 * Render REST API tab
4409 */
4410 private function render_tab_rest_api() {
4411 $is_disabled = $this->render_module_disabled_notice( 'rest_api_security' );
4412 $options = $this->settings->get_section( 'rest_api_security' );
4413 ?>
4414 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="rest_api_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
4415 <div id="vigilante-section-rest-api-main" class="vigilante-settings-section">
4416 <h2>
4417 <?php esc_html_e( 'REST API Security', 'vigilante' ); ?>
4418 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4419 </h2>
4420 <p><?php esc_html_e( 'Control access to WordPress REST API endpoints.', 'vigilante' ); ?></p>
4421
4422 <table class="form-table">
4423 <tr>
4424 <th scope="row"><label for="vigilante-f-rest-api-security-mode"><?php esc_html_e( 'Access Mode', 'vigilante' ); ?></label></th>
4425 <td>
4426 <select id="vigilante-f-rest-api-security-mode" name="rest_api_security[mode]">
4427 <option value="open" <?php selected( $options['mode'] ?? 'selective', 'open' ); ?>><?php esc_html_e( 'Open - Allow all requests', 'vigilante' ); ?></option>
4428 <option value="selective" <?php selected( $options['mode'] ?? 'selective', 'selective' ); ?>><?php esc_html_e( 'Selective - Protect sensitive endpoints', 'vigilante' ); ?></option>
4429 <option value="authenticated_only" <?php selected( $options['mode'] ?? 'selective', 'authenticated_only' ); ?>><?php esc_html_e( 'Authenticated - Require login for all', 'vigilante' ); ?></option>
4430 </select>
4431 <p class="description"><?php esc_html_e( 'Selective mode is recommended.', 'vigilante' ); ?></p>
4432 </td>
4433 </tr>
4434 <tr id="field-block-user-enumeration">
4435 <th scope="row"><?php esc_html_e( 'Block User Enumeration', 'vigilante' ); ?></th>
4436 <td>
4437 <label>
4438 <input type="checkbox" name="rest_api_security[block_user_enumeration]" value="1" <?php checked( ! empty( $options['block_user_enumeration'] ) ); ?>>
4439 <?php esc_html_e( 'Protect /wp/v2/users endpoint for unauthenticated users', 'vigilante' ); ?>
4440 </label>
4441 </td>
4442 </tr>
4443 <tr>
4444 <th scope="row"><?php esc_html_e( 'Disable JSONP', 'vigilante' ); ?></th>
4445 <td>
4446 <label>
4447 <input type="checkbox" name="rest_api_security[disable_jsonp]" value="1" <?php checked( ! empty( $options['disable_jsonp'] ) ); ?>>
4448 <?php esc_html_e( 'Disable JSONP support in REST API', 'vigilante' ); ?>
4449 </label>
4450 </td>
4451 </tr>
4452 </table>
4453 </div>
4454
4455 <p class="submit vigilante-submit-buttons">
4456 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4457 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4458 </button>
4459 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4460 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4461 </button>
4462 </p>
4463 </form>
4464 <?php
4465 }
4466
4467 /**
4468 * Render User Security tab
4469 */
4470 private function render_tab_users() {
4471 $is_disabled = $this->render_module_disabled_notice( 'user_security' );
4472 $options = $this->settings->get_section( 'user_security' );
4473 $monitoring = $options['admin_monitoring'] ?? array();
4474 $registration = $options['registration_approval'] ?? array();
4475 $session_limits = $options['session_limits'] ?? array();
4476 $password_exp = $options['password_expiration'] ?? array();
4477 $email_verify = $options['email_verification'] ?? array();
4478 ?>
4479
4480 <!-- ============================================================
4481 SETTINGS SECTION - Single form for all configuration
4482 ============================================================ -->
4483 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="user_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
4484
4485 <!-- Username & Password Protection -->
4486 <div id="vigilante-section-users-password" class="vigilante-settings-section">
4487 <h2>
4488 <?php esc_html_e( 'Username & password protection', 'vigilante' ); ?>
4489 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4490 </h2>
4491 <p><?php esc_html_e( 'Enforce secure username and password policies.', 'vigilante' ); ?></p>
4492
4493 <table class="form-table">
4494 <tr>
4495 <th scope="row"><?php esc_html_e( 'Block Insecure Usernames', 'vigilante' ); ?></th>
4496 <td>
4497 <label>
4498 <input type="checkbox" name="user_security[block_insecure_usernames]" value="1" <?php checked( ! empty( $options['block_insecure_usernames'] ) ); ?>>
4499 <?php esc_html_e( 'Prevent creation of users with common usernames (admin, administrator, etc.)', 'vigilante' ); ?>
4500 </label>
4501 </td>
4502 </tr>
4503 <?php
4504 $pw_policy = wp_parse_args(
4505 ( isset( $options['password_policy'] ) && is_array( $options['password_policy'] ) ) ? $options['password_policy'] : array(),
4506 array(
4507 'require_uppercase' => false,
4508 'require_lowercase' => false,
4509 'require_number' => false,
4510 'require_special' => false,
4511 'block_common' => true,
4512 'block_username' => true,
4513 'affected_roles' => array(),
4514 )
4515 );
4516 $pw_policy_roles = (array) $pw_policy['affected_roles'];
4517 ?>
4518 <tr>
4519 <th scope="row"><?php esc_html_e( 'Enforce Strong Passwords', 'vigilante' ); ?></th>
4520 <td>
4521 <label>
4522 <input type="checkbox" name="user_security[force_strong_passwords]" value="1" <?php checked( ! empty( $options['force_strong_passwords'] ) ); ?>>
4523 <?php esc_html_e( 'Check passwords against the requirements below when a user sets or changes one', 'vigilante' ); ?>
4524 </label>
4525 </td>
4526 </tr>
4527 <tr>
4528 <th scope="row"><label for="vigilante-f-user-security-min-password-length"><?php esc_html_e( 'Minimum Password Length', 'vigilante' ); ?></label></th>
4529 <td>
4530 <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">
4531 <?php esc_html_e( 'characters', 'vigilante' ); ?>
4532 </td>
4533 </tr>
4534 <tr>
4535 <th scope="row"><?php esc_html_e( 'Password Requirements', 'vigilante' ); ?></th>
4536 <td>
4537 <label style="display:block;margin-bottom:5px;">
4538 <input type="checkbox" name="user_security[password_policy][require_uppercase]" value="1" <?php checked( ! empty( $pw_policy['require_uppercase'] ) ); ?>>
4539 <?php esc_html_e( 'Require an uppercase letter (A-Z)', 'vigilante' ); ?>
4540 </label>
4541 <label style="display:block;margin-bottom:5px;">
4542 <input type="checkbox" name="user_security[password_policy][require_lowercase]" value="1" <?php checked( ! empty( $pw_policy['require_lowercase'] ) ); ?>>
4543 <?php esc_html_e( 'Require a lowercase letter (a-z)', 'vigilante' ); ?>
4544 </label>
4545 <label style="display:block;margin-bottom:5px;">
4546 <input type="checkbox" name="user_security[password_policy][require_number]" value="1" <?php checked( ! empty( $pw_policy['require_number'] ) ); ?>>
4547 <?php esc_html_e( 'Require a number (0-9)', 'vigilante' ); ?>
4548 </label>
4549 <label style="display:block;margin-bottom:5px;">
4550 <input type="checkbox" name="user_security[password_policy][require_special]" value="1" <?php checked( ! empty( $pw_policy['require_special'] ) ); ?>>
4551 <?php esc_html_e( 'Require a special character (!, @, #, ...)', 'vigilante' ); ?>
4552 </label>
4553 <label style="display:block;margin-bottom:5px;">
4554 <input type="checkbox" name="user_security[password_policy][block_common]" value="1" <?php checked( ! empty( $pw_policy['block_common'] ) ); ?>>
4555 <?php esc_html_e( 'Reject well-known common passwords', 'vigilante' ); ?>
4556 </label>
4557 <label style="display:block;margin-bottom:5px;">
4558 <input type="checkbox" name="user_security[password_policy][block_username]" value="1" <?php checked( ! empty( $pw_policy['block_username'] ) ); ?>>
4559 <?php esc_html_e( 'Do not allow the username inside the password', 'vigilante' ); ?>
4560 </label>
4561 <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>
4562 </td>
4563 </tr>
4564 <tr>
4565 <th scope="row"><?php esc_html_e( 'Apply Password Rules To', 'vigilante' ); ?></th>
4566 <td>
4567 <?php foreach ( wp_roles()->get_names() as $role_slug => $role_name ) : ?>
4568 <label style="display:block;margin-bottom:5px;">
4569 <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 ) ); ?>>
4570 <?php echo esc_html( translate_user_role( $role_name ) ); ?>
4571 </label>
4572 <?php endforeach; ?>
4573 <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>
4574 </td>
4575 </tr>
4576 <tr id="field-block-author-scanning">
4577 <th scope="row"><?php esc_html_e( 'Block Author Scanning', 'vigilante' ); ?></th>
4578 <td>
4579 <label>
4580 <input type="checkbox" name="user_security[block_author_scanning]" value="1" <?php checked( ! empty( $options['block_author_scanning'] ) ); ?>>
4581 <?php esc_html_e( 'Prevent username discovery via ?author=N URLs', 'vigilante' ); ?>
4582 </label>
4583 </td>
4584 </tr>
4585 <tr>
4586 <th scope="row"><?php esc_html_e( 'Display Name Protection', 'vigilante' ); ?></th>
4587 <td>
4588 <label>
4589 <input type="checkbox" name="user_security[prevent_display_name_login_match]" value="1" <?php checked( ! empty( $options['prevent_display_name_login_match'] ) ); ?>>
4590 <?php esc_html_e( 'Prevent users from saving a display name that matches their login username', 'vigilante' ); ?>
4591 </label>
4592 <p class="description"><?php esc_html_e( 'The display name is publicly visible and should not reveal the login username.', 'vigilante' ); ?></p>
4593 </td>
4594 </tr>
4595 </table>
4596 </div>
4597
4598 <!-- Admin Monitoring -->
4599 <div id="vigilante-section-users-admin-monitoring" class="vigilante-settings-section">
4600 <h2>
4601 <?php esc_html_e( 'Admin monitoring', 'vigilante' ); ?>
4602 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4603 </h2>
4604 <p><?php esc_html_e( 'Receive email alerts when administrator accounts are modified. All events are always logged to the Security Audit.', 'vigilante' ); ?></p>
4605
4606 <table class="form-table">
4607 <tr>
4608 <th scope="row"><?php esc_html_e( 'New Administrator Alert', 'vigilante' ); ?></th>
4609 <td>
4610 <label>
4611 <input type="checkbox" name="user_security[admin_monitoring][alert_new_admin]" value="1" <?php checked( ! empty( $monitoring['alert_new_admin'] ) ); ?>>
4612 <?php esc_html_e( 'Send email alert when a new administrator account is created', 'vigilante' ); ?>
4613 </label>
4614 </td>
4615 </tr>
4616 <tr>
4617 <th scope="row"><?php esc_html_e( 'Admin Email Change Alert', 'vigilante' ); ?></th>
4618 <td>
4619 <label>
4620 <input type="checkbox" name="user_security[admin_monitoring][alert_admin_email_change]" value="1" <?php checked( ! empty( $monitoring['alert_admin_email_change'] ) ); ?>>
4621 <?php esc_html_e( 'Send email alert when an administrator email address is changed', 'vigilante' ); ?>
4622 </label>
4623 </td>
4624 </tr>
4625 <tr>
4626 <th scope="row"><?php esc_html_e( 'Permission Elevation Alert', 'vigilante' ); ?></th>
4627 <td>
4628 <label>
4629 <input type="checkbox" name="user_security[admin_monitoring][alert_permission_elevation]" value="1" <?php checked( ! empty( $monitoring['alert_permission_elevation'] ) ); ?>>
4630 <?php esc_html_e( 'Send email alert when a user is elevated to administrator role', 'vigilante' ); ?>
4631 </label>
4632 </td>
4633 </tr>
4634 <tr>
4635 <th scope="row"><?php esc_html_e( 'Admin Password Change Alert', 'vigilante' ); ?></th>
4636 <td>
4637 <label>
4638 <input type="checkbox" name="user_security[admin_monitoring][alert_admin_password_change]" value="1" <?php checked( ! empty( $monitoring['alert_admin_password_change'] ) ); ?>>
4639 <?php esc_html_e( 'Send email alert when an administrator password is changed', 'vigilante' ); ?>
4640 </label>
4641 </td>
4642 </tr>
4643 </table>
4644
4645 <p class="description">
4646 <?php
4647 printf(
4648 /* translators: %s: Link to notification settings */
4649 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
4650 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
4651 );
4652 ?>
4653 </p>
4654 </div>
4655
4656 <!-- Registration Approval -->
4657 <div id="vigilante-section-users-registration" class="vigilante-settings-section">
4658 <h2>
4659 <?php esc_html_e( 'Registration approval', 'vigilante' ); ?>
4660 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4661 </h2>
4662 <p><?php esc_html_e( 'Require manual approval for new user registrations.', 'vigilante' ); ?></p>
4663
4664 <table class="form-table">
4665 <tr>
4666 <th scope="row"><?php esc_html_e( 'Enable Registration Approval', 'vigilante' ); ?></th>
4667 <td>
4668 <label>
4669 <input type="checkbox" name="user_security[registration_approval][enabled]" value="1" <?php checked( ! empty( $registration['enabled'] ) ); ?>>
4670 <?php esc_html_e( 'New users must be approved by an administrator before they can log in', 'vigilante' ); ?>
4671 </label>
4672 </td>
4673 </tr>
4674 <tr>
4675 <th scope="row"><?php esc_html_e( 'Notify Admin', 'vigilante' ); ?></th>
4676 <td>
4677 <label>
4678 <input type="checkbox" name="user_security[registration_approval][notify_admin]" value="1" <?php checked( ! empty( $registration['notify_admin'] ) ); ?>>
4679 <?php esc_html_e( 'Send email notification when a new user registers', 'vigilante' ); ?>
4680 </label>
4681 <p class="description"><?php esc_html_e( 'Disable on high-traffic sites to avoid email overload.', 'vigilante' ); ?></p>
4682 </td>
4683 </tr>
4684 <tr>
4685 <th scope="row"><label for="vigilante-f-user-security-registration-approval-auto-reject-days"><?php esc_html_e( 'Auto-reject After', 'vigilante' ); ?></label></th>
4686 <td>
4687 <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">
4688 <?php esc_html_e( 'days (0 = never)', 'vigilante' ); ?>
4689 <p class="description"><?php esc_html_e( 'Automatically reject pending registrations after this many days.', 'vigilante' ); ?></p>
4690 </td>
4691 </tr>
4692 </table>
4693 </div>
4694
4695 <!-- Session Limits -->
4696 <div id="vigilante-section-users-sessions" class="vigilante-settings-section">
4697 <h2>
4698 <?php esc_html_e( 'Session limits', 'vigilante' ); ?>
4699 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4700 </h2>
4701 <p><?php esc_html_e( 'Limit the number of simultaneous sessions per user.', 'vigilante' ); ?></p>
4702
4703 <table class="form-table">
4704 <tr>
4705 <th scope="row"><?php esc_html_e( 'Enable Session Limits', 'vigilante' ); ?></th>
4706 <td>
4707 <label>
4708 <input type="checkbox" name="user_security[session_limits][enabled]" value="1" <?php checked( ! empty( $session_limits['enabled'] ) ); ?>>
4709 <?php esc_html_e( 'Limit the number of active sessions per user', 'vigilante' ); ?>
4710 </label>
4711 </td>
4712 </tr>
4713 <tr>
4714 <th scope="row"><label for="vigilante-f-user-security-session-limits-max-sessions"><?php esc_html_e( 'Maximum Sessions', 'vigilante' ); ?></label></th>
4715 <td>
4716 <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">
4717 <?php esc_html_e( 'sessions per user', 'vigilante' ); ?>
4718 </td>
4719 </tr>
4720 <tr>
4721 <th scope="row"><label for="vigilante-f-user-security-session-limits-behavior"><?php esc_html_e( 'When Limit Exceeded', 'vigilante' ); ?></label></th>
4722 <td>
4723 <select id="vigilante-f-user-security-session-limits-behavior" name="user_security[session_limits][behavior]">
4724 <option value="block_new" <?php selected( ( $session_limits['behavior'] ?? 'close_oldest' ), 'block_new' ); ?>><?php esc_html_e( 'Block new login', 'vigilante' ); ?></option>
4725 <option value="close_oldest" <?php selected( ( $session_limits['behavior'] ?? 'close_oldest' ), 'close_oldest' ); ?>><?php esc_html_e( 'Close oldest session', 'vigilante' ); ?></option>
4726 </select>
4727 <p class="description"><?php esc_html_e( '"Close oldest" is recommended for security - ensures attackers cannot lock out legitimate users.', 'vigilante' ); ?></p>
4728 </td>
4729 </tr>
4730 <tr>
4731 <th scope="row"><?php esc_html_e( 'Exclude Administrators', 'vigilante' ); ?></th>
4732 <td>
4733 <label>
4734 <input type="checkbox" name="user_security[session_limits][exclude_admins]" value="1" <?php checked( ! empty( $session_limits['exclude_admins'] ) ); ?>>
4735 <?php esc_html_e( 'Do not apply session limits to administrators', 'vigilante' ); ?>
4736 </label>
4737 </td>
4738 </tr>
4739 </table>
4740 </div>
4741
4742 <!-- Password Expiration -->
4743 <div id="vigilante-section-users-password-exp" class="vigilante-settings-section">
4744 <h2>
4745 <?php esc_html_e( 'Password expiration', 'vigilante' ); ?>
4746 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4747 </h2>
4748 <p><?php esc_html_e( 'Force users to change their password periodically.', 'vigilante' ); ?></p>
4749
4750 <table class="form-table">
4751 <tr>
4752 <th scope="row"><?php esc_html_e( 'Enable Password Expiration', 'vigilante' ); ?></th>
4753 <td>
4754 <label>
4755 <input type="checkbox" name="user_security[password_expiration][enabled]" value="1" <?php checked( ! empty( $password_exp['enabled'] ) ); ?>>
4756 <?php esc_html_e( 'Force password change after a set number of days', 'vigilante' ); ?>
4757 </label>
4758 </td>
4759 </tr>
4760 <tr>
4761 <th scope="row"><label for="vigilante-f-user-security-password-expiration-expire-days"><?php esc_html_e( 'Expire After', 'vigilante' ); ?></label></th>
4762 <td>
4763 <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">
4764 <?php esc_html_e( 'days', 'vigilante' ); ?>
4765 <p class="description"><?php esc_html_e( 'PCI-DSS recommends 90 days.', 'vigilante' ); ?></p>
4766 </td>
4767 </tr>
4768 <tr>
4769 <th scope="row"><label for="vigilante-f-user-security-password-expiration-warning-days"><?php esc_html_e( 'Warning Period', 'vigilante' ); ?></label></th>
4770 <td>
4771 <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">
4772 <?php esc_html_e( 'days before expiration', 'vigilante' ); ?>
4773 <p class="description"><?php esc_html_e( 'Show warning notice this many days before password expires.', 'vigilante' ); ?></p>
4774 </td>
4775 </tr>
4776 <tr>
4777 <th scope="row"><label for="vigilante-f-user-security-password-expiration-password-history"><?php esc_html_e( 'Password History', 'vigilante' ); ?></label></th>
4778 <td>
4779 <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">
4780 <?php esc_html_e( 'passwords to remember', 'vigilante' ); ?>
4781 <p class="description"><?php esc_html_e( 'Prevent reusing recent passwords. Set to 0 to disable.', 'vigilante' ); ?></p>
4782 </td>
4783 </tr>
4784 <tr>
4785 <th scope="row"><?php esc_html_e( 'Email Reminder', 'vigilante' ); ?></th>
4786 <td>
4787 <label>
4788 <input type="checkbox" name="user_security[password_expiration][send_reminder]" value="1" <?php checked( ! empty( $password_exp['send_reminder'] ) ); ?>>
4789 <?php esc_html_e( 'Send email reminder when password is about to expire', 'vigilante' ); ?>
4790 </label>
4791 <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>
4792 </td>
4793 </tr>
4794 <tr>
4795 <th scope="row"><?php esc_html_e( 'Affected Roles', 'vigilante' ); ?></th>
4796 <td>
4797 <?php
4798 $affected_roles = $password_exp['affected_roles'] ?? array( 'administrator', 'editor' );
4799 $all_roles = wp_roles()->get_names();
4800 foreach ( $all_roles as $role_slug => $role_name ) :
4801 ?>
4802 <label style="display: block; margin-bottom: 5px;">
4803 <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 ) ); ?>>
4804 <?php echo esc_html( translate_user_role( $role_name ) ); ?>
4805 </label>
4806 <?php endforeach; ?>
4807 </td>
4808 </tr>
4809 <tr>
4810 <th scope="row"><?php esc_html_e( 'Exclude specific users', 'vigilante' ); ?></th>
4811 <td>
4812 <?php $pwexp_excluded = $password_exp['excluded_users'] ?? array(); ?>
4813 <div class="vigilante-2fa-user-search-container">
4814 <div class="vigilante-2fa-user-search">
4815 <span class="search-icon"></span>
4816 <input type="text"
4817 id="vigilante_pwexp_user_search"
4818 placeholder="<?php esc_attr_e( 'Search users by name or email...', 'vigilante' ); ?>"
4819 autocomplete="off">
4820 <div class="vigilante-pwexp-search-results"></div>
4821 </div>
4822 <div class="vigilante-pwexp-excluded-users">
4823 <?php
4824 foreach ( $pwexp_excluded as $pwexp_excluded_id ) :
4825 $excluded_user = get_user_by( 'ID', $pwexp_excluded_id );
4826 if ( ! $excluded_user ) {
4827 continue;
4828 }
4829 ?>
4830 <div class="vigilante-pwexp-excluded-user" data-user-id="<?php echo esc_attr( $pwexp_excluded_id ); ?>">
4831 <span class="user-display"><?php echo esc_html( $excluded_user->display_name . ' (' . $excluded_user->user_email . ')' ); ?></span>
4832 <button type="button" class="remove-user" aria-label="<?php esc_attr_e( 'Remove', 'vigilante' ); ?>">&times;</button>
4833 <input type="hidden" name="user_security[password_expiration][excluded_users][]" value="<?php echo esc_attr( $pwexp_excluded_id ); ?>">
4834 </div>
4835 <?php endforeach; ?>
4836 </div>
4837 </div>
4838 <p class="description"><?php esc_html_e( 'Listed users will be excluded from password expiration regardless of their role.', 'vigilante' ); ?></p>
4839 </td>
4840 </tr>
4841 </table>
4842 </div>
4843
4844 <!-- Email Verification -->
4845 <div id="vigilante-section-users-email-verify" class="vigilante-settings-section">
4846 <h2>
4847 <?php esc_html_e( 'Email verification', 'vigilante' ); ?>
4848 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4849 </h2>
4850 <p><?php esc_html_e( 'Require new users to verify their email address before logging in.', 'vigilante' ); ?></p>
4851
4852 <table class="form-table">
4853 <tr>
4854 <th scope="row"><?php esc_html_e( 'Enable Email Verification', 'vigilante' ); ?></th>
4855 <td>
4856 <label>
4857 <input type="checkbox" name="user_security[email_verification][enabled]" value="1" <?php checked( ! empty( $email_verify['enabled'] ) ); ?>>
4858 <?php esc_html_e( 'New users must verify their email before logging in', 'vigilante' ); ?>
4859 </label>
4860 </td>
4861 </tr>
4862 <tr>
4863 <th scope="row"><label for="vigilante-f-user-security-email-verification-token-expiry-hours"><?php esc_html_e( 'Link Expiration', 'vigilante' ); ?></label></th>
4864 <td>
4865 <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">
4866 <?php esc_html_e( 'hours', 'vigilante' ); ?>
4867 </td>
4868 </tr>
4869 <tr>
4870 <th scope="row"><?php esc_html_e( 'Allow Resend', 'vigilante' ); ?></th>
4871 <td>
4872 <label>
4873 <input type="checkbox" name="user_security[email_verification][allow_resend]" value="1" <?php checked( ! empty( $email_verify['allow_resend'] ) ); ?>>
4874 <?php esc_html_e( 'Allow users to request a new verification email', 'vigilante' ); ?>
4875 </label>
4876 </td>
4877 </tr>
4878 <tr>
4879 <th scope="row"><label for="vigilante-f-user-security-email-verification-auto-delete-days"><?php esc_html_e( 'Auto-delete Unverified', 'vigilante' ); ?></label></th>
4880 <td>
4881 <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">
4882 <?php esc_html_e( 'days (0 = never)', 'vigilante' ); ?>
4883 <p class="description"><?php esc_html_e( 'Automatically delete users who never verify their email.', 'vigilante' ); ?></p>
4884 </td>
4885 </tr>
4886 </table>
4887 </div>
4888
4889 <p class="submit vigilante-submit-buttons">
4890 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4891 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4892 </button>
4893 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4894 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4895 </button>
4896 </p>
4897 </form>
4898
4899 <!-- ============================================================
4900 TOOLS SECTION - Actions and utilities (no save button)
4901 ============================================================ -->
4902 <div class="vigilante-tools-section">
4903 <h2 class="vigilante-tools-header">
4904 <?php esc_html_e( 'User security tools', 'vigilante' ); ?>
4905 </h2>
4906
4907 <?php $this->render_user_actions_notice(); ?>
4908 <?php if ( ! $this->user_actions_locked() ) : ?>
4909
4910 <!-- Force Password Reset -->
4911 <div class="vigilante-tool-box">
4912 <h3><?php esc_html_e( 'Force password reset', 'vigilante' ); ?></h3>
4913 <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>
4914
4915 <!-- Reset Specific Users -->
4916 <div class="vigilante-password-reset-box">
4917 <h4><?php esc_html_e( 'Reset specific users', 'vigilante' ); ?></h4>
4918
4919 <div class="vigilante-user-search-wrapper">
4920 <input type="text" id="vigilante-password-reset-search" class="regular-text" placeholder="<?php esc_attr_e( 'Search by username, email, or display name...', 'vigilante' ); ?>">
4921 <div id="vigilante-password-reset-results" class="vigilante-user-search-results" style="display: none;"></div>
4922 </div>
4923
4924 <div id="vigilante-password-reset-selected" class="vigilante-selected-users" style="display: none;">
4925 <strong><?php esc_html_e( 'Selected Users:', 'vigilante' ); ?></strong>
4926 <ul class="vigilante-selected-users-list"></ul>
4927 </div>
4928
4929 <p class="description" style="margin-top: 15px;">
4930 <span class="dashicons dashicons-email-alt" style="color: #2271b1;"></span>
4931 <?php esc_html_e( 'Selected users will receive an email with a password reset link.', 'vigilante' ); ?>
4932 </p>
4933
4934 <p class="submit">
4935 <button type="button" id="vigilante-reset-selected-users" class="button button-primary" disabled>
4936 <?php esc_html_e( 'Force Reset for Selected Users', 'vigilante' ); ?>
4937 </button>
4938 </p>
4939 </div>
4940
4941 <!-- Reset by Role -->
4942 <div class="vigilante-password-reset-box" style="margin-top: 20px; padding-top: 20px; border-top: 1px solid #ddd;">
4943 <h4><?php esc_html_e( 'Reset by role', 'vigilante' ); ?></h4>
4944 <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>
4945
4946 <?php
4947 $wp_roles = wp_roles();
4948 $user_counts = count_users();
4949 $avail_roles = $user_counts['avail_roles'] ?? array();
4950 $current_user = wp_get_current_user();
4951 $current_roles = $current_user->roles;
4952 ?>
4953
4954 <fieldset class="vigilante-role-checkboxes" style="margin-top: 10px;">
4955 <?php foreach ( $wp_roles->roles as $role_slug => $role_data ) :
4956 $count = $avail_roles[ $role_slug ] ?? 0;
4957 if ( 0 === $count ) {
4958 continue;
4959 }
4960 $role_name = translate_user_role( $role_data['name'] );
4961 ?>
4962 <label style="display: block; margin-bottom: 6px;">
4963 <input type="checkbox"
4964 class="vigilante-reset-role-checkbox"
4965 value="<?php echo esc_attr( $role_slug ); ?>"
4966 data-count="<?php echo absint( $count ); ?>">
4967 <?php
4968 printf(
4969 /* translators: 1: Role name, 2: Number of users */
4970 '%1$s <span class="description">(%2$d)</span>',
4971 esc_html( $role_name ),
4972 absint( $count )
4973 );
4974 ?>
4975 <?php if ( in_array( $role_slug, $current_roles, true ) ) : ?>
4976 <em class="description"><?php esc_html_e( '(includes you)', 'vigilante' ); ?></em>
4977 <?php endif; ?>
4978 </label>
4979 <?php endforeach; ?>
4980 </fieldset>
4981
4982 <div id="vigilante-reset-role-summary" style="display: none; margin-top: 10px;">
4983 <p>
4984 <span class="dashicons dashicons-groups" style="color: #2271b1;"></span>
4985 <strong id="vigilante-reset-role-count">0</strong>
4986 <?php esc_html_e( 'user(s) will be affected.', 'vigilante' ); ?>
4987 </p>
4988 </div>
4989
4990 <div class="vigilante-password-reset-options" id="vigilante-reset-role-self-option" style="display: none; margin-top: 10px;">
4991 <label>
4992 <input type="checkbox" id="vigilante-reset-role-include-self" value="1">
4993 <?php esc_html_e( 'Include myself (your current session will end)', 'vigilante' ); ?>
4994 </label>
4995 </div>
4996
4997 <p class="submit">
4998 <button type="button" id="vigilante-reset-by-role" class="button button-primary" disabled>
4999 <?php esc_html_e( 'Force Reset for Selected Roles', 'vigilante' ); ?>
5000 </button>
5001 </p>
5002 </div>
5003
5004 <!-- Reset All Users -->
5005 <div class="vigilante-password-reset-box" style="margin-top: 20px; padding-top: 20px; border-top: 1px solid #ddd;">
5006 <h4><?php esc_html_e( 'Reset all users', 'vigilante' ); ?></h4>
5007
5008 <?php
5009 $total_users = count_users();
5010 $total_count = $total_users['total_users'];
5011 ?>
5012 <p>
5013 <?php
5014 printf(
5015 /* translators: %d: Number of users */
5016 esc_html__( 'This will affect %d user(s).', 'vigilante' ),
5017 absint( $total_count )
5018 );
5019 ?>
5020 </p>
5021
5022 <p class="description" style="color: #d63638;">
5023 <span class="dashicons dashicons-warning"></span>
5024 <?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' ); ?>
5025 </p>
5026
5027 <div class="vigilante-password-reset-options" style="margin-top: 10px;">
5028 <label>
5029 <input type="checkbox" id="vigilante-reset-all-include-self" value="1">
5030 <?php esc_html_e( 'Include myself (your current session will end)', 'vigilante' ); ?>
5031 </label>
5032 </div>
5033
5034 <p class="submit">
5035 <button type="button" id="vigilante-reset-all-users" class="button" style="color: #d63638; border-color: #d63638;">
5036 <?php esc_html_e( 'Force Reset for ALL Users', 'vigilante' ); ?>
5037 </button>
5038 </p>
5039 </div>
5040 </div>
5041
5042 <!-- Pending Registrations -->
5043 <?php
5044 $user_security = new Vigilante_User_Security( $this->settings, $this->activity_log );
5045 $pending_users = $user_security->get_pending_users();
5046 ?>
5047 <div id="vigilante-section-users-pending" class="vigilante-tool-box vigilante-pending-users-section">
5048 <h3>
5049 <?php esc_html_e( 'Pending registrations', 'vigilante' ); ?>
5050 <?php if ( count( $pending_users ) > 0 ) : ?>
5051 <span class="vigilante-badge vigilante-badge-warning"><?php echo esc_html( count( $pending_users ) ); ?></span>
5052 <?php endif; ?>
5053 </h3>
5054
5055 <?php if ( empty( $registration['enabled'] ) ) : ?>
5056 <p class="description">
5057 <span class="dashicons dashicons-info" style="color: #72aee6;"></span>
5058 <?php esc_html_e( 'Registration approval is disabled. Enable it in the settings above to require manual approval for new users.', 'vigilante' ); ?>
5059 </p>
5060 <?php elseif ( empty( $pending_users ) ) : ?>
5061 <div class="vigilante-no-lockouts">
5062 <span class="dashicons dashicons-yes-alt"></span>
5063 <p><?php esc_html_e( 'No pending registrations.', 'vigilante' ); ?></p>
5064 </div>
5065 <?php else : ?>
5066 <table class="wp-list-table widefat fixed striped vigilante-pending-users-table">
5067 <thead>
5068 <tr>
5069 <th><?php esc_html_e( 'User', 'vigilante' ); ?></th>
5070 <th><?php esc_html_e( 'Email', 'vigilante' ); ?></th>
5071 <th><?php esc_html_e( 'Registered', 'vigilante' ); ?></th>
5072 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5073 </tr>
5074 </thead>
5075 <tbody>
5076 <?php foreach ( $pending_users as $pending_user ) :
5077 $pending_since = get_user_meta( $pending_user->ID, 'vigilante_pending_since', true );
5078 ?>
5079 <tr data-user-id="<?php echo esc_attr( $pending_user->ID ); ?>">
5080 <td>
5081 <?php echo get_avatar( $pending_user->ID, 32 ); ?>
5082 <strong><?php echo esc_html( $pending_user->user_login ); ?></strong>
5083 </td>
5084 <td><?php echo esc_html( $pending_user->user_email ); ?></td>
5085 <td>
5086 <?php
5087 if ( $pending_since ) {
5088 /* translators: %s: Time ago */
5089 printf( esc_html__( '%s ago', 'vigilante' ), esc_html( human_time_diff( $pending_since ) ) );
5090 } else {
5091 echo esc_html( $pending_user->user_registered );
5092 }
5093 ?>
5094 </td>
5095 <td>
5096 <button type="button" class="button button-small vigilante-approve-user" data-user-id="<?php echo esc_attr( $pending_user->ID ); ?>">
5097 <?php esc_html_e( 'Approve', 'vigilante' ); ?>
5098 </button>
5099 <button type="button" class="button button-small vigilante-reject-user" data-user-id="<?php echo esc_attr( $pending_user->ID ); ?>" style="color: #d63638;">
5100 <?php esc_html_e( 'Reject', 'vigilante' ); ?>
5101 </button>
5102 </td>
5103 </tr>
5104 <?php endforeach; ?>
5105 </tbody>
5106 </table>
5107 <?php endif; ?>
5108 </div>
5109
5110 <!-- Active Sessions Management -->
5111 <div class="vigilante-tool-box vigilante-session-management-section">
5112 <h3><?php esc_html_e( 'Active sessions', 'vigilante' ); ?></h3>
5113 <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>
5114
5115 <!-- Current user sessions -->
5116 <h4><?php esc_html_e( 'Your sessions', 'vigilante' ); ?></h4>
5117 <?php
5118 $current_user_id = get_current_user_id();
5119 $my_sessions = $user_security->get_user_sessions( $current_user_id );
5120 $has_corrupted = $user_security->has_corrupted_sessions( $current_user_id );
5121 $raw_count = $user_security->get_raw_session_count( $current_user_id );
5122 ?>
5123
5124 <?php if ( $has_corrupted && $raw_count > 0 ) : ?>
5125 <div class="notice notice-warning inline" style="margin: 10px 0;">
5126 <p>
5127 <span class="dashicons dashicons-warning" style="color: #dba617;"></span>
5128 <?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' ); ?>
5129 </p>
5130 </div>
5131 <?php endif; ?>
5132
5133 <?php if ( empty( $my_sessions ) ) : ?>
5134 <p class="description"><?php esc_html_e( 'No active sessions found.', 'vigilante' ); ?></p>
5135 <?php if ( $has_corrupted ) : ?>
5136 <p style="margin-top: 10px;">
5137 <button type="button" class="button vigilante-revoke-other-sessions" data-user-id="<?php echo esc_attr( $current_user_id ); ?>">
5138 <?php esc_html_e( 'Clean Up Corrupted Sessions', 'vigilante' ); ?>
5139 </button>
5140 </p>
5141 <?php endif; ?>
5142 <?php else : ?>
5143 <div class="vigilante-paginated-section">
5144 <div class="vigilante-fi-pagination-wrap"></div>
5145 <table class="wp-list-table widefat fixed striped vigilante-sessions-table vigilante-fi-paginated">
5146 <thead>
5147 <tr>
5148 <th><?php esc_html_e( 'Browser', 'vigilante' ); ?></th>
5149 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
5150 <th><?php esc_html_e( 'Login Time', 'vigilante' ); ?></th>
5151 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5152 </tr>
5153 </thead>
5154 <tbody>
5155 <?php foreach ( $my_sessions as $session ) : ?>
5156 <tr data-token="<?php echo esc_attr( $session['token_hash'] ); ?>">
5157 <td><?php echo esc_html( $session['browser'] ); ?></td>
5158 <td><code><?php echo esc_html( $session['ip'] ); ?></code></td>
5159 <td>
5160 <?php
5161 if ( $session['login'] ) {
5162 /* translators: %s: Time ago */
5163 printf( esc_html__( '%s ago', 'vigilante' ), esc_html( human_time_diff( $session['login'] ) ) );
5164 } else {
5165 esc_html_e( 'Unknown', 'vigilante' );
5166 }
5167 ?>
5168 </td>
5169 <td>
5170 <?php if ( ! $session['is_current'] ) : ?>
5171 <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'] ); ?>">
5172 <?php esc_html_e( 'Revoke', 'vigilante' ); ?>
5173 </button>
5174 <?php else : ?>
5175 <span class="description"><?php esc_html_e( 'Current session', 'vigilante' ); ?></span>
5176 <?php endif; ?>
5177 </td>
5178 </tr>
5179 <?php endforeach; ?>
5180 </tbody>
5181 </table>
5182 </div>
5183
5184 <?php if ( count( $my_sessions ) > 1 || $has_corrupted ) : ?>
5185 <p style="margin-top: 10px;">
5186 <button type="button" class="button vigilante-revoke-other-sessions" data-user-id="<?php echo esc_attr( $current_user_id ); ?>">
5187 <?php esc_html_e( 'Revoke All Other Sessions', 'vigilante' ); ?>
5188 </button>
5189 </p>
5190 <?php endif; ?>
5191 <?php endif; ?>
5192
5193 <!-- Search user sessions (admin only) -->
5194 <h4 style="margin-top: 30px;"><?php esc_html_e( 'Manage user sessions', 'vigilante' ); ?></h4>
5195 <p class="description"><?php esc_html_e( 'Search for a user to view and manage their sessions.', 'vigilante' ); ?></p>
5196
5197 <div class="vigilante-user-search-wrapper" style="margin-top: 10px;">
5198 <input type="text" id="vigilante-session-user-search" class="regular-text" placeholder="<?php esc_attr_e( 'Search by username or email...', 'vigilante' ); ?>">
5199 <div id="vigilante-session-search-results" class="vigilante-user-search-results" style="display: none;"></div>
5200 </div>
5201
5202 <div id="vigilante-user-sessions-container" style="display: none; margin-top: 20px;">
5203 <h4 id="vigilante-sessions-user-name"></h4>
5204 <table class="wp-list-table widefat fixed striped vigilante-sessions-table">
5205 <thead>
5206 <tr>
5207 <th><?php esc_html_e( 'Browser', 'vigilante' ); ?></th>
5208 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
5209 <th><?php esc_html_e( 'Login Time', 'vigilante' ); ?></th>
5210 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5211 </tr>
5212 </thead>
5213 <tbody id="vigilante-user-sessions-list">
5214 </tbody>
5215 </table>
5216 <p style="margin-top: 10px;">
5217 <button type="button" class="button vigilante-revoke-all-user-sessions" style="color: #d63638;">
5218 <?php esc_html_e( 'Revoke All Sessions', 'vigilante' ); ?>
5219 </button>
5220 </p>
5221 </div>
5222 </div>
5223
5224 <?php endif; ?>
5225 </div>
5226 <?php
5227 }
5228
5229 /**
5230 * Render WordPress Hardening tab
5231 */
5232 private function render_tab_wp_hardening() {
5233 $is_disabled = $this->render_module_disabled_notice( 'wp_hardening' );
5234 $options = $this->settings->get_section( 'wp_hardening' );
5235 ?>
5236 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="wp_hardening" <?php echo $is_disabled ? 'inert' : ''; ?>>
5237 <!-- Database Hardening (outside form save flow - uses its own AJAX action) -->
5238 <?php $vg_shared_locked = $this->shared_files_locked(); ?>
5239 <?php $this->render_shared_files_notice(); ?>
5240 <div id="vigilante-section-hardening-database" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
5241 <h2>
5242 <?php esc_html_e( 'Database Hardening', 'vigilante' ); ?>
5243 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
5244 <span class="vigilante-method-badge config"><?php esc_html_e( 'WP-CONFIG', 'vigilante' ); ?></span>
5245 </h2>
5246 <p><?php esc_html_e( 'Change the database table prefix to prevent SQL injection attacks that target default WordPress tables.', 'vigilante' ); ?></p>
5247
5248 <?php
5249 $db_prefix = new Vigilante_Database_Prefix();
5250 $current_prefix = $db_prefix->get_current_prefix();
5251 $is_default = $db_prefix->is_default_prefix();
5252 ?>
5253
5254 <?php if ( is_multisite() && ! $vg_shared_locked ) : ?>
5255 <div class="notice notice-warning inline" style="margin:10px 0 16px;padding:8px 12px;">
5256 <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>
5257 </div>
5258 <?php endif; ?>
5259
5260 <table class="form-table">
5261 <tr>
5262 <th scope="row"><?php esc_html_e( 'Current prefix', 'vigilante' ); ?></th>
5263 <td>
5264 <code class="vigilante-db-current-prefix"><?php echo esc_html( $current_prefix ); ?></code>
5265 <?php if ( $is_default ) : ?>
5266 <span class="vigilante-inline-warning">
5267 <span class="dashicons dashicons-warning"></span>
5268 <?php esc_html_e( 'Default prefix detected. Changing it adds a layer of protection against automated SQL injection attacks.', 'vigilante' ); ?>
5269 </span>
5270 <?php else : ?>
5271 <span class="vigilante-inline-ok">
5272 <span class="dashicons dashicons-yes-alt"></span>
5273 <?php esc_html_e( 'Custom prefix in use.', 'vigilante' ); ?>
5274 </span>
5275 <?php endif; ?>
5276 </td>
5277 </tr>
5278 <tr>
5279 <th scope="row"><?php esc_html_e( 'New prefix', 'vigilante' ); ?></th>
5280 <td>
5281 <div class="vigilante-db-prefix-row">
5282 <code class="vigilante-db-new-prefix" id="vigilante-new-prefix"><?php echo esc_html( $db_prefix->generate_prefix() ); ?></code>
5283 <button type="button" class="button button-small vigilante-db-regenerate-prefix" title="<?php esc_attr_e( 'Generate new prefix', 'vigilante' ); ?>">
5284 <span class="dashicons dashicons-update"></span>
5285 </button>
5286 </div>
5287 </td>
5288 </tr>
5289 <tr>
5290 <th scope="row"></th>
5291 <td>
5292 <div class="vigilante-db-prefix-confirm">
5293 <label>
5294 <input type="checkbox" id="vigilante-prefix-backup-confirm">
5295 <?php esc_html_e( 'I understand this operation is irreversible and I have a current database backup', 'vigilante' ); ?>
5296 </label>
5297 <p class="description">
5298 <?php
5299 printf(
5300 /* translators: %s: Link to tools tab */
5301 esc_html__( 'Need a backup? %s first.', 'vigilante' ),
5302 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Download a database backup', 'vigilante' ) . '</a>'
5303 );
5304 ?>
5305 </p>
5306 </div>
5307 <button type="button" class="button button-primary vigilante-db-change-prefix" disabled data-original-text="<?php esc_attr_e( 'Change Database Prefix', 'vigilante' ); ?>">
5308 <?php esc_html_e( 'Change Database Prefix', 'vigilante' ); ?>
5309 </button>
5310 </td>
5311 </tr>
5312 </table>
5313 </div>
5314
5315 <!-- wp-config Security -->
5316 <?php
5317 $vg_shared_locked = $this->shared_files_locked();
5318 // Paint what is actually in force, not this site's unused copy.
5319 $vg_local_options = $options;
5320 $options = $this->get_section_for_display( 'wp_hardening' );
5321 ?>
5322 <?php $this->render_shared_files_notice(); ?>
5323 <div id="vigilante-section-hardening-wpconfig" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
5324 <h2>
5325 <?php esc_html_e( 'wp-config.php Security', 'vigilante' ); ?>
5326 <span class="vigilante-method-badge config"><?php esc_html_e( 'WP-CONFIG', 'vigilante' ); ?></span>
5327 </h2>
5328 <p><?php esc_html_e( 'Security constants added directly to wp-config.php file.', 'vigilante' ); ?></p>
5329
5330 <table class="form-table">
5331 <tr>
5332 <th scope="row"><?php esc_html_e( 'Disable File Editor', 'vigilante' ); ?></th>
5333 <td>
5334 <label>
5335 <input type="checkbox" name="wp_hardening[disallow_file_edit]" value="1" <?php checked( ! empty( $options['disallow_file_edit'] ) ); ?>>
5336 <?php esc_html_e( 'Disable plugin and theme editor in admin (DISALLOW_FILE_EDIT)', 'vigilante' ); ?>
5337 </label>
5338 </td>
5339 </tr>
5340 <tr>
5341 <th scope="row"><?php esc_html_e( 'Disable File Modifications', 'vigilante' ); ?></th>
5342 <td>
5343 <label>
5344 <input type="checkbox" name="wp_hardening[disallow_file_mods]" value="1" <?php checked( ! empty( $options['disallow_file_mods'] ) ); ?>>
5345 <?php esc_html_e( 'Disable all file modifications including updates (DISALLOW_FILE_MODS)', 'vigilante' ); ?>
5346 </label>
5347 <p class="description"><?php esc_html_e( '&#9888; Warning: This prevents automatic updates.', 'vigilante' ); ?></p>
5348 </td>
5349 </tr>
5350 <tr id="field-force-ssl-admin">
5351 <th scope="row"><?php esc_html_e( 'Force SSL Admin', 'vigilante' ); ?></th>
5352 <td>
5353 <label>
5354 <input type="checkbox" name="wp_hardening[force_ssl_admin]" value="1" <?php checked( ! empty( $options['force_ssl_admin'] ) ); ?>>
5355 <?php esc_html_e( 'Force HTTPS for admin area (FORCE_SSL_ADMIN)', 'vigilante' ); ?>
5356 </label>
5357 <p class="description"><?php esc_html_e( '&#9888; Warning: Only enable if your site fully supports HTTPS.', 'vigilante' ); ?></p>
5358 </td>
5359 </tr>
5360 <tr id="field-wp-debug">
5361 <th scope="row"><?php esc_html_e( 'Hide PHP errors from visitors', 'vigilante' ); ?></th>
5362 <td>
5363 <label>
5364 <input type="checkbox" name="wp_hardening[wp_debug]" value="1" <?php checked( ! empty( $options['wp_debug'] ) ); ?>>
5365 <?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' ); ?>
5366 </label>
5367 </td>
5368 </tr>
5369 <tr id="field-disable-wp-cron">
5370 <th scope="row"><?php esc_html_e( 'Disable WP Cron', 'vigilante' ); ?></th>
5371 <td>
5372 <label>
5373 <input type="checkbox" name="wp_hardening[disable_wp_cron]" value="1" <?php checked( ! empty( $options['disable_wp_cron'] ) ); ?>>
5374 <?php esc_html_e( 'Disable WordPress\'s page-view cron trigger (DISABLE_WP_CRON)', 'vigilante' ); ?>
5375 </label>
5376 <p class="description"><?php
5377 printf(
5378 /* translators: 1: opening <strong>, 2: closing </strong>, 3: opening <code>, 4: closing </code> */
5379 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' ),
5380 '<strong>',
5381 '</strong>',
5382 '<code>',
5383 '</code>'
5384 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
5385 ?></p>
5386 </td>
5387 </tr>
5388 </table>
5389 </div>
5390 <?php $options = $vg_local_options; ?>
5391
5392 <!-- Comment Security -->
5393 <div id="vigilante-section-hardening-xmlrpc" class="vigilante-settings-section">
5394 <h2>
5395 <?php esc_html_e( 'XML-RPC', 'vigilante' ); ?>
5396 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5397 </h2>
5398 <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>
5399
5400 <table class="form-table">
5401 <tr id="field-disable-xmlrpc">
5402 <th scope="row"><label for="vigilante-f-wp-hardening-xmlrpc-mode"><?php esc_html_e( 'XML-RPC access', 'vigilante' ); ?></label></th>
5403 <td>
5404 <?php $vig_xmlrpc_mode = Vigilante_Comment_Security::resolve_xmlrpc_mode( $this->settings ); ?>
5405 <select id="vigilante-f-wp-hardening-xmlrpc-mode" name="wp_hardening[xmlrpc_mode]">
5406 <option value="none" <?php selected( $vig_xmlrpc_mode, 'none' ); ?>>
5407 <?php esc_html_e( 'Leave XML-RPC enabled', 'vigilante' ); ?>
5408 </option>
5409 <option value="pingback" <?php selected( $vig_xmlrpc_mode, 'pingback' ); ?>>
5410 <?php esc_html_e( 'Block the pingback methods only', 'vigilante' ); ?>
5411 </option>
5412 <option value="full" <?php selected( $vig_xmlrpc_mode, 'full' ); ?>>
5413 <?php esc_html_e( 'Disable XML-RPC completely (recommended)', 'vigilante' ); ?>
5414 </option>
5415 </select>
5416 <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>
5417 </td>
5418 </tr>
5419 </table>
5420 </div>
5421
5422 <div id="vigilante-section-hardening-comments" class="vigilante-settings-section">
5423 <h2>
5424 <?php esc_html_e( 'Comment Security', 'vigilante' ); ?>
5425 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5426 <span class="vigilante-method-badge settings"><?php esc_html_e( 'Settings', 'vigilante' ); ?></span>
5427 </h2>
5428 <p><?php esc_html_e( 'Comment protection using WordPress settings and PHP hooks.', 'vigilante' ); ?></p>
5429
5430 <table class="form-table">
5431 <tr>
5432 <th scope="row"><?php esc_html_e( 'Disable Pingbacks', 'vigilante' ); ?></th>
5433 <td>
5434 <label>
5435 <input type="checkbox" name="wp_hardening[disable_pingbacks]" value="1" <?php checked( ! empty( $options['disable_pingbacks'] ) ); ?>>
5436 <?php esc_html_e( 'Disable pingbacks (commonly exploited for DDoS)', 'vigilante' ); ?>
5437 </label>
5438 </td>
5439 </tr>
5440 <tr>
5441 <th scope="row"><?php esc_html_e( 'Disable Trackbacks', 'vigilante' ); ?></th>
5442 <td>
5443 <label>
5444 <input type="checkbox" name="wp_hardening[disable_trackbacks]" value="1" <?php checked( ! empty( $options['disable_trackbacks'] ) ); ?>>
5445 <?php esc_html_e( 'Disable trackbacks (rarely used legitimately)', 'vigilante' ); ?>
5446 </label>
5447 </td>
5448 </tr>
5449 <tr>
5450 <th scope="row"><?php esc_html_e( 'Require Moderation', 'vigilante' ); ?></th>
5451 <td>
5452 <label>
5453 <input type="checkbox" name="wp_hardening[require_comment_moderation]" value="1" <?php checked( ! empty( $options['require_comment_moderation'] ) ); ?>>
5454 <?php esc_html_e( 'All comments must be manually approved', 'vigilante' ); ?>
5455 </label>
5456 </td>
5457 </tr>
5458 <tr>
5459 <th scope="row"><?php esc_html_e( 'Close Old Comments', 'vigilante' ); ?></th>
5460 <td>
5461 <label>
5462 <input type="checkbox" name="wp_hardening[close_old_comments]" value="1" <?php checked( ! empty( $options['close_old_comments'] ) ); ?>>
5463 <?php esc_html_e( 'Automatically close comments on old posts after', 'vigilante' ); ?>
5464 </label>
5465 <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">
5466 <label for="vigilante-f-wp-hardening-close-comments-after-days"><?php esc_html_e( 'days', 'vigilante' ); ?></label>
5467 </td>
5468 </tr>
5469 <tr>
5470 <th scope="row"><?php esc_html_e( 'Honeypot Protection', 'vigilante' ); ?></th>
5471 <td>
5472 <label>
5473 <input type="checkbox" name="wp_hardening[honeypot_comments]" value="1" <?php checked( ! empty( $options['honeypot_comments'] ) ); ?>>
5474 <?php esc_html_e( 'Add hidden honeypot field to catch bots', 'vigilante' ); ?>
5475 </label>
5476 </td>
5477 </tr>
5478 </table>
5479 </div>
5480
5481 <!-- Head Cleaner -->
5482 <div id="vigilante-section-hardening-headers" class="vigilante-settings-section">
5483 <h2>
5484 <?php esc_html_e( 'Header Cleanup', 'vigilante' ); ?>
5485 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5486 </h2>
5487 <p><?php esc_html_e( 'Remove meta tags from HTML head.', 'vigilante' ); ?></p>
5488
5489 <table class="form-table">
5490 <tr>
5491 <th scope="row"><?php esc_html_e( 'Remove Generator', 'vigilante' ); ?></th>
5492 <td>
5493 <label>
5494 <input type="checkbox" name="wp_hardening[remove_wp_generator]" value="1" <?php checked( ! empty( $options['remove_wp_generator'] ) ); ?>>
5495 <?php esc_html_e( 'Remove WordPress version from HTML head', 'vigilante' ); ?>
5496 </label>
5497 </td>
5498 </tr>
5499 <tr id="field-remove-wp-version-assets">
5500 <th scope="row"><?php esc_html_e( 'Remove version from assets', 'vigilante' ); ?></th>
5501 <td>
5502 <label>
5503 <input type="checkbox" name="wp_hardening[remove_wp_version_assets]" value="1" <?php checked( ! empty( $options['remove_wp_version_assets'] ) ); ?>>
5504 <?php esc_html_e( 'Remove WordPress version from script/style URLs (?ver=)', 'vigilante' ); ?>
5505 </label>
5506 <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>
5507 </td>
5508 </tr>
5509 <tr>
5510 <th scope="row"><?php esc_html_e( 'Remove RSD Link', 'vigilante' ); ?></th>
5511 <td>
5512 <label>
5513 <input type="checkbox" name="wp_hardening[remove_rsd_link]" value="1" <?php checked( ! empty( $options['remove_rsd_link'] ) ); ?>>
5514 <?php esc_html_e( 'Remove Really Simple Discovery link', 'vigilante' ); ?>
5515 </label>
5516 </td>
5517 </tr>
5518 <tr>
5519 <th scope="row"><?php esc_html_e( 'Remove WLW Manifest', 'vigilante' ); ?></th>
5520 <td>
5521 <label>
5522 <input type="checkbox" name="wp_hardening[remove_wlw_manifest]" value="1" <?php checked( ! empty( $options['remove_wlw_manifest'] ) ); ?>>
5523 <?php esc_html_e( 'Remove Windows Live Writer manifest link', 'vigilante' ); ?>
5524 </label>
5525 </td>
5526 </tr>
5527 <tr>
5528 <th scope="row"><?php esc_html_e( 'Remove Shortlink', 'vigilante' ); ?></th>
5529 <td>
5530 <label>
5531 <input type="checkbox" name="wp_hardening[remove_shortlink]" value="1" <?php checked( ! empty( $options['remove_shortlink'] ) ); ?>>
5532 <?php esc_html_e( 'Remove shortlink tag from header', 'vigilante' ); ?>
5533 </label>
5534 </td>
5535 </tr>
5536 <tr>
5537 <th scope="row"><?php esc_html_e( 'Remove REST API Link', 'vigilante' ); ?></th>
5538 <td>
5539 <label>
5540 <input type="checkbox" name="wp_hardening[remove_rest_api_link]" value="1" <?php checked( ! empty( $options['remove_rest_api_link'] ) ); ?>>
5541 <?php esc_html_e( 'Remove REST API discovery link from header', 'vigilante' ); ?>
5542 </label>
5543 <p class="description"><?php esc_html_e( '&#9888; Notice: Some plugins may need this link.', 'vigilante' ); ?></p>
5544 </td>
5545 </tr>
5546 </table>
5547 </div>
5548
5549 <!-- Feed Manager -->
5550 <div id="vigilante-section-hardening-rss" class="vigilante-settings-section">
5551 <h2>
5552 <?php esc_html_e( 'RSS Feed Settings', 'vigilante' ); ?>
5553 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5554 </h2>
5555 <p><?php esc_html_e( 'Control RSS/Atom feeds.', 'vigilante' ); ?></p>
5556
5557 <table class="form-table">
5558 <tr>
5559 <th scope="row"><?php esc_html_e( 'Disable Feeds', 'vigilante' ); ?></th>
5560 <td>
5561 <label>
5562 <input type="checkbox" name="wp_hardening[disable_feeds]" value="1" <?php checked( ! empty( $options['disable_feeds'] ) ); ?>>
5563 <?php esc_html_e( 'Completely disable RSS/Atom feeds', 'vigilante' ); ?>
5564 </label>
5565 </td>
5566 </tr>
5567 <tr>
5568 <th scope="row"><?php esc_html_e( 'Disable If No Content', 'vigilante' ); ?></th>
5569 <td>
5570 <label>
5571 <input type="checkbox" name="wp_hardening[disable_if_no_content]" value="1" <?php checked( ! empty( $options['disable_if_no_content'] ) ); ?>>
5572 <?php esc_html_e( 'Only disable feeds if site has no published posts', 'vigilante' ); ?>
5573 </label>
5574 </td>
5575 </tr>
5576 <tr>
5577 <th scope="row"><?php esc_html_e( 'Remove Feed Version', 'vigilante' ); ?></th>
5578 <td>
5579 <label>
5580 <input type="checkbox" name="wp_hardening[remove_feed_version]" value="1" <?php checked( ! empty( $options['remove_feed_version'] ) ); ?>>
5581 <?php esc_html_e( 'Remove WordPress version from feed generator tag', 'vigilante' ); ?>
5582 </label>
5583 </td>
5584 </tr>
5585 </table>
5586 </div>
5587
5588 <p class="submit vigilante-submit-buttons">
5589 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5590 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5591 </button>
5592 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5593 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5594 </button>
5595 </p>
5596 </form>
5597 <?php
5598 }
5599
5600 /**
5601 * Render activity log tab
5602 */
5603 private function render_tab_activity_log() {
5604 $is_disabled = $this->render_module_disabled_notice( 'activity_log' );
5605 $options = $this->settings->get_section( 'activity_log' );
5606 ?>
5607 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="activity_log" <?php echo $is_disabled ? 'inert' : ''; ?>>
5608 <div id="vigilante-section-audit-settings" class="vigilante-settings-section">
5609 <h2>
5610 <?php esc_html_e( 'Security Audit Settings', 'vigilante' ); ?>
5611 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5612 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
5613 </h2>
5614 <p><?php esc_html_e( 'Security event logging and auditing.', 'vigilante' ); ?></p>
5615
5616 <table class="form-table">
5617 <tr>
5618 <th scope="row"><?php esc_html_e( 'Retention', 'vigilante' ); ?></th>
5619 <td>
5620 <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">
5621 <label for="vigilante-f-activity-log-retention-days"><?php esc_html_e( 'days', 'vigilante' ); ?></label>
5622 &nbsp;&nbsp;
5623 <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">
5624 <label for="vigilante-f-activity-log-max-entries"><?php esc_html_e( 'max entries', 'vigilante' ); ?></label>
5625 <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>
5626 </td>
5627 </tr>
5628 <tr>
5629 <th scope="row"><?php esc_html_e( 'Events to Log', 'vigilante' ); ?></th>
5630 <td>
5631 <fieldset style="display:grid; grid-template-columns:repeat(auto-fit, minmax(240px, 1fr)); gap:6px 24px; max-width:600px;">
5632 <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>
5633 <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>
5634 <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>
5635 <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>
5636 <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>
5637 <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>
5638 <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>
5639 <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>
5640 <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>
5641 <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>
5642 </fieldset>
5643 <div class="notice notice-info inline" style="margin:10px 0 0;padding:8px 12px;">
5644 <p style="margin:0;">
5645 <?php esc_html_e( 'Firewall blocks, security events, and Vigilant settings changes are always logged regardless of the above selections.', 'vigilante' ); ?>
5646 </p>
5647 </div>
5648 </td>
5649 </tr>
5650 <tr>
5651 <th scope="row"><label for="vigilante-f-activity-log-tracked-options"><?php esc_html_e( 'Option Tracking', 'vigilante' ); ?></label></th>
5652 <td>
5653 <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>
5654 <br>
5655 <label><?php esc_html_e( 'Additional options to track:', 'vigilante' ); ?></label><br>
5656 <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>
5657 <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>
5658 </td>
5659 </tr>
5660 <tr>
5661 <th scope="row"><?php esc_html_e( 'Exclusions', 'vigilante' ); ?></th>
5662 <td>
5663 <div style="display:grid; grid-template-columns:repeat(auto-fit, minmax(220px, 1fr)); gap:16px; max-width:600px;">
5664 <div>
5665 <label for="vigilante-f-activity-log-excluded-users"><?php esc_html_e( 'Excluded user IDs:', 'vigilante' ); ?></label><br>
5666 <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>
5667 <p class="description"><?php esc_html_e( 'One user ID per line. Actions by these users will not be logged.', 'vigilante' ); ?></p>
5668 </div>
5669 <div>
5670 <label for="vigilante-f-activity-log-excluded-ips"><?php esc_html_e( 'Excluded IPs:', 'vigilante' ); ?></label><br>
5671 <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>
5672 <p class="description"><?php esc_html_e( 'One IP per line. Requests from these IPs will not be logged.', 'vigilante' ); ?></p>
5673 </div>
5674 </div>
5675 </td>
5676 </tr>
5677 </table>
5678 </div>
5679
5680 <p class="submit vigilante-submit-buttons">
5681 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5682 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5683 </button>
5684 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5685 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5686 </button>
5687 </p>
5688 </form>
5689
5690 <?php
5691 // Audit Alerts — alerting layer on top of Security Audit. Its own
5692 // settings section and form, rendered right after the logging settings
5693 // so the tab reads as "log this, exclude that, and alert me about this".
5694 $alerts = $this->settings->get_section( 'audit_alerts' );
5695 $immediate = isset( $alerts['immediate'] ) ? $alerts['immediate'] : array();
5696 $threshold = isset( $alerts['threshold'] ) ? $alerts['threshold'] : array();
5697 $alert_severity = isset( $immediate['min_severity'] ) ? $immediate['min_severity'] : 'critical';
5698 $alert_window = isset( $threshold['window'] ) ? $threshold['window'] : '1h';
5699 $threshold_cats = isset( $threshold['categories'] ) ? (array) $threshold['categories'] : array();
5700 $cat_labels = Vigilante_Audit_Alerts::category_labels();
5701 ?>
5702 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="audit_alerts" <?php echo $is_disabled ? 'inert' : ''; ?>>
5703 <div id="vigilante-section-audit-alerts" class="vigilante-settings-section">
5704 <h2>
5705 <?php esc_html_e( 'Audit Alerts', 'vigilante' ); ?>
5706 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5707 </h2>
5708 <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>
5709
5710 <table class="form-table">
5711 <tr id="field-audit-alerts-immediate">
5712 <th scope="row"><?php esc_html_e( 'Immediate alerts', 'vigilante' ); ?></th>
5713 <td>
5714 <label>
5715 <input type="checkbox" name="audit_alerts[immediate][enabled]" value="1" <?php checked( ! empty( $immediate['enabled'] ) ); ?>>
5716 <?php esc_html_e( 'Email me as soon as a serious event is logged', 'vigilante' ); ?>
5717 </label>
5718 <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>
5719 </td>
5720 </tr>
5721 <tr>
5722 <th scope="row"><label for="vigilante-f-audit-alerts-immediate-min-severity"><?php esc_html_e( 'Alert on severity', 'vigilante' ); ?></label></th>
5723 <td>
5724 <select id="vigilante-f-audit-alerts-immediate-min-severity" name="audit_alerts[immediate][min_severity]">
5725 <option value="critical" <?php selected( $alert_severity, 'critical' ); ?>><?php esc_html_e( 'Critical only (recommended)', 'vigilante' ); ?></option>
5726 <option value="warning" <?php selected( $alert_severity, 'warning' ); ?>><?php esc_html_e( 'Warning and Critical', 'vigilante' ); ?></option>
5727 </select>
5728 <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>
5729 </td>
5730 </tr>
5731 <tr id="field-audit-alerts-threshold">
5732 <th scope="row"><?php esc_html_e( 'Threshold alerts', 'vigilante' ); ?></th>
5733 <td>
5734 <label>
5735 <input type="checkbox" name="audit_alerts[threshold][enabled]" value="1" <?php checked( ! empty( $threshold['enabled'] ) ); ?>>
5736 <?php esc_html_e( 'Email me when a category spikes within a time window', 'vigilante' ); ?>
5737 </label>
5738 <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>
5739 </td>
5740 </tr>
5741 <tr>
5742 <th scope="row"><label for="vigilante-f-audit-alerts-threshold-window"><?php esc_html_e( 'Time window', 'vigilante' ); ?></label></th>
5743 <td>
5744 <select id="vigilante-f-audit-alerts-threshold-window" name="audit_alerts[threshold][window]">
5745 <option value="30m" <?php selected( $alert_window, '30m' ); ?>><?php esc_html_e( '30 minutes', 'vigilante' ); ?></option>
5746 <option value="1h" <?php selected( $alert_window, '1h' ); ?>><?php esc_html_e( '1 hour', 'vigilante' ); ?></option>
5747 <option value="6h" <?php selected( $alert_window, '6h' ); ?>><?php esc_html_e( '6 hours', 'vigilante' ); ?></option>
5748 <option value="24h" <?php selected( $alert_window, '24h' ); ?>><?php esc_html_e( '24 hours', 'vigilante' ); ?></option>
5749 </select>
5750 <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>
5751 </td>
5752 </tr>
5753 <tr>
5754 <th scope="row"><?php esc_html_e( 'Thresholds per category', 'vigilante' ); ?></th>
5755 <td>
5756 <fieldset style="display:grid; grid-template-columns:repeat(auto-fit, minmax(200px, 1fr)); gap:8px 24px; max-width:760px;">
5757 <?php
5758 foreach ( $cat_labels as $cat_slug => $cat_label ) :
5759 $cat_value = isset( $threshold_cats[ $cat_slug ] ) ? (int) $threshold_cats[ $cat_slug ] : 0;
5760 ?>
5761 <label style="display:flex;align-items:center;gap:8px;justify-content:space-between;">
5762 <span><?php echo esc_html( $cat_label ); ?></span>
5763 <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">
5764 </label>
5765 <?php endforeach; ?>
5766 </fieldset>
5767 <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>
5768 </td>
5769 </tr>
5770 <tr>
5771 <th scope="row"><?php esc_html_e( "Don't repeat alerts", 'vigilante' ); ?></th>
5772 <td>
5773 <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">
5774 <label for="vigilante-f-audit-alerts-cooldown-minutes"><?php esc_html_e( 'minutes', 'vigilante' ); ?></label>
5775 <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>
5776 </td>
5777 </tr>
5778
5779 <tr>
5780 <th scope="row"><?php esc_html_e( 'Recipients', 'vigilante' ); ?></th>
5781 <td>
5782 <p class="description" style="margin-top:0;">
5783 <?php
5784 printf(
5785 /* translators: %s: Link to notification settings */
5786 esc_html__( 'Alerts go to the recipients configured in %s.', 'vigilante' ),
5787 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
5788 );
5789 ?>
5790 </p>
5791 <p style="margin:8px 0 0;">
5792 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
5793 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
5794 </button>
5795 <span class="vigilante-test-email-result" style="margin-left:8px;"></span>
5796 </p>
5797 <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>
5798 </td>
5799 </tr>
5800 </table>
5801 </div>
5802
5803 <p class="submit vigilante-submit-buttons">
5804 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5805 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5806 </button>
5807 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5808 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5809 </button>
5810 </p>
5811 </form>
5812
5813 <div id="vigilante-section-audit-recent" class="vigilante-settings-section">
5814 <h2><?php esc_html_e( 'Recent Activity', 'vigilante' ); ?></h2>
5815
5816 <?php
5817 $logs = $this->activity_log->get_logs( array( 'per_page' => 20 ) );
5818 $total_logs = $this->activity_log->get_logs_count();
5819
5820 // Label maps for translated display
5821 $type_labels = array(
5822 'login' => __( 'Login', 'vigilante' ),
5823 'user' => __( 'User', 'vigilante' ),
5824 'content' => __( 'Content', 'vigilante' ),
5825 'plugin' => __( 'Plugin', 'vigilante' ),
5826 'theme' => __( 'Theme', 'vigilante' ),
5827 'settings' => __( 'Settings', 'vigilante' ),
5828 'comment' => __( 'Comment', 'vigilante' ),
5829 'media' => __( 'Media', 'vigilante' ),
5830 'firewall' => __( 'Firewall', 'vigilante' ),
5831 'file' => __( 'File', 'vigilante' ),
5832 'security' => __( 'Security', 'vigilante' ),
5833 'system' => __( 'System', 'vigilante' ),
5834 );
5835 $severity_labels = array(
5836 'info' => __( 'Info', 'vigilante' ),
5837 'warning' => __( 'Warning', 'vigilante' ),
5838 'critical' => __( 'Critical', 'vigilante' ),
5839 );
5840
5841 $firewall_options = $this->settings->get_section( 'firewall' );
5842 $ip_whitelist = $firewall_options['ip_whitelist'] ?? array();
5843 $ip_blacklist = $firewall_options['ip_blacklist'] ?? array();
5844 $ua_whitelist = $firewall_options['ua_whitelist'] ?? array();
5845 $ua_blacklist = $firewall_options['ua_blacklist'] ?? array();
5846 ?>
5847
5848 <div class="vigilante-log-filters">
5849 <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">
5850 <select id="vigilante-log-type-filter" aria-label="<?php esc_attr_e( 'Filter the log by event type', 'vigilante' ); ?>">
5851 <option value=""><?php esc_html_e( 'All Types', 'vigilante' ); ?></option>
5852 <option value="login"><?php esc_html_e( 'Login', 'vigilante' ); ?></option>
5853 <option value="user"><?php esc_html_e( 'User', 'vigilante' ); ?></option>
5854 <option value="content"><?php esc_html_e( 'Content', 'vigilante' ); ?></option>
5855 <option value="plugin"><?php esc_html_e( 'Plugin', 'vigilante' ); ?></option>
5856 <option value="theme"><?php esc_html_e( 'Theme', 'vigilante' ); ?></option>
5857 <option value="settings"><?php esc_html_e( 'Settings', 'vigilante' ); ?></option>
5858 <option value="comment"><?php esc_html_e( 'Comment', 'vigilante' ); ?></option>
5859 <option value="media"><?php esc_html_e( 'Media', 'vigilante' ); ?></option>
5860 <option value="firewall"><?php esc_html_e( 'Firewall', 'vigilante' ); ?></option>
5861 <option value="file"><?php esc_html_e( 'File', 'vigilante' ); ?></option>
5862 <option value="security"><?php esc_html_e( 'Security', 'vigilante' ); ?></option>
5863 <option value="system"><?php esc_html_e( 'System', 'vigilante' ); ?></option>
5864 </select>
5865 <select id="vigilante-log-severity-filter" aria-label="<?php esc_attr_e( 'Filter the log by severity', 'vigilante' ); ?>">
5866 <option value=""><?php esc_html_e( 'All Severities', 'vigilante' ); ?></option>
5867 <option value="info"><?php esc_html_e( 'Info', 'vigilante' ); ?></option>
5868 <option value="warning"><?php esc_html_e( 'Warning', 'vigilante' ); ?></option>
5869 <option value="critical"><?php esc_html_e( 'Critical', 'vigilante' ); ?></option>
5870 </select>
5871 <select id="vigilante-log-method-filter" aria-label="<?php esc_attr_e( 'Filter the log by HTTP method', 'vigilante' ); ?>">
5872 <option value=""><?php esc_html_e( 'All Methods', 'vigilante' ); ?></option>
5873 <option value="GET">GET</option>
5874 <option value="POST">POST</option>
5875 <option value="PUT">PUT</option>
5876 <option value="DELETE">DELETE</option>
5877 <option value="PATCH">PATCH</option>
5878 <option value="OPTIONS">OPTIONS</option>
5879 <option value="HEAD">HEAD</option>
5880 </select>
5881 <button type="button" id="vigilante-log-refresh" class="button"><?php esc_html_e( 'Refresh', 'vigilante' ); ?></button>
5882 <span class="vigilante-pagination" id="vigilante-log-pagination" data-total="<?php echo esc_attr( $total_logs ); ?>" data-per-page="20" data-page="1">
5883 <?php if ( $total_logs > 20 ) : ?>
5884 <button type="button" class="vigilante-page-first" title="<?php esc_attr_e( 'First page', 'vigilante' ); ?>" disabled>&laquo;</button>
5885 <button type="button" class="vigilante-page-prev" title="<?php esc_attr_e( 'Previous page', 'vigilante' ); ?>" disabled>&lsaquo;</button>
5886 <?php endif; ?>
5887 <span class="vigilante-page-info">
5888 <?php
5889 $showing = min( 20, $total_logs );
5890 printf(
5891 /* translators: 1: first item, 2: last item, 3: total items */
5892 esc_html__( '%1$d–%2$d of %3$d', 'vigilante' ),
5893 $total_logs > 0 ? 1 : 0,
5894 absint( $showing ),
5895 absint( $total_logs )
5896 );
5897 ?>
5898 </span>
5899 <?php if ( $total_logs > 20 ) : ?>
5900 <button type="button" class="vigilante-page-next" title="<?php esc_attr_e( 'Next page', 'vigilante' ); ?>">&rsaquo;</button>
5901 <button type="button" class="vigilante-page-last" title="<?php esc_attr_e( 'Last page', 'vigilante' ); ?>">&raquo;</button>
5902 <?php endif; ?>
5903 </span>
5904 </div>
5905
5906 <div class="vigilante-log-table-wrap">
5907 <table id="vigilante-activity-log-table" class="wp-list-table widefat striped">
5908 <thead>
5909 <tr>
5910 <th class="column-date"><?php esc_html_e( 'Date', 'vigilante' ); ?></th>
5911 <th class="column-type"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
5912 <th class="column-method"><?php esc_html_e( 'Method', 'vigilante' ); ?></th>
5913 <th class="column-severity"><?php esc_html_e( 'Severity', 'vigilante' ); ?></th>
5914 <th class="column-message"><?php esc_html_e( 'Message', 'vigilante' ); ?></th>
5915 <th class="column-user"><?php esc_html_e( 'User', 'vigilante' ); ?></th>
5916 <th class="column-ip"><?php esc_html_e( 'IP', 'vigilante' ); ?></th>
5917 <th class="column-details"><?php esc_html_e( 'Details', 'vigilante' ); ?></th>
5918 </tr>
5919 </thead>
5920 <tbody>
5921 <?php
5922 if ( empty( $logs ) ) :
5923 ?>
5924 <tr><td colspan="8"><?php esc_html_e( 'No log entries found.', 'vigilante' ); ?></td></tr>
5925 <?php else : ?>
5926 <?php foreach ( $logs as $log ) :
5927 $request_method = isset( $log->request_method ) ? $log->request_method : '';
5928 // Prepare details as a simple object
5929 $ip_val = (string) ( $log->ip_address ?? '' );
5930 $ua_val = (string) ( $log->user_agent ?? '' );
5931 $details = array(
5932 'id' => (int) $log->id,
5933 'type' => (string) ( $log->event_type ?? '' ),
5934 'action' => (string) ( $log->event_action ?? '' ),
5935 'message' => (string) ( $log->event_message ?? '' ),
5936 'user' => (string) ( $log->user_login ?? '' ),
5937 'ip' => $ip_val,
5938 'user_agent' => $ua_val,
5939 'request_method' => (string) $request_method,
5940 'request_uri' => Vigilante_Activity_Log::extract_request_uri( $log->extra_data ?? '' ),
5941 'date' => (string) ( $log->created_at ?? '' ),
5942 'severity' => (string) ( $log->severity ?? 'info' ),
5943 'is_ip_whitelisted' => ( '' !== $ip_val && in_array( $ip_val, $ip_whitelist, true ) ),
5944 'is_ip_blacklisted' => ( '' !== $ip_val && in_array( $ip_val, $ip_blacklist, true ) ),
5945 'is_ua_whitelisted' => ( '' !== $ua_val && in_array( $ua_val, $ua_whitelist, true ) ),
5946 'is_ua_blacklisted' => ( '' !== $ua_val && in_array( $ua_val, $ua_blacklist, true ) ),
5947 );
5948 $display_type = isset( $type_labels[ $log->event_type ] ) ? $type_labels[ $log->event_type ] : $log->event_type;
5949 $display_severity = isset( $severity_labels[ $log->severity ] ) ? $severity_labels[ $log->severity ] : $log->severity;
5950 ?>
5951 <tr class="vigilante-severity-<?php echo esc_attr( $log->severity ); ?>">
5952 <td><?php echo esc_html( $log->created_at ); ?></td>
5953 <td><?php echo esc_html( $display_type ); ?></td>
5954 <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>
5955 <td><span class="vigilante-badge vigilante-badge-<?php echo esc_attr( $log->severity ); ?>"><?php echo esc_html( $display_severity ); ?></span></td>
5956 <td><?php echo esc_html( $log->event_message ); ?></td>
5957 <td><?php echo esc_html( $log->user_login ?? '-' ); ?></td>
5958 <td><code><?php echo esc_html( $log->ip_address ); ?></code></td>
5959 <td>
5960 <button type="button" class="button button-small vigilante-view-log-details"
5961 data-details='<?php echo esc_attr( wp_json_encode( $details, JSON_HEX_APOS | JSON_HEX_QUOT ) ); ?>'>
5962 <?php esc_html_e( 'View', 'vigilante' ); ?>
5963 </button>
5964 </td>
5965 </tr>
5966 <?php endforeach; ?>
5967 <?php endif; ?>
5968 </tbody>
5969 </table>
5970 </div>
5971
5972 <!-- Log Details Modal -->
5973 <div id="vigilante-log-details-modal" class="vigilante-modal" style="display: none;">
5974 <div class="vigilante-modal-content">
5975 <span class="vigilante-modal-close">&times;</span>
5976 <h3><?php esc_html_e( 'Log Entry Details', 'vigilante' ); ?></h3>
5977 <div id="vigilante-log-details-content"></div>
5978 </div>
5979 </div>
5980
5981 <p>
5982 <button type="button" class="button vigilante-export-logs"><?php esc_html_e( 'Export Audit Log', 'vigilante' ); ?></button>
5983 <button type="button" class="button vigilante-clear-logs" style="color: #a00;"><?php esc_html_e( 'Clear All Logs', 'vigilante' ); ?></button>
5984 </p>
5985 </div>
5986 <?php
5987 }
5988
5989 /**
5990 * Render File Integrity tab
5991 */
5992 private function render_tab_file_integrity() {
5993 $is_disabled = $this->render_module_disabled_notice( 'file_integrity' );
5994 $options = $this->settings->get_section( 'file_integrity' );
5995 $last_scan = get_option( 'vigilante_last_integrity_scan' );
5996 $last_results = get_option( 'vigilante_last_integrity_results' );
5997 $ignored_files = get_option( 'vigilante_ignored_files', array() );
5998
5999 // Backward compat: convert old notify_on_changes to notify_level
6000 $notify_level = $options['notify_level'] ?? '';
6001 if ( empty( $notify_level ) ) {
6002 $notify_level = ! empty( $options['notify_on_changes'] ) ? 'all' : 'disabled';
6003 }
6004
6005 // Closed + Removed plugins data. Surfaced inside Last Scan Results so the
6006 // user sees file findings and plugin closures together (same tier of risk,
6007 // same UI), and as the trigger to keep Last Scan Results open even when no
6008 // file scan has run yet (the daily cron may have populated this section).
6009 //
6010 // Gating by last_check_time > 0 is how "Clear Previous Results" visually
6011 // resets this block: the option vigilante_plugin_status_last_check is
6012 // deleted on Clear, but the state map and the ignored list survive so the
6013 // next scan reconstructs without degrading a 'removed' slug. While
6014 // last_check is 0, we treat the plugin_status data as if it didn't exist.
6015 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
6016 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
6017 }
6018 $closed_checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
6019 $closed_last_check = $closed_checker->get_last_check_time();
6020 if ( $closed_last_check > 0 ) {
6021 $closed_plugins = $closed_checker->get_closed_plugins();
6022 $ignored_closed_plugins = $closed_checker->get_ignored_closed_plugins();
6023 } else {
6024 $closed_plugins = array();
6025 $ignored_closed_plugins = array();
6026 }
6027 $has_closed = ! empty( $closed_plugins );
6028 $datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
6029 ?>
6030 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="file_integrity" <?php echo $is_disabled ? 'inert' : ''; ?>>
6031 <div id="vigilante-section-fi-monitoring" class="vigilante-settings-section">
6032 <h2>
6033 <?php esc_html_e( 'File Integrity Monitoring', 'vigilante' ); ?>
6034 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
6035 </h2>
6036 <p><?php esc_html_e( 'Detects file modifications using WordPress.org checksums.', 'vigilante' ); ?></p>
6037
6038 <table class="form-table">
6039 <tr>
6040 <th scope="row"><?php esc_html_e( 'Automatic Scans', 'vigilante' ); ?></th>
6041 <td>
6042 <label>
6043 <input type="checkbox" name="file_integrity[auto_scan]" value="1" <?php checked( ! empty( $options['auto_scan'] ) ); ?>>
6044 <?php esc_html_e( 'Enable scheduled file integrity scans', 'vigilante' ); ?>
6045 </label>
6046 </td>
6047 </tr>
6048 <tr>
6049 <th scope="row"><label for="vigilante-f-file-integrity-scan-frequency"><?php esc_html_e( 'Scan Frequency', 'vigilante' ); ?></label></th>
6050 <td>
6051 <select id="vigilante-f-file-integrity-scan-frequency" name="file_integrity[scan_frequency]">
6052 <option value="daily" <?php selected( $options['scan_frequency'] ?? 'daily', 'daily' ); ?>><?php esc_html_e( 'Daily', 'vigilante' ); ?></option>
6053 <option value="weekly" <?php selected( $options['scan_frequency'] ?? 'daily', 'weekly' ); ?>><?php esc_html_e( 'Weekly', 'vigilante' ); ?></option>
6054 </select>
6055 </td>
6056 </tr>
6057 <tr>
6058 <th scope="row"><label for="vigilante-f-file-integrity-notify-level"><?php esc_html_e( 'Email Notifications', 'vigilante' ); ?></label></th>
6059 <td>
6060 <select id="vigilante-f-file-integrity-notify-level" name="file_integrity[notify_level]">
6061 <option value="all" <?php selected( $notify_level, 'all' ); ?>><?php esc_html_e( 'All issues (modified + suspicious)', 'vigilante' ); ?></option>
6062 <option value="suspicious_only" <?php selected( $notify_level, 'suspicious_only' ); ?>><?php esc_html_e( 'Suspicious files only', 'vigilante' ); ?></option>
6063 <option value="disabled" <?php selected( $notify_level, 'disabled' ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
6064 </select>
6065 <p class="description"><?php esc_html_e( '"Suspicious files only" reduces noise by skipping modified file notifications. Recommended for most sites.', 'vigilante' ); ?></p>
6066 </td>
6067 </tr>
6068 <tr>
6069 <th scope="row"><?php esc_html_e( 'Instant Alert', 'vigilante' ); ?></th>
6070 <td>
6071 <label>
6072 <input type="checkbox" name="file_integrity[instant_alert]" value="1" <?php checked( ! empty( $options['instant_alert'] ) ); ?>>
6073 <?php esc_html_e( 'Send immediate alert when modified, suspicious or additional files are detected, or when a closed plugin is found', 'vigilante' ); ?>
6074 </label>
6075 <p class="description"><?php esc_html_e( 'Fires even if the Email Notifications setting above is set to Disabled.', 'vigilante' ); ?></p>
6076 <p class="description">
6077 <?php
6078 printf(
6079 /* translators: %s: Link to notification settings */
6080 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
6081 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
6082 );
6083 ?>
6084 </p>
6085 </td>
6086 </tr>
6087 <tr>
6088 <th scope="row"><?php esc_html_e( 'Test email', 'vigilante' ); ?></th>
6089 <td>
6090 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
6091 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
6092 </button>
6093 <span class="vigilante-test-email-result" style="margin-left:8px;"></span>
6094 <p class="description"><?php esc_html_e( 'Sends a test message to the configured recipients to confirm email delivery works.', 'vigilante' ); ?></p>
6095 </td>
6096 </tr>
6097 <tr>
6098 <th scope="row"><?php esc_html_e( 'Scan Scope', 'vigilante' ); ?></th>
6099 <td>
6100 <fieldset>
6101 <label>
6102 <input type="checkbox" name="file_integrity[scan_core]" value="1" <?php checked( $options['scan_core'] ?? true ); ?>>
6103 <?php esc_html_e( 'Core files (compare against WordPress.org checksums)', 'vigilante' ); ?>
6104 </label>
6105 <br>
6106 <label>
6107 <input type="checkbox" name="file_integrity[scan_plugins]" value="1" <?php checked( $options['scan_plugins'] ?? true ); ?>>
6108 <?php esc_html_e( 'Plugins (WordPress.org repository plugins)', 'vigilante' ); ?>
6109 </label>
6110 <br>
6111 <label>
6112 <input type="checkbox" name="file_integrity[scan_themes]" value="1" <?php checked( $options['scan_themes'] ?? true ); ?>>
6113 <?php esc_html_e( 'Themes (WordPress.org repository themes)', 'vigilante' ); ?>
6114 </label>
6115 <br>
6116 <label>
6117 <input type="checkbox" name="file_integrity[scan_uploads]" value="1" <?php checked( $options['scan_uploads'] ?? true ); ?>>
6118 <?php esc_html_e( 'Uploads directory (detect PHP files, double extensions, .htaccess)', 'vigilante' ); ?>
6119 </label>
6120 <br>
6121 <label>
6122 <input type="checkbox" name="file_integrity[scan_critical_config]" value="1" <?php checked( $options['scan_critical_config'] ?? true ); ?>>
6123 <?php esc_html_e( 'Critical config files (wp-config.php, .htaccess baseline monitoring)', 'vigilante' ); ?>
6124 </label>
6125 <br>
6126 <label>
6127 <input type="checkbox" name="file_integrity[check_closed_plugins]" value="1" <?php checked( $options['check_closed_plugins'] ?? true ); ?>>
6128 <?php esc_html_e( 'Closed plugins (daily check against the WordPress.org repository)', 'vigilante' ); ?>
6129 </label>
6130 </fieldset>
6131 </td>
6132 </tr>
6133 <tr>
6134 <th scope="row"><label for="vigilante-f-file-integrity-excluded-paths"><?php esc_html_e( 'Excluded Paths', 'vigilante' ); ?></label></th>
6135 <td>
6136 <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>
6137 <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>
6138 </td>
6139 </tr>
6140 <tr>
6141 <th scope="row"><label for="vigilante-f-file-integrity-excluded-extensions"><?php esc_html_e( 'Excluded Extensions', 'vigilante' ); ?></label></th>
6142 <td>
6143 <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>
6144 <p class="description">
6145 <?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' ); ?>
6146 <br>
6147 <?php
6148 printf(
6149 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the scoped-extension example. */
6150 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' ),
6151 '<code>',
6152 '</code>'
6153 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
6154 ?>
6155 </p>
6156 </td>
6157 </tr>
6158 </table>
6159 </div>
6160
6161 <p class="submit vigilante-submit-buttons">
6162 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
6163 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
6164 </button>
6165 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
6166 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
6167 </button>
6168 <span class="vigilante-buttons-separator"></span>
6169 <button type="button" class="button button-primary vigilante-run-scan">
6170 <?php esc_html_e( 'Run Scan Now', 'vigilante' ); ?>
6171 </button>
6172 <button type="button" class="button vigilante-clear-scan-btn vigilante-clear-scan">
6173 <?php esc_html_e( 'Clear Previous Results', 'vigilante' ); ?>
6174 </button>
6175 </p>
6176 </form>
6177
6178 <div id="vigilante-scan-results" class="vigilante-settings-section" style="display:none;"></div>
6179
6180 <?php if ( $last_scan || $has_closed || $closed_last_check > 0 ) : ?>
6181 <div id="vigilante-section-fi-last-scan" class="vigilante-settings-section">
6182 <h2><?php esc_html_e( 'Last Scan Results', 'vigilante' ); ?></h2>
6183 <?php if ( $last_scan ) : ?>
6184 <p>
6185 <?php
6186 // Build the "X files scanned" hint inline with the date so it doesn't
6187 // need its own stat box (keeps the row compact when closed plugins are
6188 // present).
6189 $scanned_total = 0;
6190 if ( $last_results ) {
6191 $scanned_total = (int) ( $last_results['ok'] ?? 0 )
6192 + count( $last_results['modified'] ?? array() )
6193 + count( $last_results['suspicious'] ?? array() )
6194 + count( $last_results['extra'] ?? array() )
6195 + count( $ignored_files );
6196 }
6197 if ( $scanned_total > 0 ) {
6198 printf(
6199 /* translators: 1: date and time of last scan, 2: formatted file count */
6200 esc_html__( 'Last scan: %1$s (%2$s files scanned)', 'vigilante' ),
6201 esc_html( wp_date( $datetime_format, $last_scan ) ),
6202 esc_html( number_format_i18n( $scanned_total ) )
6203 );
6204 } else {
6205 printf(
6206 /* translators: %s: date and time of last scan */
6207 esc_html__( 'Last scan: %s', 'vigilante' ),
6208 esc_html( wp_date( $datetime_format, $last_scan ) )
6209 );
6210 }
6211 if ( $closed_last_check > 0 && $closed_last_check !== (int) $last_scan ) {
6212 echo ' &middot; ';
6213 printf(
6214 /* translators: %s: date and time of last closed plugins check */
6215 esc_html__( 'Closed plugins last checked: %s', 'vigilante' ),
6216 esc_html( wp_date( $datetime_format, $closed_last_check ) )
6217 );
6218 }
6219 ?>
6220 </p>
6221 <?php elseif ( $closed_last_check > 0 ) : ?>
6222 <p>
6223 <?php
6224 printf(
6225 /* translators: %s: date and time of last closed plugins check */
6226 esc_html__( 'Closed plugins last checked: %s &middot; the daily cron is running, no full integrity scan yet.', 'vigilante' ),
6227 esc_html( wp_date( $datetime_format, $closed_last_check ) )
6228 );
6229 ?>
6230 </p>
6231 <?php endif; ?>
6232 <div id="vigilante-last-scan-results">
6233 <?php if ( $last_results || $has_closed ) : ?>
6234 <div class="vigilante-scan-summary">
6235 <?php if ( $last_results ) : ?>
6236 <div class="vigilante-scan-stat vigilante-stat-ok">
6237 <span class="vigilante-stat-number"><?php echo esc_html( $last_results['ok'] ?? 0 ); ?></span>
6238 <span class="vigilante-stat-label"><?php esc_html_e( 'OK', 'vigilante' ); ?></span>
6239 </div>
6240 <div class="vigilante-scan-stat vigilante-stat-modified">
6241 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['modified'] ?? array() ) ); ?></span>
6242 <span class="vigilante-stat-label"><?php esc_html_e( 'Modified', 'vigilante' ); ?></span>
6243 </div>
6244 <div class="vigilante-scan-stat vigilante-stat-suspicious">
6245 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['suspicious'] ?? array() ) ); ?></span>
6246 <span class="vigilante-stat-label"><?php esc_html_e( 'Suspicious', 'vigilante' ); ?></span>
6247 </div>
6248 <div class="vigilante-scan-stat vigilante-stat-extra">
6249 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['extra'] ?? array() ) ); ?></span>
6250 <span class="vigilante-stat-label"><?php esc_html_e( 'Extra', 'vigilante' ); ?></span>
6251 </div>
6252 <?php endif; ?>
6253 <?php if ( $has_closed ) : ?>
6254 <div class="vigilante-scan-stat vigilante-stat-suspicious">
6255 <span class="vigilante-stat-number" style="color: #d63638;"><?php echo (int) count( $closed_plugins ); ?></span>
6256 <span class="vigilante-stat-label"><?php esc_html_e( 'Closed/Removed', 'vigilante' ); ?></span>
6257 </div>
6258 <?php endif; ?>
6259 <?php if ( ! empty( $ignored_files ) ) : ?>
6260 <div class="vigilante-scan-stat vigilante-stat-ignored">
6261 <span class="vigilante-stat-number"><?php echo esc_html( count( $ignored_files ) ); ?></span>
6262 <span class="vigilante-stat-label"><?php esc_html_e( 'Ignored', 'vigilante' ); ?></span>
6263 </div>
6264 <?php endif; ?>
6265 </div>
6266
6267 <?php if ( ! empty( $last_results['suspicious'] ) ) : ?>
6268 <div class="vigilante-file-list vigilante-suspicious-files vigilante-paginated-section" data-bulk-mode="ignore">
6269 <h3 style="color: #d63638;"><?php esc_html_e( 'Suspicious Files', 'vigilante' ); ?></h3>
6270 <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>
6271 <div class="vigilante-fi-bulk-bar">
6272 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
6273 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
6274 </div>
6275 <div class="vigilante-fi-pagination-wrap"></div>
6276 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
6277 <thead>
6278 <tr>
6279 <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>
6280 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6281 <th style="width: 250px;"><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
6282 <th style="width: 120px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
6283 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6284 </tr>
6285 </thead>
6286 <tbody>
6287 <?php
6288 foreach ( $last_results['suspicious'] as $item ) {
6289 $file_path = '';
6290 $file_reason = __( 'Unknown', 'vigilante' );
6291 $file_type = 'unknown';
6292
6293 if ( is_array( $item ) ) {
6294 if ( isset( $item['file'] ) ) {
6295 $file_path = $item['file'];
6296 }
6297 if ( isset( $item['reason'] ) ) {
6298 $file_reason = $item['reason'];
6299 }
6300 if ( isset( $item['type'] ) ) {
6301 $file_type = $item['type'];
6302 }
6303 } else {
6304 $file_path = (string) $item;
6305 }
6306 ?>
6307 <tr>
6308 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
6309 <td><code style="color: #d63638;"><?php echo esc_html( $file_path ); ?></code></td>
6310 <td><?php echo esc_html( $file_reason ); ?></td>
6311 <td><?php echo esc_html( $file_type ); ?></td>
6312 <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>
6313 </tr>
6314 <?php
6315 }
6316 ?>
6317 </tbody>
6318 </table>
6319 </div>
6320 <?php endif; ?>
6321
6322 <?php if ( ! empty( $last_results['extra'] ) ) : ?>
6323 <div class="vigilante-file-list vigilante-extra-files vigilante-paginated-section" data-bulk-mode="ignore">
6324 <h3 style="color: #b32d2e;"><?php esc_html_e( 'Extra Files', 'vigilante' ); ?></h3>
6325 <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>
6326 <div class="vigilante-fi-bulk-bar">
6327 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
6328 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
6329 </div>
6330 <div class="vigilante-fi-pagination-wrap"></div>
6331 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
6332 <thead>
6333 <tr>
6334 <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>
6335 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6336 <th style="width: 250px;"><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
6337 <th style="width: 120px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
6338 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6339 </tr>
6340 </thead>
6341 <tbody>
6342 <?php
6343 foreach ( $last_results['extra'] as $item ) {
6344 $file_path = is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item;
6345 $file_reason = is_array( $item ) ? ( $item['reason'] ?? __( 'Unknown', 'vigilante' ) ) : __( 'Unknown', 'vigilante' );
6346 $file_type = is_array( $item ) ? ( $item['type'] ?? 'unknown' ) : 'unknown';
6347 ?>
6348 <tr>
6349 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
6350 <td><code style="color: #b32d2e;"><?php echo esc_html( $file_path ); ?></code></td>
6351 <td><?php echo esc_html( $file_reason ); ?></td>
6352 <td><?php echo esc_html( $file_type ); ?></td>
6353 <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>
6354 </tr>
6355 <?php
6356 }
6357 ?>
6358 </tbody>
6359 </table>
6360 </div>
6361 <?php endif; ?>
6362
6363 <?php
6364 // Split critical config files from regular modified files.
6365 // Computed unconditionally so the three sub-sections that consume
6366 // these arrays (Critical Config, Closed + Removed, Modified Files)
6367 // can render independently and in the order the team picked.
6368 $critical_modified = array();
6369 $regular_modified = array();
6370 if ( $last_results && ! empty( $last_results['modified'] ) ) {
6371 foreach ( $last_results['modified'] as $item ) {
6372 if ( is_array( $item ) && isset( $item['type'] ) && 'critical_config' === $item['type'] ) {
6373 $critical_modified[] = $item;
6374 } else {
6375 $regular_modified[] = $item;
6376 }
6377 }
6378 }
6379 ?>
6380
6381 <?php if ( ! empty( $critical_modified ) ) : ?>
6382 <div class="vigilante-file-list vigilante-critical-config-files">
6383 <h3 style="color: #e36210;"><?php esc_html_e( 'Critical config files modified', 'vigilante' ); ?></h3>
6384 <p class="description">
6385 <?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' ); ?>
6386 </p>
6387 <table class="wp-list-table widefat fixed striped">
6388 <thead>
6389 <tr>
6390 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6391 <th style="width: 200px;"><?php esc_html_e( 'Changes', 'vigilante' ); ?></th>
6392 <th style="width: 220px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6393 </tr>
6394 </thead>
6395 <tbody>
6396 <?php foreach ( $critical_modified as $crit_item ) :
6397 $crit_file = $crit_item['file'] ?? '';
6398 $crit_baseline_size = $crit_item['baseline_size'] ?? 0;
6399 $crit_current_size = $crit_item['current_size'] ?? 0;
6400 $crit_diff = $crit_item['diff'] ?? array();
6401 $crit_id = sanitize_html_class( $crit_file );
6402 $added_count = is_array( $crit_diff ) ? count( $crit_diff['added'] ?? array() ) : 0;
6403 $removed_count = is_array( $crit_diff ) ? count( $crit_diff['removed'] ?? array() ) : 0;
6404 $diff_unavailable = is_array( $crit_diff ) && ! empty( $crit_diff['unavailable'] );
6405 ?>
6406 <tr>
6407 <td><code style="color: #e36210;"><?php echo esc_html( $crit_file ); ?></code></td>
6408 <td>
6409 <?php if ( ! $diff_unavailable ) : ?>
6410 <span style="color: #007017;">+<?php echo (int) $added_count; ?></span>
6411 <span style="color: #b32d2e;">-<?php echo (int) $removed_count; ?></span>
6412 <?php esc_html_e( 'lines', 'vigilante' ); ?><br>
6413 <?php endif; ?>
6414 <small style="color: #50575e;">
6415 <?php
6416 printf(
6417 /* translators: 1: baseline size, 2: current size */
6418 esc_html__( '%1$s &rarr; %2$s bytes', 'vigilante' ),
6419 esc_html( number_format_i18n( $crit_baseline_size ) ),
6420 esc_html( number_format_i18n( $crit_current_size ) )
6421 );
6422 ?>
6423 </small>
6424 </td>
6425 <td>
6426 <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' ); ?>">
6427 <?php esc_html_e( 'Review changes', 'vigilante' ); ?>
6428 </button>
6429 <?php if ( $this->critical_approval_locked() ) : ?>
6430 <span class="description" style="display:block;margin-top:4px;">
6431 <?php echo esc_html( $this->critical_approval_notice() ); ?>
6432 </span>
6433 <?php else : ?>
6434 <button type="button" class="button button-small button-primary vigilante-approve-critical-file" data-file="<?php echo esc_attr( $crit_file ); ?>">
6435 <?php esc_html_e( 'Approve', 'vigilante' ); ?>
6436 </button>
6437 <?php endif; ?>
6438 </td>
6439 </tr>
6440 <tr id="vigilante-critical-content-<?php echo esc_attr( $crit_id ); ?>" class="vigilante-critical-content-row" style="display:none;">
6441 <td colspan="3" style="padding: 0;">
6442 <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;">
6443 <?php if ( $diff_unavailable ) : ?>
6444 <p style="color: #50575e; font-style: italic; margin: 0;">
6445 <?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' ); ?>
6446 </p>
6447 <?php elseif ( empty( $crit_diff['added'] ) && empty( $crit_diff['removed'] ) ) : ?>
6448 <p style="color: #50575e; font-style: italic; margin: 0;">
6449 <?php esc_html_e( 'No line-level changes detected (may be whitespace or reordering).', 'vigilante' ); ?>
6450 </p>
6451 <?php else : ?>
6452 <?php if ( ! empty( $crit_diff['removed'] ) ) : ?>
6453 <?php foreach ( $crit_diff['removed'] as $rline ) : ?>
6454 <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>
6455 <?php endforeach; ?>
6456 <?php endif; ?>
6457 <?php if ( ! empty( $crit_diff['added'] ) ) : ?>
6458 <?php foreach ( $crit_diff['added'] as $aline ) : ?>
6459 <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>
6460 <?php endforeach; ?>
6461 <?php endif; ?>
6462 <?php endif; ?>
6463 </div>
6464 </td>
6465 </tr>
6466 <?php endforeach; ?>
6467 </tbody>
6468 </table>
6469 </div>
6470 <?php endif; ?>
6471
6472 <?php if ( $has_closed ) : ?>
6473 <div class="vigilante-file-list vigilante-closed-plugins">
6474 <h3 id="vigilante-section-fi-closed-plugins" style="color: #d63638;"><?php esc_html_e( 'Closed + Removed Plugins', 'vigilante' ); ?></h3>
6475 <p class="description" style="color: #d63638;">
6476 <?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' ); ?>
6477 </p>
6478 <table class="wp-list-table widefat striped">
6479 <thead>
6480 <tr>
6481 <th><?php esc_html_e( 'Plugin', 'vigilante' ); ?></th>
6482 <th style="width: 70px;"><?php esc_html_e( 'Version', 'vigilante' ); ?></th>
6483 <th style="width: 90px;"><?php esc_html_e( 'State', 'vigilante' ); ?></th>
6484 <th style="width: 110px;"><?php esc_html_e( 'Closed date', 'vigilante' ); ?></th>
6485 <th><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
6486 <th style="width: 130px;"><?php esc_html_e( 'Detected', 'vigilante' ); ?></th>
6487 <th style="width: 90px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6488 </tr>
6489 </thead>
6490 <tbody>
6491 <?php foreach ( $closed_plugins as $cp_slug => $cp_entry ) :
6492 $cp_state = $cp_entry['state'] ?? '';
6493 $cp_state_label = 'closed' === $cp_state ? __( 'Closed', 'vigilante' ) : __( 'Removed', 'vigilante' );
6494 $cp_state_color = 'closed' === $cp_state ? '#d63638' : '#b32d2e';
6495 $cp_reason = '';
6496 if ( ! empty( $cp_entry['closed_reason_text'] ) ) {
6497 $cp_reason = $cp_entry['closed_reason_text'];
6498 } elseif ( 'removed' === $cp_state ) {
6499 $cp_reason = __( 'Removed from repository (metadata hidden, typical of Security Issue closures)', 'vigilante' );
6500 }
6501 $cp_detected = isset( $cp_entry['first_detected'] ) ? (int) $cp_entry['first_detected'] : 0;
6502 ?>
6503 <tr>
6504 <td>
6505 <strong><?php echo esc_html( $cp_entry['name'] ?? $cp_slug ); ?></strong><br>
6506 <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>
6507 </td>
6508 <td><?php echo esc_html( $cp_entry['version'] ?? '' ); ?></td>
6509 <td><span style="color: <?php echo esc_attr( $cp_state_color ); ?>; font-weight: 600;"><?php echo esc_html( $cp_state_label ); ?></span></td>
6510 <td><?php echo esc_html( $cp_entry['closed_date'] ?? '' ); ?></td>
6511 <td><?php echo esc_html( $cp_reason ); ?></td>
6512 <td>
6513 <?php echo $cp_detected > 0 ? esc_html( wp_date( $datetime_format, $cp_detected ) ) : '&mdash;'; ?>
6514 </td>
6515 <td>
6516 <button type="button" class="button button-small vigilante-ignore-closed-plugin" data-slug="<?php echo esc_attr( $cp_slug ); ?>">
6517 <?php esc_html_e( 'Ignore', 'vigilante' ); ?>
6518 </button>
6519 </td>
6520 </tr>
6521 <?php endforeach; ?>
6522 </tbody>
6523 </table>
6524 </div>
6525 <?php endif; ?>
6526
6527 <?php if ( ! empty( $regular_modified ) ) : ?>
6528 <div class="vigilante-file-list vigilante-paginated-section" data-bulk-mode="ignore">
6529 <h3><?php esc_html_e( 'Modified Files', 'vigilante' ); ?></h3>
6530 <p class="description"><?php esc_html_e( 'These files (apparently) differ from the original WordPress or plugin versions.', 'vigilante' ); ?></p>
6531 <div class="vigilante-fi-bulk-bar">
6532 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
6533 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
6534 </div>
6535 <div class="vigilante-fi-pagination-wrap"></div>
6536 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
6537 <thead>
6538 <tr>
6539 <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>
6540 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6541 <th style="width: 100px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
6542 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6543 </tr>
6544 </thead>
6545 <tbody>
6546 <?php
6547 foreach ( $regular_modified as $item ) {
6548 $file_path = '';
6549 $file_type = 'unknown';
6550
6551 if ( is_array( $item ) ) {
6552 if ( isset( $item['file'] ) ) {
6553 $file_path = $item['file'];
6554 }
6555 if ( isset( $item['type'] ) ) {
6556 $file_type = $item['type'];
6557 }
6558 } else {
6559 $file_path = (string) $item;
6560 }
6561 ?>
6562 <tr>
6563 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
6564 <td><code><?php echo esc_html( $file_path ); ?></code></td>
6565 <td><?php echo esc_html( $file_type ); ?></td>
6566 <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>
6567 </tr>
6568 <?php
6569 }
6570 ?>
6571 </tbody>
6572 </table>
6573 </div>
6574 <?php endif; ?>
6575
6576 <?php if ( $last_results && empty( $last_results['modified'] ) && empty( $last_results['suspicious'] ) && empty( $last_results['extra'] ) && ! $has_closed ) : ?>
6577 <p class="vigilante-all-clear" style="color: #00a32a; font-weight: bold;">
6578 <?php esc_html_e( 'Good Job! All files passed integrity check. No issues found.', 'vigilante' ); ?>
6579 </p>
6580 <?php endif; ?>
6581 <?php endif; ?>
6582 </div>
6583 </div>
6584 <?php endif; ?>
6585
6586 <?php if ( ! empty( $ignored_closed_plugins ) ) : ?>
6587 <div id="vigilante-section-fi-ignored-closed" class="vigilante-settings-section">
6588 <h2><?php esc_html_e( 'Ignored Closed + Removed Plugins', 'vigilante' ); ?></h2>
6589 <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>
6590 <table class="wp-list-table widefat fixed striped">
6591 <thead>
6592 <tr>
6593 <th><?php esc_html_e( 'Plugin', 'vigilante' ); ?></th>
6594 <th style="width: 110px;"><?php esc_html_e( 'State', 'vigilante' ); ?></th>
6595 <th style="width: 120px;"><?php esc_html_e( 'Closed date', 'vigilante' ); ?></th>
6596 <th style="width: 130px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6597 </tr>
6598 </thead>
6599 <tbody>
6600 <?php foreach ( $ignored_closed_plugins as $icp_slug => $icp_entry ) :
6601 $icp_state = $icp_entry['state'] ?? '';
6602 $icp_state_label = 'closed' === $icp_state ? __( 'Closed', 'vigilante' ) : __( 'Removed', 'vigilante' );
6603 ?>
6604 <tr>
6605 <td>
6606 <strong><?php echo esc_html( $icp_entry['name'] ?? $icp_slug ); ?></strong><br>
6607 <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>
6608 </td>
6609 <td><?php echo esc_html( $icp_state_label ); ?></td>
6610 <td><?php echo esc_html( $icp_entry['closed_date'] ?? '' ); ?></td>
6611 <td>
6612 <button type="button" class="button button-small vigilante-unignore-closed-plugin" data-slug="<?php echo esc_attr( $icp_slug ); ?>">
6613 <?php esc_html_e( 'Stop ignoring', 'vigilante' ); ?>
6614 </button>
6615 </td>
6616 </tr>
6617 <?php endforeach; ?>
6618 </tbody>
6619 </table>
6620 <p style="margin-top: 10px;">
6621 <button type="button" class="button vigilante-clear-ignored-closed-plugins"><?php esc_html_e( 'Clear All Ignored Closed + Removed Plugins', 'vigilante' ); ?></button>
6622 </p>
6623 </div>
6624 <?php endif; ?>
6625
6626 <?php if ( ! empty( $ignored_files ) ) : ?>
6627 <div id="vigilante-section-fi-ignored" class="vigilante-settings-section">
6628 <h2><?php esc_html_e( 'Ignored Files', 'vigilante' ); ?></h2>
6629 <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>
6630 <div class="vigilante-paginated-section" data-bulk-mode="unignore">
6631 <div class="vigilante-fi-bulk-bar">
6632 <button type="button" class="button vigilante-bulk-unignore" disabled><?php esc_html_e( 'Stop ignoring selected', 'vigilante' ); ?></button>
6633 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
6634 </div>
6635 <div class="vigilante-fi-pagination-wrap"></div>
6636 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
6637 <thead>
6638 <tr>
6639 <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>
6640 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6641 <th style="width: 120px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6642 </tr>
6643 </thead>
6644 <tbody>
6645 <?php foreach ( $ignored_files as $file ) : ?>
6646 <tr>
6647 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file ); ?>"></th>
6648 <td><code><?php echo esc_html( $file ); ?></code></td>
6649 <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>
6650 </tr>
6651 <?php endforeach; ?>
6652 </tbody>
6653 </table>
6654 </div>
6655 <p style="margin-top: 10px;">
6656 <button type="button" class="button vigilante-clear-ignored"><?php esc_html_e( 'Clear All Ignored Files', 'vigilante' ); ?></button>
6657 </p>
6658 </div>
6659 <?php endif; ?>
6660 <?php
6661 }
6662
6663 /**
6664 * Render sidebar with promotional widgets
6665 */
6666 private function render_sidebar() {
6667 $promo_banner = new Vigilante_Promo_Banner( 'vigilante' );
6668 $promo_banner->render();
6669 }
6670
6671 /**
6672 * AJAX: Download a ZIP backup of the critical config files.
6673 *
6674 * Streams wp-config.php and .htaccess (and robots.txt if present) as a
6675 * downloadable archive. Config backups are no longer left as files under the
6676 * web root, so this hands the admin the archive directly.
6677 */
6678 public function ajax_download_files_backup() {
6679 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
6680
6681 if ( ! current_user_can( 'manage_options' ) ) {
6682 wp_die( esc_html__( 'Permission denied.', 'vigilante' ), 403 );
6683 }
6684
6685 // The archive carries wp-config.php, which a whole network shares. On a
6686 // network manage_options is held by every subsite administrator, so the
6687 // same gate the writers use applies here.
6688 if ( ! Vigilante_Settings::can_write_shared_files() ) {
6689 wp_die( esc_html( Vigilante_Settings::get_shared_files_notice() ), 403 );
6690 }
6691
6692 $backup_manager = new Vigilante_Backup_Manager();
6693 $result = $backup_manager->stream_files_zip();
6694
6695 // stream_files_zip() exits on success; only a WP_Error returns here.
6696 if ( is_wp_error( $result ) ) {
6697 wp_die( esc_html( $result->get_error_message() ), 500 );
6698 }
6699 }
6700
6701 /**
6702 * AJAX: Save settings
6703 */
6704 public function ajax_save_settings() {
6705 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
6706
6707 if ( ! current_user_can( 'manage_options' ) ) {
6708 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
6709 }
6710
6711 $section = isset( $_POST['section'] ) ? sanitize_key( $_POST['section'] ) : '';
6712
6713 // Handle $_POST['data'] based on type
6714 if ( isset( $_POST['data'] ) && is_array( $_POST['data'] ) ) {
6715 $data = map_deep( wp_unslash( $_POST['data'] ), 'sanitize_text_field' );
6716 } elseif ( isset( $_POST['data'] ) ) {
6717 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
6718 $raw_data = wp_unslash( $_POST['data'] );
6719 parse_str( $raw_data, $data );
6720 $data = map_deep( $data, 'sanitize_textarea_field' );
6721 } else {
6722 $data = array();
6723 }
6724
6725 if ( empty( $section ) ) {
6726 wp_send_json_error( __( 'Invalid section.', 'vigilante' ) );
6727 }
6728
6729 // Check if 2FA is being enabled or method changed (for notification sending)
6730 $send_2fa_notification = false;
6731 $send_login_url_notification = false;
6732
6733 if ( 'login_security' === $section ) {
6734 // Read old state from DB
6735 $db_options = get_option( Vigilante_Settings::OPTION_NAME, array() );
6736 $old_2fa_enabled = ! empty( $db_options['login_security']['two_factor']['enabled'] );
6737 $old_method = $db_options['login_security']['two_factor']['method'] ?? 'email';
6738
6739 // Check new state from submitted data
6740 $new_2fa_enabled = false;
6741 $notify_on_enable = false;
6742 $new_method = isset( $data['login_security']['two_factor']['method'] )
6743 ? sanitize_key( $data['login_security']['two_factor']['method'] )
6744 : 'email';
6745
6746 if ( isset( $data['login_security']['two_factor']['enabled'] ) ) {
6747 $new_2fa_enabled = filter_var( $data['login_security']['two_factor']['enabled'], FILTER_VALIDATE_BOOLEAN );
6748 }
6749 if ( isset( $data['login_security']['two_factor']['notify_on_enable'] ) ) {
6750 $notify_on_enable = filter_var( $data['login_security']['two_factor']['notify_on_enable'], FILTER_VALIDATE_BOOLEAN );
6751 }
6752
6753 // Send notification if:
6754 // 1. 2FA is being enabled (was off, now on) OR
6755 // 2. Method changed while 2FA is enabled
6756 if ( $notify_on_enable && $new_2fa_enabled ) {
6757 if ( ! $old_2fa_enabled || ( $old_2fa_enabled && $old_method !== $new_method ) ) {
6758 $send_2fa_notification = true;
6759 }
6760 }
6761
6762 // Check if login URL changed and notification is enabled
6763 $old_login_url = $db_options['login_security']['custom_login_url'] ?? '';
6764 $new_login_url = isset( $data['login_security']['custom_login_url'] )
6765 ? sanitize_title( $data['login_security']['custom_login_url'] )
6766 : '';
6767 $notify_on_url_change = isset( $data['login_security']['notify_on_login_url_change'] )
6768 ? filter_var( $data['login_security']['notify_on_login_url_change'], FILTER_VALIDATE_BOOLEAN )
6769 : false;
6770
6771 if ( $notify_on_url_change && ! empty( $new_login_url ) && $new_login_url !== $old_login_url ) {
6772 $send_login_url_notification = true;
6773 }
6774 }
6775
6776 // Get defaults
6777 $defaults = $this->settings->get_default_options();
6778
6779 // Read ONLY saved options from database (not merged with defaults)
6780 $saved_options = get_option( Vigilante_Settings::OPTION_NAME, array() );
6781
6782 // What is stored before this request changes anything: the shared file
6783 // settings this user may not change are put back from here (2.11.6).
6784 $stored_options = $saved_options;
6785 $locked = Vigilante_Settings::get_locked_file_settings();
6786
6787 if ( isset( $locked[ $section ] ) && true === $locked[ $section ] ) {
6788 wp_send_json_error( Vigilante_Settings::get_shared_files_notice() );
6789 }
6790
6791 // A module switch is a single key, so refusing says more than a success
6792 // that changed nothing, and the dashboard puts the toggle back.
6793 if ( 'modules' === $section && isset( $locked['modules'], $data['modules'] ) && is_array( $locked['modules'] ) && is_array( $data['modules'] ) ) {
6794 foreach ( array_keys( $data['modules'] ) as $vg_module ) {
6795 if ( in_array( sanitize_key( $vg_module ), $locked['modules'], true ) ) {
6796 wp_send_json_error( Vigilante_Settings::get_shared_files_notice() );
6797 }
6798 }
6799 }
6800
6801 $rejected_ips = array();
6802
6803 // Handle modules
6804 if ( 'modules' === $section && isset( $data['modules'] ) ) {
6805 if ( ! isset( $saved_options['modules'] ) ) {
6806 $saved_options['modules'] = array();
6807 }
6808 foreach ( $data['modules'] as $module => $enabled ) {
6809 $module = sanitize_key( $module );
6810 $saved_options['modules'][ $module ] = in_array( $enabled, array( '1', 1, 'true', true ), true );
6811 }
6812 // Clear active preset when modules change
6813 update_option( 'vigilante_active_preset', '' );
6814 } else {
6815 // Process primary section
6816 if ( isset( $data[ $section ] ) && is_array( $data[ $section ] ) ) {
6817 $section_defaults = isset( $defaults[ $section ] ) ? $defaults[ $section ] : array();
6818 $current_section = isset( $saved_options[ $section ] ) ? $saved_options[ $section ] : array();
6819
6820 // Process the submitted data
6821 $processed = $this->process_section_data( $data[ $section ], $section_defaults, $current_section );
6822
6823 // The IP boxes are free text and, until 2.9.9, whatever was typed
6824 // went straight into the option. An entry the matcher can never
6825 // match still sits in a security list looking like protection,
6826 // so the ones that cannot match are dropped and reported back
6827 // instead of being stored in silence.
6828 $rejected_ips = $this->filter_ip_lists( $section, $processed );
6829
6830 // Save the processed section
6831 $saved_options[ $section ] = $processed;
6832
6833 // Clear active preset when any section settings change
6834 update_option( 'vigilante_active_preset', '' );
6835 }
6836 }
6837
6838 // Clear cache before saving
6839 wp_cache_delete( Vigilante_Settings::OPTION_NAME, 'options' );
6840
6841 $saved_options = Vigilante_Settings::keep_locked_file_settings( $saved_options, $stored_options );
6842
6843 // Save to database
6844 update_option( Vigilante_Settings::OPTION_NAME, $saved_options );
6845
6846 // Clear the settings cache
6847 $this->settings->clear_cache();
6848
6849 // Apply changes based on section
6850 $this->apply_section_changes( $section, $saved_options );
6851
6852 // Send 2FA notifications after settings are saved
6853 $notification_result = null;
6854 if ( $send_2fa_notification ) {
6855 $notification_result = $this->send_2fa_enable_notifications();
6856 }
6857
6858 // Send login URL notifications after settings are saved
6859 $login_url_result = null;
6860 if ( $send_login_url_notification ) {
6861 $login_url_result = $this->send_login_url_notifications();
6862 }
6863
6864 // Build success message
6865 $message = __( 'Settings saved successfully.', 'vigilante' );
6866
6867 if ( $notification_result && $notification_result['sent'] > 0 ) {
6868 $message .= ' ' . sprintf(
6869 /* translators: %d: Number of emails sent */
6870 _n(
6871 '2FA notification sent to %d user.',
6872 '2FA notifications sent to %d users.',
6873 $notification_result['sent'],
6874 'vigilante'
6875 ),
6876 $notification_result['sent']
6877 );
6878 }
6879
6880 if ( $login_url_result && $login_url_result['sent'] > 0 ) {
6881 $message .= ' ' . sprintf(
6882 /* translators: %d: Number of emails sent */
6883 _n(
6884 'Login URL notification sent to %d user.',
6885 'Login URL notifications sent to %d users.',
6886 $login_url_result['sent'],
6887 'vigilante'
6888 ),
6889 $login_url_result['sent']
6890 );
6891 }
6892
6893 if ( ! empty( $rejected_ips ) ) {
6894 $message .= ' ' . sprintf(
6895 /* translators: %s: comma separated list of the entries that were not saved. */
6896 _n(
6897 'This entry is not a valid IP, CIDR range or wildcard, so it was not saved: %s',
6898 'These entries are not valid IPs, CIDR ranges or wildcards, so they were not saved: %s',
6899 count( $rejected_ips ),
6900 'vigilante'
6901 ),
6902 implode( ', ', array_map( 'esc_html', $rejected_ips ) )
6903 );
6904 }
6905
6906 wp_send_json_success( $message );
6907 }
6908
6909 /**
6910 * Keep only the IP patterns the matcher can actually match
6911 *
6912 * @since 2.9.9
6913 *
6914 * @param string $section Section being saved.
6915 * @param array $processed Section data, edited in place.
6916 * @return array Entries that were dropped, for the message back to the user.
6917 */
6918 private function filter_ip_lists( $section, &$processed ) {
6919 $lists = array(
6920 'firewall' => array( 'ip_whitelist', 'ip_blacklist' ),
6921 'login_security' => array( 'ip_whitelist' ),
6922 );
6923
6924 if ( ! isset( $lists[ $section ] ) ) {
6925 return array();
6926 }
6927
6928 $rejected = array();
6929
6930 foreach ( $lists[ $section ] as $key ) {
6931 if ( ! isset( $processed[ $key ] ) || ! is_array( $processed[ $key ] ) ) {
6932 continue;
6933 }
6934
6935 $split = Vigilante_IP_Utils::split_list( $processed[ $key ] );
6936 $processed[ $key ] = $split['valid'];
6937 $rejected = array_merge( $rejected, $split['rejected'] );
6938 }
6939
6940 return array_values( array_unique( $rejected ) );
6941 }
6942
6943 /**
6944 * Send 2FA enable notifications to users
6945 *
6946 * @return array Result with 'sent' and 'failed' counts.
6947 */
6948 private function send_2fa_enable_notifications() {
6949 $result = array(
6950 'sent' => 0,
6951 'failed' => 0,
6952 );
6953
6954 // Get settings for roles and method
6955 $login_security = $this->settings->get_section( 'login_security' );
6956 $two_factor = isset( $login_security['two_factor'] ) ? $login_security['two_factor'] : array();
6957 $roles = isset( $two_factor['enforced_roles'] ) ? $two_factor['enforced_roles'] : array( 'administrator' );
6958 $method = isset( $two_factor['method'] ) ? $two_factor['method'] : 'email';
6959
6960 if ( empty( $roles ) ) {
6961 $roles = array( 'administrator' );
6962 }
6963
6964 $excluded = isset( $two_factor['excluded_users'] ) ? array_map( 'absint', $two_factor['excluded_users'] ) : array();
6965
6966 // Get users with these roles
6967 $args = array(
6968 'role__in' => $roles,
6969 );
6970 if ( ! empty( $excluded ) ) {
6971 // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- Small excluded users list from settings.
6972 $args['exclude'] = $excluded;
6973 }
6974 $users = get_users( $args );
6975
6976 if ( empty( $users ) ) {
6977 return $result;
6978 }
6979
6980 $site_name = get_bloginfo( 'name' );
6981 $from_name = ! empty( $two_factor['email_from_name'] ) ? $two_factor['email_from_name'] : $site_name;
6982
6983 if ( 'totp' === $method ) {
6984 // Use TOTP class for styled HTML emails
6985 if ( ! class_exists( 'Vigilante_Two_Factor_TOTP' ) ) {
6986 require_once VIGILANTE_INCLUDES_DIR . 'class-two-factor-totp.php';
6987 }
6988 $totp = new Vigilante_Two_Factor_TOTP( $this->settings, $this->database, $this->activity_log );
6989
6990 foreach ( $users as $user ) {
6991 // Skip users who already have TOTP configured
6992 $totp_data = $this->database->get_totp_data( $user->ID );
6993 if ( $totp_data && ! empty( $totp_data['is_configured'] ) ) {
6994 continue;
6995 }
6996
6997 $sent = $totp->send_activation_email( $user, $site_name, $from_name );
6998
6999 if ( $sent ) {
7000 $this->database->mark_2fa_notified( $user->ID );
7001 $result['sent']++;
7002 } else {
7003 $result['failed']++;
7004 }
7005 }
7006 } else {
7007 // Email method - use existing email 2FA class
7008 if ( ! class_exists( 'Vigilante_Two_Factor_Email' ) ) {
7009 require_once VIGILANTE_INCLUDES_DIR . 'class-two-factor-email.php';
7010 }
7011 $email_2fa = new Vigilante_Two_Factor_Email( $this->settings, $this->database, $this->activity_log );
7012 return $email_2fa->send_activation_notifications( false );
7013 }
7014
7015 return $result;
7016 }
7017
7018 /**
7019 * Send login URL change notifications to users with admin access
7020 *
7021 * @return array Result with 'sent' and 'failed' counts.
7022 */
7023 private function send_login_url_notifications() {
7024 $login_options = $this->settings->get_section( 'login_security' );
7025 $custom_url = ! empty( $login_options['custom_login_url'] ) ? sanitize_title( $login_options['custom_login_url'] ) : '';
7026
7027 if ( empty( $custom_url ) ) {
7028 return array( 'sent' => 0, 'failed' => 0 );
7029 }
7030
7031 $login_url = home_url( $custom_url . '/' );
7032 $site_name = get_bloginfo( 'name' );
7033
7034 $admin_roles = array( 'administrator', 'editor', 'author', 'contributor' );
7035 $users = get_users( array( 'role__in' => $admin_roles ) );
7036
7037 if ( empty( $users ) ) {
7038 return array( 'sent' => 0, 'failed' => 0 );
7039 }
7040
7041 $subject = sprintf(
7042 /* translators: %s: Site name */
7043 __( '[%s] Your login URL has changed', 'vigilante' ),
7044 $site_name
7045 );
7046
7047 $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' ) );
7048 $body .= Vigilante_Email_Template::url_box( $login_url, __( 'Your new login URL:', 'vigilante' ) );
7049 $body .= Vigilante_Email_Template::alert_box( __( 'The old login address (wp-login.php) will no longer work.', 'vigilante' ) );
7050 $body .= Vigilante_Email_Template::button( $login_url, __( 'Go to login', 'vigilante' ) );
7051
7052 $sent = 0;
7053 $failed = 0;
7054
7055 foreach ( $users as $user ) {
7056 $result = Vigilante_Email_Template::send(
7057 $user->user_email,
7058 $subject,
7059 __( 'Login URL changed', 'vigilante' ),
7060 $body
7061 );
7062 if ( $result ) {
7063 $sent++;
7064 } else {
7065 $failed++;
7066 }
7067 }
7068
7069 if ( $this->activity_log ) {
7070 $this->activity_log->log(
7071 'login',
7072 'login_url_notified',
7073 sprintf(
7074 /* translators: 1: Sent count, 2: Failed count */
7075 __( 'Login URL notification sent on save: %1$d sent, %2$d failed', 'vigilante' ),
7076 $sent,
7077 $failed
7078 )
7079 );
7080 }
7081
7082 return array( 'sent' => $sent, 'failed' => $failed );
7083 }
7084
7085 /**
7086 * Process section data maintaining proper types from defaults
7087 *
7088 * @param array $submitted_data Data submitted from form.
7089 * @param array $defaults Default values for this section.
7090 * @param array $current Current saved values.
7091 * @param string $section_name Section name for special handling.
7092 * @return array Processed data.
7093 */
7094 private function process_section_data( $submitted_data, $defaults, $current, $section_name = '' ) {
7095 // Start with defaults, then merge current saved values
7096 $result = array_replace_recursive( $defaults, $current );
7097
7098 // Process each submitted value
7099 foreach ( $submitted_data as $key => $value ) {
7100 $key = sanitize_key( $key );
7101
7102 if ( is_array( $value ) ) {
7103 // Nested array (like rate_limiting)
7104 $nested_defaults = isset( $defaults[ $key ] ) && is_array( $defaults[ $key ] ) ? $defaults[ $key ] : array();
7105 $nested_current = isset( $result[ $key ] ) && is_array( $result[ $key ] ) ? $result[ $key ] : array();
7106 $result[ $key ] = $this->process_section_data( $value, $nested_defaults, $nested_current, $key );
7107 } else {
7108 // Determine type from default value
7109 $default_value = isset( $defaults[ $key ] ) ? $defaults[ $key ] : null;
7110
7111 if ( null === $default_value ) {
7112 // No default, check current value type or use as string
7113 $current_value = isset( $current[ $key ] ) ? $current[ $key ] : null;
7114 if ( is_bool( $current_value ) ) {
7115 $result[ $key ] = in_array( $value, array( '1', 1, 'true', true ), true );
7116 } elseif ( is_int( $current_value ) ) {
7117 $result[ $key ] = intval( $value );
7118 } elseif ( is_array( $current_value ) ) {
7119 $result[ $key ] = is_string( $value ) ? array_filter( array_map( 'trim', explode( "\n", $value ) ) ) : (array) $value;
7120 } else {
7121 $result[ $key ] = sanitize_text_field( $value );
7122 }
7123 } elseif ( is_bool( $default_value ) ) {
7124 // Boolean: '1', 1, 'true' become true; '0', 0, '', 'false' become false
7125 $result[ $key ] = in_array( $value, array( '1', 1, 'true', true ), true );
7126 } elseif ( is_int( $default_value ) ) {
7127 // Integer - with special handling for time fields shown in minutes
7128 $int_value = intval( $value );
7129
7130 // Convert minutes to seconds for login_security duration fields
7131 // These are displayed as minutes in the form but stored as seconds
7132 if ( in_array( $key, array( 'lockout_duration', 'max_lockout_duration' ), true ) ) {
7133 $int_value = $int_value * 60;
7134 }
7135
7136 $result[ $key ] = $int_value;
7137 } elseif ( is_array( $default_value ) ) {
7138 // Array from textarea (e.g., IP lists)
7139 if ( is_string( $value ) ) {
7140 $result[ $key ] = array_filter( array_map( 'trim', explode( "\n", $value ) ) );
7141 } else {
7142 $result[ $key ] = (array) $value;
7143 }
7144 } else {
7145 // String - preserve newlines for textarea fields
7146 if ( is_string( $value ) && ( strpos( $value, "\n" ) !== false || strpos( $value, "\r" ) !== false ) ) {
7147 $result[ $key ] = sanitize_textarea_field( $value );
7148 } else {
7149 $result[ $key ] = sanitize_text_field( $value );
7150 }
7151 }
7152 }
7153 }
7154
7155 // Handle unchecked checkboxes: HTML forms don't submit unchecked boxes
7156 // If a boolean field exists in defaults but NOT in submitted_data, set it to false
7157 //
7158 // EXCEPTION: the top-level 'enabled' flag of every section is the
7159 // module's master switch and is controlled by the Dashboard module
7160 // toggle, NOT by a checkbox inside the section's form. Treating it
7161 // like a regular checkbox here would silently switch the module off
7162 // every time the user saves the tab — see the REST API enabled=false
7163 // regression. We only skip it at the top level (when section_name is
7164 // empty); nested 'enabled' fields like security_headers.csp.enabled
7165 // are real checkboxes and must keep the auto-unset behaviour.
7166 $preserve_top_level = array( 'enabled' );
7167
7168 foreach ( $defaults as $key => $default_value ) {
7169 if ( '' === $section_name && in_array( $key, $preserve_top_level, true ) ) {
7170 continue;
7171 }
7172 if ( is_bool( $default_value ) && ! array_key_exists( $key, $submitted_data ) ) {
7173 $result[ $key ] = false;
7174 } elseif ( is_array( $default_value ) && ! isset( $submitted_data[ $key ] ) ) {
7175 // Check if this is a flat value list (like excluded_users, enforced_roles, ip_whitelist)
7176 // vs a nested settings group (like rate_limiting, two_factor)
7177 // Flat lists: default is empty array OR all values are scalar
7178 $is_value_list = empty( $default_value );
7179 if ( ! $is_value_list ) {
7180 $is_value_list = true;
7181 foreach ( $default_value as $dv ) {
7182 if ( ! is_scalar( $dv ) ) {
7183 $is_value_list = false;
7184 break;
7185 }
7186 }
7187 }
7188
7189 if ( $is_value_list ) {
7190 // All items removed - reset to empty array
7191 $result[ $key ] = array();
7192 } else {
7193 // Nested settings group - handle boolean children
7194 foreach ( $default_value as $nested_key => $nested_default ) {
7195 if ( is_bool( $nested_default ) && isset( $result[ $key ] ) && is_array( $result[ $key ] ) ) {
7196 $nested_submitted = isset( $submitted_data[ $key ] ) && is_array( $submitted_data[ $key ] )
7197 ? $submitted_data[ $key ]
7198 : array();
7199 if ( ! array_key_exists( $nested_key, $nested_submitted ) ) {
7200 $result[ $key ][ $nested_key ] = false;
7201 }
7202 }
7203 }
7204 }
7205 }
7206 }
7207
7208 return $result;
7209 }
7210
7211 /**
7212 * AJAX: Export settings
7213 */
7214 public function ajax_export_settings() {
7215 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7216
7217 if ( ! current_user_can( 'manage_options' ) ) {
7218 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7219 }
7220
7221 $options = $this->settings->get_all_options();
7222 $filename = 'vigilante-settings-' . gmdate( 'Y-m-d-His' ) . '.json';
7223
7224 wp_send_json_success( array(
7225 'content' => wp_json_encode( $options, JSON_PRETTY_PRINT ),
7226 'filename' => $filename,
7227 ) );
7228 }
7229
7230 /**
7231 * AJAX: Import settings
7232 */
7233 public function ajax_import_settings() {
7234 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7235
7236 if ( ! current_user_can( 'manage_options' ) ) {
7237 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7238 }
7239
7240 // Accept both 'settings' (from JS) and 'content' (legacy).
7241 // Do NOT run sanitize_text_field() on the raw payload: it calls
7242 // wp_strip_all_tags() internally, which removes any "<...>" substring
7243 // and turns a valid export JSON into garbage if any stored value
7244 // contains < or > (htaccess snippets, email templates, etc.). The
7245 // real sanitization happens after json_decode(), via map_deep() on
7246 // the parsed array.
7247 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash
7248 $content = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : '';
7249 if ( empty( $content ) ) {
7250 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash
7251 $content = isset( $_POST['content'] ) ? wp_unslash( $_POST['content'] ) : '';
7252 }
7253
7254 if ( empty( $content ) || ! is_string( $content ) ) {
7255 wp_send_json_error( __( 'No content provided.', 'vigilante' ) );
7256 }
7257
7258 $imported = json_decode( $content, true );
7259
7260 if ( json_last_error() !== JSON_ERROR_NONE || ! is_array( $imported ) ) {
7261 wp_send_json_error( __( 'Invalid JSON format.', 'vigilante' ) );
7262 }
7263
7264 // Sanitize imported data recursively
7265 $imported = map_deep( $imported, 'sanitize_text_field' );
7266
7267 // Validate structure: only sections and keys of the schema survive, and
7268 // every value takes the type of its default. Until 2.11.0 this was an
7269 // array_replace_recursive() of the file over the defaults, so any key in
7270 // the file, known or not, landed in vigilante_options (S7). Sections
7271 // the file does not carry keep their defaults; a section it does carry
7272 // replaces the default one whole, because validate_options() has
7273 // already filled in whatever the file left out.
7274 $defaults = $this->settings->get_default_options();
7275 $validated = $this->settings->validate_options( $imported );
7276 $merged = $defaults;
7277
7278 foreach ( $validated as $section => $data ) {
7279 if ( is_array( $data ) ) {
7280 $merged[ $section ] = $data;
7281 }
7282 }
7283
7284 // Save
7285 $merged = Vigilante_Settings::keep_locked_file_settings( $merged, get_option( Vigilante_Settings::OPTION_NAME, array() ) );
7286 update_option( Vigilante_Settings::OPTION_NAME, $merged );
7287 $this->settings->clear_cache();
7288
7289 // Re-evaluate the active preset marker. The imported config may match
7290 // a known preset exactly, partially, or not at all — without this step
7291 // the dashboard would keep showing whatever preset was active before
7292 // the import even if the new config no longer matches it.
7293 $matched_preset = $this->detect_matching_preset( $merged );
7294 if ( null === $matched_preset ) {
7295 delete_option( 'vigilante_active_preset' );
7296 } else {
7297 update_option( 'vigilante_active_preset', $matched_preset );
7298 }
7299
7300 // Apply file changes after import
7301 $this->apply_all_file_changes( $merged );
7302
7303 // Refresh the Security Analyzer score so the dashboard widget reflects
7304 // the imported config rather than the pre-import scan. Reuse the
7305 // post-Under-Attack scan hook (same job: full scan, async).
7306 if ( ! wp_next_scheduled( 'vigilante_under_attack_post_scan' ) ) {
7307 wp_schedule_single_event( time() + 5, 'vigilante_under_attack_post_scan' );
7308 }
7309
7310 wp_send_json_success( __( 'Settings imported successfully.', 'vigilante' ) . $this->locked_file_settings_message() );
7311 }
7312
7313 /**
7314 * Detect whether a vigilante_options array matches a known preset.
7315 *
7316 * A preset matches when every field the preset explicitly declares is
7317 * present in the config with the same (normalised) value. Fields outside
7318 * the preset are ignored — they may have been modified by the user before
7319 * applying the preset and do not invalidate the match. This mirrors how
7320 * apply_preset() now layers presets on top of the user's existing config.
7321 *
7322 * @param array $options The current/imported vigilante_options.
7323 * @return string|null Preset id ('standard', 'maximum') or null if custom.
7324 */
7325 private function detect_matching_preset( $options ) {
7326 if ( ! is_array( $options ) ) {
7327 return null;
7328 }
7329
7330 $presets = $this->settings->get_presets();
7331
7332 foreach ( $presets as $preset_id => $preset_data ) {
7333 unset( $preset_data['name'], $preset_data['description'] );
7334 if ( $this->preset_subset_matches( $preset_data, $options ) ) {
7335 return $preset_id;
7336 }
7337 }
7338
7339 return null;
7340 }
7341
7342 /**
7343 * Check whether every leaf value inside $preset_subset exists with the
7344 * same (normalised) value at the same path inside $config.
7345 *
7346 * @param mixed $preset_subset Branch of the preset definition.
7347 * @param mixed $config Same branch in the live/imported config.
7348 * @return bool
7349 */
7350 private function preset_subset_matches( $preset_subset, $config ) {
7351 if ( is_array( $preset_subset ) ) {
7352 if ( ! is_array( $config ) ) {
7353 return false;
7354 }
7355 foreach ( $preset_subset as $key => $value ) {
7356 if ( ! array_key_exists( $key, $config ) ) {
7357 return false;
7358 }
7359 if ( ! $this->preset_subset_matches( $value, $config[ $key ] ) ) {
7360 return false;
7361 }
7362 }
7363 return true;
7364 }
7365
7366 return $this->normalise_scalar_for_compare( $preset_subset ) === $this->normalise_scalar_for_compare( $config );
7367 }
7368
7369 /**
7370 * Normalise a scalar value so that the variants WordPress and the form
7371 * layer routinely produce ('1' / 1 / true → "1"; '' / '0' / 0 / false /
7372 * null → "") compare equal. Other values become strings unchanged.
7373 *
7374 * @param mixed $value
7375 * @return string
7376 */
7377 private function normalise_scalar_for_compare( $value ) {
7378 if ( is_bool( $value ) ) {
7379 return $value ? '1' : '';
7380 }
7381 if ( null === $value ) {
7382 return '';
7383 }
7384 if ( is_int( $value ) || is_float( $value ) ) {
7385 return (string) $value;
7386 }
7387 if ( is_string( $value ) ) {
7388 if ( 'true' === $value ) {
7389 return '1';
7390 }
7391 if ( 'false' === $value ) {
7392 return '';
7393 }
7394 return $value;
7395 }
7396 // Arrays and objects shouldn't reach here (handled by recursion above),
7397 // but if they do, fall back to a stable comparable representation.
7398 return wp_json_encode( $value );
7399 }
7400
7401 /**
7402 * AJAX: Apply preset
7403 */
7404 public function ajax_apply_preset() {
7405 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7406
7407 if ( ! current_user_can( 'manage_options' ) ) {
7408 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7409 }
7410
7411 $preset = isset( $_POST['preset'] ) ? sanitize_key( $_POST['preset'] ) : '';
7412
7413 // Handle reset to defaults
7414 if ( 'reset' === $preset ) {
7415 $stored_options = get_option( Vigilante_Settings::OPTION_NAME, array() );
7416 $defaults = Vigilante_Settings::get_defaults_preserving_user_data( $stored_options );
7417 $defaults = Vigilante_Settings::keep_locked_file_settings( $defaults, $stored_options );
7418 update_option( Vigilante_Settings::OPTION_NAME, $defaults );
7419 $this->settings->clear_cache();
7420
7421 // Clear active preset
7422 update_option( 'vigilante_active_preset', '' );
7423
7424 // Apply file changes after reset
7425 $this->apply_all_file_changes( $defaults );
7426
7427 wp_send_json_success( __( 'Settings reset to defaults.', 'vigilante' ) . $this->locked_file_settings_message() );
7428 return;
7429 }
7430
7431 $presets = $this->settings->get_presets();
7432
7433 if ( ! isset( $presets[ $preset ] ) ) {
7434 wp_send_json_error( __( 'Invalid preset.', 'vigilante' ) );
7435 }
7436
7437 $preset_options = $presets[ $preset ];
7438 unset( $preset_options['name'], $preset_options['description'] );
7439
7440 // Layer the preset on top of the user's CURRENT configuration, not on
7441 // top of defaults. This way applying a preset only changes the fields
7442 // the preset explicitly mentions; everything else stays as the user
7443 // had it. For example, applying Maximum will not flip HSTS off if the
7444 // user had it on — Maximum doesn't touch HSTS, so it's left alone.
7445 // Use "Reset to Defaults" if a clean slate is needed.
7446 $current = get_option( Vigilante_Settings::OPTION_NAME, array() );
7447 if ( ! is_array( $current ) ) {
7448 $current = array();
7449 }
7450 // Make sure all known keys exist before merging — the merge does not
7451 // invent keys that are missing on both sides.
7452 $current = Vigilante_Settings::merge_preset( $this->settings->get_default_options(), $current );
7453
7454 $merged = Vigilante_Settings::merge_preset( $current, $preset_options );
7455 $merged = Vigilante_Settings::keep_locked_file_settings( $merged, get_option( Vigilante_Settings::OPTION_NAME, array() ) );
7456
7457 update_option( Vigilante_Settings::OPTION_NAME, $merged );
7458 $this->settings->clear_cache();
7459
7460 // Save active preset
7461 update_option( 'vigilante_active_preset', $preset );
7462
7463 // Apply file changes after preset
7464 $this->apply_all_file_changes( $merged );
7465
7466 wp_send_json_success( __( 'Preset applied successfully.', 'vigilante' ) . $this->locked_file_settings_message() );
7467 }
7468
7469 /**
7470 * AJAX: Reset a specific section to defaults
7471 */
7472 public function ajax_reset_section() {
7473 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7474
7475 if ( ! current_user_can( 'manage_options' ) ) {
7476 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7477 }
7478
7479 $section = isset( $_POST['section'] ) ? sanitize_key( $_POST['section'] ) : '';
7480
7481 if ( empty( $section ) ) {
7482 wp_send_json_error( __( 'No section specified.', 'vigilante' ) );
7483 }
7484
7485 // Get current options and defaults. get_defaults_preserving_user_data()
7486 // applies the tweaks a fresh installation gets, so the button and a new
7487 // install agree, and keeps whatever the owner typed in.
7488 $current_options = $this->settings->get_all_options();
7489 $defaults = Vigilante_Settings::get_defaults_preserving_user_data( $current_options );
7490
7491 // Check if section exists in defaults
7492 if ( ! isset( $defaults[ $section ] ) ) {
7493 wp_send_json_error( __( 'Invalid section.', 'vigilante' ) );
7494 }
7495
7496 $new_values = $defaults[ $section ];
7497
7498 /*
7499 * On a subsite, the settings written to wp-config.php and .htaccess are
7500 * the main site's business. Resetting the local copy of those would only
7501 * make this screen disagree with the file, so they are carried over
7502 * untouched, and a section that is nothing but shared settings is not
7503 * reset at all. On the main site, a user without network rights keeps
7504 * the ones the shared files are built from as well (2.11.6).
7505 */
7506 $locked = Vigilante_Settings::get_locked_file_settings();
7507
7508 if ( isset( $locked[ $section ] ) && true === $locked[ $section ] ) {
7509 wp_send_json_error( Vigilante_Settings::get_shared_files_notice() );
7510 }
7511
7512 $current_options[ $section ] = $new_values;
7513 $current_options = Vigilante_Settings::keep_locked_file_settings( $current_options, get_option( Vigilante_Settings::OPTION_NAME, array() ) );
7514
7515 // Save
7516 update_option( Vigilante_Settings::OPTION_NAME, $current_options );
7517 $this->settings->clear_cache();
7518
7519 // Apply file changes if needed
7520 $this->apply_section_changes( $section, $current_options );
7521
7522 wp_send_json_success( array(
7523 'message' => __( 'Section reset to defaults.', 'vigilante' ),
7524 'section' => $section,
7525 'reload' => true,
7526 ) );
7527 }
7528
7529 /**
7530 * AJAX: Clear lockouts
7531 */
7532 public function ajax_clear_lockouts() {
7533 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7534
7535 if ( ! current_user_can( 'manage_options' ) ) {
7536 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7537 }
7538
7539 $ip = isset( $_POST['ip'] ) ? sanitize_text_field( wp_unslash( $_POST['ip'] ) ) : '';
7540
7541 if ( ! empty( $ip ) ) {
7542 $this->database->clear_lockout( $ip );
7543 } else {
7544 $this->database->clear_all_lockouts();
7545 }
7546
7547 wp_send_json_success( __( 'Lockouts cleared.', 'vigilante' ) );
7548 }
7549
7550 /**
7551 * AJAX: Clear logs
7552 */
7553 public function ajax_clear_logs() {
7554 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7555
7556 if ( ! current_user_can( 'manage_options' ) ) {
7557 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7558 }
7559
7560 if ( $this->activity_log ) {
7561 $result = $this->activity_log->clear_all_logs();
7562 if ( $result ) {
7563 wp_send_json_success( __( 'Logs cleared.', 'vigilante' ) );
7564 } else {
7565 wp_send_json_error( __( 'Failed to clear logs.', 'vigilante' ) );
7566 }
7567 } else {
7568 wp_send_json_error( __( 'Activity log not available.', 'vigilante' ) );
7569 }
7570 }
7571
7572 /**
7573 * AJAX: Run file integrity scan.
7574 *
7575 * Triggers the file integrity scan, which now also runs the closed plugins
7576 * check at the end when the `check_closed_plugins` toggle is on. Activity
7577 * log is passed through so Security Audit entries (both file-level and
7578 * plugin-status) are recorded from this entry point.
7579 */
7580 public function ajax_run_scan() {
7581 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7582
7583 if ( ! current_user_can( 'manage_options' ) ) {
7584 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7585 }
7586
7587 // Clear previous results before running new scan
7588 delete_option( 'vigilante_last_integrity_results' );
7589 delete_option( 'vigilante_last_integrity_scan' );
7590
7591 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database, $this->activity_log );
7592 $results = $file_integrity->run_scan();
7593
7594 // Save new results
7595 update_option( 'vigilante_last_integrity_scan', time() );
7596 update_option( 'vigilante_last_integrity_results', $results );
7597
7598 wp_send_json_success( array(
7599 'message' => __( 'Scan completed.', 'vigilante' ),
7600 'results' => $results,
7601 'ignored_count' => count( get_option( 'vigilante_ignored_files', array() ) ),
7602 ) );
7603 }
7604
7605 /**
7606 * AJAX: Clear scan results.
7607 *
7608 * Wipes visually everything inside "Last Scan Results": file scan findings
7609 * (Suspicious / Modified / Extra / Critical Config), file hashes and the
7610 * Closed + Removed Plugins block.
7611 *
7612 * Implementation detail to keep persistence intact:
7613 * - We delete the file scan options + hashes outright.
7614 * - For plugin status we ONLY delete the last_check timestamp — the state
7615 * map and the ignore list are preserved in DB. The render gates the
7616 * plugin_status subsections on last_check > 0, so they hide after
7617 * Clear (visual reset) and reappear on the next Run Scan Now with the
7618 * state intact. This avoids degrading a 'removed' slug (404 without
7619 * metadata) back to 'not_in_repo' on the next scan, which would
7620 * silently lose the alert.
7621 *
7622 * The Ignored Files list and the Ignored Closed + Removed Plugins list
7623 * are preserved on purpose; each has its own explicit "Clear All …"
7624 * button.
7625 */
7626 public function ajax_clear_scan() {
7627 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7628
7629 if ( ! current_user_can( 'manage_options' ) ) {
7630 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7631 }
7632
7633 delete_option( 'vigilante_last_integrity_results' );
7634 delete_option( 'vigilante_last_integrity_scan' );
7635
7636 if ( $this->database ) {
7637 $this->database->clear_file_hashes();
7638 }
7639
7640 // Visual reset of plugin_status block without touching the state map
7641 // or the ignored list. See PHPDoc above for the rationale.
7642 delete_option( 'vigilante_plugin_status_last_check' );
7643
7644 wp_send_json_success( __( 'Scan results cleared.', 'vigilante' ) );
7645 }
7646
7647 /**
7648 * AJAX: Ignore a file from scan results
7649 */
7650 public function ajax_ignore_file() {
7651 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7652
7653 if ( ! current_user_can( 'manage_options' ) ) {
7654 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7655 }
7656
7657 $file = isset( $_POST['file'] ) ? sanitize_text_field( wp_unslash( $_POST['file'] ) ) : '';
7658
7659 if ( empty( $file ) ) {
7660 wp_send_json_error( __( 'No file specified.', 'vigilante' ) );
7661 }
7662
7663 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7664 $file_integrity->ignore_file( $file );
7665
7666 // Also remove the file from stored scan results so UI updates
7667 $results = get_option( 'vigilante_last_integrity_results' );
7668 if ( $results ) {
7669 foreach ( array( 'modified', 'suspicious', 'extra' ) as $category ) {
7670 if ( ! empty( $results[ $category ] ) ) {
7671 $results[ $category ] = array_values(
7672 array_filter(
7673 $results[ $category ],
7674 function ( $item ) use ( $file ) {
7675 return ( is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item ) !== $file;
7676 }
7677 )
7678 );
7679 }
7680 }
7681 update_option( 'vigilante_last_integrity_results', $results );
7682 }
7683
7684 wp_send_json_success( __( 'File added to ignored list.', 'vigilante' ) );
7685 }
7686
7687 /**
7688 * AJAX: Stop ignoring a file
7689 */
7690 public function ajax_unignore_file() {
7691 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7692
7693 if ( ! current_user_can( 'manage_options' ) ) {
7694 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7695 }
7696
7697 $file = isset( $_POST['file'] ) ? sanitize_text_field( wp_unslash( $_POST['file'] ) ) : '';
7698
7699 if ( empty( $file ) ) {
7700 wp_send_json_error( __( 'No file specified.', 'vigilante' ) );
7701 }
7702
7703 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7704 $file_integrity->unignore_file( $file );
7705
7706 wp_send_json_success( __( 'File removed from ignored list.', 'vigilante' ) );
7707 }
7708
7709 /**
7710 * AJAX: Bulk ignore multiple files at once
7711 *
7712 * Processes a single batch into ignored list and prunes them from the
7713 * stored scan results so the UI updates without a re-scan.
7714 */
7715 public function ajax_bulk_ignore_files() {
7716 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7717
7718 if ( ! current_user_can( 'manage_options' ) ) {
7719 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7720 }
7721
7722 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized below per-item.
7723 $raw_files = isset( $_POST['files'] ) ? wp_unslash( $_POST['files'] ) : array();
7724 if ( ! is_array( $raw_files ) ) {
7725 wp_send_json_error( __( 'Invalid request.', 'vigilante' ) );
7726 }
7727
7728 $files = array();
7729 foreach ( $raw_files as $f ) {
7730 $clean = sanitize_text_field( $f );
7731 if ( '' !== $clean ) {
7732 $files[] = $clean;
7733 }
7734 }
7735
7736 if ( empty( $files ) ) {
7737 wp_send_json_error( __( 'No files selected.', 'vigilante' ) );
7738 }
7739
7740 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7741 $count = 0;
7742 foreach ( $files as $file ) {
7743 $file_integrity->ignore_file( $file );
7744 $count++;
7745 }
7746
7747 // Also prune the stored scan results so the UI matches the new ignore list.
7748 $results = get_option( 'vigilante_last_integrity_results' );
7749 if ( $results ) {
7750 $files_set = array_flip( $files );
7751 foreach ( array( 'modified', 'suspicious', 'extra' ) as $category ) {
7752 if ( ! empty( $results[ $category ] ) ) {
7753 $results[ $category ] = array_values(
7754 array_filter(
7755 $results[ $category ],
7756 function ( $item ) use ( $files_set ) {
7757 $path = is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item;
7758 return ! isset( $files_set[ $path ] );
7759 }
7760 )
7761 );
7762 }
7763 }
7764 update_option( 'vigilante_last_integrity_results', $results );
7765 }
7766
7767 wp_send_json_success(
7768 array(
7769 'count' => $count,
7770 'message' => sprintf(
7771 /* translators: %d: number of files added to the ignored list */
7772 _n( '%d file added to ignored list.', '%d files added to ignored list.', $count, 'vigilante' ),
7773 $count
7774 ),
7775 )
7776 );
7777 }
7778
7779 /**
7780 * AJAX: Bulk un-ignore multiple files at once
7781 */
7782 public function ajax_bulk_unignore_files() {
7783 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7784
7785 if ( ! current_user_can( 'manage_options' ) ) {
7786 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7787 }
7788
7789 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized below per-item.
7790 $raw_files = isset( $_POST['files'] ) ? wp_unslash( $_POST['files'] ) : array();
7791 if ( ! is_array( $raw_files ) ) {
7792 wp_send_json_error( __( 'Invalid request.', 'vigilante' ) );
7793 }
7794
7795 $files = array();
7796 foreach ( $raw_files as $f ) {
7797 $clean = sanitize_text_field( $f );
7798 if ( '' !== $clean ) {
7799 $files[] = $clean;
7800 }
7801 }
7802
7803 if ( empty( $files ) ) {
7804 wp_send_json_error( __( 'No files selected.', 'vigilante' ) );
7805 }
7806
7807 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7808 $count = 0;
7809 foreach ( $files as $file ) {
7810 $file_integrity->unignore_file( $file );
7811 $count++;
7812 }
7813
7814 wp_send_json_success(
7815 array(
7816 'count' => $count,
7817 'message' => sprintf(
7818 /* translators: %d: number of files removed from the ignored list */
7819 _n( '%d file removed from ignored list.', '%d files removed from ignored list.', $count, 'vigilante' ),
7820 $count
7821 ),
7822 )
7823 );
7824 }
7825
7826 /**
7827 * AJAX: Clear all ignored files
7828 */
7829 public function ajax_clear_ignored() {
7830 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7831
7832 if ( ! current_user_can( 'manage_options' ) ) {
7833 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7834 }
7835
7836 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7837 $file_integrity->clear_ignored_files();
7838
7839 wp_send_json_success( __( 'Ignored files list cleared.', 'vigilante' ) );
7840 }
7841
7842 /**
7843 * AJAX: Ignore a closed/removed plugin slug so it stops appearing in the
7844 * main list and email digests. The plugin keeps running on the site;
7845 * silencing is purely cosmetic and reversible.
7846 */
7847 public function ajax_ignore_closed_plugin() {
7848 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7849
7850 if ( ! current_user_can( 'manage_options' ) ) {
7851 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7852 }
7853
7854 $slug = isset( $_POST['slug'] ) ? sanitize_key( wp_unslash( $_POST['slug'] ) ) : '';
7855 if ( '' === $slug ) {
7856 wp_send_json_error( __( 'No slug specified.', 'vigilante' ) );
7857 }
7858
7859 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
7860 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
7861 }
7862 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
7863 $checker->ignore_slug( $slug );
7864
7865 wp_send_json_success( __( 'Plugin added to the ignored list.', 'vigilante' ) );
7866 }
7867
7868 /**
7869 * AJAX: Stop ignoring a previously-ignored closed/removed plugin slug.
7870 */
7871 public function ajax_unignore_closed_plugin() {
7872 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7873
7874 if ( ! current_user_can( 'manage_options' ) ) {
7875 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7876 }
7877
7878 $slug = isset( $_POST['slug'] ) ? sanitize_key( wp_unslash( $_POST['slug'] ) ) : '';
7879 if ( '' === $slug ) {
7880 wp_send_json_error( __( 'No slug specified.', 'vigilante' ) );
7881 }
7882
7883 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
7884 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
7885 }
7886 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
7887 $checker->unignore_slug( $slug );
7888
7889 wp_send_json_success( __( 'Plugin removed from the ignored list.', 'vigilante' ) );
7890 }
7891
7892 /**
7893 * AJAX: Clear the entire ignored-closed-plugins list.
7894 */
7895 public function ajax_clear_ignored_closed_plugins() {
7896 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7897
7898 if ( ! current_user_can( 'manage_options' ) ) {
7899 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7900 }
7901
7902 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
7903 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
7904 }
7905 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
7906 $checker->clear_ignored();
7907
7908 wp_send_json_success( __( 'Ignored closed plugins list cleared.', 'vigilante' ) );
7909 }
7910
7911 /**
7912 * AJAX: Test security headers
7913 */
7914 public function ajax_test_headers() {
7915 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7916
7917 if ( ! current_user_can( 'manage_options' ) ) {
7918 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7919 }
7920
7921 // Get security grade from settings (not from actual HTTP request)
7922 $security_headers = new Vigilante_Security_Headers( $this->settings );
7923 $results = $security_headers->get_security_grade();
7924
7925 wp_send_json_success( $results );
7926 }
7927
7928 /**
7929 * Sanitize section data (kept for compatibility)
7930 *
7931 * @param string $section Section name.
7932 * @param array $data Section data.
7933 * @return array
7934 */
7935 private function sanitize_section_data( $section, $data ) {
7936 $sanitized = array();
7937
7938 foreach ( $data as $key => $value ) {
7939 $key = sanitize_key( $key );
7940
7941 if ( is_array( $value ) ) {
7942 $sanitized[ $key ] = $this->sanitize_section_data( $key, $value );
7943 } elseif ( is_numeric( $value ) ) {
7944 $sanitized[ $key ] = intval( $value );
7945 } else {
7946 $sanitized[ $key ] = sanitize_text_field( $value );
7947 }
7948 }
7949
7950 return $sanitized;
7951 }
7952
7953 /**
7954 * Apply changes after saving settings
7955 *
7956 * @param string $section Section that was updated.
7957 * @param array $all_options All options.
7958 */
7959 private function apply_section_changes( $section, $all_options ) {
7960 // Create fresh settings instance to ensure we have the latest data
7961 $fresh_settings = new Vigilante_Settings();
7962
7963 // The shared Vigilant .htaccess block carries BOTH the firewall's
7964 // file-protection rules and the server-signature / fingerprinting rules
7965 // that are configured under Security Headers. So it must be regenerated
7966 // whenever either section (or the module toggles) changes, not only on
7967 // the firewall save — otherwise toggling "Hide server signature" or
7968 // "Remove fingerprinting headers" never reaches the .htaccess.
7969 if ( in_array( $section, array( 'firewall', 'security_headers', 'modules' ), true ) ) {
7970 $htaccess = new Vigilante_Htaccess_Protection( $fresh_settings );
7971 $sh = $fresh_settings->get_section( 'security_headers' );
7972 $needs_htaccess_block = ! empty( $all_options['modules']['firewall'] )
7973 || ! empty( $sh['hide_server_signature'] )
7974 || ! empty( $sh['remove_fingerprinting_headers'] );
7975
7976 if ( $needs_htaccess_block ) {
7977 $htaccess->apply_rules();
7978 } else {
7979 $htaccess->remove_rules();
7980 }
7981 }
7982
7983 // Regenerate the HTTP security headers (sent by PHP) for the headers section.
7984 if ( 'security_headers' === $section || 'modules' === $section ) {
7985 $security_headers = new Vigilante_Security_Headers( $fresh_settings );
7986 $headers_enabled = ! empty( $all_options['modules']['security_headers'] );
7987
7988 if ( $headers_enabled ) {
7989 $security_headers->apply_rules();
7990 } else {
7991 $security_headers->remove_rules();
7992 }
7993 }
7994
7995 // Regenerate wp-config for wp_hardening section
7996 if ( 'wp_hardening' === $section || 'modules' === $section ) {
7997 $wpconfig = new Vigilante_Wpconfig_Security( $fresh_settings );
7998 $hardening_enabled = ! empty( $all_options['modules']['wp_hardening'] );
7999
8000 if ( $hardening_enabled ) {
8001 $wpconfig->apply_security_constants();
8002 } else {
8003 $wpconfig->remove_constants();
8004 }
8005
8006 // Apply WordPress options for comments/pingbacks
8007 $hardening_options = $all_options['wp_hardening'] ?? array();
8008
8009 if ( $hardening_enabled ) {
8010 // Pingbacks
8011 if ( ! empty( $hardening_options['disable_pingbacks'] ) ) {
8012 update_option( 'default_pingback_flag', 0 );
8013 } else {
8014 // Restore default: pingbacks enabled
8015 update_option( 'default_pingback_flag', 1 );
8016 }
8017
8018 // Trackbacks and ping status
8019 // Only close if either pingbacks OR trackbacks are disabled
8020 if ( ! empty( $hardening_options['disable_pingbacks'] ) || ! empty( $hardening_options['disable_trackbacks'] ) ) {
8021 update_option( 'default_ping_status', 'closed' );
8022 } else {
8023 // Restore default: pings open
8024 update_option( 'default_ping_status', 'open' );
8025 }
8026
8027 // Comment moderation
8028 if ( ! empty( $hardening_options['require_comment_moderation'] ) ) {
8029 update_option( 'comment_moderation', 1 );
8030 } else {
8031 // Restore default: no moderation required
8032 update_option( 'comment_moderation', 0 );
8033 }
8034 }
8035 }
8036
8037 // Trim activity log entries immediately when limits change
8038 if ( 'activity_log' === $section && $this->activity_log ) {
8039 $this->activity_log->cleanup_old_logs();
8040 }
8041
8042 // Flush rewrite rules if login URL changed
8043 if ( 'login_security' === $section ) {
8044 $login_options = $all_options['login_security'] ?? array();
8045 if ( ! empty( $login_options['custom_login_url'] ) ) {
8046 delete_option( 'vigilante_login_rules_version' );
8047 }
8048 }
8049
8050 // Log the settings change with readable section name
8051 if ( $this->activity_log ) {
8052 $section_names = array(
8053 'firewall' => __( 'Firewall', 'vigilante' ),
8054 'login_security' => __( 'Login Security', 'vigilante' ),
8055 'security_headers' => __( 'Security Headers', 'vigilante' ),
8056 'rest_api_security'=> __( 'REST API Security', 'vigilante' ),
8057 'user_security' => __( 'User Security', 'vigilante' ),
8058 'wp_hardening' => __( 'WP Hardening', 'vigilante' ),
8059 'activity_log' => __( 'Security Audit', 'vigilante' ),
8060 'file_integrity' => __( 'File Integrity', 'vigilante' ),
8061 'email' => __( 'Notification Settings', 'vigilante' ),
8062 'backup' => __( 'Backup', 'vigilante' ),
8063 'advanced' => __( 'Advanced', 'vigilante' ),
8064 'modules' => __( 'Modules', 'vigilante' ),
8065 );
8066 $display_name = isset( $section_names[ $section ] ) ? $section_names[ $section ] : $section;
8067
8068 $this->activity_log->log(
8069 'settings',
8070 'settings_updated',
8071 sprintf(
8072 /* translators: %s: Section name */
8073 __( 'Settings updated: %s', 'vigilante' ),
8074 $display_name
8075 ),
8076 array( 'section' => $section ),
8077 'info'
8078 );
8079 }
8080 }
8081
8082 /**
8083 * Apply all file changes (htaccess, wp-config) based on current options
8084 *
8085 * Used after preset, import, or reset operations
8086 *
8087 * @param array $all_options All plugin options.
8088 */
8089 private function apply_all_file_changes( $all_options ) {
8090 // Refresh settings cache first
8091 $this->settings->clear_cache();
8092
8093 // Create fresh settings instance
8094 $fresh_settings = new Vigilante_Settings();
8095
8096 // Apply firewall htaccess changes
8097 $htaccess = new Vigilante_Htaccess_Protection( $fresh_settings );
8098 $firewall_enabled = ! empty( $all_options['modules']['firewall'] );
8099
8100 if ( $firewall_enabled ) {
8101 $htaccess->apply_rules();
8102 } else {
8103 $htaccess->remove_rules();
8104 }
8105
8106 // Apply security headers htaccess changes
8107 $security_headers = new Vigilante_Security_Headers( $fresh_settings );
8108 $headers_enabled = ! empty( $all_options['modules']['security_headers'] );
8109
8110 if ( $headers_enabled ) {
8111 $security_headers->apply_rules();
8112 } else {
8113 $security_headers->remove_rules();
8114 }
8115
8116 // Apply wp-config changes
8117 $wpconfig = new Vigilante_Wpconfig_Security( $fresh_settings );
8118 $hardening_enabled = ! empty( $all_options['modules']['wp_hardening'] );
8119
8120 if ( $hardening_enabled ) {
8121 $wpconfig->apply_security_constants();
8122 } else {
8123 $wpconfig->remove_constants();
8124 }
8125
8126 // Apply WordPress options for comments/pingbacks
8127 $hardening_options = $all_options['wp_hardening'] ?? array();
8128
8129 if ( $hardening_enabled ) {
8130 // Pingbacks
8131 if ( ! empty( $hardening_options['disable_pingbacks'] ) ) {
8132 update_option( 'default_pingback_flag', 0 );
8133 } else {
8134 // Restore default: pingbacks enabled
8135 update_option( 'default_pingback_flag', 1 );
8136 }
8137
8138 // Trackbacks and ping status
8139 // Only close if either pingbacks OR trackbacks are disabled
8140 if ( ! empty( $hardening_options['disable_pingbacks'] ) || ! empty( $hardening_options['disable_trackbacks'] ) ) {
8141 update_option( 'default_ping_status', 'closed' );
8142 } else {
8143 // Restore default: pings open
8144 update_option( 'default_ping_status', 'open' );
8145 }
8146
8147 // Comment moderation
8148 if ( ! empty( $hardening_options['require_comment_moderation'] ) ) {
8149 update_option( 'comment_moderation', 1 );
8150 } else {
8151 // Restore default: no moderation required
8152 update_option( 'comment_moderation', 0 );
8153 }
8154 }
8155
8156 // Log the change
8157 if ( $this->activity_log ) {
8158 $this->activity_log->log(
8159 'settings',
8160 'bulk_settings_applied',
8161 __( 'Bulk settings applied (preset/import/reset)', 'vigilante' ),
8162 array(),
8163 'info'
8164 );
8165 }
8166 }
8167 }