Esempio n. 1
0
def clone_site(old_site, new_user, new_domain, db_conn):
    """
    Create a new WordPress website cloned from an existing site.

    Args:
        old_site - The domain name for the site to be cloned from
        new_user - The non-existing system user for the cloned site
        new_domain - The domain name for the cloned site
        db_conn - An open database connection with rights to create the database
            and user
    """
    php_version = php.get_site_version(old_site)
    old_user = php.user_from_domain(old_site)
    user.make_user(new_user)
    bind.make_zone(new_domain)
    bind.rebuild_zone_index()
    nginx.make_vhost(new_user, new_domain)
    for rule_id in nginx.get_bypassed_modsec_rules(old_site):
        nginx.bypass_modsec_rule(new_domain, rule_id)
    php.make_vhost(new_user, new_domain, php_version)
    db_name = new_user[:18]
    db_user = db_name
    db_pass = input_util.random_string(20, False)
    print("Setting db password to: " + db_pass)
    db.create_database_with_user(db_name, db_user, db_pass, db_conn)
    old_db_user, old_db, old_pass = get_db_info(old_user)
    db.clone(old_db, db_name, db_conn)
    old_dir = user.webroot(old_user)
    new_dir = user.webroot(new_user)
    print('Copying site files...')
    os.system("cp -a '" + old_dir + ".' '" + new_dir + "'")
    print('Copy complete, fixing permissions...')
    os.system("find '" + new_dir + "' -user '" + old_user + "' -exec chown '" +
              new_user + "' {} \;")
    os.system("find '" + new_dir + "' -group '" + old_user +
              "' -exec chgrp '" + new_user + "' {} \;")
    print('Permissions fixed')
    os.system("sed -i 's~" + old_dir + "~" + new_dir + "~g' " + new_dir +
              "wp-config.php")
    update_config(new_user, db_name, db_user, db_pass)
    os.system("sudo -u '" + new_user + "' -i wp search-replace --path='" +
              new_dir + "' '" + old_site + "' '" + new_domain + "'")
    os.system("sudo -u '" + new_user + "' -i wp cache flush --path='" +
              new_dir + "'")
    has_cert = cert_try_loop(new_domain, new_user)
    if has_cert:
        nginx.add_ssl_to_site_hosts(new_domain)
    return has_cert
Esempio n. 2
0
def get_version(domain):
    """
    Check the WordPress version for a domain

    Args:
        domain - The domain associated with the installation
    """
    sys_user = nginx.user_from_domain(domain)
    webroot = user.webroot(sys_user)
    return subprocess.getoutput('sudo -u "' + sys_user +
                                '" -i wp core version --path="' + webroot +
                                '"')
Esempio n. 3
0
def is_wordpress_installation(domain):
    """
    Check if a domain has a valid WordPress installation

    Args:
        domain - The domain associated with the installation
    """
    sys_user = nginx.user_from_domain(domain)
    webroot = user.webroot(sys_user)
    if os.path.exists(webroot + 'wp-content') and \
            os.path.exists(webroot + 'wp-includes') and \
            os.path.exists(webroot + 'wp-config.php'):
        return True
    return False
Esempio n. 4
0
def wp_cron_disabled(domain):
    """
    Check if a domain has it's built in cron disabled

    Args:
        domain - The domain associated with the installation
    """
    sys_user = nginx.user_from_domain(domain)
    webroot = user.webroot(sys_user)
    output = subprocess.getoutput('sudo -u "' + sys_user +
                                  '" -i wp config get --path="' + webroot +
                                  '" DISABLE_WP_CRON')
    output = output.lower()
    if output == 'true':
        return True
    return False
Esempio n. 5
0
def get_db_info(sys_user, webroot=False):
    """
    Get the database name, user and password for an existing WordPress
    installation.

    Args:
        sys_user - The system user that the WorpPress site is stored in
        webroot - (optional) the webroot for the WordPress installation
    """
    if webroot == False:
        webroot = user.webroot(sys_user)
    db_user = subprocess.getoutput('sudo -u "' + sys_user +
                                   '" -i wp config get --path="' + webroot +
                                   '" DB_USER')
    name = subprocess.getoutput('sudo -u "' + sys_user +
                                '" -i wp config get --path="' + webroot +
                                '" DB_NAME')
    password = subprocess.getoutput('sudo -u "' + sys_user +
                                    '" -i wp config get --path="' + webroot +
                                    '" DB_PASSWORD')
    return (name, db_user, password)