2017-10-21 01:18:06 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
const BUFFERSIZE = 1024
|
|
|
|
|
|
|
|
var oneGigabytePerSecond = 1000000 // expressed as kbps
|
|
|
|
|
|
|
|
type Flags struct {
|
|
|
|
Relay bool
|
|
|
|
Debug bool
|
|
|
|
Wait bool
|
2017-10-22 07:05:08 +03:00
|
|
|
PathSpec bool
|
2017-10-21 01:18:06 +03:00
|
|
|
DontEncrypt bool
|
|
|
|
Server string
|
|
|
|
File string
|
2017-10-22 07:05:08 +03:00
|
|
|
Path string
|
2017-10-21 01:18:06 +03:00
|
|
|
Code string
|
|
|
|
Rate int
|
|
|
|
NumberOfConnections int
|
|
|
|
}
|
|
|
|
|
|
|
|
var version string
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
fmt.Println(`
|
2017-10-21 16:43:07 +03:00
|
|
|
,_
|
|
|
|
>' )
|
|
|
|
croc version ` + fmt.Sprintf("%5s", version) + ` ( ( \
|
|
|
|
|| \
|
|
|
|
/^^^^\ ||
|
|
|
|
/^^\________/0 \ ||
|
|
|
|
( ` + "`" + `~+++,,_||__,,++~^^^^^^^
|
|
|
|
...V^V^V^V^V^V^\...............................
|
|
|
|
|
2017-10-21 01:18:06 +03:00
|
|
|
|
|
|
|
`)
|
|
|
|
flags := new(Flags)
|
|
|
|
flag.BoolVar(&flags.Relay, "relay", false, "run as relay")
|
|
|
|
flag.BoolVar(&flags.Debug, "debug", false, "debug mode")
|
|
|
|
flag.BoolVar(&flags.Wait, "wait", false, "wait for code to be sent")
|
2017-10-22 07:05:08 +03:00
|
|
|
flag.BoolVar(&flags.PathSpec, "ask-save", false, "ask for path to save to")
|
2017-10-21 01:18:06 +03:00
|
|
|
flag.StringVar(&flags.Server, "server", "cowyo.com", "address of relay server")
|
|
|
|
flag.StringVar(&flags.File, "send", "", "file to send")
|
2017-10-22 07:05:08 +03:00
|
|
|
flag.StringVar(&flags.Path, "save", "", "path to save to")
|
2017-10-21 01:18:06 +03:00
|
|
|
flag.StringVar(&flags.Code, "code", "", "use your own code phrase")
|
|
|
|
flag.IntVar(&flags.Rate, "rate", oneGigabytePerSecond, "throttle down to speed in kbps")
|
|
|
|
flag.BoolVar(&flags.DontEncrypt, "no-encrypt", false, "turn off encryption")
|
|
|
|
flag.IntVar(&flags.NumberOfConnections, "threads", 4, "number of threads to use")
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if flags.Relay {
|
|
|
|
r := NewRelay(flags)
|
|
|
|
r.Run()
|
|
|
|
} else {
|
|
|
|
c := NewConnection(flags)
|
|
|
|
err := c.Run()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Error! Please submit the following error to https://github.com/schollz/croc/issues:\n\n'%s'\n\n", err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func getInput(prompt string) string {
|
|
|
|
reader := bufio.NewReader(os.Stdin)
|
|
|
|
fmt.Print(prompt)
|
|
|
|
text, _ := reader.ReadString('\n')
|
|
|
|
return strings.TrimSpace(text)
|
|
|
|
}
|