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

Compare commits

..

No commits in common. "4be76188681766f9369e82efbae78b5a0a4b0c7e" and "3e68fa189710e7236a7a74cc78f3606bb2a0c1ed" have entirely different histories.

11 changed files with 32 additions and 64 deletions

View file

@ -42,11 +42,3 @@ jobs:
CGO_ENABLED=0 GOOS=freebsd GOARCH=arm64 go build -ldflags '' -o croc-freebsd-arm64
CGO_ENABLED=0 GOOS=openbsd GOARCH=amd64 go build -ldflags '' -o croc-openbsd-amd64
CGO_ENABLED=0 GOOS=openbsd GOARCH=arm64 go build -ldflags '' -o croc-openbsd-arm64
- name: Check static build of the linux version
run: |
if ldd croc-linux-amd64 2>&1 | grep -q "not a dynamic executable"; then
echo "Static build confirmed."
else
echo "Error: croc-linux-amd64 is a dynamic executable."
exit 1
fi

View file

@ -45,5 +45,5 @@ jobs:
file: ./Dockerfile
platforms: linux/amd64,linux/arm,linux/arm64,linux/386
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}

6
.gitignore vendored
View file

@ -21,9 +21,5 @@
go.work
go.work.sum
# Environment variables file
# env file
.env
# Croc builds
/croc
croc_v*

View file

@ -20,9 +20,5 @@ COPY --from=builder /go/croc/croc /go/croc/croc-entrypoint.sh /
USER nobody
# Simple TCP health check with nc!
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD nc -z localhost 9009 || exit 1
ENTRYPOINT ["/croc-entrypoint.sh"]
CMD ["relay"]

View file

@ -47,7 +47,7 @@ func main() {
}()
// Wait for a termination signal
<-sigs
_ = <-sigs
utils.RemoveMarkedFiles()
// Exit the program gracefully

View file

@ -119,7 +119,7 @@ func Run() (err error) {
&cli.StringFlag{Name: "pass", Value: models.DEFAULT_PASSPHRASE, Usage: "password for the relay", EnvVars: []string{"CROC_PASS"}},
&cli.StringFlag{Name: "socks5", Value: "", Usage: "add a socks5 proxy", EnvVars: []string{"SOCKS5_PROXY"}},
&cli.StringFlag{Name: "connect", Value: "", Usage: "add a http proxy", EnvVars: []string{"HTTP_PROXY"}},
&cli.StringFlag{Name: "throttleUpload", Value: "", Usage: "throttle the upload speed e.g. 500k"},
&cli.StringFlag{Name: "throttleUpload", Value: "", Usage: "Throttle the upload speed e.g. 500k"},
}
app.EnableBashCompletion = true
app.HideHelp = false
@ -478,7 +478,9 @@ Or you can go back to the classic croc behavior by enabling classic mode:
// save the config
saveConfig(c, crocOptions)
err = cr.Send(minimalFileInfos, emptyFoldersToTransfer, totalNumberFolders)
return
}

View file

@ -142,9 +142,7 @@ func (c *Comm) Read() (buf []byte, numBytes int, bs []byte, err error) {
log.Warnf("error setting read deadline: %v", err)
}
// must clear the timeout setting
if err := c.connection.SetDeadline(time.Time{}); err != nil {
log.Warnf("failed to clear deadline: %v", err)
}
defer c.connection.SetDeadline(time.Time{})
// read until we get 4 bytes for the magic
header := make([]byte, 4)

View file

@ -32,11 +32,7 @@ func TestComm(t *testing.T) {
log.Error(err)
return
}
defer func() {
if err := server.Close(); err != nil {
log.Error(err)
}
}()
defer server.Close()
// spawn a new goroutine whenever a client connects
for {
connection, err := server.Accept()

View file

@ -258,7 +258,6 @@ type TransferOptions struct {
KeepPathInRemote bool
}
// helper function checking for an empty folder
func isEmptyFolder(folderPath string) (bool, error) {
f, err := os.Open(folderPath)
if err != nil {
@ -314,6 +313,15 @@ func isChild(parentPath, childPath string) bool {
return !strings.HasPrefix(relPath, "..")
}
func recursiveFiles(path string) (paths []string, err error) {
paths = []string{strings.ToLower(path)}
err = filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
paths = append(paths, strings.ToLower(path))
return nil
})
return
}
// This function retrieves the important file information
// for every file that will be transferred
func GetFilesInfo(fnames []string, zipfolder bool, ignoreGit bool, exclusions []string) (filesInfo []FileInfo, emptyFolders []FileInfo, totalNumberFolders int, err error) {
@ -671,7 +679,7 @@ On the other computer run:
machid, _ := machineid.ID()
fmt.Fprintf(os.Stderr, "\rYour machine ID is '%s'\n", machid)
}
// c.spinner.Suffix = " waiting for recipient..."
// // c.spinner.Suffix = " waiting for recipient..."
// c.spinner.Start()
// create channel for quitting
// connect to the relay for messaging
@ -822,7 +830,8 @@ On the other computer run:
err = <-errchan
if err == nil {
return // no error
// return if no error
return
} else {
log.Debugf("error from errchan: %v", err)
if strings.Contains(err.Error(), "could not secure channel") {
@ -979,6 +988,7 @@ func (c *Client) Receive() (err error) {
if c.Options.TestFlag || (!usingLocal && !c.Options.DisableLocal && !isIPset) {
// ask the sender for their local ips and port
// and try to connect to them
var ips []string
err = func() (err error) {
var A *pake.Pake
@ -1281,7 +1291,7 @@ func (c *Client) processMessageFileInfo(m message.Message) (done bool, err error
}
}
}
// check the totalSize does not exceed disk space
// // check the totalSize does not exceed disk space
// usage := diskusage.NewDiskUsage(".")
// if usage.Available() < uint64(totalSize) {
// return true, fmt.Errorf("not enough disk space")
@ -1445,6 +1455,7 @@ func (c *Client) processMessagePake(m message.Message) (err error) {
}(i)
}
wg.Wait()
if !c.Options.IsSender {
log.Debug("sending external IP")
err = message.Send(c.conn[0], c.Key, message.Message{
@ -2124,48 +2135,26 @@ func (c *Client) sendData(i int) {
}
}
// isExecutableInPath checks for the availability of an executable
func isExecutableInPath(executableName string) bool {
_, err := exec.LookPath(executableName)
return err == nil
}
// copyToClipboard tries to send the code to the operating system clipboard
func copyToClipboard(str string) {
var cmd *exec.Cmd
switch runtime.GOOS {
// Windows should always have clip.exe in PATH by default
case "windows":
cmd = exec.Command("clip")
// MacOS uses pbcopy
case "darwin":
cmd = exec.Command("pbcopy")
// These Unix-like systems are likely using Xorg(with xclip or xsel) or Wayland(with wl-copy)
case "linux", "hurd", "freebsd", "openbsd", "netbsd", "dragonfly", "solaris", "illumos", "plan9":
if os.Getenv("XDG_SESSION_TYPE") == "wayland" { // Wayland running
case "linux":
if os.Getenv("XDG_SESSION_TYPE") == "wayland" {
cmd = exec.Command("wl-copy")
} else if os.Getenv("XDG_SESSION_TYPE") == "x11" || os.Getenv("XDG_SESSION_TYPE") == "xorg" { // Xorg running
if isExecutableInPath("xclip") {
cmd = exec.Command("xclip", "-selection", "clipboard")
}
} else {
if isExecutableInPath("xsel") {
cmd = exec.Command("xsel", "-b")
}
cmd = exec.Command("xclip", "-selection", "clipboard")
}
default:
return
}
// Nothing has been found
if cmd == nil {
log.Warn("system not supported, display server not supported or supported clipboard tool missing!")
return
}
// Sending stdin into the available clipboard program
cmd.Stdin = bytes.NewReader([]byte(str))
if err := cmd.Run(); err != nil {
log.Debugf("error copying to clipboard: %v", err)
return
}
fmt.Fprintf(os.Stderr, "Code copied to clipboard!\n")
fmt.Fprintf(os.Stderr, "Code copied to clipboard\n")
}

View file

@ -46,7 +46,7 @@ func replaceInFile(fname, start, end, replacement string) (err error) {
if err != nil {
return
}
oldVersion := getStringInBetween(string(b), start, end)
oldVersion := GetStringInBetween(string(b), start, end)
if oldVersion == "" {
err = fmt.Errorf("nothing")
return
@ -61,8 +61,8 @@ func replaceInFile(fname, start, end, replacement string) (err error) {
return
}
// getStringInBetween Returns empty string if no start string found
func getStringInBetween(str, start, end string) (result string) {
// GetStringInBetween Returns empty string if no start string found
func GetStringInBetween(str string, start string, end string) (result string) {
s := strings.Index(str, start)
if s == -1 {
return

View file

@ -281,12 +281,11 @@ func LocalIP() string {
return localAddr.IP.String()
}
// GenerateRandomPin returns a randomly generated pin with set lenght
func GenerateRandomPin() string {
s := ""
max := new(big.Int)
max.SetInt64(9)
for range NbPinNumbers {
for i := 0; i < NbPinNumbers; i++ {
v, err := rand.Int(rand.Reader, max)
if err != nil {
panic(err)