feat(protect): 验证窗补齐公告、版本更新(含自动更新)、设备已满解绑页
三块都按平台已有接口接线,不是自造流程:
1) 公告 —— GET /announcements
- 启动时拉取,未读(按最后已读 id 记在 %APPDATA%\vfy\account.ini)就弹覆盖页
- 标题/正文/上一条/下一条/序号/我知道了;正文换行按 JSON 的 \n 还原
- 点了「我知道了」才记已读,不会每次启动都烦
2) 版本更新 + 自动更新 —— GET /check-update?version=
- 加壳时可选填「程序版本」(新增 program_version 表单字段,白名单校验,落进 cfg 的 ver)
- 有更新就弹更新页:新版本号、changelog(兼容 update_notes)、稍后/立即更新
- 强制更新(update_strategy=forced)不显示「稍后」,拦在登录之前
- 立即更新:下载到 <exe>.new → 把运行中的 exe 改名 .old 腾名字 → .new 换回原路径 →
CreateProcess 重启 → 退出当前进程;失败三种情况都提示且回滚
- cfg 没有 ver(没登记版本)就完全不检查更新,不打扰用户
3) 设备已满 —— 登录 403 DEVICE_LIMIT_EXCEEDED
- 独立页展示服务器返回的设备列表(序号/名称/ID)+ 上限 N/N
- 「解绑该设备」按输入序号、「解绑最早一台」一键,调 /unbind-device-with-auth(用刚输入的账号口令)
- 解绑成功后自动重试登录;失败给出服务器原文
配套:七套皮肤都加了这三个覆盖面板(显示时隐藏四个 tab 面板并按面板高度改窗口大小,
原生 EDIT 需强制布局一次才落到正确位置);/info 补 9 个开关字段此前已上。
实测:公告页/设备页/更新页三页都截图核对;设备页解绑后自动重登成功、旧设备软删;
自动更新用假新版本 exe 跑通(下载→改名→替换→重启,新程序写标记文件并弹框)。
壳资源 849,408 B,e2e 8 套全过。
This commit is contained in:
Binary file not shown.
@@ -334,12 +334,19 @@ func BuildCfg(appKey, appName, baseURL string) []byte {
|
||||
|
||||
// BuildCfgThemed 生成壳用的配置;theme 决定验证界面用哪套皮肤(DuiLib 壳读取)
|
||||
func BuildCfgThemed(appKey, appName, baseURL, theme string) []byte {
|
||||
return BuildCfgThemedVer(appKey, appName, baseURL, theme, "")
|
||||
}
|
||||
|
||||
// BuildCfgThemedVer 额外带上目标程序的版本号。
|
||||
// 只有登记了版本的程序才做自动更新比对;空版本号 = 壳不打扰用户。
|
||||
func BuildCfgThemedVer(appKey, appName, baseURL, theme, ver string) []byte {
|
||||
api := fmt.Sprintf("%s/api/v1/app/%s/login", strings.TrimRight(baseURL, "/"), appKey)
|
||||
if theme == "" {
|
||||
theme = "classic"
|
||||
}
|
||||
cfg := fmt.Sprintf(`{"api":%q,"name":%q,"device_auto":1,"shell_ver":%d,"theme":%q}`,
|
||||
api, appName, shellVer, theme)
|
||||
ver = strings.TrimSpace(ver)
|
||||
cfg := fmt.Sprintf(`{"api":%q,"name":%q,"device_auto":1,"shell_ver":%d,"theme":%q,"ver":%q}`,
|
||||
api, appName, shellVer, theme, ver)
|
||||
return []byte(cfg)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package protect
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
@@ -114,6 +115,11 @@ func CreateAndRunSignedIdentity(app *model.Application, userID uint, srcName str
|
||||
|
||||
// CreateAndRunThemed 同 CreateAndRunSignedIdentity,并指定验证界面皮肤
|
||||
func CreateAndRunThemed(app *model.Application, userID uint, srcName string, data []byte, baseURL string, signProfileID *uint, certIdentity int, theme string) (*model.ProtectTask, error) {
|
||||
return CreateAndRunThemedVer(app, userID, srcName, data, baseURL, signProfileID, certIdentity, theme, "")
|
||||
}
|
||||
|
||||
// CreateAndRunThemedVer 同上,并显式指定「程序版本」(壳拿它做自动更新比对;空则不比对)
|
||||
func CreateAndRunThemedVer(app *model.Application, userID uint, srcName string, data []byte, baseURL string, signProfileID *uint, certIdentity int, theme, programVer string) (*model.ProtectTask, error) {
|
||||
if theme == "" {
|
||||
theme = "classic"
|
||||
}
|
||||
@@ -121,7 +127,11 @@ func CreateAndRunThemed(app *model.Application, userID uint, srcName string, dat
|
||||
if err != nil {
|
||||
return task, err
|
||||
}
|
||||
cfg := BuildCfgThemed(app.AppKey, app.Name, baseURL, theme)
|
||||
ver := strings.TrimSpace(programVer)
|
||||
if ver == "" {
|
||||
ver = programVersion(task.VersionID) // 没手填就退回来源版本的版本号
|
||||
}
|
||||
cfg := BuildCfgThemedVer(app.AppKey, app.Name, baseURL, theme, ver)
|
||||
go execute(task.ID, srcPath, srcName, cfg)
|
||||
return task, nil
|
||||
}
|
||||
@@ -154,13 +164,25 @@ func CreateAndRunSyncThemed(app *model.Application, userID uint, srcName string,
|
||||
database.DB.Model(task).Update("version_id", versionID)
|
||||
task.VersionID = versionID
|
||||
}
|
||||
info, err := execute(task.ID, srcPath, srcName, BuildCfgThemed(app.AppKey, app.Name, baseURL, theme))
|
||||
info, err := execute(task.ID, srcPath, srcName, BuildCfgThemedVer(app.AppKey, app.Name, baseURL, theme, programVersion(task.VersionID)))
|
||||
if err != nil {
|
||||
return task, info, err
|
||||
}
|
||||
return task, info, nil
|
||||
}
|
||||
|
||||
// programVersion 取来源版本的版本号;没有来源版本就返回空(壳不做更新比对)
|
||||
func programVersion(versionID uint) string {
|
||||
if versionID == 0 {
|
||||
return ""
|
||||
}
|
||||
var v model.Version
|
||||
if err := database.DB.First(&v, versionID).Error; err != nil {
|
||||
return ""
|
||||
}
|
||||
return v.Version
|
||||
}
|
||||
|
||||
// WaitSource 等源文件出现(版本包按需解包是异步的,最多等 3 秒)
|
||||
func WaitSource(path string) error {
|
||||
for i := 0; i < 10; i++ {
|
||||
|
||||
@@ -218,7 +218,16 @@ func HandleCreateProtectTask(c *gin.Context) {
|
||||
warnings = append(warnings, "验证界面使用 DuiLib 皮肤「"+protect.ShellThemes[theme]+"」")
|
||||
}
|
||||
|
||||
task, err := protect.CreateAndRunThemed(&app, userID, name, data, baseURL(c), signProfileID, certIdentity, theme)
|
||||
programVer := strings.TrimSpace(c.PostForm("program_version"))
|
||||
if len(programVer) > 32 {
|
||||
response.Error(c, 400, "程序版本号过长(最多 32 个字符)")
|
||||
return
|
||||
}
|
||||
if programVer != "" && !validVersionString(programVer) {
|
||||
response.Error(c, 400, "程序版本号只能包含字母、数字、点、下划线和横线,例如 1.2.3")
|
||||
return
|
||||
}
|
||||
task, err := protect.CreateAndRunThemedVer(&app, userID, name, data, baseURL(c), signProfileID, certIdentity, theme, programVer)
|
||||
if err != nil {
|
||||
response.ParamError(c, err.Error())
|
||||
return
|
||||
@@ -360,3 +369,15 @@ func HandleDeleteProtectTask(c *gin.Context) {
|
||||
database.DB.Delete(&model.ProtectTask{}, task.ID)
|
||||
response.SuccessWithMessage(c, "已删除", nil)
|
||||
}
|
||||
|
||||
// validVersionString 版本号白名单:只允许字母、数字、点、下划线、横线
|
||||
func validVersionString(v string) bool {
|
||||
for _, r := range v {
|
||||
switch {
|
||||
case r >= '0' && r <= '9', r >= 'a' && r <= 'z', r >= 'A' && r <= 'Z', r == '.', r == '_', r == '-':
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -75,6 +75,7 @@ const certSupported = computed(() => wantPlatform.value !== '')
|
||||
|
||||
// 验证界面皮肤(DuiLib 壳):classic 是原 Direct2D 壳,其余走 DuiLib
|
||||
const shellTheme = ref('classic')
|
||||
const programVersion = ref('')
|
||||
const themeOptions = computed(() => [
|
||||
{ value: 'classic', label: t('admin.protect.themeClassic') },
|
||||
{ value: 'dark', label: t('admin.protect.themeDark') },
|
||||
@@ -290,6 +291,7 @@ async function startProtect() {
|
||||
fd.append('cert_identity', selectedIdentity.value || '1')
|
||||
}
|
||||
fd.append('shell_theme', shellTheme.value)
|
||||
if (programVersion.value.trim()) fd.append('program_version', programVersion.value.trim())
|
||||
await api.postFormDataWithProgress(
|
||||
'/dev/protect/tasks',
|
||||
fd,
|
||||
@@ -553,6 +555,21 @@ onBeforeUnmount(() => {
|
||||
{{ t('admin.protect.themeHint') }}
|
||||
</p>
|
||||
|
||||
<!-- 程序版本:壳拿它和平台已发布版本比对,决定是否提示/强制更新 -->
|
||||
<div class="flex flex-col gap-3 sm:flex-row sm:items-center">
|
||||
<UiLabel class="shrink-0 text-sm font-medium">
|
||||
{{ t('admin.protect.programVersionLabel') }}
|
||||
</UiLabel>
|
||||
<UiInput
|
||||
v-model="programVersion"
|
||||
:placeholder="t('admin.protect.programVersionPlaceholder')"
|
||||
class="w-full sm:max-w-xs"
|
||||
/>
|
||||
</div>
|
||||
<p class="text-xs text-muted-foreground">
|
||||
{{ t('admin.protect.programVersionHint') }}
|
||||
</p>
|
||||
|
||||
<!-- 选中证书的状态:用途 / 吊销 / 拉黑 -->
|
||||
<div v-if="selectedCertRow" class="flex flex-wrap items-center gap-2 text-xs">
|
||||
<span class="rounded bg-muted px-1.5 py-0.5 text-muted-foreground">{{ selectedCertRow.usage_label || '-' }}</span>
|
||||
|
||||
@@ -2661,7 +2661,10 @@
|
||||
"themeCompact": "Compact banner · single row",
|
||||
"themeSplit": "Split · brand sidebar",
|
||||
"themeCard": "Wide card · two columns",
|
||||
"themeTerminal": "Terminal style"
|
||||
"themeTerminal": "Terminal style",
|
||||
"programVersionLabel": "Program version",
|
||||
"programVersionPlaceholder": "e.g. 1.2.3 (leave empty to skip update check)",
|
||||
"programVersionHint": "When set, the packaged program asks the platform for updates on startup. Publishing a newer version shows an update prompt; forced updates cannot be skipped."
|
||||
},
|
||||
"signProfiles": {
|
||||
"title": "Signing certificates",
|
||||
@@ -3432,4 +3435,4 @@
|
||||
"prevDoc": "Previous",
|
||||
"nextDoc": "Next"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2680,7 +2680,10 @@
|
||||
"themeCompact": "极简横幅 · 单行激活",
|
||||
"themeSplit": "左右分栏 · 品牌竖栏",
|
||||
"themeCard": "宽扁卡片 · 双列说明",
|
||||
"themeTerminal": "终端风 · 命令行"
|
||||
"themeTerminal": "终端风 · 命令行",
|
||||
"programVersionLabel": "程序版本",
|
||||
"programVersionPlaceholder": "例如 1.2.3(留空则不检查更新)",
|
||||
"programVersionHint": "填了版本号后,程序启动时会向平台查询是否有更新;平台里发布更高版本就会弹出更新提示,设为强制更新时不允许跳过。"
|
||||
},
|
||||
"signProfiles": {
|
||||
"title": "签名证书",
|
||||
@@ -3451,4 +3454,4 @@
|
||||
"prevDoc": "上一篇",
|
||||
"nextDoc": "下一篇"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user