feat: merge Telegram settings into ticket system

dev
admin 2 months ago
parent 1e2f8aba60
commit 34259bd277

@ -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 安装到临时测试目录,未升级项目锁定版本、未给网站安装运行依赖。

@ -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;
}

@ -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];
}

@ -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 [

@ -195,7 +195,7 @@ final class TicketTelegramNotifier
'Telegram Webhook 密钥',
'Telegram 通信域名',
'PHP sodium ',
'请在管理员 Telegram ',
'请在工单系统的 Telegram ',
] as $safePrefix) {
if (str_starts_with($message, $safePrefix)) {
return $message;

@ -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());

@ -1,5 +1,5 @@
{assign var=admin_title value='管理概览'}{assign var=admin_active value='index'}{include file='admin/static_header.tpl'}
<div class="py-3"><h4 class="fs-20 fw-semibold">管理概览</h4><p class="text-muted">管理账户、商品、支付、公告和工单。虚拟化服务尚未接入。</p></div>
<div class="row g-3"><div class="col-md-4"><div class="card"><div class="card-body"><p>注册账户</p><h3>{$sts->getTotalUser()}</h3><a href="/admin/user">用户列表</a></div></div></div><div class="col-md-4"><div class="card"><div class="card-body"><p>商品与订单</p><h3>云服务器套餐</h3><a href="/admin/shop">商品管理</a> · <a href="/admin/bought">订单记录</a></div></div></div><div class="col-md-4"><div class="card"><div class="card-body"><p>服务支持</p><h3>工单与通知</h3><a href="/admin/ticket">工单管理</a> · <a href="/admin/telegram">Telegram 工单提醒</a></div></div></div></div>
<div class="row g-3"><div class="col-md-4"><div class="card"><div class="card-body"><p>注册账户</p><h3>{$sts->getTotalUser()}</h3><a href="/admin/user">用户列表</a></div></div></div><div class="col-md-4"><div class="card"><div class="card-body"><p>商品与订单</p><h3>云服务器套餐</h3><a href="/admin/shop">商品管理</a> · <a href="/admin/bought">订单记录</a></div></div></div><div class="col-md-4"><div class="card"><div class="card-body"><p>服务支持</p><h3>工单系统</h3><a href="/admin/ticket">工单与 Telegram 通知</a></div></div></div></div>
<div class="card"><div class="card-body"><h5>宿主机设置准备</h5><p>宿主机页面仅展示后续配置结构,不会保存凭据或建立连接。</p><a class="btn btn-primary" href="/admin/hosts">查看宿主机设置</a></div></div>
{include file='admin/static_footer.tpl'}

@ -151,10 +151,9 @@
<li><a class="{if $admin_active|default:'' == 'checkout'}active{/if}" href="/admin/checkout"><i class="mdi mdi-cash-refund"></i><span>提现管理</span></a></li>
<li><a class="{if $admin_active|default:'' == 'ticket'}active{/if}" href="/admin/ticket"><i class="mdi mdi-message-question-outline"></i><span>工单管理</span></a></li>
<li><a class="{if $admin_active|default:'' == 'ticket'}active{/if}" href="/admin/ticket"><i class="mdi mdi-message-question-outline"></i><span>工单系统</span></a></li>
<li><a class="{if $admin_active|default:'' == 'config'}active{/if}" href="/admin/config"><i class="mdi mdi-file-cog-outline"></i><span>配置文件</span></a></li>
<li><a class="{if $admin_active|default:'' == 'telegram'}active{/if}" href="/admin/telegram"><i class="mdi mdi-telegram"></i><span>Telegram 工单提醒</span></a></li>
<li class="menu-title">虚拟化</li>
<li><a class="{if $admin_active|default:'' == 'hosts'}active{/if}" href="/admin/hosts"><i class="mdi mdi-router-network"></i><span>宿主机设置</span></a></li>

@ -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'}
<div class="py-3 d-flex align-items-sm-center flex-sm-row flex-column">
<div class="py-3 d-flex align-items-md-center flex-md-row flex-column">
<div class="flex-grow-1">
<h4 class="fs-20 fw-semibold mb-1">工单管理</h4>
<p class="text-muted mb-0">查看用户提交的工单,快速筛选待处理与已关闭记录。</p>
<h4 class="fs-20 fw-semibold mb-1">工单系统</h4>
<p class="text-muted mb-0">集中处理用户工单,并管理 Telegram 工单通知。</p>
</div>
<div class="text-sm-end mt-3 mt-sm-0">
<div class="text-md-end mt-3 mt-md-0 d-flex flex-wrap gap-2 justify-content-md-end">
{if $admin_can_manage|default:false}<a class="btn btn-light" href="#telegram-notifications">
<i class="mdi mdi-telegram me-1"></i>通知设置
</a>{/if}
<button id="ticketReload" class="btn btn-light" type="button">
<i class="mdi mdi-refresh me-1"></i>刷新
</button>
@ -251,4 +254,6 @@
</script>
{/literal}
{if $admin_can_manage|default:false}{include file='admin/ticket/telegram_settings.tpl'}{/if}
{include file='admin/static_footer.tpl'}

@ -1,13 +1,11 @@
{assign var=admin_title value='Telegram 工单提醒'}
{assign var=admin_active value='telegram'}
{include file='admin/static_header.tpl'}
<section id="telegram-notifications" class="mt-4" aria-labelledby="telegram-notifications-title">
<div class="py-3 d-flex align-items-sm-center flex-sm-row flex-column">
<div class="py-3 d-flex align-items-md-center flex-md-row flex-column">
<div class="flex-grow-1">
<h4 class="fs-20 fw-semibold mb-1">Telegram 工单提醒</h4>
<h5 id="telegram-notifications-title" class="fs-20 fw-semibold mb-1">Telegram 工单提醒</h5>
<p class="text-muted mb-0">配置工单机器人、独立通信域名和管理员私聊接收账号。用户仍只通过网站查看与回复工单。</p>
</div>
<div class="text-sm-end mt-3 mt-sm-0 admin-config-actions">
<div class="text-md-end mt-3 mt-md-0 admin-config-actions">
<span class="admin-config-status {if $telegram_enabled && $telegram_configured}is-success{else}is-loading{/if}" id="telegramPageStatus">
{if $telegram_enabled && $telegram_configured}通知服务已就绪{elseif $telegram_enabled}配置尚未完成{else}通知服务未启用{/if}
</span>
@ -105,6 +103,7 @@
</div>
<div class="mt-3 d-flex justify-content-end"><span class="admin-config-status" id="telegramStatus" role="status" aria-live="polite">等待操作</span></div>
</section>
{literal}
<script>
@ -167,7 +166,10 @@
if (!data) return;
document.getElementById('telegramBotToken').value = '';
document.getElementById('telegramRotateSecret').checked = false;
window.setTimeout(function () { window.location.reload(); }, 700);
window.setTimeout(function () {
window.location.hash = 'telegram-notifications';
window.location.reload();
}, 700);
});
bind.addEventListener('click', async function () {
var data = await request('/admin/telegram/bind', '');
@ -188,7 +190,10 @@
});
unbind.addEventListener('click', async function () {
if (!window.confirm('解除后将不再向当前 Telegram 账号发送工单提醒,确定解除?')) return;
if (await request('/admin/telegram/unbind', '')) window.location.reload();
if (await request('/admin/telegram/unbind', '')) {
window.location.hash = 'telegram-notifications';
window.location.reload();
}
});
webhook.addEventListener('click', async function () {
if (!window.confirm('确定把页面显示的回调地址注册到当前 Telegram Bot?')) return;
@ -203,4 +208,3 @@
})();
</script>
{/literal}
{include file='admin/static_footer.tpl'}

@ -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, '<span>工单系统</span>'), '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);

Loading…
Cancel
Save