mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-08 07:10:56 +03:00
portable mode: advertise WebDAV service if requested
This commit is contained in:
@@ -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,34 +146,55 @@ func (s *Service) advertiseServices(advertiseService, advertiseCredentials bool)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
sftpdConf := config.GetSFTPDConfig()
|
sftpdConf := config.GetSFTPDConfig()
|
||||||
mDNSServiceSFTP, err = zeroconf.Register(
|
if sftpdConf.BindPort > 0 {
|
||||||
fmt.Sprintf("SFTPGo portable %v", sftpdConf.BindPort), // service instance name
|
mDNSServiceSFTP, err = zeroconf.Register(
|
||||||
"_sftp-ssh._tcp", // service type and protocol
|
fmt.Sprintf("SFTPGo portable %v", sftpdConf.BindPort), // service instance name
|
||||||
"local.", // service domain
|
"_sftp-ssh._tcp", // service type and protocol
|
||||||
sftpdConf.BindPort, // service port
|
"local.", // service domain
|
||||||
meta, // service metadata
|
sftpdConf.BindPort, // service port
|
||||||
nil, // register on all network interfaces
|
meta, // service metadata
|
||||||
)
|
nil, // register on all network interfaces
|
||||||
if err != nil {
|
)
|
||||||
mDNSServiceSFTP = nil
|
if err != nil {
|
||||||
logger.WarnToConsole("Unable to advertise SFTP service via multicast DNS: %v", err)
|
mDNSServiceSFTP = nil
|
||||||
} else {
|
logger.WarnToConsole("Unable to advertise SFTP service via multicast DNS: %v", err)
|
||||||
logger.InfoToConsole("SFTP service advertised via multicast DNS")
|
} else {
|
||||||
|
logger.InfoToConsole("SFTP service advertised via multicast DNS")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ftpdConf := config.GetFTPDConfig()
|
ftpdConf := config.GetFTPDConfig()
|
||||||
mDNSServiceFTP, err = zeroconf.Register(
|
if ftpdConf.BindPort > 0 {
|
||||||
fmt.Sprintf("SFTPGo portable %v", ftpdConf.BindPort),
|
mDNSServiceFTP, err = zeroconf.Register(
|
||||||
"_ftp._tcp",
|
fmt.Sprintf("SFTPGo portable %v", ftpdConf.BindPort),
|
||||||
"local.",
|
"_ftp._tcp",
|
||||||
ftpdConf.BindPort,
|
"local.",
|
||||||
meta,
|
ftpdConf.BindPort,
|
||||||
nil,
|
meta,
|
||||||
)
|
nil,
|
||||||
if err != nil {
|
)
|
||||||
mDNSServiceFTP = nil
|
if err != nil {
|
||||||
logger.WarnToConsole("Unable to advertise FTP service via multicast DNS: %v", err)
|
mDNSServiceFTP = nil
|
||||||
} else {
|
logger.WarnToConsole("Unable to advertise FTP service via multicast DNS: %v", err)
|
||||||
logger.InfoToConsole("FTP service advertised via multicast DNS")
|
} else {
|
||||||
|
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)
|
||||||
@@ -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()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user