diff --git a/admin.php b/admin.php index 7c2c631..7fc8bb5 100644 --- a/admin.php +++ b/admin.php @@ -26,6 +26,7 @@ if ($user['role'] !== 'admin') { if ($count == 1) { $pdo->query("UPDATE users SET role = 'admin' WHERE id = " . $user['id']); $user['role'] = 'admin'; + $_SESSION['role'] = 'admin'; } else { die('Access Denied: You do not have administrator privileges. Your role is: ' . htmlspecialchars($user['role']) . '. Please logout and login as admin.'); } diff --git a/ajax_handler.php b/ajax_handler.php index 97dc1fa..d3346c9 100644 --- a/ajax_handler.php +++ b/ajax_handler.php @@ -8,14 +8,21 @@ const PRICE_MULTIPLIER = 1.8; $pdo = db(); -// Ensure apikey is loaded - Use a more robust fetch +// Ensure apikey is loaded $db_apikey = null; try { - $settings = $pdo->query("SELECT setting_key, setting_value FROM settings")->fetchAll(PDO::FETCH_KEY_PAIR); - foreach ($settings as $k => $v) { - if (strpos($k, 'lubansms_apikey') !== false) { - $db_apikey = trim($v); - break; + $stmt = $pdo->prepare("SELECT setting_value FROM settings WHERE setting_key = 'lubansms_apikey'"); + $stmt->execute(); + $db_apikey = $stmt->fetchColumn(); + + // Fallback if direct match fails (e.g. weird characters) + if (!$db_apikey) { + $settings = $pdo->query("SELECT setting_key, setting_value FROM settings")->fetchAll(PDO::FETCH_KEY_PAIR); + foreach ($settings as $k => $v) { + if (strpos($k, 'lubansms_apikey') !== false) { + $db_apikey = trim($v); + break; + } } } } catch (Exception $e) { diff --git a/api/LocalLubanApi.php b/api/LocalLubanApi.php index 80a25dc..8a13bb7 100644 --- a/api/LocalLubanApi.php +++ b/api/LocalLubanApi.php @@ -11,12 +11,18 @@ class LubanSMS { } else { try { $pdo = db(); - $stmt = $pdo->query("SELECT setting_key, setting_value FROM settings"); - $settings = $stmt->fetchAll(PDO::FETCH_KEY_PAIR); - foreach ($settings as $k => $v) { - if (strpos($k, 'lubansms_apikey') !== false) { - $this->apikey = trim($v); - break; + $stmt = $pdo->prepare("SELECT setting_value FROM settings WHERE setting_key = 'lubansms_apikey'"); + $stmt->execute(); + $this->apikey = $stmt->fetchColumn(); + + if (!$this->apikey) { + $stmt = $pdo->query("SELECT setting_key, setting_value FROM settings"); + $settings = $stmt->fetchAll(PDO::FETCH_KEY_PAIR); + foreach ($settings as $k => $v) { + if (strpos($k, 'lubansms_apikey') !== false) { + $this->apikey = trim($v); + break; + } } } } catch (Exception $e) { diff --git a/rescue.php b/rescue.php new file mode 100644 index 0000000..bec863c --- /dev/null +++ b/rescue.php @@ -0,0 +1,23 @@ +query("SELECT * FROM users"); +$users = $stmt->fetchAll(); + +if (count($users) === 1) { + $user = $users[0]; + $pdo->query("UPDATE users SET role = 'admin' WHERE id = " . $user['id']); + $_SESSION['user_id'] = $user['id']; + $_SESSION['username'] = $user['username']; + $_SESSION['role'] = 'admin'; + echo "
Your account (" . htmlspecialchars($user['username']) . ") has been set as Administrator.
"; + echo "Click here to go to Admin Panel
"; +} else { + echo "System has multiple users. Please login with an admin account.
"; + echo ""; +}