Skip to content

Commit

Permalink
feat: set renewal interval of certificates #343
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJacky committed Apr 30, 2024
1 parent 4c7e037 commit e77d37b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 25 deletions.
8 changes: 8 additions & 0 deletions app/src/views/preference/BasicSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ const errors: Record<string, Record<string, string>> = inject('errors') as Recor
>
<AInput v-model:value="data.server.ca_dir" />
</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>
</template>

Expand Down
1 change: 1 addition & 0 deletions app/src/views/preference/Preference.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const data = ref<Settings>({
github_proxy: '',
ca_dir: '',
node_secret: '',
cert_renewal_interval: 7,
},
nginx: {
access_log_path: '',
Expand Down
1 change: 1 addition & 0 deletions app/src/views/preference/typedef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface Settings {
github_proxy: string
email: string
ca_dir: string
cert_renewal_interval: number
}
nginx: {
access_log_path: string
Expand Down
5 changes: 3 additions & 2 deletions internal/cert/auto_cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/0xJacky/Nginx-UI/internal/logger"
"github.com/0xJacky/Nginx-UI/internal/notification"
"github.com/0xJacky/Nginx-UI/model"
"github.com/0xJacky/Nginx-UI/settings"
"github.com/pkg/errors"
"runtime"
"strings"
Expand Down Expand Up @@ -59,8 +60,8 @@ func renew(certModel *model.Cert) {
notification.Error("Renew Certificate Error", strings.Join(certModel.Domains, ", "))
return
}
if time.Now().Sub(cert.NotBefore).Hours()/24 < 7 {
// not between 1 week, ignore this certificate
if int(time.Now().Sub(cert.NotBefore).Hours()/24) < settings.ServerSettings.CertRenewalInterval {
// not after settings.ServerSettings.CertRenewalInterval, ignore
return
}

Expand Down
48 changes: 25 additions & 23 deletions settings/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@ import (
)

type Server struct {
HttpHost string `json:"http_host" protected:"true"`
HttpPort string `json:"http_port" protected:"true"`
RunMode string `json:"run_mode" protected:"true"`
JwtSecret string `json:"jwt_secret" protected:"true"`
NodeSecret string `json:"node_secret" protected:"true"`
HTTPChallengePort string `json:"http_challenge_port"`
Email string `json:"email" protected:"true"`
Database string `json:"database" protected:"true"`
StartCmd string `json:"start_cmd" protected:"true"`
CADir string `json:"ca_dir" binding:"omitempty,url"`
Demo bool `json:"demo" protected:"true"`
PageSize int `json:"page_size" protected:"true"`
GithubProxy string `json:"github_proxy" binding:"omitempty,url"`
HttpHost string `json:"http_host" protected:"true"`
HttpPort string `json:"http_port" protected:"true"`
RunMode string `json:"run_mode" protected:"true"`
JwtSecret string `json:"jwt_secret" protected:"true"`
NodeSecret string `json:"node_secret" protected:"true"`
HTTPChallengePort string `json:"http_challenge_port"`
Email string `json:"email" protected:"true"`
Database string `json:"database" protected:"true"`
StartCmd string `json:"start_cmd" protected:"true"`
CADir string `json:"ca_dir" binding:"omitempty,url"`
Demo bool `json:"demo" protected:"true"`
PageSize int `json:"page_size" protected:"true"`
GithubProxy string `json:"github_proxy" binding:"omitempty,url"`
CertRenewalInterval int `json:"cert_renewal_interval" binging:"min=7,max=21"`
}

func (s *Server) GetCADir() string {
Expand All @@ -33,14 +34,15 @@ func (s *Server) GetCADir() string {
}

var ServerSettings = Server{
HttpHost: "0.0.0.0",
HttpPort: "9000",
RunMode: "debug",
HTTPChallengePort: "9180",
Database: "database",
StartCmd: "login",
Demo: false,
PageSize: 10,
CADir: "",
GithubProxy: "",
HttpHost: "0.0.0.0",
HttpPort: "9000",
RunMode: "debug",
HTTPChallengePort: "9180",
Database: "database",
StartCmd: "login",
Demo: false,
PageSize: 10,
CADir: "",
GithubProxy: "",
CertRenewalInterval: 7,
}

0 comments on commit e77d37b

Please sign in to comment.