2017-03-22 18:09:21 +01:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2023-05-19 07:51:40 +02:00
|
|
|
"errors"
|
2017-03-22 18:09:21 +01:00
|
|
|
"fmt"
|
2019-03-19 11:35:30 +01:00
|
|
|
"log"
|
2017-03-22 18:09:21 +01:00
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
2023-03-11 02:08:55 +01:00
|
|
|
"github.com/dutchcoders/transfer.sh/server/storage"
|
|
|
|
|
2017-03-22 18:09:21 +01:00
|
|
|
"github.com/dutchcoders/transfer.sh/server"
|
|
|
|
"github.com/fatih/color"
|
2023-05-19 07:51:40 +02:00
|
|
|
"github.com/urfave/cli/v2"
|
2019-03-18 20:52:38 +01:00
|
|
|
"google.golang.org/api/googleapi"
|
2017-03-22 18:09:21 +01:00
|
|
|
)
|
|
|
|
|
2021-08-19 22:45:30 +02:00
|
|
|
// Version is inject at build time
|
2021-07-07 20:51:05 +02:00
|
|
|
var Version = "0.0.0"
|
2017-03-22 18:09:21 +01:00
|
|
|
var helpTemplate = `NAME:
|
|
|
|
{{.Name}} - {{.Usage}}
|
|
|
|
|
|
|
|
DESCRIPTION:
|
|
|
|
{{.Description}}
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
{{.Name}} {{if .Flags}}[flags] {{end}}command{{if .Flags}}{{end}} [arguments...]
|
|
|
|
|
|
|
|
COMMANDS:
|
|
|
|
{{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}}
|
|
|
|
{{end}}{{if .Flags}}
|
|
|
|
FLAGS:
|
|
|
|
{{range .Flags}}{{.}}
|
|
|
|
{{end}}{{end}}
|
|
|
|
VERSION:
|
|
|
|
` + Version +
|
|
|
|
`{{ "\n"}}`
|
|
|
|
|
|
|
|
var globalFlags = []cli.Flag{
|
2023-05-19 07:51:40 +02:00
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "listener",
|
|
|
|
Usage: "127.0.0.1:8080",
|
|
|
|
Value: "127.0.0.1:8080",
|
|
|
|
EnvVars: []string{"LISTENER"},
|
2017-03-22 18:09:21 +01:00
|
|
|
},
|
|
|
|
// redirect to https?
|
|
|
|
// hostnames
|
2023-05-19 07:51:40 +02:00
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "profile-listener",
|
|
|
|
Usage: "127.0.0.1:6060",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"PROFILE_LISTENER"},
|
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "force-https",
|
|
|
|
Usage: "",
|
|
|
|
EnvVars: []string{"FORCE_HTTPS"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "tls-listener",
|
|
|
|
Usage: "127.0.0.1:8443",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"TLS_LISTENER"},
|
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "tls-listener-only",
|
|
|
|
Usage: "",
|
|
|
|
EnvVars: []string{"TLS_LISTENER_ONLY"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "tls-cert-file",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"TLS_CERT_FILE"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "tls-private-key",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"TLS_PRIVATE_KEY"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "temp-path",
|
|
|
|
Usage: "path to temp files",
|
|
|
|
Value: os.TempDir(),
|
|
|
|
EnvVars: []string{"TEMP_PATH"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "web-path",
|
|
|
|
Usage: "path to static web files",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"WEB_PATH"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "proxy-path",
|
|
|
|
Usage: "path prefix when service is run behind a proxy",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"PROXY_PATH"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "proxy-port",
|
|
|
|
Usage: "port of the proxy when the service is run behind a proxy",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"PROXY_PORT"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "email-contact",
|
|
|
|
Usage: "email address to link in Contact Us (front end)",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"EMAIL_CONTACT"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "ga-key",
|
|
|
|
Usage: "key for google analytics (front end)",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"GA_KEY"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "uservoice-key",
|
|
|
|
Usage: "key for user voice (front end)",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"USERVOICE_KEY"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "provider",
|
|
|
|
Usage: "s3|gdrive|local",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"PROVIDER"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "s3-endpoint",
|
|
|
|
Usage: "",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"S3_ENDPOINT"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "s3-region",
|
|
|
|
Usage: "",
|
|
|
|
Value: "eu-west-1",
|
|
|
|
EnvVars: []string{"S3_REGION"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "aws-access-key",
|
|
|
|
Usage: "",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"AWS_ACCESS_KEY"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "aws-secret-key",
|
|
|
|
Usage: "",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"AWS_SECRET_KEY"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "bucket",
|
|
|
|
Usage: "",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"BUCKET"},
|
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "s3-no-multipart",
|
|
|
|
Usage: "Disables S3 Multipart Puts",
|
|
|
|
EnvVars: []string{"S3_NO_MULTIPART"},
|
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "s3-path-style",
|
|
|
|
Usage: "Forces path style URLs, required for Minio.",
|
|
|
|
EnvVars: []string{"S3_PATH_STYLE"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "gdrive-client-json-filepath",
|
|
|
|
Usage: "",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"GDRIVE_CLIENT_JSON_FILEPATH"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "gdrive-local-config-path",
|
|
|
|
Usage: "",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"GDRIVE_LOCAL_CONFIG_PATH"},
|
|
|
|
},
|
|
|
|
&cli.IntFlag{
|
|
|
|
Name: "gdrive-chunk-size",
|
|
|
|
Usage: "",
|
|
|
|
Value: googleapi.DefaultUploadChunkSize / 1024 / 1024,
|
|
|
|
EnvVars: []string{"GDRIVE_CHUNK_SIZE"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "storj-access",
|
|
|
|
Usage: "Access for the project",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"STORJ_ACCESS"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "storj-bucket",
|
|
|
|
Usage: "Bucket to use within the project",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"STORJ_BUCKET"},
|
|
|
|
},
|
|
|
|
&cli.IntFlag{
|
|
|
|
Name: "rate-limit",
|
|
|
|
Usage: "requests per minute",
|
|
|
|
Value: 0,
|
|
|
|
EnvVars: []string{"RATE_LIMIT"},
|
|
|
|
},
|
|
|
|
&cli.IntFlag{
|
|
|
|
Name: "purge-days",
|
|
|
|
Usage: "number of days after uploads are purged automatically",
|
|
|
|
Value: 0,
|
|
|
|
EnvVars: []string{"PURGE_DAYS"},
|
|
|
|
},
|
|
|
|
&cli.IntFlag{
|
|
|
|
Name: "purge-interval",
|
|
|
|
Usage: "interval in hours to run the automatic purge for",
|
|
|
|
Value: 0,
|
|
|
|
EnvVars: []string{"PURGE_INTERVAL"},
|
|
|
|
},
|
|
|
|
&cli.Int64Flag{
|
|
|
|
Name: "max-upload-size",
|
|
|
|
Usage: "max limit for upload, in kilobytes",
|
|
|
|
Value: 0,
|
|
|
|
EnvVars: []string{"MAX_UPLOAD_SIZE"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "lets-encrypt-hosts",
|
|
|
|
Usage: "host1, host2",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"HOSTS"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "log",
|
|
|
|
Usage: "/var/log/transfersh.log",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"LOG"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "basedir",
|
|
|
|
Usage: "path to storage",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"BASEDIR"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "clamav-host",
|
|
|
|
Usage: "clamav-host",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"CLAMAV_HOST"},
|
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "perform-clamav-prescan",
|
|
|
|
Usage: "perform-clamav-prescan",
|
|
|
|
EnvVars: []string{"PERFORM_CLAMAV_PRESCAN"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "virustotal-key",
|
|
|
|
Usage: "virustotal-key",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"VIRUSTOTAL_KEY"},
|
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "profiler",
|
|
|
|
Usage: "enable profiling",
|
|
|
|
EnvVars: []string{"PROFILER"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "http-auth-user",
|
|
|
|
Usage: "user for http basic auth",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"HTTP_AUTH_USER"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "http-auth-pass",
|
|
|
|
Usage: "pass for http basic auth",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"HTTP_AUTH_PASS"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "http-auth-htpasswd",
|
|
|
|
Usage: "htpasswd file http basic auth",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"HTTP_AUTH_HTPASSWD"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "http-auth-ip-whitelist",
|
|
|
|
Usage: "comma separated list of ips allowed to upload without being challenged an http auth",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"HTTP_AUTH_IP_WHITELIST"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "ip-whitelist",
|
|
|
|
Usage: "comma separated list of ips allowed to connect to the service",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"IP_WHITELIST"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "ip-blacklist",
|
|
|
|
Usage: "comma separated list of ips not allowed to connect to the service",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"IP_BLACKLIST"},
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "cors-domains",
|
|
|
|
Usage: "comma separated list of domains allowed for CORS requests",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"CORS_DOMAINS"},
|
|
|
|
},
|
|
|
|
&cli.IntFlag{
|
|
|
|
Name: "random-token-length",
|
|
|
|
Usage: "",
|
|
|
|
Value: 10,
|
|
|
|
EnvVars: []string{"RANDOM_TOKEN_LENGTH"},
|
2021-05-20 08:26:07 +02:00
|
|
|
},
|
2017-03-22 18:09:21 +01:00
|
|
|
}
|
|
|
|
|
2021-08-19 22:45:30 +02:00
|
|
|
// Cmd wraps cli.app
|
2017-03-22 18:09:21 +01:00
|
|
|
type Cmd struct {
|
|
|
|
*cli.App
|
|
|
|
}
|
|
|
|
|
2023-05-19 07:51:40 +02:00
|
|
|
func versionCommand(_ *cli.Context) error {
|
2022-07-13 06:26:42 +02:00
|
|
|
fmt.Println(color.YellowString("transfer.sh %s: Easy file sharing from the command line", Version))
|
2023-05-19 07:51:40 +02:00
|
|
|
return nil
|
2017-03-22 18:09:21 +01:00
|
|
|
}
|
|
|
|
|
2021-08-19 22:45:30 +02:00
|
|
|
// New is the factory for transfer.sh
|
2017-03-22 18:09:21 +01:00
|
|
|
func New() *Cmd {
|
2018-10-27 00:15:55 +02:00
|
|
|
logger := log.New(os.Stdout, "[transfer.sh]", log.LstdFlags)
|
|
|
|
|
2017-03-22 18:09:21 +01:00
|
|
|
app := cli.NewApp()
|
|
|
|
app.Name = "transfer.sh"
|
2023-05-19 07:51:40 +02:00
|
|
|
app.Authors = []*cli.Author{}
|
2017-03-22 18:09:21 +01:00
|
|
|
app.Usage = "transfer.sh"
|
|
|
|
app.Description = `Easy file sharing from the command line`
|
2019-07-06 20:42:33 +02:00
|
|
|
app.Version = Version
|
2017-03-22 18:09:21 +01:00
|
|
|
app.Flags = globalFlags
|
|
|
|
app.CustomAppHelpTemplate = helpTemplate
|
2023-05-19 07:51:40 +02:00
|
|
|
app.Commands = []*cli.Command{
|
2017-03-22 18:09:21 +01:00
|
|
|
{
|
|
|
|
Name: "version",
|
2022-07-13 06:26:42 +02:00
|
|
|
Action: versionCommand,
|
2017-03-22 18:09:21 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
app.Before = func(c *cli.Context) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-05-19 07:51:40 +02:00
|
|
|
app.Action = func(c *cli.Context) error {
|
2022-07-13 06:26:42 +02:00
|
|
|
var options []server.OptionFn
|
2017-03-22 18:09:21 +01:00
|
|
|
if v := c.String("listener"); v != "" {
|
|
|
|
options = append(options, server.Listener(v))
|
|
|
|
}
|
|
|
|
|
2020-04-04 14:29:33 +02:00
|
|
|
if v := c.String("cors-domains"); v != "" {
|
|
|
|
options = append(options, server.CorsDomains(v))
|
|
|
|
}
|
|
|
|
|
2018-07-07 19:05:16 +02:00
|
|
|
if v := c.String("tls-listener"); v == "" {
|
|
|
|
} else if c.Bool("tls-listener-only") {
|
|
|
|
options = append(options, server.TLSListener(v, true))
|
|
|
|
} else {
|
|
|
|
options = append(options, server.TLSListener(v, false))
|
2017-03-22 18:09:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if v := c.String("profile-listener"); v != "" {
|
|
|
|
options = append(options, server.ProfileListener(v))
|
|
|
|
}
|
|
|
|
|
|
|
|
if v := c.String("web-path"); v != "" {
|
|
|
|
options = append(options, server.WebPath(v))
|
|
|
|
}
|
|
|
|
|
2019-03-30 12:35:57 +01:00
|
|
|
if v := c.String("proxy-path"); v != "" {
|
|
|
|
options = append(options, server.ProxyPath(v))
|
|
|
|
}
|
|
|
|
|
2020-05-03 11:19:32 +02:00
|
|
|
if v := c.String("proxy-port"); v != "" {
|
|
|
|
options = append(options, server.ProxyPort(v))
|
|
|
|
}
|
|
|
|
|
2021-12-15 21:06:54 +01:00
|
|
|
if v := c.String("email-contact"); v != "" {
|
|
|
|
options = append(options, server.EmailContact(v))
|
|
|
|
}
|
|
|
|
|
2018-06-26 18:39:56 +02:00
|
|
|
if v := c.String("ga-key"); v != "" {
|
|
|
|
options = append(options, server.GoogleAnalytics(v))
|
|
|
|
}
|
|
|
|
|
|
|
|
if v := c.String("uservoice-key"); v != "" {
|
|
|
|
options = append(options, server.UserVoice(v))
|
|
|
|
}
|
|
|
|
|
2017-03-22 18:09:21 +01:00
|
|
|
if v := c.String("temp-path"); v != "" {
|
|
|
|
options = append(options, server.TempPath(v))
|
|
|
|
}
|
|
|
|
|
2018-10-27 00:15:55 +02:00
|
|
|
if v := c.String("log"); v != "" {
|
|
|
|
options = append(options, server.LogFile(logger, v))
|
|
|
|
} else {
|
|
|
|
options = append(options, server.Logger(logger))
|
|
|
|
}
|
|
|
|
|
2017-03-22 18:09:21 +01:00
|
|
|
if v := c.String("lets-encrypt-hosts"); v != "" {
|
|
|
|
options = append(options, server.UseLetsEncrypt(strings.Split(v, ",")))
|
|
|
|
}
|
|
|
|
|
2017-03-22 23:14:01 +01:00
|
|
|
if v := c.String("virustotal-key"); v != "" {
|
|
|
|
options = append(options, server.VirustotalKey(v))
|
|
|
|
}
|
|
|
|
|
2017-03-22 23:13:34 +01:00
|
|
|
if v := c.String("clamav-host"); v != "" {
|
|
|
|
options = append(options, server.ClamavHost(v))
|
|
|
|
}
|
|
|
|
|
2022-01-10 11:01:26 +01:00
|
|
|
if v := c.Bool("perform-clamav-prescan"); v {
|
2022-01-09 22:14:10 +01:00
|
|
|
if c.String("clamav-host") == "" {
|
2023-05-19 07:51:40 +02:00
|
|
|
return errors.New("clamav-host not set")
|
2022-01-09 22:14:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
options = append(options, server.PerformClamavPrescan(v))
|
|
|
|
}
|
|
|
|
|
2020-12-31 20:08:42 +01:00
|
|
|
if v := c.Int64("max-upload-size"); v > 0 {
|
|
|
|
options = append(options, server.MaxUploadSize(v))
|
|
|
|
}
|
|
|
|
|
2017-03-28 17:08:34 +02:00
|
|
|
if v := c.Int("rate-limit"); v > 0 {
|
|
|
|
options = append(options, server.RateLimit(v))
|
|
|
|
}
|
|
|
|
|
2021-07-08 07:48:32 +02:00
|
|
|
v := c.Int("random-token-length")
|
2021-05-20 08:26:07 +02:00
|
|
|
options = append(options, server.RandomTokenLength(v))
|
|
|
|
|
2021-01-05 17:23:47 +01:00
|
|
|
purgeDays := c.Int("purge-days")
|
|
|
|
purgeInterval := c.Int("purge-interval")
|
2021-01-05 17:24:16 +01:00
|
|
|
if purgeDays > 0 && purgeInterval > 0 {
|
2021-01-05 17:23:47 +01:00
|
|
|
options = append(options, server.Purge(purgeDays, purgeInterval))
|
|
|
|
}
|
|
|
|
|
2017-03-22 18:09:21 +01:00
|
|
|
if cert := c.String("tls-cert-file"); cert == "" {
|
|
|
|
} else if pk := c.String("tls-private-key"); pk == "" {
|
|
|
|
} else {
|
|
|
|
options = append(options, server.TLSConfig(cert, pk))
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.Bool("profiler") {
|
|
|
|
options = append(options, server.EnableProfiler())
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.Bool("force-https") {
|
2021-08-19 22:45:30 +02:00
|
|
|
options = append(options, server.ForceHTTPS())
|
2017-03-22 18:09:21 +01:00
|
|
|
}
|
|
|
|
|
2018-06-23 18:46:28 +02:00
|
|
|
if httpAuthUser := c.String("http-auth-user"); httpAuthUser == "" {
|
|
|
|
} else if httpAuthPass := c.String("http-auth-pass"); httpAuthPass == "" {
|
|
|
|
} else {
|
2021-08-19 22:45:30 +02:00
|
|
|
options = append(options, server.HTTPAuthCredentials(httpAuthUser, httpAuthPass))
|
2018-06-23 18:46:28 +02:00
|
|
|
}
|
|
|
|
|
2023-03-12 03:52:45 +01:00
|
|
|
if httpAuthHtpasswd := c.String("http-auth-htpasswd"); httpAuthHtpasswd != "" {
|
|
|
|
options = append(options, server.HTTPAuthHtpasswd(httpAuthHtpasswd))
|
|
|
|
}
|
|
|
|
|
2023-03-12 05:34:41 +01:00
|
|
|
if httpAuthIPWhitelist := c.String("http-auth-ip-whitelist"); httpAuthIPWhitelist != "" {
|
|
|
|
ipFilterOptions := server.IPFilterOptions{}
|
|
|
|
ipFilterOptions.AllowedIPs = strings.Split(httpAuthIPWhitelist, ",")
|
|
|
|
ipFilterOptions.BlockByDefault = false
|
|
|
|
options = append(options, server.HTTPAUTHFilterOptions(ipFilterOptions))
|
|
|
|
}
|
|
|
|
|
2019-05-11 14:42:59 +02:00
|
|
|
applyIPFilter := false
|
|
|
|
ipFilterOptions := server.IPFilterOptions{}
|
|
|
|
if ipWhitelist := c.String("ip-whitelist"); ipWhitelist != "" {
|
|
|
|
applyIPFilter = true
|
|
|
|
ipFilterOptions.AllowedIPs = strings.Split(ipWhitelist, ",")
|
|
|
|
ipFilterOptions.BlockByDefault = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if ipBlacklist := c.String("ip-blacklist"); ipBlacklist != "" {
|
|
|
|
applyIPFilter = true
|
|
|
|
ipFilterOptions.BlockedIPs = strings.Split(ipBlacklist, ",")
|
|
|
|
}
|
|
|
|
|
|
|
|
if applyIPFilter {
|
|
|
|
options = append(options, server.FilterOptions(ipFilterOptions))
|
|
|
|
}
|
|
|
|
|
2017-03-22 18:09:21 +01:00
|
|
|
switch provider := c.String("provider"); provider {
|
|
|
|
case "s3":
|
|
|
|
if accessKey := c.String("aws-access-key"); accessKey == "" {
|
2023-05-19 07:51:40 +02:00
|
|
|
return errors.New("access-key not set.")
|
2017-03-22 18:09:21 +01:00
|
|
|
} else if secretKey := c.String("aws-secret-key"); secretKey == "" {
|
2023-05-19 07:51:40 +02:00
|
|
|
return errors.New("secret-key not set.")
|
2017-03-22 18:09:21 +01:00
|
|
|
} else if bucket := c.String("bucket"); bucket == "" {
|
2023-05-19 07:51:40 +02:00
|
|
|
return errors.New("bucket not set.")
|
2023-05-24 11:37:06 +02:00
|
|
|
} else if store, err := storage.NewS3Storage(c.Context, accessKey, secretKey, bucket, purgeDays, c.String("s3-region"), c.String("s3-endpoint"), c.Bool("s3-no-multipart"), c.Bool("s3-path-style"), logger); err != nil {
|
2023-05-19 07:51:40 +02:00
|
|
|
return err
|
2017-03-22 18:09:21 +01:00
|
|
|
} else {
|
2022-07-13 06:26:42 +02:00
|
|
|
options = append(options, server.UseStorage(store))
|
2017-03-22 18:09:21 +01:00
|
|
|
}
|
2018-06-19 15:30:26 +02:00
|
|
|
case "gdrive":
|
2022-07-14 18:02:18 +02:00
|
|
|
chunkSize := c.Int("gdrive-chunk-size") * 1024 * 1024
|
2019-03-18 20:52:38 +01:00
|
|
|
|
2021-08-19 22:45:30 +02:00
|
|
|
if clientJSONFilepath := c.String("gdrive-client-json-filepath"); clientJSONFilepath == "" {
|
2023-05-19 07:51:40 +02:00
|
|
|
return errors.New("gdrive-client-json-filepath not set.")
|
2018-06-19 15:30:26 +02:00
|
|
|
} else if localConfigPath := c.String("gdrive-local-config-path"); localConfigPath == "" {
|
2023-05-19 07:51:40 +02:00
|
|
|
return errors.New("gdrive-local-config-path not set.")
|
2018-06-19 15:30:26 +02:00
|
|
|
} else if basedir := c.String("basedir"); basedir == "" {
|
2023-05-19 07:51:40 +02:00
|
|
|
return errors.New("basedir not set.")
|
|
|
|
} else if store, err := storage.NewGDriveStorage(c.Context, clientJSONFilepath, localConfigPath, basedir, chunkSize, logger); err != nil {
|
|
|
|
return err
|
2018-06-19 15:30:26 +02:00
|
|
|
} else {
|
2022-07-13 06:26:42 +02:00
|
|
|
options = append(options, server.UseStorage(store))
|
2018-06-19 15:30:26 +02:00
|
|
|
}
|
2019-08-28 15:29:35 +02:00
|
|
|
case "storj":
|
2020-02-21 23:10:33 +01:00
|
|
|
if access := c.String("storj-access"); access == "" {
|
2023-05-19 07:51:40 +02:00
|
|
|
return errors.New("storj-access not set.")
|
2019-08-28 15:29:35 +02:00
|
|
|
} else if bucket := c.String("storj-bucket"); bucket == "" {
|
2023-05-19 07:51:40 +02:00
|
|
|
return errors.New("storj-bucket not set.")
|
|
|
|
} else if store, err := storage.NewStorjStorage(c.Context, access, bucket, purgeDays, logger); err != nil {
|
|
|
|
return err
|
2019-08-28 15:29:35 +02:00
|
|
|
} else {
|
2022-07-13 06:26:42 +02:00
|
|
|
options = append(options, server.UseStorage(store))
|
2019-08-28 15:29:35 +02:00
|
|
|
}
|
2017-03-22 18:09:21 +01:00
|
|
|
case "local":
|
|
|
|
if v := c.String("basedir"); v == "" {
|
2023-05-19 07:51:40 +02:00
|
|
|
return errors.New("basedir not set.")
|
2022-07-13 06:26:42 +02:00
|
|
|
} else if store, err := storage.NewLocalStorage(v, logger); err != nil {
|
2023-05-19 07:51:40 +02:00
|
|
|
return err
|
2017-03-22 18:09:21 +01:00
|
|
|
} else {
|
2022-07-13 06:26:42 +02:00
|
|
|
options = append(options, server.UseStorage(store))
|
2017-03-22 18:09:21 +01:00
|
|
|
}
|
|
|
|
default:
|
2023-05-19 07:51:40 +02:00
|
|
|
return errors.New("Provider not set or invalid.")
|
2017-03-22 18:09:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
srvr, err := server.New(
|
|
|
|
options...,
|
|
|
|
)
|
|
|
|
|
|
|
|
if err != nil {
|
2018-10-27 00:15:55 +02:00
|
|
|
logger.Println(color.RedString("Error starting server: %s", err.Error()))
|
2023-05-19 07:51:40 +02:00
|
|
|
return err
|
2017-03-22 18:09:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
srvr.Run()
|
2023-05-19 07:51:40 +02:00
|
|
|
return nil
|
2017-03-22 18:09:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return &Cmd{
|
|
|
|
App: app,
|
|
|
|
}
|
|
|
|
}
|