Persiapan hosting: config DB, perbaikan role, fix redirect

This commit is contained in:
Athallah Ghathfan Aqila
2026-06-13 13:56:43 +07:00
parent e3d7750f11
commit 46e999a9d0
9 changed files with 255 additions and 26 deletions
+13 -7
View File
@@ -1,10 +1,14 @@
<?php
if (isset($conn)) return;
$host = getenv('DB_HOST') ?: '127.0.0.1';
$user = getenv('DB_USER') ?: 'root';
$pass = getenv('DB_PASS') ?: '';
$name = getenv('DB_NAME') ?: 'db_webgis';
$port = (int)(getenv('DB_PORT') ?: 3306);
if (!defined('DB_HOST')) {
$cfg = dirname(__DIR__) . '/config.php';
if (file_exists($cfg)) require_once $cfg;
}
$host = defined('DB_HOST') ? DB_HOST : (getenv('DB_HOST') ?: '127.0.0.1');
$user = defined('DB_USER') ? DB_USER : (getenv('DB_USER') ?: 'root');
$pass = defined('DB_PASS') ? DB_PASS : (getenv('DB_PASS') ?: '');
$name = defined('DB_NAME') ? DB_NAME : (getenv('DB_NAME') ?: 'db_webgis');
$port = defined('DB_PORT') ? (int)DB_PORT : (int)(getenv('DB_PORT') ?: 3306);
$conn = mysqli_init();
mysqli_options($conn, MYSQLI_OPT_CONNECT_TIMEOUT, 5);
$ok = @mysqli_real_connect($conn, $host, $user, $pass, $name, $port);
@@ -23,7 +27,7 @@ if (!isset($GLOBALS[$setup_flag])) {
username VARCHAR(50) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL,
nama VARCHAR(100),
role ENUM('superadmin','admin','operator') DEFAULT 'operator',
role ENUM('admin','operator') DEFAULT 'operator',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)");
$conn->query("CREATE TABLE IF NOT EXISTS rumah_ibadah (
@@ -55,10 +59,12 @@ if (!isset($GLOBALS[$setup_flag])) {
hubungan VARCHAR(50), umur INT, pekerjaan VARCHAR(100), keterangan TEXT,
FOREIGN KEY (penduduk_id) REFERENCES penduduk_miskin(id) ON DELETE CASCADE
)");
$conn->query("UPDATE users SET role='admin' WHERE role='superadmin'");
$conn->query("ALTER TABLE users MODIFY COLUMN role ENUM('admin','operator') DEFAULT 'operator'");
$count = $conn->query("SELECT COUNT(*) FROM users")->fetch_row()[0];
if ($count == 0) {
$hash = '$2y$10$Ep64LS7KEQc2jKMu.AsH.O2wKF9ku4C8Cz0z4RHahgmYbz0vMr0/.';
$conn->query("INSERT INTO users (username,password,nama,role) VALUES ('admin','$hash','Administrator','superadmin')");
$conn->query("INSERT INTO users (username,password,nama,role) VALUES ('admin','$hash','Administrator','admin')");
$conn->query("INSERT INTO users (username,password,nama,role) VALUES ('operator','$hash','Operator Lapangan','operator')");
}
$conn->query("INSERT IGNORE INTO rumah_ibadah (id,nama,jenis,kontak,alamat,lat,lng,radius) VALUES