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

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

9,331 lines 585.9 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="maintenance@example.com&#10;security@example.com"><?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 foreach ( $all_roles as $role_slug => $role_data ) :
4442 $user_count = count( get_users( array( 'role' => $role_slug, 'fields' => 'ID' ) ) );
4443 ?>
4444 <label>
4445 <input type="checkbox"
4446 name="login_security[two_factor][enforced_roles][]"
4447 value="<?php echo esc_attr( $role_slug ); ?>"
4448 <?php checked( in_array( $role_slug, $enforced, true ) ); ?>>
4449 <span class="role-name"><?php echo esc_html( translate_user_role( $role_data['name'] ) ); ?></span>
4450 <span class="role-count">(<?php echo esc_html( $user_count ); ?>)</span>
4451 </label>
4452 <?php endforeach; ?>
4453 </div>
4454 <p class="description"><?php esc_html_e( 'Users with these roles will be required to verify with the selected method.', 'vigilante' ); ?></p>
4455 </td>
4456 </tr>
4457 <tr>
4458 <th scope="row"><?php esc_html_e( 'Exclude specific users', 'vigilante' ); ?></th>
4459 <td>
4460 <div class="vigilante-2fa-user-search-container">
4461 <div class="vigilante-2fa-user-search">
4462 <span class="search-icon"></span>
4463 <input type="text"
4464 id="vigilante_2fa_user_search"
4465 placeholder="<?php esc_attr_e( 'Search users by name or email...', 'vigilante' ); ?>"
4466 autocomplete="off">
4467 <div class="vigilante-2fa-search-results"></div>
4468 </div>
4469 <div class="vigilante-2fa-excluded-users">
4470 <?php
4471 foreach ( $excluded as $user_id ) :
4472 $user = get_user_by( 'ID', $user_id );
4473 if ( ! $user ) continue;
4474 ?>
4475 <div class="vigilante-2fa-excluded-user" data-user-id="<?php echo esc_attr( $user_id ); ?>">
4476 <span class="user-display"><?php echo esc_html( $user->display_name . ' (' . $user->user_email . ')' ); ?></span>
4477 <button type="button" class="remove-user" aria-label="<?php esc_attr_e( 'Remove', 'vigilante' ); ?>">&times;</button>
4478 <input type="hidden" name="login_security[two_factor][excluded_users][]" value="<?php echo esc_attr( $user_id ); ?>">
4479 </div>
4480 <?php endforeach; ?>
4481 </div>
4482 </div>
4483 <p class="description"><?php esc_html_e( 'These users will not be required to use 2FA regardless of their role.', 'vigilante' ); ?></p>
4484 </td>
4485 </tr>
4486
4487 <!-- Remember device option -->
4488 <tr>
4489 <th scope="row"><?php esc_html_e( 'Remember device', 'vigilante' ); ?></th>
4490 <td>
4491 <label>
4492 <input type="checkbox" name="login_security[two_factor][allow_remember_device]" value="1" <?php checked( ! empty( $two_factor['allow_remember_device'] ) ); ?>>
4493 <?php esc_html_e( 'Allow users to skip 2FA verification on trusted devices', 'vigilante' ); ?>
4494 </label>
4495 <p class="description">
4496 <?php
4497 printf(
4498 /* translators: %d: Number of days */
4499 esc_html__( 'When enabled, users can check "Remember this device" on the verification screen to skip 2FA for %d days.', 'vigilante' ),
4500 absint( $two_factor['remember_device_days'] ?? 30 )
4501 );
4502 ?>
4503 </p>
4504 </td>
4505 </tr>
4506
4507 <!-- TOTP-specific: Grace period -->
4508 <tr class="vigilante-2fa-totp-only" <?php echo 'totp' !== $method ? 'style="display:none;"' : ''; ?>>
4509 <th scope="row"><label for="vigilante-f-login-security-two-factor-grace-period-days"><?php esc_html_e( 'Grace period', 'vigilante' ); ?></label></th>
4510 <td>
4511 <input id="vigilante-f-login-security-two-factor-grace-period-days" type="number"
4512 name="login_security[two_factor][grace_period_days]"
4513 value="<?php echo esc_attr( $grace_days ); ?>"
4514 min="0" max="30" class="small-text">
4515 <?php esc_html_e( 'days', 'vigilante' ); ?>
4516 <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>
4517 </td>
4518 </tr>
4519
4520 <!-- Email-specific: Sender name -->
4521 <tr class="vigilante-2fa-email-only" <?php echo 'email' !== $method ? 'style="display:none;"' : ''; ?>>
4522 <th scope="row"><label for="vigilante-f-login-security-two-factor-email-from-name"><?php esc_html_e( 'Email sender name', 'vigilante' ); ?></label></th>
4523 <td>
4524 <input id="vigilante-f-login-security-two-factor-email-from-name" type="text"
4525 name="login_security[two_factor][email_from_name]"
4526 value="<?php echo esc_attr( $two_factor['email_from_name'] ?? '' ); ?>"
4527 class="regular-text vigilante-2fa-email-from"
4528 placeholder="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>">
4529 <p class="description"><?php esc_html_e( 'Name shown in verification emails. Leave empty to use site name.', 'vigilante' ); ?></p>
4530 </td>
4531 </tr>
4532
4533 <!-- TOTP-specific: Reset users -->
4534 <tr class="vigilante-2fa-totp-only" <?php echo 'totp' !== $method ? 'style="display:none;"' : ''; ?>>
4535 <th scope="row"><?php esc_html_e( 'Reset user TOTP', 'vigilante' ); ?></th>
4536 <td>
4537 <div class="vigilante-totp-reset-container">
4538 <div class="vigilante-2fa-user-search">
4539 <span class="search-icon"></span>
4540 <input type="text"
4541 id="vigilante_totp_reset_search"
4542 placeholder="<?php esc_attr_e( 'Search users with TOTP configured...', 'vigilante' ); ?>"
4543 autocomplete="off">
4544 <div class="vigilante-totp-reset-results"></div>
4545 </div>
4546 <div class="vigilante-totp-reset-selected"></div>
4547 <button type="button" id="vigilante_totp_reset_btn" class="button" style="display:none;">
4548 <?php esc_html_e( 'Reset selected', 'vigilante' ); ?>
4549 </button>
4550 <span class="vigilante-totp-reset-status"></span>
4551 </div>
4552 <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>
4553 </td>
4554 </tr>
4555 </table>
4556
4557 <h3><?php esc_html_e( 'User notification', 'vigilante' ); ?></h3>
4558 <table class="form-table">
4559 <tr>
4560 <th scope="row"><?php esc_html_e( 'Notify on enable', 'vigilante' ); ?></th>
4561 <td>
4562 <label>
4563 <input type="checkbox" name="login_security[two_factor][notify_on_enable]" value="1" <?php checked( $two_factor['notify_on_enable'] ?? true ); ?>>
4564 <?php esc_html_e( 'Send notification email to affected users when 2FA is enabled', 'vigilante' ); ?>
4565 </label>
4566
4567 <div class="vigilante-2fa-notification-options">
4568 <label>
4569 <input type="radio" name="vigilante_2fa_notify_mode" value="all" checked>
4570 <?php esc_html_e( 'Send to all affected users', 'vigilante' ); ?>
4571 </label>
4572 <label>
4573 <input type="radio" name="vigilante_2fa_notify_mode" value="new">
4574 <?php esc_html_e( 'Send only to users not previously notified', 'vigilante' ); ?>
4575 </label>
4576 </div>
4577
4578 <div class="vigilante-2fa-send-notification">
4579 <button type="button" id="vigilante_2fa_send_notification" class="button">
4580 <?php esc_html_e( 'Send notification now', 'vigilante' ); ?>
4581 </button>
4582 <span class="vigilante-2fa-notification-status"></span>
4583 </div>
4584 </td>
4585 </tr>
4586 </table>
4587 </div>
4588 <?php
4589 }
4590
4591 /**
4592 * Render security headers tab
4593 */
4594 /**
4595 * Offer back the header settings the 2.9.8 migration wiped.
4596 *
4597 * Rendered outside the settings form on purpose, so its buttons can never
4598 * submit it, and only when there is something to actually change. Shows the
4599 * difference before anything is written: nothing is applied that the owner
4600 * has not seen first.
4601 *
4602 * @since 2.10.0
4603 */
4604 private function render_headers_recovery_offer() {
4605 /*
4606 * On a network the .htaccess belongs to every site and only the main one
4607 * writes it, so this is not a decision a subsite gets to make. Its own
4608 * security_headers options are inert anyway: what the network serves
4609 * comes from the file the main site owns. Without this gate a subsite
4610 * administrator was shown a Restore button that could only ever answer
4611 * with a permission error, which is worse than showing nothing.
4612 */
4613 if ( ! Vigilante_Settings::can_write_shared_files() ) {
4614 return;
4615 }
4616
4617 if ( ! Vigilante_Htaccess_Recovery::is_available() ) {
4618 /*
4619 * Already restored. Offer to take it back for as long as the previous
4620 * section is still stored: a restore that cannot be undone is a second
4621 * irreversible change on top of the one being repaired.
4622 */
4623 if ( Vigilante_Htaccess_Recovery::has_undo() ) {
4624 ?>
4625 <div class="notice notice-info inline" id="vigilante-headers-recovery-undo">
4626 <p>
4627 <?php esc_html_e( 'The Security Headers settings were restored from the copy Vigilant had kept of your .htaccess.', 'vigilante' ); ?>
4628 <button type="button" class="button button-small" id="vigilante-recovery-undo">
4629 <?php esc_html_e( 'Undo the restore', 'vigilante' ); ?>
4630 </button>
4631 </p>
4632 </div>
4633 <?php
4634 }
4635
4636 return;
4637 }
4638
4639 $rows = Vigilante_Htaccess_Recovery::get_diff( $this->settings );
4640
4641 if ( empty( $rows ) ) {
4642 return;
4643 }
4644
4645 $snapshot = Vigilante_Htaccess_Recovery::get_snapshot();
4646 $taken = isset( $snapshot['time'] ) ? (int) $snapshot['time'] : 0;
4647 $block = Vigilante_Htaccess_Recovery::get_raw_block();
4648 ?>
4649 <div class="vigilante-settings-section" id="vigilante-headers-recovery">
4650 <h2><?php esc_html_e( 'Recover your previous header settings', 'vigilante' ); ?></h2>
4651 <p>
4652 <?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' ); ?>
4653 </p>
4654 <?php if ( $taken ) : ?>
4655 <p class="description">
4656 <?php
4657 printf(
4658 /* translators: %s: date and time the .htaccess copy was taken. */
4659 esc_html__( 'Copy taken on %s.', 'vigilante' ),
4660 esc_html( wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $taken ) )
4661 );
4662 ?>
4663 </p>
4664 <?php endif; ?>
4665
4666 <table class="widefat striped">
4667 <thead>
4668 <tr>
4669 <th scope="col"><?php esc_html_e( 'Setting', 'vigilante' ); ?></th>
4670 <th scope="col"><?php esc_html_e( 'Now', 'vigilante' ); ?></th>
4671 <th scope="col"><?php esc_html_e( 'Would be restored to', 'vigilante' ); ?></th>
4672 </tr>
4673 </thead>
4674 <tbody>
4675 <?php foreach ( $rows as $row ) : ?>
4676 <tr>
4677 <th scope="row"><?php echo esc_html( $row['label'] ); ?></th>
4678 <td><?php echo esc_html( $row['current'] ); ?></td>
4679 <td>
4680 <?php echo esc_html( $row['recovered'] ); ?>
4681 <?php if ( ! empty( $row['detail'] ) ) : ?>
4682 <br><span class="description"><?php echo esc_html( $row['detail'] ); ?></span>
4683 <?php endif; ?>
4684 </td>
4685 </tr>
4686 <?php endforeach; ?>
4687 </tbody>
4688 </table>
4689
4690 <p class="description">
4691 <?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' ); ?>
4692 </p>
4693
4694 <?php if ( '' !== $block ) : ?>
4695 <details>
4696 <summary><?php esc_html_e( 'Show the saved .htaccess block', 'vigilante' ); ?></summary>
4697 <textarea readonly rows="12" class="large-text code" onclick="this.select();"><?php echo esc_textarea( $block ); ?></textarea>
4698 </details>
4699 <?php endif; ?>
4700
4701 <p class="submit vigilante-submit-buttons">
4702 <button type="button" class="button button-primary" id="vigilante-recovery-restore">
4703 <?php esc_html_e( 'Restore these settings', 'vigilante' ); ?>
4704 </button>
4705 <button type="button" class="button" id="vigilante-recovery-dismiss">
4706 <?php esc_html_e( 'No thanks, keep what I have', 'vigilante' ); ?>
4707 </button>
4708 </p>
4709 <div id="vigilante-recovery-result"></div>
4710 </div>
4711 <?php
4712 }
4713
4714 private function render_tab_headers() {
4715 $is_disabled = $this->render_module_disabled_notice( 'security_headers' );
4716 // Every setting on this tab ends up in .htaccess, so on a subsite the
4717 // whole tab is somebody else's, values included.
4718 $vg_shared_locked = $this->shared_files_locked();
4719 $options = $this->get_section_for_display( 'security_headers' );
4720 ?>
4721 <?php $this->render_headers_recovery_offer(); ?>
4722
4723 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="security_headers" <?php echo $is_disabled ? 'inert' : ''; ?>>
4724 <?php $this->render_shared_files_notice(); ?>
4725 <div id="vigilante-section-headers-main" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
4726 <h2>
4727 <?php esc_html_e( 'Security Headers', 'vigilante' ); ?>
4728 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
4729 </h2>
4730 <p><?php esc_html_e( 'HTTP headers sent with every response via .htaccess (mod_headers).', 'vigilante' ); ?></p>
4731
4732 <table class="form-table">
4733 <tr>
4734 <th scope="row"><label for="vigilante-f-security-headers-x-frame-options"><?php esc_html_e( 'X-Frame-Options', 'vigilante' ); ?></label></th>
4735 <td>
4736 <select id="vigilante-f-security-headers-x-frame-options" name="security_headers[x_frame_options]">
4737 <option value="" <?php selected( empty( $options['x_frame_options'] ) ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
4738 <option value="SAMEORIGIN" <?php selected( $options['x_frame_options'] ?? '', 'SAMEORIGIN' ); ?>>SAMEORIGIN</option>
4739 <option value="DENY" <?php selected( $options['x_frame_options'] ?? '', 'DENY' ); ?>>DENY</option>
4740 </select>
4741 <p class="description"><?php esc_html_e( '&#9432; Prevents clickjacking attacks. Also sets CSP frame-ancestors automatically.', 'vigilante' ); ?></p>
4742 </td>
4743 </tr>
4744 <tr>
4745 <th scope="row"><?php esc_html_e( 'X-Content-Type-Options', 'vigilante' ); ?></th>
4746 <td>
4747 <label>
4748 <input type="checkbox" name="security_headers[x_content_type_options]" value="1" <?php checked( ! empty( $options['x_content_type_options'] ) ); ?>>
4749 <?php esc_html_e( 'Add nosniff header to prevent MIME type sniffing', 'vigilante' ); ?>
4750 </label>
4751 </td>
4752 </tr>
4753 <tr>
4754 <th scope="row"><label for="vigilante-f-security-headers-referrer-policy"><?php esc_html_e( 'Referrer-Policy', 'vigilante' ); ?></label></th>
4755 <td>
4756 <select id="vigilante-f-security-headers-referrer-policy" name="security_headers[referrer_policy]">
4757 <option value="" <?php selected( empty( $options['referrer_policy'] ) ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
4758 <option value="no-referrer" <?php selected( $options['referrer_policy'] ?? '', 'no-referrer' ); ?>>no-referrer</option>
4759 <option value="strict-origin-when-cross-origin" <?php selected( $options['referrer_policy'] ?? '', 'strict-origin-when-cross-origin' ); ?>>strict-origin-when-cross-origin</option>
4760 <option value="same-origin" <?php selected( $options['referrer_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
4761 </select>
4762 </td>
4763 </tr>
4764 </table>
4765
4766 <h3 id="vigilante-section-headers-csp"><?php esc_html_e( 'Content Security Policy', 'vigilante' ); ?></h3>
4767 <table class="form-table">
4768 <tr>
4769 <th scope="row"><?php esc_html_e( 'Enable CSP', 'vigilante' ); ?></th>
4770 <td>
4771 <label>
4772 <input type="checkbox" name="security_headers[csp][enabled]" value="1" <?php checked( ! empty( $options['csp']['enabled'] ) ); ?>>
4773 <?php esc_html_e( 'Enable Content Security Policy', 'vigilante' ); ?>
4774 </label>
4775 </td>
4776 </tr>
4777 <tr>
4778 <th scope="row"><?php esc_html_e( 'Report Only Mode', 'vigilante' ); ?></th>
4779 <td>
4780 <label>
4781 <input type="checkbox" name="security_headers[csp][report_only]" value="1" <?php checked( ! empty( $options['csp']['report_only'] ) ); ?>>
4782 <?php esc_html_e( 'Report violations without blocking (for testing)', 'vigilante' ); ?>
4783 </label>
4784 </td>
4785 </tr>
4786 </table>
4787
4788 <h3 id="vigilante-section-headers-force-https"><?php esc_html_e( 'HTTPS', 'vigilante' ); ?></h3>
4789 <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>
4790 <table class="form-table">
4791 <tr>
4792 <th scope="row"><?php esc_html_e( 'Redirect HTTP to HTTPS', 'vigilante' ); ?></th>
4793 <td>
4794 <label>
4795 <input type="checkbox" name="security_headers[redirect_http_to_https]" value="1" <?php checked( ! empty( $options['redirect_http_to_https'] ) ); ?>>
4796 <?php esc_html_e( 'Send visitors arriving over HTTP to the HTTPS address', 'vigilante' ); ?>
4797 </label>
4798 <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>
4799 </td>
4800 </tr>
4801 <tr>
4802 <th scope="row"><?php esc_html_e( 'Fix Mixed Content', 'vigilante' ); ?></th>
4803 <td>
4804 <label>
4805 <input type="checkbox" name="security_headers[fix_mixed_content]" value="1" <?php checked( ! empty( $options['fix_mixed_content'] ) ); ?>>
4806 <?php esc_html_e( 'Rewrite this site http:// resources to https://', 'vigilante' ); ?>
4807 </label>
4808 <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>
4809 </td>
4810 </tr>
4811 <tr id="field-upgrade-insecure-requests">
4812 <th scope="row"><?php esc_html_e( 'Upgrade Insecure Requests', 'vigilante' ); ?></th>
4813 <td>
4814 <label>
4815 <input type="checkbox" name="security_headers[upgrade_insecure_requests]" value="1" <?php checked( ! empty( $options['upgrade_insecure_requests'] ) ); ?>>
4816 <?php esc_html_e( 'Ask browsers to upgrade every http:// request to https://', 'vigilante' ); ?>
4817 </label>
4818 <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>
4819 </td>
4820 </tr>
4821 <tr>
4822 <th scope="row"><?php esc_html_e( 'Rewrite Site Address on Activation', 'vigilante' ); ?></th>
4823 <td>
4824 <label>
4825 <input type="checkbox" name="security_headers[force_https]" value="1" <?php checked( ! empty( $options['force_https'] ) ); ?>>
4826 <?php esc_html_e( 'Change the WordPress and site addresses to https:// when the plugin is activated', 'vigilante' ); ?>
4827 </label>
4828 <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>
4829 </td>
4830 </tr>
4831 </table>
4832
4833 <h3 id="vigilante-section-headers-hsts"><?php esc_html_e( 'HSTS (HTTP Strict Transport Security)', 'vigilante' ); ?></h3>
4834 <?php $vig_home_https = ( 0 === strpos( (string) get_option( 'home' ), 'https://' ) ); ?>
4835 <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>
4836 <?php if ( ! $vig_home_https ) : ?>
4837 <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>
4838 <?php endif; ?>
4839 <table class="form-table">
4840 <tr>
4841 <th scope="row"><?php esc_html_e( 'Enable HSTS', 'vigilante' ); ?></th>
4842 <td>
4843 <?php if ( ! $vig_home_https ) : ?>
4844 <?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. */ ?>
4845 <input type="hidden" name="security_headers[hsts][enabled]" value="<?php echo ! empty( $options['hsts']['enabled'] ) ? '1' : '0'; ?>">
4846 <?php endif; ?>
4847 <label>
4848 <input type="checkbox" name="security_headers[hsts][enabled]" value="1" <?php checked( ! empty( $options['hsts']['enabled'] ) ); ?> <?php disabled( ! $vig_home_https ); ?>>
4849 <?php esc_html_e( 'Send the Strict-Transport-Security header', 'vigilante' ); ?>
4850 </label>
4851 <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>
4852 </td>
4853 </tr>
4854 <tr>
4855 <th scope="row"><label for="vigilante-f-security-headers-hsts-max-age"><?php esc_html_e( 'Max Age', 'vigilante' ); ?></label></th>
4856 <td>
4857 <select id="vigilante-f-security-headers-hsts-max-age" name="security_headers[hsts][max_age]">
4858 <option value="86400" <?php selected( $options['hsts']['max_age'] ?? 31536000, 86400 ); ?>><?php esc_html_e( '1 day (testing)', 'vigilante' ); ?></option>
4859 <option value="2592000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 2592000 ); ?>><?php esc_html_e( '30 days', 'vigilante' ); ?></option>
4860 <option value="31536000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 31536000 ); ?>><?php esc_html_e( '1 year (recommended)', 'vigilante' ); ?></option>
4861 <option value="63072000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 63072000 ); ?>><?php esc_html_e( '2 years', 'vigilante' ); ?></option>
4862 </select>
4863 </td>
4864 </tr>
4865 <tr>
4866 <th scope="row"><?php esc_html_e( 'Include Subdomains', 'vigilante' ); ?></th>
4867 <td>
4868 <label>
4869 <input type="checkbox" name="security_headers[hsts][include_subdomains]" value="1" <?php checked( ! empty( $options['hsts']['include_subdomains'] ) ); ?>>
4870 <?php esc_html_e( 'Apply HSTS to all subdomains', 'vigilante' ); ?>
4871 </label>
4872 </td>
4873 </tr>
4874 </table>
4875
4876 <h3 id="vigilante-section-headers-fingerprint"><?php esc_html_e( 'Server Identity', 'vigilante' ); ?></h3>
4877 <p class="description"><?php esc_html_e( 'Hide identifying information that servers expose in responses.', 'vigilante' ); ?></p>
4878 <table class="form-table">
4879 <tr>
4880 <th scope="row"><?php esc_html_e( 'Server Signature', 'vigilante' ); ?></th>
4881 <td>
4882 <label>
4883 <input type="checkbox" name="security_headers[hide_server_signature]" value="1" <?php checked( ! empty( $options['hide_server_signature'] ) ); ?>>
4884 <?php esc_html_e( 'Hide server signature (ServerSignature Off)', 'vigilante' ); ?>
4885 </label>
4886 </td>
4887 </tr>
4888 <tr>
4889 <th scope="row"><?php esc_html_e( 'Remove Fingerprinting Headers', 'vigilante' ); ?></th>
4890 <td>
4891 <label>
4892 <input type="checkbox" name="security_headers[remove_fingerprinting_headers]" value="1" <?php checked( ! empty( $options['remove_fingerprinting_headers'] ) ); ?>>
4893 <?php esc_html_e( 'Remove X-Powered-By and Server headers', 'vigilante' ); ?>
4894 </label>
4895 </td>
4896 </tr>
4897 </table>
4898 </div>
4899
4900 <?php $vg_cop = ( isset( $options['cross_origin_policies'] ) && is_array( $options['cross_origin_policies'] ) ) ? $options['cross_origin_policies'] : array(); ?>
4901 <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' : ''; ?>>
4902 <h2>
4903 <?php esc_html_e( 'Cross-Origin Policies', 'vigilante' ); ?>
4904 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
4905 </h2>
4906 <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>
4907
4908 <table class="form-table">
4909 <tr>
4910 <th scope="row"><label for="vigilante-f-security-headers-coop"><?php esc_html_e( 'Cross-Origin-Opener-Policy (COOP)', 'vigilante' ); ?></label></th>
4911 <td>
4912 <select id="vigilante-f-security-headers-coop" name="security_headers[cross_origin_policies][opener_policy]">
4913 <option value="" <?php selected( empty( $vg_cop['opener_policy'] ) ); ?>><?php esc_html_e( 'Disabled (header not sent)', 'vigilante' ); ?></option>
4914 <option value="unsafe-none" <?php selected( $vg_cop['opener_policy'] ?? '', 'unsafe-none' ); ?>>unsafe-none</option>
4915 <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>
4916 <option value="same-origin" <?php selected( $vg_cop['opener_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
4917 </select>
4918 <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>
4919 </td>
4920 </tr>
4921 <tr>
4922 <th scope="row"><label for="vigilante-f-security-headers-coep"><?php esc_html_e( 'Cross-Origin-Embedder-Policy (COEP)', 'vigilante' ); ?></label></th>
4923 <td>
4924 <select id="vigilante-f-security-headers-coep" name="security_headers[cross_origin_policies][embedder_policy]">
4925 <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>
4926 <option value="credentialless" <?php selected( $vg_cop['embedder_policy'] ?? '', 'credentialless' ); ?>>credentialless</option>
4927 <option value="require-corp" <?php selected( $vg_cop['embedder_policy'] ?? '', 'require-corp' ); ?>>require-corp</option>
4928 </select>
4929 <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>
4930 </td>
4931 </tr>
4932 <tr>
4933 <th scope="row"><label for="vigilante-f-security-headers-corp"><?php esc_html_e( 'Cross-Origin-Resource-Policy (CORP)', 'vigilante' ); ?></label></th>
4934 <td>
4935 <select id="vigilante-f-security-headers-corp" name="security_headers[cross_origin_policies][resource_policy]">
4936 <option value="" <?php selected( empty( $vg_cop['resource_policy'] ) ); ?>><?php esc_html_e( 'Disabled (header not sent)', 'vigilante' ); ?></option>
4937 <option value="same-site" <?php selected( $vg_cop['resource_policy'] ?? '', 'same-site' ); ?>>same-site</option>
4938 <option value="same-origin" <?php selected( $vg_cop['resource_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
4939 <option value="cross-origin" <?php selected( $vg_cop['resource_policy'] ?? '', 'cross-origin' ); ?>><?php esc_html_e( 'cross-origin (recommended)', 'vigilante' ); ?></option>
4940 </select>
4941 <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>
4942 </td>
4943 </tr>
4944 </table>
4945 </div>
4946
4947 <p class="submit vigilante-submit-buttons">
4948 <?php if ( ! $vg_shared_locked ) : ?>
4949 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4950 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4951 </button>
4952 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4953 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4954 </button>
4955 <?php endif; ?>
4956 <?php /* Testing what the server actually sends is read-only and useful from any site of a network. */ ?>
4957 <button type="button" class="button vigilante-test-headers">
4958 <?php esc_html_e( 'Test Headers', 'vigilante' ); ?>
4959 </button>
4960 </p>
4961 </form>
4962
4963 <div id="vigilante-headers-result"></div>
4964 <?php
4965 }
4966
4967 /**
4968 * Render REST API tab
4969 */
4970 private function render_tab_rest_api() {
4971 $is_disabled = $this->render_module_disabled_notice( 'rest_api_security' );
4972 $options = $this->settings->get_section( 'rest_api_security' );
4973 ?>
4974 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="rest_api_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
4975 <div id="vigilante-section-rest-api-main" class="vigilante-settings-section">
4976 <h2>
4977 <?php esc_html_e( 'REST API Security', 'vigilante' ); ?>
4978 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4979 </h2>
4980 <p><?php esc_html_e( 'Control access to WordPress REST API endpoints.', 'vigilante' ); ?></p>
4981
4982 <table class="form-table">
4983 <tr>
4984 <th scope="row"><label for="vigilante-f-rest-api-security-mode"><?php esc_html_e( 'Access Mode', 'vigilante' ); ?></label></th>
4985 <td>
4986 <select id="vigilante-f-rest-api-security-mode" name="rest_api_security[mode]">
4987 <option value="open" <?php selected( $options['mode'] ?? 'selective', 'open' ); ?>><?php esc_html_e( 'Open - Allow all requests', 'vigilante' ); ?></option>
4988 <option value="selective" <?php selected( $options['mode'] ?? 'selective', 'selective' ); ?>><?php esc_html_e( 'Selective - Protect sensitive endpoints', 'vigilante' ); ?></option>
4989 <option value="authenticated_only" <?php selected( $options['mode'] ?? 'selective', 'authenticated_only' ); ?>><?php esc_html_e( 'Authenticated - Require login for all', 'vigilante' ); ?></option>
4990 </select>
4991 <p class="description"><?php esc_html_e( 'Selective mode is recommended.', 'vigilante' ); ?></p>
4992 </td>
4993 </tr>
4994 <tr id="field-block-user-enumeration">
4995 <th scope="row"><?php esc_html_e( 'Block User Enumeration', 'vigilante' ); ?></th>
4996 <td>
4997 <label>
4998 <input type="checkbox" name="rest_api_security[block_user_enumeration]" value="1" <?php checked( ! empty( $options['block_user_enumeration'] ) ); ?>>
4999 <?php esc_html_e( 'Protect /wp/v2/users endpoint for unauthenticated users', 'vigilante' ); ?>
5000 </label>
5001 </td>
5002 </tr>
5003 <tr>
5004 <th scope="row"><?php esc_html_e( 'Disable JSONP', 'vigilante' ); ?></th>
5005 <td>
5006 <label>
5007 <input type="checkbox" name="rest_api_security[disable_jsonp]" value="1" <?php checked( ! empty( $options['disable_jsonp'] ) ); ?>>
5008 <?php esc_html_e( 'Disable JSONP support in REST API', 'vigilante' ); ?>
5009 </label>
5010 </td>
5011 </tr>
5012 </table>
5013 </div>
5014
5015 <p class="submit vigilante-submit-buttons">
5016 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5017 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5018 </button>
5019 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5020 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5021 </button>
5022 </p>
5023 </form>
5024 <?php
5025 }
5026
5027 /**
5028 * Render User Security tab
5029 */
5030 private function render_tab_users() {
5031 $is_disabled = $this->render_module_disabled_notice( 'user_security' );
5032 $options = $this->settings->get_section( 'user_security' );
5033 $monitoring = $options['admin_monitoring'] ?? array();
5034 $registration = $options['registration_approval'] ?? array();
5035 $session_limits = $options['session_limits'] ?? array();
5036 $password_exp = $options['password_expiration'] ?? array();
5037 $email_verify = $options['email_verification'] ?? array();
5038 ?>
5039
5040 <!-- ============================================================
5041 SETTINGS SECTION - Single form for all configuration
5042 ============================================================ -->
5043 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="user_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
5044
5045 <!-- Username & Password Protection -->
5046 <div id="vigilante-section-users-password" class="vigilante-settings-section">
5047 <h2>
5048 <?php esc_html_e( 'Username & password protection', 'vigilante' ); ?>
5049 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5050 </h2>
5051 <p><?php esc_html_e( 'Enforce secure username and password policies.', 'vigilante' ); ?></p>
5052
5053 <table class="form-table">
5054 <tr>
5055 <th scope="row"><?php esc_html_e( 'Block Insecure Usernames', 'vigilante' ); ?></th>
5056 <td>
5057 <label>
5058 <input type="checkbox" name="user_security[block_insecure_usernames]" value="1" <?php checked( ! empty( $options['block_insecure_usernames'] ) ); ?>>
5059 <?php esc_html_e( 'Prevent creation of users with common usernames (admin, administrator, etc.)', 'vigilante' ); ?>
5060 </label>
5061 </td>
5062 </tr>
5063 <?php
5064 $pw_policy = wp_parse_args(
5065 ( isset( $options['password_policy'] ) && is_array( $options['password_policy'] ) ) ? $options['password_policy'] : array(),
5066 array(
5067 'require_uppercase' => false,
5068 'require_lowercase' => false,
5069 'require_number' => false,
5070 'require_special' => false,
5071 'block_common' => true,
5072 'block_username' => true,
5073 'affected_roles' => array(),
5074 )
5075 );
5076 $pw_policy_roles = (array) $pw_policy['affected_roles'];
5077 ?>
5078 <tr>
5079 <th scope="row"><?php esc_html_e( 'Enforce Strong Passwords', 'vigilante' ); ?></th>
5080 <td>
5081 <label>
5082 <input type="checkbox" name="user_security[force_strong_passwords]" value="1" <?php checked( ! empty( $options['force_strong_passwords'] ) ); ?>>
5083 <?php esc_html_e( 'Check passwords against the requirements below when a user sets or changes one', 'vigilante' ); ?>
5084 </label>
5085 </td>
5086 </tr>
5087 <tr>
5088 <th scope="row"><label for="vigilante-f-user-security-min-password-length"><?php esc_html_e( 'Minimum Password Length', 'vigilante' ); ?></label></th>
5089 <td>
5090 <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">
5091 <?php esc_html_e( 'characters', 'vigilante' ); ?>
5092 </td>
5093 </tr>
5094 <tr>
5095 <th scope="row"><?php esc_html_e( 'Password Requirements', 'vigilante' ); ?></th>
5096 <td>
5097 <label style="display:block;margin-bottom:5px;">
5098 <input type="checkbox" name="user_security[password_policy][require_uppercase]" value="1" <?php checked( ! empty( $pw_policy['require_uppercase'] ) ); ?>>
5099 <?php esc_html_e( 'Require an uppercase letter (A-Z)', 'vigilante' ); ?>
5100 </label>
5101 <label style="display:block;margin-bottom:5px;">
5102 <input type="checkbox" name="user_security[password_policy][require_lowercase]" value="1" <?php checked( ! empty( $pw_policy['require_lowercase'] ) ); ?>>
5103 <?php esc_html_e( 'Require a lowercase letter (a-z)', 'vigilante' ); ?>
5104 </label>
5105 <label style="display:block;margin-bottom:5px;">
5106 <input type="checkbox" name="user_security[password_policy][require_number]" value="1" <?php checked( ! empty( $pw_policy['require_number'] ) ); ?>>
5107 <?php esc_html_e( 'Require a number (0-9)', 'vigilante' ); ?>
5108 </label>
5109 <label style="display:block;margin-bottom:5px;">
5110 <input type="checkbox" name="user_security[password_policy][require_special]" value="1" <?php checked( ! empty( $pw_policy['require_special'] ) ); ?>>
5111 <?php esc_html_e( 'Require a special character (!, @, #, ...)', 'vigilante' ); ?>
5112 </label>
5113 <label style="display:block;margin-bottom:5px;">
5114 <input type="checkbox" name="user_security[password_policy][block_common]" value="1" <?php checked( ! empty( $pw_policy['block_common'] ) ); ?>>
5115 <?php esc_html_e( 'Reject well-known common passwords', 'vigilante' ); ?>
5116 </label>
5117 <label style="display:block;margin-bottom:5px;">
5118 <input type="checkbox" name="user_security[password_policy][block_username]" value="1" <?php checked( ! empty( $pw_policy['block_username'] ) ); ?>>
5119 <?php esc_html_e( 'Do not allow the username inside the password', 'vigilante' ); ?>
5120 </label>
5121 <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>
5122 </td>
5123 </tr>
5124 <tr>
5125 <th scope="row"><?php esc_html_e( 'Apply Password Rules To', 'vigilante' ); ?></th>
5126 <td>
5127 <?php foreach ( wp_roles()->get_names() as $role_slug => $role_name ) : ?>
5128 <label style="display:block;margin-bottom:5px;">
5129 <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 ) ); ?>>
5130 <?php echo esc_html( translate_user_role( $role_name ) ); ?>
5131 </label>
5132 <?php endforeach; ?>
5133 <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>
5134 </td>
5135 </tr>
5136 <tr id="field-block-author-scanning">
5137 <th scope="row"><?php esc_html_e( 'Block Author Scanning', 'vigilante' ); ?></th>
5138 <td>
5139 <label>
5140 <input type="checkbox" name="user_security[block_author_scanning]" value="1" <?php checked( ! empty( $options['block_author_scanning'] ) ); ?>>
5141 <?php esc_html_e( 'Prevent username discovery via ?author=N URLs', 'vigilante' ); ?>
5142 </label>
5143 </td>
5144 </tr>
5145 <tr>
5146 <th scope="row"><?php esc_html_e( 'Display Name Protection', 'vigilante' ); ?></th>
5147 <td>
5148 <label>
5149 <input type="checkbox" name="user_security[prevent_display_name_login_match]" value="1" <?php checked( ! empty( $options['prevent_display_name_login_match'] ) ); ?>>
5150 <?php esc_html_e( 'Prevent users from saving a display name that matches their login username', 'vigilante' ); ?>
5151 </label>
5152 <p class="description"><?php esc_html_e( 'The display name is publicly visible and should not reveal the login username.', 'vigilante' ); ?></p>
5153 </td>
5154 </tr>
5155 </table>
5156 </div>
5157
5158 <!-- Admin Monitoring -->
5159 <div id="vigilante-section-users-admin-monitoring" class="vigilante-settings-section">
5160 <h2>
5161 <?php esc_html_e( 'Admin monitoring', 'vigilante' ); ?>
5162 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5163 </h2>
5164 <p><?php esc_html_e( 'Receive email alerts when administrator accounts are modified. All events are always logged to the Security Audit.', 'vigilante' ); ?></p>
5165
5166 <table class="form-table">
5167 <tr>
5168 <th scope="row"><?php esc_html_e( 'New Administrator Alert', 'vigilante' ); ?></th>
5169 <td>
5170 <label>
5171 <input type="checkbox" name="user_security[admin_monitoring][alert_new_admin]" value="1" <?php checked( ! empty( $monitoring['alert_new_admin'] ) ); ?>>
5172 <?php esc_html_e( 'Send email alert when a new administrator account is created', 'vigilante' ); ?>
5173 </label>
5174 </td>
5175 </tr>
5176 <tr>
5177 <th scope="row"><?php esc_html_e( 'Admin Email Change Alert', 'vigilante' ); ?></th>
5178 <td>
5179 <label>
5180 <input type="checkbox" name="user_security[admin_monitoring][alert_admin_email_change]" value="1" <?php checked( ! empty( $monitoring['alert_admin_email_change'] ) ); ?>>
5181 <?php esc_html_e( 'Send email alert when an administrator email address is changed', 'vigilante' ); ?>
5182 </label>
5183 </td>
5184 </tr>
5185 <tr>
5186 <th scope="row"><?php esc_html_e( 'Permission Elevation Alert', 'vigilante' ); ?></th>
5187 <td>
5188 <label>
5189 <input type="checkbox" name="user_security[admin_monitoring][alert_permission_elevation]" value="1" <?php checked( ! empty( $monitoring['alert_permission_elevation'] ) ); ?>>
5190 <?php esc_html_e( 'Send email alert when a user is elevated to administrator role', 'vigilante' ); ?>
5191 </label>
5192 </td>
5193 </tr>
5194 <tr>
5195 <th scope="row"><?php esc_html_e( 'Admin Password Change Alert', 'vigilante' ); ?></th>
5196 <td>
5197 <label>
5198 <input type="checkbox" name="user_security[admin_monitoring][alert_admin_password_change]" value="1" <?php checked( ! empty( $monitoring['alert_admin_password_change'] ) ); ?>>
5199 <?php esc_html_e( 'Send email alert when an administrator password is changed', 'vigilante' ); ?>
5200 </label>
5201 </td>
5202 </tr>
5203 </table>
5204
5205 <p class="description">
5206 <?php
5207 printf(
5208 /* translators: %s: Link to notification settings */
5209 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
5210 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
5211 );
5212 ?>
5213 </p>
5214 </div>
5215
5216 <!-- Registration Approval -->
5217 <div id="vigilante-section-users-registration" class="vigilante-settings-section">
5218 <h2>
5219 <?php esc_html_e( 'Registration approval', 'vigilante' ); ?>
5220 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5221 </h2>
5222 <p><?php esc_html_e( 'Require manual approval for new user registrations.', 'vigilante' ); ?></p>
5223
5224 <table class="form-table">
5225 <tr>
5226 <th scope="row"><?php esc_html_e( 'Enable Registration Approval', 'vigilante' ); ?></th>
5227 <td>
5228 <label>
5229 <input type="checkbox" name="user_security[registration_approval][enabled]" value="1" <?php checked( ! empty( $registration['enabled'] ) ); ?>>
5230 <?php esc_html_e( 'New users must be approved by an administrator before they can log in', 'vigilante' ); ?>
5231 </label>
5232 </td>
5233 </tr>
5234 <tr>
5235 <th scope="row"><?php esc_html_e( 'Notify Admin', 'vigilante' ); ?></th>
5236 <td>
5237 <label>
5238 <input type="checkbox" name="user_security[registration_approval][notify_admin]" value="1" <?php checked( ! empty( $registration['notify_admin'] ) ); ?>>
5239 <?php esc_html_e( 'Send email notification when a new user registers', 'vigilante' ); ?>
5240 </label>
5241 <p class="description"><?php esc_html_e( 'Disable on high-traffic sites to avoid email overload.', 'vigilante' ); ?></p>
5242 </td>
5243 </tr>
5244 <tr>
5245 <th scope="row"><label for="vigilante-f-user-security-registration-approval-auto-reject-days"><?php esc_html_e( 'Auto-reject After', 'vigilante' ); ?></label></th>
5246 <td>
5247 <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">
5248 <?php esc_html_e( 'days (0 = never)', 'vigilante' ); ?>
5249 <p class="description"><?php esc_html_e( 'Automatically reject pending registrations after this many days.', 'vigilante' ); ?></p>
5250 </td>
5251 </tr>
5252 </table>
5253 </div>
5254
5255 <!-- Session Limits -->
5256 <div id="vigilante-section-users-sessions" class="vigilante-settings-section">
5257 <h2>
5258 <?php esc_html_e( 'Session limits', 'vigilante' ); ?>
5259 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5260 </h2>
5261 <p><?php esc_html_e( 'Limit the number of simultaneous sessions per user.', 'vigilante' ); ?></p>
5262
5263 <?php if ( Vigilante_User_Security::session_limit_is_network_wide() ) : ?>
5264 <div class="notice notice-warning inline">
5265 <p>
5266 <?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' ); ?>
5267 </p>
5268 </div>
5269 <?php endif; ?>
5270
5271 <table class="form-table">
5272 <tr>
5273 <th scope="row"><?php esc_html_e( 'Enable Session Limits', 'vigilante' ); ?></th>
5274 <td>
5275 <label>
5276 <input type="checkbox" name="user_security[session_limits][enabled]" value="1" <?php checked( ! empty( $session_limits['enabled'] ) ); ?>>
5277 <?php esc_html_e( 'Limit the number of active sessions per user', 'vigilante' ); ?>
5278 </label>
5279 </td>
5280 </tr>
5281 <tr>
5282 <th scope="row"><label for="vigilante-f-user-security-session-limits-max-sessions"><?php esc_html_e( 'Maximum Sessions', 'vigilante' ); ?></label></th>
5283 <td>
5284 <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">
5285 <?php esc_html_e( 'sessions per user', 'vigilante' ); ?>
5286 </td>
5287 </tr>
5288 <tr>
5289 <th scope="row"><label for="vigilante-f-user-security-session-limits-behavior"><?php esc_html_e( 'When Limit Exceeded', 'vigilante' ); ?></label></th>
5290 <td>
5291 <select id="vigilante-f-user-security-session-limits-behavior" name="user_security[session_limits][behavior]">
5292 <option value="block_new" <?php selected( ( $session_limits['behavior'] ?? 'close_oldest' ), 'block_new' ); ?>><?php esc_html_e( 'Block new login', 'vigilante' ); ?></option>
5293 <option value="close_oldest" <?php selected( ( $session_limits['behavior'] ?? 'close_oldest' ), 'close_oldest' ); ?>><?php esc_html_e( 'Close oldest session', 'vigilante' ); ?></option>
5294 </select>
5295 <p class="description"><?php esc_html_e( '"Close oldest" is recommended for security - ensures attackers cannot lock out legitimate users.', 'vigilante' ); ?></p>
5296 </td>
5297 </tr>
5298 <tr>
5299 <th scope="row"><?php esc_html_e( 'Exclude Administrators', 'vigilante' ); ?></th>
5300 <td>
5301 <label>
5302 <input type="checkbox" name="user_security[session_limits][exclude_admins]" value="1" <?php checked( ! empty( $session_limits['exclude_admins'] ) ); ?>>
5303 <?php esc_html_e( 'Do not apply session limits to administrators', 'vigilante' ); ?>
5304 </label>
5305 </td>
5306 </tr>
5307 </table>
5308 </div>
5309
5310 <!-- Password Expiration -->
5311 <div id="vigilante-section-users-password-exp" class="vigilante-settings-section">
5312 <h2>
5313 <?php esc_html_e( 'Password expiration', 'vigilante' ); ?>
5314 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5315 </h2>
5316 <p><?php esc_html_e( 'Force users to change their password periodically.', 'vigilante' ); ?></p>
5317
5318 <table class="form-table">
5319 <tr>
5320 <th scope="row"><?php esc_html_e( 'Enable Password Expiration', 'vigilante' ); ?></th>
5321 <td>
5322 <label>
5323 <input type="checkbox" name="user_security[password_expiration][enabled]" value="1" <?php checked( ! empty( $password_exp['enabled'] ) ); ?>>
5324 <?php esc_html_e( 'Force password change after a set number of days', 'vigilante' ); ?>
5325 </label>
5326 </td>
5327 </tr>
5328 <tr>
5329 <th scope="row"><label for="vigilante-f-user-security-password-expiration-expire-days"><?php esc_html_e( 'Expire After', 'vigilante' ); ?></label></th>
5330 <td>
5331 <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">
5332 <?php esc_html_e( 'days', 'vigilante' ); ?>
5333 <p class="description"><?php esc_html_e( 'PCI-DSS recommends 90 days.', 'vigilante' ); ?></p>
5334 </td>
5335 </tr>
5336 <tr>
5337 <th scope="row"><label for="vigilante-f-user-security-password-expiration-warning-days"><?php esc_html_e( 'Warning Period', 'vigilante' ); ?></label></th>
5338 <td>
5339 <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">
5340 <?php esc_html_e( 'days before expiration', 'vigilante' ); ?>
5341 <p class="description"><?php esc_html_e( 'Show warning notice this many days before password expires.', 'vigilante' ); ?></p>
5342 </td>
5343 </tr>
5344 <tr>
5345 <th scope="row"><label for="vigilante-f-user-security-password-expiration-password-history"><?php esc_html_e( 'Password History', 'vigilante' ); ?></label></th>
5346 <td>
5347 <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">
5348 <?php esc_html_e( 'passwords to remember', 'vigilante' ); ?>
5349 <p class="description"><?php esc_html_e( 'Prevent reusing recent passwords. Set to 0 to disable.', 'vigilante' ); ?></p>
5350 </td>
5351 </tr>
5352 <tr>
5353 <th scope="row"><?php esc_html_e( 'Email Reminder', 'vigilante' ); ?></th>
5354 <td>
5355 <label>
5356 <input type="checkbox" name="user_security[password_expiration][send_reminder]" value="1" <?php checked( ! empty( $password_exp['send_reminder'] ) ); ?>>
5357 <?php esc_html_e( 'Send email reminder when password is about to expire', 'vigilante' ); ?>
5358 </label>
5359 <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>
5360 </td>
5361 </tr>
5362 <tr>
5363 <th scope="row"><?php esc_html_e( 'Affected Roles', 'vigilante' ); ?></th>
5364 <td>
5365 <?php
5366 $affected_roles = $password_exp['affected_roles'] ?? array( 'administrator', 'editor' );
5367 $all_roles = wp_roles()->get_names();
5368 foreach ( $all_roles as $role_slug => $role_name ) :
5369 ?>
5370 <label style="display: block; margin-bottom: 5px;">
5371 <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 ) ); ?>>
5372 <?php echo esc_html( translate_user_role( $role_name ) ); ?>
5373 </label>
5374 <?php endforeach; ?>
5375 </td>
5376 </tr>
5377 <tr>
5378 <th scope="row"><?php esc_html_e( 'Exclude specific users', 'vigilante' ); ?></th>
5379 <td>
5380 <?php $pwexp_excluded = $password_exp['excluded_users'] ?? array(); ?>
5381 <div class="vigilante-2fa-user-search-container">
5382 <div class="vigilante-2fa-user-search">
5383 <span class="search-icon"></span>
5384 <input type="text"
5385 id="vigilante_pwexp_user_search"
5386 placeholder="<?php esc_attr_e( 'Search users by name or email...', 'vigilante' ); ?>"
5387 autocomplete="off">
5388 <div class="vigilante-pwexp-search-results"></div>
5389 </div>
5390 <div class="vigilante-pwexp-excluded-users">
5391 <?php
5392 foreach ( $pwexp_excluded as $pwexp_excluded_id ) :
5393 $excluded_user = get_user_by( 'ID', $pwexp_excluded_id );
5394 if ( ! $excluded_user ) {
5395 continue;
5396 }
5397 ?>
5398 <div class="vigilante-pwexp-excluded-user" data-user-id="<?php echo esc_attr( $pwexp_excluded_id ); ?>">
5399 <span class="user-display"><?php echo esc_html( $excluded_user->display_name . ' (' . $excluded_user->user_email . ')' ); ?></span>
5400 <button type="button" class="remove-user" aria-label="<?php esc_attr_e( 'Remove', 'vigilante' ); ?>">&times;</button>
5401 <input type="hidden" name="user_security[password_expiration][excluded_users][]" value="<?php echo esc_attr( $pwexp_excluded_id ); ?>">
5402 </div>
5403 <?php endforeach; ?>
5404 </div>
5405 </div>
5406 <p class="description"><?php esc_html_e( 'Listed users will be excluded from password expiration regardless of their role.', 'vigilante' ); ?></p>
5407 </td>
5408 </tr>
5409 </table>
5410 </div>
5411
5412 <!-- Email Verification -->
5413 <div id="vigilante-section-users-email-verify" class="vigilante-settings-section">
5414 <h2>
5415 <?php esc_html_e( 'Email verification', 'vigilante' ); ?>
5416 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5417 </h2>
5418 <p><?php esc_html_e( 'Require new users to verify their email address before logging in.', 'vigilante' ); ?></p>
5419
5420 <table class="form-table">
5421 <tr>
5422 <th scope="row"><?php esc_html_e( 'Enable Email Verification', 'vigilante' ); ?></th>
5423 <td>
5424 <label>
5425 <input type="checkbox" name="user_security[email_verification][enabled]" value="1" <?php checked( ! empty( $email_verify['enabled'] ) ); ?>>
5426 <?php esc_html_e( 'New users must verify their email before logging in', 'vigilante' ); ?>
5427 </label>
5428 </td>
5429 </tr>
5430 <tr>
5431 <th scope="row"><label for="vigilante-f-user-security-email-verification-token-expiry-hours"><?php esc_html_e( 'Link Expiration', 'vigilante' ); ?></label></th>
5432 <td>
5433 <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">
5434 <?php esc_html_e( 'hours', 'vigilante' ); ?>
5435 </td>
5436 </tr>
5437 <tr>
5438 <th scope="row"><?php esc_html_e( 'Allow Resend', 'vigilante' ); ?></th>
5439 <td>
5440 <label>
5441 <input type="checkbox" name="user_security[email_verification][allow_resend]" value="1" <?php checked( ! empty( $email_verify['allow_resend'] ) ); ?>>
5442 <?php esc_html_e( 'Allow users to request a new verification email', 'vigilante' ); ?>
5443 </label>
5444 </td>
5445 </tr>
5446 <tr>
5447 <th scope="row"><label for="vigilante-f-user-security-email-verification-auto-delete-days"><?php esc_html_e( 'Auto-delete Unverified', 'vigilante' ); ?></label></th>
5448 <td>
5449 <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">
5450 <?php esc_html_e( 'days (0 = never)', 'vigilante' ); ?>
5451 <p class="description"><?php esc_html_e( 'Automatically delete users who never verify their email.', 'vigilante' ); ?></p>
5452 </td>
5453 </tr>
5454 </table>
5455 </div>
5456
5457 <p class="submit vigilante-submit-buttons">
5458 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5459 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5460 </button>
5461 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5462 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5463 </button>
5464 </p>
5465 </form>
5466
5467 <!-- ============================================================
5468 TOOLS SECTION - Actions and utilities (no save button)
5469 ============================================================ -->
5470 <div class="vigilante-tools-section">
5471 <h2 class="vigilante-tools-header">
5472 <?php esc_html_e( 'User security tools', 'vigilante' ); ?>
5473 </h2>
5474
5475 <?php $this->render_user_actions_notice(); ?>
5476 <?php if ( ! $this->user_actions_locked() ) : ?>
5477
5478 <!-- Force Password Reset -->
5479 <div class="vigilante-tool-box">
5480 <h3><?php esc_html_e( 'Force password reset', 'vigilante' ); ?></h3>
5481 <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>
5482
5483 <!-- Reset Specific Users -->
5484 <div class="vigilante-password-reset-box">
5485 <h4><?php esc_html_e( 'Reset specific users', 'vigilante' ); ?></h4>
5486
5487 <div class="vigilante-user-search-wrapper">
5488 <input type="text" id="vigilante-password-reset-search" class="regular-text" placeholder="<?php esc_attr_e( 'Search by username, email, or display name...', 'vigilante' ); ?>">
5489 <div id="vigilante-password-reset-results" class="vigilante-user-search-results" style="display: none;"></div>
5490 </div>
5491
5492 <div id="vigilante-password-reset-selected" class="vigilante-selected-users" style="display: none;">
5493 <strong><?php esc_html_e( 'Selected Users:', 'vigilante' ); ?></strong>
5494 <ul class="vigilante-selected-users-list"></ul>
5495 </div>
5496
5497 <p class="description" style="margin-top: 15px;">
5498 <span class="dashicons dashicons-email-alt" style="color: #2271b1;"></span>
5499 <?php esc_html_e( 'Selected users will receive an email with a password reset link.', 'vigilante' ); ?>
5500 </p>
5501
5502 <p class="submit">
5503 <button type="button" id="vigilante-reset-selected-users" class="button button-primary" disabled>
5504 <?php esc_html_e( 'Force Reset for Selected Users', 'vigilante' ); ?>
5505 </button>
5506 </p>
5507 </div>
5508
5509 <!-- Reset by Role -->
5510 <div class="vigilante-password-reset-box" style="margin-top: 20px; padding-top: 20px; border-top: 1px solid #ddd;">
5511 <h4><?php esc_html_e( 'Reset by role', 'vigilante' ); ?></h4>
5512 <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>
5513
5514 <?php
5515 $wp_roles = wp_roles();
5516 $user_counts = count_users();
5517 $avail_roles = $user_counts['avail_roles'] ?? array();
5518 $current_user = wp_get_current_user();
5519 $current_roles = $current_user->roles;
5520 ?>
5521
5522 <fieldset class="vigilante-role-checkboxes" style="margin-top: 10px;">
5523 <?php foreach ( $wp_roles->roles as $role_slug => $role_data ) :
5524 $count = $avail_roles[ $role_slug ] ?? 0;
5525 if ( 0 === $count ) {
5526 continue;
5527 }
5528 $role_name = translate_user_role( $role_data['name'] );
5529 ?>
5530 <label style="display: block; margin-bottom: 6px;">
5531 <input type="checkbox"
5532 class="vigilante-reset-role-checkbox"
5533 value="<?php echo esc_attr( $role_slug ); ?>"
5534 data-count="<?php echo absint( $count ); ?>">
5535 <?php
5536 printf(
5537 /* translators: 1: Role name, 2: Number of users */
5538 '%1$s <span class="description">(%2$d)</span>',
5539 esc_html( $role_name ),
5540 absint( $count )
5541 );
5542 ?>
5543 <?php if ( in_array( $role_slug, $current_roles, true ) ) : ?>
5544 <em class="description"><?php esc_html_e( '(includes you)', 'vigilante' ); ?></em>
5545 <?php endif; ?>
5546 </label>
5547 <?php endforeach; ?>
5548 </fieldset>
5549
5550 <div id="vigilante-reset-role-summary" style="display: none; margin-top: 10px;">
5551 <p>
5552 <span class="dashicons dashicons-groups" style="color: #2271b1;"></span>
5553 <strong id="vigilante-reset-role-count">0</strong>
5554 <?php esc_html_e( 'user(s) will be affected.', 'vigilante' ); ?>
5555 </p>
5556 </div>
5557
5558 <div class="vigilante-password-reset-options" id="vigilante-reset-role-self-option" style="display: none; margin-top: 10px;">
5559 <label>
5560 <input type="checkbox" id="vigilante-reset-role-include-self" value="1">
5561 <?php esc_html_e( 'Include myself (your current session will end)', 'vigilante' ); ?>
5562 </label>
5563 </div>
5564
5565 <p class="submit">
5566 <button type="button" id="vigilante-reset-by-role" class="button button-primary" disabled>
5567 <?php esc_html_e( 'Force Reset for Selected Roles', 'vigilante' ); ?>
5568 </button>
5569 </p>
5570 </div>
5571
5572 <!-- Reset All Users -->
5573 <div class="vigilante-password-reset-box" style="margin-top: 20px; padding-top: 20px; border-top: 1px solid #ddd;">
5574 <h4><?php esc_html_e( 'Reset all users', 'vigilante' ); ?></h4>
5575
5576 <?php
5577 $total_users = count_users();
5578 $total_count = $total_users['total_users'];
5579 ?>
5580 <p>
5581 <?php
5582 printf(
5583 /* translators: %d: Number of users */
5584 esc_html__( 'This will affect %d user(s).', 'vigilante' ),
5585 absint( $total_count )
5586 );
5587 ?>
5588 </p>
5589
5590 <p class="description" style="color: #d63638;">
5591 <span class="dashicons dashicons-warning"></span>
5592 <?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' ); ?>
5593 </p>
5594
5595 <div class="vigilante-password-reset-options" style="margin-top: 10px;">
5596 <label>
5597 <input type="checkbox" id="vigilante-reset-all-include-self" value="1">
5598 <?php esc_html_e( 'Include myself (your current session will end)', 'vigilante' ); ?>
5599 </label>
5600 </div>
5601
5602 <p class="submit">
5603 <button type="button" id="vigilante-reset-all-users" class="button" style="color: #d63638; border-color: #d63638;">
5604 <?php esc_html_e( 'Force Reset for ALL Users', 'vigilante' ); ?>
5605 </button>
5606 </p>
5607 </div>
5608 </div>
5609
5610 <!-- Pending Registrations -->
5611 <?php
5612 // Enforcement-only: this instance exists to read the queue, and the
5613 // flag keeps it from registering the module's own hooks a second
5614 // time. It is not inert, and saying it was would be a false comment:
5615 // init_enforcement_hooks() does add its three filters again, on top
5616 // of the ones already registered. They are idempotent (the same
5617 // methods of an equivalent instance, deciding on the same user meta),
5618 // so running them twice in an admin request changes nothing, which is
5619 // why this is accepted rather than worked around.
5620 $user_security = new Vigilante_User_Security( $this->settings, $this->activity_log, true );
5621 $pending_users = $user_security->get_pending_users();
5622 ?>
5623 <div id="vigilante-section-users-pending" class="vigilante-tool-box vigilante-pending-users-section">
5624 <h3>
5625 <?php esc_html_e( 'Pending registrations', 'vigilante' ); ?>
5626 <?php if ( count( $pending_users ) > 0 ) : ?>
5627 <span class="vigilante-badge vigilante-badge-warning"><?php echo esc_html( count( $pending_users ) ); ?></span>
5628 <?php endif; ?>
5629 </h3>
5630
5631 <?php
5632 /*
5633 * The queue is shown whenever there is somebody in it, even with
5634 * the feature off. Since 2.11.10 an account already waiting stays
5635 * blocked when the feature is switched off, which is the point:
5636 * turning a setting off must not quietly let in people an
5637 * administrator decided not to approve. But hiding the table then
5638 * left them locked out with no button anywhere to approve or
5639 * reject them. Found by the cross review of 2.11.10.
5640 */
5641 ?>
5642 <?php if ( empty( $registration['enabled'] ) && empty( $pending_users ) ) : ?>
5643 <p class="description">
5644 <span class="dashicons dashicons-info" style="color: #72aee6;"></span>
5645 <?php esc_html_e( 'Registration approval is disabled. Enable it in the settings above to require manual approval for new users.', 'vigilante' ); ?>
5646 </p>
5647 <?php elseif ( empty( $pending_users ) ) : ?>
5648 <div class="vigilante-no-lockouts">
5649 <span class="dashicons dashicons-yes-alt"></span>
5650 <p><?php esc_html_e( 'No pending registrations.', 'vigilante' ); ?></p>
5651 </div>
5652 <?php else : ?>
5653 <?php $this->render_user_actions_notice(); ?>
5654 <table class="wp-list-table widefat fixed striped vigilante-pending-users-table">
5655 <thead>
5656 <tr>
5657 <th><?php esc_html_e( 'User', 'vigilante' ); ?></th>
5658 <th><?php esc_html_e( 'Email', 'vigilante' ); ?></th>
5659 <th><?php esc_html_e( 'Registered', 'vigilante' ); ?></th>
5660 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5661 </tr>
5662 </thead>
5663 <tbody>
5664 <?php foreach ( $pending_users as $pending_user ) :
5665 $pending_since = get_user_meta( $pending_user->ID, Vigilante_User_Security::site_user_meta_key( 'vigilante_pending_since' ), true );
5666 ?>
5667 <tr data-user-id="<?php echo esc_attr( $pending_user->ID ); ?>">
5668 <td>
5669 <?php echo get_avatar( $pending_user->ID, 32 ); ?>
5670 <strong><?php echo esc_html( $pending_user->user_login ); ?></strong>
5671 </td>
5672 <td><?php echo esc_html( $pending_user->user_email ); ?></td>
5673 <td>
5674 <?php
5675 if ( $pending_since ) {
5676 /* translators: %s: Time ago */
5677 printf( esc_html__( '%s ago', 'vigilante' ), esc_html( human_time_diff( $pending_since ) ) );
5678 } else {
5679 echo esc_html( $pending_user->user_registered );
5680 }
5681 ?>
5682 </td>
5683 <td>
5684 <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() ); ?>>
5685 <?php esc_html_e( 'Approve', 'vigilante' ); ?>
5686 </button>
5687 <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() ); ?>>
5688 <?php esc_html_e( 'Reject', 'vigilante' ); ?>
5689 </button>
5690 </td>
5691 </tr>
5692 <?php endforeach; ?>
5693 </tbody>
5694 </table>
5695 <?php endif; ?>
5696 </div>
5697
5698 <!-- Active Sessions Management -->
5699 <div class="vigilante-tool-box vigilante-session-management-section">
5700 <h3><?php esc_html_e( 'Active sessions', 'vigilante' ); ?></h3>
5701 <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>
5702
5703 <!-- Current user sessions -->
5704 <h4><?php esc_html_e( 'Your sessions', 'vigilante' ); ?></h4>
5705 <?php
5706 $current_user_id = get_current_user_id();
5707 $my_sessions = $user_security->get_user_sessions( $current_user_id );
5708 $has_corrupted = $user_security->has_corrupted_sessions( $current_user_id );
5709 $raw_count = $user_security->get_raw_session_count( $current_user_id );
5710 ?>
5711
5712 <?php if ( $has_corrupted && $raw_count > 0 ) : ?>
5713 <div class="notice notice-warning inline" style="margin: 10px 0;">
5714 <p>
5715 <span class="dashicons dashicons-warning" style="color: #dba617;"></span>
5716 <?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' ); ?>
5717 </p>
5718 </div>
5719 <?php endif; ?>
5720
5721 <?php if ( empty( $my_sessions ) ) : ?>
5722 <p class="description"><?php esc_html_e( 'No active sessions found.', 'vigilante' ); ?></p>
5723 <?php if ( $has_corrupted ) : ?>
5724 <p style="margin-top: 10px;">
5725 <button type="button" class="button vigilante-revoke-other-sessions" data-user-id="<?php echo esc_attr( $current_user_id ); ?>">
5726 <?php esc_html_e( 'Clean Up Corrupted Sessions', 'vigilante' ); ?>
5727 </button>
5728 </p>
5729 <?php endif; ?>
5730 <?php else : ?>
5731 <div class="vigilante-paginated-section">
5732 <div class="vigilante-fi-pagination-wrap"></div>
5733 <table class="wp-list-table widefat fixed striped vigilante-sessions-table vigilante-fi-paginated">
5734 <thead>
5735 <tr>
5736 <th><?php esc_html_e( 'Browser', 'vigilante' ); ?></th>
5737 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
5738 <th><?php esc_html_e( 'Login Time', 'vigilante' ); ?></th>
5739 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5740 </tr>
5741 </thead>
5742 <tbody>
5743 <?php foreach ( $my_sessions as $session ) : ?>
5744 <tr data-token="<?php echo esc_attr( $session['token_hash'] ); ?>">
5745 <td><?php echo esc_html( $session['browser'] ); ?></td>
5746 <td><code><?php echo esc_html( $session['ip'] ); ?></code></td>
5747 <td>
5748 <?php
5749 if ( $session['login'] ) {
5750 /* translators: %s: Time ago */
5751 printf( esc_html__( '%s ago', 'vigilante' ), esc_html( human_time_diff( $session['login'] ) ) );
5752 } else {
5753 esc_html_e( 'Unknown', 'vigilante' );
5754 }
5755 ?>
5756 </td>
5757 <td>
5758 <?php if ( ! $session['is_current'] ) : ?>
5759 <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'] ); ?>">
5760 <?php esc_html_e( 'Revoke', 'vigilante' ); ?>
5761 </button>
5762 <?php else : ?>
5763 <span class="description"><?php esc_html_e( 'Current session', 'vigilante' ); ?></span>
5764 <?php endif; ?>
5765 </td>
5766 </tr>
5767 <?php endforeach; ?>
5768 </tbody>
5769 </table>
5770 </div>
5771
5772 <?php if ( count( $my_sessions ) > 1 || $has_corrupted ) : ?>
5773 <p style="margin-top: 10px;">
5774 <button type="button" class="button vigilante-revoke-other-sessions" data-user-id="<?php echo esc_attr( $current_user_id ); ?>">
5775 <?php esc_html_e( 'Revoke All Other Sessions', 'vigilante' ); ?>
5776 </button>
5777 </p>
5778 <?php endif; ?>
5779 <?php endif; ?>
5780
5781 <!-- Search user sessions (admin only) -->
5782 <h4 style="margin-top: 30px;"><?php esc_html_e( 'Manage user sessions', 'vigilante' ); ?></h4>
5783 <p class="description"><?php esc_html_e( 'Search for a user to view and manage their sessions.', 'vigilante' ); ?></p>
5784
5785 <div class="vigilante-user-search-wrapper" style="margin-top: 10px;">
5786 <input type="text" id="vigilante-session-user-search" class="regular-text" placeholder="<?php esc_attr_e( 'Search by username or email...', 'vigilante' ); ?>">
5787 <div id="vigilante-session-search-results" class="vigilante-user-search-results" style="display: none;"></div>
5788 </div>
5789
5790 <div id="vigilante-user-sessions-container" style="display: none; margin-top: 20px;">
5791 <h4 id="vigilante-sessions-user-name"></h4>
5792 <table class="wp-list-table widefat fixed striped vigilante-sessions-table">
5793 <thead>
5794 <tr>
5795 <th><?php esc_html_e( 'Browser', 'vigilante' ); ?></th>
5796 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
5797 <th><?php esc_html_e( 'Login Time', 'vigilante' ); ?></th>
5798 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5799 </tr>
5800 </thead>
5801 <tbody id="vigilante-user-sessions-list">
5802 </tbody>
5803 </table>
5804 <p style="margin-top: 10px;">
5805 <button type="button" class="button vigilante-revoke-all-user-sessions" style="color: #d63638;">
5806 <?php esc_html_e( 'Revoke All Sessions', 'vigilante' ); ?>
5807 </button>
5808 </p>
5809 </div>
5810 </div>
5811
5812 <?php endif; ?>
5813 </div>
5814 <?php
5815 }
5816
5817 /**
5818 * Render WordPress Hardening tab
5819 */
5820 private function render_tab_wp_hardening() {
5821 $is_disabled = $this->render_module_disabled_notice( 'wp_hardening' );
5822 $options = $this->settings->get_section( 'wp_hardening' );
5823 ?>
5824 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="wp_hardening" <?php echo $is_disabled ? 'inert' : ''; ?>>
5825 <!-- Database Hardening (outside form save flow - uses its own AJAX action) -->
5826 <?php $vg_shared_locked = $this->shared_files_locked(); ?>
5827 <?php $this->render_shared_files_notice(); ?>
5828 <div id="vigilante-section-hardening-database" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
5829 <h2>
5830 <?php esc_html_e( 'Database Hardening', 'vigilante' ); ?>
5831 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
5832 <span class="vigilante-method-badge config"><?php esc_html_e( 'WP-CONFIG', 'vigilante' ); ?></span>
5833 </h2>
5834 <p><?php esc_html_e( 'Change the database table prefix to prevent SQL injection attacks that target default WordPress tables.', 'vigilante' ); ?></p>
5835
5836 <?php
5837 $db_prefix = new Vigilante_Database_Prefix();
5838 $current_prefix = $db_prefix->get_current_prefix();
5839 $is_default = $db_prefix->is_default_prefix();
5840 ?>
5841
5842 <?php if ( is_multisite() && ! $vg_shared_locked ) : ?>
5843 <div class="notice notice-warning inline" style="margin:10px 0 16px;padding:8px 12px;">
5844 <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>
5845 </div>
5846 <?php endif; ?>
5847
5848 <table class="form-table">
5849 <tr>
5850 <th scope="row"><?php esc_html_e( 'Current prefix', 'vigilante' ); ?></th>
5851 <td>
5852 <code class="vigilante-db-current-prefix"><?php echo esc_html( $current_prefix ); ?></code>
5853 <?php if ( $is_default ) : ?>
5854 <span class="vigilante-inline-warning">
5855 <span class="dashicons dashicons-warning"></span>
5856 <?php esc_html_e( 'Default prefix detected. Changing it adds a layer of protection against automated SQL injection attacks.', 'vigilante' ); ?>
5857 </span>
5858 <?php else : ?>
5859 <span class="vigilante-inline-ok">
5860 <span class="dashicons dashicons-yes-alt"></span>
5861 <?php esc_html_e( 'Custom prefix in use.', 'vigilante' ); ?>
5862 </span>
5863 <?php endif; ?>
5864 </td>
5865 </tr>
5866 <tr>
5867 <th scope="row"><?php esc_html_e( 'New prefix', 'vigilante' ); ?></th>
5868 <td>
5869 <div class="vigilante-db-prefix-row">
5870 <code class="vigilante-db-new-prefix" id="vigilante-new-prefix"><?php echo esc_html( $db_prefix->generate_prefix() ); ?></code>
5871 <button type="button" class="button button-small vigilante-db-regenerate-prefix" title="<?php esc_attr_e( 'Generate new prefix', 'vigilante' ); ?>">
5872 <span class="dashicons dashicons-update"></span>
5873 </button>
5874 </div>
5875 </td>
5876 </tr>
5877 <tr>
5878 <th scope="row"></th>
5879 <td>
5880 <div class="vigilante-db-prefix-confirm">
5881 <label>
5882 <input type="checkbox" id="vigilante-prefix-backup-confirm">
5883 <?php esc_html_e( 'I understand this operation is irreversible and I have a current database backup', 'vigilante' ); ?>
5884 </label>
5885 <p class="description">
5886 <?php
5887 printf(
5888 /* translators: %s: Link to tools tab */
5889 esc_html__( 'Need a backup? %s first.', 'vigilante' ),
5890 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Download a database backup', 'vigilante' ) . '</a>'
5891 );
5892 ?>
5893 </p>
5894 </div>
5895 <button type="button" class="button button-primary vigilante-db-change-prefix" disabled data-original-text="<?php esc_attr_e( 'Change Database Prefix', 'vigilante' ); ?>">
5896 <?php esc_html_e( 'Change Database Prefix', 'vigilante' ); ?>
5897 </button>
5898 </td>
5899 </tr>
5900 </table>
5901 </div>
5902
5903 <!-- wp-config Security -->
5904 <?php
5905 $vg_shared_locked = $this->shared_files_locked();
5906 // Paint what is actually in force, not this site's unused copy.
5907 $vg_local_options = $options;
5908 $options = $this->get_section_for_display( 'wp_hardening' );
5909 ?>
5910 <?php $this->render_shared_files_notice(); ?>
5911 <div id="vigilante-section-hardening-wpconfig" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
5912 <h2>
5913 <?php esc_html_e( 'wp-config.php Security', 'vigilante' ); ?>
5914 <span class="vigilante-method-badge config"><?php esc_html_e( 'WP-CONFIG', 'vigilante' ); ?></span>
5915 </h2>
5916 <p><?php esc_html_e( 'Security constants added directly to wp-config.php file.', 'vigilante' ); ?></p>
5917
5918 <table class="form-table">
5919 <tr>
5920 <th scope="row"><?php esc_html_e( 'Disable File Editor', 'vigilante' ); ?></th>
5921 <td>
5922 <label>
5923 <input type="checkbox" name="wp_hardening[disallow_file_edit]" value="1" <?php checked( ! empty( $options['disallow_file_edit'] ) ); ?>>
5924 <?php esc_html_e( 'Disable plugin and theme editor in admin (DISALLOW_FILE_EDIT)', 'vigilante' ); ?>
5925 </label>
5926 </td>
5927 </tr>
5928 <tr>
5929 <th scope="row"><?php esc_html_e( 'Disable File Modifications', 'vigilante' ); ?></th>
5930 <td>
5931 <label>
5932 <input type="checkbox" name="wp_hardening[disallow_file_mods]" value="1" <?php checked( ! empty( $options['disallow_file_mods'] ) ); ?>>
5933 <?php esc_html_e( 'Disable all file modifications including updates (DISALLOW_FILE_MODS)', 'vigilante' ); ?>
5934 </label>
5935 <p class="description"><?php esc_html_e( '&#9888; Warning: This prevents automatic updates.', 'vigilante' ); ?></p>
5936 </td>
5937 </tr>
5938 <tr id="field-force-ssl-admin">
5939 <th scope="row"><?php esc_html_e( 'Force SSL Admin', 'vigilante' ); ?></th>
5940 <td>
5941 <label>
5942 <input type="checkbox" name="wp_hardening[force_ssl_admin]" value="1" <?php checked( ! empty( $options['force_ssl_admin'] ) ); ?>>
5943 <?php esc_html_e( 'Force HTTPS for admin area (FORCE_SSL_ADMIN)', 'vigilante' ); ?>
5944 </label>
5945 <p class="description"><?php esc_html_e( '&#9888; Warning: Only enable if your site fully supports HTTPS.', 'vigilante' ); ?></p>
5946 </td>
5947 </tr>
5948 <tr id="field-wp-debug">
5949 <th scope="row"><?php esc_html_e( 'Hide PHP errors from visitors', 'vigilante' ); ?></th>
5950 <td>
5951 <label>
5952 <input type="checkbox" name="wp_hardening[wp_debug]" value="1" <?php checked( ! empty( $options['wp_debug'] ) ); ?>>
5953 <?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' ); ?>
5954 </label>
5955 </td>
5956 </tr>
5957 <tr id="field-disable-wp-cron">
5958 <th scope="row"><?php esc_html_e( 'Disable WP Cron', 'vigilante' ); ?></th>
5959 <td>
5960 <label>
5961 <input type="checkbox" name="wp_hardening[disable_wp_cron]" value="1" <?php checked( ! empty( $options['disable_wp_cron'] ) ); ?>>
5962 <?php esc_html_e( 'Disable WordPress\'s page-view cron trigger (DISABLE_WP_CRON)', 'vigilante' ); ?>
5963 </label>
5964 <p class="description"><?php
5965 printf(
5966 /* translators: 1: opening <strong>, 2: closing </strong>, 3: opening <code>, 4: closing </code> */
5967 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' ),
5968 '<strong>',
5969 '</strong>',
5970 '<code>',
5971 '</code>'
5972 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
5973 ?></p>
5974 </td>
5975 </tr>
5976 </table>
5977 </div>
5978 <?php $options = $vg_local_options; ?>
5979
5980 <!-- Comment Security -->
5981 <div id="vigilante-section-hardening-xmlrpc" class="vigilante-settings-section">
5982 <h2>
5983 <?php esc_html_e( 'XML-RPC', 'vigilante' ); ?>
5984 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5985 </h2>
5986 <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>
5987
5988 <table class="form-table">
5989 <tr id="field-disable-xmlrpc">
5990 <th scope="row"><label for="vigilante-f-wp-hardening-xmlrpc-mode"><?php esc_html_e( 'XML-RPC access', 'vigilante' ); ?></label></th>
5991 <td>
5992 <?php $vig_xmlrpc_mode = Vigilante_Comment_Security::resolve_xmlrpc_mode( $this->settings ); ?>
5993 <select id="vigilante-f-wp-hardening-xmlrpc-mode" name="wp_hardening[xmlrpc_mode]">
5994 <option value="none" <?php selected( $vig_xmlrpc_mode, 'none' ); ?>>
5995 <?php esc_html_e( 'Leave XML-RPC enabled', 'vigilante' ); ?>
5996 </option>
5997 <option value="pingback" <?php selected( $vig_xmlrpc_mode, 'pingback' ); ?>>
5998 <?php esc_html_e( 'Block the pingback methods only', 'vigilante' ); ?>
5999 </option>
6000 <option value="full" <?php selected( $vig_xmlrpc_mode, 'full' ); ?>>
6001 <?php esc_html_e( 'Disable XML-RPC completely (recommended)', 'vigilante' ); ?>
6002 </option>
6003 </select>
6004 <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>
6005 </td>
6006 </tr>
6007 </table>
6008 </div>
6009
6010 <div id="vigilante-section-hardening-comments" class="vigilante-settings-section">
6011 <h2>
6012 <?php esc_html_e( 'Comment Security', 'vigilante' ); ?>
6013 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
6014 <span class="vigilante-method-badge settings"><?php esc_html_e( 'Settings', 'vigilante' ); ?></span>
6015 </h2>
6016 <p><?php esc_html_e( 'Comment protection using WordPress settings and PHP hooks.', 'vigilante' ); ?></p>
6017
6018 <table class="form-table">
6019 <tr>
6020 <th scope="row"><?php esc_html_e( 'Disable Pingbacks', 'vigilante' ); ?></th>
6021 <td>
6022 <label>
6023 <input type="checkbox" name="wp_hardening[disable_pingbacks]" value="1" <?php checked( ! empty( $options['disable_pingbacks'] ) ); ?>>
6024 <?php esc_html_e( 'Disable pingbacks (commonly exploited for DDoS)', 'vigilante' ); ?>
6025 </label>
6026 </td>
6027 </tr>
6028 <tr>
6029 <th scope="row"><?php esc_html_e( 'Disable Trackbacks', 'vigilante' ); ?></th>
6030 <td>
6031 <label>
6032 <input type="checkbox" name="wp_hardening[disable_trackbacks]" value="1" <?php checked( ! empty( $options['disable_trackbacks'] ) ); ?>>
6033 <?php esc_html_e( 'Disable trackbacks (rarely used legitimately)', 'vigilante' ); ?>
6034 </label>
6035 </td>
6036 </tr>
6037 <tr>
6038 <th scope="row"><?php esc_html_e( 'Require Moderation', 'vigilante' ); ?></th>
6039 <td>
6040 <label>
6041 <input type="checkbox" name="wp_hardening[require_comment_moderation]" value="1" <?php checked( ! empty( $options['require_comment_moderation'] ) ); ?>>
6042 <?php esc_html_e( 'All comments must be manually approved', 'vigilante' ); ?>
6043 </label>
6044 </td>
6045 </tr>
6046 <tr>
6047 <th scope="row"><?php esc_html_e( 'Close Old Comments', 'vigilante' ); ?></th>
6048 <td>
6049 <label>
6050 <input type="checkbox" name="wp_hardening[close_old_comments]" value="1" <?php checked( ! empty( $options['close_old_comments'] ) ); ?>>
6051 <?php esc_html_e( 'Automatically close comments on old posts after', 'vigilante' ); ?>
6052 </label>
6053 <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">
6054 <label for="vigilante-f-wp-hardening-close-comments-after-days"><?php esc_html_e( 'days', 'vigilante' ); ?></label>
6055 </td>
6056 </tr>
6057 <tr>
6058 <th scope="row"><?php esc_html_e( 'Honeypot Protection', 'vigilante' ); ?></th>
6059 <td>
6060 <label>
6061 <input type="checkbox" name="wp_hardening[honeypot_comments]" value="1" <?php checked( ! empty( $options['honeypot_comments'] ) ); ?>>
6062 <?php esc_html_e( 'Add hidden honeypot field to catch bots', 'vigilante' ); ?>
6063 </label>
6064 </td>
6065 </tr>
6066 </table>
6067 </div>
6068
6069 <!-- Head Cleaner -->
6070 <div id="vigilante-section-hardening-headers" class="vigilante-settings-section">
6071 <h2>
6072 <?php esc_html_e( 'Header Cleanup', 'vigilante' ); ?>
6073 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
6074 </h2>
6075 <p><?php esc_html_e( 'Remove meta tags from HTML head.', 'vigilante' ); ?></p>
6076
6077 <table class="form-table">
6078 <tr>
6079 <th scope="row"><?php esc_html_e( 'Remove Generator', 'vigilante' ); ?></th>
6080 <td>
6081 <label>
6082 <input type="checkbox" name="wp_hardening[remove_wp_generator]" value="1" <?php checked( ! empty( $options['remove_wp_generator'] ) ); ?>>
6083 <?php esc_html_e( 'Remove WordPress version from HTML head', 'vigilante' ); ?>
6084 </label>
6085 </td>
6086 </tr>
6087 <tr id="field-remove-wp-version-assets">
6088 <th scope="row"><?php esc_html_e( 'Remove version from assets', 'vigilante' ); ?></th>
6089 <td>
6090 <label>
6091 <input type="checkbox" name="wp_hardening[remove_wp_version_assets]" value="1" <?php checked( ! empty( $options['remove_wp_version_assets'] ) ); ?>>
6092 <?php esc_html_e( 'Remove WordPress version from script/style URLs (?ver=)', 'vigilante' ); ?>
6093 </label>
6094 <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>
6095 </td>
6096 </tr>
6097 <tr>
6098 <th scope="row"><?php esc_html_e( 'Remove RSD Link', 'vigilante' ); ?></th>
6099 <td>
6100 <label>
6101 <input type="checkbox" name="wp_hardening[remove_rsd_link]" value="1" <?php checked( ! empty( $options['remove_rsd_link'] ) ); ?>>
6102 <?php esc_html_e( 'Remove Really Simple Discovery link', 'vigilante' ); ?>
6103 </label>
6104 </td>
6105 </tr>
6106 <tr>
6107 <th scope="row"><?php esc_html_e( 'Remove WLW Manifest', 'vigilante' ); ?></th>
6108 <td>
6109 <label>
6110 <input type="checkbox" name="wp_hardening[remove_wlw_manifest]" value="1" <?php checked( ! empty( $options['remove_wlw_manifest'] ) ); ?>>
6111 <?php esc_html_e( 'Remove Windows Live Writer manifest link', 'vigilante' ); ?>
6112 </label>
6113 </td>
6114 </tr>
6115 <tr>
6116 <th scope="row"><?php esc_html_e( 'Remove Shortlink', 'vigilante' ); ?></th>
6117 <td>
6118 <label>
6119 <input type="checkbox" name="wp_hardening[remove_shortlink]" value="1" <?php checked( ! empty( $options['remove_shortlink'] ) ); ?>>
6120 <?php esc_html_e( 'Remove shortlink tag from header', 'vigilante' ); ?>
6121 </label>
6122 </td>
6123 </tr>
6124 <tr>
6125 <th scope="row"><?php esc_html_e( 'Remove REST API Link', 'vigilante' ); ?></th>
6126 <td>
6127 <label>
6128 <input type="checkbox" name="wp_hardening[remove_rest_api_link]" value="1" <?php checked( ! empty( $options['remove_rest_api_link'] ) ); ?>>
6129 <?php esc_html_e( 'Remove REST API discovery link from header', 'vigilante' ); ?>
6130 </label>
6131 <p class="description"><?php esc_html_e( '&#9888; Notice: Some plugins may need this link.', 'vigilante' ); ?></p>
6132 </td>
6133 </tr>
6134 </table>
6135 </div>
6136
6137 <!-- Feed Manager -->
6138 <div id="vigilante-section-hardening-rss" class="vigilante-settings-section">
6139 <h2>
6140 <?php esc_html_e( 'RSS Feed Settings', 'vigilante' ); ?>
6141 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
6142 </h2>
6143 <p><?php esc_html_e( 'Control RSS/Atom feeds.', 'vigilante' ); ?></p>
6144
6145 <table class="form-table">
6146 <tr>
6147 <th scope="row"><?php esc_html_e( 'Disable Feeds', 'vigilante' ); ?></th>
6148 <td>
6149 <label>
6150 <input type="checkbox" name="wp_hardening[disable_feeds]" value="1" <?php checked( ! empty( $options['disable_feeds'] ) ); ?>>
6151 <?php esc_html_e( 'Completely disable RSS/Atom feeds', 'vigilante' ); ?>
6152 </label>
6153 </td>
6154 </tr>
6155 <tr>
6156 <th scope="row"><?php esc_html_e( 'Disable If No Content', 'vigilante' ); ?></th>
6157 <td>
6158 <label>
6159 <input type="checkbox" name="wp_hardening[disable_if_no_content]" value="1" <?php checked( ! empty( $options['disable_if_no_content'] ) ); ?>>
6160 <?php esc_html_e( 'Only disable feeds if site has no published posts', 'vigilante' ); ?>
6161 </label>
6162 </td>
6163 </tr>
6164 <tr>
6165 <th scope="row"><?php esc_html_e( 'Remove Feed Version', 'vigilante' ); ?></th>
6166 <td>
6167 <label>
6168 <input type="checkbox" name="wp_hardening[remove_feed_version]" value="1" <?php checked( ! empty( $options['remove_feed_version'] ) ); ?>>
6169 <?php esc_html_e( 'Remove WordPress version from feed generator tag', 'vigilante' ); ?>
6170 </label>
6171 </td>
6172 </tr>
6173 </table>
6174 </div>
6175
6176 <p class="submit vigilante-submit-buttons">
6177 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
6178 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
6179 </button>
6180 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
6181 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
6182 </button>
6183 </p>
6184 </form>
6185 <?php
6186 }
6187
6188 /**
6189 * Render activity log tab
6190 */
6191 private function render_tab_activity_log() {
6192 $is_disabled = $this->render_module_disabled_notice( 'activity_log' );
6193 $options = $this->settings->get_section( 'activity_log' );
6194 ?>
6195 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="activity_log" <?php echo $is_disabled ? 'inert' : ''; ?>>
6196 <div id="vigilante-section-audit-settings" class="vigilante-settings-section">
6197 <h2>
6198 <?php esc_html_e( 'Security Audit Settings', 'vigilante' ); ?>
6199 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
6200 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
6201 </h2>
6202 <p><?php esc_html_e( 'Security event logging and auditing.', 'vigilante' ); ?></p>
6203
6204 <table class="form-table">
6205 <tr>
6206 <th scope="row"><?php esc_html_e( 'Retention', 'vigilante' ); ?></th>
6207 <td>
6208 <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">
6209 <label for="vigilante-f-activity-log-retention-days"><?php esc_html_e( 'days', 'vigilante' ); ?></label>
6210 &nbsp;&nbsp;
6211 <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">
6212 <label for="vigilante-f-activity-log-max-entries"><?php esc_html_e( 'max entries', 'vigilante' ); ?></label>
6213 <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>
6214 </td>
6215 </tr>
6216 <tr>
6217 <th scope="row"><?php esc_html_e( 'Events to Log', 'vigilante' ); ?></th>
6218 <td>
6219 <fieldset style="display:grid; grid-template-columns:repeat(auto-fit, minmax(240px, 1fr)); gap:6px 24px; max-width:600px;">
6220 <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>
6221 <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>
6222 <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>
6223 <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>
6224 <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>
6225 <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>
6226 <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>
6227 <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>
6228 <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>
6229 <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>
6230 </fieldset>
6231 <div class="notice notice-info inline" style="margin:10px 0 0;padding:8px 12px;">
6232 <p style="margin:0;">
6233 <?php esc_html_e( 'Firewall blocks, security events, and Vigilant settings changes are always logged regardless of the above selections.', 'vigilante' ); ?>
6234 </p>
6235 </div>
6236 </td>
6237 </tr>
6238 <tr>
6239 <th scope="row"><label for="vigilante-f-activity-log-tracked-options"><?php esc_html_e( 'Option Tracking', 'vigilante' ); ?></label></th>
6240 <td>
6241 <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>
6242 <br>
6243 <label><?php esc_html_e( 'Additional options to track:', 'vigilante' ); ?></label><br>
6244 <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>
6245 <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>
6246 </td>
6247 </tr>
6248 <tr>
6249 <th scope="row"><?php esc_html_e( 'Exclusions', 'vigilante' ); ?></th>
6250 <td>
6251 <div style="display:grid; grid-template-columns:repeat(auto-fit, minmax(220px, 1fr)); gap:16px; max-width:600px;">
6252 <div>
6253 <label for="vigilante-f-activity-log-excluded-users"><?php esc_html_e( 'Excluded user IDs:', 'vigilante' ); ?></label><br>
6254 <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>
6255 <p class="description"><?php esc_html_e( 'One user ID per line. Actions by these users will not be logged.', 'vigilante' ); ?></p>
6256 </div>
6257 <div>
6258 <label for="vigilante-f-activity-log-excluded-ips"><?php esc_html_e( 'Excluded IPs:', 'vigilante' ); ?></label><br>
6259 <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>
6260 <p class="description"><?php esc_html_e( 'One IP per line. Requests from these IPs will not be logged.', 'vigilante' ); ?></p>
6261 </div>
6262 </div>
6263 </td>
6264 </tr>
6265 </table>
6266 </div>
6267
6268 <p class="submit vigilante-submit-buttons">
6269 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
6270 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
6271 </button>
6272 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
6273 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
6274 </button>
6275 </p>
6276 </form>
6277
6278 <?php
6279 // Audit Alerts — alerting layer on top of Security Audit. Its own
6280 // settings section and form, rendered right after the logging settings
6281 // so the tab reads as "log this, exclude that, and alert me about this".
6282 $alerts = $this->settings->get_section( 'audit_alerts' );
6283 $immediate = isset( $alerts['immediate'] ) ? $alerts['immediate'] : array();
6284 $threshold = isset( $alerts['threshold'] ) ? $alerts['threshold'] : array();
6285 $alert_severity = isset( $immediate['min_severity'] ) ? $immediate['min_severity'] : 'critical';
6286 $alert_window = isset( $threshold['window'] ) ? $threshold['window'] : '1h';
6287 $threshold_cats = isset( $threshold['categories'] ) ? (array) $threshold['categories'] : array();
6288 $cat_labels = Vigilante_Audit_Alerts::category_labels();
6289 ?>
6290 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="audit_alerts" <?php echo $is_disabled ? 'inert' : ''; ?>>
6291 <div id="vigilante-section-audit-alerts" class="vigilante-settings-section">
6292 <h2>
6293 <?php esc_html_e( 'Audit Alerts', 'vigilante' ); ?>
6294 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
6295 </h2>
6296 <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>
6297
6298 <table class="form-table">
6299 <tr id="field-audit-alerts-immediate">
6300 <th scope="row"><?php esc_html_e( 'Immediate alerts', 'vigilante' ); ?></th>
6301 <td>
6302 <label>
6303 <input type="checkbox" name="audit_alerts[immediate][enabled]" value="1" <?php checked( ! empty( $immediate['enabled'] ) ); ?>>
6304 <?php esc_html_e( 'Email me as soon as a serious event is logged', 'vigilante' ); ?>
6305 </label>
6306 <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>
6307 </td>
6308 </tr>
6309 <tr>
6310 <th scope="row"><label for="vigilante-f-audit-alerts-immediate-min-severity"><?php esc_html_e( 'Alert on severity', 'vigilante' ); ?></label></th>
6311 <td>
6312 <select id="vigilante-f-audit-alerts-immediate-min-severity" name="audit_alerts[immediate][min_severity]">
6313 <option value="critical" <?php selected( $alert_severity, 'critical' ); ?>><?php esc_html_e( 'Critical only (recommended)', 'vigilante' ); ?></option>
6314 <option value="warning" <?php selected( $alert_severity, 'warning' ); ?>><?php esc_html_e( 'Warning and Critical', 'vigilante' ); ?></option>
6315 </select>
6316 <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>
6317 </td>
6318 </tr>
6319 <tr id="field-audit-alerts-threshold">
6320 <th scope="row"><?php esc_html_e( 'Threshold alerts', 'vigilante' ); ?></th>
6321 <td>
6322 <label>
6323 <input type="checkbox" name="audit_alerts[threshold][enabled]" value="1" <?php checked( ! empty( $threshold['enabled'] ) ); ?>>
6324 <?php esc_html_e( 'Email me when a category spikes within a time window', 'vigilante' ); ?>
6325 </label>
6326 <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>
6327 </td>
6328 </tr>
6329 <tr>
6330 <th scope="row"><label for="vigilante-f-audit-alerts-threshold-window"><?php esc_html_e( 'Time window', 'vigilante' ); ?></label></th>
6331 <td>
6332 <select id="vigilante-f-audit-alerts-threshold-window" name="audit_alerts[threshold][window]">
6333 <option value="30m" <?php selected( $alert_window, '30m' ); ?>><?php esc_html_e( '30 minutes', 'vigilante' ); ?></option>
6334 <option value="1h" <?php selected( $alert_window, '1h' ); ?>><?php esc_html_e( '1 hour', 'vigilante' ); ?></option>
6335 <option value="6h" <?php selected( $alert_window, '6h' ); ?>><?php esc_html_e( '6 hours', 'vigilante' ); ?></option>
6336 <option value="24h" <?php selected( $alert_window, '24h' ); ?>><?php esc_html_e( '24 hours', 'vigilante' ); ?></option>
6337 </select>
6338 <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>
6339 </td>
6340 </tr>
6341 <tr>
6342 <th scope="row"><?php esc_html_e( 'Thresholds per category', 'vigilante' ); ?></th>
6343 <td>
6344 <fieldset style="display:grid; grid-template-columns:repeat(auto-fit, minmax(200px, 1fr)); gap:8px 24px; max-width:760px;">
6345 <?php
6346 foreach ( $cat_labels as $cat_slug => $cat_label ) :
6347 $cat_value = isset( $threshold_cats[ $cat_slug ] ) ? (int) $threshold_cats[ $cat_slug ] : 0;
6348 ?>
6349 <label style="display:flex;align-items:center;gap:8px;justify-content:space-between;">
6350 <span><?php echo esc_html( $cat_label ); ?></span>
6351 <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">
6352 </label>
6353 <?php endforeach; ?>
6354 </fieldset>
6355 <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>
6356 </td>
6357 </tr>
6358 <tr>
6359 <th scope="row"><?php esc_html_e( "Don't repeat alerts", 'vigilante' ); ?></th>
6360 <td>
6361 <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">
6362 <label for="vigilante-f-audit-alerts-cooldown-minutes"><?php esc_html_e( 'minutes', 'vigilante' ); ?></label>
6363 <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>
6364 </td>
6365 </tr>
6366
6367 <tr>
6368 <th scope="row"><?php esc_html_e( 'Recipients', 'vigilante' ); ?></th>
6369 <td>
6370 <p class="description" style="margin-top:0;">
6371 <?php
6372 printf(
6373 /* translators: %s: Link to notification settings */
6374 esc_html__( 'Alerts go to the recipients configured in %s.', 'vigilante' ),
6375 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
6376 );
6377 ?>
6378 </p>
6379 <p style="margin:8px 0 0;">
6380 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
6381 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
6382 </button>
6383 <span class="vigilante-test-email-result" style="margin-left:8px;"></span>
6384 </p>
6385 <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>
6386 </td>
6387 </tr>
6388 </table>
6389 </div>
6390
6391 <p class="submit vigilante-submit-buttons">
6392 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
6393 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
6394 </button>
6395 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
6396 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
6397 </button>
6398 </p>
6399 </form>
6400
6401 <div id="vigilante-section-audit-recent" class="vigilante-settings-section">
6402 <h2><?php esc_html_e( 'Recent Activity', 'vigilante' ); ?></h2>
6403
6404 <?php
6405 $logs = $this->activity_log->get_logs( array( 'per_page' => 20 ) );
6406 $total_logs = $this->activity_log->get_logs_count();
6407
6408 // Label maps for translated display
6409 $type_labels = array(
6410 'login' => __( 'Login', 'vigilante' ),
6411 'user' => __( 'User', 'vigilante' ),
6412 'content' => __( 'Content', 'vigilante' ),
6413 'plugin' => __( 'Plugin', 'vigilante' ),
6414 'theme' => __( 'Theme', 'vigilante' ),
6415 'settings' => __( 'Settings', 'vigilante' ),
6416 'comment' => __( 'Comment', 'vigilante' ),
6417 'media' => __( 'Media', 'vigilante' ),
6418 'firewall' => __( 'Firewall', 'vigilante' ),
6419 'file' => __( 'File', 'vigilante' ),
6420 'security' => __( 'Security', 'vigilante' ),
6421 'system' => __( 'System', 'vigilante' ),
6422 );
6423 $severity_labels = array(
6424 'info' => __( 'Info', 'vigilante' ),
6425 'warning' => __( 'Warning', 'vigilante' ),
6426 'critical' => __( 'Critical', 'vigilante' ),
6427 );
6428
6429 $firewall_options = $this->settings->get_section( 'firewall' );
6430 $ip_whitelist = $firewall_options['ip_whitelist'] ?? array();
6431 $ip_blacklist = $firewall_options['ip_blacklist'] ?? array();
6432 $ua_whitelist = $firewall_options['ua_whitelist'] ?? array();
6433 $ua_blacklist = $firewall_options['ua_blacklist'] ?? array();
6434 ?>
6435
6436 <div class="vigilante-log-filters">
6437 <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">
6438 <select id="vigilante-log-type-filter" aria-label="<?php esc_attr_e( 'Filter the log by event type', 'vigilante' ); ?>">
6439 <option value=""><?php esc_html_e( 'All Types', 'vigilante' ); ?></option>
6440 <option value="login"><?php esc_html_e( 'Login', 'vigilante' ); ?></option>
6441 <option value="user"><?php esc_html_e( 'User', 'vigilante' ); ?></option>
6442 <option value="content"><?php esc_html_e( 'Content', 'vigilante' ); ?></option>
6443 <option value="plugin"><?php esc_html_e( 'Plugin', 'vigilante' ); ?></option>
6444 <option value="theme"><?php esc_html_e( 'Theme', 'vigilante' ); ?></option>
6445 <option value="settings"><?php esc_html_e( 'Settings', 'vigilante' ); ?></option>
6446 <option value="comment"><?php esc_html_e( 'Comment', 'vigilante' ); ?></option>
6447 <option value="media"><?php esc_html_e( 'Media', 'vigilante' ); ?></option>
6448 <option value="firewall"><?php esc_html_e( 'Firewall', 'vigilante' ); ?></option>
6449 <option value="file"><?php esc_html_e( 'File', 'vigilante' ); ?></option>
6450 <option value="security"><?php esc_html_e( 'Security', 'vigilante' ); ?></option>
6451 <option value="system"><?php esc_html_e( 'System', 'vigilante' ); ?></option>
6452 </select>
6453 <select id="vigilante-log-severity-filter" aria-label="<?php esc_attr_e( 'Filter the log by severity', 'vigilante' ); ?>">
6454 <option value=""><?php esc_html_e( 'All Severities', 'vigilante' ); ?></option>
6455 <option value="info"><?php esc_html_e( 'Info', 'vigilante' ); ?></option>
6456 <option value="warning"><?php esc_html_e( 'Warning', 'vigilante' ); ?></option>
6457 <option value="critical"><?php esc_html_e( 'Critical', 'vigilante' ); ?></option>
6458 </select>
6459 <select id="vigilante-log-method-filter" aria-label="<?php esc_attr_e( 'Filter the log by HTTP method', 'vigilante' ); ?>">
6460 <option value=""><?php esc_html_e( 'All Methods', 'vigilante' ); ?></option>
6461 <option value="GET">GET</option>
6462 <option value="POST">POST</option>
6463 <option value="PUT">PUT</option>
6464 <option value="DELETE">DELETE</option>
6465 <option value="PATCH">PATCH</option>
6466 <option value="OPTIONS">OPTIONS</option>
6467 <option value="HEAD">HEAD</option>
6468 </select>
6469 <button type="button" id="vigilante-log-refresh" class="button"><?php esc_html_e( 'Refresh', 'vigilante' ); ?></button>
6470 <span class="vigilante-pagination" id="vigilante-log-pagination" data-total="<?php echo esc_attr( $total_logs ); ?>" data-per-page="20" data-page="1">
6471 <?php if ( $total_logs > 20 ) : ?>
6472 <button type="button" class="vigilante-page-first" title="<?php esc_attr_e( 'First page', 'vigilante' ); ?>" disabled>&laquo;</button>
6473 <button type="button" class="vigilante-page-prev" title="<?php esc_attr_e( 'Previous page', 'vigilante' ); ?>" disabled>&lsaquo;</button>
6474 <?php endif; ?>
6475 <span class="vigilante-page-info">
6476 <?php
6477 $showing = min( 20, $total_logs );
6478 printf(
6479 /* translators: 1: first item, 2: last item, 3: total items */
6480 esc_html__( '%1$d–%2$d of %3$d', 'vigilante' ),
6481 $total_logs > 0 ? 1 : 0,
6482 absint( $showing ),
6483 absint( $total_logs )
6484 );
6485 ?>
6486 </span>
6487 <?php if ( $total_logs > 20 ) : ?>
6488 <button type="button" class="vigilante-page-next" title="<?php esc_attr_e( 'Next page', 'vigilante' ); ?>">&rsaquo;</button>
6489 <button type="button" class="vigilante-page-last" title="<?php esc_attr_e( 'Last page', 'vigilante' ); ?>">&raquo;</button>
6490 <?php endif; ?>
6491 </span>
6492 </div>
6493
6494 <div class="vigilante-log-table-wrap">
6495 <table id="vigilante-activity-log-table" class="wp-list-table widefat striped">
6496 <thead>
6497 <tr>
6498 <th class="column-date"><?php esc_html_e( 'Date', 'vigilante' ); ?></th>
6499 <th class="column-type"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
6500 <th class="column-method"><?php esc_html_e( 'Method', 'vigilante' ); ?></th>
6501 <th class="column-severity"><?php esc_html_e( 'Severity', 'vigilante' ); ?></th>
6502 <th class="column-message"><?php esc_html_e( 'Message', 'vigilante' ); ?></th>
6503 <th class="column-user"><?php esc_html_e( 'User', 'vigilante' ); ?></th>
6504 <th class="column-ip"><?php esc_html_e( 'IP', 'vigilante' ); ?></th>
6505 <th class="column-details"><?php esc_html_e( 'Details', 'vigilante' ); ?></th>
6506 </tr>
6507 </thead>
6508 <tbody>
6509 <?php
6510 if ( empty( $logs ) ) :
6511 ?>
6512 <tr><td colspan="8"><?php esc_html_e( 'No log entries found.', 'vigilante' ); ?></td></tr>
6513 <?php else : ?>
6514 <?php foreach ( $logs as $log ) :
6515 $request_method = isset( $log->request_method ) ? $log->request_method : '';
6516 // Prepare details as a simple object
6517 $ip_val = (string) ( $log->ip_address ?? '' );
6518 $ua_val = (string) ( $log->user_agent ?? '' );
6519 $details = array(
6520 'id' => (int) $log->id,
6521 'type' => (string) ( $log->event_type ?? '' ),
6522 'action' => (string) ( $log->event_action ?? '' ),
6523 'message' => (string) ( $log->event_message ?? '' ),
6524 'user' => (string) ( $log->user_login ?? '' ),
6525 'ip' => $ip_val,
6526 'user_agent' => $ua_val,
6527 'request_method' => (string) $request_method,
6528 'request_uri' => Vigilante_Activity_Log::extract_request_uri( $log->extra_data ?? '' ),
6529 'date' => (string) ( $log->created_at ?? '' ),
6530 'severity' => (string) ( $log->severity ?? 'info' ),
6531 'is_ip_whitelisted' => ( '' !== $ip_val && in_array( $ip_val, $ip_whitelist, true ) ),
6532 'is_ip_blacklisted' => ( '' !== $ip_val && in_array( $ip_val, $ip_blacklist, true ) ),
6533 'is_ua_whitelisted' => ( '' !== $ua_val && in_array( $ua_val, $ua_whitelist, true ) ),
6534 'is_ua_blacklisted' => ( '' !== $ua_val && in_array( $ua_val, $ua_blacklist, true ) ),
6535 );
6536 // Self-protection entries carry what happened, what
6537 // it means and what to do, from the same catalogue
6538 // the File Integrity box uses.
6539 $vg_self_event = Vigilante_Self_Integrity_Guidance::for_log_event(
6540 (string) ( $log->event_action ?? '' ),
6541 $log->extra_data ?? '',
6542 (string) ( $log->severity ?? 'info' )
6543 );
6544 if ( null !== $vg_self_event ) {
6545 $details['self'] = $vg_self_event;
6546 }
6547 $display_type = isset( $type_labels[ $log->event_type ] ) ? $type_labels[ $log->event_type ] : $log->event_type;
6548 $display_severity = isset( $severity_labels[ $log->severity ] ) ? $severity_labels[ $log->severity ] : $log->severity;
6549 ?>
6550 <tr class="vigilante-severity-<?php echo esc_attr( $log->severity ); ?>">
6551 <td><?php echo esc_html( $log->created_at ); ?></td>
6552 <td><?php echo esc_html( $display_type ); ?></td>
6553 <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>
6554 <td><span class="vigilante-badge vigilante-badge-<?php echo esc_attr( $log->severity ); ?>"><?php echo esc_html( $display_severity ); ?></span></td>
6555 <td><?php echo esc_html( $log->event_message ); ?></td>
6556 <td><?php echo esc_html( $log->user_login ?? '-' ); ?></td>
6557 <td><code><?php echo esc_html( $log->ip_address ); ?></code></td>
6558 <td>
6559 <button type="button" class="button button-small vigilante-view-log-details"
6560 data-details='<?php echo esc_attr( wp_json_encode( $details, JSON_HEX_APOS | JSON_HEX_QUOT ) ); ?>'>
6561 <?php esc_html_e( 'View', 'vigilante' ); ?>
6562 </button>
6563 </td>
6564 </tr>
6565 <?php endforeach; ?>
6566 <?php endif; ?>
6567 </tbody>
6568 </table>
6569 </div>
6570
6571 <!-- Log Details Modal -->
6572 <div id="vigilante-log-details-modal" class="vigilante-modal" style="display: none;">
6573 <div class="vigilante-modal-content">
6574 <span class="vigilante-modal-close">&times;</span>
6575 <h3><?php esc_html_e( 'Log Entry Details', 'vigilante' ); ?></h3>
6576 <div id="vigilante-log-details-content"></div>
6577 </div>
6578 </div>
6579
6580 <p>
6581 <button type="button" class="button vigilante-export-logs"><?php esc_html_e( 'Export Audit Log', 'vigilante' ); ?></button>
6582 <button type="button" class="button vigilante-clear-logs" style="color: #a00;"><?php esc_html_e( 'Clear All Logs', 'vigilante' ); ?></button>
6583 </p>
6584 </div>
6585 <?php
6586 }
6587
6588 /**
6589 * Render File Integrity tab
6590 */
6591 /**
6592 * Findings of the self-check grouped by the case that explains them, worst
6593 * first: ten modified files are one case with ten paths, not ten copies of
6594 * the same explanation.
6595 *
6596 * @param array $findings Findings from the state.
6597 * @return array
6598 */
6599 private function self_findings_by_case( $findings ) {
6600 $groups = array();
6601 foreach ( (array) $findings as $finding ) {
6602 if ( ! is_array( $finding ) || 'info' === ( $finding['severity'] ?? '' ) ) {
6603 continue;
6604 }
6605 $guidance = Vigilante_Self_Integrity_Guidance::for_finding( $finding );
6606 $key = $guidance['key'];
6607 if ( ! isset( $groups[ $key ] ) ) {
6608 $guidance['files'] = array();
6609 $guidance['severity'] = 'warning';
6610 $groups[ $key ] = $guidance;
6611 }
6612 $file = isset( $finding['file'] ) ? (string) $finding['file'] : '';
6613 if ( '' !== $file && ! in_array( $file, $groups[ $key ]['files'], true ) ) {
6614 $groups[ $key ]['files'][] = $file;
6615 }
6616 if ( 'critical' === ( $finding['severity'] ?? '' ) ) {
6617 $groups[ $key ]['severity'] = 'critical';
6618 }
6619 }
6620 uasort(
6621 $groups,
6622 function ( $a, $b ) {
6623 $rank = array( 'critical' => 0, 'warning' => 1 );
6624 $ra = isset( $rank[ $a['severity'] ] ) ? $rank[ $a['severity'] ] : 2;
6625 $rb = isset( $rank[ $b['severity'] ] ) ? $rank[ $b['severity'] ] : 2;
6626 return $ra - $rb;
6627 }
6628 );
6629 return $groups;
6630 }
6631
6632 /**
6633 * Human label for the context that ran the last self-check.
6634 *
6635 * @param string $context Stored context.
6636 * @return string
6637 */
6638 private function self_context_label( $context ) {
6639 switch ( (string) $context ) {
6640 case 'scan':
6641 return __( 'during a file integrity scan', 'vigilante' );
6642 case 'upgrader':
6643 return __( 'right after updating Vigilant', 'vigilante' );
6644 case 'version_change':
6645 return __( 'after a version change made outside the updater', 'vigilante' );
6646 case 'migration':
6647 return __( 'while updating to this version', 'vigilante' );
6648 case 'activation':
6649 return __( 'when Vigilant was activated', 'vigilante' );
6650 case 'watchdog':
6651 return __( 'from the scheduled task watchdog', 'vigilante' );
6652 }
6653 return '';
6654 }
6655
6656 /**
6657 * Short line for the badge of the box, the notices and the Dashboard strip.
6658 *
6659 * @param string $tone Tone from Vigilante_Self_Integrity::tone().
6660 * @param array $state State.
6661 * @return string
6662 */
6663 private function self_integrity_headline( $tone, $state ) {
6664 $files = isset( $state['files_checked'] ) ? (int) $state['files_checked'] : 0;
6665 $anchors = ( isset( $state['anchors'] ) && is_array( $state['anchors'] ) ) ? $state['anchors'] : array();
6666 switch ( $tone ) {
6667 case 'critical':
6668 return __( 'Changes detected in Vigilant own files', 'vigilante' );
6669 case 'warning':
6670 return ( $files < 1 )
6671 ? __( 'Vigilant could not check its own files', 'vigilante' )
6672 : __( 'Vigilant self-protection needs your attention', 'vigilante' );
6673 case 'off':
6674 return __( 'Self-protection is switched off by code', 'vigilante' );
6675 case 'none':
6676 return __( 'Vigilant has not checked its own files yet', 'vigilante' );
6677 }
6678 return sprintf(
6679 /* translators: 1: number of files verified, 2: number of references available, out of three */
6680 __( 'Verified: %1$d files, %2$d of 3 references', 'vigilante' ),
6681 $files,
6682 count( array_filter( $anchors ) )
6683 );
6684 }
6685
6686 /**
6687 * Vigilant self-protection box: the first block of the File Integrity
6688 * results, with its own colour by severity, what each finding means and
6689 * how to fix it.
6690 *
6691 * It renders whether or not a scan has been stored, because the self-check
6692 * also runs after every update and once a day: before 3.0.0 this lived in
6693 * a line above the numeric cards of the last scan, where it was invisible
6694 * and, without a stored scan, absent.
6695 *
6696 * @param array $fi_options File Integrity settings section.
6697 */
6698 /**
6699 * Everything the screens need to say about self-protection, read once:
6700 * the state, its findings grouped by case, and the tone that colours the
6701 * box, the menu counter and the notices.
6702 *
6703 * @param array|null $fi_options File Integrity settings, read if not given.
6704 * @return array { state, findings, groups, tone, enabled }
6705 */
6706 private function self_integrity_summary( $fi_options = null ) {
6707 // Four to six screens ask for this in the same page load (menu, notice,
6708 // box, strip, both scores). The option is cached by the core options
6709 // layer, but the grouping and the tone are not: memoize per request.
6710 static $cached = null;
6711 if ( null !== $cached && ! is_array( $fi_options ) ) {
6712 return $cached;
6713 }
6714 if ( ! is_array( $fi_options ) ) {
6715 $fi_options = (array) $this->settings->get_section( 'file_integrity' );
6716 }
6717 $enabled = Vigilante_Self_Integrity::is_on();
6718 $state = Vigilante_Self_Integrity::display_state();
6719 $findings = Vigilante_Self_Integrity::state_findings( $state, $enabled );
6720 $summary = array(
6721 'state' => $state,
6722 'findings' => $findings,
6723 'groups' => $this->self_findings_by_case( $findings ),
6724 'tone' => Vigilante_Self_Integrity::tone( $state, $enabled ),
6725 'enabled' => $enabled,
6726 );
6727 $cached = $summary;
6728 return $summary;
6729 }
6730
6731 private function render_self_protection_box( $fi_options ) {
6732 $summary = $this->self_integrity_summary( $fi_options );
6733 $enabled = $summary['enabled'];
6734 $state = $summary['state'];
6735 $findings = $summary['findings'];
6736 $groups = $summary['groups'];
6737 $tone = $summary['tone'];
6738 $total = isset( $state['last_findings_total'] ) ? (int) $state['last_findings_total'] : count( $findings );
6739 $status = array(
6740 'status' => isset( $state['last_status'] ) ? (string) $state['last_status'] : '',
6741 'files' => isset( $state['files_checked'] ) ? (int) $state['files_checked'] : 0,
6742 'anchors' => ( isset( $state['anchors'] ) && is_array( $state['anchors'] ) ) ? $state['anchors'] : array(),
6743 'enabled' => $enabled,
6744 'has_run' => ! empty( $state['last_check'] ),
6745 );
6746
6747 /*
6748 * Nothing to do, nothing to open: one line. A card with a big icon and
6749 * folded sections for "everything is fine" is furniture, and furniture
6750 * is what made the previous version of this invisible.
6751 */
6752 if ( empty( $groups ) ) {
6753 $this->render_self_line( $tone, $state, $status );
6754 return;
6755 }
6756
6757 $datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
6758 $context_label = $this->self_context_label( isset( $state['last_context'] ) ? $state['last_context'] : '' );
6759 $icon = ( 'critical' === $tone ) ? 'dashicons-shield' : 'dashicons-warning';
6760 ?>
6761 <div id="vigilante-section-fi-self" class="vigilante-settings-section vigilante-self-box vigilante-self-box--<?php echo esc_attr( $tone ); ?>">
6762 <div class="vigilante-self-card">
6763 <div class="vigilante-self-head">
6764 <span class="vigilante-self-icon"><span class="dashicons <?php echo esc_attr( $icon ); ?>" aria-hidden="true"></span></span>
6765 <div class="vigilante-self-head-text">
6766 <h2><?php echo esc_html( $this->self_integrity_headline( $tone, $state ) ); ?></h2>
6767 <p class="vigilante-self-meta">
6768 <?php
6769 printf(
6770 /* translators: %s: date and time of the last self-check */
6771 esc_html__( 'Checked on %s', 'vigilante' ),
6772 esc_html( wp_date( $datetime_format, (int) $state['last_check'] ) )
6773 );
6774 if ( '' !== $context_label ) {
6775 echo ', ' . esc_html( $context_label );
6776 }
6777 if ( $status['files'] > 0 ) {
6778 echo ', ';
6779 printf(
6780 /* translators: 1: number of files checked, 2: number of references available, out of three */
6781 esc_html__( '%1$d files against %2$d of 3 references', 'vigilante' ),
6782 (int) $status['files'],
6783 (int) count( array_filter( $status['anchors'] ) )
6784 );
6785 }
6786 ?>
6787 </p>
6788 </div>
6789 </div>
6790
6791 <div class="vigilante-self-cases">
6792 <?php
6793 $first = true;
6794 foreach ( $groups as $group ) {
6795 $this->render_self_case( $group, $group['files'], $group['severity'], $first );
6796 $first = false;
6797 }
6798
6799 if ( in_array( $tone, array( 'critical', 'warning' ), true ) ) {
6800 $can_repair = class_exists( 'Vigilante_Self_Repair' ) && Vigilante_Self_Repair::can_repair();
6801 if ( ! $can_repair ) {
6802 if ( class_exists( 'Vigilante_Self_Repair' ) && ! Vigilante_Self_Repair::folder_is_the_distributed_one() ) {
6803 $vg_reason = 'renamed';
6804 } elseif ( ! wp_is_file_mod_allowed( 'capability_update_core' ) ) {
6805 // With DISALLOW_FILE_MODS nobody can do it from the admin,
6806 // not even a network administrator: telling a subsite admin
6807 // to ask theirs would send them to someone equally blocked.
6808 $vg_reason = 'no_caps';
6809 } elseif ( is_multisite() && ! current_user_can( 'update_plugins' ) ) {
6810 $vg_reason = 'network';
6811 } else {
6812 $vg_reason = 'no_caps';
6813 }
6814 $this->render_self_case(
6815 array(
6816 'title' => __( 'How to repair it here', 'vigilante' ),
6817 'meaning' => __( 'This site does not let Vigilant replace its own files from this screen.', 'vigilante' ),
6818 'steps' => Vigilante_Self_Integrity_Guidance::manual_steps( $vg_reason ),
6819 ),
6820 array(),
6821 '',
6822 false
6823 );
6824 }
6825 }
6826 ?>
6827 </div>
6828
6829 <?php if ( $total > count( $findings ) ) : ?>
6830 <p class="description">
6831 <?php
6832 printf(
6833 /* translators: 1: findings shown, 2: findings found in total */
6834 esc_html__( 'Showing %1$d of %2$d findings: the rest are of the same kind.', 'vigilante' ),
6835 (int) count( $findings ),
6836 (int) $total
6837 );
6838 ?>
6839 </p>
6840 <?php endif; ?>
6841
6842 <?php
6843 /*
6844 * Reinstalling fixes files, not a filter someone wrote or a hook
6845 * someone removed: the button only appears when at least one of the
6846 * cases on screen is one a clean copy solves. Offering it next to
6847 * "switched off by code" was telling the person to fix something
6848 * else.
6849 */
6850 $vg_offer_repair = false;
6851 foreach ( $groups as $vg_group ) {
6852 if ( ! empty( $vg_group['repair'] ) ) {
6853 $vg_offer_repair = true;
6854 break;
6855 }
6856 }
6857 ?>
6858 <p class="vigilante-self-actions">
6859 <?php if ( $vg_offer_repair && class_exists( 'Vigilante_Self_Repair' ) && Vigilante_Self_Repair::can_repair() ) : ?>
6860 <a class="button button-primary" href="<?php echo esc_url( Vigilante_Self_Repair::action_url() ); ?>">
6861 <?php esc_html_e( 'Repair Vigilant', 'vigilante' ); ?>
6862 </a>
6863 <span class="description">
6864 <?php esc_html_e( 'It downloads a clean copy from WordPress.org, asks before changing anything, and keeps your settings and log.', 'vigilante' ); ?>
6865 </span>
6866 <?php else : ?>
6867 <span class="description">
6868 <?php esc_html_e( 'After fixing it, run a new scan with the Run Scan Now button above.', 'vigilante' ); ?>
6869 </span>
6870 <?php endif; ?>
6871 </p>
6872 </div>
6873 </div>
6874 <?php
6875 }
6876
6877 /**
6878 * The same state when there is nothing to act on: one line inside the same
6879 * card, so the first block of the results is always the same object.
6880 *
6881 * @param string $tone Tone from Vigilante_Self_Integrity::tone().
6882 * @param array $state State.
6883 * @param array $status Arguments for the guidance catalogue.
6884 */
6885 private function render_self_line( $tone, $state, $status ) {
6886 $guidance = Vigilante_Self_Integrity_Guidance::for_status( $status );
6887 $icon = ( 'ok' === $tone ) ? 'dashicons-yes-alt' : 'dashicons-shield';
6888 ?>
6889 <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">
6890 <div class="vigilante-self-card vigilante-self-card--quiet">
6891 <p class="vigilante-self-line">
6892 <span class="dashicons <?php echo esc_attr( $icon ); ?>" aria-hidden="true"></span>
6893 <strong><?php esc_html_e( 'Vigilant self-protection:', 'vigilante' ); ?></strong>
6894 <span class="vigilante-self-line-state"><?php echo esc_html( $this->self_integrity_headline( $tone, $state ) ); ?></span>
6895 <?php if ( ! empty( $state['last_check'] ) ) : ?>
6896 <span class="vigilante-self-line-meta">
6897 <?php
6898 printf(
6899 /* translators: %s: human time difference, like "2 hours" */
6900 esc_html__( 'checked %s ago', 'vigilante' ),
6901 esc_html( human_time_diff( (int) $state['last_check'], time() ) )
6902 );
6903 ?>
6904 </span>
6905 <?php endif; ?>
6906 </p>
6907 <?php if ( ! empty( $guidance['steps'] ) && 'none' === $tone ) : ?>
6908 <p class="description vigilante-self-line-help"><?php echo esc_html( $guidance['steps'][0] ); ?></p>
6909 <?php endif; ?>
6910 </div>
6911 </div>
6912 <?php
6913 }
6914
6915 /**
6916 * One case of the self-protection box, as a row that opens: what it is, how
6917 * many files, its severity, and inside, the files, what it means and what to
6918 * do. Plain HTML details, so there is no JavaScript between a finding about
6919 * the security plugin and the person reading it.
6920 *
6921 * @param array $guidance Guidance entry (title, meaning, steps).
6922 * @param array $files Paths this case was found in.
6923 * @param string $severity critical|warning, empty for the how-to-repair row.
6924 * @param bool $open Whether the row starts open.
6925 */
6926 private function render_self_case( $guidance, $files = array(), $severity = '', $open = false ) {
6927 $shown = array_slice( (array) $files, 0, 20 );
6928 $hidden = count( (array) $files ) - count( $shown );
6929 ?>
6930 <details class="vigilante-self-case vigilante-self-case--<?php echo esc_attr( '' !== $severity ? $severity : 'plain' ); ?>"<?php echo $open ? ' open' : ''; ?>>
6931 <summary>
6932 <span class="vigilante-self-case-title"><?php echo esc_html( $guidance['title'] ); ?></span>
6933 <?php if ( ! empty( $files ) ) : ?>
6934 <span class="vigilante-self-case-count">
6935 <?php
6936 printf(
6937 /* translators: %d: number of files of this finding */
6938 esc_html( _n( '%d file', '%d files', count( (array) $files ), 'vigilante' ) ),
6939 (int) count( (array) $files )
6940 );
6941 ?>
6942 </span>
6943 <?php endif; ?>
6944 <?php if ( '' !== $severity ) : ?>
6945 <span class="vigilante-self-case-severity">
6946 <?php echo esc_html( 'critical' === $severity ? __( 'critical', 'vigilante' ) : __( 'warning', 'vigilante' ) ); ?>
6947 </span>
6948 <?php endif; ?>
6949 </summary>
6950 <div class="vigilante-self-case-body">
6951 <?php if ( ! empty( $shown ) ) : ?>
6952 <ul class="vigilante-self-paths">
6953 <?php foreach ( $shown as $file ) : ?>
6954 <li><code><?php echo esc_html( $file ); ?></code></li>
6955 <?php endforeach; ?>
6956 <?php if ( $hidden > 0 ) : ?>
6957 <li>
6958 <?php
6959 printf(
6960 /* translators: %d: number of additional files */
6961 esc_html__( 'and %d more', 'vigilante' ),
6962 (int) $hidden
6963 );
6964 ?>
6965 </li>
6966 <?php endif; ?>
6967 </ul>
6968 <?php endif; ?>
6969 <p class="vigilante-self-meaning">
6970 <strong><?php esc_html_e( 'What it means:', 'vigilante' ); ?></strong>
6971 <?php echo esc_html( $guidance['meaning'] ); ?>
6972 </p>
6973 <?php if ( ! empty( $guidance['steps'] ) ) : ?>
6974 <p class="vigilante-self-todo"><strong><?php esc_html_e( 'What to do:', 'vigilante' ); ?></strong></p>
6975 <ol class="vigilante-self-steps">
6976 <?php foreach ( $guidance['steps'] as $step ) : ?>
6977 <li><?php echo esc_html( $step ); ?></li>
6978 <?php endforeach; ?>
6979 </ol>
6980 <?php endif; ?>
6981 </div>
6982 </details>
6983 <?php
6984 }
6985
6986 private function render_tab_file_integrity() {
6987 $is_disabled = $this->render_module_disabled_notice( 'file_integrity' );
6988 $options = $this->settings->get_section( 'file_integrity' );
6989 // On the main site of a network the critical-file scan is the network's
6990 // canary for a change to wp-config.php or the root .htaccess, so a
6991 // main-site admin without network rights cannot turn it off. Since
6992 // 2.11.8; see Vigilante_Settings::get_main_site_file_settings().
6993 $vg_main_locked = $this->main_site_files_locked();
6994 $last_scan = get_option( 'vigilante_last_integrity_scan' );
6995 $last_results = get_option( 'vigilante_last_integrity_results' );
6996 $ignored_files = get_option( 'vigilante_ignored_files', array() );
6997
6998 /*
6999 * Vigilant own findings are shown in their own box, the first of the
7000 * results, with what each one means and how to fix it. They are taken
7001 * out of the generic tables here (and out of the counters above them)
7002 * so the same finding is not reported twice and so no row of the
7003 * security plugin's own files offers an Ignore button. The stored
7004 * results keep them: the scan email reads its own section from there.
7005 */
7006 if ( is_array( $last_results ) ) {
7007 foreach ( array( 'modified', 'suspicious', 'extra', 'missing' ) as $vg_bucket ) {
7008 if ( empty( $last_results[ $vg_bucket ] ) || ! is_array( $last_results[ $vg_bucket ] ) ) {
7009 continue;
7010 }
7011 $last_results[ $vg_bucket ] = array_values(
7012 array_filter(
7013 $last_results[ $vg_bucket ],
7014 function ( $vg_item ) {
7015 return ! ( is_array( $vg_item ) && 'vigilante_self' === ( $vg_item['type'] ?? '' ) );
7016 }
7017 )
7018 );
7019 }
7020 }
7021
7022 // Backward compat: convert old notify_on_changes to notify_level
7023 $notify_level = $options['notify_level'] ?? '';
7024 if ( empty( $notify_level ) ) {
7025 $notify_level = ! empty( $options['notify_on_changes'] ) ? 'all' : 'disabled';
7026 }
7027
7028 // Closed + Removed plugins data. Surfaced inside Last Scan Results so the
7029 // user sees file findings and plugin closures together (same tier of risk,
7030 // same UI), and as the trigger to keep Last Scan Results open even when no
7031 // file scan has run yet (the daily cron may have populated this section).
7032 //
7033 // Gating by last_check_time > 0 is how "Clear Previous Results" visually
7034 // resets this block: the option vigilante_plugin_status_last_check is
7035 // deleted on Clear, but the state map and the ignored list survive so the
7036 // next scan reconstructs without degrading a 'removed' slug. While
7037 // last_check is 0, we treat the plugin_status data as if it didn't exist.
7038 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
7039 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
7040 }
7041 $closed_checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
7042 $closed_last_check = $closed_checker->get_last_check_time();
7043 if ( $closed_last_check > 0 ) {
7044 $closed_plugins = $closed_checker->get_closed_plugins();
7045 $ignored_closed_plugins = $closed_checker->get_ignored_closed_plugins();
7046 } else {
7047 $closed_plugins = array();
7048 $ignored_closed_plugins = array();
7049 }
7050 $has_closed = ! empty( $closed_plugins );
7051 $datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
7052 ?>
7053 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="file_integrity" <?php echo $is_disabled ? 'inert' : ''; ?>>
7054 <div id="vigilante-section-fi-monitoring" class="vigilante-settings-section">
7055 <h2>
7056 <?php esc_html_e( 'File Integrity Monitoring', 'vigilante' ); ?>
7057 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
7058 </h2>
7059 <p><?php esc_html_e( 'Detects file modifications using WordPress.org checksums.', 'vigilante' ); ?></p>
7060
7061 <table class="form-table">
7062 <tr>
7063 <th scope="row"><?php esc_html_e( 'Automatic Scans', 'vigilante' ); ?></th>
7064 <td>
7065 <label>
7066 <input type="checkbox" name="file_integrity[auto_scan]" value="1" <?php checked( ! empty( $options['auto_scan'] ) ); ?>>
7067 <?php esc_html_e( 'Enable scheduled file integrity scans', 'vigilante' ); ?>
7068 </label>
7069 </td>
7070 </tr>
7071 <tr>
7072 <th scope="row"><label for="vigilante-f-file-integrity-scan-frequency"><?php esc_html_e( 'Scan Frequency', 'vigilante' ); ?></label></th>
7073 <td>
7074 <select id="vigilante-f-file-integrity-scan-frequency" name="file_integrity[scan_frequency]">
7075 <option value="daily" <?php selected( $options['scan_frequency'] ?? 'daily', 'daily' ); ?>><?php esc_html_e( 'Daily', 'vigilante' ); ?></option>
7076 <option value="weekly" <?php selected( $options['scan_frequency'] ?? 'daily', 'weekly' ); ?>><?php esc_html_e( 'Weekly', 'vigilante' ); ?></option>
7077 </select>
7078 </td>
7079 </tr>
7080 <tr>
7081 <th scope="row"><label for="vigilante-f-file-integrity-notify-level"><?php esc_html_e( 'Email Notifications', 'vigilante' ); ?></label></th>
7082 <td>
7083 <select id="vigilante-f-file-integrity-notify-level" name="file_integrity[notify_level]">
7084 <option value="all" <?php selected( $notify_level, 'all' ); ?>><?php esc_html_e( 'All issues (modified + suspicious)', 'vigilante' ); ?></option>
7085 <option value="suspicious_only" <?php selected( $notify_level, 'suspicious_only' ); ?>><?php esc_html_e( 'Suspicious files only', 'vigilante' ); ?></option>
7086 <option value="disabled" <?php selected( $notify_level, 'disabled' ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
7087 </select>
7088 <p class="description"><?php esc_html_e( '"Suspicious files only" reduces noise by skipping modified file notifications. Recommended for most sites.', 'vigilante' ); ?></p>
7089 </td>
7090 </tr>
7091 <tr>
7092 <th scope="row"><?php esc_html_e( 'Instant Alert', 'vigilante' ); ?></th>
7093 <td>
7094 <label>
7095 <input type="checkbox" name="file_integrity[instant_alert]" value="1" <?php checked( ! empty( $options['instant_alert'] ) ); ?>>
7096 <?php esc_html_e( 'Send immediate alert when modified, suspicious or additional files are detected, or when a closed plugin is found', 'vigilante' ); ?>
7097 </label>
7098 <p class="description"><?php esc_html_e( 'Fires even if the Email Notifications setting above is set to Disabled.', 'vigilante' ); ?></p>
7099 <p class="description">
7100 <?php
7101 printf(
7102 /* translators: %s: Link to notification settings */
7103 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
7104 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
7105 );
7106 ?>
7107 </p>
7108 </td>
7109 </tr>
7110 <tr>
7111 <th scope="row"><?php esc_html_e( 'Test email', 'vigilante' ); ?></th>
7112 <td>
7113 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
7114 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
7115 </button>
7116 <span class="vigilante-test-email-result" style="margin-left:8px;"></span>
7117 <p class="description"><?php esc_html_e( 'Sends a test message to the configured recipients to confirm email delivery works.', 'vigilante' ); ?></p>
7118 </td>
7119 </tr>
7120 <tr>
7121 <th scope="row"><?php esc_html_e( 'Scan Scope', 'vigilante' ); ?></th>
7122 <td>
7123 <fieldset>
7124 <label>
7125 <input type="checkbox" name="file_integrity[scan_core]" value="1" <?php checked( $options['scan_core'] ?? true ); ?>>
7126 <?php esc_html_e( 'Core files (compare against WordPress.org checksums)', 'vigilante' ); ?>
7127 </label>
7128 <br>
7129 <label>
7130 <input type="checkbox" name="file_integrity[scan_plugins]" value="1" <?php checked( $options['scan_plugins'] ?? true ); ?>>
7131 <?php esc_html_e( 'Plugins (WordPress.org repository plugins)', 'vigilante' ); ?>
7132 </label>
7133 <br>
7134 <label>
7135 <input type="checkbox" name="file_integrity[scan_themes]" value="1" <?php checked( $options['scan_themes'] ?? true ); ?>>
7136 <?php esc_html_e( 'Themes (WordPress.org repository themes)', 'vigilante' ); ?>
7137 </label>
7138 <br>
7139 <label>
7140 <input type="checkbox" name="file_integrity[scan_uploads]" value="1" <?php checked( $options['scan_uploads'] ?? true ); ?>>
7141 <?php esc_html_e( 'Uploads directory (detect PHP files, double extensions, .htaccess)', 'vigilante' ); ?>
7142 </label>
7143 <br>
7144 <label>
7145 <input type="checkbox" name="file_integrity[scan_critical_config]" value="1" <?php disabled( $vg_main_locked ); ?> <?php checked( $options['scan_critical_config'] ?? true ); ?>>
7146 <?php esc_html_e( 'Critical config files (wp-config.php, .htaccess baseline monitoring)', 'vigilante' ); ?>
7147 <?php if ( $vg_main_locked ) : ?>
7148 <span class="description" style="display:block;margin-left:24px;"><?php echo esc_html( Vigilante_Settings::get_shared_files_notice() ); ?></span>
7149 <?php endif; ?>
7150 </label>
7151 <br>
7152 <label>
7153 <input type="checkbox" name="file_integrity[check_closed_plugins]" value="1" <?php checked( $options['check_closed_plugins'] ?? true ); ?>>
7154 <?php esc_html_e( 'Closed plugins (daily check against the WordPress.org repository)', 'vigilante' ); ?>
7155 </label>
7156 </fieldset>
7157 </td>
7158 </tr>
7159 <tr>
7160 <th scope="row"><label for="vigilante-f-file-integrity-excluded-paths"><?php esc_html_e( 'Excluded Paths', 'vigilante' ); ?></label></th>
7161 <td>
7162 <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>
7163 <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>
7164 </td>
7165 </tr>
7166 <tr>
7167 <th scope="row"><label for="vigilante-f-file-integrity-excluded-extensions"><?php esc_html_e( 'Excluded Extensions', 'vigilante' ); ?></label></th>
7168 <td>
7169 <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>
7170 <p class="description">
7171 <?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' ); ?>
7172 <br>
7173 <?php
7174 printf(
7175 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the scoped-extension example. */
7176 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' ),
7177 '<code>',
7178 '</code>'
7179 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
7180 ?>
7181 </p>
7182 </td>
7183 </tr>
7184 </table>
7185 </div>
7186
7187 <p class="submit vigilante-submit-buttons">
7188 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
7189 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
7190 </button>
7191 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
7192 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
7193 </button>
7194 <span class="vigilante-buttons-separator"></span>
7195 <button type="button" class="button button-primary vigilante-run-scan">
7196 <?php esc_html_e( 'Run Scan Now', 'vigilante' ); ?>
7197 </button>
7198 <button type="button" class="button vigilante-clear-scan-btn vigilante-clear-scan">
7199 <?php esc_html_e( 'Clear Previous Results', 'vigilante' ); ?>
7200 </button>
7201 </p>
7202 </form>
7203
7204 <div id="vigilante-scan-results" class="vigilante-settings-section" style="display:none;"></div>
7205
7206 <?php $this->render_self_protection_box( $options ); ?>
7207
7208 <?php if ( $last_scan || $has_closed || $closed_last_check > 0 ) : ?>
7209 <div id="vigilante-section-fi-last-scan" class="vigilante-settings-section">
7210 <h2><?php esc_html_e( 'Last Scan Results', 'vigilante' ); ?></h2>
7211 <?php if ( $last_scan ) : ?>
7212 <p>
7213 <?php
7214 // Build the "X files scanned" hint inline with the date so it doesn't
7215 // need its own stat box (keeps the row compact when closed plugins are
7216 // present).
7217 $scanned_total = 0;
7218 if ( $last_results ) {
7219 $scanned_total = (int) ( $last_results['ok'] ?? 0 )
7220 + count( $last_results['modified'] ?? array() )
7221 + count( $last_results['suspicious'] ?? array() )
7222 + count( $last_results['extra'] ?? array() )
7223 + count( $ignored_files );
7224 }
7225 if ( $scanned_total > 0 ) {
7226 printf(
7227 /* translators: 1: date and time of last scan, 2: formatted file count */
7228 esc_html__( 'Last scan: %1$s (%2$s files scanned)', 'vigilante' ),
7229 esc_html( wp_date( $datetime_format, $last_scan ) ),
7230 esc_html( number_format_i18n( $scanned_total ) )
7231 );
7232 } else {
7233 printf(
7234 /* translators: %s: date and time of last scan */
7235 esc_html__( 'Last scan: %s', 'vigilante' ),
7236 esc_html( wp_date( $datetime_format, $last_scan ) )
7237 );
7238 }
7239 if ( $closed_last_check > 0 && $closed_last_check !== (int) $last_scan ) {
7240 echo ' &middot; ';
7241 printf(
7242 /* translators: %s: date and time of last closed plugins check */
7243 esc_html__( 'Closed plugins last checked: %s', 'vigilante' ),
7244 esc_html( wp_date( $datetime_format, $closed_last_check ) )
7245 );
7246 }
7247 ?>
7248 </p>
7249 <?php elseif ( $closed_last_check > 0 ) : ?>
7250 <p>
7251 <?php
7252 printf(
7253 /* translators: %s: date and time of last closed plugins check */
7254 esc_html__( 'Closed plugins last checked: %s &middot; the daily cron is running, no full integrity scan yet.', 'vigilante' ),
7255 esc_html( wp_date( $datetime_format, $closed_last_check ) )
7256 );
7257 ?>
7258 </p>
7259 <?php endif; ?>
7260 <div id="vigilante-last-scan-results">
7261 <?php if ( $last_results || $has_closed ) : ?>
7262 <div class="vigilante-scan-summary">
7263 <?php if ( $last_results ) : ?>
7264 <div class="vigilante-scan-stat vigilante-stat-ok">
7265 <span class="vigilante-stat-number"><?php echo esc_html( $last_results['ok'] ?? 0 ); ?></span>
7266 <span class="vigilante-stat-label"><?php esc_html_e( 'OK', 'vigilante' ); ?></span>
7267 </div>
7268 <div class="vigilante-scan-stat vigilante-stat-modified">
7269 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['modified'] ?? array() ) ); ?></span>
7270 <span class="vigilante-stat-label"><?php esc_html_e( 'Modified', 'vigilante' ); ?></span>
7271 </div>
7272 <div class="vigilante-scan-stat vigilante-stat-suspicious">
7273 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['suspicious'] ?? array() ) ); ?></span>
7274 <span class="vigilante-stat-label"><?php esc_html_e( 'Suspicious', 'vigilante' ); ?></span>
7275 </div>
7276 <div class="vigilante-scan-stat vigilante-stat-extra">
7277 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['extra'] ?? array() ) ); ?></span>
7278 <span class="vigilante-stat-label"><?php esc_html_e( 'Extra', 'vigilante' ); ?></span>
7279 </div>
7280 <?php endif; ?>
7281 <?php if ( $has_closed ) : ?>
7282 <div class="vigilante-scan-stat vigilante-stat-suspicious">
7283 <span class="vigilante-stat-number" style="color: #d63638;"><?php echo (int) count( $closed_plugins ); ?></span>
7284 <span class="vigilante-stat-label"><?php esc_html_e( 'Closed/Removed', 'vigilante' ); ?></span>
7285 </div>
7286 <?php endif; ?>
7287 <?php if ( ! empty( $ignored_files ) ) : ?>
7288 <div class="vigilante-scan-stat vigilante-stat-ignored">
7289 <span class="vigilante-stat-number"><?php echo esc_html( count( $ignored_files ) ); ?></span>
7290 <span class="vigilante-stat-label"><?php esc_html_e( 'Ignored', 'vigilante' ); ?></span>
7291 </div>
7292 <?php endif; ?>
7293 </div>
7294
7295 <?php if ( ! empty( $last_results['suspicious'] ) ) : ?>
7296 <div class="vigilante-file-list vigilante-suspicious-files vigilante-paginated-section" data-bulk-mode="ignore">
7297 <h3 style="color: #d63638;"><?php esc_html_e( 'Suspicious Files', 'vigilante' ); ?></h3>
7298 <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>
7299 <div class="vigilante-fi-bulk-bar">
7300 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
7301 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
7302 </div>
7303 <div class="vigilante-fi-pagination-wrap"></div>
7304 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
7305 <thead>
7306 <tr>
7307 <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>
7308 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
7309 <th style="width: 250px;"><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
7310 <th style="width: 120px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
7311 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
7312 </tr>
7313 </thead>
7314 <tbody>
7315 <?php
7316 foreach ( $last_results['suspicious'] as $item ) {
7317 $file_path = '';
7318 $file_reason = __( 'Unknown', 'vigilante' );
7319 $file_type = 'unknown';
7320
7321 if ( is_array( $item ) ) {
7322 if ( isset( $item['file'] ) ) {
7323 $file_path = $item['file'];
7324 }
7325 if ( isset( $item['reason'] ) ) {
7326 $file_reason = $item['reason'];
7327 }
7328 if ( isset( $item['type'] ) ) {
7329 $file_type = $item['type'];
7330 }
7331 } else {
7332 $file_path = (string) $item;
7333 }
7334 if ( 'vigilante_self' === $file_type ) {
7335 $file_type = __( 'Vigilant (self)', 'vigilante' );
7336 }
7337 ?>
7338 <tr>
7339 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
7340 <td><code style="color: #d63638;"><?php echo esc_html( $file_path ); ?></code></td>
7341 <td><?php echo esc_html( $file_reason ); ?></td>
7342 <td><?php echo esc_html( $file_type ); ?></td>
7343 <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>
7344 </tr>
7345 <?php
7346 }
7347 ?>
7348 </tbody>
7349 </table>
7350 </div>
7351 <?php endif; ?>
7352
7353 <?php if ( ! empty( $last_results['extra'] ) ) : ?>
7354 <div class="vigilante-file-list vigilante-extra-files vigilante-paginated-section" data-bulk-mode="ignore">
7355 <h3 style="color: #b32d2e;"><?php esc_html_e( 'Extra Files', 'vigilante' ); ?></h3>
7356 <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>
7357 <div class="vigilante-fi-bulk-bar">
7358 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
7359 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
7360 </div>
7361 <div class="vigilante-fi-pagination-wrap"></div>
7362 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
7363 <thead>
7364 <tr>
7365 <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>
7366 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
7367 <th style="width: 250px;"><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
7368 <th style="width: 120px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
7369 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
7370 </tr>
7371 </thead>
7372 <tbody>
7373 <?php
7374 foreach ( $last_results['extra'] as $item ) {
7375 $file_path = is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item;
7376 $file_reason = is_array( $item ) ? ( $item['reason'] ?? __( 'Unknown', 'vigilante' ) ) : __( 'Unknown', 'vigilante' );
7377 $file_type = is_array( $item ) ? ( $item['type'] ?? 'unknown' ) : 'unknown';
7378 if ( 'vigilante_self' === $file_type ) {
7379 $file_type = __( 'Vigilant (self)', 'vigilante' );
7380 }
7381 ?>
7382 <tr>
7383 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
7384 <td><code style="color: #b32d2e;"><?php echo esc_html( $file_path ); ?></code></td>
7385 <td><?php echo esc_html( $file_reason ); ?></td>
7386 <td><?php echo esc_html( $file_type ); ?></td>
7387 <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>
7388 </tr>
7389 <?php
7390 }
7391 ?>
7392 </tbody>
7393 </table>
7394 </div>
7395 <?php endif; ?>
7396
7397 <?php
7398 // Split critical config files from regular modified files.
7399 // Computed unconditionally so the three sub-sections that consume
7400 // these arrays (Critical Config, Closed + Removed, Modified Files)
7401 // can render independently and in the order the team picked.
7402 $critical_modified = array();
7403 $regular_modified = array();
7404 if ( $last_results && ! empty( $last_results['modified'] ) ) {
7405 foreach ( $last_results['modified'] as $item ) {
7406 if ( is_array( $item ) && isset( $item['type'] ) && 'critical_config' === $item['type'] ) {
7407 $critical_modified[] = $item;
7408 } else {
7409 $regular_modified[] = $item;
7410 }
7411 }
7412 }
7413 // A missing file of Vigilant is critical, and the missing
7414 // files of the generic scan have no table: it is listed with
7415 // the modified files, or the tab said "All files passed" with
7416 // a module deleted.
7417 if ( $last_results && ! empty( $last_results['missing'] ) && is_array( $last_results['missing'] ) ) {
7418 foreach ( $last_results['missing'] as $item ) {
7419 if ( is_array( $item ) && 'vigilante_self' === ( $item['type'] ?? '' ) ) {
7420 $regular_modified[] = $item;
7421 }
7422 }
7423 }
7424 ?>
7425
7426 <?php if ( ! empty( $critical_modified ) ) : ?>
7427 <div class="vigilante-file-list vigilante-critical-config-files">
7428 <h3 style="color: #e36210;"><?php esc_html_e( 'Critical config files modified', 'vigilante' ); ?></h3>
7429 <p class="description">
7430 <?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' ); ?>
7431 </p>
7432 <table class="wp-list-table widefat fixed striped">
7433 <thead>
7434 <tr>
7435 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
7436 <th style="width: 200px;"><?php esc_html_e( 'Changes', 'vigilante' ); ?></th>
7437 <th style="width: 220px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
7438 </tr>
7439 </thead>
7440 <tbody>
7441 <?php foreach ( $critical_modified as $crit_item ) :
7442 $crit_file = $crit_item['file'] ?? '';
7443 $crit_baseline_size = $crit_item['baseline_size'] ?? 0;
7444 $crit_current_size = $crit_item['current_size'] ?? 0;
7445 $crit_diff = $crit_item['diff'] ?? array();
7446 $crit_id = sanitize_html_class( $crit_file );
7447 $added_count = is_array( $crit_diff ) ? count( $crit_diff['added'] ?? array() ) : 0;
7448 $removed_count = is_array( $crit_diff ) ? count( $crit_diff['removed'] ?? array() ) : 0;
7449 // The lines of a shared file are for whoever approves it. Results
7450 // stored before 2.11.8 on the main site still carry them, so the
7451 // screen asks too, not only the scan that wrote them.
7452 $diff_network = ( is_array( $crit_diff ) && ! empty( $crit_diff['network'] ) ) || $this->critical_approval_locked();
7453 $diff_rescan = is_array( $crit_diff ) && ! empty( $crit_diff['rescan'] );
7454 $diff_redaction = is_array( $crit_diff ) && ! empty( $crit_diff['redaction'] );
7455 $diff_unavailable = $diff_network || ( is_array( $crit_diff ) && ! empty( $crit_diff['unavailable'] ) );
7456 ?>
7457 <tr>
7458 <td><code style="color: #e36210;"><?php echo esc_html( $crit_file ); ?></code></td>
7459 <td>
7460 <?php if ( ! $diff_unavailable ) : ?>
7461 <span style="color: #007017;">+<?php echo (int) $added_count; ?></span>
7462 <span style="color: #b32d2e;">-<?php echo (int) $removed_count; ?></span>
7463 <?php esc_html_e( 'lines', 'vigilante' ); ?><br>
7464 <?php endif; ?>
7465 <small style="color: #50575e;">
7466 <?php
7467 printf(
7468 /* translators: 1: baseline size, 2: current size */
7469 esc_html__( '%1$s &rarr; %2$s bytes', 'vigilante' ),
7470 esc_html( number_format_i18n( $crit_baseline_size ) ),
7471 esc_html( number_format_i18n( $crit_current_size ) )
7472 );
7473 ?>
7474 </small>
7475 </td>
7476 <td>
7477 <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' ); ?>">
7478 <?php esc_html_e( 'Review changes', 'vigilante' ); ?>
7479 </button>
7480 <?php if ( $this->critical_approval_locked() ) : ?>
7481 <span class="description" style="display:block;margin-top:4px;">
7482 <?php echo esc_html( $this->critical_approval_notice() ); ?>
7483 </span>
7484 <?php else : ?>
7485 <button type="button" class="button button-small button-primary vigilante-approve-critical-file" data-file="<?php echo esc_attr( $crit_file ); ?>">
7486 <?php esc_html_e( 'Approve', 'vigilante' ); ?>
7487 </button>
7488 <?php endif; ?>
7489 </td>
7490 </tr>
7491 <tr id="vigilante-critical-content-<?php echo esc_attr( $crit_id ); ?>" class="vigilante-critical-content-row" style="display:none;">
7492 <td colspan="3" style="padding: 0;">
7493 <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;">
7494 <?php if ( $diff_network ) : ?>
7495 <p style="color: #50575e; font-style: italic; margin: 0;">
7496 <?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' ); ?>
7497 </p>
7498 <?php elseif ( $diff_rescan ) : ?>
7499 <p style="color: #50575e; font-style: italic; margin: 0;">
7500 <?php esc_html_e( 'Run a new scan to see the line changes of this file.', 'vigilante' ); ?>
7501 </p>
7502 <?php elseif ( $diff_redaction ) : ?>
7503 <p style="color: #50575e; font-style: italic; margin: 0;">
7504 <?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' ); ?>
7505 </p>
7506 <?php elseif ( $diff_unavailable ) : ?>
7507 <p style="color: #50575e; font-style: italic; margin: 0;">
7508 <?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' ); ?>
7509 </p>
7510 <?php elseif ( empty( $crit_diff['added'] ) && empty( $crit_diff['removed'] ) ) : ?>
7511 <p style="color: #50575e; font-style: italic; margin: 0;">
7512 <?php esc_html_e( 'No line-level changes detected (may be whitespace or reordering).', 'vigilante' ); ?>
7513 </p>
7514 <?php else : ?>
7515 <?php if ( ! empty( $crit_diff['removed'] ) ) : ?>
7516 <?php foreach ( $crit_diff['removed'] as $rline ) : ?>
7517 <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>
7518 <?php endforeach; ?>
7519 <?php endif; ?>
7520 <?php if ( ! empty( $crit_diff['added'] ) ) : ?>
7521 <?php foreach ( $crit_diff['added'] as $aline ) : ?>
7522 <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>
7523 <?php endforeach; ?>
7524 <?php endif; ?>
7525 <?php endif; ?>
7526 </div>
7527 </td>
7528 </tr>
7529 <?php endforeach; ?>
7530 </tbody>
7531 </table>
7532 </div>
7533 <?php endif; ?>
7534
7535 <?php if ( $has_closed ) : ?>
7536 <div class="vigilante-file-list vigilante-closed-plugins">
7537 <h3 id="vigilante-section-fi-closed-plugins" style="color: #d63638;"><?php esc_html_e( 'Closed + Removed Plugins', 'vigilante' ); ?></h3>
7538 <p class="description" style="color: #d63638;">
7539 <?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' ); ?>
7540 </p>
7541 <table class="wp-list-table widefat striped">
7542 <thead>
7543 <tr>
7544 <th><?php esc_html_e( 'Plugin', 'vigilante' ); ?></th>
7545 <th style="width: 70px;"><?php esc_html_e( 'Version', 'vigilante' ); ?></th>
7546 <th style="width: 90px;"><?php esc_html_e( 'State', 'vigilante' ); ?></th>
7547 <th style="width: 110px;"><?php esc_html_e( 'Closed date', 'vigilante' ); ?></th>
7548 <th><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
7549 <th style="width: 130px;"><?php esc_html_e( 'Detected', 'vigilante' ); ?></th>
7550 <th style="width: 90px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
7551 </tr>
7552 </thead>
7553 <tbody>
7554 <?php foreach ( $closed_plugins as $cp_slug => $cp_entry ) :
7555 $cp_state = $cp_entry['state'] ?? '';
7556 $cp_state_label = 'closed' === $cp_state ? __( 'Closed', 'vigilante' ) : __( 'Removed', 'vigilante' );
7557 $cp_state_color = 'closed' === $cp_state ? '#d63638' : '#b32d2e';
7558 $cp_reason = '';
7559 if ( ! empty( $cp_entry['closed_reason_text'] ) ) {
7560 $cp_reason = $cp_entry['closed_reason_text'];
7561 } elseif ( 'removed' === $cp_state ) {
7562 $cp_reason = __( 'Removed from repository (metadata hidden, typical of Security Issue closures)', 'vigilante' );
7563 }
7564 $cp_detected = isset( $cp_entry['first_detected'] ) ? (int) $cp_entry['first_detected'] : 0;
7565 ?>
7566 <tr>
7567 <td>
7568 <strong><?php echo esc_html( $cp_entry['name'] ?? $cp_slug ); ?></strong><br>
7569 <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>
7570 </td>
7571 <td><?php echo esc_html( $cp_entry['version'] ?? '' ); ?></td>
7572 <td><span style="color: <?php echo esc_attr( $cp_state_color ); ?>; font-weight: 600;"><?php echo esc_html( $cp_state_label ); ?></span></td>
7573 <td><?php echo esc_html( $cp_entry['closed_date'] ?? '' ); ?></td>
7574 <td><?php echo esc_html( $cp_reason ); ?></td>
7575 <td>
7576 <?php echo $cp_detected > 0 ? esc_html( wp_date( $datetime_format, $cp_detected ) ) : '&mdash;'; ?>
7577 </td>
7578 <td>
7579 <button type="button" class="button button-small vigilante-ignore-closed-plugin" data-slug="<?php echo esc_attr( $cp_slug ); ?>">
7580 <?php esc_html_e( 'Ignore', 'vigilante' ); ?>
7581 </button>
7582 </td>
7583 </tr>
7584 <?php endforeach; ?>
7585 </tbody>
7586 </table>
7587 </div>
7588 <?php endif; ?>
7589
7590 <?php if ( ! empty( $regular_modified ) ) : ?>
7591 <div class="vigilante-file-list vigilante-paginated-section" data-bulk-mode="ignore">
7592 <h3><?php esc_html_e( 'Modified Files', 'vigilante' ); ?></h3>
7593 <p class="description"><?php esc_html_e( 'These files (apparently) differ from the original WordPress or plugin versions.', 'vigilante' ); ?></p>
7594 <div class="vigilante-fi-bulk-bar">
7595 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
7596 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
7597 </div>
7598 <div class="vigilante-fi-pagination-wrap"></div>
7599 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
7600 <thead>
7601 <tr>
7602 <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>
7603 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
7604 <th style="width: 100px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
7605 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
7606 </tr>
7607 </thead>
7608 <tbody>
7609 <?php
7610 foreach ( $regular_modified as $item ) {
7611 $file_path = '';
7612 $file_type = 'unknown';
7613
7614 if ( is_array( $item ) ) {
7615 if ( isset( $item['file'] ) ) {
7616 $file_path = $item['file'];
7617 }
7618 if ( isset( $item['type'] ) ) {
7619 $file_type = $item['type'];
7620 }
7621 } else {
7622 $file_path = (string) $item;
7623 }
7624 if ( 'vigilante_self' === $file_type ) {
7625 $file_type = __( 'Vigilant (self)', 'vigilante' );
7626 }
7627 ?>
7628 <tr>
7629 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
7630 <td><code><?php echo esc_html( $file_path ); ?></code></td>
7631 <td><?php echo esc_html( $file_type ); ?></td>
7632 <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>
7633 </tr>
7634 <?php
7635 }
7636 ?>
7637 </tbody>
7638 </table>
7639 </div>
7640 <?php endif; ?>
7641
7642 <?php
7643 // "All files passed" is about every file, and Vigilant's own
7644 // are files too: with the self-protection box in red or amber
7645 // above, this line contradicted it (its findings no longer
7646 // travel in the tables below).
7647 $vg_self_alarm = in_array( $this->self_integrity_summary( $options )['tone'], array( 'critical', 'off', 'warning' ), true );
7648 ?>
7649 <?php if ( $last_results && ! $vg_self_alarm && empty( $critical_modified ) && empty( $regular_modified ) && empty( $last_results['suspicious'] ) && empty( $last_results['extra'] ) && ! $has_closed ) : ?>
7650 <p class="vigilante-all-clear" style="color: #00a32a; font-weight: bold;">
7651 <?php esc_html_e( 'Good Job! All files passed integrity check. No issues found.', 'vigilante' ); ?>
7652 </p>
7653 <?php endif; ?>
7654 <?php endif; ?>
7655 </div>
7656 </div>
7657 <?php endif; ?>
7658
7659 <?php if ( ! empty( $ignored_closed_plugins ) ) : ?>
7660 <div id="vigilante-section-fi-ignored-closed" class="vigilante-settings-section">
7661 <h2><?php esc_html_e( 'Ignored Closed + Removed Plugins', 'vigilante' ); ?></h2>
7662 <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>
7663 <table class="wp-list-table widefat fixed striped">
7664 <thead>
7665 <tr>
7666 <th><?php esc_html_e( 'Plugin', 'vigilante' ); ?></th>
7667 <th style="width: 110px;"><?php esc_html_e( 'State', 'vigilante' ); ?></th>
7668 <th style="width: 120px;"><?php esc_html_e( 'Closed date', 'vigilante' ); ?></th>
7669 <th style="width: 130px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
7670 </tr>
7671 </thead>
7672 <tbody>
7673 <?php foreach ( $ignored_closed_plugins as $icp_slug => $icp_entry ) :
7674 $icp_state = $icp_entry['state'] ?? '';
7675 $icp_state_label = 'closed' === $icp_state ? __( 'Closed', 'vigilante' ) : __( 'Removed', 'vigilante' );
7676 ?>
7677 <tr>
7678 <td>
7679 <strong><?php echo esc_html( $icp_entry['name'] ?? $icp_slug ); ?></strong><br>
7680 <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>
7681 </td>
7682 <td><?php echo esc_html( $icp_state_label ); ?></td>
7683 <td><?php echo esc_html( $icp_entry['closed_date'] ?? '' ); ?></td>
7684 <td>
7685 <button type="button" class="button button-small vigilante-unignore-closed-plugin" data-slug="<?php echo esc_attr( $icp_slug ); ?>">
7686 <?php esc_html_e( 'Stop ignoring', 'vigilante' ); ?>
7687 </button>
7688 </td>
7689 </tr>
7690 <?php endforeach; ?>
7691 </tbody>
7692 </table>
7693 <p style="margin-top: 10px;">
7694 <button type="button" class="button vigilante-clear-ignored-closed-plugins"><?php esc_html_e( 'Clear All Ignored Closed + Removed Plugins', 'vigilante' ); ?></button>
7695 </p>
7696 </div>
7697 <?php endif; ?>
7698
7699 <?php if ( ! empty( $ignored_files ) ) : ?>
7700 <div id="vigilante-section-fi-ignored" class="vigilante-settings-section">
7701 <h2><?php esc_html_e( 'Ignored Files', 'vigilante' ); ?></h2>
7702 <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>
7703 <div class="vigilante-paginated-section" data-bulk-mode="unignore">
7704 <div class="vigilante-fi-bulk-bar">
7705 <button type="button" class="button vigilante-bulk-unignore" disabled><?php esc_html_e( 'Stop ignoring selected', 'vigilante' ); ?></button>
7706 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
7707 </div>
7708 <div class="vigilante-fi-pagination-wrap"></div>
7709 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
7710 <thead>
7711 <tr>
7712 <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>
7713 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
7714 <th style="width: 120px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
7715 </tr>
7716 </thead>
7717 <tbody>
7718 <?php foreach ( $ignored_files as $file ) : ?>
7719 <tr>
7720 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file ); ?>"></th>
7721 <td><code><?php echo esc_html( $file ); ?></code></td>
7722 <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>
7723 </tr>
7724 <?php endforeach; ?>
7725 </tbody>
7726 </table>
7727 </div>
7728 <p style="margin-top: 10px;">
7729 <button type="button" class="button vigilante-clear-ignored"><?php esc_html_e( 'Clear All Ignored Files', 'vigilante' ); ?></button>
7730 </p>
7731 </div>
7732 <?php endif; ?>
7733 <?php
7734 }
7735
7736 /**
7737 * Render sidebar with promotional widgets
7738 */
7739 private function render_sidebar() {
7740 $promo_banner = new Vigilante_Promo_Banner( 'vigilante' );
7741 $promo_banner->render();
7742 }
7743
7744 /**
7745 * AJAX: Download a ZIP backup of the critical config files.
7746 *
7747 * Streams wp-config.php and .htaccess (and robots.txt if present) as a
7748 * downloadable archive. Config backups are no longer left as files under the
7749 * web root, so this hands the admin the archive directly.
7750 */
7751 public function ajax_download_files_backup() {
7752 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7753
7754 if ( ! current_user_can( 'manage_options' ) ) {
7755 wp_die( esc_html__( 'Permission denied.', 'vigilante' ), 403 );
7756 }
7757
7758 // The archive carries wp-config.php, which a whole network shares. On a
7759 // network manage_options is held by every subsite administrator, so the
7760 // same gate the writers use applies here.
7761 if ( ! Vigilante_Settings::can_write_shared_files() ) {
7762 wp_die( esc_html( Vigilante_Settings::get_shared_files_notice() ), 403 );
7763 }
7764
7765 $backup_manager = new Vigilante_Backup_Manager();
7766 $result = $backup_manager->stream_files_zip();
7767
7768 // stream_files_zip() exits on success; only a WP_Error returns here.
7769 if ( is_wp_error( $result ) ) {
7770 wp_die( esc_html( $result->get_error_message() ), 500 );
7771 }
7772 }
7773
7774 /**
7775 * AJAX: Save settings
7776 */
7777 public function ajax_save_settings() {
7778 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7779
7780 if ( ! current_user_can( 'manage_options' ) ) {
7781 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7782 }
7783
7784 $section = isset( $_POST['section'] ) ? sanitize_key( $_POST['section'] ) : '';
7785
7786 // Handle $_POST['data'] based on type
7787 if ( isset( $_POST['data'] ) && is_array( $_POST['data'] ) ) {
7788 $data = map_deep( wp_unslash( $_POST['data'] ), 'sanitize_text_field' );
7789 } elseif ( isset( $_POST['data'] ) ) {
7790 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
7791 $raw_data = wp_unslash( $_POST['data'] );
7792 parse_str( $raw_data, $data );
7793 $data = map_deep( $data, 'sanitize_textarea_field' );
7794 } else {
7795 $data = array();
7796 }
7797
7798 if ( empty( $section ) ) {
7799 wp_send_json_error( __( 'Invalid section.', 'vigilante' ) );
7800 }
7801
7802 // Check if 2FA is being enabled or method changed (for notification sending)
7803 $send_2fa_notification = false;
7804 $send_login_url_notification = false;
7805
7806 if ( 'login_security' === $section ) {
7807 // Read old state from DB
7808 $db_options = get_option( Vigilante_Settings::OPTION_NAME, array() );
7809 $old_2fa_enabled = ! empty( $db_options['login_security']['two_factor']['enabled'] );
7810 $old_method = $db_options['login_security']['two_factor']['method'] ?? 'email';
7811
7812 // Check new state from submitted data
7813 $new_2fa_enabled = false;
7814 $notify_on_enable = false;
7815 $new_method = isset( $data['login_security']['two_factor']['method'] )
7816 ? sanitize_key( $data['login_security']['two_factor']['method'] )
7817 : 'email';
7818
7819 if ( isset( $data['login_security']['two_factor']['enabled'] ) ) {
7820 $new_2fa_enabled = filter_var( $data['login_security']['two_factor']['enabled'], FILTER_VALIDATE_BOOLEAN );
7821 }
7822 if ( isset( $data['login_security']['two_factor']['notify_on_enable'] ) ) {
7823 $notify_on_enable = filter_var( $data['login_security']['two_factor']['notify_on_enable'], FILTER_VALIDATE_BOOLEAN );
7824 }
7825
7826 // Send notification if:
7827 // 1. 2FA is being enabled (was off, now on) OR
7828 // 2. Method changed while 2FA is enabled
7829 if ( $notify_on_enable && $new_2fa_enabled ) {
7830 if ( ! $old_2fa_enabled || ( $old_2fa_enabled && $old_method !== $new_method ) ) {
7831 $send_2fa_notification = true;
7832 }
7833 }
7834
7835 // Check if login URL changed and notification is enabled
7836 $old_login_url = $db_options['login_security']['custom_login_url'] ?? '';
7837 $new_login_url = isset( $data['login_security']['custom_login_url'] )
7838 ? sanitize_title( $data['login_security']['custom_login_url'] )
7839 : '';
7840 $notify_on_url_change = isset( $data['login_security']['notify_on_login_url_change'] )
7841 ? filter_var( $data['login_security']['notify_on_login_url_change'], FILTER_VALIDATE_BOOLEAN )
7842 : false;
7843
7844 if ( $notify_on_url_change && ! empty( $new_login_url ) && $new_login_url !== $old_login_url ) {
7845 $send_login_url_notification = true;
7846 }
7847 }
7848
7849 // Get defaults
7850 $defaults = $this->settings->get_default_options();
7851
7852 // Read ONLY saved options from database (not merged with defaults)
7853 $saved_options = get_option( Vigilante_Settings::OPTION_NAME, array() );
7854
7855 // What is stored before this request changes anything: the shared file
7856 // settings this user may not change are put back from here (2.11.6).
7857 $stored_options = $saved_options;
7858 $locked = Vigilante_Settings::get_locked_file_settings();
7859
7860 if ( isset( $locked[ $section ] ) && true === $locked[ $section ] ) {
7861 wp_send_json_error( Vigilante_Settings::get_shared_files_notice() );
7862 }
7863
7864 // A module switch is a single key, so refusing says more than a success
7865 // that changed nothing, and the dashboard puts the toggle back.
7866 if ( 'modules' === $section && isset( $locked['modules'], $data['modules'] ) && is_array( $locked['modules'] ) && is_array( $data['modules'] ) ) {
7867 foreach ( array_keys( $data['modules'] ) as $vg_module ) {
7868 if ( in_array( sanitize_key( $vg_module ), $locked['modules'], true ) ) {
7869 wp_send_json_error( Vigilante_Settings::get_shared_files_notice() );
7870 }
7871 }
7872 }
7873
7874 $rejected_ips = array();
7875 $rejected_proxies = array();
7876
7877 // Handle modules
7878 if ( 'modules' === $section && isset( $data['modules'] ) ) {
7879 if ( ! isset( $saved_options['modules'] ) ) {
7880 $saved_options['modules'] = array();
7881 }
7882 foreach ( $data['modules'] as $module => $enabled ) {
7883 $module = sanitize_key( $module );
7884 $saved_options['modules'][ $module ] = in_array( $enabled, array( '1', 1, 'true', true ), true );
7885 }
7886 // Clear active preset when modules change
7887 update_option( 'vigilante_active_preset', '' );
7888 } else {
7889 // Process primary section
7890 if ( isset( $data[ $section ] ) && is_array( $data[ $section ] ) ) {
7891 $section_defaults = isset( $defaults[ $section ] ) ? $defaults[ $section ] : array();
7892 $current_section = isset( $saved_options[ $section ] ) ? $saved_options[ $section ] : array();
7893
7894 // Process the submitted data
7895 $processed = $this->process_section_data( $data[ $section ], $section_defaults, $current_section );
7896
7897 // The IP boxes are free text and, until 2.9.9, whatever was typed
7898 // went straight into the option. An entry the matcher can never
7899 // match still sits in a security list looking like protection,
7900 // so the ones that cannot match are dropped and reported back
7901 // instead of being stored in silence.
7902 $rejected_ips = $this->filter_ip_lists( $section, $processed, $rejected_proxies );
7903
7904 // Save the processed section
7905 $saved_options[ $section ] = $processed;
7906
7907 // Clear active preset when any section settings change
7908 update_option( 'vigilante_active_preset', '' );
7909 }
7910 }
7911
7912 // Clear cache before saving
7913 wp_cache_delete( Vigilante_Settings::OPTION_NAME, 'options' );
7914
7915 $saved_options = Vigilante_Settings::keep_locked_file_settings( $saved_options, $stored_options );
7916
7917 // Save to database
7918 update_option( Vigilante_Settings::OPTION_NAME, $saved_options );
7919
7920 // Clear the settings cache
7921 $this->settings->clear_cache();
7922
7923 // Apply changes based on section
7924 $this->apply_section_changes( $section, $saved_options );
7925
7926 // Send 2FA notifications after settings are saved
7927 $notification_result = null;
7928 if ( $send_2fa_notification ) {
7929 $notification_result = $this->send_2fa_enable_notifications();
7930 }
7931
7932 // Send login URL notifications after settings are saved
7933 $login_url_result = null;
7934 if ( $send_login_url_notification ) {
7935 $login_url_result = $this->send_login_url_notifications();
7936 }
7937
7938 // Build success message
7939 $message = __( 'Settings saved successfully.', 'vigilante' );
7940
7941 if ( $notification_result && $notification_result['sent'] > 0 ) {
7942 $message .= ' ' . sprintf(
7943 /* translators: %d: Number of emails sent */
7944 _n(
7945 '2FA notification sent to %d user.',
7946 '2FA notifications sent to %d users.',
7947 $notification_result['sent'],
7948 'vigilante'
7949 ),
7950 $notification_result['sent']
7951 );
7952 }
7953
7954 if ( $login_url_result && $login_url_result['sent'] > 0 ) {
7955 $message .= ' ' . sprintf(
7956 /* translators: %d: Number of emails sent */
7957 _n(
7958 'Login URL notification sent to %d user.',
7959 'Login URL notifications sent to %d users.',
7960 $login_url_result['sent'],
7961 'vigilante'
7962 ),
7963 $login_url_result['sent']
7964 );
7965 }
7966
7967 if ( ! empty( $rejected_ips ) ) {
7968 $message .= ' ' . sprintf(
7969 /* translators: %s: comma separated list of the entries that were not saved. */
7970 _n(
7971 'This entry is not a valid IP, CIDR range or wildcard, so it was not saved: %s',
7972 'These entries are not valid IPs, CIDR ranges or wildcards, so they were not saved: %s',
7973 count( $rejected_ips ),
7974 'vigilante'
7975 ),
7976 implode( ', ', array_map( 'esc_html', $rejected_ips ) )
7977 );
7978 }
7979
7980 if ( ! empty( $rejected_proxies ) ) {
7981 $message .= ' ' . sprintf(
7982 /* translators: %s: comma separated list of the trusted proxy entries that were not saved. */
7983 _n(
7984 'A trusted proxy must be an exact IP or a CIDR range, not a wildcard, so this entry was not saved: %s',
7985 'A trusted proxy must be an exact IP or a CIDR range, not a wildcard, so these entries were not saved: %s',
7986 count( $rejected_proxies ),
7987 'vigilante'
7988 ),
7989 implode( ', ', array_map( 'esc_html', $rejected_proxies ) )
7990 );
7991 }
7992
7993 wp_send_json_success( $message );
7994 }
7995
7996 /**
7997 * Keep only the IP patterns the matcher can actually match
7998 *
7999 * @since 2.9.9
8000 *
8001 * @param string $section Section being saved.
8002 * @param array $processed Section data, edited in place.
8003 * @return array Entries that were dropped, for the message back to the user.
8004 */
8005 private function filter_ip_lists( $section, &$processed, &$rejected_proxies = array() ) {
8006 $rejected_proxies = array();
8007
8008 // Trusted proxies feed an identity decision, so only exact addresses and
8009 // CIDR ranges belong there: a wildcard is stripped with its own message,
8010 // never stored looking effective. The matcher ignores it anyway (see
8011 // Vigilante_IP_Utils::in_list_ip_or_cidr), this stops it persisting.
8012 if ( 'firewall' === $section && isset( $processed['trusted_proxies'] ) && is_array( $processed['trusted_proxies'] ) ) {
8013 $split = Vigilante_IP_Utils::split_list_ip_or_cidr( $processed['trusted_proxies'] );
8014 $processed['trusted_proxies'] = $split['valid'];
8015 $rejected_proxies = $split['rejected'];
8016 }
8017
8018 $lists = array(
8019 'firewall' => array( 'ip_whitelist', 'ip_blacklist' ),
8020 'login_security' => array( 'ip_whitelist' ),
8021 );
8022
8023 if ( ! isset( $lists[ $section ] ) ) {
8024 return array();
8025 }
8026
8027 $rejected = array();
8028
8029 foreach ( $lists[ $section ] as $key ) {
8030 if ( ! isset( $processed[ $key ] ) || ! is_array( $processed[ $key ] ) ) {
8031 continue;
8032 }
8033
8034 $split = Vigilante_IP_Utils::split_list( $processed[ $key ] );
8035 $processed[ $key ] = $split['valid'];
8036 $rejected = array_merge( $rejected, $split['rejected'] );
8037 }
8038
8039 return array_values( array_unique( $rejected ) );
8040 }
8041
8042 /**
8043 * Send 2FA enable notifications to users
8044 *
8045 * @return array Result with 'sent' and 'failed' counts.
8046 */
8047 private function send_2fa_enable_notifications() {
8048 $result = array(
8049 'sent' => 0,
8050 'failed' => 0,
8051 );
8052
8053 // Get settings for roles and method
8054 $login_security = $this->settings->get_section( 'login_security' );
8055 $two_factor = isset( $login_security['two_factor'] ) ? $login_security['two_factor'] : array();
8056 $roles = isset( $two_factor['enforced_roles'] ) ? $two_factor['enforced_roles'] : array( 'administrator' );
8057 $method = isset( $two_factor['method'] ) ? $two_factor['method'] : 'email';
8058
8059 if ( empty( $roles ) ) {
8060 $roles = array( 'administrator' );
8061 }
8062
8063 $excluded = isset( $two_factor['excluded_users'] ) ? array_map( 'absint', $two_factor['excluded_users'] ) : array();
8064
8065 // Get users with these roles
8066 $args = array(
8067 'role__in' => $roles,
8068 );
8069 if ( ! empty( $excluded ) ) {
8070 // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- Small excluded users list from settings.
8071 $args['exclude'] = $excluded;
8072 }
8073 $users = get_users( $args );
8074
8075 if ( empty( $users ) ) {
8076 return $result;
8077 }
8078
8079 $site_name = get_bloginfo( 'name' );
8080 $from_name = ! empty( $two_factor['email_from_name'] ) ? $two_factor['email_from_name'] : $site_name;
8081
8082 if ( 'totp' === $method ) {
8083 // Use TOTP class for styled HTML emails
8084 if ( ! class_exists( 'Vigilante_Two_Factor_TOTP' ) ) {
8085 require_once VIGILANTE_INCLUDES_DIR . 'class-two-factor-totp.php';
8086 }
8087 $totp = new Vigilante_Two_Factor_TOTP( $this->settings, $this->database, $this->activity_log );
8088
8089 foreach ( $users as $user ) {
8090 // Skip users who already have TOTP configured
8091 $totp_data = $this->database->get_totp_data( $user->ID );
8092 if ( $totp_data && ! empty( $totp_data['is_configured'] ) ) {
8093 continue;
8094 }
8095
8096 $sent = $totp->send_activation_email( $user, $site_name, $from_name );
8097
8098 if ( $sent ) {
8099 $this->database->mark_2fa_notified( $user->ID );
8100 $result['sent']++;
8101 } else {
8102 $result['failed']++;
8103 }
8104 }
8105 } else {
8106 // Email method - use existing email 2FA class
8107 if ( ! class_exists( 'Vigilante_Two_Factor_Email' ) ) {
8108 require_once VIGILANTE_INCLUDES_DIR . 'class-two-factor-email.php';
8109 }
8110 $email_2fa = new Vigilante_Two_Factor_Email( $this->settings, $this->database, $this->activity_log );
8111 return $email_2fa->send_activation_notifications( false );
8112 }
8113
8114 return $result;
8115 }
8116
8117 /**
8118 * Send login URL change notifications to users with admin access
8119 *
8120 * @return array Result with 'sent' and 'failed' counts.
8121 */
8122 private function send_login_url_notifications() {
8123 $login_options = $this->settings->get_section( 'login_security' );
8124 $custom_url = ! empty( $login_options['custom_login_url'] ) ? sanitize_title( $login_options['custom_login_url'] ) : '';
8125
8126 if ( empty( $custom_url ) ) {
8127 return array( 'sent' => 0, 'failed' => 0 );
8128 }
8129
8130 $login_url = home_url( $custom_url . '/' );
8131 $site_name = get_bloginfo( 'name' );
8132
8133 $admin_roles = array( 'administrator', 'editor', 'author', 'contributor' );
8134 $users = get_users( array( 'role__in' => $admin_roles ) );
8135
8136 if ( empty( $users ) ) {
8137 return array( 'sent' => 0, 'failed' => 0 );
8138 }
8139
8140 $subject = sprintf(
8141 /* translators: %s: Site name */
8142 __( '[%s] Your login URL has changed', 'vigilante' ),
8143 $site_name
8144 );
8145
8146 $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' ) );
8147 $body .= Vigilante_Email_Template::url_box( $login_url, __( 'Your new login URL:', 'vigilante' ) );
8148 $body .= Vigilante_Email_Template::alert_box( __( 'The old login address (wp-login.php) will no longer work.', 'vigilante' ) );
8149 $body .= Vigilante_Email_Template::button( $login_url, __( 'Go to login', 'vigilante' ) );
8150
8151 $sent = 0;
8152 $failed = 0;
8153
8154 foreach ( $users as $user ) {
8155 $result = Vigilante_Email_Template::send(
8156 $user->user_email,
8157 $subject,
8158 __( 'Login URL changed', 'vigilante' ),
8159 $body
8160 );
8161 if ( $result ) {
8162 $sent++;
8163 } else {
8164 $failed++;
8165 }
8166 }
8167
8168 if ( $this->activity_log ) {
8169 $this->activity_log->log(
8170 'login',
8171 'login_url_notified',
8172 sprintf(
8173 /* translators: 1: Sent count, 2: Failed count */
8174 __( 'Login URL notification sent on save: %1$d sent, %2$d failed', 'vigilante' ),
8175 $sent,
8176 $failed
8177 )
8178 );
8179 }
8180
8181 return array( 'sent' => $sent, 'failed' => $failed );
8182 }
8183
8184 /**
8185 * Process section data maintaining proper types from defaults
8186 *
8187 * @param array $submitted_data Data submitted from form.
8188 * @param array $defaults Default values for this section.
8189 * @param array $current Current saved values.
8190 * @param string $section_name Section name for special handling.
8191 * @return array Processed data.
8192 */
8193 private function process_section_data( $submitted_data, $defaults, $current, $section_name = '' ) {
8194 // Start with defaults, then merge current saved values
8195 $result = array_replace_recursive( $defaults, $current );
8196
8197 // Process each submitted value
8198 foreach ( $submitted_data as $key => $value ) {
8199 $key = sanitize_key( $key );
8200
8201 if ( is_array( $value ) ) {
8202 // Nested array (like rate_limiting)
8203 $nested_defaults = isset( $defaults[ $key ] ) && is_array( $defaults[ $key ] ) ? $defaults[ $key ] : array();
8204 $nested_current = isset( $result[ $key ] ) && is_array( $result[ $key ] ) ? $result[ $key ] : array();
8205 $result[ $key ] = $this->process_section_data( $value, $nested_defaults, $nested_current, $key );
8206 } else {
8207 // Determine type from default value
8208 $default_value = isset( $defaults[ $key ] ) ? $defaults[ $key ] : null;
8209
8210 if ( null === $default_value ) {
8211 // No default, check current value type or use as string
8212 $current_value = isset( $current[ $key ] ) ? $current[ $key ] : null;
8213 if ( is_bool( $current_value ) ) {
8214 $result[ $key ] = in_array( $value, array( '1', 1, 'true', true ), true );
8215 } elseif ( is_int( $current_value ) ) {
8216 $result[ $key ] = intval( $value );
8217 } elseif ( is_array( $current_value ) ) {
8218 $result[ $key ] = is_string( $value ) ? array_filter( array_map( 'trim', explode( "\n", $value ) ) ) : (array) $value;
8219 } else {
8220 $result[ $key ] = sanitize_text_field( $value );
8221 }
8222 } elseif ( is_bool( $default_value ) ) {
8223 // Boolean: '1', 1, 'true' become true; '0', 0, '', 'false' become false
8224 $result[ $key ] = in_array( $value, array( '1', 1, 'true', true ), true );
8225 } elseif ( is_int( $default_value ) ) {
8226 // Integer - with special handling for time fields shown in minutes
8227 $int_value = intval( $value );
8228
8229 // Convert minutes to seconds for login_security duration fields
8230 // These are displayed as minutes in the form but stored as seconds
8231 if ( in_array( $key, array( 'lockout_duration', 'max_lockout_duration' ), true ) ) {
8232 $int_value = $int_value * 60;
8233 }
8234
8235 $result[ $key ] = $int_value;
8236 } elseif ( is_array( $default_value ) ) {
8237 // Array from textarea (e.g., IP lists)
8238 if ( is_string( $value ) ) {
8239 $result[ $key ] = array_filter( array_map( 'trim', explode( "\n", $value ) ) );
8240 } else {
8241 $result[ $key ] = (array) $value;
8242 }
8243 } else {
8244 // String - preserve newlines for textarea fields
8245 if ( is_string( $value ) && ( strpos( $value, "\n" ) !== false || strpos( $value, "\r" ) !== false ) ) {
8246 $result[ $key ] = sanitize_textarea_field( $value );
8247 } else {
8248 $result[ $key ] = sanitize_text_field( $value );
8249 }
8250 }
8251 }
8252 }
8253
8254 // Handle unchecked checkboxes: HTML forms don't submit unchecked boxes
8255 // If a boolean field exists in defaults but NOT in submitted_data, set it to false
8256 //
8257 // EXCEPTION: the top-level 'enabled' flag of every section is the
8258 // module's master switch and is controlled by the Dashboard module
8259 // toggle, NOT by a checkbox inside the section's form. Treating it
8260 // like a regular checkbox here would silently switch the module off
8261 // every time the user saves the tab — see the REST API enabled=false
8262 // regression. We only skip it at the top level (when section_name is
8263 // empty); nested 'enabled' fields like security_headers.csp.enabled
8264 // are real checkboxes and must keep the auto-unset behaviour.
8265 $preserve_top_level = array( 'enabled' );
8266
8267 foreach ( $defaults as $key => $default_value ) {
8268 if ( '' === $section_name && in_array( $key, $preserve_top_level, true ) ) {
8269 continue;
8270 }
8271 if ( is_bool( $default_value ) && ! array_key_exists( $key, $submitted_data ) ) {
8272 $result[ $key ] = false;
8273 } elseif ( is_array( $default_value ) && ! isset( $submitted_data[ $key ] ) ) {
8274 // Check if this is a flat value list (like excluded_users, enforced_roles, ip_whitelist)
8275 // vs a nested settings group (like rate_limiting, two_factor)
8276 // Flat lists: default is empty array OR all values are scalar
8277 $is_value_list = empty( $default_value );
8278 if ( ! $is_value_list ) {
8279 $is_value_list = true;
8280 foreach ( $default_value as $dv ) {
8281 if ( ! is_scalar( $dv ) ) {
8282 $is_value_list = false;
8283 break;
8284 }
8285 }
8286 }
8287
8288 if ( $is_value_list ) {
8289 // All items removed - reset to empty array
8290 $result[ $key ] = array();
8291 } else {
8292 // Nested settings group - handle boolean children
8293 foreach ( $default_value as $nested_key => $nested_default ) {
8294 if ( is_bool( $nested_default ) && isset( $result[ $key ] ) && is_array( $result[ $key ] ) ) {
8295 $nested_submitted = isset( $submitted_data[ $key ] ) && is_array( $submitted_data[ $key ] )
8296 ? $submitted_data[ $key ]
8297 : array();
8298 if ( ! array_key_exists( $nested_key, $nested_submitted ) ) {
8299 $result[ $key ][ $nested_key ] = false;
8300 }
8301 }
8302 }
8303 }
8304 }
8305 }
8306
8307 return $result;
8308 }
8309
8310 /**
8311 * AJAX: Export settings
8312 */
8313 public function ajax_export_settings() {
8314 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8315
8316 if ( ! current_user_can( 'manage_options' ) ) {
8317 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8318 }
8319
8320 $options = $this->settings->get_all_options();
8321 $filename = 'vigilante-settings-' . gmdate( 'Y-m-d-His' ) . '.json';
8322
8323 wp_send_json_success( array(
8324 'content' => wp_json_encode( $options, JSON_PRETTY_PRINT ),
8325 'filename' => $filename,
8326 ) );
8327 }
8328
8329 /**
8330 * AJAX: Import settings
8331 */
8332 public function ajax_import_settings() {
8333 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8334
8335 if ( ! current_user_can( 'manage_options' ) ) {
8336 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8337 }
8338
8339 // Accept both 'settings' (from JS) and 'content' (legacy).
8340 // Do NOT run sanitize_text_field() on the raw payload: it calls
8341 // wp_strip_all_tags() internally, which removes any "<...>" substring
8342 // and turns a valid export JSON into garbage if any stored value
8343 // contains < or > (htaccess snippets, email templates, etc.). The
8344 // real sanitization happens after json_decode(), via map_deep() on
8345 // the parsed array.
8346 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash
8347 $content = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : '';
8348 if ( empty( $content ) ) {
8349 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash
8350 $content = isset( $_POST['content'] ) ? wp_unslash( $_POST['content'] ) : '';
8351 }
8352
8353 if ( empty( $content ) || ! is_string( $content ) ) {
8354 wp_send_json_error( __( 'No content provided.', 'vigilante' ) );
8355 }
8356
8357 $imported = json_decode( $content, true );
8358
8359 if ( json_last_error() !== JSON_ERROR_NONE || ! is_array( $imported ) ) {
8360 wp_send_json_error( __( 'Invalid JSON format.', 'vigilante' ) );
8361 }
8362
8363 // Sanitize imported data recursively
8364 $imported = map_deep( $imported, 'sanitize_text_field' );
8365
8366 // Validate structure: only sections and keys of the schema survive, and
8367 // every value takes the type of its default. Until 2.11.0 this was an
8368 // array_replace_recursive() of the file over the defaults, so any key in
8369 // the file, known or not, landed in vigilante_options (S7). Sections
8370 // the file does not carry keep their defaults; a section it does carry
8371 // replaces the default one whole, because validate_options() has
8372 // already filled in whatever the file left out.
8373 $defaults = $this->settings->get_default_options();
8374 $validated = $this->settings->validate_options( $imported );
8375 $merged = $defaults;
8376
8377 foreach ( $validated as $section => $data ) {
8378 if ( is_array( $data ) ) {
8379 $merged[ $section ] = $data;
8380 }
8381 }
8382
8383 // Save
8384 $merged = Vigilante_Settings::keep_locked_file_settings( $merged, get_option( Vigilante_Settings::OPTION_NAME, array() ) );
8385 update_option( Vigilante_Settings::OPTION_NAME, $merged );
8386 $this->settings->clear_cache();
8387
8388 // Re-evaluate the active preset marker. The imported config may match
8389 // a known preset exactly, partially, or not at all — without this step
8390 // the dashboard would keep showing whatever preset was active before
8391 // the import even if the new config no longer matches it.
8392 $matched_preset = $this->detect_matching_preset( $merged );
8393 if ( null === $matched_preset ) {
8394 delete_option( 'vigilante_active_preset' );
8395 } else {
8396 update_option( 'vigilante_active_preset', $matched_preset );
8397 }
8398
8399 // Apply file changes after import
8400 $this->apply_all_file_changes( $merged );
8401
8402 // Refresh the Security Analyzer score so the dashboard widget reflects
8403 // the imported config rather than the pre-import scan. Reuse the
8404 // post-Under-Attack scan hook (same job: full scan, async).
8405 if ( ! wp_next_scheduled( 'vigilante_under_attack_post_scan' ) ) {
8406 wp_schedule_single_event( time() + 5, 'vigilante_under_attack_post_scan' );
8407 }
8408
8409 wp_send_json_success( __( 'Settings imported successfully.', 'vigilante' ) . $this->locked_file_settings_message() );
8410 }
8411
8412 /**
8413 * Detect whether a vigilante_options array matches a known preset.
8414 *
8415 * A preset matches when every field the preset explicitly declares is
8416 * present in the config with the same (normalised) value. Fields outside
8417 * the preset are ignored — they may have been modified by the user before
8418 * applying the preset and do not invalidate the match. This mirrors how
8419 * apply_preset() now layers presets on top of the user's existing config.
8420 *
8421 * @param array $options The current/imported vigilante_options.
8422 * @return string|null Preset id ('standard', 'maximum') or null if custom.
8423 */
8424 private function detect_matching_preset( $options ) {
8425 if ( ! is_array( $options ) ) {
8426 return null;
8427 }
8428
8429 $presets = $this->settings->get_presets();
8430
8431 foreach ( $presets as $preset_id => $preset_data ) {
8432 unset( $preset_data['name'], $preset_data['description'] );
8433 if ( $this->preset_subset_matches( $preset_data, $options ) ) {
8434 return $preset_id;
8435 }
8436 }
8437
8438 return null;
8439 }
8440
8441 /**
8442 * Check whether every leaf value inside $preset_subset exists with the
8443 * same (normalised) value at the same path inside $config.
8444 *
8445 * @param mixed $preset_subset Branch of the preset definition.
8446 * @param mixed $config Same branch in the live/imported config.
8447 * @return bool
8448 */
8449 private function preset_subset_matches( $preset_subset, $config ) {
8450 if ( is_array( $preset_subset ) ) {
8451 if ( ! is_array( $config ) ) {
8452 return false;
8453 }
8454 foreach ( $preset_subset as $key => $value ) {
8455 if ( ! array_key_exists( $key, $config ) ) {
8456 return false;
8457 }
8458 if ( ! $this->preset_subset_matches( $value, $config[ $key ] ) ) {
8459 return false;
8460 }
8461 }
8462 return true;
8463 }
8464
8465 return $this->normalise_scalar_for_compare( $preset_subset ) === $this->normalise_scalar_for_compare( $config );
8466 }
8467
8468 /**
8469 * Normalise a scalar value so that the variants WordPress and the form
8470 * layer routinely produce ('1' / 1 / true → "1"; '' / '0' / 0 / false /
8471 * null → "") compare equal. Other values become strings unchanged.
8472 *
8473 * @param mixed $value
8474 * @return string
8475 */
8476 private function normalise_scalar_for_compare( $value ) {
8477 if ( is_bool( $value ) ) {
8478 return $value ? '1' : '';
8479 }
8480 if ( null === $value ) {
8481 return '';
8482 }
8483 if ( is_int( $value ) || is_float( $value ) ) {
8484 return (string) $value;
8485 }
8486 if ( is_string( $value ) ) {
8487 if ( 'true' === $value ) {
8488 return '1';
8489 }
8490 if ( 'false' === $value ) {
8491 return '';
8492 }
8493 return $value;
8494 }
8495 // Arrays and objects shouldn't reach here (handled by recursion above),
8496 // but if they do, fall back to a stable comparable representation.
8497 return wp_json_encode( $value );
8498 }
8499
8500 /**
8501 * AJAX: Apply preset
8502 */
8503 public function ajax_apply_preset() {
8504 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8505
8506 if ( ! current_user_can( 'manage_options' ) ) {
8507 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8508 }
8509
8510 $preset = isset( $_POST['preset'] ) ? sanitize_key( $_POST['preset'] ) : '';
8511
8512 // Handle reset to defaults
8513 if ( 'reset' === $preset ) {
8514 $stored_options = get_option( Vigilante_Settings::OPTION_NAME, array() );
8515 $defaults = Vigilante_Settings::get_defaults_preserving_user_data( $stored_options );
8516 $defaults = Vigilante_Settings::keep_locked_file_settings( $defaults, $stored_options );
8517 update_option( Vigilante_Settings::OPTION_NAME, $defaults );
8518 $this->settings->clear_cache();
8519
8520 // Clear active preset
8521 update_option( 'vigilante_active_preset', '' );
8522
8523 // Apply file changes after reset
8524 $this->apply_all_file_changes( $defaults );
8525
8526 wp_send_json_success( __( 'Settings reset to defaults.', 'vigilante' ) . $this->locked_file_settings_message() );
8527 return;
8528 }
8529
8530 $presets = $this->settings->get_presets();
8531
8532 if ( ! isset( $presets[ $preset ] ) ) {
8533 wp_send_json_error( __( 'Invalid preset.', 'vigilante' ) );
8534 }
8535
8536 $preset_options = $presets[ $preset ];
8537 unset( $preset_options['name'], $preset_options['description'] );
8538
8539 // Layer the preset on top of the user's CURRENT configuration, not on
8540 // top of defaults. This way applying a preset only changes the fields
8541 // the preset explicitly mentions; everything else stays as the user
8542 // had it. For example, applying Maximum will not flip HSTS off if the
8543 // user had it on — Maximum doesn't touch HSTS, so it's left alone.
8544 // Use "Reset to Defaults" if a clean slate is needed.
8545 $current = get_option( Vigilante_Settings::OPTION_NAME, array() );
8546 if ( ! is_array( $current ) ) {
8547 $current = array();
8548 }
8549 // Make sure all known keys exist before merging — the merge does not
8550 // invent keys that are missing on both sides.
8551 $current = Vigilante_Settings::merge_preset( $this->settings->get_default_options(), $current );
8552
8553 $merged = Vigilante_Settings::merge_preset( $current, $preset_options );
8554 $merged = Vigilante_Settings::keep_locked_file_settings( $merged, get_option( Vigilante_Settings::OPTION_NAME, array() ) );
8555
8556 update_option( Vigilante_Settings::OPTION_NAME, $merged );
8557 $this->settings->clear_cache();
8558
8559 // Save active preset
8560 update_option( 'vigilante_active_preset', $preset );
8561
8562 // Apply file changes after preset
8563 $this->apply_all_file_changes( $merged );
8564
8565 wp_send_json_success( __( 'Preset applied successfully.', 'vigilante' ) . $this->locked_file_settings_message() );
8566 }
8567
8568 /**
8569 * AJAX: Reset a specific section to defaults
8570 */
8571 public function ajax_reset_section() {
8572 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8573
8574 if ( ! current_user_can( 'manage_options' ) ) {
8575 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8576 }
8577
8578 $section = isset( $_POST['section'] ) ? sanitize_key( $_POST['section'] ) : '';
8579
8580 if ( empty( $section ) ) {
8581 wp_send_json_error( __( 'No section specified.', 'vigilante' ) );
8582 }
8583
8584 // Get current options and defaults. get_defaults_preserving_user_data()
8585 // applies the tweaks a fresh installation gets, so the button and a new
8586 // install agree, and keeps whatever the owner typed in.
8587 $current_options = $this->settings->get_all_options();
8588 $defaults = Vigilante_Settings::get_defaults_preserving_user_data( $current_options );
8589
8590 // Check if section exists in defaults
8591 if ( ! isset( $defaults[ $section ] ) ) {
8592 wp_send_json_error( __( 'Invalid section.', 'vigilante' ) );
8593 }
8594
8595 $new_values = $defaults[ $section ];
8596
8597 /*
8598 * On a subsite, the settings written to wp-config.php and .htaccess are
8599 * the main site's business. Resetting the local copy of those would only
8600 * make this screen disagree with the file, so they are carried over
8601 * untouched, and a section that is nothing but shared settings is not
8602 * reset at all. On the main site, a user without network rights keeps
8603 * the ones the shared files are built from as well (2.11.6).
8604 */
8605 $locked = Vigilante_Settings::get_locked_file_settings();
8606
8607 if ( isset( $locked[ $section ] ) && true === $locked[ $section ] ) {
8608 wp_send_json_error( Vigilante_Settings::get_shared_files_notice() );
8609 }
8610
8611 $current_options[ $section ] = $new_values;
8612 $current_options = Vigilante_Settings::keep_locked_file_settings( $current_options, get_option( Vigilante_Settings::OPTION_NAME, array() ) );
8613
8614 // Save
8615 update_option( Vigilante_Settings::OPTION_NAME, $current_options );
8616 $this->settings->clear_cache();
8617
8618 // Apply file changes if needed
8619 $this->apply_section_changes( $section, $current_options );
8620
8621 wp_send_json_success( array(
8622 'message' => __( 'Section reset to defaults.', 'vigilante' ),
8623 'section' => $section,
8624 'reload' => true,
8625 ) );
8626 }
8627
8628 /**
8629 * AJAX: Clear lockouts
8630 */
8631 public function ajax_clear_lockouts() {
8632 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8633
8634 if ( ! current_user_can( 'manage_options' ) ) {
8635 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8636 }
8637
8638 $ip = isset( $_POST['ip'] ) ? sanitize_text_field( wp_unslash( $_POST['ip'] ) ) : '';
8639
8640 if ( ! empty( $ip ) ) {
8641 $this->database->clear_lockout( $ip );
8642 } else {
8643 $this->database->clear_all_lockouts();
8644 }
8645
8646 wp_send_json_success( __( 'Lockouts cleared.', 'vigilante' ) );
8647 }
8648
8649 /**
8650 * AJAX: Clear logs
8651 */
8652 public function ajax_clear_logs() {
8653 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8654
8655 if ( ! current_user_can( 'manage_options' ) ) {
8656 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8657 }
8658
8659 if ( $this->activity_log ) {
8660 $result = $this->activity_log->clear_all_logs();
8661 if ( $result ) {
8662 wp_send_json_success( __( 'Logs cleared.', 'vigilante' ) );
8663 } else {
8664 wp_send_json_error( __( 'Failed to clear logs.', 'vigilante' ) );
8665 }
8666 } else {
8667 wp_send_json_error( __( 'Activity log not available.', 'vigilante' ) );
8668 }
8669 }
8670
8671 /**
8672 * AJAX: Run file integrity scan.
8673 *
8674 * Triggers the file integrity scan, which now also runs the closed plugins
8675 * check at the end when the `check_closed_plugins` toggle is on. Activity
8676 * log is passed through so Security Audit entries (both file-level and
8677 * plugin-status) are recorded from this entry point.
8678 */
8679 public function ajax_run_scan() {
8680 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8681
8682 if ( ! current_user_can( 'manage_options' ) ) {
8683 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8684 }
8685
8686 // Clear previous results before running new scan
8687 delete_option( 'vigilante_last_integrity_results' );
8688 delete_option( 'vigilante_last_integrity_scan' );
8689
8690 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database, $this->activity_log );
8691 $results = $file_integrity->run_scan();
8692
8693 // Save new results
8694 update_option( 'vigilante_last_integrity_scan', time() );
8695 update_option( 'vigilante_last_integrity_results', $results );
8696
8697 // On the main site the scan does compute the lines of wp-config.php and
8698 // .htaccess, for the network administrator. Somebody without network
8699 // rights gets the change and its sizes, not the lines.
8700 if ( $this->critical_approval_locked() && ! empty( $results['modified'] ) && is_array( $results['modified'] ) ) {
8701 foreach ( $results['modified'] as $index => $item ) {
8702 if ( is_array( $item ) && 'critical_config' === ( $item['type'] ?? '' ) ) {
8703 $results['modified'][ $index ]['diff'] = Vigilante_File_Integrity::network_only_diff();
8704 }
8705 }
8706 }
8707
8708 wp_send_json_success( array(
8709 'message' => __( 'Scan completed.', 'vigilante' ),
8710 'results' => $results,
8711 'ignored_count' => count( get_option( 'vigilante_ignored_files', array() ) ),
8712 ) );
8713 }
8714
8715 /**
8716 * AJAX: Clear scan results.
8717 *
8718 * Wipes visually everything inside "Last Scan Results": file scan findings
8719 * (Suspicious / Modified / Extra / Critical Config), file hashes and the
8720 * Closed + Removed Plugins block.
8721 *
8722 * Implementation detail to keep persistence intact:
8723 * - We delete the file scan options + hashes outright.
8724 * - For plugin status we ONLY delete the last_check timestamp — the state
8725 * map and the ignore list are preserved in DB. The render gates the
8726 * plugin_status subsections on last_check > 0, so they hide after
8727 * Clear (visual reset) and reappear on the next Run Scan Now with the
8728 * state intact. This avoids degrading a 'removed' slug (404 without
8729 * metadata) back to 'not_in_repo' on the next scan, which would
8730 * silently lose the alert.
8731 *
8732 * The Ignored Files list and the Ignored Closed + Removed Plugins list
8733 * are preserved on purpose; each has its own explicit "Clear All …"
8734 * button.
8735 */
8736 public function ajax_clear_scan() {
8737 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8738
8739 if ( ! current_user_can( 'manage_options' ) ) {
8740 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8741 }
8742
8743 $results = get_option( 'vigilante_last_integrity_results' );
8744 $scanned_at = get_option( 'vigilante_last_integrity_scan' );
8745
8746 delete_option( 'vigilante_last_integrity_results' );
8747 delete_option( 'vigilante_last_integrity_scan' );
8748
8749 /*
8750 * A pending change to wp-config.php or the root .htaccess is closed by
8751 * approving it, which takes the network. Clearing the results was one
8752 * more way to close it without, until the next scan: the ignore list was
8753 * shut in 2.11.8 and this button was left open, found by the cross
8754 * review of 2.11.8. So for somebody who cannot approve, those entries
8755 * stay and everything else goes.
8756 */
8757 // The findings about Vigilant's own files stay too: they report for the
8758 // whole network, and ignoring them already takes network rights.
8759 if ( $this->critical_approval_locked() && is_array( $results ) ) {
8760 $kept = array();
8761 $found = false;
8762 foreach ( array( 'modified', 'missing', 'suspicious', 'extra' ) as $bucket ) {
8763 $kept[ $bucket ] = array_values(
8764 array_filter(
8765 isset( $results[ $bucket ] ) && is_array( $results[ $bucket ] ) ? $results[ $bucket ] : array(),
8766 function ( $item ) {
8767 return is_array( $item ) && in_array( $item['type'] ?? '', array( 'critical_config', 'vigilante_self' ), true );
8768 }
8769 )
8770 );
8771 $found = $found || ! empty( $kept[ $bucket ] );
8772 }
8773
8774 if ( $found ) {
8775 $results = array_merge( $results, $kept );
8776 update_option( 'vigilante_last_integrity_results', $results );
8777 update_option( 'vigilante_last_integrity_scan', $scanned_at ? $scanned_at : time() );
8778 }
8779 }
8780
8781 if ( $this->database ) {
8782 $this->database->clear_file_hashes();
8783 }
8784
8785 // Visual reset of plugin_status block without touching the state map
8786 // or the ignored list. See PHPDoc above for the rationale.
8787 delete_option( 'vigilante_plugin_status_last_check' );
8788
8789 wp_send_json_success( __( 'Scan results cleared.', 'vigilante' ) );
8790 }
8791
8792 /**
8793 * AJAX: Ignore a file from scan results
8794 */
8795 public function ajax_ignore_file() {
8796 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8797
8798 if ( ! current_user_can( 'manage_options' ) ) {
8799 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8800 }
8801
8802 $file = isset( $_POST['file'] ) ? sanitize_text_field( wp_unslash( $_POST['file'] ) ) : '';
8803
8804 if ( empty( $file ) ) {
8805 wp_send_json_error( __( 'No file specified.', 'vigilante' ) );
8806 }
8807
8808 // A change to a shared file is closed by approving it, and approving it
8809 // takes the network. Ignoring it would close the same warning without.
8810 if ( $this->critical_approval_locked() && in_array( $file, array( 'wp-config.php', '.htaccess' ), true ) ) {
8811 wp_send_json_error( $this->critical_approval_notice() );
8812 }
8813
8814 // Vigilant's own files are never ignored, on any site: silencing the
8815 // check that says the security plugin was changed is the one button
8816 // an attacker would want on this screen. Since 3.0.0 those findings
8817 // are not rows of these tables either, so nothing in the interface
8818 // sends them here; this is the door, not the label.
8819 if ( Vigilante_Self_Integrity::is_own_file_path( $file ) ) {
8820 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' ) );
8821 }
8822
8823 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
8824 $file_integrity->ignore_file( $file );
8825
8826 // Also remove the file from stored scan results so UI updates
8827 $results = get_option( 'vigilante_last_integrity_results' );
8828 if ( $results ) {
8829 foreach ( array( 'modified', 'suspicious', 'extra' ) as $category ) {
8830 if ( ! empty( $results[ $category ] ) ) {
8831 $results[ $category ] = array_values(
8832 array_filter(
8833 $results[ $category ],
8834 function ( $item ) use ( $file ) {
8835 return ( is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item ) !== $file;
8836 }
8837 )
8838 );
8839 }
8840 }
8841 update_option( 'vigilante_last_integrity_results', $results );
8842 }
8843
8844 wp_send_json_success( __( 'File added to ignored list.', 'vigilante' ) );
8845 }
8846
8847 /**
8848 * AJAX: Stop ignoring a file
8849 */
8850 public function ajax_unignore_file() {
8851 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8852
8853 if ( ! current_user_can( 'manage_options' ) ) {
8854 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8855 }
8856
8857 $file = isset( $_POST['file'] ) ? sanitize_text_field( wp_unslash( $_POST['file'] ) ) : '';
8858
8859 if ( empty( $file ) ) {
8860 wp_send_json_error( __( 'No file specified.', 'vigilante' ) );
8861 }
8862
8863 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
8864 $file_integrity->unignore_file( $file );
8865
8866 wp_send_json_success( __( 'File removed from ignored list.', 'vigilante' ) );
8867 }
8868
8869 /**
8870 * AJAX: Bulk ignore multiple files at once
8871 *
8872 * Processes a single batch into ignored list and prunes them from the
8873 * stored scan results so the UI updates without a re-scan.
8874 */
8875 public function ajax_bulk_ignore_files() {
8876 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8877
8878 if ( ! current_user_can( 'manage_options' ) ) {
8879 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8880 }
8881
8882 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized below per-item.
8883 $raw_files = isset( $_POST['files'] ) ? wp_unslash( $_POST['files'] ) : array();
8884 if ( ! is_array( $raw_files ) ) {
8885 wp_send_json_error( __( 'Invalid request.', 'vigilante' ) );
8886 }
8887
8888 $files = array();
8889 $locked = $this->critical_approval_locked();
8890 $shared = $locked ? array( 'wp-config.php', '.htaccess' ) : array();
8891 foreach ( $raw_files as $f ) {
8892 $clean = sanitize_text_field( $f );
8893 // Same rule as ajax_ignore_file(): the two shared files when the
8894 // network locks them, and Vigilant's own files always.
8895 if ( '' !== $clean && ! in_array( $clean, $shared, true ) && ! Vigilante_Self_Integrity::is_own_file_path( $clean ) ) {
8896 $files[] = $clean;
8897 }
8898 }
8899
8900 if ( empty( $files ) ) {
8901 wp_send_json_error( __( 'No files selected.', 'vigilante' ) );
8902 }
8903
8904 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
8905 $count = 0;
8906 foreach ( $files as $file ) {
8907 $file_integrity->ignore_file( $file );
8908 $count++;
8909 }
8910
8911 // Also prune the stored scan results so the UI matches the new ignore list.
8912 $results = get_option( 'vigilante_last_integrity_results' );
8913 if ( $results ) {
8914 $files_set = array_flip( $files );
8915 foreach ( array( 'modified', 'suspicious', 'extra' ) as $category ) {
8916 if ( ! empty( $results[ $category ] ) ) {
8917 $results[ $category ] = array_values(
8918 array_filter(
8919 $results[ $category ],
8920 function ( $item ) use ( $files_set ) {
8921 $path = is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item;
8922 return ! isset( $files_set[ $path ] );
8923 }
8924 )
8925 );
8926 }
8927 }
8928 update_option( 'vigilante_last_integrity_results', $results );
8929 }
8930
8931 wp_send_json_success(
8932 array(
8933 'count' => $count,
8934 'message' => sprintf(
8935 /* translators: %d: number of files added to the ignored list */
8936 _n( '%d file added to ignored list.', '%d files added to ignored list.', $count, 'vigilante' ),
8937 $count
8938 ),
8939 )
8940 );
8941 }
8942
8943 /**
8944 * AJAX: Bulk un-ignore multiple files at once
8945 */
8946 public function ajax_bulk_unignore_files() {
8947 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8948
8949 if ( ! current_user_can( 'manage_options' ) ) {
8950 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8951 }
8952
8953 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized below per-item.
8954 $raw_files = isset( $_POST['files'] ) ? wp_unslash( $_POST['files'] ) : array();
8955 if ( ! is_array( $raw_files ) ) {
8956 wp_send_json_error( __( 'Invalid request.', 'vigilante' ) );
8957 }
8958
8959 $files = array();
8960 foreach ( $raw_files as $f ) {
8961 $clean = sanitize_text_field( $f );
8962 if ( '' !== $clean ) {
8963 $files[] = $clean;
8964 }
8965 }
8966
8967 if ( empty( $files ) ) {
8968 wp_send_json_error( __( 'No files selected.', 'vigilante' ) );
8969 }
8970
8971 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
8972 $count = 0;
8973 foreach ( $files as $file ) {
8974 $file_integrity->unignore_file( $file );
8975 $count++;
8976 }
8977
8978 wp_send_json_success(
8979 array(
8980 'count' => $count,
8981 'message' => sprintf(
8982 /* translators: %d: number of files removed from the ignored list */
8983 _n( '%d file removed from ignored list.', '%d files removed from ignored list.', $count, 'vigilante' ),
8984 $count
8985 ),
8986 )
8987 );
8988 }
8989
8990 /**
8991 * AJAX: Clear all ignored files
8992 */
8993 public function ajax_clear_ignored() {
8994 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8995
8996 if ( ! current_user_can( 'manage_options' ) ) {
8997 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8998 }
8999
9000 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
9001 $file_integrity->clear_ignored_files();
9002
9003 wp_send_json_success( __( 'Ignored files list cleared.', 'vigilante' ) );
9004 }
9005
9006 /**
9007 * AJAX: Ignore a closed/removed plugin slug so it stops appearing in the
9008 * main list and email digests. The plugin keeps running on the site;
9009 * silencing is purely cosmetic and reversible.
9010 */
9011 public function ajax_ignore_closed_plugin() {
9012 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9013
9014 if ( ! current_user_can( 'manage_options' ) ) {
9015 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9016 }
9017
9018 $slug = isset( $_POST['slug'] ) ? sanitize_key( wp_unslash( $_POST['slug'] ) ) : '';
9019 if ( '' === $slug ) {
9020 wp_send_json_error( __( 'No slug specified.', 'vigilante' ) );
9021 }
9022
9023 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
9024 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
9025 }
9026 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
9027 $checker->ignore_slug( $slug );
9028
9029 wp_send_json_success( __( 'Plugin added to the ignored list.', 'vigilante' ) );
9030 }
9031
9032 /**
9033 * AJAX: Stop ignoring a previously-ignored closed/removed plugin slug.
9034 */
9035 public function ajax_unignore_closed_plugin() {
9036 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9037
9038 if ( ! current_user_can( 'manage_options' ) ) {
9039 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9040 }
9041
9042 $slug = isset( $_POST['slug'] ) ? sanitize_key( wp_unslash( $_POST['slug'] ) ) : '';
9043 if ( '' === $slug ) {
9044 wp_send_json_error( __( 'No slug specified.', 'vigilante' ) );
9045 }
9046
9047 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
9048 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
9049 }
9050 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
9051 $checker->unignore_slug( $slug );
9052
9053 wp_send_json_success( __( 'Plugin removed from the ignored list.', 'vigilante' ) );
9054 }
9055
9056 /**
9057 * AJAX: Clear the entire ignored-closed-plugins list.
9058 */
9059 public function ajax_clear_ignored_closed_plugins() {
9060 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9061
9062 if ( ! current_user_can( 'manage_options' ) ) {
9063 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9064 }
9065
9066 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
9067 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
9068 }
9069 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
9070 $checker->clear_ignored();
9071
9072 wp_send_json_success( __( 'Ignored closed plugins list cleared.', 'vigilante' ) );
9073 }
9074
9075 /**
9076 * AJAX: Test security headers
9077 */
9078 public function ajax_test_headers() {
9079 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9080
9081 if ( ! current_user_can( 'manage_options' ) ) {
9082 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9083 }
9084
9085 // Get security grade from settings (not from actual HTTP request)
9086 $security_headers = new Vigilante_Security_Headers( $this->settings );
9087 $results = $security_headers->get_security_grade();
9088
9089 wp_send_json_success( $results );
9090 }
9091
9092 /**
9093 * Sanitize section data (kept for compatibility)
9094 *
9095 * @param string $section Section name.
9096 * @param array $data Section data.
9097 * @return array
9098 */
9099 private function sanitize_section_data( $section, $data ) {
9100 $sanitized = array();
9101
9102 foreach ( $data as $key => $value ) {
9103 $key = sanitize_key( $key );
9104
9105 if ( is_array( $value ) ) {
9106 $sanitized[ $key ] = $this->sanitize_section_data( $key, $value );
9107 } elseif ( is_numeric( $value ) ) {
9108 $sanitized[ $key ] = intval( $value );
9109 } else {
9110 $sanitized[ $key ] = sanitize_text_field( $value );
9111 }
9112 }
9113
9114 return $sanitized;
9115 }
9116
9117 /**
9118 * Apply changes after saving settings
9119 *
9120 * @param string $section Section that was updated.
9121 * @param array $all_options All options.
9122 */
9123 private function apply_section_changes( $section, $all_options ) {
9124 // Create fresh settings instance to ensure we have the latest data
9125 $fresh_settings = new Vigilante_Settings();
9126
9127 // The shared Vigilant .htaccess block carries BOTH the firewall's
9128 // file-protection rules and the server-signature / fingerprinting rules
9129 // that are configured under Security Headers. So it must be regenerated
9130 // whenever either section (or the module toggles) changes, not only on
9131 // the firewall save — otherwise toggling "Hide server signature" or
9132 // "Remove fingerprinting headers" never reaches the .htaccess.
9133 if ( in_array( $section, array( 'firewall', 'security_headers', 'modules' ), true ) ) {
9134 $htaccess = new Vigilante_Htaccess_Protection( $fresh_settings );
9135 $sh = $fresh_settings->get_section( 'security_headers' );
9136 $needs_htaccess_block = ! empty( $all_options['modules']['firewall'] )
9137 || ! empty( $sh['hide_server_signature'] )
9138 || ! empty( $sh['remove_fingerprinting_headers'] );
9139
9140 if ( $needs_htaccess_block ) {
9141 $htaccess->apply_rules();
9142 } else {
9143 $htaccess->remove_rules();
9144 }
9145 }
9146
9147 // Regenerate the HTTP security headers (sent by PHP) for the headers section.
9148 if ( 'security_headers' === $section || 'modules' === $section ) {
9149 $security_headers = new Vigilante_Security_Headers( $fresh_settings );
9150 $headers_enabled = ! empty( $all_options['modules']['security_headers'] );
9151
9152 if ( $headers_enabled ) {
9153 $security_headers->apply_rules();
9154 } else {
9155 $security_headers->remove_rules();
9156 }
9157 }
9158
9159 // Regenerate wp-config for wp_hardening section
9160 if ( 'wp_hardening' === $section || 'modules' === $section ) {
9161 $wpconfig = new Vigilante_Wpconfig_Security( $fresh_settings );
9162 $hardening_enabled = ! empty( $all_options['modules']['wp_hardening'] );
9163
9164 if ( $hardening_enabled ) {
9165 $wpconfig->apply_security_constants();
9166 } else {
9167 $wpconfig->remove_constants();
9168 }
9169
9170 // Apply WordPress options for comments/pingbacks
9171 $hardening_options = $all_options['wp_hardening'] ?? array();
9172
9173 if ( $hardening_enabled ) {
9174 // Pingbacks
9175 if ( ! empty( $hardening_options['disable_pingbacks'] ) ) {
9176 update_option( 'default_pingback_flag', 0 );
9177 } else {
9178 // Restore default: pingbacks enabled
9179 update_option( 'default_pingback_flag', 1 );
9180 }
9181
9182 // Trackbacks and ping status
9183 // Only close if either pingbacks OR trackbacks are disabled
9184 if ( ! empty( $hardening_options['disable_pingbacks'] ) || ! empty( $hardening_options['disable_trackbacks'] ) ) {
9185 update_option( 'default_ping_status', 'closed' );
9186 } else {
9187 // Restore default: pings open
9188 update_option( 'default_ping_status', 'open' );
9189 }
9190
9191 // Comment moderation
9192 if ( ! empty( $hardening_options['require_comment_moderation'] ) ) {
9193 update_option( 'comment_moderation', 1 );
9194 } else {
9195 // Restore default: no moderation required
9196 update_option( 'comment_moderation', 0 );
9197 }
9198 }
9199 }
9200
9201 // Trim activity log entries immediately when limits change
9202 if ( 'activity_log' === $section && $this->activity_log ) {
9203 $this->activity_log->cleanup_old_logs();
9204 }
9205
9206 // Flush rewrite rules if login URL changed
9207 if ( 'login_security' === $section ) {
9208 $login_options = $all_options['login_security'] ?? array();
9209 if ( ! empty( $login_options['custom_login_url'] ) ) {
9210 delete_option( 'vigilante_login_rules_version' );
9211 }
9212 }
9213
9214 // Log the settings change with readable section name
9215 if ( $this->activity_log ) {
9216 $section_names = array(
9217 'firewall' => __( 'Firewall', 'vigilante' ),
9218 'login_security' => __( 'Login Security', 'vigilante' ),
9219 'security_headers' => __( 'Security Headers', 'vigilante' ),
9220 'rest_api_security'=> __( 'REST API Security', 'vigilante' ),
9221 'user_security' => __( 'User Security', 'vigilante' ),
9222 'wp_hardening' => __( 'WP Hardening', 'vigilante' ),
9223 'activity_log' => __( 'Security Audit', 'vigilante' ),
9224 'file_integrity' => __( 'File Integrity', 'vigilante' ),
9225 'email' => __( 'Notification Settings', 'vigilante' ),
9226 'backup' => __( 'Backup', 'vigilante' ),
9227 'advanced' => __( 'Advanced', 'vigilante' ),
9228 'modules' => __( 'Modules', 'vigilante' ),
9229 );
9230 $display_name = isset( $section_names[ $section ] ) ? $section_names[ $section ] : $section;
9231
9232 $this->activity_log->log(
9233 'settings',
9234 'settings_updated',
9235 sprintf(
9236 /* translators: %s: Section name */
9237 __( 'Settings updated: %s', 'vigilante' ),
9238 $display_name
9239 ),
9240 array( 'section' => $section ),
9241 'info'
9242 );
9243 }
9244 }
9245
9246 /**
9247 * Apply all file changes (htaccess, wp-config) based on current options
9248 *
9249 * Used after preset, import, or reset operations
9250 *
9251 * @param array $all_options All plugin options.
9252 */
9253 private function apply_all_file_changes( $all_options ) {
9254 // Refresh settings cache first
9255 $this->settings->clear_cache();
9256
9257 // Create fresh settings instance
9258 $fresh_settings = new Vigilante_Settings();
9259
9260 // Apply firewall htaccess changes
9261 $htaccess = new Vigilante_Htaccess_Protection( $fresh_settings );
9262 $firewall_enabled = ! empty( $all_options['modules']['firewall'] );
9263
9264 if ( $firewall_enabled ) {
9265 $htaccess->apply_rules();
9266 } else {
9267 $htaccess->remove_rules();
9268 }
9269
9270 // Apply security headers htaccess changes
9271 $security_headers = new Vigilante_Security_Headers( $fresh_settings );
9272 $headers_enabled = ! empty( $all_options['modules']['security_headers'] );
9273
9274 if ( $headers_enabled ) {
9275 $security_headers->apply_rules();
9276 } else {
9277 $security_headers->remove_rules();
9278 }
9279
9280 // Apply wp-config changes
9281 $wpconfig = new Vigilante_Wpconfig_Security( $fresh_settings );
9282 $hardening_enabled = ! empty( $all_options['modules']['wp_hardening'] );
9283
9284 if ( $hardening_enabled ) {
9285 $wpconfig->apply_security_constants();
9286 } else {
9287 $wpconfig->remove_constants();
9288 }
9289
9290 // Apply WordPress options for comments/pingbacks
9291 $hardening_options = $all_options['wp_hardening'] ?? array();
9292
9293 if ( $hardening_enabled ) {
9294 // Pingbacks
9295 if ( ! empty( $hardening_options['disable_pingbacks'] ) ) {
9296 update_option( 'default_pingback_flag', 0 );
9297 } else {
9298 // Restore default: pingbacks enabled
9299 update_option( 'default_pingback_flag', 1 );
9300 }
9301
9302 // Trackbacks and ping status
9303 // Only close if either pingbacks OR trackbacks are disabled
9304 if ( ! empty( $hardening_options['disable_pingbacks'] ) || ! empty( $hardening_options['disable_trackbacks'] ) ) {
9305 update_option( 'default_ping_status', 'closed' );
9306 } else {
9307 // Restore default: pings open
9308 update_option( 'default_ping_status', 'open' );
9309 }
9310
9311 // Comment moderation
9312 if ( ! empty( $hardening_options['require_comment_moderation'] ) ) {
9313 update_option( 'comment_moderation', 1 );
9314 } else {
9315 // Restore default: no moderation required
9316 update_option( 'comment_moderation', 0 );
9317 }
9318 }
9319
9320 // Log the change
9321 if ( $this->activity_log ) {
9322 $this->activity_log->log(
9323 'settings',
9324 'bulk_settings_applied',
9325 __( 'Bulk settings applied (preset/import/reset)', 'vigilante' ),
9326 array(),
9327 'info'
9328 );
9329 }
9330 }
9331 }