diff --git a/cmd/dashboard/controller/common_page.go b/cmd/dashboard/controller/common_page.go
index 5d0b309..b41f035 100644
--- a/cmd/dashboard/controller/common_page.go
+++ b/cmd/dashboard/controller/common_page.go
@@ -209,7 +209,7 @@ func (cp *commonPage) network(c *gin.Context) {
}))
}
-func (cp *commonPage) getServerStat(c *gin.Context) ([]byte, error) {
+func (cp *commonPage) getServerStat(c *gin.Context, withPublicNote bool) ([]byte, error) {
_, isMember := c.Get(model.CtxKeyAuthorizedUser)
_, isViewPasswordVerfied := c.Get(model.CtxKeyViewPasswordVerified)
authorized := isMember || isViewPasswordVerfied
@@ -219,16 +219,15 @@ func (cp *commonPage) getServerStat(c *gin.Context) ([]byte, error) {
var servers []*model.Server
- if authorized {
- servers = singleton.SortedServerList
- } else {
- filteredServers := make([]*model.Server, len(singleton.SortedServerListForGuest))
- for i, server := range singleton.SortedServerListForGuest {
- filteredServer := *server
- filteredServer.DDNSDomain = "redacted"
- filteredServers[i] = &filteredServer
+ for _, server := range singleton.SortedServerListForGuest {
+ item := *server
+ if item.HideForGuest && !authorized {
+ continue
}
- servers = filteredServers
+ if !withPublicNote {
+ item.PublicNote = ""
+ }
+ servers = append(servers, &item)
}
return utils.Json.Marshal(Data{
@@ -240,7 +239,7 @@ func (cp *commonPage) getServerStat(c *gin.Context) ([]byte, error) {
}
func (cp *commonPage) home(c *gin.Context) {
- stat, err := cp.getServerStat(c)
+ stat, err := cp.getServerStat(c, true)
if err != nil {
mygin.ShowErrorPage(c, mygin.ErrInfo{
Code: http.StatusInternalServerError,
@@ -285,7 +284,7 @@ func (cp *commonPage) ws(c *gin.Context) {
defer conn.Close()
count := 0
for {
- stat, err := cp.getServerStat(c)
+ stat, err := cp.getServerStat(c, false)
if err != nil {
continue
}
diff --git a/cmd/dashboard/controller/member_api.go b/cmd/dashboard/controller/member_api.go
index 713a275..3878e74 100644
--- a/cmd/dashboard/controller/member_api.go
+++ b/cmd/dashboard/controller/member_api.go
@@ -306,6 +306,7 @@ type serverForm struct {
Secret string
Tag string
Note string
+ PublicNote string
HideForGuest string
EnableDDNS string
EnableIPv4 string
@@ -326,6 +327,7 @@ func (ma *memberAPI) addOrEditServer(c *gin.Context) {
s.ID = sf.ID
s.Tag = sf.Tag
s.Note = sf.Note
+ s.PublicNote = sf.PublicNote
s.HideForGuest = sf.HideForGuest == "on"
s.EnableDDNS = sf.EnableDDNS == "on"
s.EnableIPv4 = sf.EnableIPv4 == "on"
diff --git a/model/server.go b/model/server.go
index 043bada..d481087 100644
--- a/model/server.go
+++ b/model/server.go
@@ -15,7 +15,8 @@ type Server struct {
Name string
Tag string // 分组名
Secret string `gorm:"uniqueIndex" json:"-"`
- Note string `json:"-"` // 管理员可见备注
+ Note string `json:"-"` // 管理员可见备注
+ PublicNote string `json:"PublicNote,omitempty"` // 公开备注
DisplayIndex int // 展示排序,越大越靠前
HideForGuest bool // 对游客隐藏
EnableDDNS bool `json:"-"` // 是否启用DDNS 未在配置文件中启用DDNS 或 DDNS检查时间为0时此项无效
@@ -54,12 +55,13 @@ func boolToString(b bool) string {
return "false"
}
-func (s Server) Marshal() template.JS {
+func (s Server) MarshalForDashboard() template.JS {
name, _ := utils.Json.Marshal(s.Name)
tag, _ := utils.Json.Marshal(s.Tag)
note, _ := utils.Json.Marshal(s.Note)
secret, _ := utils.Json.Marshal(s.Secret)
ddnsDomain, _ := utils.Json.Marshal(s.DDNSDomain)
ddnsProfile, _ := utils.Json.Marshal(s.DDNSProfile)
- 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,"DDNSProfile": %s}`, s.ID, name, secret, s.DisplayIndex, tag, note, boolToString(s.HideForGuest), boolToString(s.EnableDDNS), boolToString(s.EnableIPv4), boolToString(s.EnableIpv6), ddnsDomain, ddnsProfile)) // #nosec
+ publicNote, _ := utils.Json.Marshal(s.PublicNote)
+ 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,"DDNSProfile": %s,"PublicNote": %s}`, s.ID, name, secret, s.DisplayIndex, tag, note, boolToString(s.HideForGuest), boolToString(s.EnableDDNS), boolToString(s.EnableIPv4), boolToString(s.EnableIpv6), ddnsDomain, ddnsProfile, publicNote))
}
diff --git a/model/server_test.go b/model/server_test.go
index b55b81d..7a4d91f 100644
--- a/model/server_test.go
+++ b/model/server_test.go
@@ -18,7 +18,7 @@ func TestServerMarshal(t *testing.T) {
Name: patterns[i],
Tag: patterns[i],
}
- serverStr := string(server.Marshal())
+ serverStr := string(server.MarshalForDashboard())
var serverRestore Server
if utils.Json.Unmarshal([]byte(serverStr), &serverRestore) != nil {
t.Fatalf("Error: %s", serverStr)
diff --git a/resource/l10n/en-US.toml b/resource/l10n/en-US.toml
index bb46b04..3884ab0 100644
--- a/resource/l10n/en-US.toml
+++ b/resource/l10n/en-US.toml
@@ -226,6 +226,9 @@ other = "Secret"
[Note]
other = "Note"
+[PublicNote]
+other = "Public Note"
+
[LinuxOneKeyInstall]
other = "Linux One-Command Install"
diff --git a/resource/l10n/es-ES.toml b/resource/l10n/es-ES.toml
index e4ba8f7..1d77d67 100644
--- a/resource/l10n/es-ES.toml
+++ b/resource/l10n/es-ES.toml
@@ -226,6 +226,9 @@ other = "Secreto"
[Note]
other = "Nota"
+[PublicNote]
+other = "Nota Pública"
+
[LinuxOneKeyInstall]
other = "Instalación Linux con Un Solo Clic"
diff --git a/resource/l10n/zh-CN.toml b/resource/l10n/zh-CN.toml
index 2a622f4..2208494 100644
--- a/resource/l10n/zh-CN.toml
+++ b/resource/l10n/zh-CN.toml
@@ -226,6 +226,9 @@ other = "密钥"
[Note]
other = "备注"
+[PublicNote]
+other = "公开备注"
+
[LinuxOneKeyInstall]
other = "Linux 一键安装"
diff --git a/resource/l10n/zh-TW.toml b/resource/l10n/zh-TW.toml
index aa84097..cde3d23 100644
--- a/resource/l10n/zh-TW.toml
+++ b/resource/l10n/zh-TW.toml
@@ -226,6 +226,9 @@ other = "金鑰"
[Note]
other = "備註"
+[PublicNote]
+other = "公開備註"
+
[LinuxOneKeyInstall]
other = "Linux 一鍵安裝"
diff --git a/resource/static/main.js b/resource/static/main.js
index e5e91a1..28d31ea 100644
--- a/resource/static/main.js
+++ b/resource/static/main.js
@@ -331,6 +331,7 @@ function addOrEditServer(server, conf) {
.find("input[name=DisplayIndex]")
.val(server ? server.DisplayIndex : null);
modal.find("textarea[name=Note]").val(server ? server.Note : null);
+ modal.find("textarea[name=PublicNote]").val(server ? server.PublicNote : null);
if (server) {
modal.find(".secret.field").attr("style", "");
modal.find(".command.field").attr("style", "");
diff --git a/resource/template/common/footer.html b/resource/template/common/footer.html
index 042b433..a787fa0 100644
--- a/resource/template/common/footer.html
+++ b/resource/template/common/footer.html
@@ -10,7 +10,7 @@
-
+