mirror of
https://github.com/nezhahq/nezha.git
synced 2025-02-02 01:28:13 -05:00
✨ 增加透传给前端的自定义字段方便前端扩展功能
This commit is contained in:
parent
bdf36276da
commit
106d58575b
@ -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)
|
_, isMember := c.Get(model.CtxKeyAuthorizedUser)
|
||||||
_, isViewPasswordVerfied := c.Get(model.CtxKeyViewPasswordVerified)
|
_, isViewPasswordVerfied := c.Get(model.CtxKeyViewPasswordVerified)
|
||||||
authorized := isMember || isViewPasswordVerfied
|
authorized := isMember || isViewPasswordVerfied
|
||||||
@ -219,16 +219,15 @@ func (cp *commonPage) getServerStat(c *gin.Context) ([]byte, error) {
|
|||||||
|
|
||||||
var servers []*model.Server
|
var servers []*model.Server
|
||||||
|
|
||||||
if authorized {
|
for _, server := range singleton.SortedServerListForGuest {
|
||||||
servers = singleton.SortedServerList
|
item := *server
|
||||||
} else {
|
if item.HideForGuest && !authorized {
|
||||||
filteredServers := make([]*model.Server, len(singleton.SortedServerListForGuest))
|
continue
|
||||||
for i, server := range singleton.SortedServerListForGuest {
|
|
||||||
filteredServer := *server
|
|
||||||
filteredServer.DDNSDomain = "redacted"
|
|
||||||
filteredServers[i] = &filteredServer
|
|
||||||
}
|
}
|
||||||
servers = filteredServers
|
if !withPublicNote {
|
||||||
|
item.PublicNote = ""
|
||||||
|
}
|
||||||
|
servers = append(servers, &item)
|
||||||
}
|
}
|
||||||
|
|
||||||
return utils.Json.Marshal(Data{
|
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) {
|
func (cp *commonPage) home(c *gin.Context) {
|
||||||
stat, err := cp.getServerStat(c)
|
stat, err := cp.getServerStat(c, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
mygin.ShowErrorPage(c, mygin.ErrInfo{
|
mygin.ShowErrorPage(c, mygin.ErrInfo{
|
||||||
Code: http.StatusInternalServerError,
|
Code: http.StatusInternalServerError,
|
||||||
@ -285,7 +284,7 @@ func (cp *commonPage) ws(c *gin.Context) {
|
|||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
count := 0
|
count := 0
|
||||||
for {
|
for {
|
||||||
stat, err := cp.getServerStat(c)
|
stat, err := cp.getServerStat(c, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -306,6 +306,7 @@ type serverForm struct {
|
|||||||
Secret string
|
Secret string
|
||||||
Tag string
|
Tag string
|
||||||
Note string
|
Note string
|
||||||
|
PublicNote string
|
||||||
HideForGuest string
|
HideForGuest string
|
||||||
EnableDDNS string
|
EnableDDNS string
|
||||||
EnableIPv4 string
|
EnableIPv4 string
|
||||||
@ -326,6 +327,7 @@ func (ma *memberAPI) addOrEditServer(c *gin.Context) {
|
|||||||
s.ID = sf.ID
|
s.ID = sf.ID
|
||||||
s.Tag = sf.Tag
|
s.Tag = sf.Tag
|
||||||
s.Note = sf.Note
|
s.Note = sf.Note
|
||||||
|
s.PublicNote = sf.PublicNote
|
||||||
s.HideForGuest = sf.HideForGuest == "on"
|
s.HideForGuest = sf.HideForGuest == "on"
|
||||||
s.EnableDDNS = sf.EnableDDNS == "on"
|
s.EnableDDNS = sf.EnableDDNS == "on"
|
||||||
s.EnableIPv4 = sf.EnableIPv4 == "on"
|
s.EnableIPv4 = sf.EnableIPv4 == "on"
|
||||||
|
@ -15,7 +15,8 @@ type Server struct {
|
|||||||
Name string
|
Name string
|
||||||
Tag string // 分组名
|
Tag string // 分组名
|
||||||
Secret string `gorm:"uniqueIndex" json:"-"`
|
Secret string `gorm:"uniqueIndex" json:"-"`
|
||||||
Note string `json:"-"` // 管理员可见备注
|
Note string `json:"-"` // 管理员可见备注
|
||||||
|
PublicNote string `json:"PublicNote,omitempty"` // 公开备注
|
||||||
DisplayIndex int // 展示排序,越大越靠前
|
DisplayIndex int // 展示排序,越大越靠前
|
||||||
HideForGuest bool // 对游客隐藏
|
HideForGuest bool // 对游客隐藏
|
||||||
EnableDDNS bool `json:"-"` // 是否启用DDNS 未在配置文件中启用DDNS 或 DDNS检查时间为0时此项无效
|
EnableDDNS bool `json:"-"` // 是否启用DDNS 未在配置文件中启用DDNS 或 DDNS检查时间为0时此项无效
|
||||||
@ -54,12 +55,13 @@ func boolToString(b bool) string {
|
|||||||
return "false"
|
return "false"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Server) Marshal() template.JS {
|
func (s Server) MarshalForDashboard() template.JS {
|
||||||
name, _ := utils.Json.Marshal(s.Name)
|
name, _ := utils.Json.Marshal(s.Name)
|
||||||
tag, _ := utils.Json.Marshal(s.Tag)
|
tag, _ := utils.Json.Marshal(s.Tag)
|
||||||
note, _ := utils.Json.Marshal(s.Note)
|
note, _ := utils.Json.Marshal(s.Note)
|
||||||
secret, _ := utils.Json.Marshal(s.Secret)
|
secret, _ := utils.Json.Marshal(s.Secret)
|
||||||
ddnsDomain, _ := utils.Json.Marshal(s.DDNSDomain)
|
ddnsDomain, _ := utils.Json.Marshal(s.DDNSDomain)
|
||||||
ddnsProfile, _ := utils.Json.Marshal(s.DDNSProfile)
|
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))
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ func TestServerMarshal(t *testing.T) {
|
|||||||
Name: patterns[i],
|
Name: patterns[i],
|
||||||
Tag: patterns[i],
|
Tag: patterns[i],
|
||||||
}
|
}
|
||||||
serverStr := string(server.Marshal())
|
serverStr := string(server.MarshalForDashboard())
|
||||||
var serverRestore Server
|
var serverRestore Server
|
||||||
if utils.Json.Unmarshal([]byte(serverStr), &serverRestore) != nil {
|
if utils.Json.Unmarshal([]byte(serverStr), &serverRestore) != nil {
|
||||||
t.Fatalf("Error: %s", serverStr)
|
t.Fatalf("Error: %s", serverStr)
|
||||||
|
3
resource/l10n/en-US.toml
vendored
3
resource/l10n/en-US.toml
vendored
@ -226,6 +226,9 @@ other = "Secret"
|
|||||||
[Note]
|
[Note]
|
||||||
other = "Note"
|
other = "Note"
|
||||||
|
|
||||||
|
[PublicNote]
|
||||||
|
other = "Public Note"
|
||||||
|
|
||||||
[LinuxOneKeyInstall]
|
[LinuxOneKeyInstall]
|
||||||
other = "Linux One-Command Install"
|
other = "Linux One-Command Install"
|
||||||
|
|
||||||
|
3
resource/l10n/es-ES.toml
vendored
3
resource/l10n/es-ES.toml
vendored
@ -226,6 +226,9 @@ other = "Secreto"
|
|||||||
[Note]
|
[Note]
|
||||||
other = "Nota"
|
other = "Nota"
|
||||||
|
|
||||||
|
[PublicNote]
|
||||||
|
other = "Nota Pública"
|
||||||
|
|
||||||
[LinuxOneKeyInstall]
|
[LinuxOneKeyInstall]
|
||||||
other = "Instalación Linux con Un Solo Clic"
|
other = "Instalación Linux con Un Solo Clic"
|
||||||
|
|
||||||
|
3
resource/l10n/zh-CN.toml
vendored
3
resource/l10n/zh-CN.toml
vendored
@ -226,6 +226,9 @@ other = "密钥"
|
|||||||
[Note]
|
[Note]
|
||||||
other = "备注"
|
other = "备注"
|
||||||
|
|
||||||
|
[PublicNote]
|
||||||
|
other = "公开备注"
|
||||||
|
|
||||||
[LinuxOneKeyInstall]
|
[LinuxOneKeyInstall]
|
||||||
other = "Linux 一键安装"
|
other = "Linux 一键安装"
|
||||||
|
|
||||||
|
3
resource/l10n/zh-TW.toml
vendored
3
resource/l10n/zh-TW.toml
vendored
@ -226,6 +226,9 @@ other = "金鑰"
|
|||||||
[Note]
|
[Note]
|
||||||
other = "備註"
|
other = "備註"
|
||||||
|
|
||||||
|
[PublicNote]
|
||||||
|
other = "公開備註"
|
||||||
|
|
||||||
[LinuxOneKeyInstall]
|
[LinuxOneKeyInstall]
|
||||||
other = "Linux 一鍵安裝"
|
other = "Linux 一鍵安裝"
|
||||||
|
|
||||||
|
@ -331,6 +331,7 @@ function addOrEditServer(server, conf) {
|
|||||||
.find("input[name=DisplayIndex]")
|
.find("input[name=DisplayIndex]")
|
||||||
.val(server ? server.DisplayIndex : null);
|
.val(server ? server.DisplayIndex : null);
|
||||||
modal.find("textarea[name=Note]").val(server ? server.Note : null);
|
modal.find("textarea[name=Note]").val(server ? server.Note : null);
|
||||||
|
modal.find("textarea[name=PublicNote]").val(server ? server.PublicNote : null);
|
||||||
if (server) {
|
if (server) {
|
||||||
modal.find(".secret.field").attr("style", "");
|
modal.find(".secret.field").attr("style", "");
|
||||||
modal.find(".command.field").attr("style", "");
|
modal.find(".command.field").attr("style", "");
|
||||||
|
2
resource/template/common/footer.html
vendored
2
resource/template/common/footer.html
vendored
@ -10,7 +10,7 @@
|
|||||||
<script src="https://unpkg.com/semantic-ui@2.4.0/dist/semantic.min.js"></script>
|
<script src="https://unpkg.com/semantic-ui@2.4.0/dist/semantic.min.js"></script>
|
||||||
<script src="/static/semantic-ui-alerts.min.js"></script>
|
<script src="/static/semantic-ui-alerts.min.js"></script>
|
||||||
<script src="https://unpkg.com/vue@2.6.14/dist/vue.min.js"></script>
|
<script src="https://unpkg.com/vue@2.6.14/dist/vue.min.js"></script>
|
||||||
<script src="/static/main.js?v20240714"></script>
|
<script src="/static/main.js?v2024927"></script>
|
||||||
<script>
|
<script>
|
||||||
(function () {
|
(function () {
|
||||||
updateLang({{.LANG }});
|
updateLang({{.LANG }});
|
||||||
|
4
resource/template/component/server.html
vendored
4
resource/template/component/server.html
vendored
@ -56,6 +56,10 @@
|
|||||||
<label>{{tr "Note"}}</label>
|
<label>{{tr "Note"}}</label>
|
||||||
<textarea name="Note"></textarea>
|
<textarea name="Note"></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label>{{tr "PublicNote"}}</label>
|
||||||
|
<textarea name="PublicNote"></textarea>
|
||||||
|
</div>
|
||||||
<div class="command field">
|
<div class="command field">
|
||||||
<label>{{tr "LinuxOneKeyInstall"}}</label>
|
<label>{{tr "LinuxOneKeyInstall"}}</label>
|
||||||
<div class="ui message">
|
<div class="ui message">
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
<th>{{tr "Secret"}}</th>
|
<th>{{tr "Secret"}}</th>
|
||||||
<th>{{tr "OneKeyInstall"}}</th>
|
<th>{{tr "OneKeyInstall"}}</th>
|
||||||
<th>{{tr "Note"}}</th>
|
<th>{{tr "Note"}}</th>
|
||||||
|
<th>{{tr "PublicNote"}}</th>
|
||||||
<th>{{tr "Administration"}}</th>
|
<th>{{tr "Administration"}}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@ -76,12 +77,13 @@
|
|||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
<td style="word-break: break-word;white-space: pre-wrap;">{{$server.Note}}</td>
|
<td style="word-break: break-word;white-space: pre-wrap;">{{$server.Note}}</td>
|
||||||
|
<td style="word-break: break-word;white-space: pre-wrap;">{{$server.PublicNote}}</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="ui mini icon buttons">
|
<div class="ui mini icon buttons">
|
||||||
<button class="ui button" onclick="connectToServer({{$server.ID}})">
|
<button class="ui button" onclick="connectToServer({{$server.ID}})">
|
||||||
<i class="terminal icon"></i>
|
<i class="terminal icon"></i>
|
||||||
</button>
|
</button>
|
||||||
<button class="ui button" onclick="addOrEditServer({{$server.Marshal}})">
|
<button class="ui button" onclick="addOrEditServer({{$server.MarshalForDashboard}})">
|
||||||
<i class="edit icon"></i>
|
<i class="edit icon"></i>
|
||||||
</button>
|
</button>
|
||||||
<button class="ui button"
|
<button class="ui button"
|
||||||
|
Loading…
Reference in New Issue
Block a user