mirror of https://github.com/schollz/croc.git
building the ui
This commit is contained in:
parent
f1b62ea30d
commit
d95c90de44
126
main.go
126
main.go
|
@ -1,30 +1,122 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
croc "github.com/schollz/croc/src"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
role := flag.Int("role", 0, "role number")
|
||||
passphrase := flag.String("code", "chou", "codephrase")
|
||||
fname := flag.String("file", "", "codephrase")
|
||||
flag.Parse()
|
||||
var version string
|
||||
|
||||
c := croc.Init()
|
||||
// croc.SetLogLevel("error")
|
||||
if *role == -1 {
|
||||
err = c.Relay()
|
||||
} else if *role == 0 {
|
||||
err = c.Send(*fname, *passphrase)
|
||||
} else {
|
||||
err = c.Receive(*passphrase)
|
||||
var cr *croc.Croc
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app.Name = "croc"
|
||||
if version == "" {
|
||||
version = "dev"
|
||||
}
|
||||
|
||||
app.Version = version
|
||||
app.Compiled = time.Now()
|
||||
app.Usage = "easily and securely transfer stuff from one computer to another"
|
||||
app.UsageText = "croc allows any two computers to directly and securely transfer files"
|
||||
// app.ArgsUsage = "[args and such]"
|
||||
app.Commands = []cli.Command{
|
||||
cli.Command{
|
||||
Name: "send",
|
||||
Usage: "send a file",
|
||||
Description: "send a file over the relay",
|
||||
ArgsUsage: "[filename]",
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolTFlag{Name: "compress, o"},
|
||||
cli.BoolTFlag{Name: "encrypt, e"},
|
||||
},
|
||||
HelpName: "croc send",
|
||||
Action: func(c *cli.Context) error {
|
||||
return send(c)
|
||||
},
|
||||
},
|
||||
cli.Command{
|
||||
Name: "receive",
|
||||
Usage: "receive a file",
|
||||
Description: "receve a file over the relay",
|
||||
HelpName: "croc receive",
|
||||
Action: func(c *cli.Context) error {
|
||||
return receive(c)
|
||||
},
|
||||
},
|
||||
cli.Command{
|
||||
Name: "relay",
|
||||
Usage: "start a croc relay",
|
||||
Description: "the croc relay will handle websocket and TCP connections",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{Name: "tcp", Value: "27130,27131,27132,27133", Usage: "ports for the tcp connections"},
|
||||
cli.StringFlag{Name: "port", Value: "8130", Usage: "port that the websocket listens on"},
|
||||
},
|
||||
HelpName: "croc relay",
|
||||
Action: func(c *cli.Context) error {
|
||||
return relay(c)
|
||||
},
|
||||
},
|
||||
}
|
||||
app.Flags = []cli.Flag{
|
||||
cli.StringFlag{Name: "relay", Value: "wss://croc3.schollz.com"},
|
||||
cli.StringFlag{Name: "code, c", Usage: "codephrase used to connect to relay"},
|
||||
cli.BoolFlag{Name: "local", Usage: "use only local mode"},
|
||||
cli.BoolFlag{Name: "debug", Usage: "increase verbosity (a lot)"},
|
||||
cli.BoolFlag{Name: "yes", Usage: "automatically agree to all prompts"},
|
||||
cli.BoolFlag{Name: "stdout", Usage: "redirect file to stdout"},
|
||||
}
|
||||
app.EnableBashCompletion = true
|
||||
app.HideHelp = false
|
||||
app.HideVersion = false
|
||||
app.BashComplete = func(c *cli.Context) {
|
||||
fmt.Fprintf(c.App.Writer, "lipstick\nkiss\nme\nlipstick\nringo\n")
|
||||
}
|
||||
app.Action = func(c *cli.Context) error {
|
||||
fmt.Printf("made it!\n")
|
||||
return nil
|
||||
}
|
||||
app.Before = func(c *cli.Context) error {
|
||||
cr = croc.Init()
|
||||
cr.AllowLocalDiscovery = true
|
||||
cr.WebsocketAddress = c.GlobalString("relay")
|
||||
cr.Debug = c.GlobalBool("debug")
|
||||
cr.Yes = c.GlobalBool("yes")
|
||||
cr.Stdout = c.GlobalBool("stdout")
|
||||
cr.LocalOnly = c.GlobalBool("local")
|
||||
cr.CodePhrase = c.GlobalString("code")
|
||||
return nil
|
||||
}
|
||||
|
||||
err := app.Run(os.Args)
|
||||
if err != nil {
|
||||
fmt.Print("Error: ")
|
||||
fmt.Println(err.Error())
|
||||
fmt.Printf("error: %s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func send(c *cli.Context) error {
|
||||
if c.Args().First() == "" {
|
||||
return errors.New("must specify file: croc send [filename]")
|
||||
}
|
||||
cr.UseCompression = c.GlobalBoolT("compress")
|
||||
cr.UseEncryption = c.GlobalBoolT("encrypt")
|
||||
|
||||
fmt.Println("sending")
|
||||
return nil
|
||||
}
|
||||
|
||||
func receive(c *cli.Context) error {
|
||||
fmt.Println("receive")
|
||||
return nil
|
||||
}
|
||||
|
||||
func relay(c *cli.Context) error {
|
||||
fmt.Println("relay")
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -16,17 +16,25 @@ const (
|
|||
)
|
||||
|
||||
type Croc struct {
|
||||
// Options for all
|
||||
Debug bool
|
||||
|
||||
// Options for relay
|
||||
ServerPort string
|
||||
CurveType string
|
||||
|
||||
// Options for connecting to server
|
||||
TcpPorts []string
|
||||
WebsocketAddress string
|
||||
ServerPort string
|
||||
Timeout time.Duration
|
||||
LocalOnly bool
|
||||
|
||||
// Options for file transfering
|
||||
UseEncryption bool
|
||||
UseCompression bool
|
||||
CurveType string
|
||||
AllowLocalDiscovery bool
|
||||
Yes bool
|
||||
Stdout bool
|
||||
|
||||
// private variables
|
||||
// rs relay state is only for the relay
|
||||
|
@ -59,6 +67,14 @@ func Init() (c *Croc) {
|
|||
return
|
||||
}
|
||||
|
||||
func (c *Croc) SetDebug(debug bool) {
|
||||
if debug {
|
||||
SetLogLevel("debug")
|
||||
} else {
|
||||
SetLogLevel("error")
|
||||
}
|
||||
}
|
||||
|
||||
type relayState struct {
|
||||
channel map[string]*channelData
|
||||
sync.RWMutex
|
||||
|
|
Loading…
Reference in New Issue