123456
This commit is contained in:
parent
48b78f8a22
commit
fb7b115095
10
admin.php
10
admin.php
@ -19,8 +19,16 @@ if (!$user) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Ensure role is admin
|
||||
if ($user['role'] !== 'admin') {
|
||||
die('Access Denied: You do not have administrator privileges. Your role is: ' . htmlspecialchars($user['role']));
|
||||
// Check if this is the ONLY user, if so, force admin
|
||||
$count = $pdo->query("SELECT COUNT(*) FROM users")->fetchColumn();
|
||||
if ($count == 1) {
|
||||
$pdo->query("UPDATE users SET role = 'admin' WHERE id = " . $user['id']);
|
||||
$user['role'] = 'admin';
|
||||
} else {
|
||||
die('Access Denied: You do not have administrator privileges. Your role is: ' . htmlspecialchars($user['role']) . '. Please logout and login as admin.');
|
||||
}
|
||||
}
|
||||
|
||||
$action = $_GET['action'] ?? 'dashboard';
|
||||
|
||||
@ -8,10 +8,19 @@ const PRICE_MULTIPLIER = 1.8;
|
||||
|
||||
$pdo = db();
|
||||
|
||||
// Ensure apikey is loaded
|
||||
$stmt = $pdo->prepare("SELECT setting_value FROM settings WHERE setting_key = 'lubansms_apikey'");
|
||||
$stmt->execute();
|
||||
$db_apikey = $stmt->fetchColumn();
|
||||
// Ensure apikey is loaded - Use a more robust fetch
|
||||
$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;
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
// Log error
|
||||
}
|
||||
|
||||
$api = new LubanSMS($db_apikey);
|
||||
|
||||
@ -69,7 +78,7 @@ try {
|
||||
|
||||
case 'get_countries':
|
||||
if (!$db_apikey) {
|
||||
echo json_encode(['code' => 500, 'msg' => 'API Key not configured in DB'], JSON_UNESCAPED_UNICODE);
|
||||
echo json_encode(['code' => 500, 'msg' => '加载失败: API Key not configured in DB (Debug: key is null)'], JSON_UNESCAPED_UNICODE);
|
||||
break;
|
||||
}
|
||||
$res = $api->getCountries();
|
||||
@ -83,7 +92,7 @@ try {
|
||||
|
||||
case 'get_services':
|
||||
if (!$db_apikey) {
|
||||
echo json_encode(['code' => 500, 'msg' => 'API Key not configured in DB'], JSON_UNESCAPED_UNICODE);
|
||||
echo json_encode(['code' => 500, 'msg' => '加载行情失败: API Key not configured in DB'], JSON_UNESCAPED_UNICODE);
|
||||
break;
|
||||
}
|
||||
$country = $_GET['country'] ?? '';
|
||||
|
||||
@ -11,11 +11,13 @@ class LubanSMS {
|
||||
} else {
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare("SELECT setting_value FROM settings WHERE setting_key = 'lubansms_apikey'");
|
||||
$stmt->execute();
|
||||
$val = $stmt->fetchColumn();
|
||||
if ($val) {
|
||||
$this->apikey = trim($val);
|
||||
$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) {
|
||||
// Log error or handle
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user