fix:ssl task folder

This commit is contained in:
samwaf
2025-01-02 09:22:12 +08:00
parent 9d220df01a
commit 421f752ff6
4 changed files with 15 additions and 11 deletions
-1
View File
@@ -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()
+5
View File
@@ -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
+6 -7
View File
@@ -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 {
+4 -3
View File
@@ -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
}