Files
sam-sales/fix_env.php

50 lines
1.9 KiB
PHP

<?php
header('Content-Type: text/plain; charset=utf-8');
echo "=== Production Environment Auto-Configurator ===\n";
$sourceEnv = '/home/webservice/sales_org/.env';
$targetEnv = '/home/webservice/sales/.env';
if (isset($_GET['apply']) && $_GET['apply'] === 'true') {
if (file_exists($sourceEnv)) {
echo "Reading configuration from $sourceEnv...\n";
$content = file_get_contents($sourceEnv);
// Parse source credentials
$db_host = 'localhost';
$db_name = 'chandj';
$db_user = 'codebridge';
$db_pass = '';
foreach (explode("\n", $content) as $line) {
$line = trim($line);
if (strpos($line, '=') === false) continue;
list($key, $val) = explode('=', $line, 2);
if ($key === 'DB_HOST') $db_host = $val;
if ($key === 'DB_NAME') $db_name = $val;
if ($key === 'DB_USER') $db_user = $val;
if ($key === 'DB_PASS') $db_pass = $val;
}
// Construct new .env for current server
$newContent = "APP_URL=https://sales.codebridge-x.com/\n";
$newContent .= "DB_HOST=$db_host\n";
$newContent .= "DB_NAME=$db_name\n";
$newContent .= "DB_USER=$db_user\n";
$newContent .= "DB_PASS=$db_pass\n";
$newContent .= "DOCUMENT_ROOT=/home/webservice/sales\n";
if (file_put_contents($targetEnv, $newContent)) {
echo "SUCCESS: New .env created at $targetEnv\n";
echo "You can now log in to the sales management system.\n";
echo "\nIMPORTANT: Delete fix_env.php after verification!\n";
} else {
echo "ERROR: Failed to write to $targetEnv. Check directory permissions.\n";
}
} else {
echo "ERROR: Source .env not found at $sourceEnv\n";
}
} else {
echo "Usage: Append ?apply=true to execute the configuration copy.\n";
}