Panel/modules/billing/includes/config_loader.php
copilot-swe-agent[bot] 1247e5e7ca
fix: harden billing module for standalone portability
- config_loader.php: prefer local billing config FIRST (root cause fix)
  - was: panel config loaded first, overriding local config with wrong db name
  - now: local modules/billing/includes/config.inc.php always wins when present
- config.inc.php: add $db_port="3306"
- config.example.php: new example config with all variables documented
- menu.php: add $db_port to mysqli_connect
- admin_auth.php: add $db_port; remove hardcoded /_website path detection
- bootstrap.php billing_get_db(): add $db_port
- login.php: fix /_website path detection
- adminserverlist.php: add $db_port; fix hardcoded /modules/billing/ URL
- All other mysqli_connect calls: add isset($db_port) port parameter
  (my_servers, forgot_password, serverlist, server_status, order, register,
   reset_password, payment_success, my_account, admin_invoices, admin_payments,
   diag_remote, admin_coupons, test_db_connection, tools/check_db_user,
   renew_server)
- timestamp.txt: updated

Agent-Logs-Url: https://github.com/GameServerPanel/GSP/sessions/a3e1e4bb-8eb1-4e6e-b1f8-7f3952301231

Co-authored-by: iaretechnician <2749183+iaretechnician@users.noreply.github.com>
2026-05-02 13:15:50 +00:00

70 lines
2.1 KiB
PHP

<?php
/**
* Billing config loader
*
* Priority order (standalone-first):
* 1. modules/billing/includes/config.inc.php (local billing config — always wins when present)
* 2. <panel_root>/includes/config.inc.php (panel config — fallback when no local config)
*
* This ensures that copying modules/billing/ to any web root works correctly
* after editing its own config.inc.php, without being overridden by a parent
* panel installation that may have a different database name.
*/
if (defined('BILLING_CONFIG_LOADED')) {
return;
}
$localConfig = __DIR__ . '/config.inc.php';
$attempted = [];
// Always prefer the local billing config so the module is self-contained.
if (is_readable($localConfig)) {
$attempted[] = $localConfig;
require_once $localConfig;
if (!defined('BILLING_CONFIG_PATH')) {
define('BILLING_CONFIG_PATH', $localConfig);
}
define('BILLING_CONFIG_LOADED', true);
return;
}
$attempted[] = $localConfig;
// Fallback: try to load the panel's config (useful when running embedded inside the panel
// and no local copy has been made yet).
$panelConfig = null;
$projectRoot = realpath(__DIR__ . '/../../..');
if ($projectRoot !== false) {
$panelConfig = $projectRoot . '/includes/config.inc.php';
} else {
$panelConfig = __DIR__ . '/../../..' . '/includes/config.inc.php';
}
if ($panelConfig && is_readable($panelConfig)) {
$attempted[] = $panelConfig;
require_once $panelConfig;
if (!defined('BILLING_CONFIG_PATH')) {
define('BILLING_CONFIG_PATH', $panelConfig);
}
define('BILLING_CONFIG_LOADED', true);
return;
}
$attempted[] = $panelConfig;
$message = "GSP Billing module cannot find config.inc.php.\n";
$message .= "Looked in:\n";
foreach ((array)$attempted as $path) {
if (!$path) {
continue;
}
$message .= " - " . $path . "\n";
}
$message .= "\nCopy your panel's includes/config.inc.php into modules/billing/includes/config.inc.php ";
$message .= "or ensure the panel config is readable so the billing pages can load database settings.\n";
if (!headers_sent()) {
header('Content-Type: text/plain; charset=UTF-8', true, 500);
}
echo $message;
exit(1);