diff --git a/config.go b/config.go index 73eea2ca..727329fa 100755 --- a/config.go +++ b/config.go @@ -5,6 +5,7 @@ package core import ( "io" "io/ioutil" + "os" "strings" "github.com/golang/protobuf/proto" @@ -92,9 +93,15 @@ func init() { if len(v) == 0 { return nil, newError("input has no element") } + var data []byte + var rerr error // pb type can only handle the first config - data, err := ioutil.ReadFile(v[0]) - common.Must(err) + if v[0] == "stdin:" { + data, rerr = buf.ReadAllToBytes(os.Stdin) + } else { + data, rerr = ioutil.ReadFile(v[0]) + } + common.Must(rerr) return loadProtobufConfig(data) case io.Reader: data, err := buf.ReadAllToBytes(v) diff --git a/infra/control/config.go b/infra/control/config.go index cc2c9860..a0f456dd 100644 --- a/infra/control/config.go +++ b/infra/control/config.go @@ -63,6 +63,8 @@ func (c *ConfigCommand) LoadArg(arg string) (out io.Reader, err error) { var data []byte if strings.HasPrefix(arg, "http://") || strings.HasPrefix(arg, "https://") { data, err = FetchHTTPContent(arg) + } else if arg == "stdin:" { + data, err = ioutil.ReadAll(os.Stdin) } else { data, err = ioutil.ReadFile(arg) } diff --git a/main/json/config_json.go b/main/json/config_json.go index 84f405bd..68334104 100644 --- a/main/json/config_json.go +++ b/main/json/config_json.go @@ -4,6 +4,7 @@ package json import ( "io" + "os" "v2ray.com/core" "v2ray.com/core/common" @@ -20,7 +21,7 @@ func init() { Loader: func(input interface{}) (*core.Config, error) { switch v := input.(type) { case cmdarg.Arg: - jsonContent, err := ctlcmd.Run(append([]string{"config"}, v...), nil) + jsonContent, err := ctlcmd.Run(append([]string{"config"}, v...), os.Stdin) if err != nil { return nil, newError("failed to execute v2ctl to convert config file.").Base(err).AtWarning() } diff --git a/main/jsonem/jsonem.go b/main/jsonem/jsonem.go index 95e0bb13..dd447187 100644 --- a/main/jsonem/jsonem.go +++ b/main/jsonem/jsonem.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "net/http" "net/url" + "os" "strings" "time" @@ -26,6 +27,7 @@ func init() { case cmdarg.Arg: cf := &conf.Config{} for _, arg := range v { + newError("Reading config: ", arg).AtInfo().WriteToLog() r, err := LoadArg(arg) common.Must(err) c, err := serial.DecodeJSONConfig(r) @@ -47,6 +49,8 @@ func LoadArg(arg string) (out io.Reader, err error) { var data []byte if strings.HasPrefix(arg, "http://") || strings.HasPrefix(arg, "https://") { data, err = FetchHTTPContent(arg) + } else if arg == "stdin:" { + data, err = ioutil.ReadAll(os.Stdin) } else { data, err = ioutil.ReadFile(arg) }