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(市场 / 开发者中心 / 审核 / 分润)
This commit is contained in:
yangwx committed 2026-10-22 00:53:39 +08:00
1 parent 1d49e6f5ee
commit 18101cf11a
636 files changed
+58517 -9519

No files matched your search

+211
View File
@@ -0,0 +1,211 @@
/**
* 数据库备份 / 还原
*
* 权限按钮用完整权限名(database:backup / database:restore / database:delete / database:optimize),
* 表格渲染后由 auth.filterDom() 移除无权限按钮。
*/
layui.define(['table', 'layer', 'form', 'util', 'element', 'auth', 'http', 'jquery'], function (exports) {
var table = layui.table,
layer = layui.layer,
form = layui.form,
auth = layui.auth,
http = layui.http,
$ = layui.jquery;
// 注意:http 的 baseURL 为空,URL 由浏览器按「当前页面所在目录」解析,
// 核心后台页面的目录就是 /admin/<controller>/,所以这里只写动作名(纯相对),
// 写成 'database/index' 会被解析成 /admin/database/database/index(404)。
var FUNC = {
index: 'index',
backup: 'backup',
recovery: 'recovery',
delete: 'delete',
optimize: 'optimize',
download: 'download'
};
/**
* 统一的响应处理:Result 返回 {code, message, data, count}
*/
function parse(res) {
return {
code: res.code,
msg: res.message,
count: res.count || 0,
data: res.data || []
};
}
/**
* 提交型请求
*/
function post(url, data, okTip, done) {
var loading = layer.load(2);
http.post(url, data).then(function (res) {
layer.close(loading);
if (res && res.code === 0) {
layer.msg(okTip || res.message || '操作成功', {icon: 1});
if (done) { done(res.data); }
} else {
layer.msg((res && res.message) || '操作失败', {icon: 2});
}
}).catch(function (err) {
layer.close(loading);
layer.msg('请求失败:' + (err && err.message ? err.message : '网络异常'), {icon: 2});
});
}
/**
* 取当前勾选的表名
*/
function checkedTables() {
var rows = table.checkStatus('tableList').data || [];
var names = [];
for (var i = 0; i < rows.length; i++) {
names.push(rows[i].name);
}
return names;
}
var obj = {
renderTable: function () {
table.render({
elem: '#tableList',
url: FUNC.index,
where: {type: 'table'},
toolbar: '#tableBar',
defaultToolbar: ['filter'],
method: 'get',
cols: [[
{type: 'checkbox', width: 50},
{field: 'name', title: '表名', minWidth: 220},
{field: 'comment', title: '备注', minWidth: 160},
{field: 'engine', title: '引擎', width: 100},
{field: 'rows', title: '行数', width: 110, sort: true},
{field: 'size_text', title: '大小', width: 110}
]],
page: true,
limit: 15,
limits: [15, 30, 50, 100],
response: {statusCode: 0},
parseData: parse,
done: function () {
var view = $('#tableList').next('.layui-table-view');
auth.filterDom(view);
auth.filterDom('.layui-btn[data-perm]');
}
});
},
renderBackup: function () {
table.render({
elem: '#backupList',
url: FUNC.index,
where: {type: 'backup'},
toolbar: '#backupBar',
method: 'get',
cols: [[
{field: 'name', title: '备份名', minWidth: 220},
{field: 'parts', title: '分卷', width: 80},
{field: 'size_text', title: '大小', width: 110},
{field: 'time_text', title: '时间', width: 180, sort: true},
{title: '操作', width: 190, templet: '#backupAction', fixed: 'right'}
]],
page: true,
limit: 15,
response: {statusCode: 0},
parseData: parse,
done: function () {
var view = $('#backupList').next('.layui-table-view');
auth.filterDom(view);
auth.filterDom('.layui-btn[data-perm]');
}
});
},
events: function () {
// 数据表工具条
table.on('toolbar(tableList)', function (o) {
if (o.event === 'backupSelected' || o.event === 'backupAll') {
var names = o.event === 'backupAll' ? [] : checkedTables();
if (o.event === 'backupSelected' && names.length === 0) {
return layer.msg('请先勾选要备份的表', {icon: 2});
}
layer.confirm(
o.event === 'backupAll' ? '确认备份全部数据表?' : '确认备份选中的 ' + names.length + ' 张表?',
{title: '备份确认'},
function (index) {
layer.close(index);
post(FUNC.backup, {tables: names, part_size: 2097152}, '备份完成', function () {
table.reload('backupList');
});
}
);
} else if (o.event === 'optimize') {
var opts = checkedTables();
if (opts.length === 0) {
return layer.msg('请先勾选要优化的表', {icon: 2});
}
post(FUNC.optimize, {tables: opts}, '优化完成', function () {
table.reload('tableList');
});
}
});
// 备份记录工具条
table.on('toolbar(backupList)', function (o) {
if (o.event === 'reload') {
table.reload('backupList');
}
});
// 备份记录行操作
table.on('tool(backupList)', function (o) {
if (o.event === 'download') {
window.open(FUNC.download + '?name=' + encodeURIComponent(o.data.name));
} else if (o.event === 'recovery') {
layer.confirm(
'还原会覆盖当前同名表的数据,确定继续?<br><span style="color:#ff5722">建议先做一次新备份</span>',
{title: '危险操作', btn: ['确定还原', '取消']},
function (index) {
layer.close(index);
post(FUNC.recovery, {name: o.data.name}, '还原完成', function () {
table.reload('tableList');
});
}
);
} else if (o.event === 'delete') {
layer.confirm('确定删除该备份?', {title: '提示'}, function (index) {
layer.close(index);
post(FUNC.delete, {name: o.data.name}, '已删除', function () {
table.reload('backupList');
});
});
}
});
// 搜索
form.on('submit(data-search-btn)', function (o) {
table.reload('tableList', {where: {keyword: o.field.keyword}, page: {curr: 1}});
return false;
});
$('#btn-reset').on('click', function () {
setTimeout(function () {
table.reload('tableList', {where: {keyword: ''}, page: {curr: 1}});
}, 10);
});
// 切 tab 时修正列宽(隐藏时渲染的表格宽度会算错)
layui.element.on('tab(dbTab)', function () {
table.resize('tableList');
table.resize('backupList');
});
}
};
obj.renderTable();
obj.renderBackup();
obj.events();
exports('database', obj);
});