portable mode: advertise WebDAV service if requested

This commit is contained in:
Nicola Murino
2020-09-21 16:08:32 +02:00
parent 6c1a7449fe
commit a550d082a3

View File

@@ -81,7 +81,7 @@ func (s *Service) StartPortableMode(sftpdPort, ftpPort, webdavPort int, enabledS
config.SetFTPDConfig(ftpConf) config.SetFTPDConfig(ftpConf)
} }
if webdavPort > 0 { if webdavPort >= 0 {
webDavConf := config.GetWebDAVDConfig() webDavConf := config.GetWebDAVDConfig()
if webdavPort > 0 { if webdavPort > 0 {
webDavConf.BindPort = webdavPort webDavConf.BindPort = webdavPort
@@ -129,7 +129,9 @@ func (s *Service) getServiceOptionalInfoString() string {
func (s *Service) advertiseServices(advertiseService, advertiseCredentials bool) { func (s *Service) advertiseServices(advertiseService, advertiseCredentials bool) {
var mDNSServiceSFTP *zeroconf.Server var mDNSServiceSFTP *zeroconf.Server
var mDNSServiceFTP *zeroconf.Server var mDNSServiceFTP *zeroconf.Server
var mDNSServiceDAV *zeroconf.Server
var err error var err error
if advertiseService { if advertiseService {
meta := []string{ meta := []string{
fmt.Sprintf("version=%v", version.Get().Version), fmt.Sprintf("version=%v", version.Get().Version),
@@ -144,6 +146,7 @@ func (s *Service) advertiseServices(advertiseService, advertiseCredentials bool)
} }
} }
sftpdConf := config.GetSFTPDConfig() sftpdConf := config.GetSFTPDConfig()
if sftpdConf.BindPort > 0 {
mDNSServiceSFTP, err = zeroconf.Register( mDNSServiceSFTP, err = zeroconf.Register(
fmt.Sprintf("SFTPGo portable %v", sftpdConf.BindPort), // service instance name fmt.Sprintf("SFTPGo portable %v", sftpdConf.BindPort), // service instance name
"_sftp-ssh._tcp", // service type and protocol "_sftp-ssh._tcp", // service type and protocol
@@ -158,7 +161,9 @@ func (s *Service) advertiseServices(advertiseService, advertiseCredentials bool)
} else { } else {
logger.InfoToConsole("SFTP service advertised via multicast DNS") logger.InfoToConsole("SFTP service advertised via multicast DNS")
} }
}
ftpdConf := config.GetFTPDConfig() ftpdConf := config.GetFTPDConfig()
if ftpdConf.BindPort > 0 {
mDNSServiceFTP, err = zeroconf.Register( mDNSServiceFTP, err = zeroconf.Register(
fmt.Sprintf("SFTPGo portable %v", ftpdConf.BindPort), fmt.Sprintf("SFTPGo portable %v", ftpdConf.BindPort),
"_ftp._tcp", "_ftp._tcp",
@@ -174,6 +179,24 @@ func (s *Service) advertiseServices(advertiseService, advertiseCredentials bool)
logger.InfoToConsole("FTP service advertised via multicast DNS") logger.InfoToConsole("FTP service advertised via multicast DNS")
} }
} }
webdavConf := config.GetWebDAVDConfig()
if webdavConf.BindPort > 0 {
mDNSServiceDAV, err = zeroconf.Register(
fmt.Sprintf("SFTPGo portable %v", webdavConf.BindPort),
"_http._tcp",
"local.",
webdavConf.BindPort,
meta,
nil,
)
if err != nil {
mDNSServiceDAV = nil
logger.WarnToConsole("Unable to advertise WebDAV service via multicast DNS: %v", err)
} else {
logger.InfoToConsole("WebDAV service advertised via multicast DNS")
}
}
}
sig := make(chan os.Signal, 1) sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, syscall.SIGTERM) signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
go func() { go func() {
@@ -186,6 +209,10 @@ func (s *Service) advertiseServices(advertiseService, advertiseCredentials bool)
logger.InfoToConsole("unregistering multicast DNS FTP service") logger.InfoToConsole("unregistering multicast DNS FTP service")
mDNSServiceFTP.Shutdown() mDNSServiceFTP.Shutdown()
} }
if mDNSServiceDAV != nil {
logger.InfoToConsole("unregistering multicast DNS WebDAV service")
mDNSServiceDAV.Shutdown()
}
s.Stop() s.Stop()
}() }()
} }