ddns: remove ipv6 nameservers, support custom nameservers (#439)

This commit is contained in:
UUBulb 2024-10-18 22:06:01 +08:00 committed by GitHub
parent c58c4f866a
commit f6531a52bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 45 additions and 3 deletions

View File

@ -1012,6 +1012,7 @@ type settingForm struct {
DashboardTheme string
CustomCode string
CustomCodeDashboard string
CustomNameservers string
ViewPassword string
IgnoredIPNotification string
IPChangeNotificationTag string // IP变更提醒的通知组
@ -1078,6 +1079,7 @@ func (ma *memberAPI) updateSetting(c *gin.Context) {
singleton.Conf.Site.DashboardTheme = sf.DashboardTheme
singleton.Conf.Site.CustomCode = sf.CustomCode
singleton.Conf.Site.CustomCodeDashboard = sf.CustomCodeDashboard
singleton.Conf.DNSServers = sf.CustomNameservers
singleton.Conf.Site.ViewPassword = sf.ViewPassword
singleton.Conf.Oauth2.Admin = sf.Admin
// 保证NotificationTag不为空
@ -1093,6 +1095,8 @@ func (ma *memberAPI) updateSetting(c *gin.Context) {
}
// 更新系统语言
singleton.InitLocalizer()
// 更新DNS服务器
singleton.OnNameserverUpdate()
c.JSON(http.StatusOK, model.Response{
Code: http.StatusOK,
})

View File

@ -125,6 +125,8 @@ type Config struct {
IgnoredIPNotificationServerIDs map[uint64]bool // [ServerID] -> bool(值为true代表当前ServerID在特定服务器列表内)
MaxTCPPingValue int32
AvgPingCount int
DNSServers string
}
// Read 读取配置文件并应用

View File

@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
"strings"
"time"
"github.com/libdns/libdns"
@ -13,7 +14,10 @@ import (
"github.com/naiba/nezha/pkg/utils"
)
var dnsTimeOut = 10 * time.Second
var (
dnsTimeOut = 10 * time.Second
customDNSServers []string
)
type IP struct {
Ipv4Addr string
@ -33,6 +37,12 @@ type Provider struct {
Setter libdns.RecordSetter
}
func InitDNSServers(s string) {
if s != "" {
customDNSServers = strings.Split(s, ",")
}
}
func (provider *Provider) UpdateDomain(ctx context.Context) {
provider.ctx = ctx
for _, domain := range provider.DDNSProfile.Domains {
@ -95,12 +105,17 @@ func splitDomainSOA(domain string) (prefix string, zone string, err error) {
domain += "."
indexes := dns.Split(domain)
servers := utils.DNSServers
if len(customDNSServers) > 0 {
servers = customDNSServers
}
var r *dns.Msg
for _, idx := range indexes {
m := new(dns.Msg)
m.SetQuestion(domain[idx:], dns.TypeSOA)
for _, server := range utils.DNSServers {
for _, server := range servers {
r, _, err = c.Exchange(m, server)
if err != nil {
return

View File

@ -13,7 +13,7 @@ import (
var (
Json = jsoniter.ConfigCompatibleWithStandardLibrary
DNSServers = []string{"1.1.1.1:53", "223.5.5.5:53", "[2606:4700:4700::1111]:53", "[2400:3200::1]:53"}
DNSServers = []string{"1.1.1.1:53", "223.5.5.5:53"}
)
func IsWindows() bool {

View File

@ -747,3 +747,6 @@ other = "Expired"
[Days]
other = "d"
[CustomNameservers]
other = "Custom Public DNS Nameservers for DDNS (separate with comma)"

View File

@ -747,3 +747,6 @@ other = "Expired"
[Days]
other = "d"
[CustomNameservers]
other = "Servidores DNS públicos personalizados para DDNS (separar con coma)"

View File

@ -747,3 +747,6 @@ other = "已到期"
[Days]
other = "天"
[CustomNameservers]
other = "自定义DDNS使用的公共DNS服务器(逗号分隔)"

View File

@ -747,3 +747,6 @@ other = "已到期"
[Days]
other = "天"
[CustomNameservers]
other = "自訂DDNS使用的公共DNS伺服器(逗號分隔)"

View File

@ -53,6 +53,10 @@
<label>{{tr "PanelServerDomainAndIP"}}</label>
<input type="text" name="GRPCHost" placeholder="" value="{{.Conf.GRPCHost}}">
</div>
<div class="field">
<label>{{tr "CustomNameservers"}}</label>
<input type="text" name="CustomNameservers" placeholder="" value="{{.Conf.DNSServers}}">
</div>
<div class="field">
<label>{{tr "IPChangeAlert"}}</label>
</div>

View File

@ -20,6 +20,7 @@ var (
func initDDNS() {
OnDDNSUpdate()
OnNameserverUpdate()
}
func OnDDNSUpdate() {
@ -33,6 +34,10 @@ func OnDDNSUpdate() {
}
}
func OnNameserverUpdate() {
ddns2.InitDNSServers(Conf.DNSServers)
}
func GetDDNSProvidersFromProfiles(profileId []uint64, ip *ddns2.IP) ([]*ddns2.Provider, error) {
profiles := make([]*model.DDNSProfile, 0, len(profileId))
ddnsCacheLock.RLock()