root/tags/1_0-rc2/index-install.php

Revision 623, 17.1 kB (checked in by donncha, 2 years ago)

Don't call index-install.php directly

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