[PR #6227] [MERGED] feat(server): keep this machine's own settings when importing a database #6189

Closed
opened 2026-11-02 04:06:59 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6227
Author: @n0ctal
Created: 8/16/2026
Status: ✅ Merged
Merged: 8/18/2026
Merged by: @MHSanaei

Base: main ← Head: upstream-keep-host-settings-on-import


📝 Commits (4)

  • 301d274 feat(server): keep this machine's own settings when importing a database
  • 55ce879 fix(server): drop imported host settings this machine never had, and cover Postgres
  • c6f7266 chore: drop the accidentally committed dist build stub
  • 8ca7a6d Merge branch 'main' into upstream-keep-host-settings-on-import

📊 Changes

17 files changed (+248 additions, -20 deletions)

View changed files

📝 frontend/src/pages/index/BackupModal.tsx (+13 -1)
📝 internal/web/controller/server.go (+5 -1)
➕ internal/web/service/import_host_settings_test.go (+99 -0)
📝 internal/web/service/server.go (+92 -5)
📝 internal/web/translation/ar-EG.json (+3 -1)
📝 internal/web/translation/en-US.json (+3 -1)
📝 internal/web/translation/es-ES.json (+3 -1)
📝 internal/web/translation/fa-IR.json (+3 -1)
📝 internal/web/translation/id-ID.json (+3 -1)
📝 internal/web/translation/ja-JP.json (+3 -1)
📝 internal/web/translation/pt-BR.json (+3 -1)
📝 internal/web/translation/ru-RU.json (+3 -1)
📝 internal/web/translation/tr-TR.json (+3 -1)
📝 internal/web/translation/uk-UA.json (+3 -1)
📝 internal/web/translation/vi-VN.json (+3 -1)
📝 internal/web/translation/zh-CN.json (+3 -1)
📝 internal/web/translation/zh-TW.json (+3 -1)

📄 Description

Closes #5004.

Summary

Import replaces the whole database, so the uploaded file's listen addresses, ports, base path, certificate paths and node identity land on the destination machine. Moving a configuration to a new host leaves the panel answering on an address it does not own and presenting certificates it does not have — the reporter's "the panel broke due to ssl config errors".

This keeps the destination's own host-bound settings and takes everything else from the file.

Why not filter on export

That was the shape the issue asked for, and it is the weaker half of the fix. getDb streams the SQLite file byte-for-byte, so filtering means building and shipping a modified copy — and it only helps exports taken after the change. Every backup already sitting on someone's disk still breaks on restore.

Doing it on import fixes those too, and removes the failure mode where the box was simply not ticked.

What counts as host-bound

webListen  webDomain  webPort  webCertFile  webKeyFile  webBasePath
subListen  subDomain  subPort  subCertFile  subKeyFile  subURI  subJsonURI
secret  panelGuid
nodeMtls{CaCertPem,CaKeyPem,ClientCertPem,ClientKeyPem,ClientCertSha256,ClientCAPem}

The first two rows are the reachability the reporter lost. secret and panelGuid identify the panel itself. The mTLS material is the identity this panel presents to its nodes — importing another machine's would leave two panels claiming the same identity, which is worse than an unreachable port because it fails silently.

Everything else — inbounds, clients, users, templates, all remaining settings — still comes from the imported file, which is what the feature is for.

Interface

A checkbox in the backup dialog, defaulting to keeping this machine's values. Clearing it restores today's behaviour for anyone deliberately cloning a host. The controller treats a missing field as "keep", so an API caller that has not been updated gets the safe path.

Validation

TestImportKeepsHostBoundSettings seeds this machine's values, overwrites them the way an import does, restores, and asserts each host-bound key holds the local value while an ordinary setting (remarkTemplate) still holds the imported one — so the test fails both if preservation stops working and if it starts swallowing settings it should not.

Mutation-checked: making restoreHostBoundSettings a no-op turns it red with setting subURI = "from-imported-file" after import, want this machine's "https://this-host.example/sub/".

go build ./..., go vet, golangci-lint clean; 36 Go packages green; frontend typecheck, eslint and the 936-test unit suite green.

Risk

Low, and the sharp edge is named: someone who wants the source machine's certificates and ports must now clear the checkbox. That trade is deliberate — the silent-breakage direction is the one that costs an evening of debugging on a machine you have just migrated to.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6227 **Author:** [@n0ctal](https://github.com/n0ctal) **Created:** 8/16/2026 **Status:** ✅ Merged **Merged:** 8/18/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `upstream-keep-host-settings-on-import` --- ### 📝 Commits (4) - [`301d274`](https://github.com/MHSanaei/3x-ui/commit/301d274ad982e98e9012b7d8ed14826caf055073) feat(server): keep this machine's own settings when importing a database - [`55ce879`](https://github.com/MHSanaei/3x-ui/commit/55ce8796689a9e073127b268746747ff31670e9b) fix(server): drop imported host settings this machine never had, and cover Postgres - [`c6f7266`](https://github.com/MHSanaei/3x-ui/commit/c6f726686bb5519186a990d0cac1905f2cab17bb) chore: drop the accidentally committed dist build stub - [`8ca7a6d`](https://github.com/MHSanaei/3x-ui/commit/8ca7a6d45769892031bd8ace0e99e3b11437fb52) Merge branch 'main' into upstream-keep-host-settings-on-import ### 📊 Changes **17 files changed** (+248 additions, -20 deletions) <details> <summary>View changed files</summary> 📝 `frontend/src/pages/index/BackupModal.tsx` (+13 -1) 📝 `internal/web/controller/server.go` (+5 -1) ➕ `internal/web/service/import_host_settings_test.go` (+99 -0) 📝 `internal/web/service/server.go` (+92 -5) 📝 `internal/web/translation/ar-EG.json` (+3 -1) 📝 `internal/web/translation/en-US.json` (+3 -1) 📝 `internal/web/translation/es-ES.json` (+3 -1) 📝 `internal/web/translation/fa-IR.json` (+3 -1) 📝 `internal/web/translation/id-ID.json` (+3 -1) 📝 `internal/web/translation/ja-JP.json` (+3 -1) 📝 `internal/web/translation/pt-BR.json` (+3 -1) 📝 `internal/web/translation/ru-RU.json` (+3 -1) 📝 `internal/web/translation/tr-TR.json` (+3 -1) 📝 `internal/web/translation/uk-UA.json` (+3 -1) 📝 `internal/web/translation/vi-VN.json` (+3 -1) 📝 `internal/web/translation/zh-CN.json` (+3 -1) 📝 `internal/web/translation/zh-TW.json` (+3 -1) </details> ### 📄 Description Closes #5004. ## Summary Import replaces the whole database, so the uploaded file's listen addresses, ports, base path, certificate paths and node identity land on the destination machine. Moving a configuration to a new host leaves the panel answering on an address it does not own and presenting certificates it does not have — the reporter's "the panel broke due to ssl config errors". This keeps the destination's own host-bound settings and takes everything else from the file. ## Why not filter on export That was the shape the issue asked for, and it is the weaker half of the fix. `getDb` streams the SQLite file byte-for-byte, so filtering means building and shipping a modified copy — and it only helps exports taken *after* the change. Every backup already sitting on someone's disk still breaks on restore. Doing it on import fixes those too, and removes the failure mode where the box was simply not ticked. ## What counts as host-bound ``` webListen webDomain webPort webCertFile webKeyFile webBasePath subListen subDomain subPort subCertFile subKeyFile subURI subJsonURI secret panelGuid nodeMtls{CaCertPem,CaKeyPem,ClientCertPem,ClientKeyPem,ClientCertSha256,ClientCAPem} ``` The first two rows are the reachability the reporter lost. `secret` and `panelGuid` identify the panel itself. The mTLS material is the identity this panel presents to its nodes — importing another machine's would leave two panels claiming the same identity, which is worse than an unreachable port because it fails silently. Everything else — inbounds, clients, users, templates, all remaining settings — still comes from the imported file, which is what the feature is for. ## Interface A checkbox in the backup dialog, defaulting to keeping this machine's values. Clearing it restores today's behaviour for anyone deliberately cloning a host. The controller treats a missing field as "keep", so an API caller that has not been updated gets the safe path. ## Validation `TestImportKeepsHostBoundSettings` seeds this machine's values, overwrites them the way an import does, restores, and asserts each host-bound key holds the local value while an ordinary setting (`remarkTemplate`) still holds the imported one — so the test fails both if preservation stops working and if it starts swallowing settings it should not. Mutation-checked: making `restoreHostBoundSettings` a no-op turns it red with `setting subURI = "from-imported-file" after import, want this machine's "https://this-host.example/sub/"`. `go build ./...`, `go vet`, `golangci-lint` clean; 36 Go packages green; frontend typecheck, eslint and the 936-test unit suite green. ## Risk Low, and the sharp edge is named: someone who *wants* the source machine's certificates and ports must now clear the checkbox. That trade is deliberate — the silent-breakage direction is the one that costs an evening of debugging on a machine you have just migrated to. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:06:59 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6189
No description provided.