mirror of
https://github.com/drakkan/sftpgo.git
synced 2024-11-25 09:00:27 +00:00
portable mode: fix disabling services if enabled using a config file
clarify that a config file/env vars can still be used for further customizations Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
parent
00ce4e4685
commit
ba472c3c67
3 changed files with 28 additions and 24 deletions
|
@ -181,3 +181,6 @@ Flags:
|
|||
--webdav-port int 0 means a random unprivileged port,
|
||||
< 0 disabled (default -1)
|
||||
```
|
||||
|
||||
In portable mode you can apply further customizations using a configuration file/environment variables as for the service mode.
|
||||
SFTP, FTP, HTTP and WebDAV settings configured using the CLI flags are applied to the first binding, any additional bindings will not be affected.
|
||||
|
|
|
@ -783,13 +783,13 @@ func (p *EventParams) getStringReplacements(addObjectData, jsonEscaped bool) []s
|
|||
"{{FsTargetPath}}", p.getStringReplacement(p.FsTargetPath, jsonEscaped),
|
||||
"{{ObjectName}}", p.getStringReplacement(p.ObjectName, jsonEscaped),
|
||||
"{{ObjectType}}", p.ObjectType,
|
||||
"{{FileSize}}", fmt.Sprintf("%d", p.FileSize),
|
||||
"{{Elapsed}}", fmt.Sprintf("%d", p.Elapsed),
|
||||
"{{FileSize}}", strconv.FormatInt(p.FileSize, 10),
|
||||
"{{Elapsed}}", strconv.FormatInt(p.Elapsed, 10),
|
||||
"{{Protocol}}", p.Protocol,
|
||||
"{{IP}}", p.IP,
|
||||
"{{Role}}", p.getStringReplacement(p.Role, jsonEscaped),
|
||||
"{{Email}}", p.getStringReplacement(p.Email, jsonEscaped),
|
||||
"{{Timestamp}}", fmt.Sprintf("%d", p.Timestamp),
|
||||
"{{Timestamp}}", strconv.FormatInt(p.Timestamp, 10),
|
||||
"{{StatusString}}", p.getStatusString(),
|
||||
"{{UID}}", p.getStringReplacement(p.UID, jsonEscaped),
|
||||
"{{Ext}}", p.getStringReplacement(p.Extension, jsonEscaped),
|
||||
|
|
|
@ -65,21 +65,10 @@ func (s *Service) StartPortableMode(sftpdPort, ftpPort, webdavPort, httpPort int
|
|||
telemetryConf.BindPort = 0
|
||||
config.SetTelemetryConfig(telemetryConf)
|
||||
|
||||
if sftpdPort >= 0 {
|
||||
configurePortableSFTPService(sftpdPort, enabledSSHCommands)
|
||||
}
|
||||
|
||||
if ftpPort >= 0 {
|
||||
configurePortableFTPService(ftpPort, ftpsCert, ftpsKey)
|
||||
}
|
||||
|
||||
if webdavPort >= 0 {
|
||||
configurePortableWebDAVService(webdavPort, webDavCert, webDavKey)
|
||||
}
|
||||
|
||||
if httpPort >= 0 {
|
||||
configurePortableHTTPService(httpPort, httpsCert, httpsKey)
|
||||
}
|
||||
configurePortableSFTPService(sftpdPort, enabledSSHCommands)
|
||||
configurePortableFTPService(ftpPort, ftpsCert, ftpsKey)
|
||||
configurePortableWebDAVService(webdavPort, webDavCert, webDavKey)
|
||||
configurePortableHTTPService(httpPort, httpsCert, httpsKey)
|
||||
|
||||
err = s.Start(true)
|
||||
if err != nil {
|
||||
|
@ -217,9 +206,11 @@ func configurePortableSFTPService(port int, enabledSSHCommands []string) {
|
|||
}
|
||||
if port > 0 {
|
||||
sftpdConf.Bindings[0].Port = port
|
||||
} else {
|
||||
} else if port == 0 {
|
||||
// dynamic ports starts from 49152
|
||||
sftpdConf.Bindings[0].Port = 49152 + rand.Intn(15000)
|
||||
} else {
|
||||
sftpdConf.Bindings[0].Port = 0
|
||||
}
|
||||
if util.Contains(enabledSSHCommands, "*") {
|
||||
sftpdConf.EnabledSSHCommands = sftpd.GetSupportedSSHCommands()
|
||||
|
@ -236,8 +227,10 @@ func configurePortableFTPService(port int, cert, key string) {
|
|||
}
|
||||
if port > 0 {
|
||||
ftpConf.Bindings[0].Port = port
|
||||
} else {
|
||||
} else if port == 0 {
|
||||
ftpConf.Bindings[0].Port = 49152 + rand.Intn(15000)
|
||||
} else {
|
||||
ftpConf.Bindings[0].Port = 0
|
||||
}
|
||||
if ftpConf.Banner == "" {
|
||||
ftpConf.Banner = fmt.Sprintf("SFTPGo portable %v ready", version.Get().Version)
|
||||
|
@ -254,12 +247,16 @@ func configurePortableWebDAVService(port int, cert, key string) {
|
|||
}
|
||||
if port > 0 {
|
||||
webDavConf.Bindings[0].Port = port
|
||||
} else {
|
||||
} else if port == 0 {
|
||||
webDavConf.Bindings[0].Port = 49152 + rand.Intn(15000)
|
||||
} else {
|
||||
webDavConf.Bindings[0].Port = 0
|
||||
}
|
||||
webDavConf.Bindings[0].CertificateFile = cert
|
||||
webDavConf.Bindings[0].CertificateKeyFile = key
|
||||
webDavConf.Bindings[0].EnableHTTPS = true
|
||||
if cert != "" && key != "" {
|
||||
webDavConf.Bindings[0].EnableHTTPS = true
|
||||
}
|
||||
config.SetWebDAVDConfig(webDavConf)
|
||||
}
|
||||
|
||||
|
@ -270,12 +267,16 @@ func configurePortableHTTPService(port int, cert, key string) {
|
|||
}
|
||||
if port > 0 {
|
||||
httpdConf.Bindings[0].Port = port
|
||||
} else {
|
||||
} else if port == 0 {
|
||||
httpdConf.Bindings[0].Port = 49152 + rand.Intn(15000)
|
||||
} else {
|
||||
httpdConf.Bindings[0].Port = 0
|
||||
}
|
||||
httpdConf.Bindings[0].CertificateFile = cert
|
||||
httpdConf.Bindings[0].CertificateKeyFile = key
|
||||
httpdConf.Bindings[0].EnableHTTPS = true
|
||||
if cert != "" && key != "" {
|
||||
httpdConf.Bindings[0].EnableHTTPS = true
|
||||
}
|
||||
httpdConf.Bindings[0].EnableWebAdmin = false
|
||||
httpdConf.Bindings[0].EnableWebClient = true
|
||||
httpdConf.Bindings[0].EnableRESTAPI = false
|
||||
|
|
Loading…
Reference in a new issue