PORT environment variable always takes priority over database settings. Lock UI, when defined

This commit is contained in:
2025-12-01 14:26:19 +01:00
parent 272e112ac9
commit ac0f634236
9 changed files with 103 additions and 11 deletions

View File

@@ -485,17 +485,15 @@ func setDefaultsLocked() {
if currentSettings.Language == "" {
currentSettings.Language = "en"
}
if currentSettings.Port == 0 {
// Check for PORT environment variable first
if portEnv := os.Getenv("PORT"); portEnv != "" {
if port, err := strconv.Atoi(portEnv); err == nil && port > 0 && port <= 65535 {
currentSettings.Port = port
} else {
currentSettings.Port = 8080
}
} else {
// Check for PORT environment variable first - it always takes priority
if portEnv := os.Getenv("PORT"); portEnv != "" {
if port, err := strconv.Atoi(portEnv); err == nil && port > 0 && port <= 65535 {
currentSettings.Port = port
} else if currentSettings.Port == 0 {
currentSettings.Port = 8080
}
} else if currentSettings.Port == 0 {
currentSettings.Port = 8080
}
if currentSettings.CallbackURL == "" {
currentSettings.CallbackURL = fmt.Sprintf("http://127.0.0.1:%d", currentSettings.Port)
@@ -1112,6 +1110,18 @@ func SetDefaultServer(id string) (Fail2banServer, error) {
}
// GetSettings returns a copy of the current settings
// GetPortFromEnv returns the PORT environment variable value if set, and whether it's set
func GetPortFromEnv() (int, bool) {
portEnv := os.Getenv("PORT")
if portEnv == "" {
return 0, false
}
if port, err := strconv.Atoi(portEnv); err == nil && port > 0 && port <= 65535 {
return port, true
}
return 0, false
}
func GetSettings() AppSettings {
settingsLock.RLock()
defer settingsLock.RUnlock()