Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f6531a52bd | ||
|
|
c58c4f866a | ||
|
|
fc9f1b6bcc | ||
|
|
be7b6e9c5e |
@@ -96,6 +96,13 @@ func loadThirdPartyTemplates(tmpl *template.Template) *template.Template {
|
|||||||
}
|
}
|
||||||
|
|
||||||
themeDir := theme.Name()
|
themeDir := theme.Name()
|
||||||
|
if themeDir == "theme-custom" {
|
||||||
|
// for backward compatibility
|
||||||
|
// note: will remove this in future versions
|
||||||
|
ret = loadTemplates(ret, themeDir)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(themeDir, "dashboard-") {
|
if strings.HasPrefix(themeDir, "dashboard-") {
|
||||||
// load dashboard templates, ignore desc file
|
// load dashboard templates, ignore desc file
|
||||||
ret = loadTemplates(ret, themeDir)
|
ret = loadTemplates(ret, themeDir)
|
||||||
|
|||||||
@@ -781,6 +781,7 @@ type ddnsForm struct {
|
|||||||
AccessSecret string
|
AccessSecret string
|
||||||
WebhookURL string
|
WebhookURL string
|
||||||
WebhookMethod uint8
|
WebhookMethod uint8
|
||||||
|
WebhookRequestType uint8
|
||||||
WebhookRequestBody string
|
WebhookRequestBody string
|
||||||
WebhookHeaders string
|
WebhookHeaders string
|
||||||
}
|
}
|
||||||
@@ -809,6 +810,7 @@ func (ma *memberAPI) addOrEditDDNS(c *gin.Context) {
|
|||||||
p.AccessSecret = df.AccessSecret
|
p.AccessSecret = df.AccessSecret
|
||||||
p.WebhookURL = df.WebhookURL
|
p.WebhookURL = df.WebhookURL
|
||||||
p.WebhookMethod = df.WebhookMethod
|
p.WebhookMethod = df.WebhookMethod
|
||||||
|
p.WebhookRequestType = df.WebhookRequestType
|
||||||
p.WebhookRequestBody = df.WebhookRequestBody
|
p.WebhookRequestBody = df.WebhookRequestBody
|
||||||
p.WebhookHeaders = df.WebhookHeaders
|
p.WebhookHeaders = df.WebhookHeaders
|
||||||
|
|
||||||
@@ -1010,6 +1012,7 @@ type settingForm struct {
|
|||||||
DashboardTheme string
|
DashboardTheme string
|
||||||
CustomCode string
|
CustomCode string
|
||||||
CustomCodeDashboard string
|
CustomCodeDashboard string
|
||||||
|
CustomNameservers string
|
||||||
ViewPassword string
|
ViewPassword string
|
||||||
IgnoredIPNotification string
|
IgnoredIPNotification string
|
||||||
IPChangeNotificationTag string // IP变更提醒的通知组
|
IPChangeNotificationTag string // IP变更提醒的通知组
|
||||||
@@ -1076,6 +1079,7 @@ func (ma *memberAPI) updateSetting(c *gin.Context) {
|
|||||||
singleton.Conf.Site.DashboardTheme = sf.DashboardTheme
|
singleton.Conf.Site.DashboardTheme = sf.DashboardTheme
|
||||||
singleton.Conf.Site.CustomCode = sf.CustomCode
|
singleton.Conf.Site.CustomCode = sf.CustomCode
|
||||||
singleton.Conf.Site.CustomCodeDashboard = sf.CustomCodeDashboard
|
singleton.Conf.Site.CustomCodeDashboard = sf.CustomCodeDashboard
|
||||||
|
singleton.Conf.DNSServers = sf.CustomNameservers
|
||||||
singleton.Conf.Site.ViewPassword = sf.ViewPassword
|
singleton.Conf.Site.ViewPassword = sf.ViewPassword
|
||||||
singleton.Conf.Oauth2.Admin = sf.Admin
|
singleton.Conf.Oauth2.Admin = sf.Admin
|
||||||
// 保证NotificationTag不为空
|
// 保证NotificationTag不为空
|
||||||
@@ -1091,6 +1095,8 @@ func (ma *memberAPI) updateSetting(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
// 更新系统语言
|
// 更新系统语言
|
||||||
singleton.InitLocalizer()
|
singleton.InitLocalizer()
|
||||||
|
// 更新DNS服务器
|
||||||
|
singleton.OnNameserverUpdate()
|
||||||
c.JSON(http.StatusOK, model.Response{
|
c.JSON(http.StatusOK, model.Response{
|
||||||
Code: http.StatusOK,
|
Code: http.StatusOK,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -125,6 +125,8 @@ type Config struct {
|
|||||||
IgnoredIPNotificationServerIDs map[uint64]bool // [ServerID] -> bool(值为true代表当前ServerID在特定服务器列表内)
|
IgnoredIPNotificationServerIDs map[uint64]bool // [ServerID] -> bool(值为true代表当前ServerID在特定服务器列表内)
|
||||||
MaxTCPPingValue int32
|
MaxTCPPingValue int32
|
||||||
AvgPingCount int
|
AvgPingCount int
|
||||||
|
|
||||||
|
DNSServers string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read 读取配置文件并应用
|
// Read 读取配置文件并应用
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ var ProviderList = []DDNSProvider{
|
|||||||
AccessSecret: true,
|
AccessSecret: true,
|
||||||
WebhookURL: true,
|
WebhookURL: true,
|
||||||
WebhookMethod: true,
|
WebhookMethod: true,
|
||||||
|
WebhookRequestType: true,
|
||||||
WebhookRequestBody: true,
|
WebhookRequestBody: true,
|
||||||
WebhookHeaders: true,
|
WebhookHeaders: true,
|
||||||
},
|
},
|
||||||
@@ -93,6 +94,7 @@ type DDNSProvider struct {
|
|||||||
AccessSecret bool
|
AccessSecret bool
|
||||||
WebhookURL bool
|
WebhookURL bool
|
||||||
WebhookMethod bool
|
WebhookMethod bool
|
||||||
|
WebhookRequestType bool
|
||||||
WebhookRequestBody bool
|
WebhookRequestBody bool
|
||||||
WebhookHeaders bool
|
WebhookHeaders bool
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-3
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/libdns/libdns"
|
"github.com/libdns/libdns"
|
||||||
@@ -13,7 +14,10 @@ import (
|
|||||||
"github.com/naiba/nezha/pkg/utils"
|
"github.com/naiba/nezha/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
var dnsTimeOut = 10 * time.Second
|
var (
|
||||||
|
dnsTimeOut = 10 * time.Second
|
||||||
|
customDNSServers []string
|
||||||
|
)
|
||||||
|
|
||||||
type IP struct {
|
type IP struct {
|
||||||
Ipv4Addr string
|
Ipv4Addr string
|
||||||
@@ -33,6 +37,12 @@ type Provider struct {
|
|||||||
Setter libdns.RecordSetter
|
Setter libdns.RecordSetter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func InitDNSServers(s string) {
|
||||||
|
if s != "" {
|
||||||
|
customDNSServers = strings.Split(s, ",")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (provider *Provider) UpdateDomain(ctx context.Context) {
|
func (provider *Provider) UpdateDomain(ctx context.Context) {
|
||||||
provider.ctx = ctx
|
provider.ctx = ctx
|
||||||
for _, domain := range provider.DDNSProfile.Domains {
|
for _, domain := range provider.DDNSProfile.Domains {
|
||||||
@@ -95,12 +105,17 @@ func splitDomainSOA(domain string) (prefix string, zone string, err error) {
|
|||||||
domain += "."
|
domain += "."
|
||||||
indexes := dns.Split(domain)
|
indexes := dns.Split(domain)
|
||||||
|
|
||||||
|
servers := utils.DNSServers
|
||||||
|
if len(customDNSServers) > 0 {
|
||||||
|
servers = customDNSServers
|
||||||
|
}
|
||||||
|
|
||||||
var r *dns.Msg
|
var r *dns.Msg
|
||||||
for _, idx := range indexes {
|
for _, idx := range indexes {
|
||||||
m := new(dns.Msg)
|
m := new(dns.Msg)
|
||||||
m.SetQuestion(domain[idx:], dns.TypeSOA)
|
m.SetQuestion(domain[idx:], dns.TypeSOA)
|
||||||
|
|
||||||
for _, server := range utils.DNSServers {
|
for _, server := range servers {
|
||||||
r, _, err = c.Exchange(m, server)
|
r, _, err = c.Exchange(m, server)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@@ -108,7 +123,7 @@ func splitDomainSOA(domain string) (prefix string, zone string, err error) {
|
|||||||
if len(r.Answer) > 0 {
|
if len(r.Answer) > 0 {
|
||||||
if soa, ok := r.Answer[0].(*dns.SOA); ok {
|
if soa, ok := r.Answer[0].(*dns.SOA); ok {
|
||||||
zone = soa.Hdr.Name
|
zone = soa.Hdr.Name
|
||||||
prefix = domain[:len(domain)-len(zone)-1]
|
prefix = libdns.RelativeName(domain, zone)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,11 @@ func TestSplitDomainSOA(t *testing.T) {
|
|||||||
zone: "example.com.",
|
zone: "example.com.",
|
||||||
prefix: "abc",
|
prefix: "abc",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
domain: "example.com",
|
||||||
|
zone: "example.com.",
|
||||||
|
prefix: "",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
|
|||||||
@@ -159,6 +159,8 @@ func (provider *Provider) formatWebhookString(s string) string {
|
|||||||
"#domain#", provider.domain,
|
"#domain#", provider.domain,
|
||||||
"#type#", provider.ipType,
|
"#type#", provider.ipType,
|
||||||
"#record#", provider.recordType,
|
"#record#", provider.recordType,
|
||||||
|
"#access_id#", provider.DDNSProfile.AccessID,
|
||||||
|
"#access_secret#", provider.DDNSProfile.AccessSecret,
|
||||||
"\r", "",
|
"\r", "",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -13,7 +13,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
Json = jsoniter.ConfigCompatibleWithStandardLibrary
|
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 {
|
func IsWindows() bool {
|
||||||
|
|||||||
Vendored
+6
@@ -670,6 +670,9 @@ other = "Webhook URL"
|
|||||||
[WebhookMethod]
|
[WebhookMethod]
|
||||||
other = "Webhook Request Method"
|
other = "Webhook Request Method"
|
||||||
|
|
||||||
|
[WebhookRequestType]
|
||||||
|
other = "Webhook Request Type"
|
||||||
|
|
||||||
[WebhookHeaders]
|
[WebhookHeaders]
|
||||||
other = "Webhook Request Headers"
|
other = "Webhook Request Headers"
|
||||||
|
|
||||||
@@ -744,3 +747,6 @@ other = "Expired"
|
|||||||
|
|
||||||
[Days]
|
[Days]
|
||||||
other = "d"
|
other = "d"
|
||||||
|
|
||||||
|
[CustomNameservers]
|
||||||
|
other = "Custom Public DNS Nameservers for DDNS (separate with comma)"
|
||||||
|
|||||||
Vendored
+6
@@ -670,6 +670,9 @@ other = "URL del Webhook"
|
|||||||
[WebhookMethod]
|
[WebhookMethod]
|
||||||
other = "Método de Solicitud del Webhook"
|
other = "Método de Solicitud del Webhook"
|
||||||
|
|
||||||
|
[WebhookRequestType]
|
||||||
|
other = "Tipo de solicitud del Webhook"
|
||||||
|
|
||||||
[WebhookHeaders]
|
[WebhookHeaders]
|
||||||
other = "Encabezados de Solicitud del Webhook"
|
other = "Encabezados de Solicitud del Webhook"
|
||||||
|
|
||||||
@@ -744,3 +747,6 @@ other = "Expired"
|
|||||||
|
|
||||||
[Days]
|
[Days]
|
||||||
other = "d"
|
other = "d"
|
||||||
|
|
||||||
|
[CustomNameservers]
|
||||||
|
other = "Servidores DNS públicos personalizados para DDNS (separar con coma)"
|
||||||
|
|||||||
Vendored
+11
-5
@@ -632,22 +632,22 @@ other = "DDNS配置"
|
|||||||
other = "新配置"
|
other = "新配置"
|
||||||
|
|
||||||
[EnableDDNS]
|
[EnableDDNS]
|
||||||
other = "启用DDNS"
|
other = "启用 DDNS"
|
||||||
|
|
||||||
[EnableIPv4]
|
[EnableIPv4]
|
||||||
other = "启用DDNS IPv4"
|
other = "启用 DDNS IPv4"
|
||||||
|
|
||||||
[EnableIPv6]
|
[EnableIPv6]
|
||||||
other = "启用DDNS IPv6"
|
other = "启用 DDNS IPv6"
|
||||||
|
|
||||||
[DDNSDomain]
|
[DDNSDomain]
|
||||||
other = "DDNS域名"
|
other = "DDNS 域名"
|
||||||
|
|
||||||
[DDNSDomains]
|
[DDNSDomains]
|
||||||
other = "域名(逗号分隔)"
|
other = "域名(逗号分隔)"
|
||||||
|
|
||||||
[DDNSProvider]
|
[DDNSProvider]
|
||||||
other = "DDNS供应商"
|
other = "DDNS 供应商"
|
||||||
|
|
||||||
[MaxRetries]
|
[MaxRetries]
|
||||||
other = "最大重试次数"
|
other = "最大重试次数"
|
||||||
@@ -670,6 +670,9 @@ other = "Webhook 地址"
|
|||||||
[WebhookMethod]
|
[WebhookMethod]
|
||||||
other = "Webhook 请求方式"
|
other = "Webhook 请求方式"
|
||||||
|
|
||||||
|
[WebhookRequestType]
|
||||||
|
other = "Webhook 请求类型"
|
||||||
|
|
||||||
[WebhookHeaders]
|
[WebhookHeaders]
|
||||||
other = "Webhook 请求头"
|
other = "Webhook 请求头"
|
||||||
|
|
||||||
@@ -744,3 +747,6 @@ other = "已到期"
|
|||||||
|
|
||||||
[Days]
|
[Days]
|
||||||
other = "天"
|
other = "天"
|
||||||
|
|
||||||
|
[CustomNameservers]
|
||||||
|
other = "自定义DDNS使用的公共DNS服务器(逗号分隔)"
|
||||||
|
|||||||
Vendored
+19
-13
@@ -632,49 +632,52 @@ other = "DDNS配置"
|
|||||||
other = "新增配置"
|
other = "新增配置"
|
||||||
|
|
||||||
[EnableDDNS]
|
[EnableDDNS]
|
||||||
other = "啟用DDNS"
|
other = "啟用 DDNS"
|
||||||
|
|
||||||
[EnableIPv4]
|
[EnableIPv4]
|
||||||
other = "啟用DDNS IPv4"
|
other = "啟用 DDNS IPv4"
|
||||||
|
|
||||||
[EnableIPv6]
|
[EnableIPv6]
|
||||||
other = "啟用DDNS IPv6"
|
other = "啟用 DDNS IPv6"
|
||||||
|
|
||||||
[DDNSDomain]
|
[DDNSDomain]
|
||||||
other = "DDNS域名"
|
other = "DDNS 域名"
|
||||||
|
|
||||||
[DDNSDomains]
|
[DDNSDomains]
|
||||||
other = "域名(逗號分隔)"
|
other = "域名(逗號分隔)"
|
||||||
|
|
||||||
[DDNSProvider]
|
[DDNSProvider]
|
||||||
other = "DDNS供應商"
|
other = "DDN S供應商"
|
||||||
|
|
||||||
[MaxRetries]
|
[MaxRetries]
|
||||||
other = "最大重試次數"
|
other = "最大重試次數"
|
||||||
|
|
||||||
[DDNSAccessID]
|
[DDNSAccessID]
|
||||||
other = "DDNS憑據1"
|
other = "DDNS 憑據 1"
|
||||||
|
|
||||||
[DDNSAccessSecret]
|
[DDNSAccessSecret]
|
||||||
other = "DDNS憑據2"
|
other = "DDNS 憑據 2"
|
||||||
|
|
||||||
[DDNSTokenID]
|
[DDNSTokenID]
|
||||||
other = "令牌ID"
|
other = "令牌 ID"
|
||||||
|
|
||||||
[DDNSTokenSecret]
|
[DDNSTokenSecret]
|
||||||
other = "令牌Secret"
|
other = "令牌 Secret"
|
||||||
|
|
||||||
[WebhookURL]
|
[WebhookURL]
|
||||||
other = "Webhook地址"
|
other = "Webhook 地址"
|
||||||
|
|
||||||
[WebhookMethod]
|
[WebhookMethod]
|
||||||
other = "Webhook請求方式"
|
other = "Webhook 請求方式"
|
||||||
|
|
||||||
|
[WebhookRequestType]
|
||||||
|
other = "Webhook 請求類型"
|
||||||
|
|
||||||
[WebhookHeaders]
|
[WebhookHeaders]
|
||||||
other = "Webhook請求頭"
|
other = "Webhook 請求頭"
|
||||||
|
|
||||||
[WebhookRequestBody]
|
[WebhookRequestBody]
|
||||||
other = "Webhook請求體"
|
other = "Webhook 請求體"
|
||||||
|
|
||||||
[Feature]
|
[Feature]
|
||||||
other = "功能"
|
other = "功能"
|
||||||
@@ -744,3 +747,6 @@ other = "已到期"
|
|||||||
|
|
||||||
[Days]
|
[Days]
|
||||||
other = "天"
|
other = "天"
|
||||||
|
|
||||||
|
[CustomNameservers]
|
||||||
|
other = "自訂DDNS使用的公共DNS伺服器(逗號分隔)"
|
||||||
|
|||||||
@@ -102,7 +102,8 @@ function showFormModal(modelSelector, formID, URL, getData) {
|
|||||||
item.name === "Duration" ||
|
item.name === "Duration" ||
|
||||||
item.name === "MaxRetries" ||
|
item.name === "MaxRetries" ||
|
||||||
item.name === "Provider" ||
|
item.name === "Provider" ||
|
||||||
item.name === "WebhookMethod"
|
item.name === "WebhookMethod" ||
|
||||||
|
item.name === "WebhookRequestType"
|
||||||
) {
|
) {
|
||||||
obj[item.name] = parseInt(item.value);
|
obj[item.name] = parseInt(item.value);
|
||||||
} else if (item.name.endsWith("Latency")) {
|
} else if (item.name.endsWith("Latency")) {
|
||||||
@@ -299,6 +300,9 @@ function addOrEditDDNS(ddns) {
|
|||||||
modal
|
modal
|
||||||
.find("select[name=WebhookMethod]")
|
.find("select[name=WebhookMethod]")
|
||||||
.val(ddns ? ddns.WebhookMethod : 1);
|
.val(ddns ? ddns.WebhookMethod : 1);
|
||||||
|
modal
|
||||||
|
.find("select[name=WebhookRequestType]")
|
||||||
|
.val(ddns ? ddns.WebhookRequestType : 1);
|
||||||
if (ddns && ddns.EnableIPv4) {
|
if (ddns && ddns.EnableIPv4) {
|
||||||
modal.find(".ui.enableipv4.checkbox").checkbox("set checked");
|
modal.find(".ui.enableipv4.checkbox").checkbox("set checked");
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+7
@@ -48,6 +48,13 @@
|
|||||||
<option value="5">PUT</option>
|
<option value="5">PUT</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label>{{tr "WebhookRequestType"}}</label>
|
||||||
|
<select name="WebhookRequestType" class="ui fluid dropdown">
|
||||||
|
<option value="1">JSON</option>
|
||||||
|
<option value="2">Form</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>{{tr "WebhookHeaders"}}</label>
|
<label>{{tr "WebhookHeaders"}}</label>
|
||||||
<textarea name="WebhookHeaders" placeholder='{"User-Agent":"Nezha-Agent"}'></textarea>
|
<textarea name="WebhookHeaders" placeholder='{"User-Agent":"Nezha-Agent"}'></textarea>
|
||||||
|
|||||||
@@ -53,6 +53,10 @@
|
|||||||
<label>{{tr "PanelServerDomainAndIP"}}</label>
|
<label>{{tr "PanelServerDomainAndIP"}}</label>
|
||||||
<input type="text" name="GRPCHost" placeholder="" value="{{.Conf.GRPCHost}}">
|
<input type="text" name="GRPCHost" placeholder="" value="{{.Conf.GRPCHost}}">
|
||||||
</div>
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label>{{tr "CustomNameservers"}}</label>
|
||||||
|
<input type="text" name="CustomNameservers" placeholder="" value="{{.Conf.DNSServers}}">
|
||||||
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>{{tr "IPChangeAlert"}}</label>
|
<label>{{tr "IPChangeAlert"}}</label>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ var (
|
|||||||
|
|
||||||
func initDDNS() {
|
func initDDNS() {
|
||||||
OnDDNSUpdate()
|
OnDDNSUpdate()
|
||||||
|
OnNameserverUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
func OnDDNSUpdate() {
|
func OnDDNSUpdate() {
|
||||||
@@ -33,6 +34,10 @@ func OnDDNSUpdate() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func OnNameserverUpdate() {
|
||||||
|
ddns2.InitDNSServers(Conf.DNSServers)
|
||||||
|
}
|
||||||
|
|
||||||
func GetDDNSProvidersFromProfiles(profileId []uint64, ip *ddns2.IP) ([]*ddns2.Provider, error) {
|
func GetDDNSProvidersFromProfiles(profileId []uint64, ip *ddns2.IP) ([]*ddns2.Provider, error) {
|
||||||
profiles := make([]*model.DDNSProfile, 0, len(profileId))
|
profiles := make([]*model.DDNSProfile, 0, len(profileId))
|
||||||
ddnsCacheLock.RLock()
|
ddnsCacheLock.RLock()
|
||||||
|
|||||||
Reference in New Issue
Block a user