Preview: wp-config.php
Size: 9.90 KB
/home/medyaist/Secure/hurdamakara.com.tr/wp-config.php
<?php
/**
* WordPress Configuration File
* Using Encrypted Environment Variables (.env)
* Encryption: AES-256-CBC with Base64 encoding
*/
// Prevent any output before WordPress loads
if (ob_get_level() === 0) {
ob_start();
}
// Suppress all errors and warnings during config loading
error_reporting(0);
ini_set('display_errors', 0);
// ===================================================
// ENCRYPTION FUNCTIONS
// ===================================================
function decrypt_value($encrypted_value, $encryption_key) {
if (empty($encrypted_value) || empty($encryption_key)) {
return $encrypted_value;
}
// If value doesn't look like base64, assume it's plain text
if (!preg_match('/^[A-Za-z0-9+\/]+=*$/', $encrypted_value)) {
return $encrypted_value;
}
// Decode from base64
$data = @base64_decode($encrypted_value, true);
if ($data === false || strlen($data) < 16) {
// If not base64 or too short, return as is (plain text)
return $encrypted_value;
}
// Ensure encryption key is 32 bytes for AES-256
$key = hash('sha256', $encryption_key, true);
// Extract IV and encrypted data
$iv = substr($data, 0, 16);
$encrypted = substr($data, 16);
// Decrypt
$decrypted = @openssl_decrypt($encrypted, 'AES-256-CBC', $key, OPENSSL_RAW_DATA, $iv);
if ($decrypted === false || empty($decrypted)) {
// If decryption fails, return original (might be plain text)
return $encrypted_value;
}
return $decrypted;
}
// ===================================================
// LOAD ENVIRONMENT VARIABLES
// ===================================================
// .env dosyası konumu (önce özel konumu kontrol et, sonra WordPress dizininde ara)
$env_file = '/home/medyaist/.env-hurdamakaracomtr';
if (!file_exists($env_file)) {
$env_file = '/home/medyaist/.env';
}
if (!file_exists($env_file)) {
$env_file = __DIR__ . '/.env';
}
$encryption_key = null;
// Load .env file in two passes: first get ENCRYPTION_KEY, then process other values
if (file_exists($env_file) && is_readable($env_file)) {
$lines = @file($env_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
if ($lines !== false) {
// First pass: Get ENCRYPTION_KEY
foreach ($lines as $line) {
$line = trim($line);
if (empty($line) || strpos($line, '#') === 0) continue;
if (strpos($line, '=') !== false) {
list($key, $value) = explode('=', $line, 2);
$key = trim($key);
$value = trim($value);
if (preg_match('/^(["\'])(.*)\1$/', $value, $matches)) {
$value = $matches[2];
}
if ($key === 'ENCRYPTION_KEY') {
$encryption_key = $value;
break;
}
}
}
// Second pass: Process all other values
foreach ($lines as $line) {
$line = trim($line);
if (empty($line) || strpos($line, '#') === 0) continue;
if (strpos($line, '=') !== false) {
list($key, $value) = explode('=', $line, 2);
$key = trim($key);
$value = trim($value);
if (preg_match('/^(["\'])(.*)\1$/', $value, $matches)) {
$value = $matches[2];
}
// Skip ENCRYPTION_KEY (already processed)
if ($key === 'ENCRYPTION_KEY') {
continue;
}
// Decrypt only DB_PASSWORD (other values remain plain text)
// Support both encrypted and plain text passwords
if ($key === 'DB_PASSWORD') {
if ($encryption_key) {
// Try to decrypt, if it fails, use as plain text
$decrypted = decrypt_value($value, $encryption_key);
$value = $decrypted;
}
// If no encryption key, use as plain text (backward compatibility)
}
// Define as constant if it's a WordPress constant
if (defined_name($key)) {
if ($value === 'true' || $value === 'false') {
$value = $value === 'true';
}
if (!defined($key)) {
define($key, $value);
}
} else {
// Set as environment variable
putenv("$key=$value");
$_ENV[$key] = $value;
$_SERVER[$key] = $value;
}
}
}
}
}
// Helper function to check if string should be a constant
function defined_name($name) {
$wp_constants = [
'DB_NAME', 'DB_USER', 'DB_PASSWORD', 'DB_HOST',
'DB_CHARSET', 'DB_COLLATE', 'WP_DEBUG', 'WP_DEBUG_DISPLAY',
'WP_DEBUG_LOG', 'WP_CACHE', 'DISALLOW_FILE_EDIT',
'CONCATENATE_SCRIPTS', 'AUTH_KEY', 'SECURE_AUTH_KEY',
'LOGGED_IN_KEY', 'NONCE_KEY', 'AUTH_SALT', 'SECURE_AUTH_SALT',
'LOGGED_IN_SALT', 'NONCE_SALT', 'WP_TEMP_DIR',
'COMPRESS_CSS', 'COMPRESS_SCRIPTS', 'ENFORCE_GZIP',
'WP_ENV', 'WP_HOME', 'WP_SITEURL'
];
return in_array($name, $wp_constants);
}
// ===================================================
// DATABASE SETTINGS (Required from .env)
// ===================================================
// Check if .env file was loaded successfully
$env_loaded = defined('DB_NAME') && !empty(DB_NAME) &&
defined('DB_USER') && !empty(DB_USER) &&
defined('DB_PASSWORD');
if (!$env_loaded) {
// .env file not loaded or incomplete
// Try to use fallback values or show helpful error
if (!defined('DB_NAME') || empty(DB_NAME)) {
define('DB_NAME', 'medyaist_hurdamakaracomtr');
}
if (!defined('DB_USER') || empty(DB_USER)) {
define('DB_USER', 'medyaist_hurdamakaracomtr');
}
if (!defined('DB_PASSWORD')) {
define('DB_PASSWORD', '');
}
if (!defined('DB_HOST') || empty(DB_HOST)) {
define('DB_HOST', 'localhost');
}
}
// Set default charset and collate if not defined
if (!defined('DB_CHARSET')) {
define('DB_CHARSET', 'utf8mb4');
}
if (!defined('DB_COLLATE')) {
define('DB_COLLATE', '');
}
// ===================================================
// AUTHENTICATION KEYS (Required from .env)
// ===================================================
// Set defaults if not defined (will cause security warning if .env missing)
if (!defined('AUTH_KEY')) {
define('AUTH_KEY', 'put your unique phrase here');
}
if (!defined('SECURE_AUTH_KEY')) {
define('SECURE_AUTH_KEY', 'put your unique phrase here');
}
if (!defined('LOGGED_IN_KEY')) {
define('LOGGED_IN_KEY', 'put your unique phrase here');
}
if (!defined('NONCE_KEY')) {
define('NONCE_KEY', 'put your unique phrase here');
}
if (!defined('AUTH_SALT')) {
define('AUTH_SALT', 'put your unique phrase here');
}
if (!defined('SECURE_AUTH_SALT')) {
define('SECURE_AUTH_SALT', 'put your unique phrase here');
}
if (!defined('LOGGED_IN_SALT')) {
define('LOGGED_IN_SALT', 'put your unique phrase here');
}
if (!defined('NONCE_SALT')) {
define('NONCE_SALT', 'put your unique phrase here');
}
// ===================================================
// WORDPRESS SETTINGS
// ===================================================
if (!defined('WP_DEBUG')) {
define('WP_DEBUG', false);
define('WP_DEBUG_DISPLAY', false);
define('WP_DEBUG_LOG', false);
}
if (!defined('DISALLOW_FILE_EDIT')) {
define('DISALLOW_FILE_EDIT', true);
}
if (!defined('CONCATENATE_SCRIPTS')) {
define('CONCATENATE_SCRIPTS', false);
}
// ===================================================
// PERFORMANCE OPTIMIZATIONS
// ===================================================
if (!defined('COMPRESS_CSS')) {
define('COMPRESS_CSS', true);
}
if (!defined('COMPRESS_SCRIPTS')) {
define('COMPRESS_SCRIPTS', true);
}
if (!defined('ENFORCE_GZIP')) {
define('ENFORCE_GZIP', true);
}
// ===================================================
// SITE URLS (Auto-detect if not set)
// ===================================================
if (!defined('WP_HOME')) {
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
$host = $_SERVER['HTTP_HOST'] ?? 'localhost';
define('WP_HOME', $protocol . '://' . $host);
}
if (!defined('WP_SITEURL')) {
define('WP_SITEURL', WP_HOME);
}
// ===================================================
// ENVIRONMENT TYPE
// ===================================================
if (!defined('WP_ENVIRONMENT_TYPE')) {
$wp_env = defined('WP_ENV') ? WP_ENV : 'production';
define('WP_ENVIRONMENT_TYPE', $wp_env);
}
// ===================================================
// DATABASE TABLE PREFIX
// ===================================================
$table_prefix = getenv('DB_PREFIX') ?: 'wp_';
// ===================================================
// ABSOLUTE PATH
// ===================================================
if (!defined('ABSPATH')) {
define('ABSPATH', __DIR__ . '/');
}
// ===================================================
// LOAD WORDPRESS
// ===================================================
// Clear any output buffer before loading WordPress
if (ob_get_level() > 0) {
ob_end_clean();
}
// Restore error reporting (WordPress will handle it)
error_reporting(E_ALL);
ini_set('display_errors', defined('WP_DEBUG') && WP_DEBUG ? 1 : 0);
require_once ABSPATH . 'wp-settings.php';
Directory Contents
Dirs: 0 × Files: 1