refactor: remove pages, combine grpc http port

This commit is contained in:
naiba
2024-10-20 11:47:45 +08:00
parent 4fc0aad7a0
commit 606e10ca0a
20 changed files with 368 additions and 761 deletions

View File

@@ -5,6 +5,7 @@ import (
"strconv"
"strings"
"github.com/naiba/nezha/pkg/utils"
"github.com/spf13/viper"
"sigs.k8s.io/yaml"
)
@@ -77,40 +78,17 @@ func (c *AgentConfig) Save() error {
// Config 站点配置
type Config struct {
Debug bool // debug模式开关
Language string // 系统语言,默认 zh-CN
Site struct {
Brand string // 站点名称
CookieName string // 浏览器 Cookie 名称
Theme string
DashboardTheme string
CustomCode string
CustomCodeDashboard string
ViewPassword string // 前台查看密码
}
Oauth2 struct {
Type string
Admin string // 管理员用户名列表
AdminGroups string // 管理员用户组列表
ClientID string
ClientSecret string
Endpoint string
OidcDisplayName string // for OIDC Display Name
OidcIssuer string // for OIDC Issuer
OidcLogoutURL string // for OIDC Logout URL
OidcRegisterURL string // for OIDC Register URL
OidcLoginClaim string // for OIDC Claim
OidcGroupClaim string // for OIDC Group Claim
OidcScopes string // for OIDC Scopes
OidcAutoCreate bool // for OIDC Auto Create
OidcAutoLogin bool // for OIDC Auto Login
}
Debug bool // debug模式开关
Language string // 系统语言,默认 zh-CN
SiteName string
SecretKey string
ListenPort uint
InstallHost string
TLS bool
Location string // 时区,默认为 Asia/Shanghai
EnablePlainIPInNotification bool // 通知信息IP不打码
DisableSwitchTemplateInFrontend bool // 前台禁用切换模板功能
EnablePlainIPInNotification bool // 通知信息IP不打码
// IP变更提醒
EnableIPChangeNotification bool
@@ -118,14 +96,11 @@ type Config struct {
Cover uint8 // 覆盖范围0:提醒未被 IgnoredIPNotification 包含的所有服务器; 1:仅提醒被 IgnoredIPNotification 包含的服务器;
IgnoredIPNotification string // 特定服务器IP多个服务器用逗号分隔
Location string // 时区,默认为 Asia/Shanghai
v *viper.Viper
IgnoredIPNotificationServerIDs map[uint64]bool // [ServerID] -> bool(值为true代表当前ServerID在特定服务器列表内
MaxTCPPingValue int32
AvgPingCount int
DNSServers string
DNSServers string
v *viper.Viper
}
// Read 读取配置文件并应用
@@ -142,12 +117,6 @@ func (c *Config) Read(path string) error {
return err
}
if c.Site.Theme == "" {
c.Site.Theme = "default"
}
if c.Site.DashboardTheme == "" {
c.Site.DashboardTheme = "default"
}
if c.Language == "" {
c.Language = "zh-CN"
}
@@ -157,23 +126,17 @@ func (c *Config) Read(path string) error {
if c.Location == "" {
c.Location = "Asia/Shanghai"
}
if c.MaxTCPPingValue == 0 {
c.MaxTCPPingValue = 1000
}
if c.AvgPingCount == 0 {
c.AvgPingCount = 2
}
if c.Oauth2.OidcScopes == "" {
c.Oauth2.OidcScopes = "openid,profile,email"
}
if c.Oauth2.OidcLoginClaim == "" {
c.Oauth2.OidcLoginClaim = "sub"
}
if c.Oauth2.OidcDisplayName == "" {
c.Oauth2.OidcDisplayName = "OIDC"
}
if c.Oauth2.OidcGroupClaim == "" {
c.Oauth2.OidcGroupClaim = "groups"
if c.SecretKey == "" {
c.SecretKey, err = utils.GenerateRandomString(1024)
if err != nil {
return err
}
if err = c.Save(); err != nil {
return err
}
}
c.updateIgnoredIPNotificationID()