mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 15:34:01 +03:00
Add public-ipv4/public-ipv6 config options for manual IP override
On some servers ifconfig.co is unreachable (e.g. Hetzner, AdGuard DNS blocklists), causing 'mtg doctor' SNI-DNS check and 'mtg access' link generation to fail. New config options allow specifying public IPs manually, with automatic detection as fallback. Fixes #405
This commit is contained in:
@@ -58,6 +58,9 @@ func (a *Access) Run(cli *CLI, version string) error {
|
||||
|
||||
wg.Go(func() {
|
||||
ip := a.PublicIPv4
|
||||
if ip == nil {
|
||||
ip = conf.PublicIPv4.Get(nil)
|
||||
}
|
||||
if ip == nil {
|
||||
ip = getIP(ntw, "tcp4")
|
||||
}
|
||||
@@ -70,6 +73,9 @@ func (a *Access) Run(cli *CLI, version string) error {
|
||||
})
|
||||
wg.Go(func() {
|
||||
ip := a.PublicIPv6
|
||||
if ip == nil {
|
||||
ip = conf.PublicIPv6.Get(nil)
|
||||
}
|
||||
if ip == nil {
|
||||
ip = getIP(ntw, "tcp6")
|
||||
}
|
||||
|
||||
+10
-3
@@ -332,13 +332,20 @@ func (d *Doctor) checkSecretHost(resolver *net.Resolver, ntw mtglib.Network) boo
|
||||
return false
|
||||
}
|
||||
|
||||
ourIP4 := getIP(ntw, "tcp4")
|
||||
ourIP6 := getIP(ntw, "tcp6")
|
||||
ourIP4 := d.conf.PublicIPv4.Get(nil)
|
||||
if ourIP4 == nil {
|
||||
ourIP4 = getIP(ntw, "tcp4")
|
||||
}
|
||||
|
||||
ourIP6 := d.conf.PublicIPv6.Get(nil)
|
||||
if ourIP6 == nil {
|
||||
ourIP6 = getIP(ntw, "tcp6")
|
||||
}
|
||||
|
||||
if ourIP4 == nil && ourIP6 == nil {
|
||||
tplError.Execute(os.Stdout, map[string]any{ //nolint: errcheck
|
||||
"description": "cannot detect public IP address",
|
||||
"error": errors.New("ifconfig.co is unreachable for both IPv4 and IPv6"),
|
||||
"error": errors.New("cannot detect automatically and public-ipv4/public-ipv6 are not set in config"),
|
||||
})
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user