This commit is contained in:
ZhuoQinghui 2024-10-31 14:36:31 +08:00
parent a1defc9aff
commit 7a60ce0651

View File

@ -26,7 +26,7 @@ func OnCommand() {
case "edit": case "edit":
editConf() editConf()
case "get": case "get":
getCert() onGet()
case "-s": case "-s":
onServerCommand() onServerCommand()
default: default:
@ -43,6 +43,8 @@ func showHelp() {
fmt.Printf("edit\t修改配置\n") fmt.Printf("edit\t修改配置\n")
fmt.Printf("get\t从获取端获取证书,会自动判断有效期\n") fmt.Printf("get\t从获取端获取证书,会自动判断有效期\n")
fmt.Printf("\t[-f]\t从获取端获取证书,不判断有效期\n") fmt.Printf("\t[-f]\t从获取端获取证书,不判断有效期\n")
fmt.Printf("get all\t从获取端获取证书,会自动判断有效期\n")
fmt.Printf("\t[-f]\t从获取端获取证书,不判断有效期\n")
fmt.Printf("-s list\t查看服务端已配置的Domain名称\n") fmt.Printf("-s list\t查看服务端已配置的Domain名称\n")
} }
@ -108,12 +110,55 @@ func editConf() {
showList() showList()
} }
func getCert() { func onGet() {
fmt.Println("当前配置") fmt.Println("当前配置")
showList() showList()
_, domain := selectDomain("请选择要获取证书的配置编号")
args := os.Args args := os.Args
isDoGet := len(args) >= 3 && args[3] == "-f" if len(args) < 3 {
_, domain := selectDomain("请选择要获取证书的配置编号")
getCert(domain, false)
return
}
if args[2] == "all" {
getCertAll()
return
}
if args[2] == "-f" {
_, domain := selectDomain("请选择要获取证书的配置编号")
getCert(domain, true)
return
}
fmt.Printf("参数错误, get指令不支持 %s 参数\n", args[3])
}
func getCertAll() {
args := os.Args
isForce := false
if len(args) < 4 {
isForce = false
} else {
if args[3] == "-f" {
isForce = true
}
}
msg := "获取所有已配置的证书"
if isForce {
msg = "强制" + msg
}
log.Println(msg)
for _, domain := range GetClientConfig().Domains {
getCert(&domain, isForce)
}
}
func getCert(domain *Domain, isForceGet bool) {
msg := "开始获取 %s 的证书信息."
if isForceGet {
msg = msg + " 不校验本地证书信息,直接获取."
}
log.Printf(msg, domain.Name)
isDoGet := isForceGet
certFile := domain.CertFile certFile := domain.CertFile
keyFile := domain.KeyFile keyFile := domain.KeyFile