Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
74355c1dd2 | ||
|
|
a446a1ba37 | ||
|
|
f997035972 | ||
|
|
ead706ea52 |
@@ -4,6 +4,8 @@ app:
|
||||
port: "8080"
|
||||
jwt_secret: "your-secret-key-change-in-production"
|
||||
jwt_expire_hours: "24"
|
||||
# 加壳时写进壳 cfg 的站点根地址;留空则按请求头推断(反代需要传 X-Forwarded-Host)
|
||||
public_url: ""
|
||||
|
||||
database:
|
||||
host: "localhost"
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"verification-platform-backend/internal/config"
|
||||
"verification-platform-backend/internal/database"
|
||||
"verification-platform-backend/internal/model"
|
||||
"verification-platform-backend/internal/protect"
|
||||
@@ -31,8 +32,14 @@ func SetupProtectRoutes(r *gin.RouterGroup) {
|
||||
}
|
||||
}
|
||||
|
||||
// baseURL 从请求推断站点根地址(面板/应用共用同一域名)
|
||||
func baseURL(c *gin.Context) string {
|
||||
// baseURL 推断站点根地址(面板/应用共用同一域名)。
|
||||
//
|
||||
// 这里踩过一次真实的坑:AcePanel 默认的反代模板写的是 `proxy_set_header Host $proxy_host`,
|
||||
// 于是后端看到的 Host 是 `127.0.0.1:9998`,打包出来的每个客户端都会把
|
||||
// `https://127.0.0.1:9998/api/v1/app/<key>/login` 写进壳 cfg —— 到了客户机上根本连不上。
|
||||
// 所以:优先 X-Forwarded-Host,其次(配置里的站点地址),最后才是请求 Host;
|
||||
// 一旦推断出来是本机/内网地址,宁可让加壳任务报错,也不要产出一个连不上服务器的产物。
|
||||
func baseURL(c *gin.Context) (string, error) {
|
||||
scheme := c.GetHeader("X-Forwarded-Proto")
|
||||
if scheme == "" {
|
||||
if c.Request.TLS != nil {
|
||||
@@ -41,11 +48,48 @@ func baseURL(c *gin.Context) string {
|
||||
scheme = "http"
|
||||
}
|
||||
}
|
||||
host := c.GetHeader("X-Forwarded-Host")
|
||||
|
||||
// 反代应当带上 X-Forwarded-Host;它才是用户浏览器里那个域名
|
||||
host := strings.TrimSpace(c.GetHeader("X-Forwarded-Host"))
|
||||
if host == "" {
|
||||
host = c.Request.Host
|
||||
host = strings.TrimSpace(c.Request.Host)
|
||||
}
|
||||
return fmt.Sprintf("%s://%s", scheme, host)
|
||||
|
||||
// 站点地址可以在 config.yaml 里显式指定(app.public_url),配了就优先用
|
||||
if pub := strings.TrimRight(config.GetString("app.public_url"), "/"); pub != "" {
|
||||
return pub, nil
|
||||
}
|
||||
|
||||
if host == "" || isInternalHost(host) {
|
||||
return "", fmt.Errorf("无法推断站点地址(反向代理没有传 X-Forwarded-Host,Host 为 %q),请在 config.yaml 配置 app.public_url", host)
|
||||
}
|
||||
return fmt.Sprintf("%s://%s", scheme, host), nil
|
||||
}
|
||||
|
||||
// isInternalHost 判断 host 是不是只在本机/内网有意义(127.x、localhost、内网网段、无域名端口等)
|
||||
func isInternalHost(host string) bool {
|
||||
h := host
|
||||
if i := strings.LastIndex(h, ":"); i > 0 && !strings.Contains(h[i:], "]") {
|
||||
h = h[:i] // 去掉端口
|
||||
}
|
||||
h = strings.ToLower(strings.Trim(h, "[]"))
|
||||
switch {
|
||||
case h == "", h == "localhost", h == "0.0.0.0", h == "::1":
|
||||
return true
|
||||
case strings.HasPrefix(h, "127."), strings.HasPrefix(h, "10."), strings.HasPrefix(h, "192.168."):
|
||||
return true
|
||||
case strings.HasPrefix(h, "172."):
|
||||
// 172.16.0.0/12
|
||||
parts := strings.Split(h, ".")
|
||||
if len(parts) == 4 {
|
||||
if n, err := strconv.Atoi(parts[1]); err == nil && n >= 16 && n <= 31 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
case strings.HasPrefix(h, "169.254."):
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// HandleCreateProtectTask 上传原始程序 → 建任务 → 异步加壳
|
||||
@@ -227,7 +271,12 @@ func HandleCreateProtectTask(c *gin.Context) {
|
||||
response.Error(c, 400, "程序版本号只能包含字母、数字、点、下划线和横线,例如 1.2.3")
|
||||
return
|
||||
}
|
||||
task, err := protect.CreateAndRunThemedVer(&app, userID, name, data, baseURL(c), signProfileID, certIdentity, theme, programVer)
|
||||
siteURL, err := baseURL(c)
|
||||
if err != nil {
|
||||
response.Error(c, 400, err.Error())
|
||||
return
|
||||
}
|
||||
task, err := protect.CreateAndRunThemedVer(&app, userID, name, data, siteURL, signProfileID, certIdentity, theme, programVer)
|
||||
if err != nil {
|
||||
response.ParamError(c, err.Error())
|
||||
return
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func TestIsInternalHost(t *testing.T) {
|
||||
cases := map[string]bool{
|
||||
"127.0.0.1:9998": true,
|
||||
"127.0.0.1": true,
|
||||
"localhost:8080": true,
|
||||
"localhost": true,
|
||||
"10.0.0.5": true,
|
||||
"192.168.1.10:443": true,
|
||||
"172.16.0.1": true,
|
||||
"172.31.255.1:8080": true,
|
||||
"169.254.1.1": true,
|
||||
"": true,
|
||||
"[::1]:8080": true,
|
||||
"0.0.0.0:8080": true,
|
||||
"v.viaeon.com": false,
|
||||
"v.viaeon.com:443": false,
|
||||
"172.32.0.1": false, // 不在 172.16/12 里
|
||||
"verify.example.com": false,
|
||||
"8.8.8.8": false,
|
||||
}
|
||||
for host, want := range cases {
|
||||
if got := isInternalHost(host); got != want {
|
||||
t.Fatalf("isInternalHost(%q) = %v, want %v", host, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func newCtx(host, xfh, proto string) *gin.Context {
|
||||
gin.SetMode(gin.TestMode)
|
||||
req := httptest.NewRequest("POST", "/", nil)
|
||||
req.Host = host
|
||||
if xfh != "" {
|
||||
req.Header.Set("X-Forwarded-Host", xfh)
|
||||
}
|
||||
if proto != "" {
|
||||
req.Header.Set("X-Forwarded-Proto", proto)
|
||||
}
|
||||
c, _ := gin.CreateTestContext(httptest.NewRecorder())
|
||||
c.Request = req
|
||||
return c
|
||||
}
|
||||
|
||||
// 反代把 Host 改写成 127.0.0.1 时必须报错,绝不能把内网地址打进产物
|
||||
func TestBaseURLRejectsLoopback(t *testing.T) {
|
||||
u, err := baseURL(newCtx("127.0.0.1:9998", "", "https"))
|
||||
if err == nil {
|
||||
t.Fatalf("期望报错,实际返回 %q", u)
|
||||
}
|
||||
}
|
||||
|
||||
// 反代带了 X-Forwarded-Host 就用它
|
||||
func TestBaseURLPrefersForwardedHost(t *testing.T) {
|
||||
u, err := baseURL(newCtx("127.0.0.1:9998", "v.viaeon.com", "https"))
|
||||
if err != nil {
|
||||
t.Fatalf("期望成功,实际 %v", err)
|
||||
}
|
||||
if want := "https://v.viaeon.com"; u != want {
|
||||
t.Fatalf("baseURL = %q, want %q", u, want)
|
||||
}
|
||||
}
|
||||
|
||||
// 直连(无反代)时用请求 Host
|
||||
func TestBaseURLUsesRequestHost(t *testing.T) {
|
||||
u, err := baseURL(newCtx("v.viaeon.com", "", "https"))
|
||||
if err != nil {
|
||||
t.Fatalf("期望成功,实际 %v", err)
|
||||
}
|
||||
if want := "https://v.viaeon.com"; u != want {
|
||||
t.Fatalf("baseURL = %q, want %q", u, want)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
# 加壳产物的服务器地址是怎么来的(`app.public_url` / 反代头)
|
||||
|
||||
## 结论
|
||||
|
||||
打包时写进壳 cfg 的 `api` 字段 = `<站点根地址>/api/v1/app/<app_key>/login`。
|
||||
站点根地址按下面的顺序确定(`backend/internal/router/admin/protect.go` 的 `baseURL()`):
|
||||
|
||||
1. `config.yaml` 里的 **`app.public_url`**(配了就最优先,推荐生产环境配上)
|
||||
2. 请求头 **`X-Forwarded-Host`**(反向代理应当传,值就是用户浏览器地址栏里的域名)
|
||||
3. 请求的 `Host`
|
||||
4. 上面两者都没有,或者拿到的是本机/内网地址(`127.x` / `localhost` / `10.x` / `172.16-31.x` / `192.168.x` / `169.254.x`)→ **加壳任务直接报错**,不产出连不上服务器的产物
|
||||
|
||||
## 为什么这么写(真实事故)
|
||||
|
||||
服务器上的站点是 AcePanel 管的,它默认的反向代理模板写的是:
|
||||
|
||||
```nginx
|
||||
proxy_set_header Host $proxy_host; # ← 后端会看到 127.0.0.1:9998
|
||||
```
|
||||
|
||||
于是 `baseURL()` 推断出 `https://127.0.0.1:9998`,产出的每个客户端壳里都写着:
|
||||
|
||||
```
|
||||
{"api":"https://127.0.0.1:9998/api/v1/app/f26091ac.../login"}
|
||||
```
|
||||
|
||||
客户机上的壳去连自己的 127.0.0.1:9998 —— 必然失败。已确认修复前产出的 `data/protect/*/…_protected.exe` 全部带这个错误地址。
|
||||
|
||||
## 正确配法
|
||||
|
||||
站点反代(AcePanel → 站点 → 反向代理)里应当是:
|
||||
|
||||
```nginx
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-Host $host;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
```
|
||||
|
||||
`$host` 是请求里的域名(经 Cloudflare 到达时是 `v.viaeon.com`),`$proxy_host` 是上游地址(`127.0.0.1:9998`)。
|
||||
|
||||
懒得依赖反代的话,直接在部署目录的 `data/config.yaml` 里写死:
|
||||
|
||||
```yaml
|
||||
app:
|
||||
public_url: "https://v.viaeon.com"
|
||||
```
|
||||
|
||||
改完重启容器生效(`docker compose restart app`)。
|
||||
|
||||
## 自查方法
|
||||
|
||||
产物里直接能看出来:
|
||||
|
||||
```bash
|
||||
grep -aoE '\{"api":"[^"]*"' 产物.exe
|
||||
```
|
||||
|
||||
应该看到 `"api":"https://v.viaeon.com/api/v1/app/<key>/login"`。
|
||||
看到 `127.0.0.1` / `localhost` / 内网 IP 就是踩了这个坑,需要重新打包。
|
||||
|
||||
## 验收记录(2026-11-24)
|
||||
|
||||
- 反代改前:`proxy_set_header Host $proxy_host` → 探针实测后端收到 `Host: 127.0.0.1:9998`
|
||||
- 反代改后:`Host $host` + `X-Forwarded-Host $host` → 探针实测后端收到
|
||||
`Host: v.viaeon.com`、`X-Forwarded-Host: v.viaeon.com`、`X-Forwarded-Proto: https`
|
||||
- 代码单测:`go test ./internal/router/admin -run "BaseURL|IsInternalHost"`(4 例通过,含「本机地址必须报错」)
|
||||
@@ -0,0 +1,28 @@
|
||||
# 皮肤选择卡片的预览图是怎么来的
|
||||
|
||||
面板「云端加密 → 验证界面」里 8 张预览图是**真机截图**,不是设计稿:
|
||||
|
||||
```
|
||||
frontend/public/theme-previews/{classic,dark,light,industrial,compact,split,card,terminal}.png
|
||||
```
|
||||
|
||||
统一 560×420(4:3),窗口居中、去掉黑边,单张 14–33KB,合计约 190KB。构建时由 Vite 原样拷进 `dist/theme-previews/`,页面里按 `/theme-previews/<theme>.png` 引用。
|
||||
|
||||
## 重新生成(换皮肤/改布局后要重跑)
|
||||
|
||||
1. **打 8 个样本**:`packthemed origin64.exe themed/prev_<theme>.exe cfg_prev_<theme>.json <theme>`
|
||||
- `cfg_prev_<theme>.json` 里的 `name` 用中性值(例如「示例软件」),不要留测试名
|
||||
- **`cfg` 里的 `theme` 必须和该主题一致**:`PatchSignedThemed` 只按第四个参数挑要嵌的 shell DLL,不会改写 cfg;cfg 里写错皮肤名,8 个产物会渲染成同一套
|
||||
2. **截图**:`/root/work/shot64.sh prev_classic prev_dark …`
|
||||
- `Xvfb :99` + `openbox` + `scrot`
|
||||
- **必须用独立的 64 位 prefix**(`WINEPREFIX=/root/.wine64 WINEARCH=win64`):装了 `wine32:i386` 之后默认 prefix 会报 `could not load kernel32.dll`
|
||||
- 每轮开始前 `wineserver -k` 并等到可见窗口数归零,否则会截到上一套皮肤的窗口
|
||||
3. **裁边 + 统一尺寸**:`python3 /root/work/mktheme_previews.py`
|
||||
- 不依赖 PIL:用 `ffmpeg -f rawvideo -pix_fmt rgb24` 取出像素
|
||||
- 窗口边界用**逐列/逐行亮像素密度**判定(阈值 + 最小像素数),避免桌面上的零星亮像素把边界撑大导致缩略图偏心
|
||||
- `scale=W:H:force_original_aspect_ratio=decrease` 后再 `pad`,保证任何宽高比的窗口都不变形
|
||||
4. **重新构建前端**:`npm run build`,否则页面拿到的还是旧的 `dist/theme-previews/`
|
||||
|
||||
## 位宽徽标
|
||||
|
||||
卡片右上角的徽标由 `themeBits()` 决定:`classic` 显示「32/64 位」,其余 7 套显示「64 位」—— 因为 DuiLib 皮肤只做了 64 位构建,32 位程序加壳时服务端会自动回落到经典壳。
|
||||
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 20 KiB |
@@ -87,6 +87,18 @@ const themeOptions = computed(() => [
|
||||
{ value: 'terminal', label: t('admin.protect.themeTerminal') },
|
||||
])
|
||||
// DuiLib 壳目前只有 64 位构建;32 位程序产物会回落到 classic 壳(服务端处理)
|
||||
// 皮肤名形如「深色 · 卡密登录」:卡片上标题取前半,副标题取后半
|
||||
function themeTitle(label: string) {
|
||||
return label.split('·')[0].trim()
|
||||
}
|
||||
function themeSub(label: string) {
|
||||
const parts = label.split('·')
|
||||
return parts.length > 1 ? parts.slice(1).join('·').trim() : ''
|
||||
}
|
||||
// 位宽提示:经典壳 32/64 位都有产物,DuiLib 那几套只有 64 位构建
|
||||
function themeBits(theme: string) {
|
||||
return theme === 'classic' ? t('admin.protect.themeBits32') : t('admin.protect.themeBits64')
|
||||
}
|
||||
const themeDisabled = computed(() => false)
|
||||
|
||||
// 证书选择:直接列「每一套证书」(不再先选文件、再选身份)
|
||||
@@ -535,25 +547,46 @@ onBeforeUnmount(() => {
|
||||
{{ certOptionsForFile.length ? t('admin.protect.signProfileHint') : t('admin.protect.signProfileEmpty') }}
|
||||
</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.themeLabel') }}
|
||||
</UiLabel>
|
||||
<UiSelect v-model="shellTheme" :disabled="themeDisabled">
|
||||
<UiSelectTrigger class="w-full sm:max-w-xs">
|
||||
<UiSelectValue :placeholder="t('admin.protect.themeClassic')" />
|
||||
</UiSelectTrigger>
|
||||
<UiSelectContent>
|
||||
<UiSelectItem v-for="o in themeOptions" :key="o.value" :value="o.value">
|
||||
{{ o.label }}
|
||||
</UiSelectItem>
|
||||
</UiSelectContent>
|
||||
</UiSelect>
|
||||
<!-- 验证界面皮肤:云端加密时选择,产物里的壳按此渲染(带界面预览,选哪套一眼就能看出来) -->
|
||||
<div class="space-y-3">
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<UiLabel class="shrink-0 text-sm font-medium">
|
||||
{{ t('admin.protect.themeLabel') }}
|
||||
</UiLabel>
|
||||
<span class="text-xs text-muted-foreground">{{ t('admin.protect.themeGridHint') }}</span>
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-3 sm:grid-cols-4">
|
||||
<button
|
||||
v-for="o in themeOptions" :key="o.value" type="button"
|
||||
class="group relative overflow-hidden rounded-lg border text-left transition-all"
|
||||
:class="shellTheme === o.value
|
||||
? 'border-primary ring-2 ring-primary/25'
|
||||
: 'border-border hover:border-primary/40'"
|
||||
@click="shellTheme = o.value"
|
||||
>
|
||||
<img
|
||||
:src="`/theme-previews/${o.value}.png`" :alt="o.label"
|
||||
class="aspect-[4/3] w-full bg-[#101419] object-cover transition-transform group-hover:scale-[1.02]"
|
||||
loading="lazy"
|
||||
>
|
||||
<span
|
||||
class="absolute right-1.5 top-1.5 rounded bg-black/55 px-1.5 py-0.5 text-[10px] leading-none text-white/90 backdrop-blur-sm"
|
||||
>{{ themeBits(o.value) }}</span>
|
||||
<div class="space-y-0.5 px-2 py-1.5">
|
||||
<div class="flex items-center justify-between gap-1">
|
||||
<span class="truncate text-xs font-medium">{{ themeTitle(o.label) }}</span>
|
||||
<CheckCircle2 v-if="shellTheme === o.value" class="size-3.5 shrink-0 text-primary" />
|
||||
</div>
|
||||
<p v-if="themeSub(o.label)" class="truncate text-[11px] text-muted-foreground">
|
||||
{{ themeSub(o.label) }}
|
||||
</p>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
<p class="text-xs text-muted-foreground">
|
||||
{{ t('admin.protect.themeHint') }}
|
||||
</p>
|
||||
</div>
|
||||
<p class="text-xs text-muted-foreground">
|
||||
{{ t('admin.protect.themeHint') }}
|
||||
</p>
|
||||
|
||||
<!-- 程序版本:壳拿它和平台已发布版本比对,决定是否提示/强制更新 -->
|
||||
<div class="flex flex-col gap-3 sm:flex-row sm:items-center">
|
||||
|
||||
@@ -2662,14 +2662,17 @@
|
||||
"themeDark": "Dark · card key login",
|
||||
"themeLight": "Light · office style",
|
||||
"themeIndustrial": "Industrial blue · device licensing",
|
||||
"themeHint": "DuiLib skins apply to 64-bit builds; 32-bit binaries keep the classic shell.",
|
||||
"themeHint": "DuiLib skins are 64-bit builds only; 32-bit programs fall back to the classic shell automatically.",
|
||||
"themeCompact": "Compact banner · single row",
|
||||
"themeSplit": "Split · brand sidebar",
|
||||
"themeCard": "Wide card · two columns",
|
||||
"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."
|
||||
"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.",
|
||||
"themeGridHint": "Click a skin to apply it to the build — screenshots are from the real client",
|
||||
"themeBits64": "64-bit",
|
||||
"themeBits32": "32/64-bit"
|
||||
},
|
||||
"signProfiles": {
|
||||
"title": "Signing certificates",
|
||||
|
||||
@@ -2681,14 +2681,17 @@
|
||||
"themeDark": "深色 · 卡密登录",
|
||||
"themeLight": "浅色 · 办公风",
|
||||
"themeIndustrial": "工业蓝 · 设备授权",
|
||||
"themeHint": "DuiLib 皮肤目前 64 位生效;32 位程序仍用经典壳。选好皮肤后云端加密,产物弹窗就按该皮肤渲染。",
|
||||
"themeHint": "DuiLib 皮肤只做了 64 位构建,32 位程序固定用经典壳(服务端会自动回落)。选好后云端加密,产物验证弹窗就按这套皮肤渲染。",
|
||||
"themeCompact": "极简横幅 · 单行激活",
|
||||
"themeSplit": "左右分栏 · 品牌竖栏",
|
||||
"themeCard": "宽扁卡片 · 双列说明",
|
||||
"themeTerminal": "终端风 · 命令行",
|
||||
"programVersionLabel": "程序版本",
|
||||
"programVersionPlaceholder": "例如 1.2.3(留空则不检查更新)",
|
||||
"programVersionHint": "填了版本号后,程序启动时会向平台查询是否有更新;平台里发布更高版本就会弹出更新提示,设为强制更新时不允许跳过。"
|
||||
"programVersionHint": "填了版本号后,程序启动时会向平台查询是否有更新;平台里发布更高版本就会弹出更新提示,设为强制更新时不允许跳过。",
|
||||
"themeGridHint": "点一套直接套用到产物,下面是各套界面实拍",
|
||||
"themeBits64": "64 位",
|
||||
"themeBits32": "32/64 位"
|
||||
},
|
||||
"signProfiles": {
|
||||
"title": "签名证书",
|
||||
|
||||