diff --git a/docs/PRUNING_REPORT.md b/docs/PRUNING_REPORT.md index 6bdb6432..b3f5e85e 100644 --- a/docs/PRUNING_REPORT.md +++ b/docs/PRUNING_REPORT.md @@ -26,12 +26,12 @@ - 加密备份保存在 `storage/backups`,不自动删除历史。恢复加密支付设置还需另行保管原应用密钥/环境密钥;仅 SQL 不能替代密钥保管。 - cron 为注释示例,不会在副本中启动自动任务。 -管理员 Telegram:在 `/admin/telegram` 配置开关、bot token 和独立 HTTPS 通信域名;token 与服务端生成的 webhook secret 使用 purpose-separated 密钥加密存储。升级时会尝试一次性导入旧 `config.php` 值,写入迁移标记后运行期只读数据库;示例配置已删除这些旧项。后台状态展示使用 60 秒 Redis 快照,其中 token 和 secret 始终保持密文,Redis 故障自动回退数据库,配置写入后立即失效快照;Webhook 校验、通知、注册和绑定等运行期凭据始终绕过缓存读取权威数据库。保存后注册 webhook、生成五分钟一次性绑定码,再向机器人私聊发送 `/start 绑定码`。绑定码只存哈希、事务锁消费;Webhook 使用官方 [secret token 请求头](https://core.telegram.org/bots/api#setwebhook) 校验,不在 URL 中传 secret。当前通知仅绑定一个管理员接收方,后台可重新绑定或解绑。 +管理员 Telegram:配置入口已合并到 `/admin/ticket#telegram-notifications` 的“工单系统”,独立管理页面已删除。在这里配置开关、bot token 和独立 HTTPS 通信域名;token 与服务端生成的 webhook secret 使用 purpose-separated 密钥加密存储。升级时会尝试一次性导入旧 `config.php` 值,写入迁移标记后运行期只读数据库;示例配置已删除这些旧项。后台状态展示使用 60 秒 Redis 快照,其中 token 和 secret 始终保持密文,Redis 故障自动回退数据库,配置写入后立即失效快照;Webhook 校验、通知、注册和绑定等运行期凭据始终绕过缓存读取权威数据库。保存后注册 webhook、生成五分钟一次性绑定码,再向机器人私聊发送 `/start 绑定码`。绑定码只存哈希、事务锁消费;Webhook 使用官方 [secret token 请求头](https://core.telegram.org/bots/api#setwebhook) 校验,不在 URL 中传 secret。当前通知仅绑定一个管理员接收方,后台可重新绑定或解绑。 ## 验证及限制 - 使用隔离 PHP 8.5.10 检查全部 177 个 PHP 源文件语法,32 个测试中 30 个通过、2 个因运行时缺少 sodium 扩展未能完成。涵盖路由目标、账户强密码、配置/SQL 边界、手动删除隔离、验证码、会话、邮件假客户端、配额阈值、CLI 安全等。 -- Smarty 编译全部 66 个 venix 模板,无应用引导、无真实数据库访问;143 条路由注册目标均可解析。 +- Smarty 编译全部 66 个 venix 模板,无应用引导、无真实数据库访问;独立 Telegram 管理页路由移除后,共 142 条路由注册目标可解析。 - 44 个内联脚本以两种模板分支共检查 88 次,10 个顶层 venix JS 文件语法通过;51 个完整页面展开后的 HTML 标签检查通过。 - USDT 模拟扫描与 SQLite 内存库重复入账测试通过。易支付/Paytaro 完整测试受隔离运行时缺少 sodium 扩展限制,不能记为完整通过;保留真实加密实现,未做降级。生产运行仍需对应 PHP sodium 扩展。 - 依赖按现有 Composer lock 安装到临时测试目录,未升级项目锁定版本、未给网站安装运行依赖。 diff --git a/web/app/Controllers/Admin/TelegramController.php b/web/app/Controllers/Admin/TelegramController.php index b9e882ff..33e62dc3 100644 --- a/web/app/Controllers/Admin/TelegramController.php +++ b/web/app/Controllers/Admin/TelegramController.php @@ -10,31 +10,6 @@ use App\Services\TicketTelegramNotifier; final class TelegramController extends AdminController { - public function index($request, $response, $args) - { - $status = TicketTelegramNotifier::bindingStatus(); - try { - $config = TicketTelegramConfig::publicValues(); - } catch (\Throwable $exception) { - $config = [ - 'enabled' => false, - 'webhook_base_url' => '', - 'webhook_url' => '', - 'bot_token_configured' => false, - 'webhook_secret_configured' => false, - 'configured' => false, - 'configuration_error' => 'Telegram 配置读取失败,请检查数据库与 cloud_payload_key', - ]; - } - return $this->view() - ->assign('telegram_config', $config) - ->assign('telegram_enabled', $config['enabled']) - ->assign('telegram_configured', $config['configured']) - ->assign('telegram_bound', $status['bound']) - ->assign('telegram_admin_id', $status['admin_id']) - ->display('admin/telegram/index.tpl'); - } - public function save($request, $response, $args) { if (!$this->canManageBinding()) { @@ -151,7 +126,7 @@ final class TelegramController extends AdminController private function safeConfigurationMessage(\RuntimeException $exception): string { $message = $exception->getMessage(); - foreach (['Telegram ', 'PHP sodium ', '请在管理员 Telegram '] as $safePrefix) { + foreach (['Telegram ', 'PHP sodium ', '请在工单系统的 Telegram '] as $safePrefix) { if (str_starts_with($message, $safePrefix)) { return $message; } diff --git a/web/app/Controllers/Admin/TicketController.php b/web/app/Controllers/Admin/TicketController.php index 2a363b37..3f74bbce 100644 --- a/web/app/Controllers/Admin/TicketController.php +++ b/web/app/Controllers/Admin/TicketController.php @@ -9,6 +9,8 @@ use voku\helper\AntiXSS; use App\Services\Auth; use App\Services\AdminDataMasker; use App\Services\AdminPermission; +use App\Services\TicketTelegramConfig; +use App\Services\TicketTelegramNotifier; use App\Services\Mail; use App\Services\Config; @@ -28,7 +30,47 @@ class TicketController extends AdminController $table_config['default_show_column'] = array("op", "id", "datetime", "title", "userid", "user_name", "status"); $table_config['ajax_url'] = 'ticket/ajax'; - return $this->view()->assign('table_config', $table_config)->display('admin/ticket/index.tpl'); + $view = $this->view()->assign('table_config', $table_config); + if (AdminPermission::isSuperAdmin()) { + $telegram = $this->telegramViewState(); + $view + ->assign('telegram_config', $telegram['config']) + ->assign('telegram_enabled', $telegram['config']['enabled']) + ->assign('telegram_configured', $telegram['config']['configured']) + ->assign('telegram_bound', $telegram['binding']['bound']) + ->assign('telegram_admin_id', $telegram['binding']['admin_id']); + } + return $view->display('admin/ticket/index.tpl'); + } + + private function telegramViewState(): array + { + $binding = ['bound' => false, 'admin_id' => null]; + $bindingError = ''; + try { + $binding = TicketTelegramNotifier::bindingStatus(); + } catch (\Throwable $exception) { + $bindingError = 'Telegram 绑定状态读取失败,请检查数据库日志'; + } + + try { + $config = TicketTelegramConfig::publicValues(); + } catch (\Throwable $exception) { + $config = [ + 'enabled' => false, + 'webhook_base_url' => '', + 'webhook_url' => '', + 'bot_token_configured' => false, + 'webhook_secret_configured' => false, + 'configured' => false, + 'configuration_error' => 'Telegram 配置读取失败,请检查数据库与 cloud_payload_key', + ]; + } + if ($bindingError !== '' && ($config['configuration_error'] ?? '') === '') { + $config['configuration_error'] = $bindingError; + } + + return ['config' => $config, 'binding' => $binding]; } diff --git a/web/app/Services/TicketTelegramConfig.php b/web/app/Services/TicketTelegramConfig.php index 4921a114..968cec53 100644 --- a/web/app/Services/TicketTelegramConfig.php +++ b/web/app/Services/TicketTelegramConfig.php @@ -83,7 +83,7 @@ final class TicketTelegramConfig self::assertBotToken($token); self::assertWebhookSecret($secret); if ($baseUrl === '') { - throw new \RuntimeException('请在管理员 Telegram 页面配置独立 HTTPS 通信域名'); + throw new \RuntimeException('请在工单系统的 Telegram 设置中配置独立 HTTPS 通信域名'); } return [ diff --git a/web/app/Services/TicketTelegramNotifier.php b/web/app/Services/TicketTelegramNotifier.php index 3e61e19f..ffc4d559 100644 --- a/web/app/Services/TicketTelegramNotifier.php +++ b/web/app/Services/TicketTelegramNotifier.php @@ -195,7 +195,7 @@ final class TicketTelegramNotifier 'Telegram Webhook 密钥', 'Telegram 通信域名', 'PHP sodium ', - '请在管理员 Telegram ', + '请在工单系统的 Telegram ', ] as $safePrefix) { if (str_starts_with($message, $safePrefix)) { return $message; diff --git a/web/config/routes.php b/web/config/routes.php index 4b979e8c..66ee28bc 100644 --- a/web/config/routes.php +++ b/web/config/routes.php @@ -165,7 +165,8 @@ $app->group('/admin', function () { $this->get('/cloud/instances', 'App\Controllers\Admin\CloudPageController:instances'); $this->get('/cloud/orders', 'App\Controllers\Admin\CloudPageController:orders'); $this->get('/update', 'App\Controllers\Admin\CloudPageController:update')->add(new SuperAdmin()); - $this->get('/telegram', 'App\Controllers\Admin\TelegramController:index'); + // 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()); diff --git a/web/resources/views/venix/admin/index.tpl b/web/resources/views/venix/admin/index.tpl index 004e789e..ffb91f2b 100644 --- a/web/resources/views/venix/admin/index.tpl +++ b/web/resources/views/venix/admin/index.tpl @@ -1,5 +1,5 @@ {assign var=admin_title value='管理概览'}{assign var=admin_active value='index'}{include file='admin/static_header.tpl'}

管理概览

管理账户、商品、支付、公告和工单。虚拟化服务尚未接入。

-

注册账户

{$sts->getTotalUser()}

用户列表

商品与订单

云服务器套餐

商品管理 · 订单记录

服务支持

工单与通知

工单管理 · Telegram 工单提醒
+

注册账户

{$sts->getTotalUser()}

用户列表

商品与订单

云服务器套餐

商品管理 · 订单记录

服务支持

工单系统

工单与 Telegram 通知
宿主机设置准备

宿主机页面仅展示后续配置结构,不会保存凭据或建立连接。

查看宿主机设置
{include file='admin/static_footer.tpl'} diff --git a/web/resources/views/venix/admin/static_header.tpl b/web/resources/views/venix/admin/static_header.tpl index 873b1db7..0c684cff 100644 --- a/web/resources/views/venix/admin/static_header.tpl +++ b/web/resources/views/venix/admin/static_header.tpl @@ -151,10 +151,9 @@
  • 提现管理
  • -
  • 工单管理
  • +
  • 工单系统
  • 配置文件
  • -
  • Telegram 工单提醒
  • 宿主机设置
  • diff --git a/web/resources/views/venix/admin/ticket/index.tpl b/web/resources/views/venix/admin/ticket/index.tpl index 42509dbd..9e631f3c 100644 --- a/web/resources/views/venix/admin/ticket/index.tpl +++ b/web/resources/views/venix/admin/ticket/index.tpl @@ -1,13 +1,16 @@ -{assign var=admin_title value='工单管理'} +{assign var=admin_title value='工单系统'} {assign var=admin_active value='ticket'} {include file='admin/static_header.tpl'} -
    +
    -

    工单管理

    -

    查看用户提交的工单,快速筛选待处理与已关闭记录。

    +

    工单系统

    +

    集中处理用户工单,并管理 Telegram 工单通知。

    -
    +
    + {if $admin_can_manage|default:false} + 通知设置 + {/if} @@ -251,4 +254,6 @@ {/literal} +{if $admin_can_manage|default:false}{include file='admin/ticket/telegram_settings.tpl'}{/if} + {include file='admin/static_footer.tpl'} diff --git a/web/resources/views/venix/admin/telegram/index.tpl b/web/resources/views/venix/admin/ticket/telegram_settings.tpl similarity index 95% rename from web/resources/views/venix/admin/telegram/index.tpl rename to web/resources/views/venix/admin/ticket/telegram_settings.tpl index 111785ae..05e2f68f 100644 --- a/web/resources/views/venix/admin/telegram/index.tpl +++ b/web/resources/views/venix/admin/ticket/telegram_settings.tpl @@ -1,13 +1,11 @@ -{assign var=admin_title value='Telegram 工单提醒'} -{assign var=admin_active value='telegram'} -{include file='admin/static_header.tpl'} +
    -
    +
    -

    Telegram 工单提醒

    +
    Telegram 工单提醒

    配置工单机器人、独立通信域名和管理员私聊接收账号。用户仍只通过网站查看与回复工单。

    -
    +
    {if $telegram_enabled && $telegram_configured}通知服务已就绪{elseif $telegram_enabled}配置尚未完成{else}通知服务未启用{/if} @@ -105,6 +103,7 @@
    等待操作
    +
    {literal} {/literal} -{include file='admin/static_footer.tpl'} diff --git a/web/tests/PrunedProjectContractTest.php b/web/tests/PrunedProjectContractTest.php index e7fd3955..e4c2d92c 100644 --- a/web/tests/PrunedProjectContractTest.php +++ b/web/tests/PrunedProjectContractTest.php @@ -15,6 +15,14 @@ foreach (['/community', '/paid-registration', '/trafficlog', '/tcplog', '/tcpmon } $assert(!is_dir($root . '/resources/views/material') && !is_dir($root . '/resources/views/codex'), 'Retired templates remain'); $assert(is_file($root . '/resources/views/venix/admin/hosts/index.tpl'), 'Host administration template missing'); +$assert(!str_contains($routes, "get('/telegram'"), 'Standalone administrator Telegram page route remains'); +$assert(!is_file($root . '/resources/views/venix/admin/telegram/index.tpl'), 'Standalone administrator Telegram page template remains'); +$ticketSystem = file_get_contents($root . '/resources/views/venix/admin/ticket/index.tpl'); +$ticketTelegram = $root . '/resources/views/venix/admin/ticket/telegram_settings.tpl'; +$adminSidebar = file_get_contents($root . '/resources/views/venix/admin/static_header.tpl'); +$assert(is_file($ticketTelegram) && str_contains($ticketSystem, "admin/ticket/telegram_settings.tpl"), 'Ticket system Telegram settings were not integrated'); +$assert(str_contains($ticketSystem, "value='工单系统'") && str_contains($adminSidebar, '工单系统'), 'Ticket system label was not updated'); +$assert(!str_contains($adminSidebar, 'href="/admin/telegram"'), 'Standalone administrator Telegram navigation remains'); $config = file_get_contents($root . '/config/.config.php.example'); foreach (['user_try', 'reg_method', 'user_class_default', 'enable_class_expire_reset', 'auto_clean_', 'auto_backup_webroot', 'mu_suffix', 'mu_regex', 'checkinMin', 'enable_documents', 'subUrl', 'tgUrl', 'enable_telegram', 'telegram_token', 'telegram_request_token', 'chatgpt_api'] as $key) { $assert(!str_contains($config, $key), 'Retired configuration remains: ' . $key);