Files
Binbim b8788c239e
MCP Docker / build-and-push (push) Has been cancelled
feat: SafeLine CE 9.3.9 with pro features
- Remove telemetry: disabled all phone-home (installation notify, false positives, behavior tracking, upgrade tips)
- Version branding: removed 'ce-' prefix, product name changed to '长亭雷池 WAF'
- Detection engine enhancement: strict preset enables all 17 modules with aggressive configs
- Multi-user RBAC: admin/operator/viewer roles with password + TOTP 2FA
- Rate limiting: nginx limit_req per website (RPS, burst, action)
- JS Challenge: browser fingerprint verification page with cookie-based bypass
- Security fixes: removed InsecureSkipVerify, hardcoded credentials, NO_AUTH backdoor
2026-07-04 07:59:04 +08:00

64 lines
1.2 KiB
Go

package database
import (
"gorm.io/driver/postgres"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"gorm.io/gorm/schema"
"chaitin.cn/dev/go/errors"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/config"
)
type PostgresDB struct {
*gorm.DB
}
var (
// db is not designed to be used directly, use method `GetDB` instead.
db PostgresDB
)
func GetDB() *PostgresDB {
return &db
}
func InitDB() error {
dbConfig := config.GlobalConfig.DB
if dbConfig.URL == "" {
return errors.New("empty database url")
}
// URL also works, see https://godoc.org/github.com/lib/pq
var (
gormDB *gorm.DB
err error
)
gormConfig := &gorm.Config{
NamingStrategy: schema.NamingStrategy{
TablePrefix: "mgt_", // table name prefix, table for `User` would be `t_users`
SingularTable: true, // use singular table name, table for `User` would be `user` with this option enabled
},
AllowGlobalUpdate: false,
Logger: logger.Default.LogMode(logger.Silent),
}
if dbConfig.LogSQL {
gormConfig.Logger = logger.Default.LogMode(logger.Info)
}
gormDB, err = gorm.Open(postgres.Open(dbConfig.URL), gormConfig)
if err != nil {
return err
}
db.DB = gormDB
return nil
}
func (db *PostgresDB) SetDB(gormDB *gorm.DB) {
db.DB = gormDB
}