]> scripts.mit.edu Git - wizard.git/commitdiff
Handle Wordpress random keys correctly on install and upgrade.
authorEdward Z. Yang <ezyang@mit.edu>
Sun, 28 Mar 2010 23:58:25 +0000 (19:58 -0400)
committerEdward Z. Yang <ezyang@mit.edu>
Sun, 28 Mar 2010 23:58:25 +0000 (19:58 -0400)
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
doc/module/wizard.util.rst
wizard/app/__init__.py
wizard/app/wordpress.py
wizard/util.py

index cba7f347791bbd7796d5625af700a811bb3e36a2..c20430b7e51985f262558e4f3985e5e08d7822ba 100644 (file)
@@ -33,6 +33,7 @@ Functions
 .. autofunction:: soft_unlink
 .. autofunction:: fetch
 .. autofunction:: mixed_newlines
+.. autofunction:: random_key
 
 Exceptions
 ----------
index f4b53a32dc2a02ce1c6926b5af31806264b8f146..a3664dba694ec340bd6334185875eb899e178cfa 100644 (file)
@@ -41,7 +41,6 @@ import logging
 import shutil
 import sqlalchemy
 import sqlalchemy.exc
-import random
 import string
 import urlparse
 import tempfile
@@ -115,6 +114,9 @@ class Application(object):
     deprecated_keys = set()
     #: Keys that we can simply generate random strings for if they're missing
     random_keys = set()
+    #: Values that are not sufficiently random for a random key.  This can
+    #: include default values for a random configuration option,
+    random_blacklist = set()
     #: Dictionary of variable names to extractor functions.  These functions
     #: take a :class:`wizard.deploy.Deployment` as an argument and return the value of
     #: the variable, or ``None`` if it could not be found.
@@ -173,8 +175,8 @@ class Application(object):
             result[k] = extractor(deployment)
         # XXX: ugh... we have to do quoting
         for k in self.random_keys:
-            if result[k] is None:
-                result[k] = "'%s'" % ''.join(random.choice(string.letters + string.digits) for i in xrange(30))
+            if result[k] is None or result[k] in self.random_blacklist:
+                result[k] = "'%s'" % util.random_key()
         return result
     def dsn(self, deployment):
         """
@@ -259,6 +261,9 @@ class Application(object):
         :attr:`parametrized_files` and a simple search and replace on those
         files.
         """
+        # deployment is not used in this implementation, but note that
+        # we do have the invariant the current directory matches
+        # deployment's directory
         variables = ref_deployment.extract()
         for file in self.parametrized_files:
             try:
index bd82ee1fa4a12a6595c593f91ab2c55d1ecc03c0..bdcf25d1c9fa5357e83aedcbff6dd44051f47059 100644 (file)
@@ -36,6 +36,7 @@ class Application(app.Application):
     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'])
+    random_blacklist = set(['put your unique phrase here'])
     def urlFromExtract(self, deployment):
         try:
             meta = sql.connect(deployment.dsn)
@@ -117,6 +118,16 @@ class Application(app.Application):
         pluggable_file.write(pluggable)
         pluggable_file.close()
 
+        # replace random variable stubs with real values
+        old_config = open('wp-config.php').read()
+        def replace_with_random(s):
+            return s.replace('put your unique phrase here', util.random_key(), 1)
+        config = replace_with_random(old_config)
+        while config != old_config:
+            old_config = config
+            config = replace_with_random(config)
+        open('wp-config.php', 'w').write(config)
+
         php.ini_replace_vars()
     def upgrade(self, d, version, options):
         result = d.fetch("wp-admin/upgrade.php?step=1")
index 1c884035af4e04562488301e75d164fa6cd9e848..6c9764d317d88d4dd8f6f05b4546d91778665ec4 100644 (file)
@@ -19,6 +19,8 @@ import httplib
 import urllib
 import time
 import logging
+import random
+import string
 
 import wizard
 
@@ -372,6 +374,10 @@ def mixed_newlines(filename):
     f.close() # just to be safe
     return ret
 
+def random_key(length=30):
+    """Generates a random alphanumeric key of ``length`` size."""
+    return ''.join(random.choice(string.letters + string.digits) for i in xrange(length))
+
 class NoOperatorInfo(wizard.Error):
     """No information could be found about the operator from Kerberos."""
     pass