MCPcopy Create free account
hub / github.com/tbphp/gpt-load / getSecurityWarnings

Method getSecurityWarnings

internal/handler/dashboard_handler.go:240–306  ·  view source on GitHub ↗

getSecurityWarnings 检查安全配置并返回警告信息

(c *gin.Context)

Source from the content-addressed store, hash-verified

238
239// getSecurityWarnings 检查安全配置并返回警告信息
240func (s *Server) getSecurityWarnings(c *gin.Context) []models.SecurityWarning {
241 var warnings []models.SecurityWarning
242
243 // 获取AUTH_KEY和ENCRYPTION_KEY
244 authConfig := s.config.GetAuthConfig()
245 encryptionKey := s.config.GetEncryptionKey()
246
247 // 检查AUTH_KEY
248 if authConfig.Key == "" {
249 warnings = append(warnings, models.SecurityWarning{
250 Type: "AUTH_KEY",
251 Message: i18n.Message(c, "dashboard.auth_key_missing"),
252 Severity: "high",
253 Suggestion: i18n.Message(c, "dashboard.auth_key_required"),
254 })
255 } else {
256 authWarnings := checkPasswordSecurity(c, authConfig.Key, "AUTH_KEY")
257 warnings = append(warnings, authWarnings...)
258 }
259
260 // 检查ENCRYPTION_KEY
261 if encryptionKey == "" {
262 warnings = append(warnings, models.SecurityWarning{
263 Type: "ENCRYPTION_KEY",
264 Message: i18n.Message(c, "dashboard.encryption_key_missing"),
265 Severity: "high",
266 Suggestion: i18n.Message(c, "dashboard.encryption_key_recommended"),
267 })
268 } else {
269 encryptionWarnings := checkPasswordSecurity(c, encryptionKey, "ENCRYPTION_KEY")
270 warnings = append(warnings, encryptionWarnings...)
271 }
272
273 // 检查系统级代理密钥
274 systemSettings := s.SettingsManager.GetSettings()
275 if systemSettings.ProxyKeys != "" {
276 proxyKeys := strings.Split(systemSettings.ProxyKeys, ",")
277 for i, key := range proxyKeys {
278 key = strings.TrimSpace(key)
279 if key != "" {
280 keyName := fmt.Sprintf("%s #%d", i18n.Message(c, "dashboard.global_proxy_key"), i+1)
281 proxyWarnings := checkPasswordSecurity(c, key, keyName)
282 warnings = append(warnings, proxyWarnings...)
283 }
284 }
285 }
286
287 // 检查分组级代理密钥
288 var groups []models.Group
289 if err := s.DB.Where("proxy_keys IS NOT NULL AND proxy_keys != ''").Find(&groups).Error; err == nil {
290 for _, group := range groups {
291 if group.ProxyKeys != "" {
292 proxyKeys := strings.Split(group.ProxyKeys, ",")
293 for i, key := range proxyKeys {
294 key = strings.TrimSpace(key)
295 if key != "" {
296 keyName := fmt.Sprintf("%s [%s] #%d", i18n.Message(c, "dashboard.group_proxy_key"), group.Name, i+1)
297 proxyWarnings := checkPasswordSecurity(c, key, keyName)

Callers 1

StatsMethod · 0.95

Calls 5

MessageFunction · 0.92
checkPasswordSecurityFunction · 0.85
GetAuthConfigMethod · 0.65
GetEncryptionKeyMethod · 0.65
GetSettingsMethod · 0.45

Tested by

no test coverage detected