home($request, $response, $args); } public function home($request, $response, $args) { return $response->withHeader('Location', '/user/cloud/instances')->withStatus(302); } public function instances($request, $response, $args) { return $this->render($response, 'instances', '实例管理'); } public function detail($request, $response, $args) { return $this->renderVmPage($response, $args, 'detail', '实例详情'); } public function deploy($request, $response, $args) { return $this->render($response, 'deploy', '部署实例'); } public function isoImages($request, $response, $args) { if (!CloudUserIsoFeature::enabled()) { return $response->withHeader('Location', '/user/cloud/instances')->withStatus(302); } return $this->render($response, 'isos', 'ISO 镜像'); } public function sshKeys($request, $response, $args) { return $this->render($response, 'keys', 'SSH 公钥'); } public function invoices($request, $response, $args) { return $this->render($response, 'invoices', '账单信息'); } public function invoiceDetail($request, $response, $args) { $invoiceId = isset($args['id']) ? (string) $args['id'] : ''; if (!preg_match('/^[1-9][0-9]*$/', $invoiceId)) { return $response->withHeader('Location', '/user/cloud/invoices')->withStatus(302); } return $this->render($response, 'invoice-detail', '账单详情', '', $invoiceId); } public function reinstall($request, $response, $args) { return $this->renderVmPage($response, $args, 'reinstall', '重装系统'); } public function rescue($request, $response, $args) { return $this->renderVmPage($response, $args, 'rescue', '紧急救援'); } public function legacyShop($request, $response, $args) { return $response->withHeader('Location', '/user/cloud/deploy')->withStatus(302); } private function renderVmPage($response, $args, $page, $title) { $vmId = isset($args['id']) ? (string) $args['id'] : ''; if (!preg_match('/^[1-9][0-9]*$/', $vmId)) { return $response->withHeader('Location', '/user/cloud/instances')->withStatus(302); } return $this->render($response, $page, $title, $vmId); } private function render($response, $page, $title, $vmId = '', $invoiceId = '') { $smarty = View::getSmarty('venix'); $smarty->assign('cloud_page', $page); $smarty->assign('cloud_title', $title); $smarty->assign('cloud_vm_id', $vmId); $smarty->assign('cloud_invoice_id', $invoiceId); $response->getBody()->write($smarty->fetch('cloud/page.tpl')); return $response; } }