X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/7f1521bf193b382565eb753043c161f4cb3fcda7..HEAD:/wp-admin/setup-config.php diff --git a/wp-admin/setup-config.php b/wp-admin/setup-config.php index 34e19c76..1404c325 100644 --- a/wp-admin/setup-config.php +++ b/wp-admin/setup-config.php @@ -5,8 +5,6 @@ * The permissions for the base directory must allow for writing files in order * for the wp-config.php to be created using this page. * - * @internal This file must be parsable by PHP4. - * * @package WordPress * @subpackage Administration */ @@ -28,7 +26,9 @@ define('WP_SETUP_CONFIG', true); */ error_reporting(0); -define( 'ABSPATH', dirname( dirname( __FILE__ ) ) . '/' ); +if ( ! defined( 'ABSPATH' ) ) { + define( 'ABSPATH', dirname( dirname( __FILE__ ) ) . '/' ); +} require( ABSPATH . 'wp-settings.php' ); @@ -46,15 +46,26 @@ if ( file_exists( ABSPATH . 'wp-config-sample.php' ) ) elseif ( file_exists( dirname( ABSPATH ) . '/wp-config-sample.php' ) ) $config_file = file( dirname( ABSPATH ) . '/wp-config-sample.php' ); else - wp_die( __( 'Sorry, I need a wp-config-sample.php file to work from. Please re-upload this file from your WordPress installation.' ) ); + wp_die( __( 'Sorry, I need a wp-config-sample.php file to work from. Please re-upload this file to your WordPress installation.' ) ); // Check if wp-config.php has been created if ( file_exists( ABSPATH . 'wp-config.php' ) ) - wp_die( '

' . sprintf( __( "The file 'wp-config.php' already exists. If you need to reset any of the configuration items in this file, please delete it first. You may try installing now." ), 'install.php' ) . '

' ); + wp_die( '

' . sprintf( + /* translators: %s: install.php */ + __( "The file 'wp-config.php' already exists. If you need to reset any of the configuration items in this file, please delete it first. You may try installing now." ), + 'install.php' + ) . '

' + ); // Check if wp-config.php exists above the root directory but is not part of another install -if ( file_exists(ABSPATH . '../wp-config.php' ) && ! file_exists( ABSPATH . '../wp-settings.php' ) ) - wp_die( '

' . sprintf( __( "The file 'wp-config.php' already exists one level above your WordPress installation. If you need to reset any of the configuration items in this file, please delete it first. You may try installing now."), 'install.php' ) . '

' ); +if ( @file_exists( ABSPATH . '../wp-config.php' ) && ! @file_exists( ABSPATH . '../wp-settings.php' ) ) { + wp_die( '

' . sprintf( + /* translators: %s: install.php */ + __( "The file 'wp-config.php' already exists one level above your WordPress installation. If you need to reset any of the configuration items in this file, please delete it first. You may try installing now." ), + 'install.php' + ) . '

' + ); +} $step = isset( $_GET['step'] ) ? (int) $_GET['step'] : -1; @@ -63,9 +74,13 @@ $step = isset( $_GET['step'] ) ? (int) $_GET['step'] : -1; * * @ignore * @since 2.3.0 + * + * @global string $wp_local_package + * @global WP_Locale $wp_locale + * + * @param string|array $body_classes */ function setup_config_display_header( $body_classes = array() ) { - global $wp_version; $body_classes = (array) $body_classes; $body_classes[] = 'wp-core-ui'; if ( is_rtl() ) { @@ -79,11 +94,12 @@ function setup_config_display_header( $body_classes = array() ) { + <?php _e( 'WordPress › Setup Configuration File' ); ?> -

+ Select a default language'; echo '
'; wp_install_language_form( $languages ); echo '
'; @@ -124,7 +141,7 @@ switch($step) { $step_1 .= '&language=' . $loaded_language; } ?> - +

  1. @@ -133,12 +150,26 @@ switch($step) {
-

- wp-config.php file.' ); ?> - wp-config-sample.php in a text editor, fill in your information, and save it as wp-config.php." ); ?> - We got it." ); ?> -

-

+

wp-config.php' + ); + ?> + wp-config-sample.php', + 'wp-config.php' + ); + ?> + We got it.' ), + __( 'https://codex.wordpress.org/Editing_wp-config.php' ) + ); +?>

+

+

-

+

- + - + - + - + - + @@ -241,26 +276,44 @@ switch($step) { if ( ! empty( $wpdb->error ) ) wp_die( $wpdb->error->get_error_message() . $tryagain_link ); - // Fetch or generate keys and salts. - $no_api = isset( $_POST['noapi'] ); - if ( ! $no_api ) { - $secret_keys = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' ); + $wpdb->query( "SELECT $prefix" ); + if ( ! $wpdb->last_error ) { + // MySQL was able to parse the prefix as a value, which we don't want. Bail. + wp_die( __( 'ERROR: "Table Prefix" is invalid.' ) ); } - if ( $no_api || is_wp_error( $secret_keys ) ) { - $secret_keys = array(); + // Generate keys and salts using secure CSPRNG; fallback to API if enabled; further fallback to original wp_generate_password(). + try { + $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_ []{}<>~`+=,.;:/?|'; + $max = strlen($chars) - 1; for ( $i = 0; $i < 8; $i++ ) { - $secret_keys[] = wp_generate_password( 64, true, true ); + $key = ''; + for ( $j = 0; $j < 64; $j++ ) { + $key .= substr( $chars, random_int( 0, $max ), 1 ); + } + $secret_keys[] = $key; } - } else { - $secret_keys = explode( "\n", wp_remote_retrieve_body( $secret_keys ) ); - foreach ( $secret_keys as $k => $v ) { - $secret_keys[$k] = substr( $v, 28, 64 ); + } catch ( Exception $ex ) { + $no_api = isset( $_POST['noapi'] ); + + if ( ! $no_api ) { + $secret_keys = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' ); + } + + if ( $no_api || is_wp_error( $secret_keys ) ) { + $secret_keys = array(); + for ( $i = 0; $i < 8; $i++ ) { + $secret_keys[] = wp_generate_password( 64, true, true ); + } + } else { + $secret_keys = explode( "\n", wp_remote_retrieve_body( $secret_keys ) ); + foreach ( $secret_keys as $k => $v ) { + $secret_keys[$k] = substr( $v, 28, 64 ); + } } } $key = 0; - // Not a PHP5-style by-reference foreach, as this file must be parseable by PHP4. foreach ( $config_file as $line_num => $line ) { if ( '$table_prefix =' == substr( $line, 0, 16 ) ) { $config_file[ $line_num ] = '$table_prefix = \'' . addcslashes( $prefix, "\\'" ) . "';\r\n"; @@ -302,10 +355,16 @@ switch($step) { if ( ! is_writable(ABSPATH) ) : setup_config_display_header(); ?> -

wp-config.php file." ); ?>

-

wp-config.php manually and paste the following text into it.' ); ?>

+

wp-config.php' ); +?>

+

wp-config.php' ); +?>

@@ -332,14 +391,15 @@ if ( ! /iPad|iPod|iPhone/.test( navigator.userAgent ) ) { $path_to_wp_config = dirname( ABSPATH ) . '/wp-config.php'; $handle = fopen( $path_to_wp_config, 'w' ); - foreach( $config_file as $line ) { + foreach ( $config_file as $line ) { fwrite( $handle, $line ); } fclose( $handle ); chmod( $path_to_wp_config, 0666 ); setup_config_display_header(); ?> -

+

+

localhost does not work.' ); ?>localhost' ); + ?>