PluginProbe
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… / 2.11.12
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… v2.11.12
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 +90 -27 2.9.42.11.12 View file →
@@ -41,9 +41,28 @@
41 41 $current_options = get_option( Vigilante_Settings::OPTION_NAME );
42 42
43 43 if ( false === $current_options ) {
44 44 // First installation - set defaults
45 - update_option( Vigilante_Settings::OPTION_NAME, $settings->get_default_options() );
45 + $first_run = $settings->get_default_options();
46 +
47 + /*
48 + * XML-RPC on a brand new install: block the pingback methods, which is
49 + * what gets abused for amplification, and leave the rest reachable so
50 + * the WordPress app, Jetpack or a remote manager keep working out of
51 + * the box. Disabling it completely is the stricter choice and the one
52 + * the settings screen recommends, but it is not imposed on a site that
53 + * never asked for it. Brute force through XML-RPC stays covered either
54 + * way, because those logins go through wp_authenticate() and the login
55 + * lockout hooks into it.
56 + *
57 + * Only written here, on a first installation. Sites upgrading keep
58 + * whatever they had: the activation hook does not run on an update, and
59 + * Vigilante_Comment_Security::resolve_xmlrpc_mode() answers 'full' when
60 + * nothing is stored, which is what every version since 1.0.0 did.
61 + */
62 + $first_run = Vigilante_Settings::apply_install_tweaks( $first_run );
63 +
64 + update_option( Vigilante_Settings::OPTION_NAME, $first_run );
46 65 // Refresh settings instance to get new values
47 66 $settings->clear_cache();
48 67 $settings = new Vigilante_Settings();
49 68 } else {
@@ -53,11 +72,8 @@
53 72 $settings = new Vigilante_Settings();
54 73 }
55 74 }
56 75
57 - // Create backup of current files FIRST (before any modifications)
58 - self::create_activation_backup( $settings );
59 -
60 76 // Apply htaccess protection (part of firewall module)
61 77 if ( $settings->is_module_enabled( 'firewall' ) ) {
62 78 self::apply_htaccess_protection( $settings );
63 79 }
@@ -207,25 +223,8 @@
207 223 return true;
208 224 }
209 225
210 226 /**
211 - * Create backup of important files
212 - *
213 - * @param Vigilante_Settings $settings Settings instance.
214 - */
215 - private static function create_activation_backup( $settings ) {
216 - require_once VIGILANTE_INCLUDES_DIR . 'class-backup-manager.php';
217 -
218 - $backup_manager = new Vigilante_Backup_Manager();
219 - $result = $backup_manager->create_backups();
220 -
221 - if ( is_wp_error( $result ) ) {
222 - // Store error for admin notice
223 - set_transient( 'vigilante_backup_error', $result->get_error_message(), 60 );
224 - }
225 - }
226 -
227 - /**
228 227 * Apply htaccess protection
229 228 *
230 229 * @param Vigilante_Settings $settings Settings instance.
231 230 */
@@ -231,8 +230,9 @@
231 230 */
232 231 private static function apply_htaccess_protection( $settings ) {
233 232 // Only apply if Apache server
234 233 if ( ! self::is_apache() ) {
234 + self::mark_server_files_pending();
235 235 return;
236 236 }
237 237
238 238 require_once VIGILANTE_INCLUDES_DIR . 'class-htaccess-protection.php';
@@ -248,8 +248,9 @@
248 248 */
249 249 private static function apply_security_headers( $settings ) {
250 250 // Only apply if Apache server
251 251 if ( ! self::is_apache() ) {
252 + self::mark_server_files_pending();
252 253 return;
253 254 }
254 255
255 256 require_once VIGILANTE_INCLUDES_DIR . 'class-security-headers.php';
@@ -281,8 +282,20 @@
281 282 if ( empty( $options['force_https'] ) ) {
282 283 return;
283 284 }
284 285
286 + /*
287 + * Only rewrite the URLs when the request doing the activation is itself
288 + * running over HTTPS, which proves the site answers over it. Without this
289 + * check, activating on an HTTP-only site pointed it at an address that
290 + * may not respond, locking the owner out of their own admin. is_ssl() is
291 + * also false under WP-CLI, where there is no request to learn from, so a
292 + * command-line activation leaves the URLs alone as well.
293 + */
294 + if ( ! is_ssl() ) {
295 + return;
296 + }
297 +
285 298 // Check if already HTTPS
286 299 $site_url = get_option( 'siteurl' );
287 300 $home_url = get_option( 'home' );
288 301
@@ -301,8 +314,14 @@
301 314 *
302 315 * @param Vigilante_Settings $settings Settings instance.
303 316 */
304 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 +
305 324 $advanced = $settings->get_section( 'advanced' );
306 325
307 326 // Remove readme.html
308 327 if ( ! empty( $advanced['remove_readme'] ) ) {
@@ -342,9 +361,15 @@
342 361 $database = new Vigilante_Database();
343 362 $activity_log = null; // Not needed for baseline generation
344 363
345 364 $fi = new Vigilante_File_Integrity( $settings, $database, $activity_log );
346 - $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 + }
347 372 }
348 373
349 374 /**
350 375 * Schedule cron events
@@ -440,12 +465,50 @@
440 465 *
441 466 * @return bool
442 467 */
443 468 private static function is_apache() {
444 - if ( ! function_exists( 'apache_get_modules' ) ) {
445 - // Check server software
446 - $server = isset( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : '';
447 - 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;
448 493 }
449 - 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 + );
450 513 }
451 514 }