Полный продакшен-рефактор fix25: split peer/admin, удаление legacy, шифрование secret, auth_id, новые API/роуты и зачистка subscription
This commit is contained in:
+51
-2
@@ -105,6 +105,8 @@ func ensureSecureBootstrapAdmin() error {
|
||||
return pwdErr
|
||||
}
|
||||
adminPassword = password
|
||||
logrus.Warnf("Initial admin username: %s", adminUser)
|
||||
logrus.Warnf("Initial admin password: %s", adminPassword)
|
||||
}
|
||||
forcePasswordChange := envBoolAsInt("HY2XS_FORCE_PASSWORD_CHANGE", 1)
|
||||
status := int64(1)
|
||||
@@ -153,6 +155,7 @@ func runMigrations() error {
|
||||
}
|
||||
|
||||
migrations := []migration{
|
||||
{version: "000_base_config", apply: migrateBaseConfig},
|
||||
{version: "001_admin_peer_split", apply: migrateAdminPeerSplit},
|
||||
{version: "002_migrate_legacy_accounts", apply: migrateLegacyAccounts},
|
||||
{version: "003_archive_legacy_account", apply: archiveLegacyAccount},
|
||||
@@ -178,6 +181,52 @@ func runMigrations() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func seedBaseConfig() error {
|
||||
defaults := map[string]string{
|
||||
constant.HUIWebPort: "8080",
|
||||
constant.HUIWebContext: "/",
|
||||
constant.HUICrtPath: "",
|
||||
constant.HUIKeyPath: "",
|
||||
constant.JwtSecret: "",
|
||||
constant.Hysteria2Enable: "0",
|
||||
constant.Hysteria2Config: "",
|
||||
constant.Hysteria2TrafficTime: "10",
|
||||
constant.Hysteria2ConfigRemark: "",
|
||||
constant.ResetTrafficCron: "0 0 * * *",
|
||||
constant.Hysteria2TrafficStatsSecret: "",
|
||||
constant.PeerSecretKey: "",
|
||||
constant.PeerSecretEncryptionKey: "",
|
||||
}
|
||||
for k, v := range defaults {
|
||||
if tx := sqliteDB.Exec("INSERT OR IGNORE INTO config(key, value, remark) VALUES(?, ?, ?)", k, v, k); tx.Error != nil {
|
||||
logrus.Errorf("sqlite seed config err: %v", tx.Error)
|
||||
return errors.New("sqlite seed config err")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func migrateBaseConfig() error {
|
||||
stmts := []string{
|
||||
`CREATE TABLE IF NOT EXISTS config (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
key TEXT NOT NULL UNIQUE DEFAULT '',
|
||||
value TEXT NOT NULL DEFAULT '',
|
||||
remark TEXT NOT NULL DEFAULT '',
|
||||
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)`,
|
||||
`CREATE INDEX IF NOT EXISTS config_key_index ON config (key)`,
|
||||
}
|
||||
for _, stmt := range stmts {
|
||||
if tx := sqliteDB.Exec(stmt); tx.Error != nil {
|
||||
logrus.Errorf("sqlite migration exec err: %v", tx.Error)
|
||||
return errors.New("sqlite migration exec err")
|
||||
}
|
||||
}
|
||||
return seedBaseConfig()
|
||||
}
|
||||
|
||||
func migrationApplied(version string) (bool, error) {
|
||||
var count int64
|
||||
if tx := sqliteDB.Raw("SELECT COUNT(1) FROM schema_migrations WHERE version = ?", version).Scan(&count); tx.Error != nil {
|
||||
@@ -289,7 +338,7 @@ func migrateLegacyAccounts() error {
|
||||
return authErr
|
||||
}
|
||||
secretDigest := util.PeerSecretDigest(*acc.ConPass)
|
||||
secretCiphertext := *acc.ConPass
|
||||
secretEncrypted := *acc.ConPass
|
||||
quota := int64(0)
|
||||
if acc.Quota != nil {
|
||||
quota = *acc.Quota
|
||||
@@ -331,7 +380,7 @@ func migrateLegacyAccounts() error {
|
||||
Remark: &remark,
|
||||
AuthId: &authId,
|
||||
SecretDigest: &secretDigest,
|
||||
SecretCiphertext: &secretCiphertext,
|
||||
SecretEncrypted: &secretEncrypted,
|
||||
QuotaBytes: "a,
|
||||
DownloadBytes: &download,
|
||||
UploadBytes: &upload,
|
||||
|
||||
Reference in New Issue
Block a user