mirror of
https://github.com/wyx2685/V2bX.git
synced 2025-02-01 22:38:13 -05:00
Merge pull request #12 from stitchrs/dev_xray_remotedns
chore: move xray dns configuration processing
This commit is contained in:
commit
438bcc3361
6
.github/workflows/release.yml
vendored
6
.github/workflows/release.yml
vendored
@ -110,7 +110,7 @@ jobs:
|
|||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v3
|
uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: '1.19'
|
go-version: '1.20'
|
||||||
|
|
||||||
- name: Get project dependencies
|
- name: Get project dependencies
|
||||||
run: go mod download
|
run: go mod download
|
||||||
@ -126,13 +126,13 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
echo "version: $version"
|
echo "version: $version"
|
||||||
mkdir -p build_assets
|
mkdir -p build_assets
|
||||||
go build -v -o build_assets/V2bX -tags "xray hy" -trimpath -ldflags "-X 'github.com/InazumaV/V2bX/cmd.version=$version' -s -w -buildid="
|
go build -v -o build_assets/V2bX -tags "sing xray with_reality_server with_quic" -trimpath -ldflags "-X 'github.com/InazumaV/V2bX/cmd.version=$version' -s -w -buildid="
|
||||||
|
|
||||||
- name: Build Mips softfloat V2bX
|
- name: Build Mips softfloat V2bX
|
||||||
if: matrix.goarch == 'mips' || matrix.goarch == 'mipsle'
|
if: matrix.goarch == 'mips' || matrix.goarch == 'mipsle'
|
||||||
run: |
|
run: |
|
||||||
echo "version: $version"
|
echo "version: $version"
|
||||||
GOMIPS=softfloat go build -v -o build_assets/V2bX_softfloat -tags "xray hy" -trimpath -ldflags "-X 'github.com/InazumaV/V2bX/cmd.version=$version' -s -w -buildid="
|
GOMIPS=softfloat go build -v -o build_assets/V2bX_softfloat -tags "sing xray with_reality_server with_quic" -trimpath -ldflags "-X 'github.com/InazumaV/V2bX/cmd.version=$version' -s -w -buildid="
|
||||||
- name: Rename Windows V2bX
|
- name: Rename Windows V2bX
|
||||||
if: matrix.goos == 'windows'
|
if: matrix.goos == 'windows'
|
||||||
run: |
|
run: |
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
package panel
|
package panel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
coreConf "github.com/xtls/xray-core/infra/conf"
|
|
||||||
"os"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -13,7 +10,6 @@ import (
|
|||||||
|
|
||||||
"github.com/InazumaV/V2bX/common/crypt"
|
"github.com/InazumaV/V2bX/common/crypt"
|
||||||
"github.com/goccy/go-json"
|
"github.com/goccy/go-json"
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type CommonNodeRsp struct {
|
type CommonNodeRsp struct {
|
||||||
@ -60,6 +56,7 @@ type NodeInfo struct {
|
|||||||
Host string
|
Host string
|
||||||
Port int
|
Port int
|
||||||
Network string
|
Network string
|
||||||
|
RawDNS RawDNS
|
||||||
ExtraConfig V2rayExtraConfig
|
ExtraConfig V2rayExtraConfig
|
||||||
NetworkSettings json.RawMessage
|
NetworkSettings json.RawMessage
|
||||||
Tls bool
|
Tls bool
|
||||||
@ -73,6 +70,11 @@ type NodeInfo struct {
|
|||||||
PullInterval time.Duration
|
PullInterval time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RawDNS struct {
|
||||||
|
DNSMap map[string]map[string]interface{}
|
||||||
|
DNSJson []byte
|
||||||
|
}
|
||||||
|
|
||||||
type Rules struct {
|
type Rules struct {
|
||||||
Regexp []string
|
Regexp []string
|
||||||
Protocol []string
|
Protocol []string
|
||||||
@ -96,11 +98,6 @@ type RealityConfig struct {
|
|||||||
ShortIds []string `yaml:"ShortIds" json:"ShortIds"`
|
ShortIds []string `yaml:"ShortIds" json:"ShortIds"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DNSConfig struct {
|
|
||||||
Servers []interface{} `json:"servers"`
|
|
||||||
Tag string `json:"tag"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) GetNodeInfo() (node *NodeInfo, err error) {
|
func (c *Client) GetNodeInfo() (node *NodeInfo, err error) {
|
||||||
const path = "/api/v1/server/UniProxy/config"
|
const path = "/api/v1/server/UniProxy/config"
|
||||||
r, err := c.client.
|
r, err := c.client.
|
||||||
@ -117,6 +114,10 @@ func (c *Client) GetNodeInfo() (node *NodeInfo, err error) {
|
|||||||
node = &NodeInfo{
|
node = &NodeInfo{
|
||||||
Id: c.NodeId,
|
Id: c.NodeId,
|
||||||
Type: c.NodeType,
|
Type: c.NodeType,
|
||||||
|
RawDNS: RawDNS{
|
||||||
|
DNSMap: make(map[string]map[string]interface{}),
|
||||||
|
DNSJson: []byte(""),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
common := CommonNodeRsp{}
|
common := CommonNodeRsp{}
|
||||||
err = json.Unmarshal(r.Body(), &common)
|
err = json.Unmarshal(r.Body(), &common)
|
||||||
@ -124,14 +125,6 @@ func (c *Client) GetNodeInfo() (node *NodeInfo, err error) {
|
|||||||
return nil, fmt.Errorf("decode common params error: %s", err)
|
return nil, fmt.Errorf("decode common params error: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dnsPath := os.Getenv("XRAY_DNS_PATH")
|
|
||||||
dnsConfig := DNSConfig{
|
|
||||||
Servers: []interface{}{
|
|
||||||
"1.1.1.1",
|
|
||||||
"localhost"},
|
|
||||||
Tag: "dns_inbound",
|
|
||||||
}
|
|
||||||
var isDnsConfigUpdating bool
|
|
||||||
for i := range common.Routes {
|
for i := range common.Routes {
|
||||||
var matchs []string
|
var matchs []string
|
||||||
if _, ok := common.Routes[i].Match.(string); ok {
|
if _, ok := common.Routes[i].Match.(string); ok {
|
||||||
@ -157,32 +150,22 @@ func (c *Client) GetNodeInfo() (node *NodeInfo, err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "dns":
|
case "dns":
|
||||||
|
var domains []string
|
||||||
|
for _, v := range matchs {
|
||||||
|
domains = append(domains, v)
|
||||||
|
}
|
||||||
if matchs[0] != "main" {
|
if matchs[0] != "main" {
|
||||||
var domains []string
|
node.RawDNS.DNSMap[strconv.Itoa(i)] = map[string]interface{}{
|
||||||
for _, v := range matchs {
|
"address": common.Routes[i].ActionValue,
|
||||||
domains = append(domains, v)
|
"domains": domains,
|
||||||
}
|
}
|
||||||
dnsConfig.Servers = append(dnsConfig.Servers,
|
|
||||||
map[string]interface{}{
|
|
||||||
"address": common.Routes[i].ActionValue,
|
|
||||||
"domains": domains,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
isDnsConfigUpdating = true
|
|
||||||
} else {
|
} else {
|
||||||
dns := []byte(strings.Join(matchs[1:], ""))
|
dns := []byte(strings.Join(matchs[1:], ""))
|
||||||
saveDnsConfig(dns, dnsPath)
|
node.RawDNS.DNSJson = dns
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if isDnsConfigUpdating {
|
|
||||||
dnsConfigJSON, err := json.MarshalIndent(dnsConfig, "", " ")
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Error marshaling dnsConfig to JSON:", err)
|
|
||||||
}
|
|
||||||
saveDnsConfig(dnsConfigJSON, dnsPath)
|
|
||||||
}
|
|
||||||
node.ServerName = common.ServerName
|
node.ServerName = common.ServerName
|
||||||
node.Host = common.Host
|
node.Host = common.Host
|
||||||
node.Port = common.ServerPort
|
node.Port = common.ServerPort
|
||||||
@ -252,30 +235,3 @@ func intervalToTime(i interface{}) time.Duration {
|
|||||||
return time.Duration(reflect.ValueOf(i).Int()) * time.Second
|
return time.Duration(reflect.ValueOf(i).Int()) * time.Second
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveDnsConfig(dns []byte, dnsPath string) {
|
|
||||||
currentData, err := os.ReadFile(dnsPath)
|
|
||||||
if err != nil {
|
|
||||||
log.WithField("err", err).Error("Failed to read XRAY_DNS_PATH")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if !bytes.Equal(currentData, dns) {
|
|
||||||
coreDnsConfig := &coreConf.DNSConfig{}
|
|
||||||
if err = json.NewDecoder(bytes.NewReader(dns)).Decode(coreDnsConfig); err != nil {
|
|
||||||
log.WithField("err", err).Error("Failed to unmarshal DNS config")
|
|
||||||
}
|
|
||||||
_, err := coreDnsConfig.Build()
|
|
||||||
if err != nil {
|
|
||||||
log.WithField("err", err).Error("Failed to understand DNS config, Please check: https://xtls.github.io/config/dns.html for help")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if err = os.Truncate(dnsPath, 0); err != nil {
|
|
||||||
log.WithField("err", err).Error("Failed to clear XRAY DNS PATH file")
|
|
||||||
}
|
|
||||||
if err = os.WriteFile(dnsPath, dns, 0644); err != nil {
|
|
||||||
log.WithField("err", err).Error("Failed to write DNS to XRAY DNS PATH file")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log.Println("reloading config")
|
|
||||||
time.Sleep(5 * time.Second)
|
|
||||||
}
|
|
||||||
|
63
core/xray/dns.go
Normal file
63
core/xray/dns.go
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
package xray
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"github.com/InazumaV/V2bX/api/panel"
|
||||||
|
"github.com/goccy/go-json"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
coreConf "github.com/xtls/xray-core/infra/conf"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func updateDNSConfig(node *panel.NodeInfo) (err error) {
|
||||||
|
dnsPath := os.Getenv("XRAY_DNS_PATH")
|
||||||
|
if len(node.RawDNS.DNSJson) != 0 {
|
||||||
|
err = saveDnsConfig(node.RawDNS.DNSJson, dnsPath)
|
||||||
|
} else if len(node.RawDNS.DNSMap) != 0 {
|
||||||
|
dnsConfig := DNSConfig{
|
||||||
|
Servers: []interface{}{
|
||||||
|
"1.1.1.1",
|
||||||
|
"localhost"},
|
||||||
|
Tag: "dns_inbound",
|
||||||
|
}
|
||||||
|
for _, value := range node.RawDNS.DNSMap {
|
||||||
|
dnsConfig.Servers = append(dnsConfig.Servers, value)
|
||||||
|
}
|
||||||
|
dnsConfigJSON, err := json.MarshalIndent(dnsConfig, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
log.WithField("err", err).Error("Error marshaling dnsConfig to JSON")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = saveDnsConfig(dnsConfigJSON, dnsPath)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func saveDnsConfig(dns []byte, dnsPath string) (err error) {
|
||||||
|
currentData, err := os.ReadFile(dnsPath)
|
||||||
|
if err != nil {
|
||||||
|
log.WithField("err", err).Error("Failed to read XRAY_DNS_PATH")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !bytes.Equal(currentData, dns) {
|
||||||
|
coreDnsConfig := &coreConf.DNSConfig{}
|
||||||
|
if err = json.NewDecoder(bytes.NewReader(dns)).Decode(coreDnsConfig); err != nil {
|
||||||
|
log.WithField("err", err).Error("Failed to unmarshal DNS config")
|
||||||
|
}
|
||||||
|
_, err := coreDnsConfig.Build()
|
||||||
|
if err != nil {
|
||||||
|
log.WithField("err", err).Error("Failed to understand DNS config, Please check: https://xtls.github.io/config/dns.html for help")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err = os.Truncate(dnsPath, 0); err != nil {
|
||||||
|
log.WithField("err", err).Error("Failed to clear XRAY DNS PATH file")
|
||||||
|
}
|
||||||
|
if err = os.WriteFile(dnsPath, dns, 0644); err != nil {
|
||||||
|
log.WithField("err", err).Error("Failed to write DNS to XRAY DNS PATH file")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.Println("reloading config")
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
return err
|
||||||
|
}
|
@ -3,7 +3,6 @@ package xray
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/InazumaV/V2bX/api/panel"
|
"github.com/InazumaV/V2bX/api/panel"
|
||||||
"github.com/InazumaV/V2bX/conf"
|
"github.com/InazumaV/V2bX/conf"
|
||||||
"github.com/xtls/xray-core/core"
|
"github.com/xtls/xray-core/core"
|
||||||
@ -11,7 +10,16 @@ import (
|
|||||||
"github.com/xtls/xray-core/features/outbound"
|
"github.com/xtls/xray-core/features/outbound"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type DNSConfig struct {
|
||||||
|
Servers []interface{} `json:"servers"`
|
||||||
|
Tag string `json:"tag"`
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Core) AddNode(tag string, info *panel.NodeInfo, config *conf.Options) error {
|
func (c *Core) AddNode(tag string, info *panel.NodeInfo, config *conf.Options) error {
|
||||||
|
err := updateDNSConfig(info)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("build dns error: %s", err)
|
||||||
|
}
|
||||||
inboundConfig, err := buildInbound(config, info, tag)
|
inboundConfig, err := buildInbound(config, info, tag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("build inbound error: %s", err)
|
return fmt.Errorf("build inbound error: %s", err)
|
||||||
|
4
go.sum
4
go.sum
@ -365,10 +365,6 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
|
|||||||
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||||
github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df h1:MZf03xP9WdakyXhOWuAD5uPK3wHh96wCsqe3hCMKh8E=
|
github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df h1:MZf03xP9WdakyXhOWuAD5uPK3wHh96wCsqe3hCMKh8E=
|
||||||
github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df/go.mod h1:QMZY7/J/KSQEhKWFeDesPjMj+wCHReeknARU3wqlyN4=
|
github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df/go.mod h1:QMZY7/J/KSQEhKWFeDesPjMj+wCHReeknARU3wqlyN4=
|
||||||
github.com/inazumav/sing-box v0.0.0-20230809093045-c5fd24fc8b60 h1:JbqaLf29NrjpAU1zY9Z1inQJiau8TcedLmHkZXd7lBI=
|
|
||||||
github.com/inazumav/sing-box v0.0.0-20230809093045-c5fd24fc8b60/go.mod h1:3c9SPznRTGFV/3Cba2oyDLLQ44pqWW/9PzLXjvAaUec=
|
|
||||||
github.com/inazumav/sing-box v0.0.0-20230809113332-78bc5982ba80 h1:Qq5KmpKzCXSwu1ERBUmvqFCk+CH1rbN6vyUuo1raZHA=
|
|
||||||
github.com/inazumav/sing-box v0.0.0-20230809113332-78bc5982ba80/go.mod h1:3c9SPznRTGFV/3Cba2oyDLLQ44pqWW/9PzLXjvAaUec=
|
|
||||||
github.com/inazumav/sing-box v0.0.0-20230809113805-82b279719f5f h1:jfwKhScZeQHUkMxQpJZ6ow2e3k4UDbwau6AsCzXwauw=
|
github.com/inazumav/sing-box v0.0.0-20230809113805-82b279719f5f h1:jfwKhScZeQHUkMxQpJZ6ow2e3k4UDbwau6AsCzXwauw=
|
||||||
github.com/inazumav/sing-box v0.0.0-20230809113805-82b279719f5f/go.mod h1:3c9SPznRTGFV/3Cba2oyDLLQ44pqWW/9PzLXjvAaUec=
|
github.com/inazumav/sing-box v0.0.0-20230809113805-82b279719f5f/go.mod h1:3c9SPznRTGFV/3Cba2oyDLLQ44pqWW/9PzLXjvAaUec=
|
||||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||||
|
Loading…
Reference in New Issue
Block a user