Skip to content

Commit b486af0

Browse files
authored
feat(sftp-server): support disable password login (#1357)
1 parent ea09ce4 commit b486af0

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

internal/bootstrap/data/setting.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,11 @@ func InitialSettings() []model.SettingItem {
213213
// ftp settings
214214
{Key: conf.FTPPublicHost, Value: "127.0.0.1", Type: conf.TypeString, Group: model.FTP, Flag: model.PRIVATE},
215215
{Key: conf.FTPPasvPortMap, Value: "", Type: conf.TypeText, Group: model.FTP, Flag: model.PRIVATE},
216-
{Key: conf.FTPProxyUserAgent, Value: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " +
217-
"Chrome/87.0.4280.88 Safari/537.36", Type: conf.TypeString, Group: model.FTP, Flag: model.PRIVATE},
218216
{Key: conf.FTPMandatoryTLS, Value: "false", Type: conf.TypeBool, Group: model.FTP, Flag: model.PRIVATE},
219217
{Key: conf.FTPImplicitTLS, Value: "false", Type: conf.TypeBool, Group: model.FTP, Flag: model.PRIVATE},
220218
{Key: conf.FTPTLSPrivateKeyPath, Value: "", Type: conf.TypeString, Group: model.FTP, Flag: model.PRIVATE},
221219
{Key: conf.FTPTLSPublicCertPath, Value: "", Type: conf.TypeString, Group: model.FTP, Flag: model.PRIVATE},
220+
{Key: conf.SFTPDisablePasswordLogin, Value: "false", Type: conf.TypeBool, Group: model.FTP, Flag: model.PRIVATE},
222221

223222
// traffic settings
224223
{Key: conf.TaskOfflineDownloadThreadsNum, Value: strconv.Itoa(conf.Conf.Tasks.Download.Workers), Type: conf.TypeNumber, Group: model.TRAFFIC, Flag: model.PRIVATE},

internal/conf/const.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@ const (
125125
QbittorrentSeedtime = "qbittorrent_seedtime"
126126

127127
// ftp
128-
FTPPublicHost = "ftp_public_host"
129-
FTPPasvPortMap = "ftp_pasv_port_map"
130-
FTPProxyUserAgent = "ftp_proxy_user_agent"
131-
FTPMandatoryTLS = "ftp_mandatory_tls"
132-
FTPImplicitTLS = "ftp_implicit_tls"
133-
FTPTLSPrivateKeyPath = "ftp_tls_private_key_path"
134-
FTPTLSPublicCertPath = "ftp_tls_public_cert_path"
128+
FTPPublicHost = "ftp_public_host"
129+
FTPPasvPortMap = "ftp_pasv_port_map"
130+
FTPMandatoryTLS = "ftp_mandatory_tls"
131+
FTPImplicitTLS = "ftp_implicit_tls"
132+
FTPTLSPrivateKeyPath = "ftp_tls_private_key_path"
133+
FTPTLSPublicCertPath = "ftp_tls_public_cert_path"
134+
SFTPDisablePasswordLogin = "sftp_disable_password_login"
135135

136136
// traffic
137137
TaskOfflineDownloadThreadsNum = "offline_download_task_threads_num"

server/ftp.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"strings"
1414
"sync"
1515

16+
"github.com/OpenListTeam/OpenList/v4/drivers/base"
1617
"github.com/OpenListTeam/OpenList/v4/internal/conf"
1718
"github.com/OpenListTeam/OpenList/v4/internal/model"
1819
"github.com/OpenListTeam/OpenList/v4/internal/op"
@@ -80,7 +81,7 @@ func NewMainDriver() (*FtpMainDriver, error) {
8081
PasvConnectionsCheck: pasvConnCheck,
8182
},
8283
proxyHeader: http.Header{
83-
"User-Agent": {setting.GetStr(conf.FTPProxyUserAgent)},
84+
"User-Agent": {base.UserAgent},
8485
},
8586
clients: make(map[uint32]ftpserver.ClientContext),
8687
shutdownLock: sync.RWMutex{},

server/sftp.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"net/http"
66
"time"
77

8+
"github.com/OpenListTeam/OpenList/v4/drivers/base"
89
"github.com/OpenListTeam/OpenList/v4/internal/conf"
910
"github.com/OpenListTeam/OpenList/v4/internal/model"
1011
"github.com/OpenListTeam/OpenList/v4/internal/op"
@@ -27,7 +28,7 @@ func NewSftpDriver() (*SftpDriver, error) {
2728
sftp.InitHostKey()
2829
return &SftpDriver{
2930
proxyHeader: http.Header{
30-
"User-Agent": {setting.GetStr(conf.FTPProxyUserAgent)},
31+
"User-Agent": {base.UserAgent},
3132
},
3233
}, nil
3334
}
@@ -36,10 +37,14 @@ func (d *SftpDriver) GetConfig() *sftpd.Config {
3637
if d.config != nil {
3738
return d.config
3839
}
40+
var pwdAuth func(conn ssh.ConnMetadata, password []byte) (*ssh.Permissions, error) = nil
41+
if !setting.GetBool(conf.SFTPDisablePasswordLogin) {
42+
pwdAuth = d.PasswordAuth
43+
}
3944
serverConfig := ssh.ServerConfig{
4045
NoClientAuth: true,
4146
NoClientAuthCallback: d.NoClientAuth,
42-
PasswordCallback: d.PasswordAuth,
47+
PasswordCallback: pwdAuth,
4348
PublicKeyCallback: d.PublicKeyAuth,
4449
AuthLogCallback: d.AuthLogCallback,
4550
BannerCallback: d.GetBanner,

0 commit comments

Comments
 (0)