add option to disable public ip monitoring in config

This commit is contained in:
ghostersk
2025-05-28 07:17:03 +01:00
parent 52d20c8f0b
commit da17aef692
3 changed files with 58 additions and 3 deletions
+16 -3
View File
@@ -360,9 +360,14 @@ func destroyWindow(hwnd HWND) {
// getPublicIP retrieves public IP with HTTP first, then DNS fallback
func getPublicIP() (string, error) {
// Get config to check for custom HTTP URLs
// Get config to check if public IP detection is enabled
cfg := config.GetConfig()
// If public IP detection is disabled, return empty string
if !cfg.ObtainPublicIP {
return "", nil
}
// Use custom URLs if configured, otherwise use defaults
urls := []string{
"https://ipv4.icanhazip.com",
@@ -430,8 +435,16 @@ func (m *Monitor) logEventWithTime(eventType, username, computerName, localIP st
// Get public IP (this can be done in background as it's less time-sensitive)
publicIP, err := getPublicIP()
if err != nil {
m.logger.Warning("Failed to get public IP: %v - using 'Unknown'", err)
publicIP = "Unknown"
// Check if public IP detection is disabled
cfg := config.GetConfig()
if !cfg.ObtainPublicIP {
// If disabled, use empty string without logging warning
publicIP = ""
} else {
// If enabled but failed, log warning and use "Unknown"
m.logger.Warning("Failed to get public IP: %v - using 'Unknown'", err)
publicIP = "Unknown"
}
}
// Format the timestamp using the pre-captured event time