mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-03 12:20:28 +08:00
证书列表区分管理员和用户证书
This commit is contained in:
@@ -19,13 +19,19 @@ func (this *IndexAction) Init() {
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
UserId int64
|
||||
Type string
|
||||
Keyword string
|
||||
UserId int64
|
||||
Type string // [empty] | ca | 7days | ...
|
||||
Keyword string
|
||||
UserType string
|
||||
}) {
|
||||
this.Data["type"] = params.Type
|
||||
this.Data["keyword"] = params.Keyword
|
||||
|
||||
if params.UserId > 0 {
|
||||
params.UserType = "user"
|
||||
}
|
||||
this.Data["userType"] = params.UserType
|
||||
|
||||
// 当前用户
|
||||
this.Data["searchingUserId"] = params.UserId
|
||||
var userMap = maps.Map{
|
||||
@@ -57,12 +63,15 @@ func (this *IndexAction) RunGet(params struct {
|
||||
var count7Days int64
|
||||
var count30Days int64
|
||||
|
||||
var userOnly = params.UserType == "user" || params.UserId > 0
|
||||
|
||||
// 计算数量
|
||||
{
|
||||
// all
|
||||
resp, err := this.RPC().SSLCertRPC().CountSSLCerts(this.AdminContext(), &pb.CountSSLCertRequest{
|
||||
UserId: params.UserId,
|
||||
Keyword: params.Keyword,
|
||||
UserId: params.UserId,
|
||||
Keyword: params.Keyword,
|
||||
UserOnly: userOnly,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
@@ -72,9 +81,10 @@ func (this *IndexAction) RunGet(params struct {
|
||||
|
||||
// CA
|
||||
resp, err = this.RPC().SSLCertRPC().CountSSLCerts(this.AdminContext(), &pb.CountSSLCertRequest{
|
||||
UserId: params.UserId,
|
||||
IsCA: true,
|
||||
Keyword: params.Keyword,
|
||||
UserId: params.UserId,
|
||||
IsCA: true,
|
||||
Keyword: params.Keyword,
|
||||
UserOnly: userOnly,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
@@ -87,6 +97,7 @@ func (this *IndexAction) RunGet(params struct {
|
||||
UserId: params.UserId,
|
||||
IsAvailable: true,
|
||||
Keyword: params.Keyword,
|
||||
UserOnly: userOnly,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
@@ -99,6 +110,7 @@ func (this *IndexAction) RunGet(params struct {
|
||||
UserId: params.UserId,
|
||||
IsExpired: true,
|
||||
Keyword: params.Keyword,
|
||||
UserOnly: userOnly,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
@@ -111,6 +123,7 @@ func (this *IndexAction) RunGet(params struct {
|
||||
UserId: params.UserId,
|
||||
ExpiringDays: 7,
|
||||
Keyword: params.Keyword,
|
||||
UserOnly: userOnly,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
@@ -123,6 +136,7 @@ func (this *IndexAction) RunGet(params struct {
|
||||
UserId: params.UserId,
|
||||
ExpiringDays: 30,
|
||||
Keyword: params.Keyword,
|
||||
UserOnly: userOnly,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
@@ -146,19 +160,21 @@ func (this *IndexAction) RunGet(params struct {
|
||||
case "":
|
||||
page = this.NewPage(countAll)
|
||||
listResp, err = this.RPC().SSLCertRPC().ListSSLCerts(this.AdminContext(), &pb.ListSSLCertsRequest{
|
||||
UserId: params.UserId,
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
Keyword: params.Keyword,
|
||||
UserId: params.UserId,
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
Keyword: params.Keyword,
|
||||
UserOnly: userOnly,
|
||||
})
|
||||
case "ca":
|
||||
page = this.NewPage(countCA)
|
||||
listResp, err = this.RPC().SSLCertRPC().ListSSLCerts(this.AdminContext(), &pb.ListSSLCertsRequest{
|
||||
UserId: params.UserId,
|
||||
IsCA: true,
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
Keyword: params.Keyword,
|
||||
UserId: params.UserId,
|
||||
IsCA: true,
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
Keyword: params.Keyword,
|
||||
UserOnly: userOnly,
|
||||
})
|
||||
case "available":
|
||||
page = this.NewPage(countAvailable)
|
||||
@@ -168,6 +184,7 @@ func (this *IndexAction) RunGet(params struct {
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
Keyword: params.Keyword,
|
||||
UserOnly: userOnly,
|
||||
})
|
||||
case "expired":
|
||||
page = this.NewPage(countExpired)
|
||||
@@ -177,6 +194,7 @@ func (this *IndexAction) RunGet(params struct {
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
Keyword: params.Keyword,
|
||||
UserOnly: userOnly,
|
||||
})
|
||||
case "7days":
|
||||
page = this.NewPage(count7Days)
|
||||
@@ -195,14 +213,16 @@ func (this *IndexAction) RunGet(params struct {
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
Keyword: params.Keyword,
|
||||
UserOnly: userOnly,
|
||||
})
|
||||
default:
|
||||
page = this.NewPage(countAll)
|
||||
listResp, err = this.RPC().SSLCertRPC().ListSSLCerts(this.AdminContext(), &pb.ListSSLCertsRequest{
|
||||
UserId: params.UserId,
|
||||
Keyword: params.Keyword,
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
UserId: params.UserId,
|
||||
Keyword: params.Keyword,
|
||||
UserOnly: userOnly,
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
}
|
||||
if err != nil {
|
||||
@@ -221,6 +241,7 @@ func (this *IndexAction) RunGet(params struct {
|
||||
var certMaps = []maps.Map{}
|
||||
var nowTime = time.Now().Unix()
|
||||
for _, certConfig := range certConfigs {
|
||||
// count servers
|
||||
countServersResp, err := this.RPC().ServerRPC().CountAllEnabledServersWithSSLCertId(this.AdminContext(), &pb.CountAllEnabledServersWithSSLCertIdRequest{
|
||||
SslCertId: certConfig.Id,
|
||||
})
|
||||
@@ -229,6 +250,23 @@ func (this *IndexAction) RunGet(params struct {
|
||||
return
|
||||
}
|
||||
|
||||
// user
|
||||
userResp, err := this.RPC().SSLCertRPC().FindSSLCertUser(this.AdminContext(), &pb.FindSSLCertUserRequest{SslCertId: certConfig.Id})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var certUserMap = maps.Map{
|
||||
"id": 0,
|
||||
}
|
||||
if userResp.User != nil {
|
||||
certUserMap = maps.Map{
|
||||
"id": userResp.User.Id,
|
||||
"username": userResp.User.Username,
|
||||
"fullname": userResp.User.Fullname,
|
||||
}
|
||||
}
|
||||
|
||||
certMaps = append(certMaps, maps.Map{
|
||||
"isOn": certConfig.IsOn,
|
||||
"beginDay": timeutil.FormatTime("Y-m-d", certConfig.TimeBeginAt),
|
||||
@@ -236,6 +274,7 @@ func (this *IndexAction) RunGet(params struct {
|
||||
"isExpired": nowTime > certConfig.TimeEndAt,
|
||||
"isAvailable": nowTime <= certConfig.TimeEndAt,
|
||||
"countServers": countServersResp.Count,
|
||||
"user": certUserMap,
|
||||
})
|
||||
}
|
||||
this.Data["certInfos"] = certMaps
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
|
||||
<div class="right-box without-tabbar">
|
||||
<second-menu>
|
||||
<menu-item :href="'/servers/certs?keyword=' + keyword + '&userId=' + searchingUserId" :active="type == ''">所有证书({{countAll}})</menu-item>
|
||||
<menu-item :href="'/servers/certs?type=ca&keyword=' + keyword + '&userId=' + searchingUserId" :active="type == 'ca'">CA证书({{countCA}})</menu-item>
|
||||
<menu-item :href="'/servers/certs?type=available&keyword=' + keyword + '&userId=' + searchingUserId" :active="type == 'available'">有效证书({{countAvailable}})</menu-item>
|
||||
<menu-item :href="'/servers/certs?type=expired&keyword=' + keyword + '&userId=' + searchingUserId" :active="type == 'expired'">过期证书<span :class="{red: countExpired > 0}">({{countExpired}})</span></menu-item>
|
||||
<menu-item :href="'/servers/certs?type=7days&keyword=' + keyword + '&userId=' + searchingUserId" :active="type == '7days'">7天内过期<span :class="{red: count7Days > 0}">({{count7Days}})</span></menu-item>
|
||||
<menu-item :href="'/servers/certs?type=30days&keyword=' + keyword + '&userId=' + searchingUserId" :active="type == '30days'">30天内过期({{count30Days}})</menu-item>
|
||||
<menu-item :href="'/servers/certs?userType=' + userType + '&keyword=' + keyword + '&userId=' + searchingUserId" :active="type == ''">所有证书({{countAll}})</menu-item>
|
||||
<menu-item :href="'/servers/certs?userType=' + userType + '&type=ca&keyword=' + keyword + '&userId=' + searchingUserId" :active="type == 'ca'">CA证书({{countCA}})</menu-item>
|
||||
<menu-item :href="'/servers/certs?userType=' + userType + '&type=available&keyword=' + keyword + '&userId=' + searchingUserId" :active="type == 'available'">有效证书({{countAvailable}})</menu-item>
|
||||
<menu-item :href="'/servers/certs?userType=' + userType + '&type=expired&keyword=' + keyword + '&userId=' + searchingUserId" :active="type == 'expired'">过期证书<span :class="{red: countExpired > 0}">({{countExpired}})</span></menu-item>
|
||||
<menu-item :href="'/servers/certs?userType=' + userType + '&type=7days&keyword=' + keyword + '&userId=' + searchingUserId" :active="type == '7days'">7天内过期<span :class="{red: count7Days > 0}">({{count7Days}})</span></menu-item>
|
||||
<menu-item :href="'/servers/certs?userType=' + userType + '&type=30days&keyword=' + keyword + '&userId=' + searchingUserId" :active="type == '30days'">30天内过期({{count30Days}})</menu-item>
|
||||
<span class="item disabled">|</span>
|
||||
<a href="" class="item" @click.prevent="uploadCert">[上传证书]</a>
|
||||
<a href="" class="item" @click.prevent="uploadBatch">[批量上传]</a>
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
<form class="ui form">
|
||||
<input type="hidden" name="type" :value="type"/>
|
||||
<input type="hidden" name="userType" :value="userType"/>
|
||||
<div class="ui fields inline">
|
||||
<div class="ui field">
|
||||
<input type="text" name="keyword" placeholder="域名、说明等关键词" style="width:12em" v-model="keyword"/>
|
||||
@@ -26,17 +27,23 @@
|
||||
<div class="ui field">
|
||||
<button type="submit" class="ui button">搜索</button>
|
||||
|
||||
<a :href="Tea.url('.', { 'type':type })" v-if="keyword.length > 0 || searchingUserId > 0">[清除条件]</a>
|
||||
<a :href="Tea.url('.', { 'userType':userType, 'type':type })" v-if="keyword.length > 0 || searchingUserId > 0">[清除条件]</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div v-if="searchingUserId == 0">
|
||||
<div class="ui divider"></div>
|
||||
<p class="comment" style="padding-top: 0">默认只显示管理员所属的证书,用户所属证书请在上面表单中选择对应用户后搜索。</p>
|
||||
<div class="ui menu text basic tiny blue" style="margin-bottom:0">
|
||||
<a :href="'/servers/certs?userType=&type=' + type + '&keyword=' + keyword + '&userId=' + searchingUserId" class="item" :class="{active: userType == ''}">管理员证书</a>
|
||||
<a :href="'/servers/certs?userType=user&type=' + type + '&keyword=' + keyword + '&userId=' + searchingUserId" class="item" :class="{active: userType == 'user'}">用户证书</a>
|
||||
</div>
|
||||
<div class="ui divider" style="margin-top:0"></div>
|
||||
</div>
|
||||
|
||||
<p class="comment" v-if="certs.length == 0"><span v-if="searchingUserId > 0">当前用户下</span>暂时还没有相关的证书。</p>
|
||||
|
||||
|
||||
|
||||
<table class="ui table selectable celled" v-if="certs.length > 0">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -72,7 +79,7 @@
|
||||
<td>{{certInfos[index].endDay}}</td>
|
||||
<td class="center">{{certInfos[index].countServers}}</td>
|
||||
<td>
|
||||
<span v-if="user != null && user.id > 0"><user-link :v-user="user"></user-link></span>
|
||||
<span v-if="certInfos[index].user != null && certInfos[index].user.id > 0"><user-link :v-user="certInfos[index].user"></user-link></span>
|
||||
<span v-else class="disabled">管理员</span>
|
||||
</td>
|
||||
<td nowrap="" class="center">
|
||||
|
||||
Reference in New Issue
Block a user