mirror of
https://github.com/drakkan/sftpgo.git
synced 2024-11-21 23:20:24 +00:00
document the new banner configuration
use SFTPGo as default banner and ensure that the banner is not empty
This commit is contained in:
parent
be9a1fb7c4
commit
2456d5c3bf
4 changed files with 34 additions and 3 deletions
|
@ -64,6 +64,7 @@ The `sftpgo.conf` configuration file contains the following sections:
|
||||||
- `idle_timeout`, integer. Time in minutes after which an idle client will be disconnected. Default: 15
|
- `idle_timeout`, integer. Time in minutes after which an idle client will be disconnected. Default: 15
|
||||||
- `max_auth_tries` integer. Maximum number of authentication attempts permitted per connection. If set to a negative number, the number of attempts are unlimited. If set to zero, the number of attempts are limited to 6.
|
- `max_auth_tries` integer. Maximum number of authentication attempts permitted per connection. If set to a negative number, the number of attempts are unlimited. If set to zero, the number of attempts are limited to 6.
|
||||||
- `umask`, string. Umask for the new files and directories. This setting has no effect on Windows. Default: "0022"
|
- `umask`, string. Umask for the new files and directories. This setting has no effect on Windows. Default: "0022"
|
||||||
|
- `banner`, string. Identification string used by the server. Default "SFTPGo"
|
||||||
- `actions`, struct. It contains the command to execute and/or the HTTP URL to notify and the trigger conditions
|
- `actions`, struct. It contains the command to execute and/or the HTTP URL to notify and the trigger conditions
|
||||||
- `execute_on`, list of strings. Valid values are `download`, `upload`, `delete`, `rename`. On folder deletion a `delete` notification will be sent for each deleted file. Leave empty to disable actions.
|
- `execute_on`, list of strings. Valid values are `download`, `upload`, `delete`, `rename`. On folder deletion a `delete` notification will be sent for each deleted file. Leave empty to disable actions.
|
||||||
- `command`, string. Absolute path to the command to execute. Leave empty to disable. The command is invoked with the following arguments:
|
- `command`, string. Absolute path to the command to execute. Leave empty to disable. The command is invoked with the following arguments:
|
||||||
|
@ -104,6 +105,7 @@ Here is a full example showing the default config:
|
||||||
"idle_timeout":15,
|
"idle_timeout":15,
|
||||||
"max_auth_tries":0,
|
"max_auth_tries":0,
|
||||||
"umask":"0022",
|
"umask":"0022",
|
||||||
|
"banner":"SFTPGo",
|
||||||
"actions":{
|
"actions":{
|
||||||
"execute_on":[],
|
"execute_on":[],
|
||||||
"command":"",
|
"command":"",
|
||||||
|
|
|
@ -3,6 +3,7 @@ package config
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/drakkan/sftpgo/api"
|
"github.com/drakkan/sftpgo/api"
|
||||||
"github.com/drakkan/sftpgo/dataprovider"
|
"github.com/drakkan/sftpgo/dataprovider"
|
||||||
|
@ -11,7 +12,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
logSender = "config"
|
logSender = "config"
|
||||||
|
defaultBanner = "SFTPGo"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -28,7 +30,7 @@ func init() {
|
||||||
// create a default configuration to use if no config file is provided
|
// create a default configuration to use if no config file is provided
|
||||||
globalConf = globalConfig{
|
globalConf = globalConfig{
|
||||||
SFTPD: sftpd.Configuration{
|
SFTPD: sftpd.Configuration{
|
||||||
Banner: "SFTPServer",
|
Banner: defaultBanner,
|
||||||
BindPort: 2022,
|
BindPort: 2022,
|
||||||
BindAddress: "",
|
BindAddress: "",
|
||||||
IdleTimeout: 15,
|
IdleTimeout: 15,
|
||||||
|
@ -78,7 +80,6 @@ func GetProviderConf() dataprovider.Config {
|
||||||
// LoadConfig loads configuration from sftpgo.conf
|
// LoadConfig loads configuration from sftpgo.conf
|
||||||
func LoadConfig(configPath string) error {
|
func LoadConfig(configPath string) error {
|
||||||
logger.Debug(logSender, "load config from path: %v", configPath)
|
logger.Debug(logSender, "load config from path: %v", configPath)
|
||||||
//globalConf.basePath = basePath
|
|
||||||
file, err := os.Open(configPath)
|
file, err := os.Open(configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warn(logSender, "error loading configuration file: %v. Default configuration will be used: %+v", err, globalConf)
|
logger.Warn(logSender, "error loading configuration file: %v. Default configuration will be used: %+v", err, globalConf)
|
||||||
|
@ -90,6 +91,9 @@ func LoadConfig(configPath string) error {
|
||||||
logger.Warn(logSender, "error parsing config file: %v. Default configuration will be used: %+v", err, globalConf)
|
logger.Warn(logSender, "error parsing config file: %v. Default configuration will be used: %+v", err, globalConf)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if strings.TrimSpace(globalConf.SFTPD.Banner) == "" {
|
||||||
|
globalConf.SFTPD.Banner = defaultBanner
|
||||||
|
}
|
||||||
logger.Debug(logSender, "config loaded: %+v", globalConf)
|
logger.Debug(logSender, "config loaded: %+v", globalConf)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package config_test
|
package config_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/drakkan/sftpgo/api"
|
"github.com/drakkan/sftpgo/api"
|
||||||
|
@ -45,3 +47,25 @@ func TestLoadConfigTest(t *testing.T) {
|
||||||
}
|
}
|
||||||
os.Remove(configFilePath)
|
os.Remove(configFilePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEmptyBanner(t *testing.T) {
|
||||||
|
configDir := ".."
|
||||||
|
confName := "temp.conf"
|
||||||
|
configFilePath := filepath.Join(configDir, confName)
|
||||||
|
config.LoadConfig(configFilePath)
|
||||||
|
sftpdConf := config.GetSFTPDConfig()
|
||||||
|
sftpdConf.Banner = " "
|
||||||
|
c := make(map[string]sftpd.Configuration)
|
||||||
|
c["sftpd"] = sftpdConf
|
||||||
|
jsonConf, _ := json.Marshal(c)
|
||||||
|
err := ioutil.WriteFile(configFilePath, jsonConf, 0666)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("error saving temporary configuration")
|
||||||
|
}
|
||||||
|
config.LoadConfig(configFilePath)
|
||||||
|
sftpdConf = config.GetSFTPDConfig()
|
||||||
|
if strings.TrimSpace(sftpdConf.Banner) == "" {
|
||||||
|
t.Errorf("SFTPD banner cannot be empty")
|
||||||
|
}
|
||||||
|
os.Remove(configFilePath)
|
||||||
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
"idle_timeout":15,
|
"idle_timeout":15,
|
||||||
"max_auth_tries":0,
|
"max_auth_tries":0,
|
||||||
"umask":"0022",
|
"umask":"0022",
|
||||||
|
"banner":" ",
|
||||||
"actions":{
|
"actions":{
|
||||||
"execute_on":[],
|
"execute_on":[],
|
||||||
"command":"",
|
"command":"",
|
||||||
|
|
Loading…
Reference in a new issue