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

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

9,753 lines 612.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin Class
4 *
5 * Handles admin interface and settings page
6 *
7 * @package Vigilante
8 */
9
10 // Prevent direct access
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 // Load AJAX trait
16 require_once VIGILANTE_ADMIN_DIR . 'class-admin-ajax.php';
17
18 // Load promotional banner class
19 require_once VIGILANTE_INCLUDES_DIR . 'class-ayudawp-promo-banner.php';
20
21 /**
22 * Class Vigilante_Admin
23 *
24 * Manages the admin settings interface
25 */
26 class Vigilante_Admin {
27
28 use Vigilante_Admin_Ajax;
29 use Vigilante_Admin_Analyzer_Ajax;
30 use Vigilante_Admin_Audit_Alerts_Ajax;
31 use Vigilante_Admin_Recovery_Ajax;
32
33 /**
34 * Settings instance
35 *
36 * @var Vigilante_Settings
37 */
38 private $settings;
39
40 /**
41 * Database instance
42 *
43 * @var Vigilante_Database
44 */
45 private $database;
46
47 /**
48 * Activity log instance
49 *
50 * @var Vigilante_Activity_Log
51 */
52 private $activity_log;
53
54 /**
55 * Current tab
56 *
57 * @var string
58 */
59 private $current_tab = 'dashboard';
60
61 /**
62 * Available tabs
63 *
64 * @var array
65 */
66 private $tabs = array();
67
68 /**
69 * Constructor
70 *
71 * @param Vigilante_Settings $settings Settings instance.
72 * @param Vigilante_Database $database Database instance.
73 * @param Vigilante_Activity_Log $activity_log Activity log instance.
74 */
75 public function __construct( $settings, $database, $activity_log ) {
76 $this->settings = $settings;
77 $this->database = $database;
78 $this->activity_log = $activity_log;
79
80 $this->setup_tabs();
81 $this->init_hooks();
82 }
83
84 /**
85 * Setup available tabs
86 */
87 private function setup_tabs() {
88 $this->tabs = array(
89 'dashboard' => __( 'Dashboard', 'vigilante' ),
90 'firewall' => __( 'Firewall', 'vigilante' ),
91 'headers' => __( 'Security Headers', 'vigilante' ),
92 'login' => __( 'Login Security', 'vigilante' ),
93 'rest-api' => __( 'REST API', 'vigilante' ),
94 'users' => __( 'User Security', 'vigilante' ),
95 'wp-hardening' => __( 'WP Hardening', 'vigilante' ),
96 'file-integrity' => __( 'File Integrity', 'vigilante' ),
97 'activity-log' => __( 'Security Audit', 'vigilante' ),
98 'tools' => __( 'Settings & Tools', 'vigilante' ),
99 );
100 }
101
102 /**
103 * Initialize hooks
104 */
105 private function init_hooks() {
106 add_action( 'admin_menu', array( $this, 'add_menu' ) );
107 add_action( 'admin_init', array( $this, 'redirect_submenu_shortcuts' ) );
108 add_action( 'admin_init', array( $this, 'register_settings' ) );
109 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
110 add_action( 'admin_notices', array( $this, 'show_admin_notices' ) );
111 // Self-protection speaks in the network admin too: on a network its
112 // files are shared, and the super administrator is who can repair them.
113 add_action( 'network_admin_notices', array( $this, 'maybe_show_self_protection_notice' ) );
114
115 // Highlight correct submenu based on active tab
116 add_filter( 'submenu_file', array( $this, 'highlight_submenu_tab' ) );
117
118 // Set browser tab title to show plugin name and active tab
119 add_filter( 'admin_title', array( $this, 'set_admin_page_title' ), 10, 2 );
120
121 // AJAX handlers
122 add_action( 'wp_ajax_vigilante_save_settings', array( $this, 'ajax_save_settings' ) );
123 add_action( 'wp_ajax_vigilante_apply_preset', array( $this, 'ajax_apply_preset' ) );
124 add_action( 'wp_ajax_vigilante_reset_section', array( $this, 'ajax_reset_section' ) );
125 add_action( 'wp_ajax_vigilante_clear_lockouts', array( $this, 'ajax_clear_lockouts' ) );
126 add_action( 'wp_ajax_vigilante_clear_logs', array( $this, 'ajax_clear_logs' ) );
127 add_action( 'wp_ajax_vigilante_run_scan', array( $this, 'ajax_run_scan' ) );
128 add_action( 'wp_ajax_vigilante_clear_scan', array( $this, 'ajax_clear_scan' ) );
129 add_action( 'wp_ajax_vigilante_ignore_file', array( $this, 'ajax_ignore_file' ) );
130 add_action( 'wp_ajax_vigilante_unignore_file', array( $this, 'ajax_unignore_file' ) );
131 add_action( 'wp_ajax_vigilante_bulk_ignore_files', array( $this, 'ajax_bulk_ignore_files' ) );
132 add_action( 'wp_ajax_vigilante_bulk_unignore_files', array( $this, 'ajax_bulk_unignore_files' ) );
133 add_action( 'wp_ajax_vigilante_clear_ignored', array( $this, 'ajax_clear_ignored' ) );
134 add_action( 'wp_ajax_vigilante_ignore_closed_plugin', array( $this, 'ajax_ignore_closed_plugin' ) );
135 add_action( 'wp_ajax_vigilante_unignore_closed_plugin', array( $this, 'ajax_unignore_closed_plugin' ) );
136 add_action( 'wp_ajax_vigilante_clear_ignored_closed_plugins', array( $this, 'ajax_clear_ignored_closed_plugins' ) );
137 add_action( 'wp_ajax_vigilante_approve_critical_file', array( $this, 'ajax_approve_critical_file' ) );
138 add_action( 'wp_ajax_vigilante_export_settings', array( $this, 'ajax_export_settings' ) );
139 add_action( 'wp_ajax_vigilante_import_settings', array( $this, 'ajax_import_settings' ) );
140 add_action( 'wp_ajax_vigilante_get_logs', array( $this, 'ajax_get_logs' ) );
141 add_action( 'wp_ajax_vigilante_test_headers', array( $this, 'ajax_test_headers' ) );
142 add_action( 'wp_ajax_vigilante_download_files_backup', array( $this, 'ajax_download_files_backup' ) );
143
144 // 2FA AJAX handlers
145 add_action( 'wp_ajax_vigilante_search_users_2fa', array( $this, 'ajax_search_users_2fa' ) );
146 add_action( 'wp_ajax_vigilante_send_2fa_notification', array( $this, 'ajax_send_2fa_notification' ) );
147 add_action( 'wp_ajax_vigilante_search_totp_users', array( $this, 'ajax_search_totp_users' ) );
148 add_action( 'wp_ajax_vigilante_reset_totp_users', array( $this, 'ajax_reset_totp_users' ) );
149 add_action( 'wp_ajax_vigilante_totp_get_setup', array( $this, 'ajax_totp_get_setup' ) );
150 add_action( 'wp_ajax_vigilante_notify_login_url', array( $this, 'ajax_notify_login_url' ) );
151
152 // Password Reset AJAX handlers
153 add_action( 'wp_ajax_vigilante_search_users_password_reset', array( $this, 'ajax_search_users_password_reset' ) );
154 add_action( 'wp_ajax_vigilante_force_password_reset', array( $this, 'ajax_force_password_reset' ) );
155 add_action( 'wp_ajax_vigilante_force_password_reset_all', array( $this, 'ajax_force_password_reset_all' ) );
156 add_action( 'wp_ajax_vigilante_force_password_reset_by_role', array( $this, 'ajax_force_password_reset_by_role' ) );
157
158 // User approval AJAX handlers
159 add_action( 'wp_ajax_vigilante_approve_user', array( $this, 'ajax_approve_user' ) );
160 add_action( 'wp_ajax_vigilante_reject_user', array( $this, 'ajax_reject_user' ) );
161
162 // Session management AJAX handlers
163 add_action( 'wp_ajax_vigilante_get_user_sessions', array( $this, 'ajax_get_user_sessions' ) );
164 add_action( 'wp_ajax_vigilante_revoke_session', array( $this, 'ajax_revoke_session' ) );
165 add_action( 'wp_ajax_vigilante_revoke_all_sessions', array( $this, 'ajax_revoke_all_sessions' ) );
166
167 // Under Attack mode AJAX handlers
168 add_action( 'wp_ajax_vigilante_activate_under_attack', array( $this, 'ajax_activate_under_attack' ) );
169 add_action( 'wp_ajax_vigilante_deactivate_under_attack', array( $this, 'ajax_deactivate_under_attack' ) );
170 add_action( 'wp_ajax_vigilante_under_attack_status', array( $this, 'ajax_under_attack_status' ) );
171
172 // Database backup AJAX handlers
173 add_action( 'wp_ajax_vigilante_get_db_tables', array( $this, 'ajax_get_db_tables' ) );
174 add_action( 'wp_ajax_vigilante_download_db_backup', array( $this, 'ajax_download_db_backup' ) );
175
176 // Database prefix AJAX handlers
177 add_action( 'wp_ajax_vigilante_generate_prefix', array( $this, 'ajax_generate_prefix' ) );
178 add_action( 'wp_ajax_vigilante_change_prefix', array( $this, 'ajax_change_prefix' ) );
179
180 // Firewall list management from activity log popup
181 add_action( 'wp_ajax_vigilante_add_to_firewall_list', array( $this, 'ajax_add_to_firewall_list' ) );
182 add_action( 'wp_ajax_vigilante_unblock_firewall_ip', array( $this, 'ajax_unblock_firewall_ip' ) );
183
184 // Security Analyzer AJAX handlers (v2.1.0)
185 add_action( 'wp_ajax_vigilante_analyzer_run', array( $this, 'ajax_analyzer_run' ) );
186 add_action( 'wp_ajax_vigilante_analyzer_history', array( $this, 'ajax_analyzer_history' ) );
187 add_action( 'wp_ajax_vigilante_analyzer_dismiss_notice', array( $this, 'ajax_analyzer_dismiss_notice' ) );
188 add_action( 'wp_ajax_vigilante_analyzer_save_settings', array( $this, 'ajax_analyzer_save_settings' ) );
189
190 // Security Headers settings recovery (2.10.0)
191 add_action( 'wp_ajax_vigilante_headers_recovery_restore', array( $this, 'ajax_headers_recovery_restore' ) );
192 add_action( 'wp_ajax_vigilante_headers_recovery_undo', array( $this, 'ajax_headers_recovery_undo' ) );
193 add_action( 'wp_ajax_vigilante_headers_recovery_dismiss', array( $this, 'ajax_headers_recovery_dismiss' ) );
194
195 // Shared "Send test email" handler — Notification settings, File Integrity, Audit Alerts (v2.8.0)
196 add_action( 'wp_ajax_vigilante_send_test_email', array( $this, 'ajax_send_test_email' ) );
197
198 // Run migrations on admin load
199 add_action( 'admin_init', array( $this, 'run_migrations' ) );
200 }
201
202 /**
203 * Run database migrations based on stored version
204 */
205 public function run_migrations() {
206 /*
207 * admin-ajax.php fires admin_init before it decides who is asking
208 * (wp-admin/admin-ajax.php:45), so until 2.11.10 an anonymous POST to
209 * admin-ajax.php with any action ran every pending migration. That is
210 * not a read: the migrations rewrite wp-config.php through
211 * apply_security_constants(), rewrite the root .htaccess, move user meta
212 * of the whole network and can rebuild the file integrity baseline,
213 * taking whatever is on disk as approved. Reproduced on 12 sep 2026 with
214 * curl and no cookies, and found by the file-by-file review of 2.11.10.
215 *
216 * Migrations are maintenance for whoever administers the site, so they
217 * wait for an administrator to load a screen. Nothing is lost by
218 * waiting: every migration is idempotent and version gated.
219 */
220 if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
221 return;
222 }
223
224 $db_version = get_option( 'vigilante_db_version', '0' );
225
226 // 1.2.3: Fix IP lists corrupted by sanitize_text_field stripping newlines
227 if ( version_compare( $db_version, '1.2.3', '<' ) ) {
228 $this->migrate_fix_ip_lists();
229 update_option( 'vigilante_db_version', '1.2.3' );
230 }
231
232 // 1.3.0: Add request_method column to activity log table
233 if ( version_compare( $db_version, '1.3.0', '<' ) ) {
234 $this->database->run_migrations();
235 }
236
237 // 1.9.0: Re-apply wp-config constants (performance constants removed from managed list)
238 if ( version_compare( $db_version, '1.9.0', '<' ) ) {
239 if ( $this->settings->is_module_enabled( 'wp_hardening' ) ) {
240 require_once VIGILANTE_INCLUDES_DIR . 'class-wpconfig-security.php';
241 $wpconfig = new Vigilante_Wpconfig_Security( $this->settings );
242 $wpconfig->apply_security_constants();
243 }
244 update_option( 'vigilante_db_version', '1.9.0' );
245 }
246
247 // 1.10.0: Clean up orphaned email fields (centralized notification recipients)
248 if ( version_compare( $db_version, '1.10.0', '<' ) ) {
249 $this->migrate_cleanup_email_fields();
250 update_option( 'vigilante_db_version', '1.10.0' );
251 }
252
253 // 1.11.0: Remove stale 'enabled' key from activity_log settings
254 // + Convert additional_recipients from string to array
255 if ( version_compare( $db_version, '1.11.0', '<' ) ) {
256 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
257 $changed = false;
258
259 if ( isset( $options['activity_log']['enabled'] ) ) {
260 unset( $options['activity_log']['enabled'] );
261 $changed = true;
262 }
263
264 // Convert corrupted string to array for additional_recipients
265 if ( isset( $options['email']['additional_recipients'] ) && is_string( $options['email']['additional_recipients'] ) ) {
266 $raw = trim( $options['email']['additional_recipients'] );
267 if ( ! empty( $raw ) ) {
268 $emails = array_filter( array_map( 'trim', preg_split( '/[\r\n,; ]+/', $raw ) ) );
269 $options['email']['additional_recipients'] = array_values( array_filter( $emails, 'is_email' ) );
270 } else {
271 $options['email']['additional_recipients'] = array();
272 }
273 $changed = true;
274 }
275
276 if ( $changed ) {
277 update_option( Vigilante_Settings::OPTION_NAME, $options );
278 }
279 update_option( 'vigilante_db_version', '1.11.0' );
280 }
281
282 // 1.12.1: Regenerate htaccess (WooCommerce IPN exclusion in bot blocking rule)
283 if ( version_compare( $db_version, '1.12.1', '<' ) ) {
284 if ( ! empty( $this->settings->get_section( 'firewall' )['block_bad_bots'] ) ) {
285 require_once VIGILANTE_INCLUDES_DIR . 'class-htaccess-protection.php';
286 $htaccess = new Vigilante_Htaccess_Protection( $this->settings );
287 $htaccess->apply_rules();
288 }
289 update_option( 'vigilante_db_version', '1.12.1' );
290 }
291
292 // 1.14.0: Generate critical config files baseline (wp-config.php, .htaccess)
293 if ( version_compare( $db_version, '1.14.0', '<' ) ) {
294 if ( ! class_exists( 'Vigilante_File_Integrity' ) ) {
295 require_once VIGILANTE_INCLUDES_DIR . 'class-file-integrity.php';
296 }
297 $fi = new Vigilante_File_Integrity( $this->settings, $this->database, $this->activity_log );
298
299 /*
300 * Only when there is nothing on record. This migration exists to
301 * create the baseline that did not exist, never to discard the one
302 * the owner approved: rebuilding it from the files takes whatever
303 * is on disk right now as approved, so a wp-config.php modified and
304 * awaiting review would be blessed in silence.
305 *
306 * And this is not theory. vigilante_db_version is written on two
307 * different scales into the same option: this file counts in plugin
308 * versions (2.11.0) and Vigilante_Database counts in schema
309 * versions, currently 1.4.0 (class-database.php:322 and :380). For
310 * version_compare, 1.4.0 is LOWER than 1.14.0, so any site whose
311 * option was last written by the schema runs this migration again.
312 * Measured on the Multisite install on 10 sep 2026: one of the three
313 * sites was sitting on 1.4.0.
314 */
315 if ( ! $fi->get_critical_files_baseline() ) {
316 $fi->regenerate_all_baselines();
317 }
318
319 update_option( 'vigilante_db_version', '1.14.0' );
320 }
321
322 // 2.0.0: Move hide_server_signature and remove_fingerprinting_headers
323 // from firewall section to security_headers section
324 if ( version_compare( $db_version, '2.0.0', '<' ) ) {
325 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
326 $changed = false;
327
328 foreach ( array( 'hide_server_signature', 'remove_fingerprinting_headers' ) as $key ) {
329 if ( isset( $options['firewall'][ $key ] ) ) {
330 if ( ! isset( $options['security_headers'][ $key ] ) ) {
331 $options['security_headers'][ $key ] = $options['firewall'][ $key ];
332 }
333 unset( $options['firewall'][ $key ] );
334 $changed = true;
335 }
336 }
337
338 if ( $changed ) {
339 update_option( Vigilante_Settings::OPTION_NAME, $options );
340 }
341 update_option( 'vigilante_db_version', '2.0.0' );
342 }
343
344 // 2.6.1: Two things happen here.
345 //
346 // 1. Re-apply wp-config constants so the block is rewritten with
347 // "if ( ! defined() )" guards around every define(). Without guards,
348 // non-standard setups that pre-define WordPress constants outside
349 // wp-config.php (custom bootstraps that load constants from .env or
350 // similar) hit a fatal "Constant already defined" when wp-config.php
351 // is parsed and reaches our block.
352 //
353 // 2. Drop the cached Security Check report. The cached "max" per
354 // category was frozen at scan time; with the internal category
355 // bumping from 22 to 28 points (closed_plugins added in 2.6.0),
356 // the cached report would keep displaying 22/22 until the next
357 // full scan. Clearing it forces a fresh scan with the new caps.
358 if ( version_compare( $db_version, '2.6.1', '<' ) ) {
359 if ( $this->settings->is_module_enabled( 'wp_hardening' ) ) {
360 require_once VIGILANTE_INCLUDES_DIR . 'class-wpconfig-security.php';
361 $wpconfig = new Vigilante_Wpconfig_Security( $this->settings );
362 $wpconfig->apply_security_constants();
363 }
364 delete_option( 'vigilante_analyzer_last_scan' );
365
366 // Schedule an immediate background scan so the dashboard widget
367 // doesn't display "Last scan: never" right after the upgrade.
368 // Reuses the same hook the post-Under-Attack flow uses.
369 if ( ! wp_next_scheduled( 'vigilante_under_attack_post_scan' ) ) {
370 wp_schedule_single_event( time() + 5, 'vigilante_under_attack_post_scan' );
371 }
372
373 update_option( 'vigilante_db_version', '2.6.1' );
374 }
375
376 // 2.9.3: Regenerate the .htaccess protection block. The bad-bots
377 // User-Agent list dropped substring-prone tokens that 403'd
378 // legitimate clients (e.g. "rma" matched inside "Performance" and
379 // blocked WP Rocket's page fetch), and the blocking rules now honour
380 // the firewall IP / User-Agent whitelists as negated exceptions.
381 // Existing sites only rewrite the block when Server Protection is
382 // saved, so the upgrade has to refresh it once itself (same pattern
383 // as the 1.12.1 WooCommerce IPN migration).
384 if ( version_compare( $db_version, '2.9.3', '<' ) ) {
385 require_once VIGILANTE_INCLUDES_DIR . 'class-htaccess-protection.php';
386 $htaccess = new Vigilante_Htaccess_Protection( $this->settings );
387
388 if ( $htaccess->are_rules_active() ) {
389 $htaccess->apply_rules();
390 }
391
392 update_option( 'vigilante_db_version', '2.9.3' );
393 }
394
395 /*
396 * 2.9.8: the mixed content handling changes shape. "Upgrade Insecure
397 * Requests" becomes a setting of its own, and Fix Mixed Content ships
398 * off, where before it shipped on and carried the directive with it.
399 * Both have to be written down for sites that are updating, so their
400 * pages keep loading exactly what they loaded yesterday.
401 *
402 * Read the RAW stored options, not get_section(): that one merges the
403 * defaults, so a site that never stored the key would be read with the
404 * new default and silently lose the behaviour it had. Absent means the
405 * site was running on the old default, which was on.
406 */
407 if ( version_compare( $db_version, '2.9.8', '<' ) ) {
408 $raw = get_option( Vigilante_Settings::OPTION_NAME, array() );
409 $stored = ( is_array( $raw ) && isset( $raw['security_headers'] ) && is_array( $raw['security_headers'] ) ) ? $raw['security_headers'] : array();
410 $had_fix = array_key_exists( 'fix_mixed_content', $stored ) ? ! empty( $stored['fix_mixed_content'] ) : true;
411
412 /*
413 * Merge, never replace. update_section() overwrites the whole
414 * section, so passing just these two keys wiped every other header
415 * setting the site had stored (HSTS, CSP, cross-origin policies,
416 * the HTTPS switches, Server Identity) and left the screen showing
417 * factory defaults while the .htaccess kept serving the old values.
418 */
419 $this->settings->update_section(
420 'security_headers',
421 array_merge(
422 $stored,
423 array(
424 'fix_mixed_content' => $had_fix,
425 'upgrade_insecure_requests' => $had_fix,
426 )
427 )
428 );
429
430 update_option( 'vigilante_db_version', '2.9.8' );
431 }
432
433 /*
434 * 2.9.9: drop the settings that no code has read for versions.
435 *
436 * They were carried in the defaults and therefore written into every
437 * saved configuration, they show up in an exported configuration, and
438 * anyone reading them assumes a feature exists behind them. Removing
439 * them from the defaults is not enough: the stored copies survive, so
440 * they are swept here too. Nothing reads them, so nothing changes.
441 */
442 if ( version_compare( $db_version, '2.9.9', '<' ) ) {
443 $raw = get_option( Vigilante_Settings::OPTION_NAME, array() );
444 $dead = array(
445 'firewall' => array( 'country_blocking', 'protected_file_extensions' ),
446 'file_integrity' => array( 'suspicious_patterns' ),
447 'backup' => array( 'auto_backup', 'backup_before_update' ),
448 'advanced' => array( 'block_author_archives', 'disable_embeds', 'uninstall_cleanup', 'debug_mode' ),
449 );
450
451 $changed = false;
452 foreach ( $dead as $section => $keys ) {
453 if ( ! isset( $raw[ $section ] ) || ! is_array( $raw[ $section ] ) ) {
454 continue;
455 }
456 foreach ( $keys as $key ) {
457 if ( array_key_exists( $key, $raw[ $section ] ) ) {
458 unset( $raw[ $section ][ $key ] );
459 $changed = true;
460 }
461 }
462 }
463
464 if ( $changed ) {
465 update_option( Vigilante_Settings::OPTION_NAME, $raw );
466 }
467
468 update_option( 'vigilante_db_version', '2.9.9' );
469 }
470
471 /*
472 * 2.11.0: security release (audit of 28 Aug 2026). Runs here and not
473 * from Vigilante_Database::needs_update(): this option is shared with
474 * that class, and on any updated site it already holds a plugin version
475 * (2.9.9 or later), so a bump of DB_VERSION would never fire.
476 * create_tables() widens the email code column through dbDelta (varchar
477 * 6 to 64, the code is stored hashed since 2.11.0) and purge_for_2_11_0()
478 * does what dbDelta cannot: it empties the trusted devices, which were
479 * identified by User-Agent until now (S1), and the pending email codes,
480 * stored in clear until now (S11). Every remembered device asks for the
481 * second factor once more after this update, and the changelog says so.
482 */
483 if ( version_compare( $db_version, '2.11.0', '<' ) ) {
484 $this->database->create_tables();
485 $this->database->purge_for_2_11_0();
486
487 update_option( 'vigilante_db_version', '2.11.0' );
488 }
489
490 /*
491 * 2.11.9: clear the raw .htaccess copies that older versions left in
492 * options, on the first admin load after the update. Uninstall already
493 * removes them, but that only fires when the plugin is deleted, so a
494 * site that keeps the plugin carried them until now. Three stores, each
495 * a copy of a file that can hold secrets (a SetEnv token, an
496 * Authorization header): the same exposure the wp.org review flagged as
497 * 4.4, on the paths its fix did not reach.
498 *
499 * - vigilante_htaccess_history: up to five raw copies, by design, until
500 * 2.11.8. The writer is gone, nothing reads it, so it is deleted.
501 * - vigilante_htaccess_backup: the single rollback buffer, normally
502 * cleared in the finally of each write; a copy only lingers if a write
503 * crashed mid-operation. Nothing outside one write reads it, so a
504 * leftover is deleted.
505 * - vigilante_htaccess_pre_migration: still read by the header recovery,
506 * but older versions stored the whole file where only our own block is
507 * ever used. Truncated to that block, so the feature keeps working and
508 * nothing outside our markers stays in the option.
509 */
510 if ( version_compare( $db_version, '2.11.9', '<' ) ) {
511 delete_option( 'vigilante_htaccess_history' );
512 delete_option( 'vigilante_htaccess_backup' );
513
514 $snapshot = get_option( 'vigilante_htaccess_pre_migration' );
515 if ( is_array( $snapshot ) && isset( $snapshot['content'] ) && '' !== (string) $snapshot['content'] ) {
516 require_once VIGILANTE_INCLUDES_DIR . 'class-htaccess-recovery.php';
517 $block = Vigilante_Htaccess_Recovery::get_raw_block();
518
519 if ( '' === $block ) {
520 delete_option( 'vigilante_htaccess_pre_migration' );
521 } elseif ( $block !== $snapshot['content'] ) {
522 $snapshot['content'] = $block;
523 update_option( 'vigilante_htaccess_pre_migration', $snapshot, false );
524 }
525 }
526
527 update_option( 'vigilante_db_version', '2.11.9' );
528 }
529
530 /*
531 * 2.11.10: the pending-approval flag becomes one per site on a network.
532 * Until 2.11.9 it was a single global user meta, so the queue was shared
533 * across the whole network. Moving the key is not enough: the accounts
534 * already waiting carry the old key, and reading only the new one would
535 * let them log in. So they are moved here, each to the site it belongs
536 * to, and the old key is removed only once the new one is written.
537 */
538 if ( version_compare( $db_version, '2.11.10', '<' ) ) {
539 $this->migrate_pending_approval_per_site();
540
541 update_option( 'vigilante_db_version', '2.11.10' );
542 }
543
544 /*
545 * 3.0.0: self-protection package. This block must stay the LAST one of
546 * run_migrations(): every block compares against the same $db_version
547 * captured at the top, so the last update_option() that runs is the
548 * one that sticks, and on a jump from any older version it has to be
549 * this one.
550 *
551 * 1. Capture the self-integrity anchor (the manifest fingerprint) and
552 * run an inline self-check. It covers every update the old code never
553 * saw through the upgrader hook: from any 2.x, and manual or FTP
554 * uploads. A plain new is enough, the constructor registers no hooks.
555 * 2. Drop the cached Security Check report: the Internal category grows
556 * from 30 to 33 points (the self_integrity check), and the cached
557 * report would keep the old denominator until the next full scan.
558 * Same reason and same background refresh as the 2.6.1 block above.
559 * 3. Remove Vigilant's own files from the ignore list before that check.
560 * Until 2.11.11 the generic scan listed them like any plugin, and any
561 * administrator could ignore one (after a false alarm while
562 * WordPress.org published new checksums, for example). Kept, those
563 * entries would silence the self-check of those files for good,
564 * PHP included.
565 */
566 if ( version_compare( $db_version, '3.0.0', '<' ) ) {
567 if ( ! class_exists( 'Vigilante_Self_Integrity' ) ) {
568 require_once VIGILANTE_INCLUDES_DIR . 'class-self-integrity.php';
569 }
570 $ignored_files = get_option( 'vigilante_ignored_files', array() );
571 if ( is_array( $ignored_files ) && $ignored_files ) {
572 $kept_files = array_values(
573 array_filter(
574 $ignored_files,
575 function ( $ignored_file ) {
576 return ! Vigilante_Self_Integrity::is_own_file_path( (string) $ignored_file );
577 }
578 )
579 );
580 if ( count( $kept_files ) !== count( $ignored_files ) ) {
581 update_option( 'vigilante_ignored_files', $kept_files );
582 if ( $this->activity_log ) {
583 $this->activity_log->log(
584 'system',
585 'self_ignored_files_removed',
586 __( 'Vigilant files were removed from the File Integrity ignore list: self-protection checks them now.', 'vigilante' ),
587 array( 'removed' => count( $ignored_files ) - count( $kept_files ) ),
588 'info'
589 );
590 }
591 }
592 }
593 $self_integrity = new Vigilante_Self_Integrity( $this->settings, $this->activity_log );
594 $self_integrity->run_check( 'migration' );
595
596 delete_option( 'vigilante_analyzer_last_scan' );
597 if ( ! wp_next_scheduled( 'vigilante_under_attack_post_scan' ) ) {
598 wp_schedule_single_event( time() + 5, 'vigilante_under_attack_post_scan' );
599 }
600
601 update_option( 'vigilante_db_version', '3.0.0' );
602 }
603 }
604
605 /**
606 * Move the pending-approval flag of a network to a key per site
607 *
608 * Runs once for the whole network, not once per site: the data it moves is
609 * global, so the guard is a network option and any site may be the one that
610 * does it. On a single site the key does not change and there is nothing to
611 * do.
612 *
613 * Each waiting account goes to its primary site, or to the only site it
614 * belongs to; one that belongs to none goes to the main site rather than
615 * nowhere, because losing the flag would silently approve it.
616 *
617 * @since 2.11.10
618 */
619 private function migrate_pending_approval_per_site() {
620 global $wpdb;
621
622 if ( ! is_multisite() ) {
623 return;
624 }
625
626 if ( get_site_option( 'vigilante_pending_per_site_done' ) ) {
627 return;
628 }
629
630 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- One-off migration of the plugin's own user meta; the meta API has no "list every user with this key".
631 $user_ids = $wpdb->get_col(
632 $wpdb->prepare( "SELECT DISTINCT user_id FROM {$wpdb->usermeta} WHERE meta_key = %s", 'vigilante_pending_approval' )
633 );
634
635 foreach ( (array) $user_ids as $user_id ) {
636 $user_id = (int) $user_id;
637 if ( ! $user_id ) {
638 continue;
639 }
640
641 $pending = get_user_meta( $user_id, 'vigilante_pending_approval', true );
642 $since = get_user_meta( $user_id, 'vigilante_pending_since', true );
643
644 /*
645 * Every site the account belongs to, not its primary one. The global
646 * flag does not say where the registration happened, and the first
647 * version of this guessed the primary blog: an account that
648 * registered on B while its primary was A came out pending on A and
649 * free to log in on B, which is the very site it had never been
650 * approved on. Found by the cross review of 2.11.10.
651 *
652 * Marking every site it belongs to fails closed instead: the account
653 * stays blocked wherever it can log in, and shows up in the queue of
654 * each of those sites so somebody can actually act on it. An account
655 * that belongs to no site goes to the main one rather than nowhere,
656 * because losing the flag would silently approve it.
657 */
658 /*
659 * With $all true, because the default leaves out archived, spam and
660 * deleted sites (wp-includes/user.php:1113-1117): a site archived on
661 * the day this runs would lose the flag, and the account would walk
662 * in unapproved the moment it was brought back. Found by the second
663 * cross review of 2.11.10.
664 */
665 $blog_ids = array();
666
667 foreach ( get_blogs_of_user( $user_id, true ) as $blog ) {
668 if ( ! empty( $blog->userblog_id ) ) {
669 $blog_ids[] = (int) $blog->userblog_id;
670 }
671 }
672
673 if ( empty( $blog_ids ) ) {
674 $blog_ids[] = (int) get_main_site_id();
675 }
676
677 foreach ( array_unique( $blog_ids ) as $blog_id ) {
678 $prefix = $wpdb->get_blog_prefix( $blog_id );
679
680 update_user_meta( $user_id, $prefix . 'vigilante_pending_approval', $pending );
681 if ( '' !== $since && false !== $since ) {
682 update_user_meta( $user_id, $prefix . 'vigilante_pending_since', $since );
683 }
684 }
685
686 delete_user_meta( $user_id, 'vigilante_pending_approval' );
687 delete_user_meta( $user_id, 'vigilante_pending_since' );
688 }
689
690 update_site_option( 'vigilante_pending_per_site_done', 1 );
691 }
692
693 /**
694 * Migration: Remove orphaned email fields from saved options
695 *
696 * v1.10.0 centralized notification recipients into email section.
697 * Old per-module notify_email fields and dead email section fields
698 * are removed to avoid confusion.
699 */
700 private function migrate_cleanup_email_fields() {
701 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
702 $modified = false;
703
704 // Remove orphaned fields from email section
705 $dead_email_keys = array( 'enabled', 'from_name', 'from_email', 'admin_email', 'send_activation_email', 'custom_email' );
706 if ( isset( $options['email'] ) && is_array( $options['email'] ) ) {
707 foreach ( $dead_email_keys as $key ) {
708 if ( array_key_exists( $key, $options['email'] ) ) {
709 unset( $options['email'][ $key ] );
710 $modified = true;
711 }
712 }
713 // Ensure new fields exist with defaults
714 if ( ! array_key_exists( 'send_to_admin_email', $options['email'] ) ) {
715 $options['email']['send_to_admin_email'] = true;
716 $modified = true;
717 }
718 if ( ! array_key_exists( 'additional_recipients', $options['email'] ) ) {
719 $options['email']['additional_recipients'] = '';
720 $modified = true;
721 }
722 }
723
724 // Remove notify_email from login_security
725 if ( isset( $options['login_security']['notify_email'] ) ) {
726 unset( $options['login_security']['notify_email'] );
727 $modified = true;
728 }
729
730 // Remove notify_email from file_integrity
731 if ( isset( $options['file_integrity']['notify_email'] ) ) {
732 unset( $options['file_integrity']['notify_email'] );
733 $modified = true;
734 }
735
736 if ( $modified ) {
737 update_option( Vigilante_Settings::OPTION_NAME, $options );
738 // Clear settings cache so the plugin uses clean data immediately
739 $this->settings->clear_cache();
740 }
741 }
742
743 /**
744 * Migration: Fix IP whitelist/blacklist entries merged into single line
745 *
746 * Prior to 1.2.3, sanitize_text_field() stripped newlines from textarea data,
747 * causing multiple IPs to be stored as a single space-separated string.
748 */
749 private function migrate_fix_ip_lists() {
750 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
751 $fixed = false;
752
753 foreach ( array( 'ip_whitelist', 'ip_blacklist' ) as $key ) {
754 if ( ! empty( $options['firewall'][ $key ] ) && is_array( $options['firewall'][ $key ] ) ) {
755 $new_list = array();
756 foreach ( $options['firewall'][ $key ] as $entry ) {
757 // Split entries that were joined by spaces
758 $parts = preg_split( '/\s+/', trim( $entry ) );
759 foreach ( $parts as $part ) {
760 $part = trim( $part );
761 if ( '' !== $part ) {
762 $new_list[] = $part;
763 }
764 }
765 }
766 if ( count( $new_list ) !== count( $options['firewall'][ $key ] ) ) {
767 $options['firewall'][ $key ] = array_unique( $new_list );
768 $fixed = true;
769 }
770 }
771 }
772
773 if ( $fixed ) {
774 update_option( Vigilante_Settings::OPTION_NAME, $options );
775 // Clear settings cache so changes take effect immediately
776 $this->settings->clear_cache();
777 }
778 }
779
780 /**
781 * Add admin menu page in last position
782 */
783 public function add_menu() {
784 $menu_title = __( 'Vigilant', 'vigilante' );
785
786 // Count pending approvals (separate concern, always red if present)
787 $pending_count = $this->get_pending_approvals_count();
788
789 // Get security issues with severity
790 $security_status = $this->get_security_status_for_badge();
791
792 /*
793 * Self-protection: a change to Vigilant own files is the one finding
794 * that has to be visible from any screen of WordPress, so it adds to
795 * the counter and paints it red. A verified state, a state with fewer
796 * references than usual and the check turned off add nothing: a counter
797 * that is always on is a counter nobody reads.
798 */
799 $self_tone = Vigilante_Self_Integrity::tone(
800 Vigilante_Self_Integrity::display_state(),
801 Vigilante_Self_Integrity::is_on()
802 );
803 $self_badge = in_array( $self_tone, array( 'critical', 'off', 'warning' ), true ) ? 1 : 0;
804
805 // Total count for badge
806 $total_badge = $pending_count + $security_status['count'] + $self_badge;
807
808 if ( $total_badge > 0 ) {
809 // Determine badge color:
810 // - Red (awaiting-mod): pending approvals OR critical modules disabled
811 // - Orange (update-plugins): only non-critical modules disabled
812 if ( $pending_count > 0 || $security_status['has_critical'] || in_array( $self_tone, array( 'critical', 'off' ), true ) ) {
813 $badge_class = 'awaiting-mod';
814 } else {
815 $badge_class = 'update-plugins vigilante-badge-warning';
816 }
817
818 $menu_title .= sprintf(
819 ' <span class="%s count-%d"><span class="pending-count">%d</span></span>',
820 esc_attr( $badge_class ),
821 $total_badge,
822 $total_badge
823 );
824 }
825
826 add_menu_page(
827 __( 'Vigilant', 'vigilante' ),
828 $menu_title,
829 'manage_options',
830 'vigilante',
831 array( $this, 'render_settings_page' ),
832 'dashicons-shield',
833 999
834 );
835
836 // Rename auto-generated first submenu to "Dashboard"
837 add_submenu_page(
838 'vigilante',
839 __( 'Dashboard', 'vigilante' ),
840 __( 'Dashboard', 'vigilante' ),
841 'manage_options',
842 'vigilante',
843 array( $this, 'render_settings_page' )
844 );
845
846 // Security Audit shortcut
847 add_submenu_page(
848 'vigilante',
849 __( 'Security Audit', 'vigilante' ),
850 __( 'Security Audit', 'vigilante' ),
851 'manage_options',
852 'vigilante-activity-log',
853 array( $this, 'redirect_to_tab' )
854 );
855
856 // File Integrity shortcut, with its own counter when the self-check has
857 // something to say: that is the screen that explains it.
858 $fi_menu_title = __( 'File Integrity', 'vigilante' );
859 if ( $self_badge > 0 ) {
860 $fi_menu_title .= sprintf(
861 ' <span class="%s count-1"><span class="pending-count">1</span></span>',
862 in_array( $self_tone, array( 'critical', 'off' ), true ) ? 'awaiting-mod' : 'update-plugins vigilante-badge-warning'
863 );
864 }
865 add_submenu_page(
866 'vigilante',
867 __( 'File Integrity', 'vigilante' ),
868 $fi_menu_title,
869 'manage_options',
870 'vigilante-file-integrity',
871 array( $this, 'redirect_to_tab' )
872 );
873 }
874
875 /**
876 * Redirect submenu shortcuts early, before headers are sent
877 */
878 public function redirect_submenu_shortcuts() {
879 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Just reading page slug for redirect
880 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
881
882 $tab_map = array(
883 'vigilante-activity-log' => 'activity-log',
884 'vigilante-file-integrity' => 'file-integrity',
885 );
886
887 if ( isset( $tab_map[ $page ] ) ) {
888 wp_safe_redirect( admin_url( 'admin.php?page=vigilante&tab=' . $tab_map[ $page ] ) );
889 exit;
890 }
891 }
892
893 /**
894 * Fallback redirect for submenu shortcuts (JS-based)
895 */
896 public function redirect_to_tab() {
897 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Just reading page slug for redirect
898 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
899
900 $tab_map = array(
901 'vigilante-activity-log' => 'activity-log',
902 'vigilante-file-integrity' => 'file-integrity',
903 );
904
905 if ( isset( $tab_map[ $page ] ) ) {
906 $url = admin_url( 'admin.php?page=vigilante&tab=' . $tab_map[ $page ] );
907 echo '<script>window.location.replace(' . wp_json_encode( esc_url( $url ) ) . ');</script>';
908 }
909 }
910
911 /**
912 * Highlight the correct submenu item based on active tab
913 *
914 * @param string $submenu_file Current submenu file.
915 * @return string
916 */
917 public function highlight_submenu_tab( $submenu_file ) {
918 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading tab for menu highlight only
919 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
920 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
921 $tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : '';
922
923 if ( 'vigilante' !== $page || empty( $tab ) ) {
924 return $submenu_file;
925 }
926
927 $tab_to_submenu = array(
928 'activity-log' => 'vigilante-activity-log',
929 'file-integrity' => 'vigilante-file-integrity',
930 );
931
932 if ( isset( $tab_to_submenu[ $tab ] ) ) {
933 return $tab_to_submenu[ $tab ];
934 }
935
936 return $submenu_file;
937 }
938
939 /**
940 * Set browser tab title to show plugin name and active tab
941 *
942 * Changes "Dashboard ‹ Site Name — WordPress" to
943 * "Vigilant > Dashboard ‹ Site Name — WordPress"
944 *
945 * @param string $admin_title Full admin title.
946 * @param string $title Page title from add_menu_page/add_submenu_page.
947 * @return string Modified title.
948 */
949 public function set_admin_page_title( $admin_title, $title ) {
950 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading page slug for title only
951 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
952
953 // Only modify on Vigilante pages
954 if ( 0 !== strpos( $page, 'vigilante' ) ) {
955 return $admin_title;
956 }
957
958 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
959 $tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'dashboard';
960
961 if ( isset( $this->tabs[ $tab ] ) ) {
962 $tab_label = $this->tabs[ $tab ];
963 } else {
964 $tab_label = __( 'Dashboard', 'vigilante' );
965 }
966
967 $plugin_title = __( 'Vigilant', 'vigilante' ) . ' &rsaquo; ' . $tab_label;
968
969 // Replace the original page title portion
970 return str_replace( $title, $plugin_title, $admin_title );
971 }
972
973 /**
974 * Get count of users pending approval
975 *
976 * @return int Count of pending users.
977 */
978 private function get_pending_approvals_count() {
979 // Prevent early execution before WordPress is ready
980 if ( ! did_action( 'plugins_loaded' ) ) {
981 return 0;
982 }
983
984 /*
985 * Counted whether the feature is on or off. An account already waiting
986 * stays blocked when it is switched off (see init_enforcement_hooks()),
987 * so reporting zero there hid people who cannot log in and whom nobody
988 * could see to approve. Found by the cross review of 2.11.10.
989 */
990
991 // phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_key, WordPress.DB.SlowDBQuery.slow_db_query_meta_value -- Limited results in admin context.
992 $args = array(
993 'meta_key' => Vigilante_User_Security::site_user_meta_key( 'vigilante_pending_approval' ),
994 'meta_value' => '1',
995 'fields' => 'ID',
996 );
997 // phpcs:enable WordPress.DB.SlowDBQuery.slow_db_query_meta_key, WordPress.DB.SlowDBQuery.slow_db_query_meta_value
998
999 // Same query as Vigilante_User_Security::get_pending_users(), and for the
1000 // same reason: the meta key already scopes this to the site, and adding
1001 // core's membership filter on top hid the accounts that have no role yet.
1002 if ( is_multisite() ) {
1003 $args['blog_id'] = 0;
1004 }
1005
1006 $pending_users = get_users( $args );
1007
1008 return count( $pending_users );
1009 }
1010
1011 /**
1012 * Whether XML-RPC is blocked, whole or its pingback methods
1013 *
1014 * Both levels have to say so: the three-way setting under WP Hardening, read
1015 * through the module's own resolver, and the WP Hardening module that
1016 * enforces it. Until 3.0.2 the Dashboard read login_security[disable_xmlrpc],
1017 * the checkbox that moved to WP Hardening in 2.9.7 and is never written any
1018 * more, so the score never granted its three points and the recommendation
1019 * to disable XML-RPC stayed on for good.
1020 *
1021 * @since 3.0.2
1022 *
1023 * @param array $options Plugin options.
1024 * @return bool
1025 */
1026 private function is_xmlrpc_protected( $options ) {
1027 return ! empty( $options['modules']['wp_hardening'] )
1028 && 'none' !== Vigilante_Comment_Security::resolve_xmlrpc_mode( $this->settings );
1029 }
1030
1031 /**
1032 * Calculate comprehensive security score (0-100)
1033 *
1034 * @param array $options Plugin options.
1035 * @return int Security score.
1036 */
1037 private function calculate_security_score( $options ) {
1038 $score = 0;
1039 $max_score = 0;
1040
1041 // Module scores (60 points total)
1042 $module_weights = array(
1043 'firewall' => 10,
1044 'security_headers' => 8,
1045 'login_security' => 10,
1046 'rest_api_security' => 6,
1047 'user_security' => 8,
1048 'wp_hardening' => 8,
1049 'file_integrity' => 5,
1050 'activity_log' => 5,
1051 );
1052
1053 foreach ( $module_weights as $module => $weight ) {
1054 $max_score += $weight;
1055 if ( ! empty( $options['modules'][ $module ] ) ) {
1056 $score += $weight;
1057 }
1058 }
1059
1060 // Firewall details (10 points)
1061 if ( ! empty( $options['modules']['firewall'] ) ) {
1062 $firewall = $options['firewall'] ?? array();
1063 $max_score += 10;
1064
1065 $firewall_checks = array(
1066 'block_sql_injection',
1067 'block_xss_attacks',
1068 'block_bad_query_strings',
1069 'block_file_inclusion',
1070 'block_directory_traversal',
1071 );
1072
1073 $firewall_enabled = 0;
1074 foreach ( $firewall_checks as $check ) {
1075 if ( ! empty( $firewall[ $check ] ) ) {
1076 $firewall_enabled++;
1077 }
1078 }
1079 $score += min( 10, $firewall_enabled * 2 );
1080 }
1081
1082 // Login security details (10 points)
1083 if ( ! empty( $options['modules']['login_security'] ) ) {
1084 $login = $options['login_security'] ?? array();
1085 $max_score += 10;
1086
1087 // Max attempts configured
1088 if ( isset( $login['max_attempts'] ) && $login['max_attempts'] <= 5 ) {
1089 $score += 3;
1090 }
1091 // XML-RPC blocked, whole or its pingback methods
1092 if ( $this->is_xmlrpc_protected( $options ) ) {
1093 $score += 3;
1094 }
1095 // 2FA enabled
1096 if ( ! empty( $login['two_factor']['enabled'] ) ) {
1097 $score += 4;
1098 }
1099 }
1100
1101 // Security headers details (10 points)
1102 if ( ! empty( $options['modules']['security_headers'] ) ) {
1103 $headers = $options['security_headers'] ?? array();
1104 $max_score += 10;
1105
1106 if ( ! empty( $headers['x_frame_options'] ) ) {
1107 $score += 2;
1108 }
1109 if ( ! empty( $headers['x_content_type_options'] ) ) {
1110 $score += 2;
1111 }
1112 if ( ! empty( $headers['hsts']['enabled'] ) ) {
1113 $score += 3;
1114 }
1115 if ( ! empty( $headers['csp']['enabled'] ) ) {
1116 $score += 3;
1117 }
1118 }
1119
1120 // User security details (10 points)
1121 if ( ! empty( $options['modules']['user_security'] ) ) {
1122 $user = $options['user_security'] ?? array();
1123 $max_score += 10;
1124
1125 if ( ! empty( $user['block_insecure_usernames'] ) ) {
1126 $score += 3;
1127 }
1128 if ( ! empty( $user['force_strong_passwords'] ) ) {
1129 $score += 3;
1130 }
1131 if ( ! empty( $user['password_expiration']['enabled'] ) ) {
1132 $score += 2;
1133 }
1134 if ( ! empty( $user['email_verification']['enabled'] ) ) {
1135 $score += 2;
1136 }
1137 }
1138
1139 // Audit alerts details (6 points) - only when Security Audit is on,
1140 // because the alerting layer rides on top of the activity log. Leaving
1141 // both alert legs off keeps these points unearned.
1142 if ( ! empty( $options['modules']['activity_log'] ) ) {
1143 $alerts = isset( $options['audit_alerts'] ) ? (array) $options['audit_alerts'] : array();
1144 $max_score += 6;
1145 if ( Vigilante_Audit_Alerts::immediate_is_active( $alerts ) ) {
1146 $score += 3;
1147 }
1148 if ( Vigilante_Audit_Alerts::threshold_is_active( $alerts ) ) {
1149 $score += 3;
1150 }
1151 }
1152
1153 /*
1154 * Self-protection (15 points). Having it on is configuration, which is
1155 * what this card measures; the state of the last check caps the card,
1156 * because a plugin whose own files were changed is not well configured
1157 * in any useful sense, whatever the rest of the settings say. The
1158 * environment block below already mixes measured state into this score
1159 * (WP_DEBUG, insecure usernames), so the card keeps its meaning.
1160 */
1161 $max_score += 15;
1162 $self_enabled = Vigilante_Self_Integrity::is_on();
1163 $self_tone = Vigilante_Self_Integrity::tone( Vigilante_Self_Integrity::display_state(), $self_enabled );
1164 if ( $self_enabled ) {
1165 $score += 10;
1166 // The five points are for a check that ran and came out clean: a
1167 // site that has never checked itself has not earned them.
1168 if ( in_array( $self_tone, array( 'ok', 'info' ), true ) ) {
1169 $score += 5;
1170 }
1171 }
1172
1173 // Environment checks (8 points) - penalize insecure server configuration
1174 $max_score += 8;
1175 $env_score = 8;
1176
1177 // WP_DEBUG active in production is a security risk (exposes paths, errors)
1178 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
1179 $env_score -= 5;
1180 }
1181
1182 // Accounts with insecure usernames (targeted by brute force attacks)
1183 $insecure_admins = $this->get_insecure_admin_usernames();
1184 if ( ! empty( $insecure_admins ) ) {
1185 $env_score -= 3;
1186 }
1187
1188 $score += max( 0, $env_score );
1189
1190 $percent = $max_score > 0 ? (int) round( ( $score / $max_score ) * 100 ) : 0;
1191 if ( in_array( $self_tone, array( 'critical', 'off' ), true ) ) {
1192 // Same cap and same reason as the Security Check score.
1193 $percent = min( $percent, Vigilante_Security_Analyzer::SCORE_CAP_ON_TAMPER );
1194 }
1195 return $percent;
1196 }
1197
1198 /**
1199 * Get security recommendations based on current settings
1200 *
1201 * @param array $options Plugin options.
1202 * @return array Array of recommendations.
1203 */
1204 private function get_security_recommendations( $options ) {
1205 $recommendations = array();
1206
1207 // Self-protection first: if Vigilant itself cannot be trusted, nothing
1208 // else on this card means much.
1209 $vg_self_enabled = Vigilante_Self_Integrity::is_on();
1210 $vg_self_tone = Vigilante_Self_Integrity::tone( Vigilante_Self_Integrity::display_state(), $vg_self_enabled );
1211 if ( ! $vg_self_enabled ) {
1212 $recommendations[] = array(
1213 'icon' => 'shield',
1214 'priority' => 'high',
1215 'tab' => 'file-integrity',
1216 'message' => __( 'Turn Vigilant self-protection on, so a change to Vigilant own files does not go unnoticed.', 'vigilante' ),
1217 );
1218 } elseif ( 'off' === $vg_self_tone ) {
1219 $recommendations[] = array(
1220 'icon' => 'warning',
1221 'priority' => 'critical',
1222 'tab' => 'file-integrity',
1223 'message' => __( 'Something on this site switched Vigilant self-protection off: File Integrity says which file does it.', 'vigilante' ),
1224 );
1225 } elseif ( 'critical' === $vg_self_tone ) {
1226 $recommendations[] = array(
1227 'icon' => 'warning',
1228 'priority' => 'critical',
1229 'tab' => 'file-integrity',
1230 'message' => __( 'Vigilant own files have been changed: repair Vigilant from File Integrity before anything else.', 'vigilante' ),
1231 );
1232 } elseif ( 'warning' === $vg_self_tone ) {
1233 $recommendations[] = array(
1234 'icon' => 'shield',
1235 'priority' => 'high',
1236 'tab' => 'file-integrity',
1237 'message' => __( 'Vigilant self-protection needs your attention: File Integrity says what it found and what to do.', 'vigilante' ),
1238 );
1239 } elseif ( 'none' === $vg_self_tone ) {
1240 // The score holds back the points of a check that has not run yet,
1241 // so the card has to say why instead of just showing a lower number.
1242 $recommendations[] = array(
1243 'icon' => 'shield',
1244 'priority' => 'high',
1245 'tab' => 'file-integrity',
1246 'message' => __( 'Vigilant has not checked its own files yet: run a scan from File Integrity.', 'vigilante' ),
1247 );
1248 }
1249
1250 // Critical: Firewall disabled
1251 if ( empty( $options['modules']['firewall'] ) ) {
1252 $recommendations[] = array(
1253 'icon' => 'warning',
1254 'priority' => 'critical',
1255 'message' => __( 'Enable Firewall to protect against common attacks.', 'vigilante' ),
1256 );
1257 }
1258
1259 // Critical: Login security disabled
1260 if ( empty( $options['modules']['login_security'] ) ) {
1261 $recommendations[] = array(
1262 'icon' => 'warning',
1263 'priority' => 'critical',
1264 'message' => __( 'Enable Login Security to prevent brute force attacks.', 'vigilante' ),
1265 );
1266 }
1267
1268 // High: Security headers disabled
1269 if ( empty( $options['modules']['security_headers'] ) ) {
1270 $recommendations[] = array(
1271 'icon' => 'admin-generic',
1272 'priority' => 'high',
1273 'message' => __( 'Enable Security Headers to protect against clickjacking and XSS.', 'vigilante' ),
1274 );
1275 }
1276
1277 // High: User security disabled
1278 if ( empty( $options['modules']['user_security'] ) ) {
1279 $recommendations[] = array(
1280 'icon' => 'admin-users',
1281 'priority' => 'high',
1282 'message' => __( 'Enable User Security to enforce password policies and username protection.', 'vigilante' ),
1283 );
1284 }
1285
1286 // High: 2FA not enabled (only if login security is active)
1287 $login = $options['login_security'] ?? array();
1288 if ( ! empty( $options['modules']['login_security'] ) && empty( $login['two_factor']['enabled'] ) ) {
1289 $recommendations[] = array(
1290 'icon' => 'shield',
1291 'priority' => 'high',
1292 'message' => __( 'Enable Two-Factor Authentication for enhanced login security.', 'vigilante' ),
1293 'tab' => 'login',
1294 );
1295 }
1296
1297 // Medium: REST API security disabled
1298 if ( empty( $options['modules']['rest_api_security'] ) ) {
1299 $recommendations[] = array(
1300 'icon' => 'rest-api',
1301 'priority' => 'medium',
1302 'message' => __( 'Enable REST API Security to control API access and prevent enumeration.', 'vigilante' ),
1303 );
1304 }
1305
1306 // Medium: WP Hardening disabled
1307 if ( empty( $options['modules']['wp_hardening'] ) ) {
1308 $recommendations[] = array(
1309 'icon' => 'lock',
1310 'priority' => 'medium',
1311 'message' => __( 'Enable WP Hardening to remove version info and protect core files.', 'vigilante' ),
1312 );
1313 }
1314
1315 // Medium: File integrity disabled
1316 if ( empty( $options['modules']['file_integrity'] ) ) {
1317 $recommendations[] = array(
1318 'icon' => 'media-text',
1319 'priority' => 'medium',
1320 'message' => __( 'Enable File Integrity to detect unauthorized file changes.', 'vigilante' ),
1321 );
1322 }
1323
1324 // Medium: Security Audit disabled
1325 if ( empty( $options['modules']['activity_log'] ) ) {
1326 $recommendations[] = array(
1327 'icon' => 'list-view',
1328 'priority' => 'medium',
1329 'message' => __( 'Enable Security Audit to track security events.', 'vigilante' ),
1330 );
1331 }
1332
1333 // Low: XML-RPC enabled (only if login security is active)
1334 if ( ! empty( $options['modules']['login_security'] ) && ! $this->is_xmlrpc_protected( $options ) ) {
1335 $recommendations[] = array(
1336 'icon' => 'info',
1337 'priority' => 'low',
1338 'message' => __( 'Disable XML-RPC if not needed (reduces attack surface).', 'vigilante' ),
1339 'tab' => 'wp-hardening',
1340 );
1341 }
1342
1343 // Low: Strong passwords not enforced (only if user security is active)
1344 $user = $options['user_security'] ?? array();
1345 if ( ! empty( $options['modules']['user_security'] ) && empty( $user['force_strong_passwords'] ) ) {
1346 $recommendations[] = array(
1347 'icon' => 'admin-users',
1348 'priority' => 'low',
1349 'message' => __( 'Enforce strong passwords for all users.', 'vigilante' ),
1350 'tab' => 'users',
1351 );
1352 }
1353
1354 // High: WP_DEBUG active in production (regardless of Vigilante settings)
1355 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
1356 $recommendations[] = array(
1357 'icon' => 'warning',
1358 'priority' => 'high',
1359 'message' => __( 'WP_DEBUG is active. Debug mode exposes sensitive information and should be disabled in production.', 'vigilante' ),
1360 'tab' => 'wp-hardening',
1361 );
1362 }
1363
1364 // Low: Users with display name matching login username (only if user security active)
1365 if ( ! empty( $options['modules']['user_security'] ) ) {
1366 $exposed_users = $this->get_users_with_exposed_login();
1367 if ( ! empty( $exposed_users ) ) {
1368 $recommendations[] = array(
1369 'icon' => 'admin-users',
1370 'priority' => 'low',
1371 'message' => sprintf(
1372 /* translators: %s: Comma-separated list of usernames */
1373 __( 'These users have their login username as display name (publicly visible): %s', 'vigilante' ),
1374 implode( ', ', $exposed_users )
1375 ),
1376 'tab' => 'users',
1377 );
1378 }
1379 }
1380
1381 // High: Accounts with insecure usernames (regardless of module status)
1382 $insecure_admins = $this->get_insecure_admin_usernames();
1383 if ( ! empty( $insecure_admins ) ) {
1384 $recommendations[] = array(
1385 'icon' => 'warning',
1386 'priority' => 'high',
1387 'message' => sprintf(
1388 /* translators: %s: Comma-separated list of usernames */
1389 __( 'Insecure usernames detected: %s. These are commonly targeted in brute force attacks. Create new accounts with unique usernames and remove these.', 'vigilante' ),
1390 implode( ', ', $insecure_admins )
1391 ),
1392 );
1393 }
1394
1395 // Critical: Closed or removed plugins detected by the daily check.
1396 // Reads from the cached state map populated by Vigilante_Plugin_Status, so
1397 // there is no extra HTTP call here. Ignored slugs are filtered out so the
1398 // recommendation respects the user's per-slug Ignore decisions.
1399 if ( ! empty( $options['modules']['file_integrity'] ) && ! empty( $options['file_integrity']['check_closed_plugins'] ) ) {
1400 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
1401 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
1402 }
1403 $closed_checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
1404 $closed_active = $closed_checker->get_closed_plugins();
1405 if ( ! empty( $closed_active ) ) {
1406 $names = array();
1407 foreach ( $closed_active as $slug => $entry ) {
1408 $names[] = isset( $entry['name'] ) ? $entry['name'] : $slug;
1409 }
1410 $recommendations[] = array(
1411 'icon' => 'warning',
1412 'priority' => 'critical',
1413 'message' => sprintf(
1414 /* translators: 1: count, 2: comma-separated plugin names */
1415 _n(
1416 '%1$d closed plugin detected on this site: %2$s. Closures in WordPress.org usually indicate malware, security issues or supply chain compromises. Uninstall and replace as soon as possible.',
1417 '%1$d closed plugins detected on this site: %2$s. Closures in WordPress.org usually indicate malware, security issues or supply chain compromises. Uninstall and replace as soon as possible.',
1418 count( $closed_active ),
1419 'vigilante'
1420 ),
1421 count( $closed_active ),
1422 implode( ', ', $names )
1423 ),
1424 'tab' => 'file-integrity',
1425 );
1426 }
1427 }
1428
1429 // Medium: Security Audit is on but no audit alert is configured. The
1430 // alerting layer only makes sense while the activity log is running.
1431 if ( ! empty( $options['modules']['activity_log'] ) ) {
1432 $alerts = isset( $options['audit_alerts'] ) ? (array) $options['audit_alerts'] : array();
1433 if ( ! Vigilante_Audit_Alerts::has_active_alerts( $alerts ) ) {
1434 $recommendations[] = array(
1435 'icon' => 'email-alt',
1436 'priority' => 'medium',
1437 'message' => __( 'Set up Audit Alerts to get an email when something important happens (a new admin, a closed plugin, or an attack in progress).', 'vigilante' ),
1438 'tab' => 'activity-log',
1439 );
1440 }
1441 }
1442
1443 // Sort by priority
1444 $priority_order = array( 'critical' => 0, 'high' => 1, 'medium' => 2, 'low' => 3 );
1445 usort( $recommendations, function( $a, $b ) use ( $priority_order ) {
1446 return ( $priority_order[ $a['priority'] ] ?? 99 ) - ( $priority_order[ $b['priority'] ] ?? 99 );
1447 } );
1448
1449 return $recommendations;
1450 }
1451
1452 /**
1453 * Get users whose display name matches their login username
1454 *
1455 * Limited to administrators and editors for performance and relevance.
1456 * Cached with transient to avoid repeated queries on every dashboard load.
1457 *
1458 * @return array Array of usernames with exposed login.
1459 */
1460 private function get_users_with_exposed_login() {
1461 $cache_key = 'vigilante_exposed_display_names';
1462 $cached = get_transient( $cache_key );
1463
1464 if ( false !== $cached ) {
1465 return $cached;
1466 }
1467
1468 $exposed = array();
1469 $users = get_users( array(
1470 'role__in' => array( 'administrator', 'editor' ),
1471 'fields' => array( 'ID', 'user_login', 'display_name' ),
1472 ) );
1473
1474 foreach ( $users as $user ) {
1475 if ( strcasecmp( $user->display_name, $user->user_login ) === 0 ) {
1476 $exposed[] = $user->user_login;
1477 }
1478 }
1479
1480 // Cache for 12 hours
1481 set_transient( $cache_key, $exposed, 12 * HOUR_IN_SECONDS );
1482
1483 return $exposed;
1484 }
1485
1486 /**
1487 * Get accounts with insecure usernames
1488 *
1489 * Checks for common default usernames that are targeted by brute force attacks.
1490 * Detects any user regardless of role (consistent with username creation blocking).
1491 * Uses WordPress object cache via get_user_by() so no transient needed.
1492 *
1493 * @return array Array of insecure usernames found.
1494 */
1495 private function get_insecure_admin_usernames() {
1496 $priority_usernames = array( 'admin', 'administrator', 'root', 'test', 'user', 'guest', 'info', 'sysadmin', 'webmaster' );
1497 $found = array();
1498
1499 foreach ( $priority_usernames as $username ) {
1500 $user = get_user_by( 'login', $username );
1501 if ( $user ) {
1502 $found[] = $username;
1503 }
1504 }
1505
1506 return $found;
1507 }
1508
1509 /**
1510 * Get security status for menu badge
1511 *
1512 * Returns count of disabled modules and whether there are critical issues.
1513 * Critical = Firewall or Login Security disabled.
1514 *
1515 * @return array Array with 'count' and 'has_critical'.
1516 */
1517 public function get_security_status_for_badge() {
1518 $options = $this->settings->get_all_options();
1519 $modules = $options['modules'] ?? array();
1520
1521 // Count disabled modules
1522 $disabled_count = 0;
1523 $has_critical = false;
1524
1525 // Critical modules - if disabled, badge is red
1526 $critical_modules = array( 'firewall', 'login_security' );
1527
1528 foreach ( $modules as $module => $enabled ) {
1529 // Handle both boolean and string values ('1', '0', true, false)
1530 $is_enabled = filter_var( $enabled, FILTER_VALIDATE_BOOLEAN );
1531
1532 if ( ! $is_enabled ) {
1533 $disabled_count++;
1534
1535 // Check if this is a critical module
1536 if ( in_array( $module, $critical_modules, true ) ) {
1537 $has_critical = true;
1538 }
1539 }
1540 }
1541
1542 return array(
1543 'count' => $disabled_count,
1544 'has_critical' => $has_critical,
1545 );
1546 }
1547
1548 /**
1549 * Get count of security issues for menu badge (deprecated, use get_security_status_for_badge)
1550 *
1551 * @return int Count of critical/high issues.
1552 */
1553 public function get_security_issues_count() {
1554 $status = $this->get_security_status_for_badge();
1555 return $status['count'];
1556 }
1557
1558 /**
1559 * Register settings
1560 */
1561 public function register_settings() {
1562 register_setting(
1563 'vigilante_options',
1564 Vigilante_Settings::OPTION_NAME,
1565 array( $this->settings, 'validate_options' )
1566 );
1567 }
1568
1569 /**
1570 * Index behind the settings search box.
1571 *
1572 * Each entry points at one settings row. The search matches on the label,
1573 * on its English original and on 'keywords', which are extra terms someone
1574 * might type instead of the label itself.
1575 *
1576 * Those keywords are wrapped in _x() with the context "settings search
1577 * keywords" so every locale can supply its own: the source strings are in
1578 * English, and a Spanish user typing "contrasena" or a German one typing
1579 * "Kennwort" only reaches the password settings if that locale translated
1580 * them. Translators can add, drop or replace terms freely, one per space;
1581 * they are never displayed, only matched against what the user types.
1582 *
1583 * The list is maintained by hand, so a new settings row needs an entry here
1584 * or it cannot be found. It had drifted to 68 of 131 rows before 2.9.7.
1585 *
1586 * @return array
1587 */
1588 private function get_search_index() {
1589 return array(
1590 // Firewall - Main
1591 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Block bad bots', 'vigilante' ), 'label_en' => 'Block bad bots', 'keywords' => _x( 'block bad bots blocking blocked deny malicious harmful bot crawler crawlers spider scraper robots', 'settings search keywords', 'vigilante' ) ),
1592 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Block malicious requests', 'vigilante' ), 'label_en' => 'Block malicious requests', 'keywords' => _x( 'block malicious requests blocking blocked deny attack attacks exploit injection sqli xss rfi lfi request traffic', 'settings search keywords', 'vigilante' ) ),
1593 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Rate limiting', 'vigilante' ), 'label_en' => 'Rate limiting', 'keywords' => _x( 'rate limiting throttle flood burst limit limits', 'settings search keywords', 'vigilante' ) ),
1594 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Brute force protection', 'vigilante' ), 'label_en' => 'Brute force protection', 'keywords' => _x( 'brute force protection bruteforce login', 'settings search keywords', 'vigilante' ) ),
1595 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'IP Whitelist', 'vigilante' ), 'label_en' => 'IP Whitelist', 'keywords' => _x( 'ip whitelist ips address addresses cidr ipv4 ipv6 allowlist allowed trusted', 'settings search keywords', 'vigilante' ) ),
1596 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'IP Blacklist', 'vigilante' ), 'label_en' => 'IP Blacklist', 'keywords' => _x( 'ip blacklist ips address addresses cidr ipv4 ipv6 blocklist denylist banned', 'settings search keywords', 'vigilante' ) ),
1597 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'User-Agent Whitelist', 'vigilante' ), 'label_en' => 'User-Agent Whitelist', 'keywords' => _x( 'user-agent whitelist ua useragent browser allowlist allowed trusted user', 'settings search keywords', 'vigilante' ) ),
1598 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'User-Agent Blacklist', 'vigilante' ), 'label_en' => 'User-Agent Blacklist', 'keywords' => _x( 'user-agent blacklist ua useragent browser blocklist denylist banned user', 'settings search keywords', 'vigilante' ) ),
1599 // Firewall - Server Protection
1600 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Server Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-server', 'label' => __( 'Directory Browsing', 'vigilante' ), 'label_en' => 'Directory Browsing', 'keywords' => _x( 'directory browsing folder folders listing indexing index', 'settings search keywords', 'vigilante' ) ),
1601 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Server Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-server', 'label' => __( 'Protect wp-config.php', 'vigilante' ), 'label_en' => 'Protect wp-config.php', 'keywords' => _x( 'protect wp-config php protection secure lock', 'settings search keywords', 'vigilante' ) ),
1602 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Server Protection', 'vigilante' ), 'anchor' => 'field-protect-wp-cron', 'label' => __( 'Protect wp-cron.php', 'vigilante' ), 'label_en' => 'Protect wp-cron.php', 'keywords' => _x( 'protect wp-cron php protection secure lock cron scheduled tasks block spam', 'settings search keywords', 'vigilante' ) ),
1603 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Server Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-server', 'label' => __( 'Protect wp-includes', 'vigilante' ), 'label_en' => 'Protect wp-includes', 'keywords' => _x( 'protect wp-includes protection secure lock', 'settings search keywords', 'vigilante' ) ),
1604 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Server Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-server', 'label' => __( 'PHP in Uploads', 'vigilante' ), 'label_en' => 'PHP in Uploads', 'keywords' => _x( 'php in uploads media upload', 'settings search keywords', 'vigilante' ) ),
1605 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Server Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-server', 'label' => __( 'Sensitive Files', 'vigilante' ), 'label_en' => 'Sensitive Files', 'keywords' => _x( 'sensitive files private secret file log', 'settings search keywords', 'vigilante' ) ),
1606 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Server Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-server', 'label' => __( 'Limit HTTP Methods', 'vigilante' ), 'label_en' => 'Limit HTTP Methods', 'keywords' => _x( 'limit http methods', 'settings search keywords', 'vigilante' ) ),
1607 // Security Headers
1608 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'X-Frame-Options', 'vigilante' ), 'label_en' => 'X-Frame-Options', 'keywords' => _x( 'x-frame-options headers', 'settings search keywords', 'vigilante' ) ),
1609 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'X-Content-Type-Options', 'vigilante' ), 'label_en' => 'X-Content-Type-Options', 'keywords' => _x( 'x-content-type-options content headers', 'settings search keywords', 'vigilante' ) ),
1610 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Referrer-Policy', 'vigilante' ), 'label_en' => 'Referrer-Policy', 'keywords' => _x( 'referrer-policy headers', 'settings search keywords', 'vigilante' ) ),
1611 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'HSTS', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'HSTS', 'vigilante' ), 'label_en' => 'HSTS', 'keywords' => _x( 'hsts strict transport security ssl tls https headers', 'settings search keywords', 'vigilante' ) ),
1612 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Content Security Policy', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Content Security Policy', 'vigilante' ), 'label_en' => 'Content Security Policy', 'keywords' => _x( 'content security policy csp xss headers', 'settings search keywords', 'vigilante' ) ),
1613 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Server Identity', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Server Signature', 'vigilante' ), 'label_en' => 'Server Signature', 'keywords' => _x( 'server signature fingerprint banner', 'settings search keywords', 'vigilante' ) ),
1614 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Server Identity', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Remove Fingerprinting Headers', 'vigilante' ), 'label_en' => 'Remove Fingerprinting Headers', 'keywords' => _x( 'remove fingerprinting headers fingerprint banner header http', 'settings search keywords', 'vigilante' ) ),
1615 // Security Headers - Cross-Origin Policies
1616 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Cross-Origin Policies', 'vigilante' ), 'anchor' => 'vigilante-section-headers-cross-origin', 'label' => __( 'Cross-Origin-Opener-Policy (COOP)', 'vigilante' ), 'label_en' => 'Cross-Origin-Opener-Policy (COOP)', 'keywords' => _x( 'coop cross-origin opener policy popup popups window opener tag assistant google isolation browsing context headers', 'settings search keywords', 'vigilante' ) ),
1617 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Cross-Origin Policies', 'vigilante' ), 'anchor' => 'vigilante-section-headers-cross-origin', 'label' => __( 'Cross-Origin-Embedder-Policy (COEP)', 'vigilante' ), 'label_en' => 'Cross-Origin-Embedder-Policy (COEP)', 'keywords' => _x( 'coep cross-origin embedder policy require-corp credentialless embed embeds iframe fonts headers', 'settings search keywords', 'vigilante' ) ),
1618 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Cross-Origin Policies', 'vigilante' ), 'anchor' => 'vigilante-section-headers-cross-origin', 'label' => __( 'Cross-Origin-Resource-Policy (CORP)', 'vigilante' ), 'label_en' => 'Cross-Origin-Resource-Policy (CORP)', 'keywords' => _x( 'corp cross-origin resource policy hotlink hotlinking cdn images assets headers', 'settings search keywords', 'vigilante' ) ),
1619 // Login Security
1620 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Custom login URL', 'vigilante' ), 'label_en' => 'Custom login URL', 'keywords' => _x( 'custom login url signin log-in access slug', 'settings search keywords', 'vigilante' ) ),
1621 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Two-Factor Authentication', 'vigilante' ), 'label_en' => 'Two-Factor Authentication', 'keywords' => _x( 'two-factor authentication 2fa mfa otp totp authenticator', 'settings search keywords', 'vigilante' ) ),
1622 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( '2FA', 'vigilante' ), 'label_en' => '2FA', 'keywords' => _x( '2fa two-factor mfa otp totp authenticator', 'settings search keywords', 'vigilante' ) ),
1623 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Failed login attempts', 'vigilante' ), 'label_en' => 'Failed login attempts', 'keywords' => _x( 'failed login attempts signin log-in access tries retries', 'settings search keywords', 'vigilante' ) ),
1624 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Lockout', 'vigilante' ), 'label_en' => 'Lockout', 'keywords' => _x( 'lockout lock ban block login', 'settings search keywords', 'vigilante' ) ),
1625 // REST API
1626 array( 'tab' => 'rest-api', 'tab_label' => __( 'REST API', 'vigilante' ), 'section' => __( 'REST API Security', 'vigilante' ), 'anchor' => 'vigilante-section-rest-api-main', 'label' => __( 'Access Mode', 'vigilante' ), 'label_en' => 'Access Mode', 'keywords' => _x( 'access mode rest api', 'settings search keywords', 'vigilante' ) ),
1627 array( 'tab' => 'rest-api', 'tab_label' => __( 'REST API', 'vigilante' ), 'section' => __( 'REST API Security', 'vigilante' ), 'anchor' => 'vigilante-section-rest-api-main', 'label' => __( 'Block User Enumeration', 'vigilante' ), 'label_en' => 'Block User Enumeration', 'keywords' => _x( 'block user enumeration blocking blocked deny users account author slug', 'settings search keywords', 'vigilante' ) ),
1628 array( 'tab' => 'rest-api', 'tab_label' => __( 'REST API', 'vigilante' ), 'section' => __( 'REST API Security', 'vigilante' ), 'anchor' => 'vigilante-section-rest-api-main', 'label' => __( 'Disable JSONP', 'vigilante' ), 'label_en' => 'Disable JSONP', 'keywords' => _x( 'disable jsonp', 'settings search keywords', 'vigilante' ) ),
1629 // User Security
1630 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Username protection', 'vigilante' ), 'label_en' => 'Username protection', 'keywords' => _x( 'username protection admin', 'settings search keywords', 'vigilante' ) ),
1631 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Password strength', 'vigilante' ), 'label_en' => 'Password strength', 'keywords' => _x( 'password strength passwords credentials', 'settings search keywords', 'vigilante' ) ),
1632 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Admin monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-users-admin-monitoring', 'label' => __( 'Admin monitoring', 'vigilante' ), 'label_en' => 'Admin monitoring', 'keywords' => _x( 'admin monitoring administrator administrators', 'settings search keywords', 'vigilante' ) ),
1633 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Registration approval', 'vigilante' ), 'anchor' => 'vigilante-section-users-registration', 'label' => __( 'Registration approval', 'vigilante' ), 'label_en' => 'Registration approval', 'keywords' => _x( 'registration approval signup register approve moderate', 'settings search keywords', 'vigilante' ) ),
1634 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Session limits', 'vigilante' ), 'anchor' => 'vigilante-section-users-sessions', 'label' => __( 'Session limits', 'vigilante' ), 'label_en' => 'Session limits', 'keywords' => _x( 'session limits sessions concurrent', 'settings search keywords', 'vigilante' ) ),
1635 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Password expiration', 'vigilante' ), 'label_en' => 'Password expiration', 'keywords' => _x( 'password expiration passwords credentials expiry expire caducity', 'settings search keywords', 'vigilante' ) ),
1636 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Email verification', 'vigilante' ), 'anchor' => 'vigilante-section-users-email-verify', 'label' => __( 'Email verification', 'vigilante' ), 'label_en' => 'Email verification', 'keywords' => _x( 'email verification mail notification notify verify confirm', 'settings search keywords', 'vigilante' ) ),
1637 // WP Hardening
1638 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Database Hardening', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-database', 'label' => __( 'Database Hardening', 'vigilante' ), 'label_en' => 'Database Hardening', 'keywords' => _x( 'database hardening db mysql tables', 'settings search keywords', 'vigilante' ) ),
1639 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Database Hardening', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-database', 'label' => __( 'Database prefix', 'vigilante' ), 'label_en' => 'Database prefix', 'keywords' => _x( 'database prefix db mysql tables table', 'settings search keywords', 'vigilante' ) ),
1640 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'wp-config.php Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-wpconfig', 'label' => __( 'Disable file editing', 'vigilante' ), 'label_en' => 'Disable file editing', 'keywords' => _x( 'disable file editing files editor edit', 'settings search keywords', 'vigilante' ) ),
1641 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'wp-config.php Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-wpconfig', 'label' => __( 'Disable plugin/theme installation', 'vigilante' ), 'label_en' => 'Disable plugin/theme installation', 'keywords' => _x( 'disable plugin theme installation install', 'settings search keywords', 'vigilante' ) ),
1642 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'wp-config.php Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-wpconfig', 'label' => __( 'Force SSL admin', 'vigilante' ), 'label_en' => 'Force SSL admin', 'keywords' => _x( 'force ssl admin bruteforce administrator administrators tls https', 'settings search keywords', 'vigilante' ) ),
1643 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'wp-config.php Security', 'vigilante' ), 'anchor' => 'field-disable-wp-cron', 'label' => __( 'Disable WP Cron', 'vigilante' ), 'label_en' => 'Disable WP Cron', 'keywords' => _x( 'disable wp cron scheduled tasks wp-cron', 'settings search keywords', 'vigilante' ) ),
1644 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Comment Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-comments', 'label' => __( 'Comment Security', 'vigilante' ), 'label_en' => 'Comment Security', 'keywords' => _x( 'comment security comments spam honeypot url', 'settings search keywords', 'vigilante' ) ),
1645 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-headers', 'label' => __( 'Header Cleanup', 'vigilante' ), 'label_en' => 'Header Cleanup', 'keywords' => _x( 'header cleanup headers http meta generator rsd wlwmanifest', 'settings search keywords', 'vigilante' ) ),
1646 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-headers', 'label' => __( 'Remove WordPress version', 'vigilante' ), 'label_en' => 'Remove WordPress version', 'keywords' => _x( 'remove wordpress version generator meta', 'settings search keywords', 'vigilante' ) ),
1647 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'field-remove-wp-version-assets', 'label' => __( 'Remove version from assets', 'vigilante' ), 'label_en' => 'Remove version from assets', 'keywords' => _x( 'remove version from assets', 'settings search keywords', 'vigilante' ) ),
1648 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-xmlrpc', 'label' => __( 'Disable XML-RPC', 'vigilante' ), 'label_en' => 'Disable XML-RPC', 'keywords' => _x( 'disable xml-rpc xmlrpc rpc remote jetpack app pingback trackback', 'settings search keywords', 'vigilante' ) ),
1649 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'RSS Feed Settings', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-rss', 'label' => __( 'RSS Feed Settings', 'vigilante' ), 'label_en' => 'RSS Feed Settings', 'keywords' => _x( 'rss feed settings feeds atom', 'settings search keywords', 'vigilante' ) ),
1650 // File Integrity
1651 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'File Integrity Monitoring', 'vigilante' ), 'label_en' => 'File Integrity Monitoring', 'keywords' => _x( 'file integrity monitoring files checksum checksums tamper', 'settings search keywords', 'vigilante' ) ),
1652 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Scan schedule', 'vigilante' ), 'label_en' => 'Scan schedule', 'keywords' => _x( 'scan schedule scans scanning check cron', 'settings search keywords', 'vigilante' ) ),
1653 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Instant alert', 'vigilante' ), 'label_en' => 'Instant alert', 'keywords' => _x( 'instant alert alerts notification warning email', 'settings search keywords', 'vigilante' ) ),
1654 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'Vigilant self-protection', 'vigilante' ), 'anchor' => 'vigilante-section-fi-self', 'label' => __( 'Vigilant self-protection', 'vigilante' ), 'label_en' => 'Vigilant self-protection', 'keywords' => _x( 'self protection selfprotection self-check autoproteccion manifest sha256 checksums tampering tampered repair reinstall own files guardian integrity of the plugin', 'settings search keywords', 'vigilante' ) ),
1655 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'Ignored Files', 'vigilante' ), 'anchor' => 'vigilante-section-fi-ignored', 'label' => __( 'Ignored Files', 'vigilante' ), 'label_en' => 'Ignored Files', 'keywords' => _x( 'ignored files file exclude', 'settings search keywords', 'vigilante' ) ),
1656 // Security Audit
1657 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Security Audit Settings', 'vigilante' ), 'anchor' => 'vigilante-section-audit-settings', 'label' => __( 'Retention', 'vigilante' ), 'label_en' => 'Retention', 'keywords' => _x( 'retention keep days storage log', 'settings search keywords', 'vigilante' ) ),
1658 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Security Audit Settings', 'vigilante' ), 'anchor' => 'vigilante-section-audit-settings', 'label' => __( 'Events to Log', 'vigilante' ), 'label_en' => 'Events to Log', 'keywords' => _x( 'events to log', 'settings search keywords', 'vigilante' ) ),
1659 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Security Audit Settings', 'vigilante' ), 'anchor' => 'vigilante-section-audit-settings', 'label' => __( 'Option Tracking', 'vigilante' ), 'label_en' => 'Option Tracking', 'keywords' => _x( 'option tracking', 'settings search keywords', 'vigilante' ) ),
1660 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Security Audit Settings', 'vigilante' ), 'anchor' => 'vigilante-section-audit-settings', 'label' => __( 'Exclusions', 'vigilante' ), 'label_en' => 'Exclusions', 'keywords' => _x( 'exclusions roles ip', 'settings search keywords', 'vigilante' ) ),
1661 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Audit Alerts', 'vigilante' ), 'anchor' => 'vigilante-section-audit-alerts', 'label' => __( 'Audit Alerts', 'vigilante' ), 'label_en' => 'Audit Alerts', 'keywords' => _x( 'audit alerts email mail warning critical', 'settings search keywords', 'vigilante' ) ),
1662 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Audit Alerts', 'vigilante' ), 'anchor' => 'field-audit-alerts-immediate', 'label' => __( 'Immediate alerts', 'vigilante' ), 'label_en' => 'Immediate alerts', 'keywords' => _x( 'immediate alerts email mail critical warning', 'settings search keywords', 'vigilante' ) ),
1663 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Audit Alerts', 'vigilante' ), 'anchor' => 'field-audit-alerts-threshold', 'label' => __( 'Threshold alerts', 'vigilante' ), 'label_en' => 'Threshold alerts', 'keywords' => _x( 'threshold alerts email mail login', 'settings search keywords', 'vigilante' ) ),
1664 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Recent Activity', 'vigilante' ), 'anchor' => 'vigilante-section-audit-recent', 'label' => __( 'Recent Activity', 'vigilante' ), 'label_en' => 'Recent Activity', 'keywords' => _x( 'recent activity log', 'settings search keywords', 'vigilante' ) ),
1665 // Settings & Tools
1666 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Notification settings', 'vigilante' ), 'anchor' => 'vigilante-section-tools-notifications', 'label' => __( 'Notification settings', 'vigilante' ), 'label_en' => 'Notification settings', 'keywords' => _x( 'notification settings email', 'settings search keywords', 'vigilante' ) ),
1667 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Notification settings', 'vigilante' ), 'anchor' => 'vigilante-section-tools-notifications', 'label' => __( 'Additional Recipients', 'vigilante' ), 'label_en' => 'Additional Recipients', 'keywords' => _x( 'additional recipients email recipient', 'settings search keywords', 'vigilante' ) ),
1668 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Tools', 'vigilante' ), 'anchor' => 'vigilante-section-tools-main', 'label' => __( 'Export Settings', 'vigilante' ), 'label_en' => 'Export Settings', 'keywords' => _x( 'export settings json', 'settings search keywords', 'vigilante' ) ),
1669 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Tools', 'vigilante' ), 'anchor' => 'vigilante-section-tools-main', 'label' => __( 'Import Settings', 'vigilante' ), 'label_en' => 'Import Settings', 'keywords' => _x( 'import settings json', 'settings search keywords', 'vigilante' ) ),
1670 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Tools', 'vigilante' ), 'anchor' => 'vigilante-section-tools-main', 'label' => __( 'Reset to Defaults', 'vigilante' ), 'label_en' => 'Reset to Defaults', 'keywords' => _x( 'reset to defaults', 'settings search keywords', 'vigilante' ) ),
1671 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Tools', 'vigilante' ), 'anchor' => 'vigilante-section-tools-main', 'label' => __( 'Create Backup', 'vigilante' ), 'label_en' => 'Create Backup', 'keywords' => _x( 'create backup', 'settings search keywords', 'vigilante' ) ),
1672 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Tools', 'vigilante' ), 'anchor' => 'vigilante-section-tools-main', 'label' => __( 'Database Backup', 'vigilante' ), 'label_en' => 'Database Backup', 'keywords' => _x( 'database backup db mysql tables', 'settings search keywords', 'vigilante' ) ),
1673 // Entradas anadidas en la 2.9.7 tras comprobar que el indice cubria 68 de
1674 // las 131 filas de ajustes: buscar XML-RPC, por ejemplo, no devolvia nada.
1675 // El indice se mantiene a mano, asi que al anadir una fila de ajustes hay
1676 // que anadirla tambien aqui.
1677 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Notification settings', 'vigilante' ), 'anchor' => 'vigilante-section-tools-notifications', 'label' => __( 'WordPress Admin Email', 'vigilante' ), 'label_en' => 'WordPress Admin Email', 'keywords' => _x( 'wordpress admin email administrator administrators mail notification notify', 'settings search keywords', 'vigilante' ) ),
1678 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Notification settings', 'vigilante' ), 'anchor' => 'vigilante-section-tools-notifications', 'label' => __( 'Plugin Deactivation', 'vigilante' ), 'label_en' => 'Plugin Deactivation', 'keywords' => _x( 'plugin deactivation', 'settings search keywords', 'vigilante' ) ),
1679 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Block Bad Query Strings', 'vigilante' ), 'label_en' => 'Block Bad Query Strings', 'keywords' => _x( 'block bad query strings blocking blocked deny malicious harmful', 'settings search keywords', 'vigilante' ) ),
1680 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'SQL Injection Protection', 'vigilante' ), 'label_en' => 'SQL Injection Protection', 'keywords' => _x( 'sql injection protection', 'settings search keywords', 'vigilante' ) ),
1681 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'XSS Protection', 'vigilante' ), 'label_en' => 'XSS Protection', 'keywords' => _x( 'xss protection', 'settings search keywords', 'vigilante' ) ),
1682 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'File Inclusion Protection', 'vigilante' ), 'label_en' => 'File Inclusion Protection', 'keywords' => _x( 'file inclusion protection files', 'settings search keywords', 'vigilante' ) ),
1683 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Directory Traversal Protection', 'vigilante' ), 'label_en' => 'Directory Traversal Protection', 'keywords' => _x( 'directory traversal protection folder folders', 'settings search keywords', 'vigilante' ) ),
1684 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Enable Rate Limiting', 'vigilante' ), 'label_en' => 'Enable Rate Limiting', 'keywords' => _x( 'enable rate limiting throttle flood burst limit limits', 'settings search keywords', 'vigilante' ) ),
1685 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Requests per Minute', 'vigilante' ), 'label_en' => 'Requests per Minute', 'keywords' => _x( 'requests per minute request traffic', 'settings search keywords', 'vigilante' ) ),
1686 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Block Duration (seconds)', 'vigilante' ), 'label_en' => 'Block Duration (seconds)', 'keywords' => _x( 'block duration seconds blocking blocked deny', 'settings search keywords', 'vigilante' ) ),
1687 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Progressive Blocking', 'vigilante' ), 'label_en' => 'Progressive Blocking', 'keywords' => _x( 'progressive blocking', 'settings search keywords', 'vigilante' ) ),
1688 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Maximum Block Duration', 'vigilante' ), 'label_en' => 'Maximum Block Duration', 'keywords' => _x( 'maximum block duration blocking blocked deny', 'settings search keywords', 'vigilante' ) ),
1689 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Visitor IP detection', 'vigilante' ), 'label_en' => 'Visitor IP detection', 'keywords' => _x( 'visitor ip detection ips address addresses cidr ipv4 ipv6', 'settings search keywords', 'vigilante' ) ),
1690 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Max Login Attempts', 'vigilante' ), 'label_en' => 'Max Login Attempts', 'keywords' => _x( 'max login attempts signin log-in access tries retries', 'settings search keywords', 'vigilante' ) ),
1691 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Lockout Duration', 'vigilante' ), 'label_en' => 'Lockout Duration', 'keywords' => _x( 'lockout duration lock ban block', 'settings search keywords', 'vigilante' ) ),
1692 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Progressive Lockout', 'vigilante' ), 'label_en' => 'Progressive Lockout', 'keywords' => _x( 'progressive lockout lock ban block', 'settings search keywords', 'vigilante' ) ),
1693 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Hide Login Errors', 'vigilante' ), 'label_en' => 'Hide Login Errors', 'keywords' => _x( 'hide login errors signin log-in access error debug log', 'settings search keywords', 'vigilante' ) ),
1694 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Disable Application Passwords', 'vigilante' ), 'label_en' => 'Disable Application Passwords', 'keywords' => _x( 'disable application passwords password credentials', 'settings search keywords', 'vigilante' ) ),
1695 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Login URL Slug', 'vigilante' ), 'label_en' => 'Login URL Slug', 'keywords' => _x( 'login url slug signin log-in access path', 'settings search keywords', 'vigilante' ) ),
1696 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Notify users', 'vigilante' ), 'label_en' => 'Notify users', 'keywords' => _x( 'notify users notification alert email user accounts', 'settings search keywords', 'vigilante' ) ),
1697 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Notify on Lockout', 'vigilante' ), 'label_en' => 'Notify on Lockout', 'keywords' => _x( 'notify on lockout notification alert email lock ban block', 'settings search keywords', 'vigilante' ) ),
1698 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Notify on Admin Login', 'vigilante' ), 'label_en' => 'Notify on Admin Login', 'keywords' => _x( 'notify on admin login notification alert email administrator administrators signin log-in access', 'settings search keywords', 'vigilante' ) ),
1699 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Current settings', 'vigilante' ), 'label_en' => 'Current settings', 'keywords' => _x( 'current settings', 'settings search keywords', 'vigilante' ) ),
1700 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Blocked IPs', 'vigilante' ), 'label_en' => 'Blocked IPs', 'keywords' => _x( 'blocked ips', 'settings search keywords', 'vigilante' ) ),
1701 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Enable 2FA', 'vigilante' ), 'label_en' => 'Enable 2FA', 'keywords' => _x( 'enable 2fa two-factor mfa otp totp authenticator', 'settings search keywords', 'vigilante' ) ),
1702 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Verification method', 'vigilante' ), 'label_en' => 'Verification method', 'keywords' => _x( 'verification method verify confirm', 'settings search keywords', 'vigilante' ) ),
1703 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Enforce for roles', 'vigilante' ), 'label_en' => 'Enforce for roles', 'keywords' => _x( 'enforce for roles role capabilities', 'settings search keywords', 'vigilante' ) ),
1704 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Exclude specific users', 'vigilante' ), 'label_en' => 'Exclude specific users', 'keywords' => _x( 'exclude specific users user accounts', 'settings search keywords', 'vigilante' ) ),
1705 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Remember device', 'vigilante' ), 'label_en' => 'Remember device', 'keywords' => _x( 'remember device', 'settings search keywords', 'vigilante' ) ),
1706 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Grace period', 'vigilante' ), 'label_en' => 'Grace period', 'keywords' => _x( 'grace period', 'settings search keywords', 'vigilante' ) ),
1707 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Email sender name', 'vigilante' ), 'label_en' => 'Email sender name', 'keywords' => _x( 'email sender name mail notification notify names', 'settings search keywords', 'vigilante' ) ),
1708 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Reset user TOTP', 'vigilante' ), 'label_en' => 'Reset user TOTP', 'keywords' => _x( 'reset user totp users account 2fa authenticator app', 'settings search keywords', 'vigilante' ) ),
1709 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Notify on enable', 'vigilante' ), 'label_en' => 'Notify on enable', 'keywords' => _x( 'notify on enable notification alert email', 'settings search keywords', 'vigilante' ) ),
1710 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Enable CSP', 'vigilante' ), 'label_en' => 'Enable CSP', 'keywords' => _x( 'enable csp content security policy', 'settings search keywords', 'vigilante' ) ),
1711 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Report Only Mode', 'vigilante' ), 'label_en' => 'Report Only Mode', 'keywords' => _x( 'report only mode', 'settings search keywords', 'vigilante' ) ),
1712 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Redirect HTTP to HTTPS', 'vigilante' ), 'label_en' => 'Redirect HTTP to HTTPS', 'keywords' => _x( 'redirect http to https redirection forward ssl tls secure', 'settings search keywords', 'vigilante' ) ),
1713 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Fix Mixed Content', 'vigilante' ), 'label_en' => 'Fix Mixed Content', 'keywords' => _x( 'fix mixed content insecure http', 'settings search keywords', 'vigilante' ) ),
1714 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'field-upgrade-insecure-requests', 'label' => __( 'Upgrade Insecure Requests', 'vigilante' ), 'label_en' => 'Upgrade Insecure Requests', 'keywords' => _x( 'upgrade insecure requests mixed content csp https external resources', 'settings search keywords', 'vigilante' ) ),
1715 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Rewrite Site Address on Activation', 'vigilante' ), 'label_en' => 'Rewrite Site Address on Activation', 'keywords' => _x( 'rewrite site address on activation', 'settings search keywords', 'vigilante' ) ),
1716 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Enable HSTS', 'vigilante' ), 'label_en' => 'Enable HSTS', 'keywords' => _x( 'enable hsts strict transport security', 'settings search keywords', 'vigilante' ) ),
1717 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Max Age', 'vigilante' ), 'label_en' => 'Max Age', 'keywords' => _x( 'max age', 'settings search keywords', 'vigilante' ) ),
1718 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Include Subdomains', 'vigilante' ), 'label_en' => 'Include Subdomains', 'keywords' => _x( 'include subdomains', 'settings search keywords', 'vigilante' ) ),
1719 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Block Insecure Usernames', 'vigilante' ), 'label_en' => 'Block Insecure Usernames', 'keywords' => _x( 'block insecure usernames blocking blocked deny weak unsafe', 'settings search keywords', 'vigilante' ) ),
1720 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Enforce Strong Passwords', 'vigilante' ), 'label_en' => 'Enforce Strong Passwords', 'keywords' => _x( 'enforce strong passwords complexity password credentials', 'settings search keywords', 'vigilante' ) ),
1721 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Minimum Password Length', 'vigilante' ), 'label_en' => 'Minimum Password Length', 'keywords' => _x( 'minimum password length passwords credentials characters', 'settings search keywords', 'vigilante' ) ),
1722 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Password Requirements', 'vigilante' ), 'label_en' => 'Password Requirements', 'keywords' => _x( 'password requirements passwords credentials', 'settings search keywords', 'vigilante' ) ),
1723 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Apply Password Rules To', 'vigilante' ), 'label_en' => 'Apply Password Rules To', 'keywords' => _x( 'apply password rules to passwords credentials', 'settings search keywords', 'vigilante' ) ),
1724 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Block Author Scanning', 'vigilante' ), 'label_en' => 'Block Author Scanning', 'keywords' => _x( 'block author scanning blocking blocked deny authors enumeration probing', 'settings search keywords', 'vigilante' ) ),
1725 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Display Name Protection', 'vigilante' ), 'label_en' => 'Display Name Protection', 'keywords' => _x( 'display name protection public visible names', 'settings search keywords', 'vigilante' ) ),
1726 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Admin monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-users-admin-monitoring', 'label' => __( 'New Administrator Alert', 'vigilante' ), 'label_en' => 'New Administrator Alert', 'keywords' => _x( 'new administrator alert alerts notification warning', 'settings search keywords', 'vigilante' ) ),
1727 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Admin monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-users-admin-monitoring', 'label' => __( 'Admin Email Change Alert', 'vigilante' ), 'label_en' => 'Admin Email Change Alert', 'keywords' => _x( 'admin email change alert administrator administrators mail notification notify alerts warning', 'settings search keywords', 'vigilante' ) ),
1728 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Admin monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-users-admin-monitoring', 'label' => __( 'Permission Elevation Alert', 'vigilante' ), 'label_en' => 'Permission Elevation Alert', 'keywords' => _x( 'permission elevation alert alerts notification warning', 'settings search keywords', 'vigilante' ) ),
1729 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Admin monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-users-admin-monitoring', 'label' => __( 'Admin Password Change Alert', 'vigilante' ), 'label_en' => 'Admin Password Change Alert', 'keywords' => _x( 'admin password change alert administrator administrators passwords credentials alerts notification warning', 'settings search keywords', 'vigilante' ) ),
1730 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Registration approval', 'vigilante' ), 'anchor' => 'vigilante-section-users-registration', 'label' => __( 'Enable Registration Approval', 'vigilante' ), 'label_en' => 'Enable Registration Approval', 'keywords' => _x( 'enable registration approval signup register approve moderate', 'settings search keywords', 'vigilante' ) ),
1731 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Registration approval', 'vigilante' ), 'anchor' => 'vigilante-section-users-registration', 'label' => __( 'Notify Admin', 'vigilante' ), 'label_en' => 'Notify Admin', 'keywords' => _x( 'notify admin notification alert email administrator administrators', 'settings search keywords', 'vigilante' ) ),
1732 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Registration approval', 'vigilante' ), 'anchor' => 'vigilante-section-users-registration', 'label' => __( 'Auto-reject After', 'vigilante' ), 'label_en' => 'Auto-reject After', 'keywords' => _x( 'auto-reject after', 'settings search keywords', 'vigilante' ) ),
1733 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Session limits', 'vigilante' ), 'anchor' => 'vigilante-section-users-sessions', 'label' => __( 'Enable Session Limits', 'vigilante' ), 'label_en' => 'Enable Session Limits', 'keywords' => _x( 'enable session limits sessions concurrent', 'settings search keywords', 'vigilante' ) ),
1734 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Session limits', 'vigilante' ), 'anchor' => 'vigilante-section-users-sessions', 'label' => __( 'Maximum Sessions', 'vigilante' ), 'label_en' => 'Maximum Sessions', 'keywords' => _x( 'maximum sessions session concurrent', 'settings search keywords', 'vigilante' ) ),
1735 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Session limits', 'vigilante' ), 'anchor' => 'vigilante-section-users-sessions', 'label' => __( 'When Limit Exceeded', 'vigilante' ), 'label_en' => 'When Limit Exceeded', 'keywords' => _x( 'when limit exceeded', 'settings search keywords', 'vigilante' ) ),
1736 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Session limits', 'vigilante' ), 'anchor' => 'vigilante-section-users-sessions', 'label' => __( 'Exclude Administrators', 'vigilante' ), 'label_en' => 'Exclude Administrators', 'keywords' => _x( 'exclude administrators', 'settings search keywords', 'vigilante' ) ),
1737 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Enable Password Expiration', 'vigilante' ), 'label_en' => 'Enable Password Expiration', 'keywords' => _x( 'enable password expiration passwords credentials expiry expire caducity', 'settings search keywords', 'vigilante' ) ),
1738 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Expire After', 'vigilante' ), 'label_en' => 'Expire After', 'keywords' => _x( 'expire after', 'settings search keywords', 'vigilante' ) ),
1739 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Warning Period', 'vigilante' ), 'label_en' => 'Warning Period', 'keywords' => _x( 'warning period', 'settings search keywords', 'vigilante' ) ),
1740 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Password History', 'vigilante' ), 'label_en' => 'Password History', 'keywords' => _x( 'password history passwords credentials reuse previous', 'settings search keywords', 'vigilante' ) ),
1741 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Email Reminder', 'vigilante' ), 'label_en' => 'Email Reminder', 'keywords' => _x( 'email reminder mail notification notify', 'settings search keywords', 'vigilante' ) ),
1742 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Affected Roles', 'vigilante' ), 'label_en' => 'Affected Roles', 'keywords' => _x( 'affected roles role capabilities', 'settings search keywords', 'vigilante' ) ),
1743 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Exclude specific users', 'vigilante' ), 'label_en' => 'Exclude specific users', 'keywords' => _x( 'exclude specific users user accounts', 'settings search keywords', 'vigilante' ) ),
1744 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Email verification', 'vigilante' ), 'anchor' => 'vigilante-section-users-email-verify', 'label' => __( 'Enable Email Verification', 'vigilante' ), 'label_en' => 'Enable Email Verification', 'keywords' => _x( 'enable email verification mail notification notify verify confirm', 'settings search keywords', 'vigilante' ) ),
1745 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Email verification', 'vigilante' ), 'anchor' => 'vigilante-section-users-email-verify', 'label' => __( 'Link Expiration', 'vigilante' ), 'label_en' => 'Link Expiration', 'keywords' => _x( 'link expiration expiry expire caducity', 'settings search keywords', 'vigilante' ) ),
1746 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Email verification', 'vigilante' ), 'anchor' => 'vigilante-section-users-email-verify', 'label' => __( 'Allow Resend', 'vigilante' ), 'label_en' => 'Allow Resend', 'keywords' => _x( 'allow resend', 'settings search keywords', 'vigilante' ) ),
1747 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Email verification', 'vigilante' ), 'anchor' => 'vigilante-section-users-email-verify', 'label' => __( 'Auto-delete Unverified', 'vigilante' ), 'label_en' => 'Auto-delete Unverified', 'keywords' => _x( 'auto-delete unverified', 'settings search keywords', 'vigilante' ) ),
1748 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Database Hardening', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-database', 'label' => __( 'Current prefix', 'vigilante' ), 'label_en' => 'Current prefix', 'keywords' => _x( 'current prefix database db table tables mysql', 'settings search keywords', 'vigilante' ) ),
1749 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Database Hardening', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-database', 'label' => __( 'New prefix', 'vigilante' ), 'label_en' => 'New prefix', 'keywords' => _x( 'new prefix database db table tables mysql', 'settings search keywords', 'vigilante' ) ),
1750 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'wp-config.php Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-wpconfig', 'label' => __( 'Disable File Editor', 'vigilante' ), 'label_en' => 'Disable File Editor', 'keywords' => _x( 'disable file editor files edit editing', 'settings search keywords', 'vigilante' ) ),
1751 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'wp-config.php Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-wpconfig', 'label' => __( 'Disable File Modifications', 'vigilante' ), 'label_en' => 'Disable File Modifications', 'keywords' => _x( 'disable file modifications files modify install update', 'settings search keywords', 'vigilante' ) ),
1752 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'wp-config.php Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-wpconfig', 'label' => __( 'Hide PHP errors from visitors', 'vigilante' ), 'label_en' => 'Hide PHP errors from visitors', 'keywords' => _x( 'hide php errors from visitors error debug log', 'settings search keywords', 'vigilante' ) ),
1753 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'XML-RPC', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-xmlrpc', 'label' => __( 'XML-RPC access', 'vigilante' ), 'label_en' => 'XML-RPC access', 'keywords' => _x( 'xml-rpc access xmlrpc rpc remote jetpack app', 'settings search keywords', 'vigilante' ) ),
1754 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Comment Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-comments', 'label' => __( 'Disable Pingbacks', 'vigilante' ), 'label_en' => 'Disable Pingbacks', 'keywords' => _x( 'disable pingbacks pingback ping', 'settings search keywords', 'vigilante' ) ),
1755 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Comment Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-comments', 'label' => __( 'Disable Trackbacks', 'vigilante' ), 'label_en' => 'Disable Trackbacks', 'keywords' => _x( 'disable trackbacks trackback ping', 'settings search keywords', 'vigilante' ) ),
1756 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Comment Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-comments', 'label' => __( 'Require Moderation', 'vigilante' ), 'label_en' => 'Require Moderation', 'keywords' => _x( 'require moderation moderate approve', 'settings search keywords', 'vigilante' ) ),
1757 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Comment Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-comments', 'label' => __( 'Close Old Comments', 'vigilante' ), 'label_en' => 'Close Old Comments', 'keywords' => _x( 'close old comments comment discussion', 'settings search keywords', 'vigilante' ) ),
1758 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Comment Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-comments', 'label' => __( 'Honeypot Protection', 'vigilante' ), 'label_en' => 'Honeypot Protection', 'keywords' => _x( 'honeypot protection spam bots trap', 'settings search keywords', 'vigilante' ) ),
1759 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-headers', 'label' => __( 'Remove Generator', 'vigilante' ), 'label_en' => 'Remove Generator', 'keywords' => _x( 'remove generator version meta', 'settings search keywords', 'vigilante' ) ),
1760 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-headers', 'label' => __( 'Remove RSD Link', 'vigilante' ), 'label_en' => 'Remove RSD Link', 'keywords' => _x( 'remove rsd link discovery', 'settings search keywords', 'vigilante' ) ),
1761 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-headers', 'label' => __( 'Remove WLW Manifest', 'vigilante' ), 'label_en' => 'Remove WLW Manifest', 'keywords' => _x( 'remove wlw manifest wlwmanifest', 'settings search keywords', 'vigilante' ) ),
1762 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-headers', 'label' => __( 'Remove Shortlink', 'vigilante' ), 'label_en' => 'Remove Shortlink', 'keywords' => _x( 'remove shortlink link', 'settings search keywords', 'vigilante' ) ),
1763 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-headers', 'label' => __( 'Remove REST API Link', 'vigilante' ), 'label_en' => 'Remove REST API Link', 'keywords' => _x( 'remove rest api link json endpoint', 'settings search keywords', 'vigilante' ) ),
1764 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'RSS Feed Settings', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-rss', 'label' => __( 'Disable Feeds', 'vigilante' ), 'label_en' => 'Disable Feeds', 'keywords' => _x( 'disable feeds feed rss atom syndication', 'settings search keywords', 'vigilante' ) ),
1765 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'RSS Feed Settings', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-rss', 'label' => __( 'Disable If No Content', 'vigilante' ), 'label_en' => 'Disable If No Content', 'keywords' => _x( 'disable if no content', 'settings search keywords', 'vigilante' ) ),
1766 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'RSS Feed Settings', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-rss', 'label' => __( 'Remove Feed Version', 'vigilante' ), 'label_en' => 'Remove Feed Version', 'keywords' => _x( 'remove feed version feeds rss atom', 'settings search keywords', 'vigilante' ) ),
1767 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Audit Alerts', 'vigilante' ), 'anchor' => 'vigilante-section-audit-alerts', 'label' => __( 'Alert on severity', 'vigilante' ), 'label_en' => 'Alert on severity', 'keywords' => _x( 'alert on severity alerts notification warning level critical', 'settings search keywords', 'vigilante' ) ),
1768 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Audit Alerts', 'vigilante' ), 'anchor' => 'vigilante-section-audit-alerts', 'label' => __( 'Time window', 'vigilante' ), 'label_en' => 'Time window', 'keywords' => _x( 'time window', 'settings search keywords', 'vigilante' ) ),
1769 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Audit Alerts', 'vigilante' ), 'anchor' => 'vigilante-section-audit-alerts', 'label' => __( 'Thresholds per category', 'vigilante' ), 'label_en' => 'Thresholds per category', 'keywords' => _x( 'thresholds per category threshold limit', 'settings search keywords', 'vigilante' ) ),
1770 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Audit Alerts', 'vigilante' ), 'anchor' => 'vigilante-section-audit-alerts', 'label' => __( 'Recipients', 'vigilante' ), 'label_en' => 'Recipients', 'keywords' => _x( 'recipients email recipient', 'settings search keywords', 'vigilante' ) ),
1771 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Automatic Scans', 'vigilante' ), 'label_en' => 'Automatic Scans', 'keywords' => _x( 'automatic scans scan scanning', 'settings search keywords', 'vigilante' ) ),
1772 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Scan Frequency', 'vigilante' ), 'label_en' => 'Scan Frequency', 'keywords' => _x( 'scan frequency scans scanning check', 'settings search keywords', 'vigilante' ) ),
1773 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Email Notifications', 'vigilante' ), 'label_en' => 'Email Notifications', 'keywords' => _x( 'email notifications mail notification notify', 'settings search keywords', 'vigilante' ) ),
1774 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Test email', 'vigilante' ), 'label_en' => 'Test email', 'keywords' => _x( 'test email mail notification notify', 'settings search keywords', 'vigilante' ) ),
1775 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Scan Scope', 'vigilante' ), 'label_en' => 'Scan Scope', 'keywords' => _x( 'scan scope scans scanning check', 'settings search keywords', 'vigilante' ) ),
1776 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Excluded Paths', 'vigilante' ), 'label_en' => 'Excluded Paths', 'keywords' => _x( 'excluded paths exclude exclusions ignore ignored path folder folders', 'settings search keywords', 'vigilante' ) ),
1777 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Excluded Extensions', 'vigilante' ), 'label_en' => 'Excluded Extensions', 'keywords' => _x( 'excluded extensions exclude exclusions ignore ignored extension filetype', 'settings search keywords', 'vigilante' ) ),
1778 );
1779 }
1780
1781 /**
1782 * Enqueue admin assets
1783 *
1784 * @param string $hook Current admin page.
1785 */
1786 public function enqueue_assets( $hook ) {
1787 // toplevel_page_vigilante for top-level menu page
1788 if ( 'toplevel_page_vigilante' !== $hook ) {
1789 return;
1790 }
1791
1792 wp_enqueue_style(
1793 'vigilante-admin',
1794 VIGILANTE_ASSETS_URL . 'css/admin.css',
1795 array(),
1796 VIGILANTE_VERSION
1797 );
1798
1799 wp_enqueue_script(
1800 'vigilante-admin',
1801 VIGILANTE_ASSETS_URL . 'js/admin.js',
1802 array( 'jquery' ),
1803 VIGILANTE_VERSION,
1804 true
1805 );
1806
1807 wp_localize_script( 'vigilante-admin', 'vigilanteAdmin', array(
1808 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
1809 'selfBoxUrl' => esc_url( admin_url( 'admin.php?page=vigilante&tab=file-integrity#vigilante-section-fi-self' ) ),
1810 'nonce' => wp_create_nonce( 'vigilante_admin_nonce' ),
1811 'currentUserId' => get_current_user_id(),
1812 'logoutUrl' => wp_logout_url( wp_login_url() ),
1813 'adminUrl' => admin_url( 'admin.php?page=vigilante' ),
1814 'searchIndex' => $this->get_search_index(),
1815 // The scan repaints this table from JavaScript, so the same gate
1816 // has to travel with it or half the screen keeps the dead button.
1817 'approvalLocked' => $this->critical_approval_locked(),
1818 'underAttack' => array(
1819 'active' => ( new Vigilante_Under_Attack( $this->settings, $this->activity_log ) )->is_active(),
1820 'remaining' => ( new Vigilante_Under_Attack( $this->settings, $this->activity_log ) )->get_remaining_time(),
1821 ),
1822 'strings' => array(
1823 'saving' => __( 'Saving...', 'vigilante' ),
1824 'sendingTest' => __( 'Sending...', 'vigilante' ),
1825 'saved' => __( 'Settings saved', 'vigilante' ),
1826 'error' => __( 'Error saving settings', 'vigilante' ),
1827 'confirm' => __( 'Are you sure?', 'vigilante' ),
1828 'scanning' => __( 'Scanning...', 'vigilante' ),
1829 'scanComplete' => __( 'Scan complete', 'vigilante' ),
1830 'loading' => __( 'Loading...', 'vigilante' ),
1831 'searching' => __( 'Searching...', 'vigilante' ),
1832 'noUsersFound' => __( 'No users found', 'vigilante' ),
1833 'sending' => __( 'Sending...', 'vigilante' ),
1834 'sendNotification' => __( 'Send notification now', 'vigilante' ),
1835 'notificationsSent' => __( 'notifications sent', 'vigilante' ),
1836 'skipped' => __( 'skipped', 'vigilante' ),
1837 'failed' => __( 'failed', 'vigilante' ),
1838 'customConfig' => __( 'Custom Configuration', 'vigilante' ),
1839 // Header tester strings
1840 'testHeaders' => __( 'Test Headers', 'vigilante' ),
1841 'testing' => __( 'Testing...', 'vigilante' ),
1842 'score' => __( 'Score', 'vigilante' ),
1843 'enabledHeaders' => __( 'Enabled headers', 'vigilante' ),
1844 'missingHeaders' => __( 'Missing headers', 'vigilante' ),
1845 'warnings' => __( 'Warnings', 'vigilante' ),
1846 // File integrity scan results strings
1847 'scanResults' => __( 'Scan Results', 'vigilante' ),
1848 'ok' => __( 'OK', 'vigilante' ),
1849 'modified' => __( 'Modified', 'vigilante' ),
1850 'suspicious' => __( 'Suspicious', 'vigilante' ),
1851 'totalScanned' => __( 'Total Scanned', 'vigilante' ),
1852 'suspiciousFiles' => __( 'Suspicious Files', 'vigilante' ),
1853 'suspiciousWarning' => __( 'Files that can run code where none is expected, or that contain code written the way malware hides itself. Real infections show up here, and so do harmless files that plugins generate. Check the path and the reason before acting.', 'vigilante' ),
1854 'file' => __( 'File', 'vigilante' ),
1855 'reason' => __( 'Reason', 'vigilante' ),
1856 'type' => __( 'Type', 'vigilante' ),
1857 'unknown' => __( 'Unknown', 'vigilante' ),
1858 'selfType' => __( 'Vigilant (self)', 'vigilante' ),
1859 'logWhatHappened' => __( 'What happened', 'vigilante' ),
1860 'logWhatItMeans' => __( 'What it means', 'vigilante' ),
1861 'logWhatToDo' => __( 'What to do', 'vigilante' ),
1862 'logSelfSeeDetails' => __( 'Open File Integrity for the full detail', 'vigilante' ),
1863 'modifiedFiles' => __( 'Modified Files', 'vigilante' ),
1864 'modifiedDescription' => __( 'These files do not match the copy WordPress.org publishes for the installed version.', 'vigilante' ),
1865 'extraFiles' => __( 'Extra Files', 'vigilante' ),
1866 'extra' => __( 'Extra', 'vigilante' ),
1867 'ignored' => __( 'Ignored', 'vigilante' ),
1868 'extraDescription' => __( 'Files that are not part of WordPress, or of the plugin or theme they sit in. Many are legitimate, and an injected file looks the same from here, so confirm where each one comes from.', 'vigilante' ),
1869 'actions' => __( 'Actions', 'vigilante' ),
1870 'ignore' => __( 'Ignore', 'vigilante' ),
1871 'ignoring' => __( 'Ignoring...', 'vigilante' ),
1872 'fileIgnored' => __( 'File added to ignored list.', 'vigilante' ),
1873 'fileUnignored' => __( 'File removed from ignored list.', 'vigilante' ),
1874 'confirmClearIgnored' => __( 'Remove all files from the ignored list? They will appear in scan results again.', 'vigilante' ),
1875 'ignoredCleared' => __( 'Ignored files list cleared. Page will reload...', 'vigilante' ),
1876 'selectAll' => __( 'Select all', 'vigilante' ),
1877 'bulkIgnoreSelected' => __( 'Ignore selected', 'vigilante' ),
1878 'bulkNoSelection' => __( 'Select at least one file first.', 'vigilante' ),
1879 'bulkConfirmIgnore' => __( 'Ignore the selected files? They will be hidden from future scan results until you remove them from the ignored list.', 'vigilante' ),
1880 'bulkConfirmUnignore' => __( 'Remove the selected files from the ignored list? They will appear in scan results again.', 'vigilante' ),
1881 'bulkProcessing' => __( 'Processing...', 'vigilante' ),
1882 /* translators: %d: number of files selected for bulk action. */
1883 'bulkSelectedCount' => __( '%d selected', 'vigilante' ),
1884 'allClear' => __( 'Good job! Nothing to report in the files that were checked.', 'vigilante' ),
1885 'criticalConfigTitle' => __( 'Critical config files modified', 'vigilante' ),
1886 'criticalConfigDesc' => __( 'These files changed since you last approved them. They are a common target for code injection, and they are also rewritten by cache, security and redirection plugins, often on every update. Review the changes and approve them if they belong to something you use: approving records the current content as the reference and does not touch the file. Vigilant\'s own blocks are excluded from this check, and Vigilant never restores these files by itself.', 'vigilante' ),
1887 'approve' => __( 'Approve', 'vigilante' ),
1888 'approving' => __( 'Approving...', 'vigilante' ),
1889 'approvalLockedNotice' => $this->critical_approval_notice(),
1890 'criticalApproved' => __( 'Change approved. Next scan will use the current state as baseline.', 'vigilante' ),
1891 'reviewChanges' => __( 'Review changes', 'vigilante' ),
1892 'hideChanges' => __( 'Hide changes', 'vigilante' ),
1893 'changes' => __( 'Changes', 'vigilante' ),
1894 'diffUnavailable' => __( 'Diff not available for this file (baseline was created before diff tracking was added). Approve to enable diff on future changes.', 'vigilante' ),
1895 'diffNetwork' => __( 'This file belongs to the whole network, so its line changes are only shown to network administrators, on the main site.', 'vigilante' ),
1896 'diffRescan' => __( 'Run a new scan to see the line changes of this file.', 'vigilante' ),
1897 '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' ),
1898 'diffEmpty' => __( 'No line-level changes detected (may be whitespace or reordering).', 'vigilante' ),
1899 'diffLines' => __( 'lines', 'vigilante' ),
1900 // Under Attack mode strings
1901 'underAttackConfirmActivate' => __( 'Activate Under Attack mode? All visitors will see a verification page for the next 4 hours.', 'vigilante' ),
1902 'underAttackConfirmDeactivate' => __( 'Deactivate Under Attack mode?', 'vigilante' ),
1903 'underAttackActivating' => __( 'Activating...', 'vigilante' ),
1904 'underAttackDeactivating' => __( 'Deactivating...', 'vigilante' ),
1905 // Database backup strings
1906 'dbBackupDownloading' => __( 'Generating backup...', 'vigilante' ),
1907 'dbBackupNoTables' => __( 'Please select at least one table.', 'vigilante' ),
1908 'dbBackupSuccess' => __( 'Database backup downloaded successfully.', 'vigilante' ),
1909 // Firewall unblock
1910 'confirmUnblockIp' => __( 'Unblock this IP from firewall rate limiting?', 'vigilante' ),
1911 // Database prefix strings
1912 'dbPrefixConfirm' => __( 'This operation will change your database prefix. It is irreversible. Make sure you have a current database backup before proceeding.', 'vigilante' ),
1913 'dbPrefixChanging' => __( 'Changing prefix...', 'vigilante' ),
1914 'dbPrefixSuccess' => __( 'Database prefix changed successfully. The page will reload now.', 'vigilante' ),
1915 'dbPrefixCheckbox' => __( 'You must confirm that you have a database backup.', 'vigilante' ),
1916 /* translators: 1: Hours, 2: Minutes */
1917 'underAttackRemaining' => __( '%1$dh %2$dm remaining', 'vigilante' ),
1918 'underAttackLabel' => __( 'Under Attack', 'vigilante' ),
1919 'standardLabel' => __( 'Standard', 'vigilante' ),
1920 'maximumLabel' => __( 'Maximum Security', 'vigilante' ),
1921 'deactivate' => __( 'Deactivate', 'vigilante' ),
1922 'underAttackActivate' => __( 'Activate for 4 hours', 'vigilante' ),
1923 // Settings strings
1924 'saveSettings' => __( 'Save Settings', 'vigilante' ),
1925 'settingsResetDefaults' => __( 'Settings reset to defaults.', 'vigilante' ),
1926 'confirmOverwrite' => __( 'This will overwrite your current settings.', 'vigilante' ),
1927 'importFailed' => __( 'Could not import settings. Check the file and try again.', 'vigilante' ),
1928 /* translators: 1: tests passed, 2: total tests in this category */
1929 'testsCounter' => __( '%1$d/%2$d tests', 'vigilante' ),
1930 'confirmResetAll' => __( 'This will reset ALL settings to defaults.', 'vigilante' ),
1931 'couldNotDetermineSection' => __( 'Could not determine section.', 'vigilante' ),
1932 'confirmResetSection' => __( 'Reset this section to default values? This cannot be undone.', 'vigilante' ),
1933 'sectionResetDefaults' => __( 'Section reset to defaults.', 'vigilante' ),
1934 /* translators: %s: preset name */
1935 'confirmApplyPreset' => __( 'Apply the "%s" preset?', 'vigilante' ),
1936 // Scan strings
1937 'scanFailed' => __( 'Scan failed', 'vigilante' ),
1938 /* translators: %s: error message */
1939 'scanError' => __( 'Scan error: %s', 'vigilante' ),
1940 'runScanNow' => __( 'Run Scan Now', 'vigilante' ),
1941 'confirmClearScan' => __( 'Are you sure you want to clear all scan results?', 'vigilante' ),
1942 'clearing' => __( 'Clearing...', 'vigilante' ),
1943 'scanResultsCleared' => __( 'Scan results cleared. Page will reload...', 'vigilante' ),
1944 'failedClearResults' => __( 'Failed to clear results', 'vigilante' ),
1945 /* translators: %s: error message */
1946 'ajaxError' => __( 'AJAX Error: %s', 'vigilante' ),
1947 // Activity log popup strings
1948 'logRequest' => __( 'Request', 'vigilante' ),
1949 'logDate' => __( 'Date', 'vigilante' ),
1950 'logMethod' => __( 'Method', 'vigilante' ),
1951 'logType' => __( 'Type', 'vigilante' ),
1952 'logAction' => __( 'Action', 'vigilante' ),
1953 'logSeverity' => __( 'Severity', 'vigilante' ),
1954 'logMessage' => __( 'Message', 'vigilante' ),
1955 'logRequestUri' => __( 'Address', 'vigilante' ),
1956 'logClient' => __( 'Client', 'vigilante' ),
1957 'logUser' => __( 'User', 'vigilante' ),
1958 'logIpAddress' => __( 'IP Address', 'vigilante' ),
1959 'logUserAgent' => __( 'User Agent', 'vigilante' ),
1960 'logIpLabel' => __( 'IP:', 'vigilante' ),
1961 'logUaLabel' => __( 'UA:', 'vigilante' ),
1962 'logWhitelist' => __( 'Whitelist', 'vigilante' ),
1963 'logBlacklist' => __( 'Blacklist', 'vigilante' ),
1964 'logInWhitelist' => __( 'In whitelist', 'vigilante' ),
1965 'logInBlacklist' => __( 'In blacklist', 'vigilante' ),
1966 'logAdded' => __( 'Added!', 'vigilante' ),
1967 'logErrorAddingToList' => __( 'Error adding to list', 'vigilante' ),
1968 'logRequestFailed' => __( 'Request failed', 'vigilante' ),
1969 // Activity log table strings
1970 'noLogEntries' => __( 'No log entries found.', 'vigilante' ),
1971 'view' => __( 'View', 'vigilante' ),
1972 'confirmClearLogs' => __( 'This will delete all audit logs.', 'vigilante' ),
1973 // Export logs strings
1974 'exporting' => __( 'Exporting...', 'vigilante' ),
1975 /* translators: %d: number of entries */
1976 'logsExported' => __( 'Logs exported (%d entries)', 'vigilante' ),
1977 'noLogsToExport' => __( 'No logs to export', 'vigilante' ),
1978 'exportFailed' => __( 'Export failed', 'vigilante' ),
1979 'exportLogs' => __( 'Export Logs', 'vigilante' ),
1980 // Backup strings
1981 'createBackupNow' => __( 'Download Backup', 'vigilante' ),
1982 'downloadBackup' => __( 'Download Backup (.zip)', 'vigilante' ),
1983 /* translators: 1: table count, 2: human-readable size */
1984 'dbTablesTotal' => __( '%1$d tables total (%2$s)', 'vigilante' ),
1985 /* translators: 1: selected count, 2: human-readable size */
1986 'dbTablesSelected' => __( '%1$d tables selected (%2$s)', 'vigilante' ),
1987 // Settings search strings
1988 'searchNoResults' => __( 'No matching settings found.', 'vigilante' ),
1989 /* translators: %d: number of results that did not fit in the list. */
1990 'searchMoreResults' => __( '%d more results. Refine the search to see them.', 'vigilante' ),
1991 // Modules string
1992 /* translators: 1: enabled count, 2: total count */
1993 'modulesEnabled' => __( '%1$d / %2$d modules enabled', 'vigilante' ),
1994 // Activity log label maps for JS rendering
1995 'eventTypeLabels' => array(
1996 'login' => __( 'Login', 'vigilante' ),
1997 '2fa' => __( 'Two-factor', 'vigilante' ),
1998 'user' => __( 'User', 'vigilante' ),
1999 'content' => __( 'Content', 'vigilante' ),
2000 'plugin' => __( 'Plugin', 'vigilante' ),
2001 'theme' => __( 'Theme', 'vigilante' ),
2002 'settings' => __( 'Settings', 'vigilante' ),
2003 'comment' => __( 'Comment', 'vigilante' ),
2004 'media' => __( 'Media', 'vigilante' ),
2005 'firewall' => __( 'Firewall', 'vigilante' ),
2006 'file' => __( 'File', 'vigilante' ),
2007 'security' => __( 'Security', 'vigilante' ),
2008 'system' => __( 'System', 'vigilante' ),
2009 ),
2010 'severityLabels' => array(
2011 'info' => __( 'Info', 'vigilante' ),
2012 'warning' => __( 'Warning', 'vigilante' ),
2013 'critical' => __( 'Critical', 'vigilante' ),
2014 ),
2015 // Password reset strings
2016 'noUsersFoundSearch' => __( 'No users found', 'vigilante' ),
2017 /* translators: %d: number of users */
2018 'confirmForceReset' => __( 'Force password reset for %d user(s)? A password reset email will be sent to each user.', 'vigilante' ),
2019 'warningResettingSelf' => __( 'WARNING: You are including yourself. Your session will end and you will need to set a new password.', 'vigilante' ),
2020 'processing' => __( 'Processing...', 'vigilante' ),
2021 'anErrorOccurred' => __( 'An error occurred', 'vigilante' ),
2022 'forceResetSelected' => __( 'Force Reset for Selected Users', 'vigilante' ),
2023 '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' ),
2024 'warningResettingSelfAll' => __( 'WARNING: You are including yourself. Your session will end immediately.', 'vigilante' ),
2025 'forceResetAll' => __( 'Force Reset for ALL Users', 'vigilante' ),
2026 // Role-based password reset strings
2027 /* translators: %d: number of users */
2028 'confirmForceResetByRole' => __( 'Force password reset for %d user(s) with the selected roles? A password reset email will be sent to each user.', 'vigilante' ),
2029 'noRolesSelected' => __( 'Please select at least one role.', 'vigilante' ),
2030 'forceResetByRole' => __( 'Force Reset for Selected Roles', 'vigilante' ),
2031 // User approval strings
2032 'confirmApprove' => __( 'Approve this user?', 'vigilante' ),
2033 'approve' => __( 'Approve', 'vigilante' ),
2034 'rejectReason' => __( 'Enter rejection reason (optional):', 'vigilante' ),
2035 'reject' => __( 'Reject', 'vigilante' ),
2036 'noPending' => __( 'No pending registrations.', 'vigilante' ),
2037 // Session management strings
2038 'confirmRevoke' => __( 'Revoke this session?', 'vigilante' ),
2039 'confirmRevokeAll' => __( 'Revoke all other sessions?', 'vigilante' ),
2040 'revokeOthers' => __( 'Revoke All Other Sessions', 'vigilante' ),
2041 'confirmRevokeAllUser' => __( 'Revoke ALL sessions for this user? They will be logged out everywhere.', 'vigilante' ),
2042 'sessionsFor' => __( 'Sessions for:', 'vigilante' ),
2043 'noSessions' => __( 'No active sessions', 'vigilante' ),
2044 'revoke' => __( 'Revoke', 'vigilante' ),
2045 'noUsers' => __( 'No users found', 'vigilante' ),
2046 // Time ago strings
2047 'timeYear' => __( 'year', 'vigilante' ),
2048 'timeYears' => __( 'years', 'vigilante' ),
2049 'timeMonth' => __( 'month', 'vigilante' ),
2050 'timeMonths' => __( 'months', 'vigilante' ),
2051 'timeDay' => __( 'day', 'vigilante' ),
2052 'timeDays' => __( 'days', 'vigilante' ),
2053 'timeHour' => __( 'hour', 'vigilante' ),
2054 'timeHours' => __( 'hours', 'vigilante' ),
2055 'timeMinute' => __( 'minute', 'vigilante' ),
2056 'timeMinutes' => __( 'minutes', 'vigilante' ),
2057 /* translators: %1$d: count, %2$s: time unit */
2058 'timeAgo' => __( '%1$d %2$s ago', 'vigilante' ),
2059 'justNow' => __( 'Just now', 'vigilante' ),
2060 // Pagination strings
2061 /* translators: 1: first item number, 2: last item number, 3: total items */
2062 'paginationOf' => __( '%1$d–%2$d of %3$d', 'vigilante' ),
2063 'paginationEmpty' => __( '0 items', 'vigilante' ),
2064 // Security Analyzer strings
2065 'analyzerFastPhase' => __( 'Running fast checks…', 'vigilante' ),
2066 'analyzerSlowPhase' => __( 'Running remote checks…', 'vigilante' ),
2067 'analyzerScanComplete' => __( 'Security scan complete.', 'vigilante' ),
2068 'analyzerScanFailed' => __( 'Security scan failed.', 'vigilante' ),
2069 'analyzerShowDetails' => __( 'Show detailed breakdown', 'vigilante' ),
2070 'analyzerHideDetails' => __( 'Hide detailed breakdown', 'vigilante' ),
2071 'analyzerGoToSetting' => __( 'Go to setting', 'vigilante' ),
2072 'analyzerSettingsSaved' => __( 'Analyzer settings saved.', 'vigilante' ),
2073 'analyzerLastScanJustNow' => __( 'Last scan just now', 'vigilante' ),
2074 'analyzerQualityExcellent' => __( 'Excellent', 'vigilante' ),
2075 'analyzerQualityGood' => __( 'Good', 'vigilante' ),
2076 'analyzerQualityFair' => __( 'Fair', 'vigilante' ),
2077 'analyzerQualityPoor' => __( 'Poor', 'vigilante' ),
2078 'analyzerQualityCritical' => __( 'Critical', 'vigilante' ),
2079 'analyzerLearnMore' => __( 'Learn more', 'vigilante' ),
2080 'analyzerInfoAllClear' => __( 'All clear', 'vigilante' ),
2081 /* translators: %d: number of findings in an info-only category */
2082 'analyzerInfoFindings' => __( '%d findings', 'vigilante' ),
2083 ),
2084 ) );
2085
2086 // 2FA Admin assets
2087 wp_enqueue_style(
2088 'vigilante-2fa-admin',
2089 VIGILANTE_ASSETS_URL . 'css/two-factor-admin.css',
2090 array( 'vigilante-admin' ),
2091 VIGILANTE_VERSION
2092 );
2093
2094 wp_enqueue_script(
2095 'vigilante-2fa-admin',
2096 VIGILANTE_ASSETS_URL . 'js/two-factor-admin.js',
2097 array( 'jquery', 'vigilante-admin' ),
2098 VIGILANTE_VERSION,
2099 true
2100 );
2101 }
2102
2103 /**
2104 * Show admin notices
2105 */
2106 /**
2107 * Self-protection notice.
2108 *
2109 * A change to Vigilant own files is shown on every admin screen, because
2110 * waiting for someone to open the plugin is exactly what an attacker who
2111 * patched it would want. A warning is shown only on Vigilant screens, so
2112 * the notice that matters is not diluted. Neither is dismissible, both are
2113 * for administrators only, and on a network the steps depend on whether
2114 * the person can install plugins at all.
2115 */
2116 public function maybe_show_self_protection_notice() {
2117 if ( ! current_user_can( 'manage_options' ) ) {
2118 return;
2119 }
2120 $summary = $this->self_integrity_summary();
2121 $tone = $summary['tone'];
2122 if ( ! in_array( $tone, array( 'critical', 'off', 'warning' ), true ) ) {
2123 return;
2124 }
2125
2126 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading the screen slug to decide where a notice is shown; no action taken.
2127 $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : '';
2128 $on_vigilante = ( 0 === strpos( $page, 'vigilante' ) );
2129 if ( 'warning' === $tone && ! $on_vigilante ) {
2130 return;
2131 }
2132 $alarma = in_array( $tone, array( 'critical', 'off' ), true );
2133
2134 $link = admin_url( 'admin.php?page=vigilante&tab=file-integrity#vigilante-section-fi-self' );
2135 $network = is_multisite() && ! current_user_can( 'update_plugins' );
2136 ?>
2137 <div class="notice notice-<?php echo $alarma ? 'error' : 'warning'; ?> vigilante-self-notice">
2138 <p class="vigilante-self-notice-title">
2139 <span class="dashicons dashicons-shield" aria-hidden="true"></span>
2140 <strong>
2141 <?php
2142 if ( 'critical' === $tone ) {
2143 esc_html_e( 'Vigilant detected changes in its own files', 'vigilante' );
2144 } elseif ( 'off' === $tone ) {
2145 esc_html_e( 'Vigilant self-protection is switched off by code', 'vigilante' );
2146 } else {
2147 echo esc_html( $this->self_integrity_headline( $tone, $summary['state'] ) );
2148 }
2149 ?>
2150 </strong>
2151 </p>
2152 <p class="vigilante-self-notice-text">
2153 <span>
2154 <?php
2155 if ( 'critical' === $tone ) {
2156 esc_html_e( 'Your security plugin may have been tampered with, and while that is true nothing it reports can be trusted.', 'vigilante' );
2157 } elseif ( 'off' === $tone ) {
2158 esc_html_e( 'Nothing is checking that Vigilant own files are intact. File Integrity says which file switches it off.', 'vigilante' );
2159 } else {
2160 esc_html_e( 'File Integrity says what was found, what it means and what to do about it.', 'vigilante' );
2161 }
2162 if ( $network ) {
2163 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' );
2164 }
2165 ?>
2166 </span>
2167 <?php
2168 /*
2169 * One button, on the same line as the text it belongs to, and it
2170 * leads to the whole story. Repairing from a notice, without
2171 * seeing which files, what it means and what it will do, is
2172 * asking someone to fix what they have not read: the repair
2173 * button lives in the card, after all that.
2174 */
2175 ?>
2176 <a class="button button-primary button-small" href="<?php echo esc_url( $link ); ?>">
2177 <?php esc_html_e( 'See what to do', 'vigilante' ); ?>
2178 </a>
2179 </p>
2180 </div>
2181 <?php
2182 }
2183
2184 public function show_admin_notices() {
2185 $this->maybe_show_self_protection_notice();
2186
2187 // Activation notice
2188 if ( get_transient( 'vigilante_activated' ) ) {
2189 ?>
2190 <div class="notice notice-success is-dismissible vigilante-activation-notice">
2191 <p>
2192 <span class="dashicons dashicons-shield vigilante-notice-icon"></span>
2193 <strong><?php esc_html_e( 'Vigilant activated successfully!', 'vigilante' ); ?></strong>
2194 <?php esc_html_e( 'Security protection is now active.', 'vigilante' ); ?>
2195 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante' ) ); ?>">
2196 <?php esc_html_e( 'Configure settings', 'vigilante' ); ?>
2197 </a>
2198 </p>
2199 </div>
2200 <?php
2201 delete_transient( 'vigilante_activated' );
2202 }
2203
2204 // Under Attack mode notice (non-dismissible, shown on all admin pages)
2205 $ua_status = get_option( Vigilante_Under_Attack::OPTION_NAME, array() );
2206 if ( ! empty( $ua_status['active'] ) ) {
2207 $ua_remaining = ( $ua_status['activated_at'] + $ua_status['duration'] ) - time();
2208 if ( $ua_remaining > 0 ) {
2209 $ua_hours = floor( $ua_remaining / 3600 );
2210 $ua_mins = floor( ( $ua_remaining % 3600 ) / 60 );
2211 $dashboard_url = admin_url( 'admin.php?page=vigilante' );
2212 ?>
2213 <div class="notice notice-warning vigilante-ua-notice">
2214 <p>
2215 <span class="dashicons dashicons-shield"></span>
2216 <strong><?php esc_html_e( 'Under Attack mode is active', 'vigilante' ); ?></strong>
2217 &mdash;
2218 <?php
2219 printf(
2220 /* translators: 1: Hours, 2: Minutes */
2221 esc_html__( '%1$dh %2$dm remaining.', 'vigilante' ),
2222 absint( $ua_hours ),
2223 absint( $ua_mins )
2224 );
2225 ?>
2226 <a href="<?php echo esc_url( $dashboard_url ); ?>">
2227 <?php esc_html_e( 'Go to Vigilant dashboard', 'vigilante' ); ?>
2228 </a>
2229 </p>
2230 <p>
2231 <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>
2232 </p>
2233 <?php
2234 // The cache-bypass rules could not be written (a host where
2235 // WordPress cannot write files by itself, a held lock, a
2236 // failed read-back): show them, so they can be added by hand.
2237 $ua_instance = new Vigilante_Under_Attack( $this->settings, $this->activity_log );
2238 if ( $ua_instance->cache_rules_missing() ) :
2239 ?>
2240 <p>
2241 <strong><?php esc_html_e( 'The cache-bypass rules could not be written to your .htaccess.', 'vigilante' ); ?></strong>
2242 <?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' ); ?>
2243 </p>
2244 <textarea readonly rows="9" class="large-text code" onclick="this.select();"><?php echo esc_textarea( Vigilante_Under_Attack::get_cache_bypass_block() ); ?></textarea>
2245 <?php endif; ?>
2246 </div>
2247 <?php
2248 }
2249 }
2250
2251 // Proxy/CDN detection: if IP detection is set to "direct" but requests
2252 // arrive with a forwarded-for header carrying a different valid IP, the
2253 // site is very likely behind a proxy/CDN that has not been declared, so
2254 // the firewall is seeing the proxy IP for every visitor. Guide the admin.
2255 //
2256 // Two deliberate silencers (2.9.2):
2257 // - A loopback forwarded IP (::1 / 127.x) means the person browsing IS
2258 // the machine itself: that only happens in local development stacks
2259 // (Local's nginx router, Docker...), never behind a production
2260 // proxy/CDN, so the notice would be pure noise there.
2261 // - The notice is dismissible and the dismissal persists site-wide via
2262 // the vigilante_dismissed_notices option (the admin evaluated it and
2263 // decided; nagging forever helps nobody).
2264 $dismissed_notices = get_option( 'vigilante_dismissed_notices', array() );
2265 if (
2266 current_user_can( 'manage_options' )
2267 && '' === Vigilante_IP_Utils::trusted_proxy_header()
2268 && ! isset( $dismissed_notices['proxy_detection'] )
2269 ) {
2270 $remote = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '';
2271 $detected = '';
2272 foreach ( Vigilante_IP_Utils::trusted_header_map() as $proxy_label => $server_key ) {
2273 if ( empty( $_SERVER[ $server_key ] ) ) {
2274 continue;
2275 }
2276 $candidate = sanitize_text_field( wp_unslash( $_SERVER[ $server_key ] ) );
2277 if ( false !== strpos( $candidate, ',' ) ) {
2278 $parts = explode( ',', $candidate );
2279 $candidate = trim( $parts[0] );
2280 }
2281 if ( ! filter_var( $candidate, FILTER_VALIDATE_IP ) || $candidate === $remote ) {
2282 continue;
2283 }
2284 // Loopback forwarded IP = local development, not a real proxy.
2285 if ( '::1' === $candidate || 0 === strpos( $candidate, '127.' ) ) {
2286 continue;
2287 }
2288 $detected = $proxy_label;
2289 break;
2290 }
2291
2292 if ( '' !== $detected ) {
2293 $firewall_url = admin_url( 'admin.php?page=vigilante&tab=firewall' );
2294 $detail_message = sprintf(
2295 /* translators: %s: detected forwarded header name wrapped in a code tag. */
2296 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' ),
2297 '<code>' . esc_html( strtoupper( $detected ) ) . '</code>'
2298 );
2299 ?>
2300 <div class="notice notice-warning is-dismissible vigilante-proxy-notice">
2301 <p>
2302 <span class="dashicons dashicons-shield"></span>
2303 <strong><?php esc_html_e( 'Vigilant: this site looks like it is behind a proxy or CDN', 'vigilante' ); ?></strong>
2304 </p>
2305 <p><?php echo wp_kses_post( $detail_message ); ?></p>
2306 <p>
2307 <a href="<?php echo esc_url( $firewall_url ); ?>" class="button button-secondary">
2308 <?php esc_html_e( 'Set your proxy in Firewall settings', 'vigilante' ); ?>
2309 </a>
2310 </p>
2311 </div>
2312 <script>
2313 jQuery( function ( $ ) {
2314 $( document ).on( 'click', '.vigilante-proxy-notice .notice-dismiss', function () {
2315 $.post( ajaxurl, {
2316 action: 'vigilante_dismiss_notice',
2317 notice_id: 'proxy_detection',
2318 nonce: <?php echo wp_json_encode( wp_create_nonce( 'vigilante_dismiss_notice' ) ); ?>
2319 } );
2320 } );
2321 } );
2322 </script>
2323 <?php
2324 }
2325 }
2326 }
2327
2328 /**
2329 * Render settings page
2330 */
2331 public function render_settings_page() {
2332 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
2333 $this->current_tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'dashboard';
2334
2335 if ( ! array_key_exists( $this->current_tab, $this->tabs ) ) {
2336 $this->current_tab = 'dashboard';
2337 }
2338 ?>
2339 <div class="wrap vigilante-admin-wrap">
2340 <div class="vigilante-header-row">
2341 <h1 class="vigilante-page-title">
2342 <img src="<?php echo esc_url( VIGILANTE_ASSETS_URL . 'images/icon.png' ); ?>" alt="Vigilante" class="vigilante-title-icon">
2343 <?php esc_html_e( 'Vigilant', 'vigilante' ); ?>
2344 <span class="vigilante-version">v<?php echo esc_html( VIGILANTE_VERSION ); ?></span>
2345 </h1>
2346 <div class="vigilante-search-wrapper">
2347 <div class="vigilante-search-input-wrap">
2348 <span class="vigilante-search-icon dashicons dashicons-search" aria-hidden="true"></span>
2349 <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">
2350 <span class="vigilante-search-shortcut" aria-hidden="true">/</span>
2351 </div>
2352 <div id="vigilante-settings-search-results" class="vigilante-search-results" hidden role="listbox"></div>
2353 </div>
2354 </div>
2355
2356 <?php $this->render_tabs(); ?>
2357
2358 <div class="vigilante-content">
2359 <div class="vigilante-main">
2360 <?php $this->render_tab_content(); ?>
2361 </div>
2362 <div class="vigilante-sidebar">
2363 <?php $this->render_sidebar(); ?>
2364 </div>
2365 </div>
2366 </div>
2367 <?php
2368 }
2369
2370 /**
2371 * Render tabs navigation
2372 */
2373 private function render_tabs() {
2374 $options = $this->settings->get_all_options();
2375
2376 // Map tabs to modules
2377 $tab_to_module = array(
2378 'firewall' => 'firewall',
2379 'headers' => 'security_headers',
2380 'login' => 'login_security',
2381 'rest-api' => 'rest_api_security',
2382 'users' => 'user_security',
2383 'wp-hardening' => 'wp_hardening',
2384 'file-integrity' => 'file_integrity',
2385 'activity-log' => 'activity_log',
2386 );
2387 ?>
2388 <nav class="nav-tab-wrapper vigilante-nav-tabs">
2389 <?php foreach ( $this->tabs as $tab_id => $tab_name ) :
2390 $is_disabled = false;
2391 $module = isset( $tab_to_module[ $tab_id ] ) ? $tab_to_module[ $tab_id ] : null;
2392 if ( $module && empty( $options['modules'][ $module ] ) ) {
2393 $is_disabled = true;
2394 }
2395 ?>
2396 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=' . $tab_id ) ); ?>"
2397 class="nav-tab <?php echo $this->current_tab === $tab_id ? 'nav-tab-active' : ''; ?> <?php echo $is_disabled ? 'vigilante-tab-disabled' : ''; ?>"
2398 <?php if ( $is_disabled ) : ?>title="<?php esc_attr_e( 'Module Disabled', 'vigilante' ); ?>"<?php endif; ?>>
2399 <?php echo esc_html( $tab_name ); ?>
2400 <?php if ( $is_disabled ) : ?><span class="vigilante-tab-off">OFF</span><?php endif; ?>
2401 </a>
2402 <?php endforeach; ?>
2403 </nav>
2404 <?php
2405 }
2406
2407 /**
2408 * Render current tab content
2409 */
2410 private function render_tab_content() {
2411 $method = 'render_tab_' . str_replace( '-', '_', $this->current_tab );
2412
2413 if ( method_exists( $this, $method ) ) {
2414 $this->$method();
2415 } else {
2416 $this->render_tab_coming_soon();
2417 }
2418 }
2419
2420 /**
2421 * Render coming soon placeholder
2422 */
2423 private function render_tab_coming_soon() {
2424 ?>
2425 <div class="vigilante-settings-section">
2426 <h2><?php esc_html_e( 'Coming Soon', 'vigilante' ); ?></h2>
2427 <p><?php esc_html_e( 'This section is under development.', 'vigilante' ); ?></p>
2428 </div>
2429 <?php
2430 }
2431
2432 /**
2433 * Values to display for a section that this site does not control
2434 *
2435 * On a subsite the stored options are its own copy, which nothing acts on:
2436 * wp-config.php and .htaccess are written from the main site. Painting the
2437 * local copy describes a configuration that is not running, so a subsite
2438 * admin sees a box ticked here and the constant absent from the file, or the
2439 * other way round. Read the main site's values instead, which are the ones in
2440 * force, and fall back to the local ones if they cannot be read.
2441 *
2442 * @since 2.9.8
2443 *
2444 * @param string $section Settings section.
2445 * @return array
2446 */
2447 private function get_section_for_display( $section ) {
2448 $local = $this->settings->get_section( $section );
2449
2450 if ( ! $this->shared_files_locked() ) {
2451 return $local;
2452 }
2453
2454 // shared_files_locked() is only true on multisite, where get_blog_option() exists.
2455 $main = get_blog_option( get_main_site_id(), Vigilante_Settings::OPTION_NAME, array() );
2456
2457 if ( ! is_array( $main ) || empty( $main[ $section ] ) || ! is_array( $main[ $section ] ) ) {
2458 return $local;
2459 }
2460
2461 return wp_parse_args( $main[ $section ], $local );
2462 }
2463
2464 /**
2465 * Whether the sections that write wp-config.php and .htaccess are read-only here
2466 *
2467 * True on a network when this is not the main site, or the user is not a
2468 * network administrator. See Vigilante_Settings::can_write_shared_files().
2469 *
2470 * @since 2.9.8
2471 *
2472 * @return bool
2473 */
2474 private function shared_files_locked() {
2475 return ! Vigilante_Settings::can_write_shared_files();
2476 }
2477
2478 /**
2479 * Whether this is the main site and the user cannot change what it builds the shared files from
2480 *
2481 * See Vigilante_Settings::get_main_site_file_settings(). On a subsite those
2482 * settings only act on that site, so they are never locked there.
2483 *
2484 * @since 2.11.6
2485 *
2486 * @return bool
2487 */
2488 private function main_site_files_locked() {
2489 return $this->shared_files_locked() && Vigilante_Settings::owns_shared_files();
2490 }
2491
2492 /**
2493 * Sentence added to a bulk change when some settings were left as they were
2494 *
2495 * Importing a file, applying a preset and restoring the defaults touch every
2496 * section at once, so the user is told that the shared file settings did
2497 * not move.
2498 *
2499 * @since 2.11.6
2500 *
2501 * @return string Empty when the user can change every setting.
2502 */
2503 private function locked_file_settings_message() {
2504 if ( ! Vigilante_Settings::get_locked_file_settings() ) {
2505 return '';
2506 }
2507
2508 return ' ' . __( 'The settings that end up in wp-config.php or .htaccess were left as they were.', 'vigilante' ) . ' ' . Vigilante_Settings::get_shared_files_notice();
2509 }
2510
2511 /**
2512 * Print the shared-files notice for a section that cannot be edited here
2513 *
2514 * @since 2.9.8
2515 */
2516 private function render_shared_files_notice() {
2517 if ( ! $this->shared_files_locked() ) {
2518 return;
2519 }
2520 ?>
2521 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
2522 <p style="margin:0;"><?php echo esc_html( Vigilante_Settings::get_shared_files_notice() ); ?></p>
2523 </div>
2524 <?php
2525 }
2526
2527 /**
2528 * Acting on another user's account needs permission over that user
2529 *
2530 * Since 2.10.3 the handlers behind these tools ask for edit_user over the
2531 * target, which is the rule WordPress itself applies. On a network the core
2532 * grants edit_user only to network administrators, so for anybody else these
2533 * controls do nothing. Better to say so than to paint a button that silently
2534 * skips every user.
2535 *
2536 * @since 2.10.4
2537 * @return bool
2538 */
2539 private function forwarded_chain_readings() {
2540 // Shown, not decided on: the firewall resolves the address elsewhere.
2541 $chain = Vigilante_IP_Utils::trusted_forwarded_for();
2542
2543 if ( '' === $chain ) {
2544 return array();
2545 }
2546
2547 $public = array();
2548
2549 foreach ( explode( ',', $chain ) as $entry ) {
2550 $address = Vigilante_IP_Utils::unmap_ipv4( trim( $entry ) );
2551
2552 if ( filter_var( $address, FILTER_VALIDATE_IP ) && ! Vigilante_IP_Utils::is_own_network( $address ) ) {
2553 $public[] = $address;
2554 }
2555 }
2556
2557 if ( count( $public ) < 2 ) {
2558 return array();
2559 }
2560
2561 return array(
2562 'now' => Vigilante_IP_Utils::client_from_chain( $chain ),
2563 'before' => $public[0],
2564 );
2565 }
2566
2567 /**
2568 * Whether the user tools of this screen are out of reach for this user
2569 *
2570 * @return bool
2571 */
2572 private function user_actions_locked() {
2573 // On a single site edit_user maps to edit_users, which a custom role with
2574 // manage_options may lack: since 2.11.8 approving and rejecting a pending
2575 // registration ask for it, so the buttons have to say so there too.
2576 return is_multisite() ? ! current_user_can( 'manage_network_users' ) : ! current_user_can( 'edit_users' );
2577 }
2578
2579 /**
2580 * Print the notice for user tools that cannot be used from this site
2581 *
2582 * @since 2.10.4
2583 */
2584 private function render_user_actions_notice() {
2585 if ( ! $this->user_actions_locked() ) {
2586 return;
2587 }
2588 ?>
2589 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
2590 <?php if ( is_multisite() ) : ?>
2591 <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>
2592 <?php else : ?>
2593 <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>
2594 <?php endif; ?>
2595 </div>
2596 <?php
2597 }
2598
2599 /**
2600 * Approving a change to the shared config files needs the network
2601 *
2602 * Since 2.11.3 the handler behind the Approve button asks for
2603 * manage_network_options, because the two files it approves, wp-config.php
2604 * and the root .htaccess, belong to the installation, and so does the
2605 * record of them. The button, though, went on being painted for everybody,
2606 * so the administrator of a subsite saw the warning, saw the button,
2607 * pressed it and got "Permission denied" with no explanation. That is
2608 * exactly what user_actions_locked() above exists to avoid, one release
2609 * later and one screen over. Flagged by @calzbert.
2610 *
2611 * @since 2.11.4
2612 * @return bool
2613 */
2614 private function critical_approval_locked() {
2615 return is_multisite() && ! current_user_can( 'manage_network_options' );
2616 }
2617
2618 /**
2619 * The line that replaces the Approve button where it cannot be used
2620 *
2621 * @since 2.11.4
2622 * @return string
2623 */
2624 private function critical_approval_notice() {
2625 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' );
2626 }
2627
2628 /**
2629 * Check if module is disabled and render warning
2630 *
2631 * @param string $module_key Module key.
2632 * @return bool True if disabled.
2633 */
2634 private function render_module_disabled_notice( $module_key ) {
2635 if ( $this->settings->is_module_enabled( $module_key ) ) {
2636 return false;
2637 }
2638
2639 $module_labels = $this->settings->get_module_labels();
2640 $module_name = isset( $module_labels[ $module_key ] ) ? $module_labels[ $module_key ] : $module_key;
2641 ?>
2642 <div class="notice notice-warning vigilante-module-disabled-notice">
2643 <p>
2644 <strong><?php esc_html_e( 'Module Disabled', 'vigilante' ); ?></strong> -
2645 <?php
2646 printf(
2647 /* translators: %s: Module name */
2648 esc_html__( 'The %s module is currently disabled. Enable it from the Dashboard to use these settings.', 'vigilante' ),
2649 esc_html( $module_name )
2650 );
2651 ?>
2652 </p>
2653 <p>
2654 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=dashboard' ) ); ?>" class="button">
2655 <?php esc_html_e( 'Go to Dashboard', 'vigilante' ); ?>
2656 </a>
2657 </p>
2658 </div>
2659 <?php
2660 return true;
2661 }
2662
2663 /**
2664 * Render the Security Analyzer (Security Check) widget + expandable full report.
2665 *
2666 * Lives in the Dashboard tab between the Configuration Score status card and
2667 * the modules grid. Uses the last persisted scan to hydrate server-side so the
2668 * first paint shows real data; "Scan now" runs the 2-phase AJAX to refresh.
2669 *
2670 * @param array $last_scan Result of Vigilante_Security_Analyzer::get_last_scan().
2671 * @param array $history Score history (oldest first).
2672 * @param array $categories_def Category metadata (slug => label/max).
2673 * @param array $analyzer_settings Settings subsection for weekly cron + email.
2674 */
2675 private function render_analyzer_widget( $last_scan, $history, $categories_def, $analyzer_settings ) {
2676 $has_data = ! empty( $last_scan['ran_at'] );
2677 $score = isset( $last_scan['score'] ) ? (int) $last_scan['score'] : 0;
2678 $grade = isset( $last_scan['grade'] ) ? (string) $last_scan['grade'] : '';
2679 $counts = isset( $last_scan['counts'] ) && is_array( $last_scan['counts'] ) ? $last_scan['counts'] : array();
2680 $ran_at_human = $has_data
2681 ? sprintf(
2682 /* translators: %s: relative time like "2 hours" */
2683 __( 'Last scan %s ago', 'vigilante' ),
2684 human_time_diff( (int) $last_scan['ran_at'], time() )
2685 )
2686 : __( 'Never scanned', 'vigilante' );
2687 $categories = isset( $last_scan['categories'] ) && is_array( $last_scan['categories'] ) ? $last_scan['categories'] : array();
2688 $weekly_enabled = ! isset( $analyzer_settings['weekly_scan_enabled'] ) || ! empty( $analyzer_settings['weekly_scan_enabled'] );
2689 $email_enabled = ! empty( $analyzer_settings['email_on_regression'] );
2690
2691 /*
2692 * Self-protection caps the score, and it does so here and not only in
2693 * the stored report: the report is reused until the next Security
2694 * Check, so tampering found after it ran would otherwise be shown next
2695 * to the score the site earned before it happened.
2696 */
2697 $self_summary = $this->self_integrity_summary();
2698 $self_capped = in_array( $self_summary['tone'], array( 'critical', 'off' ), true )
2699 || ( 'self_integrity' === ( isset( $last_scan['capped_by'] ) ? $last_scan['capped_by'] : '' ) );
2700 if ( $self_capped && $has_data && $score > Vigilante_Security_Analyzer::SCORE_CAP_ON_TAMPER ) {
2701 $score = Vigilante_Security_Analyzer::SCORE_CAP_ON_TAMPER;
2702 $grade = 'E';
2703 }
2704
2705 $quality = self::analyzer_quality_tag( $score );
2706 ?>
2707 <div class="vigilante-analyzer" id="vigilante-analyzer"
2708 data-has-data="<?php echo $has_data ? '1' : '0'; ?>">
2709 <div class="vigilante-analyzer-header">
2710 <div class="vigilante-analyzer-title">
2711 <h2>
2712 <span class="dashicons dashicons-shield-alt" aria-hidden="true"></span>
2713 <?php esc_html_e( 'Security Check', 'vigilante' ); ?>
2714 </h2>
2715 <p class="description">
2716 <?php esc_html_e( 'On-demand audit of what an attacker would see right now, plus internal checks impossible from the outside.', 'vigilante' ); ?>
2717 </p>
2718 <p class="vigilante-analyzer-last-scan" data-role="ran-at">
2719 <span class="dashicons dashicons-clock" aria-hidden="true"></span>
2720 <?php echo esc_html( $ran_at_human ); ?>
2721 </p>
2722 </div>
2723 <div class="vigilante-analyzer-actions">
2724 <button type="button" class="button button-primary" id="vigilante-analyzer-scan">
2725 <span class="dashicons dashicons-update" aria-hidden="true"></span>
2726 <?php esc_html_e( 'Scan now', 'vigilante' ); ?>
2727 </button>
2728 </div>
2729 </div>
2730
2731 <?php if ( $self_capped ) : ?>
2732 <p class="vigilante-analyzer-capped">
2733 <span class="dashicons dashicons-shield" aria-hidden="true"></span>
2734 <strong><?php esc_html_e( 'This score is not reliable right now.', 'vigilante' ); ?></strong>
2735 <?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' ); ?>
2736 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=file-integrity#vigilante-section-fi-self' ) ); ?>">
2737 <?php esc_html_e( 'See what to do', 'vigilante' ); ?>
2738 </a>
2739 </p>
2740 <?php endif; ?>
2741
2742 <div class="vigilante-analyzer-summary">
2743 <div class="vigilante-analyzer-score-card">
2744 <?php if ( $has_data && $grade ) : ?>
2745 <div class="vigilante-score-circle vigilante-grade-<?php echo esc_attr( strtolower( $grade ) ); ?>">
2746 <span class="vigilante-grade"><?php echo esc_html( $grade ); ?></span>
2747 <span class="vigilante-score-text"><?php echo esc_html( $score ); ?>%</span>
2748 </div>
2749 <?php else : ?>
2750 <div class="vigilante-score-circle vigilante-grade-empty">
2751 <span class="vigilante-grade">—</span>
2752 <span class="vigilante-score-text"><?php esc_html_e( 'N/A', 'vigilante' ); ?></span>
2753 </div>
2754 <?php endif; ?>
2755 <div class="vigilante-analyzer-score-meta">
2756 <p class="vigilante-analyzer-score-label">
2757 <?php esc_html_e( 'Security Score', 'vigilante' ); ?>
2758 </p>
2759 <span class="vigilante-analyzer-quality-tag vigilante-analyzer-quality-<?php echo esc_attr( $quality['slug'] ); ?>"
2760 data-role="quality-tag">
2761 <?php echo esc_html( $quality['label'] ); ?>
2762 </span>
2763 </div>
2764 </div>
2765
2766 <div class="vigilante-analyzer-counts">
2767 <span class="vigilante-analyzer-count vigilante-analyzer-count--pass">
2768 <span class="dashicons dashicons-yes-alt" aria-hidden="true"></span>
2769 <strong data-role="pass"><?php echo esc_html( isset( $counts['pass'] ) ? $counts['pass'] : 0 ); ?></strong>
2770 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Passed', 'vigilante' ); ?></span>
2771 </span>
2772 <span class="vigilante-analyzer-count vigilante-analyzer-count--warn">
2773 <span class="dashicons dashicons-warning" aria-hidden="true"></span>
2774 <strong data-role="warn"><?php echo esc_html( isset( $counts['warn'] ) ? $counts['warn'] : 0 ); ?></strong>
2775 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Warnings', 'vigilante' ); ?></span>
2776 </span>
2777 <span class="vigilante-analyzer-count vigilante-analyzer-count--fail">
2778 <span class="dashicons dashicons-dismiss" aria-hidden="true"></span>
2779 <strong data-role="fail"><?php echo esc_html( isset( $counts['fail'] ) ? $counts['fail'] : 0 ); ?></strong>
2780 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Failing', 'vigilante' ); ?></span>
2781 </span>
2782 </div>
2783
2784 <?php
2785 // Sparkline of recent scores. Require at least 3 data points so the trend
2786 // is meaningful (2 points is just a line between dots, no real trend).
2787 $hist_points = array();
2788 foreach ( $history as $h ) {
2789 $hist_points[] = (int) $h['score'];
2790 }
2791 $hist_count = count( $hist_points );
2792 if ( $hist_count >= 3 ) :
2793 $current_score = (int) end( $hist_points );
2794 $previous_score = (int) $hist_points[ $hist_count - 2 ];
2795 $delta = $current_score - $previous_score;
2796 $delta_class = $delta > 0 ? 'vigilante-analyzer-delta--up' : ( $delta < 0 ? 'vigilante-analyzer-delta--down' : 'vigilante-analyzer-delta--flat' );
2797 $delta_icon = $delta > 0 ? 'arrow-up-alt' : ( $delta < 0 ? 'arrow-down-alt' : 'minus' );
2798 if ( 0 === $delta ) {
2799 $delta_text = __( 'No change', 'vigilante' );
2800 } else {
2801 $delta_text = sprintf(
2802 /* translators: %s: signed delta, e.g. "+3" or "-5" */
2803 _n( '%s pt vs. previous scan', '%s pts vs. previous scan', abs( $delta ), 'vigilante' ),
2804 ( $delta > 0 ? '+' : '' ) . (int) $delta
2805 );
2806 }
2807 ?>
2808 <div class="vigilante-analyzer-sparkline-wrap">
2809 <div class="vigilante-analyzer-sparkline-head">
2810 <span class="vigilante-analyzer-sparkline-label">
2811 <?php
2812 echo esc_html( sprintf(
2813 /* translators: %d: number of scans */
2814 _n( 'Score trend (last %d scan)', 'Score trend (last %d scans)', $hist_count, 'vigilante' ),
2815 $hist_count
2816 ) );
2817 ?>
2818 </span>
2819 <span class="vigilante-analyzer-delta <?php echo esc_attr( $delta_class ); ?>">
2820 <span class="dashicons dashicons-<?php echo esc_attr( $delta_icon ); ?>" aria-hidden="true"></span>
2821 <?php echo esc_html( $delta_text ); ?>
2822 </span>
2823 </div>
2824 <div class="vigilante-analyzer-sparkline" data-role="sparkline"
2825 data-points="<?php echo esc_attr( wp_json_encode( $hist_points ) ); ?>">
2826 <?php echo self::sparkline_svg( $hist_points ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Safe SVG from helper ?>
2827 </div>
2828 </div>
2829 <?php elseif ( $has_data ) : ?>
2830 <div class="vigilante-analyzer-sparkline-wrap vigilante-analyzer-sparkline-wrap--placeholder">
2831 <span class="vigilante-analyzer-sparkline-label">
2832 <?php esc_html_e( 'Score trend', 'vigilante' ); ?>
2833 </span>
2834 <p class="vigilante-analyzer-sparkline-hint">
2835 <span class="dashicons dashicons-chart-line" aria-hidden="true"></span>
2836 <?php
2837 $needed = 3 - $hist_count;
2838 echo esc_html( sprintf(
2839 /* translators: %d: number of additional scans needed */
2840 _n( '%d more scan needed to show a trend.', '%d more scans needed to show a trend.', $needed, 'vigilante' ),
2841 $needed
2842 ) );
2843 ?>
2844 </p>
2845 </div>
2846 <?php endif; ?>
2847 </div>
2848
2849 <div class="vigilante-analyzer-toggle-row">
2850 <button type="button" class="button-link vigilante-analyzer-toggle" aria-expanded="false">
2851 <?php esc_html_e( 'Show detailed breakdown', 'vigilante' ); ?>
2852 <span class="vigilante-analyzer-toggle-chevron" aria-hidden="true"></span>
2853 </button>
2854 </div>
2855
2856 <div class="vigilante-analyzer-details" hidden>
2857 <div class="vigilante-analyzer-categories" data-role="categories">
2858 <?php foreach ( $categories_def as $slug => $meta ) :
2859 $cat = isset( $categories[ $slug ] ) ? $categories[ $slug ] : array();
2860 $earned = isset( $cat['earned'] ) ? (int) $cat['earned'] : 0;
2861 // Always use the declared meta as the source of truth for the maximum.
2862 // The cached scan may carry an old max if a check was added/removed
2863 // between releases (see 2.6.1: closed_plugins raised internal from 22 to 28
2864 // but cached scans still reported max=22 until reset).
2865 $cat_max = (int) $meta['max'];
2866 $info_only = ! empty( $meta['info_only'] ) || 0 === (int) $meta['max'];
2867 $cat_pct = $cat_max > 0 ? (int) round( ( $earned / $cat_max ) * 100 ) : 0;
2868 $checks = isset( $cat['checks'] ) ? (array) $cat['checks'] : array();
2869 $cat_counts = isset( $cat['counts'] ) && is_array( $cat['counts'] ) ? $cat['counts'] : array( 'pass' => 0, 'warn' => 0, 'fail' => 0, 'info' => 0 );
2870 $cat_quality = self::analyzer_quality_tag( $cat_pct );
2871 $info_count = isset( $cat_counts['info'] ) ? (int) $cat_counts['info'] : 0;
2872 ?>
2873 <details class="vigilante-analyzer-category<?php echo $info_only ? ' vigilante-analyzer-category--info' : ''; ?>"
2874 data-category="<?php echo esc_attr( $slug ); ?>"
2875 data-info-only="<?php echo $info_only ? '1' : '0'; ?>">
2876 <summary class="vigilante-analyzer-category-summary">
2877 <span class="vigilante-analyzer-category-chevron" aria-hidden="true"></span>
2878 <span class="vigilante-analyzer-category-label"><?php echo esc_html( $meta['label'] ); ?></span>
2879 <?php if ( $info_only ) : ?>
2880 <span class="vigilante-analyzer-category-quality vigilante-analyzer-quality-info"
2881 data-role="category-quality"
2882 title="<?php esc_attr_e( 'Informational — does not affect the security score.', 'vigilante' ); ?>">
2883 <span class="dashicons dashicons-info-outline" aria-hidden="true"></span>
2884 <?php esc_html_e( 'Informational', 'vigilante' ); ?>
2885 </span>
2886 <?php else :
2887 $passed_count = (int) ( $cat_counts['pass'] ?? 0 );
2888 $scored_total = $passed_count
2889 + (int) ( $cat_counts['warn'] ?? 0 )
2890 + (int) ( $cat_counts['fail'] ?? 0 );
2891 ?>
2892 <span class="vigilante-analyzer-category-quality vigilante-analyzer-quality-<?php echo esc_attr( $cat_quality['slug'] ); ?>"
2893 data-role="category-quality">
2894 <span data-role="category-quality-label"><?php echo esc_html( $cat_quality['label'] ); ?></span>
2895 <span class="vigilante-analyzer-category-quality-sep" aria-hidden="true">·</span>
2896 <span class="vigilante-analyzer-category-tests" data-role="category-tests"
2897 data-passed="<?php echo esc_attr( $passed_count ); ?>"
2898 data-total="<?php echo esc_attr( $scored_total ); ?>">
2899 <?php
2900 echo esc_html( sprintf(
2901 /* translators: 1: tests passed, 2: total tests in this category */
2902 __( '%1$d/%2$d tests', 'vigilante' ),
2903 $passed_count,
2904 $scored_total
2905 ) );
2906 ?>
2907 </span>
2908 </span>
2909 <?php endif; ?>
2910 <?php if ( $info_only ) : ?>
2911 <span class="vigilante-analyzer-category-states" data-role="category-states">
2912 <?php if ( $info_count > 0 ) : ?>
2913 <span class="vigilante-analyzer-category-state vigilante-analyzer-category-state--info" title="<?php esc_attr_e( 'Informational', 'vigilante' ); ?>">
2914 <span data-role="state-info"><?php echo esc_html( $info_count ); ?></span><span class="dashicons dashicons-info-outline" aria-hidden="true"></span>
2915 </span>
2916 <?php endif; ?>
2917 </span>
2918 <?php endif; ?>
2919 <?php if ( ! $info_only ) : ?>
2920 <span class="vigilante-analyzer-category-score">
2921 <span data-role="earned"><?php echo esc_html( $earned ); ?></span><span class="vigilante-analyzer-category-score-sep">/</span><?php echo esc_html( $cat_max ); ?>
2922 <span class="vigilante-analyzer-category-score-unit"><?php esc_html_e( 'pts', 'vigilante' ); ?></span>
2923 </span>
2924 <span class="vigilante-analyzer-category-bar" aria-hidden="true">
2925 <span class="vigilante-analyzer-category-bar-fill vigilante-analyzer-category-bar-fill--<?php echo esc_attr( $cat_quality['slug'] ); ?>"
2926 style="width: <?php echo esc_attr( $cat_pct ); ?>%"
2927 data-role="category-bar"></span>
2928 </span>
2929 <?php else :
2930 $info_warn = isset( $cat_counts['warn'] ) ? (int) $cat_counts['warn'] : 0;
2931 $info_fail = isset( $cat_counts['fail'] ) ? (int) $cat_counts['fail'] : 0;
2932 $info_issues = $info_warn + $info_fail;
2933 if ( $info_issues > 0 ) : ?>
2934 <span class="vigilante-analyzer-category-status vigilante-analyzer-category-status--attention" data-role="info-status">
2935 <span class="dashicons dashicons-warning" aria-hidden="true"></span>
2936 <?php
2937 echo esc_html( sprintf(
2938 /* translators: %d: number of findings */
2939 _n( '%d finding', '%d findings', $info_issues, 'vigilante' ),
2940 $info_issues
2941 ) );
2942 ?>
2943 </span>
2944 <?php else : ?>
2945 <span class="vigilante-analyzer-category-status vigilante-analyzer-category-status--clear" data-role="info-status">
2946 <span class="dashicons dashicons-yes-alt" aria-hidden="true"></span>
2947 <?php esc_html_e( 'All clear', 'vigilante' ); ?>
2948 </span>
2949 <?php endif; ?>
2950 <?php endif; ?>
2951 </summary>
2952 <ul class="vigilante-analyzer-check-list" data-role="check-list">
2953 <?php if ( empty( $checks ) ) : ?>
2954 <li class="vigilante-analyzer-check-empty">
2955 <?php esc_html_e( 'No data yet — run a scan to populate this category.', 'vigilante' ); ?>
2956 </li>
2957 <?php else : ?>
2958 <?php foreach ( $checks as $c ) : ?>
2959 <?php echo self::render_analyzer_check_row( $c ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped inside helper ?>
2960 <?php endforeach; ?>
2961 <?php endif; ?>
2962 </ul>
2963 </details>
2964 <?php endforeach; ?>
2965 </div>
2966
2967 <div class="vigilante-analyzer-weekly">
2968 <h3><?php esc_html_e( 'Automatic weekly scan', 'vigilante' ); ?></h3>
2969 <p class="description">
2970 <?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' ); ?>
2971 </p>
2972 <label class="vigilante-analyzer-toggle-option">
2973 <input type="checkbox"
2974 name="security_analyzer[weekly_scan_enabled]"
2975 value="1"
2976 <?php checked( $weekly_enabled ); ?>>
2977 <?php esc_html_e( 'Run a weekly automatic scan', 'vigilante' ); ?>
2978 </label>
2979 <label class="vigilante-analyzer-toggle-option">
2980 <input type="checkbox"
2981 name="security_analyzer[email_on_regression]"
2982 value="1"
2983 <?php checked( $email_enabled ); ?>>
2984 <?php esc_html_e( 'Email me when the score drops significantly', 'vigilante' ); ?>
2985 </label>
2986 </div>
2987 </div>
2988 </div>
2989 <?php
2990 }
2991
2992 /**
2993 * Map a 0-100 percentage to a quality tag { label, slug } aligned with the
2994 * Dashboard grade palette (a/b/c/d/e).
2995 *
2996 * @param int $pct 0..100.
2997 * @return array{label:string,slug:string}
2998 */
2999 public static function analyzer_quality_tag( $pct ) {
3000 $pct = max( 0, min( 100, (int) $pct ) );
3001 // "Excellent" is reserved for a perfect score — a single missing point drops to Good.
3002 if ( 100 === $pct ) {
3003 return array( 'label' => __( 'Excellent', 'vigilante' ), 'slug' => 'a' );
3004 }
3005 if ( $pct >= 70 ) {
3006 return array( 'label' => __( 'Good', 'vigilante' ), 'slug' => 'b' );
3007 }
3008 if ( $pct >= 50 ) {
3009 return array( 'label' => __( 'Fair', 'vigilante' ), 'slug' => 'c' );
3010 }
3011 if ( $pct >= 30 ) {
3012 return array( 'label' => __( 'Poor', 'vigilante' ), 'slug' => 'd' );
3013 }
3014 return array( 'label' => __( 'Critical', 'vigilante' ), 'slug' => 'e' );
3015 }
3016
3017 /**
3018 * Render a single analyzer check row (used both server-side and via JS template).
3019 *
3020 * @param array $check Check result array (from Vigilante_SA_Check_Result::to_array()).
3021 * @return string HTML (escaped).
3022 */
3023 private static function render_analyzer_check_row( $check ) {
3024 $id = isset( $check['id'] ) ? $check['id'] : '';
3025 $state = isset( $check['state'] ) ? $check['state'] : 'skip';
3026 $label = isset( $check['label'] ) ? $check['label'] : '';
3027 $detail = isset( $check['detail'] ) ? $check['detail'] : '';
3028 $score = isset( $check['score'] ) ? (int) $check['score'] : 0;
3029 $max = isset( $check['max'] ) ? (int) $check['max'] : 0;
3030 $fix_link = isset( $check['fix_link'] ) ? $check['fix_link'] : '';
3031
3032 $icons = array(
3033 'pass' => 'yes-alt',
3034 'warn' => 'warning',
3035 'fail' => 'dismiss',
3036 'info' => 'info',
3037 'skip' => 'minus',
3038 );
3039 $icon = isset( $icons[ $state ] ) ? $icons[ $state ] : 'minus';
3040
3041 $html = '<li class="vigilante-analyzer-check vigilante-analyzer-check--' . esc_attr( $state ) . '"';
3042 $html .= ' data-check-id="' . esc_attr( $id ) . '">';
3043 $html .= '<span class="vigilante-analyzer-check-icon dashicons dashicons-' . esc_attr( $icon ) . '" aria-hidden="true"></span>';
3044 $html .= '<div class="vigilante-analyzer-check-body">';
3045 $html .= '<div class="vigilante-analyzer-check-label">';
3046 $html .= '<span>' . esc_html( $label ) . '</span>';
3047 if ( $max > 0 && 'info' !== $state && 'skip' !== $state ) {
3048 $html .= '<span class="vigilante-analyzer-check-score">'
3049 . esc_html( $score . '/' . $max )
3050 . ' <span class="vigilante-analyzer-check-score-unit">' . esc_html__( 'pts', 'vigilante' ) . '</span>'
3051 . '</span>';
3052 }
3053 $html .= '</div>';
3054 if ( $detail ) {
3055 $html .= '<p class="vigilante-analyzer-check-detail">' . esc_html( $detail ) . '</p>';
3056 }
3057 if ( $fix_link && in_array( $state, array( 'fail', 'warn' ), true ) ) {
3058 $html .= '<a href="' . esc_url( $fix_link ) . '" class="vigilante-analyzer-fix-link">'
3059 . esc_html__( 'Go to setting', 'vigilante' )
3060 . '<span class="vigilante-analyzer-fix-arrow" aria-hidden="true">&rarr;</span></a>';
3061 } elseif ( $fix_link && 'info' === $state ) {
3062 // Info rows (e.g. DNSBL lookups) get an external "Learn more" link instead.
3063 $is_external = 0 === strpos( $fix_link, 'http' );
3064 $html .= '<a href="' . esc_url( $fix_link ) . '" class="vigilante-analyzer-fix-link"'
3065 . ( $is_external ? ' target="_blank" rel="noopener noreferrer"' : '' ) . '>'
3066 . esc_html__( 'Learn more', 'vigilante' )
3067 . '<span class="vigilante-analyzer-fix-arrow" aria-hidden="true">&rarr;</span></a>';
3068 }
3069 $html .= '</div>';
3070 $html .= '</li>';
3071 return $html;
3072 }
3073
3074 /**
3075 * Build a minimal SVG sparkline for the score history.
3076 *
3077 * @param int[] $points Score values (0..100), oldest to newest.
3078 * @return string SVG markup.
3079 */
3080 private static function sparkline_svg( $points ) {
3081 $points = array_map( 'intval', (array) $points );
3082 $count = count( $points );
3083 if ( $count < 2 ) {
3084 return '';
3085 }
3086 $width = 280;
3087 $height = 60;
3088 $padding = 4;
3089
3090 $usable_w = $width - ( $padding * 2 );
3091 $usable_h = $height - ( $padding * 2 );
3092
3093 $step = $usable_w / max( 1, $count - 1 );
3094 $max = 100; // Fixed scale — scores are 0..100.
3095
3096 $coords = array();
3097 foreach ( $points as $i => $v ) {
3098 $x = $padding + ( $i * $step );
3099 $y = $padding + ( $usable_h - ( ( $v / $max ) * $usable_h ) );
3100 $coords[] = round( $x, 2 ) . ',' . round( $y, 2 );
3101 }
3102 $path = 'M ' . implode( ' L ', $coords );
3103 $last = end( $points );
3104 $last_x = $padding + ( ( $count - 1 ) * $step );
3105 $last_y = $padding + ( $usable_h - ( ( $last / $max ) * $usable_h ) );
3106
3107 $svg = '<svg viewBox="0 0 ' . $width . ' ' . $height . '" preserveAspectRatio="none" role="img" aria-label="' . esc_attr__( 'Security Score history', 'vigilante' ) . '" focusable="false">';
3108 $svg .= '<path d="' . esc_attr( $path ) . '" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>';
3109 $svg .= '<circle cx="' . esc_attr( round( $last_x, 2 ) ) . '" cy="' . esc_attr( round( $last_y, 2 ) ) . '" r="3" fill="currentColor"/>';
3110 $svg .= '</svg>';
3111 return $svg;
3112 }
3113
3114 /**
3115 * Render dashboard tab
3116 */
3117 /**
3118 * One line strip at the top of the Dashboard tab: the state of Vigilant own
3119 * files, above the Configuration Score and the Security Check, because
3120 * nothing else on this screen means much while it is red.
3121 */
3122 private function render_self_protection_strip() {
3123 $summary = $this->self_integrity_summary();
3124 $tone = $summary['tone'];
3125 $state = $summary['state'];
3126 $count = count( $summary['findings'] );
3127 $link = admin_url( 'admin.php?page=vigilante&tab=file-integrity#vigilante-section-fi-self' );
3128 ?>
3129 <div class="vigilante-self-strip vigilante-self-strip--<?php echo esc_attr( $tone ); ?>">
3130 <span class="dashicons dashicons-shield" aria-hidden="true"></span>
3131 <strong><?php esc_html_e( 'Vigilant self-protection', 'vigilante' ); ?></strong>
3132 <span class="vigilante-self-strip-state"><?php echo esc_html( $this->self_integrity_headline( $tone, $state ) ); ?></span>
3133 <?php if ( $count > 0 ) : ?>
3134 <span class="vigilante-self-strip-count">
3135 <?php
3136 printf(
3137 /* translators: %d: number of findings about Vigilant own files */
3138 esc_html( _n( '%d finding', '%d findings', $count, 'vigilante' ) ),
3139 (int) $count
3140 );
3141 ?>
3142 </span>
3143 <?php elseif ( ! empty( $state['last_check'] ) && 'off' !== $tone ) : ?>
3144 <span class="vigilante-self-strip-count">
3145 <?php
3146 printf(
3147 /* translators: %s: human time difference, like "2 hours" */
3148 esc_html__( 'checked %s ago', 'vigilante' ),
3149 esc_html( human_time_diff( (int) $state['last_check'], time() ) )
3150 );
3151 ?>
3152 </span>
3153 <?php endif; ?>
3154 <a href="<?php echo esc_url( $link ); ?>">
3155 <?php
3156 if ( in_array( $tone, array( 'critical', 'off', 'warning' ), true ) ) {
3157 esc_html_e( 'See what to do', 'vigilante' );
3158 } else {
3159 esc_html_e( 'See details', 'vigilante' );
3160 }
3161 ?>
3162 </a>
3163 </div>
3164 <?php
3165 }
3166
3167 private function render_tab_dashboard() {
3168 $options = $this->settings->get_all_options();
3169 $module_labels = $this->settings->get_module_labels();
3170 $module_descriptions = $this->settings->get_module_descriptions();
3171 $presets = $this->settings->get_presets();
3172 $active_preset = get_option( 'vigilante_active_preset', '' );
3173
3174 // Calculate security score with more factors
3175 $security_score = $this->calculate_security_score( $options );
3176
3177 // Security Analyzer (v2.1.0) — hydrate widget with the last persisted scan, if any.
3178 if ( ! class_exists( 'Vigilante_Security_Analyzer' ) ) {
3179 require_once VIGILANTE_INCLUDES_DIR . 'class-security-analyzer.php';
3180 }
3181 $analyzer_instance = new Vigilante_Security_Analyzer( $this->settings, $this->activity_log );
3182 $analyzer_last_scan = $analyzer_instance->get_last_scan();
3183 $analyzer_history = $analyzer_instance->get_score_history();
3184 $analyzer_categories_def = Vigilante_Security_Analyzer::get_categories();
3185 $analyzer_settings = isset( $options['security_analyzer'] ) ? $options['security_analyzer'] : array();
3186 ?>
3187 <div class="vigilante-dashboard">
3188 <?php $this->render_self_protection_strip(); ?>
3189 <div class="vigilante-status-card">
3190 <h2><?php esc_html_e( 'Configuration Score', 'vigilante' ); ?></h2>
3191 <p class="vigilante-score-kind description">
3192 <?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' ); ?>
3193 </p>
3194 <div class="vigilante-security-score">
3195 <?php
3196 // Grade thresholds: A (90+), B (70-89), C (50-69), D (30-49), E (0-29)
3197 if ( $security_score >= 90 ) {
3198 $grade = 'A';
3199 } elseif ( $security_score >= 70 ) {
3200 $grade = 'B';
3201 } elseif ( $security_score >= 50 ) {
3202 $grade = 'C';
3203 } elseif ( $security_score >= 30 ) {
3204 $grade = 'D';
3205 } else {
3206 $grade = 'E';
3207 }
3208 ?>
3209 <div class="vigilante-score-circle vigilante-grade-<?php echo esc_attr( strtolower( $grade ) ); ?>">
3210 <span class="vigilante-grade"><?php echo esc_html( $grade ); ?></span>
3211 <span class="vigilante-score-text"><?php echo esc_html( $security_score ); ?>%</span>
3212 </div>
3213 <div class="vigilante-config-status">
3214 <?php if ( $active_preset && isset( $presets[ $active_preset ] ) ) : ?>
3215 <span class="vigilante-preset-badge vigilante-preset-<?php echo esc_attr( $active_preset ); ?>">
3216 <?php echo esc_html( $presets[ $active_preset ]['name'] ); ?>
3217 </span>
3218 <?php else : ?>
3219 <span class="vigilante-preset-badge vigilante-preset-custom">
3220 <?php esc_html_e( 'Custom Configuration', 'vigilante' ); ?>
3221 </span>
3222 <?php endif; ?>
3223 </div>
3224 </div>
3225
3226 <?php
3227 $recommendations = $this->get_security_recommendations( $options );
3228 if ( ! empty( $recommendations ) ) :
3229 ?>
3230 <div class="vigilante-recommendations">
3231 <h4><?php esc_html_e( 'Recommendations', 'vigilante' ); ?></h4>
3232 <ul class="vigilante-recommendations-grid">
3233 <?php foreach ( $recommendations as $rec ) : ?>
3234 <li>
3235 <span class="dashicons dashicons-<?php echo esc_attr( $rec['icon'] ); ?> vigilante-priority-<?php echo esc_attr( $rec['priority'] ); ?>"></span>
3236 <?php echo esc_html( $rec['message'] ); ?>
3237 <?php if ( ! empty( $rec['tab'] ) ) : ?>
3238 <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>
3239 <?php endif; ?>
3240 </li>
3241 <?php endforeach; ?>
3242 </ul>
3243 </div>
3244 <?php endif; ?>
3245 </div>
3246
3247 <?php $this->render_analyzer_widget( $analyzer_last_scan, $analyzer_history, $analyzer_categories_def, $analyzer_settings ); ?>
3248
3249 <div class="vigilante-modules-grid">
3250 <h2 id="vigilante-section-dashboard-modules"><?php esc_html_e( 'Security Modules', 'vigilante' ); ?></h2>
3251 <p class="description"><?php esc_html_e( 'Enable or disable security modules. Each module controls a tab with detailed settings.', 'vigilante' ); ?></p>
3252 <div class="vigilante-modules-list">
3253 <?php foreach ( $options['modules'] as $module => $enabled ) :
3254 $label = isset( $module_labels[ $module ] ) ? $module_labels[ $module ] : ucwords( str_replace( '_', ' ', $module ) );
3255 $description = isset( $module_descriptions[ $module ] ) ? $module_descriptions[ $module ] : '';
3256 $vg_module_locked = $this->main_site_files_locked() && in_array( $module, Vigilante_Settings::get_main_site_file_settings()['modules'], true );
3257 ?>
3258 <div class="vigilante-module-item <?php echo $enabled ? 'enabled' : 'disabled'; ?>">
3259 <div class="vigilante-module-header">
3260 <span class="vigilante-module-status"></span>
3261 <span class="vigilante-module-name"><?php echo esc_html( $label ); ?></span>
3262 <label class="vigilante-toggle">
3263 <?php
3264 /* translators: %s: Security module name, for example Firewall. */
3265 $toggle_label = sprintf( __( 'Enable %s', 'vigilante' ), $label );
3266 ?>
3267 <input type="checkbox"
3268 name="modules[<?php echo esc_attr( $module ); ?>]"
3269 value="1"
3270 <?php checked( $enabled ); ?>
3271 <?php disabled( $vg_module_locked ); ?>
3272 aria-label="<?php echo esc_attr( $toggle_label ); ?>"
3273 data-module="<?php echo esc_attr( $module ); ?>">
3274 <span class="vigilante-toggle-slider"></span>
3275 </label>
3276 </div>
3277 <?php if ( $description ) : ?>
3278 <p class="vigilante-module-desc"><?php echo esc_html( $description ); ?></p>
3279 <?php endif; ?>
3280 <?php if ( $vg_module_locked ) : ?>
3281 <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>
3282 <?php endif; ?>
3283 </div>
3284 <?php endforeach; ?>
3285 </div>
3286 </div>
3287
3288 <div class="vigilante-presets-card">
3289 <h2><?php esc_html_e( 'Quick Configuration Presets', 'vigilante' ); ?></h2>
3290 <p><?php esc_html_e( 'Apply a preset to quickly set up recommended settings for standard or maximum security level.', 'vigilante' ); ?></p>
3291 <div class="vigilante-presets-grid">
3292 <?php foreach ( $presets as $preset_id => $preset ) :
3293 $is_active = ( $active_preset === $preset_id );
3294 ?>
3295 <div class="vigilante-preset-card <?php echo $is_active ? 'vigilante-preset-active' : ''; ?>">
3296 <?php if ( $is_active ) : ?>
3297 <span class="vigilante-active-indicator"><?php esc_html_e( 'Active', 'vigilante' ); ?></span>
3298 <?php endif; ?>
3299 <h3><?php echo esc_html( $preset['name'] ); ?></h3>
3300 <p><?php echo esc_html( $preset['description'] ); ?></p>
3301 <button type="button" class="button vigilante-preset-btn <?php echo $is_active ? 'button-primary' : ''; ?>" data-preset="<?php echo esc_attr( $preset_id ); ?>">
3302 <?php esc_html_e( 'Apply Preset', 'vigilante' ); ?>
3303 </button>
3304 </div>
3305 <?php endforeach; ?>
3306
3307 <?php
3308 // Under Attack mode card
3309 $under_attack = new Vigilante_Under_Attack( $this->settings, $this->activity_log );
3310 $ua_active = $under_attack->is_active();
3311 $ua_remaining = $under_attack->get_remaining_time();
3312 $ua_remaining_hours = floor( $ua_remaining / 3600 );
3313 $ua_remaining_mins = floor( ( $ua_remaining % 3600 ) / 60 );
3314 ?>
3315 <div class="vigilante-preset-card vigilante-under-attack-card <?php echo $ua_active ? 'vigilante-under-attack-active' : ''; ?>">
3316 <h3 id="vigilante-section-dashboard-under-attack">
3317 <span class="dashicons dashicons-shield"></span>
3318 <?php esc_html_e( 'Under Attack', 'vigilante' ); ?>
3319 </h3>
3320 <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>
3321 <?php if ( $ua_active ) : ?>
3322 <div class="vigilante-ua-countdown" data-expires="<?php echo esc_attr( $under_attack->get_status()['activated_at'] + $under_attack->get_status()['duration'] ); ?>">
3323 <span class="dashicons dashicons-clock"></span>
3324 <span class="vigilante-ua-time">
3325 <?php
3326 printf(
3327 /* translators: 1: Hours, 2: Minutes */
3328 esc_html__( '%1$dh %2$dm remaining', 'vigilante' ),
3329 absint( $ua_remaining_hours ),
3330 absint( $ua_remaining_mins )
3331 );
3332 ?>
3333 </span>
3334 </div>
3335 <button type="button" class="button vigilante-ua-btn vigilante-ua-deactivate">
3336 <?php esc_html_e( 'Deactivate', 'vigilante' ); ?>
3337 </button>
3338 <?php else : ?>
3339 <button type="button" class="button vigilante-ua-btn vigilante-ua-activate">
3340 <?php esc_html_e( 'Activate for 4 hours', 'vigilante' ); ?>
3341 </button>
3342 <?php endif; ?>
3343 </div>
3344 </div>
3345 </div>
3346 </div>
3347 <?php
3348 }
3349
3350 /**
3351 * Render tools tab
3352 */
3353 private function render_tab_tools() {
3354 // Get current settings for notification summary
3355 $email_options = $this->settings->get_section( 'email' );
3356 $login_options = $this->settings->get_section( 'login_security' );
3357 $user_options = $this->settings->get_section( 'user_security' );
3358 $fi_options = $this->settings->get_section( 'file_integrity' );
3359 $alerts_options = $this->settings->get_section( 'audit_alerts' );
3360 $monitoring = $user_options['admin_monitoring'] ?? array();
3361 $registration = $user_options['registration_approval'] ?? array();
3362 $current_admin = get_option( 'admin_email' );
3363 $send_to_admin = ! isset( $email_options['send_to_admin_email'] ) || ! empty( $email_options['send_to_admin_email'] );
3364 $additional_raw = $email_options['additional_recipients'] ?? array();
3365 $additional = is_array( $additional_raw ) ? implode( "\n", $additional_raw ) : trim( $additional_raw );
3366 ?>
3367
3368 <!-- Notification Settings -->
3369 <div id="vigilante-section-tools-notifications" class="vigilante-settings-section vigilante-notification-section">
3370 <h2><?php esc_html_e( 'Notification settings', 'vigilante' ); ?></h2>
3371 <p><?php esc_html_e( 'Configure who receives all administrative email notifications from Vigilant. Individual notifications are enabled in their respective tabs.', 'vigilante' ); ?></p>
3372
3373 <div class="vigilante-notification-layout">
3374
3375 <!-- Left column: Recipients settings -->
3376 <div class="vigilante-notification-settings">
3377 <form class="vigilante-settings-form" data-section="email">
3378
3379 <table class="form-table vigilante-compact-form">
3380 <tr>
3381 <th scope="row"><?php esc_html_e( 'WordPress Admin Email', 'vigilante' ); ?></th>
3382 <td>
3383 <label>
3384 <input type="checkbox" name="email[send_to_admin_email]" value="1" <?php checked( $send_to_admin ); ?>>
3385 <?php
3386 printf(
3387 /* translators: %s: Admin email address */
3388 esc_html__( 'Send to admin email (%s)', 'vigilante' ),
3389 '<code>' . esc_html( $current_admin ) . '</code>'
3390 );
3391 ?>
3392 </label>
3393 </td>
3394 </tr>
3395 <tr>
3396 <th scope="row"><label for="vigilante-f-email-additional-recipients"><?php esc_html_e( 'Additional Recipients', 'vigilante' ); ?></label></th>
3397 <td>
3398 <textarea id="vigilante-f-email-additional-recipients" name="email[additional_recipients]" rows="3" class="large-text code" placeholder="[email protected]&#10;[email protected]"><?php echo esc_textarea( $additional ); ?></textarea>
3399 <p class="description"><?php esc_html_e( 'One email per line.', 'vigilante' ); ?></p>
3400 </td>
3401 </tr>
3402 <tr>
3403 <th scope="row"><?php esc_html_e( 'Plugin Deactivation', 'vigilante' ); ?></th>
3404 <td>
3405 <label>
3406 <input type="checkbox" name="email[send_deactivation_email]" value="1" <?php checked( ! empty( $email_options['send_deactivation_email'] ) ); ?>>
3407 <?php esc_html_e( 'Send email when Vigilant is deactivated', 'vigilante' ); ?>
3408 </label>
3409 </td>
3410 </tr>
3411 </table>
3412
3413 <p class="submit vigilante-notification-submit">
3414 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
3415 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
3416 </button>
3417 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
3418 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
3419 </button>
3420 <span class="vigilante-test-email-result" style="margin-left:8px;vertical-align:middle;"></span>
3421 </p>
3422 <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>
3423
3424 </form>
3425 </div>
3426
3427 <!-- Right column: Active notifications summary -->
3428 <div class="vigilante-notification-summary">
3429 <h4><?php esc_html_e( 'Active notifications', 'vigilante' ); ?></h4>
3430
3431 <table class="widefat striped">
3432 <thead>
3433 <tr>
3434 <th><?php esc_html_e( 'Notification', 'vigilante' ); ?></th>
3435 <th style="width: 1%; white-space: nowrap; text-align: center;"><?php esc_html_e( 'Status', 'vigilante' ); ?></th>
3436 <th style="width: 50px; text-align: center;"></th>
3437 </tr>
3438 </thead>
3439 <tbody>
3440 <?php
3441 $notifications = array(
3442 array(
3443 'label' => __( 'Login lockout', 'vigilante' ),
3444 'active' => ! empty( $login_options['notify_on_lockout'] ),
3445 'tab' => 'login',
3446 ),
3447 array(
3448 'label' => __( 'Administrator login', 'vigilante' ),
3449 'active' => ! empty( $login_options['notify_on_admin_login'] ),
3450 'tab' => 'login',
3451 ),
3452 array(
3453 'label' => __( 'New administrator created', 'vigilante' ),
3454 'active' => ! empty( $monitoring['alert_new_admin'] ),
3455 'tab' => 'users',
3456 ),
3457 array(
3458 'label' => __( 'Administrator email changed', 'vigilante' ),
3459 'active' => ! empty( $monitoring['alert_admin_email_change'] ),
3460 'tab' => 'users',
3461 ),
3462 array(
3463 'label' => __( 'Permission elevation', 'vigilante' ),
3464 'active' => ! empty( $monitoring['alert_permission_elevation'] ),
3465 'tab' => 'users',
3466 ),
3467 array(
3468 'label' => __( 'Admin password changed', 'vigilante' ),
3469 'active' => ! empty( $monitoring['alert_admin_password_change'] ),
3470 'tab' => 'users',
3471 ),
3472 array(
3473 'label' => __( 'Registration pending approval', 'vigilante' ),
3474 'active' => ! empty( $registration['enabled'] ) && ! empty( $registration['notify_admin'] ),
3475 'tab' => 'users',
3476 ),
3477 array(
3478 'label' => __( 'File integrity scan report', 'vigilante' ),
3479 'active' => ( $fi_options['notify_level'] ?? 'disabled' ) !== 'disabled',
3480 'tab' => 'file-integrity',
3481 ),
3482 array(
3483 'label' => __( 'File integrity instant alert', 'vigilante' ),
3484 'active' => ! empty( $fi_options['instant_alert'] ),
3485 'tab' => 'file-integrity',
3486 ),
3487 array(
3488 'label' => __( 'Audit alert: immediate', 'vigilante' ),
3489 'active' => Vigilante_Audit_Alerts::immediate_is_active( $alerts_options ),
3490 'tab' => 'activity-log',
3491 'anchor' => 'vigilante-section-audit-alerts',
3492 ),
3493 array(
3494 'label' => __( 'Audit alert: threshold', 'vigilante' ),
3495 'active' => Vigilante_Audit_Alerts::threshold_is_active( $alerts_options ),
3496 'tab' => 'activity-log',
3497 'anchor' => 'vigilante-section-audit-alerts',
3498 ),
3499 array(
3500 'label' => __( 'Under Attack mode', 'vigilante' ),
3501 'active' => true,
3502 'tab' => '',
3503 'note' => __( 'Always active', 'vigilante' ),
3504 ),
3505 array(
3506 'label' => __( 'Plugin deactivation', 'vigilante' ),
3507 'active' => ! empty( $email_options['send_deactivation_email'] ),
3508 'tab' => 'tools',
3509 ),
3510 );
3511
3512 foreach ( $notifications as $notif ) :
3513 $status_class = $notif['active'] ? 'vigilante-status-active' : 'vigilante-status-inactive';
3514 $status_label = $notif['active'] ? __( 'Active', 'vigilante' ) : __( 'Inactive', 'vigilante' );
3515 if ( ! empty( $notif['note'] ) ) {
3516 $status_label = $notif['note'];
3517 }
3518 ?>
3519 <tr>
3520 <td><?php echo esc_html( $notif['label'] ); ?></td>
3521 <td style="text-align: center; white-space: nowrap;">
3522 <span class="<?php echo esc_attr( $status_class ); ?>"><?php echo esc_html( $status_label ); ?></span>
3523 </td>
3524 <td style="text-align: center;">
3525 <?php if ( ! empty( $notif['tab'] ) ) : ?>
3526 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=' . $notif['tab'] ) . ( ! empty( $notif['anchor'] ) ? '#' . $notif['anchor'] : '' ) ); ?>" class="button button-small">
3527 <span class="dashicons dashicons-admin-generic" style="font-size: 14px; line-height: 1.8;"></span>
3528 </a>
3529 <?php else : ?>
3530 &mdash;
3531 <?php endif; ?>
3532 </td>
3533 </tr>
3534 <?php endforeach; ?>
3535 </tbody>
3536 </table>
3537 </div>
3538
3539 </div>
3540 </div>
3541
3542 <h2 id="vigilante-section-tools-main" class="vigilante-tools-heading"><?php esc_html_e( 'Tools', 'vigilante' ); ?></h2>
3543
3544 <?php
3545 // Warn that during Under Attack mode the export/import operate against
3546 // the temporary hardened config and any imported changes will be
3547 // reverted when the mode ends.
3548 $ua_status = get_option( Vigilante_Under_Attack::OPTION_NAME, array() );
3549 if ( ! empty( $ua_status['active'] ) ) :
3550 ?>
3551 <div class="vigilante-ua-tools-notice-wrap">
3552 <div class="notice notice-warning inline vigilante-ua-tools-notice">
3553 <p>
3554 <strong><?php esc_html_e( 'Under Attack mode is active.', 'vigilante' ); ?></strong>
3555 <?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' ); ?>
3556 </p>
3557 </div>
3558 </div>
3559 <?php
3560 endif;
3561 ?>
3562
3563 <div class="vigilante-tools-grid">
3564 <div class="vigilante-tool-card">
3565 <h3><?php esc_html_e( 'Export Settings', 'vigilante' ); ?></h3>
3566 <p><?php esc_html_e( 'Download your current security settings as a JSON file.', 'vigilante' ); ?></p>
3567 <button type="button" class="button vigilante-export-settings">
3568 <?php esc_html_e( 'Export Settings', 'vigilante' ); ?>
3569 </button>
3570 </div>
3571
3572 <div class="vigilante-tool-card">
3573 <h3><?php esc_html_e( 'Import Settings', 'vigilante' ); ?></h3>
3574 <p><?php esc_html_e( 'Import settings from a previously exported JSON file.', 'vigilante' ); ?></p>
3575 <input type="file" id="vigilante-import-file" aria-label="<?php esc_attr_e( 'Configuration file to import', 'vigilante' ); ?>" accept=".json" style="display: none;">
3576 <button type="button" class="button vigilante-import-settings">
3577 <?php esc_html_e( 'Import Settings', 'vigilante' ); ?>
3578 </button>
3579 </div>
3580
3581 <div class="vigilante-tool-card">
3582 <h3><?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?></h3>
3583 <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>
3584 <button type="button" class="button vigilante-reset-settings" style="color: #a00;">
3585 <?php esc_html_e( 'Reset All Settings', 'vigilante' ); ?>
3586 </button>
3587 </div>
3588
3589 <div class="vigilante-tool-card">
3590 <h3><?php esc_html_e( 'Download Config Backup', 'vigilante' ); ?></h3>
3591 <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>
3592 <?php if ( $this->shared_files_locked() ) : ?>
3593 <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>
3594 <?php else : ?>
3595 <button type="button" class="button vigilante-create-backup">
3596 <?php esc_html_e( 'Download Backup', 'vigilante' ); ?>
3597 </button>
3598 <?php endif; ?>
3599 </div>
3600
3601 <?php if ( ! $this->shared_files_locked() ) : ?>
3602
3603 <div class="vigilante-tool-card vigilante-tool-card-wide">
3604 <h3><?php esc_html_e( 'Database Backup', 'vigilante' ); ?></h3>
3605 <p><?php esc_html_e( 'Download a backup of your database as a ZIP file. Select which tables to include.', 'vigilante' ); ?></p>
3606 <button type="button" class="button vigilante-db-backup-toggle">
3607 <?php esc_html_e( 'Download Database Backup', 'vigilante' ); ?>
3608 </button>
3609
3610 <div class="vigilante-db-backup-panel" style="display: none;">
3611 <div class="vigilante-db-tables-loading">
3612 <span class="spinner is-active"></span>
3613 <?php esc_html_e( 'Loading tables...', 'vigilante' ); ?>
3614 </div>
3615
3616 <div class="vigilante-db-tables-content" style="display: none;">
3617 <div class="vigilante-db-tables-controls">
3618 <label>
3619 <input type="checkbox" id="vigilante-db-select-all" checked>
3620 <strong><?php esc_html_e( 'Select / deselect all', 'vigilante' ); ?></strong>
3621 </label>
3622 <span class="vigilante-db-tables-info"></span>
3623 </div>
3624
3625 <div class="vigilante-db-tables-group">
3626 <h4><?php esc_html_e( 'WordPress core tables', 'vigilante' ); ?></h4>
3627 <div class="vigilante-db-tables-list" id="vigilante-db-core-tables"></div>
3628 </div>
3629
3630 <div class="vigilante-db-tables-group" id="vigilante-db-other-group" style="display: none;">
3631 <h4><?php esc_html_e( 'Plugin and custom tables', 'vigilante' ); ?></h4>
3632 <div class="vigilante-db-tables-list" id="vigilante-db-other-tables"></div>
3633 </div>
3634
3635 <div class="vigilante-db-backup-actions">
3636 <button type="button" class="button button-primary vigilante-db-backup-download">
3637 <?php esc_html_e( 'Download Backup (.zip)', 'vigilante' ); ?>
3638 </button>
3639 </div>
3640 </div>
3641 </div>
3642 </div>
3643 <?php else : ?>
3644 <div class="vigilante-tool-card vigilante-tool-card-wide">
3645 <h3><?php esc_html_e( 'Database Backup', 'vigilante' ); ?></h3>
3646 <p><?php esc_html_e( 'Download a backup of your database as a ZIP file. Select which tables to include.', 'vigilante' ); ?></p>
3647 <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>
3648 </div>
3649 <?php endif; ?>
3650 </div>
3651 <?php
3652 }
3653
3654 /**
3655 * Render firewall tab
3656 */
3657 private function render_tab_firewall() {
3658 $is_disabled = $this->render_module_disabled_notice( 'firewall' );
3659 $options = $this->settings->get_section( 'firewall' );
3660 ?>
3661 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="firewall" <?php echo $is_disabled ? 'inert' : ''; ?>>
3662 <div id="vigilante-section-firewall-main" class="vigilante-settings-section">
3663 <h2>
3664 <?php esc_html_e( 'Firewall Protection', 'vigilante' ); ?>
3665 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
3666 </h2>
3667 <p><?php esc_html_e( 'PHP-based request filtering. Analyzes each request before WordPress loads.', 'vigilante' ); ?></p>
3668 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
3669 <p style="margin:0;">
3670 <?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' ); ?>
3671 </p>
3672 </div>
3673
3674 <?php $vg_main_locked = $this->main_site_files_locked(); ?>
3675 <?php if ( $vg_main_locked ) : ?>
3676 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
3677 <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>
3678 </div>
3679 <?php endif; ?>
3680
3681 <table class="form-table">
3682 <tr>
3683 <th scope="row"><?php esc_html_e( 'Block Bad Query Strings', 'vigilante' ); ?></th>
3684 <td>
3685 <label>
3686 <input type="checkbox" name="firewall[block_bad_query_strings]" value="1" <?php disabled( $vg_main_locked ); ?> <?php checked( ! empty( $options['block_bad_query_strings'] ) ); ?>>
3687 <?php esc_html_e( 'Block malicious query string patterns', 'vigilante' ); ?>
3688 </label>
3689 </td>
3690 </tr>
3691 <tr>
3692 <th scope="row"><?php esc_html_e( 'SQL Injection Protection', 'vigilante' ); ?></th>
3693 <td>
3694 <label>
3695 <input type="checkbox" name="firewall[block_sql_injection]" value="1" <?php checked( ! empty( $options['block_sql_injection'] ) ); ?>>
3696 <?php esc_html_e( 'Block SQL injection attempts', 'vigilante' ); ?>
3697 </label>
3698 </td>
3699 </tr>
3700 <tr>
3701 <th scope="row"><?php esc_html_e( 'XSS Protection', 'vigilante' ); ?></th>
3702 <td>
3703 <label>
3704 <input type="checkbox" name="firewall[block_xss_attacks]" value="1" <?php checked( ! empty( $options['block_xss_attacks'] ) ); ?>>
3705 <?php esc_html_e( 'Block cross-site scripting attacks', 'vigilante' ); ?>
3706 </label>
3707 </td>
3708 </tr>
3709 <tr>
3710 <th scope="row"><?php esc_html_e( 'File Inclusion Protection', 'vigilante' ); ?></th>
3711 <td>
3712 <label>
3713 <input type="checkbox" name="firewall[block_file_inclusion]" value="1" <?php checked( ! empty( $options['block_file_inclusion'] ) ); ?>>
3714 <?php esc_html_e( 'Block local/remote file inclusion attempts', 'vigilante' ); ?>
3715 </label>
3716 </td>
3717 </tr>
3718 <tr>
3719 <th scope="row"><?php esc_html_e( 'Directory Traversal Protection', 'vigilante' ); ?></th>
3720 <td>
3721 <label>
3722 <input type="checkbox" name="firewall[block_directory_traversal]" value="1" <?php checked( ! empty( $options['block_directory_traversal'] ) ); ?>>
3723 <?php esc_html_e( 'Block path traversal attempts', 'vigilante' ); ?>
3724 </label>
3725 </td>
3726 </tr>
3727 <tr>
3728 <th scope="row"><?php esc_html_e( 'Block Bad Bots', 'vigilante' ); ?></th>
3729 <td>
3730 <label>
3731 <input type="checkbox" name="firewall[block_bad_bots]" value="1" <?php disabled( $vg_main_locked ); ?> <?php checked( ! empty( $options['block_bad_bots'] ) ); ?>>
3732 <?php esc_html_e( 'Block known malicious bots and scanners', 'vigilante' ); ?>
3733 </label>
3734 <p class="description"><?php esc_html_e( 'The list also stops SEO crawlers such as Ahrefs, Semrush, Majestic and Screaming Frog, and command line clients such as curl, wget and python-requests. To let one of them through, add its name to the User-Agent Whitelist below. On Apache part of the list is applied in .htaccess, before WordPress loads, so those requests get a 403 and do not appear in the Security Audit.', 'vigilante' ); ?></p>
3735 </td>
3736 </tr>
3737 </table>
3738
3739 <h3><?php esc_html_e( 'Rate Limiting', 'vigilante' ); ?></h3>
3740 <table class="form-table">
3741 <tr>
3742 <th scope="row"><?php esc_html_e( 'Enable Rate Limiting', 'vigilante' ); ?></th>
3743 <td>
3744 <label>
3745 <input type="checkbox" name="firewall[rate_limiting][enabled]" value="1" <?php checked( ! empty( $options['rate_limiting']['enabled'] ) ); ?>>
3746 <?php esc_html_e( 'Limit requests per IP address', 'vigilante' ); ?>
3747 </label>
3748 </td>
3749 </tr>
3750 <tr>
3751 <th scope="row"><label for="vigilante-f-firewall-rate-limiting-requests-per-minute"><?php esc_html_e( 'Requests per Minute', 'vigilante' ); ?></label></th>
3752 <td>
3753 <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">
3754 <p class="description">
3755 <?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' ); ?>
3756 </p>
3757 </td>
3758 </tr>
3759 <tr>
3760 <th scope="row"><label for="vigilante-f-firewall-rate-limiting-block-duration"><?php esc_html_e( 'Block Duration (seconds)', 'vigilante' ); ?></label></th>
3761 <td>
3762 <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">
3763 </td>
3764 </tr>
3765 <tr>
3766 <th scope="row"><?php esc_html_e( 'Progressive Blocking', 'vigilante' ); ?></th>
3767 <td>
3768 <label>
3769 <input type="checkbox" name="firewall[rate_limiting][progressive]" value="1" <?php checked( ! empty( $options['rate_limiting']['progressive'] ) ); ?>>
3770 <?php esc_html_e( 'Double block duration on each repeat offense', 'vigilante' ); ?>
3771 </label>
3772 <p class="description">
3773 <?php
3774 $base = absint( $options['rate_limiting']['block_duration'] ?? 300 );
3775 printf(
3776 /* translators: 1: First block duration, 2: Second, 3: Third */
3777 esc_html__( 'Example: %1$s → %2$s → %3$s and so on, up to the maximum.', 'vigilante' ),
3778 esc_html( human_time_diff( 0, $base ) ),
3779 esc_html( human_time_diff( 0, $base * 2 ) ),
3780 esc_html( human_time_diff( 0, $base * 4 ) )
3781 );
3782 ?>
3783 </p>
3784 </td>
3785 </tr>
3786 <tr>
3787 <th scope="row"><label for="vigilante-f-firewall-rate-limiting-max-block-duration"><?php esc_html_e( 'Maximum Block Duration', 'vigilante' ); ?></label></th>
3788 <td>
3789 <select id="vigilante-f-firewall-rate-limiting-max-block-duration" name="firewall[rate_limiting][max_block_duration]">
3790 <?php
3791 $max_options = array(
3792 3600 => __( '1 hour', 'vigilante' ),
3793 21600 => __( '6 hours', 'vigilante' ),
3794 43200 => __( '12 hours', 'vigilante' ),
3795 86400 => __( '24 hours', 'vigilante' ),
3796 604800 => __( '7 days', 'vigilante' ),
3797 );
3798 $current_max = absint( $options['rate_limiting']['max_block_duration'] ?? 86400 );
3799 foreach ( $max_options as $val => $label ) :
3800 ?>
3801 <option value="<?php echo esc_attr( $val ); ?>" <?php selected( $current_max, $val ); ?>>
3802 <?php echo esc_html( $label ); ?>
3803 </option>
3804 <?php endforeach; ?>
3805 </select>
3806 <p class="description"><?php esc_html_e( 'Upper limit for progressive blocking.', 'vigilante' ); ?></p>
3807 </td>
3808 </tr>
3809 </table>
3810
3811 <?php
3812 // Currently blocked IPs from rate limiting
3813 $active_blocks = Vigilante_Firewall::get_active_blocks();
3814 if ( ! empty( $active_blocks ) ) :
3815 ?>
3816 <div class="vigilante-settings-section vigilante-lockout-section" style="margin-top:20px;">
3817 <h3><?php esc_html_e( 'Currently Blocked IPs', 'vigilante' ); ?></h3>
3818 <table class="wp-list-table widefat fixed striped" style="max-width:800px;">
3819 <thead>
3820 <tr>
3821 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
3822 <th><?php esc_html_e( 'Blocked', 'vigilante' ); ?></th>
3823 <th><?php esc_html_e( 'Expires in', 'vigilante' ); ?></th>
3824 <th><?php esc_html_e( 'Strikes', 'vigilante' ); ?></th>
3825 <th><?php esc_html_e( 'Action', 'vigilante' ); ?></th>
3826 </tr>
3827 </thead>
3828 <tbody>
3829 <?php foreach ( $active_blocks as $blocked_ip => $block_data ) : ?>
3830 <tr>
3831 <td><code><?php echo esc_html( $blocked_ip ); ?></code></td>
3832 <td><?php echo esc_html( human_time_diff( $block_data['blocked_at'] ) . ' ' . __( 'ago', 'vigilante' ) ); ?></td>
3833 <td><?php echo esc_html( human_time_diff( time(), $block_data['expires'] ) ); ?></td>
3834 <td><?php echo esc_html( $block_data['strikes'] ?? 1 ); ?></td>
3835 <td>
3836 <button type="button" class="button button-small vigilante-unblock-firewall-ip"
3837 data-ip="<?php echo esc_attr( $blocked_ip ); ?>">
3838 <?php esc_html_e( 'Unblock', 'vigilante' ); ?>
3839 </button>
3840 </td>
3841 </tr>
3842 <?php endforeach; ?>
3843 </tbody>
3844 </table>
3845 </div>
3846 <?php endif; ?>
3847
3848 <?php
3849 // Since 2.11.8 X-Forwarded-For is read from its end, where the proxy
3850 // writes. The administrator's own request shows whether that end is
3851 // a CDN or a balancer for everybody here. Cross review of 2.11.8.
3852 $xff_readings = $this->forwarded_chain_readings();
3853 if ( $xff_readings ) :
3854 ?>
3855 <div id="vigilante-xff-chain-notice" class="notice notice-warning inline" style="margin:10px 0 16px;padding:8px 12px;">
3856 <p style="margin:0;">
3857 <?php
3858 printf(
3859 /* translators: 1: last address in the header, the one Vigilant reads, 2: first address in the header, which a visitor can write */
3860 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' ),
3861 esc_html( $xff_readings['now'] ),
3862 esc_html( $xff_readings['before'] )
3863 );
3864 ?>
3865 </p>
3866 </div>
3867 <?php endif; ?>
3868
3869 <h3><?php esc_html_e( 'IP Lists', 'vigilante' ); ?></h3>
3870 <p class="description">
3871 <?php
3872 printf(
3873 /* translators: %s: Current visitor IP address */
3874 esc_html__( 'Your current IP address: %s', 'vigilante' ),
3875 '<code>' . esc_html( $this->database->get_client_ip() ) . '</code>'
3876 );
3877 ?>
3878 </p>
3879 <table class="form-table">
3880 <tr>
3881 <th scope="row"><label for="vigilante-f-firewall-trusted-proxy-header"><?php esc_html_e( 'Visitor IP detection', 'vigilante' ); ?></label></th>
3882 <td>
3883 <?php $proxy_header = $options['trusted_proxy_header'] ?? ''; ?>
3884 <select id="vigilante-f-firewall-trusted-proxy-header" name="firewall[trusted_proxy_header]" <?php disabled( $vg_main_locked ); ?>>
3885 <option value="" <?php selected( $proxy_header, '' ); ?>><?php esc_html_e( 'Direct connection, only REMOTE_ADDR (recommended)', 'vigilante' ); ?></option>
3886 <option value="cf-connecting-ip" <?php selected( $proxy_header, 'cf-connecting-ip' ); ?>><?php esc_html_e( 'Behind Cloudflare (CF-Connecting-IP)', 'vigilante' ); ?></option>
3887 <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>
3888 <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>
3889 </select>
3890 <p class="description">
3891 <?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' ); ?>
3892 </p>
3893 </td>
3894 </tr>
3895 <tr>
3896 <th scope="row"><label for="vigilante-f-firewall-trusted-proxies"><?php esc_html_e( 'Trusted proxy IPs', 'vigilante' ); ?></label></th>
3897 <td>
3898 <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>
3899 <p class="description">
3900 <?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' ); ?>
3901 <?php if ( in_array( $proxy_header, array( 'x-forwarded-for', 'x-real-ip' ), true ) && empty( $options['trusted_proxies'] ) ) : ?>
3902 <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>
3903 <?php endif; ?>
3904 </p>
3905 </td>
3906 </tr>
3907 <tr>
3908 <th scope="row"><label for="vigilante-f-firewall-ip-whitelist"><?php esc_html_e( 'IP Whitelist', 'vigilante' ); ?></label></th>
3909 <td>
3910 <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>
3911 <p class="description">
3912 <?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' ); ?>
3913 <br>
3914 <?php
3915 printf(
3916 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the IP, CIDR and wildcard examples. */
3917 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' ),
3918 '<code>',
3919 '</code>'
3920 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
3921 ?>
3922 </p>
3923 </td>
3924 </tr>
3925 <tr>
3926 <th scope="row"><label for="vigilante-f-firewall-ip-blacklist"><?php esc_html_e( 'IP Blacklist', 'vigilante' ); ?></label></th>
3927 <td>
3928 <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>
3929 <p class="description">
3930 <?php esc_html_e( 'One IP per line. These IPs will be blocked immediately.', 'vigilante' ); ?>
3931 <br>
3932 <?php
3933 printf(
3934 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the IP, CIDR and wildcard examples. */
3935 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' ),
3936 '<code>',
3937 '</code>'
3938 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
3939 ?>
3940 </p>
3941 </td>
3942 </tr>
3943 </table>
3944
3945 <h3><?php esc_html_e( 'User-Agent Lists', 'vigilante' ); ?></h3>
3946 <p><?php esc_html_e( 'Partial matching: enter a keyword and any User-Agent containing it will be matched.', 'vigilante' ); ?></p>
3947 <table class="form-table">
3948 <tr>
3949 <th scope="row"><label for="vigilante-f-firewall-ua-whitelist"><?php esc_html_e( 'User-Agent Whitelist', 'vigilante' ); ?></label></th>
3950 <td>
3951 <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>
3952 <p class="description"><?php esc_html_e( 'One User-Agent per line. These will bypass all firewall checks. Example: ManageWP, MainWP, UptimeRobot.', 'vigilante' ); ?></p>
3953 </td>
3954 </tr>
3955 <tr>
3956 <th scope="row"><label for="vigilante-f-firewall-ua-blacklist"><?php esc_html_e( 'User-Agent Blacklist', 'vigilante' ); ?></label></th>
3957 <td>
3958 <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>
3959 <p class="description"><?php esc_html_e( 'One User-Agent per line. These will be blocked immediately.', 'vigilante' ); ?></p>
3960 </td>
3961 </tr>
3962 </table>
3963 </div>
3964
3965 <?php
3966 $vg_shared_locked = $this->shared_files_locked();
3967 // Paint what is actually in force, not this site's unused copy.
3968 $vg_local_options = $options;
3969 $options = $this->get_section_for_display( 'firewall' );
3970 ?>
3971 <?php $this->render_shared_files_notice(); ?>
3972 <div id="vigilante-section-firewall-server" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
3973 <h2>
3974 <?php esc_html_e( 'Server Protection', 'vigilante' ); ?>
3975 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
3976 </h2>
3977 <p><?php esc_html_e( 'Server-level rules for Apache/LiteSpeed. These rules are processed before PHP.', 'vigilante' ); ?></p>
3978
3979 <table class="form-table">
3980 <tr id="field-disable-directory-browsing">
3981 <th scope="row"><?php esc_html_e( 'Directory Browsing', 'vigilante' ); ?></th>
3982 <td>
3983 <label>
3984 <input type="checkbox" name="firewall[disable_directory_browsing]" value="1" <?php checked( ! empty( $options['disable_directory_browsing'] ) ); ?>>
3985 <?php esc_html_e( 'Disable directory listing (Options -Indexes)', 'vigilante' ); ?>
3986 </label>
3987 </td>
3988 </tr>
3989 <tr>
3990 <th scope="row"><?php esc_html_e( 'Protect wp-config.php', 'vigilante' ); ?></th>
3991 <td>
3992 <label>
3993 <input type="checkbox" name="firewall[protect_wp_config]" value="1" <?php checked( ! empty( $options['protect_wp_config'] ) ); ?>>
3994 <?php esc_html_e( 'Block direct HTTP access to wp-config.php', 'vigilante' ); ?>
3995 </label>
3996 </td>
3997 </tr>
3998 <tr id="field-protect-wp-cron">
3999 <th scope="row"><?php esc_html_e( 'Protect wp-cron.php', 'vigilante' ); ?></th>
4000 <td>
4001 <label>
4002 <input type="checkbox" name="firewall[protect_wp_cron]" value="1" <?php checked( ! empty( $options['protect_wp_cron'] ) ); ?>>
4003 <?php esc_html_e( 'Block direct HTTP access to wp-cron.php (prevents cron-spam DoS abuse)', 'vigilante' ); ?>
4004 </label>
4005 <p class="description"><?php
4006 printf(
4007 /* translators: 1: opening <strong>, 2: closing </strong> */
4008 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' ),
4009 '<strong>',
4010 '</strong>',
4011 '<code>',
4012 '</code>'
4013 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
4014 ?></p>
4015 </td>
4016 </tr>
4017 <tr>
4018 <th scope="row"><?php esc_html_e( 'Protect wp-includes', 'vigilante' ); ?></th>
4019 <td>
4020 <label>
4021 <input type="checkbox" name="firewall[protect_wp_includes]" value="1" <?php checked( ! empty( $options['protect_wp_includes'] ) ); ?>>
4022 <?php esc_html_e( 'Block direct access to PHP files in wp-includes', 'vigilante' ); ?>
4023 </label>
4024 </td>
4025 </tr>
4026 <tr>
4027 <th scope="row"><?php esc_html_e( 'PHP in Uploads', 'vigilante' ); ?></th>
4028 <td>
4029 <label>
4030 <input type="checkbox" name="firewall[protect_uploads_php]" value="1" <?php checked( ! empty( $options['protect_uploads_php'] ) ); ?>>
4031 <?php esc_html_e( 'Block PHP execution in wp-content/uploads', 'vigilante' ); ?>
4032 </label>
4033 </td>
4034 </tr>
4035 <tr>
4036 <th scope="row"><?php esc_html_e( 'Sensitive Files', 'vigilante' ); ?></th>
4037 <td>
4038 <label>
4039 <input type="checkbox" name="firewall[protect_sensitive_files]" value="1" <?php checked( ! empty( $options['protect_sensitive_files'] ) ); ?>>
4040 <?php esc_html_e( 'Block access to .sql, .bak, .log, .ini, readme.html, license.txt, licencia.txt', 'vigilante' ); ?>
4041 </label>
4042 </td>
4043 </tr>
4044 <tr>
4045 <th scope="row"><?php esc_html_e( 'Limit HTTP Methods', 'vigilante' ); ?></th>
4046 <td>
4047 <label>
4048 <input type="checkbox" name="firewall[limit_http_methods]" value="1" <?php checked( ! empty( $options['limit_http_methods'] ) ); ?>>
4049 <?php esc_html_e( 'Block the HTTP methods WordPress does not use (TRACE, TRACK, CONNECT and any unknown one). GET, POST, HEAD, OPTIONS, PUT, PATCH and DELETE keep working.', 'vigilante' ); ?>
4050 </label>
4051 </td>
4052 </tr>
4053 </table>
4054 </div>
4055 <?php $options = $vg_local_options; ?>
4056
4057 <p class="submit vigilante-submit-buttons">
4058 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4059 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4060 </button>
4061 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4062 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4063 </button>
4064 </p>
4065 </form>
4066 <?php
4067 }
4068
4069 /**
4070 * Render login security tab
4071 */
4072 private function render_tab_login() {
4073 $is_disabled = $this->render_module_disabled_notice( 'login_security' );
4074 $options = $this->settings->get_section( 'login_security' );
4075 $lockouts = $this->database->get_active_lockouts();
4076 ?>
4077 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="login_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
4078 <div id="vigilante-section-login-main" class="vigilante-settings-section">
4079 <h2>
4080 <?php esc_html_e( 'Login Protection', 'vigilante' ); ?>
4081 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4082 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
4083 </h2>
4084 <p><?php esc_html_e( 'Brute force protection and WordPress login hardening.', 'vigilante' ); ?></p>
4085
4086 <table class="form-table">
4087 <tr id="field-max-attempts">
4088 <th scope="row"><label for="vigilante-f-login-security-max-attempts"><?php esc_html_e( 'Max Login Attempts', 'vigilante' ); ?></label></th>
4089 <td>
4090 <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">
4091 <p class="description"><?php esc_html_e( 'Number of failed attempts before lockout.', 'vigilante' ); ?></p>
4092 </td>
4093 </tr>
4094 <tr>
4095 <th scope="row"><label for="vigilante-f-login-security-lockout-duration"><?php esc_html_e( 'Lockout Duration', 'vigilante' ); ?></label></th>
4096 <td>
4097 <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">
4098 <?php esc_html_e( 'minutes', 'vigilante' ); ?>
4099 </td>
4100 </tr>
4101 <tr>
4102 <th scope="row"><?php esc_html_e( 'Progressive Lockout', 'vigilante' ); ?></th>
4103 <td>
4104 <label>
4105 <input type="checkbox" name="login_security[lockout_increment]" value="1" <?php checked( ! empty( $options['lockout_increment'] ) ); ?>>
4106 <?php esc_html_e( 'Double lockout duration for repeat offenders', 'vigilante' ); ?>
4107 </label>
4108 </td>
4109 </tr>
4110 <tr>
4111 <th scope="row"><?php esc_html_e( 'Hide Login Errors', 'vigilante' ); ?></th>
4112 <td>
4113 <label>
4114 <input type="checkbox" name="login_security[hide_login_errors]" value="1" <?php checked( ! empty( $options['hide_login_errors'] ) ); ?>>
4115 <?php esc_html_e( 'Show generic error message instead of specific errors', 'vigilante' ); ?>
4116 </label>
4117 </td>
4118 </tr>
4119 <tr>
4120 <th scope="row"><?php esc_html_e( 'Disable Application Passwords', 'vigilante' ); ?></th>
4121 <td>
4122 <label>
4123 <input type="checkbox" name="login_security[disable_application_passwords]" value="1" <?php checked( ! empty( $options['disable_application_passwords'] ) ); ?>>
4124 <?php esc_html_e( 'Disable WordPress application passwords feature', 'vigilante' ); ?>
4125 </label>
4126 </td>
4127 </tr>
4128 </table>
4129
4130 <h3><?php esc_html_e( 'Custom Login URL', 'vigilante' ); ?></h3>
4131 <table class="form-table">
4132 <tr id="field-custom-login-url">
4133 <th scope="row"><?php esc_html_e( 'Login URL Slug', 'vigilante' ); ?></th>
4134 <td>
4135 <code><?php echo esc_url( home_url( '/' ) ); ?></code>
4136 <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' ); ?>">
4137 <p class="description">
4138 <?php esc_html_e( '&#9432; Leave empty to use default wp-login.php. Use only lowercase letters, numbers and hyphens.', 'vigilante' ); ?>
4139 </p>
4140 <div class="vigilante-login-url-preview" <?php echo empty( $options['custom_login_url'] ) ? 'style="display:none;"' : ''; ?>>
4141 <p class="description">
4142 <strong><?php esc_html_e( 'Your login URL:', 'vigilante' ); ?></strong>
4143 <code class="vigilante-login-url-display"><?php echo esc_url( home_url( sanitize_title( $options['custom_login_url'] ?? '' ) . '/' ) ); ?></code>
4144 </p>
4145 <p class="description">
4146 <?php esc_html_e( 'Direct access to wp-login.php and wp-admin will return a 404 error for non-logged users.', 'vigilante' ); ?>
4147 </p>
4148 <p class="description">
4149 <?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' ); ?>
4150 </p>
4151 </div>
4152 </td>
4153 </tr>
4154 </table>
4155
4156 <div class="vigilante-login-url-notify-wrapper <?php echo empty( $options['custom_login_url'] ) ? 'vigilante-login-url-notify-disabled' : ''; ?>">
4157 <table class="form-table">
4158 <tr>
4159 <th scope="row"><?php esc_html_e( 'Notify users', 'vigilante' ); ?></th>
4160 <td>
4161 <label>
4162 <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 ); ?>>
4163 <?php esc_html_e( 'Notify affected users when the login URL changes', 'vigilante' ); ?>
4164 </label>
4165 <div class="vigilante-login-url-send-notification" style="margin-top:12px;">
4166 <button type="button" id="vigilante_notify_login_url" class="button">
4167 <?php esc_html_e( 'Send notification now', 'vigilante' ); ?>
4168 </button>
4169 <span class="vigilante-login-url-notify-status"></span>
4170 <p class="description"><?php esc_html_e( 'Sends the new URL to administrators, editors, authors, and contributors.', 'vigilante' ); ?></p>
4171 </div>
4172 </td>
4173 </tr>
4174 </table>
4175 </div>
4176
4177 <?php $this->render_2fa_settings( $options ); ?>
4178
4179 <h3><?php esc_html_e( 'Notifications', 'vigilante' ); ?></h3>
4180 <table class="form-table">
4181 <tr>
4182 <th scope="row"><?php esc_html_e( 'Notify on Lockout', 'vigilante' ); ?></th>
4183 <td>
4184 <label>
4185 <input type="checkbox" name="login_security[notify_on_lockout]" value="1" <?php checked( ! empty( $options['notify_on_lockout'] ) ); ?>>
4186 <?php esc_html_e( 'Send email when an IP is locked out', 'vigilante' ); ?>
4187 </label>
4188 </td>
4189 </tr>
4190 <tr>
4191 <th scope="row"><?php esc_html_e( 'Notify on Admin Login', 'vigilante' ); ?></th>
4192 <td>
4193 <label>
4194 <input type="checkbox" name="login_security[notify_on_admin_login]" value="1" <?php checked( ! empty( $options['notify_on_admin_login'] ) ); ?>>
4195 <?php esc_html_e( 'Send email when an administrator logs in', 'vigilante' ); ?>
4196 </label>
4197 </td>
4198 </tr>
4199 </table>
4200
4201 <p class="description">
4202 <?php
4203 printf(
4204 /* translators: %s: Link to notification settings */
4205 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
4206 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
4207 );
4208 ?>
4209 </p>
4210 </div>
4211
4212 <p class="submit vigilante-submit-buttons">
4213 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4214 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4215 </button>
4216 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4217 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4218 </button>
4219 </p>
4220 </form>
4221
4222 <?php $this->render_lockout_info_section( $options, $lockouts ); ?>
4223 <?php
4224 }
4225
4226 /**
4227 * Render lockout information and blocked IPs section
4228 *
4229 * @param array $options Login security options.
4230 * @param array $lockouts Currently locked out IPs.
4231 */
4232 private function render_lockout_info_section( $options, $lockouts ) {
4233 $max_attempts = absint( $options['max_attempts'] ?? 5 );
4234 $lockout_duration = absint( $options['lockout_duration'] ?? 1800 );
4235 $lockout_increment = ! empty( $options['lockout_increment'] );
4236 $max_lockout = absint( $options['max_lockout_duration'] ?? 86400 );
4237 $two_factor = $options['two_factor'] ?? array();
4238 $two_factor_enabled = ! empty( $two_factor['enabled'] );
4239 ?>
4240 <div class="vigilante-settings-section vigilante-lockout-section">
4241 <h2 id="vigilante-section-login-status"><?php esc_html_e( 'Login Protection Status', 'vigilante' ); ?></h2>
4242
4243 <table class="form-table">
4244 <tr>
4245 <th scope="row"><?php esc_html_e( 'Current settings', 'vigilante' ); ?></th>
4246 <td>
4247 <?php
4248 printf(
4249 /* translators: 1: Maximum login attempts, 2: Lockout duration in minutes */
4250 esc_html__( 'After %1$d failed login attempts, the IP address is blocked for %2$d minutes.', 'vigilante' ),
4251 absint( $max_attempts ),
4252 absint( ceil( $lockout_duration / 60 ) )
4253 );
4254
4255 if ( $lockout_increment ) {
4256 echo '<br>';
4257 printf(
4258 /* translators: %d: Maximum lockout duration in hours */
4259 esc_html__( 'Progressive lockout enabled (max: %d hours).', 'vigilante' ),
4260 absint( ceil( $max_lockout / 3600 ) )
4261 );
4262 }
4263
4264 if ( $two_factor_enabled ) {
4265 echo '<br>';
4266 esc_html_e( 'Failed 2FA codes also count toward the lockout limit.', 'vigilante' );
4267 }
4268 ?>
4269 </td>
4270 </tr>
4271 <tr>
4272 <th scope="row"><?php esc_html_e( 'Blocked IPs', 'vigilante' ); ?></th>
4273 <td>
4274 <?php if ( ! empty( $lockouts ) ) : ?>
4275 <div class="vigilante-paginated-section">
4276 <div class="vigilante-fi-pagination-wrap"></div>
4277 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
4278 <thead>
4279 <tr>
4280 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
4281 <th><?php esc_html_e( 'Attempts', 'vigilante' ); ?></th>
4282 <th><?php esc_html_e( 'Blocked Until', 'vigilante' ); ?></th>
4283 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
4284 </tr>
4285 </thead>
4286 <tbody>
4287 <?php foreach ( $lockouts as $lockout ) :
4288 $lockout_time = strtotime( $lockout->locked_until );
4289 $remaining_seconds = $lockout_time - time();
4290 $remaining_text = $this->format_remaining_time( $remaining_seconds );
4291 ?>
4292 <tr>
4293 <td><code><?php echo esc_html( $lockout->ip_address ); ?></code></td>
4294 <td><?php echo esc_html( $lockout->attempts ); ?></td>
4295 <td>
4296 <?php echo esc_html( wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $lockout_time ) ); ?>
4297 <br>
4298 <small class="description">
4299 <?php
4300 printf(
4301 /* translators: %s: Remaining time */
4302 esc_html__( '%s remaining', 'vigilante' ),
4303 esc_html( $remaining_text )
4304 );
4305 ?>
4306 </small>
4307 </td>
4308 <td>
4309 <button type="button" class="button button-small vigilante-clear-lockout" data-ip="<?php echo esc_attr( $lockout->ip_address ); ?>">
4310 <?php esc_html_e( 'Unblock', 'vigilante' ); ?>
4311 </button>
4312 </td>
4313 </tr>
4314 <?php endforeach; ?>
4315 </tbody>
4316 </table>
4317 </div>
4318 <p class="description" style="margin-top: 10px;">
4319 <button type="button" class="button vigilante-clear-all-lockouts">
4320 <?php esc_html_e( 'Unblock All IPs', 'vigilante' ); ?>
4321 </button>
4322 <span style="margin-left: 10px;">
4323 <?php
4324 printf(
4325 /* translators: %d: Number of blocked IPs */
4326 esc_html( _n( '%d IP currently blocked', '%d IPs currently blocked', count( $lockouts ), 'vigilante' ) ),
4327 count( $lockouts )
4328 );
4329 ?>
4330 </span>
4331 </p>
4332 <?php else : ?>
4333 <span class="dashicons dashicons-yes-alt" style="color: #00a32a; font-size: 20px; width: 20px; height: 20px; vertical-align: middle;"></span>
4334 <span style="vertical-align: middle; margin-left: 5px;"><?php esc_html_e( 'No IPs are currently blocked. All clear!', 'vigilante' ); ?></span>
4335 <?php endif; ?>
4336 </td>
4337 </tr>
4338 </table>
4339 </div>
4340 <?php
4341 }
4342
4343 /**
4344 * Format remaining lockout time in human readable format
4345 *
4346 * @param int $seconds Remaining seconds.
4347 * @return string Formatted time string.
4348 */
4349 private function format_remaining_time( $seconds ) {
4350 if ( $seconds <= 0 ) {
4351 return __( 'expired', 'vigilante' );
4352 }
4353
4354 if ( $seconds < 60 ) {
4355 return sprintf(
4356 /* translators: %d: Number of seconds */
4357 _n( '%d second', '%d seconds', $seconds, 'vigilante' ),
4358 $seconds
4359 );
4360 }
4361
4362 if ( $seconds < 3600 ) {
4363 $minutes = ceil( $seconds / 60 );
4364 return sprintf(
4365 /* translators: %d: Number of minutes */
4366 _n( '%d minute', '%d minutes', $minutes, 'vigilante' ),
4367 $minutes
4368 );
4369 }
4370
4371 $hours = floor( $seconds / 3600 );
4372 $remaining_minutes = ceil( ( $seconds % 3600 ) / 60 );
4373
4374 if ( $remaining_minutes > 0 ) {
4375 return sprintf(
4376 /* translators: 1: Number of hours, 2: Number of minutes */
4377 __( '%1$d hours %2$d minutes', 'vigilante' ),
4378 $hours,
4379 $remaining_minutes
4380 );
4381 }
4382
4383 return sprintf(
4384 /* translators: %d: Number of hours */
4385 _n( '%d hour', '%d hours', $hours, 'vigilante' ),
4386 $hours
4387 );
4388 }
4389
4390 /**
4391 * Render 2FA settings section
4392 *
4393 * @param array $options Login security options.
4394 */
4395 private function render_2fa_settings( $options ) {
4396 $two_factor = $options['two_factor'] ?? array();
4397 $all_roles = wp_roles()->roles;
4398 $enforced = $two_factor['enforced_roles'] ?? array( 'administrator', 'editor' );
4399 $excluded = $two_factor['excluded_users'] ?? array();
4400 $method = $two_factor['method'] ?? 'email';
4401 $grace_days = $two_factor['grace_period_days'] ?? 3;
4402 ?>
4403 <h3 id="vigilante-section-login-2fa">
4404 <?php esc_html_e( 'Two-Factor Authentication (2FA)', 'vigilante' ); ?>
4405 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4406 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
4407 </h3>
4408 <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>
4409
4410 <table class="form-table">
4411 <tr>
4412 <th scope="row"><?php esc_html_e( 'Enable 2FA', 'vigilante' ); ?></th>
4413 <td>
4414 <label>
4415 <input type="checkbox" name="login_security[two_factor][enabled]" id="vigilante_2fa_enabled" value="1" <?php checked( ! empty( $two_factor['enabled'] ) ); ?>>
4416 <?php esc_html_e( 'Enable two-factor authentication', 'vigilante' ); ?>
4417 </label>
4418 </td>
4419 </tr>
4420 </table>
4421
4422 <div class="vigilante-2fa-settings-wrapper <?php echo empty( $two_factor['enabled'] ) ? 'vigilante-2fa-settings-disabled' : ''; ?>">
4423 <table class="form-table">
4424 <tr>
4425 <th scope="row"><?php esc_html_e( 'Verification method', 'vigilante' ); ?></th>
4426 <td>
4427 <fieldset class="vigilante-2fa-method-selector">
4428 <label class="vigilante-2fa-method-option <?php echo 'email' === $method ? 'selected' : ''; ?>">
4429 <input type="radio" name="login_security[two_factor][method]" value="email" <?php checked( $method, 'email' ); ?>>
4430 <span class="dashicons dashicons-email"></span>
4431 <span class="method-info">
4432 <strong><?php esc_html_e( 'Email code', 'vigilante' ); ?></strong>
4433 <span><?php esc_html_e( 'Users receive a 6-digit code via email after entering their password.', 'vigilante' ); ?></span>
4434 </span>
4435 </label>
4436 <label class="vigilante-2fa-method-option <?php echo 'totp' === $method ? 'selected' : ''; ?>">
4437 <input type="radio" name="login_security[two_factor][method]" value="totp" <?php checked( $method, 'totp' ); ?>>
4438 <span class="dashicons dashicons-smartphone"></span>
4439 <span class="method-info">
4440 <strong><?php esc_html_e( 'Authenticator app (TOTP)', 'vigilante' ); ?></strong>
4441 <span><?php esc_html_e( 'Users verify with a time-based code from Google Authenticator, Authy, etc.', 'vigilante' ); ?></span>
4442 </span>
4443 </label>
4444 </fieldset>
4445 </td>
4446 </tr>
4447 <tr>
4448 <th scope="row"><?php esc_html_e( 'Enforce for roles', 'vigilante' ); ?></th>
4449 <td>
4450 <div class="vigilante-2fa-roles">
4451 <?php $this->list_sentinel( 'login_security[two_factor][enforced_roles]' ); ?>
4452 <?php foreach ( $all_roles as $role_slug => $role_data ) :
4453 $user_count = count( get_users( array( 'role' => $role_slug, 'fields' => 'ID' ) ) );
4454 ?>
4455 <label>
4456 <input type="checkbox"
4457 name="login_security[two_factor][enforced_roles][]"
4458 value="<?php echo esc_attr( $role_slug ); ?>"
4459 <?php checked( in_array( $role_slug, $enforced, true ) ); ?>>
4460 <span class="role-name"><?php echo esc_html( translate_user_role( $role_data['name'] ) ); ?></span>
4461 <span class="role-count">(<?php echo esc_html( $user_count ); ?>)</span>
4462 </label>
4463 <?php endforeach; ?>
4464 </div>
4465 <p class="description"><?php esc_html_e( 'Users with these roles will be required to verify with the selected method.', 'vigilante' ); ?></p>
4466 </td>
4467 </tr>
4468 <tr>
4469 <th scope="row"><?php esc_html_e( 'Exclude specific users', 'vigilante' ); ?></th>
4470 <td>
4471 <div class="vigilante-2fa-user-search-container">
4472 <div class="vigilante-2fa-user-search">
4473 <span class="search-icon"></span>
4474 <input type="text"
4475 id="vigilante_2fa_user_search"
4476 placeholder="<?php esc_attr_e( 'Search users by name or email...', 'vigilante' ); ?>"
4477 autocomplete="off">
4478 <div class="vigilante-2fa-search-results"></div>
4479 </div>
4480 <div class="vigilante-2fa-excluded-users">
4481 <?php $this->list_sentinel( 'login_security[two_factor][excluded_users]' ); ?>
4482 <?php
4483 foreach ( $excluded as $user_id ) :
4484 $user = get_user_by( 'ID', $user_id );
4485 if ( ! $user ) continue;
4486 ?>
4487 <div class="vigilante-2fa-excluded-user" data-user-id="<?php echo esc_attr( $user_id ); ?>">
4488 <span class="user-display"><?php echo esc_html( $user->display_name . ' (' . $user->user_email . ')' ); ?></span>
4489 <button type="button" class="remove-user" aria-label="<?php esc_attr_e( 'Remove', 'vigilante' ); ?>">&times;</button>
4490 <input type="hidden" name="login_security[two_factor][excluded_users][]" value="<?php echo esc_attr( $user_id ); ?>">
4491 </div>
4492 <?php endforeach; ?>
4493 </div>
4494 </div>
4495 <p class="description"><?php esc_html_e( 'These users will not be required to use 2FA regardless of their role.', 'vigilante' ); ?></p>
4496 </td>
4497 </tr>
4498
4499 <!-- Remember device option -->
4500 <tr>
4501 <th scope="row"><?php esc_html_e( 'Remember device', 'vigilante' ); ?></th>
4502 <td>
4503 <label>
4504 <input type="checkbox" name="login_security[two_factor][allow_remember_device]" value="1" <?php checked( ! empty( $two_factor['allow_remember_device'] ) ); ?>>
4505 <?php esc_html_e( 'Allow users to skip 2FA verification on trusted devices', 'vigilante' ); ?>
4506 </label>
4507 <p class="description">
4508 <?php
4509 printf(
4510 /* translators: %d: Number of days */
4511 esc_html__( 'When enabled, users can check "Remember this device" on the verification screen to skip 2FA for %d days.', 'vigilante' ),
4512 absint( $two_factor['remember_device_days'] ?? 30 )
4513 );
4514 ?>
4515 </p>
4516 </td>
4517 </tr>
4518
4519 <!-- TOTP-specific: Grace period -->
4520 <tr class="vigilante-2fa-totp-only" <?php echo 'totp' !== $method ? 'style="display:none;"' : ''; ?>>
4521 <th scope="row"><label for="vigilante-f-login-security-two-factor-grace-period-days"><?php esc_html_e( 'Grace period', 'vigilante' ); ?></label></th>
4522 <td>
4523 <input id="vigilante-f-login-security-two-factor-grace-period-days" type="number"
4524 name="login_security[two_factor][grace_period_days]"
4525 value="<?php echo esc_attr( $grace_days ); ?>"
4526 min="0" max="30" class="small-text">
4527 <?php esc_html_e( 'days', 'vigilante' ); ?>
4528 <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>
4529 </td>
4530 </tr>
4531
4532 <!-- Email-specific: Sender name -->
4533 <tr class="vigilante-2fa-email-only" <?php echo 'email' !== $method ? 'style="display:none;"' : ''; ?>>
4534 <th scope="row"><label for="vigilante-f-login-security-two-factor-email-from-name"><?php esc_html_e( 'Email sender name', 'vigilante' ); ?></label></th>
4535 <td>
4536 <input id="vigilante-f-login-security-two-factor-email-from-name" type="text"
4537 name="login_security[two_factor][email_from_name]"
4538 value="<?php echo esc_attr( $two_factor['email_from_name'] ?? '' ); ?>"
4539 class="regular-text vigilante-2fa-email-from"
4540 placeholder="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>">
4541 <p class="description"><?php esc_html_e( 'Name shown in verification emails. Leave empty to use site name.', 'vigilante' ); ?></p>
4542 </td>
4543 </tr>
4544
4545 <!-- TOTP-specific: Reset users -->
4546 <tr class="vigilante-2fa-totp-only" <?php echo 'totp' !== $method ? 'style="display:none;"' : ''; ?>>
4547 <th scope="row"><?php esc_html_e( 'Reset user TOTP', 'vigilante' ); ?></th>
4548 <td>
4549 <div class="vigilante-totp-reset-container">
4550 <div class="vigilante-2fa-user-search">
4551 <span class="search-icon"></span>
4552 <input type="text"
4553 id="vigilante_totp_reset_search"
4554 placeholder="<?php esc_attr_e( 'Search users with TOTP configured...', 'vigilante' ); ?>"
4555 autocomplete="off">
4556 <div class="vigilante-totp-reset-results"></div>
4557 </div>
4558 <div class="vigilante-totp-reset-selected"></div>
4559 <button type="button" id="vigilante_totp_reset_btn" class="button" style="display:none;">
4560 <?php esc_html_e( 'Reset selected', 'vigilante' ); ?>
4561 </button>
4562 <span class="vigilante-totp-reset-status"></span>
4563 </div>
4564 <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>
4565 </td>
4566 </tr>
4567 </table>
4568
4569 <h3><?php esc_html_e( 'User notification', 'vigilante' ); ?></h3>
4570 <table class="form-table">
4571 <tr>
4572 <th scope="row"><?php esc_html_e( 'Notify on enable', 'vigilante' ); ?></th>
4573 <td>
4574 <label>
4575 <input type="checkbox" name="login_security[two_factor][notify_on_enable]" value="1" <?php checked( $two_factor['notify_on_enable'] ?? true ); ?>>
4576 <?php esc_html_e( 'Send notification email to affected users when 2FA is enabled', 'vigilante' ); ?>
4577 </label>
4578
4579 <div class="vigilante-2fa-notification-options">
4580 <label>
4581 <input type="radio" name="vigilante_2fa_notify_mode" value="all" checked>
4582 <?php esc_html_e( 'Send to all affected users', 'vigilante' ); ?>
4583 </label>
4584 <label>
4585 <input type="radio" name="vigilante_2fa_notify_mode" value="new">
4586 <?php esc_html_e( 'Send only to users not previously notified', 'vigilante' ); ?>
4587 </label>
4588 </div>
4589
4590 <div class="vigilante-2fa-send-notification">
4591 <button type="button" id="vigilante_2fa_send_notification" class="button">
4592 <?php esc_html_e( 'Send notification now', 'vigilante' ); ?>
4593 </button>
4594 <span class="vigilante-2fa-notification-status"></span>
4595 </div>
4596 </td>
4597 </tr>
4598 </table>
4599 </div>
4600 <?php
4601 }
4602
4603 /**
4604 * Render security headers tab
4605 */
4606 /**
4607 * Offer back the header settings the 2.9.8 migration wiped.
4608 *
4609 * Rendered outside the settings form on purpose, so its buttons can never
4610 * submit it, and only when there is something to actually change. Shows the
4611 * difference before anything is written: nothing is applied that the owner
4612 * has not seen first.
4613 *
4614 * @since 2.10.0
4615 */
4616 private function render_headers_recovery_offer() {
4617 /*
4618 * On a network the .htaccess belongs to every site and only the main one
4619 * writes it, so this is not a decision a subsite gets to make. Its own
4620 * security_headers options are inert anyway: what the network serves
4621 * comes from the file the main site owns. Without this gate a subsite
4622 * administrator was shown a Restore button that could only ever answer
4623 * with a permission error, which is worse than showing nothing.
4624 */
4625 if ( ! Vigilante_Settings::can_write_shared_files() ) {
4626 return;
4627 }
4628
4629 if ( ! Vigilante_Htaccess_Recovery::is_available() ) {
4630 /*
4631 * Already restored. Offer to take it back for as long as the previous
4632 * section is still stored: a restore that cannot be undone is a second
4633 * irreversible change on top of the one being repaired.
4634 */
4635 if ( Vigilante_Htaccess_Recovery::has_undo() ) {
4636 ?>
4637 <div class="notice notice-info inline" id="vigilante-headers-recovery-undo">
4638 <p>
4639 <?php esc_html_e( 'The Security Headers settings were restored from the copy Vigilant had kept of your .htaccess.', 'vigilante' ); ?>
4640 <button type="button" class="button button-small" id="vigilante-recovery-undo">
4641 <?php esc_html_e( 'Undo the restore', 'vigilante' ); ?>
4642 </button>
4643 </p>
4644 </div>
4645 <?php
4646 }
4647
4648 return;
4649 }
4650
4651 $rows = Vigilante_Htaccess_Recovery::get_diff( $this->settings );
4652
4653 if ( empty( $rows ) ) {
4654 return;
4655 }
4656
4657 $snapshot = Vigilante_Htaccess_Recovery::get_snapshot();
4658 $taken = isset( $snapshot['time'] ) ? (int) $snapshot['time'] : 0;
4659 $block = Vigilante_Htaccess_Recovery::get_raw_block();
4660 ?>
4661 <div class="vigilante-settings-section" id="vigilante-headers-recovery">
4662 <h2><?php esc_html_e( 'Recover your previous header settings', 'vigilante' ); ?></h2>
4663 <p>
4664 <?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' ); ?>
4665 </p>
4666 <?php if ( $taken ) : ?>
4667 <p class="description">
4668 <?php
4669 printf(
4670 /* translators: %s: date and time the .htaccess copy was taken. */
4671 esc_html__( 'Copy taken on %s.', 'vigilante' ),
4672 esc_html( wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $taken ) )
4673 );
4674 ?>
4675 </p>
4676 <?php endif; ?>
4677
4678 <table class="widefat striped">
4679 <thead>
4680 <tr>
4681 <th scope="col"><?php esc_html_e( 'Setting', 'vigilante' ); ?></th>
4682 <th scope="col"><?php esc_html_e( 'Now', 'vigilante' ); ?></th>
4683 <th scope="col"><?php esc_html_e( 'Would be restored to', 'vigilante' ); ?></th>
4684 </tr>
4685 </thead>
4686 <tbody>
4687 <?php foreach ( $rows as $row ) : ?>
4688 <tr>
4689 <th scope="row"><?php echo esc_html( $row['label'] ); ?></th>
4690 <td><?php echo esc_html( $row['current'] ); ?></td>
4691 <td>
4692 <?php echo esc_html( $row['recovered'] ); ?>
4693 <?php if ( ! empty( $row['detail'] ) ) : ?>
4694 <br><span class="description"><?php echo esc_html( $row['detail'] ); ?></span>
4695 <?php endif; ?>
4696 </td>
4697 </tr>
4698 <?php endforeach; ?>
4699 </tbody>
4700 </table>
4701
4702 <p class="description">
4703 <?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' ); ?>
4704 </p>
4705
4706 <?php if ( '' !== $block ) : ?>
4707 <details>
4708 <summary><?php esc_html_e( 'Show the saved .htaccess block', 'vigilante' ); ?></summary>
4709 <textarea readonly rows="12" class="large-text code" onclick="this.select();"><?php echo esc_textarea( $block ); ?></textarea>
4710 </details>
4711 <?php endif; ?>
4712
4713 <p class="submit vigilante-submit-buttons">
4714 <button type="button" class="button button-primary" id="vigilante-recovery-restore">
4715 <?php esc_html_e( 'Restore these settings', 'vigilante' ); ?>
4716 </button>
4717 <button type="button" class="button" id="vigilante-recovery-dismiss">
4718 <?php esc_html_e( 'No thanks, keep what I have', 'vigilante' ); ?>
4719 </button>
4720 </p>
4721 <div id="vigilante-recovery-result"></div>
4722 </div>
4723 <?php
4724 }
4725
4726 private function render_tab_headers() {
4727 $is_disabled = $this->render_module_disabled_notice( 'security_headers' );
4728 // Every setting on this tab ends up in .htaccess, so on a subsite the
4729 // whole tab is somebody else's, values included.
4730 $vg_shared_locked = $this->shared_files_locked();
4731 $options = $this->get_section_for_display( 'security_headers' );
4732 ?>
4733 <?php $this->render_headers_recovery_offer(); ?>
4734
4735 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="security_headers" <?php echo $is_disabled ? 'inert' : ''; ?>>
4736 <?php $this->render_shared_files_notice(); ?>
4737 <div id="vigilante-section-headers-main" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
4738 <h2>
4739 <?php esc_html_e( 'Security Headers', 'vigilante' ); ?>
4740 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
4741 </h2>
4742 <p><?php esc_html_e( 'HTTP headers sent with every response via .htaccess (mod_headers).', 'vigilante' ); ?></p>
4743
4744 <table class="form-table">
4745 <tr>
4746 <th scope="row"><label for="vigilante-f-security-headers-x-frame-options"><?php esc_html_e( 'X-Frame-Options', 'vigilante' ); ?></label></th>
4747 <td>
4748 <select id="vigilante-f-security-headers-x-frame-options" name="security_headers[x_frame_options]">
4749 <option value="" <?php selected( empty( $options['x_frame_options'] ) ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
4750 <option value="SAMEORIGIN" <?php selected( $options['x_frame_options'] ?? '', 'SAMEORIGIN' ); ?>>SAMEORIGIN</option>
4751 <option value="DENY" <?php selected( $options['x_frame_options'] ?? '', 'DENY' ); ?>>DENY</option>
4752 </select>
4753 <p class="description"><?php esc_html_e( '&#9432; Prevents clickjacking attacks. Also sets CSP frame-ancestors automatically.', 'vigilante' ); ?></p>
4754 </td>
4755 </tr>
4756 <tr>
4757 <th scope="row"><?php esc_html_e( 'X-Content-Type-Options', 'vigilante' ); ?></th>
4758 <td>
4759 <label>
4760 <input type="checkbox" name="security_headers[x_content_type_options]" value="1" <?php checked( ! empty( $options['x_content_type_options'] ) ); ?>>
4761 <?php esc_html_e( 'Add nosniff header to prevent MIME type sniffing', 'vigilante' ); ?>
4762 </label>
4763 </td>
4764 </tr>
4765 <tr>
4766 <th scope="row"><label for="vigilante-f-security-headers-referrer-policy"><?php esc_html_e( 'Referrer-Policy', 'vigilante' ); ?></label></th>
4767 <td>
4768 <select id="vigilante-f-security-headers-referrer-policy" name="security_headers[referrer_policy]">
4769 <option value="" <?php selected( empty( $options['referrer_policy'] ) ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
4770 <option value="no-referrer" <?php selected( $options['referrer_policy'] ?? '', 'no-referrer' ); ?>>no-referrer</option>
4771 <option value="strict-origin-when-cross-origin" <?php selected( $options['referrer_policy'] ?? '', 'strict-origin-when-cross-origin' ); ?>>strict-origin-when-cross-origin</option>
4772 <option value="same-origin" <?php selected( $options['referrer_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
4773 </select>
4774 </td>
4775 </tr>
4776 </table>
4777
4778 <h3 id="vigilante-section-headers-csp"><?php esc_html_e( 'Content Security Policy', 'vigilante' ); ?></h3>
4779 <table class="form-table">
4780 <tr>
4781 <th scope="row"><?php esc_html_e( 'Enable CSP', 'vigilante' ); ?></th>
4782 <td>
4783 <label>
4784 <input type="checkbox" name="security_headers[csp][enabled]" value="1" <?php checked( ! empty( $options['csp']['enabled'] ) ); ?>>
4785 <?php esc_html_e( 'Enable Content Security Policy', 'vigilante' ); ?>
4786 </label>
4787 <p class="description"><?php esc_html_e( 'The default policy includes upgrade-insecure-requests, which asks browsers to request every http:// resource over https. Vigilant writes it only when the site address starts with https://, because on a site served over http it would stop every stylesheet, script and image from loading. If your site is served over https through a proxy or CDN that terminates TLS, set the site address to https:// in Settings > General; the rules follow the next time this tab is saved or Vigilant is updated.', 'vigilante' ); ?></p>
4788 </td>
4789 </tr>
4790 <tr>
4791 <th scope="row"><?php esc_html_e( 'Report Only Mode', 'vigilante' ); ?></th>
4792 <td>
4793 <label>
4794 <input type="checkbox" name="security_headers[csp][report_only]" value="1" <?php checked( ! empty( $options['csp']['report_only'] ) ); ?>>
4795 <?php esc_html_e( 'Report violations without blocking (for testing)', 'vigilante' ); ?>
4796 </label>
4797 </td>
4798 </tr>
4799 </table>
4800
4801 <h3 id="vigilante-section-headers-force-https"><?php esc_html_e( 'HTTPS', 'vigilante' ); ?></h3>
4802 <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>
4803 <table class="form-table">
4804 <tr>
4805 <th scope="row"><?php esc_html_e( 'Redirect HTTP to HTTPS', 'vigilante' ); ?></th>
4806 <td>
4807 <label>
4808 <input type="checkbox" name="security_headers[redirect_http_to_https]" value="1" <?php checked( ! empty( $options['redirect_http_to_https'] ) ); ?>>
4809 <?php esc_html_e( 'Send visitors arriving over HTTP to the HTTPS address', 'vigilante' ); ?>
4810 </label>
4811 <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>
4812 </td>
4813 </tr>
4814 <tr>
4815 <th scope="row"><?php esc_html_e( 'Fix Mixed Content', 'vigilante' ); ?></th>
4816 <td>
4817 <label>
4818 <input type="checkbox" name="security_headers[fix_mixed_content]" value="1" <?php checked( ! empty( $options['fix_mixed_content'] ) ); ?>>
4819 <?php esc_html_e( 'Rewrite this site http:// resources to https://', 'vigilante' ); ?>
4820 </label>
4821 <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>
4822 </td>
4823 </tr>
4824 <tr id="field-upgrade-insecure-requests">
4825 <th scope="row"><?php esc_html_e( 'Upgrade Insecure Requests', 'vigilante' ); ?></th>
4826 <td>
4827 <label>
4828 <input type="checkbox" name="security_headers[upgrade_insecure_requests]" value="1" <?php checked( ! empty( $options['upgrade_insecure_requests'] ) ); ?>>
4829 <?php esc_html_e( 'Ask browsers to upgrade every http:// request to https://', 'vigilante' ); ?>
4830 </label>
4831 <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>
4832 </td>
4833 </tr>
4834 <tr>
4835 <th scope="row"><?php esc_html_e( 'Rewrite Site Address on Activation', 'vigilante' ); ?></th>
4836 <td>
4837 <label>
4838 <input type="checkbox" name="security_headers[force_https]" value="1" <?php checked( ! empty( $options['force_https'] ) ); ?>>
4839 <?php esc_html_e( 'Change the WordPress and site addresses to https:// when the plugin is activated', 'vigilante' ); ?>
4840 </label>
4841 <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>
4842 </td>
4843 </tr>
4844 </table>
4845
4846 <h3 id="vigilante-section-headers-hsts"><?php esc_html_e( 'HSTS (HTTP Strict Transport Security)', 'vigilante' ); ?></h3>
4847 <?php $vig_home_https = ( 0 === strpos( (string) get_option( 'home' ), 'https://' ) ); ?>
4848 <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>
4849 <?php if ( ! $vig_home_https ) : ?>
4850 <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>
4851 <?php endif; ?>
4852 <table class="form-table">
4853 <tr>
4854 <th scope="row"><?php esc_html_e( 'Enable HSTS', 'vigilante' ); ?></th>
4855 <td>
4856 <?php if ( ! $vig_home_https ) : ?>
4857 <?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. */ ?>
4858 <input type="hidden" name="security_headers[hsts][enabled]" value="<?php echo ! empty( $options['hsts']['enabled'] ) ? '1' : '0'; ?>">
4859 <?php endif; ?>
4860 <label>
4861 <input type="checkbox" name="security_headers[hsts][enabled]" value="1" <?php checked( ! empty( $options['hsts']['enabled'] ) ); ?> <?php disabled( ! $vig_home_https ); ?>>
4862 <?php esc_html_e( 'Send the Strict-Transport-Security header', 'vigilante' ); ?>
4863 </label>
4864 <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>
4865 </td>
4866 </tr>
4867 <tr>
4868 <th scope="row"><label for="vigilante-f-security-headers-hsts-max-age"><?php esc_html_e( 'Max Age', 'vigilante' ); ?></label></th>
4869 <td>
4870 <select id="vigilante-f-security-headers-hsts-max-age" name="security_headers[hsts][max_age]">
4871 <option value="86400" <?php selected( $options['hsts']['max_age'] ?? 31536000, 86400 ); ?>><?php esc_html_e( '1 day (testing)', 'vigilante' ); ?></option>
4872 <option value="2592000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 2592000 ); ?>><?php esc_html_e( '30 days', 'vigilante' ); ?></option>
4873 <option value="31536000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 31536000 ); ?>><?php esc_html_e( '1 year (recommended)', 'vigilante' ); ?></option>
4874 <option value="63072000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 63072000 ); ?>><?php esc_html_e( '2 years', 'vigilante' ); ?></option>
4875 </select>
4876 </td>
4877 </tr>
4878 <tr>
4879 <th scope="row"><?php esc_html_e( 'Include Subdomains', 'vigilante' ); ?></th>
4880 <td>
4881 <label>
4882 <input type="checkbox" name="security_headers[hsts][include_subdomains]" value="1" <?php checked( ! empty( $options['hsts']['include_subdomains'] ) ); ?>>
4883 <?php esc_html_e( 'Apply HSTS to all subdomains', 'vigilante' ); ?>
4884 </label>
4885 </td>
4886 </tr>
4887 </table>
4888
4889 <h3 id="vigilante-section-headers-fingerprint"><?php esc_html_e( 'Server Identity', 'vigilante' ); ?></h3>
4890 <p class="description"><?php esc_html_e( 'Hide identifying information that servers expose in responses.', 'vigilante' ); ?></p>
4891 <table class="form-table">
4892 <tr>
4893 <th scope="row"><?php esc_html_e( 'Server Signature', 'vigilante' ); ?></th>
4894 <td>
4895 <label>
4896 <input type="checkbox" name="security_headers[hide_server_signature]" value="1" <?php checked( ! empty( $options['hide_server_signature'] ) ); ?>>
4897 <?php esc_html_e( 'Hide server signature (ServerSignature Off)', 'vigilante' ); ?>
4898 </label>
4899 </td>
4900 </tr>
4901 <tr>
4902 <th scope="row"><?php esc_html_e( 'Remove Fingerprinting Headers', 'vigilante' ); ?></th>
4903 <td>
4904 <label>
4905 <input type="checkbox" name="security_headers[remove_fingerprinting_headers]" value="1" <?php checked( ! empty( $options['remove_fingerprinting_headers'] ) ); ?>>
4906 <?php esc_html_e( 'Remove X-Powered-By and Server headers', 'vigilante' ); ?>
4907 </label>
4908 </td>
4909 </tr>
4910 </table>
4911 </div>
4912
4913 <?php $vg_cop = ( isset( $options['cross_origin_policies'] ) && is_array( $options['cross_origin_policies'] ) ) ? $options['cross_origin_policies'] : array(); ?>
4914 <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' : ''; ?>>
4915 <h2>
4916 <?php esc_html_e( 'Cross-Origin Policies', 'vigilante' ); ?>
4917 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
4918 </h2>
4919 <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>
4920
4921 <table class="form-table">
4922 <tr>
4923 <th scope="row"><label for="vigilante-f-security-headers-coop"><?php esc_html_e( 'Cross-Origin-Opener-Policy (COOP)', 'vigilante' ); ?></label></th>
4924 <td>
4925 <select id="vigilante-f-security-headers-coop" name="security_headers[cross_origin_policies][opener_policy]">
4926 <option value="" <?php selected( empty( $vg_cop['opener_policy'] ) ); ?>><?php esc_html_e( 'Disabled (header not sent)', 'vigilante' ); ?></option>
4927 <option value="unsafe-none" <?php selected( $vg_cop['opener_policy'] ?? '', 'unsafe-none' ); ?>>unsafe-none</option>
4928 <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>
4929 <option value="same-origin" <?php selected( $vg_cop['opener_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
4930 </select>
4931 <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>
4932 </td>
4933 </tr>
4934 <tr>
4935 <th scope="row"><label for="vigilante-f-security-headers-coep"><?php esc_html_e( 'Cross-Origin-Embedder-Policy (COEP)', 'vigilante' ); ?></label></th>
4936 <td>
4937 <select id="vigilante-f-security-headers-coep" name="security_headers[cross_origin_policies][embedder_policy]">
4938 <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>
4939 <option value="credentialless" <?php selected( $vg_cop['embedder_policy'] ?? '', 'credentialless' ); ?>>credentialless</option>
4940 <option value="require-corp" <?php selected( $vg_cop['embedder_policy'] ?? '', 'require-corp' ); ?>>require-corp</option>
4941 </select>
4942 <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>
4943 </td>
4944 </tr>
4945 <tr>
4946 <th scope="row"><label for="vigilante-f-security-headers-corp"><?php esc_html_e( 'Cross-Origin-Resource-Policy (CORP)', 'vigilante' ); ?></label></th>
4947 <td>
4948 <select id="vigilante-f-security-headers-corp" name="security_headers[cross_origin_policies][resource_policy]">
4949 <option value="" <?php selected( empty( $vg_cop['resource_policy'] ) ); ?>><?php esc_html_e( 'Disabled (header not sent)', 'vigilante' ); ?></option>
4950 <option value="same-site" <?php selected( $vg_cop['resource_policy'] ?? '', 'same-site' ); ?>>same-site</option>
4951 <option value="same-origin" <?php selected( $vg_cop['resource_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
4952 <option value="cross-origin" <?php selected( $vg_cop['resource_policy'] ?? '', 'cross-origin' ); ?>><?php esc_html_e( 'cross-origin (recommended)', 'vigilante' ); ?></option>
4953 </select>
4954 <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>
4955 </td>
4956 </tr>
4957 </table>
4958 </div>
4959
4960 <p class="submit vigilante-submit-buttons">
4961 <?php if ( ! $vg_shared_locked ) : ?>
4962 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4963 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4964 </button>
4965 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4966 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4967 </button>
4968 <?php endif; ?>
4969 <?php /* Testing what the server actually sends is read-only and useful from any site of a network. */ ?>
4970 <button type="button" class="button vigilante-test-headers">
4971 <?php esc_html_e( 'Test Headers', 'vigilante' ); ?>
4972 </button>
4973 </p>
4974 </form>
4975
4976 <div id="vigilante-headers-result"></div>
4977 <?php
4978 }
4979
4980 /**
4981 * Render REST API tab
4982 */
4983 private function render_tab_rest_api() {
4984 $is_disabled = $this->render_module_disabled_notice( 'rest_api_security' );
4985 $options = $this->settings->get_section( 'rest_api_security' );
4986 ?>
4987 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="rest_api_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
4988 <div id="vigilante-section-rest-api-main" class="vigilante-settings-section">
4989 <h2>
4990 <?php esc_html_e( 'REST API Security', 'vigilante' ); ?>
4991 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4992 </h2>
4993 <p><?php esc_html_e( 'Control access to WordPress REST API endpoints.', 'vigilante' ); ?></p>
4994
4995 <table class="form-table">
4996 <tr>
4997 <th scope="row"><label for="vigilante-f-rest-api-security-mode"><?php esc_html_e( 'Access Mode', 'vigilante' ); ?></label></th>
4998 <td>
4999 <select id="vigilante-f-rest-api-security-mode" name="rest_api_security[mode]">
5000 <option value="open" <?php selected( $options['mode'] ?? 'selective', 'open' ); ?>><?php esc_html_e( 'Open - Allow all requests', 'vigilante' ); ?></option>
5001 <option value="selective" <?php selected( $options['mode'] ?? 'selective', 'selective' ); ?>><?php esc_html_e( 'Selective - Protect sensitive endpoints', 'vigilante' ); ?></option>
5002 <option value="authenticated_only" <?php selected( $options['mode'] ?? 'selective', 'authenticated_only' ); ?>><?php esc_html_e( 'Authenticated - Require login for all', 'vigilante' ); ?></option>
5003 </select>
5004 <p class="description"><?php esc_html_e( 'Selective mode is recommended.', 'vigilante' ); ?></p>
5005 </td>
5006 </tr>
5007 <tr id="field-block-user-enumeration">
5008 <th scope="row"><?php esc_html_e( 'Block User Enumeration', 'vigilante' ); ?></th>
5009 <td>
5010 <label>
5011 <input type="checkbox" name="rest_api_security[block_user_enumeration]" value="1" <?php checked( ! empty( $options['block_user_enumeration'] ) ); ?>>
5012 <?php esc_html_e( 'Protect /wp/v2/users endpoint for unauthenticated users', 'vigilante' ); ?>
5013 </label>
5014 </td>
5015 </tr>
5016 <tr>
5017 <th scope="row"><?php esc_html_e( 'Disable JSONP', 'vigilante' ); ?></th>
5018 <td>
5019 <label>
5020 <input type="checkbox" name="rest_api_security[disable_jsonp]" value="1" <?php checked( ! empty( $options['disable_jsonp'] ) ); ?>>
5021 <?php esc_html_e( 'Disable JSONP support in REST API', 'vigilante' ); ?>
5022 </label>
5023 </td>
5024 </tr>
5025 </table>
5026 </div>
5027
5028 <p class="submit vigilante-submit-buttons">
5029 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5030 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5031 </button>
5032 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5033 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5034 </button>
5035 </p>
5036 </form>
5037 <?php
5038 }
5039
5040 /**
5041 * Render User Security tab
5042 */
5043 private function render_tab_users() {
5044 $is_disabled = $this->render_module_disabled_notice( 'user_security' );
5045 $options = $this->settings->get_section( 'user_security' );
5046 $monitoring = $options['admin_monitoring'] ?? array();
5047 $registration = $options['registration_approval'] ?? array();
5048 $session_limits = $options['session_limits'] ?? array();
5049 $password_exp = $options['password_expiration'] ?? array();
5050 $email_verify = $options['email_verification'] ?? array();
5051 ?>
5052
5053 <!-- ============================================================
5054 SETTINGS SECTION - Single form for all configuration
5055 ============================================================ -->
5056 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="user_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
5057
5058 <!-- Username & Password Protection -->
5059 <div id="vigilante-section-users-password" class="vigilante-settings-section">
5060 <h2>
5061 <?php esc_html_e( 'Username & password protection', 'vigilante' ); ?>
5062 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5063 </h2>
5064 <p><?php esc_html_e( 'Enforce secure username and password policies.', 'vigilante' ); ?></p>
5065
5066 <table class="form-table">
5067 <tr>
5068 <th scope="row"><?php esc_html_e( 'Block Insecure Usernames', 'vigilante' ); ?></th>
5069 <td>
5070 <label>
5071 <input type="checkbox" name="user_security[block_insecure_usernames]" value="1" <?php checked( ! empty( $options['block_insecure_usernames'] ) ); ?>>
5072 <?php esc_html_e( 'Prevent creation of users with common usernames (admin, administrator, etc.)', 'vigilante' ); ?>
5073 </label>
5074 </td>
5075 </tr>
5076 <?php
5077 $pw_policy = wp_parse_args(
5078 ( isset( $options['password_policy'] ) && is_array( $options['password_policy'] ) ) ? $options['password_policy'] : array(),
5079 array(
5080 'require_uppercase' => false,
5081 'require_lowercase' => false,
5082 'require_number' => false,
5083 'require_special' => false,
5084 'block_common' => true,
5085 'block_username' => true,
5086 'affected_roles' => array(),
5087 )
5088 );
5089 $pw_policy_roles = (array) $pw_policy['affected_roles'];
5090 ?>
5091 <tr>
5092 <th scope="row"><?php esc_html_e( 'Enforce Strong Passwords', 'vigilante' ); ?></th>
5093 <td>
5094 <label>
5095 <input type="checkbox" name="user_security[force_strong_passwords]" value="1" <?php checked( ! empty( $options['force_strong_passwords'] ) ); ?>>
5096 <?php esc_html_e( 'Check passwords against the requirements below when a user sets or changes one', 'vigilante' ); ?>
5097 </label>
5098 </td>
5099 </tr>
5100 <tr>
5101 <th scope="row"><label for="vigilante-f-user-security-min-password-length"><?php esc_html_e( 'Minimum Password Length', 'vigilante' ); ?></label></th>
5102 <td>
5103 <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">
5104 <?php esc_html_e( 'characters', 'vigilante' ); ?>
5105 </td>
5106 </tr>
5107 <tr>
5108 <th scope="row"><?php esc_html_e( 'Password Requirements', 'vigilante' ); ?></th>
5109 <td>
5110 <label style="display:block;margin-bottom:5px;">
5111 <input type="checkbox" name="user_security[password_policy][require_uppercase]" value="1" <?php checked( ! empty( $pw_policy['require_uppercase'] ) ); ?>>
5112 <?php esc_html_e( 'Require an uppercase letter (A-Z)', 'vigilante' ); ?>
5113 </label>
5114 <label style="display:block;margin-bottom:5px;">
5115 <input type="checkbox" name="user_security[password_policy][require_lowercase]" value="1" <?php checked( ! empty( $pw_policy['require_lowercase'] ) ); ?>>
5116 <?php esc_html_e( 'Require a lowercase letter (a-z)', 'vigilante' ); ?>
5117 </label>
5118 <label style="display:block;margin-bottom:5px;">
5119 <input type="checkbox" name="user_security[password_policy][require_number]" value="1" <?php checked( ! empty( $pw_policy['require_number'] ) ); ?>>
5120 <?php esc_html_e( 'Require a number (0-9)', 'vigilante' ); ?>
5121 </label>
5122 <label style="display:block;margin-bottom:5px;">
5123 <input type="checkbox" name="user_security[password_policy][require_special]" value="1" <?php checked( ! empty( $pw_policy['require_special'] ) ); ?>>
5124 <?php esc_html_e( 'Require a special character (!, @, #, ...)', 'vigilante' ); ?>
5125 </label>
5126 <label style="display:block;margin-bottom:5px;">
5127 <input type="checkbox" name="user_security[password_policy][block_common]" value="1" <?php checked( ! empty( $pw_policy['block_common'] ) ); ?>>
5128 <?php esc_html_e( 'Reject well-known common passwords', 'vigilante' ); ?>
5129 </label>
5130 <label style="display:block;margin-bottom:5px;">
5131 <input type="checkbox" name="user_security[password_policy][block_username]" value="1" <?php checked( ! empty( $pw_policy['block_username'] ) ); ?>>
5132 <?php esc_html_e( 'Do not allow the username inside the password', 'vigilante' ); ?>
5133 </label>
5134 <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>
5135 </td>
5136 </tr>
5137 <tr>
5138 <th scope="row"><?php esc_html_e( 'Apply Password Rules To', 'vigilante' ); ?></th>
5139 <td>
5140 <?php $this->list_sentinel( 'user_security[password_policy][affected_roles]' ); ?>
5141 <?php foreach ( wp_roles()->get_names() as $role_slug => $role_name ) : ?>
5142 <label style="display:block;margin-bottom:5px;">
5143 <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 ) ); ?>>
5144 <?php echo esc_html( translate_user_role( $role_name ) ); ?>
5145 </label>
5146 <?php endforeach; ?>
5147 <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>
5148 </td>
5149 </tr>
5150 <tr id="field-block-author-scanning">
5151 <th scope="row"><?php esc_html_e( 'Block Author Scanning', 'vigilante' ); ?></th>
5152 <td>
5153 <label>
5154 <input type="checkbox" name="user_security[block_author_scanning]" value="1" <?php checked( ! empty( $options['block_author_scanning'] ) ); ?>>
5155 <?php esc_html_e( 'Prevent username discovery via ?author=N URLs', 'vigilante' ); ?>
5156 </label>
5157 </td>
5158 </tr>
5159 <tr>
5160 <th scope="row"><?php esc_html_e( 'Display Name Protection', 'vigilante' ); ?></th>
5161 <td>
5162 <label>
5163 <input type="checkbox" name="user_security[prevent_display_name_login_match]" value="1" <?php checked( ! empty( $options['prevent_display_name_login_match'] ) ); ?>>
5164 <?php esc_html_e( 'Prevent users from saving a display name that matches their login username', 'vigilante' ); ?>
5165 </label>
5166 <p class="description"><?php esc_html_e( 'The display name is publicly visible and should not reveal the login username.', 'vigilante' ); ?></p>
5167 </td>
5168 </tr>
5169 </table>
5170 </div>
5171
5172 <!-- Admin Monitoring -->
5173 <div id="vigilante-section-users-admin-monitoring" class="vigilante-settings-section">
5174 <h2>
5175 <?php esc_html_e( 'Admin monitoring', 'vigilante' ); ?>
5176 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5177 </h2>
5178 <p><?php esc_html_e( 'Receive email alerts when administrator accounts are modified. All events are always logged to the Security Audit.', 'vigilante' ); ?></p>
5179
5180 <table class="form-table">
5181 <tr>
5182 <th scope="row"><?php esc_html_e( 'New Administrator Alert', 'vigilante' ); ?></th>
5183 <td>
5184 <label>
5185 <input type="checkbox" name="user_security[admin_monitoring][alert_new_admin]" value="1" <?php checked( ! empty( $monitoring['alert_new_admin'] ) ); ?>>
5186 <?php esc_html_e( 'Send email alert when a new administrator account is created', 'vigilante' ); ?>
5187 </label>
5188 </td>
5189 </tr>
5190 <tr>
5191 <th scope="row"><?php esc_html_e( 'Admin Email Change Alert', 'vigilante' ); ?></th>
5192 <td>
5193 <label>
5194 <input type="checkbox" name="user_security[admin_monitoring][alert_admin_email_change]" value="1" <?php checked( ! empty( $monitoring['alert_admin_email_change'] ) ); ?>>
5195 <?php esc_html_e( 'Send email alert when an administrator email address is changed', 'vigilante' ); ?>
5196 </label>
5197 </td>
5198 </tr>
5199 <tr>
5200 <th scope="row"><?php esc_html_e( 'Permission Elevation Alert', 'vigilante' ); ?></th>
5201 <td>
5202 <label>
5203 <input type="checkbox" name="user_security[admin_monitoring][alert_permission_elevation]" value="1" <?php checked( ! empty( $monitoring['alert_permission_elevation'] ) ); ?>>
5204 <?php esc_html_e( 'Send email alert when a user is elevated to administrator role', 'vigilante' ); ?>
5205 </label>
5206 </td>
5207 </tr>
5208 <tr>
5209 <th scope="row"><?php esc_html_e( 'Admin Password Change Alert', 'vigilante' ); ?></th>
5210 <td>
5211 <label>
5212 <input type="checkbox" name="user_security[admin_monitoring][alert_admin_password_change]" value="1" <?php checked( ! empty( $monitoring['alert_admin_password_change'] ) ); ?>>
5213 <?php esc_html_e( 'Send email alert when an administrator password is changed', 'vigilante' ); ?>
5214 </label>
5215 </td>
5216 </tr>
5217 </table>
5218
5219 <p class="description">
5220 <?php
5221 printf(
5222 /* translators: %s: Link to notification settings */
5223 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
5224 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
5225 );
5226 ?>
5227 </p>
5228 </div>
5229
5230 <!-- Registration Approval -->
5231 <div id="vigilante-section-users-registration" class="vigilante-settings-section">
5232 <h2>
5233 <?php esc_html_e( 'Registration approval', 'vigilante' ); ?>
5234 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5235 </h2>
5236 <p><?php esc_html_e( 'Require manual approval for new user registrations.', 'vigilante' ); ?></p>
5237
5238 <table class="form-table">
5239 <tr>
5240 <th scope="row"><?php esc_html_e( 'Enable Registration Approval', 'vigilante' ); ?></th>
5241 <td>
5242 <label>
5243 <input type="checkbox" name="user_security[registration_approval][enabled]" value="1" <?php checked( ! empty( $registration['enabled'] ) ); ?>>
5244 <?php esc_html_e( 'New users must be approved by an administrator before they can log in', 'vigilante' ); ?>
5245 </label>
5246 </td>
5247 </tr>
5248 <tr>
5249 <th scope="row"><?php esc_html_e( 'Notify Admin', 'vigilante' ); ?></th>
5250 <td>
5251 <label>
5252 <input type="checkbox" name="user_security[registration_approval][notify_admin]" value="1" <?php checked( ! empty( $registration['notify_admin'] ) ); ?>>
5253 <?php esc_html_e( 'Send email notification when a new user registers', 'vigilante' ); ?>
5254 </label>
5255 <p class="description"><?php esc_html_e( 'Disable on high-traffic sites to avoid email overload.', 'vigilante' ); ?></p>
5256 </td>
5257 </tr>
5258 <tr>
5259 <th scope="row"><label for="vigilante-f-user-security-registration-approval-auto-reject-days"><?php esc_html_e( 'Auto-reject After', 'vigilante' ); ?></label></th>
5260 <td>
5261 <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">
5262 <?php esc_html_e( 'days (0 = never)', 'vigilante' ); ?>
5263 <p class="description"><?php esc_html_e( 'Automatically reject pending registrations after this many days.', 'vigilante' ); ?></p>
5264 </td>
5265 </tr>
5266 </table>
5267 </div>
5268
5269 <!-- Session Limits -->
5270 <div id="vigilante-section-users-sessions" class="vigilante-settings-section">
5271 <h2>
5272 <?php esc_html_e( 'Session limits', 'vigilante' ); ?>
5273 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5274 </h2>
5275 <p><?php esc_html_e( 'Limit the number of simultaneous sessions per user.', 'vigilante' ); ?></p>
5276
5277 <?php if ( Vigilante_User_Security::session_limit_is_network_wide() ) : ?>
5278 <div class="notice notice-warning inline">
5279 <p>
5280 <?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' ); ?>
5281 </p>
5282 </div>
5283 <?php endif; ?>
5284
5285 <table class="form-table">
5286 <tr>
5287 <th scope="row"><?php esc_html_e( 'Enable Session Limits', 'vigilante' ); ?></th>
5288 <td>
5289 <label>
5290 <input type="checkbox" name="user_security[session_limits][enabled]" value="1" <?php checked( ! empty( $session_limits['enabled'] ) ); ?>>
5291 <?php esc_html_e( 'Limit the number of active sessions per user', 'vigilante' ); ?>
5292 </label>
5293 </td>
5294 </tr>
5295 <tr>
5296 <th scope="row"><label for="vigilante-f-user-security-session-limits-max-sessions"><?php esc_html_e( 'Maximum Sessions', 'vigilante' ); ?></label></th>
5297 <td>
5298 <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">
5299 <?php esc_html_e( 'sessions per user', 'vigilante' ); ?>
5300 </td>
5301 </tr>
5302 <tr>
5303 <th scope="row"><label for="vigilante-f-user-security-session-limits-behavior"><?php esc_html_e( 'When Limit Exceeded', 'vigilante' ); ?></label></th>
5304 <td>
5305 <select id="vigilante-f-user-security-session-limits-behavior" name="user_security[session_limits][behavior]">
5306 <option value="block_new" <?php selected( ( $session_limits['behavior'] ?? 'close_oldest' ), 'block_new' ); ?>><?php esc_html_e( 'Block new login', 'vigilante' ); ?></option>
5307 <option value="close_oldest" <?php selected( ( $session_limits['behavior'] ?? 'close_oldest' ), 'close_oldest' ); ?>><?php esc_html_e( 'Close oldest session', 'vigilante' ); ?></option>
5308 </select>
5309 <p class="description"><?php esc_html_e( '"Close oldest" is recommended for security - ensures attackers cannot lock out legitimate users.', 'vigilante' ); ?></p>
5310 </td>
5311 </tr>
5312 <tr>
5313 <th scope="row"><?php esc_html_e( 'Exclude Administrators', 'vigilante' ); ?></th>
5314 <td>
5315 <label>
5316 <input type="checkbox" name="user_security[session_limits][exclude_admins]" value="1" <?php checked( ! empty( $session_limits['exclude_admins'] ) ); ?>>
5317 <?php esc_html_e( 'Do not apply session limits to administrators', 'vigilante' ); ?>
5318 </label>
5319 </td>
5320 </tr>
5321 </table>
5322 </div>
5323
5324 <!-- Password Expiration -->
5325 <div id="vigilante-section-users-password-exp" class="vigilante-settings-section">
5326 <h2>
5327 <?php esc_html_e( 'Password expiration', 'vigilante' ); ?>
5328 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5329 </h2>
5330 <p><?php esc_html_e( 'Force users to change their password periodically.', 'vigilante' ); ?></p>
5331
5332 <table class="form-table">
5333 <tr>
5334 <th scope="row"><?php esc_html_e( 'Enable Password Expiration', 'vigilante' ); ?></th>
5335 <td>
5336 <label>
5337 <input type="checkbox" name="user_security[password_expiration][enabled]" value="1" <?php checked( ! empty( $password_exp['enabled'] ) ); ?>>
5338 <?php esc_html_e( 'Force password change after a set number of days', 'vigilante' ); ?>
5339 </label>
5340 </td>
5341 </tr>
5342 <tr>
5343 <th scope="row"><label for="vigilante-f-user-security-password-expiration-expire-days"><?php esc_html_e( 'Expire After', 'vigilante' ); ?></label></th>
5344 <td>
5345 <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">
5346 <?php esc_html_e( 'days', 'vigilante' ); ?>
5347 <p class="description"><?php esc_html_e( 'PCI-DSS recommends 90 days.', 'vigilante' ); ?></p>
5348 </td>
5349 </tr>
5350 <tr>
5351 <th scope="row"><label for="vigilante-f-user-security-password-expiration-warning-days"><?php esc_html_e( 'Warning Period', 'vigilante' ); ?></label></th>
5352 <td>
5353 <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">
5354 <?php esc_html_e( 'days before expiration', 'vigilante' ); ?>
5355 <p class="description"><?php esc_html_e( 'Show warning notice this many days before password expires.', 'vigilante' ); ?></p>
5356 </td>
5357 </tr>
5358 <tr>
5359 <th scope="row"><label for="vigilante-f-user-security-password-expiration-password-history"><?php esc_html_e( 'Password History', 'vigilante' ); ?></label></th>
5360 <td>
5361 <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">
5362 <?php esc_html_e( 'passwords to remember', 'vigilante' ); ?>
5363 <p class="description"><?php esc_html_e( 'Prevent reusing recent passwords. Set to 0 to disable.', 'vigilante' ); ?></p>
5364 </td>
5365 </tr>
5366 <tr>
5367 <th scope="row"><?php esc_html_e( 'Email Reminder', 'vigilante' ); ?></th>
5368 <td>
5369 <label>
5370 <input type="checkbox" name="user_security[password_expiration][send_reminder]" value="1" <?php checked( ! empty( $password_exp['send_reminder'] ) ); ?>>
5371 <?php esc_html_e( 'Send email reminder when password is about to expire', 'vigilante' ); ?>
5372 </label>
5373 <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>
5374 </td>
5375 </tr>
5376 <tr>
5377 <th scope="row"><?php esc_html_e( 'Affected Roles', 'vigilante' ); ?></th>
5378 <td>
5379 <?php
5380 $affected_roles = $password_exp['affected_roles'] ?? array( 'administrator', 'editor' );
5381 $all_roles = wp_roles()->get_names();
5382 $this->list_sentinel( 'user_security[password_expiration][affected_roles]' );
5383 foreach ( $all_roles as $role_slug => $role_name ) :
5384 ?>
5385 <label style="display: block; margin-bottom: 5px;">
5386 <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 ) ); ?>>
5387 <?php echo esc_html( translate_user_role( $role_name ) ); ?>
5388 </label>
5389 <?php endforeach; ?>
5390 </td>
5391 </tr>
5392 <tr>
5393 <th scope="row"><?php esc_html_e( 'Exclude specific users', 'vigilante' ); ?></th>
5394 <td>
5395 <?php $pwexp_excluded = $password_exp['excluded_users'] ?? array(); ?>
5396 <div class="vigilante-2fa-user-search-container">
5397 <div class="vigilante-2fa-user-search">
5398 <span class="search-icon"></span>
5399 <input type="text"
5400 id="vigilante_pwexp_user_search"
5401 placeholder="<?php esc_attr_e( 'Search users by name or email...', 'vigilante' ); ?>"
5402 autocomplete="off">
5403 <div class="vigilante-pwexp-search-results"></div>
5404 </div>
5405 <div class="vigilante-pwexp-excluded-users">
5406 <?php $this->list_sentinel( 'user_security[password_expiration][excluded_users]' ); ?>
5407 <?php
5408 foreach ( $pwexp_excluded as $pwexp_excluded_id ) :
5409 $excluded_user = get_user_by( 'ID', $pwexp_excluded_id );
5410 if ( ! $excluded_user ) {
5411 continue;
5412 }
5413 ?>
5414 <div class="vigilante-pwexp-excluded-user" data-user-id="<?php echo esc_attr( $pwexp_excluded_id ); ?>">
5415 <span class="user-display"><?php echo esc_html( $excluded_user->display_name . ' (' . $excluded_user->user_email . ')' ); ?></span>
5416 <button type="button" class="remove-user" aria-label="<?php esc_attr_e( 'Remove', 'vigilante' ); ?>">&times;</button>
5417 <input type="hidden" name="user_security[password_expiration][excluded_users][]" value="<?php echo esc_attr( $pwexp_excluded_id ); ?>">
5418 </div>
5419 <?php endforeach; ?>
5420 </div>
5421 </div>
5422 <p class="description"><?php esc_html_e( 'Listed users will be excluded from password expiration regardless of their role.', 'vigilante' ); ?></p>
5423 </td>
5424 </tr>
5425 </table>
5426 </div>
5427
5428 <!-- Email Verification -->
5429 <div id="vigilante-section-users-email-verify" class="vigilante-settings-section">
5430 <h2>
5431 <?php esc_html_e( 'Email verification', 'vigilante' ); ?>
5432 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5433 </h2>
5434 <p><?php esc_html_e( 'Require new users to verify their email address before logging in.', 'vigilante' ); ?></p>
5435
5436 <table class="form-table">
5437 <tr>
5438 <th scope="row"><?php esc_html_e( 'Enable Email Verification', 'vigilante' ); ?></th>
5439 <td>
5440 <label>
5441 <input type="checkbox" name="user_security[email_verification][enabled]" value="1" <?php checked( ! empty( $email_verify['enabled'] ) ); ?>>
5442 <?php esc_html_e( 'New users must verify their email before logging in', 'vigilante' ); ?>
5443 </label>
5444 </td>
5445 </tr>
5446 <tr>
5447 <th scope="row"><label for="vigilante-f-user-security-email-verification-token-expiry-hours"><?php esc_html_e( 'Link Expiration', 'vigilante' ); ?></label></th>
5448 <td>
5449 <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">
5450 <?php esc_html_e( 'hours', 'vigilante' ); ?>
5451 </td>
5452 </tr>
5453 <tr>
5454 <th scope="row"><?php esc_html_e( 'Allow Resend', 'vigilante' ); ?></th>
5455 <td>
5456 <label>
5457 <input type="checkbox" name="user_security[email_verification][allow_resend]" value="1" <?php checked( ! empty( $email_verify['allow_resend'] ) ); ?>>
5458 <?php esc_html_e( 'Allow users to request a new verification email', 'vigilante' ); ?>
5459 </label>
5460 </td>
5461 </tr>
5462 <tr>
5463 <th scope="row"><label for="vigilante-f-user-security-email-verification-auto-delete-days"><?php esc_html_e( 'Auto-delete Unverified', 'vigilante' ); ?></label></th>
5464 <td>
5465 <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">
5466 <?php esc_html_e( 'days (0 = never)', 'vigilante' ); ?>
5467 <p class="description"><?php esc_html_e( 'Automatically delete users who never verify their email.', 'vigilante' ); ?></p>
5468 </td>
5469 </tr>
5470 </table>
5471 </div>
5472
5473 <p class="submit vigilante-submit-buttons">
5474 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5475 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5476 </button>
5477 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5478 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5479 </button>
5480 </p>
5481 </form>
5482
5483 <!-- ============================================================
5484 TOOLS SECTION - Actions and utilities (no save button)
5485 ============================================================ -->
5486 <div class="vigilante-tools-section">
5487 <h2 class="vigilante-tools-header">
5488 <?php esc_html_e( 'User security tools', 'vigilante' ); ?>
5489 </h2>
5490
5491 <?php $this->render_user_actions_notice(); ?>
5492 <?php if ( ! $this->user_actions_locked() ) : ?>
5493
5494 <!-- Force Password Reset -->
5495 <div class="vigilante-tool-box">
5496 <h3><?php esc_html_e( 'Force password reset', 'vigilante' ); ?></h3>
5497 <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>
5498
5499 <!-- Reset Specific Users -->
5500 <div class="vigilante-password-reset-box">
5501 <h4><?php esc_html_e( 'Reset specific users', 'vigilante' ); ?></h4>
5502
5503 <div class="vigilante-user-search-wrapper">
5504 <input type="text" id="vigilante-password-reset-search" class="regular-text" placeholder="<?php esc_attr_e( 'Search by username, email, or display name...', 'vigilante' ); ?>">
5505 <div id="vigilante-password-reset-results" class="vigilante-user-search-results" style="display: none;"></div>
5506 </div>
5507
5508 <div id="vigilante-password-reset-selected" class="vigilante-selected-users" style="display: none;">
5509 <strong><?php esc_html_e( 'Selected Users:', 'vigilante' ); ?></strong>
5510 <ul class="vigilante-selected-users-list"></ul>
5511 </div>
5512
5513 <p class="description" style="margin-top: 15px;">
5514 <span class="dashicons dashicons-email-alt" style="color: #2271b1;"></span>
5515 <?php esc_html_e( 'Selected users will receive an email with a password reset link.', 'vigilante' ); ?>
5516 </p>
5517
5518 <p class="submit">
5519 <button type="button" id="vigilante-reset-selected-users" class="button button-primary" disabled>
5520 <?php esc_html_e( 'Force Reset for Selected Users', 'vigilante' ); ?>
5521 </button>
5522 </p>
5523 </div>
5524
5525 <!-- Reset by Role -->
5526 <div class="vigilante-password-reset-box" style="margin-top: 20px; padding-top: 20px; border-top: 1px solid #ddd;">
5527 <h4><?php esc_html_e( 'Reset by role', 'vigilante' ); ?></h4>
5528 <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>
5529
5530 <?php
5531 $wp_roles = wp_roles();
5532 $user_counts = count_users();
5533 $avail_roles = $user_counts['avail_roles'] ?? array();
5534 $current_user = wp_get_current_user();
5535 $current_roles = $current_user->roles;
5536 ?>
5537
5538 <fieldset class="vigilante-role-checkboxes" style="margin-top: 10px;">
5539 <?php foreach ( $wp_roles->roles as $role_slug => $role_data ) :
5540 $count = $avail_roles[ $role_slug ] ?? 0;
5541 if ( 0 === $count ) {
5542 continue;
5543 }
5544 $role_name = translate_user_role( $role_data['name'] );
5545 ?>
5546 <label style="display: block; margin-bottom: 6px;">
5547 <input type="checkbox"
5548 class="vigilante-reset-role-checkbox"
5549 value="<?php echo esc_attr( $role_slug ); ?>"
5550 data-count="<?php echo absint( $count ); ?>">
5551 <?php
5552 printf(
5553 /* translators: 1: Role name, 2: Number of users */
5554 '%1$s <span class="description">(%2$d)</span>',
5555 esc_html( $role_name ),
5556 absint( $count )
5557 );
5558 ?>
5559 <?php if ( in_array( $role_slug, $current_roles, true ) ) : ?>
5560 <em class="description"><?php esc_html_e( '(includes you)', 'vigilante' ); ?></em>
5561 <?php endif; ?>
5562 </label>
5563 <?php endforeach; ?>
5564 </fieldset>
5565
5566 <div id="vigilante-reset-role-summary" style="display: none; margin-top: 10px;">
5567 <p>
5568 <span class="dashicons dashicons-groups" style="color: #2271b1;"></span>
5569 <strong id="vigilante-reset-role-count">0</strong>
5570 <?php esc_html_e( 'user(s) will be affected.', 'vigilante' ); ?>
5571 </p>
5572 </div>
5573
5574 <div class="vigilante-password-reset-options" id="vigilante-reset-role-self-option" style="display: none; margin-top: 10px;">
5575 <label>
5576 <input type="checkbox" id="vigilante-reset-role-include-self" value="1">
5577 <?php esc_html_e( 'Include myself (your current session will end)', 'vigilante' ); ?>
5578 </label>
5579 </div>
5580
5581 <p class="submit">
5582 <button type="button" id="vigilante-reset-by-role" class="button button-primary" disabled>
5583 <?php esc_html_e( 'Force Reset for Selected Roles', 'vigilante' ); ?>
5584 </button>
5585 </p>
5586 </div>
5587
5588 <!-- Reset All Users -->
5589 <div class="vigilante-password-reset-box" style="margin-top: 20px; padding-top: 20px; border-top: 1px solid #ddd;">
5590 <h4><?php esc_html_e( 'Reset all users', 'vigilante' ); ?></h4>
5591
5592 <?php
5593 $total_users = count_users();
5594 $total_count = $total_users['total_users'];
5595 ?>
5596 <p>
5597 <?php
5598 printf(
5599 /* translators: %d: Number of users */
5600 esc_html__( 'This will affect %d user(s).', 'vigilante' ),
5601 absint( $total_count )
5602 );
5603 ?>
5604 </p>
5605
5606 <p class="description" style="color: #d63638;">
5607 <span class="dashicons dashicons-warning"></span>
5608 <?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' ); ?>
5609 </p>
5610
5611 <div class="vigilante-password-reset-options" style="margin-top: 10px;">
5612 <label>
5613 <input type="checkbox" id="vigilante-reset-all-include-self" value="1">
5614 <?php esc_html_e( 'Include myself (your current session will end)', 'vigilante' ); ?>
5615 </label>
5616 </div>
5617
5618 <p class="submit">
5619 <button type="button" id="vigilante-reset-all-users" class="button" style="color: #d63638; border-color: #d63638;">
5620 <?php esc_html_e( 'Force Reset for ALL Users', 'vigilante' ); ?>
5621 </button>
5622 </p>
5623 </div>
5624 </div>
5625
5626 <!-- Pending Registrations -->
5627 <?php
5628 // Enforcement-only: this instance exists to read the queue, and the
5629 // flag keeps it from registering the module's own hooks a second
5630 // time. It is not inert, and saying it was would be a false comment:
5631 // init_enforcement_hooks() does add its three filters again, on top
5632 // of the ones already registered. They are idempotent (the same
5633 // methods of an equivalent instance, deciding on the same user meta),
5634 // so running them twice in an admin request changes nothing, which is
5635 // why this is accepted rather than worked around.
5636 $user_security = new Vigilante_User_Security( $this->settings, $this->activity_log, true );
5637 $pending_users = $user_security->get_pending_users();
5638 ?>
5639 <div id="vigilante-section-users-pending" class="vigilante-tool-box vigilante-pending-users-section">
5640 <h3>
5641 <?php esc_html_e( 'Pending registrations', 'vigilante' ); ?>
5642 <?php if ( count( $pending_users ) > 0 ) : ?>
5643 <span class="vigilante-badge vigilante-badge-warning"><?php echo esc_html( count( $pending_users ) ); ?></span>
5644 <?php endif; ?>
5645 </h3>
5646
5647 <?php
5648 /*
5649 * The queue is shown whenever there is somebody in it, even with
5650 * the feature off. Since 2.11.10 an account already waiting stays
5651 * blocked when the feature is switched off, which is the point:
5652 * turning a setting off must not quietly let in people an
5653 * administrator decided not to approve. But hiding the table then
5654 * left them locked out with no button anywhere to approve or
5655 * reject them. Found by the cross review of 2.11.10.
5656 */
5657 ?>
5658 <?php if ( empty( $registration['enabled'] ) && empty( $pending_users ) ) : ?>
5659 <p class="description">
5660 <span class="dashicons dashicons-info" style="color: #72aee6;"></span>
5661 <?php esc_html_e( 'Registration approval is disabled. Enable it in the settings above to require manual approval for new users.', 'vigilante' ); ?>
5662 </p>
5663 <?php elseif ( empty( $pending_users ) ) : ?>
5664 <div class="vigilante-no-lockouts">
5665 <span class="dashicons dashicons-yes-alt"></span>
5666 <p><?php esc_html_e( 'No pending registrations.', 'vigilante' ); ?></p>
5667 </div>
5668 <?php else : ?>
5669 <?php $this->render_user_actions_notice(); ?>
5670 <table class="wp-list-table widefat fixed striped vigilante-pending-users-table">
5671 <thead>
5672 <tr>
5673 <th><?php esc_html_e( 'User', 'vigilante' ); ?></th>
5674 <th><?php esc_html_e( 'Email', 'vigilante' ); ?></th>
5675 <th><?php esc_html_e( 'Registered', 'vigilante' ); ?></th>
5676 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5677 </tr>
5678 </thead>
5679 <tbody>
5680 <?php foreach ( $pending_users as $pending_user ) :
5681 $pending_since = get_user_meta( $pending_user->ID, Vigilante_User_Security::site_user_meta_key( 'vigilante_pending_since' ), true );
5682 ?>
5683 <tr data-user-id="<?php echo esc_attr( $pending_user->ID ); ?>">
5684 <td>
5685 <?php echo get_avatar( $pending_user->ID, 32 ); ?>
5686 <strong><?php echo esc_html( $pending_user->user_login ); ?></strong>
5687 </td>
5688 <td><?php echo esc_html( $pending_user->user_email ); ?></td>
5689 <td>
5690 <?php
5691 if ( $pending_since ) {
5692 /* translators: %s: Time ago */
5693 printf( esc_html__( '%s ago', 'vigilante' ), esc_html( human_time_diff( $pending_since ) ) );
5694 } else {
5695 echo esc_html( $pending_user->user_registered );
5696 }
5697 ?>
5698 </td>
5699 <td>
5700 <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() ); ?>>
5701 <?php esc_html_e( 'Approve', 'vigilante' ); ?>
5702 </button>
5703 <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() ); ?>>
5704 <?php esc_html_e( 'Reject', 'vigilante' ); ?>
5705 </button>
5706 </td>
5707 </tr>
5708 <?php endforeach; ?>
5709 </tbody>
5710 </table>
5711 <?php endif; ?>
5712 </div>
5713
5714 <!-- Active Sessions Management -->
5715 <div class="vigilante-tool-box vigilante-session-management-section">
5716 <h3><?php esc_html_e( 'Active sessions', 'vigilante' ); ?></h3>
5717 <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>
5718
5719 <!-- Current user sessions -->
5720 <h4><?php esc_html_e( 'Your sessions', 'vigilante' ); ?></h4>
5721 <?php
5722 $current_user_id = get_current_user_id();
5723 $my_sessions = $user_security->get_user_sessions( $current_user_id );
5724 $has_corrupted = $user_security->has_corrupted_sessions( $current_user_id );
5725 $raw_count = $user_security->get_raw_session_count( $current_user_id );
5726 ?>
5727
5728 <?php if ( $has_corrupted && $raw_count > 0 ) : ?>
5729 <div class="notice notice-warning inline" style="margin: 10px 0;">
5730 <p>
5731 <span class="dashicons dashicons-warning" style="color: #dba617;"></span>
5732 <?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' ); ?>
5733 </p>
5734 </div>
5735 <?php endif; ?>
5736
5737 <?php if ( empty( $my_sessions ) ) : ?>
5738 <p class="description"><?php esc_html_e( 'No active sessions found.', 'vigilante' ); ?></p>
5739 <?php if ( $has_corrupted ) : ?>
5740 <p style="margin-top: 10px;">
5741 <button type="button" class="button vigilante-revoke-other-sessions" data-user-id="<?php echo esc_attr( $current_user_id ); ?>">
5742 <?php esc_html_e( 'Clean Up Corrupted Sessions', 'vigilante' ); ?>
5743 </button>
5744 </p>
5745 <?php endif; ?>
5746 <?php else : ?>
5747 <div class="vigilante-paginated-section">
5748 <div class="vigilante-fi-pagination-wrap"></div>
5749 <table class="wp-list-table widefat fixed striped vigilante-sessions-table vigilante-fi-paginated">
5750 <thead>
5751 <tr>
5752 <th><?php esc_html_e( 'Browser', 'vigilante' ); ?></th>
5753 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
5754 <th><?php esc_html_e( 'Login Time', 'vigilante' ); ?></th>
5755 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5756 </tr>
5757 </thead>
5758 <tbody>
5759 <?php foreach ( $my_sessions as $session ) : ?>
5760 <tr data-token="<?php echo esc_attr( $session['token_hash'] ); ?>">
5761 <td><?php echo esc_html( $session['browser'] ); ?></td>
5762 <td><code><?php echo esc_html( $session['ip'] ); ?></code></td>
5763 <td>
5764 <?php
5765 if ( $session['login'] ) {
5766 /* translators: %s: Time ago */
5767 printf( esc_html__( '%s ago', 'vigilante' ), esc_html( human_time_diff( $session['login'] ) ) );
5768 } else {
5769 esc_html_e( 'Unknown', 'vigilante' );
5770 }
5771 ?>
5772 </td>
5773 <td>
5774 <?php if ( ! $session['is_current'] ) : ?>
5775 <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'] ); ?>">
5776 <?php esc_html_e( 'Revoke', 'vigilante' ); ?>
5777 </button>
5778 <?php else : ?>
5779 <span class="description"><?php esc_html_e( 'Current session', 'vigilante' ); ?></span>
5780 <?php endif; ?>
5781 </td>
5782 </tr>
5783 <?php endforeach; ?>
5784 </tbody>
5785 </table>
5786 </div>
5787
5788 <?php if ( count( $my_sessions ) > 1 || $has_corrupted ) : ?>
5789 <p style="margin-top: 10px;">
5790 <button type="button" class="button vigilante-revoke-other-sessions" data-user-id="<?php echo esc_attr( $current_user_id ); ?>">
5791 <?php esc_html_e( 'Revoke All Other Sessions', 'vigilante' ); ?>
5792 </button>
5793 </p>
5794 <?php endif; ?>
5795 <?php endif; ?>
5796
5797 <!-- Search user sessions (admin only) -->
5798 <h4 style="margin-top: 30px;"><?php esc_html_e( 'Manage user sessions', 'vigilante' ); ?></h4>
5799 <p class="description"><?php esc_html_e( 'Search for a user to view and manage their sessions.', 'vigilante' ); ?></p>
5800
5801 <div class="vigilante-user-search-wrapper" style="margin-top: 10px;">
5802 <input type="text" id="vigilante-session-user-search" class="regular-text" placeholder="<?php esc_attr_e( 'Search by username or email...', 'vigilante' ); ?>">
5803 <div id="vigilante-session-search-results" class="vigilante-user-search-results" style="display: none;"></div>
5804 </div>
5805
5806 <div id="vigilante-user-sessions-container" style="display: none; margin-top: 20px;">
5807 <h4 id="vigilante-sessions-user-name"></h4>
5808 <table class="wp-list-table widefat fixed striped vigilante-sessions-table">
5809 <thead>
5810 <tr>
5811 <th><?php esc_html_e( 'Browser', 'vigilante' ); ?></th>
5812 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
5813 <th><?php esc_html_e( 'Login Time', 'vigilante' ); ?></th>
5814 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5815 </tr>
5816 </thead>
5817 <tbody id="vigilante-user-sessions-list">
5818 </tbody>
5819 </table>
5820 <p style="margin-top: 10px;">
5821 <button type="button" class="button vigilante-revoke-all-user-sessions" style="color: #d63638;">
5822 <?php esc_html_e( 'Revoke All Sessions', 'vigilante' ); ?>
5823 </button>
5824 </p>
5825 </div>
5826 </div>
5827
5828 <?php endif; ?>
5829 </div>
5830 <?php
5831 }
5832
5833 /**
5834 * Render WordPress Hardening tab
5835 */
5836 private function render_tab_wp_hardening() {
5837 $is_disabled = $this->render_module_disabled_notice( 'wp_hardening' );
5838 $options = $this->settings->get_section( 'wp_hardening' );
5839 ?>
5840 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="wp_hardening" <?php echo $is_disabled ? 'inert' : ''; ?>>
5841 <!-- Database Hardening (outside form save flow - uses its own AJAX action) -->
5842 <?php $vg_shared_locked = $this->shared_files_locked(); ?>
5843 <?php $this->render_shared_files_notice(); ?>
5844 <div id="vigilante-section-hardening-database" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
5845 <h2>
5846 <?php esc_html_e( 'Database Hardening', 'vigilante' ); ?>
5847 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
5848 <span class="vigilante-method-badge config"><?php esc_html_e( 'WP-CONFIG', 'vigilante' ); ?></span>
5849 </h2>
5850 <p><?php esc_html_e( 'Change the database table prefix to prevent SQL injection attacks that target default WordPress tables.', 'vigilante' ); ?></p>
5851
5852 <?php
5853 $db_prefix = new Vigilante_Database_Prefix();
5854 $current_prefix = $db_prefix->get_current_prefix();
5855 $is_default = $db_prefix->is_default_prefix();
5856 ?>
5857
5858 <?php if ( is_multisite() && ! $vg_shared_locked ) : ?>
5859 <div class="notice notice-warning inline" style="margin:10px 0 16px;padding:8px 12px;">
5860 <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>
5861 </div>
5862 <?php endif; ?>
5863
5864 <table class="form-table">
5865 <tr>
5866 <th scope="row"><?php esc_html_e( 'Current prefix', 'vigilante' ); ?></th>
5867 <td>
5868 <code class="vigilante-db-current-prefix"><?php echo esc_html( $current_prefix ); ?></code>
5869 <?php if ( $is_default ) : ?>
5870 <span class="vigilante-inline-warning">
5871 <span class="dashicons dashicons-warning"></span>
5872 <?php esc_html_e( 'Default prefix detected. Changing it adds a layer of protection against automated SQL injection attacks.', 'vigilante' ); ?>
5873 </span>
5874 <?php else : ?>
5875 <span class="vigilante-inline-ok">
5876 <span class="dashicons dashicons-yes-alt"></span>
5877 <?php esc_html_e( 'Custom prefix in use.', 'vigilante' ); ?>
5878 </span>
5879 <?php endif; ?>
5880 </td>
5881 </tr>
5882 <tr>
5883 <th scope="row"><?php esc_html_e( 'New prefix', 'vigilante' ); ?></th>
5884 <td>
5885 <div class="vigilante-db-prefix-row">
5886 <code class="vigilante-db-new-prefix" id="vigilante-new-prefix"><?php echo esc_html( $db_prefix->generate_prefix() ); ?></code>
5887 <button type="button" class="button button-small vigilante-db-regenerate-prefix" title="<?php esc_attr_e( 'Generate new prefix', 'vigilante' ); ?>">
5888 <span class="dashicons dashicons-update"></span>
5889 </button>
5890 </div>
5891 </td>
5892 </tr>
5893 <tr>
5894 <th scope="row"></th>
5895 <td>
5896 <div class="vigilante-db-prefix-confirm">
5897 <label>
5898 <input type="checkbox" id="vigilante-prefix-backup-confirm">
5899 <?php esc_html_e( 'I understand this operation is irreversible and I have a current database backup', 'vigilante' ); ?>
5900 </label>
5901 <p class="description">
5902 <?php
5903 printf(
5904 /* translators: %s: Link to tools tab */
5905 esc_html__( 'Need a backup? %s first.', 'vigilante' ),
5906 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Download a database backup', 'vigilante' ) . '</a>'
5907 );
5908 ?>
5909 </p>
5910 </div>
5911 <button type="button" class="button button-primary vigilante-db-change-prefix" disabled data-original-text="<?php esc_attr_e( 'Change Database Prefix', 'vigilante' ); ?>">
5912 <?php esc_html_e( 'Change Database Prefix', 'vigilante' ); ?>
5913 </button>
5914 </td>
5915 </tr>
5916 </table>
5917 </div>
5918
5919 <!-- wp-config Security -->
5920 <?php
5921 $vg_shared_locked = $this->shared_files_locked();
5922 // Paint what is actually in force, not this site's unused copy.
5923 $vg_local_options = $options;
5924 $options = $this->get_section_for_display( 'wp_hardening' );
5925 ?>
5926 <?php $this->render_shared_files_notice(); ?>
5927 <div id="vigilante-section-hardening-wpconfig" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
5928 <h2>
5929 <?php esc_html_e( 'wp-config.php Security', 'vigilante' ); ?>
5930 <span class="vigilante-method-badge config"><?php esc_html_e( 'WP-CONFIG', 'vigilante' ); ?></span>
5931 </h2>
5932 <p><?php esc_html_e( 'Security constants added directly to wp-config.php file.', 'vigilante' ); ?></p>
5933
5934 <table class="form-table">
5935 <tr>
5936 <th scope="row"><?php esc_html_e( 'Disable File Editor', 'vigilante' ); ?></th>
5937 <td>
5938 <label>
5939 <input type="checkbox" name="wp_hardening[disallow_file_edit]" value="1" <?php checked( ! empty( $options['disallow_file_edit'] ) ); ?>>
5940 <?php esc_html_e( 'Disable plugin and theme editor in admin (DISALLOW_FILE_EDIT)', 'vigilante' ); ?>
5941 </label>
5942 </td>
5943 </tr>
5944 <tr>
5945 <th scope="row"><?php esc_html_e( 'Disable File Modifications', 'vigilante' ); ?></th>
5946 <td>
5947 <label>
5948 <input type="checkbox" name="wp_hardening[disallow_file_mods]" value="1" <?php checked( ! empty( $options['disallow_file_mods'] ) ); ?>>
5949 <?php esc_html_e( 'Disable all file modifications including updates (DISALLOW_FILE_MODS)', 'vigilante' ); ?>
5950 </label>
5951 <p class="description"><?php esc_html_e( '&#9888; Warning: This prevents automatic updates.', 'vigilante' ); ?></p>
5952 </td>
5953 </tr>
5954 <tr id="field-force-ssl-admin">
5955 <th scope="row"><?php esc_html_e( 'Force SSL Admin', 'vigilante' ); ?></th>
5956 <td>
5957 <label>
5958 <input type="checkbox" name="wp_hardening[force_ssl_admin]" value="1" <?php checked( ! empty( $options['force_ssl_admin'] ) ); ?>>
5959 <?php esc_html_e( 'Force HTTPS for admin area (FORCE_SSL_ADMIN)', 'vigilante' ); ?>
5960 </label>
5961 <p class="description"><?php esc_html_e( '&#9888; Warning: Only enable if your site fully supports HTTPS.', 'vigilante' ); ?></p>
5962 </td>
5963 </tr>
5964 <tr id="field-wp-debug">
5965 <th scope="row"><?php esc_html_e( 'Hide PHP errors from visitors', 'vigilante' ); ?></th>
5966 <td>
5967 <label>
5968 <input type="checkbox" name="wp_hardening[wp_debug]" value="1" <?php checked( ! empty( $options['wp_debug'] ) ); ?>>
5969 <?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' ); ?>
5970 </label>
5971 </td>
5972 </tr>
5973 <tr id="field-disable-wp-cron">
5974 <th scope="row"><?php esc_html_e( 'Disable WP Cron', 'vigilante' ); ?></th>
5975 <td>
5976 <label>
5977 <input type="checkbox" name="wp_hardening[disable_wp_cron]" value="1" <?php checked( ! empty( $options['disable_wp_cron'] ) ); ?>>
5978 <?php esc_html_e( 'Disable WordPress\'s page-view cron trigger (DISABLE_WP_CRON)', 'vigilante' ); ?>
5979 </label>
5980 <p class="description"><?php
5981 printf(
5982 /* translators: 1: opening <strong>, 2: closing </strong>, 3: opening <code>, 4: closing </code> */
5983 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' ),
5984 '<strong>',
5985 '</strong>',
5986 '<code>',
5987 '</code>'
5988 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
5989 ?></p>
5990 </td>
5991 </tr>
5992 </table>
5993 </div>
5994 <?php $options = $vg_local_options; ?>
5995
5996 <!-- Comment Security -->
5997 <div id="vigilante-section-hardening-xmlrpc" class="vigilante-settings-section">
5998 <h2>
5999 <?php esc_html_e( 'XML-RPC', 'vigilante' ); ?>
6000 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
6001 </h2>
6002 <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>
6003
6004 <table class="form-table">
6005 <tr id="field-disable-xmlrpc">
6006 <th scope="row"><label for="vigilante-f-wp-hardening-xmlrpc-mode"><?php esc_html_e( 'XML-RPC access', 'vigilante' ); ?></label></th>
6007 <td>
6008 <?php $vig_xmlrpc_mode = Vigilante_Comment_Security::resolve_xmlrpc_mode( $this->settings ); ?>
6009 <select id="vigilante-f-wp-hardening-xmlrpc-mode" name="wp_hardening[xmlrpc_mode]">
6010 <option value="none" <?php selected( $vig_xmlrpc_mode, 'none' ); ?>>
6011 <?php esc_html_e( 'Leave XML-RPC enabled', 'vigilante' ); ?>
6012 </option>
6013 <option value="pingback" <?php selected( $vig_xmlrpc_mode, 'pingback' ); ?>>
6014 <?php esc_html_e( 'Block the pingback methods only', 'vigilante' ); ?>
6015 </option>
6016 <option value="full" <?php selected( $vig_xmlrpc_mode, 'full' ); ?>>
6017 <?php esc_html_e( 'Disable XML-RPC completely (recommended)', 'vigilante' ); ?>
6018 </option>
6019 </select>
6020 <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>
6021 </td>
6022 </tr>
6023 </table>
6024 </div>
6025
6026 <div id="vigilante-section-hardening-comments" class="vigilante-settings-section">
6027 <h2>
6028 <?php esc_html_e( 'Comment Security', 'vigilante' ); ?>
6029 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
6030 <span class="vigilante-method-badge settings"><?php esc_html_e( 'Settings', 'vigilante' ); ?></span>
6031 </h2>
6032 <p><?php esc_html_e( 'Comment protection using WordPress settings and PHP hooks.', 'vigilante' ); ?></p>
6033
6034 <table class="form-table">
6035 <tr>
6036 <th scope="row"><?php esc_html_e( 'Disable Pingbacks', 'vigilante' ); ?></th>
6037 <td>
6038 <label>
6039 <input type="checkbox" name="wp_hardening[disable_pingbacks]" value="1" <?php checked( ! empty( $options['disable_pingbacks'] ) ); ?>>
6040 <?php esc_html_e( 'Disable pingbacks (commonly exploited for DDoS)', 'vigilante' ); ?>
6041 </label>
6042 </td>
6043 </tr>
6044 <tr>
6045 <th scope="row"><?php esc_html_e( 'Disable Trackbacks', 'vigilante' ); ?></th>
6046 <td>
6047 <label>
6048 <input type="checkbox" name="wp_hardening[disable_trackbacks]" value="1" <?php checked( ! empty( $options['disable_trackbacks'] ) ); ?>>
6049 <?php esc_html_e( 'Disable trackbacks (rarely used legitimately)', 'vigilante' ); ?>
6050 </label>
6051 </td>
6052 </tr>
6053 <tr>
6054 <th scope="row"><?php esc_html_e( 'Require Moderation', 'vigilante' ); ?></th>
6055 <td>
6056 <label>
6057 <input type="checkbox" name="wp_hardening[require_comment_moderation]" value="1" <?php checked( ! empty( $options['require_comment_moderation'] ) ); ?>>
6058 <?php esc_html_e( 'All comments must be manually approved', 'vigilante' ); ?>
6059 </label>
6060 </td>
6061 </tr>
6062 <tr>
6063 <th scope="row"><?php esc_html_e( 'Close Old Comments', 'vigilante' ); ?></th>
6064 <td>
6065 <label>
6066 <input type="checkbox" name="wp_hardening[close_old_comments]" value="1" <?php checked( ! empty( $options['close_old_comments'] ) ); ?>>
6067 <?php esc_html_e( 'Automatically close comments on old posts after', 'vigilante' ); ?>
6068 </label>
6069 <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">
6070 <label for="vigilante-f-wp-hardening-close-comments-after-days"><?php esc_html_e( 'days', 'vigilante' ); ?></label>
6071 </td>
6072 </tr>
6073 <tr>
6074 <th scope="row"><?php esc_html_e( 'Honeypot Protection', 'vigilante' ); ?></th>
6075 <td>
6076 <label>
6077 <input type="checkbox" name="wp_hardening[honeypot_comments]" value="1" <?php checked( ! empty( $options['honeypot_comments'] ) ); ?>>
6078 <?php esc_html_e( 'Add hidden honeypot field to catch bots', 'vigilante' ); ?>
6079 </label>
6080 </td>
6081 </tr>
6082 </table>
6083 </div>
6084
6085 <!-- Head Cleaner -->
6086 <div id="vigilante-section-hardening-headers" class="vigilante-settings-section">
6087 <h2>
6088 <?php esc_html_e( 'Header Cleanup', 'vigilante' ); ?>
6089 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
6090 </h2>
6091 <p><?php esc_html_e( 'Remove meta tags from HTML head.', 'vigilante' ); ?></p>
6092
6093 <table class="form-table">
6094 <tr>
6095 <th scope="row"><?php esc_html_e( 'Remove Generator', 'vigilante' ); ?></th>
6096 <td>
6097 <label>
6098 <input type="checkbox" name="wp_hardening[remove_wp_generator]" value="1" <?php checked( ! empty( $options['remove_wp_generator'] ) ); ?>>
6099 <?php esc_html_e( 'Remove WordPress version from HTML head', 'vigilante' ); ?>
6100 </label>
6101 </td>
6102 </tr>
6103 <tr id="field-remove-wp-version-assets">
6104 <th scope="row"><?php esc_html_e( 'Remove version from assets', 'vigilante' ); ?></th>
6105 <td>
6106 <label>
6107 <input type="checkbox" name="wp_hardening[remove_wp_version_assets]" value="1" <?php checked( ! empty( $options['remove_wp_version_assets'] ) ); ?>>
6108 <?php esc_html_e( 'Remove WordPress version from script/style URLs (?ver=)', 'vigilante' ); ?>
6109 </label>
6110 <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>
6111 </td>
6112 </tr>
6113 <tr>
6114 <th scope="row"><?php esc_html_e( 'Remove RSD Link', 'vigilante' ); ?></th>
6115 <td>
6116 <label>
6117 <input type="checkbox" name="wp_hardening[remove_rsd_link]" value="1" <?php checked( ! empty( $options['remove_rsd_link'] ) ); ?>>
6118 <?php esc_html_e( 'Remove Really Simple Discovery link', 'vigilante' ); ?>
6119 </label>
6120 </td>
6121 </tr>
6122 <tr>
6123 <th scope="row"><?php esc_html_e( 'Remove WLW Manifest', 'vigilante' ); ?></th>
6124 <td>
6125 <label>
6126 <input type="checkbox" name="wp_hardening[remove_wlw_manifest]" value="1" <?php checked( ! empty( $options['remove_wlw_manifest'] ) ); ?>>
6127 <?php esc_html_e( 'Remove Windows Live Writer manifest link', 'vigilante' ); ?>
6128 </label>
6129 </td>
6130 </tr>
6131 <tr>
6132 <th scope="row"><?php esc_html_e( 'Remove Shortlink', 'vigilante' ); ?></th>
6133 <td>
6134 <label>
6135 <input type="checkbox" name="wp_hardening[remove_shortlink]" value="1" <?php checked( ! empty( $options['remove_shortlink'] ) ); ?>>
6136 <?php esc_html_e( 'Remove shortlink tag from header', 'vigilante' ); ?>
6137 </label>
6138 </td>
6139 </tr>
6140 <tr>
6141 <th scope="row"><?php esc_html_e( 'Remove REST API Link', 'vigilante' ); ?></th>
6142 <td>
6143 <label>
6144 <input type="checkbox" name="wp_hardening[remove_rest_api_link]" value="1" <?php checked( ! empty( $options['remove_rest_api_link'] ) ); ?>>
6145 <?php esc_html_e( 'Remove REST API discovery link from header', 'vigilante' ); ?>
6146 </label>
6147 <p class="description"><?php esc_html_e( '&#9888; Notice: Some plugins may need this link.', 'vigilante' ); ?></p>
6148 </td>
6149 </tr>
6150 </table>
6151 </div>
6152
6153 <!-- Feed Manager -->
6154 <div id="vigilante-section-hardening-rss" class="vigilante-settings-section">
6155 <h2>
6156 <?php esc_html_e( 'RSS Feed Settings', 'vigilante' ); ?>
6157 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
6158 </h2>
6159 <p><?php esc_html_e( 'Control RSS/Atom feeds.', 'vigilante' ); ?></p>
6160
6161 <table class="form-table">
6162 <tr>
6163 <th scope="row"><?php esc_html_e( 'Disable Feeds', 'vigilante' ); ?></th>
6164 <td>
6165 <label>
6166 <input type="checkbox" name="wp_hardening[disable_feeds]" value="1" <?php checked( ! empty( $options['disable_feeds'] ) ); ?>>
6167 <?php esc_html_e( 'Completely disable RSS/Atom feeds', 'vigilante' ); ?>
6168 </label>
6169 </td>
6170 </tr>
6171 <tr>
6172 <th scope="row"><?php esc_html_e( 'Disable If No Content', 'vigilante' ); ?></th>
6173 <td>
6174 <label>
6175 <input type="checkbox" name="wp_hardening[disable_if_no_content]" value="1" <?php checked( ! empty( $options['disable_if_no_content'] ) ); ?>>
6176 <?php esc_html_e( 'Only disable feeds if site has no published posts', 'vigilante' ); ?>
6177 </label>
6178 </td>
6179 </tr>
6180 <tr>
6181 <th scope="row"><?php esc_html_e( 'Remove Feed Version', 'vigilante' ); ?></th>
6182 <td>
6183 <label>
6184 <input type="checkbox" name="wp_hardening[remove_feed_version]" value="1" <?php checked( ! empty( $options['remove_feed_version'] ) ); ?>>
6185 <?php esc_html_e( 'Remove WordPress version from feed generator tag', 'vigilante' ); ?>
6186 </label>
6187 </td>
6188 </tr>
6189 </table>
6190 </div>
6191
6192 <p class="submit vigilante-submit-buttons">
6193 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
6194 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
6195 </button>
6196 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
6197 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
6198 </button>
6199 </p>
6200 </form>
6201 <?php
6202 }
6203
6204 /**
6205 * Render activity log tab
6206 */
6207 private function render_tab_activity_log() {
6208 $is_disabled = $this->render_module_disabled_notice( 'activity_log' );
6209 $options = $this->settings->get_section( 'activity_log' );
6210 ?>
6211 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="activity_log" <?php echo $is_disabled ? 'inert' : ''; ?>>
6212 <div id="vigilante-section-audit-settings" class="vigilante-settings-section">
6213 <h2>
6214 <?php esc_html_e( 'Security Audit Settings', 'vigilante' ); ?>
6215 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
6216 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
6217 </h2>
6218 <p><?php esc_html_e( 'Security event logging and auditing.', 'vigilante' ); ?></p>
6219
6220 <table class="form-table">
6221 <tr>
6222 <th scope="row"><?php esc_html_e( 'Retention', 'vigilante' ); ?></th>
6223 <td>
6224 <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">
6225 <label for="vigilante-f-activity-log-retention-days"><?php esc_html_e( 'days', 'vigilante' ); ?></label>
6226 &nbsp;&nbsp;
6227 <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">
6228 <label for="vigilante-f-activity-log-max-entries"><?php esc_html_e( 'max entries', 'vigilante' ); ?></label>
6229 <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>
6230 </td>
6231 </tr>
6232 <tr>
6233 <th scope="row"><?php esc_html_e( 'Events to Log', 'vigilante' ); ?></th>
6234 <td>
6235 <fieldset style="display:grid; grid-template-columns:repeat(auto-fit, minmax(240px, 1fr)); gap:6px 24px; max-width:600px;">
6236 <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>
6237 <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>
6238 <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>
6239 <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>
6240 <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>
6241 <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>
6242 <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>
6243 <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>
6244 <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>
6245 <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>
6246 </fieldset>
6247 <div class="notice notice-info inline" style="margin:10px 0 0;padding:8px 12px;">
6248 <p style="margin:0;">
6249 <?php esc_html_e( 'Firewall blocks, security events, and Vigilant settings changes are always logged regardless of the above selections.', 'vigilante' ); ?>
6250 </p>
6251 </div>
6252 </td>
6253 </tr>
6254 <tr>
6255 <th scope="row"><label for="vigilante-f-activity-log-tracked-options"><?php esc_html_e( 'Option Tracking', 'vigilante' ); ?></label></th>
6256 <td>
6257 <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>
6258 <br>
6259 <label><?php esc_html_e( 'Additional options to track:', 'vigilante' ); ?></label><br>
6260 <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>
6261 <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>
6262 </td>
6263 </tr>
6264 <tr>
6265 <th scope="row"><?php esc_html_e( 'Exclusions', 'vigilante' ); ?></th>
6266 <td>
6267 <div style="display:grid; grid-template-columns:repeat(auto-fit, minmax(220px, 1fr)); gap:16px; max-width:600px;">
6268 <div>
6269 <label for="vigilante-f-activity-log-excluded-users"><?php esc_html_e( 'Excluded user IDs:', 'vigilante' ); ?></label><br>
6270 <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>
6271 <p class="description"><?php esc_html_e( 'One user ID per line. Actions by these users will not be logged.', 'vigilante' ); ?></p>
6272 </div>
6273 <div>
6274 <label for="vigilante-f-activity-log-excluded-ips"><?php esc_html_e( 'Excluded IPs:', 'vigilante' ); ?></label><br>
6275 <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>
6276 <p class="description"><?php esc_html_e( 'One IP per line. Requests from these IPs will not be logged.', 'vigilante' ); ?></p>
6277 </div>
6278 </div>
6279 </td>
6280 </tr>
6281 </table>
6282 </div>
6283
6284 <p class="submit vigilante-submit-buttons">
6285 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
6286 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
6287 </button>
6288 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
6289 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
6290 </button>
6291 </p>
6292 </form>
6293
6294 <?php
6295 // Audit Alerts — alerting layer on top of Security Audit. Its own
6296 // settings section and form, rendered right after the logging settings
6297 // so the tab reads as "log this, exclude that, and alert me about this".
6298 $alerts = $this->settings->get_section( 'audit_alerts' );
6299 $immediate = isset( $alerts['immediate'] ) ? $alerts['immediate'] : array();
6300 $threshold = isset( $alerts['threshold'] ) ? $alerts['threshold'] : array();
6301 $alert_severity = isset( $immediate['min_severity'] ) ? $immediate['min_severity'] : 'critical';
6302 $alert_window = isset( $threshold['window'] ) ? $threshold['window'] : '1h';
6303 $threshold_cats = isset( $threshold['categories'] ) ? (array) $threshold['categories'] : array();
6304 $cat_labels = Vigilante_Audit_Alerts::category_labels();
6305 ?>
6306 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="audit_alerts" <?php echo $is_disabled ? 'inert' : ''; ?>>
6307 <div id="vigilante-section-audit-alerts" class="vigilante-settings-section">
6308 <h2>
6309 <?php esc_html_e( 'Audit Alerts', 'vigilante' ); ?>
6310 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
6311 </h2>
6312 <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>
6313
6314 <table class="form-table">
6315 <tr id="field-audit-alerts-immediate">
6316 <th scope="row"><?php esc_html_e( 'Immediate alerts', 'vigilante' ); ?></th>
6317 <td>
6318 <label>
6319 <input type="checkbox" name="audit_alerts[immediate][enabled]" value="1" <?php checked( ! empty( $immediate['enabled'] ) ); ?>>
6320 <?php esc_html_e( 'Email me as soon as a serious event is logged', 'vigilante' ); ?>
6321 </label>
6322 <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>
6323 </td>
6324 </tr>
6325 <tr>
6326 <th scope="row"><label for="vigilante-f-audit-alerts-immediate-min-severity"><?php esc_html_e( 'Alert on severity', 'vigilante' ); ?></label></th>
6327 <td>
6328 <select id="vigilante-f-audit-alerts-immediate-min-severity" name="audit_alerts[immediate][min_severity]">
6329 <option value="critical" <?php selected( $alert_severity, 'critical' ); ?>><?php esc_html_e( 'Critical only (recommended)', 'vigilante' ); ?></option>
6330 <option value="warning" <?php selected( $alert_severity, 'warning' ); ?>><?php esc_html_e( 'Warning and Critical', 'vigilante' ); ?></option>
6331 </select>
6332 <p class="description"><?php esc_html_e( 'A closed plugin is logged as Critical, so "Critical only" covers it. A new administrator and a change of role are logged as Warning: they have their own emails, in Users > Admin monitoring, and reach this alert only with "Warning and Critical".', 'vigilante' ); ?></p>
6333 </td>
6334 </tr>
6335 <tr id="field-audit-alerts-threshold">
6336 <th scope="row"><?php esc_html_e( 'Threshold alerts', 'vigilante' ); ?></th>
6337 <td>
6338 <label>
6339 <input type="checkbox" name="audit_alerts[threshold][enabled]" value="1" <?php checked( ! empty( $threshold['enabled'] ) ); ?>>
6340 <?php esc_html_e( 'Email me when a category spikes within a time window', 'vigilante' ); ?>
6341 </label>
6342 <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>
6343 </td>
6344 </tr>
6345 <tr>
6346 <th scope="row"><label for="vigilante-f-audit-alerts-threshold-window"><?php esc_html_e( 'Time window', 'vigilante' ); ?></label></th>
6347 <td>
6348 <select id="vigilante-f-audit-alerts-threshold-window" name="audit_alerts[threshold][window]">
6349 <option value="30m" <?php selected( $alert_window, '30m' ); ?>><?php esc_html_e( '30 minutes', 'vigilante' ); ?></option>
6350 <option value="1h" <?php selected( $alert_window, '1h' ); ?>><?php esc_html_e( '1 hour', 'vigilante' ); ?></option>
6351 <option value="6h" <?php selected( $alert_window, '6h' ); ?>><?php esc_html_e( '6 hours', 'vigilante' ); ?></option>
6352 <option value="24h" <?php selected( $alert_window, '24h' ); ?>><?php esc_html_e( '24 hours', 'vigilante' ); ?></option>
6353 </select>
6354 <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>
6355 </td>
6356 </tr>
6357 <tr>
6358 <th scope="row"><?php esc_html_e( 'Thresholds per category', 'vigilante' ); ?></th>
6359 <td>
6360 <fieldset style="display:grid; grid-template-columns:repeat(auto-fit, minmax(200px, 1fr)); gap:8px 24px; max-width:760px;">
6361 <?php
6362 foreach ( $cat_labels as $cat_slug => $cat_label ) :
6363 $cat_value = isset( $threshold_cats[ $cat_slug ] ) ? (int) $threshold_cats[ $cat_slug ] : 0;
6364 ?>
6365 <label style="display:flex;align-items:center;gap:8px;justify-content:space-between;">
6366 <span><?php echo esc_html( $cat_label ); ?></span>
6367 <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">
6368 </label>
6369 <?php endforeach; ?>
6370 </fieldset>
6371 <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>
6372 </td>
6373 </tr>
6374 <tr>
6375 <th scope="row"><?php esc_html_e( "Don't repeat alerts", 'vigilante' ); ?></th>
6376 <td>
6377 <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">
6378 <label for="vigilante-f-audit-alerts-cooldown-minutes"><?php esc_html_e( 'minutes', 'vigilante' ); ?></label>
6379 <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>
6380 </td>
6381 </tr>
6382
6383 <tr>
6384 <th scope="row"><?php esc_html_e( 'Recipients', 'vigilante' ); ?></th>
6385 <td>
6386 <p class="description" style="margin-top:0;">
6387 <?php
6388 printf(
6389 /* translators: %s: Link to notification settings */
6390 esc_html__( 'Alerts go to the recipients configured in %s.', 'vigilante' ),
6391 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
6392 );
6393 ?>
6394 </p>
6395 <p style="margin:8px 0 0;">
6396 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
6397 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
6398 </button>
6399 <span class="vigilante-test-email-result" style="margin-left:8px;"></span>
6400 </p>
6401 <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>
6402 </td>
6403 </tr>
6404 </table>
6405 </div>
6406
6407 <p class="submit vigilante-submit-buttons">
6408 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
6409 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
6410 </button>
6411 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
6412 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
6413 </button>
6414 </p>
6415 </form>
6416
6417 <div id="vigilante-section-audit-recent" class="vigilante-settings-section">
6418 <h2><?php esc_html_e( 'Recent Activity', 'vigilante' ); ?></h2>
6419
6420 <?php
6421 $logs = $this->activity_log->get_logs( array( 'per_page' => 20 ) );
6422 $total_logs = $this->activity_log->get_logs_count();
6423
6424 // Label maps for translated display
6425 $type_labels = array(
6426 'login' => __( 'Login', 'vigilante' ),
6427 '2fa' => __( 'Two-factor', 'vigilante' ),
6428 'user' => __( 'User', 'vigilante' ),
6429 'content' => __( 'Content', 'vigilante' ),
6430 'plugin' => __( 'Plugin', 'vigilante' ),
6431 'theme' => __( 'Theme', 'vigilante' ),
6432 'settings' => __( 'Settings', 'vigilante' ),
6433 'comment' => __( 'Comment', 'vigilante' ),
6434 'media' => __( 'Media', 'vigilante' ),
6435 'firewall' => __( 'Firewall', 'vigilante' ),
6436 'file' => __( 'File', 'vigilante' ),
6437 'security' => __( 'Security', 'vigilante' ),
6438 'system' => __( 'System', 'vigilante' ),
6439 );
6440 $severity_labels = array(
6441 'info' => __( 'Info', 'vigilante' ),
6442 'warning' => __( 'Warning', 'vigilante' ),
6443 'critical' => __( 'Critical', 'vigilante' ),
6444 );
6445
6446 $firewall_options = $this->settings->get_section( 'firewall' );
6447 $ip_whitelist = $firewall_options['ip_whitelist'] ?? array();
6448 $ip_blacklist = $firewall_options['ip_blacklist'] ?? array();
6449 $ua_whitelist = $firewall_options['ua_whitelist'] ?? array();
6450 $ua_blacklist = $firewall_options['ua_blacklist'] ?? array();
6451 ?>
6452
6453 <div class="vigilante-log-filters">
6454 <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">
6455 <select id="vigilante-log-type-filter" aria-label="<?php esc_attr_e( 'Filter the log by event type', 'vigilante' ); ?>">
6456 <option value=""><?php esc_html_e( 'All Types', 'vigilante' ); ?></option>
6457 <option value="login"><?php esc_html_e( 'Login', 'vigilante' ); ?></option>
6458 <option value="2fa"><?php esc_html_e( 'Two-factor', 'vigilante' ); ?></option>
6459 <option value="user"><?php esc_html_e( 'User', 'vigilante' ); ?></option>
6460 <option value="content"><?php esc_html_e( 'Content', 'vigilante' ); ?></option>
6461 <option value="plugin"><?php esc_html_e( 'Plugin', 'vigilante' ); ?></option>
6462 <option value="theme"><?php esc_html_e( 'Theme', 'vigilante' ); ?></option>
6463 <option value="settings"><?php esc_html_e( 'Settings', 'vigilante' ); ?></option>
6464 <option value="comment"><?php esc_html_e( 'Comment', 'vigilante' ); ?></option>
6465 <option value="media"><?php esc_html_e( 'Media', 'vigilante' ); ?></option>
6466 <option value="firewall"><?php esc_html_e( 'Firewall', 'vigilante' ); ?></option>
6467 <option value="file"><?php esc_html_e( 'File', 'vigilante' ); ?></option>
6468 <option value="security"><?php esc_html_e( 'Security', 'vigilante' ); ?></option>
6469 <option value="system"><?php esc_html_e( 'System', 'vigilante' ); ?></option>
6470 </select>
6471 <select id="vigilante-log-severity-filter" aria-label="<?php esc_attr_e( 'Filter the log by severity', 'vigilante' ); ?>">
6472 <option value=""><?php esc_html_e( 'All Severities', 'vigilante' ); ?></option>
6473 <option value="info"><?php esc_html_e( 'Info', 'vigilante' ); ?></option>
6474 <option value="warning"><?php esc_html_e( 'Warning', 'vigilante' ); ?></option>
6475 <option value="critical"><?php esc_html_e( 'Critical', 'vigilante' ); ?></option>
6476 </select>
6477 <select id="vigilante-log-method-filter" aria-label="<?php esc_attr_e( 'Filter the log by HTTP method', 'vigilante' ); ?>">
6478 <option value=""><?php esc_html_e( 'All Methods', 'vigilante' ); ?></option>
6479 <option value="GET">GET</option>
6480 <option value="POST">POST</option>
6481 <option value="PUT">PUT</option>
6482 <option value="DELETE">DELETE</option>
6483 <option value="PATCH">PATCH</option>
6484 <option value="OPTIONS">OPTIONS</option>
6485 <option value="HEAD">HEAD</option>
6486 </select>
6487 <button type="button" id="vigilante-log-refresh" class="button"><?php esc_html_e( 'Refresh', 'vigilante' ); ?></button>
6488 <span class="vigilante-pagination" id="vigilante-log-pagination" data-total="<?php echo esc_attr( $total_logs ); ?>" data-per-page="20" data-page="1">
6489 <?php if ( $total_logs > 20 ) : ?>
6490 <button type="button" class="vigilante-page-first" title="<?php esc_attr_e( 'First page', 'vigilante' ); ?>" disabled>&laquo;</button>
6491 <button type="button" class="vigilante-page-prev" title="<?php esc_attr_e( 'Previous page', 'vigilante' ); ?>" disabled>&lsaquo;</button>
6492 <?php endif; ?>
6493 <span class="vigilante-page-info">
6494 <?php
6495 $showing = min( 20, $total_logs );
6496 printf(
6497 /* translators: 1: first item, 2: last item, 3: total items */
6498 esc_html__( '%1$d–%2$d of %3$d', 'vigilante' ),
6499 $total_logs > 0 ? 1 : 0,
6500 absint( $showing ),
6501 absint( $total_logs )
6502 );
6503 ?>
6504 </span>
6505 <?php if ( $total_logs > 20 ) : ?>
6506 <button type="button" class="vigilante-page-next" title="<?php esc_attr_e( 'Next page', 'vigilante' ); ?>">&rsaquo;</button>
6507 <button type="button" class="vigilante-page-last" title="<?php esc_attr_e( 'Last page', 'vigilante' ); ?>">&raquo;</button>
6508 <?php endif; ?>
6509 </span>
6510 </div>
6511
6512 <div class="vigilante-log-table-wrap">
6513 <table id="vigilante-activity-log-table" class="wp-list-table widefat striped">
6514 <thead>
6515 <tr>
6516 <th class="column-date"><?php esc_html_e( 'Date', 'vigilante' ); ?></th>
6517 <th class="column-type"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
6518 <th class="column-method"><?php esc_html_e( 'Method', 'vigilante' ); ?></th>
6519 <th class="column-severity"><?php esc_html_e( 'Severity', 'vigilante' ); ?></th>
6520 <th class="column-message"><?php esc_html_e( 'Message', 'vigilante' ); ?></th>
6521 <th class="column-user"><?php esc_html_e( 'User', 'vigilante' ); ?></th>
6522 <th class="column-ip"><?php esc_html_e( 'IP', 'vigilante' ); ?></th>
6523 <th class="column-details"><?php esc_html_e( 'Details', 'vigilante' ); ?></th>
6524 </tr>
6525 </thead>
6526 <tbody>
6527 <?php
6528 if ( empty( $logs ) ) :
6529 ?>
6530 <tr><td colspan="8"><?php esc_html_e( 'No log entries found.', 'vigilante' ); ?></td></tr>
6531 <?php else : ?>
6532 <?php foreach ( $logs as $log ) :
6533 $request_method = isset( $log->request_method ) ? $log->request_method : '';
6534 // Prepare details as a simple object
6535 $ip_val = (string) ( $log->ip_address ?? '' );
6536 $ua_val = (string) ( $log->user_agent ?? '' );
6537 $details = array(
6538 'id' => (int) $log->id,
6539 'type' => (string) ( $log->event_type ?? '' ),
6540 'action' => (string) ( $log->event_action ?? '' ),
6541 'message' => (string) ( $log->event_message ?? '' ),
6542 'user' => (string) ( $log->user_login ?? '' ),
6543 'ip' => $ip_val,
6544 'user_agent' => $ua_val,
6545 'request_method' => (string) $request_method,
6546 'request_uri' => Vigilante_Activity_Log::extract_request_uri( $log->extra_data ?? '' ),
6547 'date' => (string) ( $log->created_at ?? '' ),
6548 'severity' => (string) ( $log->severity ?? 'info' ),
6549 'is_ip_whitelisted' => ( '' !== $ip_val && in_array( $ip_val, $ip_whitelist, true ) ),
6550 'is_ip_blacklisted' => ( '' !== $ip_val && in_array( $ip_val, $ip_blacklist, true ) ),
6551 'is_ua_whitelisted' => ( '' !== $ua_val && in_array( $ua_val, $ua_whitelist, true ) ),
6552 'is_ua_blacklisted' => ( '' !== $ua_val && in_array( $ua_val, $ua_blacklist, true ) ),
6553 );
6554 // Self-protection entries carry what happened, what
6555 // it means and what to do, from the same catalogue
6556 // the File Integrity box uses.
6557 $vg_self_event = Vigilante_Self_Integrity_Guidance::for_log_event(
6558 (string) ( $log->event_action ?? '' ),
6559 $log->extra_data ?? '',
6560 (string) ( $log->severity ?? 'info' )
6561 );
6562 if ( null !== $vg_self_event ) {
6563 $details['self'] = $vg_self_event;
6564 }
6565 $display_type = isset( $type_labels[ $log->event_type ] ) ? $type_labels[ $log->event_type ] : $log->event_type;
6566 $display_severity = isset( $severity_labels[ $log->severity ] ) ? $severity_labels[ $log->severity ] : $log->severity;
6567 ?>
6568 <tr class="vigilante-severity-<?php echo esc_attr( $log->severity ); ?>">
6569 <td><?php echo esc_html( $log->created_at ); ?></td>
6570 <td><?php echo esc_html( $display_type ); ?></td>
6571 <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>
6572 <td><span class="vigilante-badge vigilante-badge-<?php echo esc_attr( $log->severity ); ?>"><?php echo esc_html( $display_severity ); ?></span></td>
6573 <td><?php echo esc_html( $log->event_message ); ?></td>
6574 <td><?php echo esc_html( $log->user_login ?? '-' ); ?></td>
6575 <td><code><?php echo esc_html( $log->ip_address ); ?></code></td>
6576 <td>
6577 <button type="button" class="button button-small vigilante-view-log-details"
6578 data-details='<?php echo esc_attr( wp_json_encode( $details, JSON_HEX_APOS | JSON_HEX_QUOT ) ); ?>'>
6579 <?php esc_html_e( 'View', 'vigilante' ); ?>
6580 </button>
6581 </td>
6582 </tr>
6583 <?php endforeach; ?>
6584 <?php endif; ?>
6585 </tbody>
6586 </table>
6587 </div>
6588
6589 <!-- Log Details Modal -->
6590 <div id="vigilante-log-details-modal" class="vigilante-modal" style="display: none;">
6591 <div class="vigilante-modal-content">
6592 <span class="vigilante-modal-close">&times;</span>
6593 <h3><?php esc_html_e( 'Log Entry Details', 'vigilante' ); ?></h3>
6594 <div id="vigilante-log-details-content"></div>
6595 </div>
6596 </div>
6597
6598 <p>
6599 <button type="button" class="button vigilante-export-logs"><?php esc_html_e( 'Export Audit Log', 'vigilante' ); ?></button>
6600 <button type="button" class="button vigilante-clear-logs" style="color: #a00;"><?php esc_html_e( 'Clear All Logs', 'vigilante' ); ?></button>
6601 </p>
6602 </div>
6603 <?php
6604 }
6605
6606 /**
6607 * Render File Integrity tab
6608 */
6609 /**
6610 * Findings of the self-check grouped by the case that explains them, worst
6611 * first: ten modified files are one case with ten paths, not ten copies of
6612 * the same explanation.
6613 *
6614 * @param array $findings Findings from the state.
6615 * @return array
6616 */
6617 private function self_findings_by_case( $findings ) {
6618 $groups = array();
6619 foreach ( (array) $findings as $finding ) {
6620 if ( ! is_array( $finding ) || 'info' === ( $finding['severity'] ?? '' ) ) {
6621 continue;
6622 }
6623 $guidance = Vigilante_Self_Integrity_Guidance::for_finding( $finding );
6624 $key = $guidance['key'];
6625 if ( ! isset( $groups[ $key ] ) ) {
6626 $guidance['files'] = array();
6627 $guidance['severity'] = 'warning';
6628 $groups[ $key ] = $guidance;
6629 }
6630 $file = isset( $finding['file'] ) ? (string) $finding['file'] : '';
6631 if ( '' !== $file && ! in_array( $file, $groups[ $key ]['files'], true ) ) {
6632 $groups[ $key ]['files'][] = $file;
6633 }
6634 if ( 'critical' === ( $finding['severity'] ?? '' ) ) {
6635 $groups[ $key ]['severity'] = 'critical';
6636 }
6637 }
6638 uasort(
6639 $groups,
6640 function ( $a, $b ) {
6641 $rank = array( 'critical' => 0, 'warning' => 1 );
6642 $ra = isset( $rank[ $a['severity'] ] ) ? $rank[ $a['severity'] ] : 2;
6643 $rb = isset( $rank[ $b['severity'] ] ) ? $rank[ $b['severity'] ] : 2;
6644 return $ra - $rb;
6645 }
6646 );
6647 return $groups;
6648 }
6649
6650 /**
6651 * Human label for the context that ran the last self-check.
6652 *
6653 * @param string $context Stored context.
6654 * @return string
6655 */
6656 private function self_context_label( $context ) {
6657 switch ( (string) $context ) {
6658 case 'scan':
6659 return __( 'during a file integrity scan', 'vigilante' );
6660 case 'upgrader':
6661 return __( 'right after updating Vigilant', 'vigilante' );
6662 case 'version_change':
6663 return __( 'after a version change made outside the updater', 'vigilante' );
6664 case 'migration':
6665 return __( 'while updating to this version', 'vigilante' );
6666 case 'activation':
6667 return __( 'when Vigilant was activated', 'vigilante' );
6668 case 'watchdog':
6669 return __( 'from the scheduled task watchdog', 'vigilante' );
6670 }
6671 return '';
6672 }
6673
6674 /**
6675 * Short line for the badge of the box, the notices and the Dashboard strip.
6676 *
6677 * @param string $tone Tone from Vigilante_Self_Integrity::tone().
6678 * @param array $state State.
6679 * @return string
6680 */
6681 private function self_integrity_headline( $tone, $state ) {
6682 $files = isset( $state['files_checked'] ) ? (int) $state['files_checked'] : 0;
6683 $anchors = ( isset( $state['anchors'] ) && is_array( $state['anchors'] ) ) ? $state['anchors'] : array();
6684 switch ( $tone ) {
6685 case 'critical':
6686 return __( 'Changes detected in Vigilant own files', 'vigilante' );
6687 case 'warning':
6688 return ( $files < 1 )
6689 ? __( 'Vigilant could not check its own files', 'vigilante' )
6690 : __( 'Vigilant self-protection needs your attention', 'vigilante' );
6691 case 'off':
6692 return __( 'Self-protection is switched off by code', 'vigilante' );
6693 case 'none':
6694 return __( 'Vigilant has not checked its own files yet', 'vigilante' );
6695 }
6696 return sprintf(
6697 /* translators: 1: number of files verified, 2: number of references available, out of three */
6698 __( 'Verified: %1$d files, %2$d of 3 references', 'vigilante' ),
6699 $files,
6700 count( array_filter( $anchors ) )
6701 );
6702 }
6703
6704 /**
6705 * Vigilant self-protection box: the first block of the File Integrity
6706 * results, with its own colour by severity, what each finding means and
6707 * how to fix it.
6708 *
6709 * It renders whether or not a scan has been stored, because the self-check
6710 * also runs after every update and once a day: before 3.0.0 this lived in
6711 * a line above the numeric cards of the last scan, where it was invisible
6712 * and, without a stored scan, absent.
6713 *
6714 * @param array $fi_options File Integrity settings section.
6715 */
6716 /**
6717 * Everything the screens need to say about self-protection, read once:
6718 * the state, its findings grouped by case, and the tone that colours the
6719 * box, the menu counter and the notices.
6720 *
6721 * @param array|null $fi_options File Integrity settings, read if not given.
6722 * @return array { state, findings, groups, tone, enabled }
6723 */
6724 private function self_integrity_summary( $fi_options = null ) {
6725 // Four to six screens ask for this in the same page load (menu, notice,
6726 // box, strip, both scores). The option is cached by the core options
6727 // layer, but the grouping and the tone are not: memoize per request.
6728 static $cached = null;
6729 if ( null !== $cached && ! is_array( $fi_options ) ) {
6730 return $cached;
6731 }
6732 if ( ! is_array( $fi_options ) ) {
6733 $fi_options = (array) $this->settings->get_section( 'file_integrity' );
6734 }
6735 $enabled = Vigilante_Self_Integrity::is_on();
6736 $state = Vigilante_Self_Integrity::display_state();
6737 $findings = Vigilante_Self_Integrity::state_findings( $state, $enabled );
6738 $summary = array(
6739 'state' => $state,
6740 'findings' => $findings,
6741 'groups' => $this->self_findings_by_case( $findings ),
6742 'tone' => Vigilante_Self_Integrity::tone( $state, $enabled ),
6743 'enabled' => $enabled,
6744 );
6745 $cached = $summary;
6746 return $summary;
6747 }
6748
6749 private function render_self_protection_box( $fi_options ) {
6750 $summary = $this->self_integrity_summary( $fi_options );
6751 $enabled = $summary['enabled'];
6752 $state = $summary['state'];
6753 $findings = $summary['findings'];
6754 $groups = $summary['groups'];
6755 $tone = $summary['tone'];
6756 $total = isset( $state['last_findings_total'] ) ? (int) $state['last_findings_total'] : count( $findings );
6757 $status = array(
6758 'status' => isset( $state['last_status'] ) ? (string) $state['last_status'] : '',
6759 'files' => isset( $state['files_checked'] ) ? (int) $state['files_checked'] : 0,
6760 'anchors' => ( isset( $state['anchors'] ) && is_array( $state['anchors'] ) ) ? $state['anchors'] : array(),
6761 'enabled' => $enabled,
6762 'has_run' => ! empty( $state['last_check'] ),
6763 );
6764
6765 /*
6766 * Nothing to do, nothing to open: one line. A card with a big icon and
6767 * folded sections for "everything is fine" is furniture, and furniture
6768 * is what made the previous version of this invisible.
6769 */
6770 if ( empty( $groups ) ) {
6771 $this->render_self_line( $tone, $state, $status );
6772 return;
6773 }
6774
6775 $datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
6776 $context_label = $this->self_context_label( isset( $state['last_context'] ) ? $state['last_context'] : '' );
6777 $icon = ( 'critical' === $tone ) ? 'dashicons-shield' : 'dashicons-warning';
6778 ?>
6779 <div id="vigilante-section-fi-self" class="vigilante-settings-section vigilante-self-box vigilante-self-box--<?php echo esc_attr( $tone ); ?>">
6780 <div class="vigilante-self-card">
6781 <div class="vigilante-self-head">
6782 <span class="vigilante-self-icon"><span class="dashicons <?php echo esc_attr( $icon ); ?>" aria-hidden="true"></span></span>
6783 <div class="vigilante-self-head-text">
6784 <h2><?php echo esc_html( $this->self_integrity_headline( $tone, $state ) ); ?></h2>
6785 <p class="vigilante-self-meta">
6786 <?php
6787 printf(
6788 /* translators: %s: date and time of the last self-check */
6789 esc_html__( 'Checked on %s', 'vigilante' ),
6790 esc_html( wp_date( $datetime_format, (int) $state['last_check'] ) )
6791 );
6792 if ( '' !== $context_label ) {
6793 echo ', ' . esc_html( $context_label );
6794 }
6795 if ( $status['files'] > 0 ) {
6796 echo ', ';
6797 printf(
6798 /* translators: 1: number of files checked, 2: number of references available, out of three */
6799 esc_html__( '%1$d files against %2$d of 3 references', 'vigilante' ),
6800 (int) $status['files'],
6801 (int) count( array_filter( $status['anchors'] ) )
6802 );
6803 }
6804 ?>
6805 </p>
6806 </div>
6807 </div>
6808
6809 <div class="vigilante-self-cases">
6810 <?php
6811 $first = true;
6812 foreach ( $groups as $group ) {
6813 $this->render_self_case( $group, $group['files'], $group['severity'], $first );
6814 $first = false;
6815 }
6816
6817 if ( in_array( $tone, array( 'critical', 'warning' ), true ) ) {
6818 $can_repair = class_exists( 'Vigilante_Self_Repair' ) && Vigilante_Self_Repair::can_repair();
6819 if ( ! $can_repair ) {
6820 if ( class_exists( 'Vigilante_Self_Repair' ) && ! Vigilante_Self_Repair::folder_is_the_distributed_one() ) {
6821 $vg_reason = 'renamed';
6822 } elseif ( ! wp_is_file_mod_allowed( 'capability_update_core' ) ) {
6823 // With DISALLOW_FILE_MODS nobody can do it from the admin,
6824 // not even a network administrator: telling a subsite admin
6825 // to ask theirs would send them to someone equally blocked.
6826 $vg_reason = 'no_caps';
6827 } elseif ( is_multisite() && ! current_user_can( 'update_plugins' ) ) {
6828 $vg_reason = 'network';
6829 } else {
6830 $vg_reason = 'no_caps';
6831 }
6832 $this->render_self_case(
6833 array(
6834 'title' => __( 'How to repair it here', 'vigilante' ),
6835 'meaning' => __( 'This site does not let Vigilant replace its own files from this screen.', 'vigilante' ),
6836 'steps' => Vigilante_Self_Integrity_Guidance::manual_steps( $vg_reason ),
6837 ),
6838 array(),
6839 '',
6840 false
6841 );
6842 }
6843 }
6844 ?>
6845 </div>
6846
6847 <?php if ( $total > count( $findings ) ) : ?>
6848 <p class="description">
6849 <?php
6850 printf(
6851 /* translators: 1: findings shown, 2: findings found in total */
6852 esc_html__( 'Showing %1$d of %2$d findings: the rest are of the same kind.', 'vigilante' ),
6853 (int) count( $findings ),
6854 (int) $total
6855 );
6856 ?>
6857 </p>
6858 <?php endif; ?>
6859
6860 <?php
6861 /*
6862 * Reinstalling fixes files, not a filter someone wrote or a hook
6863 * someone removed: the button only appears when at least one of the
6864 * cases on screen is one a clean copy solves. Offering it next to
6865 * "switched off by code" was telling the person to fix something
6866 * else.
6867 */
6868 $vg_offer_repair = false;
6869 foreach ( $groups as $vg_group ) {
6870 if ( ! empty( $vg_group['repair'] ) ) {
6871 $vg_offer_repair = true;
6872 break;
6873 }
6874 }
6875 ?>
6876 <p class="vigilante-self-actions">
6877 <?php if ( $vg_offer_repair && class_exists( 'Vigilante_Self_Repair' ) && Vigilante_Self_Repair::can_repair() ) : ?>
6878 <a class="button button-primary" href="<?php echo esc_url( Vigilante_Self_Repair::action_url() ); ?>">
6879 <?php esc_html_e( 'Repair Vigilant', 'vigilante' ); ?>
6880 </a>
6881 <span class="description">
6882 <?php esc_html_e( 'It downloads a clean copy from WordPress.org, asks before changing anything, and keeps your settings and log.', 'vigilante' ); ?>
6883 </span>
6884 <?php else : ?>
6885 <span class="description">
6886 <?php esc_html_e( 'After fixing it, run a new scan with the Run Scan Now button above.', 'vigilante' ); ?>
6887 </span>
6888 <?php endif; ?>
6889 </p>
6890 </div>
6891 </div>
6892 <?php
6893 }
6894
6895 /**
6896 * The same state when there is nothing to act on: one line inside the same
6897 * card, so the first block of the results is always the same object.
6898 *
6899 * @param string $tone Tone from Vigilante_Self_Integrity::tone().
6900 * @param array $state State.
6901 * @param array $status Arguments for the guidance catalogue.
6902 */
6903 private function render_self_line( $tone, $state, $status ) {
6904 $guidance = Vigilante_Self_Integrity_Guidance::for_status( $status );
6905 $icon = ( 'ok' === $tone ) ? 'dashicons-yes-alt' : 'dashicons-shield';
6906 ?>
6907 <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">
6908 <div class="vigilante-self-card vigilante-self-card--quiet">
6909 <p class="vigilante-self-line">
6910 <span class="dashicons <?php echo esc_attr( $icon ); ?>" aria-hidden="true"></span>
6911 <strong><?php esc_html_e( 'Vigilant self-protection:', 'vigilante' ); ?></strong>
6912 <span class="vigilante-self-line-state"><?php echo esc_html( $this->self_integrity_headline( $tone, $state ) ); ?></span>
6913 <?php if ( ! empty( $state['last_check'] ) ) : ?>
6914 <span class="vigilante-self-line-meta">
6915 <?php
6916 printf(
6917 /* translators: %s: human time difference, like "2 hours" */
6918 esc_html__( 'checked %s ago', 'vigilante' ),
6919 esc_html( human_time_diff( (int) $state['last_check'], time() ) )
6920 );
6921 ?>
6922 </span>
6923 <?php endif; ?>
6924 </p>
6925 <?php if ( ! empty( $guidance['steps'] ) && 'none' === $tone ) : ?>
6926 <p class="description vigilante-self-line-help"><?php echo esc_html( $guidance['steps'][0] ); ?></p>
6927 <?php endif; ?>
6928 </div>
6929 </div>
6930 <?php
6931 }
6932
6933 /**
6934 * One case of the self-protection box, as a row that opens: what it is, how
6935 * many files, its severity, and inside, the files, what it means and what to
6936 * do. Plain HTML details, so there is no JavaScript between a finding about
6937 * the security plugin and the person reading it.
6938 *
6939 * @param array $guidance Guidance entry (title, meaning, steps).
6940 * @param array $files Paths this case was found in.
6941 * @param string $severity critical|warning, empty for the how-to-repair row.
6942 * @param bool $open Whether the row starts open.
6943 */
6944 private function render_self_case( $guidance, $files = array(), $severity = '', $open = false ) {
6945 $shown = array_slice( (array) $files, 0, 20 );
6946 $hidden = count( (array) $files ) - count( $shown );
6947 ?>
6948 <details class="vigilante-self-case vigilante-self-case--<?php echo esc_attr( '' !== $severity ? $severity : 'plain' ); ?>"<?php echo $open ? ' open' : ''; ?>>
6949 <summary>
6950 <span class="vigilante-self-case-title"><?php echo esc_html( $guidance['title'] ); ?></span>
6951 <?php if ( ! empty( $files ) ) : ?>
6952 <span class="vigilante-self-case-count">
6953 <?php
6954 printf(
6955 /* translators: %d: number of files of this finding */
6956 esc_html( _n( '%d file', '%d files', count( (array) $files ), 'vigilante' ) ),
6957 (int) count( (array) $files )
6958 );
6959 ?>
6960 </span>
6961 <?php endif; ?>
6962 <?php if ( '' !== $severity ) : ?>
6963 <span class="vigilante-self-case-severity">
6964 <?php echo esc_html( 'critical' === $severity ? __( 'critical', 'vigilante' ) : __( 'warning', 'vigilante' ) ); ?>
6965 </span>
6966 <?php endif; ?>
6967 </summary>
6968 <div class="vigilante-self-case-body">
6969 <?php if ( ! empty( $shown ) ) : ?>
6970 <ul class="vigilante-self-paths">
6971 <?php foreach ( $shown as $file ) : ?>
6972 <li><code><?php echo esc_html( $file ); ?></code></li>
6973 <?php endforeach; ?>
6974 <?php if ( $hidden > 0 ) : ?>
6975 <li>
6976 <?php
6977 printf(
6978 /* translators: %d: number of additional files */
6979 esc_html__( 'and %d more', 'vigilante' ),
6980 (int) $hidden
6981 );
6982 ?>
6983 </li>
6984 <?php endif; ?>
6985 </ul>
6986 <?php endif; ?>
6987 <p class="vigilante-self-meaning">
6988 <strong><?php esc_html_e( 'What it means:', 'vigilante' ); ?></strong>
6989 <?php echo esc_html( $guidance['meaning'] ); ?>
6990 </p>
6991 <?php if ( ! empty( $guidance['steps'] ) ) : ?>
6992 <p class="vigilante-self-todo"><strong><?php esc_html_e( 'What to do:', 'vigilante' ); ?></strong></p>
6993 <ol class="vigilante-self-steps">
6994 <?php foreach ( $guidance['steps'] as $step ) : ?>
6995 <li><?php echo esc_html( $step ); ?></li>
6996 <?php endforeach; ?>
6997 </ol>
6998 <?php endif; ?>
6999 </div>
7000 </details>
7001 <?php
7002 }
7003
7004 /**
7005 * Print what each kind of finding in a list usually is and what to do
7006 *
7007 * One line per kind actually present in the list, from the single source
7008 * of that text, Vigilante_File_Integrity::finding_guidance().
7009 *
7010 * @param array $items Findings of one section of the last scan.
7011 */
7012 private function render_fi_guidance( $items ) {
7013 $seen = array();
7014 $guides = array();
7015
7016 foreach ( (array) $items as $item ) {
7017 $type = is_array( $item ) ? (string) ( $item['type'] ?? '' ) : '';
7018
7019 if ( '' === $type || 'vigilante_self' === $type || isset( $seen[ $type ] ) ) {
7020 continue;
7021 }
7022 $seen[ $type ] = true;
7023
7024 $guide = Vigilante_File_Integrity::finding_guidance( $type );
7025
7026 if ( '' !== $guide['advice'] ) {
7027 // A plugin and a theme share their text: one line for both,
7028 // under the two names.
7029 $guides[ $guide['advice'] ][] = $guide['label'];
7030 }
7031 }
7032
7033 if ( empty( $guides ) ) {
7034 return;
7035 }
7036 ?>
7037 <ul class="vigilante-fi-guidance" style="margin: 8px 0 12px 18px; list-style: disc;">
7038 <?php foreach ( $guides as $advice => $labels ) : ?>
7039 <li><strong><?php echo esc_html( implode( ', ', $labels ) ); ?>:</strong> <?php echo esc_html( $advice ); ?></li>
7040 <?php endforeach; ?>
7041 </ul>
7042 <?php
7043 }
7044
7045 private function render_tab_file_integrity() {
7046 $is_disabled = $this->render_module_disabled_notice( 'file_integrity' );
7047 $options = $this->settings->get_section( 'file_integrity' );
7048 // On the main site of a network the critical-file scan is the network's
7049 // canary for a change to wp-config.php or the root .htaccess, so a
7050 // main-site admin without network rights cannot turn it off. Since
7051 // 2.11.8; see Vigilante_Settings::get_main_site_file_settings().
7052 $vg_main_locked = $this->main_site_files_locked();
7053 $last_scan = get_option( 'vigilante_last_integrity_scan' );
7054 $last_results = get_option( 'vigilante_last_integrity_results' );
7055 $ignored_files = get_option( 'vigilante_ignored_files', array() );
7056
7057 /*
7058 * Vigilant own findings are shown in their own box, the first of the
7059 * results, with what each one means and how to fix it. They are taken
7060 * out of the generic tables here (and out of the counters above them)
7061 * so the same finding is not reported twice and so no row of the
7062 * security plugin's own files offers an Ignore button. The stored
7063 * results keep them: the scan email reads its own section from there.
7064 */
7065 if ( is_array( $last_results ) ) {
7066 foreach ( array( 'modified', 'suspicious', 'extra', 'missing' ) as $vg_bucket ) {
7067 if ( empty( $last_results[ $vg_bucket ] ) || ! is_array( $last_results[ $vg_bucket ] ) ) {
7068 continue;
7069 }
7070 $last_results[ $vg_bucket ] = array_values(
7071 array_filter(
7072 $last_results[ $vg_bucket ],
7073 function ( $vg_item ) {
7074 return ! ( is_array( $vg_item ) && 'vigilante_self' === ( $vg_item['type'] ?? '' ) );
7075 }
7076 )
7077 );
7078 }
7079 }
7080
7081 // Backward compat: convert old notify_on_changes to notify_level
7082 $notify_level = $options['notify_level'] ?? '';
7083 if ( empty( $notify_level ) ) {
7084 $notify_level = ! empty( $options['notify_on_changes'] ) ? 'all' : 'disabled';
7085 }
7086
7087 // Closed + Removed plugins data. Surfaced inside Last Scan Results so the
7088 // user sees file findings and plugin closures together (same tier of risk,
7089 // same UI), and as the trigger to keep Last Scan Results open even when no
7090 // file scan has run yet (the daily cron may have populated this section).
7091 //
7092 // Gating by last_check_time > 0 is how "Clear Previous Results" visually
7093 // resets this block: the option vigilante_plugin_status_last_check is
7094 // deleted on Clear, but the state map and the ignored list survive so the
7095 // next scan reconstructs without degrading a 'removed' slug. While
7096 // last_check is 0, we treat the plugin_status data as if it didn't exist.
7097 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
7098 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
7099 }
7100 $closed_checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
7101 $closed_last_check = $closed_checker->get_last_check_time();
7102 if ( $closed_last_check > 0 ) {
7103 $closed_plugins = $closed_checker->get_closed_plugins();
7104 $ignored_closed_plugins = $closed_checker->get_ignored_closed_plugins();
7105 } else {
7106 $closed_plugins = array();
7107 $ignored_closed_plugins = array();
7108 }
7109 $has_closed = ! empty( $closed_plugins );
7110 $datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
7111 ?>
7112 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="file_integrity" <?php echo $is_disabled ? 'inert' : ''; ?>>
7113 <div id="vigilante-section-fi-monitoring" class="vigilante-settings-section">
7114 <h2>
7115 <?php esc_html_e( 'File Integrity Monitoring', 'vigilante' ); ?>
7116 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
7117 </h2>
7118 <p><?php esc_html_e( 'Compares WordPress, and the plugins and themes that come from WordPress.org, with the official copy of each file, looks for code where there should be none (uploads and the site root) and watches wp-config.php and .htaccess for changes.', 'vigilante' ); ?></p>
7119 <p class="description"><?php esc_html_e( 'What it cannot compare: plugins and themes that are not on WordPress.org, must-use plugins, drop-ins (advanced-cache.php, object-cache.php and the like) and the other folders of wp-content have no official copy. They are searched for hidden code, which finds malware that disguises itself and misses most code written in the open. The results name what could not be compared.', 'vigilante' ); ?></p>
7120
7121 <table class="form-table">
7122 <tr>
7123 <th scope="row"><?php esc_html_e( 'Automatic Scans', 'vigilante' ); ?></th>
7124 <td>
7125 <label>
7126 <input type="checkbox" name="file_integrity[auto_scan]" value="1" <?php checked( ! empty( $options['auto_scan'] ) ); ?>>
7127 <?php esc_html_e( 'Enable scheduled file integrity scans', 'vigilante' ); ?>
7128 </label>
7129 </td>
7130 </tr>
7131 <tr>
7132 <th scope="row"><label for="vigilante-f-file-integrity-scan-frequency"><?php esc_html_e( 'Scan Frequency', 'vigilante' ); ?></label></th>
7133 <td>
7134 <select id="vigilante-f-file-integrity-scan-frequency" name="file_integrity[scan_frequency]">
7135 <option value="daily" <?php selected( $options['scan_frequency'] ?? 'daily', 'daily' ); ?>><?php esc_html_e( 'Daily', 'vigilante' ); ?></option>
7136 <option value="weekly" <?php selected( $options['scan_frequency'] ?? 'daily', 'weekly' ); ?>><?php esc_html_e( 'Weekly', 'vigilante' ); ?></option>
7137 </select>
7138 </td>
7139 </tr>
7140 <tr>
7141 <th scope="row"><label for="vigilante-f-file-integrity-notify-level"><?php esc_html_e( 'Email Notifications', 'vigilante' ); ?></label></th>
7142 <td>
7143 <select id="vigilante-f-file-integrity-notify-level" name="file_integrity[notify_level]">
7144 <option value="all" <?php selected( $notify_level, 'all' ); ?>><?php esc_html_e( 'Every finding, modified files included', 'vigilante' ); ?></option>
7145 <option value="suspicious_only" <?php selected( $notify_level, 'suspicious_only' ); ?>><?php esc_html_e( 'Serious findings only', 'vigilante' ); ?></option>
7146 <option value="disabled" <?php selected( $notify_level, 'disabled' ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
7147 </select>
7148 <p class="description"><?php esc_html_e( 'Serious findings are suspicious and extra files, changes in wp-config.php or .htaccess and closed plugins. That is the recommended choice: a file that is only modified is rarely more than an update that did not finish. The email goes out when a scan finds something new: a finding you were already told about is not sent again, unless the file changes once more.', 'vigilante' ); ?></p>
7149 </td>
7150 </tr>
7151 <tr>
7152 <th scope="row"><?php esc_html_e( 'Instant Alert', 'vigilante' ); ?></th>
7153 <td>
7154 <label>
7155 <input type="checkbox" name="file_integrity[instant_alert]" value="1" <?php checked( ! empty( $options['instant_alert'] ) ); ?>>
7156 <?php esc_html_e( 'Email every finding when a scan ends, modified files included, and email a closed plugin as soon as the daily check finds it', 'vigilante' ); ?>
7157 </label>
7158 <p class="description"><?php esc_html_e( 'This takes precedence over the choice above, Disabled included.', 'vigilante' ); ?></p>
7159 <p class="description">
7160 <?php
7161 printf(
7162 /* translators: %s: Link to notification settings */
7163 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
7164 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
7165 );
7166 ?>
7167 </p>
7168 </td>
7169 </tr>
7170 <tr>
7171 <th scope="row"><?php esc_html_e( 'Test email', 'vigilante' ); ?></th>
7172 <td>
7173 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
7174 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
7175 </button>
7176 <span class="vigilante-test-email-result" style="margin-left:8px;"></span>
7177 <p class="description"><?php esc_html_e( 'Sends a test message to the configured recipients to confirm email delivery works.', 'vigilante' ); ?></p>
7178 </td>
7179 </tr>
7180 <tr>
7181 <th scope="row"><?php esc_html_e( 'Scan Scope', 'vigilante' ); ?></th>
7182 <td>
7183 <fieldset>
7184 <label>
7185 <input type="checkbox" name="file_integrity[scan_core]" value="1" <?php checked( $options['scan_core'] ?? true ); ?>>
7186 <?php esc_html_e( 'WordPress core (compared with WordPress.org) and the other files in the site root', 'vigilante' ); ?>
7187 </label>
7188 <br>
7189 <label>
7190 <input type="checkbox" name="file_integrity[scan_plugins]" value="1" <?php checked( $options['scan_plugins'] ?? true ); ?>>
7191 <?php esc_html_e( 'Plugins (compared with WordPress.org; the rest, and the other folders of wp-content, are only searched for hidden code)', 'vigilante' ); ?>
7192 </label>
7193 <br>
7194 <label>
7195 <input type="checkbox" name="file_integrity[scan_themes]" value="1" <?php checked( $options['scan_themes'] ?? true ); ?>>
7196 <?php esc_html_e( 'Themes (compared with WordPress.org; the rest are only searched for hidden code)', 'vigilante' ); ?>
7197 </label>
7198 <br>
7199 <label>
7200 <input type="checkbox" name="file_integrity[scan_uploads]" value="1" <?php checked( $options['scan_uploads'] ?? true ); ?>>
7201 <?php esc_html_e( 'Uploads directory (PHP and other scripts, double extensions, .htaccess and PHP configuration files)', 'vigilante' ); ?>
7202 </label>
7203 <br>
7204 <label>
7205 <input type="checkbox" name="file_integrity[scan_critical_config]" value="1" <?php disabled( $vg_main_locked ); ?> <?php checked( $options['scan_critical_config'] ?? true ); ?>>
7206 <?php esc_html_e( 'wp-config.php and .htaccess (any change since you last approved them)', 'vigilante' ); ?>
7207 <?php if ( $vg_main_locked ) : ?>
7208 <span class="description" style="display:block;margin-left:24px;"><?php echo esc_html( Vigilante_Settings::get_shared_files_notice() ); ?></span>
7209 <?php endif; ?>
7210 </label>
7211 <br>
7212 <label>
7213 <input type="checkbox" name="file_integrity[check_closed_plugins]" value="1" <?php checked( $options['check_closed_plugins'] ?? true ); ?>>
7214 <?php esc_html_e( 'Closed plugins (daily check against the WordPress.org repository)', 'vigilante' ); ?>
7215 </label>
7216 </fieldset>
7217 </td>
7218 </tr>
7219 <tr>
7220 <th scope="row"><label for="vigilante-f-file-integrity-excluded-paths"><?php esc_html_e( 'Excluded Paths', 'vigilante' ); ?></label></th>
7221 <td>
7222 <textarea id="vigilante-f-file-integrity-excluded-paths" name="file_integrity[excluded_paths]" rows="4" class="large-text code" placeholder="wp-content/backups"><?php echo esc_textarea( implode( "\n", $options['excluded_paths'] ?? array() ) ); ?></textarea>
7223 <p class="description"><?php esc_html_e( 'One path per line, relative to the WordPress root. A path such as wp-content/backups excludes exactly that folder and everything under it. A name on its own, such as backups, excludes any folder called exactly that, wherever it is. Nothing in an excluded folder is looked at, so keep the list short.', 'vigilante' ); ?></p>
7224 </td>
7225 </tr>
7226 <tr>
7227 <th scope="row"><label for="vigilante-f-file-integrity-excluded-extensions"><?php esc_html_e( 'Excluded Extensions', 'vigilante' ); ?></label></th>
7228 <td>
7229 <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>
7230 <p class="description">
7231 <?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' ); ?>
7232 <br>
7233 <?php
7234 printf(
7235 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the scoped-extension example. */
7236 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' ),
7237 '<code>',
7238 '</code>'
7239 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
7240 ?>
7241 </p>
7242 </td>
7243 </tr>
7244 </table>
7245 </div>
7246
7247 <p class="submit vigilante-submit-buttons">
7248 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
7249 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
7250 </button>
7251 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
7252 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
7253 </button>
7254 <span class="vigilante-buttons-separator"></span>
7255 <button type="button" class="button button-primary vigilante-run-scan">
7256 <?php esc_html_e( 'Run Scan Now', 'vigilante' ); ?>
7257 </button>
7258 <button type="button" class="button vigilante-clear-scan-btn vigilante-clear-scan">
7259 <?php esc_html_e( 'Clear Previous Results', 'vigilante' ); ?>
7260 </button>
7261 </p>
7262 </form>
7263
7264 <div id="vigilante-scan-results" class="vigilante-settings-section" style="display:none;"></div>
7265
7266 <?php $this->render_self_protection_box( $options ); ?>
7267
7268 <?php
7269 // Whole folders of code left out of every scan. A partial scan tells
7270 // how to check the rest by excluding what it did check, and those
7271 // lines have to come out afterwards: with them in place a scan comes
7272 // out complete and clean without having looked there. Said for as
7273 // long as they are in the list, whoever put them there and why.
7274 $vg_fi_tool = new Vigilante_File_Integrity( $this->settings, $this->database );
7275 $vg_excluded_code = $vg_fi_tool->excluded_code_folders();
7276 $vg_folders_to_skip = $vg_fi_tool->folders_to_exclude( $last_results );
7277 ?>
7278 <?php if ( ! empty( $vg_excluded_code ) ) : ?>
7279 <div id="vigilante-fi-excluded-code" class="notice notice-warning inline">
7280 <p>
7281 <strong>
7282 <?php
7283 printf(
7284 /* translators: %s: Comma separated list of folders */
7285 esc_html__( 'Excluded Paths holds whole folders of plugins or themes, or the uploads folder: %s.', 'vigilante' ),
7286 esc_html( implode( ', ', $vg_excluded_code ) )
7287 );
7288 ?>
7289 </strong>
7290 <?php esc_html_e( 'No scan looks inside them, the scheduled one included, and a scan can come out complete and clean without having checked them. If you added them to check the rest of a large site, take them out once that scan is done.', 'vigilante' ); ?>
7291 </p>
7292 </div>
7293 <?php endif; ?>
7294
7295 <?php if ( $last_scan || $has_closed || $closed_last_check > 0 ) : ?>
7296 <div id="vigilante-section-fi-last-scan" class="vigilante-settings-section">
7297 <h2><?php esc_html_e( 'Last Scan Results', 'vigilante' ); ?></h2>
7298 <?php
7299 // A scan the server stops halfway stores nothing, and neither
7300 // does one WordPress never starts: the tab kept showing the
7301 // last result that did finish, with nothing to say that scans
7302 // had stopped. Its date is the only sign.
7303 if ( $last_scan && $this->settings->is_module_enabled( 'file_integrity' ) && Vigilante_File_Integrity::is_scan_overdue( $last_scan, $options['scan_frequency'] ?? 'daily' ) ) :
7304 ?>
7305 <div class="notice notice-warning inline">
7306 <p><strong><?php esc_html_e( 'Scans are scheduled, and none has finished since the date below.', 'vigilante' ); ?></strong> <?php esc_html_e( 'Either WordPress is not running its scheduled tasks, or the server stops the scan before it ends, and a scan that is stopped stores no result. What you see here is old. Run a scan now: if it finishes, the scheduled tasks are what is failing. If it does not, the site is too large for the time the server gives a request, and adding large folders that do not need checking to Excluded Paths leaves more time for the rest.', 'vigilante' ); ?></p>
7307 </div>
7308 <?php endif; ?>
7309 <?php if ( $last_scan ) : ?>
7310 <p>
7311 <?php
7312 // Build the "X files scanned" hint inline with the date so it doesn't
7313 // need its own stat box (keeps the row compact when closed plugins are
7314 // present).
7315 $scanned_total = 0;
7316 if ( $last_results ) {
7317 $scanned_total = (int) ( $last_results['ok'] ?? 0 )
7318 + count( $last_results['modified'] ?? array() )
7319 + count( $last_results['suspicious'] ?? array() )
7320 + count( $last_results['extra'] ?? array() )
7321 + count( $ignored_files );
7322 }
7323 if ( $scanned_total > 0 ) {
7324 printf(
7325 /* translators: 1: date and time of last scan, 2: formatted file count */
7326 esc_html__( 'Last scan: %1$s (%2$s files scanned)', 'vigilante' ),
7327 esc_html( wp_date( $datetime_format, $last_scan ) ),
7328 esc_html( number_format_i18n( $scanned_total ) )
7329 );
7330 } else {
7331 printf(
7332 /* translators: %s: date and time of last scan */
7333 esc_html__( 'Last scan: %s', 'vigilante' ),
7334 esc_html( wp_date( $datetime_format, $last_scan ) )
7335 );
7336 }
7337 if ( $closed_last_check > 0 && $closed_last_check !== (int) $last_scan ) {
7338 echo ' &middot; ';
7339 printf(
7340 /* translators: %s: date and time of last closed plugins check */
7341 esc_html__( 'Closed plugins last checked: %s', 'vigilante' ),
7342 esc_html( wp_date( $datetime_format, $closed_last_check ) )
7343 );
7344 }
7345 ?>
7346 </p>
7347 <?php elseif ( $closed_last_check > 0 ) : ?>
7348 <p>
7349 <?php
7350 printf(
7351 /* translators: %s: date and time of last closed plugins check */
7352 esc_html__( 'Closed plugins last checked: %s &middot; the daily cron is running, no full integrity scan yet.', 'vigilante' ),
7353 esc_html( wp_date( $datetime_format, $closed_last_check ) )
7354 );
7355 ?>
7356 </p>
7357 <?php endif; ?>
7358 <div id="vigilante-last-scan-results">
7359 <?php if ( $last_results || $has_closed ) : ?>
7360 <div class="vigilante-scan-summary">
7361 <?php if ( $last_results ) : ?>
7362 <div class="vigilante-scan-stat vigilante-stat-ok">
7363 <span class="vigilante-stat-number"><?php echo esc_html( $last_results['ok'] ?? 0 ); ?></span>
7364 <span class="vigilante-stat-label"><?php esc_html_e( 'OK', 'vigilante' ); ?></span>
7365 </div>
7366 <div class="vigilante-scan-stat vigilante-stat-modified">
7367 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['modified'] ?? array() ) ); ?></span>
7368 <span class="vigilante-stat-label"><?php esc_html_e( 'Modified', 'vigilante' ); ?></span>
7369 </div>
7370 <div class="vigilante-scan-stat vigilante-stat-suspicious">
7371 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['suspicious'] ?? array() ) ); ?></span>
7372 <span class="vigilante-stat-label"><?php esc_html_e( 'Suspicious', 'vigilante' ); ?></span>
7373 </div>
7374 <div class="vigilante-scan-stat vigilante-stat-extra">
7375 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['extra'] ?? array() ) ); ?></span>
7376 <span class="vigilante-stat-label"><?php esc_html_e( 'Extra', 'vigilante' ); ?></span>
7377 </div>
7378 <?php endif; ?>
7379 <?php if ( $has_closed ) : ?>
7380 <div class="vigilante-scan-stat vigilante-stat-suspicious">
7381 <span class="vigilante-stat-number" style="color: #d63638;"><?php echo (int) count( $closed_plugins ); ?></span>
7382 <span class="vigilante-stat-label"><?php esc_html_e( 'Closed/Removed', 'vigilante' ); ?></span>
7383 </div>
7384 <?php endif; ?>
7385 <?php if ( ! empty( $ignored_files ) ) : ?>
7386 <div class="vigilante-scan-stat vigilante-stat-ignored">
7387 <span class="vigilante-stat-number"><?php echo esc_html( count( $ignored_files ) ); ?></span>
7388 <span class="vigilante-stat-label"><?php esc_html_e( 'Ignored', 'vigilante' ); ?></span>
7389 </div>
7390 <?php endif; ?>
7391 </div>
7392
7393 <?php
7394 // A scan that could not finish, or could not get the official
7395 // copy to compare with, checked less than it seems. Until now
7396 // its errors were stored and never shown, and the tab could
7397 // say that every file had passed.
7398 $vg_scan_errors = ( $last_results && ! empty( $last_results['errors'] ) && is_array( $last_results['errors'] ) ) ? $last_results['errors'] : array();
7399 $vg_scan_partial = ! empty( $vg_scan_errors ) || ( $last_results && ! empty( $last_results['incomplete'] ) );
7400
7401 // Files of the official copies that are not on the server. Core
7402 // files under wp-content are left out: results stored before
7403 // the bundled themes and plugins got their own turn list
7404 // there the ones people delete on purpose.
7405 $vg_missing_core = array();
7406 if ( $last_results && ! empty( $last_results['missing'] ) && is_array( $last_results['missing'] ) ) {
7407 foreach ( $last_results['missing'] as $item ) {
7408 if ( ! is_array( $item ) || ! isset( $item['file'] ) ) {
7409 continue;
7410 }
7411
7412 $vg_missing_type = (string) ( $item['type'] ?? '' );
7413
7414 if ( in_array( $vg_missing_type, array( 'plugin', 'theme' ), true )
7415 || ( 'core' === $vg_missing_type && 0 !== strpos( (string) $item['file'], 'wp-content/' ) ) ) {
7416 $vg_missing_core[] = (string) $item['file'];
7417 }
7418 }
7419 }
7420 ?>
7421
7422 <?php if ( $last_results && ! empty( $last_results['unverified'] ) && is_array( $last_results['unverified'] ) ) : ?>
7423 <p class="description">
7424 <?php
7425 printf(
7426 /* translators: %s: Comma separated list of plugin and theme names */
7427 esc_html__( 'No official copy to compare with, so only searched for hidden code: %s.', 'vigilante' ),
7428 esc_html( implode( ', ', array_unique( array_map( 'strval', $last_results['unverified'] ) ) ) )
7429 );
7430 ?>
7431 </p>
7432 <?php endif; ?>
7433
7434 <?php
7435 // What the scan did not get to, by name. A scan starts from
7436 // the beginning every time, so on a site too large for it
7437 // these are the same on every scan, and whoever reads the
7438 // result has to know that nothing here was looked at.
7439 $vg_scan_notes = array_merge( $vg_scan_errors, Vigilante_File_Integrity::not_checked_lines( $last_results ) );
7440 ?>
7441 <?php if ( $vg_scan_partial ) : ?>
7442 <div class="notice notice-warning inline">
7443 <p><strong><?php esc_html_e( 'The last scan could not check everything, so its result is partial.', 'vigilante' ); ?></strong></p>
7444 <?php if ( ! empty( $vg_scan_notes ) ) : ?>
7445 <ul style="margin: 0 0 8px 18px; list-style: disc;">
7446 <?php foreach ( $vg_scan_notes as $vg_scan_note ) : ?>
7447 <li><?php echo esc_html( (string) $vg_scan_note ); ?></li>
7448 <?php endforeach; ?>
7449 </ul>
7450 <?php endif; ?>
7451 <p>
7452 <?php
7453 printf(
7454 /* translators: %d: Seconds a scan runs for at most */
7455 esc_html__( 'Run the scan again: a second scan is faster, because what it downloads from WordPress.org is kept for a while. If the result is still partial, either the server cannot reach WordPress.org or the site is larger than a scan can check in its %d seconds, and then every scan leaves the same part unchecked. Adding large folders that do not need checking to Excluded Paths leaves more time for the rest.', 'vigilante' ),
7456 (int) Vigilante_File_Integrity::MAX_SCAN_SECONDS
7457 );
7458 ?>
7459 </p>
7460 <?php if ( ! empty( $vg_folders_to_skip ) ) : ?>
7461 <p><strong><?php esc_html_e( 'To check what was left out:', 'vigilante' ); ?></strong></p>
7462 <ol style="margin: 0 0 8px 18px;">
7463 <li><?php esc_html_e( 'Deal first with what this scan found in the plugins and themes it did check: the next result will not list it. Then add the lines below, which are their folders, to Excluded Paths, higher up on this page, and save.', 'vigilante' ); ?></li>
7464 <li><?php esc_html_e( 'Press Run Scan Now. The scan spends its time on the rest. If it comes out partial again, repeat with the lines it gives then.', 'vigilante' ); ?></li>
7465 <li><?php esc_html_e( 'Take those lines out of Excluded Paths. While they are there no scan looks inside those folders, the scheduled one included.', 'vigilante' ); ?></li>
7466 </ol>
7467 <textarea id="vigilante-fi-folders-to-exclude" readonly rows="<?php echo (int) min( 12, max( 3, count( $vg_folders_to_skip ) ) ); ?>" class="large-text code" style="margin-bottom: 8px;"><?php echo esc_textarea( implode( "\n", $vg_folders_to_skip ) ); ?></textarea>
7468 <?php endif; ?>
7469 </div>
7470 <?php endif; ?>
7471
7472 <?php if ( ! empty( $vg_missing_core ) ) : ?>
7473 <div class="vigilante-file-list">
7474 <h3><?php esc_html_e( 'Missing Files', 'vigilante' ); ?></h3>
7475 <p class="description"><?php esc_html_e( 'These files are in the official copy and not on the server. Reinstall what they belong to (WordPress from Dashboard > Updates, a plugin or a theme from its own screen) and scan again.', 'vigilante' ); ?></p>
7476 <ul style="margin: 8px 0 12px 18px; list-style: disc;">
7477 <?php foreach ( array_slice( $vg_missing_core, 0, 20 ) as $vg_missing_file ) : ?>
7478 <li><code><?php echo esc_html( $vg_missing_file ); ?></code></li>
7479 <?php endforeach; ?>
7480 </ul>
7481 <?php if ( count( $vg_missing_core ) > 20 ) : ?>
7482 <p class="description">
7483 <?php
7484 /* translators: %d: Number of additional files */
7485 printf( esc_html__( '... and %d more', 'vigilante' ), (int) ( count( $vg_missing_core ) - 20 ) );
7486 ?>
7487 </p>
7488 <?php endif; ?>
7489 </div>
7490 <?php endif; ?>
7491
7492 <?php if ( ! empty( $last_results['suspicious'] ) ) : ?>
7493 <div class="vigilante-file-list vigilante-suspicious-files vigilante-paginated-section" data-bulk-mode="ignore">
7494 <h3 style="color: #d63638;"><?php esc_html_e( 'Suspicious Files', 'vigilante' ); ?></h3>
7495 <p class="description" style="color: #d63638;"><?php esc_html_e( '&#9888; Files that can run code where none is expected, or that contain code written the way malware hides itself. Real infections show up here, and so do harmless files that plugins generate. Check the path and the reason before acting.', 'vigilante' ); ?></p>
7496 <?php $this->render_fi_guidance( $last_results['suspicious'] ); ?>
7497 <div class="vigilante-fi-bulk-bar">
7498 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
7499 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
7500 </div>
7501 <div class="vigilante-fi-pagination-wrap"></div>
7502 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
7503 <thead>
7504 <tr>
7505 <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>
7506 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
7507 <th style="width: 250px;"><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
7508 <th style="width: 120px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
7509 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
7510 </tr>
7511 </thead>
7512 <tbody>
7513 <?php
7514 foreach ( $last_results['suspicious'] as $item ) {
7515 $file_path = '';
7516 $file_reason = __( 'Unknown', 'vigilante' );
7517 $file_type = 'unknown';
7518
7519 if ( is_array( $item ) ) {
7520 if ( isset( $item['file'] ) ) {
7521 $file_path = $item['file'];
7522 }
7523 if ( isset( $item['reason'] ) ) {
7524 $file_reason = $item['reason'];
7525 }
7526 if ( isset( $item['type'] ) ) {
7527 $file_type = $item['type'];
7528 }
7529 } else {
7530 $file_path = (string) $item;
7531 }
7532 if ( 'vigilante_self' === $file_type ) {
7533 $file_type = __( 'Vigilant (self)', 'vigilante' );
7534 } else {
7535 // A name a person can read, instead of the internal slug.
7536 $file_type = Vigilante_File_Integrity::finding_guidance( $file_type )['label'];
7537 }
7538 ?>
7539 <tr>
7540 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
7541 <td><code style="color: #d63638;"><?php echo esc_html( $file_path ); ?></code></td>
7542 <td><?php echo esc_html( $file_reason ); ?></td>
7543 <td><?php echo esc_html( $file_type ); ?></td>
7544 <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>
7545 </tr>
7546 <?php
7547 }
7548 ?>
7549 </tbody>
7550 </table>
7551 </div>
7552 <?php endif; ?>
7553
7554 <?php if ( ! empty( $last_results['extra'] ) ) : ?>
7555 <div class="vigilante-file-list vigilante-extra-files vigilante-paginated-section" data-bulk-mode="ignore">
7556 <h3 style="color: #b32d2e;"><?php esc_html_e( 'Extra Files', 'vigilante' ); ?></h3>
7557 <p class="description"><?php esc_html_e( 'Files that are not part of WordPress, or of the plugin or theme they sit in. Many are legitimate, and an injected file looks the same from here, so confirm where each one comes from.', 'vigilante' ); ?></p>
7558 <?php $this->render_fi_guidance( $last_results['extra'] ); ?>
7559 <div class="vigilante-fi-bulk-bar">
7560 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
7561 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
7562 </div>
7563 <div class="vigilante-fi-pagination-wrap"></div>
7564 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
7565 <thead>
7566 <tr>
7567 <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>
7568 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
7569 <th style="width: 250px;"><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
7570 <th style="width: 120px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
7571 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
7572 </tr>
7573 </thead>
7574 <tbody>
7575 <?php
7576 foreach ( $last_results['extra'] as $item ) {
7577 $file_path = is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item;
7578 $file_reason = is_array( $item ) ? ( $item['reason'] ?? __( 'Unknown', 'vigilante' ) ) : __( 'Unknown', 'vigilante' );
7579 $file_type = is_array( $item ) ? ( $item['type'] ?? 'unknown' ) : 'unknown';
7580 if ( 'vigilante_self' === $file_type ) {
7581 $file_type = __( 'Vigilant (self)', 'vigilante' );
7582 } else {
7583 // A name a person can read, instead of the internal slug.
7584 $file_type = Vigilante_File_Integrity::finding_guidance( $file_type )['label'];
7585 }
7586 ?>
7587 <tr>
7588 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
7589 <td><code style="color: #b32d2e;"><?php echo esc_html( $file_path ); ?></code></td>
7590 <td><?php echo esc_html( $file_reason ); ?></td>
7591 <td><?php echo esc_html( $file_type ); ?></td>
7592 <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>
7593 </tr>
7594 <?php
7595 }
7596 ?>
7597 </tbody>
7598 </table>
7599 </div>
7600 <?php endif; ?>
7601
7602 <?php
7603 // Split critical config files from regular modified files.
7604 // Computed unconditionally so the three sub-sections that consume
7605 // these arrays (Critical Config, Closed + Removed, Modified Files)
7606 // can render independently and in the order the team picked.
7607 $critical_modified = array();
7608 $regular_modified = array();
7609 if ( $last_results && ! empty( $last_results['modified'] ) ) {
7610 foreach ( $last_results['modified'] as $item ) {
7611 if ( is_array( $item ) && isset( $item['type'] ) && 'critical_config' === $item['type'] ) {
7612 $critical_modified[] = $item;
7613 } else {
7614 $regular_modified[] = $item;
7615 }
7616 }
7617 }
7618 // A missing file of Vigilant is critical, and the missing
7619 // files of the generic scan have no table: it is listed with
7620 // the modified files, or the tab said "All files passed" with
7621 // a module deleted.
7622 if ( $last_results && ! empty( $last_results['missing'] ) && is_array( $last_results['missing'] ) ) {
7623 foreach ( $last_results['missing'] as $item ) {
7624 if ( is_array( $item ) && 'vigilante_self' === ( $item['type'] ?? '' ) ) {
7625 $regular_modified[] = $item;
7626 }
7627 }
7628 }
7629 ?>
7630
7631 <?php if ( ! empty( $critical_modified ) ) : ?>
7632 <div class="vigilante-file-list vigilante-critical-config-files">
7633 <h3 style="color: #e36210;"><?php esc_html_e( 'Critical config files modified', 'vigilante' ); ?></h3>
7634 <p class="description">
7635 <?php esc_html_e( 'These files changed since you last approved them. They are a common target for code injection, and they are also rewritten by cache, security and redirection plugins, often on every update. Review the changes and approve them if they belong to something you use: approving records the current content as the reference and does not touch the file. Vigilant\'s own blocks are excluded from this check, and Vigilant never restores these files by itself.', 'vigilante' ); ?>
7636 </p>
7637 <table class="wp-list-table widefat fixed striped">
7638 <thead>
7639 <tr>
7640 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
7641 <th style="width: 200px;"><?php esc_html_e( 'Changes', 'vigilante' ); ?></th>
7642 <th style="width: 220px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
7643 </tr>
7644 </thead>
7645 <tbody>
7646 <?php foreach ( $critical_modified as $crit_item ) :
7647 $crit_file = $crit_item['file'] ?? '';
7648 $crit_baseline_size = $crit_item['baseline_size'] ?? 0;
7649 $crit_current_size = $crit_item['current_size'] ?? 0;
7650 $crit_diff = $crit_item['diff'] ?? array();
7651 $crit_id = sanitize_html_class( $crit_file );
7652 $added_count = is_array( $crit_diff ) ? count( $crit_diff['added'] ?? array() ) : 0;
7653 $removed_count = is_array( $crit_diff ) ? count( $crit_diff['removed'] ?? array() ) : 0;
7654 // The lines of a shared file are for whoever approves it. Results
7655 // stored before 2.11.8 on the main site still carry them, so the
7656 // screen asks too, not only the scan that wrote them.
7657 $diff_network = ( is_array( $crit_diff ) && ! empty( $crit_diff['network'] ) ) || $this->critical_approval_locked();
7658 $diff_rescan = is_array( $crit_diff ) && ! empty( $crit_diff['rescan'] );
7659 $diff_redaction = is_array( $crit_diff ) && ! empty( $crit_diff['redaction'] );
7660 $diff_unavailable = $diff_network || ( is_array( $crit_diff ) && ! empty( $crit_diff['unavailable'] ) );
7661 ?>
7662 <tr>
7663 <td><code style="color: #e36210;"><?php echo esc_html( $crit_file ); ?></code></td>
7664 <td>
7665 <?php if ( ! $diff_unavailable ) : ?>
7666 <span style="color: #007017;">+<?php echo (int) $added_count; ?></span>
7667 <span style="color: #b32d2e;">-<?php echo (int) $removed_count; ?></span>
7668 <?php esc_html_e( 'lines', 'vigilante' ); ?><br>
7669 <?php endif; ?>
7670 <small style="color: #50575e;">
7671 <?php
7672 printf(
7673 /* translators: 1: baseline size, 2: current size */
7674 esc_html__( '%1$s &rarr; %2$s bytes', 'vigilante' ),
7675 esc_html( number_format_i18n( $crit_baseline_size ) ),
7676 esc_html( number_format_i18n( $crit_current_size ) )
7677 );
7678 ?>
7679 </small>
7680 </td>
7681 <td>
7682 <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' ); ?>">
7683 <?php esc_html_e( 'Review changes', 'vigilante' ); ?>
7684 </button>
7685 <?php if ( $this->critical_approval_locked() ) : ?>
7686 <span class="description" style="display:block;margin-top:4px;">
7687 <?php echo esc_html( $this->critical_approval_notice() ); ?>
7688 </span>
7689 <?php else : ?>
7690 <button type="button" class="button button-small button-primary vigilante-approve-critical-file" data-file="<?php echo esc_attr( $crit_file ); ?>">
7691 <?php esc_html_e( 'Approve', 'vigilante' ); ?>
7692 </button>
7693 <?php endif; ?>
7694 </td>
7695 </tr>
7696 <tr id="vigilante-critical-content-<?php echo esc_attr( $crit_id ); ?>" class="vigilante-critical-content-row" style="display:none;">
7697 <td colspan="3" style="padding: 0;">
7698 <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;">
7699 <?php if ( $diff_network ) : ?>
7700 <p style="color: #50575e; font-style: italic; margin: 0;">
7701 <?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' ); ?>
7702 </p>
7703 <?php elseif ( $diff_rescan ) : ?>
7704 <p style="color: #50575e; font-style: italic; margin: 0;">
7705 <?php esc_html_e( 'Run a new scan to see the line changes of this file.', 'vigilante' ); ?>
7706 </p>
7707 <?php elseif ( $diff_redaction ) : ?>
7708 <p style="color: #50575e; font-style: italic; margin: 0;">
7709 <?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' ); ?>
7710 </p>
7711 <?php elseif ( $diff_unavailable ) : ?>
7712 <p style="color: #50575e; font-style: italic; margin: 0;">
7713 <?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' ); ?>
7714 </p>
7715 <?php elseif ( empty( $crit_diff['added'] ) && empty( $crit_diff['removed'] ) ) : ?>
7716 <p style="color: #50575e; font-style: italic; margin: 0;">
7717 <?php esc_html_e( 'No line-level changes detected (may be whitespace or reordering).', 'vigilante' ); ?>
7718 </p>
7719 <?php else : ?>
7720 <?php if ( ! empty( $crit_diff['removed'] ) ) : ?>
7721 <?php foreach ( $crit_diff['removed'] as $rline ) : ?>
7722 <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>
7723 <?php endforeach; ?>
7724 <?php endif; ?>
7725 <?php if ( ! empty( $crit_diff['added'] ) ) : ?>
7726 <?php foreach ( $crit_diff['added'] as $aline ) : ?>
7727 <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>
7728 <?php endforeach; ?>
7729 <?php endif; ?>
7730 <?php endif; ?>
7731 </div>
7732 </td>
7733 </tr>
7734 <?php endforeach; ?>
7735 </tbody>
7736 </table>
7737 </div>
7738 <?php endif; ?>
7739
7740 <?php if ( $has_closed ) : ?>
7741 <div class="vigilante-file-list vigilante-closed-plugins">
7742 <h3 id="vigilante-section-fi-closed-plugins" style="color: #d63638;"><?php esc_html_e( 'Closed + Removed Plugins', 'vigilante' ); ?></h3>
7743 <p class="description" style="color: #d63638;">
7744 <?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' ); ?>
7745 </p>
7746 <table class="wp-list-table widefat striped">
7747 <thead>
7748 <tr>
7749 <th><?php esc_html_e( 'Plugin', 'vigilante' ); ?></th>
7750 <th style="width: 70px;"><?php esc_html_e( 'Version', 'vigilante' ); ?></th>
7751 <th style="width: 90px;"><?php esc_html_e( 'State', 'vigilante' ); ?></th>
7752 <th style="width: 110px;"><?php esc_html_e( 'Closed date', 'vigilante' ); ?></th>
7753 <th><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
7754 <th style="width: 130px;"><?php esc_html_e( 'Detected', 'vigilante' ); ?></th>
7755 <th style="width: 90px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
7756 </tr>
7757 </thead>
7758 <tbody>
7759 <?php foreach ( $closed_plugins as $cp_slug => $cp_entry ) :
7760 $cp_state = $cp_entry['state'] ?? '';
7761 $cp_state_label = 'closed' === $cp_state ? __( 'Closed', 'vigilante' ) : __( 'Removed', 'vigilante' );
7762 $cp_state_color = 'closed' === $cp_state ? '#d63638' : '#b32d2e';
7763 $cp_reason = '';
7764 if ( ! empty( $cp_entry['closed_reason_text'] ) ) {
7765 $cp_reason = $cp_entry['closed_reason_text'];
7766 } elseif ( 'removed' === $cp_state ) {
7767 $cp_reason = __( 'Removed from repository (metadata hidden, typical of Security Issue closures)', 'vigilante' );
7768 }
7769 $cp_detected = isset( $cp_entry['first_detected'] ) ? (int) $cp_entry['first_detected'] : 0;
7770 ?>
7771 <tr>
7772 <td>
7773 <strong><?php echo esc_html( $cp_entry['name'] ?? $cp_slug ); ?></strong><br>
7774 <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>
7775 </td>
7776 <td><?php echo esc_html( $cp_entry['version'] ?? '' ); ?></td>
7777 <td><span style="color: <?php echo esc_attr( $cp_state_color ); ?>; font-weight: 600;"><?php echo esc_html( $cp_state_label ); ?></span></td>
7778 <td><?php echo esc_html( $cp_entry['closed_date'] ?? '' ); ?></td>
7779 <td><?php echo esc_html( $cp_reason ); ?></td>
7780 <td>
7781 <?php echo $cp_detected > 0 ? esc_html( wp_date( $datetime_format, $cp_detected ) ) : '&mdash;'; ?>
7782 </td>
7783 <td>
7784 <button type="button" class="button button-small vigilante-ignore-closed-plugin" data-slug="<?php echo esc_attr( $cp_slug ); ?>">
7785 <?php esc_html_e( 'Ignore', 'vigilante' ); ?>
7786 </button>
7787 </td>
7788 </tr>
7789 <?php endforeach; ?>
7790 </tbody>
7791 </table>
7792 </div>
7793 <?php endif; ?>
7794
7795 <?php if ( ! empty( $regular_modified ) ) : ?>
7796 <div class="vigilante-file-list vigilante-paginated-section" data-bulk-mode="ignore">
7797 <h3><?php esc_html_e( 'Modified Files', 'vigilante' ); ?></h3>
7798 <p class="description"><?php esc_html_e( 'These files do not match the copy WordPress.org publishes for the installed version.', 'vigilante' ); ?></p>
7799 <?php $this->render_fi_guidance( $regular_modified ); ?>
7800 <div class="vigilante-fi-bulk-bar">
7801 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
7802 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
7803 </div>
7804 <div class="vigilante-fi-pagination-wrap"></div>
7805 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
7806 <thead>
7807 <tr>
7808 <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>
7809 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
7810 <th style="width: 100px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
7811 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
7812 </tr>
7813 </thead>
7814 <tbody>
7815 <?php
7816 foreach ( $regular_modified as $item ) {
7817 $file_path = '';
7818 $file_type = 'unknown';
7819
7820 if ( is_array( $item ) ) {
7821 if ( isset( $item['file'] ) ) {
7822 $file_path = $item['file'];
7823 }
7824 if ( isset( $item['type'] ) ) {
7825 $file_type = $item['type'];
7826 }
7827 } else {
7828 $file_path = (string) $item;
7829 }
7830 if ( 'vigilante_self' === $file_type ) {
7831 $file_type = __( 'Vigilant (self)', 'vigilante' );
7832 } else {
7833 // A name a person can read, instead of the internal slug.
7834 $file_type = Vigilante_File_Integrity::finding_guidance( $file_type )['label'];
7835 }
7836 ?>
7837 <tr>
7838 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
7839 <td><code><?php echo esc_html( $file_path ); ?></code></td>
7840 <td><?php echo esc_html( $file_type ); ?></td>
7841 <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>
7842 </tr>
7843 <?php
7844 }
7845 ?>
7846 </tbody>
7847 </table>
7848 </div>
7849 <?php endif; ?>
7850
7851 <?php
7852 // "All files passed" is about every file, and Vigilant's own
7853 // are files too: with the self-protection box in red or amber
7854 // above, this line contradicted it (its findings no longer
7855 // travel in the tables below).
7856 $vg_self_alarm = in_array( $this->self_integrity_summary( $options )['tone'], array( 'critical', 'off', 'warning' ), true );
7857 ?>
7858 <?php if ( $last_results && ! $vg_self_alarm && empty( $critical_modified ) && empty( $regular_modified ) && empty( $last_results['suspicious'] ) && empty( $last_results['extra'] ) && ! $has_closed && ! $vg_scan_partial && empty( $vg_missing_core ) ) : ?>
7859 <p class="vigilante-all-clear" style="color: #00a32a; font-weight: bold;">
7860 <?php esc_html_e( 'Good job! Nothing to report in the files that were checked.', 'vigilante' ); ?>
7861 </p>
7862 <?php endif; ?>
7863 <?php endif; ?>
7864 </div>
7865 </div>
7866 <?php endif; ?>
7867
7868 <?php if ( ! empty( $ignored_closed_plugins ) ) : ?>
7869 <div id="vigilante-section-fi-ignored-closed" class="vigilante-settings-section">
7870 <h2><?php esc_html_e( 'Ignored Closed + Removed Plugins', 'vigilante' ); ?></h2>
7871 <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>
7872 <table class="wp-list-table widefat fixed striped">
7873 <thead>
7874 <tr>
7875 <th><?php esc_html_e( 'Plugin', 'vigilante' ); ?></th>
7876 <th style="width: 110px;"><?php esc_html_e( 'State', 'vigilante' ); ?></th>
7877 <th style="width: 120px;"><?php esc_html_e( 'Closed date', 'vigilante' ); ?></th>
7878 <th style="width: 130px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
7879 </tr>
7880 </thead>
7881 <tbody>
7882 <?php foreach ( $ignored_closed_plugins as $icp_slug => $icp_entry ) :
7883 $icp_state = $icp_entry['state'] ?? '';
7884 $icp_state_label = 'closed' === $icp_state ? __( 'Closed', 'vigilante' ) : __( 'Removed', 'vigilante' );
7885 ?>
7886 <tr>
7887 <td>
7888 <strong><?php echo esc_html( $icp_entry['name'] ?? $icp_slug ); ?></strong><br>
7889 <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>
7890 </td>
7891 <td><?php echo esc_html( $icp_state_label ); ?></td>
7892 <td><?php echo esc_html( $icp_entry['closed_date'] ?? '' ); ?></td>
7893 <td>
7894 <button type="button" class="button button-small vigilante-unignore-closed-plugin" data-slug="<?php echo esc_attr( $icp_slug ); ?>">
7895 <?php esc_html_e( 'Stop ignoring', 'vigilante' ); ?>
7896 </button>
7897 </td>
7898 </tr>
7899 <?php endforeach; ?>
7900 </tbody>
7901 </table>
7902 <p style="margin-top: 10px;">
7903 <button type="button" class="button vigilante-clear-ignored-closed-plugins"><?php esc_html_e( 'Clear All Ignored Closed + Removed Plugins', 'vigilante' ); ?></button>
7904 </p>
7905 </div>
7906 <?php endif; ?>
7907
7908 <?php if ( ! empty( $ignored_files ) ) : ?>
7909 <div id="vigilante-section-fi-ignored" class="vigilante-settings-section">
7910 <h2><?php esc_html_e( 'Ignored Files', 'vigilante' ); ?></h2>
7911 <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. To leave a whole folder out, add it to Excluded Paths instead.', 'vigilante' ); ?></p>
7912 <div class="vigilante-paginated-section" data-bulk-mode="unignore">
7913 <div class="vigilante-fi-bulk-bar">
7914 <button type="button" class="button vigilante-bulk-unignore" disabled><?php esc_html_e( 'Stop ignoring selected', 'vigilante' ); ?></button>
7915 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
7916 </div>
7917 <div class="vigilante-fi-pagination-wrap"></div>
7918 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
7919 <thead>
7920 <tr>
7921 <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>
7922 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
7923 <th style="width: 120px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
7924 </tr>
7925 </thead>
7926 <tbody>
7927 <?php foreach ( $ignored_files as $file ) : ?>
7928 <tr>
7929 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file ); ?>"></th>
7930 <td><code><?php echo esc_html( $file ); ?></code></td>
7931 <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>
7932 </tr>
7933 <?php endforeach; ?>
7934 </tbody>
7935 </table>
7936 </div>
7937 <p style="margin-top: 10px;">
7938 <button type="button" class="button vigilante-clear-ignored"><?php esc_html_e( 'Clear All Ignored Files', 'vigilante' ); ?></button>
7939 </p>
7940 </div>
7941 <?php endif; ?>
7942 <?php
7943 }
7944
7945 /**
7946 * Render sidebar with promotional widgets
7947 */
7948 private function render_sidebar() {
7949 $promo_banner = new Vigilante_Promo_Banner( 'vigilante' );
7950 $promo_banner->render();
7951 }
7952
7953 /**
7954 * AJAX: Download a ZIP backup of the critical config files.
7955 *
7956 * Streams wp-config.php and .htaccess (and robots.txt if present) as a
7957 * downloadable archive. Config backups are no longer left as files under the
7958 * web root, so this hands the admin the archive directly.
7959 */
7960 public function ajax_download_files_backup() {
7961 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7962
7963 if ( ! current_user_can( 'manage_options' ) ) {
7964 wp_die( esc_html__( 'Permission denied.', 'vigilante' ), 403 );
7965 }
7966
7967 // The archive carries wp-config.php, which a whole network shares. On a
7968 // network manage_options is held by every subsite administrator, so the
7969 // same gate the writers use applies here.
7970 if ( ! Vigilante_Settings::can_write_shared_files() ) {
7971 wp_die( esc_html( Vigilante_Settings::get_shared_files_notice() ), 403 );
7972 }
7973
7974 $backup_manager = new Vigilante_Backup_Manager();
7975 $result = $backup_manager->stream_files_zip();
7976
7977 // stream_files_zip() exits on success; only a WP_Error returns here.
7978 if ( is_wp_error( $result ) ) {
7979 wp_die( esc_html( $result->get_error_message() ), 500 );
7980 }
7981 }
7982
7983 /**
7984 * AJAX: Save settings
7985 */
7986 public function ajax_save_settings() {
7987 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7988
7989 if ( ! current_user_can( 'manage_options' ) ) {
7990 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7991 }
7992
7993 $section = isset( $_POST['section'] ) ? sanitize_key( $_POST['section'] ) : '';
7994
7995 // Handle $_POST['data'] based on type
7996 if ( isset( $_POST['data'] ) && is_array( $_POST['data'] ) ) {
7997 $data = map_deep( wp_unslash( $_POST['data'] ), 'sanitize_text_field' );
7998 } elseif ( isset( $_POST['data'] ) ) {
7999 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
8000 $raw_data = wp_unslash( $_POST['data'] );
8001 parse_str( $raw_data, $data );
8002 $data = $this->sanitize_posted_settings( $data );
8003 } else {
8004 $data = array();
8005 }
8006
8007 if ( empty( $section ) ) {
8008 wp_send_json_error( __( 'Invalid section.', 'vigilante' ) );
8009 }
8010
8011 // Check if 2FA is being enabled or method changed (for notification sending)
8012 $send_2fa_notification = false;
8013 $send_login_url_notification = false;
8014
8015 if ( 'login_security' === $section ) {
8016 // Read old state from DB
8017 $db_options = get_option( Vigilante_Settings::OPTION_NAME, array() );
8018 $old_2fa_enabled = ! empty( $db_options['login_security']['two_factor']['enabled'] );
8019 $old_method = $db_options['login_security']['two_factor']['method'] ?? 'email';
8020
8021 // Check new state from submitted data
8022 $new_2fa_enabled = false;
8023 $notify_on_enable = false;
8024 $new_method = isset( $data['login_security']['two_factor']['method'] )
8025 ? sanitize_key( $data['login_security']['two_factor']['method'] )
8026 : 'email';
8027
8028 if ( isset( $data['login_security']['two_factor']['enabled'] ) ) {
8029 $new_2fa_enabled = filter_var( $data['login_security']['two_factor']['enabled'], FILTER_VALIDATE_BOOLEAN );
8030 }
8031 if ( isset( $data['login_security']['two_factor']['notify_on_enable'] ) ) {
8032 $notify_on_enable = filter_var( $data['login_security']['two_factor']['notify_on_enable'], FILTER_VALIDATE_BOOLEAN );
8033 }
8034
8035 // Send notification if:
8036 // 1. 2FA is being enabled (was off, now on) OR
8037 // 2. Method changed while 2FA is enabled
8038 if ( $notify_on_enable && $new_2fa_enabled ) {
8039 if ( ! $old_2fa_enabled || ( $old_2fa_enabled && $old_method !== $new_method ) ) {
8040 $send_2fa_notification = true;
8041 }
8042 }
8043
8044 // Check if login URL changed and notification is enabled
8045 $old_login_url = $db_options['login_security']['custom_login_url'] ?? '';
8046 $new_login_url = isset( $data['login_security']['custom_login_url'] )
8047 ? sanitize_title( $data['login_security']['custom_login_url'] )
8048 : '';
8049 $notify_on_url_change = isset( $data['login_security']['notify_on_login_url_change'] )
8050 ? filter_var( $data['login_security']['notify_on_login_url_change'], FILTER_VALIDATE_BOOLEAN )
8051 : false;
8052
8053 if ( $notify_on_url_change && ! empty( $new_login_url ) && $new_login_url !== $old_login_url ) {
8054 $send_login_url_notification = true;
8055 }
8056 }
8057
8058 // Get defaults
8059 $defaults = $this->settings->get_default_options();
8060
8061 // Read ONLY saved options from database (not merged with defaults)
8062 $saved_options = get_option( Vigilante_Settings::OPTION_NAME, array() );
8063
8064 // What is stored before this request changes anything: the shared file
8065 // settings this user may not change are put back from here (2.11.6).
8066 $stored_options = $saved_options;
8067 $locked = Vigilante_Settings::get_locked_file_settings();
8068
8069 if ( isset( $locked[ $section ] ) && true === $locked[ $section ] ) {
8070 wp_send_json_error( Vigilante_Settings::get_shared_files_notice() );
8071 }
8072
8073 // A module switch is a single key, so refusing says more than a success
8074 // that changed nothing, and the dashboard puts the toggle back.
8075 if ( 'modules' === $section && isset( $locked['modules'], $data['modules'] ) && is_array( $locked['modules'] ) && is_array( $data['modules'] ) ) {
8076 foreach ( array_keys( $data['modules'] ) as $vg_module ) {
8077 if ( in_array( sanitize_key( $vg_module ), $locked['modules'], true ) ) {
8078 wp_send_json_error( Vigilante_Settings::get_shared_files_notice() );
8079 }
8080 }
8081 }
8082
8083 $rejected_ips = array();
8084 $rejected_proxies = array();
8085
8086 // Handle modules
8087 if ( 'modules' === $section && isset( $data['modules'] ) ) {
8088 if ( ! isset( $saved_options['modules'] ) ) {
8089 $saved_options['modules'] = array();
8090 }
8091 foreach ( $data['modules'] as $module => $enabled ) {
8092 $module = sanitize_key( $module );
8093 $saved_options['modules'][ $module ] = in_array( $enabled, array( '1', 1, 'true', true ), true );
8094 }
8095 // Clear active preset when modules change
8096 update_option( 'vigilante_active_preset', '' );
8097 } else {
8098 // Process primary section
8099 if ( isset( $data[ $section ] ) && is_array( $data[ $section ] ) ) {
8100 $section_defaults = isset( $defaults[ $section ] ) ? $defaults[ $section ] : array();
8101 $current_section = isset( $saved_options[ $section ] ) ? $saved_options[ $section ] : array();
8102
8103 // Process the submitted data
8104 $processed = $this->process_section_data( $data[ $section ], $section_defaults, $current_section );
8105
8106 // The IP boxes are free text and, until 2.9.9, whatever was typed
8107 // went straight into the option. An entry the matcher can never
8108 // match still sits in a security list looking like protection,
8109 // so the ones that cannot match are dropped and reported back
8110 // instead of being stored in silence.
8111 $rejected_ips = $this->filter_ip_lists( $section, $processed, $rejected_proxies );
8112
8113 // Save the processed section
8114 $saved_options[ $section ] = $processed;
8115
8116 // Clear active preset when any section settings change
8117 update_option( 'vigilante_active_preset', '' );
8118 }
8119 }
8120
8121 // Clear cache before saving
8122 wp_cache_delete( Vigilante_Settings::OPTION_NAME, 'options' );
8123
8124 $saved_options = Vigilante_Settings::keep_locked_file_settings( $saved_options, $stored_options );
8125
8126 // Save to database
8127 update_option( Vigilante_Settings::OPTION_NAME, $saved_options );
8128
8129 // Clear the settings cache
8130 $this->settings->clear_cache();
8131
8132 // Apply changes based on section
8133 $this->apply_section_changes( $section, $saved_options );
8134
8135 // Send 2FA notifications after settings are saved
8136 $notification_result = null;
8137 if ( $send_2fa_notification ) {
8138 $notification_result = $this->send_2fa_enable_notifications();
8139 }
8140
8141 // Send login URL notifications after settings are saved
8142 $login_url_result = null;
8143 if ( $send_login_url_notification ) {
8144 $login_url_result = $this->send_login_url_notifications();
8145 }
8146
8147 // Build success message
8148 $message = __( 'Settings saved successfully.', 'vigilante' );
8149
8150 if ( $notification_result && $notification_result['sent'] > 0 ) {
8151 $message .= ' ' . sprintf(
8152 /* translators: %d: Number of emails sent */
8153 _n(
8154 '2FA notification sent to %d user.',
8155 '2FA notifications sent to %d users.',
8156 $notification_result['sent'],
8157 'vigilante'
8158 ),
8159 $notification_result['sent']
8160 );
8161 }
8162
8163 if ( $login_url_result && $login_url_result['sent'] > 0 ) {
8164 $message .= ' ' . sprintf(
8165 /* translators: %d: Number of emails sent */
8166 _n(
8167 'Login URL notification sent to %d user.',
8168 'Login URL notifications sent to %d users.',
8169 $login_url_result['sent'],
8170 'vigilante'
8171 ),
8172 $login_url_result['sent']
8173 );
8174 }
8175
8176 if ( ! empty( $rejected_ips ) ) {
8177 $message .= ' ' . sprintf(
8178 /* translators: %s: comma separated list of the entries that were not saved. */
8179 _n(
8180 'This entry is not a valid IP, CIDR range or wildcard, so it was not saved: %s',
8181 'These entries are not valid IPs, CIDR ranges or wildcards, so they were not saved: %s',
8182 count( $rejected_ips ),
8183 'vigilante'
8184 ),
8185 implode( ', ', array_map( 'esc_html', $rejected_ips ) )
8186 );
8187 }
8188
8189 if ( ! empty( $rejected_proxies ) ) {
8190 $message .= ' ' . sprintf(
8191 /* translators: %s: comma separated list of the trusted proxy entries that were not saved. */
8192 _n(
8193 'A trusted proxy must be an exact IP or a CIDR range, not a wildcard, so this entry was not saved: %s',
8194 'A trusted proxy must be an exact IP or a CIDR range, not a wildcard, so these entries were not saved: %s',
8195 count( $rejected_proxies ),
8196 'vigilante'
8197 ),
8198 implode( ', ', array_map( 'esc_html', $rejected_proxies ) )
8199 );
8200 }
8201
8202 wp_send_json_success( $message );
8203 }
8204
8205 /**
8206 * Keep only the IP patterns the matcher can actually match
8207 *
8208 * @since 2.9.9
8209 *
8210 * @param string $section Section being saved.
8211 * @param array $processed Section data, edited in place.
8212 * @return array Entries that were dropped, for the message back to the user.
8213 */
8214 private function filter_ip_lists( $section, &$processed, &$rejected_proxies = array() ) {
8215 $rejected_proxies = array();
8216
8217 // Trusted proxies feed an identity decision, so only exact addresses and
8218 // CIDR ranges belong there: a wildcard is stripped with its own message,
8219 // never stored looking effective. The matcher ignores it anyway (see
8220 // Vigilante_IP_Utils::in_list_ip_or_cidr), this stops it persisting.
8221 if ( 'firewall' === $section && isset( $processed['trusted_proxies'] ) && is_array( $processed['trusted_proxies'] ) ) {
8222 $split = Vigilante_IP_Utils::split_list_ip_or_cidr( $processed['trusted_proxies'] );
8223 $processed['trusted_proxies'] = $split['valid'];
8224 $rejected_proxies = $split['rejected'];
8225 }
8226
8227 $lists = array(
8228 'firewall' => array( 'ip_whitelist', 'ip_blacklist' ),
8229 'login_security' => array( 'ip_whitelist' ),
8230 );
8231
8232 if ( ! isset( $lists[ $section ] ) ) {
8233 return array();
8234 }
8235
8236 $rejected = array();
8237
8238 foreach ( $lists[ $section ] as $key ) {
8239 if ( ! isset( $processed[ $key ] ) || ! is_array( $processed[ $key ] ) ) {
8240 continue;
8241 }
8242
8243 $split = Vigilante_IP_Utils::split_list( $processed[ $key ] );
8244 $processed[ $key ] = $split['valid'];
8245 $rejected = array_merge( $rejected, $split['rejected'] );
8246 }
8247
8248 return array_values( array_unique( $rejected ) );
8249 }
8250
8251 /**
8252 * Send 2FA enable notifications to users
8253 *
8254 * @return array Result with 'sent' and 'failed' counts.
8255 */
8256 private function send_2fa_enable_notifications() {
8257 $result = array(
8258 'sent' => 0,
8259 'failed' => 0,
8260 );
8261
8262 // Get settings for roles and method
8263 $login_security = $this->settings->get_section( 'login_security' );
8264 $two_factor = isset( $login_security['two_factor'] ) ? $login_security['two_factor'] : array();
8265 $roles = isset( $two_factor['enforced_roles'] ) ? $two_factor['enforced_roles'] : array( 'administrator' );
8266 $method = isset( $two_factor['method'] ) ? $two_factor['method'] : 'email';
8267
8268 if ( empty( $roles ) ) {
8269 $roles = array( 'administrator' );
8270 }
8271
8272 $excluded = isset( $two_factor['excluded_users'] ) ? array_map( 'absint', $two_factor['excluded_users'] ) : array();
8273
8274 // Get users with these roles
8275 $args = array(
8276 'role__in' => $roles,
8277 );
8278 if ( ! empty( $excluded ) ) {
8279 // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- Small excluded users list from settings.
8280 $args['exclude'] = $excluded;
8281 }
8282 $users = get_users( $args );
8283
8284 if ( empty( $users ) ) {
8285 return $result;
8286 }
8287
8288 $site_name = get_bloginfo( 'name' );
8289 $from_name = ! empty( $two_factor['email_from_name'] ) ? $two_factor['email_from_name'] : $site_name;
8290
8291 if ( 'totp' === $method ) {
8292 // Use TOTP class for styled HTML emails
8293 if ( ! class_exists( 'Vigilante_Two_Factor_TOTP' ) ) {
8294 require_once VIGILANTE_INCLUDES_DIR . 'class-two-factor-totp.php';
8295 }
8296 $totp = new Vigilante_Two_Factor_TOTP( $this->settings, $this->database, $this->activity_log );
8297
8298 foreach ( $users as $user ) {
8299 // Skip users who already have TOTP configured
8300 $totp_data = $this->database->get_totp_data( $user->ID );
8301 if ( $totp_data && ! empty( $totp_data['is_configured'] ) ) {
8302 continue;
8303 }
8304
8305 $sent = $totp->send_activation_email( $user, $site_name, $from_name );
8306
8307 if ( $sent ) {
8308 $this->database->mark_2fa_notified( $user->ID );
8309 $result['sent']++;
8310 } else {
8311 $result['failed']++;
8312 }
8313 }
8314 } else {
8315 // Email method - use existing email 2FA class
8316 if ( ! class_exists( 'Vigilante_Two_Factor_Email' ) ) {
8317 require_once VIGILANTE_INCLUDES_DIR . 'class-two-factor-email.php';
8318 }
8319 $email_2fa = new Vigilante_Two_Factor_Email( $this->settings, $this->database, $this->activity_log );
8320 return $email_2fa->send_activation_notifications( false );
8321 }
8322
8323 return $result;
8324 }
8325
8326 /**
8327 * Send login URL change notifications to users with admin access
8328 *
8329 * @return array Result with 'sent' and 'failed' counts.
8330 */
8331 private function send_login_url_notifications() {
8332 $login_options = $this->settings->get_section( 'login_security' );
8333 $custom_url = ! empty( $login_options['custom_login_url'] ) ? sanitize_title( $login_options['custom_login_url'] ) : '';
8334
8335 if ( empty( $custom_url ) ) {
8336 return array( 'sent' => 0, 'failed' => 0 );
8337 }
8338
8339 $login_url = home_url( $custom_url . '/' );
8340 $site_name = get_bloginfo( 'name' );
8341
8342 $admin_roles = array( 'administrator', 'editor', 'author', 'contributor' );
8343 $users = get_users( array( 'role__in' => $admin_roles ) );
8344
8345 if ( empty( $users ) ) {
8346 return array( 'sent' => 0, 'failed' => 0 );
8347 }
8348
8349 $subject = sprintf(
8350 /* translators: %s: Site name */
8351 __( '[%s] Your login URL has changed', 'vigilante' ),
8352 $site_name
8353 );
8354
8355 $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' ) );
8356 $body .= Vigilante_Email_Template::url_box( $login_url, __( 'Your new login URL:', 'vigilante' ) );
8357 $body .= Vigilante_Email_Template::alert_box( __( 'The old login address (wp-login.php) will no longer work.', 'vigilante' ) );
8358 $body .= Vigilante_Email_Template::button( $login_url, __( 'Go to login', 'vigilante' ) );
8359
8360 $sent = 0;
8361 $failed = 0;
8362
8363 foreach ( $users as $user ) {
8364 $result = Vigilante_Email_Template::send(
8365 $user->user_email,
8366 $subject,
8367 __( 'Login URL changed', 'vigilante' ),
8368 $body
8369 );
8370 if ( $result ) {
8371 $sent++;
8372 } else {
8373 $failed++;
8374 }
8375 }
8376
8377 if ( $this->activity_log ) {
8378 $this->activity_log->log(
8379 'login',
8380 'login_url_notified',
8381 sprintf(
8382 /* translators: 1: Sent count, 2: Failed count */
8383 __( 'Login URL notification sent on save: %1$d sent, %2$d failed', 'vigilante' ),
8384 $sent,
8385 $failed
8386 )
8387 );
8388 }
8389
8390 return array( 'sent' => $sent, 'failed' => $failed );
8391 }
8392
8393 /**
8394 * Sanitize the settings a tab posted, once the serialized form is parsed
8395 *
8396 * Every value goes through sanitize_textarea_field() except the lists of
8397 * file paths (Vigilante_Settings::path_list_keys()). That one deletes every
8398 * %XX octet and, when it finds one, collapses repeated spaces, so an
8399 * exclusion for a folder called foto%20x was saved as fotox and excluded
8400 * nothing (measured on 1 oct 2026 against 3.0.1). The paths are read as
8401 * paths before the generic sanitizer runs and put back after it.
8402 *
8403 * @since 3.0.2
8404 *
8405 * @param array $data Parsed form: section => key => value.
8406 * @return array
8407 */
8408 private function sanitize_posted_settings( $data ) {
8409 $paths = Vigilante_Settings::take_path_lists( $data );
8410 $data = map_deep( $data, 'sanitize_textarea_field' );
8411
8412 return Vigilante_Settings::restore_path_lists( $data, $paths );
8413 }
8414
8415 /**
8416 * Sanitize an imported settings file, once it is decoded
8417 *
8418 * Same rule as sanitize_posted_settings(): the lists of paths keep what the
8419 * export wrote, so an exclusion survives an export and an import.
8420 *
8421 * @since 3.0.2
8422 *
8423 * @param array $imported Decoded export.
8424 * @return array
8425 */
8426 private function sanitize_imported_settings( $imported ) {
8427 $paths = Vigilante_Settings::take_path_lists( $imported );
8428 $imported = map_deep( $imported, 'sanitize_text_field' );
8429
8430 return Vigilante_Settings::restore_path_lists( $imported, $paths );
8431 }
8432
8433 /**
8434 * Process section data maintaining proper types from defaults
8435 *
8436 * @param array $submitted_data Data submitted from form.
8437 * @param array $defaults Default values for this section.
8438 * @param array $current Current saved values.
8439 * @param string $section_name Section name for special handling.
8440 * @return array Processed data.
8441 */
8442 private function process_section_data( $submitted_data, $defaults, $current, $section_name = '' ) {
8443 // Start with defaults, then merge current saved values. Lists are put
8444 // back whole afterwards: array_replace_recursive() merges them index by
8445 // index, so a saved list shorter than the default kept the default's
8446 // tail (see below, and Vigilante_Settings::array_merge_deep()).
8447 $result = array_replace_recursive( $defaults, $current );
8448 $result = $this->restore_lists( $result, $current );
8449
8450 // Process each submitted value
8451 foreach ( $submitted_data as $key => $value ) {
8452 $key = sanitize_key( $key );
8453
8454 if ( is_array( $value ) && $this->is_list_field( $key, $value, $defaults, $current ) ) {
8455 /*
8456 * A list of values, not a group of settings: the roles of a
8457 * checkbox group, the excluded user ids. What the form sent IS
8458 * the list, so it replaces the stored one outright.
8459 *
8460 * Until 3.0.1 this went through the recursion below, which
8461 * writes position by position and left every stored entry the
8462 * new list was too short to overwrite. Unchecking Editor in
8463 * "Enforce for roles" saved administrator over position 0 and
8464 * kept editor in position 1, so the box came back ticked
8465 * (reported on the support forum for 3.0.0, and the same bug
8466 * merge_preset() was fixed for in 2.9.8).
8467 *
8468 * Keys are dropped on purpose: a list is data, so anything the
8469 * request tried to name is not carried over. The empty string
8470 * is dropped too, which is what the hidden field that marks an
8471 * empty group sends.
8472 */
8473 $list = array();
8474 foreach ( $value as $entry ) {
8475 if ( ! is_scalar( $entry ) ) {
8476 continue;
8477 }
8478 $entry = sanitize_text_field( (string) $entry );
8479 if ( '' === $entry ) {
8480 continue;
8481 }
8482 $list[] = $entry;
8483 }
8484 $result[ $key ] = $list;
8485 } elseif ( is_array( $value ) ) {
8486 // Nested array (like rate_limiting)
8487 $nested_defaults = isset( $defaults[ $key ] ) && is_array( $defaults[ $key ] ) ? $defaults[ $key ] : array();
8488 $nested_current = isset( $result[ $key ] ) && is_array( $result[ $key ] ) ? $result[ $key ] : array();
8489 $result[ $key ] = $this->process_section_data( $value, $nested_defaults, $nested_current, $key );
8490 } else {
8491 // Determine type from default value
8492 $default_value = isset( $defaults[ $key ] ) ? $defaults[ $key ] : null;
8493
8494 if ( null === $default_value ) {
8495 // No default, check current value type or use as string
8496 $current_value = isset( $current[ $key ] ) ? $current[ $key ] : null;
8497 if ( is_bool( $current_value ) ) {
8498 $result[ $key ] = in_array( $value, array( '1', 1, 'true', true ), true );
8499 } elseif ( is_int( $current_value ) ) {
8500 $result[ $key ] = intval( $value );
8501 } elseif ( is_array( $current_value ) ) {
8502 $result[ $key ] = is_string( $value ) ? array_filter( array_map( 'trim', explode( "\n", $value ) ) ) : (array) $value;
8503 } else {
8504 $result[ $key ] = sanitize_text_field( $value );
8505 }
8506 } elseif ( is_bool( $default_value ) ) {
8507 // Boolean: '1', 1, 'true' become true; '0', 0, '', 'false' become false
8508 $result[ $key ] = in_array( $value, array( '1', 1, 'true', true ), true );
8509 } elseif ( is_int( $default_value ) ) {
8510 // Integer - with special handling for time fields shown in minutes
8511 $int_value = intval( $value );
8512
8513 // Convert minutes to seconds for login_security duration fields
8514 // These are displayed as minutes in the form but stored as seconds
8515 if ( in_array( $key, array( 'lockout_duration', 'max_lockout_duration' ), true ) ) {
8516 $int_value = $int_value * 60;
8517 }
8518
8519 $result[ $key ] = $int_value;
8520 } elseif ( is_array( $default_value ) ) {
8521 // Array from textarea (e.g., IP lists)
8522 if ( is_string( $value ) ) {
8523 $result[ $key ] = array_filter( array_map( 'trim', explode( "\n", $value ) ) );
8524 } else {
8525 $result[ $key ] = (array) $value;
8526 }
8527 } else {
8528 // String - preserve newlines for textarea fields
8529 if ( is_string( $value ) && ( strpos( $value, "\n" ) !== false || strpos( $value, "\r" ) !== false ) ) {
8530 $result[ $key ] = sanitize_textarea_field( $value );
8531 } else {
8532 $result[ $key ] = sanitize_text_field( $value );
8533 }
8534 }
8535 }
8536 }
8537
8538 // Handle unchecked checkboxes: HTML forms don't submit unchecked boxes
8539 // If a boolean field exists in defaults but NOT in submitted_data, set it to false
8540 //
8541 // EXCEPTION: the top-level 'enabled' flag of every section is the
8542 // module's master switch and is controlled by the Dashboard module
8543 // toggle, NOT by a checkbox inside the section's form. Treating it
8544 // like a regular checkbox here would silently switch the module off
8545 // every time the user saves the tab — see the REST API enabled=false
8546 // regression. We only skip it at the top level (when section_name is
8547 // empty); nested 'enabled' fields like security_headers.csp.enabled
8548 // are real checkboxes and must keep the auto-unset behaviour.
8549 $preserve_top_level = array( 'enabled' );
8550
8551 foreach ( $defaults as $key => $default_value ) {
8552 if ( '' === $section_name && in_array( $key, $preserve_top_level, true ) ) {
8553 continue;
8554 }
8555 if ( is_bool( $default_value ) && ! array_key_exists( $key, $submitted_data ) ) {
8556 $result[ $key ] = false;
8557 } elseif ( is_array( $default_value ) && ! isset( $submitted_data[ $key ] ) ) {
8558 // Check if this is a flat value list (like excluded_users, enforced_roles, ip_whitelist)
8559 // vs a nested settings group (like rate_limiting, two_factor)
8560 // Flat lists: default is empty array OR all values are scalar
8561 $is_value_list = empty( $default_value );
8562 if ( ! $is_value_list ) {
8563 $is_value_list = true;
8564 foreach ( $default_value as $dv ) {
8565 if ( ! is_scalar( $dv ) ) {
8566 $is_value_list = false;
8567 break;
8568 }
8569 }
8570 }
8571
8572 if ( $is_value_list ) {
8573 /*
8574 * A list whose key did not travel is left as it was. Until
8575 * 3.0.1 it was blanked here, which read "the user unticked
8576 * everything" into something the form never asked about:
8577 * saving the Firewall tab blanked allowed_http_methods,
8578 * which has no field on any screen, and saving Users blanked
8579 * insecure_usernames. Both survived only because reading the
8580 * option put the defaults back on top, and that is exactly
8581 * the merge being removed in this release: with lists
8582 * replaced whole, blanking here would have left a site
8583 * answering 403 to every HTTP method.
8584 *
8585 * Emptying a group is still possible, and is now said out
8586 * loud: each checkbox group prints a hidden field with an
8587 * empty value, so an empty group arrives as an empty list
8588 * instead of as silence. See list_sentinel().
8589 */
8590 continue;
8591 } else {
8592 // Nested settings group - handle boolean children
8593 foreach ( $default_value as $nested_key => $nested_default ) {
8594 if ( is_bool( $nested_default ) && isset( $result[ $key ] ) && is_array( $result[ $key ] ) ) {
8595 $nested_submitted = isset( $submitted_data[ $key ] ) && is_array( $submitted_data[ $key ] )
8596 ? $submitted_data[ $key ]
8597 : array();
8598 if ( ! array_key_exists( $nested_key, $nested_submitted ) ) {
8599 $result[ $key ][ $nested_key ] = false;
8600 }
8601 }
8602 }
8603 }
8604 }
8605 }
8606
8607 return $result;
8608 }
8609
8610 /**
8611 * Whether a submitted value is a list of values rather than a group of settings
8612 *
8613 * The difference decides whether what arrived replaces the stored value or
8614 * is merged into it key by key, so it is answered from what the setting is
8615 * (its default, or what is stored today), not from the shape of the
8616 * request. A request that sends named keys where a list belongs gets them
8617 * dropped, which is one way this is narrower than what it replaces.
8618 *
8619 * @since 3.0.1
8620 *
8621 * @param string $key Setting key, already through sanitize_key().
8622 * @param array $value Value as submitted.
8623 * @param array $defaults Defaults of the section being processed.
8624 * @param array $current Stored values of the section being processed.
8625 * @return bool
8626 */
8627 private function is_list_field( $key, $value, $defaults, $current ) {
8628 $default_known = array_key_exists( $key, $defaults ) && is_array( $defaults[ $key ] );
8629
8630 // The default has the first and the last word, the same rule that
8631 // array_merge_deep() and restore_lists() follow. Letting the stored
8632 // value decide, as this did until the fourth cross review of 3.0.1,
8633 // disagrees with them where it matters: an option corrupted into
8634 // two_factor = array( 'a', 'b' ) would have been treated as a list and
8635 // saving the tab would have replaced the whole group of settings with
8636 // the two values that arrived.
8637 if ( $default_known && array() !== $defaults[ $key ] ) {
8638 return Vigilante_Settings::is_list( $defaults[ $key ] );
8639 }
8640
8641 // Nothing declares it either way (an empty default, or a key with no
8642 // default at all), so what is stored, and then what was submitted, is
8643 // all there is to go on.
8644 if ( isset( $current[ $key ] ) && is_array( $current[ $key ] ) && array() !== $current[ $key ] && Vigilante_Settings::is_list( $current[ $key ] ) ) {
8645 return true;
8646 }
8647
8648 return Vigilante_Settings::is_list( $value );
8649 }
8650
8651 /**
8652 * Put stored lists back after array_replace_recursive()
8653 *
8654 * array_replace_recursive() merges a list by position, so a stored list
8655 * shorter than the default comes out with the default's tail attached:
8656 * ['administrator'] over ['administrator','editor'] gives both back. Every
8657 * list that is stored is therefore restored whole before anything else is
8658 * processed, and only associative arrays are walked into.
8659 *
8660 * @since 3.0.1
8661 *
8662 * @param array $result Defaults with the stored values merged over them.
8663 * @param array $current Stored values.
8664 * @return array
8665 */
8666 private function restore_lists( $result, $current ) {
8667 if ( ! is_array( $current ) ) {
8668 return $result;
8669 }
8670
8671 foreach ( $current as $key => $value ) {
8672 if ( ! is_array( $value ) || ! isset( $result[ $key ] ) || ! is_array( $result[ $key ] ) ) {
8673 continue;
8674 }
8675
8676 // Decided by what is in $result, which comes from the defaults, and
8677 // never by the stored value: array() is a list by any definition, so
8678 // a section stored empty would have replaced a whole group of
8679 // settings with nothing. Same reasoning as in array_merge_deep().
8680 if ( Vigilante_Settings::is_list( $result[ $key ] ) ) {
8681 $result[ $key ] = $value;
8682 continue;
8683 }
8684
8685 $result[ $key ] = $this->restore_lists( $result[ $key ], $value );
8686 }
8687
8688 return $result;
8689 }
8690
8691 /**
8692 * Print the hidden field that lets a checkbox group arrive empty
8693 *
8694 * A checkbox group sends nothing at all when every box is unticked, which
8695 * is indistinguishable from a form that never had that field. Since 3.0.1
8696 * the save path leaves an absent list alone, so the difference has to be
8697 * stated: this empty entry always travels, and the save path drops empty
8698 * strings, so an untouched group arrives as an empty list.
8699 *
8700 * @since 3.0.1
8701 *
8702 * @param string $name Field name without the trailing [].
8703 */
8704 private function list_sentinel( $name ) {
8705 printf( '<input type="hidden" name="%s[]" value="">', esc_attr( $name ) );
8706 }
8707
8708 /**
8709 * AJAX: Export settings
8710 */
8711 public function ajax_export_settings() {
8712 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8713
8714 if ( ! current_user_can( 'manage_options' ) ) {
8715 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8716 }
8717
8718 $options = $this->settings->get_all_options();
8719 $filename = 'vigilante-settings-' . gmdate( 'Y-m-d-His' ) . '.json';
8720
8721 wp_send_json_success( array(
8722 'content' => wp_json_encode( $options, JSON_PRETTY_PRINT ),
8723 'filename' => $filename,
8724 ) );
8725 }
8726
8727 /**
8728 * AJAX: Import settings
8729 */
8730 public function ajax_import_settings() {
8731 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8732
8733 if ( ! current_user_can( 'manage_options' ) ) {
8734 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8735 }
8736
8737 // Accept both 'settings' (from JS) and 'content' (legacy).
8738 // Do NOT run sanitize_text_field() on the raw payload: it calls
8739 // wp_strip_all_tags() internally, which removes any "<...>" substring
8740 // and turns a valid export JSON into garbage if any stored value
8741 // contains < or > (htaccess snippets, email templates, etc.). The
8742 // real sanitization happens after json_decode(), via map_deep() on
8743 // the parsed array.
8744 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash
8745 $content = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : '';
8746 if ( empty( $content ) ) {
8747 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash
8748 $content = isset( $_POST['content'] ) ? wp_unslash( $_POST['content'] ) : '';
8749 }
8750
8751 if ( empty( $content ) || ! is_string( $content ) ) {
8752 wp_send_json_error( __( 'No content provided.', 'vigilante' ) );
8753 }
8754
8755 $imported = json_decode( $content, true );
8756
8757 if ( json_last_error() !== JSON_ERROR_NONE || ! is_array( $imported ) ) {
8758 wp_send_json_error( __( 'Invalid JSON format.', 'vigilante' ) );
8759 }
8760
8761 // Sanitize imported data recursively
8762 $imported = $this->sanitize_imported_settings( $imported );
8763
8764 // Validate structure: only sections and keys of the schema survive, and
8765 // every value takes the type of its default. Until 2.11.0 this was an
8766 // array_replace_recursive() of the file over the defaults, so any key in
8767 // the file, known or not, landed in vigilante_options (S7). Sections
8768 // the file does not carry keep their defaults; a section it does carry
8769 // replaces the default one whole, because validate_options() has
8770 // already filled in whatever the file left out.
8771 $defaults = $this->settings->get_default_options();
8772 $validated = $this->settings->validate_options( $imported );
8773 $merged = $defaults;
8774
8775 foreach ( $validated as $section => $data ) {
8776 if ( is_array( $data ) ) {
8777 $merged[ $section ] = $data;
8778 }
8779 }
8780
8781 // Save
8782 $merged = Vigilante_Settings::keep_locked_file_settings( $merged, get_option( Vigilante_Settings::OPTION_NAME, array() ) );
8783 update_option( Vigilante_Settings::OPTION_NAME, $merged );
8784 $this->settings->clear_cache();
8785
8786 // Re-evaluate the active preset marker. The imported config may match
8787 // a known preset exactly, partially, or not at all — without this step
8788 // the dashboard would keep showing whatever preset was active before
8789 // the import even if the new config no longer matches it.
8790 $matched_preset = $this->detect_matching_preset( $merged );
8791 if ( null === $matched_preset ) {
8792 delete_option( 'vigilante_active_preset' );
8793 } else {
8794 update_option( 'vigilante_active_preset', $matched_preset );
8795 }
8796
8797 // Apply file changes after import
8798 $this->apply_all_file_changes( $merged );
8799
8800 // Refresh the Security Analyzer score so the dashboard widget reflects
8801 // the imported config rather than the pre-import scan. Reuse the
8802 // post-Under-Attack scan hook (same job: full scan, async).
8803 if ( ! wp_next_scheduled( 'vigilante_under_attack_post_scan' ) ) {
8804 wp_schedule_single_event( time() + 5, 'vigilante_under_attack_post_scan' );
8805 }
8806
8807 wp_send_json_success( __( 'Settings imported successfully.', 'vigilante' ) . $this->locked_file_settings_message() );
8808 }
8809
8810 /**
8811 * Detect whether a vigilante_options array matches a known preset.
8812 *
8813 * A preset matches when every field the preset explicitly declares is
8814 * present in the config with the same (normalised) value. Fields outside
8815 * the preset are ignored — they may have been modified by the user before
8816 * applying the preset and do not invalidate the match. This mirrors how
8817 * apply_preset() now layers presets on top of the user's existing config.
8818 *
8819 * @param array $options The current/imported vigilante_options.
8820 * @return string|null Preset id ('standard', 'maximum') or null if custom.
8821 */
8822 private function detect_matching_preset( $options ) {
8823 if ( ! is_array( $options ) ) {
8824 return null;
8825 }
8826
8827 $presets = $this->settings->get_presets();
8828
8829 foreach ( $presets as $preset_id => $preset_data ) {
8830 unset( $preset_data['name'], $preset_data['description'] );
8831 if ( $this->preset_subset_matches( $preset_data, $options ) ) {
8832 return $preset_id;
8833 }
8834 }
8835
8836 return null;
8837 }
8838
8839 /**
8840 * Check whether every leaf value inside $preset_subset exists with the
8841 * same (normalised) value at the same path inside $config.
8842 *
8843 * @param mixed $preset_subset Branch of the preset definition.
8844 * @param mixed $config Same branch in the live/imported config.
8845 * @return bool
8846 */
8847 private function preset_subset_matches( $preset_subset, $config ) {
8848 if ( is_array( $preset_subset ) ) {
8849 if ( ! is_array( $config ) ) {
8850 return false;
8851 }
8852 foreach ( $preset_subset as $key => $value ) {
8853 if ( ! array_key_exists( $key, $config ) ) {
8854 return false;
8855 }
8856 if ( ! $this->preset_subset_matches( $value, $config[ $key ] ) ) {
8857 return false;
8858 }
8859 }
8860 return true;
8861 }
8862
8863 return $this->normalise_scalar_for_compare( $preset_subset ) === $this->normalise_scalar_for_compare( $config );
8864 }
8865
8866 /**
8867 * Normalise a scalar value so that the variants WordPress and the form
8868 * layer routinely produce ('1' / 1 / true → "1"; '' / '0' / 0 / false /
8869 * null → "") compare equal. Other values become strings unchanged.
8870 *
8871 * @param mixed $value
8872 * @return string
8873 */
8874 private function normalise_scalar_for_compare( $value ) {
8875 if ( is_bool( $value ) ) {
8876 return $value ? '1' : '';
8877 }
8878 if ( null === $value ) {
8879 return '';
8880 }
8881 if ( is_int( $value ) || is_float( $value ) ) {
8882 return (string) $value;
8883 }
8884 if ( is_string( $value ) ) {
8885 if ( 'true' === $value ) {
8886 return '1';
8887 }
8888 if ( 'false' === $value ) {
8889 return '';
8890 }
8891 return $value;
8892 }
8893 // Arrays and objects shouldn't reach here (handled by recursion above),
8894 // but if they do, fall back to a stable comparable representation.
8895 return wp_json_encode( $value );
8896 }
8897
8898 /**
8899 * AJAX: Apply preset
8900 */
8901 public function ajax_apply_preset() {
8902 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8903
8904 if ( ! current_user_can( 'manage_options' ) ) {
8905 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8906 }
8907
8908 $preset = isset( $_POST['preset'] ) ? sanitize_key( $_POST['preset'] ) : '';
8909
8910 // Handle reset to defaults
8911 if ( 'reset' === $preset ) {
8912 $stored_options = get_option( Vigilante_Settings::OPTION_NAME, array() );
8913 $defaults = Vigilante_Settings::get_defaults_preserving_user_data( $stored_options );
8914 $defaults = Vigilante_Settings::keep_locked_file_settings( $defaults, $stored_options );
8915 update_option( Vigilante_Settings::OPTION_NAME, $defaults );
8916 $this->settings->clear_cache();
8917
8918 // Clear active preset
8919 update_option( 'vigilante_active_preset', '' );
8920
8921 // Apply file changes after reset
8922 $this->apply_all_file_changes( $defaults );
8923
8924 wp_send_json_success( __( 'Settings reset to defaults.', 'vigilante' ) . $this->locked_file_settings_message() );
8925 return;
8926 }
8927
8928 $presets = $this->settings->get_presets();
8929
8930 if ( ! isset( $presets[ $preset ] ) ) {
8931 wp_send_json_error( __( 'Invalid preset.', 'vigilante' ) );
8932 }
8933
8934 $preset_options = $presets[ $preset ];
8935 unset( $preset_options['name'], $preset_options['description'] );
8936
8937 // Layer the preset on top of the user's CURRENT configuration, not on
8938 // top of defaults. This way applying a preset only changes the fields
8939 // the preset explicitly mentions; everything else stays as the user
8940 // had it. For example, applying Maximum will not flip HSTS off if the
8941 // user had it on — Maximum doesn't touch HSTS, so it's left alone.
8942 // Use "Reset to Defaults" if a clean slate is needed.
8943 $current = get_option( Vigilante_Settings::OPTION_NAME, array() );
8944 if ( ! is_array( $current ) ) {
8945 $current = array();
8946 }
8947 // Make sure all known keys exist before merging — the merge does not
8948 // invent keys that are missing on both sides.
8949 $current = Vigilante_Settings::merge_preset( $this->settings->get_default_options(), $current );
8950
8951 $merged = Vigilante_Settings::merge_preset( $current, $preset_options );
8952 $merged = Vigilante_Settings::keep_locked_file_settings( $merged, get_option( Vigilante_Settings::OPTION_NAME, array() ) );
8953
8954 update_option( Vigilante_Settings::OPTION_NAME, $merged );
8955 $this->settings->clear_cache();
8956
8957 // Save active preset
8958 update_option( 'vigilante_active_preset', $preset );
8959
8960 // Apply file changes after preset
8961 $this->apply_all_file_changes( $merged );
8962
8963 wp_send_json_success( __( 'Preset applied successfully.', 'vigilante' ) . $this->locked_file_settings_message() );
8964 }
8965
8966 /**
8967 * AJAX: Reset a specific section to defaults
8968 */
8969 public function ajax_reset_section() {
8970 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
8971
8972 if ( ! current_user_can( 'manage_options' ) ) {
8973 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
8974 }
8975
8976 $section = isset( $_POST['section'] ) ? sanitize_key( $_POST['section'] ) : '';
8977
8978 if ( empty( $section ) ) {
8979 wp_send_json_error( __( 'No section specified.', 'vigilante' ) );
8980 }
8981
8982 // Get current options and defaults. get_defaults_preserving_user_data()
8983 // applies the tweaks a fresh installation gets, so the button and a new
8984 // install agree, and keeps whatever the owner typed in.
8985 $current_options = $this->settings->get_all_options();
8986 $defaults = Vigilante_Settings::get_defaults_preserving_user_data( $current_options );
8987
8988 // Check if section exists in defaults
8989 if ( ! isset( $defaults[ $section ] ) ) {
8990 wp_send_json_error( __( 'Invalid section.', 'vigilante' ) );
8991 }
8992
8993 $new_values = $defaults[ $section ];
8994
8995 /*
8996 * On a subsite, the settings written to wp-config.php and .htaccess are
8997 * the main site's business. Resetting the local copy of those would only
8998 * make this screen disagree with the file, so they are carried over
8999 * untouched, and a section that is nothing but shared settings is not
9000 * reset at all. On the main site, a user without network rights keeps
9001 * the ones the shared files are built from as well (2.11.6).
9002 */
9003 $locked = Vigilante_Settings::get_locked_file_settings();
9004
9005 if ( isset( $locked[ $section ] ) && true === $locked[ $section ] ) {
9006 wp_send_json_error( Vigilante_Settings::get_shared_files_notice() );
9007 }
9008
9009 $current_options[ $section ] = $new_values;
9010 $current_options = Vigilante_Settings::keep_locked_file_settings( $current_options, get_option( Vigilante_Settings::OPTION_NAME, array() ) );
9011
9012 // Save
9013 update_option( Vigilante_Settings::OPTION_NAME, $current_options );
9014 $this->settings->clear_cache();
9015
9016 // Apply file changes if needed
9017 $this->apply_section_changes( $section, $current_options );
9018
9019 wp_send_json_success( array(
9020 'message' => __( 'Section reset to defaults.', 'vigilante' ),
9021 'section' => $section,
9022 'reload' => true,
9023 ) );
9024 }
9025
9026 /**
9027 * AJAX: Clear lockouts
9028 */
9029 public function ajax_clear_lockouts() {
9030 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9031
9032 if ( ! current_user_can( 'manage_options' ) ) {
9033 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9034 }
9035
9036 $ip = isset( $_POST['ip'] ) ? sanitize_text_field( wp_unslash( $_POST['ip'] ) ) : '';
9037
9038 if ( ! empty( $ip ) ) {
9039 $this->database->clear_lockout( $ip );
9040 } else {
9041 $this->database->clear_all_lockouts();
9042 }
9043
9044 wp_send_json_success( __( 'Lockouts cleared.', 'vigilante' ) );
9045 }
9046
9047 /**
9048 * AJAX: Clear logs
9049 */
9050 public function ajax_clear_logs() {
9051 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9052
9053 if ( ! current_user_can( 'manage_options' ) ) {
9054 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9055 }
9056
9057 if ( $this->activity_log ) {
9058 $result = $this->activity_log->clear_all_logs();
9059 if ( $result ) {
9060 wp_send_json_success( __( 'Logs cleared.', 'vigilante' ) );
9061 } else {
9062 wp_send_json_error( __( 'Failed to clear logs.', 'vigilante' ) );
9063 }
9064 } else {
9065 wp_send_json_error( __( 'Activity log not available.', 'vigilante' ) );
9066 }
9067 }
9068
9069 /**
9070 * AJAX: Run file integrity scan.
9071 *
9072 * Triggers the file integrity scan, which now also runs the closed plugins
9073 * check at the end when the `check_closed_plugins` toggle is on. Activity
9074 * log is passed through so Security Audit entries (both file-level and
9075 * plugin-status) are recorded from this entry point.
9076 */
9077 public function ajax_run_scan() {
9078 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9079
9080 if ( ! current_user_can( 'manage_options' ) ) {
9081 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9082 }
9083
9084 // Clear previous results before running new scan
9085 delete_option( 'vigilante_last_integrity_results' );
9086 delete_option( 'vigilante_last_integrity_scan' );
9087
9088 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database, $this->activity_log );
9089 $results = $file_integrity->run_scan();
9090
9091 // Save new results
9092 update_option( 'vigilante_last_integrity_scan', time() );
9093 update_option( 'vigilante_last_integrity_results', $results );
9094
9095 // On the main site the scan does compute the lines of wp-config.php and
9096 // .htaccess, for the network administrator. Somebody without network
9097 // rights gets the change and its sizes, not the lines.
9098 if ( $this->critical_approval_locked() && ! empty( $results['modified'] ) && is_array( $results['modified'] ) ) {
9099 foreach ( $results['modified'] as $index => $item ) {
9100 if ( is_array( $item ) && 'critical_config' === ( $item['type'] ?? '' ) ) {
9101 $results['modified'][ $index ]['diff'] = Vigilante_File_Integrity::network_only_diff();
9102 }
9103 }
9104 }
9105
9106 wp_send_json_success( array(
9107 'message' => __( 'Scan completed.', 'vigilante' ),
9108 'results' => $results,
9109 'ignored_count' => count( get_option( 'vigilante_ignored_files', array() ) ),
9110 ) );
9111 }
9112
9113 /**
9114 * AJAX: Clear scan results.
9115 *
9116 * Wipes visually everything inside "Last Scan Results": file scan findings
9117 * (Suspicious / Modified / Extra / Critical Config), file hashes and the
9118 * Closed + Removed Plugins block.
9119 *
9120 * Implementation detail to keep persistence intact:
9121 * - We delete the file scan options + hashes outright.
9122 * - For plugin status we ONLY delete the last_check timestamp — the state
9123 * map and the ignore list are preserved in DB. The render gates the
9124 * plugin_status subsections on last_check > 0, so they hide after
9125 * Clear (visual reset) and reappear on the next Run Scan Now with the
9126 * state intact. This avoids degrading a 'removed' slug (404 without
9127 * metadata) back to 'not_in_repo' on the next scan, which would
9128 * silently lose the alert.
9129 *
9130 * The Ignored Files list and the Ignored Closed + Removed Plugins list
9131 * are preserved on purpose; each has its own explicit "Clear All …"
9132 * button.
9133 */
9134 public function ajax_clear_scan() {
9135 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9136
9137 if ( ! current_user_can( 'manage_options' ) ) {
9138 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9139 }
9140
9141 $results = get_option( 'vigilante_last_integrity_results' );
9142 $scanned_at = get_option( 'vigilante_last_integrity_scan' );
9143
9144 delete_option( 'vigilante_last_integrity_results' );
9145 delete_option( 'vigilante_last_integrity_scan' );
9146
9147 // Starting over also means being told again: the next scan emails
9148 // whatever it finds, as if nothing had been reported before.
9149 delete_option( Vigilante_File_Integrity::NOTIFIED_OPTION );
9150
9151 /*
9152 * A pending change to wp-config.php or the root .htaccess is closed by
9153 * approving it, which takes the network. Clearing the results was one
9154 * more way to close it without, until the next scan: the ignore list was
9155 * shut in 2.11.8 and this button was left open, found by the cross
9156 * review of 2.11.8. So for somebody who cannot approve, those entries
9157 * stay and everything else goes.
9158 */
9159 // The findings about Vigilant's own files stay too: they report for the
9160 // whole network, and ignoring them already takes network rights.
9161 if ( $this->critical_approval_locked() && is_array( $results ) ) {
9162 $kept = array();
9163 $found = false;
9164 foreach ( array( 'modified', 'missing', 'suspicious', 'extra' ) as $bucket ) {
9165 $kept[ $bucket ] = array_values(
9166 array_filter(
9167 isset( $results[ $bucket ] ) && is_array( $results[ $bucket ] ) ? $results[ $bucket ] : array(),
9168 function ( $item ) {
9169 return is_array( $item ) && in_array( $item['type'] ?? '', array( 'critical_config', 'vigilante_self' ), true );
9170 }
9171 )
9172 );
9173 $found = $found || ! empty( $kept[ $bucket ] );
9174 }
9175
9176 if ( $found ) {
9177 $results = array_merge( $results, $kept );
9178 update_option( 'vigilante_last_integrity_results', $results );
9179 update_option( 'vigilante_last_integrity_scan', $scanned_at ? $scanned_at : time() );
9180 }
9181 }
9182
9183 if ( $this->database ) {
9184 $this->database->clear_file_hashes();
9185 }
9186
9187 // Visual reset of plugin_status block without touching the state map
9188 // or the ignored list. See PHPDoc above for the rationale.
9189 delete_option( 'vigilante_plugin_status_last_check' );
9190
9191 wp_send_json_success( __( 'Scan results cleared.', 'vigilante' ) );
9192 }
9193
9194 /**
9195 * AJAX: Ignore a file from scan results
9196 */
9197 public function ajax_ignore_file() {
9198 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9199
9200 if ( ! current_user_can( 'manage_options' ) ) {
9201 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9202 }
9203
9204 /*
9205 * The path as the scan reported it, which is what the interface sends
9206 * back. sanitize_text_field() is the wrong reader for it: it deletes
9207 * every %XX octet and collapses repeated spaces, so a file named
9208 * foto%20nueva.php was stored as fotonueva.php, the scan compared the
9209 * list with the paths it finds one by one, never matched, and the
9210 * warning came back (measured on 1 oct 2026 against 3.0.1). The four
9211 * handlers of the ignore list read the path the same way.
9212 *
9213 * Known limits, found by the cross review, that only a file name with a
9214 * stray < in it reaches. wp_strip_all_tags() shortens such a name at the
9215 * < instead of refusing it, so the stored entry can match another file
9216 * (a.php<b is stored as a.php), and the value ignore_file() returns is
9217 * not read, so a refusal of its own is answered as success. The fix, if
9218 * a site ever needs it, is to answer with an error when
9219 * wp_strip_all_tags() changes what was sent and to check that return
9220 * value. An entry the old reader stored for such a name (it wrote the
9221 * < as &lt;) is listed but "Stop ignoring" cannot remove it; "Clear all
9222 * ignored files" does.
9223 */
9224 $file = ( isset( $_POST['file'] ) && is_string( $_POST['file'] ) ) ? wp_strip_all_tags( wp_unslash( $_POST['file'] ) ) : '';
9225
9226 if ( empty( $file ) ) {
9227 wp_send_json_error( __( 'No file specified.', 'vigilante' ) );
9228 }
9229
9230 // A change to a shared file is closed by approving it, and approving it
9231 // takes the network. Ignoring it would close the same warning without.
9232 if ( $this->critical_approval_locked() && in_array( $file, array( 'wp-config.php', '.htaccess' ), true ) ) {
9233 wp_send_json_error( $this->critical_approval_notice() );
9234 }
9235
9236 // Vigilant's own files are never ignored, on any site: silencing the
9237 // check that says the security plugin was changed is the one button
9238 // an attacker would want on this screen. Since 3.0.0 those findings
9239 // are not rows of these tables either, so nothing in the interface
9240 // sends them here; this is the door, not the label.
9241 if ( Vigilante_Self_Integrity::is_own_file_path( $file ) ) {
9242 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' ) );
9243 }
9244
9245 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
9246 $file_integrity->ignore_file( $file );
9247
9248 // Also remove the file from stored scan results so UI updates
9249 $results = get_option( 'vigilante_last_integrity_results' );
9250 if ( $results ) {
9251 foreach ( array( 'modified', 'suspicious', 'extra' ) as $category ) {
9252 if ( ! empty( $results[ $category ] ) ) {
9253 $results[ $category ] = array_values(
9254 array_filter(
9255 $results[ $category ],
9256 function ( $item ) use ( $file ) {
9257 return ( is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item ) !== $file;
9258 }
9259 )
9260 );
9261 }
9262 }
9263 update_option( 'vigilante_last_integrity_results', $results );
9264 }
9265
9266 wp_send_json_success( __( 'File added to ignored list.', 'vigilante' ) );
9267 }
9268
9269 /**
9270 * AJAX: Stop ignoring a file
9271 */
9272 public function ajax_unignore_file() {
9273 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9274
9275 if ( ! current_user_can( 'manage_options' ) ) {
9276 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9277 }
9278
9279 $file = ( isset( $_POST['file'] ) && is_string( $_POST['file'] ) ) ? wp_strip_all_tags( wp_unslash( $_POST['file'] ) ) : '';
9280
9281 if ( empty( $file ) ) {
9282 wp_send_json_error( __( 'No file specified.', 'vigilante' ) );
9283 }
9284
9285 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
9286 $file_integrity->unignore_file( $file );
9287
9288 wp_send_json_success( __( 'File removed from ignored list.', 'vigilante' ) );
9289 }
9290
9291 /**
9292 * AJAX: Bulk ignore multiple files at once
9293 *
9294 * Processes a single batch into ignored list and prunes them from the
9295 * stored scan results so the UI updates without a re-scan.
9296 */
9297 public function ajax_bulk_ignore_files() {
9298 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9299
9300 if ( ! current_user_can( 'manage_options' ) ) {
9301 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9302 }
9303
9304 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized below per-item.
9305 $raw_files = isset( $_POST['files'] ) ? wp_unslash( $_POST['files'] ) : array();
9306 if ( ! is_array( $raw_files ) ) {
9307 wp_send_json_error( __( 'Invalid request.', 'vigilante' ) );
9308 }
9309
9310 $files = array();
9311 $locked = $this->critical_approval_locked();
9312 $shared = $locked ? array( 'wp-config.php', '.htaccess' ) : array();
9313 foreach ( $raw_files as $f ) {
9314 $clean = is_string( $f ) ? wp_strip_all_tags( $f ) : '';
9315 // Same rule as ajax_ignore_file(): the two shared files when the
9316 // network locks them, and Vigilant's own files always.
9317 if ( '' !== $clean && ! in_array( $clean, $shared, true ) && ! Vigilante_Self_Integrity::is_own_file_path( $clean ) ) {
9318 $files[] = $clean;
9319 }
9320 }
9321
9322 if ( empty( $files ) ) {
9323 wp_send_json_error( __( 'No files selected.', 'vigilante' ) );
9324 }
9325
9326 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
9327 $count = 0;
9328 foreach ( $files as $file ) {
9329 $file_integrity->ignore_file( $file );
9330 $count++;
9331 }
9332
9333 // Also prune the stored scan results so the UI matches the new ignore list.
9334 $results = get_option( 'vigilante_last_integrity_results' );
9335 if ( $results ) {
9336 $files_set = array_flip( $files );
9337 foreach ( array( 'modified', 'suspicious', 'extra' ) as $category ) {
9338 if ( ! empty( $results[ $category ] ) ) {
9339 $results[ $category ] = array_values(
9340 array_filter(
9341 $results[ $category ],
9342 function ( $item ) use ( $files_set ) {
9343 $path = is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item;
9344 return ! isset( $files_set[ $path ] );
9345 }
9346 )
9347 );
9348 }
9349 }
9350 update_option( 'vigilante_last_integrity_results', $results );
9351 }
9352
9353 wp_send_json_success(
9354 array(
9355 'count' => $count,
9356 'message' => sprintf(
9357 /* translators: %d: number of files added to the ignored list */
9358 _n( '%d file added to ignored list.', '%d files added to ignored list.', $count, 'vigilante' ),
9359 $count
9360 ),
9361 )
9362 );
9363 }
9364
9365 /**
9366 * AJAX: Bulk un-ignore multiple files at once
9367 */
9368 public function ajax_bulk_unignore_files() {
9369 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9370
9371 if ( ! current_user_can( 'manage_options' ) ) {
9372 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9373 }
9374
9375 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized below per-item.
9376 $raw_files = isset( $_POST['files'] ) ? wp_unslash( $_POST['files'] ) : array();
9377 if ( ! is_array( $raw_files ) ) {
9378 wp_send_json_error( __( 'Invalid request.', 'vigilante' ) );
9379 }
9380
9381 $files = array();
9382 foreach ( $raw_files as $f ) {
9383 $clean = is_string( $f ) ? wp_strip_all_tags( $f ) : '';
9384 if ( '' !== $clean ) {
9385 $files[] = $clean;
9386 }
9387 }
9388
9389 if ( empty( $files ) ) {
9390 wp_send_json_error( __( 'No files selected.', 'vigilante' ) );
9391 }
9392
9393 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
9394 $count = 0;
9395 foreach ( $files as $file ) {
9396 $file_integrity->unignore_file( $file );
9397 $count++;
9398 }
9399
9400 wp_send_json_success(
9401 array(
9402 'count' => $count,
9403 'message' => sprintf(
9404 /* translators: %d: number of files removed from the ignored list */
9405 _n( '%d file removed from ignored list.', '%d files removed from ignored list.', $count, 'vigilante' ),
9406 $count
9407 ),
9408 )
9409 );
9410 }
9411
9412 /**
9413 * AJAX: Clear all ignored files
9414 */
9415 public function ajax_clear_ignored() {
9416 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9417
9418 if ( ! current_user_can( 'manage_options' ) ) {
9419 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9420 }
9421
9422 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
9423 $file_integrity->clear_ignored_files();
9424
9425 wp_send_json_success( __( 'Ignored files list cleared.', 'vigilante' ) );
9426 }
9427
9428 /**
9429 * AJAX: Ignore a closed/removed plugin slug so it stops appearing in the
9430 * main list and email digests. The plugin keeps running on the site;
9431 * silencing is purely cosmetic and reversible.
9432 */
9433 public function ajax_ignore_closed_plugin() {
9434 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9435
9436 if ( ! current_user_can( 'manage_options' ) ) {
9437 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9438 }
9439
9440 $slug = isset( $_POST['slug'] ) ? sanitize_key( wp_unslash( $_POST['slug'] ) ) : '';
9441 if ( '' === $slug ) {
9442 wp_send_json_error( __( 'No slug specified.', 'vigilante' ) );
9443 }
9444
9445 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
9446 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
9447 }
9448 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
9449 $checker->ignore_slug( $slug );
9450
9451 wp_send_json_success( __( 'Plugin added to the ignored list.', 'vigilante' ) );
9452 }
9453
9454 /**
9455 * AJAX: Stop ignoring a previously-ignored closed/removed plugin slug.
9456 */
9457 public function ajax_unignore_closed_plugin() {
9458 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9459
9460 if ( ! current_user_can( 'manage_options' ) ) {
9461 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9462 }
9463
9464 $slug = isset( $_POST['slug'] ) ? sanitize_key( wp_unslash( $_POST['slug'] ) ) : '';
9465 if ( '' === $slug ) {
9466 wp_send_json_error( __( 'No slug specified.', 'vigilante' ) );
9467 }
9468
9469 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
9470 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
9471 }
9472 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
9473 $checker->unignore_slug( $slug );
9474
9475 wp_send_json_success( __( 'Plugin removed from the ignored list.', 'vigilante' ) );
9476 }
9477
9478 /**
9479 * AJAX: Clear the entire ignored-closed-plugins list.
9480 */
9481 public function ajax_clear_ignored_closed_plugins() {
9482 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9483
9484 if ( ! current_user_can( 'manage_options' ) ) {
9485 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9486 }
9487
9488 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
9489 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
9490 }
9491 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
9492 $checker->clear_ignored();
9493
9494 wp_send_json_success( __( 'Ignored closed plugins list cleared.', 'vigilante' ) );
9495 }
9496
9497 /**
9498 * AJAX: Test security headers
9499 */
9500 public function ajax_test_headers() {
9501 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
9502
9503 if ( ! current_user_can( 'manage_options' ) ) {
9504 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
9505 }
9506
9507 // Get security grade from settings (not from actual HTTP request)
9508 $security_headers = new Vigilante_Security_Headers( $this->settings );
9509 $results = $security_headers->get_security_grade();
9510
9511 wp_send_json_success( $results );
9512 }
9513
9514 /**
9515 * Sanitize section data (kept for compatibility)
9516 *
9517 * @param string $section Section name.
9518 * @param array $data Section data.
9519 * @return array
9520 */
9521 private function sanitize_section_data( $section, $data ) {
9522 $sanitized = array();
9523
9524 foreach ( $data as $key => $value ) {
9525 $key = sanitize_key( $key );
9526
9527 if ( is_array( $value ) ) {
9528 $sanitized[ $key ] = $this->sanitize_section_data( $key, $value );
9529 } elseif ( is_numeric( $value ) ) {
9530 $sanitized[ $key ] = intval( $value );
9531 } else {
9532 $sanitized[ $key ] = sanitize_text_field( $value );
9533 }
9534 }
9535
9536 return $sanitized;
9537 }
9538
9539 /**
9540 * Apply changes after saving settings
9541 *
9542 * @param string $section Section that was updated.
9543 * @param array $all_options All options.
9544 */
9545 private function apply_section_changes( $section, $all_options ) {
9546 // Create fresh settings instance to ensure we have the latest data
9547 $fresh_settings = new Vigilante_Settings();
9548
9549 // The shared Vigilant .htaccess block carries BOTH the firewall's
9550 // file-protection rules and the server-signature / fingerprinting rules
9551 // that are configured under Security Headers. So it must be regenerated
9552 // whenever either section (or the module toggles) changes, not only on
9553 // the firewall save — otherwise toggling "Hide server signature" or
9554 // "Remove fingerprinting headers" never reaches the .htaccess.
9555 if ( in_array( $section, array( 'firewall', 'security_headers', 'modules' ), true ) ) {
9556 $htaccess = new Vigilante_Htaccess_Protection( $fresh_settings );
9557 $sh = $fresh_settings->get_section( 'security_headers' );
9558 $needs_htaccess_block = ! empty( $all_options['modules']['firewall'] )
9559 || ! empty( $sh['hide_server_signature'] )
9560 || ! empty( $sh['remove_fingerprinting_headers'] );
9561
9562 if ( $needs_htaccess_block ) {
9563 $htaccess->apply_rules();
9564 } else {
9565 $htaccess->remove_rules();
9566 }
9567 }
9568
9569 // Regenerate the HTTP security headers (sent by PHP) for the headers section.
9570 if ( 'security_headers' === $section || 'modules' === $section ) {
9571 $security_headers = new Vigilante_Security_Headers( $fresh_settings );
9572 $headers_enabled = ! empty( $all_options['modules']['security_headers'] );
9573
9574 if ( $headers_enabled ) {
9575 $security_headers->apply_rules();
9576 } else {
9577 $security_headers->remove_rules();
9578 }
9579 }
9580
9581 // Regenerate wp-config for wp_hardening section
9582 if ( 'wp_hardening' === $section || 'modules' === $section ) {
9583 $wpconfig = new Vigilante_Wpconfig_Security( $fresh_settings );
9584 $hardening_enabled = ! empty( $all_options['modules']['wp_hardening'] );
9585
9586 if ( $hardening_enabled ) {
9587 $wpconfig->apply_security_constants();
9588 } else {
9589 $wpconfig->remove_constants();
9590 }
9591
9592 // Apply WordPress options for comments/pingbacks
9593 $hardening_options = $all_options['wp_hardening'] ?? array();
9594
9595 if ( $hardening_enabled ) {
9596 // Pingbacks
9597 if ( ! empty( $hardening_options['disable_pingbacks'] ) ) {
9598 update_option( 'default_pingback_flag', 0 );
9599 } else {
9600 // Restore default: pingbacks enabled
9601 update_option( 'default_pingback_flag', 1 );
9602 }
9603
9604 // Trackbacks and ping status
9605 // Only close if either pingbacks OR trackbacks are disabled
9606 if ( ! empty( $hardening_options['disable_pingbacks'] ) || ! empty( $hardening_options['disable_trackbacks'] ) ) {
9607 update_option( 'default_ping_status', 'closed' );
9608 } else {
9609 // Restore default: pings open
9610 update_option( 'default_ping_status', 'open' );
9611 }
9612
9613 // Comment moderation
9614 if ( ! empty( $hardening_options['require_comment_moderation'] ) ) {
9615 update_option( 'comment_moderation', 1 );
9616 } else {
9617 // Restore default: no moderation required
9618 update_option( 'comment_moderation', 0 );
9619 }
9620 }
9621 }
9622
9623 // Trim activity log entries immediately when limits change
9624 if ( 'activity_log' === $section && $this->activity_log ) {
9625 $this->activity_log->cleanup_old_logs();
9626 }
9627
9628 // Flush rewrite rules if login URL changed
9629 if ( 'login_security' === $section ) {
9630 $login_options = $all_options['login_security'] ?? array();
9631 if ( ! empty( $login_options['custom_login_url'] ) ) {
9632 delete_option( 'vigilante_login_rules_version' );
9633 }
9634 }
9635
9636 // Log the settings change with readable section name
9637 if ( $this->activity_log ) {
9638 $section_names = array(
9639 'firewall' => __( 'Firewall', 'vigilante' ),
9640 'login_security' => __( 'Login Security', 'vigilante' ),
9641 'security_headers' => __( 'Security Headers', 'vigilante' ),
9642 'rest_api_security'=> __( 'REST API Security', 'vigilante' ),
9643 'user_security' => __( 'User Security', 'vigilante' ),
9644 'wp_hardening' => __( 'WP Hardening', 'vigilante' ),
9645 'activity_log' => __( 'Security Audit', 'vigilante' ),
9646 'file_integrity' => __( 'File Integrity', 'vigilante' ),
9647 'email' => __( 'Notification Settings', 'vigilante' ),
9648 'backup' => __( 'Backup', 'vigilante' ),
9649 'advanced' => __( 'Advanced', 'vigilante' ),
9650 'modules' => __( 'Modules', 'vigilante' ),
9651 );
9652 $display_name = isset( $section_names[ $section ] ) ? $section_names[ $section ] : $section;
9653
9654 $this->activity_log->log(
9655 'settings',
9656 'settings_updated',
9657 sprintf(
9658 /* translators: %s: Section name */
9659 __( 'Settings updated: %s', 'vigilante' ),
9660 $display_name
9661 ),
9662 array( 'section' => $section ),
9663 'info'
9664 );
9665 }
9666 }
9667
9668 /**
9669 * Apply all file changes (htaccess, wp-config) based on current options
9670 *
9671 * Used after preset, import, or reset operations
9672 *
9673 * @param array $all_options All plugin options.
9674 */
9675 private function apply_all_file_changes( $all_options ) {
9676 // Refresh settings cache first
9677 $this->settings->clear_cache();
9678
9679 // Create fresh settings instance
9680 $fresh_settings = new Vigilante_Settings();
9681
9682 // Apply firewall htaccess changes
9683 $htaccess = new Vigilante_Htaccess_Protection( $fresh_settings );
9684 $firewall_enabled = ! empty( $all_options['modules']['firewall'] );
9685
9686 if ( $firewall_enabled ) {
9687 $htaccess->apply_rules();
9688 } else {
9689 $htaccess->remove_rules();
9690 }
9691
9692 // Apply security headers htaccess changes
9693 $security_headers = new Vigilante_Security_Headers( $fresh_settings );
9694 $headers_enabled = ! empty( $all_options['modules']['security_headers'] );
9695
9696 if ( $headers_enabled ) {
9697 $security_headers->apply_rules();
9698 } else {
9699 $security_headers->remove_rules();
9700 }
9701
9702 // Apply wp-config changes
9703 $wpconfig = new Vigilante_Wpconfig_Security( $fresh_settings );
9704 $hardening_enabled = ! empty( $all_options['modules']['wp_hardening'] );
9705
9706 if ( $hardening_enabled ) {
9707 $wpconfig->apply_security_constants();
9708 } else {
9709 $wpconfig->remove_constants();
9710 }
9711
9712 // Apply WordPress options for comments/pingbacks
9713 $hardening_options = $all_options['wp_hardening'] ?? array();
9714
9715 if ( $hardening_enabled ) {
9716 // Pingbacks
9717 if ( ! empty( $hardening_options['disable_pingbacks'] ) ) {
9718 update_option( 'default_pingback_flag', 0 );
9719 } else {
9720 // Restore default: pingbacks enabled
9721 update_option( 'default_pingback_flag', 1 );
9722 }
9723
9724 // Trackbacks and ping status
9725 // Only close if either pingbacks OR trackbacks are disabled
9726 if ( ! empty( $hardening_options['disable_pingbacks'] ) || ! empty( $hardening_options['disable_trackbacks'] ) ) {
9727 update_option( 'default_ping_status', 'closed' );
9728 } else {
9729 // Restore default: pings open
9730 update_option( 'default_ping_status', 'open' );
9731 }
9732
9733 // Comment moderation
9734 if ( ! empty( $hardening_options['require_comment_moderation'] ) ) {
9735 update_option( 'comment_moderation', 1 );
9736 } else {
9737 // Restore default: no moderation required
9738 update_option( 'comment_moderation', 0 );
9739 }
9740 }
9741
9742 // Log the change
9743 if ( $this->activity_log ) {
9744 $this->activity_log->log(
9745 'settings',
9746 'bulk_settings_applied',
9747 __( 'Bulk settings applied (preset/import/reset)', 'vigilante' ),
9748 array(),
9749 'info'
9750 );
9751 }
9752 }
9753 }