mirror of
https://github.com/XrayR-project/XrayR.git
synced 2025-06-14 08:19:54 +00:00
update: support v2board DNS rules
This commit is contained in:
parent
77814acd1a
commit
1de5143fde
@ -3,6 +3,8 @@ package api
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
|
"github.com/xtls/xray-core/infra/conf"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config API config
|
// Config API config
|
||||||
@ -45,6 +47,7 @@ type NodeInfo struct {
|
|||||||
ServerKey string
|
ServerKey string
|
||||||
ServiceName string
|
ServiceName string
|
||||||
Header json.RawMessage
|
Header json.RawMessage
|
||||||
|
NameServerConfig []*conf.NameServerConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserInfo struct {
|
type UserInfo struct {
|
||||||
|
@ -15,6 +15,8 @@ import (
|
|||||||
|
|
||||||
"github.com/bitly/go-simplejson"
|
"github.com/bitly/go-simplejson"
|
||||||
"github.com/go-resty/resty/v2"
|
"github.com/go-resty/resty/v2"
|
||||||
|
"github.com/xtls/xray-core/common/net"
|
||||||
|
"github.com/xtls/xray-core/infra/conf"
|
||||||
|
|
||||||
"github.com/XrayR-project/XrayR/api"
|
"github.com/XrayR-project/XrayR/api"
|
||||||
)
|
)
|
||||||
@ -304,6 +306,7 @@ func (c *APIClient) parseTrojanNodeResponse(nodeInfoResponse *simplejson.Json) (
|
|||||||
TLSType: TLSType,
|
TLSType: TLSType,
|
||||||
Host: nodeInfoResponse.Get("host").MustString(),
|
Host: nodeInfoResponse.Get("host").MustString(),
|
||||||
ServiceName: nodeInfoResponse.Get("server_name").MustString(),
|
ServiceName: nodeInfoResponse.Get("server_name").MustString(),
|
||||||
|
NameServerConfig: parseDNSConfig(nodeInfoResponse),
|
||||||
}
|
}
|
||||||
return nodeInfo, nil
|
return nodeInfo, nil
|
||||||
}
|
}
|
||||||
@ -318,6 +321,7 @@ func (c *APIClient) parseSSNodeResponse(nodeInfoResponse *simplejson.Json) (*api
|
|||||||
TransportProtocol: "tcp",
|
TransportProtocol: "tcp",
|
||||||
CypherMethod: nodeInfoResponse.Get("cipher").MustString(),
|
CypherMethod: nodeInfoResponse.Get("cipher").MustString(),
|
||||||
ServerKey: nodeInfoResponse.Get("server_key").MustString(), // shadowsocks2022 share key
|
ServerKey: nodeInfoResponse.Get("server_key").MustString(), // shadowsocks2022 share key
|
||||||
|
NameServerConfig: parseDNSConfig(nodeInfoResponse),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,5 +377,20 @@ func (c *APIClient) parseV2rayNodeResponse(nodeInfoResponse *simplejson.Json) (*
|
|||||||
EnableVless: c.EnableVless,
|
EnableVless: c.EnableVless,
|
||||||
ServiceName: serviceName,
|
ServiceName: serviceName,
|
||||||
Header: header,
|
Header: header,
|
||||||
|
NameServerConfig: parseDNSConfig(nodeInfoResponse),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseDNSConfig(nodeInfoResponse *simplejson.Json) (nameServerList []*conf.NameServerConfig) {
|
||||||
|
for _, rule := range nodeInfoResponse.Get("routes").MustArray() {
|
||||||
|
r := rule.(map[string]any)
|
||||||
|
if r["action"] == "dns" {
|
||||||
|
nameServerList = append(nameServerList, &conf.NameServerConfig{
|
||||||
|
Address: &conf.Address{Address: net.ParseAddress(r["action_value"].(string))},
|
||||||
|
Domains: strings.Split(r["match"].(string), ","),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@ -66,10 +66,12 @@ func (p *Panel) loadCore(panelConfig *Config) *core.Instance {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dnsConfig, err := coreDnsConfig.Build()
|
|
||||||
if err != nil {
|
// init controller's DNS config
|
||||||
log.Panicf("Failed to understand DNS config, Please check: https://xtls.github.io/config/dns.html for help: %s", err)
|
for _, config := range p.panelConfig.NodesConfig {
|
||||||
|
config.ControllerConfig.DNSConfig = coreDnsConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
// Routing config
|
// Routing config
|
||||||
coreRouterConfig := &conf.RouterConfig{}
|
coreRouterConfig := &conf.RouterConfig{}
|
||||||
if panelConfig.RouteConfigPath != "" {
|
if panelConfig.RouteConfigPath != "" {
|
||||||
@ -137,7 +139,6 @@ func (p *Panel) loadCore(panelConfig *Config) *core.Instance {
|
|||||||
serial.ToTypedMessage(&proxyman.InboundConfig{}),
|
serial.ToTypedMessage(&proxyman.InboundConfig{}),
|
||||||
serial.ToTypedMessage(&proxyman.OutboundConfig{}),
|
serial.ToTypedMessage(&proxyman.OutboundConfig{}),
|
||||||
serial.ToTypedMessage(policyConfig),
|
serial.ToTypedMessage(policyConfig),
|
||||||
serial.ToTypedMessage(dnsConfig),
|
|
||||||
serial.ToTypedMessage(routeConfig),
|
serial.ToTypedMessage(routeConfig),
|
||||||
},
|
},
|
||||||
Inbound: inBoundConfig,
|
Inbound: inBoundConfig,
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/xtls/xray-core/infra/conf"
|
||||||
|
|
||||||
"github.com/XrayR-project/XrayR/common/limiter"
|
"github.com/XrayR-project/XrayR/common/limiter"
|
||||||
"github.com/XrayR-project/XrayR/common/mylego"
|
"github.com/XrayR-project/XrayR/common/mylego"
|
||||||
)
|
)
|
||||||
@ -21,6 +23,7 @@ type Config struct {
|
|||||||
AutoSpeedLimitConfig *AutoSpeedLimitConfig `mapstructure:"AutoSpeedLimitConfig"`
|
AutoSpeedLimitConfig *AutoSpeedLimitConfig `mapstructure:"AutoSpeedLimitConfig"`
|
||||||
GlobalDeviceLimitConfig *limiter.GlobalDeviceLimitConfig `mapstructure:"GlobalDeviceLimitConfig"`
|
GlobalDeviceLimitConfig *limiter.GlobalDeviceLimitConfig `mapstructure:"GlobalDeviceLimitConfig"`
|
||||||
FallBackConfigs []*FallBackConfig `mapstructure:"FallBackConfigs"`
|
FallBackConfigs []*FallBackConfig `mapstructure:"FallBackConfigs"`
|
||||||
|
DNSConfig *conf.DNSConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
type AutoSpeedLimitConfig struct {
|
type AutoSpeedLimitConfig struct {
|
||||||
|
@ -7,12 +7,15 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common/protocol"
|
"github.com/xtls/xray-core/common/protocol"
|
||||||
|
"github.com/xtls/xray-core/common/serial"
|
||||||
"github.com/xtls/xray-core/common/task"
|
"github.com/xtls/xray-core/common/task"
|
||||||
"github.com/xtls/xray-core/core"
|
"github.com/xtls/xray-core/core"
|
||||||
|
"github.com/xtls/xray-core/features"
|
||||||
"github.com/xtls/xray-core/features/inbound"
|
"github.com/xtls/xray-core/features/inbound"
|
||||||
"github.com/xtls/xray-core/features/outbound"
|
"github.com/xtls/xray-core/features/outbound"
|
||||||
"github.com/xtls/xray-core/features/routing"
|
"github.com/xtls/xray-core/features/routing"
|
||||||
"github.com/xtls/xray-core/features/stats"
|
"github.com/xtls/xray-core/features/stats"
|
||||||
|
"github.com/xtls/xray-core/infra/conf"
|
||||||
|
|
||||||
"github.com/XrayR-project/XrayR/api"
|
"github.com/XrayR-project/XrayR/api"
|
||||||
"github.com/XrayR-project/XrayR/app/mydispatcher"
|
"github.com/XrayR-project/XrayR/app/mydispatcher"
|
||||||
@ -77,6 +80,13 @@ func (c *Controller) Start() error {
|
|||||||
}
|
}
|
||||||
c.nodeInfo = newNodeInfo
|
c.nodeInfo = newNodeInfo
|
||||||
c.Tag = c.buildNodeTag()
|
c.Tag = c.buildNodeTag()
|
||||||
|
|
||||||
|
// append remote DNS config and init dns service
|
||||||
|
err = c.addNewDNS(newNodeInfo)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Add new tag
|
// Add new tag
|
||||||
err = c.addNewTag(newNodeInfo)
|
err = c.addNewTag(newNodeInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -252,6 +262,13 @@ func (c *Controller) nodeInfoMonitor() (err error) {
|
|||||||
log.Print(err)
|
log.Print(err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add DNS
|
||||||
|
log.Printf("%s Reload DNS service", c.logPrefix())
|
||||||
|
if err := c.addNewDNS(newNodeInfo); err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
var deleted, added []api.UserInfo
|
var deleted, added []api.UserInfo
|
||||||
if usersChanged {
|
if usersChanged {
|
||||||
@ -613,3 +630,32 @@ func (c *Controller) certMonitor() error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// append remote dns
|
||||||
|
func (c *Controller) addNewDNS(newNodeInfo *api.NodeInfo) error {
|
||||||
|
// reserve local DNS
|
||||||
|
servers := make([]*conf.NameServerConfig, len(c.config.DNSConfig.Servers))
|
||||||
|
copy(servers, c.config.DNSConfig.Servers)
|
||||||
|
servers = append(servers, newNodeInfo.NameServerConfig...)
|
||||||
|
|
||||||
|
buf := &conf.DNSConfig{Servers: servers}
|
||||||
|
dnsConfig, err := buf.Build()
|
||||||
|
if err != nil {
|
||||||
|
log.Panicf("Failed to understand DNS config, Please check: https://xtls.github.io/config/dns.html for help: %s", err)
|
||||||
|
}
|
||||||
|
dnsInstance, err := serial.ToTypedMessage(dnsConfig).GetInstance()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
obj, err := core.CreateObject(c.server, dnsInstance)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if feature, ok := obj.(features.Feature); ok {
|
||||||
|
if err := c.server.AddFeature(feature); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user