PluginProbe
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… / 3.0.0
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… v3.0.0
3.0.0 2.11.12 2.11.11 2.11.10 2.11.9 2.11.7 2.11.8 2.11.6 2.11.5 2.11.4 2.11.3 2.11.1 2.11.2 2.11.0 2.10.5 2.10.4 2.10.3 2.10.2 2.10.1 2.10.0 2.9.9 2.9.8 2.9.6 2.9.7 2.9.5 All 88 releases
← All changes | includes/class-activator.php +88 -26 2.9.83.0.0 View file →
@@ -72,11 +72,8 @@
72 72 $settings = new Vigilante_Settings();
73 73 }
74 74 }
75 75
76 - // Create backup of current files FIRST (before any modifications)
77 - self::create_activation_backup( $settings );
78 -
79 76 // Apply htaccess protection (part of firewall module)
80 77 if ( $settings->is_module_enabled( 'firewall' ) ) {
81 78 self::apply_htaccess_protection( $settings );
82 79 }
@@ -109,8 +106,11 @@
109 106
110 107 // Schedule cron events
111 108 self::schedule_events();
112 109
110 + // Capture the self-integrity anchor (A3: manifest fingerprint in DB).
111 + self::anchor_self_integrity( $settings );
112 +
113 113 // Set activation transient for admin notice
114 114 set_transient( 'vigilante_activated', true, 30 );
115 115
116 116 // Store activation time
@@ -126,8 +126,35 @@
126 126 ob_end_clean();
127 127 }
128 128
129 129 /**
130 + * Anchor the self-integrity check on activation
131 + *
132 + * The first activation captures the fingerprint of the shipped manifest,
133 + * unless WordPress.org distributes something else for that version, so
134 + * the self-check has a baseline from the very first run. A
135 + * reactivation keeps the anchor it already has and checks against it:
136 + * capturing again adopted whatever manifest the folder held at that
137 + * moment, a regenerated one included, the same reason the critical files
138 + * baseline is not thrown away on reactivation.
139 + *
140 + * @since 3.0.0
141 + *
142 + * @param Vigilante_Settings $settings Settings instance.
143 + * @return void
144 + */
145 + public static function anchor_self_integrity( $settings ) {
146 + if ( ! class_exists( 'Vigilante_Self_Integrity' ) ) {
147 + require_once VIGILANTE_INCLUDES_DIR . 'class-self-integrity.php';
148 + }
149 + // run_check() captures on the first run itself, but only when
150 + // WordPress.org does not contradict the manifest; with an anchor already
151 + // there it checks against it.
152 + $self_integrity = new Vigilante_Self_Integrity( $settings );
153 + $self_integrity->run_check( 'activation' );
154 + }
155 +
156 + /**
130 157 * Idempotent migrations for existing installations.
131 158 *
132 159 * @param array $current_options Current vigilante_options array.
133 160 * @return bool True if any migration changed the stored option.
@@ -226,25 +253,8 @@
226 253 return true;
227 254 }
228 255
229 256 /**
230 - * Create backup of important files
231 - *
232 - * @param Vigilante_Settings $settings Settings instance.
233 - */
234 - private static function create_activation_backup( $settings ) {
235 - require_once VIGILANTE_INCLUDES_DIR . 'class-backup-manager.php';
236 -
237 - $backup_manager = new Vigilante_Backup_Manager();
238 - $result = $backup_manager->create_backups();
239 -
240 - if ( is_wp_error( $result ) ) {
241 - // Store error for admin notice
242 - set_transient( 'vigilante_backup_error', $result->get_error_message(), 60 );
243 - }
244 - }
245 -
246 - /**
247 257 * Apply htaccess protection
248 258 *
249 259 * @param Vigilante_Settings $settings Settings instance.
250 260 */
@@ -250,8 +260,9 @@
250 260 */
251 261 private static function apply_htaccess_protection( $settings ) {
252 262 // Only apply if Apache server
253 263 if ( ! self::is_apache() ) {
264 + self::mark_server_files_pending();
254 265 return;
255 266 }
256 267
257 268 require_once VIGILANTE_INCLUDES_DIR . 'class-htaccess-protection.php';
@@ -267,8 +278,9 @@
267 278 */
268 279 private static function apply_security_headers( $settings ) {
269 280 // Only apply if Apache server
270 281 if ( ! self::is_apache() ) {
282 + self::mark_server_files_pending();
271 283 return;
272 284 }
273 285
274 286 require_once VIGILANTE_INCLUDES_DIR . 'class-security-headers.php';
@@ -332,8 +344,14 @@
332 344 *
333 345 * @param Vigilante_Settings $settings Settings instance.
334 346 */
335 347 private static function remove_sensitive_files( $settings ) {
348 + // They sit in the root every site of a network shares. Until 2.11.6 the
349 + // activation on any site removed them.
350 + if ( ! Vigilante_Settings::can_write_shared_files() ) {
351 + return;
352 + }
353 +
336 354 $advanced = $settings->get_section( 'advanced' );
337 355
338 356 // Remove readme.html
339 357 if ( ! empty( $advanced['remove_readme'] ) ) {
@@ -373,9 +391,15 @@
373 391 $database = new Vigilante_Database();
374 392 $activity_log = null; // Not needed for baseline generation
375 393
376 394 $fi = new Vigilante_File_Integrity( $settings, $database, $activity_log );
377 - $fi->regenerate_all_baselines();
395 +
396 + // Same care as the migration: reactivating the plugin on a site that
397 + // already has an approved baseline must not throw it away and adopt
398 + // whatever the files say today.
399 + if ( ! $fi->get_critical_files_baseline() ) {
400 + $fi->regenerate_all_baselines();
401 + }
378 402 }
379 403
380 404 /**
381 405 * Schedule cron events
@@ -471,12 +495,50 @@
471 495 *
472 496 * @return bool
473 497 */
474 498 private static function is_apache() {
475 - if ( ! function_exists( 'apache_get_modules' ) ) {
476 - // Check server software
477 - $server = isset( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : '';
478 - return stripos( $server, 'apache' ) !== false || stripos( $server, 'litespeed' ) !== false;
499 + require_once VIGILANTE_INCLUDES_DIR . 'class-htaccess-manager.php';
500 +
501 + // One detection for the whole plugin. This used to be a second copy of
502 + // the same logic, so fixing one never fixed the other.
503 + return Vigilante_Htaccess_Manager::get_instance()->is_apache();
504 + }
505 +
506 + /**
507 + * Leave the server layer pending when the server could not be identified
508 + *
509 + * An activation from WP-CLI has no request to read the server software
510 + * from, so before 2.9.9 the two apply_* guards below simply returned and
511 + * the site was left without the .htaccess layer, with every switch showing
512 + * as on. Now it is written down, so the first web request applies it, and
513 + * it is logged, so it is visible that it happened.
514 + *
515 + * @since 2.9.9
516 + */
517 + private static function mark_server_files_pending() {
518 + require_once VIGILANTE_INCLUDES_DIR . 'class-htaccess-manager.php';
519 +
520 + // On a server known not to be Apache there is nothing to write, ever.
521 + if ( ! Vigilante_Htaccess_Manager::get_instance()->server_is_unknown() ) {
522 + return;
479 523 }
480 - return true;
524 +
525 + update_option( 'vigilante_server_files_pending', 1 );
526 +
527 + // The activation runs before the plugin has loaded its own files, so
528 + // every link of the chain has to be pulled in: the log asks the database
529 + // for the client IP, and that resolves it through the IP helper.
530 + require_once VIGILANTE_INCLUDES_DIR . 'class-ip-utils.php';
531 + require_once VIGILANTE_INCLUDES_DIR . 'class-database.php';
532 + require_once VIGILANTE_INCLUDES_DIR . 'class-activity-log.php';
533 +
534 + $settings = new Vigilante_Settings();
535 + $activity_log = new Vigilante_Activity_Log( $settings, new Vigilante_Database() );
536 + $activity_log->log(
537 + 'system',
538 + 'server_rules_pending',
539 + __( 'The server type could not be identified from this request, so the .htaccess rules were left pending and will be written on the first web request.', 'vigilante' ),
540 + array( 'sapi' => PHP_SAPI ),
541 + 'warning'
542 + );
481 543 }
482 544 }