]> scripts.mit.edu Git - wizard.git/commitdiff
Admin username and password support for Wordpress
authorIan Smith <ismith@mit.edu>
Tue, 29 Dec 2009 02:07:21 +0000 (21:07 -0500)
committerEdward Z. Yang <ezyang@mit.edu>
Tue, 29 Dec 2009 03:07:06 +0000 (22:07 -0500)
* Installer now prompts for admin name and password
* Initial temporary password email suppressed
* You are using default password nag suppressed

Signed-off-by: Ian Smith <ismith@mit.edu>
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
TODO
wizard/app/wordpress.py

diff --git a/TODO b/TODO
index 0bf1865e65ccee23416ab9f8908d74a6280757fc..939bb38c64e6d9fdd7e46de0cf9f8d10e9232a94 100644 (file)
--- a/TODO
+++ b/TODO
@@ -13,10 +13,6 @@ TODO NOW:
   get marked as conflicted.  Maybe we should say for certain files "if they're
   gone, they're gone forever"?  What is the proper resolution?
 
-- wizard install wordpress should ask for password.  One problem with this is that
-  Wordpress will still send mail with the wrong username and password, so Wordpress
-  will need to be patched to not do that.  Alternatively we can initally set the admin
-  email to a null address and then fix it manually.
 - Parse output HTML for class="error" and give those errors back to the user (done),
   then boot them back into configure so they can enter in something different
 
index c7590743074caeec1ae8266d7e1e1012d33d9d0d..62a41389b30d037b075bed11c29a603b45990097 100644 (file)
@@ -3,6 +3,7 @@ import re
 import logging
 import distutils
 import urlparse
+import hashlib
 
 from wizard import app, install, resolve, sql, util
 from wizard.app import php
@@ -31,7 +32,7 @@ class Application(app.Application):
     extractors.update(php.extractors)
     substitutions = app.make_substitutions(seed)
     substitutions.update(php.substitutions)
-    install_schema = install.ArgSchema("db", "email", "title")
+    install_schema = install.ArgSchema("db", "admin", "email", "title")
     deprecated_keys = set(['WIZARD_SECRETKEY'])
     random_keys = set(['WIZARD_SECRETKEY', 'WIZARD_AUTH_KEY', 'WIZARD_SECURE_AUTH_KEY', 'WIZARD_LOGGED_IN_KEY', 'WIZARD_NONCE_KEY'])
     def download(self, version):
@@ -68,6 +69,16 @@ class Application(app.Application):
                 }
         old_mode = os.stat(".").st_mode
         os.chmod(".", 0777) # XXX: squick squick
+
+        # we need to disable the wp_mail function in wp-includes/pluggable[-functions].php
+        pluggable_path = os.path.exists('wp-includes/pluggable.php') and 'wp-includes/pluggable.php' or 'wp-includes/pluggable-functions.php'
+        pluggable = open(pluggable_path, 'r').read()
+        wp_mail_noop = "<?php function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) { /*noop*/ } ?> \n\n"
+        pluggable_file = open(pluggable_path,'w')
+        pluggable_file.write(wp_mail_noop)
+        pluggable_file.write(pluggable)
+        pluggable_file.close()
+
         result = install.fetch(options, "wp-admin/setup-config.php?step=2", post_setup_config)
         logging.debug("setup-config.php output\n\n" + result)
         result = install.fetch(options, "wp-admin/install.php?step=2", post_install)
@@ -82,6 +93,18 @@ class Application(app.Application):
         wp_options.update().where(wp_options.c.option_name == 'siteurl').values(option_value=options.web_path).execute()
         wp_options.update().where(wp_options.c.option_name == 'home').values(option_value="http://%s%s" % (options.web_host, options.web_path)).execute() # XXX: what if missing leading slash; this should be put in a function
         # should also set the username and admin password
+
+        wp_users = meta.tables["wp_users"]
+        hashed_pass = hashlib.md5(options.admin_password).hexdigest()
+        wp_users.update().where(wp_users.c.ID == 1).values(user_login=options.admin_name,user_nicename=options.admin_name,display_name=options.admin_name,user_pass=hashed_pass).execute()
+        wp_usermeta = meta.tables["wp_usermeta"]
+        wp_usermeta.delete().where(wp_usermeta.c.user_id==1 and wp_usermeta.c.meta_key == "default_password_nag").execute()
+
+        # now we can restore the wp_mail function in wp-includes/pluggable[-functions].php
+        pluggable_file = open(pluggable_path,'w')
+        pluggable_file.write(pluggable)
+        pluggable_file.close()
+
         php.ini_replace_vars()
     def upgrade(self, d, version, options):
         result = d.fetch("wp-admin/upgrade.php?step=1")