移除自动DNS记录验证方式 (#141)
Co-authored-by: jinnrry <jinnrry@users.noreply.github.com>
This commit is contained in:
1 parent
01cbdc9875
commit
056036e880
10 files changed
+155
-2639
No files matched your search
@@ -1,67 +1,67 @@
|
||||
package ssl
|
||||
|
||||
import (
|
||||
"github.com/go-acme/lego/v4/providers/dns"
|
||||
"os"
|
||||
"pmail/utils/errors"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetServerParamsList(serverName string) ([]string, error) {
|
||||
var serverParams []string
|
||||
|
||||
infos, err := os.ReadDir("./")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err)
|
||||
}
|
||||
|
||||
upperServerName := strings.ToUpper(serverName)
|
||||
|
||||
for _, info := range infos {
|
||||
if strings.HasPrefix(info.Name(), upperServerName) {
|
||||
serverParams = append(serverParams, info.Name())
|
||||
}
|
||||
}
|
||||
if len(serverParams) != 0 {
|
||||
return serverParams, nil
|
||||
}
|
||||
|
||||
_, err = dns.NewDNSChallengeProviderByName(serverName)
|
||||
if err == nil {
|
||||
return nil, errors.New(serverName + " Not Support")
|
||||
}
|
||||
if strings.Contains(err.Error(), "unrecognized DNS provider") {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
re := regexp.MustCompile(`missing: (.+)`)
|
||||
// namesilo: some credentials information are missing: NAMESILO_API_KEY
|
||||
estr := err.Error()
|
||||
name := re.FindStringSubmatch(estr)
|
||||
|
||||
if len(name) == 2 {
|
||||
names := strings.Split(name[1], ",")
|
||||
|
||||
for _, s := range names {
|
||||
serverParams = append(serverParams, s)
|
||||
SetDomainServerParams(s, "empty")
|
||||
}
|
||||
|
||||
}
|
||||
_, err = dns.NewDNSChallengeProviderByName(serverName)
|
||||
|
||||
return serverParams, err
|
||||
}
|
||||
|
||||
func SetDomainServerParams(name, value string) {
|
||||
key := name
|
||||
err := os.WriteFile(key, []byte(value), 0644)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = os.Setenv(name+"_FILE", key)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
//import (
|
||||
// "github.com/go-acme/lego/v4/providers/dns"
|
||||
// "os"
|
||||
// "pmail/utils/errors"
|
||||
// "regexp"
|
||||
// "strings"
|
||||
//)
|
||||
//
|
||||
//func GetServerParamsList(serverName string) ([]string, error) {
|
||||
// var serverParams []string
|
||||
//
|
||||
// infos, err := os.ReadDir("./")
|
||||
// if err != nil {
|
||||
// return nil, errors.Wrap(err)
|
||||
// }
|
||||
//
|
||||
// upperServerName := strings.ToUpper(serverName)
|
||||
//
|
||||
// for _, info := range infos {
|
||||
// if strings.HasPrefix(info.Name(), upperServerName) {
|
||||
// serverParams = append(serverParams, info.Name())
|
||||
// }
|
||||
// }
|
||||
// if len(serverParams) != 0 {
|
||||
// return serverParams, nil
|
||||
// }
|
||||
//
|
||||
// _, err = dns.NewDNSChallengeProviderByName(serverName)
|
||||
// if err == nil {
|
||||
// return nil, errors.New(serverName + " Not Support")
|
||||
// }
|
||||
// if strings.Contains(err.Error(), "unrecognized DNS provider") {
|
||||
// return nil, err
|
||||
// }
|
||||
//
|
||||
// re := regexp.MustCompile(`missing: (.+)`)
|
||||
// // namesilo: some credentials information are missing: NAMESILO_API_KEY
|
||||
// estr := err.Error()
|
||||
// name := re.FindStringSubmatch(estr)
|
||||
//
|
||||
// if len(name) == 2 {
|
||||
// names := strings.Split(name[1], ",")
|
||||
//
|
||||
// for _, s := range names {
|
||||
// serverParams = append(serverParams, s)
|
||||
// SetDomainServerParams(s, "empty")
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// _, err = dns.NewDNSChallengeProviderByName(serverName)
|
||||
//
|
||||
// return serverParams, err
|
||||
//}
|
||||
//
|
||||
//func SetDomainServerParams(name, value string) {
|
||||
// key := name
|
||||
// err := os.WriteFile(key, []byte(value), 0644)
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// err = os.Setenv(name+"_FILE", key)
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
//}
|
||||
@@ -1,36 +1,37 @@
|
||||
package ssl
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetServerParamsList(t *testing.T) {
|
||||
type args struct {
|
||||
serverName string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []string
|
||||
wantErr bool
|
||||
}{
|
||||
{name: "namesilo", args: args{serverName: "namesilo"}, want: []string{"NAMESILO_API_KEY"}, wantErr: false},
|
||||
{name: "namesiloAgain", args: args{serverName: "namesilo"}, want: []string{"NAMESILO_API_KEY"}, wantErr: false},
|
||||
{name: "auroradns", args: args{serverName: "auroradns"}, want: []string{"AURORA_API_KEY", "AURORA_SECRET"}, wantErr: false},
|
||||
{name: "alidns", args: args{serverName: "alidns"}, want: []string{"ALICLOUD_ACCESS_KEY", "ALICLOUD_SECRET_KEY"}, wantErr: false},
|
||||
{name: "null", args: args{serverName: "null"}, want: nil, wantErr: true},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := GetServerParamsList(tt.args.serverName)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("GetServerParamsList() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("GetServerParamsList() got = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
//
|
||||
//import (
|
||||
// "reflect"
|
||||
// "testing"
|
||||
//)
|
||||
//
|
||||
//func TestGetServerParamsList(t *testing.T) {
|
||||
// type args struct {
|
||||
// serverName string
|
||||
// }
|
||||
// tests := []struct {
|
||||
// name string
|
||||
// args args
|
||||
// want []string
|
||||
// wantErr bool
|
||||
// }{
|
||||
// {name: "namesilo", args: args{serverName: "namesilo"}, want: []string{"NAMESILO_API_KEY"}, wantErr: false},
|
||||
// {name: "namesiloAgain", args: args{serverName: "namesilo"}, want: []string{"NAMESILO_API_KEY"}, wantErr: false},
|
||||
// {name: "auroradns", args: args{serverName: "auroradns"}, want: []string{"AURORA_API_KEY", "AURORA_SECRET"}, wantErr: false},
|
||||
// {name: "alidns", args: args{serverName: "alidns"}, want: []string{"ALICLOUD_ACCESS_KEY", "ALICLOUD_SECRET_KEY"}, wantErr: false},
|
||||
// {name: "null", args: args{serverName: "null"}, want: nil, wantErr: true},
|
||||
// }
|
||||
// for _, tt := range tests {
|
||||
// t.Run(tt.name, func(t *testing.T) {
|
||||
// got, err := GetServerParamsList(tt.args.serverName)
|
||||
// if (err != nil) != tt.wantErr {
|
||||
// t.Errorf("GetServerParamsList() error = %v, wantErr %v", err, tt.wantErr)
|
||||
// return
|
||||
// }
|
||||
// if !reflect.DeepEqual(got, tt.want) {
|
||||
// t.Errorf("GetServerParamsList() got = %v, want %v", got, tt.want)
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
//}
|
||||
@@ -8,8 +8,6 @@ import (
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"github.com/go-acme/lego/v4/certificate"
|
||||
"github.com/go-acme/lego/v4/challenge/dns01"
|
||||
"github.com/go-acme/lego/v4/providers/dns"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cast"
|
||||
"os"
|
||||
@@ -18,7 +16,6 @@ import (
|
||||
"pmail/signal"
|
||||
"pmail/utils/async"
|
||||
"pmail/utils/errors"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-acme/lego/v4/certcrypto"
|
||||
@@ -59,9 +56,10 @@ func SetSSL(sslType, priKey, crtKey, serviceName string) error {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if sslType == config.SSLTypeAutoHTTP || sslType == config.SSLTypeUser || sslType == config.SSLTypeAutoDNS {
|
||||
//if sslType == config.SSLTypeAutoHTTP || sslType == config.SSLTypeUser || sslType == config.SSLTypeAutoDNS {
|
||||
if sslType == config.SSLTypeAutoHTTP || sslType == config.SSLTypeUser {
|
||||
cfg.SSLType = sslType
|
||||
cfg.DomainServiceName = serviceName
|
||||
//cfg.DomainServiceName = serviceName
|
||||
} else {
|
||||
return errors.New("SSL Type Error!")
|
||||
}
|
||||
@@ -121,20 +119,21 @@ func GenSSL(update bool) error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err)
|
||||
}
|
||||
} else if cfg.SSLType == "2" {
|
||||
err = os.Setenv(strings.ToUpper(cfg.DomainServiceName)+"_PROPAGATION_TIMEOUT", "900")
|
||||
if err != nil {
|
||||
log.Errorf("Set ENV Variable Error: %s", err.Error())
|
||||
}
|
||||
dnspodProvider, err := dns.NewDNSChallengeProviderByName(cfg.DomainServiceName)
|
||||
if err != nil {
|
||||
return errors.Wrap(err)
|
||||
}
|
||||
err = client.Challenge.SetDNS01Provider(dnspodProvider, dns01.AddDNSTimeout(15*time.Minute))
|
||||
if err != nil {
|
||||
return errors.Wrap(err)
|
||||
}
|
||||
}
|
||||
//else if cfg.SSLType == "2" {
|
||||
// err = os.Setenv(strings.ToUpper(cfg.DomainServiceName)+"_PROPAGATION_TIMEOUT", "900")
|
||||
// if err != nil {
|
||||
// log.Errorf("Set ENV Variable Error: %s", err.Error())
|
||||
// }
|
||||
// dnspodProvider, err := dns.NewDNSChallengeProviderByName(cfg.DomainServiceName)
|
||||
// if err != nil {
|
||||
// return errors.Wrap(err)
|
||||
// }
|
||||
// err = client.Challenge.SetDNS01Provider(dnspodProvider, dns01.AddDNSTimeout(15*time.Minute))
|
||||
// if err != nil {
|
||||
// return errors.Wrap(err)
|
||||
// }
|
||||
//}
|
||||
|
||||
reg, err := client.Registration.Register(registration.RegisterOptions{TermsOfServiceAgreed: true})
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user