1
1
Fork 0
mirror of https://github.com/schollz/croc.git synced 2025-10-11 05:11:06 +02:00

allow getting password through file Fix #226

This commit is contained in:
Zack Scholl 2020-09-03 13:31:01 -07:00
parent def4f94ffd
commit bd2376e920
2 changed files with 15 additions and 4 deletions

View file

@ -163,6 +163,8 @@ Be sure to include the password for the relay otherwise any requests will be rej
$ croc --pass YOURPASSWORD --relay "myreal.example.com:9009" send [filename] $ croc --pass YOURPASSWORD --relay "myreal.example.com:9009" send [filename]
``` ```
Note: when including `--pass YOURPASSWORD` you can instead pass a file with the password, e.g. `--pass FILEWITHPASSWORD`.
## License ## License
MIT MIT

View file

@ -137,6 +137,15 @@ func getConfigFile() string {
return path.Join(configFile, "send.json") return path.Join(configFile, "send.json")
} }
func determinePass(c *cli.Context) (pass string) {
pass = c.GlobalString("pass")
b, err := ioutil.ReadFile(pass)
if err == nil {
pass = strings.TrimSpace(string(b))
}
return
}
func send(c *cli.Context) (err error) { func send(c *cli.Context) (err error) {
setDebugLevel(c) setDebugLevel(c)
crocOptions := croc.Options{ crocOptions := croc.Options{
@ -151,7 +160,7 @@ func send(c *cli.Context) (err error) {
RelayPorts: strings.Split(c.String("ports"), ","), RelayPorts: strings.Split(c.String("ports"), ","),
Ask: c.GlobalBool("ask"), Ask: c.GlobalBool("ask"),
NoMultiplexing: c.Bool("no-multi"), NoMultiplexing: c.Bool("no-multi"),
RelayPassword: c.GlobalString("pass"), RelayPassword: determinePass(c),
SendingText: c.String("text") != "", SendingText: c.String("text") != "",
} }
if crocOptions.RelayAddress != models.DEFAULT_RELAY { if crocOptions.RelayAddress != models.DEFAULT_RELAY {
@ -344,7 +353,7 @@ func receive(c *cli.Context) (err error) {
RelayAddress6: c.GlobalString("relay6"), RelayAddress6: c.GlobalString("relay6"),
Stdout: c.GlobalBool("stdout"), Stdout: c.GlobalBool("stdout"),
Ask: c.GlobalBool("ask"), Ask: c.GlobalBool("ask"),
RelayPassword: c.GlobalString("pass"), RelayPassword: determinePass(c),
} }
if crocOptions.RelayAddress != models.DEFAULT_RELAY { if crocOptions.RelayAddress != models.DEFAULT_RELAY {
crocOptions.RelayAddress6 = "" crocOptions.RelayAddress6 = ""
@ -441,11 +450,11 @@ func relay(c *cli.Context) (err error) {
continue continue
} }
go func(portStr string) { go func(portStr string) {
err = tcp.Run(debugString, portStr, c.GlobalString("pass")) err = tcp.Run(debugString, portStr, determinePass(c))
if err != nil { if err != nil {
panic(err) panic(err)
} }
}(port) }(port)
} }
return tcp.Run(debugString, ports[0], c.GlobalString("pass"), tcpPorts) return tcp.Run(debugString, ports[0], determinePass(c), tcpPorts)
} }