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/global"
|
2023-05-08 13:01:39 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/utils/common"
|
2023-01-04 11:44:43 +08:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ssl struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewSSLJob() *ssl {
|
|
|
|
return &ssl{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ssl *ssl) Run() {
|
|
|
|
sslRepo := repo.NewISSLRepo()
|
|
|
|
sslService := service.NewIWebsiteSSLService()
|
|
|
|
sslList, _ := sslRepo.List()
|
2023-05-08 13:01:39 +08:00
|
|
|
nyc, _ := time.LoadLocation(common.LoadTimeZone())
|
2023-04-13 08:24:32 +08:00
|
|
|
global.LOG.Info("The scheduled certificate update task is currently in progress ...")
|
2023-03-21 13:10:27 +08:00
|
|
|
now := time.Now().Add(10 * time.Second)
|
2023-01-04 11:44:43 +08:00
|
|
|
for _, s := range sslList {
|
2023-11-20 16:16:20 +08:00
|
|
|
if !s.AutoRenew || s.Provider == "manual" || s.Provider == "dnsManual" || s.Status == "applying" {
|
2023-01-04 11:44:43 +08:00
|
|
|
continue
|
|
|
|
}
|
2023-05-08 13:01:39 +08:00
|
|
|
expireDate := s.ExpireDate.In(nyc)
|
2023-04-13 08:24:32 +08:00
|
|
|
sub := expireDate.Sub(now)
|
|
|
|
if sub.Hours() < 720 {
|
|
|
|
global.LOG.Errorf("Update the SSL certificate for the [%s] domain", s.PrimaryDomain)
|
2023-01-04 11:44:43 +08:00
|
|
|
if err := sslService.Renew(s.ID); err != nil {
|
2023-04-13 08:24:32 +08:00
|
|
|
global.LOG.Errorf("Failed to update the SSL certificate for the [%s] domain , err:%s", s.PrimaryDomain, err.Error())
|
|
|
|
continue
|
2023-01-04 11:44:43 +08:00
|
|
|
}
|
2023-04-13 08:24:32 +08:00
|
|
|
global.LOG.Errorf("The SSL certificate for the [%s] domain has been successfully updated", s.PrimaryDomain)
|
2023-01-04 11:44:43 +08:00
|
|
|
}
|
|
|
|
}
|
2023-04-13 08:24:32 +08:00
|
|
|
global.LOG.Info("The scheduled certificate update task has completed")
|
2023-01-04 11:44:43 +08:00
|
|
|
}
|