|
@@ -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
|