feat(settings): panel network proxy for the panel's own outbound requests

Add a panelProxy setting that routes the panel's self-initiated HTTP requests (geo updates, Xray version/core download, panel update check) through an admin-configured socks5/http(s) proxy, to bypass server-side filtering of GitHub/Telegram. The Telegram bot falls back to it when tgBotProxy is empty (socks5 only). New util/netproxy.NewHTTPClient builds the proxied client.

Also fix the Mixed-inbound SOCKS/HTTP share URLs that had host:port and user:pass in the wrong order, and consolidate the Telegram settings tab (move API server into the general tab, drop the empty Proxy & Server tab).
This commit is contained in:
MHSanaei
2026-05-28 00:45:32 +02:00
parent 272854df91
commit 9d9737f470
15 changed files with 196 additions and 28 deletions
+28
View File
@@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"net"
"net/http"
"reflect"
"strconv"
"strings"
@@ -15,6 +16,7 @@ import (
"github.com/mhsanaei/3x-ui/v3/database/model"
"github.com/mhsanaei/3x-ui/v3/logger"
"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/reflect_util"
"github.com/mhsanaei/3x-ui/v3/web/entity"
@@ -88,6 +90,7 @@ var defaultValueMap = map[string]string{
"externalTrafficInformURI": "",
"restartXrayOnClientDisable": "true",
"xrayOutboundTestUrl": "https://www.google.com/generate_204",
"panelProxy": "",
// LDAP defaults
"ldapEnable": "false",
@@ -351,6 +354,31 @@ func (s *SettingService) SetTgBotProxy(token string) error {
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) {
return s.getString("tgBotAPIServer")
}