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

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

8,105 lines 519.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin Class
4 *
5 * Handles admin interface and settings page
6 *
7 * @package Vigilante
8 */
9
10 // Prevent direct access
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 // Load AJAX trait
16 require_once VIGILANTE_ADMIN_DIR . 'class-admin-ajax.php';
17
18 // Load promotional banner class
19 require_once VIGILANTE_INCLUDES_DIR . 'class-ayudawp-promo-banner.php';
20
21 /**
22 * Class Vigilante_Admin
23 *
24 * Manages the admin settings interface
25 */
26 class Vigilante_Admin {
27
28 use Vigilante_Admin_Ajax;
29 use Vigilante_Admin_Analyzer_Ajax;
30 use Vigilante_Admin_Audit_Alerts_Ajax;
31 use Vigilante_Admin_Recovery_Ajax;
32
33 /**
34 * Settings instance
35 *
36 * @var Vigilante_Settings
37 */
38 private $settings;
39
40 /**
41 * Database instance
42 *
43 * @var Vigilante_Database
44 */
45 private $database;
46
47 /**
48 * Activity log instance
49 *
50 * @var Vigilante_Activity_Log
51 */
52 private $activity_log;
53
54 /**
55 * Current tab
56 *
57 * @var string
58 */
59 private $current_tab = 'dashboard';
60
61 /**
62 * Available tabs
63 *
64 * @var array
65 */
66 private $tabs = array();
67
68 /**
69 * Constructor
70 *
71 * @param Vigilante_Settings $settings Settings instance.
72 * @param Vigilante_Database $database Database instance.
73 * @param Vigilante_Activity_Log $activity_log Activity log instance.
74 */
75 public function __construct( $settings, $database, $activity_log ) {
76 $this->settings = $settings;
77 $this->database = $database;
78 $this->activity_log = $activity_log;
79
80 $this->setup_tabs();
81 $this->init_hooks();
82 }
83
84 /**
85 * Setup available tabs
86 */
87 private function setup_tabs() {
88 $this->tabs = array(
89 'dashboard' => __( 'Dashboard', 'vigilante' ),
90 'firewall' => __( 'Firewall', 'vigilante' ),
91 'headers' => __( 'Security Headers', 'vigilante' ),
92 'login' => __( 'Login Security', 'vigilante' ),
93 'rest-api' => __( 'REST API', 'vigilante' ),
94 'users' => __( 'User Security', 'vigilante' ),
95 'wp-hardening' => __( 'WP Hardening', 'vigilante' ),
96 'file-integrity' => __( 'File Integrity', 'vigilante' ),
97 'activity-log' => __( 'Security Audit', 'vigilante' ),
98 'tools' => __( 'Settings & Tools', 'vigilante' ),
99 );
100 }
101
102 /**
103 * Initialize hooks
104 */
105 private function init_hooks() {
106 add_action( 'admin_menu', array( $this, 'add_menu' ) );
107 add_action( 'admin_init', array( $this, 'redirect_submenu_shortcuts' ) );
108 add_action( 'admin_init', array( $this, 'register_settings' ) );
109 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
110 add_action( 'admin_notices', array( $this, 'show_admin_notices' ) );
111
112 // Highlight correct submenu based on active tab
113 add_filter( 'submenu_file', array( $this, 'highlight_submenu_tab' ) );
114
115 // Set browser tab title to show plugin name and active tab
116 add_filter( 'admin_title', array( $this, 'set_admin_page_title' ), 10, 2 );
117
118 // AJAX handlers
119 add_action( 'wp_ajax_vigilante_save_settings', array( $this, 'ajax_save_settings' ) );
120 add_action( 'wp_ajax_vigilante_apply_preset', array( $this, 'ajax_apply_preset' ) );
121 add_action( 'wp_ajax_vigilante_reset_section', array( $this, 'ajax_reset_section' ) );
122 add_action( 'wp_ajax_vigilante_clear_lockouts', array( $this, 'ajax_clear_lockouts' ) );
123 add_action( 'wp_ajax_vigilante_clear_logs', array( $this, 'ajax_clear_logs' ) );
124 add_action( 'wp_ajax_vigilante_run_scan', array( $this, 'ajax_run_scan' ) );
125 add_action( 'wp_ajax_vigilante_clear_scan', array( $this, 'ajax_clear_scan' ) );
126 add_action( 'wp_ajax_vigilante_ignore_file', array( $this, 'ajax_ignore_file' ) );
127 add_action( 'wp_ajax_vigilante_unignore_file', array( $this, 'ajax_unignore_file' ) );
128 add_action( 'wp_ajax_vigilante_bulk_ignore_files', array( $this, 'ajax_bulk_ignore_files' ) );
129 add_action( 'wp_ajax_vigilante_bulk_unignore_files', array( $this, 'ajax_bulk_unignore_files' ) );
130 add_action( 'wp_ajax_vigilante_clear_ignored', array( $this, 'ajax_clear_ignored' ) );
131 add_action( 'wp_ajax_vigilante_ignore_closed_plugin', array( $this, 'ajax_ignore_closed_plugin' ) );
132 add_action( 'wp_ajax_vigilante_unignore_closed_plugin', array( $this, 'ajax_unignore_closed_plugin' ) );
133 add_action( 'wp_ajax_vigilante_clear_ignored_closed_plugins', array( $this, 'ajax_clear_ignored_closed_plugins' ) );
134 add_action( 'wp_ajax_vigilante_approve_critical_file', array( $this, 'ajax_approve_critical_file' ) );
135 add_action( 'wp_ajax_vigilante_export_settings', array( $this, 'ajax_export_settings' ) );
136 add_action( 'wp_ajax_vigilante_import_settings', array( $this, 'ajax_import_settings' ) );
137 add_action( 'wp_ajax_vigilante_get_logs', array( $this, 'ajax_get_logs' ) );
138 add_action( 'wp_ajax_vigilante_test_headers', array( $this, 'ajax_test_headers' ) );
139 add_action( 'wp_ajax_vigilante_download_files_backup', array( $this, 'ajax_download_files_backup' ) );
140
141 // 2FA AJAX handlers
142 add_action( 'wp_ajax_vigilante_search_users_2fa', array( $this, 'ajax_search_users_2fa' ) );
143 add_action( 'wp_ajax_vigilante_send_2fa_notification', array( $this, 'ajax_send_2fa_notification' ) );
144 add_action( 'wp_ajax_vigilante_search_totp_users', array( $this, 'ajax_search_totp_users' ) );
145 add_action( 'wp_ajax_vigilante_reset_totp_users', array( $this, 'ajax_reset_totp_users' ) );
146 add_action( 'wp_ajax_vigilante_totp_get_setup', array( $this, 'ajax_totp_get_setup' ) );
147 add_action( 'wp_ajax_vigilante_notify_login_url', array( $this, 'ajax_notify_login_url' ) );
148
149 // Password Reset AJAX handlers
150 add_action( 'wp_ajax_vigilante_search_users_password_reset', array( $this, 'ajax_search_users_password_reset' ) );
151 add_action( 'wp_ajax_vigilante_force_password_reset', array( $this, 'ajax_force_password_reset' ) );
152 add_action( 'wp_ajax_vigilante_force_password_reset_all', array( $this, 'ajax_force_password_reset_all' ) );
153 add_action( 'wp_ajax_vigilante_force_password_reset_by_role', array( $this, 'ajax_force_password_reset_by_role' ) );
154
155 // User approval AJAX handlers
156 add_action( 'wp_ajax_vigilante_approve_user', array( $this, 'ajax_approve_user' ) );
157 add_action( 'wp_ajax_vigilante_reject_user', array( $this, 'ajax_reject_user' ) );
158
159 // Session management AJAX handlers
160 add_action( 'wp_ajax_vigilante_get_user_sessions', array( $this, 'ajax_get_user_sessions' ) );
161 add_action( 'wp_ajax_vigilante_revoke_session', array( $this, 'ajax_revoke_session' ) );
162 add_action( 'wp_ajax_vigilante_revoke_all_sessions', array( $this, 'ajax_revoke_all_sessions' ) );
163
164 // Under Attack mode AJAX handlers
165 add_action( 'wp_ajax_vigilante_activate_under_attack', array( $this, 'ajax_activate_under_attack' ) );
166 add_action( 'wp_ajax_vigilante_deactivate_under_attack', array( $this, 'ajax_deactivate_under_attack' ) );
167 add_action( 'wp_ajax_vigilante_under_attack_status', array( $this, 'ajax_under_attack_status' ) );
168
169 // Database backup AJAX handlers
170 add_action( 'wp_ajax_vigilante_get_db_tables', array( $this, 'ajax_get_db_tables' ) );
171 add_action( 'wp_ajax_vigilante_download_db_backup', array( $this, 'ajax_download_db_backup' ) );
172
173 // Database prefix AJAX handlers
174 add_action( 'wp_ajax_vigilante_generate_prefix', array( $this, 'ajax_generate_prefix' ) );
175 add_action( 'wp_ajax_vigilante_change_prefix', array( $this, 'ajax_change_prefix' ) );
176
177 // Firewall list management from activity log popup
178 add_action( 'wp_ajax_vigilante_add_to_firewall_list', array( $this, 'ajax_add_to_firewall_list' ) );
179 add_action( 'wp_ajax_vigilante_unblock_firewall_ip', array( $this, 'ajax_unblock_firewall_ip' ) );
180
181 // Security Analyzer AJAX handlers (v2.1.0)
182 add_action( 'wp_ajax_vigilante_analyzer_run', array( $this, 'ajax_analyzer_run' ) );
183 add_action( 'wp_ajax_vigilante_analyzer_history', array( $this, 'ajax_analyzer_history' ) );
184 add_action( 'wp_ajax_vigilante_analyzer_dismiss_notice', array( $this, 'ajax_analyzer_dismiss_notice' ) );
185 add_action( 'wp_ajax_vigilante_analyzer_save_settings', array( $this, 'ajax_analyzer_save_settings' ) );
186
187 // Security Headers settings recovery (2.10.0)
188 add_action( 'wp_ajax_vigilante_headers_recovery_restore', array( $this, 'ajax_headers_recovery_restore' ) );
189 add_action( 'wp_ajax_vigilante_headers_recovery_undo', array( $this, 'ajax_headers_recovery_undo' ) );
190 add_action( 'wp_ajax_vigilante_headers_recovery_dismiss', array( $this, 'ajax_headers_recovery_dismiss' ) );
191
192 // Shared "Send test email" handler — Notification settings, File Integrity, Audit Alerts (v2.8.0)
193 add_action( 'wp_ajax_vigilante_send_test_email', array( $this, 'ajax_send_test_email' ) );
194
195 // Run migrations on admin load
196 add_action( 'admin_init', array( $this, 'run_migrations' ) );
197 }
198
199 /**
200 * Run database migrations based on stored version
201 */
202 public function run_migrations() {
203 $db_version = get_option( 'vigilante_db_version', '0' );
204
205 // 1.2.3: Fix IP lists corrupted by sanitize_text_field stripping newlines
206 if ( version_compare( $db_version, '1.2.3', '<' ) ) {
207 $this->migrate_fix_ip_lists();
208 update_option( 'vigilante_db_version', '1.2.3' );
209 }
210
211 // 1.3.0: Add request_method column to activity log table
212 if ( version_compare( $db_version, '1.3.0', '<' ) ) {
213 $this->database->run_migrations();
214 }
215
216 // 1.9.0: Re-apply wp-config constants (performance constants removed from managed list)
217 if ( version_compare( $db_version, '1.9.0', '<' ) ) {
218 if ( $this->settings->is_module_enabled( 'wp_hardening' ) ) {
219 require_once VIGILANTE_INCLUDES_DIR . 'class-wpconfig-security.php';
220 $wpconfig = new Vigilante_Wpconfig_Security( $this->settings );
221 $wpconfig->apply_security_constants();
222 }
223 update_option( 'vigilante_db_version', '1.9.0' );
224 }
225
226 // 1.10.0: Clean up orphaned email fields (centralized notification recipients)
227 if ( version_compare( $db_version, '1.10.0', '<' ) ) {
228 $this->migrate_cleanup_email_fields();
229 update_option( 'vigilante_db_version', '1.10.0' );
230 }
231
232 // 1.11.0: Remove stale 'enabled' key from activity_log settings
233 // + Convert additional_recipients from string to array
234 if ( version_compare( $db_version, '1.11.0', '<' ) ) {
235 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
236 $changed = false;
237
238 if ( isset( $options['activity_log']['enabled'] ) ) {
239 unset( $options['activity_log']['enabled'] );
240 $changed = true;
241 }
242
243 // Convert corrupted string to array for additional_recipients
244 if ( isset( $options['email']['additional_recipients'] ) && is_string( $options['email']['additional_recipients'] ) ) {
245 $raw = trim( $options['email']['additional_recipients'] );
246 if ( ! empty( $raw ) ) {
247 $emails = array_filter( array_map( 'trim', preg_split( '/[\r\n,; ]+/', $raw ) ) );
248 $options['email']['additional_recipients'] = array_values( array_filter( $emails, 'is_email' ) );
249 } else {
250 $options['email']['additional_recipients'] = array();
251 }
252 $changed = true;
253 }
254
255 if ( $changed ) {
256 update_option( Vigilante_Settings::OPTION_NAME, $options );
257 }
258 update_option( 'vigilante_db_version', '1.11.0' );
259 }
260
261 // 1.12.1: Regenerate htaccess (WooCommerce IPN exclusion in bot blocking rule)
262 if ( version_compare( $db_version, '1.12.1', '<' ) ) {
263 if ( ! empty( $this->settings->get_section( 'firewall' )['block_bad_bots'] ) ) {
264 require_once VIGILANTE_INCLUDES_DIR . 'class-htaccess-protection.php';
265 $htaccess = new Vigilante_Htaccess_Protection( $this->settings );
266 $htaccess->apply_rules();
267 }
268 update_option( 'vigilante_db_version', '1.12.1' );
269 }
270
271 // 1.14.0: Generate critical config files baseline (wp-config.php, .htaccess)
272 if ( version_compare( $db_version, '1.14.0', '<' ) ) {
273 if ( ! class_exists( 'Vigilante_File_Integrity' ) ) {
274 require_once VIGILANTE_INCLUDES_DIR . 'class-file-integrity.php';
275 }
276 $fi = new Vigilante_File_Integrity( $this->settings, $this->database, $this->activity_log );
277
278 /*
279 * Only when there is nothing on record. This migration exists to
280 * create the baseline that did not exist, never to discard the one
281 * the owner approved: rebuilding it from the files takes whatever
282 * is on disk right now as approved, so a wp-config.php modified and
283 * awaiting review would be blessed in silence.
284 *
285 * And this is not theory. vigilante_db_version is written on two
286 * different scales into the same option: this file counts in plugin
287 * versions (2.11.0) and Vigilante_Database counts in schema
288 * versions, currently 1.4.0 (class-database.php:322 and :380). For
289 * version_compare, 1.4.0 is LOWER than 1.14.0, so any site whose
290 * option was last written by the schema runs this migration again.
291 * Measured on the Multisite install on 10 sep 2026: one of the three
292 * sites was sitting on 1.4.0.
293 */
294 if ( ! $fi->get_critical_files_baseline() ) {
295 $fi->regenerate_all_baselines();
296 }
297
298 update_option( 'vigilante_db_version', '1.14.0' );
299 }
300
301 // 2.0.0: Move hide_server_signature and remove_fingerprinting_headers
302 // from firewall section to security_headers section
303 if ( version_compare( $db_version, '2.0.0', '<' ) ) {
304 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
305 $changed = false;
306
307 foreach ( array( 'hide_server_signature', 'remove_fingerprinting_headers' ) as $key ) {
308 if ( isset( $options['firewall'][ $key ] ) ) {
309 if ( ! isset( $options['security_headers'][ $key ] ) ) {
310 $options['security_headers'][ $key ] = $options['firewall'][ $key ];
311 }
312 unset( $options['firewall'][ $key ] );
313 $changed = true;
314 }
315 }
316
317 if ( $changed ) {
318 update_option( Vigilante_Settings::OPTION_NAME, $options );
319 }
320 update_option( 'vigilante_db_version', '2.0.0' );
321 }
322
323 // 2.6.1: Two things happen here.
324 //
325 // 1. Re-apply wp-config constants so the block is rewritten with
326 // "if ( ! defined() )" guards around every define(). Without guards,
327 // non-standard setups that pre-define WordPress constants outside
328 // wp-config.php (custom bootstraps that load constants from .env or
329 // similar) hit a fatal "Constant already defined" when wp-config.php
330 // is parsed and reaches our block.
331 //
332 // 2. Drop the cached Security Check report. The cached "max" per
333 // category was frozen at scan time; with the internal category
334 // bumping from 22 to 28 points (closed_plugins added in 2.6.0),
335 // the cached report would keep displaying 22/22 until the next
336 // full scan. Clearing it forces a fresh scan with the new caps.
337 if ( version_compare( $db_version, '2.6.1', '<' ) ) {
338 if ( $this->settings->is_module_enabled( 'wp_hardening' ) ) {
339 require_once VIGILANTE_INCLUDES_DIR . 'class-wpconfig-security.php';
340 $wpconfig = new Vigilante_Wpconfig_Security( $this->settings );
341 $wpconfig->apply_security_constants();
342 }
343 delete_option( 'vigilante_analyzer_last_scan' );
344
345 // Schedule an immediate background scan so the dashboard widget
346 // doesn't display "Last scan: never" right after the upgrade.
347 // Reuses the same hook the post-Under-Attack flow uses.
348 if ( ! wp_next_scheduled( 'vigilante_under_attack_post_scan' ) ) {
349 wp_schedule_single_event( time() + 5, 'vigilante_under_attack_post_scan' );
350 }
351
352 update_option( 'vigilante_db_version', '2.6.1' );
353 }
354
355 // 2.9.3: Regenerate the .htaccess protection block. The bad-bots
356 // User-Agent list dropped substring-prone tokens that 403'd
357 // legitimate clients (e.g. "rma" matched inside "Performance" and
358 // blocked WP Rocket's page fetch), and the blocking rules now honour
359 // the firewall IP / User-Agent whitelists as negated exceptions.
360 // Existing sites only rewrite the block when Server Protection is
361 // saved, so the upgrade has to refresh it once itself (same pattern
362 // as the 1.12.1 WooCommerce IPN migration).
363 if ( version_compare( $db_version, '2.9.3', '<' ) ) {
364 require_once VIGILANTE_INCLUDES_DIR . 'class-htaccess-protection.php';
365 $htaccess = new Vigilante_Htaccess_Protection( $this->settings );
366
367 if ( $htaccess->are_rules_active() ) {
368 $htaccess->apply_rules();
369 }
370
371 update_option( 'vigilante_db_version', '2.9.3' );
372 }
373
374 /*
375 * 2.9.8: the mixed content handling changes shape. "Upgrade Insecure
376 * Requests" becomes a setting of its own, and Fix Mixed Content ships
377 * off, where before it shipped on and carried the directive with it.
378 * Both have to be written down for sites that are updating, so their
379 * pages keep loading exactly what they loaded yesterday.
380 *
381 * Read the RAW stored options, not get_section(): that one merges the
382 * defaults, so a site that never stored the key would be read with the
383 * new default and silently lose the behaviour it had. Absent means the
384 * site was running on the old default, which was on.
385 */
386 if ( version_compare( $db_version, '2.9.8', '<' ) ) {
387 $raw = get_option( Vigilante_Settings::OPTION_NAME, array() );
388 $stored = ( is_array( $raw ) && isset( $raw['security_headers'] ) && is_array( $raw['security_headers'] ) ) ? $raw['security_headers'] : array();
389 $had_fix = array_key_exists( 'fix_mixed_content', $stored ) ? ! empty( $stored['fix_mixed_content'] ) : true;
390
391 /*
392 * Merge, never replace. update_section() overwrites the whole
393 * section, so passing just these two keys wiped every other header
394 * setting the site had stored (HSTS, CSP, cross-origin policies,
395 * the HTTPS switches, Server Identity) and left the screen showing
396 * factory defaults while the .htaccess kept serving the old values.
397 */
398 $this->settings->update_section(
399 'security_headers',
400 array_merge(
401 $stored,
402 array(
403 'fix_mixed_content' => $had_fix,
404 'upgrade_insecure_requests' => $had_fix,
405 )
406 )
407 );
408
409 update_option( 'vigilante_db_version', '2.9.8' );
410 }
411
412 /*
413 * 2.9.9: drop the settings that no code has read for versions.
414 *
415 * They were carried in the defaults and therefore written into every
416 * saved configuration, they show up in an exported configuration, and
417 * anyone reading them assumes a feature exists behind them. Removing
418 * them from the defaults is not enough: the stored copies survive, so
419 * they are swept here too. Nothing reads them, so nothing changes.
420 */
421 if ( version_compare( $db_version, '2.9.9', '<' ) ) {
422 $raw = get_option( Vigilante_Settings::OPTION_NAME, array() );
423 $dead = array(
424 'firewall' => array( 'country_blocking', 'protected_file_extensions' ),
425 'file_integrity' => array( 'suspicious_patterns' ),
426 'backup' => array( 'auto_backup', 'backup_before_update' ),
427 'advanced' => array( 'block_author_archives', 'disable_embeds', 'uninstall_cleanup', 'debug_mode' ),
428 );
429
430 $changed = false;
431 foreach ( $dead as $section => $keys ) {
432 if ( ! isset( $raw[ $section ] ) || ! is_array( $raw[ $section ] ) ) {
433 continue;
434 }
435 foreach ( $keys as $key ) {
436 if ( array_key_exists( $key, $raw[ $section ] ) ) {
437 unset( $raw[ $section ][ $key ] );
438 $changed = true;
439 }
440 }
441 }
442
443 if ( $changed ) {
444 update_option( Vigilante_Settings::OPTION_NAME, $raw );
445 }
446
447 update_option( 'vigilante_db_version', '2.9.9' );
448 }
449
450 /*
451 * 2.11.0: security release (audit of 28 Aug 2026). Runs here and not
452 * from Vigilante_Database::needs_update(): this option is shared with
453 * that class, and on any updated site it already holds a plugin version
454 * (2.9.9 or later), so a bump of DB_VERSION would never fire.
455 * create_tables() widens the email code column through dbDelta (varchar
456 * 6 to 64, the code is stored hashed since 2.11.0) and purge_for_2_11_0()
457 * does what dbDelta cannot: it empties the trusted devices, which were
458 * identified by User-Agent until now (S1), and the pending email codes,
459 * stored in clear until now (S11). Every remembered device asks for the
460 * second factor once more after this update, and the changelog says so.
461 */
462 if ( version_compare( $db_version, '2.11.0', '<' ) ) {
463 $this->database->create_tables();
464 $this->database->purge_for_2_11_0();
465
466 update_option( 'vigilante_db_version', '2.11.0' );
467 }
468 }
469
470 /**
471 * Migration: Remove orphaned email fields from saved options
472 *
473 * v1.10.0 centralized notification recipients into email section.
474 * Old per-module notify_email fields and dead email section fields
475 * are removed to avoid confusion.
476 */
477 private function migrate_cleanup_email_fields() {
478 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
479 $modified = false;
480
481 // Remove orphaned fields from email section
482 $dead_email_keys = array( 'enabled', 'from_name', 'from_email', 'admin_email', 'send_activation_email', 'custom_email' );
483 if ( isset( $options['email'] ) && is_array( $options['email'] ) ) {
484 foreach ( $dead_email_keys as $key ) {
485 if ( array_key_exists( $key, $options['email'] ) ) {
486 unset( $options['email'][ $key ] );
487 $modified = true;
488 }
489 }
490 // Ensure new fields exist with defaults
491 if ( ! array_key_exists( 'send_to_admin_email', $options['email'] ) ) {
492 $options['email']['send_to_admin_email'] = true;
493 $modified = true;
494 }
495 if ( ! array_key_exists( 'additional_recipients', $options['email'] ) ) {
496 $options['email']['additional_recipients'] = '';
497 $modified = true;
498 }
499 }
500
501 // Remove notify_email from login_security
502 if ( isset( $options['login_security']['notify_email'] ) ) {
503 unset( $options['login_security']['notify_email'] );
504 $modified = true;
505 }
506
507 // Remove notify_email from file_integrity
508 if ( isset( $options['file_integrity']['notify_email'] ) ) {
509 unset( $options['file_integrity']['notify_email'] );
510 $modified = true;
511 }
512
513 if ( $modified ) {
514 update_option( Vigilante_Settings::OPTION_NAME, $options );
515 // Clear settings cache so the plugin uses clean data immediately
516 $this->settings->clear_cache();
517 }
518 }
519
520 /**
521 * Migration: Fix IP whitelist/blacklist entries merged into single line
522 *
523 * Prior to 1.2.3, sanitize_text_field() stripped newlines from textarea data,
524 * causing multiple IPs to be stored as a single space-separated string.
525 */
526 private function migrate_fix_ip_lists() {
527 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
528 $fixed = false;
529
530 foreach ( array( 'ip_whitelist', 'ip_blacklist' ) as $key ) {
531 if ( ! empty( $options['firewall'][ $key ] ) && is_array( $options['firewall'][ $key ] ) ) {
532 $new_list = array();
533 foreach ( $options['firewall'][ $key ] as $entry ) {
534 // Split entries that were joined by spaces
535 $parts = preg_split( '/\s+/', trim( $entry ) );
536 foreach ( $parts as $part ) {
537 $part = trim( $part );
538 if ( '' !== $part ) {
539 $new_list[] = $part;
540 }
541 }
542 }
543 if ( count( $new_list ) !== count( $options['firewall'][ $key ] ) ) {
544 $options['firewall'][ $key ] = array_unique( $new_list );
545 $fixed = true;
546 }
547 }
548 }
549
550 if ( $fixed ) {
551 update_option( Vigilante_Settings::OPTION_NAME, $options );
552 // Clear settings cache so changes take effect immediately
553 $this->settings->clear_cache();
554 }
555 }
556
557 /**
558 * Add admin menu page in last position
559 */
560 public function add_menu() {
561 $menu_title = __( 'Vigilant', 'vigilante' );
562
563 // Count pending approvals (separate concern, always red if present)
564 $pending_count = $this->get_pending_approvals_count();
565
566 // Get security issues with severity
567 $security_status = $this->get_security_status_for_badge();
568
569 // Total count for badge
570 $total_badge = $pending_count + $security_status['count'];
571
572 if ( $total_badge > 0 ) {
573 // Determine badge color:
574 // - Red (awaiting-mod): pending approvals OR critical modules disabled
575 // - Orange (update-plugins): only non-critical modules disabled
576 if ( $pending_count > 0 || $security_status['has_critical'] ) {
577 $badge_class = 'awaiting-mod';
578 } else {
579 $badge_class = 'update-plugins vigilante-badge-warning';
580 }
581
582 $menu_title .= sprintf(
583 ' <span class="%s count-%d"><span class="pending-count">%d</span></span>',
584 esc_attr( $badge_class ),
585 $total_badge,
586 $total_badge
587 );
588 }
589
590 add_menu_page(
591 __( 'Vigilant', 'vigilante' ),
592 $menu_title,
593 'manage_options',
594 'vigilante',
595 array( $this, 'render_settings_page' ),
596 'dashicons-shield',
597 999
598 );
599
600 // Rename auto-generated first submenu to "Dashboard"
601 add_submenu_page(
602 'vigilante',
603 __( 'Dashboard', 'vigilante' ),
604 __( 'Dashboard', 'vigilante' ),
605 'manage_options',
606 'vigilante',
607 array( $this, 'render_settings_page' )
608 );
609
610 // Security Audit shortcut
611 add_submenu_page(
612 'vigilante',
613 __( 'Security Audit', 'vigilante' ),
614 __( 'Security Audit', 'vigilante' ),
615 'manage_options',
616 'vigilante-activity-log',
617 array( $this, 'redirect_to_tab' )
618 );
619
620 // File Integrity shortcut
621 add_submenu_page(
622 'vigilante',
623 __( 'File Integrity', 'vigilante' ),
624 __( 'File Integrity', 'vigilante' ),
625 'manage_options',
626 'vigilante-file-integrity',
627 array( $this, 'redirect_to_tab' )
628 );
629 }
630
631 /**
632 * Redirect submenu shortcuts early, before headers are sent
633 */
634 public function redirect_submenu_shortcuts() {
635 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Just reading page slug for redirect
636 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
637
638 $tab_map = array(
639 'vigilante-activity-log' => 'activity-log',
640 'vigilante-file-integrity' => 'file-integrity',
641 );
642
643 if ( isset( $tab_map[ $page ] ) ) {
644 wp_safe_redirect( admin_url( 'admin.php?page=vigilante&tab=' . $tab_map[ $page ] ) );
645 exit;
646 }
647 }
648
649 /**
650 * Fallback redirect for submenu shortcuts (JS-based)
651 */
652 public function redirect_to_tab() {
653 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Just reading page slug for redirect
654 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
655
656 $tab_map = array(
657 'vigilante-activity-log' => 'activity-log',
658 'vigilante-file-integrity' => 'file-integrity',
659 );
660
661 if ( isset( $tab_map[ $page ] ) ) {
662 $url = admin_url( 'admin.php?page=vigilante&tab=' . $tab_map[ $page ] );
663 echo '<script>window.location.replace(' . wp_json_encode( esc_url( $url ) ) . ');</script>';
664 }
665 }
666
667 /**
668 * Highlight the correct submenu item based on active tab
669 *
670 * @param string $submenu_file Current submenu file.
671 * @return string
672 */
673 public function highlight_submenu_tab( $submenu_file ) {
674 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading tab for menu highlight only
675 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
676 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
677 $tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : '';
678
679 if ( 'vigilante' !== $page || empty( $tab ) ) {
680 return $submenu_file;
681 }
682
683 $tab_to_submenu = array(
684 'activity-log' => 'vigilante-activity-log',
685 'file-integrity' => 'vigilante-file-integrity',
686 );
687
688 if ( isset( $tab_to_submenu[ $tab ] ) ) {
689 return $tab_to_submenu[ $tab ];
690 }
691
692 return $submenu_file;
693 }
694
695 /**
696 * Set browser tab title to show plugin name and active tab
697 *
698 * Changes "Dashboard ‹ Site Name — WordPress" to
699 * "Vigilant > Dashboard ‹ Site Name — WordPress"
700 *
701 * @param string $admin_title Full admin title.
702 * @param string $title Page title from add_menu_page/add_submenu_page.
703 * @return string Modified title.
704 */
705 public function set_admin_page_title( $admin_title, $title ) {
706 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading page slug for title only
707 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
708
709 // Only modify on Vigilante pages
710 if ( 0 !== strpos( $page, 'vigilante' ) ) {
711 return $admin_title;
712 }
713
714 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
715 $tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'dashboard';
716
717 if ( isset( $this->tabs[ $tab ] ) ) {
718 $tab_label = $this->tabs[ $tab ];
719 } else {
720 $tab_label = __( 'Dashboard', 'vigilante' );
721 }
722
723 $plugin_title = __( 'Vigilant', 'vigilante' ) . ' &rsaquo; ' . $tab_label;
724
725 // Replace the original page title portion
726 return str_replace( $title, $plugin_title, $admin_title );
727 }
728
729 /**
730 * Get count of users pending approval
731 *
732 * @return int Count of pending users.
733 */
734 private function get_pending_approvals_count() {
735 // Prevent early execution before WordPress is ready
736 if ( ! did_action( 'plugins_loaded' ) ) {
737 return 0;
738 }
739
740 $registration_approval = $this->settings->get_section( 'user_security' );
741 $approval_settings = $registration_approval['registration_approval'] ?? array();
742
743 if ( empty( $approval_settings['enabled'] ) ) {
744 return 0;
745 }
746
747 // phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_key, WordPress.DB.SlowDBQuery.slow_db_query_meta_value -- Limited results in admin context.
748 $pending_users = get_users( array(
749 'meta_key' => 'vigilante_pending_approval',
750 'meta_value' => '1',
751 'fields' => 'ID',
752 ) );
753 // phpcs:enable WordPress.DB.SlowDBQuery.slow_db_query_meta_key, WordPress.DB.SlowDBQuery.slow_db_query_meta_value
754
755 return count( $pending_users );
756 }
757
758 /**
759 * Calculate comprehensive security score (0-100)
760 *
761 * @param array $options Plugin options.
762 * @return int Security score.
763 */
764 private function calculate_security_score( $options ) {
765 $score = 0;
766 $max_score = 0;
767
768 // Module scores (60 points total)
769 $module_weights = array(
770 'firewall' => 10,
771 'security_headers' => 8,
772 'login_security' => 10,
773 'rest_api_security' => 6,
774 'user_security' => 8,
775 'wp_hardening' => 8,
776 'file_integrity' => 5,
777 'activity_log' => 5,
778 );
779
780 foreach ( $module_weights as $module => $weight ) {
781 $max_score += $weight;
782 if ( ! empty( $options['modules'][ $module ] ) ) {
783 $score += $weight;
784 }
785 }
786
787 // Firewall details (10 points)
788 if ( ! empty( $options['modules']['firewall'] ) ) {
789 $firewall = $options['firewall'] ?? array();
790 $max_score += 10;
791
792 $firewall_checks = array(
793 'block_sql_injection',
794 'block_xss_attacks',
795 'block_bad_query_strings',
796 'block_file_inclusion',
797 'block_directory_traversal',
798 );
799
800 $firewall_enabled = 0;
801 foreach ( $firewall_checks as $check ) {
802 if ( ! empty( $firewall[ $check ] ) ) {
803 $firewall_enabled++;
804 }
805 }
806 $score += min( 10, $firewall_enabled * 2 );
807 }
808
809 // Login security details (10 points)
810 if ( ! empty( $options['modules']['login_security'] ) ) {
811 $login = $options['login_security'] ?? array();
812 $max_score += 10;
813
814 // Max attempts configured
815 if ( isset( $login['max_attempts'] ) && $login['max_attempts'] <= 5 ) {
816 $score += 3;
817 }
818 // XML-RPC disabled
819 if ( ! empty( $login['disable_xmlrpc'] ) ) {
820 $score += 3;
821 }
822 // 2FA enabled
823 if ( ! empty( $login['two_factor']['enabled'] ) ) {
824 $score += 4;
825 }
826 }
827
828 // Security headers details (10 points)
829 if ( ! empty( $options['modules']['security_headers'] ) ) {
830 $headers = $options['security_headers'] ?? array();
831 $max_score += 10;
832
833 if ( ! empty( $headers['x_frame_options'] ) ) {
834 $score += 2;
835 }
836 if ( ! empty( $headers['x_content_type_options'] ) ) {
837 $score += 2;
838 }
839 if ( ! empty( $headers['hsts']['enabled'] ) ) {
840 $score += 3;
841 }
842 if ( ! empty( $headers['csp']['enabled'] ) ) {
843 $score += 3;
844 }
845 }
846
847 // User security details (10 points)
848 if ( ! empty( $options['modules']['user_security'] ) ) {
849 $user = $options['user_security'] ?? array();
850 $max_score += 10;
851
852 if ( ! empty( $user['block_insecure_usernames'] ) ) {
853 $score += 3;
854 }
855 if ( ! empty( $user['force_strong_passwords'] ) ) {
856 $score += 3;
857 }
858 if ( ! empty( $user['password_expiration']['enabled'] ) ) {
859 $score += 2;
860 }
861 if ( ! empty( $user['email_verification']['enabled'] ) ) {
862 $score += 2;
863 }
864 }
865
866 // Audit alerts details (6 points) - only when Security Audit is on,
867 // because the alerting layer rides on top of the activity log. Leaving
868 // both alert legs off keeps these points unearned.
869 if ( ! empty( $options['modules']['activity_log'] ) ) {
870 $alerts = isset( $options['audit_alerts'] ) ? (array) $options['audit_alerts'] : array();
871 $max_score += 6;
872 if ( Vigilante_Audit_Alerts::immediate_is_active( $alerts ) ) {
873 $score += 3;
874 }
875 if ( Vigilante_Audit_Alerts::threshold_is_active( $alerts ) ) {
876 $score += 3;
877 }
878 }
879
880 // Environment checks (8 points) - penalize insecure server configuration
881 $max_score += 8;
882 $env_score = 8;
883
884 // WP_DEBUG active in production is a security risk (exposes paths, errors)
885 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
886 $env_score -= 5;
887 }
888
889 // Accounts with insecure usernames (targeted by brute force attacks)
890 $insecure_admins = $this->get_insecure_admin_usernames();
891 if ( ! empty( $insecure_admins ) ) {
892 $env_score -= 3;
893 }
894
895 $score += max( 0, $env_score );
896
897 return $max_score > 0 ? round( ( $score / $max_score ) * 100 ) : 0;
898 }
899
900 /**
901 * Get security recommendations based on current settings
902 *
903 * @param array $options Plugin options.
904 * @return array Array of recommendations.
905 */
906 private function get_security_recommendations( $options ) {
907 $recommendations = array();
908
909 // Critical: Firewall disabled
910 if ( empty( $options['modules']['firewall'] ) ) {
911 $recommendations[] = array(
912 'icon' => 'warning',
913 'priority' => 'critical',
914 'message' => __( 'Enable Firewall to protect against common attacks.', 'vigilante' ),
915 );
916 }
917
918 // Critical: Login security disabled
919 if ( empty( $options['modules']['login_security'] ) ) {
920 $recommendations[] = array(
921 'icon' => 'warning',
922 'priority' => 'critical',
923 'message' => __( 'Enable Login Security to prevent brute force attacks.', 'vigilante' ),
924 );
925 }
926
927 // High: Security headers disabled
928 if ( empty( $options['modules']['security_headers'] ) ) {
929 $recommendations[] = array(
930 'icon' => 'admin-generic',
931 'priority' => 'high',
932 'message' => __( 'Enable Security Headers to protect against clickjacking and XSS.', 'vigilante' ),
933 );
934 }
935
936 // High: User security disabled
937 if ( empty( $options['modules']['user_security'] ) ) {
938 $recommendations[] = array(
939 'icon' => 'admin-users',
940 'priority' => 'high',
941 'message' => __( 'Enable User Security to enforce password policies and username protection.', 'vigilante' ),
942 );
943 }
944
945 // High: 2FA not enabled (only if login security is active)
946 $login = $options['login_security'] ?? array();
947 if ( ! empty( $options['modules']['login_security'] ) && empty( $login['two_factor']['enabled'] ) ) {
948 $recommendations[] = array(
949 'icon' => 'shield',
950 'priority' => 'high',
951 'message' => __( 'Enable Two-Factor Authentication for enhanced login security.', 'vigilante' ),
952 'tab' => 'login',
953 );
954 }
955
956 // Medium: REST API security disabled
957 if ( empty( $options['modules']['rest_api_security'] ) ) {
958 $recommendations[] = array(
959 'icon' => 'rest-api',
960 'priority' => 'medium',
961 'message' => __( 'Enable REST API Security to control API access and prevent enumeration.', 'vigilante' ),
962 );
963 }
964
965 // Medium: WP Hardening disabled
966 if ( empty( $options['modules']['wp_hardening'] ) ) {
967 $recommendations[] = array(
968 'icon' => 'lock',
969 'priority' => 'medium',
970 'message' => __( 'Enable WP Hardening to remove version info and protect core files.', 'vigilante' ),
971 );
972 }
973
974 // Medium: File integrity disabled
975 if ( empty( $options['modules']['file_integrity'] ) ) {
976 $recommendations[] = array(
977 'icon' => 'media-text',
978 'priority' => 'medium',
979 'message' => __( 'Enable File Integrity to detect unauthorized file changes.', 'vigilante' ),
980 );
981 }
982
983 // Medium: Security Audit disabled
984 if ( empty( $options['modules']['activity_log'] ) ) {
985 $recommendations[] = array(
986 'icon' => 'list-view',
987 'priority' => 'medium',
988 'message' => __( 'Enable Security Audit to track security events.', 'vigilante' ),
989 );
990 }
991
992 // Low: XML-RPC enabled (only if login security is active)
993 if ( ! empty( $options['modules']['login_security'] ) && empty( $login['disable_xmlrpc'] ) ) {
994 $recommendations[] = array(
995 'icon' => 'info',
996 'priority' => 'low',
997 'message' => __( 'Disable XML-RPC if not needed (reduces attack surface).', 'vigilante' ),
998 'tab' => 'login',
999 );
1000 }
1001
1002 // Low: Strong passwords not enforced (only if user security is active)
1003 $user = $options['user_security'] ?? array();
1004 if ( ! empty( $options['modules']['user_security'] ) && empty( $user['force_strong_passwords'] ) ) {
1005 $recommendations[] = array(
1006 'icon' => 'admin-users',
1007 'priority' => 'low',
1008 'message' => __( 'Enforce strong passwords for all users.', 'vigilante' ),
1009 'tab' => 'users',
1010 );
1011 }
1012
1013 // High: WP_DEBUG active in production (regardless of Vigilante settings)
1014 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
1015 $recommendations[] = array(
1016 'icon' => 'warning',
1017 'priority' => 'high',
1018 'message' => __( 'WP_DEBUG is active. Debug mode exposes sensitive information and should be disabled in production.', 'vigilante' ),
1019 'tab' => 'wp-hardening',
1020 );
1021 }
1022
1023 // Low: Users with display name matching login username (only if user security active)
1024 if ( ! empty( $options['modules']['user_security'] ) ) {
1025 $exposed_users = $this->get_users_with_exposed_login();
1026 if ( ! empty( $exposed_users ) ) {
1027 $recommendations[] = array(
1028 'icon' => 'admin-users',
1029 'priority' => 'low',
1030 'message' => sprintf(
1031 /* translators: %s: Comma-separated list of usernames */
1032 __( 'These users have their login username as display name (publicly visible): %s', 'vigilante' ),
1033 implode( ', ', $exposed_users )
1034 ),
1035 'tab' => 'users',
1036 );
1037 }
1038 }
1039
1040 // High: Accounts with insecure usernames (regardless of module status)
1041 $insecure_admins = $this->get_insecure_admin_usernames();
1042 if ( ! empty( $insecure_admins ) ) {
1043 $recommendations[] = array(
1044 'icon' => 'warning',
1045 'priority' => 'high',
1046 'message' => sprintf(
1047 /* translators: %s: Comma-separated list of usernames */
1048 __( 'Insecure usernames detected: %s. These are commonly targeted in brute force attacks. Create new accounts with unique usernames and remove these.', 'vigilante' ),
1049 implode( ', ', $insecure_admins )
1050 ),
1051 );
1052 }
1053
1054 // Critical: Closed or removed plugins detected by the daily check.
1055 // Reads from the cached state map populated by Vigilante_Plugin_Status, so
1056 // there is no extra HTTP call here. Ignored slugs are filtered out so the
1057 // recommendation respects the user's per-slug Ignore decisions.
1058 if ( ! empty( $options['modules']['file_integrity'] ) && ! empty( $options['file_integrity']['check_closed_plugins'] ) ) {
1059 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
1060 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
1061 }
1062 $closed_checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
1063 $closed_active = $closed_checker->get_closed_plugins();
1064 if ( ! empty( $closed_active ) ) {
1065 $names = array();
1066 foreach ( $closed_active as $slug => $entry ) {
1067 $names[] = isset( $entry['name'] ) ? $entry['name'] : $slug;
1068 }
1069 $recommendations[] = array(
1070 'icon' => 'warning',
1071 'priority' => 'critical',
1072 'message' => sprintf(
1073 /* translators: 1: count, 2: comma-separated plugin names */
1074 _n(
1075 '%1$d closed plugin detected on this site: %2$s. Closures in WordPress.org usually indicate malware, security issues or supply chain compromises. Uninstall and replace as soon as possible.',
1076 '%1$d closed plugins detected on this site: %2$s. Closures in WordPress.org usually indicate malware, security issues or supply chain compromises. Uninstall and replace as soon as possible.',
1077 count( $closed_active ),
1078 'vigilante'
1079 ),
1080 count( $closed_active ),
1081 implode( ', ', $names )
1082 ),
1083 'tab' => 'file-integrity',
1084 );
1085 }
1086 }
1087
1088 // Medium: Security Audit is on but no audit alert is configured. The
1089 // alerting layer only makes sense while the activity log is running.
1090 if ( ! empty( $options['modules']['activity_log'] ) ) {
1091 $alerts = isset( $options['audit_alerts'] ) ? (array) $options['audit_alerts'] : array();
1092 if ( ! Vigilante_Audit_Alerts::has_active_alerts( $alerts ) ) {
1093 $recommendations[] = array(
1094 'icon' => 'email-alt',
1095 'priority' => 'medium',
1096 'message' => __( 'Set up Audit Alerts to get an email when something important happens (a new admin, a closed plugin, or an attack in progress).', 'vigilante' ),
1097 'tab' => 'activity-log',
1098 );
1099 }
1100 }
1101
1102 // Sort by priority
1103 $priority_order = array( 'critical' => 0, 'high' => 1, 'medium' => 2, 'low' => 3 );
1104 usort( $recommendations, function( $a, $b ) use ( $priority_order ) {
1105 return ( $priority_order[ $a['priority'] ] ?? 99 ) - ( $priority_order[ $b['priority'] ] ?? 99 );
1106 } );
1107
1108 return $recommendations;
1109 }
1110
1111 /**
1112 * Get users whose display name matches their login username
1113 *
1114 * Limited to administrators and editors for performance and relevance.
1115 * Cached with transient to avoid repeated queries on every dashboard load.
1116 *
1117 * @return array Array of usernames with exposed login.
1118 */
1119 private function get_users_with_exposed_login() {
1120 $cache_key = 'vigilante_exposed_display_names';
1121 $cached = get_transient( $cache_key );
1122
1123 if ( false !== $cached ) {
1124 return $cached;
1125 }
1126
1127 $exposed = array();
1128 $users = get_users( array(
1129 'role__in' => array( 'administrator', 'editor' ),
1130 'fields' => array( 'ID', 'user_login', 'display_name' ),
1131 ) );
1132
1133 foreach ( $users as $user ) {
1134 if ( strcasecmp( $user->display_name, $user->user_login ) === 0 ) {
1135 $exposed[] = $user->user_login;
1136 }
1137 }
1138
1139 // Cache for 12 hours
1140 set_transient( $cache_key, $exposed, 12 * HOUR_IN_SECONDS );
1141
1142 return $exposed;
1143 }
1144
1145 /**
1146 * Get accounts with insecure usernames
1147 *
1148 * Checks for common default usernames that are targeted by brute force attacks.
1149 * Detects any user regardless of role (consistent with username creation blocking).
1150 * Uses WordPress object cache via get_user_by() so no transient needed.
1151 *
1152 * @return array Array of insecure usernames found.
1153 */
1154 private function get_insecure_admin_usernames() {
1155 $priority_usernames = array( 'admin', 'administrator', 'root', 'test', 'user', 'guest', 'info', 'sysadmin', 'webmaster' );
1156 $found = array();
1157
1158 foreach ( $priority_usernames as $username ) {
1159 $user = get_user_by( 'login', $username );
1160 if ( $user ) {
1161 $found[] = $username;
1162 }
1163 }
1164
1165 return $found;
1166 }
1167
1168 /**
1169 * Get security status for menu badge
1170 *
1171 * Returns count of disabled modules and whether there are critical issues.
1172 * Critical = Firewall or Login Security disabled.
1173 *
1174 * @return array Array with 'count' and 'has_critical'.
1175 */
1176 public function get_security_status_for_badge() {
1177 $options = $this->settings->get_all_options();
1178 $modules = $options['modules'] ?? array();
1179
1180 // Count disabled modules
1181 $disabled_count = 0;
1182 $has_critical = false;
1183
1184 // Critical modules - if disabled, badge is red
1185 $critical_modules = array( 'firewall', 'login_security' );
1186
1187 foreach ( $modules as $module => $enabled ) {
1188 // Handle both boolean and string values ('1', '0', true, false)
1189 $is_enabled = filter_var( $enabled, FILTER_VALIDATE_BOOLEAN );
1190
1191 if ( ! $is_enabled ) {
1192 $disabled_count++;
1193
1194 // Check if this is a critical module
1195 if ( in_array( $module, $critical_modules, true ) ) {
1196 $has_critical = true;
1197 }
1198 }
1199 }
1200
1201 return array(
1202 'count' => $disabled_count,
1203 'has_critical' => $has_critical,
1204 );
1205 }
1206
1207 /**
1208 * Get count of security issues for menu badge (deprecated, use get_security_status_for_badge)
1209 *
1210 * @return int Count of critical/high issues.
1211 */
1212 public function get_security_issues_count() {
1213 $status = $this->get_security_status_for_badge();
1214 return $status['count'];
1215 }
1216
1217 /**
1218 * Register settings
1219 */
1220 public function register_settings() {
1221 register_setting(
1222 'vigilante_options',
1223 Vigilante_Settings::OPTION_NAME,
1224 array( $this->settings, 'validate_options' )
1225 );
1226 }
1227
1228 /**
1229 * Index behind the settings search box.
1230 *
1231 * Each entry points at one settings row. The search matches on the label,
1232 * on its English original and on 'keywords', which are extra terms someone
1233 * might type instead of the label itself.
1234 *
1235 * Those keywords are wrapped in _x() with the context "settings search
1236 * keywords" so every locale can supply its own: the source strings are in
1237 * English, and a Spanish user typing "contrasena" or a German one typing
1238 * "Kennwort" only reaches the password settings if that locale translated
1239 * them. Translators can add, drop or replace terms freely, one per space;
1240 * they are never displayed, only matched against what the user types.
1241 *
1242 * The list is maintained by hand, so a new settings row needs an entry here
1243 * or it cannot be found. It had drifted to 68 of 131 rows before 2.9.7.
1244 *
1245 * @return array
1246 */
1247 private function get_search_index() {
1248 return array(
1249 // Firewall - Main
1250 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Block bad bots', 'vigilante' ), 'label_en' => 'Block bad bots', 'keywords' => _x( 'block bad bots blocking blocked deny malicious harmful bot crawler crawlers spider scraper robots', 'settings search keywords', 'vigilante' ) ),
1251 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Block malicious requests', 'vigilante' ), 'label_en' => 'Block malicious requests', 'keywords' => _x( 'block malicious requests blocking blocked deny attack attacks exploit injection sqli xss rfi lfi request traffic', 'settings search keywords', 'vigilante' ) ),
1252 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Rate limiting', 'vigilante' ), 'label_en' => 'Rate limiting', 'keywords' => _x( 'rate limiting throttle flood burst limit limits', 'settings search keywords', 'vigilante' ) ),
1253 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Brute force protection', 'vigilante' ), 'label_en' => 'Brute force protection', 'keywords' => _x( 'brute force protection bruteforce login', 'settings search keywords', 'vigilante' ) ),
1254 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'IP Whitelist', 'vigilante' ), 'label_en' => 'IP Whitelist', 'keywords' => _x( 'ip whitelist ips address addresses cidr ipv4 ipv6 allowlist allowed trusted', 'settings search keywords', 'vigilante' ) ),
1255 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'IP Blacklist', 'vigilante' ), 'label_en' => 'IP Blacklist', 'keywords' => _x( 'ip blacklist ips address addresses cidr ipv4 ipv6 blocklist denylist banned', 'settings search keywords', 'vigilante' ) ),
1256 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'User-Agent Whitelist', 'vigilante' ), 'label_en' => 'User-Agent Whitelist', 'keywords' => _x( 'user-agent whitelist ua useragent browser allowlist allowed trusted user', 'settings search keywords', 'vigilante' ) ),
1257 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'User-Agent Blacklist', 'vigilante' ), 'label_en' => 'User-Agent Blacklist', 'keywords' => _x( 'user-agent blacklist ua useragent browser blocklist denylist banned user', 'settings search keywords', 'vigilante' ) ),
1258 // Firewall - Server Protection
1259 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Server Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-server', 'label' => __( 'Directory Browsing', 'vigilante' ), 'label_en' => 'Directory Browsing', 'keywords' => _x( 'directory browsing folder folders listing indexing index', 'settings search keywords', 'vigilante' ) ),
1260 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Server Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-server', 'label' => __( 'Protect wp-config.php', 'vigilante' ), 'label_en' => 'Protect wp-config.php', 'keywords' => _x( 'protect wp-config php protection secure lock', 'settings search keywords', 'vigilante' ) ),
1261 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Server Protection', 'vigilante' ), 'anchor' => 'field-protect-wp-cron', 'label' => __( 'Protect wp-cron.php', 'vigilante' ), 'label_en' => 'Protect wp-cron.php', 'keywords' => _x( 'protect wp-cron php protection secure lock cron scheduled tasks block spam', 'settings search keywords', 'vigilante' ) ),
1262 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Server Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-server', 'label' => __( 'Protect wp-includes', 'vigilante' ), 'label_en' => 'Protect wp-includes', 'keywords' => _x( 'protect wp-includes protection secure lock', 'settings search keywords', 'vigilante' ) ),
1263 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Server Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-server', 'label' => __( 'PHP in Uploads', 'vigilante' ), 'label_en' => 'PHP in Uploads', 'keywords' => _x( 'php in uploads media upload', 'settings search keywords', 'vigilante' ) ),
1264 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Server Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-server', 'label' => __( 'Sensitive Files', 'vigilante' ), 'label_en' => 'Sensitive Files', 'keywords' => _x( 'sensitive files private secret file log', 'settings search keywords', 'vigilante' ) ),
1265 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Server Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-server', 'label' => __( 'Limit HTTP Methods', 'vigilante' ), 'label_en' => 'Limit HTTP Methods', 'keywords' => _x( 'limit http methods', 'settings search keywords', 'vigilante' ) ),
1266 // Security Headers
1267 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'X-Frame-Options', 'vigilante' ), 'label_en' => 'X-Frame-Options', 'keywords' => _x( 'x-frame-options headers', 'settings search keywords', 'vigilante' ) ),
1268 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'X-Content-Type-Options', 'vigilante' ), 'label_en' => 'X-Content-Type-Options', 'keywords' => _x( 'x-content-type-options content headers', 'settings search keywords', 'vigilante' ) ),
1269 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Referrer-Policy', 'vigilante' ), 'label_en' => 'Referrer-Policy', 'keywords' => _x( 'referrer-policy headers', 'settings search keywords', 'vigilante' ) ),
1270 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'HSTS', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'HSTS', 'vigilante' ), 'label_en' => 'HSTS', 'keywords' => _x( 'hsts strict transport security ssl tls https headers', 'settings search keywords', 'vigilante' ) ),
1271 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Content Security Policy', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Content Security Policy', 'vigilante' ), 'label_en' => 'Content Security Policy', 'keywords' => _x( 'content security policy csp xss headers', 'settings search keywords', 'vigilante' ) ),
1272 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Server Identity', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Server Signature', 'vigilante' ), 'label_en' => 'Server Signature', 'keywords' => _x( 'server signature fingerprint banner', 'settings search keywords', 'vigilante' ) ),
1273 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Server Identity', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Remove Fingerprinting Headers', 'vigilante' ), 'label_en' => 'Remove Fingerprinting Headers', 'keywords' => _x( 'remove fingerprinting headers fingerprint banner header http', 'settings search keywords', 'vigilante' ) ),
1274 // Security Headers - Cross-Origin Policies
1275 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Cross-Origin Policies', 'vigilante' ), 'anchor' => 'vigilante-section-headers-cross-origin', 'label' => __( 'Cross-Origin-Opener-Policy (COOP)', 'vigilante' ), 'label_en' => 'Cross-Origin-Opener-Policy (COOP)', 'keywords' => _x( 'coop cross-origin opener policy popup popups window opener tag assistant google isolation browsing context headers', 'settings search keywords', 'vigilante' ) ),
1276 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Cross-Origin Policies', 'vigilante' ), 'anchor' => 'vigilante-section-headers-cross-origin', 'label' => __( 'Cross-Origin-Embedder-Policy (COEP)', 'vigilante' ), 'label_en' => 'Cross-Origin-Embedder-Policy (COEP)', 'keywords' => _x( 'coep cross-origin embedder policy require-corp credentialless embed embeds iframe fonts headers', 'settings search keywords', 'vigilante' ) ),
1277 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Cross-Origin Policies', 'vigilante' ), 'anchor' => 'vigilante-section-headers-cross-origin', 'label' => __( 'Cross-Origin-Resource-Policy (CORP)', 'vigilante' ), 'label_en' => 'Cross-Origin-Resource-Policy (CORP)', 'keywords' => _x( 'corp cross-origin resource policy hotlink hotlinking cdn images assets headers', 'settings search keywords', 'vigilante' ) ),
1278 // Login Security
1279 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Custom login URL', 'vigilante' ), 'label_en' => 'Custom login URL', 'keywords' => _x( 'custom login url signin log-in access slug', 'settings search keywords', 'vigilante' ) ),
1280 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Two-Factor Authentication', 'vigilante' ), 'label_en' => 'Two-Factor Authentication', 'keywords' => _x( 'two-factor authentication 2fa mfa otp totp authenticator', 'settings search keywords', 'vigilante' ) ),
1281 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( '2FA', 'vigilante' ), 'label_en' => '2FA', 'keywords' => _x( '2fa two-factor mfa otp totp authenticator', 'settings search keywords', 'vigilante' ) ),
1282 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Failed login attempts', 'vigilante' ), 'label_en' => 'Failed login attempts', 'keywords' => _x( 'failed login attempts signin log-in access tries retries', 'settings search keywords', 'vigilante' ) ),
1283 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Lockout', 'vigilante' ), 'label_en' => 'Lockout', 'keywords' => _x( 'lockout lock ban block login', 'settings search keywords', 'vigilante' ) ),
1284 // REST API
1285 array( 'tab' => 'rest-api', 'tab_label' => __( 'REST API', 'vigilante' ), 'section' => __( 'REST API Security', 'vigilante' ), 'anchor' => 'vigilante-section-rest-api-main', 'label' => __( 'Access Mode', 'vigilante' ), 'label_en' => 'Access Mode', 'keywords' => _x( 'access mode rest api', 'settings search keywords', 'vigilante' ) ),
1286 array( 'tab' => 'rest-api', 'tab_label' => __( 'REST API', 'vigilante' ), 'section' => __( 'REST API Security', 'vigilante' ), 'anchor' => 'vigilante-section-rest-api-main', 'label' => __( 'Block User Enumeration', 'vigilante' ), 'label_en' => 'Block User Enumeration', 'keywords' => _x( 'block user enumeration blocking blocked deny users account author slug', 'settings search keywords', 'vigilante' ) ),
1287 array( 'tab' => 'rest-api', 'tab_label' => __( 'REST API', 'vigilante' ), 'section' => __( 'REST API Security', 'vigilante' ), 'anchor' => 'vigilante-section-rest-api-main', 'label' => __( 'Disable JSONP', 'vigilante' ), 'label_en' => 'Disable JSONP', 'keywords' => _x( 'disable jsonp', 'settings search keywords', 'vigilante' ) ),
1288 // User Security
1289 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Username protection', 'vigilante' ), 'label_en' => 'Username protection', 'keywords' => _x( 'username protection admin', 'settings search keywords', 'vigilante' ) ),
1290 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Password strength', 'vigilante' ), 'label_en' => 'Password strength', 'keywords' => _x( 'password strength passwords credentials', 'settings search keywords', 'vigilante' ) ),
1291 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Admin monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-users-admin-monitoring', 'label' => __( 'Admin monitoring', 'vigilante' ), 'label_en' => 'Admin monitoring', 'keywords' => _x( 'admin monitoring administrator administrators', 'settings search keywords', 'vigilante' ) ),
1292 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Registration approval', 'vigilante' ), 'anchor' => 'vigilante-section-users-registration', 'label' => __( 'Registration approval', 'vigilante' ), 'label_en' => 'Registration approval', 'keywords' => _x( 'registration approval signup register approve moderate', 'settings search keywords', 'vigilante' ) ),
1293 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Session limits', 'vigilante' ), 'anchor' => 'vigilante-section-users-sessions', 'label' => __( 'Session limits', 'vigilante' ), 'label_en' => 'Session limits', 'keywords' => _x( 'session limits sessions concurrent', 'settings search keywords', 'vigilante' ) ),
1294 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Password expiration', 'vigilante' ), 'label_en' => 'Password expiration', 'keywords' => _x( 'password expiration passwords credentials expiry expire caducity', 'settings search keywords', 'vigilante' ) ),
1295 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Email verification', 'vigilante' ), 'anchor' => 'vigilante-section-users-email-verify', 'label' => __( 'Email verification', 'vigilante' ), 'label_en' => 'Email verification', 'keywords' => _x( 'email verification mail notification notify verify confirm', 'settings search keywords', 'vigilante' ) ),
1296 // WP Hardening
1297 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Database Hardening', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-database', 'label' => __( 'Database Hardening', 'vigilante' ), 'label_en' => 'Database Hardening', 'keywords' => _x( 'database hardening db mysql tables', 'settings search keywords', 'vigilante' ) ),
1298 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Database Hardening', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-database', 'label' => __( 'Database prefix', 'vigilante' ), 'label_en' => 'Database prefix', 'keywords' => _x( 'database prefix db mysql tables table', 'settings search keywords', 'vigilante' ) ),
1299 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'wp-config.php Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-wpconfig', 'label' => __( 'Disable file editing', 'vigilante' ), 'label_en' => 'Disable file editing', 'keywords' => _x( 'disable file editing files editor edit', 'settings search keywords', 'vigilante' ) ),
1300 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'wp-config.php Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-wpconfig', 'label' => __( 'Disable plugin/theme installation', 'vigilante' ), 'label_en' => 'Disable plugin/theme installation', 'keywords' => _x( 'disable plugin theme installation install', 'settings search keywords', 'vigilante' ) ),
1301 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'wp-config.php Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-wpconfig', 'label' => __( 'Force SSL admin', 'vigilante' ), 'label_en' => 'Force SSL admin', 'keywords' => _x( 'force ssl admin bruteforce administrator administrators tls https', 'settings search keywords', 'vigilante' ) ),
1302 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'wp-config.php Security', 'vigilante' ), 'anchor' => 'field-disable-wp-cron', 'label' => __( 'Disable WP Cron', 'vigilante' ), 'label_en' => 'Disable WP Cron', 'keywords' => _x( 'disable wp cron scheduled tasks wp-cron', 'settings search keywords', 'vigilante' ) ),
1303 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Comment Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-comments', 'label' => __( 'Comment Security', 'vigilante' ), 'label_en' => 'Comment Security', 'keywords' => _x( 'comment security comments spam honeypot url', 'settings search keywords', 'vigilante' ) ),
1304 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-headers', 'label' => __( 'Header Cleanup', 'vigilante' ), 'label_en' => 'Header Cleanup', 'keywords' => _x( 'header cleanup headers http meta generator rsd wlwmanifest', 'settings search keywords', 'vigilante' ) ),
1305 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-headers', 'label' => __( 'Remove WordPress version', 'vigilante' ), 'label_en' => 'Remove WordPress version', 'keywords' => _x( 'remove wordpress version generator meta', 'settings search keywords', 'vigilante' ) ),
1306 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'field-remove-wp-version-assets', 'label' => __( 'Remove version from assets', 'vigilante' ), 'label_en' => 'Remove version from assets', 'keywords' => _x( 'remove version from assets', 'settings search keywords', 'vigilante' ) ),
1307 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-xmlrpc', 'label' => __( 'Disable XML-RPC', 'vigilante' ), 'label_en' => 'Disable XML-RPC', 'keywords' => _x( 'disable xml-rpc xmlrpc rpc remote jetpack app pingback trackback', 'settings search keywords', 'vigilante' ) ),
1308 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'RSS Feed Settings', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-rss', 'label' => __( 'RSS Feed Settings', 'vigilante' ), 'label_en' => 'RSS Feed Settings', 'keywords' => _x( 'rss feed settings feeds atom', 'settings search keywords', 'vigilante' ) ),
1309 // File Integrity
1310 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'File Integrity Monitoring', 'vigilante' ), 'label_en' => 'File Integrity Monitoring', 'keywords' => _x( 'file integrity monitoring files checksum checksums tamper', 'settings search keywords', 'vigilante' ) ),
1311 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Scan schedule', 'vigilante' ), 'label_en' => 'Scan schedule', 'keywords' => _x( 'scan schedule scans scanning check cron', 'settings search keywords', 'vigilante' ) ),
1312 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Instant alert', 'vigilante' ), 'label_en' => 'Instant alert', 'keywords' => _x( 'instant alert alerts notification warning email', 'settings search keywords', 'vigilante' ) ),
1313 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'Ignored Files', 'vigilante' ), 'anchor' => 'vigilante-section-fi-ignored', 'label' => __( 'Ignored Files', 'vigilante' ), 'label_en' => 'Ignored Files', 'keywords' => _x( 'ignored files file exclude', 'settings search keywords', 'vigilante' ) ),
1314 // Security Audit
1315 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Security Audit Settings', 'vigilante' ), 'anchor' => 'vigilante-section-audit-settings', 'label' => __( 'Retention', 'vigilante' ), 'label_en' => 'Retention', 'keywords' => _x( 'retention keep days storage log', 'settings search keywords', 'vigilante' ) ),
1316 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Security Audit Settings', 'vigilante' ), 'anchor' => 'vigilante-section-audit-settings', 'label' => __( 'Events to Log', 'vigilante' ), 'label_en' => 'Events to Log', 'keywords' => _x( 'events to log', 'settings search keywords', 'vigilante' ) ),
1317 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Security Audit Settings', 'vigilante' ), 'anchor' => 'vigilante-section-audit-settings', 'label' => __( 'Option Tracking', 'vigilante' ), 'label_en' => 'Option Tracking', 'keywords' => _x( 'option tracking', 'settings search keywords', 'vigilante' ) ),
1318 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Security Audit Settings', 'vigilante' ), 'anchor' => 'vigilante-section-audit-settings', 'label' => __( 'Exclusions', 'vigilante' ), 'label_en' => 'Exclusions', 'keywords' => _x( 'exclusions roles ip', 'settings search keywords', 'vigilante' ) ),
1319 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Audit Alerts', 'vigilante' ), 'anchor' => 'vigilante-section-audit-alerts', 'label' => __( 'Audit Alerts', 'vigilante' ), 'label_en' => 'Audit Alerts', 'keywords' => _x( 'audit alerts email mail warning critical', 'settings search keywords', 'vigilante' ) ),
1320 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Audit Alerts', 'vigilante' ), 'anchor' => 'field-audit-alerts-immediate', 'label' => __( 'Immediate alerts', 'vigilante' ), 'label_en' => 'Immediate alerts', 'keywords' => _x( 'immediate alerts email mail critical warning', 'settings search keywords', 'vigilante' ) ),
1321 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Audit Alerts', 'vigilante' ), 'anchor' => 'field-audit-alerts-threshold', 'label' => __( 'Threshold alerts', 'vigilante' ), 'label_en' => 'Threshold alerts', 'keywords' => _x( 'threshold alerts email mail login', 'settings search keywords', 'vigilante' ) ),
1322 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Recent Activity', 'vigilante' ), 'anchor' => 'vigilante-section-audit-recent', 'label' => __( 'Recent Activity', 'vigilante' ), 'label_en' => 'Recent Activity', 'keywords' => _x( 'recent activity log', 'settings search keywords', 'vigilante' ) ),
1323 // Settings & Tools
1324 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Notification settings', 'vigilante' ), 'anchor' => 'vigilante-section-tools-notifications', 'label' => __( 'Notification settings', 'vigilante' ), 'label_en' => 'Notification settings', 'keywords' => _x( 'notification settings email', 'settings search keywords', 'vigilante' ) ),
1325 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Notification settings', 'vigilante' ), 'anchor' => 'vigilante-section-tools-notifications', 'label' => __( 'Additional Recipients', 'vigilante' ), 'label_en' => 'Additional Recipients', 'keywords' => _x( 'additional recipients email recipient', 'settings search keywords', 'vigilante' ) ),
1326 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Tools', 'vigilante' ), 'anchor' => 'vigilante-section-tools-main', 'label' => __( 'Export Settings', 'vigilante' ), 'label_en' => 'Export Settings', 'keywords' => _x( 'export settings json', 'settings search keywords', 'vigilante' ) ),
1327 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Tools', 'vigilante' ), 'anchor' => 'vigilante-section-tools-main', 'label' => __( 'Import Settings', 'vigilante' ), 'label_en' => 'Import Settings', 'keywords' => _x( 'import settings json', 'settings search keywords', 'vigilante' ) ),
1328 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Tools', 'vigilante' ), 'anchor' => 'vigilante-section-tools-main', 'label' => __( 'Reset to Defaults', 'vigilante' ), 'label_en' => 'Reset to Defaults', 'keywords' => _x( 'reset to defaults', 'settings search keywords', 'vigilante' ) ),
1329 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Tools', 'vigilante' ), 'anchor' => 'vigilante-section-tools-main', 'label' => __( 'Create Backup', 'vigilante' ), 'label_en' => 'Create Backup', 'keywords' => _x( 'create backup', 'settings search keywords', 'vigilante' ) ),
1330 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Tools', 'vigilante' ), 'anchor' => 'vigilante-section-tools-main', 'label' => __( 'Database Backup', 'vigilante' ), 'label_en' => 'Database Backup', 'keywords' => _x( 'database backup db mysql tables', 'settings search keywords', 'vigilante' ) ),
1331 // Entradas anadidas en la 2.9.7 tras comprobar que el indice cubria 68 de
1332 // las 131 filas de ajustes: buscar XML-RPC, por ejemplo, no devolvia nada.
1333 // El indice se mantiene a mano, asi que al anadir una fila de ajustes hay
1334 // que anadirla tambien aqui.
1335 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Notification settings', 'vigilante' ), 'anchor' => 'vigilante-section-tools-notifications', 'label' => __( 'WordPress Admin Email', 'vigilante' ), 'label_en' => 'WordPress Admin Email', 'keywords' => _x( 'wordpress admin email administrator administrators mail notification notify', 'settings search keywords', 'vigilante' ) ),
1336 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Notification settings', 'vigilante' ), 'anchor' => 'vigilante-section-tools-notifications', 'label' => __( 'Plugin Deactivation', 'vigilante' ), 'label_en' => 'Plugin Deactivation', 'keywords' => _x( 'plugin deactivation', 'settings search keywords', 'vigilante' ) ),
1337 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Block Bad Query Strings', 'vigilante' ), 'label_en' => 'Block Bad Query Strings', 'keywords' => _x( 'block bad query strings blocking blocked deny malicious harmful', 'settings search keywords', 'vigilante' ) ),
1338 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'SQL Injection Protection', 'vigilante' ), 'label_en' => 'SQL Injection Protection', 'keywords' => _x( 'sql injection protection', 'settings search keywords', 'vigilante' ) ),
1339 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'XSS Protection', 'vigilante' ), 'label_en' => 'XSS Protection', 'keywords' => _x( 'xss protection', 'settings search keywords', 'vigilante' ) ),
1340 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'File Inclusion Protection', 'vigilante' ), 'label_en' => 'File Inclusion Protection', 'keywords' => _x( 'file inclusion protection files', 'settings search keywords', 'vigilante' ) ),
1341 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Directory Traversal Protection', 'vigilante' ), 'label_en' => 'Directory Traversal Protection', 'keywords' => _x( 'directory traversal protection folder folders', 'settings search keywords', 'vigilante' ) ),
1342 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Enable Rate Limiting', 'vigilante' ), 'label_en' => 'Enable Rate Limiting', 'keywords' => _x( 'enable rate limiting throttle flood burst limit limits', 'settings search keywords', 'vigilante' ) ),
1343 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Requests per Minute', 'vigilante' ), 'label_en' => 'Requests per Minute', 'keywords' => _x( 'requests per minute request traffic', 'settings search keywords', 'vigilante' ) ),
1344 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Block Duration (seconds)', 'vigilante' ), 'label_en' => 'Block Duration (seconds)', 'keywords' => _x( 'block duration seconds blocking blocked deny', 'settings search keywords', 'vigilante' ) ),
1345 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Progressive Blocking', 'vigilante' ), 'label_en' => 'Progressive Blocking', 'keywords' => _x( 'progressive blocking', 'settings search keywords', 'vigilante' ) ),
1346 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Maximum Block Duration', 'vigilante' ), 'label_en' => 'Maximum Block Duration', 'keywords' => _x( 'maximum block duration blocking blocked deny', 'settings search keywords', 'vigilante' ) ),
1347 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Visitor IP detection', 'vigilante' ), 'label_en' => 'Visitor IP detection', 'keywords' => _x( 'visitor ip detection ips address addresses cidr ipv4 ipv6', 'settings search keywords', 'vigilante' ) ),
1348 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Max Login Attempts', 'vigilante' ), 'label_en' => 'Max Login Attempts', 'keywords' => _x( 'max login attempts signin log-in access tries retries', 'settings search keywords', 'vigilante' ) ),
1349 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Lockout Duration', 'vigilante' ), 'label_en' => 'Lockout Duration', 'keywords' => _x( 'lockout duration lock ban block', 'settings search keywords', 'vigilante' ) ),
1350 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Progressive Lockout', 'vigilante' ), 'label_en' => 'Progressive Lockout', 'keywords' => _x( 'progressive lockout lock ban block', 'settings search keywords', 'vigilante' ) ),
1351 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Hide Login Errors', 'vigilante' ), 'label_en' => 'Hide Login Errors', 'keywords' => _x( 'hide login errors signin log-in access error debug log', 'settings search keywords', 'vigilante' ) ),
1352 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Disable Application Passwords', 'vigilante' ), 'label_en' => 'Disable Application Passwords', 'keywords' => _x( 'disable application passwords password credentials', 'settings search keywords', 'vigilante' ) ),
1353 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Login URL Slug', 'vigilante' ), 'label_en' => 'Login URL Slug', 'keywords' => _x( 'login url slug signin log-in access path', 'settings search keywords', 'vigilante' ) ),
1354 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Notify users', 'vigilante' ), 'label_en' => 'Notify users', 'keywords' => _x( 'notify users notification alert email user accounts', 'settings search keywords', 'vigilante' ) ),
1355 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Notify on Lockout', 'vigilante' ), 'label_en' => 'Notify on Lockout', 'keywords' => _x( 'notify on lockout notification alert email lock ban block', 'settings search keywords', 'vigilante' ) ),
1356 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Notify on Admin Login', 'vigilante' ), 'label_en' => 'Notify on Admin Login', 'keywords' => _x( 'notify on admin login notification alert email administrator administrators signin log-in access', 'settings search keywords', 'vigilante' ) ),
1357 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Current settings', 'vigilante' ), 'label_en' => 'Current settings', 'keywords' => _x( 'current settings', 'settings search keywords', 'vigilante' ) ),
1358 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Blocked IPs', 'vigilante' ), 'label_en' => 'Blocked IPs', 'keywords' => _x( 'blocked ips', 'settings search keywords', 'vigilante' ) ),
1359 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Enable 2FA', 'vigilante' ), 'label_en' => 'Enable 2FA', 'keywords' => _x( 'enable 2fa two-factor mfa otp totp authenticator', 'settings search keywords', 'vigilante' ) ),
1360 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Verification method', 'vigilante' ), 'label_en' => 'Verification method', 'keywords' => _x( 'verification method verify confirm', 'settings search keywords', 'vigilante' ) ),
1361 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Enforce for roles', 'vigilante' ), 'label_en' => 'Enforce for roles', 'keywords' => _x( 'enforce for roles role capabilities', 'settings search keywords', 'vigilante' ) ),
1362 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Exclude specific users', 'vigilante' ), 'label_en' => 'Exclude specific users', 'keywords' => _x( 'exclude specific users user accounts', 'settings search keywords', 'vigilante' ) ),
1363 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Remember device', 'vigilante' ), 'label_en' => 'Remember device', 'keywords' => _x( 'remember device', 'settings search keywords', 'vigilante' ) ),
1364 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Grace period', 'vigilante' ), 'label_en' => 'Grace period', 'keywords' => _x( 'grace period', 'settings search keywords', 'vigilante' ) ),
1365 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Email sender name', 'vigilante' ), 'label_en' => 'Email sender name', 'keywords' => _x( 'email sender name mail notification notify names', 'settings search keywords', 'vigilante' ) ),
1366 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Reset user TOTP', 'vigilante' ), 'label_en' => 'Reset user TOTP', 'keywords' => _x( 'reset user totp users account 2fa authenticator app', 'settings search keywords', 'vigilante' ) ),
1367 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Notify on enable', 'vigilante' ), 'label_en' => 'Notify on enable', 'keywords' => _x( 'notify on enable notification alert email', 'settings search keywords', 'vigilante' ) ),
1368 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Enable CSP', 'vigilante' ), 'label_en' => 'Enable CSP', 'keywords' => _x( 'enable csp content security policy', 'settings search keywords', 'vigilante' ) ),
1369 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Report Only Mode', 'vigilante' ), 'label_en' => 'Report Only Mode', 'keywords' => _x( 'report only mode', 'settings search keywords', 'vigilante' ) ),
1370 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Redirect HTTP to HTTPS', 'vigilante' ), 'label_en' => 'Redirect HTTP to HTTPS', 'keywords' => _x( 'redirect http to https redirection forward ssl tls secure', 'settings search keywords', 'vigilante' ) ),
1371 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Fix Mixed Content', 'vigilante' ), 'label_en' => 'Fix Mixed Content', 'keywords' => _x( 'fix mixed content insecure http', 'settings search keywords', 'vigilante' ) ),
1372 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'field-upgrade-insecure-requests', 'label' => __( 'Upgrade Insecure Requests', 'vigilante' ), 'label_en' => 'Upgrade Insecure Requests', 'keywords' => _x( 'upgrade insecure requests mixed content csp https external resources', 'settings search keywords', 'vigilante' ) ),
1373 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Rewrite Site Address on Activation', 'vigilante' ), 'label_en' => 'Rewrite Site Address on Activation', 'keywords' => _x( 'rewrite site address on activation', 'settings search keywords', 'vigilante' ) ),
1374 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Enable HSTS', 'vigilante' ), 'label_en' => 'Enable HSTS', 'keywords' => _x( 'enable hsts strict transport security', 'settings search keywords', 'vigilante' ) ),
1375 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Max Age', 'vigilante' ), 'label_en' => 'Max Age', 'keywords' => _x( 'max age', 'settings search keywords', 'vigilante' ) ),
1376 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Include Subdomains', 'vigilante' ), 'label_en' => 'Include Subdomains', 'keywords' => _x( 'include subdomains', 'settings search keywords', 'vigilante' ) ),
1377 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Block Insecure Usernames', 'vigilante' ), 'label_en' => 'Block Insecure Usernames', 'keywords' => _x( 'block insecure usernames blocking blocked deny weak unsafe', 'settings search keywords', 'vigilante' ) ),
1378 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Enforce Strong Passwords', 'vigilante' ), 'label_en' => 'Enforce Strong Passwords', 'keywords' => _x( 'enforce strong passwords complexity password credentials', 'settings search keywords', 'vigilante' ) ),
1379 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Minimum Password Length', 'vigilante' ), 'label_en' => 'Minimum Password Length', 'keywords' => _x( 'minimum password length passwords credentials characters', 'settings search keywords', 'vigilante' ) ),
1380 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Password Requirements', 'vigilante' ), 'label_en' => 'Password Requirements', 'keywords' => _x( 'password requirements passwords credentials', 'settings search keywords', 'vigilante' ) ),
1381 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Apply Password Rules To', 'vigilante' ), 'label_en' => 'Apply Password Rules To', 'keywords' => _x( 'apply password rules to passwords credentials', 'settings search keywords', 'vigilante' ) ),
1382 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Block Author Scanning', 'vigilante' ), 'label_en' => 'Block Author Scanning', 'keywords' => _x( 'block author scanning blocking blocked deny authors enumeration probing', 'settings search keywords', 'vigilante' ) ),
1383 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Display Name Protection', 'vigilante' ), 'label_en' => 'Display Name Protection', 'keywords' => _x( 'display name protection public visible names', 'settings search keywords', 'vigilante' ) ),
1384 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Admin monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-users-admin-monitoring', 'label' => __( 'New Administrator Alert', 'vigilante' ), 'label_en' => 'New Administrator Alert', 'keywords' => _x( 'new administrator alert alerts notification warning', 'settings search keywords', 'vigilante' ) ),
1385 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Admin monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-users-admin-monitoring', 'label' => __( 'Admin Email Change Alert', 'vigilante' ), 'label_en' => 'Admin Email Change Alert', 'keywords' => _x( 'admin email change alert administrator administrators mail notification notify alerts warning', 'settings search keywords', 'vigilante' ) ),
1386 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Admin monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-users-admin-monitoring', 'label' => __( 'Permission Elevation Alert', 'vigilante' ), 'label_en' => 'Permission Elevation Alert', 'keywords' => _x( 'permission elevation alert alerts notification warning', 'settings search keywords', 'vigilante' ) ),
1387 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Admin monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-users-admin-monitoring', 'label' => __( 'Admin Password Change Alert', 'vigilante' ), 'label_en' => 'Admin Password Change Alert', 'keywords' => _x( 'admin password change alert administrator administrators passwords credentials alerts notification warning', 'settings search keywords', 'vigilante' ) ),
1388 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Registration approval', 'vigilante' ), 'anchor' => 'vigilante-section-users-registration', 'label' => __( 'Enable Registration Approval', 'vigilante' ), 'label_en' => 'Enable Registration Approval', 'keywords' => _x( 'enable registration approval signup register approve moderate', 'settings search keywords', 'vigilante' ) ),
1389 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Registration approval', 'vigilante' ), 'anchor' => 'vigilante-section-users-registration', 'label' => __( 'Notify Admin', 'vigilante' ), 'label_en' => 'Notify Admin', 'keywords' => _x( 'notify admin notification alert email administrator administrators', 'settings search keywords', 'vigilante' ) ),
1390 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Registration approval', 'vigilante' ), 'anchor' => 'vigilante-section-users-registration', 'label' => __( 'Auto-reject After', 'vigilante' ), 'label_en' => 'Auto-reject After', 'keywords' => _x( 'auto-reject after', 'settings search keywords', 'vigilante' ) ),
1391 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Session limits', 'vigilante' ), 'anchor' => 'vigilante-section-users-sessions', 'label' => __( 'Enable Session Limits', 'vigilante' ), 'label_en' => 'Enable Session Limits', 'keywords' => _x( 'enable session limits sessions concurrent', 'settings search keywords', 'vigilante' ) ),
1392 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Session limits', 'vigilante' ), 'anchor' => 'vigilante-section-users-sessions', 'label' => __( 'Maximum Sessions', 'vigilante' ), 'label_en' => 'Maximum Sessions', 'keywords' => _x( 'maximum sessions session concurrent', 'settings search keywords', 'vigilante' ) ),
1393 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Session limits', 'vigilante' ), 'anchor' => 'vigilante-section-users-sessions', 'label' => __( 'When Limit Exceeded', 'vigilante' ), 'label_en' => 'When Limit Exceeded', 'keywords' => _x( 'when limit exceeded', 'settings search keywords', 'vigilante' ) ),
1394 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Session limits', 'vigilante' ), 'anchor' => 'vigilante-section-users-sessions', 'label' => __( 'Exclude Administrators', 'vigilante' ), 'label_en' => 'Exclude Administrators', 'keywords' => _x( 'exclude administrators', 'settings search keywords', 'vigilante' ) ),
1395 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Enable Password Expiration', 'vigilante' ), 'label_en' => 'Enable Password Expiration', 'keywords' => _x( 'enable password expiration passwords credentials expiry expire caducity', 'settings search keywords', 'vigilante' ) ),
1396 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Expire After', 'vigilante' ), 'label_en' => 'Expire After', 'keywords' => _x( 'expire after', 'settings search keywords', 'vigilante' ) ),
1397 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Warning Period', 'vigilante' ), 'label_en' => 'Warning Period', 'keywords' => _x( 'warning period', 'settings search keywords', 'vigilante' ) ),
1398 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Password History', 'vigilante' ), 'label_en' => 'Password History', 'keywords' => _x( 'password history passwords credentials reuse previous', 'settings search keywords', 'vigilante' ) ),
1399 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Email Reminder', 'vigilante' ), 'label_en' => 'Email Reminder', 'keywords' => _x( 'email reminder mail notification notify', 'settings search keywords', 'vigilante' ) ),
1400 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Affected Roles', 'vigilante' ), 'label_en' => 'Affected Roles', 'keywords' => _x( 'affected roles role capabilities', 'settings search keywords', 'vigilante' ) ),
1401 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Exclude specific users', 'vigilante' ), 'label_en' => 'Exclude specific users', 'keywords' => _x( 'exclude specific users user accounts', 'settings search keywords', 'vigilante' ) ),
1402 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Email verification', 'vigilante' ), 'anchor' => 'vigilante-section-users-email-verify', 'label' => __( 'Enable Email Verification', 'vigilante' ), 'label_en' => 'Enable Email Verification', 'keywords' => _x( 'enable email verification mail notification notify verify confirm', 'settings search keywords', 'vigilante' ) ),
1403 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Email verification', 'vigilante' ), 'anchor' => 'vigilante-section-users-email-verify', 'label' => __( 'Link Expiration', 'vigilante' ), 'label_en' => 'Link Expiration', 'keywords' => _x( 'link expiration expiry expire caducity', 'settings search keywords', 'vigilante' ) ),
1404 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Email verification', 'vigilante' ), 'anchor' => 'vigilante-section-users-email-verify', 'label' => __( 'Allow Resend', 'vigilante' ), 'label_en' => 'Allow Resend', 'keywords' => _x( 'allow resend', 'settings search keywords', 'vigilante' ) ),
1405 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Email verification', 'vigilante' ), 'anchor' => 'vigilante-section-users-email-verify', 'label' => __( 'Auto-delete Unverified', 'vigilante' ), 'label_en' => 'Auto-delete Unverified', 'keywords' => _x( 'auto-delete unverified', 'settings search keywords', 'vigilante' ) ),
1406 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Database Hardening', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-database', 'label' => __( 'Current prefix', 'vigilante' ), 'label_en' => 'Current prefix', 'keywords' => _x( 'current prefix database db table tables mysql', 'settings search keywords', 'vigilante' ) ),
1407 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Database Hardening', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-database', 'label' => __( 'New prefix', 'vigilante' ), 'label_en' => 'New prefix', 'keywords' => _x( 'new prefix database db table tables mysql', 'settings search keywords', 'vigilante' ) ),
1408 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'wp-config.php Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-wpconfig', 'label' => __( 'Disable File Editor', 'vigilante' ), 'label_en' => 'Disable File Editor', 'keywords' => _x( 'disable file editor files edit editing', 'settings search keywords', 'vigilante' ) ),
1409 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'wp-config.php Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-wpconfig', 'label' => __( 'Disable File Modifications', 'vigilante' ), 'label_en' => 'Disable File Modifications', 'keywords' => _x( 'disable file modifications files modify install update', 'settings search keywords', 'vigilante' ) ),
1410 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'wp-config.php Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-wpconfig', 'label' => __( 'Hide PHP errors from visitors', 'vigilante' ), 'label_en' => 'Hide PHP errors from visitors', 'keywords' => _x( 'hide php errors from visitors error debug log', 'settings search keywords', 'vigilante' ) ),
1411 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'XML-RPC', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-xmlrpc', 'label' => __( 'XML-RPC access', 'vigilante' ), 'label_en' => 'XML-RPC access', 'keywords' => _x( 'xml-rpc access xmlrpc rpc remote jetpack app', 'settings search keywords', 'vigilante' ) ),
1412 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Comment Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-comments', 'label' => __( 'Disable Pingbacks', 'vigilante' ), 'label_en' => 'Disable Pingbacks', 'keywords' => _x( 'disable pingbacks pingback ping', 'settings search keywords', 'vigilante' ) ),
1413 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Comment Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-comments', 'label' => __( 'Disable Trackbacks', 'vigilante' ), 'label_en' => 'Disable Trackbacks', 'keywords' => _x( 'disable trackbacks trackback ping', 'settings search keywords', 'vigilante' ) ),
1414 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Comment Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-comments', 'label' => __( 'Require Moderation', 'vigilante' ), 'label_en' => 'Require Moderation', 'keywords' => _x( 'require moderation moderate approve', 'settings search keywords', 'vigilante' ) ),
1415 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Comment Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-comments', 'label' => __( 'Close Old Comments', 'vigilante' ), 'label_en' => 'Close Old Comments', 'keywords' => _x( 'close old comments comment discussion', 'settings search keywords', 'vigilante' ) ),
1416 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Comment Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-comments', 'label' => __( 'Honeypot Protection', 'vigilante' ), 'label_en' => 'Honeypot Protection', 'keywords' => _x( 'honeypot protection spam bots trap', 'settings search keywords', 'vigilante' ) ),
1417 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-headers', 'label' => __( 'Remove Generator', 'vigilante' ), 'label_en' => 'Remove Generator', 'keywords' => _x( 'remove generator version meta', 'settings search keywords', 'vigilante' ) ),
1418 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-headers', 'label' => __( 'Remove RSD Link', 'vigilante' ), 'label_en' => 'Remove RSD Link', 'keywords' => _x( 'remove rsd link discovery', 'settings search keywords', 'vigilante' ) ),
1419 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-headers', 'label' => __( 'Remove WLW Manifest', 'vigilante' ), 'label_en' => 'Remove WLW Manifest', 'keywords' => _x( 'remove wlw manifest wlwmanifest', 'settings search keywords', 'vigilante' ) ),
1420 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-headers', 'label' => __( 'Remove Shortlink', 'vigilante' ), 'label_en' => 'Remove Shortlink', 'keywords' => _x( 'remove shortlink link', 'settings search keywords', 'vigilante' ) ),
1421 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-headers', 'label' => __( 'Remove REST API Link', 'vigilante' ), 'label_en' => 'Remove REST API Link', 'keywords' => _x( 'remove rest api link json endpoint', 'settings search keywords', 'vigilante' ) ),
1422 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'RSS Feed Settings', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-rss', 'label' => __( 'Disable Feeds', 'vigilante' ), 'label_en' => 'Disable Feeds', 'keywords' => _x( 'disable feeds feed rss atom syndication', 'settings search keywords', 'vigilante' ) ),
1423 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'RSS Feed Settings', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-rss', 'label' => __( 'Disable If No Content', 'vigilante' ), 'label_en' => 'Disable If No Content', 'keywords' => _x( 'disable if no content', 'settings search keywords', 'vigilante' ) ),
1424 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'RSS Feed Settings', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-rss', 'label' => __( 'Remove Feed Version', 'vigilante' ), 'label_en' => 'Remove Feed Version', 'keywords' => _x( 'remove feed version feeds rss atom', 'settings search keywords', 'vigilante' ) ),
1425 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Audit Alerts', 'vigilante' ), 'anchor' => 'vigilante-section-audit-alerts', 'label' => __( 'Alert on severity', 'vigilante' ), 'label_en' => 'Alert on severity', 'keywords' => _x( 'alert on severity alerts notification warning level critical', 'settings search keywords', 'vigilante' ) ),
1426 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Audit Alerts', 'vigilante' ), 'anchor' => 'vigilante-section-audit-alerts', 'label' => __( 'Time window', 'vigilante' ), 'label_en' => 'Time window', 'keywords' => _x( 'time window', 'settings search keywords', 'vigilante' ) ),
1427 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Audit Alerts', 'vigilante' ), 'anchor' => 'vigilante-section-audit-alerts', 'label' => __( 'Thresholds per category', 'vigilante' ), 'label_en' => 'Thresholds per category', 'keywords' => _x( 'thresholds per category threshold limit', 'settings search keywords', 'vigilante' ) ),
1428 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Audit Alerts', 'vigilante' ), 'anchor' => 'vigilante-section-audit-alerts', 'label' => __( 'Recipients', 'vigilante' ), 'label_en' => 'Recipients', 'keywords' => _x( 'recipients email recipient', 'settings search keywords', 'vigilante' ) ),
1429 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Automatic Scans', 'vigilante' ), 'label_en' => 'Automatic Scans', 'keywords' => _x( 'automatic scans scan scanning', 'settings search keywords', 'vigilante' ) ),
1430 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Scan Frequency', 'vigilante' ), 'label_en' => 'Scan Frequency', 'keywords' => _x( 'scan frequency scans scanning check', 'settings search keywords', 'vigilante' ) ),
1431 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Email Notifications', 'vigilante' ), 'label_en' => 'Email Notifications', 'keywords' => _x( 'email notifications mail notification notify', 'settings search keywords', 'vigilante' ) ),
1432 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Test email', 'vigilante' ), 'label_en' => 'Test email', 'keywords' => _x( 'test email mail notification notify', 'settings search keywords', 'vigilante' ) ),
1433 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Scan Scope', 'vigilante' ), 'label_en' => 'Scan Scope', 'keywords' => _x( 'scan scope scans scanning check', 'settings search keywords', 'vigilante' ) ),
1434 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Excluded Paths', 'vigilante' ), 'label_en' => 'Excluded Paths', 'keywords' => _x( 'excluded paths exclude exclusions ignore ignored path folder folders', 'settings search keywords', 'vigilante' ) ),
1435 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Excluded Extensions', 'vigilante' ), 'label_en' => 'Excluded Extensions', 'keywords' => _x( 'excluded extensions exclude exclusions ignore ignored extension filetype', 'settings search keywords', 'vigilante' ) ),
1436 );
1437 }
1438
1439 /**
1440 * Enqueue admin assets
1441 *
1442 * @param string $hook Current admin page.
1443 */
1444 public function enqueue_assets( $hook ) {
1445 // toplevel_page_vigilante for top-level menu page
1446 if ( 'toplevel_page_vigilante' !== $hook ) {
1447 return;
1448 }
1449
1450 wp_enqueue_style(
1451 'vigilante-admin',
1452 VIGILANTE_ASSETS_URL . 'css/admin.css',
1453 array(),
1454 VIGILANTE_VERSION
1455 );
1456
1457 wp_enqueue_script(
1458 'vigilante-admin',
1459 VIGILANTE_ASSETS_URL . 'js/admin.js',
1460 array( 'jquery' ),
1461 VIGILANTE_VERSION,
1462 true
1463 );
1464
1465 wp_localize_script( 'vigilante-admin', 'vigilanteAdmin', array(
1466 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
1467 'nonce' => wp_create_nonce( 'vigilante_admin_nonce' ),
1468 'currentUserId' => get_current_user_id(),
1469 'logoutUrl' => wp_logout_url( wp_login_url() ),
1470 'adminUrl' => admin_url( 'admin.php?page=vigilante' ),
1471 'searchIndex' => $this->get_search_index(),
1472 // The scan repaints this table from JavaScript, so the same gate
1473 // has to travel with it or half the screen keeps the dead button.
1474 'approvalLocked' => $this->critical_approval_locked(),
1475 'underAttack' => array(
1476 'active' => ( new Vigilante_Under_Attack( $this->settings, $this->activity_log ) )->is_active(),
1477 'remaining' => ( new Vigilante_Under_Attack( $this->settings, $this->activity_log ) )->get_remaining_time(),
1478 ),
1479 'strings' => array(
1480 'saving' => __( 'Saving...', 'vigilante' ),
1481 'sendingTest' => __( 'Sending...', 'vigilante' ),
1482 'saved' => __( 'Settings saved', 'vigilante' ),
1483 'error' => __( 'Error saving settings', 'vigilante' ),
1484 'confirm' => __( 'Are you sure?', 'vigilante' ),
1485 'scanning' => __( 'Scanning...', 'vigilante' ),
1486 'scanComplete' => __( 'Scan complete', 'vigilante' ),
1487 'loading' => __( 'Loading...', 'vigilante' ),
1488 'searching' => __( 'Searching...', 'vigilante' ),
1489 'noUsersFound' => __( 'No users found', 'vigilante' ),
1490 'searchError' => __( 'Error searching users', 'vigilante' ),
1491 'sending' => __( 'Sending...', 'vigilante' ),
1492 'sendNotification' => __( 'Send notification now', 'vigilante' ),
1493 'notificationsSent' => __( 'notifications sent', 'vigilante' ),
1494 'skipped' => __( 'skipped', 'vigilante' ),
1495 'failed' => __( 'failed', 'vigilante' ),
1496 'customConfig' => __( 'Custom Configuration', 'vigilante' ),
1497 // Header tester strings
1498 'testHeaders' => __( 'Test Headers', 'vigilante' ),
1499 'testing' => __( 'Testing...', 'vigilante' ),
1500 'score' => __( 'Score', 'vigilante' ),
1501 'enabledHeaders' => __( 'Enabled headers', 'vigilante' ),
1502 'missingHeaders' => __( 'Missing headers', 'vigilante' ),
1503 'warnings' => __( 'Warnings', 'vigilante' ),
1504 // File integrity scan results strings
1505 'scanResults' => __( 'Scan Results', 'vigilante' ),
1506 'ok' => __( 'OK', 'vigilante' ),
1507 'modified' => __( 'Modified', 'vigilante' ),
1508 'suspicious' => __( 'Suspicious', 'vigilante' ),
1509 'totalScanned' => __( 'Total Scanned', 'vigilante' ),
1510 'suspiciousFiles' => __( 'Suspicious Files', 'vigilante' ),
1511 'suspiciousWarning' => __( 'These files may contain malicious code or are in unexpected locations. Review immediately!', 'vigilante' ),
1512 'file' => __( 'File', 'vigilante' ),
1513 'reason' => __( 'Reason', 'vigilante' ),
1514 'type' => __( 'Type', 'vigilante' ),
1515 'unknown' => __( 'Unknown', 'vigilante' ),
1516 'modifiedFiles' => __( 'Modified Files', 'vigilante' ),
1517 'modifiedDescription' => __( 'These files (apparently) differ from the original WordPress or plugin versions.', 'vigilante' ),
1518 'extraFiles' => __( 'Extra Files', 'vigilante' ),
1519 'extra' => __( 'Extra', 'vigilante' ),
1520 'ignored' => __( 'Ignored', 'vigilante' ),
1521 'extraDescription' => __( 'PHP files found in plugins or themes that are not part of the original distribution from WordPress.org.', 'vigilante' ),
1522 'actions' => __( 'Actions', 'vigilante' ),
1523 'ignore' => __( 'Ignore', 'vigilante' ),
1524 'ignoring' => __( 'Ignoring...', 'vigilante' ),
1525 'fileIgnored' => __( 'File added to ignored list.', 'vigilante' ),
1526 'fileUnignored' => __( 'File removed from ignored list.', 'vigilante' ),
1527 'confirmClearIgnored' => __( 'Remove all files from the ignored list? They will appear in scan results again.', 'vigilante' ),
1528 'ignoredCleared' => __( 'Ignored files list cleared. Page will reload...', 'vigilante' ),
1529 'selectAll' => __( 'Select all', 'vigilante' ),
1530 'bulkIgnoreSelected' => __( 'Ignore selected', 'vigilante' ),
1531 'bulkUnignoreSelected'=> __( 'Stop ignoring selected', 'vigilante' ),
1532 'bulkNoSelection' => __( 'Select at least one file first.', 'vigilante' ),
1533 'bulkConfirmIgnore' => __( 'Ignore the selected files? They will be hidden from future scan results until you remove them from the ignored list.', 'vigilante' ),
1534 'bulkConfirmUnignore' => __( 'Remove the selected files from the ignored list? They will appear in scan results again.', 'vigilante' ),
1535 'bulkProcessing' => __( 'Processing...', 'vigilante' ),
1536 /* translators: %d: number of files selected for bulk action. */
1537 'bulkSelectedCount' => __( '%d selected', 'vigilante' ),
1538 'allClear' => __( 'All files verified - no issues found!', 'vigilante' ),
1539 'criticalConfigTitle' => __( 'Critical config files modified', 'vigilante' ),
1540 'criticalConfigDesc' => __( 'These files are common targets for code injection. Review the changes and approve if they are legitimate. Vigilant\'s own blocks are excluded from this check.', 'vigilante' ),
1541 'approve' => __( 'Approve', 'vigilante' ),
1542 'approving' => __( 'Approving...', 'vigilante' ),
1543 'approvalLockedNotice' => $this->critical_approval_notice(),
1544 'criticalApproved' => __( 'Change approved. Next scan will use the current state as baseline.', 'vigilante' ),
1545 'reviewChanges' => __( 'Review changes', 'vigilante' ),
1546 'hideChanges' => __( 'Hide changes', 'vigilante' ),
1547 'changes' => __( 'Changes', 'vigilante' ),
1548 'diffUnavailable' => __( 'Diff not available for this file (baseline was created before diff tracking was added). Approve to enable diff on future changes.', 'vigilante' ),
1549 'diffEmpty' => __( 'No line-level changes detected (may be whitespace or reordering).', 'vigilante' ),
1550 'diffLines' => __( 'lines', 'vigilante' ),
1551 // Under Attack mode strings
1552 'underAttackConfirmActivate' => __( 'Activate Under Attack mode? All visitors will see a verification page for the next 4 hours.', 'vigilante' ),
1553 'underAttackConfirmDeactivate' => __( 'Deactivate Under Attack mode?', 'vigilante' ),
1554 'underAttackActivating' => __( 'Activating...', 'vigilante' ),
1555 'underAttackDeactivating' => __( 'Deactivating...', 'vigilante' ),
1556 // Database backup strings
1557 'dbBackupDownloading' => __( 'Generating backup...', 'vigilante' ),
1558 'dbBackupNoTables' => __( 'Please select at least one table.', 'vigilante' ),
1559 'dbBackupSuccess' => __( 'Database backup downloaded successfully.', 'vigilante' ),
1560 // Firewall unblock
1561 'confirmUnblockIp' => __( 'Unblock this IP from firewall rate limiting?', 'vigilante' ),
1562 // Database prefix strings
1563 'dbPrefixConfirm' => __( 'This operation will change your database prefix. It is irreversible. Make sure you have a current database backup before proceeding.', 'vigilante' ),
1564 'dbPrefixChanging' => __( 'Changing prefix...', 'vigilante' ),
1565 'dbPrefixSuccess' => __( 'Database prefix changed successfully. The page will reload now.', 'vigilante' ),
1566 'dbPrefixCheckbox' => __( 'You must confirm that you have a database backup.', 'vigilante' ),
1567 /* translators: 1: Hours, 2: Minutes */
1568 'underAttackRemaining' => __( '%1$dh %2$dm remaining', 'vigilante' ),
1569 'underAttackLabel' => __( 'Under Attack', 'vigilante' ),
1570 'standardLabel' => __( 'Standard', 'vigilante' ),
1571 'maximumLabel' => __( 'Maximum Security', 'vigilante' ),
1572 'deactivate' => __( 'Deactivate', 'vigilante' ),
1573 'underAttackActivate' => __( 'Activate for 4 hours', 'vigilante' ),
1574 // Settings strings
1575 'saveSettings' => __( 'Save Settings', 'vigilante' ),
1576 'settingsResetDefaults' => __( 'Settings reset to defaults.', 'vigilante' ),
1577 'confirmOverwrite' => __( 'This will overwrite your current settings.', 'vigilante' ),
1578 'importFailed' => __( 'Could not import settings. Check the file and try again.', 'vigilante' ),
1579 /* translators: 1: tests passed, 2: total tests in this category */
1580 'testsCounter' => __( '%1$d/%2$d tests', 'vigilante' ),
1581 'confirmResetAll' => __( 'This will reset ALL settings to defaults.', 'vigilante' ),
1582 'couldNotDetermineSection' => __( 'Could not determine section.', 'vigilante' ),
1583 'confirmResetSection' => __( 'Reset this section to default values? This cannot be undone.', 'vigilante' ),
1584 'sectionResetDefaults' => __( 'Section reset to defaults.', 'vigilante' ),
1585 /* translators: %s: preset name */
1586 'confirmApplyPreset' => __( 'Apply the "%s" preset?', 'vigilante' ),
1587 // Scan strings
1588 'scanFailed' => __( 'Scan failed', 'vigilante' ),
1589 /* translators: %s: error message */
1590 'scanError' => __( 'Scan error: %s', 'vigilante' ),
1591 'runScanNow' => __( 'Run Scan Now', 'vigilante' ),
1592 'confirmClearScan' => __( 'Are you sure you want to clear all scan results?', 'vigilante' ),
1593 'clearing' => __( 'Clearing...', 'vigilante' ),
1594 'scanResultsCleared' => __( 'Scan results cleared. Page will reload...', 'vigilante' ),
1595 'failedClearResults' => __( 'Failed to clear results', 'vigilante' ),
1596 /* translators: %s: error message */
1597 'ajaxError' => __( 'AJAX Error: %s', 'vigilante' ),
1598 // Activity log popup strings
1599 'logRequest' => __( 'Request', 'vigilante' ),
1600 'logDate' => __( 'Date', 'vigilante' ),
1601 'logMethod' => __( 'Method', 'vigilante' ),
1602 'logType' => __( 'Type', 'vigilante' ),
1603 'logAction' => __( 'Action', 'vigilante' ),
1604 'logSeverity' => __( 'Severity', 'vigilante' ),
1605 'logMessage' => __( 'Message', 'vigilante' ),
1606 'logRequestUri' => __( 'Address', 'vigilante' ),
1607 'logClient' => __( 'Client', 'vigilante' ),
1608 'logUser' => __( 'User', 'vigilante' ),
1609 'logIpAddress' => __( 'IP Address', 'vigilante' ),
1610 'logUserAgent' => __( 'User Agent', 'vigilante' ),
1611 'logIpLabel' => __( 'IP:', 'vigilante' ),
1612 'logUaLabel' => __( 'UA:', 'vigilante' ),
1613 'logWhitelist' => __( 'Whitelist', 'vigilante' ),
1614 'logBlacklist' => __( 'Blacklist', 'vigilante' ),
1615 'logInWhitelist' => __( 'In whitelist', 'vigilante' ),
1616 'logInBlacklist' => __( 'In blacklist', 'vigilante' ),
1617 'logAdded' => __( 'Added!', 'vigilante' ),
1618 'logErrorAddingToList' => __( 'Error adding to list', 'vigilante' ),
1619 'logRequestFailed' => __( 'Request failed', 'vigilante' ),
1620 // Activity log table strings
1621 'noLogEntries' => __( 'No log entries found.', 'vigilante' ),
1622 'view' => __( 'View', 'vigilante' ),
1623 'confirmClearLogs' => __( 'This will delete all audit logs.', 'vigilante' ),
1624 // Export logs strings
1625 'exporting' => __( 'Exporting...', 'vigilante' ),
1626 /* translators: %d: number of entries */
1627 'logsExported' => __( 'Logs exported (%d entries)', 'vigilante' ),
1628 'noLogsToExport' => __( 'No logs to export', 'vigilante' ),
1629 'exportFailed' => __( 'Export failed', 'vigilante' ),
1630 'exportLogs' => __( 'Export Logs', 'vigilante' ),
1631 // Backup strings
1632 'backupCreated' => __( 'Backup created successfully.', 'vigilante' ),
1633 'createBackupNow' => __( 'Download Backup', 'vigilante' ),
1634 'downloadBackup' => __( 'Download Backup (.zip)', 'vigilante' ),
1635 /* translators: %d: number of tables */
1636 'tablesCount' => __( '%d tables', 'vigilante' ),
1637 /* translators: 1: table count, 2: human-readable size */
1638 'dbTablesTotal' => __( '%1$d tables total (%2$s)', 'vigilante' ),
1639 /* translators: 1: selected count, 2: human-readable size */
1640 'dbTablesSelected' => __( '%1$d tables selected (%2$s)', 'vigilante' ),
1641 // Settings search strings
1642 'searchNoResults' => __( 'No matching settings found.', 'vigilante' ),
1643 /* translators: %d: number of results that did not fit in the list. */
1644 'searchMoreResults' => __( '%d more results. Refine the search to see them.', 'vigilante' ),
1645 'searchInTab' => __( 'in', 'vigilante' ),
1646 // Modules string
1647 /* translators: 1: enabled count, 2: total count */
1648 'modulesEnabled' => __( '%1$d / %2$d modules enabled', 'vigilante' ),
1649 // Activity log label maps for JS rendering
1650 'eventTypeLabels' => array(
1651 'login' => __( 'Login', 'vigilante' ),
1652 'user' => __( 'User', 'vigilante' ),
1653 'content' => __( 'Content', 'vigilante' ),
1654 'plugin' => __( 'Plugin', 'vigilante' ),
1655 'theme' => __( 'Theme', 'vigilante' ),
1656 'settings' => __( 'Settings', 'vigilante' ),
1657 'comment' => __( 'Comment', 'vigilante' ),
1658 'media' => __( 'Media', 'vigilante' ),
1659 'firewall' => __( 'Firewall', 'vigilante' ),
1660 'file' => __( 'File', 'vigilante' ),
1661 'security' => __( 'Security', 'vigilante' ),
1662 'system' => __( 'System', 'vigilante' ),
1663 ),
1664 'severityLabels' => array(
1665 'info' => __( 'Info', 'vigilante' ),
1666 'warning' => __( 'Warning', 'vigilante' ),
1667 'critical' => __( 'Critical', 'vigilante' ),
1668 ),
1669 // Password reset strings
1670 'noUsersFoundSearch' => __( 'No users found', 'vigilante' ),
1671 /* translators: %d: number of users */
1672 'confirmForceReset' => __( 'Force password reset for %d user(s)? A password reset email will be sent to each user.', 'vigilante' ),
1673 'warningResettingSelf' => __( 'WARNING: You are including yourself. Your session will end and you will need to set a new password.', 'vigilante' ),
1674 'processing' => __( 'Processing...', 'vigilante' ),
1675 'anErrorOccurred' => __( 'An error occurred', 'vigilante' ),
1676 'forceResetSelected' => __( 'Force Reset for Selected Users', 'vigilante' ),
1677 'confirmForceResetAll' => __( 'This will force ALL users to reset their password. All users will receive a password reset email. Are you sure you want to continue?', 'vigilante' ),
1678 'warningResettingSelfAll' => __( 'WARNING: You are including yourself. Your session will end immediately.', 'vigilante' ),
1679 'forceResetAll' => __( 'Force Reset for ALL Users', 'vigilante' ),
1680 // Role-based password reset strings
1681 /* translators: %d: number of users */
1682 'confirmForceResetByRole' => __( 'Force password reset for %d user(s) with the selected roles? A password reset email will be sent to each user.', 'vigilante' ),
1683 'noRolesSelected' => __( 'Please select at least one role.', 'vigilante' ),
1684 'forceResetByRole' => __( 'Force Reset for Selected Roles', 'vigilante' ),
1685 // User approval strings
1686 'confirmApprove' => __( 'Approve this user?', 'vigilante' ),
1687 'approve' => __( 'Approve', 'vigilante' ),
1688 'rejectReason' => __( 'Enter rejection reason (optional):', 'vigilante' ),
1689 'reject' => __( 'Reject', 'vigilante' ),
1690 'noPending' => __( 'No pending registrations.', 'vigilante' ),
1691 // Session management strings
1692 'confirmRevoke' => __( 'Revoke this session?', 'vigilante' ),
1693 'confirmRevokeAll' => __( 'Revoke all other sessions?', 'vigilante' ),
1694 'revokeOthers' => __( 'Revoke All Other Sessions', 'vigilante' ),
1695 'confirmRevokeAllUser' => __( 'Revoke ALL sessions for this user? They will be logged out everywhere.', 'vigilante' ),
1696 'sessionsFor' => __( 'Sessions for:', 'vigilante' ),
1697 'noSessions' => __( 'No active sessions', 'vigilante' ),
1698 'revoke' => __( 'Revoke', 'vigilante' ),
1699 'noUsers' => __( 'No users found', 'vigilante' ),
1700 // Time ago strings
1701 'timeYear' => __( 'year', 'vigilante' ),
1702 'timeYears' => __( 'years', 'vigilante' ),
1703 'timeMonth' => __( 'month', 'vigilante' ),
1704 'timeMonths' => __( 'months', 'vigilante' ),
1705 'timeDay' => __( 'day', 'vigilante' ),
1706 'timeDays' => __( 'days', 'vigilante' ),
1707 'timeHour' => __( 'hour', 'vigilante' ),
1708 'timeHours' => __( 'hours', 'vigilante' ),
1709 'timeMinute' => __( 'minute', 'vigilante' ),
1710 'timeMinutes' => __( 'minutes', 'vigilante' ),
1711 /* translators: %1$d: count, %2$s: time unit */
1712 'timeAgo' => __( '%1$d %2$s ago', 'vigilante' ),
1713 'justNow' => __( 'Just now', 'vigilante' ),
1714 // Pagination strings
1715 /* translators: 1: first item number, 2: last item number, 3: total items */
1716 'paginationOf' => __( '%1$d–%2$d of %3$d', 'vigilante' ),
1717 'paginationEmpty' => __( '0 items', 'vigilante' ),
1718 // Security Analyzer strings
1719 'analyzerScanNow' => __( 'Scan now', 'vigilante' ),
1720 'analyzerScanning' => __( 'Scanning…', 'vigilante' ),
1721 'analyzerFastPhase' => __( 'Running fast checks…', 'vigilante' ),
1722 'analyzerSlowPhase' => __( 'Running remote checks…', 'vigilante' ),
1723 'analyzerScanComplete' => __( 'Security scan complete.', 'vigilante' ),
1724 'analyzerScanFailed' => __( 'Security scan failed.', 'vigilante' ),
1725 'analyzerShowDetails' => __( 'Show detailed breakdown', 'vigilante' ),
1726 'analyzerHideDetails' => __( 'Hide detailed breakdown', 'vigilante' ),
1727 'analyzerGoToSetting' => __( 'Go to setting', 'vigilante' ),
1728 'analyzerNoData' => __( 'No data yet — run a scan to populate this category.', 'vigilante' ),
1729 'analyzerJustNow' => __( 'just now', 'vigilante' ),
1730 'analyzerAgo' => __( 'ago', 'vigilante' ),
1731 'analyzerSettingsSaved' => __( 'Analyzer settings saved.', 'vigilante' ),
1732 'analyzerLastScanJustNow' => __( 'Last scan just now', 'vigilante' ),
1733 'analyzerQualityExcellent' => __( 'Excellent', 'vigilante' ),
1734 'analyzerQualityGood' => __( 'Good', 'vigilante' ),
1735 'analyzerQualityFair' => __( 'Fair', 'vigilante' ),
1736 'analyzerQualityPoor' => __( 'Poor', 'vigilante' ),
1737 'analyzerQualityCritical' => __( 'Critical', 'vigilante' ),
1738 'analyzerPts' => __( 'pts', 'vigilante' ),
1739 'analyzerLearnMore' => __( 'Learn more', 'vigilante' ),
1740 'analyzerInfoAllClear' => __( 'All clear', 'vigilante' ),
1741 /* translators: %d: number of findings in an info-only category */
1742 'analyzerInfoFindings' => __( '%d findings', 'vigilante' ),
1743 ),
1744 ) );
1745
1746 // 2FA Admin assets
1747 wp_enqueue_style(
1748 'vigilante-2fa-admin',
1749 VIGILANTE_ASSETS_URL . 'css/two-factor-admin.css',
1750 array( 'vigilante-admin' ),
1751 VIGILANTE_VERSION
1752 );
1753
1754 wp_enqueue_script(
1755 'vigilante-2fa-admin',
1756 VIGILANTE_ASSETS_URL . 'js/two-factor-admin.js',
1757 array( 'jquery', 'vigilante-admin' ),
1758 VIGILANTE_VERSION,
1759 true
1760 );
1761 }
1762
1763 /**
1764 * Show admin notices
1765 */
1766 public function show_admin_notices() {
1767 // Activation notice
1768 if ( get_transient( 'vigilante_activated' ) ) {
1769 ?>
1770 <div class="notice notice-success is-dismissible vigilante-activation-notice">
1771 <p>
1772 <span class="dashicons dashicons-shield vigilante-notice-icon"></span>
1773 <strong><?php esc_html_e( 'Vigilant activated successfully!', 'vigilante' ); ?></strong>
1774 <?php esc_html_e( 'Security protection is now active.', 'vigilante' ); ?>
1775 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante' ) ); ?>">
1776 <?php esc_html_e( 'Configure settings', 'vigilante' ); ?>
1777 </a>
1778 </p>
1779 </div>
1780 <?php
1781 delete_transient( 'vigilante_activated' );
1782 }
1783
1784 // Under Attack mode notice (non-dismissible, shown on all admin pages)
1785 $ua_status = get_option( Vigilante_Under_Attack::OPTION_NAME, array() );
1786 if ( ! empty( $ua_status['active'] ) ) {
1787 $ua_remaining = ( $ua_status['activated_at'] + $ua_status['duration'] ) - time();
1788 if ( $ua_remaining > 0 ) {
1789 $ua_hours = floor( $ua_remaining / 3600 );
1790 $ua_mins = floor( ( $ua_remaining % 3600 ) / 60 );
1791 $dashboard_url = admin_url( 'admin.php?page=vigilante' );
1792 ?>
1793 <div class="notice notice-warning vigilante-ua-notice">
1794 <p>
1795 <span class="dashicons dashicons-shield"></span>
1796 <strong><?php esc_html_e( 'Under Attack mode is active', 'vigilante' ); ?></strong>
1797 &mdash;
1798 <?php
1799 printf(
1800 /* translators: 1: Hours, 2: Minutes */
1801 esc_html__( '%1$dh %2$dm remaining.', 'vigilante' ),
1802 absint( $ua_hours ),
1803 absint( $ua_mins )
1804 );
1805 ?>
1806 <a href="<?php echo esc_url( $dashboard_url ); ?>">
1807 <?php esc_html_e( 'Go to Vigilant dashboard', 'vigilante' ); ?>
1808 </a>
1809 </p>
1810 <p>
1811 <em><?php esc_html_e( 'Vigilant has applied the Maximum preset plus extra hardening on top of your previous configuration. Any changes you make to Vigilant settings while this mode is active will be reverted when it ends.', 'vigilante' ); ?></em>
1812 </p>
1813 <?php
1814 // The cache-bypass rules could not be written (a host where
1815 // WordPress cannot write files by itself, a held lock, a
1816 // failed read-back): show them, so they can be added by hand.
1817 $ua_instance = new Vigilante_Under_Attack( $this->settings, $this->activity_log );
1818 if ( $ua_instance->cache_rules_missing() ) :
1819 ?>
1820 <p>
1821 <strong><?php esc_html_e( 'The cache-bypass rules could not be written to your .htaccess.', 'vigilante' ); ?></strong>
1822 <?php esc_html_e( 'Without them a page cache may keep serving stored pages during the attack. Add this block at the top of the .htaccess in your site root (the activity log records why it was not written):', 'vigilante' ); ?>
1823 </p>
1824 <textarea readonly rows="9" class="large-text code" onclick="this.select();"><?php echo esc_textarea( Vigilante_Under_Attack::get_cache_bypass_block() ); ?></textarea>
1825 <?php endif; ?>
1826 </div>
1827 <?php
1828 }
1829 }
1830
1831 // Proxy/CDN detection: if IP detection is set to "direct" but requests
1832 // arrive with a forwarded-for header carrying a different valid IP, the
1833 // site is very likely behind a proxy/CDN that has not been declared, so
1834 // the firewall is seeing the proxy IP for every visitor. Guide the admin.
1835 //
1836 // Two deliberate silencers (2.9.2):
1837 // - A loopback forwarded IP (::1 / 127.x) means the person browsing IS
1838 // the machine itself: that only happens in local development stacks
1839 // (Local's nginx router, Docker...), never behind a production
1840 // proxy/CDN, so the notice would be pure noise there.
1841 // - The notice is dismissible and the dismissal persists site-wide via
1842 // the vigilante_dismissed_notices option (the admin evaluated it and
1843 // decided; nagging forever helps nobody).
1844 $dismissed_notices = get_option( 'vigilante_dismissed_notices', array() );
1845 if (
1846 current_user_can( 'manage_options' )
1847 && '' === Vigilante_IP_Utils::trusted_proxy_header()
1848 && ! isset( $dismissed_notices['proxy_detection'] )
1849 ) {
1850 $remote = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '';
1851 $detected = '';
1852 foreach ( Vigilante_IP_Utils::trusted_header_map() as $proxy_label => $server_key ) {
1853 if ( empty( $_SERVER[ $server_key ] ) ) {
1854 continue;
1855 }
1856 $candidate = sanitize_text_field( wp_unslash( $_SERVER[ $server_key ] ) );
1857 if ( false !== strpos( $candidate, ',' ) ) {
1858 $parts = explode( ',', $candidate );
1859 $candidate = trim( $parts[0] );
1860 }
1861 if ( ! filter_var( $candidate, FILTER_VALIDATE_IP ) || $candidate === $remote ) {
1862 continue;
1863 }
1864 // Loopback forwarded IP = local development, not a real proxy.
1865 if ( '::1' === $candidate || 0 === strpos( $candidate, '127.' ) ) {
1866 continue;
1867 }
1868 $detected = $proxy_label;
1869 break;
1870 }
1871
1872 if ( '' !== $detected ) {
1873 $firewall_url = admin_url( 'admin.php?page=vigilante&tab=firewall' );
1874 $detail_message = sprintf(
1875 /* translators: %s: detected forwarded header name wrapped in a code tag. */
1876 esc_html__( 'Requests are arriving with a %s header, but visitor IP detection is set to direct connection. The firewall is reading the proxy address instead of the real visitor IP, which affects the IP lists and rate limiting.', 'vigilante' ),
1877 '<code>' . esc_html( strtoupper( $detected ) ) . '</code>'
1878 );
1879 ?>
1880 <div class="notice notice-warning is-dismissible vigilante-proxy-notice">
1881 <p>
1882 <span class="dashicons dashicons-shield"></span>
1883 <strong><?php esc_html_e( 'Vigilant: this site looks like it is behind a proxy or CDN', 'vigilante' ); ?></strong>
1884 </p>
1885 <p><?php echo wp_kses_post( $detail_message ); ?></p>
1886 <p>
1887 <a href="<?php echo esc_url( $firewall_url ); ?>" class="button button-secondary">
1888 <?php esc_html_e( 'Set your proxy in Firewall settings', 'vigilante' ); ?>
1889 </a>
1890 </p>
1891 </div>
1892 <script>
1893 jQuery( function ( $ ) {
1894 $( document ).on( 'click', '.vigilante-proxy-notice .notice-dismiss', function () {
1895 $.post( ajaxurl, {
1896 action: 'vigilante_dismiss_notice',
1897 notice_id: 'proxy_detection',
1898 nonce: <?php echo wp_json_encode( wp_create_nonce( 'vigilante_dismiss_notice' ) ); ?>
1899 } );
1900 } );
1901 } );
1902 </script>
1903 <?php
1904 }
1905 }
1906 }
1907
1908 /**
1909 * Render settings page
1910 */
1911 public function render_settings_page() {
1912 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
1913 $this->current_tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'dashboard';
1914
1915 if ( ! array_key_exists( $this->current_tab, $this->tabs ) ) {
1916 $this->current_tab = 'dashboard';
1917 }
1918 ?>
1919 <div class="wrap vigilante-admin-wrap">
1920 <div class="vigilante-header-row">
1921 <h1 class="vigilante-page-title">
1922 <img src="<?php echo esc_url( VIGILANTE_ASSETS_URL . 'images/icon.png' ); ?>" alt="Vigilante" class="vigilante-title-icon">
1923 <?php esc_html_e( 'Vigilant', 'vigilante' ); ?>
1924 <span class="vigilante-version">v<?php echo esc_html( VIGILANTE_VERSION ); ?></span>
1925 </h1>
1926 <div class="vigilante-search-wrapper">
1927 <div class="vigilante-search-input-wrap">
1928 <span class="vigilante-search-icon dashicons dashicons-search" aria-hidden="true"></span>
1929 <input type="search" id="vigilante-settings-search" class="vigilante-settings-search" aria-label="<?php esc_attr_e( 'Search settings', 'vigilante' ); ?>" placeholder="<?php esc_attr_e( 'Search settings…', 'vigilante' ); ?>" autocomplete="off">
1930 <span class="vigilante-search-shortcut" aria-hidden="true">/</span>
1931 </div>
1932 <div id="vigilante-settings-search-results" class="vigilante-search-results" hidden role="listbox"></div>
1933 </div>
1934 </div>
1935
1936 <?php $this->render_tabs(); ?>
1937
1938 <div class="vigilante-content">
1939 <div class="vigilante-main">
1940 <?php $this->render_tab_content(); ?>
1941 </div>
1942 <div class="vigilante-sidebar">
1943 <?php $this->render_sidebar(); ?>
1944 </div>
1945 </div>
1946 </div>
1947 <?php
1948 }
1949
1950 /**
1951 * Render tabs navigation
1952 */
1953 private function render_tabs() {
1954 $options = $this->settings->get_all_options();
1955
1956 // Map tabs to modules
1957 $tab_to_module = array(
1958 'firewall' => 'firewall',
1959 'headers' => 'security_headers',
1960 'login' => 'login_security',
1961 'rest-api' => 'rest_api_security',
1962 'users' => 'user_security',
1963 'wp-hardening' => 'wp_hardening',
1964 'file-integrity' => 'file_integrity',
1965 'activity-log' => 'activity_log',
1966 );
1967 ?>
1968 <nav class="nav-tab-wrapper vigilante-nav-tabs">
1969 <?php foreach ( $this->tabs as $tab_id => $tab_name ) :
1970 $is_disabled = false;
1971 $module = isset( $tab_to_module[ $tab_id ] ) ? $tab_to_module[ $tab_id ] : null;
1972 if ( $module && empty( $options['modules'][ $module ] ) ) {
1973 $is_disabled = true;
1974 }
1975 ?>
1976 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=' . $tab_id ) ); ?>"
1977 class="nav-tab <?php echo $this->current_tab === $tab_id ? 'nav-tab-active' : ''; ?> <?php echo $is_disabled ? 'vigilante-tab-disabled' : ''; ?>"
1978 <?php if ( $is_disabled ) : ?>title="<?php esc_attr_e( 'Module Disabled', 'vigilante' ); ?>"<?php endif; ?>>
1979 <?php echo esc_html( $tab_name ); ?>
1980 <?php if ( $is_disabled ) : ?><span class="vigilante-tab-off">OFF</span><?php endif; ?>
1981 </a>
1982 <?php endforeach; ?>
1983 </nav>
1984 <?php
1985 }
1986
1987 /**
1988 * Render current tab content
1989 */
1990 private function render_tab_content() {
1991 $method = 'render_tab_' . str_replace( '-', '_', $this->current_tab );
1992
1993 if ( method_exists( $this, $method ) ) {
1994 $this->$method();
1995 } else {
1996 $this->render_tab_coming_soon();
1997 }
1998 }
1999
2000 /**
2001 * Render coming soon placeholder
2002 */
2003 private function render_tab_coming_soon() {
2004 ?>
2005 <div class="vigilante-settings-section">
2006 <h2><?php esc_html_e( 'Coming Soon', 'vigilante' ); ?></h2>
2007 <p><?php esc_html_e( 'This section is under development.', 'vigilante' ); ?></p>
2008 </div>
2009 <?php
2010 }
2011
2012 /**
2013 * Values to display for a section that this site does not control
2014 *
2015 * On a subsite the stored options are its own copy, which nothing acts on:
2016 * wp-config.php and .htaccess are written from the main site. Painting the
2017 * local copy describes a configuration that is not running, so a subsite
2018 * admin sees a box ticked here and the constant absent from the file, or the
2019 * other way round. Read the main site's values instead, which are the ones in
2020 * force, and fall back to the local ones if they cannot be read.
2021 *
2022 * @since 2.9.8
2023 *
2024 * @param string $section Settings section.
2025 * @return array
2026 */
2027 private function get_section_for_display( $section ) {
2028 $local = $this->settings->get_section( $section );
2029
2030 if ( ! $this->shared_files_locked() ) {
2031 return $local;
2032 }
2033
2034 // shared_files_locked() is only true on multisite, where get_blog_option() exists.
2035 $main = get_blog_option( get_main_site_id(), Vigilante_Settings::OPTION_NAME, array() );
2036
2037 if ( ! is_array( $main ) || empty( $main[ $section ] ) || ! is_array( $main[ $section ] ) ) {
2038 return $local;
2039 }
2040
2041 return wp_parse_args( $main[ $section ], $local );
2042 }
2043
2044 /**
2045 * Whether the sections that write wp-config.php and .htaccess are read-only here
2046 *
2047 * True on a network when this is not the main site, or the user is not a
2048 * network administrator. See Vigilante_Settings::can_write_shared_files().
2049 *
2050 * @since 2.9.8
2051 *
2052 * @return bool
2053 */
2054 private function shared_files_locked() {
2055 return ! Vigilante_Settings::can_write_shared_files();
2056 }
2057
2058 /**
2059 * Print the shared-files notice for a section that cannot be edited here
2060 *
2061 * @since 2.9.8
2062 */
2063 private function render_shared_files_notice() {
2064 if ( ! $this->shared_files_locked() ) {
2065 return;
2066 }
2067 ?>
2068 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
2069 <p style="margin:0;"><?php echo esc_html( Vigilante_Settings::get_shared_files_notice() ); ?></p>
2070 </div>
2071 <?php
2072 }
2073
2074 /**
2075 * Acting on another user's account needs permission over that user
2076 *
2077 * Since 2.10.3 the handlers behind these tools ask for edit_user over the
2078 * target, which is the rule WordPress itself applies. On a network the core
2079 * grants edit_user only to network administrators, so for anybody else these
2080 * controls do nothing. Better to say so than to paint a button that silently
2081 * skips every user.
2082 *
2083 * @since 2.10.4
2084 * @return bool
2085 */
2086 private function user_actions_locked() {
2087 return is_multisite() && ! current_user_can( 'manage_network_users' );
2088 }
2089
2090 /**
2091 * Print the notice for user tools that cannot be used from this site
2092 *
2093 * @since 2.10.4
2094 */
2095 private function render_user_actions_notice() {
2096 if ( ! $this->user_actions_locked() ) {
2097 return;
2098 }
2099 ?>
2100 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
2101 <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>
2102 </div>
2103 <?php
2104 }
2105
2106 /**
2107 * Approving a change to the shared config files needs the network
2108 *
2109 * Since 2.11.3 the handler behind the Approve button asks for
2110 * manage_network_options, because the two files it approves, wp-config.php
2111 * and the root .htaccess, belong to the installation, and so does the
2112 * record of them. The button, though, went on being painted for everybody,
2113 * so the administrator of a subsite saw the warning, saw the button,
2114 * pressed it and got "Permission denied" with no explanation. That is
2115 * exactly what user_actions_locked() above exists to avoid, one release
2116 * later and one screen over. Flagged by @calzbert.
2117 *
2118 * @since 2.11.4
2119 * @return bool
2120 */
2121 private function critical_approval_locked() {
2122 return is_multisite() && ! current_user_can( 'manage_network_options' );
2123 }
2124
2125 /**
2126 * The line that replaces the Approve button where it cannot be used
2127 *
2128 * @since 2.11.4
2129 * @return string
2130 */
2131 private function critical_approval_notice() {
2132 return __( 'These files belong to the whole network rather than to this site, so a change to them is approved from the network admin.', 'vigilante' );
2133 }
2134
2135 /**
2136 * Check if module is disabled and render warning
2137 *
2138 * @param string $module_key Module key.
2139 * @return bool True if disabled.
2140 */
2141 private function render_module_disabled_notice( $module_key ) {
2142 if ( $this->settings->is_module_enabled( $module_key ) ) {
2143 return false;
2144 }
2145
2146 $module_labels = $this->settings->get_module_labels();
2147 $module_name = isset( $module_labels[ $module_key ] ) ? $module_labels[ $module_key ] : $module_key;
2148 ?>
2149 <div class="notice notice-warning vigilante-module-disabled-notice">
2150 <p>
2151 <strong><?php esc_html_e( 'Module Disabled', 'vigilante' ); ?></strong> -
2152 <?php
2153 printf(
2154 /* translators: %s: Module name */
2155 esc_html__( 'The %s module is currently disabled. Enable it from the Dashboard to use these settings.', 'vigilante' ),
2156 esc_html( $module_name )
2157 );
2158 ?>
2159 </p>
2160 <p>
2161 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=dashboard' ) ); ?>" class="button">
2162 <?php esc_html_e( 'Go to Dashboard', 'vigilante' ); ?>
2163 </a>
2164 </p>
2165 </div>
2166 <?php
2167 return true;
2168 }
2169
2170 /**
2171 * Render the Security Analyzer (Security Check) widget + expandable full report.
2172 *
2173 * Lives in the Dashboard tab between the Configuration Score status card and
2174 * the modules grid. Uses the last persisted scan to hydrate server-side so the
2175 * first paint shows real data; "Scan now" runs the 2-phase AJAX to refresh.
2176 *
2177 * @param array $last_scan Result of Vigilante_Security_Analyzer::get_last_scan().
2178 * @param array $history Score history (oldest first).
2179 * @param array $categories_def Category metadata (slug => label/max).
2180 * @param array $analyzer_settings Settings subsection for weekly cron + email.
2181 */
2182 private function render_analyzer_widget( $last_scan, $history, $categories_def, $analyzer_settings ) {
2183 $has_data = ! empty( $last_scan['ran_at'] );
2184 $score = isset( $last_scan['score'] ) ? (int) $last_scan['score'] : 0;
2185 $grade = isset( $last_scan['grade'] ) ? (string) $last_scan['grade'] : '';
2186 $counts = isset( $last_scan['counts'] ) && is_array( $last_scan['counts'] ) ? $last_scan['counts'] : array();
2187 $ran_at_human = $has_data
2188 ? sprintf(
2189 /* translators: %s: relative time like "2 hours" */
2190 __( 'Last scan %s ago', 'vigilante' ),
2191 human_time_diff( (int) $last_scan['ran_at'], time() )
2192 )
2193 : __( 'Never scanned', 'vigilante' );
2194 $categories = isset( $last_scan['categories'] ) && is_array( $last_scan['categories'] ) ? $last_scan['categories'] : array();
2195 $weekly_enabled = ! isset( $analyzer_settings['weekly_scan_enabled'] ) || ! empty( $analyzer_settings['weekly_scan_enabled'] );
2196 $email_enabled = ! empty( $analyzer_settings['email_on_regression'] );
2197
2198 $quality = self::analyzer_quality_tag( $score );
2199 ?>
2200 <div class="vigilante-analyzer" id="vigilante-analyzer"
2201 data-has-data="<?php echo $has_data ? '1' : '0'; ?>">
2202 <div class="vigilante-analyzer-header">
2203 <div class="vigilante-analyzer-title">
2204 <h2>
2205 <span class="dashicons dashicons-shield-alt" aria-hidden="true"></span>
2206 <?php esc_html_e( 'Security Check', 'vigilante' ); ?>
2207 </h2>
2208 <p class="description">
2209 <?php esc_html_e( 'On-demand audit of what an attacker would see right now, plus 13 internal checks impossible from the outside.', 'vigilante' ); ?>
2210 </p>
2211 <p class="vigilante-analyzer-last-scan" data-role="ran-at">
2212 <span class="dashicons dashicons-clock" aria-hidden="true"></span>
2213 <?php echo esc_html( $ran_at_human ); ?>
2214 </p>
2215 </div>
2216 <div class="vigilante-analyzer-actions">
2217 <button type="button" class="button button-primary" id="vigilante-analyzer-scan">
2218 <span class="dashicons dashicons-update" aria-hidden="true"></span>
2219 <?php esc_html_e( 'Scan now', 'vigilante' ); ?>
2220 </button>
2221 </div>
2222 </div>
2223
2224 <div class="vigilante-analyzer-summary">
2225 <div class="vigilante-analyzer-score-card">
2226 <?php if ( $has_data && $grade ) : ?>
2227 <div class="vigilante-score-circle vigilante-grade-<?php echo esc_attr( strtolower( $grade ) ); ?>">
2228 <span class="vigilante-grade"><?php echo esc_html( $grade ); ?></span>
2229 <span class="vigilante-score-text"><?php echo esc_html( $score ); ?>%</span>
2230 </div>
2231 <?php else : ?>
2232 <div class="vigilante-score-circle vigilante-grade-empty">
2233 <span class="vigilante-grade">—</span>
2234 <span class="vigilante-score-text"><?php esc_html_e( 'N/A', 'vigilante' ); ?></span>
2235 </div>
2236 <?php endif; ?>
2237 <div class="vigilante-analyzer-score-meta">
2238 <p class="vigilante-analyzer-score-label">
2239 <?php esc_html_e( 'Security Score', 'vigilante' ); ?>
2240 </p>
2241 <span class="vigilante-analyzer-quality-tag vigilante-analyzer-quality-<?php echo esc_attr( $quality['slug'] ); ?>"
2242 data-role="quality-tag">
2243 <?php echo esc_html( $quality['label'] ); ?>
2244 </span>
2245 </div>
2246 </div>
2247
2248 <div class="vigilante-analyzer-counts">
2249 <span class="vigilante-analyzer-count vigilante-analyzer-count--pass">
2250 <span class="dashicons dashicons-yes-alt" aria-hidden="true"></span>
2251 <strong data-role="pass"><?php echo esc_html( isset( $counts['pass'] ) ? $counts['pass'] : 0 ); ?></strong>
2252 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Passed', 'vigilante' ); ?></span>
2253 </span>
2254 <span class="vigilante-analyzer-count vigilante-analyzer-count--warn">
2255 <span class="dashicons dashicons-warning" aria-hidden="true"></span>
2256 <strong data-role="warn"><?php echo esc_html( isset( $counts['warn'] ) ? $counts['warn'] : 0 ); ?></strong>
2257 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Warnings', 'vigilante' ); ?></span>
2258 </span>
2259 <span class="vigilante-analyzer-count vigilante-analyzer-count--fail">
2260 <span class="dashicons dashicons-dismiss" aria-hidden="true"></span>
2261 <strong data-role="fail"><?php echo esc_html( isset( $counts['fail'] ) ? $counts['fail'] : 0 ); ?></strong>
2262 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Failing', 'vigilante' ); ?></span>
2263 </span>
2264 </div>
2265
2266 <?php
2267 // Sparkline of recent scores. Require at least 3 data points so the trend
2268 // is meaningful (2 points is just a line between dots, no real trend).
2269 $hist_points = array();
2270 foreach ( $history as $h ) {
2271 $hist_points[] = (int) $h['score'];
2272 }
2273 $hist_count = count( $hist_points );
2274 if ( $hist_count >= 3 ) :
2275 $current_score = (int) end( $hist_points );
2276 $previous_score = (int) $hist_points[ $hist_count - 2 ];
2277 $delta = $current_score - $previous_score;
2278 $delta_class = $delta > 0 ? 'vigilante-analyzer-delta--up' : ( $delta < 0 ? 'vigilante-analyzer-delta--down' : 'vigilante-analyzer-delta--flat' );
2279 $delta_icon = $delta > 0 ? 'arrow-up-alt' : ( $delta < 0 ? 'arrow-down-alt' : 'minus' );
2280 if ( 0 === $delta ) {
2281 $delta_text = __( 'No change', 'vigilante' );
2282 } else {
2283 $delta_text = sprintf(
2284 /* translators: %s: signed delta, e.g. "+3" or "-5" */
2285 _n( '%s pt vs. previous scan', '%s pts vs. previous scan', abs( $delta ), 'vigilante' ),
2286 ( $delta > 0 ? '+' : '' ) . (int) $delta
2287 );
2288 }
2289 ?>
2290 <div class="vigilante-analyzer-sparkline-wrap">
2291 <div class="vigilante-analyzer-sparkline-head">
2292 <span class="vigilante-analyzer-sparkline-label">
2293 <?php
2294 echo esc_html( sprintf(
2295 /* translators: %d: number of scans */
2296 _n( 'Score trend (last %d scan)', 'Score trend (last %d scans)', $hist_count, 'vigilante' ),
2297 $hist_count
2298 ) );
2299 ?>
2300 </span>
2301 <span class="vigilante-analyzer-delta <?php echo esc_attr( $delta_class ); ?>">
2302 <span class="dashicons dashicons-<?php echo esc_attr( $delta_icon ); ?>" aria-hidden="true"></span>
2303 <?php echo esc_html( $delta_text ); ?>
2304 </span>
2305 </div>
2306 <div class="vigilante-analyzer-sparkline" data-role="sparkline"
2307 data-points="<?php echo esc_attr( wp_json_encode( $hist_points ) ); ?>">
2308 <?php echo self::sparkline_svg( $hist_points ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Safe SVG from helper ?>
2309 </div>
2310 </div>
2311 <?php elseif ( $has_data ) : ?>
2312 <div class="vigilante-analyzer-sparkline-wrap vigilante-analyzer-sparkline-wrap--placeholder">
2313 <span class="vigilante-analyzer-sparkline-label">
2314 <?php esc_html_e( 'Score trend', 'vigilante' ); ?>
2315 </span>
2316 <p class="vigilante-analyzer-sparkline-hint">
2317 <span class="dashicons dashicons-chart-line" aria-hidden="true"></span>
2318 <?php
2319 $needed = 3 - $hist_count;
2320 echo esc_html( sprintf(
2321 /* translators: %d: number of additional scans needed */
2322 _n( '%d more scan needed to show a trend.', '%d more scans needed to show a trend.', $needed, 'vigilante' ),
2323 $needed
2324 ) );
2325 ?>
2326 </p>
2327 </div>
2328 <?php endif; ?>
2329 </div>
2330
2331 <div class="vigilante-analyzer-toggle-row">
2332 <button type="button" class="button-link vigilante-analyzer-toggle" aria-expanded="false">
2333 <?php esc_html_e( 'Show detailed breakdown', 'vigilante' ); ?>
2334 <span class="vigilante-analyzer-toggle-chevron" aria-hidden="true"></span>
2335 </button>
2336 </div>
2337
2338 <div class="vigilante-analyzer-details" hidden>
2339 <div class="vigilante-analyzer-categories" data-role="categories">
2340 <?php foreach ( $categories_def as $slug => $meta ) :
2341 $cat = isset( $categories[ $slug ] ) ? $categories[ $slug ] : array();
2342 $earned = isset( $cat['earned'] ) ? (int) $cat['earned'] : 0;
2343 // Always use the declared meta as the source of truth for the maximum.
2344 // The cached scan may carry an old max if a check was added/removed
2345 // between releases (see 2.6.1: closed_plugins raised internal from 22 to 28
2346 // but cached scans still reported max=22 until reset).
2347 $cat_max = (int) $meta['max'];
2348 $info_only = ! empty( $meta['info_only'] ) || 0 === (int) $meta['max'];
2349 $cat_pct = $cat_max > 0 ? (int) round( ( $earned / $cat_max ) * 100 ) : 0;
2350 $checks = isset( $cat['checks'] ) ? (array) $cat['checks'] : array();
2351 $cat_counts = isset( $cat['counts'] ) && is_array( $cat['counts'] ) ? $cat['counts'] : array( 'pass' => 0, 'warn' => 0, 'fail' => 0, 'info' => 0 );
2352 $cat_quality = self::analyzer_quality_tag( $cat_pct );
2353 $info_count = isset( $cat_counts['info'] ) ? (int) $cat_counts['info'] : 0;
2354 ?>
2355 <details class="vigilante-analyzer-category<?php echo $info_only ? ' vigilante-analyzer-category--info' : ''; ?>"
2356 data-category="<?php echo esc_attr( $slug ); ?>"
2357 data-info-only="<?php echo $info_only ? '1' : '0'; ?>">
2358 <summary class="vigilante-analyzer-category-summary">
2359 <span class="vigilante-analyzer-category-chevron" aria-hidden="true"></span>
2360 <span class="vigilante-analyzer-category-label"><?php echo esc_html( $meta['label'] ); ?></span>
2361 <?php if ( $info_only ) : ?>
2362 <span class="vigilante-analyzer-category-quality vigilante-analyzer-quality-info"
2363 data-role="category-quality"
2364 title="<?php esc_attr_e( 'Informational — does not affect the security score.', 'vigilante' ); ?>">
2365 <span class="dashicons dashicons-info-outline" aria-hidden="true"></span>
2366 <?php esc_html_e( 'Informational', 'vigilante' ); ?>
2367 </span>
2368 <?php else :
2369 $passed_count = (int) ( $cat_counts['pass'] ?? 0 );
2370 $scored_total = $passed_count
2371 + (int) ( $cat_counts['warn'] ?? 0 )
2372 + (int) ( $cat_counts['fail'] ?? 0 );
2373 ?>
2374 <span class="vigilante-analyzer-category-quality vigilante-analyzer-quality-<?php echo esc_attr( $cat_quality['slug'] ); ?>"
2375 data-role="category-quality">
2376 <span data-role="category-quality-label"><?php echo esc_html( $cat_quality['label'] ); ?></span>
2377 <span class="vigilante-analyzer-category-quality-sep" aria-hidden="true">·</span>
2378 <span class="vigilante-analyzer-category-tests" data-role="category-tests"
2379 data-passed="<?php echo esc_attr( $passed_count ); ?>"
2380 data-total="<?php echo esc_attr( $scored_total ); ?>">
2381 <?php
2382 echo esc_html( sprintf(
2383 /* translators: 1: tests passed, 2: total tests in this category */
2384 __( '%1$d/%2$d tests', 'vigilante' ),
2385 $passed_count,
2386 $scored_total
2387 ) );
2388 ?>
2389 </span>
2390 </span>
2391 <?php endif; ?>
2392 <?php if ( $info_only ) : ?>
2393 <span class="vigilante-analyzer-category-states" data-role="category-states">
2394 <?php if ( $info_count > 0 ) : ?>
2395 <span class="vigilante-analyzer-category-state vigilante-analyzer-category-state--info" title="<?php esc_attr_e( 'Informational', 'vigilante' ); ?>">
2396 <span data-role="state-info"><?php echo esc_html( $info_count ); ?></span><span class="dashicons dashicons-info-outline" aria-hidden="true"></span>
2397 </span>
2398 <?php endif; ?>
2399 </span>
2400 <?php endif; ?>
2401 <?php if ( ! $info_only ) : ?>
2402 <span class="vigilante-analyzer-category-score">
2403 <span data-role="earned"><?php echo esc_html( $earned ); ?></span><span class="vigilante-analyzer-category-score-sep">/</span><?php echo esc_html( $cat_max ); ?>
2404 <span class="vigilante-analyzer-category-score-unit"><?php esc_html_e( 'pts', 'vigilante' ); ?></span>
2405 </span>
2406 <span class="vigilante-analyzer-category-bar" aria-hidden="true">
2407 <span class="vigilante-analyzer-category-bar-fill vigilante-analyzer-category-bar-fill--<?php echo esc_attr( $cat_quality['slug'] ); ?>"
2408 style="width: <?php echo esc_attr( $cat_pct ); ?>%"
2409 data-role="category-bar"></span>
2410 </span>
2411 <?php else :
2412 $info_warn = isset( $cat_counts['warn'] ) ? (int) $cat_counts['warn'] : 0;
2413 $info_fail = isset( $cat_counts['fail'] ) ? (int) $cat_counts['fail'] : 0;
2414 $info_issues = $info_warn + $info_fail;
2415 if ( $info_issues > 0 ) : ?>
2416 <span class="vigilante-analyzer-category-status vigilante-analyzer-category-status--attention" data-role="info-status">
2417 <span class="dashicons dashicons-warning" aria-hidden="true"></span>
2418 <?php
2419 echo esc_html( sprintf(
2420 /* translators: %d: number of findings */
2421 _n( '%d finding', '%d findings', $info_issues, 'vigilante' ),
2422 $info_issues
2423 ) );
2424 ?>
2425 </span>
2426 <?php else : ?>
2427 <span class="vigilante-analyzer-category-status vigilante-analyzer-category-status--clear" data-role="info-status">
2428 <span class="dashicons dashicons-yes-alt" aria-hidden="true"></span>
2429 <?php esc_html_e( 'All clear', 'vigilante' ); ?>
2430 </span>
2431 <?php endif; ?>
2432 <?php endif; ?>
2433 </summary>
2434 <ul class="vigilante-analyzer-check-list" data-role="check-list">
2435 <?php if ( empty( $checks ) ) : ?>
2436 <li class="vigilante-analyzer-check-empty">
2437 <?php esc_html_e( 'No data yet — run a scan to populate this category.', 'vigilante' ); ?>
2438 </li>
2439 <?php else : ?>
2440 <?php foreach ( $checks as $c ) : ?>
2441 <?php echo self::render_analyzer_check_row( $c ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped inside helper ?>
2442 <?php endforeach; ?>
2443 <?php endif; ?>
2444 </ul>
2445 </details>
2446 <?php endforeach; ?>
2447 </div>
2448
2449 <div class="vigilante-analyzer-weekly">
2450 <h3><?php esc_html_e( 'Automatic weekly scan', 'vigilante' ); ?></h3>
2451 <p class="description">
2452 <?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' ); ?>
2453 </p>
2454 <label class="vigilante-analyzer-toggle-option">
2455 <input type="checkbox"
2456 name="security_analyzer[weekly_scan_enabled]"
2457 value="1"
2458 <?php checked( $weekly_enabled ); ?>>
2459 <?php esc_html_e( 'Run a weekly automatic scan', 'vigilante' ); ?>
2460 </label>
2461 <label class="vigilante-analyzer-toggle-option">
2462 <input type="checkbox"
2463 name="security_analyzer[email_on_regression]"
2464 value="1"
2465 <?php checked( $email_enabled ); ?>>
2466 <?php esc_html_e( 'Email me when the score drops significantly', 'vigilante' ); ?>
2467 </label>
2468 </div>
2469 </div>
2470 </div>
2471 <?php
2472 }
2473
2474 /**
2475 * Map a 0-100 percentage to a quality tag { label, slug } aligned with the
2476 * Dashboard grade palette (a/b/c/d/e).
2477 *
2478 * @param int $pct 0..100.
2479 * @return array{label:string,slug:string}
2480 */
2481 public static function analyzer_quality_tag( $pct ) {
2482 $pct = max( 0, min( 100, (int) $pct ) );
2483 // "Excellent" is reserved for a perfect score — a single missing point drops to Good.
2484 if ( 100 === $pct ) {
2485 return array( 'label' => __( 'Excellent', 'vigilante' ), 'slug' => 'a' );
2486 }
2487 if ( $pct >= 70 ) {
2488 return array( 'label' => __( 'Good', 'vigilante' ), 'slug' => 'b' );
2489 }
2490 if ( $pct >= 50 ) {
2491 return array( 'label' => __( 'Fair', 'vigilante' ), 'slug' => 'c' );
2492 }
2493 if ( $pct >= 30 ) {
2494 return array( 'label' => __( 'Poor', 'vigilante' ), 'slug' => 'd' );
2495 }
2496 return array( 'label' => __( 'Critical', 'vigilante' ), 'slug' => 'e' );
2497 }
2498
2499 /**
2500 * Render a single analyzer check row (used both server-side and via JS template).
2501 *
2502 * @param array $check Check result array (from Vigilante_SA_Check_Result::to_array()).
2503 * @return string HTML (escaped).
2504 */
2505 private static function render_analyzer_check_row( $check ) {
2506 $id = isset( $check['id'] ) ? $check['id'] : '';
2507 $state = isset( $check['state'] ) ? $check['state'] : 'skip';
2508 $label = isset( $check['label'] ) ? $check['label'] : '';
2509 $detail = isset( $check['detail'] ) ? $check['detail'] : '';
2510 $score = isset( $check['score'] ) ? (int) $check['score'] : 0;
2511 $max = isset( $check['max'] ) ? (int) $check['max'] : 0;
2512 $fix_link = isset( $check['fix_link'] ) ? $check['fix_link'] : '';
2513
2514 $icons = array(
2515 'pass' => 'yes-alt',
2516 'warn' => 'warning',
2517 'fail' => 'dismiss',
2518 'info' => 'info',
2519 'skip' => 'minus',
2520 );
2521 $icon = isset( $icons[ $state ] ) ? $icons[ $state ] : 'minus';
2522
2523 $html = '<li class="vigilante-analyzer-check vigilante-analyzer-check--' . esc_attr( $state ) . '"';
2524 $html .= ' data-check-id="' . esc_attr( $id ) . '">';
2525 $html .= '<span class="vigilante-analyzer-check-icon dashicons dashicons-' . esc_attr( $icon ) . '" aria-hidden="true"></span>';
2526 $html .= '<div class="vigilante-analyzer-check-body">';
2527 $html .= '<div class="vigilante-analyzer-check-label">';
2528 $html .= '<span>' . esc_html( $label ) . '</span>';
2529 if ( $max > 0 && 'info' !== $state && 'skip' !== $state ) {
2530 $html .= '<span class="vigilante-analyzer-check-score">'
2531 . esc_html( $score . '/' . $max )
2532 . ' <span class="vigilante-analyzer-check-score-unit">' . esc_html__( 'pts', 'vigilante' ) . '</span>'
2533 . '</span>';
2534 }
2535 $html .= '</div>';
2536 if ( $detail ) {
2537 $html .= '<p class="vigilante-analyzer-check-detail">' . esc_html( $detail ) . '</p>';
2538 }
2539 if ( $fix_link && in_array( $state, array( 'fail', 'warn' ), true ) ) {
2540 $html .= '<a href="' . esc_url( $fix_link ) . '" class="vigilante-analyzer-fix-link">'
2541 . esc_html__( 'Go to setting', 'vigilante' )
2542 . '<span class="vigilante-analyzer-fix-arrow" aria-hidden="true">&rarr;</span></a>';
2543 } elseif ( $fix_link && 'info' === $state ) {
2544 // Info rows (e.g. DNSBL lookups) get an external "Learn more" link instead.
2545 $is_external = 0 === strpos( $fix_link, 'http' );
2546 $html .= '<a href="' . esc_url( $fix_link ) . '" class="vigilante-analyzer-fix-link"'
2547 . ( $is_external ? ' target="_blank" rel="noopener noreferrer"' : '' ) . '>'
2548 . esc_html__( 'Learn more', 'vigilante' )
2549 . '<span class="vigilante-analyzer-fix-arrow" aria-hidden="true">&rarr;</span></a>';
2550 }
2551 $html .= '</div>';
2552 $html .= '</li>';
2553 return $html;
2554 }
2555
2556 /**
2557 * Build a minimal SVG sparkline for the score history.
2558 *
2559 * @param int[] $points Score values (0..100), oldest to newest.
2560 * @return string SVG markup.
2561 */
2562 private static function sparkline_svg( $points ) {
2563 $points = array_map( 'intval', (array) $points );
2564 $count = count( $points );
2565 if ( $count < 2 ) {
2566 return '';
2567 }
2568 $width = 280;
2569 $height = 60;
2570 $padding = 4;
2571
2572 $usable_w = $width - ( $padding * 2 );
2573 $usable_h = $height - ( $padding * 2 );
2574
2575 $step = $usable_w / max( 1, $count - 1 );
2576 $max = 100; // Fixed scale — scores are 0..100.
2577
2578 $coords = array();
2579 foreach ( $points as $i => $v ) {
2580 $x = $padding + ( $i * $step );
2581 $y = $padding + ( $usable_h - ( ( $v / $max ) * $usable_h ) );
2582 $coords[] = round( $x, 2 ) . ',' . round( $y, 2 );
2583 }
2584 $path = 'M ' . implode( ' L ', $coords );
2585 $last = end( $points );
2586 $last_x = $padding + ( ( $count - 1 ) * $step );
2587 $last_y = $padding + ( $usable_h - ( ( $last / $max ) * $usable_h ) );
2588
2589 $svg = '<svg viewBox="0 0 ' . $width . ' ' . $height . '" preserveAspectRatio="none" role="img" aria-label="' . esc_attr__( 'Security Score history', 'vigilante' ) . '" focusable="false">';
2590 $svg .= '<path d="' . esc_attr( $path ) . '" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>';
2591 $svg .= '<circle cx="' . esc_attr( round( $last_x, 2 ) ) . '" cy="' . esc_attr( round( $last_y, 2 ) ) . '" r="3" fill="currentColor"/>';
2592 $svg .= '</svg>';
2593 return $svg;
2594 }
2595
2596 /**
2597 * Render dashboard tab
2598 */
2599 private function render_tab_dashboard() {
2600 $options = $this->settings->get_all_options();
2601 $module_labels = $this->settings->get_module_labels();
2602 $module_descriptions = $this->settings->get_module_descriptions();
2603 $presets = $this->settings->get_presets();
2604 $active_preset = get_option( 'vigilante_active_preset', '' );
2605
2606 // Calculate security score with more factors
2607 $security_score = $this->calculate_security_score( $options );
2608
2609 // Security Analyzer (v2.1.0) — hydrate widget with the last persisted scan, if any.
2610 if ( ! class_exists( 'Vigilante_Security_Analyzer' ) ) {
2611 require_once VIGILANTE_INCLUDES_DIR . 'class-security-analyzer.php';
2612 }
2613 $analyzer_instance = new Vigilante_Security_Analyzer( $this->settings, $this->activity_log );
2614 $analyzer_last_scan = $analyzer_instance->get_last_scan();
2615 $analyzer_history = $analyzer_instance->get_score_history();
2616 $analyzer_categories_def = Vigilante_Security_Analyzer::get_categories();
2617 $analyzer_settings = isset( $options['security_analyzer'] ) ? $options['security_analyzer'] : array();
2618 ?>
2619 <div class="vigilante-dashboard">
2620 <div class="vigilante-status-card">
2621 <h2><?php esc_html_e( 'Configuration Score', 'vigilante' ); ?></h2>
2622 <p class="vigilante-score-kind description">
2623 <?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' ); ?>
2624 </p>
2625 <div class="vigilante-security-score">
2626 <?php
2627 // Grade thresholds: A (90+), B (70-89), C (50-69), D (30-49), E (0-29)
2628 if ( $security_score >= 90 ) {
2629 $grade = 'A';
2630 } elseif ( $security_score >= 70 ) {
2631 $grade = 'B';
2632 } elseif ( $security_score >= 50 ) {
2633 $grade = 'C';
2634 } elseif ( $security_score >= 30 ) {
2635 $grade = 'D';
2636 } else {
2637 $grade = 'E';
2638 }
2639 ?>
2640 <div class="vigilante-score-circle vigilante-grade-<?php echo esc_attr( strtolower( $grade ) ); ?>">
2641 <span class="vigilante-grade"><?php echo esc_html( $grade ); ?></span>
2642 <span class="vigilante-score-text"><?php echo esc_html( $security_score ); ?>%</span>
2643 </div>
2644 <div class="vigilante-config-status">
2645 <?php if ( $active_preset && isset( $presets[ $active_preset ] ) ) : ?>
2646 <span class="vigilante-preset-badge vigilante-preset-<?php echo esc_attr( $active_preset ); ?>">
2647 <?php echo esc_html( $presets[ $active_preset ]['name'] ); ?>
2648 </span>
2649 <?php else : ?>
2650 <span class="vigilante-preset-badge vigilante-preset-custom">
2651 <?php esc_html_e( 'Custom Configuration', 'vigilante' ); ?>
2652 </span>
2653 <?php endif; ?>
2654 </div>
2655 </div>
2656
2657 <?php
2658 $recommendations = $this->get_security_recommendations( $options );
2659 if ( ! empty( $recommendations ) ) :
2660 ?>
2661 <div class="vigilante-recommendations">
2662 <h4><?php esc_html_e( 'Recommendations', 'vigilante' ); ?></h4>
2663 <ul class="vigilante-recommendations-grid">
2664 <?php foreach ( $recommendations as $rec ) : ?>
2665 <li>
2666 <span class="dashicons dashicons-<?php echo esc_attr( $rec['icon'] ); ?> vigilante-priority-<?php echo esc_attr( $rec['priority'] ); ?>"></span>
2667 <?php echo esc_html( $rec['message'] ); ?>
2668 <?php if ( ! empty( $rec['tab'] ) ) : ?>
2669 <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>
2670 <?php endif; ?>
2671 </li>
2672 <?php endforeach; ?>
2673 </ul>
2674 </div>
2675 <?php endif; ?>
2676 </div>
2677
2678 <?php $this->render_analyzer_widget( $analyzer_last_scan, $analyzer_history, $analyzer_categories_def, $analyzer_settings ); ?>
2679
2680 <div class="vigilante-modules-grid">
2681 <h2 id="vigilante-section-dashboard-modules"><?php esc_html_e( 'Security Modules', 'vigilante' ); ?></h2>
2682 <p class="description"><?php esc_html_e( 'Enable or disable security modules. Each module controls a tab with detailed settings.', 'vigilante' ); ?></p>
2683 <div class="vigilante-modules-list">
2684 <?php foreach ( $options['modules'] as $module => $enabled ) :
2685 $label = isset( $module_labels[ $module ] ) ? $module_labels[ $module ] : ucwords( str_replace( '_', ' ', $module ) );
2686 $description = isset( $module_descriptions[ $module ] ) ? $module_descriptions[ $module ] : '';
2687 ?>
2688 <div class="vigilante-module-item <?php echo $enabled ? 'enabled' : 'disabled'; ?>">
2689 <div class="vigilante-module-header">
2690 <span class="vigilante-module-status"></span>
2691 <span class="vigilante-module-name"><?php echo esc_html( $label ); ?></span>
2692 <label class="vigilante-toggle">
2693 <?php
2694 /* translators: %s: Security module name, for example Firewall. */
2695 $toggle_label = sprintf( __( 'Enable %s', 'vigilante' ), $label );
2696 ?>
2697 <input type="checkbox"
2698 name="modules[<?php echo esc_attr( $module ); ?>]"
2699 value="1"
2700 <?php checked( $enabled ); ?>
2701 aria-label="<?php echo esc_attr( $toggle_label ); ?>"
2702 data-module="<?php echo esc_attr( $module ); ?>">
2703 <span class="vigilante-toggle-slider"></span>
2704 </label>
2705 </div>
2706 <?php if ( $description ) : ?>
2707 <p class="vigilante-module-desc"><?php echo esc_html( $description ); ?></p>
2708 <?php endif; ?>
2709 </div>
2710 <?php endforeach; ?>
2711 </div>
2712 </div>
2713
2714 <div class="vigilante-presets-card">
2715 <h2><?php esc_html_e( 'Quick Configuration Presets', 'vigilante' ); ?></h2>
2716 <p><?php esc_html_e( 'Apply a preset to quickly set up recommended settings for standard or maximum security level.', 'vigilante' ); ?></p>
2717 <div class="vigilante-presets-grid">
2718 <?php foreach ( $presets as $preset_id => $preset ) :
2719 $is_active = ( $active_preset === $preset_id );
2720 ?>
2721 <div class="vigilante-preset-card <?php echo $is_active ? 'vigilante-preset-active' : ''; ?>">
2722 <?php if ( $is_active ) : ?>
2723 <span class="vigilante-active-indicator"><?php esc_html_e( 'Active', 'vigilante' ); ?></span>
2724 <?php endif; ?>
2725 <h3><?php echo esc_html( $preset['name'] ); ?></h3>
2726 <p><?php echo esc_html( $preset['description'] ); ?></p>
2727 <button type="button" class="button vigilante-preset-btn <?php echo $is_active ? 'button-primary' : ''; ?>" data-preset="<?php echo esc_attr( $preset_id ); ?>">
2728 <?php esc_html_e( 'Apply Preset', 'vigilante' ); ?>
2729 </button>
2730 </div>
2731 <?php endforeach; ?>
2732
2733 <?php
2734 // Under Attack mode card
2735 $under_attack = new Vigilante_Under_Attack( $this->settings, $this->activity_log );
2736 $ua_active = $under_attack->is_active();
2737 $ua_remaining = $under_attack->get_remaining_time();
2738 $ua_remaining_hours = floor( $ua_remaining / 3600 );
2739 $ua_remaining_mins = floor( ( $ua_remaining % 3600 ) / 60 );
2740 ?>
2741 <div class="vigilante-preset-card vigilante-under-attack-card <?php echo $ua_active ? 'vigilante-under-attack-active' : ''; ?>">
2742 <h3 id="vigilante-section-dashboard-under-attack">
2743 <span class="dashicons dashicons-shield"></span>
2744 <?php esc_html_e( 'Under Attack', 'vigilante' ); ?>
2745 </h3>
2746 <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>
2747 <?php if ( $ua_active ) : ?>
2748 <div class="vigilante-ua-countdown" data-expires="<?php echo esc_attr( $under_attack->get_status()['activated_at'] + $under_attack->get_status()['duration'] ); ?>">
2749 <span class="dashicons dashicons-clock"></span>
2750 <span class="vigilante-ua-time">
2751 <?php
2752 printf(
2753 /* translators: 1: Hours, 2: Minutes */
2754 esc_html__( '%1$dh %2$dm remaining', 'vigilante' ),
2755 absint( $ua_remaining_hours ),
2756 absint( $ua_remaining_mins )
2757 );
2758 ?>
2759 </span>
2760 </div>
2761 <button type="button" class="button vigilante-ua-btn vigilante-ua-deactivate">
2762 <?php esc_html_e( 'Deactivate', 'vigilante' ); ?>
2763 </button>
2764 <?php else : ?>
2765 <button type="button" class="button vigilante-ua-btn vigilante-ua-activate">
2766 <?php esc_html_e( 'Activate for 4 hours', 'vigilante' ); ?>
2767 </button>
2768 <?php endif; ?>
2769 </div>
2770 </div>
2771 </div>
2772 </div>
2773 <?php
2774 }
2775
2776 /**
2777 * Render tools tab
2778 */
2779 private function render_tab_tools() {
2780 // Get current settings for notification summary
2781 $email_options = $this->settings->get_section( 'email' );
2782 $login_options = $this->settings->get_section( 'login_security' );
2783 $user_options = $this->settings->get_section( 'user_security' );
2784 $fi_options = $this->settings->get_section( 'file_integrity' );
2785 $alerts_options = $this->settings->get_section( 'audit_alerts' );
2786 $monitoring = $user_options['admin_monitoring'] ?? array();
2787 $registration = $user_options['registration_approval'] ?? array();
2788 $current_admin = get_option( 'admin_email' );
2789 $send_to_admin = ! isset( $email_options['send_to_admin_email'] ) || ! empty( $email_options['send_to_admin_email'] );
2790 $additional_raw = $email_options['additional_recipients'] ?? array();
2791 $additional = is_array( $additional_raw ) ? implode( "\n", $additional_raw ) : trim( $additional_raw );
2792 ?>
2793
2794 <!-- Notification Settings -->
2795 <div id="vigilante-section-tools-notifications" class="vigilante-settings-section vigilante-notification-section">
2796 <h2><?php esc_html_e( 'Notification settings', 'vigilante' ); ?></h2>
2797 <p><?php esc_html_e( 'Configure who receives all administrative email notifications from Vigilant. Individual notifications are enabled in their respective tabs.', 'vigilante' ); ?></p>
2798
2799 <div class="vigilante-notification-layout">
2800
2801 <!-- Left column: Recipients settings -->
2802 <div class="vigilante-notification-settings">
2803 <form class="vigilante-settings-form" data-section="email">
2804
2805 <table class="form-table vigilante-compact-form">
2806 <tr>
2807 <th scope="row"><?php esc_html_e( 'WordPress Admin Email', 'vigilante' ); ?></th>
2808 <td>
2809 <label>
2810 <input type="checkbox" name="email[send_to_admin_email]" value="1" <?php checked( $send_to_admin ); ?>>
2811 <?php
2812 printf(
2813 /* translators: %s: Admin email address */
2814 esc_html__( 'Send to admin email (%s)', 'vigilante' ),
2815 '<code>' . esc_html( $current_admin ) . '</code>'
2816 );
2817 ?>
2818 </label>
2819 </td>
2820 </tr>
2821 <tr>
2822 <th scope="row"><label for="vigilante-f-email-additional-recipients"><?php esc_html_e( 'Additional Recipients', 'vigilante' ); ?></label></th>
2823 <td>
2824 <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>
2825 <p class="description"><?php esc_html_e( 'One email per line.', 'vigilante' ); ?></p>
2826 </td>
2827 </tr>
2828 <tr>
2829 <th scope="row"><?php esc_html_e( 'Plugin Deactivation', 'vigilante' ); ?></th>
2830 <td>
2831 <label>
2832 <input type="checkbox" name="email[send_deactivation_email]" value="1" <?php checked( ! empty( $email_options['send_deactivation_email'] ) ); ?>>
2833 <?php esc_html_e( 'Send email when Vigilant is deactivated', 'vigilante' ); ?>
2834 </label>
2835 </td>
2836 </tr>
2837 </table>
2838
2839 <p class="submit vigilante-notification-submit">
2840 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
2841 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
2842 </button>
2843 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
2844 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
2845 </button>
2846 <span class="vigilante-test-email-result" style="margin-left:8px;vertical-align:middle;"></span>
2847 </p>
2848 <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>
2849
2850 </form>
2851 </div>
2852
2853 <!-- Right column: Active notifications summary -->
2854 <div class="vigilante-notification-summary">
2855 <h4><?php esc_html_e( 'Active notifications', 'vigilante' ); ?></h4>
2856
2857 <table class="widefat striped">
2858 <thead>
2859 <tr>
2860 <th><?php esc_html_e( 'Notification', 'vigilante' ); ?></th>
2861 <th style="width: 1%; white-space: nowrap; text-align: center;"><?php esc_html_e( 'Status', 'vigilante' ); ?></th>
2862 <th style="width: 50px; text-align: center;"></th>
2863 </tr>
2864 </thead>
2865 <tbody>
2866 <?php
2867 $notifications = array(
2868 array(
2869 'label' => __( 'Login lockout', 'vigilante' ),
2870 'active' => ! empty( $login_options['notify_on_lockout'] ),
2871 'tab' => 'login',
2872 ),
2873 array(
2874 'label' => __( 'Administrator login', 'vigilante' ),
2875 'active' => ! empty( $login_options['notify_on_admin_login'] ),
2876 'tab' => 'login',
2877 ),
2878 array(
2879 'label' => __( 'New administrator created', 'vigilante' ),
2880 'active' => ! empty( $monitoring['alert_new_admin'] ),
2881 'tab' => 'users',
2882 ),
2883 array(
2884 'label' => __( 'Administrator email changed', 'vigilante' ),
2885 'active' => ! empty( $monitoring['alert_admin_email_change'] ),
2886 'tab' => 'users',
2887 ),
2888 array(
2889 'label' => __( 'Permission elevation', 'vigilante' ),
2890 'active' => ! empty( $monitoring['alert_permission_elevation'] ),
2891 'tab' => 'users',
2892 ),
2893 array(
2894 'label' => __( 'Admin password changed', 'vigilante' ),
2895 'active' => ! empty( $monitoring['alert_admin_password_change'] ),
2896 'tab' => 'users',
2897 ),
2898 array(
2899 'label' => __( 'Registration pending approval', 'vigilante' ),
2900 'active' => ! empty( $registration['enabled'] ) && ! empty( $registration['notify_admin'] ),
2901 'tab' => 'users',
2902 ),
2903 array(
2904 'label' => __( 'File integrity scan report', 'vigilante' ),
2905 'active' => ( $fi_options['notify_level'] ?? 'disabled' ) !== 'disabled',
2906 'tab' => 'file-integrity',
2907 ),
2908 array(
2909 'label' => __( 'File integrity instant alert', 'vigilante' ),
2910 'active' => ! empty( $fi_options['instant_alert'] ),
2911 'tab' => 'file-integrity',
2912 ),
2913 array(
2914 'label' => __( 'Audit alert: immediate', 'vigilante' ),
2915 'active' => Vigilante_Audit_Alerts::immediate_is_active( $alerts_options ),
2916 'tab' => 'activity-log',
2917 'anchor' => 'vigilante-section-audit-alerts',
2918 ),
2919 array(
2920 'label' => __( 'Audit alert: threshold', 'vigilante' ),
2921 'active' => Vigilante_Audit_Alerts::threshold_is_active( $alerts_options ),
2922 'tab' => 'activity-log',
2923 'anchor' => 'vigilante-section-audit-alerts',
2924 ),
2925 array(
2926 'label' => __( 'Under Attack mode', 'vigilante' ),
2927 'active' => true,
2928 'tab' => '',
2929 'note' => __( 'Always active', 'vigilante' ),
2930 ),
2931 array(
2932 'label' => __( 'Plugin deactivation', 'vigilante' ),
2933 'active' => ! empty( $email_options['send_deactivation_email'] ),
2934 'tab' => 'tools',
2935 ),
2936 );
2937
2938 foreach ( $notifications as $notif ) :
2939 $status_class = $notif['active'] ? 'vigilante-status-active' : 'vigilante-status-inactive';
2940 $status_label = $notif['active'] ? __( 'Active', 'vigilante' ) : __( 'Inactive', 'vigilante' );
2941 if ( ! empty( $notif['note'] ) ) {
2942 $status_label = $notif['note'];
2943 }
2944 ?>
2945 <tr>
2946 <td><?php echo esc_html( $notif['label'] ); ?></td>
2947 <td style="text-align: center; white-space: nowrap;">
2948 <span class="<?php echo esc_attr( $status_class ); ?>"><?php echo esc_html( $status_label ); ?></span>
2949 </td>
2950 <td style="text-align: center;">
2951 <?php if ( ! empty( $notif['tab'] ) ) : ?>
2952 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=' . $notif['tab'] ) . ( ! empty( $notif['anchor'] ) ? '#' . $notif['anchor'] : '' ) ); ?>" class="button button-small">
2953 <span class="dashicons dashicons-admin-generic" style="font-size: 14px; line-height: 1.8;"></span>
2954 </a>
2955 <?php else : ?>
2956 &mdash;
2957 <?php endif; ?>
2958 </td>
2959 </tr>
2960 <?php endforeach; ?>
2961 </tbody>
2962 </table>
2963 </div>
2964
2965 </div>
2966 </div>
2967
2968 <h2 id="vigilante-section-tools-main" class="vigilante-tools-heading"><?php esc_html_e( 'Tools', 'vigilante' ); ?></h2>
2969
2970 <?php
2971 // Warn that during Under Attack mode the export/import operate against
2972 // the temporary hardened config and any imported changes will be
2973 // reverted when the mode ends.
2974 $ua_status = get_option( Vigilante_Under_Attack::OPTION_NAME, array() );
2975 if ( ! empty( $ua_status['active'] ) ) :
2976 ?>
2977 <div class="vigilante-ua-tools-notice-wrap">
2978 <div class="notice notice-warning inline vigilante-ua-tools-notice">
2979 <p>
2980 <strong><?php esc_html_e( 'Under Attack mode is active.', 'vigilante' ); ?></strong>
2981 <?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' ); ?>
2982 </p>
2983 </div>
2984 </div>
2985 <?php
2986 endif;
2987 ?>
2988
2989 <div class="vigilante-tools-grid">
2990 <div class="vigilante-tool-card">
2991 <h3><?php esc_html_e( 'Export Settings', 'vigilante' ); ?></h3>
2992 <p><?php esc_html_e( 'Download your current security settings as a JSON file.', 'vigilante' ); ?></p>
2993 <button type="button" class="button vigilante-export-settings">
2994 <?php esc_html_e( 'Export Settings', 'vigilante' ); ?>
2995 </button>
2996 </div>
2997
2998 <div class="vigilante-tool-card">
2999 <h3><?php esc_html_e( 'Import Settings', 'vigilante' ); ?></h3>
3000 <p><?php esc_html_e( 'Import settings from a previously exported JSON file.', 'vigilante' ); ?></p>
3001 <input type="file" id="vigilante-import-file" aria-label="<?php esc_attr_e( 'Configuration file to import', 'vigilante' ); ?>" accept=".json" style="display: none;">
3002 <button type="button" class="button vigilante-import-settings">
3003 <?php esc_html_e( 'Import Settings', 'vigilante' ); ?>
3004 </button>
3005 </div>
3006
3007 <div class="vigilante-tool-card">
3008 <h3><?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?></h3>
3009 <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>
3010 <button type="button" class="button vigilante-reset-settings" style="color: #a00;">
3011 <?php esc_html_e( 'Reset All Settings', 'vigilante' ); ?>
3012 </button>
3013 </div>
3014
3015 <div class="vigilante-tool-card">
3016 <h3><?php esc_html_e( 'Download Config Backup', 'vigilante' ); ?></h3>
3017 <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>
3018 <?php if ( $this->shared_files_locked() ) : ?>
3019 <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>
3020 <?php else : ?>
3021 <button type="button" class="button vigilante-create-backup">
3022 <?php esc_html_e( 'Download Backup', 'vigilante' ); ?>
3023 </button>
3024 <?php endif; ?>
3025 </div>
3026
3027 <?php if ( ! $this->shared_files_locked() ) : ?>
3028
3029 <div class="vigilante-tool-card vigilante-tool-card-wide">
3030 <h3><?php esc_html_e( 'Database Backup', 'vigilante' ); ?></h3>
3031 <p><?php esc_html_e( 'Download a backup of your database as a ZIP file. Select which tables to include.', 'vigilante' ); ?></p>
3032 <button type="button" class="button vigilante-db-backup-toggle">
3033 <?php esc_html_e( 'Download Database Backup', 'vigilante' ); ?>
3034 </button>
3035
3036 <div class="vigilante-db-backup-panel" style="display: none;">
3037 <div class="vigilante-db-tables-loading">
3038 <span class="spinner is-active"></span>
3039 <?php esc_html_e( 'Loading tables...', 'vigilante' ); ?>
3040 </div>
3041
3042 <div class="vigilante-db-tables-content" style="display: none;">
3043 <div class="vigilante-db-tables-controls">
3044 <label>
3045 <input type="checkbox" id="vigilante-db-select-all" checked>
3046 <strong><?php esc_html_e( 'Select / deselect all', 'vigilante' ); ?></strong>
3047 </label>
3048 <span class="vigilante-db-tables-info"></span>
3049 </div>
3050
3051 <div class="vigilante-db-tables-group">
3052 <h4><?php esc_html_e( 'WordPress core tables', 'vigilante' ); ?></h4>
3053 <div class="vigilante-db-tables-list" id="vigilante-db-core-tables"></div>
3054 </div>
3055
3056 <div class="vigilante-db-tables-group" id="vigilante-db-other-group" style="display: none;">
3057 <h4><?php esc_html_e( 'Plugin and custom tables', 'vigilante' ); ?></h4>
3058 <div class="vigilante-db-tables-list" id="vigilante-db-other-tables"></div>
3059 </div>
3060
3061 <div class="vigilante-db-backup-actions">
3062 <button type="button" class="button button-primary vigilante-db-backup-download">
3063 <?php esc_html_e( 'Download Backup (.zip)', 'vigilante' ); ?>
3064 </button>
3065 </div>
3066 </div>
3067 </div>
3068 </div>
3069 <?php else : ?>
3070 <div class="vigilante-tool-card vigilante-tool-card-wide">
3071 <h3><?php esc_html_e( 'Database Backup', 'vigilante' ); ?></h3>
3072 <p><?php esc_html_e( 'Download a backup of your database as a ZIP file. Select which tables to include.', 'vigilante' ); ?></p>
3073 <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>
3074 </div>
3075 <?php endif; ?>
3076 </div>
3077 <?php
3078 }
3079
3080 /**
3081 * Render firewall tab
3082 */
3083 private function render_tab_firewall() {
3084 $is_disabled = $this->render_module_disabled_notice( 'firewall' );
3085 $options = $this->settings->get_section( 'firewall' );
3086 ?>
3087 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="firewall" <?php echo $is_disabled ? 'inert' : ''; ?>>
3088 <div id="vigilante-section-firewall-main" class="vigilante-settings-section">
3089 <h2>
3090 <?php esc_html_e( 'Firewall Protection', 'vigilante' ); ?>
3091 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
3092 </h2>
3093 <p><?php esc_html_e( 'PHP-based request filtering. Analyzes each request before WordPress loads.', 'vigilante' ); ?></p>
3094 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
3095 <p style="margin:0;">
3096 <?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' ); ?>
3097 </p>
3098 </div>
3099
3100 <table class="form-table">
3101 <tr>
3102 <th scope="row"><?php esc_html_e( 'Block Bad Query Strings', 'vigilante' ); ?></th>
3103 <td>
3104 <label>
3105 <input type="checkbox" name="firewall[block_bad_query_strings]" value="1" <?php checked( ! empty( $options['block_bad_query_strings'] ) ); ?>>
3106 <?php esc_html_e( 'Block malicious query string patterns', 'vigilante' ); ?>
3107 </label>
3108 </td>
3109 </tr>
3110 <tr>
3111 <th scope="row"><?php esc_html_e( 'SQL Injection Protection', 'vigilante' ); ?></th>
3112 <td>
3113 <label>
3114 <input type="checkbox" name="firewall[block_sql_injection]" value="1" <?php checked( ! empty( $options['block_sql_injection'] ) ); ?>>
3115 <?php esc_html_e( 'Block SQL injection attempts', 'vigilante' ); ?>
3116 </label>
3117 </td>
3118 </tr>
3119 <tr>
3120 <th scope="row"><?php esc_html_e( 'XSS Protection', 'vigilante' ); ?></th>
3121 <td>
3122 <label>
3123 <input type="checkbox" name="firewall[block_xss_attacks]" value="1" <?php checked( ! empty( $options['block_xss_attacks'] ) ); ?>>
3124 <?php esc_html_e( 'Block cross-site scripting attacks', 'vigilante' ); ?>
3125 </label>
3126 </td>
3127 </tr>
3128 <tr>
3129 <th scope="row"><?php esc_html_e( 'File Inclusion Protection', 'vigilante' ); ?></th>
3130 <td>
3131 <label>
3132 <input type="checkbox" name="firewall[block_file_inclusion]" value="1" <?php checked( ! empty( $options['block_file_inclusion'] ) ); ?>>
3133 <?php esc_html_e( 'Block local/remote file inclusion attempts', 'vigilante' ); ?>
3134 </label>
3135 </td>
3136 </tr>
3137 <tr>
3138 <th scope="row"><?php esc_html_e( 'Directory Traversal Protection', 'vigilante' ); ?></th>
3139 <td>
3140 <label>
3141 <input type="checkbox" name="firewall[block_directory_traversal]" value="1" <?php checked( ! empty( $options['block_directory_traversal'] ) ); ?>>
3142 <?php esc_html_e( 'Block path traversal attempts', 'vigilante' ); ?>
3143 </label>
3144 </td>
3145 </tr>
3146 <tr>
3147 <th scope="row"><?php esc_html_e( 'Block Bad Bots', 'vigilante' ); ?></th>
3148 <td>
3149 <label>
3150 <input type="checkbox" name="firewall[block_bad_bots]" value="1" <?php checked( ! empty( $options['block_bad_bots'] ) ); ?>>
3151 <?php esc_html_e( 'Block known malicious bots and scanners', 'vigilante' ); ?>
3152 </label>
3153 </td>
3154 </tr>
3155 </table>
3156
3157 <h3><?php esc_html_e( 'Rate Limiting', 'vigilante' ); ?></h3>
3158 <table class="form-table">
3159 <tr>
3160 <th scope="row"><?php esc_html_e( 'Enable Rate Limiting', 'vigilante' ); ?></th>
3161 <td>
3162 <label>
3163 <input type="checkbox" name="firewall[rate_limiting][enabled]" value="1" <?php checked( ! empty( $options['rate_limiting']['enabled'] ) ); ?>>
3164 <?php esc_html_e( 'Limit requests per IP address', 'vigilante' ); ?>
3165 </label>
3166 </td>
3167 </tr>
3168 <tr>
3169 <th scope="row"><label for="vigilante-f-firewall-rate-limiting-requests-per-minute"><?php esc_html_e( 'Requests per Minute', 'vigilante' ); ?></label></th>
3170 <td>
3171 <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">
3172 <p class="description">
3173 <?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' ); ?>
3174 </p>
3175 </td>
3176 </tr>
3177 <tr>
3178 <th scope="row"><label for="vigilante-f-firewall-rate-limiting-block-duration"><?php esc_html_e( 'Block Duration (seconds)', 'vigilante' ); ?></label></th>
3179 <td>
3180 <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">
3181 </td>
3182 </tr>
3183 <tr>
3184 <th scope="row"><?php esc_html_e( 'Progressive Blocking', 'vigilante' ); ?></th>
3185 <td>
3186 <label>
3187 <input type="checkbox" name="firewall[rate_limiting][progressive]" value="1" <?php checked( ! empty( $options['rate_limiting']['progressive'] ) ); ?>>
3188 <?php esc_html_e( 'Double block duration on each repeat offense', 'vigilante' ); ?>
3189 </label>
3190 <p class="description">
3191 <?php
3192 $base = absint( $options['rate_limiting']['block_duration'] ?? 300 );
3193 printf(
3194 /* translators: 1: First block duration, 2: Second, 3: Third */
3195 esc_html__( 'Example: %1$s → %2$s → %3$s and so on, up to the maximum.', 'vigilante' ),
3196 esc_html( human_time_diff( 0, $base ) ),
3197 esc_html( human_time_diff( 0, $base * 2 ) ),
3198 esc_html( human_time_diff( 0, $base * 4 ) )
3199 );
3200 ?>
3201 </p>
3202 </td>
3203 </tr>
3204 <tr>
3205 <th scope="row"><label for="vigilante-f-firewall-rate-limiting-max-block-duration"><?php esc_html_e( 'Maximum Block Duration', 'vigilante' ); ?></label></th>
3206 <td>
3207 <select id="vigilante-f-firewall-rate-limiting-max-block-duration" name="firewall[rate_limiting][max_block_duration]">
3208 <?php
3209 $max_options = array(
3210 3600 => __( '1 hour', 'vigilante' ),
3211 21600 => __( '6 hours', 'vigilante' ),
3212 43200 => __( '12 hours', 'vigilante' ),
3213 86400 => __( '24 hours', 'vigilante' ),
3214 604800 => __( '7 days', 'vigilante' ),
3215 );
3216 $current_max = absint( $options['rate_limiting']['max_block_duration'] ?? 86400 );
3217 foreach ( $max_options as $val => $label ) :
3218 ?>
3219 <option value="<?php echo esc_attr( $val ); ?>" <?php selected( $current_max, $val ); ?>>
3220 <?php echo esc_html( $label ); ?>
3221 </option>
3222 <?php endforeach; ?>
3223 </select>
3224 <p class="description"><?php esc_html_e( 'Upper limit for progressive blocking.', 'vigilante' ); ?></p>
3225 </td>
3226 </tr>
3227 </table>
3228
3229 <?php
3230 // Currently blocked IPs from rate limiting
3231 $active_blocks = Vigilante_Firewall::get_active_blocks();
3232 if ( ! empty( $active_blocks ) ) :
3233 ?>
3234 <div class="vigilante-settings-section vigilante-lockout-section" style="margin-top:20px;">
3235 <h3><?php esc_html_e( 'Currently Blocked IPs', 'vigilante' ); ?></h3>
3236 <table class="wp-list-table widefat fixed striped" style="max-width:800px;">
3237 <thead>
3238 <tr>
3239 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
3240 <th><?php esc_html_e( 'Blocked', 'vigilante' ); ?></th>
3241 <th><?php esc_html_e( 'Expires in', 'vigilante' ); ?></th>
3242 <th><?php esc_html_e( 'Strikes', 'vigilante' ); ?></th>
3243 <th><?php esc_html_e( 'Action', 'vigilante' ); ?></th>
3244 </tr>
3245 </thead>
3246 <tbody>
3247 <?php foreach ( $active_blocks as $blocked_ip => $block_data ) : ?>
3248 <tr>
3249 <td><code><?php echo esc_html( $blocked_ip ); ?></code></td>
3250 <td><?php echo esc_html( human_time_diff( $block_data['blocked_at'] ) . ' ' . __( 'ago', 'vigilante' ) ); ?></td>
3251 <td><?php echo esc_html( human_time_diff( time(), $block_data['expires'] ) ); ?></td>
3252 <td><?php echo esc_html( $block_data['strikes'] ?? 1 ); ?></td>
3253 <td>
3254 <button type="button" class="button button-small vigilante-unblock-firewall-ip"
3255 data-ip="<?php echo esc_attr( $blocked_ip ); ?>">
3256 <?php esc_html_e( 'Unblock', 'vigilante' ); ?>
3257 </button>
3258 </td>
3259 </tr>
3260 <?php endforeach; ?>
3261 </tbody>
3262 </table>
3263 </div>
3264 <?php endif; ?>
3265
3266 <h3><?php esc_html_e( 'IP Lists', 'vigilante' ); ?></h3>
3267 <p class="description">
3268 <?php
3269 printf(
3270 /* translators: %s: Current visitor IP address */
3271 esc_html__( 'Your current IP address: %s', 'vigilante' ),
3272 '<code>' . esc_html( $this->database->get_client_ip() ) . '</code>'
3273 );
3274 ?>
3275 </p>
3276 <table class="form-table">
3277 <tr>
3278 <th scope="row"><label for="vigilante-f-firewall-trusted-proxy-header"><?php esc_html_e( 'Visitor IP detection', 'vigilante' ); ?></label></th>
3279 <td>
3280 <?php $proxy_header = $options['trusted_proxy_header'] ?? ''; ?>
3281 <select id="vigilante-f-firewall-trusted-proxy-header" name="firewall[trusted_proxy_header]">
3282 <option value="" <?php selected( $proxy_header, '' ); ?>><?php esc_html_e( 'Direct connection, only REMOTE_ADDR (recommended)', 'vigilante' ); ?></option>
3283 <option value="cf-connecting-ip" <?php selected( $proxy_header, 'cf-connecting-ip' ); ?>><?php esc_html_e( 'Behind Cloudflare (CF-Connecting-IP)', 'vigilante' ); ?></option>
3284 <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>
3285 <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>
3286 </select>
3287 <p class="description">
3288 <?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' ); ?>
3289 </p>
3290 </td>
3291 </tr>
3292 <tr>
3293 <th scope="row"><label for="vigilante-f-firewall-ip-whitelist"><?php esc_html_e( 'IP Whitelist', 'vigilante' ); ?></label></th>
3294 <td>
3295 <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>
3296 <p class="description">
3297 <?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' ); ?>
3298 <br>
3299 <?php
3300 printf(
3301 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the IP, CIDR and wildcard examples. */
3302 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' ),
3303 '<code>',
3304 '</code>'
3305 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
3306 ?>
3307 </p>
3308 </td>
3309 </tr>
3310 <tr>
3311 <th scope="row"><label for="vigilante-f-firewall-ip-blacklist"><?php esc_html_e( 'IP Blacklist', 'vigilante' ); ?></label></th>
3312 <td>
3313 <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>
3314 <p class="description">
3315 <?php esc_html_e( 'One IP per line. These IPs will be blocked immediately.', 'vigilante' ); ?>
3316 <br>
3317 <?php
3318 printf(
3319 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the IP, CIDR and wildcard examples. */
3320 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' ),
3321 '<code>',
3322 '</code>'
3323 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
3324 ?>
3325 </p>
3326 </td>
3327 </tr>
3328 </table>
3329
3330 <h3><?php esc_html_e( 'User-Agent Lists', 'vigilante' ); ?></h3>
3331 <p><?php esc_html_e( 'Partial matching: enter a keyword and any User-Agent containing it will be matched.', 'vigilante' ); ?></p>
3332 <table class="form-table">
3333 <tr>
3334 <th scope="row"><label for="vigilante-f-firewall-ua-whitelist"><?php esc_html_e( 'User-Agent Whitelist', 'vigilante' ); ?></label></th>
3335 <td>
3336 <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>
3337 <p class="description"><?php esc_html_e( 'One User-Agent per line. These will bypass all firewall checks. Example: ManageWP, MainWP, UptimeRobot.', 'vigilante' ); ?></p>
3338 </td>
3339 </tr>
3340 <tr>
3341 <th scope="row"><label for="vigilante-f-firewall-ua-blacklist"><?php esc_html_e( 'User-Agent Blacklist', 'vigilante' ); ?></label></th>
3342 <td>
3343 <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>
3344 <p class="description"><?php esc_html_e( 'One User-Agent per line. These will be blocked immediately.', 'vigilante' ); ?></p>
3345 </td>
3346 </tr>
3347 </table>
3348 </div>
3349
3350 <?php
3351 $vg_shared_locked = $this->shared_files_locked();
3352 // Paint what is actually in force, not this site's unused copy.
3353 $vg_local_options = $options;
3354 $options = $this->get_section_for_display( 'firewall' );
3355 ?>
3356 <?php $this->render_shared_files_notice(); ?>
3357 <div id="vigilante-section-firewall-server" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
3358 <h2>
3359 <?php esc_html_e( 'Server Protection', 'vigilante' ); ?>
3360 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
3361 </h2>
3362 <p><?php esc_html_e( 'Server-level rules for Apache/LiteSpeed. These rules are processed before PHP.', 'vigilante' ); ?></p>
3363
3364 <table class="form-table">
3365 <tr id="field-disable-directory-browsing">
3366 <th scope="row"><?php esc_html_e( 'Directory Browsing', 'vigilante' ); ?></th>
3367 <td>
3368 <label>
3369 <input type="checkbox" name="firewall[disable_directory_browsing]" value="1" <?php checked( ! empty( $options['disable_directory_browsing'] ) ); ?>>
3370 <?php esc_html_e( 'Disable directory listing (Options -Indexes)', 'vigilante' ); ?>
3371 </label>
3372 </td>
3373 </tr>
3374 <tr>
3375 <th scope="row"><?php esc_html_e( 'Protect wp-config.php', 'vigilante' ); ?></th>
3376 <td>
3377 <label>
3378 <input type="checkbox" name="firewall[protect_wp_config]" value="1" <?php checked( ! empty( $options['protect_wp_config'] ) ); ?>>
3379 <?php esc_html_e( 'Block direct HTTP access to wp-config.php', 'vigilante' ); ?>
3380 </label>
3381 </td>
3382 </tr>
3383 <tr id="field-protect-wp-cron">
3384 <th scope="row"><?php esc_html_e( 'Protect wp-cron.php', 'vigilante' ); ?></th>
3385 <td>
3386 <label>
3387 <input type="checkbox" name="firewall[protect_wp_cron]" value="1" <?php checked( ! empty( $options['protect_wp_cron'] ) ); ?>>
3388 <?php esc_html_e( 'Block direct HTTP access to wp-cron.php (prevents cron-spam DoS abuse)', 'vigilante' ); ?>
3389 </label>
3390 <p class="description"><?php
3391 printf(
3392 /* translators: 1: opening <strong>, 2: closing </strong> */
3393 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' ),
3394 '<strong>',
3395 '</strong>',
3396 '<code>',
3397 '</code>'
3398 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
3399 ?></p>
3400 </td>
3401 </tr>
3402 <tr>
3403 <th scope="row"><?php esc_html_e( 'Protect wp-includes', 'vigilante' ); ?></th>
3404 <td>
3405 <label>
3406 <input type="checkbox" name="firewall[protect_wp_includes]" value="1" <?php checked( ! empty( $options['protect_wp_includes'] ) ); ?>>
3407 <?php esc_html_e( 'Block direct access to PHP files in wp-includes', 'vigilante' ); ?>
3408 </label>
3409 </td>
3410 </tr>
3411 <tr>
3412 <th scope="row"><?php esc_html_e( 'PHP in Uploads', 'vigilante' ); ?></th>
3413 <td>
3414 <label>
3415 <input type="checkbox" name="firewall[protect_uploads_php]" value="1" <?php checked( ! empty( $options['protect_uploads_php'] ) ); ?>>
3416 <?php esc_html_e( 'Block PHP execution in wp-content/uploads', 'vigilante' ); ?>
3417 </label>
3418 </td>
3419 </tr>
3420 <tr>
3421 <th scope="row"><?php esc_html_e( 'Sensitive Files', 'vigilante' ); ?></th>
3422 <td>
3423 <label>
3424 <input type="checkbox" name="firewall[protect_sensitive_files]" value="1" <?php checked( ! empty( $options['protect_sensitive_files'] ) ); ?>>
3425 <?php esc_html_e( 'Block access to .sql, .bak, .log, .ini, readme.html, license.txt, licencia.txt', 'vigilante' ); ?>
3426 </label>
3427 </td>
3428 </tr>
3429 <tr>
3430 <th scope="row"><?php esc_html_e( 'Limit HTTP Methods', 'vigilante' ); ?></th>
3431 <td>
3432 <label>
3433 <input type="checkbox" name="firewall[limit_http_methods]" value="1" <?php checked( ! empty( $options['limit_http_methods'] ) ); ?>>
3434 <?php esc_html_e( 'Allow only GET, POST, HEAD (blocks PUT, DELETE, TRACE, etc.)', 'vigilante' ); ?>
3435 </label>
3436 </td>
3437 </tr>
3438 </table>
3439 </div>
3440 <?php $options = $vg_local_options; ?>
3441
3442 <p class="submit vigilante-submit-buttons">
3443 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
3444 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
3445 </button>
3446 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
3447 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
3448 </button>
3449 </p>
3450 </form>
3451 <?php
3452 }
3453
3454 /**
3455 * Render login security tab
3456 */
3457 private function render_tab_login() {
3458 $is_disabled = $this->render_module_disabled_notice( 'login_security' );
3459 $options = $this->settings->get_section( 'login_security' );
3460 $lockouts = $this->database->get_active_lockouts();
3461 ?>
3462 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="login_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
3463 <div id="vigilante-section-login-main" class="vigilante-settings-section">
3464 <h2>
3465 <?php esc_html_e( 'Login Protection', 'vigilante' ); ?>
3466 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
3467 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
3468 </h2>
3469 <p><?php esc_html_e( 'Brute force protection and WordPress login hardening.', 'vigilante' ); ?></p>
3470
3471 <table class="form-table">
3472 <tr id="field-max-attempts">
3473 <th scope="row"><label for="vigilante-f-login-security-max-attempts"><?php esc_html_e( 'Max Login Attempts', 'vigilante' ); ?></label></th>
3474 <td>
3475 <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">
3476 <p class="description"><?php esc_html_e( 'Number of failed attempts before lockout.', 'vigilante' ); ?></p>
3477 </td>
3478 </tr>
3479 <tr>
3480 <th scope="row"><label for="vigilante-f-login-security-lockout-duration"><?php esc_html_e( 'Lockout Duration', 'vigilante' ); ?></label></th>
3481 <td>
3482 <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">
3483 <?php esc_html_e( 'minutes', 'vigilante' ); ?>
3484 </td>
3485 </tr>
3486 <tr>
3487 <th scope="row"><?php esc_html_e( 'Progressive Lockout', 'vigilante' ); ?></th>
3488 <td>
3489 <label>
3490 <input type="checkbox" name="login_security[lockout_increment]" value="1" <?php checked( ! empty( $options['lockout_increment'] ) ); ?>>
3491 <?php esc_html_e( 'Double lockout duration for repeat offenders', 'vigilante' ); ?>
3492 </label>
3493 </td>
3494 </tr>
3495 <tr>
3496 <th scope="row"><?php esc_html_e( 'Hide Login Errors', 'vigilante' ); ?></th>
3497 <td>
3498 <label>
3499 <input type="checkbox" name="login_security[hide_login_errors]" value="1" <?php checked( ! empty( $options['hide_login_errors'] ) ); ?>>
3500 <?php esc_html_e( 'Show generic error message instead of specific errors', 'vigilante' ); ?>
3501 </label>
3502 </td>
3503 </tr>
3504 <tr>
3505 <th scope="row"><?php esc_html_e( 'Disable Application Passwords', 'vigilante' ); ?></th>
3506 <td>
3507 <label>
3508 <input type="checkbox" name="login_security[disable_application_passwords]" value="1" <?php checked( ! empty( $options['disable_application_passwords'] ) ); ?>>
3509 <?php esc_html_e( 'Disable WordPress application passwords feature', 'vigilante' ); ?>
3510 </label>
3511 </td>
3512 </tr>
3513 </table>
3514
3515 <h3><?php esc_html_e( 'Custom Login URL', 'vigilante' ); ?></h3>
3516 <table class="form-table">
3517 <tr id="field-custom-login-url">
3518 <th scope="row"><?php esc_html_e( 'Login URL Slug', 'vigilante' ); ?></th>
3519 <td>
3520 <code><?php echo esc_url( home_url( '/' ) ); ?></code>
3521 <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' ); ?>">
3522 <p class="description">
3523 <?php esc_html_e( '&#9432; Leave empty to use default wp-login.php. Use only lowercase letters, numbers and hyphens.', 'vigilante' ); ?>
3524 </p>
3525 <div class="vigilante-login-url-preview" <?php echo empty( $options['custom_login_url'] ) ? 'style="display:none;"' : ''; ?>>
3526 <p class="description">
3527 <strong><?php esc_html_e( 'Your login URL:', 'vigilante' ); ?></strong>
3528 <code class="vigilante-login-url-display"><?php echo esc_url( home_url( sanitize_title( $options['custom_login_url'] ?? '' ) . '/' ) ); ?></code>
3529 </p>
3530 <p class="description">
3531 <?php esc_html_e( 'Direct access to wp-login.php and wp-admin will return a 404 error for non-logged users.', 'vigilante' ); ?>
3532 </p>
3533 <p class="description">
3534 <?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' ); ?>
3535 </p>
3536 </div>
3537 </td>
3538 </tr>
3539 </table>
3540
3541 <div class="vigilante-login-url-notify-wrapper <?php echo empty( $options['custom_login_url'] ) ? 'vigilante-login-url-notify-disabled' : ''; ?>">
3542 <table class="form-table">
3543 <tr>
3544 <th scope="row"><?php esc_html_e( 'Notify users', 'vigilante' ); ?></th>
3545 <td>
3546 <label>
3547 <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 ); ?>>
3548 <?php esc_html_e( 'Notify affected users when the login URL changes', 'vigilante' ); ?>
3549 </label>
3550 <div class="vigilante-login-url-send-notification" style="margin-top:12px;">
3551 <button type="button" id="vigilante_notify_login_url" class="button">
3552 <?php esc_html_e( 'Send notification now', 'vigilante' ); ?>
3553 </button>
3554 <span class="vigilante-login-url-notify-status"></span>
3555 <p class="description"><?php esc_html_e( 'Sends the new URL to administrators, editors, authors, and contributors.', 'vigilante' ); ?></p>
3556 </div>
3557 </td>
3558 </tr>
3559 </table>
3560 </div>
3561
3562 <?php $this->render_2fa_settings( $options ); ?>
3563
3564 <h3><?php esc_html_e( 'Notifications', 'vigilante' ); ?></h3>
3565 <table class="form-table">
3566 <tr>
3567 <th scope="row"><?php esc_html_e( 'Notify on Lockout', 'vigilante' ); ?></th>
3568 <td>
3569 <label>
3570 <input type="checkbox" name="login_security[notify_on_lockout]" value="1" <?php checked( ! empty( $options['notify_on_lockout'] ) ); ?>>
3571 <?php esc_html_e( 'Send email when an IP is locked out', 'vigilante' ); ?>
3572 </label>
3573 </td>
3574 </tr>
3575 <tr>
3576 <th scope="row"><?php esc_html_e( 'Notify on Admin Login', 'vigilante' ); ?></th>
3577 <td>
3578 <label>
3579 <input type="checkbox" name="login_security[notify_on_admin_login]" value="1" <?php checked( ! empty( $options['notify_on_admin_login'] ) ); ?>>
3580 <?php esc_html_e( 'Send email when an administrator logs in', 'vigilante' ); ?>
3581 </label>
3582 </td>
3583 </tr>
3584 </table>
3585
3586 <p class="description">
3587 <?php
3588 printf(
3589 /* translators: %s: Link to notification settings */
3590 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
3591 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
3592 );
3593 ?>
3594 </p>
3595 </div>
3596
3597 <p class="submit vigilante-submit-buttons">
3598 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
3599 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
3600 </button>
3601 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
3602 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
3603 </button>
3604 </p>
3605 </form>
3606
3607 <?php $this->render_lockout_info_section( $options, $lockouts ); ?>
3608 <?php
3609 }
3610
3611 /**
3612 * Render lockout information and blocked IPs section
3613 *
3614 * @param array $options Login security options.
3615 * @param array $lockouts Currently locked out IPs.
3616 */
3617 private function render_lockout_info_section( $options, $lockouts ) {
3618 $max_attempts = absint( $options['max_attempts'] ?? 5 );
3619 $lockout_duration = absint( $options['lockout_duration'] ?? 1800 );
3620 $lockout_increment = ! empty( $options['lockout_increment'] );
3621 $max_lockout = absint( $options['max_lockout_duration'] ?? 86400 );
3622 $two_factor = $options['two_factor'] ?? array();
3623 $two_factor_enabled = ! empty( $two_factor['enabled'] );
3624 ?>
3625 <div class="vigilante-settings-section vigilante-lockout-section">
3626 <h2 id="vigilante-section-login-status"><?php esc_html_e( 'Login Protection Status', 'vigilante' ); ?></h2>
3627
3628 <table class="form-table">
3629 <tr>
3630 <th scope="row"><?php esc_html_e( 'Current settings', 'vigilante' ); ?></th>
3631 <td>
3632 <?php
3633 printf(
3634 /* translators: 1: Maximum login attempts, 2: Lockout duration in minutes */
3635 esc_html__( 'After %1$d failed login attempts, the IP address is blocked for %2$d minutes.', 'vigilante' ),
3636 absint( $max_attempts ),
3637 absint( ceil( $lockout_duration / 60 ) )
3638 );
3639
3640 if ( $lockout_increment ) {
3641 echo '<br>';
3642 printf(
3643 /* translators: %d: Maximum lockout duration in hours */
3644 esc_html__( 'Progressive lockout enabled (max: %d hours).', 'vigilante' ),
3645 absint( ceil( $max_lockout / 3600 ) )
3646 );
3647 }
3648
3649 if ( $two_factor_enabled ) {
3650 echo '<br>';
3651 esc_html_e( 'Failed 2FA codes also count toward the lockout limit.', 'vigilante' );
3652 }
3653 ?>
3654 </td>
3655 </tr>
3656 <tr>
3657 <th scope="row"><?php esc_html_e( 'Blocked IPs', 'vigilante' ); ?></th>
3658 <td>
3659 <?php if ( ! empty( $lockouts ) ) : ?>
3660 <div class="vigilante-paginated-section">
3661 <div class="vigilante-fi-pagination-wrap"></div>
3662 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
3663 <thead>
3664 <tr>
3665 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
3666 <th><?php esc_html_e( 'Attempts', 'vigilante' ); ?></th>
3667 <th><?php esc_html_e( 'Blocked Until', 'vigilante' ); ?></th>
3668 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
3669 </tr>
3670 </thead>
3671 <tbody>
3672 <?php foreach ( $lockouts as $lockout ) :
3673 $lockout_time = strtotime( $lockout->locked_until );
3674 $remaining_seconds = $lockout_time - time();
3675 $remaining_text = $this->format_remaining_time( $remaining_seconds );
3676 ?>
3677 <tr>
3678 <td><code><?php echo esc_html( $lockout->ip_address ); ?></code></td>
3679 <td><?php echo esc_html( $lockout->attempts ); ?></td>
3680 <td>
3681 <?php echo esc_html( wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $lockout_time ) ); ?>
3682 <br>
3683 <small class="description">
3684 <?php
3685 printf(
3686 /* translators: %s: Remaining time */
3687 esc_html__( '%s remaining', 'vigilante' ),
3688 esc_html( $remaining_text )
3689 );
3690 ?>
3691 </small>
3692 </td>
3693 <td>
3694 <button type="button" class="button button-small vigilante-clear-lockout" data-ip="<?php echo esc_attr( $lockout->ip_address ); ?>">
3695 <?php esc_html_e( 'Unblock', 'vigilante' ); ?>
3696 </button>
3697 </td>
3698 </tr>
3699 <?php endforeach; ?>
3700 </tbody>
3701 </table>
3702 </div>
3703 <p class="description" style="margin-top: 10px;">
3704 <button type="button" class="button vigilante-clear-all-lockouts">
3705 <?php esc_html_e( 'Unblock All IPs', 'vigilante' ); ?>
3706 </button>
3707 <span style="margin-left: 10px;">
3708 <?php
3709 printf(
3710 /* translators: %d: Number of blocked IPs */
3711 esc_html( _n( '%d IP currently blocked', '%d IPs currently blocked', count( $lockouts ), 'vigilante' ) ),
3712 count( $lockouts )
3713 );
3714 ?>
3715 </span>
3716 </p>
3717 <?php else : ?>
3718 <span class="dashicons dashicons-yes-alt" style="color: #00a32a; font-size: 20px; width: 20px; height: 20px; vertical-align: middle;"></span>
3719 <span style="vertical-align: middle; margin-left: 5px;"><?php esc_html_e( 'No IPs are currently blocked. All clear!', 'vigilante' ); ?></span>
3720 <?php endif; ?>
3721 </td>
3722 </tr>
3723 </table>
3724 </div>
3725 <?php
3726 }
3727
3728 /**
3729 * Format remaining lockout time in human readable format
3730 *
3731 * @param int $seconds Remaining seconds.
3732 * @return string Formatted time string.
3733 */
3734 private function format_remaining_time( $seconds ) {
3735 if ( $seconds <= 0 ) {
3736 return __( 'expired', 'vigilante' );
3737 }
3738
3739 if ( $seconds < 60 ) {
3740 return sprintf(
3741 /* translators: %d: Number of seconds */
3742 _n( '%d second', '%d seconds', $seconds, 'vigilante' ),
3743 $seconds
3744 );
3745 }
3746
3747 if ( $seconds < 3600 ) {
3748 $minutes = ceil( $seconds / 60 );
3749 return sprintf(
3750 /* translators: %d: Number of minutes */
3751 _n( '%d minute', '%d minutes', $minutes, 'vigilante' ),
3752 $minutes
3753 );
3754 }
3755
3756 $hours = floor( $seconds / 3600 );
3757 $remaining_minutes = ceil( ( $seconds % 3600 ) / 60 );
3758
3759 if ( $remaining_minutes > 0 ) {
3760 return sprintf(
3761 /* translators: 1: Number of hours, 2: Number of minutes */
3762 __( '%1$d hours %2$d minutes', 'vigilante' ),
3763 $hours,
3764 $remaining_minutes
3765 );
3766 }
3767
3768 return sprintf(
3769 /* translators: %d: Number of hours */
3770 _n( '%d hour', '%d hours', $hours, 'vigilante' ),
3771 $hours
3772 );
3773 }
3774
3775 /**
3776 * Render 2FA settings section
3777 *
3778 * @param array $options Login security options.
3779 */
3780 private function render_2fa_settings( $options ) {
3781 $two_factor = $options['two_factor'] ?? array();
3782 $all_roles = wp_roles()->roles;
3783 $enforced = $two_factor['enforced_roles'] ?? array( 'administrator', 'editor' );
3784 $excluded = $two_factor['excluded_users'] ?? array();
3785 $method = $two_factor['method'] ?? 'email';
3786 $grace_days = $two_factor['grace_period_days'] ?? 3;
3787 ?>
3788 <h3 id="vigilante-section-login-2fa">
3789 <?php esc_html_e( 'Two-Factor Authentication (2FA)', 'vigilante' ); ?>
3790 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
3791 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
3792 </h3>
3793 <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>
3794
3795 <table class="form-table">
3796 <tr>
3797 <th scope="row"><?php esc_html_e( 'Enable 2FA', 'vigilante' ); ?></th>
3798 <td>
3799 <label>
3800 <input type="checkbox" name="login_security[two_factor][enabled]" id="vigilante_2fa_enabled" value="1" <?php checked( ! empty( $two_factor['enabled'] ) ); ?>>
3801 <?php esc_html_e( 'Enable two-factor authentication', 'vigilante' ); ?>
3802 </label>
3803 </td>
3804 </tr>
3805 </table>
3806
3807 <div class="vigilante-2fa-settings-wrapper <?php echo empty( $two_factor['enabled'] ) ? 'vigilante-2fa-settings-disabled' : ''; ?>">
3808 <table class="form-table">
3809 <tr>
3810 <th scope="row"><?php esc_html_e( 'Verification method', 'vigilante' ); ?></th>
3811 <td>
3812 <fieldset class="vigilante-2fa-method-selector">
3813 <label class="vigilante-2fa-method-option <?php echo 'email' === $method ? 'selected' : ''; ?>">
3814 <input type="radio" name="login_security[two_factor][method]" value="email" <?php checked( $method, 'email' ); ?>>
3815 <span class="dashicons dashicons-email"></span>
3816 <span class="method-info">
3817 <strong><?php esc_html_e( 'Email code', 'vigilante' ); ?></strong>
3818 <span><?php esc_html_e( 'Users receive a 6-digit code via email after entering their password.', 'vigilante' ); ?></span>
3819 </span>
3820 </label>
3821 <label class="vigilante-2fa-method-option <?php echo 'totp' === $method ? 'selected' : ''; ?>">
3822 <input type="radio" name="login_security[two_factor][method]" value="totp" <?php checked( $method, 'totp' ); ?>>
3823 <span class="dashicons dashicons-smartphone"></span>
3824 <span class="method-info">
3825 <strong><?php esc_html_e( 'Authenticator app (TOTP)', 'vigilante' ); ?></strong>
3826 <span><?php esc_html_e( 'Users verify with a time-based code from Google Authenticator, Authy, etc.', 'vigilante' ); ?></span>
3827 </span>
3828 </label>
3829 </fieldset>
3830 </td>
3831 </tr>
3832 <tr>
3833 <th scope="row"><?php esc_html_e( 'Enforce for roles', 'vigilante' ); ?></th>
3834 <td>
3835 <div class="vigilante-2fa-roles">
3836 <?php foreach ( $all_roles as $role_slug => $role_data ) :
3837 $user_count = count( get_users( array( 'role' => $role_slug, 'fields' => 'ID' ) ) );
3838 ?>
3839 <label>
3840 <input type="checkbox"
3841 name="login_security[two_factor][enforced_roles][]"
3842 value="<?php echo esc_attr( $role_slug ); ?>"
3843 <?php checked( in_array( $role_slug, $enforced, true ) ); ?>>
3844 <span class="role-name"><?php echo esc_html( translate_user_role( $role_data['name'] ) ); ?></span>
3845 <span class="role-count">(<?php echo esc_html( $user_count ); ?>)</span>
3846 </label>
3847 <?php endforeach; ?>
3848 </div>
3849 <p class="description"><?php esc_html_e( 'Users with these roles will be required to verify with the selected method.', 'vigilante' ); ?></p>
3850 </td>
3851 </tr>
3852 <tr>
3853 <th scope="row"><?php esc_html_e( 'Exclude specific users', 'vigilante' ); ?></th>
3854 <td>
3855 <div class="vigilante-2fa-user-search-container">
3856 <div class="vigilante-2fa-user-search">
3857 <span class="search-icon"></span>
3858 <input type="text"
3859 id="vigilante_2fa_user_search"
3860 placeholder="<?php esc_attr_e( 'Search users by name or email...', 'vigilante' ); ?>"
3861 autocomplete="off">
3862 <div class="vigilante-2fa-search-results"></div>
3863 </div>
3864 <div class="vigilante-2fa-excluded-users">
3865 <?php
3866 foreach ( $excluded as $user_id ) :
3867 $user = get_user_by( 'ID', $user_id );
3868 if ( ! $user ) continue;
3869 ?>
3870 <div class="vigilante-2fa-excluded-user" data-user-id="<?php echo esc_attr( $user_id ); ?>">
3871 <span class="user-display"><?php echo esc_html( $user->display_name . ' (' . $user->user_email . ')' ); ?></span>
3872 <button type="button" class="remove-user" aria-label="<?php esc_attr_e( 'Remove', 'vigilante' ); ?>">&times;</button>
3873 <input type="hidden" name="login_security[two_factor][excluded_users][]" value="<?php echo esc_attr( $user_id ); ?>">
3874 </div>
3875 <?php endforeach; ?>
3876 </div>
3877 </div>
3878 <p class="description"><?php esc_html_e( 'These users will not be required to use 2FA regardless of their role.', 'vigilante' ); ?></p>
3879 </td>
3880 </tr>
3881
3882 <!-- Remember device option -->
3883 <tr>
3884 <th scope="row"><?php esc_html_e( 'Remember device', 'vigilante' ); ?></th>
3885 <td>
3886 <label>
3887 <input type="checkbox" name="login_security[two_factor][allow_remember_device]" value="1" <?php checked( ! empty( $two_factor['allow_remember_device'] ) ); ?>>
3888 <?php esc_html_e( 'Allow users to skip 2FA verification on trusted devices', 'vigilante' ); ?>
3889 </label>
3890 <p class="description">
3891 <?php
3892 printf(
3893 /* translators: %d: Number of days */
3894 esc_html__( 'When enabled, users can check "Remember this device" on the verification screen to skip 2FA for %d days.', 'vigilante' ),
3895 absint( $two_factor['remember_device_days'] ?? 30 )
3896 );
3897 ?>
3898 </p>
3899 </td>
3900 </tr>
3901
3902 <!-- TOTP-specific: Grace period -->
3903 <tr class="vigilante-2fa-totp-only" <?php echo 'totp' !== $method ? 'style="display:none;"' : ''; ?>>
3904 <th scope="row"><label for="vigilante-f-login-security-two-factor-grace-period-days"><?php esc_html_e( 'Grace period', 'vigilante' ); ?></label></th>
3905 <td>
3906 <input id="vigilante-f-login-security-two-factor-grace-period-days" type="number"
3907 name="login_security[two_factor][grace_period_days]"
3908 value="<?php echo esc_attr( $grace_days ); ?>"
3909 min="0" max="30" class="small-text">
3910 <?php esc_html_e( 'days', 'vigilante' ); ?>
3911 <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>
3912 </td>
3913 </tr>
3914
3915 <!-- Email-specific: Sender name -->
3916 <tr class="vigilante-2fa-email-only" <?php echo 'email' !== $method ? 'style="display:none;"' : ''; ?>>
3917 <th scope="row"><label for="vigilante-f-login-security-two-factor-email-from-name"><?php esc_html_e( 'Email sender name', 'vigilante' ); ?></label></th>
3918 <td>
3919 <input id="vigilante-f-login-security-two-factor-email-from-name" type="text"
3920 name="login_security[two_factor][email_from_name]"
3921 value="<?php echo esc_attr( $two_factor['email_from_name'] ?? '' ); ?>"
3922 class="regular-text vigilante-2fa-email-from"
3923 placeholder="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>">
3924 <p class="description"><?php esc_html_e( 'Name shown in verification emails. Leave empty to use site name.', 'vigilante' ); ?></p>
3925 </td>
3926 </tr>
3927
3928 <!-- TOTP-specific: Reset users -->
3929 <tr class="vigilante-2fa-totp-only" <?php echo 'totp' !== $method ? 'style="display:none;"' : ''; ?>>
3930 <th scope="row"><?php esc_html_e( 'Reset user TOTP', 'vigilante' ); ?></th>
3931 <td>
3932 <div class="vigilante-totp-reset-container">
3933 <div class="vigilante-2fa-user-search">
3934 <span class="search-icon"></span>
3935 <input type="text"
3936 id="vigilante_totp_reset_search"
3937 placeholder="<?php esc_attr_e( 'Search users with TOTP configured...', 'vigilante' ); ?>"
3938 autocomplete="off">
3939 <div class="vigilante-totp-reset-results"></div>
3940 </div>
3941 <div class="vigilante-totp-reset-selected"></div>
3942 <button type="button" id="vigilante_totp_reset_btn" class="button" style="display:none;">
3943 <?php esc_html_e( 'Reset selected', 'vigilante' ); ?>
3944 </button>
3945 <span class="vigilante-totp-reset-status"></span>
3946 </div>
3947 <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>
3948 </td>
3949 </tr>
3950 </table>
3951
3952 <h3><?php esc_html_e( 'User notification', 'vigilante' ); ?></h3>
3953 <table class="form-table">
3954 <tr>
3955 <th scope="row"><?php esc_html_e( 'Notify on enable', 'vigilante' ); ?></th>
3956 <td>
3957 <label>
3958 <input type="checkbox" name="login_security[two_factor][notify_on_enable]" value="1" <?php checked( $two_factor['notify_on_enable'] ?? true ); ?>>
3959 <?php esc_html_e( 'Send notification email to affected users when 2FA is enabled', 'vigilante' ); ?>
3960 </label>
3961
3962 <div class="vigilante-2fa-notification-options">
3963 <label>
3964 <input type="radio" name="vigilante_2fa_notify_mode" value="all" checked>
3965 <?php esc_html_e( 'Send to all affected users', 'vigilante' ); ?>
3966 </label>
3967 <label>
3968 <input type="radio" name="vigilante_2fa_notify_mode" value="new">
3969 <?php esc_html_e( 'Send only to users not previously notified', 'vigilante' ); ?>
3970 </label>
3971 </div>
3972
3973 <div class="vigilante-2fa-send-notification">
3974 <button type="button" id="vigilante_2fa_send_notification" class="button">
3975 <?php esc_html_e( 'Send notification now', 'vigilante' ); ?>
3976 </button>
3977 <span class="vigilante-2fa-notification-status"></span>
3978 </div>
3979 </td>
3980 </tr>
3981 </table>
3982 </div>
3983 <?php
3984 }
3985
3986 /**
3987 * Render security headers tab
3988 */
3989 /**
3990 * Offer back the header settings the 2.9.8 migration wiped.
3991 *
3992 * Rendered outside the settings form on purpose, so its buttons can never
3993 * submit it, and only when there is something to actually change. Shows the
3994 * difference before anything is written: nothing is applied that the owner
3995 * has not seen first.
3996 *
3997 * @since 2.10.0
3998 */
3999 private function render_headers_recovery_offer() {
4000 /*
4001 * On a network the .htaccess belongs to every site and only the main one
4002 * writes it, so this is not a decision a subsite gets to make. Its own
4003 * security_headers options are inert anyway: what the network serves
4004 * comes from the file the main site owns. Without this gate a subsite
4005 * administrator was shown a Restore button that could only ever answer
4006 * with a permission error, which is worse than showing nothing.
4007 */
4008 if ( ! Vigilante_Settings::can_write_shared_files() ) {
4009 return;
4010 }
4011
4012 if ( ! Vigilante_Htaccess_Recovery::is_available() ) {
4013 /*
4014 * Already restored. Offer to take it back for as long as the previous
4015 * section is still stored: a restore that cannot be undone is a second
4016 * irreversible change on top of the one being repaired.
4017 */
4018 if ( Vigilante_Htaccess_Recovery::has_undo() ) {
4019 ?>
4020 <div class="notice notice-info inline" id="vigilante-headers-recovery-undo">
4021 <p>
4022 <?php esc_html_e( 'The Security Headers settings were restored from the copy Vigilant had kept of your .htaccess.', 'vigilante' ); ?>
4023 <button type="button" class="button button-small" id="vigilante-recovery-undo">
4024 <?php esc_html_e( 'Undo the restore', 'vigilante' ); ?>
4025 </button>
4026 </p>
4027 </div>
4028 <?php
4029 }
4030
4031 return;
4032 }
4033
4034 $rows = Vigilante_Htaccess_Recovery::get_diff( $this->settings );
4035
4036 if ( empty( $rows ) ) {
4037 return;
4038 }
4039
4040 $snapshot = Vigilante_Htaccess_Recovery::get_snapshot();
4041 $taken = isset( $snapshot['time'] ) ? (int) $snapshot['time'] : 0;
4042 $block = Vigilante_Htaccess_Recovery::get_raw_block();
4043 ?>
4044 <div class="vigilante-settings-section" id="vigilante-headers-recovery">
4045 <h2><?php esc_html_e( 'Recover your previous header settings', 'vigilante' ); ?></h2>
4046 <p>
4047 <?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' ); ?>
4048 </p>
4049 <?php if ( $taken ) : ?>
4050 <p class="description">
4051 <?php
4052 printf(
4053 /* translators: %s: date and time the .htaccess copy was taken. */
4054 esc_html__( 'Copy taken on %s.', 'vigilante' ),
4055 esc_html( wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $taken ) )
4056 );
4057 ?>
4058 </p>
4059 <?php endif; ?>
4060
4061 <table class="widefat striped">
4062 <thead>
4063 <tr>
4064 <th scope="col"><?php esc_html_e( 'Setting', 'vigilante' ); ?></th>
4065 <th scope="col"><?php esc_html_e( 'Now', 'vigilante' ); ?></th>
4066 <th scope="col"><?php esc_html_e( 'Would be restored to', 'vigilante' ); ?></th>
4067 </tr>
4068 </thead>
4069 <tbody>
4070 <?php foreach ( $rows as $row ) : ?>
4071 <tr>
4072 <th scope="row"><?php echo esc_html( $row['label'] ); ?></th>
4073 <td><?php echo esc_html( $row['current'] ); ?></td>
4074 <td>
4075 <?php echo esc_html( $row['recovered'] ); ?>
4076 <?php if ( ! empty( $row['detail'] ) ) : ?>
4077 <br><span class="description"><?php echo esc_html( $row['detail'] ); ?></span>
4078 <?php endif; ?>
4079 </td>
4080 </tr>
4081 <?php endforeach; ?>
4082 </tbody>
4083 </table>
4084
4085 <p class="description">
4086 <?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' ); ?>
4087 </p>
4088
4089 <?php if ( '' !== $block ) : ?>
4090 <details>
4091 <summary><?php esc_html_e( 'Show the saved .htaccess block', 'vigilante' ); ?></summary>
4092 <textarea readonly rows="12" class="large-text code" onclick="this.select();"><?php echo esc_textarea( $block ); ?></textarea>
4093 </details>
4094 <?php endif; ?>
4095
4096 <p class="submit vigilante-submit-buttons">
4097 <button type="button" class="button button-primary" id="vigilante-recovery-restore">
4098 <?php esc_html_e( 'Restore these settings', 'vigilante' ); ?>
4099 </button>
4100 <button type="button" class="button" id="vigilante-recovery-dismiss">
4101 <?php esc_html_e( 'No thanks, keep what I have', 'vigilante' ); ?>
4102 </button>
4103 </p>
4104 <div id="vigilante-recovery-result"></div>
4105 </div>
4106 <?php
4107 }
4108
4109 private function render_tab_headers() {
4110 $is_disabled = $this->render_module_disabled_notice( 'security_headers' );
4111 // Every setting on this tab ends up in .htaccess, so on a subsite the
4112 // whole tab is somebody else's, values included.
4113 $vg_shared_locked = $this->shared_files_locked();
4114 $options = $this->get_section_for_display( 'security_headers' );
4115 ?>
4116 <?php $this->render_headers_recovery_offer(); ?>
4117
4118 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="security_headers" <?php echo $is_disabled ? 'inert' : ''; ?>>
4119 <?php $this->render_shared_files_notice(); ?>
4120 <div id="vigilante-section-headers-main" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
4121 <h2>
4122 <?php esc_html_e( 'Security Headers', 'vigilante' ); ?>
4123 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
4124 </h2>
4125 <p><?php esc_html_e( 'HTTP headers sent with every response via .htaccess (mod_headers).', 'vigilante' ); ?></p>
4126
4127 <table class="form-table">
4128 <tr>
4129 <th scope="row"><label for="vigilante-f-security-headers-x-frame-options"><?php esc_html_e( 'X-Frame-Options', 'vigilante' ); ?></label></th>
4130 <td>
4131 <select id="vigilante-f-security-headers-x-frame-options" name="security_headers[x_frame_options]">
4132 <option value="" <?php selected( empty( $options['x_frame_options'] ) ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
4133 <option value="SAMEORIGIN" <?php selected( $options['x_frame_options'] ?? '', 'SAMEORIGIN' ); ?>>SAMEORIGIN</option>
4134 <option value="DENY" <?php selected( $options['x_frame_options'] ?? '', 'DENY' ); ?>>DENY</option>
4135 </select>
4136 <p class="description"><?php esc_html_e( '&#9432; Prevents clickjacking attacks. Also sets CSP frame-ancestors automatically.', 'vigilante' ); ?></p>
4137 </td>
4138 </tr>
4139 <tr>
4140 <th scope="row"><?php esc_html_e( 'X-Content-Type-Options', 'vigilante' ); ?></th>
4141 <td>
4142 <label>
4143 <input type="checkbox" name="security_headers[x_content_type_options]" value="1" <?php checked( ! empty( $options['x_content_type_options'] ) ); ?>>
4144 <?php esc_html_e( 'Add nosniff header to prevent MIME type sniffing', 'vigilante' ); ?>
4145 </label>
4146 </td>
4147 </tr>
4148 <tr>
4149 <th scope="row"><label for="vigilante-f-security-headers-referrer-policy"><?php esc_html_e( 'Referrer-Policy', 'vigilante' ); ?></label></th>
4150 <td>
4151 <select id="vigilante-f-security-headers-referrer-policy" name="security_headers[referrer_policy]">
4152 <option value="" <?php selected( empty( $options['referrer_policy'] ) ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
4153 <option value="no-referrer" <?php selected( $options['referrer_policy'] ?? '', 'no-referrer' ); ?>>no-referrer</option>
4154 <option value="strict-origin-when-cross-origin" <?php selected( $options['referrer_policy'] ?? '', 'strict-origin-when-cross-origin' ); ?>>strict-origin-when-cross-origin</option>
4155 <option value="same-origin" <?php selected( $options['referrer_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
4156 </select>
4157 </td>
4158 </tr>
4159 </table>
4160
4161 <h3 id="vigilante-section-headers-csp"><?php esc_html_e( 'Content Security Policy', 'vigilante' ); ?></h3>
4162 <table class="form-table">
4163 <tr>
4164 <th scope="row"><?php esc_html_e( 'Enable CSP', 'vigilante' ); ?></th>
4165 <td>
4166 <label>
4167 <input type="checkbox" name="security_headers[csp][enabled]" value="1" <?php checked( ! empty( $options['csp']['enabled'] ) ); ?>>
4168 <?php esc_html_e( 'Enable Content Security Policy', 'vigilante' ); ?>
4169 </label>
4170 </td>
4171 </tr>
4172 <tr>
4173 <th scope="row"><?php esc_html_e( 'Report Only Mode', 'vigilante' ); ?></th>
4174 <td>
4175 <label>
4176 <input type="checkbox" name="security_headers[csp][report_only]" value="1" <?php checked( ! empty( $options['csp']['report_only'] ) ); ?>>
4177 <?php esc_html_e( 'Report violations without blocking (for testing)', 'vigilante' ); ?>
4178 </label>
4179 </td>
4180 </tr>
4181 </table>
4182
4183 <h3 id="vigilante-section-headers-force-https"><?php esc_html_e( 'HTTPS', 'vigilante' ); ?></h3>
4184 <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>
4185 <table class="form-table">
4186 <tr>
4187 <th scope="row"><?php esc_html_e( 'Redirect HTTP to HTTPS', 'vigilante' ); ?></th>
4188 <td>
4189 <label>
4190 <input type="checkbox" name="security_headers[redirect_http_to_https]" value="1" <?php checked( ! empty( $options['redirect_http_to_https'] ) ); ?>>
4191 <?php esc_html_e( 'Send visitors arriving over HTTP to the HTTPS address', 'vigilante' ); ?>
4192 </label>
4193 <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>
4194 </td>
4195 </tr>
4196 <tr>
4197 <th scope="row"><?php esc_html_e( 'Fix Mixed Content', 'vigilante' ); ?></th>
4198 <td>
4199 <label>
4200 <input type="checkbox" name="security_headers[fix_mixed_content]" value="1" <?php checked( ! empty( $options['fix_mixed_content'] ) ); ?>>
4201 <?php esc_html_e( 'Rewrite this site http:// resources to https://', 'vigilante' ); ?>
4202 </label>
4203 <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>
4204 </td>
4205 </tr>
4206 <tr id="field-upgrade-insecure-requests">
4207 <th scope="row"><?php esc_html_e( 'Upgrade Insecure Requests', 'vigilante' ); ?></th>
4208 <td>
4209 <label>
4210 <input type="checkbox" name="security_headers[upgrade_insecure_requests]" value="1" <?php checked( ! empty( $options['upgrade_insecure_requests'] ) ); ?>>
4211 <?php esc_html_e( 'Ask browsers to upgrade every http:// request to https://', 'vigilante' ); ?>
4212 </label>
4213 <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>
4214 </td>
4215 </tr>
4216 <tr>
4217 <th scope="row"><?php esc_html_e( 'Rewrite Site Address on Activation', 'vigilante' ); ?></th>
4218 <td>
4219 <label>
4220 <input type="checkbox" name="security_headers[force_https]" value="1" <?php checked( ! empty( $options['force_https'] ) ); ?>>
4221 <?php esc_html_e( 'Change the WordPress and site addresses to https:// when the plugin is activated', 'vigilante' ); ?>
4222 </label>
4223 <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>
4224 </td>
4225 </tr>
4226 </table>
4227
4228 <h3 id="vigilante-section-headers-hsts"><?php esc_html_e( 'HSTS (HTTP Strict Transport Security)', 'vigilante' ); ?></h3>
4229 <?php $vig_home_https = ( 0 === strpos( (string) get_option( 'home' ), 'https://' ) ); ?>
4230 <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>
4231 <?php if ( ! $vig_home_https ) : ?>
4232 <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>
4233 <?php endif; ?>
4234 <table class="form-table">
4235 <tr>
4236 <th scope="row"><?php esc_html_e( 'Enable HSTS', 'vigilante' ); ?></th>
4237 <td>
4238 <?php if ( ! $vig_home_https ) : ?>
4239 <?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. */ ?>
4240 <input type="hidden" name="security_headers[hsts][enabled]" value="<?php echo ! empty( $options['hsts']['enabled'] ) ? '1' : '0'; ?>">
4241 <?php endif; ?>
4242 <label>
4243 <input type="checkbox" name="security_headers[hsts][enabled]" value="1" <?php checked( ! empty( $options['hsts']['enabled'] ) ); ?> <?php disabled( ! $vig_home_https ); ?>>
4244 <?php esc_html_e( 'Send the Strict-Transport-Security header', 'vigilante' ); ?>
4245 </label>
4246 <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>
4247 </td>
4248 </tr>
4249 <tr>
4250 <th scope="row"><label for="vigilante-f-security-headers-hsts-max-age"><?php esc_html_e( 'Max Age', 'vigilante' ); ?></label></th>
4251 <td>
4252 <select id="vigilante-f-security-headers-hsts-max-age" name="security_headers[hsts][max_age]">
4253 <option value="86400" <?php selected( $options['hsts']['max_age'] ?? 31536000, 86400 ); ?>><?php esc_html_e( '1 day (testing)', 'vigilante' ); ?></option>
4254 <option value="2592000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 2592000 ); ?>><?php esc_html_e( '30 days', 'vigilante' ); ?></option>
4255 <option value="31536000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 31536000 ); ?>><?php esc_html_e( '1 year (recommended)', 'vigilante' ); ?></option>
4256 <option value="63072000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 63072000 ); ?>><?php esc_html_e( '2 years', 'vigilante' ); ?></option>
4257 </select>
4258 </td>
4259 </tr>
4260 <tr>
4261 <th scope="row"><?php esc_html_e( 'Include Subdomains', 'vigilante' ); ?></th>
4262 <td>
4263 <label>
4264 <input type="checkbox" name="security_headers[hsts][include_subdomains]" value="1" <?php checked( ! empty( $options['hsts']['include_subdomains'] ) ); ?>>
4265 <?php esc_html_e( 'Apply HSTS to all subdomains', 'vigilante' ); ?>
4266 </label>
4267 </td>
4268 </tr>
4269 </table>
4270
4271 <h3 id="vigilante-section-headers-fingerprint"><?php esc_html_e( 'Server Identity', 'vigilante' ); ?></h3>
4272 <p class="description"><?php esc_html_e( 'Hide identifying information that servers expose in responses.', 'vigilante' ); ?></p>
4273 <table class="form-table">
4274 <tr>
4275 <th scope="row"><?php esc_html_e( 'Server Signature', 'vigilante' ); ?></th>
4276 <td>
4277 <label>
4278 <input type="checkbox" name="security_headers[hide_server_signature]" value="1" <?php checked( ! empty( $options['hide_server_signature'] ) ); ?>>
4279 <?php esc_html_e( 'Hide server signature (ServerSignature Off)', 'vigilante' ); ?>
4280 </label>
4281 </td>
4282 </tr>
4283 <tr>
4284 <th scope="row"><?php esc_html_e( 'Remove Fingerprinting Headers', 'vigilante' ); ?></th>
4285 <td>
4286 <label>
4287 <input type="checkbox" name="security_headers[remove_fingerprinting_headers]" value="1" <?php checked( ! empty( $options['remove_fingerprinting_headers'] ) ); ?>>
4288 <?php esc_html_e( 'Remove X-Powered-By and Server headers', 'vigilante' ); ?>
4289 </label>
4290 </td>
4291 </tr>
4292 </table>
4293 </div>
4294
4295 <?php $vg_cop = ( isset( $options['cross_origin_policies'] ) && is_array( $options['cross_origin_policies'] ) ) ? $options['cross_origin_policies'] : array(); ?>
4296 <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' : ''; ?>>
4297 <h2>
4298 <?php esc_html_e( 'Cross-Origin Policies', 'vigilante' ); ?>
4299 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
4300 </h2>
4301 <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>
4302
4303 <table class="form-table">
4304 <tr>
4305 <th scope="row"><label for="vigilante-f-security-headers-coop"><?php esc_html_e( 'Cross-Origin-Opener-Policy (COOP)', 'vigilante' ); ?></label></th>
4306 <td>
4307 <select id="vigilante-f-security-headers-coop" name="security_headers[cross_origin_policies][opener_policy]">
4308 <option value="" <?php selected( empty( $vg_cop['opener_policy'] ) ); ?>><?php esc_html_e( 'Disabled (header not sent)', 'vigilante' ); ?></option>
4309 <option value="unsafe-none" <?php selected( $vg_cop['opener_policy'] ?? '', 'unsafe-none' ); ?>>unsafe-none</option>
4310 <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>
4311 <option value="same-origin" <?php selected( $vg_cop['opener_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
4312 </select>
4313 <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>
4314 </td>
4315 </tr>
4316 <tr>
4317 <th scope="row"><label for="vigilante-f-security-headers-coep"><?php esc_html_e( 'Cross-Origin-Embedder-Policy (COEP)', 'vigilante' ); ?></label></th>
4318 <td>
4319 <select id="vigilante-f-security-headers-coep" name="security_headers[cross_origin_policies][embedder_policy]">
4320 <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>
4321 <option value="credentialless" <?php selected( $vg_cop['embedder_policy'] ?? '', 'credentialless' ); ?>>credentialless</option>
4322 <option value="require-corp" <?php selected( $vg_cop['embedder_policy'] ?? '', 'require-corp' ); ?>>require-corp</option>
4323 </select>
4324 <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>
4325 </td>
4326 </tr>
4327 <tr>
4328 <th scope="row"><label for="vigilante-f-security-headers-corp"><?php esc_html_e( 'Cross-Origin-Resource-Policy (CORP)', 'vigilante' ); ?></label></th>
4329 <td>
4330 <select id="vigilante-f-security-headers-corp" name="security_headers[cross_origin_policies][resource_policy]">
4331 <option value="" <?php selected( empty( $vg_cop['resource_policy'] ) ); ?>><?php esc_html_e( 'Disabled (header not sent)', 'vigilante' ); ?></option>
4332 <option value="same-site" <?php selected( $vg_cop['resource_policy'] ?? '', 'same-site' ); ?>>same-site</option>
4333 <option value="same-origin" <?php selected( $vg_cop['resource_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
4334 <option value="cross-origin" <?php selected( $vg_cop['resource_policy'] ?? '', 'cross-origin' ); ?>><?php esc_html_e( 'cross-origin (recommended)', 'vigilante' ); ?></option>
4335 </select>
4336 <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>
4337 </td>
4338 </tr>
4339 </table>
4340 </div>
4341
4342 <p class="submit vigilante-submit-buttons">
4343 <?php if ( ! $vg_shared_locked ) : ?>
4344 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4345 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4346 </button>
4347 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4348 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4349 </button>
4350 <?php endif; ?>
4351 <?php /* Testing what the server actually sends is read-only and useful from any site of a network. */ ?>
4352 <button type="button" class="button vigilante-test-headers">
4353 <?php esc_html_e( 'Test Headers', 'vigilante' ); ?>
4354 </button>
4355 </p>
4356 </form>
4357
4358 <div id="vigilante-headers-result"></div>
4359 <?php
4360 }
4361
4362 /**
4363 * Render REST API tab
4364 */
4365 private function render_tab_rest_api() {
4366 $is_disabled = $this->render_module_disabled_notice( 'rest_api_security' );
4367 $options = $this->settings->get_section( 'rest_api_security' );
4368 ?>
4369 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="rest_api_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
4370 <div id="vigilante-section-rest-api-main" class="vigilante-settings-section">
4371 <h2>
4372 <?php esc_html_e( 'REST API Security', 'vigilante' ); ?>
4373 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4374 </h2>
4375 <p><?php esc_html_e( 'Control access to WordPress REST API endpoints.', 'vigilante' ); ?></p>
4376
4377 <table class="form-table">
4378 <tr>
4379 <th scope="row"><label for="vigilante-f-rest-api-security-mode"><?php esc_html_e( 'Access Mode', 'vigilante' ); ?></label></th>
4380 <td>
4381 <select id="vigilante-f-rest-api-security-mode" name="rest_api_security[mode]">
4382 <option value="open" <?php selected( $options['mode'] ?? 'selective', 'open' ); ?>><?php esc_html_e( 'Open - Allow all requests', 'vigilante' ); ?></option>
4383 <option value="selective" <?php selected( $options['mode'] ?? 'selective', 'selective' ); ?>><?php esc_html_e( 'Selective - Protect sensitive endpoints', 'vigilante' ); ?></option>
4384 <option value="authenticated_only" <?php selected( $options['mode'] ?? 'selective', 'authenticated_only' ); ?>><?php esc_html_e( 'Authenticated - Require login for all', 'vigilante' ); ?></option>
4385 </select>
4386 <p class="description"><?php esc_html_e( 'Selective mode is recommended.', 'vigilante' ); ?></p>
4387 </td>
4388 </tr>
4389 <tr id="field-block-user-enumeration">
4390 <th scope="row"><?php esc_html_e( 'Block User Enumeration', 'vigilante' ); ?></th>
4391 <td>
4392 <label>
4393 <input type="checkbox" name="rest_api_security[block_user_enumeration]" value="1" <?php checked( ! empty( $options['block_user_enumeration'] ) ); ?>>
4394 <?php esc_html_e( 'Protect /wp/v2/users endpoint for unauthenticated users', 'vigilante' ); ?>
4395 </label>
4396 </td>
4397 </tr>
4398 <tr>
4399 <th scope="row"><?php esc_html_e( 'Disable JSONP', 'vigilante' ); ?></th>
4400 <td>
4401 <label>
4402 <input type="checkbox" name="rest_api_security[disable_jsonp]" value="1" <?php checked( ! empty( $options['disable_jsonp'] ) ); ?>>
4403 <?php esc_html_e( 'Disable JSONP support in REST API', 'vigilante' ); ?>
4404 </label>
4405 </td>
4406 </tr>
4407 </table>
4408 </div>
4409
4410 <p class="submit vigilante-submit-buttons">
4411 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4412 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4413 </button>
4414 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4415 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4416 </button>
4417 </p>
4418 </form>
4419 <?php
4420 }
4421
4422 /**
4423 * Render User Security tab
4424 */
4425 private function render_tab_users() {
4426 $is_disabled = $this->render_module_disabled_notice( 'user_security' );
4427 $options = $this->settings->get_section( 'user_security' );
4428 $monitoring = $options['admin_monitoring'] ?? array();
4429 $registration = $options['registration_approval'] ?? array();
4430 $session_limits = $options['session_limits'] ?? array();
4431 $password_exp = $options['password_expiration'] ?? array();
4432 $email_verify = $options['email_verification'] ?? array();
4433 ?>
4434
4435 <!-- ============================================================
4436 SETTINGS SECTION - Single form for all configuration
4437 ============================================================ -->
4438 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="user_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
4439
4440 <!-- Username & Password Protection -->
4441 <div id="vigilante-section-users-password" class="vigilante-settings-section">
4442 <h2>
4443 <?php esc_html_e( 'Username & password protection', 'vigilante' ); ?>
4444 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4445 </h2>
4446 <p><?php esc_html_e( 'Enforce secure username and password policies.', 'vigilante' ); ?></p>
4447
4448 <table class="form-table">
4449 <tr>
4450 <th scope="row"><?php esc_html_e( 'Block Insecure Usernames', 'vigilante' ); ?></th>
4451 <td>
4452 <label>
4453 <input type="checkbox" name="user_security[block_insecure_usernames]" value="1" <?php checked( ! empty( $options['block_insecure_usernames'] ) ); ?>>
4454 <?php esc_html_e( 'Prevent creation of users with common usernames (admin, administrator, etc.)', 'vigilante' ); ?>
4455 </label>
4456 </td>
4457 </tr>
4458 <?php
4459 $pw_policy = wp_parse_args(
4460 ( isset( $options['password_policy'] ) && is_array( $options['password_policy'] ) ) ? $options['password_policy'] : array(),
4461 array(
4462 'require_uppercase' => false,
4463 'require_lowercase' => false,
4464 'require_number' => false,
4465 'require_special' => false,
4466 'block_common' => true,
4467 'block_username' => true,
4468 'affected_roles' => array(),
4469 )
4470 );
4471 $pw_policy_roles = (array) $pw_policy['affected_roles'];
4472 ?>
4473 <tr>
4474 <th scope="row"><?php esc_html_e( 'Enforce Strong Passwords', 'vigilante' ); ?></th>
4475 <td>
4476 <label>
4477 <input type="checkbox" name="user_security[force_strong_passwords]" value="1" <?php checked( ! empty( $options['force_strong_passwords'] ) ); ?>>
4478 <?php esc_html_e( 'Check passwords against the requirements below when a user sets or changes one', 'vigilante' ); ?>
4479 </label>
4480 </td>
4481 </tr>
4482 <tr>
4483 <th scope="row"><label for="vigilante-f-user-security-min-password-length"><?php esc_html_e( 'Minimum Password Length', 'vigilante' ); ?></label></th>
4484 <td>
4485 <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">
4486 <?php esc_html_e( 'characters', 'vigilante' ); ?>
4487 </td>
4488 </tr>
4489 <tr>
4490 <th scope="row"><?php esc_html_e( 'Password Requirements', 'vigilante' ); ?></th>
4491 <td>
4492 <label style="display:block;margin-bottom:5px;">
4493 <input type="checkbox" name="user_security[password_policy][require_uppercase]" value="1" <?php checked( ! empty( $pw_policy['require_uppercase'] ) ); ?>>
4494 <?php esc_html_e( 'Require an uppercase letter (A-Z)', 'vigilante' ); ?>
4495 </label>
4496 <label style="display:block;margin-bottom:5px;">
4497 <input type="checkbox" name="user_security[password_policy][require_lowercase]" value="1" <?php checked( ! empty( $pw_policy['require_lowercase'] ) ); ?>>
4498 <?php esc_html_e( 'Require a lowercase letter (a-z)', 'vigilante' ); ?>
4499 </label>
4500 <label style="display:block;margin-bottom:5px;">
4501 <input type="checkbox" name="user_security[password_policy][require_number]" value="1" <?php checked( ! empty( $pw_policy['require_number'] ) ); ?>>
4502 <?php esc_html_e( 'Require a number (0-9)', 'vigilante' ); ?>
4503 </label>
4504 <label style="display:block;margin-bottom:5px;">
4505 <input type="checkbox" name="user_security[password_policy][require_special]" value="1" <?php checked( ! empty( $pw_policy['require_special'] ) ); ?>>
4506 <?php esc_html_e( 'Require a special character (!, @, #, ...)', 'vigilante' ); ?>
4507 </label>
4508 <label style="display:block;margin-bottom:5px;">
4509 <input type="checkbox" name="user_security[password_policy][block_common]" value="1" <?php checked( ! empty( $pw_policy['block_common'] ) ); ?>>
4510 <?php esc_html_e( 'Reject well-known common passwords', 'vigilante' ); ?>
4511 </label>
4512 <label style="display:block;margin-bottom:5px;">
4513 <input type="checkbox" name="user_security[password_policy][block_username]" value="1" <?php checked( ! empty( $pw_policy['block_username'] ) ); ?>>
4514 <?php esc_html_e( 'Do not allow the username inside the password', 'vigilante' ); ?>
4515 </label>
4516 <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>
4517 </td>
4518 </tr>
4519 <tr>
4520 <th scope="row"><?php esc_html_e( 'Apply Password Rules To', 'vigilante' ); ?></th>
4521 <td>
4522 <?php foreach ( wp_roles()->get_names() as $role_slug => $role_name ) : ?>
4523 <label style="display:block;margin-bottom:5px;">
4524 <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 ) ); ?>>
4525 <?php echo esc_html( translate_user_role( $role_name ) ); ?>
4526 </label>
4527 <?php endforeach; ?>
4528 <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>
4529 </td>
4530 </tr>
4531 <tr id="field-block-author-scanning">
4532 <th scope="row"><?php esc_html_e( 'Block Author Scanning', 'vigilante' ); ?></th>
4533 <td>
4534 <label>
4535 <input type="checkbox" name="user_security[block_author_scanning]" value="1" <?php checked( ! empty( $options['block_author_scanning'] ) ); ?>>
4536 <?php esc_html_e( 'Prevent username discovery via ?author=N URLs', 'vigilante' ); ?>
4537 </label>
4538 </td>
4539 </tr>
4540 <tr>
4541 <th scope="row"><?php esc_html_e( 'Display Name Protection', 'vigilante' ); ?></th>
4542 <td>
4543 <label>
4544 <input type="checkbox" name="user_security[prevent_display_name_login_match]" value="1" <?php checked( ! empty( $options['prevent_display_name_login_match'] ) ); ?>>
4545 <?php esc_html_e( 'Prevent users from saving a display name that matches their login username', 'vigilante' ); ?>
4546 </label>
4547 <p class="description"><?php esc_html_e( 'The display name is publicly visible and should not reveal the login username.', 'vigilante' ); ?></p>
4548 </td>
4549 </tr>
4550 </table>
4551 </div>
4552
4553 <!-- Admin Monitoring -->
4554 <div id="vigilante-section-users-admin-monitoring" class="vigilante-settings-section">
4555 <h2>
4556 <?php esc_html_e( 'Admin monitoring', 'vigilante' ); ?>
4557 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4558 </h2>
4559 <p><?php esc_html_e( 'Receive email alerts when administrator accounts are modified. All events are always logged to the Security Audit.', 'vigilante' ); ?></p>
4560
4561 <table class="form-table">
4562 <tr>
4563 <th scope="row"><?php esc_html_e( 'New Administrator Alert', 'vigilante' ); ?></th>
4564 <td>
4565 <label>
4566 <input type="checkbox" name="user_security[admin_monitoring][alert_new_admin]" value="1" <?php checked( ! empty( $monitoring['alert_new_admin'] ) ); ?>>
4567 <?php esc_html_e( 'Send email alert when a new administrator account is created', 'vigilante' ); ?>
4568 </label>
4569 </td>
4570 </tr>
4571 <tr>
4572 <th scope="row"><?php esc_html_e( 'Admin Email Change Alert', 'vigilante' ); ?></th>
4573 <td>
4574 <label>
4575 <input type="checkbox" name="user_security[admin_monitoring][alert_admin_email_change]" value="1" <?php checked( ! empty( $monitoring['alert_admin_email_change'] ) ); ?>>
4576 <?php esc_html_e( 'Send email alert when an administrator email address is changed', 'vigilante' ); ?>
4577 </label>
4578 </td>
4579 </tr>
4580 <tr>
4581 <th scope="row"><?php esc_html_e( 'Permission Elevation Alert', 'vigilante' ); ?></th>
4582 <td>
4583 <label>
4584 <input type="checkbox" name="user_security[admin_monitoring][alert_permission_elevation]" value="1" <?php checked( ! empty( $monitoring['alert_permission_elevation'] ) ); ?>>
4585 <?php esc_html_e( 'Send email alert when a user is elevated to administrator role', 'vigilante' ); ?>
4586 </label>
4587 </td>
4588 </tr>
4589 <tr>
4590 <th scope="row"><?php esc_html_e( 'Admin Password Change Alert', 'vigilante' ); ?></th>
4591 <td>
4592 <label>
4593 <input type="checkbox" name="user_security[admin_monitoring][alert_admin_password_change]" value="1" <?php checked( ! empty( $monitoring['alert_admin_password_change'] ) ); ?>>
4594 <?php esc_html_e( 'Send email alert when an administrator password is changed', 'vigilante' ); ?>
4595 </label>
4596 </td>
4597 </tr>
4598 </table>
4599
4600 <p class="description">
4601 <?php
4602 printf(
4603 /* translators: %s: Link to notification settings */
4604 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
4605 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
4606 );
4607 ?>
4608 </p>
4609 </div>
4610
4611 <!-- Registration Approval -->
4612 <div id="vigilante-section-users-registration" class="vigilante-settings-section">
4613 <h2>
4614 <?php esc_html_e( 'Registration approval', 'vigilante' ); ?>
4615 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4616 </h2>
4617 <p><?php esc_html_e( 'Require manual approval for new user registrations.', 'vigilante' ); ?></p>
4618
4619 <table class="form-table">
4620 <tr>
4621 <th scope="row"><?php esc_html_e( 'Enable Registration Approval', 'vigilante' ); ?></th>
4622 <td>
4623 <label>
4624 <input type="checkbox" name="user_security[registration_approval][enabled]" value="1" <?php checked( ! empty( $registration['enabled'] ) ); ?>>
4625 <?php esc_html_e( 'New users must be approved by an administrator before they can log in', 'vigilante' ); ?>
4626 </label>
4627 </td>
4628 </tr>
4629 <tr>
4630 <th scope="row"><?php esc_html_e( 'Notify Admin', 'vigilante' ); ?></th>
4631 <td>
4632 <label>
4633 <input type="checkbox" name="user_security[registration_approval][notify_admin]" value="1" <?php checked( ! empty( $registration['notify_admin'] ) ); ?>>
4634 <?php esc_html_e( 'Send email notification when a new user registers', 'vigilante' ); ?>
4635 </label>
4636 <p class="description"><?php esc_html_e( 'Disable on high-traffic sites to avoid email overload.', 'vigilante' ); ?></p>
4637 </td>
4638 </tr>
4639 <tr>
4640 <th scope="row"><label for="vigilante-f-user-security-registration-approval-auto-reject-days"><?php esc_html_e( 'Auto-reject After', 'vigilante' ); ?></label></th>
4641 <td>
4642 <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">
4643 <?php esc_html_e( 'days (0 = never)', 'vigilante' ); ?>
4644 <p class="description"><?php esc_html_e( 'Automatically reject pending registrations after this many days.', 'vigilante' ); ?></p>
4645 </td>
4646 </tr>
4647 </table>
4648 </div>
4649
4650 <!-- Session Limits -->
4651 <div id="vigilante-section-users-sessions" class="vigilante-settings-section">
4652 <h2>
4653 <?php esc_html_e( 'Session limits', 'vigilante' ); ?>
4654 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4655 </h2>
4656 <p><?php esc_html_e( 'Limit the number of simultaneous sessions per user.', 'vigilante' ); ?></p>
4657
4658 <table class="form-table">
4659 <tr>
4660 <th scope="row"><?php esc_html_e( 'Enable Session Limits', 'vigilante' ); ?></th>
4661 <td>
4662 <label>
4663 <input type="checkbox" name="user_security[session_limits][enabled]" value="1" <?php checked( ! empty( $session_limits['enabled'] ) ); ?>>
4664 <?php esc_html_e( 'Limit the number of active sessions per user', 'vigilante' ); ?>
4665 </label>
4666 </td>
4667 </tr>
4668 <tr>
4669 <th scope="row"><label for="vigilante-f-user-security-session-limits-max-sessions"><?php esc_html_e( 'Maximum Sessions', 'vigilante' ); ?></label></th>
4670 <td>
4671 <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">
4672 <?php esc_html_e( 'sessions per user', 'vigilante' ); ?>
4673 </td>
4674 </tr>
4675 <tr>
4676 <th scope="row"><label for="vigilante-f-user-security-session-limits-behavior"><?php esc_html_e( 'When Limit Exceeded', 'vigilante' ); ?></label></th>
4677 <td>
4678 <select id="vigilante-f-user-security-session-limits-behavior" name="user_security[session_limits][behavior]">
4679 <option value="block_new" <?php selected( ( $session_limits['behavior'] ?? 'close_oldest' ), 'block_new' ); ?>><?php esc_html_e( 'Block new login', 'vigilante' ); ?></option>
4680 <option value="close_oldest" <?php selected( ( $session_limits['behavior'] ?? 'close_oldest' ), 'close_oldest' ); ?>><?php esc_html_e( 'Close oldest session', 'vigilante' ); ?></option>
4681 </select>
4682 <p class="description"><?php esc_html_e( '"Close oldest" is recommended for security - ensures attackers cannot lock out legitimate users.', 'vigilante' ); ?></p>
4683 </td>
4684 </tr>
4685 <tr>
4686 <th scope="row"><?php esc_html_e( 'Exclude Administrators', 'vigilante' ); ?></th>
4687 <td>
4688 <label>
4689 <input type="checkbox" name="user_security[session_limits][exclude_admins]" value="1" <?php checked( ! empty( $session_limits['exclude_admins'] ) ); ?>>
4690 <?php esc_html_e( 'Do not apply session limits to administrators', 'vigilante' ); ?>
4691 </label>
4692 </td>
4693 </tr>
4694 </table>
4695 </div>
4696
4697 <!-- Password Expiration -->
4698 <div id="vigilante-section-users-password-exp" class="vigilante-settings-section">
4699 <h2>
4700 <?php esc_html_e( 'Password expiration', 'vigilante' ); ?>
4701 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4702 </h2>
4703 <p><?php esc_html_e( 'Force users to change their password periodically.', 'vigilante' ); ?></p>
4704
4705 <table class="form-table">
4706 <tr>
4707 <th scope="row"><?php esc_html_e( 'Enable Password Expiration', 'vigilante' ); ?></th>
4708 <td>
4709 <label>
4710 <input type="checkbox" name="user_security[password_expiration][enabled]" value="1" <?php checked( ! empty( $password_exp['enabled'] ) ); ?>>
4711 <?php esc_html_e( 'Force password change after a set number of days', 'vigilante' ); ?>
4712 </label>
4713 </td>
4714 </tr>
4715 <tr>
4716 <th scope="row"><label for="vigilante-f-user-security-password-expiration-expire-days"><?php esc_html_e( 'Expire After', 'vigilante' ); ?></label></th>
4717 <td>
4718 <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">
4719 <?php esc_html_e( 'days', 'vigilante' ); ?>
4720 <p class="description"><?php esc_html_e( 'PCI-DSS recommends 90 days.', 'vigilante' ); ?></p>
4721 </td>
4722 </tr>
4723 <tr>
4724 <th scope="row"><label for="vigilante-f-user-security-password-expiration-warning-days"><?php esc_html_e( 'Warning Period', 'vigilante' ); ?></label></th>
4725 <td>
4726 <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">
4727 <?php esc_html_e( 'days before expiration', 'vigilante' ); ?>
4728 <p class="description"><?php esc_html_e( 'Show warning notice this many days before password expires.', 'vigilante' ); ?></p>
4729 </td>
4730 </tr>
4731 <tr>
4732 <th scope="row"><label for="vigilante-f-user-security-password-expiration-password-history"><?php esc_html_e( 'Password History', 'vigilante' ); ?></label></th>
4733 <td>
4734 <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">
4735 <?php esc_html_e( 'passwords to remember', 'vigilante' ); ?>
4736 <p class="description"><?php esc_html_e( 'Prevent reusing recent passwords. Set to 0 to disable.', 'vigilante' ); ?></p>
4737 </td>
4738 </tr>
4739 <tr>
4740 <th scope="row"><?php esc_html_e( 'Email Reminder', 'vigilante' ); ?></th>
4741 <td>
4742 <label>
4743 <input type="checkbox" name="user_security[password_expiration][send_reminder]" value="1" <?php checked( ! empty( $password_exp['send_reminder'] ) ); ?>>
4744 <?php esc_html_e( 'Send email reminder when password is about to expire', 'vigilante' ); ?>
4745 </label>
4746 <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>
4747 </td>
4748 </tr>
4749 <tr>
4750 <th scope="row"><?php esc_html_e( 'Affected Roles', 'vigilante' ); ?></th>
4751 <td>
4752 <?php
4753 $affected_roles = $password_exp['affected_roles'] ?? array( 'administrator', 'editor' );
4754 $all_roles = wp_roles()->get_names();
4755 foreach ( $all_roles as $role_slug => $role_name ) :
4756 ?>
4757 <label style="display: block; margin-bottom: 5px;">
4758 <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 ) ); ?>>
4759 <?php echo esc_html( translate_user_role( $role_name ) ); ?>
4760 </label>
4761 <?php endforeach; ?>
4762 </td>
4763 </tr>
4764 <tr>
4765 <th scope="row"><?php esc_html_e( 'Exclude specific users', 'vigilante' ); ?></th>
4766 <td>
4767 <?php $pwexp_excluded = $password_exp['excluded_users'] ?? array(); ?>
4768 <div class="vigilante-2fa-user-search-container">
4769 <div class="vigilante-2fa-user-search">
4770 <span class="search-icon"></span>
4771 <input type="text"
4772 id="vigilante_pwexp_user_search"
4773 placeholder="<?php esc_attr_e( 'Search users by name or email...', 'vigilante' ); ?>"
4774 autocomplete="off">
4775 <div class="vigilante-pwexp-search-results"></div>
4776 </div>
4777 <div class="vigilante-pwexp-excluded-users">
4778 <?php
4779 foreach ( $pwexp_excluded as $pwexp_excluded_id ) :
4780 $excluded_user = get_user_by( 'ID', $pwexp_excluded_id );
4781 if ( ! $excluded_user ) {
4782 continue;
4783 }
4784 ?>
4785 <div class="vigilante-pwexp-excluded-user" data-user-id="<?php echo esc_attr( $pwexp_excluded_id ); ?>">
4786 <span class="user-display"><?php echo esc_html( $excluded_user->display_name . ' (' . $excluded_user->user_email . ')' ); ?></span>
4787 <button type="button" class="remove-user" aria-label="<?php esc_attr_e( 'Remove', 'vigilante' ); ?>">&times;</button>
4788 <input type="hidden" name="user_security[password_expiration][excluded_users][]" value="<?php echo esc_attr( $pwexp_excluded_id ); ?>">
4789 </div>
4790 <?php endforeach; ?>
4791 </div>
4792 </div>
4793 <p class="description"><?php esc_html_e( 'Listed users will be excluded from password expiration regardless of their role.', 'vigilante' ); ?></p>
4794 </td>
4795 </tr>
4796 </table>
4797 </div>
4798
4799 <!-- Email Verification -->
4800 <div id="vigilante-section-users-email-verify" class="vigilante-settings-section">
4801 <h2>
4802 <?php esc_html_e( 'Email verification', 'vigilante' ); ?>
4803 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4804 </h2>
4805 <p><?php esc_html_e( 'Require new users to verify their email address before logging in.', 'vigilante' ); ?></p>
4806
4807 <table class="form-table">
4808 <tr>
4809 <th scope="row"><?php esc_html_e( 'Enable Email Verification', 'vigilante' ); ?></th>
4810 <td>
4811 <label>
4812 <input type="checkbox" name="user_security[email_verification][enabled]" value="1" <?php checked( ! empty( $email_verify['enabled'] ) ); ?>>
4813 <?php esc_html_e( 'New users must verify their email before logging in', 'vigilante' ); ?>
4814 </label>
4815 </td>
4816 </tr>
4817 <tr>
4818 <th scope="row"><label for="vigilante-f-user-security-email-verification-token-expiry-hours"><?php esc_html_e( 'Link Expiration', 'vigilante' ); ?></label></th>
4819 <td>
4820 <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">
4821 <?php esc_html_e( 'hours', 'vigilante' ); ?>
4822 </td>
4823 </tr>
4824 <tr>
4825 <th scope="row"><?php esc_html_e( 'Allow Resend', 'vigilante' ); ?></th>
4826 <td>
4827 <label>
4828 <input type="checkbox" name="user_security[email_verification][allow_resend]" value="1" <?php checked( ! empty( $email_verify['allow_resend'] ) ); ?>>
4829 <?php esc_html_e( 'Allow users to request a new verification email', 'vigilante' ); ?>
4830 </label>
4831 </td>
4832 </tr>
4833 <tr>
4834 <th scope="row"><label for="vigilante-f-user-security-email-verification-auto-delete-days"><?php esc_html_e( 'Auto-delete Unverified', 'vigilante' ); ?></label></th>
4835 <td>
4836 <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">
4837 <?php esc_html_e( 'days (0 = never)', 'vigilante' ); ?>
4838 <p class="description"><?php esc_html_e( 'Automatically delete users who never verify their email.', 'vigilante' ); ?></p>
4839 </td>
4840 </tr>
4841 </table>
4842 </div>
4843
4844 <p class="submit vigilante-submit-buttons">
4845 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4846 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4847 </button>
4848 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4849 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4850 </button>
4851 </p>
4852 </form>
4853
4854 <!-- ============================================================
4855 TOOLS SECTION - Actions and utilities (no save button)
4856 ============================================================ -->
4857 <div class="vigilante-tools-section">
4858 <h2 class="vigilante-tools-header">
4859 <?php esc_html_e( 'User security tools', 'vigilante' ); ?>
4860 </h2>
4861
4862 <?php $this->render_user_actions_notice(); ?>
4863 <?php if ( ! $this->user_actions_locked() ) : ?>
4864
4865 <!-- Force Password Reset -->
4866 <div class="vigilante-tool-box">
4867 <h3><?php esc_html_e( 'Force password reset', 'vigilante' ); ?></h3>
4868 <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>
4869
4870 <!-- Reset Specific Users -->
4871 <div class="vigilante-password-reset-box">
4872 <h4><?php esc_html_e( 'Reset specific users', 'vigilante' ); ?></h4>
4873
4874 <div class="vigilante-user-search-wrapper">
4875 <input type="text" id="vigilante-password-reset-search" class="regular-text" placeholder="<?php esc_attr_e( 'Search by username, email, or display name...', 'vigilante' ); ?>">
4876 <div id="vigilante-password-reset-results" class="vigilante-user-search-results" style="display: none;"></div>
4877 </div>
4878
4879 <div id="vigilante-password-reset-selected" class="vigilante-selected-users" style="display: none;">
4880 <strong><?php esc_html_e( 'Selected Users:', 'vigilante' ); ?></strong>
4881 <ul class="vigilante-selected-users-list"></ul>
4882 </div>
4883
4884 <p class="description" style="margin-top: 15px;">
4885 <span class="dashicons dashicons-email-alt" style="color: #2271b1;"></span>
4886 <?php esc_html_e( 'Selected users will receive an email with a password reset link.', 'vigilante' ); ?>
4887 </p>
4888
4889 <p class="submit">
4890 <button type="button" id="vigilante-reset-selected-users" class="button button-primary" disabled>
4891 <?php esc_html_e( 'Force Reset for Selected Users', 'vigilante' ); ?>
4892 </button>
4893 </p>
4894 </div>
4895
4896 <!-- Reset by Role -->
4897 <div class="vigilante-password-reset-box" style="margin-top: 20px; padding-top: 20px; border-top: 1px solid #ddd;">
4898 <h4><?php esc_html_e( 'Reset by role', 'vigilante' ); ?></h4>
4899 <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>
4900
4901 <?php
4902 $wp_roles = wp_roles();
4903 $user_counts = count_users();
4904 $avail_roles = $user_counts['avail_roles'] ?? array();
4905 $current_user = wp_get_current_user();
4906 $current_roles = $current_user->roles;
4907 ?>
4908
4909 <fieldset class="vigilante-role-checkboxes" style="margin-top: 10px;">
4910 <?php foreach ( $wp_roles->roles as $role_slug => $role_data ) :
4911 $count = $avail_roles[ $role_slug ] ?? 0;
4912 if ( 0 === $count ) {
4913 continue;
4914 }
4915 $role_name = translate_user_role( $role_data['name'] );
4916 ?>
4917 <label style="display: block; margin-bottom: 6px;">
4918 <input type="checkbox"
4919 class="vigilante-reset-role-checkbox"
4920 value="<?php echo esc_attr( $role_slug ); ?>"
4921 data-count="<?php echo absint( $count ); ?>">
4922 <?php
4923 printf(
4924 /* translators: 1: Role name, 2: Number of users */
4925 '%1$s <span class="description">(%2$d)</span>',
4926 esc_html( $role_name ),
4927 absint( $count )
4928 );
4929 ?>
4930 <?php if ( in_array( $role_slug, $current_roles, true ) ) : ?>
4931 <em class="description"><?php esc_html_e( '(includes you)', 'vigilante' ); ?></em>
4932 <?php endif; ?>
4933 </label>
4934 <?php endforeach; ?>
4935 </fieldset>
4936
4937 <div id="vigilante-reset-role-summary" style="display: none; margin-top: 10px;">
4938 <p>
4939 <span class="dashicons dashicons-groups" style="color: #2271b1;"></span>
4940 <strong id="vigilante-reset-role-count">0</strong>
4941 <?php esc_html_e( 'user(s) will be affected.', 'vigilante' ); ?>
4942 </p>
4943 </div>
4944
4945 <div class="vigilante-password-reset-options" id="vigilante-reset-role-self-option" style="display: none; margin-top: 10px;">
4946 <label>
4947 <input type="checkbox" id="vigilante-reset-role-include-self" value="1">
4948 <?php esc_html_e( 'Include myself (your current session will end)', 'vigilante' ); ?>
4949 </label>
4950 </div>
4951
4952 <p class="submit">
4953 <button type="button" id="vigilante-reset-by-role" class="button button-primary" disabled>
4954 <?php esc_html_e( 'Force Reset for Selected Roles', 'vigilante' ); ?>
4955 </button>
4956 </p>
4957 </div>
4958
4959 <!-- Reset All Users -->
4960 <div class="vigilante-password-reset-box" style="margin-top: 20px; padding-top: 20px; border-top: 1px solid #ddd;">
4961 <h4><?php esc_html_e( 'Reset all users', 'vigilante' ); ?></h4>
4962
4963 <?php
4964 $total_users = count_users();
4965 $total_count = $total_users['total_users'];
4966 ?>
4967 <p>
4968 <?php
4969 printf(
4970 /* translators: %d: Number of users */
4971 esc_html__( 'This will affect %d user(s).', 'vigilante' ),
4972 absint( $total_count )
4973 );
4974 ?>
4975 </p>
4976
4977 <p class="description" style="color: #d63638;">
4978 <span class="dashicons dashicons-warning"></span>
4979 <?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' ); ?>
4980 </p>
4981
4982 <div class="vigilante-password-reset-options" style="margin-top: 10px;">
4983 <label>
4984 <input type="checkbox" id="vigilante-reset-all-include-self" value="1">
4985 <?php esc_html_e( 'Include myself (your current session will end)', 'vigilante' ); ?>
4986 </label>
4987 </div>
4988
4989 <p class="submit">
4990 <button type="button" id="vigilante-reset-all-users" class="button" style="color: #d63638; border-color: #d63638;">
4991 <?php esc_html_e( 'Force Reset for ALL Users', 'vigilante' ); ?>
4992 </button>
4993 </p>
4994 </div>
4995 </div>
4996
4997 <!-- Pending Registrations -->
4998 <?php
4999 $user_security = new Vigilante_User_Security( $this->settings, $this->activity_log );
5000 $pending_users = $user_security->get_pending_users();
5001 ?>
5002 <div id="vigilante-section-users-pending" class="vigilante-tool-box vigilante-pending-users-section">
5003 <h3>
5004 <?php esc_html_e( 'Pending registrations', 'vigilante' ); ?>
5005 <?php if ( count( $pending_users ) > 0 ) : ?>
5006 <span class="vigilante-badge vigilante-badge-warning"><?php echo esc_html( count( $pending_users ) ); ?></span>
5007 <?php endif; ?>
5008 </h3>
5009
5010 <?php if ( empty( $registration['enabled'] ) ) : ?>
5011 <p class="description">
5012 <span class="dashicons dashicons-info" style="color: #72aee6;"></span>
5013 <?php esc_html_e( 'Registration approval is disabled. Enable it in the settings above to require manual approval for new users.', 'vigilante' ); ?>
5014 </p>
5015 <?php elseif ( empty( $pending_users ) ) : ?>
5016 <div class="vigilante-no-lockouts">
5017 <span class="dashicons dashicons-yes-alt"></span>
5018 <p><?php esc_html_e( 'No pending registrations.', 'vigilante' ); ?></p>
5019 </div>
5020 <?php else : ?>
5021 <table class="wp-list-table widefat fixed striped vigilante-pending-users-table">
5022 <thead>
5023 <tr>
5024 <th><?php esc_html_e( 'User', 'vigilante' ); ?></th>
5025 <th><?php esc_html_e( 'Email', 'vigilante' ); ?></th>
5026 <th><?php esc_html_e( 'Registered', 'vigilante' ); ?></th>
5027 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5028 </tr>
5029 </thead>
5030 <tbody>
5031 <?php foreach ( $pending_users as $pending_user ) :
5032 $pending_since = get_user_meta( $pending_user->ID, 'vigilante_pending_since', true );
5033 ?>
5034 <tr data-user-id="<?php echo esc_attr( $pending_user->ID ); ?>">
5035 <td>
5036 <?php echo get_avatar( $pending_user->ID, 32 ); ?>
5037 <strong><?php echo esc_html( $pending_user->user_login ); ?></strong>
5038 </td>
5039 <td><?php echo esc_html( $pending_user->user_email ); ?></td>
5040 <td>
5041 <?php
5042 if ( $pending_since ) {
5043 /* translators: %s: Time ago */
5044 printf( esc_html__( '%s ago', 'vigilante' ), esc_html( human_time_diff( $pending_since ) ) );
5045 } else {
5046 echo esc_html( $pending_user->user_registered );
5047 }
5048 ?>
5049 </td>
5050 <td>
5051 <button type="button" class="button button-small vigilante-approve-user" data-user-id="<?php echo esc_attr( $pending_user->ID ); ?>">
5052 <?php esc_html_e( 'Approve', 'vigilante' ); ?>
5053 </button>
5054 <button type="button" class="button button-small vigilante-reject-user" data-user-id="<?php echo esc_attr( $pending_user->ID ); ?>" style="color: #d63638;">
5055 <?php esc_html_e( 'Reject', 'vigilante' ); ?>
5056 </button>
5057 </td>
5058 </tr>
5059 <?php endforeach; ?>
5060 </tbody>
5061 </table>
5062 <?php endif; ?>
5063 </div>
5064
5065 <!-- Active Sessions Management -->
5066 <div class="vigilante-tool-box vigilante-session-management-section">
5067 <h3><?php esc_html_e( 'Active sessions', 'vigilante' ); ?></h3>
5068 <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>
5069
5070 <!-- Current user sessions -->
5071 <h4><?php esc_html_e( 'Your sessions', 'vigilante' ); ?></h4>
5072 <?php
5073 $current_user_id = get_current_user_id();
5074 $my_sessions = $user_security->get_user_sessions( $current_user_id );
5075 $has_corrupted = $user_security->has_corrupted_sessions( $current_user_id );
5076 $raw_count = $user_security->get_raw_session_count( $current_user_id );
5077 ?>
5078
5079 <?php if ( $has_corrupted && $raw_count > 0 ) : ?>
5080 <div class="notice notice-warning inline" style="margin: 10px 0;">
5081 <p>
5082 <span class="dashicons dashicons-warning" style="color: #dba617;"></span>
5083 <?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' ); ?>
5084 </p>
5085 </div>
5086 <?php endif; ?>
5087
5088 <?php if ( empty( $my_sessions ) ) : ?>
5089 <p class="description"><?php esc_html_e( 'No active sessions found.', 'vigilante' ); ?></p>
5090 <?php if ( $has_corrupted ) : ?>
5091 <p style="margin-top: 10px;">
5092 <button type="button" class="button vigilante-revoke-other-sessions" data-user-id="<?php echo esc_attr( $current_user_id ); ?>">
5093 <?php esc_html_e( 'Clean Up Corrupted Sessions', 'vigilante' ); ?>
5094 </button>
5095 </p>
5096 <?php endif; ?>
5097 <?php else : ?>
5098 <div class="vigilante-paginated-section">
5099 <div class="vigilante-fi-pagination-wrap"></div>
5100 <table class="wp-list-table widefat fixed striped vigilante-sessions-table vigilante-fi-paginated">
5101 <thead>
5102 <tr>
5103 <th><?php esc_html_e( 'Browser', 'vigilante' ); ?></th>
5104 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
5105 <th><?php esc_html_e( 'Login Time', 'vigilante' ); ?></th>
5106 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5107 </tr>
5108 </thead>
5109 <tbody>
5110 <?php foreach ( $my_sessions as $session ) : ?>
5111 <tr data-token="<?php echo esc_attr( $session['token_hash'] ); ?>">
5112 <td><?php echo esc_html( $session['browser'] ); ?></td>
5113 <td><code><?php echo esc_html( $session['ip'] ); ?></code></td>
5114 <td>
5115 <?php
5116 if ( $session['login'] ) {
5117 /* translators: %s: Time ago */
5118 printf( esc_html__( '%s ago', 'vigilante' ), esc_html( human_time_diff( $session['login'] ) ) );
5119 } else {
5120 esc_html_e( 'Unknown', 'vigilante' );
5121 }
5122 ?>
5123 </td>
5124 <td>
5125 <?php if ( ! $session['is_current'] ) : ?>
5126 <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'] ); ?>">
5127 <?php esc_html_e( 'Revoke', 'vigilante' ); ?>
5128 </button>
5129 <?php else : ?>
5130 <span class="description"><?php esc_html_e( 'Current session', 'vigilante' ); ?></span>
5131 <?php endif; ?>
5132 </td>
5133 </tr>
5134 <?php endforeach; ?>
5135 </tbody>
5136 </table>
5137 </div>
5138
5139 <?php if ( count( $my_sessions ) > 1 || $has_corrupted ) : ?>
5140 <p style="margin-top: 10px;">
5141 <button type="button" class="button vigilante-revoke-other-sessions" data-user-id="<?php echo esc_attr( $current_user_id ); ?>">
5142 <?php esc_html_e( 'Revoke All Other Sessions', 'vigilante' ); ?>
5143 </button>
5144 </p>
5145 <?php endif; ?>
5146 <?php endif; ?>
5147
5148 <!-- Search user sessions (admin only) -->
5149 <h4 style="margin-top: 30px;"><?php esc_html_e( 'Manage user sessions', 'vigilante' ); ?></h4>
5150 <p class="description"><?php esc_html_e( 'Search for a user to view and manage their sessions.', 'vigilante' ); ?></p>
5151
5152 <div class="vigilante-user-search-wrapper" style="margin-top: 10px;">
5153 <input type="text" id="vigilante-session-user-search" class="regular-text" placeholder="<?php esc_attr_e( 'Search by username or email...', 'vigilante' ); ?>">
5154 <div id="vigilante-session-search-results" class="vigilante-user-search-results" style="display: none;"></div>
5155 </div>
5156
5157 <div id="vigilante-user-sessions-container" style="display: none; margin-top: 20px;">
5158 <h4 id="vigilante-sessions-user-name"></h4>
5159 <table class="wp-list-table widefat fixed striped vigilante-sessions-table">
5160 <thead>
5161 <tr>
5162 <th><?php esc_html_e( 'Browser', 'vigilante' ); ?></th>
5163 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
5164 <th><?php esc_html_e( 'Login Time', 'vigilante' ); ?></th>
5165 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5166 </tr>
5167 </thead>
5168 <tbody id="vigilante-user-sessions-list">
5169 </tbody>
5170 </table>
5171 <p style="margin-top: 10px;">
5172 <button type="button" class="button vigilante-revoke-all-user-sessions" style="color: #d63638;">
5173 <?php esc_html_e( 'Revoke All Sessions', 'vigilante' ); ?>
5174 </button>
5175 </p>
5176 </div>
5177 </div>
5178
5179 <?php endif; ?>
5180 </div>
5181 <?php
5182 }
5183
5184 /**
5185 * Render WordPress Hardening tab
5186 */
5187 private function render_tab_wp_hardening() {
5188 $is_disabled = $this->render_module_disabled_notice( 'wp_hardening' );
5189 $options = $this->settings->get_section( 'wp_hardening' );
5190 ?>
5191 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="wp_hardening" <?php echo $is_disabled ? 'inert' : ''; ?>>
5192 <!-- Database Hardening (outside form save flow - uses its own AJAX action) -->
5193 <?php $vg_shared_locked = $this->shared_files_locked(); ?>
5194 <?php $this->render_shared_files_notice(); ?>
5195 <div id="vigilante-section-hardening-database" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
5196 <h2>
5197 <?php esc_html_e( 'Database Hardening', 'vigilante' ); ?>
5198 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
5199 <span class="vigilante-method-badge config"><?php esc_html_e( 'WP-CONFIG', 'vigilante' ); ?></span>
5200 </h2>
5201 <p><?php esc_html_e( 'Change the database table prefix to prevent SQL injection attacks that target default WordPress tables.', 'vigilante' ); ?></p>
5202
5203 <?php
5204 $db_prefix = new Vigilante_Database_Prefix();
5205 $current_prefix = $db_prefix->get_current_prefix();
5206 $is_default = $db_prefix->is_default_prefix();
5207 ?>
5208
5209 <?php if ( is_multisite() && ! $vg_shared_locked ) : ?>
5210 <div class="notice notice-warning inline" style="margin:10px 0 16px;padding:8px 12px;">
5211 <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>
5212 </div>
5213 <?php endif; ?>
5214
5215 <table class="form-table">
5216 <tr>
5217 <th scope="row"><?php esc_html_e( 'Current prefix', 'vigilante' ); ?></th>
5218 <td>
5219 <code class="vigilante-db-current-prefix"><?php echo esc_html( $current_prefix ); ?></code>
5220 <?php if ( $is_default ) : ?>
5221 <span class="vigilante-inline-warning">
5222 <span class="dashicons dashicons-warning"></span>
5223 <?php esc_html_e( 'Default prefix detected. Changing it adds a layer of protection against automated SQL injection attacks.', 'vigilante' ); ?>
5224 </span>
5225 <?php else : ?>
5226 <span class="vigilante-inline-ok">
5227 <span class="dashicons dashicons-yes-alt"></span>
5228 <?php esc_html_e( 'Custom prefix in use.', 'vigilante' ); ?>
5229 </span>
5230 <?php endif; ?>
5231 </td>
5232 </tr>
5233 <tr>
5234 <th scope="row"><?php esc_html_e( 'New prefix', 'vigilante' ); ?></th>
5235 <td>
5236 <div class="vigilante-db-prefix-row">
5237 <code class="vigilante-db-new-prefix" id="vigilante-new-prefix"><?php echo esc_html( $db_prefix->generate_prefix() ); ?></code>
5238 <button type="button" class="button button-small vigilante-db-regenerate-prefix" title="<?php esc_attr_e( 'Generate new prefix', 'vigilante' ); ?>">
5239 <span class="dashicons dashicons-update"></span>
5240 </button>
5241 </div>
5242 </td>
5243 </tr>
5244 <tr>
5245 <th scope="row"></th>
5246 <td>
5247 <div class="vigilante-db-prefix-confirm">
5248 <label>
5249 <input type="checkbox" id="vigilante-prefix-backup-confirm">
5250 <?php esc_html_e( 'I understand this operation is irreversible and I have a current database backup', 'vigilante' ); ?>
5251 </label>
5252 <p class="description">
5253 <?php
5254 printf(
5255 /* translators: %s: Link to tools tab */
5256 esc_html__( 'Need a backup? %s first.', 'vigilante' ),
5257 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Download a database backup', 'vigilante' ) . '</a>'
5258 );
5259 ?>
5260 </p>
5261 </div>
5262 <button type="button" class="button button-primary vigilante-db-change-prefix" disabled data-original-text="<?php esc_attr_e( 'Change Database Prefix', 'vigilante' ); ?>">
5263 <?php esc_html_e( 'Change Database Prefix', 'vigilante' ); ?>
5264 </button>
5265 </td>
5266 </tr>
5267 </table>
5268 </div>
5269
5270 <!-- wp-config Security -->
5271 <?php
5272 $vg_shared_locked = $this->shared_files_locked();
5273 // Paint what is actually in force, not this site's unused copy.
5274 $vg_local_options = $options;
5275 $options = $this->get_section_for_display( 'wp_hardening' );
5276 ?>
5277 <?php $this->render_shared_files_notice(); ?>
5278 <div id="vigilante-section-hardening-wpconfig" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
5279 <h2>
5280 <?php esc_html_e( 'wp-config.php Security', 'vigilante' ); ?>
5281 <span class="vigilante-method-badge config"><?php esc_html_e( 'WP-CONFIG', 'vigilante' ); ?></span>
5282 </h2>
5283 <p><?php esc_html_e( 'Security constants added directly to wp-config.php file.', 'vigilante' ); ?></p>
5284
5285 <table class="form-table">
5286 <tr>
5287 <th scope="row"><?php esc_html_e( 'Disable File Editor', 'vigilante' ); ?></th>
5288 <td>
5289 <label>
5290 <input type="checkbox" name="wp_hardening[disallow_file_edit]" value="1" <?php checked( ! empty( $options['disallow_file_edit'] ) ); ?>>
5291 <?php esc_html_e( 'Disable plugin and theme editor in admin (DISALLOW_FILE_EDIT)', 'vigilante' ); ?>
5292 </label>
5293 </td>
5294 </tr>
5295 <tr>
5296 <th scope="row"><?php esc_html_e( 'Disable File Modifications', 'vigilante' ); ?></th>
5297 <td>
5298 <label>
5299 <input type="checkbox" name="wp_hardening[disallow_file_mods]" value="1" <?php checked( ! empty( $options['disallow_file_mods'] ) ); ?>>
5300 <?php esc_html_e( 'Disable all file modifications including updates (DISALLOW_FILE_MODS)', 'vigilante' ); ?>
5301 </label>
5302 <p class="description"><?php esc_html_e( '&#9888; Warning: This prevents automatic updates.', 'vigilante' ); ?></p>
5303 </td>
5304 </tr>
5305 <tr id="field-force-ssl-admin">
5306 <th scope="row"><?php esc_html_e( 'Force SSL Admin', 'vigilante' ); ?></th>
5307 <td>
5308 <label>
5309 <input type="checkbox" name="wp_hardening[force_ssl_admin]" value="1" <?php checked( ! empty( $options['force_ssl_admin'] ) ); ?>>
5310 <?php esc_html_e( 'Force HTTPS for admin area (FORCE_SSL_ADMIN)', 'vigilante' ); ?>
5311 </label>
5312 <p class="description"><?php esc_html_e( '&#9888; Warning: Only enable if your site fully supports HTTPS.', 'vigilante' ); ?></p>
5313 </td>
5314 </tr>
5315 <tr id="field-wp-debug">
5316 <th scope="row"><?php esc_html_e( 'Hide PHP errors from visitors', 'vigilante' ); ?></th>
5317 <td>
5318 <label>
5319 <input type="checkbox" name="wp_hardening[wp_debug]" value="1" <?php checked( ! empty( $options['wp_debug'] ) ); ?>>
5320 <?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' ); ?>
5321 </label>
5322 </td>
5323 </tr>
5324 <tr id="field-disable-wp-cron">
5325 <th scope="row"><?php esc_html_e( 'Disable WP Cron', 'vigilante' ); ?></th>
5326 <td>
5327 <label>
5328 <input type="checkbox" name="wp_hardening[disable_wp_cron]" value="1" <?php checked( ! empty( $options['disable_wp_cron'] ) ); ?>>
5329 <?php esc_html_e( 'Disable WordPress\'s page-view cron trigger (DISABLE_WP_CRON)', 'vigilante' ); ?>
5330 </label>
5331 <p class="description"><?php
5332 printf(
5333 /* translators: 1: opening <strong>, 2: closing </strong>, 3: opening <code>, 4: closing </code> */
5334 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' ),
5335 '<strong>',
5336 '</strong>',
5337 '<code>',
5338 '</code>'
5339 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
5340 ?></p>
5341 </td>
5342 </tr>
5343 </table>
5344 </div>
5345 <?php $options = $vg_local_options; ?>
5346
5347 <!-- Comment Security -->
5348 <div id="vigilante-section-hardening-xmlrpc" class="vigilante-settings-section">
5349 <h2>
5350 <?php esc_html_e( 'XML-RPC', 'vigilante' ); ?>
5351 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5352 </h2>
5353 <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>
5354
5355 <table class="form-table">
5356 <tr id="field-disable-xmlrpc">
5357 <th scope="row"><label for="vigilante-f-wp-hardening-xmlrpc-mode"><?php esc_html_e( 'XML-RPC access', 'vigilante' ); ?></label></th>
5358 <td>
5359 <?php $vig_xmlrpc_mode = Vigilante_Comment_Security::resolve_xmlrpc_mode( $this->settings ); ?>
5360 <select id="vigilante-f-wp-hardening-xmlrpc-mode" name="wp_hardening[xmlrpc_mode]">
5361 <option value="none" <?php selected( $vig_xmlrpc_mode, 'none' ); ?>>
5362 <?php esc_html_e( 'Leave XML-RPC enabled', 'vigilante' ); ?>
5363 </option>
5364 <option value="pingback" <?php selected( $vig_xmlrpc_mode, 'pingback' ); ?>>
5365 <?php esc_html_e( 'Block the pingback methods only', 'vigilante' ); ?>
5366 </option>
5367 <option value="full" <?php selected( $vig_xmlrpc_mode, 'full' ); ?>>
5368 <?php esc_html_e( 'Disable XML-RPC completely (recommended)', 'vigilante' ); ?>
5369 </option>
5370 </select>
5371 <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>
5372 </td>
5373 </tr>
5374 </table>
5375 </div>
5376
5377 <div id="vigilante-section-hardening-comments" class="vigilante-settings-section">
5378 <h2>
5379 <?php esc_html_e( 'Comment Security', 'vigilante' ); ?>
5380 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5381 <span class="vigilante-method-badge settings"><?php esc_html_e( 'Settings', 'vigilante' ); ?></span>
5382 </h2>
5383 <p><?php esc_html_e( 'Comment protection using WordPress settings and PHP hooks.', 'vigilante' ); ?></p>
5384
5385 <table class="form-table">
5386 <tr>
5387 <th scope="row"><?php esc_html_e( 'Disable Pingbacks', 'vigilante' ); ?></th>
5388 <td>
5389 <label>
5390 <input type="checkbox" name="wp_hardening[disable_pingbacks]" value="1" <?php checked( ! empty( $options['disable_pingbacks'] ) ); ?>>
5391 <?php esc_html_e( 'Disable pingbacks (commonly exploited for DDoS)', 'vigilante' ); ?>
5392 </label>
5393 </td>
5394 </tr>
5395 <tr>
5396 <th scope="row"><?php esc_html_e( 'Disable Trackbacks', 'vigilante' ); ?></th>
5397 <td>
5398 <label>
5399 <input type="checkbox" name="wp_hardening[disable_trackbacks]" value="1" <?php checked( ! empty( $options['disable_trackbacks'] ) ); ?>>
5400 <?php esc_html_e( 'Disable trackbacks (rarely used legitimately)', 'vigilante' ); ?>
5401 </label>
5402 </td>
5403 </tr>
5404 <tr>
5405 <th scope="row"><?php esc_html_e( 'Require Moderation', 'vigilante' ); ?></th>
5406 <td>
5407 <label>
5408 <input type="checkbox" name="wp_hardening[require_comment_moderation]" value="1" <?php checked( ! empty( $options['require_comment_moderation'] ) ); ?>>
5409 <?php esc_html_e( 'All comments must be manually approved', 'vigilante' ); ?>
5410 </label>
5411 </td>
5412 </tr>
5413 <tr>
5414 <th scope="row"><?php esc_html_e( 'Close Old Comments', 'vigilante' ); ?></th>
5415 <td>
5416 <label>
5417 <input type="checkbox" name="wp_hardening[close_old_comments]" value="1" <?php checked( ! empty( $options['close_old_comments'] ) ); ?>>
5418 <?php esc_html_e( 'Automatically close comments on old posts after', 'vigilante' ); ?>
5419 </label>
5420 <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">
5421 <label for="vigilante-f-wp-hardening-close-comments-after-days"><?php esc_html_e( 'days', 'vigilante' ); ?></label>
5422 </td>
5423 </tr>
5424 <tr>
5425 <th scope="row"><?php esc_html_e( 'Honeypot Protection', 'vigilante' ); ?></th>
5426 <td>
5427 <label>
5428 <input type="checkbox" name="wp_hardening[honeypot_comments]" value="1" <?php checked( ! empty( $options['honeypot_comments'] ) ); ?>>
5429 <?php esc_html_e( 'Add hidden honeypot field to catch bots', 'vigilante' ); ?>
5430 </label>
5431 </td>
5432 </tr>
5433 </table>
5434 </div>
5435
5436 <!-- Head Cleaner -->
5437 <div id="vigilante-section-hardening-headers" class="vigilante-settings-section">
5438 <h2>
5439 <?php esc_html_e( 'Header Cleanup', 'vigilante' ); ?>
5440 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5441 </h2>
5442 <p><?php esc_html_e( 'Remove meta tags from HTML head.', 'vigilante' ); ?></p>
5443
5444 <table class="form-table">
5445 <tr>
5446 <th scope="row"><?php esc_html_e( 'Remove Generator', 'vigilante' ); ?></th>
5447 <td>
5448 <label>
5449 <input type="checkbox" name="wp_hardening[remove_wp_generator]" value="1" <?php checked( ! empty( $options['remove_wp_generator'] ) ); ?>>
5450 <?php esc_html_e( 'Remove WordPress version from HTML head', 'vigilante' ); ?>
5451 </label>
5452 </td>
5453 </tr>
5454 <tr id="field-remove-wp-version-assets">
5455 <th scope="row"><?php esc_html_e( 'Remove version from assets', 'vigilante' ); ?></th>
5456 <td>
5457 <label>
5458 <input type="checkbox" name="wp_hardening[remove_wp_version_assets]" value="1" <?php checked( ! empty( $options['remove_wp_version_assets'] ) ); ?>>
5459 <?php esc_html_e( 'Remove WordPress version from script/style URLs (?ver=)', 'vigilante' ); ?>
5460 </label>
5461 <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>
5462 </td>
5463 </tr>
5464 <tr>
5465 <th scope="row"><?php esc_html_e( 'Remove RSD Link', 'vigilante' ); ?></th>
5466 <td>
5467 <label>
5468 <input type="checkbox" name="wp_hardening[remove_rsd_link]" value="1" <?php checked( ! empty( $options['remove_rsd_link'] ) ); ?>>
5469 <?php esc_html_e( 'Remove Really Simple Discovery link', 'vigilante' ); ?>
5470 </label>
5471 </td>
5472 </tr>
5473 <tr>
5474 <th scope="row"><?php esc_html_e( 'Remove WLW Manifest', 'vigilante' ); ?></th>
5475 <td>
5476 <label>
5477 <input type="checkbox" name="wp_hardening[remove_wlw_manifest]" value="1" <?php checked( ! empty( $options['remove_wlw_manifest'] ) ); ?>>
5478 <?php esc_html_e( 'Remove Windows Live Writer manifest link', 'vigilante' ); ?>
5479 </label>
5480 </td>
5481 </tr>
5482 <tr>
5483 <th scope="row"><?php esc_html_e( 'Remove Shortlink', 'vigilante' ); ?></th>
5484 <td>
5485 <label>
5486 <input type="checkbox" name="wp_hardening[remove_shortlink]" value="1" <?php checked( ! empty( $options['remove_shortlink'] ) ); ?>>
5487 <?php esc_html_e( 'Remove shortlink tag from header', 'vigilante' ); ?>
5488 </label>
5489 </td>
5490 </tr>
5491 <tr>
5492 <th scope="row"><?php esc_html_e( 'Remove REST API Link', 'vigilante' ); ?></th>
5493 <td>
5494 <label>
5495 <input type="checkbox" name="wp_hardening[remove_rest_api_link]" value="1" <?php checked( ! empty( $options['remove_rest_api_link'] ) ); ?>>
5496 <?php esc_html_e( 'Remove REST API discovery link from header', 'vigilante' ); ?>
5497 </label>
5498 <p class="description"><?php esc_html_e( '&#9888; Notice: Some plugins may need this link.', 'vigilante' ); ?></p>
5499 </td>
5500 </tr>
5501 </table>
5502 </div>
5503
5504 <!-- Feed Manager -->
5505 <div id="vigilante-section-hardening-rss" class="vigilante-settings-section">
5506 <h2>
5507 <?php esc_html_e( 'RSS Feed Settings', 'vigilante' ); ?>
5508 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5509 </h2>
5510 <p><?php esc_html_e( 'Control RSS/Atom feeds.', 'vigilante' ); ?></p>
5511
5512 <table class="form-table">
5513 <tr>
5514 <th scope="row"><?php esc_html_e( 'Disable Feeds', 'vigilante' ); ?></th>
5515 <td>
5516 <label>
5517 <input type="checkbox" name="wp_hardening[disable_feeds]" value="1" <?php checked( ! empty( $options['disable_feeds'] ) ); ?>>
5518 <?php esc_html_e( 'Completely disable RSS/Atom feeds', 'vigilante' ); ?>
5519 </label>
5520 </td>
5521 </tr>
5522 <tr>
5523 <th scope="row"><?php esc_html_e( 'Disable If No Content', 'vigilante' ); ?></th>
5524 <td>
5525 <label>
5526 <input type="checkbox" name="wp_hardening[disable_if_no_content]" value="1" <?php checked( ! empty( $options['disable_if_no_content'] ) ); ?>>
5527 <?php esc_html_e( 'Only disable feeds if site has no published posts', 'vigilante' ); ?>
5528 </label>
5529 </td>
5530 </tr>
5531 <tr>
5532 <th scope="row"><?php esc_html_e( 'Remove Feed Version', 'vigilante' ); ?></th>
5533 <td>
5534 <label>
5535 <input type="checkbox" name="wp_hardening[remove_feed_version]" value="1" <?php checked( ! empty( $options['remove_feed_version'] ) ); ?>>
5536 <?php esc_html_e( 'Remove WordPress version from feed generator tag', 'vigilante' ); ?>
5537 </label>
5538 </td>
5539 </tr>
5540 </table>
5541 </div>
5542
5543 <p class="submit vigilante-submit-buttons">
5544 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5545 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5546 </button>
5547 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5548 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5549 </button>
5550 </p>
5551 </form>
5552 <?php
5553 }
5554
5555 /**
5556 * Render activity log tab
5557 */
5558 private function render_tab_activity_log() {
5559 $is_disabled = $this->render_module_disabled_notice( 'activity_log' );
5560 $options = $this->settings->get_section( 'activity_log' );
5561 ?>
5562 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="activity_log" <?php echo $is_disabled ? 'inert' : ''; ?>>
5563 <div id="vigilante-section-audit-settings" class="vigilante-settings-section">
5564 <h2>
5565 <?php esc_html_e( 'Security Audit Settings', 'vigilante' ); ?>
5566 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5567 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
5568 </h2>
5569 <p><?php esc_html_e( 'Security event logging and auditing.', 'vigilante' ); ?></p>
5570
5571 <table class="form-table">
5572 <tr>
5573 <th scope="row"><?php esc_html_e( 'Retention', 'vigilante' ); ?></th>
5574 <td>
5575 <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">
5576 <label for="vigilante-f-activity-log-retention-days"><?php esc_html_e( 'days', 'vigilante' ); ?></label>
5577 &nbsp;&nbsp;
5578 <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">
5579 <label for="vigilante-f-activity-log-max-entries"><?php esc_html_e( 'max entries', 'vigilante' ); ?></label>
5580 <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>
5581 </td>
5582 </tr>
5583 <tr>
5584 <th scope="row"><?php esc_html_e( 'Events to Log', 'vigilante' ); ?></th>
5585 <td>
5586 <fieldset style="display:grid; grid-template-columns:repeat(auto-fit, minmax(240px, 1fr)); gap:6px 24px; max-width:600px;">
5587 <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>
5588 <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>
5589 <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>
5590 <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>
5591 <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>
5592 <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>
5593 <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>
5594 <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>
5595 <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>
5596 <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>
5597 </fieldset>
5598 <div class="notice notice-info inline" style="margin:10px 0 0;padding:8px 12px;">
5599 <p style="margin:0;">
5600 <?php esc_html_e( 'Firewall blocks, security events, and Vigilant settings changes are always logged regardless of the above selections.', 'vigilante' ); ?>
5601 </p>
5602 </div>
5603 </td>
5604 </tr>
5605 <tr>
5606 <th scope="row"><label for="vigilante-f-activity-log-tracked-options"><?php esc_html_e( 'Option Tracking', 'vigilante' ); ?></label></th>
5607 <td>
5608 <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>
5609 <br>
5610 <label><?php esc_html_e( 'Additional options to track:', 'vigilante' ); ?></label><br>
5611 <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>
5612 <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>
5613 </td>
5614 </tr>
5615 <tr>
5616 <th scope="row"><?php esc_html_e( 'Exclusions', 'vigilante' ); ?></th>
5617 <td>
5618 <div style="display:grid; grid-template-columns:repeat(auto-fit, minmax(220px, 1fr)); gap:16px; max-width:600px;">
5619 <div>
5620 <label for="vigilante-f-activity-log-excluded-users"><?php esc_html_e( 'Excluded user IDs:', 'vigilante' ); ?></label><br>
5621 <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>
5622 <p class="description"><?php esc_html_e( 'One user ID per line. Actions by these users will not be logged.', 'vigilante' ); ?></p>
5623 </div>
5624 <div>
5625 <label for="vigilante-f-activity-log-excluded-ips"><?php esc_html_e( 'Excluded IPs:', 'vigilante' ); ?></label><br>
5626 <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>
5627 <p class="description"><?php esc_html_e( 'One IP per line. Requests from these IPs will not be logged.', 'vigilante' ); ?></p>
5628 </div>
5629 </div>
5630 </td>
5631 </tr>
5632 </table>
5633 </div>
5634
5635 <p class="submit vigilante-submit-buttons">
5636 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5637 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5638 </button>
5639 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5640 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5641 </button>
5642 </p>
5643 </form>
5644
5645 <?php
5646 // Audit Alerts — alerting layer on top of Security Audit. Its own
5647 // settings section and form, rendered right after the logging settings
5648 // so the tab reads as "log this, exclude that, and alert me about this".
5649 $alerts = $this->settings->get_section( 'audit_alerts' );
5650 $immediate = isset( $alerts['immediate'] ) ? $alerts['immediate'] : array();
5651 $threshold = isset( $alerts['threshold'] ) ? $alerts['threshold'] : array();
5652 $alert_severity = isset( $immediate['min_severity'] ) ? $immediate['min_severity'] : 'critical';
5653 $alert_window = isset( $threshold['window'] ) ? $threshold['window'] : '1h';
5654 $threshold_cats = isset( $threshold['categories'] ) ? (array) $threshold['categories'] : array();
5655 $cat_labels = Vigilante_Audit_Alerts::category_labels();
5656 ?>
5657 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="audit_alerts" <?php echo $is_disabled ? 'inert' : ''; ?>>
5658 <div id="vigilante-section-audit-alerts" class="vigilante-settings-section">
5659 <h2>
5660 <?php esc_html_e( 'Audit Alerts', 'vigilante' ); ?>
5661 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5662 </h2>
5663 <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>
5664
5665 <table class="form-table">
5666 <tr id="field-audit-alerts-immediate">
5667 <th scope="row"><?php esc_html_e( 'Immediate alerts', 'vigilante' ); ?></th>
5668 <td>
5669 <label>
5670 <input type="checkbox" name="audit_alerts[immediate][enabled]" value="1" <?php checked( ! empty( $immediate['enabled'] ) ); ?>>
5671 <?php esc_html_e( 'Email me as soon as a serious event is logged', 'vigilante' ); ?>
5672 </label>
5673 <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>
5674 </td>
5675 </tr>
5676 <tr>
5677 <th scope="row"><label for="vigilante-f-audit-alerts-immediate-min-severity"><?php esc_html_e( 'Alert on severity', 'vigilante' ); ?></label></th>
5678 <td>
5679 <select id="vigilante-f-audit-alerts-immediate-min-severity" name="audit_alerts[immediate][min_severity]">
5680 <option value="critical" <?php selected( $alert_severity, 'critical' ); ?>><?php esc_html_e( 'Critical only (recommended)', 'vigilante' ); ?></option>
5681 <option value="warning" <?php selected( $alert_severity, 'warning' ); ?>><?php esc_html_e( 'Warning and Critical', 'vigilante' ); ?></option>
5682 </select>
5683 <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>
5684 </td>
5685 </tr>
5686 <tr id="field-audit-alerts-threshold">
5687 <th scope="row"><?php esc_html_e( 'Threshold alerts', 'vigilante' ); ?></th>
5688 <td>
5689 <label>
5690 <input type="checkbox" name="audit_alerts[threshold][enabled]" value="1" <?php checked( ! empty( $threshold['enabled'] ) ); ?>>
5691 <?php esc_html_e( 'Email me when a category spikes within a time window', 'vigilante' ); ?>
5692 </label>
5693 <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>
5694 </td>
5695 </tr>
5696 <tr>
5697 <th scope="row"><label for="vigilante-f-audit-alerts-threshold-window"><?php esc_html_e( 'Time window', 'vigilante' ); ?></label></th>
5698 <td>
5699 <select id="vigilante-f-audit-alerts-threshold-window" name="audit_alerts[threshold][window]">
5700 <option value="30m" <?php selected( $alert_window, '30m' ); ?>><?php esc_html_e( '30 minutes', 'vigilante' ); ?></option>
5701 <option value="1h" <?php selected( $alert_window, '1h' ); ?>><?php esc_html_e( '1 hour', 'vigilante' ); ?></option>
5702 <option value="6h" <?php selected( $alert_window, '6h' ); ?>><?php esc_html_e( '6 hours', 'vigilante' ); ?></option>
5703 <option value="24h" <?php selected( $alert_window, '24h' ); ?>><?php esc_html_e( '24 hours', 'vigilante' ); ?></option>
5704 </select>
5705 <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>
5706 </td>
5707 </tr>
5708 <tr>
5709 <th scope="row"><?php esc_html_e( 'Thresholds per category', 'vigilante' ); ?></th>
5710 <td>
5711 <fieldset style="display:grid; grid-template-columns:repeat(auto-fit, minmax(200px, 1fr)); gap:8px 24px; max-width:760px;">
5712 <?php
5713 foreach ( $cat_labels as $cat_slug => $cat_label ) :
5714 $cat_value = isset( $threshold_cats[ $cat_slug ] ) ? (int) $threshold_cats[ $cat_slug ] : 0;
5715 ?>
5716 <label style="display:flex;align-items:center;gap:8px;justify-content:space-between;">
5717 <span><?php echo esc_html( $cat_label ); ?></span>
5718 <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">
5719 </label>
5720 <?php endforeach; ?>
5721 </fieldset>
5722 <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>
5723 </td>
5724 </tr>
5725 <tr>
5726 <th scope="row"><?php esc_html_e( "Don't repeat alerts", 'vigilante' ); ?></th>
5727 <td>
5728 <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">
5729 <label for="vigilante-f-audit-alerts-cooldown-minutes"><?php esc_html_e( 'minutes', 'vigilante' ); ?></label>
5730 <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>
5731 </td>
5732 </tr>
5733
5734 <tr>
5735 <th scope="row"><?php esc_html_e( 'Recipients', 'vigilante' ); ?></th>
5736 <td>
5737 <p class="description" style="margin-top:0;">
5738 <?php
5739 printf(
5740 /* translators: %s: Link to notification settings */
5741 esc_html__( 'Alerts go to the recipients configured in %s.', 'vigilante' ),
5742 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
5743 );
5744 ?>
5745 </p>
5746 <p style="margin:8px 0 0;">
5747 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
5748 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
5749 </button>
5750 <span class="vigilante-test-email-result" style="margin-left:8px;"></span>
5751 </p>
5752 <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>
5753 </td>
5754 </tr>
5755 </table>
5756 </div>
5757
5758 <p class="submit vigilante-submit-buttons">
5759 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5760 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5761 </button>
5762 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5763 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5764 </button>
5765 </p>
5766 </form>
5767
5768 <div id="vigilante-section-audit-recent" class="vigilante-settings-section">
5769 <h2><?php esc_html_e( 'Recent Activity', 'vigilante' ); ?></h2>
5770
5771 <?php
5772 $logs = $this->activity_log->get_logs( array( 'per_page' => 20 ) );
5773 $total_logs = $this->activity_log->get_logs_count();
5774
5775 // Label maps for translated display
5776 $type_labels = array(
5777 'login' => __( 'Login', 'vigilante' ),
5778 'user' => __( 'User', 'vigilante' ),
5779 'content' => __( 'Content', 'vigilante' ),
5780 'plugin' => __( 'Plugin', 'vigilante' ),
5781 'theme' => __( 'Theme', 'vigilante' ),
5782 'settings' => __( 'Settings', 'vigilante' ),
5783 'comment' => __( 'Comment', 'vigilante' ),
5784 'media' => __( 'Media', 'vigilante' ),
5785 'firewall' => __( 'Firewall', 'vigilante' ),
5786 'file' => __( 'File', 'vigilante' ),
5787 'security' => __( 'Security', 'vigilante' ),
5788 'system' => __( 'System', 'vigilante' ),
5789 );
5790 $severity_labels = array(
5791 'info' => __( 'Info', 'vigilante' ),
5792 'warning' => __( 'Warning', 'vigilante' ),
5793 'critical' => __( 'Critical', 'vigilante' ),
5794 );
5795
5796 $firewall_options = $this->settings->get_section( 'firewall' );
5797 $ip_whitelist = $firewall_options['ip_whitelist'] ?? array();
5798 $ip_blacklist = $firewall_options['ip_blacklist'] ?? array();
5799 $ua_whitelist = $firewall_options['ua_whitelist'] ?? array();
5800 $ua_blacklist = $firewall_options['ua_blacklist'] ?? array();
5801 ?>
5802
5803 <div class="vigilante-log-filters">
5804 <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">
5805 <select id="vigilante-log-type-filter" aria-label="<?php esc_attr_e( 'Filter the log by event type', 'vigilante' ); ?>">
5806 <option value=""><?php esc_html_e( 'All Types', 'vigilante' ); ?></option>
5807 <option value="login"><?php esc_html_e( 'Login', 'vigilante' ); ?></option>
5808 <option value="user"><?php esc_html_e( 'User', 'vigilante' ); ?></option>
5809 <option value="content"><?php esc_html_e( 'Content', 'vigilante' ); ?></option>
5810 <option value="plugin"><?php esc_html_e( 'Plugin', 'vigilante' ); ?></option>
5811 <option value="theme"><?php esc_html_e( 'Theme', 'vigilante' ); ?></option>
5812 <option value="settings"><?php esc_html_e( 'Settings', 'vigilante' ); ?></option>
5813 <option value="comment"><?php esc_html_e( 'Comment', 'vigilante' ); ?></option>
5814 <option value="media"><?php esc_html_e( 'Media', 'vigilante' ); ?></option>
5815 <option value="firewall"><?php esc_html_e( 'Firewall', 'vigilante' ); ?></option>
5816 <option value="file"><?php esc_html_e( 'File', 'vigilante' ); ?></option>
5817 <option value="security"><?php esc_html_e( 'Security', 'vigilante' ); ?></option>
5818 <option value="system"><?php esc_html_e( 'System', 'vigilante' ); ?></option>
5819 </select>
5820 <select id="vigilante-log-severity-filter" aria-label="<?php esc_attr_e( 'Filter the log by severity', 'vigilante' ); ?>">
5821 <option value=""><?php esc_html_e( 'All Severities', 'vigilante' ); ?></option>
5822 <option value="info"><?php esc_html_e( 'Info', 'vigilante' ); ?></option>
5823 <option value="warning"><?php esc_html_e( 'Warning', 'vigilante' ); ?></option>
5824 <option value="critical"><?php esc_html_e( 'Critical', 'vigilante' ); ?></option>
5825 </select>
5826 <select id="vigilante-log-method-filter" aria-label="<?php esc_attr_e( 'Filter the log by HTTP method', 'vigilante' ); ?>">
5827 <option value=""><?php esc_html_e( 'All Methods', 'vigilante' ); ?></option>
5828 <option value="GET">GET</option>
5829 <option value="POST">POST</option>
5830 <option value="PUT">PUT</option>
5831 <option value="DELETE">DELETE</option>
5832 <option value="PATCH">PATCH</option>
5833 <option value="OPTIONS">OPTIONS</option>
5834 <option value="HEAD">HEAD</option>
5835 </select>
5836 <button type="button" id="vigilante-log-refresh" class="button"><?php esc_html_e( 'Refresh', 'vigilante' ); ?></button>
5837 <span class="vigilante-pagination" id="vigilante-log-pagination" data-total="<?php echo esc_attr( $total_logs ); ?>" data-per-page="20" data-page="1">
5838 <?php if ( $total_logs > 20 ) : ?>
5839 <button type="button" class="vigilante-page-first" title="<?php esc_attr_e( 'First page', 'vigilante' ); ?>" disabled>&laquo;</button>
5840 <button type="button" class="vigilante-page-prev" title="<?php esc_attr_e( 'Previous page', 'vigilante' ); ?>" disabled>&lsaquo;</button>
5841 <?php endif; ?>
5842 <span class="vigilante-page-info">
5843 <?php
5844 $showing = min( 20, $total_logs );
5845 printf(
5846 /* translators: 1: first item, 2: last item, 3: total items */
5847 esc_html__( '%1$d–%2$d of %3$d', 'vigilante' ),
5848 $total_logs > 0 ? 1 : 0,
5849 absint( $showing ),
5850 absint( $total_logs )
5851 );
5852 ?>
5853 </span>
5854 <?php if ( $total_logs > 20 ) : ?>
5855 <button type="button" class="vigilante-page-next" title="<?php esc_attr_e( 'Next page', 'vigilante' ); ?>">&rsaquo;</button>
5856 <button type="button" class="vigilante-page-last" title="<?php esc_attr_e( 'Last page', 'vigilante' ); ?>">&raquo;</button>
5857 <?php endif; ?>
5858 </span>
5859 </div>
5860
5861 <div class="vigilante-log-table-wrap">
5862 <table id="vigilante-activity-log-table" class="wp-list-table widefat striped">
5863 <thead>
5864 <tr>
5865 <th class="column-date"><?php esc_html_e( 'Date', 'vigilante' ); ?></th>
5866 <th class="column-type"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
5867 <th class="column-method"><?php esc_html_e( 'Method', 'vigilante' ); ?></th>
5868 <th class="column-severity"><?php esc_html_e( 'Severity', 'vigilante' ); ?></th>
5869 <th class="column-message"><?php esc_html_e( 'Message', 'vigilante' ); ?></th>
5870 <th class="column-user"><?php esc_html_e( 'User', 'vigilante' ); ?></th>
5871 <th class="column-ip"><?php esc_html_e( 'IP', 'vigilante' ); ?></th>
5872 <th class="column-details"><?php esc_html_e( 'Details', 'vigilante' ); ?></th>
5873 </tr>
5874 </thead>
5875 <tbody>
5876 <?php
5877 if ( empty( $logs ) ) :
5878 ?>
5879 <tr><td colspan="8"><?php esc_html_e( 'No log entries found.', 'vigilante' ); ?></td></tr>
5880 <?php else : ?>
5881 <?php foreach ( $logs as $log ) :
5882 $request_method = isset( $log->request_method ) ? $log->request_method : '';
5883 // Prepare details as a simple object
5884 $ip_val = (string) ( $log->ip_address ?? '' );
5885 $ua_val = (string) ( $log->user_agent ?? '' );
5886 $details = array(
5887 'id' => (int) $log->id,
5888 'type' => (string) ( $log->event_type ?? '' ),
5889 'action' => (string) ( $log->event_action ?? '' ),
5890 'message' => (string) ( $log->event_message ?? '' ),
5891 'user' => (string) ( $log->user_login ?? '' ),
5892 'ip' => $ip_val,
5893 'user_agent' => $ua_val,
5894 'request_method' => (string) $request_method,
5895 'request_uri' => Vigilante_Activity_Log::extract_request_uri( $log->extra_data ?? '' ),
5896 'date' => (string) ( $log->created_at ?? '' ),
5897 'severity' => (string) ( $log->severity ?? 'info' ),
5898 'is_ip_whitelisted' => ( '' !== $ip_val && in_array( $ip_val, $ip_whitelist, true ) ),
5899 'is_ip_blacklisted' => ( '' !== $ip_val && in_array( $ip_val, $ip_blacklist, true ) ),
5900 'is_ua_whitelisted' => ( '' !== $ua_val && in_array( $ua_val, $ua_whitelist, true ) ),
5901 'is_ua_blacklisted' => ( '' !== $ua_val && in_array( $ua_val, $ua_blacklist, true ) ),
5902 );
5903 $display_type = isset( $type_labels[ $log->event_type ] ) ? $type_labels[ $log->event_type ] : $log->event_type;
5904 $display_severity = isset( $severity_labels[ $log->severity ] ) ? $severity_labels[ $log->severity ] : $log->severity;
5905 ?>
5906 <tr class="vigilante-severity-<?php echo esc_attr( $log->severity ); ?>">
5907 <td><?php echo esc_html( $log->created_at ); ?></td>
5908 <td><?php echo esc_html( $display_type ); ?></td>
5909 <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>
5910 <td><span class="vigilante-badge vigilante-badge-<?php echo esc_attr( $log->severity ); ?>"><?php echo esc_html( $display_severity ); ?></span></td>
5911 <td><?php echo esc_html( $log->event_message ); ?></td>
5912 <td><?php echo esc_html( $log->user_login ?? '-' ); ?></td>
5913 <td><code><?php echo esc_html( $log->ip_address ); ?></code></td>
5914 <td>
5915 <button type="button" class="button button-small vigilante-view-log-details"
5916 data-details='<?php echo esc_attr( wp_json_encode( $details, JSON_HEX_APOS | JSON_HEX_QUOT ) ); ?>'>
5917 <?php esc_html_e( 'View', 'vigilante' ); ?>
5918 </button>
5919 </td>
5920 </tr>
5921 <?php endforeach; ?>
5922 <?php endif; ?>
5923 </tbody>
5924 </table>
5925 </div>
5926
5927 <!-- Log Details Modal -->
5928 <div id="vigilante-log-details-modal" class="vigilante-modal" style="display: none;">
5929 <div class="vigilante-modal-content">
5930 <span class="vigilante-modal-close">&times;</span>
5931 <h3><?php esc_html_e( 'Log Entry Details', 'vigilante' ); ?></h3>
5932 <div id="vigilante-log-details-content"></div>
5933 </div>
5934 </div>
5935
5936 <p>
5937 <button type="button" class="button vigilante-export-logs"><?php esc_html_e( 'Export Audit Log', 'vigilante' ); ?></button>
5938 <button type="button" class="button vigilante-clear-logs" style="color: #a00;"><?php esc_html_e( 'Clear All Logs', 'vigilante' ); ?></button>
5939 </p>
5940 </div>
5941 <?php
5942 }
5943
5944 /**
5945 * Render File Integrity tab
5946 */
5947 private function render_tab_file_integrity() {
5948 $is_disabled = $this->render_module_disabled_notice( 'file_integrity' );
5949 $options = $this->settings->get_section( 'file_integrity' );
5950 $last_scan = get_option( 'vigilante_last_integrity_scan' );
5951 $last_results = get_option( 'vigilante_last_integrity_results' );
5952 $ignored_files = get_option( 'vigilante_ignored_files', array() );
5953
5954 // Backward compat: convert old notify_on_changes to notify_level
5955 $notify_level = $options['notify_level'] ?? '';
5956 if ( empty( $notify_level ) ) {
5957 $notify_level = ! empty( $options['notify_on_changes'] ) ? 'all' : 'disabled';
5958 }
5959
5960 // Closed + Removed plugins data. Surfaced inside Last Scan Results so the
5961 // user sees file findings and plugin closures together (same tier of risk,
5962 // same UI), and as the trigger to keep Last Scan Results open even when no
5963 // file scan has run yet (the daily cron may have populated this section).
5964 //
5965 // Gating by last_check_time > 0 is how "Clear Previous Results" visually
5966 // resets this block: the option vigilante_plugin_status_last_check is
5967 // deleted on Clear, but the state map and the ignored list survive so the
5968 // next scan reconstructs without degrading a 'removed' slug. While
5969 // last_check is 0, we treat the plugin_status data as if it didn't exist.
5970 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
5971 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
5972 }
5973 $closed_checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
5974 $closed_last_check = $closed_checker->get_last_check_time();
5975 if ( $closed_last_check > 0 ) {
5976 $closed_plugins = $closed_checker->get_closed_plugins();
5977 $ignored_closed_plugins = $closed_checker->get_ignored_closed_plugins();
5978 } else {
5979 $closed_plugins = array();
5980 $ignored_closed_plugins = array();
5981 }
5982 $has_closed = ! empty( $closed_plugins );
5983 $datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
5984 ?>
5985 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="file_integrity" <?php echo $is_disabled ? 'inert' : ''; ?>>
5986 <div id="vigilante-section-fi-monitoring" class="vigilante-settings-section">
5987 <h2>
5988 <?php esc_html_e( 'File Integrity Monitoring', 'vigilante' ); ?>
5989 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5990 </h2>
5991 <p><?php esc_html_e( 'Detects file modifications using WordPress.org checksums.', 'vigilante' ); ?></p>
5992
5993 <table class="form-table">
5994 <tr>
5995 <th scope="row"><?php esc_html_e( 'Automatic Scans', 'vigilante' ); ?></th>
5996 <td>
5997 <label>
5998 <input type="checkbox" name="file_integrity[auto_scan]" value="1" <?php checked( ! empty( $options['auto_scan'] ) ); ?>>
5999 <?php esc_html_e( 'Enable scheduled file integrity scans', 'vigilante' ); ?>
6000 </label>
6001 </td>
6002 </tr>
6003 <tr>
6004 <th scope="row"><label for="vigilante-f-file-integrity-scan-frequency"><?php esc_html_e( 'Scan Frequency', 'vigilante' ); ?></label></th>
6005 <td>
6006 <select id="vigilante-f-file-integrity-scan-frequency" name="file_integrity[scan_frequency]">
6007 <option value="daily" <?php selected( $options['scan_frequency'] ?? 'daily', 'daily' ); ?>><?php esc_html_e( 'Daily', 'vigilante' ); ?></option>
6008 <option value="weekly" <?php selected( $options['scan_frequency'] ?? 'daily', 'weekly' ); ?>><?php esc_html_e( 'Weekly', 'vigilante' ); ?></option>
6009 </select>
6010 </td>
6011 </tr>
6012 <tr>
6013 <th scope="row"><label for="vigilante-f-file-integrity-notify-level"><?php esc_html_e( 'Email Notifications', 'vigilante' ); ?></label></th>
6014 <td>
6015 <select id="vigilante-f-file-integrity-notify-level" name="file_integrity[notify_level]">
6016 <option value="all" <?php selected( $notify_level, 'all' ); ?>><?php esc_html_e( 'All issues (modified + suspicious)', 'vigilante' ); ?></option>
6017 <option value="suspicious_only" <?php selected( $notify_level, 'suspicious_only' ); ?>><?php esc_html_e( 'Suspicious files only', 'vigilante' ); ?></option>
6018 <option value="disabled" <?php selected( $notify_level, 'disabled' ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
6019 </select>
6020 <p class="description"><?php esc_html_e( '"Suspicious files only" reduces noise by skipping modified file notifications. Recommended for most sites.', 'vigilante' ); ?></p>
6021 </td>
6022 </tr>
6023 <tr>
6024 <th scope="row"><?php esc_html_e( 'Instant Alert', 'vigilante' ); ?></th>
6025 <td>
6026 <label>
6027 <input type="checkbox" name="file_integrity[instant_alert]" value="1" <?php checked( ! empty( $options['instant_alert'] ) ); ?>>
6028 <?php esc_html_e( 'Send immediate alert when modified, suspicious or additional files are detected, or when a closed plugin is found', 'vigilante' ); ?>
6029 </label>
6030 <p class="description"><?php esc_html_e( 'Fires even if the Email Notifications setting above is set to Disabled.', 'vigilante' ); ?></p>
6031 <p class="description">
6032 <?php
6033 printf(
6034 /* translators: %s: Link to notification settings */
6035 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
6036 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
6037 );
6038 ?>
6039 </p>
6040 </td>
6041 </tr>
6042 <tr>
6043 <th scope="row"><?php esc_html_e( 'Test email', 'vigilante' ); ?></th>
6044 <td>
6045 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
6046 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
6047 </button>
6048 <span class="vigilante-test-email-result" style="margin-left:8px;"></span>
6049 <p class="description"><?php esc_html_e( 'Sends a test message to the configured recipients to confirm email delivery works.', 'vigilante' ); ?></p>
6050 </td>
6051 </tr>
6052 <tr>
6053 <th scope="row"><?php esc_html_e( 'Scan Scope', 'vigilante' ); ?></th>
6054 <td>
6055 <fieldset>
6056 <label>
6057 <input type="checkbox" name="file_integrity[scan_core]" value="1" <?php checked( $options['scan_core'] ?? true ); ?>>
6058 <?php esc_html_e( 'Core files (compare against WordPress.org checksums)', 'vigilante' ); ?>
6059 </label>
6060 <br>
6061 <label>
6062 <input type="checkbox" name="file_integrity[scan_plugins]" value="1" <?php checked( $options['scan_plugins'] ?? true ); ?>>
6063 <?php esc_html_e( 'Plugins (WordPress.org repository plugins)', 'vigilante' ); ?>
6064 </label>
6065 <br>
6066 <label>
6067 <input type="checkbox" name="file_integrity[scan_themes]" value="1" <?php checked( $options['scan_themes'] ?? true ); ?>>
6068 <?php esc_html_e( 'Themes (WordPress.org repository themes)', 'vigilante' ); ?>
6069 </label>
6070 <br>
6071 <label>
6072 <input type="checkbox" name="file_integrity[scan_uploads]" value="1" <?php checked( $options['scan_uploads'] ?? true ); ?>>
6073 <?php esc_html_e( 'Uploads directory (detect PHP files, double extensions, .htaccess)', 'vigilante' ); ?>
6074 </label>
6075 <br>
6076 <label>
6077 <input type="checkbox" name="file_integrity[scan_critical_config]" value="1" <?php checked( $options['scan_critical_config'] ?? true ); ?>>
6078 <?php esc_html_e( 'Critical config files (wp-config.php, .htaccess baseline monitoring)', 'vigilante' ); ?>
6079 </label>
6080 <br>
6081 <label>
6082 <input type="checkbox" name="file_integrity[check_closed_plugins]" value="1" <?php checked( $options['check_closed_plugins'] ?? true ); ?>>
6083 <?php esc_html_e( 'Closed plugins (daily check against the WordPress.org repository)', 'vigilante' ); ?>
6084 </label>
6085 </fieldset>
6086 </td>
6087 </tr>
6088 <tr>
6089 <th scope="row"><label for="vigilante-f-file-integrity-excluded-paths"><?php esc_html_e( 'Excluded Paths', 'vigilante' ); ?></label></th>
6090 <td>
6091 <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>
6092 <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>
6093 </td>
6094 </tr>
6095 <tr>
6096 <th scope="row"><label for="vigilante-f-file-integrity-excluded-extensions"><?php esc_html_e( 'Excluded Extensions', 'vigilante' ); ?></label></th>
6097 <td>
6098 <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>
6099 <p class="description">
6100 <?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' ); ?>
6101 <br>
6102 <?php
6103 printf(
6104 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the scoped-extension example. */
6105 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' ),
6106 '<code>',
6107 '</code>'
6108 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
6109 ?>
6110 </p>
6111 </td>
6112 </tr>
6113 </table>
6114 </div>
6115
6116 <p class="submit vigilante-submit-buttons">
6117 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
6118 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
6119 </button>
6120 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
6121 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
6122 </button>
6123 <span class="vigilante-buttons-separator"></span>
6124 <button type="button" class="button button-primary vigilante-run-scan">
6125 <?php esc_html_e( 'Run Scan Now', 'vigilante' ); ?>
6126 </button>
6127 <button type="button" class="button vigilante-clear-scan-btn vigilante-clear-scan">
6128 <?php esc_html_e( 'Clear Previous Results', 'vigilante' ); ?>
6129 </button>
6130 </p>
6131 </form>
6132
6133 <div id="vigilante-scan-results" class="vigilante-settings-section" style="display:none;"></div>
6134
6135 <?php if ( $last_scan || $has_closed || $closed_last_check > 0 ) : ?>
6136 <div id="vigilante-section-fi-last-scan" class="vigilante-settings-section">
6137 <h2><?php esc_html_e( 'Last Scan Results', 'vigilante' ); ?></h2>
6138 <?php if ( $last_scan ) : ?>
6139 <p>
6140 <?php
6141 // Build the "X files scanned" hint inline with the date so it doesn't
6142 // need its own stat box (keeps the row compact when closed plugins are
6143 // present).
6144 $scanned_total = 0;
6145 if ( $last_results ) {
6146 $scanned_total = (int) ( $last_results['ok'] ?? 0 )
6147 + count( $last_results['modified'] ?? array() )
6148 + count( $last_results['suspicious'] ?? array() )
6149 + count( $last_results['extra'] ?? array() )
6150 + count( $ignored_files );
6151 }
6152 if ( $scanned_total > 0 ) {
6153 printf(
6154 /* translators: 1: date and time of last scan, 2: formatted file count */
6155 esc_html__( 'Last scan: %1$s (%2$s files scanned)', 'vigilante' ),
6156 esc_html( wp_date( $datetime_format, $last_scan ) ),
6157 esc_html( number_format_i18n( $scanned_total ) )
6158 );
6159 } else {
6160 printf(
6161 /* translators: %s: date and time of last scan */
6162 esc_html__( 'Last scan: %s', 'vigilante' ),
6163 esc_html( wp_date( $datetime_format, $last_scan ) )
6164 );
6165 }
6166 if ( $closed_last_check > 0 && $closed_last_check !== (int) $last_scan ) {
6167 echo ' &middot; ';
6168 printf(
6169 /* translators: %s: date and time of last closed plugins check */
6170 esc_html__( 'Closed plugins last checked: %s', 'vigilante' ),
6171 esc_html( wp_date( $datetime_format, $closed_last_check ) )
6172 );
6173 }
6174 ?>
6175 </p>
6176 <?php elseif ( $closed_last_check > 0 ) : ?>
6177 <p>
6178 <?php
6179 printf(
6180 /* translators: %s: date and time of last closed plugins check */
6181 esc_html__( 'Closed plugins last checked: %s &middot; the daily cron is running, no full integrity scan yet.', 'vigilante' ),
6182 esc_html( wp_date( $datetime_format, $closed_last_check ) )
6183 );
6184 ?>
6185 </p>
6186 <?php endif; ?>
6187 <div id="vigilante-last-scan-results">
6188 <?php if ( $last_results || $has_closed ) : ?>
6189 <div class="vigilante-scan-summary">
6190 <?php if ( $last_results ) : ?>
6191 <div class="vigilante-scan-stat vigilante-stat-ok">
6192 <span class="vigilante-stat-number"><?php echo esc_html( $last_results['ok'] ?? 0 ); ?></span>
6193 <span class="vigilante-stat-label"><?php esc_html_e( 'OK', 'vigilante' ); ?></span>
6194 </div>
6195 <div class="vigilante-scan-stat vigilante-stat-modified">
6196 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['modified'] ?? array() ) ); ?></span>
6197 <span class="vigilante-stat-label"><?php esc_html_e( 'Modified', 'vigilante' ); ?></span>
6198 </div>
6199 <div class="vigilante-scan-stat vigilante-stat-suspicious">
6200 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['suspicious'] ?? array() ) ); ?></span>
6201 <span class="vigilante-stat-label"><?php esc_html_e( 'Suspicious', 'vigilante' ); ?></span>
6202 </div>
6203 <div class="vigilante-scan-stat vigilante-stat-extra">
6204 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['extra'] ?? array() ) ); ?></span>
6205 <span class="vigilante-stat-label"><?php esc_html_e( 'Extra', 'vigilante' ); ?></span>
6206 </div>
6207 <?php endif; ?>
6208 <?php if ( $has_closed ) : ?>
6209 <div class="vigilante-scan-stat vigilante-stat-suspicious">
6210 <span class="vigilante-stat-number" style="color: #d63638;"><?php echo (int) count( $closed_plugins ); ?></span>
6211 <span class="vigilante-stat-label"><?php esc_html_e( 'Closed/Removed', 'vigilante' ); ?></span>
6212 </div>
6213 <?php endif; ?>
6214 <?php if ( ! empty( $ignored_files ) ) : ?>
6215 <div class="vigilante-scan-stat vigilante-stat-ignored">
6216 <span class="vigilante-stat-number"><?php echo esc_html( count( $ignored_files ) ); ?></span>
6217 <span class="vigilante-stat-label"><?php esc_html_e( 'Ignored', 'vigilante' ); ?></span>
6218 </div>
6219 <?php endif; ?>
6220 </div>
6221
6222 <?php if ( ! empty( $last_results['suspicious'] ) ) : ?>
6223 <div class="vigilante-file-list vigilante-suspicious-files vigilante-paginated-section" data-bulk-mode="ignore">
6224 <h3 style="color: #d63638;"><?php esc_html_e( 'Suspicious Files', 'vigilante' ); ?></h3>
6225 <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>
6226 <div class="vigilante-fi-bulk-bar">
6227 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
6228 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
6229 </div>
6230 <div class="vigilante-fi-pagination-wrap"></div>
6231 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
6232 <thead>
6233 <tr>
6234 <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>
6235 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6236 <th style="width: 250px;"><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
6237 <th style="width: 120px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
6238 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6239 </tr>
6240 </thead>
6241 <tbody>
6242 <?php
6243 foreach ( $last_results['suspicious'] as $item ) {
6244 $file_path = '';
6245 $file_reason = __( 'Unknown', 'vigilante' );
6246 $file_type = 'unknown';
6247
6248 if ( is_array( $item ) ) {
6249 if ( isset( $item['file'] ) ) {
6250 $file_path = $item['file'];
6251 }
6252 if ( isset( $item['reason'] ) ) {
6253 $file_reason = $item['reason'];
6254 }
6255 if ( isset( $item['type'] ) ) {
6256 $file_type = $item['type'];
6257 }
6258 } else {
6259 $file_path = (string) $item;
6260 }
6261 ?>
6262 <tr>
6263 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
6264 <td><code style="color: #d63638;"><?php echo esc_html( $file_path ); ?></code></td>
6265 <td><?php echo esc_html( $file_reason ); ?></td>
6266 <td><?php echo esc_html( $file_type ); ?></td>
6267 <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>
6268 </tr>
6269 <?php
6270 }
6271 ?>
6272 </tbody>
6273 </table>
6274 </div>
6275 <?php endif; ?>
6276
6277 <?php if ( ! empty( $last_results['extra'] ) ) : ?>
6278 <div class="vigilante-file-list vigilante-extra-files vigilante-paginated-section" data-bulk-mode="ignore">
6279 <h3 style="color: #b32d2e;"><?php esc_html_e( 'Extra Files', 'vigilante' ); ?></h3>
6280 <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>
6281 <div class="vigilante-fi-bulk-bar">
6282 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
6283 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
6284 </div>
6285 <div class="vigilante-fi-pagination-wrap"></div>
6286 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
6287 <thead>
6288 <tr>
6289 <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>
6290 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6291 <th style="width: 250px;"><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
6292 <th style="width: 120px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
6293 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6294 </tr>
6295 </thead>
6296 <tbody>
6297 <?php
6298 foreach ( $last_results['extra'] as $item ) {
6299 $file_path = is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item;
6300 $file_reason = is_array( $item ) ? ( $item['reason'] ?? __( 'Unknown', 'vigilante' ) ) : __( 'Unknown', 'vigilante' );
6301 $file_type = is_array( $item ) ? ( $item['type'] ?? 'unknown' ) : 'unknown';
6302 ?>
6303 <tr>
6304 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
6305 <td><code style="color: #b32d2e;"><?php echo esc_html( $file_path ); ?></code></td>
6306 <td><?php echo esc_html( $file_reason ); ?></td>
6307 <td><?php echo esc_html( $file_type ); ?></td>
6308 <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>
6309 </tr>
6310 <?php
6311 }
6312 ?>
6313 </tbody>
6314 </table>
6315 </div>
6316 <?php endif; ?>
6317
6318 <?php
6319 // Split critical config files from regular modified files.
6320 // Computed unconditionally so the three sub-sections that consume
6321 // these arrays (Critical Config, Closed + Removed, Modified Files)
6322 // can render independently and in the order the team picked.
6323 $critical_modified = array();
6324 $regular_modified = array();
6325 if ( $last_results && ! empty( $last_results['modified'] ) ) {
6326 foreach ( $last_results['modified'] as $item ) {
6327 if ( is_array( $item ) && isset( $item['type'] ) && 'critical_config' === $item['type'] ) {
6328 $critical_modified[] = $item;
6329 } else {
6330 $regular_modified[] = $item;
6331 }
6332 }
6333 }
6334 ?>
6335
6336 <?php if ( ! empty( $critical_modified ) ) : ?>
6337 <div class="vigilante-file-list vigilante-critical-config-files">
6338 <h3 style="color: #e36210;"><?php esc_html_e( 'Critical config files modified', 'vigilante' ); ?></h3>
6339 <p class="description">
6340 <?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' ); ?>
6341 </p>
6342 <table class="wp-list-table widefat fixed striped">
6343 <thead>
6344 <tr>
6345 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6346 <th style="width: 200px;"><?php esc_html_e( 'Changes', 'vigilante' ); ?></th>
6347 <th style="width: 220px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6348 </tr>
6349 </thead>
6350 <tbody>
6351 <?php foreach ( $critical_modified as $crit_item ) :
6352 $crit_file = $crit_item['file'] ?? '';
6353 $crit_baseline_size = $crit_item['baseline_size'] ?? 0;
6354 $crit_current_size = $crit_item['current_size'] ?? 0;
6355 $crit_diff = $crit_item['diff'] ?? array();
6356 $crit_id = sanitize_html_class( $crit_file );
6357 $added_count = is_array( $crit_diff ) ? count( $crit_diff['added'] ?? array() ) : 0;
6358 $removed_count = is_array( $crit_diff ) ? count( $crit_diff['removed'] ?? array() ) : 0;
6359 $diff_unavailable = is_array( $crit_diff ) && ! empty( $crit_diff['unavailable'] );
6360 ?>
6361 <tr>
6362 <td><code style="color: #e36210;"><?php echo esc_html( $crit_file ); ?></code></td>
6363 <td>
6364 <?php if ( ! $diff_unavailable ) : ?>
6365 <span style="color: #007017;">+<?php echo (int) $added_count; ?></span>
6366 <span style="color: #b32d2e;">-<?php echo (int) $removed_count; ?></span>
6367 <?php esc_html_e( 'lines', 'vigilante' ); ?><br>
6368 <?php endif; ?>
6369 <small style="color: #50575e;">
6370 <?php
6371 printf(
6372 /* translators: 1: baseline size, 2: current size */
6373 esc_html__( '%1$s &rarr; %2$s bytes', 'vigilante' ),
6374 esc_html( number_format_i18n( $crit_baseline_size ) ),
6375 esc_html( number_format_i18n( $crit_current_size ) )
6376 );
6377 ?>
6378 </small>
6379 </td>
6380 <td>
6381 <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' ); ?>">
6382 <?php esc_html_e( 'Review changes', 'vigilante' ); ?>
6383 </button>
6384 <?php if ( $this->critical_approval_locked() ) : ?>
6385 <span class="description" style="display:block;margin-top:4px;">
6386 <?php echo esc_html( $this->critical_approval_notice() ); ?>
6387 </span>
6388 <?php else : ?>
6389 <button type="button" class="button button-small button-primary vigilante-approve-critical-file" data-file="<?php echo esc_attr( $crit_file ); ?>">
6390 <?php esc_html_e( 'Approve', 'vigilante' ); ?>
6391 </button>
6392 <?php endif; ?>
6393 </td>
6394 </tr>
6395 <tr id="vigilante-critical-content-<?php echo esc_attr( $crit_id ); ?>" class="vigilante-critical-content-row" style="display:none;">
6396 <td colspan="3" style="padding: 0;">
6397 <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;">
6398 <?php if ( $diff_unavailable ) : ?>
6399 <p style="color: #50575e; font-style: italic; margin: 0;">
6400 <?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' ); ?>
6401 </p>
6402 <?php elseif ( empty( $crit_diff['added'] ) && empty( $crit_diff['removed'] ) ) : ?>
6403 <p style="color: #50575e; font-style: italic; margin: 0;">
6404 <?php esc_html_e( 'No line-level changes detected (may be whitespace or reordering).', 'vigilante' ); ?>
6405 </p>
6406 <?php else : ?>
6407 <?php if ( ! empty( $crit_diff['removed'] ) ) : ?>
6408 <?php foreach ( $crit_diff['removed'] as $rline ) : ?>
6409 <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>
6410 <?php endforeach; ?>
6411 <?php endif; ?>
6412 <?php if ( ! empty( $crit_diff['added'] ) ) : ?>
6413 <?php foreach ( $crit_diff['added'] as $aline ) : ?>
6414 <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>
6415 <?php endforeach; ?>
6416 <?php endif; ?>
6417 <?php endif; ?>
6418 </div>
6419 </td>
6420 </tr>
6421 <?php endforeach; ?>
6422 </tbody>
6423 </table>
6424 </div>
6425 <?php endif; ?>
6426
6427 <?php if ( $has_closed ) : ?>
6428 <div class="vigilante-file-list vigilante-closed-plugins">
6429 <h3 id="vigilante-section-fi-closed-plugins" style="color: #d63638;"><?php esc_html_e( 'Closed + Removed Plugins', 'vigilante' ); ?></h3>
6430 <p class="description" style="color: #d63638;">
6431 <?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' ); ?>
6432 </p>
6433 <table class="wp-list-table widefat striped">
6434 <thead>
6435 <tr>
6436 <th><?php esc_html_e( 'Plugin', 'vigilante' ); ?></th>
6437 <th style="width: 70px;"><?php esc_html_e( 'Version', 'vigilante' ); ?></th>
6438 <th style="width: 90px;"><?php esc_html_e( 'State', 'vigilante' ); ?></th>
6439 <th style="width: 110px;"><?php esc_html_e( 'Closed date', 'vigilante' ); ?></th>
6440 <th><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
6441 <th style="width: 130px;"><?php esc_html_e( 'Detected', 'vigilante' ); ?></th>
6442 <th style="width: 90px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6443 </tr>
6444 </thead>
6445 <tbody>
6446 <?php foreach ( $closed_plugins as $cp_slug => $cp_entry ) :
6447 $cp_state = $cp_entry['state'] ?? '';
6448 $cp_state_label = 'closed' === $cp_state ? __( 'Closed', 'vigilante' ) : __( 'Removed', 'vigilante' );
6449 $cp_state_color = 'closed' === $cp_state ? '#d63638' : '#b32d2e';
6450 $cp_reason = '';
6451 if ( ! empty( $cp_entry['closed_reason_text'] ) ) {
6452 $cp_reason = $cp_entry['closed_reason_text'];
6453 } elseif ( 'removed' === $cp_state ) {
6454 $cp_reason = __( 'Removed from repository (metadata hidden, typical of Security Issue closures)', 'vigilante' );
6455 }
6456 $cp_detected = isset( $cp_entry['first_detected'] ) ? (int) $cp_entry['first_detected'] : 0;
6457 ?>
6458 <tr>
6459 <td>
6460 <strong><?php echo esc_html( $cp_entry['name'] ?? $cp_slug ); ?></strong><br>
6461 <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>
6462 </td>
6463 <td><?php echo esc_html( $cp_entry['version'] ?? '' ); ?></td>
6464 <td><span style="color: <?php echo esc_attr( $cp_state_color ); ?>; font-weight: 600;"><?php echo esc_html( $cp_state_label ); ?></span></td>
6465 <td><?php echo esc_html( $cp_entry['closed_date'] ?? '' ); ?></td>
6466 <td><?php echo esc_html( $cp_reason ); ?></td>
6467 <td>
6468 <?php echo $cp_detected > 0 ? esc_html( wp_date( $datetime_format, $cp_detected ) ) : '&mdash;'; ?>
6469 </td>
6470 <td>
6471 <button type="button" class="button button-small vigilante-ignore-closed-plugin" data-slug="<?php echo esc_attr( $cp_slug ); ?>">
6472 <?php esc_html_e( 'Ignore', 'vigilante' ); ?>
6473 </button>
6474 </td>
6475 </tr>
6476 <?php endforeach; ?>
6477 </tbody>
6478 </table>
6479 </div>
6480 <?php endif; ?>
6481
6482 <?php if ( ! empty( $regular_modified ) ) : ?>
6483 <div class="vigilante-file-list vigilante-paginated-section" data-bulk-mode="ignore">
6484 <h3><?php esc_html_e( 'Modified Files', 'vigilante' ); ?></h3>
6485 <p class="description"><?php esc_html_e( 'These files (apparently) differ from the original WordPress or plugin versions.', 'vigilante' ); ?></p>
6486 <div class="vigilante-fi-bulk-bar">
6487 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
6488 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
6489 </div>
6490 <div class="vigilante-fi-pagination-wrap"></div>
6491 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
6492 <thead>
6493 <tr>
6494 <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>
6495 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6496 <th style="width: 100px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
6497 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6498 </tr>
6499 </thead>
6500 <tbody>
6501 <?php
6502 foreach ( $regular_modified as $item ) {
6503 $file_path = '';
6504 $file_type = 'unknown';
6505
6506 if ( is_array( $item ) ) {
6507 if ( isset( $item['file'] ) ) {
6508 $file_path = $item['file'];
6509 }
6510 if ( isset( $item['type'] ) ) {
6511 $file_type = $item['type'];
6512 }
6513 } else {
6514 $file_path = (string) $item;
6515 }
6516 ?>
6517 <tr>
6518 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
6519 <td><code><?php echo esc_html( $file_path ); ?></code></td>
6520 <td><?php echo esc_html( $file_type ); ?></td>
6521 <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>
6522 </tr>
6523 <?php
6524 }
6525 ?>
6526 </tbody>
6527 </table>
6528 </div>
6529 <?php endif; ?>
6530
6531 <?php if ( $last_results && empty( $last_results['modified'] ) && empty( $last_results['suspicious'] ) && empty( $last_results['extra'] ) && ! $has_closed ) : ?>
6532 <p class="vigilante-all-clear" style="color: #00a32a; font-weight: bold;">
6533 <?php esc_html_e( 'Good Job! All files passed integrity check. No issues found.', 'vigilante' ); ?>
6534 </p>
6535 <?php endif; ?>
6536 <?php endif; ?>
6537 </div>
6538 </div>
6539 <?php endif; ?>
6540
6541 <?php if ( ! empty( $ignored_closed_plugins ) ) : ?>
6542 <div id="vigilante-section-fi-ignored-closed" class="vigilante-settings-section">
6543 <h2><?php esc_html_e( 'Ignored Closed + Removed Plugins', 'vigilante' ); ?></h2>
6544 <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>
6545 <table class="wp-list-table widefat fixed striped">
6546 <thead>
6547 <tr>
6548 <th><?php esc_html_e( 'Plugin', 'vigilante' ); ?></th>
6549 <th style="width: 110px;"><?php esc_html_e( 'State', 'vigilante' ); ?></th>
6550 <th style="width: 120px;"><?php esc_html_e( 'Closed date', 'vigilante' ); ?></th>
6551 <th style="width: 130px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6552 </tr>
6553 </thead>
6554 <tbody>
6555 <?php foreach ( $ignored_closed_plugins as $icp_slug => $icp_entry ) :
6556 $icp_state = $icp_entry['state'] ?? '';
6557 $icp_state_label = 'closed' === $icp_state ? __( 'Closed', 'vigilante' ) : __( 'Removed', 'vigilante' );
6558 ?>
6559 <tr>
6560 <td>
6561 <strong><?php echo esc_html( $icp_entry['name'] ?? $icp_slug ); ?></strong><br>
6562 <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>
6563 </td>
6564 <td><?php echo esc_html( $icp_state_label ); ?></td>
6565 <td><?php echo esc_html( $icp_entry['closed_date'] ?? '' ); ?></td>
6566 <td>
6567 <button type="button" class="button button-small vigilante-unignore-closed-plugin" data-slug="<?php echo esc_attr( $icp_slug ); ?>">
6568 <?php esc_html_e( 'Stop ignoring', 'vigilante' ); ?>
6569 </button>
6570 </td>
6571 </tr>
6572 <?php endforeach; ?>
6573 </tbody>
6574 </table>
6575 <p style="margin-top: 10px;">
6576 <button type="button" class="button vigilante-clear-ignored-closed-plugins"><?php esc_html_e( 'Clear All Ignored Closed + Removed Plugins', 'vigilante' ); ?></button>
6577 </p>
6578 </div>
6579 <?php endif; ?>
6580
6581 <?php if ( ! empty( $ignored_files ) ) : ?>
6582 <div id="vigilante-section-fi-ignored" class="vigilante-settings-section">
6583 <h2><?php esc_html_e( 'Ignored Files', 'vigilante' ); ?></h2>
6584 <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>
6585 <div class="vigilante-paginated-section" data-bulk-mode="unignore">
6586 <div class="vigilante-fi-bulk-bar">
6587 <button type="button" class="button vigilante-bulk-unignore" disabled><?php esc_html_e( 'Stop ignoring selected', 'vigilante' ); ?></button>
6588 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
6589 </div>
6590 <div class="vigilante-fi-pagination-wrap"></div>
6591 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
6592 <thead>
6593 <tr>
6594 <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>
6595 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6596 <th style="width: 120px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6597 </tr>
6598 </thead>
6599 <tbody>
6600 <?php foreach ( $ignored_files as $file ) : ?>
6601 <tr>
6602 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file ); ?>"></th>
6603 <td><code><?php echo esc_html( $file ); ?></code></td>
6604 <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>
6605 </tr>
6606 <?php endforeach; ?>
6607 </tbody>
6608 </table>
6609 </div>
6610 <p style="margin-top: 10px;">
6611 <button type="button" class="button vigilante-clear-ignored"><?php esc_html_e( 'Clear All Ignored Files', 'vigilante' ); ?></button>
6612 </p>
6613 </div>
6614 <?php endif; ?>
6615 <?php
6616 }
6617
6618 /**
6619 * Render sidebar with promotional widgets
6620 */
6621 private function render_sidebar() {
6622 $promo_banner = new Vigilante_Promo_Banner( 'vigilante' );
6623 $promo_banner->render();
6624 }
6625
6626 /**
6627 * AJAX: Download a ZIP backup of the critical config files.
6628 *
6629 * Streams wp-config.php and .htaccess (and robots.txt if present) as a
6630 * downloadable archive. Config backups are no longer left as files under the
6631 * web root, so this hands the admin the archive directly.
6632 */
6633 public function ajax_download_files_backup() {
6634 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
6635
6636 if ( ! current_user_can( 'manage_options' ) ) {
6637 wp_die( esc_html__( 'Permission denied.', 'vigilante' ), 403 );
6638 }
6639
6640 // The archive carries wp-config.php, which a whole network shares. On a
6641 // network manage_options is held by every subsite administrator, so the
6642 // same gate the writers use applies here.
6643 if ( ! Vigilante_Settings::can_write_shared_files() ) {
6644 wp_die( esc_html( Vigilante_Settings::get_shared_files_notice() ), 403 );
6645 }
6646
6647 $backup_manager = new Vigilante_Backup_Manager();
6648 $result = $backup_manager->stream_files_zip();
6649
6650 // stream_files_zip() exits on success; only a WP_Error returns here.
6651 if ( is_wp_error( $result ) ) {
6652 wp_die( esc_html( $result->get_error_message() ), 500 );
6653 }
6654 }
6655
6656 /**
6657 * AJAX: Save settings
6658 */
6659 public function ajax_save_settings() {
6660 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
6661
6662 if ( ! current_user_can( 'manage_options' ) ) {
6663 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
6664 }
6665
6666 $section = isset( $_POST['section'] ) ? sanitize_key( $_POST['section'] ) : '';
6667
6668 // Handle $_POST['data'] based on type
6669 if ( isset( $_POST['data'] ) && is_array( $_POST['data'] ) ) {
6670 $data = map_deep( wp_unslash( $_POST['data'] ), 'sanitize_text_field' );
6671 } elseif ( isset( $_POST['data'] ) ) {
6672 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
6673 $raw_data = wp_unslash( $_POST['data'] );
6674 parse_str( $raw_data, $data );
6675 $data = map_deep( $data, 'sanitize_textarea_field' );
6676 } else {
6677 $data = array();
6678 }
6679
6680 if ( empty( $section ) ) {
6681 wp_send_json_error( __( 'Invalid section.', 'vigilante' ) );
6682 }
6683
6684 // Check if 2FA is being enabled or method changed (for notification sending)
6685 $send_2fa_notification = false;
6686 $send_login_url_notification = false;
6687
6688 if ( 'login_security' === $section ) {
6689 // Read old state from DB
6690 $db_options = get_option( Vigilante_Settings::OPTION_NAME, array() );
6691 $old_2fa_enabled = ! empty( $db_options['login_security']['two_factor']['enabled'] );
6692 $old_method = $db_options['login_security']['two_factor']['method'] ?? 'email';
6693
6694 // Check new state from submitted data
6695 $new_2fa_enabled = false;
6696 $notify_on_enable = false;
6697 $new_method = isset( $data['login_security']['two_factor']['method'] )
6698 ? sanitize_key( $data['login_security']['two_factor']['method'] )
6699 : 'email';
6700
6701 if ( isset( $data['login_security']['two_factor']['enabled'] ) ) {
6702 $new_2fa_enabled = filter_var( $data['login_security']['two_factor']['enabled'], FILTER_VALIDATE_BOOLEAN );
6703 }
6704 if ( isset( $data['login_security']['two_factor']['notify_on_enable'] ) ) {
6705 $notify_on_enable = filter_var( $data['login_security']['two_factor']['notify_on_enable'], FILTER_VALIDATE_BOOLEAN );
6706 }
6707
6708 // Send notification if:
6709 // 1. 2FA is being enabled (was off, now on) OR
6710 // 2. Method changed while 2FA is enabled
6711 if ( $notify_on_enable && $new_2fa_enabled ) {
6712 if ( ! $old_2fa_enabled || ( $old_2fa_enabled && $old_method !== $new_method ) ) {
6713 $send_2fa_notification = true;
6714 }
6715 }
6716
6717 // Check if login URL changed and notification is enabled
6718 $old_login_url = $db_options['login_security']['custom_login_url'] ?? '';
6719 $new_login_url = isset( $data['login_security']['custom_login_url'] )
6720 ? sanitize_title( $data['login_security']['custom_login_url'] )
6721 : '';
6722 $notify_on_url_change = isset( $data['login_security']['notify_on_login_url_change'] )
6723 ? filter_var( $data['login_security']['notify_on_login_url_change'], FILTER_VALIDATE_BOOLEAN )
6724 : false;
6725
6726 if ( $notify_on_url_change && ! empty( $new_login_url ) && $new_login_url !== $old_login_url ) {
6727 $send_login_url_notification = true;
6728 }
6729 }
6730
6731 // Get defaults
6732 $defaults = $this->settings->get_default_options();
6733
6734 // Read ONLY saved options from database (not merged with defaults)
6735 $saved_options = get_option( Vigilante_Settings::OPTION_NAME, array() );
6736
6737 $rejected_ips = array();
6738
6739 // Handle modules
6740 if ( 'modules' === $section && isset( $data['modules'] ) ) {
6741 if ( ! isset( $saved_options['modules'] ) ) {
6742 $saved_options['modules'] = array();
6743 }
6744 foreach ( $data['modules'] as $module => $enabled ) {
6745 $module = sanitize_key( $module );
6746 $saved_options['modules'][ $module ] = in_array( $enabled, array( '1', 1, 'true', true ), true );
6747 }
6748 // Clear active preset when modules change
6749 update_option( 'vigilante_active_preset', '' );
6750 } else {
6751 // Process primary section
6752 if ( isset( $data[ $section ] ) && is_array( $data[ $section ] ) ) {
6753 $section_defaults = isset( $defaults[ $section ] ) ? $defaults[ $section ] : array();
6754 $current_section = isset( $saved_options[ $section ] ) ? $saved_options[ $section ] : array();
6755
6756 // Process the submitted data
6757 $processed = $this->process_section_data( $data[ $section ], $section_defaults, $current_section );
6758
6759 // The IP boxes are free text and, until 2.9.9, whatever was typed
6760 // went straight into the option. An entry the matcher can never
6761 // match still sits in a security list looking like protection,
6762 // so the ones that cannot match are dropped and reported back
6763 // instead of being stored in silence.
6764 $rejected_ips = $this->filter_ip_lists( $section, $processed );
6765
6766 // Save the processed section
6767 $saved_options[ $section ] = $processed;
6768
6769 // Clear active preset when any section settings change
6770 update_option( 'vigilante_active_preset', '' );
6771 }
6772 }
6773
6774 // Clear cache before saving
6775 wp_cache_delete( Vigilante_Settings::OPTION_NAME, 'options' );
6776
6777 // Save to database
6778 update_option( Vigilante_Settings::OPTION_NAME, $saved_options );
6779
6780 // Clear the settings cache
6781 $this->settings->clear_cache();
6782
6783 // Apply changes based on section
6784 $this->apply_section_changes( $section, $saved_options );
6785
6786 // Send 2FA notifications after settings are saved
6787 $notification_result = null;
6788 if ( $send_2fa_notification ) {
6789 $notification_result = $this->send_2fa_enable_notifications();
6790 }
6791
6792 // Send login URL notifications after settings are saved
6793 $login_url_result = null;
6794 if ( $send_login_url_notification ) {
6795 $login_url_result = $this->send_login_url_notifications();
6796 }
6797
6798 // Build success message
6799 $message = __( 'Settings saved successfully.', 'vigilante' );
6800
6801 if ( $notification_result && $notification_result['sent'] > 0 ) {
6802 $message .= ' ' . sprintf(
6803 /* translators: %d: Number of emails sent */
6804 _n(
6805 '2FA notification sent to %d user.',
6806 '2FA notifications sent to %d users.',
6807 $notification_result['sent'],
6808 'vigilante'
6809 ),
6810 $notification_result['sent']
6811 );
6812 }
6813
6814 if ( $login_url_result && $login_url_result['sent'] > 0 ) {
6815 $message .= ' ' . sprintf(
6816 /* translators: %d: Number of emails sent */
6817 _n(
6818 'Login URL notification sent to %d user.',
6819 'Login URL notifications sent to %d users.',
6820 $login_url_result['sent'],
6821 'vigilante'
6822 ),
6823 $login_url_result['sent']
6824 );
6825 }
6826
6827 if ( ! empty( $rejected_ips ) ) {
6828 $message .= ' ' . sprintf(
6829 /* translators: %s: comma separated list of the entries that were not saved. */
6830 _n(
6831 'This entry is not a valid IP, CIDR range or wildcard, so it was not saved: %s',
6832 'These entries are not valid IPs, CIDR ranges or wildcards, so they were not saved: %s',
6833 count( $rejected_ips ),
6834 'vigilante'
6835 ),
6836 implode( ', ', array_map( 'esc_html', $rejected_ips ) )
6837 );
6838 }
6839
6840 wp_send_json_success( $message );
6841 }
6842
6843 /**
6844 * Keep only the IP patterns the matcher can actually match
6845 *
6846 * @since 2.9.9
6847 *
6848 * @param string $section Section being saved.
6849 * @param array $processed Section data, edited in place.
6850 * @return array Entries that were dropped, for the message back to the user.
6851 */
6852 private function filter_ip_lists( $section, &$processed ) {
6853 $lists = array(
6854 'firewall' => array( 'ip_whitelist', 'ip_blacklist' ),
6855 'login_security' => array( 'ip_whitelist' ),
6856 );
6857
6858 if ( ! isset( $lists[ $section ] ) ) {
6859 return array();
6860 }
6861
6862 $rejected = array();
6863
6864 foreach ( $lists[ $section ] as $key ) {
6865 if ( ! isset( $processed[ $key ] ) || ! is_array( $processed[ $key ] ) ) {
6866 continue;
6867 }
6868
6869 $split = Vigilante_IP_Utils::split_list( $processed[ $key ] );
6870 $processed[ $key ] = $split['valid'];
6871 $rejected = array_merge( $rejected, $split['rejected'] );
6872 }
6873
6874 return array_values( array_unique( $rejected ) );
6875 }
6876
6877 /**
6878 * Send 2FA enable notifications to users
6879 *
6880 * @return array Result with 'sent' and 'failed' counts.
6881 */
6882 private function send_2fa_enable_notifications() {
6883 $result = array(
6884 'sent' => 0,
6885 'failed' => 0,
6886 );
6887
6888 // Get settings for roles and method
6889 $login_security = $this->settings->get_section( 'login_security' );
6890 $two_factor = isset( $login_security['two_factor'] ) ? $login_security['two_factor'] : array();
6891 $roles = isset( $two_factor['enforced_roles'] ) ? $two_factor['enforced_roles'] : array( 'administrator' );
6892 $method = isset( $two_factor['method'] ) ? $two_factor['method'] : 'email';
6893
6894 if ( empty( $roles ) ) {
6895 $roles = array( 'administrator' );
6896 }
6897
6898 $excluded = isset( $two_factor['excluded_users'] ) ? array_map( 'absint', $two_factor['excluded_users'] ) : array();
6899
6900 // Get users with these roles
6901 $args = array(
6902 'role__in' => $roles,
6903 );
6904 if ( ! empty( $excluded ) ) {
6905 // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- Small excluded users list from settings.
6906 $args['exclude'] = $excluded;
6907 }
6908 $users = get_users( $args );
6909
6910 if ( empty( $users ) ) {
6911 return $result;
6912 }
6913
6914 $site_name = get_bloginfo( 'name' );
6915 $from_name = ! empty( $two_factor['email_from_name'] ) ? $two_factor['email_from_name'] : $site_name;
6916
6917 if ( 'totp' === $method ) {
6918 // Use TOTP class for styled HTML emails
6919 if ( ! class_exists( 'Vigilante_Two_Factor_TOTP' ) ) {
6920 require_once VIGILANTE_INCLUDES_DIR . 'class-two-factor-totp.php';
6921 }
6922 $totp = new Vigilante_Two_Factor_TOTP( $this->settings, $this->database, $this->activity_log );
6923
6924 foreach ( $users as $user ) {
6925 // Skip users who already have TOTP configured
6926 $totp_data = $this->database->get_totp_data( $user->ID );
6927 if ( $totp_data && ! empty( $totp_data['is_configured'] ) ) {
6928 continue;
6929 }
6930
6931 $sent = $totp->send_activation_email( $user, $site_name, $from_name );
6932
6933 if ( $sent ) {
6934 $this->database->mark_2fa_notified( $user->ID );
6935 $result['sent']++;
6936 } else {
6937 $result['failed']++;
6938 }
6939 }
6940 } else {
6941 // Email method - use existing email 2FA class
6942 if ( ! class_exists( 'Vigilante_Two_Factor_Email' ) ) {
6943 require_once VIGILANTE_INCLUDES_DIR . 'class-two-factor-email.php';
6944 }
6945 $email_2fa = new Vigilante_Two_Factor_Email( $this->settings, $this->database, $this->activity_log );
6946 return $email_2fa->send_activation_notifications( false );
6947 }
6948
6949 return $result;
6950 }
6951
6952 /**
6953 * Send login URL change notifications to users with admin access
6954 *
6955 * @return array Result with 'sent' and 'failed' counts.
6956 */
6957 private function send_login_url_notifications() {
6958 $login_options = $this->settings->get_section( 'login_security' );
6959 $custom_url = ! empty( $login_options['custom_login_url'] ) ? sanitize_title( $login_options['custom_login_url'] ) : '';
6960
6961 if ( empty( $custom_url ) ) {
6962 return array( 'sent' => 0, 'failed' => 0 );
6963 }
6964
6965 $login_url = home_url( $custom_url . '/' );
6966 $site_name = get_bloginfo( 'name' );
6967
6968 $admin_roles = array( 'administrator', 'editor', 'author', 'contributor' );
6969 $users = get_users( array( 'role__in' => $admin_roles ) );
6970
6971 if ( empty( $users ) ) {
6972 return array( 'sent' => 0, 'failed' => 0 );
6973 }
6974
6975 $subject = sprintf(
6976 /* translators: %s: Site name */
6977 __( '[%s] Your login URL has changed', 'vigilante' ),
6978 $site_name
6979 );
6980
6981 $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' ) );
6982 $body .= Vigilante_Email_Template::url_box( $login_url, __( 'Your new login URL:', 'vigilante' ) );
6983 $body .= Vigilante_Email_Template::alert_box( __( 'The old login address (wp-login.php) will no longer work.', 'vigilante' ) );
6984 $body .= Vigilante_Email_Template::button( $login_url, __( 'Go to login', 'vigilante' ) );
6985
6986 $sent = 0;
6987 $failed = 0;
6988
6989 foreach ( $users as $user ) {
6990 $result = Vigilante_Email_Template::send(
6991 $user->user_email,
6992 $subject,
6993 __( 'Login URL changed', 'vigilante' ),
6994 $body
6995 );
6996 if ( $result ) {
6997 $sent++;
6998 } else {
6999 $failed++;
7000 }
7001 }
7002
7003 if ( $this->activity_log ) {
7004 $this->activity_log->log(
7005 'login',
7006 'login_url_notified',
7007 sprintf(
7008 /* translators: 1: Sent count, 2: Failed count */
7009 __( 'Login URL notification sent on save: %1$d sent, %2$d failed', 'vigilante' ),
7010 $sent,
7011 $failed
7012 )
7013 );
7014 }
7015
7016 return array( 'sent' => $sent, 'failed' => $failed );
7017 }
7018
7019 /**
7020 * Process section data maintaining proper types from defaults
7021 *
7022 * @param array $submitted_data Data submitted from form.
7023 * @param array $defaults Default values for this section.
7024 * @param array $current Current saved values.
7025 * @param string $section_name Section name for special handling.
7026 * @return array Processed data.
7027 */
7028 private function process_section_data( $submitted_data, $defaults, $current, $section_name = '' ) {
7029 // Start with defaults, then merge current saved values
7030 $result = array_replace_recursive( $defaults, $current );
7031
7032 // Process each submitted value
7033 foreach ( $submitted_data as $key => $value ) {
7034 $key = sanitize_key( $key );
7035
7036 if ( is_array( $value ) ) {
7037 // Nested array (like rate_limiting)
7038 $nested_defaults = isset( $defaults[ $key ] ) && is_array( $defaults[ $key ] ) ? $defaults[ $key ] : array();
7039 $nested_current = isset( $result[ $key ] ) && is_array( $result[ $key ] ) ? $result[ $key ] : array();
7040 $result[ $key ] = $this->process_section_data( $value, $nested_defaults, $nested_current, $key );
7041 } else {
7042 // Determine type from default value
7043 $default_value = isset( $defaults[ $key ] ) ? $defaults[ $key ] : null;
7044
7045 if ( null === $default_value ) {
7046 // No default, check current value type or use as string
7047 $current_value = isset( $current[ $key ] ) ? $current[ $key ] : null;
7048 if ( is_bool( $current_value ) ) {
7049 $result[ $key ] = in_array( $value, array( '1', 1, 'true', true ), true );
7050 } elseif ( is_int( $current_value ) ) {
7051 $result[ $key ] = intval( $value );
7052 } elseif ( is_array( $current_value ) ) {
7053 $result[ $key ] = is_string( $value ) ? array_filter( array_map( 'trim', explode( "\n", $value ) ) ) : (array) $value;
7054 } else {
7055 $result[ $key ] = sanitize_text_field( $value );
7056 }
7057 } elseif ( is_bool( $default_value ) ) {
7058 // Boolean: '1', 1, 'true' become true; '0', 0, '', 'false' become false
7059 $result[ $key ] = in_array( $value, array( '1', 1, 'true', true ), true );
7060 } elseif ( is_int( $default_value ) ) {
7061 // Integer - with special handling for time fields shown in minutes
7062 $int_value = intval( $value );
7063
7064 // Convert minutes to seconds for login_security duration fields
7065 // These are displayed as minutes in the form but stored as seconds
7066 if ( in_array( $key, array( 'lockout_duration', 'max_lockout_duration' ), true ) ) {
7067 $int_value = $int_value * 60;
7068 }
7069
7070 $result[ $key ] = $int_value;
7071 } elseif ( is_array( $default_value ) ) {
7072 // Array from textarea (e.g., IP lists)
7073 if ( is_string( $value ) ) {
7074 $result[ $key ] = array_filter( array_map( 'trim', explode( "\n", $value ) ) );
7075 } else {
7076 $result[ $key ] = (array) $value;
7077 }
7078 } else {
7079 // String - preserve newlines for textarea fields
7080 if ( is_string( $value ) && ( strpos( $value, "\n" ) !== false || strpos( $value, "\r" ) !== false ) ) {
7081 $result[ $key ] = sanitize_textarea_field( $value );
7082 } else {
7083 $result[ $key ] = sanitize_text_field( $value );
7084 }
7085 }
7086 }
7087 }
7088
7089 // Handle unchecked checkboxes: HTML forms don't submit unchecked boxes
7090 // If a boolean field exists in defaults but NOT in submitted_data, set it to false
7091 //
7092 // EXCEPTION: the top-level 'enabled' flag of every section is the
7093 // module's master switch and is controlled by the Dashboard module
7094 // toggle, NOT by a checkbox inside the section's form. Treating it
7095 // like a regular checkbox here would silently switch the module off
7096 // every time the user saves the tab — see the REST API enabled=false
7097 // regression. We only skip it at the top level (when section_name is
7098 // empty); nested 'enabled' fields like security_headers.csp.enabled
7099 // are real checkboxes and must keep the auto-unset behaviour.
7100 $preserve_top_level = array( 'enabled' );
7101
7102 foreach ( $defaults as $key => $default_value ) {
7103 if ( '' === $section_name && in_array( $key, $preserve_top_level, true ) ) {
7104 continue;
7105 }
7106 if ( is_bool( $default_value ) && ! array_key_exists( $key, $submitted_data ) ) {
7107 $result[ $key ] = false;
7108 } elseif ( is_array( $default_value ) && ! isset( $submitted_data[ $key ] ) ) {
7109 // Check if this is a flat value list (like excluded_users, enforced_roles, ip_whitelist)
7110 // vs a nested settings group (like rate_limiting, two_factor)
7111 // Flat lists: default is empty array OR all values are scalar
7112 $is_value_list = empty( $default_value );
7113 if ( ! $is_value_list ) {
7114 $is_value_list = true;
7115 foreach ( $default_value as $dv ) {
7116 if ( ! is_scalar( $dv ) ) {
7117 $is_value_list = false;
7118 break;
7119 }
7120 }
7121 }
7122
7123 if ( $is_value_list ) {
7124 // All items removed - reset to empty array
7125 $result[ $key ] = array();
7126 } else {
7127 // Nested settings group - handle boolean children
7128 foreach ( $default_value as $nested_key => $nested_default ) {
7129 if ( is_bool( $nested_default ) && isset( $result[ $key ] ) && is_array( $result[ $key ] ) ) {
7130 $nested_submitted = isset( $submitted_data[ $key ] ) && is_array( $submitted_data[ $key ] )
7131 ? $submitted_data[ $key ]
7132 : array();
7133 if ( ! array_key_exists( $nested_key, $nested_submitted ) ) {
7134 $result[ $key ][ $nested_key ] = false;
7135 }
7136 }
7137 }
7138 }
7139 }
7140 }
7141
7142 return $result;
7143 }
7144
7145 /**
7146 * AJAX: Export settings
7147 */
7148 public function ajax_export_settings() {
7149 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7150
7151 if ( ! current_user_can( 'manage_options' ) ) {
7152 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7153 }
7154
7155 $options = $this->settings->get_all_options();
7156 $filename = 'vigilante-settings-' . gmdate( 'Y-m-d-His' ) . '.json';
7157
7158 wp_send_json_success( array(
7159 'content' => wp_json_encode( $options, JSON_PRETTY_PRINT ),
7160 'filename' => $filename,
7161 ) );
7162 }
7163
7164 /**
7165 * AJAX: Import settings
7166 */
7167 public function ajax_import_settings() {
7168 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7169
7170 if ( ! current_user_can( 'manage_options' ) ) {
7171 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7172 }
7173
7174 // Accept both 'settings' (from JS) and 'content' (legacy).
7175 // Do NOT run sanitize_text_field() on the raw payload: it calls
7176 // wp_strip_all_tags() internally, which removes any "<...>" substring
7177 // and turns a valid export JSON into garbage if any stored value
7178 // contains < or > (htaccess snippets, email templates, etc.). The
7179 // real sanitization happens after json_decode(), via map_deep() on
7180 // the parsed array.
7181 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash
7182 $content = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : '';
7183 if ( empty( $content ) ) {
7184 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash
7185 $content = isset( $_POST['content'] ) ? wp_unslash( $_POST['content'] ) : '';
7186 }
7187
7188 if ( empty( $content ) || ! is_string( $content ) ) {
7189 wp_send_json_error( __( 'No content provided.', 'vigilante' ) );
7190 }
7191
7192 $imported = json_decode( $content, true );
7193
7194 if ( json_last_error() !== JSON_ERROR_NONE || ! is_array( $imported ) ) {
7195 wp_send_json_error( __( 'Invalid JSON format.', 'vigilante' ) );
7196 }
7197
7198 // Sanitize imported data recursively
7199 $imported = map_deep( $imported, 'sanitize_text_field' );
7200
7201 // Validate structure: only sections and keys of the schema survive, and
7202 // every value takes the type of its default. Until 2.11.0 this was an
7203 // array_replace_recursive() of the file over the defaults, so any key in
7204 // the file, known or not, landed in vigilante_options (S7). Sections
7205 // the file does not carry keep their defaults; a section it does carry
7206 // replaces the default one whole, because validate_options() has
7207 // already filled in whatever the file left out.
7208 $defaults = $this->settings->get_default_options();
7209 $validated = $this->settings->validate_options( $imported );
7210 $merged = $defaults;
7211
7212 foreach ( $validated as $section => $data ) {
7213 if ( is_array( $data ) ) {
7214 $merged[ $section ] = $data;
7215 }
7216 }
7217
7218 // Save
7219 update_option( Vigilante_Settings::OPTION_NAME, $merged );
7220 $this->settings->clear_cache();
7221
7222 // Re-evaluate the active preset marker. The imported config may match
7223 // a known preset exactly, partially, or not at all — without this step
7224 // the dashboard would keep showing whatever preset was active before
7225 // the import even if the new config no longer matches it.
7226 $matched_preset = $this->detect_matching_preset( $merged );
7227 if ( null === $matched_preset ) {
7228 delete_option( 'vigilante_active_preset' );
7229 } else {
7230 update_option( 'vigilante_active_preset', $matched_preset );
7231 }
7232
7233 // Apply file changes after import
7234 $this->apply_all_file_changes( $merged );
7235
7236 // Refresh the Security Analyzer score so the dashboard widget reflects
7237 // the imported config rather than the pre-import scan. Reuse the
7238 // post-Under-Attack scan hook (same job: full scan, async).
7239 if ( ! wp_next_scheduled( 'vigilante_under_attack_post_scan' ) ) {
7240 wp_schedule_single_event( time() + 5, 'vigilante_under_attack_post_scan' );
7241 }
7242
7243 wp_send_json_success( __( 'Settings imported successfully.', 'vigilante' ) );
7244 }
7245
7246 /**
7247 * Detect whether a vigilante_options array matches a known preset.
7248 *
7249 * A preset matches when every field the preset explicitly declares is
7250 * present in the config with the same (normalised) value. Fields outside
7251 * the preset are ignored — they may have been modified by the user before
7252 * applying the preset and do not invalidate the match. This mirrors how
7253 * apply_preset() now layers presets on top of the user's existing config.
7254 *
7255 * @param array $options The current/imported vigilante_options.
7256 * @return string|null Preset id ('standard', 'maximum') or null if custom.
7257 */
7258 private function detect_matching_preset( $options ) {
7259 if ( ! is_array( $options ) ) {
7260 return null;
7261 }
7262
7263 $presets = $this->settings->get_presets();
7264
7265 foreach ( $presets as $preset_id => $preset_data ) {
7266 unset( $preset_data['name'], $preset_data['description'] );
7267 if ( $this->preset_subset_matches( $preset_data, $options ) ) {
7268 return $preset_id;
7269 }
7270 }
7271
7272 return null;
7273 }
7274
7275 /**
7276 * Check whether every leaf value inside $preset_subset exists with the
7277 * same (normalised) value at the same path inside $config.
7278 *
7279 * @param mixed $preset_subset Branch of the preset definition.
7280 * @param mixed $config Same branch in the live/imported config.
7281 * @return bool
7282 */
7283 private function preset_subset_matches( $preset_subset, $config ) {
7284 if ( is_array( $preset_subset ) ) {
7285 if ( ! is_array( $config ) ) {
7286 return false;
7287 }
7288 foreach ( $preset_subset as $key => $value ) {
7289 if ( ! array_key_exists( $key, $config ) ) {
7290 return false;
7291 }
7292 if ( ! $this->preset_subset_matches( $value, $config[ $key ] ) ) {
7293 return false;
7294 }
7295 }
7296 return true;
7297 }
7298
7299 return $this->normalise_scalar_for_compare( $preset_subset ) === $this->normalise_scalar_for_compare( $config );
7300 }
7301
7302 /**
7303 * Normalise a scalar value so that the variants WordPress and the form
7304 * layer routinely produce ('1' / 1 / true → "1"; '' / '0' / 0 / false /
7305 * null → "") compare equal. Other values become strings unchanged.
7306 *
7307 * @param mixed $value
7308 * @return string
7309 */
7310 private function normalise_scalar_for_compare( $value ) {
7311 if ( is_bool( $value ) ) {
7312 return $value ? '1' : '';
7313 }
7314 if ( null === $value ) {
7315 return '';
7316 }
7317 if ( is_int( $value ) || is_float( $value ) ) {
7318 return (string) $value;
7319 }
7320 if ( is_string( $value ) ) {
7321 if ( 'true' === $value ) {
7322 return '1';
7323 }
7324 if ( 'false' === $value ) {
7325 return '';
7326 }
7327 return $value;
7328 }
7329 // Arrays and objects shouldn't reach here (handled by recursion above),
7330 // but if they do, fall back to a stable comparable representation.
7331 return wp_json_encode( $value );
7332 }
7333
7334 /**
7335 * AJAX: Apply preset
7336 */
7337 public function ajax_apply_preset() {
7338 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7339
7340 if ( ! current_user_can( 'manage_options' ) ) {
7341 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7342 }
7343
7344 $preset = isset( $_POST['preset'] ) ? sanitize_key( $_POST['preset'] ) : '';
7345
7346 // Handle reset to defaults
7347 if ( 'reset' === $preset ) {
7348 $defaults = Vigilante_Settings::get_defaults_preserving_user_data( get_option( Vigilante_Settings::OPTION_NAME, array() ) );
7349 update_option( Vigilante_Settings::OPTION_NAME, $defaults );
7350 $this->settings->clear_cache();
7351
7352 // Clear active preset
7353 update_option( 'vigilante_active_preset', '' );
7354
7355 // Apply file changes after reset
7356 $this->apply_all_file_changes( $defaults );
7357
7358 wp_send_json_success( __( 'Settings reset to defaults.', 'vigilante' ) );
7359 return;
7360 }
7361
7362 $presets = $this->settings->get_presets();
7363
7364 if ( ! isset( $presets[ $preset ] ) ) {
7365 wp_send_json_error( __( 'Invalid preset.', 'vigilante' ) );
7366 }
7367
7368 $preset_options = $presets[ $preset ];
7369 unset( $preset_options['name'], $preset_options['description'] );
7370
7371 // Layer the preset on top of the user's CURRENT configuration, not on
7372 // top of defaults. This way applying a preset only changes the fields
7373 // the preset explicitly mentions; everything else stays as the user
7374 // had it. For example, applying Maximum will not flip HSTS off if the
7375 // user had it on — Maximum doesn't touch HSTS, so it's left alone.
7376 // Use "Reset to Defaults" if a clean slate is needed.
7377 $current = get_option( Vigilante_Settings::OPTION_NAME, array() );
7378 if ( ! is_array( $current ) ) {
7379 $current = array();
7380 }
7381 // Make sure all known keys exist before merging — the merge does not
7382 // invent keys that are missing on both sides.
7383 $current = Vigilante_Settings::merge_preset( $this->settings->get_default_options(), $current );
7384
7385 $merged = Vigilante_Settings::merge_preset( $current, $preset_options );
7386
7387 update_option( Vigilante_Settings::OPTION_NAME, $merged );
7388 $this->settings->clear_cache();
7389
7390 // Save active preset
7391 update_option( 'vigilante_active_preset', $preset );
7392
7393 // Apply file changes after preset
7394 $this->apply_all_file_changes( $merged );
7395
7396 wp_send_json_success( __( 'Preset applied successfully.', 'vigilante' ) );
7397 }
7398
7399 /**
7400 * AJAX: Reset a specific section to defaults
7401 */
7402 public function ajax_reset_section() {
7403 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7404
7405 if ( ! current_user_can( 'manage_options' ) ) {
7406 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7407 }
7408
7409 $section = isset( $_POST['section'] ) ? sanitize_key( $_POST['section'] ) : '';
7410
7411 if ( empty( $section ) ) {
7412 wp_send_json_error( __( 'No section specified.', 'vigilante' ) );
7413 }
7414
7415 // Get current options and defaults. get_defaults_preserving_user_data()
7416 // applies the tweaks a fresh installation gets, so the button and a new
7417 // install agree, and keeps whatever the owner typed in.
7418 $current_options = $this->settings->get_all_options();
7419 $defaults = Vigilante_Settings::get_defaults_preserving_user_data( $current_options );
7420
7421 // Check if section exists in defaults
7422 if ( ! isset( $defaults[ $section ] ) ) {
7423 wp_send_json_error( __( 'Invalid section.', 'vigilante' ) );
7424 }
7425
7426 $new_values = $defaults[ $section ];
7427
7428 /*
7429 * On a subsite, the settings written to wp-config.php and .htaccess are
7430 * the main site's business. Resetting the local copy of those would only
7431 * make this screen disagree with the file, so they are carried over
7432 * untouched, and a section that is nothing but shared settings is not
7433 * reset at all.
7434 */
7435 if ( ! Vigilante_Settings::can_write_shared_files() ) {
7436 $shared = Vigilante_Settings::get_shared_file_settings();
7437
7438 if ( isset( $shared[ $section ] ) ) {
7439 if ( true === $shared[ $section ] ) {
7440 wp_send_json_error( Vigilante_Settings::get_shared_files_notice() );
7441 }
7442
7443 foreach ( $shared[ $section ] as $shared_key ) {
7444 if ( array_key_exists( $shared_key, (array) $current_options[ $section ] ) ) {
7445 $new_values[ $shared_key ] = $current_options[ $section ][ $shared_key ];
7446 }
7447 }
7448 }
7449 }
7450
7451 $current_options[ $section ] = $new_values;
7452
7453 // Save
7454 update_option( Vigilante_Settings::OPTION_NAME, $current_options );
7455 $this->settings->clear_cache();
7456
7457 // Apply file changes if needed
7458 $this->apply_section_changes( $section, $current_options );
7459
7460 wp_send_json_success( array(
7461 'message' => __( 'Section reset to defaults.', 'vigilante' ),
7462 'section' => $section,
7463 'reload' => true,
7464 ) );
7465 }
7466
7467 /**
7468 * AJAX: Clear lockouts
7469 */
7470 public function ajax_clear_lockouts() {
7471 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7472
7473 if ( ! current_user_can( 'manage_options' ) ) {
7474 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7475 }
7476
7477 $ip = isset( $_POST['ip'] ) ? sanitize_text_field( wp_unslash( $_POST['ip'] ) ) : '';
7478
7479 if ( ! empty( $ip ) ) {
7480 $this->database->clear_lockout( $ip );
7481 } else {
7482 $this->database->clear_all_lockouts();
7483 }
7484
7485 wp_send_json_success( __( 'Lockouts cleared.', 'vigilante' ) );
7486 }
7487
7488 /**
7489 * AJAX: Clear logs
7490 */
7491 public function ajax_clear_logs() {
7492 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7493
7494 if ( ! current_user_can( 'manage_options' ) ) {
7495 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7496 }
7497
7498 if ( $this->activity_log ) {
7499 $result = $this->activity_log->clear_all_logs();
7500 if ( $result ) {
7501 wp_send_json_success( __( 'Logs cleared.', 'vigilante' ) );
7502 } else {
7503 wp_send_json_error( __( 'Failed to clear logs.', 'vigilante' ) );
7504 }
7505 } else {
7506 wp_send_json_error( __( 'Activity log not available.', 'vigilante' ) );
7507 }
7508 }
7509
7510 /**
7511 * AJAX: Run file integrity scan.
7512 *
7513 * Triggers the file integrity scan, which now also runs the closed plugins
7514 * check at the end when the `check_closed_plugins` toggle is on. Activity
7515 * log is passed through so Security Audit entries (both file-level and
7516 * plugin-status) are recorded from this entry point.
7517 */
7518 public function ajax_run_scan() {
7519 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7520
7521 if ( ! current_user_can( 'manage_options' ) ) {
7522 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7523 }
7524
7525 // Clear previous results before running new scan
7526 delete_option( 'vigilante_last_integrity_results' );
7527 delete_option( 'vigilante_last_integrity_scan' );
7528
7529 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database, $this->activity_log );
7530 $results = $file_integrity->run_scan();
7531
7532 // Save new results
7533 update_option( 'vigilante_last_integrity_scan', time() );
7534 update_option( 'vigilante_last_integrity_results', $results );
7535
7536 wp_send_json_success( array(
7537 'message' => __( 'Scan completed.', 'vigilante' ),
7538 'results' => $results,
7539 'ignored_count' => count( get_option( 'vigilante_ignored_files', array() ) ),
7540 ) );
7541 }
7542
7543 /**
7544 * AJAX: Clear scan results.
7545 *
7546 * Wipes visually everything inside "Last Scan Results": file scan findings
7547 * (Suspicious / Modified / Extra / Critical Config), file hashes and the
7548 * Closed + Removed Plugins block.
7549 *
7550 * Implementation detail to keep persistence intact:
7551 * - We delete the file scan options + hashes outright.
7552 * - For plugin status we ONLY delete the last_check timestamp — the state
7553 * map and the ignore list are preserved in DB. The render gates the
7554 * plugin_status subsections on last_check > 0, so they hide after
7555 * Clear (visual reset) and reappear on the next Run Scan Now with the
7556 * state intact. This avoids degrading a 'removed' slug (404 without
7557 * metadata) back to 'not_in_repo' on the next scan, which would
7558 * silently lose the alert.
7559 *
7560 * The Ignored Files list and the Ignored Closed + Removed Plugins list
7561 * are preserved on purpose; each has its own explicit "Clear All …"
7562 * button.
7563 */
7564 public function ajax_clear_scan() {
7565 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7566
7567 if ( ! current_user_can( 'manage_options' ) ) {
7568 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7569 }
7570
7571 delete_option( 'vigilante_last_integrity_results' );
7572 delete_option( 'vigilante_last_integrity_scan' );
7573
7574 if ( $this->database ) {
7575 $this->database->clear_file_hashes();
7576 }
7577
7578 // Visual reset of plugin_status block without touching the state map
7579 // or the ignored list. See PHPDoc above for the rationale.
7580 delete_option( 'vigilante_plugin_status_last_check' );
7581
7582 wp_send_json_success( __( 'Scan results cleared.', 'vigilante' ) );
7583 }
7584
7585 /**
7586 * AJAX: Ignore a file from scan results
7587 */
7588 public function ajax_ignore_file() {
7589 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7590
7591 if ( ! current_user_can( 'manage_options' ) ) {
7592 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7593 }
7594
7595 $file = isset( $_POST['file'] ) ? sanitize_text_field( wp_unslash( $_POST['file'] ) ) : '';
7596
7597 if ( empty( $file ) ) {
7598 wp_send_json_error( __( 'No file specified.', 'vigilante' ) );
7599 }
7600
7601 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7602 $file_integrity->ignore_file( $file );
7603
7604 // Also remove the file from stored scan results so UI updates
7605 $results = get_option( 'vigilante_last_integrity_results' );
7606 if ( $results ) {
7607 foreach ( array( 'modified', 'suspicious', 'extra' ) as $category ) {
7608 if ( ! empty( $results[ $category ] ) ) {
7609 $results[ $category ] = array_values(
7610 array_filter(
7611 $results[ $category ],
7612 function ( $item ) use ( $file ) {
7613 return ( is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item ) !== $file;
7614 }
7615 )
7616 );
7617 }
7618 }
7619 update_option( 'vigilante_last_integrity_results', $results );
7620 }
7621
7622 wp_send_json_success( __( 'File added to ignored list.', 'vigilante' ) );
7623 }
7624
7625 /**
7626 * AJAX: Stop ignoring a file
7627 */
7628 public function ajax_unignore_file() {
7629 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7630
7631 if ( ! current_user_can( 'manage_options' ) ) {
7632 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7633 }
7634
7635 $file = isset( $_POST['file'] ) ? sanitize_text_field( wp_unslash( $_POST['file'] ) ) : '';
7636
7637 if ( empty( $file ) ) {
7638 wp_send_json_error( __( 'No file specified.', 'vigilante' ) );
7639 }
7640
7641 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7642 $file_integrity->unignore_file( $file );
7643
7644 wp_send_json_success( __( 'File removed from ignored list.', 'vigilante' ) );
7645 }
7646
7647 /**
7648 * AJAX: Bulk ignore multiple files at once
7649 *
7650 * Processes a single batch into ignored list and prunes them from the
7651 * stored scan results so the UI updates without a re-scan.
7652 */
7653 public function ajax_bulk_ignore_files() {
7654 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7655
7656 if ( ! current_user_can( 'manage_options' ) ) {
7657 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7658 }
7659
7660 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized below per-item.
7661 $raw_files = isset( $_POST['files'] ) ? wp_unslash( $_POST['files'] ) : array();
7662 if ( ! is_array( $raw_files ) ) {
7663 wp_send_json_error( __( 'Invalid request.', 'vigilante' ) );
7664 }
7665
7666 $files = array();
7667 foreach ( $raw_files as $f ) {
7668 $clean = sanitize_text_field( $f );
7669 if ( '' !== $clean ) {
7670 $files[] = $clean;
7671 }
7672 }
7673
7674 if ( empty( $files ) ) {
7675 wp_send_json_error( __( 'No files selected.', 'vigilante' ) );
7676 }
7677
7678 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7679 $count = 0;
7680 foreach ( $files as $file ) {
7681 $file_integrity->ignore_file( $file );
7682 $count++;
7683 }
7684
7685 // Also prune the stored scan results so the UI matches the new ignore list.
7686 $results = get_option( 'vigilante_last_integrity_results' );
7687 if ( $results ) {
7688 $files_set = array_flip( $files );
7689 foreach ( array( 'modified', 'suspicious', 'extra' ) as $category ) {
7690 if ( ! empty( $results[ $category ] ) ) {
7691 $results[ $category ] = array_values(
7692 array_filter(
7693 $results[ $category ],
7694 function ( $item ) use ( $files_set ) {
7695 $path = is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item;
7696 return ! isset( $files_set[ $path ] );
7697 }
7698 )
7699 );
7700 }
7701 }
7702 update_option( 'vigilante_last_integrity_results', $results );
7703 }
7704
7705 wp_send_json_success(
7706 array(
7707 'count' => $count,
7708 'message' => sprintf(
7709 /* translators: %d: number of files added to the ignored list */
7710 _n( '%d file added to ignored list.', '%d files added to ignored list.', $count, 'vigilante' ),
7711 $count
7712 ),
7713 )
7714 );
7715 }
7716
7717 /**
7718 * AJAX: Bulk un-ignore multiple files at once
7719 */
7720 public function ajax_bulk_unignore_files() {
7721 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7722
7723 if ( ! current_user_can( 'manage_options' ) ) {
7724 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7725 }
7726
7727 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized below per-item.
7728 $raw_files = isset( $_POST['files'] ) ? wp_unslash( $_POST['files'] ) : array();
7729 if ( ! is_array( $raw_files ) ) {
7730 wp_send_json_error( __( 'Invalid request.', 'vigilante' ) );
7731 }
7732
7733 $files = array();
7734 foreach ( $raw_files as $f ) {
7735 $clean = sanitize_text_field( $f );
7736 if ( '' !== $clean ) {
7737 $files[] = $clean;
7738 }
7739 }
7740
7741 if ( empty( $files ) ) {
7742 wp_send_json_error( __( 'No files selected.', 'vigilante' ) );
7743 }
7744
7745 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7746 $count = 0;
7747 foreach ( $files as $file ) {
7748 $file_integrity->unignore_file( $file );
7749 $count++;
7750 }
7751
7752 wp_send_json_success(
7753 array(
7754 'count' => $count,
7755 'message' => sprintf(
7756 /* translators: %d: number of files removed from the ignored list */
7757 _n( '%d file removed from ignored list.', '%d files removed from ignored list.', $count, 'vigilante' ),
7758 $count
7759 ),
7760 )
7761 );
7762 }
7763
7764 /**
7765 * AJAX: Clear all ignored files
7766 */
7767 public function ajax_clear_ignored() {
7768 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7769
7770 if ( ! current_user_can( 'manage_options' ) ) {
7771 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7772 }
7773
7774 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7775 $file_integrity->clear_ignored_files();
7776
7777 wp_send_json_success( __( 'Ignored files list cleared.', 'vigilante' ) );
7778 }
7779
7780 /**
7781 * AJAX: Ignore a closed/removed plugin slug so it stops appearing in the
7782 * main list and email digests. The plugin keeps running on the site;
7783 * silencing is purely cosmetic and reversible.
7784 */
7785 public function ajax_ignore_closed_plugin() {
7786 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7787
7788 if ( ! current_user_can( 'manage_options' ) ) {
7789 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7790 }
7791
7792 $slug = isset( $_POST['slug'] ) ? sanitize_key( wp_unslash( $_POST['slug'] ) ) : '';
7793 if ( '' === $slug ) {
7794 wp_send_json_error( __( 'No slug specified.', 'vigilante' ) );
7795 }
7796
7797 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
7798 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
7799 }
7800 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
7801 $checker->ignore_slug( $slug );
7802
7803 wp_send_json_success( __( 'Plugin added to the ignored list.', 'vigilante' ) );
7804 }
7805
7806 /**
7807 * AJAX: Stop ignoring a previously-ignored closed/removed plugin slug.
7808 */
7809 public function ajax_unignore_closed_plugin() {
7810 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7811
7812 if ( ! current_user_can( 'manage_options' ) ) {
7813 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7814 }
7815
7816 $slug = isset( $_POST['slug'] ) ? sanitize_key( wp_unslash( $_POST['slug'] ) ) : '';
7817 if ( '' === $slug ) {
7818 wp_send_json_error( __( 'No slug specified.', 'vigilante' ) );
7819 }
7820
7821 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
7822 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
7823 }
7824 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
7825 $checker->unignore_slug( $slug );
7826
7827 wp_send_json_success( __( 'Plugin removed from the ignored list.', 'vigilante' ) );
7828 }
7829
7830 /**
7831 * AJAX: Clear the entire ignored-closed-plugins list.
7832 */
7833 public function ajax_clear_ignored_closed_plugins() {
7834 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7835
7836 if ( ! current_user_can( 'manage_options' ) ) {
7837 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7838 }
7839
7840 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
7841 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
7842 }
7843 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
7844 $checker->clear_ignored();
7845
7846 wp_send_json_success( __( 'Ignored closed plugins list cleared.', 'vigilante' ) );
7847 }
7848
7849 /**
7850 * AJAX: Test security headers
7851 */
7852 public function ajax_test_headers() {
7853 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7854
7855 if ( ! current_user_can( 'manage_options' ) ) {
7856 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7857 }
7858
7859 // Get security grade from settings (not from actual HTTP request)
7860 $security_headers = new Vigilante_Security_Headers( $this->settings );
7861 $results = $security_headers->get_security_grade();
7862
7863 wp_send_json_success( $results );
7864 }
7865
7866 /**
7867 * Sanitize section data (kept for compatibility)
7868 *
7869 * @param string $section Section name.
7870 * @param array $data Section data.
7871 * @return array
7872 */
7873 private function sanitize_section_data( $section, $data ) {
7874 $sanitized = array();
7875
7876 foreach ( $data as $key => $value ) {
7877 $key = sanitize_key( $key );
7878
7879 if ( is_array( $value ) ) {
7880 $sanitized[ $key ] = $this->sanitize_section_data( $key, $value );
7881 } elseif ( is_numeric( $value ) ) {
7882 $sanitized[ $key ] = intval( $value );
7883 } else {
7884 $sanitized[ $key ] = sanitize_text_field( $value );
7885 }
7886 }
7887
7888 return $sanitized;
7889 }
7890
7891 /**
7892 * Apply changes after saving settings
7893 *
7894 * @param string $section Section that was updated.
7895 * @param array $all_options All options.
7896 */
7897 private function apply_section_changes( $section, $all_options ) {
7898 // Create fresh settings instance to ensure we have the latest data
7899 $fresh_settings = new Vigilante_Settings();
7900
7901 // The shared Vigilant .htaccess block carries BOTH the firewall's
7902 // file-protection rules and the server-signature / fingerprinting rules
7903 // that are configured under Security Headers. So it must be regenerated
7904 // whenever either section (or the module toggles) changes, not only on
7905 // the firewall save — otherwise toggling "Hide server signature" or
7906 // "Remove fingerprinting headers" never reaches the .htaccess.
7907 if ( in_array( $section, array( 'firewall', 'security_headers', 'modules' ), true ) ) {
7908 $htaccess = new Vigilante_Htaccess_Protection( $fresh_settings );
7909 $sh = $fresh_settings->get_section( 'security_headers' );
7910 $needs_htaccess_block = ! empty( $all_options['modules']['firewall'] )
7911 || ! empty( $sh['hide_server_signature'] )
7912 || ! empty( $sh['remove_fingerprinting_headers'] );
7913
7914 if ( $needs_htaccess_block ) {
7915 $htaccess->apply_rules();
7916 } else {
7917 $htaccess->remove_rules();
7918 }
7919 }
7920
7921 // Regenerate the HTTP security headers (sent by PHP) for the headers section.
7922 if ( 'security_headers' === $section || 'modules' === $section ) {
7923 $security_headers = new Vigilante_Security_Headers( $fresh_settings );
7924 $headers_enabled = ! empty( $all_options['modules']['security_headers'] );
7925
7926 if ( $headers_enabled ) {
7927 $security_headers->apply_rules();
7928 } else {
7929 $security_headers->remove_rules();
7930 }
7931 }
7932
7933 // Regenerate wp-config for wp_hardening section
7934 if ( 'wp_hardening' === $section || 'modules' === $section ) {
7935 $wpconfig = new Vigilante_Wpconfig_Security( $fresh_settings );
7936 $hardening_enabled = ! empty( $all_options['modules']['wp_hardening'] );
7937
7938 if ( $hardening_enabled ) {
7939 $wpconfig->apply_security_constants();
7940 } else {
7941 $wpconfig->remove_constants();
7942 }
7943
7944 // Apply WordPress options for comments/pingbacks
7945 $hardening_options = $all_options['wp_hardening'] ?? array();
7946
7947 if ( $hardening_enabled ) {
7948 // Pingbacks
7949 if ( ! empty( $hardening_options['disable_pingbacks'] ) ) {
7950 update_option( 'default_pingback_flag', 0 );
7951 } else {
7952 // Restore default: pingbacks enabled
7953 update_option( 'default_pingback_flag', 1 );
7954 }
7955
7956 // Trackbacks and ping status
7957 // Only close if either pingbacks OR trackbacks are disabled
7958 if ( ! empty( $hardening_options['disable_pingbacks'] ) || ! empty( $hardening_options['disable_trackbacks'] ) ) {
7959 update_option( 'default_ping_status', 'closed' );
7960 } else {
7961 // Restore default: pings open
7962 update_option( 'default_ping_status', 'open' );
7963 }
7964
7965 // Comment moderation
7966 if ( ! empty( $hardening_options['require_comment_moderation'] ) ) {
7967 update_option( 'comment_moderation', 1 );
7968 } else {
7969 // Restore default: no moderation required
7970 update_option( 'comment_moderation', 0 );
7971 }
7972 }
7973 }
7974
7975 // Trim activity log entries immediately when limits change
7976 if ( 'activity_log' === $section && $this->activity_log ) {
7977 $this->activity_log->cleanup_old_logs();
7978 }
7979
7980 // Flush rewrite rules if login URL changed
7981 if ( 'login_security' === $section ) {
7982 $login_options = $all_options['login_security'] ?? array();
7983 if ( ! empty( $login_options['custom_login_url'] ) ) {
7984 delete_option( 'vigilante_login_rules_version' );
7985 }
7986 }
7987
7988 // Log the settings change with readable section name
7989 if ( $this->activity_log ) {
7990 $section_names = array(
7991 'firewall' => __( 'Firewall', 'vigilante' ),
7992 'login_security' => __( 'Login Security', 'vigilante' ),
7993 'security_headers' => __( 'Security Headers', 'vigilante' ),
7994 'rest_api_security'=> __( 'REST API Security', 'vigilante' ),
7995 'user_security' => __( 'User Security', 'vigilante' ),
7996 'wp_hardening' => __( 'WP Hardening', 'vigilante' ),
7997 'activity_log' => __( 'Security Audit', 'vigilante' ),
7998 'file_integrity' => __( 'File Integrity', 'vigilante' ),
7999 'email' => __( 'Notification Settings', 'vigilante' ),
8000 'backup' => __( 'Backup', 'vigilante' ),
8001 'advanced' => __( 'Advanced', 'vigilante' ),
8002 'modules' => __( 'Modules', 'vigilante' ),
8003 );
8004 $display_name = isset( $section_names[ $section ] ) ? $section_names[ $section ] : $section;
8005
8006 $this->activity_log->log(
8007 'settings',
8008 'settings_updated',
8009 sprintf(
8010 /* translators: %s: Section name */
8011 __( 'Settings updated: %s', 'vigilante' ),
8012 $display_name
8013 ),
8014 array( 'section' => $section ),
8015 'info'
8016 );
8017 }
8018 }
8019
8020 /**
8021 * Apply all file changes (htaccess, wp-config) based on current options
8022 *
8023 * Used after preset, import, or reset operations
8024 *
8025 * @param array $all_options All plugin options.
8026 */
8027 private function apply_all_file_changes( $all_options ) {
8028 // Refresh settings cache first
8029 $this->settings->clear_cache();
8030
8031 // Create fresh settings instance
8032 $fresh_settings = new Vigilante_Settings();
8033
8034 // Apply firewall htaccess changes
8035 $htaccess = new Vigilante_Htaccess_Protection( $fresh_settings );
8036 $firewall_enabled = ! empty( $all_options['modules']['firewall'] );
8037
8038 if ( $firewall_enabled ) {
8039 $htaccess->apply_rules();
8040 } else {
8041 $htaccess->remove_rules();
8042 }
8043
8044 // Apply security headers htaccess changes
8045 $security_headers = new Vigilante_Security_Headers( $fresh_settings );
8046 $headers_enabled = ! empty( $all_options['modules']['security_headers'] );
8047
8048 if ( $headers_enabled ) {
8049 $security_headers->apply_rules();
8050 } else {
8051 $security_headers->remove_rules();
8052 }
8053
8054 // Apply wp-config changes
8055 $wpconfig = new Vigilante_Wpconfig_Security( $fresh_settings );
8056 $hardening_enabled = ! empty( $all_options['modules']['wp_hardening'] );
8057
8058 if ( $hardening_enabled ) {
8059 $wpconfig->apply_security_constants();
8060 } else {
8061 $wpconfig->remove_constants();
8062 }
8063
8064 // Apply WordPress options for comments/pingbacks
8065 $hardening_options = $all_options['wp_hardening'] ?? array();
8066
8067 if ( $hardening_enabled ) {
8068 // Pingbacks
8069 if ( ! empty( $hardening_options['disable_pingbacks'] ) ) {
8070 update_option( 'default_pingback_flag', 0 );
8071 } else {
8072 // Restore default: pingbacks enabled
8073 update_option( 'default_pingback_flag', 1 );
8074 }
8075
8076 // Trackbacks and ping status
8077 // Only close if either pingbacks OR trackbacks are disabled
8078 if ( ! empty( $hardening_options['disable_pingbacks'] ) || ! empty( $hardening_options['disable_trackbacks'] ) ) {
8079 update_option( 'default_ping_status', 'closed' );
8080 } else {
8081 // Restore default: pings open
8082 update_option( 'default_ping_status', 'open' );
8083 }
8084
8085 // Comment moderation
8086 if ( ! empty( $hardening_options['require_comment_moderation'] ) ) {
8087 update_option( 'comment_moderation', 1 );
8088 } else {
8089 // Restore default: no moderation required
8090 update_option( 'comment_moderation', 0 );
8091 }
8092 }
8093
8094 // Log the change
8095 if ( $this->activity_log ) {
8096 $this->activity_log->log(
8097 'settings',
8098 'bulk_settings_applied',
8099 __( 'Bulk settings applied (preset/import/reset)', 'vigilante' ),
8100 array(),
8101 'info'
8102 );
8103 }
8104 }
8105 }