2019-12-08 23:18:29 +08:00
|
|
|
package model
|
|
|
|
|
2019-12-10 17:57:57 +08:00
|
|
|
import (
|
2020-12-09 10:27:00 +08:00
|
|
|
"fmt"
|
2020-12-19 22:14:36 +08:00
|
|
|
"html/template"
|
2020-10-24 21:29:05 +08:00
|
|
|
"time"
|
|
|
|
|
2022-03-18 23:13:22 +08:00
|
|
|
"github.com/naiba/nezha/pkg/utils"
|
2020-11-11 10:07:45 +08:00
|
|
|
pb "github.com/naiba/nezha/proto"
|
2019-12-10 17:57:57 +08:00
|
|
|
)
|
|
|
|
|
2019-12-08 23:18:29 +08:00
|
|
|
type Server struct {
|
|
|
|
Common
|
2021-01-08 21:04:50 +08:00
|
|
|
Name string
|
2021-01-20 19:24:59 +08:00
|
|
|
Tag string // 分组名
|
2021-01-30 17:10:51 +08:00
|
|
|
Secret string `gorm:"uniqueIndex" json:"-"`
|
2021-01-20 19:24:59 +08:00
|
|
|
Note string `json:"-"` // 管理员可见备注
|
2021-01-30 11:22:59 +08:00
|
|
|
DisplayIndex int // 展示排序,越大越靠前
|
2022-09-30 22:40:56 +08:00
|
|
|
HideForGuest bool // 对游客隐藏
|
2024-02-24 21:10:27 +08:00
|
|
|
EnableDDNS bool // 是否启用DDNS 未在配置文件中启用DDNS 或 DDNS检查时间为0时此项无效
|
2024-03-30 11:00:55 +08:00
|
|
|
EnableIPv4 bool // 是否启用DDNS IPv4
|
|
|
|
EnableIpv6 bool // 是否启用DDNS IPv6
|
2024-02-24 21:10:27 +08:00
|
|
|
DDNSDomain string // DDNS中的前缀 如基础域名为abc.oracle DDNSName为mjj 就会把mjj.abc.oracle解析服务器IP 为空则停用
|
2024-04-27 13:36:36 +08:00
|
|
|
DDNSProfile string // DDNS配置
|
2021-01-17 22:05:59 +08:00
|
|
|
|
|
|
|
Host *Host `gorm:"-"`
|
|
|
|
State *HostState `gorm:"-"`
|
2021-01-18 13:45:06 +08:00
|
|
|
LastActive time.Time `gorm:"-"`
|
2019-12-10 17:57:57 +08:00
|
|
|
|
2021-01-16 00:45:49 +08:00
|
|
|
TaskClose chan error `gorm:"-" json:"-"`
|
|
|
|
TaskStream pb.NezhaService_RequestTaskServer `gorm:"-" json:"-"`
|
2021-07-14 23:53:37 +08:00
|
|
|
|
|
|
|
PrevHourlyTransferIn int64 `gorm:"-" json:"-"` // 上次数据点时的入站使用量
|
|
|
|
PrevHourlyTransferOut int64 `gorm:"-" json:"-"` // 上次数据点时的出站使用量
|
2019-12-08 23:18:29 +08:00
|
|
|
}
|
2020-12-09 10:27:00 +08:00
|
|
|
|
2021-07-25 23:50:08 +08:00
|
|
|
func (s *Server) CopyFromRunningServer(old *Server) {
|
|
|
|
s.Host = old.Host
|
|
|
|
s.State = old.State
|
|
|
|
s.LastActive = old.LastActive
|
|
|
|
s.TaskClose = old.TaskClose
|
|
|
|
s.TaskStream = old.TaskStream
|
|
|
|
s.PrevHourlyTransferIn = old.PrevHourlyTransferIn
|
|
|
|
s.PrevHourlyTransferOut = old.PrevHourlyTransferOut
|
|
|
|
}
|
|
|
|
|
2022-09-30 22:40:56 +08:00
|
|
|
func boolToString(b bool) string {
|
|
|
|
if b {
|
|
|
|
return "true"
|
|
|
|
}
|
|
|
|
return "false"
|
|
|
|
}
|
|
|
|
|
2020-12-19 22:14:36 +08:00
|
|
|
func (s Server) Marshal() template.JS {
|
2022-03-18 23:13:22 +08:00
|
|
|
name, _ := utils.Json.Marshal(s.Name)
|
|
|
|
tag, _ := utils.Json.Marshal(s.Tag)
|
|
|
|
note, _ := utils.Json.Marshal(s.Note)
|
|
|
|
secret, _ := utils.Json.Marshal(s.Secret)
|
2024-02-24 21:10:27 +08:00
|
|
|
ddnsDomain, _ := utils.Json.Marshal(s.DDNSDomain)
|
2024-04-27 13:36:36 +08:00
|
|
|
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
|
2020-12-09 10:27:00 +08:00
|
|
|
}
|