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

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

8,307 lines 532.0 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 'diffNetwork' => __( 'This file belongs to the whole network, so its line changes are only shown to network administrators, on the main site.', 'vigilante' ),
1550 'diffRescan' => __( 'Run a new scan to see the line changes of this file.', 'vigilante' ),
1551 'diffRedaction' => __( 'The line changes of this file are not shown because a value in it could not be hidden safely. The change itself is still detected.', 'vigilante' ),
1552 'diffEmpty' => __( 'No line-level changes detected (may be whitespace or reordering).', 'vigilante' ),
1553 'diffLines' => __( 'lines', 'vigilante' ),
1554 // Under Attack mode strings
1555 'underAttackConfirmActivate' => __( 'Activate Under Attack mode? All visitors will see a verification page for the next 4 hours.', 'vigilante' ),
1556 'underAttackConfirmDeactivate' => __( 'Deactivate Under Attack mode?', 'vigilante' ),
1557 'underAttackActivating' => __( 'Activating...', 'vigilante' ),
1558 'underAttackDeactivating' => __( 'Deactivating...', 'vigilante' ),
1559 // Database backup strings
1560 'dbBackupDownloading' => __( 'Generating backup...', 'vigilante' ),
1561 'dbBackupNoTables' => __( 'Please select at least one table.', 'vigilante' ),
1562 'dbBackupSuccess' => __( 'Database backup downloaded successfully.', 'vigilante' ),
1563 // Firewall unblock
1564 'confirmUnblockIp' => __( 'Unblock this IP from firewall rate limiting?', 'vigilante' ),
1565 // Database prefix strings
1566 'dbPrefixConfirm' => __( 'This operation will change your database prefix. It is irreversible. Make sure you have a current database backup before proceeding.', 'vigilante' ),
1567 'dbPrefixChanging' => __( 'Changing prefix...', 'vigilante' ),
1568 'dbPrefixSuccess' => __( 'Database prefix changed successfully. The page will reload now.', 'vigilante' ),
1569 'dbPrefixCheckbox' => __( 'You must confirm that you have a database backup.', 'vigilante' ),
1570 /* translators: 1: Hours, 2: Minutes */
1571 'underAttackRemaining' => __( '%1$dh %2$dm remaining', 'vigilante' ),
1572 'underAttackLabel' => __( 'Under Attack', 'vigilante' ),
1573 'standardLabel' => __( 'Standard', 'vigilante' ),
1574 'maximumLabel' => __( 'Maximum Security', 'vigilante' ),
1575 'deactivate' => __( 'Deactivate', 'vigilante' ),
1576 'underAttackActivate' => __( 'Activate for 4 hours', 'vigilante' ),
1577 // Settings strings
1578 'saveSettings' => __( 'Save Settings', 'vigilante' ),
1579 'settingsResetDefaults' => __( 'Settings reset to defaults.', 'vigilante' ),
1580 'confirmOverwrite' => __( 'This will overwrite your current settings.', 'vigilante' ),
1581 'importFailed' => __( 'Could not import settings. Check the file and try again.', 'vigilante' ),
1582 /* translators: 1: tests passed, 2: total tests in this category */
1583 'testsCounter' => __( '%1$d/%2$d tests', 'vigilante' ),
1584 'confirmResetAll' => __( 'This will reset ALL settings to defaults.', 'vigilante' ),
1585 'couldNotDetermineSection' => __( 'Could not determine section.', 'vigilante' ),
1586 'confirmResetSection' => __( 'Reset this section to default values? This cannot be undone.', 'vigilante' ),
1587 'sectionResetDefaults' => __( 'Section reset to defaults.', 'vigilante' ),
1588 /* translators: %s: preset name */
1589 'confirmApplyPreset' => __( 'Apply the "%s" preset?', 'vigilante' ),
1590 // Scan strings
1591 'scanFailed' => __( 'Scan failed', 'vigilante' ),
1592 /* translators: %s: error message */
1593 'scanError' => __( 'Scan error: %s', 'vigilante' ),
1594 'runScanNow' => __( 'Run Scan Now', 'vigilante' ),
1595 'confirmClearScan' => __( 'Are you sure you want to clear all scan results?', 'vigilante' ),
1596 'clearing' => __( 'Clearing...', 'vigilante' ),
1597 'scanResultsCleared' => __( 'Scan results cleared. Page will reload...', 'vigilante' ),
1598 'failedClearResults' => __( 'Failed to clear results', 'vigilante' ),
1599 /* translators: %s: error message */
1600 'ajaxError' => __( 'AJAX Error: %s', 'vigilante' ),
1601 // Activity log popup strings
1602 'logRequest' => __( 'Request', 'vigilante' ),
1603 'logDate' => __( 'Date', 'vigilante' ),
1604 'logMethod' => __( 'Method', 'vigilante' ),
1605 'logType' => __( 'Type', 'vigilante' ),
1606 'logAction' => __( 'Action', 'vigilante' ),
1607 'logSeverity' => __( 'Severity', 'vigilante' ),
1608 'logMessage' => __( 'Message', 'vigilante' ),
1609 'logRequestUri' => __( 'Address', 'vigilante' ),
1610 'logClient' => __( 'Client', 'vigilante' ),
1611 'logUser' => __( 'User', 'vigilante' ),
1612 'logIpAddress' => __( 'IP Address', 'vigilante' ),
1613 'logUserAgent' => __( 'User Agent', 'vigilante' ),
1614 'logIpLabel' => __( 'IP:', 'vigilante' ),
1615 'logUaLabel' => __( 'UA:', 'vigilante' ),
1616 'logWhitelist' => __( 'Whitelist', 'vigilante' ),
1617 'logBlacklist' => __( 'Blacklist', 'vigilante' ),
1618 'logInWhitelist' => __( 'In whitelist', 'vigilante' ),
1619 'logInBlacklist' => __( 'In blacklist', 'vigilante' ),
1620 'logAdded' => __( 'Added!', 'vigilante' ),
1621 'logErrorAddingToList' => __( 'Error adding to list', 'vigilante' ),
1622 'logRequestFailed' => __( 'Request failed', 'vigilante' ),
1623 // Activity log table strings
1624 'noLogEntries' => __( 'No log entries found.', 'vigilante' ),
1625 'view' => __( 'View', 'vigilante' ),
1626 'confirmClearLogs' => __( 'This will delete all audit logs.', 'vigilante' ),
1627 // Export logs strings
1628 'exporting' => __( 'Exporting...', 'vigilante' ),
1629 /* translators: %d: number of entries */
1630 'logsExported' => __( 'Logs exported (%d entries)', 'vigilante' ),
1631 'noLogsToExport' => __( 'No logs to export', 'vigilante' ),
1632 'exportFailed' => __( 'Export failed', 'vigilante' ),
1633 'exportLogs' => __( 'Export Logs', 'vigilante' ),
1634 // Backup strings
1635 'backupCreated' => __( 'Backup created successfully.', 'vigilante' ),
1636 'createBackupNow' => __( 'Download Backup', 'vigilante' ),
1637 'downloadBackup' => __( 'Download Backup (.zip)', 'vigilante' ),
1638 /* translators: %d: number of tables */
1639 'tablesCount' => __( '%d tables', 'vigilante' ),
1640 /* translators: 1: table count, 2: human-readable size */
1641 'dbTablesTotal' => __( '%1$d tables total (%2$s)', 'vigilante' ),
1642 /* translators: 1: selected count, 2: human-readable size */
1643 'dbTablesSelected' => __( '%1$d tables selected (%2$s)', 'vigilante' ),
1644 // Settings search strings
1645 'searchNoResults' => __( 'No matching settings found.', 'vigilante' ),
1646 /* translators: %d: number of results that did not fit in the list. */
1647 'searchMoreResults' => __( '%d more results. Refine the search to see them.', 'vigilante' ),
1648 'searchInTab' => __( 'in', 'vigilante' ),
1649 // Modules string
1650 /* translators: 1: enabled count, 2: total count */
1651 'modulesEnabled' => __( '%1$d / %2$d modules enabled', 'vigilante' ),
1652 // Activity log label maps for JS rendering
1653 'eventTypeLabels' => array(
1654 'login' => __( 'Login', 'vigilante' ),
1655 'user' => __( 'User', 'vigilante' ),
1656 'content' => __( 'Content', 'vigilante' ),
1657 'plugin' => __( 'Plugin', 'vigilante' ),
1658 'theme' => __( 'Theme', 'vigilante' ),
1659 'settings' => __( 'Settings', 'vigilante' ),
1660 'comment' => __( 'Comment', 'vigilante' ),
1661 'media' => __( 'Media', 'vigilante' ),
1662 'firewall' => __( 'Firewall', 'vigilante' ),
1663 'file' => __( 'File', 'vigilante' ),
1664 'security' => __( 'Security', 'vigilante' ),
1665 'system' => __( 'System', 'vigilante' ),
1666 ),
1667 'severityLabels' => array(
1668 'info' => __( 'Info', 'vigilante' ),
1669 'warning' => __( 'Warning', 'vigilante' ),
1670 'critical' => __( 'Critical', 'vigilante' ),
1671 ),
1672 // Password reset strings
1673 'noUsersFoundSearch' => __( 'No users found', 'vigilante' ),
1674 /* translators: %d: number of users */
1675 'confirmForceReset' => __( 'Force password reset for %d user(s)? A password reset email will be sent to each user.', 'vigilante' ),
1676 'warningResettingSelf' => __( 'WARNING: You are including yourself. Your session will end and you will need to set a new password.', 'vigilante' ),
1677 'processing' => __( 'Processing...', 'vigilante' ),
1678 'anErrorOccurred' => __( 'An error occurred', 'vigilante' ),
1679 'forceResetSelected' => __( 'Force Reset for Selected Users', 'vigilante' ),
1680 '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' ),
1681 'warningResettingSelfAll' => __( 'WARNING: You are including yourself. Your session will end immediately.', 'vigilante' ),
1682 'forceResetAll' => __( 'Force Reset for ALL Users', 'vigilante' ),
1683 // Role-based password reset strings
1684 /* translators: %d: number of users */
1685 'confirmForceResetByRole' => __( 'Force password reset for %d user(s) with the selected roles? A password reset email will be sent to each user.', 'vigilante' ),
1686 'noRolesSelected' => __( 'Please select at least one role.', 'vigilante' ),
1687 'forceResetByRole' => __( 'Force Reset for Selected Roles', 'vigilante' ),
1688 // User approval strings
1689 'confirmApprove' => __( 'Approve this user?', 'vigilante' ),
1690 'approve' => __( 'Approve', 'vigilante' ),
1691 'rejectReason' => __( 'Enter rejection reason (optional):', 'vigilante' ),
1692 'reject' => __( 'Reject', 'vigilante' ),
1693 'noPending' => __( 'No pending registrations.', 'vigilante' ),
1694 // Session management strings
1695 'confirmRevoke' => __( 'Revoke this session?', 'vigilante' ),
1696 'confirmRevokeAll' => __( 'Revoke all other sessions?', 'vigilante' ),
1697 'revokeOthers' => __( 'Revoke All Other Sessions', 'vigilante' ),
1698 'confirmRevokeAllUser' => __( 'Revoke ALL sessions for this user? They will be logged out everywhere.', 'vigilante' ),
1699 'sessionsFor' => __( 'Sessions for:', 'vigilante' ),
1700 'noSessions' => __( 'No active sessions', 'vigilante' ),
1701 'revoke' => __( 'Revoke', 'vigilante' ),
1702 'noUsers' => __( 'No users found', 'vigilante' ),
1703 // Time ago strings
1704 'timeYear' => __( 'year', 'vigilante' ),
1705 'timeYears' => __( 'years', 'vigilante' ),
1706 'timeMonth' => __( 'month', 'vigilante' ),
1707 'timeMonths' => __( 'months', 'vigilante' ),
1708 'timeDay' => __( 'day', 'vigilante' ),
1709 'timeDays' => __( 'days', 'vigilante' ),
1710 'timeHour' => __( 'hour', 'vigilante' ),
1711 'timeHours' => __( 'hours', 'vigilante' ),
1712 'timeMinute' => __( 'minute', 'vigilante' ),
1713 'timeMinutes' => __( 'minutes', 'vigilante' ),
1714 /* translators: %1$d: count, %2$s: time unit */
1715 'timeAgo' => __( '%1$d %2$s ago', 'vigilante' ),
1716 'justNow' => __( 'Just now', 'vigilante' ),
1717 // Pagination strings
1718 /* translators: 1: first item number, 2: last item number, 3: total items */
1719 'paginationOf' => __( '%1$d–%2$d of %3$d', 'vigilante' ),
1720 'paginationEmpty' => __( '0 items', 'vigilante' ),
1721 // Security Analyzer strings
1722 'analyzerScanNow' => __( 'Scan now', 'vigilante' ),
1723 'analyzerScanning' => __( 'Scanning…', 'vigilante' ),
1724 'analyzerFastPhase' => __( 'Running fast checks…', 'vigilante' ),
1725 'analyzerSlowPhase' => __( 'Running remote checks…', 'vigilante' ),
1726 'analyzerScanComplete' => __( 'Security scan complete.', 'vigilante' ),
1727 'analyzerScanFailed' => __( 'Security scan failed.', 'vigilante' ),
1728 'analyzerShowDetails' => __( 'Show detailed breakdown', 'vigilante' ),
1729 'analyzerHideDetails' => __( 'Hide detailed breakdown', 'vigilante' ),
1730 'analyzerGoToSetting' => __( 'Go to setting', 'vigilante' ),
1731 'analyzerNoData' => __( 'No data yet — run a scan to populate this category.', 'vigilante' ),
1732 'analyzerJustNow' => __( 'just now', 'vigilante' ),
1733 'analyzerAgo' => __( 'ago', 'vigilante' ),
1734 'analyzerSettingsSaved' => __( 'Analyzer settings saved.', 'vigilante' ),
1735 'analyzerLastScanJustNow' => __( 'Last scan just now', 'vigilante' ),
1736 'analyzerQualityExcellent' => __( 'Excellent', 'vigilante' ),
1737 'analyzerQualityGood' => __( 'Good', 'vigilante' ),
1738 'analyzerQualityFair' => __( 'Fair', 'vigilante' ),
1739 'analyzerQualityPoor' => __( 'Poor', 'vigilante' ),
1740 'analyzerQualityCritical' => __( 'Critical', 'vigilante' ),
1741 'analyzerPts' => __( 'pts', 'vigilante' ),
1742 'analyzerLearnMore' => __( 'Learn more', 'vigilante' ),
1743 'analyzerInfoAllClear' => __( 'All clear', 'vigilante' ),
1744 /* translators: %d: number of findings in an info-only category */
1745 'analyzerInfoFindings' => __( '%d findings', 'vigilante' ),
1746 ),
1747 ) );
1748
1749 // 2FA Admin assets
1750 wp_enqueue_style(
1751 'vigilante-2fa-admin',
1752 VIGILANTE_ASSETS_URL . 'css/two-factor-admin.css',
1753 array( 'vigilante-admin' ),
1754 VIGILANTE_VERSION
1755 );
1756
1757 wp_enqueue_script(
1758 'vigilante-2fa-admin',
1759 VIGILANTE_ASSETS_URL . 'js/two-factor-admin.js',
1760 array( 'jquery', 'vigilante-admin' ),
1761 VIGILANTE_VERSION,
1762 true
1763 );
1764 }
1765
1766 /**
1767 * Show admin notices
1768 */
1769 public function show_admin_notices() {
1770 // Activation notice
1771 if ( get_transient( 'vigilante_activated' ) ) {
1772 ?>
1773 <div class="notice notice-success is-dismissible vigilante-activation-notice">
1774 <p>
1775 <span class="dashicons dashicons-shield vigilante-notice-icon"></span>
1776 <strong><?php esc_html_e( 'Vigilant activated successfully!', 'vigilante' ); ?></strong>
1777 <?php esc_html_e( 'Security protection is now active.', 'vigilante' ); ?>
1778 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante' ) ); ?>">
1779 <?php esc_html_e( 'Configure settings', 'vigilante' ); ?>
1780 </a>
1781 </p>
1782 </div>
1783 <?php
1784 delete_transient( 'vigilante_activated' );
1785 }
1786
1787 // Under Attack mode notice (non-dismissible, shown on all admin pages)
1788 $ua_status = get_option( Vigilante_Under_Attack::OPTION_NAME, array() );
1789 if ( ! empty( $ua_status['active'] ) ) {
1790 $ua_remaining = ( $ua_status['activated_at'] + $ua_status['duration'] ) - time();
1791 if ( $ua_remaining > 0 ) {
1792 $ua_hours = floor( $ua_remaining / 3600 );
1793 $ua_mins = floor( ( $ua_remaining % 3600 ) / 60 );
1794 $dashboard_url = admin_url( 'admin.php?page=vigilante' );
1795 ?>
1796 <div class="notice notice-warning vigilante-ua-notice">
1797 <p>
1798 <span class="dashicons dashicons-shield"></span>
1799 <strong><?php esc_html_e( 'Under Attack mode is active', 'vigilante' ); ?></strong>
1800 &mdash;
1801 <?php
1802 printf(
1803 /* translators: 1: Hours, 2: Minutes */
1804 esc_html__( '%1$dh %2$dm remaining.', 'vigilante' ),
1805 absint( $ua_hours ),
1806 absint( $ua_mins )
1807 );
1808 ?>
1809 <a href="<?php echo esc_url( $dashboard_url ); ?>">
1810 <?php esc_html_e( 'Go to Vigilant dashboard', 'vigilante' ); ?>
1811 </a>
1812 </p>
1813 <p>
1814 <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>
1815 </p>
1816 <?php
1817 // The cache-bypass rules could not be written (a host where
1818 // WordPress cannot write files by itself, a held lock, a
1819 // failed read-back): show them, so they can be added by hand.
1820 $ua_instance = new Vigilante_Under_Attack( $this->settings, $this->activity_log );
1821 if ( $ua_instance->cache_rules_missing() ) :
1822 ?>
1823 <p>
1824 <strong><?php esc_html_e( 'The cache-bypass rules could not be written to your .htaccess.', 'vigilante' ); ?></strong>
1825 <?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' ); ?>
1826 </p>
1827 <textarea readonly rows="9" class="large-text code" onclick="this.select();"><?php echo esc_textarea( Vigilante_Under_Attack::get_cache_bypass_block() ); ?></textarea>
1828 <?php endif; ?>
1829 </div>
1830 <?php
1831 }
1832 }
1833
1834 // Proxy/CDN detection: if IP detection is set to "direct" but requests
1835 // arrive with a forwarded-for header carrying a different valid IP, the
1836 // site is very likely behind a proxy/CDN that has not been declared, so
1837 // the firewall is seeing the proxy IP for every visitor. Guide the admin.
1838 //
1839 // Two deliberate silencers (2.9.2):
1840 // - A loopback forwarded IP (::1 / 127.x) means the person browsing IS
1841 // the machine itself: that only happens in local development stacks
1842 // (Local's nginx router, Docker...), never behind a production
1843 // proxy/CDN, so the notice would be pure noise there.
1844 // - The notice is dismissible and the dismissal persists site-wide via
1845 // the vigilante_dismissed_notices option (the admin evaluated it and
1846 // decided; nagging forever helps nobody).
1847 $dismissed_notices = get_option( 'vigilante_dismissed_notices', array() );
1848 if (
1849 current_user_can( 'manage_options' )
1850 && '' === Vigilante_IP_Utils::trusted_proxy_header()
1851 && ! isset( $dismissed_notices['proxy_detection'] )
1852 ) {
1853 $remote = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '';
1854 $detected = '';
1855 foreach ( Vigilante_IP_Utils::trusted_header_map() as $proxy_label => $server_key ) {
1856 if ( empty( $_SERVER[ $server_key ] ) ) {
1857 continue;
1858 }
1859 $candidate = sanitize_text_field( wp_unslash( $_SERVER[ $server_key ] ) );
1860 if ( false !== strpos( $candidate, ',' ) ) {
1861 $parts = explode( ',', $candidate );
1862 $candidate = trim( $parts[0] );
1863 }
1864 if ( ! filter_var( $candidate, FILTER_VALIDATE_IP ) || $candidate === $remote ) {
1865 continue;
1866 }
1867 // Loopback forwarded IP = local development, not a real proxy.
1868 if ( '::1' === $candidate || 0 === strpos( $candidate, '127.' ) ) {
1869 continue;
1870 }
1871 $detected = $proxy_label;
1872 break;
1873 }
1874
1875 if ( '' !== $detected ) {
1876 $firewall_url = admin_url( 'admin.php?page=vigilante&tab=firewall' );
1877 $detail_message = sprintf(
1878 /* translators: %s: detected forwarded header name wrapped in a code tag. */
1879 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' ),
1880 '<code>' . esc_html( strtoupper( $detected ) ) . '</code>'
1881 );
1882 ?>
1883 <div class="notice notice-warning is-dismissible vigilante-proxy-notice">
1884 <p>
1885 <span class="dashicons dashicons-shield"></span>
1886 <strong><?php esc_html_e( 'Vigilant: this site looks like it is behind a proxy or CDN', 'vigilante' ); ?></strong>
1887 </p>
1888 <p><?php echo wp_kses_post( $detail_message ); ?></p>
1889 <p>
1890 <a href="<?php echo esc_url( $firewall_url ); ?>" class="button button-secondary">
1891 <?php esc_html_e( 'Set your proxy in Firewall settings', 'vigilante' ); ?>
1892 </a>
1893 </p>
1894 </div>
1895 <script>
1896 jQuery( function ( $ ) {
1897 $( document ).on( 'click', '.vigilante-proxy-notice .notice-dismiss', function () {
1898 $.post( ajaxurl, {
1899 action: 'vigilante_dismiss_notice',
1900 notice_id: 'proxy_detection',
1901 nonce: <?php echo wp_json_encode( wp_create_nonce( 'vigilante_dismiss_notice' ) ); ?>
1902 } );
1903 } );
1904 } );
1905 </script>
1906 <?php
1907 }
1908 }
1909 }
1910
1911 /**
1912 * Render settings page
1913 */
1914 public function render_settings_page() {
1915 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
1916 $this->current_tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'dashboard';
1917
1918 if ( ! array_key_exists( $this->current_tab, $this->tabs ) ) {
1919 $this->current_tab = 'dashboard';
1920 }
1921 ?>
1922 <div class="wrap vigilante-admin-wrap">
1923 <div class="vigilante-header-row">
1924 <h1 class="vigilante-page-title">
1925 <img src="<?php echo esc_url( VIGILANTE_ASSETS_URL . 'images/icon.png' ); ?>" alt="Vigilante" class="vigilante-title-icon">
1926 <?php esc_html_e( 'Vigilant', 'vigilante' ); ?>
1927 <span class="vigilante-version">v<?php echo esc_html( VIGILANTE_VERSION ); ?></span>
1928 </h1>
1929 <div class="vigilante-search-wrapper">
1930 <div class="vigilante-search-input-wrap">
1931 <span class="vigilante-search-icon dashicons dashicons-search" aria-hidden="true"></span>
1932 <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">
1933 <span class="vigilante-search-shortcut" aria-hidden="true">/</span>
1934 </div>
1935 <div id="vigilante-settings-search-results" class="vigilante-search-results" hidden role="listbox"></div>
1936 </div>
1937 </div>
1938
1939 <?php $this->render_tabs(); ?>
1940
1941 <div class="vigilante-content">
1942 <div class="vigilante-main">
1943 <?php $this->render_tab_content(); ?>
1944 </div>
1945 <div class="vigilante-sidebar">
1946 <?php $this->render_sidebar(); ?>
1947 </div>
1948 </div>
1949 </div>
1950 <?php
1951 }
1952
1953 /**
1954 * Render tabs navigation
1955 */
1956 private function render_tabs() {
1957 $options = $this->settings->get_all_options();
1958
1959 // Map tabs to modules
1960 $tab_to_module = array(
1961 'firewall' => 'firewall',
1962 'headers' => 'security_headers',
1963 'login' => 'login_security',
1964 'rest-api' => 'rest_api_security',
1965 'users' => 'user_security',
1966 'wp-hardening' => 'wp_hardening',
1967 'file-integrity' => 'file_integrity',
1968 'activity-log' => 'activity_log',
1969 );
1970 ?>
1971 <nav class="nav-tab-wrapper vigilante-nav-tabs">
1972 <?php foreach ( $this->tabs as $tab_id => $tab_name ) :
1973 $is_disabled = false;
1974 $module = isset( $tab_to_module[ $tab_id ] ) ? $tab_to_module[ $tab_id ] : null;
1975 if ( $module && empty( $options['modules'][ $module ] ) ) {
1976 $is_disabled = true;
1977 }
1978 ?>
1979 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=' . $tab_id ) ); ?>"
1980 class="nav-tab <?php echo $this->current_tab === $tab_id ? 'nav-tab-active' : ''; ?> <?php echo $is_disabled ? 'vigilante-tab-disabled' : ''; ?>"
1981 <?php if ( $is_disabled ) : ?>title="<?php esc_attr_e( 'Module Disabled', 'vigilante' ); ?>"<?php endif; ?>>
1982 <?php echo esc_html( $tab_name ); ?>
1983 <?php if ( $is_disabled ) : ?><span class="vigilante-tab-off">OFF</span><?php endif; ?>
1984 </a>
1985 <?php endforeach; ?>
1986 </nav>
1987 <?php
1988 }
1989
1990 /**
1991 * Render current tab content
1992 */
1993 private function render_tab_content() {
1994 $method = 'render_tab_' . str_replace( '-', '_', $this->current_tab );
1995
1996 if ( method_exists( $this, $method ) ) {
1997 $this->$method();
1998 } else {
1999 $this->render_tab_coming_soon();
2000 }
2001 }
2002
2003 /**
2004 * Render coming soon placeholder
2005 */
2006 private function render_tab_coming_soon() {
2007 ?>
2008 <div class="vigilante-settings-section">
2009 <h2><?php esc_html_e( 'Coming Soon', 'vigilante' ); ?></h2>
2010 <p><?php esc_html_e( 'This section is under development.', 'vigilante' ); ?></p>
2011 </div>
2012 <?php
2013 }
2014
2015 /**
2016 * Values to display for a section that this site does not control
2017 *
2018 * On a subsite the stored options are its own copy, which nothing acts on:
2019 * wp-config.php and .htaccess are written from the main site. Painting the
2020 * local copy describes a configuration that is not running, so a subsite
2021 * admin sees a box ticked here and the constant absent from the file, or the
2022 * other way round. Read the main site's values instead, which are the ones in
2023 * force, and fall back to the local ones if they cannot be read.
2024 *
2025 * @since 2.9.8
2026 *
2027 * @param string $section Settings section.
2028 * @return array
2029 */
2030 private function get_section_for_display( $section ) {
2031 $local = $this->settings->get_section( $section );
2032
2033 if ( ! $this->shared_files_locked() ) {
2034 return $local;
2035 }
2036
2037 // shared_files_locked() is only true on multisite, where get_blog_option() exists.
2038 $main = get_blog_option( get_main_site_id(), Vigilante_Settings::OPTION_NAME, array() );
2039
2040 if ( ! is_array( $main ) || empty( $main[ $section ] ) || ! is_array( $main[ $section ] ) ) {
2041 return $local;
2042 }
2043
2044 return wp_parse_args( $main[ $section ], $local );
2045 }
2046
2047 /**
2048 * Whether the sections that write wp-config.php and .htaccess are read-only here
2049 *
2050 * True on a network when this is not the main site, or the user is not a
2051 * network administrator. See Vigilante_Settings::can_write_shared_files().
2052 *
2053 * @since 2.9.8
2054 *
2055 * @return bool
2056 */
2057 private function shared_files_locked() {
2058 return ! Vigilante_Settings::can_write_shared_files();
2059 }
2060
2061 /**
2062 * Whether this is the main site and the user cannot change what it builds the shared files from
2063 *
2064 * See Vigilante_Settings::get_main_site_file_settings(). On a subsite those
2065 * settings only act on that site, so they are never locked there.
2066 *
2067 * @since 2.11.6
2068 *
2069 * @return bool
2070 */
2071 private function main_site_files_locked() {
2072 return $this->shared_files_locked() && Vigilante_Settings::owns_shared_files();
2073 }
2074
2075 /**
2076 * Sentence added to a bulk change when some settings were left as they were
2077 *
2078 * Importing a file, applying a preset and restoring the defaults touch every
2079 * section at once, so the user is told that the shared file settings did
2080 * not move.
2081 *
2082 * @since 2.11.6
2083 *
2084 * @return string Empty when the user can change every setting.
2085 */
2086 private function locked_file_settings_message() {
2087 if ( ! Vigilante_Settings::get_locked_file_settings() ) {
2088 return '';
2089 }
2090
2091 return ' ' . __( 'The settings that end up in wp-config.php or .htaccess were left as they were.', 'vigilante' ) . ' ' . Vigilante_Settings::get_shared_files_notice();
2092 }
2093
2094 /**
2095 * Print the shared-files notice for a section that cannot be edited here
2096 *
2097 * @since 2.9.8
2098 */
2099 private function render_shared_files_notice() {
2100 if ( ! $this->shared_files_locked() ) {
2101 return;
2102 }
2103 ?>
2104 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
2105 <p style="margin:0;"><?php echo esc_html( Vigilante_Settings::get_shared_files_notice() ); ?></p>
2106 </div>
2107 <?php
2108 }
2109
2110 /**
2111 * Acting on another user's account needs permission over that user
2112 *
2113 * Since 2.10.3 the handlers behind these tools ask for edit_user over the
2114 * target, which is the rule WordPress itself applies. On a network the core
2115 * grants edit_user only to network administrators, so for anybody else these
2116 * controls do nothing. Better to say so than to paint a button that silently
2117 * skips every user.
2118 *
2119 * @since 2.10.4
2120 * @return bool
2121 */
2122 private function forwarded_chain_readings() {
2123 // Shown, not decided on: the firewall resolves the address elsewhere.
2124 $chain = Vigilante_IP_Utils::trusted_forwarded_for();
2125
2126 if ( '' === $chain ) {
2127 return array();
2128 }
2129
2130 $public = array();
2131
2132 foreach ( explode( ',', $chain ) as $entry ) {
2133 $address = Vigilante_IP_Utils::unmap_ipv4( trim( $entry ) );
2134
2135 if ( filter_var( $address, FILTER_VALIDATE_IP ) && ! Vigilante_IP_Utils::is_own_network( $address ) ) {
2136 $public[] = $address;
2137 }
2138 }
2139
2140 if ( count( $public ) < 2 ) {
2141 return array();
2142 }
2143
2144 return array(
2145 'now' => Vigilante_IP_Utils::client_from_chain( $chain ),
2146 'before' => $public[0],
2147 );
2148 }
2149
2150 /**
2151 * Whether the user tools of this screen are out of reach for this user
2152 *
2153 * @return bool
2154 */
2155 private function user_actions_locked() {
2156 // On a single site edit_user maps to edit_users, which a custom role with
2157 // manage_options may lack: since 2.11.8 approving and rejecting a pending
2158 // registration ask for it, so the buttons have to say so there too.
2159 return is_multisite() ? ! current_user_can( 'manage_network_users' ) : ! current_user_can( 'edit_users' );
2160 }
2161
2162 /**
2163 * Print the notice for user tools that cannot be used from this site
2164 *
2165 * @since 2.10.4
2166 */
2167 private function render_user_actions_notice() {
2168 if ( ! $this->user_actions_locked() ) {
2169 return;
2170 }
2171 ?>
2172 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
2173 <?php if ( is_multisite() ) : ?>
2174 <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>
2175 <?php else : ?>
2176 <p style="margin:0;"><?php esc_html_e( 'These tools act on other user accounts, and your role cannot edit users, so they are not available to you.', 'vigilante' ); ?></p>
2177 <?php endif; ?>
2178 </div>
2179 <?php
2180 }
2181
2182 /**
2183 * Approving a change to the shared config files needs the network
2184 *
2185 * Since 2.11.3 the handler behind the Approve button asks for
2186 * manage_network_options, because the two files it approves, wp-config.php
2187 * and the root .htaccess, belong to the installation, and so does the
2188 * record of them. The button, though, went on being painted for everybody,
2189 * so the administrator of a subsite saw the warning, saw the button,
2190 * pressed it and got "Permission denied" with no explanation. That is
2191 * exactly what user_actions_locked() above exists to avoid, one release
2192 * later and one screen over. Flagged by @calzbert.
2193 *
2194 * @since 2.11.4
2195 * @return bool
2196 */
2197 private function critical_approval_locked() {
2198 return is_multisite() && ! current_user_can( 'manage_network_options' );
2199 }
2200
2201 /**
2202 * The line that replaces the Approve button where it cannot be used
2203 *
2204 * @since 2.11.4
2205 * @return string
2206 */
2207 private function critical_approval_notice() {
2208 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' );
2209 }
2210
2211 /**
2212 * Check if module is disabled and render warning
2213 *
2214 * @param string $module_key Module key.
2215 * @return bool True if disabled.
2216 */
2217 private function render_module_disabled_notice( $module_key ) {
2218 if ( $this->settings->is_module_enabled( $module_key ) ) {
2219 return false;
2220 }
2221
2222 $module_labels = $this->settings->get_module_labels();
2223 $module_name = isset( $module_labels[ $module_key ] ) ? $module_labels[ $module_key ] : $module_key;
2224 ?>
2225 <div class="notice notice-warning vigilante-module-disabled-notice">
2226 <p>
2227 <strong><?php esc_html_e( 'Module Disabled', 'vigilante' ); ?></strong> -
2228 <?php
2229 printf(
2230 /* translators: %s: Module name */
2231 esc_html__( 'The %s module is currently disabled. Enable it from the Dashboard to use these settings.', 'vigilante' ),
2232 esc_html( $module_name )
2233 );
2234 ?>
2235 </p>
2236 <p>
2237 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=dashboard' ) ); ?>" class="button">
2238 <?php esc_html_e( 'Go to Dashboard', 'vigilante' ); ?>
2239 </a>
2240 </p>
2241 </div>
2242 <?php
2243 return true;
2244 }
2245
2246 /**
2247 * Render the Security Analyzer (Security Check) widget + expandable full report.
2248 *
2249 * Lives in the Dashboard tab between the Configuration Score status card and
2250 * the modules grid. Uses the last persisted scan to hydrate server-side so the
2251 * first paint shows real data; "Scan now" runs the 2-phase AJAX to refresh.
2252 *
2253 * @param array $last_scan Result of Vigilante_Security_Analyzer::get_last_scan().
2254 * @param array $history Score history (oldest first).
2255 * @param array $categories_def Category metadata (slug => label/max).
2256 * @param array $analyzer_settings Settings subsection for weekly cron + email.
2257 */
2258 private function render_analyzer_widget( $last_scan, $history, $categories_def, $analyzer_settings ) {
2259 $has_data = ! empty( $last_scan['ran_at'] );
2260 $score = isset( $last_scan['score'] ) ? (int) $last_scan['score'] : 0;
2261 $grade = isset( $last_scan['grade'] ) ? (string) $last_scan['grade'] : '';
2262 $counts = isset( $last_scan['counts'] ) && is_array( $last_scan['counts'] ) ? $last_scan['counts'] : array();
2263 $ran_at_human = $has_data
2264 ? sprintf(
2265 /* translators: %s: relative time like "2 hours" */
2266 __( 'Last scan %s ago', 'vigilante' ),
2267 human_time_diff( (int) $last_scan['ran_at'], time() )
2268 )
2269 : __( 'Never scanned', 'vigilante' );
2270 $categories = isset( $last_scan['categories'] ) && is_array( $last_scan['categories'] ) ? $last_scan['categories'] : array();
2271 $weekly_enabled = ! isset( $analyzer_settings['weekly_scan_enabled'] ) || ! empty( $analyzer_settings['weekly_scan_enabled'] );
2272 $email_enabled = ! empty( $analyzer_settings['email_on_regression'] );
2273
2274 $quality = self::analyzer_quality_tag( $score );
2275 ?>
2276 <div class="vigilante-analyzer" id="vigilante-analyzer"
2277 data-has-data="<?php echo $has_data ? '1' : '0'; ?>">
2278 <div class="vigilante-analyzer-header">
2279 <div class="vigilante-analyzer-title">
2280 <h2>
2281 <span class="dashicons dashicons-shield-alt" aria-hidden="true"></span>
2282 <?php esc_html_e( 'Security Check', 'vigilante' ); ?>
2283 </h2>
2284 <p class="description">
2285 <?php esc_html_e( 'On-demand audit of what an attacker would see right now, plus 13 internal checks impossible from the outside.', 'vigilante' ); ?>
2286 </p>
2287 <p class="vigilante-analyzer-last-scan" data-role="ran-at">
2288 <span class="dashicons dashicons-clock" aria-hidden="true"></span>
2289 <?php echo esc_html( $ran_at_human ); ?>
2290 </p>
2291 </div>
2292 <div class="vigilante-analyzer-actions">
2293 <button type="button" class="button button-primary" id="vigilante-analyzer-scan">
2294 <span class="dashicons dashicons-update" aria-hidden="true"></span>
2295 <?php esc_html_e( 'Scan now', 'vigilante' ); ?>
2296 </button>
2297 </div>
2298 </div>
2299
2300 <div class="vigilante-analyzer-summary">
2301 <div class="vigilante-analyzer-score-card">
2302 <?php if ( $has_data && $grade ) : ?>
2303 <div class="vigilante-score-circle vigilante-grade-<?php echo esc_attr( strtolower( $grade ) ); ?>">
2304 <span class="vigilante-grade"><?php echo esc_html( $grade ); ?></span>
2305 <span class="vigilante-score-text"><?php echo esc_html( $score ); ?>%</span>
2306 </div>
2307 <?php else : ?>
2308 <div class="vigilante-score-circle vigilante-grade-empty">
2309 <span class="vigilante-grade">—</span>
2310 <span class="vigilante-score-text"><?php esc_html_e( 'N/A', 'vigilante' ); ?></span>
2311 </div>
2312 <?php endif; ?>
2313 <div class="vigilante-analyzer-score-meta">
2314 <p class="vigilante-analyzer-score-label">
2315 <?php esc_html_e( 'Security Score', 'vigilante' ); ?>
2316 </p>
2317 <span class="vigilante-analyzer-quality-tag vigilante-analyzer-quality-<?php echo esc_attr( $quality['slug'] ); ?>"
2318 data-role="quality-tag">
2319 <?php echo esc_html( $quality['label'] ); ?>
2320 </span>
2321 </div>
2322 </div>
2323
2324 <div class="vigilante-analyzer-counts">
2325 <span class="vigilante-analyzer-count vigilante-analyzer-count--pass">
2326 <span class="dashicons dashicons-yes-alt" aria-hidden="true"></span>
2327 <strong data-role="pass"><?php echo esc_html( isset( $counts['pass'] ) ? $counts['pass'] : 0 ); ?></strong>
2328 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Passed', 'vigilante' ); ?></span>
2329 </span>
2330 <span class="vigilante-analyzer-count vigilante-analyzer-count--warn">
2331 <span class="dashicons dashicons-warning" aria-hidden="true"></span>
2332 <strong data-role="warn"><?php echo esc_html( isset( $counts['warn'] ) ? $counts['warn'] : 0 ); ?></strong>
2333 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Warnings', 'vigilante' ); ?></span>
2334 </span>
2335 <span class="vigilante-analyzer-count vigilante-analyzer-count--fail">
2336 <span class="dashicons dashicons-dismiss" aria-hidden="true"></span>
2337 <strong data-role="fail"><?php echo esc_html( isset( $counts['fail'] ) ? $counts['fail'] : 0 ); ?></strong>
2338 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Failing', 'vigilante' ); ?></span>
2339 </span>
2340 </div>
2341
2342 <?php
2343 // Sparkline of recent scores. Require at least 3 data points so the trend
2344 // is meaningful (2 points is just a line between dots, no real trend).
2345 $hist_points = array();
2346 foreach ( $history as $h ) {
2347 $hist_points[] = (int) $h['score'];
2348 }
2349 $hist_count = count( $hist_points );
2350 if ( $hist_count >= 3 ) :
2351 $current_score = (int) end( $hist_points );
2352 $previous_score = (int) $hist_points[ $hist_count - 2 ];
2353 $delta = $current_score - $previous_score;
2354 $delta_class = $delta > 0 ? 'vigilante-analyzer-delta--up' : ( $delta < 0 ? 'vigilante-analyzer-delta--down' : 'vigilante-analyzer-delta--flat' );
2355 $delta_icon = $delta > 0 ? 'arrow-up-alt' : ( $delta < 0 ? 'arrow-down-alt' : 'minus' );
2356 if ( 0 === $delta ) {
2357 $delta_text = __( 'No change', 'vigilante' );
2358 } else {
2359 $delta_text = sprintf(
2360 /* translators: %s: signed delta, e.g. "+3" or "-5" */
2361 _n( '%s pt vs. previous scan', '%s pts vs. previous scan', abs( $delta ), 'vigilante' ),
2362 ( $delta > 0 ? '+' : '' ) . (int) $delta
2363 );
2364 }
2365 ?>
2366 <div class="vigilante-analyzer-sparkline-wrap">
2367 <div class="vigilante-analyzer-sparkline-head">
2368 <span class="vigilante-analyzer-sparkline-label">
2369 <?php
2370 echo esc_html( sprintf(
2371 /* translators: %d: number of scans */
2372 _n( 'Score trend (last %d scan)', 'Score trend (last %d scans)', $hist_count, 'vigilante' ),
2373 $hist_count
2374 ) );
2375 ?>
2376 </span>
2377 <span class="vigilante-analyzer-delta <?php echo esc_attr( $delta_class ); ?>">
2378 <span class="dashicons dashicons-<?php echo esc_attr( $delta_icon ); ?>" aria-hidden="true"></span>
2379 <?php echo esc_html( $delta_text ); ?>
2380 </span>
2381 </div>
2382 <div class="vigilante-analyzer-sparkline" data-role="sparkline"
2383 data-points="<?php echo esc_attr( wp_json_encode( $hist_points ) ); ?>">
2384 <?php echo self::sparkline_svg( $hist_points ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Safe SVG from helper ?>
2385 </div>
2386 </div>
2387 <?php elseif ( $has_data ) : ?>
2388 <div class="vigilante-analyzer-sparkline-wrap vigilante-analyzer-sparkline-wrap--placeholder">
2389 <span class="vigilante-analyzer-sparkline-label">
2390 <?php esc_html_e( 'Score trend', 'vigilante' ); ?>
2391 </span>
2392 <p class="vigilante-analyzer-sparkline-hint">
2393 <span class="dashicons dashicons-chart-line" aria-hidden="true"></span>
2394 <?php
2395 $needed = 3 - $hist_count;
2396 echo esc_html( sprintf(
2397 /* translators: %d: number of additional scans needed */
2398 _n( '%d more scan needed to show a trend.', '%d more scans needed to show a trend.', $needed, 'vigilante' ),
2399 $needed
2400 ) );
2401 ?>
2402 </p>
2403 </div>
2404 <?php endif; ?>
2405 </div>
2406
2407 <div class="vigilante-analyzer-toggle-row">
2408 <button type="button" class="button-link vigilante-analyzer-toggle" aria-expanded="false">
2409 <?php esc_html_e( 'Show detailed breakdown', 'vigilante' ); ?>
2410 <span class="vigilante-analyzer-toggle-chevron" aria-hidden="true"></span>
2411 </button>
2412 </div>
2413
2414 <div class="vigilante-analyzer-details" hidden>
2415 <div class="vigilante-analyzer-categories" data-role="categories">
2416 <?php foreach ( $categories_def as $slug => $meta ) :
2417 $cat = isset( $categories[ $slug ] ) ? $categories[ $slug ] : array();
2418 $earned = isset( $cat['earned'] ) ? (int) $cat['earned'] : 0;
2419 // Always use the declared meta as the source of truth for the maximum.
2420 // The cached scan may carry an old max if a check was added/removed
2421 // between releases (see 2.6.1: closed_plugins raised internal from 22 to 28
2422 // but cached scans still reported max=22 until reset).
2423 $cat_max = (int) $meta['max'];
2424 $info_only = ! empty( $meta['info_only'] ) || 0 === (int) $meta['max'];
2425 $cat_pct = $cat_max > 0 ? (int) round( ( $earned / $cat_max ) * 100 ) : 0;
2426 $checks = isset( $cat['checks'] ) ? (array) $cat['checks'] : array();
2427 $cat_counts = isset( $cat['counts'] ) && is_array( $cat['counts'] ) ? $cat['counts'] : array( 'pass' => 0, 'warn' => 0, 'fail' => 0, 'info' => 0 );
2428 $cat_quality = self::analyzer_quality_tag( $cat_pct );
2429 $info_count = isset( $cat_counts['info'] ) ? (int) $cat_counts['info'] : 0;
2430 ?>
2431 <details class="vigilante-analyzer-category<?php echo $info_only ? ' vigilante-analyzer-category--info' : ''; ?>"
2432 data-category="<?php echo esc_attr( $slug ); ?>"
2433 data-info-only="<?php echo $info_only ? '1' : '0'; ?>">
2434 <summary class="vigilante-analyzer-category-summary">
2435 <span class="vigilante-analyzer-category-chevron" aria-hidden="true"></span>
2436 <span class="vigilante-analyzer-category-label"><?php echo esc_html( $meta['label'] ); ?></span>
2437 <?php if ( $info_only ) : ?>
2438 <span class="vigilante-analyzer-category-quality vigilante-analyzer-quality-info"
2439 data-role="category-quality"
2440 title="<?php esc_attr_e( 'Informational — does not affect the security score.', 'vigilante' ); ?>">
2441 <span class="dashicons dashicons-info-outline" aria-hidden="true"></span>
2442 <?php esc_html_e( 'Informational', 'vigilante' ); ?>
2443 </span>
2444 <?php else :
2445 $passed_count = (int) ( $cat_counts['pass'] ?? 0 );
2446 $scored_total = $passed_count
2447 + (int) ( $cat_counts['warn'] ?? 0 )
2448 + (int) ( $cat_counts['fail'] ?? 0 );
2449 ?>
2450 <span class="vigilante-analyzer-category-quality vigilante-analyzer-quality-<?php echo esc_attr( $cat_quality['slug'] ); ?>"
2451 data-role="category-quality">
2452 <span data-role="category-quality-label"><?php echo esc_html( $cat_quality['label'] ); ?></span>
2453 <span class="vigilante-analyzer-category-quality-sep" aria-hidden="true">·</span>
2454 <span class="vigilante-analyzer-category-tests" data-role="category-tests"
2455 data-passed="<?php echo esc_attr( $passed_count ); ?>"
2456 data-total="<?php echo esc_attr( $scored_total ); ?>">
2457 <?php
2458 echo esc_html( sprintf(
2459 /* translators: 1: tests passed, 2: total tests in this category */
2460 __( '%1$d/%2$d tests', 'vigilante' ),
2461 $passed_count,
2462 $scored_total
2463 ) );
2464 ?>
2465 </span>
2466 </span>
2467 <?php endif; ?>
2468 <?php if ( $info_only ) : ?>
2469 <span class="vigilante-analyzer-category-states" data-role="category-states">
2470 <?php if ( $info_count > 0 ) : ?>
2471 <span class="vigilante-analyzer-category-state vigilante-analyzer-category-state--info" title="<?php esc_attr_e( 'Informational', 'vigilante' ); ?>">
2472 <span data-role="state-info"><?php echo esc_html( $info_count ); ?></span><span class="dashicons dashicons-info-outline" aria-hidden="true"></span>
2473 </span>
2474 <?php endif; ?>
2475 </span>
2476 <?php endif; ?>
2477 <?php if ( ! $info_only ) : ?>
2478 <span class="vigilante-analyzer-category-score">
2479 <span data-role="earned"><?php echo esc_html( $earned ); ?></span><span class="vigilante-analyzer-category-score-sep">/</span><?php echo esc_html( $cat_max ); ?>
2480 <span class="vigilante-analyzer-category-score-unit"><?php esc_html_e( 'pts', 'vigilante' ); ?></span>
2481 </span>
2482 <span class="vigilante-analyzer-category-bar" aria-hidden="true">
2483 <span class="vigilante-analyzer-category-bar-fill vigilante-analyzer-category-bar-fill--<?php echo esc_attr( $cat_quality['slug'] ); ?>"
2484 style="width: <?php echo esc_attr( $cat_pct ); ?>%"
2485 data-role="category-bar"></span>
2486 </span>
2487 <?php else :
2488 $info_warn = isset( $cat_counts['warn'] ) ? (int) $cat_counts['warn'] : 0;
2489 $info_fail = isset( $cat_counts['fail'] ) ? (int) $cat_counts['fail'] : 0;
2490 $info_issues = $info_warn + $info_fail;
2491 if ( $info_issues > 0 ) : ?>
2492 <span class="vigilante-analyzer-category-status vigilante-analyzer-category-status--attention" data-role="info-status">
2493 <span class="dashicons dashicons-warning" aria-hidden="true"></span>
2494 <?php
2495 echo esc_html( sprintf(
2496 /* translators: %d: number of findings */
2497 _n( '%d finding', '%d findings', $info_issues, 'vigilante' ),
2498 $info_issues
2499 ) );
2500 ?>
2501 </span>
2502 <?php else : ?>
2503 <span class="vigilante-analyzer-category-status vigilante-analyzer-category-status--clear" data-role="info-status">
2504 <span class="dashicons dashicons-yes-alt" aria-hidden="true"></span>
2505 <?php esc_html_e( 'All clear', 'vigilante' ); ?>
2506 </span>
2507 <?php endif; ?>
2508 <?php endif; ?>
2509 </summary>
2510 <ul class="vigilante-analyzer-check-list" data-role="check-list">
2511 <?php if ( empty( $checks ) ) : ?>
2512 <li class="vigilante-analyzer-check-empty">
2513 <?php esc_html_e( 'No data yet — run a scan to populate this category.', 'vigilante' ); ?>
2514 </li>
2515 <?php else : ?>
2516 <?php foreach ( $checks as $c ) : ?>
2517 <?php echo self::render_analyzer_check_row( $c ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped inside helper ?>
2518 <?php endforeach; ?>
2519 <?php endif; ?>
2520 </ul>
2521 </details>
2522 <?php endforeach; ?>
2523 </div>
2524
2525 <div class="vigilante-analyzer-weekly">
2526 <h3><?php esc_html_e( 'Automatic weekly scan', 'vigilante' ); ?></h3>
2527 <p class="description">
2528 <?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' ); ?>
2529 </p>
2530 <label class="vigilante-analyzer-toggle-option">
2531 <input type="checkbox"
2532 name="security_analyzer[weekly_scan_enabled]"
2533 value="1"
2534 <?php checked( $weekly_enabled ); ?>>
2535 <?php esc_html_e( 'Run a weekly automatic scan', 'vigilante' ); ?>
2536 </label>
2537 <label class="vigilante-analyzer-toggle-option">
2538 <input type="checkbox"
2539 name="security_analyzer[email_on_regression]"
2540 value="1"
2541 <?php checked( $email_enabled ); ?>>
2542 <?php esc_html_e( 'Email me when the score drops significantly', 'vigilante' ); ?>
2543 </label>
2544 </div>
2545 </div>
2546 </div>
2547 <?php
2548 }
2549
2550 /**
2551 * Map a 0-100 percentage to a quality tag { label, slug } aligned with the
2552 * Dashboard grade palette (a/b/c/d/e).
2553 *
2554 * @param int $pct 0..100.
2555 * @return array{label:string,slug:string}
2556 */
2557 public static function analyzer_quality_tag( $pct ) {
2558 $pct = max( 0, min( 100, (int) $pct ) );
2559 // "Excellent" is reserved for a perfect score — a single missing point drops to Good.
2560 if ( 100 === $pct ) {
2561 return array( 'label' => __( 'Excellent', 'vigilante' ), 'slug' => 'a' );
2562 }
2563 if ( $pct >= 70 ) {
2564 return array( 'label' => __( 'Good', 'vigilante' ), 'slug' => 'b' );
2565 }
2566 if ( $pct >= 50 ) {
2567 return array( 'label' => __( 'Fair', 'vigilante' ), 'slug' => 'c' );
2568 }
2569 if ( $pct >= 30 ) {
2570 return array( 'label' => __( 'Poor', 'vigilante' ), 'slug' => 'd' );
2571 }
2572 return array( 'label' => __( 'Critical', 'vigilante' ), 'slug' => 'e' );
2573 }
2574
2575 /**
2576 * Render a single analyzer check row (used both server-side and via JS template).
2577 *
2578 * @param array $check Check result array (from Vigilante_SA_Check_Result::to_array()).
2579 * @return string HTML (escaped).
2580 */
2581 private static function render_analyzer_check_row( $check ) {
2582 $id = isset( $check['id'] ) ? $check['id'] : '';
2583 $state = isset( $check['state'] ) ? $check['state'] : 'skip';
2584 $label = isset( $check['label'] ) ? $check['label'] : '';
2585 $detail = isset( $check['detail'] ) ? $check['detail'] : '';
2586 $score = isset( $check['score'] ) ? (int) $check['score'] : 0;
2587 $max = isset( $check['max'] ) ? (int) $check['max'] : 0;
2588 $fix_link = isset( $check['fix_link'] ) ? $check['fix_link'] : '';
2589
2590 $icons = array(
2591 'pass' => 'yes-alt',
2592 'warn' => 'warning',
2593 'fail' => 'dismiss',
2594 'info' => 'info',
2595 'skip' => 'minus',
2596 );
2597 $icon = isset( $icons[ $state ] ) ? $icons[ $state ] : 'minus';
2598
2599 $html = '<li class="vigilante-analyzer-check vigilante-analyzer-check--' . esc_attr( $state ) . '"';
2600 $html .= ' data-check-id="' . esc_attr( $id ) . '">';
2601 $html .= '<span class="vigilante-analyzer-check-icon dashicons dashicons-' . esc_attr( $icon ) . '" aria-hidden="true"></span>';
2602 $html .= '<div class="vigilante-analyzer-check-body">';
2603 $html .= '<div class="vigilante-analyzer-check-label">';
2604 $html .= '<span>' . esc_html( $label ) . '</span>';
2605 if ( $max > 0 && 'info' !== $state && 'skip' !== $state ) {
2606 $html .= '<span class="vigilante-analyzer-check-score">'
2607 . esc_html( $score . '/' . $max )
2608 . ' <span class="vigilante-analyzer-check-score-unit">' . esc_html__( 'pts', 'vigilante' ) . '</span>'
2609 . '</span>';
2610 }
2611 $html .= '</div>';
2612 if ( $detail ) {
2613 $html .= '<p class="vigilante-analyzer-check-detail">' . esc_html( $detail ) . '</p>';
2614 }
2615 if ( $fix_link && in_array( $state, array( 'fail', 'warn' ), true ) ) {
2616 $html .= '<a href="' . esc_url( $fix_link ) . '" class="vigilante-analyzer-fix-link">'
2617 . esc_html__( 'Go to setting', 'vigilante' )
2618 . '<span class="vigilante-analyzer-fix-arrow" aria-hidden="true">&rarr;</span></a>';
2619 } elseif ( $fix_link && 'info' === $state ) {
2620 // Info rows (e.g. DNSBL lookups) get an external "Learn more" link instead.
2621 $is_external = 0 === strpos( $fix_link, 'http' );
2622 $html .= '<a href="' . esc_url( $fix_link ) . '" class="vigilante-analyzer-fix-link"'
2623 . ( $is_external ? ' target="_blank" rel="noopener noreferrer"' : '' ) . '>'
2624 . esc_html__( 'Learn more', 'vigilante' )
2625 . '<span class="vigilante-analyzer-fix-arrow" aria-hidden="true">&rarr;</span></a>';
2626 }
2627 $html .= '</div>';
2628 $html .= '</li>';
2629 return $html;
2630 }
2631
2632 /**
2633 * Build a minimal SVG sparkline for the score history.
2634 *
2635 * @param int[] $points Score values (0..100), oldest to newest.
2636 * @return string SVG markup.
2637 */
2638 private static function sparkline_svg( $points ) {
2639 $points = array_map( 'intval', (array) $points );
2640 $count = count( $points );
2641 if ( $count < 2 ) {
2642 return '';
2643 }
2644 $width = 280;
2645 $height = 60;
2646 $padding = 4;
2647
2648 $usable_w = $width - ( $padding * 2 );
2649 $usable_h = $height - ( $padding * 2 );
2650
2651 $step = $usable_w / max( 1, $count - 1 );
2652 $max = 100; // Fixed scale — scores are 0..100.
2653
2654 $coords = array();
2655 foreach ( $points as $i => $v ) {
2656 $x = $padding + ( $i * $step );
2657 $y = $padding + ( $usable_h - ( ( $v / $max ) * $usable_h ) );
2658 $coords[] = round( $x, 2 ) . ',' . round( $y, 2 );
2659 }
2660 $path = 'M ' . implode( ' L ', $coords );
2661 $last = end( $points );
2662 $last_x = $padding + ( ( $count - 1 ) * $step );
2663 $last_y = $padding + ( $usable_h - ( ( $last / $max ) * $usable_h ) );
2664
2665 $svg = '<svg viewBox="0 0 ' . $width . ' ' . $height . '" preserveAspectRatio="none" role="img" aria-label="' . esc_attr__( 'Security Score history', 'vigilante' ) . '" focusable="false">';
2666 $svg .= '<path d="' . esc_attr( $path ) . '" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>';
2667 $svg .= '<circle cx="' . esc_attr( round( $last_x, 2 ) ) . '" cy="' . esc_attr( round( $last_y, 2 ) ) . '" r="3" fill="currentColor"/>';
2668 $svg .= '</svg>';
2669 return $svg;
2670 }
2671
2672 /**
2673 * Render dashboard tab
2674 */
2675 private function render_tab_dashboard() {
2676 $options = $this->settings->get_all_options();
2677 $module_labels = $this->settings->get_module_labels();
2678 $module_descriptions = $this->settings->get_module_descriptions();
2679 $presets = $this->settings->get_presets();
2680 $active_preset = get_option( 'vigilante_active_preset', '' );
2681
2682 // Calculate security score with more factors
2683 $security_score = $this->calculate_security_score( $options );
2684
2685 // Security Analyzer (v2.1.0) — hydrate widget with the last persisted scan, if any.
2686 if ( ! class_exists( 'Vigilante_Security_Analyzer' ) ) {
2687 require_once VIGILANTE_INCLUDES_DIR . 'class-security-analyzer.php';
2688 }
2689 $analyzer_instance = new Vigilante_Security_Analyzer( $this->settings, $this->activity_log );
2690 $analyzer_last_scan = $analyzer_instance->get_last_scan();
2691 $analyzer_history = $analyzer_instance->get_score_history();
2692 $analyzer_categories_def = Vigilante_Security_Analyzer::get_categories();
2693 $analyzer_settings = isset( $options['security_analyzer'] ) ? $options['security_analyzer'] : array();
2694 ?>
2695 <div class="vigilante-dashboard">
2696 <div class="vigilante-status-card">
2697 <h2><?php esc_html_e( 'Configuration Score', 'vigilante' ); ?></h2>
2698 <p class="vigilante-score-kind description">
2699 <?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' ); ?>
2700 </p>
2701 <div class="vigilante-security-score">
2702 <?php
2703 // Grade thresholds: A (90+), B (70-89), C (50-69), D (30-49), E (0-29)
2704 if ( $security_score >= 90 ) {
2705 $grade = 'A';
2706 } elseif ( $security_score >= 70 ) {
2707 $grade = 'B';
2708 } elseif ( $security_score >= 50 ) {
2709 $grade = 'C';
2710 } elseif ( $security_score >= 30 ) {
2711 $grade = 'D';
2712 } else {
2713 $grade = 'E';
2714 }
2715 ?>
2716 <div class="vigilante-score-circle vigilante-grade-<?php echo esc_attr( strtolower( $grade ) ); ?>">
2717 <span class="vigilante-grade"><?php echo esc_html( $grade ); ?></span>
2718 <span class="vigilante-score-text"><?php echo esc_html( $security_score ); ?>%</span>
2719 </div>
2720 <div class="vigilante-config-status">
2721 <?php if ( $active_preset && isset( $presets[ $active_preset ] ) ) : ?>
2722 <span class="vigilante-preset-badge vigilante-preset-<?php echo esc_attr( $active_preset ); ?>">
2723 <?php echo esc_html( $presets[ $active_preset ]['name'] ); ?>
2724 </span>
2725 <?php else : ?>
2726 <span class="vigilante-preset-badge vigilante-preset-custom">
2727 <?php esc_html_e( 'Custom Configuration', 'vigilante' ); ?>
2728 </span>
2729 <?php endif; ?>
2730 </div>
2731 </div>
2732
2733 <?php
2734 $recommendations = $this->get_security_recommendations( $options );
2735 if ( ! empty( $recommendations ) ) :
2736 ?>
2737 <div class="vigilante-recommendations">
2738 <h4><?php esc_html_e( 'Recommendations', 'vigilante' ); ?></h4>
2739 <ul class="vigilante-recommendations-grid">
2740 <?php foreach ( $recommendations as $rec ) : ?>
2741 <li>
2742 <span class="dashicons dashicons-<?php echo esc_attr( $rec['icon'] ); ?> vigilante-priority-<?php echo esc_attr( $rec['priority'] ); ?>"></span>
2743 <?php echo esc_html( $rec['message'] ); ?>
2744 <?php if ( ! empty( $rec['tab'] ) ) : ?>
2745 <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>
2746 <?php endif; ?>
2747 </li>
2748 <?php endforeach; ?>
2749 </ul>
2750 </div>
2751 <?php endif; ?>
2752 </div>
2753
2754 <?php $this->render_analyzer_widget( $analyzer_last_scan, $analyzer_history, $analyzer_categories_def, $analyzer_settings ); ?>
2755
2756 <div class="vigilante-modules-grid">
2757 <h2 id="vigilante-section-dashboard-modules"><?php esc_html_e( 'Security Modules', 'vigilante' ); ?></h2>
2758 <p class="description"><?php esc_html_e( 'Enable or disable security modules. Each module controls a tab with detailed settings.', 'vigilante' ); ?></p>
2759 <div class="vigilante-modules-list">
2760 <?php foreach ( $options['modules'] as $module => $enabled ) :
2761 $label = isset( $module_labels[ $module ] ) ? $module_labels[ $module ] : ucwords( str_replace( '_', ' ', $module ) );
2762 $description = isset( $module_descriptions[ $module ] ) ? $module_descriptions[ $module ] : '';
2763 $vg_module_locked = $this->main_site_files_locked() && in_array( $module, Vigilante_Settings::get_main_site_file_settings()['modules'], true );
2764 ?>
2765 <div class="vigilante-module-item <?php echo $enabled ? 'enabled' : 'disabled'; ?>">
2766 <div class="vigilante-module-header">
2767 <span class="vigilante-module-status"></span>
2768 <span class="vigilante-module-name"><?php echo esc_html( $label ); ?></span>
2769 <label class="vigilante-toggle">
2770 <?php
2771 /* translators: %s: Security module name, for example Firewall. */
2772 $toggle_label = sprintf( __( 'Enable %s', 'vigilante' ), $label );
2773 ?>
2774 <input type="checkbox"
2775 name="modules[<?php echo esc_attr( $module ); ?>]"
2776 value="1"
2777 <?php checked( $enabled ); ?>
2778 <?php disabled( $vg_module_locked ); ?>
2779 aria-label="<?php echo esc_attr( $toggle_label ); ?>"
2780 data-module="<?php echo esc_attr( $module ); ?>">
2781 <span class="vigilante-toggle-slider"></span>
2782 </label>
2783 </div>
2784 <?php if ( $description ) : ?>
2785 <p class="vigilante-module-desc"><?php echo esc_html( $description ); ?></p>
2786 <?php endif; ?>
2787 <?php if ( $vg_module_locked ) : ?>
2788 <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>
2789 <?php endif; ?>
2790 </div>
2791 <?php endforeach; ?>
2792 </div>
2793 </div>
2794
2795 <div class="vigilante-presets-card">
2796 <h2><?php esc_html_e( 'Quick Configuration Presets', 'vigilante' ); ?></h2>
2797 <p><?php esc_html_e( 'Apply a preset to quickly set up recommended settings for standard or maximum security level.', 'vigilante' ); ?></p>
2798 <div class="vigilante-presets-grid">
2799 <?php foreach ( $presets as $preset_id => $preset ) :
2800 $is_active = ( $active_preset === $preset_id );
2801 ?>
2802 <div class="vigilante-preset-card <?php echo $is_active ? 'vigilante-preset-active' : ''; ?>">
2803 <?php if ( $is_active ) : ?>
2804 <span class="vigilante-active-indicator"><?php esc_html_e( 'Active', 'vigilante' ); ?></span>
2805 <?php endif; ?>
2806 <h3><?php echo esc_html( $preset['name'] ); ?></h3>
2807 <p><?php echo esc_html( $preset['description'] ); ?></p>
2808 <button type="button" class="button vigilante-preset-btn <?php echo $is_active ? 'button-primary' : ''; ?>" data-preset="<?php echo esc_attr( $preset_id ); ?>">
2809 <?php esc_html_e( 'Apply Preset', 'vigilante' ); ?>
2810 </button>
2811 </div>
2812 <?php endforeach; ?>
2813
2814 <?php
2815 // Under Attack mode card
2816 $under_attack = new Vigilante_Under_Attack( $this->settings, $this->activity_log );
2817 $ua_active = $under_attack->is_active();
2818 $ua_remaining = $under_attack->get_remaining_time();
2819 $ua_remaining_hours = floor( $ua_remaining / 3600 );
2820 $ua_remaining_mins = floor( ( $ua_remaining % 3600 ) / 60 );
2821 ?>
2822 <div class="vigilante-preset-card vigilante-under-attack-card <?php echo $ua_active ? 'vigilante-under-attack-active' : ''; ?>">
2823 <h3 id="vigilante-section-dashboard-under-attack">
2824 <span class="dashicons dashicons-shield"></span>
2825 <?php esc_html_e( 'Under Attack', 'vigilante' ); ?>
2826 </h3>
2827 <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>
2828 <?php if ( $ua_active ) : ?>
2829 <div class="vigilante-ua-countdown" data-expires="<?php echo esc_attr( $under_attack->get_status()['activated_at'] + $under_attack->get_status()['duration'] ); ?>">
2830 <span class="dashicons dashicons-clock"></span>
2831 <span class="vigilante-ua-time">
2832 <?php
2833 printf(
2834 /* translators: 1: Hours, 2: Minutes */
2835 esc_html__( '%1$dh %2$dm remaining', 'vigilante' ),
2836 absint( $ua_remaining_hours ),
2837 absint( $ua_remaining_mins )
2838 );
2839 ?>
2840 </span>
2841 </div>
2842 <button type="button" class="button vigilante-ua-btn vigilante-ua-deactivate">
2843 <?php esc_html_e( 'Deactivate', 'vigilante' ); ?>
2844 </button>
2845 <?php else : ?>
2846 <button type="button" class="button vigilante-ua-btn vigilante-ua-activate">
2847 <?php esc_html_e( 'Activate for 4 hours', 'vigilante' ); ?>
2848 </button>
2849 <?php endif; ?>
2850 </div>
2851 </div>
2852 </div>
2853 </div>
2854 <?php
2855 }
2856
2857 /**
2858 * Render tools tab
2859 */
2860 private function render_tab_tools() {
2861 // Get current settings for notification summary
2862 $email_options = $this->settings->get_section( 'email' );
2863 $login_options = $this->settings->get_section( 'login_security' );
2864 $user_options = $this->settings->get_section( 'user_security' );
2865 $fi_options = $this->settings->get_section( 'file_integrity' );
2866 $alerts_options = $this->settings->get_section( 'audit_alerts' );
2867 $monitoring = $user_options['admin_monitoring'] ?? array();
2868 $registration = $user_options['registration_approval'] ?? array();
2869 $current_admin = get_option( 'admin_email' );
2870 $send_to_admin = ! isset( $email_options['send_to_admin_email'] ) || ! empty( $email_options['send_to_admin_email'] );
2871 $additional_raw = $email_options['additional_recipients'] ?? array();
2872 $additional = is_array( $additional_raw ) ? implode( "\n", $additional_raw ) : trim( $additional_raw );
2873 ?>
2874
2875 <!-- Notification Settings -->
2876 <div id="vigilante-section-tools-notifications" class="vigilante-settings-section vigilante-notification-section">
2877 <h2><?php esc_html_e( 'Notification settings', 'vigilante' ); ?></h2>
2878 <p><?php esc_html_e( 'Configure who receives all administrative email notifications from Vigilant. Individual notifications are enabled in their respective tabs.', 'vigilante' ); ?></p>
2879
2880 <div class="vigilante-notification-layout">
2881
2882 <!-- Left column: Recipients settings -->
2883 <div class="vigilante-notification-settings">
2884 <form class="vigilante-settings-form" data-section="email">
2885
2886 <table class="form-table vigilante-compact-form">
2887 <tr>
2888 <th scope="row"><?php esc_html_e( 'WordPress Admin Email', 'vigilante' ); ?></th>
2889 <td>
2890 <label>
2891 <input type="checkbox" name="email[send_to_admin_email]" value="1" <?php checked( $send_to_admin ); ?>>
2892 <?php
2893 printf(
2894 /* translators: %s: Admin email address */
2895 esc_html__( 'Send to admin email (%s)', 'vigilante' ),
2896 '<code>' . esc_html( $current_admin ) . '</code>'
2897 );
2898 ?>
2899 </label>
2900 </td>
2901 </tr>
2902 <tr>
2903 <th scope="row"><label for="vigilante-f-email-additional-recipients"><?php esc_html_e( 'Additional Recipients', 'vigilante' ); ?></label></th>
2904 <td>
2905 <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>
2906 <p class="description"><?php esc_html_e( 'One email per line.', 'vigilante' ); ?></p>
2907 </td>
2908 </tr>
2909 <tr>
2910 <th scope="row"><?php esc_html_e( 'Plugin Deactivation', 'vigilante' ); ?></th>
2911 <td>
2912 <label>
2913 <input type="checkbox" name="email[send_deactivation_email]" value="1" <?php checked( ! empty( $email_options['send_deactivation_email'] ) ); ?>>
2914 <?php esc_html_e( 'Send email when Vigilant is deactivated', 'vigilante' ); ?>
2915 </label>
2916 </td>
2917 </tr>
2918 </table>
2919
2920 <p class="submit vigilante-notification-submit">
2921 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
2922 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
2923 </button>
2924 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
2925 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
2926 </button>
2927 <span class="vigilante-test-email-result" style="margin-left:8px;vertical-align:middle;"></span>
2928 </p>
2929 <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>
2930
2931 </form>
2932 </div>
2933
2934 <!-- Right column: Active notifications summary -->
2935 <div class="vigilante-notification-summary">
2936 <h4><?php esc_html_e( 'Active notifications', 'vigilante' ); ?></h4>
2937
2938 <table class="widefat striped">
2939 <thead>
2940 <tr>
2941 <th><?php esc_html_e( 'Notification', 'vigilante' ); ?></th>
2942 <th style="width: 1%; white-space: nowrap; text-align: center;"><?php esc_html_e( 'Status', 'vigilante' ); ?></th>
2943 <th style="width: 50px; text-align: center;"></th>
2944 </tr>
2945 </thead>
2946 <tbody>
2947 <?php
2948 $notifications = array(
2949 array(
2950 'label' => __( 'Login lockout', 'vigilante' ),
2951 'active' => ! empty( $login_options['notify_on_lockout'] ),
2952 'tab' => 'login',
2953 ),
2954 array(
2955 'label' => __( 'Administrator login', 'vigilante' ),
2956 'active' => ! empty( $login_options['notify_on_admin_login'] ),
2957 'tab' => 'login',
2958 ),
2959 array(
2960 'label' => __( 'New administrator created', 'vigilante' ),
2961 'active' => ! empty( $monitoring['alert_new_admin'] ),
2962 'tab' => 'users',
2963 ),
2964 array(
2965 'label' => __( 'Administrator email changed', 'vigilante' ),
2966 'active' => ! empty( $monitoring['alert_admin_email_change'] ),
2967 'tab' => 'users',
2968 ),
2969 array(
2970 'label' => __( 'Permission elevation', 'vigilante' ),
2971 'active' => ! empty( $monitoring['alert_permission_elevation'] ),
2972 'tab' => 'users',
2973 ),
2974 array(
2975 'label' => __( 'Admin password changed', 'vigilante' ),
2976 'active' => ! empty( $monitoring['alert_admin_password_change'] ),
2977 'tab' => 'users',
2978 ),
2979 array(
2980 'label' => __( 'Registration pending approval', 'vigilante' ),
2981 'active' => ! empty( $registration['enabled'] ) && ! empty( $registration['notify_admin'] ),
2982 'tab' => 'users',
2983 ),
2984 array(
2985 'label' => __( 'File integrity scan report', 'vigilante' ),
2986 'active' => ( $fi_options['notify_level'] ?? 'disabled' ) !== 'disabled',
2987 'tab' => 'file-integrity',
2988 ),
2989 array(
2990 'label' => __( 'File integrity instant alert', 'vigilante' ),
2991 'active' => ! empty( $fi_options['instant_alert'] ),
2992 'tab' => 'file-integrity',
2993 ),
2994 array(
2995 'label' => __( 'Audit alert: immediate', 'vigilante' ),
2996 'active' => Vigilante_Audit_Alerts::immediate_is_active( $alerts_options ),
2997 'tab' => 'activity-log',
2998 'anchor' => 'vigilante-section-audit-alerts',
2999 ),
3000 array(
3001 'label' => __( 'Audit alert: threshold', 'vigilante' ),
3002 'active' => Vigilante_Audit_Alerts::threshold_is_active( $alerts_options ),
3003 'tab' => 'activity-log',
3004 'anchor' => 'vigilante-section-audit-alerts',
3005 ),
3006 array(
3007 'label' => __( 'Under Attack mode', 'vigilante' ),
3008 'active' => true,
3009 'tab' => '',
3010 'note' => __( 'Always active', 'vigilante' ),
3011 ),
3012 array(
3013 'label' => __( 'Plugin deactivation', 'vigilante' ),
3014 'active' => ! empty( $email_options['send_deactivation_email'] ),
3015 'tab' => 'tools',
3016 ),
3017 );
3018
3019 foreach ( $notifications as $notif ) :
3020 $status_class = $notif['active'] ? 'vigilante-status-active' : 'vigilante-status-inactive';
3021 $status_label = $notif['active'] ? __( 'Active', 'vigilante' ) : __( 'Inactive', 'vigilante' );
3022 if ( ! empty( $notif['note'] ) ) {
3023 $status_label = $notif['note'];
3024 }
3025 ?>
3026 <tr>
3027 <td><?php echo esc_html( $notif['label'] ); ?></td>
3028 <td style="text-align: center; white-space: nowrap;">
3029 <span class="<?php echo esc_attr( $status_class ); ?>"><?php echo esc_html( $status_label ); ?></span>
3030 </td>
3031 <td style="text-align: center;">
3032 <?php if ( ! empty( $notif['tab'] ) ) : ?>
3033 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=' . $notif['tab'] ) . ( ! empty( $notif['anchor'] ) ? '#' . $notif['anchor'] : '' ) ); ?>" class="button button-small">
3034 <span class="dashicons dashicons-admin-generic" style="font-size: 14px; line-height: 1.8;"></span>
3035 </a>
3036 <?php else : ?>
3037 &mdash;
3038 <?php endif; ?>
3039 </td>
3040 </tr>
3041 <?php endforeach; ?>
3042 </tbody>
3043 </table>
3044 </div>
3045
3046 </div>
3047 </div>
3048
3049 <h2 id="vigilante-section-tools-main" class="vigilante-tools-heading"><?php esc_html_e( 'Tools', 'vigilante' ); ?></h2>
3050
3051 <?php
3052 // Warn that during Under Attack mode the export/import operate against
3053 // the temporary hardened config and any imported changes will be
3054 // reverted when the mode ends.
3055 $ua_status = get_option( Vigilante_Under_Attack::OPTION_NAME, array() );
3056 if ( ! empty( $ua_status['active'] ) ) :
3057 ?>
3058 <div class="vigilante-ua-tools-notice-wrap">
3059 <div class="notice notice-warning inline vigilante-ua-tools-notice">
3060 <p>
3061 <strong><?php esc_html_e( 'Under Attack mode is active.', 'vigilante' ); ?></strong>
3062 <?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' ); ?>
3063 </p>
3064 </div>
3065 </div>
3066 <?php
3067 endif;
3068 ?>
3069
3070 <div class="vigilante-tools-grid">
3071 <div class="vigilante-tool-card">
3072 <h3><?php esc_html_e( 'Export Settings', 'vigilante' ); ?></h3>
3073 <p><?php esc_html_e( 'Download your current security settings as a JSON file.', 'vigilante' ); ?></p>
3074 <button type="button" class="button vigilante-export-settings">
3075 <?php esc_html_e( 'Export Settings', 'vigilante' ); ?>
3076 </button>
3077 </div>
3078
3079 <div class="vigilante-tool-card">
3080 <h3><?php esc_html_e( 'Import Settings', 'vigilante' ); ?></h3>
3081 <p><?php esc_html_e( 'Import settings from a previously exported JSON file.', 'vigilante' ); ?></p>
3082 <input type="file" id="vigilante-import-file" aria-label="<?php esc_attr_e( 'Configuration file to import', 'vigilante' ); ?>" accept=".json" style="display: none;">
3083 <button type="button" class="button vigilante-import-settings">
3084 <?php esc_html_e( 'Import Settings', 'vigilante' ); ?>
3085 </button>
3086 </div>
3087
3088 <div class="vigilante-tool-card">
3089 <h3><?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?></h3>
3090 <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>
3091 <button type="button" class="button vigilante-reset-settings" style="color: #a00;">
3092 <?php esc_html_e( 'Reset All Settings', 'vigilante' ); ?>
3093 </button>
3094 </div>
3095
3096 <div class="vigilante-tool-card">
3097 <h3><?php esc_html_e( 'Download Config Backup', 'vigilante' ); ?></h3>
3098 <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>
3099 <?php if ( $this->shared_files_locked() ) : ?>
3100 <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>
3101 <?php else : ?>
3102 <button type="button" class="button vigilante-create-backup">
3103 <?php esc_html_e( 'Download Backup', 'vigilante' ); ?>
3104 </button>
3105 <?php endif; ?>
3106 </div>
3107
3108 <?php if ( ! $this->shared_files_locked() ) : ?>
3109
3110 <div class="vigilante-tool-card vigilante-tool-card-wide">
3111 <h3><?php esc_html_e( 'Database Backup', 'vigilante' ); ?></h3>
3112 <p><?php esc_html_e( 'Download a backup of your database as a ZIP file. Select which tables to include.', 'vigilante' ); ?></p>
3113 <button type="button" class="button vigilante-db-backup-toggle">
3114 <?php esc_html_e( 'Download Database Backup', 'vigilante' ); ?>
3115 </button>
3116
3117 <div class="vigilante-db-backup-panel" style="display: none;">
3118 <div class="vigilante-db-tables-loading">
3119 <span class="spinner is-active"></span>
3120 <?php esc_html_e( 'Loading tables...', 'vigilante' ); ?>
3121 </div>
3122
3123 <div class="vigilante-db-tables-content" style="display: none;">
3124 <div class="vigilante-db-tables-controls">
3125 <label>
3126 <input type="checkbox" id="vigilante-db-select-all" checked>
3127 <strong><?php esc_html_e( 'Select / deselect all', 'vigilante' ); ?></strong>
3128 </label>
3129 <span class="vigilante-db-tables-info"></span>
3130 </div>
3131
3132 <div class="vigilante-db-tables-group">
3133 <h4><?php esc_html_e( 'WordPress core tables', 'vigilante' ); ?></h4>
3134 <div class="vigilante-db-tables-list" id="vigilante-db-core-tables"></div>
3135 </div>
3136
3137 <div class="vigilante-db-tables-group" id="vigilante-db-other-group" style="display: none;">
3138 <h4><?php esc_html_e( 'Plugin and custom tables', 'vigilante' ); ?></h4>
3139 <div class="vigilante-db-tables-list" id="vigilante-db-other-tables"></div>
3140 </div>
3141
3142 <div class="vigilante-db-backup-actions">
3143 <button type="button" class="button button-primary vigilante-db-backup-download">
3144 <?php esc_html_e( 'Download Backup (.zip)', 'vigilante' ); ?>
3145 </button>
3146 </div>
3147 </div>
3148 </div>
3149 </div>
3150 <?php else : ?>
3151 <div class="vigilante-tool-card vigilante-tool-card-wide">
3152 <h3><?php esc_html_e( 'Database Backup', 'vigilante' ); ?></h3>
3153 <p><?php esc_html_e( 'Download a backup of your database as a ZIP file. Select which tables to include.', 'vigilante' ); ?></p>
3154 <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>
3155 </div>
3156 <?php endif; ?>
3157 </div>
3158 <?php
3159 }
3160
3161 /**
3162 * Render firewall tab
3163 */
3164 private function render_tab_firewall() {
3165 $is_disabled = $this->render_module_disabled_notice( 'firewall' );
3166 $options = $this->settings->get_section( 'firewall' );
3167 ?>
3168 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="firewall" <?php echo $is_disabled ? 'inert' : ''; ?>>
3169 <div id="vigilante-section-firewall-main" class="vigilante-settings-section">
3170 <h2>
3171 <?php esc_html_e( 'Firewall Protection', 'vigilante' ); ?>
3172 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
3173 </h2>
3174 <p><?php esc_html_e( 'PHP-based request filtering. Analyzes each request before WordPress loads.', 'vigilante' ); ?></p>
3175 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
3176 <p style="margin:0;">
3177 <?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' ); ?>
3178 </p>
3179 </div>
3180
3181 <?php $vg_main_locked = $this->main_site_files_locked(); ?>
3182 <?php if ( $vg_main_locked ) : ?>
3183 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
3184 <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>
3185 </div>
3186 <?php endif; ?>
3187
3188 <table class="form-table">
3189 <tr>
3190 <th scope="row"><?php esc_html_e( 'Block Bad Query Strings', 'vigilante' ); ?></th>
3191 <td>
3192 <label>
3193 <input type="checkbox" name="firewall[block_bad_query_strings]" value="1" <?php disabled( $vg_main_locked ); ?> <?php checked( ! empty( $options['block_bad_query_strings'] ) ); ?>>
3194 <?php esc_html_e( 'Block malicious query string patterns', 'vigilante' ); ?>
3195 </label>
3196 </td>
3197 </tr>
3198 <tr>
3199 <th scope="row"><?php esc_html_e( 'SQL Injection Protection', 'vigilante' ); ?></th>
3200 <td>
3201 <label>
3202 <input type="checkbox" name="firewall[block_sql_injection]" value="1" <?php checked( ! empty( $options['block_sql_injection'] ) ); ?>>
3203 <?php esc_html_e( 'Block SQL injection attempts', 'vigilante' ); ?>
3204 </label>
3205 </td>
3206 </tr>
3207 <tr>
3208 <th scope="row"><?php esc_html_e( 'XSS Protection', 'vigilante' ); ?></th>
3209 <td>
3210 <label>
3211 <input type="checkbox" name="firewall[block_xss_attacks]" value="1" <?php checked( ! empty( $options['block_xss_attacks'] ) ); ?>>
3212 <?php esc_html_e( 'Block cross-site scripting attacks', 'vigilante' ); ?>
3213 </label>
3214 </td>
3215 </tr>
3216 <tr>
3217 <th scope="row"><?php esc_html_e( 'File Inclusion Protection', 'vigilante' ); ?></th>
3218 <td>
3219 <label>
3220 <input type="checkbox" name="firewall[block_file_inclusion]" value="1" <?php checked( ! empty( $options['block_file_inclusion'] ) ); ?>>
3221 <?php esc_html_e( 'Block local/remote file inclusion attempts', 'vigilante' ); ?>
3222 </label>
3223 </td>
3224 </tr>
3225 <tr>
3226 <th scope="row"><?php esc_html_e( 'Directory Traversal Protection', 'vigilante' ); ?></th>
3227 <td>
3228 <label>
3229 <input type="checkbox" name="firewall[block_directory_traversal]" value="1" <?php checked( ! empty( $options['block_directory_traversal'] ) ); ?>>
3230 <?php esc_html_e( 'Block path traversal attempts', 'vigilante' ); ?>
3231 </label>
3232 </td>
3233 </tr>
3234 <tr>
3235 <th scope="row"><?php esc_html_e( 'Block Bad Bots', 'vigilante' ); ?></th>
3236 <td>
3237 <label>
3238 <input type="checkbox" name="firewall[block_bad_bots]" value="1" <?php disabled( $vg_main_locked ); ?> <?php checked( ! empty( $options['block_bad_bots'] ) ); ?>>
3239 <?php esc_html_e( 'Block known malicious bots and scanners', 'vigilante' ); ?>
3240 </label>
3241 </td>
3242 </tr>
3243 </table>
3244
3245 <h3><?php esc_html_e( 'Rate Limiting', 'vigilante' ); ?></h3>
3246 <table class="form-table">
3247 <tr>
3248 <th scope="row"><?php esc_html_e( 'Enable Rate Limiting', 'vigilante' ); ?></th>
3249 <td>
3250 <label>
3251 <input type="checkbox" name="firewall[rate_limiting][enabled]" value="1" <?php checked( ! empty( $options['rate_limiting']['enabled'] ) ); ?>>
3252 <?php esc_html_e( 'Limit requests per IP address', 'vigilante' ); ?>
3253 </label>
3254 </td>
3255 </tr>
3256 <tr>
3257 <th scope="row"><label for="vigilante-f-firewall-rate-limiting-requests-per-minute"><?php esc_html_e( 'Requests per Minute', 'vigilante' ); ?></label></th>
3258 <td>
3259 <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">
3260 <p class="description">
3261 <?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' ); ?>
3262 </p>
3263 </td>
3264 </tr>
3265 <tr>
3266 <th scope="row"><label for="vigilante-f-firewall-rate-limiting-block-duration"><?php esc_html_e( 'Block Duration (seconds)', 'vigilante' ); ?></label></th>
3267 <td>
3268 <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">
3269 </td>
3270 </tr>
3271 <tr>
3272 <th scope="row"><?php esc_html_e( 'Progressive Blocking', 'vigilante' ); ?></th>
3273 <td>
3274 <label>
3275 <input type="checkbox" name="firewall[rate_limiting][progressive]" value="1" <?php checked( ! empty( $options['rate_limiting']['progressive'] ) ); ?>>
3276 <?php esc_html_e( 'Double block duration on each repeat offense', 'vigilante' ); ?>
3277 </label>
3278 <p class="description">
3279 <?php
3280 $base = absint( $options['rate_limiting']['block_duration'] ?? 300 );
3281 printf(
3282 /* translators: 1: First block duration, 2: Second, 3: Third */
3283 esc_html__( 'Example: %1$s → %2$s → %3$s and so on, up to the maximum.', 'vigilante' ),
3284 esc_html( human_time_diff( 0, $base ) ),
3285 esc_html( human_time_diff( 0, $base * 2 ) ),
3286 esc_html( human_time_diff( 0, $base * 4 ) )
3287 );
3288 ?>
3289 </p>
3290 </td>
3291 </tr>
3292 <tr>
3293 <th scope="row"><label for="vigilante-f-firewall-rate-limiting-max-block-duration"><?php esc_html_e( 'Maximum Block Duration', 'vigilante' ); ?></label></th>
3294 <td>
3295 <select id="vigilante-f-firewall-rate-limiting-max-block-duration" name="firewall[rate_limiting][max_block_duration]">
3296 <?php
3297 $max_options = array(
3298 3600 => __( '1 hour', 'vigilante' ),
3299 21600 => __( '6 hours', 'vigilante' ),
3300 43200 => __( '12 hours', 'vigilante' ),
3301 86400 => __( '24 hours', 'vigilante' ),
3302 604800 => __( '7 days', 'vigilante' ),
3303 );
3304 $current_max = absint( $options['rate_limiting']['max_block_duration'] ?? 86400 );
3305 foreach ( $max_options as $val => $label ) :
3306 ?>
3307 <option value="<?php echo esc_attr( $val ); ?>" <?php selected( $current_max, $val ); ?>>
3308 <?php echo esc_html( $label ); ?>
3309 </option>
3310 <?php endforeach; ?>
3311 </select>
3312 <p class="description"><?php esc_html_e( 'Upper limit for progressive blocking.', 'vigilante' ); ?></p>
3313 </td>
3314 </tr>
3315 </table>
3316
3317 <?php
3318 // Currently blocked IPs from rate limiting
3319 $active_blocks = Vigilante_Firewall::get_active_blocks();
3320 if ( ! empty( $active_blocks ) ) :
3321 ?>
3322 <div class="vigilante-settings-section vigilante-lockout-section" style="margin-top:20px;">
3323 <h3><?php esc_html_e( 'Currently Blocked IPs', 'vigilante' ); ?></h3>
3324 <table class="wp-list-table widefat fixed striped" style="max-width:800px;">
3325 <thead>
3326 <tr>
3327 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
3328 <th><?php esc_html_e( 'Blocked', 'vigilante' ); ?></th>
3329 <th><?php esc_html_e( 'Expires in', 'vigilante' ); ?></th>
3330 <th><?php esc_html_e( 'Strikes', 'vigilante' ); ?></th>
3331 <th><?php esc_html_e( 'Action', 'vigilante' ); ?></th>
3332 </tr>
3333 </thead>
3334 <tbody>
3335 <?php foreach ( $active_blocks as $blocked_ip => $block_data ) : ?>
3336 <tr>
3337 <td><code><?php echo esc_html( $blocked_ip ); ?></code></td>
3338 <td><?php echo esc_html( human_time_diff( $block_data['blocked_at'] ) . ' ' . __( 'ago', 'vigilante' ) ); ?></td>
3339 <td><?php echo esc_html( human_time_diff( time(), $block_data['expires'] ) ); ?></td>
3340 <td><?php echo esc_html( $block_data['strikes'] ?? 1 ); ?></td>
3341 <td>
3342 <button type="button" class="button button-small vigilante-unblock-firewall-ip"
3343 data-ip="<?php echo esc_attr( $blocked_ip ); ?>">
3344 <?php esc_html_e( 'Unblock', 'vigilante' ); ?>
3345 </button>
3346 </td>
3347 </tr>
3348 <?php endforeach; ?>
3349 </tbody>
3350 </table>
3351 </div>
3352 <?php endif; ?>
3353
3354 <?php
3355 // Since 2.11.8 X-Forwarded-For is read from its end, where the proxy
3356 // writes. The administrator's own request shows whether that end is
3357 // a CDN or a balancer for everybody here. Cross review of 2.11.8.
3358 $xff_readings = $this->forwarded_chain_readings();
3359 if ( $xff_readings ) :
3360 ?>
3361 <div id="vigilante-xff-chain-notice" class="notice notice-warning inline" style="margin:10px 0 16px;padding:8px 12px;">
3362 <p style="margin:0;">
3363 <?php
3364 printf(
3365 /* translators: 1: address Vigilant reads now, 2: address earlier versions read */
3366 esc_html__( 'Your own request reaches the site with more than one public address in X-Forwarded-For. Vigilant reads the last one, %1$s, which is the one your proxy added; up to version 2.11.7 it read the first one, %2$s, which a visitor can write. If %1$s belongs to a CDN or a load balancer rather than to you, every visitor shares it for rate limiting, login lockouts and the IP lists: choose the header of that CDN in Visitor IP detection, such as CF-Connecting-IP for Cloudflare.', 'vigilante' ),
3367 esc_html( $xff_readings['now'] ),
3368 esc_html( $xff_readings['before'] )
3369 );
3370 ?>
3371 </p>
3372 </div>
3373 <?php endif; ?>
3374
3375 <h3><?php esc_html_e( 'IP Lists', 'vigilante' ); ?></h3>
3376 <p class="description">
3377 <?php
3378 printf(
3379 /* translators: %s: Current visitor IP address */
3380 esc_html__( 'Your current IP address: %s', 'vigilante' ),
3381 '<code>' . esc_html( $this->database->get_client_ip() ) . '</code>'
3382 );
3383 ?>
3384 </p>
3385 <table class="form-table">
3386 <tr>
3387 <th scope="row"><label for="vigilante-f-firewall-trusted-proxy-header"><?php esc_html_e( 'Visitor IP detection', 'vigilante' ); ?></label></th>
3388 <td>
3389 <?php $proxy_header = $options['trusted_proxy_header'] ?? ''; ?>
3390 <select id="vigilante-f-firewall-trusted-proxy-header" name="firewall[trusted_proxy_header]" <?php disabled( $vg_main_locked ); ?>>
3391 <option value="" <?php selected( $proxy_header, '' ); ?>><?php esc_html_e( 'Direct connection, only REMOTE_ADDR (recommended)', 'vigilante' ); ?></option>
3392 <option value="cf-connecting-ip" <?php selected( $proxy_header, 'cf-connecting-ip' ); ?>><?php esc_html_e( 'Behind Cloudflare (CF-Connecting-IP)', 'vigilante' ); ?></option>
3393 <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>
3394 <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>
3395 </select>
3396 <p class="description">
3397 <?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' ); ?>
3398 </p>
3399 </td>
3400 </tr>
3401 <tr>
3402 <th scope="row"><label for="vigilante-f-firewall-ip-whitelist"><?php esc_html_e( 'IP Whitelist', 'vigilante' ); ?></label></th>
3403 <td>
3404 <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>
3405 <p class="description">
3406 <?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' ); ?>
3407 <br>
3408 <?php
3409 printf(
3410 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the IP, CIDR and wildcard examples. */
3411 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' ),
3412 '<code>',
3413 '</code>'
3414 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
3415 ?>
3416 </p>
3417 </td>
3418 </tr>
3419 <tr>
3420 <th scope="row"><label for="vigilante-f-firewall-ip-blacklist"><?php esc_html_e( 'IP Blacklist', 'vigilante' ); ?></label></th>
3421 <td>
3422 <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>
3423 <p class="description">
3424 <?php esc_html_e( 'One IP per line. These IPs will be blocked immediately.', 'vigilante' ); ?>
3425 <br>
3426 <?php
3427 printf(
3428 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the IP, CIDR and wildcard examples. */
3429 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' ),
3430 '<code>',
3431 '</code>'
3432 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
3433 ?>
3434 </p>
3435 </td>
3436 </tr>
3437 </table>
3438
3439 <h3><?php esc_html_e( 'User-Agent Lists', 'vigilante' ); ?></h3>
3440 <p><?php esc_html_e( 'Partial matching: enter a keyword and any User-Agent containing it will be matched.', 'vigilante' ); ?></p>
3441 <table class="form-table">
3442 <tr>
3443 <th scope="row"><label for="vigilante-f-firewall-ua-whitelist"><?php esc_html_e( 'User-Agent Whitelist', 'vigilante' ); ?></label></th>
3444 <td>
3445 <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>
3446 <p class="description"><?php esc_html_e( 'One User-Agent per line. These will bypass all firewall checks. Example: ManageWP, MainWP, UptimeRobot.', 'vigilante' ); ?></p>
3447 </td>
3448 </tr>
3449 <tr>
3450 <th scope="row"><label for="vigilante-f-firewall-ua-blacklist"><?php esc_html_e( 'User-Agent Blacklist', 'vigilante' ); ?></label></th>
3451 <td>
3452 <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>
3453 <p class="description"><?php esc_html_e( 'One User-Agent per line. These will be blocked immediately.', 'vigilante' ); ?></p>
3454 </td>
3455 </tr>
3456 </table>
3457 </div>
3458
3459 <?php
3460 $vg_shared_locked = $this->shared_files_locked();
3461 // Paint what is actually in force, not this site's unused copy.
3462 $vg_local_options = $options;
3463 $options = $this->get_section_for_display( 'firewall' );
3464 ?>
3465 <?php $this->render_shared_files_notice(); ?>
3466 <div id="vigilante-section-firewall-server" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
3467 <h2>
3468 <?php esc_html_e( 'Server Protection', 'vigilante' ); ?>
3469 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
3470 </h2>
3471 <p><?php esc_html_e( 'Server-level rules for Apache/LiteSpeed. These rules are processed before PHP.', 'vigilante' ); ?></p>
3472
3473 <table class="form-table">
3474 <tr id="field-disable-directory-browsing">
3475 <th scope="row"><?php esc_html_e( 'Directory Browsing', 'vigilante' ); ?></th>
3476 <td>
3477 <label>
3478 <input type="checkbox" name="firewall[disable_directory_browsing]" value="1" <?php checked( ! empty( $options['disable_directory_browsing'] ) ); ?>>
3479 <?php esc_html_e( 'Disable directory listing (Options -Indexes)', 'vigilante' ); ?>
3480 </label>
3481 </td>
3482 </tr>
3483 <tr>
3484 <th scope="row"><?php esc_html_e( 'Protect wp-config.php', 'vigilante' ); ?></th>
3485 <td>
3486 <label>
3487 <input type="checkbox" name="firewall[protect_wp_config]" value="1" <?php checked( ! empty( $options['protect_wp_config'] ) ); ?>>
3488 <?php esc_html_e( 'Block direct HTTP access to wp-config.php', 'vigilante' ); ?>
3489 </label>
3490 </td>
3491 </tr>
3492 <tr id="field-protect-wp-cron">
3493 <th scope="row"><?php esc_html_e( 'Protect wp-cron.php', 'vigilante' ); ?></th>
3494 <td>
3495 <label>
3496 <input type="checkbox" name="firewall[protect_wp_cron]" value="1" <?php checked( ! empty( $options['protect_wp_cron'] ) ); ?>>
3497 <?php esc_html_e( 'Block direct HTTP access to wp-cron.php (prevents cron-spam DoS abuse)', 'vigilante' ); ?>
3498 </label>
3499 <p class="description"><?php
3500 printf(
3501 /* translators: 1: opening <strong>, 2: closing </strong> */
3502 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' ),
3503 '<strong>',
3504 '</strong>',
3505 '<code>',
3506 '</code>'
3507 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
3508 ?></p>
3509 </td>
3510 </tr>
3511 <tr>
3512 <th scope="row"><?php esc_html_e( 'Protect wp-includes', 'vigilante' ); ?></th>
3513 <td>
3514 <label>
3515 <input type="checkbox" name="firewall[protect_wp_includes]" value="1" <?php checked( ! empty( $options['protect_wp_includes'] ) ); ?>>
3516 <?php esc_html_e( 'Block direct access to PHP files in wp-includes', 'vigilante' ); ?>
3517 </label>
3518 </td>
3519 </tr>
3520 <tr>
3521 <th scope="row"><?php esc_html_e( 'PHP in Uploads', 'vigilante' ); ?></th>
3522 <td>
3523 <label>
3524 <input type="checkbox" name="firewall[protect_uploads_php]" value="1" <?php checked( ! empty( $options['protect_uploads_php'] ) ); ?>>
3525 <?php esc_html_e( 'Block PHP execution in wp-content/uploads', 'vigilante' ); ?>
3526 </label>
3527 </td>
3528 </tr>
3529 <tr>
3530 <th scope="row"><?php esc_html_e( 'Sensitive Files', 'vigilante' ); ?></th>
3531 <td>
3532 <label>
3533 <input type="checkbox" name="firewall[protect_sensitive_files]" value="1" <?php checked( ! empty( $options['protect_sensitive_files'] ) ); ?>>
3534 <?php esc_html_e( 'Block access to .sql, .bak, .log, .ini, readme.html, license.txt, licencia.txt', 'vigilante' ); ?>
3535 </label>
3536 </td>
3537 </tr>
3538 <tr>
3539 <th scope="row"><?php esc_html_e( 'Limit HTTP Methods', 'vigilante' ); ?></th>
3540 <td>
3541 <label>
3542 <input type="checkbox" name="firewall[limit_http_methods]" value="1" <?php checked( ! empty( $options['limit_http_methods'] ) ); ?>>
3543 <?php esc_html_e( 'Allow only GET, POST, HEAD (blocks PUT, DELETE, TRACE, etc.)', 'vigilante' ); ?>
3544 </label>
3545 </td>
3546 </tr>
3547 </table>
3548 </div>
3549 <?php $options = $vg_local_options; ?>
3550
3551 <p class="submit vigilante-submit-buttons">
3552 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
3553 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
3554 </button>
3555 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
3556 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
3557 </button>
3558 </p>
3559 </form>
3560 <?php
3561 }
3562
3563 /**
3564 * Render login security tab
3565 */
3566 private function render_tab_login() {
3567 $is_disabled = $this->render_module_disabled_notice( 'login_security' );
3568 $options = $this->settings->get_section( 'login_security' );
3569 $lockouts = $this->database->get_active_lockouts();
3570 ?>
3571 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="login_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
3572 <div id="vigilante-section-login-main" class="vigilante-settings-section">
3573 <h2>
3574 <?php esc_html_e( 'Login Protection', 'vigilante' ); ?>
3575 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
3576 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
3577 </h2>
3578 <p><?php esc_html_e( 'Brute force protection and WordPress login hardening.', 'vigilante' ); ?></p>
3579
3580 <table class="form-table">
3581 <tr id="field-max-attempts">
3582 <th scope="row"><label for="vigilante-f-login-security-max-attempts"><?php esc_html_e( 'Max Login Attempts', 'vigilante' ); ?></label></th>
3583 <td>
3584 <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">
3585 <p class="description"><?php esc_html_e( 'Number of failed attempts before lockout.', 'vigilante' ); ?></p>
3586 </td>
3587 </tr>
3588 <tr>
3589 <th scope="row"><label for="vigilante-f-login-security-lockout-duration"><?php esc_html_e( 'Lockout Duration', 'vigilante' ); ?></label></th>
3590 <td>
3591 <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">
3592 <?php esc_html_e( 'minutes', 'vigilante' ); ?>
3593 </td>
3594 </tr>
3595 <tr>
3596 <th scope="row"><?php esc_html_e( 'Progressive Lockout', 'vigilante' ); ?></th>
3597 <td>
3598 <label>
3599 <input type="checkbox" name="login_security[lockout_increment]" value="1" <?php checked( ! empty( $options['lockout_increment'] ) ); ?>>
3600 <?php esc_html_e( 'Double lockout duration for repeat offenders', 'vigilante' ); ?>
3601 </label>
3602 </td>
3603 </tr>
3604 <tr>
3605 <th scope="row"><?php esc_html_e( 'Hide Login Errors', 'vigilante' ); ?></th>
3606 <td>
3607 <label>
3608 <input type="checkbox" name="login_security[hide_login_errors]" value="1" <?php checked( ! empty( $options['hide_login_errors'] ) ); ?>>
3609 <?php esc_html_e( 'Show generic error message instead of specific errors', 'vigilante' ); ?>
3610 </label>
3611 </td>
3612 </tr>
3613 <tr>
3614 <th scope="row"><?php esc_html_e( 'Disable Application Passwords', 'vigilante' ); ?></th>
3615 <td>
3616 <label>
3617 <input type="checkbox" name="login_security[disable_application_passwords]" value="1" <?php checked( ! empty( $options['disable_application_passwords'] ) ); ?>>
3618 <?php esc_html_e( 'Disable WordPress application passwords feature', 'vigilante' ); ?>
3619 </label>
3620 </td>
3621 </tr>
3622 </table>
3623
3624 <h3><?php esc_html_e( 'Custom Login URL', 'vigilante' ); ?></h3>
3625 <table class="form-table">
3626 <tr id="field-custom-login-url">
3627 <th scope="row"><?php esc_html_e( 'Login URL Slug', 'vigilante' ); ?></th>
3628 <td>
3629 <code><?php echo esc_url( home_url( '/' ) ); ?></code>
3630 <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' ); ?>">
3631 <p class="description">
3632 <?php esc_html_e( '&#9432; Leave empty to use default wp-login.php. Use only lowercase letters, numbers and hyphens.', 'vigilante' ); ?>
3633 </p>
3634 <div class="vigilante-login-url-preview" <?php echo empty( $options['custom_login_url'] ) ? 'style="display:none;"' : ''; ?>>
3635 <p class="description">
3636 <strong><?php esc_html_e( 'Your login URL:', 'vigilante' ); ?></strong>
3637 <code class="vigilante-login-url-display"><?php echo esc_url( home_url( sanitize_title( $options['custom_login_url'] ?? '' ) . '/' ) ); ?></code>
3638 </p>
3639 <p class="description">
3640 <?php esc_html_e( 'Direct access to wp-login.php and wp-admin will return a 404 error for non-logged users.', 'vigilante' ); ?>
3641 </p>
3642 <p class="description">
3643 <?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' ); ?>
3644 </p>
3645 </div>
3646 </td>
3647 </tr>
3648 </table>
3649
3650 <div class="vigilante-login-url-notify-wrapper <?php echo empty( $options['custom_login_url'] ) ? 'vigilante-login-url-notify-disabled' : ''; ?>">
3651 <table class="form-table">
3652 <tr>
3653 <th scope="row"><?php esc_html_e( 'Notify users', 'vigilante' ); ?></th>
3654 <td>
3655 <label>
3656 <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 ); ?>>
3657 <?php esc_html_e( 'Notify affected users when the login URL changes', 'vigilante' ); ?>
3658 </label>
3659 <div class="vigilante-login-url-send-notification" style="margin-top:12px;">
3660 <button type="button" id="vigilante_notify_login_url" class="button">
3661 <?php esc_html_e( 'Send notification now', 'vigilante' ); ?>
3662 </button>
3663 <span class="vigilante-login-url-notify-status"></span>
3664 <p class="description"><?php esc_html_e( 'Sends the new URL to administrators, editors, authors, and contributors.', 'vigilante' ); ?></p>
3665 </div>
3666 </td>
3667 </tr>
3668 </table>
3669 </div>
3670
3671 <?php $this->render_2fa_settings( $options ); ?>
3672
3673 <h3><?php esc_html_e( 'Notifications', 'vigilante' ); ?></h3>
3674 <table class="form-table">
3675 <tr>
3676 <th scope="row"><?php esc_html_e( 'Notify on Lockout', 'vigilante' ); ?></th>
3677 <td>
3678 <label>
3679 <input type="checkbox" name="login_security[notify_on_lockout]" value="1" <?php checked( ! empty( $options['notify_on_lockout'] ) ); ?>>
3680 <?php esc_html_e( 'Send email when an IP is locked out', 'vigilante' ); ?>
3681 </label>
3682 </td>
3683 </tr>
3684 <tr>
3685 <th scope="row"><?php esc_html_e( 'Notify on Admin Login', 'vigilante' ); ?></th>
3686 <td>
3687 <label>
3688 <input type="checkbox" name="login_security[notify_on_admin_login]" value="1" <?php checked( ! empty( $options['notify_on_admin_login'] ) ); ?>>
3689 <?php esc_html_e( 'Send email when an administrator logs in', 'vigilante' ); ?>
3690 </label>
3691 </td>
3692 </tr>
3693 </table>
3694
3695 <p class="description">
3696 <?php
3697 printf(
3698 /* translators: %s: Link to notification settings */
3699 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
3700 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
3701 );
3702 ?>
3703 </p>
3704 </div>
3705
3706 <p class="submit vigilante-submit-buttons">
3707 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
3708 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
3709 </button>
3710 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
3711 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
3712 </button>
3713 </p>
3714 </form>
3715
3716 <?php $this->render_lockout_info_section( $options, $lockouts ); ?>
3717 <?php
3718 }
3719
3720 /**
3721 * Render lockout information and blocked IPs section
3722 *
3723 * @param array $options Login security options.
3724 * @param array $lockouts Currently locked out IPs.
3725 */
3726 private function render_lockout_info_section( $options, $lockouts ) {
3727 $max_attempts = absint( $options['max_attempts'] ?? 5 );
3728 $lockout_duration = absint( $options['lockout_duration'] ?? 1800 );
3729 $lockout_increment = ! empty( $options['lockout_increment'] );
3730 $max_lockout = absint( $options['max_lockout_duration'] ?? 86400 );
3731 $two_factor = $options['two_factor'] ?? array();
3732 $two_factor_enabled = ! empty( $two_factor['enabled'] );
3733 ?>
3734 <div class="vigilante-settings-section vigilante-lockout-section">
3735 <h2 id="vigilante-section-login-status"><?php esc_html_e( 'Login Protection Status', 'vigilante' ); ?></h2>
3736
3737 <table class="form-table">
3738 <tr>
3739 <th scope="row"><?php esc_html_e( 'Current settings', 'vigilante' ); ?></th>
3740 <td>
3741 <?php
3742 printf(
3743 /* translators: 1: Maximum login attempts, 2: Lockout duration in minutes */
3744 esc_html__( 'After %1$d failed login attempts, the IP address is blocked for %2$d minutes.', 'vigilante' ),
3745 absint( $max_attempts ),
3746 absint( ceil( $lockout_duration / 60 ) )
3747 );
3748
3749 if ( $lockout_increment ) {
3750 echo '<br>';
3751 printf(
3752 /* translators: %d: Maximum lockout duration in hours */
3753 esc_html__( 'Progressive lockout enabled (max: %d hours).', 'vigilante' ),
3754 absint( ceil( $max_lockout / 3600 ) )
3755 );
3756 }
3757
3758 if ( $two_factor_enabled ) {
3759 echo '<br>';
3760 esc_html_e( 'Failed 2FA codes also count toward the lockout limit.', 'vigilante' );
3761 }
3762 ?>
3763 </td>
3764 </tr>
3765 <tr>
3766 <th scope="row"><?php esc_html_e( 'Blocked IPs', 'vigilante' ); ?></th>
3767 <td>
3768 <?php if ( ! empty( $lockouts ) ) : ?>
3769 <div class="vigilante-paginated-section">
3770 <div class="vigilante-fi-pagination-wrap"></div>
3771 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
3772 <thead>
3773 <tr>
3774 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
3775 <th><?php esc_html_e( 'Attempts', 'vigilante' ); ?></th>
3776 <th><?php esc_html_e( 'Blocked Until', 'vigilante' ); ?></th>
3777 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
3778 </tr>
3779 </thead>
3780 <tbody>
3781 <?php foreach ( $lockouts as $lockout ) :
3782 $lockout_time = strtotime( $lockout->locked_until );
3783 $remaining_seconds = $lockout_time - time();
3784 $remaining_text = $this->format_remaining_time( $remaining_seconds );
3785 ?>
3786 <tr>
3787 <td><code><?php echo esc_html( $lockout->ip_address ); ?></code></td>
3788 <td><?php echo esc_html( $lockout->attempts ); ?></td>
3789 <td>
3790 <?php echo esc_html( wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $lockout_time ) ); ?>
3791 <br>
3792 <small class="description">
3793 <?php
3794 printf(
3795 /* translators: %s: Remaining time */
3796 esc_html__( '%s remaining', 'vigilante' ),
3797 esc_html( $remaining_text )
3798 );
3799 ?>
3800 </small>
3801 </td>
3802 <td>
3803 <button type="button" class="button button-small vigilante-clear-lockout" data-ip="<?php echo esc_attr( $lockout->ip_address ); ?>">
3804 <?php esc_html_e( 'Unblock', 'vigilante' ); ?>
3805 </button>
3806 </td>
3807 </tr>
3808 <?php endforeach; ?>
3809 </tbody>
3810 </table>
3811 </div>
3812 <p class="description" style="margin-top: 10px;">
3813 <button type="button" class="button vigilante-clear-all-lockouts">
3814 <?php esc_html_e( 'Unblock All IPs', 'vigilante' ); ?>
3815 </button>
3816 <span style="margin-left: 10px;">
3817 <?php
3818 printf(
3819 /* translators: %d: Number of blocked IPs */
3820 esc_html( _n( '%d IP currently blocked', '%d IPs currently blocked', count( $lockouts ), 'vigilante' ) ),
3821 count( $lockouts )
3822 );
3823 ?>
3824 </span>
3825 </p>
3826 <?php else : ?>
3827 <span class="dashicons dashicons-yes-alt" style="color: #00a32a; font-size: 20px; width: 20px; height: 20px; vertical-align: middle;"></span>
3828 <span style="vertical-align: middle; margin-left: 5px;"><?php esc_html_e( 'No IPs are currently blocked. All clear!', 'vigilante' ); ?></span>
3829 <?php endif; ?>
3830 </td>
3831 </tr>
3832 </table>
3833 </div>
3834 <?php
3835 }
3836
3837 /**
3838 * Format remaining lockout time in human readable format
3839 *
3840 * @param int $seconds Remaining seconds.
3841 * @return string Formatted time string.
3842 */
3843 private function format_remaining_time( $seconds ) {
3844 if ( $seconds <= 0 ) {
3845 return __( 'expired', 'vigilante' );
3846 }
3847
3848 if ( $seconds < 60 ) {
3849 return sprintf(
3850 /* translators: %d: Number of seconds */
3851 _n( '%d second', '%d seconds', $seconds, 'vigilante' ),
3852 $seconds
3853 );
3854 }
3855
3856 if ( $seconds < 3600 ) {
3857 $minutes = ceil( $seconds / 60 );
3858 return sprintf(
3859 /* translators: %d: Number of minutes */
3860 _n( '%d minute', '%d minutes', $minutes, 'vigilante' ),
3861 $minutes
3862 );
3863 }
3864
3865 $hours = floor( $seconds / 3600 );
3866 $remaining_minutes = ceil( ( $seconds % 3600 ) / 60 );
3867
3868 if ( $remaining_minutes > 0 ) {
3869 return sprintf(
3870 /* translators: 1: Number of hours, 2: Number of minutes */
3871 __( '%1$d hours %2$d minutes', 'vigilante' ),
3872 $hours,
3873 $remaining_minutes
3874 );
3875 }
3876
3877 return sprintf(
3878 /* translators: %d: Number of hours */
3879 _n( '%d hour', '%d hours', $hours, 'vigilante' ),
3880 $hours
3881 );
3882 }
3883
3884 /**
3885 * Render 2FA settings section
3886 *
3887 * @param array $options Login security options.
3888 */
3889 private function render_2fa_settings( $options ) {
3890 $two_factor = $options['two_factor'] ?? array();
3891 $all_roles = wp_roles()->roles;
3892 $enforced = $two_factor['enforced_roles'] ?? array( 'administrator', 'editor' );
3893 $excluded = $two_factor['excluded_users'] ?? array();
3894 $method = $two_factor['method'] ?? 'email';
3895 $grace_days = $two_factor['grace_period_days'] ?? 3;
3896 ?>
3897 <h3 id="vigilante-section-login-2fa">
3898 <?php esc_html_e( 'Two-Factor Authentication (2FA)', 'vigilante' ); ?>
3899 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
3900 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
3901 </h3>
3902 <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>
3903
3904 <table class="form-table">
3905 <tr>
3906 <th scope="row"><?php esc_html_e( 'Enable 2FA', 'vigilante' ); ?></th>
3907 <td>
3908 <label>
3909 <input type="checkbox" name="login_security[two_factor][enabled]" id="vigilante_2fa_enabled" value="1" <?php checked( ! empty( $two_factor['enabled'] ) ); ?>>
3910 <?php esc_html_e( 'Enable two-factor authentication', 'vigilante' ); ?>
3911 </label>
3912 </td>
3913 </tr>
3914 </table>
3915
3916 <div class="vigilante-2fa-settings-wrapper <?php echo empty( $two_factor['enabled'] ) ? 'vigilante-2fa-settings-disabled' : ''; ?>">
3917 <table class="form-table">
3918 <tr>
3919 <th scope="row"><?php esc_html_e( 'Verification method', 'vigilante' ); ?></th>
3920 <td>
3921 <fieldset class="vigilante-2fa-method-selector">
3922 <label class="vigilante-2fa-method-option <?php echo 'email' === $method ? 'selected' : ''; ?>">
3923 <input type="radio" name="login_security[two_factor][method]" value="email" <?php checked( $method, 'email' ); ?>>
3924 <span class="dashicons dashicons-email"></span>
3925 <span class="method-info">
3926 <strong><?php esc_html_e( 'Email code', 'vigilante' ); ?></strong>
3927 <span><?php esc_html_e( 'Users receive a 6-digit code via email after entering their password.', 'vigilante' ); ?></span>
3928 </span>
3929 </label>
3930 <label class="vigilante-2fa-method-option <?php echo 'totp' === $method ? 'selected' : ''; ?>">
3931 <input type="radio" name="login_security[two_factor][method]" value="totp" <?php checked( $method, 'totp' ); ?>>
3932 <span class="dashicons dashicons-smartphone"></span>
3933 <span class="method-info">
3934 <strong><?php esc_html_e( 'Authenticator app (TOTP)', 'vigilante' ); ?></strong>
3935 <span><?php esc_html_e( 'Users verify with a time-based code from Google Authenticator, Authy, etc.', 'vigilante' ); ?></span>
3936 </span>
3937 </label>
3938 </fieldset>
3939 </td>
3940 </tr>
3941 <tr>
3942 <th scope="row"><?php esc_html_e( 'Enforce for roles', 'vigilante' ); ?></th>
3943 <td>
3944 <div class="vigilante-2fa-roles">
3945 <?php foreach ( $all_roles as $role_slug => $role_data ) :
3946 $user_count = count( get_users( array( 'role' => $role_slug, 'fields' => 'ID' ) ) );
3947 ?>
3948 <label>
3949 <input type="checkbox"
3950 name="login_security[two_factor][enforced_roles][]"
3951 value="<?php echo esc_attr( $role_slug ); ?>"
3952 <?php checked( in_array( $role_slug, $enforced, true ) ); ?>>
3953 <span class="role-name"><?php echo esc_html( translate_user_role( $role_data['name'] ) ); ?></span>
3954 <span class="role-count">(<?php echo esc_html( $user_count ); ?>)</span>
3955 </label>
3956 <?php endforeach; ?>
3957 </div>
3958 <p class="description"><?php esc_html_e( 'Users with these roles will be required to verify with the selected method.', 'vigilante' ); ?></p>
3959 </td>
3960 </tr>
3961 <tr>
3962 <th scope="row"><?php esc_html_e( 'Exclude specific users', 'vigilante' ); ?></th>
3963 <td>
3964 <div class="vigilante-2fa-user-search-container">
3965 <div class="vigilante-2fa-user-search">
3966 <span class="search-icon"></span>
3967 <input type="text"
3968 id="vigilante_2fa_user_search"
3969 placeholder="<?php esc_attr_e( 'Search users by name or email...', 'vigilante' ); ?>"
3970 autocomplete="off">
3971 <div class="vigilante-2fa-search-results"></div>
3972 </div>
3973 <div class="vigilante-2fa-excluded-users">
3974 <?php
3975 foreach ( $excluded as $user_id ) :
3976 $user = get_user_by( 'ID', $user_id );
3977 if ( ! $user ) continue;
3978 ?>
3979 <div class="vigilante-2fa-excluded-user" data-user-id="<?php echo esc_attr( $user_id ); ?>">
3980 <span class="user-display"><?php echo esc_html( $user->display_name . ' (' . $user->user_email . ')' ); ?></span>
3981 <button type="button" class="remove-user" aria-label="<?php esc_attr_e( 'Remove', 'vigilante' ); ?>">&times;</button>
3982 <input type="hidden" name="login_security[two_factor][excluded_users][]" value="<?php echo esc_attr( $user_id ); ?>">
3983 </div>
3984 <?php endforeach; ?>
3985 </div>
3986 </div>
3987 <p class="description"><?php esc_html_e( 'These users will not be required to use 2FA regardless of their role.', 'vigilante' ); ?></p>
3988 </td>
3989 </tr>
3990
3991 <!-- Remember device option -->
3992 <tr>
3993 <th scope="row"><?php esc_html_e( 'Remember device', 'vigilante' ); ?></th>
3994 <td>
3995 <label>
3996 <input type="checkbox" name="login_security[two_factor][allow_remember_device]" value="1" <?php checked( ! empty( $two_factor['allow_remember_device'] ) ); ?>>
3997 <?php esc_html_e( 'Allow users to skip 2FA verification on trusted devices', 'vigilante' ); ?>
3998 </label>
3999 <p class="description">
4000 <?php
4001 printf(
4002 /* translators: %d: Number of days */
4003 esc_html__( 'When enabled, users can check "Remember this device" on the verification screen to skip 2FA for %d days.', 'vigilante' ),
4004 absint( $two_factor['remember_device_days'] ?? 30 )
4005 );
4006 ?>
4007 </p>
4008 </td>
4009 </tr>
4010
4011 <!-- TOTP-specific: Grace period -->
4012 <tr class="vigilante-2fa-totp-only" <?php echo 'totp' !== $method ? 'style="display:none;"' : ''; ?>>
4013 <th scope="row"><label for="vigilante-f-login-security-two-factor-grace-period-days"><?php esc_html_e( 'Grace period', 'vigilante' ); ?></label></th>
4014 <td>
4015 <input id="vigilante-f-login-security-two-factor-grace-period-days" type="number"
4016 name="login_security[two_factor][grace_period_days]"
4017 value="<?php echo esc_attr( $grace_days ); ?>"
4018 min="0" max="30" class="small-text">
4019 <?php esc_html_e( 'days', 'vigilante' ); ?>
4020 <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>
4021 </td>
4022 </tr>
4023
4024 <!-- Email-specific: Sender name -->
4025 <tr class="vigilante-2fa-email-only" <?php echo 'email' !== $method ? 'style="display:none;"' : ''; ?>>
4026 <th scope="row"><label for="vigilante-f-login-security-two-factor-email-from-name"><?php esc_html_e( 'Email sender name', 'vigilante' ); ?></label></th>
4027 <td>
4028 <input id="vigilante-f-login-security-two-factor-email-from-name" type="text"
4029 name="login_security[two_factor][email_from_name]"
4030 value="<?php echo esc_attr( $two_factor['email_from_name'] ?? '' ); ?>"
4031 class="regular-text vigilante-2fa-email-from"
4032 placeholder="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>">
4033 <p class="description"><?php esc_html_e( 'Name shown in verification emails. Leave empty to use site name.', 'vigilante' ); ?></p>
4034 </td>
4035 </tr>
4036
4037 <!-- TOTP-specific: Reset users -->
4038 <tr class="vigilante-2fa-totp-only" <?php echo 'totp' !== $method ? 'style="display:none;"' : ''; ?>>
4039 <th scope="row"><?php esc_html_e( 'Reset user TOTP', 'vigilante' ); ?></th>
4040 <td>
4041 <div class="vigilante-totp-reset-container">
4042 <div class="vigilante-2fa-user-search">
4043 <span class="search-icon"></span>
4044 <input type="text"
4045 id="vigilante_totp_reset_search"
4046 placeholder="<?php esc_attr_e( 'Search users with TOTP configured...', 'vigilante' ); ?>"
4047 autocomplete="off">
4048 <div class="vigilante-totp-reset-results"></div>
4049 </div>
4050 <div class="vigilante-totp-reset-selected"></div>
4051 <button type="button" id="vigilante_totp_reset_btn" class="button" style="display:none;">
4052 <?php esc_html_e( 'Reset selected', 'vigilante' ); ?>
4053 </button>
4054 <span class="vigilante-totp-reset-status"></span>
4055 </div>
4056 <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>
4057 </td>
4058 </tr>
4059 </table>
4060
4061 <h3><?php esc_html_e( 'User notification', 'vigilante' ); ?></h3>
4062 <table class="form-table">
4063 <tr>
4064 <th scope="row"><?php esc_html_e( 'Notify on enable', 'vigilante' ); ?></th>
4065 <td>
4066 <label>
4067 <input type="checkbox" name="login_security[two_factor][notify_on_enable]" value="1" <?php checked( $two_factor['notify_on_enable'] ?? true ); ?>>
4068 <?php esc_html_e( 'Send notification email to affected users when 2FA is enabled', 'vigilante' ); ?>
4069 </label>
4070
4071 <div class="vigilante-2fa-notification-options">
4072 <label>
4073 <input type="radio" name="vigilante_2fa_notify_mode" value="all" checked>
4074 <?php esc_html_e( 'Send to all affected users', 'vigilante' ); ?>
4075 </label>
4076 <label>
4077 <input type="radio" name="vigilante_2fa_notify_mode" value="new">
4078 <?php esc_html_e( 'Send only to users not previously notified', 'vigilante' ); ?>
4079 </label>
4080 </div>
4081
4082 <div class="vigilante-2fa-send-notification">
4083 <button type="button" id="vigilante_2fa_send_notification" class="button">
4084 <?php esc_html_e( 'Send notification now', 'vigilante' ); ?>
4085 </button>
4086 <span class="vigilante-2fa-notification-status"></span>
4087 </div>
4088 </td>
4089 </tr>
4090 </table>
4091 </div>
4092 <?php
4093 }
4094
4095 /**
4096 * Render security headers tab
4097 */
4098 /**
4099 * Offer back the header settings the 2.9.8 migration wiped.
4100 *
4101 * Rendered outside the settings form on purpose, so its buttons can never
4102 * submit it, and only when there is something to actually change. Shows the
4103 * difference before anything is written: nothing is applied that the owner
4104 * has not seen first.
4105 *
4106 * @since 2.10.0
4107 */
4108 private function render_headers_recovery_offer() {
4109 /*
4110 * On a network the .htaccess belongs to every site and only the main one
4111 * writes it, so this is not a decision a subsite gets to make. Its own
4112 * security_headers options are inert anyway: what the network serves
4113 * comes from the file the main site owns. Without this gate a subsite
4114 * administrator was shown a Restore button that could only ever answer
4115 * with a permission error, which is worse than showing nothing.
4116 */
4117 if ( ! Vigilante_Settings::can_write_shared_files() ) {
4118 return;
4119 }
4120
4121 if ( ! Vigilante_Htaccess_Recovery::is_available() ) {
4122 /*
4123 * Already restored. Offer to take it back for as long as the previous
4124 * section is still stored: a restore that cannot be undone is a second
4125 * irreversible change on top of the one being repaired.
4126 */
4127 if ( Vigilante_Htaccess_Recovery::has_undo() ) {
4128 ?>
4129 <div class="notice notice-info inline" id="vigilante-headers-recovery-undo">
4130 <p>
4131 <?php esc_html_e( 'The Security Headers settings were restored from the copy Vigilant had kept of your .htaccess.', 'vigilante' ); ?>
4132 <button type="button" class="button button-small" id="vigilante-recovery-undo">
4133 <?php esc_html_e( 'Undo the restore', 'vigilante' ); ?>
4134 </button>
4135 </p>
4136 </div>
4137 <?php
4138 }
4139
4140 return;
4141 }
4142
4143 $rows = Vigilante_Htaccess_Recovery::get_diff( $this->settings );
4144
4145 if ( empty( $rows ) ) {
4146 return;
4147 }
4148
4149 $snapshot = Vigilante_Htaccess_Recovery::get_snapshot();
4150 $taken = isset( $snapshot['time'] ) ? (int) $snapshot['time'] : 0;
4151 $block = Vigilante_Htaccess_Recovery::get_raw_block();
4152 ?>
4153 <div class="vigilante-settings-section" id="vigilante-headers-recovery">
4154 <h2><?php esc_html_e( 'Recover your previous header settings', 'vigilante' ); ?></h2>
4155 <p>
4156 <?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' ); ?>
4157 </p>
4158 <?php if ( $taken ) : ?>
4159 <p class="description">
4160 <?php
4161 printf(
4162 /* translators: %s: date and time the .htaccess copy was taken. */
4163 esc_html__( 'Copy taken on %s.', 'vigilante' ),
4164 esc_html( wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $taken ) )
4165 );
4166 ?>
4167 </p>
4168 <?php endif; ?>
4169
4170 <table class="widefat striped">
4171 <thead>
4172 <tr>
4173 <th scope="col"><?php esc_html_e( 'Setting', 'vigilante' ); ?></th>
4174 <th scope="col"><?php esc_html_e( 'Now', 'vigilante' ); ?></th>
4175 <th scope="col"><?php esc_html_e( 'Would be restored to', 'vigilante' ); ?></th>
4176 </tr>
4177 </thead>
4178 <tbody>
4179 <?php foreach ( $rows as $row ) : ?>
4180 <tr>
4181 <th scope="row"><?php echo esc_html( $row['label'] ); ?></th>
4182 <td><?php echo esc_html( $row['current'] ); ?></td>
4183 <td>
4184 <?php echo esc_html( $row['recovered'] ); ?>
4185 <?php if ( ! empty( $row['detail'] ) ) : ?>
4186 <br><span class="description"><?php echo esc_html( $row['detail'] ); ?></span>
4187 <?php endif; ?>
4188 </td>
4189 </tr>
4190 <?php endforeach; ?>
4191 </tbody>
4192 </table>
4193
4194 <p class="description">
4195 <?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' ); ?>
4196 </p>
4197
4198 <?php if ( '' !== $block ) : ?>
4199 <details>
4200 <summary><?php esc_html_e( 'Show the saved .htaccess block', 'vigilante' ); ?></summary>
4201 <textarea readonly rows="12" class="large-text code" onclick="this.select();"><?php echo esc_textarea( $block ); ?></textarea>
4202 </details>
4203 <?php endif; ?>
4204
4205 <p class="submit vigilante-submit-buttons">
4206 <button type="button" class="button button-primary" id="vigilante-recovery-restore">
4207 <?php esc_html_e( 'Restore these settings', 'vigilante' ); ?>
4208 </button>
4209 <button type="button" class="button" id="vigilante-recovery-dismiss">
4210 <?php esc_html_e( 'No thanks, keep what I have', 'vigilante' ); ?>
4211 </button>
4212 </p>
4213 <div id="vigilante-recovery-result"></div>
4214 </div>
4215 <?php
4216 }
4217
4218 private function render_tab_headers() {
4219 $is_disabled = $this->render_module_disabled_notice( 'security_headers' );
4220 // Every setting on this tab ends up in .htaccess, so on a subsite the
4221 // whole tab is somebody else's, values included.
4222 $vg_shared_locked = $this->shared_files_locked();
4223 $options = $this->get_section_for_display( 'security_headers' );
4224 ?>
4225 <?php $this->render_headers_recovery_offer(); ?>
4226
4227 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="security_headers" <?php echo $is_disabled ? 'inert' : ''; ?>>
4228 <?php $this->render_shared_files_notice(); ?>
4229 <div id="vigilante-section-headers-main" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
4230 <h2>
4231 <?php esc_html_e( 'Security Headers', 'vigilante' ); ?>
4232 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
4233 </h2>
4234 <p><?php esc_html_e( 'HTTP headers sent with every response via .htaccess (mod_headers).', 'vigilante' ); ?></p>
4235
4236 <table class="form-table">
4237 <tr>
4238 <th scope="row"><label for="vigilante-f-security-headers-x-frame-options"><?php esc_html_e( 'X-Frame-Options', 'vigilante' ); ?></label></th>
4239 <td>
4240 <select id="vigilante-f-security-headers-x-frame-options" name="security_headers[x_frame_options]">
4241 <option value="" <?php selected( empty( $options['x_frame_options'] ) ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
4242 <option value="SAMEORIGIN" <?php selected( $options['x_frame_options'] ?? '', 'SAMEORIGIN' ); ?>>SAMEORIGIN</option>
4243 <option value="DENY" <?php selected( $options['x_frame_options'] ?? '', 'DENY' ); ?>>DENY</option>
4244 </select>
4245 <p class="description"><?php esc_html_e( '&#9432; Prevents clickjacking attacks. Also sets CSP frame-ancestors automatically.', 'vigilante' ); ?></p>
4246 </td>
4247 </tr>
4248 <tr>
4249 <th scope="row"><?php esc_html_e( 'X-Content-Type-Options', 'vigilante' ); ?></th>
4250 <td>
4251 <label>
4252 <input type="checkbox" name="security_headers[x_content_type_options]" value="1" <?php checked( ! empty( $options['x_content_type_options'] ) ); ?>>
4253 <?php esc_html_e( 'Add nosniff header to prevent MIME type sniffing', 'vigilante' ); ?>
4254 </label>
4255 </td>
4256 </tr>
4257 <tr>
4258 <th scope="row"><label for="vigilante-f-security-headers-referrer-policy"><?php esc_html_e( 'Referrer-Policy', 'vigilante' ); ?></label></th>
4259 <td>
4260 <select id="vigilante-f-security-headers-referrer-policy" name="security_headers[referrer_policy]">
4261 <option value="" <?php selected( empty( $options['referrer_policy'] ) ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
4262 <option value="no-referrer" <?php selected( $options['referrer_policy'] ?? '', 'no-referrer' ); ?>>no-referrer</option>
4263 <option value="strict-origin-when-cross-origin" <?php selected( $options['referrer_policy'] ?? '', 'strict-origin-when-cross-origin' ); ?>>strict-origin-when-cross-origin</option>
4264 <option value="same-origin" <?php selected( $options['referrer_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
4265 </select>
4266 </td>
4267 </tr>
4268 </table>
4269
4270 <h3 id="vigilante-section-headers-csp"><?php esc_html_e( 'Content Security Policy', 'vigilante' ); ?></h3>
4271 <table class="form-table">
4272 <tr>
4273 <th scope="row"><?php esc_html_e( 'Enable CSP', 'vigilante' ); ?></th>
4274 <td>
4275 <label>
4276 <input type="checkbox" name="security_headers[csp][enabled]" value="1" <?php checked( ! empty( $options['csp']['enabled'] ) ); ?>>
4277 <?php esc_html_e( 'Enable Content Security Policy', 'vigilante' ); ?>
4278 </label>
4279 </td>
4280 </tr>
4281 <tr>
4282 <th scope="row"><?php esc_html_e( 'Report Only Mode', 'vigilante' ); ?></th>
4283 <td>
4284 <label>
4285 <input type="checkbox" name="security_headers[csp][report_only]" value="1" <?php checked( ! empty( $options['csp']['report_only'] ) ); ?>>
4286 <?php esc_html_e( 'Report violations without blocking (for testing)', 'vigilante' ); ?>
4287 </label>
4288 </td>
4289 </tr>
4290 </table>
4291
4292 <h3 id="vigilante-section-headers-force-https"><?php esc_html_e( 'HTTPS', 'vigilante' ); ?></h3>
4293 <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>
4294 <table class="form-table">
4295 <tr>
4296 <th scope="row"><?php esc_html_e( 'Redirect HTTP to HTTPS', 'vigilante' ); ?></th>
4297 <td>
4298 <label>
4299 <input type="checkbox" name="security_headers[redirect_http_to_https]" value="1" <?php checked( ! empty( $options['redirect_http_to_https'] ) ); ?>>
4300 <?php esc_html_e( 'Send visitors arriving over HTTP to the HTTPS address', 'vigilante' ); ?>
4301 </label>
4302 <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>
4303 </td>
4304 </tr>
4305 <tr>
4306 <th scope="row"><?php esc_html_e( 'Fix Mixed Content', 'vigilante' ); ?></th>
4307 <td>
4308 <label>
4309 <input type="checkbox" name="security_headers[fix_mixed_content]" value="1" <?php checked( ! empty( $options['fix_mixed_content'] ) ); ?>>
4310 <?php esc_html_e( 'Rewrite this site http:// resources to https://', 'vigilante' ); ?>
4311 </label>
4312 <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>
4313 </td>
4314 </tr>
4315 <tr id="field-upgrade-insecure-requests">
4316 <th scope="row"><?php esc_html_e( 'Upgrade Insecure Requests', 'vigilante' ); ?></th>
4317 <td>
4318 <label>
4319 <input type="checkbox" name="security_headers[upgrade_insecure_requests]" value="1" <?php checked( ! empty( $options['upgrade_insecure_requests'] ) ); ?>>
4320 <?php esc_html_e( 'Ask browsers to upgrade every http:// request to https://', 'vigilante' ); ?>
4321 </label>
4322 <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>
4323 </td>
4324 </tr>
4325 <tr>
4326 <th scope="row"><?php esc_html_e( 'Rewrite Site Address on Activation', 'vigilante' ); ?></th>
4327 <td>
4328 <label>
4329 <input type="checkbox" name="security_headers[force_https]" value="1" <?php checked( ! empty( $options['force_https'] ) ); ?>>
4330 <?php esc_html_e( 'Change the WordPress and site addresses to https:// when the plugin is activated', 'vigilante' ); ?>
4331 </label>
4332 <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>
4333 </td>
4334 </tr>
4335 </table>
4336
4337 <h3 id="vigilante-section-headers-hsts"><?php esc_html_e( 'HSTS (HTTP Strict Transport Security)', 'vigilante' ); ?></h3>
4338 <?php $vig_home_https = ( 0 === strpos( (string) get_option( 'home' ), 'https://' ) ); ?>
4339 <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>
4340 <?php if ( ! $vig_home_https ) : ?>
4341 <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>
4342 <?php endif; ?>
4343 <table class="form-table">
4344 <tr>
4345 <th scope="row"><?php esc_html_e( 'Enable HSTS', 'vigilante' ); ?></th>
4346 <td>
4347 <?php if ( ! $vig_home_https ) : ?>
4348 <?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. */ ?>
4349 <input type="hidden" name="security_headers[hsts][enabled]" value="<?php echo ! empty( $options['hsts']['enabled'] ) ? '1' : '0'; ?>">
4350 <?php endif; ?>
4351 <label>
4352 <input type="checkbox" name="security_headers[hsts][enabled]" value="1" <?php checked( ! empty( $options['hsts']['enabled'] ) ); ?> <?php disabled( ! $vig_home_https ); ?>>
4353 <?php esc_html_e( 'Send the Strict-Transport-Security header', 'vigilante' ); ?>
4354 </label>
4355 <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>
4356 </td>
4357 </tr>
4358 <tr>
4359 <th scope="row"><label for="vigilante-f-security-headers-hsts-max-age"><?php esc_html_e( 'Max Age', 'vigilante' ); ?></label></th>
4360 <td>
4361 <select id="vigilante-f-security-headers-hsts-max-age" name="security_headers[hsts][max_age]">
4362 <option value="86400" <?php selected( $options['hsts']['max_age'] ?? 31536000, 86400 ); ?>><?php esc_html_e( '1 day (testing)', 'vigilante' ); ?></option>
4363 <option value="2592000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 2592000 ); ?>><?php esc_html_e( '30 days', 'vigilante' ); ?></option>
4364 <option value="31536000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 31536000 ); ?>><?php esc_html_e( '1 year (recommended)', 'vigilante' ); ?></option>
4365 <option value="63072000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 63072000 ); ?>><?php esc_html_e( '2 years', 'vigilante' ); ?></option>
4366 </select>
4367 </td>
4368 </tr>
4369 <tr>
4370 <th scope="row"><?php esc_html_e( 'Include Subdomains', 'vigilante' ); ?></th>
4371 <td>
4372 <label>
4373 <input type="checkbox" name="security_headers[hsts][include_subdomains]" value="1" <?php checked( ! empty( $options['hsts']['include_subdomains'] ) ); ?>>
4374 <?php esc_html_e( 'Apply HSTS to all subdomains', 'vigilante' ); ?>
4375 </label>
4376 </td>
4377 </tr>
4378 </table>
4379
4380 <h3 id="vigilante-section-headers-fingerprint"><?php esc_html_e( 'Server Identity', 'vigilante' ); ?></h3>
4381 <p class="description"><?php esc_html_e( 'Hide identifying information that servers expose in responses.', 'vigilante' ); ?></p>
4382 <table class="form-table">
4383 <tr>
4384 <th scope="row"><?php esc_html_e( 'Server Signature', 'vigilante' ); ?></th>
4385 <td>
4386 <label>
4387 <input type="checkbox" name="security_headers[hide_server_signature]" value="1" <?php checked( ! empty( $options['hide_server_signature'] ) ); ?>>
4388 <?php esc_html_e( 'Hide server signature (ServerSignature Off)', 'vigilante' ); ?>
4389 </label>
4390 </td>
4391 </tr>
4392 <tr>
4393 <th scope="row"><?php esc_html_e( 'Remove Fingerprinting Headers', 'vigilante' ); ?></th>
4394 <td>
4395 <label>
4396 <input type="checkbox" name="security_headers[remove_fingerprinting_headers]" value="1" <?php checked( ! empty( $options['remove_fingerprinting_headers'] ) ); ?>>
4397 <?php esc_html_e( 'Remove X-Powered-By and Server headers', 'vigilante' ); ?>
4398 </label>
4399 </td>
4400 </tr>
4401 </table>
4402 </div>
4403
4404 <?php $vg_cop = ( isset( $options['cross_origin_policies'] ) && is_array( $options['cross_origin_policies'] ) ) ? $options['cross_origin_policies'] : array(); ?>
4405 <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' : ''; ?>>
4406 <h2>
4407 <?php esc_html_e( 'Cross-Origin Policies', 'vigilante' ); ?>
4408 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
4409 </h2>
4410 <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>
4411
4412 <table class="form-table">
4413 <tr>
4414 <th scope="row"><label for="vigilante-f-security-headers-coop"><?php esc_html_e( 'Cross-Origin-Opener-Policy (COOP)', 'vigilante' ); ?></label></th>
4415 <td>
4416 <select id="vigilante-f-security-headers-coop" name="security_headers[cross_origin_policies][opener_policy]">
4417 <option value="" <?php selected( empty( $vg_cop['opener_policy'] ) ); ?>><?php esc_html_e( 'Disabled (header not sent)', 'vigilante' ); ?></option>
4418 <option value="unsafe-none" <?php selected( $vg_cop['opener_policy'] ?? '', 'unsafe-none' ); ?>>unsafe-none</option>
4419 <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>
4420 <option value="same-origin" <?php selected( $vg_cop['opener_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
4421 </select>
4422 <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>
4423 </td>
4424 </tr>
4425 <tr>
4426 <th scope="row"><label for="vigilante-f-security-headers-coep"><?php esc_html_e( 'Cross-Origin-Embedder-Policy (COEP)', 'vigilante' ); ?></label></th>
4427 <td>
4428 <select id="vigilante-f-security-headers-coep" name="security_headers[cross_origin_policies][embedder_policy]">
4429 <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>
4430 <option value="credentialless" <?php selected( $vg_cop['embedder_policy'] ?? '', 'credentialless' ); ?>>credentialless</option>
4431 <option value="require-corp" <?php selected( $vg_cop['embedder_policy'] ?? '', 'require-corp' ); ?>>require-corp</option>
4432 </select>
4433 <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>
4434 </td>
4435 </tr>
4436 <tr>
4437 <th scope="row"><label for="vigilante-f-security-headers-corp"><?php esc_html_e( 'Cross-Origin-Resource-Policy (CORP)', 'vigilante' ); ?></label></th>
4438 <td>
4439 <select id="vigilante-f-security-headers-corp" name="security_headers[cross_origin_policies][resource_policy]">
4440 <option value="" <?php selected( empty( $vg_cop['resource_policy'] ) ); ?>><?php esc_html_e( 'Disabled (header not sent)', 'vigilante' ); ?></option>
4441 <option value="same-site" <?php selected( $vg_cop['resource_policy'] ?? '', 'same-site' ); ?>>same-site</option>
4442 <option value="same-origin" <?php selected( $vg_cop['resource_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
4443 <option value="cross-origin" <?php selected( $vg_cop['resource_policy'] ?? '', 'cross-origin' ); ?>><?php esc_html_e( 'cross-origin (recommended)', 'vigilante' ); ?></option>
4444 </select>
4445 <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>
4446 </td>
4447 </tr>
4448 </table>
4449 </div>
4450
4451 <p class="submit vigilante-submit-buttons">
4452 <?php if ( ! $vg_shared_locked ) : ?>
4453 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4454 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4455 </button>
4456 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4457 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4458 </button>
4459 <?php endif; ?>
4460 <?php /* Testing what the server actually sends is read-only and useful from any site of a network. */ ?>
4461 <button type="button" class="button vigilante-test-headers">
4462 <?php esc_html_e( 'Test Headers', 'vigilante' ); ?>
4463 </button>
4464 </p>
4465 </form>
4466
4467 <div id="vigilante-headers-result"></div>
4468 <?php
4469 }
4470
4471 /**
4472 * Render REST API tab
4473 */
4474 private function render_tab_rest_api() {
4475 $is_disabled = $this->render_module_disabled_notice( 'rest_api_security' );
4476 $options = $this->settings->get_section( 'rest_api_security' );
4477 ?>
4478 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="rest_api_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
4479 <div id="vigilante-section-rest-api-main" class="vigilante-settings-section">
4480 <h2>
4481 <?php esc_html_e( 'REST API Security', 'vigilante' ); ?>
4482 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4483 </h2>
4484 <p><?php esc_html_e( 'Control access to WordPress REST API endpoints.', 'vigilante' ); ?></p>
4485
4486 <table class="form-table">
4487 <tr>
4488 <th scope="row"><label for="vigilante-f-rest-api-security-mode"><?php esc_html_e( 'Access Mode', 'vigilante' ); ?></label></th>
4489 <td>
4490 <select id="vigilante-f-rest-api-security-mode" name="rest_api_security[mode]">
4491 <option value="open" <?php selected( $options['mode'] ?? 'selective', 'open' ); ?>><?php esc_html_e( 'Open - Allow all requests', 'vigilante' ); ?></option>
4492 <option value="selective" <?php selected( $options['mode'] ?? 'selective', 'selective' ); ?>><?php esc_html_e( 'Selective - Protect sensitive endpoints', 'vigilante' ); ?></option>
4493 <option value="authenticated_only" <?php selected( $options['mode'] ?? 'selective', 'authenticated_only' ); ?>><?php esc_html_e( 'Authenticated - Require login for all', 'vigilante' ); ?></option>
4494 </select>
4495 <p class="description"><?php esc_html_e( 'Selective mode is recommended.', 'vigilante' ); ?></p>
4496 </td>
4497 </tr>
4498 <tr id="field-block-user-enumeration">
4499 <th scope="row"><?php esc_html_e( 'Block User Enumeration', 'vigilante' ); ?></th>
4500 <td>
4501 <label>
4502 <input type="checkbox" name="rest_api_security[block_user_enumeration]" value="1" <?php checked( ! empty( $options['block_user_enumeration'] ) ); ?>>
4503 <?php esc_html_e( 'Protect /wp/v2/users endpoint for unauthenticated users', 'vigilante' ); ?>
4504 </label>
4505 </td>
4506 </tr>
4507 <tr>
4508 <th scope="row"><?php esc_html_e( 'Disable JSONP', 'vigilante' ); ?></th>
4509 <td>
4510 <label>
4511 <input type="checkbox" name="rest_api_security[disable_jsonp]" value="1" <?php checked( ! empty( $options['disable_jsonp'] ) ); ?>>
4512 <?php esc_html_e( 'Disable JSONP support in REST API', 'vigilante' ); ?>
4513 </label>
4514 </td>
4515 </tr>
4516 </table>
4517 </div>
4518
4519 <p class="submit vigilante-submit-buttons">
4520 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4521 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4522 </button>
4523 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4524 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4525 </button>
4526 </p>
4527 </form>
4528 <?php
4529 }
4530
4531 /**
4532 * Render User Security tab
4533 */
4534 private function render_tab_users() {
4535 $is_disabled = $this->render_module_disabled_notice( 'user_security' );
4536 $options = $this->settings->get_section( 'user_security' );
4537 $monitoring = $options['admin_monitoring'] ?? array();
4538 $registration = $options['registration_approval'] ?? array();
4539 $session_limits = $options['session_limits'] ?? array();
4540 $password_exp = $options['password_expiration'] ?? array();
4541 $email_verify = $options['email_verification'] ?? array();
4542 ?>
4543
4544 <!-- ============================================================
4545 SETTINGS SECTION - Single form for all configuration
4546 ============================================================ -->
4547 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="user_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
4548
4549 <!-- Username & Password Protection -->
4550 <div id="vigilante-section-users-password" class="vigilante-settings-section">
4551 <h2>
4552 <?php esc_html_e( 'Username & password protection', 'vigilante' ); ?>
4553 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4554 </h2>
4555 <p><?php esc_html_e( 'Enforce secure username and password policies.', 'vigilante' ); ?></p>
4556
4557 <table class="form-table">
4558 <tr>
4559 <th scope="row"><?php esc_html_e( 'Block Insecure Usernames', 'vigilante' ); ?></th>
4560 <td>
4561 <label>
4562 <input type="checkbox" name="user_security[block_insecure_usernames]" value="1" <?php checked( ! empty( $options['block_insecure_usernames'] ) ); ?>>
4563 <?php esc_html_e( 'Prevent creation of users with common usernames (admin, administrator, etc.)', 'vigilante' ); ?>
4564 </label>
4565 </td>
4566 </tr>
4567 <?php
4568 $pw_policy = wp_parse_args(
4569 ( isset( $options['password_policy'] ) && is_array( $options['password_policy'] ) ) ? $options['password_policy'] : array(),
4570 array(
4571 'require_uppercase' => false,
4572 'require_lowercase' => false,
4573 'require_number' => false,
4574 'require_special' => false,
4575 'block_common' => true,
4576 'block_username' => true,
4577 'affected_roles' => array(),
4578 )
4579 );
4580 $pw_policy_roles = (array) $pw_policy['affected_roles'];
4581 ?>
4582 <tr>
4583 <th scope="row"><?php esc_html_e( 'Enforce Strong Passwords', 'vigilante' ); ?></th>
4584 <td>
4585 <label>
4586 <input type="checkbox" name="user_security[force_strong_passwords]" value="1" <?php checked( ! empty( $options['force_strong_passwords'] ) ); ?>>
4587 <?php esc_html_e( 'Check passwords against the requirements below when a user sets or changes one', 'vigilante' ); ?>
4588 </label>
4589 </td>
4590 </tr>
4591 <tr>
4592 <th scope="row"><label for="vigilante-f-user-security-min-password-length"><?php esc_html_e( 'Minimum Password Length', 'vigilante' ); ?></label></th>
4593 <td>
4594 <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">
4595 <?php esc_html_e( 'characters', 'vigilante' ); ?>
4596 </td>
4597 </tr>
4598 <tr>
4599 <th scope="row"><?php esc_html_e( 'Password Requirements', 'vigilante' ); ?></th>
4600 <td>
4601 <label style="display:block;margin-bottom:5px;">
4602 <input type="checkbox" name="user_security[password_policy][require_uppercase]" value="1" <?php checked( ! empty( $pw_policy['require_uppercase'] ) ); ?>>
4603 <?php esc_html_e( 'Require an uppercase letter (A-Z)', 'vigilante' ); ?>
4604 </label>
4605 <label style="display:block;margin-bottom:5px;">
4606 <input type="checkbox" name="user_security[password_policy][require_lowercase]" value="1" <?php checked( ! empty( $pw_policy['require_lowercase'] ) ); ?>>
4607 <?php esc_html_e( 'Require a lowercase letter (a-z)', 'vigilante' ); ?>
4608 </label>
4609 <label style="display:block;margin-bottom:5px;">
4610 <input type="checkbox" name="user_security[password_policy][require_number]" value="1" <?php checked( ! empty( $pw_policy['require_number'] ) ); ?>>
4611 <?php esc_html_e( 'Require a number (0-9)', 'vigilante' ); ?>
4612 </label>
4613 <label style="display:block;margin-bottom:5px;">
4614 <input type="checkbox" name="user_security[password_policy][require_special]" value="1" <?php checked( ! empty( $pw_policy['require_special'] ) ); ?>>
4615 <?php esc_html_e( 'Require a special character (!, @, #, ...)', 'vigilante' ); ?>
4616 </label>
4617 <label style="display:block;margin-bottom:5px;">
4618 <input type="checkbox" name="user_security[password_policy][block_common]" value="1" <?php checked( ! empty( $pw_policy['block_common'] ) ); ?>>
4619 <?php esc_html_e( 'Reject well-known common passwords', 'vigilante' ); ?>
4620 </label>
4621 <label style="display:block;margin-bottom:5px;">
4622 <input type="checkbox" name="user_security[password_policy][block_username]" value="1" <?php checked( ! empty( $pw_policy['block_username'] ) ); ?>>
4623 <?php esc_html_e( 'Do not allow the username inside the password', 'vigilante' ); ?>
4624 </label>
4625 <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>
4626 </td>
4627 </tr>
4628 <tr>
4629 <th scope="row"><?php esc_html_e( 'Apply Password Rules To', 'vigilante' ); ?></th>
4630 <td>
4631 <?php foreach ( wp_roles()->get_names() as $role_slug => $role_name ) : ?>
4632 <label style="display:block;margin-bottom:5px;">
4633 <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 ) ); ?>>
4634 <?php echo esc_html( translate_user_role( $role_name ) ); ?>
4635 </label>
4636 <?php endforeach; ?>
4637 <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>
4638 </td>
4639 </tr>
4640 <tr id="field-block-author-scanning">
4641 <th scope="row"><?php esc_html_e( 'Block Author Scanning', 'vigilante' ); ?></th>
4642 <td>
4643 <label>
4644 <input type="checkbox" name="user_security[block_author_scanning]" value="1" <?php checked( ! empty( $options['block_author_scanning'] ) ); ?>>
4645 <?php esc_html_e( 'Prevent username discovery via ?author=N URLs', 'vigilante' ); ?>
4646 </label>
4647 </td>
4648 </tr>
4649 <tr>
4650 <th scope="row"><?php esc_html_e( 'Display Name Protection', 'vigilante' ); ?></th>
4651 <td>
4652 <label>
4653 <input type="checkbox" name="user_security[prevent_display_name_login_match]" value="1" <?php checked( ! empty( $options['prevent_display_name_login_match'] ) ); ?>>
4654 <?php esc_html_e( 'Prevent users from saving a display name that matches their login username', 'vigilante' ); ?>
4655 </label>
4656 <p class="description"><?php esc_html_e( 'The display name is publicly visible and should not reveal the login username.', 'vigilante' ); ?></p>
4657 </td>
4658 </tr>
4659 </table>
4660 </div>
4661
4662 <!-- Admin Monitoring -->
4663 <div id="vigilante-section-users-admin-monitoring" class="vigilante-settings-section">
4664 <h2>
4665 <?php esc_html_e( 'Admin monitoring', 'vigilante' ); ?>
4666 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4667 </h2>
4668 <p><?php esc_html_e( 'Receive email alerts when administrator accounts are modified. All events are always logged to the Security Audit.', 'vigilante' ); ?></p>
4669
4670 <table class="form-table">
4671 <tr>
4672 <th scope="row"><?php esc_html_e( 'New Administrator Alert', 'vigilante' ); ?></th>
4673 <td>
4674 <label>
4675 <input type="checkbox" name="user_security[admin_monitoring][alert_new_admin]" value="1" <?php checked( ! empty( $monitoring['alert_new_admin'] ) ); ?>>
4676 <?php esc_html_e( 'Send email alert when a new administrator account is created', 'vigilante' ); ?>
4677 </label>
4678 </td>
4679 </tr>
4680 <tr>
4681 <th scope="row"><?php esc_html_e( 'Admin Email Change Alert', 'vigilante' ); ?></th>
4682 <td>
4683 <label>
4684 <input type="checkbox" name="user_security[admin_monitoring][alert_admin_email_change]" value="1" <?php checked( ! empty( $monitoring['alert_admin_email_change'] ) ); ?>>
4685 <?php esc_html_e( 'Send email alert when an administrator email address is changed', 'vigilante' ); ?>
4686 </label>
4687 </td>
4688 </tr>
4689 <tr>
4690 <th scope="row"><?php esc_html_e( 'Permission Elevation Alert', 'vigilante' ); ?></th>
4691 <td>
4692 <label>
4693 <input type="checkbox" name="user_security[admin_monitoring][alert_permission_elevation]" value="1" <?php checked( ! empty( $monitoring['alert_permission_elevation'] ) ); ?>>
4694 <?php esc_html_e( 'Send email alert when a user is elevated to administrator role', 'vigilante' ); ?>
4695 </label>
4696 </td>
4697 </tr>
4698 <tr>
4699 <th scope="row"><?php esc_html_e( 'Admin Password Change Alert', 'vigilante' ); ?></th>
4700 <td>
4701 <label>
4702 <input type="checkbox" name="user_security[admin_monitoring][alert_admin_password_change]" value="1" <?php checked( ! empty( $monitoring['alert_admin_password_change'] ) ); ?>>
4703 <?php esc_html_e( 'Send email alert when an administrator password is changed', 'vigilante' ); ?>
4704 </label>
4705 </td>
4706 </tr>
4707 </table>
4708
4709 <p class="description">
4710 <?php
4711 printf(
4712 /* translators: %s: Link to notification settings */
4713 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
4714 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
4715 );
4716 ?>
4717 </p>
4718 </div>
4719
4720 <!-- Registration Approval -->
4721 <div id="vigilante-section-users-registration" class="vigilante-settings-section">
4722 <h2>
4723 <?php esc_html_e( 'Registration approval', 'vigilante' ); ?>
4724 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4725 </h2>
4726 <p><?php esc_html_e( 'Require manual approval for new user registrations.', 'vigilante' ); ?></p>
4727
4728 <table class="form-table">
4729 <tr>
4730 <th scope="row"><?php esc_html_e( 'Enable Registration Approval', 'vigilante' ); ?></th>
4731 <td>
4732 <label>
4733 <input type="checkbox" name="user_security[registration_approval][enabled]" value="1" <?php checked( ! empty( $registration['enabled'] ) ); ?>>
4734 <?php esc_html_e( 'New users must be approved by an administrator before they can log in', 'vigilante' ); ?>
4735 </label>
4736 </td>
4737 </tr>
4738 <tr>
4739 <th scope="row"><?php esc_html_e( 'Notify Admin', 'vigilante' ); ?></th>
4740 <td>
4741 <label>
4742 <input type="checkbox" name="user_security[registration_approval][notify_admin]" value="1" <?php checked( ! empty( $registration['notify_admin'] ) ); ?>>
4743 <?php esc_html_e( 'Send email notification when a new user registers', 'vigilante' ); ?>
4744 </label>
4745 <p class="description"><?php esc_html_e( 'Disable on high-traffic sites to avoid email overload.', 'vigilante' ); ?></p>
4746 </td>
4747 </tr>
4748 <tr>
4749 <th scope="row"><label for="vigilante-f-user-security-registration-approval-auto-reject-days"><?php esc_html_e( 'Auto-reject After', 'vigilante' ); ?></label></th>
4750 <td>
4751 <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">
4752 <?php esc_html_e( 'days (0 = never)', 'vigilante' ); ?>
4753 <p class="description"><?php esc_html_e( 'Automatically reject pending registrations after this many days.', 'vigilante' ); ?></p>
4754 </td>
4755 </tr>
4756 </table>
4757 </div>
4758
4759 <!-- Session Limits -->
4760 <div id="vigilante-section-users-sessions" class="vigilante-settings-section">
4761 <h2>
4762 <?php esc_html_e( 'Session limits', 'vigilante' ); ?>
4763 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4764 </h2>
4765 <p><?php esc_html_e( 'Limit the number of simultaneous sessions per user.', 'vigilante' ); ?></p>
4766
4767 <table class="form-table">
4768 <tr>
4769 <th scope="row"><?php esc_html_e( 'Enable Session Limits', 'vigilante' ); ?></th>
4770 <td>
4771 <label>
4772 <input type="checkbox" name="user_security[session_limits][enabled]" value="1" <?php checked( ! empty( $session_limits['enabled'] ) ); ?>>
4773 <?php esc_html_e( 'Limit the number of active sessions per user', 'vigilante' ); ?>
4774 </label>
4775 </td>
4776 </tr>
4777 <tr>
4778 <th scope="row"><label for="vigilante-f-user-security-session-limits-max-sessions"><?php esc_html_e( 'Maximum Sessions', 'vigilante' ); ?></label></th>
4779 <td>
4780 <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">
4781 <?php esc_html_e( 'sessions per user', 'vigilante' ); ?>
4782 </td>
4783 </tr>
4784 <tr>
4785 <th scope="row"><label for="vigilante-f-user-security-session-limits-behavior"><?php esc_html_e( 'When Limit Exceeded', 'vigilante' ); ?></label></th>
4786 <td>
4787 <select id="vigilante-f-user-security-session-limits-behavior" name="user_security[session_limits][behavior]">
4788 <option value="block_new" <?php selected( ( $session_limits['behavior'] ?? 'close_oldest' ), 'block_new' ); ?>><?php esc_html_e( 'Block new login', 'vigilante' ); ?></option>
4789 <option value="close_oldest" <?php selected( ( $session_limits['behavior'] ?? 'close_oldest' ), 'close_oldest' ); ?>><?php esc_html_e( 'Close oldest session', 'vigilante' ); ?></option>
4790 </select>
4791 <p class="description"><?php esc_html_e( '"Close oldest" is recommended for security - ensures attackers cannot lock out legitimate users.', 'vigilante' ); ?></p>
4792 </td>
4793 </tr>
4794 <tr>
4795 <th scope="row"><?php esc_html_e( 'Exclude Administrators', 'vigilante' ); ?></th>
4796 <td>
4797 <label>
4798 <input type="checkbox" name="user_security[session_limits][exclude_admins]" value="1" <?php checked( ! empty( $session_limits['exclude_admins'] ) ); ?>>
4799 <?php esc_html_e( 'Do not apply session limits to administrators', 'vigilante' ); ?>
4800 </label>
4801 </td>
4802 </tr>
4803 </table>
4804 </div>
4805
4806 <!-- Password Expiration -->
4807 <div id="vigilante-section-users-password-exp" class="vigilante-settings-section">
4808 <h2>
4809 <?php esc_html_e( 'Password expiration', 'vigilante' ); ?>
4810 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4811 </h2>
4812 <p><?php esc_html_e( 'Force users to change their password periodically.', 'vigilante' ); ?></p>
4813
4814 <table class="form-table">
4815 <tr>
4816 <th scope="row"><?php esc_html_e( 'Enable Password Expiration', 'vigilante' ); ?></th>
4817 <td>
4818 <label>
4819 <input type="checkbox" name="user_security[password_expiration][enabled]" value="1" <?php checked( ! empty( $password_exp['enabled'] ) ); ?>>
4820 <?php esc_html_e( 'Force password change after a set number of days', 'vigilante' ); ?>
4821 </label>
4822 </td>
4823 </tr>
4824 <tr>
4825 <th scope="row"><label for="vigilante-f-user-security-password-expiration-expire-days"><?php esc_html_e( 'Expire After', 'vigilante' ); ?></label></th>
4826 <td>
4827 <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">
4828 <?php esc_html_e( 'days', 'vigilante' ); ?>
4829 <p class="description"><?php esc_html_e( 'PCI-DSS recommends 90 days.', 'vigilante' ); ?></p>
4830 </td>
4831 </tr>
4832 <tr>
4833 <th scope="row"><label for="vigilante-f-user-security-password-expiration-warning-days"><?php esc_html_e( 'Warning Period', 'vigilante' ); ?></label></th>
4834 <td>
4835 <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">
4836 <?php esc_html_e( 'days before expiration', 'vigilante' ); ?>
4837 <p class="description"><?php esc_html_e( 'Show warning notice this many days before password expires.', 'vigilante' ); ?></p>
4838 </td>
4839 </tr>
4840 <tr>
4841 <th scope="row"><label for="vigilante-f-user-security-password-expiration-password-history"><?php esc_html_e( 'Password History', 'vigilante' ); ?></label></th>
4842 <td>
4843 <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">
4844 <?php esc_html_e( 'passwords to remember', 'vigilante' ); ?>
4845 <p class="description"><?php esc_html_e( 'Prevent reusing recent passwords. Set to 0 to disable.', 'vigilante' ); ?></p>
4846 </td>
4847 </tr>
4848 <tr>
4849 <th scope="row"><?php esc_html_e( 'Email Reminder', 'vigilante' ); ?></th>
4850 <td>
4851 <label>
4852 <input type="checkbox" name="user_security[password_expiration][send_reminder]" value="1" <?php checked( ! empty( $password_exp['send_reminder'] ) ); ?>>
4853 <?php esc_html_e( 'Send email reminder when password is about to expire', 'vigilante' ); ?>
4854 </label>
4855 <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>
4856 </td>
4857 </tr>
4858 <tr>
4859 <th scope="row"><?php esc_html_e( 'Affected Roles', 'vigilante' ); ?></th>
4860 <td>
4861 <?php
4862 $affected_roles = $password_exp['affected_roles'] ?? array( 'administrator', 'editor' );
4863 $all_roles = wp_roles()->get_names();
4864 foreach ( $all_roles as $role_slug => $role_name ) :
4865 ?>
4866 <label style="display: block; margin-bottom: 5px;">
4867 <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 ) ); ?>>
4868 <?php echo esc_html( translate_user_role( $role_name ) ); ?>
4869 </label>
4870 <?php endforeach; ?>
4871 </td>
4872 </tr>
4873 <tr>
4874 <th scope="row"><?php esc_html_e( 'Exclude specific users', 'vigilante' ); ?></th>
4875 <td>
4876 <?php $pwexp_excluded = $password_exp['excluded_users'] ?? array(); ?>
4877 <div class="vigilante-2fa-user-search-container">
4878 <div class="vigilante-2fa-user-search">
4879 <span class="search-icon"></span>
4880 <input type="text"
4881 id="vigilante_pwexp_user_search"
4882 placeholder="<?php esc_attr_e( 'Search users by name or email...', 'vigilante' ); ?>"
4883 autocomplete="off">
4884 <div class="vigilante-pwexp-search-results"></div>
4885 </div>
4886 <div class="vigilante-pwexp-excluded-users">
4887 <?php
4888 foreach ( $pwexp_excluded as $pwexp_excluded_id ) :
4889 $excluded_user = get_user_by( 'ID', $pwexp_excluded_id );
4890 if ( ! $excluded_user ) {
4891 continue;
4892 }
4893 ?>
4894 <div class="vigilante-pwexp-excluded-user" data-user-id="<?php echo esc_attr( $pwexp_excluded_id ); ?>">
4895 <span class="user-display"><?php echo esc_html( $excluded_user->display_name . ' (' . $excluded_user->user_email . ')' ); ?></span>
4896 <button type="button" class="remove-user" aria-label="<?php esc_attr_e( 'Remove', 'vigilante' ); ?>">&times;</button>
4897 <input type="hidden" name="user_security[password_expiration][excluded_users][]" value="<?php echo esc_attr( $pwexp_excluded_id ); ?>">
4898 </div>
4899 <?php endforeach; ?>
4900 </div>
4901 </div>
4902 <p class="description"><?php esc_html_e( 'Listed users will be excluded from password expiration regardless of their role.', 'vigilante' ); ?></p>
4903 </td>
4904 </tr>
4905 </table>
4906 </div>
4907
4908 <!-- Email Verification -->
4909 <div id="vigilante-section-users-email-verify" class="vigilante-settings-section">
4910 <h2>
4911 <?php esc_html_e( 'Email verification', 'vigilante' ); ?>
4912 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4913 </h2>
4914 <p><?php esc_html_e( 'Require new users to verify their email address before logging in.', 'vigilante' ); ?></p>
4915
4916 <table class="form-table">
4917 <tr>
4918 <th scope="row"><?php esc_html_e( 'Enable Email Verification', 'vigilante' ); ?></th>
4919 <td>
4920 <label>
4921 <input type="checkbox" name="user_security[email_verification][enabled]" value="1" <?php checked( ! empty( $email_verify['enabled'] ) ); ?>>
4922 <?php esc_html_e( 'New users must verify their email before logging in', 'vigilante' ); ?>
4923 </label>
4924 </td>
4925 </tr>
4926 <tr>
4927 <th scope="row"><label for="vigilante-f-user-security-email-verification-token-expiry-hours"><?php esc_html_e( 'Link Expiration', 'vigilante' ); ?></label></th>
4928 <td>
4929 <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">
4930 <?php esc_html_e( 'hours', 'vigilante' ); ?>
4931 </td>
4932 </tr>
4933 <tr>
4934 <th scope="row"><?php esc_html_e( 'Allow Resend', 'vigilante' ); ?></th>
4935 <td>
4936 <label>
4937 <input type="checkbox" name="user_security[email_verification][allow_resend]" value="1" <?php checked( ! empty( $email_verify['allow_resend'] ) ); ?>>
4938 <?php esc_html_e( 'Allow users to request a new verification email', 'vigilante' ); ?>
4939 </label>
4940 </td>
4941 </tr>
4942 <tr>
4943 <th scope="row"><label for="vigilante-f-user-security-email-verification-auto-delete-days"><?php esc_html_e( 'Auto-delete Unverified', 'vigilante' ); ?></label></th>
4944 <td>
4945 <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">
4946 <?php esc_html_e( 'days (0 = never)', 'vigilante' ); ?>
4947 <p class="description"><?php esc_html_e( 'Automatically delete users who never verify their email.', 'vigilante' ); ?></p>
4948 </td>
4949 </tr>
4950 </table>
4951 </div>
4952
4953 <p class="submit vigilante-submit-buttons">
4954 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4955 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4956 </button>
4957 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4958 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4959 </button>
4960 </p>
4961 </form>
4962
4963 <!-- ============================================================
4964 TOOLS SECTION - Actions and utilities (no save button)
4965 ============================================================ -->
4966 <div class="vigilante-tools-section">
4967 <h2 class="vigilante-tools-header">
4968 <?php esc_html_e( 'User security tools', 'vigilante' ); ?>
4969 </h2>
4970
4971 <?php $this->render_user_actions_notice(); ?>
4972 <?php if ( ! $this->user_actions_locked() ) : ?>
4973
4974 <!-- Force Password Reset -->
4975 <div class="vigilante-tool-box">
4976 <h3><?php esc_html_e( 'Force password reset', 'vigilante' ); ?></h3>
4977 <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>
4978
4979 <!-- Reset Specific Users -->
4980 <div class="vigilante-password-reset-box">
4981 <h4><?php esc_html_e( 'Reset specific users', 'vigilante' ); ?></h4>
4982
4983 <div class="vigilante-user-search-wrapper">
4984 <input type="text" id="vigilante-password-reset-search" class="regular-text" placeholder="<?php esc_attr_e( 'Search by username, email, or display name...', 'vigilante' ); ?>">
4985 <div id="vigilante-password-reset-results" class="vigilante-user-search-results" style="display: none;"></div>
4986 </div>
4987
4988 <div id="vigilante-password-reset-selected" class="vigilante-selected-users" style="display: none;">
4989 <strong><?php esc_html_e( 'Selected Users:', 'vigilante' ); ?></strong>
4990 <ul class="vigilante-selected-users-list"></ul>
4991 </div>
4992
4993 <p class="description" style="margin-top: 15px;">
4994 <span class="dashicons dashicons-email-alt" style="color: #2271b1;"></span>
4995 <?php esc_html_e( 'Selected users will receive an email with a password reset link.', 'vigilante' ); ?>
4996 </p>
4997
4998 <p class="submit">
4999 <button type="button" id="vigilante-reset-selected-users" class="button button-primary" disabled>
5000 <?php esc_html_e( 'Force Reset for Selected Users', 'vigilante' ); ?>
5001 </button>
5002 </p>
5003 </div>
5004
5005 <!-- Reset by Role -->
5006 <div class="vigilante-password-reset-box" style="margin-top: 20px; padding-top: 20px; border-top: 1px solid #ddd;">
5007 <h4><?php esc_html_e( 'Reset by role', 'vigilante' ); ?></h4>
5008 <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>
5009
5010 <?php
5011 $wp_roles = wp_roles();
5012 $user_counts = count_users();
5013 $avail_roles = $user_counts['avail_roles'] ?? array();
5014 $current_user = wp_get_current_user();
5015 $current_roles = $current_user->roles;
5016 ?>
5017
5018 <fieldset class="vigilante-role-checkboxes" style="margin-top: 10px;">
5019 <?php foreach ( $wp_roles->roles as $role_slug => $role_data ) :
5020 $count = $avail_roles[ $role_slug ] ?? 0;
5021 if ( 0 === $count ) {
5022 continue;
5023 }
5024 $role_name = translate_user_role( $role_data['name'] );
5025 ?>
5026 <label style="display: block; margin-bottom: 6px;">
5027 <input type="checkbox"
5028 class="vigilante-reset-role-checkbox"
5029 value="<?php echo esc_attr( $role_slug ); ?>"
5030 data-count="<?php echo absint( $count ); ?>">
5031 <?php
5032 printf(
5033 /* translators: 1: Role name, 2: Number of users */
5034 '%1$s <span class="description">(%2$d)</span>',
5035 esc_html( $role_name ),
5036 absint( $count )
5037 );
5038 ?>
5039 <?php if ( in_array( $role_slug, $current_roles, true ) ) : ?>
5040 <em class="description"><?php esc_html_e( '(includes you)', 'vigilante' ); ?></em>
5041 <?php endif; ?>
5042 </label>
5043 <?php endforeach; ?>
5044 </fieldset>
5045
5046 <div id="vigilante-reset-role-summary" style="display: none; margin-top: 10px;">
5047 <p>
5048 <span class="dashicons dashicons-groups" style="color: #2271b1;"></span>
5049 <strong id="vigilante-reset-role-count">0</strong>
5050 <?php esc_html_e( 'user(s) will be affected.', 'vigilante' ); ?>
5051 </p>
5052 </div>
5053
5054 <div class="vigilante-password-reset-options" id="vigilante-reset-role-self-option" style="display: none; margin-top: 10px;">
5055 <label>
5056 <input type="checkbox" id="vigilante-reset-role-include-self" value="1">
5057 <?php esc_html_e( 'Include myself (your current session will end)', 'vigilante' ); ?>
5058 </label>
5059 </div>
5060
5061 <p class="submit">
5062 <button type="button" id="vigilante-reset-by-role" class="button button-primary" disabled>
5063 <?php esc_html_e( 'Force Reset for Selected Roles', 'vigilante' ); ?>
5064 </button>
5065 </p>
5066 </div>
5067
5068 <!-- Reset All Users -->
5069 <div class="vigilante-password-reset-box" style="margin-top: 20px; padding-top: 20px; border-top: 1px solid #ddd;">
5070 <h4><?php esc_html_e( 'Reset all users', 'vigilante' ); ?></h4>
5071
5072 <?php
5073 $total_users = count_users();
5074 $total_count = $total_users['total_users'];
5075 ?>
5076 <p>
5077 <?php
5078 printf(
5079 /* translators: %d: Number of users */
5080 esc_html__( 'This will affect %d user(s).', 'vigilante' ),
5081 absint( $total_count )
5082 );
5083 ?>
5084 </p>
5085
5086 <p class="description" style="color: #d63638;">
5087 <span class="dashicons dashicons-warning"></span>
5088 <?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' ); ?>
5089 </p>
5090
5091 <div class="vigilante-password-reset-options" style="margin-top: 10px;">
5092 <label>
5093 <input type="checkbox" id="vigilante-reset-all-include-self" value="1">
5094 <?php esc_html_e( 'Include myself (your current session will end)', 'vigilante' ); ?>
5095 </label>
5096 </div>
5097
5098 <p class="submit">
5099 <button type="button" id="vigilante-reset-all-users" class="button" style="color: #d63638; border-color: #d63638;">
5100 <?php esc_html_e( 'Force Reset for ALL Users', 'vigilante' ); ?>
5101 </button>
5102 </p>
5103 </div>
5104 </div>
5105
5106 <!-- Pending Registrations -->
5107 <?php
5108 $user_security = new Vigilante_User_Security( $this->settings, $this->activity_log );
5109 $pending_users = $user_security->get_pending_users();
5110 ?>
5111 <div id="vigilante-section-users-pending" class="vigilante-tool-box vigilante-pending-users-section">
5112 <h3>
5113 <?php esc_html_e( 'Pending registrations', 'vigilante' ); ?>
5114 <?php if ( count( $pending_users ) > 0 ) : ?>
5115 <span class="vigilante-badge vigilante-badge-warning"><?php echo esc_html( count( $pending_users ) ); ?></span>
5116 <?php endif; ?>
5117 </h3>
5118
5119 <?php if ( empty( $registration['enabled'] ) ) : ?>
5120 <p class="description">
5121 <span class="dashicons dashicons-info" style="color: #72aee6;"></span>
5122 <?php esc_html_e( 'Registration approval is disabled. Enable it in the settings above to require manual approval for new users.', 'vigilante' ); ?>
5123 </p>
5124 <?php elseif ( empty( $pending_users ) ) : ?>
5125 <div class="vigilante-no-lockouts">
5126 <span class="dashicons dashicons-yes-alt"></span>
5127 <p><?php esc_html_e( 'No pending registrations.', 'vigilante' ); ?></p>
5128 </div>
5129 <?php else : ?>
5130 <?php $this->render_user_actions_notice(); ?>
5131 <table class="wp-list-table widefat fixed striped vigilante-pending-users-table">
5132 <thead>
5133 <tr>
5134 <th><?php esc_html_e( 'User', 'vigilante' ); ?></th>
5135 <th><?php esc_html_e( 'Email', 'vigilante' ); ?></th>
5136 <th><?php esc_html_e( 'Registered', 'vigilante' ); ?></th>
5137 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5138 </tr>
5139 </thead>
5140 <tbody>
5141 <?php foreach ( $pending_users as $pending_user ) :
5142 $pending_since = get_user_meta( $pending_user->ID, 'vigilante_pending_since', true );
5143 ?>
5144 <tr data-user-id="<?php echo esc_attr( $pending_user->ID ); ?>">
5145 <td>
5146 <?php echo get_avatar( $pending_user->ID, 32 ); ?>
5147 <strong><?php echo esc_html( $pending_user->user_login ); ?></strong>
5148 </td>
5149 <td><?php echo esc_html( $pending_user->user_email ); ?></td>
5150 <td>
5151 <?php
5152 if ( $pending_since ) {
5153 /* translators: %s: Time ago */
5154 printf( esc_html__( '%s ago', 'vigilante' ), esc_html( human_time_diff( $pending_since ) ) );
5155 } else {
5156 echo esc_html( $pending_user->user_registered );
5157 }
5158 ?>
5159 </td>
5160 <td>
5161 <button type="button" class="button button-small vigilante-approve-user" data-user-id="<?php echo esc_attr( $pending_user->ID ); ?>" <?php disabled( $this->user_actions_locked() ); ?>>
5162 <?php esc_html_e( 'Approve', 'vigilante' ); ?>
5163 </button>
5164 <button type="button" class="button button-small vigilante-reject-user" data-user-id="<?php echo esc_attr( $pending_user->ID ); ?>" style="color: #d63638;" <?php disabled( $this->user_actions_locked() ); ?>>
5165 <?php esc_html_e( 'Reject', 'vigilante' ); ?>
5166 </button>
5167 </td>
5168 </tr>
5169 <?php endforeach; ?>
5170 </tbody>
5171 </table>
5172 <?php endif; ?>
5173 </div>
5174
5175 <!-- Active Sessions Management -->
5176 <div class="vigilante-tool-box vigilante-session-management-section">
5177 <h3><?php esc_html_e( 'Active sessions', 'vigilante' ); ?></h3>
5178 <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>
5179
5180 <!-- Current user sessions -->
5181 <h4><?php esc_html_e( 'Your sessions', 'vigilante' ); ?></h4>
5182 <?php
5183 $current_user_id = get_current_user_id();
5184 $my_sessions = $user_security->get_user_sessions( $current_user_id );
5185 $has_corrupted = $user_security->has_corrupted_sessions( $current_user_id );
5186 $raw_count = $user_security->get_raw_session_count( $current_user_id );
5187 ?>
5188
5189 <?php if ( $has_corrupted && $raw_count > 0 ) : ?>
5190 <div class="notice notice-warning inline" style="margin: 10px 0;">
5191 <p>
5192 <span class="dashicons dashicons-warning" style="color: #dba617;"></span>
5193 <?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' ); ?>
5194 </p>
5195 </div>
5196 <?php endif; ?>
5197
5198 <?php if ( empty( $my_sessions ) ) : ?>
5199 <p class="description"><?php esc_html_e( 'No active sessions found.', 'vigilante' ); ?></p>
5200 <?php if ( $has_corrupted ) : ?>
5201 <p style="margin-top: 10px;">
5202 <button type="button" class="button vigilante-revoke-other-sessions" data-user-id="<?php echo esc_attr( $current_user_id ); ?>">
5203 <?php esc_html_e( 'Clean Up Corrupted Sessions', 'vigilante' ); ?>
5204 </button>
5205 </p>
5206 <?php endif; ?>
5207 <?php else : ?>
5208 <div class="vigilante-paginated-section">
5209 <div class="vigilante-fi-pagination-wrap"></div>
5210 <table class="wp-list-table widefat fixed striped vigilante-sessions-table vigilante-fi-paginated">
5211 <thead>
5212 <tr>
5213 <th><?php esc_html_e( 'Browser', 'vigilante' ); ?></th>
5214 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
5215 <th><?php esc_html_e( 'Login Time', 'vigilante' ); ?></th>
5216 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5217 </tr>
5218 </thead>
5219 <tbody>
5220 <?php foreach ( $my_sessions as $session ) : ?>
5221 <tr data-token="<?php echo esc_attr( $session['token_hash'] ); ?>">
5222 <td><?php echo esc_html( $session['browser'] ); ?></td>
5223 <td><code><?php echo esc_html( $session['ip'] ); ?></code></td>
5224 <td>
5225 <?php
5226 if ( $session['login'] ) {
5227 /* translators: %s: Time ago */
5228 printf( esc_html__( '%s ago', 'vigilante' ), esc_html( human_time_diff( $session['login'] ) ) );
5229 } else {
5230 esc_html_e( 'Unknown', 'vigilante' );
5231 }
5232 ?>
5233 </td>
5234 <td>
5235 <?php if ( ! $session['is_current'] ) : ?>
5236 <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'] ); ?>">
5237 <?php esc_html_e( 'Revoke', 'vigilante' ); ?>
5238 </button>
5239 <?php else : ?>
5240 <span class="description"><?php esc_html_e( 'Current session', 'vigilante' ); ?></span>
5241 <?php endif; ?>
5242 </td>
5243 </tr>
5244 <?php endforeach; ?>
5245 </tbody>
5246 </table>
5247 </div>
5248
5249 <?php if ( count( $my_sessions ) > 1 || $has_corrupted ) : ?>
5250 <p style="margin-top: 10px;">
5251 <button type="button" class="button vigilante-revoke-other-sessions" data-user-id="<?php echo esc_attr( $current_user_id ); ?>">
5252 <?php esc_html_e( 'Revoke All Other Sessions', 'vigilante' ); ?>
5253 </button>
5254 </p>
5255 <?php endif; ?>
5256 <?php endif; ?>
5257
5258 <!-- Search user sessions (admin only) -->
5259 <h4 style="margin-top: 30px;"><?php esc_html_e( 'Manage user sessions', 'vigilante' ); ?></h4>
5260 <p class="description"><?php esc_html_e( 'Search for a user to view and manage their sessions.', 'vigilante' ); ?></p>
5261
5262 <div class="vigilante-user-search-wrapper" style="margin-top: 10px;">
5263 <input type="text" id="vigilante-session-user-search" class="regular-text" placeholder="<?php esc_attr_e( 'Search by username or email...', 'vigilante' ); ?>">
5264 <div id="vigilante-session-search-results" class="vigilante-user-search-results" style="display: none;"></div>
5265 </div>
5266
5267 <div id="vigilante-user-sessions-container" style="display: none; margin-top: 20px;">
5268 <h4 id="vigilante-sessions-user-name"></h4>
5269 <table class="wp-list-table widefat fixed striped vigilante-sessions-table">
5270 <thead>
5271 <tr>
5272 <th><?php esc_html_e( 'Browser', 'vigilante' ); ?></th>
5273 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
5274 <th><?php esc_html_e( 'Login Time', 'vigilante' ); ?></th>
5275 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5276 </tr>
5277 </thead>
5278 <tbody id="vigilante-user-sessions-list">
5279 </tbody>
5280 </table>
5281 <p style="margin-top: 10px;">
5282 <button type="button" class="button vigilante-revoke-all-user-sessions" style="color: #d63638;">
5283 <?php esc_html_e( 'Revoke All Sessions', 'vigilante' ); ?>
5284 </button>
5285 </p>
5286 </div>
5287 </div>
5288
5289 <?php endif; ?>
5290 </div>
5291 <?php
5292 }
5293
5294 /**
5295 * Render WordPress Hardening tab
5296 */
5297 private function render_tab_wp_hardening() {
5298 $is_disabled = $this->render_module_disabled_notice( 'wp_hardening' );
5299 $options = $this->settings->get_section( 'wp_hardening' );
5300 ?>
5301 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="wp_hardening" <?php echo $is_disabled ? 'inert' : ''; ?>>
5302 <!-- Database Hardening (outside form save flow - uses its own AJAX action) -->
5303 <?php $vg_shared_locked = $this->shared_files_locked(); ?>
5304 <?php $this->render_shared_files_notice(); ?>
5305 <div id="vigilante-section-hardening-database" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
5306 <h2>
5307 <?php esc_html_e( 'Database Hardening', 'vigilante' ); ?>
5308 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
5309 <span class="vigilante-method-badge config"><?php esc_html_e( 'WP-CONFIG', 'vigilante' ); ?></span>
5310 </h2>
5311 <p><?php esc_html_e( 'Change the database table prefix to prevent SQL injection attacks that target default WordPress tables.', 'vigilante' ); ?></p>
5312
5313 <?php
5314 $db_prefix = new Vigilante_Database_Prefix();
5315 $current_prefix = $db_prefix->get_current_prefix();
5316 $is_default = $db_prefix->is_default_prefix();
5317 ?>
5318
5319 <?php if ( is_multisite() && ! $vg_shared_locked ) : ?>
5320 <div class="notice notice-warning inline" style="margin:10px 0 16px;padding:8px 12px;">
5321 <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>
5322 </div>
5323 <?php endif; ?>
5324
5325 <table class="form-table">
5326 <tr>
5327 <th scope="row"><?php esc_html_e( 'Current prefix', 'vigilante' ); ?></th>
5328 <td>
5329 <code class="vigilante-db-current-prefix"><?php echo esc_html( $current_prefix ); ?></code>
5330 <?php if ( $is_default ) : ?>
5331 <span class="vigilante-inline-warning">
5332 <span class="dashicons dashicons-warning"></span>
5333 <?php esc_html_e( 'Default prefix detected. Changing it adds a layer of protection against automated SQL injection attacks.', 'vigilante' ); ?>
5334 </span>
5335 <?php else : ?>
5336 <span class="vigilante-inline-ok">
5337 <span class="dashicons dashicons-yes-alt"></span>
5338 <?php esc_html_e( 'Custom prefix in use.', 'vigilante' ); ?>
5339 </span>
5340 <?php endif; ?>
5341 </td>
5342 </tr>
5343 <tr>
5344 <th scope="row"><?php esc_html_e( 'New prefix', 'vigilante' ); ?></th>
5345 <td>
5346 <div class="vigilante-db-prefix-row">
5347 <code class="vigilante-db-new-prefix" id="vigilante-new-prefix"><?php echo esc_html( $db_prefix->generate_prefix() ); ?></code>
5348 <button type="button" class="button button-small vigilante-db-regenerate-prefix" title="<?php esc_attr_e( 'Generate new prefix', 'vigilante' ); ?>">
5349 <span class="dashicons dashicons-update"></span>
5350 </button>
5351 </div>
5352 </td>
5353 </tr>
5354 <tr>
5355 <th scope="row"></th>
5356 <td>
5357 <div class="vigilante-db-prefix-confirm">
5358 <label>
5359 <input type="checkbox" id="vigilante-prefix-backup-confirm">
5360 <?php esc_html_e( 'I understand this operation is irreversible and I have a current database backup', 'vigilante' ); ?>
5361 </label>
5362 <p class="description">
5363 <?php
5364 printf(
5365 /* translators: %s: Link to tools tab */
5366 esc_html__( 'Need a backup? %s first.', 'vigilante' ),
5367 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Download a database backup', 'vigilante' ) . '</a>'
5368 );
5369 ?>
5370 </p>
5371 </div>
5372 <button type="button" class="button button-primary vigilante-db-change-prefix" disabled data-original-text="<?php esc_attr_e( 'Change Database Prefix', 'vigilante' ); ?>">
5373 <?php esc_html_e( 'Change Database Prefix', 'vigilante' ); ?>
5374 </button>
5375 </td>
5376 </tr>
5377 </table>
5378 </div>
5379
5380 <!-- wp-config Security -->
5381 <?php
5382 $vg_shared_locked = $this->shared_files_locked();
5383 // Paint what is actually in force, not this site's unused copy.
5384 $vg_local_options = $options;
5385 $options = $this->get_section_for_display( 'wp_hardening' );
5386 ?>
5387 <?php $this->render_shared_files_notice(); ?>
5388 <div id="vigilante-section-hardening-wpconfig" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
5389 <h2>
5390 <?php esc_html_e( 'wp-config.php Security', 'vigilante' ); ?>
5391 <span class="vigilante-method-badge config"><?php esc_html_e( 'WP-CONFIG', 'vigilante' ); ?></span>
5392 </h2>
5393 <p><?php esc_html_e( 'Security constants added directly to wp-config.php file.', 'vigilante' ); ?></p>
5394
5395 <table class="form-table">
5396 <tr>
5397 <th scope="row"><?php esc_html_e( 'Disable File Editor', 'vigilante' ); ?></th>
5398 <td>
5399 <label>
5400 <input type="checkbox" name="wp_hardening[disallow_file_edit]" value="1" <?php checked( ! empty( $options['disallow_file_edit'] ) ); ?>>
5401 <?php esc_html_e( 'Disable plugin and theme editor in admin (DISALLOW_FILE_EDIT)', 'vigilante' ); ?>
5402 </label>
5403 </td>
5404 </tr>
5405 <tr>
5406 <th scope="row"><?php esc_html_e( 'Disable File Modifications', 'vigilante' ); ?></th>
5407 <td>
5408 <label>
5409 <input type="checkbox" name="wp_hardening[disallow_file_mods]" value="1" <?php checked( ! empty( $options['disallow_file_mods'] ) ); ?>>
5410 <?php esc_html_e( 'Disable all file modifications including updates (DISALLOW_FILE_MODS)', 'vigilante' ); ?>
5411 </label>
5412 <p class="description"><?php esc_html_e( '&#9888; Warning: This prevents automatic updates.', 'vigilante' ); ?></p>
5413 </td>
5414 </tr>
5415 <tr id="field-force-ssl-admin">
5416 <th scope="row"><?php esc_html_e( 'Force SSL Admin', 'vigilante' ); ?></th>
5417 <td>
5418 <label>
5419 <input type="checkbox" name="wp_hardening[force_ssl_admin]" value="1" <?php checked( ! empty( $options['force_ssl_admin'] ) ); ?>>
5420 <?php esc_html_e( 'Force HTTPS for admin area (FORCE_SSL_ADMIN)', 'vigilante' ); ?>
5421 </label>
5422 <p class="description"><?php esc_html_e( '&#9888; Warning: Only enable if your site fully supports HTTPS.', 'vigilante' ); ?></p>
5423 </td>
5424 </tr>
5425 <tr id="field-wp-debug">
5426 <th scope="row"><?php esc_html_e( 'Hide PHP errors from visitors', 'vigilante' ); ?></th>
5427 <td>
5428 <label>
5429 <input type="checkbox" name="wp_hardening[wp_debug]" value="1" <?php checked( ! empty( $options['wp_debug'] ) ); ?>>
5430 <?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' ); ?>
5431 </label>
5432 </td>
5433 </tr>
5434 <tr id="field-disable-wp-cron">
5435 <th scope="row"><?php esc_html_e( 'Disable WP Cron', 'vigilante' ); ?></th>
5436 <td>
5437 <label>
5438 <input type="checkbox" name="wp_hardening[disable_wp_cron]" value="1" <?php checked( ! empty( $options['disable_wp_cron'] ) ); ?>>
5439 <?php esc_html_e( 'Disable WordPress\'s page-view cron trigger (DISABLE_WP_CRON)', 'vigilante' ); ?>
5440 </label>
5441 <p class="description"><?php
5442 printf(
5443 /* translators: 1: opening <strong>, 2: closing </strong>, 3: opening <code>, 4: closing </code> */
5444 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' ),
5445 '<strong>',
5446 '</strong>',
5447 '<code>',
5448 '</code>'
5449 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
5450 ?></p>
5451 </td>
5452 </tr>
5453 </table>
5454 </div>
5455 <?php $options = $vg_local_options; ?>
5456
5457 <!-- Comment Security -->
5458 <div id="vigilante-section-hardening-xmlrpc" class="vigilante-settings-section">
5459 <h2>
5460 <?php esc_html_e( 'XML-RPC', 'vigilante' ); ?>
5461 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5462 </h2>
5463 <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>
5464
5465 <table class="form-table">
5466 <tr id="field-disable-xmlrpc">
5467 <th scope="row"><label for="vigilante-f-wp-hardening-xmlrpc-mode"><?php esc_html_e( 'XML-RPC access', 'vigilante' ); ?></label></th>
5468 <td>
5469 <?php $vig_xmlrpc_mode = Vigilante_Comment_Security::resolve_xmlrpc_mode( $this->settings ); ?>
5470 <select id="vigilante-f-wp-hardening-xmlrpc-mode" name="wp_hardening[xmlrpc_mode]">
5471 <option value="none" <?php selected( $vig_xmlrpc_mode, 'none' ); ?>>
5472 <?php esc_html_e( 'Leave XML-RPC enabled', 'vigilante' ); ?>
5473 </option>
5474 <option value="pingback" <?php selected( $vig_xmlrpc_mode, 'pingback' ); ?>>
5475 <?php esc_html_e( 'Block the pingback methods only', 'vigilante' ); ?>
5476 </option>
5477 <option value="full" <?php selected( $vig_xmlrpc_mode, 'full' ); ?>>
5478 <?php esc_html_e( 'Disable XML-RPC completely (recommended)', 'vigilante' ); ?>
5479 </option>
5480 </select>
5481 <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>
5482 </td>
5483 </tr>
5484 </table>
5485 </div>
5486
5487 <div id="vigilante-section-hardening-comments" class="vigilante-settings-section">
5488 <h2>
5489 <?php esc_html_e( 'Comment Security', 'vigilante' ); ?>
5490 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5491 <span class="vigilante-method-badge settings"><?php esc_html_e( 'Settings', 'vigilante' ); ?></span>
5492 </h2>
5493 <p><?php esc_html_e( 'Comment protection using WordPress settings and PHP hooks.', 'vigilante' ); ?></p>
5494
5495 <table class="form-table">
5496 <tr>
5497 <th scope="row"><?php esc_html_e( 'Disable Pingbacks', 'vigilante' ); ?></th>
5498 <td>
5499 <label>
5500 <input type="checkbox" name="wp_hardening[disable_pingbacks]" value="1" <?php checked( ! empty( $options['disable_pingbacks'] ) ); ?>>
5501 <?php esc_html_e( 'Disable pingbacks (commonly exploited for DDoS)', 'vigilante' ); ?>
5502 </label>
5503 </td>
5504 </tr>
5505 <tr>
5506 <th scope="row"><?php esc_html_e( 'Disable Trackbacks', 'vigilante' ); ?></th>
5507 <td>
5508 <label>
5509 <input type="checkbox" name="wp_hardening[disable_trackbacks]" value="1" <?php checked( ! empty( $options['disable_trackbacks'] ) ); ?>>
5510 <?php esc_html_e( 'Disable trackbacks (rarely used legitimately)', 'vigilante' ); ?>
5511 </label>
5512 </td>
5513 </tr>
5514 <tr>
5515 <th scope="row"><?php esc_html_e( 'Require Moderation', 'vigilante' ); ?></th>
5516 <td>
5517 <label>
5518 <input type="checkbox" name="wp_hardening[require_comment_moderation]" value="1" <?php checked( ! empty( $options['require_comment_moderation'] ) ); ?>>
5519 <?php esc_html_e( 'All comments must be manually approved', 'vigilante' ); ?>
5520 </label>
5521 </td>
5522 </tr>
5523 <tr>
5524 <th scope="row"><?php esc_html_e( 'Close Old Comments', 'vigilante' ); ?></th>
5525 <td>
5526 <label>
5527 <input type="checkbox" name="wp_hardening[close_old_comments]" value="1" <?php checked( ! empty( $options['close_old_comments'] ) ); ?>>
5528 <?php esc_html_e( 'Automatically close comments on old posts after', 'vigilante' ); ?>
5529 </label>
5530 <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">
5531 <label for="vigilante-f-wp-hardening-close-comments-after-days"><?php esc_html_e( 'days', 'vigilante' ); ?></label>
5532 </td>
5533 </tr>
5534 <tr>
5535 <th scope="row"><?php esc_html_e( 'Honeypot Protection', 'vigilante' ); ?></th>
5536 <td>
5537 <label>
5538 <input type="checkbox" name="wp_hardening[honeypot_comments]" value="1" <?php checked( ! empty( $options['honeypot_comments'] ) ); ?>>
5539 <?php esc_html_e( 'Add hidden honeypot field to catch bots', 'vigilante' ); ?>
5540 </label>
5541 </td>
5542 </tr>
5543 </table>
5544 </div>
5545
5546 <!-- Head Cleaner -->
5547 <div id="vigilante-section-hardening-headers" class="vigilante-settings-section">
5548 <h2>
5549 <?php esc_html_e( 'Header Cleanup', 'vigilante' ); ?>
5550 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5551 </h2>
5552 <p><?php esc_html_e( 'Remove meta tags from HTML head.', 'vigilante' ); ?></p>
5553
5554 <table class="form-table">
5555 <tr>
5556 <th scope="row"><?php esc_html_e( 'Remove Generator', 'vigilante' ); ?></th>
5557 <td>
5558 <label>
5559 <input type="checkbox" name="wp_hardening[remove_wp_generator]" value="1" <?php checked( ! empty( $options['remove_wp_generator'] ) ); ?>>
5560 <?php esc_html_e( 'Remove WordPress version from HTML head', 'vigilante' ); ?>
5561 </label>
5562 </td>
5563 </tr>
5564 <tr id="field-remove-wp-version-assets">
5565 <th scope="row"><?php esc_html_e( 'Remove version from assets', 'vigilante' ); ?></th>
5566 <td>
5567 <label>
5568 <input type="checkbox" name="wp_hardening[remove_wp_version_assets]" value="1" <?php checked( ! empty( $options['remove_wp_version_assets'] ) ); ?>>
5569 <?php esc_html_e( 'Remove WordPress version from script/style URLs (?ver=)', 'vigilante' ); ?>
5570 </label>
5571 <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>
5572 </td>
5573 </tr>
5574 <tr>
5575 <th scope="row"><?php esc_html_e( 'Remove RSD Link', 'vigilante' ); ?></th>
5576 <td>
5577 <label>
5578 <input type="checkbox" name="wp_hardening[remove_rsd_link]" value="1" <?php checked( ! empty( $options['remove_rsd_link'] ) ); ?>>
5579 <?php esc_html_e( 'Remove Really Simple Discovery link', 'vigilante' ); ?>
5580 </label>
5581 </td>
5582 </tr>
5583 <tr>
5584 <th scope="row"><?php esc_html_e( 'Remove WLW Manifest', 'vigilante' ); ?></th>
5585 <td>
5586 <label>
5587 <input type="checkbox" name="wp_hardening[remove_wlw_manifest]" value="1" <?php checked( ! empty( $options['remove_wlw_manifest'] ) ); ?>>
5588 <?php esc_html_e( 'Remove Windows Live Writer manifest link', 'vigilante' ); ?>
5589 </label>
5590 </td>
5591 </tr>
5592 <tr>
5593 <th scope="row"><?php esc_html_e( 'Remove Shortlink', 'vigilante' ); ?></th>
5594 <td>
5595 <label>
5596 <input type="checkbox" name="wp_hardening[remove_shortlink]" value="1" <?php checked( ! empty( $options['remove_shortlink'] ) ); ?>>
5597 <?php esc_html_e( 'Remove shortlink tag from header', 'vigilante' ); ?>
5598 </label>
5599 </td>
5600 </tr>
5601 <tr>
5602 <th scope="row"><?php esc_html_e( 'Remove REST API Link', 'vigilante' ); ?></th>
5603 <td>
5604 <label>
5605 <input type="checkbox" name="wp_hardening[remove_rest_api_link]" value="1" <?php checked( ! empty( $options['remove_rest_api_link'] ) ); ?>>
5606 <?php esc_html_e( 'Remove REST API discovery link from header', 'vigilante' ); ?>
5607 </label>
5608 <p class="description"><?php esc_html_e( '&#9888; Notice: Some plugins may need this link.', 'vigilante' ); ?></p>
5609 </td>
5610 </tr>
5611 </table>
5612 </div>
5613
5614 <!-- Feed Manager -->
5615 <div id="vigilante-section-hardening-rss" class="vigilante-settings-section">
5616 <h2>
5617 <?php esc_html_e( 'RSS Feed Settings', 'vigilante' ); ?>
5618 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5619 </h2>
5620 <p><?php esc_html_e( 'Control RSS/Atom feeds.', 'vigilante' ); ?></p>
5621
5622 <table class="form-table">
5623 <tr>
5624 <th scope="row"><?php esc_html_e( 'Disable Feeds', 'vigilante' ); ?></th>
5625 <td>
5626 <label>
5627 <input type="checkbox" name="wp_hardening[disable_feeds]" value="1" <?php checked( ! empty( $options['disable_feeds'] ) ); ?>>
5628 <?php esc_html_e( 'Completely disable RSS/Atom feeds', 'vigilante' ); ?>
5629 </label>
5630 </td>
5631 </tr>
5632 <tr>
5633 <th scope="row"><?php esc_html_e( 'Disable If No Content', 'vigilante' ); ?></th>
5634 <td>
5635 <label>
5636 <input type="checkbox" name="wp_hardening[disable_if_no_content]" value="1" <?php checked( ! empty( $options['disable_if_no_content'] ) ); ?>>
5637 <?php esc_html_e( 'Only disable feeds if site has no published posts', 'vigilante' ); ?>
5638 </label>
5639 </td>
5640 </tr>
5641 <tr>
5642 <th scope="row"><?php esc_html_e( 'Remove Feed Version', 'vigilante' ); ?></th>
5643 <td>
5644 <label>
5645 <input type="checkbox" name="wp_hardening[remove_feed_version]" value="1" <?php checked( ! empty( $options['remove_feed_version'] ) ); ?>>
5646 <?php esc_html_e( 'Remove WordPress version from feed generator tag', 'vigilante' ); ?>
5647 </label>
5648 </td>
5649 </tr>
5650 </table>
5651 </div>
5652
5653 <p class="submit vigilante-submit-buttons">
5654 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5655 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5656 </button>
5657 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5658 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5659 </button>
5660 </p>
5661 </form>
5662 <?php
5663 }
5664
5665 /**
5666 * Render activity log tab
5667 */
5668 private function render_tab_activity_log() {
5669 $is_disabled = $this->render_module_disabled_notice( 'activity_log' );
5670 $options = $this->settings->get_section( 'activity_log' );
5671 ?>
5672 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="activity_log" <?php echo $is_disabled ? 'inert' : ''; ?>>
5673 <div id="vigilante-section-audit-settings" class="vigilante-settings-section">
5674 <h2>
5675 <?php esc_html_e( 'Security Audit Settings', 'vigilante' ); ?>
5676 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5677 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
5678 </h2>
5679 <p><?php esc_html_e( 'Security event logging and auditing.', 'vigilante' ); ?></p>
5680
5681 <table class="form-table">
5682 <tr>
5683 <th scope="row"><?php esc_html_e( 'Retention', 'vigilante' ); ?></th>
5684 <td>
5685 <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">
5686 <label for="vigilante-f-activity-log-retention-days"><?php esc_html_e( 'days', 'vigilante' ); ?></label>
5687 &nbsp;&nbsp;
5688 <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">
5689 <label for="vigilante-f-activity-log-max-entries"><?php esc_html_e( 'max entries', 'vigilante' ); ?></label>
5690 <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>
5691 </td>
5692 </tr>
5693 <tr>
5694 <th scope="row"><?php esc_html_e( 'Events to Log', 'vigilante' ); ?></th>
5695 <td>
5696 <fieldset style="display:grid; grid-template-columns:repeat(auto-fit, minmax(240px, 1fr)); gap:6px 24px; max-width:600px;">
5697 <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>
5698 <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>
5699 <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>
5700 <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>
5701 <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>
5702 <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>
5703 <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>
5704 <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>
5705 <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>
5706 <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>
5707 </fieldset>
5708 <div class="notice notice-info inline" style="margin:10px 0 0;padding:8px 12px;">
5709 <p style="margin:0;">
5710 <?php esc_html_e( 'Firewall blocks, security events, and Vigilant settings changes are always logged regardless of the above selections.', 'vigilante' ); ?>
5711 </p>
5712 </div>
5713 </td>
5714 </tr>
5715 <tr>
5716 <th scope="row"><label for="vigilante-f-activity-log-tracked-options"><?php esc_html_e( 'Option Tracking', 'vigilante' ); ?></label></th>
5717 <td>
5718 <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>
5719 <br>
5720 <label><?php esc_html_e( 'Additional options to track:', 'vigilante' ); ?></label><br>
5721 <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>
5722 <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>
5723 </td>
5724 </tr>
5725 <tr>
5726 <th scope="row"><?php esc_html_e( 'Exclusions', 'vigilante' ); ?></th>
5727 <td>
5728 <div style="display:grid; grid-template-columns:repeat(auto-fit, minmax(220px, 1fr)); gap:16px; max-width:600px;">
5729 <div>
5730 <label for="vigilante-f-activity-log-excluded-users"><?php esc_html_e( 'Excluded user IDs:', 'vigilante' ); ?></label><br>
5731 <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>
5732 <p class="description"><?php esc_html_e( 'One user ID per line. Actions by these users will not be logged.', 'vigilante' ); ?></p>
5733 </div>
5734 <div>
5735 <label for="vigilante-f-activity-log-excluded-ips"><?php esc_html_e( 'Excluded IPs:', 'vigilante' ); ?></label><br>
5736 <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>
5737 <p class="description"><?php esc_html_e( 'One IP per line. Requests from these IPs will not be logged.', 'vigilante' ); ?></p>
5738 </div>
5739 </div>
5740 </td>
5741 </tr>
5742 </table>
5743 </div>
5744
5745 <p class="submit vigilante-submit-buttons">
5746 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5747 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5748 </button>
5749 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5750 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5751 </button>
5752 </p>
5753 </form>
5754
5755 <?php
5756 // Audit Alerts — alerting layer on top of Security Audit. Its own
5757 // settings section and form, rendered right after the logging settings
5758 // so the tab reads as "log this, exclude that, and alert me about this".
5759 $alerts = $this->settings->get_section( 'audit_alerts' );
5760 $immediate = isset( $alerts['immediate'] ) ? $alerts['immediate'] : array();
5761 $threshold = isset( $alerts['threshold'] ) ? $alerts['threshold'] : array();
5762 $alert_severity = isset( $immediate['min_severity'] ) ? $immediate['min_severity'] : 'critical';
5763 $alert_window = isset( $threshold['window'] ) ? $threshold['window'] : '1h';
5764 $threshold_cats = isset( $threshold['categories'] ) ? (array) $threshold['categories'] : array();
5765 $cat_labels = Vigilante_Audit_Alerts::category_labels();
5766 ?>
5767 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="audit_alerts" <?php echo $is_disabled ? 'inert' : ''; ?>>
5768 <div id="vigilante-section-audit-alerts" class="vigilante-settings-section">
5769 <h2>
5770 <?php esc_html_e( 'Audit Alerts', 'vigilante' ); ?>
5771 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5772 </h2>
5773 <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>
5774
5775 <table class="form-table">
5776 <tr id="field-audit-alerts-immediate">
5777 <th scope="row"><?php esc_html_e( 'Immediate alerts', 'vigilante' ); ?></th>
5778 <td>
5779 <label>
5780 <input type="checkbox" name="audit_alerts[immediate][enabled]" value="1" <?php checked( ! empty( $immediate['enabled'] ) ); ?>>
5781 <?php esc_html_e( 'Email me as soon as a serious event is logged', 'vigilante' ); ?>
5782 </label>
5783 <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>
5784 </td>
5785 </tr>
5786 <tr>
5787 <th scope="row"><label for="vigilante-f-audit-alerts-immediate-min-severity"><?php esc_html_e( 'Alert on severity', 'vigilante' ); ?></label></th>
5788 <td>
5789 <select id="vigilante-f-audit-alerts-immediate-min-severity" name="audit_alerts[immediate][min_severity]">
5790 <option value="critical" <?php selected( $alert_severity, 'critical' ); ?>><?php esc_html_e( 'Critical only (recommended)', 'vigilante' ); ?></option>
5791 <option value="warning" <?php selected( $alert_severity, 'warning' ); ?>><?php esc_html_e( 'Warning and Critical', 'vigilante' ); ?></option>
5792 </select>
5793 <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>
5794 </td>
5795 </tr>
5796 <tr id="field-audit-alerts-threshold">
5797 <th scope="row"><?php esc_html_e( 'Threshold alerts', 'vigilante' ); ?></th>
5798 <td>
5799 <label>
5800 <input type="checkbox" name="audit_alerts[threshold][enabled]" value="1" <?php checked( ! empty( $threshold['enabled'] ) ); ?>>
5801 <?php esc_html_e( 'Email me when a category spikes within a time window', 'vigilante' ); ?>
5802 </label>
5803 <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>
5804 </td>
5805 </tr>
5806 <tr>
5807 <th scope="row"><label for="vigilante-f-audit-alerts-threshold-window"><?php esc_html_e( 'Time window', 'vigilante' ); ?></label></th>
5808 <td>
5809 <select id="vigilante-f-audit-alerts-threshold-window" name="audit_alerts[threshold][window]">
5810 <option value="30m" <?php selected( $alert_window, '30m' ); ?>><?php esc_html_e( '30 minutes', 'vigilante' ); ?></option>
5811 <option value="1h" <?php selected( $alert_window, '1h' ); ?>><?php esc_html_e( '1 hour', 'vigilante' ); ?></option>
5812 <option value="6h" <?php selected( $alert_window, '6h' ); ?>><?php esc_html_e( '6 hours', 'vigilante' ); ?></option>
5813 <option value="24h" <?php selected( $alert_window, '24h' ); ?>><?php esc_html_e( '24 hours', 'vigilante' ); ?></option>
5814 </select>
5815 <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>
5816 </td>
5817 </tr>
5818 <tr>
5819 <th scope="row"><?php esc_html_e( 'Thresholds per category', 'vigilante' ); ?></th>
5820 <td>
5821 <fieldset style="display:grid; grid-template-columns:repeat(auto-fit, minmax(200px, 1fr)); gap:8px 24px; max-width:760px;">
5822 <?php
5823 foreach ( $cat_labels as $cat_slug => $cat_label ) :
5824 $cat_value = isset( $threshold_cats[ $cat_slug ] ) ? (int) $threshold_cats[ $cat_slug ] : 0;
5825 ?>
5826 <label style="display:flex;align-items:center;gap:8px;justify-content:space-between;">
5827 <span><?php echo esc_html( $cat_label ); ?></span>
5828 <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">
5829 </label>
5830 <?php endforeach; ?>
5831 </fieldset>
5832 <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>
5833 </td>
5834 </tr>
5835 <tr>
5836 <th scope="row"><?php esc_html_e( "Don't repeat alerts", 'vigilante' ); ?></th>
5837 <td>
5838 <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">
5839 <label for="vigilante-f-audit-alerts-cooldown-minutes"><?php esc_html_e( 'minutes', 'vigilante' ); ?></label>
5840 <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>
5841 </td>
5842 </tr>
5843
5844 <tr>
5845 <th scope="row"><?php esc_html_e( 'Recipients', 'vigilante' ); ?></th>
5846 <td>
5847 <p class="description" style="margin-top:0;">
5848 <?php
5849 printf(
5850 /* translators: %s: Link to notification settings */
5851 esc_html__( 'Alerts go to the recipients configured in %s.', 'vigilante' ),
5852 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
5853 );
5854 ?>
5855 </p>
5856 <p style="margin:8px 0 0;">
5857 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
5858 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
5859 </button>
5860 <span class="vigilante-test-email-result" style="margin-left:8px;"></span>
5861 </p>
5862 <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>
5863 </td>
5864 </tr>
5865 </table>
5866 </div>
5867
5868 <p class="submit vigilante-submit-buttons">
5869 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5870 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5871 </button>
5872 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5873 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5874 </button>
5875 </p>
5876 </form>
5877
5878 <div id="vigilante-section-audit-recent" class="vigilante-settings-section">
5879 <h2><?php esc_html_e( 'Recent Activity', 'vigilante' ); ?></h2>
5880
5881 <?php
5882 $logs = $this->activity_log->get_logs( array( 'per_page' => 20 ) );
5883 $total_logs = $this->activity_log->get_logs_count();
5884
5885 // Label maps for translated display
5886 $type_labels = array(
5887 'login' => __( 'Login', 'vigilante' ),
5888 'user' => __( 'User', 'vigilante' ),
5889 'content' => __( 'Content', 'vigilante' ),
5890 'plugin' => __( 'Plugin', 'vigilante' ),
5891 'theme' => __( 'Theme', 'vigilante' ),
5892 'settings' => __( 'Settings', 'vigilante' ),
5893 'comment' => __( 'Comment', 'vigilante' ),
5894 'media' => __( 'Media', 'vigilante' ),
5895 'firewall' => __( 'Firewall', 'vigilante' ),
5896 'file' => __( 'File', 'vigilante' ),
5897 'security' => __( 'Security', 'vigilante' ),
5898 'system' => __( 'System', 'vigilante' ),
5899 );
5900 $severity_labels = array(
5901 'info' => __( 'Info', 'vigilante' ),
5902 'warning' => __( 'Warning', 'vigilante' ),
5903 'critical' => __( 'Critical', 'vigilante' ),
5904 );
5905
5906 $firewall_options = $this->settings->get_section( 'firewall' );
5907 $ip_whitelist = $firewall_options['ip_whitelist'] ?? array();
5908 $ip_blacklist = $firewall_options['ip_blacklist'] ?? array();
5909 $ua_whitelist = $firewall_options['ua_whitelist'] ?? array();
5910 $ua_blacklist = $firewall_options['ua_blacklist'] ?? array();
5911 ?>
5912
5913 <div class="vigilante-log-filters">
5914 <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">
5915 <select id="vigilante-log-type-filter" aria-label="<?php esc_attr_e( 'Filter the log by event type', 'vigilante' ); ?>">
5916 <option value=""><?php esc_html_e( 'All Types', 'vigilante' ); ?></option>
5917 <option value="login"><?php esc_html_e( 'Login', 'vigilante' ); ?></option>
5918 <option value="user"><?php esc_html_e( 'User', 'vigilante' ); ?></option>
5919 <option value="content"><?php esc_html_e( 'Content', 'vigilante' ); ?></option>
5920 <option value="plugin"><?php esc_html_e( 'Plugin', 'vigilante' ); ?></option>
5921 <option value="theme"><?php esc_html_e( 'Theme', 'vigilante' ); ?></option>
5922 <option value="settings"><?php esc_html_e( 'Settings', 'vigilante' ); ?></option>
5923 <option value="comment"><?php esc_html_e( 'Comment', 'vigilante' ); ?></option>
5924 <option value="media"><?php esc_html_e( 'Media', 'vigilante' ); ?></option>
5925 <option value="firewall"><?php esc_html_e( 'Firewall', 'vigilante' ); ?></option>
5926 <option value="file"><?php esc_html_e( 'File', 'vigilante' ); ?></option>
5927 <option value="security"><?php esc_html_e( 'Security', 'vigilante' ); ?></option>
5928 <option value="system"><?php esc_html_e( 'System', 'vigilante' ); ?></option>
5929 </select>
5930 <select id="vigilante-log-severity-filter" aria-label="<?php esc_attr_e( 'Filter the log by severity', 'vigilante' ); ?>">
5931 <option value=""><?php esc_html_e( 'All Severities', 'vigilante' ); ?></option>
5932 <option value="info"><?php esc_html_e( 'Info', 'vigilante' ); ?></option>
5933 <option value="warning"><?php esc_html_e( 'Warning', 'vigilante' ); ?></option>
5934 <option value="critical"><?php esc_html_e( 'Critical', 'vigilante' ); ?></option>
5935 </select>
5936 <select id="vigilante-log-method-filter" aria-label="<?php esc_attr_e( 'Filter the log by HTTP method', 'vigilante' ); ?>">
5937 <option value=""><?php esc_html_e( 'All Methods', 'vigilante' ); ?></option>
5938 <option value="GET">GET</option>
5939 <option value="POST">POST</option>
5940 <option value="PUT">PUT</option>
5941 <option value="DELETE">DELETE</option>
5942 <option value="PATCH">PATCH</option>
5943 <option value="OPTIONS">OPTIONS</option>
5944 <option value="HEAD">HEAD</option>
5945 </select>
5946 <button type="button" id="vigilante-log-refresh" class="button"><?php esc_html_e( 'Refresh', 'vigilante' ); ?></button>
5947 <span class="vigilante-pagination" id="vigilante-log-pagination" data-total="<?php echo esc_attr( $total_logs ); ?>" data-per-page="20" data-page="1">
5948 <?php if ( $total_logs > 20 ) : ?>
5949 <button type="button" class="vigilante-page-first" title="<?php esc_attr_e( 'First page', 'vigilante' ); ?>" disabled>&laquo;</button>
5950 <button type="button" class="vigilante-page-prev" title="<?php esc_attr_e( 'Previous page', 'vigilante' ); ?>" disabled>&lsaquo;</button>
5951 <?php endif; ?>
5952 <span class="vigilante-page-info">
5953 <?php
5954 $showing = min( 20, $total_logs );
5955 printf(
5956 /* translators: 1: first item, 2: last item, 3: total items */
5957 esc_html__( '%1$d–%2$d of %3$d', 'vigilante' ),
5958 $total_logs > 0 ? 1 : 0,
5959 absint( $showing ),
5960 absint( $total_logs )
5961 );
5962 ?>
5963 </span>
5964 <?php if ( $total_logs > 20 ) : ?>
5965 <button type="button" class="vigilante-page-next" title="<?php esc_attr_e( 'Next page', 'vigilante' ); ?>">&rsaquo;</button>
5966 <button type="button" class="vigilante-page-last" title="<?php esc_attr_e( 'Last page', 'vigilante' ); ?>">&raquo;</button>
5967 <?php endif; ?>
5968 </span>
5969 </div>
5970
5971 <div class="vigilante-log-table-wrap">
5972 <table id="vigilante-activity-log-table" class="wp-list-table widefat striped">
5973 <thead>
5974 <tr>
5975 <th class="column-date"><?php esc_html_e( 'Date', 'vigilante' ); ?></th>
5976 <th class="column-type"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
5977 <th class="column-method"><?php esc_html_e( 'Method', 'vigilante' ); ?></th>
5978 <th class="column-severity"><?php esc_html_e( 'Severity', 'vigilante' ); ?></th>
5979 <th class="column-message"><?php esc_html_e( 'Message', 'vigilante' ); ?></th>
5980 <th class="column-user"><?php esc_html_e( 'User', 'vigilante' ); ?></th>
5981 <th class="column-ip"><?php esc_html_e( 'IP', 'vigilante' ); ?></th>
5982 <th class="column-details"><?php esc_html_e( 'Details', 'vigilante' ); ?></th>
5983 </tr>
5984 </thead>
5985 <tbody>
5986 <?php
5987 if ( empty( $logs ) ) :
5988 ?>
5989 <tr><td colspan="8"><?php esc_html_e( 'No log entries found.', 'vigilante' ); ?></td></tr>
5990 <?php else : ?>
5991 <?php foreach ( $logs as $log ) :
5992 $request_method = isset( $log->request_method ) ? $log->request_method : '';
5993 // Prepare details as a simple object
5994 $ip_val = (string) ( $log->ip_address ?? '' );
5995 $ua_val = (string) ( $log->user_agent ?? '' );
5996 $details = array(
5997 'id' => (int) $log->id,
5998 'type' => (string) ( $log->event_type ?? '' ),
5999 'action' => (string) ( $log->event_action ?? '' ),
6000 'message' => (string) ( $log->event_message ?? '' ),
6001 'user' => (string) ( $log->user_login ?? '' ),
6002 'ip' => $ip_val,
6003 'user_agent' => $ua_val,
6004 'request_method' => (string) $request_method,
6005 'request_uri' => Vigilante_Activity_Log::extract_request_uri( $log->extra_data ?? '' ),
6006 'date' => (string) ( $log->created_at ?? '' ),
6007 'severity' => (string) ( $log->severity ?? 'info' ),
6008 'is_ip_whitelisted' => ( '' !== $ip_val && in_array( $ip_val, $ip_whitelist, true ) ),
6009 'is_ip_blacklisted' => ( '' !== $ip_val && in_array( $ip_val, $ip_blacklist, true ) ),
6010 'is_ua_whitelisted' => ( '' !== $ua_val && in_array( $ua_val, $ua_whitelist, true ) ),
6011 'is_ua_blacklisted' => ( '' !== $ua_val && in_array( $ua_val, $ua_blacklist, true ) ),
6012 );
6013 $display_type = isset( $type_labels[ $log->event_type ] ) ? $type_labels[ $log->event_type ] : $log->event_type;
6014 $display_severity = isset( $severity_labels[ $log->severity ] ) ? $severity_labels[ $log->severity ] : $log->severity;
6015 ?>
6016 <tr class="vigilante-severity-<?php echo esc_attr( $log->severity ); ?>">
6017 <td><?php echo esc_html( $log->created_at ); ?></td>
6018 <td><?php echo esc_html( $display_type ); ?></td>
6019 <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>
6020 <td><span class="vigilante-badge vigilante-badge-<?php echo esc_attr( $log->severity ); ?>"><?php echo esc_html( $display_severity ); ?></span></td>
6021 <td><?php echo esc_html( $log->event_message ); ?></td>
6022 <td><?php echo esc_html( $log->user_login ?? '-' ); ?></td>
6023 <td><code><?php echo esc_html( $log->ip_address ); ?></code></td>
6024 <td>
6025 <button type="button" class="button button-small vigilante-view-log-details"
6026 data-details='<?php echo esc_attr( wp_json_encode( $details, JSON_HEX_APOS | JSON_HEX_QUOT ) ); ?>'>
6027 <?php esc_html_e( 'View', 'vigilante' ); ?>
6028 </button>
6029 </td>
6030 </tr>
6031 <?php endforeach; ?>
6032 <?php endif; ?>
6033 </tbody>
6034 </table>
6035 </div>
6036
6037 <!-- Log Details Modal -->
6038 <div id="vigilante-log-details-modal" class="vigilante-modal" style="display: none;">
6039 <div class="vigilante-modal-content">
6040 <span class="vigilante-modal-close">&times;</span>
6041 <h3><?php esc_html_e( 'Log Entry Details', 'vigilante' ); ?></h3>
6042 <div id="vigilante-log-details-content"></div>
6043 </div>
6044 </div>
6045
6046 <p>
6047 <button type="button" class="button vigilante-export-logs"><?php esc_html_e( 'Export Audit Log', 'vigilante' ); ?></button>
6048 <button type="button" class="button vigilante-clear-logs" style="color: #a00;"><?php esc_html_e( 'Clear All Logs', 'vigilante' ); ?></button>
6049 </p>
6050 </div>
6051 <?php
6052 }
6053
6054 /**
6055 * Render File Integrity tab
6056 */
6057 private function render_tab_file_integrity() {
6058 $is_disabled = $this->render_module_disabled_notice( 'file_integrity' );
6059 $options = $this->settings->get_section( 'file_integrity' );
6060 // On the main site of a network the critical-file scan is the network's
6061 // canary for a change to wp-config.php or the root .htaccess, so a
6062 // main-site admin without network rights cannot turn it off. Since
6063 // 2.11.8; see Vigilante_Settings::get_main_site_file_settings().
6064 $vg_main_locked = $this->main_site_files_locked();
6065 $last_scan = get_option( 'vigilante_last_integrity_scan' );
6066 $last_results = get_option( 'vigilante_last_integrity_results' );
6067 $ignored_files = get_option( 'vigilante_ignored_files', array() );
6068
6069 // Backward compat: convert old notify_on_changes to notify_level
6070 $notify_level = $options['notify_level'] ?? '';
6071 if ( empty( $notify_level ) ) {
6072 $notify_level = ! empty( $options['notify_on_changes'] ) ? 'all' : 'disabled';
6073 }
6074
6075 // Closed + Removed plugins data. Surfaced inside Last Scan Results so the
6076 // user sees file findings and plugin closures together (same tier of risk,
6077 // same UI), and as the trigger to keep Last Scan Results open even when no
6078 // file scan has run yet (the daily cron may have populated this section).
6079 //
6080 // Gating by last_check_time > 0 is how "Clear Previous Results" visually
6081 // resets this block: the option vigilante_plugin_status_last_check is
6082 // deleted on Clear, but the state map and the ignored list survive so the
6083 // next scan reconstructs without degrading a 'removed' slug. While
6084 // last_check is 0, we treat the plugin_status data as if it didn't exist.
6085 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
6086 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
6087 }
6088 $closed_checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
6089 $closed_last_check = $closed_checker->get_last_check_time();
6090 if ( $closed_last_check > 0 ) {
6091 $closed_plugins = $closed_checker->get_closed_plugins();
6092 $ignored_closed_plugins = $closed_checker->get_ignored_closed_plugins();
6093 } else {
6094 $closed_plugins = array();
6095 $ignored_closed_plugins = array();
6096 }
6097 $has_closed = ! empty( $closed_plugins );
6098 $datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
6099 ?>
6100 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="file_integrity" <?php echo $is_disabled ? 'inert' : ''; ?>>
6101 <div id="vigilante-section-fi-monitoring" class="vigilante-settings-section">
6102 <h2>
6103 <?php esc_html_e( 'File Integrity Monitoring', 'vigilante' ); ?>
6104 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
6105 </h2>
6106 <p><?php esc_html_e( 'Detects file modifications using WordPress.org checksums.', 'vigilante' ); ?></p>
6107
6108 <table class="form-table">
6109 <tr>
6110 <th scope="row"><?php esc_html_e( 'Automatic Scans', 'vigilante' ); ?></th>
6111 <td>
6112 <label>
6113 <input type="checkbox" name="file_integrity[auto_scan]" value="1" <?php checked( ! empty( $options['auto_scan'] ) ); ?>>
6114 <?php esc_html_e( 'Enable scheduled file integrity scans', 'vigilante' ); ?>
6115 </label>
6116 </td>
6117 </tr>
6118 <tr>
6119 <th scope="row"><label for="vigilante-f-file-integrity-scan-frequency"><?php esc_html_e( 'Scan Frequency', 'vigilante' ); ?></label></th>
6120 <td>
6121 <select id="vigilante-f-file-integrity-scan-frequency" name="file_integrity[scan_frequency]">
6122 <option value="daily" <?php selected( $options['scan_frequency'] ?? 'daily', 'daily' ); ?>><?php esc_html_e( 'Daily', 'vigilante' ); ?></option>
6123 <option value="weekly" <?php selected( $options['scan_frequency'] ?? 'daily', 'weekly' ); ?>><?php esc_html_e( 'Weekly', 'vigilante' ); ?></option>
6124 </select>
6125 </td>
6126 </tr>
6127 <tr>
6128 <th scope="row"><label for="vigilante-f-file-integrity-notify-level"><?php esc_html_e( 'Email Notifications', 'vigilante' ); ?></label></th>
6129 <td>
6130 <select id="vigilante-f-file-integrity-notify-level" name="file_integrity[notify_level]">
6131 <option value="all" <?php selected( $notify_level, 'all' ); ?>><?php esc_html_e( 'All issues (modified + suspicious)', 'vigilante' ); ?></option>
6132 <option value="suspicious_only" <?php selected( $notify_level, 'suspicious_only' ); ?>><?php esc_html_e( 'Suspicious files only', 'vigilante' ); ?></option>
6133 <option value="disabled" <?php selected( $notify_level, 'disabled' ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
6134 </select>
6135 <p class="description"><?php esc_html_e( '"Suspicious files only" reduces noise by skipping modified file notifications. Recommended for most sites.', 'vigilante' ); ?></p>
6136 </td>
6137 </tr>
6138 <tr>
6139 <th scope="row"><?php esc_html_e( 'Instant Alert', 'vigilante' ); ?></th>
6140 <td>
6141 <label>
6142 <input type="checkbox" name="file_integrity[instant_alert]" value="1" <?php checked( ! empty( $options['instant_alert'] ) ); ?>>
6143 <?php esc_html_e( 'Send immediate alert when modified, suspicious or additional files are detected, or when a closed plugin is found', 'vigilante' ); ?>
6144 </label>
6145 <p class="description"><?php esc_html_e( 'Fires even if the Email Notifications setting above is set to Disabled.', 'vigilante' ); ?></p>
6146 <p class="description">
6147 <?php
6148 printf(
6149 /* translators: %s: Link to notification settings */
6150 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
6151 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
6152 );
6153 ?>
6154 </p>
6155 </td>
6156 </tr>
6157 <tr>
6158 <th scope="row"><?php esc_html_e( 'Test email', 'vigilante' ); ?></th>
6159 <td>
6160 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
6161 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
6162 </button>
6163 <span class="vigilante-test-email-result" style="margin-left:8px;"></span>
6164 <p class="description"><?php esc_html_e( 'Sends a test message to the configured recipients to confirm email delivery works.', 'vigilante' ); ?></p>
6165 </td>
6166 </tr>
6167 <tr>
6168 <th scope="row"><?php esc_html_e( 'Scan Scope', 'vigilante' ); ?></th>
6169 <td>
6170 <fieldset>
6171 <label>
6172 <input type="checkbox" name="file_integrity[scan_core]" value="1" <?php checked( $options['scan_core'] ?? true ); ?>>
6173 <?php esc_html_e( 'Core files (compare against WordPress.org checksums)', 'vigilante' ); ?>
6174 </label>
6175 <br>
6176 <label>
6177 <input type="checkbox" name="file_integrity[scan_plugins]" value="1" <?php checked( $options['scan_plugins'] ?? true ); ?>>
6178 <?php esc_html_e( 'Plugins (WordPress.org repository plugins)', 'vigilante' ); ?>
6179 </label>
6180 <br>
6181 <label>
6182 <input type="checkbox" name="file_integrity[scan_themes]" value="1" <?php checked( $options['scan_themes'] ?? true ); ?>>
6183 <?php esc_html_e( 'Themes (WordPress.org repository themes)', 'vigilante' ); ?>
6184 </label>
6185 <br>
6186 <label>
6187 <input type="checkbox" name="file_integrity[scan_uploads]" value="1" <?php checked( $options['scan_uploads'] ?? true ); ?>>
6188 <?php esc_html_e( 'Uploads directory (detect PHP files, double extensions, .htaccess)', 'vigilante' ); ?>
6189 </label>
6190 <br>
6191 <label>
6192 <input type="checkbox" name="file_integrity[scan_critical_config]" value="1" <?php disabled( $vg_main_locked ); ?> <?php checked( $options['scan_critical_config'] ?? true ); ?>>
6193 <?php esc_html_e( 'Critical config files (wp-config.php, .htaccess baseline monitoring)', 'vigilante' ); ?>
6194 <?php if ( $vg_main_locked ) : ?>
6195 <span class="description" style="display:block;margin-left:24px;"><?php echo esc_html( Vigilante_Settings::get_shared_files_notice() ); ?></span>
6196 <?php endif; ?>
6197 </label>
6198 <br>
6199 <label>
6200 <input type="checkbox" name="file_integrity[check_closed_plugins]" value="1" <?php checked( $options['check_closed_plugins'] ?? true ); ?>>
6201 <?php esc_html_e( 'Closed plugins (daily check against the WordPress.org repository)', 'vigilante' ); ?>
6202 </label>
6203 </fieldset>
6204 </td>
6205 </tr>
6206 <tr>
6207 <th scope="row"><label for="vigilante-f-file-integrity-excluded-paths"><?php esc_html_e( 'Excluded Paths', 'vigilante' ); ?></label></th>
6208 <td>
6209 <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>
6210 <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>
6211 </td>
6212 </tr>
6213 <tr>
6214 <th scope="row"><label for="vigilante-f-file-integrity-excluded-extensions"><?php esc_html_e( 'Excluded Extensions', 'vigilante' ); ?></label></th>
6215 <td>
6216 <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>
6217 <p class="description">
6218 <?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' ); ?>
6219 <br>
6220 <?php
6221 printf(
6222 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the scoped-extension example. */
6223 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' ),
6224 '<code>',
6225 '</code>'
6226 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
6227 ?>
6228 </p>
6229 </td>
6230 </tr>
6231 </table>
6232 </div>
6233
6234 <p class="submit vigilante-submit-buttons">
6235 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
6236 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
6237 </button>
6238 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
6239 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
6240 </button>
6241 <span class="vigilante-buttons-separator"></span>
6242 <button type="button" class="button button-primary vigilante-run-scan">
6243 <?php esc_html_e( 'Run Scan Now', 'vigilante' ); ?>
6244 </button>
6245 <button type="button" class="button vigilante-clear-scan-btn vigilante-clear-scan">
6246 <?php esc_html_e( 'Clear Previous Results', 'vigilante' ); ?>
6247 </button>
6248 </p>
6249 </form>
6250
6251 <div id="vigilante-scan-results" class="vigilante-settings-section" style="display:none;"></div>
6252
6253 <?php if ( $last_scan || $has_closed || $closed_last_check > 0 ) : ?>
6254 <div id="vigilante-section-fi-last-scan" class="vigilante-settings-section">
6255 <h2><?php esc_html_e( 'Last Scan Results', 'vigilante' ); ?></h2>
6256 <?php if ( $last_scan ) : ?>
6257 <p>
6258 <?php
6259 // Build the "X files scanned" hint inline with the date so it doesn't
6260 // need its own stat box (keeps the row compact when closed plugins are
6261 // present).
6262 $scanned_total = 0;
6263 if ( $last_results ) {
6264 $scanned_total = (int) ( $last_results['ok'] ?? 0 )
6265 + count( $last_results['modified'] ?? array() )
6266 + count( $last_results['suspicious'] ?? array() )
6267 + count( $last_results['extra'] ?? array() )
6268 + count( $ignored_files );
6269 }
6270 if ( $scanned_total > 0 ) {
6271 printf(
6272 /* translators: 1: date and time of last scan, 2: formatted file count */
6273 esc_html__( 'Last scan: %1$s (%2$s files scanned)', 'vigilante' ),
6274 esc_html( wp_date( $datetime_format, $last_scan ) ),
6275 esc_html( number_format_i18n( $scanned_total ) )
6276 );
6277 } else {
6278 printf(
6279 /* translators: %s: date and time of last scan */
6280 esc_html__( 'Last scan: %s', 'vigilante' ),
6281 esc_html( wp_date( $datetime_format, $last_scan ) )
6282 );
6283 }
6284 if ( $closed_last_check > 0 && $closed_last_check !== (int) $last_scan ) {
6285 echo ' &middot; ';
6286 printf(
6287 /* translators: %s: date and time of last closed plugins check */
6288 esc_html__( 'Closed plugins last checked: %s', 'vigilante' ),
6289 esc_html( wp_date( $datetime_format, $closed_last_check ) )
6290 );
6291 }
6292 ?>
6293 </p>
6294 <?php elseif ( $closed_last_check > 0 ) : ?>
6295 <p>
6296 <?php
6297 printf(
6298 /* translators: %s: date and time of last closed plugins check */
6299 esc_html__( 'Closed plugins last checked: %s &middot; the daily cron is running, no full integrity scan yet.', 'vigilante' ),
6300 esc_html( wp_date( $datetime_format, $closed_last_check ) )
6301 );
6302 ?>
6303 </p>
6304 <?php endif; ?>
6305 <div id="vigilante-last-scan-results">
6306 <?php if ( $last_results || $has_closed ) : ?>
6307 <div class="vigilante-scan-summary">
6308 <?php if ( $last_results ) : ?>
6309 <div class="vigilante-scan-stat vigilante-stat-ok">
6310 <span class="vigilante-stat-number"><?php echo esc_html( $last_results['ok'] ?? 0 ); ?></span>
6311 <span class="vigilante-stat-label"><?php esc_html_e( 'OK', 'vigilante' ); ?></span>
6312 </div>
6313 <div class="vigilante-scan-stat vigilante-stat-modified">
6314 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['modified'] ?? array() ) ); ?></span>
6315 <span class="vigilante-stat-label"><?php esc_html_e( 'Modified', 'vigilante' ); ?></span>
6316 </div>
6317 <div class="vigilante-scan-stat vigilante-stat-suspicious">
6318 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['suspicious'] ?? array() ) ); ?></span>
6319 <span class="vigilante-stat-label"><?php esc_html_e( 'Suspicious', 'vigilante' ); ?></span>
6320 </div>
6321 <div class="vigilante-scan-stat vigilante-stat-extra">
6322 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['extra'] ?? array() ) ); ?></span>
6323 <span class="vigilante-stat-label"><?php esc_html_e( 'Extra', 'vigilante' ); ?></span>
6324 </div>
6325 <?php endif; ?>
6326 <?php if ( $has_closed ) : ?>
6327 <div class="vigilante-scan-stat vigilante-stat-suspicious">
6328 <span class="vigilante-stat-number" style="color: #d63638;"><?php echo (int) count( $closed_plugins ); ?></span>
6329 <span class="vigilante-stat-label"><?php esc_html_e( 'Closed/Removed', 'vigilante' ); ?></span>
6330 </div>
6331 <?php endif; ?>
6332 <?php if ( ! empty( $ignored_files ) ) : ?>
6333 <div class="vigilante-scan-stat vigilante-stat-ignored">
6334 <span class="vigilante-stat-number"><?php echo esc_html( count( $ignored_files ) ); ?></span>
6335 <span class="vigilante-stat-label"><?php esc_html_e( 'Ignored', 'vigilante' ); ?></span>
6336 </div>
6337 <?php endif; ?>
6338 </div>
6339
6340 <?php if ( ! empty( $last_results['suspicious'] ) ) : ?>
6341 <div class="vigilante-file-list vigilante-suspicious-files vigilante-paginated-section" data-bulk-mode="ignore">
6342 <h3 style="color: #d63638;"><?php esc_html_e( 'Suspicious Files', 'vigilante' ); ?></h3>
6343 <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>
6344 <div class="vigilante-fi-bulk-bar">
6345 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
6346 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
6347 </div>
6348 <div class="vigilante-fi-pagination-wrap"></div>
6349 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
6350 <thead>
6351 <tr>
6352 <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>
6353 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6354 <th style="width: 250px;"><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
6355 <th style="width: 120px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
6356 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6357 </tr>
6358 </thead>
6359 <tbody>
6360 <?php
6361 foreach ( $last_results['suspicious'] as $item ) {
6362 $file_path = '';
6363 $file_reason = __( 'Unknown', 'vigilante' );
6364 $file_type = 'unknown';
6365
6366 if ( is_array( $item ) ) {
6367 if ( isset( $item['file'] ) ) {
6368 $file_path = $item['file'];
6369 }
6370 if ( isset( $item['reason'] ) ) {
6371 $file_reason = $item['reason'];
6372 }
6373 if ( isset( $item['type'] ) ) {
6374 $file_type = $item['type'];
6375 }
6376 } else {
6377 $file_path = (string) $item;
6378 }
6379 ?>
6380 <tr>
6381 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
6382 <td><code style="color: #d63638;"><?php echo esc_html( $file_path ); ?></code></td>
6383 <td><?php echo esc_html( $file_reason ); ?></td>
6384 <td><?php echo esc_html( $file_type ); ?></td>
6385 <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>
6386 </tr>
6387 <?php
6388 }
6389 ?>
6390 </tbody>
6391 </table>
6392 </div>
6393 <?php endif; ?>
6394
6395 <?php if ( ! empty( $last_results['extra'] ) ) : ?>
6396 <div class="vigilante-file-list vigilante-extra-files vigilante-paginated-section" data-bulk-mode="ignore">
6397 <h3 style="color: #b32d2e;"><?php esc_html_e( 'Extra Files', 'vigilante' ); ?></h3>
6398 <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>
6399 <div class="vigilante-fi-bulk-bar">
6400 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
6401 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
6402 </div>
6403 <div class="vigilante-fi-pagination-wrap"></div>
6404 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
6405 <thead>
6406 <tr>
6407 <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>
6408 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6409 <th style="width: 250px;"><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
6410 <th style="width: 120px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
6411 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6412 </tr>
6413 </thead>
6414 <tbody>
6415 <?php
6416 foreach ( $last_results['extra'] as $item ) {
6417 $file_path = is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item;
6418 $file_reason = is_array( $item ) ? ( $item['reason'] ?? __( 'Unknown', 'vigilante' ) ) : __( 'Unknown', 'vigilante' );
6419 $file_type = is_array( $item ) ? ( $item['type'] ?? 'unknown' ) : 'unknown';
6420 ?>
6421 <tr>
6422 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
6423 <td><code style="color: #b32d2e;"><?php echo esc_html( $file_path ); ?></code></td>
6424 <td><?php echo esc_html( $file_reason ); ?></td>
6425 <td><?php echo esc_html( $file_type ); ?></td>
6426 <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>
6427 </tr>
6428 <?php
6429 }
6430 ?>
6431 </tbody>
6432 </table>
6433 </div>
6434 <?php endif; ?>
6435
6436 <?php
6437 // Split critical config files from regular modified files.
6438 // Computed unconditionally so the three sub-sections that consume
6439 // these arrays (Critical Config, Closed + Removed, Modified Files)
6440 // can render independently and in the order the team picked.
6441 $critical_modified = array();
6442 $regular_modified = array();
6443 if ( $last_results && ! empty( $last_results['modified'] ) ) {
6444 foreach ( $last_results['modified'] as $item ) {
6445 if ( is_array( $item ) && isset( $item['type'] ) && 'critical_config' === $item['type'] ) {
6446 $critical_modified[] = $item;
6447 } else {
6448 $regular_modified[] = $item;
6449 }
6450 }
6451 }
6452 ?>
6453
6454 <?php if ( ! empty( $critical_modified ) ) : ?>
6455 <div class="vigilante-file-list vigilante-critical-config-files">
6456 <h3 style="color: #e36210;"><?php esc_html_e( 'Critical config files modified', 'vigilante' ); ?></h3>
6457 <p class="description">
6458 <?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' ); ?>
6459 </p>
6460 <table class="wp-list-table widefat fixed striped">
6461 <thead>
6462 <tr>
6463 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6464 <th style="width: 200px;"><?php esc_html_e( 'Changes', 'vigilante' ); ?></th>
6465 <th style="width: 220px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6466 </tr>
6467 </thead>
6468 <tbody>
6469 <?php foreach ( $critical_modified as $crit_item ) :
6470 $crit_file = $crit_item['file'] ?? '';
6471 $crit_baseline_size = $crit_item['baseline_size'] ?? 0;
6472 $crit_current_size = $crit_item['current_size'] ?? 0;
6473 $crit_diff = $crit_item['diff'] ?? array();
6474 $crit_id = sanitize_html_class( $crit_file );
6475 $added_count = is_array( $crit_diff ) ? count( $crit_diff['added'] ?? array() ) : 0;
6476 $removed_count = is_array( $crit_diff ) ? count( $crit_diff['removed'] ?? array() ) : 0;
6477 // The lines of a shared file are for whoever approves it. Results
6478 // stored before 2.11.8 on the main site still carry them, so the
6479 // screen asks too, not only the scan that wrote them.
6480 $diff_network = ( is_array( $crit_diff ) && ! empty( $crit_diff['network'] ) ) || $this->critical_approval_locked();
6481 $diff_rescan = is_array( $crit_diff ) && ! empty( $crit_diff['rescan'] );
6482 $diff_redaction = is_array( $crit_diff ) && ! empty( $crit_diff['redaction'] );
6483 $diff_unavailable = $diff_network || ( is_array( $crit_diff ) && ! empty( $crit_diff['unavailable'] ) );
6484 ?>
6485 <tr>
6486 <td><code style="color: #e36210;"><?php echo esc_html( $crit_file ); ?></code></td>
6487 <td>
6488 <?php if ( ! $diff_unavailable ) : ?>
6489 <span style="color: #007017;">+<?php echo (int) $added_count; ?></span>
6490 <span style="color: #b32d2e;">-<?php echo (int) $removed_count; ?></span>
6491 <?php esc_html_e( 'lines', 'vigilante' ); ?><br>
6492 <?php endif; ?>
6493 <small style="color: #50575e;">
6494 <?php
6495 printf(
6496 /* translators: 1: baseline size, 2: current size */
6497 esc_html__( '%1$s &rarr; %2$s bytes', 'vigilante' ),
6498 esc_html( number_format_i18n( $crit_baseline_size ) ),
6499 esc_html( number_format_i18n( $crit_current_size ) )
6500 );
6501 ?>
6502 </small>
6503 </td>
6504 <td>
6505 <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' ); ?>">
6506 <?php esc_html_e( 'Review changes', 'vigilante' ); ?>
6507 </button>
6508 <?php if ( $this->critical_approval_locked() ) : ?>
6509 <span class="description" style="display:block;margin-top:4px;">
6510 <?php echo esc_html( $this->critical_approval_notice() ); ?>
6511 </span>
6512 <?php else : ?>
6513 <button type="button" class="button button-small button-primary vigilante-approve-critical-file" data-file="<?php echo esc_attr( $crit_file ); ?>">
6514 <?php esc_html_e( 'Approve', 'vigilante' ); ?>
6515 </button>
6516 <?php endif; ?>
6517 </td>
6518 </tr>
6519 <tr id="vigilante-critical-content-<?php echo esc_attr( $crit_id ); ?>" class="vigilante-critical-content-row" style="display:none;">
6520 <td colspan="3" style="padding: 0;">
6521 <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;">
6522 <?php if ( $diff_network ) : ?>
6523 <p style="color: #50575e; font-style: italic; margin: 0;">
6524 <?php esc_html_e( 'This file belongs to the whole network, so its line changes are only shown to network administrators, on the main site.', 'vigilante' ); ?>
6525 </p>
6526 <?php elseif ( $diff_rescan ) : ?>
6527 <p style="color: #50575e; font-style: italic; margin: 0;">
6528 <?php esc_html_e( 'Run a new scan to see the line changes of this file.', 'vigilante' ); ?>
6529 </p>
6530 <?php elseif ( $diff_redaction ) : ?>
6531 <p style="color: #50575e; font-style: italic; margin: 0;">
6532 <?php esc_html_e( 'The line changes of this file are not shown because a value in it could not be hidden safely. The change itself is still detected.', 'vigilante' ); ?>
6533 </p>
6534 <?php elseif ( $diff_unavailable ) : ?>
6535 <p style="color: #50575e; font-style: italic; margin: 0;">
6536 <?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' ); ?>
6537 </p>
6538 <?php elseif ( empty( $crit_diff['added'] ) && empty( $crit_diff['removed'] ) ) : ?>
6539 <p style="color: #50575e; font-style: italic; margin: 0;">
6540 <?php esc_html_e( 'No line-level changes detected (may be whitespace or reordering).', 'vigilante' ); ?>
6541 </p>
6542 <?php else : ?>
6543 <?php if ( ! empty( $crit_diff['removed'] ) ) : ?>
6544 <?php foreach ( $crit_diff['removed'] as $rline ) : ?>
6545 <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>
6546 <?php endforeach; ?>
6547 <?php endif; ?>
6548 <?php if ( ! empty( $crit_diff['added'] ) ) : ?>
6549 <?php foreach ( $crit_diff['added'] as $aline ) : ?>
6550 <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>
6551 <?php endforeach; ?>
6552 <?php endif; ?>
6553 <?php endif; ?>
6554 </div>
6555 </td>
6556 </tr>
6557 <?php endforeach; ?>
6558 </tbody>
6559 </table>
6560 </div>
6561 <?php endif; ?>
6562
6563 <?php if ( $has_closed ) : ?>
6564 <div class="vigilante-file-list vigilante-closed-plugins">
6565 <h3 id="vigilante-section-fi-closed-plugins" style="color: #d63638;"><?php esc_html_e( 'Closed + Removed Plugins', 'vigilante' ); ?></h3>
6566 <p class="description" style="color: #d63638;">
6567 <?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' ); ?>
6568 </p>
6569 <table class="wp-list-table widefat striped">
6570 <thead>
6571 <tr>
6572 <th><?php esc_html_e( 'Plugin', 'vigilante' ); ?></th>
6573 <th style="width: 70px;"><?php esc_html_e( 'Version', 'vigilante' ); ?></th>
6574 <th style="width: 90px;"><?php esc_html_e( 'State', 'vigilante' ); ?></th>
6575 <th style="width: 110px;"><?php esc_html_e( 'Closed date', 'vigilante' ); ?></th>
6576 <th><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
6577 <th style="width: 130px;"><?php esc_html_e( 'Detected', 'vigilante' ); ?></th>
6578 <th style="width: 90px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6579 </tr>
6580 </thead>
6581 <tbody>
6582 <?php foreach ( $closed_plugins as $cp_slug => $cp_entry ) :
6583 $cp_state = $cp_entry['state'] ?? '';
6584 $cp_state_label = 'closed' === $cp_state ? __( 'Closed', 'vigilante' ) : __( 'Removed', 'vigilante' );
6585 $cp_state_color = 'closed' === $cp_state ? '#d63638' : '#b32d2e';
6586 $cp_reason = '';
6587 if ( ! empty( $cp_entry['closed_reason_text'] ) ) {
6588 $cp_reason = $cp_entry['closed_reason_text'];
6589 } elseif ( 'removed' === $cp_state ) {
6590 $cp_reason = __( 'Removed from repository (metadata hidden, typical of Security Issue closures)', 'vigilante' );
6591 }
6592 $cp_detected = isset( $cp_entry['first_detected'] ) ? (int) $cp_entry['first_detected'] : 0;
6593 ?>
6594 <tr>
6595 <td>
6596 <strong><?php echo esc_html( $cp_entry['name'] ?? $cp_slug ); ?></strong><br>
6597 <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>
6598 </td>
6599 <td><?php echo esc_html( $cp_entry['version'] ?? '' ); ?></td>
6600 <td><span style="color: <?php echo esc_attr( $cp_state_color ); ?>; font-weight: 600;"><?php echo esc_html( $cp_state_label ); ?></span></td>
6601 <td><?php echo esc_html( $cp_entry['closed_date'] ?? '' ); ?></td>
6602 <td><?php echo esc_html( $cp_reason ); ?></td>
6603 <td>
6604 <?php echo $cp_detected > 0 ? esc_html( wp_date( $datetime_format, $cp_detected ) ) : '&mdash;'; ?>
6605 </td>
6606 <td>
6607 <button type="button" class="button button-small vigilante-ignore-closed-plugin" data-slug="<?php echo esc_attr( $cp_slug ); ?>">
6608 <?php esc_html_e( 'Ignore', 'vigilante' ); ?>
6609 </button>
6610 </td>
6611 </tr>
6612 <?php endforeach; ?>
6613 </tbody>
6614 </table>
6615 </div>
6616 <?php endif; ?>
6617
6618 <?php if ( ! empty( $regular_modified ) ) : ?>
6619 <div class="vigilante-file-list vigilante-paginated-section" data-bulk-mode="ignore">
6620 <h3><?php esc_html_e( 'Modified Files', 'vigilante' ); ?></h3>
6621 <p class="description"><?php esc_html_e( 'These files (apparently) differ from the original WordPress or plugin versions.', 'vigilante' ); ?></p>
6622 <div class="vigilante-fi-bulk-bar">
6623 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
6624 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
6625 </div>
6626 <div class="vigilante-fi-pagination-wrap"></div>
6627 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
6628 <thead>
6629 <tr>
6630 <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>
6631 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6632 <th style="width: 100px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
6633 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6634 </tr>
6635 </thead>
6636 <tbody>
6637 <?php
6638 foreach ( $regular_modified as $item ) {
6639 $file_path = '';
6640 $file_type = 'unknown';
6641
6642 if ( is_array( $item ) ) {
6643 if ( isset( $item['file'] ) ) {
6644 $file_path = $item['file'];
6645 }
6646 if ( isset( $item['type'] ) ) {
6647 $file_type = $item['type'];
6648 }
6649 } else {
6650 $file_path = (string) $item;
6651 }
6652 ?>
6653 <tr>
6654 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
6655 <td><code><?php echo esc_html( $file_path ); ?></code></td>
6656 <td><?php echo esc_html( $file_type ); ?></td>
6657 <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>
6658 </tr>
6659 <?php
6660 }
6661 ?>
6662 </tbody>
6663 </table>
6664 </div>
6665 <?php endif; ?>
6666
6667 <?php if ( $last_results && empty( $last_results['modified'] ) && empty( $last_results['suspicious'] ) && empty( $last_results['extra'] ) && ! $has_closed ) : ?>
6668 <p class="vigilante-all-clear" style="color: #00a32a; font-weight: bold;">
6669 <?php esc_html_e( 'Good Job! All files passed integrity check. No issues found.', 'vigilante' ); ?>
6670 </p>
6671 <?php endif; ?>
6672 <?php endif; ?>
6673 </div>
6674 </div>
6675 <?php endif; ?>
6676
6677 <?php if ( ! empty( $ignored_closed_plugins ) ) : ?>
6678 <div id="vigilante-section-fi-ignored-closed" class="vigilante-settings-section">
6679 <h2><?php esc_html_e( 'Ignored Closed + Removed Plugins', 'vigilante' ); ?></h2>
6680 <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>
6681 <table class="wp-list-table widefat fixed striped">
6682 <thead>
6683 <tr>
6684 <th><?php esc_html_e( 'Plugin', 'vigilante' ); ?></th>
6685 <th style="width: 110px;"><?php esc_html_e( 'State', 'vigilante' ); ?></th>
6686 <th style="width: 120px;"><?php esc_html_e( 'Closed date', 'vigilante' ); ?></th>
6687 <th style="width: 130px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6688 </tr>
6689 </thead>
6690 <tbody>
6691 <?php foreach ( $ignored_closed_plugins as $icp_slug => $icp_entry ) :
6692 $icp_state = $icp_entry['state'] ?? '';
6693 $icp_state_label = 'closed' === $icp_state ? __( 'Closed', 'vigilante' ) : __( 'Removed', 'vigilante' );
6694 ?>
6695 <tr>
6696 <td>
6697 <strong><?php echo esc_html( $icp_entry['name'] ?? $icp_slug ); ?></strong><br>
6698 <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>
6699 </td>
6700 <td><?php echo esc_html( $icp_state_label ); ?></td>
6701 <td><?php echo esc_html( $icp_entry['closed_date'] ?? '' ); ?></td>
6702 <td>
6703 <button type="button" class="button button-small vigilante-unignore-closed-plugin" data-slug="<?php echo esc_attr( $icp_slug ); ?>">
6704 <?php esc_html_e( 'Stop ignoring', 'vigilante' ); ?>
6705 </button>
6706 </td>
6707 </tr>
6708 <?php endforeach; ?>
6709 </tbody>
6710 </table>
6711 <p style="margin-top: 10px;">
6712 <button type="button" class="button vigilante-clear-ignored-closed-plugins"><?php esc_html_e( 'Clear All Ignored Closed + Removed Plugins', 'vigilante' ); ?></button>
6713 </p>
6714 </div>
6715 <?php endif; ?>
6716
6717 <?php if ( ! empty( $ignored_files ) ) : ?>
6718 <div id="vigilante-section-fi-ignored" class="vigilante-settings-section">
6719 <h2><?php esc_html_e( 'Ignored Files', 'vigilante' ); ?></h2>
6720 <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>
6721 <div class="vigilante-paginated-section" data-bulk-mode="unignore">
6722 <div class="vigilante-fi-bulk-bar">
6723 <button type="button" class="button vigilante-bulk-unignore" disabled><?php esc_html_e( 'Stop ignoring selected', 'vigilante' ); ?></button>
6724 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
6725 </div>
6726 <div class="vigilante-fi-pagination-wrap"></div>
6727 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
6728 <thead>
6729 <tr>
6730 <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>
6731 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6732 <th style="width: 120px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6733 </tr>
6734 </thead>
6735 <tbody>
6736 <?php foreach ( $ignored_files as $file ) : ?>
6737 <tr>
6738 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file ); ?>"></th>
6739 <td><code><?php echo esc_html( $file ); ?></code></td>
6740 <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>
6741 </tr>
6742 <?php endforeach; ?>
6743 </tbody>
6744 </table>
6745 </div>
6746 <p style="margin-top: 10px;">
6747 <button type="button" class="button vigilante-clear-ignored"><?php esc_html_e( 'Clear All Ignored Files', 'vigilante' ); ?></button>
6748 </p>
6749 </div>
6750 <?php endif; ?>
6751 <?php
6752 }
6753
6754 /**
6755 * Render sidebar with promotional widgets
6756 */
6757 private function render_sidebar() {
6758 $promo_banner = new Vigilante_Promo_Banner( 'vigilante' );
6759 $promo_banner->render();
6760 }
6761
6762 /**
6763 * AJAX: Download a ZIP backup of the critical config files.
6764 *
6765 * Streams wp-config.php and .htaccess (and robots.txt if present) as a
6766 * downloadable archive. Config backups are no longer left as files under the
6767 * web root, so this hands the admin the archive directly.
6768 */
6769 public function ajax_download_files_backup() {
6770 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
6771
6772 if ( ! current_user_can( 'manage_options' ) ) {
6773 wp_die( esc_html__( 'Permission denied.', 'vigilante' ), 403 );
6774 }
6775
6776 // The archive carries wp-config.php, which a whole network shares. On a
6777 // network manage_options is held by every subsite administrator, so the
6778 // same gate the writers use applies here.
6779 if ( ! Vigilante_Settings::can_write_shared_files() ) {
6780 wp_die( esc_html( Vigilante_Settings::get_shared_files_notice() ), 403 );
6781 }
6782
6783 $backup_manager = new Vigilante_Backup_Manager();
6784 $result = $backup_manager->stream_files_zip();
6785
6786 // stream_files_zip() exits on success; only a WP_Error returns here.
6787 if ( is_wp_error( $result ) ) {
6788 wp_die( esc_html( $result->get_error_message() ), 500 );
6789 }
6790 }
6791
6792 /**
6793 * AJAX: Save settings
6794 */
6795 public function ajax_save_settings() {
6796 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
6797
6798 if ( ! current_user_can( 'manage_options' ) ) {
6799 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
6800 }
6801
6802 $section = isset( $_POST['section'] ) ? sanitize_key( $_POST['section'] ) : '';
6803
6804 // Handle $_POST['data'] based on type
6805 if ( isset( $_POST['data'] ) && is_array( $_POST['data'] ) ) {
6806 $data = map_deep( wp_unslash( $_POST['data'] ), 'sanitize_text_field' );
6807 } elseif ( isset( $_POST['data'] ) ) {
6808 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
6809 $raw_data = wp_unslash( $_POST['data'] );
6810 parse_str( $raw_data, $data );
6811 $data = map_deep( $data, 'sanitize_textarea_field' );
6812 } else {
6813 $data = array();
6814 }
6815
6816 if ( empty( $section ) ) {
6817 wp_send_json_error( __( 'Invalid section.', 'vigilante' ) );
6818 }
6819
6820 // Check if 2FA is being enabled or method changed (for notification sending)
6821 $send_2fa_notification = false;
6822 $send_login_url_notification = false;
6823
6824 if ( 'login_security' === $section ) {
6825 // Read old state from DB
6826 $db_options = get_option( Vigilante_Settings::OPTION_NAME, array() );
6827 $old_2fa_enabled = ! empty( $db_options['login_security']['two_factor']['enabled'] );
6828 $old_method = $db_options['login_security']['two_factor']['method'] ?? 'email';
6829
6830 // Check new state from submitted data
6831 $new_2fa_enabled = false;
6832 $notify_on_enable = false;
6833 $new_method = isset( $data['login_security']['two_factor']['method'] )
6834 ? sanitize_key( $data['login_security']['two_factor']['method'] )
6835 : 'email';
6836
6837 if ( isset( $data['login_security']['two_factor']['enabled'] ) ) {
6838 $new_2fa_enabled = filter_var( $data['login_security']['two_factor']['enabled'], FILTER_VALIDATE_BOOLEAN );
6839 }
6840 if ( isset( $data['login_security']['two_factor']['notify_on_enable'] ) ) {
6841 $notify_on_enable = filter_var( $data['login_security']['two_factor']['notify_on_enable'], FILTER_VALIDATE_BOOLEAN );
6842 }
6843
6844 // Send notification if:
6845 // 1. 2FA is being enabled (was off, now on) OR
6846 // 2. Method changed while 2FA is enabled
6847 if ( $notify_on_enable && $new_2fa_enabled ) {
6848 if ( ! $old_2fa_enabled || ( $old_2fa_enabled && $old_method !== $new_method ) ) {
6849 $send_2fa_notification = true;
6850 }
6851 }
6852
6853 // Check if login URL changed and notification is enabled
6854 $old_login_url = $db_options['login_security']['custom_login_url'] ?? '';
6855 $new_login_url = isset( $data['login_security']['custom_login_url'] )
6856 ? sanitize_title( $data['login_security']['custom_login_url'] )
6857 : '';
6858 $notify_on_url_change = isset( $data['login_security']['notify_on_login_url_change'] )
6859 ? filter_var( $data['login_security']['notify_on_login_url_change'], FILTER_VALIDATE_BOOLEAN )
6860 : false;
6861
6862 if ( $notify_on_url_change && ! empty( $new_login_url ) && $new_login_url !== $old_login_url ) {
6863 $send_login_url_notification = true;
6864 }
6865 }
6866
6867 // Get defaults
6868 $defaults = $this->settings->get_default_options();
6869
6870 // Read ONLY saved options from database (not merged with defaults)
6871 $saved_options = get_option( Vigilante_Settings::OPTION_NAME, array() );
6872
6873 // What is stored before this request changes anything: the shared file
6874 // settings this user may not change are put back from here (2.11.6).
6875 $stored_options = $saved_options;
6876 $locked = Vigilante_Settings::get_locked_file_settings();
6877
6878 if ( isset( $locked[ $section ] ) && true === $locked[ $section ] ) {
6879 wp_send_json_error( Vigilante_Settings::get_shared_files_notice() );
6880 }
6881
6882 // A module switch is a single key, so refusing says more than a success
6883 // that changed nothing, and the dashboard puts the toggle back.
6884 if ( 'modules' === $section && isset( $locked['modules'], $data['modules'] ) && is_array( $locked['modules'] ) && is_array( $data['modules'] ) ) {
6885 foreach ( array_keys( $data['modules'] ) as $vg_module ) {
6886 if ( in_array( sanitize_key( $vg_module ), $locked['modules'], true ) ) {
6887 wp_send_json_error( Vigilante_Settings::get_shared_files_notice() );
6888 }
6889 }
6890 }
6891
6892 $rejected_ips = array();
6893
6894 // Handle modules
6895 if ( 'modules' === $section && isset( $data['modules'] ) ) {
6896 if ( ! isset( $saved_options['modules'] ) ) {
6897 $saved_options['modules'] = array();
6898 }
6899 foreach ( $data['modules'] as $module => $enabled ) {
6900 $module = sanitize_key( $module );
6901 $saved_options['modules'][ $module ] = in_array( $enabled, array( '1', 1, 'true', true ), true );
6902 }
6903 // Clear active preset when modules change
6904 update_option( 'vigilante_active_preset', '' );
6905 } else {
6906 // Process primary section
6907 if ( isset( $data[ $section ] ) && is_array( $data[ $section ] ) ) {
6908 $section_defaults = isset( $defaults[ $section ] ) ? $defaults[ $section ] : array();
6909 $current_section = isset( $saved_options[ $section ] ) ? $saved_options[ $section ] : array();
6910
6911 // Process the submitted data
6912 $processed = $this->process_section_data( $data[ $section ], $section_defaults, $current_section );
6913
6914 // The IP boxes are free text and, until 2.9.9, whatever was typed
6915 // went straight into the option. An entry the matcher can never
6916 // match still sits in a security list looking like protection,
6917 // so the ones that cannot match are dropped and reported back
6918 // instead of being stored in silence.
6919 $rejected_ips = $this->filter_ip_lists( $section, $processed );
6920
6921 // Save the processed section
6922 $saved_options[ $section ] = $processed;
6923
6924 // Clear active preset when any section settings change
6925 update_option( 'vigilante_active_preset', '' );
6926 }
6927 }
6928
6929 // Clear cache before saving
6930 wp_cache_delete( Vigilante_Settings::OPTION_NAME, 'options' );
6931
6932 $saved_options = Vigilante_Settings::keep_locked_file_settings( $saved_options, $stored_options );
6933
6934 // Save to database
6935 update_option( Vigilante_Settings::OPTION_NAME, $saved_options );
6936
6937 // Clear the settings cache
6938 $this->settings->clear_cache();
6939
6940 // Apply changes based on section
6941 $this->apply_section_changes( $section, $saved_options );
6942
6943 // Send 2FA notifications after settings are saved
6944 $notification_result = null;
6945 if ( $send_2fa_notification ) {
6946 $notification_result = $this->send_2fa_enable_notifications();
6947 }
6948
6949 // Send login URL notifications after settings are saved
6950 $login_url_result = null;
6951 if ( $send_login_url_notification ) {
6952 $login_url_result = $this->send_login_url_notifications();
6953 }
6954
6955 // Build success message
6956 $message = __( 'Settings saved successfully.', 'vigilante' );
6957
6958 if ( $notification_result && $notification_result['sent'] > 0 ) {
6959 $message .= ' ' . sprintf(
6960 /* translators: %d: Number of emails sent */
6961 _n(
6962 '2FA notification sent to %d user.',
6963 '2FA notifications sent to %d users.',
6964 $notification_result['sent'],
6965 'vigilante'
6966 ),
6967 $notification_result['sent']
6968 );
6969 }
6970
6971 if ( $login_url_result && $login_url_result['sent'] > 0 ) {
6972 $message .= ' ' . sprintf(
6973 /* translators: %d: Number of emails sent */
6974 _n(
6975 'Login URL notification sent to %d user.',
6976 'Login URL notifications sent to %d users.',
6977 $login_url_result['sent'],
6978 'vigilante'
6979 ),
6980 $login_url_result['sent']
6981 );
6982 }
6983
6984 if ( ! empty( $rejected_ips ) ) {
6985 $message .= ' ' . sprintf(
6986 /* translators: %s: comma separated list of the entries that were not saved. */
6987 _n(
6988 'This entry is not a valid IP, CIDR range or wildcard, so it was not saved: %s',
6989 'These entries are not valid IPs, CIDR ranges or wildcards, so they were not saved: %s',
6990 count( $rejected_ips ),
6991 'vigilante'
6992 ),
6993 implode( ', ', array_map( 'esc_html', $rejected_ips ) )
6994 );
6995 }
6996
6997 wp_send_json_success( $message );
6998 }
6999
7000 /**
7001 * Keep only the IP patterns the matcher can actually match
7002 *
7003 * @since 2.9.9
7004 *
7005 * @param string $section Section being saved.
7006 * @param array $processed Section data, edited in place.
7007 * @return array Entries that were dropped, for the message back to the user.
7008 */
7009 private function filter_ip_lists( $section, &$processed ) {
7010 $lists = array(
7011 'firewall' => array( 'ip_whitelist', 'ip_blacklist' ),
7012 'login_security' => array( 'ip_whitelist' ),
7013 );
7014
7015 if ( ! isset( $lists[ $section ] ) ) {
7016 return array();
7017 }
7018
7019 $rejected = array();
7020
7021 foreach ( $lists[ $section ] as $key ) {
7022 if ( ! isset( $processed[ $key ] ) || ! is_array( $processed[ $key ] ) ) {
7023 continue;
7024 }
7025
7026 $split = Vigilante_IP_Utils::split_list( $processed[ $key ] );
7027 $processed[ $key ] = $split['valid'];
7028 $rejected = array_merge( $rejected, $split['rejected'] );
7029 }
7030
7031 return array_values( array_unique( $rejected ) );
7032 }
7033
7034 /**
7035 * Send 2FA enable notifications to users
7036 *
7037 * @return array Result with 'sent' and 'failed' counts.
7038 */
7039 private function send_2fa_enable_notifications() {
7040 $result = array(
7041 'sent' => 0,
7042 'failed' => 0,
7043 );
7044
7045 // Get settings for roles and method
7046 $login_security = $this->settings->get_section( 'login_security' );
7047 $two_factor = isset( $login_security['two_factor'] ) ? $login_security['two_factor'] : array();
7048 $roles = isset( $two_factor['enforced_roles'] ) ? $two_factor['enforced_roles'] : array( 'administrator' );
7049 $method = isset( $two_factor['method'] ) ? $two_factor['method'] : 'email';
7050
7051 if ( empty( $roles ) ) {
7052 $roles = array( 'administrator' );
7053 }
7054
7055 $excluded = isset( $two_factor['excluded_users'] ) ? array_map( 'absint', $two_factor['excluded_users'] ) : array();
7056
7057 // Get users with these roles
7058 $args = array(
7059 'role__in' => $roles,
7060 );
7061 if ( ! empty( $excluded ) ) {
7062 // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- Small excluded users list from settings.
7063 $args['exclude'] = $excluded;
7064 }
7065 $users = get_users( $args );
7066
7067 if ( empty( $users ) ) {
7068 return $result;
7069 }
7070
7071 $site_name = get_bloginfo( 'name' );
7072 $from_name = ! empty( $two_factor['email_from_name'] ) ? $two_factor['email_from_name'] : $site_name;
7073
7074 if ( 'totp' === $method ) {
7075 // Use TOTP class for styled HTML emails
7076 if ( ! class_exists( 'Vigilante_Two_Factor_TOTP' ) ) {
7077 require_once VIGILANTE_INCLUDES_DIR . 'class-two-factor-totp.php';
7078 }
7079 $totp = new Vigilante_Two_Factor_TOTP( $this->settings, $this->database, $this->activity_log );
7080
7081 foreach ( $users as $user ) {
7082 // Skip users who already have TOTP configured
7083 $totp_data = $this->database->get_totp_data( $user->ID );
7084 if ( $totp_data && ! empty( $totp_data['is_configured'] ) ) {
7085 continue;
7086 }
7087
7088 $sent = $totp->send_activation_email( $user, $site_name, $from_name );
7089
7090 if ( $sent ) {
7091 $this->database->mark_2fa_notified( $user->ID );
7092 $result['sent']++;
7093 } else {
7094 $result['failed']++;
7095 }
7096 }
7097 } else {
7098 // Email method - use existing email 2FA class
7099 if ( ! class_exists( 'Vigilante_Two_Factor_Email' ) ) {
7100 require_once VIGILANTE_INCLUDES_DIR . 'class-two-factor-email.php';
7101 }
7102 $email_2fa = new Vigilante_Two_Factor_Email( $this->settings, $this->database, $this->activity_log );
7103 return $email_2fa->send_activation_notifications( false );
7104 }
7105
7106 return $result;
7107 }
7108
7109 /**
7110 * Send login URL change notifications to users with admin access
7111 *
7112 * @return array Result with 'sent' and 'failed' counts.
7113 */
7114 private function send_login_url_notifications() {
7115 $login_options = $this->settings->get_section( 'login_security' );
7116 $custom_url = ! empty( $login_options['custom_login_url'] ) ? sanitize_title( $login_options['custom_login_url'] ) : '';
7117
7118 if ( empty( $custom_url ) ) {
7119 return array( 'sent' => 0, 'failed' => 0 );
7120 }
7121
7122 $login_url = home_url( $custom_url . '/' );
7123 $site_name = get_bloginfo( 'name' );
7124
7125 $admin_roles = array( 'administrator', 'editor', 'author', 'contributor' );
7126 $users = get_users( array( 'role__in' => $admin_roles ) );
7127
7128 if ( empty( $users ) ) {
7129 return array( 'sent' => 0, 'failed' => 0 );
7130 }
7131
7132 $subject = sprintf(
7133 /* translators: %s: Site name */
7134 __( '[%s] Your login URL has changed', 'vigilante' ),
7135 $site_name
7136 );
7137
7138 $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' ) );
7139 $body .= Vigilante_Email_Template::url_box( $login_url, __( 'Your new login URL:', 'vigilante' ) );
7140 $body .= Vigilante_Email_Template::alert_box( __( 'The old login address (wp-login.php) will no longer work.', 'vigilante' ) );
7141 $body .= Vigilante_Email_Template::button( $login_url, __( 'Go to login', 'vigilante' ) );
7142
7143 $sent = 0;
7144 $failed = 0;
7145
7146 foreach ( $users as $user ) {
7147 $result = Vigilante_Email_Template::send(
7148 $user->user_email,
7149 $subject,
7150 __( 'Login URL changed', 'vigilante' ),
7151 $body
7152 );
7153 if ( $result ) {
7154 $sent++;
7155 } else {
7156 $failed++;
7157 }
7158 }
7159
7160 if ( $this->activity_log ) {
7161 $this->activity_log->log(
7162 'login',
7163 'login_url_notified',
7164 sprintf(
7165 /* translators: 1: Sent count, 2: Failed count */
7166 __( 'Login URL notification sent on save: %1$d sent, %2$d failed', 'vigilante' ),
7167 $sent,
7168 $failed
7169 )
7170 );
7171 }
7172
7173 return array( 'sent' => $sent, 'failed' => $failed );
7174 }
7175
7176 /**
7177 * Process section data maintaining proper types from defaults
7178 *
7179 * @param array $submitted_data Data submitted from form.
7180 * @param array $defaults Default values for this section.
7181 * @param array $current Current saved values.
7182 * @param string $section_name Section name for special handling.
7183 * @return array Processed data.
7184 */
7185 private function process_section_data( $submitted_data, $defaults, $current, $section_name = '' ) {
7186 // Start with defaults, then merge current saved values
7187 $result = array_replace_recursive( $defaults, $current );
7188
7189 // Process each submitted value
7190 foreach ( $submitted_data as $key => $value ) {
7191 $key = sanitize_key( $key );
7192
7193 if ( is_array( $value ) ) {
7194 // Nested array (like rate_limiting)
7195 $nested_defaults = isset( $defaults[ $key ] ) && is_array( $defaults[ $key ] ) ? $defaults[ $key ] : array();
7196 $nested_current = isset( $result[ $key ] ) && is_array( $result[ $key ] ) ? $result[ $key ] : array();
7197 $result[ $key ] = $this->process_section_data( $value, $nested_defaults, $nested_current, $key );
7198 } else {
7199 // Determine type from default value
7200 $default_value = isset( $defaults[ $key ] ) ? $defaults[ $key ] : null;
7201
7202 if ( null === $default_value ) {
7203 // No default, check current value type or use as string
7204 $current_value = isset( $current[ $key ] ) ? $current[ $key ] : null;
7205 if ( is_bool( $current_value ) ) {
7206 $result[ $key ] = in_array( $value, array( '1', 1, 'true', true ), true );
7207 } elseif ( is_int( $current_value ) ) {
7208 $result[ $key ] = intval( $value );
7209 } elseif ( is_array( $current_value ) ) {
7210 $result[ $key ] = is_string( $value ) ? array_filter( array_map( 'trim', explode( "\n", $value ) ) ) : (array) $value;
7211 } else {
7212 $result[ $key ] = sanitize_text_field( $value );
7213 }
7214 } elseif ( is_bool( $default_value ) ) {
7215 // Boolean: '1', 1, 'true' become true; '0', 0, '', 'false' become false
7216 $result[ $key ] = in_array( $value, array( '1', 1, 'true', true ), true );
7217 } elseif ( is_int( $default_value ) ) {
7218 // Integer - with special handling for time fields shown in minutes
7219 $int_value = intval( $value );
7220
7221 // Convert minutes to seconds for login_security duration fields
7222 // These are displayed as minutes in the form but stored as seconds
7223 if ( in_array( $key, array( 'lockout_duration', 'max_lockout_duration' ), true ) ) {
7224 $int_value = $int_value * 60;
7225 }
7226
7227 $result[ $key ] = $int_value;
7228 } elseif ( is_array( $default_value ) ) {
7229 // Array from textarea (e.g., IP lists)
7230 if ( is_string( $value ) ) {
7231 $result[ $key ] = array_filter( array_map( 'trim', explode( "\n", $value ) ) );
7232 } else {
7233 $result[ $key ] = (array) $value;
7234 }
7235 } else {
7236 // String - preserve newlines for textarea fields
7237 if ( is_string( $value ) && ( strpos( $value, "\n" ) !== false || strpos( $value, "\r" ) !== false ) ) {
7238 $result[ $key ] = sanitize_textarea_field( $value );
7239 } else {
7240 $result[ $key ] = sanitize_text_field( $value );
7241 }
7242 }
7243 }
7244 }
7245
7246 // Handle unchecked checkboxes: HTML forms don't submit unchecked boxes
7247 // If a boolean field exists in defaults but NOT in submitted_data, set it to false
7248 //
7249 // EXCEPTION: the top-level 'enabled' flag of every section is the
7250 // module's master switch and is controlled by the Dashboard module
7251 // toggle, NOT by a checkbox inside the section's form. Treating it
7252 // like a regular checkbox here would silently switch the module off
7253 // every time the user saves the tab — see the REST API enabled=false
7254 // regression. We only skip it at the top level (when section_name is
7255 // empty); nested 'enabled' fields like security_headers.csp.enabled
7256 // are real checkboxes and must keep the auto-unset behaviour.
7257 $preserve_top_level = array( 'enabled' );
7258
7259 foreach ( $defaults as $key => $default_value ) {
7260 if ( '' === $section_name && in_array( $key, $preserve_top_level, true ) ) {
7261 continue;
7262 }
7263 if ( is_bool( $default_value ) && ! array_key_exists( $key, $submitted_data ) ) {
7264 $result[ $key ] = false;
7265 } elseif ( is_array( $default_value ) && ! isset( $submitted_data[ $key ] ) ) {
7266 // Check if this is a flat value list (like excluded_users, enforced_roles, ip_whitelist)
7267 // vs a nested settings group (like rate_limiting, two_factor)
7268 // Flat lists: default is empty array OR all values are scalar
7269 $is_value_list = empty( $default_value );
7270 if ( ! $is_value_list ) {
7271 $is_value_list = true;
7272 foreach ( $default_value as $dv ) {
7273 if ( ! is_scalar( $dv ) ) {
7274 $is_value_list = false;
7275 break;
7276 }
7277 }
7278 }
7279
7280 if ( $is_value_list ) {
7281 // All items removed - reset to empty array
7282 $result[ $key ] = array();
7283 } else {
7284 // Nested settings group - handle boolean children
7285 foreach ( $default_value as $nested_key => $nested_default ) {
7286 if ( is_bool( $nested_default ) && isset( $result[ $key ] ) && is_array( $result[ $key ] ) ) {
7287 $nested_submitted = isset( $submitted_data[ $key ] ) && is_array( $submitted_data[ $key ] )
7288 ? $submitted_data[ $key ]
7289 : array();
7290 if ( ! array_key_exists( $nested_key, $nested_submitted ) ) {
7291 $result[ $key ][ $nested_key ] = false;
7292 }
7293 }
7294 }
7295 }
7296 }
7297 }
7298
7299 return $result;
7300 }
7301
7302 /**
7303 * AJAX: Export settings
7304 */
7305 public function ajax_export_settings() {
7306 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7307
7308 if ( ! current_user_can( 'manage_options' ) ) {
7309 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7310 }
7311
7312 $options = $this->settings->get_all_options();
7313 $filename = 'vigilante-settings-' . gmdate( 'Y-m-d-His' ) . '.json';
7314
7315 wp_send_json_success( array(
7316 'content' => wp_json_encode( $options, JSON_PRETTY_PRINT ),
7317 'filename' => $filename,
7318 ) );
7319 }
7320
7321 /**
7322 * AJAX: Import settings
7323 */
7324 public function ajax_import_settings() {
7325 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7326
7327 if ( ! current_user_can( 'manage_options' ) ) {
7328 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7329 }
7330
7331 // Accept both 'settings' (from JS) and 'content' (legacy).
7332 // Do NOT run sanitize_text_field() on the raw payload: it calls
7333 // wp_strip_all_tags() internally, which removes any "<...>" substring
7334 // and turns a valid export JSON into garbage if any stored value
7335 // contains < or > (htaccess snippets, email templates, etc.). The
7336 // real sanitization happens after json_decode(), via map_deep() on
7337 // the parsed array.
7338 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash
7339 $content = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : '';
7340 if ( empty( $content ) ) {
7341 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash
7342 $content = isset( $_POST['content'] ) ? wp_unslash( $_POST['content'] ) : '';
7343 }
7344
7345 if ( empty( $content ) || ! is_string( $content ) ) {
7346 wp_send_json_error( __( 'No content provided.', 'vigilante' ) );
7347 }
7348
7349 $imported = json_decode( $content, true );
7350
7351 if ( json_last_error() !== JSON_ERROR_NONE || ! is_array( $imported ) ) {
7352 wp_send_json_error( __( 'Invalid JSON format.', 'vigilante' ) );
7353 }
7354
7355 // Sanitize imported data recursively
7356 $imported = map_deep( $imported, 'sanitize_text_field' );
7357
7358 // Validate structure: only sections and keys of the schema survive, and
7359 // every value takes the type of its default. Until 2.11.0 this was an
7360 // array_replace_recursive() of the file over the defaults, so any key in
7361 // the file, known or not, landed in vigilante_options (S7). Sections
7362 // the file does not carry keep their defaults; a section it does carry
7363 // replaces the default one whole, because validate_options() has
7364 // already filled in whatever the file left out.
7365 $defaults = $this->settings->get_default_options();
7366 $validated = $this->settings->validate_options( $imported );
7367 $merged = $defaults;
7368
7369 foreach ( $validated as $section => $data ) {
7370 if ( is_array( $data ) ) {
7371 $merged[ $section ] = $data;
7372 }
7373 }
7374
7375 // Save
7376 $merged = Vigilante_Settings::keep_locked_file_settings( $merged, get_option( Vigilante_Settings::OPTION_NAME, array() ) );
7377 update_option( Vigilante_Settings::OPTION_NAME, $merged );
7378 $this->settings->clear_cache();
7379
7380 // Re-evaluate the active preset marker. The imported config may match
7381 // a known preset exactly, partially, or not at all — without this step
7382 // the dashboard would keep showing whatever preset was active before
7383 // the import even if the new config no longer matches it.
7384 $matched_preset = $this->detect_matching_preset( $merged );
7385 if ( null === $matched_preset ) {
7386 delete_option( 'vigilante_active_preset' );
7387 } else {
7388 update_option( 'vigilante_active_preset', $matched_preset );
7389 }
7390
7391 // Apply file changes after import
7392 $this->apply_all_file_changes( $merged );
7393
7394 // Refresh the Security Analyzer score so the dashboard widget reflects
7395 // the imported config rather than the pre-import scan. Reuse the
7396 // post-Under-Attack scan hook (same job: full scan, async).
7397 if ( ! wp_next_scheduled( 'vigilante_under_attack_post_scan' ) ) {
7398 wp_schedule_single_event( time() + 5, 'vigilante_under_attack_post_scan' );
7399 }
7400
7401 wp_send_json_success( __( 'Settings imported successfully.', 'vigilante' ) . $this->locked_file_settings_message() );
7402 }
7403
7404 /**
7405 * Detect whether a vigilante_options array matches a known preset.
7406 *
7407 * A preset matches when every field the preset explicitly declares is
7408 * present in the config with the same (normalised) value. Fields outside
7409 * the preset are ignored — they may have been modified by the user before
7410 * applying the preset and do not invalidate the match. This mirrors how
7411 * apply_preset() now layers presets on top of the user's existing config.
7412 *
7413 * @param array $options The current/imported vigilante_options.
7414 * @return string|null Preset id ('standard', 'maximum') or null if custom.
7415 */
7416 private function detect_matching_preset( $options ) {
7417 if ( ! is_array( $options ) ) {
7418 return null;
7419 }
7420
7421 $presets = $this->settings->get_presets();
7422
7423 foreach ( $presets as $preset_id => $preset_data ) {
7424 unset( $preset_data['name'], $preset_data['description'] );
7425 if ( $this->preset_subset_matches( $preset_data, $options ) ) {
7426 return $preset_id;
7427 }
7428 }
7429
7430 return null;
7431 }
7432
7433 /**
7434 * Check whether every leaf value inside $preset_subset exists with the
7435 * same (normalised) value at the same path inside $config.
7436 *
7437 * @param mixed $preset_subset Branch of the preset definition.
7438 * @param mixed $config Same branch in the live/imported config.
7439 * @return bool
7440 */
7441 private function preset_subset_matches( $preset_subset, $config ) {
7442 if ( is_array( $preset_subset ) ) {
7443 if ( ! is_array( $config ) ) {
7444 return false;
7445 }
7446 foreach ( $preset_subset as $key => $value ) {
7447 if ( ! array_key_exists( $key, $config ) ) {
7448 return false;
7449 }
7450 if ( ! $this->preset_subset_matches( $value, $config[ $key ] ) ) {
7451 return false;
7452 }
7453 }
7454 return true;
7455 }
7456
7457 return $this->normalise_scalar_for_compare( $preset_subset ) === $this->normalise_scalar_for_compare( $config );
7458 }
7459
7460 /**
7461 * Normalise a scalar value so that the variants WordPress and the form
7462 * layer routinely produce ('1' / 1 / true → "1"; '' / '0' / 0 / false /
7463 * null → "") compare equal. Other values become strings unchanged.
7464 *
7465 * @param mixed $value
7466 * @return string
7467 */
7468 private function normalise_scalar_for_compare( $value ) {
7469 if ( is_bool( $value ) ) {
7470 return $value ? '1' : '';
7471 }
7472 if ( null === $value ) {
7473 return '';
7474 }
7475 if ( is_int( $value ) || is_float( $value ) ) {
7476 return (string) $value;
7477 }
7478 if ( is_string( $value ) ) {
7479 if ( 'true' === $value ) {
7480 return '1';
7481 }
7482 if ( 'false' === $value ) {
7483 return '';
7484 }
7485 return $value;
7486 }
7487 // Arrays and objects shouldn't reach here (handled by recursion above),
7488 // but if they do, fall back to a stable comparable representation.
7489 return wp_json_encode( $value );
7490 }
7491
7492 /**
7493 * AJAX: Apply preset
7494 */
7495 public function ajax_apply_preset() {
7496 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7497
7498 if ( ! current_user_can( 'manage_options' ) ) {
7499 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7500 }
7501
7502 $preset = isset( $_POST['preset'] ) ? sanitize_key( $_POST['preset'] ) : '';
7503
7504 // Handle reset to defaults
7505 if ( 'reset' === $preset ) {
7506 $stored_options = get_option( Vigilante_Settings::OPTION_NAME, array() );
7507 $defaults = Vigilante_Settings::get_defaults_preserving_user_data( $stored_options );
7508 $defaults = Vigilante_Settings::keep_locked_file_settings( $defaults, $stored_options );
7509 update_option( Vigilante_Settings::OPTION_NAME, $defaults );
7510 $this->settings->clear_cache();
7511
7512 // Clear active preset
7513 update_option( 'vigilante_active_preset', '' );
7514
7515 // Apply file changes after reset
7516 $this->apply_all_file_changes( $defaults );
7517
7518 wp_send_json_success( __( 'Settings reset to defaults.', 'vigilante' ) . $this->locked_file_settings_message() );
7519 return;
7520 }
7521
7522 $presets = $this->settings->get_presets();
7523
7524 if ( ! isset( $presets[ $preset ] ) ) {
7525 wp_send_json_error( __( 'Invalid preset.', 'vigilante' ) );
7526 }
7527
7528 $preset_options = $presets[ $preset ];
7529 unset( $preset_options['name'], $preset_options['description'] );
7530
7531 // Layer the preset on top of the user's CURRENT configuration, not on
7532 // top of defaults. This way applying a preset only changes the fields
7533 // the preset explicitly mentions; everything else stays as the user
7534 // had it. For example, applying Maximum will not flip HSTS off if the
7535 // user had it on — Maximum doesn't touch HSTS, so it's left alone.
7536 // Use "Reset to Defaults" if a clean slate is needed.
7537 $current = get_option( Vigilante_Settings::OPTION_NAME, array() );
7538 if ( ! is_array( $current ) ) {
7539 $current = array();
7540 }
7541 // Make sure all known keys exist before merging — the merge does not
7542 // invent keys that are missing on both sides.
7543 $current = Vigilante_Settings::merge_preset( $this->settings->get_default_options(), $current );
7544
7545 $merged = Vigilante_Settings::merge_preset( $current, $preset_options );
7546 $merged = Vigilante_Settings::keep_locked_file_settings( $merged, get_option( Vigilante_Settings::OPTION_NAME, array() ) );
7547
7548 update_option( Vigilante_Settings::OPTION_NAME, $merged );
7549 $this->settings->clear_cache();
7550
7551 // Save active preset
7552 update_option( 'vigilante_active_preset', $preset );
7553
7554 // Apply file changes after preset
7555 $this->apply_all_file_changes( $merged );
7556
7557 wp_send_json_success( __( 'Preset applied successfully.', 'vigilante' ) . $this->locked_file_settings_message() );
7558 }
7559
7560 /**
7561 * AJAX: Reset a specific section to defaults
7562 */
7563 public function ajax_reset_section() {
7564 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7565
7566 if ( ! current_user_can( 'manage_options' ) ) {
7567 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7568 }
7569
7570 $section = isset( $_POST['section'] ) ? sanitize_key( $_POST['section'] ) : '';
7571
7572 if ( empty( $section ) ) {
7573 wp_send_json_error( __( 'No section specified.', 'vigilante' ) );
7574 }
7575
7576 // Get current options and defaults. get_defaults_preserving_user_data()
7577 // applies the tweaks a fresh installation gets, so the button and a new
7578 // install agree, and keeps whatever the owner typed in.
7579 $current_options = $this->settings->get_all_options();
7580 $defaults = Vigilante_Settings::get_defaults_preserving_user_data( $current_options );
7581
7582 // Check if section exists in defaults
7583 if ( ! isset( $defaults[ $section ] ) ) {
7584 wp_send_json_error( __( 'Invalid section.', 'vigilante' ) );
7585 }
7586
7587 $new_values = $defaults[ $section ];
7588
7589 /*
7590 * On a subsite, the settings written to wp-config.php and .htaccess are
7591 * the main site's business. Resetting the local copy of those would only
7592 * make this screen disagree with the file, so they are carried over
7593 * untouched, and a section that is nothing but shared settings is not
7594 * reset at all. On the main site, a user without network rights keeps
7595 * the ones the shared files are built from as well (2.11.6).
7596 */
7597 $locked = Vigilante_Settings::get_locked_file_settings();
7598
7599 if ( isset( $locked[ $section ] ) && true === $locked[ $section ] ) {
7600 wp_send_json_error( Vigilante_Settings::get_shared_files_notice() );
7601 }
7602
7603 $current_options[ $section ] = $new_values;
7604 $current_options = Vigilante_Settings::keep_locked_file_settings( $current_options, get_option( Vigilante_Settings::OPTION_NAME, array() ) );
7605
7606 // Save
7607 update_option( Vigilante_Settings::OPTION_NAME, $current_options );
7608 $this->settings->clear_cache();
7609
7610 // Apply file changes if needed
7611 $this->apply_section_changes( $section, $current_options );
7612
7613 wp_send_json_success( array(
7614 'message' => __( 'Section reset to defaults.', 'vigilante' ),
7615 'section' => $section,
7616 'reload' => true,
7617 ) );
7618 }
7619
7620 /**
7621 * AJAX: Clear lockouts
7622 */
7623 public function ajax_clear_lockouts() {
7624 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7625
7626 if ( ! current_user_can( 'manage_options' ) ) {
7627 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7628 }
7629
7630 $ip = isset( $_POST['ip'] ) ? sanitize_text_field( wp_unslash( $_POST['ip'] ) ) : '';
7631
7632 if ( ! empty( $ip ) ) {
7633 $this->database->clear_lockout( $ip );
7634 } else {
7635 $this->database->clear_all_lockouts();
7636 }
7637
7638 wp_send_json_success( __( 'Lockouts cleared.', 'vigilante' ) );
7639 }
7640
7641 /**
7642 * AJAX: Clear logs
7643 */
7644 public function ajax_clear_logs() {
7645 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7646
7647 if ( ! current_user_can( 'manage_options' ) ) {
7648 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7649 }
7650
7651 if ( $this->activity_log ) {
7652 $result = $this->activity_log->clear_all_logs();
7653 if ( $result ) {
7654 wp_send_json_success( __( 'Logs cleared.', 'vigilante' ) );
7655 } else {
7656 wp_send_json_error( __( 'Failed to clear logs.', 'vigilante' ) );
7657 }
7658 } else {
7659 wp_send_json_error( __( 'Activity log not available.', 'vigilante' ) );
7660 }
7661 }
7662
7663 /**
7664 * AJAX: Run file integrity scan.
7665 *
7666 * Triggers the file integrity scan, which now also runs the closed plugins
7667 * check at the end when the `check_closed_plugins` toggle is on. Activity
7668 * log is passed through so Security Audit entries (both file-level and
7669 * plugin-status) are recorded from this entry point.
7670 */
7671 public function ajax_run_scan() {
7672 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7673
7674 if ( ! current_user_can( 'manage_options' ) ) {
7675 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7676 }
7677
7678 // Clear previous results before running new scan
7679 delete_option( 'vigilante_last_integrity_results' );
7680 delete_option( 'vigilante_last_integrity_scan' );
7681
7682 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database, $this->activity_log );
7683 $results = $file_integrity->run_scan();
7684
7685 // Save new results
7686 update_option( 'vigilante_last_integrity_scan', time() );
7687 update_option( 'vigilante_last_integrity_results', $results );
7688
7689 // On the main site the scan does compute the lines of wp-config.php and
7690 // .htaccess, for the network administrator. Somebody without network
7691 // rights gets the change and its sizes, not the lines.
7692 if ( $this->critical_approval_locked() && ! empty( $results['modified'] ) && is_array( $results['modified'] ) ) {
7693 foreach ( $results['modified'] as $index => $item ) {
7694 if ( is_array( $item ) && 'critical_config' === ( $item['type'] ?? '' ) ) {
7695 $results['modified'][ $index ]['diff'] = Vigilante_File_Integrity::network_only_diff();
7696 }
7697 }
7698 }
7699
7700 wp_send_json_success( array(
7701 'message' => __( 'Scan completed.', 'vigilante' ),
7702 'results' => $results,
7703 'ignored_count' => count( get_option( 'vigilante_ignored_files', array() ) ),
7704 ) );
7705 }
7706
7707 /**
7708 * AJAX: Clear scan results.
7709 *
7710 * Wipes visually everything inside "Last Scan Results": file scan findings
7711 * (Suspicious / Modified / Extra / Critical Config), file hashes and the
7712 * Closed + Removed Plugins block.
7713 *
7714 * Implementation detail to keep persistence intact:
7715 * - We delete the file scan options + hashes outright.
7716 * - For plugin status we ONLY delete the last_check timestamp — the state
7717 * map and the ignore list are preserved in DB. The render gates the
7718 * plugin_status subsections on last_check > 0, so they hide after
7719 * Clear (visual reset) and reappear on the next Run Scan Now with the
7720 * state intact. This avoids degrading a 'removed' slug (404 without
7721 * metadata) back to 'not_in_repo' on the next scan, which would
7722 * silently lose the alert.
7723 *
7724 * The Ignored Files list and the Ignored Closed + Removed Plugins list
7725 * are preserved on purpose; each has its own explicit "Clear All …"
7726 * button.
7727 */
7728 public function ajax_clear_scan() {
7729 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7730
7731 if ( ! current_user_can( 'manage_options' ) ) {
7732 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7733 }
7734
7735 $results = get_option( 'vigilante_last_integrity_results' );
7736 $scanned_at = get_option( 'vigilante_last_integrity_scan' );
7737
7738 delete_option( 'vigilante_last_integrity_results' );
7739 delete_option( 'vigilante_last_integrity_scan' );
7740
7741 /*
7742 * A pending change to wp-config.php or the root .htaccess is closed by
7743 * approving it, which takes the network. Clearing the results was one
7744 * more way to close it without, until the next scan: the ignore list was
7745 * shut in 2.11.8 and this button was left open, found by the cross
7746 * review of 2.11.8. So for somebody who cannot approve, those entries
7747 * stay and everything else goes.
7748 */
7749 if ( $this->critical_approval_locked() && is_array( $results ) && ! empty( $results['modified'] ) && is_array( $results['modified'] ) ) {
7750 $critical = array_values(
7751 array_filter(
7752 $results['modified'],
7753 function ( $item ) {
7754 return is_array( $item ) && 'critical_config' === ( $item['type'] ?? '' );
7755 }
7756 )
7757 );
7758
7759 if ( $critical ) {
7760 $results['modified'] = $critical;
7761 $results['suspicious'] = array();
7762 $results['extra'] = array();
7763 update_option( 'vigilante_last_integrity_results', $results );
7764 update_option( 'vigilante_last_integrity_scan', $scanned_at ? $scanned_at : time() );
7765 }
7766 }
7767
7768 if ( $this->database ) {
7769 $this->database->clear_file_hashes();
7770 }
7771
7772 // Visual reset of plugin_status block without touching the state map
7773 // or the ignored list. See PHPDoc above for the rationale.
7774 delete_option( 'vigilante_plugin_status_last_check' );
7775
7776 wp_send_json_success( __( 'Scan results cleared.', 'vigilante' ) );
7777 }
7778
7779 /**
7780 * AJAX: Ignore a file from scan results
7781 */
7782 public function ajax_ignore_file() {
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 $file = isset( $_POST['file'] ) ? sanitize_text_field( wp_unslash( $_POST['file'] ) ) : '';
7790
7791 if ( empty( $file ) ) {
7792 wp_send_json_error( __( 'No file specified.', 'vigilante' ) );
7793 }
7794
7795 // A change to a shared file is closed by approving it, and approving it
7796 // takes the network. Ignoring it would close the same warning without.
7797 if ( $this->critical_approval_locked() && in_array( $file, array( 'wp-config.php', '.htaccess' ), true ) ) {
7798 wp_send_json_error( $this->critical_approval_notice() );
7799 }
7800
7801 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7802 $file_integrity->ignore_file( $file );
7803
7804 // Also remove the file from stored scan results so UI updates
7805 $results = get_option( 'vigilante_last_integrity_results' );
7806 if ( $results ) {
7807 foreach ( array( 'modified', 'suspicious', 'extra' ) as $category ) {
7808 if ( ! empty( $results[ $category ] ) ) {
7809 $results[ $category ] = array_values(
7810 array_filter(
7811 $results[ $category ],
7812 function ( $item ) use ( $file ) {
7813 return ( is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item ) !== $file;
7814 }
7815 )
7816 );
7817 }
7818 }
7819 update_option( 'vigilante_last_integrity_results', $results );
7820 }
7821
7822 wp_send_json_success( __( 'File added to ignored list.', 'vigilante' ) );
7823 }
7824
7825 /**
7826 * AJAX: Stop ignoring a file
7827 */
7828 public function ajax_unignore_file() {
7829 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7830
7831 if ( ! current_user_can( 'manage_options' ) ) {
7832 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7833 }
7834
7835 $file = isset( $_POST['file'] ) ? sanitize_text_field( wp_unslash( $_POST['file'] ) ) : '';
7836
7837 if ( empty( $file ) ) {
7838 wp_send_json_error( __( 'No file specified.', 'vigilante' ) );
7839 }
7840
7841 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7842 $file_integrity->unignore_file( $file );
7843
7844 wp_send_json_success( __( 'File removed from ignored list.', 'vigilante' ) );
7845 }
7846
7847 /**
7848 * AJAX: Bulk ignore multiple files at once
7849 *
7850 * Processes a single batch into ignored list and prunes them from the
7851 * stored scan results so the UI updates without a re-scan.
7852 */
7853 public function ajax_bulk_ignore_files() {
7854 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7855
7856 if ( ! current_user_can( 'manage_options' ) ) {
7857 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7858 }
7859
7860 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized below per-item.
7861 $raw_files = isset( $_POST['files'] ) ? wp_unslash( $_POST['files'] ) : array();
7862 if ( ! is_array( $raw_files ) ) {
7863 wp_send_json_error( __( 'Invalid request.', 'vigilante' ) );
7864 }
7865
7866 $files = array();
7867 $shared = $this->critical_approval_locked() ? array( 'wp-config.php', '.htaccess' ) : array();
7868 foreach ( $raw_files as $f ) {
7869 $clean = sanitize_text_field( $f );
7870 // Same rule as ajax_ignore_file() for the two shared files.
7871 if ( '' !== $clean && ! in_array( $clean, $shared, true ) ) {
7872 $files[] = $clean;
7873 }
7874 }
7875
7876 if ( empty( $files ) ) {
7877 wp_send_json_error( __( 'No files selected.', 'vigilante' ) );
7878 }
7879
7880 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7881 $count = 0;
7882 foreach ( $files as $file ) {
7883 $file_integrity->ignore_file( $file );
7884 $count++;
7885 }
7886
7887 // Also prune the stored scan results so the UI matches the new ignore list.
7888 $results = get_option( 'vigilante_last_integrity_results' );
7889 if ( $results ) {
7890 $files_set = array_flip( $files );
7891 foreach ( array( 'modified', 'suspicious', 'extra' ) as $category ) {
7892 if ( ! empty( $results[ $category ] ) ) {
7893 $results[ $category ] = array_values(
7894 array_filter(
7895 $results[ $category ],
7896 function ( $item ) use ( $files_set ) {
7897 $path = is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item;
7898 return ! isset( $files_set[ $path ] );
7899 }
7900 )
7901 );
7902 }
7903 }
7904 update_option( 'vigilante_last_integrity_results', $results );
7905 }
7906
7907 wp_send_json_success(
7908 array(
7909 'count' => $count,
7910 'message' => sprintf(
7911 /* translators: %d: number of files added to the ignored list */
7912 _n( '%d file added to ignored list.', '%d files added to ignored list.', $count, 'vigilante' ),
7913 $count
7914 ),
7915 )
7916 );
7917 }
7918
7919 /**
7920 * AJAX: Bulk un-ignore multiple files at once
7921 */
7922 public function ajax_bulk_unignore_files() {
7923 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7924
7925 if ( ! current_user_can( 'manage_options' ) ) {
7926 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7927 }
7928
7929 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized below per-item.
7930 $raw_files = isset( $_POST['files'] ) ? wp_unslash( $_POST['files'] ) : array();
7931 if ( ! is_array( $raw_files ) ) {
7932 wp_send_json_error( __( 'Invalid request.', 'vigilante' ) );
7933 }
7934
7935 $files = array();
7936 foreach ( $raw_files as $f ) {
7937 $clean = sanitize_text_field( $f );
7938 if ( '' !== $clean ) {
7939 $files[] = $clean;
7940 }
7941 }
7942
7943 if ( empty( $files ) ) {
7944 wp_send_json_error( __( 'No files selected.', 'vigilante' ) );
7945 }
7946
7947 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7948 $count = 0;
7949 foreach ( $files as $file ) {
7950 $file_integrity->unignore_file( $file );
7951 $count++;
7952 }
7953
7954 wp_send_json_success(
7955 array(
7956 'count' => $count,
7957 'message' => sprintf(
7958 /* translators: %d: number of files removed from the ignored list */
7959 _n( '%d file removed from ignored list.', '%d files removed from ignored list.', $count, 'vigilante' ),
7960 $count
7961 ),
7962 )
7963 );
7964 }
7965
7966 /**
7967 * AJAX: Clear all ignored files
7968 */
7969 public function ajax_clear_ignored() {
7970 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7971
7972 if ( ! current_user_can( 'manage_options' ) ) {
7973 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7974 }
7975
7976 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7977 $file_integrity->clear_ignored_files();
7978
7979 wp_send_json_success( __( 'Ignored files list cleared.', 'vigilante' ) );
7980 }
7981
7982 /**
7983 * AJAX: Ignore a closed/removed plugin slug so it stops appearing in the
7984 * main list and email digests. The plugin keeps running on the site;
7985 * silencing is purely cosmetic and reversible.
7986 */
7987 public function ajax_ignore_closed_plugin() {
7988 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7989
7990 if ( ! current_user_can( 'manage_options' ) ) {
7991 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7992 }
7993
7994 $slug = isset( $_POST['slug'] ) ? sanitize_key( wp_unslash( $_POST['slug'] ) ) : '';
7995 if ( '' === $slug ) {
7996 wp_send_json_error( __( 'No slug specified.', 'vigilante' ) );
7997 }
7998
7999 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
8000 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
8001 }
8002 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
8003 $checker->ignore_slug( $slug );
8004
8005 wp_send_json_success( __( 'Plugin added to the ignored list.', 'vigilante' ) );
8006 }
8007
8008 /**
8009 * AJAX: Stop ignoring a previously-ignored closed/removed plugin slug.
8010 */
8011 public function ajax_unignore_closed_plugin() {
8012 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8013
8014 if ( ! current_user_can( 'manage_options' ) ) {
8015 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8016 }
8017
8018 $slug = isset( $_POST['slug'] ) ? sanitize_key( wp_unslash( $_POST['slug'] ) ) : '';
8019 if ( '' === $slug ) {
8020 wp_send_json_error( __( 'No slug specified.', 'vigilante' ) );
8021 }
8022
8023 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
8024 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
8025 }
8026 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
8027 $checker->unignore_slug( $slug );
8028
8029 wp_send_json_success( __( 'Plugin removed from the ignored list.', 'vigilante' ) );
8030 }
8031
8032 /**
8033 * AJAX: Clear the entire ignored-closed-plugins list.
8034 */
8035 public function ajax_clear_ignored_closed_plugins() {
8036 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8037
8038 if ( ! current_user_can( 'manage_options' ) ) {
8039 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8040 }
8041
8042 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
8043 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
8044 }
8045 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
8046 $checker->clear_ignored();
8047
8048 wp_send_json_success( __( 'Ignored closed plugins list cleared.', 'vigilante' ) );
8049 }
8050
8051 /**
8052 * AJAX: Test security headers
8053 */
8054 public function ajax_test_headers() {
8055 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8056
8057 if ( ! current_user_can( 'manage_options' ) ) {
8058 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8059 }
8060
8061 // Get security grade from settings (not from actual HTTP request)
8062 $security_headers = new Vigilante_Security_Headers( $this->settings );
8063 $results = $security_headers->get_security_grade();
8064
8065 wp_send_json_success( $results );
8066 }
8067
8068 /**
8069 * Sanitize section data (kept for compatibility)
8070 *
8071 * @param string $section Section name.
8072 * @param array $data Section data.
8073 * @return array
8074 */
8075 private function sanitize_section_data( $section, $data ) {
8076 $sanitized = array();
8077
8078 foreach ( $data as $key => $value ) {
8079 $key = sanitize_key( $key );
8080
8081 if ( is_array( $value ) ) {
8082 $sanitized[ $key ] = $this->sanitize_section_data( $key, $value );
8083 } elseif ( is_numeric( $value ) ) {
8084 $sanitized[ $key ] = intval( $value );
8085 } else {
8086 $sanitized[ $key ] = sanitize_text_field( $value );
8087 }
8088 }
8089
8090 return $sanitized;
8091 }
8092
8093 /**
8094 * Apply changes after saving settings
8095 *
8096 * @param string $section Section that was updated.
8097 * @param array $all_options All options.
8098 */
8099 private function apply_section_changes( $section, $all_options ) {
8100 // Create fresh settings instance to ensure we have the latest data
8101 $fresh_settings = new Vigilante_Settings();
8102
8103 // The shared Vigilant .htaccess block carries BOTH the firewall's
8104 // file-protection rules and the server-signature / fingerprinting rules
8105 // that are configured under Security Headers. So it must be regenerated
8106 // whenever either section (or the module toggles) changes, not only on
8107 // the firewall save — otherwise toggling "Hide server signature" or
8108 // "Remove fingerprinting headers" never reaches the .htaccess.
8109 if ( in_array( $section, array( 'firewall', 'security_headers', 'modules' ), true ) ) {
8110 $htaccess = new Vigilante_Htaccess_Protection( $fresh_settings );
8111 $sh = $fresh_settings->get_section( 'security_headers' );
8112 $needs_htaccess_block = ! empty( $all_options['modules']['firewall'] )
8113 || ! empty( $sh['hide_server_signature'] )
8114 || ! empty( $sh['remove_fingerprinting_headers'] );
8115
8116 if ( $needs_htaccess_block ) {
8117 $htaccess->apply_rules();
8118 } else {
8119 $htaccess->remove_rules();
8120 }
8121 }
8122
8123 // Regenerate the HTTP security headers (sent by PHP) for the headers section.
8124 if ( 'security_headers' === $section || 'modules' === $section ) {
8125 $security_headers = new Vigilante_Security_Headers( $fresh_settings );
8126 $headers_enabled = ! empty( $all_options['modules']['security_headers'] );
8127
8128 if ( $headers_enabled ) {
8129 $security_headers->apply_rules();
8130 } else {
8131 $security_headers->remove_rules();
8132 }
8133 }
8134
8135 // Regenerate wp-config for wp_hardening section
8136 if ( 'wp_hardening' === $section || 'modules' === $section ) {
8137 $wpconfig = new Vigilante_Wpconfig_Security( $fresh_settings );
8138 $hardening_enabled = ! empty( $all_options['modules']['wp_hardening'] );
8139
8140 if ( $hardening_enabled ) {
8141 $wpconfig->apply_security_constants();
8142 } else {
8143 $wpconfig->remove_constants();
8144 }
8145
8146 // Apply WordPress options for comments/pingbacks
8147 $hardening_options = $all_options['wp_hardening'] ?? array();
8148
8149 if ( $hardening_enabled ) {
8150 // Pingbacks
8151 if ( ! empty( $hardening_options['disable_pingbacks'] ) ) {
8152 update_option( 'default_pingback_flag', 0 );
8153 } else {
8154 // Restore default: pingbacks enabled
8155 update_option( 'default_pingback_flag', 1 );
8156 }
8157
8158 // Trackbacks and ping status
8159 // Only close if either pingbacks OR trackbacks are disabled
8160 if ( ! empty( $hardening_options['disable_pingbacks'] ) || ! empty( $hardening_options['disable_trackbacks'] ) ) {
8161 update_option( 'default_ping_status', 'closed' );
8162 } else {
8163 // Restore default: pings open
8164 update_option( 'default_ping_status', 'open' );
8165 }
8166
8167 // Comment moderation
8168 if ( ! empty( $hardening_options['require_comment_moderation'] ) ) {
8169 update_option( 'comment_moderation', 1 );
8170 } else {
8171 // Restore default: no moderation required
8172 update_option( 'comment_moderation', 0 );
8173 }
8174 }
8175 }
8176
8177 // Trim activity log entries immediately when limits change
8178 if ( 'activity_log' === $section && $this->activity_log ) {
8179 $this->activity_log->cleanup_old_logs();
8180 }
8181
8182 // Flush rewrite rules if login URL changed
8183 if ( 'login_security' === $section ) {
8184 $login_options = $all_options['login_security'] ?? array();
8185 if ( ! empty( $login_options['custom_login_url'] ) ) {
8186 delete_option( 'vigilante_login_rules_version' );
8187 }
8188 }
8189
8190 // Log the settings change with readable section name
8191 if ( $this->activity_log ) {
8192 $section_names = array(
8193 'firewall' => __( 'Firewall', 'vigilante' ),
8194 'login_security' => __( 'Login Security', 'vigilante' ),
8195 'security_headers' => __( 'Security Headers', 'vigilante' ),
8196 'rest_api_security'=> __( 'REST API Security', 'vigilante' ),
8197 'user_security' => __( 'User Security', 'vigilante' ),
8198 'wp_hardening' => __( 'WP Hardening', 'vigilante' ),
8199 'activity_log' => __( 'Security Audit', 'vigilante' ),
8200 'file_integrity' => __( 'File Integrity', 'vigilante' ),
8201 'email' => __( 'Notification Settings', 'vigilante' ),
8202 'backup' => __( 'Backup', 'vigilante' ),
8203 'advanced' => __( 'Advanced', 'vigilante' ),
8204 'modules' => __( 'Modules', 'vigilante' ),
8205 );
8206 $display_name = isset( $section_names[ $section ] ) ? $section_names[ $section ] : $section;
8207
8208 $this->activity_log->log(
8209 'settings',
8210 'settings_updated',
8211 sprintf(
8212 /* translators: %s: Section name */
8213 __( 'Settings updated: %s', 'vigilante' ),
8214 $display_name
8215 ),
8216 array( 'section' => $section ),
8217 'info'
8218 );
8219 }
8220 }
8221
8222 /**
8223 * Apply all file changes (htaccess, wp-config) based on current options
8224 *
8225 * Used after preset, import, or reset operations
8226 *
8227 * @param array $all_options All plugin options.
8228 */
8229 private function apply_all_file_changes( $all_options ) {
8230 // Refresh settings cache first
8231 $this->settings->clear_cache();
8232
8233 // Create fresh settings instance
8234 $fresh_settings = new Vigilante_Settings();
8235
8236 // Apply firewall htaccess changes
8237 $htaccess = new Vigilante_Htaccess_Protection( $fresh_settings );
8238 $firewall_enabled = ! empty( $all_options['modules']['firewall'] );
8239
8240 if ( $firewall_enabled ) {
8241 $htaccess->apply_rules();
8242 } else {
8243 $htaccess->remove_rules();
8244 }
8245
8246 // Apply security headers htaccess changes
8247 $security_headers = new Vigilante_Security_Headers( $fresh_settings );
8248 $headers_enabled = ! empty( $all_options['modules']['security_headers'] );
8249
8250 if ( $headers_enabled ) {
8251 $security_headers->apply_rules();
8252 } else {
8253 $security_headers->remove_rules();
8254 }
8255
8256 // Apply wp-config changes
8257 $wpconfig = new Vigilante_Wpconfig_Security( $fresh_settings );
8258 $hardening_enabled = ! empty( $all_options['modules']['wp_hardening'] );
8259
8260 if ( $hardening_enabled ) {
8261 $wpconfig->apply_security_constants();
8262 } else {
8263 $wpconfig->remove_constants();
8264 }
8265
8266 // Apply WordPress options for comments/pingbacks
8267 $hardening_options = $all_options['wp_hardening'] ?? array();
8268
8269 if ( $hardening_enabled ) {
8270 // Pingbacks
8271 if ( ! empty( $hardening_options['disable_pingbacks'] ) ) {
8272 update_option( 'default_pingback_flag', 0 );
8273 } else {
8274 // Restore default: pingbacks enabled
8275 update_option( 'default_pingback_flag', 1 );
8276 }
8277
8278 // Trackbacks and ping status
8279 // Only close if either pingbacks OR trackbacks are disabled
8280 if ( ! empty( $hardening_options['disable_pingbacks'] ) || ! empty( $hardening_options['disable_trackbacks'] ) ) {
8281 update_option( 'default_ping_status', 'closed' );
8282 } else {
8283 // Restore default: pings open
8284 update_option( 'default_ping_status', 'open' );
8285 }
8286
8287 // Comment moderation
8288 if ( ! empty( $hardening_options['require_comment_moderation'] ) ) {
8289 update_option( 'comment_moderation', 1 );
8290 } else {
8291 // Restore default: no moderation required
8292 update_option( 'comment_moderation', 0 );
8293 }
8294 }
8295
8296 // Log the change
8297 if ( $this->activity_log ) {
8298 $this->activity_log->log(
8299 'settings',
8300 'bulk_settings_applied',
8301 __( 'Bulk settings applied (preset/import/reset)', 'vigilante' ),
8302 array(),
8303 'info'
8304 );
8305 }
8306 }
8307 }