mirror of
https://github.com/wyx2685/V2bX.git
synced 2025-01-22 18:08:14 -05:00
chore: trojan and singConfigs
This commit is contained in:
parent
45099f6056
commit
85609b41de
@ -7,21 +7,30 @@ type Options struct {
|
|||||||
CertConfig *CertConfig `yaml:"CertConfig"`
|
CertConfig *CertConfig `yaml:"CertConfig"`
|
||||||
XrayOptions XrayOptions `yaml:"XrayOptions"`
|
XrayOptions XrayOptions `yaml:"XrayOptions"`
|
||||||
HyOptions HyOptions `yaml:"HyOptions"`
|
HyOptions HyOptions `yaml:"HyOptions"`
|
||||||
|
SingOptions SingOptions `yaml:"SingOptions"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type XrayOptions struct {
|
type XrayOptions struct {
|
||||||
EnableProxyProtocol bool `yaml:"EnableProxyProtocol"`
|
EnableProxyProtocol bool `yaml:"EnableProxyProtocol"`
|
||||||
EnableDNS bool `yaml:"EnableDNS"`
|
EnableDNS bool `yaml:"EnableDNS"`
|
||||||
DNSType string `yaml:"DNSType"`
|
DNSType string `yaml:"DNSType"`
|
||||||
EnableUot bool `yaml:"EnableUot"`
|
EnableUot bool `yaml:"EnableUot"`
|
||||||
EnableTFO bool `yaml:"EnableTFO"`
|
EnableTFO bool `yaml:"EnableTFO"`
|
||||||
DisableIVCheck bool `yaml:"DisableIVCheck"`
|
DisableIVCheck bool `yaml:"DisableIVCheck"`
|
||||||
DisableSniffing bool `yaml:"DisableSniffing"`
|
DisableSniffing bool `yaml:"DisableSniffing"`
|
||||||
EnableFallback bool `yaml:"EnableFallback"`
|
EnableFallback bool `yaml:"EnableFallback"`
|
||||||
FallBackConfigs []FallBackConfig `yaml:"FallBackConfigs"`
|
FallBackConfigs []FallBackConfigForXray `yaml:"FallBackConfigs"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type FallBackConfig struct {
|
type SingOptions struct {
|
||||||
|
EnableProxyProtocol bool `yaml:"EnableProxyProtocol"`
|
||||||
|
TCPFastOpen bool `yaml:"EnableTFO"`
|
||||||
|
SniffEnabled bool `yaml:"EnableSniff"`
|
||||||
|
SniffOverrideDestination bool `yaml:"SniffOverrideDestination"`
|
||||||
|
FallBackConfigs *FallBackConfigForSing `yaml:"FallBackConfigs"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type FallBackConfigForXray struct {
|
||||||
SNI string `yaml:"SNI"`
|
SNI string `yaml:"SNI"`
|
||||||
Alpn string `yaml:"Alpn"`
|
Alpn string `yaml:"Alpn"`
|
||||||
Path string `yaml:"Path"`
|
Path string `yaml:"Path"`
|
||||||
@ -29,6 +38,16 @@ type FallBackConfig struct {
|
|||||||
ProxyProtocolVer uint64 `yaml:"ProxyProtocolVer"`
|
ProxyProtocolVer uint64 `yaml:"ProxyProtocolVer"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FallBackConfigForSing struct {
|
||||||
|
// sing-box
|
||||||
|
FallBack FallBack `yaml:"FallBack"`
|
||||||
|
FallBackForALPN map[string]FallBack `yaml:"FallBackForALPN"`
|
||||||
|
}
|
||||||
|
type FallBack struct {
|
||||||
|
Server string `yaml:"Server"`
|
||||||
|
ServerPort string `yaml:"ServerPort"`
|
||||||
|
}
|
||||||
|
|
||||||
type HyOptions struct {
|
type HyOptions struct {
|
||||||
Resolver string `yaml:"Resolver"`
|
Resolver string `yaml:"Resolver"`
|
||||||
ResolvePreference string `yaml:"ResolvePreference"`
|
ResolvePreference string `yaml:"ResolvePreference"`
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/google/uuid"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -30,9 +31,14 @@ func getInboundOptions(tag string, info *panel.NodeInfo, c *conf.Options) (optio
|
|||||||
return option.Inbound{}, fmt.Errorf("the listen ip not vail")
|
return option.Inbound{}, fmt.Errorf("the listen ip not vail")
|
||||||
}
|
}
|
||||||
listen := option.ListenOptions{
|
listen := option.ListenOptions{
|
||||||
//ProxyProtocol: true,
|
Listen: (*option.ListenAddress)(&addr),
|
||||||
Listen: (*option.ListenAddress)(&addr),
|
ListenPort: uint16(info.Port),
|
||||||
ListenPort: uint16(info.Port),
|
ProxyProtocol: c.SingOptions.EnableProxyProtocol,
|
||||||
|
TCPFastOpen: c.SingOptions.TCPFastOpen,
|
||||||
|
InboundOptions: option.InboundOptions{
|
||||||
|
SniffEnabled: c.SingOptions.SniffEnabled,
|
||||||
|
SniffOverrideDestination: c.SingOptions.SniffOverrideDestination,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
tls := option.InboundTLSOptions{
|
tls := option.InboundTLSOptions{
|
||||||
Enabled: info.Tls,
|
Enabled: info.Tls,
|
||||||
@ -121,6 +127,46 @@ func getInboundOptions(tag string, info *panel.NodeInfo, c *conf.Options) (optio
|
|||||||
in.ShadowsocksOptions.Users = []option.ShadowsocksUser{{
|
in.ShadowsocksOptions.Users = []option.ShadowsocksUser{{
|
||||||
Password: randomPasswd,
|
Password: randomPasswd,
|
||||||
}}
|
}}
|
||||||
|
case "trojan":
|
||||||
|
in.Type = "trojan"
|
||||||
|
t := option.V2RayTransportOptions{
|
||||||
|
Type: info.Network,
|
||||||
|
}
|
||||||
|
switch info.Network {
|
||||||
|
case "tcp":
|
||||||
|
t.Type = ""
|
||||||
|
case "grpc":
|
||||||
|
err := json.Unmarshal(info.NetworkSettings, &t.GRPCOptions)
|
||||||
|
if err != nil {
|
||||||
|
return option.Inbound{}, fmt.Errorf("decode NetworkSettings error: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
randomPasswd := uuid.New().String()
|
||||||
|
in.TrojanOptions = option.TrojanInboundOptions{
|
||||||
|
ListenOptions: listen,
|
||||||
|
Users: []option.TrojanUser{{
|
||||||
|
Name: randomPasswd,
|
||||||
|
Password: randomPasswd,
|
||||||
|
}},
|
||||||
|
TLS: &tls,
|
||||||
|
Transport: &t,
|
||||||
|
}
|
||||||
|
if c.SingOptions.FallBackConfigs != nil {
|
||||||
|
// fallback handling
|
||||||
|
fallback := c.SingOptions.FallBackConfigs.FallBack
|
||||||
|
fallbackPort, err := strconv.Atoi(fallback.ServerPort)
|
||||||
|
if err == nil {
|
||||||
|
in.TrojanOptions.Fallback = &option.ServerOptions{
|
||||||
|
Server: fallback.Server,
|
||||||
|
ServerPort: uint16(fallbackPort),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fallbackForALPNMap := c.SingOptions.FallBackConfigs.FallBackForALPN
|
||||||
|
fallbackForALPN := make(map[string]*option.ServerOptions, len(fallbackForALPNMap))
|
||||||
|
if err := processFallback(c, fallbackForALPN); err == nil {
|
||||||
|
in.TrojanOptions.FallbackForALPN = fallbackForALPN
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return in, nil
|
return in, nil
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,15 @@ func (b *Box) AddUsers(p *core.AddUsersParams) (added int, err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = b.inbounds[p.Tag].(*inbound.ShadowsocksMulti).AddUsers(us)
|
err = b.inbounds[p.Tag].(*inbound.ShadowsocksMulti).AddUsers(us)
|
||||||
|
case "trojan":
|
||||||
|
us := make([]option.TrojanUser, len(p.UserInfo))
|
||||||
|
for i := range p.UserInfo {
|
||||||
|
us[i] = option.TrojanUser{
|
||||||
|
Name: p.UserInfo[i].Uuid,
|
||||||
|
Password: p.UserInfo[i].Uuid,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err = b.inbounds[p.Tag].(*inbound.Trojan).AddUsers(us)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
19
core/sing/utils.go
Normal file
19
core/sing/utils.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package sing
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/InazumaV/V2bX/conf"
|
||||||
|
"github.com/inazumav/sing-box/option"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
func processFallback(c *conf.Options, fallbackForALPN map[string]*option.ServerOptions) error {
|
||||||
|
for k, v := range c.SingOptions.FallBackConfigs.FallBackForALPN {
|
||||||
|
fallbackPort, err := strconv.Atoi(v.ServerPort)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to parse fallbackForALPN server port error: %s", err)
|
||||||
|
}
|
||||||
|
fallbackForALPN[k] = &option.ServerOptions{Server: v.Server, ServerPort: uint16(fallbackPort)}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
@ -274,7 +274,7 @@ func buildShadowsocks(config *conf.Options, nodeInfo *panel.NodeInfo, inbound *c
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildVlessFallbacks(fallbackConfigs []conf.FallBackConfig) ([]*coreConf.VLessInboundFallback, error) {
|
func buildVlessFallbacks(fallbackConfigs []conf.FallBackConfigForXray) ([]*coreConf.VLessInboundFallback, error) {
|
||||||
if fallbackConfigs == nil {
|
if fallbackConfigs == nil {
|
||||||
return nil, fmt.Errorf("you must provide FallBackConfigs")
|
return nil, fmt.Errorf("you must provide FallBackConfigs")
|
||||||
}
|
}
|
||||||
@ -299,7 +299,7 @@ func buildVlessFallbacks(fallbackConfigs []conf.FallBackConfig) ([]*coreConf.VLe
|
|||||||
return vlessFallBacks, nil
|
return vlessFallBacks, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildTrojanFallbacks(fallbackConfigs []conf.FallBackConfig) ([]*coreConf.TrojanInboundFallback, error) {
|
func buildTrojanFallbacks(fallbackConfigs []conf.FallBackConfigForXray) ([]*coreConf.TrojanInboundFallback, error) {
|
||||||
if fallbackConfigs == nil {
|
if fallbackConfigs == nil {
|
||||||
return nil, fmt.Errorf("you must provide FallBackConfigs")
|
return nil, fmt.Errorf("you must provide FallBackConfigs")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user