Compare commits
3 Commits
ISSUE-440
...
changes-in
Author | SHA1 | Date | |
---|---|---|---|
|
0953383523 | ||
|
6f49951bc0 | ||
|
d2a0e77814 |
4
.github/workflows/build-docker-images.yml
vendored
4
.github/workflows/build-docker-images.yml
vendored
@@ -4,9 +4,9 @@ on:
|
||||
schedule:
|
||||
- cron: '0 0 * * *' # everyday at midnight UTC
|
||||
pull_request:
|
||||
branches: master
|
||||
branches: main
|
||||
push:
|
||||
branches: master
|
||||
branches: main
|
||||
tags:
|
||||
- v*
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
# transfer.sh [](https://goreportcard.com/report/github.com/dutchcoders/transfer.sh) [](https://hub.docker.com/r/dutchcoders/transfer.sh/) [](https://github.com/dutchcoders/transfer.sh/actions/workflows/test.yml?query=branch%3Amaster)
|
||||
# transfer.sh [](https://goreportcard.com/report/github.com/dutchcoders/transfer.sh) [](https://hub.docker.com/r/dutchcoders/transfer.sh/) [](https://github.com/dutchcoders/transfer.sh/actions/workflows/test.yml?query=branch%3Amain)
|
||||
|
||||
Easy and fast file sharing from the command-line. This code contains the server with everything you need to create your own instance.
|
||||
|
||||
@@ -90,6 +90,7 @@ 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 |
|
||||
proxy-port | port of the proxy when the service is run behind a proxy | | PROXY_PORT |
|
||||
email-contact | email contact for the front end | | EMAIL_CONTACT |
|
||||
ga-key | google analytics key for the front end | | GA_KEY |
|
||||
provider | which storage provider to use | (s3, storj, gdrive or local) |
|
||||
uservoice-key | user voice key for the front end | | USERVOICE_KEY |
|
||||
|
10
cmd/cmd.go
10
cmd/cmd.go
@@ -98,6 +98,12 @@ var globalFlags = []cli.Flag{
|
||||
Value: "",
|
||||
EnvVar: "PROXY_PORT",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "email-contact",
|
||||
Usage: "email address to link in Contact Us (front end)",
|
||||
Value: "",
|
||||
EnvVar: "EMAIL_CONTACT",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "ga-key",
|
||||
Usage: "key for google analytics (front end)",
|
||||
@@ -348,6 +354,10 @@ func New() *Cmd {
|
||||
options = append(options, server.ProxyPort(v))
|
||||
}
|
||||
|
||||
if v := c.String("email-contact"); v != "" {
|
||||
options = append(options, server.EmailContact(v))
|
||||
}
|
||||
|
||||
if v := c.String("ga-key"); v != "" {
|
||||
options = append(options, server.GoogleAnalytics(v))
|
||||
}
|
||||
|
@@ -51,6 +51,7 @@
|
||||
proxy-path = mkOption { type = types.nullOr types.str; description = "path prefix when service is run behind a proxy"; };
|
||||
proxy-port = mkOption { type = types.nullOr types.str; description = "port of the proxy when the service is run behind a proxy"; };
|
||||
ga-key = mkOption { type = types.nullOr types.str; description = "google analytics key for the front end"; };
|
||||
email-contact = mkOption { type = types.nullOr types.str; description = "email contact for the front end"; };
|
||||
uservoice-key = mkOption { type = types.nullOr types.str; description = "user voice key for the front end"; };
|
||||
lets-encrypt-hosts = mkOption { type = types.nullOr (types.listOf types.str); description = "hosts to use for lets encrypt certificates"; };
|
||||
log = mkOption { type = types.nullOr types.str; description = "path to log file"; };
|
||||
|
2
go.mod
2
go.mod
@@ -12,7 +12,7 @@ require (
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
|
||||
github.com/dutchcoders/go-clamd v0.0.0-20170520113014-b970184f4d9e
|
||||
github.com/dutchcoders/go-virustotal v0.0.0-20140923143438-24cc8e6fa329
|
||||
github.com/dutchcoders/transfer.sh-web v0.0.0-20210819203540-bbdd40be1311
|
||||
github.com/dutchcoders/transfer.sh-web v0.0.0-20211215083008-31e11925a9d3
|
||||
github.com/elazarl/go-bindata-assetfs v1.0.1
|
||||
github.com/fatih/color v1.10.0
|
||||
github.com/garyburd/redigo v1.6.2 // indirect
|
||||
|
2
go.sum
2
go.sum
@@ -88,6 +88,8 @@ github.com/dutchcoders/transfer.sh-web v0.0.0-20210723094506-f0946ebceb7a h1:+N7
|
||||
github.com/dutchcoders/transfer.sh-web v0.0.0-20210723094506-f0946ebceb7a/go.mod h1:F6Q37CxDh2MHr5KXkcZmNB3tdkK7v+bgE+OpBY+9ilI=
|
||||
github.com/dutchcoders/transfer.sh-web v0.0.0-20210819203540-bbdd40be1311 h1:/Rwuhcp8ZLUauWajAgMyy6AiVbobvD52I+/OnzThK0A=
|
||||
github.com/dutchcoders/transfer.sh-web v0.0.0-20210819203540-bbdd40be1311/go.mod h1:F6Q37CxDh2MHr5KXkcZmNB3tdkK7v+bgE+OpBY+9ilI=
|
||||
github.com/dutchcoders/transfer.sh-web v0.0.0-20211215083008-31e11925a9d3 h1:HyfU90/8y9S5IkHTQgIfzs4dT3iagbJUJLncCsSwZCI=
|
||||
github.com/dutchcoders/transfer.sh-web v0.0.0-20211215083008-31e11925a9d3/go.mod h1:F6Q37CxDh2MHr5KXkcZmNB3tdkK7v+bgE+OpBY+9ilI=
|
||||
github.com/elazarl/go-bindata-assetfs v1.0.1 h1:m0kkaHRKEu7tUIUFVwhGGGYClXvyl4RE03qmvRTNfbw=
|
||||
github.com/elazarl/go-bindata-assetfs v1.0.1/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
|
@@ -253,6 +253,7 @@ func (s *Server) viewHandler(w http.ResponseWriter, r *http.Request) {
|
||||
data := struct {
|
||||
Hostname string
|
||||
WebAddress string
|
||||
EmailContact string
|
||||
GAKey string
|
||||
UserVoiceKey string
|
||||
PurgeTime string
|
||||
@@ -262,6 +263,7 @@ func (s *Server) viewHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}{
|
||||
hostname,
|
||||
webAddress,
|
||||
s.emailContact,
|
||||
s.gaKey,
|
||||
s.userVoiceKey,
|
||||
purgeTime,
|
||||
@@ -630,25 +632,24 @@ func getURL(r *http.Request, proxyPort string) *url.URL {
|
||||
u.Scheme = "http"
|
||||
}
|
||||
|
||||
if u.Host == "" {
|
||||
host, port, err := net.SplitHostPort(r.Host)
|
||||
if err != nil {
|
||||
host = r.Host
|
||||
port = ""
|
||||
}
|
||||
if len(proxyPort) != 0 {
|
||||
port = proxyPort
|
||||
}
|
||||
if len(port) == 0 {
|
||||
host, port, err := net.SplitHostPort(r.Host)
|
||||
if err != nil {
|
||||
host = r.Host
|
||||
port = ""
|
||||
}
|
||||
if len(proxyPort) != 0 {
|
||||
port = proxyPort
|
||||
}
|
||||
|
||||
if len(port) == 0 {
|
||||
u.Host = host
|
||||
} else {
|
||||
if port == "80" && u.Scheme == "http" {
|
||||
u.Host = host
|
||||
} else if port == "443" && u.Scheme == "https" {
|
||||
u.Host = host
|
||||
} else {
|
||||
if port == "80" && u.Scheme == "http" {
|
||||
u.Host = host
|
||||
} else if port == "443" && u.Scheme == "https" {
|
||||
u.Host = host
|
||||
} else {
|
||||
u.Host = net.JoinHostPort(host, port)
|
||||
}
|
||||
u.Host = net.JoinHostPort(host, port)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1099,10 +1100,22 @@ func (s *Server) RedirectHandler(h http.Handler) http.HandlerFunc {
|
||||
} else if strings.HasSuffix(ipAddrFromRemoteAddr(r.Host), ".onion") {
|
||||
// .onion addresses cannot get a valid certificate, so don't redirect
|
||||
} else if r.Header.Get("X-Forwarded-Proto") == "https" {
|
||||
} else if r.URL.Scheme == "https" {
|
||||
} else if r.TLS != nil {
|
||||
} else {
|
||||
u := getURL(r, s.proxyPort)
|
||||
u.Scheme = "https"
|
||||
if len(s.proxyPort) == 0 && len(s.TLSListenerString) > 0 {
|
||||
_, port, err := net.SplitHostPort(s.TLSListenerString)
|
||||
if err != nil || port == "443" {
|
||||
port = ""
|
||||
}
|
||||
|
||||
if len(port) > 0 {
|
||||
u.Host = net.JoinHostPort(u.Hostname(), port)
|
||||
} else {
|
||||
u.Host = u.Hostname()
|
||||
}
|
||||
}
|
||||
|
||||
http.Redirect(w, r, u.String(), http.StatusPermanentRedirect)
|
||||
return
|
||||
|
@@ -99,6 +99,13 @@ func CorsDomains(s string) OptionFn {
|
||||
|
||||
}
|
||||
|
||||
// EmailContact sets email contact
|
||||
func EmailContact(emailContact string) OptionFn {
|
||||
return func(srvr *Server) {
|
||||
srvr.emailContact = emailContact
|
||||
}
|
||||
}
|
||||
|
||||
// GoogleAnalytics sets GA key
|
||||
func GoogleAnalytics(gaKey string) OptionFn {
|
||||
return func(srvr *Server) {
|
||||
@@ -339,6 +346,7 @@ type Server struct {
|
||||
webPath string
|
||||
proxyPath string
|
||||
proxyPort string
|
||||
emailContact string
|
||||
gaKey string
|
||||
userVoiceKey string
|
||||
|
||||
|
Reference in New Issue
Block a user