2020-05-23 09:58:05 +00:00
|
|
|
// +build !noportable
|
|
|
|
|
2019-10-24 16:50:35 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2020-01-31 18:04:00 +00:00
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2020-03-05 14:37:10 +00:00
|
|
|
"path"
|
2019-10-24 16:50:35 +00:00
|
|
|
"path/filepath"
|
2020-03-05 14:37:10 +00:00
|
|
|
"strings"
|
2019-10-24 16:50:35 +00:00
|
|
|
|
2020-05-06 17:36:34 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
2020-07-29 19:56:56 +00:00
|
|
|
"github.com/drakkan/sftpgo/common"
|
2019-10-24 16:50:35 +00:00
|
|
|
"github.com/drakkan/sftpgo/dataprovider"
|
|
|
|
"github.com/drakkan/sftpgo/service"
|
2019-11-18 22:30:37 +00:00
|
|
|
"github.com/drakkan/sftpgo/sftpd"
|
2020-06-19 15:08:51 +00:00
|
|
|
"github.com/drakkan/sftpgo/version"
|
2020-01-19 06:41:05 +00:00
|
|
|
"github.com/drakkan/sftpgo/vfs"
|
2019-10-24 16:50:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2019-10-26 16:25:53 +00:00
|
|
|
directoryToServe string
|
|
|
|
portableSFTPDPort int
|
|
|
|
portableAdvertiseService bool
|
|
|
|
portableAdvertiseCredentials bool
|
|
|
|
portableUsername string
|
|
|
|
portablePassword string
|
|
|
|
portableLogFile string
|
2020-04-28 13:02:48 +00:00
|
|
|
portableLogVerbose bool
|
2019-10-26 16:25:53 +00:00
|
|
|
portablePublicKeys []string
|
|
|
|
portablePermissions []string
|
2019-11-18 22:30:37 +00:00
|
|
|
portableSSHCommands []string
|
2020-03-05 14:37:10 +00:00
|
|
|
portableAllowedExtensions []string
|
|
|
|
portableDeniedExtensions []string
|
2020-01-19 06:41:05 +00:00
|
|
|
portableFsProvider int
|
|
|
|
portableS3Bucket string
|
|
|
|
portableS3Region string
|
|
|
|
portableS3AccessKey string
|
|
|
|
portableS3AccessSecret string
|
|
|
|
portableS3Endpoint string
|
|
|
|
portableS3StorageClass string
|
2020-01-19 22:23:09 +00:00
|
|
|
portableS3KeyPrefix string
|
2020-03-15 10:40:06 +00:00
|
|
|
portableS3ULPartSize int
|
|
|
|
portableS3ULConcurrency int
|
2020-01-31 18:04:00 +00:00
|
|
|
portableGCSBucket string
|
|
|
|
portableGCSCredentialsFile string
|
2020-02-19 08:41:15 +00:00
|
|
|
portableGCSAutoCredentials int
|
2020-01-31 18:04:00 +00:00
|
|
|
portableGCSStorageClass string
|
|
|
|
portableGCSKeyPrefix string
|
2020-07-29 19:56:56 +00:00
|
|
|
portableFTPDPort int
|
|
|
|
portableFTPSCert string
|
|
|
|
portableFTPSKey string
|
2020-08-17 12:08:08 +00:00
|
|
|
portableWebDAVPort int
|
|
|
|
portableWebDAVCert string
|
|
|
|
portableWebDAVKey string
|
2020-10-25 20:42:43 +00:00
|
|
|
portableAzContainer string
|
|
|
|
portableAzAccountName string
|
|
|
|
portableAzAccountKey string
|
|
|
|
portableAzEndpoint string
|
2020-10-30 21:17:17 +00:00
|
|
|
portableAzAccessTier string
|
2020-10-25 20:42:43 +00:00
|
|
|
portableAzSASURL string
|
|
|
|
portableAzKeyPrefix string
|
|
|
|
portableAzULPartSize int
|
|
|
|
portableAzULConcurrency int
|
|
|
|
portableAzUseEmulator bool
|
2019-10-26 16:25:53 +00:00
|
|
|
portableCmd = &cobra.Command{
|
2019-10-24 16:50:35 +00:00
|
|
|
Use: "portable",
|
|
|
|
Short: "Serve a single directory",
|
2020-07-09 16:58:22 +00:00
|
|
|
Long: `To serve the current working directory with auto generated credentials simply
|
|
|
|
use:
|
2019-10-24 16:50:35 +00:00
|
|
|
|
2020-07-09 16:58:22 +00:00
|
|
|
$ sftpgo portable
|
2019-10-24 16:50:35 +00:00
|
|
|
|
|
|
|
Please take a look at the usage below to customize the serving parameters`,
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
portableDir := directoryToServe
|
2020-10-05 18:58:41 +00:00
|
|
|
fsProvider := dataprovider.FilesystemProvider(portableFsProvider)
|
2019-10-24 16:50:35 +00:00
|
|
|
if !filepath.IsAbs(portableDir) {
|
2020-10-05 18:58:41 +00:00
|
|
|
if fsProvider == dataprovider.LocalFilesystemProvider {
|
2020-02-19 08:41:15 +00:00
|
|
|
portableDir, _ = filepath.Abs(portableDir)
|
|
|
|
} else {
|
|
|
|
portableDir = os.TempDir()
|
|
|
|
}
|
2019-10-24 16:50:35 +00:00
|
|
|
}
|
2019-12-25 17:20:19 +00:00
|
|
|
permissions := make(map[string][]string)
|
|
|
|
permissions["/"] = portablePermissions
|
2020-10-22 08:42:40 +00:00
|
|
|
var portableGCSCredentials []byte
|
2020-10-05 18:58:41 +00:00
|
|
|
if fsProvider == dataprovider.GCSFilesystemProvider && len(portableGCSCredentialsFile) > 0 {
|
2020-01-31 18:04:00 +00:00
|
|
|
fi, err := os.Stat(portableGCSCredentialsFile)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Invalid GCS credentials file: %v\n", err)
|
2020-06-20 12:30:46 +00:00
|
|
|
os.Exit(1)
|
2020-01-31 18:04:00 +00:00
|
|
|
}
|
|
|
|
if fi.Size() > 1048576 {
|
|
|
|
fmt.Printf("Invalid GCS credentials file: %#v is too big %v/1048576 bytes\n", portableGCSCredentialsFile,
|
|
|
|
fi.Size())
|
2020-06-20 12:30:46 +00:00
|
|
|
os.Exit(1)
|
2020-01-31 18:04:00 +00:00
|
|
|
}
|
|
|
|
creds, err := ioutil.ReadFile(portableGCSCredentialsFile)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Unable to read credentials file: %v\n", err)
|
|
|
|
}
|
2020-10-22 08:42:40 +00:00
|
|
|
portableGCSCredentials = creds
|
2020-02-19 08:41:15 +00:00
|
|
|
portableGCSAutoCredentials = 0
|
2020-01-31 18:04:00 +00:00
|
|
|
}
|
2020-07-29 19:56:56 +00:00
|
|
|
if portableFTPDPort >= 0 && len(portableFTPSCert) > 0 && len(portableFTPSKey) > 0 {
|
|
|
|
_, err := common.NewCertManager(portableFTPSCert, portableFTPSKey, "FTP portable")
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Unable to load FTPS key pair, cert file %#v key file %#v error: %v\n",
|
|
|
|
portableFTPSCert, portableFTPSKey, err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
2020-08-17 12:08:08 +00:00
|
|
|
if portableWebDAVPort > 0 && len(portableWebDAVCert) > 0 && len(portableWebDAVKey) > 0 {
|
|
|
|
_, err := common.NewCertManager(portableWebDAVCert, portableWebDAVKey, "WebDAV portable")
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Unable to load WebDAV key pair, cert file %#v key file %#v error: %v\n",
|
|
|
|
portableWebDAVCert, portableWebDAVKey, err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
2019-10-24 16:50:35 +00:00
|
|
|
service := service.Service{
|
2020-03-02 21:56:14 +00:00
|
|
|
ConfigDir: filepath.Clean(defaultConfigDir),
|
2019-10-24 16:50:35 +00:00
|
|
|
ConfigFile: defaultConfigName,
|
2019-10-26 16:25:53 +00:00
|
|
|
LogFilePath: portableLogFile,
|
2019-10-24 16:50:35 +00:00
|
|
|
LogMaxSize: defaultLogMaxSize,
|
|
|
|
LogMaxBackups: defaultLogMaxBackup,
|
|
|
|
LogMaxAge: defaultLogMaxAge,
|
|
|
|
LogCompress: defaultLogCompress,
|
2020-04-28 13:02:48 +00:00
|
|
|
LogVerbose: portableLogVerbose,
|
2020-03-15 14:16:35 +00:00
|
|
|
Profiler: defaultProfiler,
|
2019-10-24 16:50:35 +00:00
|
|
|
Shutdown: make(chan bool),
|
|
|
|
PortableMode: 1,
|
|
|
|
PortableUser: dataprovider.User{
|
|
|
|
Username: portableUsername,
|
|
|
|
Password: portablePassword,
|
|
|
|
PublicKeys: portablePublicKeys,
|
2019-12-25 17:20:19 +00:00
|
|
|
Permissions: permissions,
|
2019-10-24 16:50:35 +00:00
|
|
|
HomeDir: portableDir,
|
2019-11-13 10:36:21 +00:00
|
|
|
Status: 1,
|
2020-01-19 06:41:05 +00:00
|
|
|
FsConfig: dataprovider.Filesystem{
|
2020-10-05 18:58:41 +00:00
|
|
|
Provider: dataprovider.FilesystemProvider(portableFsProvider),
|
2020-01-19 06:41:05 +00:00
|
|
|
S3Config: vfs.S3FsConfig{
|
2020-03-15 10:40:06 +00:00
|
|
|
Bucket: portableS3Bucket,
|
|
|
|
Region: portableS3Region,
|
|
|
|
AccessKey: portableS3AccessKey,
|
|
|
|
AccessSecret: portableS3AccessSecret,
|
|
|
|
Endpoint: portableS3Endpoint,
|
|
|
|
StorageClass: portableS3StorageClass,
|
|
|
|
KeyPrefix: portableS3KeyPrefix,
|
|
|
|
UploadPartSize: int64(portableS3ULPartSize),
|
|
|
|
UploadConcurrency: portableS3ULConcurrency,
|
2020-01-19 06:41:05 +00:00
|
|
|
},
|
2020-01-31 18:04:00 +00:00
|
|
|
GCSConfig: vfs.GCSFsConfig{
|
2020-02-19 08:41:15 +00:00
|
|
|
Bucket: portableGCSBucket,
|
|
|
|
Credentials: portableGCSCredentials,
|
|
|
|
AutomaticCredentials: portableGCSAutoCredentials,
|
|
|
|
StorageClass: portableGCSStorageClass,
|
|
|
|
KeyPrefix: portableGCSKeyPrefix,
|
2020-01-31 18:04:00 +00:00
|
|
|
},
|
2020-10-25 20:42:43 +00:00
|
|
|
AzBlobConfig: vfs.AzBlobFsConfig{
|
|
|
|
Container: portableAzContainer,
|
|
|
|
AccountName: portableAzAccountName,
|
|
|
|
AccountKey: portableAzAccountKey,
|
|
|
|
Endpoint: portableAzEndpoint,
|
2020-10-30 21:17:17 +00:00
|
|
|
AccessTier: portableAzAccessTier,
|
2020-10-25 20:42:43 +00:00
|
|
|
SASURL: portableAzSASURL,
|
|
|
|
KeyPrefix: portableAzKeyPrefix,
|
|
|
|
UseEmulator: portableAzUseEmulator,
|
|
|
|
UploadPartSize: int64(portableAzULPartSize),
|
|
|
|
UploadConcurrency: portableAzULConcurrency,
|
|
|
|
},
|
2020-01-19 06:41:05 +00:00
|
|
|
},
|
2020-03-05 14:37:10 +00:00
|
|
|
Filters: dataprovider.UserFilters{
|
|
|
|
FileExtensions: parseFileExtensionsFilters(),
|
|
|
|
},
|
2019-10-24 16:50:35 +00:00
|
|
|
},
|
|
|
|
}
|
2020-08-17 12:08:08 +00:00
|
|
|
if err := service.StartPortableMode(portableSFTPDPort, portableFTPDPort, portableWebDAVPort, portableSSHCommands, portableAdvertiseService,
|
|
|
|
portableAdvertiseCredentials, portableFTPSCert, portableFTPSKey, portableWebDAVCert, portableWebDAVKey); err == nil {
|
2019-10-24 16:50:35 +00:00
|
|
|
service.Wait()
|
2020-07-29 19:56:56 +00:00
|
|
|
if service.Error == nil {
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
2019-10-24 16:50:35 +00:00
|
|
|
}
|
2020-06-20 12:30:46 +00:00
|
|
|
os.Exit(1)
|
2019-10-24 16:50:35 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2020-06-19 15:08:51 +00:00
|
|
|
version.AddFeature("+portable")
|
2020-05-23 09:58:05 +00:00
|
|
|
|
2020-07-09 16:58:22 +00:00
|
|
|
portableCmd.Flags().StringVarP(&directoryToServe, "directory", "d", ".", `Path to the directory to serve.
|
|
|
|
This can be an absolute path or a path
|
|
|
|
relative to the current directory
|
|
|
|
`)
|
2020-07-29 19:56:56 +00:00
|
|
|
portableCmd.Flags().IntVarP(&portableSFTPDPort, "sftpd-port", "s", 0, "0 means a random unprivileged port")
|
|
|
|
portableCmd.Flags().IntVar(&portableFTPDPort, "ftpd-port", -1, `0 means a random unprivileged port,
|
2020-08-17 12:08:08 +00:00
|
|
|
< 0 disabled`)
|
|
|
|
portableCmd.Flags().IntVar(&portableWebDAVPort, "webdav-port", -1, `0 means a random unprivileged port,
|
2020-07-29 19:56:56 +00:00
|
|
|
< 0 disabled`)
|
2019-11-18 22:30:37 +00:00
|
|
|
portableCmd.Flags().StringSliceVarP(&portableSSHCommands, "ssh-commands", "c", sftpd.GetDefaultSSHCommands(),
|
2020-07-09 16:58:22 +00:00
|
|
|
`SSH commands to enable.
|
|
|
|
"*" means any supported SSH command
|
|
|
|
including scp
|
|
|
|
`)
|
|
|
|
portableCmd.Flags().StringVarP(&portableUsername, "username", "u", "", `Leave empty to use an auto generated
|
|
|
|
value`)
|
|
|
|
portableCmd.Flags().StringVarP(&portablePassword, "password", "p", "", `Leave empty to use an auto generated
|
|
|
|
value`)
|
2019-10-26 16:25:53 +00:00
|
|
|
portableCmd.Flags().StringVarP(&portableLogFile, logFilePathFlag, "l", "", "Leave empty to disable logging")
|
2020-04-28 13:02:48 +00:00
|
|
|
portableCmd.Flags().BoolVarP(&portableLogVerbose, logVerboseFlag, "v", false, "Enable verbose logs")
|
2019-10-24 16:50:35 +00:00
|
|
|
portableCmd.Flags().StringSliceVarP(&portablePublicKeys, "public-key", "k", []string{}, "")
|
|
|
|
portableCmd.Flags().StringSliceVarP(&portablePermissions, "permissions", "g", []string{"list", "download"},
|
2020-07-09 16:58:22 +00:00
|
|
|
`User's permissions. "*" means any
|
|
|
|
permission`)
|
2020-03-05 14:37:10 +00:00
|
|
|
portableCmd.Flags().StringArrayVar(&portableAllowedExtensions, "allowed-extensions", []string{},
|
2020-07-09 16:58:22 +00:00
|
|
|
`Allowed file extensions case
|
|
|
|
insensitive. The format is
|
|
|
|
/dir::ext1,ext2.
|
|
|
|
For example: "/somedir::.jpg,.png"`)
|
2020-03-05 14:37:10 +00:00
|
|
|
portableCmd.Flags().StringArrayVar(&portableDeniedExtensions, "denied-extensions", []string{},
|
2020-07-09 16:58:22 +00:00
|
|
|
`Denied file extensions case
|
|
|
|
insensitive. The format is
|
|
|
|
/dir::ext1,ext2.
|
|
|
|
For example: "/somedir::.jpg,.png"`)
|
2020-06-24 11:37:38 +00:00
|
|
|
portableCmd.Flags().BoolVarP(&portableAdvertiseService, "advertise-service", "S", false,
|
2020-07-29 19:56:56 +00:00
|
|
|
`Advertise SFTP/FTP service using
|
|
|
|
multicast DNS`)
|
2019-10-26 16:25:53 +00:00
|
|
|
portableCmd.Flags().BoolVarP(&portableAdvertiseCredentials, "advertise-credentials", "C", false,
|
2020-07-29 19:56:56 +00:00
|
|
|
`If the SFTP/FTP service is
|
|
|
|
advertised via multicast DNS, this
|
|
|
|
flag allows to put username/password
|
|
|
|
inside the advertised TXT record`)
|
2020-10-25 20:42:43 +00:00
|
|
|
portableCmd.Flags().IntVarP(&portableFsProvider, "fs-provider", "f", int(dataprovider.LocalFilesystemProvider), `0 => local filesystem
|
2020-10-26 18:01:17 +00:00
|
|
|
1 => AWS S3 compatible
|
2020-10-25 20:42:43 +00:00
|
|
|
2 => Google Cloud Storage
|
|
|
|
3 => Azure Blob Storage`)
|
2020-01-19 06:41:05 +00:00
|
|
|
portableCmd.Flags().StringVar(&portableS3Bucket, "s3-bucket", "", "")
|
|
|
|
portableCmd.Flags().StringVar(&portableS3Region, "s3-region", "", "")
|
|
|
|
portableCmd.Flags().StringVar(&portableS3AccessKey, "s3-access-key", "", "")
|
|
|
|
portableCmd.Flags().StringVar(&portableS3AccessSecret, "s3-access-secret", "", "")
|
|
|
|
portableCmd.Flags().StringVar(&portableS3Endpoint, "s3-endpoint", "", "")
|
|
|
|
portableCmd.Flags().StringVar(&portableS3StorageClass, "s3-storage-class", "", "")
|
2020-07-09 16:58:22 +00:00
|
|
|
portableCmd.Flags().StringVar(&portableS3KeyPrefix, "s3-key-prefix", "", `Allows to restrict access to the
|
|
|
|
virtual folder identified by this
|
|
|
|
prefix and its contents`)
|
|
|
|
portableCmd.Flags().IntVar(&portableS3ULPartSize, "s3-upload-part-size", 5, `The buffer size for multipart uploads
|
|
|
|
(MB)`)
|
|
|
|
portableCmd.Flags().IntVar(&portableS3ULConcurrency, "s3-upload-concurrency", 2, `How many parts are uploaded in
|
|
|
|
parallel`)
|
2020-01-31 18:04:00 +00:00
|
|
|
portableCmd.Flags().StringVar(&portableGCSBucket, "gcs-bucket", "", "")
|
|
|
|
portableCmd.Flags().StringVar(&portableGCSStorageClass, "gcs-storage-class", "", "")
|
2020-07-09 16:58:22 +00:00
|
|
|
portableCmd.Flags().StringVar(&portableGCSKeyPrefix, "gcs-key-prefix", "", `Allows to restrict access to the
|
|
|
|
virtual folder identified by this
|
|
|
|
prefix and its contents`)
|
|
|
|
portableCmd.Flags().StringVar(&portableGCSCredentialsFile, "gcs-credentials-file", "", `Google Cloud Storage JSON credentials
|
|
|
|
file`)
|
|
|
|
portableCmd.Flags().IntVar(&portableGCSAutoCredentials, "gcs-automatic-credentials", 1, `0 means explicit credentials using
|
|
|
|
a JSON credentials file, 1 automatic
|
|
|
|
`)
|
2020-07-29 19:56:56 +00:00
|
|
|
portableCmd.Flags().StringVar(&portableFTPSCert, "ftpd-cert", "", "Path to the certificate file for FTPS")
|
|
|
|
portableCmd.Flags().StringVar(&portableFTPSKey, "ftpd-key", "", "Path to the key file for FTPS")
|
2020-08-17 12:08:08 +00:00
|
|
|
portableCmd.Flags().StringVar(&portableWebDAVCert, "webdav-cert", "", `Path to the certificate file for WebDAV
|
|
|
|
over HTTPS`)
|
|
|
|
portableCmd.Flags().StringVar(&portableWebDAVKey, "webdav-key", "", `Path to the key file for WebDAV over
|
|
|
|
HTTPS`)
|
2020-10-25 20:42:43 +00:00
|
|
|
portableCmd.Flags().StringVar(&portableAzContainer, "az-container", "", "")
|
|
|
|
portableCmd.Flags().StringVar(&portableAzAccountName, "az-account-name", "", "")
|
|
|
|
portableCmd.Flags().StringVar(&portableAzAccountKey, "az-account-key", "", "")
|
|
|
|
portableCmd.Flags().StringVar(&portableAzSASURL, "az-sas-url", "", `Shared access signature URL`)
|
|
|
|
portableCmd.Flags().StringVar(&portableAzEndpoint, "az-endpoint", "", `Leave empty to use the default:
|
|
|
|
"blob.core.windows.net"`)
|
2020-10-30 21:17:17 +00:00
|
|
|
portableCmd.Flags().StringVar(&portableAzAccessTier, "az-access-tier", "", `Leave empty to use the default
|
|
|
|
container setting`)
|
2020-10-25 20:42:43 +00:00
|
|
|
portableCmd.Flags().StringVar(&portableAzKeyPrefix, "az-key-prefix", "", `Allows to restrict access to the
|
|
|
|
virtual folder identified by this
|
|
|
|
prefix and its contents`)
|
|
|
|
portableCmd.Flags().IntVar(&portableAzULPartSize, "az-upload-part-size", 4, `The buffer size for multipart uploads
|
|
|
|
(MB)`)
|
|
|
|
portableCmd.Flags().IntVar(&portableAzULConcurrency, "az-upload-concurrency", 2, `How many parts are uploaded in
|
|
|
|
parallel`)
|
|
|
|
portableCmd.Flags().BoolVar(&portableAzUseEmulator, "az-use-emulator", false, "")
|
2019-10-24 16:50:35 +00:00
|
|
|
rootCmd.AddCommand(portableCmd)
|
|
|
|
}
|
2020-03-05 14:37:10 +00:00
|
|
|
|
|
|
|
func parseFileExtensionsFilters() []dataprovider.ExtensionsFilter {
|
|
|
|
var extensions []dataprovider.ExtensionsFilter
|
|
|
|
for _, val := range portableAllowedExtensions {
|
|
|
|
p, exts := getExtensionsFilterValues(strings.TrimSpace(val))
|
|
|
|
if len(p) > 0 {
|
|
|
|
extensions = append(extensions, dataprovider.ExtensionsFilter{
|
|
|
|
Path: path.Clean(p),
|
|
|
|
AllowedExtensions: exts,
|
|
|
|
DeniedExtensions: []string{},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, val := range portableDeniedExtensions {
|
|
|
|
p, exts := getExtensionsFilterValues(strings.TrimSpace(val))
|
|
|
|
if len(p) > 0 {
|
|
|
|
found := false
|
|
|
|
for index, e := range extensions {
|
|
|
|
if path.Clean(e.Path) == path.Clean(p) {
|
|
|
|
extensions[index].DeniedExtensions = append(extensions[index].DeniedExtensions, exts...)
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !found {
|
|
|
|
extensions = append(extensions, dataprovider.ExtensionsFilter{
|
|
|
|
Path: path.Clean(p),
|
|
|
|
AllowedExtensions: []string{},
|
|
|
|
DeniedExtensions: exts,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return extensions
|
|
|
|
}
|
|
|
|
|
|
|
|
func getExtensionsFilterValues(value string) (string, []string) {
|
|
|
|
if strings.Contains(value, "::") {
|
|
|
|
dirExts := strings.Split(value, "::")
|
|
|
|
if len(dirExts) > 1 {
|
|
|
|
dir := strings.TrimSpace(dirExts[0])
|
|
|
|
exts := []string{}
|
|
|
|
for _, e := range strings.Split(dirExts[1], ",") {
|
|
|
|
cleanedExt := strings.TrimSpace(e)
|
|
|
|
if len(cleanedExt) > 0 {
|
|
|
|
exts = append(exts, cleanedExt)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(dir) > 0 && len(exts) > 0 {
|
|
|
|
return dir, exts
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "", nil
|
|
|
|
}
|