From 17f3df7e364d962973c9d9698f6f71afecbb8b03 Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 10 Jan 2021 13:14:10 +0000 Subject: [PATCH 1/7] Added an option to ignore attached stdin, for compatibility with node child_process --- src/cli/cli.go | 4 +++- src/croc/croc.go | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cli/cli.go b/src/cli/cli.go index 0c5bc2b1..23914018 100644 --- a/src/cli/cli.go +++ b/src/cli/cli.go @@ -85,6 +85,7 @@ func Run() (err error) { &cli.BoolFlag{Name: "no-compress", Usage: "disable compression"}, &cli.BoolFlag{Name: "ask", Usage: "make sure sender and recipient are prompted"}, &cli.BoolFlag{Name: "local", Usage: "force to use only local connections"}, + &cli.BoolFlag{Name: "ignoreStdin", Usage: "ignore piped stdin"}, &cli.StringFlag{Name: "ip", Value: "", Usage: "set sender ip if known e.g. 10.0.0.1:9009, [::1]:9009"}, &cli.StringFlag{Name: "relay", Value: models.DEFAULT_RELAY, Usage: "address of the relay", EnvVars: []string{"CROC_RELAY"}}, &cli.StringFlag{Name: "relay6", Value: models.DEFAULT_RELAY6, Usage: "ipv6 address of the relay", EnvVars: []string{"CROC_RELAY6"}}, @@ -177,6 +178,7 @@ func send(c *cli.Context) (err error) { Stdout: c.Bool("stdout"), DisableLocal: c.Bool("no-local"), OnlyLocal: c.Bool("local"), + IgnoreStdin: c.Bool("ignoreStdin"), RelayPorts: strings.Split(c.String("ports"), ","), Ask: c.Bool("ask"), NoMultiplexing: c.Bool("no-multi"), @@ -217,7 +219,7 @@ func send(c *cli.Context) (err error) { var fnames []string stat, _ := os.Stdin.Stat() - if (stat.Mode() & os.ModeCharDevice) == 0 { + if ((stat.Mode() & os.ModeCharDevice) == 0) && !c.Bool("ignoreStdin") { fnames, err = getStdin() if err != nil { return diff --git a/src/croc/croc.go b/src/croc/croc.go index 03f4783c..c556582b 100644 --- a/src/croc/croc.go +++ b/src/croc/croc.go @@ -61,6 +61,7 @@ type Options struct { NoMultiplexing bool DisableLocal bool OnlyLocal bool + IgnoreStdin bool Ask bool SendingText bool NoCompress bool From 90eda5639fd1a561c64ebf8c27e2044f5e2b57e2 Mon Sep 17 00:00:00 2001 From: Spaceface16518 Date: Wed, 27 Jan 2021 12:30:45 -0600 Subject: [PATCH 2/7] Strip go binary in docker build --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 08917ed6..3595f90b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM golang:1.15-alpine as builder RUN apk add --no-cache git WORKDIR /go/croc COPY . . -RUN go build -v +RUN go build -v -ldflags="-s -w" FROM alpine:latest EXPOSE 9009 From b5f1b35213487350b31d2280fedfdeae370640e9 Mon Sep 17 00:00:00 2001 From: Benjamin Wen Date: Thu, 28 Jan 2021 11:27:27 +0800 Subject: [PATCH 3/7] Update year --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 698785da..3589cfad 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017-2020 Zack +Copyright (c) 2017-2021 Zack Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 3ccd4d07e98c6bf8eb962b4ca7099369a9d65dff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niko=20K=C3=B6ser?= Date: Mon, 1 Feb 2021 10:34:06 +0100 Subject: [PATCH 4/7] fix: accidentally overwritten error value In function _cli.send_ the named return value 'err' gets accidentally overwritten in the deferred anonymous function that removes the files/directories. Renamed the error variable inside the deferred function so that it does not overwrite the original error anymore. Closes #296 --- src/cli/cli.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cli/cli.go b/src/cli/cli.go index 0c5bc2b1..b70e1f02 100644 --- a/src/cli/cli.go +++ b/src/cli/cli.go @@ -223,9 +223,9 @@ func send(c *cli.Context) (err error) { return } defer func() { - err = os.Remove(fnames[0]) - if err != nil { - log.Error(err) + e := os.Remove(fnames[0]) + if e != nil { + log.Error(e) } }() } else if c.String("text") != "" { @@ -234,9 +234,9 @@ func send(c *cli.Context) (err error) { return } defer func() { - err = os.Remove(fnames[0]) - if err != nil { - log.Error(err) + e := os.Remove(fnames[0]) + if e != nil { + log.Error(e) } }() From 0b60fef24620e813eb387f37fc8dfb7344157985 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niko=20K=C3=B6ser?= Date: Mon, 1 Feb 2021 10:48:34 +0100 Subject: [PATCH 5/7] refactor: write errors into stderr and add exit code Instead of writing errors into stdout and alway returning exit code 0, we now write into stderr and return exit code 1 in case that an error occured. --- main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 4c442fb3..a3a9f4e3 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,7 @@ package main //go:generate git tag -af v$VERSION -m "v$VERSION" import ( - "fmt" + "log" "github.com/schollz/croc/v8/src/cli" ) @@ -28,6 +28,6 @@ func main() { // } // }() if err := cli.Run(); err != nil { - fmt.Println(err) + log.Fatalln(err) } } From 7f5d704a264eb114412dbf184056cdd3484a4c9e Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Mon, 1 Feb 2021 06:58:27 -0800 Subject: [PATCH 6/7] change name --- src/cli/cli.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cli/cli.go b/src/cli/cli.go index 23914018..4473d171 100644 --- a/src/cli/cli.go +++ b/src/cli/cli.go @@ -85,7 +85,7 @@ func Run() (err error) { &cli.BoolFlag{Name: "no-compress", Usage: "disable compression"}, &cli.BoolFlag{Name: "ask", Usage: "make sure sender and recipient are prompted"}, &cli.BoolFlag{Name: "local", Usage: "force to use only local connections"}, - &cli.BoolFlag{Name: "ignoreStdin", Usage: "ignore piped stdin"}, + &cli.BoolFlag{Name: "ignore-stdin", Usage: "ignore piped stdin"}, &cli.StringFlag{Name: "ip", Value: "", Usage: "set sender ip if known e.g. 10.0.0.1:9009, [::1]:9009"}, &cli.StringFlag{Name: "relay", Value: models.DEFAULT_RELAY, Usage: "address of the relay", EnvVars: []string{"CROC_RELAY"}}, &cli.StringFlag{Name: "relay6", Value: models.DEFAULT_RELAY6, Usage: "ipv6 address of the relay", EnvVars: []string{"CROC_RELAY6"}}, @@ -178,7 +178,7 @@ func send(c *cli.Context) (err error) { Stdout: c.Bool("stdout"), DisableLocal: c.Bool("no-local"), OnlyLocal: c.Bool("local"), - IgnoreStdin: c.Bool("ignoreStdin"), + IgnoreStdin: c.Bool("ignore-stdin"), RelayPorts: strings.Split(c.String("ports"), ","), Ask: c.Bool("ask"), NoMultiplexing: c.Bool("no-multi"), @@ -219,7 +219,7 @@ func send(c *cli.Context) (err error) { var fnames []string stat, _ := os.Stdin.Stat() - if ((stat.Mode() & os.ModeCharDevice) == 0) && !c.Bool("ignoreStdin") { + if ((stat.Mode() & os.ModeCharDevice) == 0) && !c.Bool("ignore-stdin") { fnames, err = getStdin() if err != nil { return From 681c824ef40b4347f96c720585f8855a9452e932 Mon Sep 17 00:00:00 2001 From: Zack Date: Tue, 2 Feb 2021 06:43:12 -0800 Subject: [PATCH 7/7] remove snap, it just doesn't work --- README.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/README.md b/README.md index 1cedd56a..11d11736 100644 --- a/README.md +++ b/README.md @@ -77,12 +77,6 @@ On Arch Linux you can install the latest release with `pacman`: $ pacman -S croc ``` -On Ubuntu you can install with `snap`: - -``` -$ snap install croc -``` - On Gentoo you can install with `portage`: ``` $ emerge net-misc/croc