Only resolve github.com for healthcheck, fix #170
This commit is contained in:
@@ -3,34 +3,14 @@ package cli
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/golibs/files"
|
||||
"github.com/qdm12/golibs/network"
|
||||
"github.com/qdm12/private-internet-access-docker/internal/params"
|
||||
"github.com/qdm12/private-internet-access-docker/internal/publicip"
|
||||
)
|
||||
|
||||
func HealthCheck() error {
|
||||
paramsReader := params.NewReader(nil)
|
||||
ipStatusFilepath, err := paramsReader.GetIPStatusFilepath()
|
||||
ips, err := net.LookupIP("github.com")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Get all VPN ip addresses from openvpn configuration file
|
||||
fileManager := files.NewFileManager()
|
||||
b, err := fileManager.ReadFile(string(ipStatusFilepath))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
savedPublicIP := net.ParseIP(string(b))
|
||||
publicIP, err := publicip.NewIPGetter(network.NewClient(3 * time.Second)).Get()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !publicIP.Equal(savedPublicIP) {
|
||||
return fmt.Errorf("Public IP address is %s instead of initial vpn IP address %s", publicIP, savedPublicIP)
|
||||
return fmt.Errorf("cannot resolve github.com (%s)", err)
|
||||
} else if len(ips) == 0 {
|
||||
return fmt.Errorf("resolved no IP addresses for github.com")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user