1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-31 14:08:06 +08:00

feat: 网站列表增加证书过期时间显示 (#5488)

Refs https://github.com/1Panel-dev/1Panel/issues/4271
This commit is contained in:
zhengkunwang 2024-06-18 18:06:54 +08:00 committed by GitHub
parent c30ea553bd
commit e32104581b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 75 additions and 9 deletions

View File

@ -2,6 +2,7 @@ package response
import ( import (
"github.com/1Panel-dev/1Panel/backend/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"time"
) )
type WebsiteDTO struct { type WebsiteDTO struct {
@ -11,6 +12,24 @@ type WebsiteDTO struct {
SitePath string `json:"sitePath"` SitePath string `json:"sitePath"`
AppName string `json:"appName"` AppName string `json:"appName"`
RuntimeName string `json:"runtimeName"` RuntimeName string `json:"runtimeName"`
SiteDir string `gorm:"type:varchar;" json:"siteDir"`
}
type WebsiteRes struct {
ID uint `json:"id"`
CreatedAt time.Time `json:"createdAt"`
Protocol string `json:"protocol"`
PrimaryDomain string `json:"primaryDomain"`
Type string `json:"type"`
Alias string `json:"alias"`
Remark string `json:"remark"`
Status string `json:"status"`
ExpireDate time.Time `json:"expireDate"`
SitePath string `json:"sitePath"`
AppName string `json:"appName"`
RuntimeName string `json:"runtimeName"`
SSLExpireDate time.Time `json:"sslExpireDate"`
SSLStatus string `json:"sslStatus"`
} }
type WebsiteOption struct { type WebsiteOption struct {

View File

@ -53,7 +53,7 @@ type WebsiteService struct {
} }
type IWebsiteService interface { type IWebsiteService interface {
PageWebsite(req request.WebsiteSearch) (int64, []response.WebsiteDTO, error) PageWebsite(req request.WebsiteSearch) (int64, []response.WebsiteRes, error)
GetWebsites() ([]response.WebsiteDTO, error) GetWebsites() ([]response.WebsiteDTO, error)
CreateWebsite(create request.WebsiteCreate) error CreateWebsite(create request.WebsiteCreate) error
OpWebsite(req request.WebsiteOp) error OpWebsite(req request.WebsiteOp) error
@ -102,9 +102,9 @@ func NewIWebsiteService() IWebsiteService {
return &WebsiteService{} return &WebsiteService{}
} }
func (w WebsiteService) PageWebsite(req request.WebsiteSearch) (int64, []response.WebsiteDTO, error) { func (w WebsiteService) PageWebsite(req request.WebsiteSearch) (int64, []response.WebsiteRes, error) {
var ( var (
websiteDTOs []response.WebsiteDTO websiteDTOs []response.WebsiteRes
opts []repo.DBOption opts []repo.DBOption
) )
nginxInstall, err := getAppInstallByKey(constant.AppOpenresty) nginxInstall, err := getAppInstallByKey(constant.AppOpenresty)
@ -154,11 +154,22 @@ func (w WebsiteService) PageWebsite(req request.WebsiteSearch) (int64, []respons
runtimeName = runtime.Name runtimeName = runtime.Name
} }
sitePath := path.Join(constant.AppInstallDir, constant.AppOpenresty, nginxInstall.Name, "www", "sites", web.Alias) sitePath := path.Join(constant.AppInstallDir, constant.AppOpenresty, nginxInstall.Name, "www", "sites", web.Alias)
websiteDTOs = append(websiteDTOs, response.WebsiteDTO{
Website: web, websiteDTOs = append(websiteDTOs, response.WebsiteRes{
AppName: appName, ID: web.ID,
RuntimeName: runtimeName, CreatedAt: web.CreatedAt,
SitePath: sitePath, Protocol: web.Protocol,
PrimaryDomain: web.PrimaryDomain,
Type: web.Type,
Remark: web.Remark,
Status: web.Status,
Alias: web.Alias,
AppName: appName,
ExpireDate: web.ExpireDate,
SSLExpireDate: web.WebsiteSSL.ExpireDate,
SSLStatus: checkSSLStatus(web.WebsiteSSL.ExpireDate),
RuntimeName: runtimeName,
SitePath: sitePath,
}) })
} }
return total, websiteDTOs, nil return total, websiteDTOs, nil

View File

@ -1080,3 +1080,15 @@ func ChangeHSTSConfig(enable bool, nginxInstall model.AppInstall, website model.
} }
return nil return nil
} }
func checkSSLStatus(expireDate time.Time) string {
now := time.Now()
daysUntilExpiry := int(expireDate.Sub(now).Hours() / 24)
if daysUntilExpiry < 0 {
return "danger"
} else if daysUntilExpiry <= 10 {
return "warning"
}
return "success"
}

View File

@ -32,6 +32,19 @@ export namespace Website {
appName: string; appName: string;
runtimeName: string; runtimeName: string;
} }
export interface WebsiteRes extends CommonModel {
protocol: string;
primaryDomain: string;
type: string;
alias: string;
remark: string;
status: string;
expireDate: string;
sitePath: string;
appName: string;
runtimeName: string;
sslExpireDate: Date;
}
export interface NewAppInstall { export interface NewAppInstall {
name: string; name: string;

View File

@ -7,7 +7,7 @@ import { deepCopy } from '@/utils/util';
import { Base64 } from 'js-base64'; import { Base64 } from 'js-base64';
export const SearchWebsites = (req: Website.WebSiteSearch) => { export const SearchWebsites = (req: Website.WebSiteSearch) => {
return http.post<ResPage<Website.WebsiteDTO>>(`/websites/search`, req); return http.post<ResPage<Website.WebsiteRes>>(`/websites/search`, req);
}; };
export const ListWebsites = () => { export const ListWebsites = () => {

View File

@ -2028,6 +2028,7 @@ const message = {
'Only supports importing local backups, importing backups from other machines may cause recovery failure', 'Only supports importing local backups, importing backups from other machines may cause recovery failure',
ipWebsiteWarn: 'Websites with IP as domain names need to be set as default sites to be accessed normally', ipWebsiteWarn: 'Websites with IP as domain names need to be set as default sites to be accessed normally',
hstsHelper: 'Enabling HSTS can increase website security', hstsHelper: 'Enabling HSTS can increase website security',
sslExpireDate: 'Certificate expiration date',
}, },
php: { php: {
short_open_tag: 'Short tag support', short_open_tag: 'Short tag support',

View File

@ -1888,6 +1888,7 @@ const message = {
websiteBackupWarn: '僅支援導入本機備份導入其他機器備份可能會恢復失敗', websiteBackupWarn: '僅支援導入本機備份導入其他機器備份可能會恢復失敗',
ipWebsiteWarn: 'IP 為網域名稱的網站需要設定為預設網站才能正常存取', ipWebsiteWarn: 'IP 為網域名稱的網站需要設定為預設網站才能正常存取',
hstsHelper: '開啟 HSTS 可以增加網站安全性', hstsHelper: '開啟 HSTS 可以增加網站安全性',
sslExpireDate: '憑證過期時間',
}, },
php: { php: {
short_open_tag: '短標簽支持', short_open_tag: '短標簽支持',

View File

@ -1890,6 +1890,7 @@ const message = {
websiteBackupWarn: '仅支持导入本机备份导入其他机器备份可能会恢复失败', websiteBackupWarn: '仅支持导入本机备份导入其他机器备份可能会恢复失败',
ipWebsiteWarn: 'IP 为域名的网站需要设置为默认站点才能正常访问', ipWebsiteWarn: 'IP 为域名的网站需要设置为默认站点才能正常访问',
hstsHelper: '开启 HSTS 可以增加网站安全性', hstsHelper: '开启 HSTS 可以增加网站安全性',
sslExpireDate: '证书过期时间',
}, },
php: { php: {
short_open_tag: '短标签支持', short_open_tag: '短标签支持',

View File

@ -319,6 +319,7 @@ const submit = async (formEl: FormInstance | undefined) => {
const changeEnable = (enable: boolean) => { const changeEnable = (enable: boolean) => {
if (enable) { if (enable) {
listSSL(); listSSL();
form.hsts = true;
} }
if (resData.value.enable && !enable) { if (resData.value.enable && !enable) {
ElMessageBox.confirm(i18n.global.t('website.disableHTTPSHelper'), i18n.global.t('website.disableHTTPS'), { ElMessageBox.confirm(i18n.global.t('website.disableHTTPSHelper'), i18n.global.t('website.disableHTTPS'), {

View File

@ -154,6 +154,13 @@
</div> </div>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column :label="$t('website.sslExpireDate')" width="150px">
<template #default="{ row }">
<el-tag v-if="row.protocol == 'HTTPS'" :type="row.sslStatus">
{{ dateFormatSimple(row.sslExpireDate) }}
</el-tag>
</template>
</el-table-column>
<fu-table-operations <fu-table-operations
:ellipsis="10" :ellipsis="10"
width="400px" width="400px"