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-database-prefix.php +18 -16 2.10.52.11.8 View file →
@@ -74,9 +74,9 @@
74 74 if ( ! is_multisite() ) {
75 75 return true;
76 76 }
77 77
78 - if ( ! is_main_site() ) {
78 + if ( ! is_main_site() || ! is_main_network() ) {
79 79 return new WP_Error(
80 80 'multisite_not_main_site',
81 81 __( 'The database prefix is shared by the whole network. Change it from the main site of the network.', 'vigilante' )
82 82 );
@@ -440,14 +440,24 @@
440 440 if ( false === $content ) {
441 441 return new WP_Error( 'read_error', __( 'Cannot read wp-config.php.', 'vigilante' ) );
442 442 }
443 443
444 - // Back up the original file
445 - $backup_path = $this->wpconfig_path . '.vigilante-backup-' . gmdate( 'YmdHis' );
446 - // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents
447 - if ( ! file_put_contents( $backup_path, $content ) ) {
448 - return new WP_Error( 'backup_error', __( 'Cannot create wp-config.php backup.', 'vigilante' ) );
449 - }
444 + /*
445 + * The original file is held in $content, in memory, and that is the
446 + * whole backup this needs.
447 + *
448 + * Until 2.11.3 it also wrote a copy next to wp-config.php, named
449 + * wp-config.php.vigilante-backup-<timestamp>. On a standard install
450 + * that is the site root, the name is a predictable timestamp and it
451 + * carries no .php extension, so a server hands it over as plain text
452 + * with the database credentials and the eight salts inside. It was
453 + * deleted straight after, but a request that died in between left it
454 + * there for good, and that is exactly the moment when the owner is busy
455 + * with a site that will not load. Present since 1.2.0.
456 + *
457 + * Nothing is lost by removing it: that file was never read back. The
458 + * restore below, the only path that undoes anything, uses $content.
459 + */
450 460
451 461 // Match the $table_prefix line (handles single and double quotes, with/without spaces)
452 462 $pattern = '/(\$table_prefix\s*=\s*)([\'"]).+?\\2(\s*;)/';
453 463 $replacement = '${1}\'' . $this->new_prefix . '\'${3}';
@@ -454,10 +464,8 @@
454 464
455 465 $new_content = preg_replace( $pattern, $replacement, $content, 1, $count );
456 466
457 467 if ( 0 === $count || null === $new_content ) {
458 - // phpcs:ignore WordPress.WP.AlternativeFunctions.unlink_unlink
459 - unlink( $backup_path );
460 468 return new WP_Error( 'replace_error', __( 'Cannot find $table_prefix in wp-config.php.', 'vigilante' ) );
461 469 }
462 470
463 471 // Write updated content
@@ -464,19 +472,13 @@
464 472 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents
465 473 $result = file_put_contents( $this->wpconfig_path, $new_content );
466 474
467 475 if ( false === $result ) {
468 - // Restore backup
476 + // Restore from memory, which is where the original has been all along.
469 477 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents
470 478 file_put_contents( $this->wpconfig_path, $content );
471 - // phpcs:ignore WordPress.WP.AlternativeFunctions.unlink_unlink
472 - unlink( $backup_path );
473 479 return new WP_Error( 'write_error', __( 'Cannot write to wp-config.php.', 'vigilante' ) );
474 480 }
475 -
476 - // Clean up backup after successful write
477 - // phpcs:ignore WordPress.WP.AlternativeFunctions.unlink_unlink
478 - unlink( $backup_path );
479 481
480 482 $this->invalidate_wpconfig_opcode_cache();
481 483
482 484 return true;