diff --git a/3rdparty/QHotkey b/3rdparty/QHotkey index 52e25ac..bb63025 160000 --- a/3rdparty/QHotkey +++ b/3rdparty/QHotkey @@ -1 +1 @@ -Subproject commit 52e25acf221e5ac86ce648f6922620fb2d6a7121 +Subproject commit bb630252684d3556b79ac7a521616692f348fcf7 diff --git a/go/cmd/nekobox_core/core_box.go b/go/cmd/nekobox_core/core_box.go index b45162b..627b148 100644 --- a/go/cmd/nekobox_core/core_box.go +++ b/go/cmd/nekobox_core/core_box.go @@ -2,6 +2,8 @@ package main import ( "context" + "github.com/sagernet/sing-box/common/settings" + "github.com/sagernet/sing/common/metadata" "net" "net/http" @@ -13,6 +15,8 @@ import ( ) var instance *boxbox.Box +var systemProxyController settings.SystemProxy +var systemProxyAddr metadata.Socksaddr var instance_cancel context.CancelFunc func setupCore() { diff --git a/go/cmd/nekobox_core/grpc_box.go b/go/cmd/nekobox_core/grpc_box.go index 73f6e39..fe0ca5d 100644 --- a/go/cmd/nekobox_core/grpc_box.go +++ b/go/cmd/nekobox_core/grpc_box.go @@ -4,6 +4,8 @@ import ( "context" "errors" "fmt" + "github.com/sagernet/sing-box/common/settings" + "github.com/sagernet/sing/common/metadata" "strings" "time" @@ -201,3 +203,26 @@ func (s *server) CompileGeoSiteToSrs(ctx context.Context, in *gen.CompileGeoSite return &gen.EmptyResp{}, nil } + +func (s *server) SetSystemProxy(ctx context.Context, in *gen.SetSystemProxyRequest) (*gen.EmptyResp, error) { + var err error + addr := metadata.ParseSocksaddr(in.Address) + if systemProxyController == nil || systemProxyAddr.String() != addr.String() { + systemProxyController, err = settings.NewSystemProxy(context.Background(), addr, true) + if err != nil { + return nil, err + } + systemProxyAddr = addr + } + if in.Enable && !systemProxyController.IsEnabled() { + err = systemProxyController.Enable() + } + if !in.Enable && systemProxyController.IsEnabled() { + err = systemProxyController.Disable() + } + if err != nil { + return nil, err + } + + return &gen.EmptyResp{}, nil +} diff --git a/go/cmd/nekobox_core/main.go b/go/cmd/nekobox_core/main.go index 7d5b17b..a7f46eb 100644 --- a/go/cmd/nekobox_core/main.go +++ b/go/cmd/nekobox_core/main.go @@ -2,28 +2,18 @@ package main import ( "fmt" - "os" _ "unsafe" "grpc_server" "github.com/Mahdi-zarei/sing-box-extra/boxbox" - "github.com/Mahdi-zarei/sing-box-extra/boxmain" _ "github.com/Mahdi-zarei/sing-box-extra/distro/all" - "github.com/matsuridayo/libneko/neko_common" ) func main() { fmt.Println("sing-box:", boxbox.Version) fmt.Println() - // nekobox_core - if len(os.Args) > 1 && os.Args[1] == "nekobox" { - neko_common.RunMode = neko_common.RunMode_NekoBox_Core - grpc_server.RunCore(setupCore, &server{}) - return - } - - // sing-box - boxmain.Main() + grpc_server.RunCore(setupCore, &server{}) + return } diff --git a/go/grpc_server/gen/libcore.pb.go b/go/grpc_server/gen/libcore.pb.go index 600a7c3..b22cc1d 100644 --- a/go/grpc_server/gen/libcore.pb.go +++ b/go/grpc_server/gen/libcore.pb.go @@ -1007,6 +1007,61 @@ func (x *CompileGeoSiteToSrsRequest) GetItem() string { return "" } +type SetSystemProxyRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Enable bool `protobuf:"varint,1,opt,name=enable,proto3" json:"enable,omitempty"` + Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` +} + +func (x *SetSystemProxyRequest) Reset() { + *x = SetSystemProxyRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_libcore_proto_msgTypes[15] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SetSystemProxyRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SetSystemProxyRequest) ProtoMessage() {} + +func (x *SetSystemProxyRequest) ProtoReflect() protoreflect.Message { + mi := &file_libcore_proto_msgTypes[15] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SetSystemProxyRequest.ProtoReflect.Descriptor instead. +func (*SetSystemProxyRequest) Descriptor() ([]byte, []int) { + return file_libcore_proto_rawDescGZIP(), []int{15} +} + +func (x *SetSystemProxyRequest) GetEnable() bool { + if x != nil { + return x.Enable + } + return false +} + +func (x *SetSystemProxyRequest) GetAddress() string { + if x != nil { + return x.Address + } + return "" +} + var File_libcore_proto protoreflect.FileDescriptor var file_libcore_proto_rawDesc = []byte{ @@ -1105,58 +1160,67 @@ var file_libcore_proto_rawDesc = []byte{ 0x28, 0x09, 0x52, 0x04, 0x69, 0x74, 0x65, 0x6d, 0x22, 0x30, 0x0a, 0x1a, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x47, 0x65, 0x6f, 0x53, 0x69, 0x74, 0x65, 0x54, 0x6f, 0x53, 0x72, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x69, 0x74, 0x65, 0x6d, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x69, 0x74, 0x65, 0x6d, 0x2a, 0x32, 0x0a, 0x08, 0x54, 0x65, - 0x73, 0x74, 0x4d, 0x6f, 0x64, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x54, 0x63, 0x70, 0x50, 0x69, 0x6e, - 0x67, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x72, 0x6c, 0x54, 0x65, 0x73, 0x74, 0x10, 0x01, - 0x12, 0x0c, 0x0a, 0x08, 0x46, 0x75, 0x6c, 0x6c, 0x54, 0x65, 0x73, 0x74, 0x10, 0x02, 0x2a, 0x27, - 0x0a, 0x0c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x09, - 0x0a, 0x05, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x44, 0x6f, 0x77, - 0x6e, 0x6c, 0x6f, 0x61, 0x64, 0x10, 0x01, 0x32, 0xb8, 0x05, 0x0a, 0x0e, 0x4c, 0x69, 0x62, 0x63, - 0x6f, 0x72, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x2f, 0x0a, 0x04, 0x45, 0x78, - 0x69, 0x74, 0x12, 0x11, 0x2e, 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x45, 0x6d, 0x70, - 0x74, 0x79, 0x52, 0x65, 0x71, 0x1a, 0x12, 0x2e, 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, - 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x33, 0x0a, 0x06, 0x55, - 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x12, 0x2e, 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, - 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x1a, 0x13, 0x2e, 0x6c, 0x69, 0x62, 0x63, - 0x6f, 0x72, 0x65, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, - 0x12, 0x35, 0x0a, 0x05, 0x53, 0x74, 0x61, 0x72, 0x74, 0x12, 0x16, 0x2e, 0x6c, 0x69, 0x62, 0x63, - 0x6f, 0x72, 0x65, 0x2e, 0x4c, 0x6f, 0x61, 0x64, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, - 0x71, 0x1a, 0x12, 0x2e, 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x45, 0x72, 0x72, 0x6f, - 0x72, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x2f, 0x0a, 0x04, 0x53, 0x74, 0x6f, 0x70, 0x12, - 0x11, 0x2e, 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, - 0x65, 0x71, 0x1a, 0x12, 0x2e, 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x45, 0x72, 0x72, - 0x6f, 0x72, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x2d, 0x0a, 0x04, 0x54, 0x65, 0x73, 0x74, - 0x12, 0x10, 0x2e, 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x54, 0x65, 0x73, 0x74, 0x52, - 0x65, 0x71, 0x1a, 0x11, 0x2e, 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x54, 0x65, 0x73, - 0x74, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x3f, 0x0a, 0x0a, 0x51, 0x75, 0x65, 0x72, 0x79, - 0x53, 0x74, 0x61, 0x74, 0x73, 0x12, 0x16, 0x2e, 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, - 0x51, 0x75, 0x65, 0x72, 0x79, 0x53, 0x74, 0x61, 0x74, 0x73, 0x52, 0x65, 0x71, 0x1a, 0x17, 0x2e, - 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x53, 0x74, 0x61, - 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x44, 0x0a, 0x0f, 0x4c, 0x69, 0x73, 0x74, - 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x11, 0x2e, 0x6c, 0x69, - 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, 0x65, 0x71, 0x1a, 0x1c, - 0x2e, 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x43, 0x6f, 0x6e, - 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x40, - 0x0a, 0x0c, 0x47, 0x65, 0x74, 0x47, 0x65, 0x6f, 0x49, 0x50, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x11, - 0x2e, 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, 0x65, - 0x71, 0x1a, 0x1d, 0x2e, 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x47, - 0x65, 0x6f, 0x49, 0x50, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x12, 0x44, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x47, 0x65, 0x6f, 0x53, 0x69, 0x74, 0x65, 0x4c, 0x69, - 0x73, 0x74, 0x12, 0x11, 0x2e, 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x45, 0x6d, 0x70, - 0x74, 0x79, 0x52, 0x65, 0x71, 0x1a, 0x1f, 0x2e, 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, - 0x47, 0x65, 0x74, 0x47, 0x65, 0x6f, 0x53, 0x69, 0x74, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4a, 0x0a, 0x11, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, - 0x65, 0x47, 0x65, 0x6f, 0x49, 0x50, 0x54, 0x6f, 0x53, 0x72, 0x73, 0x12, 0x21, 0x2e, 0x6c, 0x69, - 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x47, 0x65, 0x6f, - 0x49, 0x50, 0x54, 0x6f, 0x53, 0x72, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, - 0x2e, 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, 0x65, - 0x73, 0x70, 0x12, 0x4e, 0x0a, 0x13, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x47, 0x65, 0x6f, - 0x53, 0x69, 0x74, 0x65, 0x54, 0x6f, 0x53, 0x72, 0x73, 0x12, 0x23, 0x2e, 0x6c, 0x69, 0x62, 0x63, - 0x6f, 0x72, 0x65, 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x47, 0x65, 0x6f, 0x53, 0x69, - 0x74, 0x65, 0x54, 0x6f, 0x53, 0x72, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, - 0x2e, 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, 0x65, - 0x73, 0x70, 0x42, 0x11, 0x5a, 0x0f, 0x67, 0x72, 0x70, 0x63, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x65, - 0x72, 0x2f, 0x67, 0x65, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x69, 0x74, 0x65, 0x6d, 0x22, 0x49, 0x0a, 0x15, 0x53, 0x65, + 0x74, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x08, 0x52, 0x06, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x61, + 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, + 0x64, 0x72, 0x65, 0x73, 0x73, 0x2a, 0x32, 0x0a, 0x08, 0x54, 0x65, 0x73, 0x74, 0x4d, 0x6f, 0x64, + 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x54, 0x63, 0x70, 0x50, 0x69, 0x6e, 0x67, 0x10, 0x00, 0x12, 0x0b, + 0x0a, 0x07, 0x55, 0x72, 0x6c, 0x54, 0x65, 0x73, 0x74, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x46, + 0x75, 0x6c, 0x6c, 0x54, 0x65, 0x73, 0x74, 0x10, 0x02, 0x2a, 0x27, 0x0a, 0x0c, 0x55, 0x70, 0x64, + 0x61, 0x74, 0x65, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x09, 0x0a, 0x05, 0x43, 0x68, 0x65, + 0x63, 0x6b, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x44, 0x6f, 0x77, 0x6e, 0x6c, 0x6f, 0x61, 0x64, + 0x10, 0x01, 0x32, 0xfe, 0x05, 0x0a, 0x0e, 0x4c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x53, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x2f, 0x0a, 0x04, 0x45, 0x78, 0x69, 0x74, 0x12, 0x11, 0x2e, + 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, 0x65, 0x71, + 0x1a, 0x12, 0x2e, 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, + 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x33, 0x0a, 0x06, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x12, 0x12, 0x2e, 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, + 0x65, 0x52, 0x65, 0x71, 0x1a, 0x13, 0x2e, 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x55, + 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x35, 0x0a, 0x05, 0x53, + 0x74, 0x61, 0x72, 0x74, 0x12, 0x16, 0x2e, 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x4c, + 0x6f, 0x61, 0x64, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, 0x71, 0x1a, 0x12, 0x2e, 0x6c, + 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x52, 0x65, 0x73, 0x70, + 0x22, 0x00, 0x12, 0x2f, 0x0a, 0x04, 0x53, 0x74, 0x6f, 0x70, 0x12, 0x11, 0x2e, 0x6c, 0x69, 0x62, + 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, 0x65, 0x71, 0x1a, 0x12, 0x2e, + 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x52, 0x65, 0x73, + 0x70, 0x22, 0x00, 0x12, 0x2d, 0x0a, 0x04, 0x54, 0x65, 0x73, 0x74, 0x12, 0x10, 0x2e, 0x6c, 0x69, + 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x54, 0x65, 0x73, 0x74, 0x52, 0x65, 0x71, 0x1a, 0x11, 0x2e, + 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x54, 0x65, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, + 0x22, 0x00, 0x12, 0x3f, 0x0a, 0x0a, 0x51, 0x75, 0x65, 0x72, 0x79, 0x53, 0x74, 0x61, 0x74, 0x73, + 0x12, 0x16, 0x2e, 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, + 0x53, 0x74, 0x61, 0x74, 0x73, 0x52, 0x65, 0x71, 0x1a, 0x17, 0x2e, 0x6c, 0x69, 0x62, 0x63, 0x6f, + 0x72, 0x65, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x53, 0x74, 0x61, 0x74, 0x73, 0x52, 0x65, 0x73, + 0x70, 0x22, 0x00, 0x12, 0x44, 0x0a, 0x0f, 0x4c, 0x69, 0x73, 0x74, 0x43, 0x6f, 0x6e, 0x6e, 0x65, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x11, 0x2e, 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, + 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, 0x65, 0x71, 0x1a, 0x1c, 0x2e, 0x6c, 0x69, 0x62, 0x63, + 0x6f, 0x72, 0x65, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x73, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x40, 0x0a, 0x0c, 0x47, 0x65, 0x74, + 0x47, 0x65, 0x6f, 0x49, 0x50, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x11, 0x2e, 0x6c, 0x69, 0x62, 0x63, + 0x6f, 0x72, 0x65, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, 0x65, 0x71, 0x1a, 0x1d, 0x2e, 0x6c, + 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x47, 0x65, 0x6f, 0x49, 0x50, 0x4c, + 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x44, 0x0a, 0x0e, 0x47, + 0x65, 0x74, 0x47, 0x65, 0x6f, 0x53, 0x69, 0x74, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x11, 0x2e, + 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, 0x65, 0x71, + 0x1a, 0x1f, 0x2e, 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x47, 0x65, + 0x6f, 0x53, 0x69, 0x74, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x4a, 0x0a, 0x11, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x47, 0x65, 0x6f, 0x49, + 0x50, 0x54, 0x6f, 0x53, 0x72, 0x73, 0x12, 0x21, 0x2e, 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, + 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x47, 0x65, 0x6f, 0x49, 0x50, 0x54, 0x6f, 0x53, + 0x72, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x6c, 0x69, 0x62, 0x63, + 0x6f, 0x72, 0x65, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, 0x65, 0x73, 0x70, 0x12, 0x4e, 0x0a, + 0x13, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x47, 0x65, 0x6f, 0x53, 0x69, 0x74, 0x65, 0x54, + 0x6f, 0x53, 0x72, 0x73, 0x12, 0x23, 0x2e, 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x43, + 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x47, 0x65, 0x6f, 0x53, 0x69, 0x74, 0x65, 0x54, 0x6f, 0x53, + 0x72, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x6c, 0x69, 0x62, 0x63, + 0x6f, 0x72, 0x65, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, 0x65, 0x73, 0x70, 0x12, 0x44, 0x0a, + 0x0e, 0x53, 0x65, 0x74, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x12, + 0x1e, 0x2e, 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x53, 0x65, 0x74, 0x53, 0x79, 0x73, + 0x74, 0x65, 0x6d, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x12, 0x2e, 0x6c, 0x69, 0x62, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, + 0x65, 0x73, 0x70, 0x42, 0x11, 0x5a, 0x0f, 0x67, 0x72, 0x70, 0x63, 0x5f, 0x73, 0x65, 0x72, 0x76, + 0x65, 0x72, 0x2f, 0x67, 0x65, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -1172,7 +1236,7 @@ func file_libcore_proto_rawDescGZIP() []byte { } var file_libcore_proto_enumTypes = make([]protoimpl.EnumInfo, 2) -var file_libcore_proto_msgTypes = make([]protoimpl.MessageInfo, 15) +var file_libcore_proto_msgTypes = make([]protoimpl.MessageInfo, 16) var file_libcore_proto_goTypes = []interface{}{ (TestMode)(0), // 0: libcore.TestMode (UpdateAction)(0), // 1: libcore.UpdateAction @@ -1191,6 +1255,7 @@ var file_libcore_proto_goTypes = []interface{}{ (*GetGeoSiteListResponse)(nil), // 14: libcore.GetGeoSiteListResponse (*CompileGeoIPToSrsRequest)(nil), // 15: libcore.CompileGeoIPToSrsRequest (*CompileGeoSiteToSrsRequest)(nil), // 16: libcore.CompileGeoSiteToSrsRequest + (*SetSystemProxyRequest)(nil), // 17: libcore.SetSystemProxyRequest } var file_libcore_proto_depIdxs = []int32{ 0, // 0: libcore.TestReq.mode:type_name -> libcore.TestMode @@ -1207,19 +1272,21 @@ var file_libcore_proto_depIdxs = []int32{ 2, // 11: libcore.LibcoreService.GetGeoSiteList:input_type -> libcore.EmptyReq 15, // 12: libcore.LibcoreService.CompileGeoIPToSrs:input_type -> libcore.CompileGeoIPToSrsRequest 16, // 13: libcore.LibcoreService.CompileGeoSiteToSrs:input_type -> libcore.CompileGeoSiteToSrsRequest - 3, // 14: libcore.LibcoreService.Exit:output_type -> libcore.EmptyResp - 11, // 15: libcore.LibcoreService.Update:output_type -> libcore.UpdateResp - 4, // 16: libcore.LibcoreService.Start:output_type -> libcore.ErrorResp - 4, // 17: libcore.LibcoreService.Stop:output_type -> libcore.ErrorResp - 7, // 18: libcore.LibcoreService.Test:output_type -> libcore.TestResp - 9, // 19: libcore.LibcoreService.QueryStats:output_type -> libcore.QueryStatsResp - 12, // 20: libcore.LibcoreService.ListConnections:output_type -> libcore.ListConnectionsResp - 13, // 21: libcore.LibcoreService.GetGeoIPList:output_type -> libcore.GetGeoIPListResponse - 14, // 22: libcore.LibcoreService.GetGeoSiteList:output_type -> libcore.GetGeoSiteListResponse - 3, // 23: libcore.LibcoreService.CompileGeoIPToSrs:output_type -> libcore.EmptyResp - 3, // 24: libcore.LibcoreService.CompileGeoSiteToSrs:output_type -> libcore.EmptyResp - 14, // [14:25] is the sub-list for method output_type - 3, // [3:14] is the sub-list for method input_type + 17, // 14: libcore.LibcoreService.SetSystemProxy:input_type -> libcore.SetSystemProxyRequest + 3, // 15: libcore.LibcoreService.Exit:output_type -> libcore.EmptyResp + 11, // 16: libcore.LibcoreService.Update:output_type -> libcore.UpdateResp + 4, // 17: libcore.LibcoreService.Start:output_type -> libcore.ErrorResp + 4, // 18: libcore.LibcoreService.Stop:output_type -> libcore.ErrorResp + 7, // 19: libcore.LibcoreService.Test:output_type -> libcore.TestResp + 9, // 20: libcore.LibcoreService.QueryStats:output_type -> libcore.QueryStatsResp + 12, // 21: libcore.LibcoreService.ListConnections:output_type -> libcore.ListConnectionsResp + 13, // 22: libcore.LibcoreService.GetGeoIPList:output_type -> libcore.GetGeoIPListResponse + 14, // 23: libcore.LibcoreService.GetGeoSiteList:output_type -> libcore.GetGeoSiteListResponse + 3, // 24: libcore.LibcoreService.CompileGeoIPToSrs:output_type -> libcore.EmptyResp + 3, // 25: libcore.LibcoreService.CompileGeoSiteToSrs:output_type -> libcore.EmptyResp + 3, // 26: libcore.LibcoreService.SetSystemProxy:output_type -> libcore.EmptyResp + 15, // [15:27] is the sub-list for method output_type + 3, // [3:15] is the sub-list for method input_type 3, // [3:3] is the sub-list for extension type_name 3, // [3:3] is the sub-list for extension extendee 0, // [0:3] is the sub-list for field type_name @@ -1411,6 +1478,18 @@ func file_libcore_proto_init() { return nil } } + file_libcore_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SetSystemProxyRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -1418,7 +1497,7 @@ func file_libcore_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_libcore_proto_rawDesc, NumEnums: 2, - NumMessages: 15, + NumMessages: 16, NumExtensions: 0, NumServices: 1, }, diff --git a/go/grpc_server/gen/libcore.proto b/go/grpc_server/gen/libcore.proto index d914a19..28610b3 100644 --- a/go/grpc_server/gen/libcore.proto +++ b/go/grpc_server/gen/libcore.proto @@ -17,6 +17,8 @@ service LibcoreService { rpc GetGeoSiteList(EmptyReq) returns (GetGeoSiteListResponse); rpc CompileGeoIPToSrs(CompileGeoIPToSrsRequest) returns (EmptyResp); rpc CompileGeoSiteToSrs(CompileGeoSiteToSrsRequest) returns (EmptyResp); + // + rpc SetSystemProxy(SetSystemProxyRequest) returns (EmptyResp); } message EmptyReq {} @@ -113,4 +115,9 @@ message CompileGeoIPToSrsRequest { message CompileGeoSiteToSrsRequest { string item = 1; +} + +message SetSystemProxyRequest { + bool enable = 1; + string address = 2; } \ No newline at end of file diff --git a/go/grpc_server/gen/libcore_grpc.pb.go b/go/grpc_server/gen/libcore_grpc.pb.go index 834e861..f90d401 100644 --- a/go/grpc_server/gen/libcore_grpc.pb.go +++ b/go/grpc_server/gen/libcore_grpc.pb.go @@ -30,6 +30,7 @@ const ( LibcoreService_GetGeoSiteList_FullMethodName = "/libcore.LibcoreService/GetGeoSiteList" LibcoreService_CompileGeoIPToSrs_FullMethodName = "/libcore.LibcoreService/CompileGeoIPToSrs" LibcoreService_CompileGeoSiteToSrs_FullMethodName = "/libcore.LibcoreService/CompileGeoSiteToSrs" + LibcoreService_SetSystemProxy_FullMethodName = "/libcore.LibcoreService/SetSystemProxy" ) // LibcoreServiceClient is the client API for LibcoreService service. @@ -47,6 +48,7 @@ type LibcoreServiceClient interface { GetGeoSiteList(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*GetGeoSiteListResponse, error) CompileGeoIPToSrs(ctx context.Context, in *CompileGeoIPToSrsRequest, opts ...grpc.CallOption) (*EmptyResp, error) CompileGeoSiteToSrs(ctx context.Context, in *CompileGeoSiteToSrsRequest, opts ...grpc.CallOption) (*EmptyResp, error) + SetSystemProxy(ctx context.Context, in *SetSystemProxyRequest, opts ...grpc.CallOption) (*EmptyResp, error) } type libcoreServiceClient struct { @@ -156,6 +158,15 @@ func (c *libcoreServiceClient) CompileGeoSiteToSrs(ctx context.Context, in *Comp return out, nil } +func (c *libcoreServiceClient) SetSystemProxy(ctx context.Context, in *SetSystemProxyRequest, opts ...grpc.CallOption) (*EmptyResp, error) { + out := new(EmptyResp) + err := c.cc.Invoke(ctx, LibcoreService_SetSystemProxy_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // LibcoreServiceServer is the server API for LibcoreService service. // All implementations must embed UnimplementedLibcoreServiceServer // for forward compatibility @@ -171,6 +182,7 @@ type LibcoreServiceServer interface { GetGeoSiteList(context.Context, *EmptyReq) (*GetGeoSiteListResponse, error) CompileGeoIPToSrs(context.Context, *CompileGeoIPToSrsRequest) (*EmptyResp, error) CompileGeoSiteToSrs(context.Context, *CompileGeoSiteToSrsRequest) (*EmptyResp, error) + SetSystemProxy(context.Context, *SetSystemProxyRequest) (*EmptyResp, error) mustEmbedUnimplementedLibcoreServiceServer() } @@ -211,6 +223,9 @@ func (UnimplementedLibcoreServiceServer) CompileGeoIPToSrs(context.Context, *Com func (UnimplementedLibcoreServiceServer) CompileGeoSiteToSrs(context.Context, *CompileGeoSiteToSrsRequest) (*EmptyResp, error) { return nil, status.Errorf(codes.Unimplemented, "method CompileGeoSiteToSrs not implemented") } +func (UnimplementedLibcoreServiceServer) SetSystemProxy(context.Context, *SetSystemProxyRequest) (*EmptyResp, error) { + return nil, status.Errorf(codes.Unimplemented, "method SetSystemProxy not implemented") +} func (UnimplementedLibcoreServiceServer) mustEmbedUnimplementedLibcoreServiceServer() {} // UnsafeLibcoreServiceServer may be embedded to opt out of forward compatibility for this service. @@ -422,6 +437,24 @@ func _LibcoreService_CompileGeoSiteToSrs_Handler(srv interface{}, ctx context.Co return interceptor(ctx, in, info, handler) } +func _LibcoreService_SetSystemProxy_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SetSystemProxyRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(LibcoreServiceServer).SetSystemProxy(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: LibcoreService_SetSystemProxy_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(LibcoreServiceServer).SetSystemProxy(ctx, req.(*SetSystemProxyRequest)) + } + return interceptor(ctx, in, info, handler) +} + // LibcoreService_ServiceDesc is the grpc.ServiceDesc for LibcoreService service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -473,6 +506,10 @@ var LibcoreService_ServiceDesc = grpc.ServiceDesc{ MethodName: "CompileGeoSiteToSrs", Handler: _LibcoreService_CompileGeoSiteToSrs_Handler, }, + { + MethodName: "SetSystemProxy", + Handler: _LibcoreService_SetSystemProxy_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "libcore.proto", diff --git a/go/grpc_server/grpc.go b/go/grpc_server/grpc.go index 772dd60..210f780 100644 --- a/go/grpc_server/grpc.go +++ b/go/grpc_server/grpc.go @@ -94,10 +94,7 @@ func RunCore(setupCore func(), server gen.LibcoreServiceServer) { ) gen.RegisterLibcoreServiceServer(s, server) - name := "nekoray_core" - if neko_common.RunMode == neko_common.RunMode_NekoBox_Core { - name = "nekobox_core" - } + name := "nekobox_core" log.Printf("%s grpc server listening at %v\n", name, lis.Addr()) if err := s.Serve(lis); err != nil { diff --git a/rpc/gRPC.cpp b/rpc/gRPC.cpp index 6a59414..cc84bcb 100644 --- a/rpc/gRPC.cpp +++ b/rpc/gRPC.cpp @@ -354,4 +354,20 @@ namespace NekoGui_rpc { } } + QString Client::SetSystemProxy(bool *rpcOK, bool enable) { + libcore::SetSystemProxyRequest req; + libcore::EmptyResp resp; + req.set_enable(enable); + req.set_address(QString(NekoGui::dataStore->inbound_address + ":" + Int2String(NekoGui::dataStore->inbound_socks_port)).toStdString()); + + auto status = default_grpc_channel->Call("SetSystemProxy", req, &resp); + if (status == QNetworkReply::NoError) { + *rpcOK = true; + return ""; + } else { + NOT_OK + return qt_error_string(status); + } + } + } // namespace NekoGui_rpc diff --git a/rpc/gRPC.h b/rpc/gRPC.h index b803879..fe6650e 100644 --- a/rpc/gRPC.h +++ b/rpc/gRPC.h @@ -34,6 +34,8 @@ namespace NekoGui_rpc { QString CompileGeoSet(bool *rpcOK, GeoRuleSetType mode, std::string category); + QString SetSystemProxy(bool *rpcOK, bool enable); + private: std::function()> make_grpc_channel; std::unique_ptr default_grpc_channel; diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index 8134ab3..c5e12f7 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -691,28 +691,6 @@ void MainWindow::on_menu_exit_triggered() { refresh_status(); \ return; -void MainWindow::neko_set_spmode_system_proxy(bool enable, bool save) { - if (enable != NekoGui::dataStore->spmode_system_proxy) { - if (enable) { - auto socks_port = NekoGui::dataStore->inbound_socks_port; - SetSystemProxy(socks_port, socks_port); - } else { - ClearSystemProxy(); - } - } - - if (save) { - NekoGui::dataStore->remember_spmode.removeAll("system_proxy"); - if (enable && NekoGui::dataStore->remember_enable) { - NekoGui::dataStore->remember_spmode.append("system_proxy"); - } - NekoGui::dataStore->Save(); - } - - NekoGui::dataStore->spmode_system_proxy = enable; - refresh_status(); -} - void MainWindow::neko_toggle_system_proxy() { auto currentState = NekoGui::dataStore->spmode_system_proxy; if (currentState) { diff --git a/ui/mainwindow_grpc.cpp b/ui/mainwindow_grpc.cpp index d1e0a88..3dccd2d 100644 --- a/ui/mainwindow_grpc.cpp +++ b/ui/mainwindow_grpc.cpp @@ -384,6 +384,30 @@ void MainWindow::neko_start(int _id) { }); } +void MainWindow::neko_set_spmode_system_proxy(bool enable, bool save) { + if (enable != NekoGui::dataStore->spmode_system_proxy) { + bool ok; + auto error = defaultClient->SetSystemProxy(&ok, enable); + if (!ok) { + MW_show_log("Failed to set system proxy with error " + error); + ui->checkBox_SystemProxy->setChecked(false); + refresh_status(); + return; + } + } + + if (save) { + NekoGui::dataStore->remember_spmode.removeAll("system_proxy"); + if (enable && NekoGui::dataStore->remember_enable) { + NekoGui::dataStore->remember_spmode.append("system_proxy"); + } + NekoGui::dataStore->Save(); + } + + NekoGui::dataStore->spmode_system_proxy = enable; + refresh_status(); +} + void MainWindow::neko_stop(bool crash, bool sem) { auto id = NekoGui::dataStore->started_id; if (id < 0) {