diff --git a/backend/internal/protect/assets/shell64_dui.bin b/backend/internal/protect/assets/shell64_dui.bin index 10817d2..7013da3 100755 Binary files a/backend/internal/protect/assets/shell64_dui.bin and b/backend/internal/protect/assets/shell64_dui.bin differ diff --git a/backend/internal/protect/protect.go b/backend/internal/protect/protect.go index a1ae80a..29973a9 100644 --- a/backend/internal/protect/protect.go +++ b/backend/internal/protect/protect.go @@ -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) } diff --git a/backend/internal/protect/task.go b/backend/internal/protect/task.go index f9f2012..1e93b2e 100644 --- a/backend/internal/protect/task.go +++ b/backend/internal/protect/task.go @@ -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++ { diff --git a/backend/internal/router/admin/protect.go b/backend/internal/router/admin/protect.go index c7a8792..35921af 100644 --- a/backend/internal/router/admin/protect.go +++ b/backend/internal/router/admin/protect.go @@ -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 +} diff --git a/frontend/src/pages/admin/protect/index.vue b/frontend/src/pages/admin/protect/index.vue index 04a4870..1ee80f3 100644 --- a/frontend/src/pages/admin/protect/index.vue +++ b/frontend/src/pages/admin/protect/index.vue @@ -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') }}

+ +
+ + {{ t('admin.protect.programVersionLabel') }} + + +
+

+ {{ t('admin.protect.programVersionHint') }} +

+
{{ selectedCertRow.usage_label || '-' }} diff --git a/frontend/src/plugins/i18n/en.json b/frontend/src/plugins/i18n/en.json index 73e719f..9ba7da4 100644 --- a/frontend/src/plugins/i18n/en.json +++ b/frontend/src/plugins/i18n/en.json @@ -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" } -} \ No newline at end of file +} diff --git a/frontend/src/plugins/i18n/zh.json b/frontend/src/plugins/i18n/zh.json index d575ace..f597b39 100644 --- a/frontend/src/plugins/i18n/zh.json +++ b/frontend/src/plugins/i18n/zh.json @@ -2680,7 +2680,10 @@ "themeCompact": "极简横幅 · 单行激活", "themeSplit": "左右分栏 · 品牌竖栏", "themeCard": "宽扁卡片 · 双列说明", - "themeTerminal": "终端风 · 命令行" + "themeTerminal": "终端风 · 命令行", + "programVersionLabel": "程序版本", + "programVersionPlaceholder": "例如 1.2.3(留空则不检查更新)", + "programVersionHint": "填了版本号后,程序启动时会向平台查询是否有更新;平台里发布更高版本就会弹出更新提示,设为强制更新时不允许跳过。" }, "signProfiles": { "title": "签名证书", @@ -3451,4 +3454,4 @@ "prevDoc": "上一篇", "nextDoc": "下一篇" } -} \ No newline at end of file +}