PluginProbe
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… / 3.0.2
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… v3.0.2
3.0.5 3.0.4 3.0.3 3.0.2 3.0.1 3.0.0 2.11.12 2.11.11 2.11.10 2.11.9 2.11.7 2.11.8 2.11.6 2.11.5 2.11.4 2.11.3 2.11.1 2.11.2 2.11.0 2.10.5 2.10.4 2.10.3 2.10.2 2.10.1 2.10.0 All 93 releases
vigilante / admin / class-admin.php

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

9,566 lines 598.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin Class
4 *
5 * Handles admin interface and settings page
6 *
7 * @package Vigilante
8 */
9
10 // Prevent direct access
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 // Load AJAX trait
16 require_once VIGILANTE_ADMIN_DIR . 'class-admin-ajax.php';
17
18 // Load promotional banner class
19 require_once VIGILANTE_INCLUDES_DIR . 'class-ayudawp-promo-banner.php';
20
21 /**
22 * Class Vigilante_Admin
23 *
24 * Manages the admin settings interface
25 */
26 class Vigilante_Admin {
27
28 use Vigilante_Admin_Ajax;
29 use Vigilante_Admin_Analyzer_Ajax;
30 use Vigilante_Admin_Audit_Alerts_Ajax;
31 use Vigilante_Admin_Recovery_Ajax;
32
33 /**
34 * Settings instance
35 *
36 * @var Vigilante_Settings
37 */
38 private $settings;
39
40 /**
41 * Database instance
42 *
43 * @var Vigilante_Database
44 */
45 private $database;
46
47 /**
48 * Activity log instance
49 *
50 * @var Vigilante_Activity_Log
51 */
52 private $activity_log;
53
54 /**
55 * Current tab
56 *
57 * @var string
58 */
59 private $current_tab = 'dashboard';
60
61 /**
62 * Available tabs
63 *
64 * @var array
65 */
66 private $tabs = array();
67
68 /**
69 * Constructor
70 *
71 * @param Vigilante_Settings $settings Settings instance.
72 * @param Vigilante_Database $database Database instance.
73 * @param Vigilante_Activity_Log $activity_log Activity log instance.
74 */
75 public function __construct( $settings, $database, $activity_log ) {
76 $this->settings = $settings;
77 $this->database = $database;
78 $this->activity_log = $activity_log;
79
80 $this->setup_tabs();
81 $this->init_hooks();
82 }
83
84 /**
85 * Setup available tabs
86 */
87 private function setup_tabs() {
88 $this->tabs = array(
89 'dashboard' => __( 'Dashboard', 'vigilante' ),
90 'firewall' => __( 'Firewall', 'vigilante' ),
91 'headers' => __( 'Security Headers', 'vigilante' ),
92 'login' => __( 'Login Security', 'vigilante' ),
93 'rest-api' => __( 'REST API', 'vigilante' ),
94 'users' => __( 'User Security', 'vigilante' ),
95 'wp-hardening' => __( 'WP Hardening', 'vigilante' ),
96 'file-integrity' => __( 'File Integrity', 'vigilante' ),
97 'activity-log' => __( 'Security Audit', 'vigilante' ),
98 'tools' => __( 'Settings & Tools', 'vigilante' ),
99 );
100 }
101
102 /**
103 * Initialize hooks
104 */
105 private function init_hooks() {
106 add_action( 'admin_menu', array( $this, 'add_menu' ) );
107 add_action( 'admin_init', array( $this, 'redirect_submenu_shortcuts' ) );
108 add_action( 'admin_init', array( $this, 'register_settings' ) );
109 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
110 add_action( 'admin_notices', array( $this, 'show_admin_notices' ) );
111 // Self-protection speaks in the network admin too: on a network its
112 // files are shared, and the super administrator is who can repair them.
113 add_action( 'network_admin_notices', array( $this, 'maybe_show_self_protection_notice' ) );
114
115 // Highlight correct submenu based on active tab
116 add_filter( 'submenu_file', array( $this, 'highlight_submenu_tab' ) );
117
118 // Set browser tab title to show plugin name and active tab
119 add_filter( 'admin_title', array( $this, 'set_admin_page_title' ), 10, 2 );
120
121 // AJAX handlers
122 add_action( 'wp_ajax_vigilante_save_settings', array( $this, 'ajax_save_settings' ) );
123 add_action( 'wp_ajax_vigilante_apply_preset', array( $this, 'ajax_apply_preset' ) );
124 add_action( 'wp_ajax_vigilante_reset_section', array( $this, 'ajax_reset_section' ) );
125 add_action( 'wp_ajax_vigilante_clear_lockouts', array( $this, 'ajax_clear_lockouts' ) );
126 add_action( 'wp_ajax_vigilante_clear_logs', array( $this, 'ajax_clear_logs' ) );
127 add_action( 'wp_ajax_vigilante_run_scan', array( $this, 'ajax_run_scan' ) );
128 add_action( 'wp_ajax_vigilante_clear_scan', array( $this, 'ajax_clear_scan' ) );
129 add_action( 'wp_ajax_vigilante_ignore_file', array( $this, 'ajax_ignore_file' ) );
130 add_action( 'wp_ajax_vigilante_unignore_file', array( $this, 'ajax_unignore_file' ) );
131 add_action( 'wp_ajax_vigilante_bulk_ignore_files', array( $this, 'ajax_bulk_ignore_files' ) );
132 add_action( 'wp_ajax_vigilante_bulk_unignore_files', array( $this, 'ajax_bulk_unignore_files' ) );
133 add_action( 'wp_ajax_vigilante_clear_ignored', array( $this, 'ajax_clear_ignored' ) );
134 add_action( 'wp_ajax_vigilante_ignore_closed_plugin', array( $this, 'ajax_ignore_closed_plugin' ) );
135 add_action( 'wp_ajax_vigilante_unignore_closed_plugin', array( $this, 'ajax_unignore_closed_plugin' ) );
136 add_action( 'wp_ajax_vigilante_clear_ignored_closed_plugins', array( $this, 'ajax_clear_ignored_closed_plugins' ) );
137 add_action( 'wp_ajax_vigilante_approve_critical_file', array( $this, 'ajax_approve_critical_file' ) );
138 add_action( 'wp_ajax_vigilante_export_settings', array( $this, 'ajax_export_settings' ) );
139 add_action( 'wp_ajax_vigilante_import_settings', array( $this, 'ajax_import_settings' ) );
140 add_action( 'wp_ajax_vigilante_get_logs', array( $this, 'ajax_get_logs' ) );
141 add_action( 'wp_ajax_vigilante_test_headers', array( $this, 'ajax_test_headers' ) );
142 add_action( 'wp_ajax_vigilante_download_files_backup', array( $this, 'ajax_download_files_backup' ) );
143
144 // 2FA AJAX handlers
145 add_action( 'wp_ajax_vigilante_search_users_2fa', array( $this, 'ajax_search_users_2fa' ) );
146 add_action( 'wp_ajax_vigilante_send_2fa_notification', array( $this, 'ajax_send_2fa_notification' ) );
147 add_action( 'wp_ajax_vigilante_search_totp_users', array( $this, 'ajax_search_totp_users' ) );
148 add_action( 'wp_ajax_vigilante_reset_totp_users', array( $this, 'ajax_reset_totp_users' ) );
149 add_action( 'wp_ajax_vigilante_totp_get_setup', array( $this, 'ajax_totp_get_setup' ) );
150 add_action( 'wp_ajax_vigilante_notify_login_url', array( $this, 'ajax_notify_login_url' ) );
151
152 // Password Reset AJAX handlers
153 add_action( 'wp_ajax_vigilante_search_users_password_reset', array( $this, 'ajax_search_users_password_reset' ) );
154 add_action( 'wp_ajax_vigilante_force_password_reset', array( $this, 'ajax_force_password_reset' ) );
155 add_action( 'wp_ajax_vigilante_force_password_reset_all', array( $this, 'ajax_force_password_reset_all' ) );
156 add_action( 'wp_ajax_vigilante_force_password_reset_by_role', array( $this, 'ajax_force_password_reset_by_role' ) );
157
158 // User approval AJAX handlers
159 add_action( 'wp_ajax_vigilante_approve_user', array( $this, 'ajax_approve_user' ) );
160 add_action( 'wp_ajax_vigilante_reject_user', array( $this, 'ajax_reject_user' ) );
161
162 // Session management AJAX handlers
163 add_action( 'wp_ajax_vigilante_get_user_sessions', array( $this, 'ajax_get_user_sessions' ) );
164 add_action( 'wp_ajax_vigilante_revoke_session', array( $this, 'ajax_revoke_session' ) );
165 add_action( 'wp_ajax_vigilante_revoke_all_sessions', array( $this, 'ajax_revoke_all_sessions' ) );
166
167 // Under Attack mode AJAX handlers
168 add_action( 'wp_ajax_vigilante_activate_under_attack', array( $this, 'ajax_activate_under_attack' ) );
169 add_action( 'wp_ajax_vigilante_deactivate_under_attack', array( $this, 'ajax_deactivate_under_attack' ) );
170 add_action( 'wp_ajax_vigilante_under_attack_status', array( $this, 'ajax_under_attack_status' ) );
171
172 // Database backup AJAX handlers
173 add_action( 'wp_ajax_vigilante_get_db_tables', array( $this, 'ajax_get_db_tables' ) );
174 add_action( 'wp_ajax_vigilante_download_db_backup', array( $this, 'ajax_download_db_backup' ) );
175
176 // Database prefix AJAX handlers
177 add_action( 'wp_ajax_vigilante_generate_prefix', array( $this, 'ajax_generate_prefix' ) );
178 add_action( 'wp_ajax_vigilante_change_prefix', array( $this, 'ajax_change_prefix' ) );
179
180 // Firewall list management from activity log popup
181 add_action( 'wp_ajax_vigilante_add_to_firewall_list', array( $this, 'ajax_add_to_firewall_list' ) );
182 add_action( 'wp_ajax_vigilante_unblock_firewall_ip', array( $this, 'ajax_unblock_firewall_ip' ) );
183
184 // Security Analyzer AJAX handlers (v2.1.0)
185 add_action( 'wp_ajax_vigilante_analyzer_run', array( $this, 'ajax_analyzer_run' ) );
186 add_action( 'wp_ajax_vigilante_analyzer_history', array( $this, 'ajax_analyzer_history' ) );
187 add_action( 'wp_ajax_vigilante_analyzer_dismiss_notice', array( $this, 'ajax_analyzer_dismiss_notice' ) );
188 add_action( 'wp_ajax_vigilante_analyzer_save_settings', array( $this, 'ajax_analyzer_save_settings' ) );
189
190 // Security Headers settings recovery (2.10.0)
191 add_action( 'wp_ajax_vigilante_headers_recovery_restore', array( $this, 'ajax_headers_recovery_restore' ) );
192 add_action( 'wp_ajax_vigilante_headers_recovery_undo', array( $this, 'ajax_headers_recovery_undo' ) );
193 add_action( 'wp_ajax_vigilante_headers_recovery_dismiss', array( $this, 'ajax_headers_recovery_dismiss' ) );
194
195 // Shared "Send test email" handler — Notification settings, File Integrity, Audit Alerts (v2.8.0)
196 add_action( 'wp_ajax_vigilante_send_test_email', array( $this, 'ajax_send_test_email' ) );
197
198 // Run migrations on admin load
199 add_action( 'admin_init', array( $this, 'run_migrations' ) );
200 }
201
202 /**
203 * Run database migrations based on stored version
204 */
205 public function run_migrations() {
206 /*
207 * admin-ajax.php fires admin_init before it decides who is asking
208 * (wp-admin/admin-ajax.php:45), so until 2.11.10 an anonymous POST to
209 * admin-ajax.php with any action ran every pending migration. That is
210 * not a read: the migrations rewrite wp-config.php through
211 * apply_security_constants(), rewrite the root .htaccess, move user meta
212 * of the whole network and can rebuild the file integrity baseline,
213 * taking whatever is on disk as approved. Reproduced on 12 sep 2026 with
214 * curl and no cookies, and found by the file-by-file review of 2.11.10.
215 *
216 * Migrations are maintenance for whoever administers the site, so they
217 * wait for an administrator to load a screen. Nothing is lost by
218 * waiting: every migration is idempotent and version gated.
219 */
220 if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
221 return;
222 }
223
224 $db_version = get_option( 'vigilante_db_version', '0' );
225
226 // 1.2.3: Fix IP lists corrupted by sanitize_text_field stripping newlines
227 if ( version_compare( $db_version, '1.2.3', '<' ) ) {
228 $this->migrate_fix_ip_lists();
229 update_option( 'vigilante_db_version', '1.2.3' );
230 }
231
232 // 1.3.0: Add request_method column to activity log table
233 if ( version_compare( $db_version, '1.3.0', '<' ) ) {
234 $this->database->run_migrations();
235 }
236
237 // 1.9.0: Re-apply wp-config constants (performance constants removed from managed list)
238 if ( version_compare( $db_version, '1.9.0', '<' ) ) {
239 if ( $this->settings->is_module_enabled( 'wp_hardening' ) ) {
240 require_once VIGILANTE_INCLUDES_DIR . 'class-wpconfig-security.php';
241 $wpconfig = new Vigilante_Wpconfig_Security( $this->settings );
242 $wpconfig->apply_security_constants();
243 }
244 update_option( 'vigilante_db_version', '1.9.0' );
245 }
246
247 // 1.10.0: Clean up orphaned email fields (centralized notification recipients)
248 if ( version_compare( $db_version, '1.10.0', '<' ) ) {
249 $this->migrate_cleanup_email_fields();
250 update_option( 'vigilante_db_version', '1.10.0' );
251 }
252
253 // 1.11.0: Remove stale 'enabled' key from activity_log settings
254 // + Convert additional_recipients from string to array
255 if ( version_compare( $db_version, '1.11.0', '<' ) ) {
256 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
257 $changed = false;
258
259 if ( isset( $options['activity_log']['enabled'] ) ) {
260 unset( $options['activity_log']['enabled'] );
261 $changed = true;
262 }
263
264 // Convert corrupted string to array for additional_recipients
265 if ( isset( $options['email']['additional_recipients'] ) && is_string( $options['email']['additional_recipients'] ) ) {
266 $raw = trim( $options['email']['additional_recipients'] );
267 if ( ! empty( $raw ) ) {
268 $emails = array_filter( array_map( 'trim', preg_split( '/[\r\n,; ]+/', $raw ) ) );
269 $options['email']['additional_recipients'] = array_values( array_filter( $emails, 'is_email' ) );
270 } else {
271 $options['email']['additional_recipients'] = array();
272 }
273 $changed = true;
274 }
275
276 if ( $changed ) {
277 update_option( Vigilante_Settings::OPTION_NAME, $options );
278 }
279 update_option( 'vigilante_db_version', '1.11.0' );
280 }
281
282 // 1.12.1: Regenerate htaccess (WooCommerce IPN exclusion in bot blocking rule)
283 if ( version_compare( $db_version, '1.12.1', '<' ) ) {
284 if ( ! empty( $this->settings->get_section( 'firewall' )['block_bad_bots'] ) ) {
285 require_once VIGILANTE_INCLUDES_DIR . 'class-htaccess-protection.php';
286 $htaccess = new Vigilante_Htaccess_Protection( $this->settings );
287 $htaccess->apply_rules();
288 }
289 update_option( 'vigilante_db_version', '1.12.1' );
290 }
291
292 // 1.14.0: Generate critical config files baseline (wp-config.php, .htaccess)
293 if ( version_compare( $db_version, '1.14.0', '<' ) ) {
294 if ( ! class_exists( 'Vigilante_File_Integrity' ) ) {
295 require_once VIGILANTE_INCLUDES_DIR . 'class-file-integrity.php';
296 }
297 $fi = new Vigilante_File_Integrity( $this->settings, $this->database, $this->activity_log );
298
299 /*
300 * Only when there is nothing on record. This migration exists to
301 * create the baseline that did not exist, never to discard the one
302 * the owner approved: rebuilding it from the files takes whatever
303 * is on disk right now as approved, so a wp-config.php modified and
304 * awaiting review would be blessed in silence.
305 *
306 * And this is not theory. vigilante_db_version is written on two
307 * different scales into the same option: this file counts in plugin
308 * versions (2.11.0) and Vigilante_Database counts in schema
309 * versions, currently 1.4.0 (class-database.php:322 and :380). For
310 * version_compare, 1.4.0 is LOWER than 1.14.0, so any site whose
311 * option was last written by the schema runs this migration again.
312 * Measured on the Multisite install on 10 sep 2026: one of the three
313 * sites was sitting on 1.4.0.
314 */
315 if ( ! $fi->get_critical_files_baseline() ) {
316 $fi->regenerate_all_baselines();
317 }
318
319 update_option( 'vigilante_db_version', '1.14.0' );
320 }
321
322 // 2.0.0: Move hide_server_signature and remove_fingerprinting_headers
323 // from firewall section to security_headers section
324 if ( version_compare( $db_version, '2.0.0', '<' ) ) {
325 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
326 $changed = false;
327
328 foreach ( array( 'hide_server_signature', 'remove_fingerprinting_headers' ) as $key ) {
329 if ( isset( $options['firewall'][ $key ] ) ) {
330 if ( ! isset( $options['security_headers'][ $key ] ) ) {
331 $options['security_headers'][ $key ] = $options['firewall'][ $key ];
332 }
333 unset( $options['firewall'][ $key ] );
334 $changed = true;
335 }
336 }
337
338 if ( $changed ) {
339 update_option( Vigilante_Settings::OPTION_NAME, $options );
340 }
341 update_option( 'vigilante_db_version', '2.0.0' );
342 }
343
344 // 2.6.1: Two things happen here.
345 //
346 // 1. Re-apply wp-config constants so the block is rewritten with
347 // "if ( ! defined() )" guards around every define(). Without guards,
348 // non-standard setups that pre-define WordPress constants outside
349 // wp-config.php (custom bootstraps that load constants from .env or
350 // similar) hit a fatal "Constant already defined" when wp-config.php
351 // is parsed and reaches our block.
352 //
353 // 2. Drop the cached Security Check report. The cached "max" per
354 // category was frozen at scan time; with the internal category
355 // bumping from 22 to 28 points (closed_plugins added in 2.6.0),
356 // the cached report would keep displaying 22/22 until the next
357 // full scan. Clearing it forces a fresh scan with the new caps.
358 if ( version_compare( $db_version, '2.6.1', '<' ) ) {
359 if ( $this->settings->is_module_enabled( 'wp_hardening' ) ) {
360 require_once VIGILANTE_INCLUDES_DIR . 'class-wpconfig-security.php';
361 $wpconfig = new Vigilante_Wpconfig_Security( $this->settings );
362 $wpconfig->apply_security_constants();
363 }
364 delete_option( 'vigilante_analyzer_last_scan' );
365
366 // Schedule an immediate background scan so the dashboard widget
367 // doesn't display "Last scan: never" right after the upgrade.
368 // Reuses the same hook the post-Under-Attack flow uses.
369 if ( ! wp_next_scheduled( 'vigilante_under_attack_post_scan' ) ) {
370 wp_schedule_single_event( time() + 5, 'vigilante_under_attack_post_scan' );
371 }
372
373 update_option( 'vigilante_db_version', '2.6.1' );
374 }
375
376 // 2.9.3: Regenerate the .htaccess protection block. The bad-bots
377 // User-Agent list dropped substring-prone tokens that 403'd
378 // legitimate clients (e.g. "rma" matched inside "Performance" and
379 // blocked WP Rocket's page fetch), and the blocking rules now honour
380 // the firewall IP / User-Agent whitelists as negated exceptions.
381 // Existing sites only rewrite the block when Server Protection is
382 // saved, so the upgrade has to refresh it once itself (same pattern
383 // as the 1.12.1 WooCommerce IPN migration).
384 if ( version_compare( $db_version, '2.9.3', '<' ) ) {
385 require_once VIGILANTE_INCLUDES_DIR . 'class-htaccess-protection.php';
386 $htaccess = new Vigilante_Htaccess_Protection( $this->settings );
387
388 if ( $htaccess->are_rules_active() ) {
389 $htaccess->apply_rules();
390 }
391
392 update_option( 'vigilante_db_version', '2.9.3' );
393 }
394
395 /*
396 * 2.9.8: the mixed content handling changes shape. "Upgrade Insecure
397 * Requests" becomes a setting of its own, and Fix Mixed Content ships
398 * off, where before it shipped on and carried the directive with it.
399 * Both have to be written down for sites that are updating, so their
400 * pages keep loading exactly what they loaded yesterday.
401 *
402 * Read the RAW stored options, not get_section(): that one merges the
403 * defaults, so a site that never stored the key would be read with the
404 * new default and silently lose the behaviour it had. Absent means the
405 * site was running on the old default, which was on.
406 */
407 if ( version_compare( $db_version, '2.9.8', '<' ) ) {
408 $raw = get_option( Vigilante_Settings::OPTION_NAME, array() );
409 $stored = ( is_array( $raw ) && isset( $raw['security_headers'] ) && is_array( $raw['security_headers'] ) ) ? $raw['security_headers'] : array();
410 $had_fix = array_key_exists( 'fix_mixed_content', $stored ) ? ! empty( $stored['fix_mixed_content'] ) : true;
411
412 /*
413 * Merge, never replace. update_section() overwrites the whole
414 * section, so passing just these two keys wiped every other header
415 * setting the site had stored (HSTS, CSP, cross-origin policies,
416 * the HTTPS switches, Server Identity) and left the screen showing
417 * factory defaults while the .htaccess kept serving the old values.
418 */
419 $this->settings->update_section(
420 'security_headers',
421 array_merge(
422 $stored,
423 array(
424 'fix_mixed_content' => $had_fix,
425 'upgrade_insecure_requests' => $had_fix,
426 )
427 )
428 );
429
430 update_option( 'vigilante_db_version', '2.9.8' );
431 }
432
433 /*
434 * 2.9.9: drop the settings that no code has read for versions.
435 *
436 * They were carried in the defaults and therefore written into every
437 * saved configuration, they show up in an exported configuration, and
438 * anyone reading them assumes a feature exists behind them. Removing
439 * them from the defaults is not enough: the stored copies survive, so
440 * they are swept here too. Nothing reads them, so nothing changes.
441 */
442 if ( version_compare( $db_version, '2.9.9', '<' ) ) {
443 $raw = get_option( Vigilante_Settings::OPTION_NAME, array() );
444 $dead = array(
445 'firewall' => array( 'country_blocking', 'protected_file_extensions' ),
446 'file_integrity' => array( 'suspicious_patterns' ),
447 'backup' => array( 'auto_backup', 'backup_before_update' ),
448 'advanced' => array( 'block_author_archives', 'disable_embeds', 'uninstall_cleanup', 'debug_mode' ),
449 );
450
451 $changed = false;
452 foreach ( $dead as $section => $keys ) {
453 if ( ! isset( $raw[ $section ] ) || ! is_array( $raw[ $section ] ) ) {
454 continue;
455 }
456 foreach ( $keys as $key ) {
457 if ( array_key_exists( $key, $raw[ $section ] ) ) {
458 unset( $raw[ $section ][ $key ] );
459 $changed = true;
460 }
461 }
462 }
463
464 if ( $changed ) {
465 update_option( Vigilante_Settings::OPTION_NAME, $raw );
466 }
467
468 update_option( 'vigilante_db_version', '2.9.9' );
469 }
470
471 /*
472 * 2.11.0: security release (audit of 28 Aug 2026). Runs here and not
473 * from Vigilante_Database::needs_update(): this option is shared with
474 * that class, and on any updated site it already holds a plugin version
475 * (2.9.9 or later), so a bump of DB_VERSION would never fire.
476 * create_tables() widens the email code column through dbDelta (varchar
477 * 6 to 64, the code is stored hashed since 2.11.0) and purge_for_2_11_0()
478 * does what dbDelta cannot: it empties the trusted devices, which were
479 * identified by User-Agent until now (S1), and the pending email codes,
480 * stored in clear until now (S11). Every remembered device asks for the
481 * second factor once more after this update, and the changelog says so.
482 */
483 if ( version_compare( $db_version, '2.11.0', '<' ) ) {
484 $this->database->create_tables();
485 $this->database->purge_for_2_11_0();
486
487 update_option( 'vigilante_db_version', '2.11.0' );
488 }
489
490 /*
491 * 2.11.9: clear the raw .htaccess copies that older versions left in
492 * options, on the first admin load after the update. Uninstall already
493 * removes them, but that only fires when the plugin is deleted, so a
494 * site that keeps the plugin carried them until now. Three stores, each
495 * a copy of a file that can hold secrets (a SetEnv token, an
496 * Authorization header): the same exposure the wp.org review flagged as
497 * 4.4, on the paths its fix did not reach.
498 *
499 * - vigilante_htaccess_history: up to five raw copies, by design, until
500 * 2.11.8. The writer is gone, nothing reads it, so it is deleted.
501 * - vigilante_htaccess_backup: the single rollback buffer, normally
502 * cleared in the finally of each write; a copy only lingers if a write
503 * crashed mid-operation. Nothing outside one write reads it, so a
504 * leftover is deleted.
505 * - vigilante_htaccess_pre_migration: still read by the header recovery,
506 * but older versions stored the whole file where only our own block is
507 * ever used. Truncated to that block, so the feature keeps working and
508 * nothing outside our markers stays in the option.
509 */
510 if ( version_compare( $db_version, '2.11.9', '<' ) ) {
511 delete_option( 'vigilante_htaccess_history' );
512 delete_option( 'vigilante_htaccess_backup' );
513
514 $snapshot = get_option( 'vigilante_htaccess_pre_migration' );
515 if ( is_array( $snapshot ) && isset( $snapshot['content'] ) && '' !== (string) $snapshot['content'] ) {
516 require_once VIGILANTE_INCLUDES_DIR . 'class-htaccess-recovery.php';
517 $block = Vigilante_Htaccess_Recovery::get_raw_block();
518
519 if ( '' === $block ) {
520 delete_option( 'vigilante_htaccess_pre_migration' );
521 } elseif ( $block !== $snapshot['content'] ) {
522 $snapshot['content'] = $block;
523 update_option( 'vigilante_htaccess_pre_migration', $snapshot, false );
524 }
525 }
526
527 update_option( 'vigilante_db_version', '2.11.9' );
528 }
529
530 /*
531 * 2.11.10: the pending-approval flag becomes one per site on a network.
532 * Until 2.11.9 it was a single global user meta, so the queue was shared
533 * across the whole network. Moving the key is not enough: the accounts
534 * already waiting carry the old key, and reading only the new one would
535 * let them log in. So they are moved here, each to the site it belongs
536 * to, and the old key is removed only once the new one is written.
537 */
538 if ( version_compare( $db_version, '2.11.10', '<' ) ) {
539 $this->migrate_pending_approval_per_site();
540
541 update_option( 'vigilante_db_version', '2.11.10' );
542 }
543
544 /*
545 * 3.0.0: self-protection package. This block must stay the LAST one of
546 * run_migrations(): every block compares against the same $db_version
547 * captured at the top, so the last update_option() that runs is the
548 * one that sticks, and on a jump from any older version it has to be
549 * this one.
550 *
551 * 1. Capture the self-integrity anchor (the manifest fingerprint) and
552 * run an inline self-check. It covers every update the old code never
553 * saw through the upgrader hook: from any 2.x, and manual or FTP
554 * uploads. A plain new is enough, the constructor registers no hooks.
555 * 2. Drop the cached Security Check report: the Internal category grows
556 * from 30 to 33 points (the self_integrity check), and the cached
557 * report would keep the old denominator until the next full scan.
558 * Same reason and same background refresh as the 2.6.1 block above.
559 * 3. Remove Vigilant's own files from the ignore list before that check.
560 * Until 2.11.11 the generic scan listed them like any plugin, and any
561 * administrator could ignore one (after a false alarm while
562 * WordPress.org published new checksums, for example). Kept, those
563 * entries would silence the self-check of those files for good,
564 * PHP included.
565 */
566 if ( version_compare( $db_version, '3.0.0', '<' ) ) {
567 if ( ! class_exists( 'Vigilante_Self_Integrity' ) ) {
568 require_once VIGILANTE_INCLUDES_DIR . 'class-self-integrity.php';
569 }
570 $ignored_files = get_option( 'vigilante_ignored_files', array() );
571 if ( is_array( $ignored_files ) && $ignored_files ) {
572 $kept_files = array_values(
573 array_filter(
574 $ignored_files,
575 function ( $ignored_file ) {
576 return ! Vigilante_Self_Integrity::is_own_file_path( (string) $ignored_file );
577 }
578 )
579 );
580 if ( count( $kept_files ) !== count( $ignored_files ) ) {
581 update_option( 'vigilante_ignored_files', $kept_files );
582 if ( $this->activity_log ) {
583 $this->activity_log->log(
584 'system',
585 'self_ignored_files_removed',
586 __( 'Vigilant files were removed from the File Integrity ignore list: self-protection checks them now.', 'vigilante' ),
587 array( 'removed' => count( $ignored_files ) - count( $kept_files ) ),
588 'info'
589 );
590 }
591 }
592 }
593 $self_integrity = new Vigilante_Self_Integrity( $this->settings, $this->activity_log );
594 $self_integrity->run_check( 'migration' );
595
596 delete_option( 'vigilante_analyzer_last_scan' );
597 if ( ! wp_next_scheduled( 'vigilante_under_attack_post_scan' ) ) {
598 wp_schedule_single_event( time() + 5, 'vigilante_under_attack_post_scan' );
599 }
600
601 update_option( 'vigilante_db_version', '3.0.0' );
602 }
603 }
604
605 /**
606 * Move the pending-approval flag of a network to a key per site
607 *
608 * Runs once for the whole network, not once per site: the data it moves is
609 * global, so the guard is a network option and any site may be the one that
610 * does it. On a single site the key does not change and there is nothing to
611 * do.
612 *
613 * Each waiting account goes to its primary site, or to the only site it
614 * belongs to; one that belongs to none goes to the main site rather than
615 * nowhere, because losing the flag would silently approve it.
616 *
617 * @since 2.11.10
618 */
619 private function migrate_pending_approval_per_site() {
620 global $wpdb;
621
622 if ( ! is_multisite() ) {
623 return;
624 }
625
626 if ( get_site_option( 'vigilante_pending_per_site_done' ) ) {
627 return;
628 }
629
630 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- One-off migration of the plugin's own user meta; the meta API has no "list every user with this key".
631 $user_ids = $wpdb->get_col(
632 $wpdb->prepare( "SELECT DISTINCT user_id FROM {$wpdb->usermeta} WHERE meta_key = %s", 'vigilante_pending_approval' )
633 );
634
635 foreach ( (array) $user_ids as $user_id ) {
636 $user_id = (int) $user_id;
637 if ( ! $user_id ) {
638 continue;
639 }
640
641 $pending = get_user_meta( $user_id, 'vigilante_pending_approval', true );
642 $since = get_user_meta( $user_id, 'vigilante_pending_since', true );
643
644 /*
645 * Every site the account belongs to, not its primary one. The global
646 * flag does not say where the registration happened, and the first
647 * version of this guessed the primary blog: an account that
648 * registered on B while its primary was A came out pending on A and
649 * free to log in on B, which is the very site it had never been
650 * approved on. Found by the cross review of 2.11.10.
651 *
652 * Marking every site it belongs to fails closed instead: the account
653 * stays blocked wherever it can log in, and shows up in the queue of
654 * each of those sites so somebody can actually act on it. An account
655 * that belongs to no site goes to the main one rather than nowhere,
656 * because losing the flag would silently approve it.
657 */
658 /*
659 * With $all true, because the default leaves out archived, spam and
660 * deleted sites (wp-includes/user.php:1113-1117): a site archived on
661 * the day this runs would lose the flag, and the account would walk
662 * in unapproved the moment it was brought back. Found by the second
663 * cross review of 2.11.10.
664 */
665 $blog_ids = array();
666
667 foreach ( get_blogs_of_user( $user_id, true ) as $blog ) {
668 if ( ! empty( $blog->userblog_id ) ) {
669 $blog_ids[] = (int) $blog->userblog_id;
670 }
671 }
672
673 if ( empty( $blog_ids ) ) {
674 $blog_ids[] = (int) get_main_site_id();
675 }
676
677 foreach ( array_unique( $blog_ids ) as $blog_id ) {
678 $prefix = $wpdb->get_blog_prefix( $blog_id );
679
680 update_user_meta( $user_id, $prefix . 'vigilante_pending_approval', $pending );
681 if ( '' !== $since && false !== $since ) {
682 update_user_meta( $user_id, $prefix . 'vigilante_pending_since', $since );
683 }
684 }
685
686 delete_user_meta( $user_id, 'vigilante_pending_approval' );
687 delete_user_meta( $user_id, 'vigilante_pending_since' );
688 }
689
690 update_site_option( 'vigilante_pending_per_site_done', 1 );
691 }
692
693 /**
694 * Migration: Remove orphaned email fields from saved options
695 *
696 * v1.10.0 centralized notification recipients into email section.
697 * Old per-module notify_email fields and dead email section fields
698 * are removed to avoid confusion.
699 */
700 private function migrate_cleanup_email_fields() {
701 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
702 $modified = false;
703
704 // Remove orphaned fields from email section
705 $dead_email_keys = array( 'enabled', 'from_name', 'from_email', 'admin_email', 'send_activation_email', 'custom_email' );
706 if ( isset( $options['email'] ) && is_array( $options['email'] ) ) {
707 foreach ( $dead_email_keys as $key ) {
708 if ( array_key_exists( $key, $options['email'] ) ) {
709 unset( $options['email'][ $key ] );
710 $modified = true;
711 }
712 }
713 // Ensure new fields exist with defaults
714 if ( ! array_key_exists( 'send_to_admin_email', $options['email'] ) ) {
715 $options['email']['send_to_admin_email'] = true;
716 $modified = true;
717 }
718 if ( ! array_key_exists( 'additional_recipients', $options['email'] ) ) {
719 $options['email']['additional_recipients'] = '';
720 $modified = true;
721 }
722 }
723
724 // Remove notify_email from login_security
725 if ( isset( $options['login_security']['notify_email'] ) ) {
726 unset( $options['login_security']['notify_email'] );
727 $modified = true;
728 }
729
730 // Remove notify_email from file_integrity
731 if ( isset( $options['file_integrity']['notify_email'] ) ) {
732 unset( $options['file_integrity']['notify_email'] );
733 $modified = true;
734 }
735
736 if ( $modified ) {
737 update_option( Vigilante_Settings::OPTION_NAME, $options );
738 // Clear settings cache so the plugin uses clean data immediately
739 $this->settings->clear_cache();
740 }
741 }
742
743 /**
744 * Migration: Fix IP whitelist/blacklist entries merged into single line
745 *
746 * Prior to 1.2.3, sanitize_text_field() stripped newlines from textarea data,
747 * causing multiple IPs to be stored as a single space-separated string.
748 */
749 private function migrate_fix_ip_lists() {
750 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
751 $fixed = false;
752
753 foreach ( array( 'ip_whitelist', 'ip_blacklist' ) as $key ) {
754 if ( ! empty( $options['firewall'][ $key ] ) && is_array( $options['firewall'][ $key ] ) ) {
755 $new_list = array();
756 foreach ( $options['firewall'][ $key ] as $entry ) {
757 // Split entries that were joined by spaces
758 $parts = preg_split( '/\s+/', trim( $entry ) );
759 foreach ( $parts as $part ) {
760 $part = trim( $part );
761 if ( '' !== $part ) {
762 $new_list[] = $part;
763 }
764 }
765 }
766 if ( count( $new_list ) !== count( $options['firewall'][ $key ] ) ) {
767 $options['firewall'][ $key ] = array_unique( $new_list );
768 $fixed = true;
769 }
770 }
771 }
772
773 if ( $fixed ) {
774 update_option( Vigilante_Settings::OPTION_NAME, $options );
775 // Clear settings cache so changes take effect immediately
776 $this->settings->clear_cache();
777 }
778 }
779
780 /**
781 * Add admin menu page in last position
782 */
783 public function add_menu() {
784 $menu_title = __( 'Vigilant', 'vigilante' );
785
786 // Count pending approvals (separate concern, always red if present)
787 $pending_count = $this->get_pending_approvals_count();
788
789 // Get security issues with severity
790 $security_status = $this->get_security_status_for_badge();
791
792 /*
793 * Self-protection: a change to Vigilant own files is the one finding
794 * that has to be visible from any screen of WordPress, so it adds to
795 * the counter and paints it red. A verified state, a state with fewer
796 * references than usual and the check turned off add nothing: a counter
797 * that is always on is a counter nobody reads.
798 */
799 $self_tone = Vigilante_Self_Integrity::tone(
800 Vigilante_Self_Integrity::display_state(),
801 Vigilante_Self_Integrity::is_on()
802 );
803 $self_badge = in_array( $self_tone, array( 'critical', 'off', 'warning' ), true ) ? 1 : 0;
804
805 // Total count for badge
806 $total_badge = $pending_count + $security_status['count'] + $self_badge;
807
808 if ( $total_badge > 0 ) {
809 // Determine badge color:
810 // - Red (awaiting-mod): pending approvals OR critical modules disabled
811 // - Orange (update-plugins): only non-critical modules disabled
812 if ( $pending_count > 0 || $security_status['has_critical'] || in_array( $self_tone, array( 'critical', 'off' ), true ) ) {
813 $badge_class = 'awaiting-mod';
814 } else {
815 $badge_class = 'update-plugins vigilante-badge-warning';
816 }
817
818 $menu_title .= sprintf(
819 ' <span class="%s count-%d"><span class="pending-count">%d</span></span>',
820 esc_attr( $badge_class ),
821 $total_badge,
822 $total_badge
823 );
824 }
825
826 add_menu_page(
827 __( 'Vigilant', 'vigilante' ),
828 $menu_title,
829 'manage_options',
830 'vigilante',
831 array( $this, 'render_settings_page' ),
832 'dashicons-shield',
833 999
834 );
835
836 // Rename auto-generated first submenu to "Dashboard"
837 add_submenu_page(
838 'vigilante',
839 __( 'Dashboard', 'vigilante' ),
840 __( 'Dashboard', 'vigilante' ),
841 'manage_options',
842 'vigilante',
843 array( $this, 'render_settings_page' )
844 );
845
846 // Security Audit shortcut
847 add_submenu_page(
848 'vigilante',
849 __( 'Security Audit', 'vigilante' ),
850 __( 'Security Audit', 'vigilante' ),
851 'manage_options',
852 'vigilante-activity-log',
853 array( $this, 'redirect_to_tab' )
854 );
855
856 // File Integrity shortcut, with its own counter when the self-check has
857 // something to say: that is the screen that explains it.
858 $fi_menu_title = __( 'File Integrity', 'vigilante' );
859 if ( $self_badge > 0 ) {
860 $fi_menu_title .= sprintf(
861 ' <span class="%s count-1"><span class="pending-count">1</span></span>',
862 in_array( $self_tone, array( 'critical', 'off' ), true ) ? 'awaiting-mod' : 'update-plugins vigilante-badge-warning'
863 );
864 }
865 add_submenu_page(
866 'vigilante',
867 __( 'File Integrity', 'vigilante' ),
868 $fi_menu_title,
869 'manage_options',
870 'vigilante-file-integrity',
871 array( $this, 'redirect_to_tab' )
872 );
873 }
874
875 /**
876 * Redirect submenu shortcuts early, before headers are sent
877 */
878 public function redirect_submenu_shortcuts() {
879 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Just reading page slug for redirect
880 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
881
882 $tab_map = array(
883 'vigilante-activity-log' => 'activity-log',
884 'vigilante-file-integrity' => 'file-integrity',
885 );
886
887 if ( isset( $tab_map[ $page ] ) ) {
888 wp_safe_redirect( admin_url( 'admin.php?page=vigilante&tab=' . $tab_map[ $page ] ) );
889 exit;
890 }
891 }
892
893 /**
894 * Fallback redirect for submenu shortcuts (JS-based)
895 */
896 public function redirect_to_tab() {
897 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Just reading page slug for redirect
898 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
899
900 $tab_map = array(
901 'vigilante-activity-log' => 'activity-log',
902 'vigilante-file-integrity' => 'file-integrity',
903 );
904
905 if ( isset( $tab_map[ $page ] ) ) {
906 $url = admin_url( 'admin.php?page=vigilante&tab=' . $tab_map[ $page ] );
907 echo '<script>window.location.replace(' . wp_json_encode( esc_url( $url ) ) . ');</script>';
908 }
909 }
910
911 /**
912 * Highlight the correct submenu item based on active tab
913 *
914 * @param string $submenu_file Current submenu file.
915 * @return string
916 */
917 public function highlight_submenu_tab( $submenu_file ) {
918 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading tab for menu highlight only
919 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
920 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
921 $tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : '';
922
923 if ( 'vigilante' !== $page || empty( $tab ) ) {
924 return $submenu_file;
925 }
926
927 $tab_to_submenu = array(
928 'activity-log' => 'vigilante-activity-log',
929 'file-integrity' => 'vigilante-file-integrity',
930 );
931
932 if ( isset( $tab_to_submenu[ $tab ] ) ) {
933 return $tab_to_submenu[ $tab ];
934 }
935
936 return $submenu_file;
937 }
938
939 /**
940 * Set browser tab title to show plugin name and active tab
941 *
942 * Changes "Dashboard ‹ Site Name — WordPress" to
943 * "Vigilant > Dashboard ‹ Site Name — WordPress"
944 *
945 * @param string $admin_title Full admin title.
946 * @param string $title Page title from add_menu_page/add_submenu_page.
947 * @return string Modified title.
948 */
949 public function set_admin_page_title( $admin_title, $title ) {
950 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading page slug for title only
951 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
952
953 // Only modify on Vigilante pages
954 if ( 0 !== strpos( $page, 'vigilante' ) ) {
955 return $admin_title;
956 }
957
958 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
959 $tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'dashboard';
960
961 if ( isset( $this->tabs[ $tab ] ) ) {
962 $tab_label = $this->tabs[ $tab ];
963 } else {
964 $tab_label = __( 'Dashboard', 'vigilante' );
965 }
966
967 $plugin_title = __( 'Vigilant', 'vigilante' ) . ' &rsaquo; ' . $tab_label;
968
969 // Replace the original page title portion
970 return str_replace( $title, $plugin_title, $admin_title );
971 }
972
973 /**
974 * Get count of users pending approval
975 *
976 * @return int Count of pending users.
977 */
978 private function get_pending_approvals_count() {
979 // Prevent early execution before WordPress is ready
980 if ( ! did_action( 'plugins_loaded' ) ) {
981 return 0;
982 }
983
984 /*
985 * Counted whether the feature is on or off. An account already waiting
986 * stays blocked when it is switched off (see init_enforcement_hooks()),
987 * so reporting zero there hid people who cannot log in and whom nobody
988 * could see to approve. Found by the cross review of 2.11.10.
989 */
990
991 // phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_key, WordPress.DB.SlowDBQuery.slow_db_query_meta_value -- Limited results in admin context.
992 $args = array(
993 'meta_key' => Vigilante_User_Security::site_user_meta_key( 'vigilante_pending_approval' ),
994 'meta_value' => '1',
995 'fields' => 'ID',
996 );
997 // phpcs:enable WordPress.DB.SlowDBQuery.slow_db_query_meta_key, WordPress.DB.SlowDBQuery.slow_db_query_meta_value
998
999 // Same query as Vigilante_User_Security::get_pending_users(), and for the
1000 // same reason: the meta key already scopes this to the site, and adding
1001 // core's membership filter on top hid the accounts that have no role yet.
1002 if ( is_multisite() ) {
1003 $args['blog_id'] = 0;
1004 }
1005
1006 $pending_users = get_users( $args );
1007
1008 return count( $pending_users );
1009 }
1010
1011 /**
1012 * Whether XML-RPC is blocked, whole or its pingback methods
1013 *
1014 * Both levels have to say so: the three-way setting under WP Hardening, read
1015 * through the module's own resolver, and the WP Hardening module that
1016 * enforces it. Until 3.0.2 the Dashboard read login_security[disable_xmlrpc],
1017 * the checkbox that moved to WP Hardening in 2.9.7 and is never written any
1018 * more, so the score never granted its three points and the recommendation
1019 * to disable XML-RPC stayed on for good.
1020 *
1021 * @since 3.0.2
1022 *
1023 * @param array $options Plugin options.
1024 * @return bool
1025 */
1026 private function is_xmlrpc_protected( $options ) {
1027 return ! empty( $options['modules']['wp_hardening'] )
1028 && 'none' !== Vigilante_Comment_Security::resolve_xmlrpc_mode( $this->settings );
1029 }
1030
1031 /**
1032 * Calculate comprehensive security score (0-100)
1033 *
1034 * @param array $options Plugin options.
1035 * @return int Security score.
1036 */
1037 private function calculate_security_score( $options ) {
1038 $score = 0;
1039 $max_score = 0;
1040
1041 // Module scores (60 points total)
1042 $module_weights = array(
1043 'firewall' => 10,
1044 'security_headers' => 8,
1045 'login_security' => 10,
1046 'rest_api_security' => 6,
1047 'user_security' => 8,
1048 'wp_hardening' => 8,
1049 'file_integrity' => 5,
1050 'activity_log' => 5,
1051 );
1052
1053 foreach ( $module_weights as $module => $weight ) {
1054 $max_score += $weight;
1055 if ( ! empty( $options['modules'][ $module ] ) ) {
1056 $score += $weight;
1057 }
1058 }
1059
1060 // Firewall details (10 points)
1061 if ( ! empty( $options['modules']['firewall'] ) ) {
1062 $firewall = $options['firewall'] ?? array();
1063 $max_score += 10;
1064
1065 $firewall_checks = array(
1066 'block_sql_injection',
1067 'block_xss_attacks',
1068 'block_bad_query_strings',
1069 'block_file_inclusion',
1070 'block_directory_traversal',
1071 );
1072
1073 $firewall_enabled = 0;
1074 foreach ( $firewall_checks as $check ) {
1075 if ( ! empty( $firewall[ $check ] ) ) {
1076 $firewall_enabled++;
1077 }
1078 }
1079 $score += min( 10, $firewall_enabled * 2 );
1080 }
1081
1082 // Login security details (10 points)
1083 if ( ! empty( $options['modules']['login_security'] ) ) {
1084 $login = $options['login_security'] ?? array();
1085 $max_score += 10;
1086
1087 // Max attempts configured
1088 if ( isset( $login['max_attempts'] ) && $login['max_attempts'] <= 5 ) {
1089 $score += 3;
1090 }
1091 // XML-RPC blocked, whole or its pingback methods
1092 if ( $this->is_xmlrpc_protected( $options ) ) {
1093 $score += 3;
1094 }
1095 // 2FA enabled
1096 if ( ! empty( $login['two_factor']['enabled'] ) ) {
1097 $score += 4;
1098 }
1099 }
1100
1101 // Security headers details (10 points)
1102 if ( ! empty( $options['modules']['security_headers'] ) ) {
1103 $headers = $options['security_headers'] ?? array();
1104 $max_score += 10;
1105
1106 if ( ! empty( $headers['x_frame_options'] ) ) {
1107 $score += 2;
1108 }
1109 if ( ! empty( $headers['x_content_type_options'] ) ) {
1110 $score += 2;
1111 }
1112 if ( ! empty( $headers['hsts']['enabled'] ) ) {
1113 $score += 3;
1114 }
1115 if ( ! empty( $headers['csp']['enabled'] ) ) {
1116 $score += 3;
1117 }
1118 }
1119
1120 // User security details (10 points)
1121 if ( ! empty( $options['modules']['user_security'] ) ) {
1122 $user = $options['user_security'] ?? array();
1123 $max_score += 10;
1124
1125 if ( ! empty( $user['block_insecure_usernames'] ) ) {
1126 $score += 3;
1127 }
1128 if ( ! empty( $user['force_strong_passwords'] ) ) {
1129 $score += 3;
1130 }
1131 if ( ! empty( $user['password_expiration']['enabled'] ) ) {
1132 $score += 2;
1133 }
1134 if ( ! empty( $user['email_verification']['enabled'] ) ) {
1135 $score += 2;
1136 }
1137 }
1138
1139 // Audit alerts details (6 points) - only when Security Audit is on,
1140 // because the alerting layer rides on top of the activity log. Leaving
1141 // both alert legs off keeps these points unearned.
1142 if ( ! empty( $options['modules']['activity_log'] ) ) {
1143 $alerts = isset( $options['audit_alerts'] ) ? (array) $options['audit_alerts'] : array();
1144 $max_score += 6;
1145 if ( Vigilante_Audit_Alerts::immediate_is_active( $alerts ) ) {
1146 $score += 3;
1147 }
1148 if ( Vigilante_Audit_Alerts::threshold_is_active( $alerts ) ) {
1149 $score += 3;
1150 }
1151 }
1152
1153 /*
1154 * Self-protection (15 points). Having it on is configuration, which is
1155 * what this card measures; the state of the last check caps the card,
1156 * because a plugin whose own files were changed is not well configured
1157 * in any useful sense, whatever the rest of the settings say. The
1158 * environment block below already mixes measured state into this score
1159 * (WP_DEBUG, insecure usernames), so the card keeps its meaning.
1160 */
1161 $max_score += 15;
1162 $self_enabled = Vigilante_Self_Integrity::is_on();
1163 $self_tone = Vigilante_Self_Integrity::tone( Vigilante_Self_Integrity::display_state(), $self_enabled );
1164 if ( $self_enabled ) {
1165 $score += 10;
1166 // The five points are for a check that ran and came out clean: a
1167 // site that has never checked itself has not earned them.
1168 if ( in_array( $self_tone, array( 'ok', 'info' ), true ) ) {
1169 $score += 5;
1170 }
1171 }
1172
1173 // Environment checks (8 points) - penalize insecure server configuration
1174 $max_score += 8;
1175 $env_score = 8;
1176
1177 // WP_DEBUG active in production is a security risk (exposes paths, errors)
1178 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
1179 $env_score -= 5;
1180 }
1181
1182 // Accounts with insecure usernames (targeted by brute force attacks)
1183 $insecure_admins = $this->get_insecure_admin_usernames();
1184 if ( ! empty( $insecure_admins ) ) {
1185 $env_score -= 3;
1186 }
1187
1188 $score += max( 0, $env_score );
1189
1190 $percent = $max_score > 0 ? (int) round( ( $score / $max_score ) * 100 ) : 0;
1191 if ( in_array( $self_tone, array( 'critical', 'off' ), true ) ) {
1192 // Same cap and same reason as the Security Check score.
1193 $percent = min( $percent, Vigilante_Security_Analyzer::SCORE_CAP_ON_TAMPER );
1194 }
1195 return $percent;
1196 }
1197
1198 /**
1199 * Get security recommendations based on current settings
1200 *
1201 * @param array $options Plugin options.
1202 * @return array Array of recommendations.
1203 */
1204 private function get_security_recommendations( $options ) {
1205 $recommendations = array();
1206
1207 // Self-protection first: if Vigilant itself cannot be trusted, nothing
1208 // else on this card means much.
1209 $vg_self_enabled = Vigilante_Self_Integrity::is_on();
1210 $vg_self_tone = Vigilante_Self_Integrity::tone( Vigilante_Self_Integrity::display_state(), $vg_self_enabled );
1211 if ( ! $vg_self_enabled ) {
1212 $recommendations[] = array(
1213 'icon' => 'shield',
1214 'priority' => 'high',
1215 'tab' => 'file-integrity',
1216 'message' => __( 'Turn Vigilant self-protection on, so a change to Vigilant own files does not go unnoticed.', 'vigilante' ),
1217 );
1218 } elseif ( 'off' === $vg_self_tone ) {
1219 $recommendations[] = array(
1220 'icon' => 'warning',
1221 'priority' => 'critical',
1222 'tab' => 'file-integrity',
1223 'message' => __( 'Something on this site switched Vigilant self-protection off: File Integrity says which file does it.', 'vigilante' ),
1224 );
1225 } elseif ( 'critical' === $vg_self_tone ) {
1226 $recommendations[] = array(
1227 'icon' => 'warning',
1228 'priority' => 'critical',
1229 'tab' => 'file-integrity',
1230 'message' => __( 'Vigilant own files have been changed: repair Vigilant from File Integrity before anything else.', 'vigilante' ),
1231 );
1232 } elseif ( 'warning' === $vg_self_tone ) {
1233 $recommendations[] = array(
1234 'icon' => 'shield',
1235 'priority' => 'high',
1236 'tab' => 'file-integrity',
1237 'message' => __( 'Vigilant self-protection needs your attention: File Integrity says what it found and what to do.', 'vigilante' ),
1238 );
1239 } elseif ( 'none' === $vg_self_tone ) {
1240 // The score holds back the points of a check that has not run yet,
1241 // so the card has to say why instead of just showing a lower number.
1242 $recommendations[] = array(
1243 'icon' => 'shield',
1244 'priority' => 'high',
1245 'tab' => 'file-integrity',
1246 'message' => __( 'Vigilant has not checked its own files yet: run a scan from File Integrity.', 'vigilante' ),
1247 );
1248 }
1249
1250 // Critical: Firewall disabled
1251 if ( empty( $options['modules']['firewall'] ) ) {
1252 $recommendations[] = array(
1253 'icon' => 'warning',
1254 'priority' => 'critical',
1255 'message' => __( 'Enable Firewall to protect against common attacks.', 'vigilante' ),
1256 );
1257 }
1258
1259 // Critical: Login security disabled
1260 if ( empty( $options['modules']['login_security'] ) ) {
1261 $recommendations[] = array(
1262 'icon' => 'warning',
1263 'priority' => 'critical',
1264 'message' => __( 'Enable Login Security to prevent brute force attacks.', 'vigilante' ),
1265 );
1266 }
1267
1268 // High: Security headers disabled
1269 if ( empty( $options['modules']['security_headers'] ) ) {
1270 $recommendations[] = array(
1271 'icon' => 'admin-generic',
1272 'priority' => 'high',
1273 'message' => __( 'Enable Security Headers to protect against clickjacking and XSS.', 'vigilante' ),
1274 );
1275 }
1276
1277 // High: User security disabled
1278 if ( empty( $options['modules']['user_security'] ) ) {
1279 $recommendations[] = array(
1280 'icon' => 'admin-users',
1281 'priority' => 'high',
1282 'message' => __( 'Enable User Security to enforce password policies and username protection.', 'vigilante' ),
1283 );
1284 }
1285
1286 // High: 2FA not enabled (only if login security is active)
1287 $login = $options['login_security'] ?? array();
1288 if ( ! empty( $options['modules']['login_security'] ) && empty( $login['two_factor']['enabled'] ) ) {
1289 $recommendations[] = array(
1290 'icon' => 'shield',
1291 'priority' => 'high',
1292 'message' => __( 'Enable Two-Factor Authentication for enhanced login security.', 'vigilante' ),
1293 'tab' => 'login',
1294 );
1295 }
1296
1297 // Medium: REST API security disabled
1298 if ( empty( $options['modules']['rest_api_security'] ) ) {
1299 $recommendations[] = array(
1300 'icon' => 'rest-api',
1301 'priority' => 'medium',
1302 'message' => __( 'Enable REST API Security to control API access and prevent enumeration.', 'vigilante' ),
1303 );
1304 }
1305
1306 // Medium: WP Hardening disabled
1307 if ( empty( $options['modules']['wp_hardening'] ) ) {
1308 $recommendations[] = array(
1309 'icon' => 'lock',
1310 'priority' => 'medium',
1311 'message' => __( 'Enable WP Hardening to remove version info and protect core files.', 'vigilante' ),
1312 );
1313 }
1314
1315 // Medium: File integrity disabled
1316 if ( empty( $options['modules']['file_integrity'] ) ) {
1317 $recommendations[] = array(
1318 'icon' => 'media-text',
1319 'priority' => 'medium',
1320 'message' => __( 'Enable File Integrity to detect unauthorized file changes.', 'vigilante' ),
1321 );
1322 }
1323
1324 // Medium: Security Audit disabled
1325 if ( empty( $options['modules']['activity_log'] ) ) {
1326 $recommendations[] = array(
1327 'icon' => 'list-view',
1328 'priority' => 'medium',
1329 'message' => __( 'Enable Security Audit to track security events.', 'vigilante' ),
1330 );
1331 }
1332
1333 // Low: XML-RPC enabled (only if login security is active)
1334 if ( ! empty( $options['modules']['login_security'] ) && ! $this->is_xmlrpc_protected( $options ) ) {
1335 $recommendations[] = array(
1336 'icon' => 'info',
1337 'priority' => 'low',
1338 'message' => __( 'Disable XML-RPC if not needed (reduces attack surface).', 'vigilante' ),
1339 'tab' => 'wp-hardening',
1340 );
1341 }
1342
1343 // Low: Strong passwords not enforced (only if user security is active)
1344 $user = $options['user_security'] ?? array();
1345 if ( ! empty( $options['modules']['user_security'] ) && empty( $user['force_strong_passwords'] ) ) {
1346 $recommendations[] = array(
1347 'icon' => 'admin-users',
1348 'priority' => 'low',
1349 'message' => __( 'Enforce strong passwords for all users.', 'vigilante' ),
1350 'tab' => 'users',
1351 );
1352 }
1353
1354 // High: WP_DEBUG active in production (regardless of Vigilante settings)
1355 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
1356 $recommendations[] = array(
1357 'icon' => 'warning',
1358 'priority' => 'high',
1359 'message' => __( 'WP_DEBUG is active. Debug mode exposes sensitive information and should be disabled in production.', 'vigilante' ),
1360 'tab' => 'wp-hardening',
1361 );
1362 }
1363
1364 // Low: Users with display name matching login username (only if user security active)
1365 if ( ! empty( $options['modules']['user_security'] ) ) {
1366 $exposed_users = $this->get_users_with_exposed_login();
1367 if ( ! empty( $exposed_users ) ) {
1368 $recommendations[] = array(
1369 'icon' => 'admin-users',
1370 'priority' => 'low',
1371 'message' => sprintf(
1372 /* translators: %s: Comma-separated list of usernames */
1373 __( 'These users have their login username as display name (publicly visible): %s', 'vigilante' ),
1374 implode( ', ', $exposed_users )
1375 ),
1376 'tab' => 'users',
1377 );
1378 }
1379 }
1380
1381 // High: Accounts with insecure usernames (regardless of module status)
1382 $insecure_admins = $this->get_insecure_admin_usernames();
1383 if ( ! empty( $insecure_admins ) ) {
1384 $recommendations[] = array(
1385 'icon' => 'warning',
1386 'priority' => 'high',
1387 'message' => sprintf(
1388 /* translators: %s: Comma-separated list of usernames */
1389 __( 'Insecure usernames detected: %s. These are commonly targeted in brute force attacks. Create new accounts with unique usernames and remove these.', 'vigilante' ),
1390 implode( ', ', $insecure_admins )
1391 ),
1392 );
1393 }
1394
1395 // Critical: Closed or removed plugins detected by the daily check.
1396 // Reads from the cached state map populated by Vigilante_Plugin_Status, so
1397 // there is no extra HTTP call here. Ignored slugs are filtered out so the
1398 // recommendation respects the user's per-slug Ignore decisions.
1399 if ( ! empty( $options['modules']['file_integrity'] ) && ! empty( $options['file_integrity']['check_closed_plugins'] ) ) {
1400 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
1401 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
1402 }
1403 $closed_checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
1404 $closed_active = $closed_checker->get_closed_plugins();
1405 if ( ! empty( $closed_active ) ) {
1406 $names = array();
1407 foreach ( $closed_active as $slug => $entry ) {
1408 $names[] = isset( $entry['name'] ) ? $entry['name'] : $slug;
1409 }
1410 $recommendations[] = array(
1411 'icon' => 'warning',
1412 'priority' => 'critical',
1413 'message' => sprintf(
1414 /* translators: 1: count, 2: comma-separated plugin names */
1415 _n(
1416 '%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.',
1417 '%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.',
1418 count( $closed_active ),
1419 'vigilante'
1420 ),
1421 count( $closed_active ),
1422 implode( ', ', $names )
1423 ),
1424 'tab' => 'file-integrity',
1425 );
1426 }
1427 }
1428
1429 // Medium: Security Audit is on but no audit alert is configured. The
1430 // alerting layer only makes sense while the activity log is running.
1431 if ( ! empty( $options['modules']['activity_log'] ) ) {
1432 $alerts = isset( $options['audit_alerts'] ) ? (array) $options['audit_alerts'] : array();
1433 if ( ! Vigilante_Audit_Alerts::has_active_alerts( $alerts ) ) {
1434 $recommendations[] = array(
1435 'icon' => 'email-alt',
1436 'priority' => 'medium',
1437 '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' ),
1438 'tab' => 'activity-log',
1439 );
1440 }
1441 }
1442
1443 // Sort by priority
1444 $priority_order = array( 'critical' => 0, 'high' => 1, 'medium' => 2, 'low' => 3 );
1445 usort( $recommendations, function( $a, $b ) use ( $priority_order ) {
1446 return ( $priority_order[ $a['priority'] ] ?? 99 ) - ( $priority_order[ $b['priority'] ] ?? 99 );
1447 } );
1448
1449 return $recommendations;
1450 }
1451
1452 /**
1453 * Get users whose display name matches their login username
1454 *
1455 * Limited to administrators and editors for performance and relevance.
1456 * Cached with transient to avoid repeated queries on every dashboard load.
1457 *
1458 * @return array Array of usernames with exposed login.
1459 */
1460 private function get_users_with_exposed_login() {
1461 $cache_key = 'vigilante_exposed_display_names';
1462 $cached = get_transient( $cache_key );
1463
1464 if ( false !== $cached ) {
1465 return $cached;
1466 }
1467
1468 $exposed = array();
1469 $users = get_users( array(
1470 'role__in' => array( 'administrator', 'editor' ),
1471 'fields' => array( 'ID', 'user_login', 'display_name' ),
1472 ) );
1473
1474 foreach ( $users as $user ) {
1475 if ( strcasecmp( $user->display_name, $user->user_login ) === 0 ) {
1476 $exposed[] = $user->user_login;
1477 }
1478 }
1479
1480 // Cache for 12 hours
1481 set_transient( $cache_key, $exposed, 12 * HOUR_IN_SECONDS );
1482
1483 return $exposed;
1484 }
1485
1486 /**
1487 * Get accounts with insecure usernames
1488 *
1489 * Checks for common default usernames that are targeted by brute force attacks.
1490 * Detects any user regardless of role (consistent with username creation blocking).
1491 * Uses WordPress object cache via get_user_by() so no transient needed.
1492 *
1493 * @return array Array of insecure usernames found.
1494 */
1495 private function get_insecure_admin_usernames() {
1496 $priority_usernames = array( 'admin', 'administrator', 'root', 'test', 'user', 'guest', 'info', 'sysadmin', 'webmaster' );
1497 $found = array();
1498
1499 foreach ( $priority_usernames as $username ) {
1500 $user = get_user_by( 'login', $username );
1501 if ( $user ) {
1502 $found[] = $username;
1503 }
1504 }
1505
1506 return $found;
1507 }
1508
1509 /**
1510 * Get security status for menu badge
1511 *
1512 * Returns count of disabled modules and whether there are critical issues.
1513 * Critical = Firewall or Login Security disabled.
1514 *
1515 * @return array Array with 'count' and 'has_critical'.
1516 */
1517 public function get_security_status_for_badge() {
1518 $options = $this->settings->get_all_options();
1519 $modules = $options['modules'] ?? array();
1520
1521 // Count disabled modules
1522 $disabled_count = 0;
1523 $has_critical = false;
1524
1525 // Critical modules - if disabled, badge is red
1526 $critical_modules = array( 'firewall', 'login_security' );
1527
1528 foreach ( $modules as $module => $enabled ) {
1529 // Handle both boolean and string values ('1', '0', true, false)
1530 $is_enabled = filter_var( $enabled, FILTER_VALIDATE_BOOLEAN );
1531
1532 if ( ! $is_enabled ) {
1533 $disabled_count++;
1534
1535 // Check if this is a critical module
1536 if ( in_array( $module, $critical_modules, true ) ) {
1537 $has_critical = true;
1538 }
1539 }
1540 }
1541
1542 return array(
1543 'count' => $disabled_count,
1544 'has_critical' => $has_critical,
1545 );
1546 }
1547
1548 /**
1549 * Get count of security issues for menu badge (deprecated, use get_security_status_for_badge)
1550 *
1551 * @return int Count of critical/high issues.
1552 */
1553 public function get_security_issues_count() {
1554 $status = $this->get_security_status_for_badge();
1555 return $status['count'];
1556 }
1557
1558 /**
1559 * Register settings
1560 */
1561 public function register_settings() {
1562 register_setting(
1563 'vigilante_options',
1564 Vigilante_Settings::OPTION_NAME,
1565 array( $this->settings, 'validate_options' )
1566 );
1567 }
1568
1569 /**
1570 * Index behind the settings search box.
1571 *
1572 * Each entry points at one settings row. The search matches on the label,
1573 * on its English original and on 'keywords', which are extra terms someone
1574 * might type instead of the label itself.
1575 *
1576 * Those keywords are wrapped in _x() with the context "settings search
1577 * keywords" so every locale can supply its own: the source strings are in
1578 * English, and a Spanish user typing "contrasena" or a German one typing
1579 * "Kennwort" only reaches the password settings if that locale translated
1580 * them. Translators can add, drop or replace terms freely, one per space;
1581 * they are never displayed, only matched against what the user types.
1582 *
1583 * The list is maintained by hand, so a new settings row needs an entry here
1584 * or it cannot be found. It had drifted to 68 of 131 rows before 2.9.7.
1585 *
1586 * @return array
1587 */
1588 private function get_search_index() {
1589 return array(
1590 // Firewall - Main
1591 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' ) ),
1592 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' ) ),
1593 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' ) ),
1594 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' ) ),
1595 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' ) ),
1596 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' ) ),
1597 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' ) ),
1598 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' ) ),
1599 // Firewall - Server Protection
1600 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' ) ),
1601 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' ) ),
1602 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' ) ),
1603 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' ) ),
1604 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' ) ),
1605 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' ) ),
1606 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' ) ),
1607 // Security Headers
1608 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' ) ),
1609 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' ) ),
1610 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' ) ),
1611 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' ) ),
1612 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' ) ),
1613 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' ) ),
1614 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' ) ),
1615 // Security Headers - Cross-Origin Policies
1616 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' ) ),
1617 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' ) ),
1618 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' ) ),
1619 // Login Security
1620 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' ) ),
1621 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' ) ),
1622 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' ) ),
1623 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' ) ),
1624 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' ) ),
1625 // REST API
1626 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' ) ),
1627 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' ) ),
1628 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' ) ),
1629 // User Security
1630 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' ) ),
1631 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' ) ),
1632 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' ) ),
1633 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' ) ),
1634 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' ) ),
1635 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' ) ),
1636 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' ) ),
1637 // WP Hardening
1638 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' ) ),
1639 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' ) ),
1640 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' ) ),
1641 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' ) ),
1642 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' ) ),
1643 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' ) ),
1644 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' ) ),
1645 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' ) ),
1646 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' ) ),
1647 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' ) ),
1648 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' ) ),
1649 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' ) ),
1650 // File Integrity
1651 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' ) ),
1652 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' ) ),
1653 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' ) ),
1654 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'Vigilant self-protection', 'vigilante' ), 'anchor' => 'vigilante-section-fi-self', 'label' => __( 'Vigilant self-protection', 'vigilante' ), 'label_en' => 'Vigilant self-protection', 'keywords' => _x( 'self protection selfprotection self-check autoproteccion manifest sha256 checksums tampering tampered repair reinstall own files guardian integrity of the plugin', 'settings search keywords', 'vigilante' ) ),
1655 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' ) ),
1656 // Security Audit
1657 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' ) ),
1658 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' ) ),
1659 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' ) ),
1660 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' ) ),
1661 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' ) ),
1662 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' ) ),
1663 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' ) ),
1664 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' ) ),
1665 // Settings & Tools
1666 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' ) ),
1667 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' ) ),
1668 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' ) ),
1669 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' ) ),
1670 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' ) ),
1671 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' ) ),
1672 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' ) ),
1673 // Entradas anadidas en la 2.9.7 tras comprobar que el indice cubria 68 de
1674 // las 131 filas de ajustes: buscar XML-RPC, por ejemplo, no devolvia nada.
1675 // El indice se mantiene a mano, asi que al anadir una fila de ajustes hay
1676 // que anadirla tambien aqui.
1677 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' ) ),
1678 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' ) ),
1679 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' ) ),
1680 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' ) ),
1681 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' ) ),
1682 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' ) ),
1683 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' ) ),
1684 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' ) ),
1685 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' ) ),
1686 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' ) ),
1687 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' ) ),
1688 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' ) ),
1689 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' ) ),
1690 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' ) ),
1691 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' ) ),
1692 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' ) ),
1693 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' ) ),
1694 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' ) ),
1695 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' ) ),
1696 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' ) ),
1697 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' ) ),
1698 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' ) ),
1699 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' ) ),
1700 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' ) ),
1701 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' ) ),
1702 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' ) ),
1703 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' ) ),
1704 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' ) ),
1705 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' ) ),
1706 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' ) ),
1707 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' ) ),
1708 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' ) ),
1709 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' ) ),
1710 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' ) ),
1711 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' ) ),
1712 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' ) ),
1713 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' ) ),
1714 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' ) ),
1715 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' ) ),
1716 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' ) ),
1717 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' ) ),
1718 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' ) ),
1719 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' ) ),
1720 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' ) ),
1721 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' ) ),
1722 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' ) ),
1723 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' ) ),
1724 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' ) ),
1725 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' ) ),
1726 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' ) ),
1727 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' ) ),
1728 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' ) ),
1729 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' ) ),
1730 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' ) ),
1731 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' ) ),
1732 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' ) ),
1733 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' ) ),
1734 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' ) ),
1735 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' ) ),
1736 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' ) ),
1737 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' ) ),
1738 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' ) ),
1739 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' ) ),
1740 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' ) ),
1741 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' ) ),
1742 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' ) ),
1743 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' ) ),
1744 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' ) ),
1745 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' ) ),
1746 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' ) ),
1747 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' ) ),
1748 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' ) ),
1749 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' ) ),
1750 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' ) ),
1751 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' ) ),
1752 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' ) ),
1753 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' ) ),
1754 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' ) ),
1755 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' ) ),
1756 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' ) ),
1757 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' ) ),
1758 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' ) ),
1759 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' ) ),
1760 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' ) ),
1761 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' ) ),
1762 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' ) ),
1763 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' ) ),
1764 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' ) ),
1765 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' ) ),
1766 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' ) ),
1767 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' ) ),
1768 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' ) ),
1769 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' ) ),
1770 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' ) ),
1771 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' ) ),
1772 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' ) ),
1773 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' ) ),
1774 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' ) ),
1775 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' ) ),
1776 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' ) ),
1777 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' ) ),
1778 );
1779 }
1780
1781 /**
1782 * Enqueue admin assets
1783 *
1784 * @param string $hook Current admin page.
1785 */
1786 public function enqueue_assets( $hook ) {
1787 // toplevel_page_vigilante for top-level menu page
1788 if ( 'toplevel_page_vigilante' !== $hook ) {
1789 return;
1790 }
1791
1792 wp_enqueue_style(
1793 'vigilante-admin',
1794 VIGILANTE_ASSETS_URL . 'css/admin.css',
1795 array(),
1796 VIGILANTE_VERSION
1797 );
1798
1799 wp_enqueue_script(
1800 'vigilante-admin',
1801 VIGILANTE_ASSETS_URL . 'js/admin.js',
1802 array( 'jquery' ),
1803 VIGILANTE_VERSION,
1804 true
1805 );
1806
1807 wp_localize_script( 'vigilante-admin', 'vigilanteAdmin', array(
1808 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
1809 'selfBoxUrl' => esc_url( admin_url( 'admin.php?page=vigilante&tab=file-integrity#vigilante-section-fi-self' ) ),
1810 'nonce' => wp_create_nonce( 'vigilante_admin_nonce' ),
1811 'currentUserId' => get_current_user_id(),
1812 'logoutUrl' => wp_logout_url( wp_login_url() ),
1813 'adminUrl' => admin_url( 'admin.php?page=vigilante' ),
1814 'searchIndex' => $this->get_search_index(),
1815 // The scan repaints this table from JavaScript, so the same gate
1816 // has to travel with it or half the screen keeps the dead button.
1817 'approvalLocked' => $this->critical_approval_locked(),
1818 'underAttack' => array(
1819 'active' => ( new Vigilante_Under_Attack( $this->settings, $this->activity_log ) )->is_active(),
1820 'remaining' => ( new Vigilante_Under_Attack( $this->settings, $this->activity_log ) )->get_remaining_time(),
1821 ),
1822 'strings' => array(
1823 'saving' => __( 'Saving...', 'vigilante' ),
1824 'sendingTest' => __( 'Sending...', 'vigilante' ),
1825 'saved' => __( 'Settings saved', 'vigilante' ),
1826 'error' => __( 'Error saving settings', 'vigilante' ),
1827 'confirm' => __( 'Are you sure?', 'vigilante' ),
1828 'scanning' => __( 'Scanning...', 'vigilante' ),
1829 'scanComplete' => __( 'Scan complete', 'vigilante' ),
1830 'loading' => __( 'Loading...', 'vigilante' ),
1831 'searching' => __( 'Searching...', 'vigilante' ),
1832 'noUsersFound' => __( 'No users found', 'vigilante' ),
1833 'searchError' => __( 'Error searching users', 'vigilante' ),
1834 'sending' => __( 'Sending...', 'vigilante' ),
1835 'sendNotification' => __( 'Send notification now', 'vigilante' ),
1836 'notificationsSent' => __( 'notifications sent', 'vigilante' ),
1837 'skipped' => __( 'skipped', 'vigilante' ),
1838 'failed' => __( 'failed', 'vigilante' ),
1839 'customConfig' => __( 'Custom Configuration', 'vigilante' ),
1840 // Header tester strings
1841 'testHeaders' => __( 'Test Headers', 'vigilante' ),
1842 'testing' => __( 'Testing...', 'vigilante' ),
1843 'score' => __( 'Score', 'vigilante' ),
1844 'enabledHeaders' => __( 'Enabled headers', 'vigilante' ),
1845 'missingHeaders' => __( 'Missing headers', 'vigilante' ),
1846 'warnings' => __( 'Warnings', 'vigilante' ),
1847 // File integrity scan results strings
1848 'scanResults' => __( 'Scan Results', 'vigilante' ),
1849 'ok' => __( 'OK', 'vigilante' ),
1850 'modified' => __( 'Modified', 'vigilante' ),
1851 'suspicious' => __( 'Suspicious', 'vigilante' ),
1852 'totalScanned' => __( 'Total Scanned', 'vigilante' ),
1853 'suspiciousFiles' => __( 'Suspicious Files', 'vigilante' ),
1854 'suspiciousWarning' => __( 'These files may contain malicious code or are in unexpected locations. Review immediately!', 'vigilante' ),
1855 'file' => __( 'File', 'vigilante' ),
1856 'reason' => __( 'Reason', 'vigilante' ),
1857 'type' => __( 'Type', 'vigilante' ),
1858 'unknown' => __( 'Unknown', 'vigilante' ),
1859 'selfType' => __( 'Vigilant (self)', 'vigilante' ),
1860 'logWhatHappened' => __( 'What happened', 'vigilante' ),
1861 'logWhatItMeans' => __( 'What it means', 'vigilante' ),
1862 'logWhatToDo' => __( 'What to do', 'vigilante' ),
1863 'logSelfSeeDetails' => __( 'Open File Integrity for the full detail', 'vigilante' ),
1864 'modifiedFiles' => __( 'Modified Files', 'vigilante' ),
1865 'modifiedDescription' => __( 'These files (apparently) differ from the original WordPress or plugin versions.', 'vigilante' ),
1866 'extraFiles' => __( 'Extra Files', 'vigilante' ),
1867 'extra' => __( 'Extra', 'vigilante' ),
1868 'ignored' => __( 'Ignored', 'vigilante' ),
1869 'extraDescription' => __( 'PHP files found in plugins or themes that are not part of the original distribution from WordPress.org.', 'vigilante' ),
1870 'actions' => __( 'Actions', 'vigilante' ),
1871 'ignore' => __( 'Ignore', 'vigilante' ),
1872 'ignoring' => __( 'Ignoring...', 'vigilante' ),
1873 'fileIgnored' => __( 'File added to ignored list.', 'vigilante' ),
1874 'fileUnignored' => __( 'File removed from ignored list.', 'vigilante' ),
1875 'confirmClearIgnored' => __( 'Remove all files from the ignored list? They will appear in scan results again.', 'vigilante' ),
1876 'ignoredCleared' => __( 'Ignored files list cleared. Page will reload...', 'vigilante' ),
1877 'selectAll' => __( 'Select all', 'vigilante' ),
1878 'bulkIgnoreSelected' => __( 'Ignore selected', 'vigilante' ),
1879 'bulkUnignoreSelected'=> __( 'Stop ignoring selected', 'vigilante' ),
1880 'bulkNoSelection' => __( 'Select at least one file first.', 'vigilante' ),
1881 'bulkConfirmIgnore' => __( 'Ignore the selected files? They will be hidden from future scan results until you remove them from the ignored list.', 'vigilante' ),
1882 'bulkConfirmUnignore' => __( 'Remove the selected files from the ignored list? They will appear in scan results again.', 'vigilante' ),
1883 'bulkProcessing' => __( 'Processing...', 'vigilante' ),
1884 /* translators: %d: number of files selected for bulk action. */
1885 'bulkSelectedCount' => __( '%d selected', 'vigilante' ),
1886 'allClear' => __( 'All files verified - no issues found!', 'vigilante' ),
1887 'criticalConfigTitle' => __( 'Critical config files modified', 'vigilante' ),
1888 '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' ),
1889 'approve' => __( 'Approve', 'vigilante' ),
1890 'approving' => __( 'Approving...', 'vigilante' ),
1891 'approvalLockedNotice' => $this->critical_approval_notice(),
1892 'criticalApproved' => __( 'Change approved. Next scan will use the current state as baseline.', 'vigilante' ),
1893 'reviewChanges' => __( 'Review changes', 'vigilante' ),
1894 'hideChanges' => __( 'Hide changes', 'vigilante' ),
1895 'changes' => __( 'Changes', 'vigilante' ),
1896 'diffUnavailable' => __( 'Diff not available for this file (baseline was created before diff tracking was added). Approve to enable diff on future changes.', 'vigilante' ),
1897 'diffNetwork' => __( 'This file belongs to the whole network, so its line changes are only shown to network administrators, on the main site.', 'vigilante' ),
1898 'diffRescan' => __( 'Run a new scan to see the line changes of this file.', 'vigilante' ),
1899 'diffRedaction' => __( 'The line changes of this file are not shown because a value in it could not be hidden safely. The change itself is still detected.', 'vigilante' ),
1900 'diffEmpty' => __( 'No line-level changes detected (may be whitespace or reordering).', 'vigilante' ),
1901 'diffLines' => __( 'lines', 'vigilante' ),
1902 // Under Attack mode strings
1903 'underAttackConfirmActivate' => __( 'Activate Under Attack mode? All visitors will see a verification page for the next 4 hours.', 'vigilante' ),
1904 'underAttackConfirmDeactivate' => __( 'Deactivate Under Attack mode?', 'vigilante' ),
1905 'underAttackActivating' => __( 'Activating...', 'vigilante' ),
1906 'underAttackDeactivating' => __( 'Deactivating...', 'vigilante' ),
1907 // Database backup strings
1908 'dbBackupDownloading' => __( 'Generating backup...', 'vigilante' ),
1909 'dbBackupNoTables' => __( 'Please select at least one table.', 'vigilante' ),
1910 'dbBackupSuccess' => __( 'Database backup downloaded successfully.', 'vigilante' ),
1911 // Firewall unblock
1912 'confirmUnblockIp' => __( 'Unblock this IP from firewall rate limiting?', 'vigilante' ),
1913 // Database prefix strings
1914 'dbPrefixConfirm' => __( 'This operation will change your database prefix. It is irreversible. Make sure you have a current database backup before proceeding.', 'vigilante' ),
1915 'dbPrefixChanging' => __( 'Changing prefix...', 'vigilante' ),
1916 'dbPrefixSuccess' => __( 'Database prefix changed successfully. The page will reload now.', 'vigilante' ),
1917 'dbPrefixCheckbox' => __( 'You must confirm that you have a database backup.', 'vigilante' ),
1918 /* translators: 1: Hours, 2: Minutes */
1919 'underAttackRemaining' => __( '%1$dh %2$dm remaining', 'vigilante' ),
1920 'underAttackLabel' => __( 'Under Attack', 'vigilante' ),
1921 'standardLabel' => __( 'Standard', 'vigilante' ),
1922 'maximumLabel' => __( 'Maximum Security', 'vigilante' ),
1923 'deactivate' => __( 'Deactivate', 'vigilante' ),
1924 'underAttackActivate' => __( 'Activate for 4 hours', 'vigilante' ),
1925 // Settings strings
1926 'saveSettings' => __( 'Save Settings', 'vigilante' ),
1927 'settingsResetDefaults' => __( 'Settings reset to defaults.', 'vigilante' ),
1928 'confirmOverwrite' => __( 'This will overwrite your current settings.', 'vigilante' ),
1929 'importFailed' => __( 'Could not import settings. Check the file and try again.', 'vigilante' ),
1930 /* translators: 1: tests passed, 2: total tests in this category */
1931 'testsCounter' => __( '%1$d/%2$d tests', 'vigilante' ),
1932 'confirmResetAll' => __( 'This will reset ALL settings to defaults.', 'vigilante' ),
1933 'couldNotDetermineSection' => __( 'Could not determine section.', 'vigilante' ),
1934 'confirmResetSection' => __( 'Reset this section to default values? This cannot be undone.', 'vigilante' ),
1935 'sectionResetDefaults' => __( 'Section reset to defaults.', 'vigilante' ),
1936 /* translators: %s: preset name */
1937 'confirmApplyPreset' => __( 'Apply the "%s" preset?', 'vigilante' ),
1938 // Scan strings
1939 'scanFailed' => __( 'Scan failed', 'vigilante' ),
1940 /* translators: %s: error message */
1941 'scanError' => __( 'Scan error: %s', 'vigilante' ),
1942 'runScanNow' => __( 'Run Scan Now', 'vigilante' ),
1943 'confirmClearScan' => __( 'Are you sure you want to clear all scan results?', 'vigilante' ),
1944 'clearing' => __( 'Clearing...', 'vigilante' ),
1945 'scanResultsCleared' => __( 'Scan results cleared. Page will reload...', 'vigilante' ),
1946 'failedClearResults' => __( 'Failed to clear results', 'vigilante' ),
1947 /* translators: %s: error message */
1948 'ajaxError' => __( 'AJAX Error: %s', 'vigilante' ),
1949 // Activity log popup strings
1950 'logRequest' => __( 'Request', 'vigilante' ),
1951 'logDate' => __( 'Date', 'vigilante' ),
1952 'logMethod' => __( 'Method', 'vigilante' ),
1953 'logType' => __( 'Type', 'vigilante' ),
1954 'logAction' => __( 'Action', 'vigilante' ),
1955 'logSeverity' => __( 'Severity', 'vigilante' ),
1956 'logMessage' => __( 'Message', 'vigilante' ),
1957 'logRequestUri' => __( 'Address', 'vigilante' ),
1958 'logClient' => __( 'Client', 'vigilante' ),
1959 'logUser' => __( 'User', 'vigilante' ),
1960 'logIpAddress' => __( 'IP Address', 'vigilante' ),
1961 'logUserAgent' => __( 'User Agent', 'vigilante' ),
1962 'logIpLabel' => __( 'IP:', 'vigilante' ),
1963 'logUaLabel' => __( 'UA:', 'vigilante' ),
1964 'logWhitelist' => __( 'Whitelist', 'vigilante' ),
1965 'logBlacklist' => __( 'Blacklist', 'vigilante' ),
1966 'logInWhitelist' => __( 'In whitelist', 'vigilante' ),
1967 'logInBlacklist' => __( 'In blacklist', 'vigilante' ),
1968 'logAdded' => __( 'Added!', 'vigilante' ),
1969 'logErrorAddingToList' => __( 'Error adding to list', 'vigilante' ),
1970 'logRequestFailed' => __( 'Request failed', 'vigilante' ),
1971 // Activity log table strings
1972 'noLogEntries' => __( 'No log entries found.', 'vigilante' ),
1973 'view' => __( 'View', 'vigilante' ),
1974 'confirmClearLogs' => __( 'This will delete all audit logs.', 'vigilante' ),
1975 // Export logs strings
1976 'exporting' => __( 'Exporting...', 'vigilante' ),
1977 /* translators: %d: number of entries */
1978 'logsExported' => __( 'Logs exported (%d entries)', 'vigilante' ),
1979 'noLogsToExport' => __( 'No logs to export', 'vigilante' ),
1980 'exportFailed' => __( 'Export failed', 'vigilante' ),
1981 'exportLogs' => __( 'Export Logs', 'vigilante' ),
1982 // Backup strings
1983 'backupCreated' => __( 'Backup created successfully.', 'vigilante' ),
1984 'createBackupNow' => __( 'Download Backup', 'vigilante' ),
1985 'downloadBackup' => __( 'Download Backup (.zip)', 'vigilante' ),
1986 /* translators: %d: number of tables */
1987 'tablesCount' => __( '%d tables', 'vigilante' ),
1988 /* translators: 1: table count, 2: human-readable size */
1989 'dbTablesTotal' => __( '%1$d tables total (%2$s)', 'vigilante' ),
1990 /* translators: 1: selected count, 2: human-readable size */
1991 'dbTablesSelected' => __( '%1$d tables selected (%2$s)', 'vigilante' ),
1992 // Settings search strings
1993 'searchNoResults' => __( 'No matching settings found.', 'vigilante' ),
1994 /* translators: %d: number of results that did not fit in the list. */
1995 'searchMoreResults' => __( '%d more results. Refine the search to see them.', 'vigilante' ),
1996 'searchInTab' => __( 'in', 'vigilante' ),
1997 // Modules string
1998 /* translators: 1: enabled count, 2: total count */
1999 'modulesEnabled' => __( '%1$d / %2$d modules enabled', 'vigilante' ),
2000 // Activity log label maps for JS rendering
2001 'eventTypeLabels' => array(
2002 'login' => __( 'Login', 'vigilante' ),
2003 'user' => __( 'User', 'vigilante' ),
2004 'content' => __( 'Content', 'vigilante' ),
2005 'plugin' => __( 'Plugin', 'vigilante' ),
2006 'theme' => __( 'Theme', 'vigilante' ),
2007 'settings' => __( 'Settings', 'vigilante' ),
2008 'comment' => __( 'Comment', 'vigilante' ),
2009 'media' => __( 'Media', 'vigilante' ),
2010 'firewall' => __( 'Firewall', 'vigilante' ),
2011 'file' => __( 'File', 'vigilante' ),
2012 'security' => __( 'Security', 'vigilante' ),
2013 'system' => __( 'System', 'vigilante' ),
2014 ),
2015 'severityLabels' => array(
2016 'info' => __( 'Info', 'vigilante' ),
2017 'warning' => __( 'Warning', 'vigilante' ),
2018 'critical' => __( 'Critical', 'vigilante' ),
2019 ),
2020 // Password reset strings
2021 'noUsersFoundSearch' => __( 'No users found', 'vigilante' ),
2022 /* translators: %d: number of users */
2023 'confirmForceReset' => __( 'Force password reset for %d user(s)? A password reset email will be sent to each user.', 'vigilante' ),
2024 'warningResettingSelf' => __( 'WARNING: You are including yourself. Your session will end and you will need to set a new password.', 'vigilante' ),
2025 'processing' => __( 'Processing...', 'vigilante' ),
2026 'anErrorOccurred' => __( 'An error occurred', 'vigilante' ),
2027 'forceResetSelected' => __( 'Force Reset for Selected Users', 'vigilante' ),
2028 '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' ),
2029 'warningResettingSelfAll' => __( 'WARNING: You are including yourself. Your session will end immediately.', 'vigilante' ),
2030 'forceResetAll' => __( 'Force Reset for ALL Users', 'vigilante' ),
2031 // Role-based password reset strings
2032 /* translators: %d: number of users */
2033 'confirmForceResetByRole' => __( 'Force password reset for %d user(s) with the selected roles? A password reset email will be sent to each user.', 'vigilante' ),
2034 'noRolesSelected' => __( 'Please select at least one role.', 'vigilante' ),
2035 'forceResetByRole' => __( 'Force Reset for Selected Roles', 'vigilante' ),
2036 // User approval strings
2037 'confirmApprove' => __( 'Approve this user?', 'vigilante' ),
2038 'approve' => __( 'Approve', 'vigilante' ),
2039 'rejectReason' => __( 'Enter rejection reason (optional):', 'vigilante' ),
2040 'reject' => __( 'Reject', 'vigilante' ),
2041 'noPending' => __( 'No pending registrations.', 'vigilante' ),
2042 // Session management strings
2043 'confirmRevoke' => __( 'Revoke this session?', 'vigilante' ),
2044 'confirmRevokeAll' => __( 'Revoke all other sessions?', 'vigilante' ),
2045 'revokeOthers' => __( 'Revoke All Other Sessions', 'vigilante' ),
2046 'confirmRevokeAllUser' => __( 'Revoke ALL sessions for this user? They will be logged out everywhere.', 'vigilante' ),
2047 'sessionsFor' => __( 'Sessions for:', 'vigilante' ),
2048 'noSessions' => __( 'No active sessions', 'vigilante' ),
2049 'revoke' => __( 'Revoke', 'vigilante' ),
2050 'noUsers' => __( 'No users found', 'vigilante' ),
2051 // Time ago strings
2052 'timeYear' => __( 'year', 'vigilante' ),
2053 'timeYears' => __( 'years', 'vigilante' ),
2054 'timeMonth' => __( 'month', 'vigilante' ),
2055 'timeMonths' => __( 'months', 'vigilante' ),
2056 'timeDay' => __( 'day', 'vigilante' ),
2057 'timeDays' => __( 'days', 'vigilante' ),
2058 'timeHour' => __( 'hour', 'vigilante' ),
2059 'timeHours' => __( 'hours', 'vigilante' ),
2060 'timeMinute' => __( 'minute', 'vigilante' ),
2061 'timeMinutes' => __( 'minutes', 'vigilante' ),
2062 /* translators: %1$d: count, %2$s: time unit */
2063 'timeAgo' => __( '%1$d %2$s ago', 'vigilante' ),
2064 'justNow' => __( 'Just now', 'vigilante' ),
2065 // Pagination strings
2066 /* translators: 1: first item number, 2: last item number, 3: total items */
2067 'paginationOf' => __( '%1$d–%2$d of %3$d', 'vigilante' ),
2068 'paginationEmpty' => __( '0 items', 'vigilante' ),
2069 // Security Analyzer strings
2070 'analyzerScanNow' => __( 'Scan now', 'vigilante' ),
2071 'analyzerScanning' => __( 'Scanning…', 'vigilante' ),
2072 'analyzerFastPhase' => __( 'Running fast checks…', 'vigilante' ),
2073 'analyzerSlowPhase' => __( 'Running remote checks…', 'vigilante' ),
2074 'analyzerScanComplete' => __( 'Security scan complete.', 'vigilante' ),
2075 'analyzerScanFailed' => __( 'Security scan failed.', 'vigilante' ),
2076 'analyzerShowDetails' => __( 'Show detailed breakdown', 'vigilante' ),
2077 'analyzerHideDetails' => __( 'Hide detailed breakdown', 'vigilante' ),
2078 'analyzerGoToSetting' => __( 'Go to setting', 'vigilante' ),
2079 'analyzerNoData' => __( 'No data yet — run a scan to populate this category.', 'vigilante' ),
2080 'analyzerJustNow' => __( 'just now', 'vigilante' ),
2081 'analyzerAgo' => __( 'ago', 'vigilante' ),
2082 'analyzerSettingsSaved' => __( 'Analyzer settings saved.', 'vigilante' ),
2083 'analyzerLastScanJustNow' => __( 'Last scan just now', 'vigilante' ),
2084 'analyzerQualityExcellent' => __( 'Excellent', 'vigilante' ),
2085 'analyzerQualityGood' => __( 'Good', 'vigilante' ),
2086 'analyzerQualityFair' => __( 'Fair', 'vigilante' ),
2087 'analyzerQualityPoor' => __( 'Poor', 'vigilante' ),
2088 'analyzerQualityCritical' => __( 'Critical', 'vigilante' ),
2089 'analyzerPts' => __( 'pts', 'vigilante' ),
2090 'analyzerLearnMore' => __( 'Learn more', 'vigilante' ),
2091 'analyzerInfoAllClear' => __( 'All clear', 'vigilante' ),
2092 /* translators: %d: number of findings in an info-only category */
2093 'analyzerInfoFindings' => __( '%d findings', 'vigilante' ),
2094 ),
2095 ) );
2096
2097 // 2FA Admin assets
2098 wp_enqueue_style(
2099 'vigilante-2fa-admin',
2100 VIGILANTE_ASSETS_URL . 'css/two-factor-admin.css',
2101 array( 'vigilante-admin' ),
2102 VIGILANTE_VERSION
2103 );
2104
2105 wp_enqueue_script(
2106 'vigilante-2fa-admin',
2107 VIGILANTE_ASSETS_URL . 'js/two-factor-admin.js',
2108 array( 'jquery', 'vigilante-admin' ),
2109 VIGILANTE_VERSION,
2110 true
2111 );
2112 }
2113
2114 /**
2115 * Show admin notices
2116 */
2117 /**
2118 * Self-protection notice.
2119 *
2120 * A change to Vigilant own files is shown on every admin screen, because
2121 * waiting for someone to open the plugin is exactly what an attacker who
2122 * patched it would want. A warning is shown only on Vigilant screens, so
2123 * the notice that matters is not diluted. Neither is dismissible, both are
2124 * for administrators only, and on a network the steps depend on whether
2125 * the person can install plugins at all.
2126 */
2127 public function maybe_show_self_protection_notice() {
2128 if ( ! current_user_can( 'manage_options' ) ) {
2129 return;
2130 }
2131 $summary = $this->self_integrity_summary();
2132 $tone = $summary['tone'];
2133 if ( ! in_array( $tone, array( 'critical', 'off', 'warning' ), true ) ) {
2134 return;
2135 }
2136
2137 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading the screen slug to decide where a notice is shown; no action taken.
2138 $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : '';
2139 $on_vigilante = ( 0 === strpos( $page, 'vigilante' ) );
2140 if ( 'warning' === $tone && ! $on_vigilante ) {
2141 return;
2142 }
2143 $alarma = in_array( $tone, array( 'critical', 'off' ), true );
2144
2145 $link = admin_url( 'admin.php?page=vigilante&tab=file-integrity#vigilante-section-fi-self' );
2146 $network = is_multisite() && ! current_user_can( 'update_plugins' );
2147 ?>
2148 <div class="notice notice-<?php echo $alarma ? 'error' : 'warning'; ?> vigilante-self-notice">
2149 <p class="vigilante-self-notice-title">
2150 <span class="dashicons dashicons-shield" aria-hidden="true"></span>
2151 <strong>
2152 <?php
2153 if ( 'critical' === $tone ) {
2154 esc_html_e( 'Vigilant detected changes in its own files', 'vigilante' );
2155 } elseif ( 'off' === $tone ) {
2156 esc_html_e( 'Vigilant self-protection is switched off by code', 'vigilante' );
2157 } else {
2158 echo esc_html( $this->self_integrity_headline( $tone, $summary['state'] ) );
2159 }
2160 ?>
2161 </strong>
2162 </p>
2163 <p class="vigilante-self-notice-text">
2164 <span>
2165 <?php
2166 if ( 'critical' === $tone ) {
2167 esc_html_e( 'Your security plugin may have been tampered with, and while that is true nothing it reports can be trusted.', 'vigilante' );
2168 } elseif ( 'off' === $tone ) {
2169 esc_html_e( 'Nothing is checking that Vigilant own files are intact. File Integrity says which file switches it off.', 'vigilante' );
2170 } else {
2171 esc_html_e( 'File Integrity says what was found, what it means and what to do about it.', 'vigilante' );
2172 }
2173 if ( $network ) {
2174 echo ' ' . esc_html__( 'Only your network administrator can repair Vigilant, because its files are shared by every site in the network. Let them know.', 'vigilante' );
2175 }
2176 ?>
2177 </span>
2178 <?php
2179 /*
2180 * One button, on the same line as the text it belongs to, and it
2181 * leads to the whole story. Repairing from a notice, without
2182 * seeing which files, what it means and what it will do, is
2183 * asking someone to fix what they have not read: the repair
2184 * button lives in the card, after all that.
2185 */
2186 ?>
2187 <a class="button button-primary button-small" href="<?php echo esc_url( $link ); ?>">
2188 <?php esc_html_e( 'See what to do', 'vigilante' ); ?>
2189 </a>
2190 </p>
2191 </div>
2192 <?php
2193 }
2194
2195 public function show_admin_notices() {
2196 $this->maybe_show_self_protection_notice();
2197
2198 // Activation notice
2199 if ( get_transient( 'vigilante_activated' ) ) {
2200 ?>
2201 <div class="notice notice-success is-dismissible vigilante-activation-notice">
2202 <p>
2203 <span class="dashicons dashicons-shield vigilante-notice-icon"></span>
2204 <strong><?php esc_html_e( 'Vigilant activated successfully!', 'vigilante' ); ?></strong>
2205 <?php esc_html_e( 'Security protection is now active.', 'vigilante' ); ?>
2206 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante' ) ); ?>">
2207 <?php esc_html_e( 'Configure settings', 'vigilante' ); ?>
2208 </a>
2209 </p>
2210 </div>
2211 <?php
2212 delete_transient( 'vigilante_activated' );
2213 }
2214
2215 // Under Attack mode notice (non-dismissible, shown on all admin pages)
2216 $ua_status = get_option( Vigilante_Under_Attack::OPTION_NAME, array() );
2217 if ( ! empty( $ua_status['active'] ) ) {
2218 $ua_remaining = ( $ua_status['activated_at'] + $ua_status['duration'] ) - time();
2219 if ( $ua_remaining > 0 ) {
2220 $ua_hours = floor( $ua_remaining / 3600 );
2221 $ua_mins = floor( ( $ua_remaining % 3600 ) / 60 );
2222 $dashboard_url = admin_url( 'admin.php?page=vigilante' );
2223 ?>
2224 <div class="notice notice-warning vigilante-ua-notice">
2225 <p>
2226 <span class="dashicons dashicons-shield"></span>
2227 <strong><?php esc_html_e( 'Under Attack mode is active', 'vigilante' ); ?></strong>
2228 &mdash;
2229 <?php
2230 printf(
2231 /* translators: 1: Hours, 2: Minutes */
2232 esc_html__( '%1$dh %2$dm remaining.', 'vigilante' ),
2233 absint( $ua_hours ),
2234 absint( $ua_mins )
2235 );
2236 ?>
2237 <a href="<?php echo esc_url( $dashboard_url ); ?>">
2238 <?php esc_html_e( 'Go to Vigilant dashboard', 'vigilante' ); ?>
2239 </a>
2240 </p>
2241 <p>
2242 <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>
2243 </p>
2244 <?php
2245 // The cache-bypass rules could not be written (a host where
2246 // WordPress cannot write files by itself, a held lock, a
2247 // failed read-back): show them, so they can be added by hand.
2248 $ua_instance = new Vigilante_Under_Attack( $this->settings, $this->activity_log );
2249 if ( $ua_instance->cache_rules_missing() ) :
2250 ?>
2251 <p>
2252 <strong><?php esc_html_e( 'The cache-bypass rules could not be written to your .htaccess.', 'vigilante' ); ?></strong>
2253 <?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' ); ?>
2254 </p>
2255 <textarea readonly rows="9" class="large-text code" onclick="this.select();"><?php echo esc_textarea( Vigilante_Under_Attack::get_cache_bypass_block() ); ?></textarea>
2256 <?php endif; ?>
2257 </div>
2258 <?php
2259 }
2260 }
2261
2262 // Proxy/CDN detection: if IP detection is set to "direct" but requests
2263 // arrive with a forwarded-for header carrying a different valid IP, the
2264 // site is very likely behind a proxy/CDN that has not been declared, so
2265 // the firewall is seeing the proxy IP for every visitor. Guide the admin.
2266 //
2267 // Two deliberate silencers (2.9.2):
2268 // - A loopback forwarded IP (::1 / 127.x) means the person browsing IS
2269 // the machine itself: that only happens in local development stacks
2270 // (Local's nginx router, Docker...), never behind a production
2271 // proxy/CDN, so the notice would be pure noise there.
2272 // - The notice is dismissible and the dismissal persists site-wide via
2273 // the vigilante_dismissed_notices option (the admin evaluated it and
2274 // decided; nagging forever helps nobody).
2275 $dismissed_notices = get_option( 'vigilante_dismissed_notices', array() );
2276 if (
2277 current_user_can( 'manage_options' )
2278 && '' === Vigilante_IP_Utils::trusted_proxy_header()
2279 && ! isset( $dismissed_notices['proxy_detection'] )
2280 ) {
2281 $remote = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '';
2282 $detected = '';
2283 foreach ( Vigilante_IP_Utils::trusted_header_map() as $proxy_label => $server_key ) {
2284 if ( empty( $_SERVER[ $server_key ] ) ) {
2285 continue;
2286 }
2287 $candidate = sanitize_text_field( wp_unslash( $_SERVER[ $server_key ] ) );
2288 if ( false !== strpos( $candidate, ',' ) ) {
2289 $parts = explode( ',', $candidate );
2290 $candidate = trim( $parts[0] );
2291 }
2292 if ( ! filter_var( $candidate, FILTER_VALIDATE_IP ) || $candidate === $remote ) {
2293 continue;
2294 }
2295 // Loopback forwarded IP = local development, not a real proxy.
2296 if ( '::1' === $candidate || 0 === strpos( $candidate, '127.' ) ) {
2297 continue;
2298 }
2299 $detected = $proxy_label;
2300 break;
2301 }
2302
2303 if ( '' !== $detected ) {
2304 $firewall_url = admin_url( 'admin.php?page=vigilante&tab=firewall' );
2305 $detail_message = sprintf(
2306 /* translators: %s: detected forwarded header name wrapped in a code tag. */
2307 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' ),
2308 '<code>' . esc_html( strtoupper( $detected ) ) . '</code>'
2309 );
2310 ?>
2311 <div class="notice notice-warning is-dismissible vigilante-proxy-notice">
2312 <p>
2313 <span class="dashicons dashicons-shield"></span>
2314 <strong><?php esc_html_e( 'Vigilant: this site looks like it is behind a proxy or CDN', 'vigilante' ); ?></strong>
2315 </p>
2316 <p><?php echo wp_kses_post( $detail_message ); ?></p>
2317 <p>
2318 <a href="<?php echo esc_url( $firewall_url ); ?>" class="button button-secondary">
2319 <?php esc_html_e( 'Set your proxy in Firewall settings', 'vigilante' ); ?>
2320 </a>
2321 </p>
2322 </div>
2323 <script>
2324 jQuery( function ( $ ) {
2325 $( document ).on( 'click', '.vigilante-proxy-notice .notice-dismiss', function () {
2326 $.post( ajaxurl, {
2327 action: 'vigilante_dismiss_notice',
2328 notice_id: 'proxy_detection',
2329 nonce: <?php echo wp_json_encode( wp_create_nonce( 'vigilante_dismiss_notice' ) ); ?>
2330 } );
2331 } );
2332 } );
2333 </script>
2334 <?php
2335 }
2336 }
2337 }
2338
2339 /**
2340 * Render settings page
2341 */
2342 public function render_settings_page() {
2343 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
2344 $this->current_tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'dashboard';
2345
2346 if ( ! array_key_exists( $this->current_tab, $this->tabs ) ) {
2347 $this->current_tab = 'dashboard';
2348 }
2349 ?>
2350 <div class="wrap vigilante-admin-wrap">
2351 <div class="vigilante-header-row">
2352 <h1 class="vigilante-page-title">
2353 <img src="<?php echo esc_url( VIGILANTE_ASSETS_URL . 'images/icon.png' ); ?>" alt="Vigilante" class="vigilante-title-icon">
2354 <?php esc_html_e( 'Vigilant', 'vigilante' ); ?>
2355 <span class="vigilante-version">v<?php echo esc_html( VIGILANTE_VERSION ); ?></span>
2356 </h1>
2357 <div class="vigilante-search-wrapper">
2358 <div class="vigilante-search-input-wrap">
2359 <span class="vigilante-search-icon dashicons dashicons-search" aria-hidden="true"></span>
2360 <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">
2361 <span class="vigilante-search-shortcut" aria-hidden="true">/</span>
2362 </div>
2363 <div id="vigilante-settings-search-results" class="vigilante-search-results" hidden role="listbox"></div>
2364 </div>
2365 </div>
2366
2367 <?php $this->render_tabs(); ?>
2368
2369 <div class="vigilante-content">
2370 <div class="vigilante-main">
2371 <?php $this->render_tab_content(); ?>
2372 </div>
2373 <div class="vigilante-sidebar">
2374 <?php $this->render_sidebar(); ?>
2375 </div>
2376 </div>
2377 </div>
2378 <?php
2379 }
2380
2381 /**
2382 * Render tabs navigation
2383 */
2384 private function render_tabs() {
2385 $options = $this->settings->get_all_options();
2386
2387 // Map tabs to modules
2388 $tab_to_module = array(
2389 'firewall' => 'firewall',
2390 'headers' => 'security_headers',
2391 'login' => 'login_security',
2392 'rest-api' => 'rest_api_security',
2393 'users' => 'user_security',
2394 'wp-hardening' => 'wp_hardening',
2395 'file-integrity' => 'file_integrity',
2396 'activity-log' => 'activity_log',
2397 );
2398 ?>
2399 <nav class="nav-tab-wrapper vigilante-nav-tabs">
2400 <?php foreach ( $this->tabs as $tab_id => $tab_name ) :
2401 $is_disabled = false;
2402 $module = isset( $tab_to_module[ $tab_id ] ) ? $tab_to_module[ $tab_id ] : null;
2403 if ( $module && empty( $options['modules'][ $module ] ) ) {
2404 $is_disabled = true;
2405 }
2406 ?>
2407 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=' . $tab_id ) ); ?>"
2408 class="nav-tab <?php echo $this->current_tab === $tab_id ? 'nav-tab-active' : ''; ?> <?php echo $is_disabled ? 'vigilante-tab-disabled' : ''; ?>"
2409 <?php if ( $is_disabled ) : ?>title="<?php esc_attr_e( 'Module Disabled', 'vigilante' ); ?>"<?php endif; ?>>
2410 <?php echo esc_html( $tab_name ); ?>
2411 <?php if ( $is_disabled ) : ?><span class="vigilante-tab-off">OFF</span><?php endif; ?>
2412 </a>
2413 <?php endforeach; ?>
2414 </nav>
2415 <?php
2416 }
2417
2418 /**
2419 * Render current tab content
2420 */
2421 private function render_tab_content() {
2422 $method = 'render_tab_' . str_replace( '-', '_', $this->current_tab );
2423
2424 if ( method_exists( $this, $method ) ) {
2425 $this->$method();
2426 } else {
2427 $this->render_tab_coming_soon();
2428 }
2429 }
2430
2431 /**
2432 * Render coming soon placeholder
2433 */
2434 private function render_tab_coming_soon() {
2435 ?>
2436 <div class="vigilante-settings-section">
2437 <h2><?php esc_html_e( 'Coming Soon', 'vigilante' ); ?></h2>
2438 <p><?php esc_html_e( 'This section is under development.', 'vigilante' ); ?></p>
2439 </div>
2440 <?php
2441 }
2442
2443 /**
2444 * Values to display for a section that this site does not control
2445 *
2446 * On a subsite the stored options are its own copy, which nothing acts on:
2447 * wp-config.php and .htaccess are written from the main site. Painting the
2448 * local copy describes a configuration that is not running, so a subsite
2449 * admin sees a box ticked here and the constant absent from the file, or the
2450 * other way round. Read the main site's values instead, which are the ones in
2451 * force, and fall back to the local ones if they cannot be read.
2452 *
2453 * @since 2.9.8
2454 *
2455 * @param string $section Settings section.
2456 * @return array
2457 */
2458 private function get_section_for_display( $section ) {
2459 $local = $this->settings->get_section( $section );
2460
2461 if ( ! $this->shared_files_locked() ) {
2462 return $local;
2463 }
2464
2465 // shared_files_locked() is only true on multisite, where get_blog_option() exists.
2466 $main = get_blog_option( get_main_site_id(), Vigilante_Settings::OPTION_NAME, array() );
2467
2468 if ( ! is_array( $main ) || empty( $main[ $section ] ) || ! is_array( $main[ $section ] ) ) {
2469 return $local;
2470 }
2471
2472 return wp_parse_args( $main[ $section ], $local );
2473 }
2474
2475 /**
2476 * Whether the sections that write wp-config.php and .htaccess are read-only here
2477 *
2478 * True on a network when this is not the main site, or the user is not a
2479 * network administrator. See Vigilante_Settings::can_write_shared_files().
2480 *
2481 * @since 2.9.8
2482 *
2483 * @return bool
2484 */
2485 private function shared_files_locked() {
2486 return ! Vigilante_Settings::can_write_shared_files();
2487 }
2488
2489 /**
2490 * Whether this is the main site and the user cannot change what it builds the shared files from
2491 *
2492 * See Vigilante_Settings::get_main_site_file_settings(). On a subsite those
2493 * settings only act on that site, so they are never locked there.
2494 *
2495 * @since 2.11.6
2496 *
2497 * @return bool
2498 */
2499 private function main_site_files_locked() {
2500 return $this->shared_files_locked() && Vigilante_Settings::owns_shared_files();
2501 }
2502
2503 /**
2504 * Sentence added to a bulk change when some settings were left as they were
2505 *
2506 * Importing a file, applying a preset and restoring the defaults touch every
2507 * section at once, so the user is told that the shared file settings did
2508 * not move.
2509 *
2510 * @since 2.11.6
2511 *
2512 * @return string Empty when the user can change every setting.
2513 */
2514 private function locked_file_settings_message() {
2515 if ( ! Vigilante_Settings::get_locked_file_settings() ) {
2516 return '';
2517 }
2518
2519 return ' ' . __( 'The settings that end up in wp-config.php or .htaccess were left as they were.', 'vigilante' ) . ' ' . Vigilante_Settings::get_shared_files_notice();
2520 }
2521
2522 /**
2523 * Print the shared-files notice for a section that cannot be edited here
2524 *
2525 * @since 2.9.8
2526 */
2527 private function render_shared_files_notice() {
2528 if ( ! $this->shared_files_locked() ) {
2529 return;
2530 }
2531 ?>
2532 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
2533 <p style="margin:0;"><?php echo esc_html( Vigilante_Settings::get_shared_files_notice() ); ?></p>
2534 </div>
2535 <?php
2536 }
2537
2538 /**
2539 * Acting on another user's account needs permission over that user
2540 *
2541 * Since 2.10.3 the handlers behind these tools ask for edit_user over the
2542 * target, which is the rule WordPress itself applies. On a network the core
2543 * grants edit_user only to network administrators, so for anybody else these
2544 * controls do nothing. Better to say so than to paint a button that silently
2545 * skips every user.
2546 *
2547 * @since 2.10.4
2548 * @return bool
2549 */
2550 private function forwarded_chain_readings() {
2551 // Shown, not decided on: the firewall resolves the address elsewhere.
2552 $chain = Vigilante_IP_Utils::trusted_forwarded_for();
2553
2554 if ( '' === $chain ) {
2555 return array();
2556 }
2557
2558 $public = array();
2559
2560 foreach ( explode( ',', $chain ) as $entry ) {
2561 $address = Vigilante_IP_Utils::unmap_ipv4( trim( $entry ) );
2562
2563 if ( filter_var( $address, FILTER_VALIDATE_IP ) && ! Vigilante_IP_Utils::is_own_network( $address ) ) {
2564 $public[] = $address;
2565 }
2566 }
2567
2568 if ( count( $public ) < 2 ) {
2569 return array();
2570 }
2571
2572 return array(
2573 'now' => Vigilante_IP_Utils::client_from_chain( $chain ),
2574 'before' => $public[0],
2575 );
2576 }
2577
2578 /**
2579 * Whether the user tools of this screen are out of reach for this user
2580 *
2581 * @return bool
2582 */
2583 private function user_actions_locked() {
2584 // On a single site edit_user maps to edit_users, which a custom role with
2585 // manage_options may lack: since 2.11.8 approving and rejecting a pending
2586 // registration ask for it, so the buttons have to say so there too.
2587 return is_multisite() ? ! current_user_can( 'manage_network_users' ) : ! current_user_can( 'edit_users' );
2588 }
2589
2590 /**
2591 * Print the notice for user tools that cannot be used from this site
2592 *
2593 * @since 2.10.4
2594 */
2595 private function render_user_actions_notice() {
2596 if ( ! $this->user_actions_locked() ) {
2597 return;
2598 }
2599 ?>
2600 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
2601 <?php if ( is_multisite() ) : ?>
2602 <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>
2603 <?php else : ?>
2604 <p style="margin:0;"><?php esc_html_e( 'These tools act on other user accounts, and your role cannot edit users, so they are not available to you.', 'vigilante' ); ?></p>
2605 <?php endif; ?>
2606 </div>
2607 <?php
2608 }
2609
2610 /**
2611 * Approving a change to the shared config files needs the network
2612 *
2613 * Since 2.11.3 the handler behind the Approve button asks for
2614 * manage_network_options, because the two files it approves, wp-config.php
2615 * and the root .htaccess, belong to the installation, and so does the
2616 * record of them. The button, though, went on being painted for everybody,
2617 * so the administrator of a subsite saw the warning, saw the button,
2618 * pressed it and got "Permission denied" with no explanation. That is
2619 * exactly what user_actions_locked() above exists to avoid, one release
2620 * later and one screen over. Flagged by @calzbert.
2621 *
2622 * @since 2.11.4
2623 * @return bool
2624 */
2625 private function critical_approval_locked() {
2626 return is_multisite() && ! current_user_can( 'manage_network_options' );
2627 }
2628
2629 /**
2630 * The line that replaces the Approve button where it cannot be used
2631 *
2632 * @since 2.11.4
2633 * @return string
2634 */
2635 private function critical_approval_notice() {
2636 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' );
2637 }
2638
2639 /**
2640 * Check if module is disabled and render warning
2641 *
2642 * @param string $module_key Module key.
2643 * @return bool True if disabled.
2644 */
2645 private function render_module_disabled_notice( $module_key ) {
2646 if ( $this->settings->is_module_enabled( $module_key ) ) {
2647 return false;
2648 }
2649
2650 $module_labels = $this->settings->get_module_labels();
2651 $module_name = isset( $module_labels[ $module_key ] ) ? $module_labels[ $module_key ] : $module_key;
2652 ?>
2653 <div class="notice notice-warning vigilante-module-disabled-notice">
2654 <p>
2655 <strong><?php esc_html_e( 'Module Disabled', 'vigilante' ); ?></strong> -
2656 <?php
2657 printf(
2658 /* translators: %s: Module name */
2659 esc_html__( 'The %s module is currently disabled. Enable it from the Dashboard to use these settings.', 'vigilante' ),
2660 esc_html( $module_name )
2661 );
2662 ?>
2663 </p>
2664 <p>
2665 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=dashboard' ) ); ?>" class="button">
2666 <?php esc_html_e( 'Go to Dashboard', 'vigilante' ); ?>
2667 </a>
2668 </p>
2669 </div>
2670 <?php
2671 return true;
2672 }
2673
2674 /**
2675 * Render the Security Analyzer (Security Check) widget + expandable full report.
2676 *
2677 * Lives in the Dashboard tab between the Configuration Score status card and
2678 * the modules grid. Uses the last persisted scan to hydrate server-side so the
2679 * first paint shows real data; "Scan now" runs the 2-phase AJAX to refresh.
2680 *
2681 * @param array $last_scan Result of Vigilante_Security_Analyzer::get_last_scan().
2682 * @param array $history Score history (oldest first).
2683 * @param array $categories_def Category metadata (slug => label/max).
2684 * @param array $analyzer_settings Settings subsection for weekly cron + email.
2685 */
2686 private function render_analyzer_widget( $last_scan, $history, $categories_def, $analyzer_settings ) {
2687 $has_data = ! empty( $last_scan['ran_at'] );
2688 $score = isset( $last_scan['score'] ) ? (int) $last_scan['score'] : 0;
2689 $grade = isset( $last_scan['grade'] ) ? (string) $last_scan['grade'] : '';
2690 $counts = isset( $last_scan['counts'] ) && is_array( $last_scan['counts'] ) ? $last_scan['counts'] : array();
2691 $ran_at_human = $has_data
2692 ? sprintf(
2693 /* translators: %s: relative time like "2 hours" */
2694 __( 'Last scan %s ago', 'vigilante' ),
2695 human_time_diff( (int) $last_scan['ran_at'], time() )
2696 )
2697 : __( 'Never scanned', 'vigilante' );
2698 $categories = isset( $last_scan['categories'] ) && is_array( $last_scan['categories'] ) ? $last_scan['categories'] : array();
2699 $weekly_enabled = ! isset( $analyzer_settings['weekly_scan_enabled'] ) || ! empty( $analyzer_settings['weekly_scan_enabled'] );
2700 $email_enabled = ! empty( $analyzer_settings['email_on_regression'] );
2701
2702 /*
2703 * Self-protection caps the score, and it does so here and not only in
2704 * the stored report: the report is reused until the next Security
2705 * Check, so tampering found after it ran would otherwise be shown next
2706 * to the score the site earned before it happened.
2707 */
2708 $self_summary = $this->self_integrity_summary();
2709 $self_capped = in_array( $self_summary['tone'], array( 'critical', 'off' ), true )
2710 || ( 'self_integrity' === ( isset( $last_scan['capped_by'] ) ? $last_scan['capped_by'] : '' ) );
2711 if ( $self_capped && $has_data && $score > Vigilante_Security_Analyzer::SCORE_CAP_ON_TAMPER ) {
2712 $score = Vigilante_Security_Analyzer::SCORE_CAP_ON_TAMPER;
2713 $grade = 'E';
2714 }
2715
2716 $quality = self::analyzer_quality_tag( $score );
2717 ?>
2718 <div class="vigilante-analyzer" id="vigilante-analyzer"
2719 data-has-data="<?php echo $has_data ? '1' : '0'; ?>">
2720 <div class="vigilante-analyzer-header">
2721 <div class="vigilante-analyzer-title">
2722 <h2>
2723 <span class="dashicons dashicons-shield-alt" aria-hidden="true"></span>
2724 <?php esc_html_e( 'Security Check', 'vigilante' ); ?>
2725 </h2>
2726 <p class="description">
2727 <?php esc_html_e( 'On-demand audit of what an attacker would see right now, plus internal checks impossible from the outside.', 'vigilante' ); ?>
2728 </p>
2729 <p class="vigilante-analyzer-last-scan" data-role="ran-at">
2730 <span class="dashicons dashicons-clock" aria-hidden="true"></span>
2731 <?php echo esc_html( $ran_at_human ); ?>
2732 </p>
2733 </div>
2734 <div class="vigilante-analyzer-actions">
2735 <button type="button" class="button button-primary" id="vigilante-analyzer-scan">
2736 <span class="dashicons dashicons-update" aria-hidden="true"></span>
2737 <?php esc_html_e( 'Scan now', 'vigilante' ); ?>
2738 </button>
2739 </div>
2740 </div>
2741
2742 <?php if ( $self_capped ) : ?>
2743 <p class="vigilante-analyzer-capped">
2744 <span class="dashicons dashicons-shield" aria-hidden="true"></span>
2745 <strong><?php esc_html_e( 'This score is not reliable right now.', 'vigilante' ); ?></strong>
2746 <?php esc_html_e( 'Vigilant own files have been changed, and every other result on this page is produced by that same code. The score is held at the bottom of the scale until the files verify clean again.', 'vigilante' ); ?>
2747 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=file-integrity#vigilante-section-fi-self' ) ); ?>">
2748 <?php esc_html_e( 'See what to do', 'vigilante' ); ?>
2749 </a>
2750 </p>
2751 <?php endif; ?>
2752
2753 <div class="vigilante-analyzer-summary">
2754 <div class="vigilante-analyzer-score-card">
2755 <?php if ( $has_data && $grade ) : ?>
2756 <div class="vigilante-score-circle vigilante-grade-<?php echo esc_attr( strtolower( $grade ) ); ?>">
2757 <span class="vigilante-grade"><?php echo esc_html( $grade ); ?></span>
2758 <span class="vigilante-score-text"><?php echo esc_html( $score ); ?>%</span>
2759 </div>
2760 <?php else : ?>
2761 <div class="vigilante-score-circle vigilante-grade-empty">
2762 <span class="vigilante-grade">—</span>
2763 <span class="vigilante-score-text"><?php esc_html_e( 'N/A', 'vigilante' ); ?></span>
2764 </div>
2765 <?php endif; ?>
2766 <div class="vigilante-analyzer-score-meta">
2767 <p class="vigilante-analyzer-score-label">
2768 <?php esc_html_e( 'Security Score', 'vigilante' ); ?>
2769 </p>
2770 <span class="vigilante-analyzer-quality-tag vigilante-analyzer-quality-<?php echo esc_attr( $quality['slug'] ); ?>"
2771 data-role="quality-tag">
2772 <?php echo esc_html( $quality['label'] ); ?>
2773 </span>
2774 </div>
2775 </div>
2776
2777 <div class="vigilante-analyzer-counts">
2778 <span class="vigilante-analyzer-count vigilante-analyzer-count--pass">
2779 <span class="dashicons dashicons-yes-alt" aria-hidden="true"></span>
2780 <strong data-role="pass"><?php echo esc_html( isset( $counts['pass'] ) ? $counts['pass'] : 0 ); ?></strong>
2781 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Passed', 'vigilante' ); ?></span>
2782 </span>
2783 <span class="vigilante-analyzer-count vigilante-analyzer-count--warn">
2784 <span class="dashicons dashicons-warning" aria-hidden="true"></span>
2785 <strong data-role="warn"><?php echo esc_html( isset( $counts['warn'] ) ? $counts['warn'] : 0 ); ?></strong>
2786 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Warnings', 'vigilante' ); ?></span>
2787 </span>
2788 <span class="vigilante-analyzer-count vigilante-analyzer-count--fail">
2789 <span class="dashicons dashicons-dismiss" aria-hidden="true"></span>
2790 <strong data-role="fail"><?php echo esc_html( isset( $counts['fail'] ) ? $counts['fail'] : 0 ); ?></strong>
2791 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Failing', 'vigilante' ); ?></span>
2792 </span>
2793 </div>
2794
2795 <?php
2796 // Sparkline of recent scores. Require at least 3 data points so the trend
2797 // is meaningful (2 points is just a line between dots, no real trend).
2798 $hist_points = array();
2799 foreach ( $history as $h ) {
2800 $hist_points[] = (int) $h['score'];
2801 }
2802 $hist_count = count( $hist_points );
2803 if ( $hist_count >= 3 ) :
2804 $current_score = (int) end( $hist_points );
2805 $previous_score = (int) $hist_points[ $hist_count - 2 ];
2806 $delta = $current_score - $previous_score;
2807 $delta_class = $delta > 0 ? 'vigilante-analyzer-delta--up' : ( $delta < 0 ? 'vigilante-analyzer-delta--down' : 'vigilante-analyzer-delta--flat' );
2808 $delta_icon = $delta > 0 ? 'arrow-up-alt' : ( $delta < 0 ? 'arrow-down-alt' : 'minus' );
2809 if ( 0 === $delta ) {
2810 $delta_text = __( 'No change', 'vigilante' );
2811 } else {
2812 $delta_text = sprintf(
2813 /* translators: %s: signed delta, e.g. "+3" or "-5" */
2814 _n( '%s pt vs. previous scan', '%s pts vs. previous scan', abs( $delta ), 'vigilante' ),
2815 ( $delta > 0 ? '+' : '' ) . (int) $delta
2816 );
2817 }
2818 ?>
2819 <div class="vigilante-analyzer-sparkline-wrap">
2820 <div class="vigilante-analyzer-sparkline-head">
2821 <span class="vigilante-analyzer-sparkline-label">
2822 <?php
2823 echo esc_html( sprintf(
2824 /* translators: %d: number of scans */
2825 _n( 'Score trend (last %d scan)', 'Score trend (last %d scans)', $hist_count, 'vigilante' ),
2826 $hist_count
2827 ) );
2828 ?>
2829 </span>
2830 <span class="vigilante-analyzer-delta <?php echo esc_attr( $delta_class ); ?>">
2831 <span class="dashicons dashicons-<?php echo esc_attr( $delta_icon ); ?>" aria-hidden="true"></span>
2832 <?php echo esc_html( $delta_text ); ?>
2833 </span>
2834 </div>
2835 <div class="vigilante-analyzer-sparkline" data-role="sparkline"
2836 data-points="<?php echo esc_attr( wp_json_encode( $hist_points ) ); ?>">
2837 <?php echo self::sparkline_svg( $hist_points ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Safe SVG from helper ?>
2838 </div>
2839 </div>
2840 <?php elseif ( $has_data ) : ?>
2841 <div class="vigilante-analyzer-sparkline-wrap vigilante-analyzer-sparkline-wrap--placeholder">
2842 <span class="vigilante-analyzer-sparkline-label">
2843 <?php esc_html_e( 'Score trend', 'vigilante' ); ?>
2844 </span>
2845 <p class="vigilante-analyzer-sparkline-hint">
2846 <span class="dashicons dashicons-chart-line" aria-hidden="true"></span>
2847 <?php
2848 $needed = 3 - $hist_count;
2849 echo esc_html( sprintf(
2850 /* translators: %d: number of additional scans needed */
2851 _n( '%d more scan needed to show a trend.', '%d more scans needed to show a trend.', $needed, 'vigilante' ),
2852 $needed
2853 ) );
2854 ?>
2855 </p>
2856 </div>
2857 <?php endif; ?>
2858 </div>
2859
2860 <div class="vigilante-analyzer-toggle-row">
2861 <button type="button" class="button-link vigilante-analyzer-toggle" aria-expanded="false">
2862 <?php esc_html_e( 'Show detailed breakdown', 'vigilante' ); ?>
2863 <span class="vigilante-analyzer-toggle-chevron" aria-hidden="true"></span>
2864 </button>
2865 </div>
2866
2867 <div class="vigilante-analyzer-details" hidden>
2868 <div class="vigilante-analyzer-categories" data-role="categories">
2869 <?php foreach ( $categories_def as $slug => $meta ) :
2870 $cat = isset( $categories[ $slug ] ) ? $categories[ $slug ] : array();
2871 $earned = isset( $cat['earned'] ) ? (int) $cat['earned'] : 0;
2872 // Always use the declared meta as the source of truth for the maximum.
2873 // The cached scan may carry an old max if a check was added/removed
2874 // between releases (see 2.6.1: closed_plugins raised internal from 22 to 28
2875 // but cached scans still reported max=22 until reset).
2876 $cat_max = (int) $meta['max'];
2877 $info_only = ! empty( $meta['info_only'] ) || 0 === (int) $meta['max'];
2878 $cat_pct = $cat_max > 0 ? (int) round( ( $earned / $cat_max ) * 100 ) : 0;
2879 $checks = isset( $cat['checks'] ) ? (array) $cat['checks'] : array();
2880 $cat_counts = isset( $cat['counts'] ) && is_array( $cat['counts'] ) ? $cat['counts'] : array( 'pass' => 0, 'warn' => 0, 'fail' => 0, 'info' => 0 );
2881 $cat_quality = self::analyzer_quality_tag( $cat_pct );
2882 $info_count = isset( $cat_counts['info'] ) ? (int) $cat_counts['info'] : 0;
2883 ?>
2884 <details class="vigilante-analyzer-category<?php echo $info_only ? ' vigilante-analyzer-category--info' : ''; ?>"
2885 data-category="<?php echo esc_attr( $slug ); ?>"
2886 data-info-only="<?php echo $info_only ? '1' : '0'; ?>">
2887 <summary class="vigilante-analyzer-category-summary">
2888 <span class="vigilante-analyzer-category-chevron" aria-hidden="true"></span>
2889 <span class="vigilante-analyzer-category-label"><?php echo esc_html( $meta['label'] ); ?></span>
2890 <?php if ( $info_only ) : ?>
2891 <span class="vigilante-analyzer-category-quality vigilante-analyzer-quality-info"
2892 data-role="category-quality"
2893 title="<?php esc_attr_e( 'Informational — does not affect the security score.', 'vigilante' ); ?>">
2894 <span class="dashicons dashicons-info-outline" aria-hidden="true"></span>
2895 <?php esc_html_e( 'Informational', 'vigilante' ); ?>
2896 </span>
2897 <?php else :
2898 $passed_count = (int) ( $cat_counts['pass'] ?? 0 );
2899 $scored_total = $passed_count
2900 + (int) ( $cat_counts['warn'] ?? 0 )
2901 + (int) ( $cat_counts['fail'] ?? 0 );
2902 ?>
2903 <span class="vigilante-analyzer-category-quality vigilante-analyzer-quality-<?php echo esc_attr( $cat_quality['slug'] ); ?>"
2904 data-role="category-quality">
2905 <span data-role="category-quality-label"><?php echo esc_html( $cat_quality['label'] ); ?></span>
2906 <span class="vigilante-analyzer-category-quality-sep" aria-hidden="true">·</span>
2907 <span class="vigilante-analyzer-category-tests" data-role="category-tests"
2908 data-passed="<?php echo esc_attr( $passed_count ); ?>"
2909 data-total="<?php echo esc_attr( $scored_total ); ?>">
2910 <?php
2911 echo esc_html( sprintf(
2912 /* translators: 1: tests passed, 2: total tests in this category */
2913 __( '%1$d/%2$d tests', 'vigilante' ),
2914 $passed_count,
2915 $scored_total
2916 ) );
2917 ?>
2918 </span>
2919 </span>
2920 <?php endif; ?>
2921 <?php if ( $info_only ) : ?>
2922 <span class="vigilante-analyzer-category-states" data-role="category-states">
2923 <?php if ( $info_count > 0 ) : ?>
2924 <span class="vigilante-analyzer-category-state vigilante-analyzer-category-state--info" title="<?php esc_attr_e( 'Informational', 'vigilante' ); ?>">
2925 <span data-role="state-info"><?php echo esc_html( $info_count ); ?></span><span class="dashicons dashicons-info-outline" aria-hidden="true"></span>
2926 </span>
2927 <?php endif; ?>
2928 </span>
2929 <?php endif; ?>
2930 <?php if ( ! $info_only ) : ?>
2931 <span class="vigilante-analyzer-category-score">
2932 <span data-role="earned"><?php echo esc_html( $earned ); ?></span><span class="vigilante-analyzer-category-score-sep">/</span><?php echo esc_html( $cat_max ); ?>
2933 <span class="vigilante-analyzer-category-score-unit"><?php esc_html_e( 'pts', 'vigilante' ); ?></span>
2934 </span>
2935 <span class="vigilante-analyzer-category-bar" aria-hidden="true">
2936 <span class="vigilante-analyzer-category-bar-fill vigilante-analyzer-category-bar-fill--<?php echo esc_attr( $cat_quality['slug'] ); ?>"
2937 style="width: <?php echo esc_attr( $cat_pct ); ?>%"
2938 data-role="category-bar"></span>
2939 </span>
2940 <?php else :
2941 $info_warn = isset( $cat_counts['warn'] ) ? (int) $cat_counts['warn'] : 0;
2942 $info_fail = isset( $cat_counts['fail'] ) ? (int) $cat_counts['fail'] : 0;
2943 $info_issues = $info_warn + $info_fail;
2944 if ( $info_issues > 0 ) : ?>
2945 <span class="vigilante-analyzer-category-status vigilante-analyzer-category-status--attention" data-role="info-status">
2946 <span class="dashicons dashicons-warning" aria-hidden="true"></span>
2947 <?php
2948 echo esc_html( sprintf(
2949 /* translators: %d: number of findings */
2950 _n( '%d finding', '%d findings', $info_issues, 'vigilante' ),
2951 $info_issues
2952 ) );
2953 ?>
2954 </span>
2955 <?php else : ?>
2956 <span class="vigilante-analyzer-category-status vigilante-analyzer-category-status--clear" data-role="info-status">
2957 <span class="dashicons dashicons-yes-alt" aria-hidden="true"></span>
2958 <?php esc_html_e( 'All clear', 'vigilante' ); ?>
2959 </span>
2960 <?php endif; ?>
2961 <?php endif; ?>
2962 </summary>
2963 <ul class="vigilante-analyzer-check-list" data-role="check-list">
2964 <?php if ( empty( $checks ) ) : ?>
2965 <li class="vigilante-analyzer-check-empty">
2966 <?php esc_html_e( 'No data yet — run a scan to populate this category.', 'vigilante' ); ?>
2967 </li>
2968 <?php else : ?>
2969 <?php foreach ( $checks as $c ) : ?>
2970 <?php echo self::render_analyzer_check_row( $c ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped inside helper ?>
2971 <?php endforeach; ?>
2972 <?php endif; ?>
2973 </ul>
2974 </details>
2975 <?php endforeach; ?>
2976 </div>
2977
2978 <div class="vigilante-analyzer-weekly">
2979 <h3><?php esc_html_e( 'Automatic weekly scan', 'vigilante' ); ?></h3>
2980 <p class="description">
2981 <?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' ); ?>
2982 </p>
2983 <label class="vigilante-analyzer-toggle-option">
2984 <input type="checkbox"
2985 name="security_analyzer[weekly_scan_enabled]"
2986 value="1"
2987 <?php checked( $weekly_enabled ); ?>>
2988 <?php esc_html_e( 'Run a weekly automatic scan', 'vigilante' ); ?>
2989 </label>
2990 <label class="vigilante-analyzer-toggle-option">
2991 <input type="checkbox"
2992 name="security_analyzer[email_on_regression]"
2993 value="1"
2994 <?php checked( $email_enabled ); ?>>
2995 <?php esc_html_e( 'Email me when the score drops significantly', 'vigilante' ); ?>
2996 </label>
2997 </div>
2998 </div>
2999 </div>
3000 <?php
3001 }
3002
3003 /**
3004 * Map a 0-100 percentage to a quality tag { label, slug } aligned with the
3005 * Dashboard grade palette (a/b/c/d/e).
3006 *
3007 * @param int $pct 0..100.
3008 * @return array{label:string,slug:string}
3009 */
3010 public static function analyzer_quality_tag( $pct ) {
3011 $pct = max( 0, min( 100, (int) $pct ) );
3012 // "Excellent" is reserved for a perfect score — a single missing point drops to Good.
3013 if ( 100 === $pct ) {
3014 return array( 'label' => __( 'Excellent', 'vigilante' ), 'slug' => 'a' );
3015 }
3016 if ( $pct >= 70 ) {
3017 return array( 'label' => __( 'Good', 'vigilante' ), 'slug' => 'b' );
3018 }
3019 if ( $pct >= 50 ) {
3020 return array( 'label' => __( 'Fair', 'vigilante' ), 'slug' => 'c' );
3021 }
3022 if ( $pct >= 30 ) {
3023 return array( 'label' => __( 'Poor', 'vigilante' ), 'slug' => 'd' );
3024 }
3025 return array( 'label' => __( 'Critical', 'vigilante' ), 'slug' => 'e' );
3026 }
3027
3028 /**
3029 * Render a single analyzer check row (used both server-side and via JS template).
3030 *
3031 * @param array $check Check result array (from Vigilante_SA_Check_Result::to_array()).
3032 * @return string HTML (escaped).
3033 */
3034 private static function render_analyzer_check_row( $check ) {
3035 $id = isset( $check['id'] ) ? $check['id'] : '';
3036 $state = isset( $check['state'] ) ? $check['state'] : 'skip';
3037 $label = isset( $check['label'] ) ? $check['label'] : '';
3038 $detail = isset( $check['detail'] ) ? $check['detail'] : '';
3039 $score = isset( $check['score'] ) ? (int) $check['score'] : 0;
3040 $max = isset( $check['max'] ) ? (int) $check['max'] : 0;
3041 $fix_link = isset( $check['fix_link'] ) ? $check['fix_link'] : '';
3042
3043 $icons = array(
3044 'pass' => 'yes-alt',
3045 'warn' => 'warning',
3046 'fail' => 'dismiss',
3047 'info' => 'info',
3048 'skip' => 'minus',
3049 );
3050 $icon = isset( $icons[ $state ] ) ? $icons[ $state ] : 'minus';
3051
3052 $html = '<li class="vigilante-analyzer-check vigilante-analyzer-check--' . esc_attr( $state ) . '"';
3053 $html .= ' data-check-id="' . esc_attr( $id ) . '">';
3054 $html .= '<span class="vigilante-analyzer-check-icon dashicons dashicons-' . esc_attr( $icon ) . '" aria-hidden="true"></span>';
3055 $html .= '<div class="vigilante-analyzer-check-body">';
3056 $html .= '<div class="vigilante-analyzer-check-label">';
3057 $html .= '<span>' . esc_html( $label ) . '</span>';
3058 if ( $max > 0 && 'info' !== $state && 'skip' !== $state ) {
3059 $html .= '<span class="vigilante-analyzer-check-score">'
3060 . esc_html( $score . '/' . $max )
3061 . ' <span class="vigilante-analyzer-check-score-unit">' . esc_html__( 'pts', 'vigilante' ) . '</span>'
3062 . '</span>';
3063 }
3064 $html .= '</div>';
3065 if ( $detail ) {
3066 $html .= '<p class="vigilante-analyzer-check-detail">' . esc_html( $detail ) . '</p>';
3067 }
3068 if ( $fix_link && in_array( $state, array( 'fail', 'warn' ), true ) ) {
3069 $html .= '<a href="' . esc_url( $fix_link ) . '" class="vigilante-analyzer-fix-link">'
3070 . esc_html__( 'Go to setting', 'vigilante' )
3071 . '<span class="vigilante-analyzer-fix-arrow" aria-hidden="true">&rarr;</span></a>';
3072 } elseif ( $fix_link && 'info' === $state ) {
3073 // Info rows (e.g. DNSBL lookups) get an external "Learn more" link instead.
3074 $is_external = 0 === strpos( $fix_link, 'http' );
3075 $html .= '<a href="' . esc_url( $fix_link ) . '" class="vigilante-analyzer-fix-link"'
3076 . ( $is_external ? ' target="_blank" rel="noopener noreferrer"' : '' ) . '>'
3077 . esc_html__( 'Learn more', 'vigilante' )
3078 . '<span class="vigilante-analyzer-fix-arrow" aria-hidden="true">&rarr;</span></a>';
3079 }
3080 $html .= '</div>';
3081 $html .= '</li>';
3082 return $html;
3083 }
3084
3085 /**
3086 * Build a minimal SVG sparkline for the score history.
3087 *
3088 * @param int[] $points Score values (0..100), oldest to newest.
3089 * @return string SVG markup.
3090 */
3091 private static function sparkline_svg( $points ) {
3092 $points = array_map( 'intval', (array) $points );
3093 $count = count( $points );
3094 if ( $count < 2 ) {
3095 return '';
3096 }
3097 $width = 280;
3098 $height = 60;
3099 $padding = 4;
3100
3101 $usable_w = $width - ( $padding * 2 );
3102 $usable_h = $height - ( $padding * 2 );
3103
3104 $step = $usable_w / max( 1, $count - 1 );
3105 $max = 100; // Fixed scale — scores are 0..100.
3106
3107 $coords = array();
3108 foreach ( $points as $i => $v ) {
3109 $x = $padding + ( $i * $step );
3110 $y = $padding + ( $usable_h - ( ( $v / $max ) * $usable_h ) );
3111 $coords[] = round( $x, 2 ) . ',' . round( $y, 2 );
3112 }
3113 $path = 'M ' . implode( ' L ', $coords );
3114 $last = end( $points );
3115 $last_x = $padding + ( ( $count - 1 ) * $step );
3116 $last_y = $padding + ( $usable_h - ( ( $last / $max ) * $usable_h ) );
3117
3118 $svg = '<svg viewBox="0 0 ' . $width . ' ' . $height . '" preserveAspectRatio="none" role="img" aria-label="' . esc_attr__( 'Security Score history', 'vigilante' ) . '" focusable="false">';
3119 $svg .= '<path d="' . esc_attr( $path ) . '" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>';
3120 $svg .= '<circle cx="' . esc_attr( round( $last_x, 2 ) ) . '" cy="' . esc_attr( round( $last_y, 2 ) ) . '" r="3" fill="currentColor"/>';
3121 $svg .= '</svg>';
3122 return $svg;
3123 }
3124
3125 /**
3126 * Render dashboard tab
3127 */
3128 /**
3129 * One line strip at the top of the Dashboard tab: the state of Vigilant own
3130 * files, above the Configuration Score and the Security Check, because
3131 * nothing else on this screen means much while it is red.
3132 */
3133 private function render_self_protection_strip() {
3134 $summary = $this->self_integrity_summary();
3135 $tone = $summary['tone'];
3136 $state = $summary['state'];
3137 $count = count( $summary['findings'] );
3138 $link = admin_url( 'admin.php?page=vigilante&tab=file-integrity#vigilante-section-fi-self' );
3139 ?>
3140 <div class="vigilante-self-strip vigilante-self-strip--<?php echo esc_attr( $tone ); ?>">
3141 <span class="dashicons dashicons-shield" aria-hidden="true"></span>
3142 <strong><?php esc_html_e( 'Vigilant self-protection', 'vigilante' ); ?></strong>
3143 <span class="vigilante-self-strip-state"><?php echo esc_html( $this->self_integrity_headline( $tone, $state ) ); ?></span>
3144 <?php if ( $count > 0 ) : ?>
3145 <span class="vigilante-self-strip-count">
3146 <?php
3147 printf(
3148 /* translators: %d: number of findings about Vigilant own files */
3149 esc_html( _n( '%d finding', '%d findings', $count, 'vigilante' ) ),
3150 (int) $count
3151 );
3152 ?>
3153 </span>
3154 <?php elseif ( ! empty( $state['last_check'] ) && 'off' !== $tone ) : ?>
3155 <span class="vigilante-self-strip-count">
3156 <?php
3157 printf(
3158 /* translators: %s: human time difference, like "2 hours" */
3159 esc_html__( 'checked %s ago', 'vigilante' ),
3160 esc_html( human_time_diff( (int) $state['last_check'], time() ) )
3161 );
3162 ?>
3163 </span>
3164 <?php endif; ?>
3165 <a href="<?php echo esc_url( $link ); ?>">
3166 <?php
3167 if ( in_array( $tone, array( 'critical', 'off', 'warning' ), true ) ) {
3168 esc_html_e( 'See what to do', 'vigilante' );
3169 } else {
3170 esc_html_e( 'See details', 'vigilante' );
3171 }
3172 ?>
3173 </a>
3174 </div>
3175 <?php
3176 }
3177
3178 private function render_tab_dashboard() {
3179 $options = $this->settings->get_all_options();
3180 $module_labels = $this->settings->get_module_labels();
3181 $module_descriptions = $this->settings->get_module_descriptions();
3182 $presets = $this->settings->get_presets();
3183 $active_preset = get_option( 'vigilante_active_preset', '' );
3184
3185 // Calculate security score with more factors
3186 $security_score = $this->calculate_security_score( $options );
3187
3188 // Security Analyzer (v2.1.0) — hydrate widget with the last persisted scan, if any.
3189 if ( ! class_exists( 'Vigilante_Security_Analyzer' ) ) {
3190 require_once VIGILANTE_INCLUDES_DIR . 'class-security-analyzer.php';
3191 }
3192 $analyzer_instance = new Vigilante_Security_Analyzer( $this->settings, $this->activity_log );
3193 $analyzer_last_scan = $analyzer_instance->get_last_scan();
3194 $analyzer_history = $analyzer_instance->get_score_history();
3195 $analyzer_categories_def = Vigilante_Security_Analyzer::get_categories();
3196 $analyzer_settings = isset( $options['security_analyzer'] ) ? $options['security_analyzer'] : array();
3197 ?>
3198 <div class="vigilante-dashboard">
3199 <?php $this->render_self_protection_strip(); ?>
3200 <div class="vigilante-status-card">
3201 <h2><?php esc_html_e( 'Configuration Score', 'vigilante' ); ?></h2>
3202 <p class="vigilante-score-kind description">
3203 <?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' ); ?>
3204 </p>
3205 <div class="vigilante-security-score">
3206 <?php
3207 // Grade thresholds: A (90+), B (70-89), C (50-69), D (30-49), E (0-29)
3208 if ( $security_score >= 90 ) {
3209 $grade = 'A';
3210 } elseif ( $security_score >= 70 ) {
3211 $grade = 'B';
3212 } elseif ( $security_score >= 50 ) {
3213 $grade = 'C';
3214 } elseif ( $security_score >= 30 ) {
3215 $grade = 'D';
3216 } else {
3217 $grade = 'E';
3218 }
3219 ?>
3220 <div class="vigilante-score-circle vigilante-grade-<?php echo esc_attr( strtolower( $grade ) ); ?>">
3221 <span class="vigilante-grade"><?php echo esc_html( $grade ); ?></span>
3222 <span class="vigilante-score-text"><?php echo esc_html( $security_score ); ?>%</span>
3223 </div>
3224 <div class="vigilante-config-status">
3225 <?php if ( $active_preset && isset( $presets[ $active_preset ] ) ) : ?>
3226 <span class="vigilante-preset-badge vigilante-preset-<?php echo esc_attr( $active_preset ); ?>">
3227 <?php echo esc_html( $presets[ $active_preset ]['name'] ); ?>
3228 </span>
3229 <?php else : ?>
3230 <span class="vigilante-preset-badge vigilante-preset-custom">
3231 <?php esc_html_e( 'Custom Configuration', 'vigilante' ); ?>
3232 </span>
3233 <?php endif; ?>
3234 </div>
3235 </div>
3236
3237 <?php
3238 $recommendations = $this->get_security_recommendations( $options );
3239 if ( ! empty( $recommendations ) ) :
3240 ?>
3241 <div class="vigilante-recommendations">
3242 <h4><?php esc_html_e( 'Recommendations', 'vigilante' ); ?></h4>
3243 <ul class="vigilante-recommendations-grid">
3244 <?php foreach ( $recommendations as $rec ) : ?>
3245 <li>
3246 <span class="dashicons dashicons-<?php echo esc_attr( $rec['icon'] ); ?> vigilante-priority-<?php echo esc_attr( $rec['priority'] ); ?>"></span>
3247 <?php echo esc_html( $rec['message'] ); ?>
3248 <?php if ( ! empty( $rec['tab'] ) ) : ?>
3249 <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>
3250 <?php endif; ?>
3251 </li>
3252 <?php endforeach; ?>
3253 </ul>
3254 </div>
3255 <?php endif; ?>
3256 </div>
3257
3258 <?php $this->render_analyzer_widget( $analyzer_last_scan, $analyzer_history, $analyzer_categories_def, $analyzer_settings ); ?>
3259
3260 <div class="vigilante-modules-grid">
3261 <h2 id="vigilante-section-dashboard-modules"><?php esc_html_e( 'Security Modules', 'vigilante' ); ?></h2>
3262 <p class="description"><?php esc_html_e( 'Enable or disable security modules. Each module controls a tab with detailed settings.', 'vigilante' ); ?></p>
3263 <div class="vigilante-modules-list">
3264 <?php foreach ( $options['modules'] as $module => $enabled ) :
3265 $label = isset( $module_labels[ $module ] ) ? $module_labels[ $module ] : ucwords( str_replace( '_', ' ', $module ) );
3266 $description = isset( $module_descriptions[ $module ] ) ? $module_descriptions[ $module ] : '';
3267 $vg_module_locked = $this->main_site_files_locked() && in_array( $module, Vigilante_Settings::get_main_site_file_settings()['modules'], true );
3268 ?>
3269 <div class="vigilante-module-item <?php echo $enabled ? 'enabled' : 'disabled'; ?>">
3270 <div class="vigilante-module-header">
3271 <span class="vigilante-module-status"></span>
3272 <span class="vigilante-module-name"><?php echo esc_html( $label ); ?></span>
3273 <label class="vigilante-toggle">
3274 <?php
3275 /* translators: %s: Security module name, for example Firewall. */
3276 $toggle_label = sprintf( __( 'Enable %s', 'vigilante' ), $label );
3277 ?>
3278 <input type="checkbox"
3279 name="modules[<?php echo esc_attr( $module ); ?>]"
3280 value="1"
3281 <?php checked( $enabled ); ?>
3282 <?php disabled( $vg_module_locked ); ?>
3283 aria-label="<?php echo esc_attr( $toggle_label ); ?>"
3284 data-module="<?php echo esc_attr( $module ); ?>">
3285 <span class="vigilante-toggle-slider"></span>
3286 </label>
3287 </div>
3288 <?php if ( $description ) : ?>
3289 <p class="vigilante-module-desc"><?php echo esc_html( $description ); ?></p>
3290 <?php endif; ?>
3291 <?php if ( $vg_module_locked ) : ?>
3292 <p class="vigilante-module-desc"><?php esc_html_e( 'On the main site of a network this module also writes files every site shares, so only a network administrator can switch it.', 'vigilante' ); ?></p>
3293 <?php endif; ?>
3294 </div>
3295 <?php endforeach; ?>
3296 </div>
3297 </div>
3298
3299 <div class="vigilante-presets-card">
3300 <h2><?php esc_html_e( 'Quick Configuration Presets', 'vigilante' ); ?></h2>
3301 <p><?php esc_html_e( 'Apply a preset to quickly set up recommended settings for standard or maximum security level.', 'vigilante' ); ?></p>
3302 <div class="vigilante-presets-grid">
3303 <?php foreach ( $presets as $preset_id => $preset ) :
3304 $is_active = ( $active_preset === $preset_id );
3305 ?>
3306 <div class="vigilante-preset-card <?php echo $is_active ? 'vigilante-preset-active' : ''; ?>">
3307 <?php if ( $is_active ) : ?>
3308 <span class="vigilante-active-indicator"><?php esc_html_e( 'Active', 'vigilante' ); ?></span>
3309 <?php endif; ?>
3310 <h3><?php echo esc_html( $preset['name'] ); ?></h3>
3311 <p><?php echo esc_html( $preset['description'] ); ?></p>
3312 <button type="button" class="button vigilante-preset-btn <?php echo $is_active ? 'button-primary' : ''; ?>" data-preset="<?php echo esc_attr( $preset_id ); ?>">
3313 <?php esc_html_e( 'Apply Preset', 'vigilante' ); ?>
3314 </button>
3315 </div>
3316 <?php endforeach; ?>
3317
3318 <?php
3319 // Under Attack mode card
3320 $under_attack = new Vigilante_Under_Attack( $this->settings, $this->activity_log );
3321 $ua_active = $under_attack->is_active();
3322 $ua_remaining = $under_attack->get_remaining_time();
3323 $ua_remaining_hours = floor( $ua_remaining / 3600 );
3324 $ua_remaining_mins = floor( ( $ua_remaining % 3600 ) / 60 );
3325 ?>
3326 <div class="vigilante-preset-card vigilante-under-attack-card <?php echo $ua_active ? 'vigilante-under-attack-active' : ''; ?>">
3327 <h3 id="vigilante-section-dashboard-under-attack">
3328 <span class="dashicons dashicons-shield"></span>
3329 <?php esc_html_e( 'Under Attack', 'vigilante' ); ?>
3330 </h3>
3331 <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>
3332 <?php if ( $ua_active ) : ?>
3333 <div class="vigilante-ua-countdown" data-expires="<?php echo esc_attr( $under_attack->get_status()['activated_at'] + $under_attack->get_status()['duration'] ); ?>">
3334 <span class="dashicons dashicons-clock"></span>
3335 <span class="vigilante-ua-time">
3336 <?php
3337 printf(
3338 /* translators: 1: Hours, 2: Minutes */
3339 esc_html__( '%1$dh %2$dm remaining', 'vigilante' ),
3340 absint( $ua_remaining_hours ),
3341 absint( $ua_remaining_mins )
3342 );
3343 ?>
3344 </span>
3345 </div>
3346 <button type="button" class="button vigilante-ua-btn vigilante-ua-deactivate">
3347 <?php esc_html_e( 'Deactivate', 'vigilante' ); ?>
3348 </button>
3349 <?php else : ?>
3350 <button type="button" class="button vigilante-ua-btn vigilante-ua-activate">
3351 <?php esc_html_e( 'Activate for 4 hours', 'vigilante' ); ?>
3352 </button>
3353 <?php endif; ?>
3354 </div>
3355 </div>
3356 </div>
3357 </div>
3358 <?php
3359 }
3360
3361 /**
3362 * Render tools tab
3363 */
3364 private function render_tab_tools() {
3365 // Get current settings for notification summary
3366 $email_options = $this->settings->get_section( 'email' );
3367 $login_options = $this->settings->get_section( 'login_security' );
3368 $user_options = $this->settings->get_section( 'user_security' );
3369 $fi_options = $this->settings->get_section( 'file_integrity' );
3370 $alerts_options = $this->settings->get_section( 'audit_alerts' );
3371 $monitoring = $user_options['admin_monitoring'] ?? array();
3372 $registration = $user_options['registration_approval'] ?? array();
3373 $current_admin = get_option( 'admin_email' );
3374 $send_to_admin = ! isset( $email_options['send_to_admin_email'] ) || ! empty( $email_options['send_to_admin_email'] );
3375 $additional_raw = $email_options['additional_recipients'] ?? array();
3376 $additional = is_array( $additional_raw ) ? implode( "\n", $additional_raw ) : trim( $additional_raw );
3377 ?>
3378
3379 <!-- Notification Settings -->
3380 <div id="vigilante-section-tools-notifications" class="vigilante-settings-section vigilante-notification-section">
3381 <h2><?php esc_html_e( 'Notification settings', 'vigilante' ); ?></h2>
3382 <p><?php esc_html_e( 'Configure who receives all administrative email notifications from Vigilant. Individual notifications are enabled in their respective tabs.', 'vigilante' ); ?></p>
3383
3384 <div class="vigilante-notification-layout">
3385
3386 <!-- Left column: Recipients settings -->
3387 <div class="vigilante-notification-settings">
3388 <form class="vigilante-settings-form" data-section="email">
3389
3390 <table class="form-table vigilante-compact-form">
3391 <tr>
3392 <th scope="row"><?php esc_html_e( 'WordPress Admin Email', 'vigilante' ); ?></th>
3393 <td>
3394 <label>
3395 <input type="checkbox" name="email[send_to_admin_email]" value="1" <?php checked( $send_to_admin ); ?>>
3396 <?php
3397 printf(
3398 /* translators: %s: Admin email address */
3399 esc_html__( 'Send to admin email (%s)', 'vigilante' ),
3400 '<code>' . esc_html( $current_admin ) . '</code>'
3401 );
3402 ?>
3403 </label>
3404 </td>
3405 </tr>
3406 <tr>
3407 <th scope="row"><label for="vigilante-f-email-additional-recipients"><?php esc_html_e( 'Additional Recipients', 'vigilante' ); ?></label></th>
3408 <td>
3409 <textarea id="vigilante-f-email-additional-recipients" name="email[additional_recipients]" rows="3" class="large-text code" placeholder="[email protected]&#10;[email protected]"><?php echo esc_textarea( $additional ); ?></textarea>
3410 <p class="description"><?php esc_html_e( 'One email per line.', 'vigilante' ); ?></p>
3411 </td>
3412 </tr>
3413 <tr>
3414 <th scope="row"><?php esc_html_e( 'Plugin Deactivation', 'vigilante' ); ?></th>
3415 <td>
3416 <label>
3417 <input type="checkbox" name="email[send_deactivation_email]" value="1" <?php checked( ! empty( $email_options['send_deactivation_email'] ) ); ?>>
3418 <?php esc_html_e( 'Send email when Vigilant is deactivated', 'vigilante' ); ?>
3419 </label>
3420 </td>
3421 </tr>
3422 </table>
3423
3424 <p class="submit vigilante-notification-submit">
3425 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
3426 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
3427 </button>
3428 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
3429 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
3430 </button>
3431 <span class="vigilante-test-email-result" style="margin-left:8px;vertical-align:middle;"></span>
3432 </p>
3433 <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>
3434
3435 </form>
3436 </div>
3437
3438 <!-- Right column: Active notifications summary -->
3439 <div class="vigilante-notification-summary">
3440 <h4><?php esc_html_e( 'Active notifications', 'vigilante' ); ?></h4>
3441
3442 <table class="widefat striped">
3443 <thead>
3444 <tr>
3445 <th><?php esc_html_e( 'Notification', 'vigilante' ); ?></th>
3446 <th style="width: 1%; white-space: nowrap; text-align: center;"><?php esc_html_e( 'Status', 'vigilante' ); ?></th>
3447 <th style="width: 50px; text-align: center;"></th>
3448 </tr>
3449 </thead>
3450 <tbody>
3451 <?php
3452 $notifications = array(
3453 array(
3454 'label' => __( 'Login lockout', 'vigilante' ),
3455 'active' => ! empty( $login_options['notify_on_lockout'] ),
3456 'tab' => 'login',
3457 ),
3458 array(
3459 'label' => __( 'Administrator login', 'vigilante' ),
3460 'active' => ! empty( $login_options['notify_on_admin_login'] ),
3461 'tab' => 'login',
3462 ),
3463 array(
3464 'label' => __( 'New administrator created', 'vigilante' ),
3465 'active' => ! empty( $monitoring['alert_new_admin'] ),
3466 'tab' => 'users',
3467 ),
3468 array(
3469 'label' => __( 'Administrator email changed', 'vigilante' ),
3470 'active' => ! empty( $monitoring['alert_admin_email_change'] ),
3471 'tab' => 'users',
3472 ),
3473 array(
3474 'label' => __( 'Permission elevation', 'vigilante' ),
3475 'active' => ! empty( $monitoring['alert_permission_elevation'] ),
3476 'tab' => 'users',
3477 ),
3478 array(
3479 'label' => __( 'Admin password changed', 'vigilante' ),
3480 'active' => ! empty( $monitoring['alert_admin_password_change'] ),
3481 'tab' => 'users',
3482 ),
3483 array(
3484 'label' => __( 'Registration pending approval', 'vigilante' ),
3485 'active' => ! empty( $registration['enabled'] ) && ! empty( $registration['notify_admin'] ),
3486 'tab' => 'users',
3487 ),
3488 array(
3489 'label' => __( 'File integrity scan report', 'vigilante' ),
3490 'active' => ( $fi_options['notify_level'] ?? 'disabled' ) !== 'disabled',
3491 'tab' => 'file-integrity',
3492 ),
3493 array(
3494 'label' => __( 'File integrity instant alert', 'vigilante' ),
3495 'active' => ! empty( $fi_options['instant_alert'] ),
3496 'tab' => 'file-integrity',
3497 ),
3498 array(
3499 'label' => __( 'Audit alert: immediate', 'vigilante' ),
3500 'active' => Vigilante_Audit_Alerts::immediate_is_active( $alerts_options ),
3501 'tab' => 'activity-log',
3502 'anchor' => 'vigilante-section-audit-alerts',
3503 ),
3504 array(
3505 'label' => __( 'Audit alert: threshold', 'vigilante' ),
3506 'active' => Vigilante_Audit_Alerts::threshold_is_active( $alerts_options ),
3507 'tab' => 'activity-log',
3508 'anchor' => 'vigilante-section-audit-alerts',
3509 ),
3510 array(
3511 'label' => __( 'Under Attack mode', 'vigilante' ),
3512 'active' => true,
3513 'tab' => '',
3514 'note' => __( 'Always active', 'vigilante' ),
3515 ),
3516 array(
3517 'label' => __( 'Plugin deactivation', 'vigilante' ),
3518 'active' => ! empty( $email_options['send_deactivation_email'] ),
3519 'tab' => 'tools',
3520 ),
3521 );
3522
3523 foreach ( $notifications as $notif ) :
3524 $status_class = $notif['active'] ? 'vigilante-status-active' : 'vigilante-status-inactive';
3525 $status_label = $notif['active'] ? __( 'Active', 'vigilante' ) : __( 'Inactive', 'vigilante' );
3526 if ( ! empty( $notif['note'] ) ) {
3527 $status_label = $notif['note'];
3528 }
3529 ?>
3530 <tr>
3531 <td><?php echo esc_html( $notif['label'] ); ?></td>
3532 <td style="text-align: center; white-space: nowrap;">
3533 <span class="<?php echo esc_attr( $status_class ); ?>"><?php echo esc_html( $status_label ); ?></span>
3534 </td>
3535 <td style="text-align: center;">
3536 <?php if ( ! empty( $notif['tab'] ) ) : ?>
3537 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=' . $notif['tab'] ) . ( ! empty( $notif['anchor'] ) ? '#' . $notif['anchor'] : '' ) ); ?>" class="button button-small">
3538 <span class="dashicons dashicons-admin-generic" style="font-size: 14px; line-height: 1.8;"></span>
3539 </a>
3540 <?php else : ?>
3541 &mdash;
3542 <?php endif; ?>
3543 </td>
3544 </tr>
3545 <?php endforeach; ?>
3546 </tbody>
3547 </table>
3548 </div>
3549
3550 </div>
3551 </div>
3552
3553 <h2 id="vigilante-section-tools-main" class="vigilante-tools-heading"><?php esc_html_e( 'Tools', 'vigilante' ); ?></h2>
3554
3555 <?php
3556 // Warn that during Under Attack mode the export/import operate against
3557 // the temporary hardened config and any imported changes will be
3558 // reverted when the mode ends.
3559 $ua_status = get_option( Vigilante_Under_Attack::OPTION_NAME, array() );
3560 if ( ! empty( $ua_status['active'] ) ) :
3561 ?>
3562 <div class="vigilante-ua-tools-notice-wrap">
3563 <div class="notice notice-warning inline vigilante-ua-tools-notice">
3564 <p>
3565 <strong><?php esc_html_e( 'Under Attack mode is active.', 'vigilante' ); ?></strong>
3566 <?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' ); ?>
3567 </p>
3568 </div>
3569 </div>
3570 <?php
3571 endif;
3572 ?>
3573
3574 <div class="vigilante-tools-grid">
3575 <div class="vigilante-tool-card">
3576 <h3><?php esc_html_e( 'Export Settings', 'vigilante' ); ?></h3>
3577 <p><?php esc_html_e( 'Download your current security settings as a JSON file.', 'vigilante' ); ?></p>
3578 <button type="button" class="button vigilante-export-settings">
3579 <?php esc_html_e( 'Export Settings', 'vigilante' ); ?>
3580 </button>
3581 </div>
3582
3583 <div class="vigilante-tool-card">
3584 <h3><?php esc_html_e( 'Import Settings', 'vigilante' ); ?></h3>
3585 <p><?php esc_html_e( 'Import settings from a previously exported JSON file.', 'vigilante' ); ?></p>
3586 <input type="file" id="vigilante-import-file" aria-label="<?php esc_attr_e( 'Configuration file to import', 'vigilante' ); ?>" accept=".json" style="display: none;">
3587 <button type="button" class="button vigilante-import-settings">
3588 <?php esc_html_e( 'Import Settings', 'vigilante' ); ?>
3589 </button>
3590 </div>
3591
3592 <div class="vigilante-tool-card">
3593 <h3><?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?></h3>
3594 <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>
3595 <button type="button" class="button vigilante-reset-settings" style="color: #a00;">
3596 <?php esc_html_e( 'Reset All Settings', 'vigilante' ); ?>
3597 </button>
3598 </div>
3599
3600 <div class="vigilante-tool-card">
3601 <h3><?php esc_html_e( 'Download Config Backup', 'vigilante' ); ?></h3>
3602 <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>
3603 <?php if ( $this->shared_files_locked() ) : ?>
3604 <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>
3605 <?php else : ?>
3606 <button type="button" class="button vigilante-create-backup">
3607 <?php esc_html_e( 'Download Backup', 'vigilante' ); ?>
3608 </button>
3609 <?php endif; ?>
3610 </div>
3611
3612 <?php if ( ! $this->shared_files_locked() ) : ?>
3613
3614 <div class="vigilante-tool-card vigilante-tool-card-wide">
3615 <h3><?php esc_html_e( 'Database Backup', 'vigilante' ); ?></h3>
3616 <p><?php esc_html_e( 'Download a backup of your database as a ZIP file. Select which tables to include.', 'vigilante' ); ?></p>
3617 <button type="button" class="button vigilante-db-backup-toggle">
3618 <?php esc_html_e( 'Download Database Backup', 'vigilante' ); ?>
3619 </button>
3620
3621 <div class="vigilante-db-backup-panel" style="display: none;">
3622 <div class="vigilante-db-tables-loading">
3623 <span class="spinner is-active"></span>
3624 <?php esc_html_e( 'Loading tables...', 'vigilante' ); ?>
3625 </div>
3626
3627 <div class="vigilante-db-tables-content" style="display: none;">
3628 <div class="vigilante-db-tables-controls">
3629 <label>
3630 <input type="checkbox" id="vigilante-db-select-all" checked>
3631 <strong><?php esc_html_e( 'Select / deselect all', 'vigilante' ); ?></strong>
3632 </label>
3633 <span class="vigilante-db-tables-info"></span>
3634 </div>
3635
3636 <div class="vigilante-db-tables-group">
3637 <h4><?php esc_html_e( 'WordPress core tables', 'vigilante' ); ?></h4>
3638 <div class="vigilante-db-tables-list" id="vigilante-db-core-tables"></div>
3639 </div>
3640
3641 <div class="vigilante-db-tables-group" id="vigilante-db-other-group" style="display: none;">
3642 <h4><?php esc_html_e( 'Plugin and custom tables', 'vigilante' ); ?></h4>
3643 <div class="vigilante-db-tables-list" id="vigilante-db-other-tables"></div>
3644 </div>
3645
3646 <div class="vigilante-db-backup-actions">
3647 <button type="button" class="button button-primary vigilante-db-backup-download">
3648 <?php esc_html_e( 'Download Backup (.zip)', 'vigilante' ); ?>
3649 </button>
3650 </div>
3651 </div>
3652 </div>
3653 </div>
3654 <?php else : ?>
3655 <div class="vigilante-tool-card vigilante-tool-card-wide">
3656 <h3><?php esc_html_e( 'Database Backup', 'vigilante' ); ?></h3>
3657 <p><?php esc_html_e( 'Download a backup of your database as a ZIP file. Select which tables to include.', 'vigilante' ); ?></p>
3658 <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>
3659 </div>
3660 <?php endif; ?>
3661 </div>
3662 <?php
3663 }
3664
3665 /**
3666 * Render firewall tab
3667 */
3668 private function render_tab_firewall() {
3669 $is_disabled = $this->render_module_disabled_notice( 'firewall' );
3670 $options = $this->settings->get_section( 'firewall' );
3671 ?>
3672 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="firewall" <?php echo $is_disabled ? 'inert' : ''; ?>>
3673 <div id="vigilante-section-firewall-main" class="vigilante-settings-section">
3674 <h2>
3675 <?php esc_html_e( 'Firewall Protection', 'vigilante' ); ?>
3676 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
3677 </h2>
3678 <p><?php esc_html_e( 'PHP-based request filtering. Analyzes each request before WordPress loads.', 'vigilante' ); ?></p>
3679 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
3680 <p style="margin:0;">
3681 <?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' ); ?>
3682 </p>
3683 </div>
3684
3685 <?php $vg_main_locked = $this->main_site_files_locked(); ?>
3686 <?php if ( $vg_main_locked ) : ?>
3687 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
3688 <p style="margin:0;"><?php esc_html_e( 'On the main site of a network, blocking bad bots and bad query strings, the visitor IP detection and the two whitelists also build the .htaccess rules every site shares, so only a network administrator can change them.', 'vigilante' ); ?></p>
3689 </div>
3690 <?php endif; ?>
3691
3692 <table class="form-table">
3693 <tr>
3694 <th scope="row"><?php esc_html_e( 'Block Bad Query Strings', 'vigilante' ); ?></th>
3695 <td>
3696 <label>
3697 <input type="checkbox" name="firewall[block_bad_query_strings]" value="1" <?php disabled( $vg_main_locked ); ?> <?php checked( ! empty( $options['block_bad_query_strings'] ) ); ?>>
3698 <?php esc_html_e( 'Block malicious query string patterns', 'vigilante' ); ?>
3699 </label>
3700 </td>
3701 </tr>
3702 <tr>
3703 <th scope="row"><?php esc_html_e( 'SQL Injection Protection', 'vigilante' ); ?></th>
3704 <td>
3705 <label>
3706 <input type="checkbox" name="firewall[block_sql_injection]" value="1" <?php checked( ! empty( $options['block_sql_injection'] ) ); ?>>
3707 <?php esc_html_e( 'Block SQL injection attempts', 'vigilante' ); ?>
3708 </label>
3709 </td>
3710 </tr>
3711 <tr>
3712 <th scope="row"><?php esc_html_e( 'XSS Protection', 'vigilante' ); ?></th>
3713 <td>
3714 <label>
3715 <input type="checkbox" name="firewall[block_xss_attacks]" value="1" <?php checked( ! empty( $options['block_xss_attacks'] ) ); ?>>
3716 <?php esc_html_e( 'Block cross-site scripting attacks', 'vigilante' ); ?>
3717 </label>
3718 </td>
3719 </tr>
3720 <tr>
3721 <th scope="row"><?php esc_html_e( 'File Inclusion Protection', 'vigilante' ); ?></th>
3722 <td>
3723 <label>
3724 <input type="checkbox" name="firewall[block_file_inclusion]" value="1" <?php checked( ! empty( $options['block_file_inclusion'] ) ); ?>>
3725 <?php esc_html_e( 'Block local/remote file inclusion attempts', 'vigilante' ); ?>
3726 </label>
3727 </td>
3728 </tr>
3729 <tr>
3730 <th scope="row"><?php esc_html_e( 'Directory Traversal Protection', 'vigilante' ); ?></th>
3731 <td>
3732 <label>
3733 <input type="checkbox" name="firewall[block_directory_traversal]" value="1" <?php checked( ! empty( $options['block_directory_traversal'] ) ); ?>>
3734 <?php esc_html_e( 'Block path traversal attempts', 'vigilante' ); ?>
3735 </label>
3736 </td>
3737 </tr>
3738 <tr>
3739 <th scope="row"><?php esc_html_e( 'Block Bad Bots', 'vigilante' ); ?></th>
3740 <td>
3741 <label>
3742 <input type="checkbox" name="firewall[block_bad_bots]" value="1" <?php disabled( $vg_main_locked ); ?> <?php checked( ! empty( $options['block_bad_bots'] ) ); ?>>
3743 <?php esc_html_e( 'Block known malicious bots and scanners', 'vigilante' ); ?>
3744 </label>
3745 </td>
3746 </tr>
3747 </table>
3748
3749 <h3><?php esc_html_e( 'Rate Limiting', 'vigilante' ); ?></h3>
3750 <table class="form-table">
3751 <tr>
3752 <th scope="row"><?php esc_html_e( 'Enable Rate Limiting', 'vigilante' ); ?></th>
3753 <td>
3754 <label>
3755 <input type="checkbox" name="firewall[rate_limiting][enabled]" value="1" <?php checked( ! empty( $options['rate_limiting']['enabled'] ) ); ?>>
3756 <?php esc_html_e( 'Limit requests per IP address', 'vigilante' ); ?>
3757 </label>
3758 </td>
3759 </tr>
3760 <tr>
3761 <th scope="row"><label for="vigilante-f-firewall-rate-limiting-requests-per-minute"><?php esc_html_e( 'Requests per Minute', 'vigilante' ); ?></label></th>
3762 <td>
3763 <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">
3764 <p class="description">
3765 <?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' ); ?>
3766 </p>
3767 </td>
3768 </tr>
3769 <tr>
3770 <th scope="row"><label for="vigilante-f-firewall-rate-limiting-block-duration"><?php esc_html_e( 'Block Duration (seconds)', 'vigilante' ); ?></label></th>
3771 <td>
3772 <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">
3773 </td>
3774 </tr>
3775 <tr>
3776 <th scope="row"><?php esc_html_e( 'Progressive Blocking', 'vigilante' ); ?></th>
3777 <td>
3778 <label>
3779 <input type="checkbox" name="firewall[rate_limiting][progressive]" value="1" <?php checked( ! empty( $options['rate_limiting']['progressive'] ) ); ?>>
3780 <?php esc_html_e( 'Double block duration on each repeat offense', 'vigilante' ); ?>
3781 </label>
3782 <p class="description">
3783 <?php
3784 $base = absint( $options['rate_limiting']['block_duration'] ?? 300 );
3785 printf(
3786 /* translators: 1: First block duration, 2: Second, 3: Third */
3787 esc_html__( 'Example: %1$s → %2$s → %3$s and so on, up to the maximum.', 'vigilante' ),
3788 esc_html( human_time_diff( 0, $base ) ),
3789 esc_html( human_time_diff( 0, $base * 2 ) ),
3790 esc_html( human_time_diff( 0, $base * 4 ) )
3791 );
3792 ?>
3793 </p>
3794 </td>
3795 </tr>
3796 <tr>
3797 <th scope="row"><label for="vigilante-f-firewall-rate-limiting-max-block-duration"><?php esc_html_e( 'Maximum Block Duration', 'vigilante' ); ?></label></th>
3798 <td>
3799 <select id="vigilante-f-firewall-rate-limiting-max-block-duration" name="firewall[rate_limiting][max_block_duration]">
3800 <?php
3801 $max_options = array(
3802 3600 => __( '1 hour', 'vigilante' ),
3803 21600 => __( '6 hours', 'vigilante' ),
3804 43200 => __( '12 hours', 'vigilante' ),
3805 86400 => __( '24 hours', 'vigilante' ),
3806 604800 => __( '7 days', 'vigilante' ),
3807 );
3808 $current_max = absint( $options['rate_limiting']['max_block_duration'] ?? 86400 );
3809 foreach ( $max_options as $val => $label ) :
3810 ?>
3811 <option value="<?php echo esc_attr( $val ); ?>" <?php selected( $current_max, $val ); ?>>
3812 <?php echo esc_html( $label ); ?>
3813 </option>
3814 <?php endforeach; ?>
3815 </select>
3816 <p class="description"><?php esc_html_e( 'Upper limit for progressive blocking.', 'vigilante' ); ?></p>
3817 </td>
3818 </tr>
3819 </table>
3820
3821 <?php
3822 // Currently blocked IPs from rate limiting
3823 $active_blocks = Vigilante_Firewall::get_active_blocks();
3824 if ( ! empty( $active_blocks ) ) :
3825 ?>
3826 <div class="vigilante-settings-section vigilante-lockout-section" style="margin-top:20px;">
3827 <h3><?php esc_html_e( 'Currently Blocked IPs', 'vigilante' ); ?></h3>
3828 <table class="wp-list-table widefat fixed striped" style="max-width:800px;">
3829 <thead>
3830 <tr>
3831 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
3832 <th><?php esc_html_e( 'Blocked', 'vigilante' ); ?></th>
3833 <th><?php esc_html_e( 'Expires in', 'vigilante' ); ?></th>
3834 <th><?php esc_html_e( 'Strikes', 'vigilante' ); ?></th>
3835 <th><?php esc_html_e( 'Action', 'vigilante' ); ?></th>
3836 </tr>
3837 </thead>
3838 <tbody>
3839 <?php foreach ( $active_blocks as $blocked_ip => $block_data ) : ?>
3840 <tr>
3841 <td><code><?php echo esc_html( $blocked_ip ); ?></code></td>
3842 <td><?php echo esc_html( human_time_diff( $block_data['blocked_at'] ) . ' ' . __( 'ago', 'vigilante' ) ); ?></td>
3843 <td><?php echo esc_html( human_time_diff( time(), $block_data['expires'] ) ); ?></td>
3844 <td><?php echo esc_html( $block_data['strikes'] ?? 1 ); ?></td>
3845 <td>
3846 <button type="button" class="button button-small vigilante-unblock-firewall-ip"
3847 data-ip="<?php echo esc_attr( $blocked_ip ); ?>">
3848 <?php esc_html_e( 'Unblock', 'vigilante' ); ?>
3849 </button>
3850 </td>
3851 </tr>
3852 <?php endforeach; ?>
3853 </tbody>
3854 </table>
3855 </div>
3856 <?php endif; ?>
3857
3858 <?php
3859 // Since 2.11.8 X-Forwarded-For is read from its end, where the proxy
3860 // writes. The administrator's own request shows whether that end is
3861 // a CDN or a balancer for everybody here. Cross review of 2.11.8.
3862 $xff_readings = $this->forwarded_chain_readings();
3863 if ( $xff_readings ) :
3864 ?>
3865 <div id="vigilante-xff-chain-notice" class="notice notice-warning inline" style="margin:10px 0 16px;padding:8px 12px;">
3866 <p style="margin:0;">
3867 <?php
3868 printf(
3869 /* translators: 1: last address in the header, the one Vigilant reads, 2: first address in the header, which a visitor can write */
3870 esc_html__( 'Your own request reaches the site with more than one public address in X-Forwarded-For. Vigilant reads the last one, %1$s, which is the one your proxy added, and not the first one, %2$s, which a visitor can write. If %1$s belongs to a CDN or a load balancer rather than to you, every visitor shares it for rate limiting, login lockouts and the IP lists: choose the header of that CDN in Visitor IP detection, such as CF-Connecting-IP for Cloudflare.', 'vigilante' ),
3871 esc_html( $xff_readings['now'] ),
3872 esc_html( $xff_readings['before'] )
3873 );
3874 ?>
3875 </p>
3876 </div>
3877 <?php endif; ?>
3878
3879 <h3><?php esc_html_e( 'IP Lists', 'vigilante' ); ?></h3>
3880 <p class="description">
3881 <?php
3882 printf(
3883 /* translators: %s: Current visitor IP address */
3884 esc_html__( 'Your current IP address: %s', 'vigilante' ),
3885 '<code>' . esc_html( $this->database->get_client_ip() ) . '</code>'
3886 );
3887 ?>
3888 </p>
3889 <table class="form-table">
3890 <tr>
3891 <th scope="row"><label for="vigilante-f-firewall-trusted-proxy-header"><?php esc_html_e( 'Visitor IP detection', 'vigilante' ); ?></label></th>
3892 <td>
3893 <?php $proxy_header = $options['trusted_proxy_header'] ?? ''; ?>
3894 <select id="vigilante-f-firewall-trusted-proxy-header" name="firewall[trusted_proxy_header]" <?php disabled( $vg_main_locked ); ?>>
3895 <option value="" <?php selected( $proxy_header, '' ); ?>><?php esc_html_e( 'Direct connection, only REMOTE_ADDR (recommended)', 'vigilante' ); ?></option>
3896 <option value="cf-connecting-ip" <?php selected( $proxy_header, 'cf-connecting-ip' ); ?>><?php esc_html_e( 'Behind Cloudflare (CF-Connecting-IP)', 'vigilante' ); ?></option>
3897 <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>
3898 <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>
3899 </select>
3900 <p class="description">
3901 <?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' ); ?>
3902 </p>
3903 </td>
3904 </tr>
3905 <tr>
3906 <th scope="row"><label for="vigilante-f-firewall-trusted-proxies"><?php esc_html_e( 'Trusted proxy IPs', 'vigilante' ); ?></label></th>
3907 <td>
3908 <textarea id="vigilante-f-firewall-trusted-proxies" name="firewall[trusted_proxies]" rows="3" class="large-text code" placeholder="10.0.0.0/8&#10;192.168.1.1" <?php disabled( $vg_main_locked ); ?>><?php echo esc_textarea( implode( "\n", $options['trusted_proxies'] ?? array() ) ); ?></textarea>
3909 <p class="description">
3910 <?php esc_html_e( 'Only used with a forwarded header selected above. One IP or CIDR range per line: the addresses your proxy or load balancer connects from. The forwarded header is accepted only from these. Left empty, Vigilant accepts it from your own private network, and for Cloudflare from Cloudflare\'s own ranges automatically.', 'vigilante' ); ?>
3911 <?php if ( in_array( $proxy_header, array( 'x-forwarded-for', 'x-real-ip' ), true ) && empty( $options['trusted_proxies'] ) ) : ?>
3912 <br><strong><?php esc_html_e( 'The header above is trusted but no proxy IPs are set. If your proxy or load balancer connects from a public address, add it here, or the header is ignored for safety and every visitor is seen as that proxy.', 'vigilante' ); ?></strong>
3913 <?php endif; ?>
3914 </p>
3915 </td>
3916 </tr>
3917 <tr>
3918 <th scope="row"><label for="vigilante-f-firewall-ip-whitelist"><?php esc_html_e( 'IP Whitelist', 'vigilante' ); ?></label></th>
3919 <td>
3920 <textarea id="vigilante-f-firewall-ip-whitelist" name="firewall[ip_whitelist]" <?php disabled( $vg_main_locked ); ?> rows="4" class="large-text code" placeholder="192.168.1.50&#10;192.168.1.0/24&#10;192.168.1.*"><?php echo esc_textarea( implode( "\n", $options['ip_whitelist'] ?? array() ) ); ?></textarea>
3921 <p class="description">
3922 <?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' ); ?>
3923 <br>
3924 <?php
3925 printf(
3926 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the IP, CIDR and wildcard examples. */
3927 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' ),
3928 '<code>',
3929 '</code>'
3930 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
3931 ?>
3932 </p>
3933 </td>
3934 </tr>
3935 <tr>
3936 <th scope="row"><label for="vigilante-f-firewall-ip-blacklist"><?php esc_html_e( 'IP Blacklist', 'vigilante' ); ?></label></th>
3937 <td>
3938 <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>
3939 <p class="description">
3940 <?php esc_html_e( 'One IP per line. These IPs will be blocked immediately.', 'vigilante' ); ?>
3941 <br>
3942 <?php
3943 printf(
3944 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the IP, CIDR and wildcard examples. */
3945 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' ),
3946 '<code>',
3947 '</code>'
3948 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
3949 ?>
3950 </p>
3951 </td>
3952 </tr>
3953 </table>
3954
3955 <h3><?php esc_html_e( 'User-Agent Lists', 'vigilante' ); ?></h3>
3956 <p><?php esc_html_e( 'Partial matching: enter a keyword and any User-Agent containing it will be matched.', 'vigilante' ); ?></p>
3957 <table class="form-table">
3958 <tr>
3959 <th scope="row"><label for="vigilante-f-firewall-ua-whitelist"><?php esc_html_e( 'User-Agent Whitelist', 'vigilante' ); ?></label></th>
3960 <td>
3961 <textarea id="vigilante-f-firewall-ua-whitelist" name="firewall[ua_whitelist]" <?php disabled( $vg_main_locked ); ?> rows="4" class="large-text code"><?php echo esc_textarea( implode( "\n", $options['ua_whitelist'] ?? array() ) ); ?></textarea>
3962 <p class="description"><?php esc_html_e( 'One User-Agent per line. These will bypass all firewall checks. Example: ManageWP, MainWP, UptimeRobot.', 'vigilante' ); ?></p>
3963 </td>
3964 </tr>
3965 <tr>
3966 <th scope="row"><label for="vigilante-f-firewall-ua-blacklist"><?php esc_html_e( 'User-Agent Blacklist', 'vigilante' ); ?></label></th>
3967 <td>
3968 <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>
3969 <p class="description"><?php esc_html_e( 'One User-Agent per line. These will be blocked immediately.', 'vigilante' ); ?></p>
3970 </td>
3971 </tr>
3972 </table>
3973 </div>
3974
3975 <?php
3976 $vg_shared_locked = $this->shared_files_locked();
3977 // Paint what is actually in force, not this site's unused copy.
3978 $vg_local_options = $options;
3979 $options = $this->get_section_for_display( 'firewall' );
3980 ?>
3981 <?php $this->render_shared_files_notice(); ?>
3982 <div id="vigilante-section-firewall-server" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
3983 <h2>
3984 <?php esc_html_e( 'Server Protection', 'vigilante' ); ?>
3985 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
3986 </h2>
3987 <p><?php esc_html_e( 'Server-level rules for Apache/LiteSpeed. These rules are processed before PHP.', 'vigilante' ); ?></p>
3988
3989 <table class="form-table">
3990 <tr id="field-disable-directory-browsing">
3991 <th scope="row"><?php esc_html_e( 'Directory Browsing', 'vigilante' ); ?></th>
3992 <td>
3993 <label>
3994 <input type="checkbox" name="firewall[disable_directory_browsing]" value="1" <?php checked( ! empty( $options['disable_directory_browsing'] ) ); ?>>
3995 <?php esc_html_e( 'Disable directory listing (Options -Indexes)', 'vigilante' ); ?>
3996 </label>
3997 </td>
3998 </tr>
3999 <tr>
4000 <th scope="row"><?php esc_html_e( 'Protect wp-config.php', 'vigilante' ); ?></th>
4001 <td>
4002 <label>
4003 <input type="checkbox" name="firewall[protect_wp_config]" value="1" <?php checked( ! empty( $options['protect_wp_config'] ) ); ?>>
4004 <?php esc_html_e( 'Block direct HTTP access to wp-config.php', 'vigilante' ); ?>
4005 </label>
4006 </td>
4007 </tr>
4008 <tr id="field-protect-wp-cron">
4009 <th scope="row"><?php esc_html_e( 'Protect wp-cron.php', 'vigilante' ); ?></th>
4010 <td>
4011 <label>
4012 <input type="checkbox" name="firewall[protect_wp_cron]" value="1" <?php checked( ! empty( $options['protect_wp_cron'] ) ); ?>>
4013 <?php esc_html_e( 'Block direct HTTP access to wp-cron.php (prevents cron-spam DoS abuse)', 'vigilante' ); ?>
4014 </label>
4015 <p class="description"><?php
4016 printf(
4017 /* translators: 1: opening <strong>, 2: closing </strong> */
4018 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' ),
4019 '<strong>',
4020 '</strong>',
4021 '<code>',
4022 '</code>'
4023 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
4024 ?></p>
4025 </td>
4026 </tr>
4027 <tr>
4028 <th scope="row"><?php esc_html_e( 'Protect wp-includes', 'vigilante' ); ?></th>
4029 <td>
4030 <label>
4031 <input type="checkbox" name="firewall[protect_wp_includes]" value="1" <?php checked( ! empty( $options['protect_wp_includes'] ) ); ?>>
4032 <?php esc_html_e( 'Block direct access to PHP files in wp-includes', 'vigilante' ); ?>
4033 </label>
4034 </td>
4035 </tr>
4036 <tr>
4037 <th scope="row"><?php esc_html_e( 'PHP in Uploads', 'vigilante' ); ?></th>
4038 <td>
4039 <label>
4040 <input type="checkbox" name="firewall[protect_uploads_php]" value="1" <?php checked( ! empty( $options['protect_uploads_php'] ) ); ?>>
4041 <?php esc_html_e( 'Block PHP execution in wp-content/uploads', 'vigilante' ); ?>
4042 </label>
4043 </td>
4044 </tr>
4045 <tr>
4046 <th scope="row"><?php esc_html_e( 'Sensitive Files', 'vigilante' ); ?></th>
4047 <td>
4048 <label>
4049 <input type="checkbox" name="firewall[protect_sensitive_files]" value="1" <?php checked( ! empty( $options['protect_sensitive_files'] ) ); ?>>
4050 <?php esc_html_e( 'Block access to .sql, .bak, .log, .ini, readme.html, license.txt, licencia.txt', 'vigilante' ); ?>
4051 </label>
4052 </td>
4053 </tr>
4054 <tr>
4055 <th scope="row"><?php esc_html_e( 'Limit HTTP Methods', 'vigilante' ); ?></th>
4056 <td>
4057 <label>
4058 <input type="checkbox" name="firewall[limit_http_methods]" value="1" <?php checked( ! empty( $options['limit_http_methods'] ) ); ?>>
4059 <?php esc_html_e( 'Allow only GET, POST, HEAD (blocks PUT, DELETE, TRACE, etc.)', 'vigilante' ); ?>
4060 </label>
4061 </td>
4062 </tr>
4063 </table>
4064 </div>
4065 <?php $options = $vg_local_options; ?>
4066
4067 <p class="submit vigilante-submit-buttons">
4068 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4069 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4070 </button>
4071 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4072 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4073 </button>
4074 </p>
4075 </form>
4076 <?php
4077 }
4078
4079 /**
4080 * Render login security tab
4081 */
4082 private function render_tab_login() {
4083 $is_disabled = $this->render_module_disabled_notice( 'login_security' );
4084 $options = $this->settings->get_section( 'login_security' );
4085 $lockouts = $this->database->get_active_lockouts();
4086 ?>
4087 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="login_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
4088 <div id="vigilante-section-login-main" class="vigilante-settings-section">
4089 <h2>
4090 <?php esc_html_e( 'Login Protection', 'vigilante' ); ?>
4091 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4092 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
4093 </h2>
4094 <p><?php esc_html_e( 'Brute force protection and WordPress login hardening.', 'vigilante' ); ?></p>
4095
4096 <table class="form-table">
4097 <tr id="field-max-attempts">
4098 <th scope="row"><label for="vigilante-f-login-security-max-attempts"><?php esc_html_e( 'Max Login Attempts', 'vigilante' ); ?></label></th>
4099 <td>
4100 <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">
4101 <p class="description"><?php esc_html_e( 'Number of failed attempts before lockout.', 'vigilante' ); ?></p>
4102 </td>
4103 </tr>
4104 <tr>
4105 <th scope="row"><label for="vigilante-f-login-security-lockout-duration"><?php esc_html_e( 'Lockout Duration', 'vigilante' ); ?></label></th>
4106 <td>
4107 <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">
4108 <?php esc_html_e( 'minutes', 'vigilante' ); ?>
4109 </td>
4110 </tr>
4111 <tr>
4112 <th scope="row"><?php esc_html_e( 'Progressive Lockout', 'vigilante' ); ?></th>
4113 <td>
4114 <label>
4115 <input type="checkbox" name="login_security[lockout_increment]" value="1" <?php checked( ! empty( $options['lockout_increment'] ) ); ?>>
4116 <?php esc_html_e( 'Double lockout duration for repeat offenders', 'vigilante' ); ?>
4117 </label>
4118 </td>
4119 </tr>
4120 <tr>
4121 <th scope="row"><?php esc_html_e( 'Hide Login Errors', 'vigilante' ); ?></th>
4122 <td>
4123 <label>
4124 <input type="checkbox" name="login_security[hide_login_errors]" value="1" <?php checked( ! empty( $options['hide_login_errors'] ) ); ?>>
4125 <?php esc_html_e( 'Show generic error message instead of specific errors', 'vigilante' ); ?>
4126 </label>
4127 </td>
4128 </tr>
4129 <tr>
4130 <th scope="row"><?php esc_html_e( 'Disable Application Passwords', 'vigilante' ); ?></th>
4131 <td>
4132 <label>
4133 <input type="checkbox" name="login_security[disable_application_passwords]" value="1" <?php checked( ! empty( $options['disable_application_passwords'] ) ); ?>>
4134 <?php esc_html_e( 'Disable WordPress application passwords feature', 'vigilante' ); ?>
4135 </label>
4136 </td>
4137 </tr>
4138 </table>
4139
4140 <h3><?php esc_html_e( 'Custom Login URL', 'vigilante' ); ?></h3>
4141 <table class="form-table">
4142 <tr id="field-custom-login-url">
4143 <th scope="row"><?php esc_html_e( 'Login URL Slug', 'vigilante' ); ?></th>
4144 <td>
4145 <code><?php echo esc_url( home_url( '/' ) ); ?></code>
4146 <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' ); ?>">
4147 <p class="description">
4148 <?php esc_html_e( '&#9432; Leave empty to use default wp-login.php. Use only lowercase letters, numbers and hyphens.', 'vigilante' ); ?>
4149 </p>
4150 <div class="vigilante-login-url-preview" <?php echo empty( $options['custom_login_url'] ) ? 'style="display:none;"' : ''; ?>>
4151 <p class="description">
4152 <strong><?php esc_html_e( 'Your login URL:', 'vigilante' ); ?></strong>
4153 <code class="vigilante-login-url-display"><?php echo esc_url( home_url( sanitize_title( $options['custom_login_url'] ?? '' ) . '/' ) ); ?></code>
4154 </p>
4155 <p class="description">
4156 <?php esc_html_e( 'Direct access to wp-login.php and wp-admin will return a 404 error for non-logged users.', 'vigilante' ); ?>
4157 </p>
4158 <p class="description">
4159 <?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' ); ?>
4160 </p>
4161 </div>
4162 </td>
4163 </tr>
4164 </table>
4165
4166 <div class="vigilante-login-url-notify-wrapper <?php echo empty( $options['custom_login_url'] ) ? 'vigilante-login-url-notify-disabled' : ''; ?>">
4167 <table class="form-table">
4168 <tr>
4169 <th scope="row"><?php esc_html_e( 'Notify users', 'vigilante' ); ?></th>
4170 <td>
4171 <label>
4172 <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 ); ?>>
4173 <?php esc_html_e( 'Notify affected users when the login URL changes', 'vigilante' ); ?>
4174 </label>
4175 <div class="vigilante-login-url-send-notification" style="margin-top:12px;">
4176 <button type="button" id="vigilante_notify_login_url" class="button">
4177 <?php esc_html_e( 'Send notification now', 'vigilante' ); ?>
4178 </button>
4179 <span class="vigilante-login-url-notify-status"></span>
4180 <p class="description"><?php esc_html_e( 'Sends the new URL to administrators, editors, authors, and contributors.', 'vigilante' ); ?></p>
4181 </div>
4182 </td>
4183 </tr>
4184 </table>
4185 </div>
4186
4187 <?php $this->render_2fa_settings( $options ); ?>
4188
4189 <h3><?php esc_html_e( 'Notifications', 'vigilante' ); ?></h3>
4190 <table class="form-table">
4191 <tr>
4192 <th scope="row"><?php esc_html_e( 'Notify on Lockout', 'vigilante' ); ?></th>
4193 <td>
4194 <label>
4195 <input type="checkbox" name="login_security[notify_on_lockout]" value="1" <?php checked( ! empty( $options['notify_on_lockout'] ) ); ?>>
4196 <?php esc_html_e( 'Send email when an IP is locked out', 'vigilante' ); ?>
4197 </label>
4198 </td>
4199 </tr>
4200 <tr>
4201 <th scope="row"><?php esc_html_e( 'Notify on Admin Login', 'vigilante' ); ?></th>
4202 <td>
4203 <label>
4204 <input type="checkbox" name="login_security[notify_on_admin_login]" value="1" <?php checked( ! empty( $options['notify_on_admin_login'] ) ); ?>>
4205 <?php esc_html_e( 'Send email when an administrator logs in', 'vigilante' ); ?>
4206 </label>
4207 </td>
4208 </tr>
4209 </table>
4210
4211 <p class="description">
4212 <?php
4213 printf(
4214 /* translators: %s: Link to notification settings */
4215 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
4216 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
4217 );
4218 ?>
4219 </p>
4220 </div>
4221
4222 <p class="submit vigilante-submit-buttons">
4223 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4224 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4225 </button>
4226 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4227 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4228 </button>
4229 </p>
4230 </form>
4231
4232 <?php $this->render_lockout_info_section( $options, $lockouts ); ?>
4233 <?php
4234 }
4235
4236 /**
4237 * Render lockout information and blocked IPs section
4238 *
4239 * @param array $options Login security options.
4240 * @param array $lockouts Currently locked out IPs.
4241 */
4242 private function render_lockout_info_section( $options, $lockouts ) {
4243 $max_attempts = absint( $options['max_attempts'] ?? 5 );
4244 $lockout_duration = absint( $options['lockout_duration'] ?? 1800 );
4245 $lockout_increment = ! empty( $options['lockout_increment'] );
4246 $max_lockout = absint( $options['max_lockout_duration'] ?? 86400 );
4247 $two_factor = $options['two_factor'] ?? array();
4248 $two_factor_enabled = ! empty( $two_factor['enabled'] );
4249 ?>
4250 <div class="vigilante-settings-section vigilante-lockout-section">
4251 <h2 id="vigilante-section-login-status"><?php esc_html_e( 'Login Protection Status', 'vigilante' ); ?></h2>
4252
4253 <table class="form-table">
4254 <tr>
4255 <th scope="row"><?php esc_html_e( 'Current settings', 'vigilante' ); ?></th>
4256 <td>
4257 <?php
4258 printf(
4259 /* translators: 1: Maximum login attempts, 2: Lockout duration in minutes */
4260 esc_html__( 'After %1$d failed login attempts, the IP address is blocked for %2$d minutes.', 'vigilante' ),
4261 absint( $max_attempts ),
4262 absint( ceil( $lockout_duration / 60 ) )
4263 );
4264
4265 if ( $lockout_increment ) {
4266 echo '<br>';
4267 printf(
4268 /* translators: %d: Maximum lockout duration in hours */
4269 esc_html__( 'Progressive lockout enabled (max: %d hours).', 'vigilante' ),
4270 absint( ceil( $max_lockout / 3600 ) )
4271 );
4272 }
4273
4274 if ( $two_factor_enabled ) {
4275 echo '<br>';
4276 esc_html_e( 'Failed 2FA codes also count toward the lockout limit.', 'vigilante' );
4277 }
4278 ?>
4279 </td>
4280 </tr>
4281 <tr>
4282 <th scope="row"><?php esc_html_e( 'Blocked IPs', 'vigilante' ); ?></th>
4283 <td>
4284 <?php if ( ! empty( $lockouts ) ) : ?>
4285 <div class="vigilante-paginated-section">
4286 <div class="vigilante-fi-pagination-wrap"></div>
4287 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
4288 <thead>
4289 <tr>
4290 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
4291 <th><?php esc_html_e( 'Attempts', 'vigilante' ); ?></th>
4292 <th><?php esc_html_e( 'Blocked Until', 'vigilante' ); ?></th>
4293 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
4294 </tr>
4295 </thead>
4296 <tbody>
4297 <?php foreach ( $lockouts as $lockout ) :
4298 $lockout_time = strtotime( $lockout->locked_until );
4299 $remaining_seconds = $lockout_time - time();
4300 $remaining_text = $this->format_remaining_time( $remaining_seconds );
4301 ?>
4302 <tr>
4303 <td><code><?php echo esc_html( $lockout->ip_address ); ?></code></td>
4304 <td><?php echo esc_html( $lockout->attempts ); ?></td>
4305 <td>
4306 <?php echo esc_html( wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $lockout_time ) ); ?>
4307 <br>
4308 <small class="description">
4309 <?php
4310 printf(
4311 /* translators: %s: Remaining time */
4312 esc_html__( '%s remaining', 'vigilante' ),
4313 esc_html( $remaining_text )
4314 );
4315 ?>
4316 </small>
4317 </td>
4318 <td>
4319 <button type="button" class="button button-small vigilante-clear-lockout" data-ip="<?php echo esc_attr( $lockout->ip_address ); ?>">
4320 <?php esc_html_e( 'Unblock', 'vigilante' ); ?>
4321 </button>
4322 </td>
4323 </tr>
4324 <?php endforeach; ?>
4325 </tbody>
4326 </table>
4327 </div>
4328 <p class="description" style="margin-top: 10px;">
4329 <button type="button" class="button vigilante-clear-all-lockouts">
4330 <?php esc_html_e( 'Unblock All IPs', 'vigilante' ); ?>
4331 </button>
4332 <span style="margin-left: 10px;">
4333 <?php
4334 printf(
4335 /* translators: %d: Number of blocked IPs */
4336 esc_html( _n( '%d IP currently blocked', '%d IPs currently blocked', count( $lockouts ), 'vigilante' ) ),
4337 count( $lockouts )
4338 );
4339 ?>
4340 </span>
4341 </p>
4342 <?php else : ?>
4343 <span class="dashicons dashicons-yes-alt" style="color: #00a32a; font-size: 20px; width: 20px; height: 20px; vertical-align: middle;"></span>
4344 <span style="vertical-align: middle; margin-left: 5px;"><?php esc_html_e( 'No IPs are currently blocked. All clear!', 'vigilante' ); ?></span>
4345 <?php endif; ?>
4346 </td>
4347 </tr>
4348 </table>
4349 </div>
4350 <?php
4351 }
4352
4353 /**
4354 * Format remaining lockout time in human readable format
4355 *
4356 * @param int $seconds Remaining seconds.
4357 * @return string Formatted time string.
4358 */
4359 private function format_remaining_time( $seconds ) {
4360 if ( $seconds <= 0 ) {
4361 return __( 'expired', 'vigilante' );
4362 }
4363
4364 if ( $seconds < 60 ) {
4365 return sprintf(
4366 /* translators: %d: Number of seconds */
4367 _n( '%d second', '%d seconds', $seconds, 'vigilante' ),
4368 $seconds
4369 );
4370 }
4371
4372 if ( $seconds < 3600 ) {
4373 $minutes = ceil( $seconds / 60 );
4374 return sprintf(
4375 /* translators: %d: Number of minutes */
4376 _n( '%d minute', '%d minutes', $minutes, 'vigilante' ),
4377 $minutes
4378 );
4379 }
4380
4381 $hours = floor( $seconds / 3600 );
4382 $remaining_minutes = ceil( ( $seconds % 3600 ) / 60 );
4383
4384 if ( $remaining_minutes > 0 ) {
4385 return sprintf(
4386 /* translators: 1: Number of hours, 2: Number of minutes */
4387 __( '%1$d hours %2$d minutes', 'vigilante' ),
4388 $hours,
4389 $remaining_minutes
4390 );
4391 }
4392
4393 return sprintf(
4394 /* translators: %d: Number of hours */
4395 _n( '%d hour', '%d hours', $hours, 'vigilante' ),
4396 $hours
4397 );
4398 }
4399
4400 /**
4401 * Render 2FA settings section
4402 *
4403 * @param array $options Login security options.
4404 */
4405 private function render_2fa_settings( $options ) {
4406 $two_factor = $options['two_factor'] ?? array();
4407 $all_roles = wp_roles()->roles;
4408 $enforced = $two_factor['enforced_roles'] ?? array( 'administrator', 'editor' );
4409 $excluded = $two_factor['excluded_users'] ?? array();
4410 $method = $two_factor['method'] ?? 'email';
4411 $grace_days = $two_factor['grace_period_days'] ?? 3;
4412 ?>
4413 <h3 id="vigilante-section-login-2fa">
4414 <?php esc_html_e( 'Two-Factor Authentication (2FA)', 'vigilante' ); ?>
4415 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4416 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
4417 </h3>
4418 <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>
4419
4420 <table class="form-table">
4421 <tr>
4422 <th scope="row"><?php esc_html_e( 'Enable 2FA', 'vigilante' ); ?></th>
4423 <td>
4424 <label>
4425 <input type="checkbox" name="login_security[two_factor][enabled]" id="vigilante_2fa_enabled" value="1" <?php checked( ! empty( $two_factor['enabled'] ) ); ?>>
4426 <?php esc_html_e( 'Enable two-factor authentication', 'vigilante' ); ?>
4427 </label>
4428 </td>
4429 </tr>
4430 </table>
4431
4432 <div class="vigilante-2fa-settings-wrapper <?php echo empty( $two_factor['enabled'] ) ? 'vigilante-2fa-settings-disabled' : ''; ?>">
4433 <table class="form-table">
4434 <tr>
4435 <th scope="row"><?php esc_html_e( 'Verification method', 'vigilante' ); ?></th>
4436 <td>
4437 <fieldset class="vigilante-2fa-method-selector">
4438 <label class="vigilante-2fa-method-option <?php echo 'email' === $method ? 'selected' : ''; ?>">
4439 <input type="radio" name="login_security[two_factor][method]" value="email" <?php checked( $method, 'email' ); ?>>
4440 <span class="dashicons dashicons-email"></span>
4441 <span class="method-info">
4442 <strong><?php esc_html_e( 'Email code', 'vigilante' ); ?></strong>
4443 <span><?php esc_html_e( 'Users receive a 6-digit code via email after entering their password.', 'vigilante' ); ?></span>
4444 </span>
4445 </label>
4446 <label class="vigilante-2fa-method-option <?php echo 'totp' === $method ? 'selected' : ''; ?>">
4447 <input type="radio" name="login_security[two_factor][method]" value="totp" <?php checked( $method, 'totp' ); ?>>
4448 <span class="dashicons dashicons-smartphone"></span>
4449 <span class="method-info">
4450 <strong><?php esc_html_e( 'Authenticator app (TOTP)', 'vigilante' ); ?></strong>
4451 <span><?php esc_html_e( 'Users verify with a time-based code from Google Authenticator, Authy, etc.', 'vigilante' ); ?></span>
4452 </span>
4453 </label>
4454 </fieldset>
4455 </td>
4456 </tr>
4457 <tr>
4458 <th scope="row"><?php esc_html_e( 'Enforce for roles', 'vigilante' ); ?></th>
4459 <td>
4460 <div class="vigilante-2fa-roles">
4461 <?php $this->list_sentinel( 'login_security[two_factor][enforced_roles]' ); ?>
4462 <?php foreach ( $all_roles as $role_slug => $role_data ) :
4463 $user_count = count( get_users( array( 'role' => $role_slug, 'fields' => 'ID' ) ) );
4464 ?>
4465 <label>
4466 <input type="checkbox"
4467 name="login_security[two_factor][enforced_roles][]"
4468 value="<?php echo esc_attr( $role_slug ); ?>"
4469 <?php checked( in_array( $role_slug, $enforced, true ) ); ?>>
4470 <span class="role-name"><?php echo esc_html( translate_user_role( $role_data['name'] ) ); ?></span>
4471 <span class="role-count">(<?php echo esc_html( $user_count ); ?>)</span>
4472 </label>
4473 <?php endforeach; ?>
4474 </div>
4475 <p class="description"><?php esc_html_e( 'Users with these roles will be required to verify with the selected method.', 'vigilante' ); ?></p>
4476 </td>
4477 </tr>
4478 <tr>
4479 <th scope="row"><?php esc_html_e( 'Exclude specific users', 'vigilante' ); ?></th>
4480 <td>
4481 <div class="vigilante-2fa-user-search-container">
4482 <div class="vigilante-2fa-user-search">
4483 <span class="search-icon"></span>
4484 <input type="text"
4485 id="vigilante_2fa_user_search"
4486 placeholder="<?php esc_attr_e( 'Search users by name or email...', 'vigilante' ); ?>"
4487 autocomplete="off">
4488 <div class="vigilante-2fa-search-results"></div>
4489 </div>
4490 <div class="vigilante-2fa-excluded-users">
4491 <?php $this->list_sentinel( 'login_security[two_factor][excluded_users]' ); ?>
4492 <?php
4493 foreach ( $excluded as $user_id ) :
4494 $user = get_user_by( 'ID', $user_id );
4495 if ( ! $user ) continue;
4496 ?>
4497 <div class="vigilante-2fa-excluded-user" data-user-id="<?php echo esc_attr( $user_id ); ?>">
4498 <span class="user-display"><?php echo esc_html( $user->display_name . ' (' . $user->user_email . ')' ); ?></span>
4499 <button type="button" class="remove-user" aria-label="<?php esc_attr_e( 'Remove', 'vigilante' ); ?>">&times;</button>
4500 <input type="hidden" name="login_security[two_factor][excluded_users][]" value="<?php echo esc_attr( $user_id ); ?>">
4501 </div>
4502 <?php endforeach; ?>
4503 </div>
4504 </div>
4505 <p class="description"><?php esc_html_e( 'These users will not be required to use 2FA regardless of their role.', 'vigilante' ); ?></p>
4506 </td>
4507 </tr>
4508
4509 <!-- Remember device option -->
4510 <tr>
4511 <th scope="row"><?php esc_html_e( 'Remember device', 'vigilante' ); ?></th>
4512 <td>
4513 <label>
4514 <input type="checkbox" name="login_security[two_factor][allow_remember_device]" value="1" <?php checked( ! empty( $two_factor['allow_remember_device'] ) ); ?>>
4515 <?php esc_html_e( 'Allow users to skip 2FA verification on trusted devices', 'vigilante' ); ?>
4516 </label>
4517 <p class="description">
4518 <?php
4519 printf(
4520 /* translators: %d: Number of days */
4521 esc_html__( 'When enabled, users can check "Remember this device" on the verification screen to skip 2FA for %d days.', 'vigilante' ),
4522 absint( $two_factor['remember_device_days'] ?? 30 )
4523 );
4524 ?>
4525 </p>
4526 </td>
4527 </tr>
4528
4529 <!-- TOTP-specific: Grace period -->
4530 <tr class="vigilante-2fa-totp-only" <?php echo 'totp' !== $method ? 'style="display:none;"' : ''; ?>>
4531 <th scope="row"><label for="vigilante-f-login-security-two-factor-grace-period-days"><?php esc_html_e( 'Grace period', 'vigilante' ); ?></label></th>
4532 <td>
4533 <input id="vigilante-f-login-security-two-factor-grace-period-days" type="number"
4534 name="login_security[two_factor][grace_period_days]"
4535 value="<?php echo esc_attr( $grace_days ); ?>"
4536 min="0" max="30" class="small-text">
4537 <?php esc_html_e( 'days', 'vigilante' ); ?>
4538 <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>
4539 </td>
4540 </tr>
4541
4542 <!-- Email-specific: Sender name -->
4543 <tr class="vigilante-2fa-email-only" <?php echo 'email' !== $method ? 'style="display:none;"' : ''; ?>>
4544 <th scope="row"><label for="vigilante-f-login-security-two-factor-email-from-name"><?php esc_html_e( 'Email sender name', 'vigilante' ); ?></label></th>
4545 <td>
4546 <input id="vigilante-f-login-security-two-factor-email-from-name" type="text"
4547 name="login_security[two_factor][email_from_name]"
4548 value="<?php echo esc_attr( $two_factor['email_from_name'] ?? '' ); ?>"
4549 class="regular-text vigilante-2fa-email-from"
4550 placeholder="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>">
4551 <p class="description"><?php esc_html_e( 'Name shown in verification emails. Leave empty to use site name.', 'vigilante' ); ?></p>
4552 </td>
4553 </tr>
4554
4555 <!-- TOTP-specific: Reset users -->
4556 <tr class="vigilante-2fa-totp-only" <?php echo 'totp' !== $method ? 'style="display:none;"' : ''; ?>>
4557 <th scope="row"><?php esc_html_e( 'Reset user TOTP', 'vigilante' ); ?></th>
4558 <td>
4559 <div class="vigilante-totp-reset-container">
4560 <div class="vigilante-2fa-user-search">
4561 <span class="search-icon"></span>
4562 <input type="text"
4563 id="vigilante_totp_reset_search"
4564 placeholder="<?php esc_attr_e( 'Search users with TOTP configured...', 'vigilante' ); ?>"
4565 autocomplete="off">
4566 <div class="vigilante-totp-reset-results"></div>
4567 </div>
4568 <div class="vigilante-totp-reset-selected"></div>
4569 <button type="button" id="vigilante_totp_reset_btn" class="button" style="display:none;">
4570 <?php esc_html_e( 'Reset selected', 'vigilante' ); ?>
4571 </button>
4572 <span class="vigilante-totp-reset-status"></span>
4573 </div>
4574 <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>
4575 </td>
4576 </tr>
4577 </table>
4578
4579 <h3><?php esc_html_e( 'User notification', 'vigilante' ); ?></h3>
4580 <table class="form-table">
4581 <tr>
4582 <th scope="row"><?php esc_html_e( 'Notify on enable', 'vigilante' ); ?></th>
4583 <td>
4584 <label>
4585 <input type="checkbox" name="login_security[two_factor][notify_on_enable]" value="1" <?php checked( $two_factor['notify_on_enable'] ?? true ); ?>>
4586 <?php esc_html_e( 'Send notification email to affected users when 2FA is enabled', 'vigilante' ); ?>
4587 </label>
4588
4589 <div class="vigilante-2fa-notification-options">
4590 <label>
4591 <input type="radio" name="vigilante_2fa_notify_mode" value="all" checked>
4592 <?php esc_html_e( 'Send to all affected users', 'vigilante' ); ?>
4593 </label>
4594 <label>
4595 <input type="radio" name="vigilante_2fa_notify_mode" value="new">
4596 <?php esc_html_e( 'Send only to users not previously notified', 'vigilante' ); ?>
4597 </label>
4598 </div>
4599
4600 <div class="vigilante-2fa-send-notification">
4601 <button type="button" id="vigilante_2fa_send_notification" class="button">
4602 <?php esc_html_e( 'Send notification now', 'vigilante' ); ?>
4603 </button>
4604 <span class="vigilante-2fa-notification-status"></span>
4605 </div>
4606 </td>
4607 </tr>
4608 </table>
4609 </div>
4610 <?php
4611 }
4612
4613 /**
4614 * Render security headers tab
4615 */
4616 /**
4617 * Offer back the header settings the 2.9.8 migration wiped.
4618 *
4619 * Rendered outside the settings form on purpose, so its buttons can never
4620 * submit it, and only when there is something to actually change. Shows the
4621 * difference before anything is written: nothing is applied that the owner
4622 * has not seen first.
4623 *
4624 * @since 2.10.0
4625 */
4626 private function render_headers_recovery_offer() {
4627 /*
4628 * On a network the .htaccess belongs to every site and only the main one
4629 * writes it, so this is not a decision a subsite gets to make. Its own
4630 * security_headers options are inert anyway: what the network serves
4631 * comes from the file the main site owns. Without this gate a subsite
4632 * administrator was shown a Restore button that could only ever answer
4633 * with a permission error, which is worse than showing nothing.
4634 */
4635 if ( ! Vigilante_Settings::can_write_shared_files() ) {
4636 return;
4637 }
4638
4639 if ( ! Vigilante_Htaccess_Recovery::is_available() ) {
4640 /*
4641 * Already restored. Offer to take it back for as long as the previous
4642 * section is still stored: a restore that cannot be undone is a second
4643 * irreversible change on top of the one being repaired.
4644 */
4645 if ( Vigilante_Htaccess_Recovery::has_undo() ) {
4646 ?>
4647 <div class="notice notice-info inline" id="vigilante-headers-recovery-undo">
4648 <p>
4649 <?php esc_html_e( 'The Security Headers settings were restored from the copy Vigilant had kept of your .htaccess.', 'vigilante' ); ?>
4650 <button type="button" class="button button-small" id="vigilante-recovery-undo">
4651 <?php esc_html_e( 'Undo the restore', 'vigilante' ); ?>
4652 </button>
4653 </p>
4654 </div>
4655 <?php
4656 }
4657
4658 return;
4659 }
4660
4661 $rows = Vigilante_Htaccess_Recovery::get_diff( $this->settings );
4662
4663 if ( empty( $rows ) ) {
4664 return;
4665 }
4666
4667 $snapshot = Vigilante_Htaccess_Recovery::get_snapshot();
4668 $taken = isset( $snapshot['time'] ) ? (int) $snapshot['time'] : 0;
4669 $block = Vigilante_Htaccess_Recovery::get_raw_block();
4670 ?>
4671 <div class="vigilante-settings-section" id="vigilante-headers-recovery">
4672 <h2><?php esc_html_e( 'Recover your previous header settings', 'vigilante' ); ?></h2>
4673 <p>
4674 <?php esc_html_e( 'An earlier update 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' ); ?>
4675 </p>
4676 <?php if ( $taken ) : ?>
4677 <p class="description">
4678 <?php
4679 printf(
4680 /* translators: %s: date and time the .htaccess copy was taken. */
4681 esc_html__( 'Copy taken on %s.', 'vigilante' ),
4682 esc_html( wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $taken ) )
4683 );
4684 ?>
4685 </p>
4686 <?php endif; ?>
4687
4688 <table class="widefat striped">
4689 <thead>
4690 <tr>
4691 <th scope="col"><?php esc_html_e( 'Setting', 'vigilante' ); ?></th>
4692 <th scope="col"><?php esc_html_e( 'Now', 'vigilante' ); ?></th>
4693 <th scope="col"><?php esc_html_e( 'Would be restored to', 'vigilante' ); ?></th>
4694 </tr>
4695 </thead>
4696 <tbody>
4697 <?php foreach ( $rows as $row ) : ?>
4698 <tr>
4699 <th scope="row"><?php echo esc_html( $row['label'] ); ?></th>
4700 <td><?php echo esc_html( $row['current'] ); ?></td>
4701 <td>
4702 <?php echo esc_html( $row['recovered'] ); ?>
4703 <?php if ( ! empty( $row['detail'] ) ) : ?>
4704 <br><span class="description"><?php echo esc_html( $row['detail'] ); ?></span>
4705 <?php endif; ?>
4706 </td>
4707 </tr>
4708 <?php endforeach; ?>
4709 </tbody>
4710 </table>
4711
4712 <p class="description">
4713 <?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' ); ?>
4714 </p>
4715
4716 <?php if ( '' !== $block ) : ?>
4717 <details>
4718 <summary><?php esc_html_e( 'Show the saved .htaccess block', 'vigilante' ); ?></summary>
4719 <textarea readonly rows="12" class="large-text code" onclick="this.select();"><?php echo esc_textarea( $block ); ?></textarea>
4720 </details>
4721 <?php endif; ?>
4722
4723 <p class="submit vigilante-submit-buttons">
4724 <button type="button" class="button button-primary" id="vigilante-recovery-restore">
4725 <?php esc_html_e( 'Restore these settings', 'vigilante' ); ?>
4726 </button>
4727 <button type="button" class="button" id="vigilante-recovery-dismiss">
4728 <?php esc_html_e( 'No thanks, keep what I have', 'vigilante' ); ?>
4729 </button>
4730 </p>
4731 <div id="vigilante-recovery-result"></div>
4732 </div>
4733 <?php
4734 }
4735
4736 private function render_tab_headers() {
4737 $is_disabled = $this->render_module_disabled_notice( 'security_headers' );
4738 // Every setting on this tab ends up in .htaccess, so on a subsite the
4739 // whole tab is somebody else's, values included.
4740 $vg_shared_locked = $this->shared_files_locked();
4741 $options = $this->get_section_for_display( 'security_headers' );
4742 ?>
4743 <?php $this->render_headers_recovery_offer(); ?>
4744
4745 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="security_headers" <?php echo $is_disabled ? 'inert' : ''; ?>>
4746 <?php $this->render_shared_files_notice(); ?>
4747 <div id="vigilante-section-headers-main" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
4748 <h2>
4749 <?php esc_html_e( 'Security Headers', 'vigilante' ); ?>
4750 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
4751 </h2>
4752 <p><?php esc_html_e( 'HTTP headers sent with every response via .htaccess (mod_headers).', 'vigilante' ); ?></p>
4753
4754 <table class="form-table">
4755 <tr>
4756 <th scope="row"><label for="vigilante-f-security-headers-x-frame-options"><?php esc_html_e( 'X-Frame-Options', 'vigilante' ); ?></label></th>
4757 <td>
4758 <select id="vigilante-f-security-headers-x-frame-options" name="security_headers[x_frame_options]">
4759 <option value="" <?php selected( empty( $options['x_frame_options'] ) ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
4760 <option value="SAMEORIGIN" <?php selected( $options['x_frame_options'] ?? '', 'SAMEORIGIN' ); ?>>SAMEORIGIN</option>
4761 <option value="DENY" <?php selected( $options['x_frame_options'] ?? '', 'DENY' ); ?>>DENY</option>
4762 </select>
4763 <p class="description"><?php esc_html_e( '&#9432; Prevents clickjacking attacks. Also sets CSP frame-ancestors automatically.', 'vigilante' ); ?></p>
4764 </td>
4765 </tr>
4766 <tr>
4767 <th scope="row"><?php esc_html_e( 'X-Content-Type-Options', 'vigilante' ); ?></th>
4768 <td>
4769 <label>
4770 <input type="checkbox" name="security_headers[x_content_type_options]" value="1" <?php checked( ! empty( $options['x_content_type_options'] ) ); ?>>
4771 <?php esc_html_e( 'Add nosniff header to prevent MIME type sniffing', 'vigilante' ); ?>
4772 </label>
4773 </td>
4774 </tr>
4775 <tr>
4776 <th scope="row"><label for="vigilante-f-security-headers-referrer-policy"><?php esc_html_e( 'Referrer-Policy', 'vigilante' ); ?></label></th>
4777 <td>
4778 <select id="vigilante-f-security-headers-referrer-policy" name="security_headers[referrer_policy]">
4779 <option value="" <?php selected( empty( $options['referrer_policy'] ) ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
4780 <option value="no-referrer" <?php selected( $options['referrer_policy'] ?? '', 'no-referrer' ); ?>>no-referrer</option>
4781 <option value="strict-origin-when-cross-origin" <?php selected( $options['referrer_policy'] ?? '', 'strict-origin-when-cross-origin' ); ?>>strict-origin-when-cross-origin</option>
4782 <option value="same-origin" <?php selected( $options['referrer_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
4783 </select>
4784 </td>
4785 </tr>
4786 </table>
4787
4788 <h3 id="vigilante-section-headers-csp"><?php esc_html_e( 'Content Security Policy', 'vigilante' ); ?></h3>
4789 <table class="form-table">
4790 <tr>
4791 <th scope="row"><?php esc_html_e( 'Enable CSP', 'vigilante' ); ?></th>
4792 <td>
4793 <label>
4794 <input type="checkbox" name="security_headers[csp][enabled]" value="1" <?php checked( ! empty( $options['csp']['enabled'] ) ); ?>>
4795 <?php esc_html_e( 'Enable Content Security Policy', 'vigilante' ); ?>
4796 </label>
4797 <p class="description"><?php esc_html_e( 'The default policy includes upgrade-insecure-requests, which asks browsers to request every http:// resource over https. Vigilant writes it only when the site address starts with https://, because on a site served over http it would stop every stylesheet, script and image from loading. If your site is served over https through a proxy or CDN that terminates TLS, set the site address to https:// in Settings > General; the rules follow the next time this tab is saved or Vigilant is updated.', 'vigilante' ); ?></p>
4798 </td>
4799 </tr>
4800 <tr>
4801 <th scope="row"><?php esc_html_e( 'Report Only Mode', 'vigilante' ); ?></th>
4802 <td>
4803 <label>
4804 <input type="checkbox" name="security_headers[csp][report_only]" value="1" <?php checked( ! empty( $options['csp']['report_only'] ) ); ?>>
4805 <?php esc_html_e( 'Report violations without blocking (for testing)', 'vigilante' ); ?>
4806 </label>
4807 </td>
4808 </tr>
4809 </table>
4810
4811 <h3 id="vigilante-section-headers-force-https"><?php esc_html_e( 'HTTPS', 'vigilante' ); ?></h3>
4812 <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>
4813 <table class="form-table">
4814 <tr>
4815 <th scope="row"><?php esc_html_e( 'Redirect HTTP to HTTPS', 'vigilante' ); ?></th>
4816 <td>
4817 <label>
4818 <input type="checkbox" name="security_headers[redirect_http_to_https]" value="1" <?php checked( ! empty( $options['redirect_http_to_https'] ) ); ?>>
4819 <?php esc_html_e( 'Send visitors arriving over HTTP to the HTTPS address', 'vigilante' ); ?>
4820 </label>
4821 <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>
4822 </td>
4823 </tr>
4824 <tr>
4825 <th scope="row"><?php esc_html_e( 'Fix Mixed Content', 'vigilante' ); ?></th>
4826 <td>
4827 <label>
4828 <input type="checkbox" name="security_headers[fix_mixed_content]" value="1" <?php checked( ! empty( $options['fix_mixed_content'] ) ); ?>>
4829 <?php esc_html_e( 'Rewrite this site http:// resources to https://', 'vigilante' ); ?>
4830 </label>
4831 <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>
4832 </td>
4833 </tr>
4834 <tr id="field-upgrade-insecure-requests">
4835 <th scope="row"><?php esc_html_e( 'Upgrade Insecure Requests', 'vigilante' ); ?></th>
4836 <td>
4837 <label>
4838 <input type="checkbox" name="security_headers[upgrade_insecure_requests]" value="1" <?php checked( ! empty( $options['upgrade_insecure_requests'] ) ); ?>>
4839 <?php esc_html_e( 'Ask browsers to upgrade every http:// request to https://', 'vigilante' ); ?>
4840 </label>
4841 <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>
4842 </td>
4843 </tr>
4844 <tr>
4845 <th scope="row"><?php esc_html_e( 'Rewrite Site Address on Activation', 'vigilante' ); ?></th>
4846 <td>
4847 <label>
4848 <input type="checkbox" name="security_headers[force_https]" value="1" <?php checked( ! empty( $options['force_https'] ) ); ?>>
4849 <?php esc_html_e( 'Change the WordPress and site addresses to https:// when the plugin is activated', 'vigilante' ); ?>
4850 </label>
4851 <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>
4852 </td>
4853 </tr>
4854 </table>
4855
4856 <h3 id="vigilante-section-headers-hsts"><?php esc_html_e( 'HSTS (HTTP Strict Transport Security)', 'vigilante' ); ?></h3>
4857 <?php $vig_home_https = ( 0 === strpos( (string) get_option( 'home' ), 'https://' ) ); ?>
4858 <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>
4859 <?php if ( ! $vig_home_https ) : ?>
4860 <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>
4861 <?php endif; ?>
4862 <table class="form-table">
4863 <tr>
4864 <th scope="row"><?php esc_html_e( 'Enable HSTS', 'vigilante' ); ?></th>
4865 <td>
4866 <?php if ( ! $vig_home_https ) : ?>
4867 <?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. */ ?>
4868 <input type="hidden" name="security_headers[hsts][enabled]" value="<?php echo ! empty( $options['hsts']['enabled'] ) ? '1' : '0'; ?>">
4869 <?php endif; ?>
4870 <label>
4871 <input type="checkbox" name="security_headers[hsts][enabled]" value="1" <?php checked( ! empty( $options['hsts']['enabled'] ) ); ?> <?php disabled( ! $vig_home_https ); ?>>
4872 <?php esc_html_e( 'Send the Strict-Transport-Security header', 'vigilante' ); ?>
4873 </label>
4874 <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>
4875 </td>
4876 </tr>
4877 <tr>
4878 <th scope="row"><label for="vigilante-f-security-headers-hsts-max-age"><?php esc_html_e( 'Max Age', 'vigilante' ); ?></label></th>
4879 <td>
4880 <select id="vigilante-f-security-headers-hsts-max-age" name="security_headers[hsts][max_age]">
4881 <option value="86400" <?php selected( $options['hsts']['max_age'] ?? 31536000, 86400 ); ?>><?php esc_html_e( '1 day (testing)', 'vigilante' ); ?></option>
4882 <option value="2592000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 2592000 ); ?>><?php esc_html_e( '30 days', 'vigilante' ); ?></option>
4883 <option value="31536000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 31536000 ); ?>><?php esc_html_e( '1 year (recommended)', 'vigilante' ); ?></option>
4884 <option value="63072000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 63072000 ); ?>><?php esc_html_e( '2 years', 'vigilante' ); ?></option>
4885 </select>
4886 </td>
4887 </tr>
4888 <tr>
4889 <th scope="row"><?php esc_html_e( 'Include Subdomains', 'vigilante' ); ?></th>
4890 <td>
4891 <label>
4892 <input type="checkbox" name="security_headers[hsts][include_subdomains]" value="1" <?php checked( ! empty( $options['hsts']['include_subdomains'] ) ); ?>>
4893 <?php esc_html_e( 'Apply HSTS to all subdomains', 'vigilante' ); ?>
4894 </label>
4895 </td>
4896 </tr>
4897 </table>
4898
4899 <h3 id="vigilante-section-headers-fingerprint"><?php esc_html_e( 'Server Identity', 'vigilante' ); ?></h3>
4900 <p class="description"><?php esc_html_e( 'Hide identifying information that servers expose in responses.', 'vigilante' ); ?></p>
4901 <table class="form-table">
4902 <tr>
4903 <th scope="row"><?php esc_html_e( 'Server Signature', 'vigilante' ); ?></th>
4904 <td>
4905 <label>
4906 <input type="checkbox" name="security_headers[hide_server_signature]" value="1" <?php checked( ! empty( $options['hide_server_signature'] ) ); ?>>
4907 <?php esc_html_e( 'Hide server signature (ServerSignature Off)', 'vigilante' ); ?>
4908 </label>
4909 </td>
4910 </tr>
4911 <tr>
4912 <th scope="row"><?php esc_html_e( 'Remove Fingerprinting Headers', 'vigilante' ); ?></th>
4913 <td>
4914 <label>
4915 <input type="checkbox" name="security_headers[remove_fingerprinting_headers]" value="1" <?php checked( ! empty( $options['remove_fingerprinting_headers'] ) ); ?>>
4916 <?php esc_html_e( 'Remove X-Powered-By and Server headers', 'vigilante' ); ?>
4917 </label>
4918 </td>
4919 </tr>
4920 </table>
4921 </div>
4922
4923 <?php $vg_cop = ( isset( $options['cross_origin_policies'] ) && is_array( $options['cross_origin_policies'] ) ) ? $options['cross_origin_policies'] : array(); ?>
4924 <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' : ''; ?>>
4925 <h2>
4926 <?php esc_html_e( 'Cross-Origin Policies', 'vigilante' ); ?>
4927 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
4928 </h2>
4929 <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>
4930
4931 <table class="form-table">
4932 <tr>
4933 <th scope="row"><label for="vigilante-f-security-headers-coop"><?php esc_html_e( 'Cross-Origin-Opener-Policy (COOP)', 'vigilante' ); ?></label></th>
4934 <td>
4935 <select id="vigilante-f-security-headers-coop" name="security_headers[cross_origin_policies][opener_policy]">
4936 <option value="" <?php selected( empty( $vg_cop['opener_policy'] ) ); ?>><?php esc_html_e( 'Disabled (header not sent)', 'vigilante' ); ?></option>
4937 <option value="unsafe-none" <?php selected( $vg_cop['opener_policy'] ?? '', 'unsafe-none' ); ?>>unsafe-none</option>
4938 <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>
4939 <option value="same-origin" <?php selected( $vg_cop['opener_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
4940 </select>
4941 <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>
4942 </td>
4943 </tr>
4944 <tr>
4945 <th scope="row"><label for="vigilante-f-security-headers-coep"><?php esc_html_e( 'Cross-Origin-Embedder-Policy (COEP)', 'vigilante' ); ?></label></th>
4946 <td>
4947 <select id="vigilante-f-security-headers-coep" name="security_headers[cross_origin_policies][embedder_policy]">
4948 <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>
4949 <option value="credentialless" <?php selected( $vg_cop['embedder_policy'] ?? '', 'credentialless' ); ?>>credentialless</option>
4950 <option value="require-corp" <?php selected( $vg_cop['embedder_policy'] ?? '', 'require-corp' ); ?>>require-corp</option>
4951 </select>
4952 <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>
4953 </td>
4954 </tr>
4955 <tr>
4956 <th scope="row"><label for="vigilante-f-security-headers-corp"><?php esc_html_e( 'Cross-Origin-Resource-Policy (CORP)', 'vigilante' ); ?></label></th>
4957 <td>
4958 <select id="vigilante-f-security-headers-corp" name="security_headers[cross_origin_policies][resource_policy]">
4959 <option value="" <?php selected( empty( $vg_cop['resource_policy'] ) ); ?>><?php esc_html_e( 'Disabled (header not sent)', 'vigilante' ); ?></option>
4960 <option value="same-site" <?php selected( $vg_cop['resource_policy'] ?? '', 'same-site' ); ?>>same-site</option>
4961 <option value="same-origin" <?php selected( $vg_cop['resource_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
4962 <option value="cross-origin" <?php selected( $vg_cop['resource_policy'] ?? '', 'cross-origin' ); ?>><?php esc_html_e( 'cross-origin (recommended)', 'vigilante' ); ?></option>
4963 </select>
4964 <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>
4965 </td>
4966 </tr>
4967 </table>
4968 </div>
4969
4970 <p class="submit vigilante-submit-buttons">
4971 <?php if ( ! $vg_shared_locked ) : ?>
4972 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4973 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4974 </button>
4975 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4976 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4977 </button>
4978 <?php endif; ?>
4979 <?php /* Testing what the server actually sends is read-only and useful from any site of a network. */ ?>
4980 <button type="button" class="button vigilante-test-headers">
4981 <?php esc_html_e( 'Test Headers', 'vigilante' ); ?>
4982 </button>
4983 </p>
4984 </form>
4985
4986 <div id="vigilante-headers-result"></div>
4987 <?php
4988 }
4989
4990 /**
4991 * Render REST API tab
4992 */
4993 private function render_tab_rest_api() {
4994 $is_disabled = $this->render_module_disabled_notice( 'rest_api_security' );
4995 $options = $this->settings->get_section( 'rest_api_security' );
4996 ?>
4997 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="rest_api_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
4998 <div id="vigilante-section-rest-api-main" class="vigilante-settings-section">
4999 <h2>
5000 <?php esc_html_e( 'REST API Security', 'vigilante' ); ?>
5001 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5002 </h2>
5003 <p><?php esc_html_e( 'Control access to WordPress REST API endpoints.', 'vigilante' ); ?></p>
5004
5005 <table class="form-table">
5006 <tr>
5007 <th scope="row"><label for="vigilante-f-rest-api-security-mode"><?php esc_html_e( 'Access Mode', 'vigilante' ); ?></label></th>
5008 <td>
5009 <select id="vigilante-f-rest-api-security-mode" name="rest_api_security[mode]">
5010 <option value="open" <?php selected( $options['mode'] ?? 'selective', 'open' ); ?>><?php esc_html_e( 'Open - Allow all requests', 'vigilante' ); ?></option>
5011 <option value="selective" <?php selected( $options['mode'] ?? 'selective', 'selective' ); ?>><?php esc_html_e( 'Selective - Protect sensitive endpoints', 'vigilante' ); ?></option>
5012 <option value="authenticated_only" <?php selected( $options['mode'] ?? 'selective', 'authenticated_only' ); ?>><?php esc_html_e( 'Authenticated - Require login for all', 'vigilante' ); ?></option>
5013 </select>
5014 <p class="description"><?php esc_html_e( 'Selective mode is recommended.', 'vigilante' ); ?></p>
5015 </td>
5016 </tr>
5017 <tr id="field-block-user-enumeration">
5018 <th scope="row"><?php esc_html_e( 'Block User Enumeration', 'vigilante' ); ?></th>
5019 <td>
5020 <label>
5021 <input type="checkbox" name="rest_api_security[block_user_enumeration]" value="1" <?php checked( ! empty( $options['block_user_enumeration'] ) ); ?>>
5022 <?php esc_html_e( 'Protect /wp/v2/users endpoint for unauthenticated users', 'vigilante' ); ?>
5023 </label>
5024 </td>
5025 </tr>
5026 <tr>
5027 <th scope="row"><?php esc_html_e( 'Disable JSONP', 'vigilante' ); ?></th>
5028 <td>
5029 <label>
5030 <input type="checkbox" name="rest_api_security[disable_jsonp]" value="1" <?php checked( ! empty( $options['disable_jsonp'] ) ); ?>>
5031 <?php esc_html_e( 'Disable JSONP support in REST API', 'vigilante' ); ?>
5032 </label>
5033 </td>
5034 </tr>
5035 </table>
5036 </div>
5037
5038 <p class="submit vigilante-submit-buttons">
5039 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5040 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5041 </button>
5042 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5043 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5044 </button>
5045 </p>
5046 </form>
5047 <?php
5048 }
5049
5050 /**
5051 * Render User Security tab
5052 */
5053 private function render_tab_users() {
5054 $is_disabled = $this->render_module_disabled_notice( 'user_security' );
5055 $options = $this->settings->get_section( 'user_security' );
5056 $monitoring = $options['admin_monitoring'] ?? array();
5057 $registration = $options['registration_approval'] ?? array();
5058 $session_limits = $options['session_limits'] ?? array();
5059 $password_exp = $options['password_expiration'] ?? array();
5060 $email_verify = $options['email_verification'] ?? array();
5061 ?>
5062
5063 <!-- ============================================================
5064 SETTINGS SECTION - Single form for all configuration
5065 ============================================================ -->
5066 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="user_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
5067
5068 <!-- Username & Password Protection -->
5069 <div id="vigilante-section-users-password" class="vigilante-settings-section">
5070 <h2>
5071 <?php esc_html_e( 'Username & password protection', 'vigilante' ); ?>
5072 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5073 </h2>
5074 <p><?php esc_html_e( 'Enforce secure username and password policies.', 'vigilante' ); ?></p>
5075
5076 <table class="form-table">
5077 <tr>
5078 <th scope="row"><?php esc_html_e( 'Block Insecure Usernames', 'vigilante' ); ?></th>
5079 <td>
5080 <label>
5081 <input type="checkbox" name="user_security[block_insecure_usernames]" value="1" <?php checked( ! empty( $options['block_insecure_usernames'] ) ); ?>>
5082 <?php esc_html_e( 'Prevent creation of users with common usernames (admin, administrator, etc.)', 'vigilante' ); ?>
5083 </label>
5084 </td>
5085 </tr>
5086 <?php
5087 $pw_policy = wp_parse_args(
5088 ( isset( $options['password_policy'] ) && is_array( $options['password_policy'] ) ) ? $options['password_policy'] : array(),
5089 array(
5090 'require_uppercase' => false,
5091 'require_lowercase' => false,
5092 'require_number' => false,
5093 'require_special' => false,
5094 'block_common' => true,
5095 'block_username' => true,
5096 'affected_roles' => array(),
5097 )
5098 );
5099 $pw_policy_roles = (array) $pw_policy['affected_roles'];
5100 ?>
5101 <tr>
5102 <th scope="row"><?php esc_html_e( 'Enforce Strong Passwords', 'vigilante' ); ?></th>
5103 <td>
5104 <label>
5105 <input type="checkbox" name="user_security[force_strong_passwords]" value="1" <?php checked( ! empty( $options['force_strong_passwords'] ) ); ?>>
5106 <?php esc_html_e( 'Check passwords against the requirements below when a user sets or changes one', 'vigilante' ); ?>
5107 </label>
5108 </td>
5109 </tr>
5110 <tr>
5111 <th scope="row"><label for="vigilante-f-user-security-min-password-length"><?php esc_html_e( 'Minimum Password Length', 'vigilante' ); ?></label></th>
5112 <td>
5113 <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">
5114 <?php esc_html_e( 'characters', 'vigilante' ); ?>
5115 </td>
5116 </tr>
5117 <tr>
5118 <th scope="row"><?php esc_html_e( 'Password Requirements', 'vigilante' ); ?></th>
5119 <td>
5120 <label style="display:block;margin-bottom:5px;">
5121 <input type="checkbox" name="user_security[password_policy][require_uppercase]" value="1" <?php checked( ! empty( $pw_policy['require_uppercase'] ) ); ?>>
5122 <?php esc_html_e( 'Require an uppercase letter (A-Z)', 'vigilante' ); ?>
5123 </label>
5124 <label style="display:block;margin-bottom:5px;">
5125 <input type="checkbox" name="user_security[password_policy][require_lowercase]" value="1" <?php checked( ! empty( $pw_policy['require_lowercase'] ) ); ?>>
5126 <?php esc_html_e( 'Require a lowercase letter (a-z)', 'vigilante' ); ?>
5127 </label>
5128 <label style="display:block;margin-bottom:5px;">
5129 <input type="checkbox" name="user_security[password_policy][require_number]" value="1" <?php checked( ! empty( $pw_policy['require_number'] ) ); ?>>
5130 <?php esc_html_e( 'Require a number (0-9)', 'vigilante' ); ?>
5131 </label>
5132 <label style="display:block;margin-bottom:5px;">
5133 <input type="checkbox" name="user_security[password_policy][require_special]" value="1" <?php checked( ! empty( $pw_policy['require_special'] ) ); ?>>
5134 <?php esc_html_e( 'Require a special character (!, @, #, ...)', 'vigilante' ); ?>
5135 </label>
5136 <label style="display:block;margin-bottom:5px;">
5137 <input type="checkbox" name="user_security[password_policy][block_common]" value="1" <?php checked( ! empty( $pw_policy['block_common'] ) ); ?>>
5138 <?php esc_html_e( 'Reject well-known common passwords', 'vigilante' ); ?>
5139 </label>
5140 <label style="display:block;margin-bottom:5px;">
5141 <input type="checkbox" name="user_security[password_policy][block_username]" value="1" <?php checked( ! empty( $pw_policy['block_username'] ) ); ?>>
5142 <?php esc_html_e( 'Do not allow the username inside the password', 'vigilante' ); ?>
5143 </label>
5144 <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>
5145 </td>
5146 </tr>
5147 <tr>
5148 <th scope="row"><?php esc_html_e( 'Apply Password Rules To', 'vigilante' ); ?></th>
5149 <td>
5150 <?php $this->list_sentinel( 'user_security[password_policy][affected_roles]' ); ?>
5151 <?php foreach ( wp_roles()->get_names() as $role_slug => $role_name ) : ?>
5152 <label style="display:block;margin-bottom:5px;">
5153 <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 ) ); ?>>
5154 <?php echo esc_html( translate_user_role( $role_name ) ); ?>
5155 </label>
5156 <?php endforeach; ?>
5157 <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>
5158 </td>
5159 </tr>
5160 <tr id="field-block-author-scanning">
5161 <th scope="row"><?php esc_html_e( 'Block Author Scanning', 'vigilante' ); ?></th>
5162 <td>
5163 <label>
5164 <input type="checkbox" name="user_security[block_author_scanning]" value="1" <?php checked( ! empty( $options['block_author_scanning'] ) ); ?>>
5165 <?php esc_html_e( 'Prevent username discovery via ?author=N URLs', 'vigilante' ); ?>
5166 </label>
5167 </td>
5168 </tr>
5169 <tr>
5170 <th scope="row"><?php esc_html_e( 'Display Name Protection', 'vigilante' ); ?></th>
5171 <td>
5172 <label>
5173 <input type="checkbox" name="user_security[prevent_display_name_login_match]" value="1" <?php checked( ! empty( $options['prevent_display_name_login_match'] ) ); ?>>
5174 <?php esc_html_e( 'Prevent users from saving a display name that matches their login username', 'vigilante' ); ?>
5175 </label>
5176 <p class="description"><?php esc_html_e( 'The display name is publicly visible and should not reveal the login username.', 'vigilante' ); ?></p>
5177 </td>
5178 </tr>
5179 </table>
5180 </div>
5181
5182 <!-- Admin Monitoring -->
5183 <div id="vigilante-section-users-admin-monitoring" class="vigilante-settings-section">
5184 <h2>
5185 <?php esc_html_e( 'Admin monitoring', 'vigilante' ); ?>
5186 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5187 </h2>
5188 <p><?php esc_html_e( 'Receive email alerts when administrator accounts are modified. All events are always logged to the Security Audit.', 'vigilante' ); ?></p>
5189
5190 <table class="form-table">
5191 <tr>
5192 <th scope="row"><?php esc_html_e( 'New Administrator Alert', 'vigilante' ); ?></th>
5193 <td>
5194 <label>
5195 <input type="checkbox" name="user_security[admin_monitoring][alert_new_admin]" value="1" <?php checked( ! empty( $monitoring['alert_new_admin'] ) ); ?>>
5196 <?php esc_html_e( 'Send email alert when a new administrator account is created', 'vigilante' ); ?>
5197 </label>
5198 </td>
5199 </tr>
5200 <tr>
5201 <th scope="row"><?php esc_html_e( 'Admin Email Change Alert', 'vigilante' ); ?></th>
5202 <td>
5203 <label>
5204 <input type="checkbox" name="user_security[admin_monitoring][alert_admin_email_change]" value="1" <?php checked( ! empty( $monitoring['alert_admin_email_change'] ) ); ?>>
5205 <?php esc_html_e( 'Send email alert when an administrator email address is changed', 'vigilante' ); ?>
5206 </label>
5207 </td>
5208 </tr>
5209 <tr>
5210 <th scope="row"><?php esc_html_e( 'Permission Elevation Alert', 'vigilante' ); ?></th>
5211 <td>
5212 <label>
5213 <input type="checkbox" name="user_security[admin_monitoring][alert_permission_elevation]" value="1" <?php checked( ! empty( $monitoring['alert_permission_elevation'] ) ); ?>>
5214 <?php esc_html_e( 'Send email alert when a user is elevated to administrator role', 'vigilante' ); ?>
5215 </label>
5216 </td>
5217 </tr>
5218 <tr>
5219 <th scope="row"><?php esc_html_e( 'Admin Password Change Alert', 'vigilante' ); ?></th>
5220 <td>
5221 <label>
5222 <input type="checkbox" name="user_security[admin_monitoring][alert_admin_password_change]" value="1" <?php checked( ! empty( $monitoring['alert_admin_password_change'] ) ); ?>>
5223 <?php esc_html_e( 'Send email alert when an administrator password is changed', 'vigilante' ); ?>
5224 </label>
5225 </td>
5226 </tr>
5227 </table>
5228
5229 <p class="description">
5230 <?php
5231 printf(
5232 /* translators: %s: Link to notification settings */
5233 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
5234 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
5235 );
5236 ?>
5237 </p>
5238 </div>
5239
5240 <!-- Registration Approval -->
5241 <div id="vigilante-section-users-registration" class="vigilante-settings-section">
5242 <h2>
5243 <?php esc_html_e( 'Registration approval', 'vigilante' ); ?>
5244 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5245 </h2>
5246 <p><?php esc_html_e( 'Require manual approval for new user registrations.', 'vigilante' ); ?></p>
5247
5248 <table class="form-table">
5249 <tr>
5250 <th scope="row"><?php esc_html_e( 'Enable Registration Approval', 'vigilante' ); ?></th>
5251 <td>
5252 <label>
5253 <input type="checkbox" name="user_security[registration_approval][enabled]" value="1" <?php checked( ! empty( $registration['enabled'] ) ); ?>>
5254 <?php esc_html_e( 'New users must be approved by an administrator before they can log in', 'vigilante' ); ?>
5255 </label>
5256 </td>
5257 </tr>
5258 <tr>
5259 <th scope="row"><?php esc_html_e( 'Notify Admin', 'vigilante' ); ?></th>
5260 <td>
5261 <label>
5262 <input type="checkbox" name="user_security[registration_approval][notify_admin]" value="1" <?php checked( ! empty( $registration['notify_admin'] ) ); ?>>
5263 <?php esc_html_e( 'Send email notification when a new user registers', 'vigilante' ); ?>
5264 </label>
5265 <p class="description"><?php esc_html_e( 'Disable on high-traffic sites to avoid email overload.', 'vigilante' ); ?></p>
5266 </td>
5267 </tr>
5268 <tr>
5269 <th scope="row"><label for="vigilante-f-user-security-registration-approval-auto-reject-days"><?php esc_html_e( 'Auto-reject After', 'vigilante' ); ?></label></th>
5270 <td>
5271 <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">
5272 <?php esc_html_e( 'days (0 = never)', 'vigilante' ); ?>
5273 <p class="description"><?php esc_html_e( 'Automatically reject pending registrations after this many days.', 'vigilante' ); ?></p>
5274 </td>
5275 </tr>
5276 </table>
5277 </div>
5278
5279 <!-- Session Limits -->
5280 <div id="vigilante-section-users-sessions" class="vigilante-settings-section">
5281 <h2>
5282 <?php esc_html_e( 'Session limits', 'vigilante' ); ?>
5283 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5284 </h2>
5285 <p><?php esc_html_e( 'Limit the number of simultaneous sessions per user.', 'vigilante' ); ?></p>
5286
5287 <?php if ( Vigilante_User_Security::session_limit_is_network_wide() ) : ?>
5288 <div class="notice notice-warning inline">
5289 <p>
5290 <?php esc_html_e( 'This limit does not apply on a network. WordPress keeps the sessions of an account for the whole network, not per site, so a limit set here would count and close the sessions that person opened on other sites, including an administrator session elsewhere. A network-wide session policy is planned; until then these settings are saved but not enforced.', 'vigilante' ); ?>
5291 </p>
5292 </div>
5293 <?php endif; ?>
5294
5295 <table class="form-table">
5296 <tr>
5297 <th scope="row"><?php esc_html_e( 'Enable Session Limits', 'vigilante' ); ?></th>
5298 <td>
5299 <label>
5300 <input type="checkbox" name="user_security[session_limits][enabled]" value="1" <?php checked( ! empty( $session_limits['enabled'] ) ); ?>>
5301 <?php esc_html_e( 'Limit the number of active sessions per user', 'vigilante' ); ?>
5302 </label>
5303 </td>
5304 </tr>
5305 <tr>
5306 <th scope="row"><label for="vigilante-f-user-security-session-limits-max-sessions"><?php esc_html_e( 'Maximum Sessions', 'vigilante' ); ?></label></th>
5307 <td>
5308 <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">
5309 <?php esc_html_e( 'sessions per user', 'vigilante' ); ?>
5310 </td>
5311 </tr>
5312 <tr>
5313 <th scope="row"><label for="vigilante-f-user-security-session-limits-behavior"><?php esc_html_e( 'When Limit Exceeded', 'vigilante' ); ?></label></th>
5314 <td>
5315 <select id="vigilante-f-user-security-session-limits-behavior" name="user_security[session_limits][behavior]">
5316 <option value="block_new" <?php selected( ( $session_limits['behavior'] ?? 'close_oldest' ), 'block_new' ); ?>><?php esc_html_e( 'Block new login', 'vigilante' ); ?></option>
5317 <option value="close_oldest" <?php selected( ( $session_limits['behavior'] ?? 'close_oldest' ), 'close_oldest' ); ?>><?php esc_html_e( 'Close oldest session', 'vigilante' ); ?></option>
5318 </select>
5319 <p class="description"><?php esc_html_e( '"Close oldest" is recommended for security - ensures attackers cannot lock out legitimate users.', 'vigilante' ); ?></p>
5320 </td>
5321 </tr>
5322 <tr>
5323 <th scope="row"><?php esc_html_e( 'Exclude Administrators', 'vigilante' ); ?></th>
5324 <td>
5325 <label>
5326 <input type="checkbox" name="user_security[session_limits][exclude_admins]" value="1" <?php checked( ! empty( $session_limits['exclude_admins'] ) ); ?>>
5327 <?php esc_html_e( 'Do not apply session limits to administrators', 'vigilante' ); ?>
5328 </label>
5329 </td>
5330 </tr>
5331 </table>
5332 </div>
5333
5334 <!-- Password Expiration -->
5335 <div id="vigilante-section-users-password-exp" class="vigilante-settings-section">
5336 <h2>
5337 <?php esc_html_e( 'Password expiration', 'vigilante' ); ?>
5338 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5339 </h2>
5340 <p><?php esc_html_e( 'Force users to change their password periodically.', 'vigilante' ); ?></p>
5341
5342 <table class="form-table">
5343 <tr>
5344 <th scope="row"><?php esc_html_e( 'Enable Password Expiration', 'vigilante' ); ?></th>
5345 <td>
5346 <label>
5347 <input type="checkbox" name="user_security[password_expiration][enabled]" value="1" <?php checked( ! empty( $password_exp['enabled'] ) ); ?>>
5348 <?php esc_html_e( 'Force password change after a set number of days', 'vigilante' ); ?>
5349 </label>
5350 </td>
5351 </tr>
5352 <tr>
5353 <th scope="row"><label for="vigilante-f-user-security-password-expiration-expire-days"><?php esc_html_e( 'Expire After', 'vigilante' ); ?></label></th>
5354 <td>
5355 <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">
5356 <?php esc_html_e( 'days', 'vigilante' ); ?>
5357 <p class="description"><?php esc_html_e( 'PCI-DSS recommends 90 days.', 'vigilante' ); ?></p>
5358 </td>
5359 </tr>
5360 <tr>
5361 <th scope="row"><label for="vigilante-f-user-security-password-expiration-warning-days"><?php esc_html_e( 'Warning Period', 'vigilante' ); ?></label></th>
5362 <td>
5363 <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">
5364 <?php esc_html_e( 'days before expiration', 'vigilante' ); ?>
5365 <p class="description"><?php esc_html_e( 'Show warning notice this many days before password expires.', 'vigilante' ); ?></p>
5366 </td>
5367 </tr>
5368 <tr>
5369 <th scope="row"><label for="vigilante-f-user-security-password-expiration-password-history"><?php esc_html_e( 'Password History', 'vigilante' ); ?></label></th>
5370 <td>
5371 <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">
5372 <?php esc_html_e( 'passwords to remember', 'vigilante' ); ?>
5373 <p class="description"><?php esc_html_e( 'Prevent reusing recent passwords. Set to 0 to disable.', 'vigilante' ); ?></p>
5374 </td>
5375 </tr>
5376 <tr>
5377 <th scope="row"><?php esc_html_e( 'Email Reminder', 'vigilante' ); ?></th>
5378 <td>
5379 <label>
5380 <input type="checkbox" name="user_security[password_expiration][send_reminder]" value="1" <?php checked( ! empty( $password_exp['send_reminder'] ) ); ?>>
5381 <?php esc_html_e( 'Send email reminder when password is about to expire', 'vigilante' ); ?>
5382 </label>
5383 <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>
5384 </td>
5385 </tr>
5386 <tr>
5387 <th scope="row"><?php esc_html_e( 'Affected Roles', 'vigilante' ); ?></th>
5388 <td>
5389 <?php
5390 $affected_roles = $password_exp['affected_roles'] ?? array( 'administrator', 'editor' );
5391 $all_roles = wp_roles()->get_names();
5392 $this->list_sentinel( 'user_security[password_expiration][affected_roles]' );
5393 foreach ( $all_roles as $role_slug => $role_name ) :
5394 ?>
5395 <label style="display: block; margin-bottom: 5px;">
5396 <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 ) ); ?>>
5397 <?php echo esc_html( translate_user_role( $role_name ) ); ?>
5398 </label>
5399 <?php endforeach; ?>
5400 </td>
5401 </tr>
5402 <tr>
5403 <th scope="row"><?php esc_html_e( 'Exclude specific users', 'vigilante' ); ?></th>
5404 <td>
5405 <?php $pwexp_excluded = $password_exp['excluded_users'] ?? array(); ?>
5406 <div class="vigilante-2fa-user-search-container">
5407 <div class="vigilante-2fa-user-search">
5408 <span class="search-icon"></span>
5409 <input type="text"
5410 id="vigilante_pwexp_user_search"
5411 placeholder="<?php esc_attr_e( 'Search users by name or email...', 'vigilante' ); ?>"
5412 autocomplete="off">
5413 <div class="vigilante-pwexp-search-results"></div>
5414 </div>
5415 <div class="vigilante-pwexp-excluded-users">
5416 <?php $this->list_sentinel( 'user_security[password_expiration][excluded_users]' ); ?>
5417 <?php
5418 foreach ( $pwexp_excluded as $pwexp_excluded_id ) :
5419 $excluded_user = get_user_by( 'ID', $pwexp_excluded_id );
5420 if ( ! $excluded_user ) {
5421 continue;
5422 }
5423 ?>
5424 <div class="vigilante-pwexp-excluded-user" data-user-id="<?php echo esc_attr( $pwexp_excluded_id ); ?>">
5425 <span class="user-display"><?php echo esc_html( $excluded_user->display_name . ' (' . $excluded_user->user_email . ')' ); ?></span>
5426 <button type="button" class="remove-user" aria-label="<?php esc_attr_e( 'Remove', 'vigilante' ); ?>">&times;</button>
5427 <input type="hidden" name="user_security[password_expiration][excluded_users][]" value="<?php echo esc_attr( $pwexp_excluded_id ); ?>">
5428 </div>
5429 <?php endforeach; ?>
5430 </div>
5431 </div>
5432 <p class="description"><?php esc_html_e( 'Listed users will be excluded from password expiration regardless of their role.', 'vigilante' ); ?></p>
5433 </td>
5434 </tr>
5435 </table>
5436 </div>
5437
5438 <!-- Email Verification -->
5439 <div id="vigilante-section-users-email-verify" class="vigilante-settings-section">
5440 <h2>
5441 <?php esc_html_e( 'Email verification', 'vigilante' ); ?>
5442 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5443 </h2>
5444 <p><?php esc_html_e( 'Require new users to verify their email address before logging in.', 'vigilante' ); ?></p>
5445
5446 <table class="form-table">
5447 <tr>
5448 <th scope="row"><?php esc_html_e( 'Enable Email Verification', 'vigilante' ); ?></th>
5449 <td>
5450 <label>
5451 <input type="checkbox" name="user_security[email_verification][enabled]" value="1" <?php checked( ! empty( $email_verify['enabled'] ) ); ?>>
5452 <?php esc_html_e( 'New users must verify their email before logging in', 'vigilante' ); ?>
5453 </label>
5454 </td>
5455 </tr>
5456 <tr>
5457 <th scope="row"><label for="vigilante-f-user-security-email-verification-token-expiry-hours"><?php esc_html_e( 'Link Expiration', 'vigilante' ); ?></label></th>
5458 <td>
5459 <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">
5460 <?php esc_html_e( 'hours', 'vigilante' ); ?>
5461 </td>
5462 </tr>
5463 <tr>
5464 <th scope="row"><?php esc_html_e( 'Allow Resend', 'vigilante' ); ?></th>
5465 <td>
5466 <label>
5467 <input type="checkbox" name="user_security[email_verification][allow_resend]" value="1" <?php checked( ! empty( $email_verify['allow_resend'] ) ); ?>>
5468 <?php esc_html_e( 'Allow users to request a new verification email', 'vigilante' ); ?>
5469 </label>
5470 </td>
5471 </tr>
5472 <tr>
5473 <th scope="row"><label for="vigilante-f-user-security-email-verification-auto-delete-days"><?php esc_html_e( 'Auto-delete Unverified', 'vigilante' ); ?></label></th>
5474 <td>
5475 <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">
5476 <?php esc_html_e( 'days (0 = never)', 'vigilante' ); ?>
5477 <p class="description"><?php esc_html_e( 'Automatically delete users who never verify their email.', 'vigilante' ); ?></p>
5478 </td>
5479 </tr>
5480 </table>
5481 </div>
5482
5483 <p class="submit vigilante-submit-buttons">
5484 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5485 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5486 </button>
5487 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5488 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5489 </button>
5490 </p>
5491 </form>
5492
5493 <!-- ============================================================
5494 TOOLS SECTION - Actions and utilities (no save button)
5495 ============================================================ -->
5496 <div class="vigilante-tools-section">
5497 <h2 class="vigilante-tools-header">
5498 <?php esc_html_e( 'User security tools', 'vigilante' ); ?>
5499 </h2>
5500
5501 <?php $this->render_user_actions_notice(); ?>
5502 <?php if ( ! $this->user_actions_locked() ) : ?>
5503
5504 <!-- Force Password Reset -->
5505 <div class="vigilante-tool-box">
5506 <h3><?php esc_html_e( 'Force password reset', 'vigilante' ); ?></h3>
5507 <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>
5508
5509 <!-- Reset Specific Users -->
5510 <div class="vigilante-password-reset-box">
5511 <h4><?php esc_html_e( 'Reset specific users', 'vigilante' ); ?></h4>
5512
5513 <div class="vigilante-user-search-wrapper">
5514 <input type="text" id="vigilante-password-reset-search" class="regular-text" placeholder="<?php esc_attr_e( 'Search by username, email, or display name...', 'vigilante' ); ?>">
5515 <div id="vigilante-password-reset-results" class="vigilante-user-search-results" style="display: none;"></div>
5516 </div>
5517
5518 <div id="vigilante-password-reset-selected" class="vigilante-selected-users" style="display: none;">
5519 <strong><?php esc_html_e( 'Selected Users:', 'vigilante' ); ?></strong>
5520 <ul class="vigilante-selected-users-list"></ul>
5521 </div>
5522
5523 <p class="description" style="margin-top: 15px;">
5524 <span class="dashicons dashicons-email-alt" style="color: #2271b1;"></span>
5525 <?php esc_html_e( 'Selected users will receive an email with a password reset link.', 'vigilante' ); ?>
5526 </p>
5527
5528 <p class="submit">
5529 <button type="button" id="vigilante-reset-selected-users" class="button button-primary" disabled>
5530 <?php esc_html_e( 'Force Reset for Selected Users', 'vigilante' ); ?>
5531 </button>
5532 </p>
5533 </div>
5534
5535 <!-- Reset by Role -->
5536 <div class="vigilante-password-reset-box" style="margin-top: 20px; padding-top: 20px; border-top: 1px solid #ddd;">
5537 <h4><?php esc_html_e( 'Reset by role', 'vigilante' ); ?></h4>
5538 <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>
5539
5540 <?php
5541 $wp_roles = wp_roles();
5542 $user_counts = count_users();
5543 $avail_roles = $user_counts['avail_roles'] ?? array();
5544 $current_user = wp_get_current_user();
5545 $current_roles = $current_user->roles;
5546 ?>
5547
5548 <fieldset class="vigilante-role-checkboxes" style="margin-top: 10px;">
5549 <?php foreach ( $wp_roles->roles as $role_slug => $role_data ) :
5550 $count = $avail_roles[ $role_slug ] ?? 0;
5551 if ( 0 === $count ) {
5552 continue;
5553 }
5554 $role_name = translate_user_role( $role_data['name'] );
5555 ?>
5556 <label style="display: block; margin-bottom: 6px;">
5557 <input type="checkbox"
5558 class="vigilante-reset-role-checkbox"
5559 value="<?php echo esc_attr( $role_slug ); ?>"
5560 data-count="<?php echo absint( $count ); ?>">
5561 <?php
5562 printf(
5563 /* translators: 1: Role name, 2: Number of users */
5564 '%1$s <span class="description">(%2$d)</span>',
5565 esc_html( $role_name ),
5566 absint( $count )
5567 );
5568 ?>
5569 <?php if ( in_array( $role_slug, $current_roles, true ) ) : ?>
5570 <em class="description"><?php esc_html_e( '(includes you)', 'vigilante' ); ?></em>
5571 <?php endif; ?>
5572 </label>
5573 <?php endforeach; ?>
5574 </fieldset>
5575
5576 <div id="vigilante-reset-role-summary" style="display: none; margin-top: 10px;">
5577 <p>
5578 <span class="dashicons dashicons-groups" style="color: #2271b1;"></span>
5579 <strong id="vigilante-reset-role-count">0</strong>
5580 <?php esc_html_e( 'user(s) will be affected.', 'vigilante' ); ?>
5581 </p>
5582 </div>
5583
5584 <div class="vigilante-password-reset-options" id="vigilante-reset-role-self-option" style="display: none; margin-top: 10px;">
5585 <label>
5586 <input type="checkbox" id="vigilante-reset-role-include-self" value="1">
5587 <?php esc_html_e( 'Include myself (your current session will end)', 'vigilante' ); ?>
5588 </label>
5589 </div>
5590
5591 <p class="submit">
5592 <button type="button" id="vigilante-reset-by-role" class="button button-primary" disabled>
5593 <?php esc_html_e( 'Force Reset for Selected Roles', 'vigilante' ); ?>
5594 </button>
5595 </p>
5596 </div>
5597
5598 <!-- Reset All Users -->
5599 <div class="vigilante-password-reset-box" style="margin-top: 20px; padding-top: 20px; border-top: 1px solid #ddd;">
5600 <h4><?php esc_html_e( 'Reset all users', 'vigilante' ); ?></h4>
5601
5602 <?php
5603 $total_users = count_users();
5604 $total_count = $total_users['total_users'];
5605 ?>
5606 <p>
5607 <?php
5608 printf(
5609 /* translators: %d: Number of users */
5610 esc_html__( 'This will affect %d user(s).', 'vigilante' ),
5611 absint( $total_count )
5612 );
5613 ?>
5614 </p>
5615
5616 <p class="description" style="color: #d63638;">
5617 <span class="dashicons dashicons-warning"></span>
5618 <?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' ); ?>
5619 </p>
5620
5621 <div class="vigilante-password-reset-options" style="margin-top: 10px;">
5622 <label>
5623 <input type="checkbox" id="vigilante-reset-all-include-self" value="1">
5624 <?php esc_html_e( 'Include myself (your current session will end)', 'vigilante' ); ?>
5625 </label>
5626 </div>
5627
5628 <p class="submit">
5629 <button type="button" id="vigilante-reset-all-users" class="button" style="color: #d63638; border-color: #d63638;">
5630 <?php esc_html_e( 'Force Reset for ALL Users', 'vigilante' ); ?>
5631 </button>
5632 </p>
5633 </div>
5634 </div>
5635
5636 <!-- Pending Registrations -->
5637 <?php
5638 // Enforcement-only: this instance exists to read the queue, and the
5639 // flag keeps it from registering the module's own hooks a second
5640 // time. It is not inert, and saying it was would be a false comment:
5641 // init_enforcement_hooks() does add its three filters again, on top
5642 // of the ones already registered. They are idempotent (the same
5643 // methods of an equivalent instance, deciding on the same user meta),
5644 // so running them twice in an admin request changes nothing, which is
5645 // why this is accepted rather than worked around.
5646 $user_security = new Vigilante_User_Security( $this->settings, $this->activity_log, true );
5647 $pending_users = $user_security->get_pending_users();
5648 ?>
5649 <div id="vigilante-section-users-pending" class="vigilante-tool-box vigilante-pending-users-section">
5650 <h3>
5651 <?php esc_html_e( 'Pending registrations', 'vigilante' ); ?>
5652 <?php if ( count( $pending_users ) > 0 ) : ?>
5653 <span class="vigilante-badge vigilante-badge-warning"><?php echo esc_html( count( $pending_users ) ); ?></span>
5654 <?php endif; ?>
5655 </h3>
5656
5657 <?php
5658 /*
5659 * The queue is shown whenever there is somebody in it, even with
5660 * the feature off. Since 2.11.10 an account already waiting stays
5661 * blocked when the feature is switched off, which is the point:
5662 * turning a setting off must not quietly let in people an
5663 * administrator decided not to approve. But hiding the table then
5664 * left them locked out with no button anywhere to approve or
5665 * reject them. Found by the cross review of 2.11.10.
5666 */
5667 ?>
5668 <?php if ( empty( $registration['enabled'] ) && empty( $pending_users ) ) : ?>
5669 <p class="description">
5670 <span class="dashicons dashicons-info" style="color: #72aee6;"></span>
5671 <?php esc_html_e( 'Registration approval is disabled. Enable it in the settings above to require manual approval for new users.', 'vigilante' ); ?>
5672 </p>
5673 <?php elseif ( empty( $pending_users ) ) : ?>
5674 <div class="vigilante-no-lockouts">
5675 <span class="dashicons dashicons-yes-alt"></span>
5676 <p><?php esc_html_e( 'No pending registrations.', 'vigilante' ); ?></p>
5677 </div>
5678 <?php else : ?>
5679 <?php $this->render_user_actions_notice(); ?>
5680 <table class="wp-list-table widefat fixed striped vigilante-pending-users-table">
5681 <thead>
5682 <tr>
5683 <th><?php esc_html_e( 'User', 'vigilante' ); ?></th>
5684 <th><?php esc_html_e( 'Email', 'vigilante' ); ?></th>
5685 <th><?php esc_html_e( 'Registered', 'vigilante' ); ?></th>
5686 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5687 </tr>
5688 </thead>
5689 <tbody>
5690 <?php foreach ( $pending_users as $pending_user ) :
5691 $pending_since = get_user_meta( $pending_user->ID, Vigilante_User_Security::site_user_meta_key( 'vigilante_pending_since' ), true );
5692 ?>
5693 <tr data-user-id="<?php echo esc_attr( $pending_user->ID ); ?>">
5694 <td>
5695 <?php echo get_avatar( $pending_user->ID, 32 ); ?>
5696 <strong><?php echo esc_html( $pending_user->user_login ); ?></strong>
5697 </td>
5698 <td><?php echo esc_html( $pending_user->user_email ); ?></td>
5699 <td>
5700 <?php
5701 if ( $pending_since ) {
5702 /* translators: %s: Time ago */
5703 printf( esc_html__( '%s ago', 'vigilante' ), esc_html( human_time_diff( $pending_since ) ) );
5704 } else {
5705 echo esc_html( $pending_user->user_registered );
5706 }
5707 ?>
5708 </td>
5709 <td>
5710 <button type="button" class="button button-small vigilante-approve-user" data-user-id="<?php echo esc_attr( $pending_user->ID ); ?>" <?php disabled( $this->user_actions_locked() ); ?>>
5711 <?php esc_html_e( 'Approve', 'vigilante' ); ?>
5712 </button>
5713 <button type="button" class="button button-small vigilante-reject-user" data-user-id="<?php echo esc_attr( $pending_user->ID ); ?>" style="color: #d63638;" <?php disabled( $this->user_actions_locked() ); ?>>
5714 <?php esc_html_e( 'Reject', 'vigilante' ); ?>
5715 </button>
5716 </td>
5717 </tr>
5718 <?php endforeach; ?>
5719 </tbody>
5720 </table>
5721 <?php endif; ?>
5722 </div>
5723
5724 <!-- Active Sessions Management -->
5725 <div class="vigilante-tool-box vigilante-session-management-section">
5726 <h3><?php esc_html_e( 'Active sessions', 'vigilante' ); ?></h3>
5727 <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>
5728
5729 <!-- Current user sessions -->
5730 <h4><?php esc_html_e( 'Your sessions', 'vigilante' ); ?></h4>
5731 <?php
5732 $current_user_id = get_current_user_id();
5733 $my_sessions = $user_security->get_user_sessions( $current_user_id );
5734 $has_corrupted = $user_security->has_corrupted_sessions( $current_user_id );
5735 $raw_count = $user_security->get_raw_session_count( $current_user_id );
5736 ?>
5737
5738 <?php if ( $has_corrupted && $raw_count > 0 ) : ?>
5739 <div class="notice notice-warning inline" style="margin: 10px 0;">
5740 <p>
5741 <span class="dashicons dashicons-warning" style="color: #dba617;"></span>
5742 <?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' ); ?>
5743 </p>
5744 </div>
5745 <?php endif; ?>
5746
5747 <?php if ( empty( $my_sessions ) ) : ?>
5748 <p class="description"><?php esc_html_e( 'No active sessions found.', 'vigilante' ); ?></p>
5749 <?php if ( $has_corrupted ) : ?>
5750 <p style="margin-top: 10px;">
5751 <button type="button" class="button vigilante-revoke-other-sessions" data-user-id="<?php echo esc_attr( $current_user_id ); ?>">
5752 <?php esc_html_e( 'Clean Up Corrupted Sessions', 'vigilante' ); ?>
5753 </button>
5754 </p>
5755 <?php endif; ?>
5756 <?php else : ?>
5757 <div class="vigilante-paginated-section">
5758 <div class="vigilante-fi-pagination-wrap"></div>
5759 <table class="wp-list-table widefat fixed striped vigilante-sessions-table vigilante-fi-paginated">
5760 <thead>
5761 <tr>
5762 <th><?php esc_html_e( 'Browser', 'vigilante' ); ?></th>
5763 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
5764 <th><?php esc_html_e( 'Login Time', 'vigilante' ); ?></th>
5765 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5766 </tr>
5767 </thead>
5768 <tbody>
5769 <?php foreach ( $my_sessions as $session ) : ?>
5770 <tr data-token="<?php echo esc_attr( $session['token_hash'] ); ?>">
5771 <td><?php echo esc_html( $session['browser'] ); ?></td>
5772 <td><code><?php echo esc_html( $session['ip'] ); ?></code></td>
5773 <td>
5774 <?php
5775 if ( $session['login'] ) {
5776 /* translators: %s: Time ago */
5777 printf( esc_html__( '%s ago', 'vigilante' ), esc_html( human_time_diff( $session['login'] ) ) );
5778 } else {
5779 esc_html_e( 'Unknown', 'vigilante' );
5780 }
5781 ?>
5782 </td>
5783 <td>
5784 <?php if ( ! $session['is_current'] ) : ?>
5785 <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'] ); ?>">
5786 <?php esc_html_e( 'Revoke', 'vigilante' ); ?>
5787 </button>
5788 <?php else : ?>
5789 <span class="description"><?php esc_html_e( 'Current session', 'vigilante' ); ?></span>
5790 <?php endif; ?>
5791 </td>
5792 </tr>
5793 <?php endforeach; ?>
5794 </tbody>
5795 </table>
5796 </div>
5797
5798 <?php if ( count( $my_sessions ) > 1 || $has_corrupted ) : ?>
5799 <p style="margin-top: 10px;">
5800 <button type="button" class="button vigilante-revoke-other-sessions" data-user-id="<?php echo esc_attr( $current_user_id ); ?>">
5801 <?php esc_html_e( 'Revoke All Other Sessions', 'vigilante' ); ?>
5802 </button>
5803 </p>
5804 <?php endif; ?>
5805 <?php endif; ?>
5806
5807 <!-- Search user sessions (admin only) -->
5808 <h4 style="margin-top: 30px;"><?php esc_html_e( 'Manage user sessions', 'vigilante' ); ?></h4>
5809 <p class="description"><?php esc_html_e( 'Search for a user to view and manage their sessions.', 'vigilante' ); ?></p>
5810
5811 <div class="vigilante-user-search-wrapper" style="margin-top: 10px;">
5812 <input type="text" id="vigilante-session-user-search" class="regular-text" placeholder="<?php esc_attr_e( 'Search by username or email...', 'vigilante' ); ?>">
5813 <div id="vigilante-session-search-results" class="vigilante-user-search-results" style="display: none;"></div>
5814 </div>
5815
5816 <div id="vigilante-user-sessions-container" style="display: none; margin-top: 20px;">
5817 <h4 id="vigilante-sessions-user-name"></h4>
5818 <table class="wp-list-table widefat fixed striped vigilante-sessions-table">
5819 <thead>
5820 <tr>
5821 <th><?php esc_html_e( 'Browser', 'vigilante' ); ?></th>
5822 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
5823 <th><?php esc_html_e( 'Login Time', 'vigilante' ); ?></th>
5824 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5825 </tr>
5826 </thead>
5827 <tbody id="vigilante-user-sessions-list">
5828 </tbody>
5829 </table>
5830 <p style="margin-top: 10px;">
5831 <button type="button" class="button vigilante-revoke-all-user-sessions" style="color: #d63638;">
5832 <?php esc_html_e( 'Revoke All Sessions', 'vigilante' ); ?>
5833 </button>
5834 </p>
5835 </div>
5836 </div>
5837
5838 <?php endif; ?>
5839 </div>
5840 <?php
5841 }
5842
5843 /**
5844 * Render WordPress Hardening tab
5845 */
5846 private function render_tab_wp_hardening() {
5847 $is_disabled = $this->render_module_disabled_notice( 'wp_hardening' );
5848 $options = $this->settings->get_section( 'wp_hardening' );
5849 ?>
5850 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="wp_hardening" <?php echo $is_disabled ? 'inert' : ''; ?>>
5851 <!-- Database Hardening (outside form save flow - uses its own AJAX action) -->
5852 <?php $vg_shared_locked = $this->shared_files_locked(); ?>
5853 <?php $this->render_shared_files_notice(); ?>
5854 <div id="vigilante-section-hardening-database" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
5855 <h2>
5856 <?php esc_html_e( 'Database Hardening', 'vigilante' ); ?>
5857 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
5858 <span class="vigilante-method-badge config"><?php esc_html_e( 'WP-CONFIG', 'vigilante' ); ?></span>
5859 </h2>
5860 <p><?php esc_html_e( 'Change the database table prefix to prevent SQL injection attacks that target default WordPress tables.', 'vigilante' ); ?></p>
5861
5862 <?php
5863 $db_prefix = new Vigilante_Database_Prefix();
5864 $current_prefix = $db_prefix->get_current_prefix();
5865 $is_default = $db_prefix->is_default_prefix();
5866 ?>
5867
5868 <?php if ( is_multisite() && ! $vg_shared_locked ) : ?>
5869 <div class="notice notice-warning inline" style="margin:10px 0 16px;padding:8px 12px;">
5870 <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>
5871 </div>
5872 <?php endif; ?>
5873
5874 <table class="form-table">
5875 <tr>
5876 <th scope="row"><?php esc_html_e( 'Current prefix', 'vigilante' ); ?></th>
5877 <td>
5878 <code class="vigilante-db-current-prefix"><?php echo esc_html( $current_prefix ); ?></code>
5879 <?php if ( $is_default ) : ?>
5880 <span class="vigilante-inline-warning">
5881 <span class="dashicons dashicons-warning"></span>
5882 <?php esc_html_e( 'Default prefix detected. Changing it adds a layer of protection against automated SQL injection attacks.', 'vigilante' ); ?>
5883 </span>
5884 <?php else : ?>
5885 <span class="vigilante-inline-ok">
5886 <span class="dashicons dashicons-yes-alt"></span>
5887 <?php esc_html_e( 'Custom prefix in use.', 'vigilante' ); ?>
5888 </span>
5889 <?php endif; ?>
5890 </td>
5891 </tr>
5892 <tr>
5893 <th scope="row"><?php esc_html_e( 'New prefix', 'vigilante' ); ?></th>
5894 <td>
5895 <div class="vigilante-db-prefix-row">
5896 <code class="vigilante-db-new-prefix" id="vigilante-new-prefix"><?php echo esc_html( $db_prefix->generate_prefix() ); ?></code>
5897 <button type="button" class="button button-small vigilante-db-regenerate-prefix" title="<?php esc_attr_e( 'Generate new prefix', 'vigilante' ); ?>">
5898 <span class="dashicons dashicons-update"></span>
5899 </button>
5900 </div>
5901 </td>
5902 </tr>
5903 <tr>
5904 <th scope="row"></th>
5905 <td>
5906 <div class="vigilante-db-prefix-confirm">
5907 <label>
5908 <input type="checkbox" id="vigilante-prefix-backup-confirm">
5909 <?php esc_html_e( 'I understand this operation is irreversible and I have a current database backup', 'vigilante' ); ?>
5910 </label>
5911 <p class="description">
5912 <?php
5913 printf(
5914 /* translators: %s: Link to tools tab */
5915 esc_html__( 'Need a backup? %s first.', 'vigilante' ),
5916 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Download a database backup', 'vigilante' ) . '</a>'
5917 );
5918 ?>
5919 </p>
5920 </div>
5921 <button type="button" class="button button-primary vigilante-db-change-prefix" disabled data-original-text="<?php esc_attr_e( 'Change Database Prefix', 'vigilante' ); ?>">
5922 <?php esc_html_e( 'Change Database Prefix', 'vigilante' ); ?>
5923 </button>
5924 </td>
5925 </tr>
5926 </table>
5927 </div>
5928
5929 <!-- wp-config Security -->
5930 <?php
5931 $vg_shared_locked = $this->shared_files_locked();
5932 // Paint what is actually in force, not this site's unused copy.
5933 $vg_local_options = $options;
5934 $options = $this->get_section_for_display( 'wp_hardening' );
5935 ?>
5936 <?php $this->render_shared_files_notice(); ?>
5937 <div id="vigilante-section-hardening-wpconfig" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
5938 <h2>
5939 <?php esc_html_e( 'wp-config.php Security', 'vigilante' ); ?>
5940 <span class="vigilante-method-badge config"><?php esc_html_e( 'WP-CONFIG', 'vigilante' ); ?></span>
5941 </h2>
5942 <p><?php esc_html_e( 'Security constants added directly to wp-config.php file.', 'vigilante' ); ?></p>
5943
5944 <table class="form-table">
5945 <tr>
5946 <th scope="row"><?php esc_html_e( 'Disable File Editor', 'vigilante' ); ?></th>
5947 <td>
5948 <label>
5949 <input type="checkbox" name="wp_hardening[disallow_file_edit]" value="1" <?php checked( ! empty( $options['disallow_file_edit'] ) ); ?>>
5950 <?php esc_html_e( 'Disable plugin and theme editor in admin (DISALLOW_FILE_EDIT)', 'vigilante' ); ?>
5951 </label>
5952 </td>
5953 </tr>
5954 <tr>
5955 <th scope="row"><?php esc_html_e( 'Disable File Modifications', 'vigilante' ); ?></th>
5956 <td>
5957 <label>
5958 <input type="checkbox" name="wp_hardening[disallow_file_mods]" value="1" <?php checked( ! empty( $options['disallow_file_mods'] ) ); ?>>
5959 <?php esc_html_e( 'Disable all file modifications including updates (DISALLOW_FILE_MODS)', 'vigilante' ); ?>
5960 </label>
5961 <p class="description"><?php esc_html_e( '&#9888; Warning: This prevents automatic updates.', 'vigilante' ); ?></p>
5962 </td>
5963 </tr>
5964 <tr id="field-force-ssl-admin">
5965 <th scope="row"><?php esc_html_e( 'Force SSL Admin', 'vigilante' ); ?></th>
5966 <td>
5967 <label>
5968 <input type="checkbox" name="wp_hardening[force_ssl_admin]" value="1" <?php checked( ! empty( $options['force_ssl_admin'] ) ); ?>>
5969 <?php esc_html_e( 'Force HTTPS for admin area (FORCE_SSL_ADMIN)', 'vigilante' ); ?>
5970 </label>
5971 <p class="description"><?php esc_html_e( '&#9888; Warning: Only enable if your site fully supports HTTPS.', 'vigilante' ); ?></p>
5972 </td>
5973 </tr>
5974 <tr id="field-wp-debug">
5975 <th scope="row"><?php esc_html_e( 'Hide PHP errors from visitors', 'vigilante' ); ?></th>
5976 <td>
5977 <label>
5978 <input type="checkbox" name="wp_hardening[wp_debug]" value="1" <?php checked( ! empty( $options['wp_debug'] ) ); ?>>
5979 <?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' ); ?>
5980 </label>
5981 </td>
5982 </tr>
5983 <tr id="field-disable-wp-cron">
5984 <th scope="row"><?php esc_html_e( 'Disable WP Cron', 'vigilante' ); ?></th>
5985 <td>
5986 <label>
5987 <input type="checkbox" name="wp_hardening[disable_wp_cron]" value="1" <?php checked( ! empty( $options['disable_wp_cron'] ) ); ?>>
5988 <?php esc_html_e( 'Disable WordPress\'s page-view cron trigger (DISABLE_WP_CRON)', 'vigilante' ); ?>
5989 </label>
5990 <p class="description"><?php
5991 printf(
5992 /* translators: 1: opening <strong>, 2: closing </strong>, 3: opening <code>, 4: closing </code> */
5993 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' ),
5994 '<strong>',
5995 '</strong>',
5996 '<code>',
5997 '</code>'
5998 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
5999 ?></p>
6000 </td>
6001 </tr>
6002 </table>
6003 </div>
6004 <?php $options = $vg_local_options; ?>
6005
6006 <!-- Comment Security -->
6007 <div id="vigilante-section-hardening-xmlrpc" class="vigilante-settings-section">
6008 <h2>
6009 <?php esc_html_e( 'XML-RPC', 'vigilante' ); ?>
6010 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
6011 </h2>
6012 <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>
6013
6014 <table class="form-table">
6015 <tr id="field-disable-xmlrpc">
6016 <th scope="row"><label for="vigilante-f-wp-hardening-xmlrpc-mode"><?php esc_html_e( 'XML-RPC access', 'vigilante' ); ?></label></th>
6017 <td>
6018 <?php $vig_xmlrpc_mode = Vigilante_Comment_Security::resolve_xmlrpc_mode( $this->settings ); ?>
6019 <select id="vigilante-f-wp-hardening-xmlrpc-mode" name="wp_hardening[xmlrpc_mode]">
6020 <option value="none" <?php selected( $vig_xmlrpc_mode, 'none' ); ?>>
6021 <?php esc_html_e( 'Leave XML-RPC enabled', 'vigilante' ); ?>
6022 </option>
6023 <option value="pingback" <?php selected( $vig_xmlrpc_mode, 'pingback' ); ?>>
6024 <?php esc_html_e( 'Block the pingback methods only', 'vigilante' ); ?>
6025 </option>
6026 <option value="full" <?php selected( $vig_xmlrpc_mode, 'full' ); ?>>
6027 <?php esc_html_e( 'Disable XML-RPC completely (recommended)', 'vigilante' ); ?>
6028 </option>
6029 </select>
6030 <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>
6031 </td>
6032 </tr>
6033 </table>
6034 </div>
6035
6036 <div id="vigilante-section-hardening-comments" class="vigilante-settings-section">
6037 <h2>
6038 <?php esc_html_e( 'Comment Security', 'vigilante' ); ?>
6039 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
6040 <span class="vigilante-method-badge settings"><?php esc_html_e( 'Settings', 'vigilante' ); ?></span>
6041 </h2>
6042 <p><?php esc_html_e( 'Comment protection using WordPress settings and PHP hooks.', 'vigilante' ); ?></p>
6043
6044 <table class="form-table">
6045 <tr>
6046 <th scope="row"><?php esc_html_e( 'Disable Pingbacks', 'vigilante' ); ?></th>
6047 <td>
6048 <label>
6049 <input type="checkbox" name="wp_hardening[disable_pingbacks]" value="1" <?php checked( ! empty( $options['disable_pingbacks'] ) ); ?>>
6050 <?php esc_html_e( 'Disable pingbacks (commonly exploited for DDoS)', 'vigilante' ); ?>
6051 </label>
6052 </td>
6053 </tr>
6054 <tr>
6055 <th scope="row"><?php esc_html_e( 'Disable Trackbacks', 'vigilante' ); ?></th>
6056 <td>
6057 <label>
6058 <input type="checkbox" name="wp_hardening[disable_trackbacks]" value="1" <?php checked( ! empty( $options['disable_trackbacks'] ) ); ?>>
6059 <?php esc_html_e( 'Disable trackbacks (rarely used legitimately)', 'vigilante' ); ?>
6060 </label>
6061 </td>
6062 </tr>
6063 <tr>
6064 <th scope="row"><?php esc_html_e( 'Require Moderation', 'vigilante' ); ?></th>
6065 <td>
6066 <label>
6067 <input type="checkbox" name="wp_hardening[require_comment_moderation]" value="1" <?php checked( ! empty( $options['require_comment_moderation'] ) ); ?>>
6068 <?php esc_html_e( 'All comments must be manually approved', 'vigilante' ); ?>
6069 </label>
6070 </td>
6071 </tr>
6072 <tr>
6073 <th scope="row"><?php esc_html_e( 'Close Old Comments', 'vigilante' ); ?></th>
6074 <td>
6075 <label>
6076 <input type="checkbox" name="wp_hardening[close_old_comments]" value="1" <?php checked( ! empty( $options['close_old_comments'] ) ); ?>>
6077 <?php esc_html_e( 'Automatically close comments on old posts after', 'vigilante' ); ?>
6078 </label>
6079 <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">
6080 <label for="vigilante-f-wp-hardening-close-comments-after-days"><?php esc_html_e( 'days', 'vigilante' ); ?></label>
6081 </td>
6082 </tr>
6083 <tr>
6084 <th scope="row"><?php esc_html_e( 'Honeypot Protection', 'vigilante' ); ?></th>
6085 <td>
6086 <label>
6087 <input type="checkbox" name="wp_hardening[honeypot_comments]" value="1" <?php checked( ! empty( $options['honeypot_comments'] ) ); ?>>
6088 <?php esc_html_e( 'Add hidden honeypot field to catch bots', 'vigilante' ); ?>
6089 </label>
6090 </td>
6091 </tr>
6092 </table>
6093 </div>
6094
6095 <!-- Head Cleaner -->
6096 <div id="vigilante-section-hardening-headers" class="vigilante-settings-section">
6097 <h2>
6098 <?php esc_html_e( 'Header Cleanup', 'vigilante' ); ?>
6099 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
6100 </h2>
6101 <p><?php esc_html_e( 'Remove meta tags from HTML head.', 'vigilante' ); ?></p>
6102
6103 <table class="form-table">
6104 <tr>
6105 <th scope="row"><?php esc_html_e( 'Remove Generator', 'vigilante' ); ?></th>
6106 <td>
6107 <label>
6108 <input type="checkbox" name="wp_hardening[remove_wp_generator]" value="1" <?php checked( ! empty( $options['remove_wp_generator'] ) ); ?>>
6109 <?php esc_html_e( 'Remove WordPress version from HTML head', 'vigilante' ); ?>
6110 </label>
6111 </td>
6112 </tr>
6113 <tr id="field-remove-wp-version-assets">
6114 <th scope="row"><?php esc_html_e( 'Remove version from assets', 'vigilante' ); ?></th>
6115 <td>
6116 <label>
6117 <input type="checkbox" name="wp_hardening[remove_wp_version_assets]" value="1" <?php checked( ! empty( $options['remove_wp_version_assets'] ) ); ?>>
6118 <?php esc_html_e( 'Remove WordPress version from script/style URLs (?ver=)', 'vigilante' ); ?>
6119 </label>
6120 <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>
6121 </td>
6122 </tr>
6123 <tr>
6124 <th scope="row"><?php esc_html_e( 'Remove RSD Link', 'vigilante' ); ?></th>
6125 <td>
6126 <label>
6127 <input type="checkbox" name="wp_hardening[remove_rsd_link]" value="1" <?php checked( ! empty( $options['remove_rsd_link'] ) ); ?>>
6128 <?php esc_html_e( 'Remove Really Simple Discovery link', 'vigilante' ); ?>
6129 </label>
6130 </td>
6131 </tr>
6132 <tr>
6133 <th scope="row"><?php esc_html_e( 'Remove WLW Manifest', 'vigilante' ); ?></th>
6134 <td>
6135 <label>
6136 <input type="checkbox" name="wp_hardening[remove_wlw_manifest]" value="1" <?php checked( ! empty( $options['remove_wlw_manifest'] ) ); ?>>
6137 <?php esc_html_e( 'Remove Windows Live Writer manifest link', 'vigilante' ); ?>
6138 </label>
6139 </td>
6140 </tr>
6141 <tr>
6142 <th scope="row"><?php esc_html_e( 'Remove Shortlink', 'vigilante' ); ?></th>
6143 <td>
6144 <label>
6145 <input type="checkbox" name="wp_hardening[remove_shortlink]" value="1" <?php checked( ! empty( $options['remove_shortlink'] ) ); ?>>
6146 <?php esc_html_e( 'Remove shortlink tag from header', 'vigilante' ); ?>
6147 </label>
6148 </td>
6149 </tr>
6150 <tr>
6151 <th scope="row"><?php esc_html_e( 'Remove REST API Link', 'vigilante' ); ?></th>
6152 <td>
6153 <label>
6154 <input type="checkbox" name="wp_hardening[remove_rest_api_link]" value="1" <?php checked( ! empty( $options['remove_rest_api_link'] ) ); ?>>
6155 <?php esc_html_e( 'Remove REST API discovery link from header', 'vigilante' ); ?>
6156 </label>
6157 <p class="description"><?php esc_html_e( '&#9888; Notice: Some plugins may need this link.', 'vigilante' ); ?></p>
6158 </td>
6159 </tr>
6160 </table>
6161 </div>
6162
6163 <!-- Feed Manager -->
6164 <div id="vigilante-section-hardening-rss" class="vigilante-settings-section">
6165 <h2>
6166 <?php esc_html_e( 'RSS Feed Settings', 'vigilante' ); ?>
6167 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
6168 </h2>
6169 <p><?php esc_html_e( 'Control RSS/Atom feeds.', 'vigilante' ); ?></p>
6170
6171 <table class="form-table">
6172 <tr>
6173 <th scope="row"><?php esc_html_e( 'Disable Feeds', 'vigilante' ); ?></th>
6174 <td>
6175 <label>
6176 <input type="checkbox" name="wp_hardening[disable_feeds]" value="1" <?php checked( ! empty( $options['disable_feeds'] ) ); ?>>
6177 <?php esc_html_e( 'Completely disable RSS/Atom feeds', 'vigilante' ); ?>
6178 </label>
6179 </td>
6180 </tr>
6181 <tr>
6182 <th scope="row"><?php esc_html_e( 'Disable If No Content', 'vigilante' ); ?></th>
6183 <td>
6184 <label>
6185 <input type="checkbox" name="wp_hardening[disable_if_no_content]" value="1" <?php checked( ! empty( $options['disable_if_no_content'] ) ); ?>>
6186 <?php esc_html_e( 'Only disable feeds if site has no published posts', 'vigilante' ); ?>
6187 </label>
6188 </td>
6189 </tr>
6190 <tr>
6191 <th scope="row"><?php esc_html_e( 'Remove Feed Version', 'vigilante' ); ?></th>
6192 <td>
6193 <label>
6194 <input type="checkbox" name="wp_hardening[remove_feed_version]" value="1" <?php checked( ! empty( $options['remove_feed_version'] ) ); ?>>
6195 <?php esc_html_e( 'Remove WordPress version from feed generator tag', 'vigilante' ); ?>
6196 </label>
6197 </td>
6198 </tr>
6199 </table>
6200 </div>
6201
6202 <p class="submit vigilante-submit-buttons">
6203 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
6204 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
6205 </button>
6206 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
6207 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
6208 </button>
6209 </p>
6210 </form>
6211 <?php
6212 }
6213
6214 /**
6215 * Render activity log tab
6216 */
6217 private function render_tab_activity_log() {
6218 $is_disabled = $this->render_module_disabled_notice( 'activity_log' );
6219 $options = $this->settings->get_section( 'activity_log' );
6220 ?>
6221 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="activity_log" <?php echo $is_disabled ? 'inert' : ''; ?>>
6222 <div id="vigilante-section-audit-settings" class="vigilante-settings-section">
6223 <h2>
6224 <?php esc_html_e( 'Security Audit Settings', 'vigilante' ); ?>
6225 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
6226 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
6227 </h2>
6228 <p><?php esc_html_e( 'Security event logging and auditing.', 'vigilante' ); ?></p>
6229
6230 <table class="form-table">
6231 <tr>
6232 <th scope="row"><?php esc_html_e( 'Retention', 'vigilante' ); ?></th>
6233 <td>
6234 <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">
6235 <label for="vigilante-f-activity-log-retention-days"><?php esc_html_e( 'days', 'vigilante' ); ?></label>
6236 &nbsp;&nbsp;
6237 <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">
6238 <label for="vigilante-f-activity-log-max-entries"><?php esc_html_e( 'max entries', 'vigilante' ); ?></label>
6239 <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>
6240 </td>
6241 </tr>
6242 <tr>
6243 <th scope="row"><?php esc_html_e( 'Events to Log', 'vigilante' ); ?></th>
6244 <td>
6245 <fieldset style="display:grid; grid-template-columns:repeat(auto-fit, minmax(240px, 1fr)); gap:6px 24px; max-width:600px;">
6246 <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>
6247 <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>
6248 <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>
6249 <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>
6250 <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>
6251 <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>
6252 <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>
6253 <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>
6254 <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>
6255 <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>
6256 </fieldset>
6257 <div class="notice notice-info inline" style="margin:10px 0 0;padding:8px 12px;">
6258 <p style="margin:0;">
6259 <?php esc_html_e( 'Firewall blocks, security events, and Vigilant settings changes are always logged regardless of the above selections.', 'vigilante' ); ?>
6260 </p>
6261 </div>
6262 </td>
6263 </tr>
6264 <tr>
6265 <th scope="row"><label for="vigilante-f-activity-log-tracked-options"><?php esc_html_e( 'Option Tracking', 'vigilante' ); ?></label></th>
6266 <td>
6267 <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>
6268 <br>
6269 <label><?php esc_html_e( 'Additional options to track:', 'vigilante' ); ?></label><br>
6270 <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>
6271 <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>
6272 </td>
6273 </tr>
6274 <tr>
6275 <th scope="row"><?php esc_html_e( 'Exclusions', 'vigilante' ); ?></th>
6276 <td>
6277 <div style="display:grid; grid-template-columns:repeat(auto-fit, minmax(220px, 1fr)); gap:16px; max-width:600px;">
6278 <div>
6279 <label for="vigilante-f-activity-log-excluded-users"><?php esc_html_e( 'Excluded user IDs:', 'vigilante' ); ?></label><br>
6280 <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>
6281 <p class="description"><?php esc_html_e( 'One user ID per line. Actions by these users will not be logged.', 'vigilante' ); ?></p>
6282 </div>
6283 <div>
6284 <label for="vigilante-f-activity-log-excluded-ips"><?php esc_html_e( 'Excluded IPs:', 'vigilante' ); ?></label><br>
6285 <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>
6286 <p class="description"><?php esc_html_e( 'One IP per line. Requests from these IPs will not be logged.', 'vigilante' ); ?></p>
6287 </div>
6288 </div>
6289 </td>
6290 </tr>
6291 </table>
6292 </div>
6293
6294 <p class="submit vigilante-submit-buttons">
6295 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
6296 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
6297 </button>
6298 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
6299 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
6300 </button>
6301 </p>
6302 </form>
6303
6304 <?php
6305 // Audit Alerts — alerting layer on top of Security Audit. Its own
6306 // settings section and form, rendered right after the logging settings
6307 // so the tab reads as "log this, exclude that, and alert me about this".
6308 $alerts = $this->settings->get_section( 'audit_alerts' );
6309 $immediate = isset( $alerts['immediate'] ) ? $alerts['immediate'] : array();
6310 $threshold = isset( $alerts['threshold'] ) ? $alerts['threshold'] : array();
6311 $alert_severity = isset( $immediate['min_severity'] ) ? $immediate['min_severity'] : 'critical';
6312 $alert_window = isset( $threshold['window'] ) ? $threshold['window'] : '1h';
6313 $threshold_cats = isset( $threshold['categories'] ) ? (array) $threshold['categories'] : array();
6314 $cat_labels = Vigilante_Audit_Alerts::category_labels();
6315 ?>
6316 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="audit_alerts" <?php echo $is_disabled ? 'inert' : ''; ?>>
6317 <div id="vigilante-section-audit-alerts" class="vigilante-settings-section">
6318 <h2>
6319 <?php esc_html_e( 'Audit Alerts', 'vigilante' ); ?>
6320 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
6321 </h2>
6322 <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>
6323
6324 <table class="form-table">
6325 <tr id="field-audit-alerts-immediate">
6326 <th scope="row"><?php esc_html_e( 'Immediate alerts', 'vigilante' ); ?></th>
6327 <td>
6328 <label>
6329 <input type="checkbox" name="audit_alerts[immediate][enabled]" value="1" <?php checked( ! empty( $immediate['enabled'] ) ); ?>>
6330 <?php esc_html_e( 'Email me as soon as a serious event is logged', 'vigilante' ); ?>
6331 </label>
6332 <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>
6333 </td>
6334 </tr>
6335 <tr>
6336 <th scope="row"><label for="vigilante-f-audit-alerts-immediate-min-severity"><?php esc_html_e( 'Alert on severity', 'vigilante' ); ?></label></th>
6337 <td>
6338 <select id="vigilante-f-audit-alerts-immediate-min-severity" name="audit_alerts[immediate][min_severity]">
6339 <option value="critical" <?php selected( $alert_severity, 'critical' ); ?>><?php esc_html_e( 'Critical only (recommended)', 'vigilante' ); ?></option>
6340 <option value="warning" <?php selected( $alert_severity, 'warning' ); ?>><?php esc_html_e( 'Warning and Critical', 'vigilante' ); ?></option>
6341 </select>
6342 <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>
6343 </td>
6344 </tr>
6345 <tr id="field-audit-alerts-threshold">
6346 <th scope="row"><?php esc_html_e( 'Threshold alerts', 'vigilante' ); ?></th>
6347 <td>
6348 <label>
6349 <input type="checkbox" name="audit_alerts[threshold][enabled]" value="1" <?php checked( ! empty( $threshold['enabled'] ) ); ?>>
6350 <?php esc_html_e( 'Email me when a category spikes within a time window', 'vigilante' ); ?>
6351 </label>
6352 <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>
6353 </td>
6354 </tr>
6355 <tr>
6356 <th scope="row"><label for="vigilante-f-audit-alerts-threshold-window"><?php esc_html_e( 'Time window', 'vigilante' ); ?></label></th>
6357 <td>
6358 <select id="vigilante-f-audit-alerts-threshold-window" name="audit_alerts[threshold][window]">
6359 <option value="30m" <?php selected( $alert_window, '30m' ); ?>><?php esc_html_e( '30 minutes', 'vigilante' ); ?></option>
6360 <option value="1h" <?php selected( $alert_window, '1h' ); ?>><?php esc_html_e( '1 hour', 'vigilante' ); ?></option>
6361 <option value="6h" <?php selected( $alert_window, '6h' ); ?>><?php esc_html_e( '6 hours', 'vigilante' ); ?></option>
6362 <option value="24h" <?php selected( $alert_window, '24h' ); ?>><?php esc_html_e( '24 hours', 'vigilante' ); ?></option>
6363 </select>
6364 <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>
6365 </td>
6366 </tr>
6367 <tr>
6368 <th scope="row"><?php esc_html_e( 'Thresholds per category', 'vigilante' ); ?></th>
6369 <td>
6370 <fieldset style="display:grid; grid-template-columns:repeat(auto-fit, minmax(200px, 1fr)); gap:8px 24px; max-width:760px;">
6371 <?php
6372 foreach ( $cat_labels as $cat_slug => $cat_label ) :
6373 $cat_value = isset( $threshold_cats[ $cat_slug ] ) ? (int) $threshold_cats[ $cat_slug ] : 0;
6374 ?>
6375 <label style="display:flex;align-items:center;gap:8px;justify-content:space-between;">
6376 <span><?php echo esc_html( $cat_label ); ?></span>
6377 <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">
6378 </label>
6379 <?php endforeach; ?>
6380 </fieldset>
6381 <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>
6382 </td>
6383 </tr>
6384 <tr>
6385 <th scope="row"><?php esc_html_e( "Don't repeat alerts", 'vigilante' ); ?></th>
6386 <td>
6387 <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">
6388 <label for="vigilante-f-audit-alerts-cooldown-minutes"><?php esc_html_e( 'minutes', 'vigilante' ); ?></label>
6389 <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>
6390 </td>
6391 </tr>
6392
6393 <tr>
6394 <th scope="row"><?php esc_html_e( 'Recipients', 'vigilante' ); ?></th>
6395 <td>
6396 <p class="description" style="margin-top:0;">
6397 <?php
6398 printf(
6399 /* translators: %s: Link to notification settings */
6400 esc_html__( 'Alerts go to the recipients configured in %s.', 'vigilante' ),
6401 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
6402 );
6403 ?>
6404 </p>
6405 <p style="margin:8px 0 0;">
6406 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
6407 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
6408 </button>
6409 <span class="vigilante-test-email-result" style="margin-left:8px;"></span>
6410 </p>
6411 <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>
6412 </td>
6413 </tr>
6414 </table>
6415 </div>
6416
6417 <p class="submit vigilante-submit-buttons">
6418 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
6419 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
6420 </button>
6421 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
6422 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
6423 </button>
6424 </p>
6425 </form>
6426
6427 <div id="vigilante-section-audit-recent" class="vigilante-settings-section">
6428 <h2><?php esc_html_e( 'Recent Activity', 'vigilante' ); ?></h2>
6429
6430 <?php
6431 $logs = $this->activity_log->get_logs( array( 'per_page' => 20 ) );
6432 $total_logs = $this->activity_log->get_logs_count();
6433
6434 // Label maps for translated display
6435 $type_labels = array(
6436 'login' => __( 'Login', 'vigilante' ),
6437 'user' => __( 'User', 'vigilante' ),
6438 'content' => __( 'Content', 'vigilante' ),
6439 'plugin' => __( 'Plugin', 'vigilante' ),
6440 'theme' => __( 'Theme', 'vigilante' ),
6441 'settings' => __( 'Settings', 'vigilante' ),
6442 'comment' => __( 'Comment', 'vigilante' ),
6443 'media' => __( 'Media', 'vigilante' ),
6444 'firewall' => __( 'Firewall', 'vigilante' ),
6445 'file' => __( 'File', 'vigilante' ),
6446 'security' => __( 'Security', 'vigilante' ),
6447 'system' => __( 'System', 'vigilante' ),
6448 );
6449 $severity_labels = array(
6450 'info' => __( 'Info', 'vigilante' ),
6451 'warning' => __( 'Warning', 'vigilante' ),
6452 'critical' => __( 'Critical', 'vigilante' ),
6453 );
6454
6455 $firewall_options = $this->settings->get_section( 'firewall' );
6456 $ip_whitelist = $firewall_options['ip_whitelist'] ?? array();
6457 $ip_blacklist = $firewall_options['ip_blacklist'] ?? array();
6458 $ua_whitelist = $firewall_options['ua_whitelist'] ?? array();
6459 $ua_blacklist = $firewall_options['ua_blacklist'] ?? array();
6460 ?>
6461
6462 <div class="vigilante-log-filters">
6463 <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">
6464 <select id="vigilante-log-type-filter" aria-label="<?php esc_attr_e( 'Filter the log by event type', 'vigilante' ); ?>">
6465 <option value=""><?php esc_html_e( 'All Types', 'vigilante' ); ?></option>
6466 <option value="login"><?php esc_html_e( 'Login', 'vigilante' ); ?></option>
6467 <option value="user"><?php esc_html_e( 'User', 'vigilante' ); ?></option>
6468 <option value="content"><?php esc_html_e( 'Content', 'vigilante' ); ?></option>
6469 <option value="plugin"><?php esc_html_e( 'Plugin', 'vigilante' ); ?></option>
6470 <option value="theme"><?php esc_html_e( 'Theme', 'vigilante' ); ?></option>
6471 <option value="settings"><?php esc_html_e( 'Settings', 'vigilante' ); ?></option>
6472 <option value="comment"><?php esc_html_e( 'Comment', 'vigilante' ); ?></option>
6473 <option value="media"><?php esc_html_e( 'Media', 'vigilante' ); ?></option>
6474 <option value="firewall"><?php esc_html_e( 'Firewall', 'vigilante' ); ?></option>
6475 <option value="file"><?php esc_html_e( 'File', 'vigilante' ); ?></option>
6476 <option value="security"><?php esc_html_e( 'Security', 'vigilante' ); ?></option>
6477 <option value="system"><?php esc_html_e( 'System', 'vigilante' ); ?></option>
6478 </select>
6479 <select id="vigilante-log-severity-filter" aria-label="<?php esc_attr_e( 'Filter the log by severity', 'vigilante' ); ?>">
6480 <option value=""><?php esc_html_e( 'All Severities', 'vigilante' ); ?></option>
6481 <option value="info"><?php esc_html_e( 'Info', 'vigilante' ); ?></option>
6482 <option value="warning"><?php esc_html_e( 'Warning', 'vigilante' ); ?></option>
6483 <option value="critical"><?php esc_html_e( 'Critical', 'vigilante' ); ?></option>
6484 </select>
6485 <select id="vigilante-log-method-filter" aria-label="<?php esc_attr_e( 'Filter the log by HTTP method', 'vigilante' ); ?>">
6486 <option value=""><?php esc_html_e( 'All Methods', 'vigilante' ); ?></option>
6487 <option value="GET">GET</option>
6488 <option value="POST">POST</option>
6489 <option value="PUT">PUT</option>
6490 <option value="DELETE">DELETE</option>
6491 <option value="PATCH">PATCH</option>
6492 <option value="OPTIONS">OPTIONS</option>
6493 <option value="HEAD">HEAD</option>
6494 </select>
6495 <button type="button" id="vigilante-log-refresh" class="button"><?php esc_html_e( 'Refresh', 'vigilante' ); ?></button>
6496 <span class="vigilante-pagination" id="vigilante-log-pagination" data-total="<?php echo esc_attr( $total_logs ); ?>" data-per-page="20" data-page="1">
6497 <?php if ( $total_logs > 20 ) : ?>
6498 <button type="button" class="vigilante-page-first" title="<?php esc_attr_e( 'First page', 'vigilante' ); ?>" disabled>&laquo;</button>
6499 <button type="button" class="vigilante-page-prev" title="<?php esc_attr_e( 'Previous page', 'vigilante' ); ?>" disabled>&lsaquo;</button>
6500 <?php endif; ?>
6501 <span class="vigilante-page-info">
6502 <?php
6503 $showing = min( 20, $total_logs );
6504 printf(
6505 /* translators: 1: first item, 2: last item, 3: total items */
6506 esc_html__( '%1$d–%2$d of %3$d', 'vigilante' ),
6507 $total_logs > 0 ? 1 : 0,
6508 absint( $showing ),
6509 absint( $total_logs )
6510 );
6511 ?>
6512 </span>
6513 <?php if ( $total_logs > 20 ) : ?>
6514 <button type="button" class="vigilante-page-next" title="<?php esc_attr_e( 'Next page', 'vigilante' ); ?>">&rsaquo;</button>
6515 <button type="button" class="vigilante-page-last" title="<?php esc_attr_e( 'Last page', 'vigilante' ); ?>">&raquo;</button>
6516 <?php endif; ?>
6517 </span>
6518 </div>
6519
6520 <div class="vigilante-log-table-wrap">
6521 <table id="vigilante-activity-log-table" class="wp-list-table widefat striped">
6522 <thead>
6523 <tr>
6524 <th class="column-date"><?php esc_html_e( 'Date', 'vigilante' ); ?></th>
6525 <th class="column-type"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
6526 <th class="column-method"><?php esc_html_e( 'Method', 'vigilante' ); ?></th>
6527 <th class="column-severity"><?php esc_html_e( 'Severity', 'vigilante' ); ?></th>
6528 <th class="column-message"><?php esc_html_e( 'Message', 'vigilante' ); ?></th>
6529 <th class="column-user"><?php esc_html_e( 'User', 'vigilante' ); ?></th>
6530 <th class="column-ip"><?php esc_html_e( 'IP', 'vigilante' ); ?></th>
6531 <th class="column-details"><?php esc_html_e( 'Details', 'vigilante' ); ?></th>
6532 </tr>
6533 </thead>
6534 <tbody>
6535 <?php
6536 if ( empty( $logs ) ) :
6537 ?>
6538 <tr><td colspan="8"><?php esc_html_e( 'No log entries found.', 'vigilante' ); ?></td></tr>
6539 <?php else : ?>
6540 <?php foreach ( $logs as $log ) :
6541 $request_method = isset( $log->request_method ) ? $log->request_method : '';
6542 // Prepare details as a simple object
6543 $ip_val = (string) ( $log->ip_address ?? '' );
6544 $ua_val = (string) ( $log->user_agent ?? '' );
6545 $details = array(
6546 'id' => (int) $log->id,
6547 'type' => (string) ( $log->event_type ?? '' ),
6548 'action' => (string) ( $log->event_action ?? '' ),
6549 'message' => (string) ( $log->event_message ?? '' ),
6550 'user' => (string) ( $log->user_login ?? '' ),
6551 'ip' => $ip_val,
6552 'user_agent' => $ua_val,
6553 'request_method' => (string) $request_method,
6554 'request_uri' => Vigilante_Activity_Log::extract_request_uri( $log->extra_data ?? '' ),
6555 'date' => (string) ( $log->created_at ?? '' ),
6556 'severity' => (string) ( $log->severity ?? 'info' ),
6557 'is_ip_whitelisted' => ( '' !== $ip_val && in_array( $ip_val, $ip_whitelist, true ) ),
6558 'is_ip_blacklisted' => ( '' !== $ip_val && in_array( $ip_val, $ip_blacklist, true ) ),
6559 'is_ua_whitelisted' => ( '' !== $ua_val && in_array( $ua_val, $ua_whitelist, true ) ),
6560 'is_ua_blacklisted' => ( '' !== $ua_val && in_array( $ua_val, $ua_blacklist, true ) ),
6561 );
6562 // Self-protection entries carry what happened, what
6563 // it means and what to do, from the same catalogue
6564 // the File Integrity box uses.
6565 $vg_self_event = Vigilante_Self_Integrity_Guidance::for_log_event(
6566 (string) ( $log->event_action ?? '' ),
6567 $log->extra_data ?? '',
6568 (string) ( $log->severity ?? 'info' )
6569 );
6570 if ( null !== $vg_self_event ) {
6571 $details['self'] = $vg_self_event;
6572 }
6573 $display_type = isset( $type_labels[ $log->event_type ] ) ? $type_labels[ $log->event_type ] : $log->event_type;
6574 $display_severity = isset( $severity_labels[ $log->severity ] ) ? $severity_labels[ $log->severity ] : $log->severity;
6575 ?>
6576 <tr class="vigilante-severity-<?php echo esc_attr( $log->severity ); ?>">
6577 <td><?php echo esc_html( $log->created_at ); ?></td>
6578 <td><?php echo esc_html( $display_type ); ?></td>
6579 <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>
6580 <td><span class="vigilante-badge vigilante-badge-<?php echo esc_attr( $log->severity ); ?>"><?php echo esc_html( $display_severity ); ?></span></td>
6581 <td><?php echo esc_html( $log->event_message ); ?></td>
6582 <td><?php echo esc_html( $log->user_login ?? '-' ); ?></td>
6583 <td><code><?php echo esc_html( $log->ip_address ); ?></code></td>
6584 <td>
6585 <button type="button" class="button button-small vigilante-view-log-details"
6586 data-details='<?php echo esc_attr( wp_json_encode( $details, JSON_HEX_APOS | JSON_HEX_QUOT ) ); ?>'>
6587 <?php esc_html_e( 'View', 'vigilante' ); ?>
6588 </button>
6589 </td>
6590 </tr>
6591 <?php endforeach; ?>
6592 <?php endif; ?>
6593 </tbody>
6594 </table>
6595 </div>
6596
6597 <!-- Log Details Modal -->
6598 <div id="vigilante-log-details-modal" class="vigilante-modal" style="display: none;">
6599 <div class="vigilante-modal-content">
6600 <span class="vigilante-modal-close">&times;</span>
6601 <h3><?php esc_html_e( 'Log Entry Details', 'vigilante' ); ?></h3>
6602 <div id="vigilante-log-details-content"></div>
6603 </div>
6604 </div>
6605
6606 <p>
6607 <button type="button" class="button vigilante-export-logs"><?php esc_html_e( 'Export Audit Log', 'vigilante' ); ?></button>
6608 <button type="button" class="button vigilante-clear-logs" style="color: #a00;"><?php esc_html_e( 'Clear All Logs', 'vigilante' ); ?></button>
6609 </p>
6610 </div>
6611 <?php
6612 }
6613
6614 /**
6615 * Render File Integrity tab
6616 */
6617 /**
6618 * Findings of the self-check grouped by the case that explains them, worst
6619 * first: ten modified files are one case with ten paths, not ten copies of
6620 * the same explanation.
6621 *
6622 * @param array $findings Findings from the state.
6623 * @return array
6624 */
6625 private function self_findings_by_case( $findings ) {
6626 $groups = array();
6627 foreach ( (array) $findings as $finding ) {
6628 if ( ! is_array( $finding ) || 'info' === ( $finding['severity'] ?? '' ) ) {
6629 continue;
6630 }
6631 $guidance = Vigilante_Self_Integrity_Guidance::for_finding( $finding );
6632 $key = $guidance['key'];
6633 if ( ! isset( $groups[ $key ] ) ) {
6634 $guidance['files'] = array();
6635 $guidance['severity'] = 'warning';
6636 $groups[ $key ] = $guidance;
6637 }
6638 $file = isset( $finding['file'] ) ? (string) $finding['file'] : '';
6639 if ( '' !== $file && ! in_array( $file, $groups[ $key ]['files'], true ) ) {
6640 $groups[ $key ]['files'][] = $file;
6641 }
6642 if ( 'critical' === ( $finding['severity'] ?? '' ) ) {
6643 $groups[ $key ]['severity'] = 'critical';
6644 }
6645 }
6646 uasort(
6647 $groups,
6648 function ( $a, $b ) {
6649 $rank = array( 'critical' => 0, 'warning' => 1 );
6650 $ra = isset( $rank[ $a['severity'] ] ) ? $rank[ $a['severity'] ] : 2;
6651 $rb = isset( $rank[ $b['severity'] ] ) ? $rank[ $b['severity'] ] : 2;
6652 return $ra - $rb;
6653 }
6654 );
6655 return $groups;
6656 }
6657
6658 /**
6659 * Human label for the context that ran the last self-check.
6660 *
6661 * @param string $context Stored context.
6662 * @return string
6663 */
6664 private function self_context_label( $context ) {
6665 switch ( (string) $context ) {
6666 case 'scan':
6667 return __( 'during a file integrity scan', 'vigilante' );
6668 case 'upgrader':
6669 return __( 'right after updating Vigilant', 'vigilante' );
6670 case 'version_change':
6671 return __( 'after a version change made outside the updater', 'vigilante' );
6672 case 'migration':
6673 return __( 'while updating to this version', 'vigilante' );
6674 case 'activation':
6675 return __( 'when Vigilant was activated', 'vigilante' );
6676 case 'watchdog':
6677 return __( 'from the scheduled task watchdog', 'vigilante' );
6678 }
6679 return '';
6680 }
6681
6682 /**
6683 * Short line for the badge of the box, the notices and the Dashboard strip.
6684 *
6685 * @param string $tone Tone from Vigilante_Self_Integrity::tone().
6686 * @param array $state State.
6687 * @return string
6688 */
6689 private function self_integrity_headline( $tone, $state ) {
6690 $files = isset( $state['files_checked'] ) ? (int) $state['files_checked'] : 0;
6691 $anchors = ( isset( $state['anchors'] ) && is_array( $state['anchors'] ) ) ? $state['anchors'] : array();
6692 switch ( $tone ) {
6693 case 'critical':
6694 return __( 'Changes detected in Vigilant own files', 'vigilante' );
6695 case 'warning':
6696 return ( $files < 1 )
6697 ? __( 'Vigilant could not check its own files', 'vigilante' )
6698 : __( 'Vigilant self-protection needs your attention', 'vigilante' );
6699 case 'off':
6700 return __( 'Self-protection is switched off by code', 'vigilante' );
6701 case 'none':
6702 return __( 'Vigilant has not checked its own files yet', 'vigilante' );
6703 }
6704 return sprintf(
6705 /* translators: 1: number of files verified, 2: number of references available, out of three */
6706 __( 'Verified: %1$d files, %2$d of 3 references', 'vigilante' ),
6707 $files,
6708 count( array_filter( $anchors ) )
6709 );
6710 }
6711
6712 /**
6713 * Vigilant self-protection box: the first block of the File Integrity
6714 * results, with its own colour by severity, what each finding means and
6715 * how to fix it.
6716 *
6717 * It renders whether or not a scan has been stored, because the self-check
6718 * also runs after every update and once a day: before 3.0.0 this lived in
6719 * a line above the numeric cards of the last scan, where it was invisible
6720 * and, without a stored scan, absent.
6721 *
6722 * @param array $fi_options File Integrity settings section.
6723 */
6724 /**
6725 * Everything the screens need to say about self-protection, read once:
6726 * the state, its findings grouped by case, and the tone that colours the
6727 * box, the menu counter and the notices.
6728 *
6729 * @param array|null $fi_options File Integrity settings, read if not given.
6730 * @return array { state, findings, groups, tone, enabled }
6731 */
6732 private function self_integrity_summary( $fi_options = null ) {
6733 // Four to six screens ask for this in the same page load (menu, notice,
6734 // box, strip, both scores). The option is cached by the core options
6735 // layer, but the grouping and the tone are not: memoize per request.
6736 static $cached = null;
6737 if ( null !== $cached && ! is_array( $fi_options ) ) {
6738 return $cached;
6739 }
6740 if ( ! is_array( $fi_options ) ) {
6741 $fi_options = (array) $this->settings->get_section( 'file_integrity' );
6742 }
6743 $enabled = Vigilante_Self_Integrity::is_on();
6744 $state = Vigilante_Self_Integrity::display_state();
6745 $findings = Vigilante_Self_Integrity::state_findings( $state, $enabled );
6746 $summary = array(
6747 'state' => $state,
6748 'findings' => $findings,
6749 'groups' => $this->self_findings_by_case( $findings ),
6750 'tone' => Vigilante_Self_Integrity::tone( $state, $enabled ),
6751 'enabled' => $enabled,
6752 );
6753 $cached = $summary;
6754 return $summary;
6755 }
6756
6757 private function render_self_protection_box( $fi_options ) {
6758 $summary = $this->self_integrity_summary( $fi_options );
6759 $enabled = $summary['enabled'];
6760 $state = $summary['state'];
6761 $findings = $summary['findings'];
6762 $groups = $summary['groups'];
6763 $tone = $summary['tone'];
6764 $total = isset( $state['last_findings_total'] ) ? (int) $state['last_findings_total'] : count( $findings );
6765 $status = array(
6766 'status' => isset( $state['last_status'] ) ? (string) $state['last_status'] : '',
6767 'files' => isset( $state['files_checked'] ) ? (int) $state['files_checked'] : 0,
6768 'anchors' => ( isset( $state['anchors'] ) && is_array( $state['anchors'] ) ) ? $state['anchors'] : array(),
6769 'enabled' => $enabled,
6770 'has_run' => ! empty( $state['last_check'] ),
6771 );
6772
6773 /*
6774 * Nothing to do, nothing to open: one line. A card with a big icon and
6775 * folded sections for "everything is fine" is furniture, and furniture
6776 * is what made the previous version of this invisible.
6777 */
6778 if ( empty( $groups ) ) {
6779 $this->render_self_line( $tone, $state, $status );
6780 return;
6781 }
6782
6783 $datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
6784 $context_label = $this->self_context_label( isset( $state['last_context'] ) ? $state['last_context'] : '' );
6785 $icon = ( 'critical' === $tone ) ? 'dashicons-shield' : 'dashicons-warning';
6786 ?>
6787 <div id="vigilante-section-fi-self" class="vigilante-settings-section vigilante-self-box vigilante-self-box--<?php echo esc_attr( $tone ); ?>">
6788 <div class="vigilante-self-card">
6789 <div class="vigilante-self-head">
6790 <span class="vigilante-self-icon"><span class="dashicons <?php echo esc_attr( $icon ); ?>" aria-hidden="true"></span></span>
6791 <div class="vigilante-self-head-text">
6792 <h2><?php echo esc_html( $this->self_integrity_headline( $tone, $state ) ); ?></h2>
6793 <p class="vigilante-self-meta">
6794 <?php
6795 printf(
6796 /* translators: %s: date and time of the last self-check */
6797 esc_html__( 'Checked on %s', 'vigilante' ),
6798 esc_html( wp_date( $datetime_format, (int) $state['last_check'] ) )
6799 );
6800 if ( '' !== $context_label ) {
6801 echo ', ' . esc_html( $context_label );
6802 }
6803 if ( $status['files'] > 0 ) {
6804 echo ', ';
6805 printf(
6806 /* translators: 1: number of files checked, 2: number of references available, out of three */
6807 esc_html__( '%1$d files against %2$d of 3 references', 'vigilante' ),
6808 (int) $status['files'],
6809 (int) count( array_filter( $status['anchors'] ) )
6810 );
6811 }
6812 ?>
6813 </p>
6814 </div>
6815 </div>
6816
6817 <div class="vigilante-self-cases">
6818 <?php
6819 $first = true;
6820 foreach ( $groups as $group ) {
6821 $this->render_self_case( $group, $group['files'], $group['severity'], $first );
6822 $first = false;
6823 }
6824
6825 if ( in_array( $tone, array( 'critical', 'warning' ), true ) ) {
6826 $can_repair = class_exists( 'Vigilante_Self_Repair' ) && Vigilante_Self_Repair::can_repair();
6827 if ( ! $can_repair ) {
6828 if ( class_exists( 'Vigilante_Self_Repair' ) && ! Vigilante_Self_Repair::folder_is_the_distributed_one() ) {
6829 $vg_reason = 'renamed';
6830 } elseif ( ! wp_is_file_mod_allowed( 'capability_update_core' ) ) {
6831 // With DISALLOW_FILE_MODS nobody can do it from the admin,
6832 // not even a network administrator: telling a subsite admin
6833 // to ask theirs would send them to someone equally blocked.
6834 $vg_reason = 'no_caps';
6835 } elseif ( is_multisite() && ! current_user_can( 'update_plugins' ) ) {
6836 $vg_reason = 'network';
6837 } else {
6838 $vg_reason = 'no_caps';
6839 }
6840 $this->render_self_case(
6841 array(
6842 'title' => __( 'How to repair it here', 'vigilante' ),
6843 'meaning' => __( 'This site does not let Vigilant replace its own files from this screen.', 'vigilante' ),
6844 'steps' => Vigilante_Self_Integrity_Guidance::manual_steps( $vg_reason ),
6845 ),
6846 array(),
6847 '',
6848 false
6849 );
6850 }
6851 }
6852 ?>
6853 </div>
6854
6855 <?php if ( $total > count( $findings ) ) : ?>
6856 <p class="description">
6857 <?php
6858 printf(
6859 /* translators: 1: findings shown, 2: findings found in total */
6860 esc_html__( 'Showing %1$d of %2$d findings: the rest are of the same kind.', 'vigilante' ),
6861 (int) count( $findings ),
6862 (int) $total
6863 );
6864 ?>
6865 </p>
6866 <?php endif; ?>
6867
6868 <?php
6869 /*
6870 * Reinstalling fixes files, not a filter someone wrote or a hook
6871 * someone removed: the button only appears when at least one of the
6872 * cases on screen is one a clean copy solves. Offering it next to
6873 * "switched off by code" was telling the person to fix something
6874 * else.
6875 */
6876 $vg_offer_repair = false;
6877 foreach ( $groups as $vg_group ) {
6878 if ( ! empty( $vg_group['repair'] ) ) {
6879 $vg_offer_repair = true;
6880 break;
6881 }
6882 }
6883 ?>
6884 <p class="vigilante-self-actions">
6885 <?php if ( $vg_offer_repair && class_exists( 'Vigilante_Self_Repair' ) && Vigilante_Self_Repair::can_repair() ) : ?>
6886 <a class="button button-primary" href="<?php echo esc_url( Vigilante_Self_Repair::action_url() ); ?>">
6887 <?php esc_html_e( 'Repair Vigilant', 'vigilante' ); ?>
6888 </a>
6889 <span class="description">
6890 <?php esc_html_e( 'It downloads a clean copy from WordPress.org, asks before changing anything, and keeps your settings and log.', 'vigilante' ); ?>
6891 </span>
6892 <?php else : ?>
6893 <span class="description">
6894 <?php esc_html_e( 'After fixing it, run a new scan with the Run Scan Now button above.', 'vigilante' ); ?>
6895 </span>
6896 <?php endif; ?>
6897 </p>
6898 </div>
6899 </div>
6900 <?php
6901 }
6902
6903 /**
6904 * The same state when there is nothing to act on: one line inside the same
6905 * card, so the first block of the results is always the same object.
6906 *
6907 * @param string $tone Tone from Vigilante_Self_Integrity::tone().
6908 * @param array $state State.
6909 * @param array $status Arguments for the guidance catalogue.
6910 */
6911 private function render_self_line( $tone, $state, $status ) {
6912 $guidance = Vigilante_Self_Integrity_Guidance::for_status( $status );
6913 $icon = ( 'ok' === $tone ) ? 'dashicons-yes-alt' : 'dashicons-shield';
6914 ?>
6915 <div id="vigilante-section-fi-self" class="vigilante-settings-section vigilante-self-box vigilante-self-box--<?php echo esc_attr( $tone ); ?> vigilante-self-box--quiet">
6916 <div class="vigilante-self-card vigilante-self-card--quiet">
6917 <p class="vigilante-self-line">
6918 <span class="dashicons <?php echo esc_attr( $icon ); ?>" aria-hidden="true"></span>
6919 <strong><?php esc_html_e( 'Vigilant self-protection:', 'vigilante' ); ?></strong>
6920 <span class="vigilante-self-line-state"><?php echo esc_html( $this->self_integrity_headline( $tone, $state ) ); ?></span>
6921 <?php if ( ! empty( $state['last_check'] ) ) : ?>
6922 <span class="vigilante-self-line-meta">
6923 <?php
6924 printf(
6925 /* translators: %s: human time difference, like "2 hours" */
6926 esc_html__( 'checked %s ago', 'vigilante' ),
6927 esc_html( human_time_diff( (int) $state['last_check'], time() ) )
6928 );
6929 ?>
6930 </span>
6931 <?php endif; ?>
6932 </p>
6933 <?php if ( ! empty( $guidance['steps'] ) && 'none' === $tone ) : ?>
6934 <p class="description vigilante-self-line-help"><?php echo esc_html( $guidance['steps'][0] ); ?></p>
6935 <?php endif; ?>
6936 </div>
6937 </div>
6938 <?php
6939 }
6940
6941 /**
6942 * One case of the self-protection box, as a row that opens: what it is, how
6943 * many files, its severity, and inside, the files, what it means and what to
6944 * do. Plain HTML details, so there is no JavaScript between a finding about
6945 * the security plugin and the person reading it.
6946 *
6947 * @param array $guidance Guidance entry (title, meaning, steps).
6948 * @param array $files Paths this case was found in.
6949 * @param string $severity critical|warning, empty for the how-to-repair row.
6950 * @param bool $open Whether the row starts open.
6951 */
6952 private function render_self_case( $guidance, $files = array(), $severity = '', $open = false ) {
6953 $shown = array_slice( (array) $files, 0, 20 );
6954 $hidden = count( (array) $files ) - count( $shown );
6955 ?>
6956 <details class="vigilante-self-case vigilante-self-case--<?php echo esc_attr( '' !== $severity ? $severity : 'plain' ); ?>"<?php echo $open ? ' open' : ''; ?>>
6957 <summary>
6958 <span class="vigilante-self-case-title"><?php echo esc_html( $guidance['title'] ); ?></span>
6959 <?php if ( ! empty( $files ) ) : ?>
6960 <span class="vigilante-self-case-count">
6961 <?php
6962 printf(
6963 /* translators: %d: number of files of this finding */
6964 esc_html( _n( '%d file', '%d files', count( (array) $files ), 'vigilante' ) ),
6965 (int) count( (array) $files )
6966 );
6967 ?>
6968 </span>
6969 <?php endif; ?>
6970 <?php if ( '' !== $severity ) : ?>
6971 <span class="vigilante-self-case-severity">
6972 <?php echo esc_html( 'critical' === $severity ? __( 'critical', 'vigilante' ) : __( 'warning', 'vigilante' ) ); ?>
6973 </span>
6974 <?php endif; ?>
6975 </summary>
6976 <div class="vigilante-self-case-body">
6977 <?php if ( ! empty( $shown ) ) : ?>
6978 <ul class="vigilante-self-paths">
6979 <?php foreach ( $shown as $file ) : ?>
6980 <li><code><?php echo esc_html( $file ); ?></code></li>
6981 <?php endforeach; ?>
6982 <?php if ( $hidden > 0 ) : ?>
6983 <li>
6984 <?php
6985 printf(
6986 /* translators: %d: number of additional files */
6987 esc_html__( 'and %d more', 'vigilante' ),
6988 (int) $hidden
6989 );
6990 ?>
6991 </li>
6992 <?php endif; ?>
6993 </ul>
6994 <?php endif; ?>
6995 <p class="vigilante-self-meaning">
6996 <strong><?php esc_html_e( 'What it means:', 'vigilante' ); ?></strong>
6997 <?php echo esc_html( $guidance['meaning'] ); ?>
6998 </p>
6999 <?php if ( ! empty( $guidance['steps'] ) ) : ?>
7000 <p class="vigilante-self-todo"><strong><?php esc_html_e( 'What to do:', 'vigilante' ); ?></strong></p>
7001 <ol class="vigilante-self-steps">
7002 <?php foreach ( $guidance['steps'] as $step ) : ?>
7003 <li><?php echo esc_html( $step ); ?></li>
7004 <?php endforeach; ?>
7005 </ol>
7006 <?php endif; ?>
7007 </div>
7008 </details>
7009 <?php
7010 }
7011
7012 private function render_tab_file_integrity() {
7013 $is_disabled = $this->render_module_disabled_notice( 'file_integrity' );
7014 $options = $this->settings->get_section( 'file_integrity' );
7015 // On the main site of a network the critical-file scan is the network's
7016 // canary for a change to wp-config.php or the root .htaccess, so a
7017 // main-site admin without network rights cannot turn it off. Since
7018 // 2.11.8; see Vigilante_Settings::get_main_site_file_settings().
7019 $vg_main_locked = $this->main_site_files_locked();
7020 $last_scan = get_option( 'vigilante_last_integrity_scan' );
7021 $last_results = get_option( 'vigilante_last_integrity_results' );
7022 $ignored_files = get_option( 'vigilante_ignored_files', array() );
7023
7024 /*
7025 * Vigilant own findings are shown in their own box, the first of the
7026 * results, with what each one means and how to fix it. They are taken
7027 * out of the generic tables here (and out of the counters above them)
7028 * so the same finding is not reported twice and so no row of the
7029 * security plugin's own files offers an Ignore button. The stored
7030 * results keep them: the scan email reads its own section from there.
7031 */
7032 if ( is_array( $last_results ) ) {
7033 foreach ( array( 'modified', 'suspicious', 'extra', 'missing' ) as $vg_bucket ) {
7034 if ( empty( $last_results[ $vg_bucket ] ) || ! is_array( $last_results[ $vg_bucket ] ) ) {
7035 continue;
7036 }
7037 $last_results[ $vg_bucket ] = array_values(
7038 array_filter(
7039 $last_results[ $vg_bucket ],
7040 function ( $vg_item ) {
7041 return ! ( is_array( $vg_item ) && 'vigilante_self' === ( $vg_item['type'] ?? '' ) );
7042 }
7043 )
7044 );
7045 }
7046 }
7047
7048 // Backward compat: convert old notify_on_changes to notify_level
7049 $notify_level = $options['notify_level'] ?? '';
7050 if ( empty( $notify_level ) ) {
7051 $notify_level = ! empty( $options['notify_on_changes'] ) ? 'all' : 'disabled';
7052 }
7053
7054 // Closed + Removed plugins data. Surfaced inside Last Scan Results so the
7055 // user sees file findings and plugin closures together (same tier of risk,
7056 // same UI), and as the trigger to keep Last Scan Results open even when no
7057 // file scan has run yet (the daily cron may have populated this section).
7058 //
7059 // Gating by last_check_time > 0 is how "Clear Previous Results" visually
7060 // resets this block: the option vigilante_plugin_status_last_check is
7061 // deleted on Clear, but the state map and the ignored list survive so the
7062 // next scan reconstructs without degrading a 'removed' slug. While
7063 // last_check is 0, we treat the plugin_status data as if it didn't exist.
7064 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
7065 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
7066 }
7067 $closed_checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
7068 $closed_last_check = $closed_checker->get_last_check_time();
7069 if ( $closed_last_check > 0 ) {
7070 $closed_plugins = $closed_checker->get_closed_plugins();
7071 $ignored_closed_plugins = $closed_checker->get_ignored_closed_plugins();
7072 } else {
7073 $closed_plugins = array();
7074 $ignored_closed_plugins = array();
7075 }
7076 $has_closed = ! empty( $closed_plugins );
7077 $datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
7078 ?>
7079 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="file_integrity" <?php echo $is_disabled ? 'inert' : ''; ?>>
7080 <div id="vigilante-section-fi-monitoring" class="vigilante-settings-section">
7081 <h2>
7082 <?php esc_html_e( 'File Integrity Monitoring', 'vigilante' ); ?>
7083 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
7084 </h2>
7085 <p><?php esc_html_e( 'Detects file modifications using WordPress.org checksums.', 'vigilante' ); ?></p>
7086
7087 <table class="form-table">
7088 <tr>
7089 <th scope="row"><?php esc_html_e( 'Automatic Scans', 'vigilante' ); ?></th>
7090 <td>
7091 <label>
7092 <input type="checkbox" name="file_integrity[auto_scan]" value="1" <?php checked( ! empty( $options['auto_scan'] ) ); ?>>
7093 <?php esc_html_e( 'Enable scheduled file integrity scans', 'vigilante' ); ?>
7094 </label>
7095 </td>
7096 </tr>
7097 <tr>
7098 <th scope="row"><label for="vigilante-f-file-integrity-scan-frequency"><?php esc_html_e( 'Scan Frequency', 'vigilante' ); ?></label></th>
7099 <td>
7100 <select id="vigilante-f-file-integrity-scan-frequency" name="file_integrity[scan_frequency]">
7101 <option value="daily" <?php selected( $options['scan_frequency'] ?? 'daily', 'daily' ); ?>><?php esc_html_e( 'Daily', 'vigilante' ); ?></option>
7102 <option value="weekly" <?php selected( $options['scan_frequency'] ?? 'daily', 'weekly' ); ?>><?php esc_html_e( 'Weekly', 'vigilante' ); ?></option>
7103 </select>
7104 </td>
7105 </tr>
7106 <tr>
7107 <th scope="row"><label for="vigilante-f-file-integrity-notify-level"><?php esc_html_e( 'Email Notifications', 'vigilante' ); ?></label></th>
7108 <td>
7109 <select id="vigilante-f-file-integrity-notify-level" name="file_integrity[notify_level]">
7110 <option value="all" <?php selected( $notify_level, 'all' ); ?>><?php esc_html_e( 'All issues (modified + suspicious)', 'vigilante' ); ?></option>
7111 <option value="suspicious_only" <?php selected( $notify_level, 'suspicious_only' ); ?>><?php esc_html_e( 'Suspicious files only', 'vigilante' ); ?></option>
7112 <option value="disabled" <?php selected( $notify_level, 'disabled' ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
7113 </select>
7114 <p class="description"><?php esc_html_e( '"Suspicious files only" reduces noise by skipping modified file notifications. Recommended for most sites.', 'vigilante' ); ?></p>
7115 </td>
7116 </tr>
7117 <tr>
7118 <th scope="row"><?php esc_html_e( 'Instant Alert', 'vigilante' ); ?></th>
7119 <td>
7120 <label>
7121 <input type="checkbox" name="file_integrity[instant_alert]" value="1" <?php checked( ! empty( $options['instant_alert'] ) ); ?>>
7122 <?php esc_html_e( 'Send immediate alert when modified, suspicious or additional files are detected, or when a closed plugin is found', 'vigilante' ); ?>
7123 </label>
7124 <p class="description"><?php esc_html_e( 'Fires even if the Email Notifications setting above is set to Disabled.', 'vigilante' ); ?></p>
7125 <p class="description">
7126 <?php
7127 printf(
7128 /* translators: %s: Link to notification settings */
7129 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
7130 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
7131 );
7132 ?>
7133 </p>
7134 </td>
7135 </tr>
7136 <tr>
7137 <th scope="row"><?php esc_html_e( 'Test email', 'vigilante' ); ?></th>
7138 <td>
7139 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
7140 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
7141 </button>
7142 <span class="vigilante-test-email-result" style="margin-left:8px;"></span>
7143 <p class="description"><?php esc_html_e( 'Sends a test message to the configured recipients to confirm email delivery works.', 'vigilante' ); ?></p>
7144 </td>
7145 </tr>
7146 <tr>
7147 <th scope="row"><?php esc_html_e( 'Scan Scope', 'vigilante' ); ?></th>
7148 <td>
7149 <fieldset>
7150 <label>
7151 <input type="checkbox" name="file_integrity[scan_core]" value="1" <?php checked( $options['scan_core'] ?? true ); ?>>
7152 <?php esc_html_e( 'Core files (compare against WordPress.org checksums)', 'vigilante' ); ?>
7153 </label>
7154 <br>
7155 <label>
7156 <input type="checkbox" name="file_integrity[scan_plugins]" value="1" <?php checked( $options['scan_plugins'] ?? true ); ?>>
7157 <?php esc_html_e( 'Plugins (WordPress.org repository plugins)', 'vigilante' ); ?>
7158 </label>
7159 <br>
7160 <label>
7161 <input type="checkbox" name="file_integrity[scan_themes]" value="1" <?php checked( $options['scan_themes'] ?? true ); ?>>
7162 <?php esc_html_e( 'Themes (WordPress.org repository themes)', 'vigilante' ); ?>
7163 </label>
7164 <br>
7165 <label>
7166 <input type="checkbox" name="file_integrity[scan_uploads]" value="1" <?php checked( $options['scan_uploads'] ?? true ); ?>>
7167 <?php esc_html_e( 'Uploads directory (detect PHP files, double extensions, .htaccess)', 'vigilante' ); ?>
7168 </label>
7169 <br>
7170 <label>
7171 <input type="checkbox" name="file_integrity[scan_critical_config]" value="1" <?php disabled( $vg_main_locked ); ?> <?php checked( $options['scan_critical_config'] ?? true ); ?>>
7172 <?php esc_html_e( 'Critical config files (wp-config.php, .htaccess baseline monitoring)', 'vigilante' ); ?>
7173 <?php if ( $vg_main_locked ) : ?>
7174 <span class="description" style="display:block;margin-left:24px;"><?php echo esc_html( Vigilante_Settings::get_shared_files_notice() ); ?></span>
7175 <?php endif; ?>
7176 </label>
7177 <br>
7178 <label>
7179 <input type="checkbox" name="file_integrity[check_closed_plugins]" value="1" <?php checked( $options['check_closed_plugins'] ?? true ); ?>>
7180 <?php esc_html_e( 'Closed plugins (daily check against the WordPress.org repository)', 'vigilante' ); ?>
7181 </label>
7182 </fieldset>
7183 </td>
7184 </tr>
7185 <tr>
7186 <th scope="row"><label for="vigilante-f-file-integrity-excluded-paths"><?php esc_html_e( 'Excluded Paths', 'vigilante' ); ?></label></th>
7187 <td>
7188 <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>
7189 <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>
7190 </td>
7191 </tr>
7192 <tr>
7193 <th scope="row"><label for="vigilante-f-file-integrity-excluded-extensions"><?php esc_html_e( 'Excluded Extensions', 'vigilante' ); ?></label></th>
7194 <td>
7195 <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>
7196 <p class="description">
7197 <?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' ); ?>
7198 <br>
7199 <?php
7200 printf(
7201 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the scoped-extension example. */
7202 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' ),
7203 '<code>',
7204 '</code>'
7205 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
7206 ?>
7207 </p>
7208 </td>
7209 </tr>
7210 </table>
7211 </div>
7212
7213 <p class="submit vigilante-submit-buttons">
7214 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
7215 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
7216 </button>
7217 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
7218 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
7219 </button>
7220 <span class="vigilante-buttons-separator"></span>
7221 <button type="button" class="button button-primary vigilante-run-scan">
7222 <?php esc_html_e( 'Run Scan Now', 'vigilante' ); ?>
7223 </button>
7224 <button type="button" class="button vigilante-clear-scan-btn vigilante-clear-scan">
7225 <?php esc_html_e( 'Clear Previous Results', 'vigilante' ); ?>
7226 </button>
7227 </p>
7228 </form>
7229
7230 <div id="vigilante-scan-results" class="vigilante-settings-section" style="display:none;"></div>
7231
7232 <?php $this->render_self_protection_box( $options ); ?>
7233
7234 <?php if ( $last_scan || $has_closed || $closed_last_check > 0 ) : ?>
7235 <div id="vigilante-section-fi-last-scan" class="vigilante-settings-section">
7236 <h2><?php esc_html_e( 'Last Scan Results', 'vigilante' ); ?></h2>
7237 <?php if ( $last_scan ) : ?>
7238 <p>
7239 <?php
7240 // Build the "X files scanned" hint inline with the date so it doesn't
7241 // need its own stat box (keeps the row compact when closed plugins are
7242 // present).
7243 $scanned_total = 0;
7244 if ( $last_results ) {
7245 $scanned_total = (int) ( $last_results['ok'] ?? 0 )
7246 + count( $last_results['modified'] ?? array() )
7247 + count( $last_results['suspicious'] ?? array() )
7248 + count( $last_results['extra'] ?? array() )
7249 + count( $ignored_files );
7250 }
7251 if ( $scanned_total > 0 ) {
7252 printf(
7253 /* translators: 1: date and time of last scan, 2: formatted file count */
7254 esc_html__( 'Last scan: %1$s (%2$s files scanned)', 'vigilante' ),
7255 esc_html( wp_date( $datetime_format, $last_scan ) ),
7256 esc_html( number_format_i18n( $scanned_total ) )
7257 );
7258 } else {
7259 printf(
7260 /* translators: %s: date and time of last scan */
7261 esc_html__( 'Last scan: %s', 'vigilante' ),
7262 esc_html( wp_date( $datetime_format, $last_scan ) )
7263 );
7264 }
7265 if ( $closed_last_check > 0 && $closed_last_check !== (int) $last_scan ) {
7266 echo ' &middot; ';
7267 printf(
7268 /* translators: %s: date and time of last closed plugins check */
7269 esc_html__( 'Closed plugins last checked: %s', 'vigilante' ),
7270 esc_html( wp_date( $datetime_format, $closed_last_check ) )
7271 );
7272 }
7273 ?>
7274 </p>
7275 <?php elseif ( $closed_last_check > 0 ) : ?>
7276 <p>
7277 <?php
7278 printf(
7279 /* translators: %s: date and time of last closed plugins check */
7280 esc_html__( 'Closed plugins last checked: %s &middot; the daily cron is running, no full integrity scan yet.', 'vigilante' ),
7281 esc_html( wp_date( $datetime_format, $closed_last_check ) )
7282 );
7283 ?>
7284 </p>
7285 <?php endif; ?>
7286 <div id="vigilante-last-scan-results">
7287 <?php if ( $last_results || $has_closed ) : ?>
7288 <div class="vigilante-scan-summary">
7289 <?php if ( $last_results ) : ?>
7290 <div class="vigilante-scan-stat vigilante-stat-ok">
7291 <span class="vigilante-stat-number"><?php echo esc_html( $last_results['ok'] ?? 0 ); ?></span>
7292 <span class="vigilante-stat-label"><?php esc_html_e( 'OK', 'vigilante' ); ?></span>
7293 </div>
7294 <div class="vigilante-scan-stat vigilante-stat-modified">
7295 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['modified'] ?? array() ) ); ?></span>
7296 <span class="vigilante-stat-label"><?php esc_html_e( 'Modified', 'vigilante' ); ?></span>
7297 </div>
7298 <div class="vigilante-scan-stat vigilante-stat-suspicious">
7299 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['suspicious'] ?? array() ) ); ?></span>
7300 <span class="vigilante-stat-label"><?php esc_html_e( 'Suspicious', 'vigilante' ); ?></span>
7301 </div>
7302 <div class="vigilante-scan-stat vigilante-stat-extra">
7303 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['extra'] ?? array() ) ); ?></span>
7304 <span class="vigilante-stat-label"><?php esc_html_e( 'Extra', 'vigilante' ); ?></span>
7305 </div>
7306 <?php endif; ?>
7307 <?php if ( $has_closed ) : ?>
7308 <div class="vigilante-scan-stat vigilante-stat-suspicious">
7309 <span class="vigilante-stat-number" style="color: #d63638;"><?php echo (int) count( $closed_plugins ); ?></span>
7310 <span class="vigilante-stat-label"><?php esc_html_e( 'Closed/Removed', 'vigilante' ); ?></span>
7311 </div>
7312 <?php endif; ?>
7313 <?php if ( ! empty( $ignored_files ) ) : ?>
7314 <div class="vigilante-scan-stat vigilante-stat-ignored">
7315 <span class="vigilante-stat-number"><?php echo esc_html( count( $ignored_files ) ); ?></span>
7316 <span class="vigilante-stat-label"><?php esc_html_e( 'Ignored', 'vigilante' ); ?></span>
7317 </div>
7318 <?php endif; ?>
7319 </div>
7320
7321 <?php if ( ! empty( $last_results['suspicious'] ) ) : ?>
7322 <div class="vigilante-file-list vigilante-suspicious-files vigilante-paginated-section" data-bulk-mode="ignore">
7323 <h3 style="color: #d63638;"><?php esc_html_e( 'Suspicious Files', 'vigilante' ); ?></h3>
7324 <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>
7325 <div class="vigilante-fi-bulk-bar">
7326 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
7327 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
7328 </div>
7329 <div class="vigilante-fi-pagination-wrap"></div>
7330 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
7331 <thead>
7332 <tr>
7333 <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>
7334 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
7335 <th style="width: 250px;"><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
7336 <th style="width: 120px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
7337 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
7338 </tr>
7339 </thead>
7340 <tbody>
7341 <?php
7342 foreach ( $last_results['suspicious'] as $item ) {
7343 $file_path = '';
7344 $file_reason = __( 'Unknown', 'vigilante' );
7345 $file_type = 'unknown';
7346
7347 if ( is_array( $item ) ) {
7348 if ( isset( $item['file'] ) ) {
7349 $file_path = $item['file'];
7350 }
7351 if ( isset( $item['reason'] ) ) {
7352 $file_reason = $item['reason'];
7353 }
7354 if ( isset( $item['type'] ) ) {
7355 $file_type = $item['type'];
7356 }
7357 } else {
7358 $file_path = (string) $item;
7359 }
7360 if ( 'vigilante_self' === $file_type ) {
7361 $file_type = __( 'Vigilant (self)', 'vigilante' );
7362 }
7363 ?>
7364 <tr>
7365 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
7366 <td><code style="color: #d63638;"><?php echo esc_html( $file_path ); ?></code></td>
7367 <td><?php echo esc_html( $file_reason ); ?></td>
7368 <td><?php echo esc_html( $file_type ); ?></td>
7369 <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>
7370 </tr>
7371 <?php
7372 }
7373 ?>
7374 </tbody>
7375 </table>
7376 </div>
7377 <?php endif; ?>
7378
7379 <?php if ( ! empty( $last_results['extra'] ) ) : ?>
7380 <div class="vigilante-file-list vigilante-extra-files vigilante-paginated-section" data-bulk-mode="ignore">
7381 <h3 style="color: #b32d2e;"><?php esc_html_e( 'Extra Files', 'vigilante' ); ?></h3>
7382 <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>
7383 <div class="vigilante-fi-bulk-bar">
7384 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
7385 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
7386 </div>
7387 <div class="vigilante-fi-pagination-wrap"></div>
7388 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
7389 <thead>
7390 <tr>
7391 <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>
7392 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
7393 <th style="width: 250px;"><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
7394 <th style="width: 120px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
7395 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
7396 </tr>
7397 </thead>
7398 <tbody>
7399 <?php
7400 foreach ( $last_results['extra'] as $item ) {
7401 $file_path = is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item;
7402 $file_reason = is_array( $item ) ? ( $item['reason'] ?? __( 'Unknown', 'vigilante' ) ) : __( 'Unknown', 'vigilante' );
7403 $file_type = is_array( $item ) ? ( $item['type'] ?? 'unknown' ) : 'unknown';
7404 if ( 'vigilante_self' === $file_type ) {
7405 $file_type = __( 'Vigilant (self)', 'vigilante' );
7406 }
7407 ?>
7408 <tr>
7409 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
7410 <td><code style="color: #b32d2e;"><?php echo esc_html( $file_path ); ?></code></td>
7411 <td><?php echo esc_html( $file_reason ); ?></td>
7412 <td><?php echo esc_html( $file_type ); ?></td>
7413 <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>
7414 </tr>
7415 <?php
7416 }
7417 ?>
7418 </tbody>
7419 </table>
7420 </div>
7421 <?php endif; ?>
7422
7423 <?php
7424 // Split critical config files from regular modified files.
7425 // Computed unconditionally so the three sub-sections that consume
7426 // these arrays (Critical Config, Closed + Removed, Modified Files)
7427 // can render independently and in the order the team picked.
7428 $critical_modified = array();
7429 $regular_modified = array();
7430 if ( $last_results && ! empty( $last_results['modified'] ) ) {
7431 foreach ( $last_results['modified'] as $item ) {
7432 if ( is_array( $item ) && isset( $item['type'] ) && 'critical_config' === $item['type'] ) {
7433 $critical_modified[] = $item;
7434 } else {
7435 $regular_modified[] = $item;
7436 }
7437 }
7438 }
7439 // A missing file of Vigilant is critical, and the missing
7440 // files of the generic scan have no table: it is listed with
7441 // the modified files, or the tab said "All files passed" with
7442 // a module deleted.
7443 if ( $last_results && ! empty( $last_results['missing'] ) && is_array( $last_results['missing'] ) ) {
7444 foreach ( $last_results['missing'] as $item ) {
7445 if ( is_array( $item ) && 'vigilante_self' === ( $item['type'] ?? '' ) ) {
7446 $regular_modified[] = $item;
7447 }
7448 }
7449 }
7450 ?>
7451
7452 <?php if ( ! empty( $critical_modified ) ) : ?>
7453 <div class="vigilante-file-list vigilante-critical-config-files">
7454 <h3 style="color: #e36210;"><?php esc_html_e( 'Critical config files modified', 'vigilante' ); ?></h3>
7455 <p class="description">
7456 <?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' ); ?>
7457 </p>
7458 <table class="wp-list-table widefat fixed striped">
7459 <thead>
7460 <tr>
7461 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
7462 <th style="width: 200px;"><?php esc_html_e( 'Changes', 'vigilante' ); ?></th>
7463 <th style="width: 220px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
7464 </tr>
7465 </thead>
7466 <tbody>
7467 <?php foreach ( $critical_modified as $crit_item ) :
7468 $crit_file = $crit_item['file'] ?? '';
7469 $crit_baseline_size = $crit_item['baseline_size'] ?? 0;
7470 $crit_current_size = $crit_item['current_size'] ?? 0;
7471 $crit_diff = $crit_item['diff'] ?? array();
7472 $crit_id = sanitize_html_class( $crit_file );
7473 $added_count = is_array( $crit_diff ) ? count( $crit_diff['added'] ?? array() ) : 0;
7474 $removed_count = is_array( $crit_diff ) ? count( $crit_diff['removed'] ?? array() ) : 0;
7475 // The lines of a shared file are for whoever approves it. Results
7476 // stored before 2.11.8 on the main site still carry them, so the
7477 // screen asks too, not only the scan that wrote them.
7478 $diff_network = ( is_array( $crit_diff ) && ! empty( $crit_diff['network'] ) ) || $this->critical_approval_locked();
7479 $diff_rescan = is_array( $crit_diff ) && ! empty( $crit_diff['rescan'] );
7480 $diff_redaction = is_array( $crit_diff ) && ! empty( $crit_diff['redaction'] );
7481 $diff_unavailable = $diff_network || ( is_array( $crit_diff ) && ! empty( $crit_diff['unavailable'] ) );
7482 ?>
7483 <tr>
7484 <td><code style="color: #e36210;"><?php echo esc_html( $crit_file ); ?></code></td>
7485 <td>
7486 <?php if ( ! $diff_unavailable ) : ?>
7487 <span style="color: #007017;">+<?php echo (int) $added_count; ?></span>
7488 <span style="color: #b32d2e;">-<?php echo (int) $removed_count; ?></span>
7489 <?php esc_html_e( 'lines', 'vigilante' ); ?><br>
7490 <?php endif; ?>
7491 <small style="color: #50575e;">
7492 <?php
7493 printf(
7494 /* translators: 1: baseline size, 2: current size */
7495 esc_html__( '%1$s &rarr; %2$s bytes', 'vigilante' ),
7496 esc_html( number_format_i18n( $crit_baseline_size ) ),
7497 esc_html( number_format_i18n( $crit_current_size ) )
7498 );
7499 ?>
7500 </small>
7501 </td>
7502 <td>
7503 <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' ); ?>">
7504 <?php esc_html_e( 'Review changes', 'vigilante' ); ?>
7505 </button>
7506 <?php if ( $this->critical_approval_locked() ) : ?>
7507 <span class="description" style="display:block;margin-top:4px;">
7508 <?php echo esc_html( $this->critical_approval_notice() ); ?>
7509 </span>
7510 <?php else : ?>
7511 <button type="button" class="button button-small button-primary vigilante-approve-critical-file" data-file="<?php echo esc_attr( $crit_file ); ?>">
7512 <?php esc_html_e( 'Approve', 'vigilante' ); ?>
7513 </button>
7514 <?php endif; ?>
7515 </td>
7516 </tr>
7517 <tr id="vigilante-critical-content-<?php echo esc_attr( $crit_id ); ?>" class="vigilante-critical-content-row" style="display:none;">
7518 <td colspan="3" style="padding: 0;">
7519 <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;">
7520 <?php if ( $diff_network ) : ?>
7521 <p style="color: #50575e; font-style: italic; margin: 0;">
7522 <?php esc_html_e( 'This file belongs to the whole network, so its line changes are only shown to network administrators, on the main site.', 'vigilante' ); ?>
7523 </p>
7524 <?php elseif ( $diff_rescan ) : ?>
7525 <p style="color: #50575e; font-style: italic; margin: 0;">
7526 <?php esc_html_e( 'Run a new scan to see the line changes of this file.', 'vigilante' ); ?>
7527 </p>
7528 <?php elseif ( $diff_redaction ) : ?>
7529 <p style="color: #50575e; font-style: italic; margin: 0;">
7530 <?php esc_html_e( 'The line changes of this file are not shown because a value in it could not be hidden safely. The change itself is still detected.', 'vigilante' ); ?>
7531 </p>
7532 <?php elseif ( $diff_unavailable ) : ?>
7533 <p style="color: #50575e; font-style: italic; margin: 0;">
7534 <?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' ); ?>
7535 </p>
7536 <?php elseif ( empty( $crit_diff['added'] ) && empty( $crit_diff['removed'] ) ) : ?>
7537 <p style="color: #50575e; font-style: italic; margin: 0;">
7538 <?php esc_html_e( 'No line-level changes detected (may be whitespace or reordering).', 'vigilante' ); ?>
7539 </p>
7540 <?php else : ?>
7541 <?php if ( ! empty( $crit_diff['removed'] ) ) : ?>
7542 <?php foreach ( $crit_diff['removed'] as $rline ) : ?>
7543 <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>
7544 <?php endforeach; ?>
7545 <?php endif; ?>
7546 <?php if ( ! empty( $crit_diff['added'] ) ) : ?>
7547 <?php foreach ( $crit_diff['added'] as $aline ) : ?>
7548 <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>
7549 <?php endforeach; ?>
7550 <?php endif; ?>
7551 <?php endif; ?>
7552 </div>
7553 </td>
7554 </tr>
7555 <?php endforeach; ?>
7556 </tbody>
7557 </table>
7558 </div>
7559 <?php endif; ?>
7560
7561 <?php if ( $has_closed ) : ?>
7562 <div class="vigilante-file-list vigilante-closed-plugins">
7563 <h3 id="vigilante-section-fi-closed-plugins" style="color: #d63638;"><?php esc_html_e( 'Closed + Removed Plugins', 'vigilante' ); ?></h3>
7564 <p class="description" style="color: #d63638;">
7565 <?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' ); ?>
7566 </p>
7567 <table class="wp-list-table widefat striped">
7568 <thead>
7569 <tr>
7570 <th><?php esc_html_e( 'Plugin', 'vigilante' ); ?></th>
7571 <th style="width: 70px;"><?php esc_html_e( 'Version', 'vigilante' ); ?></th>
7572 <th style="width: 90px;"><?php esc_html_e( 'State', 'vigilante' ); ?></th>
7573 <th style="width: 110px;"><?php esc_html_e( 'Closed date', 'vigilante' ); ?></th>
7574 <th><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
7575 <th style="width: 130px;"><?php esc_html_e( 'Detected', 'vigilante' ); ?></th>
7576 <th style="width: 90px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
7577 </tr>
7578 </thead>
7579 <tbody>
7580 <?php foreach ( $closed_plugins as $cp_slug => $cp_entry ) :
7581 $cp_state = $cp_entry['state'] ?? '';
7582 $cp_state_label = 'closed' === $cp_state ? __( 'Closed', 'vigilante' ) : __( 'Removed', 'vigilante' );
7583 $cp_state_color = 'closed' === $cp_state ? '#d63638' : '#b32d2e';
7584 $cp_reason = '';
7585 if ( ! empty( $cp_entry['closed_reason_text'] ) ) {
7586 $cp_reason = $cp_entry['closed_reason_text'];
7587 } elseif ( 'removed' === $cp_state ) {
7588 $cp_reason = __( 'Removed from repository (metadata hidden, typical of Security Issue closures)', 'vigilante' );
7589 }
7590 $cp_detected = isset( $cp_entry['first_detected'] ) ? (int) $cp_entry['first_detected'] : 0;
7591 ?>
7592 <tr>
7593 <td>
7594 <strong><?php echo esc_html( $cp_entry['name'] ?? $cp_slug ); ?></strong><br>
7595 <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>
7596 </td>
7597 <td><?php echo esc_html( $cp_entry['version'] ?? '' ); ?></td>
7598 <td><span style="color: <?php echo esc_attr( $cp_state_color ); ?>; font-weight: 600;"><?php echo esc_html( $cp_state_label ); ?></span></td>
7599 <td><?php echo esc_html( $cp_entry['closed_date'] ?? '' ); ?></td>
7600 <td><?php echo esc_html( $cp_reason ); ?></td>
7601 <td>
7602 <?php echo $cp_detected > 0 ? esc_html( wp_date( $datetime_format, $cp_detected ) ) : '&mdash;'; ?>
7603 </td>
7604 <td>
7605 <button type="button" class="button button-small vigilante-ignore-closed-plugin" data-slug="<?php echo esc_attr( $cp_slug ); ?>">
7606 <?php esc_html_e( 'Ignore', 'vigilante' ); ?>
7607 </button>
7608 </td>
7609 </tr>
7610 <?php endforeach; ?>
7611 </tbody>
7612 </table>
7613 </div>
7614 <?php endif; ?>
7615
7616 <?php if ( ! empty( $regular_modified ) ) : ?>
7617 <div class="vigilante-file-list vigilante-paginated-section" data-bulk-mode="ignore">
7618 <h3><?php esc_html_e( 'Modified Files', 'vigilante' ); ?></h3>
7619 <p class="description"><?php esc_html_e( 'These files (apparently) differ from the original WordPress or plugin versions.', 'vigilante' ); ?></p>
7620 <div class="vigilante-fi-bulk-bar">
7621 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
7622 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
7623 </div>
7624 <div class="vigilante-fi-pagination-wrap"></div>
7625 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
7626 <thead>
7627 <tr>
7628 <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>
7629 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
7630 <th style="width: 100px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
7631 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
7632 </tr>
7633 </thead>
7634 <tbody>
7635 <?php
7636 foreach ( $regular_modified as $item ) {
7637 $file_path = '';
7638 $file_type = 'unknown';
7639
7640 if ( is_array( $item ) ) {
7641 if ( isset( $item['file'] ) ) {
7642 $file_path = $item['file'];
7643 }
7644 if ( isset( $item['type'] ) ) {
7645 $file_type = $item['type'];
7646 }
7647 } else {
7648 $file_path = (string) $item;
7649 }
7650 if ( 'vigilante_self' === $file_type ) {
7651 $file_type = __( 'Vigilant (self)', 'vigilante' );
7652 }
7653 ?>
7654 <tr>
7655 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
7656 <td><code><?php echo esc_html( $file_path ); ?></code></td>
7657 <td><?php echo esc_html( $file_type ); ?></td>
7658 <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>
7659 </tr>
7660 <?php
7661 }
7662 ?>
7663 </tbody>
7664 </table>
7665 </div>
7666 <?php endif; ?>
7667
7668 <?php
7669 // "All files passed" is about every file, and Vigilant's own
7670 // are files too: with the self-protection box in red or amber
7671 // above, this line contradicted it (its findings no longer
7672 // travel in the tables below).
7673 $vg_self_alarm = in_array( $this->self_integrity_summary( $options )['tone'], array( 'critical', 'off', 'warning' ), true );
7674 ?>
7675 <?php if ( $last_results && ! $vg_self_alarm && empty( $critical_modified ) && empty( $regular_modified ) && empty( $last_results['suspicious'] ) && empty( $last_results['extra'] ) && ! $has_closed ) : ?>
7676 <p class="vigilante-all-clear" style="color: #00a32a; font-weight: bold;">
7677 <?php esc_html_e( 'Good Job! All files passed integrity check. No issues found.', 'vigilante' ); ?>
7678 </p>
7679 <?php endif; ?>
7680 <?php endif; ?>
7681 </div>
7682 </div>
7683 <?php endif; ?>
7684
7685 <?php if ( ! empty( $ignored_closed_plugins ) ) : ?>
7686 <div id="vigilante-section-fi-ignored-closed" class="vigilante-settings-section">
7687 <h2><?php esc_html_e( 'Ignored Closed + Removed Plugins', 'vigilante' ); ?></h2>
7688 <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>
7689 <table class="wp-list-table widefat fixed striped">
7690 <thead>
7691 <tr>
7692 <th><?php esc_html_e( 'Plugin', 'vigilante' ); ?></th>
7693 <th style="width: 110px;"><?php esc_html_e( 'State', 'vigilante' ); ?></th>
7694 <th style="width: 120px;"><?php esc_html_e( 'Closed date', 'vigilante' ); ?></th>
7695 <th style="width: 130px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
7696 </tr>
7697 </thead>
7698 <tbody>
7699 <?php foreach ( $ignored_closed_plugins as $icp_slug => $icp_entry ) :
7700 $icp_state = $icp_entry['state'] ?? '';
7701 $icp_state_label = 'closed' === $icp_state ? __( 'Closed', 'vigilante' ) : __( 'Removed', 'vigilante' );
7702 ?>
7703 <tr>
7704 <td>
7705 <strong><?php echo esc_html( $icp_entry['name'] ?? $icp_slug ); ?></strong><br>
7706 <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>
7707 </td>
7708 <td><?php echo esc_html( $icp_state_label ); ?></td>
7709 <td><?php echo esc_html( $icp_entry['closed_date'] ?? '' ); ?></td>
7710 <td>
7711 <button type="button" class="button button-small vigilante-unignore-closed-plugin" data-slug="<?php echo esc_attr( $icp_slug ); ?>">
7712 <?php esc_html_e( 'Stop ignoring', 'vigilante' ); ?>
7713 </button>
7714 </td>
7715 </tr>
7716 <?php endforeach; ?>
7717 </tbody>
7718 </table>
7719 <p style="margin-top: 10px;">
7720 <button type="button" class="button vigilante-clear-ignored-closed-plugins"><?php esc_html_e( 'Clear All Ignored Closed + Removed Plugins', 'vigilante' ); ?></button>
7721 </p>
7722 </div>
7723 <?php endif; ?>
7724
7725 <?php if ( ! empty( $ignored_files ) ) : ?>
7726 <div id="vigilante-section-fi-ignored" class="vigilante-settings-section">
7727 <h2><?php esc_html_e( 'Ignored Files', 'vigilante' ); ?></h2>
7728 <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>
7729 <div class="vigilante-paginated-section" data-bulk-mode="unignore">
7730 <div class="vigilante-fi-bulk-bar">
7731 <button type="button" class="button vigilante-bulk-unignore" disabled><?php esc_html_e( 'Stop ignoring selected', 'vigilante' ); ?></button>
7732 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
7733 </div>
7734 <div class="vigilante-fi-pagination-wrap"></div>
7735 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
7736 <thead>
7737 <tr>
7738 <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>
7739 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
7740 <th style="width: 120px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
7741 </tr>
7742 </thead>
7743 <tbody>
7744 <?php foreach ( $ignored_files as $file ) : ?>
7745 <tr>
7746 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file ); ?>"></th>
7747 <td><code><?php echo esc_html( $file ); ?></code></td>
7748 <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>
7749 </tr>
7750 <?php endforeach; ?>
7751 </tbody>
7752 </table>
7753 </div>
7754 <p style="margin-top: 10px;">
7755 <button type="button" class="button vigilante-clear-ignored"><?php esc_html_e( 'Clear All Ignored Files', 'vigilante' ); ?></button>
7756 </p>
7757 </div>
7758 <?php endif; ?>
7759 <?php
7760 }
7761
7762 /**
7763 * Render sidebar with promotional widgets
7764 */
7765 private function render_sidebar() {
7766 $promo_banner = new Vigilante_Promo_Banner( 'vigilante' );
7767 $promo_banner->render();
7768 }
7769
7770 /**
7771 * AJAX: Download a ZIP backup of the critical config files.
7772 *
7773 * Streams wp-config.php and .htaccess (and robots.txt if present) as a
7774 * downloadable archive. Config backups are no longer left as files under the
7775 * web root, so this hands the admin the archive directly.
7776 */
7777 public function ajax_download_files_backup() {
7778 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7779
7780 if ( ! current_user_can( 'manage_options' ) ) {
7781 wp_die( esc_html__( 'Permission denied.', 'vigilante' ), 403 );
7782 }
7783
7784 // The archive carries wp-config.php, which a whole network shares. On a
7785 // network manage_options is held by every subsite administrator, so the
7786 // same gate the writers use applies here.
7787 if ( ! Vigilante_Settings::can_write_shared_files() ) {
7788 wp_die( esc_html( Vigilante_Settings::get_shared_files_notice() ), 403 );
7789 }
7790
7791 $backup_manager = new Vigilante_Backup_Manager();
7792 $result = $backup_manager->stream_files_zip();
7793
7794 // stream_files_zip() exits on success; only a WP_Error returns here.
7795 if ( is_wp_error( $result ) ) {
7796 wp_die( esc_html( $result->get_error_message() ), 500 );
7797 }
7798 }
7799
7800 /**
7801 * AJAX: Save settings
7802 */
7803 public function ajax_save_settings() {
7804 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7805
7806 if ( ! current_user_can( 'manage_options' ) ) {
7807 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7808 }
7809
7810 $section = isset( $_POST['section'] ) ? sanitize_key( $_POST['section'] ) : '';
7811
7812 // Handle $_POST['data'] based on type
7813 if ( isset( $_POST['data'] ) && is_array( $_POST['data'] ) ) {
7814 $data = map_deep( wp_unslash( $_POST['data'] ), 'sanitize_text_field' );
7815 } elseif ( isset( $_POST['data'] ) ) {
7816 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
7817 $raw_data = wp_unslash( $_POST['data'] );
7818 parse_str( $raw_data, $data );
7819 $data = $this->sanitize_posted_settings( $data );
7820 } else {
7821 $data = array();
7822 }
7823
7824 if ( empty( $section ) ) {
7825 wp_send_json_error( __( 'Invalid section.', 'vigilante' ) );
7826 }
7827
7828 // Check if 2FA is being enabled or method changed (for notification sending)
7829 $send_2fa_notification = false;
7830 $send_login_url_notification = false;
7831
7832 if ( 'login_security' === $section ) {
7833 // Read old state from DB
7834 $db_options = get_option( Vigilante_Settings::OPTION_NAME, array() );
7835 $old_2fa_enabled = ! empty( $db_options['login_security']['two_factor']['enabled'] );
7836 $old_method = $db_options['login_security']['two_factor']['method'] ?? 'email';
7837
7838 // Check new state from submitted data
7839 $new_2fa_enabled = false;
7840 $notify_on_enable = false;
7841 $new_method = isset( $data['login_security']['two_factor']['method'] )
7842 ? sanitize_key( $data['login_security']['two_factor']['method'] )
7843 : 'email';
7844
7845 if ( isset( $data['login_security']['two_factor']['enabled'] ) ) {
7846 $new_2fa_enabled = filter_var( $data['login_security']['two_factor']['enabled'], FILTER_VALIDATE_BOOLEAN );
7847 }
7848 if ( isset( $data['login_security']['two_factor']['notify_on_enable'] ) ) {
7849 $notify_on_enable = filter_var( $data['login_security']['two_factor']['notify_on_enable'], FILTER_VALIDATE_BOOLEAN );
7850 }
7851
7852 // Send notification if:
7853 // 1. 2FA is being enabled (was off, now on) OR
7854 // 2. Method changed while 2FA is enabled
7855 if ( $notify_on_enable && $new_2fa_enabled ) {
7856 if ( ! $old_2fa_enabled || ( $old_2fa_enabled && $old_method !== $new_method ) ) {
7857 $send_2fa_notification = true;
7858 }
7859 }
7860
7861 // Check if login URL changed and notification is enabled
7862 $old_login_url = $db_options['login_security']['custom_login_url'] ?? '';
7863 $new_login_url = isset( $data['login_security']['custom_login_url'] )
7864 ? sanitize_title( $data['login_security']['custom_login_url'] )
7865 : '';
7866 $notify_on_url_change = isset( $data['login_security']['notify_on_login_url_change'] )
7867 ? filter_var( $data['login_security']['notify_on_login_url_change'], FILTER_VALIDATE_BOOLEAN )
7868 : false;
7869
7870 if ( $notify_on_url_change && ! empty( $new_login_url ) && $new_login_url !== $old_login_url ) {
7871 $send_login_url_notification = true;
7872 }
7873 }
7874
7875 // Get defaults
7876 $defaults = $this->settings->get_default_options();
7877
7878 // Read ONLY saved options from database (not merged with defaults)
7879 $saved_options = get_option( Vigilante_Settings::OPTION_NAME, array() );
7880
7881 // What is stored before this request changes anything: the shared file
7882 // settings this user may not change are put back from here (2.11.6).
7883 $stored_options = $saved_options;
7884 $locked = Vigilante_Settings::get_locked_file_settings();
7885
7886 if ( isset( $locked[ $section ] ) && true === $locked[ $section ] ) {
7887 wp_send_json_error( Vigilante_Settings::get_shared_files_notice() );
7888 }
7889
7890 // A module switch is a single key, so refusing says more than a success
7891 // that changed nothing, and the dashboard puts the toggle back.
7892 if ( 'modules' === $section && isset( $locked['modules'], $data['modules'] ) && is_array( $locked['modules'] ) && is_array( $data['modules'] ) ) {
7893 foreach ( array_keys( $data['modules'] ) as $vg_module ) {
7894 if ( in_array( sanitize_key( $vg_module ), $locked['modules'], true ) ) {
7895 wp_send_json_error( Vigilante_Settings::get_shared_files_notice() );
7896 }
7897 }
7898 }
7899
7900 $rejected_ips = array();
7901 $rejected_proxies = array();
7902
7903 // Handle modules
7904 if ( 'modules' === $section && isset( $data['modules'] ) ) {
7905 if ( ! isset( $saved_options['modules'] ) ) {
7906 $saved_options['modules'] = array();
7907 }
7908 foreach ( $data['modules'] as $module => $enabled ) {
7909 $module = sanitize_key( $module );
7910 $saved_options['modules'][ $module ] = in_array( $enabled, array( '1', 1, 'true', true ), true );
7911 }
7912 // Clear active preset when modules change
7913 update_option( 'vigilante_active_preset', '' );
7914 } else {
7915 // Process primary section
7916 if ( isset( $data[ $section ] ) && is_array( $data[ $section ] ) ) {
7917 $section_defaults = isset( $defaults[ $section ] ) ? $defaults[ $section ] : array();
7918 $current_section = isset( $saved_options[ $section ] ) ? $saved_options[ $section ] : array();
7919
7920 // Process the submitted data
7921 $processed = $this->process_section_data( $data[ $section ], $section_defaults, $current_section );
7922
7923 // The IP boxes are free text and, until 2.9.9, whatever was typed
7924 // went straight into the option. An entry the matcher can never
7925 // match still sits in a security list looking like protection,
7926 // so the ones that cannot match are dropped and reported back
7927 // instead of being stored in silence.
7928 $rejected_ips = $this->filter_ip_lists( $section, $processed, $rejected_proxies );
7929
7930 // Save the processed section
7931 $saved_options[ $section ] = $processed;
7932
7933 // Clear active preset when any section settings change
7934 update_option( 'vigilante_active_preset', '' );
7935 }
7936 }
7937
7938 // Clear cache before saving
7939 wp_cache_delete( Vigilante_Settings::OPTION_NAME, 'options' );
7940
7941 $saved_options = Vigilante_Settings::keep_locked_file_settings( $saved_options, $stored_options );
7942
7943 // Save to database
7944 update_option( Vigilante_Settings::OPTION_NAME, $saved_options );
7945
7946 // Clear the settings cache
7947 $this->settings->clear_cache();
7948
7949 // Apply changes based on section
7950 $this->apply_section_changes( $section, $saved_options );
7951
7952 // Send 2FA notifications after settings are saved
7953 $notification_result = null;
7954 if ( $send_2fa_notification ) {
7955 $notification_result = $this->send_2fa_enable_notifications();
7956 }
7957
7958 // Send login URL notifications after settings are saved
7959 $login_url_result = null;
7960 if ( $send_login_url_notification ) {
7961 $login_url_result = $this->send_login_url_notifications();
7962 }
7963
7964 // Build success message
7965 $message = __( 'Settings saved successfully.', 'vigilante' );
7966
7967 if ( $notification_result && $notification_result['sent'] > 0 ) {
7968 $message .= ' ' . sprintf(
7969 /* translators: %d: Number of emails sent */
7970 _n(
7971 '2FA notification sent to %d user.',
7972 '2FA notifications sent to %d users.',
7973 $notification_result['sent'],
7974 'vigilante'
7975 ),
7976 $notification_result['sent']
7977 );
7978 }
7979
7980 if ( $login_url_result && $login_url_result['sent'] > 0 ) {
7981 $message .= ' ' . sprintf(
7982 /* translators: %d: Number of emails sent */
7983 _n(
7984 'Login URL notification sent to %d user.',
7985 'Login URL notifications sent to %d users.',
7986 $login_url_result['sent'],
7987 'vigilante'
7988 ),
7989 $login_url_result['sent']
7990 );
7991 }
7992
7993 if ( ! empty( $rejected_ips ) ) {
7994 $message .= ' ' . sprintf(
7995 /* translators: %s: comma separated list of the entries that were not saved. */
7996 _n(
7997 'This entry is not a valid IP, CIDR range or wildcard, so it was not saved: %s',
7998 'These entries are not valid IPs, CIDR ranges or wildcards, so they were not saved: %s',
7999 count( $rejected_ips ),
8000 'vigilante'
8001 ),
8002 implode( ', ', array_map( 'esc_html', $rejected_ips ) )
8003 );
8004 }
8005
8006 if ( ! empty( $rejected_proxies ) ) {
8007 $message .= ' ' . sprintf(
8008 /* translators: %s: comma separated list of the trusted proxy entries that were not saved. */
8009 _n(
8010 'A trusted proxy must be an exact IP or a CIDR range, not a wildcard, so this entry was not saved: %s',
8011 'A trusted proxy must be an exact IP or a CIDR range, not a wildcard, so these entries were not saved: %s',
8012 count( $rejected_proxies ),
8013 'vigilante'
8014 ),
8015 implode( ', ', array_map( 'esc_html', $rejected_proxies ) )
8016 );
8017 }
8018
8019 wp_send_json_success( $message );
8020 }
8021
8022 /**
8023 * Keep only the IP patterns the matcher can actually match
8024 *
8025 * @since 2.9.9
8026 *
8027 * @param string $section Section being saved.
8028 * @param array $processed Section data, edited in place.
8029 * @return array Entries that were dropped, for the message back to the user.
8030 */
8031 private function filter_ip_lists( $section, &$processed, &$rejected_proxies = array() ) {
8032 $rejected_proxies = array();
8033
8034 // Trusted proxies feed an identity decision, so only exact addresses and
8035 // CIDR ranges belong there: a wildcard is stripped with its own message,
8036 // never stored looking effective. The matcher ignores it anyway (see
8037 // Vigilante_IP_Utils::in_list_ip_or_cidr), this stops it persisting.
8038 if ( 'firewall' === $section && isset( $processed['trusted_proxies'] ) && is_array( $processed['trusted_proxies'] ) ) {
8039 $split = Vigilante_IP_Utils::split_list_ip_or_cidr( $processed['trusted_proxies'] );
8040 $processed['trusted_proxies'] = $split['valid'];
8041 $rejected_proxies = $split['rejected'];
8042 }
8043
8044 $lists = array(
8045 'firewall' => array( 'ip_whitelist', 'ip_blacklist' ),
8046 'login_security' => array( 'ip_whitelist' ),
8047 );
8048
8049 if ( ! isset( $lists[ $section ] ) ) {
8050 return array();
8051 }
8052
8053 $rejected = array();
8054
8055 foreach ( $lists[ $section ] as $key ) {
8056 if ( ! isset( $processed[ $key ] ) || ! is_array( $processed[ $key ] ) ) {
8057 continue;
8058 }
8059
8060 $split = Vigilante_IP_Utils::split_list( $processed[ $key ] );
8061 $processed[ $key ] = $split['valid'];
8062 $rejected = array_merge( $rejected, $split['rejected'] );
8063 }
8064
8065 return array_values( array_unique( $rejected ) );
8066 }
8067
8068 /**
8069 * Send 2FA enable notifications to users
8070 *
8071 * @return array Result with 'sent' and 'failed' counts.
8072 */
8073 private function send_2fa_enable_notifications() {
8074 $result = array(
8075 'sent' => 0,
8076 'failed' => 0,
8077 );
8078
8079 // Get settings for roles and method
8080 $login_security = $this->settings->get_section( 'login_security' );
8081 $two_factor = isset( $login_security['two_factor'] ) ? $login_security['two_factor'] : array();
8082 $roles = isset( $two_factor['enforced_roles'] ) ? $two_factor['enforced_roles'] : array( 'administrator' );
8083 $method = isset( $two_factor['method'] ) ? $two_factor['method'] : 'email';
8084
8085 if ( empty( $roles ) ) {
8086 $roles = array( 'administrator' );
8087 }
8088
8089 $excluded = isset( $two_factor['excluded_users'] ) ? array_map( 'absint', $two_factor['excluded_users'] ) : array();
8090
8091 // Get users with these roles
8092 $args = array(
8093 'role__in' => $roles,
8094 );
8095 if ( ! empty( $excluded ) ) {
8096 // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- Small excluded users list from settings.
8097 $args['exclude'] = $excluded;
8098 }
8099 $users = get_users( $args );
8100
8101 if ( empty( $users ) ) {
8102 return $result;
8103 }
8104
8105 $site_name = get_bloginfo( 'name' );
8106 $from_name = ! empty( $two_factor['email_from_name'] ) ? $two_factor['email_from_name'] : $site_name;
8107
8108 if ( 'totp' === $method ) {
8109 // Use TOTP class for styled HTML emails
8110 if ( ! class_exists( 'Vigilante_Two_Factor_TOTP' ) ) {
8111 require_once VIGILANTE_INCLUDES_DIR . 'class-two-factor-totp.php';
8112 }
8113 $totp = new Vigilante_Two_Factor_TOTP( $this->settings, $this->database, $this->activity_log );
8114
8115 foreach ( $users as $user ) {
8116 // Skip users who already have TOTP configured
8117 $totp_data = $this->database->get_totp_data( $user->ID );
8118 if ( $totp_data && ! empty( $totp_data['is_configured'] ) ) {
8119 continue;
8120 }
8121
8122 $sent = $totp->send_activation_email( $user, $site_name, $from_name );
8123
8124 if ( $sent ) {
8125 $this->database->mark_2fa_notified( $user->ID );
8126 $result['sent']++;
8127 } else {
8128 $result['failed']++;
8129 }
8130 }
8131 } else {
8132 // Email method - use existing email 2FA class
8133 if ( ! class_exists( 'Vigilante_Two_Factor_Email' ) ) {
8134 require_once VIGILANTE_INCLUDES_DIR . 'class-two-factor-email.php';
8135 }
8136 $email_2fa = new Vigilante_Two_Factor_Email( $this->settings, $this->database, $this->activity_log );
8137 return $email_2fa->send_activation_notifications( false );
8138 }
8139
8140 return $result;
8141 }
8142
8143 /**
8144 * Send login URL change notifications to users with admin access
8145 *
8146 * @return array Result with 'sent' and 'failed' counts.
8147 */
8148 private function send_login_url_notifications() {
8149 $login_options = $this->settings->get_section( 'login_security' );
8150 $custom_url = ! empty( $login_options['custom_login_url'] ) ? sanitize_title( $login_options['custom_login_url'] ) : '';
8151
8152 if ( empty( $custom_url ) ) {
8153 return array( 'sent' => 0, 'failed' => 0 );
8154 }
8155
8156 $login_url = home_url( $custom_url . '/' );
8157 $site_name = get_bloginfo( 'name' );
8158
8159 $admin_roles = array( 'administrator', 'editor', 'author', 'contributor' );
8160 $users = get_users( array( 'role__in' => $admin_roles ) );
8161
8162 if ( empty( $users ) ) {
8163 return array( 'sent' => 0, 'failed' => 0 );
8164 }
8165
8166 $subject = sprintf(
8167 /* translators: %s: Site name */
8168 __( '[%s] Your login URL has changed', 'vigilante' ),
8169 $site_name
8170 );
8171
8172 $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' ) );
8173 $body .= Vigilante_Email_Template::url_box( $login_url, __( 'Your new login URL:', 'vigilante' ) );
8174 $body .= Vigilante_Email_Template::alert_box( __( 'The old login address (wp-login.php) will no longer work.', 'vigilante' ) );
8175 $body .= Vigilante_Email_Template::button( $login_url, __( 'Go to login', 'vigilante' ) );
8176
8177 $sent = 0;
8178 $failed = 0;
8179
8180 foreach ( $users as $user ) {
8181 $result = Vigilante_Email_Template::send(
8182 $user->user_email,
8183 $subject,
8184 __( 'Login URL changed', 'vigilante' ),
8185 $body
8186 );
8187 if ( $result ) {
8188 $sent++;
8189 } else {
8190 $failed++;
8191 }
8192 }
8193
8194 if ( $this->activity_log ) {
8195 $this->activity_log->log(
8196 'login',
8197 'login_url_notified',
8198 sprintf(
8199 /* translators: 1: Sent count, 2: Failed count */
8200 __( 'Login URL notification sent on save: %1$d sent, %2$d failed', 'vigilante' ),
8201 $sent,
8202 $failed
8203 )
8204 );
8205 }
8206
8207 return array( 'sent' => $sent, 'failed' => $failed );
8208 }
8209
8210 /**
8211 * Sanitize the settings a tab posted, once the serialized form is parsed
8212 *
8213 * Every value goes through sanitize_textarea_field() except the lists of
8214 * file paths (Vigilante_Settings::path_list_keys()). That one deletes every
8215 * %XX octet and, when it finds one, collapses repeated spaces, so an
8216 * exclusion for a folder called foto%20x was saved as fotox and excluded
8217 * nothing (measured on 1 oct 2026 against 3.0.1). The paths are read as
8218 * paths before the generic sanitizer runs and put back after it.
8219 *
8220 * @since 3.0.2
8221 *
8222 * @param array $data Parsed form: section => key => value.
8223 * @return array
8224 */
8225 private function sanitize_posted_settings( $data ) {
8226 $paths = Vigilante_Settings::take_path_lists( $data );
8227 $data = map_deep( $data, 'sanitize_textarea_field' );
8228
8229 return Vigilante_Settings::restore_path_lists( $data, $paths );
8230 }
8231
8232 /**
8233 * Sanitize an imported settings file, once it is decoded
8234 *
8235 * Same rule as sanitize_posted_settings(): the lists of paths keep what the
8236 * export wrote, so an exclusion survives an export and an import.
8237 *
8238 * @since 3.0.2
8239 *
8240 * @param array $imported Decoded export.
8241 * @return array
8242 */
8243 private function sanitize_imported_settings( $imported ) {
8244 $paths = Vigilante_Settings::take_path_lists( $imported );
8245 $imported = map_deep( $imported, 'sanitize_text_field' );
8246
8247 return Vigilante_Settings::restore_path_lists( $imported, $paths );
8248 }
8249
8250 /**
8251 * Process section data maintaining proper types from defaults
8252 *
8253 * @param array $submitted_data Data submitted from form.
8254 * @param array $defaults Default values for this section.
8255 * @param array $current Current saved values.
8256 * @param string $section_name Section name for special handling.
8257 * @return array Processed data.
8258 */
8259 private function process_section_data( $submitted_data, $defaults, $current, $section_name = '' ) {
8260 // Start with defaults, then merge current saved values. Lists are put
8261 // back whole afterwards: array_replace_recursive() merges them index by
8262 // index, so a saved list shorter than the default kept the default's
8263 // tail (see below, and Vigilante_Settings::array_merge_deep()).
8264 $result = array_replace_recursive( $defaults, $current );
8265 $result = $this->restore_lists( $result, $current );
8266
8267 // Process each submitted value
8268 foreach ( $submitted_data as $key => $value ) {
8269 $key = sanitize_key( $key );
8270
8271 if ( is_array( $value ) && $this->is_list_field( $key, $value, $defaults, $current ) ) {
8272 /*
8273 * A list of values, not a group of settings: the roles of a
8274 * checkbox group, the excluded user ids. What the form sent IS
8275 * the list, so it replaces the stored one outright.
8276 *
8277 * Until 3.0.1 this went through the recursion below, which
8278 * writes position by position and left every stored entry the
8279 * new list was too short to overwrite. Unchecking Editor in
8280 * "Enforce for roles" saved administrator over position 0 and
8281 * kept editor in position 1, so the box came back ticked
8282 * (reported on the support forum for 3.0.0, and the same bug
8283 * merge_preset() was fixed for in 2.9.8).
8284 *
8285 * Keys are dropped on purpose: a list is data, so anything the
8286 * request tried to name is not carried over. The empty string
8287 * is dropped too, which is what the hidden field that marks an
8288 * empty group sends.
8289 */
8290 $list = array();
8291 foreach ( $value as $entry ) {
8292 if ( ! is_scalar( $entry ) ) {
8293 continue;
8294 }
8295 $entry = sanitize_text_field( (string) $entry );
8296 if ( '' === $entry ) {
8297 continue;
8298 }
8299 $list[] = $entry;
8300 }
8301 $result[ $key ] = $list;
8302 } elseif ( is_array( $value ) ) {
8303 // Nested array (like rate_limiting)
8304 $nested_defaults = isset( $defaults[ $key ] ) && is_array( $defaults[ $key ] ) ? $defaults[ $key ] : array();
8305 $nested_current = isset( $result[ $key ] ) && is_array( $result[ $key ] ) ? $result[ $key ] : array();
8306 $result[ $key ] = $this->process_section_data( $value, $nested_defaults, $nested_current, $key );
8307 } else {
8308 // Determine type from default value
8309 $default_value = isset( $defaults[ $key ] ) ? $defaults[ $key ] : null;
8310
8311 if ( null === $default_value ) {
8312 // No default, check current value type or use as string
8313 $current_value = isset( $current[ $key ] ) ? $current[ $key ] : null;
8314 if ( is_bool( $current_value ) ) {
8315 $result[ $key ] = in_array( $value, array( '1', 1, 'true', true ), true );
8316 } elseif ( is_int( $current_value ) ) {
8317 $result[ $key ] = intval( $value );
8318 } elseif ( is_array( $current_value ) ) {
8319 $result[ $key ] = is_string( $value ) ? array_filter( array_map( 'trim', explode( "\n", $value ) ) ) : (array) $value;
8320 } else {
8321 $result[ $key ] = sanitize_text_field( $value );
8322 }
8323 } elseif ( is_bool( $default_value ) ) {
8324 // Boolean: '1', 1, 'true' become true; '0', 0, '', 'false' become false
8325 $result[ $key ] = in_array( $value, array( '1', 1, 'true', true ), true );
8326 } elseif ( is_int( $default_value ) ) {
8327 // Integer - with special handling for time fields shown in minutes
8328 $int_value = intval( $value );
8329
8330 // Convert minutes to seconds for login_security duration fields
8331 // These are displayed as minutes in the form but stored as seconds
8332 if ( in_array( $key, array( 'lockout_duration', 'max_lockout_duration' ), true ) ) {
8333 $int_value = $int_value * 60;
8334 }
8335
8336 $result[ $key ] = $int_value;
8337 } elseif ( is_array( $default_value ) ) {
8338 // Array from textarea (e.g., IP lists)
8339 if ( is_string( $value ) ) {
8340 $result[ $key ] = array_filter( array_map( 'trim', explode( "\n", $value ) ) );
8341 } else {
8342 $result[ $key ] = (array) $value;
8343 }
8344 } else {
8345 // String - preserve newlines for textarea fields
8346 if ( is_string( $value ) && ( strpos( $value, "\n" ) !== false || strpos( $value, "\r" ) !== false ) ) {
8347 $result[ $key ] = sanitize_textarea_field( $value );
8348 } else {
8349 $result[ $key ] = sanitize_text_field( $value );
8350 }
8351 }
8352 }
8353 }
8354
8355 // Handle unchecked checkboxes: HTML forms don't submit unchecked boxes
8356 // If a boolean field exists in defaults but NOT in submitted_data, set it to false
8357 //
8358 // EXCEPTION: the top-level 'enabled' flag of every section is the
8359 // module's master switch and is controlled by the Dashboard module
8360 // toggle, NOT by a checkbox inside the section's form. Treating it
8361 // like a regular checkbox here would silently switch the module off
8362 // every time the user saves the tab — see the REST API enabled=false
8363 // regression. We only skip it at the top level (when section_name is
8364 // empty); nested 'enabled' fields like security_headers.csp.enabled
8365 // are real checkboxes and must keep the auto-unset behaviour.
8366 $preserve_top_level = array( 'enabled' );
8367
8368 foreach ( $defaults as $key => $default_value ) {
8369 if ( '' === $section_name && in_array( $key, $preserve_top_level, true ) ) {
8370 continue;
8371 }
8372 if ( is_bool( $default_value ) && ! array_key_exists( $key, $submitted_data ) ) {
8373 $result[ $key ] = false;
8374 } elseif ( is_array( $default_value ) && ! isset( $submitted_data[ $key ] ) ) {
8375 // Check if this is a flat value list (like excluded_users, enforced_roles, ip_whitelist)
8376 // vs a nested settings group (like rate_limiting, two_factor)
8377 // Flat lists: default is empty array OR all values are scalar
8378 $is_value_list = empty( $default_value );
8379 if ( ! $is_value_list ) {
8380 $is_value_list = true;
8381 foreach ( $default_value as $dv ) {
8382 if ( ! is_scalar( $dv ) ) {
8383 $is_value_list = false;
8384 break;
8385 }
8386 }
8387 }
8388
8389 if ( $is_value_list ) {
8390 /*
8391 * A list whose key did not travel is left as it was. Until
8392 * 3.0.1 it was blanked here, which read "the user unticked
8393 * everything" into something the form never asked about:
8394 * saving the Firewall tab blanked allowed_http_methods,
8395 * which has no field on any screen, and saving Users blanked
8396 * insecure_usernames. Both survived only because reading the
8397 * option put the defaults back on top, and that is exactly
8398 * the merge being removed in this release: with lists
8399 * replaced whole, blanking here would have left a site
8400 * answering 403 to every HTTP method.
8401 *
8402 * Emptying a group is still possible, and is now said out
8403 * loud: each checkbox group prints a hidden field with an
8404 * empty value, so an empty group arrives as an empty list
8405 * instead of as silence. See list_sentinel().
8406 */
8407 continue;
8408 } else {
8409 // Nested settings group - handle boolean children
8410 foreach ( $default_value as $nested_key => $nested_default ) {
8411 if ( is_bool( $nested_default ) && isset( $result[ $key ] ) && is_array( $result[ $key ] ) ) {
8412 $nested_submitted = isset( $submitted_data[ $key ] ) && is_array( $submitted_data[ $key ] )
8413 ? $submitted_data[ $key ]
8414 : array();
8415 if ( ! array_key_exists( $nested_key, $nested_submitted ) ) {
8416 $result[ $key ][ $nested_key ] = false;
8417 }
8418 }
8419 }
8420 }
8421 }
8422 }
8423
8424 return $result;
8425 }
8426
8427 /**
8428 * Whether a submitted value is a list of values rather than a group of settings
8429 *
8430 * The difference decides whether what arrived replaces the stored value or
8431 * is merged into it key by key, so it is answered from what the setting is
8432 * (its default, or what is stored today), not from the shape of the
8433 * request. A request that sends named keys where a list belongs gets them
8434 * dropped, which is one way this is narrower than what it replaces.
8435 *
8436 * @since 3.0.1
8437 *
8438 * @param string $key Setting key, already through sanitize_key().
8439 * @param array $value Value as submitted.
8440 * @param array $defaults Defaults of the section being processed.
8441 * @param array $current Stored values of the section being processed.
8442 * @return bool
8443 */
8444 private function is_list_field( $key, $value, $defaults, $current ) {
8445 $default_known = array_key_exists( $key, $defaults ) && is_array( $defaults[ $key ] );
8446
8447 // The default has the first and the last word, the same rule that
8448 // array_merge_deep() and restore_lists() follow. Letting the stored
8449 // value decide, as this did until the fourth cross review of 3.0.1,
8450 // disagrees with them where it matters: an option corrupted into
8451 // two_factor = array( 'a', 'b' ) would have been treated as a list and
8452 // saving the tab would have replaced the whole group of settings with
8453 // the two values that arrived.
8454 if ( $default_known && array() !== $defaults[ $key ] ) {
8455 return Vigilante_Settings::is_list( $defaults[ $key ] );
8456 }
8457
8458 // Nothing declares it either way (an empty default, or a key with no
8459 // default at all), so what is stored, and then what was submitted, is
8460 // all there is to go on.
8461 if ( isset( $current[ $key ] ) && is_array( $current[ $key ] ) && array() !== $current[ $key ] && Vigilante_Settings::is_list( $current[ $key ] ) ) {
8462 return true;
8463 }
8464
8465 return Vigilante_Settings::is_list( $value );
8466 }
8467
8468 /**
8469 * Put stored lists back after array_replace_recursive()
8470 *
8471 * array_replace_recursive() merges a list by position, so a stored list
8472 * shorter than the default comes out with the default's tail attached:
8473 * ['administrator'] over ['administrator','editor'] gives both back. Every
8474 * list that is stored is therefore restored whole before anything else is
8475 * processed, and only associative arrays are walked into.
8476 *
8477 * @since 3.0.1
8478 *
8479 * @param array $result Defaults with the stored values merged over them.
8480 * @param array $current Stored values.
8481 * @return array
8482 */
8483 private function restore_lists( $result, $current ) {
8484 if ( ! is_array( $current ) ) {
8485 return $result;
8486 }
8487
8488 foreach ( $current as $key => $value ) {
8489 if ( ! is_array( $value ) || ! isset( $result[ $key ] ) || ! is_array( $result[ $key ] ) ) {
8490 continue;
8491 }
8492
8493 // Decided by what is in $result, which comes from the defaults, and
8494 // never by the stored value: array() is a list by any definition, so
8495 // a section stored empty would have replaced a whole group of
8496 // settings with nothing. Same reasoning as in array_merge_deep().
8497 if ( Vigilante_Settings::is_list( $result[ $key ] ) ) {
8498 $result[ $key ] = $value;
8499 continue;
8500 }
8501
8502 $result[ $key ] = $this->restore_lists( $result[ $key ], $value );
8503 }
8504
8505 return $result;
8506 }
8507
8508 /**
8509 * Print the hidden field that lets a checkbox group arrive empty
8510 *
8511 * A checkbox group sends nothing at all when every box is unticked, which
8512 * is indistinguishable from a form that never had that field. Since 3.0.1
8513 * the save path leaves an absent list alone, so the difference has to be
8514 * stated: this empty entry always travels, and the save path drops empty
8515 * strings, so an untouched group arrives as an empty list.
8516 *
8517 * @since 3.0.1
8518 *
8519 * @param string $name Field name without the trailing [].
8520 */
8521 private function list_sentinel( $name ) {
8522 printf( '<input type="hidden" name="%s[]" value="">', esc_attr( $name ) );
8523 }
8524
8525 /**
8526 * AJAX: Export settings
8527 */
8528 public function ajax_export_settings() {
8529 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8530
8531 if ( ! current_user_can( 'manage_options' ) ) {
8532 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8533 }
8534
8535 $options = $this->settings->get_all_options();
8536 $filename = 'vigilante-settings-' . gmdate( 'Y-m-d-His' ) . '.json';
8537
8538 wp_send_json_success( array(
8539 'content' => wp_json_encode( $options, JSON_PRETTY_PRINT ),
8540 'filename' => $filename,
8541 ) );
8542 }
8543
8544 /**
8545 * AJAX: Import settings
8546 */
8547 public function ajax_import_settings() {
8548 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8549
8550 if ( ! current_user_can( 'manage_options' ) ) {
8551 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8552 }
8553
8554 // Accept both 'settings' (from JS) and 'content' (legacy).
8555 // Do NOT run sanitize_text_field() on the raw payload: it calls
8556 // wp_strip_all_tags() internally, which removes any "<...>" substring
8557 // and turns a valid export JSON into garbage if any stored value
8558 // contains < or > (htaccess snippets, email templates, etc.). The
8559 // real sanitization happens after json_decode(), via map_deep() on
8560 // the parsed array.
8561 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash
8562 $content = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : '';
8563 if ( empty( $content ) ) {
8564 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash
8565 $content = isset( $_POST['content'] ) ? wp_unslash( $_POST['content'] ) : '';
8566 }
8567
8568 if ( empty( $content ) || ! is_string( $content ) ) {
8569 wp_send_json_error( __( 'No content provided.', 'vigilante' ) );
8570 }
8571
8572 $imported = json_decode( $content, true );
8573
8574 if ( json_last_error() !== JSON_ERROR_NONE || ! is_array( $imported ) ) {
8575 wp_send_json_error( __( 'Invalid JSON format.', 'vigilante' ) );
8576 }
8577
8578 // Sanitize imported data recursively
8579 $imported = $this->sanitize_imported_settings( $imported );
8580
8581 // Validate structure: only sections and keys of the schema survive, and
8582 // every value takes the type of its default. Until 2.11.0 this was an
8583 // array_replace_recursive() of the file over the defaults, so any key in
8584 // the file, known or not, landed in vigilante_options (S7). Sections
8585 // the file does not carry keep their defaults; a section it does carry
8586 // replaces the default one whole, because validate_options() has
8587 // already filled in whatever the file left out.
8588 $defaults = $this->settings->get_default_options();
8589 $validated = $this->settings->validate_options( $imported );
8590 $merged = $defaults;
8591
8592 foreach ( $validated as $section => $data ) {
8593 if ( is_array( $data ) ) {
8594 $merged[ $section ] = $data;
8595 }
8596 }
8597
8598 // Save
8599 $merged = Vigilante_Settings::keep_locked_file_settings( $merged, get_option( Vigilante_Settings::OPTION_NAME, array() ) );
8600 update_option( Vigilante_Settings::OPTION_NAME, $merged );
8601 $this->settings->clear_cache();
8602
8603 // Re-evaluate the active preset marker. The imported config may match
8604 // a known preset exactly, partially, or not at all — without this step
8605 // the dashboard would keep showing whatever preset was active before
8606 // the import even if the new config no longer matches it.
8607 $matched_preset = $this->detect_matching_preset( $merged );
8608 if ( null === $matched_preset ) {
8609 delete_option( 'vigilante_active_preset' );
8610 } else {
8611 update_option( 'vigilante_active_preset', $matched_preset );
8612 }
8613
8614 // Apply file changes after import
8615 $this->apply_all_file_changes( $merged );
8616
8617 // Refresh the Security Analyzer score so the dashboard widget reflects
8618 // the imported config rather than the pre-import scan. Reuse the
8619 // post-Under-Attack scan hook (same job: full scan, async).
8620 if ( ! wp_next_scheduled( 'vigilante_under_attack_post_scan' ) ) {
8621 wp_schedule_single_event( time() + 5, 'vigilante_under_attack_post_scan' );
8622 }
8623
8624 wp_send_json_success( __( 'Settings imported successfully.', 'vigilante' ) . $this->locked_file_settings_message() );
8625 }
8626
8627 /**
8628 * Detect whether a vigilante_options array matches a known preset.
8629 *
8630 * A preset matches when every field the preset explicitly declares is
8631 * present in the config with the same (normalised) value. Fields outside
8632 * the preset are ignored — they may have been modified by the user before
8633 * applying the preset and do not invalidate the match. This mirrors how
8634 * apply_preset() now layers presets on top of the user's existing config.
8635 *
8636 * @param array $options The current/imported vigilante_options.
8637 * @return string|null Preset id ('standard', 'maximum') or null if custom.
8638 */
8639 private function detect_matching_preset( $options ) {
8640 if ( ! is_array( $options ) ) {
8641 return null;
8642 }
8643
8644 $presets = $this->settings->get_presets();
8645
8646 foreach ( $presets as $preset_id => $preset_data ) {
8647 unset( $preset_data['name'], $preset_data['description'] );
8648 if ( $this->preset_subset_matches( $preset_data, $options ) ) {
8649 return $preset_id;
8650 }
8651 }
8652
8653 return null;
8654 }
8655
8656 /**
8657 * Check whether every leaf value inside $preset_subset exists with the
8658 * same (normalised) value at the same path inside $config.
8659 *
8660 * @param mixed $preset_subset Branch of the preset definition.
8661 * @param mixed $config Same branch in the live/imported config.
8662 * @return bool
8663 */
8664 private function preset_subset_matches( $preset_subset, $config ) {
8665 if ( is_array( $preset_subset ) ) {
8666 if ( ! is_array( $config ) ) {
8667 return false;
8668 }
8669 foreach ( $preset_subset as $key => $value ) {
8670 if ( ! array_key_exists( $key, $config ) ) {
8671 return false;
8672 }
8673 if ( ! $this->preset_subset_matches( $value, $config[ $key ] ) ) {
8674 return false;
8675 }
8676 }
8677 return true;
8678 }
8679
8680 return $this->normalise_scalar_for_compare( $preset_subset ) === $this->normalise_scalar_for_compare( $config );
8681 }
8682
8683 /**
8684 * Normalise a scalar value so that the variants WordPress and the form
8685 * layer routinely produce ('1' / 1 / true → "1"; '' / '0' / 0 / false /
8686 * null → "") compare equal. Other values become strings unchanged.
8687 *
8688 * @param mixed $value
8689 * @return string
8690 */
8691 private function normalise_scalar_for_compare( $value ) {
8692 if ( is_bool( $value ) ) {
8693 return $value ? '1' : '';
8694 }
8695 if ( null === $value ) {
8696 return '';
8697 }
8698 if ( is_int( $value ) || is_float( $value ) ) {
8699 return (string) $value;
8700 }
8701 if ( is_string( $value ) ) {
8702 if ( 'true' === $value ) {
8703 return '1';
8704 }
8705 if ( 'false' === $value ) {
8706 return '';
8707 }
8708 return $value;
8709 }
8710 // Arrays and objects shouldn't reach here (handled by recursion above),
8711 // but if they do, fall back to a stable comparable representation.
8712 return wp_json_encode( $value );
8713 }
8714
8715 /**
8716 * AJAX: Apply preset
8717 */
8718 public function ajax_apply_preset() {
8719 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8720
8721 if ( ! current_user_can( 'manage_options' ) ) {
8722 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8723 }
8724
8725 $preset = isset( $_POST['preset'] ) ? sanitize_key( $_POST['preset'] ) : '';
8726
8727 // Handle reset to defaults
8728 if ( 'reset' === $preset ) {
8729 $stored_options = get_option( Vigilante_Settings::OPTION_NAME, array() );
8730 $defaults = Vigilante_Settings::get_defaults_preserving_user_data( $stored_options );
8731 $defaults = Vigilante_Settings::keep_locked_file_settings( $defaults, $stored_options );
8732 update_option( Vigilante_Settings::OPTION_NAME, $defaults );
8733 $this->settings->clear_cache();
8734
8735 // Clear active preset
8736 update_option( 'vigilante_active_preset', '' );
8737
8738 // Apply file changes after reset
8739 $this->apply_all_file_changes( $defaults );
8740
8741 wp_send_json_success( __( 'Settings reset to defaults.', 'vigilante' ) . $this->locked_file_settings_message() );
8742 return;
8743 }
8744
8745 $presets = $this->settings->get_presets();
8746
8747 if ( ! isset( $presets[ $preset ] ) ) {
8748 wp_send_json_error( __( 'Invalid preset.', 'vigilante' ) );
8749 }
8750
8751 $preset_options = $presets[ $preset ];
8752 unset( $preset_options['name'], $preset_options['description'] );
8753
8754 // Layer the preset on top of the user's CURRENT configuration, not on
8755 // top of defaults. This way applying a preset only changes the fields
8756 // the preset explicitly mentions; everything else stays as the user
8757 // had it. For example, applying Maximum will not flip HSTS off if the
8758 // user had it on — Maximum doesn't touch HSTS, so it's left alone.
8759 // Use "Reset to Defaults" if a clean slate is needed.
8760 $current = get_option( Vigilante_Settings::OPTION_NAME, array() );
8761 if ( ! is_array( $current ) ) {
8762 $current = array();
8763 }
8764 // Make sure all known keys exist before merging — the merge does not
8765 // invent keys that are missing on both sides.
8766 $current = Vigilante_Settings::merge_preset( $this->settings->get_default_options(), $current );
8767
8768 $merged = Vigilante_Settings::merge_preset( $current, $preset_options );
8769 $merged = Vigilante_Settings::keep_locked_file_settings( $merged, get_option( Vigilante_Settings::OPTION_NAME, array() ) );
8770
8771 update_option( Vigilante_Settings::OPTION_NAME, $merged );
8772 $this->settings->clear_cache();
8773
8774 // Save active preset
8775 update_option( 'vigilante_active_preset', $preset );
8776
8777 // Apply file changes after preset
8778 $this->apply_all_file_changes( $merged );
8779
8780 wp_send_json_success( __( 'Preset applied successfully.', 'vigilante' ) . $this->locked_file_settings_message() );
8781 }
8782
8783 /**
8784 * AJAX: Reset a specific section to defaults
8785 */
8786 public function ajax_reset_section() {
8787 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8788
8789 if ( ! current_user_can( 'manage_options' ) ) {
8790 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8791 }
8792
8793 $section = isset( $_POST['section'] ) ? sanitize_key( $_POST['section'] ) : '';
8794
8795 if ( empty( $section ) ) {
8796 wp_send_json_error( __( 'No section specified.', 'vigilante' ) );
8797 }
8798
8799 // Get current options and defaults. get_defaults_preserving_user_data()
8800 // applies the tweaks a fresh installation gets, so the button and a new
8801 // install agree, and keeps whatever the owner typed in.
8802 $current_options = $this->settings->get_all_options();
8803 $defaults = Vigilante_Settings::get_defaults_preserving_user_data( $current_options );
8804
8805 // Check if section exists in defaults
8806 if ( ! isset( $defaults[ $section ] ) ) {
8807 wp_send_json_error( __( 'Invalid section.', 'vigilante' ) );
8808 }
8809
8810 $new_values = $defaults[ $section ];
8811
8812 /*
8813 * On a subsite, the settings written to wp-config.php and .htaccess are
8814 * the main site's business. Resetting the local copy of those would only
8815 * make this screen disagree with the file, so they are carried over
8816 * untouched, and a section that is nothing but shared settings is not
8817 * reset at all. On the main site, a user without network rights keeps
8818 * the ones the shared files are built from as well (2.11.6).
8819 */
8820 $locked = Vigilante_Settings::get_locked_file_settings();
8821
8822 if ( isset( $locked[ $section ] ) && true === $locked[ $section ] ) {
8823 wp_send_json_error( Vigilante_Settings::get_shared_files_notice() );
8824 }
8825
8826 $current_options[ $section ] = $new_values;
8827 $current_options = Vigilante_Settings::keep_locked_file_settings( $current_options, get_option( Vigilante_Settings::OPTION_NAME, array() ) );
8828
8829 // Save
8830 update_option( Vigilante_Settings::OPTION_NAME, $current_options );
8831 $this->settings->clear_cache();
8832
8833 // Apply file changes if needed
8834 $this->apply_section_changes( $section, $current_options );
8835
8836 wp_send_json_success( array(
8837 'message' => __( 'Section reset to defaults.', 'vigilante' ),
8838 'section' => $section,
8839 'reload' => true,
8840 ) );
8841 }
8842
8843 /**
8844 * AJAX: Clear lockouts
8845 */
8846 public function ajax_clear_lockouts() {
8847 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8848
8849 if ( ! current_user_can( 'manage_options' ) ) {
8850 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8851 }
8852
8853 $ip = isset( $_POST['ip'] ) ? sanitize_text_field( wp_unslash( $_POST['ip'] ) ) : '';
8854
8855 if ( ! empty( $ip ) ) {
8856 $this->database->clear_lockout( $ip );
8857 } else {
8858 $this->database->clear_all_lockouts();
8859 }
8860
8861 wp_send_json_success( __( 'Lockouts cleared.', 'vigilante' ) );
8862 }
8863
8864 /**
8865 * AJAX: Clear logs
8866 */
8867 public function ajax_clear_logs() {
8868 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8869
8870 if ( ! current_user_can( 'manage_options' ) ) {
8871 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8872 }
8873
8874 if ( $this->activity_log ) {
8875 $result = $this->activity_log->clear_all_logs();
8876 if ( $result ) {
8877 wp_send_json_success( __( 'Logs cleared.', 'vigilante' ) );
8878 } else {
8879 wp_send_json_error( __( 'Failed to clear logs.', 'vigilante' ) );
8880 }
8881 } else {
8882 wp_send_json_error( __( 'Activity log not available.', 'vigilante' ) );
8883 }
8884 }
8885
8886 /**
8887 * AJAX: Run file integrity scan.
8888 *
8889 * Triggers the file integrity scan, which now also runs the closed plugins
8890 * check at the end when the `check_closed_plugins` toggle is on. Activity
8891 * log is passed through so Security Audit entries (both file-level and
8892 * plugin-status) are recorded from this entry point.
8893 */
8894 public function ajax_run_scan() {
8895 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8896
8897 if ( ! current_user_can( 'manage_options' ) ) {
8898 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8899 }
8900
8901 // Clear previous results before running new scan
8902 delete_option( 'vigilante_last_integrity_results' );
8903 delete_option( 'vigilante_last_integrity_scan' );
8904
8905 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database, $this->activity_log );
8906 $results = $file_integrity->run_scan();
8907
8908 // Save new results
8909 update_option( 'vigilante_last_integrity_scan', time() );
8910 update_option( 'vigilante_last_integrity_results', $results );
8911
8912 // On the main site the scan does compute the lines of wp-config.php and
8913 // .htaccess, for the network administrator. Somebody without network
8914 // rights gets the change and its sizes, not the lines.
8915 if ( $this->critical_approval_locked() && ! empty( $results['modified'] ) && is_array( $results['modified'] ) ) {
8916 foreach ( $results['modified'] as $index => $item ) {
8917 if ( is_array( $item ) && 'critical_config' === ( $item['type'] ?? '' ) ) {
8918 $results['modified'][ $index ]['diff'] = Vigilante_File_Integrity::network_only_diff();
8919 }
8920 }
8921 }
8922
8923 wp_send_json_success( array(
8924 'message' => __( 'Scan completed.', 'vigilante' ),
8925 'results' => $results,
8926 'ignored_count' => count( get_option( 'vigilante_ignored_files', array() ) ),
8927 ) );
8928 }
8929
8930 /**
8931 * AJAX: Clear scan results.
8932 *
8933 * Wipes visually everything inside "Last Scan Results": file scan findings
8934 * (Suspicious / Modified / Extra / Critical Config), file hashes and the
8935 * Closed + Removed Plugins block.
8936 *
8937 * Implementation detail to keep persistence intact:
8938 * - We delete the file scan options + hashes outright.
8939 * - For plugin status we ONLY delete the last_check timestamp — the state
8940 * map and the ignore list are preserved in DB. The render gates the
8941 * plugin_status subsections on last_check > 0, so they hide after
8942 * Clear (visual reset) and reappear on the next Run Scan Now with the
8943 * state intact. This avoids degrading a 'removed' slug (404 without
8944 * metadata) back to 'not_in_repo' on the next scan, which would
8945 * silently lose the alert.
8946 *
8947 * The Ignored Files list and the Ignored Closed + Removed Plugins list
8948 * are preserved on purpose; each has its own explicit "Clear All …"
8949 * button.
8950 */
8951 public function ajax_clear_scan() {
8952 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8953
8954 if ( ! current_user_can( 'manage_options' ) ) {
8955 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8956 }
8957
8958 $results = get_option( 'vigilante_last_integrity_results' );
8959 $scanned_at = get_option( 'vigilante_last_integrity_scan' );
8960
8961 delete_option( 'vigilante_last_integrity_results' );
8962 delete_option( 'vigilante_last_integrity_scan' );
8963
8964 /*
8965 * A pending change to wp-config.php or the root .htaccess is closed by
8966 * approving it, which takes the network. Clearing the results was one
8967 * more way to close it without, until the next scan: the ignore list was
8968 * shut in 2.11.8 and this button was left open, found by the cross
8969 * review of 2.11.8. So for somebody who cannot approve, those entries
8970 * stay and everything else goes.
8971 */
8972 // The findings about Vigilant's own files stay too: they report for the
8973 // whole network, and ignoring them already takes network rights.
8974 if ( $this->critical_approval_locked() && is_array( $results ) ) {
8975 $kept = array();
8976 $found = false;
8977 foreach ( array( 'modified', 'missing', 'suspicious', 'extra' ) as $bucket ) {
8978 $kept[ $bucket ] = array_values(
8979 array_filter(
8980 isset( $results[ $bucket ] ) && is_array( $results[ $bucket ] ) ? $results[ $bucket ] : array(),
8981 function ( $item ) {
8982 return is_array( $item ) && in_array( $item['type'] ?? '', array( 'critical_config', 'vigilante_self' ), true );
8983 }
8984 )
8985 );
8986 $found = $found || ! empty( $kept[ $bucket ] );
8987 }
8988
8989 if ( $found ) {
8990 $results = array_merge( $results, $kept );
8991 update_option( 'vigilante_last_integrity_results', $results );
8992 update_option( 'vigilante_last_integrity_scan', $scanned_at ? $scanned_at : time() );
8993 }
8994 }
8995
8996 if ( $this->database ) {
8997 $this->database->clear_file_hashes();
8998 }
8999
9000 // Visual reset of plugin_status block without touching the state map
9001 // or the ignored list. See PHPDoc above for the rationale.
9002 delete_option( 'vigilante_plugin_status_last_check' );
9003
9004 wp_send_json_success( __( 'Scan results cleared.', 'vigilante' ) );
9005 }
9006
9007 /**
9008 * AJAX: Ignore a file from scan results
9009 */
9010 public function ajax_ignore_file() {
9011 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9012
9013 if ( ! current_user_can( 'manage_options' ) ) {
9014 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9015 }
9016
9017 /*
9018 * The path as the scan reported it, which is what the interface sends
9019 * back. sanitize_text_field() is the wrong reader for it: it deletes
9020 * every %XX octet and collapses repeated spaces, so a file named
9021 * foto%20nueva.php was stored as fotonueva.php, the scan compared the
9022 * list with the paths it finds one by one, never matched, and the
9023 * warning came back (measured on 1 oct 2026 against 3.0.1). The four
9024 * handlers of the ignore list read the path the same way.
9025 *
9026 * Known limits, found by the cross review, that only a file name with a
9027 * stray < in it reaches. wp_strip_all_tags() shortens such a name at the
9028 * < instead of refusing it, so the stored entry can match another file
9029 * (a.php<b is stored as a.php), and the value ignore_file() returns is
9030 * not read, so a refusal of its own is answered as success. The fix, if
9031 * a site ever needs it, is to answer with an error when
9032 * wp_strip_all_tags() changes what was sent and to check that return
9033 * value. An entry the old reader stored for such a name (it wrote the
9034 * < as &lt;) is listed but "Stop ignoring" cannot remove it; "Clear all
9035 * ignored files" does.
9036 */
9037 $file = ( isset( $_POST['file'] ) && is_string( $_POST['file'] ) ) ? wp_strip_all_tags( wp_unslash( $_POST['file'] ) ) : '';
9038
9039 if ( empty( $file ) ) {
9040 wp_send_json_error( __( 'No file specified.', 'vigilante' ) );
9041 }
9042
9043 // A change to a shared file is closed by approving it, and approving it
9044 // takes the network. Ignoring it would close the same warning without.
9045 if ( $this->critical_approval_locked() && in_array( $file, array( 'wp-config.php', '.htaccess' ), true ) ) {
9046 wp_send_json_error( $this->critical_approval_notice() );
9047 }
9048
9049 // Vigilant's own files are never ignored, on any site: silencing the
9050 // check that says the security plugin was changed is the one button
9051 // an attacker would want on this screen. Since 3.0.0 those findings
9052 // are not rows of these tables either, so nothing in the interface
9053 // sends them here; this is the door, not the label.
9054 if ( Vigilante_Self_Integrity::is_own_file_path( $file ) ) {
9055 wp_send_json_error( __( 'Findings about Vigilant own files cannot be ignored. File Integrity explains what each one means and how to repair it.', 'vigilante' ) );
9056 }
9057
9058 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
9059 $file_integrity->ignore_file( $file );
9060
9061 // Also remove the file from stored scan results so UI updates
9062 $results = get_option( 'vigilante_last_integrity_results' );
9063 if ( $results ) {
9064 foreach ( array( 'modified', 'suspicious', 'extra' ) as $category ) {
9065 if ( ! empty( $results[ $category ] ) ) {
9066 $results[ $category ] = array_values(
9067 array_filter(
9068 $results[ $category ],
9069 function ( $item ) use ( $file ) {
9070 return ( is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item ) !== $file;
9071 }
9072 )
9073 );
9074 }
9075 }
9076 update_option( 'vigilante_last_integrity_results', $results );
9077 }
9078
9079 wp_send_json_success( __( 'File added to ignored list.', 'vigilante' ) );
9080 }
9081
9082 /**
9083 * AJAX: Stop ignoring a file
9084 */
9085 public function ajax_unignore_file() {
9086 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9087
9088 if ( ! current_user_can( 'manage_options' ) ) {
9089 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9090 }
9091
9092 $file = ( isset( $_POST['file'] ) && is_string( $_POST['file'] ) ) ? wp_strip_all_tags( wp_unslash( $_POST['file'] ) ) : '';
9093
9094 if ( empty( $file ) ) {
9095 wp_send_json_error( __( 'No file specified.', 'vigilante' ) );
9096 }
9097
9098 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
9099 $file_integrity->unignore_file( $file );
9100
9101 wp_send_json_success( __( 'File removed from ignored list.', 'vigilante' ) );
9102 }
9103
9104 /**
9105 * AJAX: Bulk ignore multiple files at once
9106 *
9107 * Processes a single batch into ignored list and prunes them from the
9108 * stored scan results so the UI updates without a re-scan.
9109 */
9110 public function ajax_bulk_ignore_files() {
9111 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9112
9113 if ( ! current_user_can( 'manage_options' ) ) {
9114 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9115 }
9116
9117 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized below per-item.
9118 $raw_files = isset( $_POST['files'] ) ? wp_unslash( $_POST['files'] ) : array();
9119 if ( ! is_array( $raw_files ) ) {
9120 wp_send_json_error( __( 'Invalid request.', 'vigilante' ) );
9121 }
9122
9123 $files = array();
9124 $locked = $this->critical_approval_locked();
9125 $shared = $locked ? array( 'wp-config.php', '.htaccess' ) : array();
9126 foreach ( $raw_files as $f ) {
9127 $clean = is_string( $f ) ? wp_strip_all_tags( $f ) : '';
9128 // Same rule as ajax_ignore_file(): the two shared files when the
9129 // network locks them, and Vigilant's own files always.
9130 if ( '' !== $clean && ! in_array( $clean, $shared, true ) && ! Vigilante_Self_Integrity::is_own_file_path( $clean ) ) {
9131 $files[] = $clean;
9132 }
9133 }
9134
9135 if ( empty( $files ) ) {
9136 wp_send_json_error( __( 'No files selected.', 'vigilante' ) );
9137 }
9138
9139 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
9140 $count = 0;
9141 foreach ( $files as $file ) {
9142 $file_integrity->ignore_file( $file );
9143 $count++;
9144 }
9145
9146 // Also prune the stored scan results so the UI matches the new ignore list.
9147 $results = get_option( 'vigilante_last_integrity_results' );
9148 if ( $results ) {
9149 $files_set = array_flip( $files );
9150 foreach ( array( 'modified', 'suspicious', 'extra' ) as $category ) {
9151 if ( ! empty( $results[ $category ] ) ) {
9152 $results[ $category ] = array_values(
9153 array_filter(
9154 $results[ $category ],
9155 function ( $item ) use ( $files_set ) {
9156 $path = is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item;
9157 return ! isset( $files_set[ $path ] );
9158 }
9159 )
9160 );
9161 }
9162 }
9163 update_option( 'vigilante_last_integrity_results', $results );
9164 }
9165
9166 wp_send_json_success(
9167 array(
9168 'count' => $count,
9169 'message' => sprintf(
9170 /* translators: %d: number of files added to the ignored list */
9171 _n( '%d file added to ignored list.', '%d files added to ignored list.', $count, 'vigilante' ),
9172 $count
9173 ),
9174 )
9175 );
9176 }
9177
9178 /**
9179 * AJAX: Bulk un-ignore multiple files at once
9180 */
9181 public function ajax_bulk_unignore_files() {
9182 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9183
9184 if ( ! current_user_can( 'manage_options' ) ) {
9185 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9186 }
9187
9188 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized below per-item.
9189 $raw_files = isset( $_POST['files'] ) ? wp_unslash( $_POST['files'] ) : array();
9190 if ( ! is_array( $raw_files ) ) {
9191 wp_send_json_error( __( 'Invalid request.', 'vigilante' ) );
9192 }
9193
9194 $files = array();
9195 foreach ( $raw_files as $f ) {
9196 $clean = is_string( $f ) ? wp_strip_all_tags( $f ) : '';
9197 if ( '' !== $clean ) {
9198 $files[] = $clean;
9199 }
9200 }
9201
9202 if ( empty( $files ) ) {
9203 wp_send_json_error( __( 'No files selected.', 'vigilante' ) );
9204 }
9205
9206 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
9207 $count = 0;
9208 foreach ( $files as $file ) {
9209 $file_integrity->unignore_file( $file );
9210 $count++;
9211 }
9212
9213 wp_send_json_success(
9214 array(
9215 'count' => $count,
9216 'message' => sprintf(
9217 /* translators: %d: number of files removed from the ignored list */
9218 _n( '%d file removed from ignored list.', '%d files removed from ignored list.', $count, 'vigilante' ),
9219 $count
9220 ),
9221 )
9222 );
9223 }
9224
9225 /**
9226 * AJAX: Clear all ignored files
9227 */
9228 public function ajax_clear_ignored() {
9229 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9230
9231 if ( ! current_user_can( 'manage_options' ) ) {
9232 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9233 }
9234
9235 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
9236 $file_integrity->clear_ignored_files();
9237
9238 wp_send_json_success( __( 'Ignored files list cleared.', 'vigilante' ) );
9239 }
9240
9241 /**
9242 * AJAX: Ignore a closed/removed plugin slug so it stops appearing in the
9243 * main list and email digests. The plugin keeps running on the site;
9244 * silencing is purely cosmetic and reversible.
9245 */
9246 public function ajax_ignore_closed_plugin() {
9247 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9248
9249 if ( ! current_user_can( 'manage_options' ) ) {
9250 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9251 }
9252
9253 $slug = isset( $_POST['slug'] ) ? sanitize_key( wp_unslash( $_POST['slug'] ) ) : '';
9254 if ( '' === $slug ) {
9255 wp_send_json_error( __( 'No slug specified.', 'vigilante' ) );
9256 }
9257
9258 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
9259 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
9260 }
9261 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
9262 $checker->ignore_slug( $slug );
9263
9264 wp_send_json_success( __( 'Plugin added to the ignored list.', 'vigilante' ) );
9265 }
9266
9267 /**
9268 * AJAX: Stop ignoring a previously-ignored closed/removed plugin slug.
9269 */
9270 public function ajax_unignore_closed_plugin() {
9271 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9272
9273 if ( ! current_user_can( 'manage_options' ) ) {
9274 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9275 }
9276
9277 $slug = isset( $_POST['slug'] ) ? sanitize_key( wp_unslash( $_POST['slug'] ) ) : '';
9278 if ( '' === $slug ) {
9279 wp_send_json_error( __( 'No slug specified.', 'vigilante' ) );
9280 }
9281
9282 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
9283 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
9284 }
9285 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
9286 $checker->unignore_slug( $slug );
9287
9288 wp_send_json_success( __( 'Plugin removed from the ignored list.', 'vigilante' ) );
9289 }
9290
9291 /**
9292 * AJAX: Clear the entire ignored-closed-plugins list.
9293 */
9294 public function ajax_clear_ignored_closed_plugins() {
9295 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9296
9297 if ( ! current_user_can( 'manage_options' ) ) {
9298 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9299 }
9300
9301 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
9302 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
9303 }
9304 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
9305 $checker->clear_ignored();
9306
9307 wp_send_json_success( __( 'Ignored closed plugins list cleared.', 'vigilante' ) );
9308 }
9309
9310 /**
9311 * AJAX: Test security headers
9312 */
9313 public function ajax_test_headers() {
9314 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9315
9316 if ( ! current_user_can( 'manage_options' ) ) {
9317 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9318 }
9319
9320 // Get security grade from settings (not from actual HTTP request)
9321 $security_headers = new Vigilante_Security_Headers( $this->settings );
9322 $results = $security_headers->get_security_grade();
9323
9324 wp_send_json_success( $results );
9325 }
9326
9327 /**
9328 * Sanitize section data (kept for compatibility)
9329 *
9330 * @param string $section Section name.
9331 * @param array $data Section data.
9332 * @return array
9333 */
9334 private function sanitize_section_data( $section, $data ) {
9335 $sanitized = array();
9336
9337 foreach ( $data as $key => $value ) {
9338 $key = sanitize_key( $key );
9339
9340 if ( is_array( $value ) ) {
9341 $sanitized[ $key ] = $this->sanitize_section_data( $key, $value );
9342 } elseif ( is_numeric( $value ) ) {
9343 $sanitized[ $key ] = intval( $value );
9344 } else {
9345 $sanitized[ $key ] = sanitize_text_field( $value );
9346 }
9347 }
9348
9349 return $sanitized;
9350 }
9351
9352 /**
9353 * Apply changes after saving settings
9354 *
9355 * @param string $section Section that was updated.
9356 * @param array $all_options All options.
9357 */
9358 private function apply_section_changes( $section, $all_options ) {
9359 // Create fresh settings instance to ensure we have the latest data
9360 $fresh_settings = new Vigilante_Settings();
9361
9362 // The shared Vigilant .htaccess block carries BOTH the firewall's
9363 // file-protection rules and the server-signature / fingerprinting rules
9364 // that are configured under Security Headers. So it must be regenerated
9365 // whenever either section (or the module toggles) changes, not only on
9366 // the firewall save — otherwise toggling "Hide server signature" or
9367 // "Remove fingerprinting headers" never reaches the .htaccess.
9368 if ( in_array( $section, array( 'firewall', 'security_headers', 'modules' ), true ) ) {
9369 $htaccess = new Vigilante_Htaccess_Protection( $fresh_settings );
9370 $sh = $fresh_settings->get_section( 'security_headers' );
9371 $needs_htaccess_block = ! empty( $all_options['modules']['firewall'] )
9372 || ! empty( $sh['hide_server_signature'] )
9373 || ! empty( $sh['remove_fingerprinting_headers'] );
9374
9375 if ( $needs_htaccess_block ) {
9376 $htaccess->apply_rules();
9377 } else {
9378 $htaccess->remove_rules();
9379 }
9380 }
9381
9382 // Regenerate the HTTP security headers (sent by PHP) for the headers section.
9383 if ( 'security_headers' === $section || 'modules' === $section ) {
9384 $security_headers = new Vigilante_Security_Headers( $fresh_settings );
9385 $headers_enabled = ! empty( $all_options['modules']['security_headers'] );
9386
9387 if ( $headers_enabled ) {
9388 $security_headers->apply_rules();
9389 } else {
9390 $security_headers->remove_rules();
9391 }
9392 }
9393
9394 // Regenerate wp-config for wp_hardening section
9395 if ( 'wp_hardening' === $section || 'modules' === $section ) {
9396 $wpconfig = new Vigilante_Wpconfig_Security( $fresh_settings );
9397 $hardening_enabled = ! empty( $all_options['modules']['wp_hardening'] );
9398
9399 if ( $hardening_enabled ) {
9400 $wpconfig->apply_security_constants();
9401 } else {
9402 $wpconfig->remove_constants();
9403 }
9404
9405 // Apply WordPress options for comments/pingbacks
9406 $hardening_options = $all_options['wp_hardening'] ?? array();
9407
9408 if ( $hardening_enabled ) {
9409 // Pingbacks
9410 if ( ! empty( $hardening_options['disable_pingbacks'] ) ) {
9411 update_option( 'default_pingback_flag', 0 );
9412 } else {
9413 // Restore default: pingbacks enabled
9414 update_option( 'default_pingback_flag', 1 );
9415 }
9416
9417 // Trackbacks and ping status
9418 // Only close if either pingbacks OR trackbacks are disabled
9419 if ( ! empty( $hardening_options['disable_pingbacks'] ) || ! empty( $hardening_options['disable_trackbacks'] ) ) {
9420 update_option( 'default_ping_status', 'closed' );
9421 } else {
9422 // Restore default: pings open
9423 update_option( 'default_ping_status', 'open' );
9424 }
9425
9426 // Comment moderation
9427 if ( ! empty( $hardening_options['require_comment_moderation'] ) ) {
9428 update_option( 'comment_moderation', 1 );
9429 } else {
9430 // Restore default: no moderation required
9431 update_option( 'comment_moderation', 0 );
9432 }
9433 }
9434 }
9435
9436 // Trim activity log entries immediately when limits change
9437 if ( 'activity_log' === $section && $this->activity_log ) {
9438 $this->activity_log->cleanup_old_logs();
9439 }
9440
9441 // Flush rewrite rules if login URL changed
9442 if ( 'login_security' === $section ) {
9443 $login_options = $all_options['login_security'] ?? array();
9444 if ( ! empty( $login_options['custom_login_url'] ) ) {
9445 delete_option( 'vigilante_login_rules_version' );
9446 }
9447 }
9448
9449 // Log the settings change with readable section name
9450 if ( $this->activity_log ) {
9451 $section_names = array(
9452 'firewall' => __( 'Firewall', 'vigilante' ),
9453 'login_security' => __( 'Login Security', 'vigilante' ),
9454 'security_headers' => __( 'Security Headers', 'vigilante' ),
9455 'rest_api_security'=> __( 'REST API Security', 'vigilante' ),
9456 'user_security' => __( 'User Security', 'vigilante' ),
9457 'wp_hardening' => __( 'WP Hardening', 'vigilante' ),
9458 'activity_log' => __( 'Security Audit', 'vigilante' ),
9459 'file_integrity' => __( 'File Integrity', 'vigilante' ),
9460 'email' => __( 'Notification Settings', 'vigilante' ),
9461 'backup' => __( 'Backup', 'vigilante' ),
9462 'advanced' => __( 'Advanced', 'vigilante' ),
9463 'modules' => __( 'Modules', 'vigilante' ),
9464 );
9465 $display_name = isset( $section_names[ $section ] ) ? $section_names[ $section ] : $section;
9466
9467 $this->activity_log->log(
9468 'settings',
9469 'settings_updated',
9470 sprintf(
9471 /* translators: %s: Section name */
9472 __( 'Settings updated: %s', 'vigilante' ),
9473 $display_name
9474 ),
9475 array( 'section' => $section ),
9476 'info'
9477 );
9478 }
9479 }
9480
9481 /**
9482 * Apply all file changes (htaccess, wp-config) based on current options
9483 *
9484 * Used after preset, import, or reset operations
9485 *
9486 * @param array $all_options All plugin options.
9487 */
9488 private function apply_all_file_changes( $all_options ) {
9489 // Refresh settings cache first
9490 $this->settings->clear_cache();
9491
9492 // Create fresh settings instance
9493 $fresh_settings = new Vigilante_Settings();
9494
9495 // Apply firewall htaccess changes
9496 $htaccess = new Vigilante_Htaccess_Protection( $fresh_settings );
9497 $firewall_enabled = ! empty( $all_options['modules']['firewall'] );
9498
9499 if ( $firewall_enabled ) {
9500 $htaccess->apply_rules();
9501 } else {
9502 $htaccess->remove_rules();
9503 }
9504
9505 // Apply security headers htaccess changes
9506 $security_headers = new Vigilante_Security_Headers( $fresh_settings );
9507 $headers_enabled = ! empty( $all_options['modules']['security_headers'] );
9508
9509 if ( $headers_enabled ) {
9510 $security_headers->apply_rules();
9511 } else {
9512 $security_headers->remove_rules();
9513 }
9514
9515 // Apply wp-config changes
9516 $wpconfig = new Vigilante_Wpconfig_Security( $fresh_settings );
9517 $hardening_enabled = ! empty( $all_options['modules']['wp_hardening'] );
9518
9519 if ( $hardening_enabled ) {
9520 $wpconfig->apply_security_constants();
9521 } else {
9522 $wpconfig->remove_constants();
9523 }
9524
9525 // Apply WordPress options for comments/pingbacks
9526 $hardening_options = $all_options['wp_hardening'] ?? array();
9527
9528 if ( $hardening_enabled ) {
9529 // Pingbacks
9530 if ( ! empty( $hardening_options['disable_pingbacks'] ) ) {
9531 update_option( 'default_pingback_flag', 0 );
9532 } else {
9533 // Restore default: pingbacks enabled
9534 update_option( 'default_pingback_flag', 1 );
9535 }
9536
9537 // Trackbacks and ping status
9538 // Only close if either pingbacks OR trackbacks are disabled
9539 if ( ! empty( $hardening_options['disable_pingbacks'] ) || ! empty( $hardening_options['disable_trackbacks'] ) ) {
9540 update_option( 'default_ping_status', 'closed' );
9541 } else {
9542 // Restore default: pings open
9543 update_option( 'default_ping_status', 'open' );
9544 }
9545
9546 // Comment moderation
9547 if ( ! empty( $hardening_options['require_comment_moderation'] ) ) {
9548 update_option( 'comment_moderation', 1 );
9549 } else {
9550 // Restore default: no moderation required
9551 update_option( 'comment_moderation', 0 );
9552 }
9553 }
9554
9555 // Log the change
9556 if ( $this->activity_log ) {
9557 $this->activity_log->log(
9558 'settings',
9559 'bulk_settings_applied',
9560 __( 'Bulk settings applied (preset/import/reset)', 'vigilante' ),
9561 array(),
9562 'info'
9563 );
9564 }
9565 }
9566 }