From 421f752ff6e46beac2712f2819ae310cc08ab132 Mon Sep 17 00:00:00 2001 From: samwaf Date: Thu, 2 Jan 2025 09:22:12 +0800 Subject: [PATCH] fix:ssl task folder --- main.go | 1 - model/sslconfig.go | 5 +++++ service/waf_service/waf_sslconfig.go | 13 ++++++------- waftask/task_ssl.go | 7 ++++--- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/main.go b/main.go index 0f644e8..cf593ba 100644 --- a/main.go +++ b/main.go @@ -353,7 +353,6 @@ func (m *wafSystenService) run() { go waftask.TaskHistoryDownload() }) - //每天早晨3点进行执行ssl证书的处理 globalobj.GWAF_RUNTIME_OBJ_WAF_CRON.Every(1).Day().At("03:00").Do(func() { go waftask.SSLReload() diff --git a/model/sslconfig.go b/model/sslconfig.go index 92d110e..190fff9 100644 --- a/model/sslconfig.go +++ b/model/sslconfig.go @@ -100,6 +100,11 @@ func (s *SslConfig) CheckKeyAndCertFileLoad() (error, SslConfig, SslConfig) { if daysLeft <= 0 { return errors.New("路径下的文件已经过期,不加载"), SslConfig{}, SslConfig{} } + //现有证书大于路径下的也不进行更新 + if s.ValidTo.After(validTo) { + return errors.New("现有证书到期时间大于路径下的到期时间也不进行更新"), SslConfig{}, SslConfig{} + } + updateSslConfig := *s backSslConfig := *s diff --git a/service/waf_service/waf_sslconfig.go b/service/waf_service/waf_sslconfig.go index a9fa99d..0893acd 100644 --- a/service/waf_service/waf_sslconfig.go +++ b/service/waf_service/waf_sslconfig.go @@ -245,14 +245,13 @@ func (receiver *WafSslConfigService) GetListApi(req request.SslConfigSearchReq) return repList, total, nil } -func (receiver *WafSslConfigService) GetAllListInner() ([]response.WafSslConfigRep, int64, error) { +func (receiver *WafSslConfigService) GetAllListInner() ([]response.WafSslConfigRep, error) { var list []model.SslConfig - var total int64 = 0 - var whereField = "" - var whereValues []interface{} - global.GWAF_LOCAL_DB.Model(&model.SslConfig{}).Where(whereField, whereValues...).Order("valid_to desc").Find(&list) - global.GWAF_LOCAL_DB.Model(&model.SslConfig{}).Where(whereField, whereValues...).Count(&total) + var bindSslIDs []string + global.GWAF_LOCAL_DB.Model(&model.Hosts{}).Select("bind_ssl_id").Where("ssl =? and bind_ssl_id <> ?", 1, "").Find(&bindSslIDs) + + global.GWAF_LOCAL_DB.Model(&model.SslConfig{}).Where("id IN ?", bindSslIDs).Order("valid_to desc").Find(&list) // 初始化返回结果列表 var repList []response.WafSslConfigRep @@ -272,7 +271,7 @@ func (receiver *WafSslConfigService) GetAllListInner() ([]response.WafSslConfigR repList = append(repList, rep) } - return repList, total, nil + return repList, nil } func (receiver *WafSslConfigService) DelApi(req request.SslConfigDeleteReq) error { diff --git a/waftask/task_ssl.go b/waftask/task_ssl.go index eb4cc27..3a56d87 100644 --- a/waftask/task_ssl.go +++ b/waftask/task_ssl.go @@ -20,19 +20,20 @@ SSL路径自动加载—_证书自动续期 */ func SSLReload() { innerLogName := "TaskSSL" - zlog.Info(innerLogName, "准备进行ssl证书自动加载") + zlog.Info(innerLogName, "准备进行ssl证书文件路径自动加载") if global.GCONFIG_RECORD_AUTO_LOAD_SSL == 1 { zlog.Info(innerLogName, "自动加载ssl开关:开启") //1.遍历所有证书夹得内容 //2.如果对应得位置有内容 //3.就开始判断数据是否是正常的,如果正常则备份现有,然后现有的证书替换掉 //4.重新查询让关联的主机信息重新加载 - sslConfigReps, sslConfigSize, err := wafSslConfigService.GetAllListInner() + sslConfigReps, err := wafSslConfigService.GetAllListInner() if err != nil { zlog.Error(innerLogName, "ssl config:", err) return } - if sslConfigSize <= 0 { + + if len(sslConfigReps) <= 0 { zlog.Info(innerLogName, "没有ssl证书") return }