![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/soundstudiopro.com/public_html/radio/migrations/ |
<?php
/**
* Add password field to radio_stations table
* Implements proper password system instead of using API secret
*/
require_once __DIR__ . '/../../config/database.php';
$pdo = getDBConnection();
if (!$pdo) {
die("Database connection failed\n");
}
$is_cli = php_sapi_name() === 'cli';
if (!$is_cli) {
echo "<!DOCTYPE html><html><head><title>Add Password Field</title>";
echo "<style>body{font-family:Arial;padding:2rem;background:#f5f5f5;}";
echo ".success{color:#10b981;}.error{color:#ef4444;}.warning{color:#f59e0b;}</style>";
echo "</head><body><h1>Add Password Field to radio_stations</h1><pre>";
}
try {
echo "Checking radio_stations table...\n";
// Check if column exists
$stmt = $pdo->query("SHOW COLUMNS FROM radio_stations LIKE 'password_hash'");
if ($stmt->fetch()) {
echo "ℹ password_hash column already exists\n";
} else {
echo "Adding password_hash column...\n";
$pdo->exec("ALTER TABLE radio_stations ADD COLUMN password_hash VARCHAR(255) NULL");
echo "✓ password_hash column added\n";
// For existing stations, set a default password (they'll need to reset)
echo "Setting default passwords for existing stations...\n";
$stmt = $pdo->query("SELECT id, api_secret FROM radio_stations WHERE password_hash IS NULL");
$stations = $stmt->fetchAll();
foreach ($stations as $station) {
// Use API secret as temporary password (stations will need to change it)
if (!empty($station['api_secret'])) {
$temp_password = password_hash($station['api_secret'], PASSWORD_DEFAULT);
$update = $pdo->prepare("UPDATE radio_stations SET password_hash = ? WHERE id = ?");
$update->execute([$temp_password, $station['id']]);
}
}
echo "✓ Default passwords set for " . count($stations) . " existing stations\n";
echo "⚠️ Existing stations should reset their passwords on first login\n";
}
echo "\n✅ Migration completed successfully!\n";
if (!$is_cli) {
echo "</pre><div style='background:#d1fae5;padding:1rem;border-radius:4px;margin-top:1rem;'>";
echo "<strong class='success'>✅ Password system added!</strong>";
echo "<p>Stations can now use proper passwords instead of API secrets.</p>";
echo "</div></body></html>";
}
} catch (PDOException $e) {
$error = "❌ Error: " . $e->getMessage();
if ($is_cli) {
echo $error . "\n";
exit(1);
} else {
echo "</pre><div style='background:#fee2e2;padding:1rem;border-radius:4px;margin-top:1rem;'>";
echo "<strong class='error'>$error</strong>";
echo "</div></body></html>";
exit(1);
}
}