mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-06 22:30:56 +03:00
remove data retention hook
use the EventManager instead Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
@@ -35,7 +35,6 @@ const (
|
|||||||
HookStartup = "startup"
|
HookStartup = "startup"
|
||||||
HookPostConnect = "post_connect"
|
HookPostConnect = "post_connect"
|
||||||
HookPostDisconnect = "post_disconnect"
|
HookPostDisconnect = "post_disconnect"
|
||||||
HookDataRetention = "data_retention"
|
|
||||||
HookCheckPassword = "check_password"
|
HookCheckPassword = "check_password"
|
||||||
HookPreLogin = "pre_login"
|
HookPreLogin = "pre_login"
|
||||||
HookPostLogin = "post_login"
|
HookPostLogin = "post_login"
|
||||||
@@ -46,7 +45,7 @@ const (
|
|||||||
var (
|
var (
|
||||||
config Config
|
config Config
|
||||||
supportedHooks = []string{HookFsActions, HookProviderActions, HookStartup, HookPostConnect, HookPostDisconnect,
|
supportedHooks = []string{HookFsActions, HookProviderActions, HookStartup, HookPostConnect, HookPostDisconnect,
|
||||||
HookDataRetention, HookCheckPassword, HookPreLogin, HookPostLogin, HookExternalAuth, HookKeyboardInteractive}
|
HookCheckPassword, HookPreLogin, HookPostLogin, HookExternalAuth, HookKeyboardInteractive}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Command define the configuration for a specific commands
|
// Command define the configuration for a specific commands
|
||||||
|
|||||||
@@ -615,9 +615,6 @@ type Configuration struct {
|
|||||||
// Absolute path to an external program or an HTTP URL to invoke after an SSH/FTP connection ends.
|
// Absolute path to an external program or an HTTP URL to invoke after an SSH/FTP connection ends.
|
||||||
// Leave empty do disable.
|
// Leave empty do disable.
|
||||||
PostDisconnectHook string `json:"post_disconnect_hook" mapstructure:"post_disconnect_hook"`
|
PostDisconnectHook string `json:"post_disconnect_hook" mapstructure:"post_disconnect_hook"`
|
||||||
// Absolute path to an external program or an HTTP URL to invoke after a data retention check completes.
|
|
||||||
// Leave empty do disable.
|
|
||||||
DataRetentionHook string `json:"data_retention_hook" mapstructure:"data_retention_hook"`
|
|
||||||
// Maximum number of concurrent client connections. 0 means unlimited
|
// Maximum number of concurrent client connections. 0 means unlimited
|
||||||
MaxTotalConnections int `json:"max_total_connections" mapstructure:"max_total_connections"`
|
MaxTotalConnections int `json:"max_total_connections" mapstructure:"max_total_connections"`
|
||||||
// Maximum number of concurrent client connections from the same host (IP). 0 means unlimited
|
// Maximum number of concurrent client connections from the same host (IP). 0 means unlimited
|
||||||
|
|||||||
@@ -217,7 +217,6 @@ func Init() {
|
|||||||
ProxySkipped: []string{},
|
ProxySkipped: []string{},
|
||||||
PostConnectHook: "",
|
PostConnectHook: "",
|
||||||
PostDisconnectHook: "",
|
PostDisconnectHook: "",
|
||||||
DataRetentionHook: "",
|
|
||||||
MaxTotalConnections: 0,
|
MaxTotalConnections: 0,
|
||||||
MaxPerHostConnections: 20,
|
MaxPerHostConnections: 20,
|
||||||
AllowListStatus: 0,
|
AllowListStatus: 0,
|
||||||
@@ -645,7 +644,6 @@ func getRedactedGlobalConf() globalConfig {
|
|||||||
conf.Common.StartupHook = util.GetRedactedURL(conf.Common.StartupHook)
|
conf.Common.StartupHook = util.GetRedactedURL(conf.Common.StartupHook)
|
||||||
conf.Common.PostConnectHook = util.GetRedactedURL(conf.Common.PostConnectHook)
|
conf.Common.PostConnectHook = util.GetRedactedURL(conf.Common.PostConnectHook)
|
||||||
conf.Common.PostDisconnectHook = util.GetRedactedURL(conf.Common.PostDisconnectHook)
|
conf.Common.PostDisconnectHook = util.GetRedactedURL(conf.Common.PostDisconnectHook)
|
||||||
conf.Common.DataRetentionHook = util.GetRedactedURL(conf.Common.DataRetentionHook)
|
|
||||||
conf.SFTPD.KeyboardInteractiveHook = util.GetRedactedURL(conf.SFTPD.KeyboardInteractiveHook)
|
conf.SFTPD.KeyboardInteractiveHook = util.GetRedactedURL(conf.SFTPD.KeyboardInteractiveHook)
|
||||||
conf.HTTPDConfig.SigningPassphrase = getRedactedPassword(conf.HTTPDConfig.SigningPassphrase)
|
conf.HTTPDConfig.SigningPassphrase = getRedactedPassword(conf.HTTPDConfig.SigningPassphrase)
|
||||||
conf.HTTPDConfig.Setup.InstallationCode = getRedactedPassword(conf.HTTPDConfig.Setup.InstallationCode)
|
conf.HTTPDConfig.Setup.InstallationCode = getRedactedPassword(conf.HTTPDConfig.Setup.InstallationCode)
|
||||||
@@ -2066,7 +2064,6 @@ func setViperDefaults() {
|
|||||||
viper.SetDefault("common.proxy_skipped", globalConf.Common.ProxySkipped)
|
viper.SetDefault("common.proxy_skipped", globalConf.Common.ProxySkipped)
|
||||||
viper.SetDefault("common.post_connect_hook", globalConf.Common.PostConnectHook)
|
viper.SetDefault("common.post_connect_hook", globalConf.Common.PostConnectHook)
|
||||||
viper.SetDefault("common.post_disconnect_hook", globalConf.Common.PostDisconnectHook)
|
viper.SetDefault("common.post_disconnect_hook", globalConf.Common.PostDisconnectHook)
|
||||||
viper.SetDefault("common.data_retention_hook", globalConf.Common.DataRetentionHook)
|
|
||||||
viper.SetDefault("common.max_total_connections", globalConf.Common.MaxTotalConnections)
|
viper.SetDefault("common.max_total_connections", globalConf.Common.MaxTotalConnections)
|
||||||
viper.SetDefault("common.max_per_host_connections", globalConf.Common.MaxPerHostConnections)
|
viper.SetDefault("common.max_per_host_connections", globalConf.Common.MaxPerHostConnections)
|
||||||
viper.SetDefault("common.allowlist_status", globalConf.Common.AllowListStatus)
|
viper.SetDefault("common.allowlist_status", globalConf.Common.AllowListStatus)
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/sftp"
|
"github.com/pkg/sftp"
|
||||||
|
"github.com/rs/xid"
|
||||||
"github.com/sftpgo/sdk/plugin/notifier"
|
"github.com/sftpgo/sdk/plugin/notifier"
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
|
|
||||||
@@ -563,7 +564,7 @@ func (c *Configuration) configureKeyboardInteractiveAuth(serverConfig *ssh.Serve
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AcceptInboundConnection handles an inbound connection to the server instance and determines if the request should be served or not.
|
// AcceptInboundConnection handles an inbound connection to the server instance and determines if the request should be served or not.
|
||||||
func (c *Configuration) AcceptInboundConnection(conn net.Conn, config *ssh.ServerConfig) {
|
func (c *Configuration) AcceptInboundConnection(conn net.Conn, config *ssh.ServerConfig) { //nolint:gocyclo
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
logger.Error(logSender, "", "panic in AcceptInboundConnection: %q stack trace: %v", r, string(debug.Stack()))
|
logger.Error(logSender, "", "panic in AcceptInboundConnection: %q stack trace: %v", r, string(debug.Stack()))
|
||||||
@@ -600,7 +601,7 @@ func (c *Configuration) AcceptInboundConnection(conn net.Conn, config *ssh.Serve
|
|||||||
json.Unmarshal(util.StringToBytes(sconn.Permissions.Extensions["sftpgo_user"]), &user) //nolint:errcheck
|
json.Unmarshal(util.StringToBytes(sconn.Permissions.Extensions["sftpgo_user"]), &user) //nolint:errcheck
|
||||||
|
|
||||||
loginType := sconn.Permissions.Extensions["sftpgo_login_method"]
|
loginType := sconn.Permissions.Extensions["sftpgo_login_method"]
|
||||||
connectionID := hex.EncodeToString(sconn.SessionID())
|
connectionID := xid.New().String()
|
||||||
|
|
||||||
defer user.CloseFs() //nolint:errcheck
|
defer user.CloseFs() //nolint:errcheck
|
||||||
if err = user.CheckFsRoot(connectionID); err != nil {
|
if err = user.CheckFsRoot(connectionID); err != nil {
|
||||||
@@ -638,7 +639,6 @@ func (c *Configuration) AcceptInboundConnection(conn net.Conn, config *ssh.Serve
|
|||||||
}
|
}
|
||||||
|
|
||||||
channelCounter++
|
channelCounter++
|
||||||
sshConnection.UpdateLastActivity()
|
|
||||||
// Channels have a type that is dependent on the protocol. For SFTP this is "subsystem"
|
// Channels have a type that is dependent on the protocol. For SFTP this is "subsystem"
|
||||||
// with a payload that (should) be "sftp". Discard anything else we receive ("pty", "shell", etc)
|
// with a payload that (should) be "sftp". Discard anything else we receive ("pty", "shell", etc)
|
||||||
go func(in <-chan *ssh.Request, counter int64) {
|
go func(in <-chan *ssh.Request, counter int64) {
|
||||||
@@ -650,6 +650,7 @@ func (c *Configuration) AcceptInboundConnection(conn net.Conn, config *ssh.Serve
|
|||||||
case "subsystem":
|
case "subsystem":
|
||||||
if bytes.Equal(req.Payload[4:], []byte("sftp")) {
|
if bytes.Equal(req.Payload[4:], []byte("sftp")) {
|
||||||
ok = true
|
ok = true
|
||||||
|
sshConnection.UpdateLastActivity()
|
||||||
connection := &Connection{
|
connection := &Connection{
|
||||||
BaseConnection: common.NewBaseConnection(connID, common.ProtocolSFTP, conn.LocalAddr().String(),
|
BaseConnection: common.NewBaseConnection(connID, common.ProtocolSFTP, conn.LocalAddr().String(),
|
||||||
conn.RemoteAddr().String(), user),
|
conn.RemoteAddr().String(), user),
|
||||||
@@ -671,6 +672,9 @@ func (c *Configuration) AcceptInboundConnection(conn net.Conn, config *ssh.Serve
|
|||||||
channel: channel,
|
channel: channel,
|
||||||
}
|
}
|
||||||
ok = processSSHCommand(req.Payload, &connection, c.EnabledSSHCommands)
|
ok = processSSHCommand(req.Payload, &connection, c.EnabledSSHCommands)
|
||||||
|
if ok {
|
||||||
|
sshConnection.UpdateLastActivity()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if req.WantReply {
|
if req.WantReply {
|
||||||
req.Reply(ok, nil) //nolint:errcheck
|
req.Reply(ok, nil) //nolint:errcheck
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
"startup_hook": "",
|
"startup_hook": "",
|
||||||
"post_connect_hook": "",
|
"post_connect_hook": "",
|
||||||
"post_disconnect_hook": "",
|
"post_disconnect_hook": "",
|
||||||
"data_retention_hook": "",
|
|
||||||
"max_total_connections": 0,
|
"max_total_connections": 0,
|
||||||
"max_per_host_connections": 20,
|
"max_per_host_connections": 20,
|
||||||
"allowlist_status": 0,
|
"allowlist_status": 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user