PluginProbe
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… / 3.0.1
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… v3.0.1
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.1, at admin/class-admin.php

9,485 lines 593.6 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 * Calculate comprehensive security score (0-100)
1013 *
1014 * @param array $options Plugin options.
1015 * @return int Security score.
1016 */
1017 private function calculate_security_score( $options ) {
1018 $score = 0;
1019 $max_score = 0;
1020
1021 // Module scores (60 points total)
1022 $module_weights = array(
1023 'firewall' => 10,
1024 'security_headers' => 8,
1025 'login_security' => 10,
1026 'rest_api_security' => 6,
1027 'user_security' => 8,
1028 'wp_hardening' => 8,
1029 'file_integrity' => 5,
1030 'activity_log' => 5,
1031 );
1032
1033 foreach ( $module_weights as $module => $weight ) {
1034 $max_score += $weight;
1035 if ( ! empty( $options['modules'][ $module ] ) ) {
1036 $score += $weight;
1037 }
1038 }
1039
1040 // Firewall details (10 points)
1041 if ( ! empty( $options['modules']['firewall'] ) ) {
1042 $firewall = $options['firewall'] ?? array();
1043 $max_score += 10;
1044
1045 $firewall_checks = array(
1046 'block_sql_injection',
1047 'block_xss_attacks',
1048 'block_bad_query_strings',
1049 'block_file_inclusion',
1050 'block_directory_traversal',
1051 );
1052
1053 $firewall_enabled = 0;
1054 foreach ( $firewall_checks as $check ) {
1055 if ( ! empty( $firewall[ $check ] ) ) {
1056 $firewall_enabled++;
1057 }
1058 }
1059 $score += min( 10, $firewall_enabled * 2 );
1060 }
1061
1062 // Login security details (10 points)
1063 if ( ! empty( $options['modules']['login_security'] ) ) {
1064 $login = $options['login_security'] ?? array();
1065 $max_score += 10;
1066
1067 // Max attempts configured
1068 if ( isset( $login['max_attempts'] ) && $login['max_attempts'] <= 5 ) {
1069 $score += 3;
1070 }
1071 // XML-RPC disabled
1072 if ( ! empty( $login['disable_xmlrpc'] ) ) {
1073 $score += 3;
1074 }
1075 // 2FA enabled
1076 if ( ! empty( $login['two_factor']['enabled'] ) ) {
1077 $score += 4;
1078 }
1079 }
1080
1081 // Security headers details (10 points)
1082 if ( ! empty( $options['modules']['security_headers'] ) ) {
1083 $headers = $options['security_headers'] ?? array();
1084 $max_score += 10;
1085
1086 if ( ! empty( $headers['x_frame_options'] ) ) {
1087 $score += 2;
1088 }
1089 if ( ! empty( $headers['x_content_type_options'] ) ) {
1090 $score += 2;
1091 }
1092 if ( ! empty( $headers['hsts']['enabled'] ) ) {
1093 $score += 3;
1094 }
1095 if ( ! empty( $headers['csp']['enabled'] ) ) {
1096 $score += 3;
1097 }
1098 }
1099
1100 // User security details (10 points)
1101 if ( ! empty( $options['modules']['user_security'] ) ) {
1102 $user = $options['user_security'] ?? array();
1103 $max_score += 10;
1104
1105 if ( ! empty( $user['block_insecure_usernames'] ) ) {
1106 $score += 3;
1107 }
1108 if ( ! empty( $user['force_strong_passwords'] ) ) {
1109 $score += 3;
1110 }
1111 if ( ! empty( $user['password_expiration']['enabled'] ) ) {
1112 $score += 2;
1113 }
1114 if ( ! empty( $user['email_verification']['enabled'] ) ) {
1115 $score += 2;
1116 }
1117 }
1118
1119 // Audit alerts details (6 points) - only when Security Audit is on,
1120 // because the alerting layer rides on top of the activity log. Leaving
1121 // both alert legs off keeps these points unearned.
1122 if ( ! empty( $options['modules']['activity_log'] ) ) {
1123 $alerts = isset( $options['audit_alerts'] ) ? (array) $options['audit_alerts'] : array();
1124 $max_score += 6;
1125 if ( Vigilante_Audit_Alerts::immediate_is_active( $alerts ) ) {
1126 $score += 3;
1127 }
1128 if ( Vigilante_Audit_Alerts::threshold_is_active( $alerts ) ) {
1129 $score += 3;
1130 }
1131 }
1132
1133 /*
1134 * Self-protection (15 points). Having it on is configuration, which is
1135 * what this card measures; the state of the last check caps the card,
1136 * because a plugin whose own files were changed is not well configured
1137 * in any useful sense, whatever the rest of the settings say. The
1138 * environment block below already mixes measured state into this score
1139 * (WP_DEBUG, insecure usernames), so the card keeps its meaning.
1140 */
1141 $max_score += 15;
1142 $self_enabled = Vigilante_Self_Integrity::is_on();
1143 $self_tone = Vigilante_Self_Integrity::tone( Vigilante_Self_Integrity::display_state(), $self_enabled );
1144 if ( $self_enabled ) {
1145 $score += 10;
1146 // The five points are for a check that ran and came out clean: a
1147 // site that has never checked itself has not earned them.
1148 if ( in_array( $self_tone, array( 'ok', 'info' ), true ) ) {
1149 $score += 5;
1150 }
1151 }
1152
1153 // Environment checks (8 points) - penalize insecure server configuration
1154 $max_score += 8;
1155 $env_score = 8;
1156
1157 // WP_DEBUG active in production is a security risk (exposes paths, errors)
1158 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
1159 $env_score -= 5;
1160 }
1161
1162 // Accounts with insecure usernames (targeted by brute force attacks)
1163 $insecure_admins = $this->get_insecure_admin_usernames();
1164 if ( ! empty( $insecure_admins ) ) {
1165 $env_score -= 3;
1166 }
1167
1168 $score += max( 0, $env_score );
1169
1170 $percent = $max_score > 0 ? (int) round( ( $score / $max_score ) * 100 ) : 0;
1171 if ( in_array( $self_tone, array( 'critical', 'off' ), true ) ) {
1172 // Same cap and same reason as the Security Check score.
1173 $percent = min( $percent, Vigilante_Security_Analyzer::SCORE_CAP_ON_TAMPER );
1174 }
1175 return $percent;
1176 }
1177
1178 /**
1179 * Get security recommendations based on current settings
1180 *
1181 * @param array $options Plugin options.
1182 * @return array Array of recommendations.
1183 */
1184 private function get_security_recommendations( $options ) {
1185 $recommendations = array();
1186
1187 // Self-protection first: if Vigilant itself cannot be trusted, nothing
1188 // else on this card means much.
1189 $vg_self_enabled = Vigilante_Self_Integrity::is_on();
1190 $vg_self_tone = Vigilante_Self_Integrity::tone( Vigilante_Self_Integrity::display_state(), $vg_self_enabled );
1191 if ( ! $vg_self_enabled ) {
1192 $recommendations[] = array(
1193 'icon' => 'shield',
1194 'priority' => 'high',
1195 'tab' => 'file-integrity',
1196 'message' => __( 'Turn Vigilant self-protection on, so a change to Vigilant own files does not go unnoticed.', 'vigilante' ),
1197 );
1198 } elseif ( 'off' === $vg_self_tone ) {
1199 $recommendations[] = array(
1200 'icon' => 'warning',
1201 'priority' => 'critical',
1202 'tab' => 'file-integrity',
1203 'message' => __( 'Something on this site switched Vigilant self-protection off: File Integrity says which file does it.', 'vigilante' ),
1204 );
1205 } elseif ( 'critical' === $vg_self_tone ) {
1206 $recommendations[] = array(
1207 'icon' => 'warning',
1208 'priority' => 'critical',
1209 'tab' => 'file-integrity',
1210 'message' => __( 'Vigilant own files have been changed: repair Vigilant from File Integrity before anything else.', 'vigilante' ),
1211 );
1212 } elseif ( 'warning' === $vg_self_tone ) {
1213 $recommendations[] = array(
1214 'icon' => 'shield',
1215 'priority' => 'high',
1216 'tab' => 'file-integrity',
1217 'message' => __( 'Vigilant self-protection needs your attention: File Integrity says what it found and what to do.', 'vigilante' ),
1218 );
1219 } elseif ( 'none' === $vg_self_tone ) {
1220 // The score holds back the points of a check that has not run yet,
1221 // so the card has to say why instead of just showing a lower number.
1222 $recommendations[] = array(
1223 'icon' => 'shield',
1224 'priority' => 'high',
1225 'tab' => 'file-integrity',
1226 'message' => __( 'Vigilant has not checked its own files yet: run a scan from File Integrity.', 'vigilante' ),
1227 );
1228 }
1229
1230 // Critical: Firewall disabled
1231 if ( empty( $options['modules']['firewall'] ) ) {
1232 $recommendations[] = array(
1233 'icon' => 'warning',
1234 'priority' => 'critical',
1235 'message' => __( 'Enable Firewall to protect against common attacks.', 'vigilante' ),
1236 );
1237 }
1238
1239 // Critical: Login security disabled
1240 if ( empty( $options['modules']['login_security'] ) ) {
1241 $recommendations[] = array(
1242 'icon' => 'warning',
1243 'priority' => 'critical',
1244 'message' => __( 'Enable Login Security to prevent brute force attacks.', 'vigilante' ),
1245 );
1246 }
1247
1248 // High: Security headers disabled
1249 if ( empty( $options['modules']['security_headers'] ) ) {
1250 $recommendations[] = array(
1251 'icon' => 'admin-generic',
1252 'priority' => 'high',
1253 'message' => __( 'Enable Security Headers to protect against clickjacking and XSS.', 'vigilante' ),
1254 );
1255 }
1256
1257 // High: User security disabled
1258 if ( empty( $options['modules']['user_security'] ) ) {
1259 $recommendations[] = array(
1260 'icon' => 'admin-users',
1261 'priority' => 'high',
1262 'message' => __( 'Enable User Security to enforce password policies and username protection.', 'vigilante' ),
1263 );
1264 }
1265
1266 // High: 2FA not enabled (only if login security is active)
1267 $login = $options['login_security'] ?? array();
1268 if ( ! empty( $options['modules']['login_security'] ) && empty( $login['two_factor']['enabled'] ) ) {
1269 $recommendations[] = array(
1270 'icon' => 'shield',
1271 'priority' => 'high',
1272 'message' => __( 'Enable Two-Factor Authentication for enhanced login security.', 'vigilante' ),
1273 'tab' => 'login',
1274 );
1275 }
1276
1277 // Medium: REST API security disabled
1278 if ( empty( $options['modules']['rest_api_security'] ) ) {
1279 $recommendations[] = array(
1280 'icon' => 'rest-api',
1281 'priority' => 'medium',
1282 'message' => __( 'Enable REST API Security to control API access and prevent enumeration.', 'vigilante' ),
1283 );
1284 }
1285
1286 // Medium: WP Hardening disabled
1287 if ( empty( $options['modules']['wp_hardening'] ) ) {
1288 $recommendations[] = array(
1289 'icon' => 'lock',
1290 'priority' => 'medium',
1291 'message' => __( 'Enable WP Hardening to remove version info and protect core files.', 'vigilante' ),
1292 );
1293 }
1294
1295 // Medium: File integrity disabled
1296 if ( empty( $options['modules']['file_integrity'] ) ) {
1297 $recommendations[] = array(
1298 'icon' => 'media-text',
1299 'priority' => 'medium',
1300 'message' => __( 'Enable File Integrity to detect unauthorized file changes.', 'vigilante' ),
1301 );
1302 }
1303
1304 // Medium: Security Audit disabled
1305 if ( empty( $options['modules']['activity_log'] ) ) {
1306 $recommendations[] = array(
1307 'icon' => 'list-view',
1308 'priority' => 'medium',
1309 'message' => __( 'Enable Security Audit to track security events.', 'vigilante' ),
1310 );
1311 }
1312
1313 // Low: XML-RPC enabled (only if login security is active)
1314 if ( ! empty( $options['modules']['login_security'] ) && empty( $login['disable_xmlrpc'] ) ) {
1315 $recommendations[] = array(
1316 'icon' => 'info',
1317 'priority' => 'low',
1318 'message' => __( 'Disable XML-RPC if not needed (reduces attack surface).', 'vigilante' ),
1319 'tab' => 'login',
1320 );
1321 }
1322
1323 // Low: Strong passwords not enforced (only if user security is active)
1324 $user = $options['user_security'] ?? array();
1325 if ( ! empty( $options['modules']['user_security'] ) && empty( $user['force_strong_passwords'] ) ) {
1326 $recommendations[] = array(
1327 'icon' => 'admin-users',
1328 'priority' => 'low',
1329 'message' => __( 'Enforce strong passwords for all users.', 'vigilante' ),
1330 'tab' => 'users',
1331 );
1332 }
1333
1334 // High: WP_DEBUG active in production (regardless of Vigilante settings)
1335 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
1336 $recommendations[] = array(
1337 'icon' => 'warning',
1338 'priority' => 'high',
1339 'message' => __( 'WP_DEBUG is active. Debug mode exposes sensitive information and should be disabled in production.', 'vigilante' ),
1340 'tab' => 'wp-hardening',
1341 );
1342 }
1343
1344 // Low: Users with display name matching login username (only if user security active)
1345 if ( ! empty( $options['modules']['user_security'] ) ) {
1346 $exposed_users = $this->get_users_with_exposed_login();
1347 if ( ! empty( $exposed_users ) ) {
1348 $recommendations[] = array(
1349 'icon' => 'admin-users',
1350 'priority' => 'low',
1351 'message' => sprintf(
1352 /* translators: %s: Comma-separated list of usernames */
1353 __( 'These users have their login username as display name (publicly visible): %s', 'vigilante' ),
1354 implode( ', ', $exposed_users )
1355 ),
1356 'tab' => 'users',
1357 );
1358 }
1359 }
1360
1361 // High: Accounts with insecure usernames (regardless of module status)
1362 $insecure_admins = $this->get_insecure_admin_usernames();
1363 if ( ! empty( $insecure_admins ) ) {
1364 $recommendations[] = array(
1365 'icon' => 'warning',
1366 'priority' => 'high',
1367 'message' => sprintf(
1368 /* translators: %s: Comma-separated list of usernames */
1369 __( 'Insecure usernames detected: %s. These are commonly targeted in brute force attacks. Create new accounts with unique usernames and remove these.', 'vigilante' ),
1370 implode( ', ', $insecure_admins )
1371 ),
1372 );
1373 }
1374
1375 // Critical: Closed or removed plugins detected by the daily check.
1376 // Reads from the cached state map populated by Vigilante_Plugin_Status, so
1377 // there is no extra HTTP call here. Ignored slugs are filtered out so the
1378 // recommendation respects the user's per-slug Ignore decisions.
1379 if ( ! empty( $options['modules']['file_integrity'] ) && ! empty( $options['file_integrity']['check_closed_plugins'] ) ) {
1380 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
1381 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
1382 }
1383 $closed_checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
1384 $closed_active = $closed_checker->get_closed_plugins();
1385 if ( ! empty( $closed_active ) ) {
1386 $names = array();
1387 foreach ( $closed_active as $slug => $entry ) {
1388 $names[] = isset( $entry['name'] ) ? $entry['name'] : $slug;
1389 }
1390 $recommendations[] = array(
1391 'icon' => 'warning',
1392 'priority' => 'critical',
1393 'message' => sprintf(
1394 /* translators: 1: count, 2: comma-separated plugin names */
1395 _n(
1396 '%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.',
1397 '%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.',
1398 count( $closed_active ),
1399 'vigilante'
1400 ),
1401 count( $closed_active ),
1402 implode( ', ', $names )
1403 ),
1404 'tab' => 'file-integrity',
1405 );
1406 }
1407 }
1408
1409 // Medium: Security Audit is on but no audit alert is configured. The
1410 // alerting layer only makes sense while the activity log is running.
1411 if ( ! empty( $options['modules']['activity_log'] ) ) {
1412 $alerts = isset( $options['audit_alerts'] ) ? (array) $options['audit_alerts'] : array();
1413 if ( ! Vigilante_Audit_Alerts::has_active_alerts( $alerts ) ) {
1414 $recommendations[] = array(
1415 'icon' => 'email-alt',
1416 'priority' => 'medium',
1417 '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' ),
1418 'tab' => 'activity-log',
1419 );
1420 }
1421 }
1422
1423 // Sort by priority
1424 $priority_order = array( 'critical' => 0, 'high' => 1, 'medium' => 2, 'low' => 3 );
1425 usort( $recommendations, function( $a, $b ) use ( $priority_order ) {
1426 return ( $priority_order[ $a['priority'] ] ?? 99 ) - ( $priority_order[ $b['priority'] ] ?? 99 );
1427 } );
1428
1429 return $recommendations;
1430 }
1431
1432 /**
1433 * Get users whose display name matches their login username
1434 *
1435 * Limited to administrators and editors for performance and relevance.
1436 * Cached with transient to avoid repeated queries on every dashboard load.
1437 *
1438 * @return array Array of usernames with exposed login.
1439 */
1440 private function get_users_with_exposed_login() {
1441 $cache_key = 'vigilante_exposed_display_names';
1442 $cached = get_transient( $cache_key );
1443
1444 if ( false !== $cached ) {
1445 return $cached;
1446 }
1447
1448 $exposed = array();
1449 $users = get_users( array(
1450 'role__in' => array( 'administrator', 'editor' ),
1451 'fields' => array( 'ID', 'user_login', 'display_name' ),
1452 ) );
1453
1454 foreach ( $users as $user ) {
1455 if ( strcasecmp( $user->display_name, $user->user_login ) === 0 ) {
1456 $exposed[] = $user->user_login;
1457 }
1458 }
1459
1460 // Cache for 12 hours
1461 set_transient( $cache_key, $exposed, 12 * HOUR_IN_SECONDS );
1462
1463 return $exposed;
1464 }
1465
1466 /**
1467 * Get accounts with insecure usernames
1468 *
1469 * Checks for common default usernames that are targeted by brute force attacks.
1470 * Detects any user regardless of role (consistent with username creation blocking).
1471 * Uses WordPress object cache via get_user_by() so no transient needed.
1472 *
1473 * @return array Array of insecure usernames found.
1474 */
1475 private function get_insecure_admin_usernames() {
1476 $priority_usernames = array( 'admin', 'administrator', 'root', 'test', 'user', 'guest', 'info', 'sysadmin', 'webmaster' );
1477 $found = array();
1478
1479 foreach ( $priority_usernames as $username ) {
1480 $user = get_user_by( 'login', $username );
1481 if ( $user ) {
1482 $found[] = $username;
1483 }
1484 }
1485
1486 return $found;
1487 }
1488
1489 /**
1490 * Get security status for menu badge
1491 *
1492 * Returns count of disabled modules and whether there are critical issues.
1493 * Critical = Firewall or Login Security disabled.
1494 *
1495 * @return array Array with 'count' and 'has_critical'.
1496 */
1497 public function get_security_status_for_badge() {
1498 $options = $this->settings->get_all_options();
1499 $modules = $options['modules'] ?? array();
1500
1501 // Count disabled modules
1502 $disabled_count = 0;
1503 $has_critical = false;
1504
1505 // Critical modules - if disabled, badge is red
1506 $critical_modules = array( 'firewall', 'login_security' );
1507
1508 foreach ( $modules as $module => $enabled ) {
1509 // Handle both boolean and string values ('1', '0', true, false)
1510 $is_enabled = filter_var( $enabled, FILTER_VALIDATE_BOOLEAN );
1511
1512 if ( ! $is_enabled ) {
1513 $disabled_count++;
1514
1515 // Check if this is a critical module
1516 if ( in_array( $module, $critical_modules, true ) ) {
1517 $has_critical = true;
1518 }
1519 }
1520 }
1521
1522 return array(
1523 'count' => $disabled_count,
1524 'has_critical' => $has_critical,
1525 );
1526 }
1527
1528 /**
1529 * Get count of security issues for menu badge (deprecated, use get_security_status_for_badge)
1530 *
1531 * @return int Count of critical/high issues.
1532 */
1533 public function get_security_issues_count() {
1534 $status = $this->get_security_status_for_badge();
1535 return $status['count'];
1536 }
1537
1538 /**
1539 * Register settings
1540 */
1541 public function register_settings() {
1542 register_setting(
1543 'vigilante_options',
1544 Vigilante_Settings::OPTION_NAME,
1545 array( $this->settings, 'validate_options' )
1546 );
1547 }
1548
1549 /**
1550 * Index behind the settings search box.
1551 *
1552 * Each entry points at one settings row. The search matches on the label,
1553 * on its English original and on 'keywords', which are extra terms someone
1554 * might type instead of the label itself.
1555 *
1556 * Those keywords are wrapped in _x() with the context "settings search
1557 * keywords" so every locale can supply its own: the source strings are in
1558 * English, and a Spanish user typing "contrasena" or a German one typing
1559 * "Kennwort" only reaches the password settings if that locale translated
1560 * them. Translators can add, drop or replace terms freely, one per space;
1561 * they are never displayed, only matched against what the user types.
1562 *
1563 * The list is maintained by hand, so a new settings row needs an entry here
1564 * or it cannot be found. It had drifted to 68 of 131 rows before 2.9.7.
1565 *
1566 * @return array
1567 */
1568 private function get_search_index() {
1569 return array(
1570 // Firewall - Main
1571 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' ) ),
1572 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' ) ),
1573 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' ) ),
1574 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' ) ),
1575 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' ) ),
1576 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' ) ),
1577 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' ) ),
1578 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' ) ),
1579 // Firewall - Server Protection
1580 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' ) ),
1581 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' ) ),
1582 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' ) ),
1583 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' ) ),
1584 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' ) ),
1585 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' ) ),
1586 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' ) ),
1587 // Security Headers
1588 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' ) ),
1589 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' ) ),
1590 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' ) ),
1591 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' ) ),
1592 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' ) ),
1593 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' ) ),
1594 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' ) ),
1595 // Security Headers - Cross-Origin Policies
1596 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' ) ),
1597 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' ) ),
1598 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' ) ),
1599 // Login Security
1600 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' ) ),
1601 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' ) ),
1602 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' ) ),
1603 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' ) ),
1604 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' ) ),
1605 // REST API
1606 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' ) ),
1607 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' ) ),
1608 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' ) ),
1609 // User Security
1610 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' ) ),
1611 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' ) ),
1612 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' ) ),
1613 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' ) ),
1614 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' ) ),
1615 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' ) ),
1616 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' ) ),
1617 // WP Hardening
1618 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' ) ),
1619 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' ) ),
1620 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' ) ),
1621 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' ) ),
1622 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' ) ),
1623 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' ) ),
1624 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' ) ),
1625 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' ) ),
1626 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' ) ),
1627 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' ) ),
1628 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' ) ),
1629 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' ) ),
1630 // File Integrity
1631 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' ) ),
1632 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' ) ),
1633 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' ) ),
1634 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' ) ),
1635 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' ) ),
1636 // Security Audit
1637 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' ) ),
1638 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' ) ),
1639 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' ) ),
1640 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' ) ),
1641 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' ) ),
1642 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' ) ),
1643 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' ) ),
1644 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' ) ),
1645 // Settings & Tools
1646 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' ) ),
1647 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' ) ),
1648 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' ) ),
1649 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' ) ),
1650 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' ) ),
1651 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' ) ),
1652 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' ) ),
1653 // Entradas anadidas en la 2.9.7 tras comprobar que el indice cubria 68 de
1654 // las 131 filas de ajustes: buscar XML-RPC, por ejemplo, no devolvia nada.
1655 // El indice se mantiene a mano, asi que al anadir una fila de ajustes hay
1656 // que anadirla tambien aqui.
1657 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' ) ),
1658 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' ) ),
1659 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' ) ),
1660 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' ) ),
1661 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' ) ),
1662 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' ) ),
1663 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' ) ),
1664 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' ) ),
1665 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' ) ),
1666 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' ) ),
1667 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' ) ),
1668 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' ) ),
1669 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' ) ),
1670 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' ) ),
1671 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' ) ),
1672 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' ) ),
1673 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' ) ),
1674 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' ) ),
1675 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' ) ),
1676 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' ) ),
1677 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' ) ),
1678 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' ) ),
1679 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' ) ),
1680 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' ) ),
1681 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' ) ),
1682 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' ) ),
1683 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' ) ),
1684 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' ) ),
1685 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' ) ),
1686 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' ) ),
1687 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' ) ),
1688 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' ) ),
1689 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' ) ),
1690 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' ) ),
1691 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' ) ),
1692 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' ) ),
1693 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' ) ),
1694 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' ) ),
1695 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' ) ),
1696 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' ) ),
1697 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' ) ),
1698 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' ) ),
1699 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' ) ),
1700 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' ) ),
1701 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' ) ),
1702 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' ) ),
1703 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' ) ),
1704 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' ) ),
1705 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' ) ),
1706 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' ) ),
1707 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' ) ),
1708 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' ) ),
1709 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' ) ),
1710 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' ) ),
1711 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' ) ),
1712 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' ) ),
1713 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' ) ),
1714 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' ) ),
1715 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' ) ),
1716 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' ) ),
1717 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' ) ),
1718 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' ) ),
1719 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' ) ),
1720 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' ) ),
1721 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' ) ),
1722 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' ) ),
1723 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' ) ),
1724 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' ) ),
1725 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' ) ),
1726 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' ) ),
1727 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' ) ),
1728 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' ) ),
1729 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' ) ),
1730 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' ) ),
1731 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' ) ),
1732 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' ) ),
1733 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' ) ),
1734 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' ) ),
1735 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' ) ),
1736 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' ) ),
1737 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' ) ),
1738 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' ) ),
1739 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' ) ),
1740 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' ) ),
1741 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' ) ),
1742 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' ) ),
1743 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' ) ),
1744 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' ) ),
1745 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' ) ),
1746 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' ) ),
1747 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' ) ),
1748 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' ) ),
1749 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' ) ),
1750 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' ) ),
1751 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' ) ),
1752 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' ) ),
1753 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' ) ),
1754 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' ) ),
1755 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' ) ),
1756 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' ) ),
1757 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' ) ),
1758 );
1759 }
1760
1761 /**
1762 * Enqueue admin assets
1763 *
1764 * @param string $hook Current admin page.
1765 */
1766 public function enqueue_assets( $hook ) {
1767 // toplevel_page_vigilante for top-level menu page
1768 if ( 'toplevel_page_vigilante' !== $hook ) {
1769 return;
1770 }
1771
1772 wp_enqueue_style(
1773 'vigilante-admin',
1774 VIGILANTE_ASSETS_URL . 'css/admin.css',
1775 array(),
1776 VIGILANTE_VERSION
1777 );
1778
1779 wp_enqueue_script(
1780 'vigilante-admin',
1781 VIGILANTE_ASSETS_URL . 'js/admin.js',
1782 array( 'jquery' ),
1783 VIGILANTE_VERSION,
1784 true
1785 );
1786
1787 wp_localize_script( 'vigilante-admin', 'vigilanteAdmin', array(
1788 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
1789 'selfBoxUrl' => esc_url( admin_url( 'admin.php?page=vigilante&tab=file-integrity#vigilante-section-fi-self' ) ),
1790 'nonce' => wp_create_nonce( 'vigilante_admin_nonce' ),
1791 'currentUserId' => get_current_user_id(),
1792 'logoutUrl' => wp_logout_url( wp_login_url() ),
1793 'adminUrl' => admin_url( 'admin.php?page=vigilante' ),
1794 'searchIndex' => $this->get_search_index(),
1795 // The scan repaints this table from JavaScript, so the same gate
1796 // has to travel with it or half the screen keeps the dead button.
1797 'approvalLocked' => $this->critical_approval_locked(),
1798 'underAttack' => array(
1799 'active' => ( new Vigilante_Under_Attack( $this->settings, $this->activity_log ) )->is_active(),
1800 'remaining' => ( new Vigilante_Under_Attack( $this->settings, $this->activity_log ) )->get_remaining_time(),
1801 ),
1802 'strings' => array(
1803 'saving' => __( 'Saving...', 'vigilante' ),
1804 'sendingTest' => __( 'Sending...', 'vigilante' ),
1805 'saved' => __( 'Settings saved', 'vigilante' ),
1806 'error' => __( 'Error saving settings', 'vigilante' ),
1807 'confirm' => __( 'Are you sure?', 'vigilante' ),
1808 'scanning' => __( 'Scanning...', 'vigilante' ),
1809 'scanComplete' => __( 'Scan complete', 'vigilante' ),
1810 'loading' => __( 'Loading...', 'vigilante' ),
1811 'searching' => __( 'Searching...', 'vigilante' ),
1812 'noUsersFound' => __( 'No users found', 'vigilante' ),
1813 'searchError' => __( 'Error searching users', 'vigilante' ),
1814 'sending' => __( 'Sending...', 'vigilante' ),
1815 'sendNotification' => __( 'Send notification now', 'vigilante' ),
1816 'notificationsSent' => __( 'notifications sent', 'vigilante' ),
1817 'skipped' => __( 'skipped', 'vigilante' ),
1818 'failed' => __( 'failed', 'vigilante' ),
1819 'customConfig' => __( 'Custom Configuration', 'vigilante' ),
1820 // Header tester strings
1821 'testHeaders' => __( 'Test Headers', 'vigilante' ),
1822 'testing' => __( 'Testing...', 'vigilante' ),
1823 'score' => __( 'Score', 'vigilante' ),
1824 'enabledHeaders' => __( 'Enabled headers', 'vigilante' ),
1825 'missingHeaders' => __( 'Missing headers', 'vigilante' ),
1826 'warnings' => __( 'Warnings', 'vigilante' ),
1827 // File integrity scan results strings
1828 'scanResults' => __( 'Scan Results', 'vigilante' ),
1829 'ok' => __( 'OK', 'vigilante' ),
1830 'modified' => __( 'Modified', 'vigilante' ),
1831 'suspicious' => __( 'Suspicious', 'vigilante' ),
1832 'totalScanned' => __( 'Total Scanned', 'vigilante' ),
1833 'suspiciousFiles' => __( 'Suspicious Files', 'vigilante' ),
1834 'suspiciousWarning' => __( 'These files may contain malicious code or are in unexpected locations. Review immediately!', 'vigilante' ),
1835 'file' => __( 'File', 'vigilante' ),
1836 'reason' => __( 'Reason', 'vigilante' ),
1837 'type' => __( 'Type', 'vigilante' ),
1838 'unknown' => __( 'Unknown', 'vigilante' ),
1839 'selfType' => __( 'Vigilant (self)', 'vigilante' ),
1840 'logWhatHappened' => __( 'What happened', 'vigilante' ),
1841 'logWhatItMeans' => __( 'What it means', 'vigilante' ),
1842 'logWhatToDo' => __( 'What to do', 'vigilante' ),
1843 'logSelfSeeDetails' => __( 'Open File Integrity for the full detail', 'vigilante' ),
1844 'modifiedFiles' => __( 'Modified Files', 'vigilante' ),
1845 'modifiedDescription' => __( 'These files (apparently) differ from the original WordPress or plugin versions.', 'vigilante' ),
1846 'extraFiles' => __( 'Extra Files', 'vigilante' ),
1847 'extra' => __( 'Extra', 'vigilante' ),
1848 'ignored' => __( 'Ignored', 'vigilante' ),
1849 'extraDescription' => __( 'PHP files found in plugins or themes that are not part of the original distribution from WordPress.org.', 'vigilante' ),
1850 'actions' => __( 'Actions', 'vigilante' ),
1851 'ignore' => __( 'Ignore', 'vigilante' ),
1852 'ignoring' => __( 'Ignoring...', 'vigilante' ),
1853 'fileIgnored' => __( 'File added to ignored list.', 'vigilante' ),
1854 'fileUnignored' => __( 'File removed from ignored list.', 'vigilante' ),
1855 'confirmClearIgnored' => __( 'Remove all files from the ignored list? They will appear in scan results again.', 'vigilante' ),
1856 'ignoredCleared' => __( 'Ignored files list cleared. Page will reload...', 'vigilante' ),
1857 'selectAll' => __( 'Select all', 'vigilante' ),
1858 'bulkIgnoreSelected' => __( 'Ignore selected', 'vigilante' ),
1859 'bulkUnignoreSelected'=> __( 'Stop ignoring selected', 'vigilante' ),
1860 'bulkNoSelection' => __( 'Select at least one file first.', 'vigilante' ),
1861 'bulkConfirmIgnore' => __( 'Ignore the selected files? They will be hidden from future scan results until you remove them from the ignored list.', 'vigilante' ),
1862 'bulkConfirmUnignore' => __( 'Remove the selected files from the ignored list? They will appear in scan results again.', 'vigilante' ),
1863 'bulkProcessing' => __( 'Processing...', 'vigilante' ),
1864 /* translators: %d: number of files selected for bulk action. */
1865 'bulkSelectedCount' => __( '%d selected', 'vigilante' ),
1866 'allClear' => __( 'All files verified - no issues found!', 'vigilante' ),
1867 'criticalConfigTitle' => __( 'Critical config files modified', 'vigilante' ),
1868 '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' ),
1869 'approve' => __( 'Approve', 'vigilante' ),
1870 'approving' => __( 'Approving...', 'vigilante' ),
1871 'approvalLockedNotice' => $this->critical_approval_notice(),
1872 'criticalApproved' => __( 'Change approved. Next scan will use the current state as baseline.', 'vigilante' ),
1873 'reviewChanges' => __( 'Review changes', 'vigilante' ),
1874 'hideChanges' => __( 'Hide changes', 'vigilante' ),
1875 'changes' => __( 'Changes', 'vigilante' ),
1876 'diffUnavailable' => __( 'Diff not available for this file (baseline was created before diff tracking was added). Approve to enable diff on future changes.', 'vigilante' ),
1877 'diffNetwork' => __( 'This file belongs to the whole network, so its line changes are only shown to network administrators, on the main site.', 'vigilante' ),
1878 'diffRescan' => __( 'Run a new scan to see the line changes of this file.', 'vigilante' ),
1879 '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' ),
1880 'diffEmpty' => __( 'No line-level changes detected (may be whitespace or reordering).', 'vigilante' ),
1881 'diffLines' => __( 'lines', 'vigilante' ),
1882 // Under Attack mode strings
1883 'underAttackConfirmActivate' => __( 'Activate Under Attack mode? All visitors will see a verification page for the next 4 hours.', 'vigilante' ),
1884 'underAttackConfirmDeactivate' => __( 'Deactivate Under Attack mode?', 'vigilante' ),
1885 'underAttackActivating' => __( 'Activating...', 'vigilante' ),
1886 'underAttackDeactivating' => __( 'Deactivating...', 'vigilante' ),
1887 // Database backup strings
1888 'dbBackupDownloading' => __( 'Generating backup...', 'vigilante' ),
1889 'dbBackupNoTables' => __( 'Please select at least one table.', 'vigilante' ),
1890 'dbBackupSuccess' => __( 'Database backup downloaded successfully.', 'vigilante' ),
1891 // Firewall unblock
1892 'confirmUnblockIp' => __( 'Unblock this IP from firewall rate limiting?', 'vigilante' ),
1893 // Database prefix strings
1894 'dbPrefixConfirm' => __( 'This operation will change your database prefix. It is irreversible. Make sure you have a current database backup before proceeding.', 'vigilante' ),
1895 'dbPrefixChanging' => __( 'Changing prefix...', 'vigilante' ),
1896 'dbPrefixSuccess' => __( 'Database prefix changed successfully. The page will reload now.', 'vigilante' ),
1897 'dbPrefixCheckbox' => __( 'You must confirm that you have a database backup.', 'vigilante' ),
1898 /* translators: 1: Hours, 2: Minutes */
1899 'underAttackRemaining' => __( '%1$dh %2$dm remaining', 'vigilante' ),
1900 'underAttackLabel' => __( 'Under Attack', 'vigilante' ),
1901 'standardLabel' => __( 'Standard', 'vigilante' ),
1902 'maximumLabel' => __( 'Maximum Security', 'vigilante' ),
1903 'deactivate' => __( 'Deactivate', 'vigilante' ),
1904 'underAttackActivate' => __( 'Activate for 4 hours', 'vigilante' ),
1905 // Settings strings
1906 'saveSettings' => __( 'Save Settings', 'vigilante' ),
1907 'settingsResetDefaults' => __( 'Settings reset to defaults.', 'vigilante' ),
1908 'confirmOverwrite' => __( 'This will overwrite your current settings.', 'vigilante' ),
1909 'importFailed' => __( 'Could not import settings. Check the file and try again.', 'vigilante' ),
1910 /* translators: 1: tests passed, 2: total tests in this category */
1911 'testsCounter' => __( '%1$d/%2$d tests', 'vigilante' ),
1912 'confirmResetAll' => __( 'This will reset ALL settings to defaults.', 'vigilante' ),
1913 'couldNotDetermineSection' => __( 'Could not determine section.', 'vigilante' ),
1914 'confirmResetSection' => __( 'Reset this section to default values? This cannot be undone.', 'vigilante' ),
1915 'sectionResetDefaults' => __( 'Section reset to defaults.', 'vigilante' ),
1916 /* translators: %s: preset name */
1917 'confirmApplyPreset' => __( 'Apply the "%s" preset?', 'vigilante' ),
1918 // Scan strings
1919 'scanFailed' => __( 'Scan failed', 'vigilante' ),
1920 /* translators: %s: error message */
1921 'scanError' => __( 'Scan error: %s', 'vigilante' ),
1922 'runScanNow' => __( 'Run Scan Now', 'vigilante' ),
1923 'confirmClearScan' => __( 'Are you sure you want to clear all scan results?', 'vigilante' ),
1924 'clearing' => __( 'Clearing...', 'vigilante' ),
1925 'scanResultsCleared' => __( 'Scan results cleared. Page will reload...', 'vigilante' ),
1926 'failedClearResults' => __( 'Failed to clear results', 'vigilante' ),
1927 /* translators: %s: error message */
1928 'ajaxError' => __( 'AJAX Error: %s', 'vigilante' ),
1929 // Activity log popup strings
1930 'logRequest' => __( 'Request', 'vigilante' ),
1931 'logDate' => __( 'Date', 'vigilante' ),
1932 'logMethod' => __( 'Method', 'vigilante' ),
1933 'logType' => __( 'Type', 'vigilante' ),
1934 'logAction' => __( 'Action', 'vigilante' ),
1935 'logSeverity' => __( 'Severity', 'vigilante' ),
1936 'logMessage' => __( 'Message', 'vigilante' ),
1937 'logRequestUri' => __( 'Address', 'vigilante' ),
1938 'logClient' => __( 'Client', 'vigilante' ),
1939 'logUser' => __( 'User', 'vigilante' ),
1940 'logIpAddress' => __( 'IP Address', 'vigilante' ),
1941 'logUserAgent' => __( 'User Agent', 'vigilante' ),
1942 'logIpLabel' => __( 'IP:', 'vigilante' ),
1943 'logUaLabel' => __( 'UA:', 'vigilante' ),
1944 'logWhitelist' => __( 'Whitelist', 'vigilante' ),
1945 'logBlacklist' => __( 'Blacklist', 'vigilante' ),
1946 'logInWhitelist' => __( 'In whitelist', 'vigilante' ),
1947 'logInBlacklist' => __( 'In blacklist', 'vigilante' ),
1948 'logAdded' => __( 'Added!', 'vigilante' ),
1949 'logErrorAddingToList' => __( 'Error adding to list', 'vigilante' ),
1950 'logRequestFailed' => __( 'Request failed', 'vigilante' ),
1951 // Activity log table strings
1952 'noLogEntries' => __( 'No log entries found.', 'vigilante' ),
1953 'view' => __( 'View', 'vigilante' ),
1954 'confirmClearLogs' => __( 'This will delete all audit logs.', 'vigilante' ),
1955 // Export logs strings
1956 'exporting' => __( 'Exporting...', 'vigilante' ),
1957 /* translators: %d: number of entries */
1958 'logsExported' => __( 'Logs exported (%d entries)', 'vigilante' ),
1959 'noLogsToExport' => __( 'No logs to export', 'vigilante' ),
1960 'exportFailed' => __( 'Export failed', 'vigilante' ),
1961 'exportLogs' => __( 'Export Logs', 'vigilante' ),
1962 // Backup strings
1963 'backupCreated' => __( 'Backup created successfully.', 'vigilante' ),
1964 'createBackupNow' => __( 'Download Backup', 'vigilante' ),
1965 'downloadBackup' => __( 'Download Backup (.zip)', 'vigilante' ),
1966 /* translators: %d: number of tables */
1967 'tablesCount' => __( '%d tables', 'vigilante' ),
1968 /* translators: 1: table count, 2: human-readable size */
1969 'dbTablesTotal' => __( '%1$d tables total (%2$s)', 'vigilante' ),
1970 /* translators: 1: selected count, 2: human-readable size */
1971 'dbTablesSelected' => __( '%1$d tables selected (%2$s)', 'vigilante' ),
1972 // Settings search strings
1973 'searchNoResults' => __( 'No matching settings found.', 'vigilante' ),
1974 /* translators: %d: number of results that did not fit in the list. */
1975 'searchMoreResults' => __( '%d more results. Refine the search to see them.', 'vigilante' ),
1976 'searchInTab' => __( 'in', 'vigilante' ),
1977 // Modules string
1978 /* translators: 1: enabled count, 2: total count */
1979 'modulesEnabled' => __( '%1$d / %2$d modules enabled', 'vigilante' ),
1980 // Activity log label maps for JS rendering
1981 'eventTypeLabels' => array(
1982 'login' => __( 'Login', 'vigilante' ),
1983 'user' => __( 'User', 'vigilante' ),
1984 'content' => __( 'Content', 'vigilante' ),
1985 'plugin' => __( 'Plugin', 'vigilante' ),
1986 'theme' => __( 'Theme', 'vigilante' ),
1987 'settings' => __( 'Settings', 'vigilante' ),
1988 'comment' => __( 'Comment', 'vigilante' ),
1989 'media' => __( 'Media', 'vigilante' ),
1990 'firewall' => __( 'Firewall', 'vigilante' ),
1991 'file' => __( 'File', 'vigilante' ),
1992 'security' => __( 'Security', 'vigilante' ),
1993 'system' => __( 'System', 'vigilante' ),
1994 ),
1995 'severityLabels' => array(
1996 'info' => __( 'Info', 'vigilante' ),
1997 'warning' => __( 'Warning', 'vigilante' ),
1998 'critical' => __( 'Critical', 'vigilante' ),
1999 ),
2000 // Password reset strings
2001 'noUsersFoundSearch' => __( 'No users found', 'vigilante' ),
2002 /* translators: %d: number of users */
2003 'confirmForceReset' => __( 'Force password reset for %d user(s)? A password reset email will be sent to each user.', 'vigilante' ),
2004 'warningResettingSelf' => __( 'WARNING: You are including yourself. Your session will end and you will need to set a new password.', 'vigilante' ),
2005 'processing' => __( 'Processing...', 'vigilante' ),
2006 'anErrorOccurred' => __( 'An error occurred', 'vigilante' ),
2007 'forceResetSelected' => __( 'Force Reset for Selected Users', 'vigilante' ),
2008 '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' ),
2009 'warningResettingSelfAll' => __( 'WARNING: You are including yourself. Your session will end immediately.', 'vigilante' ),
2010 'forceResetAll' => __( 'Force Reset for ALL Users', 'vigilante' ),
2011 // Role-based password reset strings
2012 /* translators: %d: number of users */
2013 'confirmForceResetByRole' => __( 'Force password reset for %d user(s) with the selected roles? A password reset email will be sent to each user.', 'vigilante' ),
2014 'noRolesSelected' => __( 'Please select at least one role.', 'vigilante' ),
2015 'forceResetByRole' => __( 'Force Reset for Selected Roles', 'vigilante' ),
2016 // User approval strings
2017 'confirmApprove' => __( 'Approve this user?', 'vigilante' ),
2018 'approve' => __( 'Approve', 'vigilante' ),
2019 'rejectReason' => __( 'Enter rejection reason (optional):', 'vigilante' ),
2020 'reject' => __( 'Reject', 'vigilante' ),
2021 'noPending' => __( 'No pending registrations.', 'vigilante' ),
2022 // Session management strings
2023 'confirmRevoke' => __( 'Revoke this session?', 'vigilante' ),
2024 'confirmRevokeAll' => __( 'Revoke all other sessions?', 'vigilante' ),
2025 'revokeOthers' => __( 'Revoke All Other Sessions', 'vigilante' ),
2026 'confirmRevokeAllUser' => __( 'Revoke ALL sessions for this user? They will be logged out everywhere.', 'vigilante' ),
2027 'sessionsFor' => __( 'Sessions for:', 'vigilante' ),
2028 'noSessions' => __( 'No active sessions', 'vigilante' ),
2029 'revoke' => __( 'Revoke', 'vigilante' ),
2030 'noUsers' => __( 'No users found', 'vigilante' ),
2031 // Time ago strings
2032 'timeYear' => __( 'year', 'vigilante' ),
2033 'timeYears' => __( 'years', 'vigilante' ),
2034 'timeMonth' => __( 'month', 'vigilante' ),
2035 'timeMonths' => __( 'months', 'vigilante' ),
2036 'timeDay' => __( 'day', 'vigilante' ),
2037 'timeDays' => __( 'days', 'vigilante' ),
2038 'timeHour' => __( 'hour', 'vigilante' ),
2039 'timeHours' => __( 'hours', 'vigilante' ),
2040 'timeMinute' => __( 'minute', 'vigilante' ),
2041 'timeMinutes' => __( 'minutes', 'vigilante' ),
2042 /* translators: %1$d: count, %2$s: time unit */
2043 'timeAgo' => __( '%1$d %2$s ago', 'vigilante' ),
2044 'justNow' => __( 'Just now', 'vigilante' ),
2045 // Pagination strings
2046 /* translators: 1: first item number, 2: last item number, 3: total items */
2047 'paginationOf' => __( '%1$d–%2$d of %3$d', 'vigilante' ),
2048 'paginationEmpty' => __( '0 items', 'vigilante' ),
2049 // Security Analyzer strings
2050 'analyzerScanNow' => __( 'Scan now', 'vigilante' ),
2051 'analyzerScanning' => __( 'Scanning…', 'vigilante' ),
2052 'analyzerFastPhase' => __( 'Running fast checks…', 'vigilante' ),
2053 'analyzerSlowPhase' => __( 'Running remote checks…', 'vigilante' ),
2054 'analyzerScanComplete' => __( 'Security scan complete.', 'vigilante' ),
2055 'analyzerScanFailed' => __( 'Security scan failed.', 'vigilante' ),
2056 'analyzerShowDetails' => __( 'Show detailed breakdown', 'vigilante' ),
2057 'analyzerHideDetails' => __( 'Hide detailed breakdown', 'vigilante' ),
2058 'analyzerGoToSetting' => __( 'Go to setting', 'vigilante' ),
2059 'analyzerNoData' => __( 'No data yet — run a scan to populate this category.', 'vigilante' ),
2060 'analyzerJustNow' => __( 'just now', 'vigilante' ),
2061 'analyzerAgo' => __( 'ago', 'vigilante' ),
2062 'analyzerSettingsSaved' => __( 'Analyzer settings saved.', 'vigilante' ),
2063 'analyzerLastScanJustNow' => __( 'Last scan just now', 'vigilante' ),
2064 'analyzerQualityExcellent' => __( 'Excellent', 'vigilante' ),
2065 'analyzerQualityGood' => __( 'Good', 'vigilante' ),
2066 'analyzerQualityFair' => __( 'Fair', 'vigilante' ),
2067 'analyzerQualityPoor' => __( 'Poor', 'vigilante' ),
2068 'analyzerQualityCritical' => __( 'Critical', 'vigilante' ),
2069 'analyzerPts' => __( 'pts', 'vigilante' ),
2070 'analyzerLearnMore' => __( 'Learn more', 'vigilante' ),
2071 'analyzerInfoAllClear' => __( 'All clear', 'vigilante' ),
2072 /* translators: %d: number of findings in an info-only category */
2073 'analyzerInfoFindings' => __( '%d findings', 'vigilante' ),
2074 ),
2075 ) );
2076
2077 // 2FA Admin assets
2078 wp_enqueue_style(
2079 'vigilante-2fa-admin',
2080 VIGILANTE_ASSETS_URL . 'css/two-factor-admin.css',
2081 array( 'vigilante-admin' ),
2082 VIGILANTE_VERSION
2083 );
2084
2085 wp_enqueue_script(
2086 'vigilante-2fa-admin',
2087 VIGILANTE_ASSETS_URL . 'js/two-factor-admin.js',
2088 array( 'jquery', 'vigilante-admin' ),
2089 VIGILANTE_VERSION,
2090 true
2091 );
2092 }
2093
2094 /**
2095 * Show admin notices
2096 */
2097 /**
2098 * Self-protection notice.
2099 *
2100 * A change to Vigilant own files is shown on every admin screen, because
2101 * waiting for someone to open the plugin is exactly what an attacker who
2102 * patched it would want. A warning is shown only on Vigilant screens, so
2103 * the notice that matters is not diluted. Neither is dismissible, both are
2104 * for administrators only, and on a network the steps depend on whether
2105 * the person can install plugins at all.
2106 */
2107 public function maybe_show_self_protection_notice() {
2108 if ( ! current_user_can( 'manage_options' ) ) {
2109 return;
2110 }
2111 $summary = $this->self_integrity_summary();
2112 $tone = $summary['tone'];
2113 if ( ! in_array( $tone, array( 'critical', 'off', 'warning' ), true ) ) {
2114 return;
2115 }
2116
2117 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading the screen slug to decide where a notice is shown; no action taken.
2118 $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : '';
2119 $on_vigilante = ( 0 === strpos( $page, 'vigilante' ) );
2120 if ( 'warning' === $tone && ! $on_vigilante ) {
2121 return;
2122 }
2123 $alarma = in_array( $tone, array( 'critical', 'off' ), true );
2124
2125 $link = admin_url( 'admin.php?page=vigilante&tab=file-integrity#vigilante-section-fi-self' );
2126 $network = is_multisite() && ! current_user_can( 'update_plugins' );
2127 ?>
2128 <div class="notice notice-<?php echo $alarma ? 'error' : 'warning'; ?> vigilante-self-notice">
2129 <p class="vigilante-self-notice-title">
2130 <span class="dashicons dashicons-shield" aria-hidden="true"></span>
2131 <strong>
2132 <?php
2133 if ( 'critical' === $tone ) {
2134 esc_html_e( 'Vigilant detected changes in its own files', 'vigilante' );
2135 } elseif ( 'off' === $tone ) {
2136 esc_html_e( 'Vigilant self-protection is switched off by code', 'vigilante' );
2137 } else {
2138 echo esc_html( $this->self_integrity_headline( $tone, $summary['state'] ) );
2139 }
2140 ?>
2141 </strong>
2142 </p>
2143 <p class="vigilante-self-notice-text">
2144 <span>
2145 <?php
2146 if ( 'critical' === $tone ) {
2147 esc_html_e( 'Your security plugin may have been tampered with, and while that is true nothing it reports can be trusted.', 'vigilante' );
2148 } elseif ( 'off' === $tone ) {
2149 esc_html_e( 'Nothing is checking that Vigilant own files are intact. File Integrity says which file switches it off.', 'vigilante' );
2150 } else {
2151 esc_html_e( 'File Integrity says what was found, what it means and what to do about it.', 'vigilante' );
2152 }
2153 if ( $network ) {
2154 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' );
2155 }
2156 ?>
2157 </span>
2158 <?php
2159 /*
2160 * One button, on the same line as the text it belongs to, and it
2161 * leads to the whole story. Repairing from a notice, without
2162 * seeing which files, what it means and what it will do, is
2163 * asking someone to fix what they have not read: the repair
2164 * button lives in the card, after all that.
2165 */
2166 ?>
2167 <a class="button button-primary button-small" href="<?php echo esc_url( $link ); ?>">
2168 <?php esc_html_e( 'See what to do', 'vigilante' ); ?>
2169 </a>
2170 </p>
2171 </div>
2172 <?php
2173 }
2174
2175 public function show_admin_notices() {
2176 $this->maybe_show_self_protection_notice();
2177
2178 // Activation notice
2179 if ( get_transient( 'vigilante_activated' ) ) {
2180 ?>
2181 <div class="notice notice-success is-dismissible vigilante-activation-notice">
2182 <p>
2183 <span class="dashicons dashicons-shield vigilante-notice-icon"></span>
2184 <strong><?php esc_html_e( 'Vigilant activated successfully!', 'vigilante' ); ?></strong>
2185 <?php esc_html_e( 'Security protection is now active.', 'vigilante' ); ?>
2186 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante' ) ); ?>">
2187 <?php esc_html_e( 'Configure settings', 'vigilante' ); ?>
2188 </a>
2189 </p>
2190 </div>
2191 <?php
2192 delete_transient( 'vigilante_activated' );
2193 }
2194
2195 // Under Attack mode notice (non-dismissible, shown on all admin pages)
2196 $ua_status = get_option( Vigilante_Under_Attack::OPTION_NAME, array() );
2197 if ( ! empty( $ua_status['active'] ) ) {
2198 $ua_remaining = ( $ua_status['activated_at'] + $ua_status['duration'] ) - time();
2199 if ( $ua_remaining > 0 ) {
2200 $ua_hours = floor( $ua_remaining / 3600 );
2201 $ua_mins = floor( ( $ua_remaining % 3600 ) / 60 );
2202 $dashboard_url = admin_url( 'admin.php?page=vigilante' );
2203 ?>
2204 <div class="notice notice-warning vigilante-ua-notice">
2205 <p>
2206 <span class="dashicons dashicons-shield"></span>
2207 <strong><?php esc_html_e( 'Under Attack mode is active', 'vigilante' ); ?></strong>
2208 &mdash;
2209 <?php
2210 printf(
2211 /* translators: 1: Hours, 2: Minutes */
2212 esc_html__( '%1$dh %2$dm remaining.', 'vigilante' ),
2213 absint( $ua_hours ),
2214 absint( $ua_mins )
2215 );
2216 ?>
2217 <a href="<?php echo esc_url( $dashboard_url ); ?>">
2218 <?php esc_html_e( 'Go to Vigilant dashboard', 'vigilante' ); ?>
2219 </a>
2220 </p>
2221 <p>
2222 <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>
2223 </p>
2224 <?php
2225 // The cache-bypass rules could not be written (a host where
2226 // WordPress cannot write files by itself, a held lock, a
2227 // failed read-back): show them, so they can be added by hand.
2228 $ua_instance = new Vigilante_Under_Attack( $this->settings, $this->activity_log );
2229 if ( $ua_instance->cache_rules_missing() ) :
2230 ?>
2231 <p>
2232 <strong><?php esc_html_e( 'The cache-bypass rules could not be written to your .htaccess.', 'vigilante' ); ?></strong>
2233 <?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' ); ?>
2234 </p>
2235 <textarea readonly rows="9" class="large-text code" onclick="this.select();"><?php echo esc_textarea( Vigilante_Under_Attack::get_cache_bypass_block() ); ?></textarea>
2236 <?php endif; ?>
2237 </div>
2238 <?php
2239 }
2240 }
2241
2242 // Proxy/CDN detection: if IP detection is set to "direct" but requests
2243 // arrive with a forwarded-for header carrying a different valid IP, the
2244 // site is very likely behind a proxy/CDN that has not been declared, so
2245 // the firewall is seeing the proxy IP for every visitor. Guide the admin.
2246 //
2247 // Two deliberate silencers (2.9.2):
2248 // - A loopback forwarded IP (::1 / 127.x) means the person browsing IS
2249 // the machine itself: that only happens in local development stacks
2250 // (Local's nginx router, Docker...), never behind a production
2251 // proxy/CDN, so the notice would be pure noise there.
2252 // - The notice is dismissible and the dismissal persists site-wide via
2253 // the vigilante_dismissed_notices option (the admin evaluated it and
2254 // decided; nagging forever helps nobody).
2255 $dismissed_notices = get_option( 'vigilante_dismissed_notices', array() );
2256 if (
2257 current_user_can( 'manage_options' )
2258 && '' === Vigilante_IP_Utils::trusted_proxy_header()
2259 && ! isset( $dismissed_notices['proxy_detection'] )
2260 ) {
2261 $remote = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '';
2262 $detected = '';
2263 foreach ( Vigilante_IP_Utils::trusted_header_map() as $proxy_label => $server_key ) {
2264 if ( empty( $_SERVER[ $server_key ] ) ) {
2265 continue;
2266 }
2267 $candidate = sanitize_text_field( wp_unslash( $_SERVER[ $server_key ] ) );
2268 if ( false !== strpos( $candidate, ',' ) ) {
2269 $parts = explode( ',', $candidate );
2270 $candidate = trim( $parts[0] );
2271 }
2272 if ( ! filter_var( $candidate, FILTER_VALIDATE_IP ) || $candidate === $remote ) {
2273 continue;
2274 }
2275 // Loopback forwarded IP = local development, not a real proxy.
2276 if ( '::1' === $candidate || 0 === strpos( $candidate, '127.' ) ) {
2277 continue;
2278 }
2279 $detected = $proxy_label;
2280 break;
2281 }
2282
2283 if ( '' !== $detected ) {
2284 $firewall_url = admin_url( 'admin.php?page=vigilante&tab=firewall' );
2285 $detail_message = sprintf(
2286 /* translators: %s: detected forwarded header name wrapped in a code tag. */
2287 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' ),
2288 '<code>' . esc_html( strtoupper( $detected ) ) . '</code>'
2289 );
2290 ?>
2291 <div class="notice notice-warning is-dismissible vigilante-proxy-notice">
2292 <p>
2293 <span class="dashicons dashicons-shield"></span>
2294 <strong><?php esc_html_e( 'Vigilant: this site looks like it is behind a proxy or CDN', 'vigilante' ); ?></strong>
2295 </p>
2296 <p><?php echo wp_kses_post( $detail_message ); ?></p>
2297 <p>
2298 <a href="<?php echo esc_url( $firewall_url ); ?>" class="button button-secondary">
2299 <?php esc_html_e( 'Set your proxy in Firewall settings', 'vigilante' ); ?>
2300 </a>
2301 </p>
2302 </div>
2303 <script>
2304 jQuery( function ( $ ) {
2305 $( document ).on( 'click', '.vigilante-proxy-notice .notice-dismiss', function () {
2306 $.post( ajaxurl, {
2307 action: 'vigilante_dismiss_notice',
2308 notice_id: 'proxy_detection',
2309 nonce: <?php echo wp_json_encode( wp_create_nonce( 'vigilante_dismiss_notice' ) ); ?>
2310 } );
2311 } );
2312 } );
2313 </script>
2314 <?php
2315 }
2316 }
2317 }
2318
2319 /**
2320 * Render settings page
2321 */
2322 public function render_settings_page() {
2323 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
2324 $this->current_tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'dashboard';
2325
2326 if ( ! array_key_exists( $this->current_tab, $this->tabs ) ) {
2327 $this->current_tab = 'dashboard';
2328 }
2329 ?>
2330 <div class="wrap vigilante-admin-wrap">
2331 <div class="vigilante-header-row">
2332 <h1 class="vigilante-page-title">
2333 <img src="<?php echo esc_url( VIGILANTE_ASSETS_URL . 'images/icon.png' ); ?>" alt="Vigilante" class="vigilante-title-icon">
2334 <?php esc_html_e( 'Vigilant', 'vigilante' ); ?>
2335 <span class="vigilante-version">v<?php echo esc_html( VIGILANTE_VERSION ); ?></span>
2336 </h1>
2337 <div class="vigilante-search-wrapper">
2338 <div class="vigilante-search-input-wrap">
2339 <span class="vigilante-search-icon dashicons dashicons-search" aria-hidden="true"></span>
2340 <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">
2341 <span class="vigilante-search-shortcut" aria-hidden="true">/</span>
2342 </div>
2343 <div id="vigilante-settings-search-results" class="vigilante-search-results" hidden role="listbox"></div>
2344 </div>
2345 </div>
2346
2347 <?php $this->render_tabs(); ?>
2348
2349 <div class="vigilante-content">
2350 <div class="vigilante-main">
2351 <?php $this->render_tab_content(); ?>
2352 </div>
2353 <div class="vigilante-sidebar">
2354 <?php $this->render_sidebar(); ?>
2355 </div>
2356 </div>
2357 </div>
2358 <?php
2359 }
2360
2361 /**
2362 * Render tabs navigation
2363 */
2364 private function render_tabs() {
2365 $options = $this->settings->get_all_options();
2366
2367 // Map tabs to modules
2368 $tab_to_module = array(
2369 'firewall' => 'firewall',
2370 'headers' => 'security_headers',
2371 'login' => 'login_security',
2372 'rest-api' => 'rest_api_security',
2373 'users' => 'user_security',
2374 'wp-hardening' => 'wp_hardening',
2375 'file-integrity' => 'file_integrity',
2376 'activity-log' => 'activity_log',
2377 );
2378 ?>
2379 <nav class="nav-tab-wrapper vigilante-nav-tabs">
2380 <?php foreach ( $this->tabs as $tab_id => $tab_name ) :
2381 $is_disabled = false;
2382 $module = isset( $tab_to_module[ $tab_id ] ) ? $tab_to_module[ $tab_id ] : null;
2383 if ( $module && empty( $options['modules'][ $module ] ) ) {
2384 $is_disabled = true;
2385 }
2386 ?>
2387 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=' . $tab_id ) ); ?>"
2388 class="nav-tab <?php echo $this->current_tab === $tab_id ? 'nav-tab-active' : ''; ?> <?php echo $is_disabled ? 'vigilante-tab-disabled' : ''; ?>"
2389 <?php if ( $is_disabled ) : ?>title="<?php esc_attr_e( 'Module Disabled', 'vigilante' ); ?>"<?php endif; ?>>
2390 <?php echo esc_html( $tab_name ); ?>
2391 <?php if ( $is_disabled ) : ?><span class="vigilante-tab-off">OFF</span><?php endif; ?>
2392 </a>
2393 <?php endforeach; ?>
2394 </nav>
2395 <?php
2396 }
2397
2398 /**
2399 * Render current tab content
2400 */
2401 private function render_tab_content() {
2402 $method = 'render_tab_' . str_replace( '-', '_', $this->current_tab );
2403
2404 if ( method_exists( $this, $method ) ) {
2405 $this->$method();
2406 } else {
2407 $this->render_tab_coming_soon();
2408 }
2409 }
2410
2411 /**
2412 * Render coming soon placeholder
2413 */
2414 private function render_tab_coming_soon() {
2415 ?>
2416 <div class="vigilante-settings-section">
2417 <h2><?php esc_html_e( 'Coming Soon', 'vigilante' ); ?></h2>
2418 <p><?php esc_html_e( 'This section is under development.', 'vigilante' ); ?></p>
2419 </div>
2420 <?php
2421 }
2422
2423 /**
2424 * Values to display for a section that this site does not control
2425 *
2426 * On a subsite the stored options are its own copy, which nothing acts on:
2427 * wp-config.php and .htaccess are written from the main site. Painting the
2428 * local copy describes a configuration that is not running, so a subsite
2429 * admin sees a box ticked here and the constant absent from the file, or the
2430 * other way round. Read the main site's values instead, which are the ones in
2431 * force, and fall back to the local ones if they cannot be read.
2432 *
2433 * @since 2.9.8
2434 *
2435 * @param string $section Settings section.
2436 * @return array
2437 */
2438 private function get_section_for_display( $section ) {
2439 $local = $this->settings->get_section( $section );
2440
2441 if ( ! $this->shared_files_locked() ) {
2442 return $local;
2443 }
2444
2445 // shared_files_locked() is only true on multisite, where get_blog_option() exists.
2446 $main = get_blog_option( get_main_site_id(), Vigilante_Settings::OPTION_NAME, array() );
2447
2448 if ( ! is_array( $main ) || empty( $main[ $section ] ) || ! is_array( $main[ $section ] ) ) {
2449 return $local;
2450 }
2451
2452 return wp_parse_args( $main[ $section ], $local );
2453 }
2454
2455 /**
2456 * Whether the sections that write wp-config.php and .htaccess are read-only here
2457 *
2458 * True on a network when this is not the main site, or the user is not a
2459 * network administrator. See Vigilante_Settings::can_write_shared_files().
2460 *
2461 * @since 2.9.8
2462 *
2463 * @return bool
2464 */
2465 private function shared_files_locked() {
2466 return ! Vigilante_Settings::can_write_shared_files();
2467 }
2468
2469 /**
2470 * Whether this is the main site and the user cannot change what it builds the shared files from
2471 *
2472 * See Vigilante_Settings::get_main_site_file_settings(). On a subsite those
2473 * settings only act on that site, so they are never locked there.
2474 *
2475 * @since 2.11.6
2476 *
2477 * @return bool
2478 */
2479 private function main_site_files_locked() {
2480 return $this->shared_files_locked() && Vigilante_Settings::owns_shared_files();
2481 }
2482
2483 /**
2484 * Sentence added to a bulk change when some settings were left as they were
2485 *
2486 * Importing a file, applying a preset and restoring the defaults touch every
2487 * section at once, so the user is told that the shared file settings did
2488 * not move.
2489 *
2490 * @since 2.11.6
2491 *
2492 * @return string Empty when the user can change every setting.
2493 */
2494 private function locked_file_settings_message() {
2495 if ( ! Vigilante_Settings::get_locked_file_settings() ) {
2496 return '';
2497 }
2498
2499 return ' ' . __( 'The settings that end up in wp-config.php or .htaccess were left as they were.', 'vigilante' ) . ' ' . Vigilante_Settings::get_shared_files_notice();
2500 }
2501
2502 /**
2503 * Print the shared-files notice for a section that cannot be edited here
2504 *
2505 * @since 2.9.8
2506 */
2507 private function render_shared_files_notice() {
2508 if ( ! $this->shared_files_locked() ) {
2509 return;
2510 }
2511 ?>
2512 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
2513 <p style="margin:0;"><?php echo esc_html( Vigilante_Settings::get_shared_files_notice() ); ?></p>
2514 </div>
2515 <?php
2516 }
2517
2518 /**
2519 * Acting on another user's account needs permission over that user
2520 *
2521 * Since 2.10.3 the handlers behind these tools ask for edit_user over the
2522 * target, which is the rule WordPress itself applies. On a network the core
2523 * grants edit_user only to network administrators, so for anybody else these
2524 * controls do nothing. Better to say so than to paint a button that silently
2525 * skips every user.
2526 *
2527 * @since 2.10.4
2528 * @return bool
2529 */
2530 private function forwarded_chain_readings() {
2531 // Shown, not decided on: the firewall resolves the address elsewhere.
2532 $chain = Vigilante_IP_Utils::trusted_forwarded_for();
2533
2534 if ( '' === $chain ) {
2535 return array();
2536 }
2537
2538 $public = array();
2539
2540 foreach ( explode( ',', $chain ) as $entry ) {
2541 $address = Vigilante_IP_Utils::unmap_ipv4( trim( $entry ) );
2542
2543 if ( filter_var( $address, FILTER_VALIDATE_IP ) && ! Vigilante_IP_Utils::is_own_network( $address ) ) {
2544 $public[] = $address;
2545 }
2546 }
2547
2548 if ( count( $public ) < 2 ) {
2549 return array();
2550 }
2551
2552 return array(
2553 'now' => Vigilante_IP_Utils::client_from_chain( $chain ),
2554 'before' => $public[0],
2555 );
2556 }
2557
2558 /**
2559 * Whether the user tools of this screen are out of reach for this user
2560 *
2561 * @return bool
2562 */
2563 private function user_actions_locked() {
2564 // On a single site edit_user maps to edit_users, which a custom role with
2565 // manage_options may lack: since 2.11.8 approving and rejecting a pending
2566 // registration ask for it, so the buttons have to say so there too.
2567 return is_multisite() ? ! current_user_can( 'manage_network_users' ) : ! current_user_can( 'edit_users' );
2568 }
2569
2570 /**
2571 * Print the notice for user tools that cannot be used from this site
2572 *
2573 * @since 2.10.4
2574 */
2575 private function render_user_actions_notice() {
2576 if ( ! $this->user_actions_locked() ) {
2577 return;
2578 }
2579 ?>
2580 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
2581 <?php if ( is_multisite() ) : ?>
2582 <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>
2583 <?php else : ?>
2584 <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>
2585 <?php endif; ?>
2586 </div>
2587 <?php
2588 }
2589
2590 /**
2591 * Approving a change to the shared config files needs the network
2592 *
2593 * Since 2.11.3 the handler behind the Approve button asks for
2594 * manage_network_options, because the two files it approves, wp-config.php
2595 * and the root .htaccess, belong to the installation, and so does the
2596 * record of them. The button, though, went on being painted for everybody,
2597 * so the administrator of a subsite saw the warning, saw the button,
2598 * pressed it and got "Permission denied" with no explanation. That is
2599 * exactly what user_actions_locked() above exists to avoid, one release
2600 * later and one screen over. Flagged by @calzbert.
2601 *
2602 * @since 2.11.4
2603 * @return bool
2604 */
2605 private function critical_approval_locked() {
2606 return is_multisite() && ! current_user_can( 'manage_network_options' );
2607 }
2608
2609 /**
2610 * The line that replaces the Approve button where it cannot be used
2611 *
2612 * @since 2.11.4
2613 * @return string
2614 */
2615 private function critical_approval_notice() {
2616 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' );
2617 }
2618
2619 /**
2620 * Check if module is disabled and render warning
2621 *
2622 * @param string $module_key Module key.
2623 * @return bool True if disabled.
2624 */
2625 private function render_module_disabled_notice( $module_key ) {
2626 if ( $this->settings->is_module_enabled( $module_key ) ) {
2627 return false;
2628 }
2629
2630 $module_labels = $this->settings->get_module_labels();
2631 $module_name = isset( $module_labels[ $module_key ] ) ? $module_labels[ $module_key ] : $module_key;
2632 ?>
2633 <div class="notice notice-warning vigilante-module-disabled-notice">
2634 <p>
2635 <strong><?php esc_html_e( 'Module Disabled', 'vigilante' ); ?></strong> -
2636 <?php
2637 printf(
2638 /* translators: %s: Module name */
2639 esc_html__( 'The %s module is currently disabled. Enable it from the Dashboard to use these settings.', 'vigilante' ),
2640 esc_html( $module_name )
2641 );
2642 ?>
2643 </p>
2644 <p>
2645 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=dashboard' ) ); ?>" class="button">
2646 <?php esc_html_e( 'Go to Dashboard', 'vigilante' ); ?>
2647 </a>
2648 </p>
2649 </div>
2650 <?php
2651 return true;
2652 }
2653
2654 /**
2655 * Render the Security Analyzer (Security Check) widget + expandable full report.
2656 *
2657 * Lives in the Dashboard tab between the Configuration Score status card and
2658 * the modules grid. Uses the last persisted scan to hydrate server-side so the
2659 * first paint shows real data; "Scan now" runs the 2-phase AJAX to refresh.
2660 *
2661 * @param array $last_scan Result of Vigilante_Security_Analyzer::get_last_scan().
2662 * @param array $history Score history (oldest first).
2663 * @param array $categories_def Category metadata (slug => label/max).
2664 * @param array $analyzer_settings Settings subsection for weekly cron + email.
2665 */
2666 private function render_analyzer_widget( $last_scan, $history, $categories_def, $analyzer_settings ) {
2667 $has_data = ! empty( $last_scan['ran_at'] );
2668 $score = isset( $last_scan['score'] ) ? (int) $last_scan['score'] : 0;
2669 $grade = isset( $last_scan['grade'] ) ? (string) $last_scan['grade'] : '';
2670 $counts = isset( $last_scan['counts'] ) && is_array( $last_scan['counts'] ) ? $last_scan['counts'] : array();
2671 $ran_at_human = $has_data
2672 ? sprintf(
2673 /* translators: %s: relative time like "2 hours" */
2674 __( 'Last scan %s ago', 'vigilante' ),
2675 human_time_diff( (int) $last_scan['ran_at'], time() )
2676 )
2677 : __( 'Never scanned', 'vigilante' );
2678 $categories = isset( $last_scan['categories'] ) && is_array( $last_scan['categories'] ) ? $last_scan['categories'] : array();
2679 $weekly_enabled = ! isset( $analyzer_settings['weekly_scan_enabled'] ) || ! empty( $analyzer_settings['weekly_scan_enabled'] );
2680 $email_enabled = ! empty( $analyzer_settings['email_on_regression'] );
2681
2682 /*
2683 * Self-protection caps the score, and it does so here and not only in
2684 * the stored report: the report is reused until the next Security
2685 * Check, so tampering found after it ran would otherwise be shown next
2686 * to the score the site earned before it happened.
2687 */
2688 $self_summary = $this->self_integrity_summary();
2689 $self_capped = in_array( $self_summary['tone'], array( 'critical', 'off' ), true )
2690 || ( 'self_integrity' === ( isset( $last_scan['capped_by'] ) ? $last_scan['capped_by'] : '' ) );
2691 if ( $self_capped && $has_data && $score > Vigilante_Security_Analyzer::SCORE_CAP_ON_TAMPER ) {
2692 $score = Vigilante_Security_Analyzer::SCORE_CAP_ON_TAMPER;
2693 $grade = 'E';
2694 }
2695
2696 $quality = self::analyzer_quality_tag( $score );
2697 ?>
2698 <div class="vigilante-analyzer" id="vigilante-analyzer"
2699 data-has-data="<?php echo $has_data ? '1' : '0'; ?>">
2700 <div class="vigilante-analyzer-header">
2701 <div class="vigilante-analyzer-title">
2702 <h2>
2703 <span class="dashicons dashicons-shield-alt" aria-hidden="true"></span>
2704 <?php esc_html_e( 'Security Check', 'vigilante' ); ?>
2705 </h2>
2706 <p class="description">
2707 <?php esc_html_e( 'On-demand audit of what an attacker would see right now, plus 13 internal checks impossible from the outside.', 'vigilante' ); ?>
2708 </p>
2709 <p class="vigilante-analyzer-last-scan" data-role="ran-at">
2710 <span class="dashicons dashicons-clock" aria-hidden="true"></span>
2711 <?php echo esc_html( $ran_at_human ); ?>
2712 </p>
2713 </div>
2714 <div class="vigilante-analyzer-actions">
2715 <button type="button" class="button button-primary" id="vigilante-analyzer-scan">
2716 <span class="dashicons dashicons-update" aria-hidden="true"></span>
2717 <?php esc_html_e( 'Scan now', 'vigilante' ); ?>
2718 </button>
2719 </div>
2720 </div>
2721
2722 <?php if ( $self_capped ) : ?>
2723 <p class="vigilante-analyzer-capped">
2724 <span class="dashicons dashicons-shield" aria-hidden="true"></span>
2725 <strong><?php esc_html_e( 'This score is not reliable right now.', 'vigilante' ); ?></strong>
2726 <?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' ); ?>
2727 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=file-integrity#vigilante-section-fi-self' ) ); ?>">
2728 <?php esc_html_e( 'See what to do', 'vigilante' ); ?>
2729 </a>
2730 </p>
2731 <?php endif; ?>
2732
2733 <div class="vigilante-analyzer-summary">
2734 <div class="vigilante-analyzer-score-card">
2735 <?php if ( $has_data && $grade ) : ?>
2736 <div class="vigilante-score-circle vigilante-grade-<?php echo esc_attr( strtolower( $grade ) ); ?>">
2737 <span class="vigilante-grade"><?php echo esc_html( $grade ); ?></span>
2738 <span class="vigilante-score-text"><?php echo esc_html( $score ); ?>%</span>
2739 </div>
2740 <?php else : ?>
2741 <div class="vigilante-score-circle vigilante-grade-empty">
2742 <span class="vigilante-grade">—</span>
2743 <span class="vigilante-score-text"><?php esc_html_e( 'N/A', 'vigilante' ); ?></span>
2744 </div>
2745 <?php endif; ?>
2746 <div class="vigilante-analyzer-score-meta">
2747 <p class="vigilante-analyzer-score-label">
2748 <?php esc_html_e( 'Security Score', 'vigilante' ); ?>
2749 </p>
2750 <span class="vigilante-analyzer-quality-tag vigilante-analyzer-quality-<?php echo esc_attr( $quality['slug'] ); ?>"
2751 data-role="quality-tag">
2752 <?php echo esc_html( $quality['label'] ); ?>
2753 </span>
2754 </div>
2755 </div>
2756
2757 <div class="vigilante-analyzer-counts">
2758 <span class="vigilante-analyzer-count vigilante-analyzer-count--pass">
2759 <span class="dashicons dashicons-yes-alt" aria-hidden="true"></span>
2760 <strong data-role="pass"><?php echo esc_html( isset( $counts['pass'] ) ? $counts['pass'] : 0 ); ?></strong>
2761 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Passed', 'vigilante' ); ?></span>
2762 </span>
2763 <span class="vigilante-analyzer-count vigilante-analyzer-count--warn">
2764 <span class="dashicons dashicons-warning" aria-hidden="true"></span>
2765 <strong data-role="warn"><?php echo esc_html( isset( $counts['warn'] ) ? $counts['warn'] : 0 ); ?></strong>
2766 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Warnings', 'vigilante' ); ?></span>
2767 </span>
2768 <span class="vigilante-analyzer-count vigilante-analyzer-count--fail">
2769 <span class="dashicons dashicons-dismiss" aria-hidden="true"></span>
2770 <strong data-role="fail"><?php echo esc_html( isset( $counts['fail'] ) ? $counts['fail'] : 0 ); ?></strong>
2771 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Failing', 'vigilante' ); ?></span>
2772 </span>
2773 </div>
2774
2775 <?php
2776 // Sparkline of recent scores. Require at least 3 data points so the trend
2777 // is meaningful (2 points is just a line between dots, no real trend).
2778 $hist_points = array();
2779 foreach ( $history as $h ) {
2780 $hist_points[] = (int) $h['score'];
2781 }
2782 $hist_count = count( $hist_points );
2783 if ( $hist_count >= 3 ) :
2784 $current_score = (int) end( $hist_points );
2785 $previous_score = (int) $hist_points[ $hist_count - 2 ];
2786 $delta = $current_score - $previous_score;
2787 $delta_class = $delta > 0 ? 'vigilante-analyzer-delta--up' : ( $delta < 0 ? 'vigilante-analyzer-delta--down' : 'vigilante-analyzer-delta--flat' );
2788 $delta_icon = $delta > 0 ? 'arrow-up-alt' : ( $delta < 0 ? 'arrow-down-alt' : 'minus' );
2789 if ( 0 === $delta ) {
2790 $delta_text = __( 'No change', 'vigilante' );
2791 } else {
2792 $delta_text = sprintf(
2793 /* translators: %s: signed delta, e.g. "+3" or "-5" */
2794 _n( '%s pt vs. previous scan', '%s pts vs. previous scan', abs( $delta ), 'vigilante' ),
2795 ( $delta > 0 ? '+' : '' ) . (int) $delta
2796 );
2797 }
2798 ?>
2799 <div class="vigilante-analyzer-sparkline-wrap">
2800 <div class="vigilante-analyzer-sparkline-head">
2801 <span class="vigilante-analyzer-sparkline-label">
2802 <?php
2803 echo esc_html( sprintf(
2804 /* translators: %d: number of scans */
2805 _n( 'Score trend (last %d scan)', 'Score trend (last %d scans)', $hist_count, 'vigilante' ),
2806 $hist_count
2807 ) );
2808 ?>
2809 </span>
2810 <span class="vigilante-analyzer-delta <?php echo esc_attr( $delta_class ); ?>">
2811 <span class="dashicons dashicons-<?php echo esc_attr( $delta_icon ); ?>" aria-hidden="true"></span>
2812 <?php echo esc_html( $delta_text ); ?>
2813 </span>
2814 </div>
2815 <div class="vigilante-analyzer-sparkline" data-role="sparkline"
2816 data-points="<?php echo esc_attr( wp_json_encode( $hist_points ) ); ?>">
2817 <?php echo self::sparkline_svg( $hist_points ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Safe SVG from helper ?>
2818 </div>
2819 </div>
2820 <?php elseif ( $has_data ) : ?>
2821 <div class="vigilante-analyzer-sparkline-wrap vigilante-analyzer-sparkline-wrap--placeholder">
2822 <span class="vigilante-analyzer-sparkline-label">
2823 <?php esc_html_e( 'Score trend', 'vigilante' ); ?>
2824 </span>
2825 <p class="vigilante-analyzer-sparkline-hint">
2826 <span class="dashicons dashicons-chart-line" aria-hidden="true"></span>
2827 <?php
2828 $needed = 3 - $hist_count;
2829 echo esc_html( sprintf(
2830 /* translators: %d: number of additional scans needed */
2831 _n( '%d more scan needed to show a trend.', '%d more scans needed to show a trend.', $needed, 'vigilante' ),
2832 $needed
2833 ) );
2834 ?>
2835 </p>
2836 </div>
2837 <?php endif; ?>
2838 </div>
2839
2840 <div class="vigilante-analyzer-toggle-row">
2841 <button type="button" class="button-link vigilante-analyzer-toggle" aria-expanded="false">
2842 <?php esc_html_e( 'Show detailed breakdown', 'vigilante' ); ?>
2843 <span class="vigilante-analyzer-toggle-chevron" aria-hidden="true"></span>
2844 </button>
2845 </div>
2846
2847 <div class="vigilante-analyzer-details" hidden>
2848 <div class="vigilante-analyzer-categories" data-role="categories">
2849 <?php foreach ( $categories_def as $slug => $meta ) :
2850 $cat = isset( $categories[ $slug ] ) ? $categories[ $slug ] : array();
2851 $earned = isset( $cat['earned'] ) ? (int) $cat['earned'] : 0;
2852 // Always use the declared meta as the source of truth for the maximum.
2853 // The cached scan may carry an old max if a check was added/removed
2854 // between releases (see 2.6.1: closed_plugins raised internal from 22 to 28
2855 // but cached scans still reported max=22 until reset).
2856 $cat_max = (int) $meta['max'];
2857 $info_only = ! empty( $meta['info_only'] ) || 0 === (int) $meta['max'];
2858 $cat_pct = $cat_max > 0 ? (int) round( ( $earned / $cat_max ) * 100 ) : 0;
2859 $checks = isset( $cat['checks'] ) ? (array) $cat['checks'] : array();
2860 $cat_counts = isset( $cat['counts'] ) && is_array( $cat['counts'] ) ? $cat['counts'] : array( 'pass' => 0, 'warn' => 0, 'fail' => 0, 'info' => 0 );
2861 $cat_quality = self::analyzer_quality_tag( $cat_pct );
2862 $info_count = isset( $cat_counts['info'] ) ? (int) $cat_counts['info'] : 0;
2863 ?>
2864 <details class="vigilante-analyzer-category<?php echo $info_only ? ' vigilante-analyzer-category--info' : ''; ?>"
2865 data-category="<?php echo esc_attr( $slug ); ?>"
2866 data-info-only="<?php echo $info_only ? '1' : '0'; ?>">
2867 <summary class="vigilante-analyzer-category-summary">
2868 <span class="vigilante-analyzer-category-chevron" aria-hidden="true"></span>
2869 <span class="vigilante-analyzer-category-label"><?php echo esc_html( $meta['label'] ); ?></span>
2870 <?php if ( $info_only ) : ?>
2871 <span class="vigilante-analyzer-category-quality vigilante-analyzer-quality-info"
2872 data-role="category-quality"
2873 title="<?php esc_attr_e( 'Informational — does not affect the security score.', 'vigilante' ); ?>">
2874 <span class="dashicons dashicons-info-outline" aria-hidden="true"></span>
2875 <?php esc_html_e( 'Informational', 'vigilante' ); ?>
2876 </span>
2877 <?php else :
2878 $passed_count = (int) ( $cat_counts['pass'] ?? 0 );
2879 $scored_total = $passed_count
2880 + (int) ( $cat_counts['warn'] ?? 0 )
2881 + (int) ( $cat_counts['fail'] ?? 0 );
2882 ?>
2883 <span class="vigilante-analyzer-category-quality vigilante-analyzer-quality-<?php echo esc_attr( $cat_quality['slug'] ); ?>"
2884 data-role="category-quality">
2885 <span data-role="category-quality-label"><?php echo esc_html( $cat_quality['label'] ); ?></span>
2886 <span class="vigilante-analyzer-category-quality-sep" aria-hidden="true">·</span>
2887 <span class="vigilante-analyzer-category-tests" data-role="category-tests"
2888 data-passed="<?php echo esc_attr( $passed_count ); ?>"
2889 data-total="<?php echo esc_attr( $scored_total ); ?>">
2890 <?php
2891 echo esc_html( sprintf(
2892 /* translators: 1: tests passed, 2: total tests in this category */
2893 __( '%1$d/%2$d tests', 'vigilante' ),
2894 $passed_count,
2895 $scored_total
2896 ) );
2897 ?>
2898 </span>
2899 </span>
2900 <?php endif; ?>
2901 <?php if ( $info_only ) : ?>
2902 <span class="vigilante-analyzer-category-states" data-role="category-states">
2903 <?php if ( $info_count > 0 ) : ?>
2904 <span class="vigilante-analyzer-category-state vigilante-analyzer-category-state--info" title="<?php esc_attr_e( 'Informational', 'vigilante' ); ?>">
2905 <span data-role="state-info"><?php echo esc_html( $info_count ); ?></span><span class="dashicons dashicons-info-outline" aria-hidden="true"></span>
2906 </span>
2907 <?php endif; ?>
2908 </span>
2909 <?php endif; ?>
2910 <?php if ( ! $info_only ) : ?>
2911 <span class="vigilante-analyzer-category-score">
2912 <span data-role="earned"><?php echo esc_html( $earned ); ?></span><span class="vigilante-analyzer-category-score-sep">/</span><?php echo esc_html( $cat_max ); ?>
2913 <span class="vigilante-analyzer-category-score-unit"><?php esc_html_e( 'pts', 'vigilante' ); ?></span>
2914 </span>
2915 <span class="vigilante-analyzer-category-bar" aria-hidden="true">
2916 <span class="vigilante-analyzer-category-bar-fill vigilante-analyzer-category-bar-fill--<?php echo esc_attr( $cat_quality['slug'] ); ?>"
2917 style="width: <?php echo esc_attr( $cat_pct ); ?>%"
2918 data-role="category-bar"></span>
2919 </span>
2920 <?php else :
2921 $info_warn = isset( $cat_counts['warn'] ) ? (int) $cat_counts['warn'] : 0;
2922 $info_fail = isset( $cat_counts['fail'] ) ? (int) $cat_counts['fail'] : 0;
2923 $info_issues = $info_warn + $info_fail;
2924 if ( $info_issues > 0 ) : ?>
2925 <span class="vigilante-analyzer-category-status vigilante-analyzer-category-status--attention" data-role="info-status">
2926 <span class="dashicons dashicons-warning" aria-hidden="true"></span>
2927 <?php
2928 echo esc_html( sprintf(
2929 /* translators: %d: number of findings */
2930 _n( '%d finding', '%d findings', $info_issues, 'vigilante' ),
2931 $info_issues
2932 ) );
2933 ?>
2934 </span>
2935 <?php else : ?>
2936 <span class="vigilante-analyzer-category-status vigilante-analyzer-category-status--clear" data-role="info-status">
2937 <span class="dashicons dashicons-yes-alt" aria-hidden="true"></span>
2938 <?php esc_html_e( 'All clear', 'vigilante' ); ?>
2939 </span>
2940 <?php endif; ?>
2941 <?php endif; ?>
2942 </summary>
2943 <ul class="vigilante-analyzer-check-list" data-role="check-list">
2944 <?php if ( empty( $checks ) ) : ?>
2945 <li class="vigilante-analyzer-check-empty">
2946 <?php esc_html_e( 'No data yet — run a scan to populate this category.', 'vigilante' ); ?>
2947 </li>
2948 <?php else : ?>
2949 <?php foreach ( $checks as $c ) : ?>
2950 <?php echo self::render_analyzer_check_row( $c ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped inside helper ?>
2951 <?php endforeach; ?>
2952 <?php endif; ?>
2953 </ul>
2954 </details>
2955 <?php endforeach; ?>
2956 </div>
2957
2958 <div class="vigilante-analyzer-weekly">
2959 <h3><?php esc_html_e( 'Automatic weekly scan', 'vigilante' ); ?></h3>
2960 <p class="description">
2961 <?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' ); ?>
2962 </p>
2963 <label class="vigilante-analyzer-toggle-option">
2964 <input type="checkbox"
2965 name="security_analyzer[weekly_scan_enabled]"
2966 value="1"
2967 <?php checked( $weekly_enabled ); ?>>
2968 <?php esc_html_e( 'Run a weekly automatic scan', 'vigilante' ); ?>
2969 </label>
2970 <label class="vigilante-analyzer-toggle-option">
2971 <input type="checkbox"
2972 name="security_analyzer[email_on_regression]"
2973 value="1"
2974 <?php checked( $email_enabled ); ?>>
2975 <?php esc_html_e( 'Email me when the score drops significantly', 'vigilante' ); ?>
2976 </label>
2977 </div>
2978 </div>
2979 </div>
2980 <?php
2981 }
2982
2983 /**
2984 * Map a 0-100 percentage to a quality tag { label, slug } aligned with the
2985 * Dashboard grade palette (a/b/c/d/e).
2986 *
2987 * @param int $pct 0..100.
2988 * @return array{label:string,slug:string}
2989 */
2990 public static function analyzer_quality_tag( $pct ) {
2991 $pct = max( 0, min( 100, (int) $pct ) );
2992 // "Excellent" is reserved for a perfect score — a single missing point drops to Good.
2993 if ( 100 === $pct ) {
2994 return array( 'label' => __( 'Excellent', 'vigilante' ), 'slug' => 'a' );
2995 }
2996 if ( $pct >= 70 ) {
2997 return array( 'label' => __( 'Good', 'vigilante' ), 'slug' => 'b' );
2998 }
2999 if ( $pct >= 50 ) {
3000 return array( 'label' => __( 'Fair', 'vigilante' ), 'slug' => 'c' );
3001 }
3002 if ( $pct >= 30 ) {
3003 return array( 'label' => __( 'Poor', 'vigilante' ), 'slug' => 'd' );
3004 }
3005 return array( 'label' => __( 'Critical', 'vigilante' ), 'slug' => 'e' );
3006 }
3007
3008 /**
3009 * Render a single analyzer check row (used both server-side and via JS template).
3010 *
3011 * @param array $check Check result array (from Vigilante_SA_Check_Result::to_array()).
3012 * @return string HTML (escaped).
3013 */
3014 private static function render_analyzer_check_row( $check ) {
3015 $id = isset( $check['id'] ) ? $check['id'] : '';
3016 $state = isset( $check['state'] ) ? $check['state'] : 'skip';
3017 $label = isset( $check['label'] ) ? $check['label'] : '';
3018 $detail = isset( $check['detail'] ) ? $check['detail'] : '';
3019 $score = isset( $check['score'] ) ? (int) $check['score'] : 0;
3020 $max = isset( $check['max'] ) ? (int) $check['max'] : 0;
3021 $fix_link = isset( $check['fix_link'] ) ? $check['fix_link'] : '';
3022
3023 $icons = array(
3024 'pass' => 'yes-alt',
3025 'warn' => 'warning',
3026 'fail' => 'dismiss',
3027 'info' => 'info',
3028 'skip' => 'minus',
3029 );
3030 $icon = isset( $icons[ $state ] ) ? $icons[ $state ] : 'minus';
3031
3032 $html = '<li class="vigilante-analyzer-check vigilante-analyzer-check--' . esc_attr( $state ) . '"';
3033 $html .= ' data-check-id="' . esc_attr( $id ) . '">';
3034 $html .= '<span class="vigilante-analyzer-check-icon dashicons dashicons-' . esc_attr( $icon ) . '" aria-hidden="true"></span>';
3035 $html .= '<div class="vigilante-analyzer-check-body">';
3036 $html .= '<div class="vigilante-analyzer-check-label">';
3037 $html .= '<span>' . esc_html( $label ) . '</span>';
3038 if ( $max > 0 && 'info' !== $state && 'skip' !== $state ) {
3039 $html .= '<span class="vigilante-analyzer-check-score">'
3040 . esc_html( $score . '/' . $max )
3041 . ' <span class="vigilante-analyzer-check-score-unit">' . esc_html__( 'pts', 'vigilante' ) . '</span>'
3042 . '</span>';
3043 }
3044 $html .= '</div>';
3045 if ( $detail ) {
3046 $html .= '<p class="vigilante-analyzer-check-detail">' . esc_html( $detail ) . '</p>';
3047 }
3048 if ( $fix_link && in_array( $state, array( 'fail', 'warn' ), true ) ) {
3049 $html .= '<a href="' . esc_url( $fix_link ) . '" class="vigilante-analyzer-fix-link">'
3050 . esc_html__( 'Go to setting', 'vigilante' )
3051 . '<span class="vigilante-analyzer-fix-arrow" aria-hidden="true">&rarr;</span></a>';
3052 } elseif ( $fix_link && 'info' === $state ) {
3053 // Info rows (e.g. DNSBL lookups) get an external "Learn more" link instead.
3054 $is_external = 0 === strpos( $fix_link, 'http' );
3055 $html .= '<a href="' . esc_url( $fix_link ) . '" class="vigilante-analyzer-fix-link"'
3056 . ( $is_external ? ' target="_blank" rel="noopener noreferrer"' : '' ) . '>'
3057 . esc_html__( 'Learn more', 'vigilante' )
3058 . '<span class="vigilante-analyzer-fix-arrow" aria-hidden="true">&rarr;</span></a>';
3059 }
3060 $html .= '</div>';
3061 $html .= '</li>';
3062 return $html;
3063 }
3064
3065 /**
3066 * Build a minimal SVG sparkline for the score history.
3067 *
3068 * @param int[] $points Score values (0..100), oldest to newest.
3069 * @return string SVG markup.
3070 */
3071 private static function sparkline_svg( $points ) {
3072 $points = array_map( 'intval', (array) $points );
3073 $count = count( $points );
3074 if ( $count < 2 ) {
3075 return '';
3076 }
3077 $width = 280;
3078 $height = 60;
3079 $padding = 4;
3080
3081 $usable_w = $width - ( $padding * 2 );
3082 $usable_h = $height - ( $padding * 2 );
3083
3084 $step = $usable_w / max( 1, $count - 1 );
3085 $max = 100; // Fixed scale — scores are 0..100.
3086
3087 $coords = array();
3088 foreach ( $points as $i => $v ) {
3089 $x = $padding + ( $i * $step );
3090 $y = $padding + ( $usable_h - ( ( $v / $max ) * $usable_h ) );
3091 $coords[] = round( $x, 2 ) . ',' . round( $y, 2 );
3092 }
3093 $path = 'M ' . implode( ' L ', $coords );
3094 $last = end( $points );
3095 $last_x = $padding + ( ( $count - 1 ) * $step );
3096 $last_y = $padding + ( $usable_h - ( ( $last / $max ) * $usable_h ) );
3097
3098 $svg = '<svg viewBox="0 0 ' . $width . ' ' . $height . '" preserveAspectRatio="none" role="img" aria-label="' . esc_attr__( 'Security Score history', 'vigilante' ) . '" focusable="false">';
3099 $svg .= '<path d="' . esc_attr( $path ) . '" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>';
3100 $svg .= '<circle cx="' . esc_attr( round( $last_x, 2 ) ) . '" cy="' . esc_attr( round( $last_y, 2 ) ) . '" r="3" fill="currentColor"/>';
3101 $svg .= '</svg>';
3102 return $svg;
3103 }
3104
3105 /**
3106 * Render dashboard tab
3107 */
3108 /**
3109 * One line strip at the top of the Dashboard tab: the state of Vigilant own
3110 * files, above the Configuration Score and the Security Check, because
3111 * nothing else on this screen means much while it is red.
3112 */
3113 private function render_self_protection_strip() {
3114 $summary = $this->self_integrity_summary();
3115 $tone = $summary['tone'];
3116 $state = $summary['state'];
3117 $count = count( $summary['findings'] );
3118 $link = admin_url( 'admin.php?page=vigilante&tab=file-integrity#vigilante-section-fi-self' );
3119 ?>
3120 <div class="vigilante-self-strip vigilante-self-strip--<?php echo esc_attr( $tone ); ?>">
3121 <span class="dashicons dashicons-shield" aria-hidden="true"></span>
3122 <strong><?php esc_html_e( 'Vigilant self-protection', 'vigilante' ); ?></strong>
3123 <span class="vigilante-self-strip-state"><?php echo esc_html( $this->self_integrity_headline( $tone, $state ) ); ?></span>
3124 <?php if ( $count > 0 ) : ?>
3125 <span class="vigilante-self-strip-count">
3126 <?php
3127 printf(
3128 /* translators: %d: number of findings about Vigilant own files */
3129 esc_html( _n( '%d finding', '%d findings', $count, 'vigilante' ) ),
3130 (int) $count
3131 );
3132 ?>
3133 </span>
3134 <?php elseif ( ! empty( $state['last_check'] ) && 'off' !== $tone ) : ?>
3135 <span class="vigilante-self-strip-count">
3136 <?php
3137 printf(
3138 /* translators: %s: human time difference, like "2 hours" */
3139 esc_html__( 'checked %s ago', 'vigilante' ),
3140 esc_html( human_time_diff( (int) $state['last_check'], time() ) )
3141 );
3142 ?>
3143 </span>
3144 <?php endif; ?>
3145 <a href="<?php echo esc_url( $link ); ?>">
3146 <?php
3147 if ( in_array( $tone, array( 'critical', 'off', 'warning' ), true ) ) {
3148 esc_html_e( 'See what to do', 'vigilante' );
3149 } else {
3150 esc_html_e( 'See details', 'vigilante' );
3151 }
3152 ?>
3153 </a>
3154 </div>
3155 <?php
3156 }
3157
3158 private function render_tab_dashboard() {
3159 $options = $this->settings->get_all_options();
3160 $module_labels = $this->settings->get_module_labels();
3161 $module_descriptions = $this->settings->get_module_descriptions();
3162 $presets = $this->settings->get_presets();
3163 $active_preset = get_option( 'vigilante_active_preset', '' );
3164
3165 // Calculate security score with more factors
3166 $security_score = $this->calculate_security_score( $options );
3167
3168 // Security Analyzer (v2.1.0) — hydrate widget with the last persisted scan, if any.
3169 if ( ! class_exists( 'Vigilante_Security_Analyzer' ) ) {
3170 require_once VIGILANTE_INCLUDES_DIR . 'class-security-analyzer.php';
3171 }
3172 $analyzer_instance = new Vigilante_Security_Analyzer( $this->settings, $this->activity_log );
3173 $analyzer_last_scan = $analyzer_instance->get_last_scan();
3174 $analyzer_history = $analyzer_instance->get_score_history();
3175 $analyzer_categories_def = Vigilante_Security_Analyzer::get_categories();
3176 $analyzer_settings = isset( $options['security_analyzer'] ) ? $options['security_analyzer'] : array();
3177 ?>
3178 <div class="vigilante-dashboard">
3179 <?php $this->render_self_protection_strip(); ?>
3180 <div class="vigilante-status-card">
3181 <h2><?php esc_html_e( 'Configuration Score', 'vigilante' ); ?></h2>
3182 <p class="vigilante-score-kind description">
3183 <?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' ); ?>
3184 </p>
3185 <div class="vigilante-security-score">
3186 <?php
3187 // Grade thresholds: A (90+), B (70-89), C (50-69), D (30-49), E (0-29)
3188 if ( $security_score >= 90 ) {
3189 $grade = 'A';
3190 } elseif ( $security_score >= 70 ) {
3191 $grade = 'B';
3192 } elseif ( $security_score >= 50 ) {
3193 $grade = 'C';
3194 } elseif ( $security_score >= 30 ) {
3195 $grade = 'D';
3196 } else {
3197 $grade = 'E';
3198 }
3199 ?>
3200 <div class="vigilante-score-circle vigilante-grade-<?php echo esc_attr( strtolower( $grade ) ); ?>">
3201 <span class="vigilante-grade"><?php echo esc_html( $grade ); ?></span>
3202 <span class="vigilante-score-text"><?php echo esc_html( $security_score ); ?>%</span>
3203 </div>
3204 <div class="vigilante-config-status">
3205 <?php if ( $active_preset && isset( $presets[ $active_preset ] ) ) : ?>
3206 <span class="vigilante-preset-badge vigilante-preset-<?php echo esc_attr( $active_preset ); ?>">
3207 <?php echo esc_html( $presets[ $active_preset ]['name'] ); ?>
3208 </span>
3209 <?php else : ?>
3210 <span class="vigilante-preset-badge vigilante-preset-custom">
3211 <?php esc_html_e( 'Custom Configuration', 'vigilante' ); ?>
3212 </span>
3213 <?php endif; ?>
3214 </div>
3215 </div>
3216
3217 <?php
3218 $recommendations = $this->get_security_recommendations( $options );
3219 if ( ! empty( $recommendations ) ) :
3220 ?>
3221 <div class="vigilante-recommendations">
3222 <h4><?php esc_html_e( 'Recommendations', 'vigilante' ); ?></h4>
3223 <ul class="vigilante-recommendations-grid">
3224 <?php foreach ( $recommendations as $rec ) : ?>
3225 <li>
3226 <span class="dashicons dashicons-<?php echo esc_attr( $rec['icon'] ); ?> vigilante-priority-<?php echo esc_attr( $rec['priority'] ); ?>"></span>
3227 <?php echo esc_html( $rec['message'] ); ?>
3228 <?php if ( ! empty( $rec['tab'] ) ) : ?>
3229 <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>
3230 <?php endif; ?>
3231 </li>
3232 <?php endforeach; ?>
3233 </ul>
3234 </div>
3235 <?php endif; ?>
3236 </div>
3237
3238 <?php $this->render_analyzer_widget( $analyzer_last_scan, $analyzer_history, $analyzer_categories_def, $analyzer_settings ); ?>
3239
3240 <div class="vigilante-modules-grid">
3241 <h2 id="vigilante-section-dashboard-modules"><?php esc_html_e( 'Security Modules', 'vigilante' ); ?></h2>
3242 <p class="description"><?php esc_html_e( 'Enable or disable security modules. Each module controls a tab with detailed settings.', 'vigilante' ); ?></p>
3243 <div class="vigilante-modules-list">
3244 <?php foreach ( $options['modules'] as $module => $enabled ) :
3245 $label = isset( $module_labels[ $module ] ) ? $module_labels[ $module ] : ucwords( str_replace( '_', ' ', $module ) );
3246 $description = isset( $module_descriptions[ $module ] ) ? $module_descriptions[ $module ] : '';
3247 $vg_module_locked = $this->main_site_files_locked() && in_array( $module, Vigilante_Settings::get_main_site_file_settings()['modules'], true );
3248 ?>
3249 <div class="vigilante-module-item <?php echo $enabled ? 'enabled' : 'disabled'; ?>">
3250 <div class="vigilante-module-header">
3251 <span class="vigilante-module-status"></span>
3252 <span class="vigilante-module-name"><?php echo esc_html( $label ); ?></span>
3253 <label class="vigilante-toggle">
3254 <?php
3255 /* translators: %s: Security module name, for example Firewall. */
3256 $toggle_label = sprintf( __( 'Enable %s', 'vigilante' ), $label );
3257 ?>
3258 <input type="checkbox"
3259 name="modules[<?php echo esc_attr( $module ); ?>]"
3260 value="1"
3261 <?php checked( $enabled ); ?>
3262 <?php disabled( $vg_module_locked ); ?>
3263 aria-label="<?php echo esc_attr( $toggle_label ); ?>"
3264 data-module="<?php echo esc_attr( $module ); ?>">
3265 <span class="vigilante-toggle-slider"></span>
3266 </label>
3267 </div>
3268 <?php if ( $description ) : ?>
3269 <p class="vigilante-module-desc"><?php echo esc_html( $description ); ?></p>
3270 <?php endif; ?>
3271 <?php if ( $vg_module_locked ) : ?>
3272 <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>
3273 <?php endif; ?>
3274 </div>
3275 <?php endforeach; ?>
3276 </div>
3277 </div>
3278
3279 <div class="vigilante-presets-card">
3280 <h2><?php esc_html_e( 'Quick Configuration Presets', 'vigilante' ); ?></h2>
3281 <p><?php esc_html_e( 'Apply a preset to quickly set up recommended settings for standard or maximum security level.', 'vigilante' ); ?></p>
3282 <div class="vigilante-presets-grid">
3283 <?php foreach ( $presets as $preset_id => $preset ) :
3284 $is_active = ( $active_preset === $preset_id );
3285 ?>
3286 <div class="vigilante-preset-card <?php echo $is_active ? 'vigilante-preset-active' : ''; ?>">
3287 <?php if ( $is_active ) : ?>
3288 <span class="vigilante-active-indicator"><?php esc_html_e( 'Active', 'vigilante' ); ?></span>
3289 <?php endif; ?>
3290 <h3><?php echo esc_html( $preset['name'] ); ?></h3>
3291 <p><?php echo esc_html( $preset['description'] ); ?></p>
3292 <button type="button" class="button vigilante-preset-btn <?php echo $is_active ? 'button-primary' : ''; ?>" data-preset="<?php echo esc_attr( $preset_id ); ?>">
3293 <?php esc_html_e( 'Apply Preset', 'vigilante' ); ?>
3294 </button>
3295 </div>
3296 <?php endforeach; ?>
3297
3298 <?php
3299 // Under Attack mode card
3300 $under_attack = new Vigilante_Under_Attack( $this->settings, $this->activity_log );
3301 $ua_active = $under_attack->is_active();
3302 $ua_remaining = $under_attack->get_remaining_time();
3303 $ua_remaining_hours = floor( $ua_remaining / 3600 );
3304 $ua_remaining_mins = floor( ( $ua_remaining % 3600 ) / 60 );
3305 ?>
3306 <div class="vigilante-preset-card vigilante-under-attack-card <?php echo $ua_active ? 'vigilante-under-attack-active' : ''; ?>">
3307 <h3 id="vigilante-section-dashboard-under-attack">
3308 <span class="dashicons dashicons-shield"></span>
3309 <?php esc_html_e( 'Under Attack', 'vigilante' ); ?>
3310 </h3>
3311 <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>
3312 <?php if ( $ua_active ) : ?>
3313 <div class="vigilante-ua-countdown" data-expires="<?php echo esc_attr( $under_attack->get_status()['activated_at'] + $under_attack->get_status()['duration'] ); ?>">
3314 <span class="dashicons dashicons-clock"></span>
3315 <span class="vigilante-ua-time">
3316 <?php
3317 printf(
3318 /* translators: 1: Hours, 2: Minutes */
3319 esc_html__( '%1$dh %2$dm remaining', 'vigilante' ),
3320 absint( $ua_remaining_hours ),
3321 absint( $ua_remaining_mins )
3322 );
3323 ?>
3324 </span>
3325 </div>
3326 <button type="button" class="button vigilante-ua-btn vigilante-ua-deactivate">
3327 <?php esc_html_e( 'Deactivate', 'vigilante' ); ?>
3328 </button>
3329 <?php else : ?>
3330 <button type="button" class="button vigilante-ua-btn vigilante-ua-activate">
3331 <?php esc_html_e( 'Activate for 4 hours', 'vigilante' ); ?>
3332 </button>
3333 <?php endif; ?>
3334 </div>
3335 </div>
3336 </div>
3337 </div>
3338 <?php
3339 }
3340
3341 /**
3342 * Render tools tab
3343 */
3344 private function render_tab_tools() {
3345 // Get current settings for notification summary
3346 $email_options = $this->settings->get_section( 'email' );
3347 $login_options = $this->settings->get_section( 'login_security' );
3348 $user_options = $this->settings->get_section( 'user_security' );
3349 $fi_options = $this->settings->get_section( 'file_integrity' );
3350 $alerts_options = $this->settings->get_section( 'audit_alerts' );
3351 $monitoring = $user_options['admin_monitoring'] ?? array();
3352 $registration = $user_options['registration_approval'] ?? array();
3353 $current_admin = get_option( 'admin_email' );
3354 $send_to_admin = ! isset( $email_options['send_to_admin_email'] ) || ! empty( $email_options['send_to_admin_email'] );
3355 $additional_raw = $email_options['additional_recipients'] ?? array();
3356 $additional = is_array( $additional_raw ) ? implode( "\n", $additional_raw ) : trim( $additional_raw );
3357 ?>
3358
3359 <!-- Notification Settings -->
3360 <div id="vigilante-section-tools-notifications" class="vigilante-settings-section vigilante-notification-section">
3361 <h2><?php esc_html_e( 'Notification settings', 'vigilante' ); ?></h2>
3362 <p><?php esc_html_e( 'Configure who receives all administrative email notifications from Vigilant. Individual notifications are enabled in their respective tabs.', 'vigilante' ); ?></p>
3363
3364 <div class="vigilante-notification-layout">
3365
3366 <!-- Left column: Recipients settings -->
3367 <div class="vigilante-notification-settings">
3368 <form class="vigilante-settings-form" data-section="email">
3369
3370 <table class="form-table vigilante-compact-form">
3371 <tr>
3372 <th scope="row"><?php esc_html_e( 'WordPress Admin Email', 'vigilante' ); ?></th>
3373 <td>
3374 <label>
3375 <input type="checkbox" name="email[send_to_admin_email]" value="1" <?php checked( $send_to_admin ); ?>>
3376 <?php
3377 printf(
3378 /* translators: %s: Admin email address */
3379 esc_html__( 'Send to admin email (%s)', 'vigilante' ),
3380 '<code>' . esc_html( $current_admin ) . '</code>'
3381 );
3382 ?>
3383 </label>
3384 </td>
3385 </tr>
3386 <tr>
3387 <th scope="row"><label for="vigilante-f-email-additional-recipients"><?php esc_html_e( 'Additional Recipients', 'vigilante' ); ?></label></th>
3388 <td>
3389 <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>
3390 <p class="description"><?php esc_html_e( 'One email per line.', 'vigilante' ); ?></p>
3391 </td>
3392 </tr>
3393 <tr>
3394 <th scope="row"><?php esc_html_e( 'Plugin Deactivation', 'vigilante' ); ?></th>
3395 <td>
3396 <label>
3397 <input type="checkbox" name="email[send_deactivation_email]" value="1" <?php checked( ! empty( $email_options['send_deactivation_email'] ) ); ?>>
3398 <?php esc_html_e( 'Send email when Vigilant is deactivated', 'vigilante' ); ?>
3399 </label>
3400 </td>
3401 </tr>
3402 </table>
3403
3404 <p class="submit vigilante-notification-submit">
3405 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
3406 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
3407 </button>
3408 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
3409 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
3410 </button>
3411 <span class="vigilante-test-email-result" style="margin-left:8px;vertical-align:middle;"></span>
3412 </p>
3413 <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>
3414
3415 </form>
3416 </div>
3417
3418 <!-- Right column: Active notifications summary -->
3419 <div class="vigilante-notification-summary">
3420 <h4><?php esc_html_e( 'Active notifications', 'vigilante' ); ?></h4>
3421
3422 <table class="widefat striped">
3423 <thead>
3424 <tr>
3425 <th><?php esc_html_e( 'Notification', 'vigilante' ); ?></th>
3426 <th style="width: 1%; white-space: nowrap; text-align: center;"><?php esc_html_e( 'Status', 'vigilante' ); ?></th>
3427 <th style="width: 50px; text-align: center;"></th>
3428 </tr>
3429 </thead>
3430 <tbody>
3431 <?php
3432 $notifications = array(
3433 array(
3434 'label' => __( 'Login lockout', 'vigilante' ),
3435 'active' => ! empty( $login_options['notify_on_lockout'] ),
3436 'tab' => 'login',
3437 ),
3438 array(
3439 'label' => __( 'Administrator login', 'vigilante' ),
3440 'active' => ! empty( $login_options['notify_on_admin_login'] ),
3441 'tab' => 'login',
3442 ),
3443 array(
3444 'label' => __( 'New administrator created', 'vigilante' ),
3445 'active' => ! empty( $monitoring['alert_new_admin'] ),
3446 'tab' => 'users',
3447 ),
3448 array(
3449 'label' => __( 'Administrator email changed', 'vigilante' ),
3450 'active' => ! empty( $monitoring['alert_admin_email_change'] ),
3451 'tab' => 'users',
3452 ),
3453 array(
3454 'label' => __( 'Permission elevation', 'vigilante' ),
3455 'active' => ! empty( $monitoring['alert_permission_elevation'] ),
3456 'tab' => 'users',
3457 ),
3458 array(
3459 'label' => __( 'Admin password changed', 'vigilante' ),
3460 'active' => ! empty( $monitoring['alert_admin_password_change'] ),
3461 'tab' => 'users',
3462 ),
3463 array(
3464 'label' => __( 'Registration pending approval', 'vigilante' ),
3465 'active' => ! empty( $registration['enabled'] ) && ! empty( $registration['notify_admin'] ),
3466 'tab' => 'users',
3467 ),
3468 array(
3469 'label' => __( 'File integrity scan report', 'vigilante' ),
3470 'active' => ( $fi_options['notify_level'] ?? 'disabled' ) !== 'disabled',
3471 'tab' => 'file-integrity',
3472 ),
3473 array(
3474 'label' => __( 'File integrity instant alert', 'vigilante' ),
3475 'active' => ! empty( $fi_options['instant_alert'] ),
3476 'tab' => 'file-integrity',
3477 ),
3478 array(
3479 'label' => __( 'Audit alert: immediate', 'vigilante' ),
3480 'active' => Vigilante_Audit_Alerts::immediate_is_active( $alerts_options ),
3481 'tab' => 'activity-log',
3482 'anchor' => 'vigilante-section-audit-alerts',
3483 ),
3484 array(
3485 'label' => __( 'Audit alert: threshold', 'vigilante' ),
3486 'active' => Vigilante_Audit_Alerts::threshold_is_active( $alerts_options ),
3487 'tab' => 'activity-log',
3488 'anchor' => 'vigilante-section-audit-alerts',
3489 ),
3490 array(
3491 'label' => __( 'Under Attack mode', 'vigilante' ),
3492 'active' => true,
3493 'tab' => '',
3494 'note' => __( 'Always active', 'vigilante' ),
3495 ),
3496 array(
3497 'label' => __( 'Plugin deactivation', 'vigilante' ),
3498 'active' => ! empty( $email_options['send_deactivation_email'] ),
3499 'tab' => 'tools',
3500 ),
3501 );
3502
3503 foreach ( $notifications as $notif ) :
3504 $status_class = $notif['active'] ? 'vigilante-status-active' : 'vigilante-status-inactive';
3505 $status_label = $notif['active'] ? __( 'Active', 'vigilante' ) : __( 'Inactive', 'vigilante' );
3506 if ( ! empty( $notif['note'] ) ) {
3507 $status_label = $notif['note'];
3508 }
3509 ?>
3510 <tr>
3511 <td><?php echo esc_html( $notif['label'] ); ?></td>
3512 <td style="text-align: center; white-space: nowrap;">
3513 <span class="<?php echo esc_attr( $status_class ); ?>"><?php echo esc_html( $status_label ); ?></span>
3514 </td>
3515 <td style="text-align: center;">
3516 <?php if ( ! empty( $notif['tab'] ) ) : ?>
3517 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=' . $notif['tab'] ) . ( ! empty( $notif['anchor'] ) ? '#' . $notif['anchor'] : '' ) ); ?>" class="button button-small">
3518 <span class="dashicons dashicons-admin-generic" style="font-size: 14px; line-height: 1.8;"></span>
3519 </a>
3520 <?php else : ?>
3521 &mdash;
3522 <?php endif; ?>
3523 </td>
3524 </tr>
3525 <?php endforeach; ?>
3526 </tbody>
3527 </table>
3528 </div>
3529
3530 </div>
3531 </div>
3532
3533 <h2 id="vigilante-section-tools-main" class="vigilante-tools-heading"><?php esc_html_e( 'Tools', 'vigilante' ); ?></h2>
3534
3535 <?php
3536 // Warn that during Under Attack mode the export/import operate against
3537 // the temporary hardened config and any imported changes will be
3538 // reverted when the mode ends.
3539 $ua_status = get_option( Vigilante_Under_Attack::OPTION_NAME, array() );
3540 if ( ! empty( $ua_status['active'] ) ) :
3541 ?>
3542 <div class="vigilante-ua-tools-notice-wrap">
3543 <div class="notice notice-warning inline vigilante-ua-tools-notice">
3544 <p>
3545 <strong><?php esc_html_e( 'Under Attack mode is active.', 'vigilante' ); ?></strong>
3546 <?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' ); ?>
3547 </p>
3548 </div>
3549 </div>
3550 <?php
3551 endif;
3552 ?>
3553
3554 <div class="vigilante-tools-grid">
3555 <div class="vigilante-tool-card">
3556 <h3><?php esc_html_e( 'Export Settings', 'vigilante' ); ?></h3>
3557 <p><?php esc_html_e( 'Download your current security settings as a JSON file.', 'vigilante' ); ?></p>
3558 <button type="button" class="button vigilante-export-settings">
3559 <?php esc_html_e( 'Export Settings', 'vigilante' ); ?>
3560 </button>
3561 </div>
3562
3563 <div class="vigilante-tool-card">
3564 <h3><?php esc_html_e( 'Import Settings', 'vigilante' ); ?></h3>
3565 <p><?php esc_html_e( 'Import settings from a previously exported JSON file.', 'vigilante' ); ?></p>
3566 <input type="file" id="vigilante-import-file" aria-label="<?php esc_attr_e( 'Configuration file to import', 'vigilante' ); ?>" accept=".json" style="display: none;">
3567 <button type="button" class="button vigilante-import-settings">
3568 <?php esc_html_e( 'Import Settings', 'vigilante' ); ?>
3569 </button>
3570 </div>
3571
3572 <div class="vigilante-tool-card">
3573 <h3><?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?></h3>
3574 <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>
3575 <button type="button" class="button vigilante-reset-settings" style="color: #a00;">
3576 <?php esc_html_e( 'Reset All Settings', 'vigilante' ); ?>
3577 </button>
3578 </div>
3579
3580 <div class="vigilante-tool-card">
3581 <h3><?php esc_html_e( 'Download Config Backup', 'vigilante' ); ?></h3>
3582 <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>
3583 <?php if ( $this->shared_files_locked() ) : ?>
3584 <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>
3585 <?php else : ?>
3586 <button type="button" class="button vigilante-create-backup">
3587 <?php esc_html_e( 'Download Backup', 'vigilante' ); ?>
3588 </button>
3589 <?php endif; ?>
3590 </div>
3591
3592 <?php if ( ! $this->shared_files_locked() ) : ?>
3593
3594 <div class="vigilante-tool-card vigilante-tool-card-wide">
3595 <h3><?php esc_html_e( 'Database Backup', 'vigilante' ); ?></h3>
3596 <p><?php esc_html_e( 'Download a backup of your database as a ZIP file. Select which tables to include.', 'vigilante' ); ?></p>
3597 <button type="button" class="button vigilante-db-backup-toggle">
3598 <?php esc_html_e( 'Download Database Backup', 'vigilante' ); ?>
3599 </button>
3600
3601 <div class="vigilante-db-backup-panel" style="display: none;">
3602 <div class="vigilante-db-tables-loading">
3603 <span class="spinner is-active"></span>
3604 <?php esc_html_e( 'Loading tables...', 'vigilante' ); ?>
3605 </div>
3606
3607 <div class="vigilante-db-tables-content" style="display: none;">
3608 <div class="vigilante-db-tables-controls">
3609 <label>
3610 <input type="checkbox" id="vigilante-db-select-all" checked>
3611 <strong><?php esc_html_e( 'Select / deselect all', 'vigilante' ); ?></strong>
3612 </label>
3613 <span class="vigilante-db-tables-info"></span>
3614 </div>
3615
3616 <div class="vigilante-db-tables-group">
3617 <h4><?php esc_html_e( 'WordPress core tables', 'vigilante' ); ?></h4>
3618 <div class="vigilante-db-tables-list" id="vigilante-db-core-tables"></div>
3619 </div>
3620
3621 <div class="vigilante-db-tables-group" id="vigilante-db-other-group" style="display: none;">
3622 <h4><?php esc_html_e( 'Plugin and custom tables', 'vigilante' ); ?></h4>
3623 <div class="vigilante-db-tables-list" id="vigilante-db-other-tables"></div>
3624 </div>
3625
3626 <div class="vigilante-db-backup-actions">
3627 <button type="button" class="button button-primary vigilante-db-backup-download">
3628 <?php esc_html_e( 'Download Backup (.zip)', 'vigilante' ); ?>
3629 </button>
3630 </div>
3631 </div>
3632 </div>
3633 </div>
3634 <?php else : ?>
3635 <div class="vigilante-tool-card vigilante-tool-card-wide">
3636 <h3><?php esc_html_e( 'Database Backup', 'vigilante' ); ?></h3>
3637 <p><?php esc_html_e( 'Download a backup of your database as a ZIP file. Select which tables to include.', 'vigilante' ); ?></p>
3638 <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>
3639 </div>
3640 <?php endif; ?>
3641 </div>
3642 <?php
3643 }
3644
3645 /**
3646 * Render firewall tab
3647 */
3648 private function render_tab_firewall() {
3649 $is_disabled = $this->render_module_disabled_notice( 'firewall' );
3650 $options = $this->settings->get_section( 'firewall' );
3651 ?>
3652 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="firewall" <?php echo $is_disabled ? 'inert' : ''; ?>>
3653 <div id="vigilante-section-firewall-main" class="vigilante-settings-section">
3654 <h2>
3655 <?php esc_html_e( 'Firewall Protection', 'vigilante' ); ?>
3656 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
3657 </h2>
3658 <p><?php esc_html_e( 'PHP-based request filtering. Analyzes each request before WordPress loads.', 'vigilante' ); ?></p>
3659 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
3660 <p style="margin:0;">
3661 <?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' ); ?>
3662 </p>
3663 </div>
3664
3665 <?php $vg_main_locked = $this->main_site_files_locked(); ?>
3666 <?php if ( $vg_main_locked ) : ?>
3667 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
3668 <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>
3669 </div>
3670 <?php endif; ?>
3671
3672 <table class="form-table">
3673 <tr>
3674 <th scope="row"><?php esc_html_e( 'Block Bad Query Strings', 'vigilante' ); ?></th>
3675 <td>
3676 <label>
3677 <input type="checkbox" name="firewall[block_bad_query_strings]" value="1" <?php disabled( $vg_main_locked ); ?> <?php checked( ! empty( $options['block_bad_query_strings'] ) ); ?>>
3678 <?php esc_html_e( 'Block malicious query string patterns', 'vigilante' ); ?>
3679 </label>
3680 </td>
3681 </tr>
3682 <tr>
3683 <th scope="row"><?php esc_html_e( 'SQL Injection Protection', 'vigilante' ); ?></th>
3684 <td>
3685 <label>
3686 <input type="checkbox" name="firewall[block_sql_injection]" value="1" <?php checked( ! empty( $options['block_sql_injection'] ) ); ?>>
3687 <?php esc_html_e( 'Block SQL injection attempts', 'vigilante' ); ?>
3688 </label>
3689 </td>
3690 </tr>
3691 <tr>
3692 <th scope="row"><?php esc_html_e( 'XSS Protection', 'vigilante' ); ?></th>
3693 <td>
3694 <label>
3695 <input type="checkbox" name="firewall[block_xss_attacks]" value="1" <?php checked( ! empty( $options['block_xss_attacks'] ) ); ?>>
3696 <?php esc_html_e( 'Block cross-site scripting attacks', 'vigilante' ); ?>
3697 </label>
3698 </td>
3699 </tr>
3700 <tr>
3701 <th scope="row"><?php esc_html_e( 'File Inclusion Protection', 'vigilante' ); ?></th>
3702 <td>
3703 <label>
3704 <input type="checkbox" name="firewall[block_file_inclusion]" value="1" <?php checked( ! empty( $options['block_file_inclusion'] ) ); ?>>
3705 <?php esc_html_e( 'Block local/remote file inclusion attempts', 'vigilante' ); ?>
3706 </label>
3707 </td>
3708 </tr>
3709 <tr>
3710 <th scope="row"><?php esc_html_e( 'Directory Traversal Protection', 'vigilante' ); ?></th>
3711 <td>
3712 <label>
3713 <input type="checkbox" name="firewall[block_directory_traversal]" value="1" <?php checked( ! empty( $options['block_directory_traversal'] ) ); ?>>
3714 <?php esc_html_e( 'Block path traversal attempts', 'vigilante' ); ?>
3715 </label>
3716 </td>
3717 </tr>
3718 <tr>
3719 <th scope="row"><?php esc_html_e( 'Block Bad Bots', 'vigilante' ); ?></th>
3720 <td>
3721 <label>
3722 <input type="checkbox" name="firewall[block_bad_bots]" value="1" <?php disabled( $vg_main_locked ); ?> <?php checked( ! empty( $options['block_bad_bots'] ) ); ?>>
3723 <?php esc_html_e( 'Block known malicious bots and scanners', 'vigilante' ); ?>
3724 </label>
3725 </td>
3726 </tr>
3727 </table>
3728
3729 <h3><?php esc_html_e( 'Rate Limiting', 'vigilante' ); ?></h3>
3730 <table class="form-table">
3731 <tr>
3732 <th scope="row"><?php esc_html_e( 'Enable Rate Limiting', 'vigilante' ); ?></th>
3733 <td>
3734 <label>
3735 <input type="checkbox" name="firewall[rate_limiting][enabled]" value="1" <?php checked( ! empty( $options['rate_limiting']['enabled'] ) ); ?>>
3736 <?php esc_html_e( 'Limit requests per IP address', 'vigilante' ); ?>
3737 </label>
3738 </td>
3739 </tr>
3740 <tr>
3741 <th scope="row"><label for="vigilante-f-firewall-rate-limiting-requests-per-minute"><?php esc_html_e( 'Requests per Minute', 'vigilante' ); ?></label></th>
3742 <td>
3743 <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">
3744 <p class="description">
3745 <?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' ); ?>
3746 </p>
3747 </td>
3748 </tr>
3749 <tr>
3750 <th scope="row"><label for="vigilante-f-firewall-rate-limiting-block-duration"><?php esc_html_e( 'Block Duration (seconds)', 'vigilante' ); ?></label></th>
3751 <td>
3752 <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">
3753 </td>
3754 </tr>
3755 <tr>
3756 <th scope="row"><?php esc_html_e( 'Progressive Blocking', 'vigilante' ); ?></th>
3757 <td>
3758 <label>
3759 <input type="checkbox" name="firewall[rate_limiting][progressive]" value="1" <?php checked( ! empty( $options['rate_limiting']['progressive'] ) ); ?>>
3760 <?php esc_html_e( 'Double block duration on each repeat offense', 'vigilante' ); ?>
3761 </label>
3762 <p class="description">
3763 <?php
3764 $base = absint( $options['rate_limiting']['block_duration'] ?? 300 );
3765 printf(
3766 /* translators: 1: First block duration, 2: Second, 3: Third */
3767 esc_html__( 'Example: %1$s → %2$s → %3$s and so on, up to the maximum.', 'vigilante' ),
3768 esc_html( human_time_diff( 0, $base ) ),
3769 esc_html( human_time_diff( 0, $base * 2 ) ),
3770 esc_html( human_time_diff( 0, $base * 4 ) )
3771 );
3772 ?>
3773 </p>
3774 </td>
3775 </tr>
3776 <tr>
3777 <th scope="row"><label for="vigilante-f-firewall-rate-limiting-max-block-duration"><?php esc_html_e( 'Maximum Block Duration', 'vigilante' ); ?></label></th>
3778 <td>
3779 <select id="vigilante-f-firewall-rate-limiting-max-block-duration" name="firewall[rate_limiting][max_block_duration]">
3780 <?php
3781 $max_options = array(
3782 3600 => __( '1 hour', 'vigilante' ),
3783 21600 => __( '6 hours', 'vigilante' ),
3784 43200 => __( '12 hours', 'vigilante' ),
3785 86400 => __( '24 hours', 'vigilante' ),
3786 604800 => __( '7 days', 'vigilante' ),
3787 );
3788 $current_max = absint( $options['rate_limiting']['max_block_duration'] ?? 86400 );
3789 foreach ( $max_options as $val => $label ) :
3790 ?>
3791 <option value="<?php echo esc_attr( $val ); ?>" <?php selected( $current_max, $val ); ?>>
3792 <?php echo esc_html( $label ); ?>
3793 </option>
3794 <?php endforeach; ?>
3795 </select>
3796 <p class="description"><?php esc_html_e( 'Upper limit for progressive blocking.', 'vigilante' ); ?></p>
3797 </td>
3798 </tr>
3799 </table>
3800
3801 <?php
3802 // Currently blocked IPs from rate limiting
3803 $active_blocks = Vigilante_Firewall::get_active_blocks();
3804 if ( ! empty( $active_blocks ) ) :
3805 ?>
3806 <div class="vigilante-settings-section vigilante-lockout-section" style="margin-top:20px;">
3807 <h3><?php esc_html_e( 'Currently Blocked IPs', 'vigilante' ); ?></h3>
3808 <table class="wp-list-table widefat fixed striped" style="max-width:800px;">
3809 <thead>
3810 <tr>
3811 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
3812 <th><?php esc_html_e( 'Blocked', 'vigilante' ); ?></th>
3813 <th><?php esc_html_e( 'Expires in', 'vigilante' ); ?></th>
3814 <th><?php esc_html_e( 'Strikes', 'vigilante' ); ?></th>
3815 <th><?php esc_html_e( 'Action', 'vigilante' ); ?></th>
3816 </tr>
3817 </thead>
3818 <tbody>
3819 <?php foreach ( $active_blocks as $blocked_ip => $block_data ) : ?>
3820 <tr>
3821 <td><code><?php echo esc_html( $blocked_ip ); ?></code></td>
3822 <td><?php echo esc_html( human_time_diff( $block_data['blocked_at'] ) . ' ' . __( 'ago', 'vigilante' ) ); ?></td>
3823 <td><?php echo esc_html( human_time_diff( time(), $block_data['expires'] ) ); ?></td>
3824 <td><?php echo esc_html( $block_data['strikes'] ?? 1 ); ?></td>
3825 <td>
3826 <button type="button" class="button button-small vigilante-unblock-firewall-ip"
3827 data-ip="<?php echo esc_attr( $blocked_ip ); ?>">
3828 <?php esc_html_e( 'Unblock', 'vigilante' ); ?>
3829 </button>
3830 </td>
3831 </tr>
3832 <?php endforeach; ?>
3833 </tbody>
3834 </table>
3835 </div>
3836 <?php endif; ?>
3837
3838 <?php
3839 // Since 2.11.8 X-Forwarded-For is read from its end, where the proxy
3840 // writes. The administrator's own request shows whether that end is
3841 // a CDN or a balancer for everybody here. Cross review of 2.11.8.
3842 $xff_readings = $this->forwarded_chain_readings();
3843 if ( $xff_readings ) :
3844 ?>
3845 <div id="vigilante-xff-chain-notice" class="notice notice-warning inline" style="margin:10px 0 16px;padding:8px 12px;">
3846 <p style="margin:0;">
3847 <?php
3848 printf(
3849 /* translators: 1: last address in the header, the one Vigilant reads, 2: first address in the header, which a visitor can write */
3850 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' ),
3851 esc_html( $xff_readings['now'] ),
3852 esc_html( $xff_readings['before'] )
3853 );
3854 ?>
3855 </p>
3856 </div>
3857 <?php endif; ?>
3858
3859 <h3><?php esc_html_e( 'IP Lists', 'vigilante' ); ?></h3>
3860 <p class="description">
3861 <?php
3862 printf(
3863 /* translators: %s: Current visitor IP address */
3864 esc_html__( 'Your current IP address: %s', 'vigilante' ),
3865 '<code>' . esc_html( $this->database->get_client_ip() ) . '</code>'
3866 );
3867 ?>
3868 </p>
3869 <table class="form-table">
3870 <tr>
3871 <th scope="row"><label for="vigilante-f-firewall-trusted-proxy-header"><?php esc_html_e( 'Visitor IP detection', 'vigilante' ); ?></label></th>
3872 <td>
3873 <?php $proxy_header = $options['trusted_proxy_header'] ?? ''; ?>
3874 <select id="vigilante-f-firewall-trusted-proxy-header" name="firewall[trusted_proxy_header]" <?php disabled( $vg_main_locked ); ?>>
3875 <option value="" <?php selected( $proxy_header, '' ); ?>><?php esc_html_e( 'Direct connection, only REMOTE_ADDR (recommended)', 'vigilante' ); ?></option>
3876 <option value="cf-connecting-ip" <?php selected( $proxy_header, 'cf-connecting-ip' ); ?>><?php esc_html_e( 'Behind Cloudflare (CF-Connecting-IP)', 'vigilante' ); ?></option>
3877 <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>
3878 <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>
3879 </select>
3880 <p class="description">
3881 <?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' ); ?>
3882 </p>
3883 </td>
3884 </tr>
3885 <tr>
3886 <th scope="row"><label for="vigilante-f-firewall-trusted-proxies"><?php esc_html_e( 'Trusted proxy IPs', 'vigilante' ); ?></label></th>
3887 <td>
3888 <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>
3889 <p class="description">
3890 <?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' ); ?>
3891 <?php if ( in_array( $proxy_header, array( 'x-forwarded-for', 'x-real-ip' ), true ) && empty( $options['trusted_proxies'] ) ) : ?>
3892 <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>
3893 <?php endif; ?>
3894 </p>
3895 </td>
3896 </tr>
3897 <tr>
3898 <th scope="row"><label for="vigilante-f-firewall-ip-whitelist"><?php esc_html_e( 'IP Whitelist', 'vigilante' ); ?></label></th>
3899 <td>
3900 <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>
3901 <p class="description">
3902 <?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' ); ?>
3903 <br>
3904 <?php
3905 printf(
3906 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the IP, CIDR and wildcard examples. */
3907 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' ),
3908 '<code>',
3909 '</code>'
3910 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
3911 ?>
3912 </p>
3913 </td>
3914 </tr>
3915 <tr>
3916 <th scope="row"><label for="vigilante-f-firewall-ip-blacklist"><?php esc_html_e( 'IP Blacklist', 'vigilante' ); ?></label></th>
3917 <td>
3918 <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>
3919 <p class="description">
3920 <?php esc_html_e( 'One IP per line. These IPs will be blocked immediately.', 'vigilante' ); ?>
3921 <br>
3922 <?php
3923 printf(
3924 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the IP, CIDR and wildcard examples. */
3925 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' ),
3926 '<code>',
3927 '</code>'
3928 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
3929 ?>
3930 </p>
3931 </td>
3932 </tr>
3933 </table>
3934
3935 <h3><?php esc_html_e( 'User-Agent Lists', 'vigilante' ); ?></h3>
3936 <p><?php esc_html_e( 'Partial matching: enter a keyword and any User-Agent containing it will be matched.', 'vigilante' ); ?></p>
3937 <table class="form-table">
3938 <tr>
3939 <th scope="row"><label for="vigilante-f-firewall-ua-whitelist"><?php esc_html_e( 'User-Agent Whitelist', 'vigilante' ); ?></label></th>
3940 <td>
3941 <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>
3942 <p class="description"><?php esc_html_e( 'One User-Agent per line. These will bypass all firewall checks. Example: ManageWP, MainWP, UptimeRobot.', 'vigilante' ); ?></p>
3943 </td>
3944 </tr>
3945 <tr>
3946 <th scope="row"><label for="vigilante-f-firewall-ua-blacklist"><?php esc_html_e( 'User-Agent Blacklist', 'vigilante' ); ?></label></th>
3947 <td>
3948 <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>
3949 <p class="description"><?php esc_html_e( 'One User-Agent per line. These will be blocked immediately.', 'vigilante' ); ?></p>
3950 </td>
3951 </tr>
3952 </table>
3953 </div>
3954
3955 <?php
3956 $vg_shared_locked = $this->shared_files_locked();
3957 // Paint what is actually in force, not this site's unused copy.
3958 $vg_local_options = $options;
3959 $options = $this->get_section_for_display( 'firewall' );
3960 ?>
3961 <?php $this->render_shared_files_notice(); ?>
3962 <div id="vigilante-section-firewall-server" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
3963 <h2>
3964 <?php esc_html_e( 'Server Protection', 'vigilante' ); ?>
3965 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
3966 </h2>
3967 <p><?php esc_html_e( 'Server-level rules for Apache/LiteSpeed. These rules are processed before PHP.', 'vigilante' ); ?></p>
3968
3969 <table class="form-table">
3970 <tr id="field-disable-directory-browsing">
3971 <th scope="row"><?php esc_html_e( 'Directory Browsing', 'vigilante' ); ?></th>
3972 <td>
3973 <label>
3974 <input type="checkbox" name="firewall[disable_directory_browsing]" value="1" <?php checked( ! empty( $options['disable_directory_browsing'] ) ); ?>>
3975 <?php esc_html_e( 'Disable directory listing (Options -Indexes)', 'vigilante' ); ?>
3976 </label>
3977 </td>
3978 </tr>
3979 <tr>
3980 <th scope="row"><?php esc_html_e( 'Protect wp-config.php', 'vigilante' ); ?></th>
3981 <td>
3982 <label>
3983 <input type="checkbox" name="firewall[protect_wp_config]" value="1" <?php checked( ! empty( $options['protect_wp_config'] ) ); ?>>
3984 <?php esc_html_e( 'Block direct HTTP access to wp-config.php', 'vigilante' ); ?>
3985 </label>
3986 </td>
3987 </tr>
3988 <tr id="field-protect-wp-cron">
3989 <th scope="row"><?php esc_html_e( 'Protect wp-cron.php', 'vigilante' ); ?></th>
3990 <td>
3991 <label>
3992 <input type="checkbox" name="firewall[protect_wp_cron]" value="1" <?php checked( ! empty( $options['protect_wp_cron'] ) ); ?>>
3993 <?php esc_html_e( 'Block direct HTTP access to wp-cron.php (prevents cron-spam DoS abuse)', 'vigilante' ); ?>
3994 </label>
3995 <p class="description"><?php
3996 printf(
3997 /* translators: 1: opening <strong>, 2: closing </strong> */
3998 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' ),
3999 '<strong>',
4000 '</strong>',
4001 '<code>',
4002 '</code>'
4003 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
4004 ?></p>
4005 </td>
4006 </tr>
4007 <tr>
4008 <th scope="row"><?php esc_html_e( 'Protect wp-includes', 'vigilante' ); ?></th>
4009 <td>
4010 <label>
4011 <input type="checkbox" name="firewall[protect_wp_includes]" value="1" <?php checked( ! empty( $options['protect_wp_includes'] ) ); ?>>
4012 <?php esc_html_e( 'Block direct access to PHP files in wp-includes', 'vigilante' ); ?>
4013 </label>
4014 </td>
4015 </tr>
4016 <tr>
4017 <th scope="row"><?php esc_html_e( 'PHP in Uploads', 'vigilante' ); ?></th>
4018 <td>
4019 <label>
4020 <input type="checkbox" name="firewall[protect_uploads_php]" value="1" <?php checked( ! empty( $options['protect_uploads_php'] ) ); ?>>
4021 <?php esc_html_e( 'Block PHP execution in wp-content/uploads', 'vigilante' ); ?>
4022 </label>
4023 </td>
4024 </tr>
4025 <tr>
4026 <th scope="row"><?php esc_html_e( 'Sensitive Files', 'vigilante' ); ?></th>
4027 <td>
4028 <label>
4029 <input type="checkbox" name="firewall[protect_sensitive_files]" value="1" <?php checked( ! empty( $options['protect_sensitive_files'] ) ); ?>>
4030 <?php esc_html_e( 'Block access to .sql, .bak, .log, .ini, readme.html, license.txt, licencia.txt', 'vigilante' ); ?>
4031 </label>
4032 </td>
4033 </tr>
4034 <tr>
4035 <th scope="row"><?php esc_html_e( 'Limit HTTP Methods', 'vigilante' ); ?></th>
4036 <td>
4037 <label>
4038 <input type="checkbox" name="firewall[limit_http_methods]" value="1" <?php checked( ! empty( $options['limit_http_methods'] ) ); ?>>
4039 <?php esc_html_e( 'Allow only GET, POST, HEAD (blocks PUT, DELETE, TRACE, etc.)', 'vigilante' ); ?>
4040 </label>
4041 </td>
4042 </tr>
4043 </table>
4044 </div>
4045 <?php $options = $vg_local_options; ?>
4046
4047 <p class="submit vigilante-submit-buttons">
4048 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4049 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4050 </button>
4051 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4052 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4053 </button>
4054 </p>
4055 </form>
4056 <?php
4057 }
4058
4059 /**
4060 * Render login security tab
4061 */
4062 private function render_tab_login() {
4063 $is_disabled = $this->render_module_disabled_notice( 'login_security' );
4064 $options = $this->settings->get_section( 'login_security' );
4065 $lockouts = $this->database->get_active_lockouts();
4066 ?>
4067 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="login_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
4068 <div id="vigilante-section-login-main" class="vigilante-settings-section">
4069 <h2>
4070 <?php esc_html_e( 'Login Protection', 'vigilante' ); ?>
4071 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4072 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
4073 </h2>
4074 <p><?php esc_html_e( 'Brute force protection and WordPress login hardening.', 'vigilante' ); ?></p>
4075
4076 <table class="form-table">
4077 <tr id="field-max-attempts">
4078 <th scope="row"><label for="vigilante-f-login-security-max-attempts"><?php esc_html_e( 'Max Login Attempts', 'vigilante' ); ?></label></th>
4079 <td>
4080 <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">
4081 <p class="description"><?php esc_html_e( 'Number of failed attempts before lockout.', 'vigilante' ); ?></p>
4082 </td>
4083 </tr>
4084 <tr>
4085 <th scope="row"><label for="vigilante-f-login-security-lockout-duration"><?php esc_html_e( 'Lockout Duration', 'vigilante' ); ?></label></th>
4086 <td>
4087 <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">
4088 <?php esc_html_e( 'minutes', 'vigilante' ); ?>
4089 </td>
4090 </tr>
4091 <tr>
4092 <th scope="row"><?php esc_html_e( 'Progressive Lockout', 'vigilante' ); ?></th>
4093 <td>
4094 <label>
4095 <input type="checkbox" name="login_security[lockout_increment]" value="1" <?php checked( ! empty( $options['lockout_increment'] ) ); ?>>
4096 <?php esc_html_e( 'Double lockout duration for repeat offenders', 'vigilante' ); ?>
4097 </label>
4098 </td>
4099 </tr>
4100 <tr>
4101 <th scope="row"><?php esc_html_e( 'Hide Login Errors', 'vigilante' ); ?></th>
4102 <td>
4103 <label>
4104 <input type="checkbox" name="login_security[hide_login_errors]" value="1" <?php checked( ! empty( $options['hide_login_errors'] ) ); ?>>
4105 <?php esc_html_e( 'Show generic error message instead of specific errors', 'vigilante' ); ?>
4106 </label>
4107 </td>
4108 </tr>
4109 <tr>
4110 <th scope="row"><?php esc_html_e( 'Disable Application Passwords', 'vigilante' ); ?></th>
4111 <td>
4112 <label>
4113 <input type="checkbox" name="login_security[disable_application_passwords]" value="1" <?php checked( ! empty( $options['disable_application_passwords'] ) ); ?>>
4114 <?php esc_html_e( 'Disable WordPress application passwords feature', 'vigilante' ); ?>
4115 </label>
4116 </td>
4117 </tr>
4118 </table>
4119
4120 <h3><?php esc_html_e( 'Custom Login URL', 'vigilante' ); ?></h3>
4121 <table class="form-table">
4122 <tr id="field-custom-login-url">
4123 <th scope="row"><?php esc_html_e( 'Login URL Slug', 'vigilante' ); ?></th>
4124 <td>
4125 <code><?php echo esc_url( home_url( '/' ) ); ?></code>
4126 <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' ); ?>">
4127 <p class="description">
4128 <?php esc_html_e( '&#9432; Leave empty to use default wp-login.php. Use only lowercase letters, numbers and hyphens.', 'vigilante' ); ?>
4129 </p>
4130 <div class="vigilante-login-url-preview" <?php echo empty( $options['custom_login_url'] ) ? 'style="display:none;"' : ''; ?>>
4131 <p class="description">
4132 <strong><?php esc_html_e( 'Your login URL:', 'vigilante' ); ?></strong>
4133 <code class="vigilante-login-url-display"><?php echo esc_url( home_url( sanitize_title( $options['custom_login_url'] ?? '' ) . '/' ) ); ?></code>
4134 </p>
4135 <p class="description">
4136 <?php esc_html_e( 'Direct access to wp-login.php and wp-admin will return a 404 error for non-logged users.', 'vigilante' ); ?>
4137 </p>
4138 <p class="description">
4139 <?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' ); ?>
4140 </p>
4141 </div>
4142 </td>
4143 </tr>
4144 </table>
4145
4146 <div class="vigilante-login-url-notify-wrapper <?php echo empty( $options['custom_login_url'] ) ? 'vigilante-login-url-notify-disabled' : ''; ?>">
4147 <table class="form-table">
4148 <tr>
4149 <th scope="row"><?php esc_html_e( 'Notify users', 'vigilante' ); ?></th>
4150 <td>
4151 <label>
4152 <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 ); ?>>
4153 <?php esc_html_e( 'Notify affected users when the login URL changes', 'vigilante' ); ?>
4154 </label>
4155 <div class="vigilante-login-url-send-notification" style="margin-top:12px;">
4156 <button type="button" id="vigilante_notify_login_url" class="button">
4157 <?php esc_html_e( 'Send notification now', 'vigilante' ); ?>
4158 </button>
4159 <span class="vigilante-login-url-notify-status"></span>
4160 <p class="description"><?php esc_html_e( 'Sends the new URL to administrators, editors, authors, and contributors.', 'vigilante' ); ?></p>
4161 </div>
4162 </td>
4163 </tr>
4164 </table>
4165 </div>
4166
4167 <?php $this->render_2fa_settings( $options ); ?>
4168
4169 <h3><?php esc_html_e( 'Notifications', 'vigilante' ); ?></h3>
4170 <table class="form-table">
4171 <tr>
4172 <th scope="row"><?php esc_html_e( 'Notify on Lockout', 'vigilante' ); ?></th>
4173 <td>
4174 <label>
4175 <input type="checkbox" name="login_security[notify_on_lockout]" value="1" <?php checked( ! empty( $options['notify_on_lockout'] ) ); ?>>
4176 <?php esc_html_e( 'Send email when an IP is locked out', 'vigilante' ); ?>
4177 </label>
4178 </td>
4179 </tr>
4180 <tr>
4181 <th scope="row"><?php esc_html_e( 'Notify on Admin Login', 'vigilante' ); ?></th>
4182 <td>
4183 <label>
4184 <input type="checkbox" name="login_security[notify_on_admin_login]" value="1" <?php checked( ! empty( $options['notify_on_admin_login'] ) ); ?>>
4185 <?php esc_html_e( 'Send email when an administrator logs in', 'vigilante' ); ?>
4186 </label>
4187 </td>
4188 </tr>
4189 </table>
4190
4191 <p class="description">
4192 <?php
4193 printf(
4194 /* translators: %s: Link to notification settings */
4195 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
4196 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
4197 );
4198 ?>
4199 </p>
4200 </div>
4201
4202 <p class="submit vigilante-submit-buttons">
4203 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4204 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4205 </button>
4206 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4207 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4208 </button>
4209 </p>
4210 </form>
4211
4212 <?php $this->render_lockout_info_section( $options, $lockouts ); ?>
4213 <?php
4214 }
4215
4216 /**
4217 * Render lockout information and blocked IPs section
4218 *
4219 * @param array $options Login security options.
4220 * @param array $lockouts Currently locked out IPs.
4221 */
4222 private function render_lockout_info_section( $options, $lockouts ) {
4223 $max_attempts = absint( $options['max_attempts'] ?? 5 );
4224 $lockout_duration = absint( $options['lockout_duration'] ?? 1800 );
4225 $lockout_increment = ! empty( $options['lockout_increment'] );
4226 $max_lockout = absint( $options['max_lockout_duration'] ?? 86400 );
4227 $two_factor = $options['two_factor'] ?? array();
4228 $two_factor_enabled = ! empty( $two_factor['enabled'] );
4229 ?>
4230 <div class="vigilante-settings-section vigilante-lockout-section">
4231 <h2 id="vigilante-section-login-status"><?php esc_html_e( 'Login Protection Status', 'vigilante' ); ?></h2>
4232
4233 <table class="form-table">
4234 <tr>
4235 <th scope="row"><?php esc_html_e( 'Current settings', 'vigilante' ); ?></th>
4236 <td>
4237 <?php
4238 printf(
4239 /* translators: 1: Maximum login attempts, 2: Lockout duration in minutes */
4240 esc_html__( 'After %1$d failed login attempts, the IP address is blocked for %2$d minutes.', 'vigilante' ),
4241 absint( $max_attempts ),
4242 absint( ceil( $lockout_duration / 60 ) )
4243 );
4244
4245 if ( $lockout_increment ) {
4246 echo '<br>';
4247 printf(
4248 /* translators: %d: Maximum lockout duration in hours */
4249 esc_html__( 'Progressive lockout enabled (max: %d hours).', 'vigilante' ),
4250 absint( ceil( $max_lockout / 3600 ) )
4251 );
4252 }
4253
4254 if ( $two_factor_enabled ) {
4255 echo '<br>';
4256 esc_html_e( 'Failed 2FA codes also count toward the lockout limit.', 'vigilante' );
4257 }
4258 ?>
4259 </td>
4260 </tr>
4261 <tr>
4262 <th scope="row"><?php esc_html_e( 'Blocked IPs', 'vigilante' ); ?></th>
4263 <td>
4264 <?php if ( ! empty( $lockouts ) ) : ?>
4265 <div class="vigilante-paginated-section">
4266 <div class="vigilante-fi-pagination-wrap"></div>
4267 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
4268 <thead>
4269 <tr>
4270 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
4271 <th><?php esc_html_e( 'Attempts', 'vigilante' ); ?></th>
4272 <th><?php esc_html_e( 'Blocked Until', 'vigilante' ); ?></th>
4273 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
4274 </tr>
4275 </thead>
4276 <tbody>
4277 <?php foreach ( $lockouts as $lockout ) :
4278 $lockout_time = strtotime( $lockout->locked_until );
4279 $remaining_seconds = $lockout_time - time();
4280 $remaining_text = $this->format_remaining_time( $remaining_seconds );
4281 ?>
4282 <tr>
4283 <td><code><?php echo esc_html( $lockout->ip_address ); ?></code></td>
4284 <td><?php echo esc_html( $lockout->attempts ); ?></td>
4285 <td>
4286 <?php echo esc_html( wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $lockout_time ) ); ?>
4287 <br>
4288 <small class="description">
4289 <?php
4290 printf(
4291 /* translators: %s: Remaining time */
4292 esc_html__( '%s remaining', 'vigilante' ),
4293 esc_html( $remaining_text )
4294 );
4295 ?>
4296 </small>
4297 </td>
4298 <td>
4299 <button type="button" class="button button-small vigilante-clear-lockout" data-ip="<?php echo esc_attr( $lockout->ip_address ); ?>">
4300 <?php esc_html_e( 'Unblock', 'vigilante' ); ?>
4301 </button>
4302 </td>
4303 </tr>
4304 <?php endforeach; ?>
4305 </tbody>
4306 </table>
4307 </div>
4308 <p class="description" style="margin-top: 10px;">
4309 <button type="button" class="button vigilante-clear-all-lockouts">
4310 <?php esc_html_e( 'Unblock All IPs', 'vigilante' ); ?>
4311 </button>
4312 <span style="margin-left: 10px;">
4313 <?php
4314 printf(
4315 /* translators: %d: Number of blocked IPs */
4316 esc_html( _n( '%d IP currently blocked', '%d IPs currently blocked', count( $lockouts ), 'vigilante' ) ),
4317 count( $lockouts )
4318 );
4319 ?>
4320 </span>
4321 </p>
4322 <?php else : ?>
4323 <span class="dashicons dashicons-yes-alt" style="color: #00a32a; font-size: 20px; width: 20px; height: 20px; vertical-align: middle;"></span>
4324 <span style="vertical-align: middle; margin-left: 5px;"><?php esc_html_e( 'No IPs are currently blocked. All clear!', 'vigilante' ); ?></span>
4325 <?php endif; ?>
4326 </td>
4327 </tr>
4328 </table>
4329 </div>
4330 <?php
4331 }
4332
4333 /**
4334 * Format remaining lockout time in human readable format
4335 *
4336 * @param int $seconds Remaining seconds.
4337 * @return string Formatted time string.
4338 */
4339 private function format_remaining_time( $seconds ) {
4340 if ( $seconds <= 0 ) {
4341 return __( 'expired', 'vigilante' );
4342 }
4343
4344 if ( $seconds < 60 ) {
4345 return sprintf(
4346 /* translators: %d: Number of seconds */
4347 _n( '%d second', '%d seconds', $seconds, 'vigilante' ),
4348 $seconds
4349 );
4350 }
4351
4352 if ( $seconds < 3600 ) {
4353 $minutes = ceil( $seconds / 60 );
4354 return sprintf(
4355 /* translators: %d: Number of minutes */
4356 _n( '%d minute', '%d minutes', $minutes, 'vigilante' ),
4357 $minutes
4358 );
4359 }
4360
4361 $hours = floor( $seconds / 3600 );
4362 $remaining_minutes = ceil( ( $seconds % 3600 ) / 60 );
4363
4364 if ( $remaining_minutes > 0 ) {
4365 return sprintf(
4366 /* translators: 1: Number of hours, 2: Number of minutes */
4367 __( '%1$d hours %2$d minutes', 'vigilante' ),
4368 $hours,
4369 $remaining_minutes
4370 );
4371 }
4372
4373 return sprintf(
4374 /* translators: %d: Number of hours */
4375 _n( '%d hour', '%d hours', $hours, 'vigilante' ),
4376 $hours
4377 );
4378 }
4379
4380 /**
4381 * Render 2FA settings section
4382 *
4383 * @param array $options Login security options.
4384 */
4385 private function render_2fa_settings( $options ) {
4386 $two_factor = $options['two_factor'] ?? array();
4387 $all_roles = wp_roles()->roles;
4388 $enforced = $two_factor['enforced_roles'] ?? array( 'administrator', 'editor' );
4389 $excluded = $two_factor['excluded_users'] ?? array();
4390 $method = $two_factor['method'] ?? 'email';
4391 $grace_days = $two_factor['grace_period_days'] ?? 3;
4392 ?>
4393 <h3 id="vigilante-section-login-2fa">
4394 <?php esc_html_e( 'Two-Factor Authentication (2FA)', 'vigilante' ); ?>
4395 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4396 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
4397 </h3>
4398 <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>
4399
4400 <table class="form-table">
4401 <tr>
4402 <th scope="row"><?php esc_html_e( 'Enable 2FA', 'vigilante' ); ?></th>
4403 <td>
4404 <label>
4405 <input type="checkbox" name="login_security[two_factor][enabled]" id="vigilante_2fa_enabled" value="1" <?php checked( ! empty( $two_factor['enabled'] ) ); ?>>
4406 <?php esc_html_e( 'Enable two-factor authentication', 'vigilante' ); ?>
4407 </label>
4408 </td>
4409 </tr>
4410 </table>
4411
4412 <div class="vigilante-2fa-settings-wrapper <?php echo empty( $two_factor['enabled'] ) ? 'vigilante-2fa-settings-disabled' : ''; ?>">
4413 <table class="form-table">
4414 <tr>
4415 <th scope="row"><?php esc_html_e( 'Verification method', 'vigilante' ); ?></th>
4416 <td>
4417 <fieldset class="vigilante-2fa-method-selector">
4418 <label class="vigilante-2fa-method-option <?php echo 'email' === $method ? 'selected' : ''; ?>">
4419 <input type="radio" name="login_security[two_factor][method]" value="email" <?php checked( $method, 'email' ); ?>>
4420 <span class="dashicons dashicons-email"></span>
4421 <span class="method-info">
4422 <strong><?php esc_html_e( 'Email code', 'vigilante' ); ?></strong>
4423 <span><?php esc_html_e( 'Users receive a 6-digit code via email after entering their password.', 'vigilante' ); ?></span>
4424 </span>
4425 </label>
4426 <label class="vigilante-2fa-method-option <?php echo 'totp' === $method ? 'selected' : ''; ?>">
4427 <input type="radio" name="login_security[two_factor][method]" value="totp" <?php checked( $method, 'totp' ); ?>>
4428 <span class="dashicons dashicons-smartphone"></span>
4429 <span class="method-info">
4430 <strong><?php esc_html_e( 'Authenticator app (TOTP)', 'vigilante' ); ?></strong>
4431 <span><?php esc_html_e( 'Users verify with a time-based code from Google Authenticator, Authy, etc.', 'vigilante' ); ?></span>
4432 </span>
4433 </label>
4434 </fieldset>
4435 </td>
4436 </tr>
4437 <tr>
4438 <th scope="row"><?php esc_html_e( 'Enforce for roles', 'vigilante' ); ?></th>
4439 <td>
4440 <div class="vigilante-2fa-roles">
4441 <?php $this->list_sentinel( 'login_security[two_factor][enforced_roles]' ); ?>
4442 <?php foreach ( $all_roles as $role_slug => $role_data ) :
4443 $user_count = count( get_users( array( 'role' => $role_slug, 'fields' => 'ID' ) ) );
4444 ?>
4445 <label>
4446 <input type="checkbox"
4447 name="login_security[two_factor][enforced_roles][]"
4448 value="<?php echo esc_attr( $role_slug ); ?>"
4449 <?php checked( in_array( $role_slug, $enforced, true ) ); ?>>
4450 <span class="role-name"><?php echo esc_html( translate_user_role( $role_data['name'] ) ); ?></span>
4451 <span class="role-count">(<?php echo esc_html( $user_count ); ?>)</span>
4452 </label>
4453 <?php endforeach; ?>
4454 </div>
4455 <p class="description"><?php esc_html_e( 'Users with these roles will be required to verify with the selected method.', 'vigilante' ); ?></p>
4456 </td>
4457 </tr>
4458 <tr>
4459 <th scope="row"><?php esc_html_e( 'Exclude specific users', 'vigilante' ); ?></th>
4460 <td>
4461 <div class="vigilante-2fa-user-search-container">
4462 <div class="vigilante-2fa-user-search">
4463 <span class="search-icon"></span>
4464 <input type="text"
4465 id="vigilante_2fa_user_search"
4466 placeholder="<?php esc_attr_e( 'Search users by name or email...', 'vigilante' ); ?>"
4467 autocomplete="off">
4468 <div class="vigilante-2fa-search-results"></div>
4469 </div>
4470 <div class="vigilante-2fa-excluded-users">
4471 <?php $this->list_sentinel( 'login_security[two_factor][excluded_users]' ); ?>
4472 <?php
4473 foreach ( $excluded as $user_id ) :
4474 $user = get_user_by( 'ID', $user_id );
4475 if ( ! $user ) continue;
4476 ?>
4477 <div class="vigilante-2fa-excluded-user" data-user-id="<?php echo esc_attr( $user_id ); ?>">
4478 <span class="user-display"><?php echo esc_html( $user->display_name . ' (' . $user->user_email . ')' ); ?></span>
4479 <button type="button" class="remove-user" aria-label="<?php esc_attr_e( 'Remove', 'vigilante' ); ?>">&times;</button>
4480 <input type="hidden" name="login_security[two_factor][excluded_users][]" value="<?php echo esc_attr( $user_id ); ?>">
4481 </div>
4482 <?php endforeach; ?>
4483 </div>
4484 </div>
4485 <p class="description"><?php esc_html_e( 'These users will not be required to use 2FA regardless of their role.', 'vigilante' ); ?></p>
4486 </td>
4487 </tr>
4488
4489 <!-- Remember device option -->
4490 <tr>
4491 <th scope="row"><?php esc_html_e( 'Remember device', 'vigilante' ); ?></th>
4492 <td>
4493 <label>
4494 <input type="checkbox" name="login_security[two_factor][allow_remember_device]" value="1" <?php checked( ! empty( $two_factor['allow_remember_device'] ) ); ?>>
4495 <?php esc_html_e( 'Allow users to skip 2FA verification on trusted devices', 'vigilante' ); ?>
4496 </label>
4497 <p class="description">
4498 <?php
4499 printf(
4500 /* translators: %d: Number of days */
4501 esc_html__( 'When enabled, users can check "Remember this device" on the verification screen to skip 2FA for %d days.', 'vigilante' ),
4502 absint( $two_factor['remember_device_days'] ?? 30 )
4503 );
4504 ?>
4505 </p>
4506 </td>
4507 </tr>
4508
4509 <!-- TOTP-specific: Grace period -->
4510 <tr class="vigilante-2fa-totp-only" <?php echo 'totp' !== $method ? 'style="display:none;"' : ''; ?>>
4511 <th scope="row"><label for="vigilante-f-login-security-two-factor-grace-period-days"><?php esc_html_e( 'Grace period', 'vigilante' ); ?></label></th>
4512 <td>
4513 <input id="vigilante-f-login-security-two-factor-grace-period-days" type="number"
4514 name="login_security[two_factor][grace_period_days]"
4515 value="<?php echo esc_attr( $grace_days ); ?>"
4516 min="0" max="30" class="small-text">
4517 <?php esc_html_e( 'days', 'vigilante' ); ?>
4518 <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>
4519 </td>
4520 </tr>
4521
4522 <!-- Email-specific: Sender name -->
4523 <tr class="vigilante-2fa-email-only" <?php echo 'email' !== $method ? 'style="display:none;"' : ''; ?>>
4524 <th scope="row"><label for="vigilante-f-login-security-two-factor-email-from-name"><?php esc_html_e( 'Email sender name', 'vigilante' ); ?></label></th>
4525 <td>
4526 <input id="vigilante-f-login-security-two-factor-email-from-name" type="text"
4527 name="login_security[two_factor][email_from_name]"
4528 value="<?php echo esc_attr( $two_factor['email_from_name'] ?? '' ); ?>"
4529 class="regular-text vigilante-2fa-email-from"
4530 placeholder="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>">
4531 <p class="description"><?php esc_html_e( 'Name shown in verification emails. Leave empty to use site name.', 'vigilante' ); ?></p>
4532 </td>
4533 </tr>
4534
4535 <!-- TOTP-specific: Reset users -->
4536 <tr class="vigilante-2fa-totp-only" <?php echo 'totp' !== $method ? 'style="display:none;"' : ''; ?>>
4537 <th scope="row"><?php esc_html_e( 'Reset user TOTP', 'vigilante' ); ?></th>
4538 <td>
4539 <div class="vigilante-totp-reset-container">
4540 <div class="vigilante-2fa-user-search">
4541 <span class="search-icon"></span>
4542 <input type="text"
4543 id="vigilante_totp_reset_search"
4544 placeholder="<?php esc_attr_e( 'Search users with TOTP configured...', 'vigilante' ); ?>"
4545 autocomplete="off">
4546 <div class="vigilante-totp-reset-results"></div>
4547 </div>
4548 <div class="vigilante-totp-reset-selected"></div>
4549 <button type="button" id="vigilante_totp_reset_btn" class="button" style="display:none;">
4550 <?php esc_html_e( 'Reset selected', 'vigilante' ); ?>
4551 </button>
4552 <span class="vigilante-totp-reset-status"></span>
4553 </div>
4554 <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>
4555 </td>
4556 </tr>
4557 </table>
4558
4559 <h3><?php esc_html_e( 'User notification', 'vigilante' ); ?></h3>
4560 <table class="form-table">
4561 <tr>
4562 <th scope="row"><?php esc_html_e( 'Notify on enable', 'vigilante' ); ?></th>
4563 <td>
4564 <label>
4565 <input type="checkbox" name="login_security[two_factor][notify_on_enable]" value="1" <?php checked( $two_factor['notify_on_enable'] ?? true ); ?>>
4566 <?php esc_html_e( 'Send notification email to affected users when 2FA is enabled', 'vigilante' ); ?>
4567 </label>
4568
4569 <div class="vigilante-2fa-notification-options">
4570 <label>
4571 <input type="radio" name="vigilante_2fa_notify_mode" value="all" checked>
4572 <?php esc_html_e( 'Send to all affected users', 'vigilante' ); ?>
4573 </label>
4574 <label>
4575 <input type="radio" name="vigilante_2fa_notify_mode" value="new">
4576 <?php esc_html_e( 'Send only to users not previously notified', 'vigilante' ); ?>
4577 </label>
4578 </div>
4579
4580 <div class="vigilante-2fa-send-notification">
4581 <button type="button" id="vigilante_2fa_send_notification" class="button">
4582 <?php esc_html_e( 'Send notification now', 'vigilante' ); ?>
4583 </button>
4584 <span class="vigilante-2fa-notification-status"></span>
4585 </div>
4586 </td>
4587 </tr>
4588 </table>
4589 </div>
4590 <?php
4591 }
4592
4593 /**
4594 * Render security headers tab
4595 */
4596 /**
4597 * Offer back the header settings the 2.9.8 migration wiped.
4598 *
4599 * Rendered outside the settings form on purpose, so its buttons can never
4600 * submit it, and only when there is something to actually change. Shows the
4601 * difference before anything is written: nothing is applied that the owner
4602 * has not seen first.
4603 *
4604 * @since 2.10.0
4605 */
4606 private function render_headers_recovery_offer() {
4607 /*
4608 * On a network the .htaccess belongs to every site and only the main one
4609 * writes it, so this is not a decision a subsite gets to make. Its own
4610 * security_headers options are inert anyway: what the network serves
4611 * comes from the file the main site owns. Without this gate a subsite
4612 * administrator was shown a Restore button that could only ever answer
4613 * with a permission error, which is worse than showing nothing.
4614 */
4615 if ( ! Vigilante_Settings::can_write_shared_files() ) {
4616 return;
4617 }
4618
4619 if ( ! Vigilante_Htaccess_Recovery::is_available() ) {
4620 /*
4621 * Already restored. Offer to take it back for as long as the previous
4622 * section is still stored: a restore that cannot be undone is a second
4623 * irreversible change on top of the one being repaired.
4624 */
4625 if ( Vigilante_Htaccess_Recovery::has_undo() ) {
4626 ?>
4627 <div class="notice notice-info inline" id="vigilante-headers-recovery-undo">
4628 <p>
4629 <?php esc_html_e( 'The Security Headers settings were restored from the copy Vigilant had kept of your .htaccess.', 'vigilante' ); ?>
4630 <button type="button" class="button button-small" id="vigilante-recovery-undo">
4631 <?php esc_html_e( 'Undo the restore', 'vigilante' ); ?>
4632 </button>
4633 </p>
4634 </div>
4635 <?php
4636 }
4637
4638 return;
4639 }
4640
4641 $rows = Vigilante_Htaccess_Recovery::get_diff( $this->settings );
4642
4643 if ( empty( $rows ) ) {
4644 return;
4645 }
4646
4647 $snapshot = Vigilante_Htaccess_Recovery::get_snapshot();
4648 $taken = isset( $snapshot['time'] ) ? (int) $snapshot['time'] : 0;
4649 $block = Vigilante_Htaccess_Recovery::get_raw_block();
4650 ?>
4651 <div class="vigilante-settings-section" id="vigilante-headers-recovery">
4652 <h2><?php esc_html_e( 'Recover your previous header settings', 'vigilante' ); ?></h2>
4653 <p>
4654 <?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' ); ?>
4655 </p>
4656 <?php if ( $taken ) : ?>
4657 <p class="description">
4658 <?php
4659 printf(
4660 /* translators: %s: date and time the .htaccess copy was taken. */
4661 esc_html__( 'Copy taken on %s.', 'vigilante' ),
4662 esc_html( wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $taken ) )
4663 );
4664 ?>
4665 </p>
4666 <?php endif; ?>
4667
4668 <table class="widefat striped">
4669 <thead>
4670 <tr>
4671 <th scope="col"><?php esc_html_e( 'Setting', 'vigilante' ); ?></th>
4672 <th scope="col"><?php esc_html_e( 'Now', 'vigilante' ); ?></th>
4673 <th scope="col"><?php esc_html_e( 'Would be restored to', 'vigilante' ); ?></th>
4674 </tr>
4675 </thead>
4676 <tbody>
4677 <?php foreach ( $rows as $row ) : ?>
4678 <tr>
4679 <th scope="row"><?php echo esc_html( $row['label'] ); ?></th>
4680 <td><?php echo esc_html( $row['current'] ); ?></td>
4681 <td>
4682 <?php echo esc_html( $row['recovered'] ); ?>
4683 <?php if ( ! empty( $row['detail'] ) ) : ?>
4684 <br><span class="description"><?php echo esc_html( $row['detail'] ); ?></span>
4685 <?php endif; ?>
4686 </td>
4687 </tr>
4688 <?php endforeach; ?>
4689 </tbody>
4690 </table>
4691
4692 <p class="description">
4693 <?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' ); ?>
4694 </p>
4695
4696 <?php if ( '' !== $block ) : ?>
4697 <details>
4698 <summary><?php esc_html_e( 'Show the saved .htaccess block', 'vigilante' ); ?></summary>
4699 <textarea readonly rows="12" class="large-text code" onclick="this.select();"><?php echo esc_textarea( $block ); ?></textarea>
4700 </details>
4701 <?php endif; ?>
4702
4703 <p class="submit vigilante-submit-buttons">
4704 <button type="button" class="button button-primary" id="vigilante-recovery-restore">
4705 <?php esc_html_e( 'Restore these settings', 'vigilante' ); ?>
4706 </button>
4707 <button type="button" class="button" id="vigilante-recovery-dismiss">
4708 <?php esc_html_e( 'No thanks, keep what I have', 'vigilante' ); ?>
4709 </button>
4710 </p>
4711 <div id="vigilante-recovery-result"></div>
4712 </div>
4713 <?php
4714 }
4715
4716 private function render_tab_headers() {
4717 $is_disabled = $this->render_module_disabled_notice( 'security_headers' );
4718 // Every setting on this tab ends up in .htaccess, so on a subsite the
4719 // whole tab is somebody else's, values included.
4720 $vg_shared_locked = $this->shared_files_locked();
4721 $options = $this->get_section_for_display( 'security_headers' );
4722 ?>
4723 <?php $this->render_headers_recovery_offer(); ?>
4724
4725 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="security_headers" <?php echo $is_disabled ? 'inert' : ''; ?>>
4726 <?php $this->render_shared_files_notice(); ?>
4727 <div id="vigilante-section-headers-main" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
4728 <h2>
4729 <?php esc_html_e( 'Security Headers', 'vigilante' ); ?>
4730 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
4731 </h2>
4732 <p><?php esc_html_e( 'HTTP headers sent with every response via .htaccess (mod_headers).', 'vigilante' ); ?></p>
4733
4734 <table class="form-table">
4735 <tr>
4736 <th scope="row"><label for="vigilante-f-security-headers-x-frame-options"><?php esc_html_e( 'X-Frame-Options', 'vigilante' ); ?></label></th>
4737 <td>
4738 <select id="vigilante-f-security-headers-x-frame-options" name="security_headers[x_frame_options]">
4739 <option value="" <?php selected( empty( $options['x_frame_options'] ) ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
4740 <option value="SAMEORIGIN" <?php selected( $options['x_frame_options'] ?? '', 'SAMEORIGIN' ); ?>>SAMEORIGIN</option>
4741 <option value="DENY" <?php selected( $options['x_frame_options'] ?? '', 'DENY' ); ?>>DENY</option>
4742 </select>
4743 <p class="description"><?php esc_html_e( '&#9432; Prevents clickjacking attacks. Also sets CSP frame-ancestors automatically.', 'vigilante' ); ?></p>
4744 </td>
4745 </tr>
4746 <tr>
4747 <th scope="row"><?php esc_html_e( 'X-Content-Type-Options', 'vigilante' ); ?></th>
4748 <td>
4749 <label>
4750 <input type="checkbox" name="security_headers[x_content_type_options]" value="1" <?php checked( ! empty( $options['x_content_type_options'] ) ); ?>>
4751 <?php esc_html_e( 'Add nosniff header to prevent MIME type sniffing', 'vigilante' ); ?>
4752 </label>
4753 </td>
4754 </tr>
4755 <tr>
4756 <th scope="row"><label for="vigilante-f-security-headers-referrer-policy"><?php esc_html_e( 'Referrer-Policy', 'vigilante' ); ?></label></th>
4757 <td>
4758 <select id="vigilante-f-security-headers-referrer-policy" name="security_headers[referrer_policy]">
4759 <option value="" <?php selected( empty( $options['referrer_policy'] ) ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
4760 <option value="no-referrer" <?php selected( $options['referrer_policy'] ?? '', 'no-referrer' ); ?>>no-referrer</option>
4761 <option value="strict-origin-when-cross-origin" <?php selected( $options['referrer_policy'] ?? '', 'strict-origin-when-cross-origin' ); ?>>strict-origin-when-cross-origin</option>
4762 <option value="same-origin" <?php selected( $options['referrer_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
4763 </select>
4764 </td>
4765 </tr>
4766 </table>
4767
4768 <h3 id="vigilante-section-headers-csp"><?php esc_html_e( 'Content Security Policy', 'vigilante' ); ?></h3>
4769 <table class="form-table">
4770 <tr>
4771 <th scope="row"><?php esc_html_e( 'Enable CSP', 'vigilante' ); ?></th>
4772 <td>
4773 <label>
4774 <input type="checkbox" name="security_headers[csp][enabled]" value="1" <?php checked( ! empty( $options['csp']['enabled'] ) ); ?>>
4775 <?php esc_html_e( 'Enable Content Security Policy', 'vigilante' ); ?>
4776 </label>
4777 </td>
4778 </tr>
4779 <tr>
4780 <th scope="row"><?php esc_html_e( 'Report Only Mode', 'vigilante' ); ?></th>
4781 <td>
4782 <label>
4783 <input type="checkbox" name="security_headers[csp][report_only]" value="1" <?php checked( ! empty( $options['csp']['report_only'] ) ); ?>>
4784 <?php esc_html_e( 'Report violations without blocking (for testing)', 'vigilante' ); ?>
4785 </label>
4786 </td>
4787 </tr>
4788 </table>
4789
4790 <h3 id="vigilante-section-headers-force-https"><?php esc_html_e( 'HTTPS', 'vigilante' ); ?></h3>
4791 <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>
4792 <table class="form-table">
4793 <tr>
4794 <th scope="row"><?php esc_html_e( 'Redirect HTTP to HTTPS', 'vigilante' ); ?></th>
4795 <td>
4796 <label>
4797 <input type="checkbox" name="security_headers[redirect_http_to_https]" value="1" <?php checked( ! empty( $options['redirect_http_to_https'] ) ); ?>>
4798 <?php esc_html_e( 'Send visitors arriving over HTTP to the HTTPS address', 'vigilante' ); ?>
4799 </label>
4800 <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>
4801 </td>
4802 </tr>
4803 <tr>
4804 <th scope="row"><?php esc_html_e( 'Fix Mixed Content', 'vigilante' ); ?></th>
4805 <td>
4806 <label>
4807 <input type="checkbox" name="security_headers[fix_mixed_content]" value="1" <?php checked( ! empty( $options['fix_mixed_content'] ) ); ?>>
4808 <?php esc_html_e( 'Rewrite this site http:// resources to https://', 'vigilante' ); ?>
4809 </label>
4810 <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>
4811 </td>
4812 </tr>
4813 <tr id="field-upgrade-insecure-requests">
4814 <th scope="row"><?php esc_html_e( 'Upgrade Insecure Requests', 'vigilante' ); ?></th>
4815 <td>
4816 <label>
4817 <input type="checkbox" name="security_headers[upgrade_insecure_requests]" value="1" <?php checked( ! empty( $options['upgrade_insecure_requests'] ) ); ?>>
4818 <?php esc_html_e( 'Ask browsers to upgrade every http:// request to https://', 'vigilante' ); ?>
4819 </label>
4820 <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>
4821 </td>
4822 </tr>
4823 <tr>
4824 <th scope="row"><?php esc_html_e( 'Rewrite Site Address on Activation', 'vigilante' ); ?></th>
4825 <td>
4826 <label>
4827 <input type="checkbox" name="security_headers[force_https]" value="1" <?php checked( ! empty( $options['force_https'] ) ); ?>>
4828 <?php esc_html_e( 'Change the WordPress and site addresses to https:// when the plugin is activated', 'vigilante' ); ?>
4829 </label>
4830 <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>
4831 </td>
4832 </tr>
4833 </table>
4834
4835 <h3 id="vigilante-section-headers-hsts"><?php esc_html_e( 'HSTS (HTTP Strict Transport Security)', 'vigilante' ); ?></h3>
4836 <?php $vig_home_https = ( 0 === strpos( (string) get_option( 'home' ), 'https://' ) ); ?>
4837 <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>
4838 <?php if ( ! $vig_home_https ) : ?>
4839 <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>
4840 <?php endif; ?>
4841 <table class="form-table">
4842 <tr>
4843 <th scope="row"><?php esc_html_e( 'Enable HSTS', 'vigilante' ); ?></th>
4844 <td>
4845 <?php if ( ! $vig_home_https ) : ?>
4846 <?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. */ ?>
4847 <input type="hidden" name="security_headers[hsts][enabled]" value="<?php echo ! empty( $options['hsts']['enabled'] ) ? '1' : '0'; ?>">
4848 <?php endif; ?>
4849 <label>
4850 <input type="checkbox" name="security_headers[hsts][enabled]" value="1" <?php checked( ! empty( $options['hsts']['enabled'] ) ); ?> <?php disabled( ! $vig_home_https ); ?>>
4851 <?php esc_html_e( 'Send the Strict-Transport-Security header', 'vigilante' ); ?>
4852 </label>
4853 <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>
4854 </td>
4855 </tr>
4856 <tr>
4857 <th scope="row"><label for="vigilante-f-security-headers-hsts-max-age"><?php esc_html_e( 'Max Age', 'vigilante' ); ?></label></th>
4858 <td>
4859 <select id="vigilante-f-security-headers-hsts-max-age" name="security_headers[hsts][max_age]">
4860 <option value="86400" <?php selected( $options['hsts']['max_age'] ?? 31536000, 86400 ); ?>><?php esc_html_e( '1 day (testing)', 'vigilante' ); ?></option>
4861 <option value="2592000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 2592000 ); ?>><?php esc_html_e( '30 days', 'vigilante' ); ?></option>
4862 <option value="31536000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 31536000 ); ?>><?php esc_html_e( '1 year (recommended)', 'vigilante' ); ?></option>
4863 <option value="63072000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 63072000 ); ?>><?php esc_html_e( '2 years', 'vigilante' ); ?></option>
4864 </select>
4865 </td>
4866 </tr>
4867 <tr>
4868 <th scope="row"><?php esc_html_e( 'Include Subdomains', 'vigilante' ); ?></th>
4869 <td>
4870 <label>
4871 <input type="checkbox" name="security_headers[hsts][include_subdomains]" value="1" <?php checked( ! empty( $options['hsts']['include_subdomains'] ) ); ?>>
4872 <?php esc_html_e( 'Apply HSTS to all subdomains', 'vigilante' ); ?>
4873 </label>
4874 </td>
4875 </tr>
4876 </table>
4877
4878 <h3 id="vigilante-section-headers-fingerprint"><?php esc_html_e( 'Server Identity', 'vigilante' ); ?></h3>
4879 <p class="description"><?php esc_html_e( 'Hide identifying information that servers expose in responses.', 'vigilante' ); ?></p>
4880 <table class="form-table">
4881 <tr>
4882 <th scope="row"><?php esc_html_e( 'Server Signature', 'vigilante' ); ?></th>
4883 <td>
4884 <label>
4885 <input type="checkbox" name="security_headers[hide_server_signature]" value="1" <?php checked( ! empty( $options['hide_server_signature'] ) ); ?>>
4886 <?php esc_html_e( 'Hide server signature (ServerSignature Off)', 'vigilante' ); ?>
4887 </label>
4888 </td>
4889 </tr>
4890 <tr>
4891 <th scope="row"><?php esc_html_e( 'Remove Fingerprinting Headers', 'vigilante' ); ?></th>
4892 <td>
4893 <label>
4894 <input type="checkbox" name="security_headers[remove_fingerprinting_headers]" value="1" <?php checked( ! empty( $options['remove_fingerprinting_headers'] ) ); ?>>
4895 <?php esc_html_e( 'Remove X-Powered-By and Server headers', 'vigilante' ); ?>
4896 </label>
4897 </td>
4898 </tr>
4899 </table>
4900 </div>
4901
4902 <?php $vg_cop = ( isset( $options['cross_origin_policies'] ) && is_array( $options['cross_origin_policies'] ) ) ? $options['cross_origin_policies'] : array(); ?>
4903 <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' : ''; ?>>
4904 <h2>
4905 <?php esc_html_e( 'Cross-Origin Policies', 'vigilante' ); ?>
4906 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
4907 </h2>
4908 <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>
4909
4910 <table class="form-table">
4911 <tr>
4912 <th scope="row"><label for="vigilante-f-security-headers-coop"><?php esc_html_e( 'Cross-Origin-Opener-Policy (COOP)', 'vigilante' ); ?></label></th>
4913 <td>
4914 <select id="vigilante-f-security-headers-coop" name="security_headers[cross_origin_policies][opener_policy]">
4915 <option value="" <?php selected( empty( $vg_cop['opener_policy'] ) ); ?>><?php esc_html_e( 'Disabled (header not sent)', 'vigilante' ); ?></option>
4916 <option value="unsafe-none" <?php selected( $vg_cop['opener_policy'] ?? '', 'unsafe-none' ); ?>>unsafe-none</option>
4917 <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>
4918 <option value="same-origin" <?php selected( $vg_cop['opener_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
4919 </select>
4920 <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>
4921 </td>
4922 </tr>
4923 <tr>
4924 <th scope="row"><label for="vigilante-f-security-headers-coep"><?php esc_html_e( 'Cross-Origin-Embedder-Policy (COEP)', 'vigilante' ); ?></label></th>
4925 <td>
4926 <select id="vigilante-f-security-headers-coep" name="security_headers[cross_origin_policies][embedder_policy]">
4927 <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>
4928 <option value="credentialless" <?php selected( $vg_cop['embedder_policy'] ?? '', 'credentialless' ); ?>>credentialless</option>
4929 <option value="require-corp" <?php selected( $vg_cop['embedder_policy'] ?? '', 'require-corp' ); ?>>require-corp</option>
4930 </select>
4931 <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>
4932 </td>
4933 </tr>
4934 <tr>
4935 <th scope="row"><label for="vigilante-f-security-headers-corp"><?php esc_html_e( 'Cross-Origin-Resource-Policy (CORP)', 'vigilante' ); ?></label></th>
4936 <td>
4937 <select id="vigilante-f-security-headers-corp" name="security_headers[cross_origin_policies][resource_policy]">
4938 <option value="" <?php selected( empty( $vg_cop['resource_policy'] ) ); ?>><?php esc_html_e( 'Disabled (header not sent)', 'vigilante' ); ?></option>
4939 <option value="same-site" <?php selected( $vg_cop['resource_policy'] ?? '', 'same-site' ); ?>>same-site</option>
4940 <option value="same-origin" <?php selected( $vg_cop['resource_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
4941 <option value="cross-origin" <?php selected( $vg_cop['resource_policy'] ?? '', 'cross-origin' ); ?>><?php esc_html_e( 'cross-origin (recommended)', 'vigilante' ); ?></option>
4942 </select>
4943 <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>
4944 </td>
4945 </tr>
4946 </table>
4947 </div>
4948
4949 <p class="submit vigilante-submit-buttons">
4950 <?php if ( ! $vg_shared_locked ) : ?>
4951 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4952 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4953 </button>
4954 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4955 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4956 </button>
4957 <?php endif; ?>
4958 <?php /* Testing what the server actually sends is read-only and useful from any site of a network. */ ?>
4959 <button type="button" class="button vigilante-test-headers">
4960 <?php esc_html_e( 'Test Headers', 'vigilante' ); ?>
4961 </button>
4962 </p>
4963 </form>
4964
4965 <div id="vigilante-headers-result"></div>
4966 <?php
4967 }
4968
4969 /**
4970 * Render REST API tab
4971 */
4972 private function render_tab_rest_api() {
4973 $is_disabled = $this->render_module_disabled_notice( 'rest_api_security' );
4974 $options = $this->settings->get_section( 'rest_api_security' );
4975 ?>
4976 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="rest_api_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
4977 <div id="vigilante-section-rest-api-main" class="vigilante-settings-section">
4978 <h2>
4979 <?php esc_html_e( 'REST API Security', 'vigilante' ); ?>
4980 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4981 </h2>
4982 <p><?php esc_html_e( 'Control access to WordPress REST API endpoints.', 'vigilante' ); ?></p>
4983
4984 <table class="form-table">
4985 <tr>
4986 <th scope="row"><label for="vigilante-f-rest-api-security-mode"><?php esc_html_e( 'Access Mode', 'vigilante' ); ?></label></th>
4987 <td>
4988 <select id="vigilante-f-rest-api-security-mode" name="rest_api_security[mode]">
4989 <option value="open" <?php selected( $options['mode'] ?? 'selective', 'open' ); ?>><?php esc_html_e( 'Open - Allow all requests', 'vigilante' ); ?></option>
4990 <option value="selective" <?php selected( $options['mode'] ?? 'selective', 'selective' ); ?>><?php esc_html_e( 'Selective - Protect sensitive endpoints', 'vigilante' ); ?></option>
4991 <option value="authenticated_only" <?php selected( $options['mode'] ?? 'selective', 'authenticated_only' ); ?>><?php esc_html_e( 'Authenticated - Require login for all', 'vigilante' ); ?></option>
4992 </select>
4993 <p class="description"><?php esc_html_e( 'Selective mode is recommended.', 'vigilante' ); ?></p>
4994 </td>
4995 </tr>
4996 <tr id="field-block-user-enumeration">
4997 <th scope="row"><?php esc_html_e( 'Block User Enumeration', 'vigilante' ); ?></th>
4998 <td>
4999 <label>
5000 <input type="checkbox" name="rest_api_security[block_user_enumeration]" value="1" <?php checked( ! empty( $options['block_user_enumeration'] ) ); ?>>
5001 <?php esc_html_e( 'Protect /wp/v2/users endpoint for unauthenticated users', 'vigilante' ); ?>
5002 </label>
5003 </td>
5004 </tr>
5005 <tr>
5006 <th scope="row"><?php esc_html_e( 'Disable JSONP', 'vigilante' ); ?></th>
5007 <td>
5008 <label>
5009 <input type="checkbox" name="rest_api_security[disable_jsonp]" value="1" <?php checked( ! empty( $options['disable_jsonp'] ) ); ?>>
5010 <?php esc_html_e( 'Disable JSONP support in REST API', 'vigilante' ); ?>
5011 </label>
5012 </td>
5013 </tr>
5014 </table>
5015 </div>
5016
5017 <p class="submit vigilante-submit-buttons">
5018 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5019 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5020 </button>
5021 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5022 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5023 </button>
5024 </p>
5025 </form>
5026 <?php
5027 }
5028
5029 /**
5030 * Render User Security tab
5031 */
5032 private function render_tab_users() {
5033 $is_disabled = $this->render_module_disabled_notice( 'user_security' );
5034 $options = $this->settings->get_section( 'user_security' );
5035 $monitoring = $options['admin_monitoring'] ?? array();
5036 $registration = $options['registration_approval'] ?? array();
5037 $session_limits = $options['session_limits'] ?? array();
5038 $password_exp = $options['password_expiration'] ?? array();
5039 $email_verify = $options['email_verification'] ?? array();
5040 ?>
5041
5042 <!-- ============================================================
5043 SETTINGS SECTION - Single form for all configuration
5044 ============================================================ -->
5045 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="user_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
5046
5047 <!-- Username & Password Protection -->
5048 <div id="vigilante-section-users-password" class="vigilante-settings-section">
5049 <h2>
5050 <?php esc_html_e( 'Username & password protection', 'vigilante' ); ?>
5051 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5052 </h2>
5053 <p><?php esc_html_e( 'Enforce secure username and password policies.', 'vigilante' ); ?></p>
5054
5055 <table class="form-table">
5056 <tr>
5057 <th scope="row"><?php esc_html_e( 'Block Insecure Usernames', 'vigilante' ); ?></th>
5058 <td>
5059 <label>
5060 <input type="checkbox" name="user_security[block_insecure_usernames]" value="1" <?php checked( ! empty( $options['block_insecure_usernames'] ) ); ?>>
5061 <?php esc_html_e( 'Prevent creation of users with common usernames (admin, administrator, etc.)', 'vigilante' ); ?>
5062 </label>
5063 </td>
5064 </tr>
5065 <?php
5066 $pw_policy = wp_parse_args(
5067 ( isset( $options['password_policy'] ) && is_array( $options['password_policy'] ) ) ? $options['password_policy'] : array(),
5068 array(
5069 'require_uppercase' => false,
5070 'require_lowercase' => false,
5071 'require_number' => false,
5072 'require_special' => false,
5073 'block_common' => true,
5074 'block_username' => true,
5075 'affected_roles' => array(),
5076 )
5077 );
5078 $pw_policy_roles = (array) $pw_policy['affected_roles'];
5079 ?>
5080 <tr>
5081 <th scope="row"><?php esc_html_e( 'Enforce Strong Passwords', 'vigilante' ); ?></th>
5082 <td>
5083 <label>
5084 <input type="checkbox" name="user_security[force_strong_passwords]" value="1" <?php checked( ! empty( $options['force_strong_passwords'] ) ); ?>>
5085 <?php esc_html_e( 'Check passwords against the requirements below when a user sets or changes one', 'vigilante' ); ?>
5086 </label>
5087 </td>
5088 </tr>
5089 <tr>
5090 <th scope="row"><label for="vigilante-f-user-security-min-password-length"><?php esc_html_e( 'Minimum Password Length', 'vigilante' ); ?></label></th>
5091 <td>
5092 <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">
5093 <?php esc_html_e( 'characters', 'vigilante' ); ?>
5094 </td>
5095 </tr>
5096 <tr>
5097 <th scope="row"><?php esc_html_e( 'Password Requirements', 'vigilante' ); ?></th>
5098 <td>
5099 <label style="display:block;margin-bottom:5px;">
5100 <input type="checkbox" name="user_security[password_policy][require_uppercase]" value="1" <?php checked( ! empty( $pw_policy['require_uppercase'] ) ); ?>>
5101 <?php esc_html_e( 'Require an uppercase letter (A-Z)', 'vigilante' ); ?>
5102 </label>
5103 <label style="display:block;margin-bottom:5px;">
5104 <input type="checkbox" name="user_security[password_policy][require_lowercase]" value="1" <?php checked( ! empty( $pw_policy['require_lowercase'] ) ); ?>>
5105 <?php esc_html_e( 'Require a lowercase letter (a-z)', 'vigilante' ); ?>
5106 </label>
5107 <label style="display:block;margin-bottom:5px;">
5108 <input type="checkbox" name="user_security[password_policy][require_number]" value="1" <?php checked( ! empty( $pw_policy['require_number'] ) ); ?>>
5109 <?php esc_html_e( 'Require a number (0-9)', 'vigilante' ); ?>
5110 </label>
5111 <label style="display:block;margin-bottom:5px;">
5112 <input type="checkbox" name="user_security[password_policy][require_special]" value="1" <?php checked( ! empty( $pw_policy['require_special'] ) ); ?>>
5113 <?php esc_html_e( 'Require a special character (!, @, #, ...)', 'vigilante' ); ?>
5114 </label>
5115 <label style="display:block;margin-bottom:5px;">
5116 <input type="checkbox" name="user_security[password_policy][block_common]" value="1" <?php checked( ! empty( $pw_policy['block_common'] ) ); ?>>
5117 <?php esc_html_e( 'Reject well-known common passwords', 'vigilante' ); ?>
5118 </label>
5119 <label style="display:block;margin-bottom:5px;">
5120 <input type="checkbox" name="user_security[password_policy][block_username]" value="1" <?php checked( ! empty( $pw_policy['block_username'] ) ); ?>>
5121 <?php esc_html_e( 'Do not allow the username inside the password', 'vigilante' ); ?>
5122 </label>
5123 <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>
5124 </td>
5125 </tr>
5126 <tr>
5127 <th scope="row"><?php esc_html_e( 'Apply Password Rules To', 'vigilante' ); ?></th>
5128 <td>
5129 <?php $this->list_sentinel( 'user_security[password_policy][affected_roles]' ); ?>
5130 <?php foreach ( wp_roles()->get_names() as $role_slug => $role_name ) : ?>
5131 <label style="display:block;margin-bottom:5px;">
5132 <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 ) ); ?>>
5133 <?php echo esc_html( translate_user_role( $role_name ) ); ?>
5134 </label>
5135 <?php endforeach; ?>
5136 <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>
5137 </td>
5138 </tr>
5139 <tr id="field-block-author-scanning">
5140 <th scope="row"><?php esc_html_e( 'Block Author Scanning', 'vigilante' ); ?></th>
5141 <td>
5142 <label>
5143 <input type="checkbox" name="user_security[block_author_scanning]" value="1" <?php checked( ! empty( $options['block_author_scanning'] ) ); ?>>
5144 <?php esc_html_e( 'Prevent username discovery via ?author=N URLs', 'vigilante' ); ?>
5145 </label>
5146 </td>
5147 </tr>
5148 <tr>
5149 <th scope="row"><?php esc_html_e( 'Display Name Protection', 'vigilante' ); ?></th>
5150 <td>
5151 <label>
5152 <input type="checkbox" name="user_security[prevent_display_name_login_match]" value="1" <?php checked( ! empty( $options['prevent_display_name_login_match'] ) ); ?>>
5153 <?php esc_html_e( 'Prevent users from saving a display name that matches their login username', 'vigilante' ); ?>
5154 </label>
5155 <p class="description"><?php esc_html_e( 'The display name is publicly visible and should not reveal the login username.', 'vigilante' ); ?></p>
5156 </td>
5157 </tr>
5158 </table>
5159 </div>
5160
5161 <!-- Admin Monitoring -->
5162 <div id="vigilante-section-users-admin-monitoring" class="vigilante-settings-section">
5163 <h2>
5164 <?php esc_html_e( 'Admin monitoring', 'vigilante' ); ?>
5165 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5166 </h2>
5167 <p><?php esc_html_e( 'Receive email alerts when administrator accounts are modified. All events are always logged to the Security Audit.', 'vigilante' ); ?></p>
5168
5169 <table class="form-table">
5170 <tr>
5171 <th scope="row"><?php esc_html_e( 'New Administrator Alert', 'vigilante' ); ?></th>
5172 <td>
5173 <label>
5174 <input type="checkbox" name="user_security[admin_monitoring][alert_new_admin]" value="1" <?php checked( ! empty( $monitoring['alert_new_admin'] ) ); ?>>
5175 <?php esc_html_e( 'Send email alert when a new administrator account is created', 'vigilante' ); ?>
5176 </label>
5177 </td>
5178 </tr>
5179 <tr>
5180 <th scope="row"><?php esc_html_e( 'Admin Email Change Alert', 'vigilante' ); ?></th>
5181 <td>
5182 <label>
5183 <input type="checkbox" name="user_security[admin_monitoring][alert_admin_email_change]" value="1" <?php checked( ! empty( $monitoring['alert_admin_email_change'] ) ); ?>>
5184 <?php esc_html_e( 'Send email alert when an administrator email address is changed', 'vigilante' ); ?>
5185 </label>
5186 </td>
5187 </tr>
5188 <tr>
5189 <th scope="row"><?php esc_html_e( 'Permission Elevation Alert', 'vigilante' ); ?></th>
5190 <td>
5191 <label>
5192 <input type="checkbox" name="user_security[admin_monitoring][alert_permission_elevation]" value="1" <?php checked( ! empty( $monitoring['alert_permission_elevation'] ) ); ?>>
5193 <?php esc_html_e( 'Send email alert when a user is elevated to administrator role', 'vigilante' ); ?>
5194 </label>
5195 </td>
5196 </tr>
5197 <tr>
5198 <th scope="row"><?php esc_html_e( 'Admin Password Change Alert', 'vigilante' ); ?></th>
5199 <td>
5200 <label>
5201 <input type="checkbox" name="user_security[admin_monitoring][alert_admin_password_change]" value="1" <?php checked( ! empty( $monitoring['alert_admin_password_change'] ) ); ?>>
5202 <?php esc_html_e( 'Send email alert when an administrator password is changed', 'vigilante' ); ?>
5203 </label>
5204 </td>
5205 </tr>
5206 </table>
5207
5208 <p class="description">
5209 <?php
5210 printf(
5211 /* translators: %s: Link to notification settings */
5212 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
5213 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
5214 );
5215 ?>
5216 </p>
5217 </div>
5218
5219 <!-- Registration Approval -->
5220 <div id="vigilante-section-users-registration" class="vigilante-settings-section">
5221 <h2>
5222 <?php esc_html_e( 'Registration approval', 'vigilante' ); ?>
5223 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5224 </h2>
5225 <p><?php esc_html_e( 'Require manual approval for new user registrations.', 'vigilante' ); ?></p>
5226
5227 <table class="form-table">
5228 <tr>
5229 <th scope="row"><?php esc_html_e( 'Enable Registration Approval', 'vigilante' ); ?></th>
5230 <td>
5231 <label>
5232 <input type="checkbox" name="user_security[registration_approval][enabled]" value="1" <?php checked( ! empty( $registration['enabled'] ) ); ?>>
5233 <?php esc_html_e( 'New users must be approved by an administrator before they can log in', 'vigilante' ); ?>
5234 </label>
5235 </td>
5236 </tr>
5237 <tr>
5238 <th scope="row"><?php esc_html_e( 'Notify Admin', 'vigilante' ); ?></th>
5239 <td>
5240 <label>
5241 <input type="checkbox" name="user_security[registration_approval][notify_admin]" value="1" <?php checked( ! empty( $registration['notify_admin'] ) ); ?>>
5242 <?php esc_html_e( 'Send email notification when a new user registers', 'vigilante' ); ?>
5243 </label>
5244 <p class="description"><?php esc_html_e( 'Disable on high-traffic sites to avoid email overload.', 'vigilante' ); ?></p>
5245 </td>
5246 </tr>
5247 <tr>
5248 <th scope="row"><label for="vigilante-f-user-security-registration-approval-auto-reject-days"><?php esc_html_e( 'Auto-reject After', 'vigilante' ); ?></label></th>
5249 <td>
5250 <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">
5251 <?php esc_html_e( 'days (0 = never)', 'vigilante' ); ?>
5252 <p class="description"><?php esc_html_e( 'Automatically reject pending registrations after this many days.', 'vigilante' ); ?></p>
5253 </td>
5254 </tr>
5255 </table>
5256 </div>
5257
5258 <!-- Session Limits -->
5259 <div id="vigilante-section-users-sessions" class="vigilante-settings-section">
5260 <h2>
5261 <?php esc_html_e( 'Session limits', 'vigilante' ); ?>
5262 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5263 </h2>
5264 <p><?php esc_html_e( 'Limit the number of simultaneous sessions per user.', 'vigilante' ); ?></p>
5265
5266 <?php if ( Vigilante_User_Security::session_limit_is_network_wide() ) : ?>
5267 <div class="notice notice-warning inline">
5268 <p>
5269 <?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' ); ?>
5270 </p>
5271 </div>
5272 <?php endif; ?>
5273
5274 <table class="form-table">
5275 <tr>
5276 <th scope="row"><?php esc_html_e( 'Enable Session Limits', 'vigilante' ); ?></th>
5277 <td>
5278 <label>
5279 <input type="checkbox" name="user_security[session_limits][enabled]" value="1" <?php checked( ! empty( $session_limits['enabled'] ) ); ?>>
5280 <?php esc_html_e( 'Limit the number of active sessions per user', 'vigilante' ); ?>
5281 </label>
5282 </td>
5283 </tr>
5284 <tr>
5285 <th scope="row"><label for="vigilante-f-user-security-session-limits-max-sessions"><?php esc_html_e( 'Maximum Sessions', 'vigilante' ); ?></label></th>
5286 <td>
5287 <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">
5288 <?php esc_html_e( 'sessions per user', 'vigilante' ); ?>
5289 </td>
5290 </tr>
5291 <tr>
5292 <th scope="row"><label for="vigilante-f-user-security-session-limits-behavior"><?php esc_html_e( 'When Limit Exceeded', 'vigilante' ); ?></label></th>
5293 <td>
5294 <select id="vigilante-f-user-security-session-limits-behavior" name="user_security[session_limits][behavior]">
5295 <option value="block_new" <?php selected( ( $session_limits['behavior'] ?? 'close_oldest' ), 'block_new' ); ?>><?php esc_html_e( 'Block new login', 'vigilante' ); ?></option>
5296 <option value="close_oldest" <?php selected( ( $session_limits['behavior'] ?? 'close_oldest' ), 'close_oldest' ); ?>><?php esc_html_e( 'Close oldest session', 'vigilante' ); ?></option>
5297 </select>
5298 <p class="description"><?php esc_html_e( '"Close oldest" is recommended for security - ensures attackers cannot lock out legitimate users.', 'vigilante' ); ?></p>
5299 </td>
5300 </tr>
5301 <tr>
5302 <th scope="row"><?php esc_html_e( 'Exclude Administrators', 'vigilante' ); ?></th>
5303 <td>
5304 <label>
5305 <input type="checkbox" name="user_security[session_limits][exclude_admins]" value="1" <?php checked( ! empty( $session_limits['exclude_admins'] ) ); ?>>
5306 <?php esc_html_e( 'Do not apply session limits to administrators', 'vigilante' ); ?>
5307 </label>
5308 </td>
5309 </tr>
5310 </table>
5311 </div>
5312
5313 <!-- Password Expiration -->
5314 <div id="vigilante-section-users-password-exp" class="vigilante-settings-section">
5315 <h2>
5316 <?php esc_html_e( 'Password expiration', 'vigilante' ); ?>
5317 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5318 </h2>
5319 <p><?php esc_html_e( 'Force users to change their password periodically.', 'vigilante' ); ?></p>
5320
5321 <table class="form-table">
5322 <tr>
5323 <th scope="row"><?php esc_html_e( 'Enable Password Expiration', 'vigilante' ); ?></th>
5324 <td>
5325 <label>
5326 <input type="checkbox" name="user_security[password_expiration][enabled]" value="1" <?php checked( ! empty( $password_exp['enabled'] ) ); ?>>
5327 <?php esc_html_e( 'Force password change after a set number of days', 'vigilante' ); ?>
5328 </label>
5329 </td>
5330 </tr>
5331 <tr>
5332 <th scope="row"><label for="vigilante-f-user-security-password-expiration-expire-days"><?php esc_html_e( 'Expire After', 'vigilante' ); ?></label></th>
5333 <td>
5334 <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">
5335 <?php esc_html_e( 'days', 'vigilante' ); ?>
5336 <p class="description"><?php esc_html_e( 'PCI-DSS recommends 90 days.', 'vigilante' ); ?></p>
5337 </td>
5338 </tr>
5339 <tr>
5340 <th scope="row"><label for="vigilante-f-user-security-password-expiration-warning-days"><?php esc_html_e( 'Warning Period', 'vigilante' ); ?></label></th>
5341 <td>
5342 <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">
5343 <?php esc_html_e( 'days before expiration', 'vigilante' ); ?>
5344 <p class="description"><?php esc_html_e( 'Show warning notice this many days before password expires.', 'vigilante' ); ?></p>
5345 </td>
5346 </tr>
5347 <tr>
5348 <th scope="row"><label for="vigilante-f-user-security-password-expiration-password-history"><?php esc_html_e( 'Password History', 'vigilante' ); ?></label></th>
5349 <td>
5350 <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">
5351 <?php esc_html_e( 'passwords to remember', 'vigilante' ); ?>
5352 <p class="description"><?php esc_html_e( 'Prevent reusing recent passwords. Set to 0 to disable.', 'vigilante' ); ?></p>
5353 </td>
5354 </tr>
5355 <tr>
5356 <th scope="row"><?php esc_html_e( 'Email Reminder', 'vigilante' ); ?></th>
5357 <td>
5358 <label>
5359 <input type="checkbox" name="user_security[password_expiration][send_reminder]" value="1" <?php checked( ! empty( $password_exp['send_reminder'] ) ); ?>>
5360 <?php esc_html_e( 'Send email reminder when password is about to expire', 'vigilante' ); ?>
5361 </label>
5362 <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>
5363 </td>
5364 </tr>
5365 <tr>
5366 <th scope="row"><?php esc_html_e( 'Affected Roles', 'vigilante' ); ?></th>
5367 <td>
5368 <?php
5369 $affected_roles = $password_exp['affected_roles'] ?? array( 'administrator', 'editor' );
5370 $all_roles = wp_roles()->get_names();
5371 $this->list_sentinel( 'user_security[password_expiration][affected_roles]' );
5372 foreach ( $all_roles as $role_slug => $role_name ) :
5373 ?>
5374 <label style="display: block; margin-bottom: 5px;">
5375 <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 ) ); ?>>
5376 <?php echo esc_html( translate_user_role( $role_name ) ); ?>
5377 </label>
5378 <?php endforeach; ?>
5379 </td>
5380 </tr>
5381 <tr>
5382 <th scope="row"><?php esc_html_e( 'Exclude specific users', 'vigilante' ); ?></th>
5383 <td>
5384 <?php $pwexp_excluded = $password_exp['excluded_users'] ?? array(); ?>
5385 <div class="vigilante-2fa-user-search-container">
5386 <div class="vigilante-2fa-user-search">
5387 <span class="search-icon"></span>
5388 <input type="text"
5389 id="vigilante_pwexp_user_search"
5390 placeholder="<?php esc_attr_e( 'Search users by name or email...', 'vigilante' ); ?>"
5391 autocomplete="off">
5392 <div class="vigilante-pwexp-search-results"></div>
5393 </div>
5394 <div class="vigilante-pwexp-excluded-users">
5395 <?php $this->list_sentinel( 'user_security[password_expiration][excluded_users]' ); ?>
5396 <?php
5397 foreach ( $pwexp_excluded as $pwexp_excluded_id ) :
5398 $excluded_user = get_user_by( 'ID', $pwexp_excluded_id );
5399 if ( ! $excluded_user ) {
5400 continue;
5401 }
5402 ?>
5403 <div class="vigilante-pwexp-excluded-user" data-user-id="<?php echo esc_attr( $pwexp_excluded_id ); ?>">
5404 <span class="user-display"><?php echo esc_html( $excluded_user->display_name . ' (' . $excluded_user->user_email . ')' ); ?></span>
5405 <button type="button" class="remove-user" aria-label="<?php esc_attr_e( 'Remove', 'vigilante' ); ?>">&times;</button>
5406 <input type="hidden" name="user_security[password_expiration][excluded_users][]" value="<?php echo esc_attr( $pwexp_excluded_id ); ?>">
5407 </div>
5408 <?php endforeach; ?>
5409 </div>
5410 </div>
5411 <p class="description"><?php esc_html_e( 'Listed users will be excluded from password expiration regardless of their role.', 'vigilante' ); ?></p>
5412 </td>
5413 </tr>
5414 </table>
5415 </div>
5416
5417 <!-- Email Verification -->
5418 <div id="vigilante-section-users-email-verify" class="vigilante-settings-section">
5419 <h2>
5420 <?php esc_html_e( 'Email verification', 'vigilante' ); ?>
5421 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5422 </h2>
5423 <p><?php esc_html_e( 'Require new users to verify their email address before logging in.', 'vigilante' ); ?></p>
5424
5425 <table class="form-table">
5426 <tr>
5427 <th scope="row"><?php esc_html_e( 'Enable Email Verification', 'vigilante' ); ?></th>
5428 <td>
5429 <label>
5430 <input type="checkbox" name="user_security[email_verification][enabled]" value="1" <?php checked( ! empty( $email_verify['enabled'] ) ); ?>>
5431 <?php esc_html_e( 'New users must verify their email before logging in', 'vigilante' ); ?>
5432 </label>
5433 </td>
5434 </tr>
5435 <tr>
5436 <th scope="row"><label for="vigilante-f-user-security-email-verification-token-expiry-hours"><?php esc_html_e( 'Link Expiration', 'vigilante' ); ?></label></th>
5437 <td>
5438 <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">
5439 <?php esc_html_e( 'hours', 'vigilante' ); ?>
5440 </td>
5441 </tr>
5442 <tr>
5443 <th scope="row"><?php esc_html_e( 'Allow Resend', 'vigilante' ); ?></th>
5444 <td>
5445 <label>
5446 <input type="checkbox" name="user_security[email_verification][allow_resend]" value="1" <?php checked( ! empty( $email_verify['allow_resend'] ) ); ?>>
5447 <?php esc_html_e( 'Allow users to request a new verification email', 'vigilante' ); ?>
5448 </label>
5449 </td>
5450 </tr>
5451 <tr>
5452 <th scope="row"><label for="vigilante-f-user-security-email-verification-auto-delete-days"><?php esc_html_e( 'Auto-delete Unverified', 'vigilante' ); ?></label></th>
5453 <td>
5454 <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">
5455 <?php esc_html_e( 'days (0 = never)', 'vigilante' ); ?>
5456 <p class="description"><?php esc_html_e( 'Automatically delete users who never verify their email.', 'vigilante' ); ?></p>
5457 </td>
5458 </tr>
5459 </table>
5460 </div>
5461
5462 <p class="submit vigilante-submit-buttons">
5463 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5464 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5465 </button>
5466 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5467 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5468 </button>
5469 </p>
5470 </form>
5471
5472 <!-- ============================================================
5473 TOOLS SECTION - Actions and utilities (no save button)
5474 ============================================================ -->
5475 <div class="vigilante-tools-section">
5476 <h2 class="vigilante-tools-header">
5477 <?php esc_html_e( 'User security tools', 'vigilante' ); ?>
5478 </h2>
5479
5480 <?php $this->render_user_actions_notice(); ?>
5481 <?php if ( ! $this->user_actions_locked() ) : ?>
5482
5483 <!-- Force Password Reset -->
5484 <div class="vigilante-tool-box">
5485 <h3><?php esc_html_e( 'Force password reset', 'vigilante' ); ?></h3>
5486 <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>
5487
5488 <!-- Reset Specific Users -->
5489 <div class="vigilante-password-reset-box">
5490 <h4><?php esc_html_e( 'Reset specific users', 'vigilante' ); ?></h4>
5491
5492 <div class="vigilante-user-search-wrapper">
5493 <input type="text" id="vigilante-password-reset-search" class="regular-text" placeholder="<?php esc_attr_e( 'Search by username, email, or display name...', 'vigilante' ); ?>">
5494 <div id="vigilante-password-reset-results" class="vigilante-user-search-results" style="display: none;"></div>
5495 </div>
5496
5497 <div id="vigilante-password-reset-selected" class="vigilante-selected-users" style="display: none;">
5498 <strong><?php esc_html_e( 'Selected Users:', 'vigilante' ); ?></strong>
5499 <ul class="vigilante-selected-users-list"></ul>
5500 </div>
5501
5502 <p class="description" style="margin-top: 15px;">
5503 <span class="dashicons dashicons-email-alt" style="color: #2271b1;"></span>
5504 <?php esc_html_e( 'Selected users will receive an email with a password reset link.', 'vigilante' ); ?>
5505 </p>
5506
5507 <p class="submit">
5508 <button type="button" id="vigilante-reset-selected-users" class="button button-primary" disabled>
5509 <?php esc_html_e( 'Force Reset for Selected Users', 'vigilante' ); ?>
5510 </button>
5511 </p>
5512 </div>
5513
5514 <!-- Reset by Role -->
5515 <div class="vigilante-password-reset-box" style="margin-top: 20px; padding-top: 20px; border-top: 1px solid #ddd;">
5516 <h4><?php esc_html_e( 'Reset by role', 'vigilante' ); ?></h4>
5517 <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>
5518
5519 <?php
5520 $wp_roles = wp_roles();
5521 $user_counts = count_users();
5522 $avail_roles = $user_counts['avail_roles'] ?? array();
5523 $current_user = wp_get_current_user();
5524 $current_roles = $current_user->roles;
5525 ?>
5526
5527 <fieldset class="vigilante-role-checkboxes" style="margin-top: 10px;">
5528 <?php foreach ( $wp_roles->roles as $role_slug => $role_data ) :
5529 $count = $avail_roles[ $role_slug ] ?? 0;
5530 if ( 0 === $count ) {
5531 continue;
5532 }
5533 $role_name = translate_user_role( $role_data['name'] );
5534 ?>
5535 <label style="display: block; margin-bottom: 6px;">
5536 <input type="checkbox"
5537 class="vigilante-reset-role-checkbox"
5538 value="<?php echo esc_attr( $role_slug ); ?>"
5539 data-count="<?php echo absint( $count ); ?>">
5540 <?php
5541 printf(
5542 /* translators: 1: Role name, 2: Number of users */
5543 '%1$s <span class="description">(%2$d)</span>',
5544 esc_html( $role_name ),
5545 absint( $count )
5546 );
5547 ?>
5548 <?php if ( in_array( $role_slug, $current_roles, true ) ) : ?>
5549 <em class="description"><?php esc_html_e( '(includes you)', 'vigilante' ); ?></em>
5550 <?php endif; ?>
5551 </label>
5552 <?php endforeach; ?>
5553 </fieldset>
5554
5555 <div id="vigilante-reset-role-summary" style="display: none; margin-top: 10px;">
5556 <p>
5557 <span class="dashicons dashicons-groups" style="color: #2271b1;"></span>
5558 <strong id="vigilante-reset-role-count">0</strong>
5559 <?php esc_html_e( 'user(s) will be affected.', 'vigilante' ); ?>
5560 </p>
5561 </div>
5562
5563 <div class="vigilante-password-reset-options" id="vigilante-reset-role-self-option" style="display: none; margin-top: 10px;">
5564 <label>
5565 <input type="checkbox" id="vigilante-reset-role-include-self" value="1">
5566 <?php esc_html_e( 'Include myself (your current session will end)', 'vigilante' ); ?>
5567 </label>
5568 </div>
5569
5570 <p class="submit">
5571 <button type="button" id="vigilante-reset-by-role" class="button button-primary" disabled>
5572 <?php esc_html_e( 'Force Reset for Selected Roles', 'vigilante' ); ?>
5573 </button>
5574 </p>
5575 </div>
5576
5577 <!-- Reset All Users -->
5578 <div class="vigilante-password-reset-box" style="margin-top: 20px; padding-top: 20px; border-top: 1px solid #ddd;">
5579 <h4><?php esc_html_e( 'Reset all users', 'vigilante' ); ?></h4>
5580
5581 <?php
5582 $total_users = count_users();
5583 $total_count = $total_users['total_users'];
5584 ?>
5585 <p>
5586 <?php
5587 printf(
5588 /* translators: %d: Number of users */
5589 esc_html__( 'This will affect %d user(s).', 'vigilante' ),
5590 absint( $total_count )
5591 );
5592 ?>
5593 </p>
5594
5595 <p class="description" style="color: #d63638;">
5596 <span class="dashicons dashicons-warning"></span>
5597 <?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' ); ?>
5598 </p>
5599
5600 <div class="vigilante-password-reset-options" style="margin-top: 10px;">
5601 <label>
5602 <input type="checkbox" id="vigilante-reset-all-include-self" value="1">
5603 <?php esc_html_e( 'Include myself (your current session will end)', 'vigilante' ); ?>
5604 </label>
5605 </div>
5606
5607 <p class="submit">
5608 <button type="button" id="vigilante-reset-all-users" class="button" style="color: #d63638; border-color: #d63638;">
5609 <?php esc_html_e( 'Force Reset for ALL Users', 'vigilante' ); ?>
5610 </button>
5611 </p>
5612 </div>
5613 </div>
5614
5615 <!-- Pending Registrations -->
5616 <?php
5617 // Enforcement-only: this instance exists to read the queue, and the
5618 // flag keeps it from registering the module's own hooks a second
5619 // time. It is not inert, and saying it was would be a false comment:
5620 // init_enforcement_hooks() does add its three filters again, on top
5621 // of the ones already registered. They are idempotent (the same
5622 // methods of an equivalent instance, deciding on the same user meta),
5623 // so running them twice in an admin request changes nothing, which is
5624 // why this is accepted rather than worked around.
5625 $user_security = new Vigilante_User_Security( $this->settings, $this->activity_log, true );
5626 $pending_users = $user_security->get_pending_users();
5627 ?>
5628 <div id="vigilante-section-users-pending" class="vigilante-tool-box vigilante-pending-users-section">
5629 <h3>
5630 <?php esc_html_e( 'Pending registrations', 'vigilante' ); ?>
5631 <?php if ( count( $pending_users ) > 0 ) : ?>
5632 <span class="vigilante-badge vigilante-badge-warning"><?php echo esc_html( count( $pending_users ) ); ?></span>
5633 <?php endif; ?>
5634 </h3>
5635
5636 <?php
5637 /*
5638 * The queue is shown whenever there is somebody in it, even with
5639 * the feature off. Since 2.11.10 an account already waiting stays
5640 * blocked when the feature is switched off, which is the point:
5641 * turning a setting off must not quietly let in people an
5642 * administrator decided not to approve. But hiding the table then
5643 * left them locked out with no button anywhere to approve or
5644 * reject them. Found by the cross review of 2.11.10.
5645 */
5646 ?>
5647 <?php if ( empty( $registration['enabled'] ) && empty( $pending_users ) ) : ?>
5648 <p class="description">
5649 <span class="dashicons dashicons-info" style="color: #72aee6;"></span>
5650 <?php esc_html_e( 'Registration approval is disabled. Enable it in the settings above to require manual approval for new users.', 'vigilante' ); ?>
5651 </p>
5652 <?php elseif ( empty( $pending_users ) ) : ?>
5653 <div class="vigilante-no-lockouts">
5654 <span class="dashicons dashicons-yes-alt"></span>
5655 <p><?php esc_html_e( 'No pending registrations.', 'vigilante' ); ?></p>
5656 </div>
5657 <?php else : ?>
5658 <?php $this->render_user_actions_notice(); ?>
5659 <table class="wp-list-table widefat fixed striped vigilante-pending-users-table">
5660 <thead>
5661 <tr>
5662 <th><?php esc_html_e( 'User', 'vigilante' ); ?></th>
5663 <th><?php esc_html_e( 'Email', 'vigilante' ); ?></th>
5664 <th><?php esc_html_e( 'Registered', 'vigilante' ); ?></th>
5665 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5666 </tr>
5667 </thead>
5668 <tbody>
5669 <?php foreach ( $pending_users as $pending_user ) :
5670 $pending_since = get_user_meta( $pending_user->ID, Vigilante_User_Security::site_user_meta_key( 'vigilante_pending_since' ), true );
5671 ?>
5672 <tr data-user-id="<?php echo esc_attr( $pending_user->ID ); ?>">
5673 <td>
5674 <?php echo get_avatar( $pending_user->ID, 32 ); ?>
5675 <strong><?php echo esc_html( $pending_user->user_login ); ?></strong>
5676 </td>
5677 <td><?php echo esc_html( $pending_user->user_email ); ?></td>
5678 <td>
5679 <?php
5680 if ( $pending_since ) {
5681 /* translators: %s: Time ago */
5682 printf( esc_html__( '%s ago', 'vigilante' ), esc_html( human_time_diff( $pending_since ) ) );
5683 } else {
5684 echo esc_html( $pending_user->user_registered );
5685 }
5686 ?>
5687 </td>
5688 <td>
5689 <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() ); ?>>
5690 <?php esc_html_e( 'Approve', 'vigilante' ); ?>
5691 </button>
5692 <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() ); ?>>
5693 <?php esc_html_e( 'Reject', 'vigilante' ); ?>
5694 </button>
5695 </td>
5696 </tr>
5697 <?php endforeach; ?>
5698 </tbody>
5699 </table>
5700 <?php endif; ?>
5701 </div>
5702
5703 <!-- Active Sessions Management -->
5704 <div class="vigilante-tool-box vigilante-session-management-section">
5705 <h3><?php esc_html_e( 'Active sessions', 'vigilante' ); ?></h3>
5706 <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>
5707
5708 <!-- Current user sessions -->
5709 <h4><?php esc_html_e( 'Your sessions', 'vigilante' ); ?></h4>
5710 <?php
5711 $current_user_id = get_current_user_id();
5712 $my_sessions = $user_security->get_user_sessions( $current_user_id );
5713 $has_corrupted = $user_security->has_corrupted_sessions( $current_user_id );
5714 $raw_count = $user_security->get_raw_session_count( $current_user_id );
5715 ?>
5716
5717 <?php if ( $has_corrupted && $raw_count > 0 ) : ?>
5718 <div class="notice notice-warning inline" style="margin: 10px 0;">
5719 <p>
5720 <span class="dashicons dashicons-warning" style="color: #dba617;"></span>
5721 <?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' ); ?>
5722 </p>
5723 </div>
5724 <?php endif; ?>
5725
5726 <?php if ( empty( $my_sessions ) ) : ?>
5727 <p class="description"><?php esc_html_e( 'No active sessions found.', 'vigilante' ); ?></p>
5728 <?php if ( $has_corrupted ) : ?>
5729 <p style="margin-top: 10px;">
5730 <button type="button" class="button vigilante-revoke-other-sessions" data-user-id="<?php echo esc_attr( $current_user_id ); ?>">
5731 <?php esc_html_e( 'Clean Up Corrupted Sessions', 'vigilante' ); ?>
5732 </button>
5733 </p>
5734 <?php endif; ?>
5735 <?php else : ?>
5736 <div class="vigilante-paginated-section">
5737 <div class="vigilante-fi-pagination-wrap"></div>
5738 <table class="wp-list-table widefat fixed striped vigilante-sessions-table vigilante-fi-paginated">
5739 <thead>
5740 <tr>
5741 <th><?php esc_html_e( 'Browser', 'vigilante' ); ?></th>
5742 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
5743 <th><?php esc_html_e( 'Login Time', 'vigilante' ); ?></th>
5744 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5745 </tr>
5746 </thead>
5747 <tbody>
5748 <?php foreach ( $my_sessions as $session ) : ?>
5749 <tr data-token="<?php echo esc_attr( $session['token_hash'] ); ?>">
5750 <td><?php echo esc_html( $session['browser'] ); ?></td>
5751 <td><code><?php echo esc_html( $session['ip'] ); ?></code></td>
5752 <td>
5753 <?php
5754 if ( $session['login'] ) {
5755 /* translators: %s: Time ago */
5756 printf( esc_html__( '%s ago', 'vigilante' ), esc_html( human_time_diff( $session['login'] ) ) );
5757 } else {
5758 esc_html_e( 'Unknown', 'vigilante' );
5759 }
5760 ?>
5761 </td>
5762 <td>
5763 <?php if ( ! $session['is_current'] ) : ?>
5764 <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'] ); ?>">
5765 <?php esc_html_e( 'Revoke', 'vigilante' ); ?>
5766 </button>
5767 <?php else : ?>
5768 <span class="description"><?php esc_html_e( 'Current session', 'vigilante' ); ?></span>
5769 <?php endif; ?>
5770 </td>
5771 </tr>
5772 <?php endforeach; ?>
5773 </tbody>
5774 </table>
5775 </div>
5776
5777 <?php if ( count( $my_sessions ) > 1 || $has_corrupted ) : ?>
5778 <p style="margin-top: 10px;">
5779 <button type="button" class="button vigilante-revoke-other-sessions" data-user-id="<?php echo esc_attr( $current_user_id ); ?>">
5780 <?php esc_html_e( 'Revoke All Other Sessions', 'vigilante' ); ?>
5781 </button>
5782 </p>
5783 <?php endif; ?>
5784 <?php endif; ?>
5785
5786 <!-- Search user sessions (admin only) -->
5787 <h4 style="margin-top: 30px;"><?php esc_html_e( 'Manage user sessions', 'vigilante' ); ?></h4>
5788 <p class="description"><?php esc_html_e( 'Search for a user to view and manage their sessions.', 'vigilante' ); ?></p>
5789
5790 <div class="vigilante-user-search-wrapper" style="margin-top: 10px;">
5791 <input type="text" id="vigilante-session-user-search" class="regular-text" placeholder="<?php esc_attr_e( 'Search by username or email...', 'vigilante' ); ?>">
5792 <div id="vigilante-session-search-results" class="vigilante-user-search-results" style="display: none;"></div>
5793 </div>
5794
5795 <div id="vigilante-user-sessions-container" style="display: none; margin-top: 20px;">
5796 <h4 id="vigilante-sessions-user-name"></h4>
5797 <table class="wp-list-table widefat fixed striped vigilante-sessions-table">
5798 <thead>
5799 <tr>
5800 <th><?php esc_html_e( 'Browser', 'vigilante' ); ?></th>
5801 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
5802 <th><?php esc_html_e( 'Login Time', 'vigilante' ); ?></th>
5803 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5804 </tr>
5805 </thead>
5806 <tbody id="vigilante-user-sessions-list">
5807 </tbody>
5808 </table>
5809 <p style="margin-top: 10px;">
5810 <button type="button" class="button vigilante-revoke-all-user-sessions" style="color: #d63638;">
5811 <?php esc_html_e( 'Revoke All Sessions', 'vigilante' ); ?>
5812 </button>
5813 </p>
5814 </div>
5815 </div>
5816
5817 <?php endif; ?>
5818 </div>
5819 <?php
5820 }
5821
5822 /**
5823 * Render WordPress Hardening tab
5824 */
5825 private function render_tab_wp_hardening() {
5826 $is_disabled = $this->render_module_disabled_notice( 'wp_hardening' );
5827 $options = $this->settings->get_section( 'wp_hardening' );
5828 ?>
5829 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="wp_hardening" <?php echo $is_disabled ? 'inert' : ''; ?>>
5830 <!-- Database Hardening (outside form save flow - uses its own AJAX action) -->
5831 <?php $vg_shared_locked = $this->shared_files_locked(); ?>
5832 <?php $this->render_shared_files_notice(); ?>
5833 <div id="vigilante-section-hardening-database" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
5834 <h2>
5835 <?php esc_html_e( 'Database Hardening', 'vigilante' ); ?>
5836 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
5837 <span class="vigilante-method-badge config"><?php esc_html_e( 'WP-CONFIG', 'vigilante' ); ?></span>
5838 </h2>
5839 <p><?php esc_html_e( 'Change the database table prefix to prevent SQL injection attacks that target default WordPress tables.', 'vigilante' ); ?></p>
5840
5841 <?php
5842 $db_prefix = new Vigilante_Database_Prefix();
5843 $current_prefix = $db_prefix->get_current_prefix();
5844 $is_default = $db_prefix->is_default_prefix();
5845 ?>
5846
5847 <?php if ( is_multisite() && ! $vg_shared_locked ) : ?>
5848 <div class="notice notice-warning inline" style="margin:10px 0 16px;padding:8px 12px;">
5849 <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>
5850 </div>
5851 <?php endif; ?>
5852
5853 <table class="form-table">
5854 <tr>
5855 <th scope="row"><?php esc_html_e( 'Current prefix', 'vigilante' ); ?></th>
5856 <td>
5857 <code class="vigilante-db-current-prefix"><?php echo esc_html( $current_prefix ); ?></code>
5858 <?php if ( $is_default ) : ?>
5859 <span class="vigilante-inline-warning">
5860 <span class="dashicons dashicons-warning"></span>
5861 <?php esc_html_e( 'Default prefix detected. Changing it adds a layer of protection against automated SQL injection attacks.', 'vigilante' ); ?>
5862 </span>
5863 <?php else : ?>
5864 <span class="vigilante-inline-ok">
5865 <span class="dashicons dashicons-yes-alt"></span>
5866 <?php esc_html_e( 'Custom prefix in use.', 'vigilante' ); ?>
5867 </span>
5868 <?php endif; ?>
5869 </td>
5870 </tr>
5871 <tr>
5872 <th scope="row"><?php esc_html_e( 'New prefix', 'vigilante' ); ?></th>
5873 <td>
5874 <div class="vigilante-db-prefix-row">
5875 <code class="vigilante-db-new-prefix" id="vigilante-new-prefix"><?php echo esc_html( $db_prefix->generate_prefix() ); ?></code>
5876 <button type="button" class="button button-small vigilante-db-regenerate-prefix" title="<?php esc_attr_e( 'Generate new prefix', 'vigilante' ); ?>">
5877 <span class="dashicons dashicons-update"></span>
5878 </button>
5879 </div>
5880 </td>
5881 </tr>
5882 <tr>
5883 <th scope="row"></th>
5884 <td>
5885 <div class="vigilante-db-prefix-confirm">
5886 <label>
5887 <input type="checkbox" id="vigilante-prefix-backup-confirm">
5888 <?php esc_html_e( 'I understand this operation is irreversible and I have a current database backup', 'vigilante' ); ?>
5889 </label>
5890 <p class="description">
5891 <?php
5892 printf(
5893 /* translators: %s: Link to tools tab */
5894 esc_html__( 'Need a backup? %s first.', 'vigilante' ),
5895 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Download a database backup', 'vigilante' ) . '</a>'
5896 );
5897 ?>
5898 </p>
5899 </div>
5900 <button type="button" class="button button-primary vigilante-db-change-prefix" disabled data-original-text="<?php esc_attr_e( 'Change Database Prefix', 'vigilante' ); ?>">
5901 <?php esc_html_e( 'Change Database Prefix', 'vigilante' ); ?>
5902 </button>
5903 </td>
5904 </tr>
5905 </table>
5906 </div>
5907
5908 <!-- wp-config Security -->
5909 <?php
5910 $vg_shared_locked = $this->shared_files_locked();
5911 // Paint what is actually in force, not this site's unused copy.
5912 $vg_local_options = $options;
5913 $options = $this->get_section_for_display( 'wp_hardening' );
5914 ?>
5915 <?php $this->render_shared_files_notice(); ?>
5916 <div id="vigilante-section-hardening-wpconfig" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
5917 <h2>
5918 <?php esc_html_e( 'wp-config.php Security', 'vigilante' ); ?>
5919 <span class="vigilante-method-badge config"><?php esc_html_e( 'WP-CONFIG', 'vigilante' ); ?></span>
5920 </h2>
5921 <p><?php esc_html_e( 'Security constants added directly to wp-config.php file.', 'vigilante' ); ?></p>
5922
5923 <table class="form-table">
5924 <tr>
5925 <th scope="row"><?php esc_html_e( 'Disable File Editor', 'vigilante' ); ?></th>
5926 <td>
5927 <label>
5928 <input type="checkbox" name="wp_hardening[disallow_file_edit]" value="1" <?php checked( ! empty( $options['disallow_file_edit'] ) ); ?>>
5929 <?php esc_html_e( 'Disable plugin and theme editor in admin (DISALLOW_FILE_EDIT)', 'vigilante' ); ?>
5930 </label>
5931 </td>
5932 </tr>
5933 <tr>
5934 <th scope="row"><?php esc_html_e( 'Disable File Modifications', 'vigilante' ); ?></th>
5935 <td>
5936 <label>
5937 <input type="checkbox" name="wp_hardening[disallow_file_mods]" value="1" <?php checked( ! empty( $options['disallow_file_mods'] ) ); ?>>
5938 <?php esc_html_e( 'Disable all file modifications including updates (DISALLOW_FILE_MODS)', 'vigilante' ); ?>
5939 </label>
5940 <p class="description"><?php esc_html_e( '&#9888; Warning: This prevents automatic updates.', 'vigilante' ); ?></p>
5941 </td>
5942 </tr>
5943 <tr id="field-force-ssl-admin">
5944 <th scope="row"><?php esc_html_e( 'Force SSL Admin', 'vigilante' ); ?></th>
5945 <td>
5946 <label>
5947 <input type="checkbox" name="wp_hardening[force_ssl_admin]" value="1" <?php checked( ! empty( $options['force_ssl_admin'] ) ); ?>>
5948 <?php esc_html_e( 'Force HTTPS for admin area (FORCE_SSL_ADMIN)', 'vigilante' ); ?>
5949 </label>
5950 <p class="description"><?php esc_html_e( '&#9888; Warning: Only enable if your site fully supports HTTPS.', 'vigilante' ); ?></p>
5951 </td>
5952 </tr>
5953 <tr id="field-wp-debug">
5954 <th scope="row"><?php esc_html_e( 'Hide PHP errors from visitors', 'vigilante' ); ?></th>
5955 <td>
5956 <label>
5957 <input type="checkbox" name="wp_hardening[wp_debug]" value="1" <?php checked( ! empty( $options['wp_debug'] ) ); ?>>
5958 <?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' ); ?>
5959 </label>
5960 </td>
5961 </tr>
5962 <tr id="field-disable-wp-cron">
5963 <th scope="row"><?php esc_html_e( 'Disable WP Cron', 'vigilante' ); ?></th>
5964 <td>
5965 <label>
5966 <input type="checkbox" name="wp_hardening[disable_wp_cron]" value="1" <?php checked( ! empty( $options['disable_wp_cron'] ) ); ?>>
5967 <?php esc_html_e( 'Disable WordPress\'s page-view cron trigger (DISABLE_WP_CRON)', 'vigilante' ); ?>
5968 </label>
5969 <p class="description"><?php
5970 printf(
5971 /* translators: 1: opening <strong>, 2: closing </strong>, 3: opening <code>, 4: closing </code> */
5972 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' ),
5973 '<strong>',
5974 '</strong>',
5975 '<code>',
5976 '</code>'
5977 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
5978 ?></p>
5979 </td>
5980 </tr>
5981 </table>
5982 </div>
5983 <?php $options = $vg_local_options; ?>
5984
5985 <!-- Comment Security -->
5986 <div id="vigilante-section-hardening-xmlrpc" class="vigilante-settings-section">
5987 <h2>
5988 <?php esc_html_e( 'XML-RPC', 'vigilante' ); ?>
5989 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5990 </h2>
5991 <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>
5992
5993 <table class="form-table">
5994 <tr id="field-disable-xmlrpc">
5995 <th scope="row"><label for="vigilante-f-wp-hardening-xmlrpc-mode"><?php esc_html_e( 'XML-RPC access', 'vigilante' ); ?></label></th>
5996 <td>
5997 <?php $vig_xmlrpc_mode = Vigilante_Comment_Security::resolve_xmlrpc_mode( $this->settings ); ?>
5998 <select id="vigilante-f-wp-hardening-xmlrpc-mode" name="wp_hardening[xmlrpc_mode]">
5999 <option value="none" <?php selected( $vig_xmlrpc_mode, 'none' ); ?>>
6000 <?php esc_html_e( 'Leave XML-RPC enabled', 'vigilante' ); ?>
6001 </option>
6002 <option value="pingback" <?php selected( $vig_xmlrpc_mode, 'pingback' ); ?>>
6003 <?php esc_html_e( 'Block the pingback methods only', 'vigilante' ); ?>
6004 </option>
6005 <option value="full" <?php selected( $vig_xmlrpc_mode, 'full' ); ?>>
6006 <?php esc_html_e( 'Disable XML-RPC completely (recommended)', 'vigilante' ); ?>
6007 </option>
6008 </select>
6009 <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>
6010 </td>
6011 </tr>
6012 </table>
6013 </div>
6014
6015 <div id="vigilante-section-hardening-comments" class="vigilante-settings-section">
6016 <h2>
6017 <?php esc_html_e( 'Comment Security', 'vigilante' ); ?>
6018 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
6019 <span class="vigilante-method-badge settings"><?php esc_html_e( 'Settings', 'vigilante' ); ?></span>
6020 </h2>
6021 <p><?php esc_html_e( 'Comment protection using WordPress settings and PHP hooks.', 'vigilante' ); ?></p>
6022
6023 <table class="form-table">
6024 <tr>
6025 <th scope="row"><?php esc_html_e( 'Disable Pingbacks', 'vigilante' ); ?></th>
6026 <td>
6027 <label>
6028 <input type="checkbox" name="wp_hardening[disable_pingbacks]" value="1" <?php checked( ! empty( $options['disable_pingbacks'] ) ); ?>>
6029 <?php esc_html_e( 'Disable pingbacks (commonly exploited for DDoS)', 'vigilante' ); ?>
6030 </label>
6031 </td>
6032 </tr>
6033 <tr>
6034 <th scope="row"><?php esc_html_e( 'Disable Trackbacks', 'vigilante' ); ?></th>
6035 <td>
6036 <label>
6037 <input type="checkbox" name="wp_hardening[disable_trackbacks]" value="1" <?php checked( ! empty( $options['disable_trackbacks'] ) ); ?>>
6038 <?php esc_html_e( 'Disable trackbacks (rarely used legitimately)', 'vigilante' ); ?>
6039 </label>
6040 </td>
6041 </tr>
6042 <tr>
6043 <th scope="row"><?php esc_html_e( 'Require Moderation', 'vigilante' ); ?></th>
6044 <td>
6045 <label>
6046 <input type="checkbox" name="wp_hardening[require_comment_moderation]" value="1" <?php checked( ! empty( $options['require_comment_moderation'] ) ); ?>>
6047 <?php esc_html_e( 'All comments must be manually approved', 'vigilante' ); ?>
6048 </label>
6049 </td>
6050 </tr>
6051 <tr>
6052 <th scope="row"><?php esc_html_e( 'Close Old Comments', 'vigilante' ); ?></th>
6053 <td>
6054 <label>
6055 <input type="checkbox" name="wp_hardening[close_old_comments]" value="1" <?php checked( ! empty( $options['close_old_comments'] ) ); ?>>
6056 <?php esc_html_e( 'Automatically close comments on old posts after', 'vigilante' ); ?>
6057 </label>
6058 <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">
6059 <label for="vigilante-f-wp-hardening-close-comments-after-days"><?php esc_html_e( 'days', 'vigilante' ); ?></label>
6060 </td>
6061 </tr>
6062 <tr>
6063 <th scope="row"><?php esc_html_e( 'Honeypot Protection', 'vigilante' ); ?></th>
6064 <td>
6065 <label>
6066 <input type="checkbox" name="wp_hardening[honeypot_comments]" value="1" <?php checked( ! empty( $options['honeypot_comments'] ) ); ?>>
6067 <?php esc_html_e( 'Add hidden honeypot field to catch bots', 'vigilante' ); ?>
6068 </label>
6069 </td>
6070 </tr>
6071 </table>
6072 </div>
6073
6074 <!-- Head Cleaner -->
6075 <div id="vigilante-section-hardening-headers" class="vigilante-settings-section">
6076 <h2>
6077 <?php esc_html_e( 'Header Cleanup', 'vigilante' ); ?>
6078 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
6079 </h2>
6080 <p><?php esc_html_e( 'Remove meta tags from HTML head.', 'vigilante' ); ?></p>
6081
6082 <table class="form-table">
6083 <tr>
6084 <th scope="row"><?php esc_html_e( 'Remove Generator', 'vigilante' ); ?></th>
6085 <td>
6086 <label>
6087 <input type="checkbox" name="wp_hardening[remove_wp_generator]" value="1" <?php checked( ! empty( $options['remove_wp_generator'] ) ); ?>>
6088 <?php esc_html_e( 'Remove WordPress version from HTML head', 'vigilante' ); ?>
6089 </label>
6090 </td>
6091 </tr>
6092 <tr id="field-remove-wp-version-assets">
6093 <th scope="row"><?php esc_html_e( 'Remove version from assets', 'vigilante' ); ?></th>
6094 <td>
6095 <label>
6096 <input type="checkbox" name="wp_hardening[remove_wp_version_assets]" value="1" <?php checked( ! empty( $options['remove_wp_version_assets'] ) ); ?>>
6097 <?php esc_html_e( 'Remove WordPress version from script/style URLs (?ver=)', 'vigilante' ); ?>
6098 </label>
6099 <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>
6100 </td>
6101 </tr>
6102 <tr>
6103 <th scope="row"><?php esc_html_e( 'Remove RSD Link', 'vigilante' ); ?></th>
6104 <td>
6105 <label>
6106 <input type="checkbox" name="wp_hardening[remove_rsd_link]" value="1" <?php checked( ! empty( $options['remove_rsd_link'] ) ); ?>>
6107 <?php esc_html_e( 'Remove Really Simple Discovery link', 'vigilante' ); ?>
6108 </label>
6109 </td>
6110 </tr>
6111 <tr>
6112 <th scope="row"><?php esc_html_e( 'Remove WLW Manifest', 'vigilante' ); ?></th>
6113 <td>
6114 <label>
6115 <input type="checkbox" name="wp_hardening[remove_wlw_manifest]" value="1" <?php checked( ! empty( $options['remove_wlw_manifest'] ) ); ?>>
6116 <?php esc_html_e( 'Remove Windows Live Writer manifest link', 'vigilante' ); ?>
6117 </label>
6118 </td>
6119 </tr>
6120 <tr>
6121 <th scope="row"><?php esc_html_e( 'Remove Shortlink', 'vigilante' ); ?></th>
6122 <td>
6123 <label>
6124 <input type="checkbox" name="wp_hardening[remove_shortlink]" value="1" <?php checked( ! empty( $options['remove_shortlink'] ) ); ?>>
6125 <?php esc_html_e( 'Remove shortlink tag from header', 'vigilante' ); ?>
6126 </label>
6127 </td>
6128 </tr>
6129 <tr>
6130 <th scope="row"><?php esc_html_e( 'Remove REST API Link', 'vigilante' ); ?></th>
6131 <td>
6132 <label>
6133 <input type="checkbox" name="wp_hardening[remove_rest_api_link]" value="1" <?php checked( ! empty( $options['remove_rest_api_link'] ) ); ?>>
6134 <?php esc_html_e( 'Remove REST API discovery link from header', 'vigilante' ); ?>
6135 </label>
6136 <p class="description"><?php esc_html_e( '&#9888; Notice: Some plugins may need this link.', 'vigilante' ); ?></p>
6137 </td>
6138 </tr>
6139 </table>
6140 </div>
6141
6142 <!-- Feed Manager -->
6143 <div id="vigilante-section-hardening-rss" class="vigilante-settings-section">
6144 <h2>
6145 <?php esc_html_e( 'RSS Feed Settings', 'vigilante' ); ?>
6146 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
6147 </h2>
6148 <p><?php esc_html_e( 'Control RSS/Atom feeds.', 'vigilante' ); ?></p>
6149
6150 <table class="form-table">
6151 <tr>
6152 <th scope="row"><?php esc_html_e( 'Disable Feeds', 'vigilante' ); ?></th>
6153 <td>
6154 <label>
6155 <input type="checkbox" name="wp_hardening[disable_feeds]" value="1" <?php checked( ! empty( $options['disable_feeds'] ) ); ?>>
6156 <?php esc_html_e( 'Completely disable RSS/Atom feeds', 'vigilante' ); ?>
6157 </label>
6158 </td>
6159 </tr>
6160 <tr>
6161 <th scope="row"><?php esc_html_e( 'Disable If No Content', 'vigilante' ); ?></th>
6162 <td>
6163 <label>
6164 <input type="checkbox" name="wp_hardening[disable_if_no_content]" value="1" <?php checked( ! empty( $options['disable_if_no_content'] ) ); ?>>
6165 <?php esc_html_e( 'Only disable feeds if site has no published posts', 'vigilante' ); ?>
6166 </label>
6167 </td>
6168 </tr>
6169 <tr>
6170 <th scope="row"><?php esc_html_e( 'Remove Feed Version', 'vigilante' ); ?></th>
6171 <td>
6172 <label>
6173 <input type="checkbox" name="wp_hardening[remove_feed_version]" value="1" <?php checked( ! empty( $options['remove_feed_version'] ) ); ?>>
6174 <?php esc_html_e( 'Remove WordPress version from feed generator tag', 'vigilante' ); ?>
6175 </label>
6176 </td>
6177 </tr>
6178 </table>
6179 </div>
6180
6181 <p class="submit vigilante-submit-buttons">
6182 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
6183 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
6184 </button>
6185 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
6186 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
6187 </button>
6188 </p>
6189 </form>
6190 <?php
6191 }
6192
6193 /**
6194 * Render activity log tab
6195 */
6196 private function render_tab_activity_log() {
6197 $is_disabled = $this->render_module_disabled_notice( 'activity_log' );
6198 $options = $this->settings->get_section( 'activity_log' );
6199 ?>
6200 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="activity_log" <?php echo $is_disabled ? 'inert' : ''; ?>>
6201 <div id="vigilante-section-audit-settings" class="vigilante-settings-section">
6202 <h2>
6203 <?php esc_html_e( 'Security Audit Settings', 'vigilante' ); ?>
6204 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
6205 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
6206 </h2>
6207 <p><?php esc_html_e( 'Security event logging and auditing.', 'vigilante' ); ?></p>
6208
6209 <table class="form-table">
6210 <tr>
6211 <th scope="row"><?php esc_html_e( 'Retention', 'vigilante' ); ?></th>
6212 <td>
6213 <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">
6214 <label for="vigilante-f-activity-log-retention-days"><?php esc_html_e( 'days', 'vigilante' ); ?></label>
6215 &nbsp;&nbsp;
6216 <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">
6217 <label for="vigilante-f-activity-log-max-entries"><?php esc_html_e( 'max entries', 'vigilante' ); ?></label>
6218 <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>
6219 </td>
6220 </tr>
6221 <tr>
6222 <th scope="row"><?php esc_html_e( 'Events to Log', 'vigilante' ); ?></th>
6223 <td>
6224 <fieldset style="display:grid; grid-template-columns:repeat(auto-fit, minmax(240px, 1fr)); gap:6px 24px; max-width:600px;">
6225 <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>
6226 <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>
6227 <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>
6228 <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>
6229 <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>
6230 <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>
6231 <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>
6232 <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>
6233 <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>
6234 <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>
6235 </fieldset>
6236 <div class="notice notice-info inline" style="margin:10px 0 0;padding:8px 12px;">
6237 <p style="margin:0;">
6238 <?php esc_html_e( 'Firewall blocks, security events, and Vigilant settings changes are always logged regardless of the above selections.', 'vigilante' ); ?>
6239 </p>
6240 </div>
6241 </td>
6242 </tr>
6243 <tr>
6244 <th scope="row"><label for="vigilante-f-activity-log-tracked-options"><?php esc_html_e( 'Option Tracking', 'vigilante' ); ?></label></th>
6245 <td>
6246 <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>
6247 <br>
6248 <label><?php esc_html_e( 'Additional options to track:', 'vigilante' ); ?></label><br>
6249 <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>
6250 <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>
6251 </td>
6252 </tr>
6253 <tr>
6254 <th scope="row"><?php esc_html_e( 'Exclusions', 'vigilante' ); ?></th>
6255 <td>
6256 <div style="display:grid; grid-template-columns:repeat(auto-fit, minmax(220px, 1fr)); gap:16px; max-width:600px;">
6257 <div>
6258 <label for="vigilante-f-activity-log-excluded-users"><?php esc_html_e( 'Excluded user IDs:', 'vigilante' ); ?></label><br>
6259 <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>
6260 <p class="description"><?php esc_html_e( 'One user ID per line. Actions by these users will not be logged.', 'vigilante' ); ?></p>
6261 </div>
6262 <div>
6263 <label for="vigilante-f-activity-log-excluded-ips"><?php esc_html_e( 'Excluded IPs:', 'vigilante' ); ?></label><br>
6264 <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>
6265 <p class="description"><?php esc_html_e( 'One IP per line. Requests from these IPs will not be logged.', 'vigilante' ); ?></p>
6266 </div>
6267 </div>
6268 </td>
6269 </tr>
6270 </table>
6271 </div>
6272
6273 <p class="submit vigilante-submit-buttons">
6274 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
6275 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
6276 </button>
6277 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
6278 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
6279 </button>
6280 </p>
6281 </form>
6282
6283 <?php
6284 // Audit Alerts — alerting layer on top of Security Audit. Its own
6285 // settings section and form, rendered right after the logging settings
6286 // so the tab reads as "log this, exclude that, and alert me about this".
6287 $alerts = $this->settings->get_section( 'audit_alerts' );
6288 $immediate = isset( $alerts['immediate'] ) ? $alerts['immediate'] : array();
6289 $threshold = isset( $alerts['threshold'] ) ? $alerts['threshold'] : array();
6290 $alert_severity = isset( $immediate['min_severity'] ) ? $immediate['min_severity'] : 'critical';
6291 $alert_window = isset( $threshold['window'] ) ? $threshold['window'] : '1h';
6292 $threshold_cats = isset( $threshold['categories'] ) ? (array) $threshold['categories'] : array();
6293 $cat_labels = Vigilante_Audit_Alerts::category_labels();
6294 ?>
6295 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="audit_alerts" <?php echo $is_disabled ? 'inert' : ''; ?>>
6296 <div id="vigilante-section-audit-alerts" class="vigilante-settings-section">
6297 <h2>
6298 <?php esc_html_e( 'Audit Alerts', 'vigilante' ); ?>
6299 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
6300 </h2>
6301 <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>
6302
6303 <table class="form-table">
6304 <tr id="field-audit-alerts-immediate">
6305 <th scope="row"><?php esc_html_e( 'Immediate alerts', 'vigilante' ); ?></th>
6306 <td>
6307 <label>
6308 <input type="checkbox" name="audit_alerts[immediate][enabled]" value="1" <?php checked( ! empty( $immediate['enabled'] ) ); ?>>
6309 <?php esc_html_e( 'Email me as soon as a serious event is logged', 'vigilante' ); ?>
6310 </label>
6311 <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>
6312 </td>
6313 </tr>
6314 <tr>
6315 <th scope="row"><label for="vigilante-f-audit-alerts-immediate-min-severity"><?php esc_html_e( 'Alert on severity', 'vigilante' ); ?></label></th>
6316 <td>
6317 <select id="vigilante-f-audit-alerts-immediate-min-severity" name="audit_alerts[immediate][min_severity]">
6318 <option value="critical" <?php selected( $alert_severity, 'critical' ); ?>><?php esc_html_e( 'Critical only (recommended)', 'vigilante' ); ?></option>
6319 <option value="warning" <?php selected( $alert_severity, 'warning' ); ?>><?php esc_html_e( 'Warning and Critical', 'vigilante' ); ?></option>
6320 </select>
6321 <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>
6322 </td>
6323 </tr>
6324 <tr id="field-audit-alerts-threshold">
6325 <th scope="row"><?php esc_html_e( 'Threshold alerts', 'vigilante' ); ?></th>
6326 <td>
6327 <label>
6328 <input type="checkbox" name="audit_alerts[threshold][enabled]" value="1" <?php checked( ! empty( $threshold['enabled'] ) ); ?>>
6329 <?php esc_html_e( 'Email me when a category spikes within a time window', 'vigilante' ); ?>
6330 </label>
6331 <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>
6332 </td>
6333 </tr>
6334 <tr>
6335 <th scope="row"><label for="vigilante-f-audit-alerts-threshold-window"><?php esc_html_e( 'Time window', 'vigilante' ); ?></label></th>
6336 <td>
6337 <select id="vigilante-f-audit-alerts-threshold-window" name="audit_alerts[threshold][window]">
6338 <option value="30m" <?php selected( $alert_window, '30m' ); ?>><?php esc_html_e( '30 minutes', 'vigilante' ); ?></option>
6339 <option value="1h" <?php selected( $alert_window, '1h' ); ?>><?php esc_html_e( '1 hour', 'vigilante' ); ?></option>
6340 <option value="6h" <?php selected( $alert_window, '6h' ); ?>><?php esc_html_e( '6 hours', 'vigilante' ); ?></option>
6341 <option value="24h" <?php selected( $alert_window, '24h' ); ?>><?php esc_html_e( '24 hours', 'vigilante' ); ?></option>
6342 </select>
6343 <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>
6344 </td>
6345 </tr>
6346 <tr>
6347 <th scope="row"><?php esc_html_e( 'Thresholds per category', 'vigilante' ); ?></th>
6348 <td>
6349 <fieldset style="display:grid; grid-template-columns:repeat(auto-fit, minmax(200px, 1fr)); gap:8px 24px; max-width:760px;">
6350 <?php
6351 foreach ( $cat_labels as $cat_slug => $cat_label ) :
6352 $cat_value = isset( $threshold_cats[ $cat_slug ] ) ? (int) $threshold_cats[ $cat_slug ] : 0;
6353 ?>
6354 <label style="display:flex;align-items:center;gap:8px;justify-content:space-between;">
6355 <span><?php echo esc_html( $cat_label ); ?></span>
6356 <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">
6357 </label>
6358 <?php endforeach; ?>
6359 </fieldset>
6360 <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>
6361 </td>
6362 </tr>
6363 <tr>
6364 <th scope="row"><?php esc_html_e( "Don't repeat alerts", 'vigilante' ); ?></th>
6365 <td>
6366 <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">
6367 <label for="vigilante-f-audit-alerts-cooldown-minutes"><?php esc_html_e( 'minutes', 'vigilante' ); ?></label>
6368 <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>
6369 </td>
6370 </tr>
6371
6372 <tr>
6373 <th scope="row"><?php esc_html_e( 'Recipients', 'vigilante' ); ?></th>
6374 <td>
6375 <p class="description" style="margin-top:0;">
6376 <?php
6377 printf(
6378 /* translators: %s: Link to notification settings */
6379 esc_html__( 'Alerts go to the recipients configured in %s.', 'vigilante' ),
6380 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
6381 );
6382 ?>
6383 </p>
6384 <p style="margin:8px 0 0;">
6385 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
6386 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
6387 </button>
6388 <span class="vigilante-test-email-result" style="margin-left:8px;"></span>
6389 </p>
6390 <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>
6391 </td>
6392 </tr>
6393 </table>
6394 </div>
6395
6396 <p class="submit vigilante-submit-buttons">
6397 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
6398 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
6399 </button>
6400 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
6401 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
6402 </button>
6403 </p>
6404 </form>
6405
6406 <div id="vigilante-section-audit-recent" class="vigilante-settings-section">
6407 <h2><?php esc_html_e( 'Recent Activity', 'vigilante' ); ?></h2>
6408
6409 <?php
6410 $logs = $this->activity_log->get_logs( array( 'per_page' => 20 ) );
6411 $total_logs = $this->activity_log->get_logs_count();
6412
6413 // Label maps for translated display
6414 $type_labels = array(
6415 'login' => __( 'Login', 'vigilante' ),
6416 'user' => __( 'User', 'vigilante' ),
6417 'content' => __( 'Content', 'vigilante' ),
6418 'plugin' => __( 'Plugin', 'vigilante' ),
6419 'theme' => __( 'Theme', 'vigilante' ),
6420 'settings' => __( 'Settings', 'vigilante' ),
6421 'comment' => __( 'Comment', 'vigilante' ),
6422 'media' => __( 'Media', 'vigilante' ),
6423 'firewall' => __( 'Firewall', 'vigilante' ),
6424 'file' => __( 'File', 'vigilante' ),
6425 'security' => __( 'Security', 'vigilante' ),
6426 'system' => __( 'System', 'vigilante' ),
6427 );
6428 $severity_labels = array(
6429 'info' => __( 'Info', 'vigilante' ),
6430 'warning' => __( 'Warning', 'vigilante' ),
6431 'critical' => __( 'Critical', 'vigilante' ),
6432 );
6433
6434 $firewall_options = $this->settings->get_section( 'firewall' );
6435 $ip_whitelist = $firewall_options['ip_whitelist'] ?? array();
6436 $ip_blacklist = $firewall_options['ip_blacklist'] ?? array();
6437 $ua_whitelist = $firewall_options['ua_whitelist'] ?? array();
6438 $ua_blacklist = $firewall_options['ua_blacklist'] ?? array();
6439 ?>
6440
6441 <div class="vigilante-log-filters">
6442 <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">
6443 <select id="vigilante-log-type-filter" aria-label="<?php esc_attr_e( 'Filter the log by event type', 'vigilante' ); ?>">
6444 <option value=""><?php esc_html_e( 'All Types', 'vigilante' ); ?></option>
6445 <option value="login"><?php esc_html_e( 'Login', 'vigilante' ); ?></option>
6446 <option value="user"><?php esc_html_e( 'User', 'vigilante' ); ?></option>
6447 <option value="content"><?php esc_html_e( 'Content', 'vigilante' ); ?></option>
6448 <option value="plugin"><?php esc_html_e( 'Plugin', 'vigilante' ); ?></option>
6449 <option value="theme"><?php esc_html_e( 'Theme', 'vigilante' ); ?></option>
6450 <option value="settings"><?php esc_html_e( 'Settings', 'vigilante' ); ?></option>
6451 <option value="comment"><?php esc_html_e( 'Comment', 'vigilante' ); ?></option>
6452 <option value="media"><?php esc_html_e( 'Media', 'vigilante' ); ?></option>
6453 <option value="firewall"><?php esc_html_e( 'Firewall', 'vigilante' ); ?></option>
6454 <option value="file"><?php esc_html_e( 'File', 'vigilante' ); ?></option>
6455 <option value="security"><?php esc_html_e( 'Security', 'vigilante' ); ?></option>
6456 <option value="system"><?php esc_html_e( 'System', 'vigilante' ); ?></option>
6457 </select>
6458 <select id="vigilante-log-severity-filter" aria-label="<?php esc_attr_e( 'Filter the log by severity', 'vigilante' ); ?>">
6459 <option value=""><?php esc_html_e( 'All Severities', 'vigilante' ); ?></option>
6460 <option value="info"><?php esc_html_e( 'Info', 'vigilante' ); ?></option>
6461 <option value="warning"><?php esc_html_e( 'Warning', 'vigilante' ); ?></option>
6462 <option value="critical"><?php esc_html_e( 'Critical', 'vigilante' ); ?></option>
6463 </select>
6464 <select id="vigilante-log-method-filter" aria-label="<?php esc_attr_e( 'Filter the log by HTTP method', 'vigilante' ); ?>">
6465 <option value=""><?php esc_html_e( 'All Methods', 'vigilante' ); ?></option>
6466 <option value="GET">GET</option>
6467 <option value="POST">POST</option>
6468 <option value="PUT">PUT</option>
6469 <option value="DELETE">DELETE</option>
6470 <option value="PATCH">PATCH</option>
6471 <option value="OPTIONS">OPTIONS</option>
6472 <option value="HEAD">HEAD</option>
6473 </select>
6474 <button type="button" id="vigilante-log-refresh" class="button"><?php esc_html_e( 'Refresh', 'vigilante' ); ?></button>
6475 <span class="vigilante-pagination" id="vigilante-log-pagination" data-total="<?php echo esc_attr( $total_logs ); ?>" data-per-page="20" data-page="1">
6476 <?php if ( $total_logs > 20 ) : ?>
6477 <button type="button" class="vigilante-page-first" title="<?php esc_attr_e( 'First page', 'vigilante' ); ?>" disabled>&laquo;</button>
6478 <button type="button" class="vigilante-page-prev" title="<?php esc_attr_e( 'Previous page', 'vigilante' ); ?>" disabled>&lsaquo;</button>
6479 <?php endif; ?>
6480 <span class="vigilante-page-info">
6481 <?php
6482 $showing = min( 20, $total_logs );
6483 printf(
6484 /* translators: 1: first item, 2: last item, 3: total items */
6485 esc_html__( '%1$d–%2$d of %3$d', 'vigilante' ),
6486 $total_logs > 0 ? 1 : 0,
6487 absint( $showing ),
6488 absint( $total_logs )
6489 );
6490 ?>
6491 </span>
6492 <?php if ( $total_logs > 20 ) : ?>
6493 <button type="button" class="vigilante-page-next" title="<?php esc_attr_e( 'Next page', 'vigilante' ); ?>">&rsaquo;</button>
6494 <button type="button" class="vigilante-page-last" title="<?php esc_attr_e( 'Last page', 'vigilante' ); ?>">&raquo;</button>
6495 <?php endif; ?>
6496 </span>
6497 </div>
6498
6499 <div class="vigilante-log-table-wrap">
6500 <table id="vigilante-activity-log-table" class="wp-list-table widefat striped">
6501 <thead>
6502 <tr>
6503 <th class="column-date"><?php esc_html_e( 'Date', 'vigilante' ); ?></th>
6504 <th class="column-type"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
6505 <th class="column-method"><?php esc_html_e( 'Method', 'vigilante' ); ?></th>
6506 <th class="column-severity"><?php esc_html_e( 'Severity', 'vigilante' ); ?></th>
6507 <th class="column-message"><?php esc_html_e( 'Message', 'vigilante' ); ?></th>
6508 <th class="column-user"><?php esc_html_e( 'User', 'vigilante' ); ?></th>
6509 <th class="column-ip"><?php esc_html_e( 'IP', 'vigilante' ); ?></th>
6510 <th class="column-details"><?php esc_html_e( 'Details', 'vigilante' ); ?></th>
6511 </tr>
6512 </thead>
6513 <tbody>
6514 <?php
6515 if ( empty( $logs ) ) :
6516 ?>
6517 <tr><td colspan="8"><?php esc_html_e( 'No log entries found.', 'vigilante' ); ?></td></tr>
6518 <?php else : ?>
6519 <?php foreach ( $logs as $log ) :
6520 $request_method = isset( $log->request_method ) ? $log->request_method : '';
6521 // Prepare details as a simple object
6522 $ip_val = (string) ( $log->ip_address ?? '' );
6523 $ua_val = (string) ( $log->user_agent ?? '' );
6524 $details = array(
6525 'id' => (int) $log->id,
6526 'type' => (string) ( $log->event_type ?? '' ),
6527 'action' => (string) ( $log->event_action ?? '' ),
6528 'message' => (string) ( $log->event_message ?? '' ),
6529 'user' => (string) ( $log->user_login ?? '' ),
6530 'ip' => $ip_val,
6531 'user_agent' => $ua_val,
6532 'request_method' => (string) $request_method,
6533 'request_uri' => Vigilante_Activity_Log::extract_request_uri( $log->extra_data ?? '' ),
6534 'date' => (string) ( $log->created_at ?? '' ),
6535 'severity' => (string) ( $log->severity ?? 'info' ),
6536 'is_ip_whitelisted' => ( '' !== $ip_val && in_array( $ip_val, $ip_whitelist, true ) ),
6537 'is_ip_blacklisted' => ( '' !== $ip_val && in_array( $ip_val, $ip_blacklist, true ) ),
6538 'is_ua_whitelisted' => ( '' !== $ua_val && in_array( $ua_val, $ua_whitelist, true ) ),
6539 'is_ua_blacklisted' => ( '' !== $ua_val && in_array( $ua_val, $ua_blacklist, true ) ),
6540 );
6541 // Self-protection entries carry what happened, what
6542 // it means and what to do, from the same catalogue
6543 // the File Integrity box uses.
6544 $vg_self_event = Vigilante_Self_Integrity_Guidance::for_log_event(
6545 (string) ( $log->event_action ?? '' ),
6546 $log->extra_data ?? '',
6547 (string) ( $log->severity ?? 'info' )
6548 );
6549 if ( null !== $vg_self_event ) {
6550 $details['self'] = $vg_self_event;
6551 }
6552 $display_type = isset( $type_labels[ $log->event_type ] ) ? $type_labels[ $log->event_type ] : $log->event_type;
6553 $display_severity = isset( $severity_labels[ $log->severity ] ) ? $severity_labels[ $log->severity ] : $log->severity;
6554 ?>
6555 <tr class="vigilante-severity-<?php echo esc_attr( $log->severity ); ?>">
6556 <td><?php echo esc_html( $log->created_at ); ?></td>
6557 <td><?php echo esc_html( $display_type ); ?></td>
6558 <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>
6559 <td><span class="vigilante-badge vigilante-badge-<?php echo esc_attr( $log->severity ); ?>"><?php echo esc_html( $display_severity ); ?></span></td>
6560 <td><?php echo esc_html( $log->event_message ); ?></td>
6561 <td><?php echo esc_html( $log->user_login ?? '-' ); ?></td>
6562 <td><code><?php echo esc_html( $log->ip_address ); ?></code></td>
6563 <td>
6564 <button type="button" class="button button-small vigilante-view-log-details"
6565 data-details='<?php echo esc_attr( wp_json_encode( $details, JSON_HEX_APOS | JSON_HEX_QUOT ) ); ?>'>
6566 <?php esc_html_e( 'View', 'vigilante' ); ?>
6567 </button>
6568 </td>
6569 </tr>
6570 <?php endforeach; ?>
6571 <?php endif; ?>
6572 </tbody>
6573 </table>
6574 </div>
6575
6576 <!-- Log Details Modal -->
6577 <div id="vigilante-log-details-modal" class="vigilante-modal" style="display: none;">
6578 <div class="vigilante-modal-content">
6579 <span class="vigilante-modal-close">&times;</span>
6580 <h3><?php esc_html_e( 'Log Entry Details', 'vigilante' ); ?></h3>
6581 <div id="vigilante-log-details-content"></div>
6582 </div>
6583 </div>
6584
6585 <p>
6586 <button type="button" class="button vigilante-export-logs"><?php esc_html_e( 'Export Audit Log', 'vigilante' ); ?></button>
6587 <button type="button" class="button vigilante-clear-logs" style="color: #a00;"><?php esc_html_e( 'Clear All Logs', 'vigilante' ); ?></button>
6588 </p>
6589 </div>
6590 <?php
6591 }
6592
6593 /**
6594 * Render File Integrity tab
6595 */
6596 /**
6597 * Findings of the self-check grouped by the case that explains them, worst
6598 * first: ten modified files are one case with ten paths, not ten copies of
6599 * the same explanation.
6600 *
6601 * @param array $findings Findings from the state.
6602 * @return array
6603 */
6604 private function self_findings_by_case( $findings ) {
6605 $groups = array();
6606 foreach ( (array) $findings as $finding ) {
6607 if ( ! is_array( $finding ) || 'info' === ( $finding['severity'] ?? '' ) ) {
6608 continue;
6609 }
6610 $guidance = Vigilante_Self_Integrity_Guidance::for_finding( $finding );
6611 $key = $guidance['key'];
6612 if ( ! isset( $groups[ $key ] ) ) {
6613 $guidance['files'] = array();
6614 $guidance['severity'] = 'warning';
6615 $groups[ $key ] = $guidance;
6616 }
6617 $file = isset( $finding['file'] ) ? (string) $finding['file'] : '';
6618 if ( '' !== $file && ! in_array( $file, $groups[ $key ]['files'], true ) ) {
6619 $groups[ $key ]['files'][] = $file;
6620 }
6621 if ( 'critical' === ( $finding['severity'] ?? '' ) ) {
6622 $groups[ $key ]['severity'] = 'critical';
6623 }
6624 }
6625 uasort(
6626 $groups,
6627 function ( $a, $b ) {
6628 $rank = array( 'critical' => 0, 'warning' => 1 );
6629 $ra = isset( $rank[ $a['severity'] ] ) ? $rank[ $a['severity'] ] : 2;
6630 $rb = isset( $rank[ $b['severity'] ] ) ? $rank[ $b['severity'] ] : 2;
6631 return $ra - $rb;
6632 }
6633 );
6634 return $groups;
6635 }
6636
6637 /**
6638 * Human label for the context that ran the last self-check.
6639 *
6640 * @param string $context Stored context.
6641 * @return string
6642 */
6643 private function self_context_label( $context ) {
6644 switch ( (string) $context ) {
6645 case 'scan':
6646 return __( 'during a file integrity scan', 'vigilante' );
6647 case 'upgrader':
6648 return __( 'right after updating Vigilant', 'vigilante' );
6649 case 'version_change':
6650 return __( 'after a version change made outside the updater', 'vigilante' );
6651 case 'migration':
6652 return __( 'while updating to this version', 'vigilante' );
6653 case 'activation':
6654 return __( 'when Vigilant was activated', 'vigilante' );
6655 case 'watchdog':
6656 return __( 'from the scheduled task watchdog', 'vigilante' );
6657 }
6658 return '';
6659 }
6660
6661 /**
6662 * Short line for the badge of the box, the notices and the Dashboard strip.
6663 *
6664 * @param string $tone Tone from Vigilante_Self_Integrity::tone().
6665 * @param array $state State.
6666 * @return string
6667 */
6668 private function self_integrity_headline( $tone, $state ) {
6669 $files = isset( $state['files_checked'] ) ? (int) $state['files_checked'] : 0;
6670 $anchors = ( isset( $state['anchors'] ) && is_array( $state['anchors'] ) ) ? $state['anchors'] : array();
6671 switch ( $tone ) {
6672 case 'critical':
6673 return __( 'Changes detected in Vigilant own files', 'vigilante' );
6674 case 'warning':
6675 return ( $files < 1 )
6676 ? __( 'Vigilant could not check its own files', 'vigilante' )
6677 : __( 'Vigilant self-protection needs your attention', 'vigilante' );
6678 case 'off':
6679 return __( 'Self-protection is switched off by code', 'vigilante' );
6680 case 'none':
6681 return __( 'Vigilant has not checked its own files yet', 'vigilante' );
6682 }
6683 return sprintf(
6684 /* translators: 1: number of files verified, 2: number of references available, out of three */
6685 __( 'Verified: %1$d files, %2$d of 3 references', 'vigilante' ),
6686 $files,
6687 count( array_filter( $anchors ) )
6688 );
6689 }
6690
6691 /**
6692 * Vigilant self-protection box: the first block of the File Integrity
6693 * results, with its own colour by severity, what each finding means and
6694 * how to fix it.
6695 *
6696 * It renders whether or not a scan has been stored, because the self-check
6697 * also runs after every update and once a day: before 3.0.0 this lived in
6698 * a line above the numeric cards of the last scan, where it was invisible
6699 * and, without a stored scan, absent.
6700 *
6701 * @param array $fi_options File Integrity settings section.
6702 */
6703 /**
6704 * Everything the screens need to say about self-protection, read once:
6705 * the state, its findings grouped by case, and the tone that colours the
6706 * box, the menu counter and the notices.
6707 *
6708 * @param array|null $fi_options File Integrity settings, read if not given.
6709 * @return array { state, findings, groups, tone, enabled }
6710 */
6711 private function self_integrity_summary( $fi_options = null ) {
6712 // Four to six screens ask for this in the same page load (menu, notice,
6713 // box, strip, both scores). The option is cached by the core options
6714 // layer, but the grouping and the tone are not: memoize per request.
6715 static $cached = null;
6716 if ( null !== $cached && ! is_array( $fi_options ) ) {
6717 return $cached;
6718 }
6719 if ( ! is_array( $fi_options ) ) {
6720 $fi_options = (array) $this->settings->get_section( 'file_integrity' );
6721 }
6722 $enabled = Vigilante_Self_Integrity::is_on();
6723 $state = Vigilante_Self_Integrity::display_state();
6724 $findings = Vigilante_Self_Integrity::state_findings( $state, $enabled );
6725 $summary = array(
6726 'state' => $state,
6727 'findings' => $findings,
6728 'groups' => $this->self_findings_by_case( $findings ),
6729 'tone' => Vigilante_Self_Integrity::tone( $state, $enabled ),
6730 'enabled' => $enabled,
6731 );
6732 $cached = $summary;
6733 return $summary;
6734 }
6735
6736 private function render_self_protection_box( $fi_options ) {
6737 $summary = $this->self_integrity_summary( $fi_options );
6738 $enabled = $summary['enabled'];
6739 $state = $summary['state'];
6740 $findings = $summary['findings'];
6741 $groups = $summary['groups'];
6742 $tone = $summary['tone'];
6743 $total = isset( $state['last_findings_total'] ) ? (int) $state['last_findings_total'] : count( $findings );
6744 $status = array(
6745 'status' => isset( $state['last_status'] ) ? (string) $state['last_status'] : '',
6746 'files' => isset( $state['files_checked'] ) ? (int) $state['files_checked'] : 0,
6747 'anchors' => ( isset( $state['anchors'] ) && is_array( $state['anchors'] ) ) ? $state['anchors'] : array(),
6748 'enabled' => $enabled,
6749 'has_run' => ! empty( $state['last_check'] ),
6750 );
6751
6752 /*
6753 * Nothing to do, nothing to open: one line. A card with a big icon and
6754 * folded sections for "everything is fine" is furniture, and furniture
6755 * is what made the previous version of this invisible.
6756 */
6757 if ( empty( $groups ) ) {
6758 $this->render_self_line( $tone, $state, $status );
6759 return;
6760 }
6761
6762 $datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
6763 $context_label = $this->self_context_label( isset( $state['last_context'] ) ? $state['last_context'] : '' );
6764 $icon = ( 'critical' === $tone ) ? 'dashicons-shield' : 'dashicons-warning';
6765 ?>
6766 <div id="vigilante-section-fi-self" class="vigilante-settings-section vigilante-self-box vigilante-self-box--<?php echo esc_attr( $tone ); ?>">
6767 <div class="vigilante-self-card">
6768 <div class="vigilante-self-head">
6769 <span class="vigilante-self-icon"><span class="dashicons <?php echo esc_attr( $icon ); ?>" aria-hidden="true"></span></span>
6770 <div class="vigilante-self-head-text">
6771 <h2><?php echo esc_html( $this->self_integrity_headline( $tone, $state ) ); ?></h2>
6772 <p class="vigilante-self-meta">
6773 <?php
6774 printf(
6775 /* translators: %s: date and time of the last self-check */
6776 esc_html__( 'Checked on %s', 'vigilante' ),
6777 esc_html( wp_date( $datetime_format, (int) $state['last_check'] ) )
6778 );
6779 if ( '' !== $context_label ) {
6780 echo ', ' . esc_html( $context_label );
6781 }
6782 if ( $status['files'] > 0 ) {
6783 echo ', ';
6784 printf(
6785 /* translators: 1: number of files checked, 2: number of references available, out of three */
6786 esc_html__( '%1$d files against %2$d of 3 references', 'vigilante' ),
6787 (int) $status['files'],
6788 (int) count( array_filter( $status['anchors'] ) )
6789 );
6790 }
6791 ?>
6792 </p>
6793 </div>
6794 </div>
6795
6796 <div class="vigilante-self-cases">
6797 <?php
6798 $first = true;
6799 foreach ( $groups as $group ) {
6800 $this->render_self_case( $group, $group['files'], $group['severity'], $first );
6801 $first = false;
6802 }
6803
6804 if ( in_array( $tone, array( 'critical', 'warning' ), true ) ) {
6805 $can_repair = class_exists( 'Vigilante_Self_Repair' ) && Vigilante_Self_Repair::can_repair();
6806 if ( ! $can_repair ) {
6807 if ( class_exists( 'Vigilante_Self_Repair' ) && ! Vigilante_Self_Repair::folder_is_the_distributed_one() ) {
6808 $vg_reason = 'renamed';
6809 } elseif ( ! wp_is_file_mod_allowed( 'capability_update_core' ) ) {
6810 // With DISALLOW_FILE_MODS nobody can do it from the admin,
6811 // not even a network administrator: telling a subsite admin
6812 // to ask theirs would send them to someone equally blocked.
6813 $vg_reason = 'no_caps';
6814 } elseif ( is_multisite() && ! current_user_can( 'update_plugins' ) ) {
6815 $vg_reason = 'network';
6816 } else {
6817 $vg_reason = 'no_caps';
6818 }
6819 $this->render_self_case(
6820 array(
6821 'title' => __( 'How to repair it here', 'vigilante' ),
6822 'meaning' => __( 'This site does not let Vigilant replace its own files from this screen.', 'vigilante' ),
6823 'steps' => Vigilante_Self_Integrity_Guidance::manual_steps( $vg_reason ),
6824 ),
6825 array(),
6826 '',
6827 false
6828 );
6829 }
6830 }
6831 ?>
6832 </div>
6833
6834 <?php if ( $total > count( $findings ) ) : ?>
6835 <p class="description">
6836 <?php
6837 printf(
6838 /* translators: 1: findings shown, 2: findings found in total */
6839 esc_html__( 'Showing %1$d of %2$d findings: the rest are of the same kind.', 'vigilante' ),
6840 (int) count( $findings ),
6841 (int) $total
6842 );
6843 ?>
6844 </p>
6845 <?php endif; ?>
6846
6847 <?php
6848 /*
6849 * Reinstalling fixes files, not a filter someone wrote or a hook
6850 * someone removed: the button only appears when at least one of the
6851 * cases on screen is one a clean copy solves. Offering it next to
6852 * "switched off by code" was telling the person to fix something
6853 * else.
6854 */
6855 $vg_offer_repair = false;
6856 foreach ( $groups as $vg_group ) {
6857 if ( ! empty( $vg_group['repair'] ) ) {
6858 $vg_offer_repair = true;
6859 break;
6860 }
6861 }
6862 ?>
6863 <p class="vigilante-self-actions">
6864 <?php if ( $vg_offer_repair && class_exists( 'Vigilante_Self_Repair' ) && Vigilante_Self_Repair::can_repair() ) : ?>
6865 <a class="button button-primary" href="<?php echo esc_url( Vigilante_Self_Repair::action_url() ); ?>">
6866 <?php esc_html_e( 'Repair Vigilant', 'vigilante' ); ?>
6867 </a>
6868 <span class="description">
6869 <?php esc_html_e( 'It downloads a clean copy from WordPress.org, asks before changing anything, and keeps your settings and log.', 'vigilante' ); ?>
6870 </span>
6871 <?php else : ?>
6872 <span class="description">
6873 <?php esc_html_e( 'After fixing it, run a new scan with the Run Scan Now button above.', 'vigilante' ); ?>
6874 </span>
6875 <?php endif; ?>
6876 </p>
6877 </div>
6878 </div>
6879 <?php
6880 }
6881
6882 /**
6883 * The same state when there is nothing to act on: one line inside the same
6884 * card, so the first block of the results is always the same object.
6885 *
6886 * @param string $tone Tone from Vigilante_Self_Integrity::tone().
6887 * @param array $state State.
6888 * @param array $status Arguments for the guidance catalogue.
6889 */
6890 private function render_self_line( $tone, $state, $status ) {
6891 $guidance = Vigilante_Self_Integrity_Guidance::for_status( $status );
6892 $icon = ( 'ok' === $tone ) ? 'dashicons-yes-alt' : 'dashicons-shield';
6893 ?>
6894 <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">
6895 <div class="vigilante-self-card vigilante-self-card--quiet">
6896 <p class="vigilante-self-line">
6897 <span class="dashicons <?php echo esc_attr( $icon ); ?>" aria-hidden="true"></span>
6898 <strong><?php esc_html_e( 'Vigilant self-protection:', 'vigilante' ); ?></strong>
6899 <span class="vigilante-self-line-state"><?php echo esc_html( $this->self_integrity_headline( $tone, $state ) ); ?></span>
6900 <?php if ( ! empty( $state['last_check'] ) ) : ?>
6901 <span class="vigilante-self-line-meta">
6902 <?php
6903 printf(
6904 /* translators: %s: human time difference, like "2 hours" */
6905 esc_html__( 'checked %s ago', 'vigilante' ),
6906 esc_html( human_time_diff( (int) $state['last_check'], time() ) )
6907 );
6908 ?>
6909 </span>
6910 <?php endif; ?>
6911 </p>
6912 <?php if ( ! empty( $guidance['steps'] ) && 'none' === $tone ) : ?>
6913 <p class="description vigilante-self-line-help"><?php echo esc_html( $guidance['steps'][0] ); ?></p>
6914 <?php endif; ?>
6915 </div>
6916 </div>
6917 <?php
6918 }
6919
6920 /**
6921 * One case of the self-protection box, as a row that opens: what it is, how
6922 * many files, its severity, and inside, the files, what it means and what to
6923 * do. Plain HTML details, so there is no JavaScript between a finding about
6924 * the security plugin and the person reading it.
6925 *
6926 * @param array $guidance Guidance entry (title, meaning, steps).
6927 * @param array $files Paths this case was found in.
6928 * @param string $severity critical|warning, empty for the how-to-repair row.
6929 * @param bool $open Whether the row starts open.
6930 */
6931 private function render_self_case( $guidance, $files = array(), $severity = '', $open = false ) {
6932 $shown = array_slice( (array) $files, 0, 20 );
6933 $hidden = count( (array) $files ) - count( $shown );
6934 ?>
6935 <details class="vigilante-self-case vigilante-self-case--<?php echo esc_attr( '' !== $severity ? $severity : 'plain' ); ?>"<?php echo $open ? ' open' : ''; ?>>
6936 <summary>
6937 <span class="vigilante-self-case-title"><?php echo esc_html( $guidance['title'] ); ?></span>
6938 <?php if ( ! empty( $files ) ) : ?>
6939 <span class="vigilante-self-case-count">
6940 <?php
6941 printf(
6942 /* translators: %d: number of files of this finding */
6943 esc_html( _n( '%d file', '%d files', count( (array) $files ), 'vigilante' ) ),
6944 (int) count( (array) $files )
6945 );
6946 ?>
6947 </span>
6948 <?php endif; ?>
6949 <?php if ( '' !== $severity ) : ?>
6950 <span class="vigilante-self-case-severity">
6951 <?php echo esc_html( 'critical' === $severity ? __( 'critical', 'vigilante' ) : __( 'warning', 'vigilante' ) ); ?>
6952 </span>
6953 <?php endif; ?>
6954 </summary>
6955 <div class="vigilante-self-case-body">
6956 <?php if ( ! empty( $shown ) ) : ?>
6957 <ul class="vigilante-self-paths">
6958 <?php foreach ( $shown as $file ) : ?>
6959 <li><code><?php echo esc_html( $file ); ?></code></li>
6960 <?php endforeach; ?>
6961 <?php if ( $hidden > 0 ) : ?>
6962 <li>
6963 <?php
6964 printf(
6965 /* translators: %d: number of additional files */
6966 esc_html__( 'and %d more', 'vigilante' ),
6967 (int) $hidden
6968 );
6969 ?>
6970 </li>
6971 <?php endif; ?>
6972 </ul>
6973 <?php endif; ?>
6974 <p class="vigilante-self-meaning">
6975 <strong><?php esc_html_e( 'What it means:', 'vigilante' ); ?></strong>
6976 <?php echo esc_html( $guidance['meaning'] ); ?>
6977 </p>
6978 <?php if ( ! empty( $guidance['steps'] ) ) : ?>
6979 <p class="vigilante-self-todo"><strong><?php esc_html_e( 'What to do:', 'vigilante' ); ?></strong></p>
6980 <ol class="vigilante-self-steps">
6981 <?php foreach ( $guidance['steps'] as $step ) : ?>
6982 <li><?php echo esc_html( $step ); ?></li>
6983 <?php endforeach; ?>
6984 </ol>
6985 <?php endif; ?>
6986 </div>
6987 </details>
6988 <?php
6989 }
6990
6991 private function render_tab_file_integrity() {
6992 $is_disabled = $this->render_module_disabled_notice( 'file_integrity' );
6993 $options = $this->settings->get_section( 'file_integrity' );
6994 // On the main site of a network the critical-file scan is the network's
6995 // canary for a change to wp-config.php or the root .htaccess, so a
6996 // main-site admin without network rights cannot turn it off. Since
6997 // 2.11.8; see Vigilante_Settings::get_main_site_file_settings().
6998 $vg_main_locked = $this->main_site_files_locked();
6999 $last_scan = get_option( 'vigilante_last_integrity_scan' );
7000 $last_results = get_option( 'vigilante_last_integrity_results' );
7001 $ignored_files = get_option( 'vigilante_ignored_files', array() );
7002
7003 /*
7004 * Vigilant own findings are shown in their own box, the first of the
7005 * results, with what each one means and how to fix it. They are taken
7006 * out of the generic tables here (and out of the counters above them)
7007 * so the same finding is not reported twice and so no row of the
7008 * security plugin's own files offers an Ignore button. The stored
7009 * results keep them: the scan email reads its own section from there.
7010 */
7011 if ( is_array( $last_results ) ) {
7012 foreach ( array( 'modified', 'suspicious', 'extra', 'missing' ) as $vg_bucket ) {
7013 if ( empty( $last_results[ $vg_bucket ] ) || ! is_array( $last_results[ $vg_bucket ] ) ) {
7014 continue;
7015 }
7016 $last_results[ $vg_bucket ] = array_values(
7017 array_filter(
7018 $last_results[ $vg_bucket ],
7019 function ( $vg_item ) {
7020 return ! ( is_array( $vg_item ) && 'vigilante_self' === ( $vg_item['type'] ?? '' ) );
7021 }
7022 )
7023 );
7024 }
7025 }
7026
7027 // Backward compat: convert old notify_on_changes to notify_level
7028 $notify_level = $options['notify_level'] ?? '';
7029 if ( empty( $notify_level ) ) {
7030 $notify_level = ! empty( $options['notify_on_changes'] ) ? 'all' : 'disabled';
7031 }
7032
7033 // Closed + Removed plugins data. Surfaced inside Last Scan Results so the
7034 // user sees file findings and plugin closures together (same tier of risk,
7035 // same UI), and as the trigger to keep Last Scan Results open even when no
7036 // file scan has run yet (the daily cron may have populated this section).
7037 //
7038 // Gating by last_check_time > 0 is how "Clear Previous Results" visually
7039 // resets this block: the option vigilante_plugin_status_last_check is
7040 // deleted on Clear, but the state map and the ignored list survive so the
7041 // next scan reconstructs without degrading a 'removed' slug. While
7042 // last_check is 0, we treat the plugin_status data as if it didn't exist.
7043 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
7044 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
7045 }
7046 $closed_checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
7047 $closed_last_check = $closed_checker->get_last_check_time();
7048 if ( $closed_last_check > 0 ) {
7049 $closed_plugins = $closed_checker->get_closed_plugins();
7050 $ignored_closed_plugins = $closed_checker->get_ignored_closed_plugins();
7051 } else {
7052 $closed_plugins = array();
7053 $ignored_closed_plugins = array();
7054 }
7055 $has_closed = ! empty( $closed_plugins );
7056 $datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
7057 ?>
7058 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="file_integrity" <?php echo $is_disabled ? 'inert' : ''; ?>>
7059 <div id="vigilante-section-fi-monitoring" class="vigilante-settings-section">
7060 <h2>
7061 <?php esc_html_e( 'File Integrity Monitoring', 'vigilante' ); ?>
7062 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
7063 </h2>
7064 <p><?php esc_html_e( 'Detects file modifications using WordPress.org checksums.', 'vigilante' ); ?></p>
7065
7066 <table class="form-table">
7067 <tr>
7068 <th scope="row"><?php esc_html_e( 'Automatic Scans', 'vigilante' ); ?></th>
7069 <td>
7070 <label>
7071 <input type="checkbox" name="file_integrity[auto_scan]" value="1" <?php checked( ! empty( $options['auto_scan'] ) ); ?>>
7072 <?php esc_html_e( 'Enable scheduled file integrity scans', 'vigilante' ); ?>
7073 </label>
7074 </td>
7075 </tr>
7076 <tr>
7077 <th scope="row"><label for="vigilante-f-file-integrity-scan-frequency"><?php esc_html_e( 'Scan Frequency', 'vigilante' ); ?></label></th>
7078 <td>
7079 <select id="vigilante-f-file-integrity-scan-frequency" name="file_integrity[scan_frequency]">
7080 <option value="daily" <?php selected( $options['scan_frequency'] ?? 'daily', 'daily' ); ?>><?php esc_html_e( 'Daily', 'vigilante' ); ?></option>
7081 <option value="weekly" <?php selected( $options['scan_frequency'] ?? 'daily', 'weekly' ); ?>><?php esc_html_e( 'Weekly', 'vigilante' ); ?></option>
7082 </select>
7083 </td>
7084 </tr>
7085 <tr>
7086 <th scope="row"><label for="vigilante-f-file-integrity-notify-level"><?php esc_html_e( 'Email Notifications', 'vigilante' ); ?></label></th>
7087 <td>
7088 <select id="vigilante-f-file-integrity-notify-level" name="file_integrity[notify_level]">
7089 <option value="all" <?php selected( $notify_level, 'all' ); ?>><?php esc_html_e( 'All issues (modified + suspicious)', 'vigilante' ); ?></option>
7090 <option value="suspicious_only" <?php selected( $notify_level, 'suspicious_only' ); ?>><?php esc_html_e( 'Suspicious files only', 'vigilante' ); ?></option>
7091 <option value="disabled" <?php selected( $notify_level, 'disabled' ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
7092 </select>
7093 <p class="description"><?php esc_html_e( '"Suspicious files only" reduces noise by skipping modified file notifications. Recommended for most sites.', 'vigilante' ); ?></p>
7094 </td>
7095 </tr>
7096 <tr>
7097 <th scope="row"><?php esc_html_e( 'Instant Alert', 'vigilante' ); ?></th>
7098 <td>
7099 <label>
7100 <input type="checkbox" name="file_integrity[instant_alert]" value="1" <?php checked( ! empty( $options['instant_alert'] ) ); ?>>
7101 <?php esc_html_e( 'Send immediate alert when modified, suspicious or additional files are detected, or when a closed plugin is found', 'vigilante' ); ?>
7102 </label>
7103 <p class="description"><?php esc_html_e( 'Fires even if the Email Notifications setting above is set to Disabled.', 'vigilante' ); ?></p>
7104 <p class="description">
7105 <?php
7106 printf(
7107 /* translators: %s: Link to notification settings */
7108 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
7109 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
7110 );
7111 ?>
7112 </p>
7113 </td>
7114 </tr>
7115 <tr>
7116 <th scope="row"><?php esc_html_e( 'Test email', 'vigilante' ); ?></th>
7117 <td>
7118 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
7119 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
7120 </button>
7121 <span class="vigilante-test-email-result" style="margin-left:8px;"></span>
7122 <p class="description"><?php esc_html_e( 'Sends a test message to the configured recipients to confirm email delivery works.', 'vigilante' ); ?></p>
7123 </td>
7124 </tr>
7125 <tr>
7126 <th scope="row"><?php esc_html_e( 'Scan Scope', 'vigilante' ); ?></th>
7127 <td>
7128 <fieldset>
7129 <label>
7130 <input type="checkbox" name="file_integrity[scan_core]" value="1" <?php checked( $options['scan_core'] ?? true ); ?>>
7131 <?php esc_html_e( 'Core files (compare against WordPress.org checksums)', 'vigilante' ); ?>
7132 </label>
7133 <br>
7134 <label>
7135 <input type="checkbox" name="file_integrity[scan_plugins]" value="1" <?php checked( $options['scan_plugins'] ?? true ); ?>>
7136 <?php esc_html_e( 'Plugins (WordPress.org repository plugins)', 'vigilante' ); ?>
7137 </label>
7138 <br>
7139 <label>
7140 <input type="checkbox" name="file_integrity[scan_themes]" value="1" <?php checked( $options['scan_themes'] ?? true ); ?>>
7141 <?php esc_html_e( 'Themes (WordPress.org repository themes)', 'vigilante' ); ?>
7142 </label>
7143 <br>
7144 <label>
7145 <input type="checkbox" name="file_integrity[scan_uploads]" value="1" <?php checked( $options['scan_uploads'] ?? true ); ?>>
7146 <?php esc_html_e( 'Uploads directory (detect PHP files, double extensions, .htaccess)', 'vigilante' ); ?>
7147 </label>
7148 <br>
7149 <label>
7150 <input type="checkbox" name="file_integrity[scan_critical_config]" value="1" <?php disabled( $vg_main_locked ); ?> <?php checked( $options['scan_critical_config'] ?? true ); ?>>
7151 <?php esc_html_e( 'Critical config files (wp-config.php, .htaccess baseline monitoring)', 'vigilante' ); ?>
7152 <?php if ( $vg_main_locked ) : ?>
7153 <span class="description" style="display:block;margin-left:24px;"><?php echo esc_html( Vigilante_Settings::get_shared_files_notice() ); ?></span>
7154 <?php endif; ?>
7155 </label>
7156 <br>
7157 <label>
7158 <input type="checkbox" name="file_integrity[check_closed_plugins]" value="1" <?php checked( $options['check_closed_plugins'] ?? true ); ?>>
7159 <?php esc_html_e( 'Closed plugins (daily check against the WordPress.org repository)', 'vigilante' ); ?>
7160 </label>
7161 </fieldset>
7162 </td>
7163 </tr>
7164 <tr>
7165 <th scope="row"><label for="vigilante-f-file-integrity-excluded-paths"><?php esc_html_e( 'Excluded Paths', 'vigilante' ); ?></label></th>
7166 <td>
7167 <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>
7168 <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>
7169 </td>
7170 </tr>
7171 <tr>
7172 <th scope="row"><label for="vigilante-f-file-integrity-excluded-extensions"><?php esc_html_e( 'Excluded Extensions', 'vigilante' ); ?></label></th>
7173 <td>
7174 <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>
7175 <p class="description">
7176 <?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' ); ?>
7177 <br>
7178 <?php
7179 printf(
7180 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the scoped-extension example. */
7181 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' ),
7182 '<code>',
7183 '</code>'
7184 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
7185 ?>
7186 </p>
7187 </td>
7188 </tr>
7189 </table>
7190 </div>
7191
7192 <p class="submit vigilante-submit-buttons">
7193 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
7194 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
7195 </button>
7196 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
7197 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
7198 </button>
7199 <span class="vigilante-buttons-separator"></span>
7200 <button type="button" class="button button-primary vigilante-run-scan">
7201 <?php esc_html_e( 'Run Scan Now', 'vigilante' ); ?>
7202 </button>
7203 <button type="button" class="button vigilante-clear-scan-btn vigilante-clear-scan">
7204 <?php esc_html_e( 'Clear Previous Results', 'vigilante' ); ?>
7205 </button>
7206 </p>
7207 </form>
7208
7209 <div id="vigilante-scan-results" class="vigilante-settings-section" style="display:none;"></div>
7210
7211 <?php $this->render_self_protection_box( $options ); ?>
7212
7213 <?php if ( $last_scan || $has_closed || $closed_last_check > 0 ) : ?>
7214 <div id="vigilante-section-fi-last-scan" class="vigilante-settings-section">
7215 <h2><?php esc_html_e( 'Last Scan Results', 'vigilante' ); ?></h2>
7216 <?php if ( $last_scan ) : ?>
7217 <p>
7218 <?php
7219 // Build the "X files scanned" hint inline with the date so it doesn't
7220 // need its own stat box (keeps the row compact when closed plugins are
7221 // present).
7222 $scanned_total = 0;
7223 if ( $last_results ) {
7224 $scanned_total = (int) ( $last_results['ok'] ?? 0 )
7225 + count( $last_results['modified'] ?? array() )
7226 + count( $last_results['suspicious'] ?? array() )
7227 + count( $last_results['extra'] ?? array() )
7228 + count( $ignored_files );
7229 }
7230 if ( $scanned_total > 0 ) {
7231 printf(
7232 /* translators: 1: date and time of last scan, 2: formatted file count */
7233 esc_html__( 'Last scan: %1$s (%2$s files scanned)', 'vigilante' ),
7234 esc_html( wp_date( $datetime_format, $last_scan ) ),
7235 esc_html( number_format_i18n( $scanned_total ) )
7236 );
7237 } else {
7238 printf(
7239 /* translators: %s: date and time of last scan */
7240 esc_html__( 'Last scan: %s', 'vigilante' ),
7241 esc_html( wp_date( $datetime_format, $last_scan ) )
7242 );
7243 }
7244 if ( $closed_last_check > 0 && $closed_last_check !== (int) $last_scan ) {
7245 echo ' &middot; ';
7246 printf(
7247 /* translators: %s: date and time of last closed plugins check */
7248 esc_html__( 'Closed plugins last checked: %s', 'vigilante' ),
7249 esc_html( wp_date( $datetime_format, $closed_last_check ) )
7250 );
7251 }
7252 ?>
7253 </p>
7254 <?php elseif ( $closed_last_check > 0 ) : ?>
7255 <p>
7256 <?php
7257 printf(
7258 /* translators: %s: date and time of last closed plugins check */
7259 esc_html__( 'Closed plugins last checked: %s &middot; the daily cron is running, no full integrity scan yet.', 'vigilante' ),
7260 esc_html( wp_date( $datetime_format, $closed_last_check ) )
7261 );
7262 ?>
7263 </p>
7264 <?php endif; ?>
7265 <div id="vigilante-last-scan-results">
7266 <?php if ( $last_results || $has_closed ) : ?>
7267 <div class="vigilante-scan-summary">
7268 <?php if ( $last_results ) : ?>
7269 <div class="vigilante-scan-stat vigilante-stat-ok">
7270 <span class="vigilante-stat-number"><?php echo esc_html( $last_results['ok'] ?? 0 ); ?></span>
7271 <span class="vigilante-stat-label"><?php esc_html_e( 'OK', 'vigilante' ); ?></span>
7272 </div>
7273 <div class="vigilante-scan-stat vigilante-stat-modified">
7274 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['modified'] ?? array() ) ); ?></span>
7275 <span class="vigilante-stat-label"><?php esc_html_e( 'Modified', 'vigilante' ); ?></span>
7276 </div>
7277 <div class="vigilante-scan-stat vigilante-stat-suspicious">
7278 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['suspicious'] ?? array() ) ); ?></span>
7279 <span class="vigilante-stat-label"><?php esc_html_e( 'Suspicious', 'vigilante' ); ?></span>
7280 </div>
7281 <div class="vigilante-scan-stat vigilante-stat-extra">
7282 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['extra'] ?? array() ) ); ?></span>
7283 <span class="vigilante-stat-label"><?php esc_html_e( 'Extra', 'vigilante' ); ?></span>
7284 </div>
7285 <?php endif; ?>
7286 <?php if ( $has_closed ) : ?>
7287 <div class="vigilante-scan-stat vigilante-stat-suspicious">
7288 <span class="vigilante-stat-number" style="color: #d63638;"><?php echo (int) count( $closed_plugins ); ?></span>
7289 <span class="vigilante-stat-label"><?php esc_html_e( 'Closed/Removed', 'vigilante' ); ?></span>
7290 </div>
7291 <?php endif; ?>
7292 <?php if ( ! empty( $ignored_files ) ) : ?>
7293 <div class="vigilante-scan-stat vigilante-stat-ignored">
7294 <span class="vigilante-stat-number"><?php echo esc_html( count( $ignored_files ) ); ?></span>
7295 <span class="vigilante-stat-label"><?php esc_html_e( 'Ignored', 'vigilante' ); ?></span>
7296 </div>
7297 <?php endif; ?>
7298 </div>
7299
7300 <?php if ( ! empty( $last_results['suspicious'] ) ) : ?>
7301 <div class="vigilante-file-list vigilante-suspicious-files vigilante-paginated-section" data-bulk-mode="ignore">
7302 <h3 style="color: #d63638;"><?php esc_html_e( 'Suspicious Files', 'vigilante' ); ?></h3>
7303 <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>
7304 <div class="vigilante-fi-bulk-bar">
7305 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
7306 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
7307 </div>
7308 <div class="vigilante-fi-pagination-wrap"></div>
7309 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
7310 <thead>
7311 <tr>
7312 <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>
7313 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
7314 <th style="width: 250px;"><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
7315 <th style="width: 120px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
7316 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
7317 </tr>
7318 </thead>
7319 <tbody>
7320 <?php
7321 foreach ( $last_results['suspicious'] as $item ) {
7322 $file_path = '';
7323 $file_reason = __( 'Unknown', 'vigilante' );
7324 $file_type = 'unknown';
7325
7326 if ( is_array( $item ) ) {
7327 if ( isset( $item['file'] ) ) {
7328 $file_path = $item['file'];
7329 }
7330 if ( isset( $item['reason'] ) ) {
7331 $file_reason = $item['reason'];
7332 }
7333 if ( isset( $item['type'] ) ) {
7334 $file_type = $item['type'];
7335 }
7336 } else {
7337 $file_path = (string) $item;
7338 }
7339 if ( 'vigilante_self' === $file_type ) {
7340 $file_type = __( 'Vigilant (self)', 'vigilante' );
7341 }
7342 ?>
7343 <tr>
7344 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
7345 <td><code style="color: #d63638;"><?php echo esc_html( $file_path ); ?></code></td>
7346 <td><?php echo esc_html( $file_reason ); ?></td>
7347 <td><?php echo esc_html( $file_type ); ?></td>
7348 <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>
7349 </tr>
7350 <?php
7351 }
7352 ?>
7353 </tbody>
7354 </table>
7355 </div>
7356 <?php endif; ?>
7357
7358 <?php if ( ! empty( $last_results['extra'] ) ) : ?>
7359 <div class="vigilante-file-list vigilante-extra-files vigilante-paginated-section" data-bulk-mode="ignore">
7360 <h3 style="color: #b32d2e;"><?php esc_html_e( 'Extra Files', 'vigilante' ); ?></h3>
7361 <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>
7362 <div class="vigilante-fi-bulk-bar">
7363 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
7364 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
7365 </div>
7366 <div class="vigilante-fi-pagination-wrap"></div>
7367 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
7368 <thead>
7369 <tr>
7370 <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>
7371 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
7372 <th style="width: 250px;"><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
7373 <th style="width: 120px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
7374 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
7375 </tr>
7376 </thead>
7377 <tbody>
7378 <?php
7379 foreach ( $last_results['extra'] as $item ) {
7380 $file_path = is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item;
7381 $file_reason = is_array( $item ) ? ( $item['reason'] ?? __( 'Unknown', 'vigilante' ) ) : __( 'Unknown', 'vigilante' );
7382 $file_type = is_array( $item ) ? ( $item['type'] ?? 'unknown' ) : 'unknown';
7383 if ( 'vigilante_self' === $file_type ) {
7384 $file_type = __( 'Vigilant (self)', 'vigilante' );
7385 }
7386 ?>
7387 <tr>
7388 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
7389 <td><code style="color: #b32d2e;"><?php echo esc_html( $file_path ); ?></code></td>
7390 <td><?php echo esc_html( $file_reason ); ?></td>
7391 <td><?php echo esc_html( $file_type ); ?></td>
7392 <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>
7393 </tr>
7394 <?php
7395 }
7396 ?>
7397 </tbody>
7398 </table>
7399 </div>
7400 <?php endif; ?>
7401
7402 <?php
7403 // Split critical config files from regular modified files.
7404 // Computed unconditionally so the three sub-sections that consume
7405 // these arrays (Critical Config, Closed + Removed, Modified Files)
7406 // can render independently and in the order the team picked.
7407 $critical_modified = array();
7408 $regular_modified = array();
7409 if ( $last_results && ! empty( $last_results['modified'] ) ) {
7410 foreach ( $last_results['modified'] as $item ) {
7411 if ( is_array( $item ) && isset( $item['type'] ) && 'critical_config' === $item['type'] ) {
7412 $critical_modified[] = $item;
7413 } else {
7414 $regular_modified[] = $item;
7415 }
7416 }
7417 }
7418 // A missing file of Vigilant is critical, and the missing
7419 // files of the generic scan have no table: it is listed with
7420 // the modified files, or the tab said "All files passed" with
7421 // a module deleted.
7422 if ( $last_results && ! empty( $last_results['missing'] ) && is_array( $last_results['missing'] ) ) {
7423 foreach ( $last_results['missing'] as $item ) {
7424 if ( is_array( $item ) && 'vigilante_self' === ( $item['type'] ?? '' ) ) {
7425 $regular_modified[] = $item;
7426 }
7427 }
7428 }
7429 ?>
7430
7431 <?php if ( ! empty( $critical_modified ) ) : ?>
7432 <div class="vigilante-file-list vigilante-critical-config-files">
7433 <h3 style="color: #e36210;"><?php esc_html_e( 'Critical config files modified', 'vigilante' ); ?></h3>
7434 <p class="description">
7435 <?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' ); ?>
7436 </p>
7437 <table class="wp-list-table widefat fixed striped">
7438 <thead>
7439 <tr>
7440 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
7441 <th style="width: 200px;"><?php esc_html_e( 'Changes', 'vigilante' ); ?></th>
7442 <th style="width: 220px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
7443 </tr>
7444 </thead>
7445 <tbody>
7446 <?php foreach ( $critical_modified as $crit_item ) :
7447 $crit_file = $crit_item['file'] ?? '';
7448 $crit_baseline_size = $crit_item['baseline_size'] ?? 0;
7449 $crit_current_size = $crit_item['current_size'] ?? 0;
7450 $crit_diff = $crit_item['diff'] ?? array();
7451 $crit_id = sanitize_html_class( $crit_file );
7452 $added_count = is_array( $crit_diff ) ? count( $crit_diff['added'] ?? array() ) : 0;
7453 $removed_count = is_array( $crit_diff ) ? count( $crit_diff['removed'] ?? array() ) : 0;
7454 // The lines of a shared file are for whoever approves it. Results
7455 // stored before 2.11.8 on the main site still carry them, so the
7456 // screen asks too, not only the scan that wrote them.
7457 $diff_network = ( is_array( $crit_diff ) && ! empty( $crit_diff['network'] ) ) || $this->critical_approval_locked();
7458 $diff_rescan = is_array( $crit_diff ) && ! empty( $crit_diff['rescan'] );
7459 $diff_redaction = is_array( $crit_diff ) && ! empty( $crit_diff['redaction'] );
7460 $diff_unavailable = $diff_network || ( is_array( $crit_diff ) && ! empty( $crit_diff['unavailable'] ) );
7461 ?>
7462 <tr>
7463 <td><code style="color: #e36210;"><?php echo esc_html( $crit_file ); ?></code></td>
7464 <td>
7465 <?php if ( ! $diff_unavailable ) : ?>
7466 <span style="color: #007017;">+<?php echo (int) $added_count; ?></span>
7467 <span style="color: #b32d2e;">-<?php echo (int) $removed_count; ?></span>
7468 <?php esc_html_e( 'lines', 'vigilante' ); ?><br>
7469 <?php endif; ?>
7470 <small style="color: #50575e;">
7471 <?php
7472 printf(
7473 /* translators: 1: baseline size, 2: current size */
7474 esc_html__( '%1$s &rarr; %2$s bytes', 'vigilante' ),
7475 esc_html( number_format_i18n( $crit_baseline_size ) ),
7476 esc_html( number_format_i18n( $crit_current_size ) )
7477 );
7478 ?>
7479 </small>
7480 </td>
7481 <td>
7482 <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' ); ?>">
7483 <?php esc_html_e( 'Review changes', 'vigilante' ); ?>
7484 </button>
7485 <?php if ( $this->critical_approval_locked() ) : ?>
7486 <span class="description" style="display:block;margin-top:4px;">
7487 <?php echo esc_html( $this->critical_approval_notice() ); ?>
7488 </span>
7489 <?php else : ?>
7490 <button type="button" class="button button-small button-primary vigilante-approve-critical-file" data-file="<?php echo esc_attr( $crit_file ); ?>">
7491 <?php esc_html_e( 'Approve', 'vigilante' ); ?>
7492 </button>
7493 <?php endif; ?>
7494 </td>
7495 </tr>
7496 <tr id="vigilante-critical-content-<?php echo esc_attr( $crit_id ); ?>" class="vigilante-critical-content-row" style="display:none;">
7497 <td colspan="3" style="padding: 0;">
7498 <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;">
7499 <?php if ( $diff_network ) : ?>
7500 <p style="color: #50575e; font-style: italic; margin: 0;">
7501 <?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' ); ?>
7502 </p>
7503 <?php elseif ( $diff_rescan ) : ?>
7504 <p style="color: #50575e; font-style: italic; margin: 0;">
7505 <?php esc_html_e( 'Run a new scan to see the line changes of this file.', 'vigilante' ); ?>
7506 </p>
7507 <?php elseif ( $diff_redaction ) : ?>
7508 <p style="color: #50575e; font-style: italic; margin: 0;">
7509 <?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' ); ?>
7510 </p>
7511 <?php elseif ( $diff_unavailable ) : ?>
7512 <p style="color: #50575e; font-style: italic; margin: 0;">
7513 <?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' ); ?>
7514 </p>
7515 <?php elseif ( empty( $crit_diff['added'] ) && empty( $crit_diff['removed'] ) ) : ?>
7516 <p style="color: #50575e; font-style: italic; margin: 0;">
7517 <?php esc_html_e( 'No line-level changes detected (may be whitespace or reordering).', 'vigilante' ); ?>
7518 </p>
7519 <?php else : ?>
7520 <?php if ( ! empty( $crit_diff['removed'] ) ) : ?>
7521 <?php foreach ( $crit_diff['removed'] as $rline ) : ?>
7522 <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>
7523 <?php endforeach; ?>
7524 <?php endif; ?>
7525 <?php if ( ! empty( $crit_diff['added'] ) ) : ?>
7526 <?php foreach ( $crit_diff['added'] as $aline ) : ?>
7527 <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>
7528 <?php endforeach; ?>
7529 <?php endif; ?>
7530 <?php endif; ?>
7531 </div>
7532 </td>
7533 </tr>
7534 <?php endforeach; ?>
7535 </tbody>
7536 </table>
7537 </div>
7538 <?php endif; ?>
7539
7540 <?php if ( $has_closed ) : ?>
7541 <div class="vigilante-file-list vigilante-closed-plugins">
7542 <h3 id="vigilante-section-fi-closed-plugins" style="color: #d63638;"><?php esc_html_e( 'Closed + Removed Plugins', 'vigilante' ); ?></h3>
7543 <p class="description" style="color: #d63638;">
7544 <?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' ); ?>
7545 </p>
7546 <table class="wp-list-table widefat striped">
7547 <thead>
7548 <tr>
7549 <th><?php esc_html_e( 'Plugin', 'vigilante' ); ?></th>
7550 <th style="width: 70px;"><?php esc_html_e( 'Version', 'vigilante' ); ?></th>
7551 <th style="width: 90px;"><?php esc_html_e( 'State', 'vigilante' ); ?></th>
7552 <th style="width: 110px;"><?php esc_html_e( 'Closed date', 'vigilante' ); ?></th>
7553 <th><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
7554 <th style="width: 130px;"><?php esc_html_e( 'Detected', 'vigilante' ); ?></th>
7555 <th style="width: 90px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
7556 </tr>
7557 </thead>
7558 <tbody>
7559 <?php foreach ( $closed_plugins as $cp_slug => $cp_entry ) :
7560 $cp_state = $cp_entry['state'] ?? '';
7561 $cp_state_label = 'closed' === $cp_state ? __( 'Closed', 'vigilante' ) : __( 'Removed', 'vigilante' );
7562 $cp_state_color = 'closed' === $cp_state ? '#d63638' : '#b32d2e';
7563 $cp_reason = '';
7564 if ( ! empty( $cp_entry['closed_reason_text'] ) ) {
7565 $cp_reason = $cp_entry['closed_reason_text'];
7566 } elseif ( 'removed' === $cp_state ) {
7567 $cp_reason = __( 'Removed from repository (metadata hidden, typical of Security Issue closures)', 'vigilante' );
7568 }
7569 $cp_detected = isset( $cp_entry['first_detected'] ) ? (int) $cp_entry['first_detected'] : 0;
7570 ?>
7571 <tr>
7572 <td>
7573 <strong><?php echo esc_html( $cp_entry['name'] ?? $cp_slug ); ?></strong><br>
7574 <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>
7575 </td>
7576 <td><?php echo esc_html( $cp_entry['version'] ?? '' ); ?></td>
7577 <td><span style="color: <?php echo esc_attr( $cp_state_color ); ?>; font-weight: 600;"><?php echo esc_html( $cp_state_label ); ?></span></td>
7578 <td><?php echo esc_html( $cp_entry['closed_date'] ?? '' ); ?></td>
7579 <td><?php echo esc_html( $cp_reason ); ?></td>
7580 <td>
7581 <?php echo $cp_detected > 0 ? esc_html( wp_date( $datetime_format, $cp_detected ) ) : '&mdash;'; ?>
7582 </td>
7583 <td>
7584 <button type="button" class="button button-small vigilante-ignore-closed-plugin" data-slug="<?php echo esc_attr( $cp_slug ); ?>">
7585 <?php esc_html_e( 'Ignore', 'vigilante' ); ?>
7586 </button>
7587 </td>
7588 </tr>
7589 <?php endforeach; ?>
7590 </tbody>
7591 </table>
7592 </div>
7593 <?php endif; ?>
7594
7595 <?php if ( ! empty( $regular_modified ) ) : ?>
7596 <div class="vigilante-file-list vigilante-paginated-section" data-bulk-mode="ignore">
7597 <h3><?php esc_html_e( 'Modified Files', 'vigilante' ); ?></h3>
7598 <p class="description"><?php esc_html_e( 'These files (apparently) differ from the original WordPress or plugin versions.', 'vigilante' ); ?></p>
7599 <div class="vigilante-fi-bulk-bar">
7600 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
7601 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
7602 </div>
7603 <div class="vigilante-fi-pagination-wrap"></div>
7604 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
7605 <thead>
7606 <tr>
7607 <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>
7608 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
7609 <th style="width: 100px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
7610 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
7611 </tr>
7612 </thead>
7613 <tbody>
7614 <?php
7615 foreach ( $regular_modified as $item ) {
7616 $file_path = '';
7617 $file_type = 'unknown';
7618
7619 if ( is_array( $item ) ) {
7620 if ( isset( $item['file'] ) ) {
7621 $file_path = $item['file'];
7622 }
7623 if ( isset( $item['type'] ) ) {
7624 $file_type = $item['type'];
7625 }
7626 } else {
7627 $file_path = (string) $item;
7628 }
7629 if ( 'vigilante_self' === $file_type ) {
7630 $file_type = __( 'Vigilant (self)', 'vigilante' );
7631 }
7632 ?>
7633 <tr>
7634 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
7635 <td><code><?php echo esc_html( $file_path ); ?></code></td>
7636 <td><?php echo esc_html( $file_type ); ?></td>
7637 <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>
7638 </tr>
7639 <?php
7640 }
7641 ?>
7642 </tbody>
7643 </table>
7644 </div>
7645 <?php endif; ?>
7646
7647 <?php
7648 // "All files passed" is about every file, and Vigilant's own
7649 // are files too: with the self-protection box in red or amber
7650 // above, this line contradicted it (its findings no longer
7651 // travel in the tables below).
7652 $vg_self_alarm = in_array( $this->self_integrity_summary( $options )['tone'], array( 'critical', 'off', 'warning' ), true );
7653 ?>
7654 <?php if ( $last_results && ! $vg_self_alarm && empty( $critical_modified ) && empty( $regular_modified ) && empty( $last_results['suspicious'] ) && empty( $last_results['extra'] ) && ! $has_closed ) : ?>
7655 <p class="vigilante-all-clear" style="color: #00a32a; font-weight: bold;">
7656 <?php esc_html_e( 'Good Job! All files passed integrity check. No issues found.', 'vigilante' ); ?>
7657 </p>
7658 <?php endif; ?>
7659 <?php endif; ?>
7660 </div>
7661 </div>
7662 <?php endif; ?>
7663
7664 <?php if ( ! empty( $ignored_closed_plugins ) ) : ?>
7665 <div id="vigilante-section-fi-ignored-closed" class="vigilante-settings-section">
7666 <h2><?php esc_html_e( 'Ignored Closed + Removed Plugins', 'vigilante' ); ?></h2>
7667 <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>
7668 <table class="wp-list-table widefat fixed striped">
7669 <thead>
7670 <tr>
7671 <th><?php esc_html_e( 'Plugin', 'vigilante' ); ?></th>
7672 <th style="width: 110px;"><?php esc_html_e( 'State', 'vigilante' ); ?></th>
7673 <th style="width: 120px;"><?php esc_html_e( 'Closed date', 'vigilante' ); ?></th>
7674 <th style="width: 130px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
7675 </tr>
7676 </thead>
7677 <tbody>
7678 <?php foreach ( $ignored_closed_plugins as $icp_slug => $icp_entry ) :
7679 $icp_state = $icp_entry['state'] ?? '';
7680 $icp_state_label = 'closed' === $icp_state ? __( 'Closed', 'vigilante' ) : __( 'Removed', 'vigilante' );
7681 ?>
7682 <tr>
7683 <td>
7684 <strong><?php echo esc_html( $icp_entry['name'] ?? $icp_slug ); ?></strong><br>
7685 <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>
7686 </td>
7687 <td><?php echo esc_html( $icp_state_label ); ?></td>
7688 <td><?php echo esc_html( $icp_entry['closed_date'] ?? '' ); ?></td>
7689 <td>
7690 <button type="button" class="button button-small vigilante-unignore-closed-plugin" data-slug="<?php echo esc_attr( $icp_slug ); ?>">
7691 <?php esc_html_e( 'Stop ignoring', 'vigilante' ); ?>
7692 </button>
7693 </td>
7694 </tr>
7695 <?php endforeach; ?>
7696 </tbody>
7697 </table>
7698 <p style="margin-top: 10px;">
7699 <button type="button" class="button vigilante-clear-ignored-closed-plugins"><?php esc_html_e( 'Clear All Ignored Closed + Removed Plugins', 'vigilante' ); ?></button>
7700 </p>
7701 </div>
7702 <?php endif; ?>
7703
7704 <?php if ( ! empty( $ignored_files ) ) : ?>
7705 <div id="vigilante-section-fi-ignored" class="vigilante-settings-section">
7706 <h2><?php esc_html_e( 'Ignored Files', 'vigilante' ); ?></h2>
7707 <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>
7708 <div class="vigilante-paginated-section" data-bulk-mode="unignore">
7709 <div class="vigilante-fi-bulk-bar">
7710 <button type="button" class="button vigilante-bulk-unignore" disabled><?php esc_html_e( 'Stop ignoring selected', 'vigilante' ); ?></button>
7711 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
7712 </div>
7713 <div class="vigilante-fi-pagination-wrap"></div>
7714 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
7715 <thead>
7716 <tr>
7717 <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>
7718 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
7719 <th style="width: 120px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
7720 </tr>
7721 </thead>
7722 <tbody>
7723 <?php foreach ( $ignored_files as $file ) : ?>
7724 <tr>
7725 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file ); ?>"></th>
7726 <td><code><?php echo esc_html( $file ); ?></code></td>
7727 <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>
7728 </tr>
7729 <?php endforeach; ?>
7730 </tbody>
7731 </table>
7732 </div>
7733 <p style="margin-top: 10px;">
7734 <button type="button" class="button vigilante-clear-ignored"><?php esc_html_e( 'Clear All Ignored Files', 'vigilante' ); ?></button>
7735 </p>
7736 </div>
7737 <?php endif; ?>
7738 <?php
7739 }
7740
7741 /**
7742 * Render sidebar with promotional widgets
7743 */
7744 private function render_sidebar() {
7745 $promo_banner = new Vigilante_Promo_Banner( 'vigilante' );
7746 $promo_banner->render();
7747 }
7748
7749 /**
7750 * AJAX: Download a ZIP backup of the critical config files.
7751 *
7752 * Streams wp-config.php and .htaccess (and robots.txt if present) as a
7753 * downloadable archive. Config backups are no longer left as files under the
7754 * web root, so this hands the admin the archive directly.
7755 */
7756 public function ajax_download_files_backup() {
7757 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7758
7759 if ( ! current_user_can( 'manage_options' ) ) {
7760 wp_die( esc_html__( 'Permission denied.', 'vigilante' ), 403 );
7761 }
7762
7763 // The archive carries wp-config.php, which a whole network shares. On a
7764 // network manage_options is held by every subsite administrator, so the
7765 // same gate the writers use applies here.
7766 if ( ! Vigilante_Settings::can_write_shared_files() ) {
7767 wp_die( esc_html( Vigilante_Settings::get_shared_files_notice() ), 403 );
7768 }
7769
7770 $backup_manager = new Vigilante_Backup_Manager();
7771 $result = $backup_manager->stream_files_zip();
7772
7773 // stream_files_zip() exits on success; only a WP_Error returns here.
7774 if ( is_wp_error( $result ) ) {
7775 wp_die( esc_html( $result->get_error_message() ), 500 );
7776 }
7777 }
7778
7779 /**
7780 * AJAX: Save settings
7781 */
7782 public function ajax_save_settings() {
7783 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7784
7785 if ( ! current_user_can( 'manage_options' ) ) {
7786 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7787 }
7788
7789 $section = isset( $_POST['section'] ) ? sanitize_key( $_POST['section'] ) : '';
7790
7791 // Handle $_POST['data'] based on type
7792 if ( isset( $_POST['data'] ) && is_array( $_POST['data'] ) ) {
7793 $data = map_deep( wp_unslash( $_POST['data'] ), 'sanitize_text_field' );
7794 } elseif ( isset( $_POST['data'] ) ) {
7795 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
7796 $raw_data = wp_unslash( $_POST['data'] );
7797 parse_str( $raw_data, $data );
7798 $data = map_deep( $data, 'sanitize_textarea_field' );
7799 } else {
7800 $data = array();
7801 }
7802
7803 if ( empty( $section ) ) {
7804 wp_send_json_error( __( 'Invalid section.', 'vigilante' ) );
7805 }
7806
7807 // Check if 2FA is being enabled or method changed (for notification sending)
7808 $send_2fa_notification = false;
7809 $send_login_url_notification = false;
7810
7811 if ( 'login_security' === $section ) {
7812 // Read old state from DB
7813 $db_options = get_option( Vigilante_Settings::OPTION_NAME, array() );
7814 $old_2fa_enabled = ! empty( $db_options['login_security']['two_factor']['enabled'] );
7815 $old_method = $db_options['login_security']['two_factor']['method'] ?? 'email';
7816
7817 // Check new state from submitted data
7818 $new_2fa_enabled = false;
7819 $notify_on_enable = false;
7820 $new_method = isset( $data['login_security']['two_factor']['method'] )
7821 ? sanitize_key( $data['login_security']['two_factor']['method'] )
7822 : 'email';
7823
7824 if ( isset( $data['login_security']['two_factor']['enabled'] ) ) {
7825 $new_2fa_enabled = filter_var( $data['login_security']['two_factor']['enabled'], FILTER_VALIDATE_BOOLEAN );
7826 }
7827 if ( isset( $data['login_security']['two_factor']['notify_on_enable'] ) ) {
7828 $notify_on_enable = filter_var( $data['login_security']['two_factor']['notify_on_enable'], FILTER_VALIDATE_BOOLEAN );
7829 }
7830
7831 // Send notification if:
7832 // 1. 2FA is being enabled (was off, now on) OR
7833 // 2. Method changed while 2FA is enabled
7834 if ( $notify_on_enable && $new_2fa_enabled ) {
7835 if ( ! $old_2fa_enabled || ( $old_2fa_enabled && $old_method !== $new_method ) ) {
7836 $send_2fa_notification = true;
7837 }
7838 }
7839
7840 // Check if login URL changed and notification is enabled
7841 $old_login_url = $db_options['login_security']['custom_login_url'] ?? '';
7842 $new_login_url = isset( $data['login_security']['custom_login_url'] )
7843 ? sanitize_title( $data['login_security']['custom_login_url'] )
7844 : '';
7845 $notify_on_url_change = isset( $data['login_security']['notify_on_login_url_change'] )
7846 ? filter_var( $data['login_security']['notify_on_login_url_change'], FILTER_VALIDATE_BOOLEAN )
7847 : false;
7848
7849 if ( $notify_on_url_change && ! empty( $new_login_url ) && $new_login_url !== $old_login_url ) {
7850 $send_login_url_notification = true;
7851 }
7852 }
7853
7854 // Get defaults
7855 $defaults = $this->settings->get_default_options();
7856
7857 // Read ONLY saved options from database (not merged with defaults)
7858 $saved_options = get_option( Vigilante_Settings::OPTION_NAME, array() );
7859
7860 // What is stored before this request changes anything: the shared file
7861 // settings this user may not change are put back from here (2.11.6).
7862 $stored_options = $saved_options;
7863 $locked = Vigilante_Settings::get_locked_file_settings();
7864
7865 if ( isset( $locked[ $section ] ) && true === $locked[ $section ] ) {
7866 wp_send_json_error( Vigilante_Settings::get_shared_files_notice() );
7867 }
7868
7869 // A module switch is a single key, so refusing says more than a success
7870 // that changed nothing, and the dashboard puts the toggle back.
7871 if ( 'modules' === $section && isset( $locked['modules'], $data['modules'] ) && is_array( $locked['modules'] ) && is_array( $data['modules'] ) ) {
7872 foreach ( array_keys( $data['modules'] ) as $vg_module ) {
7873 if ( in_array( sanitize_key( $vg_module ), $locked['modules'], true ) ) {
7874 wp_send_json_error( Vigilante_Settings::get_shared_files_notice() );
7875 }
7876 }
7877 }
7878
7879 $rejected_ips = array();
7880 $rejected_proxies = array();
7881
7882 // Handle modules
7883 if ( 'modules' === $section && isset( $data['modules'] ) ) {
7884 if ( ! isset( $saved_options['modules'] ) ) {
7885 $saved_options['modules'] = array();
7886 }
7887 foreach ( $data['modules'] as $module => $enabled ) {
7888 $module = sanitize_key( $module );
7889 $saved_options['modules'][ $module ] = in_array( $enabled, array( '1', 1, 'true', true ), true );
7890 }
7891 // Clear active preset when modules change
7892 update_option( 'vigilante_active_preset', '' );
7893 } else {
7894 // Process primary section
7895 if ( isset( $data[ $section ] ) && is_array( $data[ $section ] ) ) {
7896 $section_defaults = isset( $defaults[ $section ] ) ? $defaults[ $section ] : array();
7897 $current_section = isset( $saved_options[ $section ] ) ? $saved_options[ $section ] : array();
7898
7899 // Process the submitted data
7900 $processed = $this->process_section_data( $data[ $section ], $section_defaults, $current_section );
7901
7902 // The IP boxes are free text and, until 2.9.9, whatever was typed
7903 // went straight into the option. An entry the matcher can never
7904 // match still sits in a security list looking like protection,
7905 // so the ones that cannot match are dropped and reported back
7906 // instead of being stored in silence.
7907 $rejected_ips = $this->filter_ip_lists( $section, $processed, $rejected_proxies );
7908
7909 // Save the processed section
7910 $saved_options[ $section ] = $processed;
7911
7912 // Clear active preset when any section settings change
7913 update_option( 'vigilante_active_preset', '' );
7914 }
7915 }
7916
7917 // Clear cache before saving
7918 wp_cache_delete( Vigilante_Settings::OPTION_NAME, 'options' );
7919
7920 $saved_options = Vigilante_Settings::keep_locked_file_settings( $saved_options, $stored_options );
7921
7922 // Save to database
7923 update_option( Vigilante_Settings::OPTION_NAME, $saved_options );
7924
7925 // Clear the settings cache
7926 $this->settings->clear_cache();
7927
7928 // Apply changes based on section
7929 $this->apply_section_changes( $section, $saved_options );
7930
7931 // Send 2FA notifications after settings are saved
7932 $notification_result = null;
7933 if ( $send_2fa_notification ) {
7934 $notification_result = $this->send_2fa_enable_notifications();
7935 }
7936
7937 // Send login URL notifications after settings are saved
7938 $login_url_result = null;
7939 if ( $send_login_url_notification ) {
7940 $login_url_result = $this->send_login_url_notifications();
7941 }
7942
7943 // Build success message
7944 $message = __( 'Settings saved successfully.', 'vigilante' );
7945
7946 if ( $notification_result && $notification_result['sent'] > 0 ) {
7947 $message .= ' ' . sprintf(
7948 /* translators: %d: Number of emails sent */
7949 _n(
7950 '2FA notification sent to %d user.',
7951 '2FA notifications sent to %d users.',
7952 $notification_result['sent'],
7953 'vigilante'
7954 ),
7955 $notification_result['sent']
7956 );
7957 }
7958
7959 if ( $login_url_result && $login_url_result['sent'] > 0 ) {
7960 $message .= ' ' . sprintf(
7961 /* translators: %d: Number of emails sent */
7962 _n(
7963 'Login URL notification sent to %d user.',
7964 'Login URL notifications sent to %d users.',
7965 $login_url_result['sent'],
7966 'vigilante'
7967 ),
7968 $login_url_result['sent']
7969 );
7970 }
7971
7972 if ( ! empty( $rejected_ips ) ) {
7973 $message .= ' ' . sprintf(
7974 /* translators: %s: comma separated list of the entries that were not saved. */
7975 _n(
7976 'This entry is not a valid IP, CIDR range or wildcard, so it was not saved: %s',
7977 'These entries are not valid IPs, CIDR ranges or wildcards, so they were not saved: %s',
7978 count( $rejected_ips ),
7979 'vigilante'
7980 ),
7981 implode( ', ', array_map( 'esc_html', $rejected_ips ) )
7982 );
7983 }
7984
7985 if ( ! empty( $rejected_proxies ) ) {
7986 $message .= ' ' . sprintf(
7987 /* translators: %s: comma separated list of the trusted proxy entries that were not saved. */
7988 _n(
7989 'A trusted proxy must be an exact IP or a CIDR range, not a wildcard, so this entry was not saved: %s',
7990 'A trusted proxy must be an exact IP or a CIDR range, not a wildcard, so these entries were not saved: %s',
7991 count( $rejected_proxies ),
7992 'vigilante'
7993 ),
7994 implode( ', ', array_map( 'esc_html', $rejected_proxies ) )
7995 );
7996 }
7997
7998 wp_send_json_success( $message );
7999 }
8000
8001 /**
8002 * Keep only the IP patterns the matcher can actually match
8003 *
8004 * @since 2.9.9
8005 *
8006 * @param string $section Section being saved.
8007 * @param array $processed Section data, edited in place.
8008 * @return array Entries that were dropped, for the message back to the user.
8009 */
8010 private function filter_ip_lists( $section, &$processed, &$rejected_proxies = array() ) {
8011 $rejected_proxies = array();
8012
8013 // Trusted proxies feed an identity decision, so only exact addresses and
8014 // CIDR ranges belong there: a wildcard is stripped with its own message,
8015 // never stored looking effective. The matcher ignores it anyway (see
8016 // Vigilante_IP_Utils::in_list_ip_or_cidr), this stops it persisting.
8017 if ( 'firewall' === $section && isset( $processed['trusted_proxies'] ) && is_array( $processed['trusted_proxies'] ) ) {
8018 $split = Vigilante_IP_Utils::split_list_ip_or_cidr( $processed['trusted_proxies'] );
8019 $processed['trusted_proxies'] = $split['valid'];
8020 $rejected_proxies = $split['rejected'];
8021 }
8022
8023 $lists = array(
8024 'firewall' => array( 'ip_whitelist', 'ip_blacklist' ),
8025 'login_security' => array( 'ip_whitelist' ),
8026 );
8027
8028 if ( ! isset( $lists[ $section ] ) ) {
8029 return array();
8030 }
8031
8032 $rejected = array();
8033
8034 foreach ( $lists[ $section ] as $key ) {
8035 if ( ! isset( $processed[ $key ] ) || ! is_array( $processed[ $key ] ) ) {
8036 continue;
8037 }
8038
8039 $split = Vigilante_IP_Utils::split_list( $processed[ $key ] );
8040 $processed[ $key ] = $split['valid'];
8041 $rejected = array_merge( $rejected, $split['rejected'] );
8042 }
8043
8044 return array_values( array_unique( $rejected ) );
8045 }
8046
8047 /**
8048 * Send 2FA enable notifications to users
8049 *
8050 * @return array Result with 'sent' and 'failed' counts.
8051 */
8052 private function send_2fa_enable_notifications() {
8053 $result = array(
8054 'sent' => 0,
8055 'failed' => 0,
8056 );
8057
8058 // Get settings for roles and method
8059 $login_security = $this->settings->get_section( 'login_security' );
8060 $two_factor = isset( $login_security['two_factor'] ) ? $login_security['two_factor'] : array();
8061 $roles = isset( $two_factor['enforced_roles'] ) ? $two_factor['enforced_roles'] : array( 'administrator' );
8062 $method = isset( $two_factor['method'] ) ? $two_factor['method'] : 'email';
8063
8064 if ( empty( $roles ) ) {
8065 $roles = array( 'administrator' );
8066 }
8067
8068 $excluded = isset( $two_factor['excluded_users'] ) ? array_map( 'absint', $two_factor['excluded_users'] ) : array();
8069
8070 // Get users with these roles
8071 $args = array(
8072 'role__in' => $roles,
8073 );
8074 if ( ! empty( $excluded ) ) {
8075 // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- Small excluded users list from settings.
8076 $args['exclude'] = $excluded;
8077 }
8078 $users = get_users( $args );
8079
8080 if ( empty( $users ) ) {
8081 return $result;
8082 }
8083
8084 $site_name = get_bloginfo( 'name' );
8085 $from_name = ! empty( $two_factor['email_from_name'] ) ? $two_factor['email_from_name'] : $site_name;
8086
8087 if ( 'totp' === $method ) {
8088 // Use TOTP class for styled HTML emails
8089 if ( ! class_exists( 'Vigilante_Two_Factor_TOTP' ) ) {
8090 require_once VIGILANTE_INCLUDES_DIR . 'class-two-factor-totp.php';
8091 }
8092 $totp = new Vigilante_Two_Factor_TOTP( $this->settings, $this->database, $this->activity_log );
8093
8094 foreach ( $users as $user ) {
8095 // Skip users who already have TOTP configured
8096 $totp_data = $this->database->get_totp_data( $user->ID );
8097 if ( $totp_data && ! empty( $totp_data['is_configured'] ) ) {
8098 continue;
8099 }
8100
8101 $sent = $totp->send_activation_email( $user, $site_name, $from_name );
8102
8103 if ( $sent ) {
8104 $this->database->mark_2fa_notified( $user->ID );
8105 $result['sent']++;
8106 } else {
8107 $result['failed']++;
8108 }
8109 }
8110 } else {
8111 // Email method - use existing email 2FA class
8112 if ( ! class_exists( 'Vigilante_Two_Factor_Email' ) ) {
8113 require_once VIGILANTE_INCLUDES_DIR . 'class-two-factor-email.php';
8114 }
8115 $email_2fa = new Vigilante_Two_Factor_Email( $this->settings, $this->database, $this->activity_log );
8116 return $email_2fa->send_activation_notifications( false );
8117 }
8118
8119 return $result;
8120 }
8121
8122 /**
8123 * Send login URL change notifications to users with admin access
8124 *
8125 * @return array Result with 'sent' and 'failed' counts.
8126 */
8127 private function send_login_url_notifications() {
8128 $login_options = $this->settings->get_section( 'login_security' );
8129 $custom_url = ! empty( $login_options['custom_login_url'] ) ? sanitize_title( $login_options['custom_login_url'] ) : '';
8130
8131 if ( empty( $custom_url ) ) {
8132 return array( 'sent' => 0, 'failed' => 0 );
8133 }
8134
8135 $login_url = home_url( $custom_url . '/' );
8136 $site_name = get_bloginfo( 'name' );
8137
8138 $admin_roles = array( 'administrator', 'editor', 'author', 'contributor' );
8139 $users = get_users( array( 'role__in' => $admin_roles ) );
8140
8141 if ( empty( $users ) ) {
8142 return array( 'sent' => 0, 'failed' => 0 );
8143 }
8144
8145 $subject = sprintf(
8146 /* translators: %s: Site name */
8147 __( '[%s] Your login URL has changed', 'vigilante' ),
8148 $site_name
8149 );
8150
8151 $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' ) );
8152 $body .= Vigilante_Email_Template::url_box( $login_url, __( 'Your new login URL:', 'vigilante' ) );
8153 $body .= Vigilante_Email_Template::alert_box( __( 'The old login address (wp-login.php) will no longer work.', 'vigilante' ) );
8154 $body .= Vigilante_Email_Template::button( $login_url, __( 'Go to login', 'vigilante' ) );
8155
8156 $sent = 0;
8157 $failed = 0;
8158
8159 foreach ( $users as $user ) {
8160 $result = Vigilante_Email_Template::send(
8161 $user->user_email,
8162 $subject,
8163 __( 'Login URL changed', 'vigilante' ),
8164 $body
8165 );
8166 if ( $result ) {
8167 $sent++;
8168 } else {
8169 $failed++;
8170 }
8171 }
8172
8173 if ( $this->activity_log ) {
8174 $this->activity_log->log(
8175 'login',
8176 'login_url_notified',
8177 sprintf(
8178 /* translators: 1: Sent count, 2: Failed count */
8179 __( 'Login URL notification sent on save: %1$d sent, %2$d failed', 'vigilante' ),
8180 $sent,
8181 $failed
8182 )
8183 );
8184 }
8185
8186 return array( 'sent' => $sent, 'failed' => $failed );
8187 }
8188
8189 /**
8190 * Process section data maintaining proper types from defaults
8191 *
8192 * @param array $submitted_data Data submitted from form.
8193 * @param array $defaults Default values for this section.
8194 * @param array $current Current saved values.
8195 * @param string $section_name Section name for special handling.
8196 * @return array Processed data.
8197 */
8198 private function process_section_data( $submitted_data, $defaults, $current, $section_name = '' ) {
8199 // Start with defaults, then merge current saved values. Lists are put
8200 // back whole afterwards: array_replace_recursive() merges them index by
8201 // index, so a saved list shorter than the default kept the default's
8202 // tail (see below, and Vigilante_Settings::array_merge_deep()).
8203 $result = array_replace_recursive( $defaults, $current );
8204 $result = $this->restore_lists( $result, $current );
8205
8206 // Process each submitted value
8207 foreach ( $submitted_data as $key => $value ) {
8208 $key = sanitize_key( $key );
8209
8210 if ( is_array( $value ) && $this->is_list_field( $key, $value, $defaults, $current ) ) {
8211 /*
8212 * A list of values, not a group of settings: the roles of a
8213 * checkbox group, the excluded user ids. What the form sent IS
8214 * the list, so it replaces the stored one outright.
8215 *
8216 * Until 3.0.1 this went through the recursion below, which
8217 * writes position by position and left every stored entry the
8218 * new list was too short to overwrite. Unchecking Editor in
8219 * "Enforce for roles" saved administrator over position 0 and
8220 * kept editor in position 1, so the box came back ticked
8221 * (reported on the support forum for 3.0.0, and the same bug
8222 * merge_preset() was fixed for in 2.9.8).
8223 *
8224 * Keys are dropped on purpose: a list is data, so anything the
8225 * request tried to name is not carried over. The empty string
8226 * is dropped too, which is what the hidden field that marks an
8227 * empty group sends.
8228 */
8229 $list = array();
8230 foreach ( $value as $entry ) {
8231 if ( ! is_scalar( $entry ) ) {
8232 continue;
8233 }
8234 $entry = sanitize_text_field( (string) $entry );
8235 if ( '' === $entry ) {
8236 continue;
8237 }
8238 $list[] = $entry;
8239 }
8240 $result[ $key ] = $list;
8241 } elseif ( is_array( $value ) ) {
8242 // Nested array (like rate_limiting)
8243 $nested_defaults = isset( $defaults[ $key ] ) && is_array( $defaults[ $key ] ) ? $defaults[ $key ] : array();
8244 $nested_current = isset( $result[ $key ] ) && is_array( $result[ $key ] ) ? $result[ $key ] : array();
8245 $result[ $key ] = $this->process_section_data( $value, $nested_defaults, $nested_current, $key );
8246 } else {
8247 // Determine type from default value
8248 $default_value = isset( $defaults[ $key ] ) ? $defaults[ $key ] : null;
8249
8250 if ( null === $default_value ) {
8251 // No default, check current value type or use as string
8252 $current_value = isset( $current[ $key ] ) ? $current[ $key ] : null;
8253 if ( is_bool( $current_value ) ) {
8254 $result[ $key ] = in_array( $value, array( '1', 1, 'true', true ), true );
8255 } elseif ( is_int( $current_value ) ) {
8256 $result[ $key ] = intval( $value );
8257 } elseif ( is_array( $current_value ) ) {
8258 $result[ $key ] = is_string( $value ) ? array_filter( array_map( 'trim', explode( "\n", $value ) ) ) : (array) $value;
8259 } else {
8260 $result[ $key ] = sanitize_text_field( $value );
8261 }
8262 } elseif ( is_bool( $default_value ) ) {
8263 // Boolean: '1', 1, 'true' become true; '0', 0, '', 'false' become false
8264 $result[ $key ] = in_array( $value, array( '1', 1, 'true', true ), true );
8265 } elseif ( is_int( $default_value ) ) {
8266 // Integer - with special handling for time fields shown in minutes
8267 $int_value = intval( $value );
8268
8269 // Convert minutes to seconds for login_security duration fields
8270 // These are displayed as minutes in the form but stored as seconds
8271 if ( in_array( $key, array( 'lockout_duration', 'max_lockout_duration' ), true ) ) {
8272 $int_value = $int_value * 60;
8273 }
8274
8275 $result[ $key ] = $int_value;
8276 } elseif ( is_array( $default_value ) ) {
8277 // Array from textarea (e.g., IP lists)
8278 if ( is_string( $value ) ) {
8279 $result[ $key ] = array_filter( array_map( 'trim', explode( "\n", $value ) ) );
8280 } else {
8281 $result[ $key ] = (array) $value;
8282 }
8283 } else {
8284 // String - preserve newlines for textarea fields
8285 if ( is_string( $value ) && ( strpos( $value, "\n" ) !== false || strpos( $value, "\r" ) !== false ) ) {
8286 $result[ $key ] = sanitize_textarea_field( $value );
8287 } else {
8288 $result[ $key ] = sanitize_text_field( $value );
8289 }
8290 }
8291 }
8292 }
8293
8294 // Handle unchecked checkboxes: HTML forms don't submit unchecked boxes
8295 // If a boolean field exists in defaults but NOT in submitted_data, set it to false
8296 //
8297 // EXCEPTION: the top-level 'enabled' flag of every section is the
8298 // module's master switch and is controlled by the Dashboard module
8299 // toggle, NOT by a checkbox inside the section's form. Treating it
8300 // like a regular checkbox here would silently switch the module off
8301 // every time the user saves the tab — see the REST API enabled=false
8302 // regression. We only skip it at the top level (when section_name is
8303 // empty); nested 'enabled' fields like security_headers.csp.enabled
8304 // are real checkboxes and must keep the auto-unset behaviour.
8305 $preserve_top_level = array( 'enabled' );
8306
8307 foreach ( $defaults as $key => $default_value ) {
8308 if ( '' === $section_name && in_array( $key, $preserve_top_level, true ) ) {
8309 continue;
8310 }
8311 if ( is_bool( $default_value ) && ! array_key_exists( $key, $submitted_data ) ) {
8312 $result[ $key ] = false;
8313 } elseif ( is_array( $default_value ) && ! isset( $submitted_data[ $key ] ) ) {
8314 // Check if this is a flat value list (like excluded_users, enforced_roles, ip_whitelist)
8315 // vs a nested settings group (like rate_limiting, two_factor)
8316 // Flat lists: default is empty array OR all values are scalar
8317 $is_value_list = empty( $default_value );
8318 if ( ! $is_value_list ) {
8319 $is_value_list = true;
8320 foreach ( $default_value as $dv ) {
8321 if ( ! is_scalar( $dv ) ) {
8322 $is_value_list = false;
8323 break;
8324 }
8325 }
8326 }
8327
8328 if ( $is_value_list ) {
8329 /*
8330 * A list whose key did not travel is left as it was. Until
8331 * 3.0.1 it was blanked here, which read "the user unticked
8332 * everything" into something the form never asked about:
8333 * saving the Firewall tab blanked allowed_http_methods,
8334 * which has no field on any screen, and saving Users blanked
8335 * insecure_usernames. Both survived only because reading the
8336 * option put the defaults back on top, and that is exactly
8337 * the merge being removed in this release: with lists
8338 * replaced whole, blanking here would have left a site
8339 * answering 403 to every HTTP method.
8340 *
8341 * Emptying a group is still possible, and is now said out
8342 * loud: each checkbox group prints a hidden field with an
8343 * empty value, so an empty group arrives as an empty list
8344 * instead of as silence. See list_sentinel().
8345 */
8346 continue;
8347 } else {
8348 // Nested settings group - handle boolean children
8349 foreach ( $default_value as $nested_key => $nested_default ) {
8350 if ( is_bool( $nested_default ) && isset( $result[ $key ] ) && is_array( $result[ $key ] ) ) {
8351 $nested_submitted = isset( $submitted_data[ $key ] ) && is_array( $submitted_data[ $key ] )
8352 ? $submitted_data[ $key ]
8353 : array();
8354 if ( ! array_key_exists( $nested_key, $nested_submitted ) ) {
8355 $result[ $key ][ $nested_key ] = false;
8356 }
8357 }
8358 }
8359 }
8360 }
8361 }
8362
8363 return $result;
8364 }
8365
8366 /**
8367 * Whether a submitted value is a list of values rather than a group of settings
8368 *
8369 * The difference decides whether what arrived replaces the stored value or
8370 * is merged into it key by key, so it is answered from what the setting is
8371 * (its default, or what is stored today), not from the shape of the
8372 * request. A request that sends named keys where a list belongs gets them
8373 * dropped, which is one way this is narrower than what it replaces.
8374 *
8375 * @since 3.0.1
8376 *
8377 * @param string $key Setting key, already through sanitize_key().
8378 * @param array $value Value as submitted.
8379 * @param array $defaults Defaults of the section being processed.
8380 * @param array $current Stored values of the section being processed.
8381 * @return bool
8382 */
8383 private function is_list_field( $key, $value, $defaults, $current ) {
8384 $default_known = array_key_exists( $key, $defaults ) && is_array( $defaults[ $key ] );
8385
8386 // The default has the first and the last word, the same rule that
8387 // array_merge_deep() and restore_lists() follow. Letting the stored
8388 // value decide, as this did until the fourth cross review of 3.0.1,
8389 // disagrees with them where it matters: an option corrupted into
8390 // two_factor = array( 'a', 'b' ) would have been treated as a list and
8391 // saving the tab would have replaced the whole group of settings with
8392 // the two values that arrived.
8393 if ( $default_known && array() !== $defaults[ $key ] ) {
8394 return Vigilante_Settings::is_list( $defaults[ $key ] );
8395 }
8396
8397 // Nothing declares it either way (an empty default, or a key with no
8398 // default at all), so what is stored, and then what was submitted, is
8399 // all there is to go on.
8400 if ( isset( $current[ $key ] ) && is_array( $current[ $key ] ) && array() !== $current[ $key ] && Vigilante_Settings::is_list( $current[ $key ] ) ) {
8401 return true;
8402 }
8403
8404 return Vigilante_Settings::is_list( $value );
8405 }
8406
8407 /**
8408 * Put stored lists back after array_replace_recursive()
8409 *
8410 * array_replace_recursive() merges a list by position, so a stored list
8411 * shorter than the default comes out with the default's tail attached:
8412 * ['administrator'] over ['administrator','editor'] gives both back. Every
8413 * list that is stored is therefore restored whole before anything else is
8414 * processed, and only associative arrays are walked into.
8415 *
8416 * @since 3.0.1
8417 *
8418 * @param array $result Defaults with the stored values merged over them.
8419 * @param array $current Stored values.
8420 * @return array
8421 */
8422 private function restore_lists( $result, $current ) {
8423 if ( ! is_array( $current ) ) {
8424 return $result;
8425 }
8426
8427 foreach ( $current as $key => $value ) {
8428 if ( ! is_array( $value ) || ! isset( $result[ $key ] ) || ! is_array( $result[ $key ] ) ) {
8429 continue;
8430 }
8431
8432 // Decided by what is in $result, which comes from the defaults, and
8433 // never by the stored value: array() is a list by any definition, so
8434 // a section stored empty would have replaced a whole group of
8435 // settings with nothing. Same reasoning as in array_merge_deep().
8436 if ( Vigilante_Settings::is_list( $result[ $key ] ) ) {
8437 $result[ $key ] = $value;
8438 continue;
8439 }
8440
8441 $result[ $key ] = $this->restore_lists( $result[ $key ], $value );
8442 }
8443
8444 return $result;
8445 }
8446
8447 /**
8448 * Print the hidden field that lets a checkbox group arrive empty
8449 *
8450 * A checkbox group sends nothing at all when every box is unticked, which
8451 * is indistinguishable from a form that never had that field. Since 3.0.1
8452 * the save path leaves an absent list alone, so the difference has to be
8453 * stated: this empty entry always travels, and the save path drops empty
8454 * strings, so an untouched group arrives as an empty list.
8455 *
8456 * @since 3.0.1
8457 *
8458 * @param string $name Field name without the trailing [].
8459 */
8460 private function list_sentinel( $name ) {
8461 printf( '<input type="hidden" name="%s[]" value="">', esc_attr( $name ) );
8462 }
8463
8464 /**
8465 * AJAX: Export settings
8466 */
8467 public function ajax_export_settings() {
8468 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8469
8470 if ( ! current_user_can( 'manage_options' ) ) {
8471 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8472 }
8473
8474 $options = $this->settings->get_all_options();
8475 $filename = 'vigilante-settings-' . gmdate( 'Y-m-d-His' ) . '.json';
8476
8477 wp_send_json_success( array(
8478 'content' => wp_json_encode( $options, JSON_PRETTY_PRINT ),
8479 'filename' => $filename,
8480 ) );
8481 }
8482
8483 /**
8484 * AJAX: Import settings
8485 */
8486 public function ajax_import_settings() {
8487 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8488
8489 if ( ! current_user_can( 'manage_options' ) ) {
8490 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8491 }
8492
8493 // Accept both 'settings' (from JS) and 'content' (legacy).
8494 // Do NOT run sanitize_text_field() on the raw payload: it calls
8495 // wp_strip_all_tags() internally, which removes any "<...>" substring
8496 // and turns a valid export JSON into garbage if any stored value
8497 // contains < or > (htaccess snippets, email templates, etc.). The
8498 // real sanitization happens after json_decode(), via map_deep() on
8499 // the parsed array.
8500 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash
8501 $content = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : '';
8502 if ( empty( $content ) ) {
8503 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash
8504 $content = isset( $_POST['content'] ) ? wp_unslash( $_POST['content'] ) : '';
8505 }
8506
8507 if ( empty( $content ) || ! is_string( $content ) ) {
8508 wp_send_json_error( __( 'No content provided.', 'vigilante' ) );
8509 }
8510
8511 $imported = json_decode( $content, true );
8512
8513 if ( json_last_error() !== JSON_ERROR_NONE || ! is_array( $imported ) ) {
8514 wp_send_json_error( __( 'Invalid JSON format.', 'vigilante' ) );
8515 }
8516
8517 // Sanitize imported data recursively
8518 $imported = map_deep( $imported, 'sanitize_text_field' );
8519
8520 // Validate structure: only sections and keys of the schema survive, and
8521 // every value takes the type of its default. Until 2.11.0 this was an
8522 // array_replace_recursive() of the file over the defaults, so any key in
8523 // the file, known or not, landed in vigilante_options (S7). Sections
8524 // the file does not carry keep their defaults; a section it does carry
8525 // replaces the default one whole, because validate_options() has
8526 // already filled in whatever the file left out.
8527 $defaults = $this->settings->get_default_options();
8528 $validated = $this->settings->validate_options( $imported );
8529 $merged = $defaults;
8530
8531 foreach ( $validated as $section => $data ) {
8532 if ( is_array( $data ) ) {
8533 $merged[ $section ] = $data;
8534 }
8535 }
8536
8537 // Save
8538 $merged = Vigilante_Settings::keep_locked_file_settings( $merged, get_option( Vigilante_Settings::OPTION_NAME, array() ) );
8539 update_option( Vigilante_Settings::OPTION_NAME, $merged );
8540 $this->settings->clear_cache();
8541
8542 // Re-evaluate the active preset marker. The imported config may match
8543 // a known preset exactly, partially, or not at all — without this step
8544 // the dashboard would keep showing whatever preset was active before
8545 // the import even if the new config no longer matches it.
8546 $matched_preset = $this->detect_matching_preset( $merged );
8547 if ( null === $matched_preset ) {
8548 delete_option( 'vigilante_active_preset' );
8549 } else {
8550 update_option( 'vigilante_active_preset', $matched_preset );
8551 }
8552
8553 // Apply file changes after import
8554 $this->apply_all_file_changes( $merged );
8555
8556 // Refresh the Security Analyzer score so the dashboard widget reflects
8557 // the imported config rather than the pre-import scan. Reuse the
8558 // post-Under-Attack scan hook (same job: full scan, async).
8559 if ( ! wp_next_scheduled( 'vigilante_under_attack_post_scan' ) ) {
8560 wp_schedule_single_event( time() + 5, 'vigilante_under_attack_post_scan' );
8561 }
8562
8563 wp_send_json_success( __( 'Settings imported successfully.', 'vigilante' ) . $this->locked_file_settings_message() );
8564 }
8565
8566 /**
8567 * Detect whether a vigilante_options array matches a known preset.
8568 *
8569 * A preset matches when every field the preset explicitly declares is
8570 * present in the config with the same (normalised) value. Fields outside
8571 * the preset are ignored — they may have been modified by the user before
8572 * applying the preset and do not invalidate the match. This mirrors how
8573 * apply_preset() now layers presets on top of the user's existing config.
8574 *
8575 * @param array $options The current/imported vigilante_options.
8576 * @return string|null Preset id ('standard', 'maximum') or null if custom.
8577 */
8578 private function detect_matching_preset( $options ) {
8579 if ( ! is_array( $options ) ) {
8580 return null;
8581 }
8582
8583 $presets = $this->settings->get_presets();
8584
8585 foreach ( $presets as $preset_id => $preset_data ) {
8586 unset( $preset_data['name'], $preset_data['description'] );
8587 if ( $this->preset_subset_matches( $preset_data, $options ) ) {
8588 return $preset_id;
8589 }
8590 }
8591
8592 return null;
8593 }
8594
8595 /**
8596 * Check whether every leaf value inside $preset_subset exists with the
8597 * same (normalised) value at the same path inside $config.
8598 *
8599 * @param mixed $preset_subset Branch of the preset definition.
8600 * @param mixed $config Same branch in the live/imported config.
8601 * @return bool
8602 */
8603 private function preset_subset_matches( $preset_subset, $config ) {
8604 if ( is_array( $preset_subset ) ) {
8605 if ( ! is_array( $config ) ) {
8606 return false;
8607 }
8608 foreach ( $preset_subset as $key => $value ) {
8609 if ( ! array_key_exists( $key, $config ) ) {
8610 return false;
8611 }
8612 if ( ! $this->preset_subset_matches( $value, $config[ $key ] ) ) {
8613 return false;
8614 }
8615 }
8616 return true;
8617 }
8618
8619 return $this->normalise_scalar_for_compare( $preset_subset ) === $this->normalise_scalar_for_compare( $config );
8620 }
8621
8622 /**
8623 * Normalise a scalar value so that the variants WordPress and the form
8624 * layer routinely produce ('1' / 1 / true → "1"; '' / '0' / 0 / false /
8625 * null → "") compare equal. Other values become strings unchanged.
8626 *
8627 * @param mixed $value
8628 * @return string
8629 */
8630 private function normalise_scalar_for_compare( $value ) {
8631 if ( is_bool( $value ) ) {
8632 return $value ? '1' : '';
8633 }
8634 if ( null === $value ) {
8635 return '';
8636 }
8637 if ( is_int( $value ) || is_float( $value ) ) {
8638 return (string) $value;
8639 }
8640 if ( is_string( $value ) ) {
8641 if ( 'true' === $value ) {
8642 return '1';
8643 }
8644 if ( 'false' === $value ) {
8645 return '';
8646 }
8647 return $value;
8648 }
8649 // Arrays and objects shouldn't reach here (handled by recursion above),
8650 // but if they do, fall back to a stable comparable representation.
8651 return wp_json_encode( $value );
8652 }
8653
8654 /**
8655 * AJAX: Apply preset
8656 */
8657 public function ajax_apply_preset() {
8658 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8659
8660 if ( ! current_user_can( 'manage_options' ) ) {
8661 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8662 }
8663
8664 $preset = isset( $_POST['preset'] ) ? sanitize_key( $_POST['preset'] ) : '';
8665
8666 // Handle reset to defaults
8667 if ( 'reset' === $preset ) {
8668 $stored_options = get_option( Vigilante_Settings::OPTION_NAME, array() );
8669 $defaults = Vigilante_Settings::get_defaults_preserving_user_data( $stored_options );
8670 $defaults = Vigilante_Settings::keep_locked_file_settings( $defaults, $stored_options );
8671 update_option( Vigilante_Settings::OPTION_NAME, $defaults );
8672 $this->settings->clear_cache();
8673
8674 // Clear active preset
8675 update_option( 'vigilante_active_preset', '' );
8676
8677 // Apply file changes after reset
8678 $this->apply_all_file_changes( $defaults );
8679
8680 wp_send_json_success( __( 'Settings reset to defaults.', 'vigilante' ) . $this->locked_file_settings_message() );
8681 return;
8682 }
8683
8684 $presets = $this->settings->get_presets();
8685
8686 if ( ! isset( $presets[ $preset ] ) ) {
8687 wp_send_json_error( __( 'Invalid preset.', 'vigilante' ) );
8688 }
8689
8690 $preset_options = $presets[ $preset ];
8691 unset( $preset_options['name'], $preset_options['description'] );
8692
8693 // Layer the preset on top of the user's CURRENT configuration, not on
8694 // top of defaults. This way applying a preset only changes the fields
8695 // the preset explicitly mentions; everything else stays as the user
8696 // had it. For example, applying Maximum will not flip HSTS off if the
8697 // user had it on — Maximum doesn't touch HSTS, so it's left alone.
8698 // Use "Reset to Defaults" if a clean slate is needed.
8699 $current = get_option( Vigilante_Settings::OPTION_NAME, array() );
8700 if ( ! is_array( $current ) ) {
8701 $current = array();
8702 }
8703 // Make sure all known keys exist before merging — the merge does not
8704 // invent keys that are missing on both sides.
8705 $current = Vigilante_Settings::merge_preset( $this->settings->get_default_options(), $current );
8706
8707 $merged = Vigilante_Settings::merge_preset( $current, $preset_options );
8708 $merged = Vigilante_Settings::keep_locked_file_settings( $merged, get_option( Vigilante_Settings::OPTION_NAME, array() ) );
8709
8710 update_option( Vigilante_Settings::OPTION_NAME, $merged );
8711 $this->settings->clear_cache();
8712
8713 // Save active preset
8714 update_option( 'vigilante_active_preset', $preset );
8715
8716 // Apply file changes after preset
8717 $this->apply_all_file_changes( $merged );
8718
8719 wp_send_json_success( __( 'Preset applied successfully.', 'vigilante' ) . $this->locked_file_settings_message() );
8720 }
8721
8722 /**
8723 * AJAX: Reset a specific section to defaults
8724 */
8725 public function ajax_reset_section() {
8726 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8727
8728 if ( ! current_user_can( 'manage_options' ) ) {
8729 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8730 }
8731
8732 $section = isset( $_POST['section'] ) ? sanitize_key( $_POST['section'] ) : '';
8733
8734 if ( empty( $section ) ) {
8735 wp_send_json_error( __( 'No section specified.', 'vigilante' ) );
8736 }
8737
8738 // Get current options and defaults. get_defaults_preserving_user_data()
8739 // applies the tweaks a fresh installation gets, so the button and a new
8740 // install agree, and keeps whatever the owner typed in.
8741 $current_options = $this->settings->get_all_options();
8742 $defaults = Vigilante_Settings::get_defaults_preserving_user_data( $current_options );
8743
8744 // Check if section exists in defaults
8745 if ( ! isset( $defaults[ $section ] ) ) {
8746 wp_send_json_error( __( 'Invalid section.', 'vigilante' ) );
8747 }
8748
8749 $new_values = $defaults[ $section ];
8750
8751 /*
8752 * On a subsite, the settings written to wp-config.php and .htaccess are
8753 * the main site's business. Resetting the local copy of those would only
8754 * make this screen disagree with the file, so they are carried over
8755 * untouched, and a section that is nothing but shared settings is not
8756 * reset at all. On the main site, a user without network rights keeps
8757 * the ones the shared files are built from as well (2.11.6).
8758 */
8759 $locked = Vigilante_Settings::get_locked_file_settings();
8760
8761 if ( isset( $locked[ $section ] ) && true === $locked[ $section ] ) {
8762 wp_send_json_error( Vigilante_Settings::get_shared_files_notice() );
8763 }
8764
8765 $current_options[ $section ] = $new_values;
8766 $current_options = Vigilante_Settings::keep_locked_file_settings( $current_options, get_option( Vigilante_Settings::OPTION_NAME, array() ) );
8767
8768 // Save
8769 update_option( Vigilante_Settings::OPTION_NAME, $current_options );
8770 $this->settings->clear_cache();
8771
8772 // Apply file changes if needed
8773 $this->apply_section_changes( $section, $current_options );
8774
8775 wp_send_json_success( array(
8776 'message' => __( 'Section reset to defaults.', 'vigilante' ),
8777 'section' => $section,
8778 'reload' => true,
8779 ) );
8780 }
8781
8782 /**
8783 * AJAX: Clear lockouts
8784 */
8785 public function ajax_clear_lockouts() {
8786 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8787
8788 if ( ! current_user_can( 'manage_options' ) ) {
8789 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8790 }
8791
8792 $ip = isset( $_POST['ip'] ) ? sanitize_text_field( wp_unslash( $_POST['ip'] ) ) : '';
8793
8794 if ( ! empty( $ip ) ) {
8795 $this->database->clear_lockout( $ip );
8796 } else {
8797 $this->database->clear_all_lockouts();
8798 }
8799
8800 wp_send_json_success( __( 'Lockouts cleared.', 'vigilante' ) );
8801 }
8802
8803 /**
8804 * AJAX: Clear logs
8805 */
8806 public function ajax_clear_logs() {
8807 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8808
8809 if ( ! current_user_can( 'manage_options' ) ) {
8810 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8811 }
8812
8813 if ( $this->activity_log ) {
8814 $result = $this->activity_log->clear_all_logs();
8815 if ( $result ) {
8816 wp_send_json_success( __( 'Logs cleared.', 'vigilante' ) );
8817 } else {
8818 wp_send_json_error( __( 'Failed to clear logs.', 'vigilante' ) );
8819 }
8820 } else {
8821 wp_send_json_error( __( 'Activity log not available.', 'vigilante' ) );
8822 }
8823 }
8824
8825 /**
8826 * AJAX: Run file integrity scan.
8827 *
8828 * Triggers the file integrity scan, which now also runs the closed plugins
8829 * check at the end when the `check_closed_plugins` toggle is on. Activity
8830 * log is passed through so Security Audit entries (both file-level and
8831 * plugin-status) are recorded from this entry point.
8832 */
8833 public function ajax_run_scan() {
8834 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8835
8836 if ( ! current_user_can( 'manage_options' ) ) {
8837 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8838 }
8839
8840 // Clear previous results before running new scan
8841 delete_option( 'vigilante_last_integrity_results' );
8842 delete_option( 'vigilante_last_integrity_scan' );
8843
8844 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database, $this->activity_log );
8845 $results = $file_integrity->run_scan();
8846
8847 // Save new results
8848 update_option( 'vigilante_last_integrity_scan', time() );
8849 update_option( 'vigilante_last_integrity_results', $results );
8850
8851 // On the main site the scan does compute the lines of wp-config.php and
8852 // .htaccess, for the network administrator. Somebody without network
8853 // rights gets the change and its sizes, not the lines.
8854 if ( $this->critical_approval_locked() && ! empty( $results['modified'] ) && is_array( $results['modified'] ) ) {
8855 foreach ( $results['modified'] as $index => $item ) {
8856 if ( is_array( $item ) && 'critical_config' === ( $item['type'] ?? '' ) ) {
8857 $results['modified'][ $index ]['diff'] = Vigilante_File_Integrity::network_only_diff();
8858 }
8859 }
8860 }
8861
8862 wp_send_json_success( array(
8863 'message' => __( 'Scan completed.', 'vigilante' ),
8864 'results' => $results,
8865 'ignored_count' => count( get_option( 'vigilante_ignored_files', array() ) ),
8866 ) );
8867 }
8868
8869 /**
8870 * AJAX: Clear scan results.
8871 *
8872 * Wipes visually everything inside "Last Scan Results": file scan findings
8873 * (Suspicious / Modified / Extra / Critical Config), file hashes and the
8874 * Closed + Removed Plugins block.
8875 *
8876 * Implementation detail to keep persistence intact:
8877 * - We delete the file scan options + hashes outright.
8878 * - For plugin status we ONLY delete the last_check timestamp — the state
8879 * map and the ignore list are preserved in DB. The render gates the
8880 * plugin_status subsections on last_check > 0, so they hide after
8881 * Clear (visual reset) and reappear on the next Run Scan Now with the
8882 * state intact. This avoids degrading a 'removed' slug (404 without
8883 * metadata) back to 'not_in_repo' on the next scan, which would
8884 * silently lose the alert.
8885 *
8886 * The Ignored Files list and the Ignored Closed + Removed Plugins list
8887 * are preserved on purpose; each has its own explicit "Clear All …"
8888 * button.
8889 */
8890 public function ajax_clear_scan() {
8891 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8892
8893 if ( ! current_user_can( 'manage_options' ) ) {
8894 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8895 }
8896
8897 $results = get_option( 'vigilante_last_integrity_results' );
8898 $scanned_at = get_option( 'vigilante_last_integrity_scan' );
8899
8900 delete_option( 'vigilante_last_integrity_results' );
8901 delete_option( 'vigilante_last_integrity_scan' );
8902
8903 /*
8904 * A pending change to wp-config.php or the root .htaccess is closed by
8905 * approving it, which takes the network. Clearing the results was one
8906 * more way to close it without, until the next scan: the ignore list was
8907 * shut in 2.11.8 and this button was left open, found by the cross
8908 * review of 2.11.8. So for somebody who cannot approve, those entries
8909 * stay and everything else goes.
8910 */
8911 // The findings about Vigilant's own files stay too: they report for the
8912 // whole network, and ignoring them already takes network rights.
8913 if ( $this->critical_approval_locked() && is_array( $results ) ) {
8914 $kept = array();
8915 $found = false;
8916 foreach ( array( 'modified', 'missing', 'suspicious', 'extra' ) as $bucket ) {
8917 $kept[ $bucket ] = array_values(
8918 array_filter(
8919 isset( $results[ $bucket ] ) && is_array( $results[ $bucket ] ) ? $results[ $bucket ] : array(),
8920 function ( $item ) {
8921 return is_array( $item ) && in_array( $item['type'] ?? '', array( 'critical_config', 'vigilante_self' ), true );
8922 }
8923 )
8924 );
8925 $found = $found || ! empty( $kept[ $bucket ] );
8926 }
8927
8928 if ( $found ) {
8929 $results = array_merge( $results, $kept );
8930 update_option( 'vigilante_last_integrity_results', $results );
8931 update_option( 'vigilante_last_integrity_scan', $scanned_at ? $scanned_at : time() );
8932 }
8933 }
8934
8935 if ( $this->database ) {
8936 $this->database->clear_file_hashes();
8937 }
8938
8939 // Visual reset of plugin_status block without touching the state map
8940 // or the ignored list. See PHPDoc above for the rationale.
8941 delete_option( 'vigilante_plugin_status_last_check' );
8942
8943 wp_send_json_success( __( 'Scan results cleared.', 'vigilante' ) );
8944 }
8945
8946 /**
8947 * AJAX: Ignore a file from scan results
8948 */
8949 public function ajax_ignore_file() {
8950 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8951
8952 if ( ! current_user_can( 'manage_options' ) ) {
8953 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8954 }
8955
8956 $file = isset( $_POST['file'] ) ? sanitize_text_field( wp_unslash( $_POST['file'] ) ) : '';
8957
8958 if ( empty( $file ) ) {
8959 wp_send_json_error( __( 'No file specified.', 'vigilante' ) );
8960 }
8961
8962 // A change to a shared file is closed by approving it, and approving it
8963 // takes the network. Ignoring it would close the same warning without.
8964 if ( $this->critical_approval_locked() && in_array( $file, array( 'wp-config.php', '.htaccess' ), true ) ) {
8965 wp_send_json_error( $this->critical_approval_notice() );
8966 }
8967
8968 // Vigilant's own files are never ignored, on any site: silencing the
8969 // check that says the security plugin was changed is the one button
8970 // an attacker would want on this screen. Since 3.0.0 those findings
8971 // are not rows of these tables either, so nothing in the interface
8972 // sends them here; this is the door, not the label.
8973 if ( Vigilante_Self_Integrity::is_own_file_path( $file ) ) {
8974 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' ) );
8975 }
8976
8977 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
8978 $file_integrity->ignore_file( $file );
8979
8980 // Also remove the file from stored scan results so UI updates
8981 $results = get_option( 'vigilante_last_integrity_results' );
8982 if ( $results ) {
8983 foreach ( array( 'modified', 'suspicious', 'extra' ) as $category ) {
8984 if ( ! empty( $results[ $category ] ) ) {
8985 $results[ $category ] = array_values(
8986 array_filter(
8987 $results[ $category ],
8988 function ( $item ) use ( $file ) {
8989 return ( is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item ) !== $file;
8990 }
8991 )
8992 );
8993 }
8994 }
8995 update_option( 'vigilante_last_integrity_results', $results );
8996 }
8997
8998 wp_send_json_success( __( 'File added to ignored list.', 'vigilante' ) );
8999 }
9000
9001 /**
9002 * AJAX: Stop ignoring a file
9003 */
9004 public function ajax_unignore_file() {
9005 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9006
9007 if ( ! current_user_can( 'manage_options' ) ) {
9008 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9009 }
9010
9011 $file = isset( $_POST['file'] ) ? sanitize_text_field( wp_unslash( $_POST['file'] ) ) : '';
9012
9013 if ( empty( $file ) ) {
9014 wp_send_json_error( __( 'No file specified.', 'vigilante' ) );
9015 }
9016
9017 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
9018 $file_integrity->unignore_file( $file );
9019
9020 wp_send_json_success( __( 'File removed from ignored list.', 'vigilante' ) );
9021 }
9022
9023 /**
9024 * AJAX: Bulk ignore multiple files at once
9025 *
9026 * Processes a single batch into ignored list and prunes them from the
9027 * stored scan results so the UI updates without a re-scan.
9028 */
9029 public function ajax_bulk_ignore_files() {
9030 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9031
9032 if ( ! current_user_can( 'manage_options' ) ) {
9033 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9034 }
9035
9036 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized below per-item.
9037 $raw_files = isset( $_POST['files'] ) ? wp_unslash( $_POST['files'] ) : array();
9038 if ( ! is_array( $raw_files ) ) {
9039 wp_send_json_error( __( 'Invalid request.', 'vigilante' ) );
9040 }
9041
9042 $files = array();
9043 $locked = $this->critical_approval_locked();
9044 $shared = $locked ? array( 'wp-config.php', '.htaccess' ) : array();
9045 foreach ( $raw_files as $f ) {
9046 $clean = sanitize_text_field( $f );
9047 // Same rule as ajax_ignore_file(): the two shared files when the
9048 // network locks them, and Vigilant's own files always.
9049 if ( '' !== $clean && ! in_array( $clean, $shared, true ) && ! Vigilante_Self_Integrity::is_own_file_path( $clean ) ) {
9050 $files[] = $clean;
9051 }
9052 }
9053
9054 if ( empty( $files ) ) {
9055 wp_send_json_error( __( 'No files selected.', 'vigilante' ) );
9056 }
9057
9058 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
9059 $count = 0;
9060 foreach ( $files as $file ) {
9061 $file_integrity->ignore_file( $file );
9062 $count++;
9063 }
9064
9065 // Also prune the stored scan results so the UI matches the new ignore list.
9066 $results = get_option( 'vigilante_last_integrity_results' );
9067 if ( $results ) {
9068 $files_set = array_flip( $files );
9069 foreach ( array( 'modified', 'suspicious', 'extra' ) as $category ) {
9070 if ( ! empty( $results[ $category ] ) ) {
9071 $results[ $category ] = array_values(
9072 array_filter(
9073 $results[ $category ],
9074 function ( $item ) use ( $files_set ) {
9075 $path = is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item;
9076 return ! isset( $files_set[ $path ] );
9077 }
9078 )
9079 );
9080 }
9081 }
9082 update_option( 'vigilante_last_integrity_results', $results );
9083 }
9084
9085 wp_send_json_success(
9086 array(
9087 'count' => $count,
9088 'message' => sprintf(
9089 /* translators: %d: number of files added to the ignored list */
9090 _n( '%d file added to ignored list.', '%d files added to ignored list.', $count, 'vigilante' ),
9091 $count
9092 ),
9093 )
9094 );
9095 }
9096
9097 /**
9098 * AJAX: Bulk un-ignore multiple files at once
9099 */
9100 public function ajax_bulk_unignore_files() {
9101 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9102
9103 if ( ! current_user_can( 'manage_options' ) ) {
9104 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9105 }
9106
9107 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized below per-item.
9108 $raw_files = isset( $_POST['files'] ) ? wp_unslash( $_POST['files'] ) : array();
9109 if ( ! is_array( $raw_files ) ) {
9110 wp_send_json_error( __( 'Invalid request.', 'vigilante' ) );
9111 }
9112
9113 $files = array();
9114 foreach ( $raw_files as $f ) {
9115 $clean = sanitize_text_field( $f );
9116 if ( '' !== $clean ) {
9117 $files[] = $clean;
9118 }
9119 }
9120
9121 if ( empty( $files ) ) {
9122 wp_send_json_error( __( 'No files selected.', 'vigilante' ) );
9123 }
9124
9125 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
9126 $count = 0;
9127 foreach ( $files as $file ) {
9128 $file_integrity->unignore_file( $file );
9129 $count++;
9130 }
9131
9132 wp_send_json_success(
9133 array(
9134 'count' => $count,
9135 'message' => sprintf(
9136 /* translators: %d: number of files removed from the ignored list */
9137 _n( '%d file removed from ignored list.', '%d files removed from ignored list.', $count, 'vigilante' ),
9138 $count
9139 ),
9140 )
9141 );
9142 }
9143
9144 /**
9145 * AJAX: Clear all ignored files
9146 */
9147 public function ajax_clear_ignored() {
9148 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9149
9150 if ( ! current_user_can( 'manage_options' ) ) {
9151 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9152 }
9153
9154 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
9155 $file_integrity->clear_ignored_files();
9156
9157 wp_send_json_success( __( 'Ignored files list cleared.', 'vigilante' ) );
9158 }
9159
9160 /**
9161 * AJAX: Ignore a closed/removed plugin slug so it stops appearing in the
9162 * main list and email digests. The plugin keeps running on the site;
9163 * silencing is purely cosmetic and reversible.
9164 */
9165 public function ajax_ignore_closed_plugin() {
9166 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9167
9168 if ( ! current_user_can( 'manage_options' ) ) {
9169 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9170 }
9171
9172 $slug = isset( $_POST['slug'] ) ? sanitize_key( wp_unslash( $_POST['slug'] ) ) : '';
9173 if ( '' === $slug ) {
9174 wp_send_json_error( __( 'No slug specified.', 'vigilante' ) );
9175 }
9176
9177 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
9178 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
9179 }
9180 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
9181 $checker->ignore_slug( $slug );
9182
9183 wp_send_json_success( __( 'Plugin added to the ignored list.', 'vigilante' ) );
9184 }
9185
9186 /**
9187 * AJAX: Stop ignoring a previously-ignored closed/removed plugin slug.
9188 */
9189 public function ajax_unignore_closed_plugin() {
9190 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9191
9192 if ( ! current_user_can( 'manage_options' ) ) {
9193 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9194 }
9195
9196 $slug = isset( $_POST['slug'] ) ? sanitize_key( wp_unslash( $_POST['slug'] ) ) : '';
9197 if ( '' === $slug ) {
9198 wp_send_json_error( __( 'No slug specified.', 'vigilante' ) );
9199 }
9200
9201 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
9202 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
9203 }
9204 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
9205 $checker->unignore_slug( $slug );
9206
9207 wp_send_json_success( __( 'Plugin removed from the ignored list.', 'vigilante' ) );
9208 }
9209
9210 /**
9211 * AJAX: Clear the entire ignored-closed-plugins list.
9212 */
9213 public function ajax_clear_ignored_closed_plugins() {
9214 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9215
9216 if ( ! current_user_can( 'manage_options' ) ) {
9217 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9218 }
9219
9220 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
9221 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
9222 }
9223 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
9224 $checker->clear_ignored();
9225
9226 wp_send_json_success( __( 'Ignored closed plugins list cleared.', 'vigilante' ) );
9227 }
9228
9229 /**
9230 * AJAX: Test security headers
9231 */
9232 public function ajax_test_headers() {
9233 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9234
9235 if ( ! current_user_can( 'manage_options' ) ) {
9236 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9237 }
9238
9239 // Get security grade from settings (not from actual HTTP request)
9240 $security_headers = new Vigilante_Security_Headers( $this->settings );
9241 $results = $security_headers->get_security_grade();
9242
9243 wp_send_json_success( $results );
9244 }
9245
9246 /**
9247 * Sanitize section data (kept for compatibility)
9248 *
9249 * @param string $section Section name.
9250 * @param array $data Section data.
9251 * @return array
9252 */
9253 private function sanitize_section_data( $section, $data ) {
9254 $sanitized = array();
9255
9256 foreach ( $data as $key => $value ) {
9257 $key = sanitize_key( $key );
9258
9259 if ( is_array( $value ) ) {
9260 $sanitized[ $key ] = $this->sanitize_section_data( $key, $value );
9261 } elseif ( is_numeric( $value ) ) {
9262 $sanitized[ $key ] = intval( $value );
9263 } else {
9264 $sanitized[ $key ] = sanitize_text_field( $value );
9265 }
9266 }
9267
9268 return $sanitized;
9269 }
9270
9271 /**
9272 * Apply changes after saving settings
9273 *
9274 * @param string $section Section that was updated.
9275 * @param array $all_options All options.
9276 */
9277 private function apply_section_changes( $section, $all_options ) {
9278 // Create fresh settings instance to ensure we have the latest data
9279 $fresh_settings = new Vigilante_Settings();
9280
9281 // The shared Vigilant .htaccess block carries BOTH the firewall's
9282 // file-protection rules and the server-signature / fingerprinting rules
9283 // that are configured under Security Headers. So it must be regenerated
9284 // whenever either section (or the module toggles) changes, not only on
9285 // the firewall save — otherwise toggling "Hide server signature" or
9286 // "Remove fingerprinting headers" never reaches the .htaccess.
9287 if ( in_array( $section, array( 'firewall', 'security_headers', 'modules' ), true ) ) {
9288 $htaccess = new Vigilante_Htaccess_Protection( $fresh_settings );
9289 $sh = $fresh_settings->get_section( 'security_headers' );
9290 $needs_htaccess_block = ! empty( $all_options['modules']['firewall'] )
9291 || ! empty( $sh['hide_server_signature'] )
9292 || ! empty( $sh['remove_fingerprinting_headers'] );
9293
9294 if ( $needs_htaccess_block ) {
9295 $htaccess->apply_rules();
9296 } else {
9297 $htaccess->remove_rules();
9298 }
9299 }
9300
9301 // Regenerate the HTTP security headers (sent by PHP) for the headers section.
9302 if ( 'security_headers' === $section || 'modules' === $section ) {
9303 $security_headers = new Vigilante_Security_Headers( $fresh_settings );
9304 $headers_enabled = ! empty( $all_options['modules']['security_headers'] );
9305
9306 if ( $headers_enabled ) {
9307 $security_headers->apply_rules();
9308 } else {
9309 $security_headers->remove_rules();
9310 }
9311 }
9312
9313 // Regenerate wp-config for wp_hardening section
9314 if ( 'wp_hardening' === $section || 'modules' === $section ) {
9315 $wpconfig = new Vigilante_Wpconfig_Security( $fresh_settings );
9316 $hardening_enabled = ! empty( $all_options['modules']['wp_hardening'] );
9317
9318 if ( $hardening_enabled ) {
9319 $wpconfig->apply_security_constants();
9320 } else {
9321 $wpconfig->remove_constants();
9322 }
9323
9324 // Apply WordPress options for comments/pingbacks
9325 $hardening_options = $all_options['wp_hardening'] ?? array();
9326
9327 if ( $hardening_enabled ) {
9328 // Pingbacks
9329 if ( ! empty( $hardening_options['disable_pingbacks'] ) ) {
9330 update_option( 'default_pingback_flag', 0 );
9331 } else {
9332 // Restore default: pingbacks enabled
9333 update_option( 'default_pingback_flag', 1 );
9334 }
9335
9336 // Trackbacks and ping status
9337 // Only close if either pingbacks OR trackbacks are disabled
9338 if ( ! empty( $hardening_options['disable_pingbacks'] ) || ! empty( $hardening_options['disable_trackbacks'] ) ) {
9339 update_option( 'default_ping_status', 'closed' );
9340 } else {
9341 // Restore default: pings open
9342 update_option( 'default_ping_status', 'open' );
9343 }
9344
9345 // Comment moderation
9346 if ( ! empty( $hardening_options['require_comment_moderation'] ) ) {
9347 update_option( 'comment_moderation', 1 );
9348 } else {
9349 // Restore default: no moderation required
9350 update_option( 'comment_moderation', 0 );
9351 }
9352 }
9353 }
9354
9355 // Trim activity log entries immediately when limits change
9356 if ( 'activity_log' === $section && $this->activity_log ) {
9357 $this->activity_log->cleanup_old_logs();
9358 }
9359
9360 // Flush rewrite rules if login URL changed
9361 if ( 'login_security' === $section ) {
9362 $login_options = $all_options['login_security'] ?? array();
9363 if ( ! empty( $login_options['custom_login_url'] ) ) {
9364 delete_option( 'vigilante_login_rules_version' );
9365 }
9366 }
9367
9368 // Log the settings change with readable section name
9369 if ( $this->activity_log ) {
9370 $section_names = array(
9371 'firewall' => __( 'Firewall', 'vigilante' ),
9372 'login_security' => __( 'Login Security', 'vigilante' ),
9373 'security_headers' => __( 'Security Headers', 'vigilante' ),
9374 'rest_api_security'=> __( 'REST API Security', 'vigilante' ),
9375 'user_security' => __( 'User Security', 'vigilante' ),
9376 'wp_hardening' => __( 'WP Hardening', 'vigilante' ),
9377 'activity_log' => __( 'Security Audit', 'vigilante' ),
9378 'file_integrity' => __( 'File Integrity', 'vigilante' ),
9379 'email' => __( 'Notification Settings', 'vigilante' ),
9380 'backup' => __( 'Backup', 'vigilante' ),
9381 'advanced' => __( 'Advanced', 'vigilante' ),
9382 'modules' => __( 'Modules', 'vigilante' ),
9383 );
9384 $display_name = isset( $section_names[ $section ] ) ? $section_names[ $section ] : $section;
9385
9386 $this->activity_log->log(
9387 'settings',
9388 'settings_updated',
9389 sprintf(
9390 /* translators: %s: Section name */
9391 __( 'Settings updated: %s', 'vigilante' ),
9392 $display_name
9393 ),
9394 array( 'section' => $section ),
9395 'info'
9396 );
9397 }
9398 }
9399
9400 /**
9401 * Apply all file changes (htaccess, wp-config) based on current options
9402 *
9403 * Used after preset, import, or reset operations
9404 *
9405 * @param array $all_options All plugin options.
9406 */
9407 private function apply_all_file_changes( $all_options ) {
9408 // Refresh settings cache first
9409 $this->settings->clear_cache();
9410
9411 // Create fresh settings instance
9412 $fresh_settings = new Vigilante_Settings();
9413
9414 // Apply firewall htaccess changes
9415 $htaccess = new Vigilante_Htaccess_Protection( $fresh_settings );
9416 $firewall_enabled = ! empty( $all_options['modules']['firewall'] );
9417
9418 if ( $firewall_enabled ) {
9419 $htaccess->apply_rules();
9420 } else {
9421 $htaccess->remove_rules();
9422 }
9423
9424 // Apply security headers htaccess changes
9425 $security_headers = new Vigilante_Security_Headers( $fresh_settings );
9426 $headers_enabled = ! empty( $all_options['modules']['security_headers'] );
9427
9428 if ( $headers_enabled ) {
9429 $security_headers->apply_rules();
9430 } else {
9431 $security_headers->remove_rules();
9432 }
9433
9434 // Apply wp-config changes
9435 $wpconfig = new Vigilante_Wpconfig_Security( $fresh_settings );
9436 $hardening_enabled = ! empty( $all_options['modules']['wp_hardening'] );
9437
9438 if ( $hardening_enabled ) {
9439 $wpconfig->apply_security_constants();
9440 } else {
9441 $wpconfig->remove_constants();
9442 }
9443
9444 // Apply WordPress options for comments/pingbacks
9445 $hardening_options = $all_options['wp_hardening'] ?? array();
9446
9447 if ( $hardening_enabled ) {
9448 // Pingbacks
9449 if ( ! empty( $hardening_options['disable_pingbacks'] ) ) {
9450 update_option( 'default_pingback_flag', 0 );
9451 } else {
9452 // Restore default: pingbacks enabled
9453 update_option( 'default_pingback_flag', 1 );
9454 }
9455
9456 // Trackbacks and ping status
9457 // Only close if either pingbacks OR trackbacks are disabled
9458 if ( ! empty( $hardening_options['disable_pingbacks'] ) || ! empty( $hardening_options['disable_trackbacks'] ) ) {
9459 update_option( 'default_ping_status', 'closed' );
9460 } else {
9461 // Restore default: pings open
9462 update_option( 'default_ping_status', 'open' );
9463 }
9464
9465 // Comment moderation
9466 if ( ! empty( $hardening_options['require_comment_moderation'] ) ) {
9467 update_option( 'comment_moderation', 1 );
9468 } else {
9469 // Restore default: no moderation required
9470 update_option( 'comment_moderation', 0 );
9471 }
9472 }
9473
9474 // Log the change
9475 if ( $this->activity_log ) {
9476 $this->activity_log->log(
9477 'settings',
9478 'bulk_settings_applied',
9479 __( 'Bulk settings applied (preset/import/reset)', 'vigilante' ),
9480 array(),
9481 'info'
9482 );
9483 }
9484 }
9485 }