1Panel/backend/cron/job/ssl.go

38 lines
1000 B
Go
Raw Normal View History

2023-01-04 11:44:43 +08:00
package job
import (
"github.com/1Panel-dev/1Panel/backend/app/repo"
"github.com/1Panel-dev/1Panel/backend/app/service"
"github.com/1Panel-dev/1Panel/backend/constant"
2023-01-04 11:44:43 +08:00
"github.com/1Panel-dev/1Panel/backend/global"
"time"
)
type ssl struct {
}
func NewSSLJob() *ssl {
return &ssl{}
}
func (ssl *ssl) Run() {
sslRepo := repo.NewISSLRepo()
sslService := service.NewIWebsiteSSLService()
sslList, _ := sslRepo.List()
global.LOG.Info("ssl renew cron job start...")
now := time.Now().Add(10 * time.Second)
2023-01-04 11:44:43 +08:00
for _, s := range sslList {
if !s.AutoRenew || s.Provider == "manual" || s.Provider == "dnsManual" {
continue
}
expireDate, _ := time.ParseInLocation(constant.DateTimeLayout, s.ExpireDate.String(), time.Now().Location())
sum := expireDate.Sub(now)
if sum.Hours() < 720 {
2023-01-04 11:44:43 +08:00
if err := sslService.Renew(s.ID); err != nil {
global.LOG.Errorf("renew doamin [%s] ssl failed err:%s", s.PrimaryDomain, err.Error())
}
}
}
global.LOG.Info("ssl renew cron job end...")
}