2020-07-24 21:39:38 +00:00
|
|
|
// Package config manages the configuration
|
2019-07-20 10:26:52 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2019-08-04 07:37:58 +00:00
|
|
|
"fmt"
|
2019-07-29 06:53:22 +00:00
|
|
|
"strings"
|
2019-07-20 10:26:52 +00:00
|
|
|
|
2020-05-06 17:36:34 +00:00
|
|
|
"github.com/spf13/viper"
|
|
|
|
|
2020-07-24 21:39:38 +00:00
|
|
|
"github.com/drakkan/sftpgo/common"
|
2019-07-20 10:26:52 +00:00
|
|
|
"github.com/drakkan/sftpgo/dataprovider"
|
2020-07-29 19:56:56 +00:00
|
|
|
"github.com/drakkan/sftpgo/ftpd"
|
2020-04-26 21:29:09 +00:00
|
|
|
"github.com/drakkan/sftpgo/httpclient"
|
2019-10-07 16:19:01 +00:00
|
|
|
"github.com/drakkan/sftpgo/httpd"
|
2019-07-20 10:26:52 +00:00
|
|
|
"github.com/drakkan/sftpgo/logger"
|
|
|
|
"github.com/drakkan/sftpgo/sftpd"
|
2019-09-12 07:21:58 +00:00
|
|
|
"github.com/drakkan/sftpgo/utils"
|
2020-06-19 15:08:51 +00:00
|
|
|
"github.com/drakkan/sftpgo/version"
|
2020-08-11 21:56:10 +00:00
|
|
|
"github.com/drakkan/sftpgo/webdavd"
|
2019-07-20 10:26:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2019-09-12 07:21:58 +00:00
|
|
|
logSender = "config"
|
2019-08-07 20:46:13 +00:00
|
|
|
// DefaultConfigName defines the name for the default config file.
|
|
|
|
// This is the file name without extension, we use viper and so we
|
|
|
|
// support all the config files format supported by viper
|
|
|
|
DefaultConfigName = "sftpgo"
|
|
|
|
// ConfigEnvPrefix defines a prefix that ENVIRONMENT variables will use
|
|
|
|
configEnvPrefix = "sftpgo"
|
2019-07-20 10:26:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-07-29 19:56:56 +00:00
|
|
|
globalConf globalConfig
|
|
|
|
defaultSFTPDBanner = fmt.Sprintf("SFTPGo_%v", version.Get().Version)
|
|
|
|
defaultFTPDBanner = fmt.Sprintf("SFTPGo %v ready", version.Get().Version)
|
2019-07-20 10:26:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type globalConfig struct {
|
2020-08-11 21:56:10 +00:00
|
|
|
Common common.Configuration `json:"common" mapstructure:"common"`
|
|
|
|
SFTPD sftpd.Configuration `json:"sftpd" mapstructure:"sftpd"`
|
|
|
|
FTPD ftpd.Configuration `json:"ftpd" mapstructure:"ftpd"`
|
|
|
|
WebDAVD webdavd.Configuration `json:"webdavd" mapstructure:"webdavd"`
|
|
|
|
ProviderConf dataprovider.Config `json:"data_provider" mapstructure:"data_provider"`
|
|
|
|
HTTPDConfig httpd.Conf `json:"httpd" mapstructure:"httpd"`
|
|
|
|
HTTPConfig httpclient.Config `json:"http" mapstructure:"http"`
|
2019-07-20 10:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
// create a default configuration to use if no config file is provided
|
|
|
|
globalConf = globalConfig{
|
2020-07-24 21:39:38 +00:00
|
|
|
Common: common.Configuration{
|
|
|
|
IdleTimeout: 15,
|
|
|
|
UploadMode: 0,
|
|
|
|
Actions: common.ProtocolActions{
|
2020-05-24 13:29:39 +00:00
|
|
|
ExecuteOn: []string{},
|
|
|
|
Hook: "",
|
2019-07-27 07:38:09 +00:00
|
|
|
},
|
2020-07-24 21:39:38 +00:00
|
|
|
SetstatMode: 0,
|
|
|
|
ProxyProtocol: 0,
|
|
|
|
ProxyAllowed: []string{},
|
|
|
|
},
|
|
|
|
SFTPD: sftpd.Configuration{
|
2020-07-29 19:56:56 +00:00
|
|
|
Banner: defaultSFTPDBanner,
|
2020-07-24 21:39:38 +00:00
|
|
|
BindPort: 2022,
|
|
|
|
BindAddress: "",
|
|
|
|
MaxAuthTries: 0,
|
2020-05-16 21:26:44 +00:00
|
|
|
HostKeys: []string{},
|
2020-04-01 21:25:23 +00:00
|
|
|
KexAlgorithms: []string{},
|
|
|
|
Ciphers: []string{},
|
|
|
|
MACs: []string{},
|
2020-05-15 18:08:53 +00:00
|
|
|
TrustedUserCAKeys: []string{},
|
2020-04-01 21:25:23 +00:00
|
|
|
LoginBannerFile: "",
|
|
|
|
EnabledSSHCommands: sftpd.GetDefaultSSHCommands(),
|
|
|
|
KeyboardInteractiveHook: "",
|
2020-09-01 17:34:40 +00:00
|
|
|
PasswordAuthentication: true,
|
2019-07-20 10:26:52 +00:00
|
|
|
},
|
2020-07-29 19:56:56 +00:00
|
|
|
FTPD: ftpd.Configuration{
|
|
|
|
BindPort: 0,
|
|
|
|
BindAddress: "",
|
|
|
|
Banner: defaultFTPDBanner,
|
|
|
|
BannerFile: "",
|
|
|
|
ActiveTransfersPortNon20: false,
|
|
|
|
ForcePassiveIP: "",
|
|
|
|
PassivePortRange: ftpd.PortRange{
|
|
|
|
Start: 50000,
|
|
|
|
End: 50100,
|
|
|
|
},
|
|
|
|
CertificateFile: "",
|
|
|
|
CertificateKeyFile: "",
|
|
|
|
},
|
2020-08-11 21:56:10 +00:00
|
|
|
WebDAVD: webdavd.Configuration{
|
|
|
|
BindPort: 0,
|
|
|
|
BindAddress: "",
|
|
|
|
CertificateFile: "",
|
|
|
|
CertificateKeyFile: "",
|
2020-08-15 13:55:20 +00:00
|
|
|
Cors: webdavd.Cors{
|
|
|
|
Enabled: false,
|
|
|
|
AllowedOrigins: []string{},
|
|
|
|
AllowedMethods: []string{},
|
|
|
|
AllowedHeaders: []string{},
|
|
|
|
ExposedHeaders: []string{},
|
|
|
|
AllowCredentials: false,
|
|
|
|
MaxAge: 0,
|
|
|
|
},
|
2020-08-31 17:25:17 +00:00
|
|
|
Cache: webdavd.Cache{
|
2020-11-04 18:11:40 +00:00
|
|
|
Users: webdavd.UsersCacheConfig{
|
|
|
|
ExpirationTime: 0,
|
|
|
|
MaxSize: 50,
|
|
|
|
},
|
|
|
|
MimeTypes: webdavd.MimeCacheConfig{
|
|
|
|
Enabled: true,
|
|
|
|
MaxSize: 1000,
|
|
|
|
},
|
2020-08-31 17:25:17 +00:00
|
|
|
},
|
2020-08-11 21:56:10 +00:00
|
|
|
},
|
2019-07-20 10:26:52 +00:00
|
|
|
ProviderConf: dataprovider.Config{
|
|
|
|
Driver: "sqlite",
|
|
|
|
Name: "sftpgo.db",
|
|
|
|
Host: "",
|
|
|
|
Port: 5432,
|
|
|
|
Username: "",
|
|
|
|
Password: "",
|
|
|
|
ConnectionString: "",
|
2020-06-07 21:30:18 +00:00
|
|
|
SQLTablesPrefix: "",
|
2019-07-20 10:26:52 +00:00
|
|
|
ManageUsers: 1,
|
|
|
|
SSLMode: 0,
|
|
|
|
TrackQuota: 1,
|
2019-09-13 06:14:07 +00:00
|
|
|
PoolSize: 0,
|
2019-09-28 20:48:52 +00:00
|
|
|
UsersBaseDir: "",
|
2020-07-24 21:39:38 +00:00
|
|
|
Actions: dataprovider.UserActions{
|
2020-05-24 13:29:39 +00:00
|
|
|
ExecuteOn: []string{},
|
|
|
|
Hook: "",
|
2019-11-14 10:06:03 +00:00
|
|
|
},
|
2020-08-19 17:36:12 +00:00
|
|
|
ExternalAuthHook: "",
|
|
|
|
ExternalAuthScope: 0,
|
|
|
|
CredentialsPath: "credentials",
|
|
|
|
PreLoginHook: "",
|
|
|
|
PostLoginHook: "",
|
|
|
|
PostLoginScope: 0,
|
|
|
|
CheckPasswordHook: "",
|
|
|
|
CheckPasswordScope: 0,
|
2020-09-04 15:09:31 +00:00
|
|
|
PasswordHashing: dataprovider.PasswordHashing{
|
|
|
|
Argon2Options: dataprovider.Argon2Options{
|
|
|
|
Memory: 65536,
|
|
|
|
Iterations: 1,
|
|
|
|
Parallelism: 2,
|
|
|
|
},
|
|
|
|
},
|
2020-10-22 08:42:40 +00:00
|
|
|
UpdateMode: 0,
|
|
|
|
PreferDatabaseCredentials: false,
|
2019-07-20 10:26:52 +00:00
|
|
|
},
|
2019-10-07 16:19:01 +00:00
|
|
|
HTTPDConfig: httpd.Conf{
|
2020-02-03 23:08:00 +00:00
|
|
|
BindPort: 8080,
|
|
|
|
BindAddress: "127.0.0.1",
|
|
|
|
TemplatesPath: "templates",
|
|
|
|
StaticFilesPath: "static",
|
|
|
|
BackupsPath: "backups",
|
|
|
|
AuthUserFile: "",
|
|
|
|
CertificateFile: "",
|
|
|
|
CertificateKeyFile: "",
|
2019-07-20 10:26:52 +00:00
|
|
|
},
|
2020-04-26 21:29:09 +00:00
|
|
|
HTTPConfig: httpclient.Config{
|
|
|
|
Timeout: 20,
|
|
|
|
CACertificates: nil,
|
2020-05-03 09:37:50 +00:00
|
|
|
SkipTLSVerify: false,
|
2020-04-26 21:29:09 +00:00
|
|
|
},
|
2019-07-20 10:26:52 +00:00
|
|
|
}
|
2019-08-07 20:46:13 +00:00
|
|
|
|
|
|
|
viper.SetEnvPrefix(configEnvPrefix)
|
|
|
|
replacer := strings.NewReplacer(".", "__")
|
|
|
|
viper.SetEnvKeyReplacer(replacer)
|
|
|
|
viper.SetConfigName(DefaultConfigName)
|
2020-10-30 17:58:57 +00:00
|
|
|
setViperDefaults()
|
2019-08-07 20:46:13 +00:00
|
|
|
viper.AutomaticEnv()
|
2019-09-03 21:13:33 +00:00
|
|
|
viper.AllowEmptyEnv(true)
|
2019-07-20 10:26:52 +00:00
|
|
|
}
|
|
|
|
|
2020-07-24 21:39:38 +00:00
|
|
|
// GetCommonConfig returns the common protocols configuration
|
|
|
|
func GetCommonConfig() common.Configuration {
|
|
|
|
return globalConf.Common
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetCommonConfig sets the common protocols configuration
|
|
|
|
func SetCommonConfig(config common.Configuration) {
|
|
|
|
globalConf.Common = config
|
|
|
|
}
|
|
|
|
|
2019-07-30 18:51:29 +00:00
|
|
|
// GetSFTPDConfig returns the configuration for the SFTP server
|
2019-07-20 10:26:52 +00:00
|
|
|
func GetSFTPDConfig() sftpd.Configuration {
|
|
|
|
return globalConf.SFTPD
|
|
|
|
}
|
|
|
|
|
2019-10-24 16:50:35 +00:00
|
|
|
// SetSFTPDConfig sets the configuration for the SFTP server
|
|
|
|
func SetSFTPDConfig(config sftpd.Configuration) {
|
|
|
|
globalConf.SFTPD = config
|
|
|
|
}
|
|
|
|
|
2020-07-29 19:56:56 +00:00
|
|
|
// GetFTPDConfig returns the configuration for the FTP server
|
|
|
|
func GetFTPDConfig() ftpd.Configuration {
|
|
|
|
return globalConf.FTPD
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetFTPDConfig sets the configuration for the FTP server
|
|
|
|
func SetFTPDConfig(config ftpd.Configuration) {
|
|
|
|
globalConf.FTPD = config
|
|
|
|
}
|
|
|
|
|
2020-08-11 21:56:10 +00:00
|
|
|
// GetWebDAVDConfig returns the configuration for the WebDAV server
|
|
|
|
func GetWebDAVDConfig() webdavd.Configuration {
|
|
|
|
return globalConf.WebDAVD
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetWebDAVDConfig sets the configuration for the WebDAV server
|
|
|
|
func SetWebDAVDConfig(config webdavd.Configuration) {
|
|
|
|
globalConf.WebDAVD = config
|
|
|
|
}
|
|
|
|
|
2019-07-30 18:51:29 +00:00
|
|
|
// GetHTTPDConfig returns the configuration for the HTTP server
|
2019-10-07 16:19:01 +00:00
|
|
|
func GetHTTPDConfig() httpd.Conf {
|
2019-07-20 10:26:52 +00:00
|
|
|
return globalConf.HTTPDConfig
|
|
|
|
}
|
|
|
|
|
2019-10-24 16:50:35 +00:00
|
|
|
// SetHTTPDConfig sets the configuration for the HTTP server
|
|
|
|
func SetHTTPDConfig(config httpd.Conf) {
|
|
|
|
globalConf.HTTPDConfig = config
|
|
|
|
}
|
|
|
|
|
2019-07-30 18:51:29 +00:00
|
|
|
//GetProviderConf returns the configuration for the data provider
|
2019-07-20 10:26:52 +00:00
|
|
|
func GetProviderConf() dataprovider.Config {
|
|
|
|
return globalConf.ProviderConf
|
|
|
|
}
|
|
|
|
|
2019-10-24 16:50:35 +00:00
|
|
|
//SetProviderConf sets the configuration for the data provider
|
|
|
|
func SetProviderConf(config dataprovider.Config) {
|
|
|
|
globalConf.ProviderConf = config
|
|
|
|
}
|
|
|
|
|
2020-04-26 21:29:09 +00:00
|
|
|
// GetHTTPConfig returns the configuration for HTTP clients
|
|
|
|
func GetHTTPConfig() httpclient.Config {
|
|
|
|
return globalConf.HTTPConfig
|
|
|
|
}
|
|
|
|
|
2020-11-24 12:44:57 +00:00
|
|
|
// HasServicesToStart returns true if the config defines at least a service to start.
|
|
|
|
// Supported services are SFTP, FTP and WebDAV
|
|
|
|
func HasServicesToStart() bool {
|
|
|
|
if globalConf.SFTPD.BindPort > 0 {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if globalConf.FTPD.BindPort > 0 {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if globalConf.WebDAVD.BindPort > 0 {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-09-13 19:57:52 +00:00
|
|
|
func getRedactedGlobalConf() globalConfig {
|
|
|
|
conf := globalConf
|
|
|
|
conf.ProviderConf.Password = "[redacted]"
|
|
|
|
return conf
|
|
|
|
}
|
|
|
|
|
2019-08-07 20:46:13 +00:00
|
|
|
// LoadConfig loads the configuration
|
|
|
|
// configDir will be added to the configuration search paths.
|
|
|
|
// The search path contains by default the current directory and on linux it contains
|
|
|
|
// $HOME/.config/sftpgo and /etc/sftpgo too.
|
|
|
|
// configName is the name of the configuration to search without extension
|
|
|
|
func LoadConfig(configDir, configName string) error {
|
|
|
|
var err error
|
|
|
|
viper.AddConfigPath(configDir)
|
2019-09-05 20:07:59 +00:00
|
|
|
setViperAdditionalConfigPaths()
|
|
|
|
viper.AddConfigPath(".")
|
2019-08-07 20:46:13 +00:00
|
|
|
viper.SetConfigName(configName)
|
|
|
|
if err = viper.ReadInConfig(); err != nil {
|
2020-10-30 17:58:57 +00:00
|
|
|
logger.Warn(logSender, "", "error loading configuration file: %v", err)
|
|
|
|
logger.WarnToConsole("error loading configuration file: %v", err)
|
2019-07-20 10:26:52 +00:00
|
|
|
}
|
2019-08-07 20:46:13 +00:00
|
|
|
err = viper.Unmarshal(&globalConf)
|
2019-07-20 10:26:52 +00:00
|
|
|
if err != nil {
|
2019-09-13 19:57:52 +00:00
|
|
|
logger.Warn(logSender, "", "error parsing configuration file: %v. Default configuration will be used: %+v",
|
|
|
|
err, getRedactedGlobalConf())
|
2019-07-31 06:14:31 +00:00
|
|
|
logger.WarnToConsole("error parsing configuration file: %v. Default configuration will be used.", err)
|
2019-07-20 10:26:52 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-07-24 21:39:38 +00:00
|
|
|
checkCommonParamsCompatibility()
|
2019-07-29 06:53:22 +00:00
|
|
|
if strings.TrimSpace(globalConf.SFTPD.Banner) == "" {
|
2020-07-29 19:56:56 +00:00
|
|
|
globalConf.SFTPD.Banner = defaultSFTPDBanner
|
|
|
|
}
|
|
|
|
if strings.TrimSpace(globalConf.FTPD.Banner) == "" {
|
|
|
|
globalConf.FTPD.Banner = defaultFTPDBanner
|
2019-07-29 06:53:22 +00:00
|
|
|
}
|
2020-03-03 08:09:58 +00:00
|
|
|
if len(globalConf.ProviderConf.UsersBaseDir) > 0 && !utils.IsFileInputValid(globalConf.ProviderConf.UsersBaseDir) {
|
|
|
|
err = fmt.Errorf("invalid users base dir %#v will be ignored", globalConf.ProviderConf.UsersBaseDir)
|
|
|
|
globalConf.ProviderConf.UsersBaseDir = ""
|
|
|
|
logger.Warn(logSender, "", "Configuration error: %v", err)
|
|
|
|
logger.WarnToConsole("Configuration error: %v", err)
|
|
|
|
}
|
2020-07-24 21:39:38 +00:00
|
|
|
if globalConf.Common.UploadMode < 0 || globalConf.Common.UploadMode > 2 {
|
2020-02-28 23:02:06 +00:00
|
|
|
err = fmt.Errorf("invalid upload_mode 0, 1 and 2 are supported, configured: %v reset upload_mode to 0",
|
2020-07-24 21:39:38 +00:00
|
|
|
globalConf.Common.UploadMode)
|
|
|
|
globalConf.Common.UploadMode = 0
|
2019-09-05 14:21:35 +00:00
|
|
|
logger.Warn(logSender, "", "Configuration error: %v", err)
|
2019-08-04 07:37:58 +00:00
|
|
|
logger.WarnToConsole("Configuration error: %v", err)
|
|
|
|
}
|
2020-07-24 21:39:38 +00:00
|
|
|
if globalConf.Common.ProxyProtocol < 0 || globalConf.Common.ProxyProtocol > 2 {
|
2020-02-28 23:02:06 +00:00
|
|
|
err = fmt.Errorf("invalid proxy_protocol 0, 1 and 2 are supported, configured: %v reset proxy_protocol to 0",
|
2020-07-24 21:39:38 +00:00
|
|
|
globalConf.Common.ProxyProtocol)
|
|
|
|
globalConf.Common.ProxyProtocol = 0
|
2020-02-28 23:02:06 +00:00
|
|
|
logger.Warn(logSender, "", "Configuration error: %v", err)
|
|
|
|
logger.WarnToConsole("Configuration error: %v", err)
|
|
|
|
}
|
2020-01-21 09:54:05 +00:00
|
|
|
if globalConf.ProviderConf.ExternalAuthScope < 0 || globalConf.ProviderConf.ExternalAuthScope > 7 {
|
2020-01-06 20:42:41 +00:00
|
|
|
err = fmt.Errorf("invalid external_auth_scope: %v reset to 0", globalConf.ProviderConf.ExternalAuthScope)
|
|
|
|
globalConf.ProviderConf.ExternalAuthScope = 0
|
|
|
|
logger.Warn(logSender, "", "Configuration error: %v", err)
|
|
|
|
logger.WarnToConsole("Configuration error: %v", err)
|
|
|
|
}
|
2020-01-31 18:04:00 +00:00
|
|
|
if len(globalConf.ProviderConf.CredentialsPath) == 0 {
|
|
|
|
err = fmt.Errorf("invalid credentials path, reset to \"credentials\"")
|
|
|
|
globalConf.ProviderConf.CredentialsPath = "credentials"
|
|
|
|
logger.Warn(logSender, "", "Configuration error: %v", err)
|
|
|
|
logger.WarnToConsole("Configuration error: %v", err)
|
|
|
|
}
|
2020-05-16 21:26:44 +00:00
|
|
|
checkHostKeyCompatibility()
|
2020-03-03 08:09:58 +00:00
|
|
|
logger.Debug(logSender, "", "config file used: '%#v', config loaded: %+v", viper.ConfigFileUsed(), getRedactedGlobalConf())
|
2019-07-20 10:26:52 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-04-01 21:25:23 +00:00
|
|
|
|
2020-05-16 21:26:44 +00:00
|
|
|
func checkHostKeyCompatibility() {
|
|
|
|
// we copy deprecated fields to new ones to keep backward compatibility so lint is disabled
|
|
|
|
if len(globalConf.SFTPD.Keys) > 0 && len(globalConf.SFTPD.HostKeys) == 0 { //nolint:staticcheck
|
|
|
|
logger.Warn(logSender, "", "keys is deprecated, please use host_keys")
|
|
|
|
logger.WarnToConsole("keys is deprecated, please use host_keys")
|
|
|
|
for _, k := range globalConf.SFTPD.Keys { //nolint:staticcheck
|
|
|
|
globalConf.SFTPD.HostKeys = append(globalConf.SFTPD.HostKeys, k.PrivateKey)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-07-24 21:39:38 +00:00
|
|
|
|
|
|
|
func checkCommonParamsCompatibility() {
|
|
|
|
// we copy deprecated fields to new ones to keep backward compatibility so lint is disabled
|
|
|
|
if globalConf.SFTPD.IdleTimeout > 0 { //nolint:staticcheck
|
|
|
|
logger.Warn(logSender, "", "sftpd.idle_timeout is deprecated, please use common.idle_timeout")
|
|
|
|
logger.WarnToConsole("sftpd.idle_timeout is deprecated, please use common.idle_timeout")
|
|
|
|
globalConf.Common.IdleTimeout = globalConf.SFTPD.IdleTimeout //nolint:staticcheck
|
|
|
|
}
|
|
|
|
if len(globalConf.SFTPD.Actions.Hook) > 0 && len(globalConf.Common.Actions.Hook) == 0 { //nolint:staticcheck
|
|
|
|
logger.Warn(logSender, "", "sftpd.actions is deprecated, please use common.actions")
|
|
|
|
logger.WarnToConsole("sftpd.actions is deprecated, please use common.actions")
|
|
|
|
globalConf.Common.Actions.ExecuteOn = globalConf.SFTPD.Actions.ExecuteOn //nolint:staticcheck
|
|
|
|
globalConf.Common.Actions.Hook = globalConf.SFTPD.Actions.Hook //nolint:staticcheck
|
|
|
|
}
|
|
|
|
if globalConf.SFTPD.SetstatMode > 0 && globalConf.Common.SetstatMode == 0 { //nolint:staticcheck
|
|
|
|
logger.Warn(logSender, "", "sftpd.setstat_mode is deprecated, please use common.setstat_mode")
|
|
|
|
logger.WarnToConsole("sftpd.setstat_mode is deprecated, please use common.setstat_mode")
|
|
|
|
globalConf.Common.SetstatMode = globalConf.SFTPD.SetstatMode //nolint:staticcheck
|
|
|
|
}
|
|
|
|
if globalConf.SFTPD.UploadMode > 0 && globalConf.Common.UploadMode == 0 { //nolint:staticcheck
|
|
|
|
logger.Warn(logSender, "", "sftpd.upload_mode is deprecated, please use common.upload_mode")
|
|
|
|
logger.WarnToConsole("sftpd.upload_mode is deprecated, please use common.upload_mode")
|
|
|
|
globalConf.Common.UploadMode = globalConf.SFTPD.UploadMode //nolint:staticcheck
|
|
|
|
}
|
|
|
|
if globalConf.SFTPD.ProxyProtocol > 0 && globalConf.Common.ProxyProtocol == 0 { //nolint:staticcheck
|
|
|
|
logger.Warn(logSender, "", "sftpd.proxy_protocol is deprecated, please use common.proxy_protocol")
|
|
|
|
logger.WarnToConsole("sftpd.proxy_protocol is deprecated, please use common.proxy_protocol")
|
|
|
|
globalConf.Common.ProxyProtocol = globalConf.SFTPD.ProxyProtocol //nolint:staticcheck
|
|
|
|
globalConf.Common.ProxyAllowed = globalConf.SFTPD.ProxyAllowed //nolint:staticcheck
|
|
|
|
}
|
|
|
|
}
|
2020-10-30 17:58:57 +00:00
|
|
|
|
|
|
|
func setViperDefaults() {
|
|
|
|
viper.SetDefault("common.idle_timeout", globalConf.Common.IdleTimeout)
|
|
|
|
viper.SetDefault("common.upload_mode", globalConf.Common.UploadMode)
|
|
|
|
viper.SetDefault("common.actions.execute_on", globalConf.Common.Actions.ExecuteOn)
|
|
|
|
viper.SetDefault("common.actions.hook", globalConf.Common.Actions.Hook)
|
|
|
|
viper.SetDefault("common.setstat_mode", globalConf.Common.SetstatMode)
|
|
|
|
viper.SetDefault("common.proxy_protocol", globalConf.Common.ProxyProtocol)
|
|
|
|
viper.SetDefault("common.proxy_allowed", globalConf.Common.ProxyAllowed)
|
|
|
|
viper.SetDefault("common.post_connect_hook", globalConf.Common.PostConnectHook)
|
|
|
|
viper.SetDefault("sftpd.bind_port", globalConf.SFTPD.BindPort)
|
|
|
|
viper.SetDefault("sftpd.bind_address", globalConf.SFTPD.BindAddress)
|
|
|
|
viper.SetDefault("sftpd.max_auth_tries", globalConf.SFTPD.MaxAuthTries)
|
|
|
|
viper.SetDefault("sftpd.banner", globalConf.SFTPD.Banner)
|
|
|
|
viper.SetDefault("sftpd.host_keys", globalConf.SFTPD.HostKeys)
|
|
|
|
viper.SetDefault("sftpd.kex_algorithms", globalConf.SFTPD.KexAlgorithms)
|
|
|
|
viper.SetDefault("sftpd.ciphers", globalConf.SFTPD.Ciphers)
|
|
|
|
viper.SetDefault("sftpd.macs", globalConf.SFTPD.MACs)
|
|
|
|
viper.SetDefault("sftpd.trusted_user_ca_keys", globalConf.SFTPD.TrustedUserCAKeys)
|
|
|
|
viper.SetDefault("sftpd.login_banner_file", globalConf.SFTPD.LoginBannerFile)
|
|
|
|
viper.SetDefault("sftpd.enabled_ssh_commands", globalConf.SFTPD.EnabledSSHCommands)
|
|
|
|
viper.SetDefault("sftpd.keyboard_interactive_auth_hook", globalConf.SFTPD.KeyboardInteractiveHook)
|
|
|
|
viper.SetDefault("sftpd.password_authentication", globalConf.SFTPD.PasswordAuthentication)
|
|
|
|
viper.SetDefault("ftpd.bind_port", globalConf.FTPD.BindPort)
|
|
|
|
viper.SetDefault("ftpd.bind_address", globalConf.FTPD.BindAddress)
|
|
|
|
viper.SetDefault("ftpd.banner", globalConf.FTPD.Banner)
|
|
|
|
viper.SetDefault("ftpd.banner_file", globalConf.FTPD.BannerFile)
|
|
|
|
viper.SetDefault("ftpd.active_transfers_port_non_20", globalConf.FTPD.ActiveTransfersPortNon20)
|
|
|
|
viper.SetDefault("ftpd.force_passive_ip", globalConf.FTPD.ForcePassiveIP)
|
|
|
|
viper.SetDefault("ftpd.passive_port_range.start", globalConf.FTPD.PassivePortRange.Start)
|
|
|
|
viper.SetDefault("ftpd.passive_port_range.end", globalConf.FTPD.PassivePortRange.End)
|
|
|
|
viper.SetDefault("ftpd.certificate_file", globalConf.FTPD.CertificateFile)
|
|
|
|
viper.SetDefault("ftpd.certificate_key_file", globalConf.FTPD.CertificateKeyFile)
|
|
|
|
viper.SetDefault("ftpd.tls_mode", globalConf.FTPD.TLSMode)
|
|
|
|
viper.SetDefault("webdavd.bind_port", globalConf.WebDAVD.BindPort)
|
|
|
|
viper.SetDefault("webdavd.bind_address", globalConf.WebDAVD.BindAddress)
|
|
|
|
viper.SetDefault("webdavd.certificate_file", globalConf.WebDAVD.CertificateFile)
|
|
|
|
viper.SetDefault("webdavd.certificate_key_file", globalConf.WebDAVD.CertificateKeyFile)
|
|
|
|
viper.SetDefault("webdavd.cors.enabled", globalConf.WebDAVD.Cors.Enabled)
|
|
|
|
viper.SetDefault("webdavd.cors.allowed_origins", globalConf.WebDAVD.Cors.AllowedOrigins)
|
|
|
|
viper.SetDefault("webdavd.cors.allowed_methods", globalConf.WebDAVD.Cors.AllowedMethods)
|
|
|
|
viper.SetDefault("webdavd.cors.allowed_headers", globalConf.WebDAVD.Cors.AllowedHeaders)
|
|
|
|
viper.SetDefault("webdavd.cors.exposed_headers", globalConf.WebDAVD.Cors.ExposedHeaders)
|
|
|
|
viper.SetDefault("webdavd.cors.allow_credentials", globalConf.WebDAVD.Cors.AllowCredentials)
|
|
|
|
viper.SetDefault("webdavd.cors.max_age", globalConf.WebDAVD.Cors.MaxAge)
|
2020-11-04 18:11:40 +00:00
|
|
|
viper.SetDefault("webdavd.cache.users.expiration_time", globalConf.WebDAVD.Cache.Users.ExpirationTime)
|
|
|
|
viper.SetDefault("webdavd.cache.users.max_size", globalConf.WebDAVD.Cache.Users.MaxSize)
|
|
|
|
viper.SetDefault("webdavd.cache.mime_types.enabled", globalConf.WebDAVD.Cache.MimeTypes.Enabled)
|
|
|
|
viper.SetDefault("webdavd.cache.mime_types.max_size", globalConf.WebDAVD.Cache.MimeTypes.MaxSize)
|
2020-10-30 17:58:57 +00:00
|
|
|
viper.SetDefault("data_provider.driver", globalConf.ProviderConf.Driver)
|
|
|
|
viper.SetDefault("data_provider.name", globalConf.ProviderConf.Name)
|
|
|
|
viper.SetDefault("data_provider.host", globalConf.ProviderConf.Host)
|
|
|
|
viper.SetDefault("data_provider.port", globalConf.ProviderConf.Port)
|
|
|
|
viper.SetDefault("data_provider.username", globalConf.ProviderConf.Username)
|
|
|
|
viper.SetDefault("data_provider.password", globalConf.ProviderConf.Password)
|
|
|
|
viper.SetDefault("data_provider.sslmode", globalConf.ProviderConf.SSLMode)
|
|
|
|
viper.SetDefault("data_provider.connection_string", globalConf.ProviderConf.ConnectionString)
|
|
|
|
viper.SetDefault("data_provider.sql_tables_prefix", globalConf.ProviderConf.SQLTablesPrefix)
|
|
|
|
viper.SetDefault("data_provider.manage_users", globalConf.ProviderConf.ManageUsers)
|
|
|
|
viper.SetDefault("data_provider.track_quota", globalConf.ProviderConf.TrackQuota)
|
|
|
|
viper.SetDefault("data_provider.pool_size", globalConf.ProviderConf.PoolSize)
|
|
|
|
viper.SetDefault("data_provider.users_base_dir", globalConf.ProviderConf.UsersBaseDir)
|
|
|
|
viper.SetDefault("data_provider.actions.execute_on", globalConf.ProviderConf.Actions.ExecuteOn)
|
|
|
|
viper.SetDefault("data_provider.actions.hook", globalConf.ProviderConf.Actions.Hook)
|
|
|
|
viper.SetDefault("data_provider.external_auth_hook", globalConf.ProviderConf.ExternalAuthHook)
|
|
|
|
viper.SetDefault("data_provider.external_auth_scope", globalConf.ProviderConf.ExternalAuthScope)
|
|
|
|
viper.SetDefault("data_provider.credentials_path", globalConf.ProviderConf.CredentialsPath)
|
|
|
|
viper.SetDefault("data_provider.prefer_database_credentials", globalConf.ProviderConf.PreferDatabaseCredentials)
|
|
|
|
viper.SetDefault("data_provider.pre_login_hook", globalConf.ProviderConf.PreLoginHook)
|
|
|
|
viper.SetDefault("data_provider.post_login_hook", globalConf.ProviderConf.PostLoginHook)
|
|
|
|
viper.SetDefault("data_provider.post_login_scope", globalConf.ProviderConf.PostLoginScope)
|
|
|
|
viper.SetDefault("data_provider.check_password_hook", globalConf.ProviderConf.CheckPasswordHook)
|
|
|
|
viper.SetDefault("data_provider.check_password_scope", globalConf.ProviderConf.CheckPasswordScope)
|
|
|
|
viper.SetDefault("data_provider.password_hashing.argon2_options.memory", globalConf.ProviderConf.PasswordHashing.Argon2Options.Memory)
|
|
|
|
viper.SetDefault("data_provider.password_hashing.argon2_options.iterations", globalConf.ProviderConf.PasswordHashing.Argon2Options.Iterations)
|
|
|
|
viper.SetDefault("data_provider.password_hashing.argon2_options.parallelism", globalConf.ProviderConf.PasswordHashing.Argon2Options.Parallelism)
|
|
|
|
viper.SetDefault("data_provider.update_mode", globalConf.ProviderConf.UpdateMode)
|
|
|
|
viper.SetDefault("httpd.bind_port", globalConf.HTTPDConfig.BindPort)
|
|
|
|
viper.SetDefault("httpd.bind_address", globalConf.HTTPDConfig.BindAddress)
|
|
|
|
viper.SetDefault("httpd.templates_path", globalConf.HTTPDConfig.TemplatesPath)
|
|
|
|
viper.SetDefault("httpd.static_files_path", globalConf.HTTPDConfig.StaticFilesPath)
|
|
|
|
viper.SetDefault("httpd.backups_path", globalConf.HTTPDConfig.BackupsPath)
|
|
|
|
viper.SetDefault("httpd.auth_user_file", globalConf.HTTPDConfig.AuthUserFile)
|
|
|
|
viper.SetDefault("httpd.certificate_file", globalConf.HTTPDConfig.CertificateFile)
|
|
|
|
viper.SetDefault("httpd.certificate_key_file", globalConf.HTTPDConfig.CertificateKeyFile)
|
|
|
|
viper.SetDefault("http.timeout", globalConf.HTTPConfig.Timeout)
|
|
|
|
viper.SetDefault("http.ca_certificates", globalConf.HTTPConfig.CACertificates)
|
|
|
|
viper.SetDefault("http.skip_tls_verify", globalConf.HTTPConfig.SkipTLSVerify)
|
|
|
|
}
|