withStatus($exception->httpStatus) ->withHeader('Cache-Control', 'private, no-store'); } if (!($actor['is_admin'] ?? false)) { return $response->withStatus(403)->withHeader('Cache-Control', 'private, no-store'); } $payload = null; $error = ''; $status = 200; try { $payload = CloudAdminResourceService::page($request->getQueryParams()); } catch (CloudError $exception) { $error = $exception->getMessage(); $status = $exception->httpStatus; } catch (\Throwable $exception) { error_log('Admin resource snapshot failed: ' . get_class($exception)); $error = '资源调度数据暂时无法读取,请稍后重试。'; $status = 503; } $smarty = $this->view()->assign([ 'resource_page' => $payload, 'resource_error' => $error, 'resource_bootstrap_json' => json_encode($payload, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE | JSON_THROW_ON_ERROR), ]); $response->getBody()->write($smarty->fetch('admin/cloud/resources.tpl')); return $response->withStatus($status)->withHeader('Cache-Control', 'private, no-store'); } public function hosts($request, $response, $args) { return $this->view()->assign('cloud_country_options', CloudCountryCatalog::options()) ->display('admin/hosts/index.tpl'); } public function templates($request, $response, $args) { return $this->view()->display('admin/cloud/templates.tpl'); } public function rescue($request, $response, $args) { return $this->view()->display('admin/cloud/rescue.tpl'); } public function instances($request, $response, $args) { $actor = CloudAccess::actor(false); if (!($actor['is_admin'] ?? false)) { return $response->withStatus(403)->withHeader('Cache-Control', 'private, no-store'); } $payload = null; $error = ''; $status = 200; try { $payload = CloudAdminInstanceService::page($actor, $request->getQueryParams()); } catch (CloudError $exception) { $error = $exception->getMessage(); $status = $exception->httpStatus; } catch (\Throwable $exception) { error_log('Admin instance snapshot failed: ' . get_class($exception)); $error = '实例数据暂时无法读取,请稍后重试。'; $status = 503; } $smarty = $this->view()->assign([ 'instance_page' => $payload, 'instance_error' => $error, 'instance_bootstrap_json' => json_encode($payload, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE | JSON_THROW_ON_ERROR), ]); $response->getBody()->write($smarty->fetch('admin/cloud/instances.tpl')); return $response->withStatus($status)->withHeader('Cache-Control', 'private, no-store'); } public function orders($request, $response, $args) { return $response->withRedirect('/admin/billing?view=orders', 302); } public function billing($request, $response, $args) { try { $actor = CloudAccess::actor(false); } catch (CloudError $exception) { return $response->withStatus($exception->httpStatus) ->withHeader('Cache-Control', 'private, no-store'); } if (!($actor['is_admin'] ?? false)) { return $response->withStatus(403)->withHeader('Cache-Control', 'private, no-store'); } $payload = null; $error = ''; $status = 200; $requestedView = $request->getQueryParams()['view'] ?? 'invoices'; $view = is_string($requestedView) && in_array($requestedView, ['invoices', 'orders', 'payments'], true) ? $requestedView : 'invoices'; try { $payload = CloudAdminBillingService::page($request->getQueryParams()); } catch (CloudError $exception) { $error = $exception->getMessage(); $status = $exception->httpStatus; } catch (\Throwable $exception) { error_log('Admin billing snapshot failed: ' . get_class($exception)); $error = '账单数据暂时无法读取,请稍后重试。'; $status = 503; } $smarty = $this->view()->assign([ 'billing_page' => $payload, 'billing_error' => $error, 'billing_view' => $view, 'billing_bootstrap_json' => json_encode($payload, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE | JSON_THROW_ON_ERROR), ]); $response->getBody()->write($smarty->fetch('admin/billing.tpl')); return $response->withStatus($status)->withHeader('Cache-Control', 'private, no-store'); } public function operations($request, $response, $args) { try { $actor = CloudAccess::actor(false); } catch (CloudError $exception) { return $response->withStatus($exception->httpStatus) ->withHeader('Cache-Control', 'private, no-store'); } if (!($actor['is_admin'] ?? false)) { return $response->withStatus(403)->withHeader('Cache-Control', 'private, no-store'); } $payload = null; $error = ''; $status = 200; try { $payload = CloudAdminOperationsService::page($actor, $request->getQueryParams()); } catch (CloudError $exception) { $error = $exception->getMessage(); $status = $exception->httpStatus; } catch (\Throwable $exception) { error_log('Admin operations snapshot failed: ' . get_class($exception)); $error = '任务记录暂时无法读取,请稍后重试。'; $status = 503; } $smarty = $this->view()->assign([ 'operations_page' => $payload, 'operations_error' => $error, 'operations_bootstrap_json' => json_encode($payload, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE | JSON_THROW_ON_ERROR), ]); $response->getBody()->write($smarty->fetch('admin/cloud/operations.tpl')); return $response->withStatus($status)->withHeader('Cache-Control', 'private, no-store'); } public function update($request, $response, $args) { return $this->view()->display('admin/update.tpl'); } public function hostInventory($request, $response, $args) { try { $actor = CloudAccess::actor(false); } catch (CloudError $exception) { return $response->withStatus($exception->httpStatus) ->withHeader('Cache-Control', 'private, no-store'); } if (!($actor['is_admin'] ?? false)) { return $response->withStatus(403)->withHeader('Cache-Control', 'private, no-store'); } $payload = null; $error = ''; $status = 200; try { $payload = CloudHostInventoryDiagnostics::page($actor, $request->getQueryParams()); } catch (CloudError $exception) { $error = $exception->getMessage(); $status = $exception->httpStatus; } catch (\Throwable $exception) { error_log('Admin inventory history failed: ' . get_class($exception)); $error = '盘点记录暂时无法读取,请确认数据库已升级后重试。'; $status = 503; } $smarty = $this->view()->assign([ 'inventory_page' => $payload, 'inventory_error' => $error, 'inventory_timezone' => date_default_timezone_get(), 'inventory_bootstrap_json' => json_encode($payload, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE | JSON_THROW_ON_ERROR), ]); $response->getBody()->write($smarty->fetch('admin/cloud/host_inventory.tpl')); return $response->withStatus($status)->withHeader('Cache-Control', 'private, no-store'); } }