diff --git a/app/services/website.go b/app/services/website.go index a24deaf2..b78680e2 100644 --- a/app/services/website.go +++ b/app/services/website.go @@ -2,6 +2,8 @@ package services import ( + "crypto/x509" + "encoding/pem" "errors" "fmt" "regexp" @@ -49,6 +51,11 @@ type WebsiteSetting struct { Ssl bool `json:"ssl"` SslCertificate string `json:"ssl_certificate"` SslCertificateKey string `json:"ssl_certificate_key"` + SslNotBefore string `json:"ssl_not_before"` + SslNotAfter string `json:"ssl_not_after"` + SSlDNSNames []string `json:"ssl_dns_names"` + SslIssuer string `json:"ssl_issuer"` + SslOCSPServer []string `json:"ssl_ocsp_server"` HttpRedirect bool `json:"http_redirect"` Hsts bool `json:"hsts"` Waf bool `json:"waf"` @@ -319,6 +326,19 @@ func (r *WebsiteImpl) GetConfig(id int) (WebsiteSetting, error) { ssl := tools.Cut(config, "# ssl标记位开始", "# ssl标记位结束") setting.HttpRedirect = strings.Contains(ssl, "# http重定向标记位") setting.Hsts = strings.Contains(ssl, "# hsts标记位") + + certData := tools.Read("/www/server/vhost/ssl/" + website.Name + ".pem") + block, _ := pem.Decode([]byte(certData)) + if block != nil { + cert, err := x509.ParseCertificate(block.Bytes) + if err == nil { + setting.SslNotBefore = cert.NotBefore.Format("2006-01-02 15:04:05") + setting.SslNotAfter = cert.NotAfter.Format("2006-01-02 15:04:05") + setting.SslIssuer = cert.Issuer.CommonName + setting.SslOCSPServer = cert.OCSPServer + setting.SSlDNSNames = cert.DNSNames + } + } } else { setting.HttpRedirect = false setting.Hsts = false diff --git a/public/panel/views/website/edit.html b/public/panel/views/website/edit.html index 3f00efb4..b3f5c267 100644 --- a/public/panel/views/website/edit.html +++ b/public/panel/views/website/edit.html @@ -201,7 +201,27 @@ Date: 2023-07-24
+ 有效期: + {{ d.params.config.ssl_not_before }} ~ {{ d.params.config.ssl_not_after }} ++
+ 域名: + {{# layui.each(d.params.config.ssl_dns_names, function(index, item){ }} + {{ item }} + {{# }); }} ++
+ 签发者: + {{ d.params.config.ssl_issuer }} ++
+ OCSP: + {{# layui.each(d.params.config.ssl_ocsp_server, function(index, item){ }} + {{ item }} + {{# }); }} ++ {{# }else{ }} {{# } }} @@ -311,11 +331,11 @@ Date: 2023-07-24 layer.load() let ports = $("input[name='ports[]']").map(function () { return $(this).val(); - }).get() + }).get().join('\n') let domains = $("input[name='domains[]']").map(function () { return $(this).val(); - }).get() + }).get().join('\n') var reg = new RegExp(/\n443.*\n?/); // 如果开启了https,就自动添加443端口 if ($('input[name="ssl"]').prop('checked') && !reg.test(ports)) { @@ -331,8 +351,8 @@ Date: 2023-07-24 , type: 'post' , data: { id: params.data.id, - domains: domains.join('\n'), - ports: ports.join('\n'), + domains: domains, + ports: ports, ssl: $('input[name="ssl"]').prop('checked'), http_redirect: $('input[name="http_redirect"]').prop('checked'), hsts: $('input[name="hsts"]').prop('checked'),