portable mode: remove support for services discovery via multicast DNS
The library used for mDNS doesn't seem well maintained and I think this feature is rarely used Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
parent
048591553a
commit
37ffa3b55a
5 changed files with 3 additions and 140 deletions
|
@ -15,12 +15,6 @@ Usage:
|
|||
sftpgo portable [flags]
|
||||
|
||||
Flags:
|
||||
-C, --advertise-credentials If the SFTP/FTP service is
|
||||
advertised via multicast DNS, this
|
||||
flag allows to put username/password
|
||||
inside the advertised TXT record
|
||||
-S, --advertise-service Advertise configured services using
|
||||
multicast DNS
|
||||
--allowed-patterns stringArray Allowed file patterns case insensitive.
|
||||
The format is:
|
||||
/dir::pattern1,pattern2.
|
||||
|
@ -148,15 +142,3 @@ Flags:
|
|||
--webdav-port int 0 means a random unprivileged port,
|
||||
< 0 disabled (default -1)
|
||||
```
|
||||
|
||||
In portable mode, SFTPGo can advertise the SFTP/FTP services and, optionally, the credentials via multicast DNS, so there is a standard way to discover the service and to automatically connect to it.
|
||||
|
||||
Here is an example of the advertised SFTP service including credentials as seen using `avahi-browse`:
|
||||
|
||||
```console
|
||||
= enp0s31f6 IPv4 SFTPGo portable 53705 SFTP File Transfer local
|
||||
hostname = [p1.local]
|
||||
address = [192.168.1.230]
|
||||
port = [53705]
|
||||
txt = ["password=EWOo6pJe" "user=user" "version=0.9.3-dev-b409523-dirty-2019-10-26T13:43:32Z"]
|
||||
```
|
||||
|
|
2
go.mod
2
go.mod
|
@ -31,7 +31,6 @@ require (
|
|||
github.com/golang/mock v1.6.0
|
||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/grandcat/zeroconf v1.0.0
|
||||
github.com/hashicorp/go-hclog v1.3.1
|
||||
github.com/hashicorp/go-plugin v1.4.5
|
||||
github.com/hashicorp/go-retryablehttp v0.7.1
|
||||
|
@ -97,7 +96,6 @@ require (
|
|||
github.com/aws/smithy-go v1.13.4 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/boombuler/barcode v1.0.1 // indirect
|
||||
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
|
||||
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||
github.com/coreos/go-systemd/v22 v22.4.0 // indirect
|
||||
|
|
5
go.sum
5
go.sum
|
@ -315,7 +315,6 @@ github.com/bugsnag/bugsnag-go v0.0.0-20141110184014-b1d153021fcd/go.mod h1:2oa8n
|
|||
github.com/bugsnag/osext v0.0.0-20130617224835-0dd3f918b21b/go.mod h1:obH5gd0BsqsP2LwDJ9aOkm/6J86V6lyAXCoQWGw3K50=
|
||||
github.com/bugsnag/panicwrap v0.0.0-20151223152923-e2c28503fcd0/go.mod h1:D/8v3kj0zr8ZAKg1AQ6crr+5VwKN5eIywRkfhyM/+dE=
|
||||
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
|
||||
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
|
||||
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
|
||||
github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
|
||||
github.com/cenkalti/backoff/v4 v4.1.2/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
|
||||
|
@ -885,8 +884,6 @@ github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoA
|
|||
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/grafana/regexp v0.0.0-20220304095617-2e8d9baf4ac2/go.mod h1:M5qHK+eWfAv8VR/265dIuEpL3fNfeC21tXXp9itM24A=
|
||||
github.com/grandcat/zeroconf v1.0.0 h1:uHhahLBKqwWBV6WZUDAT71044vwOTL+McW0mBJvo6kE=
|
||||
github.com/grandcat/zeroconf v1.0.0/go.mod h1:lTKmG1zh86XyCoUeIHSA4FJMBwCJiQmGfcP2PdzytEs=
|
||||
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
|
||||
|
@ -1176,7 +1173,6 @@ github.com/mhale/smtpd v0.8.0/go.mod h1:MQl+y2hwIEQCXtNhe5+55n0GZOjSmeqORDIXbqUL
|
|||
github.com/microsoft/ApplicationInsights-Go v0.4.4/go.mod h1:fKRUseBqkw6bDiXTs3ESTiU/4YTIHsQS4W3fP2ieF4U=
|
||||
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||
github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso=
|
||||
github.com/miekg/dns v1.1.27/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM=
|
||||
github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI=
|
||||
github.com/miekg/dns v1.1.48/go.mod h1:e3IlAVfNqAllflbibAZEWOXOQ+Ynzk/dDozDxY7XnME=
|
||||
github.com/miekg/dns v1.1.50 h1:DQUfb9uc6smULcREF09Uc+/Gd46YWqJd5DbpPE9xkcA=
|
||||
|
@ -2086,7 +2082,6 @@ golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtn
|
|||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191216052735-49a3e744a425/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
|
|
|
@ -39,8 +39,6 @@ import (
|
|||
var (
|
||||
directoryToServe string
|
||||
portableSFTPDPort int
|
||||
portableAdvertiseService bool
|
||||
portableAdvertiseCredentials bool
|
||||
portableUsername string
|
||||
portablePassword string
|
||||
portableStartDir string
|
||||
|
@ -259,7 +257,7 @@ Please take a look at the usage below to customize the serving parameters`,
|
|||
},
|
||||
}
|
||||
err := service.StartPortableMode(portableSFTPDPort, portableFTPDPort, portableWebDAVPort, portableSSHCommands,
|
||||
portableAdvertiseService, portableAdvertiseCredentials, portableFTPSCert, portableFTPSKey, portableWebDAVCert,
|
||||
portableFTPSCert, portableFTPSKey, portableWebDAVCert,
|
||||
portableWebDAVKey)
|
||||
if err == nil {
|
||||
service.Wait()
|
||||
|
@ -318,14 +316,6 @@ For example: "/somedir::*.jpg,a*b?.png"`)
|
|||
The format is:
|
||||
/dir::pattern1,pattern2.
|
||||
For example: "/somedir::*.jpg,a*b?.png"`)
|
||||
portableCmd.Flags().BoolVarP(&portableAdvertiseService, "advertise-service", "S", false,
|
||||
`Advertise configured services using
|
||||
multicast DNS`)
|
||||
portableCmd.Flags().BoolVarP(&portableAdvertiseCredentials, "advertise-credentials", "C", false,
|
||||
`If the SFTP/FTP service is
|
||||
advertised via multicast DNS, this
|
||||
flag allows to put username/password
|
||||
inside the advertised TXT record`)
|
||||
portableCmd.Flags().StringVarP(&portableFsProvider, "fs-provider", "f", "osfs", `osfs => local filesystem (legacy value: 0)
|
||||
s3fs => AWS S3 compatible (legacy: 1)
|
||||
gcsfs => Google Cloud Storage (legacy: 2)
|
||||
|
|
|
@ -20,22 +20,16 @@ package service
|
|||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/grandcat/zeroconf"
|
||||
"github.com/sftpgo/sdk"
|
||||
|
||||
"github.com/drakkan/sftpgo/v2/internal/common"
|
||||
"github.com/drakkan/sftpgo/v2/internal/config"
|
||||
"github.com/drakkan/sftpgo/v2/internal/dataprovider"
|
||||
"github.com/drakkan/sftpgo/v2/internal/ftpd"
|
||||
"github.com/drakkan/sftpgo/v2/internal/kms"
|
||||
"github.com/drakkan/sftpgo/v2/internal/logger"
|
||||
"github.com/drakkan/sftpgo/v2/internal/plugin"
|
||||
"github.com/drakkan/sftpgo/v2/internal/sftpd"
|
||||
"github.com/drakkan/sftpgo/v2/internal/util"
|
||||
"github.com/drakkan/sftpgo/v2/internal/version"
|
||||
|
@ -43,8 +37,8 @@ import (
|
|||
)
|
||||
|
||||
// StartPortableMode starts the service in portable mode
|
||||
func (s *Service) StartPortableMode(sftpdPort, ftpPort, webdavPort int, enabledSSHCommands []string, advertiseService,
|
||||
advertiseCredentials bool, ftpsCert, ftpsKey, webDavCert, webDavKey string) error {
|
||||
func (s *Service) StartPortableMode(sftpdPort, ftpPort, webdavPort int, enabledSSHCommands []string,
|
||||
ftpsCert, ftpsKey, webDavCert, webDavKey string) error {
|
||||
if s.PortableMode != 1 {
|
||||
return fmt.Errorf("service is not configured for portable mode")
|
||||
}
|
||||
|
@ -125,8 +119,6 @@ func (s *Service) StartPortableMode(sftpdPort, ftpPort, webdavPort int, enabledS
|
|||
return err
|
||||
}
|
||||
|
||||
s.advertiseServices(advertiseService, advertiseCredentials)
|
||||
|
||||
logger.InfoToConsole("Portable mode ready, user: %#v, password: %#v, public keys: %v, directory: %#v, "+
|
||||
"permissions: %+v, enabled ssh commands: %v file patterns filters: %+v %v", s.PortableUser.Username,
|
||||
printablePassword, s.PortableUser.PublicKeys, s.getPortableDirToServe(), s.PortableUser.Permissions,
|
||||
|
@ -152,100 +144,6 @@ func (s *Service) getServiceOptionalInfoString() string {
|
|||
return info.String()
|
||||
}
|
||||
|
||||
func (s *Service) advertiseServices(advertiseService, advertiseCredentials bool) {
|
||||
var mDNSServiceSFTP *zeroconf.Server
|
||||
var mDNSServiceFTP *zeroconf.Server
|
||||
var mDNSServiceDAV *zeroconf.Server
|
||||
var err error
|
||||
|
||||
if advertiseService {
|
||||
meta := []string{
|
||||
fmt.Sprintf("version=%v", version.Get().Version),
|
||||
}
|
||||
if advertiseCredentials {
|
||||
logger.InfoToConsole("Advertising credentials via multicast DNS")
|
||||
meta = append(meta, fmt.Sprintf("user=%v", s.PortableUser.Username))
|
||||
if len(s.PortableUser.Password) > 0 {
|
||||
meta = append(meta, fmt.Sprintf("password=%v", s.PortableUser.Password))
|
||||
} else {
|
||||
logger.InfoToConsole("Unable to advertise key based credentials via multicast DNS, we don't have the private key")
|
||||
}
|
||||
}
|
||||
sftpdConf := config.GetSFTPDConfig()
|
||||
if sftpdConf.Bindings[0].IsValid() {
|
||||
mDNSServiceSFTP, err = zeroconf.Register(
|
||||
fmt.Sprintf("SFTPGo portable %v", sftpdConf.Bindings[0].Port), // service instance name
|
||||
"_sftp-ssh._tcp", // service type and protocol
|
||||
"local.", // service domain
|
||||
sftpdConf.Bindings[0].Port, // service port
|
||||
meta, // service metadata
|
||||
nil, // register on all network interfaces
|
||||
)
|
||||
if err != nil {
|
||||
mDNSServiceSFTP = nil
|
||||
logger.WarnToConsole("Unable to advertise SFTP service via multicast DNS: %v", err)
|
||||
} else {
|
||||
logger.InfoToConsole("SFTP service advertised via multicast DNS")
|
||||
}
|
||||
}
|
||||
ftpdConf := config.GetFTPDConfig()
|
||||
if ftpdConf.Bindings[0].IsValid() {
|
||||
port := ftpdConf.Bindings[0].Port
|
||||
mDNSServiceFTP, err = zeroconf.Register(
|
||||
fmt.Sprintf("SFTPGo portable %v", port),
|
||||
"_ftp._tcp",
|
||||
"local.",
|
||||
port,
|
||||
meta,
|
||||
nil,
|
||||
)
|
||||
if err != nil {
|
||||
mDNSServiceFTP = nil
|
||||
logger.WarnToConsole("Unable to advertise FTP service via multicast DNS: %v", err)
|
||||
} else {
|
||||
logger.InfoToConsole("FTP service advertised via multicast DNS")
|
||||
}
|
||||
}
|
||||
webdavConf := config.GetWebDAVDConfig()
|
||||
if webdavConf.Bindings[0].IsValid() {
|
||||
mDNSServiceDAV, err = zeroconf.Register(
|
||||
fmt.Sprintf("SFTPGo portable %v", webdavConf.Bindings[0].Port),
|
||||
"_http._tcp",
|
||||
"local.",
|
||||
webdavConf.Bindings[0].Port,
|
||||
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)
|
||||
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
|
||||
go func() {
|
||||
<-sig
|
||||
if mDNSServiceSFTP != nil {
|
||||
logger.InfoToConsole("unregistering multicast DNS SFTP service")
|
||||
mDNSServiceSFTP.Shutdown()
|
||||
}
|
||||
if mDNSServiceFTP != nil {
|
||||
logger.InfoToConsole("unregistering multicast DNS FTP service")
|
||||
mDNSServiceFTP.Shutdown()
|
||||
}
|
||||
if mDNSServiceDAV != nil {
|
||||
logger.InfoToConsole("unregistering multicast DNS WebDAV service")
|
||||
mDNSServiceDAV.Shutdown()
|
||||
}
|
||||
plugin.Handler.Cleanup()
|
||||
common.WaitForTransfers(graceTime)
|
||||
s.Stop()
|
||||
}()
|
||||
}
|
||||
|
||||
func (s *Service) getPortableDirToServe() string {
|
||||
switch s.PortableUser.FsConfig.Provider {
|
||||
case sdk.S3FilesystemProvider:
|
||||
|
|
Loading…
Reference in a new issue