fix: bugs and issues
This commit is contained in:
@@ -4,6 +4,7 @@ package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
@@ -19,20 +20,11 @@ func ExecuteCmd(exe string, background bool, args ...string) (string, error) {
|
||||
verbPtr, _ := syscall.UTF16PtrFromString(verb)
|
||||
exePtr, _ := syscall.UTF16PtrFromString(exe)
|
||||
cwdPtr, _ := syscall.UTF16PtrFromString(cwd)
|
||||
argPtr, _ := syscall.UTF16PtrFromString(strings.Join(args, " "))
|
||||
|
||||
// Convert args to UTF16Ptr slice
|
||||
var argsPtr []*uint16
|
||||
for _, arg := range args {
|
||||
argPtr, err := syscall.UTF16PtrFromString(arg)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
argsPtr = append(argsPtr, argPtr)
|
||||
}
|
||||
var showCmd int32 = 0 // SW_NORMAL
|
||||
|
||||
var showCmd int32 = 1 // SW_NORMAL
|
||||
|
||||
err = windows.ShellExecute(0, verbPtr, exePtr, nil, cwdPtr, showCmd)
|
||||
err = windows.ShellExecute(0, verbPtr, exePtr, argPtr, cwdPtr, showCmd)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -3,13 +3,12 @@ package config
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/sagernet/sing-box/option"
|
||||
dns "github.com/sagernet/sing-dns"
|
||||
@@ -21,15 +20,18 @@ const (
|
||||
stopEndpoint = "/stop"
|
||||
)
|
||||
|
||||
var tunnelServiceRunning = false
|
||||
|
||||
func isSupportedOS() bool {
|
||||
return runtime.GOOS == "windows" || runtime.GOOS == "linux"
|
||||
}
|
||||
func ActivateTunnelService(opt ConfigOptions) (bool, error) {
|
||||
tunnelServiceRunning = true
|
||||
// if !isSupportedOS() {
|
||||
// return false, E.New("Unsupported OS: " + runtime.GOOS)
|
||||
// }
|
||||
|
||||
go startTunnelRequest(opt, true)
|
||||
go startTunnelRequestWithFailover(opt, true)
|
||||
return true, nil
|
||||
}
|
||||
|
||||
@@ -37,11 +39,25 @@ func DeactivateTunnelService() (bool, error) {
|
||||
// if !isSupportedOS() {
|
||||
// return true, nil
|
||||
// }
|
||||
if tunnelServiceRunning {
|
||||
stopTunnelRequest()
|
||||
}
|
||||
tunnelServiceRunning = false
|
||||
|
||||
go stopTunnelRequest()
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func startTunnelRequestWithFailover(opt ConfigOptions, installService bool) {
|
||||
res, err := startTunnelRequest(opt, installService)
|
||||
fmt.Printf("Start Tunnel Result: %v\n", res)
|
||||
if err != nil {
|
||||
|
||||
fmt.Printf("Start Tunnel Failed! Stopping core... err=%v\n", err)
|
||||
// StopAndAlert(pb.MessageType.MessageType_UNEXPECTED_ERROR, "Start Tunnel Failed! Stopping...")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func startTunnelRequest(opt ConfigOptions, installService bool) (bool, error) {
|
||||
params := map[string]interface{}{
|
||||
"Ipv6": opt.IPv6Mode == option.DomainStrategy(dns.DomainStrategyUseIPv4),
|
||||
@@ -83,9 +99,9 @@ func stopTunnelRequest() (bool, error) {
|
||||
defer response.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(response.Body)
|
||||
fmt.Printf("Response Code: %d %s. Response Body: %s Error:%v\n", response.StatusCode, response.Status, body, err)
|
||||
// fmt.Printf("Response Code: %d %s. Response Body: %s Error:%v\n", response.StatusCode, response.Status, body, err)
|
||||
if err != nil || response.StatusCode != http.StatusOK {
|
||||
return false, fmt.Errorf("Unexpected Status Code: %d %s. Response Body: %s error:%v", response.StatusCode, response.Status, body, err)
|
||||
return false, fmt.Errorf("unexpected Status Code: %d %s. Response Body: %s error:%v", response.StatusCode, response.Status, body, err)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
|
||||
@@ -394,13 +394,16 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro
|
||||
var outbounds []option.Outbound
|
||||
var tags []string
|
||||
OutboundMainProxyTag = OutboundSelectTag
|
||||
if opt.Warp.EnableWarp && (opt.Warp.Mode == WarpOverProxy || opt.Warp.Mode == ProxyOverWarp) {
|
||||
//inbound==warp over proxies
|
||||
//outbound==proxies over warp
|
||||
if opt.Warp.EnableWarp && (opt.Warp.Mode == "inbound" || opt.Warp.Mode == "outbound") {
|
||||
|
||||
out, err := generateWarpSingbox(opt.Warp.WireguardConfig.ToWireguardConfig(), opt.Warp.CleanIP, opt.Warp.CleanPort, opt.Warp.FakePackets, opt.Warp.FakePacketSize, opt.Warp.FakePacketDelay)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to generate warp config: %v", err)
|
||||
}
|
||||
out.Tag = "Hiddify Warp ✅"
|
||||
if opt.Warp.Mode == WarpOverProxy {
|
||||
if opt.Warp.Mode == "inbound" {
|
||||
out.WireGuardOptions.Detour = OutboundURLTestTag
|
||||
OutboundMainProxyTag = out.Tag
|
||||
} else {
|
||||
@@ -531,7 +534,7 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro
|
||||
}
|
||||
|
||||
func patchHiddifyWarpFromConfig(out option.Outbound, opt ConfigOptions) option.Outbound {
|
||||
if opt.Warp.EnableWarp && opt.Warp.Mode == ProxyOverWarp {
|
||||
if opt.Warp.EnableWarp && opt.Warp.Mode == "outbound" {
|
||||
if out.DirectOptions.Detour == "" {
|
||||
out.DirectOptions.Detour = "Hiddify Warp ✅"
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ type InboundOptions struct {
|
||||
LocalDnsPort uint16 `json:"local-dns-port"`
|
||||
MTU uint32 `json:"mtu"`
|
||||
StrictRoute bool `json:"strict-route"`
|
||||
TUNStack string `json:"tun-stack"`
|
||||
TUNStack string `json:"tun-implementation"`
|
||||
}
|
||||
|
||||
type URLTestOptions struct {
|
||||
|
||||
Reference in New Issue
Block a user