Browse Source

feat: support proxy settings from env #579

Jacky 8 months ago
parent
commit
390eabf3a0

+ 1 - 0
internal/analytic/node.go

@@ -84,6 +84,7 @@ func InitNode(env *model.Environment) (n *Node) {
 
 	client := http.Client{
 		Transport: &http.Transport{
+			Proxy:           http.ProxyFromEnvironment,
 			TLSClientConfig: &tls.Config{InsecureSkipVerify: settings.ServerSettings.InsecureSkipVerify},
 		},
 	}

+ 1 - 0
internal/cert/cert.go

@@ -64,6 +64,7 @@ func IssueCert(payload *ConfigPayload, logChan chan string, errChan chan error)
 	// Skip TLS check
 	if config.HTTPClient != nil {
 		config.HTTPClient.Transport = &http.Transport{
+			Proxy:           http.ProxyFromEnvironment,
 			TLSClientConfig: &tls.Config{InsecureSkipVerify: settings.ServerSettings.InsecureSkipVerify},
 		}
 	}

+ 3 - 2
internal/cert/sync.go

@@ -11,8 +11,8 @@ import (
 	"github.com/0xJacky/Nginx-UI/internal/notification"
 	"github.com/0xJacky/Nginx-UI/model"
 	"github.com/0xJacky/Nginx-UI/query"
-    "github.com/0xJacky/Nginx-UI/settings"
-    "github.com/go-acme/lego/v4/certcrypto"
+	"github.com/0xJacky/Nginx-UI/settings"
+	"github.com/go-acme/lego/v4/certcrypto"
 	"io"
 	"net/http"
 	"os"
@@ -90,6 +90,7 @@ type SyncNotificationPayload struct {
 func deploy(env *model.Environment, c *model.Cert, payloadBytes []byte) (err error) {
 	client := http.Client{
 		Transport: &http.Transport{
+			Proxy:           http.ProxyFromEnvironment,
 			TLSClientConfig: &tls.Config{InsecureSkipVerify: settings.ServerSettings.InsecureSkipVerify},
 		},
 	}

+ 8 - 3
internal/cert/tencent_cloud_dns_test.go

@@ -5,6 +5,7 @@ import (
 	"crypto/elliptic"
 	"crypto/rand"
 	"crypto/tls"
+	"github.com/0xJacky/Nginx-UI/model"
 	"github.com/0xJacky/Nginx-UI/settings"
 	"github.com/go-acme/lego/v4/certcrypto"
 	"github.com/go-acme/lego/v4/certificate"
@@ -28,9 +29,12 @@ func TestTencentCloudDNS(t *testing.T) {
 		return
 	}
 
-	myUser := User{
+	myUser := model.AcmeUser{
 		Email: settings.ServerSettings.Email,
-		Key:   privateKey,
+		Key: model.PrivateKey{
+			X: privateKey.PublicKey.X,
+			Y: privateKey.PublicKey.Y,
+		},
 	}
 
 	config := lego.NewConfig(&myUser)
@@ -43,6 +47,7 @@ func TestTencentCloudDNS(t *testing.T) {
 		config.CADirURL = settings.ServerSettings.CADir
 		if config.HTTPClient != nil {
 			config.HTTPClient.Transport = &http.Transport{
+				Proxy:           http.ProxyFromEnvironment,
 				TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
 			}
 		}
@@ -79,7 +84,7 @@ func TestTencentCloudDNS(t *testing.T) {
 		log.Println(err)
 		return
 	}
-	myUser.Registration = reg
+	myUser.Registration = *reg
 
 	request := certificate.ObtainRequest{
 		Domains: domain,

+ 1 - 0
internal/config/sync.go

@@ -124,6 +124,7 @@ type SyncNotificationPayload struct {
 func (p *SyncConfigPayload) deploy(env *model.Environment, c *model.Config, payloadBytes []byte) (err error) {
 	client := http.Client{
 		Transport: &http.Transport{
+			Proxy:           http.ProxyFromEnvironment,
 			TLSClientConfig: &tls.Config{InsecureSkipVerify: settings.ServerSettings.InsecureSkipVerify},
 		},
 	}

+ 3 - 2
internal/middleware/proxy.go

@@ -4,8 +4,8 @@ import (
 	"crypto/tls"
 	"github.com/0xJacky/Nginx-UI/internal/logger"
 	"github.com/0xJacky/Nginx-UI/query"
-    "github.com/0xJacky/Nginx-UI/settings"
-    "github.com/gin-gonic/gin"
+	"github.com/0xJacky/Nginx-UI/settings"
+	"github.com/gin-gonic/gin"
 	"github.com/spf13/cast"
 	"io"
 	"net/http"
@@ -59,6 +59,7 @@ func Proxy() gin.HandlerFunc {
 		logger.Debug("Proxy request", proxyUrl.String())
 		client := http.Client{
 			Transport: &http.Transport{
+				Proxy:           http.ProxyFromEnvironment,
 				TLSClientConfig: &tls.Config{InsecureSkipVerify: settings.ServerSettings.InsecureSkipVerify},
 			},
 		}

+ 3 - 2
model/acme_user.go

@@ -6,8 +6,8 @@ import (
 	"crypto/elliptic"
 	"crypto/rand"
 	"crypto/tls"
-    "github.com/0xJacky/Nginx-UI/settings"
-    "github.com/go-acme/lego/v4/lego"
+	"github.com/0xJacky/Nginx-UI/settings"
+	"github.com/go-acme/lego/v4/lego"
 	"github.com/go-acme/lego/v4/registration"
 	"math/big"
 	"net/http"
@@ -64,6 +64,7 @@ func (u *AcmeUser) Register() error {
 	// Skip TLS check
 	if config.HTTPClient != nil {
 		config.HTTPClient.Transport = &http.Transport{
+			Proxy:           http.ProxyFromEnvironment,
 			TLSClientConfig: &tls.Config{InsecureSkipVerify: settings.ServerSettings.InsecureSkipVerify},
 		}
 	}