fix: resolve 3 billing admin errors and normalize remote_servers query
- admin_config.php: guard session_start() — was firing Notice because admin_auth.php → session_bridge.php already started the session - includes/menu.php: check mysqli_thread_id() before reusing $db so a closed handle does not cause 'mysqli object is already closed' fatal - admin_invoices.php / admin_payments.php: set $db = null after mysqli_close() so menu.php's reuse-check correctly falls through to opening a fresh connection - adminserverlist.php: use col_exists() to detect missing 'enabled' column in gsp_remote_servers; fall back to constant 1 and display a schema-notice banner; guard UPDATE accordingly; also add missing price_daily / price_year columns to the services SELECT; remove duplicate 'Update Enabled Servers' button - add_remote_server_enabled_column.sql: idempotent migration to add the 'enabled' INT column to gsp_remote_servers on older installs Agent-Logs-Url: https://github.com/GameServerPanel/GSP/sessions/988997ed-7568-48bf-96ef-889fb5d91fec Co-authored-by: iaretechnician <2749183+iaretechnician@users.noreply.github.com>
This commit is contained in:
parent
59a7eef4bd
commit
bb77620796
6 changed files with 59 additions and 8 deletions
31
modules/billing/add_remote_server_enabled_column.sql
Normal file
31
modules/billing/add_remote_server_enabled_column.sql
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
-- Migration: add `enabled` column to gsp_remote_servers
|
||||
--
|
||||
-- The original panel schema (panel.sql / ogp_remote_servers) includes an `enabled`
|
||||
-- INT(11) column. Installations that were created from an older schema, or whose
|
||||
-- table was renamed without carrying the column forward, may be missing it.
|
||||
--
|
||||
-- Run this once against your panel database (replace `gsp_` with your prefix if
|
||||
-- different). Safe to skip if the column already exists — just check with:
|
||||
-- SHOW COLUMNS FROM `gsp_remote_servers` LIKE 'enabled';
|
||||
--
|
||||
-- Usage:
|
||||
-- mysql -u <user> -p <db_name> < modules/billing/add_remote_server_enabled_column.sql
|
||||
|
||||
SET @table_name = 'gsp_remote_servers';
|
||||
SET @col_name = 'enabled';
|
||||
|
||||
SET @sql = IF(
|
||||
(
|
||||
SELECT COUNT(*)
|
||||
FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = @table_name
|
||||
AND COLUMN_NAME = @col_name
|
||||
) = 0,
|
||||
CONCAT('ALTER TABLE `', @table_name, '` ADD COLUMN `enabled` INT(11) NOT NULL DEFAULT 1'),
|
||||
'SELECT "Column already exists — nothing to do" AS note'
|
||||
);
|
||||
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
|
@ -5,7 +5,10 @@ require_once(__DIR__ . '/includes/config_loader.php');
|
|||
include(__DIR__ . '/includes/top.php');
|
||||
include(__DIR__ . '/includes/menu.php');
|
||||
|
||||
session_start();
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_name('opengamepanel_web');
|
||||
session_start();
|
||||
}
|
||||
if (empty($_SESSION['admin_csrf'])) $_SESSION['admin_csrf'] = bin2hex(random_bytes(16));
|
||||
$csrf = $_SESSION['admin_csrf'];
|
||||
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'], $_POST['inv
|
|||
if (!headers_sent()) {
|
||||
header('Location: admin_invoices.php?msg=' . urlencode($message) . '&type=' . $msgType);
|
||||
mysqli_close($db);
|
||||
$db = null;
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
|
@ -81,6 +82,7 @@ $res = $db->query(
|
|||
);
|
||||
if ($res) $invoices = $res->fetch_all(MYSQLI_ASSOC);
|
||||
mysqli_close($db);
|
||||
$db = null;
|
||||
|
||||
if (isset($_GET['msg'])) $message = $_GET['msg'];
|
||||
if (isset($_GET['type'])) $msgType = $_GET['type'];
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ if (!$db) {
|
|||
|
||||
$transactions = $repo->getTransactions($filter, 200, 0);
|
||||
mysqli_close($db);
|
||||
$db = null;
|
||||
}
|
||||
?>
|
||||
<!doctype html>
|
||||
|
|
|
|||
|
|
@ -66,6 +66,9 @@ function join_base($base, $path){
|
|||
$locationCol = col_exists($db, "{$table_prefix}billing_services", 'remote_server_id') ? 'remote_server_id' :
|
||||
(col_exists($db, "{$table_prefix}billing_services", 'remote_server') ? 'remote_server' : 'remote_server_id');
|
||||
|
||||
/* whether gsp_remote_servers has an 'enabled' column (may be missing on older installs) */
|
||||
$rsHasEnabled = col_exists($db, "{$table_prefix}remote_servers", 'enabled');
|
||||
|
||||
$flash = [];
|
||||
|
||||
/* A) Update global server location enable flags */
|
||||
|
|
@ -76,9 +79,11 @@ if (isset($_POST['update_remote_servers'])) {
|
|||
foreach ((array)$allIds as $row) {
|
||||
$id = (int)$row['remote_server_id'];
|
||||
$e = isset($enabledSet[$id]) ? 1 : 0;
|
||||
$db->query("UPDATE {$table_prefix}remote_servers SET enabled={$e} WHERE remote_server_id={$id}");
|
||||
if ($rsHasEnabled) {
|
||||
$db->query("UPDATE {$table_prefix}remote_servers SET enabled={$e} WHERE remote_server_id={$id}");
|
||||
}
|
||||
}
|
||||
$flash[] = "Server locations updated.";
|
||||
$flash[] = $rsHasEnabled ? "Server locations updated." : "Server locations updated (note: 'enabled' column missing from remote_servers — run add_remote_server_enabled_column.sql migration).";
|
||||
}
|
||||
|
||||
/* helper: update one service row from posted array */
|
||||
|
|
@ -148,13 +153,21 @@ if (isset($_POST['remove_service'], $_POST['service_id_remove'])) {
|
|||
}
|
||||
|
||||
/* fetch data for UI */
|
||||
$remoteServers = fetch_all_assoc($db, "SELECT remote_server_id, remote_server_name, enabled FROM {$table_prefix}remote_servers ORDER BY remote_server_name");
|
||||
$services = fetch_all_assoc($db, "SELECT service_id, service_name, `{$locationCol}` AS locs, slot_min_qty, slot_max_qty, price_monthly, img_url, enabled FROM {$table_prefix}billing_services ORDER BY service_name");
|
||||
$rsEnabledExpr = $rsHasEnabled ? ', enabled' : ', 1 AS enabled';
|
||||
$remoteServers = fetch_all_assoc($db, "SELECT remote_server_id, remote_server_name{$rsEnabledExpr} FROM {$table_prefix}remote_servers ORDER BY remote_server_name");
|
||||
$services = fetch_all_assoc($db, "SELECT service_id, service_name, `{$locationCol}` AS locs, slot_min_qty, slot_max_qty, price_daily, price_monthly, price_year, img_url, enabled FROM {$table_prefix}billing_services ORDER BY service_name");
|
||||
?>
|
||||
|
||||
<?php if ($flash): ?>
|
||||
<div class="panel" style="margin-bottom:12px"><?php foreach ((array)$flash as $m) echo "<div>".h($m)."</div>"; ?></div>
|
||||
<div class="panel mb-12"><?php foreach ((array)$flash as $m) echo "<div>".h($m)."</div>"; ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!$rsHasEnabled): ?>
|
||||
<div class="panel" style="margin-bottom:12px;background:#fff3cd;border:1px solid #ffc107;">
|
||||
<strong>⚠ Schema notice:</strong> The <code><?php echo h("{$table_prefix}remote_servers"); ?></code> table is missing the <code>enabled</code> column.
|
||||
Server location enable/disable is currently non-functional.
|
||||
Run <code>modules/billing/add_remote_server_enabled_column.sql</code> to add the column.
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<h2>Enable/Disable Server Locations (Global)</h2>
|
||||
|
|
@ -170,7 +183,6 @@ $services = fetch_all_assoc($db, "SELECT service_id, service_name, `{$locat
|
|||
<?php endforeach; ?>
|
||||
</div>
|
||||
<div style="margin-top:10px;"><button type="submit">Update Enabled Servers</button></div>
|
||||
<div class="mt-10"><button type="submit">Update Enabled Servers</button></div>
|
||||
</form>
|
||||
|
||||
<hr>
|
||||
|
|
|
|||
|
|
@ -55,7 +55,9 @@ if ($is_logged_in) {
|
|||
// Prefer reusing an existing $db if present, otherwise open a local connection
|
||||
$menu_db = null;
|
||||
$menu_db_opened = false;
|
||||
if (isset($db) && $db instanceof mysqli) {
|
||||
// Only reuse $db if it is still an open (non-closed) connection.
|
||||
// mysqli_thread_id() returns 0 on a closed handle, so guard against that.
|
||||
if (isset($db) && $db instanceof mysqli && @mysqli_thread_id($db)) {
|
||||
$menu_db = $db;
|
||||
} else {
|
||||
$menu_db_port = isset($db_port) ? (int)$db_port : null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue