mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 11:27:17 +08:00
feat: 新增证书到期时间显示,close #836
This commit is contained in:
@@ -19,6 +19,8 @@ type Website struct {
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
CertExpire string `gorm:"-:all" json:"cert_expire"` // 仅显示
|
||||
|
||||
Cert *Cert `gorm:"foreignKey:WebsiteID" json:"cert"`
|
||||
}
|
||||
|
||||
|
||||
@@ -223,6 +223,15 @@ func (r *websiteRepo) List(page, limit uint) ([]*biz.Website, int64, error) {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// 取证书剩余有效时间
|
||||
for _, website := range websites {
|
||||
crt, _ := io.Read(filepath.Join(app.Root, "server/vhost/cert", website.Name+".pem"))
|
||||
if decode, err := cert.ParseCert(crt); err == nil {
|
||||
hours := decode.NotAfter.Sub(time.Now()).Hours()
|
||||
website.CertExpire = fmt.Sprintf("%.2f", hours/24)
|
||||
}
|
||||
}
|
||||
|
||||
return websites, total, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +73,38 @@ const columns: any = [
|
||||
})
|
||||
}
|
||||
},
|
||||
{
|
||||
title: $gettext('Certificate expiration'),
|
||||
key: 'cert_expire',
|
||||
width: 200,
|
||||
render(row: any) {
|
||||
return h(
|
||||
NTag,
|
||||
{
|
||||
type: row.cert_expire == 0 ? 'default' : row.cert_expire > 0 ? 'success' : 'error',
|
||||
class: 'cursor-pointer hover:opacity-60',
|
||||
onClick: () => handleEdit(row)
|
||||
},
|
||||
{
|
||||
default: () => {
|
||||
if (row.cert_expire == 0) {
|
||||
return $gettext('Not configured')
|
||||
}
|
||||
if (row.cert_expire < 0) {
|
||||
return $gettext('Expired %{ days } days ago', {
|
||||
days: Math.abs(row.cert_expire)
|
||||
})
|
||||
}
|
||||
if (row.cert_expire > 0) {
|
||||
return $gettext('Expires in %{ days } days', {
|
||||
days: row.cert_expire
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
},
|
||||
{
|
||||
title: $gettext('Remark'),
|
||||
key: 'remark',
|
||||
@@ -378,7 +410,7 @@ onMounted(() => {
|
||||
striped
|
||||
remote
|
||||
:loading="loading"
|
||||
:scroll-x="1200"
|
||||
:scroll-x="1400"
|
||||
:columns="columns"
|
||||
:data="data"
|
||||
:row-key="(row: any) => row.id"
|
||||
|
||||
Reference in New Issue
Block a user