refactor agent auth & server api

This commit is contained in:
naiba
2024-10-20 23:23:04 +08:00
parent d3f907b5c3
commit aa20c97312
19 changed files with 488 additions and 330 deletions

View File

@@ -80,13 +80,14 @@ func (c *AgentConfig) Save() error {
type Config struct {
Debug bool // debug模式开关
Language string // 系统语言,默认 zh-CN
SiteName string
SecretKey string
ListenPort uint
InstallHost string
TLS bool
Location string // 时区,默认为 Asia/Shanghai
Language string // 系统语言,默认 zh-CN
SiteName string
JWTSecretKey string
AgentSecretKey string
ListenPort uint
InstallHost string
TLS bool
Location string // 时区,默认为 Asia/Shanghai
EnablePlainIPInNotification bool // 通知信息IP不打码
@@ -132,8 +133,18 @@ func (c *Config) Read(path string) error {
if c.AvgPingCount == 0 {
c.AvgPingCount = 2
}
if c.SecretKey == "" {
c.SecretKey, err = utils.GenerateRandomString(1024)
if c.JWTSecretKey == "" {
c.JWTSecretKey, err = utils.GenerateRandomString(1024)
if err != nil {
return err
}
if err = c.Save(); err != nil {
return err
}
}
if c.AgentSecretKey == "" {
c.AgentSecretKey, err = utils.GenerateRandomString(32)
if err != nil {
return err
}