Merge pull request #244 from samwafgo/fix_242_2

fix:ssl logic
This commit is contained in:
samwafgo
2025-04-03 08:42:50 +08:00
committed by GitHub
3 changed files with 20 additions and 4 deletions
+17 -1
View File
@@ -84,7 +84,7 @@ func (receiver *WafSslConfigService) AddApi(req request.SslConfigAddReq) error {
return nil
}
func (receiver *WafSslConfigService) AddInner(config model.SslConfig) {
func (receiver *WafSslConfigService) CreateNewIdInner(config model.SslConfig) {
//检测如果证书编号已经存在不需在进行添加了
err := global.GWAF_LOCAL_DB.First(&model.SslConfig{}, "serial_no = ?", config.SerialNo).Error
if err == nil && !errors.Is(err, gorm.ErrRecordNotFound) {
@@ -101,6 +101,22 @@ func (receiver *WafSslConfigService) AddInner(config model.SslConfig) {
global.GWAF_LOCAL_DB.Create(config)
zlog.Info(fmt.Sprintf("%s 原来证书已备份", config.Domains))
}
func (receiver *WafSslConfigService) CreateInner(config model.SslConfig) {
//检测如果证书编号已经存在不需在进行添加了
err := global.GWAF_LOCAL_DB.First(&model.SslConfig{}, "serial_no = ?", config.SerialNo).Error
if err == nil && !errors.Is(err, gorm.ErrRecordNotFound) {
zlog.Info(fmt.Sprintf("%s 证书已经存在不进行再次备份", config.Domains))
return
}
if config.CertPath == "" {
config.CertPath = filepath.Join(utils.GetCurrentDir(), "ssl", config.Id, "domain.crt")
}
if config.KeyPath == "" {
config.KeyPath = filepath.Join(utils.GetCurrentDir(), "ssl", config.Id, "domain.key")
}
global.GWAF_LOCAL_DB.Create(config)
zlog.Info(fmt.Sprintf("%s 原来证书已备份", config.Domains))
}
func (receiver *WafSslConfigService) CheckIsExistApi(serialNo string) error {
return global.GWAF_LOCAL_DB.First(&model.SslConfig{}, "serial_no = ?", serialNo).Error
+2 -2
View File
@@ -115,7 +115,7 @@ func (waf *WafEngine) processSSL(updateSSLOrder model.SslOrder, bean model.SslOr
if hostBean.BindSslId == "" || oldSslConfig.SerialNo == "" {
zlog.Info(fmt.Sprintf("%s 当前主机未配置证书新增一个证书文件夹", bean.ApplyDomain))
//添加到证书夹内
wafSslConfigService.AddInner(newSslConfig)
wafSslConfigService.CreateInner(newSslConfig)
//1.更新主机信息 2.发送主机通知
err = wafHostService.UpdateSSLInfoAndBindId(string(updateSSLOrder.ResultCertificate), string(updateSSLOrder.ResultPrivateKey), bean.HostCode, newSslConfig.Id)
if err == nil {
@@ -135,7 +135,7 @@ func (waf *WafEngine) processSSL(updateSSLOrder model.SslOrder, bean model.SslOr
//将原来的证书备份,新证书更新到现有证书里面
zlog.Info(fmt.Sprintf("%s 当前主机已绑定的证书和新证书相比后允许更新", bean.ApplyDomain))
//备份原来的配置
wafSslConfigService.AddInner(oldSslConfig)
wafSslConfigService.CreateNewIdInner(oldSslConfig)
newSslConfig.Id = oldSslConfig.Id
//把最新的配置上去
wafSslConfigService.ModifyInner(newSslConfig)
+1 -1
View File
@@ -47,7 +47,7 @@ func SSLReload() {
zlog.Error(innerLogName, "ssl config:", err.Error())
continue
}
wafSslConfigService.AddInner(backSslConfig)
wafSslConfigService.CreateNewIdInner(backSslConfig)
err = wafSslConfigService.ModifyInner(updateSslConfig)
if err != nil {
zlog.Error(innerLogName, "ssl modify inner config:", err.Error())