Only resolve github.com for healthcheck, fix #170
This commit is contained in:
@@ -3,34 +3,14 @@ package cli
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"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 {
|
func HealthCheck() error {
|
||||||
paramsReader := params.NewReader(nil)
|
ips, err := net.LookupIP("github.com")
|
||||||
ipStatusFilepath, err := paramsReader.GetIPStatusFilepath()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("cannot resolve github.com (%s)", err)
|
||||||
}
|
} else if len(ips) == 0 {
|
||||||
|
return fmt.Errorf("resolved no IP addresses for github.com")
|
||||||
// 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 nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user