<?php
/*
Template Name: WP Config Generator
*/
// Why does WP make this difficult >.<
if (strpos($_SERVER['REQUEST_URI'], '?source') !== false)
{
    
highlight_file(__FILE__);
    exit;
}

$wp_config "<?php

/**
 * The base configurations of the WordPress.
 *
 * This file has the following configurations: MySQL settings, Table Prefix,
 * Secret Keys, WordPress Language, and ABSPATH. You can find more information
 * by visiting {@link http://codex.wordpress.org/Editing_wp-config.php Editing
 * wp-config.php} Codex page. You can get the MySQL settings from your web host.
 *
 * This file is used by the wp-config.php creation script during the
 * installation. You don't have to use the web site, you can just copy this file
 * to \"wp-config.php\" and fill in the values.
 *
 * @package WordPress
 */

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', '##dbname##');

/** MySQL database username */
define('DB_USER', '##dbuser##');

/** MySQL database password */
define('DB_PASSWORD', '##dbpass##');

/** MySQL hostname */
define('DB_HOST', '##dbhost##');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

/**#@+
 * Authentication Unique Keys and Salts.
 *
 * Change these to different unique phrases!
 * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
 * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
 *
 * @since 2.6.0
 */
##key_defines##

/**#@-*/

/**
 * WordPress Database Table prefix.
 *
 * You can have multiple installations in one database if you give each a unique
 * prefix. Only numbers, letters, and underscores please!
 */
\$table_prefix  = '##tableprefix##';

/**
 * WordPress Localized Language, defaults to English. 
 *
 * Change this to localize WordPress. A corresponding MO file for the chosen
 * language must be installed to wp-content/languages. For example, install
 * de_DE.mo to wp-content/languages and set WPLANG to 'de_DE' to enable German
 * language support.
 */
define('WPLANG', '');

/**
 * For developers: WordPress debugging mode.
 *
 * Change this to true to enable the display of notices during development.
 * It is strongly recommended that plugin and theme developers use WP_DEBUG
 * in their development environments.
 */
define('WP_DEBUG', false);

/* That's all, stop editing! Happy blogging. */

/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
    define('ABSPATH', dirname(__FILE__) . '/');

/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');"
;

// ############################################################################

$errors = array();
$result '';

if (
filter_input(INPUT_POST'submitted') == 1)
{
    
$dbhost filter_input(INPUT_POST'dbhost'FILTER_SANITIZE_URL);
    
$dbhost = (empty($dbhost)) ? 'localhost' $dbhost;

    
$dbuser filter_input(INPUT_POST'dbuser'FILTER_SANITIZE_STRING);

    if (empty(
$dbuser))
    {
        
$errors[] = 'no database username entered';
    }

    
$dbpass filter_input(INPUT_POST'dbpass'FILTER_SANITIZE_STRING);

    if (empty(
$dbpass))
    {
        
$errors[] = 'no database password entered';
    }

    
$dbname filter_input(INPUT_POST'dbname'FILTER_SANITIZE_STRING);

    if (empty(
$dbname))
    {
        
$errors[] = 'database name can not be left empty';
    }

    
$tableprefix filter_input(INPUT_POST'tableprefix'FILTER_SANITIZE_STRING);
    
$tableprefix = (empty($tableprefix)) ? 'wp_' $tableprefix;

    if (
count($errors) > 0)
    {
        
$result .= "One or more errors occurred:<br />\n<ul>\n";

        foreach (
$errors AS $error)
        {
            
$result .= "\t<li>$error</li>\n";
        }

        
$result .= "</ul>\n";
    }
    else
    {
        
$ch curl_init('https://api.wordpress.org/secret-key/1.1/salt/');
        
curl_setopt_array($ch, array(
            
CURLOPT_HEADER         => false,
            
CURLOPT_RETURNTRANSFER => true,
            
CURLOPT_SSL_VERIFYHOST => 2,
            
CURLOPT_SSL_VERIFYPEER => false
        
));
        
$key_defines curl_exec($ch);
        
curl_close($ch);

        if (empty(
$key_defines))
        {
            
$key_defines "
define('AUTH_KEY',         'put your unique phrase here');
define('SECURE_AUTH_KEY',  'put your unique phrase here');
define('LOGGED_IN_KEY',    'put your unique phrase here');
define('NONCE_KEY',        'put your unique phrase here');
define('AUTH_SALT',        'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT',   'put your unique phrase here');
define('NONCE_SALT',       'put your unique phrase here');
"
;
        }

        
$key_defines trim($key_defines);

        
$wp_config str_replace(
            array(
                
'##dbhost##',
                
'##dbname##',
                
'##dbuser##',
                
'##dbpass##',
                
'##tableprefix##',
                
'##key_defines##'
            
),
            array(
                
$dbhost,
                
$dbname,
                
$dbuser,
                
$dbpass,
                
$tableprefix,
                
$key_defines
            
),
            
$wp_config
        
);

        
header("Pragma: public");
        
header("Expires: 0");
        
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        
header("Cache-Control: private"false);
        
header("Content-Type: text/php; name=\"wp-config.php\";");
        
header("Content-Disposition: attachment; filename=\"wp-config.php\";" );
        
header("Content-Transfer-Encoding: 8bit");
        
header("Content-Length: " strlen($wp_config));
        echo 
$wp_config;
        exit;
    }
}

//
get_header();

?>
<div id="primary" class="content-area">

    <main id="main" class="site-main" role="main">
        <?php
        
/**
         * The template used for displaying page content in page.php
         *
         * @package sparkling
         */
        
?>

        <?php
        
if ( is_page_template'page-fullwidth.php' ) ) {
            
the_post_thumbnail'sparkling-featured-fullwidth', array(
                
'class' => 'single-featured',
            ) );
        } else {    
the_post_thumbnail'sparkling-featured', array(
            
'class' => 'single-featured',
        ) );
        }
        
?>

        <div class="post-inner-content">
            <article id="post-999912" <?php post_class(); ?>>
                <header class="entry-header page-header">
                    <h1 class="entry-title">WordPress Config File Generator</h1>
                </header><!-- .entry-header -->

                <div class="entry-content">
                    <p>
                    This script is entirely automated. It will generate a downloadable wp-config.php file to use for your WordPress installation. 
                    At no point are your details stored, ANYWHERE. Once your config file is generated, all data you have entered is destroyed. 
                    Because of this, please ensure you enter all fields correctly, because if you submit the form and have made a mistake and need 
                    to correct it - you'll have to re-enter everything.
                </p>
                <p>
                    If you have any doubts about this script, the source code is available by going to <a href="//www.secondversion.com/tools/wordpress-config-file-generator/?source" rel="nofollow">here</a>.
                </p>
                <p>
                    DISCLAIMER: The information you enter is sent over an SSL connection to the server. I am not responsible for any loss of data or personal information. 
                    By using this tool, you agree that I am not liable for any losses incurred. I am not responsible or liable, directly or indirectly, for any damage or loss caused by 
                    or in connection with the use of, or reliance on, any such configuration file generated through this tool. 
                </p>
                <div class="wpconfig-form-panel">
                    <form action="//www.secondversion.com/tools/wordpress-config-file-generator/" method="post" id="wpconfig-form">
<?php

if (!empty($result))
{
?>
                        <fieldset style="color: #ff0000;">
                            <legend>ERROR</legend>
                            <div class="wpconfig-form-row">
                                <div>
                                    <?php echo $result?>
                                </div>
                            </div>
                        </fieldset>
<?php
}
?>
                        <fieldset>
                            <legend>Database Details</legend>
                            <div class="wpconfig-form-row">
                                <div><label for="dbhost">Server Name/Host</label>:</div>
                                <div>
                                    <input type="text" name="dbhost" id="dbhost" value="localhost" /><br />
                                    <span class="small">This is the hostname or IP address of the database server. If you are unsure, leave it as localhost.</span>
                                </div>
                            </div>
                            <div class="wpconfig-form-row">
                                <div><label for="dbname">Name</label>:</div>
                                <div>
                                    <input type="text" name="dbname" id="dbname" /><br />
                                    <span class="small">This is the name of the database where your WordPress data will be stored.</span>
                                </div>
                            </div>
                            <div class="wpconfig-form-row">
                                <div><label for="dbuser">Username</label>:</div>
                                <div>
                                    <input type="text" name="dbuser" id="dbuser" value="root" /><br />
                                    <span class="small">This is the username you use to access MySQL.</span>
                                </div>
                            </div>
                            <div class="wpconfig-form-row">
                                <div><label for="dbpass">Password</label>:</div>
                                <div>
                                    <input type="password" name="dbpass" id="dbpass" value="" /><br />
                                    <span class="small">This is the password you use to access MySQL.</span>
                                </div>
                            </div>
                            <div class="wpconfig-form-row">
                                <div><label for="tableprefix">Table Prefix</label>:</div>
                                <div>
                                    <input type="text" name="tableprefix" id="tableprefix" /><br />
                                    <span class="small">Prefix that your WordPress tables have in the database.</span>
                                </div>
                            </div>
                        </fieldset>
                        <input type="hidden" name="submitted" value="1" />
                        <input type="submit" name="submit" value="Submit" />
                    </form>
                    <p>&nbsp;</p>
                </div>
        </div><!-- .entry-content -->
</article><!-- #post-## -->
</div>

</main><!-- #main -->
</div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer
(); ?>