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

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

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