mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 21:30:16 +02:00
Merge branch 'master' of https://github.com/schollz/croc
This commit is contained in:
commit
83db5bdc68
8 changed files with 212 additions and 87 deletions
15
Dockerfile
Normal file
15
Dockerfile
Normal file
|
@ -0,0 +1,15 @@
|
|||
FROM golang:1.12-alpine as builder
|
||||
RUN apk add --no-cache git
|
||||
WORKDIR /go/croc
|
||||
COPY . .
|
||||
RUN go build -v
|
||||
|
||||
FROM alpine:latest
|
||||
EXPOSE 9009
|
||||
EXPOSE 9010
|
||||
EXPOSE 9011
|
||||
EXPOSE 9012
|
||||
EXPOSE 9013
|
||||
COPY --from=builder /go/croc/croc /croc
|
||||
ENTRYPOINT ["/croc"]
|
||||
CMD ["relay"]
|
10
README.md
10
README.md
|
@ -4,7 +4,7 @@
|
|||
src="https://user-images.githubusercontent.com/6550035/46709024-9b23ad00-cbf6-11e8-9fb2-ca8b20b7dbec.jpg"
|
||||
width="408px" border="0" alt="croc">
|
||||
<br>
|
||||
<a href="https://github.com/schollz/croc/releases/latest"><img src="https://img.shields.io/badge/version-v6.0.10-brightgreen.svg?style=flat-square" alt="Version"></a>
|
||||
<a href="https://github.com/schollz/croc/releases/latest"><img src="https://img.shields.io/badge/version-v6.1.0-brightgreen.svg?style=flat-square" alt="Version"></a>
|
||||
<a href="https://travis-ci.org/schollz/croc"><img
|
||||
src="https://img.shields.io/travis/schollz/croc.svg?style=flat-square" alt="Build
|
||||
Status"></a>
|
||||
|
@ -76,6 +76,7 @@ $ croc code-phrase
|
|||
|
||||
The code phrase is used to establish password-authenticated key agreement ([PAKE](https://en.wikipedia.org/wiki/Password-authenticated_key_agreement)) which generates a secret key for the sender and recipient to use for end-to-end encryption.
|
||||
|
||||
There are a number of configurable options (see `--help`). A set of options (like custom relay, ports, and code phrase) can be set using `--remember`.
|
||||
|
||||
### Custom code phrase
|
||||
|
||||
|
@ -85,7 +86,6 @@ You can send with your own code phrase (must be more than 4 characters).
|
|||
$ croc send --code [code-phrase] [file(s)-or-folder]
|
||||
```
|
||||
|
||||
|
||||
### Use pipes - stdin and stdout
|
||||
|
||||
You can pipe to `croc`:
|
||||
|
@ -118,6 +118,12 @@ You can send files using your relay by entering `--relay` to change the relay th
|
|||
$ croc --relay "myrelay.example.com:9009" send [filename]
|
||||
```
|
||||
|
||||
If it's easier you can also run a relay with Docker:
|
||||
|
||||
|
||||
```
|
||||
$ docker run -d -p 9009:9009 -p 9010:9010 -p 9011:9011 -p 9012:9012 -p 9013:9013 schollz/croc
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
|
|
9
go.mod
9
go.mod
|
@ -5,22 +5,21 @@ go 1.12
|
|||
require (
|
||||
github.com/OneOfOne/xxhash v1.2.5 // indirect
|
||||
github.com/cespare/xxhash v1.1.0
|
||||
github.com/denisbrodbeck/machineid v1.0.1
|
||||
github.com/fatih/color v1.7.0 // indirect
|
||||
github.com/kalafut/imohash v1.0.0
|
||||
github.com/mattn/go-colorable v0.1.2 // indirect
|
||||
github.com/pkg/errors v0.8.1
|
||||
github.com/schollz/logger v1.0.1
|
||||
github.com/schollz/mnemonicode v1.0.1
|
||||
github.com/schollz/pake v1.1.0
|
||||
github.com/schollz/pake v1.1.1
|
||||
github.com/schollz/peerdiscovery v1.4.0
|
||||
github.com/schollz/progressbar/v2 v2.13.2
|
||||
github.com/schollz/spinner v0.0.0-20180925172146-6bbc5f7804f9
|
||||
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
||||
github.com/stretchr/testify v1.3.0
|
||||
github.com/urfave/cli v1.20.0
|
||||
golang.org/x/crypto v0.0.0-20190617133340-57b3e21c3d56
|
||||
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980 // indirect
|
||||
golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f // indirect
|
||||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4
|
||||
golang.org/x/net v0.0.0-20190628185345-da137c7871d7 // indirect
|
||||
golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7 // indirect
|
||||
golang.org/x/text v0.3.2 // indirect
|
||||
)
|
||||
|
|
20
go.sum
20
go.sum
|
@ -7,8 +7,6 @@ github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghf
|
|||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ=
|
||||
github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI=
|
||||
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
|
||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/kalafut/imohash v1.0.0 h1:LgCJ+p/BwM2HKpOxFopkeddpzVCfm15EtXMroXD1SYE=
|
||||
|
@ -28,8 +26,8 @@ github.com/schollz/logger v1.0.1 h1:BuBAU+euqphM0Ny9qFVScl4RSxatis4nCHIkOxO2cUU=
|
|||
github.com/schollz/logger v1.0.1/go.mod h1:P6F4/dGMGcx8wh+kG1zrNEd4vnNpEBY/mwEMd/vn6AM=
|
||||
github.com/schollz/mnemonicode v1.0.1 h1:LiH5hwADZwjwnfXsaD4xgnMyTAtaKHN+e5AyjRU6WSU=
|
||||
github.com/schollz/mnemonicode v1.0.1/go.mod h1:cl4UAOhUV0mkdjMj/QYaUZbZZdF8BnOqoz8rHMzwboY=
|
||||
github.com/schollz/pake v1.1.0 h1:+tYqsPVkuirFpmeRePjYTUhIHHKLufdmd7QfuspaXCk=
|
||||
github.com/schollz/pake v1.1.0/go.mod h1:pL7Z08gnQ4OQ3G27s5e5T6TEzp6cFc5GzCwLm0f75Io=
|
||||
github.com/schollz/pake v1.1.1 h1:QKeojDWzdAdtRC4m89b6HAxw/8gjqrVu7r4SAOxOFg8=
|
||||
github.com/schollz/pake v1.1.1/go.mod h1:aWMxQ1jwqZRwk3StflHcdyzPR+CyW5W7+WIZD6Y3dEY=
|
||||
github.com/schollz/peerdiscovery v1.4.0 h1:wJWiJUBSMY2io9eIG1+gauXm8WD6sJVN5M+pLd4fYZQ=
|
||||
github.com/schollz/peerdiscovery v1.4.0/go.mod h1:DXj/7VvxAkUuSZNabx3q8t524uWbrhMPxeX151kvvHs=
|
||||
github.com/schollz/progressbar/v2 v2.9.1/go.mod h1:l6tn6yU6ZdQoF8lwX/VoAUQ3FjhCbrcZDnl9xeWZzYw=
|
||||
|
@ -43,28 +41,26 @@ github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0b
|
|||
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/tscholl2/siec v0.0.0-20180721101609-21667da05937 h1:lhssCpSe3TjKcbvUoPzFMuv9oUyZDgI3Cmgolfw2C90=
|
||||
github.com/tscholl2/siec v0.0.0-20180721101609-21667da05937/go.mod h1:KL9+ubr1JZdaKjgAaHr+tCytEncXBa1pR6FjbTsOJnw=
|
||||
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
|
||||
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190617133340-57b3e21c3d56 h1:ZpKuNIejY8P0ExLOVyKhb0WsgG8UdvHXe6TWjY7eL6k=
|
||||
golang.org/x/crypto v0.0.0-20190617133340-57b3e21c3d56/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc=
|
||||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/net v0.0.0-20190206173232-65e2d4e15006/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980 h1:dfGZHvZk057jK2MCeWus/TowKpJ8y4AmooUzdBSR9GU=
|
||||
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190628185345-da137c7871d7 h1:rTIdg5QFRR7XCaK4LCjBiPbx8j4DQRpdYMnGn/bJUEU=
|
||||
golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f h1:25KHgbfyiSm6vwQLbM3zZIe1v9p/3ea4Rz+nnM5K/i4=
|
||||
golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7 h1:LepdCS8Gf/MVejFIt8lsiexZATdoGVyp5bcyS+rYoUI=
|
||||
golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||
|
|
209
src/cli/cli.go
209
src/cli/cli.go
|
@ -1,20 +1,23 @@
|
|||
package cli
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/schollz/croc/v6/src/croc"
|
||||
"github.com/schollz/croc/v6/src/models"
|
||||
"github.com/schollz/croc/v6/src/tcp"
|
||||
"github.com/schollz/croc/v6/src/utils"
|
||||
log "github.com/schollz/logger"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
|
@ -27,7 +30,7 @@ func Run() (err error) {
|
|||
app := cli.NewApp()
|
||||
app.Name = "croc"
|
||||
if Version == "" {
|
||||
Version = "v6.0.10-1d744f1"
|
||||
Version = "v6.1.0-6f31418"
|
||||
}
|
||||
app.Version = Version
|
||||
app.Compiled = time.Now()
|
||||
|
@ -63,10 +66,11 @@ func Run() (err error) {
|
|||
},
|
||||
}
|
||||
app.Flags = []cli.Flag{
|
||||
cli.BoolFlag{Name: "remember", Usage: "save these settings to reuse next time"},
|
||||
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"},
|
||||
cli.StringFlag{Name: "relay", Value: "198.199.67.130:9009", Usage: "address of the relay"},
|
||||
cli.StringFlag{Name: "relay", Value: models.DEFAULT_RELAY, Usage: "address of the relay"},
|
||||
cli.StringFlag{Name: "out", Value: ".", Usage: "specify an output folder to receive the file"},
|
||||
}
|
||||
app.EnableBashCompletion = true
|
||||
|
@ -90,11 +94,66 @@ func Run() (err error) {
|
|||
return app.Run(os.Args)
|
||||
}
|
||||
|
||||
// func saveDefaultConfig(c *cli.Context) error {
|
||||
// return croc.SaveDefaultConfig()
|
||||
// }
|
||||
func getConfigDir() (homedir string, err error) {
|
||||
homedir, err = os.UserHomeDir()
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
homedir = path.Join(homedir, ".config", "croc")
|
||||
if _, err := os.Stat(homedir); os.IsNotExist(err) {
|
||||
log.Debugf("creating home directory %s", homedir)
|
||||
err = os.MkdirAll(homedir, 0700)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func send(c *cli.Context) (err error) {
|
||||
if c.GlobalBool("debug") {
|
||||
log.SetLevel("debug")
|
||||
log.Debug("debug mode on")
|
||||
} else {
|
||||
log.SetLevel("info")
|
||||
}
|
||||
configFile, err := getConfigDir()
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
configFile = path.Join(configFile, "send.json")
|
||||
|
||||
crocOptions := croc.Options{
|
||||
SharedSecret: c.String("code"),
|
||||
IsSender: true,
|
||||
Debug: c.GlobalBool("debug"),
|
||||
NoPrompt: c.GlobalBool("yes"),
|
||||
RelayAddress: c.GlobalString("relay"),
|
||||
Stdout: c.GlobalBool("stdout"),
|
||||
DisableLocal: c.Bool("no-local"),
|
||||
RelayPorts: strings.Split(c.String("ports"), ","),
|
||||
}
|
||||
b, errOpen := ioutil.ReadFile(configFile)
|
||||
if errOpen == nil && !c.GlobalBool("remember") {
|
||||
var rememberedOptions croc.Options
|
||||
err = json.Unmarshal(b, &rememberedOptions)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
// update anything that isn't explicitly set
|
||||
if !c.GlobalIsSet("relay") {
|
||||
crocOptions.RelayAddress = rememberedOptions.RelayAddress
|
||||
}
|
||||
if !c.IsSet("no-local") {
|
||||
crocOptions.DisableLocal = rememberedOptions.DisableLocal
|
||||
}
|
||||
if !c.IsSet("ports") {
|
||||
crocOptions.RelayPorts = rememberedOptions.RelayPorts
|
||||
}
|
||||
if !c.IsSet("code") {
|
||||
crocOptions.SharedSecret = rememberedOptions.SharedSecret
|
||||
}
|
||||
}
|
||||
|
||||
var fnames []string
|
||||
stat, _ := os.Stdin.Stat()
|
||||
|
@ -115,7 +174,7 @@ func send(c *cli.Context) (err error) {
|
|||
defer func() {
|
||||
err = os.Remove(fnames[0])
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
log.Error(err)
|
||||
}
|
||||
}()
|
||||
} else {
|
||||
|
@ -125,14 +184,9 @@ func send(c *cli.Context) (err error) {
|
|||
return errors.New("must specify file: croc send [filename]")
|
||||
}
|
||||
|
||||
var sharedSecret string
|
||||
if c.String("code") != "" {
|
||||
sharedSecret = c.String("code")
|
||||
}
|
||||
// cr.LoadConfig()
|
||||
if len(sharedSecret) == 0 {
|
||||
if len(crocOptions.SharedSecret) == 0 {
|
||||
// generate code phrase
|
||||
sharedSecret = utils.GetRandomName()
|
||||
crocOptions.SharedSecret = utils.GetRandomName()
|
||||
}
|
||||
|
||||
haveFolder := false
|
||||
|
@ -161,20 +215,33 @@ func send(c *cli.Context) (err error) {
|
|||
paths = append(paths, filepath.ToSlash(fname))
|
||||
}
|
||||
}
|
||||
cr, err := croc.New(croc.Options{
|
||||
SharedSecret: sharedSecret,
|
||||
IsSender: true,
|
||||
Debug: c.GlobalBool("debug"),
|
||||
NoPrompt: c.GlobalBool("yes"),
|
||||
RelayAddress: c.GlobalString("relay"),
|
||||
Stdout: c.GlobalBool("stdout"),
|
||||
DisableLocal: c.Bool("no-local"),
|
||||
RelayPorts: strings.Split(c.String("ports"), ","),
|
||||
})
|
||||
|
||||
cr, err := croc.New(crocOptions)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// save the config
|
||||
if c.GlobalBool("remember") {
|
||||
log.Debug("saving config file")
|
||||
var bConfig []byte
|
||||
// if the code wasn't set, don't save it
|
||||
if c.String("code") == "" {
|
||||
crocOptions.SharedSecret = ""
|
||||
}
|
||||
bConfig, err = json.MarshalIndent(crocOptions, "", " ")
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
err = ioutil.WriteFile(configFile, bConfig, 0644)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
log.Debugf("wrote %s", configFile)
|
||||
}
|
||||
|
||||
err = cr.Send(croc.TransferOptions{
|
||||
PathToFiles: paths,
|
||||
KeepPathInRemote: haveFolder,
|
||||
|
@ -184,31 +251,80 @@ func send(c *cli.Context) (err error) {
|
|||
}
|
||||
|
||||
func receive(c *cli.Context) (err error) {
|
||||
var sharedSecret string
|
||||
if c.GlobalString("code") != "" {
|
||||
sharedSecret = c.GlobalString("code")
|
||||
}
|
||||
if c.Args().First() != "" {
|
||||
sharedSecret = c.Args().First()
|
||||
}
|
||||
if sharedSecret == "" {
|
||||
sharedSecret = utils.GetInput("Enter receive code: ")
|
||||
}
|
||||
if c.GlobalString("out") != "" {
|
||||
os.Chdir(c.GlobalString("out"))
|
||||
}
|
||||
|
||||
cr, err := croc.New(croc.Options{
|
||||
SharedSecret: sharedSecret,
|
||||
crocOptions := croc.Options{
|
||||
SharedSecret: c.String("code"),
|
||||
IsSender: false,
|
||||
Debug: c.GlobalBool("debug"),
|
||||
NoPrompt: c.GlobalBool("yes"),
|
||||
RelayAddress: c.GlobalString("relay"),
|
||||
Stdout: c.GlobalBool("stdout"),
|
||||
})
|
||||
}
|
||||
if c.Args().First() != "" {
|
||||
crocOptions.SharedSecret = c.Args().First()
|
||||
}
|
||||
|
||||
// load options here
|
||||
if c.GlobalBool("debug") {
|
||||
log.SetLevel("debug")
|
||||
log.Debug("debug mode on")
|
||||
} else {
|
||||
log.SetLevel("info")
|
||||
}
|
||||
configFile, err := getConfigDir()
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
configFile = path.Join(configFile, "receive.json")
|
||||
b, errOpen := ioutil.ReadFile(configFile)
|
||||
if errOpen == nil && !c.GlobalBool("remember") {
|
||||
var rememberedOptions croc.Options
|
||||
err = json.Unmarshal(b, &rememberedOptions)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
// update anything that isn't explicitly set
|
||||
if !c.GlobalIsSet("relay") {
|
||||
crocOptions.RelayAddress = rememberedOptions.RelayAddress
|
||||
}
|
||||
if !c.GlobalIsSet("yes") {
|
||||
crocOptions.NoPrompt = rememberedOptions.NoPrompt
|
||||
}
|
||||
if crocOptions.SharedSecret == "" {
|
||||
crocOptions.SharedSecret = rememberedOptions.SharedSecret
|
||||
}
|
||||
}
|
||||
|
||||
if crocOptions.SharedSecret == "" {
|
||||
crocOptions.SharedSecret = utils.GetInput("Enter receive code: ")
|
||||
}
|
||||
if c.GlobalString("out") != "" {
|
||||
os.Chdir(c.GlobalString("out"))
|
||||
}
|
||||
|
||||
cr, err := croc.New(crocOptions)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// save the config
|
||||
if c.GlobalBool("remember") {
|
||||
log.Debug("saving config file")
|
||||
var bConfig []byte
|
||||
bConfig, err = json.MarshalIndent(crocOptions, "", " ")
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
err = ioutil.WriteFile(configFile, bConfig, 0644)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
log.Debugf("wrote %s", configFile)
|
||||
}
|
||||
|
||||
err = cr.Receive()
|
||||
return
|
||||
}
|
||||
|
@ -233,14 +349,3 @@ func relay(c *cli.Context) (err error) {
|
|||
}
|
||||
return tcp.Run(debugString, ports[0], tcpPorts)
|
||||
}
|
||||
|
||||
// func dirSize(path string) (int64, error) {
|
||||
// var size int64
|
||||
// err := filepath.Walk(path, func(_ string, info os.FileInfo, err error) error {
|
||||
// if !info.IsDir() {
|
||||
// size += info.Size()
|
||||
// }
|
||||
// return err
|
||||
// })
|
||||
// return size, err
|
||||
// }
|
||||
|
|
|
@ -17,7 +17,6 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/denisbrodbeck/machineid"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/schollz/croc/v6/src/comm"
|
||||
"github.com/schollz/croc/v6/src/compress"
|
||||
|
@ -88,7 +87,6 @@ type Client struct {
|
|||
|
||||
bar *progressbar.ProgressBar
|
||||
spinner *spinner.Spinner
|
||||
machineID string
|
||||
firstSend bool
|
||||
|
||||
mutex *sync.Mutex
|
||||
|
@ -117,7 +115,6 @@ type RemoteFileRequest struct {
|
|||
}
|
||||
|
||||
type SenderInfo struct {
|
||||
MachineID string
|
||||
FilesToTransfer []FileInfo
|
||||
}
|
||||
|
||||
|
@ -216,17 +213,13 @@ func (c *Client) Send(options TransferOptions) (err error) {
|
|||
if len(c.FilesToTransfer) == 1 {
|
||||
fname = fmt.Sprintf("'%s'", c.FilesToTransfer[0].Name)
|
||||
}
|
||||
machID, macIDerr := machineid.ID()
|
||||
if macIDerr != nil {
|
||||
log.Error(macIDerr)
|
||||
return
|
||||
}
|
||||
if len(machID) > 6 {
|
||||
machID = machID[:6]
|
||||
}
|
||||
c.machineID = machID
|
||||
|
||||
fmt.Fprintf(os.Stderr, "Sending %s (%s)\n", fname, utils.ByteCountDecimal(totalFilesSize))
|
||||
fmt.Fprintf(os.Stderr, "Code is: %s\nOn the other computer run\n\ncroc %s\n", c.Options.SharedSecret, c.Options.SharedSecret)
|
||||
otherRelay := ""
|
||||
if c.Options.RelayAddress != models.DEFAULT_RELAY {
|
||||
otherRelay = "--relay " + c.Options.RelayAddress + " "
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "Code is: %s\nOn the other computer run\n\ncroc %s%s\n", c.Options.SharedSecret, otherRelay, c.Options.SharedSecret)
|
||||
// // c.spinner.Suffix = " waiting for recipient..."
|
||||
// c.spinner.Start()
|
||||
// create channel for quitting
|
||||
|
@ -234,6 +227,8 @@ func (c *Client) Send(options TransferOptions) (err error) {
|
|||
errchan := make(chan error, 1)
|
||||
|
||||
if !c.Options.DisableLocal {
|
||||
// add two things to the error channel
|
||||
errchan = make(chan error, 2)
|
||||
// setup the relay locally
|
||||
for _, port := range c.Options.RelayPorts {
|
||||
|
||||
|
@ -298,6 +293,7 @@ func (c *Client) Send(options TransferOptions) (err error) {
|
|||
if err != nil {
|
||||
err = errors.Wrap(err, fmt.Sprintf("could not connect to %s", c.Options.RelayAddress))
|
||||
log.Debug(err)
|
||||
errchan <- err
|
||||
return
|
||||
}
|
||||
log.Debugf("connection established: %+v", conn)
|
||||
|
@ -331,7 +327,15 @@ func (c *Client) Send(options TransferOptions) (err error) {
|
|||
errchan <- c.transfer(options)
|
||||
}()
|
||||
|
||||
return <-errchan
|
||||
err = <-errchan
|
||||
if err == nil {
|
||||
// return if no error
|
||||
return
|
||||
}
|
||||
if !c.Options.DisableLocal {
|
||||
err = <-errchan
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// Receive will receive a file
|
||||
|
@ -641,7 +645,6 @@ func (c *Client) updateState() (err error) {
|
|||
if c.Options.IsSender && c.Step1ChannelSecured && !c.Step2FileInfoTransfered {
|
||||
var b []byte
|
||||
b, err = json.Marshal(SenderInfo{
|
||||
MachineID: c.machineID,
|
||||
FilesToTransfer: c.FilesToTransfer,
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
@ -33,7 +33,7 @@ install_croc()
|
|||
croc_os="unsupported"
|
||||
croc_arch="unknown"
|
||||
croc_arm=""
|
||||
croc_version="6.0.10"
|
||||
croc_version="6.1.0"
|
||||
|
||||
|
||||
# Termux on Android has $PREFIX set which already ends with /usr
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
package models
|
||||
|
||||
const TCP_BUFFER_SIZE = 1024 * 64
|
||||
const DEFAULT_RELAY = "142.93.177.120:9009"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue