Merge pull request #146 from GameServerPanel/copilot/fix-gsp-provisioning-xml-reading
This commit is contained in:
commit
8537c4f0f7
4 changed files with 73 additions and 13 deletions
|
|
@ -18,13 +18,19 @@ if (session_status() === PHP_SESSION_NONE) {
|
|||
session_start();
|
||||
}
|
||||
|
||||
function billing_generate_password(int $bytes = 12): string
|
||||
function billing_generate_password(): string
|
||||
{
|
||||
try {
|
||||
return substr(bin2hex(random_bytes($bytes)), 0, $bytes * 2);
|
||||
} catch (Throwable $e) {
|
||||
return substr(hash('sha256', uniqid('gsp', true) . microtime(true)), 0, $bytes * 2);
|
||||
$alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
||||
$len = strlen($alphabet);
|
||||
$password = '';
|
||||
for ($i = 0; $i < 6; $i++) {
|
||||
try {
|
||||
$password .= $alphabet[random_int(0, $len - 1)];
|
||||
} catch (Throwable $e) {
|
||||
$password .= $alphabet[mt_rand(0, $len - 1)];
|
||||
}
|
||||
}
|
||||
return $password;
|
||||
}
|
||||
|
||||
function billing_normalize_duration(string $duration): array
|
||||
|
|
|
|||
|
|
@ -183,9 +183,29 @@ if (!function_exists('billing_detect_install_state')) {
|
|||
$state['reason'] = 'home_cfg_file is missing; install completion cannot be verified.';
|
||||
return $state;
|
||||
}
|
||||
$server_xml = read_server_config(SERVER_CONFIG_LOCATION . "/" . $home_info['home_cfg_file']);
|
||||
$xml_cfg_file = $home_info['home_cfg_file'] ?? '';
|
||||
$xml_rel = rtrim(SERVER_CONFIG_LOCATION, '/') . '/' . $xml_cfg_file;
|
||||
$xml_abs = $xml_rel;
|
||||
if (!is_readable($xml_rel)) {
|
||||
$panel_root = realpath(__DIR__ . '/../../');
|
||||
if ($panel_root !== false) {
|
||||
$xml_abs = $panel_root . '/' . ltrim($xml_rel, '/');
|
||||
}
|
||||
}
|
||||
if (function_exists('billing_provision_trace')) {
|
||||
billing_provision_trace('billing_detect_install_state: XML path resolution.', array(
|
||||
'home_id' => intval($home_info['home_id'] ?? 0),
|
||||
'home_cfg_file' => $xml_cfg_file,
|
||||
'xml_rel_path' => $xml_rel,
|
||||
'xml_abs_path' => $xml_abs,
|
||||
'cwd' => getcwd(),
|
||||
'xml_file_exists' => file_exists($xml_abs),
|
||||
'xml_is_readable' => is_readable($xml_abs),
|
||||
));
|
||||
}
|
||||
$server_xml = read_server_config($xml_abs);
|
||||
if (!$server_xml) {
|
||||
$state['reason'] = 'Could not read server config XML; install completion cannot be verified.';
|
||||
$state['reason'] = "Could not read server config XML; install completion cannot be verified. Tried: {$xml_abs}";
|
||||
return $state;
|
||||
}
|
||||
$server_exec_name = trim((string)($server_xml->server_exec_name ?? ''));
|
||||
|
|
@ -1252,11 +1272,14 @@ function exec_ogp_module()
|
|||
}
|
||||
|
||||
if ($home_id > 0) {
|
||||
// Set billing_status and next_invoice_date on server_homes
|
||||
// Set billing_status, next_invoice_date, and server_expiration_date on server_homes.
|
||||
// server_expiration_date must match end_date so the billing cron can determine
|
||||
// when to suspend / delete the server.
|
||||
$db->query("UPDATE `{$db_prefix}server_homes`
|
||||
SET billing_status = 'Active',
|
||||
next_invoice_date = '" . $db->realEscapeSingle($end_date_str) . "',
|
||||
billing_enabled = 1
|
||||
SET billing_status = 'Active',
|
||||
next_invoice_date = '" . $db->realEscapeSingle($end_date_str) . "',
|
||||
server_expiration_date = '" . $db->realEscapeSingle($end_date_str) . "',
|
||||
billing_enabled = 1
|
||||
WHERE home_id = " . $db->realEscapeSingle($home_id));
|
||||
$home_row_after = billing_get_server_home_row($db, $db_prefix, intval($home_id));
|
||||
billing_provision_trace('Loaded server_homes row after billing linkage updates.', array(
|
||||
|
|
|
|||
|
|
@ -35,6 +35,10 @@ if (!function_exists('billing_panel_bootstrap')) {
|
|||
static $includeInjected = false;
|
||||
if (!$includeInjected) {
|
||||
set_include_path($root . PATH_SEPARATOR . get_include_path());
|
||||
// Change CWD to the panel root so that SERVER_CONFIG_LOCATION and other
|
||||
// relative paths (e.g. XML_SCHEMA) resolve correctly when billing endpoints
|
||||
// run outside of home.php (e.g. api/capture_order.php, PayPal webhooks).
|
||||
chdir($root);
|
||||
$includeInjected = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,9 +33,36 @@ if (!function_exists('gamemanager_trigger_update_install')) {
|
|||
return $resultBase + array('ok' => false, 'pending' => true, 'message' => "No mod profile configured for home #{$home_id}.");
|
||||
}
|
||||
|
||||
$server_xml = read_server_config(SERVER_CONFIG_LOCATION . "/" . $home_info['home_cfg_file']);
|
||||
// Build the XML path and resolve it to an absolute location so provisioning
|
||||
// paths that do not run from the panel root CWD (e.g. billing capture_order.php)
|
||||
// can still locate the file. SERVER_CONFIG_LOCATION is a relative constant
|
||||
// ("modules/config_games/server_configs/") that only works when CWD equals the
|
||||
// panel root; update_actions.php lives in modules/gamemanager/ so the panel
|
||||
// root is __DIR__ . '/../../'.
|
||||
$xml_cfg_file = $home_info['home_cfg_file'] ?? '';
|
||||
$xml_rel = rtrim(SERVER_CONFIG_LOCATION, '/') . '/' . $xml_cfg_file;
|
||||
$xml_abs = $xml_rel;
|
||||
if (!is_readable($xml_rel)) {
|
||||
$panel_root = realpath(__DIR__ . '/../../');
|
||||
if ($panel_root !== false) {
|
||||
$xml_abs = $panel_root . '/' . ltrim($xml_rel, '/');
|
||||
}
|
||||
}
|
||||
if (function_exists('billing_provision_trace')) {
|
||||
billing_provision_trace('gamemanager_trigger_update_install: XML path resolution.', array(
|
||||
'home_id' => $home_id,
|
||||
'home_cfg_file' => $xml_cfg_file,
|
||||
'server_config_location' => SERVER_CONFIG_LOCATION,
|
||||
'xml_rel_path' => $xml_rel,
|
||||
'xml_abs_path' => $xml_abs,
|
||||
'cwd' => getcwd(),
|
||||
'xml_file_exists' => file_exists($xml_abs),
|
||||
'xml_is_readable' => is_readable($xml_abs),
|
||||
));
|
||||
}
|
||||
$server_xml = read_server_config($xml_abs);
|
||||
if (!$server_xml) {
|
||||
return $resultBase + array('ok' => false, 'pending' => true, 'message' => "Could not read server config XML for home #{$home_id}.");
|
||||
return $resultBase + array('ok' => false, 'pending' => true, 'message' => "Could not read server config XML for home #{$home_id}. Tried: {$xml_abs}");
|
||||
}
|
||||
|
||||
$remote = new OGPRemoteLibrary($home_info['agent_ip'], $home_info['agent_port'], $home_info['encryption_key'], $home_info['timeout']);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue