2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-06 11:23:44 +08:00

feat: add ssl info

This commit is contained in:
耗子
2023-08-15 01:42:20 +08:00
parent 83d7aec8f5
commit b7869c36dc
2 changed files with 45 additions and 5 deletions

View File

@@ -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

View File

@@ -201,7 +201,27 @@ Date: 2023-07-24
<div class="layui-form-item layui-form-text">
{{# if(d.params.config.ssl){ }}
<label class="layui-form-label">证书 <span style="color: red; float: right;">剩余有效期{{ d.params.config.ssl_date }}</span></label>
<blockquote class="layui-elem-quote layui-quote-nm">
有效期:
<span class="layui-badge">{{ d.params.config.ssl_not_before }} ~ {{ d.params.config.ssl_not_after }}</span>
</blockquote>
<blockquote class="layui-elem-quote layui-quote-nm">
域名:
{{# layui.each(d.params.config.ssl_dns_names, function(index, item){ }}
<span class="layui-badge layui-bg-blue">{{ item }}</span>
{{# }); }}
</blockquote>
<blockquote class="layui-elem-quote layui-quote-nm">
签发者:
<span class="layui-badge layui-bg-orange">{{ d.params.config.ssl_issuer }}</span>
</blockquote>
<blockquote class="layui-elem-quote layui-quote-nm">
OCSP:
{{# layui.each(d.params.config.ssl_ocsp_server, function(index, item){ }}
<span class="layui-badge layui-bg-blue">{{ item }}</span>
{{# }); }}
</blockquote>
<label class="layui-form-label">证书</label>
{{# }else{ }}
<label class="layui-form-label">证书</label>
{{# } }}
@@ -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'),