mirror of
				https://github.com/TeaOSLab/EdgeAdmin.git
				synced 2025-11-04 21:35:33 +08:00 
			
		
		
		
	
		
			
	
	
		
			69 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
		
		
			
		
	
	
			69 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| 
								 | 
							
								package ssl
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								import (
							 | 
						||
| 
								 | 
							
									"encoding/json"
							 | 
						||
| 
								 | 
							
									"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
							 | 
						||
| 
								 | 
							
									"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
							 | 
						||
| 
								 | 
							
									"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/sslconfigs"
							 | 
						||
| 
								 | 
							
									"github.com/iwind/TeaGo/maps"
							 | 
						||
| 
								 | 
							
									timeutil "github.com/iwind/TeaGo/utils/time"
							 | 
						||
| 
								 | 
							
									"time"
							 | 
						||
| 
								 | 
							
								)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								// 选择证书
							 | 
						||
| 
								 | 
							
								type SelectPopupAction struct {
							 | 
						||
| 
								 | 
							
									actionutils.ParentAction
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								func (this *SelectPopupAction) Init() {
							 | 
						||
| 
								 | 
							
									this.Nav("", "", "")
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								func (this *SelectPopupAction) RunGet(params struct{}) {
							 | 
						||
| 
								 | 
							
									// TODO 支持关键词搜索
							 | 
						||
| 
								 | 
							
									// TODO 列出常用的证书供用户选择
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									countResp, err := this.RPC().SSLCertRPC().CountSSLCerts(this.AdminContext(), &pb.CountSSLCertRequest{})
							 | 
						||
| 
								 | 
							
									if err != nil {
							 | 
						||
| 
								 | 
							
										this.ErrorPage(err)
							 | 
						||
| 
								 | 
							
										return
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									page := this.NewPage(countResp.Count)
							 | 
						||
| 
								 | 
							
									this.Data["page"] = page.AsHTML()
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									listResp, err := this.RPC().SSLCertRPC().ListSSLCerts(this.AdminContext(), &pb.ListSSLCertsRequest{
							 | 
						||
| 
								 | 
							
										Offset: page.Offset,
							 | 
						||
| 
								 | 
							
										Size:   page.Size,
							 | 
						||
| 
								 | 
							
									})
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									certConfigs := []*sslconfigs.SSLCertConfig{}
							 | 
						||
| 
								 | 
							
									err = json.Unmarshal(listResp.CertsJSON, &certConfigs)
							 | 
						||
| 
								 | 
							
									if err != nil {
							 | 
						||
| 
								 | 
							
										this.ErrorPage(err)
							 | 
						||
| 
								 | 
							
										return
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
									this.Data["certs"] = certConfigs
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									certMaps := []maps.Map{}
							 | 
						||
| 
								 | 
							
									nowTime := time.Now().Unix()
							 | 
						||
| 
								 | 
							
									for _, certConfig := range certConfigs {
							 | 
						||
| 
								 | 
							
										countServersResp, err := this.RPC().ServerRPC().CountServersWithSSLCertId(this.AdminContext(), &pb.CountServersWithSSLCertIdRequest{CertId: certConfig.Id})
							 | 
						||
| 
								 | 
							
										if err != nil {
							 | 
						||
| 
								 | 
							
											this.ErrorPage(err)
							 | 
						||
| 
								 | 
							
											return
							 | 
						||
| 
								 | 
							
										}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										certMaps = append(certMaps, maps.Map{
							 | 
						||
| 
								 | 
							
											"beginDay":     timeutil.FormatTime("Y-m-d", certConfig.TimeBeginAt),
							 | 
						||
| 
								 | 
							
											"endDay":       timeutil.FormatTime("Y-m-d", certConfig.TimeEndAt),
							 | 
						||
| 
								 | 
							
											"isExpired":    nowTime > certConfig.TimeEndAt,
							 | 
						||
| 
								 | 
							
											"isAvailable":  nowTime <= certConfig.TimeEndAt,
							 | 
						||
| 
								 | 
							
											"countServers": countServersResp.Count,
							 | 
						||
| 
								 | 
							
										})
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
									this.Data["certInfos"] = certMaps
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									this.Show()
							 | 
						||
| 
								 | 
							
								}
							 |