Make WordPress Core

Ticket #3090: index-install.php

File index-install.php, 17.8 KB (added by saurabh_reach121, 20 years ago)

this is the fixed file

Line 
1<?php
2// don't ever call this file directly!
3if( strpos( $_SERVER["REQUEST_URI"], 'index-install.php' ) ) {
4 header( "Location: index.php" );
5 die();
6}
7if( $_SERVER[ 'HTTP_HOST' ] == 'localhost' ) {
8 die( "<h2>Warning!</h2> Installing to http://localhost/ is not supported. Please use <a href='http://localhost.localdomain/'>http://localhost.localdomain/</a> instead." );
9}
10define('WP_INSTALLING', true);
11
12function printheader() {
13 print '
14<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
15<html xmlns="http://www.w3.org/1999/xhtml">
16<head>
17 <title>WordPress &rsaquo; Installation</title>
18 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
19 <style media="screen" type="text/css">
20 <!--
21 html {
22 background: #eee;
23 }
24 body {
25 background: #fff;
26 color: #000;
27 font-family: Georgia, "Times New Roman", Times, serif;
28 margin-left: 20%;
29 margin-right: 20%;
30 padding: .2em 2em;
31 }
32
33 h1, h2 {
34 color: #006;
35 font-size: 18px;
36 font-weight: lighter;
37 }
38
39 p, li, dt {
40 line-height: 140%;
41 padding-bottom: 2px;
42 }
43
44 ul, ol {
45 padding: 5px 5px 5px 20px;
46 }
47 #logo {
48 margin-bottom: 2em;
49 }
50.step a, .step input {
51 font-size: 2em;
52}
53.step, th {
54 text-align: right;
55}
56#footer {
57text-align: center; border-top: 1px solid #ccc; padding-top: 1em; font-style: italic;
58}
59.fakelink {
60 color: #00a;
61 text-decoration: underline;
62}
63 -->
64 </style>
65</head>
66<body>
67
68<h1><img src="wp-includes/images/wordpress-mu.png" alt="WordPress MU" /></h1>
69';
70}
71
72function check_writeable_dir( $dir, $ret ) {
73 if( is_writeable( $dir ) == false ) {
74 print $dir." : <b style='color: #f55'>FAILED</b><br />Quick Fix: <code>chmod 777 $dir</code><br />";
75 return false;
76 } else {
77 if( $ret == true ) {
78 return true;
79 } else {
80 return false;
81 }
82 }
83}
84
85function filestats( $err ) {
86 print "<h1>Server Summary</h1>";
87 print "<p>If you post a message to the MU support forum at <a target='_blank' href='http://mu.wordpress.org/forums/'>http://mu.wordpress.org/forums/</a> then copy and paste the following information into your message:</p>";
88
89 print "<blockquote style='background: #eee; border: 1px solid #333; padding: 5px;'>";
90 print "<br /><strong>ERROR: $err</strong></br >";
91 clearstatcache();
92 $files = array( "htaccess.dist", ".htaccess" );
93 while( list( $key, $val ) = each( $files ) ) {
94 $stats = @stat( $val );
95 if( $stats ) {
96 print "<h2>$val</h2>";
97 print "&nbsp;&nbsp;&nbsp;&nbsp;uid/gid: " . $stats[ 'uid' ] . "/" . $stats[ 'gid' ] . "<br />\n";
98 print "&nbsp;&nbsp;&nbsp;&nbsp;size: " . $stats[ 'size' ] . "<br />";
99 print "&nbsp;&nbsp;&nbsp;&nbsp;perms: " . substr( sprintf('%o', fileperms( $val ) ), -4 ) . "<br />";
100 print "&nbsp;&nbsp;&nbsp;&nbsp;readable: ";
101 print is_readable( $val ) == true ? "yes" : "no";
102 print "<br />";
103 print "&nbsp;&nbsp;&nbsp;&nbsp;writeable: ";
104 print is_writeable( $val ) == true ? "yes" : "no";
105 print "<br />";
106
107 } elseif( file_exists( $val ) == false ) {
108 print "<h2>$val</h2>";
109 print "&nbsp;&nbsp;&nbsp;&nbsp;FILE NOT FOUND: $val<br>";
110 }
111 }
112 print "</blockquote>";
113
114}
115
116function do_htaccess( $oldfilename, $newfilename, $base, $url )
117{
118 print "Im making htaccess";
119exit;
120 // remove ending slash from $base and $url
121 $htaccess = '';
122 if( substr($base, -1 ) == '/') {
123 $base = substr($base, 0, -1);
124 }
125
126 if( substr($url, -1 ) == '/') {
127 $url = substr($url, 0, -1);
128 }
129 $err = '';
130 if( is_file( $oldfilename ) ) {
131 $fp = @fopen( $oldfilename, "r" );
132 if( $fp ) {
133 while( !feof( $fp ) )
134 {
135 $htaccess .= fgets( $fp, 4096 );
136 }
137 fclose( $fp );
138 $htaccess = str_replace( "BASE", $base, $htaccess );
139 if( touch( $newfilename ) ) {
140 $fp = fopen( $newfilename, "w" );
141 if( $fp ) {
142 fwrite( $fp, $htaccess );
143 fclose( $fp );
144 } else {
145 $err = "could not open $newfilename for writing";
146 }
147 } else {
148 $err = "could not open $newfilename for writing";
149 }
150 } else {
151 $err = "could not open $oldfilename for reading";
152 }
153 } else {
154 $err = "$oldfilename not found";
155 }
156
157 if( $err != '' ) {
158 print "<h1>Warning!</h1>";
159 print "<p><strong>There was a problem creating the .htaccess file.</strong> </p>";
160 print "<p style='color: #900'>Error: ";
161 if( $err == "could not open $newfilename for writing" ) {
162 print "Could Not Write To $newfilename.";
163 } elseif( $err == "could not open $oldfilename for reading" ) {
164 print "I could not read from $oldfilename. ";
165 } elseif( $err == "$oldfilename not found" ) {
166 print "The file, $oldfilename, is missing.";
167 }
168 print "</p>";
169 filestats( $err );
170
171 print "<p>Please ensure that the webserver can write to this directory.</p>";
172 print "<p>If you use Cpanel then read <a href='http://mu.wordpress.org/forums/topic/99'>this post</a>. Cpanel creates files that I need to overwrite and you have to fix that.</p>";
173 print "<p>If all else fails then you'll have to create it by hand:";
174 print "<ul><li> Download htaccess.dist to your computer and open it in your favourite text editor.</li>
175 <li> Replace the following text:<ul><li>BASE by '$base'</li><li>HOST by '$url'</li></li>
176 <li> Rename htaccess.dist to .htaccess and upload it back to the same directory.</li></ul>";
177 die( "Installation Aborted!" );
178 }
179}
180
181function checkdirs() {
182 $ret = true;
183 $ret = check_writeable_dir( dirname(__FILE__), $ret );
184 $ret = check_writeable_dir( dirname(__FILE__) . "/wp-content/", $ret );
185
186 if( $ret == false )
187 {
188 print "<h2>Warning!</h2>";
189 print "<div style='border: 1px solid #ccc'>";
190 print "<p style='font-weight: bold; padding-left: 10px'>One or more of the above directories must be made writeable by the webserver.<br>";
191 print "Please <code>chmod 777 <q>directory-name</q></code> or <code>chown</code> that directory to the user the web server runs as (usually nobody, apache, or www-data)<br>";
192 print "Refresh this page when you're done!<br></p>";
193 print "</div>";
194 }
195 if( file_exists( "./.htaccess" ) && is_writeable( "./.htaccess" ) == false ) {
196 $ret = false;
197 print "<h2>Warning! .htaccess already exists.</h2>";
198 print "<div style='border: 1px solid #ccc'>";
199 print "<p style='font-weight: bold; padding-left: 10px'>A file with the name '.htaccess' already exists in this directory and I cannot write to it. Please ftp to the server and delete this file from this directory!<br />";
200 print "Offending file: " . realpath( '.htaccess' ) . "</p>";
201 print "</div>";
202 }
203
204
205 return $ret;
206}
207
208function step1() {
209 print "<h2>Installing WP&micro;</h2>";
210 $mod_rewrite_msg = "<p>If the <code>mod_rewrite</code> module is disabled ask your administrator to enable that module, or look at the <a href='http://httpd.apache.org/docs/mod/mod_rewrite.html'>Apache documentation</a> or <a href='http://www.google.com/search?q=apache+mod_rewrite'>elsewhere</a> for help setting it up.</p>";
211 if( function_exists( "apache_get_modules" ) ) {
212 $modules = apache_get_modules();
213 if( in_array( "mod_rewrite", $modules ) == false ) {
214 echo "<p><strong>Warning!</strong> It looks like mod_rewrite is not installed.</p>" . $mod_rewrite_msg;
215 }
216 } else {
217 ?><p>Please make sure <code>mod_rewrite</code> is installed as it will be activated at the end of this install.</p><?php
218 echo $mod_rewrite_msg;
219 }
220 if( checkdirs() == false ) {
221 return false;
222 }
223
224 // Create Blogs living area.
225 @mkdir( dirname(__FILE__) . "/wp-content/blogs.dir", 0777 );
226
227
228 $url = stripslashes( "http://".$_SERVER["SERVER_NAME"] . dirname( $_SERVER[ "SCRIPT_NAME" ] ) );
229 if( substr( $url, -1 ) == '/' )
230 $url = substr( $url, 0, -1 );
231 $base = stripslashes( dirname( $_SERVER["SCRIPT_NAME"] ) );
232 if( $base != "/")
233 {
234 $base .= "/";
235 }
236 $realpath = dirname(__FILE__);
237
238 return true;
239}
240
241function printstep1form( $dbname = 'wordpress', $uname = 'username', $pwd = 'password', $dbhost = 'localhost', $prefix = 'wp_' ) {
242 $weblog_title = 'My new WPMU Blog';
243 $email = '';
244 $hostname = str_replace( "www.", "", $_SERVER[ 'HTTP_HOST' ] );
245 print "
246 <form method='post' action='index.php'>
247 <input type='hidden' name='action' value='step2'>
248 <h2>Blog Addresses</h2>
249 <p>Please choose whether you would like blogs for the MU install to use sub-domains or sub-directories. You can not change this later. We recommend sub-domains.</p>
250 <p><label><input type='radio' name='vhost' value='yes' /> Sub-domains (like <code>blog1.example.com</code>)</label><br />
251 <label><input type='radio' name='vhost' value='no' /> Sub-directories (like <code>example.com/blog1</code></label></p>
252
253 <h2>Database</h2>
254
255 <p>Below you should enter your database connection details. If you're not sure about these, contact your host. </p>
256 <table cellpadding='5'>
257 <tr>
258 <th scope='row' width='33%'>Database Name</th>
259 <td><input name='dbname' type='text' size='45' value='$dbname' /></td>
260 </tr>
261 <tr>
262 <th scope='row'>User Name</th>
263 <td><input name='uname' type='text' size='45' value='$uname' /></td>
264 </tr>
265 <tr>
266 <th scope='row'>Password</th>
267 <td><input name='pwd' type='text' size='45' value='$pwd' /></td>
268 </tr>
269 <tr>
270 <th scope='row'>Database Host</th>
271 <td><input name='dbhost' type='text' size='45' value='$dbhost' /></td>
272 </tr>
273 </table>
274 <h2>Server Address</h2>
275 <p><label>What is the Internet address of your site? You should enter the shortest address possible. For example, use <em>example.com</em> instead of <em>www.example.com</em> but if you are going to use an address like <em>blogs.example.com</em> then enter that unaltered in the box above.<br /><b>Server Address:</b> <input type='text' name='basedomain' value='{$hostname}'></label></p>
276 <h2>Blog Details</h2>
277 <table width='100%'>
278 <tr>
279 <th scope='row'>Weblog&nbsp;Title</th>
280 <td><input name='weblog_title' type='text' size='45' value='".$weblog_title."' /></td>
281 <td>What would you like to call your weblog? </td>
282 </tr>
283 <tr>
284 <th scope='row'>Email</th>
285 <td><input name='email' type='text' size='45' value='".$email."' /></td>
286 <td>Your email address.</td>
287 </tr>
288 </table>
289 <p class='submit'><input name='submit' type='submit' value='Submit' /> </p>
290</form> ";
291}
292
293function step2() {
294 global $wpdb, $table_prefix, $base, $blog_id;
295 $dbname = $_POST['dbname'];
296 $uname = $_POST['uname'];
297 $passwrd = $_POST['pwd'];
298 $dbhost = $_POST['dbhost'];
299 $vhost = $_POST['vhost' ];
300 $prefix = 'wp_';
301 $base = stripslashes( dirname( $_SERVER["SCRIPT_NAME"] ) );
302 if( $base != "/") {
303 $base .= "/";
304 }
305
306 // Test the db connection.
307 define('DB_NAME', $dbname);
308 define('DB_USER', $uname);
309 define('DB_PASSWORD', $passwrd);
310 define('DB_HOST', $dbhost);
311
312 if (!file_exists('wp-config-sample.php'))
313 die('Sorry, I need a wp-config-sample.php file to work from. Please re-upload this file from your WordPress installation.');
314
315 $configFile = file('wp-config-sample.php');
316 // We'll fail here if the values are no good.
317 require_once('wp-includes/wp-db.php');
318 printheader();
319
320 print "Creating Database Config File: ";
321
322 $handle = fopen('wp-config.php', 'w');
323
324 foreach ($configFile as $line_num => $line) {
325 switch (trim( substr($line,0,16) )) {
326 case "define('DB_NAME'":
327 fwrite($handle, str_replace("wordpress", $dbname, $line));
328 break;
329 case "define('DB_USER'":
330 fwrite($handle, str_replace("'username'", "'$uname'", $line));
331 break;
332 case "define('DB_PASSW":
333 fwrite($handle, str_replace("'password'", "'$passwrd'", $line));
334 break;
335 case "define('DB_HOST'":
336 fwrite($handle, str_replace("localhost", $dbhost, $line));
337 break;
338 case "define('VHOST',":
339 fwrite($handle, str_replace("VHOSTSETTING", $vhost, $line));
340 break;
341 case '$table_prefix =':
342 fwrite($handle, str_replace('wp_', $prefix, $line));
343 break;
344 case '$base = \'BASE\';':
345 fwrite($handle, str_replace('BASE', $base, $line));
346 break;
347 default:
348 fwrite($handle, $line);
349 break;
350 }
351 }
352 fclose($handle);
353 chmod('wp-config.php', 0666);
354 print "<b style='color: #00aa00; font-weight: bold'>DONE</b><br />";
355}
356
357function printuserdetailsform( $weblog_title = 'My new Blog', $username = '', $email = '' ) {
358 $hostname = str_replace( "www.", "", $_SERVER[ 'HTTP_HOST' ] );
359 print "
360 <form method='post' action='index.php'>
361 <input type='hidden' name='action' value='step3'>
362 <p>To finish setting up your blog, please fill in the following form and click <q>Submit</q>.</p>
363 <input name='submit' type='submit' value='Submit' />
364 </form>
365 <br />
366 You will be sent an email with your password and login links and details.";
367}
368
369function step3() {
370 global $wpdb, $current_site;
371 $base = stripslashes( dirname( $_SERVER["SCRIPT_NAME"] ) );
372 if( $base != "/") {
373 $base .= "/";
374 }
375 $domain = $wpdb->escape( $_POST[ 'basedomain' ] );
376 if( substr( $domain, 0, 4 ) == 'www.' )
377 $domain = substr( $domain, 4 );
378
379 $email = $wpdb->escape( $_POST[ 'email' ] );
380 $weblog_title = $wpdb->escape( $_POST[ 'weblog_title' ] );
381
382 // set up site tables
383 $wpdb->query( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'admin_email', '".$email."')" );
384 $wpdb->query( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'admin_user_id', '1')" );
385 $wpdb->query( "INSERT INTO ".$wpdb->site." ( id, domain, path ) VALUES ( NULL, '$domain', '$base' )" );
386 $wpdb->query( "INSERT INTO " . $wpdb->sitecategories . " VALUES (1, 'Uncategorized', 'uncategorized', NOW())" );
387 $wpdb->query( "INSERT INTO " . $wpdb->sitecategories . " VALUES (2, 'Blogroll', 'blogroll', NOW())" );
388 $wpdb->query( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'upload_filetypes', 'jpg jpeg png gif mp3 mov avi wmv midi mid pdf' )" );
389 $wpdb->query( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'blog_upload_space', '10' )" );
390 $wpdb->query( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'fileupload_maxk', '1500' )" );
391 $wpdb->query( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'site_admins', '" . serialize( array( 'admin' ) ) . "' )" );
392 $wpdb->query( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'allowed_themes', '" . serialize( array( 'WordPress Classic', 'WordPress Default' ) ) . "' )" );
393 $wpdb->query( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'illegal_names', '" . serialize( array( "www", "web", "root", "admin", "main", "invite", "administrator" ) ) . "' )" );
394 $wpdb->query( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'welcome_email', 'Dear User,
395
396Your new SITE_NAME blog has been successfully set up at:
397BLOG_URL
398
399You can log in to the administrator account with the following information:
400 Username: USERNAME
401 Password: PASSWORD
402Login Here: BLOG_URLwp-login.php
403
404We hope you enjoy your new weblog.
405 Thanks!
406
407--The Team @ SITE_NAME')" );
408 $wpdb->query( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'first_post', 'Welcome to <a href=\"SITE_URL\">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!' )" );
409
410 $pass = substr( md5( rand() ), 5, 12 );
411 $user_id = wpmu_create_user( 'admin', $pass, $email);
412
413 $current_site->domain = $domain;
414 $current_site->path = $base;
415 $current_site->site_name = ucfirst( $domain );
416
417 wpmu_create_blog( $domain, $base, $weblog_title, $user_id, array() );
418 update_blog_option( 1, 'template', 'home');
419 update_blog_option( 1, 'stylesheet', 'home');
420 update_blog_option( 1, 'permalink_structure', '/blog/%year%/%monthnum%/%day%/%postname%/');
421 update_blog_option( 1, 'rewrite_rules', '');
422 $msg = "Your new WPMU site has been created at\nhttp://{$domain}{$base}\n\nLogin details:\nUsername: admin\nPassword: $pass\nLogin: http://{$domain}{$base}wp-login.php\n";
423 wp_mail( $email, "Your new WPMU site is ready!", $msg, "From: wordpress@" . $_SERVER[ 'HTTP_HOST' ] );
424 print "<p>Congrats! Your <a href='http://{$domain}{$base}'>WPMU site</a> has been set up and you have been sent details of your login and password in an email.</p>";
425}
426
427switch( $_POST[ 'action' ] ) {
428 case "step2":
429 // get blog username
430 // create wp-config.php
431 step2();
432 // Install Blog!
433 include_once('./wp-config.php');
434 include_once('./wp-admin/upgrade-functions.php');
435 make_db_current_silent();
436 populate_options();
437 do_htaccess( 'htaccess.dist', '.htaccess', $base, $url);
438 step3();
439 break;
440 case "step3":
441 // call createBlog();
442 // create .htaccess
443 // print login info and links.
444 require_once('./wp-config.php');
445 require_once('./wp-admin/upgrade-functions.php');
446 make_db_current_silent();
447 populate_options();
448 do_htaccess( 'htaccess.dist', '.htaccess', $base, $url);
449 printheader();
450 step3();
451 break;
452 default:
453 // check that directories are writeable.
454 // create wpmu-settings.php
455 // get db auth info.
456 printheader();
457 if( step1() ) {
458 printstep1form();
459 }
460 break;
461}
462?>
463<br /><br />
464<div align='center'>
465<a href="http://mu.wordpress.org/">WordPress &micro;</a> | <a href="http://mu.wordpress.org/forums/">Support Forums</a>
466</div>
467</body>
468</html>