mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-02-27 20:53:01 +00:00
fix: add nil checks in xray API to prevent panics
This commit is contained in:
parent
87265403c5
commit
f754246e3e
1 changed files with 12 additions and 0 deletions
12
xray/api.go
12
xray/api.go
|
|
@ -72,6 +72,9 @@ func (x *XrayAPI) Close() {
|
|||
|
||||
// AddInbound adds a new inbound configuration to the Xray core via gRPC.
|
||||
func (x *XrayAPI) AddInbound(inbound []byte) error {
|
||||
if x.HandlerServiceClient == nil {
|
||||
return common.NewError("xray handler service client is not initialized")
|
||||
}
|
||||
client := *x.HandlerServiceClient
|
||||
|
||||
conf := new(conf.InboundDetourConfig)
|
||||
|
|
@ -94,6 +97,9 @@ func (x *XrayAPI) AddInbound(inbound []byte) error {
|
|||
|
||||
// DelInbound removes an inbound configuration from the Xray core by tag.
|
||||
func (x *XrayAPI) DelInbound(tag string) error {
|
||||
if x.HandlerServiceClient == nil {
|
||||
return common.NewError("xray handler service client is not initialized")
|
||||
}
|
||||
client := *x.HandlerServiceClient
|
||||
_, err := client.RemoveInbound(context.Background(), &command.RemoveInboundRequest{
|
||||
Tag: tag,
|
||||
|
|
@ -103,6 +109,9 @@ func (x *XrayAPI) DelInbound(tag string) error {
|
|||
|
||||
// AddUser adds a user to an inbound in the Xray core using the specified protocol and user data.
|
||||
func (x *XrayAPI) AddUser(Protocol string, inboundTag string, user map[string]any) error {
|
||||
if x.HandlerServiceClient == nil {
|
||||
return common.NewError("xray handler service client is not initialized")
|
||||
}
|
||||
var account *serial.TypedMessage
|
||||
switch Protocol {
|
||||
case "vmess":
|
||||
|
|
@ -187,6 +196,9 @@ func (x *XrayAPI) AddUser(Protocol string, inboundTag string, user map[string]an
|
|||
|
||||
// RemoveUser removes a user from an inbound in the Xray core by email.
|
||||
func (x *XrayAPI) RemoveUser(inboundTag, email string) error {
|
||||
if x.HandlerServiceClient == nil {
|
||||
return common.NewError("xray handler service client is not initialized")
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue