mirror of
https://github.com/swissmakers/fail2ban-ui.git
synced 2026-04-11 13:47:05 +02:00
PORT environment variable always takes priority over database settings. Lock UI, when defined
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user