PluginProbe
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… / 2.11.8
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… v2.11.8
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 +58 -26 2.9.82.11.8 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 }
@@ -226,25 +223,8 @@
226 223 return true;
227 224 }
228 225
229 226 /**
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 227 * Apply htaccess protection
248 228 *
249 229 * @param Vigilante_Settings $settings Settings instance.
250 230 */
@@ -250,8 +230,9 @@
250 230 */
251 231 private static function apply_htaccess_protection( $settings ) {
252 232 // Only apply if Apache server
253 233 if ( ! self::is_apache() ) {
234 + self::mark_server_files_pending();
254 235 return;
255 236 }
256 237
257 238 require_once VIGILANTE_INCLUDES_DIR . 'class-htaccess-protection.php';
@@ -267,8 +248,9 @@
267 248 */
268 249 private static function apply_security_headers( $settings ) {
269 250 // Only apply if Apache server
270 251 if ( ! self::is_apache() ) {
252 + self::mark_server_files_pending();
271 253 return;
272 254 }
273 255
274 256 require_once VIGILANTE_INCLUDES_DIR . 'class-security-headers.php';
@@ -332,8 +314,14 @@
332 314 *
333 315 * @param Vigilante_Settings $settings Settings instance.
334 316 */
335 317 private static function remove_sensitive_files( $settings ) {
318 + // They sit in the root every site of a network shares. Until 2.11.6 the
319 + // activation on any site removed them.
320 + if ( ! Vigilante_Settings::can_write_shared_files() ) {
321 + return;
322 + }
323 +
336 324 $advanced = $settings->get_section( 'advanced' );
337 325
338 326 // Remove readme.html
339 327 if ( ! empty( $advanced['remove_readme'] ) ) {
@@ -373,9 +361,15 @@
373 361 $database = new Vigilante_Database();
374 362 $activity_log = null; // Not needed for baseline generation
375 363
376 364 $fi = new Vigilante_File_Integrity( $settings, $database, $activity_log );
377 - $fi->regenerate_all_baselines();
365 +
366 + // Same care as the migration: reactivating the plugin on a site that
367 + // already has an approved baseline must not throw it away and adopt
368 + // whatever the files say today.
369 + if ( ! $fi->get_critical_files_baseline() ) {
370 + $fi->regenerate_all_baselines();
371 + }
378 372 }
379 373
380 374 /**
381 375 * Schedule cron events
@@ -471,12 +465,50 @@
471 465 *
472 466 * @return bool
473 467 */
474 468 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;
469 + require_once VIGILANTE_INCLUDES_DIR . 'class-htaccess-manager.php';
470 +
471 + // One detection for the whole plugin. This used to be a second copy of
472 + // the same logic, so fixing one never fixed the other.
473 + return Vigilante_Htaccess_Manager::get_instance()->is_apache();
474 + }
475 +
476 + /**
477 + * Leave the server layer pending when the server could not be identified
478 + *
479 + * An activation from WP-CLI has no request to read the server software
480 + * from, so before 2.9.9 the two apply_* guards below simply returned and
481 + * the site was left without the .htaccess layer, with every switch showing
482 + * as on. Now it is written down, so the first web request applies it, and
483 + * it is logged, so it is visible that it happened.
484 + *
485 + * @since 2.9.9
486 + */
487 + private static function mark_server_files_pending() {
488 + require_once VIGILANTE_INCLUDES_DIR . 'class-htaccess-manager.php';
489 +
490 + // On a server known not to be Apache there is nothing to write, ever.
491 + if ( ! Vigilante_Htaccess_Manager::get_instance()->server_is_unknown() ) {
492 + return;
479 493 }
480 - return true;
494 +
495 + update_option( 'vigilante_server_files_pending', 1 );
496 +
497 + // The activation runs before the plugin has loaded its own files, so
498 + // every link of the chain has to be pulled in: the log asks the database
499 + // for the client IP, and that resolves it through the IP helper.
500 + require_once VIGILANTE_INCLUDES_DIR . 'class-ip-utils.php';
501 + require_once VIGILANTE_INCLUDES_DIR . 'class-database.php';
502 + require_once VIGILANTE_INCLUDES_DIR . 'class-activity-log.php';
503 +
504 + $settings = new Vigilante_Settings();
505 + $activity_log = new Vigilante_Activity_Log( $settings, new Vigilante_Database() );
506 + $activity_log->log(
507 + 'system',
508 + 'server_rules_pending',
509 + __( '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' ),
510 + array( 'sapi' => PHP_SAPI ),
511 + 'warning'
512 + );
481 513 }
482 514 }