package engine import ( "io" "net/http" "strings" "time" "vpnem/internal/config" ) const DefaultBlockedSiteProbeURL = "https://rutracker.org" func ModeRequiresExitIP(mode config.Mode) bool { return mode.Final == "proxy" } func CheckExitIP(localProxyPort int) string { client, err := HTTPClientViaSOCKS5(config.LocalProxyHost, localProxyPort, 5*time.Second) if err != nil { return "" } resp, err := client.Get("http://ifconfig.me/ip") if err != nil { return "" } defer resp.Body.Close() body, err := io.ReadAll(io.LimitReader(resp.Body, 64)) if err != nil { return "" } return strings.TrimSpace(string(body)) } func ProbeBlockedSite(localProxyPort int, rawURL string, timeout time.Duration) (int, error) { client, err := HTTPClientViaSOCKS5(config.LocalProxyHost, localProxyPort, timeout) if err != nil { return 0, err } req, err := http.NewRequest(http.MethodGet, rawURL, nil) if err != nil { return 0, err } req.Header.Set("User-Agent", "vpnem-health/1.0") resp, err := client.Do(req) if err != nil { return 0, err } defer resp.Body.Close() _, _ = io.Copy(io.Discard, io.LimitReader(resp.Body, 256)) return resp.StatusCode, nil } func DeepCheckRequiresRestart(mode config.Mode, exitIP string, probeErr error) bool { if ModeRequiresExitIP(mode) { return exitIP == "" } return probeErr != nil }