feat(protect): 证书列表直接平铺每一套证书,不再藏在「身份列表」弹窗里
用户要求:不要点了才看到,主列表就该显示所有证书。
改动:
- 后端新增两个接口:
GET /dev/sign-profiles/identities-flat?page=&page_size=
把所有记录的每一套身份平铺成一页(key = profileID:index,带来源文件、
到期、是否过期、可签类型、是否配交叉证书),分页默认 50
POST /dev/sign-profiles/identities-check {keys:["12:3",...]}
批量检测吊销/拉黑(单次最多 20,内部并发 6),按 key 回结果
路由注册在 /:id 之前,否则会被 /:id 吃掉
- 前端「签名证书」页重做:主列表 = 证书表格(一行一套)
列:☑ | 证书名称(CN) | 来源文件 | 到期 | 是否过期 | 可签类型 | 吊销 | 拉黑 | 操作
工具条:全选 / 已选 N / 检测本页 / 已检测 N/M / 导出密码 / 跳过已吊销 / 导出选中为 zip
行内:检测(单套)、删除整个证书文件(两段确认)
底部:页码 + 上一页/下一页
- 状态做成带底色+描边的标签(正常绿 / 查不到黄 / 私钥泄露红),表头吸顶加粗,
几十行扫读能一眼看出哪几套有问题
实测(本地 1249 套):
- 列表第 1 页 50 行,分页「第 1/25 页 · 共 1249 套」
- 「检测本页」50 套分 3 批跑完,显示「已检测 50/50」
- 抽查:浙江恒歌 正常/正常;上海笑聘 查不到(琥珀);上海到喜啦 私钥泄露(红)
This commit is contained in:
@@ -0,0 +1,194 @@
|
||||
package admin
|
||||
|
||||
// 把所有证书记录里的「每一套签名身份」拉平成一张表。
|
||||
//
|
||||
// 一个 pfx 里可能装几十套证书(驱动签名包常见),用户要的是「一眼看到全部证书」,
|
||||
// 而不是先点某个文件再看里面。所以这里提供扁平列表:每行就是一套身份,
|
||||
// 带来源文件、到期、可签类型,吊销/拉黑状态按需检测。
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"verification-platform-backend/internal/database"
|
||||
"verification-platform-backend/internal/model"
|
||||
"verification-platform-backend/internal/protect"
|
||||
"verification-platform-backend/pkg/response"
|
||||
)
|
||||
|
||||
// FlatIdentity 扁平列表里的一行
|
||||
type FlatIdentity struct {
|
||||
Key string `json:"key"` // "profileID:index"
|
||||
ProfileID uint `json:"profile_id"`
|
||||
ProfileName string `json:"profile_name"`
|
||||
Platform string `json:"platform"`
|
||||
HasCross bool `json:"has_cross"`
|
||||
Index int `json:"index"`
|
||||
Subject string `json:"subject"`
|
||||
CN string `json:"cn"`
|
||||
NotAfter string `json:"not_after"`
|
||||
Expired bool `json:"expired"`
|
||||
Usage string `json:"usage_label"`
|
||||
UsageApp bool `json:"usage_app"`
|
||||
UsageDriver bool `json:"usage_driver"`
|
||||
ParseError string `json:"parse_error,omitempty"`
|
||||
}
|
||||
|
||||
// HandleFlatIdentities 全部证书身份(分页)
|
||||
//
|
||||
// GET /dev/sign-profiles/identities-flat?page=1&page_size=50
|
||||
func HandleFlatIdentities(c *gin.Context) {
|
||||
userID := c.GetUint("user_id")
|
||||
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
||||
size, _ := strconv.Atoi(c.DefaultQuery("page_size", "50"))
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
if size < 1 || size > 200 {
|
||||
size = 50
|
||||
}
|
||||
|
||||
var profiles []model.SignProfile
|
||||
if err := database.DB.Where("user_id = ?", userID).Order("id desc").Find(&profiles).Error; err != nil {
|
||||
response.InternalError(c, "读取证书失败")
|
||||
return
|
||||
}
|
||||
|
||||
all := make([]FlatIdentity, 0, len(profiles)*4)
|
||||
for _, sp := range profiles {
|
||||
certData, err := protect.ReadEncrypted(sp.CertPath)
|
||||
if err != nil {
|
||||
all = append(all, FlatIdentity{
|
||||
Key: strconv.FormatUint(uint64(sp.ID), 10) + ":0", ProfileID: sp.ID,
|
||||
ProfileName: sp.Name, Platform: sp.Platform, HasCross: sp.CrossPath != "",
|
||||
Subject: sp.Subject, CN: cnFromSubject(sp.Subject), ParseError: "读取证书失败",
|
||||
})
|
||||
continue
|
||||
}
|
||||
password := ""
|
||||
if b, e := protect.ReadEncrypted(sp.PassPath); e == nil {
|
||||
password = string(b)
|
||||
}
|
||||
full, perr := protect.ParseIdentitiesFull(certData, password)
|
||||
if perr != nil || len(full) == 0 {
|
||||
all = append(all, FlatIdentity{
|
||||
Key: strconv.FormatUint(uint64(sp.ID), 10) + ":0", ProfileID: sp.ID,
|
||||
ProfileName: sp.Name, Platform: sp.Platform, HasCross: sp.CrossPath != "",
|
||||
Subject: sp.Subject, CN: cnFromSubject(sp.Subject), ParseError: "解析失败",
|
||||
})
|
||||
continue
|
||||
}
|
||||
for _, d := range full {
|
||||
all = append(all, FlatIdentity{
|
||||
Key: strconv.FormatUint(uint64(sp.ID), 10) + ":" + strconv.Itoa(d.Index),
|
||||
ProfileID: sp.ID,
|
||||
ProfileName: sp.Name,
|
||||
Platform: sp.Platform,
|
||||
HasCross: sp.CrossPath != "",
|
||||
Index: d.Index,
|
||||
Subject: d.Subject,
|
||||
CN: cnFromSubject(d.Subject),
|
||||
NotAfter: d.NotAfter.Format("2006-01-02"),
|
||||
Expired: d.Expired,
|
||||
Usage: d.Usage.Label,
|
||||
UsageApp: d.Usage.App,
|
||||
UsageDriver: d.Usage.Driver,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
total := len(all)
|
||||
from := (page - 1) * size
|
||||
if from > total {
|
||||
from = total
|
||||
}
|
||||
to := from + size
|
||||
if to > total {
|
||||
to = total
|
||||
}
|
||||
response.Success(c, gin.H{
|
||||
"total": total,
|
||||
"page": page,
|
||||
"page_size": size,
|
||||
"items": all[from:to],
|
||||
})
|
||||
}
|
||||
|
||||
// HandleCheckIdentities 批量检测指定身份的吊销 / 拉黑(单次最多 20 个)
|
||||
//
|
||||
// POST /dev/sign-profiles/identities-check
|
||||
//
|
||||
// { "keys": ["12:3", "12:7", "15:1"] }
|
||||
func HandleCheckIdentities(c *gin.Context) {
|
||||
userID := c.GetUint("user_id")
|
||||
var req struct {
|
||||
Keys []string `json:"keys"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil || len(req.Keys) == 0 {
|
||||
response.ParamError(c, "请提供要检测的身份(key = profileID:index)")
|
||||
return
|
||||
}
|
||||
if len(req.Keys) > 20 {
|
||||
req.Keys = req.Keys[:20] // 一批最多 20,剩下的前端接着要
|
||||
}
|
||||
|
||||
// 按 profile 分组,减少重复解析
|
||||
byProfile := map[uint][]int{}
|
||||
order := []string{}
|
||||
for _, k := range req.Keys {
|
||||
parts := strings.Split(k, ":")
|
||||
if len(parts) != 2 {
|
||||
continue
|
||||
}
|
||||
pid, err1 := strconv.ParseUint(parts[0], 10, 64)
|
||||
idx, err2 := strconv.Atoi(parts[1])
|
||||
if err1 != nil || err2 != nil {
|
||||
continue
|
||||
}
|
||||
byProfile[uint(pid)] = append(byProfile[uint(pid)], idx)
|
||||
order = append(order, k)
|
||||
}
|
||||
|
||||
out := map[string]gin.H{}
|
||||
ban := localBanMap()
|
||||
for pid, idxs := range byProfile {
|
||||
var sp model.SignProfile
|
||||
if err := database.DB.Where("id = ? AND user_id = ?", pid, userID).First(&sp).Error; err != nil {
|
||||
continue
|
||||
}
|
||||
certData, err := protect.ReadEncrypted(sp.CertPath)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
password := ""
|
||||
if b, e := protect.ReadEncrypted(sp.PassPath); e == nil {
|
||||
password = string(b)
|
||||
}
|
||||
full, perr := protect.ParseIdentitiesFull(certData, password)
|
||||
if perr != nil {
|
||||
continue
|
||||
}
|
||||
var list []protect.IdentityDetail
|
||||
for _, i := range idxs {
|
||||
if i >= 1 && i <= len(full) {
|
||||
list = append(list, full[i-1])
|
||||
}
|
||||
}
|
||||
res := checkIdentities(list, 0, ban)
|
||||
for _, r := range res {
|
||||
key := strconv.FormatUint(uint64(pid), 10) + ":" + strconv.Itoa(r["index"].(int))
|
||||
out[key] = r
|
||||
}
|
||||
}
|
||||
|
||||
items := make([]gin.H, 0, len(order))
|
||||
for _, k := range order {
|
||||
if r, ok := out[k]; ok {
|
||||
r["key"] = k
|
||||
items = append(items, r)
|
||||
}
|
||||
}
|
||||
response.Success(c, gin.H{"items": items, "checked": len(items)})
|
||||
}
|
||||
@@ -27,6 +27,9 @@ func SetupSignProfileRoutes(r *gin.RouterGroup) {
|
||||
{
|
||||
g.POST("", HandleCreateSignProfile)
|
||||
g.GET("", HandleListSignProfiles)
|
||||
// 扁平列表与批量检测要放在 /:id 之前注册,否则会被 /:id 匹配走
|
||||
g.GET("/identities-flat", HandleFlatIdentities)
|
||||
g.POST("/identities-check", HandleCheckIdentities)
|
||||
g.GET("/:id", HandleGetSignProfile)
|
||||
g.GET("/:id/identities", HandleListIdentities)
|
||||
g.POST("/:id/export", HandleExportIdentities)
|
||||
|
||||
@@ -1,19 +1,15 @@
|
||||
<script setup lang="ts">
|
||||
import { FileKey2, Loader2, ShieldCheck, Trash2, Upload } from 'lucide-vue-next'
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { toast } from 'vue-sonner'
|
||||
|
||||
import { BasicPage } from '@/components/global-layout'
|
||||
import type { SignProfile } from '@/pages/admin/sign-profiles/data/schema'
|
||||
|
||||
import SignProfileDataTable from '@/pages/admin/sign-profiles/components/data-table.vue'
|
||||
import { BASE_URL } from '@/services/api'
|
||||
import api from '@/services/api'
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const items = ref<SignProfile[]>([])
|
||||
const loading = ref(true)
|
||||
const uploading = ref(false)
|
||||
|
||||
@@ -28,102 +24,103 @@ const crossInput = ref<HTMLInputElement | null>(null)
|
||||
const certInput = ref<HTMLInputElement | null>(null)
|
||||
const profileInput = ref<HTMLInputElement | null>(null)
|
||||
|
||||
// ---- 身份列表(一个 pfx 里的每套证书)+ 吊销/拉黑检测 ----
|
||||
const identityDialog = ref(false)
|
||||
const identityProfile = ref<SignProfile | null>(null)
|
||||
const identities = ref<any[]>([])
|
||||
const identityLoading = ref(false)
|
||||
// ------------------------------------------------- 证书列表(一行 = 一套身份)
|
||||
interface FlatIdentity {
|
||||
key: string
|
||||
profile_id: number
|
||||
profile_name: string
|
||||
platform: string
|
||||
has_cross: boolean
|
||||
index: number
|
||||
subject: string
|
||||
cn: string
|
||||
not_after: string
|
||||
expired: boolean
|
||||
usage_label: string
|
||||
usage_app: boolean
|
||||
usage_driver: boolean
|
||||
parse_error?: string
|
||||
revoke?: any
|
||||
ban?: any
|
||||
}
|
||||
|
||||
const rows = ref<FlatIdentity[]>([])
|
||||
const total = ref(0)
|
||||
const page = ref(1)
|
||||
const pageSize = ref(50)
|
||||
const pageCount = computed(() => Math.max(1, Math.ceil(total.value / pageSize.value)))
|
||||
const selected = ref<string[]>([])
|
||||
const allSelected = computed(() => rows.value.length > 0 && selected.value.length === rows.value.length)
|
||||
|
||||
function toggleAll(on: boolean) {
|
||||
selected.value = on ? rows.value.map(r => r.key) : []
|
||||
}
|
||||
|
||||
function gotoPage(p: number) {
|
||||
page.value = Math.min(Math.max(1, p), pageCount.value)
|
||||
load()
|
||||
}
|
||||
|
||||
// ------------------------------------------------------ 吊销 / 拉黑检测
|
||||
const checking = ref(false)
|
||||
const selected = ref<number[]>([])
|
||||
const checkDone = ref(0)
|
||||
const exporting = ref(false)
|
||||
const exportPassword = ref('')
|
||||
const exportSkipRevoked = ref(true)
|
||||
const checkDone = ref(0)
|
||||
|
||||
async function openIdentities(row: SignProfile) {
|
||||
identityProfile.value = row
|
||||
identityDialog.value = true
|
||||
identities.value = []
|
||||
checkDone.value = 0
|
||||
identityLoading.value = true
|
||||
try {
|
||||
const data: any = await api.get(`/dev/sign-profiles/${row.id}/identities`)
|
||||
identities.value = (data?.identities || []).map((it: any) => ({ ...it, revoke: null, ban: null }))
|
||||
}
|
||||
catch (e: any) {
|
||||
toast.error(e?.message || '读取身份列表失败')
|
||||
}
|
||||
finally {
|
||||
identityLoading.value = false
|
||||
}
|
||||
function stateText(info: any) {
|
||||
if (!info) return t('admin.signProfiles.notChecked')
|
||||
if (info.status === 'good') return t('admin.signProfiles.revokeGood')
|
||||
if (info.status === 'revoked') return info.reason || t('admin.signProfiles.revokeBad')
|
||||
if (info.status === 'unknown') return t('admin.signProfiles.revokeUnknown')
|
||||
return t('admin.signProfiles.notChecked')
|
||||
}
|
||||
|
||||
// 单套检测
|
||||
async function checkOne(index: number) {
|
||||
if (!identityProfile.value) return
|
||||
const data: any = await api.get(`/dev/sign-profiles/${identityProfile.value.id}/identities?check=${index}`)
|
||||
const item = (data?.items || [])[0]
|
||||
const row = identities.value.find((it: any) => it.index === index)
|
||||
if (row && item) {
|
||||
row.revoke = item.revoke
|
||||
row.ban = item.ban
|
||||
checkDone.value = identities.value.filter((it: any) => it.revoke).length
|
||||
}
|
||||
// 状态做成带底色的标签:纯文字颜色扫读太慢,几十行看不出哪些有问题
|
||||
function stateClass(info: any) {
|
||||
if (!info) return 'bg-muted text-muted-foreground'
|
||||
if (info.status === 'good') return 'bg-emerald-500/15 text-emerald-700 ring-1 ring-inset ring-emerald-500/25 dark:text-emerald-300'
|
||||
if (info.status === 'revoked') return 'bg-red-500/20 text-red-700 ring-1 ring-inset ring-red-500/30 dark:text-red-300'
|
||||
if (info.status === 'unknown') return 'bg-amber-500/15 text-amber-700 ring-1 ring-inset ring-amber-500/25 dark:text-amber-300'
|
||||
return 'bg-muted text-muted-foreground'
|
||||
}
|
||||
|
||||
// 全部检测:后端单次最多 20 套,前端分批要
|
||||
async function checkAll() {
|
||||
if (!identityProfile.value || checking.value) return
|
||||
async function checkKeys(keys: string[]) {
|
||||
if (!keys.length) return
|
||||
checking.value = true
|
||||
const total = identities.value.length
|
||||
try {
|
||||
for (let from = 1; from <= total; from += 20) {
|
||||
const to = Math.min(from + 19, total)
|
||||
const data: any = await api.get(`/dev/sign-profiles/${identityProfile.value.id}/identities?check=range&from=${from}&to=${to}`)
|
||||
for (const item of data?.items || []) {
|
||||
const row = identities.value.find((it: any) => it.index === item.index)
|
||||
for (let i = 0; i < keys.length; i += 20) {
|
||||
const batch = keys.slice(i, i + 20)
|
||||
const data: any = await api.post('/dev/sign-profiles/identities-check', { keys: batch })
|
||||
for (const it of data?.items || []) {
|
||||
const row = rows.value.find(r => r.key === it.key)
|
||||
if (row) {
|
||||
row.revoke = item.revoke
|
||||
row.ban = item.ban
|
||||
row.revoke = it.revoke
|
||||
row.ban = it.ban
|
||||
}
|
||||
}
|
||||
checkDone.value = identities.value.filter((it: any) => it.revoke).length
|
||||
checkDone.value = rows.value.filter(r => r.revoke).length
|
||||
}
|
||||
}
|
||||
catch (e: any) {
|
||||
toast.error(e?.message || '检测失败')
|
||||
toast.error(e.message || t('admin.signProfiles.checkFailed'))
|
||||
}
|
||||
finally {
|
||||
checking.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 状态文案
|
||||
function stateText(info: any) {
|
||||
if (!info) return t('admin.signProfiles.notChecked')
|
||||
if (info.status === 'good') return t('admin.signProfiles.revokeGood')
|
||||
if (info.status === 'revoked') return (info.reason || '') || t('admin.signProfiles.revokeBad')
|
||||
if (info.status === 'unknown') return t('admin.signProfiles.revokeUnknown')
|
||||
return t('admin.signProfiles.notChecked')
|
||||
function checkOne(row: FlatIdentity) {
|
||||
return checkKeys([row.key])
|
||||
}
|
||||
|
||||
function stateClass(info: any) {
|
||||
if (!info) return 'text-muted-foreground'
|
||||
if (info.status === 'good') return 'text-emerald-600 dark:text-emerald-400'
|
||||
if (info.status === 'revoked') return 'text-red-600 dark:text-red-400'
|
||||
if (info.status === 'unknown') return 'text-amber-600 dark:text-amber-400'
|
||||
return 'text-muted-foreground'
|
||||
}
|
||||
|
||||
// 勾选 / 全选 / 反选
|
||||
function toggleAll(on: boolean) {
|
||||
selected.value = on ? identities.value.map((i: any) => i.index) : []
|
||||
function checkAll() {
|
||||
return checkKeys(rows.value.map(r => r.key))
|
||||
}
|
||||
|
||||
async function exportSelected() {
|
||||
if (!identityProfile.value) return
|
||||
const targets = selected.value.length ? selected.value : identities.value.map((i: any) => i.index)
|
||||
if (!targets.length) {
|
||||
const keys = selected.value.length ? [...selected.value] : rows.value.map(r => r.key)
|
||||
if (!keys.length) {
|
||||
toast.error(t('admin.signProfiles.nothingToExport'))
|
||||
return
|
||||
}
|
||||
@@ -131,58 +128,66 @@ async function exportSelected() {
|
||||
toast.error(t('admin.signProfiles.exportPwdHint'))
|
||||
return
|
||||
}
|
||||
// 导出接口按「来源文件」打包,跨文件选中就分成几个 zip 依次下载
|
||||
const byProfile = new Map<number, number[]>()
|
||||
for (const k of keys) {
|
||||
const [pid, idx] = k.split(':').map(Number)
|
||||
if (!byProfile.has(pid)) byProfile.set(pid, [])
|
||||
byProfile.get(pid)!.push(idx)
|
||||
}
|
||||
exporting.value = true
|
||||
let exported = 0
|
||||
try {
|
||||
const token = localStorage.getItem('token') || ''
|
||||
const resp = await fetch(`${BASE_URL}/dev/sign-profiles/${identityProfile.value.id}/export`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
|
||||
body: JSON.stringify({
|
||||
identities: targets,
|
||||
all: targets.length === identities.value.length,
|
||||
password: exportPassword.value,
|
||||
skip_revoked: exportSkipRevoked.value,
|
||||
check_revoked: true,
|
||||
}),
|
||||
})
|
||||
if (!resp.ok) {
|
||||
let msg = '导出失败'
|
||||
try {
|
||||
const j = await resp.json()
|
||||
msg = j.message || msg
|
||||
for (const [pid, idxs] of byProfile) {
|
||||
const token = localStorage.getItem('token') || ''
|
||||
const resp = await fetch(`${BASE_URL}/dev/sign-profiles/${pid}/export`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
|
||||
body: JSON.stringify({
|
||||
identities: idxs,
|
||||
all: false,
|
||||
password: exportPassword.value,
|
||||
skip_revoked: exportSkipRevoked.value,
|
||||
check_revoked: true,
|
||||
}),
|
||||
})
|
||||
if (!resp.ok) {
|
||||
let msg = t('admin.signProfiles.exportFailed')
|
||||
try {
|
||||
const j = await resp.json()
|
||||
msg = j.message || msg
|
||||
}
|
||||
catch {}
|
||||
throw new Error(msg)
|
||||
}
|
||||
catch {}
|
||||
throw new Error(msg)
|
||||
const blob = await resp.blob()
|
||||
const url = URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
a.download = `证书导出_${pid}_${new Date().toISOString().slice(0, 10)}.zip`
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
a.remove()
|
||||
URL.revokeObjectURL(url)
|
||||
exported += idxs.length
|
||||
}
|
||||
const blob = await resp.blob()
|
||||
const url = URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
a.download = `证书身份导出_${new Date().toISOString().slice(0, 10)}.zip`
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
a.remove()
|
||||
URL.revokeObjectURL(url)
|
||||
toast.success(t('admin.signProfiles.exportDone', { n: targets.length }))
|
||||
toast.success(t('admin.signProfiles.exportDone', { n: exported }))
|
||||
}
|
||||
catch (e: any) {
|
||||
toast.error(e?.message || '导出失败')
|
||||
toast.error(e?.message || t('admin.signProfiles.exportFailed'))
|
||||
}
|
||||
finally {
|
||||
exporting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function cnOf(subject: string) {
|
||||
const sub = subject || ''
|
||||
return sub.split('CN=').pop()?.split(',')[0]?.trim() || sub
|
||||
}
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await api.get<{ items: SignProfile[] }>('/dev/sign-profiles')
|
||||
items.value = data?.items || []
|
||||
const data: any = await api.get(`/dev/sign-profiles/identities-flat?page=${page.value}&page_size=${pageSize.value}`)
|
||||
rows.value = (data?.items || []).map((it: any) => ({ ...it, revoke: null, ban: null }))
|
||||
total.value = data?.total || 0
|
||||
selected.value = []
|
||||
}
|
||||
catch (e: any) {
|
||||
toast.error(e.message || t('admin.signProfiles.loadFailed'))
|
||||
@@ -233,18 +238,9 @@ async function submit() {
|
||||
if (form.value.platform === 'ios' && profileFile.value)
|
||||
fd.append('profile', profileFile.value)
|
||||
|
||||
// 一个 pfx 里可能含多套「私钥+证书」,后端会按套拆成多条记录,
|
||||
// 这里要说清楚拆出了几条,否则用户只看到列表多了一堆名字相近的条目
|
||||
// 一个 pfx 里可能含几十套「私钥+证书」,后端解析出全部身份,列表逐套展示
|
||||
const resp: any = await api.postFormData('/dev/sign-profiles', fd)
|
||||
const items = resp?.data?.items || []
|
||||
if (items.length > 1) {
|
||||
toast.success(t('admin.signProfiles.uploadedSplit', { n: items.length }), {
|
||||
description: items.map((i: any) => `第${items.indexOf(i) + 1}套 ${i.subject}`).join(' / '),
|
||||
})
|
||||
}
|
||||
else {
|
||||
toast.success(t('admin.signProfiles.uploaded'))
|
||||
}
|
||||
toast.success(t('admin.signProfiles.uploadedWithCount', { n: resp?.key_count || 1 }))
|
||||
form.value.password = ''
|
||||
certFile.value = null
|
||||
profileFile.value = null
|
||||
@@ -268,19 +264,20 @@ async function submit() {
|
||||
|
||||
const pendingDelete = ref<number | null>(null)
|
||||
|
||||
async function remove(item: SignProfile) {
|
||||
if (pendingDelete.value !== item.id) {
|
||||
pendingDelete.value = item.id
|
||||
toast.warning(t('admin.signProfiles.confirmDelete', { name: item.name }))
|
||||
async function removeProfile(row: FlatIdentity) {
|
||||
const pid = row.profile_id
|
||||
if (pendingDelete.value !== pid) {
|
||||
pendingDelete.value = pid
|
||||
toast.warning(t('admin.signProfiles.confirmDeleteFile', { name: row.profile_name }))
|
||||
window.setTimeout(() => {
|
||||
if (pendingDelete.value === item.id)
|
||||
if (pendingDelete.value === pid)
|
||||
pendingDelete.value = null
|
||||
}, 4000)
|
||||
return
|
||||
}
|
||||
pendingDelete.value = null
|
||||
try {
|
||||
await api.delete(`/dev/sign-profiles/${item.id}`)
|
||||
await api.delete(`/dev/sign-profiles/${pid}`)
|
||||
toast.success(t('admin.signProfiles.deleted'))
|
||||
await load()
|
||||
}
|
||||
@@ -289,14 +286,6 @@ async function remove(item: SignProfile) {
|
||||
}
|
||||
}
|
||||
|
||||
function platformLabel(p: string) {
|
||||
return p === 'ios' ? 'iOS' : 'Windows'
|
||||
}
|
||||
|
||||
function formatTime(v: string | null) {
|
||||
return v ? new Date(v).toLocaleString() : '-'
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
@@ -408,148 +397,131 @@ onMounted(load)
|
||||
</UiCardContent>
|
||||
</UiCard>
|
||||
|
||||
<!-- 列表 -->
|
||||
<!-- 证书列表:一行就是一套证书身份 -->
|
||||
<UiCard>
|
||||
<UiCardHeader>
|
||||
<UiCardTitle class="text-base">
|
||||
{{ t('admin.signProfiles.list') }}
|
||||
{{ t('admin.signProfiles.flatListTitle') }}
|
||||
</UiCardTitle>
|
||||
<p class="text-sm text-muted-foreground">
|
||||
{{ t('admin.signProfiles.flatListHint', { total }) }}
|
||||
</p>
|
||||
</UiCardHeader>
|
||||
<UiCardContent>
|
||||
<SignProfileDataTable
|
||||
:data="items"
|
||||
:loading="loading"
|
||||
:platform-label="platformLabel"
|
||||
:format-time="formatTime"
|
||||
:pending-delete-id="pendingDelete"
|
||||
:on-delete="remove"
|
||||
:on-identities="openIdentities"
|
||||
@refresh="load"
|
||||
/>
|
||||
<UiCardContent class="space-y-3">
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<UiButton size="sm" variant="outline" @click="toggleAll(!allSelected)">
|
||||
{{ allSelected ? t('admin.signProfiles.unselectAll') : t('admin.signProfiles.selectAll') }}
|
||||
</UiButton>
|
||||
<span class="text-xs text-muted-foreground">{{ t('admin.signProfiles.selectedCount', { n: selected.length }) }}</span>
|
||||
<UiButton size="sm" variant="outline" :disabled="checking || loading" @click="checkAll">
|
||||
<Loader2 v-if="checking" class="mr-1.5 h-3.5 w-3.5 animate-spin" />
|
||||
{{ checking ? t('admin.signProfiles.checking') : t('admin.signProfiles.checkPage') }}
|
||||
</UiButton>
|
||||
<span class="text-xs text-muted-foreground">{{ t('admin.signProfiles.checkProgress', { done: checkDone, total: rows.length }) }}</span>
|
||||
<div class="mx-1 hidden h-5 w-px bg-border sm:block" />
|
||||
<UiInput v-model="exportPassword" type="password" class="h-8 w-40"
|
||||
:placeholder="t('admin.signProfiles.exportPwd')" />
|
||||
<label class="flex items-center gap-1 text-xs text-muted-foreground">
|
||||
<input v-model="exportSkipRevoked" type="checkbox" class="h-3.5 w-3.5">
|
||||
{{ t('admin.signProfiles.exportSkipRevoked') }}
|
||||
</label>
|
||||
<UiButton size="sm" :disabled="exporting || loading" @click="exportSelected">
|
||||
<Loader2 v-if="exporting" class="mr-1.5 h-3.5 w-3.5 animate-spin" />
|
||||
{{ exporting ? t('admin.signProfiles.exporting') : t('admin.signProfiles.exportSelected') }}
|
||||
</UiButton>
|
||||
</div>
|
||||
|
||||
<div class="overflow-auto rounded-md border">
|
||||
<table class="w-full text-sm">
|
||||
<thead class="sticky top-0 z-10 border-b bg-muted/95 backdrop-blur">
|
||||
<tr class="text-left text-xs font-semibold tracking-wide text-foreground/70 uppercase">
|
||||
<th class="w-8 px-2 py-2">
|
||||
<input type="checkbox" class="h-3.5 w-3.5" :checked="allSelected" @change="toggleAll(($event.target as HTMLInputElement).checked)">
|
||||
</th>
|
||||
<th class="px-2 py-2">{{ t('admin.signProfiles.colCertName') }}</th>
|
||||
<th class="px-2 py-2">{{ t('admin.signProfiles.colSource') }}</th>
|
||||
<th class="px-2 py-2">{{ t('admin.signProfiles.colExpiry') }}</th>
|
||||
<th class="px-2 py-2">{{ t('admin.signProfiles.colExpired') }}</th>
|
||||
<th class="px-2 py-2">{{ t('admin.signProfiles.colUsage') }}</th>
|
||||
<th class="px-2 py-2">{{ t('admin.signProfiles.colRevoke') }}</th>
|
||||
<th class="px-2 py-2">{{ t('admin.signProfiles.colBan') }}</th>
|
||||
<th class="px-2 py-2 text-right">{{ t('admin.signProfiles.colActions') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="row in rows" :key="row.key" class="border-t" :class="{ 'bg-muted/30': selected.includes(row.key) }">
|
||||
<td class="px-2 py-1.5">
|
||||
<input v-model="selected" type="checkbox" :value="row.key" class="h-3.5 w-3.5">
|
||||
</td>
|
||||
<td class="px-2 py-1.5">
|
||||
<div class="flex items-center gap-2">
|
||||
<ShieldCheck class="h-4 w-4 shrink-0 text-emerald-600 dark:text-emerald-400" />
|
||||
<span class="max-w-[300px] truncate font-medium" :title="row.subject">{{ row.cn || '-' }}</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-2 py-1.5">
|
||||
<span class="text-xs text-muted-foreground">{{ row.profile_name }}</span>
|
||||
<span v-if="row.has_cross" class="ml-1 rounded bg-emerald-500/10 px-1 text-[10px] text-emerald-600 dark:text-emerald-400">交叉证书</span>
|
||||
</td>
|
||||
<td class="px-2 py-1.5 text-xs">{{ row.not_after || '-' }}</td>
|
||||
<td class="px-2 py-1.5 text-xs">
|
||||
<span :class="row.expired ? 'text-amber-600 dark:text-amber-400' : 'text-muted-foreground'">
|
||||
{{ row.expired ? t('admin.signProfiles.yes') : t('admin.signProfiles.no') }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-2 py-1.5 text-xs">{{ row.usage_label || '-' }}</td>
|
||||
<td class="px-2 py-1.5 text-xs" :title="row.revoke?.detail">
|
||||
<span class="inline-block rounded px-1.5 py-0.5" :class="stateClass(row.revoke)">{{ stateText(row.revoke) }}</span>
|
||||
</td>
|
||||
<td class="px-2 py-1.5 text-xs" :title="row.ban?.detail">
|
||||
<span class="inline-block rounded px-1.5 py-0.5" :class="stateClass(row.ban)">{{ stateText(row.ban) }}</span>
|
||||
</td>
|
||||
<td class="px-2 py-1.5">
|
||||
<div class="flex items-center justify-end gap-1">
|
||||
<UiButton variant="outline" size="sm" class="h-7 px-2 text-xs" :disabled="checking" @click="checkOne(row)">
|
||||
{{ t('admin.signProfiles.checkOne') }}
|
||||
</UiButton>
|
||||
<UiButton
|
||||
variant="ghost" size="sm" class="h-7 px-1"
|
||||
:class="pendingDelete === row.profile_id ? 'text-destructive' : 'text-muted-foreground'"
|
||||
:title="t('admin.signProfiles.deleteFile')"
|
||||
@click="removeProfile(row)"
|
||||
>
|
||||
<Trash2 class="h-4 w-4" />
|
||||
</UiButton>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="loading">
|
||||
<td colspan="9" class="px-2 py-8 text-center text-xs text-muted-foreground">
|
||||
<Loader2 class="mx-auto mb-2 h-4 w-4 animate-spin" />
|
||||
{{ t('admin.signProfiles.checking') }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-else-if="!rows.length">
|
||||
<td colspan="9" class="px-2 py-8 text-center text-xs text-muted-foreground">
|
||||
{{ t('admin.signProfiles.emptyList') }}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-xs text-muted-foreground">
|
||||
{{ t('admin.signProfiles.pageInfo', { page, pages: pageCount, total }) }}
|
||||
</span>
|
||||
<div class="flex items-center gap-1">
|
||||
<UiButton variant="outline" size="sm" :disabled="page <= 1 || loading" @click="gotoPage(page - 1)">
|
||||
{{ t('admin.signProfiles.prevPage') }}
|
||||
</UiButton>
|
||||
<UiButton variant="outline" size="sm" :disabled="page >= pageCount || loading" @click="gotoPage(page + 1)">
|
||||
{{ t('admin.signProfiles.nextPage') }}
|
||||
</UiButton>
|
||||
</div>
|
||||
</div>
|
||||
</UiCardContent>
|
||||
</UiCard>
|
||||
</div>
|
||||
|
||||
<!-- 一个 pfx 里的所有身份:列表展示,含过期 / 吊销 / 拉黑状态 -->
|
||||
<UiDialog v-model:open="identityDialog">
|
||||
<UiDialogContent class="sm:max-w-4xl">
|
||||
<UiDialogHeader>
|
||||
<UiDialogTitle>
|
||||
{{ t('admin.signProfiles.identitiesTitle') }} · {{ identityProfile?.name }}
|
||||
</UiDialogTitle>
|
||||
<UiDialogDescription>
|
||||
{{ t('admin.signProfiles.identitiesHint') }}
|
||||
</UiDialogDescription>
|
||||
</UiDialogHeader>
|
||||
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<UiButton size="sm" variant="outline" @click="toggleAll(selected.length !== identities.length)">
|
||||
{{ selected.length === identities.length && identities.length ? t('admin.signProfiles.unselectAll') : t('admin.signProfiles.selectAll') }}
|
||||
</UiButton>
|
||||
<span class="text-xs text-muted-foreground">{{ t('admin.signProfiles.selectedCount', { n: selected.length }) }}</span>
|
||||
<UiButton size="sm" :disabled="checking || identityLoading" @click="checkAll">
|
||||
<Loader2 v-if="checking" class="mr-1.5 h-3.5 w-3.5 animate-spin" />
|
||||
{{ checking ? t('admin.signProfiles.checking') : t('admin.signProfiles.checkAll') }}
|
||||
</UiButton>
|
||||
<span class="text-xs text-muted-foreground">
|
||||
{{ t('admin.signProfiles.checkProgress', { done: checkDone, total: identities.length }) }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- 批量导出:带密码导出成 zip(每个 pfx 一套身份) -->
|
||||
<div class="flex flex-wrap items-center gap-2 rounded-md border bg-muted/30 p-2">
|
||||
<span class="text-xs font-medium">{{ t('admin.signProfiles.exportTitle') }}</span>
|
||||
<UiInput v-model="exportPassword" type="password" class="h-8 w-44"
|
||||
:placeholder="t('admin.signProfiles.exportPwd')" />
|
||||
<label class="flex items-center gap-1 text-xs text-muted-foreground">
|
||||
<input v-model="exportSkipRevoked" type="checkbox" class="h-3.5 w-3.5">
|
||||
{{ t('admin.signProfiles.exportSkipRevoked') }}
|
||||
</label>
|
||||
<UiButton size="sm" :disabled="exporting || identityLoading" @click="exportSelected">
|
||||
<Loader2 v-if="exporting" class="mr-1.5 h-3.5 w-3.5 animate-spin" />
|
||||
{{ exporting ? t('admin.signProfiles.exporting') : t('admin.signProfiles.exportSelected') }}
|
||||
</UiButton>
|
||||
<span class="text-xs text-muted-foreground">{{ t('admin.signProfiles.exportHint') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="max-h-[60vh] overflow-auto rounded-md border">
|
||||
<table class="w-full text-sm">
|
||||
<thead class="sticky top-0 bg-muted/80 backdrop-blur">
|
||||
<tr class="text-left text-xs text-muted-foreground">
|
||||
<th class="w-8 px-2 py-2">
|
||||
<input type="checkbox" class="h-3.5 w-3.5"
|
||||
:checked="identities.length > 0 && selected.length === identities.length"
|
||||
@change="toggleAll(($event.target as HTMLInputElement).checked)">
|
||||
</th>
|
||||
<th class="px-2 py-2">
|
||||
{{ t('admin.signProfiles.colIndex') }}
|
||||
</th>
|
||||
<th class="px-2 py-2">
|
||||
{{ t('admin.signProfiles.colCertName') }}
|
||||
</th>
|
||||
<th class="px-2 py-2">
|
||||
{{ t('admin.signProfiles.colExpiry') }}
|
||||
</th>
|
||||
<th class="px-2 py-2">
|
||||
{{ t('admin.signProfiles.colExpired') }}
|
||||
</th>
|
||||
<th class="px-2 py-2">
|
||||
{{ t('admin.signProfiles.colUsage') }}
|
||||
</th>
|
||||
<th class="px-2 py-2">
|
||||
{{ t('admin.signProfiles.colRevoke') }}
|
||||
</th>
|
||||
<th class="px-2 py-2">
|
||||
{{ t('admin.signProfiles.colBan') }}
|
||||
</th>
|
||||
<th class="px-2 py-2 text-right">
|
||||
{{ t('admin.signProfiles.colActions') }}
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="it in identities" :key="it.index" class="border-t" :class="{ 'bg-muted/30': selected.includes(it.index) }">
|
||||
<td class="px-2 py-1.5">
|
||||
<input v-model="selected" type="checkbox" :value="it.index" class="h-3.5 w-3.5">
|
||||
</td>
|
||||
<td class="px-2 py-1.5 font-mono text-xs text-muted-foreground">
|
||||
{{ it.index }}
|
||||
</td>
|
||||
<td class="max-w-[300px] truncate px-2 py-1.5" :title="it.subject">
|
||||
{{ cnOf(it.subject) }}
|
||||
</td>
|
||||
<td class="px-2 py-1.5 text-xs">
|
||||
{{ String(it.not_after).slice(0, 10) }}
|
||||
</td>
|
||||
<td class="px-2 py-1.5 text-xs">
|
||||
<span :class="it.expired ? 'text-amber-600 dark:text-amber-400' : 'text-muted-foreground'">
|
||||
{{ it.expired ? t('admin.signProfiles.yes') : t('admin.signProfiles.no') }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-2 py-1.5 text-xs">
|
||||
{{ it.usage?.label || '-' }}
|
||||
</td>
|
||||
<td class="px-2 py-1.5 text-xs" :class="stateClass(it.revoke)" :title="it.revoke?.detail">
|
||||
{{ stateText(it.revoke) }}
|
||||
</td>
|
||||
<td class="px-2 py-1.5 text-xs" :class="stateClass(it.ban)" :title="it.ban?.detail">
|
||||
{{ stateText(it.ban) }}
|
||||
</td>
|
||||
<td class="px-2 py-1.5 text-right">
|
||||
<UiButton variant="outline" size="sm" class="h-7 px-2 text-xs" :disabled="checking" @click="checkOne(it.index)">
|
||||
{{ t('admin.signProfiles.checkOne') }}
|
||||
</UiButton>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="identityLoading">
|
||||
<td colspan="9" class="px-2 py-6 text-center text-xs text-muted-foreground">
|
||||
{{ t('admin.signProfiles.checking') }}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</UiDialogContent>
|
||||
</UiDialog>
|
||||
</BasicPage>
|
||||
</template>
|
||||
|
||||
@@ -2732,7 +2732,20 @@
|
||||
"exportDone": "Exported {n} certificates",
|
||||
"exportHint": "Each pfx holds one identity; filenames carry index + CN",
|
||||
"exportPwdHint": "Password must be at least 4 characters",
|
||||
"nothingToExport": "Nothing to export"
|
||||
"nothingToExport": "Nothing to export",
|
||||
"flatListTitle": "Certificates (one per row)",
|
||||
"flatListHint": "{total} certificates, one per row; select to check revocation/blacklist or export",
|
||||
"colSource": "Source file",
|
||||
"checkPage": "Check this page",
|
||||
"deleteFile": "Delete whole certificate file",
|
||||
"emptyList": "No certificates yet — upload a pfx above",
|
||||
"pageInfo": "Page {page}/{pages} · {total} total",
|
||||
"prevPage": "Prev",
|
||||
"nextPage": "Next",
|
||||
"uploadedWithCount": "Parsed {n} certificates",
|
||||
"confirmDeleteFile": "Click again to delete the whole file: {name}",
|
||||
"checkFailed": "Check failed",
|
||||
"exportFailed": "Export failed"
|
||||
}
|
||||
},
|
||||
"auth": {
|
||||
|
||||
@@ -2751,7 +2751,20 @@
|
||||
"exportDone": "已导出 {n} 套证书",
|
||||
"exportHint": "每个 pfx 只含一套私钥+证书,文件名带序号和 CN",
|
||||
"exportPwdHint": "导出密码至少 4 位(pfx 必须有口令)",
|
||||
"nothingToExport": "没有可导出的身份"
|
||||
"nothingToExport": "没有可导出的身份",
|
||||
"flatListTitle": "证书列表(每行一套证书)",
|
||||
"flatListHint": "共 {total} 套证书,一行一套,可直接勾选检测吊销/拉黑或批量导出",
|
||||
"colSource": "来源文件",
|
||||
"checkPage": "检测本页",
|
||||
"deleteFile": "删除整个证书文件",
|
||||
"emptyList": "还没有证书,先在上方上传 pfx",
|
||||
"pageInfo": "第 {page}/{pages} 页 · 共 {total} 套",
|
||||
"prevPage": "上一页",
|
||||
"nextPage": "下一页",
|
||||
"uploadedWithCount": "已解析 {n} 套证书",
|
||||
"confirmDeleteFile": "再点一次删除整个文件:{name}",
|
||||
"checkFailed": "检测失败",
|
||||
"exportFailed": "导出失败"
|
||||
}
|
||||
},
|
||||
"auth": {
|
||||
|
||||
Reference in New Issue
Block a user