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:
1 parent
1d49e6f5ee
commit
18101cf11a
636 files changed
+58517
-9519
No files matched your search
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | YwxApp [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | {%title%}(由 addon:crud 生成,可按需修改)
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace {%namespace%};
|
||||
|
||||
use think\facade\Request;
|
||||
use think\Validate;
|
||||
use ywxapp\controller\BackendBase;
|
||||
// 模型与控制器同名,必须用别名导入,否则「类名已占用」编译错误
|
||||
use {%modelNs%} as {%modelAlias%};
|
||||
|
||||
/**
|
||||
* {%title%}
|
||||
*
|
||||
* 权限节点(menu.json 注入后由 php think addon:manage <插件> -a reload 生效):
|
||||
* 列表 index
|
||||
* 新增 add
|
||||
* 编辑 update
|
||||
* 删除 delete
|
||||
*/
|
||||
class {%className%} extends BackendBase
|
||||
{
|
||||
/**
|
||||
* 免登录动作
|
||||
* @var array
|
||||
*/
|
||||
protected $noNeedLogin = [];
|
||||
|
||||
/**
|
||||
* 免鉴权动作
|
||||
* @var array
|
||||
*/
|
||||
protected $noNeedVerify = [];
|
||||
|
||||
protected function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表(AJAX 返回 layui 表格数据)
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
$page = (int) $this->request->param('page', 1);
|
||||
$limit = (int) $this->request->param('limit', 15);
|
||||
$query = {%modelAlias%}::where('{%pk%}', '>', 0);{%search%}
|
||||
$data = $query->order('{%pk%}', 'desc')->paginate([
|
||||
'page' => $page,
|
||||
'list_rows' => $limit,
|
||||
]);
|
||||
// 必须回传 count,否则 layui 表格分页失效
|
||||
return json(['code' => 0, 'msg' => '', 'count' => $data->total(), 'data' => $data->items()]);
|
||||
}
|
||||
return $this->view->fetch('{%viewDir%}/index');
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
return $this->saveRow(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
return $this->saveRow((int) Request::post('id', 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除(软删除字段存在时为软删除)
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$id = (int) Request::post('id', 0);
|
||||
if ($id <= 0) {
|
||||
return json(['code' => 0, 'msg' => '参数错误']);
|
||||
}
|
||||
$row = {%modelAlias%}::find($id);
|
||||
if (!$row) {
|
||||
return json(['code' => 0, 'msg' => '记录不存在']);
|
||||
}
|
||||
$row->delete();
|
||||
return json(['code' => 1, 'msg' => '已删除']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入(新增 / 更新共用)
|
||||
*/
|
||||
protected function saveRow(int $id)
|
||||
{
|
||||
$data = Request::post();
|
||||
|
||||
$validate = new Validate([{%rules%}]);
|
||||
if (!$validate->check($data)) {
|
||||
return json(['code' => 0, 'msg' => $validate->getError()]);
|
||||
}
|
||||
|
||||
// 字段白名单,避免把非表字段写进 SQL
|
||||
$allow = [{%allow%}];
|
||||
|
||||
try {
|
||||
if ($id > 0) {
|
||||
$row = {%modelAlias%}::find($id);
|
||||
if (!$row) {
|
||||
return json(['code' => 0, 'msg' => '记录不存在']);
|
||||
}
|
||||
$row->allowField($allow)->save($data);
|
||||
} else {
|
||||
{%modelAlias%}::create($data, $allow);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
return json(['code' => 0, 'msg' => '保存失败:' . $e->getMessage()]);
|
||||
}
|
||||
|
||||
return json(['code' => 1, 'msg' => '保存成功']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
/**
|
||||
* {%title%} —— 由 addon:crud 生成
|
||||
*
|
||||
* 权限:auth.setController('{%perm%}') 与后端权限节点 {%perm%}:add|update|delete 对齐,
|
||||
* 表格渲染后由 auth.filterDom() 移除无权限按钮。
|
||||
*/
|
||||
layui.define(['table', 'layer', 'form', 'laytpl', 'util', 'auth', 'http', 'jquery'], function (exports) {
|
||||
var table = layui.table,
|
||||
layer = layui.layer,
|
||||
form = layui.form,
|
||||
laytpl = layui.laytpl,
|
||||
auth = layui.auth,
|
||||
http = layui.http,
|
||||
$ = layui.jquery;
|
||||
|
||||
// 权限控制器前缀(与 backend_power.name 对齐)
|
||||
auth.setController('{%perm%}');
|
||||
|
||||
// 请求地址只写动作名:http 的 baseURL 为空,URL 由浏览器按「当前页面所在目录」
|
||||
// 解析,而后台页面本身就是 /.../<控制器>/index.html。写成 <控制器>/index
|
||||
// 会拼成 /.../<控制器>/<控制器>/index → 404(插件与核心后台都一样)。
|
||||
var FUNC = {
|
||||
index: 'index',
|
||||
add: 'add',
|
||||
update: 'update',
|
||||
delete: 'delete'
|
||||
},
|
||||
FORM_ID = '{%var%}-form';
|
||||
|
||||
/**
|
||||
* 打开新增 / 编辑弹窗
|
||||
*/
|
||||
function openForm(data) {
|
||||
var html = laytpl($('#dataFormTpl').html()).render(data || {});
|
||||
layer.open({
|
||||
type: 1,
|
||||
title: (data && data.id) ? '编辑' : '新增',
|
||||
area: ['720px', 'auto'],
|
||||
content: html,
|
||||
success: function () {
|
||||
form.render();
|
||||
form.on('submit(' + FORM_ID + '-submit)', function (obj) {
|
||||
var url = obj.field.id ? FUNC.update : FUNC.add;
|
||||
http.post(url, obj.field).then(function (res) {
|
||||
if (res && res.code === 1) {
|
||||
layer.msg(res.msg || '保存成功', {icon: 1});
|
||||
layer.closeAll('page');
|
||||
table.reload('dataTable');
|
||||
} else {
|
||||
layer.msg((res && res.msg) || '保存失败', {icon: 2});
|
||||
}
|
||||
}).catch(function (err) {
|
||||
layer.msg('请求失败:' + (err && err.message ? err.message : '网络异常'), {icon: 2});
|
||||
});
|
||||
return false;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var obj = {
|
||||
render: function () {
|
||||
table.render({
|
||||
elem: '#dataTable',
|
||||
url: FUNC.index,
|
||||
toolbar: '#toolbar',
|
||||
defaultToolbar: ['filter', 'print', 'exports'],
|
||||
method: 'get',
|
||||
cols: [[
|
||||
{%cols%},
|
||||
{title: '操作', width: 130, templet: '#action', fixed: 'right'}
|
||||
]],
|
||||
page: true,
|
||||
limit: 15,
|
||||
limits: [15, 30, 50, 100],
|
||||
response: {statusCode: 0},
|
||||
parseData: function (res) {
|
||||
return {
|
||||
code: res.code,
|
||||
msg: res.msg,
|
||||
count: res.count,
|
||||
data: res.data || []
|
||||
};
|
||||
},
|
||||
done: function () {
|
||||
// 按权限移除无权限按钮(工具条 / 行操作按钮)
|
||||
var view = $('#dataTable').next('.layui-table-view');
|
||||
auth.filterDom(view);
|
||||
auth.filterDom('.layui-btn[data-perm]');
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
events: function () {
|
||||
// 顶部工具条
|
||||
table.on('toolbar(dataTable)', function (o) {
|
||||
if (o.event === 'add') {
|
||||
if (!auth.has('{%permPrefix%}add')) { return layer.msg('无权限', {icon: 2}); }
|
||||
openForm({});
|
||||
}
|
||||
});
|
||||
|
||||
// 行内操作
|
||||
table.on('tool(dataTable)', function (o) {
|
||||
if (o.event === 'edit') {
|
||||
if (!auth.has('{%permPrefix%}update')) { return layer.msg('无权限', {icon: 2}); }
|
||||
openForm(o.data);
|
||||
} else if (o.event === 'delete') {
|
||||
if (!auth.has('{%permPrefix%}delete')) { return layer.msg('无权限', {icon: 2}); }
|
||||
layer.confirm('确定删除该记录吗?', {title: '提示'}, function (index) {
|
||||
http.post(FUNC.delete, {id: o.data.id}).then(function (res) {
|
||||
if (res && res.code === 1) {
|
||||
layer.msg(res.msg || '已删除', {icon: 1});
|
||||
table.reload('dataTable');
|
||||
} else {
|
||||
layer.msg((res && res.msg) || '删除失败', {icon: 2});
|
||||
}
|
||||
}).catch(function (err) {
|
||||
layer.msg('请求失败:' + (err && err.message ? err.message : '网络异常'), {icon: 2});
|
||||
});
|
||||
layer.close(index);
|
||||
});
|
||||
}
|
||||
});
|
||||
{%searchEvent%} }
|
||||
};
|
||||
|
||||
obj.render();
|
||||
obj.events();
|
||||
|
||||
exports('{%module%}', obj);
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | YwxApp [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | 由 addon:crud 生成,可按需修改
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace {%namespace%};
|
||||
|
||||
{%use%}use ywxapp\model\BaseModel;
|
||||
|
||||
class {%className%} extends BaseModel
|
||||
{{%traits%}
|
||||
{%options%}
|
||||
|
||||
/**
|
||||
* 表结构自愈:从 public/install/install.sql 提取本表 CREATE TABLE 执行。
|
||||
* 建表责任绑定在模型本身,核心库不再按业务域聚合自愈。
|
||||
*/
|
||||
public static function ensureSchema(): void
|
||||
{
|
||||
self::ensureTableFromInstall(self::currentPrefix(), '{%table%}');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<div class="layui-fluid">
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-header">{%title%}</div>
|
||||
<div class="layui-card-body">
|
||||
{%searchBar%} <table class="layui-hide" id="dataTable" lay-filter="dataTable"></table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 表格顶部工具条 -->
|
||||
<script type="text/html" id="toolbar">
|
||||
<div class="layui-btn-group">
|
||||
<button class="layui-btn layui-btn-sm" lay-event="add" data-perm="{%permPrefix%}add">
|
||||
<i class="layui-icon layui-icon-add-1"></i> 新增
|
||||
</button>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<!-- 行操作按钮 -->
|
||||
<script type="text/html" id="action">
|
||||
<div class="layui-btn-group">
|
||||
<button class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit" data-perm="{%permPrefix%}update">编辑</button>
|
||||
<button class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete" data-perm="{%permPrefix%}delete">删除</button>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
{%statusTpl%}
|
||||
<!-- 新增 / 编辑表单模板(弹窗渲染) -->
|
||||
<script type="text/html" id="dataFormTpl">
|
||||
<form class="layui-form layui-form-pane" lay-filter="{%var%}-form" id="{%var%}-form" style="padding:15px">
|
||||
<input type="hidden" name="id" value="{{d.id||''}}">
|
||||
{%formItems%}
|
||||
<div class="layui-form-item layui-hide">
|
||||
<button class="layui-btn" lay-submit lay-filter="{%var%}-form-submit" id="{%var%}-form-submit">提交</button>
|
||||
</div>
|
||||
</form>
|
||||
</script>
|
||||
|
||||
<script>
|
||||
layui.use(['{%module%}'], function () {});
|
||||
</script>
|
||||
Reference in new issue
Block a user