Upload files to "/"
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
// Installer database untuk Tugas SIG gabungan.
|
||||
// Jalankan sekali setelah deploy, lalu hapus/nonaktifkan file ini dari repo.
|
||||
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
|
||||
$host = getenv('DB_HOST') ?: 'localhost';
|
||||
$user = getenv('DB_USER') ?: 'root';
|
||||
$pass = getenv('DB_PASS') ?: '';
|
||||
$db = getenv('DB_NAME') ?: 'webgis_tugas_sig';
|
||||
$port = (int)(getenv('DB_PORT') ?: 3306);
|
||||
|
||||
$sqlFile = __DIR__ . '/database/tugas_sig.sql';
|
||||
|
||||
function esc($value) {
|
||||
return htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
echo '<!doctype html><html lang="id"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Install Database Tugas SIG</title>';
|
||||
echo '<style>body{font-family:Arial,sans-serif;line-height:1.6;max-width:850px;margin:40px auto;padding:0 18px;background:#f7f7fb;color:#1f2937}.card{background:white;border:1px solid #e5e7eb;border-radius:16px;padding:24px;box-shadow:0 10px 30px rgba(0,0,0,.06)}code{background:#f1f5f9;padding:2px 6px;border-radius:6px}.ok{color:#15803d;font-weight:700}.err{color:#b91c1c;font-weight:700}.warn{color:#a16207;font-weight:700}.btn{display:inline-block;margin-top:14px;background:#2563eb;color:white;text-decoration:none;padding:10px 14px;border-radius:10px}</style></head><body><div class="card">';
|
||||
echo '<h1>Install Database Tugas SIG</h1>';
|
||||
echo '<p>Target koneksi: <code>' . esc($host) . ':' . esc($port) . '</code>, database: <code>' . esc($db) . '</code>, user: <code>' . esc($user) . '</code></p>';
|
||||
|
||||
if (!file_exists($sqlFile)) {
|
||||
echo '<p class="err">File SQL tidak ditemukan: <code>' . esc($sqlFile) . '</code></p>';
|
||||
echo '</div></body></html>';
|
||||
exit;
|
||||
}
|
||||
|
||||
$conn = @new mysqli($host, $user, $pass, $db, $port);
|
||||
|
||||
if ($conn->connect_error) {
|
||||
echo '<p class="err">Koneksi database gagal.</p>';
|
||||
echo '<p>Detail: <code>' . esc($conn->connect_error) . '</code></p>';
|
||||
echo '<p>Periksa environment variable di aplikasi Coolify:</p>';
|
||||
echo '<pre>DB_HOST=host_database_internal\nDB_PORT=3306\nDB_NAME=nama_database_aktif\nDB_USER=user_database\nDB_PASS=password_database</pre>';
|
||||
echo '<p class="warn">Catatan: kalau Initial Database di Coolify masih <code>default</code>, isi <code>DB_NAME=default</code>.</p>';
|
||||
echo '</div></body></html>';
|
||||
exit;
|
||||
}
|
||||
|
||||
$conn->set_charset('utf8mb4');
|
||||
$sql = file_get_contents($sqlFile);
|
||||
|
||||
if ($sql === false || trim($sql) === '') {
|
||||
echo '<p class="err">File SQL kosong atau tidak bisa dibaca.</p>';
|
||||
echo '</div></body></html>';
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!$conn->multi_query($sql)) {
|
||||
echo '<p class="err">Gagal menjalankan SQL.</p>';
|
||||
echo '<p>Detail: <code>' . esc($conn->error) . '</code></p>';
|
||||
echo '</div></body></html>';
|
||||
exit;
|
||||
}
|
||||
|
||||
$error = '';
|
||||
do {
|
||||
if ($result = $conn->store_result()) {
|
||||
$result->free();
|
||||
}
|
||||
if ($conn->errno) {
|
||||
$error = $conn->error;
|
||||
break;
|
||||
}
|
||||
} while ($conn->more_results() && $conn->next_result());
|
||||
|
||||
if ($error !== '') {
|
||||
echo '<p class="err">Import database selesai sebagian, tapi ada error.</p>';
|
||||
echo '<p>Detail: <code>' . esc($error) . '</code></p>';
|
||||
} else {
|
||||
echo '<p class="ok">Database berhasil diimport.</p>';
|
||||
echo '<p>Tabel yang dibuat/diperbarui:</p>';
|
||||
echo '<ul><li><code>tugas01_spbu</code></li><li><code>tugas02_data_spasial</code></li><li><code>tugas03_spbu</code></li></ul>';
|
||||
echo '<p class="warn">Setelah berhasil, hapus file <code>install_database.php</code> dari repo atau jangan biarkan publik terlalu lama.</p>';
|
||||
echo '<a class="btn" href="./">Kembali ke Landing Page</a>';
|
||||
}
|
||||
|
||||
$conn->close();
|
||||
echo '</div></body></html>';
|
||||
?>
|
||||
Reference in New Issue
Block a user