From f647a5f8e675a8831db22116b25fecd7f75e9678 Mon Sep 17 00:00:00 2001 From: UUBulb <35923940+uubulb@users.noreply.github.com> Date: Sat, 30 Mar 2024 11:00:55 +0800 Subject: [PATCH] ddns: Add ability to update IPv4 or IPv6 only (#342) * ddns: Add ability to resolve IPv4 or IPv6 only * Fix bugs * cdn cache --- cmd/dashboard/controller/member_api.go | 4 ++++ model/server.go | 4 +++- resource/l10n/en-US.toml | 6 ++++++ resource/l10n/es-ES.toml | 6 ++++++ resource/l10n/zh-CN.toml | 6 ++++++ resource/l10n/zh-TW.toml | 6 ++++++ resource/static/main.js | 10 ++++++++++ resource/template/common/footer.html | 2 +- resource/template/component/server.html | 12 ++++++++++++ resource/template/dashboard-default/server.html | 4 ++++ resource/template/theme-angel-kanade/footer.html | 2 +- service/rpc/nezha.go | 4 ++-- 12 files changed, 61 insertions(+), 5 deletions(-) diff --git a/cmd/dashboard/controller/member_api.go b/cmd/dashboard/controller/member_api.go index 69f9712..ca318a0 100644 --- a/cmd/dashboard/controller/member_api.go +++ b/cmd/dashboard/controller/member_api.go @@ -301,6 +301,8 @@ type serverForm struct { Note string HideForGuest string EnableDDNS string + EnableIPv4 string + EnableIpv6 string DDNSDomain string } @@ -318,6 +320,8 @@ func (ma *memberAPI) addOrEditServer(c *gin.Context) { s.Note = sf.Note s.HideForGuest = sf.HideForGuest == "on" s.EnableDDNS = sf.EnableDDNS == "on" + s.EnableIPv4 = sf.EnableIPv4 == "on" + s.EnableIpv6 = sf.EnableIpv6 == "on" s.DDNSDomain = sf.DDNSDomain if s.ID == 0 { s.Secret, err = utils.GenerateRandomString(18) diff --git a/model/server.go b/model/server.go index 3077265..106509b 100644 --- a/model/server.go +++ b/model/server.go @@ -18,6 +18,8 @@ type Server struct { DisplayIndex int // 展示排序,越大越靠前 HideForGuest bool // 对游客隐藏 EnableDDNS bool // 是否启用DDNS 未在配置文件中启用DDNS 或 DDNS检查时间为0时此项无效 + EnableIPv4 bool // 是否启用DDNS IPv4 + EnableIpv6 bool // 是否启用DDNS IPv6 DDNSDomain string // DDNS中的前缀 如基础域名为abc.oracle DDNSName为mjj 就会把mjj.abc.oracle解析服务器IP 为空则停用 Host *Host `gorm:"-"` @@ -54,5 +56,5 @@ func (s Server) Marshal() template.JS { note, _ := utils.Json.Marshal(s.Note) secret, _ := utils.Json.Marshal(s.Secret) ddnsDomain, _ := utils.Json.Marshal(s.DDNSDomain) - return template.JS(fmt.Sprintf(`{"ID":%d,"Name":%s,"Secret":%s,"DisplayIndex":%d,"Tag":%s,"Note":%s,"HideForGuest": %s,"EnableDDNS": %s,"DDNSDomain": %s}`, s.ID, name, secret, s.DisplayIndex, tag, note, boolToString(s.HideForGuest), boolToString(s.EnableDDNS), ddnsDomain)) // #nosec + return template.JS(fmt.Sprintf(`{"ID":%d,"Name":%s,"Secret":%s,"DisplayIndex":%d,"Tag":%s,"Note":%s,"HideForGuest": %s,"EnableDDNS": %s,"EnableIPv4": %s,"EnableIpv6": %s,"DDNSDomain": %s}`, s.ID, name, secret, s.DisplayIndex, tag, note, boolToString(s.HideForGuest), boolToString(s.EnableDDNS), boolToString(s.EnableIPv4), boolToString(s.EnableIpv6), ddnsDomain)) // #nosec } diff --git a/resource/l10n/en-US.toml b/resource/l10n/en-US.toml index c9ecf73..8214373 100644 --- a/resource/l10n/en-US.toml +++ b/resource/l10n/en-US.toml @@ -619,6 +619,12 @@ other = "Enable Show in Service" [EnableDDNS] other = "Enable DDNS" +[EnableIPv4] +other = "Enable DDNS IPv4" + +[EnableIpv6] +other = "Enable DDNS IPv6" + [DDNSDomain] other = "DDNS Domain" diff --git a/resource/l10n/es-ES.toml b/resource/l10n/es-ES.toml index 0a2d8a0..1c727bb 100644 --- a/resource/l10n/es-ES.toml +++ b/resource/l10n/es-ES.toml @@ -619,6 +619,12 @@ other = "Mostrar en servicio" [EnableDDNS] other = "Habilitar DDNS" +[EnableIPv4] +other = "Habilitar DDNS IPv4" + +[EnableIpv6] +other = "Habilitar DDNS IPv6" + [DDNSDomain] other = "Dominio DDNS" diff --git a/resource/l10n/zh-CN.toml b/resource/l10n/zh-CN.toml index b818bd8..212b236 100644 --- a/resource/l10n/zh-CN.toml +++ b/resource/l10n/zh-CN.toml @@ -619,6 +619,12 @@ other = "在服务中显示" [EnableDDNS] other = "启用DDNS" +[EnableIPv4] +other = "启用DDNS IPv4" + +[EnableIpv6] +other = "启用DDNS IPv6" + [DDNSDomain] other = "DDNS域名" diff --git a/resource/l10n/zh-TW.toml b/resource/l10n/zh-TW.toml index 717988a..1aaaba4 100644 --- a/resource/l10n/zh-TW.toml +++ b/resource/l10n/zh-TW.toml @@ -619,6 +619,12 @@ other = "在服務中顯示" [EnableDDNS] other = "啟用DDNS" +[EnableIPv4] +other = "啟用DDNS IPv4" + +[EnableIpv6] +other = "啟用DDNS IPv6" + [DDNSDomain] other = "DDNS網域" diff --git a/resource/static/main.js b/resource/static/main.js index f3b8c74..b4503cc 100644 --- a/resource/static/main.js +++ b/resource/static/main.js @@ -327,6 +327,16 @@ function addOrEditServer(server, conf) { } else { modal.find(".ui.enableddns.checkbox").checkbox("set unchecked"); } + if (server && server.EnableIPv4) { + modal.find(".ui.enableipv4.checkbox").checkbox("set checked"); + } else { + modal.find(".ui.enableipv4.checkbox").checkbox("set unchecked"); + } + if (server && server.EnableIpv6) { + modal.find(".ui.enableipv6.checkbox").checkbox("set checked"); + } else { + modal.find(".ui.enableipv6.checkbox").checkbox("set unchecked"); + } showFormModal(".server.modal", "#serverForm", "/api/server"); } diff --git a/resource/template/common/footer.html b/resource/template/common/footer.html index f243702..94a61c2 100644 --- a/resource/template/common/footer.html +++ b/resource/template/common/footer.html @@ -10,7 +10,7 @@ - + - +