mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-06 22:30:56 +03: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:
@@ -181,3 +181,6 @@ Flags:
|
|||||||
--webdav-port int 0 means a random unprivileged port,
|
--webdav-port int 0 means a random unprivileged port,
|
||||||
< 0 disabled (default -1)
|
< 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),
|
"{{FsTargetPath}}", p.getStringReplacement(p.FsTargetPath, jsonEscaped),
|
||||||
"{{ObjectName}}", p.getStringReplacement(p.ObjectName, jsonEscaped),
|
"{{ObjectName}}", p.getStringReplacement(p.ObjectName, jsonEscaped),
|
||||||
"{{ObjectType}}", p.ObjectType,
|
"{{ObjectType}}", p.ObjectType,
|
||||||
"{{FileSize}}", fmt.Sprintf("%d", p.FileSize),
|
"{{FileSize}}", strconv.FormatInt(p.FileSize, 10),
|
||||||
"{{Elapsed}}", fmt.Sprintf("%d", p.Elapsed),
|
"{{Elapsed}}", strconv.FormatInt(p.Elapsed, 10),
|
||||||
"{{Protocol}}", p.Protocol,
|
"{{Protocol}}", p.Protocol,
|
||||||
"{{IP}}", p.IP,
|
"{{IP}}", p.IP,
|
||||||
"{{Role}}", p.getStringReplacement(p.Role, jsonEscaped),
|
"{{Role}}", p.getStringReplacement(p.Role, jsonEscaped),
|
||||||
"{{Email}}", p.getStringReplacement(p.Email, jsonEscaped),
|
"{{Email}}", p.getStringReplacement(p.Email, jsonEscaped),
|
||||||
"{{Timestamp}}", fmt.Sprintf("%d", p.Timestamp),
|
"{{Timestamp}}", strconv.FormatInt(p.Timestamp, 10),
|
||||||
"{{StatusString}}", p.getStatusString(),
|
"{{StatusString}}", p.getStatusString(),
|
||||||
"{{UID}}", p.getStringReplacement(p.UID, jsonEscaped),
|
"{{UID}}", p.getStringReplacement(p.UID, jsonEscaped),
|
||||||
"{{Ext}}", p.getStringReplacement(p.Extension, jsonEscaped),
|
"{{Ext}}", p.getStringReplacement(p.Extension, jsonEscaped),
|
||||||
|
|||||||
@@ -65,21 +65,10 @@ func (s *Service) StartPortableMode(sftpdPort, ftpPort, webdavPort, httpPort int
|
|||||||
telemetryConf.BindPort = 0
|
telemetryConf.BindPort = 0
|
||||||
config.SetTelemetryConfig(telemetryConf)
|
config.SetTelemetryConfig(telemetryConf)
|
||||||
|
|
||||||
if sftpdPort >= 0 {
|
configurePortableSFTPService(sftpdPort, enabledSSHCommands)
|
||||||
configurePortableSFTPService(sftpdPort, enabledSSHCommands)
|
configurePortableFTPService(ftpPort, ftpsCert, ftpsKey)
|
||||||
}
|
configurePortableWebDAVService(webdavPort, webDavCert, webDavKey)
|
||||||
|
configurePortableHTTPService(httpPort, httpsCert, httpsKey)
|
||||||
if ftpPort >= 0 {
|
|
||||||
configurePortableFTPService(ftpPort, ftpsCert, ftpsKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
if webdavPort >= 0 {
|
|
||||||
configurePortableWebDAVService(webdavPort, webDavCert, webDavKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
if httpPort >= 0 {
|
|
||||||
configurePortableHTTPService(httpPort, httpsCert, httpsKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = s.Start(true)
|
err = s.Start(true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -217,9 +206,11 @@ func configurePortableSFTPService(port int, enabledSSHCommands []string) {
|
|||||||
}
|
}
|
||||||
if port > 0 {
|
if port > 0 {
|
||||||
sftpdConf.Bindings[0].Port = port
|
sftpdConf.Bindings[0].Port = port
|
||||||
} else {
|
} else if port == 0 {
|
||||||
// dynamic ports starts from 49152
|
// dynamic ports starts from 49152
|
||||||
sftpdConf.Bindings[0].Port = 49152 + rand.Intn(15000)
|
sftpdConf.Bindings[0].Port = 49152 + rand.Intn(15000)
|
||||||
|
} else {
|
||||||
|
sftpdConf.Bindings[0].Port = 0
|
||||||
}
|
}
|
||||||
if util.Contains(enabledSSHCommands, "*") {
|
if util.Contains(enabledSSHCommands, "*") {
|
||||||
sftpdConf.EnabledSSHCommands = sftpd.GetSupportedSSHCommands()
|
sftpdConf.EnabledSSHCommands = sftpd.GetSupportedSSHCommands()
|
||||||
@@ -236,8 +227,10 @@ func configurePortableFTPService(port int, cert, key string) {
|
|||||||
}
|
}
|
||||||
if port > 0 {
|
if port > 0 {
|
||||||
ftpConf.Bindings[0].Port = port
|
ftpConf.Bindings[0].Port = port
|
||||||
} else {
|
} else if port == 0 {
|
||||||
ftpConf.Bindings[0].Port = 49152 + rand.Intn(15000)
|
ftpConf.Bindings[0].Port = 49152 + rand.Intn(15000)
|
||||||
|
} else {
|
||||||
|
ftpConf.Bindings[0].Port = 0
|
||||||
}
|
}
|
||||||
if ftpConf.Banner == "" {
|
if ftpConf.Banner == "" {
|
||||||
ftpConf.Banner = fmt.Sprintf("SFTPGo portable %v ready", version.Get().Version)
|
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 {
|
if port > 0 {
|
||||||
webDavConf.Bindings[0].Port = port
|
webDavConf.Bindings[0].Port = port
|
||||||
} else {
|
} else if port == 0 {
|
||||||
webDavConf.Bindings[0].Port = 49152 + rand.Intn(15000)
|
webDavConf.Bindings[0].Port = 49152 + rand.Intn(15000)
|
||||||
|
} else {
|
||||||
|
webDavConf.Bindings[0].Port = 0
|
||||||
}
|
}
|
||||||
webDavConf.Bindings[0].CertificateFile = cert
|
webDavConf.Bindings[0].CertificateFile = cert
|
||||||
webDavConf.Bindings[0].CertificateKeyFile = key
|
webDavConf.Bindings[0].CertificateKeyFile = key
|
||||||
webDavConf.Bindings[0].EnableHTTPS = true
|
if cert != "" && key != "" {
|
||||||
|
webDavConf.Bindings[0].EnableHTTPS = true
|
||||||
|
}
|
||||||
config.SetWebDAVDConfig(webDavConf)
|
config.SetWebDAVDConfig(webDavConf)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,12 +267,16 @@ func configurePortableHTTPService(port int, cert, key string) {
|
|||||||
}
|
}
|
||||||
if port > 0 {
|
if port > 0 {
|
||||||
httpdConf.Bindings[0].Port = port
|
httpdConf.Bindings[0].Port = port
|
||||||
} else {
|
} else if port == 0 {
|
||||||
httpdConf.Bindings[0].Port = 49152 + rand.Intn(15000)
|
httpdConf.Bindings[0].Port = 49152 + rand.Intn(15000)
|
||||||
|
} else {
|
||||||
|
httpdConf.Bindings[0].Port = 0
|
||||||
}
|
}
|
||||||
httpdConf.Bindings[0].CertificateFile = cert
|
httpdConf.Bindings[0].CertificateFile = cert
|
||||||
httpdConf.Bindings[0].CertificateKeyFile = key
|
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].EnableWebAdmin = false
|
||||||
httpdConf.Bindings[0].EnableWebClient = true
|
httpdConf.Bindings[0].EnableWebClient = true
|
||||||
httpdConf.Bindings[0].EnableRESTAPI = false
|
httpdConf.Bindings[0].EnableRESTAPI = false
|
||||||
|
|||||||
Reference in New Issue
Block a user