Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
5e7e3a1b39 | ||
|
42adceb4c6 | ||
|
f909ad3ce2 | ||
|
8a5c737140 | ||
|
b920eb842a | ||
|
45e0967a37 | ||
|
28614c991d | ||
|
ef28bcb28f | ||
|
2dd23bff3c | ||
|
663c59e754 |
65
README.md
65
README.md
@@ -76,40 +76,43 @@ https://transfer.sh/1lDau/test.txt --> https://transfer.sh/inline/1lDau/test.txt
|
||||
|
||||
Parameter | Description | Value | Env
|
||||
--- | --- | --- | ---
|
||||
listener | port to use for http (:80) | |
|
||||
profile-listener | port to use for profiler (:6060)| |
|
||||
force-https | redirect to https | false |
|
||||
tls-listener | port to use for https (:443) | |
|
||||
tls-listener-only | flag to enable tls listener only | |
|
||||
tls-cert-file | path to tls certificate | |
|
||||
tls-private-key | path to tls private key | |
|
||||
http-auth-user | user for basic http auth on upload | |
|
||||
http-auth-pass | pass for basic http auth on upload | |
|
||||
ip-whitelist | comma separated list of ips allowed to connect to the service | |
|
||||
ip-blacklist | comma separated list of ips not allowed to connect to the service | |
|
||||
temp-path | path to temp folder | system temp |
|
||||
web-path | path to static web files (for development or custom front end) | |
|
||||
proxy-path | path prefix when service is run behind a proxy | |
|
||||
ga-key | google analytics key for the front end | |
|
||||
uservoice-key | user voice key for the front end | |
|
||||
provider | which storage provider to use | (s3, gdrive or local) |
|
||||
aws-access-key | aws access key | | AWS_ACCESS_KEY
|
||||
aws-secret-key | aws access key | | AWS_SECRET_KEY
|
||||
bucket | aws bucket | | BUCKET
|
||||
s3-endpoint | Custom S3 endpoint. | |
|
||||
s3-region | region of the s3 bucket | eu-west-1 | S3_REGION
|
||||
s3-no-multipart | disables s3 multipart upload | false | |
|
||||
s3-path-style | Forces path style URLs, required for Minio. | false | |
|
||||
basedir | path storage for local/gdrive provider| |
|
||||
gdrive-client-json-filepath | path to oauth client json config for gdrive provider| |
|
||||
gdrive-local-config-path | path to store local transfer.sh config cache for gdrive provider| |
|
||||
gdrive-chunk-size | chunk size for gdrive upload in megabytes, must be lower than available memory (8 MB) | |
|
||||
lets-encrypt-hosts | hosts to use for lets encrypt certificates (comma seperated) | |
|
||||
log | path to log file| |
|
||||
listener | port to use for http (:80) | | LISTENER |
|
||||
profile-listener | port to use for profiler (:6060) | | PROFILE_LISTENER |
|
||||
force-https | redirect to https | false | FORCE_HTTPS
|
||||
tls-listener | port to use for https (:443) | | TLS_LISTENER |
|
||||
tls-listener-only | flag to enable tls listener only | | TLS_LISTENER_ONLY |
|
||||
tls-cert-file | path to tls certificate | | TLS_CERT_FILE |
|
||||
tls-private-key | path to tls private key | | TLS_PRIVATE_KEY |
|
||||
http-auth-user | user for basic http auth on upload | | HTTP_AUTH_USER |
|
||||
http-auth-pass | pass for basic http auth on upload | | HTTP_AUTH_PASS |
|
||||
ip-whitelist | comma separated list of ips allowed to connect to the service | | IP_WHITELIST |
|
||||
ip-blacklist | comma separated list of ips not allowed to connect to the service | | IP_BLACKLIST |
|
||||
temp-path | path to temp folder | system temp | TEMP_PATH |
|
||||
web-path | path to static web files (for development or custom front end) | | WEB_PATH |
|
||||
proxy-path | path prefix when service is run behind a proxy | | PROXY_PATH |
|
||||
ga-key | google analytics key for the front end | | GA_KEY |
|
||||
uservoice-key | user voice key for the front end | | USERVOICE_KEY |
|
||||
provider | which storage provider to use | (s3, gdrive or local) | PROVIDER |
|
||||
aws-access-key | aws access key | | AWS_ACCESS_KEY |
|
||||
aws-secret-key | aws access key | | AWS_SECRET_KEY |
|
||||
bucket | aws bucket | | BUCKET |
|
||||
s3-endpoint | Custom S3 endpoint. | | S3_ENDPOINT |
|
||||
s3-region | region of the s3 bucket | eu-west-1 | S3_REGION |
|
||||
s3-no-multipart | disables s3 multipart upload | false | S3_NO_MULTIPART |
|
||||
s3-path-style | Forces path style URLs, required for Minio. | false | S3_PATH_STYLE |
|
||||
basedir | path storage for local/gdrive provider | | BASEDIR |
|
||||
gdrive-client-json-filepath | path to oauth client json config for gdrive provider | | GDRIVE_CLIENT_JSON_FILEPATH |
|
||||
gdrive-local-config-path | path to store local transfer.sh config cache for gdrive provider| | GDRIVE_LOCAL_CONFIG_PATH |
|
||||
gdrive-chunk-size | chunk size for gdrive upload in megabytes, must be lower than available memory (8 MB) | | GDRIVE_CHUNK_SIZE |
|
||||
lets-encrypt-hosts | hosts to use for lets encrypt certificates (comma seperated) | | HOSTS |
|
||||
log | path to log file| | LOG |
|
||||
cors-domains | comma separated list of domains for CORS, setting it enable CORS | | CORS_DOMAINS |
|
||||
clamav-host | host for clamav feature | | CLAMAV_HOST |
|
||||
rate-limit | request per minute | | RATE_LIMIT |
|
||||
|
||||
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.
|
||||
|
||||
If you want to use TLS using your own certificates, set tls-listener to :443, force-https, tls-cert=file and tls-private-key.
|
||||
If you want to use TLS using your own certificates, set tls-listener to :443, force-https, tls-cert-file and tls-private-key.
|
||||
|
||||
## Development
|
||||
|
||||
|
39
cmd/cmd.go
39
cmd/cmd.go
@@ -12,7 +12,7 @@ import (
|
||||
"google.golang.org/api/googleapi"
|
||||
)
|
||||
|
||||
var Version = "1.1.4"
|
||||
var Version = "1.1.7"
|
||||
var helpTemplate = `NAME:
|
||||
{{.Name}} - {{.Usage}}
|
||||
|
||||
@@ -37,6 +37,7 @@ var globalFlags = []cli.Flag{
|
||||
Name: "listener",
|
||||
Usage: "127.0.0.1:8080",
|
||||
Value: "127.0.0.1:8080",
|
||||
EnvVar: "LISTENER",
|
||||
},
|
||||
// redirect to https?
|
||||
// hostnames
|
||||
@@ -44,57 +45,69 @@ var globalFlags = []cli.Flag{
|
||||
Name: "profile-listener",
|
||||
Usage: "127.0.0.1:6060",
|
||||
Value: "",
|
||||
EnvVar: "PROFILE_LISTENER",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "force-https",
|
||||
Usage: "",
|
||||
EnvVar: "FORCE_HTTPS",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "tls-listener",
|
||||
Usage: "127.0.0.1:8443",
|
||||
Value: "",
|
||||
EnvVar: "TLS_LISTENER",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "tls-listener-only",
|
||||
Usage: "",
|
||||
EnvVar: "TLS_LISTENER_ONLY",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "tls-cert-file",
|
||||
Value: "",
|
||||
EnvVar: "TLS_CERT_FILE",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "tls-private-key",
|
||||
Value: "",
|
||||
EnvVar: "TLS_PRIVATE_KEY",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "temp-path",
|
||||
Usage: "path to temp files",
|
||||
Value: os.TempDir(),
|
||||
EnvVar: "TEMP_PATH",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "web-path",
|
||||
Usage: "path to static web files",
|
||||
Value: "",
|
||||
EnvVar: "WEB_PATH",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "proxy-path",
|
||||
Usage: "path prefix when service is run behind a proxy",
|
||||
Value: "",
|
||||
EnvVar: "PROXY_PATH",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "ga-key",
|
||||
Usage: "key for google analytics (front end)",
|
||||
Value: "",
|
||||
EnvVar: "GA_KEY",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "uservoice-key",
|
||||
Usage: "key for user voice (front end)",
|
||||
Value: "",
|
||||
EnvVar: "USERVOICE_KEY",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "provider",
|
||||
Usage: "s3|gdrive|local",
|
||||
Value: "",
|
||||
EnvVar: "PROVIDER",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "s3-endpoint",
|
||||
@@ -129,31 +142,36 @@ var globalFlags = []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "s3-no-multipart",
|
||||
Usage: "Disables S3 Multipart Puts",
|
||||
EnvVar: "S3_NO_MULTIPART",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "s3-path-style",
|
||||
Usage: "Forces path style URLs, required for Minio.",
|
||||
EnvVar: "S3_PATH_STYLE",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "gdrive-client-json-filepath",
|
||||
Usage: "",
|
||||
Value: "",
|
||||
EnvVar: "GDRIVE_CLIENT_JSON_FILEPATH",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "gdrive-local-config-path",
|
||||
Usage: "",
|
||||
Value: "",
|
||||
EnvVar: "GDRIVE_LOCAL_CONFIG_PATH",
|
||||
},
|
||||
cli.IntFlag{
|
||||
Name: "gdrive-chunk-size",
|
||||
Usage: "",
|
||||
Value: googleapi.DefaultUploadChunkSize / 1024 / 1024,
|
||||
EnvVar: "GDRIVE_CHUNK_SIZE",
|
||||
},
|
||||
cli.IntFlag{
|
||||
Name: "rate-limit",
|
||||
Usage: "requests per minute",
|
||||
Value: 0,
|
||||
EnvVar: "",
|
||||
EnvVar: "RATE_LIMIT",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "lets-encrypt-hosts",
|
||||
@@ -165,11 +183,13 @@ var globalFlags = []cli.Flag{
|
||||
Name: "log",
|
||||
Usage: "/var/log/transfersh.log",
|
||||
Value: "",
|
||||
EnvVar: "LOG",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "basedir",
|
||||
Usage: "path to storage",
|
||||
Value: "",
|
||||
EnvVar: "BASEDIR",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "clamav-host",
|
||||
@@ -186,26 +206,37 @@ var globalFlags = []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "profiler",
|
||||
Usage: "enable profiling",
|
||||
EnvVar: "PROFILER",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "http-auth-user",
|
||||
Usage: "user for http basic auth",
|
||||
Value: "",
|
||||
EnvVar: "HTTP_AUTH_USER",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "http-auth-pass",
|
||||
Usage: "pass for http basic auth",
|
||||
Value: "",
|
||||
EnvVar: "HTTP_AUTH_PASS",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "ip-whitelist",
|
||||
Usage: "comma separated list of ips allowed to connect to the service",
|
||||
Value: "",
|
||||
EnvVar: "IP_WHITELIST",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "ip-blacklist",
|
||||
Usage: "comma separated list of ips not allowed to connect to the service",
|
||||
Value: "",
|
||||
EnvVar: "IP_BLACKLIST",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "cors-domains",
|
||||
Usage: "comma separated list of domains allowed for CORS requests",
|
||||
Value: "",
|
||||
EnvVar: "CORS_DOMAINS",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -245,6 +276,10 @@ func New() *Cmd {
|
||||
options = append(options, server.Listener(v))
|
||||
}
|
||||
|
||||
if v := c.String("cors-domains"); v != "" {
|
||||
options = append(options, server.CorsDomains(v))
|
||||
}
|
||||
|
||||
if v := c.String("tls-listener"); v == "" {
|
||||
} else if c.Bool("tls-listener-only") {
|
||||
options = append(options, server.TLSListener(v, true))
|
||||
|
1
go.mod
1
go.mod
@@ -16,6 +16,7 @@ require (
|
||||
github.com/garyburd/redigo v1.6.0 // indirect
|
||||
github.com/golang/gddo v0.0.0-20200310004957-95ce5a452273
|
||||
github.com/golang/protobuf v1.3.5 // indirect
|
||||
github.com/gorilla/handlers v1.4.2
|
||||
github.com/gorilla/mux v1.7.4
|
||||
github.com/gorilla/securecookie v1.1.1 // indirect
|
||||
github.com/hashicorp/golang-lru v0.5.3 // indirect
|
||||
|
2
go.sum
2
go.sum
@@ -127,6 +127,8 @@ github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk
|
||||
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
|
||||
github.com/googleapis/gax-go/v2 v2.0.5 h1:sjZBwGj9Jlw33ImPtvFviGYvseOtDM7hkSKB7+Tv3SM=
|
||||
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
|
||||
github.com/gorilla/handlers v1.4.2 h1:0QniY0USkHQ1RGCLfKxeNHK9bkDHGRYGNDFBCS+YARg=
|
||||
github.com/gorilla/handlers v1.4.2/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ=
|
||||
github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw=
|
||||
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
||||
github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc=
|
||||
|
@@ -614,9 +614,7 @@ func (s *Server) CheckMetadata(token, filename string, increaseDownload bool) (M
|
||||
var metadata Metadata
|
||||
|
||||
r, _, err := s.storage.Get(token, fmt.Sprintf("%s.metadata", filename))
|
||||
if s.storage.IsNotExist(err) {
|
||||
return metadata, nil
|
||||
} else if err != nil {
|
||||
if err != nil {
|
||||
return metadata, err
|
||||
}
|
||||
|
||||
|
@@ -26,6 +26,7 @@ package server
|
||||
|
||||
import (
|
||||
"errors"
|
||||
gorillaHandlers "github.com/gorilla/handlers"
|
||||
"log"
|
||||
"math/rand"
|
||||
"mime"
|
||||
@@ -85,6 +86,13 @@ func Listener(s string) OptionFn {
|
||||
|
||||
}
|
||||
|
||||
func CorsDomains(s string) OptionFn {
|
||||
return func(srvr *Server) {
|
||||
srvr.CorsDomains = s
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func GoogleAnalytics(gaKey string) OptionFn {
|
||||
return func(srvr *Server) {
|
||||
srvr.gaKey = gaKey
|
||||
@@ -275,6 +283,7 @@ type Server struct {
|
||||
|
||||
TLSListenerOnly bool
|
||||
|
||||
CorsDomains string
|
||||
ListenerString string
|
||||
TLSListenerString string
|
||||
ProfileListenerString string
|
||||
@@ -413,11 +422,24 @@ func (s *Server) Run() {
|
||||
|
||||
s.logger.Printf("Transfer.sh server started.\nusing temp folder: %s\nusing storage provider: %s", s.tempPath, s.storage.Type())
|
||||
|
||||
var cors func(http.Handler) http.Handler
|
||||
if len(s.CorsDomains) > 0 {
|
||||
cors = gorillaHandlers.CORS(
|
||||
gorillaHandlers.AllowedHeaders([]string{"*"}),
|
||||
gorillaHandlers.AllowedOrigins(strings.Split(s.CorsDomains, ",")),
|
||||
gorillaHandlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS"}),
|
||||
)
|
||||
} else {
|
||||
cors = func(h http.Handler) http.Handler {
|
||||
return h
|
||||
}
|
||||
}
|
||||
|
||||
h := handlers.PanicHandler(
|
||||
IPFilterHandler(
|
||||
handlers.LogHandler(
|
||||
LoveHandler(
|
||||
s.RedirectHandler(r)),
|
||||
s.RedirectHandler(cors(r))),
|
||||
handlers.NewLogOptions(s.logger.Printf, "_default_"),
|
||||
),
|
||||
s.ipFilterOptions,
|
||||
|
Reference in New Issue
Block a user