feat: set renewal interval of certificates #343

This commit is contained in:
Jacky 2024-04-30 10:26:02 +08:00
parent 4c7e037b76
commit e77d37bbaa
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
5 changed files with 38 additions and 25 deletions

View file

@ -50,6 +50,14 @@ const errors: Record<string, Record<string, string>> = inject('errors') as Recor
> >
<AInput v-model:value="data.server.ca_dir" /> <AInput v-model:value="data.server.ca_dir" />
</AFormItem> </AFormItem>
<AFormItem :label="$gettext('Certificate Renewal Interval')">
<AInputNumber
v-model:value="data.server.cert_renewal_interval"
:min="7"
:max="21"
:addon-after="$gettext('Days')"
/>
</AFormItem>
</AForm> </AForm>
</template> </template>

View file

@ -21,6 +21,7 @@ const data = ref<Settings>({
github_proxy: '', github_proxy: '',
ca_dir: '', ca_dir: '',
node_secret: '', node_secret: '',
cert_renewal_interval: 7,
}, },
nginx: { nginx: {
access_log_path: '', access_log_path: '',

View file

@ -10,6 +10,7 @@ export interface Settings {
github_proxy: string github_proxy: string
email: string email: string
ca_dir: string ca_dir: string
cert_renewal_interval: number
} }
nginx: { nginx: {
access_log_path: string access_log_path: string

View file

@ -4,6 +4,7 @@ import (
"github.com/0xJacky/Nginx-UI/internal/logger" "github.com/0xJacky/Nginx-UI/internal/logger"
"github.com/0xJacky/Nginx-UI/internal/notification" "github.com/0xJacky/Nginx-UI/internal/notification"
"github.com/0xJacky/Nginx-UI/model" "github.com/0xJacky/Nginx-UI/model"
"github.com/0xJacky/Nginx-UI/settings"
"github.com/pkg/errors" "github.com/pkg/errors"
"runtime" "runtime"
"strings" "strings"
@ -59,8 +60,8 @@ func renew(certModel *model.Cert) {
notification.Error("Renew Certificate Error", strings.Join(certModel.Domains, ", ")) notification.Error("Renew Certificate Error", strings.Join(certModel.Domains, ", "))
return return
} }
if time.Now().Sub(cert.NotBefore).Hours()/24 < 7 { if int(time.Now().Sub(cert.NotBefore).Hours()/24) < settings.ServerSettings.CertRenewalInterval {
// not between 1 week, ignore this certificate // not after settings.ServerSettings.CertRenewalInterval, ignore
return return
} }

View file

@ -18,6 +18,7 @@ type Server struct {
Demo bool `json:"demo" protected:"true"` Demo bool `json:"demo" protected:"true"`
PageSize int `json:"page_size" protected:"true"` PageSize int `json:"page_size" protected:"true"`
GithubProxy string `json:"github_proxy" binding:"omitempty,url"` GithubProxy string `json:"github_proxy" binding:"omitempty,url"`
CertRenewalInterval int `json:"cert_renewal_interval" binging:"min=7,max=21"`
} }
func (s *Server) GetCADir() string { func (s *Server) GetCADir() string {
@ -43,4 +44,5 @@ var ServerSettings = Server{
PageSize: 10, PageSize: 10,
CADir: "", CADir: "",
GithubProxy: "", GithubProxy: "",
CertRenewalInterval: 7,
} }