diff --git a/LICENSE b/LICENSE index 0723708..bc796f9 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014 DutchCoders [https://github.com/dutchcoders/] +Copyright (c) 2014-2018 DutchCoders [https://github.com/dutchcoders/] Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 2e1a745..2ee0860 100644 --- a/README.md +++ b/README.md @@ -8,15 +8,19 @@ Transfer.sh currently supports the s3 (Amazon S3), gdrive (Google Drive) provide ``` Upload: + $ curl --upload-file ./hello.txt https://transfer.sh/hello.txt Encrypt & upload: + $ cat /tmp/hello.txt|gpg -ac -o-|curl -X PUT --upload-file "-" https://transfer.sh/test.txt Download & decrypt: + $ curl https://transfer.sh/1lDau/test.txt|gpg -o- > /tmp/hello.txt Upload to virustotal: + $ curl -X PUT --upload-file nhgbhhj https://transfer.sh/test.txt/virustotal ``` @@ -33,6 +37,16 @@ Now run it like this $ transfer test.txt ``` +## Link aliases + +Create direct download link: + +https://transfer.sh/1lDau/test.txt --> https://transfer.sh/get/1lDau/test.txt + +Inline file: + +https://transfer.sh/1lDau/test.txt --> https://transfer.sh/inline/1lDau/test.txt + ### On Windows Put a file called transfer.cmd somewhere in your PATH with this inside it: @@ -70,7 +84,7 @@ basedir | path storage for local/gdrive provider| | gdrive-client-json-filepath | path to client json config for gdrive provider| | gdrive-local-config-path | path to local transfer.sh config cache for gdrive provider| | lets-encrypt-hosts | hosts to use for lets encrypt certificates (comma seperated) | | -log | path to log file| | +log | path to log file| | If you want to use TLS using lets encrypt certificates, set lets-encrypt-hosts to your domain, set tls-listener to :443 and enable force-https. @@ -81,7 +95,7 @@ If you want to use TLS using your own certificates, set tls-listener to :443, fo Make sure your GOPATH is set correctly. ``` -go run main.go -provider=local --listener :8080 --temp-path=/tmp/ --basedir=/tmp/ +go run main.go -provider=local --listener :8080 --temp-path=/tmp/ --basedir=/tmp/ ``` ## Build @@ -102,7 +116,7 @@ docker run --publish 8080:8080 dutchcoders/transfer.sh:latest --provider local - Contributions are welcome. -## Creators +## Creators **Remco Verhoef** - @@ -112,5 +126,5 @@ Contributions are welcome. ## Copyright and license -Code and documentation copyright 2011-2014 Remco Verhoef. -Code released under [the MIT license](LICENSE). +Code and documentation copyright 2011-2014 Remco Verhoef. +Code released under [the MIT license](LICENSE). diff --git a/server/handlers.go b/server/handlers.go index 83079a2..34f5ead 100644 --- a/server/handlers.go +++ b/server/handlers.go @@ -791,9 +791,37 @@ func (s *Server) tarHandler(w http.ResponseWriter, r *http.Request) { } } +func (s *Server) headHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + + token := vars["token"] + filename := vars["filename"] + + if err := s.CheckMetadata(token, filename); err != nil { + log.Printf("Error metadata: %s", err.Error()) + http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) + return + } + + contentType, contentLength, err := s.storage.Head(token, filename) + if s.storage.IsNotExist(err) { + http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) + return + } else if err != nil { + log.Printf("%s", err.Error()) + http.Error(w, "Could not retrieve file.", 500) + return + } + + w.Header().Set("Content-Type", contentType) + w.Header().Set("Content-Length", strconv.FormatUint(contentLength, 10)) + w.Header().Set("Connection", "close") +} + func (s *Server) getHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) + action := vars["action"] token := vars["token"] filename := vars["filename"] @@ -815,10 +843,18 @@ func (s *Server) getHandler(w http.ResponseWriter, r *http.Request) { defer reader.Close() + var disposition string + + if action == "inline" { + disposition = "inline" + } else { + disposition = "attachment" + } + w.Header().Set("Content-Type", contentType) w.Header().Set("Content-Length", strconv.FormatUint(contentLength, 10)) - w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", filename)) - w.Header().Set("Connection", "close") + w.Header().Set("Content-Disposition", fmt.Sprintf("%s; filename=\"%s\"", disposition, filename)) + w.Header().Set("Connection", "keep-alive") if _, err = io.Copy(w, reader); err != nil { log.Printf("%s", err.Error()) diff --git a/server/server.go b/server/server.go index c288b6a..f6d6902 100644 --- a/server/server.go +++ b/server/server.go @@ -324,6 +324,9 @@ func (s *Server) Run() { r.HandleFunc("/({files:.*}).tar", s.tarHandler).Methods("GET") r.HandleFunc("/({files:.*}).tar.gz", s.tarGzHandler).Methods("GET") + r.HandleFunc("/{token}/{filename}", s.headHandler).Methods("HEAD") + r.HandleFunc("/{action:(?:download|get|inline)}/{token}/{filename}", s.headHandler).Methods("HEAD") + r.HandleFunc("/{token}/{filename}", s.previewHandler).MatcherFunc(func(r *http.Request, rm *mux.RouteMatch) (match bool) { match = false @@ -352,8 +355,7 @@ func (s *Server) Run() { } r.HandleFunc("/{token}/{filename}", getHandlerFn).Methods("GET") - r.HandleFunc("/get/{token}/{filename}", getHandlerFn).Methods("GET") - r.HandleFunc("/download/{token}/{filename}", getHandlerFn).Methods("GET") + r.HandleFunc("/{action:(?:download|get|inline)}/{token}/{filename}", getHandlerFn).Methods("GET") r.HandleFunc("/{filename}/virustotal", s.virusTotalHandler).Methods("PUT") r.HandleFunc("/{filename}/scan", s.scanHandler).Methods("PUT")