diff --git a/cmd/disconnect.go b/cmd/disconnect.go index d6c1a70..17e5503 100644 --- a/cmd/disconnect.go +++ b/cmd/disconnect.go @@ -1,12 +1,15 @@ package cmd import ( + "encoding/json" "os" "path/filepath" "github.com/cosmos/cosmos-sdk/client" "github.com/spf13/cobra" + "github.com/sentinel-official/cli-client/services/v2ray" + v2raytypes "github.com/sentinel-official/cli-client/services/v2ray/types" "github.com/sentinel-official/cli-client/services/wireguard" wireguardtypes "github.com/sentinel-official/cli-client/services/wireguard/types" clienttypes "github.com/sentinel-official/cli-client/types" @@ -27,36 +30,42 @@ func DisconnectCmd() *cobra.Command { statusFilePath = filepath.Join(ctx.HomeDir, "status.json") ) - if err := status.LoadFromPath(statusFilePath); err != nil { + if err = status.LoadFromPath(statusFilePath); err != nil { return err } - if status.IFace != "" { - var ( - service = wireguard.NewWireGuard(). - WithConfig( - &wireguardtypes.Config{ - Name: status.IFace, - }, - ) - ) + var service clienttypes.Service + if status.Type == 1 { + var cfg wireguardtypes.Config + if err = json.Unmarshal(status.Info, &cfg); err != nil { + return err + } - if service.IsUp() { - if err := service.PreDown(); err != nil { - return err - } - if err := service.Down(); err != nil { - return err - } - if err := service.PostDown(); err != nil { - return err - } + service = wireguard.NewWireGuard(&cfg) + } else if status.Type == 2 { + var cfg v2raytypes.Config + if err = json.Unmarshal(status.Info, &cfg); err != nil { + return err } - return os.Remove(statusFilePath) + service = v2ray.NewV2Ray(&cfg) + } else { + return nil + } + + if service.IsUp() { + if err = service.PreDown(); err != nil { + return err + } + if err = service.Down(); err != nil { + return err + } + if err = service.PostDown(); err != nil { + return err + } } - return nil + return os.Remove(statusFilePath) }, }