new: add chain support & fix warp bug
This commit is contained in:
@@ -166,6 +166,15 @@ func patchOutbound(base option.Outbound, configOpt ConfigOptions) (*option.Outbo
|
|||||||
}
|
}
|
||||||
|
|
||||||
func patchWarp(base *option.Outbound) error {
|
func patchWarp(base *option.Outbound) error {
|
||||||
|
if base.Type == C.TypeWireGuard {
|
||||||
|
host := base.WireGuardOptions.Server
|
||||||
|
if host == "default" || host == "random" || host == "auto" {
|
||||||
|
base.WireGuardOptions.Server = getRandomIP()
|
||||||
|
}
|
||||||
|
if base.WireGuardOptions.ServerPort == 0 {
|
||||||
|
base.WireGuardOptions.ServerPort = generateRandomPort()
|
||||||
|
}
|
||||||
|
}
|
||||||
if base.Type == C.TypeCustom {
|
if base.Type == C.TypeCustom {
|
||||||
if warp, ok := base.CustomOptions["warp"].(map[string]interface{}); ok {
|
if warp, ok := base.CustomOptions["warp"].(map[string]interface{}); ok {
|
||||||
key, _ := warp["key"].(string)
|
key, _ := warp["key"].(string)
|
||||||
@@ -186,6 +195,7 @@ func patchWarp(base *option.Outbound) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hiddify/ray2sing/ray2sing"
|
"github.com/hiddify/ray2sing/ray2sing"
|
||||||
"github.com/sagernet/sing-box/experimental/libbox"
|
"github.com/sagernet/sing-box/experimental/libbox"
|
||||||
|
"github.com/sagernet/sing-box/option"
|
||||||
SJ "github.com/sagernet/sing/common/json"
|
SJ "github.com/sagernet/sing/common/json"
|
||||||
"github.com/xmdhs/clash2singbox/convert"
|
"github.com/xmdhs/clash2singbox/convert"
|
||||||
"github.com/xmdhs/clash2singbox/model/clash"
|
"github.com/xmdhs/clash2singbox/model/clash"
|
||||||
@@ -38,12 +39,13 @@ func ParseConfig(path string, debug bool) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
newContent, _ := json.MarshalIndent(jsonObj, "", " ")
|
newContent, _ := json.MarshalIndent(jsonObj, "", " ")
|
||||||
return validateResult(newContent, "SingboxParser")
|
|
||||||
|
return patchConfig([]byte(newContent), "SingboxParser")
|
||||||
}
|
}
|
||||||
fmt.Printf("Convert using v2ray\n")
|
fmt.Printf("Convert using v2ray\n")
|
||||||
v2rayStr, err := ray2sing.Ray2Singbox(string(content))
|
v2rayStr, err := ray2sing.Ray2Singbox(string(content))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return validateResult([]byte(v2rayStr), "V2rayParser")
|
return patchConfig([]byte(v2rayStr), "V2rayParser")
|
||||||
}
|
}
|
||||||
fmt.Printf("Convert using clash\n")
|
fmt.Printf("Convert using clash\n")
|
||||||
clashObj := clash.Clash{}
|
clashObj := clash.Clash{}
|
||||||
@@ -60,13 +62,35 @@ func ParseConfig(path string, debug bool) ([]byte, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("[ClashParser] patching clash config error: %w", err)
|
return nil, fmt.Errorf("[ClashParser] patching clash config error: %w", err)
|
||||||
}
|
}
|
||||||
return validateResult(output, "ClashParser")
|
return patchConfig(output, "ClashParser")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("unable to determine config format")
|
return nil, fmt.Errorf("unable to determine config format")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func patchConfig(content []byte, name string) ([]byte, error) {
|
||||||
|
options := option.Options{}
|
||||||
|
err := json.Unmarshal(content, &options)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("[SingboxParser] unmarshal error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, base := range options.Outbounds {
|
||||||
|
err := patchWarp(&base)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("[Warp] patch warp error: %w", err)
|
||||||
|
}
|
||||||
|
options.Outbounds[i] = base
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
content, _ = json.MarshalIndent(options, "", " ")
|
||||||
|
fmt.Printf("%s\n", content)
|
||||||
|
return validateResult(content, name)
|
||||||
|
}
|
||||||
|
|
||||||
func validateResult(content []byte, name string) ([]byte, error) {
|
func validateResult(content []byte, name string) ([]byte, error) {
|
||||||
|
|
||||||
err := libbox.CheckConfig(string(content))
|
err := libbox.CheckConfig(string(content))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("[%s] invalid sing-box config: %w", name, err)
|
return nil, fmt.Errorf("[%s] invalid sing-box config: %w", name, err)
|
||||||
|
|||||||
@@ -162,11 +162,8 @@ func generateWarp(license string, host string, port uint16, fakePackets string)
|
|||||||
if host == "auto" && fakePackets == "" {
|
if host == "auto" && fakePackets == "" {
|
||||||
fakePackets = "5-10"
|
fakePackets = "5-10"
|
||||||
}
|
}
|
||||||
if host == "default" || host == "random" || host == "auto" {
|
if _, err := os.Stat("./wgcf-identity.json"); err == nil {
|
||||||
host = getRandomIP()
|
os.Remove("./wgcf-identity.json")
|
||||||
}
|
|
||||||
if port == 0 {
|
|
||||||
port = generateRandomPort()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !warp.CheckProfileExists(license) {
|
if !warp.CheckProfileExists(license) {
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -3,7 +3,7 @@ module github.com/hiddify/libcore
|
|||||||
go 1.21.5
|
go 1.21.5
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/hiddify/ray2sing v0.0.0-20240127015415-b0b85dcbf102
|
github.com/hiddify/ray2sing v0.0.0-20240130180912-f90754dd8f44
|
||||||
github.com/kardianos/service v1.2.2
|
github.com/kardianos/service v1.2.2
|
||||||
github.com/sagernet/gomobile v0.1.1
|
github.com/sagernet/gomobile v0.1.1
|
||||||
github.com/sagernet/sing v0.3.0
|
github.com/sagernet/sing v0.3.0
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -51,8 +51,8 @@ github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE
|
|||||||
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
|
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
|
||||||
github.com/hiddify/hiddify-sing-box v1.7.9-0.20240130115748-5838de40349e h1:FhrU990kkhxRoFAMvEZwUyM05s1AWBn7lzwijl9ucq0=
|
github.com/hiddify/hiddify-sing-box v1.7.9-0.20240130115748-5838de40349e h1:FhrU990kkhxRoFAMvEZwUyM05s1AWBn7lzwijl9ucq0=
|
||||||
github.com/hiddify/hiddify-sing-box v1.7.9-0.20240130115748-5838de40349e/go.mod h1:B74zKdMcH3ZEmCi2OUqJTvEXCNtNQjivUEQ20y/5XQM=
|
github.com/hiddify/hiddify-sing-box v1.7.9-0.20240130115748-5838de40349e/go.mod h1:B74zKdMcH3ZEmCi2OUqJTvEXCNtNQjivUEQ20y/5XQM=
|
||||||
github.com/hiddify/ray2sing v0.0.0-20240127015415-b0b85dcbf102 h1:4vKmPE8AyvsBYuZmjGkPnsju8ZzVxEjC9I96uqxX5+o=
|
github.com/hiddify/ray2sing v0.0.0-20240130180912-f90754dd8f44 h1:A/gbpY8/5jhcoKPCLYpw+LO5MqlBZAsXm6nflWMDbjA=
|
||||||
github.com/hiddify/ray2sing v0.0.0-20240127015415-b0b85dcbf102/go.mod h1:zYKnf7EoPqrk7JOMO9BApTXxfH0sva8AKfoFywN7uuA=
|
github.com/hiddify/ray2sing v0.0.0-20240130180912-f90754dd8f44/go.mod h1:zYKnf7EoPqrk7JOMO9BApTXxfH0sva8AKfoFywN7uuA=
|
||||||
github.com/hiddify/wireguard-go v0.0.0-20240125143346-481d18d77fe1 h1:neOb+wzHbWLNZ2sHFEV4+GTuqORO7/MndQLFW8FjUY8=
|
github.com/hiddify/wireguard-go v0.0.0-20240125143346-481d18d77fe1 h1:neOb+wzHbWLNZ2sHFEV4+GTuqORO7/MndQLFW8FjUY8=
|
||||||
github.com/hiddify/wireguard-go v0.0.0-20240125143346-481d18d77fe1/go.mod h1:K4J7/npM+VAMUeUmTa2JaA02JmyheP0GpRBOUvn3ecc=
|
github.com/hiddify/wireguard-go v0.0.0-20240125143346-481d18d77fe1/go.mod h1:K4J7/npM+VAMUeUmTa2JaA02JmyheP0GpRBOUvn3ecc=
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||||
|
|||||||
Reference in New Issue
Block a user