mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-09-04 09:27:15 +00:00
fix(sub): randomize fresh panel subscription paths (#6375)
* fix(sub): randomize fresh panel subscription paths Seed distinct cryptographically random paths for base64, JSON, and Clash subscriptions when a panel database is first created. Persist them so restarts keep published URLs stable while upgrades preserve existing settings. Generated-by: OpenCode:gpt-5.6-sol * fix(sub): regenerate paths on settings reset Keep subscription paths unpredictable after a factory reset, close the test database on failure, and update the builder, OpenAPI, and localized docs to describe panel-specific paths instead of obsolete fixed defaults. Generated-by: OpenCode:gpt-5.6-sol
This commit is contained in:
@@ -1169,6 +1169,22 @@ func initUser() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func seedRandomSubscriptionPaths() error {
|
||||
settings := []model.Setting{
|
||||
{Key: "subPath", Value: "/" + random.NumLower(16) + "/"},
|
||||
{Key: "subJsonPath", Value: "/" + random.NumLower(16) + "/"},
|
||||
{Key: "subClashPath", Value: "/" + random.NumLower(16) + "/"},
|
||||
}
|
||||
return db.Transaction(func(tx *gorm.DB) error {
|
||||
for i := range settings {
|
||||
if err := tx.Where("key = ?", settings[i].Key).FirstOrCreate(&settings[i]).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func runSeeders(isUsersEmpty bool) error {
|
||||
empty, err := isTableEmpty("history_of_seeders")
|
||||
if err != nil {
|
||||
@@ -2138,6 +2154,11 @@ func InitDB(dbPath string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if isUsersEmpty {
|
||||
if err := seedRandomSubscriptionPaths(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := initUser(); err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user