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,75 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | YwxApp [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2026-2036 http://ywxapp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: ywxapp<admin@ywxapp.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ywxapp\command;
|
||||
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\console\input\Option;
|
||||
use ywxapp\library\DbBackup;
|
||||
|
||||
/**
|
||||
* 数据库备份命令(纯 PHP 实现,可直接挂到定时任务)
|
||||
*
|
||||
* 用法:
|
||||
* php think db:backup # 备份全部表
|
||||
* php think db:backup -t member -t member_rule # 只备份指定表
|
||||
* php think db:backup --part=5242880 --keep=7 # 5MB 分卷,只保留最近 7 份
|
||||
*
|
||||
* 还原走后台「数据库备份」页面(有二次确认,比 CLI 更安全)。
|
||||
*
|
||||
* @author ywxapp <admin@ywxapp.cn>
|
||||
*/
|
||||
class DbBackupCommand extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('db:backup')
|
||||
->addOption('table', 't', Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, '表名,可多次传入;不传=全部表')
|
||||
->addOption('part', null, Option::VALUE_OPTIONAL, '分卷字节数,默认 2097152(2MB)')
|
||||
->addOption('keep', null, Option::VALUE_OPTIONAL, '保留最近 N 份备份,超出按时间清理旧的')
|
||||
->setDescription('数据库备份(纯 PHP 实现,可用于定时任务)');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$tables = array_values(array_filter((array) $input->getOption('table')));
|
||||
$part = (int) ($input->getOption('part') ?: 2097152);
|
||||
$keep = (int) ($input->getOption('keep') ?: 0);
|
||||
|
||||
$bak = new DbBackup(null, $part);
|
||||
try {
|
||||
$res = $bak->backup($tables);
|
||||
} catch (\Throwable $e) {
|
||||
$output->writeln('<error>备份失败:' . $e->getMessage() . '</error>');
|
||||
return 1;
|
||||
}
|
||||
|
||||
$output->writeln('<info>备份完成</info>');
|
||||
$output->writeln(' 备份名:' . $res['name']);
|
||||
$output->writeln(' 分卷:' . count($res['files']) . '(' . implode(', ', $res['files']) . ')');
|
||||
$output->writeln(' 表数:' . $res['tables'] . ',行数:' . $res['rows']);
|
||||
$output->writeln(' 大小:' . round($res['size'] / 1024, 2) . ' KB');
|
||||
$output->writeln(' 目录:' . $bak->dir() . DIRECTORY_SEPARATOR . $res['name']);
|
||||
|
||||
if ($keep > 0) {
|
||||
$list = $bak->backups();
|
||||
$drop = array_slice($list, $keep);
|
||||
foreach ($drop as $item) {
|
||||
$bak->delete($item['name']);
|
||||
$output->writeln('<comment> 清理旧备份:' . $item['name'] . '</comment>');
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user