[ * 'displayErrorDetails' => $debug, * ] * ]; * $c = new Container($configuration); ***/ // Make a Slim App // $app = new App($c); $configuration = [ 'settings' => [ 'debug' => $debug, 'whoops.editor' => 'sublime', 'displayErrorDetails' => $debug ] ]; $container = new Container($configuration); $renderErrorPage = function ($response, $status, $template) { $path = parse_url((string) ($_SERVER['REQUEST_URI'] ?? ''), PHP_URL_PATH); if (is_string($path) && (str_starts_with($path, '/api/v1/') || str_starts_with($path, '/api/internal/cloud/'))) { return $response->withJson(['detail' => $status === 500 ? '服务暂时不可用' : '接口不存在或请求方法不支持'], $status); } $newResponse = $response->withStatus($status); $newResponse->getBody()->write(View::getSmarty()->fetch($template)); return $newResponse; }; $container['notFoundHandler'] = function ($c) use ($renderErrorPage) { return function ($request, $response) use ($c, $renderErrorPage) { return $renderErrorPage($response, 404, '404.tpl'); }; }; $container['notAllowedHandler'] = function ($c) use ($renderErrorPage) { return function ($request, $response, $methods) use ($c, $renderErrorPage) { return $renderErrorPage($response, 405, '405.tpl') ->withHeader('Allow', implode(', ', $methods)); }; }; if ($debug==false) { $container['errorHandler'] = function ($c) use ($renderErrorPage) { return function ($request, $response, $exception) use ($c, $renderErrorPage) { return $renderErrorPage($response, 500, '500.tpl'); }; }; $container['phpErrorHandler'] = function ($c) use ($renderErrorPage) { return function ($request, $response, $error) use ($c, $renderErrorPage) { return $renderErrorPage($response, 500, '500.tpl'); }; }; } $app = new App($container); // Home $app->get('/', 'App\Controllers\HomeController:index'); $app->get('/404', 'App\Controllers\HomeController:page404'); $app->get('/405', 'App\Controllers\HomeController:page405'); $app->get('/500', 'App\Controllers\HomeController:page500'); $app->post('/telegram_callback', 'App\Controllers\TelegramWebhookController:handle'); // User Center $app->group('/user', function () { $this->get('', 'App\Controllers\CloudPageController:home'); $this->get('/', 'App\Controllers\CloudPageController:home'); $this->get('/cloud', 'App\Controllers\CloudPageController:index'); $this->get('/cloud/instances', 'App\Controllers\CloudPageController:instances'); $this->get('/cloud/instances/{id:[0-9]+}', 'App\Controllers\CloudPageController:detail'); $this->get('/cloud/instances/{id:[0-9]+}/reinstall', 'App\Controllers\CloudPageController:reinstall'); $this->get('/cloud/instances/{id:[0-9]+}/rescue', 'App\Controllers\CloudPageController:rescue'); $this->get('/cloud/deploy', 'App\Controllers\CloudPageController:deploy'); $this->get('/cloud/iso-images', 'App\Controllers\CloudPageController:isoImages'); $this->get('/cloud/ssh-keys', 'App\Controllers\CloudPageController:sshKeys'); $this->get('/cloud/invoices', 'App\Controllers\CloudPageController:invoices'); $this->get('/cloud/invoices/{id:[0-9]+}', 'App\Controllers\CloudPageController:invoiceDetail'); $this->get('/invite', 'App\Controllers\UserController:invite'); $this->get('/ticket', 'App\Controllers\UserController:ticket'); $this->get('/ticket/create', 'App\Controllers\UserController:ticket_create'); $this->post('/ticket', 'App\Controllers\UserController:ticket_add'); $this->get('/ticket/{id}/view', 'App\Controllers\UserController:ticket_view'); $this->get('/ticket/{id}/attachment/{attachment_id:[0-9]+}', 'App\Controllers\UserController:ticket_attachment'); // Multipart replies use POST so PHP reliably exposes uploaded files in // $_FILES; the legacy PUT endpoint remains available for text clients. $this->post('/ticket/{id}/reply', 'App\Controllers\UserController:ticket_update'); $this->put('/ticket/{id}', 'App\Controllers\UserController:ticket_update'); $this->post('/aff_check_in', 'App\Controllers\UserController:doAff'); $this->post('/aff_check_out', 'App\Controllers\UserController:doAff'); $this->post('/invite', 'App\Controllers\UserController:doInvite'); // Manual invite-code rotation is account functionality, not a proxy reset job. $this->post('/resetiv', 'App\Controllers\UserController:doResetiv'); $this->get('/edit', 'App\Controllers\UserController:edit'); // Password changes require the current password plus either a one-time // email code or an enabled Google Authenticator code. $this->post('/password/verify/send', 'App\Controllers\AccountSecurityController:passwordVerifySend'); $this->post('/password', 'App\Controllers\AccountSecurityController:updatePassword'); $this->get('/recharge/options', 'App\Controllers\AccountSecurityController:rechargeOptions'); $this->get('/recharge/methods', 'App\Controllers\AccountSecurityController:rechargeOptions'); $this->post('/security/google-authenticator', 'App\Controllers\UserController:enableGoogleAuthenticator'); $this->delete('/security/google-authenticator', 'App\Controllers\UserController:disableGoogleAuthenticator'); $this->post('/security/verify-method', 'App\Controllers\UserController:updateLoginVerifyMethod'); $this->get('/logout', 'App\Controllers\UserController:logout'); $this->get('/code', 'App\Controllers\UserController:code'); $this->get('/code_check', 'App\Controllers\UserController:code_check'); $this->post('/usdt/order', 'App\Controllers\UsdtController:create'); $this->post('/usdt/status', 'App\Controllers\UsdtController:status'); $this->post('/yipay/order', 'App\Controllers\YipayController:create'); $this->post('/yipay/status', 'App\Controllers\YipayController:status'); $this->post('/paytaro', 'App\Controllers\PaytaroController:create'); $this->post('/paytaro/order', 'App\Controllers\PaytaroController:create'); $this->post('/paytaro/status', 'App\Controllers\PaytaroController:status'); $this->get('/disable', 'App\Controllers\UserController:disable'); $this->post('/survey', 'App\Controllers\UserController:submitSurvey'); })->add(new Auth()); // Auth $app->group('/auth', function () { $this->get('/login', 'App\Controllers\AuthController:login'); $this->post('/login', 'App\Controllers\AuthController:loginHandle'); $this->post('/login/verify/send', 'App\Controllers\AuthController:sendLoginVerify'); $this->get('/register', 'App\Controllers\AuthController:register'); $this->post('/register', 'App\Controllers\AuthController:registerHandle'); $this->post('/send', 'App\Controllers\AuthController:sendVerify'); $this->get('/logout', 'App\Controllers\AuthController:logout'); })->add(new Guest()); // Password $app->group('/password', function () { $this->get('/reset', 'App\Controllers\PasswordController:reset'); $this->post('/reset', 'App\Controllers\PasswordController:handleReset'); $this->get('/token/{token}', 'App\Controllers\PasswordController:token'); $this->post('/token/{token}', 'App\Controllers\PasswordController:handleToken'); })->add(new Guest()); // Admin $app->group('/admin', function () { $this->get('', 'App\Controllers\AdminController:index'); $this->get('/', 'App\Controllers\AdminController:index'); $this->get('/resources', 'App\Controllers\Admin\CloudPageController:resources'); // Host preparation (admin only; backend integration is not enabled yet) $this->get('/hosts', 'App\Controllers\Admin\CloudPageController:hosts'); $this->get('/cloud/templates', 'App\Controllers\Admin\CloudPageController:templates'); $this->get('/cloud/rescue', 'App\Controllers\Admin\CloudPageController:rescue'); $this->get('/cloud/instances', 'App\Controllers\Admin\CloudPageController:instances'); $this->get('/billing', 'App\Controllers\Admin\CloudPageController:billing'); $this->get('/cloud/orders', 'App\Controllers\Admin\CloudPageController:orders'); $this->get('/update', 'App\Controllers\Admin\CloudPageController:update')->add(new SuperAdmin()); $this->get('/operations', 'App\Controllers\Admin\CloudPageController:operations'); $this->get('/system-logs', 'App\Controllers\Admin\CloudPageController:systemLogs'); $this->get('/platform-default-policy', 'App\Controllers\Admin\CloudPageController:platformDefaultPolicy'); // Telegram administration is rendered inside the ticket system; these // action endpoints remain stable for existing sessions and automation. $this->post('/telegram/config', 'App\Controllers\Admin\TelegramController:save')->add(new SuperAdmin()); $this->post('/telegram/secret/rotate', 'App\Controllers\Admin\TelegramController:rotateSecret')->add(new SuperAdmin()); $this->post('/telegram/bind', 'App\Controllers\Admin\TelegramController:bind')->add(new SuperAdmin()); $this->post('/telegram/unbind', 'App\Controllers\Admin\TelegramController:unbind')->add(new SuperAdmin()); $this->post('/telegram/webhook', 'App\Controllers\Admin\TelegramController:webhook')->add(new SuperAdmin()); // Tick $this->get('/ticket', 'App\Controllers\Admin\TicketController:index'); $this->get('/ticket/{id}/view', 'App\Controllers\Admin\TicketController:show'); $this->get('/ticket/{id}/attachment/{attachment_id:[0-9]+}', 'App\Controllers\Admin\TicketController:attachment'); // Keep multipart administrator replies on POST for PHP upload parsing; // existing PUT clients continue to use the original endpoint. $this->post('/ticket/{id}/reply', 'App\Controllers\Admin\TicketController:update')->add(new SuperAdmin()); $this->put('/ticket/{id}', 'App\Controllers\Admin\TicketController:update')->add(new SuperAdmin()); $this->post('/ticket/ajax', 'App\Controllers\Admin\TicketController:ajax'); // Shop Mange $this->get('/shop', 'App\Controllers\Admin\ShopController:index'); $this->post('/shop/ajax', 'App\Controllers\Admin\ShopController:ajax_shop'); $this->get('/shop/create', 'App\Controllers\Admin\ShopController:create')->add(new SuperAdmin()); $this->post('/shop', 'App\Controllers\Admin\ShopController:add')->add(new SuperAdmin()); $this->get('/shop/{id}/edit', 'App\Controllers\Admin\ShopController:edit'); $this->put('/shop/{id}', 'App\Controllers\Admin\ShopController:update')->add(new SuperAdmin()); $this->delete('/shop', 'App\Controllers\Admin\ShopController:deleteGet')->add(new SuperAdmin()); $this->get('/shop/{id}/offers/create', 'App\Controllers\Admin\ShopController:offerCreate')->add(new SuperAdmin()); $this->post('/shop/{id}/offers', 'App\Controllers\Admin\ShopController:offerAdd')->add(new SuperAdmin()); $this->get('/shop/{id}/offers/{offer_id}/edit', 'App\Controllers\Admin\ShopController:offerEdit'); $this->put('/shop/{id}/offers/{offer_id}', 'App\Controllers\Admin\ShopController:offerUpdate')->add(new SuperAdmin()); $this->delete('/shop/{id}/offers/{offer_id}', 'App\Controllers\Admin\ShopController:offerDelete')->add(new SuperAdmin()); // Ann Mange $this->get('/announcement', 'App\Controllers\Admin\AnnController:index'); $this->get('/announcement/create', 'App\Controllers\Admin\AnnController:create')->add(new SuperAdmin()); $this->post('/announcement', 'App\Controllers\Admin\AnnController:add')->add(new SuperAdmin()); $this->get('/announcement/{id}/edit', 'App\Controllers\Admin\AnnController:edit')->add(new SuperAdmin()); $this->put('/announcement/{id}', 'App\Controllers\Admin\AnnController:update')->add(new SuperAdmin()); $this->post('/announcement/{id}/status', 'App\Controllers\Admin\AnnController:status')->add(new SuperAdmin()); // Survey Manage $this->get('/survey', 'App\Controllers\Admin\SurveyController:index'); $this->get('/survey/create', 'App\Controllers\Admin\SurveyController:create')->add(new SuperAdmin()); $this->post('/survey', 'App\Controllers\Admin\SurveyController:add')->add(new SuperAdmin()); $this->get('/survey/{id}/edit', 'App\Controllers\Admin\SurveyController:edit')->add(new SuperAdmin()); $this->put('/survey/{id}', 'App\Controllers\Admin\SurveyController:update')->add(new SuperAdmin()); $this->delete('/survey', 'App\Controllers\Admin\SurveyController:delete')->add(new SuperAdmin()); // Detect Mange // IP Mange $this->get('/login', 'App\Controllers\Admin\IpController:index'); $this->post('/login/ajax', 'App\Controllers\Admin\IpController:ajax_login'); // Code Mange $this->get('/code', 'App\Controllers\Admin\CodeController:index'); $this->post('/code/ajax', 'App\Controllers\Admin\CodeController:ajax_code'); $this->get('/usdt', 'App\Controllers\Admin\UsdtController:index'); $this->post('/usdt/config', 'App\Controllers\Admin\UsdtController:save')->add(new SuperAdmin()); $this->post('/usdt/test', 'App\Controllers\Admin\UsdtController:test')->add(new SuperAdmin()); $this->get('/yipay', 'App\Controllers\Admin\YipayController:index'); $this->post('/yipay/config', 'App\Controllers\Admin\YipayController:save')->add(new SuperAdmin()); $this->post('/yipay/test', 'App\Controllers\Admin\YipayController:test')->add(new SuperAdmin()); $this->post('/yipay/refund', 'App\Controllers\Admin\YipayController:refund')->add(new SuperAdmin()); $this->get('/paytaro', 'App\Controllers\Admin\PaytaroController:index'); $this->post('/paytaro/config', 'App\Controllers\Admin\PaytaroController:save')->add(new SuperAdmin()); $this->post('/paytaro/test', 'App\Controllers\Admin\PaytaroController:test')->add(new SuperAdmin()); // User Mange $this->get('/user', 'App\Controllers\Admin\UserController:index'); $this->get('/user/{id}/edit', 'App\Controllers\Admin\UserController:edit')->add(new SuperAdmin()); $this->post('/user/{id}/trusted-login-devices/clear', 'App\Controllers\Admin\UserController:clearTrustedLoginDevices')->add(new SuperAdmin()); $this->post('/user/{id}/login-sessions/clear', 'App\Controllers\Admin\UserController:clearLoginSessions')->add(new SuperAdmin()); $this->put('/user/{id}', 'App\Controllers\Admin\UserController:update')->add(new SuperAdmin()); $this->delete('/user', 'App\Controllers\Admin\UserController:delete')->add(new SuperAdmin()); $this->get('/user/ajax', 'App\Controllers\Admin\UserController:ajax'); $this->post('/user/ajax', 'App\Controllers\Admin\UserController:ajax'); $this->post('/user/send', 'App\Controllers\Admin\UserController:send')->add(new SuperAdmin()); $this->post('/user/create', 'App\Controllers\Admin\UserController:createNewUser')->add(new SuperAdmin()); $this->get('/coupon', 'App\Controllers\AdminController:coupon'); $this->post('/coupon', 'App\Controllers\AdminController:addCoupon')->add(new SuperAdmin()); $this->post('/coupon/ajax', 'App\Controllers\AdminController:ajax_coupon'); $this->get('/invite', 'App\Controllers\AdminController:invite'); $this->get('/logout', 'App\Controllers\AdminController:logout'); $this->post('/payback/ajax', 'App\Controllers\AdminController:ajax_payback'); //checkout apply $this->get('/checkout', 'App\Controllers\Admin\CheckoutController:index'); $this->post('/checkout', 'App\Controllers\Admin\CheckoutController:deal')->add(new SuperAdmin()); $this->post('/checkout/ajax', 'App\Controllers\Admin\CheckoutController:ajax'); //log apply // stats $this->get('/api/analytics/income', 'App\Controllers\AdminController:getIncome'); $this->get('/api/analytics/new-users', 'App\Controllers\AdminController:newUsers'); $this->get('/api/analytics/month-income', 'App\Controllers\AdminController:monthIncome'); $this->get('/api/analytics/month-new-user-paid-rate', 'App\Controllers\AdminController:monthNewUserPaidRate'); $this->get('/site-analytics', 'App\Controllers\Admin\SiteAnalyticsController:index'); $this->get('/site-analytics/data', 'App\Controllers\Admin\SiteAnalyticsController:data'); $this->get('/site-analytics/security', 'App\Controllers\Admin\SiteAnalyticsController:security'); //email log $this->get('/email', 'App\Controllers\Admin\LogController:emailLog'); $this->post('/email/ajax', 'App\Controllers\Admin\LogController:ajax_emailLog'); $this->get('/config', 'App\Controllers\Admin\ConfigController:config'); $this->get('/config/get', 'App\Controllers\Admin\ConfigController:get'); $this->post('/config/save', 'App\Controllers\Admin\ConfigController:save')->add(new SuperAdmin()); $this->post('/config/trusted-login-devices/clear', 'App\Controllers\Admin\ConfigController:clearTrustedLoginDevices')->add(new SuperAdmin()); $this->post('/config/login-sessions/clear', 'App\Controllers\Admin\ConfigController:clearLoginSessions')->add(new SuperAdmin()); })->add(new Admin()); // API $app->group('/api', function () { $this->get('/captch', 'App\Controllers\ApiController:createCaptch'); }); $app->get('/paytaro/callback', 'App\Controllers\PaytaroController:callback'); $app->post('/paytaro/callback', 'App\Controllers\PaytaroController:callback'); $app->get('/paytaro/callback/', 'App\Controllers\PaytaroController:callback'); $app->post('/paytaro/callback/', 'App\Controllers\PaytaroController:callback'); $app->get('/paytaro/return', 'App\Controllers\PaytaroController:handleReturn'); $app->post('/paytaro/return', 'App\Controllers\PaytaroController:handleReturn'); $app->post('/paytaro/status', 'App\Controllers\PaytaroController:status'); $app->get('/yipay/callback', 'App\Controllers\YipayController:callback'); $app->get('/yipay/return', 'App\Controllers\YipayController:handleReturn'); // Run Slim Routes for App require BASE_PATH . '/config/routes_cloud.php'; $app->add(new \App\Middleware\SiteAnalytics()); $app->run();