diff options
| author | MHSanaei <ho3ein.sanaei@gmail.com> | 2023-07-18 02:10:22 +0300 |
|---|---|---|
| committer | MHSanaei <ho3ein.sanaei@gmail.com> | 2023-07-18 02:10:22 +0300 |
| commit | 1f78842b707a1190b6a84aded269d664254a7f1d (patch) | |
| tree | f9226bfda4856a6289a657cff21234738be4f8c3 /xray/api.go | |
| parent | 81a057d63876df5ba69260ac6b97aeeb7964c87d (diff) | |
[feature] using xray API for inbound
Co-Authored-By: Alireza Ahmadi <alireza7@gmail.com>
Diffstat (limited to 'xray/api.go')
| -rw-r--r-- | xray/api.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/xray/api.go b/xray/api.go index c2e2b4ca..99335076 100644 --- a/xray/api.go +++ b/xray/api.go @@ -2,15 +2,18 @@ package xray import ( "context" + "encoding/json" "fmt" "regexp" "time" + "x-ui/logger" "x-ui/util/common" "github.com/xtls/xray-core/app/proxyman/command" statsService "github.com/xtls/xray-core/app/stats/command" "github.com/xtls/xray-core/common/protocol" "github.com/xtls/xray-core/common/serial" + "github.com/xtls/xray-core/infra/conf" "github.com/xtls/xray-core/proxy/shadowsocks" "github.com/xtls/xray-core/proxy/trojan" "github.com/xtls/xray-core/proxy/vless" @@ -52,6 +55,33 @@ func (x *XrayAPI) Close() { x.isConnected = false } +func (x *XrayAPI) AddInbound(inbound []byte) error { + client := *x.HandlerServiceClient + + conf := new(conf.InboundDetourConfig) + err := json.Unmarshal(inbound, conf) + if err != nil { + logger.Debug("Failed to unmarshal inbound:", err) + } + config, err := conf.Build() + if err != nil { + logger.Debug("Failed to build inbound Detur:", err) + } + inboundConfig := command.AddInboundRequest{Inbound: config} + + _, err = client.AddInbound(context.Background(), &inboundConfig) + + return err +} + +func (x *XrayAPI) DelInbound(tag string) error { + client := *x.HandlerServiceClient + _, err := client.RemoveInbound(context.Background(), &command.RemoveInboundRequest{ + Tag: tag, + }) + return err +} + func (x *XrayAPI) AddUser(Protocol string, inboundTag string, user map[string]interface{}) error { var account *serial.TypedMessage switch Protocol { |
