Files
YwxAppThink/ywxapp/library/TemplateMenu.php
T
yangwx 18101cf11a feat: 上线前安全加固与发布工程化;appmall 由插件迁移为独立应用
安全(P0)
- 发布包签名:新增 scripts/package_keygen.php、scripts/package_verify.php、
  ywxapp\service\PackageVerifier;FrameworkService::apply() 解压前强制验签
  (ywxapp.framework_package_verify,默认开启)
- JWT 收紧:config/jwt.php 移除公开默认密钥,JwtService::assertStrongSecret()
  校验非空 / 长度≥32 / 已知弱值;.env.production.example 键名由 JWT_SECRET_KEY 修正为 JWT_SECRET
- /api/v1/Article:免登录白名单收窄为只读接口,写操作字段白名单 + assertOwner() 越权校验
- 开发者令牌:查找接口不再回显明文、统一失败文案 + 限流
- TemplateInstaller:文件名白名单 + realpath 归一化 + 目录内断言,修复 Zip Slip;补 use ZipArchive
- 后台登录:接入验证码、失败锁定与登录限流(config/ratelimit.php)
- 缓存 / Session 驱动可由 .env 覆盖(CACHE_DRIVER / SESSION_TYPE),集群部署改 redis
- paycenter 支付日志开关改为 PAY_LOG,不再跟随 APP_DEBUG

工程化 / 交付
- 新增 CHANGELOG.md 与 .env.production.example;composer.lock 入库锁定依赖版本
- 插件离线安装 CLI 增加 --uid,后台上传安装透传 uid,付费插件授权校验可通过
- 授权拒绝文案区分「未携带 uid」与「未找到有效授权」,便于排障
- .gitignore 放行 .env.production.example / .env.addon.example / .gitattributes / public/.htaccess

结构
- appmall 由 addon/appmall 迁移为独立应用 app/appmall(市场 / 开发者中心 / 审核 / 分润)
2026-10-22 00:53:39 +08:00

130 lines
4.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
// +----------------------------------------------------------------------
// | YwxApp [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2026-2036 http://ywxapp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: ywxapp<admin@ywxapp.cn>
// +----------------------------------------------------------------------
namespace ywxapp\library;
use ywxapp\model\BackendPower;
/**
* 模板/皮肤管理的后台菜单入口维护器(幂等)。
*
* 背景:Template 控制器(模板中心 / 界面设置)属于内置模块,但历史上没有向
* backend_power 写入入口,导致这两张页面在后台左侧菜单里不可达。
* 本类补上这个缺口——按 name 查重,存在则跳过,可安全重复执行。
*
* 菜单结构(顶级「界面」目录 + 两个子菜单):
* 界面(目录 template, route='/template')
* ├─ 模板中心(template:index -> template/index)
* └─ 界面设置(template:setting -> template/setting)
*
* 说明:install.sql 里初始数据的 route 一律是相对后台 app 的路径(如 navbar/index),
* 这里保持一致。老站点在后台点一次「同步菜单」即可补入口,无需重装。
*
* @author ywxapp <admin@ywxapp.cn>
*/
class TemplateMenu
{
/** 顶级目录的权限标识 */
public const ROOT = 'template';
/**
* 子菜单定义:name / title / route / icon / sort
*/
public static function items(): array
{
return [
[
'name' => 'template:index',
'title' => '模板中心',
'route' => 'template/index',
'icon' => 'layui-icon layui-icon-template',
'sort' => 1,
],
[
'name' => 'template:setting',
'title' => '界面设置',
'route' => 'template/setting',
'icon' => 'layui-icon layui-icon-theme',
'sort' => 2,
],
];
}
/**
* 幂等补建菜单入口。
*
* @return array [ok, created, message]
*/
public static function sync(): array
{
try {
$root = BackendPower::where('name', self::ROOT)->find();
if (empty($root)) {
BackendPower::create([
'pid' => 0,
'title' => '界面',
'name' => self::ROOT,
'type' => 1,
'route' => '/template',
'icon' => 'layui-icon layui-icon-template',
'sort' => 5,
'status' => 1,
'addon' => null,
]);
$root = BackendPower::where('name', self::ROOT)->find();
}
if (empty($root)) {
return ['ok' => false, 'created' => 0, 'message' => '顶级目录创建失败'];
}
$pid = (int) $root->id;
$created = 0;
foreach (self::items() as $item) {
$exists = BackendPower::where('name', $item['name'])->find();
if (! empty($exists)) {
continue; // 幂等:已存在跳过
}
BackendPower::create([
'pid' => $pid,
'title' => $item['title'],
'name' => $item['name'],
'type' => 2,
'route' => $item['route'],
'icon' => $item['icon'],
'sort' => $item['sort'],
'status' => 1,
'addon' => null,
]);
$created++;
}
return [
'ok' => true,
'created' => $created,
'message' => $created > 0 ? "已补建 {$created} 个菜单项" : '菜单入口已存在,无需重复创建',
];
} catch (\Throwable $e) {
// 表不存在(未安装)等情况不能影响页面
return ['ok' => false, 'created' => 0, 'message' => '同步失败:' . $e->getMessage()];
}
}
/**
* 菜单入口是否已就绪(用于决定是否提示管理员点「同步」)。
*/
public static function exists(): bool
{
try {
return (bool) BackendPower::where('name', self::ROOT)->count();
} catch (\Throwable $e) {
return true; // 查不到(未安装)就不提示
}
}
}