@@ -74,30 +74,57 @@ public function install(array $options = null)
7474 parent ::setup ($ options );
7575
7676 $ this ->appcontext ->runUser ('v-open-fs-file ' , [$ this ->getDocRoot ("wp-config-sample.php " )], $ result );
77- $ distconfig = preg_replace (
78- [
79- '/database_name_here/ ' , '/username_here/ ' , '/password_here/ ' , '/utf8/ ' , '/wp_/ '
80- ],
81- [
82- $ this ->appcontext ->user () . '_ ' . $ options ['database_name ' ],
83- $ this ->appcontext ->user () . '_ ' . $ options ['database_user ' ],
84- $ options ['database_password ' ],
85- 'utf8mb4 ' ,
86- Util::generate_string (3 , false ).'_ '
87- ],
88- $ result ->text
89- );
90-
91- while (strpos ($ distconfig , 'put your unique phrase here ' ) !== false ) {
92- $ distconfig = preg_replace ('/put your unique phrase here/ ' , Util::generate_string (64 ), $ distconfig , 1 );
77+ foreach ($ result -> raw as $ line_num => $ line ){
78+ if ( '$table_prefix = ' === substr ( $ line , 0 , 15 ) ) {
79+ $ result -> raw [ $ line_num ] = '$table_prefix = \'' . addcslashes ( Util::generate_string (5 , false ).'_ ' , "\\' " ) . "'; \r\n" ;
80+ continue ;
81+ }
82+ if ( ! preg_match ( '/^define\(\s* \'([A-Z_]+) \',([ ]+)/ ' , $ line , $ match ) ) {
83+ continue ;
84+ }
85+ $ constant = $ match [1 ];
86+ $ padding = $ match [2 ];
87+ switch ( $ constant ) {
88+ case 'DB_NAME ' :
89+ $ result -> raw [ $ line_num ] = "define( ' " . $ constant . "', " . $ padding . "' " . addcslashes ($ this ->appcontext ->user () . '_ ' . $ options ['database_name ' ], "\\' " ) . "' ); " ;
90+ break ;
91+ case 'DB_USER ' :
92+ $ result -> raw [ $ line_num ] = "define( ' " . $ constant . "', " . $ padding . "' " . addcslashes ($ this ->appcontext ->user () . '_ ' . $ options ['database_user ' ], "\\' " ) . "' ); " ;
93+ break ;
94+ case 'DB_PASSWORD ' :
95+ $ result -> raw [ $ line_num ] = "define( ' " . $ constant . "', " . $ padding . "' " . addcslashes ($ options ['database_password ' ], "\\' " ) . "' ); " ;
96+ break ;
97+ case 'DB_HOST ' :
98+ $ result -> raw [ $ line_num ] = "define( ' " . $ constant . "', " . $ padding . "' " . addcslashes ('localhost ' , "\\' " ) . "' ); " ;
99+ break ;
100+ case 'DB_CHARSET ' :
101+ $ result -> raw [ $ line_num ] = "define( ' " . $ constant . "', " . $ padding . "' " . addcslashes ('utf8mb4 ' , "\\' " ) . "' ); " ;
102+ break ;
103+ case 'AUTH_KEY ' :
104+ case 'SECURE_AUTH_KEY ' :
105+ case 'LOGGED_IN_KEY ' :
106+ case 'NONCE_KEY ' :
107+ case 'AUTH_SALT ' :
108+ case 'SECURE_AUTH_SALT ' :
109+ case 'LOGGED_IN_SALT ' :
110+ case 'NONCE_SALT ' :
111+ $ result -> raw [ $ line_num ] = "define( ' " . $ constant . "', " . $ padding . "' " . Util::generate_string (64 ) . "' ); " ;
112+ break ;
113+ }
93114 }
94-
95- $ tmp_configpath = $ this ->saveTempFile ($ distconfig );
115+
116+ $ tmp_configpath = $ this ->saveTempFile (implode ( "\r\n" , $ result -> raw ) );
96117
97118 if (!$ this ->appcontext ->runUser ('v-move-fs-file ' , [$ tmp_configpath , $ this ->getDocRoot ("wp-config.php " )], $ result )) {
98119 throw new \Exception ("Error installing config file in: " . $ tmp_configpath . " to: " . $ this ->getDocRoot ("wp-config.php " ) . $ result ->text );
99120 }
100121
122+ $ this ->appcontext ->downloadUrl ('https://raw.githubusercontent.com/roots/wp-password-bcrypt/master/wp-password-bcrypt.php ' , null , $ plugin_output );
123+ $ this ->appcontext ->runUser ('v-add-fs-directory ' , [$ this ->getDocRoot ("wp-content/mu-plugins/ " )], $ result );
124+ if (!$ this ->appcontext ->runUser ('v-copy-fs-file ' , [$ plugin_output ->file , $ this ->getDocRoot ("wp-content/mu-plugins/wp-password-bcrypt.php " )], $ result )) {
125+ throw new \Exception ("Error installing wp-password-bcrypt file in: " . $ plugin_output ->file . " to: " . $ this ->getDocRoot ("wp-content/mu-plugins/wp-password-bcrypt.php " ) . $ result ->text );
126+ }
127+
101128 $ this ->appcontext ->run ('v-list-web-domain ' , [$ this ->appcontext ->user (), $ this ->domain , 'json ' ], $ status );
102129 $ sslEnabled = ($ status ->json [$ this ->domain ]['SSL ' ] == 'no ' ? 0 : 1 );
103130 $ webDomain = ($ sslEnabled ? "https:// " : "http:// " ) . $ this ->domain . "/ " ;
0 commit comments