优化DNS解析逻辑

This commit is contained in:
2025-03-13 17:53:08 +08:00
parent d3b7020065
commit cfcc696bda
7 changed files with 579 additions and 126 deletions

View File

@@ -1,16 +1,12 @@
# PowerShell 脚本:生成自签名证书
# 默认值
$Days = 365
$Subject = "CN=localhost,OU=Test,O=GoProxy,L=Shanghai,S=Shanghai,C=CN"
# 处理命令行参数
param(
[Parameter(HelpMessage="证书有效期(天数)")]
[int]$days = 365,
[Parameter(HelpMessage="证书主题")]
[string]$subject = $Subject,
[string]$subject = "CN=localhost,OU=Test,O=GoProxy,L=Shanghai,S=Shanghai,C=CN",
[Parameter(HelpMessage="公用名(CN)")]
[string]$cn = "",
@@ -28,7 +24,7 @@ function Show-Help {
Write-Host "选项:"
Write-Host " -help 显示此帮助信息"
Write-Host " -days DAYS 证书有效期(天数),默认: 365"
Write-Host " -subject SUB 证书主题,默认: $Subject"
Write-Host " -subject SUB 证书主题,默认: $subject"
Write-Host " -cn CN 公用名(CN)将替换主题中的CN默认: localhost"
Write-Host
Write-Host "示例:"
@@ -44,12 +40,12 @@ if ($help) {
# 如果指定了CN替换主题中的CN部分
if ($cn -ne "") {
$Subject = $Subject -replace "CN=[^,]*", "CN=$cn"
$subject = $subject -replace "CN=[^,]*", "CN=$cn"
}
Write-Host "生成自签名证书..."
Write-Host "有效期: $days"
Write-Host "主题: $Subject"
Write-Host "主题: $subject"
# 检查OpenSSL是否可用
$openssl = Get-Command "openssl" -ErrorAction SilentlyContinue
@@ -66,7 +62,7 @@ try {
# 生成证书请求
Write-Host "正在生成证书请求..." -ForegroundColor Cyan
& openssl req -new -key server.key -out server.csr -subj $Subject.Replace(",", "/")
& openssl req -new -key server.key -out server.csr -subj $subject.Replace(",", "/")
# 生成自签名证书
Write-Host "正在生成自签名证书..." -ForegroundColor Cyan
@@ -85,4 +81,4 @@ try {
catch {
Write-Host "错误: 生成证书时发生错误: $_" -ForegroundColor Red
exit 1
}
}