Created
October 29, 2017 12:17
-
-
Save neuberoliveira/ae41da64488f6cebebd8ffdd0e0d148a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import re | |
import random | |
import subprocess | |
def generateSalt(size): | |
ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
chars=[] | |
for i in range(size): | |
chars.append(random.choice(ALPHABET)) | |
return "".join(chars) | |
SALT_SIZE = 64 | |
wpzipfle = "wordpress.zip" | |
db_host = "" | |
db_database = "" | |
db_user = "" | |
db_pass = "" | |
db_host = raw_input("Database Host (default to localhost): ") | |
while db_database=="" : | |
db_database = raw_input("Database Name: ") | |
while db_user=="" : | |
db_user = raw_input("Database User: ") | |
while db_pass=="" : | |
db_pass = raw_input("Database Password: ") | |
if db_host=="" : | |
db_host = "localhost" | |
#curl add options JO to save the file with the file name from server | |
subprocess.call(['curl', '-L' , 'https://wordpress.org/latest.zip', '-o', wpzipfle]) | |
subprocess.call(['unzip', '-q', wpzipfle]) | |
subprocess.call(['rm', wpzipfle]) | |
configSample = open("wordpress/wp-config-sample.php") | |
config = configSample.read() | |
configSample.close(); | |
configMap = { | |
'DB_NAME': db_database, | |
'DB_USER': db_user, | |
'DB_PASSWORD': db_pass, | |
'DB_HOST': db_host, | |
'AUTH_KEY': generateSalt(SALT_SIZE), | |
'SECURE_AUTH_KEY': generateSalt(SALT_SIZE), | |
'LOGGED_IN_KEY': generateSalt(SALT_SIZE), | |
'NONCE_KEY': generateSalt(SALT_SIZE), | |
'AUTH_SALT': generateSalt(SALT_SIZE), | |
'SECURE_AUTH_SALT': generateSalt(SALT_SIZE), | |
'LOGGED_IN_SALT': generateSalt(SALT_SIZE), | |
'NONCE_SALT': generateSalt(SALT_SIZE), | |
} | |
db_defines = re.finditer("define\('("+('|'.join(configMap.keys()))+")',(\s|\t)+'([ a-z_]*)'\)", config) | |
for deff in db_defines: | |
oldDeff = deff.group(0) | |
newDeff = oldDeff.replace(deff.group(3), configMap[deff.group(1)]) | |
config = config.replace(oldDeff, newDeff) | |
configFinal = open('wordpress/wp-config.php', 'w+') | |
configFinal.write(config) | |
configFinal.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment