|
@@ -6,6 +6,7 @@ import (
|
|
|
"errors"
|
|
"errors"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
"net"
|
|
"net"
|
|
|
|
|
+ "net/http"
|
|
|
"reflect"
|
|
"reflect"
|
|
|
"strconv"
|
|
"strconv"
|
|
|
"strings"
|
|
"strings"
|
|
@@ -15,6 +16,7 @@ import (
|
|
|
"github.com/mhsanaei/3x-ui/v3/database/model"
|
|
"github.com/mhsanaei/3x-ui/v3/database/model"
|
|
|
"github.com/mhsanaei/3x-ui/v3/logger"
|
|
"github.com/mhsanaei/3x-ui/v3/logger"
|
|
|
"github.com/mhsanaei/3x-ui/v3/util/common"
|
|
"github.com/mhsanaei/3x-ui/v3/util/common"
|
|
|
|
|
+ "github.com/mhsanaei/3x-ui/v3/util/netproxy"
|
|
|
"github.com/mhsanaei/3x-ui/v3/util/random"
|
|
"github.com/mhsanaei/3x-ui/v3/util/random"
|
|
|
"github.com/mhsanaei/3x-ui/v3/util/reflect_util"
|
|
"github.com/mhsanaei/3x-ui/v3/util/reflect_util"
|
|
|
"github.com/mhsanaei/3x-ui/v3/web/entity"
|
|
"github.com/mhsanaei/3x-ui/v3/web/entity"
|
|
@@ -88,6 +90,7 @@ var defaultValueMap = map[string]string{
|
|
|
"externalTrafficInformURI": "",
|
|
"externalTrafficInformURI": "",
|
|
|
"restartXrayOnClientDisable": "true",
|
|
"restartXrayOnClientDisable": "true",
|
|
|
"xrayOutboundTestUrl": "https://www.google.com/generate_204",
|
|
"xrayOutboundTestUrl": "https://www.google.com/generate_204",
|
|
|
|
|
+ "panelProxy": "",
|
|
|
|
|
|
|
|
// LDAP defaults
|
|
// LDAP defaults
|
|
|
"ldapEnable": "false",
|
|
"ldapEnable": "false",
|
|
@@ -351,6 +354,31 @@ func (s *SettingService) SetTgBotProxy(token string) error {
|
|
|
return s.setString("tgBotProxy", token)
|
|
return s.setString("tgBotProxy", token)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func (s *SettingService) GetPanelProxy() (string, error) {
|
|
|
|
|
+ return s.getString("panelProxy")
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (s *SettingService) SetPanelProxy(proxyUrl string) error {
|
|
|
|
|
+ return s.setString("panelProxy", proxyUrl)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// NewProxiedHTTPClient returns an HTTP client that routes the panel's own
|
|
|
|
|
+// outbound requests through the configured panelProxy setting. An invalid or
|
|
|
|
|
+// missing proxy falls back to a direct client so existing behavior is preserved.
|
|
|
|
|
+func (s *SettingService) NewProxiedHTTPClient(timeout time.Duration) *http.Client {
|
|
|
|
|
+ proxyUrl, err := s.GetPanelProxy()
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ logger.Warning("Failed to read panel proxy setting:", err)
|
|
|
|
|
+ proxyUrl = ""
|
|
|
|
|
+ }
|
|
|
|
|
+ client, err := netproxy.NewHTTPClient(proxyUrl, timeout)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ logger.Warningf("Invalid panel proxy %q, using direct connection: %v", proxyUrl, err)
|
|
|
|
|
+ return &http.Client{Timeout: timeout}
|
|
|
|
|
+ }
|
|
|
|
|
+ return client
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func (s *SettingService) GetTgBotAPIServer() (string, error) {
|
|
func (s *SettingService) GetTgBotAPIServer() (string, error) {
|
|
|
return s.getString("tgBotAPIServer")
|
|
return s.getString("tgBotAPIServer")
|
|
|
}
|
|
}
|