新增功能: - 支持 Google Authenticator 等应用进行 TOTP 二次验证 - 用户可在个人设置中启用/禁用 2FA - 登录时支持 TOTP 验证流程 - 管理后台可全局开关 TOTP 功能 安全增强: - TOTP 密钥使用 AES-256-GCM 加密存储 - 添加 TOTP_ENCRYPTION_KEY 配置项,必须手动配置才能启用功能 - 防止服务重启导致加密密钥变更使用户无法登录 - 验证失败次数限制,防止暴力破解 配置说明: - Docker 部署:在 .env 中设置 TOTP_ENCRYPTION_KEY - 非 Docker 部署:在 config.yaml 中设置 totp.encryption_key - 生成密钥命令:openssl rand -hex 32
112 lines
3.6 KiB
Go
112 lines
3.6 KiB
Go
package service
|
|
|
|
type SystemSettings struct {
|
|
RegistrationEnabled bool
|
|
EmailVerifyEnabled bool
|
|
PromoCodeEnabled bool
|
|
PasswordResetEnabled bool
|
|
TotpEnabled bool // TOTP 双因素认证
|
|
|
|
SMTPHost string
|
|
SMTPPort int
|
|
SMTPUsername string
|
|
SMTPPassword string
|
|
SMTPPasswordConfigured bool
|
|
SMTPFrom string
|
|
SMTPFromName string
|
|
SMTPUseTLS bool
|
|
|
|
TurnstileEnabled bool
|
|
TurnstileSiteKey string
|
|
TurnstileSecretKey string
|
|
TurnstileSecretKeyConfigured bool
|
|
|
|
// LinuxDo Connect OAuth 登录
|
|
LinuxDoConnectEnabled bool
|
|
LinuxDoConnectClientID string
|
|
LinuxDoConnectClientSecret string
|
|
LinuxDoConnectClientSecretConfigured bool
|
|
LinuxDoConnectRedirectURL string
|
|
|
|
SiteName string
|
|
SiteLogo string
|
|
SiteSubtitle string
|
|
APIBaseURL string
|
|
ContactInfo string
|
|
DocURL string
|
|
HomeContent string
|
|
HideCcsImportButton bool
|
|
|
|
DefaultConcurrency int
|
|
DefaultBalance float64
|
|
|
|
// Model fallback configuration
|
|
EnableModelFallback bool `json:"enable_model_fallback"`
|
|
FallbackModelAnthropic string `json:"fallback_model_anthropic"`
|
|
FallbackModelOpenAI string `json:"fallback_model_openai"`
|
|
FallbackModelGemini string `json:"fallback_model_gemini"`
|
|
FallbackModelAntigravity string `json:"fallback_model_antigravity"`
|
|
|
|
// Identity patch configuration (Claude -> Gemini)
|
|
EnableIdentityPatch bool `json:"enable_identity_patch"`
|
|
IdentityPatchPrompt string `json:"identity_patch_prompt"`
|
|
|
|
// Ops monitoring (vNext)
|
|
OpsMonitoringEnabled bool
|
|
OpsRealtimeMonitoringEnabled bool
|
|
OpsQueryModeDefault string
|
|
OpsMetricsIntervalSeconds int
|
|
}
|
|
|
|
type PublicSettings struct {
|
|
RegistrationEnabled bool
|
|
EmailVerifyEnabled bool
|
|
PromoCodeEnabled bool
|
|
PasswordResetEnabled bool
|
|
TotpEnabled bool // TOTP 双因素认证
|
|
TurnstileEnabled bool
|
|
TurnstileSiteKey string
|
|
SiteName string
|
|
SiteLogo string
|
|
SiteSubtitle string
|
|
APIBaseURL string
|
|
ContactInfo string
|
|
DocURL string
|
|
HomeContent string
|
|
HideCcsImportButton bool
|
|
LinuxDoOAuthEnabled bool
|
|
Version string
|
|
}
|
|
|
|
// StreamTimeoutSettings 流超时处理配置(仅控制超时后的处理方式,超时判定由网关配置控制)
|
|
type StreamTimeoutSettings struct {
|
|
// Enabled 是否启用流超时处理
|
|
Enabled bool `json:"enabled"`
|
|
// Action 超时后的处理方式: "temp_unsched" | "error" | "none"
|
|
Action string `json:"action"`
|
|
// TempUnschedMinutes 临时不可调度持续时间(分钟)
|
|
TempUnschedMinutes int `json:"temp_unsched_minutes"`
|
|
// ThresholdCount 触发阈值次数(累计多少次超时才触发)
|
|
ThresholdCount int `json:"threshold_count"`
|
|
// ThresholdWindowMinutes 阈值窗口时间(分钟)
|
|
ThresholdWindowMinutes int `json:"threshold_window_minutes"`
|
|
}
|
|
|
|
// StreamTimeoutAction 流超时处理方式常量
|
|
const (
|
|
StreamTimeoutActionTempUnsched = "temp_unsched" // 临时不可调度
|
|
StreamTimeoutActionError = "error" // 标记为错误状态
|
|
StreamTimeoutActionNone = "none" // 不处理
|
|
)
|
|
|
|
// DefaultStreamTimeoutSettings 返回默认的流超时配置
|
|
func DefaultStreamTimeoutSettings() *StreamTimeoutSettings {
|
|
return &StreamTimeoutSettings{
|
|
Enabled: false,
|
|
Action: StreamTimeoutActionTempUnsched,
|
|
TempUnschedMinutes: 5,
|
|
ThresholdCount: 3,
|
|
ThresholdWindowMinutes: 10,
|
|
}
|
|
}
|