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