add option to disable public ip monitoring in config
This commit is contained in:
+16
-3
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user